<s>[INST] integral of $\arcsin(\sin(x))$ I'm having trouble with this integral
$$\int\arcsin(\sin x)\,\mathrm dx$$
The problem is with the intervals of definition for each function :/ if someone could dumb it down for me.   


*

*$\arcsin\colon [-1, 1] \to [-\pi/2, \pi/2]$.  

*$\sin:\mathbb{R}\to [-1, 1]$.


right?
But what about $\arcsin(\sin x)$ ?
 [/INST] Let's have $f(x)=\arcsin(\sin(x))$ and calculate $\displaystyle F(x)=\int_0^x f(t)dt$
Since $f$ is $2\pi-$periodic and $F(2\pi)=0$ by symetry, we have that $F$ is $2\pi-$periodic too.

The idea to introduce $s(x)=\operatorname{sgn}(\cos(x))$ will be useful to find a closed form.
$F(x)=x\arcsin(\sin(x))-\frac{s(x)}2x^2+C(x)$ 
In fact his formula is correct on $1$ period interval under the condition that we assign a constant value for $C(x)$ in each of the $3$ intervals described below. 

But I'll propose a slightly different form : $F(x)=s(x)(\frac 12f(x)^2)+B(x)$ where $B(x)$ is piecewise constant too, but zero on two of the intervals. 
Under this form the periodicity of $F$ is more obvious knowing that $f$ is periodic.

$\displaystyle x\in[0,\frac{\pi}{2}];\quad F(x)=\int_0^x tdt=\frac {x^2}2$
$\displaystyle x\in[\frac{\pi}{2},\frac{3\pi}{2}];\quad F(x)=F(\frac{\pi}2)+\int_{\frac\pi2}^x (\pi-t)dt=\frac {\pi^2}8+\bigg[\pi t-\frac{t^2}2\bigg]_{\frac{\pi}2}^x=\pi x-\frac{x^2}2-\frac{\pi^2}4$
$\displaystyle x\in[\frac{3\pi}{2},2\pi];\quad F(x)=F(\frac{3\pi}2)+\int_{\frac{3\pi}2}^x (t-2\pi)dt=\frac {\pi^2}8+\bigg[\frac{t^2}2-2\pi t\bigg]_{\frac{3\pi}2}^x=\frac{x^2}2-2\pi x+2\pi^2$

$\begin{cases}
x\in[0,\frac{\pi}{2}] & f(x)=x & s(x)=+1 & \frac 12s(x)f(x)^2=\frac {x^2}2 & B(x)=0\\ 
x\in[\frac{\pi}{2},\frac{3\pi}{2}] & f(x)=\pi-x & s(x)=-1 & \frac 12s(x)f(x)^2=-\frac{\pi^2}2+\pi x-\frac {x^2}2 & B(x)=\frac{\pi^2}4\\ 
x\in[\frac{3\pi}{2},2\pi] & f(t)=x-2\pi & s(x)=+1 & \frac 12s(x)f(x)^2=\frac{x^2}2-2\pi x+2\pi^2 & B(x)=0\\ 
\end{cases}$
Now if we consider $\displaystyle \frac{1-s(x)}2=\chi_{[\frac{\pi}{2},\frac{3\pi}{2}]+2k\pi}$ then $B(x)=\big(\frac{1-s(x)}2\big)\frac{\pi^2}4$
Finally a simplified closed form for $F(x)$ can be given by :

$\displaystyle \int_0^x \arcsin(\sin(t))dt=\frac{\pi^2}8+\operatorname{sgn}(\cos(x))\bigg(\frac{\arcsin(\sin(x))^2}2-\frac{\pi^2}8\bigg)$

</s>