Number

Every fraction, exactly once

Take two fractions, add the tops and add the bottoms. That is not how fractions are added, it is not an average, and repeating it produces every positive rational exactly once, already in lowest terms.

Worth reading first: A fraction that never closes.

Adding the numerators and adding the denominators is the classic schoolroom error. 12\tfrac12 and 13\tfrac13 do not make 25\tfrac25. What that operation does make is worth an essay.

The Stern–Brocot tree to depth 4Every positive rational, each appearing exactly once, generated by taking mediants.11122113233231142535344353524115 fractions, all in lowest terms, none of them twiceand left to right they are already in order
Fig. 1 The Stern–Brocot tree. Every node is the mediant of its two nearest ancestors on either side — add the tops, add the bottoms — starting from 01\tfrac01 and 10\tfrac10. Every fraction arrives already in lowest terms, none arrives twice, and reading the drawing left to right reads them in increasing order. The generator checks all three.

The operation is called the mediant: from pq\tfrac{p}{q} and rs\tfrac{r}{s} it makes p+rq+s\tfrac{p+r}{q+s}. It is not addition and it is not an average, and unlike either of those it depends on how the fractions are written — 12\tfrac12 and 24\tfrac24 are the same number with different mediants. That looks like a fatal defect and is the source of everything below, because the construction never presents it with a fraction that is not in lowest terms.

The mediant does have one honest property: it lies strictly between its parents. If pq<rs\tfrac{p}{q} < \tfrac{r}{s} then

pq<p+rq+s<rs,\frac{p}{q} < \frac{p+r}{q+s} < \frac{r}{s},

which follows from cross-multiplying twice. So repeatedly taking mediants fills in the gaps between fractions already present, and never leaves the interval it started in.

The Stern–Brocot tree to depth 3Every positive rational, each appearing exactly once, generated by taking mediants.111221132332317 fractions, all in lowest terms, none of them twiceand left to right they are already in order
Fig. 2 The first three levels alone. 11\tfrac11 is the mediant of the two starting symbols; 12\tfrac12 and 21\tfrac21 are the mediants of 11\tfrac11 with each of them; and the third level fills the four gaps those left. Nothing on any level is a repeat of anything on any other.

Two things about that figure are worth pinning down before going further, because both are surprising and neither is obvious from the rule. Every fraction that appears is in lowest terms — no 24\tfrac24, no 36\tfrac36 — and no fraction appears twice, at any depth, ever. Neither property was designed in. Both fall out of a single identity.

The fence at the right-hand end

The tree above starts from 01\tfrac01 and 10\tfrac10, and the second of those is not a number. It is a fence: a formal symbol that behaves correctly under the mediant operation and is never evaluated. Its mediant with 01\tfrac01 is 11\tfrac11, which is right, and every subsequent use of it produces something sensible.

This is the only place in this collection where a fraction with denominator zero is allowed to stand, and it earns its place. Without it the construction needs an upper bound and produces only the fractions below that bound; with it the tree covers every positive rational and nothing has to be said about where to stop. The symbol is doing the job that a point at infinity does in the plane extended by one point — closing a construction that would otherwise have a ragged edge — and the resemblance is not a coincidence, since both are the same rational point on a projective line.

Why nothing needs cancelling

The remarkable property of the tree is that no fraction ever needs reducing. 24\tfrac{2}{4} never appears; 12\tfrac12 appears once, at the root’s left child, and 24\tfrac{2}{4} appears nowhere at all.

The reason is a determinant. Call two fractions pq\tfrac{p}{q} and rs\tfrac{r}{s} neighbours when

rqps=1.rq - ps = 1.

The starting pair 01\tfrac01 and 10\tfrac10 are neighbours: 1100=11 \cdot 1 - 0 \cdot 0 = 1. And if pq\tfrac{p}{q} and rs\tfrac{r}{s} are neighbours, then each of them is a neighbour of their mediant:

(p+r)qp(q+s)=rqps=1.(p+r)q - p(q+s) = rq - ps = 1.

So the neighbour relation propagates down the tree, and every node is a neighbour of both its parents forever.

