unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Ian Price <ianprice90@googlemail.com>
To: Panicz Maciej Godek <godek.maciek@gmail.com>
Cc: "guile-user@gnu.org" <guile-user@gnu.org>,
	guile-devel <guile-devel@gnu.org>
Subject: Re: Fun with guile, Erastones + goldbach conjecture
Date: Wed, 10 Apr 2013 01:18:36 +0100	[thread overview]
Message-ID: <87sj2z1bmr.fsf@Kagami.home> (raw)
In-Reply-To: <CAMFYt2bdBdGuz53Mgpgm5SewJHM5pcfrBhkpQg_ei7mgD=VnnQ@mail.gmail.com> (Panicz Maciej Godek's message of "Tue, 9 Apr 2013 21:35:04 +0200")

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=iso-2022-jp-2, Size: 2229 bytes --]

Panicz Maciej Godek <godek.maciek@gmail.com> writes:

> Section 3.5 (Streams), which introduces the notion
> of streams, or lazy lists (that can be infinite), with the
> most amazing example of Erastostenes' sieve^[,A ^[(B
> implementation, as well as sections^[,A ^[(B4.1^[,A ^[(Band^[,A ^[(B4.3^[,A ^[(Bof

My pedant sense is tingling :P

Two concerns here.

First, lazy lists as presented in SICP are subject to off-by-1 coding
problems. You see it throughout the streams chapter, and in the
non-deterministic evaluator chapter by occasional smatterings of 'force'
and 'delay' about the place.  In the next release of Guile, we will have
an implementation of SRFI 41[0], which does not have these problems.

Secondly, that is not actually the sieve of Eratosthenes, but Trial
Division.  Melissa E. O'Neill has a lovely paper about this[1], giving
performances analyses of both.

And before you object to me calling SICP's sieve ^[$B!H^[(Bfake^[$B!I^[(B...
^[$B!H^[(BSome readers may feel that despite all of these concerns, the earlier
algorithm is somehow ^[$B!H^[(Bmorally^[$B!I^[(B the Sieve of Eratosthenes. I would
argue, however, that they are confusing a mathematical abstraction drawn
from the Sieve of Eratosthenes with the actual algorithm. The
algorithmic details, such as how you remove all the multiples of 17,
matter.^[$B!I^[(B

I have an implementation of the genuine sieve available[2], that you
will be able to run when the next release comes out. (Needs pfds).

Okay, pedant sense sufficiently exercised for now.

SICP is a fine book IMO, but it isn't perfect. Section 3 is not
fantastic, for a variety of reasons, and I feel people are better served
learning recursion on recursive data structures (like lists or trees),
rather than the way SICP does with numbers (yes, the naturals are
recursive, but many of the algorithms, like fast-exponentiation, rely on
recursion other than on the predecessor).

0. http://srfi.schemers.org/srfi-41/srfi-41.html
1. http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf
2. https://github.com/ijp/ijputils/blob/master/streams.sls#L73
-- 
Ian Price -- shift-reset.com

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"



  reply	other threads:[~2013-04-10  0:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-08 22:03 Fun with guile, Erastones + goldbach conjecture Stefan Israelsson Tampe
2013-04-09 10:24 ` Stefan Israelsson Tampe
2013-04-09 19:35   ` Panicz Maciej Godek
2013-04-10  0:18     ` Ian Price [this message]
2013-04-10  0:11 ` Ian Price

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87sj2z1bmr.fsf@Kagami.home \
    --to=ianprice90@googlemail.com \
    --cc=godek.maciek@gmail.com \
    --cc=guile-devel@gnu.org \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).