### Farey Sequences and the Stern-Brocot Tree

#### Posted by John Baez

*guest post by Tim Silverman*

I want to discuss in more detail the modular curves $X(N)$, $X_1(N)$ and $X_0(N)$, that is, the quotients of the upper half plane $H$ by $\Gamma(N)$, $\Gamma_1(N)$ and $\Gamma_0(N)$ respectively (with cusps filled in). These are charismatic entities — for example, you may have seen Greg Egan’s movie of $X(7)$, also known as Klein’s quartic curve:

I also want to talk about the actions of the Hecke operators $<d>$ and $T_p$ on modular forms—or at least the corresponding actions on modular curves. Alas, I don’t think I’m going to get there in this post, but I can at least make a start.

But before I talk about all that, I want to talk about Farey sequences!

I was introduced to Farey sequences by a maths teacher at school, when I was about 13 or so, one afternoon when I’d done all my work and was feeling bored. They’re a simple and cute idea, and I found them kind of fascinating, but, not being much of a number theory person, I never looked into them all that deeply. But one stumbles across these things in the oddest places.

What is a Farey sequence? It’s very simple. Take all the reduced fractions from 0 to 1 (inclusive) with denominators no larger than some maximum $n$. Now arrange them in order of increasing value. And that’s a Farey sequence. Thus Farey sequences include

$\frac{0}{1},\frac{1}{1}$

$\frac{0}{1},\frac{1}{2},\frac{1}{1}$

$\frac{0}{1},\frac{1}{3},\frac{1}{2},\frac{2}{3},\frac{1}{1}$

and so on. Here’s the ninth Farey sequence:

$\frac{0}{1},\frac{1}{9},\frac{1}{8},\frac{1}{7}, \frac{1}{6},\frac{1}{5},\frac{2}{9},\frac{1}{4}, \frac{2}{7},\frac{1}{3},\frac{3}{8},\frac{2}{5}, \frac{3}{7},\frac{4}{9},\frac{1}{2},\frac{5}{9}, \frac{4}{7},\frac{3}{5},\frac{5}{8},\frac{2}{3}, \frac{5}{7},\frac{3}{4},\frac{7}{9},\frac{4}{5}, \frac{5}{6},\frac{6}{7},\frac{7}{8},\frac{8}{9}, \frac{1}{1}$

There are some curious facts about Farey sequences. Here’s one: if $\frac{a}{b}$ and $\frac{c}{d}$ appear adjacent to one another in some Farey sequence, then $bc-ad=1$.

Here’s another: if $\frac{a}{b}$ and $\frac{c}{d}$ appear adjacent to one another in some Farey sequence, then the next fraction which gets inserted between them, as you work your way through the successive Farey sequences, is the fraction $\frac{a+c}{b+d}$. This funny combination is called the *mediant* of $\frac{a}{b}$ and $\frac{c}{d}$, since it always lies between them. By repeatedly taking mediants, we build up all Farey sequences, and hence get each rational number from $0$ to $1$ exactly once.

We can indicate the way that the mediant derives from two parent fractions by drawing lines from the parents to their mediant:

Additionally, one of the parents must always derive from the other—it must have been inserted as a mediant itself at some earlier time. So if a fraction is connected to its parents by a pair of lines, the parents must also be connected to each other. So these lines actually make up a bunch of triangles, except at the top of the picture where everything starts. Taking the three numbers at the vertices of a triangle, any one of them can be derived from the other two either as their mediant, $\frac{a+b}{c+d}$, or as what we might call their ‘mediant difference’, $\left\vert\frac{a-b}{c-d}\right\vert$. In fact every pair of numbers joined by a line belongs to two triangles (one on either side of the line joining them), and one of the triangles will contain their mediant as its third point, while the other will contain their mediant difference instead!

So, can the Farey tree be extended to include fractions outside the interval $[0, 1]$? That’s something we might be wondering, and the answer is Yes! In fact, this would have happened already if we hadn’t foolishly forgotten something: we’ve included fractions with denominators of $1$, $2$, $3$, etc, but we’ve forgotten to include fractions with denominator $0$! How could we have been so careless? Let us remedy this oversight at once!

