SICP — Scheme/JS Structure and Interpretation of Computer Programs — Comparison Edition

[1] This method is reminiscent of the ancient sieve of Eratosthenes, named for Eratosthenes, a third-century BCE Alexandrian Greek mathematician. His sieve finds the primes by repeatedly crossing off the multiples of each prime in turn; although ancient, it has formed the basis for special-purpose hardware sieves that, until the 1970s, were the most powerful tools in existence for locating large primes. Since then, however, these methods have been superseded by outgrowths of the probabilistic techniques discussed in section 1.2.6. But the stream-based method given here is not actually Eratosthenes's sieve: as Melissa E. O'Neill shows in O'Neill 2009, it tests each candidate for divisibility by the primes found so far—a form of trial division—rather than crossing off multiples, and is substantially less efficient than the sieve of Eratosthenes.
[2] We have named these figures after Peter Henderson, who was the first person to show us diagrams of this sort as a way of thinking about stream processing.
[3]
Original JavaScript
This uses the generalized version of stream-map from exercise . This uses the function stream_map_2 from exercise 3.50.
[4] This last point is very subtle and relies on the fact that $p_{n+1} \leq p_{n}^2$. (Here, $p_{k}$ denotes the $k$th prime.) Estimates such as these are very difficult to establish. The ancient proof by Euclid that there are an infinite number of primes shows that $p_{n+1}\leq p_{1} p_{2}\,\cdots\,\, p_{n} +1$, and no substantially better result was proved until 1851, when the Russian mathematician P. L. Chebyshev established that $p_{n+1}\leq 2p_{n}$ for all $n$. This result, originally conjectured in 1845, is known as Bertrand's hypothesis. A proof can be found in section 22.3 of Hardy and Wright 1960.
[5] This exercise shows how call-by-need is closely related to ordinary memoization as described in exercise 3.27. In that exercise, we used assignment to explicitly construct a local table. Our call-by-need stream optimization effectively constructs such a table automatically, storing values in the previously forced parts of the stream.
3.5.2   Infinite Streams