[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

This page is part of the web mail archives of SRFI 121 from before July 7th, 2015. The new archives for SRFI 121 contain all messages, not just those from before July 7th, 2015.

*To*: John Cowan <cowan@xxxxxxxxxxxxxxxx>*Subject*: Re: Make-rational-number-generator*From*: Alex Shinn <alexshinn@xxxxxxxxx>*Date*: Mon, 16 Feb 2015 11:03:05 +0900*Cc*: srfi-121@xxxxxxxxxxxxxxxxx*Delivered-to*: srfi-121@xxxxxxxxxxxxxxxxx*Dkim-signature*: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=sYirJkNFyFxRq2nDJCSzMJE6sVMySgDaIZ07XRXqJeE=; b=GFMZTY0Y7cT9c12xKsApZ2vn5AECj3Gt/jKpV5Ji5EJquZMKb0pJkwSqdxwiacJT/v 605YUgp3NeGMtO6E5hvVjqvjjh4wjOlHULWDKhbH0BFV4qBhHKoEovu+BOUA661pT4Z1 SRbUQopcqkpugXX9MIhkZxB0I30YZh60rSfuwRRuygJBYtM3JKU750EwARGVxi4Am7fB +Eg3219h+0q2nkNG3pqKHCntv4bkiNLq/oOH2lqG+EkfHeeb8sljVtZoVzFB8cDqQD9C X0h5/UQDGzhwgv1sahvBFjPGqKF3D73/UtYpyUROikt1b80Nj9SecYirSFXKzba91uL5 tRwg==*In-reply-to*: <20150208011715.GH14765@mercury.ccil.org>*References*: <20150208011715.GH14765@mercury.ccil.org>

On Sun, Feb 8, 2015 at 10:17 AM, John Cowan <cowan@xxxxxxxxxxxxxxxx> wrote:

You could also use a more intuitive diagonalization order, at the

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, ...

Cute. Proof? (you missed 1 after 0)

You could also use a more intuitive diagonalization order, at the

cost of some busy work to filter non-reduced forms.

I like this since it stands as proof of the countability of the rationals.

Even it not too useful it strikes well with Scheme's affection for math.

If we need to rationalize a use, it could always be helpful in testing,

to make sure something works for the first n rationals.

--

Alex

**Follow-Ups**:**Re: Make-rational-number-generator***From:*John Cowan

**References**:**Make-rational-number-generator***From:*John Cowan

- Prev by Date:
**Re: Make-rational-number-generator** - Next by Date:
**Re: Make-rational-number-generator** - Previous by thread:
**Re: Make-rational-number-generator** - Next by thread:
**Re: Make-rational-number-generator** - Index(es):