<s>[INST] Formula for $\sqrt{a-\sqrt{a+\sqrt{a+\ldots}}}$ Supposedly, the infinitely nested radical $$\sqrt{a-\sqrt{a+\sqrt{a+\ldots}}}\tag1\label{1}$$
converges to $$\frac {A-1}{6}+\frac 23\sqrt{4a+A}\sin\left(\frac 13\arctan\frac {2A+1}{3\sqrt 3}\right)\tag2$$
where $A=\sqrt{4a-7}$. In fact, that's how Ramanujan arrived at the famous nested radical $$\sqrt{2-\sqrt{2+\sqrt{2+\ldots}}}=2\sin\left(\frac {\pi}{18}\right)\tag3$$
So I'm wondering how you would prove $\ref{1}$. My best try was to set $(1)$ equal to $x$ and substitute to get $$x=\sqrt{a-\sqrt{a+\sqrt{a+x}}}$$to get an octic polynomial. But I'm not too sure how the trigonometry made its way into the generalization.
And I also wonder if there is a way to generalize this even further to possible $$\sqrt{a-\sqrt{a-\sqrt{a+\sqrt{a+\ldots}}}}$$ which has period $4$ instead of $3$.
 [/INST] Here's how I duplicated
Ramanujan's result,
with a lot of help from Wolfy.
Start with
$x=\sqrt{a-\sqrt{a+\sqrt{a+x}}}
$.
Squaring,
$x^2-a
=-\sqrt{a+\sqrt{a+x}}
$.
Squaring again,
$(x^2-a)^2
=a+\sqrt{a+x}
$
or
$(x^2-a)^2-a
=\sqrt{a+x}
$.
A final squaring gives
$((x^2-a)^2-a)^2-a
=x
$.
Setting
$a=2$
gives
$x
=((x^2-2)^2-2)^2-2
$.
According to Wolfy,
there are
8 real roots
of this
(including -1 and 2),
though it identifies 
3 as complex roots
while giving them
as real numbers.
These are
$-1, 2,
-1.8794, 0.34730,
1.5321, -1.8019,
-0.44504, 1.2470,
$
though, for some reason,
it calls the last 3 complex.
I have no idea 
how Wolfy got the roots.
Each one of them
is expressed with
$\sqrt{3}$ and
expressions involving it
and $i$,
some of them raised to the
$\frac13$ and $\frac23$
powers.
It turns out
the the fourth of these,
0.34730,
is the desired root.
This can be gotten
by asking Wolfy for
"root of 
$x=\sqrt{2-\sqrt{2+\sqrt{2+x}}}$"
which gives a value
slightly less than
$0.35$.
Here is how I went
from the exact expression
for this root 
given by Wolfy
to Ramanujan's expression:
$\begin{array}\\
x
&=\dfrac{-(1-i \sqrt{3})}{2^{2/3} (-1+i \sqrt{3})^{1/3}}-\frac12 (1+i \sqrt{3}) (\frac12 (-1+i \sqrt{3}))^{1/3} \\
&=\dfrac{-1+i \sqrt{3}}{2^{2/3} (-1+i \sqrt{3})^{1/3}}-\frac12 (1+i \sqrt{3}) (\frac12 (-1+i \sqrt{3}))^{1/3} \\
&=2^{-2/3}(-1+i \sqrt{3})^{2/3}-\frac12 (1+i \sqrt{3}) (\frac12 (-1+i \sqrt{3}))^{1/3} \\
&=(\frac12(-1+i \sqrt{3}))^{2/3}-\frac12 (1+i \sqrt{3}) (\frac12 (-1+i \sqrt{3}))^{1/3} \\
&=(e^{2\pi i/3})^{2/3}-e^{\pi i/3} (e^{2\pi i/3})^{1/3} \\
&=e^{4\pi i/9}-e^{(\pi i)(1/3+2/9)} \\
&=e^{4\pi i/9}-e^{(\pi i)(5/9)} 
\qquad\text{(I was worried here)}\\
&=e^{4\pi i/9}-e^{(\pi i)(1-4/9)} 
\qquad\text{(but then I thought of this)}\\
&=e^{4\pi i/9}-e^{\pi i}e^{-4\pi i/9} \\
&=e^{4\pi i/9}+e^{-4\pi i/9} \\
&=2\cos(4\pi /9)
\qquad\text{since }2\cos(z)=e^{iz}+e^{-iz} \\
&=2\sin(\pi/2-4\pi /9)
\qquad\text{since } \cos(z) = \sin(\pi/2-z)\\
&=2\sin(\pi/18)\\
\end{array}
$
</s>