Why does this ratio of sums of square roots equal $1+\sqrt2+\sqrt{4+2\sqrt2}=\cot\frac\pi{16}$ for any natural number $n$?

$\frac {\cos (a+b) + \cos (a - b)}{\sin (a+b) + \sin (a -b)} = cotan (a)$ is independent of $b$.

In particular, with $a = \frac \pi {16}$, $\frac{\cos x + \cos (\frac \pi 8 - x)}{\sin x + \sin (\frac \pi 8 - x)}$ is independant of $x$.

Since $\cos(4(\frac \pi 8 - x)) = \sin(4x)$ and $\sin(4(\frac \pi 8 - x)) = \cos(4x)$, after multiplying the angle by $4$, those will look quite the same.

So, expressing everyone in terms of $\cos (4x)$ and $\sin (4x)$, you get the similar looking expressions (valid for $x \in [0 ; \frac \pi 8]$):

$\cos x = \sqrt{\frac 1 2 + \sqrt{\frac {1+ \cos(4x)}8}} \\ \sin x = \sqrt{\frac 1 2 - \sqrt{\frac {1+ \cos(4x)}8}} \\ \cos (\frac \pi 8 -x) = \sqrt{\frac 1 2 + \sqrt{\frac {1+ \sin(4x)}8}} \\ \sin (\frac \pi 8 -x) = \sqrt{\frac 1 2 - \sqrt{\frac {1+ \sin(4x)}8}} \\ $

Next, let $u = \cos(4x)^2$, you obtain that

$$\frac {\sqrt{\frac 1 2 + \sqrt{\frac {1+ \sqrt u}8}} + \sqrt{\frac 1 2 + \sqrt{\frac {1+ \sqrt{1-u}}8}}}{\sqrt{\frac 1 2 - \sqrt{\frac {1+ \sqrt u}8}} + \sqrt{\frac 1 2 - \sqrt{\frac {1+ \sqrt{1-u}}8}}}$$ is a constant.

Your equality is then obtained by obfuscating : multiply numerator and denominator with $\sqrt {2 \sqrt{2n+2}}$, and apply this with $u = \frac k {(n+1)^2}$

So the equality boils down to the original surprising equality about $cotan(a)$. I'm not sure if it can be understood geometrically.

You can get more complicated formulas (even more nested square roots !) by reflecting the angle around $a = \frac \pi {2^k}$ for $k > 4$