Farey Sequence Calculator

Sequence and fraction

Terms in the Farey sequence F_511
Rank of 1/3 in F_54 of 11
Predecessor1/4
Successor2/5
How this was calculated
  1. The Farey sequence F_5 lists every reduced fraction between 0 and 1 whose denominator does not exceed 5, in increasing order.
  2. Its length follows from Euler's totient: |F_n| = 1 + phi(1) + phi(2) + ... + phi(n), which here gives 11 terms.
  3. Neighbouring terms a/b and c/d in a Farey sequence always satisfy b x c - a x d = 1, the determinant identity that lets each term be generated from the last two.
  4. For 1/3 the rank is 4 of 11, with predecessor 1/4 and successor 2/5 in F_5.

The Farey sequence calculator builds the Farey sequence of a given order n and returns the full list of fractions in order, from 0/1 to 1/1. It also reports the position, or rank, of any fraction you choose. The results match the standard sequences: F_5 has 11 terms, F_8 has 23 terms and F_10 has 33 terms. In F_5, the fraction 1/3 sits at rank 4 of 11, between 1/4 and 2/5. In F_8, 3/7 sits at rank 11 of 23, between 2/5 and 1/2. In F_10, the middle term 1/2 sits at rank 17 of 33, between 4/9 and 5/9.

The method behind the calculator is the accepted standard for this kind of calculation. Neighbouring Farey terms a/b and c/d always satisfy b x c - a x d = 1, and the length of F_n is 1 plus the sum of Euler's totient phi(k) for k = 1 to n. These two properties let the sequence be generated and checked reliably. This page shows the formula, the step-by-step workings, worked examples and sources, so you can follow each result rather than take it on trust.

Worked examples

Neighbours of 1/3 in the Farey sequence of order 5

(5 · 1 · 3)

Terms in the Farey sequence F_511
Rank of 1/3 in F_54 of 11
Predecessor1/4
Successor2/5

Neighbours of 3/7 in the Farey sequence of order 8

(8 · 3 · 7)

Terms in the Farey sequence F_823
Rank of 3/7 in F_811 of 23
Predecessor2/5
Successor1/2

The middle term 1/2 in the Farey sequence of order 10

(10 · 1 · 2)

Terms in the Farey sequence F_1033
Rank of 1/2 in F_1017 of 33
Predecessor4/9
Successor5/9

What is a Farey sequence?

A Farey sequence is the ordered list of all reduced fractions between 0 and 1 whose denominators are no larger than a chosen whole number n. The sequence is named F_n, and it always begins at 0/1 and ends at 1/1. Every fraction in between is written in lowest terms, so a value like 2/4 never appears, because it reduces to 1/2. The fractions are arranged from smallest to largest, which makes F_n a complete, gap-free tour of the rational numbers in that range, up to the denominator limit. A Farey sequence calculator builds this list for you and lets you see where any given fraction falls in the order.

The size of the list grows as n grows. F_5 has 11 terms, F_8 has 23 terms and F_10 has 33 terms. Each term has a rank within its sequence, counting from 1 at the left end. In F_5 the fraction 1/3 sits at rank 4 of 11, between 1/4 and 2/5. In F_8 the fraction 3/7 sits at rank 11 of 23, between 2/5 and 1/2. In F_10 the middle term 1/2 sits at rank 17 of 33, between 4/9 and 5/9. These examples show the two things a Farey list tells you about a fraction: its position in the ordering and the two fractions that bracket it on either side.

The neighbours in a Farey sequence are tied together by a simple arithmetic rule. If a/b and c/d are neighbouring terms, then b x c - a x d = 1. This condition holds for every adjacent pair in the list, and it is what makes the ordering exact rather than approximate. The total length of F_n can also be computed directly: it is 1 plus the sum of Euler's totient phi(k) for k = 1 to n. The totient function counts how many numbers up to k share no common factor with k, which is precisely the count of new reduced fractions each denominator contributes.

Put together, these properties mean you never have to guess at the contents of a Farey sequence. The definition fixes which fractions belong, the neighbour rule fixes their order, and the totient formula fixes how many there are. For small n the list is short enough to write out by hand, but the count climbs quickly, which is where a calculator saves time. Use it to generate F_n, check the rank of a fraction, or confirm the neighbours on either side of a value you are working with.

  • F_5: 11 terms; 1/3 is at rank 4 of 11, between 1/4 and 2/5.
  • F_8: 23 terms; 3/7 is at rank 11 of 23, between 2/5 and 1/2.
  • F_10: 33 terms; 1/2 is at rank 17 of 33, between 4/9 and 5/9.
  • Neighbour rule: for adjacent terms a/b and c/d, b x c - a x d = 1.
  • Length rule: the length of F_n is 1 plus the sum of Euler's totient phi(k) for k = 1 to n.
