[Haskell-cafe] The maths behind the Fastest Fibb In The West.

Erik Rantapaa erantapaa at gmail.com
Sat May 7 02:38:35 UTC 2016



On Friday, May 6, 2016 at 6:46:26 PM UTC-5, Michael Litchard wrote:
>
> I've been working on a project that needs a good fibonacci generator, and 
> I'm to the point where can now improve upon this one: 
> https://wiki.haskell.org/The_Fibonacci_sequence#Fastest_Fib_in_the_West
>
> thanks to this guy:
> https://groups.google.com/forum/#!topic/haskell-cafe/HUgbAUCvCp4
>
> He suggested breaking up a guard into two diffeent functions, which I can 
> do, but I don't know what to call them because I don't know why the 
> operations are different. I'm referring to this section:
>
> fib' (f, g) p
>             | p         = (f*(f+2*g), f^2 + g^2)
>             | otherwise = (f^2+g^2,   g*(2*f-g))
>
> I'd like to know the reason why each guard does two entirely different things, so I know what to call the functions when I seperate them out.
>
>
Clearly `p` is a Bool, and it comes from the expression:

     map (toEnum . fromIntegral) $ unfoldl divs n

What's going on in `toEnum . fromIntegral` is that a remainder (either 0 or 
1 - it blows up for anything else) is being converted to a Bool, with 0 
mapping to False and 1 mapping to True. So `isOdd` would be a more 
descriptive name for `p`.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160506/0e29487e/attachment.html>


More information about the Haskell-Cafe mailing list