0% found this document useful (0 votes)
38 views

Generating Functions1

The document discusses generating functions, which are power series that encode sequences as coefficients and allow manipulating sequences using tools from calculus. Simple examples are provided, like the generating function 1/(1-x) for the constant sequence 1,1,1,... and how modifying x in this function generates other sequences like 1,-1,1,-1,... or 1,3,9,27,...

Uploaded by

mbsuresh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Generating Functions1

The document discusses generating functions, which are power series that encode sequences as coefficients and allow manipulating sequences using tools from calculus. Simple examples are provided, like the generating function 1/(1-x) for the constant sequence 1,1,1,... and how modifying x in this function generates other sequences like 1,-1,1,-1,... or 1,3,9,27,...

Uploaded by

mbsuresh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

15/11/2022, 17:42 Generating Functions

Discrete Mathematics: An Open


Introduction
Oscar Levin

5.1  Generating Functions ¶

There is an extremely powerful tool in discrete mathematics used to manipulate


sequences called the generating function. The idea is this: instead of an infinite
sequence (for example: 2, 3, 5, 8, 12, …) we look at a single function which
encodes the sequence. But not a function which gives the nth term as output.
Instead, a function whose power series (like from calculus) “displays” the terms
of the sequence. So for example, we would look at the power series
2 + 3x + 5x + 8x + 12x + ⋯ which displays the sequence 2, 3, 5, 8, 12, … as
2 3 4

coefficients.

An infinite power series is simply an infinite sum of terms of the form c nx


n
were
c is some constant. So we might write a power series like this:
n

k
∑ ck x .

k=0

or expanded like this


2 3 4 5
c0 + c1 x + c2 x + c3 x + c4 x + c5 x + ⋯.

When viewed in the context of generating functions, we call such a power series
a generating series. The generating series generates the sequence
c0 , c1 , c2 , c3 , c4 , c5 , … .

In other words, the sequence generated by a generating series is simply the


sequence of coefficients of the infinite polynomial.

Example 5.1.1. 
What sequence is represented by the generating series
?
5
2 3 x 6
3 + 8x + x + + 100x + ⋯
7

Solution

Now you might very naturally ask why we would do such a thing. One reason is
that encoding a sequence with a power series helps us keep track of which term
is which in the sequence. For example, if we write the sequence
1, 3, 4, 6, 9, … , 24, 41, … it is impossible to determine which term 24 is (even if

we agreed that the first term was supposed to be a ). However, if we wrote the 0

generating series instead, we would have


+ ⋯ . Now it is clear that 24 is
2 3 4 17 18
1 + 3x + 4x + 6x + 9x + ⋯ + 24x + 41x

https://discrete.openmathbooks.org/dmoi2/section-27.html 1/9
15/11/2022, 17:42 Generating Functions

the 17th term of the sequence (that is, a = 24). Of course to get this benefit we 17

could have displayed our sequence in any number of ways, perhaps


1 3 4 6 9 ⋯ 24 41 ⋯ , but we do not do this. The reason is that the
0 1 2 3 4 17 18

generating series looks like an ordinary power series (although we are


interpreting it differently) so we can do things with it that we ordinarily do with
power series such as write down what it converges to.

For example, from calculus we know that the power series


+ ⋯ converges to the function e . So we can
2 3 4 n
x x x x x
1 + x + + + + ⋯ +
2 6 24 n!

use e as a way of talking about the sequence of coefficients of the power series
x

for e . When we write down a nice compact function which has an infinite power
x

series that we view as a generating series, then we call that function a generating
function. In this example, we would say
1 1 1 1
1, 1, , , ,…, ,…  has generating function e x

2 6 24 n!

Building Generating Functions ¶


The e example is very specific. We have a rather odd sequence, and the only
x

reason we know its generating function is because we happen to know the


Taylor series for e . Our goal now is to gather some tools to build the generating
x

function of a particular given sequence.

Let's see what the generating functions are for some very simple sequences. The
simplest of all: 1, 1, 1, 1, 1, …. What does the generating series look like? It is
simply 1 + x + x + x + x + ⋯ . Now, can we find a closed formula for this
2 3 4

power series? Yes! This particular series is really just a geometric series with
common ratio x. So if we use our “multiply, shift and subtract” technique from
Section 2.2, we have
2 3
S = 1 + x + x + x + ⋯
2 3 4
−xS = x + x + x + x + ⋯
−−−−−−−−−−−−−−−−−−−−−−−−−−−−

(1 − x)S = 1

Therefore we see that


1
2 3
1 + x + x + x ⋯ =
1 − x

You might remember from calculus that this is only true on the interval of
convergence for the power series, in this case when |x| < 1. That is true for us,
but we don't care. We are never going to plug anything in for x, so as long as
there is some value of x for which the generating function and generating series
agree, we are happy. And in this case we are happy.