Every fraction in a Farey sequence is written in lowest terms, so each value appears only once, in increasing order from 0/1 to 1/1.

Worked examples

A table makes the pattern concrete. The three examples below place 1/3, 3/7 and 1/2 in their sequences, giving each fraction's rank and the two terms it sits between. Every number here comes from the sequence itself, so you can check each row by listing the terms in order.

Start with 1/3 in F_5. The sequence F_5 has 11 terms, and 1/3 sits at rank 4 of 11, between 1/4 and 2/5. Reading the rank from the low end, 1/3 is the fourth term, with three smaller fractions ahead of it and seven larger ones after it.

Next, 3/7 in F_8. F_8 has 23 terms, and 3/7 sits at rank 11 of 23, between 2/5 and 1/2. Because 23 is odd, the middle term of F_8 is a single fraction, and 3/7 is close to that midpoint without being it.

Finally, 1/2 in F_10. F_10 has 33 terms, and the middle term 1/2 sits at rank 17 of 33, between 4/9 and 5/9. With 33 terms, rank 17 is exactly the center: sixteen terms lie below 1/2 and sixteen above it.

These rows also illustrate the neighbour rule. Neighbouring Farey terms a/b and c/d always satisfy b x c - a x d = 1. You can test this on any adjacent pair in the table, such as 1/4 and 1/3, or 4/9 and 1/2. The count of terms follows a separate rule: the length of F_n is 1 plus the sum of Euler's totient phi(k) for k = 1 to n. That is why the lengths grow from 11 to 23 to 33 as n goes from 5 to 8 to 10. If you want to check other fractions, a Farey sequence calculator applies these same rules to list the terms, find a rank and confirm the neighbours.

FractionSequenceRankLower neighbourUpper neighbour
1/3F_5 (11 terms)4 of 111/42/5
3/7F_8 (23 terms)11 of 232/51/2
1/2F_10 (33 terms)17 of 334/95/9
Neighbouring terms a/b and c/d always satisfy b x c - a x d = 1, and the length of F_n is 1 plus the sum of Euler's totient phi(k) for k = 1 to n.

The determinant identity and mediants

Two fractions that sit next to each other in a Farey sequence are not related by accident. If a/b and c/d are neighbors in F_n, then b × c − a × d = 1. This determinant identity is the engine behind the whole structure: it tells you exactly how much the two fractions differ, and it guarantees that no other fraction with denominator at most n can fit between them. A Farey sequence calculator can check this quickly for any pair you enter, but the identity itself is something you can verify by hand.

Take F_5, which has 11 terms. The fraction 1/3 sits at rank 4 of 11, between 1/4 and 2/5. Test the left pair: 1/4 and 1/3 give 4 × 1 − 1 × 3 = 1. Test the right pair: 1/3 and 2/5 give 3 × 2 − 1 × 5 = 1. Both neighbors pass. The same check works higher up. In F_8, which has 23 terms, 3/7 sits at rank 11 of 23, between 2/5 and 1/2. For 2/5 and 3/7: 5 × 3 − 2 × 7 = 1. For 3/7 and 1/2: 7 × 1 − 3 × 2 = 1. The identity holds at every rank, not just the ones listed here.

The identity also explains where new terms come from. Given neighbors a/b and c/d, their mediant is (a + c)/(b + d). Because b × c − a × d = 1, the mediant always lies strictly between them, and its denominator b + d is larger than either b or d. That means the mediant cannot appear in F_n when b + d exceeds n, but it is exactly the fraction that appears between the two neighbors in the next order where the denominator limit allows it. Neighbors in one order become a three-term block in a later order, with the mediant inserted in the middle.

You can see this with 1/2 in F_10, which has 33 terms. The middle term 1/2 sits at rank 17 of 33, between 4/9 and 5/9. Check the left pair: 9 × 1 − 4 × 2 = 1. Check the right pair: 2 × 5 − 1 × 9 = 1. Now form the mediants: between 4/9 and 1/2 the mediant is 5/11, and between 1/2 and 5/9 it is 6/11. Both have denominator 11, so they are too long for F_10 but appear as the inserted terms once the order reaches 11. This is the pattern the determinant identity predicts every time.

The length of F_n is 1 plus the sum of Euler's totient phi(k) for k = 1 to n. That count grows with each new order, and every added term arrives as a mediant of two existing neighbors. The determinant identity is what makes the insertion consistent: it holds for the original pair and for each new adjacent pair created by the mediant, so the property propagates through the sequence. When you use a Farey sequence calculator, you are watching this identity enforced at every rank, from the small cases like F_5 with 11 terms up to F_10 with 33.

