RE: Odd Performance

2002-10-29 Thread Garner, Robin
Title: RE: Odd Performance You may also like to compare this definition. > import List > > primes = unfoldr sieve [2..] > sieve (x:xs) = Just (x,filter (x `notDivisor`) xs) > x `notDivisor` y = y `mod` x /= 0 Slower, but (IMO) cuter. Cheers, -Original Message-

Re: Odd Performance

2002-10-22 Thread Tim Otten
Tom Pledger writes: > Probably. Try replacing this >(\z -> z <= (intsqrt x)) > with this >(\z -> z^2 <= x) Yes! This is significantly nicer. Taking 4000 primes, this is about twice as fast as the original (loose) algorithm, and it appears that it gets better as n grows. (Call this versio

Odd Performance

2002-10-22 Thread Tom Pledger
Tom Pledger writes: | Tim Otten writes: | : | | Can anyone suggest why the tighter algorithm exhibits significantly | | worse performance? Is takeWhile significicantly more expensive than | | take? | | No. Correction (before anyone else pounces on it): Only if the predicate function (

Odd Performance

2002-10-22 Thread Tom Pledger
Tim Otten writes: : | Can anyone suggest why the tighter algorithm exhibits significantly | worse performance? Is takeWhile significicantly more expensive than | take? No. | Is the \z lambda expression expensive? No. | The intsqrt isn't recalculated each time takeWhile evalutes a | prime

Odd Performance

2002-10-22 Thread Tim Otten
As a student in an undergraduate 'Intro to Discrete Structures' course, I recently did a project which required generating the first n primes. We discussed the sieve of Eratosthenes in class. Although the professor is not familiar with Haskell, he allowed me to use it, and I mistakenly wrote the fo