Professional Documents
Culture Documents
02 Naccifibo
02 Naccifibo
Recurrence Relations
“A certain man put a pair of rabbits in a place surrounded by a wall. How many pairs
of rabbits can be produced from that pair in a year if it is supposed that every month each
pair begets a new pair from which the second month on becomes productive? ”
The sequence considers the growth of a (slightly unrealistic) population of rabbits. The
rules governing the growth of the population of rabbits are as follows
• A newborn pair of rabbits, one male, one female, are put in a field.
• Rabbits are able to mate at the age of one month so that at the end of its second
month a female can produce another pair of rabbits.
• Rabbits never die and a mating pair always produces one new pair (one male, one
female) every month from the second month on.
Fibonacci asked, “how many pairs of rabbits will there be at the end of one year?”
1
2 Analysis
We analyse the problem as follows
• At the end of month one the rabbits mate. There is still only 1 pair.
• At the end of month two the female gives birth to a new pair. There are 2 pairs of
rabbits.
• At the end of month three, the original female gives birth to a second pair. There
are 3 pairs of rabbits.
• At the end of the fourth month, the original female gives birth to another new pair.
The female born two months ago gives birth to a pair. There are 5 pairs of rabbits.
At the end of the nth month, the number of pairs of rabbits is equal to the number of
new pairs (which is the number of pairs in month n − 2) plus the number of pairs alive
last month (n − 1). This is the nth Fibonacci number. The Fibonacci Sequences begins
0, 1
and continues according to the rule that each number in the sequence is the sum of the
previous two numbers in the sequence. The first eight terms in the Fibonacci sequence
are shown below
0, 1, 1, 2, 3, 5, 8, 13, . . .
2
3 Recurrence Relations
Let’s use the notation Fn to represent the nth entry in the Fibonacci sequence so for
example
F0 = 0
F1 = 1
F2 = 0+1=1
F3 = 1+1=2
F4 = 1+2=3
F5 = 2+3=5
F6 = 3+5=8
.. .. ..
. . .
This notation enables us to write down a simple formula for the nth Fibonacci number
Fn = Fn−1 + Fn−2
for n ≥ 2. This type of formula is often referred to as a recursive formula or as a
recurrence relation. recurrence relations are very useful in computer science and they
can be used to illustrate lots of nice concepts including loops and iteration.
Exercise
Find the first twenty Fibonacci numbers.
Th Fibonacci recurrence is a nice formula but it has one unpleasant aspect. In order
to calculate the nth Fibonacci number we need to know the previous two and when n is
large this can be extremely tedious and time consuming. What we would really like is
a formula for the nth Fibonacci number which doesn’t require such calculations. Such
a formula could be considered a solution to the recurrence relation. In fact there
is a formula which generates the nth Fibonacci number known as Binet’s Formula. The
derivation of this formula is beyond the scope of this course but the formula itself is given
below.
φn − (−φ)−n
Fn = √ ,
5
√
1+ 5
where φ = 2
the golden ratio!
3
Example
Solution:
√ 30 √
(1 + 5) − (1 − 5)30
F30 = √
230 5
= 832040
x2 − x − 1 = 0.
Using the quadratic formula to solve this equation we can obtain it’s value and we give
it the symbol φ.
√
1+ 5
φ = = 1.6180339887 . . .
2
We say that two quantities a and b are in the golden ratio to each other if
a+b a
= = φ.
a b
In the image below this ratio is illustrated using line segments.
It turns out that if we divide successive Fibonacci numbers by each other that this
quantity gets closer and closer to the golden ratio! We’ll illustrate this for the first ten
Fibonacci numbers.
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, . . .
4
1
= 1
1
2
= 2
1
3
= 1.5
2
5
= 1.666666667
3
8
= 1.6
5
13
= 1.625
8
21
= 1.615384615
13
34
= 1.619047619
21
55
= 1.617647059
34
89
= 1.618181818
55
144
= 1.617977526
89
233
= 1.618055556
144
377
= 1.618025751
233
We can see that the ratio of successive Fibonacci numbers does appear to be getting ever
closer to the golden ratio.
5 Generalizations
We can generalize the properties of the Fibonacci sequence to obtain other sequences.
0, 1, 1, 2, 3, 5, 8, 13, . . .
What number must come before zero? We know that Fn = Fn−1 + Fn−2 . Using some
simple algebra we have
Fn = Fn−1 + Fn−2
Fn−2 = Fn − Fn−1
5
And hence the number that comes before zero in the Fibonacci sequence is
Fn−2 Fn−1 Fn
? 0 1
given by Fn−2 = 1 − 0 = 1 which gives
1, 0, 1, 1, 2, 3, 5, 8, 13, . . .
−1, 1, 0, 1, 1, 2, 3, 5, 8, 13, . . .
You might have notice that F−n = (−1)n+1 Fn . More terms give
. . . , −144, 89, −55, 34, −21, 13, −8, 5, −3, 2, −1, 1, 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, . . .
Charles Darwin actually observed this sequence inadvertently while studying elephant
populations in the 1800s.