Integrate ${\int\sqrt{1 + \sin\frac{x}2}\,\mathrm{d}x}$ So I was doing a integral question and I stumbled upon this question.
$\displaystyle{\int\sqrt{1 + \sin\left(\frac x2\right)}\,dx}$
In order to solve it I did the following:
I took  $u = \frac12x$
Then $\frac {du}{dx}$
Which gave me $2 du = dx$.
After that I substituted u in the equation to get $2\int \sqrt{1 + \sin(u)} du$.
After this I was stuck as I am new to integration of trigonometry so I checked my textbook which did the same just the same but the step after this was this one  
$2\int{\sqrt{\sin^2 \frac12u + \cos^2\frac12u + 2\sin \frac 12u\cos \frac12u}\text{ du}}$ 
I am in a complete awe how the textbook got $2\int{\sqrt{\sin^2 \frac12u + \cos^2\frac12u + 2\sin \frac 12u\cos \frac12u}\text{ du}}$  from $2\int \sqrt{1 + \sin(u)} \text{ du} $
Can someone please explain me how the this is achieved? I am totally stuck

Obviously, knowing the trigonometric identities as already covered is the far superior and simpler method. Here is a more 'generalised' approach. I hope it serves some value.
Here I will address the integral:
\begin{equation}
I = \int \sqrt{1 + \sin\left(\frac{x}{2}\right)}\:dx
\end{equation}
First let $u = \frac{x}{2}$:
\begin{equation}
I = \int \sqrt{1 + \sin(u)} \cdot 2\:du = 2\int \sqrt{1 + \sin(u)}\:du
\end{equation}
We now employ the Weierstrauss Substitution $t = \tan\left(\frac{u}{2}\right)$:
\begin{align}
I &= 2 \int \sqrt{1 + \frac{2t}{1 + t^2}} \cdot \frac{2}{1 + t^2}\:dt = 4 \int \frac{t + 1 }{\left(t^2 + 1 \right)^{\frac{3}{2}}} \:dt = 4\left[ \int \frac{t}{\left(t^2 + 1\right)^{\frac{3}{2}}}\:dt+ \int \frac{1}{\left(t^2 + 1\right)^{\frac{3}{2}}}\:dt \right] \nonumber ]\\
&= 4\left[ -\frac{1}{\sqrt{t^2 + 1}} + J\right]
\end{align}
For the remaining integral $J$ let $t = \tan(s)$:
\begin{align}
J &= \int \frac{1}{\left(\tan^2(s) + 1\right)^{\frac{3}{2}}} \cdot \sec^2(s)\:ds = \int \cos(s) \:ds = sin(s) + C = \sin\left(\arctan(t)\right) + C
\end{align}
Where $C$ is the constant of integration. 
Thus, 
\begin{equation}
I = 4\left[ -\frac{1}{\sqrt{t^2 + 1}} + J\right] = 4\left[ -\frac{1}{\sqrt{t^2 + 1}} + \sin\left(\arctan(t)\right)\right] + C
\end{equation}
Now $t = \tan\left(\frac{u}{2} \right) = \tan\left(\frac{x}{4}\right)$
Thus, 
\begin{align}
I &= 4\left[ -\frac{1}{\sqrt{t^2 + 1}} + \sin\left(\arctan(t)\right) \right] + C = 4\left[ -\frac{1}{\sqrt{\tan^2\left(\frac{x}{4}\right) + 1}} + \sin\left(\arctan\left(\tan\left(\frac{x}{4}\right)\right)\right) \right] + C \\
&= 4\left[ -\cos\left(\frac{x}{4} \right) + \sin\left(\frac{x}{4} \right) \right] = 4\cdot \sqrt{2}\sin\left(\frac{x}{4} = \frac{\pi}{4} \right) + C
\end{align}
