   Main Page | See live article | Alphabetical index

In mathematics, the Fibonacci numbers form a sequence defined recursively by the following equations:

F(0) = 0
F(1) = 1
F(n + 2) = F(n) + F(n + 1) for all n ≥ 0.

Alternatively the recurrence can be given by
F(0) = 1
F(1) = 1
F(n) = F(n-1) + F(n-2)
This definition may be more common, but it is equivalent to the one above up to a shift of indices.

In words: you start with two ones, and then produce the next Fibonacci number by adding the two previous Fibonacci numbers. The first Fibonacci numbers are

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657...

 Table of contents 1 Origins 2 Explicit formula 3 Computing Fibonacci numbers 4 Applications 5 Generalizations 6 Algorithm 7 Identities

## Origins

This sequence was first described by Leonardo of Pisa, who was known as Fibonacci (ca. 1200), to describe the growth of a rabbit population. The numbers describe the number of pairs in a (somewhat idealized) rabbit population after n months if it is assumed that

• the first month there is just one newly born pair,
• newly born pairs become productive from their second month on,
• we have no genetic problems whatsoever generated by inbreeding,
• each month every productive pair begets a new pair, and
• the rabbits never die

The formula above applies to the rabbit problem because if in month n we have "a" rabbits and in month n+1 we have "b" rabbits then in month n+2 we'll necessarily have a+b rabbits. That's because we know each rabbit basically gives birth to another each month (actually each pair gives birth to another pair, but it's the same thing) and that means that all "a" rabbits give birth to another number of "a" rabbits which will become fertile after two months, which is exactly at month n+2. That's why we have the population at moment n+1 (which is "b") plus exactly the population at moment n (which is "a").

The term Fibonacci sequence is also applied more generally to any function g where g(n + 2) = g(n) + g(n + 1). These functions are precisely those of the form g(n) = aF(n) + bF(n + 1) for some numbers a and b, so the Fibonacci sequences form a vector space with the functions F(n) and F(n + 1) as a basis. In particular, the Fibonacci sequence with F(1) = 1 and F(2) = 3 is sometimes referred to as the Lucas numbers.

## Explicit formula

As was pointed out by Johannes Kepler, the growth rate of the Fibonacci numbers, that is, F(n + 1) / F(n), converges to the golden mean, denoted φ. This is the positive root of the quadratic equation x2 - x - 1 = 0, so φ2 = φ + 1. If we multiply both sides by φn, we get φn+2 = φn+1 + φn, so the function φn is a Fibonacci sequence. The negative root of the quadratic, 1 - φ, can be shown to have the same properties, so the two functions φn and (1-φ)n form another basis for the space.

By adjusting the coefficients to get the proper initial values F(0) = 0 and F(1) = 1, we obtain

This result can also be derived using the technique of generating functions, or the technique of solving linear recurrence relations.

As n goes to infinity, the second term converges to zero, so the Fibonacci numbers approach the exponential φn / √5, hence their convergent ratios. In fact the second term starts out small enough that the Fibonacci numbers can be obtained from the first term alone, by rounding to the nearest integer.

## Computing Fibonacci numbers

Computing Fibonacci numbers by computing powers of the golden mean is not very practical except for small values of n, since rounding errors will accrue and floating point numbers usually don't have enough precision.

The straightforward recursive implementation of the Fibonacci sequence definition is also not advisable, since it would compute many values repeatedly (unless the programming language has a feature which allows the storing of previously computed function values). Therefore, one usually computes the Fibonacci numbers "from the bottom up", starting with the two values 0 and 1, and then repeatedly replacing the first number by the second, and the second number by the sum of the two.

For huge arguments and if a bignum system is being used, a faster way to calculate Fibonacci numbers uses the following matrix equation:

and employs exponentiating by squaring.

## Applications

The Fibonacci numbers are important in the run-time analysis of Euclid's algorithm to determine the greatest common divisor of two integers.

Matiyasevich was able to show that the Fibonacci numbers can be defined by a Diophantine equation, which led to his original solution of Hilbert's tenth problem.

The Fibonacci numbers occur in a formula about the diagonals of Pascal's triangle (see binomial coefficient).

An interesting use of the Fibonacci sequence is for converting miles to kilometers. For instance, if you want to know about how many kilometers 5 miles is, take the Fibonacci number (5) and look at the next one (8). 5 miles is about 8 kilometers. This works because it so happens that the conversion factor between miles and kilometers is roughly equal to φ.

A logarithmic spiral can be approximated as follows: start at the origin of the cartesian coordinate system, move F(1) units to the right, move F(2) units up, move F(3) units to the left, move F(4) units down, move F(5) units to the right etc. This is similar to the construction mentioned in the golden mean article. Fibonacci number s often occur in nature when logarithmic spirals are built from discrete units, such as in sunflowers or in pine cones.

In music fibonacci numbers are sometimes used to determine tunings, and, as in visual art, to determine the length or size of content or formal elements. Examples include Bela Bartok's Music for Strings, Percussion, and Celesta.

## Generalizations

A generalization of the Fibonacci sequence are the Lucas sequences. One kind can be defined thus:

L(0) = 0
L(1) = 1
L(n+2) = PL(n+1) + QL(n)

where the normal Fibonacci sequence is the special case of P = Q = 1. Another kind of Lucas Sequence begins with L(0) = 2, L(1) = P. Such sequences have applications in number theory and primality proving.

## Algorithm

```(define fab
(lambda (x)
(if (< x 2)
x
(+ (fab (- x 1)) (fab (- x 2))))))
```

This algorithm runs in O(F[n]) time, since it uses tree recursion and often unnecessarily recalculates values. This algorithm (also in Scheme) runs in O(n) time, much faster:

```(define (fab x)
(define (fab-iter x a b)
(if (= x 0)
a (fab-iter (- x 1) b (+ a b))
)
)
(fab-iter x 0 1)
)
```

Since this algorithm proceeds iteratively, each fibonnaci value is calculated at most once, rather than several times as in the first algorithm.

The first algorithms is called recursive, while the second algorithm, while not quite iterative, is tail-end recursive. Tail-end recursion is practically iteration with regard to running time, since the processes are roughly equivalent.

## Identities

F(n+1) = F(n) + F(n-1)

F(0) + F(1) + F(2) + ... + F(n) = F(n+2) - 1

0*F(0) + 1*F(1) + 2*F(2) + 3*F(3) + ... + n*F(n) = nF(n+2) - F(n+3) + 2 (Found by T. Belulovich)  