Now the cancelling follows in one line. If a common factor dd divided both p+rp+r and q+sq+s, it would divide (p+r)qp(q+s)=1(p+r)q - p(q+s) = 1, so d=1d = 1. Being in lowest terms is not checked, arranged or maintained: it is a consequence of a determinant that the construction preserves by accident of its own arithmetic.

The same fractions, laid out flat

The tree can be flattened by taking all the fractions with denominators up to some bound.

The Farey sequence of order 7Every fraction in the unit interval with denominator at most n, marked on a line.0/11/71/61/51/42/71/32/53/71/24/73/52/35/73/44/55/66/71/11/82/93/103/84/95/95/87/107/97/819 fractions, and every neighbouring pair has p′q − pq′ = 1the fraction under each arc is the mediant — the next one to appear as the order rises
Fig. 3 The Farey sequence of order seven: every fraction in the unit interval with denominator at most seven. Under each arc is the mediant of the two fractions it joins — the fraction that will appear between them as soon as the order is raised far enough to admit it. The generator checks the determinant on every neighbouring pair, and counts the sequence against the totient sum.
The Farey sequence of order 5Every fraction in the unit interval with denominator at most n, marked on a line.0/11/51/41/32/51/23/52/33/44/51/11/62/73/83/74/75/85/75/611 fractions, and every neighbouring pair has p′q − pq′ = 1the fraction under each arc is the mediant — the next one to appear as the order rises
Fig. 4 Two orders lower. Comparing this with the sequence above shows exactly which fractions the raise admits: those with denominator six and seven, and each of them appears in the gap between the two fractions whose mediant it is. Nothing else moves.

Farey sequences and the Stern–Brocot tree are the same object organised differently: the tree is ordered by when a fraction arrives, the sequence by where it sits. Going from FnF_n to Fn+1F_{n+1} inserts exactly the mediants whose denominator is n+1n+1, and inserts nothing else, which is the sense in which the tree’s levels and the sequence’s orders interleave.

The length of FnF_n counts something, and counting it two ways is the standard first exercise. Each fraction p/qp/q in lowest terms with qnq \le n is counted once; grouping by denominator gives 1+qnφ(q)1 + \sum_{q \le n} \varphi(q), where φ(q)\varphi(q) counts the numbers below qq that are coprime to it. The two counts are of the same list, so the identity is forced — and it is the same counting-one-thing-twice move that runs through the rest of this field.

Circles that touch

There is a picture of the Farey sequence that has no business working as well as it does.

Ford circles up to denominator 7A circle of diameter one over q squared resting on each fraction p over q; neighbours touch.0/11/31/22/31/1each circle has diameter one over its denominator squared, and rests on its own fractiontwo circles touch exactly when the fractions are Farey neighbours — nothing overlaps anywhere
Fig. 5 Ford circles: on each fraction p/qp/q, a circle of diameter 1/q21/q^2 resting on the line. Two circles touch exactly when the fractions are Farey neighbours, and no two circles ever overlap. The generator measures the distance between neighbouring centres and requires it to equal the sum of the radii, to within a billionth of a pixel.

Take the circles on pq\tfrac{p}{q} and rs\tfrac{r}{s}, with centres (p/q,1/2q2)(p/q, 1/2q^2) and (r/s,1/2s2)(r/s, 1/2s^2). The squared distance between the centres is

(pqrs)2+(12q212s2)2,\left(\frac{p}{q} - \frac{r}{s}\right)^2 + \left(\frac{1}{2q^2} - \frac{1}{2s^2}\right)^2,

and the squared sum of the radii is (12q2+12s2)2\left(\frac{1}{2q^2} + \frac{1}{2s^2}\right)^2. Subtracting and clearing denominators, the two are equal exactly when (psrq)2=1(ps - rq)^2 = 1 — the determinant again, now as a statement about tangency.

So a fact about arithmetic and a fact about geometry are the same fact. That is the surprise this essay is built around: the determinant that keeps fractions in lowest terms is the condition for two circles to touch, and the size of a fraction’s circle is decided by the denominator that makes the arithmetic work. Nothing about the construction of the tree suggested a picture like this existed.

The circles also explain, at a glance, why good rational approximations are scarce. A number on the line is approximated well by p/qp/q when it sits under a large circle; large circles have small denominators; and the circles fill the strip without overlapping, so there is only so much room. How close a fraction can get makes that argument exactly.