1, 1, 1, … . 

https://discrete.openmathbooks.org/dmoi2/section-27.html 2/9
15/11/2022, 17:42 Generating Functions

1
The generating function for 1, 1, 1, 1, 1, 1, … is
1 − x

Let's use this basic generating function to find generating functions for more
sequences. What if we replace x by −x. We get
1
= 1 − x + x
2
− x
3
+ ⋯  which generates 1, −1, 1, −1, …
1 + x

If we replace x by 3x we get
1
= 1 + 3x + 9x
2
+ 27x
3
+ ⋯  which generates 1, 3, 9, 27, …
1 − 3x

By replacing the x in we can get generating functions for a variety of


1−x
1

sequences, but not all. For example, you cannot plug in anything for x to get the
generating function for 2, 2, 2, 2, … . However, we are not lost yet. Notice that
each term of 2, 2, 2, 2, … is the result of multiplying the terms of 1, 1, 1, 1, … by
the constant 2. So multiply the generating function by 2 as well.
2
= 2 + 2x + 2x
2
+ 2x
3
+ ⋯  which generates 2, 2, 2, 2, …
1 − x

Similarly, to find the generating function for the sequence 3, 9, 27, 81, … , we
note that this sequence is the result of multiplying each term of 1, 3, 9, 27, … by
3. Since we have the generating function for 1, 3, 9, 27, … we can say
3
= 3 ⋅ 1 + 3 ⋅ 3x + 3 ⋅ 9x
2
+ 3 ⋅ 27x
3
+ ⋯  which generates 3, 9, 27, 81, …
1 − 3x

What about the sequence 2, 4, 10, 28, 82, … ? Here the terms are always 1 more
than powers of 3. That is, we have added the sequences 1, 1, 1, 1, … and
1, 3, 9, 27, … term by term. Therefore we can get a generating function by

adding the respective generating functions:


2 3 2 3
2 + 4x + 10x + 28x + ⋯ = (1 + 1) + (1 + 3)x + (1 + 9)x + (1 + 27)x + ⋯

2 3 2 3
= 1 + x + x + x + ⋯ + 1 + 3x + 9x + 27x + ⋯

1 1
= +
1 − x 1 − 3x

The fun does not stop there: if we replace x in our original generating function
by x we get
2

2
= 1 + x
2
+ x
4
+ x
6
⋯  which generates 1, 0, 1, 0, 1, 0, … .
1 − x

How could we get 0, 1, 0, 1, 0, 1, … ? Start with the previous sequence and shift it
over by 1. But how do you do this? To see how shifting works, let's first try to get
the generating function for the sequence 0, 1, 3, 9, 27, … . We know that
= 1 + 3x + 9x + 27x + ⋯ . To get the zero out front, we need the
1 2 3

1−3x

https://discrete.openmathbooks.org/dmoi2/section-27.html 3/9
15/11/2022, 17:42 Generating Functions

generating series to look like x + 3x + 9x + 27x + ⋯ (so there is no constant


2 3 4

term). Multiplying by x has this effect. So the generating function for


0, 1, 3, 9, 27, … is . This will also work to get the generating function for
x

1−3x

0, 1, 0, 1, 0, 1, … :
x

2
= x + x
3
+ x
5
+ ⋯  which generates 0, 1, 0, 1, 0, 1 …
1 − x

What if we add the sequences 1, 0, 1, 0, 1, 0, … and 0, 1, 0, 1, 0, 1, … term by


term? We should get 1, 1, 1, 1, 1, 1 … . What happens when we add the
generating functions? It works (try it)!
1 x 1
+ = .
2 2
1 − x 1 − x 1 − x

Here's a sneaky one: what happens if you take the derivative of ? We get 1

1−x
1
. On the other hand, if we differentiate term by term in the power series,
2
(1−x)

we get (1 + x + x + x + ⋯) = 1 + 2x + 3x
2 3 ′ 2
+ 4x
3
+ ⋯ which is the
generating series for 1, 2, 3, 4, … . This says

1, 2, 3, … . 
1
The generating function for 1, 2, 3, 4, 5, … is 2
.
(1 − x)

Take a second derivative: (1−x)


2

3
= 2 + 6x + 12x
2
+ 20x
3
+ ⋯ . So
1

(1−x)
3
= 1 + 3x + 6x
2
+ 10x
3
+ ⋯ is a generating function for the triangular
numbers, 1, 3, 6, 10 … (although here we have a 0 = 1 while T 0 = 0 usually).

Differencing ¶
We have seen how to find generating functions from using multiplication 1−x
1

