In continuation with the theme of the last lecture we define another infinite series --- the fibonacci series. Ofcourse all of you know the Fibonacci Series. It is defined by the linear recurrence relation . We assume that and to begin with.
The defintion is straight forward; it is just a one liner, but we use this as an excuse to introduce two standard list functions
The zip of the list and is the list of tuples where is the minimum of and .
1 |
|
The function zipWith
is a general form of ziping which instead of tupling combines the values with an input functions.
1 |
|
We can now give the code for fibonacci numbers.
1 |
|
Notice that the zip of fib
and tail fib
gives a set of tuples whose caluse are consecutive fibonacci numbers. Therefore, once the intial values are set all that is required is zipping through with a (+)
operation.