Farey sequence



Suggestions:

 (0) Read about the Maxima function "adjoin" and try converting your function to use sets
     instead of lists--for an n element set S, the time complexity of adjoin(x,S) is log_2(n),
     I think. For an n element list l, the time complexity for member(x,l) is n. 
     
?(1) Try bounding the time complexity of your code.

?(2) Do a web search on "Farey" and try bounding the time complexity of each algorithm you find.

 (3) Using "denom" or "num" as identifiers can cause trouble because there are Maxima functions
     with these names.

--Barton

-----maxima-bounces at math.utexas.edu wrote: -----


>I?try?to?compute?Farey?sequences.
>I?have?made?function?:
>
>Farey(n):=
>block(
>[a],
>a:[0/1,1/1],
>if?n>=2?then
>for?denom:2?thru?n?step?1?do
>for?num:1?thru?(denom-1)?step?1?do
>??if?(not?member(num/denom,a))?then?a:cons(num/denom,a),
>??return(a)
>);
>
>It?seems?to?work.
>Is?it?true?or?can?it?be?done?better??
>
>
>Adam
>
>_______________________________________________
>Maxima?mailing?list
>Maxima at math.utexas.edu
>http://www.math.utexas.edu/mailman/listinfo/maxima