# Trying to calculate the top n most irrational numbers as continued fractions

I'm trying to do something outside my depth: determine the n-th most irrational number and display it in continued fraction form.

I was told:

The n-th most irrational number is equal to the n-th Lagrange number, $$L_n$$, where $$L_n=\sqrt{9-\frac{4}{m_n^2}}$$ where $$m_n$$ is the n-th Markov number.

http://extremelearning.com.au/going-beyond-golden-ratio/

I'm not sure this is true because using this equation I wasn't able to derive 1.618 as the most irrational number. But more likely my implementation is lacking all the details. The author does stuff with quadradic irrationals that I don't understand so I'm probably missing a step.

I'm able to generate a continued fractin from a decimal number:

from __future__ import division
import math
def continued_fraction(N, percision=0.000001):
while True:
yield N//1
f = N - (N//1)
if f < percision:
break
N = 1/f

# testing:
golden = (1 + 5 ** 0.5) / 2
list(continued_fraction(golden))
# > [1, 1, 1, 1, 1, ...]


But I have two more functions that I'm not sure if they're correct, and I'm not sure if I'm using them right. First, I'm attempting to get the Markoff number according to this equation:

$$\mu_m = \frac{\sqrt{9m^2-4}}{m} = \{ \sqrt{5}, \sqrt{8}, \frac{\sqrt{221}}{5}, \frac{\sqrt{1517}}{13},… \}$$

And here's my implementation:

markov_integer =[1, 2, 5, 13, 29, 34, 89, 169, 194, 233]
def markov(markov_integer):
return math.sqrt((9 * (markov_integer ** 2)) - 4) / markov_integer


Secondly, I'm trying to calculate the Lagrange number via the equation in the quote above, thusly implemented:

def lagrange(markov_number):
return math.sqrt(9 - (4 / (markov_number ** 2)))


Lastly, I merely attempt to do the calculations for each Markoff number:

for i, markov_integer in enumerate(markov_integer):
markov_number = markov(markov_integer)
lagrange_number = lagrange(markov_number)
print(
'index:', i,
'm-integer:', markov_integer,
'm-number:', round(markov_number, 7),
'lagrange:', round(lagrange_number, 7),
'continued fraction:', list(continued_fraction(lagrange_number))[0:5], '...')


But my results are not what I expect. I want to see results that look like this as far as the decimal approximation and continued fraction go:

1.618..., [1; 1, 1, 1, 1, ...]
2.414..., [2; 2, 2, 2, 2, ...]
2.387..., [2; 2, 1, 1, 2, ...]
...


but the results I get from this method is:

index: 0 m-integer: 1 m-number: 2.236068 lagrange: 2.8635642 continued fraction: [2.0, 1.0, 6.0, 3.0, 28.0, ...]
index: 1 m-integer: 2 m-number: 2.8284271 lagrange: 2.9154759 continued fraction: [2.0, 1.0, 10.0, 1.0, 4.0, ...]
index: 2 m-integer: 5 m-number: 2.9732137 lagrange: 2.9236127 continued fraction: [2.0, 1.0, 12.0, 10.0, 1.0, ...]
...


Can you help me discover what step I'm missing in order to get the top n most irrational numbers?