
Going back to guarded Eratosthenes, first we notice that though it works with minimal number of prime multiples streams, it still starts working with each prematurely. We could use explicitly mutable monadic arrays ( see below) to remedy this, but we can also think about it a little bit more on the functional side of things still. If the update for each index were an O(1) operation, the empirical complexity would be seen as diminishing, as O(n 1.15.1.05), reflecting the true, linearithmic complexity. Indeed for unboxed arrays (suggested by Daniel Fischer with regular, boxed arrays it is very slow), the above code runs pretty fast, but with empirical complexity of O(n 1.15.1.45) in n primes produced (for producing from few hundred thousands to few millions primes, memory usage also slowly growing). P = import primesToA m = sieve 3 ( array ( 3, m ) | a ! p = sieve ( p + 2 ) $ a // ] | otherwise = sieve ( p + 2 ) a we can directly generate the multiples of a prime p by counting up from it in increments of p, resulting in a variant of the sieve of Eratosthenes. test each new candidate number for divisibility by that prime, giving rise to a kind of trial division algorithm or b. To find out a prime's multiples we can either a. those representable as product of two natural numbers greater than 1. Non-prime numbers are known as composite, i.e. In mathematics, amongst the natural numbers greater than 1, a prime number (or a prime) is such that has no divisors other than itself (and 1).

O'Neill, Melissa E., "The Genuine Sieve of Eratosthenes", Journal of Functional Programming, Published online by Cambridge University Press 9 October 2008 doi:10.1017/S0956796808007004.primes: Efficient, purely functional generation of prime numbers.NumberSieves: Number Theoretic Sieves: primes, factorization, and Euler's Totient.Numbers: An assortment of number theoretic functions.arithmoi: Various basic number theoretic functions efficient array-based sieves, Montgomery curve factorization.

11 Testing Primality, and Integer Factorization.10 Using IntSet for a traditional sieve.7.2 Bitwise prime sieve with Template Haskell.6.3 Calculating Primes in a Given Range.

