All real numbers in $[0,2]$ can be represented as $\sqrt{2 \pm \sqrt{2 \pm \sqrt{2 \pm \dots}}}$

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.


Peculiar observation

If we define a binary number $b = b_1b_2\cdots b_n$ with digits mapped to the symbols like this: $$b_k = \begin{cases}0 \text{ if } (-) \text{ at position } k\\1 \text{ if } (+) \text{ at position } k\end{cases}$$ Then if we run the algorithm proposed in the question, looping

x(k) = x(k-1)^2-2;
b(k) = (x(k)>0);

the vector b will get logical values corresponding to bits 1 and 0 of the binary number above and we can calculate it for the linear space of $x\in[0,1]$. If we do this we can then calculate each number as the scalar product $$[1/2,1/4,\cdots,1/2^k]b$$ and if we then plot it, it will look like

enter image description here Which is kind of a peculiar plot having a bit of a discontinuous and fractal structure. I think the largest discontinuity is around $x = \sqrt{1/2}$ but I have no theoretical explanation why..

edit as pointed out by Sangchul Lee this seems similar to Tent Map


Your algorithm pretty much shows that there exists an expansion for every number in $[0,2]$.

If we replace $2$ by $a>2$ (and keep the square root), we will fail because we need that squaring a number from the interval $[u,v]$ produces a number that is either in $a+[u,v]$ or in $a-[u,v]$. So we must have $u=0$ and $v\ge a$ and $v^2\le a+v$. The last two imply $a\le v\le 2$.

If we additionally switch to $k$th roots, the condition becomes that $v\ge a$ and $v^k\le a+v$, hence $a\le v\le\sqrt[k-1]2$.