The path is a continued fraction

Each node in the tree is reached by a sequence of left and right turns. Writing those turns down — LLRL\mathrm{L}\mathrm{L}\mathrm{R}\mathrm{L}, and so on — gives a code for the fraction, and the code is not new.

Group the turns into runs: three lefts, then two rights, then one left. The run lengths are the continued fraction expansion. The fraction 53=[1;1,2]\tfrac{5}{3} = [1; 1, 2] sits at RLRR\mathrm{R}\mathrm{L}\mathrm{R}\mathrm{R}, whose runs are 1,1,21, 1, 2.

5/3 as a continued fractionThe nested fraction, one quotient per step, descending to the right.=5/31 +11 +12[1; 1, 2] — and it stops, because the ratio is a ratio
Fig. 6 The tower for 53\tfrac53. Its three quotients — 11, 11, 22 — are the lengths of the three runs of turns that reach it in the tree, and neither construction was built with the other in mind.

That is the second time in two essays that the same sequence of quotients has appeared from a construction that did not mention it. The tree is built by mediants and knows nothing about Euclid’s algorithm; the algorithm peels squares and knows nothing about trees. They agree because both are recording the same thing — how many times one quantity fits inside another before the roles swap — and each step of the algorithm is a run of turns in one direction.

The golden ratio, whose expansion is all ones, is the path that alternates LRLR\mathrm{L}\mathrm{R}\mathrm{L}\mathrm{R} forever: the most balanced possible descent, never committing to a side. Its convergents are the Fibonacci fractions and they are the nodes this alternating path passes through.

Where the mediant is the right operation

The mediant is the wrong way to add fractions and the right way to combine two ratios of counts, and confusing the two is the source of a well-known statistical paradox.

A player with 33 hits from 1010 attempts and then 11 hit from 33 attempts has a season record of 44 hits from 1313 attempts. That is the mediant of 310\tfrac{3}{10} and 13\tfrac13, and it is correct: the totals really do add separately, because a hit is a hit and an attempt is an attempt. Nothing is being averaged.

Now suppose a second player beats the first in both halves of the season — a better ratio in the first, a better ratio in the second — and loses on the year. That is not a contradiction, because the mediant is not monotone in the way an average is: it slides towards whichever parent has the larger denominator. If the second player’s attempts are concentrated in the half where everybody’s ratio is low, the mediant drags their season figure down and nothing was measured wrongly.

This is Simpson’s paradox, and the drawing at the top of this essay is a picture of why it happens. The mediant sits strictly between its parents, but where between depends on the denominators, so two mediants can be ordered oppositely to both of their pairs of parents. Every entry in the Stern–Brocot tree is that effect used deliberately, to move as slowly as possible between two neighbours.

The moral is a small and general one. An operation is not wrong because it is not the operation somebody expected; it is wrong when applied to the wrong things. Mediants of fractions are meaningless — 12\tfrac12 and 24\tfrac24 would give different answers for the same numbers. Mediants of pairs of counts are exactly right, and the tree only ever handles pairs of counts, which is why it never has to cancel anything.

The same fractions in a different order

There is a second tree that enumerates every positive rational exactly once, and comparing the two says something about what the property is worth.

The Calkin–Wilf tree puts 11\tfrac11 at the root and gives pq\tfrac{p}{q} the children pp+q\tfrac{p}{p+q} and p+qq\tfrac{p+q}{q}. It also produces every positive rational once and always in lowest terms, and its nodes read in breadth-first order form a single sequence in which the denominator of each fraction is the numerator of the next — a property the Stern–Brocot tree does not have.

What it lacks is order. Reading the Calkin–Wilf tree left to right does not read the fractions in increasing order, so it cannot be flattened into a Farey sequence and it says nothing about approximation. The two trees contain the same nodes and carry different information, and the one worth using depends entirely on the question: enumeration wants Calkin–Wilf, approximation wants Stern–Brocot.

It is worth noticing that both are enumerations of the rationals, which is to say both are proofs that the rationals are countable — a fact usually demonstrated with a zigzag through a grid that visits many fractions twice and needs cancelling afterwards. Either tree does it without repetition and without reduction, which is a tidier proof of a result that is normally proved untidily.

