The Fibonacci numbers can be computed in O(1) time using the closed-form expression Fₙ = (φⁿ - ψⁿ)/√5, where φ = (1+√5)/2 is the golden ratio and ψ = (1-√5)/2 is its conjugate. This formula is derived using two mathematical techniques: generating functions (which transform the recursive definition into a rational function f(x) = x/(1-x-x²), then decomposing it into partial fractions involving geometric series with quotients φ and ψ), and eigenvalue decomposition (applying the spectral theorem to the Fibonacci matrix [[1,1],[1,0]], whose eigenvalues are exactly φ and ψ, allowing efficient computation of matrix powers that reveal the Fibonacci sequence).
Closed-Form Fibonacci Numbers via Generating Functions & Linear Algebra
Added:Because of its recursive nature, computing the Fibonacci sequence via brute force is computationally expensive. However, the Fibonacci numbers have a simple and beautiful closed form expression written in terms of the golden ratio and the conjugate golden ratio.
In this video, we are going to derive it from first principles, learning two powerful mathematical techniques along the way, generating functions and value decompositions. First, let's zoom in on the Fibonacci numbers. The zero Fibonacci number F0 is zero.
The first Fibonacci number F1 is one.
And by definition, the rest are given by the sum of the two preceding Fibonacci numbers.
Because of this, they grow insanely fast.
But that's not the problem. Let's take a look at what happens when we compute the Fibonacci numbers recursively.
f_sub_0 and f_sub_1 are given. These are our terminating conditions.
To find f_sub_2, we compute f_sub_1 and f_sub_0.
To find f_sub_3, we compute f_sub_2 and f_sub_1.
To find f_sub_4, we compute f_sub_3 and f_sub_2 and so on. When computing the Fibonacci numbers recursively, the number of function calls also grows insanely fast.
How fast? Let's see. F0 and F_sub_1 require only one call as they are terminating conditions.
F_sub_2 requires three calls. F_sub_3 requires five. F_sub_4 requires nine. F5 requires 15 and so on. In general, fn requires 2 * fn + one minus one function call. This is a problem in practice.
How to solve this?
First attempt finding an explicit formula via generating functions.
But what are generating functions?
Suppose that we have a sequence a n which we slap onto a power series as coefficients.
The resulting expression is called the generating function of a n.
There are all sorts of potential issues raised by the convergence properties of power series, but we won't deal with them.
For our purposes, a generating function is a clos line on which we hang up a sequence of numbers for display. As Herbert Wolf phrases it in his book generating functionality which is the book on the subject we are only interested in the combinatorial properties of generating functions.
Let's see an example. The generating function of the binomial coefficients.
If we take n / k multiply it by x to the k and sum over k we obtain the polomial 1 + x to the n.
This is given by the famous Newton's binomial theorem.
Another example 1 / n factorial whose generating function is our good old friend the exponential function.
One more example the most important one for our purposes the geometric series.
If we take q to the n, multiply it by x to the n and sum over n, we obtain the rational function 1 / 1 - q * x.
Q is called the quotient of the series.
Yes, I know convergence and whatever, but let's suspend our mathematical precision and go rack and roll with generating functions.
The generating function we want to study is the Fibonacci generating function defined by f ofx.
How can we find an explicit formula for fn with the help of f ofx?
Simple. If the generating functions for the sequences a n and bn are equal, then a n and bn must be equal as well.
Let's get to it. We start by unwrapping the definition of f ofx. Writing out the terms one by one. f ofx= f0 plus f_sub_1 * x + f_sub_2 * x^2 and so on.
Let's focus our attention on the third term f_sub_2 * x 2.
We can use the recursion here and write it as f_sub_0 + f_sub_1 * x^ 2.
Similarly, we can write the fourth term f_sub_3 * x cub as f_sub_2 + f_sub_1 * x cub.
We can do this for all subsequent terms.
For simplicity, let's unwrap the parenthesis and write f ofx in a more suggestive form.
Now the part f0 * x^2 + f_sub_1 * x cubed and so on can be written as x^2 * f_sub_0 + f_sub_1 * x and so on.
Similarly, f_sub_1 * x^2 + f_sub_2 * x cub and so on can be written as x * f_sub_1 * x + f_sub_2 * x^ 2 and so on.
Lucky for us, both power series in the parenthesis equal f ofx where we use the fact that f0 equals to zero.
Thus, we obtain the functional equation f ofx = f_sub_0 plus f_sub_1x + x * fx + x^2 * fx.
We can simplify this even further. As f0 equals zero and f_sub_1 = 1, we get that f ofx = x + x * f(x) + x^2 * f(x).
By arranging all the terms with f ofx on one side of the equation, we arrive at f ofx minus x * fx - x^2 * fx = x.
One last step. Now we can factor out f ofx and divide both sides by the polomial term 1 - x - x^2 which gives the closed form expression fx = x over 1 - x - x^2.
We are at the finish line. I'm not going to spell out all the details, but with the magic of partial fraction decomposition, we obtain that f ofx is a linear combination of two familiar terms. The generating functions of geometric series. The quotient of the first term is 1 +<unk> 5 / 2 otherwise known as the golden ratio. The quotient of the second term is 1 minus<unk> 5 / 2, otherwise known as the conjugate golden ratio.
Note that the golden ratio minus the conjugate golden ratio is 1 / the square root of 5.
Now we can interchange the operations with the infinite sum to arrive at our desired formula.
Can you recall the most useful property of generating functions?
two generating functions are equal if and only if the underlying sequences are the same. Now you can see where we are going with this.
With the help of generating functions, we obtained the welldeserved result, the non-recursive formula for Fibonacci numbers.
Even though generating functions are powerful and fun to use, I have to admit we did a bunch of sketchy stuff to get here. I'm a mathematical analyst at heart and I can't just overlook issues like rearranging the terms of an infinite sum or interchanging it with operations.
So what's the solution?
I'll show you another way. This time with linear algebra.
Let's talk about the Fibonacci matrix.
Let F be a simple 2x2 matrix. The first row is one one while the second row is one zero.
If we square F, we obtain the matrix 2 1 and 1 1.
The cube of F is 3 2 and 2 1.
Let's see a couple more powers. Here's F to the 4 and here's F to the 5.
Do you see the general pattern? The nth power of f contains the Fibonacci numbers f n + one fn and fn fn minus one.
Here's a property of f that hints at what we are about to do. F is invariant to matrix transposition. That is it is symmetric.
You guessed right. We are going to apply the spectra theorem for real symmetric matrices otherwise known as the value de composition theorem. It states that if a is a real and symmetric square matrix then there exists a p such that a equ= p * diagonal matrix time the inverse of p where the diagonal matrix contains the values of a.
This is an extremely powerful theorem which we are applying to a simple problem. In mathematical terms, we are about to shoot a bird with a cannon.
Let's call this diagonal matrix D to simplify the towering computations that we are about to do.
Now let's square our matrix A using the value decomposition.
As matrix multiplication is associative, we can eliminate the ps in the middle obtaining that a²= p * d² * the inverse of p.
Continuing this process, we get that a to the n = p * d to the n * the inverse of p.
Fortunately for us, computing the nth power of a diagonal matrix is simple. We just have to raise the diagonal elements to the n.
Now recall that the nth power of the Fibonacci matrix is given by the Fibonacci numbers.
Using the value decomposition of f, we'll eventually arrive at the nonrecursive formula for the Fibonacci numbers.
Let's get to work. To compute the igen values of f, we have to solve a quadratic equation given by the determinant of f - x * the identity matrix.
This determinant is given by x^2 - x - 1.
By plugging the coefficients into the quadratic solution formula, we see that the roots of x^2 - x -1 are given by the golden ratio and the conjugate golden ratio.
After crunching some numbers and matrices, we obtain the value decomposition of f by raising it to the n's power. We can already see the formula emerging.
After making some room on the screen for the incoming computation, we begin by unwrapping the first matrix product.
Now we can easily compute the top left element of the final product. We don't care about the others.
By comparing the result of our computation with the nth power of f, we get the desired formula.
Here it is once more in its full glory.
Even though the non-recursive formula directly computes the nth Fibonacci number, it involves working with floats which introduces numerical issues.
In practice, we are better off computing the powers of f.
However, if you think about it for a second, this is quite a remarkable formula.
First, it establishes a precise relation between the golden ratio and the Fibonacci numbers.
Second, even though the golden ratio and its conjugate are irrational numbers, the result is an integer.
In addition, it teaches us a valuable lesson on power series and symmetric matrices. When calculus, algebra, and combinatorics intersect, powerful tools emerge.
Thanks for watching and see you in the next video. Cheers.
Up Next

Recurrence Relations via Generating Functions | Discrete Math Tutorial
@discretemathematics9972
62.8K views•2021-02-20

Gain Recalibration in Hippocampal Path Integration: Math Theory
@1024kyz
144 views•2020-07-02

Fourier Series Introduction: The Big Idea Explained
@DrTrefor
387K views•2021-05-03

The Mathematical Impossibility of Accurate World Maps
@Vox
23.3M views•2016-12-02
Related Study Plans & Knowledge Roadmaps
Structured learning paths in Mathematics






























![1.6 Exercises [Lecture 1 - Combinatorial structures and OGFs]](https://i.ytimg.com/vi/ux8UCjYDKPw/hqdefault.jpg?sqp=-oaymwEmCOADEOgC8quKqQMa8AEB-AHUBoAC4AOKAgwIABABGCwgPSh_MA8=&rs=AOn4CLC6kNq4x6sYx0CkkWZB697S2aiUgA)








