8.
4 Generating Functions
Definition 1. The generating function for the sequence a0 , a1 , a2 , . . . , ak , . . . of real numbers is the infinite
series
X ∞
G(x) = a0 + a1 x + · · · + ak xk + · · · = ak xk .
k=0
Remark 1. When generating functions are used to solve counting problems, they are usually considered to
be formal power series.
Example 1. The generating function for the sequence 1, 1, 1, 1, . . . is
∞
X 1
1 + x + x2 + · · · = xk = for |x| < 1.
1−x
k=0
Example 2. The generating function for the sequence 1, a, a2 , a3 , . . . is
∞
X 1
1 + ax + a2 x2 + · · · = ak xk =
1 − ax
k=0
1
when |ax| < 1, or equivalently, when |x| < |a| for a 6= 0.
P∞ P∞
Theorem 1. Let f (x) = k=0 ak xk and g(x) = k=0 bk xk . Then
∞
X ∞
X Xk
f (x) + g(x) = (ak + bk )xk and f (x)g(x) = aj bk−j xk .
k=0 k=0 j=0
1
Example 3. Let f (x) = (1−x)2 . Use the theorem to find the coefficients a0 , a1 , . . . in the expansion f (x) =
P∞ k
k=0 ak x .
Solution. From Example 1 we see that
1
= 1 + x + x2 + x3 + · · · , |x| < 1.
1−x
Hence, from Theorem 1, we have
∞ k ∞
1 X X X
= 1 xk = (k + 1)xk .
(1 − x)2 j=0
k=0 k=0
Remark 2. This result also can be derived from Example 1 by differentiation. Taking derivatives is a useful
technique for producing new identities from existing identities for generating functions.
d
(1 − x)−1 = −1 · (1 − x)−1−1 · (−1) = (1 − x)−2
dx
and
∞ ∞ ∞
!
d X
k
X X
x = kxk−1 = (k + 1)xk
dx
k=0 k=1 k=0
and hence
∞
1 X
= (k + 1)xk .
(1 − x)2
k=0
1
Using Generating Functions to Solve Recurrence Relations
We may use recurrences to derive generating functions.
Example 4. Find the generating function for the sequence {an } defined by a0 = 1 and
an = 8an−1 + 10n−1 (1)
for n ≥ 1. Then find explicit formula for an .
Solution. We multiply both sides of the recurrence relation (1) by xn to obtain
an xn = 8an−1 xn + 10n−1 xn . (2)
P∞
Let G(x) = n=0 an xn be the generating function of the sequence a0 , a1 , a2 , . . .. We sum both sides of the
equation (2), starting with n = 1, to find that
∞
X
G(x) − 1 = an xn
n=1
X∞
= (8an−1 xn + 10n−1 xn )
n=1
X∞ ∞
X
=8 an−1 xn + x 10n−1 xn−1
n=1 n=1
X∞ ∞
X
= 8x an−1 xn−1 + x 10n−1 xn−1
n=1 n=1
X∞ ∞
X
= 8x an xn + x 10n xn
n=0 n=0
x
= 8xG(x) + ,
1 − 10x
where we have used Example 2 to evaluate the second summation. Therefore, we have
x
G(x) − 1 = 8xG(x) + .
1 − 10x
Solving for G(x), we obtain:
x
G(x) − 8xG(x) = 1 +
1 − 10x
x
∴ G(x)(1 − 8x) = 1 +
1 − 10x
1 − 10x + x
∴ G(x)(1 − 8x) =
1 − 10x
1 − 9x
∴ G(x)(1 − 8x) = .
1 − 10x
Therefore
1 − 9x
G(x) = . (3)
(1 − 10x)(1 − 8x)
Expanding the right-hand side of equation (3) into partial fractions (as is done in the integration of rational
2
functions studied in calculus) gives
1 − 9x A B
= +
(1 − 10x)(1 − 8x) 1 − 10x 1 − 8x
A(1 − 8x) + B(1 − 10x)
=
(1 − 10x)(1 − 8x)
A − 8Ax + B − 10Bx
=
(1 − 10x)(1 − 8x)
A + B − (8A + 10B)x
=
(1 − 10x)(1 − 8x)
Therefore
A+B =1
8A + 10B = 9
Solving the above system of two equations, we obtain
B =1−A
and hence
8A + 10(1 − A) = 9
∴ 8A + 10 − 10A = 9
∴ 10 − 2A = 9
∴ −2A = −1
1
∴A=
2
1 1
∴B =1− = .
2 2
Thus
1/2 1/2 1 1 1
G(x) = + = · + .
1 − 10x 1 − 8x 2 1 − 10x 1 − 8x
Using Example 2 twice (once with a = 10 and once with a = 8) gives
∞ ∞
!
1 X
n n
X
n n
G(x) = · 10 x + 8 x
2 n=0 n=0
∞
X 1
= · (10n + 8n ) xn .
n=0
2
Consequently, we have shown that
1
an = · (10n + 8n ) .
2
Homework: Find the generating function for the Fibonacci numbers {Fn }, using the initial conditions
F0 = F1 = 1, and the recurrence relation Fn+2 = Fn+1 + Fn .