Derivative of a trigonometric function $\arctan$ Will someone help me explain this example please? 

$$y=\arctan \dfrac{\sqrt{1-\cos (x)}}{\sqrt{1+\cos (x)} }$$

Solution:
$$\sin^2 (x/2)=\dfrac{1-\cos (x)}{2}\Rightarrow \sqrt{2}\sin (x/2)=\sqrt{1-\cos (x)}$$
$$\cos^2 (x/2)=\dfrac{1+\cos (x)}{2}\Rightarrow \sqrt{2} \cos (x/2)=\sqrt{1+\cos (x)}$$
$$y=\arctan\dfrac{\sqrt{1-\cos (x)}}{\sqrt{1+\cos (x)}}=\arctan\dfrac{\sin (x/2)}{\cos (x/2)}=\arctan (\tan (x/2))=\dfrac{x}{2}$$
$$y=\dfrac{x}{2}\rightarrow \dfrac{dy}{dx}=\dfrac{1}{2}$$
 A: Let the function $f(x)$ be given by 
$$f(x)=\arctan\left(\sqrt{\frac{1-\cos(x)}{1+\cos(x)}}\right)=\arctan\left(|\tan(x/2)|\right)$$
If $x\in (2n\pi,(2n+1)\pi)$, then $\tan(x/2)> 0$ and we have 
$$\arctan\left(|\tan(x/2)|\right)=\arctan\left(\tan(x/2)\right)=\frac x2-n\pi$$
If $x\in ((2n-1)\pi,2n\pi)$, then $\tan(x/2)< 0$ and we have 
$$\arctan\left(|\tan(x/2)|\right)=-\arctan\left(\tan(x/2)\right)=-\frac x2+n\pi$$
Differentiating, we find that 
$$f'(x)=\begin{cases}\frac12&,x\in(2n\pi,(2n+1)\pi)\\\\-\frac12&,x\in((2n-1),2n\pi)\end{cases}$$
A: Hint:
In fact,$$\tan y=\left|\tan\dfrac x2\right|$$
Now when $\tan\dfrac x2\ge0$
A: Without the preliminary simplifications.
Let $$y=\tan^{-1}(u) \qquad \text{with} \qquad u=\dfrac{\sqrt{1-\cos (x)}}{\sqrt{1+\cos (x)} } $$
$$\frac{dy}{dx}=\frac 1 {1+u^2}\frac{du}{dx}=\cos ^2\left(\frac{x}{2}\right)\,\frac{du}{dx}$$ Now $$\log(u)=\frac 12 \log(1-\cos(x))-\frac 12 \log(1+\cos(x))$$ Differentiate both sides
$$\frac{du}u=\frac{1}{2} \left(\frac{\sin (x)}{1-\cos (x)}+\frac{\sin (x)}{1+\cos (x)}\right)\,dx=\csc (x)\,dx\implies \frac{du}{dx}=\csc (x)\dfrac{\sqrt{1-\cos (x)}}{\sqrt{1+\cos (x)} }$$ Now, we make the simplifcation to get
$$\frac{du}{dx}=\sqrt{\tan ^2\left(\frac{x}{2}\right)} \csc (x)\implies \frac{dy}{dx}=\frac{1}{2} \frac{\sqrt{\tan ^2\left(\frac{x}{2}\right)}}{ \tan \left(\frac{x}{2}\right)}$$ and you see the problem related to the sign of $\tan \left(\frac{x}{2}\right)$
