Existence of continuous function $g$ with $\int_a^b f(x)g(x){\rm d}x\ge \frac{1}{2}\int_a^b |f(x)|{\rm d}x.$ Assume $f(x)\in C[a,b]$. Prove there exists $g(x)\in C[a,b]$ such that $\int_a^b f(x)g(x){\rm d}x\ge \frac{1}{2}\int_a^b |f(x)|{\rm d}x.$
Denote $J:=\int_a^b|f(x)|{\rm d}x$ and define $s(x):=\text{sgn}f(x),x\in[a,b]$, then $\int_a^b f(x)s(x){\rm d}x=\int_a^b|f(x)|{\rm d}x=J. $
Since the bounded $s(x)$ is discontinuous at some of the zero points of $f(x)$, and such points is at most countable, hence $s(x)$ is integrable. As per the approximation theorem, there exists a continuous function $g(x)$ such that $ \int_a^b|s(x)-g(x)|{\rm d}x\le\frac{1}{2}$.
Therefore, $$\left|\int_a^bf(x)[g(x)-s(x)]{\rm d}x\right|\le \int_a^b|f(x)||g(x)-s(x)|{\rm d}x\le\frac{1}{2}J$$
Finally, we obtain
\begin{align*} \int_a^b f(x)g(x){\rm d}x&=\int_a^b f(x)[g(x)-s(x)]{\rm d}x+\int_a^bf(x)s(x){\rm d}x\ge \frac{1}{2}J. \end{align*}
This is correct?
 A: $s(x)=\operatorname{sgn}f(x)$ need not be integrable, see for example the discussion at Can the sign of a continuous function be 'made Riemann integrable'? : $s$ is discontinuous exactly at the boundary points of $\{ x \mid f(x) < 0 \}$, and that boundary can be an uncountable set and even have positive Lebesgue measure.
A possible alternative: Without loss of generality we can assume that $f$ is not identically zero, so that $\int_a^b |f(x)| \, dx > 0$. For $n \in \Bbb N$ define
$$
g_n(x) = \max( \min( n f(x), 1), -1) = \begin{cases}
 +1 & \text{ if } f(x) \ge \frac 1n \, ,\\
nf(x) & \text{ if } -\frac 1n \le f(x) \le \frac 1n \, ,\\
 -1 & \text{ if } f(x) \le -\frac 1n \, .\\
\end{cases}
$$
$g_n$ is continuous with $0 \le |f(x)|-f(x)g_n(x) \le \frac 1n$ for all $x \in [a, b]$, so that
$$
 \int_a^b  |f(x)| \, dx - \int_a^b f(x)g_n(x)  \, dx \le \frac{b-a}{n} \, . 
$$
The right-hand side is $\le \frac 12 \int_a^b |f(x)| \, dx$ for sufficiently large $n$, and the desired estimate follows.
Remarks:

*

*If $f$ is just assumed to be (Riemann or Lebesgue) integrable (instead of continuous) then the same approach gives an integrable function $g$ with  $\int_a^b f(x)g(x) \, dx \ge \frac 12 \int_a^b |f(x)| \, dx$.


*The proof shows that there is such a function $g$ with $|g(x)| \le 1$.
Without that boundedness restriction one could just choose $g(x) = C f(x)$, because
$$
\int_a^b f(x)g(x) \, dx = C \int_a^bf(x)^2 \, dx \ge \frac 12 \int_a^b |f(x)| \, dx
$$
for sufficiently large $C > 0$.
