Every real number can be expressed as a continued fraction [a₀; a₁, a₂, …]. The finite truncations, called convergents, are the best rational approximations to the number — no fraction with equal or smaller denominator gets closer.
p_n = a_n * p_{n-1} + p_{n-2}
q_n = a_n * q_{n-1} + q_{n-2}
|x - p_n/q_n| < 1 / (q_n * q_{n+1})
det([[p_n, p_{n-1}],[q_n, q_{n-1}]]) = (-1)^n
The golden ratio φ = [1; 1, 1, 1, …] is the hardest number to approximate by rationals — its convergents are ratios of consecutive Fibonacci numbers (1/1, 2/1, 3/2, 5/3, 8/5, …). A sunflower's spiral count is always a Fibonacci number for this reason!
A continued fraction is an expression a₀ + 1/(a₁ + 1/(a₂ + …)) where a₀ is an integer and each aₙ (n ≥ 1) is a positive integer. Every real number has such an expansion, and it is finite if and only if the number is rational.
Convergents pₙ/qₙ are the rational numbers obtained by cutting off the continued fraction after n steps. They converge alternately from above and below to the target number, and they are provably the best rational approximations — no fraction with denominator ≤ qₙ comes closer to x.
The horizontal axis shows the real number line (or a zoomed window around the target). Each convergent p/q is plotted as a vertical tick, coloured by iteration. As more terms are added the ticks alternate above/below and get exponentially closer to the red target line, illustrating the "best approximation" property visually.
Because φ satisfies φ = 1 + 1/φ, so the continued fraction literally repeats itself as [1; 1, 1, 1, …]. This means its convergents (Fibonacci ratios) converge as slowly as possible — making φ the "most irrational" number.
It is a binary tree containing every positive rational exactly once. Starting from 0/1 and 1/0 as sentinels, each new node is the mediant (a+c)/(b+d) of its two neighbours. The path to any rational encodes its continued fraction: going right means incrementing the current partial quotient, going left starts a new term.
Exponentially fast. Since qₙ grows at least as fast as Fibonacci numbers (doubling roughly every 1.44 steps), the error |x − pₙ/qₙ| < 1/qₙ² shrinks like φ^{-2n}. Large partial quotients cause even faster convergence at that step.
A large aₙ means the previous convergent p_{n-1}/q_{n-1} was already a very good approximation. The classic example is π: after [3; 7, 15, 1] the next term is 292, meaning 355/113 is an astonishingly good approximation to π (error < 3×10⁻⁷).
By Dirichlet's theorem, every irrational number has infinitely many fractions p/q satisfying |x − p/q| < 1/q². But Liouville numbers (like 0.110001000000000000000001…) are transcendental precisely because they are too well approximated. The irrationality measure quantifies how well a number can be approximated.
The solar year is approximately 365.2422 days. The continued fraction [365; 4, 7, 1, 3, …] gives convergents 365/1 (Julian), 1461/4 (still Julian 4-year cycle), 4748/13 (unused), and then the Gregorian correction: 97 leap years in 400 gives 365 + 97/400 = 146097/400 ≈ 365.2425, one step away from optimal.
The error chart plots |x − pₙ/qₙ| on a logarithmic vertical axis against convergent index n. Since each step reduces error by roughly a factor of qₙ, the points fall roughly along a straight line on the log scale, with occasional sharp drops when a large partial quotient appears.
Between consecutive convergents pₙ/qₙ and p_{n+1}/q_{n+1}, there are intermediate fractions (pₙ + k·p_{n+1})/(qₙ + k·q_{n+1}) for k = 1, …, aₙ−1 called semiconvergents. Some are best approximations of the first kind (no fraction with smaller denominator is closer) but not of the second kind. The simulation highlights them when you hover over a row.
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.
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.
√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).
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 φ.
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.
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).
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.
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.