<s>[INST] Find an indefinite integral of $\int \left | \sin x + \cos x\right | dx$ So, I've already showed that $\sin x + \cos x = \sqrt{2}\sin (x+\frac{\pi}{4})$ and $\sin x + \cos x>0$ on the interval $\left ( -\frac{\pi}{4}+\pi k; \frac{3\pi}{4}+ \pi k\right )$, $\sin x + \cos x<0$ on the interval $\left ( \frac{3\pi}{4}+\pi k; \frac{7\pi}{4}+ \pi k\right )$.
So an integral on the "positive" interval is equal to $\sin x - \cos x +C_{1}$, on the "negative" one is equal to  $\cos x - \sin x +C_{2}$.
After that I found the limits of $\sin x - \cos x +C_{1}$ and $\cos x - \sin x +C_{2}$ at the point $\frac{3\pi}{4}$ and found that the constants should be equal $C_{1}=0$ and $C_{2}=2\sqrt{2}$ for example. 
But I don't know how to merge these two expression and get a final answer. I guess it can't be just $sgn(\sin x + \cos x)(\sin x - \cos x) + C $?
 [/INST] By a shift and a scaling, this is the same as integrating $|\sin x|$.
Over the first period ($0$ to $\pi$) we have $\displaystyle\int_0^x\sin t\,dt=1-\cos x$, which is $2$ for the full period. For other values of $x$, you add $2$ as many times as necessary to return $x$ in the first period. In other words,
$$\int_0^x\sin t\ dt=1-\cos(x\bmod\pi)+2\left\lfloor\frac x\pi\right\rfloor.$$

For the initial integral, after (optionally) adjusting the integration constant
$$\sqrt2\left(\frac1{\sqrt2}-\cos\left(\left( x+\frac\pi4\right)\bmod\pi\right)+2\left\lfloor\frac x\pi+\frac14\right\rfloor\right).$$
</s>