6

1

There is of course the silly implementation:

```
FareySequence[n_] := Union[Flatten[Table[j/i, {i, 1, n}, {j, 0, i}]]]
```

However, there are numerous properties and confinements of Farey sequences (that can be used, **potentially**, in an indirect manner).

This calls for a very simple, and, very efficient recurring/functional implementation, exhibiting *Superiority*. But I'm new to *Mathematica* and can't find the right combination of built-in functions, and pure functions..

Ideas?

1Hmm... – J. M.'s ennui – 2013-05-06T04:23:51.557

1

I saw the implementation in the link. Isn't there a simpler implementation?

– user76568 – 2013-05-06T04:34:01.8371Your implementation is certainly simpler. Of course, it's also less efficient. – J. M.'s ennui – 2013-05-06T06:03:52.227

Actually, the OPs code comes from here: http://www.physicsforums.com/showthread.php?t=489620 or here http://demonstrations.wolfram.com/FareySequence/ whichever came first.

– bill s – 2013-05-06T06:21:37.030@J.M. I'm sure there is a more elegant, more efficient, simpler to read and comprehend, method. Better than all those mentioned, because it is all very simple. I'll give it a go with a rit or 2 later.... :P – user76568 – 2013-05-06T06:34:40.367

Be my guest, then. :) – J. M.'s ennui – 2013-05-06T07:32:59.863

There are many relationships between members of the Farey sequence. For instance, if a/b and c/d are members, then the mediant (a+c)/(b+d) is in the sequence. This property might be easier to exploit than the one you've given. – bill s – 2013-05-06T07:39:39.923

What you said was not correct, but makes you wonder. – user76568 – 2013-05-06T07:45:28.040

The mediant property is well known, see for instance: http://www.cse.iitd.ernet.in/~mcs103480/farey-icip-100525.pdf

– bill s – 2013-05-06T08:04:22.410@bill, there are restrictions to be imposed on the denominators for the constructed mediant to be a proper member of the $k$th Farey sequence, of course. – J. M.'s ennui – 2013-05-06T08:14:21.177

Right, it holds as long as the denominator is not larger than

`k`

-- the`DeleteCases`

in the answer removes those extra ones. – bill s – 2013-05-06T08:15:54.563@J.M. Some ideas also here http://codegolf.stackexchange.com/questions/1896/code-challenge-farey-sequence-ii

– Dr. belisarius – 2013-05-06T12:03:20.850@bel, that just counts the number of terms in the Farey sequence. That is most easily done in

Mathematica, which has`EulerPhi[]`

. – J. M.'s ennui – 2013-05-06T12:28:12.277@J.M. Then I misread it. Sorry. – Dr. belisarius – 2013-05-06T12:39:46.767

@J.M. Nevertheless,

`EulerPhi[]`

can be handy even for our purposes... Along with another 10 (or so) tricks... (as of now) :) Let's start a most efficient Farey competition! The winner.. uumm.. will be awarded a book about Number Theory.. or... candy. – user76568 – 2013-05-06T12:50:09.0231I think the problem with finding a recursive solution using the cited property is that the property is not strictly speaking a recurrence relation, since $D_k$ depends on $F_k$. Indeed for any $F_{k-1}$, there are infinitely many solutions for $F_k$ (depending on the order). – Michael E2 – 2013-05-07T02:35:03.633

@MichaelE2 you are absolutely correct. Your comment is Superior. :) Do you think I should remake the question? So It'll be Superior? This Farey sequence is packed with logic/rules and confinments, up to a point where I think it can be implmented on/by pure logic :) – user76568 – 2013-05-07T07:07:27.680

1Yes, perhaps you should clarify whether you want an efficient way to generate the Farey sequences or to be shown how to implement certain properties. – Michael E2 – 2013-05-07T13:04:02.507