Farey sequence



Hi,

What about this :

/* setify converts list to set, orders elements and removes duplicates */
F(n):=
block(
[a],
a:[0/1,1/1],
if n>=2 then
for denominator:2 thru n step 1 do
for numerator:1 thru (denominator-1) step 1 do
 a:cons(numerator/denominator,a),
  return(setify(a))
);


It is much faster :


Farey(n) 	Evaluation took 1.3600 seconds (1.3600 elapsed)
F(n)		Evaluation took 0.0600 seconds (0.0600 elapsed)
fc(n) 		Evaluation took 0.3400 seconds (0.3400 elapsed)
fc2(n)		Evaluation took 0.0300 seconds (0.0300 elapsed)
fc3(n)		Evaluation took 0.0500 seconds (0.0500 elapsed)
ff(n)		Evaluation took 0.0600 seconds (0.0600 elapsed)
ff2(n)		Evaluation took 0.0400 seconds (0.0400 elapsed)
h(n)		Evaluation took 0.0600 seconds (0.0600 elapsed)


I do not know how to compare Lisp functions.

Also please look at :
www.math.harvard.edu/~corina/publications/farey.pdf


Adam