Recursion is awesome for writing some functions, like searching trees etc but wow how can it be THAT much slower for computing fibonacci- numbers?
is the recursive definition counting fib 1 to fib x-1 for every x? is that what lazy evaluation in functional languages avoids thus making recursive versions much faster? is recursive fibonacci in haskell as fast as an imperative solution in a procedural language? def fibr(nbr): if nbr > 1: return fibr(nbr-1) + fibr(nbr-2) if nbr == 1: return 1 if nbr == 0: return 0 def fibf(n): sum=0 a=1 b=1 if n<=2: return 1 for i in range(3,n+1): sum=a+b a=b b=sum return sum i found a version in Clojure that is superfast: (def fib-seq (concat [0 1] ((fn rfib [a b] (lazy-cons (+ a b) (rfib b (+ a b)))) 0 1))) (defn fibx [x] (last (take (+ x 1) fib-seq))) (fibx 12000) is delivered instantly. is it using lazy evaluation? -- http://mail.python.org/mailman/listinfo/python-list