Evaluate $\int \sqrt{\sin^2 \frac{x}{2}} \, \operatorname{d}\!x $ $$
\int\sqrt{\sin^{2}\left(x \over 2\right)\,}\,{\rm d}x
$$
the answer I saw considered $\sqrt{\sin^{2}\left(x\right)} = \sin\left(x\right)$
and not $\left\vert\,\sin\left(x\right)\,\right\vert$ is this correct?
And please can anyone show me the steps for the answer of $$\int\sqrt{\sin^{2}\left(x\right)}\,{\rm d}x = -\cot\left(x\right)
\left\vert\,\sin\left(x\right)\,\right\vert + C$$
 A: Consider the function
$$
f(x)=\left\{\begin{array}{}
2+4\left\lfloor\dfrac{x}{2\pi}\right\rfloor-2\,\mathrm{sgn}(\sin(x/2))\cos(x/2)
&\text{if }\sin(x/2)\ne0\\
\frac{2x}{\pi}&\text{if }\sin(x/2)=0
\end{array}\right.
$$
$\hspace{3.4cm}$
On each interval $(2n\pi,2(n+1)\pi)$, the $4\left\lfloor\frac{x}{2\pi}\right\rfloor$ term is constant and the derivative of $2\,\mathrm{sgn}(\sin(x/2))\cos(x/2)$ is $|\sin(x/2)|$.
$f(x)$ is continuous, so
$$
\int\sqrt{\sin^2(x/2)}\,\mathrm{d}x=f(x)+C
$$

Simplification: By writing $\mathrm{sgn}(\sin(x/2))=\frac{\sin(x/2)}{|\sin(x/2)|}$ when $\sin(x/2)\ne0$, we get
$$
f(x)=\left\{\begin{array}{}
2+4\left\lfloor\dfrac{x}{2\pi}\right\rfloor-\frac{\sin(x)}{|\sin(x/2)|}
&\text{if }\sin(x/2)\ne0\\
\frac{2x}{\pi}&\text{if }\sin(x/2)=0
\end{array}\right.
$$
A: Let's start by computing an antiderivative, $F(x) = \int_0^x |\sin(t)|\;dt$. Think of $|\sin(x)|$ as the piecewise defined function
$$|\sin(x)| = \begin{cases} \sin(x) & \text{if } \sin(x) \geq 0 \\ -\sin(x) & \text{if } \sin(x) \leq 0 \end{cases}$$
We can unpack this a little further:
$$|\sin(x)| = \begin{cases} \quad\vdots \\
\sin(x) & \text{if } x \in [0, \pi]\\
-\sin(x) & \text{if } x\in[\pi,2\pi]\\
\sin(x) & \text{if } x \in [2\pi, 3\pi]\\
\quad\vdots
\end{cases}$$
So, taking antiderivatives piecewise gives
$$F(x) = \begin{cases} \quad\vdots \\
-\cos(x) +C_0 & \text{if } x \in [0, \pi]\\
\cos(x) + C_1 & \text{if } x\in[\pi,2\pi]\\
-\cos(x) + C_2 & \text{if } x \in [2\pi, 3\pi]\\
\quad\vdots
\end{cases}$$
The constants $C_n$ need to be determined for all $n \in \mathbb{Z}$ so that $F$ is continuous, and $F(0) = 0$. A little thought yields 
$$F(x) = \begin{cases} \quad\vdots \\
-\cos(x) + 1 & \text{if } x \in [0, \pi]\\
\cos(x) + 3 & \text{if } x\in[\pi,2\pi]\\
-\cos(x) + 5 & \text{if } x \in [2\pi, 3\pi]\\
\quad\vdots
\end{cases}$$
Perhaps more succinctly, $F(x) = (-1)^{k+1}\cos(x) + (2k+1)$, $x \in [k\pi, (k+1)\pi]$, $k \in \mathbb{Z}$.
Now $\int|\sin(x)|\;dx = F(x) + C$. You can get yours from this by doing a (careful!) substitution.
A: You can't use $\sqrt{\sin^2x}=\sin x$ because it‘s false. Also the answer $-\cot x\cdot|\sin x|+C$ is patently wrong, because this function is not extendable to a continuos functions on $\mathbb{R}$, because at points of the form $k\pi$ ($k$ an integer) it has different limits from the left and the right. An antiderivative of a continuous function is surely continuous, because it's differentiable.
Let's try our hand to the simpler integral
$$
F(x)=\int_0^x \sqrt{\sin^2t}\,dt=\int_0^x|\sin t|\,dt
$$
which gives an antiderivative of $|\sin x|$. We know that we can write, in a unique way, $x=2k(x)\pi+r(x)$, where $k(x)\in\mathbb{Z}$ and $0\le r(x)<2\pi$. So our integral will be
$$
F(x)=k\int_0^{2\pi}|\sin t|\,dt+\int_0^{r(x)}|\sin t|\,dt
$$
It's easy to see that
$$
\int_0^{2\pi}|\sin t|\,dt=2\int_0^{\pi}\sin t\,dt=4
$$
so we need to compute the other integral; if $0\le r(x)\le\pi$,
$$
\int_{0}^{r(x)}|\sin t|\,dt=\cos0+\cos r(x)=1+\cos r(x).
$$
If $\pi<r(x)<2\pi$, then
\begin{align}
\int_{0}^{r(x)}|\sin t|\,dt
&=\int_{0}^{\pi}\sin t\,dt+\int_\pi^{r(x)}-\sin t\,dt\\[2ex]
&=2+\cos r(x)+1\\[2ex]
&=3+\cos r(x)
\end{align}
Fill in the details.
A: HINT:
From the answer mentioned, the integral seems to be $\displaystyle \sqrt{\sin^2x}$
For real $y,$ we know  $\displaystyle \sqrt{y^2}=|y|$ and
$\displaystyle|y|= \begin{cases} y &\mbox{if } y\ge 0 \\ -y  & \mbox{if } y<0\end{cases} $ 
Now, $\displaystyle\int\sin x\ dx=?$
