11/23/2015
1
Ma/CS 6aClass 24: More Generating Functions
By Adam Sheffer
Reminder: Generating Functions
Given an infinite sequence of numbers 𝑎0, 𝑎1, 𝑎2…, the generating function of the sequence is the power series
𝑎0 + 𝑎1𝑥 + 𝑎2𝑥2 +⋯
Example.
◦ Recall the Fibonacci numbers:𝐹0 = 𝐹1 = 1 𝐹𝑖 = 𝐹𝑖−1 + 𝐹𝑖−2.
◦ The corresponding generating function is1 + 𝑥 + 2𝑥2 + 3𝑥3 + 5𝑥4 +⋯
11/23/2015
2
Reminder: Using Generating Functions By rephrasing the solution to a problem
as a generating function, we obtain recursion relations such as 𝐴 𝑥 = 𝑥 + 5𝑥𝐴 𝑥 − 6𝑥2𝐴 𝑥 .
Solving the problem is equivalent to finding the power series representationof 𝐴 𝑥 .
Homogeneous Linear Recursion
The generating function of the Fibonacci numbers 𝐴 𝑥 = 𝑎0 + 𝑎1𝑥 + 𝑎2𝑥 +⋯satisfies
◦ 𝑎0 = 𝑎1 = 1.
◦ 𝑎𝑖 = 𝑎𝑖−1 + 𝑎𝑖−2 (for 𝑖 ≥ 2).
This is a special case of the homogeneous linear recursion (or HLR) defined as
◦ 𝑎0 = 𝑐0, 𝑎1 = 𝑐1, … , 𝑎𝑘−1 = 𝑐𝑘−1.
◦ 𝑎𝑛+𝑘 + 𝑑1𝑎𝑛+𝑘−1 +⋯+ 𝑑𝑘𝑎𝑛 = 0.
11/23/2015
3
HLR Property
Theorem. Given a generating function 𝐴 𝑥 with an HLR recursion 𝑎𝑛+𝑘+ 𝑑1𝑎𝑛+𝑘−1 +⋯+ 𝑑𝑘𝑎𝑛 = 0, we have
𝐴 𝑥 =𝑅 𝑥
1 + 𝑑1𝑥 +⋯+ 𝑑𝑘𝑥𝑘,
where 𝑅 𝑥 is a polynomial and deg 𝑅 𝑥 < 𝑘.
Example: Fibonacci Numbers
The generating function of the Fibonacci numbers 𝐴 𝑥 = 𝑎0 + 𝑎1𝑥 + 𝑎2𝑥 +⋯satisfies
◦ 𝑎0 = 𝑎1 = 1.
◦ 𝑎𝑖 − 𝑎𝑖−1 − 𝑎𝑖−2 = 0 (for 𝑖 ≥ 2).
𝐴 𝑥= 1 + 𝑥 + 𝑥2 𝑎0 + 𝑎1 + 𝑥
3 𝑎1 + 𝑎2 +⋯= 1 + 𝑥2 𝑎0 + 𝑎1𝑥 + 𝑎2𝑥
2 +⋯+ 𝑥 𝑎0 + 𝑎1𝑥 + 𝑎2𝑥
2 +⋯= 1 + 𝑥𝐴 𝑥 + 𝑥2𝐴 𝑥 .
11/23/2015
4
Fibonacci Numbers (cont.)
We have𝐴 𝑥 = 1 + 𝑥𝐴 𝑥 + 𝑥2𝐴 𝑥 .
That is,
𝐴 𝑥 =1
1 − 𝑥 − 𝑥2.
Proof of HLR Property
We rewrite
𝐴 𝑥 =𝑅 𝑥
1 + 𝑑1𝑥 +⋯+ 𝑑𝑘𝑥𝑘
as𝑅 𝑥 = 1 + 𝑑1𝑥 +⋯+ 𝑑𝑘𝑥
𝑘 𝐴 𝑥
= 1 + 𝑑1𝑥 +⋯+ 𝑑𝑘𝑥𝑘 𝑎0 + 𝑎1𝑥 + 𝑎2𝑥
2 +⋯ .
◦ The coefficient of 𝑥𝑛+𝑘 (for 𝑛 ≥ 0) is𝑎𝑛+𝑘 + 𝑑1𝑎𝑛+𝑘−1 +⋯+ 𝑑𝑘𝑎𝑛.
◦ By the HLR, this expression equals zero, so deg𝑅 𝑥 < 𝑘.
11/23/2015
5
The Auxiliary Equation
The auxiliary equation of the HLR𝑎0 = 𝑐0, 𝑎1 = 𝑐1, … , 𝑎𝑘−1 = 𝑐𝑘−1.𝑎𝑛+𝑘 + 𝑑1𝑎𝑛+𝑘−1 +⋯+ 𝑑𝑘𝑎𝑛 = 0
is 𝑡𝑘 + 𝑑1𝑡𝑘−1 +⋯+ 𝑑𝑘 = 0.
◦ If the auxiliary equation has 𝑘 roots (not necessarily distinct), then we can rewrite it as 𝑡 − 𝛼1
𝑚1 𝑡 − 𝛼2𝑚2⋯ 𝑡 − 𝛼𝑠
𝑚𝑠 = 0,
where 𝑚1 +⋯+𝑚𝑠 = 𝑘.
Stronger HLR Property
Theorem. Consider the sequence 𝑎0, 𝑎1, …, that is defined by an HLR with auxiliary equation 𝑡 − 𝛼1
𝑚1 𝑡 − 𝛼2𝑚2⋯ 𝑡 − 𝛼𝑠
𝑚𝑠 = 0.
Then
𝑎𝑛 = 𝑃1 𝑛 𝛼1𝑛 + 𝑃2 𝑛 𝛼2
𝑛 +⋯+ 𝑃𝑠 𝑛 𝛼𝑠𝑛,
where 𝑃𝑖 𝑛 is a polynomial of degree at most 𝑚𝑖 − 1.
11/23/2015
6
Using the Stronger HLR Property
Problem. Solve the following HLR.𝑢0 = 0, 𝑢1= −9, 𝑢2= −1, 𝑢3= 21.𝑢𝑛+4 − 5𝑢𝑛+3 + 6𝑢𝑛+2 + 4𝑢𝑛+1 − 8𝑢𝑛 = 0.
Solution.
◦ The auxiliary equation is𝑡4 − 5𝑡3 + 6𝑡2 + 4𝑡 − 8 = 0.
◦ This can be rewritten as𝑡 − 2 3 𝑡 + 1 = 0.
◦ By the theorem, we have𝑢𝑛 = 𝑃1 𝑛 𝛼1
𝑛 + 𝑃2 𝑛 𝛼2𝑛
= 𝑃1 𝑛 2𝑛 + 𝑃2 𝑛 −1
𝑛.
Solution (cont.)
From the auxiliary equation 𝑡 − 2 3 𝑡 + 1 = 0,
we know that 𝑢𝑛 = 𝐴𝑛
2 + 𝐵𝑛 + 𝐶 2𝑛 + 𝐷 −1 𝑛.
From the initial values𝑢0 = 0, 𝑢1= −9, 𝑢2= −1, 𝑢3= 21,
we get the system of equations𝐶 + 𝐷 = 0,
2𝐴 + 2𝐵 + 2𝐶 − 𝐷 = −9,16𝐴 + 8𝐵 + 4𝐶 + 𝐷 = −1,72𝐴 + 24𝐵 + 8𝐶 − 𝐷 = 21.
11/23/2015
7
Concluding the Solution
We have𝑢𝑛 = 𝐴𝑛
2 + 𝐵𝑛 + 𝐶 2𝑛 + 𝐷 −1 𝑛.
From the initial conditions, we obtain𝐶 + 𝐷 = 0,
2𝐴 + 2𝐵 + 2𝐶 − 𝐷 = −9,16𝐴 + 8𝐵 + 4𝐶 + 𝐷 = −1,72𝐴 + 24𝐵 + 8𝐶 − 𝐷 = 21.
Solving these equations yield 𝐴 = 1,𝐵 = −1, 𝐶 = −3, 𝐷 = 3. Therefore𝑢𝑛 = 𝑛
2 − 𝑛 − 3 2𝑛 + 3 −1 𝑛.
Pineapples Like Fibonacci Numbers!
(the number of strips of each of the three types)
11/23/2015
8
The Catalan Numers
The Catalan numbers. An extremely useful sequence of numbers.
In the exercises of the book “Enumerative Combinatorics” by Stanley, there are over 150 problems whose solution is the Catalan numbers.
Obtained by Euler and Lamé (not Catalan!)
Convex Polygons
A polygon is convex if no line segment between two of its vertices intersects the outside of the polygon.
Equivalently, every interior angle of a convex polygon is smaller than 180∘.
Convex Not Convex
11/23/2015
9
Triangulating of a convex Polygon
A triangulation of a convex polygon 𝑃 is the addition of non-crossing diagonals of 𝑃, partitioning the interior of 𝑃 into triangles.
Number of Triangulations
Let 𝑐𝑛 denote the number of different triangulations of a convex polygon with 𝑛 + 2 vertices.
◦ We set 𝑐0 = 1.
◦ 𝑐1 = 1.
◦ 𝑐2 = 2.
◦ 𝑐3 = 5.
◦ 𝑐4 = 14.
11/23/2015
10
A Recursive Relation
We have initial values for 𝑐𝑛. Now we need a recursive relation.
◦ Consider a side 𝑎𝑏 of an 𝑛-sided convex polygon 𝑃.
◦ In every triangulation, 𝑎𝑏 belongs to exactly one triangle Δ.
◦ The third vertex of Δcan be any of the other 𝑛 − 2 vertices of 𝑃.
A Recursive Relation (cont.)
The number of triangulations that contain the triangle 𝑎𝑏𝑣4 is 𝑐2𝑐3.
The number of triangulations that contain the triangle 𝑎𝑏𝑣5is 𝑐1𝑐4 = 𝑐4.
Recursive relation:
𝑐𝑛−2 =
𝑖=0
𝑛−3
𝑐𝑖𝑐𝑛−3−𝑖 .
11/23/2015
11
Are the Catalans an HLR?
We have the initial values
◦ 𝑐0 = 1, 𝑐1 = 1, 𝑐2 = 2, 𝑐3 = 5, 𝑐4 = 14.
We have the relation
𝑐𝑛−2 =
𝑖=0
𝑛−3
𝑐𝑖𝑐𝑛−3−𝑖 .
Is this an HLR?
◦ No! This is not linear and number of elements in the recursion changes according to 𝑛.
Solving the Recursion
We have the generating series𝐶 𝑥 = 𝑐0 + 𝑐1𝑥 + 𝑐2𝑥
2 +⋯
◦ We consider𝐶 𝑥 2
= 𝑐0𝑐0 + 𝑐0𝑐1 + 𝑐1𝑐0 𝑥+ 𝑐0𝑐2 + 𝑐1𝑐1 + 𝑐2𝑐0 𝑥
2 +⋯
◦ Writing 𝐶 𝑥 2 = 𝑛 𝑑𝑛𝑥𝑛, we get
𝑑𝑛 =
𝑖=0
𝑛
𝑐𝑖𝑐𝑛−𝑖 ,
we have𝐶 𝑥 2 = 1 + 𝑐2𝑥 + 𝑐3𝑥
2 +⋯ .
11/23/2015
12
Solving the Recursion (cont.)
We have𝐶 𝑥 2 = 1 + 𝑐2𝑥 + 𝑐3𝑥
2 +⋯ .
That is, 𝐶 𝑥 = 1 + 𝑥𝐶 𝑥 2.
Solving the Recursion (cont.)
We have 𝐶 𝑥 = 1 + 𝑥𝐶 𝑥 2.
Setting 𝑦 = 𝐶 𝑥 , we obtain the quadratic equation
𝑥𝑦2 − 𝑦 − 1 = 0,
or
𝐶 𝑥 = 𝑦 =1 ± 1 − 4𝑥
2𝑥.
How can we handle 1 − 4𝑥 ?
11/23/2015
13
More Binomial Formulas
Recall that
𝑥 + 1 𝑛 =
𝑖=0
𝑛𝑛𝑖𝑥𝑖 .
◦ By defining 𝑚𝑛=𝑚 𝑚−1 ⋯ 𝑚−𝑛+1
𝑛!also for
negative 𝑚’s, this formula is generalized also to negative powers.
◦ We can also consider values of 𝑚 that are not integers!
◦ The binomial formula holds for fractional 𝑛, but with 𝑖 going to ∞ (we do not prove this).
Fractional Powers
Using the fractional formula, we have
1 − 4𝑥 1/2 =
𝑖=0
∞
1/2𝑖−4𝑥 𝑖
= 1 +1/2
1!⋅ (−4𝑥) +
12⋅−122!⋅ 16𝑥2 +⋯
This implies
𝐶 𝑥 =1 ± 1 − 4𝑥
2𝑥=1 ± 𝑖=0
∞ 1/2𝑖−4𝑥 𝑖
2𝑥.
11/23/2015
14
Two Solutions
𝐶 𝑥 =1 ± 1 − 4𝑥
2𝑥=1 ± 𝑖=0
∞ 1/2𝑖−4𝑥 𝑖
2𝑥.
Considering the plus and minus cases separately, we have
𝐶− 𝑥 =− 𝑖=1∞ 1/2𝑖−4𝑥 𝑖
2𝑥
=−1
2
𝑖=1
∞
1/2𝑖(−4)𝑖𝑥𝑖−1 .
𝐶+ 𝑥 =1
𝑥+−1
2
𝑛=1
∞
1/2𝑛−4 𝑛𝑥𝑛 .
The Correct Solution
𝐶− 𝑥 =−1
2
𝑛=1
∞
1/2𝑛−4 𝑛𝑥𝑛−1 .
𝐶+ 𝑥 =1
𝑥+−1
2
𝑛=1
∞
1/2𝑛−4 𝑛𝑥𝑛 .
Which one is the correct solution?
◦ We saw that 𝑥−1 is not well defined!
𝑐𝑛 =−1
21/2𝑛 + 1
−4 𝑛+1
= −(−4)𝑛+1
2 𝑛 + 1 !⋅1
2⋅−1
2⋅−3
2⋯− 2𝑛 − 1
2.