I writing a mathematica function.

JohnMcBetty
Messages
12
Reaction score
0
The Farey sequence F_n (F subscript n) for any positive integer n is the set of irreducible rational numbers a/b with 0<(or equal to)a<(or equal to)b<(or equal to) n and (a,b)=1 arranged in increasing order. The first one should be:

F_1 = {0/1,1/1}

F_2 = {0/1,1/2,1/1}

F_3 = {0/1,1/3,1/2,2/3,1/1}

F_4 = {0/1,1/4,1/3,1/2,2/3,3/4,1/1}

F_5 = {0/1,1/5,1/4,1/3,2/5,1/2,3/5,2/3,3/4,4/5,1/1}

I need to write a mathematica function that takes a positive integer n and returns, as a list, the nth Farey sequence, I really need some help?
 
Physics news on Phys.org
Some hints that should help you get started.

What if you made a Table[] containing all i/j? where 0<=i<=n and 1<=j<=n?

There are several things wrong with that, it has extra {} and duplicate values and values in the wrong order and extra values you don't want.

What can you do to get rid of what you don't want and leave what you need?

Try addressing those problems, perhaps one at a time, and show what progress you have made.

You should be able to accomplish all this with a single line.

Note: Most Mathematica questions usually go in the OtherSciences/Math&ScienceSoftware section.
 
I tried this, but it still doesn't work, I am very new at using this program.


FareySequence[n_] := local a, b, c, d, k;
a := 0; b := 1; c := 1; d := n;
printf (` % d/% d \n `, a, b);
while (c < n) do
k := floor ((n + b)/d);
a := c; b := d; c := k*c - a; d := k*d - b;
printf (` % d/% d \n `, a, b);
od : end :
 
What you wrote isn't Mathematica.

FareyFirstStep[n_]:=Table[i/j,{i,0,n},{j,1,n}]

will do the very first step I suggested.

If you look at the result of that, for say FareyFirstStep[4], can you identify that it seems to be providing some interesting and useful bits that are going in the direction of what you need?

Now describe one thing that is wrong with the result from FareyFirstStep and how can you fix that using a single Mathematica supplied function?

Hint: There are several different things wrong and it may be easier to fix those in one particular order than trying to fix them in some other order so think about what fix might make your next needed fix easier to do. You are nibbling away at the problem a little at a time while you try to make sense of the Mathematica language.
 
Last edited:
Would I have to use the flatten command?
 
Is this a homework problem?
 
I asked online questions about Proposition 2.1.1: The answer I got is the following: I have some questions about the answer I got. When the person answering says: ##1.## Is the map ##\mathfrak{q}\mapsto \mathfrak{q} A _\mathfrak{p}## from ##A\setminus \mathfrak{p}\to A_\mathfrak{p}##? But I don't understand what the author meant for the rest of the sentence in mathematical notation: ##2.## In the next statement where the author says: How is ##A\to...
##\textbf{Exercise 10}:## I came across the following solution online: Questions: 1. When the author states in "that ring (not sure if he is referring to ##R## or ##R/\mathfrak{p}##, but I am guessing the later) ##x_n x_{n+1}=0## for all odd $n$ and ##x_{n+1}## is invertible, so that ##x_n=0##" 2. How does ##x_nx_{n+1}=0## implies that ##x_{n+1}## is invertible and ##x_n=0##. I mean if the quotient ring ##R/\mathfrak{p}## is an integral domain, and ##x_{n+1}## is invertible then...
The following are taken from the two sources, 1) from this online page and the book An Introduction to Module Theory by: Ibrahim Assem, Flavio U. Coelho. In the Abelian Categories chapter in the module theory text on page 157, right after presenting IV.2.21 Definition, the authors states "Image and coimage may or may not exist, but if they do, then they are unique up to isomorphism (because so are kernels and cokernels). Also in the reference url page above, the authors present two...
Back
Top