# Farey sequence

Farey diagram to F9 represented with circular arcs. In the SVG image, hover over a curve to highlight it and its terms.
Farey diagram to F9.
Symmetrical pattern made by the denominators of the Farey sequence, F9.
Symmetrical pattern made by the denominators of the Farey sequence, F25.

In mathematics, the Farey sequence of order n is the sequence of completely reduced fractions, either between 0 and 1, or without this restriction,[1] which when in lowest terms have denominators less than or equal to n, arranged in order of increasing size.

With the restricted definition, each Farey sequence starts with the value 0, denoted by the fraction 01, and ends with the value 1, denoted by the fraction 11 (although some authors omit these terms).

A Farey sequence is sometimes called a Farey series,[citation needed] which is not strictly correct, because the terms are not summed.

## Examples

The Farey sequences of orders 1 to 8 are :

F1 = { 0/1, 1/1 }
F2 = { 0/1, 1/2, 1/1 }
F3 = { 0/1, 1/3, 1/2, 2/3, 1/1 }
F4 = { 0/1, 1/4, 1/3, 1/2, 2/3, 3/4, 1/1 }
F5 = { 0/1, 1/5, 1/4, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 4/5, 1/1 }
F6 = { 0/1, 1/6, 1/5, 1/4, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 4/5, 5/6, 1/1 }
F7 = { 0/1, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 2/5, 3/7, 1/2, 4/7, 3/5, 2/3, 5/7, 3/4, 4/5, 5/6, 6/7, 1/1 }
F8 = { 0/1, 1/8, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 3/8, 2/5, 3/7, 1/2, 4/7, 3/5, 5/8, 2/3, 5/7, 3/4, 4/5, 5/6, 6/7, 7/8, 1/1 }
Centered
F1 = { 0/1, 1/1 }
F2 = { 0/1, 1/2, 1/1 }
F3 = { 0/1, 1/3, 1/2, 2/3, 1/1 }
F4 = { 0/1, 1/4, 1/3, 1/2, 2/3, 3/4, 1/1 }
F5 = { 0/1, 1/5, 1/4, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 4/5, 1/1 }
F6 = { 0/1, 1/6, 1/5, 1/4, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 4/5, 5/6, 1/1 }
F7 = { 0/1, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 2/5, 3/7, 1/2, 4/7, 3/5, 2/3, 5/7, 3/4, 4/5, 5/6, 6/7, 1/1 }
F8 = { 0/1, 1/8, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 3/8, 2/5, 3/7, 1/2, 4/7, 3/5, 5/8, 2/3, 5/7, 3/4, 4/5, 5/6, 6/7, 7/8, 1/1 }
Sorted
 F1 = {0/1,                                                                                                          1/1}
F2 = {0/1,                                                   1/2,                                                   1/1}
F3 = {0/1,                               1/3,                1/2,                2/3,                               1/1}
F4 = {0/1,                     1/4,      1/3,                1/2,                2/3,      3/4,                     1/1}
F5 = {0/1,                1/5, 1/4,      1/3,      2/5,      1/2,      3/5,      2/3,      3/4, 4/5,                1/1}
F6 = {0/1,           1/6, 1/5, 1/4,      1/3,      2/5,      1/2,      3/5,      2/3,      3/4, 4/5, 5/6,           1/1}
F7 = {0/1,      1/7, 1/6, 1/5, 1/4, 2/7, 1/3,      2/5, 3/7, 1/2, 4/7, 3/5,      2/3, 5/7, 3/4, 4/5, 5/6, 6/7,      1/1}
F8 = {0/1, 1/8, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 3/8, 2/5, 3/7, 1/2, 4/7, 3/5, 5/8, 2/3, 5/7, 3/4, 4/5, 5/6, 6/7, 7/8, 1/1}


## History

The history of 'Farey series' is very curious — Hardy & Wright (1979) Chapter III[2]
... once again the man whose name was given to a mathematical relation was not the original discoverer so far as the records go. — Beiler (1964) Chapter XVI[3]

