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