Re: [Haskell-cafe] Re: speeding up fibonacci with memoizing

2007-11-06 Thread Henning Thielemann
On Tue, 6 Nov 2007, marnes wrote: fib :: Integer - Integer fib n = fibaux n 0 1 1 where fibaux :: Integer - Integer - Integer - Integer - Integer fibaux i a b c | i==0 = a | i/=0 = fibaux (i-1) b c (b+c) http://www.haskell.org/haskellwiki/Memoization

[Haskell-cafe] Re: speeding up fibonacci with memoizing

2007-11-05 Thread marnes
fib :: Integer - Integer fib n = fibaux n 0 1 1 where fibaux :: Integer - Integer - Integer - Integer - Integer fibaux i a b c | i==0 = a | i/=0 = fibaux (i-1) b c (b+c) ___ Haskell-Cafe mailing list

Re: [Haskell-cafe] Re: speeding up fibonacci with memoizing

2007-11-05 Thread Dan Weston
Throwing in a trace statement in fibaux tells me that fibaux i a b c is not being memoized. If I do map fib [7..9], fibaux counts down to 0 afresh for each of 7, 8, and 9. Ideally, in map fib [0..n], fib (i-2) and fib (i-1) should be memoized and fib i would be evaluated in constant time. This

Re: [Haskell-cafe] Re: speeding up fibonacci with memoizing

2007-11-05 Thread Don Stewart
If people write any new variants, please add them to: http://haskell.org/haskellwiki/The_Fibonacci_sequence :) westondan: Throwing in a trace statement in fibaux tells me that fibaux i a b c is not being memoized. If I do map fib [7..9], fibaux counts down to 0 afresh for each of 7, 8,

[Haskell-cafe] Re: speeding up fibonacci with memoizing

2007-02-20 Thread Jón Fairbairn
Thomas Hartman [EMAIL PROTECTED] writes: - I just thought this was interesting, so I would share it. - -- versus, try memoized_fibs !! 1 - memoized_fibs = map memoized_fib [1..] - memoized_fib = ((map fib' [0 ..]) !!) - where - fib' 0 = 0 - fib' 1 = 1 - fib' n =