Number theory MOC

Simple continued fraction

A (simple) continued fraction for a real number 𝛼 is an expression of the form

𝛼=[𝑎0;𝑎1,𝑎2,]=𝑎0+1𝑎1+1𝑎2+.

where 𝑎𝑖 , More precisely, 𝛼 =lim𝑛𝛼𝑛, where the 𝑛th convergent

𝛼𝑛=[𝑎0;𝑎1,,𝑎𝑛]=𝑝𝑛𝑞𝑛

where there are defined by the recurrence relations

𝑝2=0,𝑝1=1,𝑝𝑛=𝑎𝑛𝑝𝑛1+𝑝𝑛2𝑞2=1,𝑞1=𝑎0,𝑞𝑛=𝑎𝑛𝑞𝑛1+𝑞𝑛2
Sage

The methods .p and .q correspond to the notation given above

K.<α> = QuadraticField(223)
continued_fraction(α) 
# [14; (1, 13, 1, 28)*]
continued_fraction(α).p(1) 
# 209
continued_fraction(α).q(1) 
# 14
continued_fraction(α).convergent(2) 
# 209/14


#state/develop | #lang/en | #SemBr