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.
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$$