Continued Fractions: The Best Way to Approximate Any Number
Imagine you need to represent π as a simple fraction — not for a math exam, but to build a physical clock, cut a gear, or tune a musical instrument. 22/7 comes to mind, and it's pretty good, accurate to within 0.04%. But 355/113 is almost shockingly better: it matches π to six decimal places, yet uses a denominator smaller than the number of days in a year. How does anyone find fractions that punch that far above their weight?
The answer is continued fractions — an ancient idea with a surprisingly modern grip on mathematics, engineering, and even cryptography. They are, in a precise mathematical sense, the best rational approximations any number can have.
The Concept
A continued fraction is what you get when you take a number and express it as an integer plus the reciprocal of another integer plus the reciprocal of another, and so on, nesting inward like a set of Russian dolls:
> a₀ + 1/(a₁ + 1/(a₂ + 1/(a₃ + ...)))
Those integer values a₀, a₁, a₂, … are called partial quotients, and they are always positive integers. Mathematicians write the whole thing compactly as [a₀; a₁, a₂, a₃, …].
The connection to arithmetic you already know is immediate: computing a continued fraction is literally the Euclidean algorithm, the ancient procedure for finding greatest common divisors. Take a number, extract its integer part, flip the remainder upside down, repeat. When the remainder hits zero, you stop — and a rational number always does, giving a finite continued fraction. An irrational number goes on forever.
The finite truncations at each step are called convergents, and this is where the magic lives. Each convergent p_n/q_n is a rational approximation to the original number. And not just any approximation — the theorem says: no fraction with a denominator ≤ q_n gets closer to x than p_n/q_n does. To beat a convergent, you must pay a higher denominator cost. They are the most efficient possible approximations, squeezing the maximum accuracy out of the smallest denominators.
Why It Matters
The 355/113 Mystery Explained
Take π = 3.14159265... Its continued fraction is [3; 7, 15, 1, 292, 1, 1, 1, 2, ...]. The first few convergents are:
- [3] = 3/1 — off by 0.14, obviously rough
- [3; 7] = 22/7 — accurate to 2 decimal places; everyone knows this one
- [3; 7, 15] = 333/106 — accurate to 4 decimal places
- [3; 7, 15, 1] = 355/113 — accurate to 6 decimal places
Why does 355/113 perform so extraordinarily well? Notice the next partial quotient: 292. A large partial quotient means the next convergent will make a giant leap in accuracy, which means the current convergent is already very close. The fraction 355/113 is so good that the next fraction to beat it — 103993/33102 — requires a denominator almost 300 times larger. No fraction with a denominator between 114 and 33101 is more accurate than 355/113. It stands alone in that range.
This fraction was known to the Chinese astronomer Zu Chongzhi in the 5th century AD, over a thousand years before European mathematicians systematized the theory. He called it milü, meaning 'close ratio.'
The Golden Ratio Is the Hardest Number to Approximate
At the opposite extreme, consider the golden ratio φ = (1 + √5)/2 ≈ 1.618... Its continued fraction is [1; 1, 1, 1, 1, ...] — the simplest possible: all ones, forever.
Small partial quotients mean slow convergence. Every convergent of φ makes the smallest possible accuracy improvement. The convergents are the ratios of consecutive Fibonacci numbers: 1/1, 2/1, 3/2, 5/3, 8/5, 13/8, 21/13, ... They creep toward φ as slowly as any fraction sequence can.
This is the rigorous meaning of the poetic claim that φ is the 'most irrational' number. The Hurwitz theorem states that for any irrational x, the inequality |x − p/q| < 1/(√5 · q²) has infinitely many rational solutions p/q. The constant √5 is the tightest possible — and the only number that saturates it (that makes the bound unimprovable) is φ itself. It is the irrational number that rational fractions pin down most slowly.
The Details
Two Thousand Years of History
Continued fractions have deep roots. The ancient Greeks used what they called 'anthyphairesis' — alternating subtraction — which is equivalent to computing the Euclidean algorithm, and they applied it to understand the ratio √2. Pietro Cataldi (1548–1626) introduced the first formal notation for continued fractions. John Wallis coined the term 'continued fraction' in his 1655 work Arithmetica Infinitorum.
The real flowering came in the 18th century. Leonhard Euler laid down the modern theory in his 1737 paper De Fractionibus Continuis, showing — among many things — that the continued fraction of e = 2.71828... has a beautiful regular pattern: [2; 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, ...]. The partial quotients follow the rhythm 1, 2k, 1, 1, 2k+2, 1, 1, ... — every third term is an even number, growing without bound. It is one of the most elegant closed forms in mathematics, and there is no comparably clean formula for π's continued fraction. Joseph-Louis Lagrange completed another landmark in 1770: a number has an eventually repeating continued fraction if and only if it is a quadratic irrational (a root of a degree-2 polynomial with integer coefficients). So √2 = [1; 2, 2, 2, ...] repeats perfectly; π and e, being transcendental, do not.
Huygens Builds the Solar System
In the 1680s, Christiaan Huygens was building a mechanical planetarium — a clockwork model of the solar system. He needed gears to turn at exactly the right relative speeds. Saturn takes about 29.46 years to orbit the Sun; Earth takes 1. He needed a gear ratio of 29.46:1. The exact decimal expansion is 2946/100 = 1473/50, but a gear with 1,473 teeth and one with 50 teeth would be large and impractical.
The continued fraction of 29.46 = [29; 1, 2, 1, 5, ...] gives convergents 29/1, then 30/1, then 89/3, then 206/7. That last one is the key: a 7-tooth gear meshing with a 206-tooth gear gives a ratio of 29.43 — close enough for a working planetary model. No gear pair with fewer teeth does better. Huygens' posthumously published Descriptio Automati Planetarii (1703) is the first recorded engineering application of continued fraction theory.
The Calendar Problem
How many days are in a year? About 365.2422. The fractional leftover 0.2422 needs to be approximated by a ratio: every n years, add m leap days. The continued fraction of 0.2422 is [0; 4, 7, 1, 3, ...].
The convergents are: 1/4 (add one leap day every 4 years — the Julian calendar), then 7/29, then 8/33 (the Persian solar calendar, which is actually more accurate than the Gregorian!), then 31/128. The Gregorian calendar uses 97/400 — 97 leap years every 400 years — which is a semi-convergent, not quite on the convergent sequence but a good nearby rational. Every major calendar reform in history was, implicitly, an exercise in continued fractions.
Music Theory and the Perfect Fifth
Here is a fact that surprises musicians: the 12-note equal-tempered scale is optimal in a continued-fraction sense.
A perfect fifth has a frequency ratio of 3:2. To fit whole-number multiples of perfect fifths into whole-number multiples of octaves (ratio 2:1), you need to solve 2^a ≈ (3/2)^b, or equivalently b × log₂(3/2) ≈ a. Since log₂(3/2) ≈ 0.585 is irrational, this is an approximation problem.
The continued fraction of log₂(3/2) = [0; 1, 1, 2, 2, 3, 1, 5, 2, 23, ...] gives convergents 1/1, 1/2, 3/5, 7/12, 24/41, 31/53, .... The denominator 12 corresponds to the 12-tone chromatic scale — the standard Western system. The next good one is 53, used in Ottoman classical music. These are the only equal-tempered systems where fifths land close to the true 3:2 ratio; continued fractions tell you exactly why.
Breaking RSA Encryption
In 1990, cryptographer Michael Wiener discovered a surprising attack on RSA encryption. If the private key d is small — specifically, less than N^(1/4)/3 where N is the public modulus — then d can be recovered by computing convergents of the continued fraction expansion of e/N (where e is the public exponent). The private key appears as a numerator of one of those convergents.
This is called the Wiener attack, and it forced RSA implementers to abandon small private exponents entirely. A mathematical curiosity about optimal rational approximation quietly imposed a constraint on internet security.
The Stern-Brocot Tree
One more beautiful structure: the Stern-Brocot tree, invented independently by mathematician Moritz Stern and French clockmaker Achille Brocot in the 19th century. It is a binary tree that lists every positive rational number exactly once, in lowest terms, in sorted order. Every rational appears at exactly one position in the tree, and its path from the root — left (L) or right (R) at each step — encodes its continued fraction expansion. Brocot, like Huygens, was a craftsman using these ideas to choose gear ratios.
A Universal Statistical Law
Here is perhaps the most surprising fact of all. Pick a random real number. Look at its partial quotients a₁, a₂, a₃, ... Take their geometric mean as you include more and more of them. Where does it converge?
For almost every real number (with probability 1, in the measure-theoretic sense), the geometric mean of partial quotients converges to Khinchin's constant, K₀ ≈ 2.6854520010..., named after Russian mathematician Aleksandr Khinchin who proved this in 1934. About 41% of partial quotients are 1s, about 17% are 2s, and so on — a universal frequency distribution called the Gauss-Kuzmin distribution. It does not matter which specific irrational you start with. The statistical behavior is the same.
We do not know whether π or e obey Khinchin's theorem — both are almost certainly 'normal' in this sense, but it has never been proven for either.
Takeaways
- A continued fraction is a nested chain of integer divisions that produces the most efficient rational approximations possible — no fraction with a smaller denominator gets closer.
- Computing a continued fraction is the Euclidean algorithm in disguise — the ancient tool for greatest common divisors secretly generates optimal approximations.
- Large partial quotients are the key to 'superstar' fractions like 355/113 for π: a big partial quotient means the current convergent is already nearly as good as fractions with much larger denominators.
- The golden ratio φ = [1; 1, 1, 1, ...] has all-ones partial quotients and is the hardest number to approximate — it stands at the outer boundary of what rational fractions can reach.
- Continued fractions quietly underpin calendar design, clockmaking, musical tuning, and internet security — four fields that seem to have nothing in common until you look for the fractions.
Resources: - Plus Maths: Chaos in Numberland — an excellent accessible deep-dive into continued fractions and their applications - Wolfram MathWorld: Continued Fraction — rigorous definitions and extensive worked examples - Euler's original 1737 paper De Fractionibus Continuis is available in translation and is more readable than you might expect