Disclaimer: - As this is a lengthy post I am going to follow Q & A pattern
Finite and infinite nested square roots of 2 can be solved to some cosine values as discussed earlier here and here
It is interesting to note that any angle $2\cos(\frac{p}{q})$ between 45° to 90° satisfying $1\over4$ < $p \over q$ <$1\over2$ where $ p \over q$ is of form $p = 2^n $ and $q$ is an odd number satisfying $2^{n+1} <q <2^{n+2}$ can be represented as cyclic infinite nested square roots of 2 ( Hereafter referred as $cin\sqrt2$) ($n \in N$, $q \in Z^+$ all odd numbers)
For example $2\cos(\frac{2\pi}{5})$ can be represented as $cin\sqrt2$[1-,1+], we have lot of others like this
Similarly any angle between 45° to 90° satisfying $1\over4$ < $p \over q$ <$1\over2$ where $ p \over q$ is of form $q = 2^n $ and $p$ is an odd number satisfying $2^{n-1} <p <2^{n-2}$ can be represented as finite nested square roots of 2. ($n \in Z^+$ and $p \in Z^+$ all odd numbers)
For example $2\cos(\frac{3\pi}{2^3})$ can be represented as $n\sqrt2(1-)$ (meaning '1' minus sign between 2 nested square roots of 2) a simplified form for $\sqrt{2-\sqrt{2}}$,
$2\cos(\frac{5\pi}{2^4})$ can be represented as $n\sqrt2(2-)$(meaning '2' minus sign between 2 nested square roots of 2) - a simplified form for $\sqrt{2-\sqrt{2-\sqrt{2}}}$
$2\cos(\frac{7\pi}{2^4})$ can be represented as $n\sqrt2(1-1+)$(meaning '1' minus sign and '1' plus sign among 3 nested square roots of 2) - a simplified form for $\sqrt{2-\sqrt{2+\sqrt{2}}}$
Following python program can find out the sequence of +ve and -ve signs in the single cycle of cyclic infinite nested square roots of 2 (except for odd number 3 - i am not able to code)
import time
n = int(input("Enter an odd number to get single cycle cinsqrt2 "))
i = 0
for i in range(n):
if 2 ** i > n and n < 2 ** (i + 1):
break
numerator = 2 ** (i - 2)
print("Numerator is", numerator)
# print("The Angle generated is", (numerator*180)/n, (numerator*180)//n,'+', ((numberator*180)%n)/n)
halfway_of_n = (n - 1) // 2
# print("Half way to n is", halfway_of_n)
lst = []
r = numerator * 2
begin = time.time()
while r != numerator:
if r > halfway_of_n:
r = n - r
r = r * 2
lst = lst + ['-']
else:
r = r * 2
lst = lst + ['+']
lst = lst + ['+']
print(len(lst))
count = lst.count('-')
print('No of minus signs is/are ', count)
count = lst.count('+')
print('No of plus signs is/are ', count)
print(lst)
end = time.time()
print('Program execution time is', end - begin)
For example by entering $5$ while running above program we get 1- and 1+ and total number of positive and negative signs as 2 which represents single cycle of infinite nested square roots of 2 for $2\cos(\frac{2\pi}{5})$
if we enter another odd number by rerunning program like if we enter $41$ we get
Enter an odd number to get single cycle cinsqrt2
Following will be displayed after execution of code
{41
Numerator is 16
Total number of signs 10
No of minus signs is/are 3
No of plus signs is/are 7
['-', '+', '-', '+', '+', '-', '+', '+', '+', '+']
Program execution time is 4.315376281738281e-05
Process finished with exit code 0}
which represents $2\cos(\frac{16\pi}{41})$ and single cycle for $cin\sqrt2[1-1+1-2+1-4+]$ has to be represented as $\sqrt{2-\sqrt{2+\sqrt{2-\sqrt{2+\sqrt{2+\sqrt{2-\sqrt{2+\sqrt{2+\sqrt{2+\sqrt{2+...}}}}}}}}}}$
Therefore by executing above Python code we can get the $cin\sqrt2$ for given cosine angle (represented in radians)