Continued Fractions Calculator: expansion, convergents, √ periodic

Continued fraction expansion of rationals, reals, √n and rational approximations (convergents) of π, e, φ. Four modes of useful number theory with examples.

Calculation parameters
Was this calculator useful?

Continued fractions: the perfect number representation

A simple continued fraction is an expression of the form a₀ + 1/(a₁ + 1/(a₂ + 1/(a₃ + ...))), abbreviated [a₀; a₁, a₂, a₃, ...], where a₀ is an integer and a₁, a₂, ... are positive integers. Systematically introduced by Euler (1737) and Lagrange, they provide the "most natural" representation of a real number: rationals give finite expansions, quadratic irrationals give periodic expansions (Lagrange), other irrationals give infinite non-periodic expansions (π, e). Every rational has exactly two representations ([...,n] or [...,n−1, 1]); for uniqueness the last term must be > 1.

Expansion algorithm (Euclidean)

Given x ∈ ℝ: a₀ = ⌊x⌋ (integer part); r = x − a₀; if r = 0 stop. Else x ← 1/r and repeat. For rationals p/q this is the Euclidean algorithm: a₀ = ⌊p/q⌋, then work on the reciprocal of the remainder. Example 355/113: 355 = 3·113 + 16, q₀=3; 113 = 7·16 + 1, q₁=7; 16 = 16·1 + 0, q₂=16. Hence 355/113 = [3; 7, 16]. Value 3 + 1/(7 + 1/16) = 3 + 16/113 = 355/113 ✓. Famous Chinese π approximation (Zu Chongzhi, 5th century).

Convergents and rational approximations

Convergents p_n/q_n are fractions obtained by truncating the continued fraction after n terms. Recursive formula: p_n = a_n·p_{n−1} + p_{n−2}, q_n = a_n·q_{n−1} + q_{n−2}, with p_{−1}=1, p_0=a₀, q_{−1}=0, q_0=1. Convergents alternate above and below x, converging rapidly: |x − p_n/q_n| < 1/(q_n·q_{n+1}). Example π: [3; 7, 15, 1, 292, 1, 1, ...]. Convergents: 3, 22/7 (error 0.04%), 333/106 (0.003%), 355/113 (10⁻⁷), 103993/33102 (10⁻¹⁰). Best approximations among all p/q with q_n ≤ q.

Quadratic irrationals and periodicity (Lagrange)

Lagrange's theorem (1770): the continued fraction of √n (n non-square) is periodic, with period made of positive integers. Examples: √2 = [1; 2, 2, 2, ...] = [1; 2̄] (period 1); √3 = [1; 1̄, 2] (period 2); √5 = [2; 4̄]; √7 = [2; 1̄, 1, 1, 4]; √19 = [4; 2̄, 1, 3, 1, 2, 8]. The period always ends with 2·a₀. Golden ratio φ = (1+√5)/2 = [1; 1, 1, 1, ...] = [1̄]: the slowest possible convergence (worst rationally approximable).

Continued fractions of notable numbers

Golden ratio φ = [1; 1, 1, 1, ...], convergents = F_{n+1}/F_n (Fibonacci). Euler's number e = [2; 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, ...] (pattern 1, 2k, 1). Number π = [3; 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, ...] no known pattern. Khintchine's constant K ≈ 2.685: for "almost all" irrationals, the geometric mean of their a_i tends to K. Liouville numbers (very large quotients) are transcendental; algebraic numbers of degree d have bounded quotients (Thue-Siegel-Roth).

Applications

Astronomical calendar (solar year 365.242... → Metonic cycle 19 years = 235 lunations via convergent); piano models (12-tone equal temperament = log₂(3/2) ≈ [0; 1, 1, 2, 2, 3, 1, 5, ...] convergent 7/12 = octave divided in 12); Diophantine Pell x² − ny² = 1 solved via continued fraction of √n; cryptography (Wiener's RSA attack: if d < n^(1/4)/3, d/e ≈ convergent of continued fraction); compression (LZW encoding rationals); network routing; music theory (Pythagoras, non-octave tuning systems).

How to use

Select mode: Rational (p/q → [a₀; a₁, a₂, ...]), Evaluate (CSV list of a_i → rational value p/q), Square root (non-square n → periodic expansion of √n), Convergents (real number, e.g. π, e, φ → successive convergents). Numeric or symbolic input (pi, e, phi) accepted.

A centuries-long history, from India to Europe

Continued fractions already appear in Euclid's algorithm (3rd century BC) and in the work of Indian mathematicians such as Aryabhata, but their systematic theory was developed in the 17th and 18th centuries by Pietro Cataldi in Bologna, John Wallis in England and above all Leonhard Euler and Joseph-Louis Lagrange. Euler proved that the number e has the continued fraction [2; 1, 2, 1, 1, 4, 1, 1, 6, …] with a regular pattern, and Lagrange proved that quadratic irrationals have a periodic expansion.

Applications: from calendars to gears

The best rational approximations given by convergents have surprising practical uses. The Gregorian calendar approximates the solar year (365.2422 days) with the fraction that generates the leap-year rule. In precision mechanics, gear-tooth ratios are chosen among convergents to obtain transmission ratios close to an irrational value with small wheels. In astronomy, orbital resonances of planets and satellites are described by simple rational ratios, themselves convergents of continued fractions.

Updated July 2026

Comments (0)

No comments yet. Be the first!