Make-rational-number-generator John Cowan (08 Feb 2015 01:17 UTC)
Re: Make-rational-number-generator Alex Shinn (16 Feb 2015 02:03 UTC)
Re: Make-rational-number-generator John Cowan (16 Feb 2015 02:29 UTC)
Re: Make-rational-number-generator Alex Shinn (16 Feb 2015 04:39 UTC)

Make-rational-number-generator John Cowan 08 Feb 2015 01:17 UTC

Here's something I found too late to put it into the first draft:

(make-rational-number-generator [ q ] )

Returns a generator of rational numbers starting with q (default 0)
according to the following recurrence:

    x' = (/ 1 (+ (* 2 (truncate x)) 1 (- x)))

It will generate all exact rationals once and only once in in the infinite
sequence 0, 1/2, 2, 1/3, 3/2, 3, 1/4, 4/3, 3/5, 5/2, 2/5, 3/4, 4, ...
It is an error if q is negative or inexact.

What do people think?

--
John Cowan          http://www.ccil.org/~cowan        xxxxxx@ccil.org
Fundamental thinking is ha-ard.  Let's go ideology-shopping.
                        --Philosopher Barbie