Farey Sequence Generator

Enter an order n to generate its Farey sequence.

How it is calculated

The tool starts from the first two neighbours 0/1 and 1/n and produces each next fraction from the previous two with the neighbour recurrence: k = floor((n + b) / d), then next = (k·c − a) / (k·d − b), where a/b and c/d are the last two fractions. It stops when it reaches 1/1. Because of this recurrence every fraction comes out already in lowest terms and in increasing order, with no sorting or gcd step. The order n is rounded to the nearest whole number and must be between 1 and 50; anything outside that range gives no result. The count it reports is the number of fractions, which equals 1 + φ(1) + φ(2) + … + φ(n), where φ is Euler's totient.

Worked example

Take n = 5. The sequence begins at 0/1 and 1/5. The next terms follow from the recurrence and the list is: 0/1, 1/5, 1/4, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 4/5, 1/1. Count them: 11 fractions. Check with the totient formula: φ(1..5) = 1, 1, 2, 2, 4, which sums to 10, plus 1 for the starting 0/1 gives 11. Neighbours such as 2/5 and 1/2 satisfy 1·5 − 2·2 = 1.

Try this example →

Common mistakes

  • Expecting fractions that are not in lowest terms. 2/4 or 3/6 never appear because 1/2 already covers them, so the count is smaller than all pairs a/b with b ≤ n.
  • Confusing the order n with the number of terms. F_5 has 11 terms, not 5; the count grows roughly with n².
  • Entering a decimal such as 4.6. The tool rounds it to 5, so you get F_5.
  • Entering an order above 50 and expecting a list. The tool only handles 1 to 50 and returns nothing beyond that.
  • Forgetting that both 0/1 and 1/1 are included, which matters when you compare the count with a totient sum.

About this calculator

The Farey sequence of order n, F_n, lists every fraction a/b in lowest terms with 0 ≤ a ≤ b ≤ n, arranged in increasing order between 0/1 and 1/1 — F_3, for instance, is 0/1, 1/3, 1/2, 2/3, 1/1. Consecutive fractions in the sequence always satisfy the property that their cross-multiplied difference (bc − ad for neighbors a/b and c/d) equals exactly 1.

Number theory students and enthusiasts use Farey sequences to study rational approximation, the Stern-Brocot tree, and the distribution of fractions with bounded denominators, and they show up in problems involving continued fractions, the Riemann hypothesis's Franel-Landau reformulation, and generating all reduced fractions up to a given denominator without duplicates.

Was this helpful?

You can pick up to 3 reactions.

Comments

  • Be the first to comment.

Popular calculators

All Calculators