RE: Finding primes using a primes map with Haskell and Hugs98

2000-12-20 Thread Shlomi Fish
On Tue, 19 Dec 2000, Simon Peyton-Jones wrote: | Another way to do this is to compute the final array directly, | instead of computing successive versions of the array: | | import Array | primes n = [ i | i - [2 ..n], not (primesMap ! i)] where | primesMap = accumArray (||)

Re: Finding primes using a primes map with Haskell and Hugs98

2000-12-20 Thread George Russell
There are numerous ways of optimising sieving for primes, none of which have much to do with this list. For example, two suggestions: (1) for each k modulo 2*3*5*7, if k is divisible by 2/3/5 or 7, ignore, otherwise sieve separately for this k on higher primes. (Or you might use products of

Re: Finding primes using a primes map with Haskell and Hugs98

2000-12-20 Thread Colin . Runciman
There are numerous ways of optimising sieving for primes, none of which have much to do with this list. For example, two suggestions: (1) for each k modulo 2*3*5*7, if k is divisible by 2/3/5 or 7, ignore, otherwise sieve separately for this k on higher primes. (Or you might use

RE: Finding primes using a primes map with Haskell and Hugs98

2000-12-19 Thread Simon Peyton-Jones
| Another way to do this is to compute the final array directly, | instead of computing successive versions of the array: | | import Array | primes n = [ i | i - [2 ..n], not (primesMap ! i)] where | primesMap = accumArray (||) False (2,n) multList | multList= [(m,True)

Re: Finding primes using a primes map with Haskell and Hugs98

2000-12-17 Thread Adrian Hey
On Fri 15 Dec, Shlomi Fish wrote: There is a different algorithm which keeps a boolean map which tells whether the number at that position is prime or not. At start it is initialized to all trues. The algorithm iterates over all the numbers from 2 to the square root of the desired bound, and

RE: Finding primes using a primes map with Haskell and Hugs98

2000-12-17 Thread Elke Kasimir
Your algorithm seems to be based on the following idea: calculate the non-primes and derive the primes from them by calculating the set difference of the natural numbers and the non-primes. A naive implementation of this idea can be found as primes' in the attachached file. The function

Re: Finding primes using a primes map with Haskell and Hugs98

2000-12-17 Thread Adrian Hey
On Sun 17 Dec, Adrian Hey wrote: You can use a variation of this algorithm with lazy lists.. primes = 2:(get_primes [3,5..]) get_primes (x:xs) = x:(get_primes (strike (x+x) (x*x) xs)) ^^^ Whoops,_|

Re: Finding primes using a primes map with Haskell and Hugs98

2000-12-16 Thread Joe English
Shlomi Fish wrote: As some of you may know, a Haskell program that prints all the primes can be as short as the following: primes = sieve [2.. ] where sieve (p:x) = p : sieve [ n | n - x, n `mod` p 0 ] Now, this program roughly corresponds to the following perl program: [ ~20

Finding primes using a primes map with Haskell and Hugs98

2000-12-15 Thread Shlomi Fish
Hi! As some of you may know, a Haskell program that prints all the primes can be as short as the following: primes = sieve [2.. ] where sieve (p:x) = p : sieve [ n | n - x, n `mod` p 0 ] Now, this program roughly corresponds to the following perl program: ## SNIP SNIP #