About proof: $\cot^{-1}\left(\frac{\sqrt{1+\sin x}+\sqrt{1-\sin x}}{\sqrt{1+\sin x}-\sqrt{1-\sin x}}\right)=\frac x2$ I have the following question:

Prove that: $$ \cot^{-1}\Biggl(\frac{\sqrt{1+\sin x} + \sqrt{1-\sin x}}{\sqrt{1+\sin x} - \sqrt{1-\sin x}}\Biggl) = \frac x2, \ x \in \biggl(0, \frac \pi4\biggl) $$
The solution: 


My question is about the second step (i.e., highlighted). We know that it has came from the following resolution: $$ \sqrt{1\pm \sin x} = \sqrt{\sin^2\frac x 2 + \cos^2\frac x 2 \pm2\sin\frac x 2\cos\frac x 2} = \pm \biggl( \cos\frac x 2 \pm \sin\frac x 2 \ \biggl) $$
I've included the $\pm$ symbol in accordance with the standard definition of square root. The above solution uses the positive resolution (i.e., $ \cos\frac x 2 - \sin\frac x 2 $) for $ \sqrt{1- \sin x} $. But, if I use the negative one, then the result changes. The sixth step changes to: $$ \cot^{-1}\biggl(\tan\frac x 2\biggl) = \cot^{-1}\Biggl(\cot\left(\frac \pi 2 - \frac x 2\right)\Biggl) $$
which yield the result: $$ \frac \pi 2 - \frac x 2 $$
Mathematically, this result is different from that provided in the RHS of question.
Is the question statement wrong or I've been hacked up?
 A: Rationalize the numerator to find
$$f(x)=\dfrac{1+|\cos x|}{\sin x}$$
Now if $\cos x\ge0,$ $$f(x)=\cot\dfrac x2$$
$\cot^{-1}f(x)=?$
Else $f(x)=\dfrac{1-\cos x}{\sin x}=\tan\dfrac x2$
Now $\cot^{-1}f(x)=\dfrac\pi2-\tan^{-1}f(x)=?$
A: As StubbornAtom mentioned in comment, for $x \in \biggl(0, \frac \pi4\biggl)$, the square root is:
$$\sqrt{1-\sin x}=\cos \frac x2-\sin \frac x2,$$
because:
$$\cos \frac x2-\sin \frac x2>0.$$
If, for example, $x \in \biggl(\frac \pi2, \pi\biggl)$, the square root would be:
$$\sqrt{1-\sin x}=\sin\frac x2-\cos \frac x2,$$
because:
$$\sin \frac x2-\cos \frac x2>0.$$
Addendum. Note that $\pm$ is placed to make the number positive and it does not imply one gets positive and negative values for the square root. Here is another way to write the same equality:
$$\sqrt{1-\sin x}=\left|\cos \frac x2-\sin \frac x2\right|=\begin{cases}+\left(\cos \frac x2-\sin \frac x2\right), \cos \frac x2-\sin \frac x2\ge 0 \\ -\left(\cos \frac x2-\sin \frac x2\right), \cos \frac x2-\sin \frac x2< 0 \\ \end{cases}.$$
A: Note that for $x\in (0,{\pi \over 4})$ we have $$\sqrt{1-{\sqrt 2\over 2}}<\sqrt{1-\sin x}<1\\\sqrt{1-{\sqrt 2\over 2}}=\cos {\pi \over 8}-\sin {\pi \over 8}<\cos {x\over 2}-\sin{x\over 2}<1\\-1<\sin {x \over 2}-\cos {x \over 2}<-\sqrt{1-{\sqrt 2\over 2}}$$comparing the range for all $x\in (0,{\pi \over 4})$ we obtain$$\sqrt{1-\sin x}=\cos {x\over 2}-\sin{x\over 2}$$and$$\sqrt{1-\sin x}\ne \sin {x\over 2}-\cos{x\over 2}$$
A: We see that
$$\frac{\sqrt{1+\sin x} + \sqrt{1-\sin x}}{\sqrt{1+\sin x} - \sqrt{1-\sin x}}$$
$$= \sqrt{(\frac{\sqrt{1+\sin x} + \sqrt{1-\sin x}}{\sqrt{1+\sin x} - \sqrt{1-\sin x}})^2}$$
$$= \sqrt{\frac{1+\sin x +1-\sin x + 2\cdot\sqrt{1-\sin^2 x}}{1+\sin x +1-\sin x -2\cdot\sqrt{1-\sin^2 x}}}$$
$$= \sqrt{\frac{1+\cos x}{1-\cos x}}$$
$$= \sqrt{\frac{2\cdot\cos^2\frac{x}{2}}{2\cdot\sin^2\frac{x}{2}}}$$
$$= \cot \frac{x}{2}$$
And hence,
$$\cot^{-1} (\frac{\sqrt{1+\sin x} + \sqrt{1-\sin x}}{\sqrt{1+\sin x} - \sqrt{1-\sin x}})$$
$$= \cot^{-1} (\cot \frac{x}{2})$$
$$= \frac{x}{2}$$
Note: as $x\in [0,\frac{\pi}{4}]$, $\sqrt{1-\sin x} \le \sqrt{1+\sin x}$.
And hence
$$0\le\frac{\sqrt{1+\sin x} + \sqrt{1-\sin x}}{\sqrt{1+\sin x} - \sqrt{1-\sin x}}$$
