Alex Rivera | Logout

Is this Fibonacci sequence function recursive?

Asked 2010-10-20T17:45:09.937
10

Consider the following (Haskell) code:

fib=0:1:zipWith (+) fib (tail fib)

A coworker is trying to assert that this is not a recursive function because fib is simply a list that defines itself with itself and that is somehow different than a function that does the same. I think he's smoking crack.

What do you think?

Edit
Report

2 Answers

3

The example you've given is recursive. But the Fibonacci sequence by nature doesn't have to be. There are iterative versions of the algorithm, and even explicit functions.

answered 2010-10-20T17:54:56.920
2

Aside from the Haskell implementation here, the Fibonacci Numbers are a sequence defined by a recurrence relation. Mathematically speaking, each term is defined as a function of the preceding terms. Defeat him with mathematical semantics.

answered 2010-10-20T17:59:13.797

Your Answer