Generating functions in 2 variables, cards, decks, hands

4
Generating functions in two variables
(Wilf, sections 1.5–1.6 and 3.14–3.17)
Definition. Let a(n, m) (n, m ≥ 0) be a function of two integer variables. The
∞ X
∞
X
2-variable generating function of a(n, m) is F (x, y) =
a(n, m)xn y m .
n=0 m=0
There are also two sequences of 1-variable ordinary power series generat∞
X
ing functions, Gn (y) =
a(n, m)y m for each n, n ≥ 0, and Hm (x) =
∞
X
m=0
a(n, m)xn for each m, m ≥ 0. Clearly,
n=0
F (x, y) =
∞
X
n
Gn (y)x =
n=0
∞
X
Hm (x)y m .
m=0
n
Examples 1. (Wilf, section 1.5) Let a(n, m) =
, then it satisfies
m
a(n, m) = a(n − 1, m − 1) + a(n − 1, m)
(4.1)
unless n = m = 0. (If n < 0 or m < 0, we set a(n, m) = 0.) We shall use this
recurrence relation to calculate the 2-variable generating function of a(n, m).
Let’s fix n ≥ 1 and calculate Gn (y). By multiplying (4.1) by y m and summing
over m we obtain
∞
X
a(n, m)y
m
m=0
=
∞
X
m
a(n − 1, m − 1)y +
m=0
∞
X
a(n − 1, m)y m
n=0
The left-hand side is Gn (y) and the second term on the right-hand side is
Gn−1 (y). The first term on the right-hand side is
∞
X
a(n − 1, m − 1)y m = y
m=0
∞
X
a(n − 1, m − 1)y m−1
m=0
=y
∞
X
m
a(n − 1, m)y = y
m=−1
∞
X
a(n − 1, m)y m = yGn−1 (y),
m=0
therefore
Gn (y) = yGn−1 (y) + Gn−1 (y) = (y + 1)Gn−1 (y).
21
Now G0 (y) =
∞
X
a(0, m)y m = 1, since a(0, 0) = 1 and a(0, m) = 0 if m > 0,
m=0
hence
Gn (y) = (y + 1)n
and
F (x, y) =
∞
X
∞
∞
X
X
n n
Gn (y)x =
(y + 1) x =
(xy + x)n =
n
n=0
n=0
n=0
1
.
1 − x − xy
xm
(see question 3 on
(1 − x)m+1
problem sheet 8) and use this to calculate F (x, y). In this case it is also
1
without using Gn
possible to give a direct proof that F (x, y) =
1 − x − xy
or Hm , but this is an exception.
Alternatively, we can prove that Hm (x) =
2. (Wilf, section 1.6) Let b(n, m) the number of ways of partitioning {1, 2, . . . , n}
into exactly m subsets (b(0, 0) = 0, b(n, m) = 0 if m < 0 or n < 0). These
numbers are called the Stirling numbers of the 2nd kind.
Given a partition of {1, 2, . . . , n} into m subsets, if n is in a subset on its
own, by omitting it we obtain a a partitioning of {1, 2, . . . , n − 1} into m − 1
subsets, if n is in a subset of at least 2 elements, by omitting it we obtain a a
partitioning of {1, 2, . . . , n − 1} into m subsets and n can be added to any of
the m subsets, therefore b(n, m) = b(n − 1, m − 1) + mb(n − 1, m) for n ≥ 1.
Let’s fix n ≥ 1 and let’s try to calculate Gn (y). By multiplying the recurrence
relation by y m and summing over m we obtain
∞
X
m
b(n, m)y =
m=0
∞
X
m
b(n − 1, m − 1)y +
m=0
∞
X
mb(n − 1, m)y m
n=0
The left-hand side is Gn (y), the first term
P on the right-handmside is 0yGn−1 (y)
just like in the previous example and ∞
= yGn−1 (y) by
n=0 mb(n − 1, m)y
Theorem 1.1 (iii), hence
Gn (y) = yGn−1 (y) + yG0n−1 (y).
∞
X
b(0, m)y m = 1, since b(0, 0) = 1 and b(0, m) = 0 if m > 0,
m=0
n
d
(1). This can be used to calculate Gn (y) for
therefore Gn (y) = y 1 +
dy
G0 (y) =
22
any particular n, for example, G1 (y) = y, G2 (y) = y 2 +y, G3 (y) = y 3 +3y 2 +y,
G4 (y) = y 4 +6y 3 +7y 2 +y, it does but this does not give an explicit expression
for Gn (y), F (x, y) or b(n, m).
There is a connection with the exponential generating function of powers of n,
egf
x
{nk }∞
n=0 ←→ Gk (x)e , because the polynomials occurring in the exponential
generating function of nk satisfy exactly the same recurrence relation.
4.1
Cards, decks and hands: the unrestricted problem
(Wilf, 3.14–3.17)
Definition. A family F is a set of objects called cards. The weight is a function w : F → Z+ associating a positive integer to each card. (In applications
the weight is usually a measure of size or value.) A deck is a set of cards of
the same weight, Dr = {x | w(x) = r} is the set of cards of weight r for each
positive integer r, and dr = |Dr | is the number of cards of weight r. We shall
assume that dr is finite for each r, but F may be infinite. A hand is a finite
collection of cards with possible repetitions, so the same card may be used
several times. The weight of a hand is the sum of the weights of the cards in
it.
h(n, k) is the number of hands of weight n consisting of k cards. h(n) =
∞
P
h(n, k) is the total number of hands of weight n. The 2-variable hand
k=0
enumerator of F is
H(x, y) =
∞ X
∞
X
h(n, k)xn y k ,
n=0 k=0
and the 1-variable hand enumerator is
∞
X
H(x) =
h(n)xn = H(x, 1).
n=0
Note: Wilf uses prefab instead of family in this context and reserves the term
family for the labelled cards used in the rest of Chapter 4.
Lemma 4.1 (Wilf, p. 93, Fundamental lemma of unlabelled counting) Let
F1 and F2 be disjoint families of cards with 2-variable hand enumerators
H1 (x, y) and H2 (x, y), respectively. Let F = F1 ∪ F2 and let H(x, y) be its
2-variable hand enumerator. Then
H(x, y) = H1 (x, y)H2 (x, y).
23
Proof. Key idea: Given a hand of weight n1 consisting of k1 cards from
F1 and a hand of weight n2 consisting of k2 cards from F2 , their union is a
hand of weight n1 + n2 consisting of k1 + k2 cards from F. Conversely, any
hand of weight n consisting of k cards from F can be split uniquely into the
union of a hand containing cards from F1 and a hand containing cards from
F2 , and if these hands have parameters n1 , k1 and n2 , k2 , respectively, then
n = n1 + n2 and k = k1 + k2 . Therefore
X
X
h(n1 , k1 )h(n2 , k2 ).
h(n, k) =
n1 +n2 =n k1 +k2 =k
n1 ≥0,n2 ≥0 k1 ≥0,k2 ≥0
Hence
H(x, y) =
=
∞ X
∞
X
h(n, k)xn y k
n=0 k=0
∞ X
∞
X
X
X
h(n1 , k1 )h(n2 , k2 )xn y k
n=0 k=0 n1 +n2 =n k1 +k2 =k
n1 ≥0,n2 ≥0 k1 ≥0,k2 ≥0
=
∞ X
∞
X
X
X
h(n1 , k1 )xn1 y k1 h(n2 , k2 )xn2 y k2
n=0 k=0 n1 +n2 =n k1 +k2 =k
n1 ≥0,n2 ≥0 k1 ≥0,k2 ≥0
=
∞ X
∞
X
∞ X
∞
X
h(n1 , k1 )xn1 y k1
n1 =0 k1 =0
h(n2 , k2 )xn2 y k2
n2 =0 k2 =0
= H1 (x, y)H2 (x, y).
Theorem 4.2 (Wilf, Theorem 3.14.1) Let F be a family of cards and let dr be
the number of cards of weight r in F, as usual. Then the hand enumerators
of F are
∞
Y
1
H(x, y) =
(1 − xr y)dr
r=1
and
H(x) =
∞
Y
1
.
(1 − xr )dr
r=1
Proof. It is sufficient to prove the theorem for the 2-variable hand enumerator
H(x, y), by substituting y = 1 into it we obtain the formula for the 1-variable
hand enumerator H(x).
The proof consists of three steps, proving the theorem gradually for more
and more general cases.
Step 1. Assume that F consists of a single card of weight s. Then ds = 1
24
and dr = 0 for r 6= s. The only possibly hand of k cards consists of k copies
of the only card and therefore has weight ks, so
(
1 if n = ks,
h(n, k) =
0 otherwise.
Hence
H(x, y) =
∞
X
k=0
xks y k =
∞
X
k=0
(xs y)k =
1
.
1 − xs y
Step 2. Assume that F is finite. We shall use induction on q = |F|.
If q = 0, then F = ∅, h(0, 0) = 1 and h(n, k) = 0 if (n, k) 6= (0, 0), so
∞
Y
1
= 1, too, so the
H(x, y) = 1. dr = 0 for all r ≥ 1, therefore
r y)dr
(1
−
x
r=1
theorem holds in this case.
Let now q ≥ 1 and let’s assume that the theorem holds for families consisting
of q − 1 cards. Let F be a family consisting of q cards. Let’s choose an
arbitrary card from F, let F1 be the family consisting of this single card and
let F2 be the family consisting of all the other cards in F. Let s be the
weight of the chosen card, and let d0s = ds − 1 and d0r = dr if r 6= s. d0r is
exactly the number of cards of weight r in F2 .
1
By Step 1, the 2-variable hand enumerator of F1 is
. F2 contains q −1
1 − xs y
∞
Y
1
cards, so by the induction hypothesis, its hand enumerator is
.
r y)d0r
(1
−
x
r=1
Hence by Lemma 4.1, the 2 variable hand enumerator of F = F1 ∪ F2 is
∞
∞
Y
Y
1
1
1
=
,
0
r y)dr
1 − xs y r=1 (1 − xr y)dr
(1
−
x
r=1
since d0s = ds − 1 and d0r = dr if r 6= s. Therefore the theorem holds for
families consisting of q cards and by induction, it holds for all finite families.
Step 3. Now F can be arbitrary, possibly infinite. Let’s fix n and k. A hand
of weight n can only contain cards of weight at most n, therefore h(n, k) is
the coefficient of xn y k in the power series expansion of the 2-variable hand
n
Y
1
enumerator of D1 ∪ D2 ∪ . . . ∪ Dn , which is
by Step 2.
r y)dr
(1
−
x
r=1
∞
Y
1
has constant term 1, all the other terms have degree at
r y)dr
(1
−
x
r=n+1
least n + 1 in x, therefore h(n, k) is also equal to the coefficient of xn y k in
25
the power series expansion of
∞
∞
Y
Y
1
1
1
=
.
r y)dr
r y)dr
r y)dr
(1
−
x
(1
−
x
(1
−
x
r=1
r=n+1
r=1
n
Y
∞
Y
1
, as claimed. As
(1 − xr y)dr
r=1
we remarked at the beginning, the result for the 1-variable hand enumerator
follows by substituting y = 1.
As this is true for all n, k, we have H(x, y) =
Examples: See pages 1–4 of http://www.maths.manchester.ac.uk/~gm/
teaching/MATH39001/Cards.pdf and http://www.maths.manchester.ac.
uk/~gm/teaching/MATH39001/Excursion_ticket.pdf.
4.2
Cards, decks and hands: the restricted problem
The family, cards, weight and decks are defined as before, but now there is a
set of non-negative integers W such that 0 ∈ W and the multiplicity of each
card in a hand must be an element of W . Let h̃(n, k) be the the number
of hands of weight n consisting of k cards which satisfy the restriction on
∞
P
the multiplicities and let h̃(n) =
h̃(n, k) be the total number of hands of
k=0
weight n satisfying the restriction.
The restricted 2-variable hand enumerator of F is
H̃(x, y) =
∞ X
∞
X
h̃(n, k)xn y k ,
n=0 k=0
and the restricted 1-variable hand enumerator is
H̃(x) =
∞
X
h̃(n)xn = H̃(x, 1).
n=0
Theorem 4.3 (Not examinable) (Wilf, Theorem 3.14.2) Let F be a family
of cards and let dr be the number of cards of weight r in F, as usual. Let W
be a subset of non-negative integers containing 0. Then the restricted hand
enumerators of F are
dr
dr
∞ X
∞ X
Y
Y
r m
mr
H̃(x, y) =
(x y)
and
H̃(x) =
x
.
r=1
r=1
m∈W
26
m∈W
Sketch of proof. Prove the analogue of Lemma 4.1 for the restricted case and
then follow the steps of the proof of Theorem 4.2. Note thatX
for a family
consisting of a single card of weight s in Step 1, H̃(x, y) =
(xs y)m by
m∈W
direct calculation.
Remarks. 1. If W = Z≥0 ,
∞
X
X
r
m
(x y) =
∞
X
(xr y)m =
m=0
m∈W
X
1
and
xmr =
r
1−x y
m∈W
1
, so we obtain Theorem 4.2 as a special case.
1 − xr
m=0
2. If the restriction is that each card can be used at most l times for a fixed
l
X
X
1 − (xr y)l+1
l, then W = {0, 1, 2, . . . , l} and
(xl y)m =
(xr y)m =
.
ry
1
−
x
m=0
m∈W
xmr =
Examples: See pages 5–6 of http://www.maths.manchester.ac.uk/~gm/
teaching/MATH39001/Cards.pdf.
27