Fractions in the Farey Series and the Stern-Brocot Tree

Contents

The Things To Do icon means there is a Things to do investigation at the end of the section. The calculator icon means there is an interactive calculator in this section.

Farey Series

If we list all the "small" fractions, that is, those using no number higher than 5, say, and if we list them in order of size from 0 to 1, then the resulting series is called a Farey series:
0  1  1  1  2  1  3  2  3  4  1
543525345
Such series of small fractions have many interesting properties.
There is a Farey series for each size of maximum denominator so we call the maximum denominator of a series the order of that series and talk about "the Farey series of order 5" for instance.

It makes the maths tidier if we start at 0 and end with 1 and write these as 0/1 and 1/1:
orderFarey seriescount
1
0  1
11
2
2
0  1  1
121
3
3
0  1  1  2  1
13231
5
4
0  1  1  1  2  3  1
1432341
7
5
0  1  1  1  2  1  3  2  3  4  1
15435253451
11
6
0  1  1  1  1  2  1  3  2  3  4  5  1
1654352534561
13
...

The lengths of these series (counts) are 2, 3, 5, 7, 11, 13, 19, 23, 29, 33, .. A005728 and, apart from the first, are always odd. Up until 29 it looked as if they might all be primes, but 33 puts an end to that theory.

The Complementary Fraction

This is because if a/b is in a Farey series then so is 1 – a/b = (b–a)/b, called its complement.
Even 0/0 has a complement: 1/1.
There is one fraction not paired in this way because it is equal to its complement: 1/2.
So there are always an odd number of fractions in any Farey series beyond those of order 1, as each is paired with its complement except for 1/2.

The Denominators

In the table of Farey series, the denominators have a pattern. To generate the denominators of the next row (order 7) we insert a 7 wherever two neighbouring denominators of level 6 sum to 7:
Level 6:  1   6   5   4   3   5   2   5   3   4   5   6   1
Level 7:    7           7       7   7       7           7
We can then number the new fractions with numerators in order from 1 to 6 since there are 6 of them. However, in general there are not n-1 fractions with a denominator of n since some of them will not be in lowest form.

The Numerators

Are there any patterns in the numerators?
We noticed above that both a/b and its complement (b–a)/b are in the same Farey series. The Farey series are always in increasing size so the sum of the second fraction from the end is the complement of the second fraction (from the beginning), and so on for the third, fourth, etc, till we get to the central fraction 1/2. Such pairs have the same denominator and their numerators will sum or n, the order of the Farey series.

Neighbouring Fractions in Farey Series

An important property of two neighbouring fractions in any Farey series is that "cross-multiplying" gives two consecutive integers. In other words, if a/b and p/q are consecutive terms in any Farey series, then b×p is the next integer after a×q. For instance, the Farey seris of order 6 has ..., 1/3, 2/5, ... and 5×1 = 5 , 3×2 = 6. This works for all pairs of terms in all Farey series if we write the first fraction, 0, as 0/1.
... ,  a,  p,  ... ⇒ b p – a q = 1
bq

The Mediant

Another way to represent all small fractions is to use the fact that between fractions a/b and p/q lies the fraction (a+p)/(b+q) formed by summing their numerators and their denominators:
a
b
  <  
a + p
b + q
  <  
p
q

The central fraction here is called the mediant of the other two.
For any three successive fractions in any Farey series, the middle one is the mediant of the other two but not always in its lowest form as we saw with the mediant of 1/6 and 1/4 above.
John Farey observed this in a letter of 1816 to the Philosophical Magazine and asked if it was always true. It was soon proved so by Cauchy who gave gave them the name "Farey series". However C Haros had already proved this in 1802 and it seems his work was unknown to both Farey and Cauchy but it is Farey's name that is now always given to these series. (See the References below for more on this in both Hardy and Wright's book and the wonderfully inspiring book by Beiler.)

Another arrangement of Fractions

There is another way to arrange all fractions. It uses the mediant operation but this time it always gives the mediant fractions in their lowest terms.
We again start with a row of just two fractions: 0/1 and 1/1.
The rows of Farey fractions table has all fractions with a denominator n or less. However, in this new table this is not true, but we do still include all fractions once and once only. It uses the mediant of two fractions to fill in each row as follows:
levelseriescount
00/1 1/12
10/1 1/2 1/13
20/1 1/3 1/2 2/3 1/15
30/11/41/32/51/23/52/33/41/19
...
So every fraction apart from 0/1 and 1/0 is the mediant of two consecutive 'parent' fractions from the level above.
Each fraction produces two 'children' formed from the mediants of itself and the fraction on its left and with the fraction on its right.
This family 'tree' of fractions has some interesting properties:
C A L C U L A T O R
Farey Fractions

