def KB(L):
n = len(L)
# print(L,n)
if n == 0:
return []
elif n == 1:
return L
elif n == 2:
return [(L[0]*L[1] +1)/L[1]]
else:
FL = L[:-2]
LL = L[-2:]
EL = KB(LL)
# print(f'EL={EL}')
return FL + EL
def KBfromback(L):
LC = L.copy()
LU=[]
while (len(LC) >1):
LC = KB(LC)
LU = LU + [LC]
return LU
L1 = [3,4,5,2]
KBfromback(L1)
show(continued_fraction(L1))
continued_fraction(L1).value()
# symboliska argument
xl =list(var('x',n=5))
KBfromback(xl)
ut=KBfromback(xl)[-1:][0][0]
ut
continued_fraction(sqrt(2))
for d in range(2,30):
print(d,continued_fraction(sqrt(d)))
print