generates the Farey sequence of order n.
FareySequence[n,k]
gives the k
element of the Farey sequence of order n.
FareySequence
generates the Farey sequence of order n.
FareySequence[n,k]
gives the k
element of the Farey sequence of order n.
Examples
open all close allBasic Examples (1)
Scope (1)
Applications (5)
Farey arc diagram, connecting adjacent rationals in a Farey sequence:
FareyPairArc[r1_, r2_] := Circle[{(r1 + r2) / 2, 0}, (r2 - r1) / 2, {0, Pi}]Table[Graphics[{ColorData[94, n], FareyPairArc@@@Partition[FareySequence[n], 2, 1]}, PlotLabel -> n], {n, 1, 6}]Show[%]Visualize a pattern of denominators of a Farey sequence of order 12:
Denominator /@ FareySequence[12]MatrixPlot[SparseArray[MapIndexed[Prepend[#2, #1] -> 1&, %]], Mesh -> All]The length of a Farey sequence for a few small orders:
Table[Length[FareySequence[n]], {n, 1, 12}]Compare with a closed-form formula in terms of Euler's totient function:
Table[1 + Underoverscript[∑, k = 1, n]EulerPhi[k], {n, 1, 12}]The product of all nonzero elements of the Farey sequence for a few small orders:
Table[Apply[Times, Rest[FareySequence[n]]], {n, 2, 12}]Compare with a closed-form formula:
Table[Underoverscript[∏, k = 1, n]((BarnesG[Quotient[n, k] + 2]/Hyperfactorial[Quotient[n, k]]))^MoebiusMu[k], {n, 2, 12}]Construct Ford circles from a Farey sequence:
FordCircle[r_] := With[{den = (2 Denominator[r] ^ 2)}, Disk[{r, 1 / den}, 1 / den]]Graphics[{GrayLevel[3 / (2 + 3Denominator[#])], Tooltip[FordCircle[#], #]}& /@ FareySequence[10], PlotRange -> {{0, 1}, {0, 1}}]Properties & Relations (2)
Obtain a Farey sequence as a union of Subdivide lists:
FareySequence[5]% === Union@@(Subdivide /@ Range[5])FareySequence[n,k] is equivalent to FareySequence[n]〚k〛:
FareySequence[50, 500]FareySequence[50][[500]]FareySequence[n,k] is much faster:
FareySequence[5000, 1000000]//AbsoluteTimingFareySequence[5000][[1000000]]//AbsoluteTimingRelated Guides
Related Links
Text
Wolfram Research (2014), FareySequence, Wolfram Language function, https://reference.wolfram.com/language/ref/FareySequence.html (updated 2016).
CMS
Wolfram Language. 2014. "FareySequence." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2016. https://reference.wolfram.com/language/ref/FareySequence.html.
APA
Wolfram Language. (2014). FareySequence. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/FareySequence.html
BibTeX
@misc{reference.wolfram_2026_fareysequence, author="Wolfram Research", title="{FareySequence}", year="2016", howpublished="\url{https://reference.wolfram.com/language/ref/FareySequence.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_fareysequence, organization={Wolfram Research}, title={FareySequence}, year={2016}, url={https://reference.wolfram.com/language/ref/FareySequence.html}, note=[Accessed: 12-June-2026]}