Sequences, recurrences, and sums [00B0]
- March 13, 2026
Sequences [00B1]
- March 13, 2026
Informally, a sequence is just a list of things (typically numbers). For example, 2, 5, 8, 11, 14, \dots . Formally, we can define a sequence as follows.
Definition Sequence [00B2]
- March 13, 2026
A sequence is a function from \mathbb {N} (or a subset of \mathbb {N}) to a set A. We use subscript notation like a_n, b_n to denote the image of n, the nth term of the sequence.
Remark [00B3]
- March 13, 2026
In other words, a sequence can also be thought of as a list where each element has a number: a_0, a_1, a_2, a_3, \dots The subset of \mathbb {N} serves as a set of indices; we often use \mathbb {N} itself, or sometimes \Z ^+ = \{1, 2, 3, \dots \}, or a finite set like \{0, 1, 2, \dots , n-1\}.
Remark [00B4]
- March 13, 2026
You sometimes see the notation \{a_n\} to refer to a sequence, but it’s terrible notation (because it looks like a set, but isn’t) and I won’t use it, even though it is (somewhat) standard.
Example [00B5]
- March 13, 2026
Consider the sequence of rational numbers with a_n = 1/n, starting with a_1. The sequence starts 1, \frac 1 2, \frac 1 3, \frac 1 4, \dots
Example [00B6]
- March 13, 2026
The sequence defined by a_n = 5 begins 5, 5, 5, 5, 5, \dots
Example [00B7]
- March 13, 2026
The string “hello” can be thought of as a finite sequence of letters, with a_0 = h, a_1 = e, a_2 = l, a_3 = l, a_4 = o.
Example Arithmetic sequence [00B8]
- March 13, 2026
Consider the sequence 2, 5, 8, 11, 14, 17, \dots Evidently each term in the sequence is three more than the previous term. This sequence can also be described by a_n = 2 + 3n, starting at a_0.
This type of sequence, in which there is a common difference between consecutive terms, is known as an arithmetic sequence.
Example Geometric sequence [00B9]
- March 13, 2026
Consider the sequence 2, 6, 18, 54, 162, \dots In this case, a_n = 2 \cdot 3^n for n \geq 0. This type of sequence, with a common ratio between consecutive terms, is known as a geometric sequence.
Recurrences [00BA]
- March 13, 2026
When we define a sequence via a formula for a_n in terms of n, we say it is in closed form. Another way to define a sequence is via a recurrence.
Definition Recurrence [00BB]
- March 13, 2026
A recurrence for a sequence is a rule expressing a_n using one or more previous terms of the sequence.
Remark [00BD]
- March 13, 2026
You will sometimes hear the term recurrence relation used in place of recurrence. This phrase is confusing, since a "recurrence relation" is not a relation (it just relates terms of a sequence to previous terms). I will try to consistently use the term recurrence.
Example [00BC]
- March 13, 2026
What sequences are described by the recurrence a_n = 3a_{n-1}? The solutions to this recurrence are all geometric sequences with a common ratio of 3. For example, one such sequence would be 1, 3, 9, 27, 81, \dots Of course, another is the example 2, 6, 18, \dots that we saw previously.
If we specify a value for a_0, say, a_0 = 2, then the sequence is determined completely: from a_0 we can compute a value for a_1; then from a_1 we can compute a_2, and so on.
Example [00BE]
- March 13, 2026
Let a_0, a_1, \dots be a sequence satisfying the recurrence a_n = 2a_{n-1} + 1 with a_0 = 0.
We have a_1 = 2a_0 + 1 = 1; then a_2 = 2 \cdot 1 + 1 = 3; then a_3 = 7; and so on. The sequence starts 0, 1, 3, 7, 15, 31, 63, \dots
Looking at this we notice that every term of the sequence seems to be one less than a power of two, so we conjecture the closed form a_n = 2^n - 1. First, let’s check that this works for a_0, which it does: 2^0 - 1 = 1 - 1 = 0. Next, let’s see if a_n satisfies the recurrence when defined in this way. We can do this by substituting our conjectured closed form for a_n into the recurrence and seeing if the two sides are equal: 2a_{n-1} + 1 = 2(2^{n-1} - 1) + 1 = 2^n - 2 + 1 = 2^n - 1 = a_n. Yay! This is in fact a valid proof that this closed form and recurrence define the same sequence.
Example [00BF]
- March 13, 2026
a_n = n \cdot a_{n-1}, a_0 = 1. These are the factorial numbers, a_n = n!.
Example [00BG]
- March 13, 2026
Consider the recurrence a_n = 2a_{n-1} - a_{n-2}. In general, there are many sequences that satisfy this recurrence. For example, let’s pick a_0 = 3 and a_1 = 13 and see what we get: 3, 13, 23, 33, 43, 53, \dots We could conjecture that a_n = 10n + 3 is a closed form for this sequence, and prove it by substituting it for a_n in the recurrence to see if it checks out.
Some example sequences [00BI]
- March 14, 2026
Can you describe the following sequences either with a closed form or a recurrence?
Example Odd numbers [00BJ]
- March 14, 2026
These are of course the odd numbers. The simplest way to describe them is to notice that each term is two more than the previous term, leading to the recurrence \begin {align*} a_0 &= 1 \\ a_n &= a_{n-1} + 2 \end {align*} Alternatively, we can describe them by the closed form a_n = 2n+1 (if we start at a_0) or a_n = 2n-1 (if we start at a_1).
Triangular numbers [00BK]
- March 14, 2026
These are the triangular numbers, because a_n is the number of dots in an equilateral triangle with n dots on a side.
Notice how the gap between successive terms increases by 1 every time. This satisfies the recurrence \begin {align*} \triangle _0 &= 0 \\ \triangle _n &= \triangle _{n-1} + n \end {align*} There is also a closed form for \triangle _n which we’ll derive shortly.
Fibonacci numbers [00BL]
- March 14, 2026
These are the famous Fibonacci numbers:
Definition Fibonacci numbers [00OZ]
- October 13, 2026
The Fibonacci numbers are the sequence F_n defined by the recurrence \begin {align*} F_0 &= 0 \\ F_1 &= 1 \\ F_n &= F_{n-1} + F_{n-2}. \end {align*}
Remark Fibonacci closed form [00P0]
- October 13, 2026
There is a closed form for F_n although we won’t derive it in this class. In fact, F_n = \frac 1 {\sqrt 5} \left ( \varphi ^n - \hat \varphi ^n \right ) where \varphi and \hat \varphi are respectively the positive and negative solutions of x^2 - x - 1 = 0, that is, (1 \pm \sqrt 5)/2. If you’re interested in learning where this comes from, check out this exercise, or just ask!
Recurrences in Disco [00BO]
- March 18, 2026
Since a sequence is formally defined as a function, we can easily define sequences in Disco.
Example Odd number sequence [00BP]
- March 18, 2026
odds : N -> N odds(n) = 2n + 1
Disco> :table odds 0 1 1 3 2 5 3 7 4 9 5 11 6 13 7 15 8 17 9 19 10 21 11 23 12 25 13 27 14 29 15 31 16 33 17 35 18 37 19 39 20 41 21 43 22 45 23 47 24 49 ...
We can also define sequences via recurrence, simply by defining a Disco function that calls itself.
Example Triangular numbers [00BQ]
- March 18, 2026
tri : N -> N tri(0) = 0 tri(n) = n + tri(n .- 1)
Instead of using :table we can also create a list to see exactly the part of the sequence we want. We can use the each function to apply tri to each index in a list.
Disco> each(tri, [0 .. 10]) [0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55]
Example Fibonacci numbers [00BR]
- March 18, 2026
fib : N -> N fib(0) = 0 fib(1) = 1 fib(n) = fib(n .- 1) + fib(n .- 2)
Disco> each(fib, [0..20]) [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765]
Summation and \Sigma -notation [00BS]
- March 18, 2026
Motivation [00BT]
- March 18, 2026
Often, what we want to do with a sequence is add the terms of the sequence. This is such a common idea that there is special notation for it, and algebraic rules for manipulating such sums.
Definition \Sigma notation [00BU]
- March 18, 2026
We use the notation \sum _{n=i}^j a_n to denote the sum of the sequence a_i + a_{i+1} + a_{i+2} + \dots + a_j. That is, we add up each a_n with n taking on the values i, i+1, and so on up to j. n is the , i is the and j is the . \Sigma is a capital Greek letter Sigma, and stands for \Sigma um.
Notation [00BV]
- March 18, 2026
I actually prefer the notation \sum _{i \leq n \leq j} a_n because we get to reuse familiar notation and we can apply a lot of our intuition and knowledge about dealing with inequalities to successfully manipulating sums.
Example [00BW]
- March 18, 2026
Write 1+3+5+7+ \dots + 99 using \Sigma -notation.
If we call the first term a_0, this is a sum of terms with closed form a_n = 2n+1, and the last term is a_{49}, so we have \sum _{0 \leq n \leq 49} (2n+1).
Now, how could we actually evaluate this sum? Let's develop some general techniques and then come back to attack it later.
Algebraic rules for sums [00BX]
- March 18, 2026
Sum of a constant [00BY]
- March 18, 2026
First, notice that \sum _{a \leq n \leq b} 1 = 1 + 1 + 1 + \dots + 1 = b-a+1. Why b-a+1 and not b-a, you ask? This is the “fence post problem”: if we number the posts of a fence, how many fence posts are there between post a and post b? If there is one post every meter, then the distance from post a to post b is certainly b-a meters. But if we try to match up a post to each meter-long section of fence, we find that we have one post left over. For example, if we match up each meter-long section of fence with the post on its left, then the post at the very end is not matched with any section. Hence, the number of posts from a to b is one more than the number of sections.
Factoring out constants [00BZ]
- March 18, 2026
\sum _n ka_n = k \sum _n a_n This works as long as k is a constant with respect to n, that is, k does not contain or depend on n at all. k does not have to be a number; it could be anything at all that does not depend on n. This rule is telling us that if we are adding up a bunch of terms, and every term is k times something, we can factor out all the k’s and simply multiply once by k at the end. If we write out what the \Sigma -notation means, this should become clear: ka_0 + ka_1 + ka_2 + \dots = k(a_0 + a_1 + a_2 + \dots )
Notice, the fact that k does not depend on n is what guarantees that all the k’s will all be the same, unlike the a_n’s which may all be different.
Summing a sum [00C0]
- March 18, 2026
\sum _n (a_n + b_n) = \left (\sum _n a_n\right ) + \left (\sum _n b_n\right ) This follows because addition is commutative and associative. Written out, the above law is really just saying: (a_0 + b_0) + (a_1 + b_1) + (a_2 + b_2) + \dots = (a_0 + a_1 + a_2 + \dots ) + (b_0 + b_1 + b_2 + \dots ) i.e. we are just putting the a_n’s and b_n’s in a different order.
Triangular numbers [00C1]
- March 18, 2026
What is the nth triangular number, \triangle _n = \sum _{j = 1}^n j ?
We can use a cute trick to compute it. First, write out the sum twice, but reversed the second time. Then add the two equations. \begin {array}{ccccccccccc} \triangle _n & = & 1 & + & 2 & + & \dots & + & (n-1) & + & n \\ +\triangle _n & = & n & + & (n-1) & + & \dots & + & 2 & + & 1 \\ \hline 2\triangle _n & = & (n+1) & + & (n+1) & + & \dots & + & (n+1) & + & (n+1) \end {array} We get n copies of n+1, so 2\triangle _n = n(n+1), and hence \triangle _n = \frac {n(n+1)}{2}.
Example Sum of an arithmetic sequence [00C2]
- March 18, 2026
We can now compute the result of our previous example.
Compute \sum _{0 \leq n \leq 49} (2n+1). We can now compute as follows:
Example Another arithmetic sequence [00C3]
- March 18, 2026
Evaluate: \sum _{5 \leq n \leq 22} 3n.
Sum of a geometric sequence [00C4]
- March 19, 2026
What about a geometric sequence such as a_n = r^n, that is, 1 + r + r^2 + r^3 + \dots + r^n? We can use a similar kind of trick as the one we used to find a closed form for triangular numbers. This time, we multiply by r and then subtract: \begin {array}{ccccccccccccc} S & = & 1 & + & r & + & r^2 & + & \dots & + & r^n && \\ rS & = & & & r & + & r^2 & + & \dots & + & r^n & + & r^{n+1} \\ \hline S - rS & = & 1 & & & & & & & & & - & r^{n+1} \end {array} Solving for S yields S = \frac {1 - r^{n+1}}{1-r} = \frac {r^{n+1} - 1}{r - 1}.
Example Powers of two [00C5]
- March 19, 2026
Consider the sum 1 + 2 + 2^2 + 2^3 + \dots + 2^n. This is a geometric series with r = 2. Hence the sum is \frac {2^{n+1} - 1}{2 - 1} = 2^{n+1} - 1.
★ Solving recurrences [00C6]
- March 19, 2026
In many situations, it is easy to write down a recurrence relation, but what we really want is a closed form. How can we figure out a closed form for a given recurrence? There are many techniques, but the simplest is to “unfold” the recurrence and look for a pattern.
Example Odd numbers, again [00C7]
- March 19, 2026
Let’s start by looking at a recurrence for the odd numbers: \begin {align*} g_0 &= 1 \\ g_n &= g_{n-1} + 2 & (n \geq 1) \end {align*}
We can start with g_n and keep unfolding it via the recurrence. For example, after unfolding to g_{n-1} + 2, the recurrence tells us that g_{n-1} = g_{n-2} + 2, so we can unfold again, and so on:
\begin {align*} g_n &= g_{n-1} + 2 \\ &= (g_{n-2} + 2) + 2 \\ &= ((g_{n-3} + 2) + 2) + 2 \\ &= \dots \end {align*}
We see a pattern: g_{n-k} is going to be followed by adding k copies of 2. So in general, we have g_n = g_{n-k} + 2k. Since we know the value of g_0, substituting k = n is helpful: g_n = g_{n-n} + 2n = g_0 + 2n = 1 + 2n. So we have derived the closed form g_n = 2n + 1 which is what we knew it should be.
Example [00C8]
- March 19, 2026
As another example, consider the recurrence \begin {align*} p_0 &= 0 \\ p_n &= 2p_{n-1} + 1 \end {align*} We have seen this recurrence before, and found a closed form just by looking at terms of the sequence and noticing a pattern. But we can derive the closed form more directly by unfolding: \begin {align*} p_n &= 2p_{n-1} + 1 \\ &= 2(2p_{n-2} + 1) + 1 \\ &= 2^2 p_{n-2} + 2 + 1 \\ &= 2^2 (2p_{n-3} + 1) + 2 + 1 \\ &= 2^3 p_{n-3} + 2^2 + 2 + 1 \\ &= \dots \\ &= 2^k p_{n-k} + 2^{k-1} + 2^{k-2} + \dots + 2 + 1 \\ &= 2^k p_{n-k} + 2^k - 1 \end {align*} The last step follows because 2^{k-1} + 2^{k-2} + \dots + 1 is the sum of a geometric sequence with ratio r = 2. When k = n, this becomes p_n = 2^n p_{n-n} + 2^n - 1 = 2^n - 1 since p_0 = 0.
Example [00C9]
- March 19, 2026
As another example, consider \begin {align*} q_0 &= 1 \\ q_n &= 3q_{n-1} + 2 \end {align*} The first few terms of this sequence are 1, 5, 17, 53, 161, \dots Unfolding: \begin {align*} q_n &= 3q_{n-1} + 2 \\ &= 3(3q_{n-2} + 2) + 2 \\ &= 3^2 q_{n-2} + 3\cdot 2 + 2 \\ &= 3^2 (3q_{n-3} + 2) + 3\cdot 2 + 2 \\ &= 3^3 q_{n-3} + 3^2 \cdot 2 + 3\cdot 2 + 2 \\ &= \dots \\ &= 3^k q_{n-k} + 3^{k-1} \cdot 2 + 3^{k-2} \cdot 2 + \dots + 2 \\ &= 3^k q_{n-k} + 2 (3^{k-1} + 3^{k-2} + \dots + 1) \\ &= 3^k q_{n-k} + 2 \frac {3^k - 1}{2} \\ &= 3^k q_{n-k} + 3^k - 1 \\ \end {align*} When k = n, we obtain q_n = 3^n q_0 + 3^k - 1 = 2 \cdot 3^n - 1. We can check that this is correct by (1) computing a few terms of the sequence and checking that our closed form generates the same terms, and/or (2) substituting our closed form into the recurrence to make sure it checks out.