🔢 Continued Fractions

Presets
View
[a0; a1, a2, …]

About Continued Fractions

Every real number can be expressed as a continued fraction: a₀ + 1/(a₁ + 1/(a₂ + 1/(a₃ + …))), where the aₙ are non-negative integers called partial quotients. For rational numbers the expansion terminates; for irrational numbers it continues infinitely. The rational approximations formed by truncating the expansion — called convergents — are the best possible rational approximations to the original number: no fraction with a smaller denominator comes closer. For example, π ≈ 355/113 (from its convergent sequence 3, 22/7, 333/106, 355/113, …) is accurate to 7 significant figures, an approximation known since ancient China.

The golden ratio φ = (1 + √5)/2 has the simplest possible continued fraction: [1; 1, 1, 1, …] — all partial quotients equal 1 — which makes it converge slowest of all irrationals, earning it the title of the "most irrational number". This simulator animates convergents approaching both π and φ and lets you input any number to see its CF expansion.

Frequently Asked Questions

Why are convergents the best rational approximations?

Convergents pₙ/qₙ satisfy the bound |x − pₙ/qₙ| < 1/(qₙ · qₙ₊₁). By Legendre's theorem, any fraction p/q with |x − p/q| < 1/(2q²) must be a convergent of x. This means that among all fractions with denominators up to qₙ, the convergent pₙ/qₙ gives the closest approximation to x — a property exploited in gear ratio design, calendar reform, and antenna array spacing.

What makes φ the "most irrational" number?

By Hurwitz's theorem, every irrational x can be approximated by infinitely many rationals p/q satisfying |x − p/q| < 1/(√5 · q²). The constant √5 is optimal — it cannot be replaced by any larger constant for all irrationals — and the number that forces this bound to be tight is precisely φ. Its all-ones continued fraction [1; 1, 1, 1, …] produces the slowest-growing denominators (Fibonacci numbers), meaning each convergent buys the least improvement in approximation quality.

How are continued fractions used in calendar design?

The tropical year is approximately 365.24219 days. The continued fraction expansion is [365; 4, 7, 1, 3, 5, …], giving convergents 365/1, 1461/4 (the Julian calendar, one leap year per 4), 10592/29, 128953/353 — but the Gregorian calendar uses 97 leap years per 400 years (365 + 97/400 = 365.2425 days), which closely matches the convergent 146097/400. The small residual error means the Gregorian calendar drifts by one day in about 3,030 years.

What is the continued fraction expansion of √2?

√2 = [1; 2, 2, 2, 2, …] — a periodic continued fraction with the repeating block [2]. By Lagrange's theorem, every quadratic irrational (root of a quadratic equation with integer coefficients) has an eventually periodic continued fraction, and conversely. The convergents of √2 are 1/1, 3/2, 7/5, 17/12, 41/29, 99/70, … — these are the Pell-number ratios, and they satisfy pₙ² − 2qₙ² = ±1 (the Pell equation).

How does the Euclidean algorithm relate to continued fractions?

The continued fraction expansion of a rational number a/b is generated directly by the Euclidean algorithm: a = q₀b + r₀, b = q₁r₀ + r₁, r₀ = q₂r₁ + r₂, … The quotients q₀, q₁, q₂, … are exactly the partial quotients aₙ of the continued fraction. This means computing continued fractions and computing GCDs are the same algorithm, and the worst-case input for the Euclidean algorithm is consecutive Fibonacci numbers — again because of the all-ones continued fraction of φ.

What is a generalised continued fraction?

A generalised continued fraction allows the numerators to be values other than 1: a₀ + b₁/(a₁ + b₂/(a₂ + b₃/(…))). Many important mathematical constants have elegant generalised CF representations: π = 4/(1 + 1/(3 + 4/(5 + 9/(7 + 16/…)))) (Brouncker's formula, 1655) and e = 2 + 1/(1 + 1/(2 + 2/(3 + 3/(4 + …)))). These generalisations often converge faster than the standard CF but lose the "best approximation" property.

Are the partial quotients of π random?

The partial quotients of π are [3; 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, …]. The large value 292 at position 4 explains why 355/113 is such an exceptionally good approximation: the next convergent uses 355×292 + 333 = 104,348 in the numerator, making the jump in accuracy enormous. Despite extensive computation of π's partial quotients, no proof exists that they are normally distributed (this is the open problem of whether π is a "normal" number in the CF sense).

What are Farey sequences and how do they connect to continued fractions?

The Farey sequence Fₙ is the ascending sequence of all reduced fractions with denominators ≤ n in [0, 1]. Adjacent fractions a/b and c/d in Fₙ satisfy the mediant property |bc − ad| = 1 and their mediant (a+c)/(b+d) is the next fraction to be inserted as n grows. The Stern-Brocot tree, which enumerates all positive rationals exactly once, is built entirely from mediants, and the path to any fraction in the tree is encoded by its continued fraction expansion — left branches correspond to the partial quotients.

How do continued fractions help design gear trains?

When designing a gear train to achieve a precise speed ratio, continued fractions find the smallest-tooth-count approximation within a specified error. For example, to approximate the ratio 1 year/1 day ≈ 365.24219, the convergents 4/1 (rough), 29/8 (better), 97/27, 365/100 suggest practical gear combinations. Antique astronomical clocks and orreries used continued-fraction analysis to choose tooth counts that keep the mechanical calendar in sync with the solar year over decades.