Solving Linear Recurrences
In this article, we'll discuss how to solve both homogenous and non-homogenous linear recurrences with constant coefficients. If you already know what linear recurrences are and all of the vocabulary surrounding them, feel free to just skip to the next section to see how to solve homogenous and non-homogenous linear recurrences. If you're unfamilar with some of these terms, the first section goes over the basic definitions regarding linear recurrences.
Definitions
Recurrence Relation
Definition
A recurrence relation is an equation that relates the next term in a sequence of numbers as a function of the terms preceding it.
A classic recurrence relation is the Fibonacci sequence:
Note that when actually calculating the values of the recursive sequence, we need more than just the recurrence relation. We also need initial values for our sequence that we can use to calculate the rest of the sequence. In this case, we can use the values of and to calculate . Once we solve for this, we can then use and the recently calculated to solve for , and so on.
Linear
A linear recurrence relation is a recurrence relation that only contains linear multiples of previous terms. That is, there can be no terms in the recurrence relation such as or . Instead, you can only have first degree terms.
Here are a few examples of linear recurrences:
On the other hand, here are a few non-linear recurrences:
In general, linear recurrences are much easier to calculate and solve than non-linear recurrence relations. As a result, this article will be focused entirely on solving linear recurrences.
Degree
In the case of the Fibonacci sequence, the recurrence relation depended on the previous values to calculate the next value in the sequence. This means that the Fibonacci relation has degree .
Here's an example of a relation with degree since the next value of depends on the previous values of .
However, the following recurrence relation still has degree even though it doesn't depend on necessarily terms:
It is only the farthest back term that matters when calculating degrees, so it doesn't matter if the term was skipped. Here's the more formal definition of the degree of a linear recurrence relation:
Definition
A linear recurrence relation has degree if and only if it can be expressed in the form
with and .
Homogenous vs Non-Homogenous
There are two primary types of linear recurrences: homogenous and non-homogenous.
Definition
A recurrence relation is homogenous if the degree of all terms in the equation is the same.
When a recurrence relation is linear, which we will assume for the remainder of this article, homogenous vs non-homogenous becomes much simpler. In this case, since linear implies that the degree of all of our terms have a power of at most , the only other terms that could appear are constant terms / polynomials of . To see what this means, it's best to look at a few examples.
All of the previous examples of linear recurrence relations in this article were actually homogenous relations, so here are a few non-homogenous ones:
Note that we can actually separate non-homogenous recurrence relations into two parts: a homogenous part and then some polynomial . This will be key to solving the relation later.
What It Means to "Solve" a Linear Recurrence
First, we have to clarify what it even means to "solve" a linear recurrence. After all, if we're given enough initial values and the recurrence relation, we can solve for any value of the sequence through just plug and chug. However, this can be extremely slow for huge values of , making an explicit formula very desirable. The idea of "solving" a recurrence relation is to find some function such as that we can plug a huge value of into directly to find the value of . This function is known as the closed-form expression for .
For instance, the Fibonacci numbers have the following closed-form expression known as Binet's Formula:
To calculate any value of , we can just plug into this formula rather than have to compute all values of up to the desired . To show how this works, let's try to calculate . From just applying the recurrence relation of the Fibonacci sequence, we get:
On the other hand, we can use Binet's formula to calculate the value for us directly without having to go through through . Unfortunately, Binet's formula is not very friendly since it has this nasty binomial power that will require just as much work, if not more, to expand. If you do the expansion with the binomial theorem, many of the terms will actually cancel out between the two binomials, but it still isn't a fun time.
The best way to do this would probably be to just use decimals and a calculator, which can show that this formula does in fact work:
As a result, the Fibonacci sequence is typically not the best example for displaying the utility of having a closed form expression. Instead, let's take a look at a different recurrence relation:
The closed form for this recurrence relation can be found to be:
Therefore, let's say we wanted to calculate . Rather than plug and chug through all values of , we can instead just plug in and quickly learn that . In this case, the simple closed form expression is much simpler and faster than bashing through the values of .
In the next two sections, we'll talk about how to derive these closed form expressions for any linear recurrence. We'll first discuss homogenous recurrences since solving them is much simpler and more systematic than solving non-homogenous recurrences.
Solving Homogenous Recurrences
As a recap of what it means for a linear recurrence to be homogenous, a homogenous linear recurrence does not contain any terms besides in its recurrence relation. In particular, this means that there can be no constant coefficients or any terms that involve directly inside of the recurrence relation. See Homogenous vs Non-Homogenous for more details.
To solve these recurrences, we'll first construct something known as the characteristic polynomial and characteristic equation of the recurrence relation.
Definition
The characteristic polynomial of the degree recurrence relation
is denoted as
When we set this to zero, we get the characteristic equation of the recurrence relation. The solutions to this equation are known as the characteristic roots.
To find the solution to our recurrence relation, we need to find the characteristic roots of it. Once we find the characteristic roots, there are two cases: either all of them are distinct or there are some duplicates. Let's first handle the case where all of them are distinct.
In the case where they are all distinct, let's call our characteristic roots . Our solution to the linear recurrence is then of the form:
The next thing we need to do is just solve for our values of , which we can do by plugging in the initial conditions. See the Homogenous Recurrence Examples section below to see an example of this.
Next, let's consider the case where the roots are not distinct. How many times a root appears as a solution to a polynomial is known as its multiplicity. For instance, the equation has distinct roots. is a root with multiplicity while is a root with multiplicity . Therefore, the idea of having non-distinct roots means that there are some characteristic roots with multiplicity greater than .
Let's denote the multiplicity of the characteristic root by , and let's say that we have distinct roots. Then, our solution has the following form instead:
Once again, we can just plug in the initial conditions to find our values of . This form is pretty hard to understand from the formula, so see the example in the Non-Homogenous Recurrence Examples section below. What it does is basically just adds another exponential for each copy of the characteristic root but with an extra factor tacked onto it.
Homogenous Recurrence Examples
Example
Solve the following recurrence equation:
Let's first write the characteristic equation:
We can solve this by factoring to get . All of our roots are distinct, so we can use the following form:
From here, we can plug in our initial conditions of . This gives us the following system of equations that we can use to solve for and .
Solving, we get . Therefore, the final solution to this recurrence equation is:
Try plugging in some values to verify this! Now, let's move on to an example that will have repeated roots.
Example
Solve the following recurrence equation:
We can set up our characteristic equation:
We can factor this to get the following, which shows that we have repeated roots:
Therefore, we have the characteristic root with multiplicity and the characteristic root with multiplicity . We can then plug this into the form mentioned above:
We can then plug in our four initial conditions to solve this recurrence:
This gives us the following system of equations:
Solving this system, we get
Therefore, our final answer is:
Solving Non-Homogenous Recurrences
While there was a systematic way to approach homogenous recurrences, solving non-homogenous recurrences requires more guessing. First, note that we can express any non-homogenous linear recurrence as the sum of a homogenous linear recurrence and a polynomial .
The first step of the procedure is to solve for the general form of . That is, find the characteristic roots of but don't find the values of . Next, we need to do some guessing and checking to find an equation for that works in the relation given. When we're looking for this, we do not need to have this equation satisfy the initial conditions.
After we find this equation for , we can then add on our solution to . After this, we can solve for those values of to make this combined equation match our initial conditions.
When searching for equation forms that will satisfy the relation for , it is mostly guess and check. However, we can use a few tips to guide our searching. Most of the time, the correct relation will be very similar in form to . For instance, if is a polynomial, we should try out polynomials of similar same degree. If is an exponential like , then we can try multiples of and also throw in some multiples of , etc. In the sections below, we will go over some examples to show you how this process works since just describing it is difficult.
Non-Homogenous Recurrence Example
Example
Solve the following recurrence equation:
The first step of the process is to isolate the homogenous linear recurrence from this equation. We can separate into a homogenous and a polynomial .
To solve , we can once apply the exact same method as in the previous step: find the characteristic roots and then write the general form of the recurrence. This gives us the following:
Therefore, our solution to will be of the form:
Now that we have solved the homogenous version of the problem, we can move on to guessing and checking for solutions to our non-homogenous . First, note that is a linear polynomial, so we may guess that a solution might also be a linear polynomial. Let's try this and do:
Now, what we want to do is substitute this expression into our recurrence relation to solve for the coefficients and that make this form work. These coefficients for and must satisfy the recurrence relation for all integer values of . Let's first do a bit of plugging in and rearranging:
Uh oh, we have a problem here. There is no constant value we can give to such that it will satisfy this equation for all . As a result, we can conclude that the recurrence relation for does not have a linear solution. Let's try a quadratic instead:
We can then do the exact same as before, although it will get a bit messy due to the quadratic:
Now that we've simplified our equation greatly, this looks much more promising! Note that disappeared in our equation, which means that we can make anything. For simplicity, we'll just take . To solve for values of and for all values of , we have a few options: the first is to just simply plug in a bunch of values of and then solve for and from there. However, a more rigorous solution would be to gather terms to form a polynomial in terms of . Then, all of the coefficients in this polynomial must be for this to be a valid solution. If this isn't possible, then this form is also invalid.
Therefore, our solution to is:
If you plug this into the recurrence relation, this will satisfy that relationship! However, we have a major issue here: it doesn't satisfy any of our initial conditions! This is where our previous solution for comes into play. What we can do is add together these solutions to create a complete solution for that also has values for that we can solve for to make sure it aligns with our specific solution.
Therefore, we finally have our full solution:
Why It Works
While the above goes over how to solve these recurrences, a lot of it just seems like magic formulas. In the below sections, I will try to explain why these equations work and how you can reason through them to the best of my ability, although the proofs may not be perfect.
Homogenous Recurrences
There are two key theorems that we will use while solving homogenous linear recurrence relation:
Theorem
If and are solutions to a recurrence relation, then their sum also satisfies that recurrence relation.
To prove this, we can simply apply the recurrence relation definition a few times and do a bit of grouping.
Theorem
If is a solution to a recurrence relation, then also satisfies that recurrence relation for any constant .
To prove this, we can simply apply the recurrence relation definition.
Now that we have this, we can construct an approach to our problem. If we have a recurrence relation of degree , then there will be initial values that we need to satisfy. Therefore, what we can do is find different sequences that satisfy our recurrence relation. We can add together these different sequences to get another sequence that will still satisfy this recurrence relation. If we take each of those different sequences and we multiply each one by some multipler , our recurrence relation will also have different parameters that we can use to completely modify the value of our sequence. Therefore, we can use this to make our sequence match the initial values of our recurrence sequence.
Now, that we have an approach, we can start finding small solutions that will fit into this recurrence equation.
Theorem
If has the characteristic polynomial
then is a solution to the recurrence equation if is a root of the characteristic polynomial.
To prove this, we can plug into the characteristic polynomial and do a bit of rearranging:
Since the last line matches the form of our recurrence relation, we can conclude that is a solution to our recurrence relation.
From here, we already have our solution for when the roots of our characteristic equation are distinct. Each distinct root will give us a distinct solution that we can then apply our above method to.
However, this doesn't work when the roots for our characteristic equation are not distinct, as we will then not get different sequences we can combine. However, when a root has a multiplicity , then we can construct another solution:
Theorem
If is a solution to the characteristic polynomial of with a multiplicity of , then for any integer between and is a solution to the recurrence equation.
Proving this is pretty complicated, so I'll omit it here. If you're interested int he full details, check out page 16 of this document that also includes a ton of awesome in-depth information about solving recurrences.
Once we have this theorem, we can then see that for each root with multiplicity , we get sequences out of it. Since the total sum of all multiplicities is equal to , we obtain our sequences that we can then create a linear combination of to match our initial conditions. With that, we have created a systematic approach towards solving linear recurrences.
Non-Homogenous Recurrences
With non-homogenous recurrences, the previous method does not apply because recurrences are not additive and the two forms we found also don't work. As a result, we have to do a bit more work to find an answer. The key is the following:
Theorem
If be a linear non-homogenous recurrence relation. Write in the following form, where is a linear homogenous recurrence relation and is a polynomial in terms of .
If we know any particular solution that satisfies the given non-homogenous recurrence relation and we know a solution that satisfies the homogenous recurrence relation, then
also satisfies the non-homogenous recurrence relation.
To prove this, let us write out the definitions of our sequences and do a bit of rearranging:
Now that we have this tool, we can design an approach to solving this non-homogenous linear recurrence. We need to first design a single solution to the linear recurrence that will satisfy it. This must be done through guess and check and once we find it, it will not necessarily satisfy our initial conditions. However, we can use this as a building block and use the above theorem to add the homogenous solution to it. This homogenous solution will be fully customizable and allow our recurrence to pass through whichever values we want. As a result, we can use it to drive our non-homogenous solution towards our desired inputs.
Finding the specific non-homogenous solution is hard though. Fortunately, as mentioned before, just trying forms similar to has been shown to work really well. In fact, there is a proof (which will be omitted here for brevity) that if is a polynomial, then there will always be a polynomial that satisfies the recurrence relation of .
Conclusion
Solving linear recurrences can be very hard at times, but it can also be extremely powerful for solving some math problems. Not only can it greatly shorten calculations, but it can also put your answers into forms you may not have seen otherwise. For instance, if you have the closed form , you can calculate your answer in a really nice way and see that it is the difference of two exponentials. If you bashed out the values of instead and got something like , it would be really hard to see this connection.