[Haskell-cafe] Application of iterate

ajb at spamcop.net ajb at spamcop.net
Sat Mar 24 22:31:40 EDT 2007

G'day all.

Quoting Henning Thielemann <lemming at henning-thielemann.de>:

> http://darcs.haskell.org/htam/src/Numerics/ZeroFinder/Newton.hs
> with
>   inverse t (\x->(x^2,2*x)) t

The problem with all such solutions was touched on by Longesh:

> > > 20 iterations is a bit arbitrary.

This isn't a one-liner, but there's a straightforward answer to the
"arbitrary" number of iterations: Assuming that the task is to compute a
square root fast, a better solution is to come up with an initial
guess that's good enough such that you only need a fixed number of

This one is as accurate as my CPU's built-in sqrt, and unlike every
other solution posted here, it uses no loops:


But, of course, we're now way off-topic from the original question!

Andrew Bromage

More information about the Haskell-Cafe mailing list