Farey sequences are named after the British geologist John Farey, Sr., whose letter about these sequences was published in the Philosophical Magazine in 1816. Farey conjectured, without offering proof, that each new term in a Farey sequence expansion is the mediant of its neighbours. Farey's letter was read by Cauchy, who provided a proof in his Exercices de mathématique, and attributed this result to Farey. In fact, another mathematician, Charles Haros, had published similar results in 1802 which were not known either to Farey or to Cauchy.[3] Thus it was a historical accident that linked Farey's name with these sequences. This is an example of Stigler's law of eponymy.

## Properties

### Sequence length and index of a fraction

The Farey sequence of order n contains all of the members of the Farey sequences of lower orders. In particular Fn contains all of the members of Fn−1 and also contains an additional fraction for each number that is less than n and coprime to n. Thus F6 consists of F5 together with the fractions 1/6 and 5/6.

The middle term of a Farey sequence Fn is always 1/2, for n > 1. From this, we can relate the lengths of Fn and Fn−1 using Euler's totient function ${\displaystyle \varphi (n)}$ :

${\displaystyle |F_{n}|=|F_{n-1}|+\varphi (n).}$

Using the fact that |F1| = 2, we can derive an expression for the length of Fn[4]:

${\displaystyle |F_{n}|=1+\sum _{m=1}^{n}\varphi (m).}$

We also have :

${\displaystyle |F_{n}|={\frac {1}{2}}\left(3+\sum _{d=1}^{n}\mu (d)\left\lfloor {\tfrac {n}{d}}\right\rfloor ^{2}\right),}$

and by a Möbius inversion formula :

${\displaystyle |F_{n}|={\frac {1}{2}}(n+3)n-\sum _{d=2}^{n}|F_{\lfloor n/d\rfloor }|,}$

where µ(d) is the number-theoretic Möbius function, and ${\displaystyle \lfloor {\tfrac {n}{d}}\rfloor }$ is the floor function.

The asymptotic behaviour of |Fn| is :

${\displaystyle |F_{n}|\sim {\frac {3n^{2}}{\pi ^{2}}}.}$

The index ${\displaystyle I_{n}(a_{k,n})=k}$ of a fraction ${\displaystyle a_{k,n}}$ in the Farey sequence ${\displaystyle F_{n}=\{a_{k,n}:k=0,1,\ldots ,m_{n}\}}$ is simply the position that ${\displaystyle a_{k,n}}$ occupies in the sequence. This is of special relevance as it is used in an alternative formulation of the Riemann hypothesis, see below. Various useful properties follow:

${\displaystyle I_{n}(0/1)=0,}$
${\displaystyle I_{n}(1/n)=1,}$
${\displaystyle I_{n}(1/2)=(|F_{n}|-1)/2,}$
${\displaystyle I_{n}(1/1)=|F_{n}|-1,}$
${\displaystyle I_{n}(h/k)=|F_{n}|-1-I_{n}((k-h)/k).}$

