IMOMATH - Generating Functions
IMOMATH - Generating Functions
IMOMATH - Generating Functions
Generating Functions
Milan Novaković
Contents
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 Theoretical Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
3 Recurrent Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
4 The Method of the Snake Oil . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
5 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
6 Solultions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1 Introduction
Generating functions are powerful tools for solving a number of problems mostly in combinatorics,
but can be useful in other branches of mathematics as well. The goal of this text is to present certain
applications of the method, and mostly those using the high school knowledge.
In the beginning we have a formal treatement of generating functions, i.e. power series. In other
parts of the article the style of writing is more problem-soving oriented. First we will focus on
solving the reccurent equations of first, second, and higher order, after that develope the powerful
method of ,,the snake oil“, and for the end we leave some other applications and various problems
where generating functions can be used.
The set of natural numbers will be denoted by N, while N0 will stand for the set of non-negative
integers. For the sums going from 0 to +∞ the bounds will frequently be omitted – if a sum is
without the bounds, they are assumed to be 0 and +∞.
2 Theoretical Introduction
In dealing with generating functions we frequently want to use different transformations and ma-
nipulations that are illegal if the generating functions are viewed as analytic functions. Therefore
they will be introduced as algebraic objects in order to obtain wider range of available methods. The
theory we will develope is called the formal theory of power series.
Remark. We will use the other expressions also: series, generating function...
For example the series
converges only for x = 0 while, in the formal theory this is well defined formal power series with the
correspongind sequence of coefficients equal to {ai }∞ i
0 , ai = i .
Remark. Sequences and their elements will be most often denoted by lower-case latin letters (a, b,
a3 · · · ), while the power series generated by them (unless stated otherwise) will be denoted by the
corresponding capital letters (A, B, · · · ).
∞ ∞
Definition 2. Two series A = ∑ ai xi and B = ∑ bixi are called equal if their corresponding se-
i=0 i=0
quences of coefficients are equal, i.e. ai = bi for every i ∈ N0 .
Remark. The coefficient near xn in the power series F will be denoted by [xn ]F.
We can define the sum and the difference of power series in the following way
∑ a n xn ∑ b n xn = ∑ cn xn , cn = ∑ ai bn−i
n n n i
Instead of F · F we write F 2 , and more generally F n+1 = F · F n . We see that the neutral for
addition is 0, and 1 is the neutral for multiplication. Now we can define the following term:
Definition 3. The formal power series G is reciprocal to the formal power series F if FG = 1.
The generating function reciprocal to F will be usually denoted by 1/F. Since the multiplication
is commutative we have that FG = 1 is equivalent to GF = 1 hence F and G are mutually reciprocal.
We also have (1−x)(1+x+x2 +· · · ) = 1+ ∑∞ i 2
i=1 (1·1−1·1)x = 1 hence (1−x) and (1+x+x +· · · )
are mutually reciprocal.
Theorem 1. Formal power series F = ∑ an xn has a reciprocal if and only if a0 6= 0. In that case
n
the reciprocal is unique.
Proof. Assume that F has a reciprocal given by 1/F = ∑ bn xn . Then F · (1/F) = 1 implying
n
1 = a0 b0 hence a0 6= 0. For n > 1 we have 0 = ∑ ak bn−k from where we conclude.
k
1
a0 ∑
bn = − ak bn−k .
k
Definition 6. A osr ∞ ∞
↔ {an }0 means that A is a usual power series which is generated by {an }0 , i.e.
A = ∑ an x .
n
n
1 A(x) − a0
∑ an+1xn = x ∑ anxn = x
n n>0
A − a0
or equivalently {an+1 }∞ osr
0 ↔ . Similarly
x
(A − a0)/x − a1 A − a0 − a1 x
{an+2}∞ osr
0 ↔ = .
x x2
Theorem 4. If {an}∞ osr
0 ↔ A the for h > 0:
A − a0 − a1x − · · · − ah−1xh−1
{an+h }∞ osr
0 ↔ .
xh
Proof. We will use the induction on h. For h = 1 the statement is true and that is shown before. If
the statement holds for some h then
A − a0 − a1x − · · · − ah−1xh−1
− ah
{an+h+1}∞ osr {a(n+h)+1}∞ osr xh
0 ↔ 0 ↔
x
osr A − a 0 − a 1 x − · · · − a h xh
↔ ,
xh+1
which finishes the proof. 2
We already know that {(n + 1)an+1}∞ osr ′ ∞
0 ↔ A . Our goal is to obtain the sequence {nan }0 . That is
′
exactly the sequence xA . We will define the operator xD in the following way:
Definition 7. xDA = xA′ i.e. xDA = x dA
dx .
The following two theorems are obvious consequences of the properties of the derivative:
Theorem 5. Let {an }∞ osr k ∞ osr k
0 ↔ A. Then {n an }0 ↔ (xD) A.
4 Olympiad Training Materials, www.imomath.com
A 1
Let us consider the generating function . It can be written as A 1−x . As we have shown
1−x
A
before the reciprocal to the series 1 − x is 1 + x + x2 + · · · , hence 1−x = (a0 + a1 x + a2x2 + · · · )(1 +
2 2
x + x + · · · ) = a0 + (a0 + a1)x + (a0 + a1 + a2 )x + · · · .
Theorem 7. If {an}∞ osr
0 ↔ A then
( )
n
A
1−x
osr
↔ ∑ aj .
j=0 n>0
an n
A=∑ x .
n n!
∞ ∞ ∞
nbn xn−1 bn xn−1 bn+1 xn
B′ = ∑ =∑ =∑
n=1 n! n=1 (n − 1)! n=0 n!
hence B′ esr ∞
↔ {bn+1 }0 .
{bn+h }∞
0
osr
↔ B(h) .
The exponential generating functions are useful in combinatorial identities because of the fol-
lowing property.
Theorem 10. Let {an }∞ esr ∞ esr
0 ↔ A and {bn }0 ↔ B. Then the generating function AB generates the se-
quence ( )∞
n
∑ k ak bn−k .
k n=0
or ( )
xn xn
n!ai b j n
AB = ∑ ∑ i! j! =∑ ∑ ak bn−k ,
n n! i+ j=n n n! k k
Milan Novaković: Generating Functions 5
1
= ∑ xn
1 − x n>0
1 xn
ln =∑
1 − x n>1 n
xn
ex = ∑ n!
n>0
x2n+1
sin x = ∑ (−1)n (2n + 1)!
n>0
x2n
cos x = ∑ (−1)n (2n)!
n>0
α k
(1 + x) = ∑ α
x
k k
1 n+k n
(1 − x)k+1 ∑
= x
n n
x B n xn
ex − 1
= ∑
n>0 n!
x2n+1
arctan x = ∑ (−1)n 2n + 1
n>0
√
1 1 2n n
(1 − 1 − 4x) = ∑ x
2x n n + 1 n
1 2n n
√ =∑ x
1 − 4x n n
(−4)n B2n 2n
x cot x = ∑ (2k)!
x
n>0
x (4n − 2)B2n 2n
= ∑ (−1)n−1 x
sin x n>0 (2n)!
√ k
1 1 − 1 − 4x 2n + k n
√ =∑ x
1 − 4x 2x n n
6 Olympiad Training Materials, www.imomath.com
√ k
1 − 1 − 4x k(2n + k − 1)! n
=∑ x
2x n>0 n!(n + k)!
(2n − 1)!!x2n+1
arcsin x = ∑
n>0 (2n)!!(2n + 1)
2 2 sin n4π n
n
e sin x = ∑
x
x
n>1 n!
1 Hn−1 n
ln2 =∑ x
1 − x n>2 n
√
s
∞
1− 1−x (4n)!
=∑ √ xn
x n=0 16
n 2(2n)!(2n + 1)!
∞
arcsin x 2 4n n!2
=∑ x2n
x n=0 (k + 1)(2k + 1)!
n
1
Remark: Here Hn = ∑ , and Bn is the n-th Bernoulli number.
i=1 i
3 Recurrent Equations
We will first solve one basic recurrent equation.
Problem 1. Let an be a sequence given by a0 = 0 and an+1 = 2an + 1 for n > 0. Find the general
term of the sequence an .
Solution. We can calculate the first several terms 0, 1, 3, 7, 15, and we are tempted to guess the
solution as an = 2n − 1. The previous formula can be easily established using mathematical induction
but we will solve the problem using generating functions. Let A(x) be the generating function of
the sequence an , i.e. let A(x) = ∑ an xn . If we multiply both sides of the recurrent relation by xn and
n
add for all n we get
A(x) − a0 A(x) 1
∑ an+1xn = x
=
x
= 2A(x) +
1−x ∑
= (2an + 1)xn .
n n
A−1 x
= 2A + .
x (1 − x)2
1 − 2x + 2x2 P Q R
= + + .
(1 − x)2(1 − 2x) (1 − x)2 1 − x 1 − 2x
or equivalently
This implies P = −1, Q = 0, and R = 2. There was an easier way to get P, Q, and R. If we multiply
both sides by (1 − x)2 and set x = 1 we get P = −1. Similarly if we multiply everything by 1 − 2x
and plug x = 21 we get R = 2. Now substituting P and R and setting x = 0 we get Q = 0.
Thus we have
−1 2
A= + .
(1 − x)2 1 − 2x
2 osr n+1 1 1 osr
Since {2 } and =D {n + 1} we get an = 2n+1 − n − 1. △
1 − 2x ↔ (1 − x)2 1−x ↔
In previous two examples the term of the sequence was depending only on the previous term.
We can use generating functions to solve recurrent relations of order greater than 1.
Problem 3 (Fibonacci’s sequence). F0 = 0, F1 = 1, and for n > 1, Fn+1 = Fn + Fn−1. Find the
general term of the sequence.
Solution. Let F be the generating function of the series {Fn}. If we multiply both sides by xn and
F−x
add them all, the left-hand side becomes {Fn+1 } osr
↔ x , while the right-hand side becomes F + xF.
Therefore
x
F= .
1 − x − x2
Now we want to expand this function into power series. First we want to represent the function as a
sum of two fractions. Let
−x2 − x + 1 = (1 − α x)(1 − β x).
√ √ √
Then α = (1 + 5)/2, β = (1 − 5)/2, and α − β = 5. We further have
x x 1 1 1
= = −
1 − x − x2 (1 − xα )(1 − xβ ) α − β 1 − xα 1 − xβ
∞ ∞
( )
1
= √ ∑α x −∑β x .
5 n=0
n n n n
n=0
8 Olympiad Training Materials, www.imomath.com
It is easy to obtain
1
Fn = √ (α n − β n ). △
5
Remark: From here we can immediately get the approximate formula for Fn . Since |β | < 1 we have
lim β n = 0 and
n→∞
√ !n
1 1+ 5
Fn ≈ √ .
5 2
Now we will consider the case with the sequence of two variables.
Problem 4. Find the number of k-element subsets of an n-element set.
Solution. We know that the result is nk , but we want to obtain this using the generating functions.
Assume that the required number is equal to c(n, k). Let A = {a1 , . . . , an } be an n-element set. There
are two types of k-element subsets – those which contain an and those that don’t. There are exactly
c(n − 1, k − 1) subsets containing an . Indeed they are all formed by taking k − 1-element subsets of
{a1 , . . . , an−1 } and adding an to each of them. On the other hand there are exaclty c(n − 1, k) subsets
not contianing an . Hence
c(n, k) = c(n − 1, k) + c(n − 1, k − 1).
We also have c(n, 0) = 1. Now we will define the generating function of the sequence c(n, k) for a
fixed n. Assume that
Cn (x) = ∑ c(n, k)xk .
k
If we multiply the recurrent relation by xk and add for all k > 1 we get
Cn (x) − 1 = (Cn−1 (x) − 1) + xCn−1(x), for each n > 0
and C0 (x) = 1. Now we have for n > 1:
Cn (x) = (1 + x)Cn−1 (x).
We finally have Cn (x) = (1 + x)n . Hence, c(n, k) is the coefficient near xk in the expansion of (1 + x)n ,
n
and that is exactly k .△
Someone might think that this was a cheating. We have used binomial formula, and that is
obtianed using a combinatorial technique which uses the result we wanted to prove. Fortunately,
there is a proof of binomial formula involving Taylor expainsion.
We can also make a generating function of the sequece Cn (x):
n 1
∑ Cn (x)y = ∑ ∑ k xk yn = ∑(1 + x)nyn = 1 − y(1 + x) .
n
n n k n
n n
In such a way we have k = [x y ](1 − y(1 + x)) . Now we can calculate the sum ∑
n k n −1
y :
n k
n k n 1 1 1
[x ] ∑ ∑
k
x y = [xk ] = [xk ] y
n k k 1 − y(1 + x) 1 − y 1 − 1−y x
k k
1 y y
= = .
1−y 1−y (1 − y)k+1
Hence we have the identities
yk
n n
∑ k xk = (1 + x)n; ∑ k yn = (1 − y)k+1 .
k n
n
Remark: For n < k we define = 0.
k
Milan Novaković: Generating Functions 9
Problem 5. Find the general term of the sequence an+3 = 6an+2 − 11an+1 + 6an, n > 0 with the
initial conditions a0 = 2, a1 = 0, a2 = −2.
Solution. If A is the generating function of the corresponding sequence then:
20x2 − 12x + 2 B C D
= + + .
(1 − x)(1 − 2x)(1 − 3x) 1 − x 1 − 2x 1 − 3x
20−12+2
We will multiply both sides by (1 − x) and set x = 1 to obtain B = (−1)·(−2) = 5. Multiplying by
5−6+2
(1 − 2x) and setting x = 1/2 we further get C = = −4. If we now substitute the found values
− 41
for B and C and put x = 0 we get B + C + D = 2 from where we deduce D = 1. We finally have
∞
5 4 1
A= − + = ∑ (5 − 4 · 2n + 3n )xn
1 − x 1 − 2x 1 − 3x n=0
−i/2 i/2
A= + .
1 − (−2 + 2i)x 1 − (−2 − 2i)x
Solution. Let X(t) be the generating function of our sequence. Using the same methods as in the
examples above we can see that the following holds:
X X 1 t
− 6 + 9X = + .
t2 t 1 − 2t (1 − t)2
t2 − t3 − t4
X(t) = ,
(1 − t)2(1 − 2t)(1 − 3t)2
hence
1 1 5 5
X(t) = + − + .
4(1 − x)2 1 − 2x 3(1 − 3x) 12(1 − 3x)2
n+1
The sequence corresponding to the first summand is , while the sequences for the second, third,
4
5(n + 1)3n+1
and fourth are 2n , 5 · 3n−1, and respectively. Now we have
12
2n+2 + n + 1 + 5(n − 3)3n−1
xn = . △
4
Milan Novaković: Generating Functions 11
Problem 8. Let f1 = 1, f2n = fn , and f2n+1 = fn + fn+1 . Find the general term of the sequence.
Solution. We see that the sequence is well define because each term is defined using the terms
already defined. Let the generating function F be given by
F(x) = ∑ fn xn−1.
n>1
Multiplying the first given relation by x2n−1 , the second by x2n , and adding all of them for n ≥ 1 we
get:
f1 + ∑ f2n x2n−1 + ∑ f2n+1 x2n = 1 + ∑ fn x2n−1 + ∑ fn x2n + ∑ fn+1 x2n
n>1 n>1 n>1 n>1 n>1
or equivalently
∑ fn xn−1 = 1 + ∑ fn x2n−1 + ∑ fn x2n + ∑ fn+1 x2n .
n>1 n>1 n>1 n>1
2 2 2 2
This exactly means that F(x) = x F(x ) + xF(x ) + F(x ) i.e.
F(x) = (1 + x + x2)F(x2 ).
Moreover we have
∞
F(x) = ∏ 1 + x2 + x2
i i+1
.
i=0
We can show that the sequence defined by the previous formula has an interesting property. For every
positive integer n we perform the following procedure: Write n in a binary expansion, discard the
last ”block” of zeroes (if it exists), and group the remaining digits in as few blocks as possible such
that each block contains the digits of the same type. If for two numbers m and n the corresponding
sets of blocks coincide the we have fm = fn . For example the binary expansion of 22 is 10110 hence
the set of corresponding blocks is {1, 0, 11}, while the number 13 is represented as 1101 and has
the very same set of blocks {11, 0, 1}, so we should have f (22) = f (13). Easy verification gives us
f (22) = f (13) = 5. From the last expression we conclude that fn is the number of representations
of n as a sum of powers of two, such that no two powers of two are taken from the same set of a
collection {1, 2}, {2, 4}, {4, 8}.
n n
Sometimes we will use the identity for ∑ x which is already mentioned in the list of gen-
n k
erating functions:
1 n+k n
(1 − x)k+1 ∑
= x .
n k
Among the common sums we will
encounter those involving
only even (or odd) indeces. For
m n m
example we have (1 + x) = ∑
m x , hence (1 − x) = ∑
m (−x)n . Adding and subtracting
n n n n
yields:
((1 + x)m + (1 − x)m)
m
∑ 2n x2n = 2
,
n
2n 2n xm (−1)m
1
∑ m x = +
2 (1 − x)m+1 (1 − x)m+1
, and
n
2n + 1 2n+1 xm (−1)m
1
∑ m x = −
2 (1 − x)m+1 (1 − x)m+1
.
n
which gives
1 1
F(x) = ∑ xk (1 + x)k = ∑(x + x2 )k = = .
k k 1 − (x − x2) 1 − x − x2
However this is very similar to the generating function of a Fibonacci’s sequence, i.e. f (n) = Fn+1
and we arrive to
k
∑ n − k = Fn+1. △
k
Milan Novaković: Generating Functions 13
n is afixed number, then m is a free variable on which the sum depends. Let f (m) =
Solution. If
n
n k
∑ (−1)k k m and let F(x) be the generating function of the sequence f (m), i.e. F(x) =
k=m
∑m f (m)xm . Then we have
n
k n k
F(x) = ∑ f (m)x = ∑ x ∑ (−1)
m m
=
m m k=m k m
k n k m n
= ∑ (−1) ∑ m x = ∑ k (1 + x)k .
k6n k m6k k6n
k m
Here we have used ∑m6k m x = (1 + x)k . Dalje je
n
n
F(x) = (−1) ∑
n
(−1)n−k (1 + x)k = (−1)n (1 + x) − 1 = (−1)n xn
k6n k
Therefore we obtained F(x) = (−1)n xn and since this is a generating function of the sequence f (m)
we have
(−1)n , n = m
f (m) =
0, m < n . △
n
n k
Problem 11. Evaluate the sum ∑ .
k=m k m
n
n k
Solution. Let f (m) = ∑ and F(x) = ∑ xm f (m). Then we have
k=m k m m
n
n k n k m n
F(x) = ∑ x f (m) = ∑ x ∑
m m
=∑ ∑ m x = ∑ k (1 + x)k ,
m m k=m k m k6n k m6k k6n
or equivalently
n
∑ k xk = (1 + x)(1 + x2)n . △
k 2
14 Olympiad Training Materials, www.imomath.com
For y = 2 we have that F(x) = (1 + x)2n+1 , implying that F(x) is the generating function of the
2n+1
sequence m and we get the following combinatorial identity:
n n−k k 2n + 1
∑ k m−k 2 = m .
k 2
Settingy =
−2 we get (1 + x)(1 − x)2n = (1
F(x) = − x)2n
+ x(1
2n
− x)hence the coefficient near x
m
2n 2n 2n 2n
equals (−1)m + (−1)m−1 = (−1)m − which implies
m m−1 m m−1
n n−k 2n 2n
∑ k m−k (−2) = (−1) m − m − 1 . △
k m
k 2
for m, n > 0.
Solution. Since there are quite a lot of variables elementary combinatorial methods doesn’t offer an
effective way to treat the sum. Since n appears on only one place in the sum, it is natural to consider
the sum as a function on n Let F(x) be the generating series of such functions. Then
2k (−1)k 2k (−1)k −k
n+k n+k
F(x) = ∑ xn ∑ =∑ x ∑ xn+k =
n k m + 2k k k + 1 k k k + 1 n m + 2k
k
2k (−1)k −k xm+2k xm+2k
2k 1 −x
=∑
(1 − x)m+2k+1 (1 − x)m+2k+1 ∑
x = =
k k k+1 k k k + 1 (1 − x)2
( s )
−xm−1 −xm−1 xm
4x 1+x
= 1 − 1 + = 1 − = .
2(1 − x)m−1 (1 − x)2 2(1 − x)m−1 1−x (1 − x)m
n−1
This is a generating function of the sequence which establishes
m−1
2k (−1)k
n+k n−1
∑ m + 2k k k + 1 =
m−1
. △
k
1 √
1 1
F(x) = ( x)2n−1 √ − √ .
2 (1 − x)2n+1 (1 + x)2n+1
implying
" #
(x1/2 )2n 1 1
−1/2 2n
G(x) = x − (−1) ,
2 (1 − x1/2)2n+1 (1 + x1/2)2n+1
or
1 √
1 1
G(x) = ( x)2n−1 √ 2n+1 − √ 2n+1 . △
2 (1 − x) (1 + x)
Problem 17. Prove that
n
2n 2k 2n−2k 4n
∑ 2k k
2 =
2n
.
k=0
Let n be the free variable on the left and right side of F(x) and G(x). We want to prove the
equality of these generating functions.
2n 2k 2n−2k 2k −2k 2n n 2n
F(x) = ∑ xn ∑ 2 =∑ 2 ∑ x 2 ,
n 06k6n 2k k 06k k n 2k
√
2k −2k 2n
F(x) = ∑ 2 ∑ (2 x)2n .
06k k n 2k
Now we use the formula for summation of even powers and get
√ 2n 1 √ 2k
2n 1 1
∑ 2k (2 x) =
2
(2 x) √ + √
(1 − 2 x)2k+1 (1 + 2 x)2k+1
,
n
1 1 1 1
F(x) = √ ·q + √ ·q ,
2(1 − 2 x) 1−4 x√ 2(1 + 2 x) 1−4 x√
(1−2 x)2 (1+2 x)2
which implies
1 1
F(x) = p √ + p √ .
2 1−4 x 2 1+4 x
4n n 2n n 1
On the other hand for G(x) we would like to get the sum ∑ x . Since ∑ x =√
n 2n n n 1 − 4x
2n 1
we have ∑ (−x)n = √ hence
n n 1 + 4x
!
1 1 1
G(x) = p √ +p √
2 1−4 x 1+4 x
Solution. In order to have shorter formulas let us introduce r = p + k. If we assume that n is the free
variable then the required sum is equal to
2n + 1 r
f (n) = ∑ .
r 2r + 1 p
Take F(x) = ∑ x2n+1 f (n). This is somehow natural since the binomial coefficient contains the term
n
2n + 1. Now we have
2n + 1 r r 2n + 1 2n+1
F(x) = ∑ x 2n+1
∑ 2r + 1 p = ∑ p ∑ 2r + 1 x .
n r r n
Since
2n + 1 2n+1 x2r+1
1 1
∑ 2r + 1 x = 2 (1 − x)2r+2 + (1 + x)2r+2 ,
n
we get
r r
x2 x2
1 x r 1 x r
2 (1 − x)2 ∑ 2 (1 + x)2 ∑
F(x) = · + · ,
r p (1 − x)2 r p (1 + x)2
p p
x2 x2
1 x (1−x)2 1 x (1+x)2
F(x) = p+1 + p+1 ,
2 (1 − x)2 2 (1 + x)2
x2 x2
1 − (1−x)2 1− (1+x)2
5 Problems
1. Prove that for the sequence of Fibonacci numbers we have
F0 + F1 + · · · + Fn = Fn+2 + 1.
2. Given a positive integer n, let A denote the number of ways in which n can be partitioned as a
sum of odd integers. Let B be the number of ways in which n can be partitioned as a sum of
different integers. Prove that A = B.
3. Find the number of permutations without fixed points of the set {1, 2, . . . , n}.
18 Olympiad Training Materials, www.imomath.com
n
4. Evaluate ∑(−1) . k
k 3k
5. Let n ∈ N and assume that
x + 2y = n has R1 solutions in N20
2x + 3y = n − 1 has R2 solutions in N20
..
.
nx + (n + 1)y = 1 has Rn solutions in N20
(n + 1)x + (n + 2)y = 0 has Rn+1 solutions in N20
Prove that ∑ Rk = n + 1.
k
for 1 6 k 6 n, σ0 = 1, and σk = 0 for k > n. Another class of symmetric polynomials are the
polynomials of the form
pk (x1 , . . . , xn ) = ∑ xi11 · · · · · xinn , where i1 , · · · , in ∈ N0 .
i1 +···+in =k
7. Assume that for some n ∈ N there are sequences of positive numbers a1 , a2 , . . . , an and b1 , b2 ,
. . . , bn such that the sums
a1 + a2, a1 + a3 , . . . , an−1 + an
and
b1 + b2, b1 + b3 , . . . , bn−1 + bn
the same up to permutation. Prove that n is a power of two.
8. (Leo Moser, Joe Lambek, 1959.) Prove that there is a unique way to partition the set of natural
numbers in two sets A and B such that: For very non-negative integer n (including 0) the
number of ways in which n can be written as a1 + a2 , a1 , a2 ∈ A, a1 6= a2 is at least 1 and is
equal to the number of ways in which it can be represented as b1 + b2, b1 , b2 ∈ B, b1 6= b2 .
9. Given several (at least two, but finitely many) arithmetic progressions, if each natural number
belongs to exactly one of them, prove there are two progressions whose common differences
are equal.
10. (This problem was posed in the journal American Mathematical Monthly) Prove that in the
contemporary calendar the 13th in a month is most likely to be Friday.
Remark: The contemporary calendar has a period of 400 years. Every fourth year has 366
days except those divisible by 100 and not by 400.
Milan Novaković: Generating Functions 19
6 Solultions
1. According to the Theorem 7 the generating function of the sum of first n terms of the se-
quence (i.e. the left-hand side) is equal to F/(1 − x), where F = x/(1 − x − x2) (such F is the
generatring function of the Fibonacci sequence). On the right-hand side we have
F −x 1
− ,
x 1−x
and after some obvious calculation we arrive to the required identity.
2. We will first prove that the generating function of the number of odd partitions is equal to
1
(1 + x + x2 + · · ·) · (1 + x3 + x6 + · · · ) · (1 + x5 + x10 + · · · ) · · · = ∏ 2k+1
.
k>1 1 − x
Indeed, to each partition in which i occurs ai times corresponds exactly one term with coeffi-
cient 1 in the product. That term is equal to x1·a1 +3·a3 +5·a5 +··· .
The generating function to the number of partitions in different summands is equal to
(1 + x) · (1 + x2) · (1 + x3) · · · = ∏ (1 + xk ),
k>1
because from each factor we may or may not take a power of x, which exactly correpsonds to
taking or not taking the corresponding summand of a partition. By some elementary transfor-
mations we get
1 − x2k (1 − x2)(1 − x4 ) · · · 1
∏ (1 + xk ) = ∏ k
= =∏
(1 − x)(1 − x )(1 − x )(1 − x ) · · · k>1 1 − x2k+1
2 3 4
k>1 k>1 1 − x
3. This example illustrates the usefullness of the exponential generating functions. This problem
is known as derangement problem or ”le Problème des Rencontres” posed by Pierre R. de
Montmort (1678-1719).
Assume that the required number is Dn and let D(x) esr ↔ Dn . The number of permutations
having exactly k given fixed points is equal to D n−k , hence the total number of permutations
with exactly k fixed points is equal to nk Dn−k , because we can choose k fixed points in nk
The required sum is equal to f (−1). The question now is how to make binomial formula to
skip all terms except those of order 3k. We will use the following identy for the sum of roots
of unity in the complex plane
r, r|n
∑ ε =
n
0, otherwise.
ε r =1
Let C(x) = (1 + x)n and let 1, ε , and ε 2 be the cube roots of 1. Then we have
The functions Σ(t) and P(t) satisfy the following condition Σ(t)p(−t) = 1. If we calculate the
coefficient of this product near t n , n > 1 we get the relation
n
∑ (−1)r σr pn−r = 0.
r=0
Notice that
n n
1
log P(t) = ∑ log and log Σ(t) = ∑ log(1 + txi).
i=1 1 − txi i=1
d P′ (t)
S(t) = log P(t) =
dt P(t)
and
d Σ′ (t)
S(−t) = − log Σ(t) = − .
dt Σ(t)
From the first formula we get S(t)P(t) = P′ (t), and from the second S(−t)Σ(t) = −Σ′ (t).
Comparing the coefficients near t n+1 we get
n n
npn = ∑ sr pn−r and nσn = ∑ (−1)r−1sr σn−r .
r=1 r=1
7. Let F and G be polynomials generated by the given sequence: F(x) = xa1 + xa2 + · · · + xan and
G(x) = xb1 + xb2 + · · · + xbn . Then
! !
n n
F 2 (x) − G2 (x) = ∑ x2ai + 2 ∑ xai +a j − ∑ x2bi + 2 ∑ xbi +b j
i=1 16i6 j6n i=1 16i6 j6n
2 2
= F(x ) − G(x ).
Since F(1) = G(1) = n, we have that 1 is zero of the order k, (k > 1) of the polynomial
F(x) − G(x). Then we have F(x) − G(x) = (x − 1)k H(x), hence
A(x) = ∑ xa , B(x) = ∑ xb .
a∈A b∈B
The condition that A and B partition the whole N without intersection is equivalent to
1
A(x) + B(x) = .
1−x
22 Olympiad Training Materials, www.imomath.com
We further have
1
(A(x) − B(x)) = A(x2 ) − B(x2)
1−x
or equivalently
(A(x) − B(x)) = (1 − x)(A(x2) − B(x2 )).
n−1
Changing x by x2 , x4 , . . . , x2 we get
n−1
A(x) − B(x) = (A(x2 ) − B(x2 )) ∏ (1 − x2 ),
n n i
i=0
implying
∞
A(x) − B(x) = ∏(1 − x2 ).
i
i=0
The last product is series whose coefficients are ±1 hence A and B are uniquely determined
(since their coefficients are 1). It is not difficult to notice that positive coefficients (i.e. coef-
ficients originating from A) are precisely those corresponding to the terms xn for which n can
be represented as a sum of even numbers of 2s. This means that the binary partition of n has
an even number of 1s. The other numbers form B.
Remark: The sequence representing the parity of the number of ones in the binary representa-
tion of n is called Morse sequence.
9. This problem is posed by Erdösz (in slightly different form), and was solved by Mirsky and
Newman after many years. This is their original proof:
Assume that k arithmetic progressionss {ai + nbi } (i = 1, 2, . . . , k) cover the entire set of pos-
∞
za
itive integers. Then = ∑
1 − zb i=0
za+ib , hence
denoted by i has appeared as the first in a month. Since Jan1, 2001 was Monday, a1 is the
number of Mondays, a2 - the number of Tuesdays, . . . , a0 - the number of Sundays. We will
consider now fA modulus t 7 − 1. The polynoimal fA (t) − gA(t) is divisible by t 7 − 1. Since we
only want to find which of the numbers a0 , a1 , . . . , a6 is the biggest, it is enough to consider
the polynomial modulus q(t) = 1 + t + t 2 + · · · + t 6 which is a factor of t 7 − 1. Let f1 (t) be the
polynomial that represents the first days of months in 2001. Since the first day of January is
Monday, Thursday– the first day of February, ..., Saturday the first day of December, we get
f1 (t) = t + t 4 + t 4 + 1 + t 2 + t 5 + 1 + t 3 + t 6 + t + t 4 + t 6 =
= 2 + 2t + t 2 + t 3 + 3t 4 + t 5 + 2t 6 ≡ 1 + t + 2t 4 + t 6 (mod q(t)).
Since the common year has 365 ≡ 1 (mod 7) days, polynomials f2 (t) and f3 (t) corresponding
to 2002. and 2003., satisfy
f2 (t) ≡ t f1 (t) ≡ tg1 (t)
and
f3 (t) ≡ t f2 (t) ≡ t 2 g1 (t),
where the congruences are modulus q(t). Using plain counting we easily verify that f4 (t) for
leap 2004 is
f4 (t) = 2 + 2t + t 2 + 2t 3 + 3t 4 + t 5 + t 6 ≡ 1 + t + t 3 + 2t 4 = g4 (t).
We will introduce a new polynomial that will count the first days for the period 2001 − 2004
h1 (t) = g1 (t)(1 + t + t 2 ) + g4 (t). Also, after each common year the days are shifted by one
place, and after each leap year by 2 places, hence after the period of 4 years all days are shifted
by 5 places. In such a way we get a polynomial that counts the numbers of first days of months
between 2001 and 2100. It is:
Here we had to write the last for years in the form g1 (t)(1 + t + t 2 + t 3 ) because 2100 is not
leap, and we can’t replace it by h1 (t). The period of 100 years shifts the calendar for 100 days
(common years) and additional 24 days (leap) which is congruent to 5 modulus 7. Now we
get
gA (t) ≡ p1 (t)(1 + t 5 + t 10) + t 15h1 (t)(1 + t 5 + · · · + t 120).
Similarly as before the last 100 are counted by last summands because 2400 is leap. Now we
will use that t 5a +t 5(a+1) + · · ·+t 5(a+6) ≡ 0. Thus 1 +t 5 + · · ·+t 23·5 ≡ 1 +t 5 +t 2·5 ≡ 1 +t 3 +t 5
and 1 + t 5 + · · · + t 25·5 ≡ 1 + t 5 + t 2·5 + t 4·5 ≡ 1 + t + t 3 + t 5 . We further have that
This means that the most probable day for the first in a month is Sunday (because a0 is the
biggest).
We can precisely determine the probability. If we use the fact that there are 4800 months in
a period of 400, we can easily get the Sunday is the first exactly 688 times, Monday – 684,
Tuesday – 687, Wednesday – 685, Thursday – 685, Friday – 687, and Saturday – 684.
References
[1] H.S. Wilf, 1994, generatingfunctionology , University of Pennsylvania, Philadelphia, USA
Electronic version: http://www.math.upenn.edu/∼wilf/gfologyLinked.pdf
[2] D. Stevanovi, M. Miloxevi, V. Balti, 2004, Diskretna matematika,
osnove kombinatorike i teorije grafova - zbirka rexenih zadataka, Druxtvo
matematiqara Srbije, Beograd (u pripremi)
Electronic version: http://www.pmf.ni.ac.yu/people/dragance/zbirka.pdf
[3] V. Drenski, ,,Poraжdawi funkcii“ u Podgotovka za olimpiadi pod redakcita
na Sava Grozdev, 2002, Sъz na matematicite v Bъlgari, Sofi
[4] Electronic materials: http://www.math.uvic.ca/faculty/gmacgill/guide/GenFuncs.pdf
[5] Lerma, A.M., 2003., Generating functions ,
http://www.math.northwestern.edu/ mlerma/problem solving/results/gen func.pdf
[6] Electronic materials: http://www.cs.brandeis.edu/∼ira/47a/gf.pdf
[7] P. Mladenovi, Kombinatorika, Druxtvo matematiqara Srbije, Beograd,
2001