1.
Generating functions for basic sequences
2. Operations on generating functions
3. Counting
Generating Functions
a sequence of numbers a function
a polynomial
Through this mapping, we can apply our techniques for manipulating functions.
1. Generating functions for basic sequences
2. Operations on generating functions
3. Counting
4. Solve recurrences
Ordinary Generating Functions
Given a sequence <g0,g1,g2,g3,………>
the ordinary generating function is:
We use a double sided arrow to indicate the correspondence.
Simple Examples
The pattern here is simple:
the i-th term in the sequence (indexing from 0) is
the coefficient of xi in the generating function.
What is the generating function for <1,1,1,1,1,1,1,………………………>?
Geometric Series
Gn ::= 1+ x + x2 +
…… + xn-1 + xn + ……
What is the closed form expression of Gn?
Gn ::= 1 + x + x2 +
…… + xn-1 + xn + ……
xGn = x + x + x + +x + x
2 3 ……
n n+1
+ ……
GnxGn= 1
1-x n+1
Gn =
1-x
More Examples
These are all closed form generating functions.
1. Generating functions for basic sequences
2. Operations on generating functions
3. Counting
Operations on Generating Functions
manipulations on sequences manipulations on functions
There are a few basic operations we’ll learn.
1. Scaling
2. Addition
3. Right shift
4. Differentiation
5. Product
We can use these operations to get new sequences from known sequences,
and new generating functions from known generating functions.
Scaling
Multiplying a generating function by a constant
=> scales every term in the associated sequence by the same constant.
Multiply the generating function by 2 gives
which generates the sequence:
Addition
Adding generating functions corresponds to adding sequences term by term.
The same result as in the previous slide.
Right Shift
How to generate the sequence <0, 0, …, 0, 1, 1, 1, 1, 1…>?
k zeros
k zeros
Adding k zeros multiplying xk on the generating function.
Differentiation
How to generate the sequence <1, 2, 3, 4, 5, …>?
The generating function is
How to obtain a closed form of this function?
We found a generating function for the sequence <1,2,3,…> of positive integers!
More Differentiation
How to generate the sequence <1, 4, 9, 16, 25, …>?
Nice idea. But not what we want.
More Differentiation
How to generate the sequence <1, 4, 9, 16, 25, …>?
Product
What is the sequence corresponds to the polynomial C(x) = A(x)B(x)?
1. Generating functions for basic sequences
2. Operations on generating functions
3. Counting
Counting with Generating Functions
General strategy:
coefficient of xn = number of ways to choose n items.
A simple example:
the coefficient of xn in (1 + x)k is the number of ways
to choose n distinct items from a set of size k.
Convolution Rule
Let A(x) be the generating function for selecting items from set A.
Let B(x) be the generating function for selecting items from set B.
If A and B are disjoint,
then the generating function for selecting items from the union A U B
is the product A(x) · B(x).
Choosing Subsets
Choose n items from k distinct elements {a1, a2, …, ak}
How many ways to choose from single element set {a1}?
There is one way to choose 0 item, one way to choose 1 element.
So the generating function for {a1} is (1+x)
So the generating function for {a2} is (1+x)
……………
By convolution rule, the generating function for
choosing items in a k-element set {a1,a2,…,ak} is:
Choosing Doughnuts
How many ways can we select n doughnuts with k varieties?
Suppose there is only chocolate doughnuts.
How many ways can we select n doughnuts?
Well there is only one way to choose zero, one, two, three, ……, chocolate doughnuts.
So the generating function for choosing chocolate doughnuts is:
The generating function for choosing doughnuts with k varieties is:
By convolution rule:
Choosing Doughnuts
The generating function for choosing doughnuts with k varieties is:
By convolution rule:
Now what? How do we obtain the answer?
Taylor’s Theorem
where f(n)(x) is the n-th derivative of f(x).
Taylor’s Theorem
Choosing Doughnuts
The generating function for choosing doughnuts with k varieties is:
……
Choosing Doughnuts
The generating function for choosing doughnuts with k varieties is:
The number of ways to choose n doughnuts with k varieties is:
This is what we get before. Now there is a general method to derive it.
Choosing Fruits
How many ways can we fill a bag with n fruits with the following constraints?
• The number of apples must be even.
• The number of bananas must be a multiple of 5.
• There can be at most four oranges.
• There can be at most one pear.
For example, there are 7 ways to form a bag with 6 fruits
Choosing Fruits
• The number of apples must be even.
• The number of bananas must be a multiple of 5.
• There can be at most four oranges.
• There can be at most one pear.
GF for apples:
GF for bananas:
GF for oranges:
GF for pears: By convolution rule
GF for fruits:
Choosing Fruits
Generating function for fruits:
How many ways can we fill a bag with n fruits with the following constraints?
The answer is exactly n+1!
We solve an impossible counting problem in a routine way…