What the picture cannot show

The tree drawn here has four levels and fifteen nodes. The fraction 355113\tfrac{355}{113}, which approximates π\pi to seven places, sits at depth 292292 — the tree is exponentially wide and the interesting fractions are exponentially deep, so no drawing shows a node worth naming.

Ford circles up to denominator 11A circle of diameter one over q squared resting on each fraction p over q; neighbours touch.0/11/31/22/31/1each circle has diameter one over its denominator squared, and rests on its own fractiontwo circles touch exactly when the fractions are Farey neighbours — nothing overlaps anywhere
Fig. 7 The circles again, two orders further on. The new circles are smaller by a factor of the denominator squared, so each raise of the order adds detail that is invisible at the previous scale — and the strip is no fuller than it was, because the total area of all the circles converges.

That depth is not a drawing problem. It is why the tree is a poor way to find a fraction and an excellent way to understand one: reaching 355113\tfrac{355}{113} by descending the tree takes 292292 steps, while Euclid’s algorithm reaches it in five, because the algorithm takes a whole run of turns at once. The tree and the algorithm carry the same information at different granularities, and the algorithm’s is the useful one.

There is also something the picture actively misleads about. Drawn on a page, the tree looks as though it fills the interval evenly. It does not fill it at all — the rationals are countable, and the tree enumerates them, so every irrational number is a path down the tree that never lands anywhere. The figure shows a set of measure zero looking dense, which is exactly the illusion more things than boxes exists to dispel.

Where it came from, twice

Moritz Stern published the construction in 1858; Achille Brocot, a French clockmaker, published it independently in 1861. Brocot was not doing number theory. He was building clocks, and needed gear ratios approximating a required ratio with tooth counts that could actually be cut — the same problem Huygens solved with continued fractions two centuries earlier.

Brocot’s version is a table rather than a tree, and it is used the way a navigator uses a chart: find the target ratio between two entries, take the mediant, and repeat until the approximation is good enough or the teeth get too numerous. Every entry in the table is automatically in lowest terms, which for a clockmaker is not an elegance but a requirement, since a gear pair sharing a factor wears unevenly.

The tree therefore has two independent discoveries, one from arithmetic and one from a workshop, five years apart. That happens often enough in this subject to be worth noticing: the constructions that survive tend to be the ones that somebody needed.

The Farey half of the story has a still stranger history. John Farey, a geologist, published a note in 1816 observing that each fraction in the sequence is the mediant of its neighbours, and admitted he could not prove it. Cauchy proved it and attached Farey’s name. But the sequences had been published fourteen years earlier by Charles Haros, who used them to build a table of decimal equivalents for fractions with denominators up to a hundred — and whose name is on nothing. Hardy’s remark that Farey “was not a mathematician” and that his one contribution to the subject was an unproved observation is unkind and roughly accurate, and the name has stuck anyway.

None of that affects the mathematics, and it affects how the mathematics is found. Both Haros and Brocot arrived at the construction while making a table, which is what people did before they had calculating machines, and a table of fractions in lowest terms is exactly what the mediant produces without being asked.

Where the ladder goes next

The determinant of one is the thread out of here. It makes the tree’s fractions irreducible, it makes Ford circles tangent, and it is the same condition that makes a lattice basis unimodular — the matrices L=(1011)L = \left(\begin{smallmatrix}1&0\\1&1\end{smallmatrix}\right) and R=(1101)R = \left(\begin{smallmatrix}1&1\\0&1\end{smallmatrix}\right) are the tree’s left and right steps, and they generate the whole group of integer matrices with determinant one.

The other direction is approximation. The tree produces every fraction; the question of which ones are worth having is how close a fraction can get, and the answer is a pigeonhole argument that finds the same fractions the tree’s alternating paths pass through.

What links here

Computed from the collection, not written here: the essays that point at this one.

Shares its objects with

Essays that name at least two of the same things, and that neither author linked.

Named objects

A dashed tag is an object no other essay names yet.

BijectionContinued fractionsCounting two waysFarey sequenceFord circlesLowest termsMediantStern brocot treeTangencyUnimodular