
16 Jun
2006
16 Jun
'06
9:28 a.m.
Chris Kuklewicz wrote:
Mathew Mills wrote:
I guess I don't get any points for an approximate solution, ay?
Is there anything that can be done (easily) to reduce the rounding errors?
http://www.google.com/search?q=haskell+exact+real+arithmetic
Using Era.hs (with the patch at http://www.haskell.org/hawiki/ExactRealArithmetic) and add spaces around 1%n to 1 % n (since I have -fglasgow-exts turned on and %n looks like a linear implicit thingie). Now this works:
fib x = let phi,phi' :: CR phi = (1 + sqrt 5) /2 phi' = (1 - sqrt 5)/2 in truncate ( recip (sqrt 5) * (phi^x -phi'^x))
*Era> fib 100 354224848179261915075 which is the (allegedly) correct answer. -- Chris