Which differential coefficient is correct and why? Given $$\cot{\theta} = \frac{\sqrt{1+\sin(x)}+\sqrt{1-\sin(x)}}{\sqrt{1+\sin(x)}-\sqrt{1-\sin(x)}}$$
I have to find its  differential coefficient w.r.t $x$ i.e. $\dfrac{d \theta }{dx}$.
Now I can find it in the following two ways:
(1). When I write $\sqrt{1-\sin(x)}=\cos(x/2)-\sin(x/2)$, I get 
    $$\cot(\theta) = \frac{\cos(x/2) + \sin(x/2) + \cos(x/2) - \sin(x/2)}{\cos(x/2) + \sin(x/2) - \cos(x/2) + \sin(x/2)} = \cot(x/2)$$
    $$\theta=x/2 \implies \frac{d \theta}{dx} = \frac12$$
(2). When I write $\sqrt{1-\sin(x)}=\sin(x/2)-\cos(x/2)$, I get
     $$\cot(\theta) = \frac{\cos(x/2) + \sin(x/2) - \cos(x/2) + \sin(x/2)}{\cos(x/2) + \sin(x/2) + \cos(x/2) - \sin(x/2)} = \tan(x/2)$$
    $$\theta=\pi/2 - x/2 \implies \frac{d \theta}{dx} = -\frac12$$
Which of the above two answers is correct and why? Please help me know it. Thanks.
 A: Neither. When you deal in half-angle formulas, you have to be careful about sign.
Notice that $\sqrt{1-\sin x}$ is always positive, while $\sin (x/2)-\cos(x/2)$ and $\cos(x/2)-\sin(x/2)$ may be positive or negative depending on $x$. The correct statement is $\sqrt{1-\sin x}=|\cos(x/2)-\sin(x/2)|$; from there, you'll need to do some case analysis to compute the derivative you want.
A: Micah has a good answer as to why you have an inconsistency. To make your task easier, consider rationalizing your denominator:
$$\begin{align}
\frac{\sqrt{1+\sin(x)}+\sqrt{1-\sin(x)}}{\sqrt{1+\sin(x)}-\sqrt{1-\sin(x)}}\cdot\frac{\sqrt{1+\sin(x)}+\sqrt{1-\sin(x)}}{\sqrt{1+\sin(x)}+\sqrt{1-\sin(x)}}&=\frac{2+2\sqrt{1-\sin^2(x)}}{2\sin(x)}\\
\cot(\theta)&=\frac{1+|\cos(x)|}{\sin(x)}
\end{align}$$
Now the chain rule, quotient rule, and the derivative of $|x|$ (which is $|x|/x$) will give you $\frac{d\theta}{dx}$ in terms of $x$ and $\csc^2(\theta)$ without dealing with any more square roots or half-angle formulas. If you like, $\csc^2(\theta)$ can be subbed out for $1+\cot^2(\theta)$, which can be written in terms of $x$ alone.