Including the fraction $\frac{1}{0}$ right at the top of the tree, it turns out that we can actually derive $\frac{1}{1}$ from this together with $\frac{0}{1}$, as their mediant, and then we can get $\frac{2}{1}$ from $\frac{1}{0}$ and $\frac{1}{1}$, and so forth, and by building up mediants, we can get all non-negative rational numbers that way. The whole tree is called the Stern-Brocot tree.

Once we’ve made these extensions, and added an edge connecting $\frac{1}{0}$ and $\frac{0}{1}$, we see that *every* fraction in the tree, including the ones right at the top, belongs to a triangle—in fact, it belongs to an infinite number of triangles! We can just keep forming new mediants from it with its new neighbours forever.
However, an infinite number of triangles hanging off every vertex is rather unmanageable. Is there some way we can get a toy version, with only a finite number of triangles instead? For instance, suppose we mod out the fractions by some natural number $N$? That is, we mod out both numerator and denominator by $N$, taking care not to forget that $\frac{a}{b}=\frac{-a}{-b}$? Then many different $\mathbb{Z}$-fractions will map to the same $\mathbb{Z}/(N)$-fraction, and if we identify the corresponding points, and also, of course, identify the corresponding edges connecting corresponding points, then we will get something finite.

For instance, suppose we take the above tree mod $3$ (reducing the fractions where necessary to their lowest form, and bearing in mind that $1=-2$, so $\frac{1}{2}=\frac{-1}{-2}=\frac{2}{1}$). We get this:

