How to prove the following formula,
$$\sqrt{2 + \sqrt{2 + ... + \sqrt{2 + \sqrt{x}}}} = \begin{cases} 2 \cos\Big[\frac{1}{2^{n}}\Big(\pi + \arctan{\frac{\sqrt{x(4-x)}}{x-2}}\Big)\Big] & 0 < x < 2 \\ 2 \cos\Big[\frac{1}{2^{n}}\arctan{\frac{\sqrt{x(4-x)}}{x-2}}\Big] & 2 < x \leq 4 \\ 2 \cosh\Big[\frac{1}{2^{n}}\text{arctanh}{\frac{\sqrt{x(x-4)}}{x-2}}\Big] & x \geq 4 \end{cases} \ $$ where $x \in \mathcal{R}$ and $n$ is the number of time the square root symbol $\sqrt{\text{ }\text{ }}$ appears.
This formula is a generalization of the following formula, which can be found here and here, and which can be obtained by taking the above general formula in the limit $x = 2$.
$$\sqrt{2 + \sqrt{2 + ... + \sqrt{2 + \sqrt{2}}}} = 2\cos\Big(\frac{\pi}{2^{n+1}}\Big)$$