[seqfan] Farey series A006842/A006843

Peter Luschny peter.luschny at googlemail.com
Sun Apr 26 01:02:18 CEST 2009


The following nice non-recursive way
to compute the Farey Tree has been
discussed by Norman Routledge,
"Computing Farey Series," The Mathematical
Gazette, Vol. 29 (No. 523), 55–62 (March 2008).

See also Wikipedia and a recent thread on
comp.soft-sys.math.maple.

Perhaps this Maple code should be added to
A006842/A006843 respectively?

--
FareyNumer := proc(n) local a,b,c,d,k,s;
a := 0; b := 1; c := 1; d := n;
if n=1 then s := 0,1 else s := 0 fi;
while (c < n) do k := iquo(n + b, d);
a, b, c, d := c, d, k*c - a, k*d - b;
s := s,a; od: s end:
--
FareyDenom := proc(n) local a,b,c,d,k,s;
a := 0; b := 1; c := 1; d := n;
if n = 1 then s := 1,1 else s := 1 fi;
while (c < n) do k := iquo(n + b, d);
a, b, c, d := c, d, k*c - a, k*d - b;
s := s,b; od: s end:
--

seq(print(FareyNumer(k)),k=1..5);
seq(print(FareyDenom(k)),k=1..5);

                1, 1
              1, 2, 1
           1, 3, 2, 3, 1
        1, 4, 3, 2, 3, 4, 1
  1, 5, 4, 3, 5, 2, 5, 3, 4, 5, 1

                0, 1
              0, 1, 1
           0, 1, 1, 2, 1
        0, 1, 1, 1, 2, 3, 1
  0, 1, 1, 1, 2, 1, 3, 2, 3, 4, 1

While I was contemplating the output I asked
myself whether these two sequences start at
the same offset. A006842 has offset 1, but
A006843 has offset 0. I am confused.

Cheers Peter




More information about the SeqFan mailing list