Section 2: Generating Functions
2.1, 2.2: Power Series Review, Intro to Ordinary Generating Functions
A formal power series is an infinite sum
whose coefficients represent a sequence .
The function is the ordinary generating function of , sometimes denoted the OGF.
These functions are quite interesting! Oftentimes, we can manipulate these functions into something else that we can recognize.
Example: Ordinary Generating Functions of Sequences
Let be given by
What is ?
We can find as
Example: Sequences of Ordinary Generating Functions
Find if the OGF is
Note that our denominator looks like the output of a geometric series, but as a product! So, we apply partial fractions to get separate geometric series.
So, we get
So we find our sequence to be
Given a recurrence, say (the fibonacci recurrence) where we are given a term in terms of the previous ones, we can obtain the closed form OGF, and then use a series expansion to get an explicit closed form formula for our sequence .
Lemma
We have
Moreover, if , , then .
Example: Closed Form Fibonacci Sequence
Find a closed form ogf for the sequence, and find a closed form for with it.
Our goal is first to find the closed form OGF.
We first start with the ogf, and then apply our sequence definition to the term. Note that we need to take out the base case as the definition for is only defined for .
We can use this to express as a function of itself. Note that the first summation is without the term, and the second summation is just .
We have found a closed form ogf. We can now use this to find our closed form sequence. We do this by applying partial fraction decomposition and converting the result into a geometric series.
Here, we apply our lemma.
We’ve found our closed form sequence!
Example: Solving Recurrence Relations
Consider codes of length using . Let denote the total codes with an even number of ‘s.
- Find a recurence of in terms of
- Find a closed form ogf.
- Find a closed form for .
We first find a recurrence. If we have length strings, we could add a to get a length string. Or, with length strings, we need an odd number of ‘s to add an extra onto, which we can find as all strings minus the even ones.
We now need to find our base case. Clearly, , as the string can only be a . So, .
We now use our recurrence to find a closed form ogf.
We now use our closed form ogf to find a closed form sequence.
We found our closed form solution as
--- End of Exam 1 Content ---
2.3: Ordinary Generating Functions and Counting
What if is a combinatorial value, like ? Well, using our techniques, we can actually find the closed form solution of (at least in some cases)!
We describe various combinatorial objects that can be used to solve counting problems.
Weak Compostions with Contraints
We have
Differentiating this, we get
Generalizing this, we find that at the derivative,
Letting , we find
Now observe that
We can find that the coefficient of any is ! And in fact, our disgusting product can actually just be seen as all possible ways we can choose in group 1, in group 2, … in group where
Which is in fact weak compositions! With this relation, we can actually solve any weak composition problem (with any constraints)!
Each exponent represents one “dollar” we can give, and each series represents one entity we could give dollars to, where the series depends on the constraints we have!
Example: Model for Solving Weak Compositions
Find the ordinary generating function and state the coefficient that would count the total ways to distribute $100 to 4 kids so that kid 1 gets at most 5 dollars, kid 2 gets at least 3 dollars, kid 3 gets an even number of dollars, and kid 4 gets any amount.
We want the coefficient of such that
Each series is given in terms of the ways we can give dollars to each of the kids. For example because kid 2 gets at least 3 dollars, the series is as when we make a “choice” in our product, the exponent (dollars) we wantt to select for kid 2 must be 3 or more.
Its hard to solve this by hand, but we could easily solve this by a computer!
Stirling Numbers
Theorem: OGF for Stirling Numbers
Let be a fixed positive integer. Then the OGF for is
Proof
Recall that
Then, . We solve for a closed form solution.
This yields us a recursion of in terms of .
So, if I repeat this recursion, I will get my definition above!
Integer Partitions
Theorem:
The OGF for the total integer partitions of , , is
Proof (Sketch)
Notice that each product gives us multiples of , and if we select one of them, we are choosing the number of ‘s we want in our integer partition! For example, if we chose in our product (2nd one), we are choosing , or in other words, 3 integers of 2! So,
- Group 1 relates to how many 1s are in the sum
- Group 2 relates to how many 2s are in the sum
- …
More generally, the group in the ogf is given as
Where the term which represents us choosing the "" number of ‘s to the integer partition of .
Example: Integer Partitions
How many ways can you make $1 using any number of pennies, nickels, dimes, quarters, and half dollars?
We can formulate this as the following OGF, where we are looking for the coefficient of .
By computer, we get 292.
Same as in weak compositions, with such a model, we can now manipulate this expression for any constraints! Say, if we wanted to use at least 5 pennies, we could replace the first group with !
Theorem: Distinct Integer Partitions
The total ways to partition integer into parts where every number is distinct equals the total ways to partition integer where each part is an odd number.
Proof
The ogf for partitions into distinct parts is
As this ensures we choose any integer at most once. We change them using difference of squares.
This is the ogf for integer partitions of odd integers!
Example: Distinct Integer Partitions
. The distinct integer partitions vs. the odd integer partitions are given as
Both have 4 cases!
Integer Partitions into Parts
Theorem: Integer Partitions into Parts
The OGF for , the ways to partition into exactly parts, is given as
Proof / Intuition
First, we find the ogf for the partitions of integer into parts with size at most . To do this, we stop our product at the term.
If we look at a Ferrers diagram, we find that the conjugate of this is integer partitions into at most parts!
Then, with this, we can get integer partitions into exactly parts by subtracting partitions of at most parts from partitions of at most parts.
We can also think of this as, to force exactly parts, we must always choose 1 part to be of size ! This way, when we take the conjugate, we will have exactly parts.
2.4: Exponential Generating Functions
The exponential generating function for sequence is
Lemma: Product of OGFs
Let , . Then,
Where .
Lemma: Product of EGFs
Let
Then,
Where
What’s important about this is that gives us the total ways to separate into two blocks, such that we do a task in ways to block 1, and a task in ways to block 2! This can be used to solve more problems.
Proof
Recall that if , then , .
Let to get our lemma.
Theorem: EGFs for Stirling Numbers
The egf for the Stirling Number (for fixed ) is given as
Proof
Recall that
From this theorem, we can find that the egf for the bell number is
Proof
But why are egfs useful? Well, let’s consider the product
Then, we can find the contribution to as
Thus, the term is
This actually is permutations with repetition using any number of A’s, B’s, and C’s ()! In fact, this makes a lot of sense, because
Like with OGFs, EGFs give us a much more versatile way to do these types of problems! See the below example.
Example: Closed Form Sequences (1)
How many rearrangements of length use an odd number of A’s, even number of B’s, and any number of C’s?
If denotes the value, find the closed form for .
We’ve found a closed form egf. We can now use this to find our closed form sequence!
Example
There are 3 bookshelves and books. How many ways can you arrange the books on shelves such that each shelf has at least 1 book?
One way we could count this directly is by rearranging the books, and then using stars and bars!
Alternatively, we can use egfs to find all ways to arrange books so each shelf has at least 1 book.
The egf for one shelf with books is given as
This problem is asking for the coefficient of in
Note that is the ogf for weak compositions into 3 parts.
We find that the coefficient of , the total ways, is
Example
Recall is the total derangements of bijections such that for all .
First, what is the egf for the total bijections where for all ? We find the EGF is
As everything is fixed, so there is only one possible bijection.
Let be the egf for derangements:
What is the meaning of ? The coefficient of counts all possible permutations! From the , we have the number of fixed inputs, and from we have the number of deranged inputs!
Thus,
Note that above, we applied the product of ogf theorem discussed earlier.
Example
How many ways can we split up “n” people into any number of groups, where each group sits at an unlabeled circular table? We assume the tables are not distinguishable, and every table has at least 1 person.
We let the case of 0 tables be 1 way.
In the case, observe that we have the following number of ways:
In total, we have 24 ways.
First, the egf for 1 table with people is
Thus, for tables, we want the coefficient of in
We divide by as there is no ordering on the tables.
But we can use any number of tables! So, we want
We have ways.
Example
Now consider partitioning into non-empty blocks, doing a task to each block (ex. seat them at a table), and then do a task to the set of blocks (ex. each table either gets white or red wine).
If and are the egfs of the two tasks, with being the ways to do task 1, then if is the total ways to partition and apply these tasks, the egf of is
Simple Example
Lets first look at a simple example. What if and are trivial?
Note that starts from 1, as we cannot partition into 0 blocks.
This is the total ways to partition , “do nothing” to each block, and then arrange the blocks in 1 way. In other words, we partition, and then look at the blocks in “1 way”. Note that , so
Which is the egf for the Bell Number!
For seating people, the egf is
Now, the egf for total ways to serve the wine to tables is
The egf we want is
Thus, the total number of ways is
Section 2.5: The Catalan Numbers
Given an lattice, how many up-right paths go from to ?
Note that regardless of the path we take, we always do steps. Out of them, choose positions to be “right”, the rest being “up.
Now consider an lattice. How many of the up-right paths never cross over the diagonal?
Let denote the total paths satisfying this. We partition these paths into classes, where they last touched the diagonal , for .
Say we last touched . Then,
- To get from to , we have ways.
- To get to to , we must go right once, then take any paths. Finally, we go up once to .
Therefore, we find
We can use generating functions to find an explicit closed form solution for this recurrence!
Here, the closed form ogf is
We must define .
Theorem
If denotes the total up-right paths that don’t cross over the diagonal,
And the ogf for is
Lastly, we can find the closed-form solution for as
Called the catalan number.
Proof (Algebra)
We have
We have a quadratic in terms of ! We can solve for using the quadratic formula to find
We find that when the is negative, so we choose the negative variant as .
By a Lemma,
Giving us .
Proof (Combinatorial)
Consider a “bad” diagonal, which is the diagonal 1 unit above our diagonal.
Any “bad” path to touches the bad diagonal. Let be the first time you touch the bad diagonal. For any path from to touching the bad diagonal, we reflect the path after it touches the bad diagonal (an UP turns into a right, and vice versa).
At we need RIGHTs and UPs to get to . After reflecting, we now have UPs and RIGHTs. Accounting for the number of UPs and RIGHTs we needed to get to , we have UPs, RIGHTs.
Now, a reflected path ends at !
We find that the number of UP-RIGHT paths ending at (ignoring anything with the diagonals) is
But by the reflection, each of these paths corresponds to a bad path from to !
We delete all of these bad paths from to , to get all good paths from to .
Example: Using the Catalan Numbers (1, Stanley Combinatorics)
What are the total ways to order “n” pairs of parentheses.
Let’s consider an opening parenthes as a “RIGHT”, and closing as an “UP”. We can’t, at any point, have too many closing parentheses than opening parentheses. In other words, we cannot cross the diagonal!
This gives us
ways.
Example: Using the Catalan Numbers (2, Stanley Combinatorics)
What are the total ways to triangulate an sided polygon (labeled)?
Note that for any given polygon, all triangulations include a triangle with two vertices as a base, and some other point . This splits the polygon into two sections.
vertices on one side, so triangulations.
vertices on the other side, so triangulations.
So, the total triangulations of the polygon is