Is the absolute value of a definite integral equal to the definite integral of the absolute value of the integrand? An interesting question occurred to me as I was reading some Physics: Is it true in general that $$\left|\int_a^b f(x) \, dx\right| = \int_a^b |f(x)| \, dx\, ?$$
If not, what properties must $f(x)$ satisfy for the above equality to be true?
I'm not a mathematician, but my hunch is that the equality holds only for $f$ such that $f(x) > 0$ for every $x \in [a,b].$ This seems to work out with some simple examples I've tried, but I haven't been able to prove it rigorously so far. I suspect the Cauchy-Schwartz inequality might come in handy, but I do not know how to use it here, unless perhaps if I interpret the definite integral as a Riemann Sum.
 A: Let $A\subset \operatorname{supp}f$ such that $\operatorname{arg} f$ is constant on $\operatorname{supp}f\backslash A$. If there exists some $A$ satisfying this property with measure zero, then $$\left|\int_a^b f(x) \, dx\right| = \int_a^b |f(x)| \, dx$$
Proof: $$\left|\int_a^b f(x) \, dx\right| = \left| \int_{[a,b]\backslash\operatorname{supp}f} f(x) \, dx \, + \int_{\operatorname{supp}f\backslash A} f(x) \, dx \, + \int_A f(x) \, dx\right| = \left| \int_{\operatorname{supp}f\backslash A} f(x) \, dx\right|$$
Because $\int_{[a,b]\backslash\operatorname{supp}f} f(x) \, dx = 0$ and, since $A$ has measure zero, $\int_A f(x) \, dx = 0$
Since $\operatorname{arg} f$ is constant on $\operatorname{supp}f\backslash A$, $\left| \int_{\operatorname{supp}f\backslash A} f(x) \, dx\right| = \int_{\operatorname{supp}f\backslash A} \left|f(x)\right| \, dx$
Therefore, because $\int_A \left|f(x)\right| \, dx = 0$, $$\left|\int_a^b f(x) \, dx\right| = \int_{\operatorname{supp}\backslash A} \left|f(x)\right| \, dx = \int_a^b |f(x)| \, dx$$
A: It is not the case in general, take $f(x)=\cos(x)$, $a=0$ and $b=\pi$ for instance. If $f$ is such that
$$ \left|\int_a^b f(x)dx\right|=\int_a^b|f(x)|dx $$
We can suppose without loss of generality that $\int_a^b f\geqslant 0$ (otherwise consider $-f$). We thus have
$$ \int_a^b (|f(x)|-f(x))dx=0 $$
and $|f|-f\geqslant 0$. If $f$ is continuous then $|f|-f=0$, in the general case where $f$ is measurable, this means that $|f|-f=0$ almost everywhere. Thus the sign of $f$ is constant in the Riemann integral if $f$ is continuous (or the same almost everywhere in the Lebesgue integral).
A: Let's define the positive and  negative part of the function $f$
$f^+:\begin{cases} f(x) & \forall x\mid f(x)> 0\\0 & \text{elsewhere}\end{cases}\ $ and $\ \displaystyle I^+=\int_a^b f^+(x)\mathop{dx}$
$f^-:\begin{cases} -f(x) & \forall x\mid f(x)< 0\\0 & \text{elsewhere}\end{cases}\ $ and $\ \displaystyle I^-=\int_a^b f^-(x)\mathop{dx}$
We have that $f^+,f^-$ are positive functions (in loose sense) and $\begin{cases} f=f^+-f^-\\|f|=f^++f^-\end{cases}$
Thus $\displaystyle \int_a^b |f(x)|\mathop{dx}=I^++I^-\ $ and $\ \displaystyle \left|\int_a^b f(x)\mathop{dx}\right|=|I^+-I^-|=\pm(I^+-I^-)$
Equalling both gives either $2I^+=0$ or $2I^-=0$ which is equivalent in saying $f^+=0\text{ a.e}$ or $f^-=0\text{ a.e}$

This means that $f$ is of constant sign (in loose sense, can be zero) except maybe on a set of measure zero.

Note 1: for Riemann integral we would say except maybe on a countable set of points.
Note 2: if you impose $f$ continuous then you restrict to constant sign only.
