- #1

- 17

- 0

## Main Question or Discussion Point

Here is an overview of Farey sequences; http://mathworld.wolfram.com/FareySequence.html" [Broken]

I need to write a program in Mathematica 8, FareySequence[n_], that takes a positive integer n and returns, as a list, the nth Farey sequence.

So far I have,

Module[{denleft, denright, f, i, j, k, numleft, numright, result, s},

(*Given a positive integer n, this function returns, as a list, the nth Farey sequence.)

But we have to deal with n=1 in a special way, i.e -

If[n==1, {0/1, 1/1},

I want to compute the "left half", L[SUB]n[/SUB] of the nth Farey sequence, first.

So, I figure I can start with L

f[

I need to write a program in Mathematica 8, FareySequence[n_], that takes a positive integer n and returns, as a list, the nth Farey sequence.

So far I have,

Module[{denleft, denright, f, i, j, k, numleft, numright, result, s},

(*Given a positive integer n, this function returns, as a list, the nth Farey sequence.)

But we have to deal with n=1 in a special way, i.e -

If[n==1, {0/1, 1/1},

I want to compute the "left half", L[SUB]n[/SUB] of the nth Farey sequence, first.

So, I figure I can start with L

_{2}and then compute L_{3}, L_{4},..., L_{n}in order. For this I would use two lists, f and s:f[

*] would be the ith fraction to appear as the various left-halves are computed*

and

s[and

s[

*] = j iff the sucessor of f[**] is f[[j]].*

For example, for L

f = {0/1, 1/2, 1/3, 1/4, 1/5, 2/5} and s = {5, 0, 6, 3, 4, 2}

Now, the variable k keeps track of which left half is being computed. So,

For[k=3, k less/equal n, k++, [B]??[/B]];

result = {};

So, I have all these pieces of code that, when I attempt to put together, looks like:

FareySequence[n_] := Module[{denleft, denright, f, i, j, k, numleft, numright, result, s}, If[n==1, {0/1, 1/1}, f={0/1, 1/2}; s={2,0}; For[k=3, k≤n, k++, [B]??[/B]]; result={}; result]]

I need to figure out how to:

(a) Copy the left half of the Farey sequence into result.

(b) Insert the right half of the Farey sequence into result.

Any help is much appreciated.For example, for L

_{5},f = {0/1, 1/2, 1/3, 1/4, 1/5, 2/5} and s = {5, 0, 6, 3, 4, 2}

Now, the variable k keeps track of which left half is being computed. So,

For[k=3, k less/equal n, k++, [B]??[/B]];

result = {};

So, I have all these pieces of code that, when I attempt to put together, looks like:

FareySequence[n_] := Module[{denleft, denright, f, i, j, k, numleft, numright, result, s}, If[n==1, {0/1, 1/1}, f={0/1, 1/2}; s={2,0}; For[k=3, k≤n, k++, [B]??[/B]]; result={}; result]]

I need to figure out how to:

(a) Copy the left half of the Farey sequence into result.

(b) Insert the right half of the Farey sequence into result.

Any help is much appreciated.

Last edited by a moderator: