Writing a Farey sequence in Mathematica.

In summary, a Farey sequence is a sequence of rational numbers in lowest terms and increasing order between 0 and 1. It can be written in Mathematica using the FareySequence function, with options to customize the output as fractions or decimals. Other functions such as FareyGrid can also generate visual representations of the sequence. The Farey sequence has applications in number theory and geometry, and can provide insights into other mathematical concepts.
  • #1
JohnMcBetty
12
0
I need some help writing a Farey Sequence in Mathematica, so far this is all I have:

FareySequence[n_] := GCD[a, b]; While b : a, b = b, a % b;
result := a

Simplify[a, b];
g := GCD[a, b]
result := (a/g, b/g)

I am very new to programming, please help!
 
Mathematics news on Phys.org

1. What is a Farey sequence?

A Farey sequence is a sequence of rational numbers that are in lowest terms and arranged in increasing order between 0 and 1. It is named after the British geologist John Farey, who first described it in 1816.

2. How do I write a Farey sequence in Mathematica?

To write a Farey sequence in Mathematica, you can use the FareySequence function. This function takes in a single integer as its input and returns a list of all the Farey fractions up to that number. For example, FareySequence[5] will return {0, 1/5, 1/4, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 4/5, 1}.

3. Can I customize the output of the Farey sequence in Mathematica?

Yes, you can customize the output of the Farey sequence in Mathematica by using the optional IncludeFractions and IncludeReals parameters. Setting IncludeFractions to True will return the sequence as fractions, while setting IncludeReals to True will return the sequence as decimals. For example, FareySequence[5, IncludeFractions -> True] will return {0, 1/5, 1/4, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 4/5, 1} and FareySequence[5, IncludeReals -> True] will return {0., 0.2, 0.25, 0.333333, 0.4, 0.5, 0.6, 0.666667, 0.75, 0.8, 1.}.

4. Are there any other functions in Mathematica that can generate Farey sequences?

Yes, in addition to the FareySequence function, there is also the FareyGrid function which can be used to generate a visual representation of a Farey sequence. This function takes in a single integer as its input and returns a grid of all the Farey fractions up to that number. For example, FareyGrid[5] will return a grid with rows representing the denominators and columns representing the numerators of the Farey fractions.

5. How can I use the Farey sequence in my mathematical research?

The Farey sequence has various applications in number theory and geometry, including in the study of rational approximations and the distribution of prime numbers. It can also be used as a tool for visualizing fractions and comparing their relative sizes. Additionally, the Farey sequence has connections to other mathematical concepts such as continued fractions and the Stern-Brocot tree. Therefore, incorporating the Farey sequence in your mathematical research can provide new insights and perspectives on various topics.

Similar threads

Replies
35
Views
2K
  • General Math
Replies
1
Views
1K
Replies
4
Views
641
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
4K
Replies
1
Views
364
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
220
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
Back
Top