← LibraryContinued Fraction Expansion of Real NumbersEngineering · MathematicsLesson 219/385← PrevNext →
ArticlePublished 7 Aug 20262 min readBy Kevin Jogincontinued fractionsconvergentsquadratic irrationalDiophantine approximation

Euclidean Algorithms and Congruences

Continued Fraction Expansion of Real Numbers

Continued fractions, convergents as best rational approximations, and the periodic expansion of quadratic irrationals.

Engineering / MathematicsEuclidean Algorithms and Congruences2 min readKV-MATH-0517

Continued fractions are the Euclidean algorithm applied to real numbers. They produce the best rational approximations available for a given denominator, and for quadratic irrationals they become periodic — which is the key to real quadratic field computation.

The expansion

x = a_0 + 1/(a_1 + 1/(a_2 + 1/(a_3 + ...)))The partial quotients a_i are obtained by repeatedly taking the integer part and inverting the remainder.

Computing the expansion

  1. Take integer partThe floor of the current value is the next partial quotient.
  2. SubtractRemove the integer part, leaving a value in the unit interval.
  3. InvertTake the reciprocal and repeat.

Convergents

Truncating the expansion gives the convergents, computed by a simple recurrence on numerators and denominators.

p_n = a_n p_(n-1) + p_(n-2), q_n = a_n q_(n-1) + q_(n-2)Started from the conventional initial values.

Quadratic irrationals

The expansion of a quadratic irrational is eventually periodic, and for the square root of a non-square integer it is purely periodic after the first term with a palindromic structure.

Why periodicity matters computationally
PropertyConsequence
PeriodicityThe expansion can be computed and stored exactly
Palindromic periodHalves the work; the second half mirrors the first
Period end detectionSignals a solution to the Pell equation
Convergents at period endGive the fundamental unit of the real quadratic field

Precision

Source. Henri Cohen, A Course in Computational Algebraic Number Theory, Springer GTM 138 — 1.3.5. Structural reference unverified: the source file was not available during authoring; chapter and section numbers are taken from the published edition and have not been checked against a physical copy.

Continue learning

Chinese Remainder Theorem AlgorithmsArticle · MathematicsNEXT LESSON →Structure of the Unit Group Modulo nArticle · MathematicsThe Extended Euclidean Algorithm and Bezout CoefficientsArticle · MathematicsLegendre, Jacobi and Kronecker Symbol ComputationArticle · Mathematics