Neighbor check: for any adjacent Farey terms a/b and c/d, b × c − a × d = 1. The mediant (a + c)/(b + d) is the fraction that slots between them at the next order that permits its denominator.

Where Farey sequences appear

Farey sequences are not just a list-building exercise. The same ordered fractions show up in several areas of mathematics and engineering, and a Farey sequence calculator gives you a quick way to see the structure those applications depend on. The key property is that neighboring terms a/b and c/d always satisfy b × c − a × d = 1. That single relation links the sequence to geometry, tree structures, and approximation problems.

Ford circles turn the sequence into a picture. Draw a circle above each fraction on a number line, with each circle resting on the line at that fraction. Fractions that are Farey neighbors produce circles that touch exactly, and the b × c − a × d = 1 rule is what guarantees the tangency. Larger denominators give smaller circles, so the sequence's ordering becomes a packing of circles along the line. The Stern-Brocot tree offers a different view of the same fractions. It is built by repeatedly inserting mediants between neighboring fractions, and every positive rational appears exactly once. Farey sequences are closely related: the terms of F_n are the fractions whose denominators are at most n, so the tree and the sequence describe the same underlying order from different directions.

In engineering, Farey sequences support gear-ratio approximation. When a desired ratio cannot be built exactly from available gear teeth, the neighboring fractions in a Farey sequence give the closest simple alternatives, and the b × c − a × d = 1 relation measures how tightly those alternatives bracket the target. The same ordering underlies Diophantine approximation, where the goal is to approximate a real number by fractions with small denominators. Farey neighbors are the natural candidates, which is why the sequence appears in the theory of rational approximation.

The sizes are worth keeping in mind. F_5 has 11 terms, F_8 has 23 terms, and F_10 has 33 terms. The length of F_n is 1 plus the sum of Euler's totient phi(k) for k = 1 to n, so the count grows with each added denominator. Position within the sequence matters too. In F_5 the fraction 1/3 sits at rank 4 of 11, between 1/4 and 2/5. In F_8 the fraction 3/7 sits at rank 11 of 23, between 2/5 and 1/2. In F_10 the middle term 1/2 sits at rank 17 of 33, between 4/9 and 5/9.

Neighboring Farey terms a/b and c/d always satisfy b × c − a × d = 1 — the same relation behind Ford circle tangency and tight rational approximations.

FAQs

How many terms are in the Farey sequence of order 5?

The Farey sequence of order 5 has 11 terms, running from 0/1 to 1/1. The terms are listed in increasing order, with each fraction written in lowest terms using denominators no larger than 5. So F_5 contains 11 fractions in total, and the full sequence begins at 0/1 and ends at 1/1.

How many terms are in the Farey sequence of order 10?

The Farey sequence of order 10 contains 33 terms. As with every Farey sequence, the fractions are in lowest terms, have denominators no larger than 10, lie between 0 and 1, and are listed in increasing order. The sequence starts at 0/1 and finishes at 1/1, with 33 fractions in all.

What are the neighbours of 1/3 in F_5?

In F_5, the fraction 1/3 is the 4th of the 11 terms. The term just before it is 1/4, and the term just after it is 2/5. So the neighbours of 1/3 in the Farey sequence of order 5 are 1/4 on the left and 2/5 on the right, with no other F_5 fraction lying between them.

How is the length of a Farey sequence computed?

The length of the Farey sequence of order n is 1 + phi(1) + phi(2) + ... + phi(n), where phi is Euler's totient function. Each phi(k) counts the fractions in lowest terms with denominator exactly k, and the extra 1 accounts for 0/1. Adding these values gives the total number of terms in the sequence.

What is special about neighbouring Farey fractions?

For any two neighbouring fractions a/b and c/d in a Farey sequence, the cross product b x c - a x d always equals 1. This property holds for every adjacent pair in the sequence. It is often used to generate Farey sequences and to check that two fractions are immediate neighbours in a given order.

What is the middle term of F_10?

The middle term of F_10 is 1/2. It sits at rank 17 of the 33 terms, so exactly 16 terms come before it and 16 come after. Its immediate neighbours in F_10 are 4/9 on the left and 5/9 on the right, with no other fraction of order 10 lying between them.

Sources

Related calculators

Euler's Totient Calculator
Euler's totient φ(n) — how many integers up to n are coprime to n — from the distinct prime factors of n.
Möbius Function Calculator
The Möbius function mu(n) from the prime factorization of n: zero for a squared prime factor, otherwise plus or minus one by the factor count.
Prime Counting Calculator
Exact count of primes up to any limit of ten million or less by the sieve of Eratosthenes, compared with the prime number theorem estimate x / ln(x), the average prime gap and the count in the top half of the range.