How to solve this absolute value equation I have the following integral $$\int_0^{\pi/2} |\sin x-\cos x|dx. $$It's a simple integral but when I try to solve the module I get stuck. I took $\sin x-\cos x>0$ and squaring this I found that $\sin 2x<1$. When I apply $\arcsin$ it would mean $$2x<\frac\pi2 \implies x<\frac\pi4$$ but the interval is wrong from the one in my book. When I apply $\arcsin$ does the sign change? Why?
 A: Hint for how to determine the sign of $\sin x - \cos x$:
$$\sin x -\cos  x = \sqrt2\left(\sin x \cos \frac\pi4 - \cos x \sin\frac\pi4\right) = \sqrt2 \sin\left(x-\frac\pi4\right)$$
A: $$
\begin{align}
\int_0^{\pi/2}|\sin(x)-\cos(x)|\,\mathrm{d}x
&=\int_0^{\pi/4}(\cos(x)-\sin(x))\,\mathrm{d}x
+\int_{\pi/4}^{\pi/2}(\sin(x)-\cos(x))\,\mathrm{d}x\tag{1}\\
&=2\int_0^{\pi/4}(\cos(x)-\sin(x))\,\mathrm{d}x\tag{2}\\
&=2\left[\vphantom{\int}\sin(x)+\cos(x)\right]_0^{\pi/4}\tag{3}\\[6pt]
&=2\sqrt2-2\tag{4}
\end{align}
$$
Explanation:
$(1)$: $\cos(x)\ge\sin(x)$ on $\left[0,\frac\pi4\right]$ and $\sin(x)\ge\cos(x)$ on $\left[\frac\pi4,\frac\pi2\right]$
$(2)$: $\cos(x)=\sin\left(\frac\pi2-x\right)$ and $\sin(x)=\cos\left(\frac\pi2-x\right)$
$(3)$: integrate
$(4)$: evaluate
A: The function $\;f(x)=\lvert \sin x-\cos x\rvert\;$ has a symmetry w.r.t. $\frac\pi 4$ since $\;f\bigl(\frac \pi2-x\bigr)=f(x)$, hence
$$\int_0^{\tfrac\pi 2} \lvert\sin x-\cos x\rvert \,\mathrm dx=2\int_0^{\tfrac\pi 4} (\cos x-\sin x) \,\mathrm dx=2(\sin x+\cos x)\biggl\rvert_0^{\tfrac\pi4}=2(\sqrt2-1).$$
A: \begin{align}
\int_0^{\pi/2} |\sin(x)-\cos(x)|dx &= \int_0^{\pi/4} |\sin(x)-\cos(x)|dx+\int^0_{\pi/4} |\sin(x)-\cos(x)|dx\\
&=-\int_0^{\pi/4} \sin(x)-\cos(x)dx+\int_{\pi/4}^{\pi/2} \sin(x)-\cos(x)dx\\
&=..
\end{align}
A: Well, we can use the relation:
$$\sin\left(x\right)-\cos\left(x\right)=-\sqrt{2}\cdot\sin\left(\frac{\pi}{4}-x\right)\tag1$$
So, for the integral we get:
$$\mathscr{I}:=\int_0^\frac{\pi}{2}\left|\sin\left(x\right)-\cos\left(x\right)\right|\space\text{d}x=\int_0^\frac{\pi}{2}\left|-\sqrt{2}\cdot\sin\left(\frac{\pi}{4}-x\right)\right|\space\text{d}x=$$
$$\int_0^\frac{\pi}{2}\left|-\sqrt{2}\right|\cdot\left|\sin\left(\frac{\pi}{4}-x\right)\right|\space\text{d}x=\sqrt{2}\int_0^\frac{\pi}{2}\left|\sin\left(\frac{\pi}{4}-x\right)\right|\space\text{d}x\tag2$$
Now, for the integral we can write:
$$\int_0^\frac{\pi}{2}\left|\sin\left(\frac{\pi}{4}-x\right)\right|\space\text{d}x=\int_0^\frac{\pi}{4}\sin\left(\frac{\pi}{4}-x\right)\space\text{d}x-\int_\frac{\pi}{4}^\frac{\pi}{2}\sin\left(\frac{\pi}{4}-x\right)\space\text{d}x\tag3$$
A: Note that $\sin x-\cos x=\cos x(\tan x-1)$.
$\sin x\le\cos x$ when $x\in[0,\frac{\pi}{4}]$.
$\sin x\ge\cos x$ when $x\in[\frac{\pi}{4},\frac{\pi}{2}]$.
$$\int_0^\frac{\pi}{2}|\sin x-\cos x|dx=\int_0^\frac{\pi}{4}(\cos x-\sin x)dx+\int_\frac{\pi}{4}^\frac{\pi}{2}(\sin x-\cos x)dx$$
