<s>[INST] All real numbers in $[0,2]$ can be represented as $\sqrt{2 \pm \sqrt{2 \pm \sqrt{2 \pm \dots}}}$ I would like some reference about this infinitely nested radical expansion for all real numbers between $0$ and $2$.
I'll use a shorthand for this expansion, as a string of signs, $+$ or $-$, with infinite periods denoted by brackets.
$$2=\sqrt{2 + \sqrt{2 + \sqrt{2 + \dots}}}=(+)$$
$$1=\sqrt{2 - \sqrt{2 - \sqrt{2 - \dots}}}=(-)$$
$$0=\sqrt{2 - \sqrt{2 + \sqrt{2 + \dots}}}=-(+)$$
$$\phi=\sqrt{2 + \sqrt{2 - \sqrt{2 + \sqrt{2 - \dots}}}}=(+-)$$
$$\frac{1}{\phi}=\sqrt{2 - \sqrt{2 + \sqrt{2 - \sqrt{2 + \dots}}}}=(-+)$$
In general, the expansion can be found by a very easy algorithm:

*

*take any number in $(0,2)$, square it

*if the result $>2$ write $+$, if the result $<2$ write $-$

*subtract $2$ from the result, square, repeat

If on some step we get $2$ exactly, we just write $(+)$ and the expansion is finished.
Examples:
$$\pi-2=--+-++-+-+++++++-+-+---------+-+--+--+--+++---++++ \dots=1.141592653589793 \dots$$
Basically, $50$ terms of our expansion gave only $15$ correct decimal digits for $\pi$. But considering the expansion can be coded as binary, it's not so bad.
The convergence plot, and two binary plots for this $50$ terms can be seen below:


$$e-1=+-----+++-++-+---++-++++-+---++-+++-++++-++++---++ \dots=1.71828182845905 \dots$$



Do you know any reference about this expansion? Can every real number between $0$ and $2$ be expanded this way?
Is number $2$ special in this case, or can we make a similar expansion using some other number (and other power for the root)?


Edit
Now that I think about it, we can use the general expansion for $x \in [0,a]$:
$$x=\left(a \pm \left(a \pm \left(a \pm \dots \right)^p \right)^p \right)^p$$
$$a=2^{\frac{p}{1-p}}$$
For example:
$$\frac{1}{4}=\left(\frac{1}{4} + \left(\frac{1}{4} + \left(\frac{1}{4} + \dots \right)^2 \right)^2 \right)^2$$
$$\frac{3}{4}-\frac{\sqrt{2}}{2}=\left(\frac{1}{4} - \left(\frac{1}{4} - \left(\frac{1}{4} - \dots \right)^2 \right)^2 \right)^2$$
etc.
However, this case $p=2,~~~a=\frac{1}{4}$ is not just a random example, it's the only rational expansion of this kind. So I would say it's more important than the titular root expansion.

Edit
An interesting article that connects the nested roots of this kind to Chebyshev polynomials: http://www.sciencedirect.com/science/article/pii/S0022247X12003344
 [/INST] Here is a possible explanation. Let $\alpha \in [0, \pi/2]$ and define $\epsilon_1, \epsilon_2, \cdots$ by $ \epsilon_i = \operatorname{sgn}( \cos ( 2^i \alpha )) \in \{-1, 1\}$. Here, we take the convention that $\operatorname{sgn}(0) =1 $. Then applying the identity $2\cos\theta = \operatorname{sgn}(\cos\theta) \sqrt{2 + 2\cos(2\theta)}$ repeatedly, we have
$$ 2\cos \alpha = \sqrt{2 + \epsilon_1 \sqrt{2 + \epsilon_2 \sqrt{ \cdots + \epsilon_n \sqrt{2 + \smash[b]{2\cos(2^{n+1} \alpha)} }}}}. $$
This can be used to show that, with an appropriate definition of infinite nested radical, the following identity
$$ 2\cos \alpha = \sqrt{2 + \epsilon_1 \sqrt{2 + \epsilon_2 \sqrt{ 2 + \cdots }}} $$
is true. This shows that any real number between $[0, 2]$ can be written as an infinite nested radical of the desired form. Moreover, if we denote $x = 2\cos\alpha$, then


*

*$\epsilon_1 = \operatorname{sgn}(2\cos (2\alpha)) = \operatorname{sgn}(x^2 - 2)$,

*$\epsilon_2 = \operatorname{sgn}(2\cos (4\alpha)) = \operatorname{sgn}((x^2 - 2)^2 - 2)$,


and likewise. This explains why signs are determined by OP's algorithm.
</s>