Wed, 23 Oct 2002 10:22:49 +1300
Tim Otten writes:
| Can anyone suggest why the tighter algorithm exhibits significantly
| worse performance? Is takeWhile significicantly more expensive than
| Is the \z lambda expression expensive?
| The intsqrt isn't recalculated each time takeWhile evalutes a
| prime, is it?
Probably. Try replacing this
(\z -> z <= (intsqrt x))
(\z -> z^2 <= x)
or moving the O(sqrt(n)) step into a let expression
let zmax = intsqrt x in ... (\z -> z <= zmax) ...
| Slightly confused,
| Tim Otten
|  Note that intsqrt calculates the floor of the square root of x.
| intsqrt x = intsqrt' 1 x
| intsqrt' n x
| | (n*n > x) = n-1
| | otherwise = intsqrt' (n+1) x