GENERATING FUNCTIONS
CSC 231 DISCRETE STRUCTURES II
PROF GODFREY C. MUGANDA
1. Generating Function Example
Consider Example 3 on page 516 in the class textbook: What is the solution to the
recurrence relation
(1)
an = an−1 + 2an−2
with a0 = 2 and a1 = 7?
Earlier we had solved this problem and found that
an = 3 · 2n − (−1)n .
(2)
Let us solve the problem again using generating functions.
The generating function for the sequence {ak } is
G(x) = a0 + a1 x + a2 x2 + a3 x3 + · · ·
The recurrence relation (1) means that
ak − ak−1 − 2ak−2 = 0
(3)
for all k ≥ 2. We want to arrange three expressions involving G(x) to take advantage
of this relation to eliminate the infinite number of terms of the generating function
that involve a2 , a3 , a4 , . . .. This is because we cannot have a closed form for the
generating function unless we eliminate the infinite summations. Note that
(4)
G(x) =a0 +a1 x+ a2 x2 + a3 x3 +a4 x4 +a5 x5 +a6 x6 · · ·
(5)
xG(x) =
a0 x+ a1 x2 + a2 x3 +a3 x4 +a4 x5 +a5 x6 · · ·
(6)
2x2 G(x) =
2a0 x2 + 2a1 x3 +2a2 x4 +2a3 x5 +2a4 x6 · · ·
Now by subtracting the equations (5) and (6) from (4) we get the equation
∞
X
(7) G(x) − xG(x) − 2x2 G(x) = a0 + (a1 − a0 )x +
(ak − ak−1 − 2ak−2 )xk .
k=2
Because of equation (3), this reduces to
(8)
G(x) − xG(x) − 2x2 G(x) = a0 + (a1 − a0 )x.
Applying the boundary conditions a0 = 2 and a1 = 7 we get the equation
(9)
G(x) − xG(x) − 2x2 G(x) = 2 + (7 − 2)x.
1
2
PROF GODFREY C. MUGANDA
Factoring G(x) out of the left hand side and solving for G(x) we get
5x + 2
(10)
G(x) =
.
1 − x − 2x2
We can factor the denominator on the right hand side of the last equation to get
5x + 2
(11)
G(x) =
.
(1 − 2x)(1 + x)
At this point, we can decompose the right hand side into partial fractions (we
explain how to do this later) and get the following expression for the generating
function:
3
−1
5x + 2
=
+
.
(12)
G(x) =
(1 − 2x)(1 + x)
1 − 2x 1 + x
We therefore see that G(x) is the sum of two functions
1
1
(13)
G(x) = 3 ·
−
.
1 − 2x 1 + x
Consulting the table of generating functions on page 542 in our textbook we see
that
∞
X
1
(−1)k xk
=
(14)
1+x
k=0
and
∞
(15)
X
1
=
2k xk
1 − 2x
k=0
Applying this to equation (13) we get
∞
∞
X
X
(−1)k xk
2k xk −
(16)
G(x) = 3 ·
k=0
k=0
from which we get
(17)
G(x) =
∞
X
3 · 2k − (−1)k xk .
k=0
This in turn means that the terms of the sequence for which G(x) is a generating
function are
(18)
ak = 3 · 2k − (−1)k .
Thus we have obtained the same solution as in equation (2).
2. Partial Fractions Decomposition
You can find explanations of how to decompose a rational fraction into partial
fractions online, for example, at
http://www.purplemath.com/modules/partfrac.htm
For our purposes, all you need to know is the following. Whenever you have an
expression of the form
Ax + B
(19)
(Cx + D)(Ex + F )
you can transform the expression into a sum
Ax + B
R
S
(20)
=
+
(Cx + D)(Ex + F )
Cx + D Ex + F
GENERATING FUNCTIONS
CSC 231 DISCRETE STRUCTURES II
3
In our case, the expression
(21)
5x + 2
(1 − 2x)(1 + x)
from equation (11) can be written in the form
5x + 2
a
b
(22)
=
+
(1 − 2x)(1 + x)
1 − 2x 1 + x
and we need to find the the values a and b.
First note that the right hand side of (10) is
(23)
b
a(1 + x) + b(1 − 2x)
(a − 2b)x + (a + b)
a
+
=
=
1 − 2x 1 + x
(1 − 2x)(1 + x)
(1 − 2x)(1 + x)
When we compare this to (21) and equate coefficients of the same powers of x we
get the equations
a + b =2
a − 2b =5
From this we get a = 3 and b = −1. Plugging these values of a and b back into
equation (10) we recover the partial fraction decomposition in equation (13).
3. Practice Problems
You do not have to turn in these practice problems. However, make sure you can
do them because problems like these will be on the final examination.
Note that all odd numbered problems have answers at the back of the book.
Do problems 3, 13 and 15 on page 549.
Do problems 32, 33, and 34 on page 550.
© Copyright 2026 Paperzz