3 ms·
> So your suggestion amounts to "compute the Nth Fibonacci number... then do a lot of work to use that value to compute the Nth Fibonacci number". :-) That mig
by eru 17y ago
> So your suggestion amounts to "compute the Nth Fibonacci number... then do a lot of work to use that value to compute the Nth Fibonacci number". :-)
That might just work in a lazy language.
- cperciva 17y agoIt works in non-lazy languages, too... it just happens to be a waste of cycles. :-)
- jcl 17y agoHow? Giving f(N) in terms of f(N) hardly seems useful, in any language. (It's hard to tell if you're joking without a smiley.)
- eru 17y agoI am too dumb / lazy to think of an example for the fibonaccy numbers at the top of my head. But suppose your problem was giving a list of natural numbers, then giving a circular definition like > naturals = 0 : (map (+1) naturals) actually works in Haskell. (In Haskell a:b means the same as (cons a b) in Lisp. I also added parens to make the definition more readable for non-Haskellers.)
- jcl 17y agoSo, that actually works by establishing a base value and a derivation step... i.e., it defines N(0), then it expresses N(n) in terms of N(n - 1). If you try to do the same thing for Fibonacci numbers, you would need to express F(n) in terms of earlier values, not in terms of F(n). What cperciva is jokingly proposing is the equivalent of: naturals = naturals which is hardly helpful for computing the values. Lazy languages would not help you there.