Professional Documents
Culture Documents
Generating Functions and Recurrence Relations
Generating Functions and Recurrence Relations
RELATIONS
Generating Functions
Recurrence Relations
Generating Functions
Linear Recurrence
Fibonacci Sequence
an = an−1 + an−2 n ≥ 2.
a0 = a1 = 1.
Generating Functions
bn = |Bn | = |{x ∈ {a, b, c}n : aa does not occur in x}|.
b1 = 3 : a b c
b2 = 8 : ab ac ba bb bc ca cb cc
bn = 2bn−1 + 2bn−2 n ≥ 2.
Generating Functions
bn = 2bn−1 + 2bn−2 n ≥ 2.
Let
(b) (c) (a)
Bn = Bn ∪ Bn ∪ Bn
(α)
where Bn = {x ∈ Bn : x1 = α} for α = a, b, c.
f (bx2 x3 . . . xn ) = x2 x3 . . . xn is a bijection.
(a)
Bn = {x ∈ Bn : x1 = a and x2 = b or c}. The map
(a) (b) (c)
g : Bn → Bn−1 ∪ Bn−1 ,
g(ax2 x3 . . . xn ) = x2 x3 . . . xn is a bijection.
(a)
Hence, |Bn | = 2|Bn−2 |.
Generating Functions
Towers of Hanoi
H n-1 moves
1 move
H n-1 moves
Generating Functions
We see that H1 = 1 and Hn = 2Hn−1 + 1 for n ≥ 2.
So,
Hn Hn−1 1
n
− n−1 = n .
2 2 2
Hn H1 1 1 1 1 1
− = n + n−1 + · · · + = − n .
2n 2 2 2 4 2 2
So
Hn = 2n − 1.
Generating Functions
A has n dollars. Everyday A buys one of a Bun (1 dollar), an
Ice-Cream (2 dollars) or a Pastry (2 dollars). How many ways
are there (sequences) for A to spend his money?
Ex. BBPIIPBI represents “Day 1, buy Bun. Day 2, buy Bun etc.”.
un = number of ways
= un,B + un,I + un,P
Generating Functions
If a0 , a1 , . . . , an is a sequence of real numbers then its
(ordinary) generating function a(x) is given by
a(x) = a0 + a1 x + a2 x 2 + · · · an x n + · · ·
and we write
an = [x n ]a(x).
Generating Functions
an = 1
1
a(x) = = 1 + x + x2 + · · · + xn + · · ·
1−x
an = n + 1.
1
a(x) = = 1 + 2x + 3x 2 + · · · + (n + 1)x n + · · ·
(1 − x)2
an = n.
x
a(x) = = x + 2x 2 + 3x 3 + · · · + nx n + · · ·
(1 − x)2
Generating Functions
Generalised binomial theorem:
α
an = n
∞
X α n
a(x) = (1 + x)α = x .
n
n=0
where
α α(α − 1)(α − 2) · · · (α − n + 1)
= .
n n!
m+n−1
an = n
∞ ∞
1 X −m n
X m+n−1 n
a(x) = = (−x) = x .
(1 − x)m n n
n=0 n=0
Generating Functions
General view.
Generating Functions
Solution of linear recurrences
an − 6an−1 + 9an−2 = 0 n ≥ 2.
a0 = 1, a1 = 9.
∞
X
(an − 6an−1 + 9an−2 )x n = 0. (2)
n=2
Generating Functions
∞
X
an x n = a(x) − a0 − a1 x
n=2
= a(x) − 1 − 9x.
∞
X ∞
X
6an−1 x n = 6x an−1 x n−1
n=2 n=2
= 6x(a(x) − a0 )
= 6x(a(x) − 1).
∞
X ∞
X
9an−2 x n = 9x 2 an−2 x n−2
n=2 n=2
= 9x 2 a(x).
Generating Functions
a(x) − 1 − 9x − 6x(a(x) − 1) + 9x 2 a(x) = 0
or
a(x)(1 − 6x + 9x 2 ) − (1 + 3x) = 0.
1 + 3x 1 + 3x
a(x) = 2
=
1 − 6x + 9x (1 − 3x)2
∞
X X∞
= (n + 1)3n x n + 3x (n + 1)3n x n
n=0 n=0
X∞ ∞
X
= (n + 1)3n x n + n n
n3 x
n=0 n=0
∞
X
= (2n + 1)3n x n .
n=0
an = (2n + 1)3n .
Generating Functions
Fibonacci sequence:
∞
X
(an − an−1 − an−2 )x n = 0.
n=2
∞
X ∞
X ∞
X
an x n − an−1 x n − an−2 x n = 0.
n=2 n=2 n=2
1
a(x) = .
1 − x − x2
Generating Functions
1
a(x) = −
(ξ1 − x)(ξ2 − x)
1 1 1
= −
ξ1 − ξ2 ξ1 − x ξ2 − x
!
1 ξ1−1 ξ2−1
= −
ξ1 − ξ2 1 − x/ξ1 1 − x/ξ2
where √ √
5+1 5−1
ξ1 = − and ξ2 =
2 2
are the 2 roots of
x 2 + x − 1 = 0.
Generating Functions
Therefore,
∞ ∞
ξ1−1 X −n n ξ2−1 X −n n
a(x) = ξ1 x − ξ2 x
ξ1 − ξ2 ξ1 − ξ2
n=0 n=0
∞ −n−1
X ξ − ξ −n−1
= 1 2
xn
ξ1 − ξ2
n=0
and so
ξ1−n−1 − ξ2−n−1
an =
ξ −ξ
1 √2 !n+1 √ !n+1
1 5+1 1− 5
= √ − .
5 2 2
Generating Functions
Inhomogeneous problem
an − 3an−1 = n2 n ≥ 1.
a0 = 1.
X ∞ ∞
X
n
(an − 3an−1 )x = n2 x n
n=1 n=1
∞
X ∞
X ∞
X
2 n n
n x = n(n − 1)x + nx n
n=1 n=2 n=1
2x 2 x
= +
(1 − x)3 (1 − x)2
x + x2
=
(1 − x)3
∞
X
(an − 3an−1 )x n = a(x) − 1 − 3xa(x)
n=1
= a(x)(1 − 3x) − 1.
Generating Functions
x + x2 1
a(x) = 3
+
(1 − x) (1 − 3x) 1 − 3x
A B C D+1
= + + +
1−x (1 − x)2 (1 − x)3 1 − 3x
where
x + x2 ∼
= A(1 − x)2 (1 − 3x) + B(1 − x)(1 − 3x)
+ C(1 − 3x) + D(1 − x)3 .
Then
A = −1/2, B = 0, C = −1, D = 3/2.
Generating Functions
So
−1/2 1 5/2
a(x) = − 3
+
1−x (1 − x) 1 − 3x
∞ ∞ ∞
1 X
n
X n+2 n 5X n n
= − x − x + 3 x
2 2 2
n=0 n=0 n=0
So
1 n+2 5
an = − − + 3n
2 2 2
3 3n n2 5 n
= − − − + 3 .
2 2 2 2
Generating Functions
General case of linear recurrence
an + c1 an−1 + · · · + ck an−k = un , n ≥ k.
u0 , u1 , . . . , uk −1 are given.
X
(an + c1 an−1 + · · · + ck an−k − un ) x n = 0
a(x)b(x) = (a0 + a1 x + a2 x 2 + · · · ) ×
(b0 + b1 x + b2 x 2 + · · · )
= a0 b0 + (a0 b1 + a1 b0 )x +
(a0 b2 + a1 b1 + a2 b0 )x 2 + · · ·
∞
X
= cn x n
n=0
where
n
X
cn = ak bn−k .
k =0
Generating Functions
Derangements
n
X n
n! = dn−k .
k
k =0
n
Explanation: k dn−k is the number of permutations with
n
exactly k cycles of length 1. Choose k elements ( k ways) for
which π(i) = i and then choose a derangement of the
remaining n − k elements.
So
n
X 1 dn−k
1 =
k ! (n − k )!
k =0
∞ ∞ n
!
X X X 1 dn−k
xn = x n. (3)
k ! (n − k )!
n=0 n=0 k =0
Generating Functions
Let
∞
X dm m
d(x) = x .
m!
m=0
1
= ex d(x)
1−x
e−x
d(x) =
1−x
∞ X n
(−1)k
X
= x n.
k!
n=0 k =0
So
n
dn X (−1)k
= .
n! k!
k =0
Generating Functions
Triangulation of n-gon
Let
an = number of triangulations of Pn+1
Xn
= ak an−k n≥2 (4)
k =0
a0 = 0, a1 = a2 = 1.
k +1
n+1
1
Generating Functions
Explanation of (4):
ak an−k counts the number of triangulations in which edge
1, n + 1 is contained in triangle 1, k + 1, n + 1.
There are ak ways of triangulating 1, 2, . . . , k + 1, 1 and for
each such there are an−k ways of triangulating
k + 1, k + 2, . . . , n + 1, k + 1.
Generating Functions
∞ ∞ n
!
X X X
x+ an x n = x + ak an−k x n.
n=2 n=2 k =0
But,
∞
X
x+ an x n = a(x)
n=2
since a0 = 0, a1 = 1.
∞ ∞
n
! n
!
X X X X
n
ak an−k x = ak an−k xn
n=2 k =0 n=0 k =0
2
= a(x) .
Generating Functions
So
a(x) = x + a(x)2
and hence
√ √
1+ 1 − 4x 1 − 1 − 4x
a(x) = or .
2 2
But a(0) = 0 and so
√
1 − 1 − 4x
a(x) =
2
∞
!
(−1)n−1 2n − 2
1 1 X
n
= − 1+ (−4x)
2 2 n22n−1 n − 1
n=1
∞
X 1 2n − 2 n
= x .
n n−1
n=1
So
1 2n − 2
an = .
n n−1
Generating Functions
Exponential Generating Functions
an = 1, n ≥ 0 implies ae (x) = ex .
1
an = n!, n ≥ 0 implies ae (x) =
1−x
Generating Functions
Products of Exponential Generating Functions
where
n
cn = ak bn−k .
k
Generating Functions
Interpretation
Examples:
(a): Each object is a directed path with k vertices and its
vertices are labelled by 1, 2, . . . , k in some order. Thus ak = k !.
(b): Each object is a directed cycle with k vertices and its
vertices are labelled by 1, 2, . . . , k in some order. Thus
ak = (k − 1)!.
Generating Functions
1
Now take example (a) and let ae (x) = 1−x be the e.g.f. of this
family. Now consider
∞
X
ce (x) = ae (x)2 = (n + 1)x n with cn = (n + 1) × n!.
n=0
Generating Functions
We will now use this machinery to count the number sn of
permutations that have an even number of cycles all of which
have odd lengths:
Cycles of a permutation
Let π : D → D be a permutation of the finite set D. Consider the
digraph Γπ = (D, A) where A = {(i, π(i)) : i ∈ D}. Γπ is a
collection of vertex disjoint cycles. Each x ∈ D being on a
unique cycle. Here a cycle can consist of a loop i.e. when
π(x) = x.
Example: D = [10].
i 1 2 3 4 5 6 7 8 9 10
π(i) 6 2 7 10 3 8 9 1 5 4
The cycles are (1, 6, 8), (2), (3, 7, 9, 5), (4, 10).
Generating Functions
In general consider the sequence i, π(i), π 2 (i), . . . ,.
Generating Functions
Now consider
∞
X (2m)!
ae (x) = x 2m+1
(2m + 1)!
m=0
Here (
0 n is even
an =
(n − 1)! n is odd
Thus each object is an odd length cycle C, labelled by [|C|].
Note that
x2 x3 x4
2
x4
x
ae (x) = x + + + + ··· − + + ···
2 3 4 2 4
1 1 1
= log − log
1−x 2 1 − x2
r
1+x
= log
1−x
Generating Functions
cn
Now consider ae (x)` . The coefficient of x n in this series is n!
where cn is the number of ways of choosing an ordered
sequence of ` cycles of lengths a1 , a2 , . . . , a` where
a1 + a2 + · · · + a` = n. And then a partition of [n] into
A1 , A2 , . . . , A` where |Ai | = ai for i = 1, 2, . . . , `. And then
labelling the ith cycle with Ai for i = 1, 2, . . . , `.
`
It follows that the coefficient of x n in ae (x)
`! is cn!n where cn is the
number of ways of choosing a set (unordered sequence) of `
cycles of lengths a1 , a2 , . . . , a` . . .
Generating Functions
Now
∞ r r !
X ae (x)2k eae (x) + e−ae (x) 1 1+x 1−x
= = +
k! 2 2 1−x 1+x
k =0
1
=√
1 − x2
Thus
n 1 n n!
sn = n![x ] √ =
1 − x2 n/2 2n
Generating Functions
Exponential Families
Generating Functions
Given F let h(n, k ) denote the number of hands of weight n
consisting of k cards, such that each card is a re-labelling of
some card in some deck of F.
(The same card can be used for re-labelling more than once.)
Next let the hand enumerator H(x, y ) be defined by
X xn k
H(x, y ) = h(n, k ) y , (h(n, 0) = 1n=0 ).
n!
n≥1
k ≥0
P∞ dn n
Let dn = |Dn | and D(x) = n=1 n! x .
Theorem
H(x, y ) = ey D(x) . (5)
Generating Functions
Example 1: Let P = {directed cycles of all lengths}.
dn = (n − 1)! and so
∞
xn
X 1
D(x) = = log
n 1−x
n=1
and
1 1
H(x, y ) = exp y log = .
1−x (1 − x)y
Generating Functions
Let kn denote the number of permutations of [n] with exactly k
cycles. Then
n h i
xn
X n 1
yk =
k n! (1 − x)y
k =1
y +n−1
= n!
n
= y (y + 1) · · · (y + n − 1).
n
The values k are referred to as the Stirling numbers of the
first kind.
Generating Functions
Example 2: Let P = {[n], n ≥ 1}.
A card is a non-empty set of positive integers.
A hand of k cards is a partition of [n] into k non-empty subsets.
dn = 1 for n ≥ 1 and so
∞
X xn
D(x) = = ex − 1
n!
n=1
and
x −1)
H(x, y ) = ey (e .
n
So, if k is the number of partitions of [n] into k parts then
x n (ex − 1)k
nno
= .
k n! k!
second kind.
Generating Functions
Proof of (5): Let F 0 , F 00 be two exponential families whose
picture sets are disjoint. We merge them to form F = F 0 ⊕ F 00
by taking all dn0 cards from the deck Dn0 and adding them to the
deck Dn00 to make a deck of dn0 + dn00 cards.
We claim that
Generating Functions
But,
0 00
X xn 0
X xn 00
H0 (x, y )H00 (x, y ) = h(n0 , k 0 ) yk h(n00 , k 00 ) yk
n0 ! n00 !
n0 ,k 0 n00 ,k 00
X n
n! 0 0 00 00 x k
= 0 0
h(n , k )h(n , k ) y .
n (n − n )! n!
n,k
Generating Functions
Now fix positive weights r , d and consider an exponential family
Fr ,d that has d cards in deck Dr and no other non-empty decks.
We claim that the hand enumerator of Fr ,d is
ydx r
Hr ,d (x, y ) = exp . (7)
r!
We prove this by induction on d.
Base Case d = 1: A hand consists of k ≥ 0 copies of the
unique standard card that exists. If n = kr then there are
n! n!
=
r !r ! · · · r ! (r !)k
choices for the labels of the cards. Then
1 n!
h(kr , k ) =
k ! (r !)k
where we have divided by k ! because the cards in a hand are
unordered. If r does not divide n then h(n, k ) = 0.
Generating Functions
Thus,
∞
X 1 n! x n k
Hr ,1 (x, y ) = y
k ! (r !)k n!
k =0
r
yx
= exp
r!
Generating Functions
Now consider a general deck D as the union of disjoint decks
Dr , r ≥ 1. then,
ydx r
Y Y
H(x, y ) = Hr (x, y ) = exp = ey D(x) .
r!
r ≥1 r ≥1
Generating Functions