Farey sequence



reyssat pisze:
> Adam Majewski a ?crit :
>> Richard Fateman pisze:
>>> Here's an idea.
>>>
>>> :lisp (defun $fa(n)(cons '(mlist)(loop for i from 0 to n collect (/ i 
>>> n))))
>>>
>>> this gives you 0, 1/100, 2/100 ..... in lowest terms.  of course 
>>> 2/100 is also 1/50...
>>>
>>> Anyway, compute all fa(1) ... fa(100) and merge them, eliminating 
>>> duplicates.
>>>
>>> :lisp (defun $merge(n m) (cons '(mlist) (merge 'list (cdr n)(cdr m) 
>>> #'<)))
>>>
>>> :lisp (defun $nodups(n)  ;; exercise for the reader.
>>>   ;; actually, eliminating duplicates during the merge is going to be 
>>> faster.
>>>
>>> RJF
>>
>> Thx.
>>
>> I have found also :
>>
>> (defun farey-cauchy (n)
>> (let ((a 0) (b 1) (c 1) (d n) k f e)
>> (format t "~a/~a " a b)
>> (loop while (< c n) do
>> (setq k (floor (/ (+ n b) d))
>> e (- (* k c) a)
>> f (- (* k d) b)
>> a c
>> b d
>> c e
>> d f)
>> (format t "~a/~a " a b))))
>>
>>
>> from http://www.ymeme.com/farey-cauchy-sequence-lisp-101.html
>>
>> but I can't find its time of execution to compare with maxima results
> This is the first method of
> http://magma.maths.usyd.edu.au/magma/Examples/node6.html
> a maxima implementation is :
> fc(n):=block(a:0,b:1,c:1,d:n,
> while c<n do
> (k:floor ((b+n)/d), e:k*c-a,f:k*d-b, a:c,b:d,c:e,d:f));

Thx but fc gives no result. (:-))

Adam