with a denominator up to

R E S U L T S

The Stern-Brocot Tree of Fractions

Stern and Brocot realised that the table we have above can be extended, using the same fill-in-with-the-mediant rule, to include all fractions, those bigger than one also and not just those between 0 and 1.
Instead of starting with 0/1 and 1/1 we start with 0/1 and 1/0 to represent 0 and infinity.
To start the tree, the first mediant is that of 0/1 and 1/0 which is 1/1. Now the left half of this new table contains all the fractions between 0 and 1 (0/1 and 1/1) while the right-hand half becomes populated with all the fractions greater than 1, between 1 and infinity (1/1 and 1/0)!
levelfractions
< 1>1
00/1 1/0
10/11/11/0
20/11/21/12/11/0
30/11/31/22/31/13/22/13/11/0
40/1 1/4 1/3 2/5 1/2 3/5 2/3 3/4 1/1 4/3 3/2 5/3 2/1 5/2 3/1 4/1 1/0
5...
Did you notice that the right-hand half of the table has the same fractions as in the left-hand half, but each is inverted and they are in reverse order?
Since the left-hand half contains all fractions m/n < 1, then the right hand half will contain all fractions n/m > 1, with 1/1 itself central to every row.

The Stern-Brocot Tree

If we ignore the two end fractions 0/1 and 1/0 then the first time a fraction appears, we can draw a line from it to its nearest fraction on the row above. The only fraction that we cannot do this for is 1/1 and this becomes the 'root' of our tree, which, like many trees in computing and mathematics, grows down the page.
Every fraction first appears as the mediant (a+p)/(b+q) of the two fractions a/b and p/q on the level above in the table. The line from (a+p)/(b+q) will therefore go to either a/b or p/q.
Stern-Brocot Tree
of ALL fractions
0/1 1/1 1/0
1/22/1
1/32/33/23/1
1/42/53/53/4 4/35/35/24/1
Did you notice that:
the fractions on each level are in order of size

A Path in the Tree to every fraction

We can now find a unique path from 1/1 to any and every fraction.
From a parent we can go down to the Left fraction (child) on the next level below or to the R fraction on the level below. Since all the fractions are joined into a single tree with root 1/1, then every fraction has such a string of Ls and Rs from the top to reach it.
In this table, each fraction appears once, on its highest (first) level and below it are its two children.
Paths in the Stern-Brocot Tree
0/1 1/1 1/0
L
1/2
R
2/1
L
1/3
R
2/3
L
3/2
R
3/1
L
1/4
R
2/5
L
3/5
R
3/4
L
4/3
R
5/3
L
5/2
R
4/1
For example: which gives us a nice method of computing the LR path from 1/1 to m/n:
  1. Input: the fraction being sought, Output will be the LR path to this fraction
  2. Two fractions define the RANGE within which we are looking for our fraction:
    0/1 and 1/0. Call these two fractions Start and End.
  3. We will build up the path letter by letter and the PATH is initially empty.
    1. Find the MEDIANT of Start and End
    2. If MEDIANT = the fraction sought then STOP and print out the PATH found so far
    3. Otherwise:
      1. If m/n < MEDIANT then
        add an "L" on to the end of the PATH and
        change End to be equal to MEDIANT
      2. If m/n > MEDIANT then
        add an "R" on to the end of the PATH and
        change Start to be equal to MEDIANT
  4. Keep repeating the previous step until the method stops.
The only problem is 1/1 itself which, being at the 'root' of the tree, has no path or, rather, its path is empty.
A similar simple algorithm will compute m/n from a given LR path but here is a Calculator to do both.

Limitations in the Calculator:
Note that the fraction 1/N occurs for the first time at the start of row N in the tree so its path can be very long compared to other fractions: the path to 1/1000000 is one million L's! As a result, the paths of some fractions cannot be fully computed with this Calculator.
Similarly, computing mediants involves very large numbers if the fractions have a large denominator or numerator and this too limits the computation of the fractions corresponding to some paths.
C A L C U L A T O R
The Stern-Brocot Fractions Tree
Fraction: LR Path:
Fraction <- LR path
Fraction -> LR path
from top to level