The index of ${\displaystyle 1/k}$ where ${\displaystyle n/(i+1) and ${\displaystyle n}$ is the least common multiple of the first ${\displaystyle i}$ numbers, ${\displaystyle n={\rm {lcm}}([2,i])}$, is given by[5]:

${\displaystyle I_{n}(1/k)=1+n\sum _{j=1}^{i}{\frac {\varphi (j)}{j}}-k\Phi (i).}$

### Farey neighbours

Fractions which are neighbouring terms in any Farey sequence are known as a Farey pair and have the following properties.

If a/b and c/d are neighbours in a Farey sequence, with a/b < c/d, then their difference c/d − a/b is equal to 1/bd.[why?] Since

${\displaystyle {\frac {c}{d}}-{\frac {a}{b}}={\frac {bc-ad}{bd}},}$

this is equivalent to saying that

${\displaystyle bc-ad=1}$.

Thus 1/3 and 2/5 are neighbours in F5, and their difference is 1/15.

The converse is also true. If

${\displaystyle bc-ad=1}$

for positive integers a,b,c and d with a < b and c < d then a/b and c/d will be neighbours in the Farey sequence of order max(b,d).

If p/q has neighbours a/b and c/d in some Farey sequence, with

${\displaystyle {\frac {a}{b}}<{\frac {p}{q}}<{\frac {c}{d}}}$

then p/q is the mediant of a/b and c/d – in other words,

${\displaystyle {\frac {p}{q}}={\frac {a+c}{b+d}}.}$

This follows easily from the previous property, since if bpaq = qcpd = 1, then bp + pd = qc + aq, p(b + d) = q(a + c), p/q = a + c/b + d.

It follows that if a/b and c/d are neighbours in a Farey sequence then the first term that appears between them as the order of the Farey sequence is incremented is

${\displaystyle {\frac {a+c}{b+d}},}$

which first appears in the Farey sequence of order b + d.

Thus the first term to appear between 1/3 and 2/5 is 3/8, which appears in F8.

The Stern–Brocot tree is a data structure showing how the sequence is built up from 0 (= 0/1) and 1 (= 1/1), by taking successive mediants.

Fractions that appear as neighbours in a Farey sequence have closely related continued fraction expansions. Every fraction has two continued fraction expansions — in one the final term is 1; in the other the final term is greater than 1. If p/q, which first appears in Farey sequence Fq, has continued fraction expansions

[0; a1, a2, ..., an − 1, an, 1]
[0; a1, a2, ..., an − 1, an + 1]

then the nearest neighbour of p/q in Fq (which will be its neighbour with the larger denominator) has a continued fraction expansion

[0; a1, a2, ..., an]

and its other neighbour has a continued fraction expansion

[0; a1, a2, ..., an − 1]

For example, 3/8 has the two continued fraction expansions [0; 2, 1, 1, 1] and [0; 2, 1, 2], and its neighbours in F8 are 2/5, which can be expanded as [0; 2, 1, 1]; and 1/3, which can be expanded as [0; 2, 1].

### Applications

Farey sequences are very useful to find rational approximations of irrational numbers.[6]

In physics systems featuring resonance phenomena Farey sequences provide a very elegant and efficient method to compute resonance locations in 1D[7] and 2D.[8]

### Ford circles

Comparison of Ford circles and a Farey diagram with circular arcs for n from 1 to 9. Note that each arc intersects its corresponding circles at right angles. In the SVG image, hover over a circle or curve to highlight it and its terms.

There is a connection between Farey sequence and Ford circles.

For every fraction p/q (in its lowest terms) there is a Ford circle C[p/q], which is the circle with radius 1/(2q2) and centre at (p/q, 1/(2q2)). Two Ford circles for different fractions are either disjoint or they are tangent to one another—two Ford circles never intersect. If 0 < p/q < 1 then the Ford circles that are tangent to C[p/q] are precisely the Ford circles for fractions that are neighbours of p/q in some Farey sequence.

Thus C[2/5] is tangent to C[1/2], C[1/3], C[3/7], C[3/8] etc.

### Riemann hypothesis

Farey sequences are used in two equivalent formulations of the Riemann hypothesis. Suppose the terms of ${\displaystyle F_{n}}$ are ${\displaystyle \{a_{k,n}:k=0,1,\ldots ,m_{n}\}}$. Define ${\displaystyle d_{k,n}=a_{k,n}-k/m_{n}}$, in other words ${\displaystyle d_{k,n}}$ is the difference between the kth term of the nth Farey sequence, and the kth member of a set of the same number of points, distributed evenly on the unit interval. In 1924 Jérôme Franel[9] proved that the statement

${\displaystyle \sum _{k=1}^{m_{n}}d_{k,n}^{2}=O(n^{r})\quad \forall r>-1}$

is equivalent to the Riemann hypothesis, and then Edmund Landau[10] remarked (just after Franel's paper) that the statement

${\displaystyle \sum _{k=1}^{m_{n}}|d_{k,n}|=O(n^{r})\quad \forall r>1/2}$

is also equivalent to the Riemann hypothesis.

## Next term

A surprisingly simple algorithm exists to generate the terms of Fn in either traditional order (ascending) or non-traditional order (descending). The algorithm computes each successive entry in terms of the previous two entries using the mediant property given above. If a/b and c/d are the two given entries, and p/q is the unknown next entry, then c/d = a + p/b + q. Since c/d is in lowest terms, there must be an integer k such that kc = a + p and kd = b + q, giving p = kc − a and q = kd − b. If we consider p and q to be functions of k, then

${\displaystyle {\frac {p(k)}{q(k)}}-{\frac {c}{d}}={\frac {cb-da}{d(kd-b)}}}$

so the larger k gets, the closer p/q gets to c/d.

To give the next term in the sequence k must be as large as possible, subject to kd − b ≤ n (as we are only considering numbers with denominators not greater than n), so k is the greatest integer ≤ n + b/d. Putting this value of k back into the equations for p and q gives

${\displaystyle p=\left\lfloor {\frac {n+b}{d}}\right\rfloor c-a}$
${\displaystyle q=\left\lfloor {\frac {n+b}{d}}\right\rfloor d-b}$

This is implemented in Python as:

def farey_function(n, descending=False):
"""Print the nth Farey sequence, either ascending or descending."""
a, b, c, d = 0, 1, 1, n
if descending:
a, c = 1, n-1
print "%d/%d" % (a,b)
while (c <= n and not descending) or (a > 0 and descending):
k = int((n + b) / d)
a, b, c, d = c, d, (k*c-a), (k*d-b)
print "%d/%d" % (a,b)


Brute-force searches for solutions to Diophantine equations in rationals can often take advantage of the Farey series (to search only reduced forms). The lines marked (*) can also be modified to include any two adjacent terms so as to generate terms only larger (or smaller) than a given term.[11]

## References

1. ^ Ivan M. Niven and Herbert S. Zuckerman, An Introduction to the theory of numbers, third edition, John Wiley and Sons 1972, Definition 6.1. "The sequence of all reduced fractions with denominators not exceeding n, listed in order of their size, is called the Farey sequence of order n." With the comment: "This definition of the Farey sequences seems to be the most convenient. However, some authors prefer to restrict the fractions to the interval from 0 to 1."
2. ^ Hardy, G.H. & Wright, E.M. (1979) An Introduction to the Theory of Numbers (Fifth Edition). Oxford University Press. ISBN 0-19-853171-0
3. ^ a b Beiler, Albert H. (1964) Recreations in the Theory of Numbers (Second Edition). Dover. ISBN 0-486-21096-0. Cited in Farey Series, A Story at Cut-the-Knot
4. ^ Sloane, N. J. A. (ed.). "Sequence A005728". The On-Line Encyclopedia of Integer Sequences. OEIS Foundation.
5. ^ Tomas, Rogelio (2018). "Partial Franel sums". arXiv:1802.07792 [math.NT]. Accessed: November 18, 2018.
6. ^ "Farey Approximation", NRICH.maths.org. Accessed: 18 November 2018.
7. ^ *Zhenhua Li, A.; Harter, W.G. (2013). "Quantum Revivals of Morse Oscillators and Farey-Ford Geometry". arXiv:1308.4470v1 [quant-ph]. Accessed: November 18, 2018.
8. ^ Tomas, R. (2014). "From Farey sequences to resonance diagrams", prst-ab.aps.org. Accessed: 18 November 2018.
9. ^ "Les suites de Farey et le problème des nombres premiers", Nachrichten von der Gesellschaft der Wissenschaften zu Göttingen, Mathematisch-Physikalische Klasse 1924, 198-201. (in French)
10. ^ "Bemerkungen zu der vorstehenden Abhandlung von Herrn Franel", Nachrichten von der Gesellschaft der Wissenschaften zu Göttingen, Mathematisch-Physikalische Klasse 1924, 202-206. (in German)
11. ^ Norman Routledge, "Computing Farey Series," The Mathematical Gazette, Vol. 92 (No. 523), 55–62 (March 2008).