# $\int \bigl| a\sin(x)+b\cos(x) \bigr| {\rm d}x = ?$

My friend evaluated this to be $$\int \bigl| a\sin(x)+b\cos(x) \bigr| {\rm d}x \\ = \sqrt{a^2+b^2} \left( \sin(x-\phi)\text{sign}(\cos(x-\phi)) +\frac{2}{\pi} \bigl(x-\arctan(\tan(x-\phi)) \bigr) \right) + C$$ where $$\phi = \arctan \left(\frac{a}{b} \right)$$.

My answer instead is much shorter, by simply looking for the intervals of $$x$$ for which I need to multiply by $$-1$$, I got

$$(b\sin(x)-a\cos(x)) \cdot \text{sign}(a\sin(x)+b\cos(x)) + C$$

Why does my friend's solution look so big and complex and how did she even come up with the idea to do that?

• Try $b=1$, $a=0$, then you suggest $\sin x\cdot\text{sign}\,\cos x$ as the antiderivative, but it is not even continuous at some points. – A.Γ. Jan 2 at 16:23
• What exactly is the point of the $\frac{\sqrt{\cos^2(x-\phi)}}{\cos(x-\phi)}$? It could be replaced by $\text{sign}(\cos(x-\phi))$. – John Doe Jan 2 at 16:23
• @A.Γ. The other solution actually also gives $\sin x \cdot \text{sign} \cos x$ in that case – John Doe Jan 2 at 16:27
• @JohnDoe Not really, it has the extra term with $\arctan$ that shifts the function in different intervals by a multiple of $2$ to make it continuous. – A.Γ. Jan 2 at 16:43
• @A.Γ. Ah yes, you're right. – John Doe Jan 2 at 16:44

She is probably starting by replacing the $$a\sin x + b\cos x$$ and rewriting in terms of a function with an amplitude and phase. One way to do this is to multiply by $$1$$ and draw a right triangle with angle $$\phi$$, adjacent side length $$b$$, and opposite side length $$a$$. Then one has
\begin{aligned} \left|a\sin x + b\cos x\right| &= \sqrt{a^{2}+b^{2}}\left|\frac{a}{\sqrt{a^{2}+b^{2}}}\,\sin x + \frac{b}{\sqrt{a^{2}+b^{2}}}\,\cos x\right| \\ &= \sqrt{a^{2}+b^{2}}\left|\sin\phi\sin x + \cos\phi\cos x\right| \\ &= \sqrt{a^{2}+b^{2}}\left|\cos(x-\phi)\right|.\end{aligned}