R E S U L T S

There are now several interesting questions that you can work on for yourself:

/ Things to do /

  1. (Easy) If m/n is in its lowest form, on what level does it appear in the tree?
  2. (Easy) How long is the path for fraction m/n?
  3. If we know the path for fraction m/n and we change all L's to R's and R's to L's in it, how is the new path's fraction related to m/n?
  4. (Easy) Where are the fractions of the form 1/n in the tree?
  5. (Easy) Where are the integers in the tree?
  6. (Easy) Look again at the table of Farey fractions at the start of this page or use the first Farey Calculator above to answer these questions:
    1. Make a table of the only the numerators of the Farey fractions (the left half of the Stern-Brocot tree ) for a particular level. What pattern do you notice? Does it apply to all levels?
    2. Now try the same thing but for the denominators.
  7. Make a list of the ratio of two consecutive Fibonacci numbers 1, 2, 3, 5, 8, 13, 21, ... and let's call these the Fibonacci Fractions:
    1/2, 2/3, 3/5, 5/8, 8/13, ... etc
    Where are they in the table, or in other words, what is the path to each of them?
  8. What about ratios of two consecutive Lucas numbers (2,) 1, 3, 4, 7, 11, ...
    (2/1,) 1/3, 3/4, 4/7, 7/11, 11/18, ... ? What are their paths and what pattern can you see in them?
What about non-fractional numbers - the irrationals such as √2 or e or π?
There is a close connection between the Stern-Brocot tree and LR paths of the fractions that best approximate any irrational value. There is more to read on this in Graham, Knuth and Patashnik's Concrete Mathematics - see the References section that follows.
What is a Continued Fraction? See An Introduction to Continued Fractions at this site and also the online Continued Fractions Calculator.
Or you can explore all the patterns of ordinary decimal fractions using the Fractions Converter at this site, where the decimal fractions are computed to many places.

References

The tree is named after Moritz Stern and Achille Brocot who both wrote about it independently around 1858.
Book: Recreations in the Theory of Numbers - The Queen of Mathematics Entertains A H Beiler, Dover, 1964
has a whole chapter on Farey Tales that is informative, fun and not at all too mathematical. I highly recommend this book to anyone who has enjoyed this page and Ron Knott's other maths web pages.
Article: On a Curious Property of Vulgar Fractions J Farey London, Edinburgh and Dublin Phil. Mag vol 47 (1816) page 385.
Book: Introduction to the Theory of numbers G H Hardy, E M Wright, Oxford University Press, 5th edition, 1980, ISBN: 0198531710
is a classic book well worth studying but some parts are at mathematics undergraduate level. There is a whole chapter on teh basic result of Farey Series with proofs.
Article: Uebe eine zahlentheoretische Funktion M A Stern, Journal für die reine und angewandte Mathematik vol 55 (1858) pages 193-220
... the original references for the Stern-Brocot tree ...
Article: Calcul des rouages par approximation, nouvelle méthode Achille Brocot Revue Chronométrique 6 (1860) pages 186-194
Article: On a curious property of vulgar fractions J Farey Philosophical Magazine vol 47 (1816) pages 385-386
is the original letter by Farey on what are now called 'Farey fractions'. However, he only spotted that the mediant of two fractions lies between them and offered no proof. This was already known and had been published :
Article: Tables pour évaluer une fraction ordinaire avec autant de decimales qu'on voudra; et pour trouver la fraction ordinaire la plus simple, et qui approche sensiblement d'une fraction décimal C. Haros Journal de L'Ecole Royale Polytechnique Tome IV (Cahier 11) (1802), pages 364-368.
...however, the name that has 'stuck' to the ordered row of fractions less than one with denominators no bigger than n, is the order n Farey sequence, i.e. it is Farey's name and not Haros's!
Book: Concrete Mathematics (2nd edition, 1994) by Graham, Knuth and Patashnik, Addison-Wesley.
is highly recommended but is at undergraduate mathematics level. Section 4.5 is a wonderful introduction to more of the mathematics of the Farey series and the Stern-Brocot tree.

Valid HTML 4.01! © 2008-2011 Dr Ron Knott
created: 26 March 2008, updated 16 April 2011