In The Original Sieve of Erastosthenes, the author uses a finite-size wheel to skip the control multiples of the first N primes on the trellis. For example, to avoid checking for multiples of 2, 3 , you can start at 5 and alternately add 2 and 4. This is wheel 2 below:
-- wheel 0 = ([2],[1]) -- wheel 1 = ([3,2],[2]) -- wheel 2 = ([5,3,2],[2,4]) -- "start at 5, add 2, 4, 2, 4..." -- wheel 3 = ([7,5,3,2],[4,2,4,2,4,6,2,6])
Its wheel is fully generated at the start of the screening process. This is a compromise since larger wheels require more memory. However, I believe that the underlying wheel generation mechanism is interesting in itself. Given its clearly repeating nature, I ask myself, is it possible to create an “endless wheel” that, like a sieve, presented itself as a stream? This stream would, I think, be the limit of the sequence of lists [1], [2], [2, 4], [4, 2, 4, 2, 4, 6, 2, 6]... - and probably worked as an implementation of primes itself.