(by a constant or by x), substitution, addition, and differentiation. To use each of


these, you must notice a way to transform the sequence 1, 1, 1, 1, 1 … into your
desired sequence. This is not always easy. It is also not really the way we have
analyzed sequences. One thing we have considered often is the sequence of
differences between terms of a sequence. This will turn out to be helpful in
finding generating functions as well. The sequence of differences is often
simpler than the original sequence. So if we know a generating function for the
differences, we would like to use this to find a generating function for the
original sequence.

For example, consider the sequence 2, 4, 10, 28, 82, … . How could we move to
the sequence of first differences: 2, 6, 18, 54, … ? We want to subtract 2 from the
4, 4 from the 10, 10 from the 28, and so on. So if we subtract (term by term) the
sequence 0, 2, 4, 10, 28, … from 2, 4, 10, 28 … , we will be set. We can get the
generating function for 0, 2, 4, 10, 28, … from the generating function for

https://discrete.openmathbooks.org/dmoi2/section-27.html 4/9
15/11/2022, 17:42 Generating Functions

2, 4, 10, 28 … by multiplying by x. Use A to represent the generating function for


2, 4, 10, 28, 82, … Then:

2 3 4
A = 2 + 4x + 10x + 28x + 82x + ⋯
2 3 4 5
−xA = 0 + 2x + 4x + 10x + 28x + 82x + ⋯
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
2 3 4
(1 − x)A = 2 + 2x + 6x + 18x + 54x + ⋯

While we don't get exactly the sequence of differences, we do get something


close. In this particular case, we already know the generating function A (we
found it in the previous section) but most of the time we will use this
differencing technique to find A: if we have the generating function for the
sequence of differences, we can then solve for A.

Example 5.1.2. 
Find a generating function for 1, 3, 5, 7, 9, … .
Solution

Now that we have a generating function for the odd numbers, we can use that
to find the generating function for the squares:

Example 5.1.3. 
Find the generating function for 1, 4, 9, 16, … . Note we take
1 = a0 .
Solution

In each of the examples above, we found the difference between consecutive


terms which gave us a sequence of differences for which we knew a generating
function. We can generalize this to more complicated relationships between
terms of the sequence. For example, if we know that the sequence satisfies the
recurrence relation a = 3a − 2a ? In other words, if we take a term of the
n n−1 n−2

sequence and subtract 3 times the previous term and then add 2 times the term
before that, we get 0 (since a − 3a + 2a = 0). That will hold for all but the
n n−1 n−2

first two terms of the sequence. So after the first two terms, the sequence of
results of these calculations would be a sequence of 0's, for which we definitely
know a generating function.

Example 5.1.4. 
The sequence 1, 3, 7, 15, 31, 63, … satisfies the recurrence
relation a n = 3an−1 − 2an−2 . Find the generating function for the sequence.
Solution

Multiplication and Partial Sums ¶


What happens to the sequences when you multiply two generating functions?
Let's see: A = a + a x + a x + ⋯ and B = b + b x + b x + ⋯ . To multiply A
0 1 2
2
0 1 2
2

and B, we need to do a lot of distributing (infinite FOIL?) but keep in mind we will
group like terms and only need to write down the first few terms to see the
pattern. The constant term is a b . The coefficient of x is a b + a b . And so on.
0 0 0 1 1 0

We get:

https://discrete.openmathbooks.org/dmoi2/section-27.html 5/9
15/11/2022, 17:42 Generating Functions
2 3
AB = a0 b0 + (a0 b1 + a1 b0 )x + (a0 b2 + a1 b1 + a2 b0 )x + (a0 b3 + a1 b2 + a2 b1 + a3 b0 )x + ⋯

Example 5.1.5. 
“Multiply” the sequence 1, 2, 3, 4, … by the sequence
1, 2, 4, 8, 16, … .
Solution

Consider the special case when you multiply a sequence by 1, 1, 1, … . For


example, multiply 1, 1, 1, … by 1, 2, 3, 4, 5 … . The first term is 1 ⋅ 1 = 1. Then
1 ⋅ 2 + 1 ⋅ 1 = 3. Then 1 ⋅ 3 + 1 ⋅ 2 + 1 ⋅ 1 = 6. The next term will be 10. We are

getting the triangular numbers. More precisely, we get the sequence of partial
sums of 1, 2, 3, 4, 5, … . In terms of generating functions, we take 1

1−x

(generating 1, 1, 1, 1, 1 …) and multiply it by (generating 1, 2, 3, 4, 5, …) and


1

(1−x)
2

this give . This should not be a surprise as we found the same generating
1

(1−x)
3

function for the triangular numbers earlier.

