Signal and Sensation

The Best Fraction

22/7 is not just close to π. Nothing with a smaller denominator is closer, and there is a machine that finds such fractions.

Open fullscreen →

What it is

The continued fraction of a number, its successive best approximations, and a brute-force search climbing through every denominator to check them. The brute-force answer is always one of the convergents. Always.

Switch between π, √2, e and φ.

How it works

Any number can be written as a whole part plus one over another such expression, repeating. π is [3; 7, 15, 1, 292, ...]. Truncating that expansion at each step gives 3, 22/7, 333/106, 355/113, and each of those is the closest fraction to π with a denominator that size or smaller. That’s a much stronger statement than merely being close.

The page proves it the dull way. A loop tries every denominator up to a growing limit, keeping whichever fraction is nearest, and its answer only ever changes at a convergent. There’s a test that does the same thing exhaustively for four different irrationals.

That’s also why 22/7 lasted two millennia. Nothing with a denominator under 57 beats it, and the fraction that finally does, 179/57, isn’t an improvement anyone would notice.

What surprised me

I wanted to measure which number is hardest to approximate. The natural quantity is the error times the denominator squared, since every irrational has convergents where that’s small, and a number resists approximation if it can’t be made small.

So I took the minimum over the convergents and got an answer for φ that was better than the theoretical best possible. Nonsense on its face.

Looking at the sequence explained it. For φ, error × d² goes 0.472, 0.438, 0.451, 0.446, 0.4477, 0.4470, 0.4473. It oscillates around 1/√5 = 0.44721 and converges to it. I’d assumed monotone approach. The second convergent, 5/3, dips to 0.438, genuinely below the limit the sequence settles at, and a naive minimum reports that transient as the answer.

The quantity that means something is the limit, not the smallest value ever seen. Skipping denominators under ten gives 0.44701 for φ, against 0.353 for √2, 0.091 for e and 0.0034 for π. π is a thousand times easier to approximate than φ is, entirely because 355/113 is freakishly good.

That’s the same fact as day 31 arriving from the other side. φ is the number whose fractions are worst, so a turn of φ of a circle is the turn that least resembles any simple repeat, so sunflower seeds using it never line up into spokes.

What I would do next

The Stern-Brocot tree, where every fraction appears exactly once and the convergents are the path you take to reach a number.