Or reducing mod $4$ (and bearing in mind that $-1=3$ and $-2=2$, we get this:

The rule about mediants and mediant differences still applies, but sometimes, with all the swapping of signs, we’ve switched around which fraction relates to which how!

Anyway, with these trees in hand, all we need to do is identify the vertices and edges correctly, and we’ll get something interesting and finite. In fact, while we’re about it, why not fill in those triangles? Then we’ll get a compact surface! It will be triangulated, and in fact each vertex will be the apex of just $N$ triangles (this is completely obvious in the case of the vertex $\frac{1}{0}$, but it applies to all vertices). Or, dually, every vertex will stand at the centre of an $N$-gon, while each of the triangular faces gives rise, dually, to a vertex at which $3$ $N$-gons meet.

Wait a minute …

That sounds familiar …

Could it be … ?

Yes it is! The compact surface we have just constructed is none other than $X(N)$, the quotient of $H$ by $\Gamma(N)$. Quel surprise! The fractions mod $N$ correspond to the cusps, and we can make the dual tiling completely regular if we pick the right constant-curvature metric (which will need positive curvature for $N<6$, negative curvature for $N>6$, and will have to be flat for $N=6$).

In fact, this also works for the full Stern-Brocot tree, without any modding out, with fractions over all integers. We can see this either arithmetically or geometrically.

Arithmetically, replace the fraction $\frac{a}{b}$ by the element $\left(\array{a\\b}\right)$ in $\mathbb{Z}^2$. Of course, $SL(2, \mathbb{Z})$ acts on this by ordinary matrix multiplication; indeed, $PSL(2, \mathbb{Z})$ acts on it too, more nicely, since switching the signs of both numerator and denominator doesn’t affect the value of the fraction.

In particular, if we pick an element of $PSL(2, \mathbb{Z})$ such as

$\left(\array{a&b\\c&d}\right),$

then those two starting fractions at the top of the tree, $\frac{0}{1}$ and $\frac{1}{0}$, will get sent, under the action of that group element, to a pair of fractions $\frac{a}{c}$ and $\frac{b}{d}$ such that $a d-b c=-1$. (That minus sign is a result of listing the fractions the ‘wrong’ way around). This same relation holds true of any two adjacent elements in a Farey sequence, and since *some* member of $PSL(2, \mathbb{Z})$ is available to send $\frac{0}{1}$ and $\frac{1}{0}$ to *any* adjacent pair, we get all Farey sequences in this way—over all integers, not just in the interval $[0, 1]$.

Now, $\frac{0}{1}$ and $\frac{1}{0}$ are joined to each other by an edge, and, being adjacent elements of a Farey sequence, so will their images be. In addition, each of $\frac{0}{1}$ and $\frac{1}{0}$ is also joined by an edge to $\frac{1}{1}$, their mediant. But the mediant of fractions corresponds simply to the sum in $\mathbb{Z}^2$ (considered as a $\mathbb{Z}$-module). And obviously the sum relation is preserved by $PSL(2, \mathbb{Z})$. So if $\frac{0}{1}$ gets sent to $\frac{a}{c}$ and $\frac{1}{0}$ gets sent to $\frac{b}{d}$, then $\frac{1}{1}$ gets sent to the mediant of $\frac{a}{b}$ and $\frac{c}{d}$, meaning that the other two sides of that top triangle $\frac{0}{1}$-$\frac{1}{0}$-$\frac{1}{1}$ are also preserved—sent to sides of a triangle in the image.

So triangles are sent to triangles. Moreover, since the relation of being the mediant (or sum) of the other two vertices—as opposed to their mediant difference (or difference)—uniquely picks out one vertex of a given triangle, and since the sign of the determinant—or, more simply, which of the parent vertices is larger—uniquely picks an orientation of the triangle, each triangle is sent to another triangle in only one way. So $PSL(2, \mathbb{Z})$ acts freely on the set of triangles, and of course preserves their relations.

Geometrically, as we can see from Don Hatch’s nice Hyperbolic Tesselations web page, the tilings of the hyperbolic plane by regular $n$-gons, $3$ meeting at each vertex, have a limiting case with a tiling by what one might call regular $\mathbb{Z}$-gons, or regular $\infty$-gons, with an infinite number of sides! They appear in the website as {infinity, 3}:

Dually, we get a tiling by triangles, an infinite number of which meet at the ‘centre’ of each $\mathbb{Z}$-gon. These triangles correspond precisely to the triangles in the Stern-Brocot tree. Rather confusingly, however, in the Poincaré disk model, the ‘centre’ of a $\mathbb{Z}$-gon appears at the edge of the disk—that’s the sort of thing that happens when you have an infinite number of sides and are trying to show them all in a bounded region.

If we compare the Poincaré disk model of the hyperbolic plane with the ‘upper half-plane’ model, we see that the real line of the latter goes to the boundary circle of the former. The $\mathbb{Z}$-gons, drawn in the Poincaré disk, are all tangent to the boundary circle, each with its own distinct point of tangency, and these points correspond precisely to the rational numbers (together with $\infty$). In turn, these rational numbers are the ones in the Stern-Brocot tree, i.e. at the vertices of the triangles, which can also be seen as tiling the hyperbolic plane, dually to the $\mathbb{Z}$-gons. In this way, we also get to label each $\mathbb{Z}$-gon by a unique rational number, and this is inherited when we go over to the version mod $N$—fractions also being reduced mod $N$.

Given all this, one way to try and understand the way that geometry and arithmetic interact in $X(N)$ is by working our way down the Stern-Brocot tree mod $N$, which will correspond to working our way outward from one of the $N$-gons in $X(N)$. What we’re going to see is a series of concentric circles of fractions with successively incrementing denominators.

But that, I think, is something for another post.

## Re: Farey Sequences and the Stern-Brocot Tree

There seems to be a lot of beautiful classical geometry connected to such

locally symmetric spaces, e.g. MacPherson and McConnell construct in:“Classical projective geometry and modular varieties”, in “Algebraic analysis, geometry, and number theory” (Baltimore, MD, 1988)

cell complexes equivalent to (compactified) locally symm. spaces from configurations of projective geometry:

“Classical projective geometry was a beautiful field in mathematics. It died, in our opinion, not because it ran out of theorems to prove, but because it lacked organizing principles by which to select theorems that were important. Also, it was isolated from the rest of mathematics. Much of what we do may be regarded as direct continuation of nineteenth century synthetic geometry. In fact, we hope the new motivation of studying C-complexes will provide projective geometry with one organizational principle, and with one relation tying it to “mainstream” mathematics. We note … representable matroids, arrangements of hyperplanes, and motivic cohomology. A large part of this paper’s exposition is motivated by this dream of continuing classical projective geometry.”

Hereis a related overview.