<s>[INST] Discrepancy in differentiating: $y=\tan^{-1}\left(\frac{\sqrt{1+\sin{x}}+\sqrt{1-\sin{x}}}{\sqrt{1+\sin{x}}-\sqrt{1-\sin{x}}}\right)$ $$y=\tan^{-1}\left(\frac{\sqrt{1+\sin{x}}+\sqrt{1-\sin{x}}}{\sqrt{1+\sin{x}}-\sqrt{1-\sin{x}}}\right)$$
$$\sqrt{1+\sin{x}}=\sin{\frac{x}{2}}+\cos{\frac{x}{2}}$$
$$\sqrt{1-\sin{x}}=\sin{\frac{x}{2}}-\cos{\frac{x}{2}}$$
$$y=\tan^{-1}\left(\tan{\frac{x}{2}}\right)$$Differentiating, we get: $$\frac{dy}{dx}=\frac{1}{2}$$
But taking: $$\sqrt{1-\sin{x}}=\cos{\frac{x}{2}}-\sin{\frac{x}{2}}$$
$$y=\tan^{-1}\left(\cot{\frac{x}{2}}\right)$$
Differentiating, we get: $$\frac{dy}{dx}=\frac{-1}{2}$$
I figured that I needed to use absolute value for the simplification of $\sqrt{1-\sin{x}}$, i.e. $\sqrt{1-\sin{x}}=\left|\sin{\frac{x}{2}}-\cos{\frac{x}{2}}\right|$. 
Subsequently, I put the below functions into Wolfram Alpha's input box to differentiate: $$y_1=\tan^{-1}\left(\frac{\sqrt{1+\sin{x}}+\sqrt{1-\sin{x}}}{\sqrt{1+\sin{x}}-\sqrt{1-\sin{x}}}\right)$$
And
$$y_2=\tan^{-1}\left(\frac{\left|\sin{\frac{x}{2}}+\cos{\frac{x}{2}}\right|+\left|\sin{\frac{x}{2}}-\cos{\frac{x}{2}}\right|}{\left|\sin{\frac{x}{2}}+\cos{\frac{x}{2}}\right|-\left|\sin{\frac{x}{2}}-\cos{\frac{x}{2}}\right|}\right)$$
The answers should ideally match, but they dont. $\frac{dy_1}{dx}=\frac{-1}{2}\neq\frac{dy_2}{dx}$
Why don't they?
 [/INST] At $x = 0$, $\sqrt{1-\sin x} = 1$, this means $\sqrt{1-\sin x} = \cos\frac{x}{2} - \sin\frac{x}{2}$ instead of $\sin\frac{x}{2} - \cos\frac{x}{2}$.
For $x \approx 0$, more precisely, $x \in (-\frac{\pi}{2},\frac{\pi}{2})$, 
we have $\frac{dy}{dx} = -\frac12$.
Notice $\sqrt{1-\sin x}$ is not smooth at the boundary of $(-\frac{\pi}{2},\frac{\pi}{2})$ and it develop cusps there.
When one start increasing $x$ from $0$ to beyond $\pi/2$, above formula for $\sqrt{1-\sin x}$ start to fail at $x = \frac{\pi}{2}$. Instead, we have $\sqrt{1-\sin x} = \sin\frac{x}{2} - \cos\frac{x}{2}$ for $x \in ( \frac{\pi}{2},\pi )$. This means $\frac{dy}{dx} = \frac12$ over that interval.
In general, $y(x)$ is a piecewise linear function with jump discontinuities at
integer multiple of $\pi$. Its derivatives has jump discontinuities at
half-integer mulitples of $\pi$. To summarize,
$$\frac{dy(x)}{dx} = 
\begin{cases}
\text{undefined}, & \frac{2x}{\pi} \text{ is a integer}\\
-\frac12, & {\rm round}(\frac{x}{\pi}) \text{ is even}\\
+\frac12, & {\rm round}(\frac{x}{\pi}) \text{ is odd}.
\end{cases}
$$
In certain sense, both answer $\pm \frac12$ are right and both are wrong. Both are right because each of them are valid over some subsets of $\mathbb{R}$. Both are wrong because $\frac{dy}{dx}$ is not a constant function.
</s>