The point is, if you need to find a generating function for the sum of the first n
terms of a particular sequence, and you know the generating function for that
sequence, you can multiply it by . To go back from the sequence of partial
1

1−x

sums to the original sequence, you look at the sequence of differences. When
you get the sequence of differences you end up multiplying by 1 − x, or
equivalently, dividing by . Multiplying by
1−x
1
gives partial sums, dividing by
1

1−x

1−x
gives differences.

Solving Recurrence Relations with Generating


Functions

We conclude with an example of one of the many reasons studying generating
functions is helpful. We can use generating functions to solve recurrence
relations.

Example 5.1.6. 
Solve the recurrence relation a n
= 3an−1 − 2an−2 with initial
conditions a 0 = 1 and a 1 = 3 .
Solution

We can now add generating functions to our list of methods for solving
recurrence relations.

Exercises ¶

1.  Find the generating function for each of the following sequences by relating
them back to a sequence with known generating function.

a. 4, 4, 4, 4, 4, … .
b. 2, 4, 6, 8, 10, … .

https://discrete.openmathbooks.org/dmoi2/section-27.html 6/9
15/11/2022, 17:42 Generating Functions

c. 0, 0, 0, 2, 4, 6, 8, 10, … .
d. 1, 5, 25, 125, … .
e. 1, −3, 9, −27, 81, … .
f. 1, 0, 5, 0, 25, 0, 125, 0, … .
g. 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0, 5, … .
Solution

2.  Find the sequence generated by the following generating functions:

4x
a. .
1 − x

1
b. .
1 − 4x

x
c. .
1 + x

3x
d. 2
.
(1 + x)

2
1 + x + x
e. 2
(Hint: multiplication).
(1 − x)

Solution

3.  Show how you can get the generating function for the triangular numbers in
three different ways:

a. Take two derivatives of the generating function for 1, 1, 1, 1, 1, …


b. Use differencing.
c. Multiply two known generating functions.
Solution

4.  Use differencing to find the generating function for 4, 5, 7, 10, 14, 19, 25, … .
Solution

5.  Find a generating function for the sequence with recurrence relation
an = 3an−1 − an−2 with initial terms a 0 = 1 and a 1 = 5 .
Solution

6.  Use the recurrence relation for the Fibonacci numbers to find the generating
function for the Fibonacci sequence.
Solution

7.  Use multiplication to find the generating function for the sequence of partial
sums of Fibonacci numbers, S 0
, S1 , S2 , … where S 0
= F0 ,S 1
= F0 + F1 ,

https://discrete.openmathbooks.org/dmoi2/section-27.html 7/9
15/11/2022, 17:42 Generating Functions

S2 = F 0 + F 1 + F 2 ,S 3
= F0 + F1 + F2 + F3 and so on.
Solution

8.  Find the generating function for the sequence with closed formula
n
an = 2(5 ) + 7(−3)
n
.
Solution

9.  Find a closed formula for the nth term of the sequence with generating
3x 1
function + .
1 − 4x 1 − x

Solution

2 x
10.  Find a 7 for the sequence with generating function 2

2
.
(1 − x) 1 − x − x

Solution

1
11.  Explain how we know that is the generating function for
(1 − x)2

1, 2, 3, 4, … .
Solution

12.  Starting with the generating function for 1, 2, 3, 4, … , find a generating


function for each of the following sequences.

a. 1, 0, 2, 0, 3, 0, 4, … .
b. 1, −2, 3, −4, 5, −6, … .
c. 0, 3, 6, 9, 12, 15, 18, … .
d. 0, 3, 9, 18, 30, 45, 63, … . (Hint: relate this sequence to the previous one.)
Solution

1
13.  You may assume that 1, 1, 2, 3, 5, 8, … has generating function 2
1 − x − x

(because it does). Use this fact to find the sequence generated by each of the
following generating functions.

a. .
2
x

2
1−x−x

b. 1

2
1−x −x
4
.

c. 1

1−3x−9x
2
.

d. 1

(1−x−x )(1−x)
2
.
Solution

14.  Find the generating function for the sequence 1, −2, 4, −8, 16, … .
https://discrete.openmathbooks.org/dmoi2/section-27.html 8/9
15/11/2022, 17:42 Generating Functions

Solution

15.  Find the generating function for the sequence 1, 1, 1, 2, 3, 4, 5, 6, … .


Solution

16.  Suppose A is the generating function for the sequence 3, 5, 9, 15, 23, 33, … .

a. Find a generating function (in terms of A) for the sequence of differences


between terms.
b. Write the sequence of differences between terms and find a generating
function for it (without referencing A).
c. Use your answers to parts (a) and (b) to find the generating function for
the original sequence.
Solution

https://discrete.openmathbooks.org/dmoi2/section-27.html 9/9

You might also like