Continued Fraction

6 min read#number-theory

A representation of a real number as a nested stack of fractions, yielding the best possible rational approximations.

Contents

Continued Fraction

A continued fraction writes a number as an integer plus a fraction whose denominator is itself an integer plus a fraction, nested down as far as you like:

x = a_0 + \cfrac{1}{a_1 + \cfrac{1}{a_2 + \cfrac{1}{a_3 + \cdots}}}.

The list of integers [a_0; a_1, a_2, a_3, \dots] is the number. This unusual notation turns out to give the best rational approximations any number can have — better, in a precise sense, than the decimal system ever could.

How to build one

The algorithm is pure Euclidean algorithm in disguise. Take the whole-number part, subtract it off, flip the remainder, and repeat:

\tfrac{45}{16} = 2 + \tfrac{13}{16} = 2 + \cfrac{1}{16/13} = 2 + \cfrac{1}{1 + \cfrac{3}{13}} = 2 + \cfrac{1}{1 + \cfrac{1}{4 + \cfrac{1}{3}}}.

So \frac{45}{16} = [2; 1, 4, 3]. The integers 2, 1, 4, 3 are exactly the quotients Euclid's algorithm produces for \gcd(45, 16) — the continued fraction and the gcd are the same computation read two ways. For a rational number the list always terminates; for an irrational it runs forever.

Convergents: the best approximations

Truncating the list early gives a convergent — a rational that approximates x. The remarkable theorem is that each convergent is the best possible rational approximation for its size of denominator: no fraction with a smaller denominator gets closer.

Convergents of π = [3; 7, 15, 1, 292, …] closing in on the true value. Each bar is one convergent p/q; its height is the error |p/q − π| on a log scale. Watch 22/7, then 333/106, then 355/113 — each a leap closer. Click to cycle through π, the golden ratio, and √2.

For \pi, the convergents are 3,\ \frac{22}{7},\ \frac{333}{106},\ \frac{355}{113}, \dots The third, \frac{355}{113}, matches \pi to six decimal places using a three-digit denominator — an approximation so good it was known in 5th-century China.

The golden ratio: the worst-approximable number

The continued fraction also tells you which numbers are hardest to approximate by rationals. A large entry a_i means the previous convergent was already excellent (you barely needed the next term). So the number that is least approximable is the one with the smallest possible entries everywhere — all 1s:

\varphi = 1 + \cfrac{1}{1 + \cfrac{1}{1 + \cfrac{1}{1 + \cdots}}} = [1; 1, 1, 1, \dots] = \frac{1+\sqrt 5}{2}.

This is the golden ratio. Its all-ones expansion makes it the most stubbornly irrational number there is — a fact that explains why sunflower seeds and pinecones space their spirals by the golden angle: it is the packing least prone to settling into a repeating, gappy rational pattern.

Why is the golden ratio φ = [1; 1, 1, 1, …] called the 'most irrational' number?

See also