Klappenecker A., Lee H. Discrete Structures 2025
Klappenecker A., Lee H. Discrete Structures 2025
Andreas Klappenecker
Hyunyoung Lee
Discrete
Structures
Undergraduate Texts in Mathematics
Undergraduate Texts in Mathematics
Series Editors
Pamela Gorkin
Mathematics, Bucknell University, Lewisburg, PA, USA
Jessica Sidman
Department of Mathematics and Statistics, Amherst College, Amherst, MA, USA
Advisory Editors
Discrete Structures
Andreas Klappenecker Hyunyoung Lee
Dept. of Computer Science & Engineering Dept. of Computer Science & Engineering
Texas A&M University Texas A&M University
College Station, TX, USA College Station, TX, USA
© The Editor(s) (if applicable) and The Author(s), under exclusive license to Springer Nature Switzerland
AG 2025
This work is subject to copyright. All rights are solely and exclusively licensed by the Publisher, whether
the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illus-
trations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission
or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar
methodology now known or hereafter developed.
The use of general descriptive names, registered names, trademarks, service marks, etc. in this publication
does not imply, even in the absence of a specific statement, that such names are exempt from the relevant
protective laws and regulations and therefore free for general use.
The publisher, the authors and the editors are safe to assume that the advice and information in this book
are believed to be true and accurate at the date of publication. Neither the publisher nor the authors or the
editors give a warranty, expressed or implied, with respect to the material contained herein or for any errors
or omissions that may have been made. The publisher remains neutral with regard to jurisdictional claims
in published maps and institutional affiliations.
This Springer imprint is published by the registered company Springer Nature Switzerland AG
The registered company address is: Gewerbestrasse 11, 6330 Cham, Switzerland
v
vi Preface
The main chapter dependencies are shown in this graph. A solid arrow Chapter
A Ñ Chapter B indicates that Chapter A should be studied before Chapter B.
A dotted arrow means that it would be our recommendation to read the chap-
ters in this order. We recommend to study Chapters 1–8 from the first part of
the book before the later chapters.
Contents ix
Notation xiii
I Discrete Structures 1
1 Introduction 3
1.1 Knight’s Tour 3
1.2 Notes 10
2 Mathematical Arguments 11
2.1 Statements 11
2.2 Logical Operations 13
2.3 Logical Equivalence 20
2.4 Logical Consequence 25
2.5 Formal Arguments 28
2.6 Predicates and Quantifiers 34
2.7 Negations 39
2.8 Proofs 42
2.9 Notes 50
3 Sets 51
3.1 Background and Motivation 51
3.2 Fundamental Concepts 52
3.3 Intersections and Unions 60
3.4 Differences and Symmetric Differences 63
3.5 Cartesian Products 67
3.6 Relations 69
3.7 Functions 72
3.8 Numbers 78
3.9 Cardinality 82
3.10 Notes 88
ix
x CONTENTS
4 Proofs by Induction 89
4.1 Perfect Squares 89
4.2 Bernoulli’s Inequality 93
4.3 Fibonacci Numbers 95
4.4 Geometric Series 97
4.5 Binomial Theorem 99
4.6 Strong Induction 101
∗4.7 Well-founded Induction 106
∗4.8 Recursion 117
∗4.9 Recursively Defined Sets 122
4.10 Notes 131
9 Sums 209
9.1 A Motivating Example 209
9.2 Difference Calculus 211
9.3 Falling Factorial Powers 217
9.4 Stirling Numbers 221
9.5 The Fundamental Theorem of Summation 224
∗9.6 Analysis of Programs 231
9.7 Notes 235
11 Counting 267
11.1 Fundamental Counting Principles 267
11.2 Permutations and Combinations 273
11.3 Combinatorial Proofs 276
11.4 Selections with Repetitions 284
11.5 Set Partitions 288
11.6 The Inclusion-Exclusion Principle 290
11.7 Pigeonhole Principle 296
11.8 Notes 299
14 Graphs 349
14.1 Undirected Graphs 349
14.2 Common Graphs 354
14.3 Connected Graphs 358
14.4 Trees 362
14.5 Planar Graphs 364
14.6 Graph Coloring 367
14.7 Hamiltonian Cycles and Paths 374
Bibliography 413
Index 419
Notation
Logic
Sets
xiii
xiv Notation
Functions
n
ÿ n
ÿ
f pnq summation, f pnq “ f p1q ` f p2q ` ¨ ¨ ¨ ` f pnq
k“1 k“1
Δ difference operator
Δ´1 summation operator
źn źn
f pnq product, f pnq “ f p1qf p2q ¨ ¨ ¨ f pnq
k“1 k“1
Number Theory
Combinatorics
k! factorial, k! “ 1 ¨ 2 ¨ ¨ ¨ pk ´ 1q ¨ k
nk falling factorial power, nk “ npn ´ 1q ¨ ¨ ¨ pn ´ k ` 1q
k
n rising factorial power, nk “ npn ` 1q ¨ ¨ ¨ pn ` k ´ 1q
n
` ˘
binomial coefficient
`k n
˘
multinomial coefficient
kn1(,k2 ,...,km
k Stirling number of the second kind, also denoted as Spn, kq
Notation xv
Graph Theory
Probability Theory
Discrete Structures
1
Chapter 1
Introduction
Problems worthy
of attack
prove their worth
by hitting back.
— Piet Hein, Grooks
Many areas of mathematics have a long history. For instance, calculus has
been studied for hundreds of years. By contrast, courses on discrete structures
emerged more recently during the past 50 years. They were designed to provide
a mathematical support of computer science. Yet, bits and pieces of this subject
have a longer history. We will begin with a playful recreational problem that
fascinated Euler. The problem asks whether it is possible to move a knight
on a chessboard such that it will visit each square of the chessboard precisely
once. We will show that the question whether or not a solution exists depends
on the size of the chessboard.
Euler was prompted by this and other recreational problems to invent graph
theory. Even though graphs are not absolutely necessary to solve the knight’s
tour problem, they make the reasoning about the problem simpler. This mo-
tivational chapter will show you how to formalize the problem. We will also
illustrate how to argue about the existence or nonexistence of solutions to the
problem.
Figure 1.1: All possible eight knight’s moves starting from the square d5 are marked
with a cross
A sequence of knight moves that visits every square of the chessboard pre-
cisely once is called a knight’s tour. If the end square of the knight’s tour is
within a knight’s move of the beginning square, then the knight’s tour is called
closed. A famous ancient chess puzzle asks to find a closed knight’s tour on
the chessboard.
Let us first study the problem on smaller chessboards. A chessboard with 3
rows and 4 columns is the smallest size that allows one to find knight’s tours.
It is not difficult to find a knight’s tour for the 3 ˆ 4 rectangular chessboard,
see Fig. 1.2.
The knight’s tour given in Fig. 1.2 is not unique. In Exercise 1.1, you are
encouraged to find more knight’s tours on a 3 ˆ 4 chessboard. You might have
difficulties finding a closed knight’s tour for this size chessboard for the reason
explained in Exercise 1.2.
One can work out the knight problems on the boards alone, but a drawback
is that the board lacks the structure of the moves. A good approach is to
formulate the possible moves with the help of a graph, a useful datatype that
we will discuss in more detail later.
Before explaining the concept of a graph, let us recall the notion of a set.
A set is an unordered collection of distinct objects, called the elements of
the set. A finite set can be defined by listing its elements in curly braces. For
instance, the set A “ ta, b, c, du contains four elements, namely a, b, c and d.
1.1 Knight’s Tour 5
The order of the elements does not matter, so tb, c, a, du is another way of
specifying the same set. We write a P A to denote that a is an element of the
set A. A set B is called a subset of a set A if and only if every element of B
is an element of A. An n-element subset B of A is a subset of A that contains
precisely n elements. For instance, B “ ta, du is a 2-element subset of A.
A graph is a pair pV, Eq of sets such that the set E consists of 2-element
subsets of V . The elements of V are called vertices or nodes of the graph,
and the elements of E are called its edges. We represent a vertex by a point
in the plane and edges by line segments or curves connecting the points of the
two vertices representing the edge.
The knight graph of an n ˆ m chessboard consists of a set of nm vertices,
where each vertex represents one square of the chessboard. Two vertices are
connected by an edge if and only if the corresponding squares on the chessboard
are one knight’s move apart. Thus, the knight graph models the possible
movements of a knight on the chessboard.
Example 1.1. The knight graph pV, Eq of a 4 ˆ 4 chess board has a set V of
16 vertices modeling the squares of the chess board and a set E of 24 edges
modeling the knight moves. The set V of vertices is given by
V “ ta1, a2, a3, a4, b1, b2, b3, b4, c1, c2, c3, c4, d1, d2, d3, d4u,
The edge ta1,c2u formalizes, for instance, that the squares a1 and c2 can reach
each other through a knight’s move. As aforementioned, the vertices of a graph
are often illustrated by a dot and edges by a line segment or a curve. Figure 1.3
shows the knight graph pV, Eq of the 4 ˆ 4 chess board in this diagrammatic
form.
pv1 , v2 , . . . , vk , vk`1 q
Example 1.2. One walk on the knight graph of the 4 ˆ 4 chessboard is, for
instance, given by
Figure 1.3: A 4 ˆ 4 chessboard and the corresponding knight graph. The vertices
b2 and d3 are connected by an edge, since these squares on the chessboard are one
knight’s move apart
It describes a walk consisting of five knight moves. The first move starts at the
square a1, then moves to c2. From c2, the knight moves to b4, then d3, and
back to b4. In the final move, the knight reaches the square a2. A less verbose
description of this walk is given by pa1, c2, b4, d3, b4, a2q.
A path in a graph is a walk with pairwise distinct vertices. Thus, a path
is a walk
pv1 , v2 , . . . , vk , vk`1 q
that does not revisit vertices, so vi is not the same as vj when the indices i
and j are distinct.
A Hamiltonian path in a graph is a path that visits every vertex of the
graph exactly once. A knight’s tour corresponds to a Hamiltonian path in the
knight graph.
A cycle in a graph is a walk such that the vertices are pairwise distinct
except that the first and the last vertex are the same. A cycle of a graph is
called a Hamiltonian cycle if and only if it visits every vertex of the graph
exactly once. A closed knight’s tour corresponds to a Hamiltonian cycle in the
knight graph.
Proposition 1.3. There does not exist a closed knight’s tour on a 4 ˆ 4 chess-
board.
Proof. How can we go about showing that a closed knight’s tour does not exist?
Well, we can show that there is going to be a problem with any purported
knight’s tour, which will force us to conclude that no knight’s tour can exist.
This method of proof is called a proof by contradiction and will be studied in
more detail in the next chapter.
Seeking a contradiction, let us assume that a closed knight’s tour exists,
so there must exist a Hamiltonian cycle in the 4 ˆ 4 knight graph. Then each
vertex is adjacent to precisely two edges of the Hamiltonian cycle. The vertices
a1 and d4 are forced to use the dashed edges in the knight graph illustrated as
follows.
1.1 Knight’s Tour 7
Then the dashed cycle must be a subpath of the Hamiltonian cycle, which
is impossible as ta1, b3, c2, d4u cannot be connected to any other nodes on
the Hamiltonian path.
The previous proposition showed that a closed knight’s tour is impossible
on a 4 ˆ 4 chessboard. We will now take advantage of the obstacle to the
Hamiltonian cycle on the 4 ˆ 4 board to systematically construct a closed
knight’s tour on the original 8 ˆ 8 board.
Theorem 1.4. There exists a closed knight’s tour on an 8 ˆ 8 chessboard.
Proof. We will subdivide the 8 ˆ 8 board into four 4 ˆ 4 boards. On each 4 ˆ 4
board, a knight can take the following paths:
Notice that the four paths partition the 4 ˆ 4 board. The idea is to walk in one
quadrant according to one of these patterns and then connect it to another such
pattern in the same or in another quadrant. Specifically, we get the following
four paths
8 1 Introduction
and
These four paths partition the entire board. Putting it all together, we get
the following closed knight’s tour:
This solution is not unique. In fact, there are 26,534,728,821,063 other closed
knight tour solutions as well.
Despite the fact that there are so many knight’s tours on an 8 ˆ 8 board,
most people find it challenging to discover one. In general, it is a good idea to
solve smaller versions of the problem as we did at the beginning of this section,
to gain insight into the problem.
If you lack the patience to solve it by hand, then you might want to solve
some small cases with the help of a computer. A general strategy to solve such
combinatorial problems is given by backtracking. The idea is to start from a
square on the chessboard and incrementally build up a knight’s tour from this
square. At each step, we make a knight’s move to another square that has
not been visited yet. We keep going on in this fashion until it is impossible to
move to another square that has not been visited yet. If we found a tour, then
we can print it; otherwise, we backtrack to a previous square that offers still
alternative moves and try the next move.
1.1 Knight’s Tour 9
This partial tour cannot be completed, as there are no further knight moves
possible from position 10. One has to backtrack five steps to find a square that
offers an alternative move. Instead of moving from position 5 at the square c1
to the square d3, as we did previously, we move instead to the square at a2.
The resulting partial tour is shown on the far right in the next figure.
Starting from the partial tour shown on the far right, one notices after a
few steps that this partial tour cannot be completed either. Since there are
no other knight’s moves available from the square at position 5, we have to
backtrack further to the square at position 4 and try an alternative knight’s
move from there.
It is an instructive exercise to write a recursive program that implements a
backtrack search for a knight’s tour, see Exercise 1.6.
EXERCISES
1.1. Find at least two more knight’s tours on a 3 ˆ 4 chessboard. These tours
should be essentially different (that is, don’t just differ in direction).
1.2. Show that there does not exist a closed knight’s tour on a 3ˆ4 chessboard.
Hint: Mark the columns a and d with crosses and the columns b and c with
circles. Where can the knight move if it sits on a field with a cross (respectively,
circle)? Now consider a putative closed knight’s tour.
10 1 Introduction
1.3. (a) Give a simple argument showing that there cannot exist a knight’s
tour on a 3 ˆ 3 chessboard. (b) Give the knight’s graph of the 3 ˆ 3 chessboard
and explain what additional insights are provided by this graph representation.
1.4. Suppose that you are given an m ˆ n chessboard such that the product
nm is an even integer. Show that the knight’s tour problem cannot be solved
when the first and the last square of the tour have the same color.
1.5. Suppose that you are given an m ˆ n chessboard such that nm is an odd
integer. Show that there cannot exist a closed knight tour.
1.6. Write a recursive program that searches for a (open) knight’s tour by
backtracking for an n ˆ m chessboard. The input should be a starting square
on the chessboard.
1.2 Notes
Finding a knight’s tour is a recreational chess problem. It was studied by Eu-
ler, who gave an open knight’s tour [26]. It is a special case of the Hamiltonian
path problem on the knight’s graph. The knight’s tour problem can be solved
in linear time. By contrast, deciding whether a general graph has a Hamilto-
nian path is NP-complete. NP-complete problems have solutions that are easy
to verify, but there are no known efficient (polynomial time) algorithms that
can solve NP-complete problems. Thus, it seems unlikely that one can find a
Hamiltonian path in polynomial time.
Chapter 2
Mathematical Arguments
My dear friend, I’d advise, in sum,
First, the Collegium Logicum.
There your mind will be trained,
As if in Spanish boots, constrained,
So that painfully, as it ought,
It creeps along the way of thought, . . .
— Johann Wolfgang von Goethe, Faust I
2.1 Statements
In mathematics, a statement is a sentence that is either true or false. State-
ments are also called assertions or propositions. For example, the sentence
There exists a closed knight’s tour on an 8 ˆ 8 chessboard
is a true statement. We showed in Chap. 1, Proposition 1.3, that the sentence
There exists a closed knight’s tour on a 4 ˆ 4 chessboard
is a false statement.
Sometimes it is difficult to decide whether a mathematical statement is true
or false. The innocuous assertion
EXERCISES
2.1. Which of the following sentences are mathematical statements? Justify
your answers.
(a) The number π is the smallest irrational real number.
(b) The number π is an irrational number.
(c) The quadratic equation x2 ´ 4x ` 2 “ 0 does not have a solution in the
integers.
(d) The inequality 123 ´ 100 ą 23 holds.
(e) The positive integer x is a prime number.
2.2. Which of the following sentences are statements? Justify your answers.
(a) Is 17 a prime?
(b) 12x ` 4 “ 10.
(c) Does there exist a knight’s tour on a 31 ˆ 31 chessboard?
(d) The positive integer x is the sum of two squares.
(e) Every even integer greater than 2 can be expressed as the sum of two
primes.
2.3. For each of the following statements, determine whether the statement is
true or false. Explain why.
(a) The real number 0.111 ¨ ¨ ¨ is equal to 1{9.
(b) The real number 0.1212121212 ¨ ¨ ¨ is not a rational number.
(c) The greatest common divisor of 1111 and 11111111 is equal to 1.
(d) p´1qp´1q “ 1.
(e) The set of positive integers t1, 2, 3, . . .u is infinite.
2.4. Research the following statement: There exist infinitely many pairs of
prime numbers that differ by 2. It is evidently a statement, but is it true?
2.2 Logical Operations 13
x ď 0 or xě0
A B A_B
F F F
F T T
T F T
T T T
Note that “A or B” is false only when both the statement A and the statement
B are false.
You might be wondering why we are concerned with statements that are
false. Well, one proof technique first negates the statement and then tries to
find a contradiction. So false statements occur quite often within mathemati-
cal arguments, even though we are ultimately concerned with establishing the
truth of mathematical assertions that are stated in theorems, propositions, and
lemmas.
is given by
A B A^B
F F F
F T F
T F F
T T T
For example, one might want to establish that 2 ă e ă 3, which amounts to
prove the conjunction of the inequalities
2ăe and e ă 3.
A B AÑB
F F T
F T T
T F F
T T T
It might seem strange that one can conclude anything from a false statement.
However, even in everyday English we sometimes make a point by drawing an
even more absurd conclusion from an absurd statement, such as If this mafioso
is innocent, then I will eat my hat. Exercise 2.14 explains why mathematicians
did not really have the option to define the implication in a different way.
Another important point is that an implication is not based on cause and
effect. For example, if A is the statement “1+1=2” and B is the statement
2.2 Logical Operations 15
A B AØB
F F T
F T F
T F F
T T T
We see that A Ø B is true if and only if A and B have the same truth value.
In the literature, an equivalence is sometimes also called a bi-implication.
B3. If A and B are Boolean formulas, then pA _ Bq, pA ^ Bq, pA Ñ Bq, and
pA Ø Bq are Boolean formulas.
Let us illustrate how to derive a truth table for the Boolean formula ppA^
Bq Ñ pA _ Bqq of the aforementioned example. The formula contains two
Boolean variables, so there are a total for four assignments of truth values to
these two Boolean variables A and B. The value of A determines A. Knowing
the truth values of A and B, we can deduce the truth values of pA ^ Bq
and pA _ Bq. After determining the truth values of pA ^ Bq and pA _ Bq,
we can deduce the truth value of the entire formula
(2.1). We first find the truth values of the subexpression A, then of A ^ B,
and finally of the statement A Ø pA ^ Bq,
A B A A ^ B A Ø pA ^ Bq
F F T F T
F T T T F
T F F F F
T T F F F
The statement A Ø pA ^ Bq is true if and only if A and B are both false. In
other words, we can conclude that A and B are both knaves.
You should recognize that the solution was quite simple after we succeeded
with the formalization of the problem. We used truth tables in our argument,
since this illustrates the operations once more. You are encouraged to use truth
tables until you become fluent with the meaning of the logical operations. We
will learn more elegant proof techniques in the remainder of this chapter.
EXERCISES
2.6. Let A denote the statement “the supermarket is open,” B the statement
“I go shopping,” and C the statement “the pharmacy is open.” Translate the
following statements into English phrases.
(a) A ^ C,
(b) A _ C,
(c) A Ñ B,
(d) B Ø pA ^ Cq.
2.7. Let A denote the statement “Albert is happy,” C the statement “Albert
cooks pasta,” and E the statement “Emmy is happy.” Translate the following
statements into English phrases.
(a) pC ^ Eq,
(b) pC Ñ pA ^ Eqq,
(c) pE Ø Aq,
(d) ppA ^ Eq _ Cq.
2.8. Let C denote the statement “it is cloudy,” R the statement “it is rainy,”
and S the statement “it is sunny.” Formalize each of the following sentences:
(a) If it is cloudy, then it is not sunny.
(b) It is cloudy and rainy.
(c) It is rainy or it is cloudy and not sunny.
(d) It is sunny if and only if it is not cloudy.
2.9. Argue that each of the following expressions is a Boolean formula. Start
with the Boolean variables occurring in the expression. Then show how the
properties B1, B2, and B3 are used to construct the entire given Boolean
formula.
(a) ppA Ñ Bq Ñ Aq
18 2 Mathematical Arguments
(b) ppA _ Bq ^ Aq
(c) ppA ^ Bq _ pA ^ Bqq
(d) ppA ^ Bq Ø pA ^ Bqq
2.10. Explain why each of the following expressions is not a Boolean formula
(a) ¨ ¨ ¨ pppA Ñ Aq Ñ Aq Ñ Aq Ñ ¨ ¨ ¨
(b) pppA Ñ Bq _ Cq
2.11. (a) How many rows are in the truth table of a Boolean formula f with
n variables?
(b) How can you systematically generate all possible truth assignments for the
n Boolean variables of F in lexicographic order?
2.12. Find the truth tables of the Boolean formulas
(a) ppA Ñ Bq Ñ Aq,
(b) pA Ñ pB Ñ Aqq,
(c) ppA Ñ Bq Ñ Bq,
(d) pA Ñ pB Ñ Bqq.
2.13. Find the truth table of the Boolean formula
2.14. In this exercise, you will demonstrate that there is really just one sensible
choice for the implication operation. If the hypothesis A is true and the con-
clusion B is true, then the implication A Ñ B should be true. If the hypothesis
A is true and the conclusion B is false, then A Ñ B should be false. However,
a d
we have four choices Ñ, . . . , Ñ for the implication when the hypothesis is false.
a b c d
A B AÑB AÑB AÑB AÑB
F F F T F T
F T F F T T
T F F F F F
T T T T T T
d
Give a compelling reason why Ñ is the only sensible choice for the implication.
[Hint: Express the equivalence Ø in terms of the newly defined implication.]
2.15. We have introduced five logical operators, namely the unary negation
operation , and the four binary operations conjunction ^, disjunction _,
implication Ñ, and equivalence Ø. There exist a total of 24 “ 16 binary
logical operators, see Table 2.1. Show that all 16 binary logical operations can
be expressed in terms of the five logical operations that we have introduced so
far by completing the “equivalent formulation” column in terms of expressions
using the operations t, ^, _, Ñ, Øu.
2.16. Rewrite the following expressions using only operators from the given
set S.
2.2 Logical Operations 19
Therefore, we can conclude that the valuation v must assign to the Boolean
formula A Ø pB ^ Cq the truth value
Proof. For a valuation v, we get the truth value vA Ñ B “ vA Ñ vB “ F
if and only if vA “ T and vB “ F . On the other hand, a valuation v
satisfies vA “ T and vB “ F if and only if vA _ B “ F . Therefore,
vA Ñ B “ vA _ B for all valuations v.
Since the result is used so often, we will give another proof that illustrates
a different style of argument. The proof rests on the fact that two Boolean
formulas A and B are logically equivalent if and only if A Ø B is a tautology.
Indeed, we have equality vA “ vB for all valuations v if and only if
vA Ø B “ T
Proof. It suffices to show that the truth tables of both expressions are the
same. This is indeed the case as the following table shows:
A B AÑB A B B Ñ A
F F T T T T
F T T T F T
T F F F T F
T T T F F T
If 2 ` 2 “ 5, then 2 is even
is a true statement, since the hypothesis is false (and the conclusion is true).
The converse
If 2 is even, then 2 ` 2 “ 5
is a false statement, since the hypothesis is true, but the conclusion is false.
Simply put, the implication F Ñ T is true, but its converse T Ñ F is false.
Thus, A Ñ B ı B Ñ A.
The Boolean operations have a very rich structure when we consider the
Boolean formulas up to logical equivalence. We begin by recording some im-
portant properties of the conjunction operation.
Proof. One can use truth tables to prove these laws, see Exercise 2.28.
Proof. One can use truth tables to verify these laws, see Exercise 2.29.
The similarities between the conjunction and disjunction operations are not
accidental. The next proposition shows that the negation of a conjunction can
be expressed in terms of a disjunction with negated arguments.
Proof. We will first show that the negation of the conjunction A and B is logi-
cally equivalent to the disjunction of the negated statements. Indeed, consider
the truth table
A B A^B pA ^ Bq A B A _ B
F F F T T T T
F T F T T F T
T F F T F T T
T T T F F F F
Since the truth values of pA^Bq and A_B are the same for all arguments,
this proves our claim (a).
By substituting the negated statements for A and B, we can infer from
pA ^ Bq ” A _ B the logical equivalence
A _ B ” pA ^ Bq.
Proof. (a) For a valuation v, we get the truth value vA ^ pB _ Cq “ T if
and only if vA “ T and vB _ C “ T if and only if vA “ T and either
vB “ T or vC “ T . In other words, we have vA ^ pB _ Cq “ T if and
only if vA “ T and vB “ T holds or vA “ T and vC “ T holds.
The latter statement is equivalent to vA^B “ T or vA^C “ T , which
is equivalent to vpA ^ Bq _ pA ^ Cq “ T . Therefore, for any valuation v,
we have the equality
(c) We can show the absorption law for conjunction using a series of known
logical equivalences. Indeed,
(d) We encourage the reader to prove the last claim in several different ways
to apply the proof techniques that we have learned, see Exercise 2.32.
EXERCISES
2.23. Let vA “ F , vB “ T , and vC “ T . Which of the following Boolean
formulas evaluate to true under the valuation v?
(a) pA Ñ pB ^ Cqq,
(b) ppA ^ Bq Ø Cq,
(c) A Ñ C,
(d) ppA ^ Bq _ Cq.
2.24. Use a truth table to prove that the implication A Ñ B and its converse
B Ñ A are not logically equivalent.
2.26. Show that pA ^ pA Ñ Bqq Ñ B is a tautology. This is the basis for the
modus ponens inference rule: If A and A Ñ B are true, then we can conclude
that B must be true.
2.27. Show that there exists a Boolean expression that uses only the operators
of the form _ and Ø that is logically equivalent to A ^ B.
2.28. Prove the claims of Proposition 2.5 using truth tables, that is, show
that the conjunction operation is an associative and commutative operation
satisfying the idempotence, identity, and domination laws.
2.29. Prove the claims of Proposition 2.6 using truth tables, that is, show
that the disjunction operation is an associative and commutative operation
satisfying the idempotence, identity, and domination laws.
2.30. Show that the associative laws hold for the conjunction and the disjunc-
tion operations
(a) A ^ pB ^ Cq ” pA ^ Bq ^ C,
(b) A _ pB _ Cq ” pA _ Bq _ C.
Do not use truth tables. Instead, show that for any valuation, the left-hand
side yields the same truth value as the right-hand side of the putative logical
equivalence.
2.31. Show that ppA _ Bq ^ pA _ Cqq Ñ pB _ Cq is a tautology. This is the
basis of the resolution inference rule: If the premises A _ B and A _ C are
true, then B _ C must be true.
2.32. Prove the absorption law from Proposition 2.8 (d) using
(a) a truth table
(b) logical equivalences that exploit de Morgan’s law, double negation, and the
absorption law from Proposition 2.8 (c).
(c) known logical equivalences (such as distributive, identity, and domination
laws), but without the use of de Morgan’s law.
One of the most pressing questions one might have about a mathematical
argument is whether the steps of the argument are valid. The logical conse-
quence paves the way to answer this question for arguments that are formulated
in the logic that we have developed so far. Given the premises or hypotheses
P1 , . . . , Pn , an argument seeks to assert a conclusion C. We call this argu-
ment valid if and only if tP1 , . . . , Pn u ( C. In other words, a valid argument
will ensure that the conclusion is true when its premises are true.
As an example, let us establish the validity of the logical argument known
as modus ponens. This is an argument form that has two premises and one
conclusion. The two premises of modus ponens are of the form A and A Ñ B.
If the premises are true, then modus ponens concludes that B must be true. As
a particular example, consider the premises A “ “it rains” and A Ñ B ““if it
rains, then the ground is wet.” Assuming that these premises are true, modus
ponens allows us to conclude that B “ “the ground is wet” must be true.
Example 2.9 (Validity of Modus Ponens). For all Boolean formulas A and B,
we have
tA, A Ñ Bu ( B,
so the conclusion B is the logical consequence of the premises A and A Ñ B.
Indeed, seeking a contradiction, let us assume that there exists a valuation v
such that the premises evaluate to true, but the conclusion evaluates to false.
In symbols, we can express this in the form vA “ T , vA Ñ B “ T , and
vB “ F . However, vA “ T and vB “ F implies that vA Ñ B “ F ,
contradicting our assumption. Therefore, all valuations assigning true to the
formulas in the set tA, A Ñ Bu, must assign true to the formula B, whence
tA, A Ñ Bu ( B as claimed.
In the exercises, you are encouraged to establish in a similar manner the
validity of other forms of logical arguments.
Notation. If the set S contains a single element B, then we write B ( A instead
of tBu ( A. Therefore, two Boolean formulas A and B are logically equivalent,
A ” B, if and only if A ( B and B ( A. If S is the empty set, then we write
( A instead of H ( A. In other words, ( A is another way of expressing that
A is a tautology.
The next theorem gives an alternative approach to prove logical conse-
quence. By combining all the premises and the conclusion into a single formula,
it suffices to establish that the resulting formula is a tautology.
Theorem 2.10. Suppose that tP1 , P2 , . . . , Pn u is a finite set of Boolean for-
mulas and C is a Boolean formula. Then
tP1 , P2 , . . . , Pn u ( C
if and only if pP1 ^ P2 ^ ¨ ¨ ¨ ^ Pn q Ñ C is a tautology.
Proof. By definition, tP1 , P2 , . . . , Pn u ( C if and only if there does not exist
a valuation v such that vP1 “ T, . . . , vPn “ T , and vC “ F . This is
2.4 Logical Consequence 27
Example 2.11. Given the premises A_B and A_C, we can conclude B _C.
This is the so-called resolution rule. The resolution rule is a valid argument,
since ppA _ Bq ^ pA _ Cqq Ñ pB _ Cq is a tautology by Exercise 2.31, so
tA _ B, A _ Cu ( B _ C holds by the previous theorem. Automated theorem
provers are often based on the resolution rule.
In principle, we can always use a truth table to establish that
tP1 , P2 , . . . , Pn u ( C
EXERCISES
2.33. Let A, B, and C be Boolean formulas. Show that the following three
arguments are valid.
(a) pA _ pB _ Cqq ( ppA _ Bq _ Cq (the associative rule)
(b) pA _ Aq ( A (the contraction rule)
(c) A ( B _ A (the expansion rule)
2.34. Let A, B, and C be Boolean formulas. We proved that the modus ponens
tA, A Ñ Bu ( B is a valid argument. Use a similar style of argument to show
that the following arguments are valid.
(a) tA Ñ B, Bu ( A (modus tollens)
(b) tA Ñ B, B Ñ Cu ( A Ñ C (hypothetical syllogism)
2.35. Show that the following arguments are valid:
(a) tA Ñ B, A Ñ Bu ( B,
(b) tA Ñ B, A Ñ Bu ( A.
2.36. Let A, B, and C be Boolean formulas. Show that the following arguments
are valid:
(a) pB Ñ Cq ( ppA ^ Bq Ñ Cq (strengthening the hypothesis),
(b) pA Ñ Bq ( pA Ñ pB _ Cqq (weakening the conclusion).
28 2 Mathematical Arguments
A ( pA ^ Bq.
A1. A Ñ pB Ñ Aq,
We call these axiom schemes rather than axioms, since each of these three rules
will lead to an infinite number of axioms by substituting Boolean formulas for
A, B, and C. One should note that A1, A2, and A3 are tautologies, see
Exercise 2.46. This means that we do not make a mistake by assuming them
as facts.
Inference Rule. We will be allowed to use the modus ponens rule of in-
ference in our arguments. If A and B are Boolean formulas, then the modus
ponens rule allows us to infer from A and A Ñ B, the Boolean formula B. We
will denote this inference rule in the form
A, A Ñ B
R1. .
B
In the previous section, we established that modus ponens is a valid argument,
so we will not make erroneous conclusions using this inference rule.
We will denote the formal system consisting of the Boolean formulas, the
axiom schemes A1, A2, A3, and the inference rule R1 by the letter H, hon-
oring the famous mathematician David Hilbert, who championed such formal
systems.
Formal Proofs. We will now use the axioms and inference rule to derive
formal proofs in the propositional calculus H. Let P “ tP1 , P2 , . . . , Pn u be a
set of premises and C a desired conclusion. We will write P $H C if and only
if we can deduce the conclusion C from the premises using the axioms and the
inference rule of the formal system H. In other words, we write P $H C if
and only if we can formulate a sequence of S1 , S2 , . . . , Sm of Boolean formulas
such that for all indices k, one of the following three choices applies
F1. Sk is an axiom from one of the axiom schemes A1, A2, or A3,
F2. Sk is a premise in P , or
F3. Sk “ B can be obtained using the modus ponens inference rule from two
prior steps Si “ A and Sj “ A Ñ B,
any axioms, but we are limited to the modus ponens inference rule in this
argument. The argument goes as follows:
p1q A premise
p2q A Ñ pA Ñ Aq by axiom A1
p3q pA Ñ Aq R1p1q, p2q
On the right-hand side, the comments give the justification for this step in the
proof.
The style of the argument is very different from the mathematical arguments
from the previous section. The argument does not involve truth values or
valuations, but merely manipulations at a syntactic level.
You might have noticed that we should be able to derive pA Ñ Aq without
the assumption A. After all, pA Ñ Aq is a tautology. We can indeed drop the
assumption A, as our second example shows.
Example 2.13. Let us formally prove that
$H A Ñ A
holds. Since there are no premises, it means that we should be able to derive
it from the axioms using the modus ponens rule. Indeed, we observe that
p1q A Ñ ppA Ñ Aq Ñ Aq by axiom A1
p2q pA Ñ ppA Ñ Aq Ñ Aqq Ñ ppA Ñ pA Ñ Aqq Ñ pA Ñ Aqq by axiom A2
p3q pA Ñ pA Ñ Aqq Ñ pA Ñ Aq by R1p1q, p2q
p4q A Ñ pA Ñ Aq by axiom A1
p5q A Ñ A by R1p4q, p3q
This proof might not be exactly intuitive. However, a formal proof has the
advantage that one can easily verify each single step—well, at least in principle.
The comments are crucial, as otherwise the verification becomes cumbersome.
In the third example, we will prove that implication is a transitive operation,
which means that if A Ñ B and B Ñ C, then A Ñ C. This is also known as
the rule of hypothetical syllogism. This fact is frequently used in other proofs.
Example 2.14. We will formally prove that
tA Ñ B, B Ñ Cu $H A Ñ C.
Indeed, we have
p1q AÑB premise
p2q BÑC premise
p3q pB Ñ Cq Ñ pA Ñ pB Ñ Cqq by axiom A1
p4q A Ñ pB Ñ Cq by R1p2q, p3q
p5q pA Ñ pB Ñ Cqq Ñ ppA Ñ Bq Ñ pA Ñ Cqq by axiom A2
p6q pA Ñ Bq Ñ pA Ñ Cq by R1p4q, p5q
p7q AÑC by R1p1q, p6q
2.5 Formal Arguments 31
When developing this proof, we did not proceed by assuming (1), (2), and
then successively deducing steps (3) through (7). Rather, we guessed that the
instance (5) of the axiom A2 might be a promising way to deduce A Ñ C.
Then we found how to obtain A Ñ pB Ñ Cq through the steps (2), (3), and
(4). Fleshing out the rest of the proof was then straightforward.
One can in principle continue in this fashion and prove many basic facts.
However, the style of argument is a bit too cumbersome, as the expressions can
become very long. Thanks to the influential logician Jacques Herbrand, there
is a more convenient way available, known as the deduction theorem.
Theorem 2.15 (Deduction Theorem). Let A and B be Boolean formulas, and
P a set of Boolean formulas. Then
The interested reader can find a proof of the deduction theorem for instance
in Goldrei [29, pages 97–98] or other introductory texts on symbolic logic.
The next example illustrates how to use this theorem.
Example 2.16. We will now give a formal proof that
tA Ñ B, A Ñ pB Ñ Cqu $H A Ñ C
tA Ñ B, A Ñ pB Ñ Cq, Au $H C
p1q A premise
p2q A Ñ B premise
p3q B by R1p1q, p2q
p4q A Ñ pB Ñ Cq premise
p5q B Ñ C by R1p1q, p4q
p6q C by R1p3q, p5q
Since we were able to move A into the set of premises, we were able to use the
modus ponens more effectively.
In the exercises, you will show that the axioms A1–A3 are tautologies.
We have shown in the previous section that the modus ponens rule is a valid
argument. One might worry that the composition of the formal proof might
somehow lead to an invalid argument. The next theorem puts these worries to
rest.
Theorem 2.17 (Soundness Theorem). Let P be a set of Boolean formulas
and C a Boolean formula. If P $H C, then P ( C. In other words, if we
can find a formal proof in the formal system H that deduces C from the set of
premises P , then this constitutes a valid argument.
32 2 Mathematical Arguments
Proof. Suppose that the conclusion C can be deduced from the set of premises
P in the formal system H; thus, we suppose that
P $H C
S1 , S2 , . . . , S m
Other Argument Forms. There are some other argument forms besides
modus ponens that are commonly used. Since we can use negation and im-
plication to define all other logical operators, see Exercises 2.43 and 2.45, we
will express the subsequent argument forms using a broader selection of logical
operators.
2.5 Formal Arguments 33
One can easily verify the validity of inference rules such as modus tollens
and the like. By the completeness theorem, we know that there must exist
some formal proof in H. The deduction theorem allows us to give a short
formal proof of the modus tollens.
tA Ñ B, Bu $H A.
Proof. We have
as claimed.
EXERCISES
2.43. Show that
(a) A _ B ” A Ñ B
(b) A ^ B ” pA Ñ Bq
(c) A Ø B ” ppA Ñ Bq Ñ pB Ñ Aqq
Thus, disjunction, conjunction, and equivalence can be expressed in terms of
implication and negation.
2.44. Show that a Boolean function f pX1 , X2 , . . . , Xn q in n Boolean vari-
ables can be expressed in canonical disjunctive normal form. This means
that f pX1 , X2 , . . . , Xn q is logically equivalent to a disjunction of minterms. A
minterm is a conjunction of n literals Y1 ^ Y2 ^ ¨ ¨ ¨ ^ Yn , where Yk P tXk , Xk u
for all integers k in the range 1 ď k ď n. [Hint: Inspect the truth table of f .]
2.45. Show that t, Ñu is a functionally complete set of operators. This
means that for each Boolean formula f there exists a logically equivalent for-
mula f 1 that contains just negation and implication operators. [Hint: Use the
fact that a Boolean formula can be written in disjunctive normal form.]
2.46. Prove that
(a) A Ñ pB Ñ Aq,
(b) pA Ñ pB Ñ Cqq Ñ ppA Ñ Bq Ñ pA Ñ Cqq,
(c) pB Ñ Aq Ñ pA Ñ Bq,
are tautologies.
2.47. Show that tA Ñ pB Ñ Cq, Bu $H A Ñ C.
2.48. Show that pA Ñ pB Ñ Cqq $H pB Ñ pA Ñ Cqq holds using the
deduction theorem once.
2.49. Reprove $H pA Ñ pA Ñ Bqq without using hypothetical syllogism in
your argument.
2.50. Show that $H ppA Ñ Aq Ñ pA Ñ Bqq. You can use the previous
exercise.
2.51. Reprove tpA Ñ Bq, pA Ñ pB Ñ Cqqu $H pA Ñ Cq without using the
deduction theorem.
2.52. Show that
A $H A.
n is a prime number.
Then P p2q expresses the statement “2 is a prime number” and P p4q expresses
the statement “4 is a prime number.” Thus, one obtains a statement that can
be true or false after substituting an integer for the argument of the predicate.
In general, a predicate or propositional function is a function that has
propositions as values. A big advantage of predicates is that they allow us to
formulate propositions that are dependent on each other. For example, suppose
that Apnq means n ą 0. Then we can express by the implication
Apnq Ñ Apn ` 1q
Figure 2.1: The points in the Euclidean plane for which the predicate Cpx, yq when
interpreted as x2 ` y 2 ď 1 evaluates to true are shaded in gray
36 2 Mathematical Arguments
Example 2.22. Suppose that the universe of discourse is the set of points in
the Euclidean plane. If the predicate U px, yq is interpreted to mean y ě 0, then
U px, yq evaluates to true for all points that lie in the closed upper half-plane
and to false for all points in the open lower half-plane (Fig. 2.2).
Figure 2.2: The points in the Euclidean plane for which the predicate U px, yq when
interpreted as y ě 0 evaluates to true are shaded in gray
If the universe is the set of positive integers, then we can express this in predi-
cate logic as @n P pnq. We call @ the universal quantifier and n the variable
bound by the universal quantifier. The statement @n P pnq is true if and only
if P pnq is true for all n in the universe. Note that the truth depends on the
interpretation of the predicate and the choice of the universe.
We can also express that a predicate P pnq is true for some1 element of
the universe. We express this in the form Dn P pnq. We call the symbol D the
existential quantifier and n the variable bound by the existential quantifier.
For instance, if the predicate P pnq has the interpretation “n is a prime,”
and the universe is the set of positive integers, then the statement
expresses that there exists a prime n such that n ` 1 is a prime as well. This
happens to be a true statement, since P p2q ^ P p3q is true.
The arguments of a predicate that are not bound by a quantifier and require
values are called free variables.
Example 2.23. Let P pnq denote the predicate with the interpretation “n is
a prime.” The value of n ranges over the set of positive integers as a universe.
1 In mathematics, “some element” is always understood in the sense of “at least one
element”.
2.6 Predicates and Quantifiers 37
In this interpretation, P pnq means that n is an integer such that 1 and n are
the only divisors of n, and n ą 1. We can express P pnq in the form
where both a and b have the set of positive integers as a universe. Here a and
b are bound variables and n is a free variable.
is bound to the universal quantifier in the predicate P pxq in the first expression,
but free in Qpxq. It is a good practice to rename the bound variable, since the
expression
p@yP pyqq ^ Qpxq,
then the order among the universal quantifiers does not matter, so we could
have written @b@aP pa, bq. We can also freely exchange existential quantifiers,
so it does not matter whether we write DaDbQpa, bq or DbDaQpa, bq. However,
the order among existential and universal quantifiers matters, as the following
example illustrates.
Example 2.24. Let Hps, cq denote the predicate with the interpretation that
“the student s owns the computer c.” The statement
@cDsHps, cq
expresses the fact that every computer is owned by a student. On the other
hand, interchanging the quantifiers yields the statement
Ds@cHps, cq,
which means that there exists a student who owns all computers.
38 2 Mathematical Arguments
EXERCISES
2.53. Let Cpa, b, cq and Spa, b, cq be predicates with the interpretation a3 `b3 “
c3 and a2 ` b2 “ c2 , respectively. How many values of pa, b, cq make the
predicates true for the given universe?
(a) Cpa, b, cq over the universe U of nonnegative integers.
(b) Cpa, b, cq over the universe U of positive integers.
(c) Spa, b, cq over the universe U “ t1, 2, 3, 4, 5u.
(d) Spa, b, cq over the universe U of positive integers.
2.54. Suppose that the universe of discourse is the set of real numbers. Trans-
late the following formal statements into mathematical statements in plain
English.
(a) @xpx2 ě 0q
(b) @xDypx ă yq
(c) @x@zDypx ă zq Ñ ppx ă yq ^ py ă zqq
(d) @x@y@zppx ă yq Ñ px ` z ă y ` zqq
(e) @x@yppx ă yq _ px “ yq _ px ą yqq.
2.56. Determine whether the following statements are true or false and justify
your answers. Suppose that the universe of discourse is the set of positive
integers for each quantifier.
(a) @aDb pa “ bq.
(b) @aDb pa “ b ` 2q.
(c) @aDb pa ď bq.
(d) Da@b pa ă bq.
(e) Da@b pa ď bq.
2.57. Suppose that the universe U “ t1, 2, 3u and P pnq a predicate over the
universe U . For each of the following statements, give an equivalent expression
that does not use quantifiers (but may use conjunctions, disjunctions, and
negations).
(a) @nP pnq
(b) DnP pnq
(c) @nP pnq
(d) DnP pnq
For expressions (c) and (d), express the statement without negated compound
expressions.
2.7 Negations 39
2.7 Negations
Finding the negation of statements is frequently needed. In this section, we
summarize the facts that we already know about the negation of formulas and
extend the results to quantified expressions and other operators.
The double negation law allows one to simplify a statement A that is pre-
ceded by two negations.
N1. A ” A.
The de Morgan’s laws govern the negation of conjunction and disjunction of
two statements A and B.
N2. pA ^ Bq ” A _ B.
N3. pA _ Bq ” A ^ B.
Example 2.26. Consider the statement “If the dessert is tiramisu, then she
eats the dessert.” The negation of this implication is given by
The dessert is tiramisu and she does not eat the dessert.
This is the conjunction of the hypothesis “the dessert is tiramisu” with the
negation of the conclusion “she eats the dessert.”
Example 2.27. The negation of the statement “She is happy if and only if
the dessert is tiramisu” has the negation
She is happy if and only if the dessert is not tiramisu.
Convince yourself that this fits the pattern outlined in N5.
Proof. Let D denote the universe. The statement @xP pxq expresses that
P pxq does not hold for all x P D. This is equivalent to saying that there exists
an x in the domain D such that P pxq does not hold, which is equivalent to
DxP pxq. Therefore, the law N6 holds.
By the first claim, we have @xQpxq ” DxQpxq. For Qpxq “ P pxq, this
yields @x P pxq ” Dx pP pxqq ” Dx P pxq. Negating both sides yields the
law N7.
Example 2.29. Let the universe of discourse be the set of all primes, and
let P pxq be the predicate with the interpretation “x is an odd integer.” Then
@xP pxq means “all primes are odd integers.” The negation of this statement is
@xP pxq, which means“not all primes are odd integers.” By N6, this can also
be expressed in the form DxP pxq, which can be interpreted as “there exists a
prime that is not an odd integer” or simply as “there exists a prime that is an
even integer.”
Example 2.30. Let the universe of discourse be the set of all right triangles
in the Euclidean plane. Let P pxq be the predicate with the interpretation “x
is an equilateral triangle”. Then DxP pxq means that “there does not exist a
right equilateral triangle.” By N7, we can also formulate this in the equivalent
form @xP pxq, which means “all right triangles are not equilateral.”
@xDy@zCpx, y, zq.
2.7 Negations 41
The beauty of the formalism is that the negation of long nested compound
statements becomes rather straightforward.
EXERCISES
2.58. Negate the following statements and simplify such that negations are
either eliminated or occur only directly before predicates.
(a) @xDypP pxq Ñ Qpyqq,
(b) @xDypP pxq ^ Qpyqq,
(c) @x@yDzppP pxq _ Qpyqq Ñ Rpx, y, zqq,
(d) Dx@ypP px, yq Ø Qpx, yqq,
(e) DxDypP pxq ^ Qpyqq.
2.59. For each of the following statements, find the negation of the statement.
Simplify such that the negations are eliminated (but you are allowed to use ).
(a) For all integers x, x2 is nonnegative.
(b) For all integers a and b, if a ă b, then f paq ă f pbq.
(c) For all integers a, there exists an integer b such that a ` b “ 1001.
(d) There exists an integer a such that for all integers b, a ` b “ 1001.
(e) For all positive integers a, there exists a positive integer b such that b ă a.
2.60. A student uses the following statement in a proof: “If x is a real number,
then x ď x2 .” The statement is evidently false. Negate this statement. For
this purpose, (a) formalize the statement, (b) negate the formalized statement
and rewrite it in a form that does not explicitly contain any negations, and (c)
translate the negated statement back into English.
2.61. Negate the following statement from a calculus book: “There exists a
constant C P R such that |f pxq| ď C for all x P R.” For this purpose, (a) first
formalize the statement with quantifiers, (b) negate the formalized statement
and rewrite it in a form such that no negations occur before a quantifier, and
(c) translate the negated statement back into English.
2.62. One of the main difficulties in a calculus course is to grasp the concept
of a limit. If the definition of the limit is given in terms of an epsilon-delta
style, then this involves three quantifiers and an implication. In this case, logic
can help to unravel the definition.
Let D be a subset of the set R of real numbers. A function f : D Ñ R has
a limit L at c P D, denoted L “ limxÑc f pxq, if and only if
for all ą 0 there exists a δ ą 0 such that for all x in D satisfying
0 ă |x ´ c| ă δ, we have |f pxq ´ L| ă .
42 2 Mathematical Arguments
2.8 Proofs
In this section, you will learn how to do certain proofs. The goal of a proof is
to convince someone that a mathematical statement is true. Ideally, a proof
will also explain why the statement is true. We will focus on three differ-
ent proof techniques: direct proofs, proofs by contraposition, and proofs by
contradiction.
An integer n is called even if and only if there exists an integer k such that
n “ 2k. An integer n is called odd if and only if there exists an integer k such
that n “ 2k ` 1.
Remark 2.33. How exactly did we prove this result? We were given the hy-
pothesis n is an odd integer. Our goal was to prove that n2 is an odd integer.
It is natural to use the definition of an odd integer to get started. In general,
it is often a good idea to make things explicit, so we expressed n in the form
n “ 2k ` 1. Since our goal was to prove a property about n2 , we simply in-
vestigated whether n2 “ p2k ` 1q2 will have that property. In this case, the
remaining steps were driven by the goal to show that n2 is of the form 2 ` 1.
Our explicit calculation proved that “ 2k 2 ` 2k will do the trick.
An integer n is called a perfect square if and only if there exists an integer
k such that n “ k 2 . In our next proposition, we are supposed to show that a
given odd integer can be expressed as a difference of two perfect squares. It
might not be apparent what these two perfect squares are. A good idea is to
look at some examples to get a feel for the problem.
3 “ 22 ´ 12 “ 4 ´ 1,
5 “ 32 ´ 22 “ 9 ´ 4,
7 “ 42 ´ 32 “ 16 ´ 9.
You probably see a pattern in these examples. So how do we get started with
the proof? By hypothesis, n is an odd integer, so we use the definition of an
odd integer, as we did in the previous proposition. For instance, 3 “ 2 ˆ 1 ` 1,
5 “ 2 ˆ 2 ` 1, and 7 “ 2 ˆ 3 ` 1. Compare this with the differences of squares
that we have guessed earlier and you should be all set to write down the proof.
Proposition 2.34. If n is an odd integer, then it is the difference between two
perfect squares.
n “ 2k ` 1 “ k 2 ` 2k ` 1 ´ k 2
“ pk ` 1q2 ´ k 2 ,
Given two integers a and b, we say that a divides b if and only if there
exists an integer q such that b “ aq. We will sometimes use the shorthand a | b
to denote that a divides b.
Proposition 2.35. Let a, b, and c be integers. Suppose that a divides both b
and c. Then a must divide mb ` nc for all integers m and n. In particular, a
divides both b ` c and b ´ c.
Proof. By assumption, there exist integers p and q such that b “ ap and c “ aq.
Therefore, mb ` nc “ map ` naq “ apmp ` nqq, so a | mb ` nc.
44 2 Mathematical Arguments
then the biggest gap between any pair of successive primes is 6. The next
proposition shows that in general it is possible to find arbitrarily long gaps
between primes. The argument is a simple direct proof.
Proposition 2.36. There exist arbitrarily long gaps between prime numbers.
pn ` 1q! ` 2, . . . , pn ` 1q! ` n ` 1
is prime. It follows that there are arbitrarily long gaps between prime numbers.
Direct proofs are used in all areas of mathematics, not just number theory.
We will give one example from calculus that is very useful in its own right. Let
|x| denote the absolute value of a real number x. So
#
x if x ě 0,
|x| “
´x if x ă 0.
|a ` b| ď |a| ` |b|.
Proposition 2.39. Let a, b, and c be integers. If a does not divide bc, then a
does not divide b and a does not divide c.
Proposition 2.41. There does not exist a smallest positive rational number.
Remark 2.42. Let us revisit the structure of the previous argument. The claim
A of the proposition was that there does not exist a smallest positive rational
number. Then the negation A of the statement is there exists a smallest
positive rational number. We called this putative smallest number s. We can
divide s by a positive integer greater than 1 to obtain a smaller number, which
leads to a contradiction.
Let us prove a particularly useful fact.
integers a, b ą 1. Since a and b are numbers that are smaller than m, we can
write them in the form
a “ a1 a2 ¨ ¨ ¨ ak , and b “ b1 b 2 ¨ ¨ ¨ b
Remark 2.44. Let P pmq denote the predicate that is true if and only if m is an
integer that can be factored into a product of primes. The claim of the previous
proposition is that @mP pmq, where m extends over all integers that are greater
than 1. Then the negation is the statement @m P pmq ” Dm P pmq. In words,
we begin the proof by assuming that there exists an integer m ą 1 that cannot
be factored into a product of primes. However, we used an important trick.
We assumed that m is the smallest integer m ą 1 that cannot be factored into
primes. This made it easier to find a contradiction.
Proofs by contradiction go back to antiquity. The next theorem is contained
in Euclid’s elements, but we give Kummer’s elegant variant of Euclid’s proof.
Theorem 2.45 (Euclid). There are infinitely many prime numbers.
Proof. Seeking a contradiction, suppose that there exist only a finite number of
primes p1 , p2 , . . . , pk . Let P “ p1 p2 ¨ ¨ ¨ pk be their product. The integer P ´ 1
can be factored into primes by Proposition 2.43. Each prime pm dividing P ´ 1
also divides P , hence by Proposition 2.35, it must divide the difference
P ´ pP ´ 1q “ 1,
which is absurd.
Figure 2.3: The figure on the left shows a 4 ˆ 4 hex board with the lower left and
upper right sides in white and the upper left and lower right in black. We can use
algebraic notation to specify the hexagons of the game board. For instance, a1 is the
left-most hexagon and d4 is the rightmost hexagon. The figure on the right illustrates
one game. White begins with c2, then Black plays b2, White plays b3, then Black
c1. White plays d2 and Black responds with a4. White’s final move a3 completes the
path between the two white regions, so White wins
Proof. Since the hex game cannot end in a tie, one of the players must have a
winning strategy. Seeking a contradiction, let us assume that the second player
has a winning strategy. Then the first player A can place a playing piece T
anywhere on the board and from then on pretend to be the second player;
this means that A will play according to the winning strategy. If the winning
strategy requires the first player to place a playing piece on the field where T
is placed, then A can place during this move A’s piece on any other field, as
this cannot hurt A’s chances. This means that the second player cannot win
anymore, contradicting our assumption that the second player has a winning
strategy.
This strategy-stealing argument works because the first move cannot hurt
the first player. What does it really mean that the first player can steal the
strategy? The nexus of the argument is that the second player simply cannot
have a winning strategy!
The theorem proves the existence of a winning strategy for the first player,
but it does not provide a recipe for such a strategy. Working out an explicit
winning strategy turns out to be difficult. Even six decades later, all explicitly
known winning strategies for hex are confined to small boards of size n ď 10,
despite a significant amount of research. In fact, we cannot hope that good
algorithms for hex will be developed, since it is know that hex is PSPACE-
complete (which means that it ranks among the most difficult problems that
can be solved on a computer with a polynomial amount of space, and it is
unlikely that such problems can be solved in polynomial time). You can learn
more about PSPACE-complete problems in a course on algorithms.
2.8 Proofs 49
EXERCISES
2.63. Suppose that m and n are consecutive integers. Use a direct proof to
show that their sum m ` n is an odd integer.
2.64. Suppose that n is an odd integer. Use a direct proof to show that n2 ´ 1
is divisible by 8.
2.65. Use a direct proof to show that n3 ´ n is divisible by 6 for all integers n.
2.66. Let n be an integer. Give a direct proof that npn ` 1qpn ` 2qpn ` 3q is
divisible by 24.
1!2!3! ¨ ¨ ¨ p2nq!
n!
is a perfect square.
2.68. Using a direct proof, show that if a and b are real numbers, then the
reverse triangle inequality
ˇ ˇ
|a ´ b| ě ˇ|a| ´ |b|ˇ
holds.
2.69. Using a direct proof, show that if a and b are real numbers, then
2.74. Prove by contradiction that the equation 42m ` 70n “ 1000 does not
have an integer solution.
2.75. Prove by contradiction that sin x ` cos x ě 1 holds for all real numbers
x in the range 0 ď x ď π{2.
50 2 Mathematical Arguments
2.9 Notes
You will need to read many proofs and practice regularly to master the art of
proofs. The books by Eccles [23] and Velleman [77] are recommended for fur-
ther reading about proof techniques. We gave a brief introduction to symbolic
logic, and we hope that you want to study this important topic in more depth.
Fortunately, there are many excellent texts on first-order predicate logic, see for
example Ebbinghaus et al. [22], Enderton [25], Gallier [28], Goldrei [29], Huth
and Ryan [37], Mendelson [60], Smullyan [68] and [69]. We recommend these
texts for further reading. A delightful collection of knight and knave puzzles
is given in [67]. There is a wide range of applications of symbolic logic and a
very long history that starts with Aristotle’s logical works. The formalization
of arguments that started with Aristotle were brought to perfection through
Frege, Hilbert, L ukasiewicz, Russell, and Whitehead and many others. We
strongly recommend that you explore metamath.org to see many more exam-
ples of formal proofs. It would be very remiss of us not to mention at least
some limitations of formal methods. For example, it is undecidable whether a
formula of first-order logic is true under all possible interpretations.
Chapter 3
Sets
No one shall expel us from the Paradise that Cantor has created.
— David Hilbert, On the Infinite, Math. Ann. 95
Set theory was invented by Georg Cantor in a remarkable series of six sem-
inal papers. In this chapter, we will learn notation, terminology, and basic
operations of set theory. We will follow the axiomatic method by Zermelo
with the amendments suggested by Fraenkel and Skolem, so that we can avoid
the consistency problems of “naive set theory.” The axioms of this set theory
are commonly known as ZFC, where the acronym honors Zermelo with Z and
Fraenkel with F, and the letter C indicates the inclusion of the axiom of choice.
This axiom schema forms the basis of most areas of modern mathematics.
t1, 2, 3u
that cannot be computed. So Cantor’s insight into the infinite has tangible
benefits to the theory of computation!
The pioneering work by Cantor was not without some flaws. He did not
delineate well enough what can and cannot constitute a set, so his theory lead
to contradictions. Fortunately, it is possible to fix these flaws, and the subse-
quent sections detail the improved version of set theory that was developed by
Zermelo, Fraenkel, and others.
For those who are familiar with Cantor’s set theory, we point out some
apparent differences. In ZFC, every element is a set itself—so there are no so-
called urelements that are not sets themselves. This allows for a more coherent
development of the theory, but the difference is not essential. The unrestricted
set comprehension of Cantor’s set theory is replaced by a more restricted ver-
sion, which eliminates troublesome antinomies.
aPA
S1. There exists a set that does not have any elements.
S2. Two sets are equal if and only if they have the same ele-
ments.
In the Zermelo–Fraenkel set theory, every element is a set. Our third axiom
schema asserts that we can form a finite set given its elements.
S “ ta1 , a2 , . . . , an u.
For example, ta, b, cu is the set containing the elements a, b, c, and no other
elements.
It should be stressed that listing elements more than once does not change
the set. For instance, ta, a, bu denotes the same set as ta, bu. We drive this
point home in the next example.
all contain the empty set H as an element. Since none of them contain any
other element, they actually all specify the same set! So, despite appearances,
the sets S1 , S2 , S3 , and S4 each contain a single element. Listing an element
multiple times is simply redundant.
Although we have only learned a few axioms of ZFC set theory, they already
allow us to specify many different sets. Starting from the empty set and the
set builder notation, we can form many different sets.
We call a set tau with one element a singleton set. This terminology is
helpful in the next example.
Example 3.2. The empty set H and the singleton set tHu containing the
empty set as an element are different sets. Indeed, the empty set H does not
contain any element, but the singleton set tHu contains one element, namely
the empty set. It follows from S2 that H is not equal to tHu.
By the axiom S2, the order of the elements does not matter, so ta, b, cu
denotes the same set as tb, c, au.
Example 3.3. We can form a set S containing as elements the empty set H,
the singleton set tHu, and the set tH, tHuu containing two elements. Appar-
ently, all three elements of this set are different, as the first contains no element,
the second contains one element, and the third contains two elements. So even
if we do not repeat elements, there are already six different ways to list the
elements of S, namely
If we form sets starting with the empty set and set builder notations, we
can quickly end up with a bewildering number of curly braces. This can be
a bit tedious to decipher. Therefore, it is customary to introduce abbrevia-
tions. For instance, the next example reformulates the previous example with
abbreviations, which dramatically increase the readability.
Example 3.4. If we denote the empty set H as 0, the singleton set tHu as 1,
and the set tH, tHuu with two elements as 2, then the sets from the previous
example can be stated in the more readable form S1 “ t0, 1, 2u, S2 “ t0, 2, 1u,
S3 “ t1, 0, 2u, S4 “ t1, 2, 0u, S5 “ t2, 0, 1u, and S6 “ t2, 1, 0u.
Example 3.6. If A “ t1, 2u, B “ t2, 3u and C “ t1, 2, 3u, then A Ď C and
B Ď C, so A and B are subsets of C. In fact, they are both proper subsets
of C. However, A is not a subset of B, as 1 is an element of A that is not
contained in B. Furthermore, B is not a subset of A, as 3 is an element of B
that is not contained in A.
A convenient way to prove that two sets A and B are equal is to show that
A Ď B and B Ď A holds. The next proposition establishes this simple fact.
Proposition 3.7. If A and B are two sets such that A Ď B and B Ď A, then
A “ B.
Every set A has itself as a subset, since the definition of a subset does not
require that a subset is a proper subset. The next proposition shows that every
set has the empty set as a subset. This is obvious if you have a good grounding
in logic, but perhaps a bit surprising for a novice.
Proof. Seeking a contradiction, we assume that there exists a set A such that
the empty set H is not a subset of A. This means that there must exist an
element x P H such that x R A. However, this is absurd since the empty set
does not contain any element x.
tx P A | Spxqu.
with four distinct elements. The set A contains the empty set H, the singleton
set tHu, the set tH, tHuu with two elements, and the set tH, tHu, tH, tHuuu
with three elements. If Spxq is the property ptHu P xq then
is the subset of A containing as elements tH, tHuu and tH, tHu, tH, tHuuu.
Both elements evidently contain tHu. Missing from this subset of A are the
elements H and tHu of A that do not contain tHu as an element.1
1 Indeed, the empty set H does not contain any elements, and the set tHu contain just
One does not need to express the property Spxq in such a formal way. It
is sufficient to specify the property Spxq unambiguously in a way that can be
expressed—in principle—by a formal statement. The next example illustrates
this point.
Example 3.10. Let A denote the set
with four distinct elements. If Spxq is the property that (x has an even number
of elements), then
tx P A | Spxqu “ tH, tH, tHuuu
is the subset of A containing the empty set with 0 elements, and the set
tH, tHuu with two elements.
Axiomatic set theory is very expressive and subsumes many areas of math-
ematics such as analysis and number theory. As we have already mentioned,
it is possible to interpret nonnegative integers as sets. Properties of numbers
such as Spxq = (x is a prime) can be expressed in principle using the formal
language of set theory, even though the expression would be long and diffi-
cult to understand. Therefore, the next example is still within the purview
of axiomatic set theory, even though everything is expressed by a convenient
shorthand.
Example 3.11. Let S “ t2, 3, . . . , 1947u be the set of integers in the range
from 2 to 1947. The set
S5. For a set A, there exists a set that contains all subsets of A
as elements.
(b) The power set of a singleton set is given by P ptauq “ tH, tauu.
Indeed, it must contain the empty set and the entire set ta, bu, as well as
the smaller subsets tau and tbu of ta, bu. There are no other subsets.
Example 3.14. When constructing the power set of a larger set such as S “
ta, b, cu, it can be helpful to notice that each subset of S either contains the
element c or does not contain c. The subsets of S that do not contain c are
given by the four elements of P pta, buq, namely
On the other hand, the subsets of S that do contain c are obtained by adding
c to each of these four sets, resulting in
P pta, b, cuq “ tH, tau, tbu, ta, bu, tcu, ta, cu, tb, cu, ta, b, cuu.
So far, we have asserted the existence of sets such as the empty set, finite
collections of sets, power sets, and subsets using specification. However, there
are some sets that cannot exist, as the next theorem shows. The irksome “set
of all sets” confounded set theorists until the proper axioms of set theory were
found.
Proof. Seeking a contradiction, we suppose that U is a set that has all sets as
elements. We can then form the subset
C “ tx P U | x R xu.
In both cases, we can conclude that both C P C and C R C hold, and this is a
contradiction. Therefore, the set U cannot exist.
58 3 Sets
C “ tx P U | x R xu.
The construction used here is valid, since any formula from predicate logic using
set membership and equality can be used as a specification, so there is nothing
out of the ordinary to use the membership relation x P x or its negation.
We remark here that sets containing themselves as elements are ruled out
by the following Axiom of Foundation in the Zermelo–Fraenkel set theory.
This axiom was introduced to set theory by von Neumann. Even though
it might not be immediately obvious from its formulation, this axiom rules
out self-referential formulations of sets (such as sets containing themselves, see
Exercise 3.14). Furthermore, the axiom S6 implies there cannot exist infinite
descending membership chains,2 such as
A1 Q A2 Q A3 Q ¨ ¨ ¨ ,
see Exercise 3.15. The main purpose of axiom S6 is to rule out weird sets that
do not occur in common mathematical practice.
EXERCISES
3.1. For each of the elements e1 “ H, e2 “ tHu and e3 “ ttHuu, determine
whether or not they are elements of the sets
(a) A1 “ tHu,
(b) A2 “ tH, tHuu,
(c) A3 “ ttHu, ttHuuu.
You have to consider nine potential membership cases.
3.2. For each of the sets S1 “ H, S2 “ tHu and S3 “ ttHuu, determine
whether or not they are subsets of the sets
(a) A1 “ tHu,
(b) A2 “ tH, tHuu,
(c) A3 “ ttHu, ttHuuu.
You have to consider nine potential subset cases.
3.3. Prove that the subset relation is transitive, i.e., show that A Ď B and
B Ď C implies A Ď C.
3.4. Express each of the following statements in your own words:
2 In the terminology of the next chapter, the membership relation is a well-founded rela-
tion.
3.2 Fundamental Concepts 59
(a) x P S
(b) txu Ď S
(c) txu P P pSq
Then show that all three statements are equivalent.
3.6. Show that the empty set is unique, meaning that if A and B are both
empty sets, then A “ B.
3.7. Show that a set, which is a subset of every set, must be the empty set.
3.8. Let Z denote the set of all integers. Describe the set
E “ tpx, yq P Z ˆ Z | x2 {4 ` y 2 ď 1u
by set enumeration, that is, by explicitly listing its elements in curly braces.
3.9. Let Z denote the set of integers. Determine the power set P pSq of the set
S “ tx P Z | x2 ă 4u.
3.10. Suppose that a set A has n elements. Show that P pAq has 2n elements
by giving a counting argument. [Hint: Notice that each element of A can be
included or excluded from a subset.]
is an element of P pP pAqq.
3.14. The Axiom of Foundation S6 states that every nonempty set A must
contain an element B P A such that the sets A and B do not have any element
in common. Show that the axiom of foundation implies that a set A cannot
satisfy A P A. [Hint: Consider the set tAu.]
3.15. Show that the Axiom of Foundation S6 implies that there cannot exist
a sequence A1 , A2 , A3 , . . . of sets such that
An`1 P An
tx P A | x P Bu.
We will denote this set by A X B and call it the intersection of the sets A
and B. The intersection of A and B contains all elements that are contained
in both sets.
We say that two sets A and B are disjoint if and only if A X B “ H.
Example 3.16. If A “ t1, 2, 3, 4, 5u, B “ t2, 4, 6, 8u and C “ t1, 3, 5, 7u, then
The sets B and C are disjoint, since B contains only even integers and the set
C contains only odd integers.
We postulate3 that there exists a set U that contains precisely the elements
of the sets A and B. In other words, x P U if and only if x P A or x P B. We
call U the union of A and B and denote it by A Y B.
Example 3.17. If A “ t1, 2, 3u and B “ t2, 4, 6, 8u then
A Y B “ t1, 2, 3, 4, 6, 8u.
The union of A and B contains the elements of both sets A and B, but no
other elements (Fig. 3.1).
Figure 3.1: The two figures show the Venn diagrams of the sets A and B. The figure
on the left illustrates the intersection A X B as the shaded region in the intersection
of the two circles. The shaded part in the figure on the right illustrates the union
AYB
Proposition 3.18. Set intersection and set union are associative operations,
that is, for all sets A, B, and C, we have
A X pB X Cq “ pA X Bq X C,
A Y pB Y Cq “ pA Y Bq Y C.
3 This is a special case of axiom S7 below.
3.3 Intersections and Unions 61
Figure 3.2: Venn diagrams can be useful to check set identities. The shaded part
of the figure illustrates the set A Y pB X Cq. Since the same area can be obtained by
shading pA Y Bq X pA Y Cq, we have a visual “proof” that the two sets are the same.
Of course, this does not replace a formal proof, but it can serve as a motivation
Example 3.20. The intersection of the sets t1, 2, 3u, t1, 3, 4u, t2, 3, 4u is given
by č
tt1, 2, 3u, t1, 3, 4u, t2, 3, 4uu “ t3u,
as 3 is the only element that is common to all three sets.
S7. For any family S of sets, there exists a set U such that x P U
if and only if x P A for some A P S.
Ť
We call U the union of the sets in the family S and denote it by S.
Example 3.21. Let A “ t1, 2u, B “ t2, 3u, and C “ t1, 3u. The family
S “ tA, B, Cu has the intersection and union
č ď
S “ H and S “ t1, 2, 3u,
respectively.
The intersection and union of a family of two sets coincide with the previous
definitions of intersection and union:
č ď
A X B “ tA, Bu and A Y B “ tA, Bu.
Remark 3.22. Since the intersection and union of a set family are at different
level than the notation in the binary case, many people prefer to write
č č ď ď
A for S and A for S.
APS APS
3.4 Differences and Symmetric Differences 63
EXERCISES
3.16. Suppose that A “ t1, 2, 3u, B “ t2, 3, 5u, and C “ t3, 4u. Determine
the following sets: (a) A X B, (b) A Y B, (c) B X C, (d) B Y C, (e) A X C,
(f) A Y C.
3.17. Let A denote the set of even integers, B the set integers that are multiples
of 3, C the set of positive integers that are powers of 6. Describe the sets (a)
A X B X C and (b) A Y B.
3.18. Show that A Ď B if and only if A X B “ A.
3.19. Show that A Ď B if and only if A Y B “ B.
3.20. Show that P pAq Y P pBq Ď P pA Y Bq.
3.21. Show that P pA Y Bq Ď P pAq Y P pBq implies that either A Ď B or
B Ď A.
Ť
3.22. Let S be a set. Show that P pSq “ S.
3.23. Let A and B be finite sets. We denote by |A| the number of elements in
A. Show that
|A Y B| ` |A X B| “ |A| ` |B|.
Difference. Given two sets A and B, we define the difference between the
sets A and B as the set A ´ B defined by
A ´ B “ tx P A | x R Bu.
If the sets A and B carry an additive operation, then the alternative notation
A z B is used to denote the set difference to avoid notational ambiguity.
Let us have a look at some properties of the set difference. The set B does
not need to be a subset of A in the difference A ´ B, but only the elements in
the intersection A X B will matter, since
A ´ B “ A ´ pA X Bq.
A ´ B “ A if and only if A X B “ H.
The two most significant properties of the set difference are given in the next
proposition.
C ´ pA X Bq “ pC ´ Aq Y pC ´ Bq,
C ´ pA Y Bq “ pC ´ Aq X pC ´ Bq
hold.
Complement. We will often encounter the situation that all sets in an ar-
gument are subsets of a given set U , which we can consider the “universe.” In
that case, it is convenient to define for each set A a complement AA in U by
AA “ U ´ A.
The main point of the notation is to suppress the set U . Of course, the universe
U needs to be clear from the context. In this case, the de Morgan’s laws read
A Y AA “ U and A X AA “ H,
This is convenient, since it allows one to translate set differences into set inter-
sections that are more straightforward to manipulate.
3.4 Differences and Symmetric Differences 65
A B “ pA ´ Bq Y pB ´ Aq.
The symmetric difference between A and B consists of all elements that belong
to either A or to B but not to both. The Venn diagrams in Fig. 3.3 might
be helpful to understand the difference between set difference and symmetric
difference.
Figure 3.3: The figure on the left illustrates the set difference A ´ B, and the figure
on the right illustrates the symmetric difference A B
AH “ HA “ A
A A “ H.
AB “ B A
holds for all sets A and B, since the union is a commutative operation. The
symmetric difference is also an associative operation, see Proposition 3.25. The
intersection distributes over the symmetric difference
A X pB Cq “ pA X Bq pA X Cq.
A B “ pA Y Bq ´ pA X Bq.
66 3 Sets
A B “ pA ´ Bq Y pB ´ Aq
“ pA X B A q Y pB X AA q
“ ppA X B A q Y Bq X ppA X B A q Y AA q
by the distributive law. Using the distributive law once more, it follows that
AB “ ppA Y Bq X U q X pU X pB A Y AA qq
“ pA Y Bq X pA X BqA
“ pA Y Bq ´ pA X Bq,
The set difference is not an associative operation, see Exercise 3.27. The
symmetric difference is an associative operation, but the proof of this fact is
more involved than the other properties of the symmetric difference.
A pB Cq “ pA Bq C
as claimed.
3.5 Cartesian Products 67
EXERCISES
3.24. Prove or disprove: The set difference is a commutative operation. In
other words, decide whether A ´ B “ B ´ A holds for all sets.
3.27. Show that the set difference is not an associative operation, that is,
A ´ pB ´ Cq is in general not equal to pA ´ Bq ´ C.
Two ordered pairs pa, bq and pc, dq are supposed to be equal if and only if they
coincide in the first coordinate as well as in the second coordinate. Let us check
that Kuratowski’s definition satisfies this property.
Proposition 3.26. The equality pa, bq “ pc, dq holds if and only if a “ c and
b “ d.
Conversely, if pa, bq “ pc, dq, then ttau, ta, buu “ ttcu, tc, duu. We distinguish
the cases (i) a ‰ b and (ii) a “ b.
68 3 Sets
Figure 3.4: René Descartes (also known as Cartesius) introduced the Cartesian
coordinate system. The first coordinate is represented by points on a horizontal line
and the second by points on a vertical line. The figure illustrates the set A ˆ B from
Example 3.27. The six dots represent the elements of A ˆ B
EXERCISES
3.31. Let A “ ta, b, cu and B “ t1, 2u. Determine A ˆ B.
A ˆ B ‰ B ˆ A.
3.36. Suppose that A is a finite nonempty set with m elements and B a set
with n elements. Prove that A ˆ B has mn elements.
3.6 Relations
Ordered pairs allow us to formalize relations among people such as x is a sibling
of y. The entities can also belong to different sets such as a client x using a
server y.
In general, a relation is a subset of a Cartesian product. We will focus on
binary relations that are subsets of a Cartesian product of two sets, but one
can form n-ary relations as subsets of the Cartesian product of n sets as well.
Given two sets A and B, a relation R between elements of these two sets is
a subset R of A ˆ B. We will say that x is in relation R to y, and write x R y
to express that px, yq P R. We will call R a relation on a set A if and only if R
is a subset of A ˆ A. We will often use symbols to denote relations instead of
letters, since that is often more natural.
The following examples will show that relations are a familiar concept, even
though you might not have seen it in our formalization.
70 3 Sets
Important Terminology
A binary relation R on a set A is called
EXERCISES
3.37. Determine whether the relation “is child of” on the set of all people is
(a) reflexive, (b) irreflexive, (c) asymmetric, (d) antisymmetric, (e) symmetric,
(f) transitive. Justify your answers.
3.38. Determine whether the relation “is sibling of” on the set of all people is
(a) reflexive, (b) irreflexive, (c) asymmetric, (d) antisymmetric, (e) symmetric,
(f) transitive. Justify your answers.
3.39. Determine whether the relation “has the same birthday as” on the set
of all people is (a) reflexive, (b) irreflexive, (c) asymmetric, (d) antisymmetric,
(e) symmetric, (f) transitive. Justify your answers.
3.40. Find a relation on a set S that is both reflexive and irreflexive. What
can you say about the set S?
3.41. Find the smallest nonempty set S that allows you to construct a relation
that is neither reflexive nor irreflexive. Explicitly give the relation and a valid
argument that S is as small as possible.
3.42. Find a relation that is both symmetric and antisymmetric. Explain why
the relation has both properties.
3.7 Functions
The concept of a function is of great importance throughout mathematics.
Undoubtedly, you have encountered many examples such as the exponential,
logarithmic, square-root, and trigonometric functions. One can get quite some
3.7 Functions 73
variety by combining such elementary functions, but the concept is too narrow.
In this section, we define functions in a much broader sense as special types of
relations.
A relation f is called a function from a set A to a set B if and only if
for each x P A there exists precisely one element y P B such that px, yq P f .
We follow Leonard Euler and write f pxq to denote the unique value that f
associates to the argument x.
We write f : A Ñ B to express that f is a function from A to B. When we
study such a function, there are four relevant sets:
(a) the domain A “ dompf q “ tx P A | there exists y P B such that px, yq P
f u of the function,
(b) the codomain B of the function,
(c) the range ranpf q “ ty P B | there exists x P A such that y “ f pxqu of the
function,
(d) the set f Ď A ˆ B that relates the arguments to function values.
The domain specifies the type of the arguments, the codomain specifies the
type of the function values, and together AˆB specifies the type of the function.
The relation f determines the domain, but not the codomain. Therefore, one
cannot omit to specify the type of the function (Fig. 3.5).
Figure 3.5: A function f : A Ñ B with range C “ ranpf q. Note that not every
element of the codomain is in the range of f . Since f is a function, each element of
A is related to just one element of B
Example 3.34. Let A denote the set of people and B the set of dates. The
function f : A Ñ B that associates to each person x their birthdate f pxq is
indeed a function, as each person has precisely one birthdate.
Example 3.35. The function χQ : R Ñ R given by
#
1 if x is a rational number,
χQ pxq “
0 if x is an irrational number
pF paq | a P Aq.
are used to specify the function f . These notations are used in calculus to
denote sequences, where a sequence is typically a function f : N0 Ñ R or a
function f : N1 Ñ R.
Given a function f : A Ñ B and a set X, then
f æ X “ tpx, yq P f | x P Xu
iB ˝ f “ f “ f ˝ iA .
Thus, iB is a left identity and iA is a right identity for the function composition.
A function f : A Ñ B is called injective or one-to-one if and only if
f pxq “ f pyq implies x “ y. In other words, a function f is injective if and only
if distinct arguments x ‰ y yield distinct function values f pxq ‰ f pyq.
Example 3.36. Any function has a unique value for each function argument,
but different arguments may share the same value. For instance, the function
f : R Ñ R given by f pxq “ x2 has a unique function value for each argument,
as a function should. However, the distinct arguments ´2 and 2 both share
the same function value, namely f p´2q “ 4 “ f p2q. Therefore, the function f
is not injective.
3.7 Functions 75
As the next proposition shows, injective functions have the crucial property
that they possess an inverse function.
Example 3.39. For instance, if b denotes a positive real number that is not
equal to 1, then the inverse of the exponential function f pxq “ bx is given by
the logarithmic function f ´1 pxq “ logb x. Thus, f ´1 pf pxqq “ logb pbx q “ x
holds for all real numbers.
Remark. Despite the notational conflation, it is usually easy to tell apart preim-
ages and inverse functions. Given a function f : A Ñ B, the inverse function
f ´1 is a function from ranpf q to A; in particular, it is a function. Given a
subset X of B, the preimage f ´1 pXq denotes a set. It is usually clear from the
context whether f ´1 is used to specify a function or a set.
A function f : A Ñ B is called surjective or onto if and only if ranpf q “ B.
In other words, a function is surjective if for every element b P B there exists
an element a P A such that b “ f paq.
Example 3.40. The function f : R Ñ Rě0 from the set of real numbers to
the set of nonnegative real numbers given by f pxq “ x2 is surjective. Indeed,
?
for any nonnegative real number y in Rě0 , the argument y yields the value
? ? 2
f p yq “ p yq “ y. So the function is surjective.
The map g is surjective, since for each a P A there exist an element b “ f paq P B
such that gpbq “ gpf paqq “ f ´1 pf paqq “ a.
Functions can be a useful tool to define new sets. For example, if f : A Ñ B
is a function, then its range
ranpf q “ ty P B | there exists some x P A such that y “ f pxqu
is again a set. We will write this set in the more descriptive form
tf pxq | x P Au.
The next axiom asserts that replacing every element x of a set A by a function
f pxq is once again a set. The intuition for this axiom is that if we replace each
element of A by some other set, then the resulting class is not bigger than A,
so it should again be a set.
However, there is a technical snag. For example, it is reasonable to form
a new set by replacing each set x P A by its power set P pxq. The power set
is defined for every set, but we cannot form the domain “set of all sets” for
the map x ÞÑ P pxq, since such a universal set does not exist, and we cannot
legally refer to the class of all sets in Zermelo–Fraenkel set theory. What we
do instead is to form a property Fpx, yq, which is true if and only if “y is the
power set of x”.
Let Fpx, yq be a property of two sets. We say that F is a functional
property if and only if for each set x there exists precisely one set y such that
Fpx, yq holds. Roughly speaking, the purpose of a functional property is to
model a function on the universe of sets. Since the universe of sets is not a
set itself, we have to resort to the usage of such functional properties. A few
examples will clarify what functional properties are.
Example 3.42. The property Fpx, yq given by “y is the power set of x” is a
functional property.
Example 3.43. Let z be a fixed set. The property Fpx, yq given by “y is the
intersection of x with the set z” is a functional property.
The functional property F can refer to other sets (so it can have parameters),
but is not allowed to refer to the set B that we try to construct. We write the
set B in the form
B “ tf pxq | x P Au,
tx2 | x P Su
is the set of the first 100 perfect squares in the set of positive integers.
The proof of the next proposition uses the Axiom of Replacement S8 and
the Axiom of Choice S9.
S “ tf ´1 ptyuq | y P Bu
so the value gpyq is one element of the preimage f ´1 ptyuq. Therefore, f pgpyqq “
f pspf ´1 ptyuqqq “ y. If gpyq “ gpzq, then y “ f pgpyqq “ f pgpzqq “ z; hence, g
is an injective function satisfying f ˝ g “ iB .
78 3 Sets
EXERCISES
3.43. Let A and B be nonempty sets. Prove that a function f : A Ñ B is
bijective if and only if there exists a function g : B Ñ A such that g ˝ f “ iA
and f ˝ g “ iB .
3.44. Let A be a nonempty set. Let f : A Ñ A be a function and denote by
f n the composition of n copies of f , so f n “ f ˝ ¨ ¨ ¨ ˝ f with n functions f .
Show that if f n “ iA for some positive integer n, then f must be bijective.
3.45. Let A, B, and C be nonempty sets. Let f : A Ñ B, g : B Ñ C, and
h : C Ñ A be functions satisfying h˝g ˝f “ iA , g ˝f ˝h “ iC , and f ˝h˝g “ iB .
Show that all three functions must be bijective.
3.46. Let A be a finite set. Show that an injective function f : A Ñ A must
be surjective. [Hint: For a given a P A, apply f n paq for various n and search
for repeated elements. Then exploit the injectivity of f .]
3.47. Describe the following subsets of the set Z of integers by functional
properties (so give the sets in the form tf pnq | n P Su for some subset S of the
set of integers).
(a) A “ t1, 4, 9, 16, 25, 36, 49u,
(b) B “ t3, 5, 7, 11, 13, 17, 19, 23u,
(c) C “ t1, 2, 4, 8, 16, 32, 64, 128, 256u,
(d) D “ t2, 6, 12, 20, 30, 42, 56, 72, 90, 110u.
3.8 Numbers
Set theory can serve as the foundation for many parts of mathematics. We will
illustrate this by defining the nonnegative integers in terms of sets. This will
allow us to characterize finite sets and pave the way to our understanding of
infinite sets.
There is a simple principle behind this bewildering number of braces and empty
sets. The definition 0 “ H is straightforward, since there is just one empty
set. Then 1 is defined to be the set t0u, 2 to be the set t0, 1u, and 3 is the set
t0, 1, 2u. If you unravel the definitions, then you end up with von Neumann’s
definitions of 0, 1, 2, and 3.
3.8 Numbers 79
Proof Principles. Since we have now defined the set of nonnegative integers,
we can now establish the validity of proof by induction, an important proof
technique. This proof technique is intrinsically linked to the structure of the
set N0 of nonnegative numbers.
This proof technique is so important that we will devote the entire next
chapter to it. As an appetizer, we will give a closed formula for the so-called
triangular numbers. For a nonnegative integer n, the triangular number Tn is
defined as Tn “ 1 ` 2 ` ¨ ¨ ¨ ` n. Figure 3.6 illustrates why triangular numbers
bear their name.
80 3 Sets
npn ` 1q
Tn “ .
2
Proof. We will prove this by induction on n. Let P pnq be the statement that
the equality
Tn “ npn ` 1q{2
holds.
Base Case Since T0 “ 0 and 0p0 ` 1q{2 “ 0, it follows that the statement P p0q
is true.
Inductive Step We need to show for all nonnegative integers n that P pnq implies
P pn ` 1q. In other words, we need to show that for all nonnegative n, if P pnq
is true, then P pn ` 1q is true.
Suppose that P pnq is true. We have
npn ` 1q n2 ` 3n ` 2 pn ` 1qpn ` 2q
Tn`1 “ `n`1“ “ ,
2 2 2
so P pn ` 1q holds. We can conclude by induction that P pnq holds for all n,
which proves the claim.
Then the property P pnq holds for all nonnegative integers n. It should be noted
that (3.1) implies P p0q, since there are no nonnegative integers k ă 0.
3.8 Numbers 81
Proof. Suppose that (3.1) is true. For all nonnegative integers, we define Qpnq
to be the statement: P pkq holds for all k ă n. Since there are no nonnegative
integers less than 0, the statement Qp0q is vacuously true.
If Qpnq holds, then P pkq holds for all k ă n. So by (3.1), P pnq is true.
It follows that P pkq holds for all k ă n ` 1. In other words, the statement
Qpn ` 1q holds.
We can conclude by induction that Qpnq is true for all nonnegative integers
n, which implies that P pnq is true for all nonnegative integers n.
EXERCISES
3.48. Explicitly give von Neumann’s definition of 4 and 5 in terms of sets.
3.9 Cardinality
We frequently count the number of elements in a set or compare the size of
sets. We have a very good intuition how to do this when the sets are finite.
Our intuition fails us when we start to compare the size of infinite sets. Cantor
showed that infinite sets can differ substantially in “size.” The technical term
for the size of a set is its cardinality.
Two sets A and B are said to have the same cardinality or are equipo-
tent if and only if there exists a bijective function from A onto B. The cardi-
nality of A is less than or equal to the cardinality of B if and only if there
exists an injective function from A to B.
If there exists an injective map from A to B, then this essentially means
that a copy of A can be embedded into B by means of the injective map, so
B is “at least as big as” the set A. If there exists a bijective function from A
onto B, then this means, roughly speaking, that the set B can be obtained by
“renaming” the elements of A using the bijective map.
For sets A and B, we write |A| ď |B| if and only if the cardinality of A is
less than or equal to the cardinality of B. We write |A| “ |B| if and only if A
and B have the same cardinality.
Let us first check that the comparison of cardinalities behaves as one might
expect from any inequality.
3.9 Cardinality 83
such that each pigeonhole contains at most one pigeon. This seems self-evident,
but giving a rigorous proof is not quite that simple.
Proof. We will prove the claim by induction on n. Let P pnq denote the state-
ment that there is no injective mapping from n onto a subset of n.
Base Case P p0q is true, since there are no proper subsets of 0 “ H.
Inductive Step We will show that for all nonnegative integers n, the statement
P pnq implies P pn ` 1q. Suppose that P pnq is true. Let f be an injective map
from t0, 1, . . . , nu onto a proper subset S. We can distinguish the cases (a)
n P S and (b) n R S.
84 3 Sets
Figure 3.7: A pair of nonnegative integers px, yq lying on the nth diagonal, where
n “ x ` y, is mapped to the value Tn ` y. For example, p2, 1q lies on the 3rd diagonal.
The number of elements on the previous three diagonals is T3 “ 1 ` 2 ` 3. So p2, 1q
is mapped to the value T3 ` 1 “ 6 ` 1 “ 7
3.9 Cardinality 85
We will now show that k is an injective function. Suppose that kpx, yq “ kpa, bq.
Seeking a contradiction, let us assume that x ` y ‰ a ` b. Without loss of
generality, we may assume that x ` y ă a ` b. By the above bound for kpx, yq,
we get
kpx, yq “ Tx`y ` y ă Ta`b ď kpa, bq,
contradicting the equality kpx, yq “ kpa, bq. Therefore, x ` y “ a ` b.
It follows that kpx, yq “ Tx`y ` y “ Tx`y ` b “ kpa, bq, so y “ b, whence
x “ a. Therefore, px, yq “ pa, bq and it follows that k is injective.
Proof. The claim holds if all sets Ai are empty, so we may assume that not all
sets Ai are empty. Let I0 “ ti P I | Ai ‰ Hu be the indices of all nonempty Ai .
Since I is countable, the subset I0 is countable as well. Therefore, there exists
N0 Ñ IŤ0 , so we can form the set family T “ tAspnq | n P N0 u,
a surjection s : Ť
which satisfies T “ S.
Since Aspnq is a nonempty set, there exists Ť a surjective map fn : N0 Ñ Aspnq .
Therefore, the functionŤ f : NŤ 0 ˆ N 0 Ñ S given by f pm, nq “ fn pmq is a
surjective map onto S “ T . If we compose this map with the inverse Ť of
´1 ´1
Cantors map Ť k : N 0 Ñ N 0 ˆN 0 , we get a surjective map f ˝k : N0 Ñ S.
Therefore, S is countable.
Let A and B be sets. We write |A| ă |B| if and only if there exists an
injective function from A into B, but no bijective function from A onto B.
86 3 Sets
Proposition 3.56 (Cantor). Let A be a set. There does not exist any surjec-
tion from A onto P pAq.
S “ tx P A | x R f pxqu.
f pAq “ χA
Proof. Let Ak denote the set of all programs in L that have k characters. Then
Ak is a finite set. The set of all programs that can beŤexpressed in L is given
Ť
S, where S “ tAk | k P N0 u. By Proposition 3.55, S is a countable set.
By contrast, the set 2N0 of characteristic functions is not countable, since
N0
|2 | “ |P pN0 q| ą |N0 | by Corollary 3.57. This proves the claim.
One should note how crude our argument was. We simply listed all possible
programs that can be written in the programming language L. Since this set
is countable, the subset of programs computing a function with a nonnegative
integer as the input and a single bit as the output is countable as well. Since the
set of characteristic functions is not countable, there are many functions that
we cannot compute. Courses on computability will explore many examples of
interesting functions that cannot be computed.
EXERCISES
3.57. Show that the sets A “ tx P R | 1 ď x ď 4u and B “ tx P R | 2 ď x ď 7u
have the same cardinality.
3.60. Show that |N0 | “ |Z| by explicitly giving a bijective function from the
set N0 of nonnegative integers onto the set Z of integers.
3.61. Suppose that A and B are sets such that |A| “ |B|. Show that |P pAq| “
|P pBq|.
3.10 Notes
Set theory was conceived by Georg Cantor [11] in a series of seminal papers.
A brief informal treatment of set theory can be found in a delightful book by
Kaplansky [45].
We have given a brief overview of Zermelo-Fraenkel set theory. The two
books by Halmos [33] and Hrbacek and Jech [36] are excellent introductions to
Zermelo–Fraenkel set theory that are recommended for further reading. Our
debt to the books by Halmos and Hrbacek and Jech should be obvious. We
also consulted the books by Deiser [19], Ebbinghaus [21], Enderton [24], and
Schindler [66] in the preparation of this chapter.
Another axiomatic set theory was conceived by von Neumann, Bernays, and
Gödel. This theory contains proper classes in addition to sets, and this can be
convenient at times. We recommend the book by Smullyan and Fitting [70] for
further information.
For a more advanced treatment of set theory including a thorough discussion
of forcing, see Jech [41] and Kunen [54].
Chapter 4
Proofs by Induction
It is impossible not to fall in love at second sight
with mathematical induction.
The principle of induction and the related principle of strong induction have
been introduced in the previous chapter. However, it takes a bit of practice
to understand how to formulate such proofs. In this chapter, we will illustrate
both methods with several examples. Furthermore, we discuss a far-reaching
generalization of these methods called well-founded induction and illustrate
this method of proof by investigating properties of the Ackermann function.
The chapter concludes with a discussion of recursion, recursively defined sets,
and structural induction.
12 “ 1, 22 “ 4, 32 “ 9, 42 “ 16, . . .
Figure 4.1: The first four perfect squares are 1, 4, 9, and 16. The illustration
explains why these are also known as square numbers. The number of squares without
an asterisk in the subfigures are 1, 3, 5, and 7
The figure makes it apparent that going from the perfect square n2 to the
next, we have to add n squares on top, n squares on the side, and 1 for the
corner; hence,
pn ` 1q2 “ n2 ` 2n ` 1,
a fact that we could have just as easily obtained by algebra. However, the
figure moreover suggests that
1 ` 3 ` 5 ` 7 “ 42 .
By looking at such small examples, it is natural to suspect that in general the
sum of the first n odd positive integers yields n2 , namely
1 ` 3 ` 5 ` . . . ` 2n ´ 1 “ n2 .
The same fact can be expressed in summation notation as
n
ÿ
n2 “ p2k ´ 1q.
k“1
We now want to give a compelling argument that the previous formula holds
for all integers n ě 1. It is not sufficient to consider a few examples. We can
take advantage of the principle of induction to prove this fact. Let us first
recall the principle of induction for positive integers.
Proposition 4.1. The sum of the first n positive odd integers equals
n
ÿ
n2 “ p2k ´ 1q
k“1
for all n ě 1.
4.1 Perfect Squares 91
Inductive Step In the inductive step, our goal is to show that the implication
P pnq Ñ P pn ` 1q holds for all n ě 1. In words, our goal is to show that the
implication
n
ÿ n`1
ÿ
n2 “ p2k ´ 1q implies pn ` 1q2 “ p2k ´ 1q (4.1)
k“1 k“1
holds for all n ě 1. If the hypothesis is false, then the implication is vacuously
true. So let us assume that the hypothesis
n
ÿ
n2 “ p2k ´ 1q (4.2)
k“1
is true. Since
pn ` 1q2 “ n2 ` p2n ` 1q,
substituting the right-hand side of the hypothesis (4.2) for n2 yields
n
ÿ n`1
ÿ
pn ` 1q2 “ p2k ´ 1q ` p2n ` 1q “ p2k ´ 1q,
k“1 k“1
@nP pnq.
92 4 Proofs by Induction
What is the difference? Suppose that P pnq is false for all n ě 1. Then
@npP pnq Ñ P pn ` 1qq is true, since each implication is vacuously true. There-
fore, the inductive step is true. However, the claim @nP pnq is false, since each
P pnq is false. This also serves as a reminder why anchoring the induction with
the base case is important.
EXERCISES
4.1. Prove or disprove: n2 ` n ` 41 is a prime for all n ě 1.
4.2. Find a proof of Proposition 4.1 that Gauss could have already found in
elementary school if his teacher would have dared to ask.
4.3. Prove by induction that the sum of the first n squares is given by
n
ÿ npn ` 1qp2n ` 1q
k 2 “ 12 ` 22 ` ¨ ¨ ¨ ` n2 “ (4.3)
k“1
6
for all n ě 1.
4.4. Prove by induction that the sum of the first n cubes is given by
n
ÿ n2 pn ` 1q2
k 3 “ 13 ` 23 ` ¨ ¨ ¨ ` n3 “ p1 ` 2 ` ¨ ¨ ¨ ` nq2 “ (4.4)
k“1
4
for all n ě 1.
4.5. Prove by induction that the sum of the squares of the first n odd positive
integers is given by
n
ÿ 1
p2k ´ 1q2 “ 12 ` 32 ` 52 ` ¨ ¨ ¨ ` p2n ´ 1q2 “ p4n3 ´ nq (4.5)
k“1
3
4.6. Prove by induction that for all integers n ě 1, the integer 22n ´ 1 is
divisible by 3.
4.7. Prove by induction that for all positive integers n, the number 2n divides
n
32 ´ 1.
p1 ` xqn ě 1 ` nx (4.7)
holds for all real numbers x ě ´1 and all nonnegative integers n. This is clear
when x is large, but is perhaps not so apparent for very small real numbers x.
Let us denote by P pnq the property that the inequality (4.7) holds for all
real numbers x such that x ě ´1. Our goal is to establish that
Establishing that P pnq holds for all integers n ě 0 suggests that we use a
proof by induction. We need to be a bit careful, though. If we were to prove the
base case P p1q and then establish P pnq for all integers n ě 1 by the induction
step, we would have established P pnq for all positive integers n, but the proof
would not cover the case n “ 0. Of course, there is an easy fix, as we can
establish P p0q as our base case and then prove that P pnq Ñ P pn ` 1q holds
for all integers n ě 0. Exercise 3.54 asserts that this is a valid variation of the
induction proof principle.
Proof. Let P pnq denote the inequality (4.8). We will prove the claim by induc-
tion on n.
Induction Basis We have P p0q, since p1 ` xq0 “ 1 “ 1 ` 0x.
Inductive Step We will show that P pnq Ñ P pn`1q holds for all n ě 0. Suppose
that P pnq holds, that is, we assume that p1 ` xqn ě 1 ` nx holds. Multiplying
both sides by the nonnegative factor p1 ` xq yields
The proof of this inequality is simple, but we will use it to illustrate a tech-
nique that you can use to gain a better understanding of a proof by induction.
We call it the modus ponens omnibus.
Let’s apply the modus ponens omnibus to the proof of Bernoulli’s inequality.
The base case P p0q established that
p1 ` xq0 ě 1 ` 0x (4.9)
p1 ` xq1 ě 1 ` 1 ¨ x. (4.10)
Since the inequality (4.9) was true and x ě ´1, we can rest assured that
the inequality (4.10) holds, so P p1q is true. The implication P p1q Ñ P p2q is
established by multiplying both sides of the inequality (4.10) by p1 ` xq ě 0
and dropping the nonnegative term x2 , which yields
Since P p1q was true and P p1q Ñ P p2q is true, this means that we have estab-
lished P p2q. At this point, you should be able to continue this pattern.
EXERCISES
?
4.10. Deduce from Bernoulli’s inequality that n
n ă 2 holds for all positive
integers n.
4.11. Determine when equality holds in Bernoulli’s inequality.
4.12. Let x1 , x2 , . . . , xn ě ´1 be real numbers that all have the same sign.
Prove by induction that
p1 ` x1 qp1 ` x2 q ¨ ¨ ¨ p1 ` xn q ě 1 ` x1 ` x2 ` ¨ ¨ ¨ ` xn .
Ln ă bn
holds for all n ě 1. [In the language of Chap. 10, this establishes bn P Ωpnq
and n P Opbn q.]
4.14. Let b ą 1 be a real number and k a positive integer. Deduce from
Bernoulli’s inequality that there exists a positive integer n0 such that
nk ď bn
holds for all n ě n0 . [In the language of Chap. 10, this establishes bn P Ωpnk q
and nk P Opbn q.]
f1 “ 1, f2 “ 1, f3 “ 2, f4 “ 3, f5 “ 5, f6 “ 8, f7 “ 13, . . .
The law governing this sequence is given by f1 “ 1 and f2 “ 1 and from then on
the next number is simply obtained as the sum of the previous two Fibonacci
numbers
fn “ fn´1 ` fn´2
96 4 Proofs by Induction
EXERCISES
4.15. Prove by induction that the sum of the first n terms of the Fibonacci
sequence that have even index is given by
n
ÿ
f2k “ f2 ` f4 ` ¨ ¨ ¨ ` f2n “ f2n`1 ´ 1. (4.13)
k“1
4.4 Geometric Series 97
4.16. Show that the number of sequences of 1s and 2s that sum to a total of
n ´ 1 is given by the Fibonacci number fn .
4.17. Prove by induction that the Fibonacci numbers satisfy the Simpson
identity
fn`1 fn´1 ´ fn2 “ p´1qn (4.14)
for all n ě 2. [Hint: Watch out for the base case.]
4.18. Prove by induction that
n
ÿ
fk2 “ fn fn`1 . (4.15)
k“1
holds for all n ě 1.
Proof. Let us denote the Eq. (4.16) by P pnq. We prove the claim by induction
on n.
Base Case The claim P pnq is true for n “ 0, since
0
ÿ
cxk “ c “ cp1 ´ x0`1 q{p1 ´ xq.
k“0
Inductive Step Our goal is to show that the implication P pnq Ñ P pn ` 1q holds
for all n ě 0. Suppose that P pnq is true. Then
n`1 n
1 ´ xn`1
ÿ ÿ ˆ ˙
k k n`1
cx “ cx ` cx “c ` cxn`1
k“0 k“0
1´x
so P pn ` 1q is true.
Therefore, we can conclude by induction that P pnq holds for all n ě 0.
Corollary 4.5. Suppose that x is a real number such that |x| ă 1 and c a real
number. Then
8
ÿ c
cxk “
k“0
1 ´ x
Proof. By definition,
8 n
1 ´ xn`1
ˆ ˙
ÿ
k
ÿ
k c
cx “ lim cx “ lim c “ ,
k“0
nÑ8
k“0
nÑ8 1´x 1´x
where the second equality follows from the previous proposition and the last
equality follows from the fact that limnÑ8 xn`1 “ 0 when |x| ă 1.
EXERCISES
ř8
4.19. Evaluate the infinite geometric series k“0 xk for
(a) x “ 1{2,
(b) x “ 1{3,
(c) x “ 2,
(d) x “ 1.
Explain your results.
For the general case, we need to recall some notation. For a positive integer
n, the factorial function n! is defined as the product of the first n positive
integers,
n! “ npn ´ 1q ¨ ¨ ¨ 2 ¨ 1,
and 0! “ 1. We define the binomial coefficient nk as
` ˘
ˆ ˙
n n!
“ .
k k!pn ´ kq!
for 1 ď k ď n.
Proof. Let P pnq denote the Eq. (4.17). We prove the claim by induction on n.
Base Case For n “ 0, we have px ` yq0 “ 1, which is equal to 00 x0 y 0 “ 1.
`˘
px ` yqn`1 “ n`1
˘ 0 n`1 `n`1˘ 1 n
` 1 x y ` ¨ ¨ ¨ ` n`1
` ` ˘ n `n`1˘ n`1
0 x y n x y ` n`1 x ,
`n˘ ` n ˘ `n`1˘
where we used Pascal’s identity k ` k´1 “ k to simplify the coefficients
k n`1´k
n`1
˘ x y
`ofn˘the `terms `n˘for `all
n`1
k˘ in the range 1 ď k ď n, and the fact that
0 “ 0 “ 1 and n “ n`1 “ 1 holds. In other words, P pn ` 1q holds.
We can conclude by induction that P pnq holds for all n ě 0.
EXERCISES
The first few exercises rely on the definition of binomial coefficients. You learn
how to evaluate them and prove some simple properties.
4.22. Numerically evaluate the binomial coefficients
ˆ ˙ ˆ ˙ ˆ ˙ ˆ ˙ ˆ ˙ ˆ ˙
5 5 5 5 5 5
, , , , , .
0 1 2 3 4 5
4.23. Show that ˆ ˙ ˆ ˙
n n
“
k n´k
holds for all nonnegative integers n and integers k in the range 0 ď k ď n.
The next few exercises are simple applications of the binomial theorem.
4.24. Use the binomial theorem to expand
p2x ` 3yq4 .
f1 “ 1, f2 “ 1, f3 “ 2, f4 “ 3, f5 “ 5, f6 “ 8, ...
does not contain every positive integer. However, it has a curious property.
We claim that each positive integer can be expressed as a sum of terms
indices,
4 “ f4 ` f1 “ 3 ` 1
6 “ f5 ` f1 “ 5 ` 1
7 “ f5 ` f2 ` f1 “ 5 ` 1 ` 1
9 “ f6 ` f1 “ 8 ` 1
It is not obvious that every positive integer should have such a representation.
However, it does seem to work for larger numbers as well. For instance, the
fairy tale number 1001 can be expressed as
1001 “ f16 ` f7 ` f1 “ 987 ` 13 ` 1.
Proposition 4.7. Every positive integer can be expressed as a sum of terms
of the Fibonacci sequence with pairwise distinct indices.
Proof. We prove this by strong induction. Let P pnq denote the property that
n is a sum of terms of the Fibonacci sequence with pairwise distinct indices.
Base Case Since f1 “ 1, the property P p1q holds.
Induction Step We claim that P p1q ^ ¨ ¨ ¨ ^ P pnq implies P pn ` 1q. Indeed,
suppose that all positive integers k in the range 1 ď k ď n can be written as a
sum of terms of the Fibonacci sequence with distinct indices.
If n ` 1 is a Fibonacci number, then P pn ` 1q holds.
It remains to show that if n ` 1 is not a Fibonacci number, then P pn ` 1q
holds as well. Let m be a positive integer such that fm is the largest Fibonacci
number less than n ` 1; hence, fm ă n ` 1 ă fm`1 . Such an integer m exists,
since the Fibonacci sequence is monotonically increasing and n ` 1 ą f2 “ 1.
Then
n ` 1 ´ fm ă fm`1 ´ fm “ fm´1 ă n ` 1
is a positive integer such that P pn ` 1 ´ fm q holds by induction hypothesis, so
there exist integers ak ą ¨ ¨ ¨ ą a1 ą 0 such that
n ` 1 ´ fm “ fak ` fak´1 ` ¨ ¨ ¨ ` fa1 .
Since n ` 1 ´ fm ă fm´1 , we have fm ą fm´1 ą fak . Therefore,
n ` 1 “ fm ` fak ` fak´1 ` ¨ ¨ ¨ ` fa1
is a representation of n ` 1 by a sum of terms of the Fibonacci sequence with
pairwise distinct indices. Therefore, P pn ` 1q holds.
We can conclude by strong induction that the claim holds for all positive
integers.
A more common way to represent integers is given in the next proposition.
Proposition 4.8. Every positive integer n can be written in the form
m
ÿ
n“ ck 2k (4.18)
k“0
Proof. We prove the claim by strong induction. Let P pnq denote the property
that n can be written in the form (4.18).
Base Case The number n “ 1 can be represented by c0 “ 1, so P p1q holds.
Inductive Step We claim that P p1q^P p2q^¨ ¨ ¨^P pnq implies P pn`1q. Suppose
that P pkq holds for all k in the range 1 ď k ď n. We are going to distinguish
between the two cases (a) n ` 1 is even and (b) n ` 1 is odd. Our goal is to
show that P pn ` 1q holds in both cases.
(a) If n ` 1 is even, then pn ` 1q{2 is a positive integer and P ppn ` 1q{2q holds.
Thus, there exists a representation
m
n`1 ÿ
“ ck 2k .
2 k“0
It follows that
m
ÿ m
ÿ
n`1“2 ck 2k “ ck 2k`1 ,
k“0 k“0
so P pn ` 1q holds.
(b) If n ` 1 ą 1 is an odd integer, then n is an even integer satisfying P pnq, so
m
ÿ
n“ ck 2k .
k“0
Proposition 4.9. For all nonnegative integers a and b with b ą 0, there exist
nonnegative numbers q and r such that
a “ qb ` r with 0 ď r ă b.
The numbers q and r are respectively called the quotient and remainder when
a is divided by b.
Proof. We are going to prove the claim by strong induction on a. Let P paq
denote that there exist nonnegative integers q and r such that a “ qb ` r with
0 ď r ă b.
Base Case For a “ 0, the numbers q “ 0 and r “ 0 yield a “ 0 “ 0 ˆ b ` 0, so
P p0q holds.
104 4 Proofs by Induction
Inductive Step For all positive integers a, we are going to show that P p0q ^
P p1q ^ ¨ ¨ ¨ ^ P pa ´ 1q implies P paq. We distinguish the cases (a) a ă b and (b)
a ě b.
Recall that an integer p ą 1 is called a prime if and only if it does not have
any positive divisors apart from 1 and p.
n “ p1 p 2 ¨ ¨ ¨ pm
of m ě 1 prime numbers.
Proof. We prove the claim by strong induction. Let P pnq denote the property
that n can be written as a product of prime numbers.
Base Case Since n “ 2 is a prime number, the property P p2q holds.
Inductive Step Suppose that P pkq holds for all k in the range 2 ď k ă n. Our
goal is to show that P pnq is true. We can distinguish two cases.
(a) If n is prime, then P pnq holds.
(b) If n is composite, then there exist integers a, b ą 1 such that n “ ab.
Since P paq and P pbq hold, there exist prime numbers a1 , . . . , ak such that
a “ a1 ¨ ¨ ¨ ak and prime numbers b1 , . . . , b such that b “ b1 ¨ ¨ ¨ b . Then
n “ a 1 ¨ ¨ ¨ a k b1 ¨ ¨ ¨ b
Proof. We prove the claim by strong induction. Let P pnq denote the predicate
that n4 ´ n2 is divisible by 12.
Base cases. We notice that
14 ´ 12 “ 0 ˆ 12, 24 ´ 22 “ 1 ˆ 12, 34 ´ 32 “ 6 ˆ 12,
44 ´ 42 “ 20 ˆ 12, 54 ´ 52 “ 50 ˆ 12, 64 ´ 62 “ 105 ˆ 12.
4.6 Strong Induction 105
EXERCISES
4.29. A positive integer n can be expressed as a sum of distinct terms of the
Fibonacci sequence. Either show that the representation is unique or give a
counter example.
4.30. Let g0 “ 1, g1 “ 2, g2 “ 3, and gn “ gn´1 ` gn´2 ` gn´3 for all integers
n ě 3. Prove by strong induction that gn ď 2n holds for all nonnegative
integers n.
4.31. Let fn be a sequence of nonnegative integers satisfying the recurrence
relation fn “ pn3 ´ 3n2 ` 2nqfn´3 , as well as f1 “ 1, f2 “ 2, and f3 “ 6. Prove
by strong induction that fn “ n! holds for all integers n ě 1.
4.32. Let φ denote the golden ratio
?
1` 5
φ“ .
2
106 4 Proofs by Induction
a1 a2 a3 ¨ ¨ ¨
of elements in S.
pa1 , a2 , a3 , . . .q
pr, b ´ 1q pr, bq
or
pr ´ 1, b ` 5q pr, bq
108 4 Proofs by Induction
T “ tx P S | P pxq is falseu
In other words, in the inductive step, we show that P pxq holds under the
assumption that P paq holds for all a satisfying a x.
Boolean Formulas. Recall that the set of Boolean formulas over a set B of
Boolean variables is the smallest set of strings over the alphabet
B Y t, _, ^, Ñ, Øu
such that
(a) a variable from B is a Boolean formula,
(b) if A is a Boolean formula, then A is a Boolean formula,
(c) if A and B are Boolean formulas, then pA _ Bq, pA ^ Bq, pA Ñ Bq, and
pA Ø Bq.
Put differently, a Boolean formula can be obtained by a finite number of ap-
plications of the rules (a), (b), and (c).
A Boolean formula is a highly structured string of symbols. Apparently,
each Boolean formula has the same number of opening as closing parentheses.
We will now show how to prove this fact by well-founded induction.
We first need to introduce a well-founded relation on the set of Boolean
formulas by letting immediate subformulas preceed a formula. In other words,
4.7 Well-founded Induction 109
A A,
A, B pA _ Bq,
A, B pA ^ Bq,
A, B pA Ñ Bq,
A, B pA Ø Bq,
A pA Ñ Bq ppA Ñ Bq ^ Cq,
Proof. Induction Basis The set of -minimal Boolean formulas coincides with
the set B of Boolean variables. Since Boolean variables do not involve any
parentheses, the claim certainly holds for them.
Inductive Step The set of Boolean formulas that are not -minimal are of
the form A, pA _ Bq, pA ^ Bq, pA Ñ Bq, or pA Ø Bq.
Suppose that the number of opening and closing parentheses is equal for the
subformulas A and B. Since A A, and A does not introduce additional
parentheses, the claim holds for A. Since A, B pA ‹ Bq, where
‹ P t_, ^, Ñ, Øu,
and each composite formula introduces one additional opening and one ad-
ditional closing parenthesis, the number of opening and closing parentheses
remains balanced.
Therefore, we can conclude by well-founded induction that all Boolean for-
mulas have the same number of opening parentheses as the number of closing
parentheses.
The next proposition gives some simple lower bound for the value of the
Ackermann function Apx, yq in terms of the right argument y. This inequality
is tight for x “ 0, but can be loose for larger values of x.
Proposition 4.20. The Ackermann function Apx, yq satisfies for all nonneg-
ative integers x and y the inequality
Apx, yq ą y.
Proof. We use well-founded induction over the strict lexicographic order from
Example 4.14.
Induction Basis Since Ap0, 0q “ 1 ą 0, the property holds for the -minimal
element p0, 0q.
Inductive Step Let us assume that Apm1 , n1 q ą n1 holds for all pm1 , n1 q pn, mq.
Then we have the following three cases for Apm, nq:
(a) If m “ 0 and n ‰ 0, then Ap0, nq “ n ` 1 ą n.
(b) If m ‰ 0 and n “ 0, then pm ´ 1, 1q pm, 0q, so Apm ´ 1, 1q ą 1; hence
Apm, 0q “ Apm ´ 1, 1q ą 1 ą 0.
2z ´ 3,
for some positive integer z. Alas, the common mathematical notations are not
well-suited to describe the exponent z, since it is simply too enormous!
We get ready for the task by introducing some notation to concisely express
huge numbers. Knuth’s up-arrow notation for iterated powers is convenient
for this purpose. For an integer x and a nonnegative integer n, the notation
expresses xn in the form x Ò1 n, which reminds us of the notation x^n that
is used in many programming languages for exponentiation. In other words,
x Ò1 n is the product
x Ò1 n “ x ¨ x ¨ . . . ¨ x,
of n terms.
The next big notational leap is to introduce iterated powers Òm for integers
m ą 1, which will allow us to describe extremely large numbers. We recursively
define Òm to be of the form
#
m x if n “ 1,
xÒ n“ m´1 m
xÒ px Ò pn ´ 1qq if n ą 1.
So the operators Òm are defined in terms of the Òm´1 operators, and so forth.
For instance, repeatedly applying this definition yields
x Ò3 4 “ x Ò2 px Ò3 3q
“ x Ò2 px Ò2 px Ò3 2qq
“ x Ò2 px Ò2 px Ò2 px Ò3 1qqq
“ x Ò2 px Ò2 px Ò2 xqq.
where the right-hand side contains n times the term x with the up-arrow op-
erator Òm´1 between them. We can then further express the operators Òm´1
in terms of Òm´2 operators, and so on.
We give a few small examples to illustrate how the iterated powers can be
reduced to ordinary powers.
4.7 Well-founded Induction 113
Example 4.21. The iterated powers allow one to quickly form large numbers.
For instance,
2 Ò1 3 “ 23 “ 8,
2
2 Ò2 3 “ 2 Ò1 p2 Ò1 2q “ 22 “ 16,
22
2 Ò3 3 “ 2 Ò2 p2 Ò2 2q “ 22 “ 65,536,
4 3 3 3
2 Ò 3 “ 2 Ò p2 Ò 2q “ 2 Ò 4,
2 Òm n “ 2 Òm´1 p2 Òm pn ´ 1qq.
Proof. For m ě 2, the claim follows directly from the definition of the up-arrow
operator Òm .
For m “ 1, 0, and ´1, it follows from the definitions that
2 Ò1 n “ 2n “ 2 ¨ 2n´1 “ 2 Ò0 p2 Ò1 pn ´ 1qq,
2 Ò0 n “ 2 ¨ n “ 2 ` 2pn ´ 1q “ 2 Ò´1 p2 Ò0 pn ´ 1qq,
2 Ò´1 n “ 2 ` n “ 1 ` p2 ` pn ´ 1qq “ 2 Ò´2 p2 Ò´1 pn ´ 1qq,
Apx, yq “ 2 Òx´2 py ` 3q ´ 3.
Proof. We will prove the claim by well-founded induction on the strict lexico-
graphic order relation given in Example 4.14.
Induction Basis For x “ 0 and all nonnegative integers y, the Ackermann
function satisfies
Ap0, yq “ y ` 1 “ 2 Ò´2 py ` 3q ´ 3.
114 4 Proofs by Induction
Inductive Step We will now show that Apx, yq “ 2 Òx´2 py ` 3q ´ 3 holds for
x ą 0, assuming that the claim holds for all Apx1 , y 1 q with px1 , y 1 q px, yq.
If x ą 0 and y “ 0, then by definition of the Ackermann function and the
Induction Hypothesis,
Apx, 0q “ 2 Òx´2 3 ´ 3,
Apx, yq “ 2 Òx´2 py ` 3q ´ 3
EXERCISES
4.34. Let be a well-founded relation on a set S. Show that
(a) must be irreflexive, meaning that there cannot exist an element a in S
such that a a.
(b) must be asymmetric, meaning that a b implies that b a cannot hold.
(c) there cannot exist elements a1 , a2 , . . . an in S such that ak ak`1 for all k
in the range 1 ď k ă n and an a1 .
4.35. Let S be an arbitrary nonempty set. Show that the “is an element of”
relation P on the set S is a well-founded relation.
4.36. Prove or disprove: The relation ă on the set of integers is a well-founded
relation.
4.37. Prove or disprove: The strict lexicographic ordering on the set of
finite strings over the alphabet ta, bu is a well-founded relation. The strict
lexicographic ordering is the usual alphabetical dictionary ordering. So we
4.7 Well-founded Induction 115
s 1 s 2 ¨ ¨ ¨ s m t1 t2 ¨ ¨ ¨ tm
4.45. Show that well-founded induction over the set of positive integers us-
ing the strictly-less-than relation from Example 4.13 is the familiar strong
induction principle over the positive integers.
4.46. Prove by induction that the Ackermann function satisfies
(a) Ap1, yq “ y ` 2 for all y P N0 .
(b) Ap2, yq “ 2py ` 3q ´ 3 for all y P N0 .
(c) Ap3, yq “ 2y`3 ´ 3 for all y P N0 .
These are the formulas for the “small” values of the Ackermann function.
4.47. This exercise allows you to get familiar with Knuth’s up-arrow notation.
(a) Determine 2 Ò2 5 and 5 Ò2 2.
(b) How many decimal digits are needed to express 3 Ò2 3?
(c) Which number is bigger 3 Ò2 4 or 4 Ò2 3?
(d) Show that 2 Òm 2 “ 4 holds for all integers m such that m ě ´1.
4.48. Use well-founded induction to show that the recursively defined function
f : N0 ˆ N0 Ñ N0 given by
$
&x
’ if y “ 0,
f px, yq “ y if x “ 0,
’
f px ´ 1, y ´ 1q if x ą 0 and y ą 0.
%
satisfies
f px, yq “ |x ´ y|
for all nonnegative integers x and y. Use the following approach:
(a) Let be the relation in the set N0 ˆ N0 given by
pa, bq pa ` 1, b ` 1q
for all nonnegative integers a and b. Show that is a well-founded relation.
(b) Determine the -minimal elements of N0 ˆ N0 .
(c) Use well-founded induction with respect to to prove that f px, yq “ |x´y|
holds for all nonnegative integers x and y.
4.49. Show using well-founded induction that the function f : Z Ñ Z given by
#
x ´ 10 if x ą 100,
f pxq “
f pf px ` 11qq otherwise,
and the function g : Z Ñ Z given by
#
x ´ 10 if x ą 100,
gpxq “
91 otherwise,
satisfy
f pxq “ gpxq
for all integer arguments x. Hint: Use the relation on the set Z of integers
given by a b if and only if b ă a ď 101.
4.8 Recursion 117
4.50. Suppose that x and y are two nonnegative integers such that x ě y and
that are not both equal to 0. Then the greatest common divisor of x and y can
be calculated by the recursively defined function
#
x if y “ 0,
gcdpx, yq “
gcdpy, x mod yq if y ą 0.
is a wellfounded relation.
(b) Show that gcdpx, yq terminates in a finite number of steps using well-
founded induction.
∗4.8 Recursion
It might be a good time to pause and reflect on some of the objects that we
reasoned about in this chapter. We began this chapter by studying the square
function that associates the square n2 to a positive integer argument n. We
realized that we need to add 2n ´ 1 to the square pn ´ 1q2 to go to the next
square n2 , as illustrated in Fig. 4.2.
The function g shows how to compute spnq from the previous term spn ´ 1q.
The reason why we expect that the recursive structure of spnq defines a well-
defined function is that it is defined in terms of “previous” terms with smaller
118 4 Proofs by Induction
spnq “ spn ´ 1q ` 2n ´ 1
“ spn ´ 2q ` 2n ´ 3 ` 2n ´ 1,
and so forth. Eventually, it reaches the base case n “ 1 that directly defines
sp1q, without relying on other terms.
with base case wp1q “ 1. Even though n2 “ pn ` 1q2 ´ p2n ` 1q, we need
to formulate the recursive step so that the recursion terminates in a finite
number of steps. Evidently, wp2q “ wp3q ´ 5 “ wp4q ´ 5 ´ 7. Further repeated
applications of the recursive step yields larger and larger arguments. The
problem with this approach is that a base case is not reached in a finite number
of steps when wpnq is called with an argument n ą 1.
spnq “ spn ´ 1q ` 2n ´ 1,
and
n2 “ pn ´ 1q2 ` 2n ´ 1.
The equality spnq “ n2 can be established using induction. Better yet, the
next theorem obviates the need for such a proof. It asserts that two functions
satisfying the same base case and the same recursive relation must be the same,
as long as the recursive step merely uses the previous term.
We recommend that you solve Exercises 4.53–4.55, so that you get familiar
with applying the Recursion Theorem. We will forgo the proof of the Recursion
Theorem, since it is a special case of a more general result that we will prove
below.
The aforementioned Recursion Theorem is somewhat limited in scope, as
f pnq can only depend on n and a single previous function value, namely f pn´1q.
So we cannot apply it to the Fibonacci numbers that depend on two previous
4.8 Recursion 119
seg x “ ts P S | s xu.
The initial segment comprises all elements that precede x. The initial segment
seg x is a finite set.
In well-founded recursion, the function value f pxq depends on x and the
finite number ofŤfunction values f æ seg x “ tf psq | s P seg xu.
Let seq S “ nPN0 S n denote the set of finite sequences over S.
Proof. The main idea of the proof is to approximate f using functions with
potentially smaller domains than f .
We say that a function h is admissible if and only if dom h Ď S, the domain
of h is closed in the sense that if x P dom h, then seg x Ď dom h, and
holds for all x in dom h. Thus, an admissible function follows the same recursive
step and has the same base case values as f , as long as x is in the domain of h.
Let A denote the set of all admissible functions.
Suppose that h1 and h2 are two admissible functions in A. We will now
show that these two functions agree for all arguments in their shared domain
dom h1 X dom h2 . Seeking a contradiction, let us suppose that the set
Since two different elements of S may have the same initial segment, we
cannot omit the argument x from the function g, as it is sometimes erroneously
done in the literature. Apart from x, the function g can depend on the value
of all terms f psq with s in seg x.
EXERCISES
4.51. Repeatedly use the recursive definition of the square function spnq to
compute sp6q. Confirm by direct calculation that sp6q “ 62 .
Describe the function f without recursion and prove equality using the Recur-
sion Theorem.
defines the oblong numbers f pnq “ n2 ` n for all nonnegative integers n. Prove
your result using the Recursion Theorem.
Describe the function f without recursion and prove equality using the General
Recursion Theorem.
Describe the function f without recursion and prove equality using the General
Recursion Theorem.
Describe the function f without recursion and prove your result using the
General Recursion Theorem.
122 4 Proofs by Induction
Motivation. Let U be a set that we will call the universe. We can specify
a subset S of the universe U using enumeration or set builder notation. Enu-
meration confines us to the definition of finite sets and set builder notation
sometimes requires intricate predicates to specify the subset. Alternatively, we
have the option to define a subset S of the universe U by recursion. In this
case, we specify
(a) one or more elements of S using a base set,
(b) and one or more rules to construct new elements of S given some known
elements.
The construction of S is anchored by the explicitly given elements that belong
to the base base. The remaining elements of S are constructed by repeatedly
applying the recursive rules mentioned in part (b). Evidently, we need to make
the recursive part (b) a bit more precise.
We have seen this way of construction already when defining the set of
nonnegative integers. Simplifying a bit, we defined the element 0 as belonging
to the base set, and the successor function that allowed us to construct from a
known element n a new element f pnq “ n ` 1.
Our first example is a variation of this construction.
1 At least when properly interpreted as the smallest possible set satisfying these rules.
4.9 Recursively Defined Sets 123
L0 “ B
The set Lk`1 contains all elements that are obtainable from the base set by
k ` 1 or fewer applications of constructors. We claim that
ď
S“ Lk .
kě0
124 4 Proofs by Induction
Indeed, the righthand side contains B, so it satisfies R1. Since f pLk q Ď Lk`1
holds for all constructors f in C, we can deduce that the right-hand side satisfies
R2 as well. So the right-hand side belongs to the family F. As each set in the
family F contains Lk for all nonnegative k, we can conclude that the righthand
side must be contained in each set of the family F. Therefore, the set kě0 Lk
Ť
must be equal to S.
Examples. We will now give a few more examples of recursively defined sets.
One of the strengths of recursive definitions is that it is possible to describe
sets that are otherwise more difficult to specify. The next example illustrates
this point.
Example 4.27. If the universe U is given by the set Z of integers, the base set
B “ t2u contains the single element 2, and the set C “ tf, gu of constructors
contains the functions f pxq “ 2x and gpxq “ x3 ´ 1. The set S defined by the
base set B and the set C of constructors contains, for instance, the elements
‚ 2, as it is an element of B Ď S,
‚ 4, since f p2q “ 4,
‚ 7, since gp2q “ 23 ´ 1 “ 7,
‚ 8, since f pf p2qq “ f p4q “ 8,
‚ 16, since f pf pf p2qqq “ f p8q “ 16,
‚ 32, since f p16q “ 32,
‚ 63, since gpf p2qq “ gp4q “ 43 ´ 1 “ 63,
‚ 64, since f p32q “ 64.
Evidently, S contains all integers of the form 2n with n ě 2, as repeated
application of the constructor f shows. When both constructors are used, the
results are not straightforward to predict. In fact, we are not aware of any
simple nonrecursive description of the set S.
There are many ways to recursively define a set. The next example recur-
sively defines a set, but arguably not in the most straightforward way.
Example 4.28. If the universe U is given by the set Z of integers, the base
set B “ t0u, and the set C “ tf4 , f´6 u of constructors contains the functions
f4 pnq “ n ` 4 and f´6 pnq “ n ´ 6. Since 0 is in the base set B, it is contained
in S. As 0 is contained in S, it follows that f4 p0q “ 0 ` 4 “ 4 is in S. Applying
the constructor f4 to 4 shows that 8 P S. Since f´6 p8q “ 2, we can conclude
that 2 P S. We claim that the smallest subset S of the universe Z defined by
the base set B and the set C “ tf4 , f´6 u of constructors is given by the set of
even integers, S “ t2n | n P Zu.
Example 4.29. Let U “ ta, bu˚ denote the universe consisting of the set of
strings of finite length over the alphabet ta, bu. So U contains strings such as
a, b, ab, ba, aab, and so on. The empty string is also contained in the universe
U . We will denote the empty string2 by λ. We denote the concatenation of
2 The empty string is commonly denoted by ε or λ in the literature. In programming
languages, strings are often enclosed in double quotes, so '' '' denotes the empty string.
4.9 Recursively Defined Sets 125
Structural Induction. Proving that a property P pxq holds for all elements
x of a recursively defined set S can be done using weak or strong induction.
An alternative way to prove such properties is by structural induction.
Theorem 4.30 (The Structural Induction Principle). Let U be a set called the
universe. Let S be a subset of U that is recursively defined by a base set B and
a set C of constructors. Suppose that
(a) (Induction Basis) P pbq holds for all elements b in the base set B,
(b) (Induction Step) for all constructors f P C, if the property P holds for
x1 , x2 , . . . , xn in S, and y “ f px1 , x2 , . . . , xn q, then P pyq holds as well.
Then P pxq holds for all elements x in S.
tp3, 14q, p6, 11q, p7, 10qu and set C “ tf, gu of constructors given by f ppa, bqq “
pa ` 4, b ` 13q and gppa, bqq “ pa ` 22, b ` 12q. We claim that all pairs pa, bq P S
have a sum a ` b that is divisible by 17.
We prove this claim by structural induction.
Induction Basis The pairs p3, 14q, p6, 11q, and p7, 10q all sum to 17, as 3 ` 14 “
6 ` 11 “ 7 ` 10 “ 17. Therefore, the claim holds for all element in the base set
B.
Induction Step For the induction hypothesis, let pa, bq be a pair in S such that
a ` b is divisible by 17, say a ` b “ 17m for some integer m. Then
• the pair f ppa, bqq “ pa ` 4, b ` 13q has the sum pa ` 4q ` pb ` 13q “
a ` b ` 17 “ 17pm ` 1q, which is divisible by 17,
• the pair gppa, bqq “ pa ` 22, b ` 12q has the sum pa ` 22q ` pb ` 12q “
pa ` bq ` 34 “ 17pm ` 2q, which is divisible by 17.
We can conclude by structural induction that all pairs pa, bq in S have a
sum a ` b that is divisible by 17.
Example 4.32. Let S be the smallest set of strings recursively defined by the
base set B “ N0 Y txu and set C “ tf, gu of constructors given by f py, zq “
py`zq and gpy, zq “ pyzq. We claim that all formulas in S have the same
number of left and right parentheses.
We prove this claim by structural induction.
Induction Basis Since the base set B contains only numbers and a variable,
there are no parentheses. So each element has 0 left parentheses and 0 right
parentheses.
Induction Step Suppose that y is an element of S that contains m left and
m right parentheses, and z an element of S that contains n left and n right
parentheses. Then
• f py, zq “ py`zq contains m ` n ` 1 left and m ` n ` 1 right parentheses,
• gpy, zq “ pyzq contains m ` n ` 1 left and m ` n ` 1 right parentheses.
So each constructor preserves the balance of left and right parentheses.
We can conclude by structural induction that all formulas in S contain an
equal number of left and right parentheses.
So any element in the set S is produced not just once, but actually infinitely
often during the recursive construction! For instance, 0 is already contained in
the base set B, but it is also created by the following sequence of constructors
We can create the set of even integers more economically. The next example
shows that only a single constructor is needed. More crucially, every element
in the set of even integers is created in a unique way in this example.
It is not difficult to see that S is the set of even integers, as hp2mq p0q “ ´2m
and hp2m`1q p0q “ 2m ` 2, where m is a nonnegative integer and hpkq means
that h is composed with itself k times.
The rules T1 and T2 guarantee that for each element y in the domain S at least
one value gpyq is defined. However, in general, these two rules do not guarantee
that g is a well-defined function, meaning that the same value is assigned for
every possible way to construct y. Proving that a function is well-defined on S
can be a nuisance. We do not run into this issue when the recursive definition
of S is free, as the next proposition shows.
Proposition 4.36. If the recursive definition of a set S with base set B and
constructor set C is free, then defining g : S Ñ V through the rules T1 and T2
yields a well-defined function.
Proof. This can be shown by structural induction, see Exercise 4.72. This is
not a difficult exercise, but it is instructive.
and
mpe1 , e2 q “ pe1 ˚e2 q.
Therefore, S consists of strings that contain fully parenthesized arithmetic
expressions such as pp1 ` xq ˚ xq.
When restricted to S, the constructors a and m are injective functions,
and their range are disjoint sets of strings. As each string in the image of the
constructors a and m contain parentheses, they are also disjoint from the base
set. It follows that S is freely generated by the base set B and this set C of
constructors.
4.9 Recursively Defined Sets 129
which evaluates to
EXERCISES
4.60. Using the set of real numbers as a universe, formulate a recursive defi-
nition of the set of integers.
4.61. Let U be the set of integers, and smallest subset S of U that is recursively
defined by the base set B “ t1u and the set C “ tf u containing the constructor
f pxq “ 2x. (a) Derive the five smallest elements of the set S. For each element,
show how it is obtained using the element in the base set and the constructor
f . (b) Explicitly describe the set S. You should explain how to obtain each
element in S.
4.62. Recursively define the set S “ tn2 | n P N1 u as a subset of the universe
U “ Z.
4.63. Recursively define the set S of palindromic strings over the alphabet
ta, bu as a subset of the universe U “ ta, bu˚ .
4.64. Recursively define the set S of strings over the alphabet ta, bu such that
no letter b occurs before a letter a.
130 4 Proofs by Induction
4.65. Let U be the universe U “ tp, qu˚ . Let S denote the smallest subset
of U containing the base set B “ tλu consisting of the empty string, and
closed under the set C “ tf u of constructors, where f pxq “ pxq. Show by
structural induction that all strings in S contain an equal number of left and
right parentheses.
4.66. Let U “ ta, bu˚ denote the set of strings over the alphabet ta, bu. Let
S denote the subset of U that is recursively defined by the base set B “ tbbu
and the set C “ tf, gu of constructors f pxq “ aax and gpxq “ bxb. Prove by
structural induction that every string in S ends in bb.
4.67. Let S be the smallest subset of the universe U “ ta, bu that is recursively
defined by the base set B “ tλu containing the empty string, and the set
C “ tf, gu of constructors such that f pxq “ aaxb and gpxq “ baxa. Show by
structural induction that each string in S contains twice as many letters a than
letters b.
4.68. Let S be the smallest subset of the universe U “ ZˆZ that is recursively
defined by the base set B “ tp0, 0qu and the set C “ tf, gu of constructors given
by f ppx, yqq “ px ` 1, yq and gppx, yqq “ px ` 1, y ´ 1q. Prove by structural
induction that every px, yq P S satisfies x ě ´y.
4.69. (a) Show by structural induction that every element in the recursively
defined set S in Example 4.28 is even. (b) Show that every even integer can be
constructed by applying the constructors f4 and f´6 a finite number of times
to the element of the base set.
4.70. Bob wants to draw his ancestor tree, so he wants to start with himself,
two branches to his parents, and then branches to their parents (his grand-
parents), and so on, as long as the ancestors are known. Show by structural
induction that an ancestor tree for g generations contains at most 2g ´ 1 per-
sons. [Hint: The ancestor tree starting at Bob’s mother might not have the
same number of generations than the ancestor tree starting at Bob’s father.
However, Bob does not include an ancestor unless he also has the information
about the spouse of the ancestor.]
4.10 Notes
The books by Eccles [23] and Velleman [77] contain more information about
proofs by induction. This proof technique is ubiquitous and is used in almost
every textbook of mathematics. Andreescu and Crişan [6] wrote an entire book
dedicated to induction proofs that contains numerous challenging problems.
Well-founded induction and structural induction are discussed in Loeckx and
Sieber [58]. They also show how to use these methods in computer science for
program verification. Manna [59] is another good source for applications of
well-founded induction in computer science.
One should note that there are different definitions of structural induction
in the literature, which can cause some confusion. Burstall introduced struc-
tural induction as a special case of well-founded induction. However, now it is
common to use a more relaxed definition of structural induction that is different
from Burstall’s version.
Chapter 5
Equivalence Relations
Equivalence relations are so ubiquitous in everyday life that we often
forget about their proactive existence.
— T. Britz, M. Mainetti, L. Pezzoli
The elements of a set may differ in many ways. Sometimes we want to single
out some of their properties or attributes. An equivalence relation allows one
to relate and “identify” elements that have the same properties. For instance,
the relation “has the same model year” is an equivalence relation on the set
of cars. In this chapter, we derive the most common properties of equivalence
relations and give some applications.
5.1 Generalities
Let S be a set. An equivalence relation on the set S is a reflexive, symmetric,
and transitive relation1 „ on S. In other words, „ is an equivalence relation if
and only if it satisfies the following three properties:
1 You might recall that we introduced these notions in Chap. 3. In this chapter, we will
Example 5.2. The relation “has the same birthday as” is an equivalence
relation on the set of people.
Example 5.3. The relation “has the same absolute value” on the set of real
numbers is an equivalence relation.
Example 5.4. Let S be the set of strings over an alphabet A. Then the
relation “has the same string length as” is an equivalence relation on the set S
of strings.
Example 5.5. Let S and T be nonempty sets and f : S Ñ T . Then the
relation „ on S defined by x „ y if and only if f pxq “ f pyq is an equivalence
relation. All previous examples are special cases of this example.
Let us verify that „ is indeed an equivalence relation. Since f pxq “ f pxq
holds for all x in S, we can deduce that x „ x for all x in S; thus, the relation
„ is reflexive. If x „ y, then f pxq “ f pyq, so f pyq “ f pxq, which implies
y „ x; therefore, the relation „ is symmetric. Finally, if x „ y and y „ z, then
f pxq “ f pyq and f pyq “ f pzq, which implies f pxq “ f pzq, whence x „ z; thus,
the relation „ is transitive.
For an element x in a set S, we can define its equivalence class rxs under
an equivalence relation „ as the set
rxs “ ty P S | x „ yu.
In other words, rxs is the set of all elements in S that are equivalent to x.
Lemma 5.6. Two equivalence classes are either the same or are disjoint.
Proof. Suppose that the equivalence classes rxs and rys have an element z in
common. Then x „ z and y „ z. It follows that z „ y by symmetry. Since
x „ z and z „ y, we have x „ y. Thus, y P rxs and the transitivity of „ allows
us to conclude rys Ď rxs. As x „ y implies by symmetry that y „ x, we can
conclude in the same vein that rxs Ď rys. Therefore, if two equivalence classes
of „ contain a common element, then they are the same.
2
Example 5.7. We can define aarelation „ on a Euclidean plane R such that
2 2 2 2
px1 , y1 q „ px2 , y2 q if and only if x1 ` y1 “ x2 ` y2 . This relation is reflex-
ive, symmetric,
a and transitive, so it is an equivalence relation.
Since x21 ` y12 denotes the distance of the point px1 , y1 q from the origin
p0, 0q, all points that are at the same distance from the origin belong to the
same equivalence class. So an equivalence class of points forms a circle about
the origin. Figure 5.1 shows three equivalence classes.
AŤpartition of a set S is a family P of nonempty subsets of S such that
S “ P and the sets in P are pairwise disjoint. The elements of P are called
blocks. For instance, the partition P “ tt1, 2u, t3uu of the set S “ t1, 2, 3u
consists of two blocks, namely t1, 2u and t3u.
Proposition 5.8. Let S be a nonempty set and „ an equivalence relation on
S. Then the equivalence classes of „ partition the set S.
5.1 Generalities 135
Figure 5.1: The equivalence classes rp0, 0.5qs, rp0, 0.7qs, and rp0, 1qs
Proof. Let P “ trxs | x P Su. The sets in the family P are pairwise disjoint by
Lemma 5.6. Since the relation „ is reflexive, we haveŤx P rxs, so the equivalence
classes are not empty. Furthermore, it follows that P “ S.
Proof. It follows from the definition that the relation ” is reflexive and sym-
metric. If x, y, z are elements of S such that x ” y and y ” z, then there
exist sets C and D in P such that x, y in C and y, z in D. Since C and D are
elements of a partition and the element y is contained in both C and D, we
must have C “ D. Thus, x ” z, which proves that the relation is transitive.
We can conclude that ” is indeed an equivalence relation.
Let C be a set in the partition P . For all x, y in C, we have by definition
rxs “ C “ rys. This implies the second claim.
of the set S “ t1, 2, 3, 4, 5u. Each block of the partition corresponds to ele-
ments of the set S that are identified under the equivalence relation ”. The
equivalence relation ” on S corresponding to P is given by
” “ tp1, 1q, p2, 2q, p1, 2q, p2, 1qu Y tp3, 3qu Y tp4, 4q, p5, 5q, p4, 5q, p5, 4qu.
S{„ “ trxs | x P Su
of all equivalence classes. The set S{„ is called the quotient set of the set S
under „. The map x ÞÑ rxs from S to its quotient set S{„ is called a natural
map.
136 5 Equivalence Relations
R “ tpx, yq P R2 | 0 ď x ď 2, 0 ď y ď 1u
of points that form a rectangle in the Euclidean plane. We can form an equiv-
alence relation „ on R that identifies points on the lower and upper border of
the rectangle. In other words, the equivalence classes of a point px, yq is given
by #
tpx, yqu if 0 ă y ă 1,
rpx, yqs “
tpx, 0q, px, 1qu if y “ 0 or y “ 1.
EXERCISES
5.1. Let n be a positive integer. Define on the set R of real numbers an
approximate equality «n such that x «n y if and only if |x ´ y| ď 10´n . Either
show that «n is an equivalence relation or give a counterexample.
5.2. Let L denote the set of all lines in the Euclidean plane R2 . Let 1 and
2 be lines in L. We say that 1 „ 2 if and only if the lines 1 and 2 either
coincide or have no point in common. In other words, 1 „ 2 if and only if
the lines 1 and 2 are parallel. (a) Show that „ is an equivalence relation.
(b) Describe the equivalence class rs of a line in L.
5.3. Dr. S. Marty Pants claims that any symmetric and transitive relation „
is an equivalence relation. He argues as follows: Given x, y in S, x „ y implies
y „ x by symmetry. Then transitivity yields x „ x, so „ is reflexive. What is
the flaw in this argument?
5.1 Generalities 137
5.12. Determine all equivalence relations on the set ta, bu with two distinct
elements a and b.
5.15. Let S be a set and I an arbitrary nonempty index set. For every k P I,
let Rk be an equivalence relation on S. Show that
č
M“ Rk
kPI
is an equivalence relation on S.
5.17. Find the smallest equivalence relation ” on the set S “ t1, 2, 3, 4, 5u that
contains the relation R “ tp1, 2q, p1, 3q, p4, 5qu.
5.18. Let R be a relation on a set S. Show that the intersection of all equiv-
alence relations containing R is the uniquely determined minimal equivalence
relation on S containing R.
is an equivalence relation.
5.2 Integers 139
5.2 Integers
Given two nonnegative integers a and b, we can form the difference
a´b
when a ě b. Since we would like to form the difference between any two
nonnegative integers, we need to extend the set of nonnegative integers to the
set of integers.
How do we form the set of integers? Naturally, the guiding principle is that
we want to define an integer as a difference of two nonnegative integers, but we
have to do this without relying on the undefined difference a´b when a ă b. We
circumvent this problem by letting pairs pa, bq of nonnegative integers represent
the elusive value a ´ b.
Since a pair pc, dq with the same difference c ´ d “ a ´ b should represent
the same number, we will define an equivalence relation „ on the set of pairs
of nonnegative integers
Since the second relation pa2 , b2 q „ pa3 , b3 q implies a2 `b3 “ b2 `a3 , this allows
us to deduce from (5.2) the equation
Z “ N0 ˆ N0 { „ .
The motivation for introducing the equivalence relation should now be clear.
For example, 0 is represented by p0, 0q „ p1, 1q „ p2, 2q „ ¨ ¨ ¨ . We defined the
140 5 Equivalence Relations
value 0 in Z as the equivalence class that combines all the various representa-
tions of 0, namely
0 “ tpn, nq | n P N0 u.
A positive integer k is represented in Z by the equivalence class
k “ tpn ` k, nq | n P N0 u.
´k “ tpn, n ` kq | n P N0 u.
EXERCISES
5.21. Show that each equivalence class rpa, bqs of Z “ N0 ˆ N0 { „ contains a
unique element that has at least one zero coordinate.
5.22. Explain how to define addition and multiplication when the set of inte-
gers Z is given by N0 ˆ N0 { „. The definition should work for any represen-
tative.
S{ „ “ trxs | 0 ď x ď n ´ 1u.
x 1 ` y1 ” x 2 ` y2 pmod nq,
x 1 y1 ” x 2 y2 pmod nq.
rx ` ys “ rxs ` rys,
rxys “ rxsrys
on the equivalence classes. The previous proposition ensures that this definition
does not depend on the representatives x and y of the equivalence classes.
Indeed, if rx1 s “ rx2 s and ry1 s “ ry2 s, then the previous proposition ensures
that rx1 ` y1 s “ rx2 ` y2 s and rx1 y1 s “ rx2 y2 s hold.
142 5 Equivalence Relations
EXERCISES
5.23. Derive the addition and multiplication tables for Z{4Z.
5.24. Find the last digit in the decimal expansion of 7500 .
5.25. Consider the equivalence relation a ” b pmod 9q. Prove by induction
that the equivalence classes r10n s and r1s are the same for all positive integers
n.
5.26. Let a and n be positive coprime integers. Show that there exists an
integer b such that ab ” 1 pmod nq. In other words, if you want to divide by
ras, then you multiply by rbs. The element rbs is the multiplicative inverse of
ras in Z{nZ and is denoted as ra´1 s.
5.27. Prove that a positive integer written in base 10 is divisible by 3 if and
only if the sum of its digits is divisible by 3.
5.28. Prove that a positive integer a written in base 10 is divisible by 11 if and
only if the alternating subtraction and addition of the digits of a is divisible by
11. For example, 12221 is divisible by 11, since 1 ´ 2 ` 2 ´ 2 ` 1 “ 0 is divisible
by 11. The integer 987654321 is not divisible by 11, since 9 ´ 8 ` 7 ´ 6 ` 5 ´
4 ` 3 ´ 2 ` 1 “ 5 is not divisible by 11.
5.29. Sow that an integer a is divisibly by 8 if and only if the number formed
by the least three digits of a is divisible by 8. For example, 9,234,232,224 is
divisible by 8, since 224 is divisible by 8.
5.30. Formulate a divisibility rule for divisibility by 24. Is the integer
111, 222, 333, 221, 112
divisible by 24?
Proof. One easily verifies that the relation is reflexive and symmetric. The
relations pa, bq „ pc, dq and pc, dq „ pe, f q imply the equations (i) bc “ ad and
(ii) de “ cf . Multiplying both sides of equation (i) by f yields bcf “ adf , and
substituting equation (ii) yields equation (iii) bde “ adf . Since d ‰ 0, we can
divide both sides of equation (iii) by d and obtain be “ af , so pa, bq „ pe, f q.
Therefore, „ is transitive and thus an equivalence relation.
EXERCISES
5.31. Show that the addition of rational numbers is well-defined, that is, show
that if a{b “ a1 {b1 and c{d “ c1 {d1 , then
a c a1 c1
` “ 1 ` 1.
b d b d
5.32. Show that the product of rational numbers is well-defined, that is, show
that if a{b “ a1 {b1 and c{d “ c1 {d1 , then
a c a1 c 1
¨ “ 1 ¨ 1.
b d b d
144 5 Equivalence Relations
5.5 Notes
Equivalence relations are discussed in nearly every book on algebra, combina-
torics, or discrete mathematics, see for example Cohn [15] or Jacobson [39].
One can say much more about the construction of number systems, even to
the level of detail of an entire book. The most famous example is Landau [56],
see also the book by Little et al. [57].
Chapter 6
Many daily tasks require a little bit of organization. For example, you would
not want your coffee poured before you got your cup. Some tasks simply need
to take precedence before other tasks, otherwise you might get into a mess.
This becomes particularly apparent if you try to teach a robot how to help
with such tasks. In this chapter, we investigate partial orders and lattices,
which allow one to abstract the precedence relation of tasks. Partial orders
are absolutely fundamental in mathematical arguments, and they have many
applications in computer science.
EXERCISES
6.1. Let N1 “ t1, 2, 3, . . .u denote the set of positive integers. For positive
integers x and y, we define x ď y if and only if there exists a positive integer q
such that y “ xq. Show that pN1 , ďq is a partially ordered set. The divisibility
relation x ď y is often denoted as x | y.
6.2. Let m and n be positive integers. Consider the set P “ t1, 2, . . . , mu ˆ
t1, 2, . . . , nu and a relation ď on P given by pa1 , a2 q ď pb1 , b2 q if and only if
a1 ď b1 and a2 ď b2 .
(a) Show that ď is partial order.
(b) Which elements in P are incomparable?
(c) Determine the height of pP, ďq.
(d) Determine the width of pP, ďq. The width is defined in Sect. 6.4.
6.3. Let pA, ďA q and pB, ďB q be two partially ordered sets. One can define on
the Cartesian product A ˆ B a relation ď by setting pa1 , b1 q ď pa2 , b2 q if and
only if a1 ďA a2 and b1 ďB b2 . (a) Show that pA ˆ B, ďq is a partially ordered
set known as the product order. (b) When is the product order a total order?
6.4. Let pA, ďA q and pB, ďB q be two partially ordered sets. One can define
on the Cartesian product A ˆ B a relation ď by setting pa1 , b1 q ď pa2 , b2 q if
and only if a1 ăA a2 or pa1 “ a2 and b1 ďB b2 q. (a) Show that pA ˆ B, ďq
is a partially ordered set known as the lexicographic order. (b) When is the
lexicographic order a total order?
6.5. Let pP, ďP q be a partially ordered set and R a subset of P . Show that
pR, ďR q with the relation ďR given by the restriction of ďP to pairs in R ˆ R
is a partially ordered set.
Example 6.7. The set N of positive integers with the strict inequality ă is a
strictly ordered set.
Example 6.8. Let A be a set and S “ P pAq its power set. Then the proper
subset relation Ĺ on S is a strict order.
The next two propositions show that partial orders and strict orders always
occur in pairs. It is a matter of personal preference whether one first specifies
a partial order and derives the associated strict order or the other way round.
Proof. Seeking a contradiction, let us suppose that there are two elements x
and y in S such that x ă y and y ă x hold. By transitivity, this implies that
x ă x must hold. However, this contradicts the irreflexivity of the relation.
6.3 Cover Relations and Hasse Diagrams 149
The previous two propositions show that one can associate with each strict
order a partial order by taking the union with the identity relation. Further-
more, one can obtain a strict order from a partial order by intersection with
the relation of distinctness.
It is customary to denote the strict order associated with ď, ď, Ď, and Ď
respectively by ă, ă, Ă, and Ă. Sometimes it is convenient to reverse the
symbols. For instance, we write x ě y for y ď x, and x ą y for y ă x.
EXERCISES
6.6. Show that the set of people with the relation “is ancestor of ” is a strictly
ordered set.
6.10. Let ă be a strict order on a finite set with n elements. Give a tight lower
bound on the number of pairs in the strict order ă.
6.11. Show that the set N1 of positive integers with the relation } is a strictly
ordered set, where a}b if and only if a ‰ b and a divides b.
ď “ tp1, 1q, p1, 2q, p1, 3q, p1, 6q, p2, 2q, p2, 6q, p3, 3q, p3, 6q, p6, 6qu.
For finite sets, the partial order ď can be recovered from the cover relation
㨠by adding relations that are implied by reflexivity and transitivity. Indeed,
reflexivity implies here the relations p1, 1q, p2, 2q, p3, 3q, and p6, 6q and transi-
tivity implies the relation p1, 6q. So the main benefit of the cover relation is
that it is a concise representation of the partial order.
Example 6.14. As a cautionary tale, let us consider an infinite partially or-
dered set, namely the set Q of rational numbers in their natural order ď. If
a and b are rational numbers with a ă b, then there always exists a rational
number that is strictly between the two, namely a ă pa ` bq{2 ă b. Hence,
the cover relation is the empty set. In this case, the partial order cannot be
recovered from the cover relation.
We will now show that a finite partially ordered set can be recovered from
its cover relation. We need the concept of the reflexive and transitive closure
for this purpose.
Let R be a relation on a set S. This relation does not need to be reflexive
or transitive. By adding pairs px, yq of elements to R, we can obtain a relation
that is reflexive and transitive. The reflexive and transitive closure of R
is the smallest reflexive and transitive relation on S containing R.
Lemma 6.15. The reflexive and transitive closure of a relation R on a set S
always exists.
Proof. Let F be the family of reflexive and transitive relations on S that con-
tain the relation R.
Ş This family is not empty, since it contains S ˆ S. The
intersection T :“ F of these relations is again a reflexive and transitive re-
lation. Evidently, T is the smallest reflexive and transitive relation containing
R, so it is the reflexive and transitive closure of R.
For a finite set S, the cover relation completely determines the partial order.
Proposition 6.16. Let ď be a partial order on a finite set S with associated
cover relation 㨠. Then the reflexive and transitive closure of the cover relation
㨠is precisely the partial order ď.
Proof. By definition, the cover relation 㨠is a subset of the reflexive and tran-
sitive partial order relation ď. Therefore, the reflexive and transitive closure
T of the cover relation 㨠is contained in the partial order ď.
Seeking a contradiction, let us suppose that x and y are elements in S
such that x ď y, but px, yq is not in T . Then x cannot be equal to y and
6.3 Cover Relations and Hasse Diagrams 151
The cover graph of the partial order pS, ďq is given by pS, 㨠q. The edges
of this directed graph are the cover relations. The Hasse diagram of the
partial order pS, ďq is the cover graph drawn in the Euclidean plane such that
each pair a 㨠b of the cover relation is represented by a line segment and the
y-coordinate of b is larger than the y-coordinate of the covered element a. The
line segments in a Hasse diagram are arranged such that there are no more
than two vertices of the cover graph on any line segment representing an edge.
The Hasse diagram is a simple concept that is helpful in visualizing small
examples. The next two examples illustrate the concept.
Example 6.18. The power set P pt1, 2, 3uq is partially ordered by set inclusion.
A set covers a subset if and only if precisely one element is omitted. The Hasse
diagram is shown as follows.
152 6 Partial Orders and Lattices
EXERCISES
6.12. Determine the cover relation of the set of positive integers in its natural
order.
6.13. Determine the cover relation of the set of positive integers ordered by
divisibility. In the divisibility relation a ď b if and only if there exists a positive
integer q such that b “ aq. The divisibility relation is usually written as a | b.
6.15. Draw the Hasse diagram for the divisibility relation on the set
t1, 2, . . . , 10u
6.16. The set t1, 2, . . . , 10u of positive integers from 1 to 10 is partially ordered
by the divisibility relation.
(a) Find an antichain of maximal cardinality and argue that this is a maximal
antichain.
(b) Find a partition of t1, 2, . . . , 10u into a minimal number of chains.
Example 6.19. The power set P pt1, 2, 3uq is partially ordered by set inclusion.
The Hasse diagram on the left shows an antichain of cardinality 3. This is the
largest cardinality of any antichain in P pt1, 2, 3uq.
The Hasse diagram on the right shows that P pt1, 2, 3uq can be partitioned
into the three chains (1) t1u Ď t1, 3u Ď t1, 2, 3u, (2) t2u Ď t1, 2u, and (3) H Ď
t3u Ď t2, 3u. We cannot partition P pt1, 2, 3uq into fewer chains, since t1u, t2u,
and t3u each must lie in a different chain. Indeed, none is a subset of the other
two sets. Dilworth’s theorem shows that the largest cardinality of an antichain
in a finite partially ordered set is always equal to the fewest number of chains
that partition this partially ordered set.
Case 2. If the chain C does not meet some maximal antichain A “ ta1 , . . . , am u
in S, then we need to proceed in a different way to show that S can be
partitioned into n “ m chains.
Let us define the downward closure Ad of A by
Since Au and Ad both include the antichain A, they still have width m.
We will show that Ad and Au are proper subsets of S such that Ad YAu “
S and Ad X Au “ A. By induction hypothesis, we will be able to cover
Ad as well as Au both with m chains, and these chains can be stitched
together to obtain m chains that cover S.
We will first show that Ad Y Au “ S. Seeking a contradiction, let us sup-
pose that Ad Y Au is a proper subset of S. Thus, there exists an element
x in SzpAd Y Au q. It follows that x is incomparable with every element
in A, but this would imply that A Y txu is an antichain, contradicting
the maximality of the antichain A. Therefore, S “ Ad Y Au .
We will show next that Ad X Au “ A. Indeed, if the intersection Ad X Au
would contain an element x that does not belong to A, then this would
imply that there exist elements ad and au in A such that au ă x and
x ă ad . However, it would follow that au ă ad , so ad and au are distinct
elements in A that are comparable, but this contradicts that A is an
antichain. Therefore, Ad X Au “ A.
We will now show that Ad and Au are both proper subsets of A. Indeed,
the greatest element of C cannot belong to Ad , since it would be less than
some element of A, contradicting the maximality of the chain C. Thus,
Ad is a proper subset of S. Similarly, the least element of C cannot belong
to Au , since it would be greater than some element of A, contradicting
the maximality of the chain C. Thus, Au is a proper subset of S as well.
By induction hypothesis, the proper subset Ad of S can be partitioned
into m chains Ca with a P A, where the index a is chosen such that
a P Ca . Similarly, Au is a proper subset of S that can be partitioned
by induction hypothesis into m chains Da with a P A such that a P Da .
Then Ca X Da “ tau holds for each a in A. The element a must be the
greatest element of Ca and the least element of Da , so Ca Y Da is a chain
in S. Therefore, S can be partitioned into the m chains Ca Y Da with a
in A, as claimed.
The next example illustrates the second case of the previous proof.
6.4 Dilworth’s Theorem 155
Figure 6.1: Hasse diagram of a partially ordered set with six elements. The set
S is divided along the antichain A “ ta, f u into the two parts Au “ ta, b, c, f u and
Ad “ ta, d, e, f u
Since the three friends f1 , f3 , f4 only like the first two gifts g1 and g2 , it is not
possible to present each of them with a gift that they like.
Evidently, any subset of x friends needs to like at least x gifts. Amazingly,
if this condition is satisfied for all possible number of friends, then everyone
can receive a gift that they like.
Theorem 6.24 (Hall’s Theorem). Suppose that G “ tg1 , g2 , . . . , gm u is a finite
set of gifts. You want to give each of your n friends f1 , f2 , . . . , fn one gift that
they like. The friend fk likes the subset Lk of the set G of gifts, where k is in
the range 1 ď k ď n. Suppose that for any subset I of the set t1, 2, . . . , nu, the
number of gifts liked by the friends indexed by I is at least
ˇ ˇ
ˇď ˇ
ˇ Lk ˇ ě |I|.
ˇ ˇ
ˇ ˇ
kPI
Then it is possible to give each of your n friends one gift that they like.
M “ tg1 , g2 , . . . , gm , f1 , f2 , . . . , fn u
EXERCISES
6.17. Let pS, ďq be a finite partially ordered set. Suppose that S can be
decomposed as a union of n pairwise disjoint chains C1 , . . . , Cn . Show that any
antichain in S has at most n elements.
6.18. Let pS, ďq be a finite partially ordered set. Suppose that the largest
chain in S has n elements. Show that S can be partitioned into n pairwise
disjoint antichains A1 , . . . , An .
In the Hasse diagram on the left, we consider the set X “ t2, 4u shown in
red. The elements 1 and 2 are lower bounds for X “ t2, 4u in S, and 2 is a
least element of X. In the Hasse diagram on the right, we consider the subset
6.5 Lower and Upper Bounds 159
Y “ t2, 3u of S. The element 1 is a lower bound for Y “ t2, 3u, but Y does
not have a least element.
Example 6.27. We keep the notation of the previous two examples. For
X “ t2, 4u, the set U pXq of upper bounds in S is given by U pXq “ t4, 8, 12u.
The least upper bound of X in S is given by the element 4. The least upper
bound of Y “ t2, 3u in S is given by 6.
Example 6.28. Let R be the set of real numbers in its natural order. Let
X “ tx P Q | x2 ď 2u be the set of rational numbers ?
whose square is less than 2.
Then the least upper bound of X in R is given by 2.
The
Ź subscript S is omitted if it is clear from the context. If X “ tx, yu, then
X is also written as x ^ y.
Example 6.29. Let us keep the notation of Example 6.25. The set X “ t2, 4u
has the lower bounds LpXq “ t1, 2u in S. So the greatest lower bound of X
is 2. The greatest lower bound of Y “ t2, 3u in S is 1.
Example 6.30. Let pS, ďq be a partially ordered set. Then the set of upper
bounds of the empty set is given by U pHq “ S, so sup H exists if and only if
S has a least element. Similarly, the set of lower bounds of the empty set is
given by LpHq “ S, and inf H exists if and only if S has a greatest element.
The Hasse diagram on the left shows the maximal elements 7, 8, 9, 10, 12 of
the set S. The Hasse diagram on the right shows the minimal element 1 of the
set S. In general, a partially ordered set might have more than one minimal
element or none at all.
Example 6.32. The following example shown in the Hasse diagram below has
two minimal elements a and b, but no least element. The greatest element is
J, which is also the unique maximal element.
EXERCISES
6.22. Prove that a partially ordered set pP, ďq can have at most one least
element and at most one greatest element.
6.23. Determine a partially ordered set pP, ďq with nonempty set P of small-
est possible cardinality such that pP, ďq does not have a least nor a greatest
element. Prove that there is indeed no partial order with fewer elements that
has this property.
6.24. Let pP, ďq be a partially ordered set. Show that pP, ďq has a greatest
element if and only if every subset of P is bounded above.
6.6 Extensions of Partial Orders 161
6.25. Show that a finite subset of a partially ordered set does not need to be
(a) bounded above nor (b) bounded below.
6.26. Let pS, ďq be a partially ordered set and x and y elements of S such that
the supremum x _ y exists. Show that x ď x _ y and y ď x _ y.
6.27. Let pS, ďq be a partially ordered set and x and y elements of S. Suppose
that the supremum x _ y exists. Show that x _ y “ y if and only if x ď y.
6.28. Let pS, ďq be a partially ordered set, x, y, and z elements of S such that
x _ z and y _ z exist. Show that if x ď y, then x _ z ď y _ z.
6.29. Show that a finite partially ordered set pS, ďq has at least one minimal
element and at least one maximal element.
6.30. Give a (simple) example of a partially ordered set that does not have
any minimal nor any maximal elements.
6.31. Determine all minimal and all maximal elements of the set P “ tx P Z |
x ě 2u ordered by divisibility.
6.33. A partially ordered set pS, ďq is called well-ordered if and only if every
nonempty subset of S has a least element. Show that pS, ďq must be a chain.
6.34. Give an example of a partially ordered set that is a chain but is not
well-ordered.
Proof. We are going to define the partial order Ď on S by including all pairs
from the relation ď, the pair pa, bq, and additional pairs that restore transitivity.
Let us define the sets
A “ tx P S | x ď au and B “ tx P S | b ď xu.
162 6 Partial Orders and Lattices
tpx, yq P S ˆ S | x ď yu Y pA ˆ Bq.
Theorem 6.34 (Zorn’s Lemma). Let pS, ďq be a partially ordered set. If every
nonempty chain in S has an upper bound, then the set S has a maximal element.
Proof. One can use a proof by contradiction to show that Zorn’s lemma follows
from the ZFC axioms. The shortest proofs use the principle of transfinite
induction, but this technique is beyond the scope of this book. You can find a
proof for instance in [36].
Example 6.36. We often have a list of tasks that we need to accomplish. For
instance, if we get ready in the morning, we need to get dressed before heading
out. This means that after we get up, we need to put on a jacket, pants, shoes,
shirt, and socks, but preferably not in this order. It is best to put on the pants
before wearing shoes. Also, we want to put on socks before wearing the shoes.
The partial order of the tasks is shown in the Hasse diagram as follows.
Evidently, it does not matter whether we put on socks first and then pants
or the other way around. We can create a total order that is compatible with
this partial order by choosing a minimum and then remove it, and repeat this
process on the remaining set. This way, we can create for instance the total
order
This is not the only choice, since“get up” can be immediately followed by either
“shirt,” “socks,” or “pants” in a total order.
EXERCISES
6.35. Find an extension of the partial order pP pt1, 2, 3uq, Ďq to a total order.
6.36. Let pP, ďq be a finite partial order.Ş(a) Show that there exists a finite set
T of total orders extending P such that Ş T “ P . (b) The smallest cardinality
of such sets T having the property T “ P is called the dimension of the
partial order. What is the dimension of the partially ordered set P “ t1, 2, 3, 4u
with ď given by tp1, 1q, p2, 2q, p3, 3q, p4, 4q, p1, 3q, p1, 4q, p2, 3q, p2, 4qu?
164 6 Partial Orders and Lattices
6.37. Show that a partially ordered set with n elements can have at most n!
linear extensions.
Example 6.37. Let S “ t1, 2, 3u. Suppose that two partial orders on S are
given by ďA “ tp1, 1q, p2, 2q, p3, 3q, p1, 2q, p1, 3qu and
ďB “ tp1, 1q, p2, 2q, p3, 3q, p1, 2q, p2, 3q, p1, 3qu.
Proof. Suppose that y and z are elements of A such that y ď z. For all x in A
such that x ď y, the transitivity of relation ď implies that
EXERCISES
6.39. Show that an embedding f of the partial order pA, ďA q into the partial
order pB, ďB q is an injective function.
6.40. For positive integers a and b, let fa,b pxq “ ax ` b be a function from
the set of positive integers in its natural order into itself. Determine for each
pair pa, bq whether fa,b is (a) a monotonic function, (b) an embedding, (c) an
isomorphism, or (d) none of the above.
6.41. Let pP, ďP q, pQ, ďQ q, and pR, ďR q be partial orders. Prove that if
f : P Ñ Q and g : Q Ñ R are monotone functions, then their composition g ˝ f
is a monotone function from P to R.
6.8 Lattices
A partially ordered set S in which every pair of elements x and y has a supre-
mum x _ y and an infimum x ^ y is called a lattice. It follows by induction
that every finite set of elements in S has a supremum and an infimum.
A lattice is called complete if and only if every subset of the lattice has a
supremum and an infimum.
Example 6.40. The set of positive integers ordered by divisibility forms a
lattice. Indeed, the supremum of two positive integers x and y is given by the
least common multiple suptx, yu “ lcmpx, yq and their infimum is given by the
greatest common divisor inftx, yu “ gcdpx, yq. This lattice is not complete,
since the supremum of the subset of all prime numbers does not exist.
Example 6.41. Let X be a set and S “ P pXq its power set orderedŤby
inclusion. The supremum of a family F of subsets of X is given
Ş by sup F “ F
and the infimum of this set family is given by inf F “ F . Thus, pS, Ďq is
a complete lattice, since the supremum and infimum exist for any family of
subsets of X.
Proposition 6.42. Let pS, ďq be a partially ordered set such that every subset
has an infimum. Then S is a complete lattice.
inf X “ p¨ ¨ ¨ ppx1 ^ x2 q ^ x3 q ^ ¨ ¨ ¨ ^ xn q.
f ď e “ d ^ xn
A map F from a partially ordered set into itself is said to have a fixpoint
x if and only if F pxq “ x holds. Ensuring that a map does have fixed points
is often a concern in many applications. The following theorem asserts the
existence of fixed points of monotonic maps on complete lattices.
Proof. Suppose that C Ď D are two nested subsets of the set A. Then f pCq Ď
f pDq preserves the inclusion, B ´ f pCq Ě B ´ f pDq reverses the inclusion, and
applying g yields gpB ´ f pCqq Ě gpB ´ f pDqq. Complementing once more, the
inclusion reverses once again and we get A ´ gpB ´ f pCqq Ď A ´ gpB ´ f pDqq.
2 Take a look at some of the standard proofs of this theorem to judge for yourself.
168 6 Partial Orders and Lattices
EXERCISES
6.46. Prove that any totally ordered set pS, ďq is a lattice.
6.47. The set R of real numbers under its natural order is a lattice, and so
are its subintervals. Let x and y denote real numbers such that x ă y.
(a) Is R a complete lattice?
(b) Is p´8, xq a complete lattice?
(c) Is p´8, xs a complete lattice?
(d) Is px, yq a complete lattice?
(e) Is rx, ys a complete lattice?
6.48. Let pS, ďq be a lattice. Show that for all elements x, y, and z, we have
the following laws,
(a) x _ y “ y _ x (commutative law for suprema),
(b) x ^ y “ y ^ x (commutative law for infima),
(c) x _ x “ x (idempotent law for suprema),
(d) x ^ x “ x (idempotent law for infima),
(e) x _ py _ zq “ px _ yq _ z (associative law for suprema),
(f) x ^ py ^ zq “ px ^ yq ^ z (associative law for infima),
(g) x _ px ^ yq “ x (absorption law),
(h) x ^ px _ yq “ x (absorption law).
6.49. Let pS, ďq be a lattice. Suppose that x, x1 , y, y 1 are elements in S sat-
isfying x ď x1 and y ď y 1 . Show that x _ y ď x1 _ y 1 and x ^ y ď x1 ^ y 1
hold.
6.9 Notes 169
6.50. Prove that the set N0 of nonnegative integers is a complete lattice when
ordered by the divisibility relation.
6.51. The extended real line R consists of the set of real numbers and two
elements ´8 and `8 such that ´8 ă x ă 8 for all real numbers x. Show
that the extended real line is a complete lattice.
6.52. Use the Schröder–Bernstein theorem to show that the set R of real
numbers has the same cardinality as the open interval p´1, 1q.
6.9 Notes
There exist many excellent textbooks on partially ordered sets and lattices that
can be used for further reading. Davey and Priestley [17] and Roman [63] give
a general overview of partially ordered sets and lattices. Caspard et al. [12]
emphasize finite partially ordered sets and some of their applications. Trotter
[76] gives a detailed account of dimension theory of partially ordered sets. Many
textbooks on algebra or combinatorics contain chapters on partially ordered set
and lattices; see, for example, Cohn [14], Jacobson [39], or Jukna [43].
Chapter 7
In this chapter, we learn about functions that round real numbers to an integer.
The floor function rounds the numbers down, and the ceiling function rounds
the numbers up. We will explore a few elementary properties of these functions.
Despite their simplicity, the floor and ceiling functions find many applications.
Similarly, the ceiling is a function from the set R of real numbers to the set
Z of integers that maps a real number x to the smallest integer n greater than
or equal to x. The ceiling function of a real number x is denoted by rxs. In
other words, the ceiling of a real number x is defined to be the integer n “ rxs
if and only if n ´ 1 ă x ď n. If we restrict the ceiling function to the set of
Figure 7.1: The graph on the left depicts the floor function, and the graph on the
right depicts the ceiling function
integers, then it is the identity, so rns “ n for all integers n. The graph of the
ceiling function is shown in Fig. 7.1.
The floor and ceiling functions are closely related. The next proposition
shows that you can use the floor function to express the ceiling function and
vice versa.1 You should pay close attention to the style of proof that we use
here in the argument, since it is typical for proofs of many other properties of
these two functions.
t´xu “ ´ rxs .
Proof. By definition, the floor of the real number ´x is equal to the integer
n “ t´xu if and only if n ď ´x ă n ` 1. Multiplying the terms in these
inequalities by ´1 yields ´n ě x ą ´pn ` 1q, which we can express in terms
of the ceiling function as ´n “ rxs. It follows that t´xu “ n “ ´ rxs holds, as
claimed.
Proposition 7.4. For any real number x and any integer k, we have
txu ` k ď x ` k ă txu ` k ` 1.
1 In this case, the coincidence of floor and ceiling is even more real than in the optical
You should memorize the inequalities characterizing the floor and ceiling
functions. If you compare a floor or ceiling with an integer, then the floor or
ceiling function might not be needed, as the following proposition shows. It is
a simple but instructive exercise to prove this proposition.
When programming, we often have to split an array into two parts that are
nearly of equal length. The next proposition shows that taking the first tn{2u
elements and the last rn{2s elements of the array will do the trick.
n “ 2k ` 1 “ k ` pk ` 1q “ tn{2u ` rn{2s .
We conclude this section with a useful result concerning the number of digits
in base b representation. Recall that a positive integer a can be represented in
base b in the form
ÿn
a“ a k bk ,
k“0
where the digits ak are integers in the range 0 ď ak ă b, and the leading
coefficient an ‰ 0. In base b, the number a can be represented by its digits
an an´1 ¨ ¨ ¨ a1 a0 . If the base b is not understood from the context, then it is
customary to add the base b as a subscript.
174 7 Floor and Ceiling Functions
For example, the number 1000 “ 103 requires 4 digits in base b “ 10. The
next proposition shows that a representation of 1000 in base 2 requires
digits. Indeed, the integer 1000 is represented in base 2 by the 10-digit number
11111010002 . The next proposition allows you to accurately determine the
number of digits in base b without calculating a base change.
bd´1 ď n ă bd , (7.1)
as bd´1 is the smallest d-digit integer in base b, and bd ´ 1 is the largest d-digit
integer. Taking the logarithm in base b yields
d ´ 1 ď logb n ă d.
d ´ 1 ă logb pn ` 1q ď d.
EXERCISES
7.1.X Determine \the values of the following floor and ceiling functions.
(a) p232 ´ 1q{8
X e \
(b) epe q
(c) t´1.234u
(d) Prπ π s
(e) p232 ´ 1q{33
T
(f) r´1.92s
7.1 Rounding Up and Down 175
7.2. Let x be a real number and n an integer. Show that the floor and ceiling
function satisfy
(a) txu “ n if and only if x ´ 1 ă n ď x.
(b) rxs “ n if and only if x ď n ă x ` 1.
7.3. Characterize the set
tx P R | txu “ rxsu
of arguments where the floor and ceiling functions coincide. Prove your result.
7.4. Prove Proposition 7.5. In other words, show that if x is a real number
and n an integer, then
(a) txu ă n if and only if x ă n,
(b) n ď txu if and only if n ď x,
(c) n ă rxs if and only if n ă x,
(d) rxs ď n if and only if x ď n.
As a cautionary tale, find counterexamples to each of the following state-
ments:
(e) txu ď n if and only if x ď n,
(f) n ă txu if and only if n ă x,
(g) n ď rxs if and only if n ď x,
(h) rxs ă n if and only if x ă n.
The moral of the story is that you need to be very careful when you omit floor
or ceiling functions in integer comparisons.
7.5. Graph the function f pxq “ sin π2 x3 on the interval r´5, 5s.
` P T˘
7.8. Rep. Quattro Sei plays around with his calculator and observes that
Y? ] Y? ] Y? ]
44 “ 6, 4444 “ 66, 444444 “ 666.
Show that in general the floor of the square root of the integer consisting of 2n
repeated digits of 4s is given by the integer consisting of n repeated digits of
6s, so that Y? ]
44 ¨ ¨ ¨ 4 “ 66 ¨ ¨ ¨ 6
loomoon
looooomooooon
6 is repeated n times
4 is repeated 2n times
0 ď t2xu ´ 2 txu ď 1.
p “ 274,207,281 ´ 1,
a number with 22,338,618 decimal digits. You join a team building a computer
based on ternary arithmetic that is supposed to find even larger primes. How
many ternary digits are needed to represent p?
7.12. Show that for any real number x and integer n, we have
Z ^ Z ^ Z ^
1 2 n´1
tnxu “ txu ` x ` ` x` ` ¨¨¨ ` x ` .
n n n
satisfies #
1 if x P Q,
f pxq “
0 if x P RzQ.
(Source: de Koninck, Mercier [18])
where p ranges over the set of primes, and k “ vp pnq denotes the highest power
of p such that pk divides n, but pk`1 does not divide n. We call vp pnq the
p-adic valuation of n. If a prime p does not divide n, then vp pnq “ 0, hence
pvp pnq “ 1, so this product really consists of a finite number of factors that are
not equal to 1.
178 7 Floor and Ceiling Functions
tlog p nu Z ^
ÿ n
vp pn!q “ .
k“1
pk
tlog p nu Z ^
ÿ n
k“1
pk
counts the number of times the prime factor p occurs in the product of the
numbers from 1 to n.
We can even use the floor function to construct a function that allows us
to characterize primes.
7.2 Divisibility and Primes 179
Therefore,
? the sum (7.2) counts the number of divisors k of n in the range from
2 to t nu. The positive integer
? n is composite if and only if it has a divisor k
in the range from 2 ď k ď t nu. Thus, n is prime if and only if the sum (7.2)
is equal to 0.
EXERCISES
7.17. Show that every real number x P R has a unique representation in the
form
x“q`r
where q is an integer and r is a real number in the range 0 ď r ă 1. The
number q “ txu and r “ x ´ txu. [You can interpret this as a division by 1 with
remainder r ” x pmod 1q.]
7.18. Let d be a positive integer. We know that every integer n can be uniquely
expressed in the form
n “ qd ` r,
where r is an integer in the range 0 ď r ă d. Show that the quotient q is given
by q “ tn{du and the remainder r by r “ n ´ tn{du d.
n ´ pn0 ` n1 ` ¨ ¨ ¨ ` nm q
vp pn!q “ .
p´1
7.23. Let n be a positive integer. Show that 2n does not divide n!. [Hint: You
can use Exercise 7.22.]
7.24. Let n be an integer such that n ě 2. Show that if 2n´1 divides n!, then
n must be a power of 2. [Hint: You can use Exercise 7.22.]
7.27. Explain why Proposition 7.12 does not lead to a fast check for primality.
Fortunately, applying the floor (or ceiling) to the argument is sometimes re-
dundant when a floor (or ceiling) is applied to the function value. The next
proposition gives a simple example.
n2 ď txu ă pn ` 1q2 .
Since the bounds are integers, it follows from Proposition 7.5 that
n2 ď x ă pn ` 1q2
as claimed.
Proof. Let us prove the first claim. If x “ txu, then the claim evidently holds.
If txu ă x, then f ptxuq ă f pxq, as f is monotonically strictly increasing. Since
the floor function is a non-decreasing function, it follows that
tf ptxuqu ď tf pxqu .
Proof. The function f pxq “ x{n is continuous and monotonically strictly in-
creasing. If the function value f pxq “ m is an integer, then the argument
x “ mn is an integer as well. Therefore, the claim follows from the previous
theorem.
Proof. Let us prove the first claim. If x “ txu, then the claim evidently holds.
If txu ă x, then f ptxuq ą f pxq, as f is a monotonically strictly decreasing
function. Since y ą y 1 implies rys ě ry 1 s, we can conclude that
rf ptxuqs ě rf pxqs .
7.3 Functions of Floors and Ceilings 183
EXERCISES
7.29. Carl was floored when he saw the following expression in a program:
Show that the rounding function r` pxq can also be expressed in the following
two ways: X
(a) r` pxq “ Qx ` U12 for all x P R,
\
t2xu
(b) r` pxq “ 2 for all x P R.
7.31. The function r` pxq “ tx ` 1{2u rounds a real number x to the nearest
integer. If two integers are equally near to x, then r` pxq “ tx ` 1{2u rounds to
the larger of the two integers. Use the floor function to define a function r´ pxq
that rounds a real number x to the nearest integer. If two integers are equally
near to x, then r´ pxq rounds to the smaller of the two integers.
7.32. Emmy is playing with a calculator. She enters an integer and takes its
square root. Then she repeats the process with the integer part of the answer.
After the third repetition, the integer part equals 1 for the first time. What is
the difference between the largest and the smallest number Emmy could have
started with? (Source: Norwegian Math Olympiad 2014–15)
7.33. Show that for all integers m and n, and all real numbers x, we have
Z Z ^^ Z Z ^^ Z ^
1 1 1 1 1
x “ x “ x .
m n n m mn
184 7 Floor and Ceiling Functions
The functions Lm pxq “ tx{mu are digital lines that are relevant in computer
graphics. This exercise claims that the composition of the digital line functions
Lm and Ln is commutative, so
Lm ˝ Ln “ Ln ˝ Lm “ Lmn .
7.4 Notes
The notations for the floor and ceiling functions were introduced by Iverson and
popularized by Knuth. A rich source of information on properties of floor and
ceiling functions is Knuth [48] and Graham et al. [30]. The book by Herman et
al. [35] contains some interesting problems about floor and ceiling functions.
Chapter 8
Number Theory
Mathematics is the queen of the sciences and number theory is the
queen of mathematics.
— Carl Friedrich Gauss
8.1 Divisibility
A large part of number theory is concerned with the multiplicative structure of
the integers. We begin by recalling the basics of divisibility. Even though we
start from first principles, our approach will be inspired by the more abstract
concepts that we learned in the previous chapters.
Given two integers a and b, we write b | a to denote that b divides a,
meaning that there exists an integer c such that a “ bc. If b divides a, then
we call b a divisor of a, and a a multiple of b. We write b a if and only if b
does not divide a.
For a nonzero integer b, the divisibility relation b | a is equivalent to the
statement that the rational number a{b is an integer. However, we strongly
recommend to use the aforementioned definition, as it generalizes to other
domains.
When restricted to positive integers, the properties D1–D3 ensure that the
divisibility relation is a partial order. However, on the set of integers, D2 is
not quite an antisymmetry, since 2 | ´2 and ´2 | 2, but 2 ‰ ´2. Therefore,
the divisibility relation on the set of integers is a preorder but not a partial
order.
Exercises
8.1. Prove the properties D3 and D4 of Proposition 8.5:
(a) For integers a, b, and c, show that if c | b and b | a, then c | a.
(b) For integers a, c, and m, show that if c | a, then c | am.
8.2. Let a and b be integers such that a ‰ 0. Show that if a | b, then pb{aq | b.
[Note that the vertical bar | denotes the divisibility relation and the slash {
denotes the usual division operation.]
8.2 The Greatest Common Divisor 187
8.3. Let a, b, and c be integers. Prove that a | b and a | c implies that a2 | bc.
8.5. Let a be an integer. Use only the definition of divisibility to prove that
3 | a and 4 | a implies that 12 | a.
8.7. Prove that for all integers n, we have 120 | pn5 ´ 5n3 ` 4nq.
8.9. Give a simple characterization of all integers a such that 10 | pa10 ` 1q.
(Source: de Koninck, Mercier)
8.10. Show that a positive integer is a perfect square if and only if it has an
odd number of positive divisors.
G3. d ą 0.
Example 8.7. Consider the integers a “ 24 and b “ 108. The positive divisors
of a are given by 1, 2, 3, 4, 6, 8, 12, 24, and the positive divisors of b are given
by 1, 2, 3, 4, 6, 9, 12, 18, 27, 36, 54, 108. The common positive divisors of a and b
are 1, 2, 3, 4, 6, and 12, so
gcdp24, 108q “ 12
is the greatest common divisor of 24 and 108.
Example 8.9. Suppose that we want to find the greatest common divisor of
a “ 24 and b “ 108. The prime-power decompositions of a and b are given
by a “ 24 “ 23 ¨ 3 and b “ 108 “ 22 33 . For each prime dividing a or b, we
need to inspect its exponents in the prime power decompositions and choose
the smaller exponent for the greatest common divisor. In this case, we have
Example 8.11. Suppose that we want to calculate the greatest common di-
visor of 391 and 357. Integer division of 391 by 357 yields
391 “ 1 ¨ 357 ` 34.
The previous proposition tells us that gcdp391, 357q “ gcdp357, 34q. Now we
simply repeat the process to determine gcdp357, 34q. Integer division of 357 by
34 yields
357 “ 10 ¨ 34 ` 17.
Therefore, gcdp357, 34q “ gcdp34, 17q, reducing the size of the numbers sub-
stantially. We can determine gcdp34, 17q by repeating the process once again.
Integer division yields
34 “ 2 ¨ 17 ` 0,
so the remainder is finally 0. Therefore, we can conclude that
gcdp391, 357q “ gcdp357, 34q “ gcdp34, 17q “ gcdp17, 0q.
Since gcdp17, 0q “ 17, we can conclude that gcdp391, 357q “ 17.
Euclid’s algorithm simply generalizes this idea. The greatest common divi-
sor of two integers a and b is done by repeatedly applying the previous proposi-
tion until a remainder of 0 is reached. In Ruby, we can formulate the Euclidean
algorithm as follows:
def gcd(a,b)
return a if b == 0
gcd(b, a.modulo(b))
end
If we start with integers a and b such that a ě b ą 0, then in each recursive call
the value of b gets reduced, eventually reaching 0. Since for any integer m, we
have gcdpm, 0q “ m, the last step simply needs to return the value contained
in the variable a.
Example 8.12. Let us compute the greatest common divisor of 96 and 42.
By the Euclidean algorithm, we have
, $
96 “ 2 ¨ 42 ` 12 . & gcdp96, 42q “ gcdp42, 12q
42 “ 3 ¨ 12 ` 6 ùñ “ gcdp12, 6q
12 “ 2 ¨ 6 ` 0 “ gcdp6, 0q “ 6.
- %
We can give a nice visual interpretation of these steps of the Euclidean al-
gorithm as follows. Let us draw a rectangle of dimensions a ˆ b “ 96 ˆ 42,
corresponding to the arguments of gcdp96, 42q. Our goal is to tile this rectangle
with squares, using squares of maximal size and then repeat the process for the
remaining area of the rectangle. Since 96 “ 2 ¨ 42 ` 12, we can fit two 42 ˆ 42
squares into this rectangle.
190 8 Number Theory
The greatest common divisor is the side length of the smallest square that
is used in the tiling of the rectangle of dimension a ˆ b “ 96 ˆ 42, so in this
case gcdp96, 42q “ 6.
You should convince yourself that each calculation of the greatest common
divisor of two positive integers has such a visual interpretation of the Euclidean
algorithm.
Exercises
8.11. Use Proposition 8.8 to determine the greatest common divisor gcdp504, 1386q.
8.12. Let a be a nonzero integer. Determine (a) gcdpa, 1q and (b) gcdpa, 0q.
8.13. Use the Euclidean algorithm to compute gcdp720, 125q.
8.14. Use the Euclidean algorithm to compute gcdp1751, 1547q.
8.15. Use the Euclidean algorithm to compute gcdp12 345 678, 9 876q.
8.16. Let a and b be positive integers. Show that if d “ gcdpa, bq, then a{d
and b{d are integers and gcdpa{d, b{dq “ 1.
8.3 Linear Diophantine Equations 191
8.17. Let a and b be integers that are not both zero. Show that if c is a positive
integer, then gcdpca, cbq “ c gcdpa, bq. [Hint: You may use Exercise 8.16.]
8.18. Let a and b be positive integers. Show that if gcdpa, bq “ 1, then gcdpa `
b, a ´ bq is either 1 or 2. [Hint: You can use facts that were proved in previous
exercises.]
8.20. The Ruby implementation of the Euclidean algorithm uses tail recursion.
The interpreter can optimize it into an equivalent iterative version, but Ruby
may not do this by default. Give an iterative implementation of the Euclidean
algorithm.
xn ` y n “ z n
for any integer value of n greater than 2. A proof remained elusive for 358
years until Andrew Wiles proved Fermat’s conjecture.
In this section, we will be concerned with linear Diophantine equations in
two variables. Given integers a, b, and c, the goal is to determine integer
solutions to the equation
ax ` by “ c.
These equations have many applications. Fortunately, solving linear Diophan-
tine equations is not difficult.
We have already encountered Diophantine equations in counting problems.
Example 8.13. Suppose that we want to know in how many different ways
we can give change to c cents using nickels and dimes. This amounts to solving
the Diophantine equation
c “ 5n ` 10d.
In this case, we are looking for nonnegative integer solutions.
Lemma 8.14. Let a, b, and c denote integers. Let d “ gcdpa, bq. If d does not
divide c, then the linear diophantine equation
ax ` by “ c
d “ ax0 ` by0 ,
and d is the smallest positive integer that can be expressed in this form.
Proof. Let us define the set I of all integer linear combination of a and b,
I “ tax ` by | x, y P Zu.
a “ qa d ` ra , and b “ qb d ` rb
and
so ra and rb are nonnegative elements in I that are both smaller than d. Since
d was the smallest positive number in I, we can conclude that ra “ 0 and
rb “ 0. In other words, d is a common divisor of a and b, so G1 holds.
ax ` by “ c
Proof. By the previous proposition, there exist integers x0 and y0 such that
ax0 ` by0 “ gcdpa, bq. Since gcdpa, bq | c, there exist an integer m such that
gcdpa, bqm “ c. So multiplying both sides of the equation ax0 ` by0 “ gcdpa, bq
by m yields
apx0 mq ` bpy0 mq “ c,
which proves the claim.
Theorem 8.17. Let a, b, and c be integers, and d “ gcdpa, bq. Then the
Diophantine equation
ax ` by “ c
has integer solutions if and only if d divides c. If the equation has one solution
px0 , y0 q, then all solutions of the equation are given by
b a
x “ x0 ´ z and y “ y0 ` z
d d
for z P Z.
Proof. The first claim follows from the previous results. It remains to show
the second claim.
Suppose that px1 , y1 q is an arbitrary integer solution of the equation ax `
by “ c. Then
ax0 ` by0 “ c “ ax1 ` by1 .
Dividing both sides of the equation by d “ gcdpa, bq yields
a b a b
x 0 ` y0 “ x 1 ` y1 .
d d d d
Subtracting pb{dqy0 ` pa{dqx1 from both sides yields
a b
px0 ´ x1 q “ py1 ´ y0 q.
d d
194 8 Number Theory
a b b
z “ py1 ´ y0 q.
d d d
a a
z “ y1 ´ y0 or y1 “ y0 ` z.
d d
We can conclude that any integer solution px1 , y1 q of the Diophantine equation
ax ` by “ c must be of the form
b a
x1 “ x0 ´ z and y1 “ y0 ` z,
d d
The previous theorem shows that if we know one solution to a linear Dio-
phantine equation in two variables, then it is easy to find all other solutions.
Corollary 8.16 showed that a solution to ax`by “ c exists if gcdpa, bq divides c.
The question is how to find such a solution. Fortunately, we can derive a solu-
tion directly from the calculations of the Euclidean algorithm. Let us look at
an example.
96 “ 2 ¨ 42 ` 12 (8.1)
42 “ 3 ¨ 12 ` 6 (8.2)
12 “ 2 ¨ 6 ` 0 (8.3)
Exercises
8.21. Determine all solutions to the coin change problem given in Exam-
ple 8.13.
8.22. Follow the proof of Proposition 8.15 and find integers x and y such that
gcdp504, 1386q “ 504x ` 1386y.
a “ b ¨ q1 ` r1 , 0 ă r1 ă b,
b “ r1 ¨ q2 ` r2 , 0 ă r2 ă r1 ,
r1 “ r2 ¨ q3 ` r3 , 0 ă r3 ă r2 ,
..
.
rn´2 “ rn´1 qn ` rn , 0 ă rn ă rn´1 ,
rn´1 “ rn ¨ qn`1 ` 0,
from which we can deduce that gcdpa, bq “ rn . Show how to obtain integers x
and y such that rn “ gcdpa, bq “ ax ` by by rewriting these equations.
8.27. A farmer lays out the sum of 1770 crowns in purchasing horses and oxen.
He pays 31 crowns for each horse and 21 crowns for each ox, and buys more
horses than oxen. How many horses and oxen did the farmer buy? (Source:
L. Euler, Elements of Algebra)
8.28. Let n be an integer. Show that the set nZ “ tnz | z P Zu of all integer
multiples of n is an ideal in Z.
8.30. Let I be an ideal in Z. Show that there exists an integer n such that
I “ nZ. [An ideal of the form nZ is called a principal ideal. So this exercise
shows that all ideals in the integers are principal ideals.]
196 8 Number Theory
We consider all solutions that belong to the same congruence class modulo m
to be equivalent. So this raises the question: How many congruence classes
modulo m solve a given linear congruence equation? Before we answer this
question, let us examine an example.
Example 8.22. The linear congruence equation
6x ” 9 pmod 15q
r4s “ t4 ` 15k|k P Zu, r9s “ t9 ` 15k|k P Zu, r14s “ t14 ` 15k|k P Zu.
Notice that all solutions are congruent modulo 5, where 5 “ 15{ gcdp6, 15q.
Proposition 8.23. Let a and b be integers, and m a positive integer. Let
d “ gcdpa, mq. If d | b, then the congruence
ax ” b pmod mq
Exercises
8.33. Solve the linear congruence equation 6x ” 5 pmod 8q. If the congruence
equation can be solved, then give all inequivalent solutions.
8.34. Solve the linear congruence equation 10x ” 12 pmod 256q.
8.35. Let a and b be positive integers such that gcdpa, bq “ 1. Solve the linear
congruence equation pa ` bqx ” a2 ` b2 pmod abq.
8.36. Let f px1 , x2 , . . . , xn q be a polynomial in n variables with integer co-
efficients. Let m be a positive integer. Let a1 , a2 , . . . , an and b1 , b2 , . . . , bn
be integers such that ak ” bk pmod mq holds for all integers k in the range
1 ď k ď n. Show that
holds.
8.37. (a) Let f px1 , x2 , . . . , xn q be a polynomial in n variables with integer
coefficients. Show that the Diophantine equation f px1 , x2 , . . . , xn q “ 0 does
not have a solution if there exists a positive integer m such that the congruence
equation f px1 , x2 , . . . , xn q ” 0 pmod mq cannot be solved. (b) Show that the
square of an integer x must satisfy x2 ” 0 pmod 3q or x2 ” 1 pmod 3q. (c) Use
the observations in part (a) and (b) to show that the Diophantine equation
x2 ` y 2 “ 3z 2 does not have a solution.
By the first equation, the solution x must be of the form 2, 5, 8, 11, 14, 17, 20, 23,
and so on. The smallest of these solutions that also satisfy the second congru-
ence is 8. Therefore, positive integers that solve the first two congruences
equations are given by 8, 23, 38, and so on, as we need to count by 15 to get
8.5 The Chinese Remainder Theorem 199
to the same remainders modulo 3 and modulo 5. Now we can check that 23
is the smallest positive integer that satisfies all three congruences. Of course,
the solution is not unique. We can add multiples of 105 “ lcmp3, 5, 7q to get
other solutions to the congruence equations. So the solution is any integer x
such that x ” 23 pmod 105q.
The ad hoc solution of the previous example is a bit undesirable, since we
cannot proceed in the same fashion when the moduli get large. The proof of
the Chinese Remainder Theorem tells you how to systematically find solutions
to such congruence equations.
Theorem 8.25 (Chinese Remainder Theorem). Let m1 , m2 , . . . , mn be n pair-
wise coprime integers greater than 1, where n is an integer such that n ě 2. Let
r1 , r2 , . . . , rn be arbitrary integers. Let m denote the product m “ m1 m2 ¨ ¨ ¨ mn .
Then there exists an integer x such that
x ” r1 pmod m1 q,
x ” r2 pmod m2 q,
..
.
x ” rn pmod mn q.
x ” x1 pmod mi q
x ” x1 pmod mq,
where m “ lcmpm1 , m2 , . . . , mn q “ m1 m2 ¨ ¨ ¨ mn .
Example 8.26. Suppose that we are given three moduli m1 “ 10, m2 “ 11,
and m3 “ 13. We look for the smallest positive integers satisfying the system
of congruences
The integer x “ ´443 solves the system of congruences, but it is not posi-
tive. We know from the previous theorem that all solutions must be congruent
modulo m “ 1430. Therefore,
is the smallest positive integer satisfying 987 ” 7 pmod 10q, 987 ” 8 pmod 11q,
and 987 ” 12 pmod 13q.
8.5 The Chinese Remainder Theorem 201
Exercises
8.38. Determine the smallest positive integer x satisfying the system of con-
gruences
x ” 3 pmod 25q,
x ” 5 pmod 26q,
x ” 7 pmod 27q.
8.40. Hilary had a very successful recital. Her friend Mary was very impressed
that every single chair was taken. So Mary asked Hilary how many chairs were
in the concert hall. Hilary never counted them, but recalled that 2 years ago,
they arranged the chairs in rows of twenties, but the last row contained just
six chairs. Last year, they arranged it such such each row contained 21 chairs,
but then the last row had only five chairs. This year they arranged it such
that each row contained 23 chairs, except the last row contained four chairs.
The number of chairs was the same each year and according to the fire marshal
the concert hall can hold at most 2000 people. Use the Chinese Remainder
Theorem to determine how many people attended Hilary’s recital.
8.41. Suppose that you are given three pairwise coprime integer moduli m1 ,
m2 , and m3 , three integer residues r1 , r2 , and r3 , and your goal is to find an
integer x satisfying
x ” r1 pmod m1 q,
x ” r2 pmod m2 q,
x ” r3 pmod m3 q.
Your friend Joe suggests that you should instead solve three much simpler
systems of congruences, namely find integers s1 , s2 , and s3 such that
, , ,
s1 ” r1 pmod m1 q . s2 ” 0 pmod m1 q . s3 ” 0 pmod m1 q .
s1 ” 0 pmod m2 q s2 ” r2 pmod m2 q s3 ” 0 pmod m2 q
s1 ” 0 pmod m3 q s2 ” 0 pmod m3 q s3 ” r3 pmod m3 q
- - -
Joe claims that the sum of the three solutions is congruent the solution x of
the original system of congruences:
x ” s1 ` s 2 ` s 3 pmod mq
(a) Show how to find the solutions s1 , s2 , and s3 to the simpler system of
congruences.
202 8 Number Theory
where the product ranges over all primes dividing n. If n “ pq is the product
of two distinct primes p and q, then ϕpnq “ pp ´ 1qpq ´ 1q.
Key Generation:
• Alice selects two distinct large prime numbers p and q, and computes
their product n “ pq.
• Alice publishes the pair P “ pe, nq, her public key. She carefully guards
as a secret the factorization of n, the product ϕpnq “ pp ´ 1qpq ´ 1q, the
integer k, and her secret key S “ pd, nq.
8.6 The RSA Public Key Cryptosystem 203
C ” Me pmod nq.
C d ” M ed pmod nq.
Example 8.27. Suppose that Alice chooses the primes p “ 991 and q “ 1087.
Calculating the product n “ pq of these primes yields n “ 1, 077, 217. The
totient function ϕpnq has the value ϕpnq “ pp ´ 1qpq ´ 1q “ 990 ¨ 1086 “
1, 075, 140. As an encoding exponent, she cannot select e “ 3 or e “ 5, since
they are not coprime to ϕpnq. Let us suppose that she selects e “ 7 as the
encoding exponent. Using the Euclidean algorithm, she determines that
Her public RSA key is pn, eq “ p1077217, 7q. She keeps her decoding exponent
d “ 307, 183 and ϕpnq secret.
If Bob wants to send her the message M “ 127, then he can calculate
and send Alice the ciphertext C “ 955, 441. Alice can then decode C by raising
it do the d-th power modulo n. So she calculates
The choice of e and d ensures that Alice decodes what Bob has sent.
An attacker knows Alice’s public key pn, eq and may observe the ciphertext
C, but solving the equation M ” C e pmod nq for M is believed to be difficult
when n is large. Alice can easily solve the equation, since she has extra in-
formation such as the decoding exponent d. Since M ÞÑ M e pmod nq is easy
to compute, but its inverse is difficult to find without extra information, it is
called a trapdoor function.
204 8 Number Theory
Correctness of RSA. We will now prove the claim that Alice always obtains
Bob’s message. We will need a slightly modified version of Fermat’s little
theorem to prove this result.
Proposition 8.28 (Fermat). Let p be a prime. If a is an integer that is not
divisible by p, then
ap´1 ” 1 pmod pq.
Proof. We showed in Exercise 4.28 that ap ” a pmod pq holds for all integers a.
The hypothesis implies that gcdpa, pq “ 1; hence, there exist integers x and y
such that ax ` py “ 1. Therefore, ax ” 1 pmod pq. It follows from ap ” a
pmod pq that ap´1 ” xap ” xa ” 1 pmod pq holds.
M ed ” M pmod nq
hold. Indeed, p and q are distinct primes, so gcdpp, qq “ 1, and the afore-
mentioned congruences imply M ed ” M pmod nq by the Chinese Remainder
Theorem.
If M ” 0 pmod pq, then certainly M ed ” M pmod pq. If M ı 0 pmod pq,
then M p´1 ” 1 pmod pq by Proposition 8.28; hence,
Exercises
8.43. Let p “ 23 and q “ 31 be primes. Can Alice use the public key ppq, eq “
p713, 3q as her RSA public key? Explain why or why not.
8.44. Let p “ 23 and q “ 29 be primes. Alice decides to use the public key
ppq, eq “ p667, 3q as her RSA public key. Calculate a valid decoding exponent
d. Show all your work.
8.7 Notes 205
8.45. Alice chooses the primes p “ 79 and q “ 97 and forms the product
n “ pq. As an encoding exponent, she chooses e “ 11. Explicitly determine
the following parameters of her RSA cryptosystem.
(a) Compute Alice’s public key pn, eq.
(b) Determine the value of the totient function ϕpnq.
(c) Compute a decoding exponent d satisfying ed ´ kϕpnq “ 1 for some integer
k using the Euclidean algorithm.
(d) Encode the message M “ 42 into C ” M e pmod nq.
(e) Decode the message C “ 24 using M ” C d pmod nq.
8.46. Let n be the product of two odd primes p and q. Show that for any
choice of encoding exponent e, there are at least nine messages that are not
concealed by the RSA public key cryptosystem, meaning that there are nine
different messages such that M e ” M pmod nq. [Hint: Find fixed-points of
x ÞÑ xe pmod pq and x ÞÑ xe pmod qq and use the Chinese Remainder Theo-
rem] (Source: G.R. Blakley and I. Borosh)
8.47. Alice likes to use small encoding exponents such as e “ 3 for her public
RSA key pn, eq, so that her friends do not have high computational costs when
messaging her. Explain the cryptographic disadvantage of choosing a small
encoding exponents. [Hint: Regardless of the exponent, we should exclude 0
and 1 as a message, as 0e ” 0 pmod nq and 1e ” 1 pmod nq. Larger m are in
general not fixpoints of the encoding map m ÞÑ me pmod nq, but may be still
easily decoded if the encoding exponent is small.]
8.48. Alice tells a friend that she creates the n for her RSA public key pn, eq
by looking at a website that gives the 10 largest primes with a given number
of bits. She did not realize that one can easily find the prime factors p and q of
n using this information. Explain how an attacker can determine a decoding
exponent d if the factorization of n into primes p and q is known.
8.49. Alice was not careful and accidentally revealed the value of the totient
function ϕpnq of the integer n in her RSA public key pn, eq. Since neither n “ pq
and ϕpnq “ pp ´ 1qpq ´ 1q directly reveals the primes p and q, she decides not to
worry. Her friend Bob tells her that a cryptanalyst can find the primes p and q
knowing n and ϕpnq. Explain how to find the primes p and q given the values
n and ϕpnq. [Hint: Form the quadratic polynomial px ´ pqpx ´ qq “ x2 ` bx ` c.
Show how to express b and c in terms of ϕpnq, n, and constants. Deduce a
simple formula for p and q given n and ϕpnq.]
8.50. Let n “ 2491 and ϕpnq “ 2392. Use the method from the previous
exercise to find the prime factors p and q of n “ pq.
8.7 Notes
There are many excellent books on number theory. At an elementary level,
there is a very readable and beautifully illustrated introduction to number
206 8 Number Theory
207
Chapter 9
Sums
The art of doing mathematics consists in finding that special case
which contains all the germs of generality.
— David Hilbert
13 ` 23 ` ¨ ¨ ¨ ` n3 “ ?
Our main tool will be a discrete analogue of calculus. It offers a difference op-
erator that is a discrete version of the derivative and an antidifference operator
that is a discrete version of the indefinite integral. The approach is to take a
sum and use the antidifference operator to turn it into a telescoping sum. We
begin by illustrating this approach using a simple example.
How can we find a closed form solution? We can always try to evaluate the
sum for small values of n in the hope to discover a pattern. You might be able
to succeed in simple cases such as this one, but your mileage may vary. We
use a different approach that transforms the given sum into a telescoping sum.
This is everyones favorite kind of sum, since all but two terms cancel.
So let’s see how we can transform beastly sums into beautiful telescoping
sums. Let us denote the summands of our sum by
1
f pkq “ .
kpk ` 1q
If we can find a function F pkq such that f pkq can be expressed by its difference
f pkq “ F pk ` 1q ´ F pkq,
What is the benefit? Well, it turns out that the latter sum is of the telescoping
kind. Indeed, using commutativity, we get
n
ÿ n
ÿ n
ÿ
pF pk ` 1q ´ F pkqq “ F pk ` 1q ´ F pkq.
k“1 k“1 k“1
Canceling like terms allows to collapse the sum to merely two remaining terms
n
ÿ
pF pk ` 1q ´ F pkqq “ F pn ` 1q ´ F p1q.
k“1
of the function f , and then express the definite integral in the form
żb
f pxq dx “ F pbq ´ F paq.
a
Our approach will be essentially the same. If you want to evaluate a definite
sum
ÿb
f pkq,
k“a
then you need to find the antidifference F pxq of f pxq, which is the analogue of
the indefinite integral. Then
b
ÿ
f pkq “ F pb ` 1q ´ F paq.
k“a
As expected, this broad-brush analogy has its limits and the devil is in the
details. Many of the rules that you know from calculus have their analogon, but
are often subtly different. Before we can embark on finding the closed form
of sums, we need to learn the analog of the differential operator d{dx. The
discrete version of d{dx is the difference operator Δ. We will then show how to
find the difference of any polynomial. This will lead us to falling factorials and
Stirling numbers. Then we are finally ready to state the Fundamental Theorem
of Summation, our main tool in finding the closed form of many sums.
1 If you have not taken calculus yet, then simply skip to the next section.
212 9 Sums
d f px ` hq ´ f pxq
f pxq “ lim .
dx hÑ0 px ` hq ´ x
By contrast, the difference calculus that we develop here uses the somewhat
crude h “ 1 approximation to this differential operator. Indeed, we have
f px ` 1q ´ f pxq
“ Δf pxq.
px ` 1q ´ x
Since Δ does not use a limit, it is conceptually much simpler than its cousin
d
d{dx from differential calculus. Geometrically, dx f pxq has the interpretation
as the slope of the tangent to f pxq at the point x, whereas Δf pxq has the
interpretation as the slope of a secant line, see Fig. 9.1.
Example 9.1. The constant function f pxq “ c, where c is a real number, has
zero difference,
Δf pxq “ f px ` 1q ´ f pxq “ c ´ c “ 0.
Example 9.2. The function f pxq “ x has a constant difference,
Δx “ px ` 1q ´ x “ 1.
9.2 Difference Calculus 213
The next few examples stress the difference between the differential operator
and the difference operator.
Example 9.3. The function f pxq “ x2 has the difference
Δx2 “ px ` 1q2 ´ x2 “ 2x ` 1.
Δ|x| “ rx ě 0s ´ rx ă 0s,
where r¨s denotes the Iverson bracket. In other words, Δ|x| has the value 1
for all nonnegative integer arguments and the value ´1 for all negative integer
arguments.
We suggest that you construct more examples to gain familiarity with the
difference operator. In particular, you should be familiar with differences of
small degree polynomials and differences of exponential functions.
Rules. The difference operator follows rules that are very similar to the rules
governing the differential operator from calculus. The first proposition shows
that the difference operator Δ is a linear operator.
Proposition 9.7. Let f and g be functions from the set of integers to the set
of real numbers, and let c be a real number. Then
(a) Δpcf q “ c Δf ,
(b) Δpf ` gq “ Δf ` Δg,
Proof.
(a) The difference operator is homogeneous in the sense that
holds.
214 9 Sums
holds.
Example 9.8. It follows from Examples 9.1–9.4 and the linearity of the differ-
ence operator Δ that we can determine the difference Δf pxq for any polynomial
of degree 3 or less. For instance, if f pxq “ x3 ´ 2x ` 1, then
The difference operator also satisfies product and quotient rules. However,
the form of these rules differs slightly from the versions of differential calculus,
as they involve a shift operator. The shift operator S is defined by
Sf pxq “ f px ` 1q.
Proposition 9.9. Let f and g be functions from the set of integers to the set of
real numbers. Then the difference operator satisfies the following three product
rules:
These are reminiscent of the product rule for the derivative, but involve either
an extra term or a shift operator.
Proof. Let us prove the first product rule. By definition, the left-hand side of
Eq. (9.1) yields
Δpf gq “ f px ` 1qgpx ` 1q ´ f pxqgpxq.
Expanding the right-hand side of the Eq. (9.1) yields
Of course, we could have used any of the other two product rules to obtain the
same result.
Proposition 9.11. Let f and g be functions from the set of integers to the set
of real numbers. Then the difference operator satisfies the quotient rule
ˆ ˙
f gΔf ´ f Δg
Δ “ .
g gSg
Proof. By definition
ˆ ˙
f f px ` 1q f pxq f px ` 1qgpxq ´ f pxqgpx ` 1q
Δ “ ´ “
g gpx ` 1q gpxq gpxqgpx ` 1q
f px ` 1qgpxq ´ f pxqgpxq ` f pxqgpxq ´ f pxqgpx ` 1q
“ .
gpxqgpx ` 1q
Example 9.12. Let f pxq “ 2x and gpxq “ x2 . Thus, we have Δ2x “ 2x and
Δx2 “ 2x ` 1. It follows from the quotient rule that
ˆ x˙
2 x2 2x ´ 2x p2x ` 1q
Δ 2
“
x x2 px ` 1q2
2x px2 ´ 2x ´ 1q
“ .
x2 px ` 1q2
216 9 Sums
Exercises
9.1. Calculate the following differences using linearity of the difference operator
Δ and the results derived in the examples of this section.
(a) Δpx2 ` xq.
(b) Δp2x2 ` 3x ` 2q.
(c) Δp2x3 ` 5x2 q.
(d) Δpx3 ` x2 ` x ` 1q.
9.2. Let x denote an integer. Recall that the x-th harmonic number Hx is
given by Hx “ 1 ` 12 ` 13 ` ¨ ¨ ¨ ` x1 . Calculate ΔHx .
9.6. Explicitly determine the result of applying the difference operator Δ twice
to a function f pxq. In other words, determine Δ2 f pxq. Determine Δ3 f pxq as
well.
9.8. Use the second product rule and linearity of Δ to determine ΔpHx x ´ xq.
9.9. Use the second product rule and the fact that Δx2 “ 2x ` 1 to calculate
Δx4 “ Δpx2 ¨ x2 q.
Δxk “ kxk´1 .
Proof.
(a) Existence. We are going to prove the claim by induction on the degree n.
If the polynomial ppxq has degree n ď 0, then it is a constant and can be
written in the form ppxq “ cx0 for some uniquely determined real number
c.
Let us assume that the claim holds for all polynomials of degree n or less.
We will show that it must hold for polynomials of degree n ` 1. If ppxq is
a polynomial of degree n ` 1 with leading coefficient an`1 , then
is a polynomial of degree
řn n. By induction hypothesis, rpxq can be written
in the form rpxq “ k“0 ak xk for some coefficients a0 , . . . , an . Therefore,
řn`1
we can conclude that ppxq can be written in the form k“0 ak xk .
(b) Uniqueness. Seeking a contradiction, let us suppose that ppxq is a polyno-
mial of smallest possible degree that has two different representations
n
ÿ n
ÿ
ak xk “ ppxq “ bk x k
k“0 k“0
Since n was the smallest degree for which representations can differ, we
can conclude that pa0 , a1 , . . . , an´1 q “ pb0 , b1 , . . . , bn´1 q. Thus, the two
representation of ppxq are actually the same, contradicting the assumption
of non-uniqueness.
9.3 Falling Factorial Powers 219
Remark 9.15. If you are familiar with linear algebra, then you will notice that
the previous proposition simply states that the polynomials in the set
of monomials is that the falling factorial powers are manipulated with ease
when using the difference operator Δ. In the next section, we will see how
one can explicitly express any monomial xn in terms of the falling factorial
powers.
We can extend the falling factorial powers to negative exponents by defining
1
x´n “
px ` 1qpx ` 2q ¨ ¨ ¨ px ` nq
for all integers n ą 0. This definition ensures that
xk`1
“x´k
xk
holds for all integers k. The next proposition shows that the difference of
negative factorial powers is once again a multiple of a negative factorial power.
Proposition 9.16. For all integers k, we have
Δxk “ kxk´1 .
We have Δx0 “ 0x´1 . Thus, the claim holds for all integers k that are not
positive. For positive k, the claim follows from Proposition 9.13.
We can define two important functions with the help of factorial falling
powers. The factorial x! of a nonnegative integer x is defined as
x! :“ xx “ xpx ´ 1q ¨ ¨ ¨ 2 ¨ 1.
This definition is a bit broader than you might expect, since it even makes
sense when x is a real number such as x “ 1{2. For instance,
1 1
ˆ1˙ ` ˘ `1 ˘
2 2 2 ´1 2 ´2 1
“ “ .
3 3! 16
We will exploit this generality in the definition a bit later in Newton’s formula.
The next proposition shows how the difference operator behaves when ap-
plied to the top argument of the binomial coefficient.
Proposition 9.17. We have
ˆ ˙ ˆ ˙
x x
Δ “ ,
k k´1
Proof. By definition,
Exercises
9.12. Prove that xk`1 ` kxk “ xxk .
px ` 1qk xk xk´1
9.13. Prove that “ `
k! k! pk ´ 1q!
9.14. The factorial x! of a nonnegative integer x is defined as x! :“ xx . (a)
Calculate Δx!, and (b) find a function F pxq such that ΔF pxq “ x!.
9.15.
(a) Use the binomial theorem to show that
n´1
ÿˆ ˙
n n k
Δx “ x .
k“0
k
(b) Use part (a) to obtain an explicit expression for Δx4 by evaluating and
simplifying the binomial coefficients.
9.4 Stirling Numbers 221
(c) Use part (a) to obtain an explicit expression for Δx5 by evaluating and
simplifying the binomial coefficients.
řn
9.16. Let n be a positive integer. Let ppxq “ k“0 ak xk be a polynomial of
degree n with leading coefficient an . Show that Δppxq is a polynomial of degree
n ´ 1 with leading coefficient nan .
řn
9.17. Let n be a positive integer and ppxq “ k“0 ak xk a polynomial of degree
n with leading coefficient an . Let Δn denote applying the difference operator n
times. Prove by induction that applying the Δ operator n times to ppxq yields
the constant polynomial
Δn ppxq “ n!an .
This result is sometimes called the Fundamental Theorem of Difference
Calculus. Hint: Use the previous exercise.
9.18. We can apply the difference operator n times and denote the resulting
operator by Δn . A direct calculation of Δn f pxq can be tedious. Show that
n ˆ ˙
n
ÿ
n´k n
Δ f pxq “ p´1q f px ` kq.
k“0
k
[Hint: You can express Δn in the form Δn “ pS ´ Iqn , where S is the shift
operator and I is the identity operator.]
holds for all polynomials f pxq of degree at most n. This is Newton’s analogue
of a Taylor series.
9.20. Determine the differences of the function f pxq “ 4xpx ´ 1qpx ´ 2qpx ´ 3q.
(a) Δf pxq.
(b) Δ2 f pxq.
(c) Δ3 f pxq.
(d) Δ4 f pxq.
In the previous section, we showed that we can express the powers xn using
the falling factorial powers. In fact, it follows from Proposition 9.14 that there
exist real numbers Spn, kq such that
n
ÿ
xn “ Spn, kqxk . (9.4)
k“0
The numbers Spn, kq are called the Stirling numbers of the second kind.
The Stirling numbers of the second kind are also denoted as
" *
n
Spn, kq “ .
k
This notation is a good mnemonic, since these numbers count the number of
ways a set with n elements can be partitioned into k nonempty subsets, as we
will see later. We will use the more compact notation Spn, kq whenever many
formulas need to be manipulated.
The next proposition shows how to quickly calculate the Stirling numbers
of the second kind.
Proposition 9.19. The Stirling numbers of the second kind satisfy Spn, nq “ 1
for all nonnegative integers n,
Sp0, kq “ Spk, 0q “ 0 for k ą 0
and the recurrence relation
Spn, kq “ Spn ´ 1, k ´ 1q ` kSpn ´ 1, kq
for all positive integers n and all integers k in the range 1 ď k ď n ´ 1.
Proof. The claim has four different parts that we will derive one by one.
(a) A comparison of the coefficients of xn on both sides of (9.4) shows that
Spn, nq “ 1 holds for all nonnegative n.
(b) A comparison of the constant terms on both sides of (9.4) shows that
Spn, 0q “ 0 for n ą 0, since the constant terms of all polynomials xk are 0
when k ą 0.
(c) Since x0 “ x0 “ k Sp0, kqxk , we have Sp0, 0q “ 1 and Sp0, kq “ 0 for all
ř
positive integers.
(d) For the recurrence relation, we are going to express xn in the form x ¨ xn´1 .
We have
n´1
ÿ
xn “ x ¨ xn´1 “ Spn ´ 1, kqx xk
k“0
By definition, xk`1 “ xk px ´ kq, and adding kxk to both sides yields
xxk “ xk`1 ` kxk . It follows that
n´1
ÿ n´1
ÿ
xn “ Spn ´ 1, kqxk`1 ` Spn ´ 1, kqkxk
k“0 k“0
ÿn n´1
ÿ
“ Spn ´ 1, ´ 1qx ` Spn ´ 1, kqkxk
“1 k“1
9.4 Stirling Numbers 223
Table 9.1: The Stirling numbers of the second kind Spn, kq.
nzk 0 1 2 3 4 5
0 1 0 0 0 0 0
1 0 1 0 0 0 0
2 0 1 1 0 0 0
3 0 1 3 1 0 0
4 0 1 7 6 1 0
5 0 1 15 25 10 1
Comparing the coefficients of the latter expression with (9.4) yields the
recurrence relation.
The recurrence relation from the previous proposition is similar to the re-
currence relation of the binomial coefficients that governs the construction of
Pascal’s triangle. Before computing “Stirling’s triangle,” let us have a look at
a small example.
Therefore, x2 “ x2 ` x1 .
Proposition 9.19 allows one to compute the Stirling numbers for small n
and k. We are going to set up a “Stirling’s triangle” that contains the coeffi-
cients Spn, kq in the n-th row. Given the values of the coefficients Spn ´ 1, kq
of row n ´ 1, the recurrence Spn, kq “ Spn ´ 1, k ´ 1q ` kSpn ´ 1, kq allows us
to quickly obtain the values of row n. The results are compiled in Table 9.1
for Stirling numbers up to n “ 5.
In this chapter, the main purpose of Stirling numbers is to express monomi-
als in terms of falling factorial powers. We saw that it is fairly straightforward
to calculate the values of Stirling numbers of the second kind. We will discuss
combinatorial properties of Stirling numbers in Sect. 11.5.
224 9 Sums
Exercises
9.21. Calculate
(the following Stirling numbers of the second kind:
(a) Sp7, 3q “ 73 ,
(b) Sp7, 5q “ 75 ,
(
(c) Sp8, 3q “ 83 ,
(
(d) Sp8, 5q “ 85 .
(
9.22. Derive from Eq. (9.4) explicit expressions for monomials of small degree
in terms of falling factorials by explicitly calculating the Stirling numbers of
the second kind for the following monomials:
(a) x3
(b) x4
(c) x5
(d) x6
(e) x7
9.23. Prove by induction that Spn, 1q “ 1 holds for all n ě 1.
řn´1
9.24. Prove by induction that Spn, n ´ 1q “ k“1 k holds for all positive
integers n.
9.25. Verify that the number of different partitions of the set t1, 2, 3, 4u into
nonempty sets is equal to
" * " * " * " *
4 4 4 4
Sp4, 1q ` Sp4, 2q ` Sp4, 3q ` Sp4, 4q “ ` ` ` .
1 2 3 4
9.26. Prove that the upper bound
ˆ ˙
1 n n´k
Spn, kq ď k
2 k
holds for all integers n and k satisfying n ě 2 and 1 ď k ď n ´ 1.
9.27. Prove that the lower bound
1 2
pk ` k ` 2qk n´k´1 ´ 1 ď Spn, kq
2
holds for all integers n and k such that n ě 2 and 1 ď k ď n.
The sum on the right-hand side contains more terms, but is very easy to eval-
uate! Indeed, the next theorem shows that all but two terms cancel.
Theorem 9.21 (Fundamental Theorem of Summation). Let f be a function
from the set of integers to the set of real numbers, and let F be an antidifference
of f . Then
ÿb
f pkq “ F pb ` 1q ´ F paq.
k“a
where the intermediate terms F pa ` 1q, F pa ` 2q, . . . , F pbq all cancel, since they
are added once and subtracted once.
It might be instructive to expand on the aforementioned proof using a small
example.
Example 9.22. Suppose that we want to evaluate the sum
4
ÿ
f pkq “ f p1q ` f p2q ` f p3q ` f p4q.
k“1
So the entire point of rewriting the sum in terms of antidifferences should now
be clear! Indeed, if we remove all the canceling terms in the middle, we get the
following simple expression for the sum on the left-hand side
The aforementioned theorem asserts that the same approach works for sums
with many more terms!
So let us see how we can use the theorem to evaluate some actual sums.
1 4 1
F pkq “ k “ kpk ´ 1qpk ´ 2qpk ´ 3q.
4 4
By the Fundamental Theorem of Summation, we have
n`2
ÿ pn ` 3qpn ` 2qpn ` 1qn
k 3 “ F pn ` 3q ´ F p3q “ .
k“3
4
How can we find antidifferences? Known difference relations are our main
source, at least initially. For instance, we have shown that
Figure 9.2: The figure shows a selection of antidifferences. We omitted the addition
of constants C on the right-hand side
Example 9.24. We begin with the sum of the first n positive integers
1 ` 2 ` 3 ` ¨ ¨ ¨ ` n.
Most likely you are already aware how to evaluate this sum. However, the
simplicity of this example will allow you to focus on the method. We can
formulate this problem as the sum
n
ÿ n
ÿ
f pkq “ k.
k“1 k“1
Incidentally, this is the formula that Karl Friedrich Gauss supposedly derived
in elementary school when he was asked by his teacher to sum the first 100
positive integers.
228 9 Sums
Geometric series are another standard example of sums that you will fre-
quently encounter in practice. We will cover them in the next example.
Example 9.25. Let α be a real number such that α ‰ 1. For integers a and
b satisfying a ď b, we want to evaluate the sum
b
ÿ
αk “ αa ` αa`1 ` αa`2 ` ¨ ¨ ¨ ` αb .
k“a
In particular, if α “ 2 then
n
ÿ
2k “ 2n`1 ´ 1.
k“0
Such sums of geometric series are for instance frequently used in the analysis
of fast Fourier transform algorithms or randomized algorithms.
If we want to handle more elaborate sums, then we need to know more about
antidifferences. We know the antidifference of xk for all integers k, except when
the exponent k “ ´1. We need to introduce harmonic numbers so that we can
fill the gap for k “ ´1.
We define the x-th harmonic number Hx as
1 1
Hx “ 1 ` ` ¨¨¨ ` ,
2 x
for all nonnegative integers x. Then
1
ΔHx “ “ x´1
x`1
In other words, Hx´1 is the discrete analog of the logarithm, which explains
why harmonic numbers occur quite frequently in the analysis of algorithms.
Proposition 9.26. For any integer k, we have
$
& 1 xk`1 ` C if k ‰ ´1
Δ´1 xk “ k ` 1
%H ` C if k “ ´1
x
where Spn, kq denotes the Stirling number of the second kind and C is a constant
function when restricted to the integers.
Proof. We have
˜ ¸
n n n
ÿ Spn, kq k`1 ÿ Spn, kq ÿ
Δ x `C “ Δxk`1 “ Spn, kqxk “ xn ,
k“0
k`1 k“0
k ` 1 k“0
where the last equality follows from the definition of the Stirling numbers.
Applying the antidifference operator to both sides of the equation yields the
claim.
Example 9.28. We now solve the motivating problem of this chapter: Find
the sum
13 ` 23 ` ¨ ¨ ¨ ` n3
A similar approach works sums over functions f pxq that are polynomials of low
degree. We will later see a more convenient way of determining sums of high
degree powers.
230 9 Sums
Exercises
9.28. Let f be a function from the set of integers to the set of real numbers.
Show that an antidifference F pxq of f pxq is not uniquely determined.
9.29. Let f be a function from the set of integers to the set of real numbers
such that f pkq “ 0 for all negative integers k.
(a) Show that the partial sum
x´1
ÿ
F pxq “ f pxq
k“0
is an antidifference of f pxq.
(b) Explain why the partial sum F pxq given in part (a) is in general an unde-
sirable version of the antidifference Δ´1 f pxq.
ˆ ˙
1 1
9.30. Show that Δ´1 x
“ ´ x´1 ` C
2 2
9.31. Use the Fundamental Theorem of Summation to show that the sum of
the first n odd numbers yields n2 ,
1 ` 3 ` 5 ` ¨ ¨ ¨ ` p2n ´ 1q “ n2 .
F 1 ` F 2 ` ¨ ¨ ¨ ` Fn
Sk “ Δ´1 Tk .
1 ¨ 1! ` 2 ¨ 2! ` 3 ¨ 3! ` ¨ ¨ ¨ ` pn ´ 1q ¨ pn ´ 1q!
9.38.
is simply the type of sum that we have studied in Example 9.24 in reverse
order.
3 In idiomatic Ruby, one would replace the for loops by iterators over a range, but we
opted to use the notation that most programmers will understand, even if they are not
familiar with Ruby.
9.6 Analysis of Programs 233
in-place array manipulations and a better pivot selection. Since our goal is to merely illustrate
how summation techniques occur in the analysis of algorithms, this simple version will do.
234 9 Sums
and consequently
n´2
ÿ
pn ´ 1qCn´1 “ pn ´ 1qpn ´ 2q ` 2 Ck .
k“0
9.7 Notes
The techniques described in this chapter have a long history. An early mono-
graph by Boole [10] describing the Calculus of Finite Differences had been
published in 1860. Other early works include the comprehensive monographs
by Milne-Thomson [61] and Jordán [42], and all are still very valuable today.
Many books on discrete mathematics give a brief introduction to the Calculus
of Finite Differences, since it has so many applications in the analysis of com-
puter programs. Our exposition has been influenced by Aigner [4], Graham,
Knuth, and Patashnik [30], Jordán [42], and Stopple [75]. The recent interest
in calculus without limits sparked a new renaissance for the Calculus of Finite
Differences under the moniker “quantum calculus,” see Kac and Cheung [44].
The material of this chapter finds applications in the analysis of algorithms,
see for example Knuth [48–51]. Our analysis of quicksort is adapted from [50],
see also [4].
Chapter 10
Asymptotic Analysis
We could, of course, use any notation we want; do not laugh at
notations; invent them, they are powerful. In fact, mathematics is,
to a large extent, invention of better notations.
— Richard Feynman, The Feynman Lectures on Physics, Vol. 1
In this chapter, our goal is to compare a function f pnq with some simple func-
tion gpnq so that we can understand its order of growth as n approaches infinity.
We discuss asymptotic equality „, asymptotic tightness Θ, asymptotic upper
bounds O and o, and asymptotic lower bounds Ω and ω. These asymptotic
notations are widely used in computer science, mathematics, and related disci-
plines. These notations allow us to quickly determine the order of growth of a
function without forcing us to become imprecise. We briefly illustrate the use
of asymptotic notations in the analysis of algorithms.
holds. By definition of the limit, this means that for each real number ą 0,
there exists a positive integer n such that
ˇ ˇ
ˇ f pnq ˇ
ˇ gpnq ´ 1ˇ ă (10.1)
ˇ ˇ
holds for all n ě n . As the notation suggests, the positive integer n depends
on the choice of . Informally, this means that for large n, the fraction f pnq{gpnq
gets arbitrarily close to 1.
Another way to interpret the inequality (10.1) is that two functions f and
g are asymptotically equal if and only if the relative error pf pnq ´ gpnqq{gpnq
between these functions vanishes for large n. Essentially, this means that the
functions f and g have the same growth for large n.
Let us see why this notation is popular, especially in analysis, combinatorics,
and number theory.
Example 10.1. Suppose that we are given the function
?
n ln n ` n ` ln n ` 1517 ln ln n
f pnq “ .
n
If we are only interested in the growth of the function f for large n, then it
is important to realize that most of the terms of f do not have a significant
contribution! Indeed, the three terms
?
n ln n 1517 ln ln n
lim “ 0, lim “ 0, lim “0
nÑ8 n nÑ8 n nÑ8 n
all vanish for large n, so only the term n ln n{n “ ln n has an impact on the
growth of the function f pnq for large n. The asymptotic equality
f pnq „ ln n
expresses that f pnq essentially grows like the natural logarithm ln n. Since ln n
is shorter and more familiar than f pnq, it is the preferred way to describe the
behavior of f pnq for large arguments n.
Another example is the Harmonic number Hn that is defined by a sum
that does not have a simple closed form. The asymptotic equality nevertheless
allows us to describe the growth of Hn by comparing it to a familiar function.
1 1
Example 10.2. The n-th Harmonic number Hn “ 1 ` 2 ` ¨¨¨ ` n is asymp-
totically equal to the natural logarithm ln n,
Hn „ ln n.
Indeed, since the inequalities lnpn ` 1q ď Hn ď 1 ` ln n hold, dividing by ln n
and taking the limit yields for the logarithmic terms
lnpn ` 1q n 1 ` ln n
lim “ lim “ 1 and lim “ 1,
nÑ8 ln n nÑ8 n ` 1 nÑ8 ln n
where we used l’Hôpital’s rule in the calculation of the first limit. Thus, it
follows from the squeeze theorem for limits that
Hn
lim “ 1,
nÑ8 ln n
which proves that Hn „ ln n. In other words, the Harmonic numbers grow like
the natural logarithm for large n. Relating a function such as Hn to the more
familiar logarithmic function ln n certainly helps one to understand the growth
of Hn as n approaches infinity.
10.1 Asymptotic Equality 239
ppxq „ am xm .
Then
f pn ` cq ´ f pnq „ cf 1 pnq.
Proof. By the mean value theorem of calculus, there exists a real number θ in
the range 0 ď θ ď c such that
cf 1 pnq cf 1 pn ` cq
lim “1 and lim “ 1.
nÑ8 cf 1 pnq nÑ8 cf 1 pnq
f pn ` cq ´ f pnq
lim “ 1,
nÑ8 cf 1 pnq
Indeed, choose f pxq “ k lnpxq. Then f 1 pxq “ k{x. As f 1 pxq “ k{x is monoton-
ically decreasing and nonzero, and
f 1 pn ` 1q n
lim 1
“ lim “ 1,
nÑ8 f pnq nÑ8 n ` 1
where we have used in the last equality that the limit of a product is the product
of the limits of its factors. Since the first and last limit is 1 by hypothesis, we
can conclude that
f1 pnq g1 pnq
lim “ lim ,
nÑ8 f2 pnq nÑ8 g2 pnq
that follows!
242 10 Asymptotic Analysis
We can use similar tricks when the numerator and denominators contain
radicals.
Exercises
10.1. Suppose that f , g, and h are functions from the set of positive integers
to the set of real numbers that are nonzero for all but a finite number of
arguments. Show that
(i) f „ f ,
(ii) f „ g if and only if g „ f ,
(iii) f „ g and g „ h implies f „ h.
This means that „ is an equivalence relation on the set of functions that are
nonzero for all but a finite number of arguments.
10.2. As an important reminder that „ is an equivalence relation only on the
set of functions that are nonzero for all but a finite number of arguments, show
that there cannot be a function f such that f „ 0 or 0 „ f .
10.3. Ernie and Bert study the functions f pnq “ n2 ` 2n and gpnq “ n2 .
Ernie claims that the functions are asymptotically equal, so f „ g. Bert insists
that f can never be asymptotically equal to g, since they always differ quite
significantly, namely f pnq ´ gpnq ě 2n for all n ě 1. Explain why one is right
and why the other is wrong.
10.4. Let k and be positive integers. Show that
1 ` nk
„ nk´ .
n
10.5. For a positive integer n, let dpnq denote the number of divisors n. For
example, dp6q “ 4, since 6 has the divisors 1, 2, 3, and 6.
(a) Show that
n ˆY ] Z ^˙
ÿ n n´1
dpnq “ ´ .
k“1
k k
(b) The function dpnq exhibits some very erratic behavior that is difficult to
analyze. However, the average of the first n values of the function d is
easier to analyze. Show that
n
1 ÿ
dpkq „ ln n.
n k“1
10.6. Let a be a real constant satisfying a ă 1. Show that
exppna q „ expppn ` 1qa q.
10.7. Show that
4n
ˆ ˙
2n
„? .
n πn
10.8. Show that sinp1{nq is asymptotically equal to 1{n.
10.9. Show that lnpn!q is asymptotically equal to n ln n.
10.2 Limit Superior and Limit Inferior 243
Upper and Lower Envelope. Let f be a function from the set of positive
integers to the set of real numbers. If f oscillates between different values, then
the limit limnÑ8 f pnq fails to exist. We can associate with f its upper and
lower envelope, which are better behaved with respect to taking limits. The
upper envelope u of the function f is defined by
The general term of the upper envelope uf pnq of the function f is given by
1
uf pnq “ f p2 rn{2sq “ 2 `
2 rn{2s
1
f pnq “ f p2 tn{2u ` 1q “ 1 ´
2 tn{2u ` 1
Figure 10.1: The graph shows the function (or sequence) f from Example 10.10
with values depicted by large dots. The values of the upper envelope uf are shown
by small dotted lines, and the values of the lower envelope f by small solid lines
A crucial point in the definition of the upper and lower envelope is that they
omit more and more initial terms of f from consideration as n Ñ 8. Therefore,
the upper envelope is in general a monotonically decreasing function, and the
lower envelope is in general a monotonically increasing function. Consequently,
the limit of the upper envelope uf pnq and the lower envelope f pnq always exist
in the extended real line.
Recall that the extended real line consists of the set of real numbers R
and two symbols ´8 and `8 such that ´8 ă r ă 8 for all real numbers
r. The extended real line has the convenient property that every subset has
a supremum and an infimum, so it is a complete lattice. The extended real
line is convenient for denoting the limit of diverging sequences. We will explic-
itly point out the properties related to the nonfinite values in the subsequent
discussion.
Limit Inferior and Limit Superior. The limit superior lim supnÑ8 f pnq
is defined as ´ ¯
lim sup f pnq “ lim suptf pkq | k ě nu
nÑ8 nÑ8
In other words, the limit superior is the limit of the upper envelope of f , and
the limit inferior is the limit of the lower envelope of f .
Let us have a look at a particularly instructive example.
10.2 Limit Superior and Limit Inferior 245
Example 10.11. Let us continue the Example 10.10. Recall that the function
#
2 ` 1{n if n is even,
f pnq “
1 ´ 1{n if n is odd.
1
has the upper envelope uf pnq “ f p2 rn{2sq “ 2 ` 2rn{2s and the lower envelope
1
f pnq “ f p2 tn{2u ` 1q “ 1 ´ 2tn{2u`1 . Then
ˆ ˙
1
lim sup f pnq “ lim 2 ` “2
nÑ8 nÑ8 2 rn{2s
and ˆ ˙
1
lim inf f pnq “ lim 1 ´ “ 1.
nÑ8 nÑ8 2 tn{2u ` 1
The example shows that the limit inferior is in general not the smallest value
of f , since
0 “ 1 ´ 1{1 “ inftf pnq | n ě 1u ă lim inf f pnq “ 1.
nÑ8
Likewise, the example also shows that the limit superior is in general not the
largest value of f , since
2 “ lim sup f pnq ă suptf pnq | n ě 1u “ 2 ` 1{2.
nÑ8
We will characterize the limit inferior and limit superior as smallest and largest
accumulation points of f .
The next proposition stresses the difference between the infimum and limit
inferior as well as the difference between the supremum and the limit superior.
Proposition 10.12. Let f be a function from the set of positive integers to
the set of real numbers. Then
inftf pkq | k ě 1u ď lim inf f pnq ď lim sup f pnq ď suptf pkq | k ě 1u.
nÑ8 nÑ8
The previous example shows that any of these three inequalities can be strict.
Proof. The first inequality holds, since the lower envelope f of f is a mono-
tonically increasing function and f p1q “ inftf pkq | k ě 1u. The second
inequality follows directly from the definitions. The third inequality holds,
since the upper envelope uf of f is a monotonically decreasing function and
uf p1q “ suptf pkq | k ě 1u.
Let us now discuss four different situations when the limit inferior or limit
superior do not have finite values. If the function f does not have an upper
bound, then the suprema suptf pnq, f pn ` 1q, f pn ` 2q, . . .u “ 8 for all n, and
we define
lim sup f pnq “ `8.
nÑ8
246 10 Asymptotic Analysis
|f pnq ´ a| ă .
U1 For each real number ą 0 there exist infinitely many positive integers
n such that f pnq ą u ´ ,
U2 For each real number ą 0 there exist at most finitely many positive
integers such that f pnq ą u ` .
Proposition 10.19. Let f be a function from the set of positive integers to the
set of real numbers that is bounded above and does not diverge to ´8. Then
the real number u is equal to lim supnÑ8 f pnq if and only if u is the upper
accumulation point of f .
Proof. pñq Suppose that the limit superior of the function f is given by the
real number u “ lim supnÑ8 f pnq. We are going to show that u must be an
upper accumulation point. This means that we need to prove that (i) f pnq
satisfies U1 and that (ii) f pnq satisfies U2.
(i) Seeking a contradiction, suppose that there exists an ą 0 and an n such
that f pkq ď u ´ for all k ě n. Then uf pkq ď u ´ for all k ě n, so
lim supnÑ8 f pnq “ limnÑ8 uf pnq ď u ´ , contradicting our assumption
u “ lim supnÑ8 f pnq. Therefore, we can conclude that U1 holds.
(ii) Seeking a contradiction, suppose that there exists an ą 0 such that
there are infinitely many positive integers n so that f pnq ą u ` . This
implies that uf pnq “ suptf pnq, f pn ` 1q, f pn ` 2q, . . .u ą u ` for all
n ě 1. Therefore,
For any ą 0, all even positive integers n such that n ą 1{ have a function
value f pnq ą 2 ´ . We have f pnq ą 2 ` only when n is an even positive
integer satisfying n ă 1{. Therefore, 2 is an upper accumulation point of f pnq.
This is also illustrated in Fig. 10.2. We can conclude that lim sup f pnq “ 2.
nÑ8
Figure 10.2: The graph shows the function (or sequence) f from Example 10.20. For
each ą 0, there are finitely many points above 2 ` , but an infinite number above
2 ´ , so it has an upper accumulation point of value 2. Hence, lim supnÑ8 f pnq “ 2
L2. For each real number ą 0, there exist at most finitely many positive
integers such that f pnq ă ´ .
Figure 10.3: The graph shows the function (or sequence) f from Example 10.20. For
each ą 0, there are finitely many points below 1 ´ , but an infinite number below
1 ` , so it has a lower accumulation point of value 1. Hence lim inf nÑ8 f pnq “ 1
The function f is called bounded below if and only if there exists a real
number such that f pnq ě holds for all positive integers n. If f has a lower
accumulation point, then it is bounded below.
Proof. Since lim inf nÑ8 f pnq “ ´ lim supnÑ8 ´f pnq, the claim is a direct con-
sequence of Proposition 10.19.
Exercises
10.10. Find all accumulation points of the following functions, and determine
their upper and lower accumulation points.
(a) f pnq “ p´1qn ,
(b) f pnq “ 4 ` p´1qn n{pn ` 10q
(c) f pnq “ pp´1qn ` p´1qtn{2u qp1 ` 1{nq.
10.11. Construct a function f pnq that has all positive integers as accumulation
points.
10.12. Determine lim supnÑ8 f pnq and lim inf nÑ8 f pnq when f pnq is given as
250 10 Asymptotic Analysis
holds for all n ě 5. Indeed, the lower bound is clear. For the upper bound, it
suffices to note that n ě 5 implies n3 ě 8 ¨ 9 ¨ 12{10, and dividing both sides by
n2
8 ¨ 9 ¨ n yields 18 n2 ´ 19 n2 “ 8¨9 12
ě 10n , so adding 19 n2 to both sides yields the
upper bound 18 n2 ě f pnq. The graphs of these functions are shown in Fig. 10.4.
When we want to prove that f P Θpgq holds, we need to find three constants
n0 , c, and C such that
Proof. It follows from the definition of the limit that for each ą 0 there exists
a positive integer n such that
|f pnq|
d´ď ďd`
|gpnq|
252 10 Asymptotic Analysis
The next example shows that even when the limit of the quotient of two
functions does not exist, they might still have the same order of growth.
Example 10.26. Let f pnq “ p2 ` p´1qn qn2 and gpnq “ n2 . Then the limit
|f pnq|
lim
nÑ8 |gpnq|
We call a function f from the set of positive integers to the set of real
numbers eventually nonzero if and only if there exists an integer n0 such
that f pnq is nonzero for all n ě n0 .
The next proposition gives a necessary and sufficient condition for asymp-
totically tight bounds.
|f pnq| |f pnq|
lim inf ą0 and lim sup ă 8.
nÑ8 |gpnq| nÑ8 |gpnq|
10.3 Asymptotically Tight Bounds 253
Proof. If f P Θpgq, then there exist positive constants c and C and a positive
integer n0 such that c ď |f pnq|{|gpnq| ď C holds for all n ě n0 . This implies
that
|f pnq| |f pnq|
lim inf ě c ą 0 and lim sup ďCă8
nÑ8 |gpnq| nÑ8 |gpnq|
hold.
Conversely, suppose that f and g are functions satisfying
By definition of the limit superior and inferior, for any in the range 0 ă ă c
there exists a positive integer n0 such that
|f pnq|
0ăc´ď ď pC ` q
|gpnq|
holds for all n ě n0 . Multiplying these inequalities by |gpnq| shows that f P
Θpgq holds.
We claim that T pnq P Θp2n q. Indeed, let us calculate the limit inferior and
limit superior of T pnq{2n . We have
Exercises
10.15. Suppose that f, g, and h are functions from the set of positive integers
to the set of real numbers. Show that
(i) f — f ,
(ii) f — g if and only if g — f ,
(iii) f — g and g — h implies f — h.
In other words, show that — is an equivalence relation.
10.16. Show that a polynomial ppxq of degree m satisfies ppxq “ Θpxm q.
10.17. Let f pnq “ 2n3 ` 3n ` 2 and gpnq “ 5n4 ` 3n3 ` 2n ` 1. Express Θpf gq
in the simplest possible terms.
10.18. Let b and d be positive real numbers that are not equal to 1.
(a) Show that Θplogb nq “ Θplogd nq, so one can write Θplog nq using a baseless
logarithm without causing confusion.
(b) Prove or disprove: Does Θpnlogb n q “ Θpnlogd n q hold in general?
10.19. Let a be a real number, a ą 1. Show that
n
ÿ
ak “ Θpan q.
k“0
1k ` 2k ` ¨ ¨ ¨ ` nk “ Θpnk`1 q.
1 2
Figure 10.5: The graphs of the functions 15 n, 4 ln n, and 20 n on the interval
1 2 1 2
r1, 20s. The quick growth of the function 20 n suggests that 15 n P Op 20 n q and
1 2
4 ln n P Op 20 n q. However, graphs are not a good tool to judge such relationships.
For example, 4 ln n exceeds 15 n throughout this graph, but it is not difficult to show
that 4 ln n P Op 15 nq, whereas 15 n R Op4 ln nq
|n| ď 1|n2 |.
Example 10.30. Suppose that k and are integers such that 1 ď k ă . For
all integers n ě 1, raising both sides to the p ´ kq-th power yields n´k ě 1. If
we then multiply both sides by nk , we get n ě nk . Therefore, we can conclude
that nk P Opn q.
|f pnq|
lim sup ă 8.
nÑ8 |gpnq|
Proof. The proof is straightforward, but instructive if you are not yet familiar
with the notion of the limit superior, see Exercise 10.23.
Corollary 10.32. Let f and g be functions from the set of positive integers to
the set of real numbers. If the limit
|f pnq|
lim
nÑ8 |gpnq|
Figure 10.6 gives some rules that are convenient when trying to establish
asymptotic upper bounds. For example, it follows from the constant rule that
2n P Op2nq “ Opnq. You can gain familiarity with asymptotic upper bounds
by proving these rules.
Let f and g be functions from the set of positive integers to the set of real
numbers. We say that g is a strict asymptotic upper bound for f and
write f P opgq if and only if for every real number ą 0 there exists a positive
integer n such that
|f pnq| ď |gpnq|
Proposition 10.34. Let f and g be functions from the set of positive integers
to the set of real numbers such that g is eventually nonzero. Then f P opgq if
and only if
f pnq
lim “0 (10.11)
nÑ8 gpnq
holds.
10.4 Asymptotic Upper Bounds 257
Figure 10.6: Some simple rules for the manipulation of upper bounds
Proof. Suppose that (10.11) holds. By definition of the limit, this means that
for any ą 0 there exists a positive integer n such that
ˇ ˇ
ˇ f pnq ˇ
ˇ gpnq ˇ ă
ˇ ˇ
holds for all n ě n . This is equivalent to the condition that for each ą 0
there exists an n such that
|f pnq| ď |gpnq|
Corollary 10.35. Let f and g be functions from the set of positive integers to
the set of real numbers. Suppose that f P opgq. Then
g ` f P Opgq.
Example 10.36. We claim that n ln n P opn2 q, so n ln n P Opn2 q. Indeed, it
follows from l’Hôpital’s rule that
n ln n ln n 1
lim 2
“ lim “ lim “ 0.
nÑ8 n nÑ8 n nÑ8 n
Therefore, we can deduce from Proposition 10.34 that n ln n P opn2 q.
Exercises
10.21. Let f pnq “ 4 ln n, gpnq “ 15 n, and hpnq “ 1 2
20 n . Show that
(a) f P opgq,
(b) g P ophq.
(c) Conclude that f P Opgq and g P Ophq.
10.22. Let f and g be positive functions. Show that f P opgq implies that
g R Opf q.
10.23. Prove Proposition 10.31: Let f be a function from the set of positive
integers to the set of real numbers, and g an eventually nonzero function from
the set of positive integers to the set of real numbers. Then f pnq P Opgpnqq if
and only if
|f pnq|
lim sup ă 8.
nÑ8 |gpnq|
Example 10.38. The function n2 is in ωpnq, since for a given positive constant
c, the inequality cn “ c|n| ď |n2 | “ n2 holds for all positive integer n ě c. On
the other hand, n is not in ωpnq, since there does not exist any positive integer
n for which 2n “ 2|n| ď |n| “ n holds.
Proposition 10.39. Let f and g be functions from the set of positive integers
to the set of real numbers, and assume that g is eventually nonzero. Then we
have f P ωpgq if and only if
|f pnq|
lim “ 8.
nÑ8 |gpnq|
Proof. We have f P ωpgq if and only if for all positive constants c there exists
a positive integer n0 such that c ď |f pnq|{|gpnq| holds for all n ě n0 , so
|f pnq|{|gpnq| grows without bound. By definition of the limit, this is equivalent
to
|f pnq|
lim “ 8,
nÑ8 |gpnq|
with long integer arithmetic. If the integers remain bounded, then spxq “ 1
would be a reasonable choice.
Let I denote the set of all possible inputs to an algorithm A. If we denote by
tA pxq the running time of the algorithm A on an input x, then the worst-case
running time of the algorithm A is defined as
This measures the worst-case performance of the algorithm for all inputs of
length n. We will use asymptotic notations to simplify the resulting worst-case
running time.
So how do we determine the worst-case running time of an algorithm in
practice? The answer is that we simply analyze the algorithm line-by-line and
essentially count operations. The main complications are conditional state-
ments, loops, and function or procedure calls. We now put forth the axioms
that govern the run-time analysis. The list is incomplete, but you will see the
pattern, and it should be easy to extend this list by further language constructs.
if C then S1 else S2
has worst-case running time T pCq ` maxtT pS1 q, T pS2 qu when the condi-
tional statement C and the statements S1 and S2 have worst case running
time T pCq, T pS1 q and T pS2 q on an input of size n, respectively.
The next axiom gives the estimate for the running-time of a for loop, which
iterates through all integers k in the range a ď k ď b, where a and b are
integers. The notation pa..bq
262 10 Asymptotic Analysis
for k in pa..bq do
S1
end
řb
has worst-case running time T pSq ď c ` k“a pT pS1 , kq ` cq, where
T pS1 , kq is the worst-case running time of statement S1 during iteration
k and c is the cost of evaluating the loop condition.
In the worst case, such a for loop iterates b´a`1 times and checks the loop
condition b ´ a ` 2 times (as the loop verifies that k is out of bounds before it
stops the iteration). One special case is worth noting. If T pS1 q “ T pS1 , kqq is
nonzero and independent of k, then this simplifies to
There exist numerous variations of for loops. We will leave it to the reader
to modify the axiom for these variations.
The running-time of a do-while loop (sometimes also called a repeat-until
loop) is given in the next axiom. This style of loop executes the statement S1
at least once before checking the condition C. It will repeat while the condition
C is met.
A5. The running-time of a do-while loop statement S given by
begin
S1
end while C
řmpnq
has worst-case running time T pSq ď k“1 pT pCq`T pS1 , kqq, where mpnq
is the maximal number of loop iterations on an input of size n and T pCq
and T pS1 , kq are the worst-case running times of the conditional state-
ment C and the statement S1 during iteration k, respectively.
We illustrate how to obtain an estimate for the worst-case running-time
with a small example.
Example 10.40. Suppose that you want to write a program to evaluate a
polynomial
ppxq “ an xn ` an´1 xn´1 ` ¨ ¨ ¨ ` a1 x ` a0 ,
so for a given input x, you would like to know the value y “ ppxq. You can
save multiplications by using the Horner scheme
T pnq “ c1 ` c2 pn ` 1q ` c3 n ` c4 n ` c5 ` c6 “ Θpnq.
This compares favorably with the naive Θpn2 q algorithm that evaluates the
polynomial ppxq by computing each power independently by repeated multi-
plication.
Exercises
10.38. Analyze the running time of the following algorithm using a step count
analysis (as in the Horner scheme).
10.39. Analyze the running time of the following algorithm using a step count
analysis (as in the Horner scheme).
10.40. Determine how many times the block Block(a,b) is executed in the
following code fragment:
264 10 Asymptotic Analysis
n = 100
for a in (0..n-1) do
for b in (0..n) do
Block(a,b)
end
end
You can assume that Block(a,b) does not exit the for loops, nor does it
manipulate the loop variables a and b.
10.41. Determine how many times the block Block(a,b) is executed in the
following code fragment:
n = 100
for a in (0..n) do
for b in (0..a) do
Block(a,b)
end
end
You can assume that Block(a,b) does not exit the encapsulating for loops and
does not manipulate the loop variables a and b.
10.7 Notes
Asymptotic notations were introduced by Bachmann [7] and further popular-
ized by Landau [55]. Graham, Knuth, and Patashnik [30] give a more in-depth
treatment of asymptotic notations. Spencer [71] dedicates an entire book to
asymptotic notations and gives numerous surprising applications. Books on the
analysis of algorithms contain numerous examples of asymptotic estimates of
the running time; see, for example, Aho, Hopcroft, and Ullman [1] or Cormen,
Leiserson, Rivest, and Stein [16].
Part III
Combinatorics
265
Chapter 11
Counting
As I was going to St. Ives,
I met a man with seven wives,
Each wife had seven sacks,
Each sack had seven cats,
Each cat had seven kits:
Kits, cats, sacks, and wives,
How many were there going to St. Ives?
n1 ` n2 ` ¨ ¨ ¨ ` nm .
The key is that the tasks are mutually exclusive, so if you choose to do the first
task, then there are n1 ways to do it, but none of the other tasks can be done.
The next two examples illustrate the summation principle.
Example 11.1. Emily wants to buy some nice loaf of bread. She can go to
a nice downtown bakery where they offer three different kinds of bread that
she likes. Alternatively, she can go to a nearby bakery that has two different
kinds of artisanal breads that she fancies. By the summation principle, she can
choose from 3 ` 2 “ 5 loafs of bread.
Example 11.2. How many strings of six decimal digits have exactly five 7s?
Apparently, the strings are of the form
where x can represent any of the nine digits in the set t0, 1, . . . , 6u Y t8, 9u.
We can now count the possibilities as follows. Let Sk be the set of strings
of length six that have a 7 in each position except at position k. Since there
are 9 choices of digits other than 7, we have |Sk | “ 9. Therefore, the number of
strings with six decimal digits that have exactly five 7s is given by summation
principle as
ÿ6 6
ÿ
|Sk | “ 9 “ 54.
k“1 k“1
The advantage of the set theoretic approach is that it easily scales to large
problem sizes.
We can use this principle as follows. Suppose that a task can be broken up
into m consecutive independent subtasks. If the k-th subtask can be done in
nk ways, then the entire task can be done in
11.1 Fundamental Counting Principles 269
n1 ˆ n2 ˆ ¨ ¨ ¨ ˆ nm
ways.
The next two examples illustrate how to use the multiplication principle.
Example 11.3. Sam has decided on a smartphone. He can choose from the
four colors S1 “ tsilver, gold, red, blueu, three different memory sizes S2 “
t16 GB, 64 GB, 128 GBu, and sim cards from four different network providers
S3 “ tP1 , P2 , P3 , P4 u. From how many different smartphone configurations can
he choose? By the multiplication principle, he can choose from 4 ˆ 3 ˆ 4 “ 48
different configurations.
Example 11.4. Tera wants to travel from Houston to Vancouver, and she
thought that it might be nice to have a layover in New York. She found three
different flights from Houston to New York that are affordable, and four differ-
ent flights from New York to Vancouver on the next day. By the multiplication
principle, she can choose from a total of 3 ˆ 4 “ 12 different travel itineraries.
|S| “ n1 ˆ n2 ˆ ¨ ¨ ¨ ˆ nm .
Example 11.5. Suppose that you want to order a pizza. The pizza parlor
offers an attractive deal when you choose two different toppings from
where the amount for the first topping is about twice the amount of the second
topping. How many different pizzas are covered by this deal? We can visualize
the choices using a decision tree, see Fig. 11.1. For the first (and dominant)
topping, there are three different choices. If you pick, say, olives as the first
topping, then there are two choices for the second topping, namely pepperoni or
mushrooms. Since there are three choices for the first topping, and two choice
for the second topping (regardless of your choice for the first topping), there
270 11 Counting
Figure 11.1: The decision tree for the ingredient selection. There are three choices
for the first dominant topping. For the second nondominant topping, there remain
two choices for each selection of the first topping
are 3 ˆ 2 “ 6 choices for the two-toppings pizza. We emphasize that the second
topping selection choices are not from a fixed set (as in the Multiplication
Principle I), but rather from different sets.
Example 11.6. Suppose that a student organization has nine active members.
In how many ways can they elect a president, vice-president, secretary, and
treasurer as officers, assuming that everyone can hold only one officer position?
There are nine ways to choose someone as president. From the remaining eight
students, one can choose the vice-president. After president and vice-president
have been chosen, there are seven ways to select the secretary. Finally, the
treasurer can be chosen from the remaining six students. Therefore, there are
a total of
9 ˆ 8 ˆ 7 ˆ 6 “ 3024
different ways of filling the four officer positions from the nine active members
of the student organization.
Example 11.7. A restaurant offers on Mother’s Day on their prix fixe menu
either a three-course meal or a four-course meal. In the three-course meal,
one can choose from three different appetizers, four main courses, and three
desserts. In the four-course meal, there are three choices for the appetizer
course, five choices for the second course, three choices for the third course,
and three choices for the dessert course. By the multiplication principle, there
are 3 ˆ 4 ˆ 3 “ 36 possible three-course meals, and 3 ˆ 5 ˆ 3 ˆ 3 “ 135 possible
four-course meals. By the summation principle, the prix fixe menu offers a
total of 36 ` 135 “ 171 different choices.
Example 11.8. In Sesame street, Season 1, Episode 45, the “As I was going
to St. Ives” nursery rhyme quoted at the beginning of this chapter was made
into a song. A purple Anything Muppet boy sings the song with the nursery
rhyme and challenges a green Anything Muppet girl to figure out how many
really go to St. Ives. He then reveals that the answer is 1, as the others go the
11.1 Fundamental Counting Principles 271
other way. The amusing part about the skit is that the green girl turns the
tables and asks him how many go the other way, which he cannot answer. She
correctly calculates using the multiplication principle that there is 1 man, 7
wives, 72 “ 49 sacks, 73 “ 343 cats, and 74 “ 2401 kittens. By the summation
principle, there are 1 ` 7 ` 49 ` 343 ` 2401 “ 2801 going the other way.1
In the subtraction principle, one counts the number |T | of elements in the subset
T of unwanted elements and subtracts this from the total |S|. The subtraction
principle is also known as complementary counting. This method can be
beneficial when it is tedious to count the elements in the set S z T directly.
The next two examples illustrate the flavor of this method.
Example 11.9. Suppose that you want to determine the number of positive
integers in the set S “ t1, 2, . . . , 100u that are not divisible by 6. A direct
count does not seem to be so obvious. However, the set
T “ tx P S | x is a multiple of 6u
of unwanted elements has cardinality t100{6u. Since |S| “ 100, we can conclude
that the number of elements in S that are not divisible by 6 is given by
Exercises
11.1. How many bit strings of length 12 are there?
11.2. Anna wants to go on a vacation. She packs merely five different shirts,
three different pairs of pants, and two different pairs of shoes. In how many
different ways can she combine her outfit?
1 She was also counting the sacks to conform to the nursery rhyme. Do you recall a better
11.3. Suppose that you have an alphabet with m different symbols. How many
strings of length n can you form that have symbols from this alphabet in each
position?
11.4. Suppose that a state has license plates of the following form: three letters
followed by four digits. How many different license plates are there if no further
restrictions are imposed?
11.5. The selection of a password of a computer account has the following
restrictions: The password must be 6, 7, or 8 characters long. A character
can be lower case letter or a decimal digit. The first character must be a
lowercase letter. Determine the total number of possible passwords with the
given restrictions.
11.6. Deduce the subtraction principle from the summation principle.
11.7. The North American Numbering Plan NANP regulates the form of phone
numbers in North America. A 10-digit phone number is of the form NXX-NXX-
XXXX, where N denotes any digit in the range 2–9, and X denotes any digit
in the range 0–9. The first three digits cannot be of the form N11, as these
are reserved for special services. Determine how many 10-digit NANP phone
numbers there are according to the restrictions given here (there are a few
more, which we ignore for the sake of this exercise).
11.8. Andrea wants to create a game that requires many game pieces. She
paints a wooden cube red on all sides and plans to cut it on a bandsaw into k 3
smaller congruent cubes. The small cubes will serve as the game pieces. What
is the smallest k such that she gets at least 100 small cubes that have one or
more red sides?
11.9. Bob suffers from aibohphobia, the irrational fear of palindromes. Cal-
culate for him the number of words of length n over an alphabet with k letters
that are not palindromes.
11.10. How many different relations exist on a set with n elements.
11.11. Count the number of reflexive relations on a set with n elements.
11.12. Count the number of irreflexive relations on a set with n elements.
11.13. Count the number of asymmetric relations on a set with n elements.
11.14. Count the number of antisymmetric relations on a set with n elements.
11.15. Count the number of symmetric relations on a set with n elements.
11.16. Suppose that we are given m pairwise disjoint finite sets S1 , S2 , . . . , Sm
of cardinality ck “ |Sk | for all k in the range 1 ď k ď m. Show that the number
of subsets of S1 Y S2 Y ¨ ¨ ¨ Y Sm containing at most one element from each set
Sk with 1 ď k ď m is given by
pc1 ` 1qpc2 ` 1q ¨ ¨ ¨ pcm ` 1q.
11.2 Permutations and Combinations 273
11.17. Alice, Joe, and Bert are naming integers a, j, and b in the range
0 ď a, j, b ă 1000. Joe finds it amusing to pretend to be an “average Joe,”
so he manipulates Alice and Bert to name integers a and b such that he can
choose the average
a`b
j“
2
of their values a and b as his integer. How many triples are in the set
a`b
tpa, , bq P Z3 | 0 ď a, b ă 1000u?
2
pa, bq, pa, cq, pb, aq, pb, cq, pc, aq, pc, bq.
Example 11.11. Suppose that eight runners qualified for the final 100 meter
sprint race. If we denote the set of runners by S “ tA, B, C, D, E, F, G, Hu,
then the 3-permutations describe the possible placings for gold, silver, and
274 11 Counting
bronze medals, assuming that there are no ties. The 3-permutation pB, F, Gq
can be interpreted as B winning the gold medal, F winning the silver medal,
and G winning the bronze medal. There are eight choices for the potential gold
medal winner, seven choices for the silver medal winner from the remaining
runners, and six choices for the bronze medal winner. Therefore, it follows
from the multiplication principle that 8 ˆ 7 ˆ 6 “ 336 is the total number of
possible race outcomes in terms of olympic medals.
nk “ npn ´ 1q ¨ ¨ ¨ pn ´ k ` 1q,
where n0 “ 1.
as claimed.
The next proposition reveals that the number of k-combination of a set with n
elements is given by a binomial coefficient.
11.2 Permutations and Combinations 275
nk
ˆ ˙
n! n
Cpn, kq “ “ “ ,
k! k!pn ´ kq! k
as claimed.
Exercises
11.18. A tennis team consists of 12 players. The team lines up for a group
photo, where the players all stand next to each other in a single line. In how
many different ways can the photographer arrange the players for the photo?
11.19. Tom has a book shelf containing 20 novels and 7 math books. In how
many ways can he arrange the books on the shelf, assuming he wants to keep
all the math books next to each other?
11.20. John is moving and has packed all his possessions into six large boxes.
(a) John can load three boxes in his car. In how many ways can John select
three of the six boxes?
(b) John makes two trips, transporting three boxes in each trip. How many
ways are there to transport the six boxes?
(c) John moved into his new apartment. He labels the boxes from 1 to 6 and
forms three stacks of boxes. The first stack has three boxes, the second
has two boxes, and the third has one box. In how many ways can he stack
the six boxes in this way?
In your answers, you should use counting coefficients P pn, kq or Cpn, kq when-
ever appropriate. Then evaluate your expressions.
11.21. There are 12 guests at a party. Bob observed that each pair of guests
clinked glasses precisely once. How many times did the glasses clink at the
party?
11.24. Zeta wants to write down all seven digit nonnegative integers that can
be formed with digits from the set t0, 1, 2, . . . , 9u, but without using a digit
twice. She follows the usual conventions for writing down integers. How many
different integers would she need to write down?
11.25. Let S be a set of n distinct points such that n ´ m points lie on a circle
and m points lie on a line that does not meet any of the points on the circle.
How many different nondegenerate triangles can be formed from these points?
Example 11.14. A computer science teacher wants to treat her students, since
they did very well in a competition. There are 10 students, and she promises
a slice of pie for everyone from a nearby bakery. The students can choose from
apple pie, cherry pie, key lime pie, and pecan pie. The teacher records a apple
pies, c cherry pies, k key lime pies, and p pecan pies in the short form pa, c, k, pq.
So the possible orders of the pies can be described by the set
While they were waiting for their pies to arrive, the students are wondering how
many different orders are possible. However, it was not immediately apparent
to them how to determine |P |.
11.3 Combinatorial Proofs 277
The students are baffled when their teacher mentions that the pie orders
correspond to the set B of bit strings of length 13 that contain precisely three
1s. Indeed, she explains that it is possible to map pa, c, k, pq to the bit string
0o¨mo
lo ¨ ¨o0n 1 lo
0o¨mo
¨ ¨o0n 1 lo
0o¨mo
¨ ¨o0n 1 lo
0o¨mo
¨ ¨o0n
a times c times k times p times
This time we will not use a proof by induction, but rather a double counting
argument. We will count the points in the set
S “ tpx, yq P Z2 | 0 ď x, y ď nu
in two different ways. Evidently, the set S contains pn ` 1q2 points, namely
each point px, yq with integer coordinates in the range 0 ď x, y ď n. However,
we can count the set also by diagonals, see Fig. 11.2. The number of points on
the diagonals below the main diagonal are given by
n
ÿ
k.
k“1
We obtain the same formula for the number of points on diagonals above the
main diagonal of the quadratic grid. In addition, there are n ` 1 points on the
main diagonal. Summing over all diagonals, we get
˜ ¸
n
ÿ
2 k ` pn ` 1q “ pn ` 1q2 .
k“1
as claimed.
Figure 11.2: The figure illustrates the set S containing pn ` 1q2 points with integer
coordinates. The case n “ 6 is shown that contains 7 ˆ 7 points. Counting the points
on the diagonals yields 2p1 ` 2 ` ¨ ¨ ¨ ` 6q ` 7 “ 72 , which implies 1 ` 2 ` ¨ ¨ ¨ ` 6 “
p72 ´ 7q{2 “ 6 ¨ 7{2
11.3 Combinatorial Proofs 279
Proof. Let S be a set with n elements. The power set P pSq contains subsets
of S of cardinality 0, 1, 2, . . . , n. The left-hand side
n ˆ ˙
ÿ n
k“0
k
The previous result would have been cumbersome to prove using just the
definition of the binomial coefficients. In the combinatorial proof, we simply
counted the number of elements of the power set of S in two different ways.
We will now give another proof of the binomial theorem. We proved it by
induction, but the following proof provides additional insights.
Theorem 11.18 (Binomial Theorem). For a nonnegative integer n, we have
n ˆ ˙
ÿ n k n´k
px ` yqn “ x y .
k“0
k
px ` yqn “ loomoon
px ` yq loomoon
px ` yq ¨ ¨ ¨ loomoon
px ` yq .
1 2 n
From each of these n terms, we can select either x or y. Suppose that we select
x from k of these n terms (and y from the remaining n ´ k terms), then we
obtain the term xk y n´k . We can do this in nk ways. The right-hand side
` ˘
collects these terms for all possible k, which proves our theorem.
Let us illustrate the idea of the proof for the case n “ 3. Expanding
yields
xxx ` xxy ` xyx ` xyy ` yxx ` yxy ` yyx ` yyy.
Since the latter expression is equal to
x3 ` x2 y ` x2 y ` xy 2 ` x2 y ` xy 2 ` xy 2 ` y 3 ,
280 11 Counting
Proof. Let S denote a set with m elements and T a set with n elements such
that
` S X˘T “ H. We can choose a subset of cardinality k from the union S Y T
in n`m
k ways, since |S Y T | “ m ` n.
On the other hand,` ˘ we can choose a subset of S that has cardinality i
with 0 ď i ď k in mi ways. By choosing k ´ i elements from T , we can
complement this to a subset` nof˘cardinality k of S Y T . Since we can choose the
k ´ i elements from T in k´i ways, the product principle shows that there
2 This
` n˘
is the generating function for the binomial coefficients k
for fixed n that we will
discuss later.
11.3 Combinatorial Proofs 281
are mi k´i
` ˘` n ˘
subsets of cardinality k of S Y T that have i elements from S and
k ´ i elements from T . Consequently, the sum
k ˆ ˙ˆ ˙
ÿ m n
i“0
i k´i
Proof. We will prove the claim by double counting. Let S denote the set
S “ t1, 2, . . . , nu of n elements. This set has nk subsets with k elements.
` ˘
Pascal’s
` ˘ identity gives
` ˘ a recursive way to compute binomial coefficients. In-
deed, n0 “ 1 and nn “ 1 hold for all nonnegative integers` n. ˘ Therefore,
n
Pascal’s identity can be used to calculate all other coefficients k . This recur-
sion underlies Pascal’s triangle, see Fig. 11.3.
Figure 11.3: Pascal’s triangle. An entry nk can be obtained by adding the entry
` ˘
`n´1˘ `n´1˘
k
above it and the entry k´1 above it to the left. The left part of the figure
shows the binomial
` ˘ coefficients, and the right
` ˘ part of the
` ˘ figure shows their evaluation.
For example, 42 is obtained by adding 31 “ 3 and 32 “ 3
282 11 Counting
Exercises
11.26. A very simple use of the bijection principle is the accurate counting
of the number of elements in a finite arithmetic sequence. For instance, if we
are given a set S “ ta, a ` d, a ` 2d, . . . , a ` pn ´ 1qdu, then adding d ´ a to
each element and dividing by d yields a bijection onto the set t1, 2, 3, . . . , nu,
so |S| “ n. For instance, if T “ t1, 4, 7, . . . , 100u is a set whose elements form
an arithmetic sequence with difference 3, then adding 2 to each element and
dividing by 3 maps T bijectively onto the set t1, 2, 3, . . . , 34u, so |T | “ 34. Use
the bijection principle to determine the number of elements for each of the
following sets.
(a) A “ t27, 28, 29, . . . , 333u,
(b) B “ t4, 6, 8, . . . , 2802u,
(c) C “ t55, 58, 61, . . . , 421u,
(d) D “ t128, 121, 114, . . . , ´61u.
The approach outlined earlier can help you to avoid off-by-one errors when
quickly counting the number of elements of each set.
11.27. Prove the absorption property of binomial coefficients
ˆ ˙ ˆ ˙
n n´1
k“n .
k k´1
If n is even, then the two coefficients in the middle coincide. If n is odd, then
the two coefficients in the middle are different but happen to have the same
value. A sequence of coefficients that first increases and then decreases is called
a unimodal sequence.
2n`1
ˆ ˙
n
„?
n{2 2πn
for even n.
pa, aq, pa, bq, pa, cq, pb, aq, pb, bq, pb, cq, pc, aq, pc, bq, pc, cq.
Let Rpn, kq denote the number of ordered k-selections with repetition over a
set with n elements. In other words, we want to count the number of functions
from K to S.
Proposition 11.23. Let K be a finite set with k elements and S a finite set
with n elements. Then the number of functions from K to S is given by nk .
Thus, the number of ordered k-selections of elements from S with repetitions
allowed is given by Rpn, kq “ nk .
Example 11.24. Suppose that you want to order k “ 3 scoops of ice cream
from a set S “ tc, s, vu of three different flavors, where we use c to denote
chocolate, s to denote strawberry, and v to denote vanilla flavor. Then there
are 10 different choices
tc, c, cu, tc, c, su, tc, c, vu, tc, s, su, tc, s, vu,
tc, v, vu, ts, s, su, ts, s, vu, ts, v, vu, tv, v, vu.
Here tc, c, vu means that you get two scoops of chocolate ice cream and one
scoop of vanilla. Since this is an unordered selection, tc, c, vu is the same as
tc, v, cu. Note that tc, c, vu is not the same as tc, vu, since in the latter case
you would only receive two scoops of ice cream.
Proof. Without loss of generality, we may assume that S “ t1, 2, . . . , nu. Let
A denote the set of all multisets with k elements from S, and let B denote the
set of all subsets with k elements of the set t1, 2, . . . , n ` k ´ 1u.
A multiset T “ tm1 , m2 , . . . , mk u P A can be arranged in nondecreasing
order so that m1 ď m2 ď ¨ ¨ ¨ ď mk . Define a map σ : A Ñ B by
Since the cardinality of the set B of k element subsets of t1, 2, . . . , n`k ´1u
is given by ˆ ˙
n`k´1
|B| “ ,
k
the claim follows.
Corollary 11.26. The number of integer solutions to the equation
x1 ` x2 ` ¨ ¨ ¨ ` xn “ k (11.1)
such that xm ě 0 holds for all m in the range 1 ď m ď n is given by
ˆ ˙
n`k´1
M pn, kq “ .
k
Proof. Let S “ t1, 2, . . . , nu. Each solution to the equation x1 `x2 `¨ ¨ ¨`xn “ k
in the nonnegative integers specifies a multiset M with k elements that contains
the element m P S exactly xm times for 1 ď m ď n.
Conversely, every multiset M with k elements from S yields a solution to
the equation by setting xm to the multiplicity of the element m P S in the
multiset M .
By the bijection principle, the number of nonnegative integer solutions to
the Eq. (11.1) coincides with the number M pn, kq of multisets with k elements
from S, and the claim follows from the previous theorem.
of them. Indeed, for every color pattern in a row, there are 3!2!4! “ 288
different rearrangements that look exactly the same, as there are 3! ways to
reorder the blue tokens, 2! ways to reorder the green tokens, and 4! ways to
reorder the red tokens.
The next example paves the way to the multinomial theorem that general-
izes the binomial theorem.
If we want to fully expand this expression, then we obtain ` a sum˘ of terms of the
form xn1 1 xn2 2 xn3 3 such that n1 ` n2 ` n3 “ 4. There are n1 ,n42 ,n3 different ways
to obtain the term xn1 1 xn2 2 xn3 3 from the product of four terms. For instance,
there are ˆ ˙
4 4!
“ “4
3, 1, 0 3!1!0!
different ways to form the term x31 x2 . Calculating the multinomial coefficient
for each term, we obtain the expansion
px1 `x2 ` x3 q4 “ x41 ` 4x31 x2 ` 4x31 x3 ` 6x21 x22 ` 6x21 x23 ` 12x21 x2 x3 ` 4x1 x32
` 4x1 x33 ` 12x1 x2 x23 ` 12x1 x22 x3 ` x42 ` x43 ` 4x2 x33 ` 6x22 x23 ` 4x32 x3 .
Proof. Expand the term px1 ` x2 ` ¨`¨ ¨ ` xm qn . ˘The number of ways to obtain
the term xn1 1 xn2 2 ¨ ¨ ¨ xnmm is given by n1 ,n2n,...,nm .
Exercises
11.38. Determine in how many different ways one can permute the following
words:
(a) lillypilly
(b) spoonfeed
(c) subbookkeeper
(d) honorificabilitudinitatibus
(e) supercalifragilisticexpialidocious
288 11 Counting
tt1u, t2, 3, 4uu, tt2u, t1, 3, 4uu, tt3u, t1, 2, 4uu, tt4u, t1, 2, 3uu,
tt1, 2u, t3, 4uu, tt1, 3u, t2, 4uu, tt1, 4u, t2, 3uu.
4( 4( 4(
One can similarly show that 1 “ 1, 3 “ 6, and 4 “ 1.
n(
Example 11.31. We have n “ 1 for all positive integers n, since there is
only one partition of S “ t1, 2, . . . , nu with n nonempty parts, namely the
partition tt1u, t2u, . . . , tnuu of S into singleton sets.
Proposition 11.32. For all positive integers n and all integers k in the range
1 ď k ď n ´ 1, we have
" * " * " *
n n´1 n´1
“ `k .
k k´1 k
Remark 11.33.
( The claim of the previous proposition holds for k “ n as well,
since k n´1
n “ 0. For k ą n, the left-hand side and the right-hand side are
both equal to 0. Therefore,
" * " * " *
n n´1 n´1
“ `k
k k´1 k
parts satisfies the same recurrence that we have encountered when studying the
Stirling numbers Spn, kq of the second kind. Recall that the Stirling numbers
Spn, kq of the second kind were defined as the connection coefficients when
changing from the basis of falling factorials xk to the monomial powers xn ,
n
ÿ
xn “ Spn, kqxk .
k“0
Let us now verify that the Stirling numbers Spn, kq of the second kind coincide
with the number of set partitions of a set with n elements into k nonempty
parts.
290 11 Counting
Proof. We will prove this by induction on n. Let P pnq denote that the equality
" *
n
Spn, kq “
k
of the connecting coefficients Spn, kq and the number of partitions of a set with
n elements into k nonempty parts holds for all nonnegative integers k.
Induction Basis For n “ 0, we have Sp0, 0q “ 1 “ 00 and Sp0, kq “ 0 “ k0
( (
can conclude that Spn, kq “ nk holds for all nonnegative integers k, so P pnq
holds.
We can conclude by induction that for all nonnegative integers n, we have
Spn, kq “ nk for all nonnegative integers k.
(
Exercises
11.43. Give a simple formula for n2 and prove your result by a combinatorial
(
[Hint: Partition the set t1, 2, . . . , nu into k parts by first forming the block
containing the element n and then partitioning the rest into k ´ 1 blocks.]
then the question can be reformulated as the task to determine the cardinality
of the set ˇ ˇ
ˇ m
ď ˇ
ˇS z Sk ˇ .
ˇ ˇ
ˇ ˇ
k“1
We assume that we can determine the number of elements having one of the
properties, two of the properties and so forth.
It is instructive to work out special cases for a small number of properties.
For example, let us consider the case of m “ 2 properties, see Fig. 11.4.
Figure 11.4: The shaded part illustrates the set SzpS1 Y S2 q, whose elements we
would like to count
The latter formula is known as the inclusion-exclusion formula for two proper-
ties.
Let us give some insights into the inclusion-exclusion formula. We can
estimate the number of elements in SzpS1 Y S2 q by |S|, but this is clearly an
overestimate. If we subtract from |S| the number of elements in S1 and the
number of elements in S2 , then we get an underestimate, since the elements in
the intersection S1 X S2 were counted both in S1 and in S2 . As we have shown
earlier, the inclusion-exclusion formula
S2 “ tx P S | x is divisible by 5u “ t5x | 1 ď x ď 4u
is a set with |S2 | “ 4 elements. The numbers that are divisible by both 2 and
5 are given by |S1 X S2 | “ |t10, 20u| “ 2.
By the inclusion-exclusion formula, the number |SzpS1 Y S2 q| of elements
in S that are not divisible by either 2 or 5 is given by
The appeal of the inclusion-exclusion formula is that it is easy to count the num-
ber of elements in the sets S1 , S2 , and S1 X S2 . Of course, we could have deter-
mined the number of elements of the set SzpS1 Y S2 q “ t1, 3, 7, 9, 11, 13, 17, 19u
by simply forming the set, but for larger n, this will not be an attractive solu-
tion.
We will now state and prove the general inclusion-exclusion principle. It
will be useful to introduce some notation that will allow us to state the result
in a compact form. Let I denote a subset of t1, 2, . . . , mu. Then we denote by
SI the set
#
S if I “ H,
SI “
Si1 X Si2 X ¨ ¨ ¨ X Sik if I “ ti1 , i2 , . . . , ik u.
Example 11.37. Let us find the number of integers in the range from 1 to
100 that are neither a perfect square nor a perfect cube nor a perfect 4th
11.6 The Inclusion-Exclusion Principle 293
Proof. A surjective map from a set A with n elements to a set with m elements
induces a partition on A with m nonempty parts via its preimages. There are
n
(
m ways to partition A in this way, and m! ways to assign the function values
to the partitions, so
" * m ˆ ˙
n ÿ
k m
m! “ p´1q pm ´ kqn ,
m k“0
k
Suppose that an office with n office workers is organizing a Secret Santa gift
exchange. So everyone is drawing a name of a coworker that she is supposed
to surprise with a gift. It is arranged such that no one will be able to draw
her own name. In how many different ways is it possible to give the gifts? The
next proposition answers this question in a more abstract setting.
Let S be a finite set. Recall that a permutation π on S is a bijection on S.
The permutation π is called a derangement if and only if it is fixedpoint-free,
so πpxq ‰ x holds for all x P S.
Proposition 11.41. The number of derangements on a set T of n elements
is given by
n
ÿ p´1qk
n! .
k“0
k!
Proof. Let T “ tt1 , t2 , . . . , tn u. Let S denote the set of all permutations from
the set T to itself. We denote by Tk the subset of T consisting of permu-
tations π such that πptk q “ tk . For I “ ti1 , . . . , ik u Ď t1, . . . , nu, the set
TI “ Ti1 X ¨ ¨ ¨ X Tik has cardinality pn ´ kq!, since the permutations in TI fix
k elements and permute the remaining n ´ k elements in an arbitrary fashion.
By Corollary 11.38, the number of permutations that do not fix any elements
is given by
n n n
p´1qk
ˆ ˙
ÿ n ÿ n! ÿ
p´1qk pn ´ kq! “ p´1qk “ n! ,
k“0
k k“0
k! k“0
k!
Exercises
11.46. How many bit strings of length 8 start with 1 or end with 00?
11.49. Use the inclusion-exclusion formula to find the number of integral so-
lutions to x1 ` x2 ` x3 ` x4 “ 25 such that xk is in the range 0 ď xk ď 10 for
k P t1, 2, 3, 4u.
11.50. Suppose that you are given a book with pages numbered from 1 to
500. Use the inclusion-exclusion formula to determine the number of pages
that contain a 1 in the page number.
Figure 11.5: There are five points on the sphere. A great circle through the points
a and b is shown, which divides the sphere into two hemispheres, an upper and a
lower hemisphere. Since there are three remaining points, at least two must be in the
same (upper or lower) hemisphere. The points in the upper hemisphere are depicted
by a bullet ‚ and the point in the lower hemisphere is depicted by a circle ˝
Example 11.47. Suppose that we are given a string of length 500 over the
alphabet ta, b, . . . , zu of lower case letters. Then at least one letter must occur
R V
500
“ r19.2307 ¨ ¨ ¨ s “ 20
26
or more times.
Example 11.48. Ernie is rolling four dice 100 times. Each time, he records
the sum of face values of the dice. For instance, if Ernie rolls then he
records the sum 4 ` 5 ` 2 ` 6 “ 17. Evidently, all sums could be the same, but
this is unlikely to occur. Bert wants to know how many sums are guaranteed
to be the same (even in the most unfavorable situation)?
Ernie enthusiastically attempts to write down all possible sequences of 100
die rolls. Bert is flabbergasted and interrupts him. Bert points out that there
are 64 “ 1296 different combinations of face values of four dice, and Ernie
cannot possibly write down all sequences of 100 rolls, as 1296100 is more than
100 duocentillion. Bert points out that it will take too long to get an answer
to his question.
Ernie informs Bert that he already knows the answer. He explains to Bert
that the sum of the face values of the four dice ranges from 4 to 24, so there
are 21 different sum values. Ernie further elaborates that one sum value must
occur at least R V
100
“5
21
times by the Strong Pigeonhole Principle. Ernie chuckles and goes back to
writing down die roll sequences.
Example 11.49. The Isaac Stern Auditorium in Carnegie Hall can fit 2840
people. In a sold out performance, there must be at least five people having
the exact same first and last initial. Indeed, there are 26 ˆ 26 “ 676 different
298 11 Counting
You can find more examples of the pigeonhole principle in Chap. 14.
Exercises
11.51. Mr. Bocks has a drawer that contains 12 pairs of socks. They all have
a different color, so they do not match up well. During a power outage, he is
not able to see the colors. How many socks should he grab from the drawer to
ensure that he gets a pair with matching colors?
11.52. Mr. Bocks bought new socks. His drawer still contains 12 pairs of
socks. However, he now has six pairs of white socks, two pairs of beige socks,
one pair of red socks, and three pairs of blue socks. There is again a power
outage, and he is not able to see the colors of his socks. How many socks should
he grab from the drawer to ensure that he gets a pair with matching colors?
11.53. Choose seven different integers from the set U “ t1, 2, . . . , 12u. Show
that at least two of the seven integers need to sum to 13.
11.54. Color each point in the Euclidean plane R2 either red or blue. For any
coloring, show that there are two points of the same color that are at distance
1 from each other.
11.55. (a) Show that if five points are placed anywhere inside a closed equi-
lateral triangle of side length 1, then at least two of the five points will be no
farther apart than 1{2. (b) How many points are guaranteed to be within a
Euclidean distance of 1/2 if 17 points are placed inside the triangle?
11.56. Suppose that 101 Dalmatians are locked in a square room that has an
area of 400ft2 . Use the pigeonhole principle to show that at any point in time
there are at least two Dalmatians that are less than 3 feet apart.
11.57. Show that every positive integer n has a nonzero integer multiple whose
digits consist entirely of 0s and 1s.
11.59. Suppose that n people attend a party in a posh new restaurant. Show
that there are two people at the party that have the same number of friends
at the party. You can assume that the friends’ relationship is symmetric and
11.8 Notes 299
irreflexive and that at least two people attend the party. [Hint: People without
friends are a bit suspicious and people that are friends with everyone are a bit
overbearing. Investigate them!]
11.8 Notes
Counting is at the heart of enumerative combinatorics. It is discussed in almost
every book on discrete mathematics or enumerative combinatorics. Aigner
discusses the basics of counting in [4] and more advanced techniques in [2] and
[3]. Graham, Knuth, and Patashnik [30] systematically develop many facts
about counting coefficients. Jukna [43] gives more applications of counting.
Moll [62] contains a wealth of material on counting coefficients. The seminal
work by Stanley [72, 73] is a good place to start if you are interested in more
advanced techniques of enumerative combinatorics. There are even entire books
dedicated to counting, see for example Beeler [8]. The book by Benjamin and
Quinn [9] is entirely dedicated to combinatorial proofs.
Chapter 12
Generating Functions
A generating function is a device somewhat similar to a bag. Instead
of carrying many little objects detachedly, which could be embarrass-
ing, we put them all in a bag, and then we have only one object to
carry, the bag.
— George Pólya, Mathematics and Plausible Reasoning, Volume 1
Some counting problems are difficult to solve by a direct approach. For ex-
ample, we often want to count the number of elements in a set that have a
certain property. Euler and Laplace introduced generating functions that can
often help. At first sight it might appear as a mere change of representation,
but solutions using generating functions can be surprisingly effective. In the
next chapter, we will see how generating functions can help solving recurrence
relations.
So each value from 1 to 6 occurs precisely once, and all other values do not
occur. The generating function of the normal die is
Dpzq “ z ` z 2 ` z 3 ` z 4 ` z 5 ` z 6 .
The exponents represent the face values. As each face value occurs only once,
rz k sDpzq “ 1 for all values k in the range 1 ď k ď 6. Suppose that we want to
know in how many different ways a pair of normal dice will yield a sum of 7.
Since the problem is so small, we could simply list all possible cases. So here
are the only combinations of the pair of dice that sum to 7:
Dpzq2 “ z 2 ` 2z 3 ` 3z 4 ` 4z 5 ` 5z 6 ` 6z 7 ` 5z 8 ` 4z 9 ` 3z 10 ` 2z 11 ` z 12 .
so it has the 2 and 3 repeated twice, and the largest value is a 4. The second
die has the following six sides
The generating functions of the face values of the first and second die are
given by
The coefficient rz k sCpzq counts the number of times the value k occurs on the
first die. For instance rz 3 sCpzq “ 2, since the value 3 occurs twice. Multiplying
the two generating functions yields
CpzqW pzq “ z 2 ` 2z 3 ` 3z 4 ` 4z 5 ` 5z 6 ` 6z 7 ` 5z 8 ` 4z 9 ` 3z 10 ` 2z 11 ` z 12 ,
which is exactly the same distribution of values as for a pair of standard dice.
In other words, even though each die is a bit wacky, their sums behave exactly
in the same way as the sum of a pair of normal dice. It is quite remarkable that
one can obtain a fair sum of dice values from dice that are not all fair. The
generating function allowed us to quickly check this fact without much hassle.
Exercises
12.1. Show that apart from the pair of normal dice and the pair of crazy
dice there cannot exist any other pair of dice such that the product of their
generating functions is equal to
P pzq “ z 2 ` 2z 3 ` 3z 4 ` 4z 5 ` 5z 6 ` 6z 7 ` 5z 8 ` 4z 9 ` 3z 10 ` 2z 11 ` z 12 ,
assuming that (a) the face values are at least 1 and (b) each die has 6 faces.
[Hint: Factor the polynomial P pzq over the rational numbers and inspect all
possible combinations of factors.]
12.2. Let us use the notations of Example 12.2. Find all terms z a and z b in
Cpzq and W pzq, respectively, such that z a`b “ z 6 . Explain in your own words
why there must be five such pairs.
12.4. Grandpa Dell found 20 collectible baseball cards that he wants to divide
among his three grandchildren. Since the oldest grandson Albert just helped
with the dishes, he wants to give him an even number of baseball cards, so
that Albert receives at least eight but not more than 14 baseball cards. The
younger grandchildren Bella and Clara should each receive an odd number of
baseball cards; they should get at least three and at most nine cards, but not
necessarily the same number of cards. In how many different ways can grandpa
Dell distribute the 20 cards subject to these rules?
where ak and bk are real numbers for all nonnegative integer indices k.
The sum Apzq ` Bpzq is defined as
8
ÿ
Apzq ` Bpzq “ pak ` bk qz k .
k“0
ApzqBpzq “ 1,
so all terms in the product vanish except the constant term. If a multiplicative
inverse Bpzq of the power series Apzq in Rrrzss exists, then we can express Apzq
also in the form
1
Apzq “ .
Bpzq
This form is particularly useful when Bpzq is a polynomial. Among other
things, it will allow us to find a closed-form expression for the Fibonacci num-
bers.
Not all formal power series have a multiplicative inverse. The next propo-
sition gives a simple criterion for the existence of a multiplicative inverse.
ř8
Proposition 12.3. A formal power series Apzq “ k“0 ak z k has a multiplica-
tive inverse if and only if a0 ‰ 0.
ř8
Proof. Suppose that Bpzq “ k“0 bk z k is a multiplicative inverse of Apzq.
Then we must have
rz 0 sApzqBpzq “ a0 b0 “ 1,
which implies that a0 ‰ 0.
12.2 Operations on Generating Functions 305
Conversely, suppose that Apzq is a formal power series with nonzero con-
stant coefficient
ř8 rz 0 sApzq “ a0 ‰ 0. Then the putative inverse power series
Bpzq “ k“0 bk z k must satisfy b0 “ 1{a0 . Let us now consider the coeffi-
cients bk with nonzero index. Suppose that we have already determined the
coefficients b0 , . . . , bk´1 . Then we can define bk by the expression
k
1 ÿ
bk “ ´ a bk´ .
a0 “1
Indeed, all coefficients in the sum on the right-hand side are defined, and a0 ‰ 0,
so forming the quotient ´1{a0 is valid. If we multiply both sides by ´a0 , then
we obtain
ÿk
´a0 bk “ a bk´ .
“1
The next example shows how to determine the multiplicative inverse of the
constant 1 sequence.
Example 12.4. Let Apzq denote the generating function of the constant se-
quence a “ p1, 1, 1, . . .q, so
8
ÿ
Apzq “ zk .
k“0
Then
8
ÿ 8
ÿ
zApzq “ z k`1 “ z k “ Apzq ´ 1.
k“0 k“1
It follows that
1 “ Apzq ´ zApzq “ Apzqp1 ´ zq.
Therefore Bpzq “ p1 ´ zq is the multiplicative inverse of Apzq. For this reason,
we often write
8
1 ÿ
“ zk .
1 ´ z k“0
In this case, we even have convergence for all z satisfying |z| ă 1, since this is
a geometric series.
The next example illustrates the product of two formal power series.
306 12 Generating Functions
Example 12.5. Let Apzq denote the generating function of the constant se-
quence a “ p1, 1, 1, . . .q, so
8
ÿ
Apzq “ zk .
k“0
Then ˜ ¸
8
ÿ k
ÿ 8
ÿ
ApzqApzq “ 1 ¨ 1 zk “ pk ` 1qz k .
k“0 “0 k“0
pa0 , a0 ` a1 , a0 ` a1 ` a2 , a0 ` a1 ` a2 ` a3 , . . .q.
pa0 , a0 ` a1 , a0 ` a1 ` a2 , a0 ` a1 ` a2 ` a3 , . . .q,
as claimed.
Suppose that the sequence pa0 , a1 , a2 , . . .q has the generating function Apzq,
then the right-shifted sequence
p0, . . . , 0, a0 , a1 , a2 , . . .q
loomoon
k zeros
Apzq ´ 1 1 ´ p1 ´ zq2 2 z
“ 2
“ 2
´ .
z zp1 ´ zq p1 ´ zq p1 ´ zq2
This equation asserts that the doubled sequence p2, 4, 6, . . .q minus the right-
shifted sequence p0, 1, 2, . . .q is equal to the left-shifted sequence p2, 3, 4, . . .q.
pa0 , a1 , a2 , . . .q
d
Then dz Apzq is the generating function of the sequence pa1 , 2a2 , 3a3 , . . .q that is
multiplied by a proportionality factor. However, this also shifts the sequence
to the left. We can compensate for the left shift of the differential operator
d
by multiplying it with z. Thus, pz dz qApzq is the generating function of the
sequence
p0a0 , 1a1 , 2a2 , 3a3 , . . .q
that multiplies each term by its index.
d
Let D denote the differential operation D “ dz .
Proposition 12.9. Let Apzq denote the generating function of the sequence
pa0 , a1 , a2 , . . .q. Let P pxq denote a polynomial with real coefficients. Then the
sequence pP p0qa0 , P p1qa1 , P p2qa2 , . . .q has the generating function P pzDqApzq.
In particular, zDApzq is the generating function of p0a0 , 1a1 , 2a2 , 3a3 , . . . q.
ř8
Proof. The generating function of pa0 , a1 , a2 , . . .q is given by Apzq “ k“0 ak z k .
Then
ÿ8 ÿ8
zDApzq “ z pk ` 1qak`1 z k “ kak z k
k“0 k“0
as claimed.
of the constant one sequence p1, 1, 1, . . .q, then we obtain the generating func-
tion
8
zk
ˆ ˙
1 ÿ
ln “ .
1´z k“1
k
of the sequence p0, 1, 1{2, 1{3, . . .q.
ř8
If we are given a formal power series Apzq “ k“0 ak z k and a positive
integer m, then the power Apzqm is given by
˜ ¸
8
ÿ ÿ
ak1 ak2 ¨ ¨ ¨ akm z k .
k“0 k1 `k2 `¨¨¨`km “k
The inner sum ranges over all m-tuples pk1 , k2 , . . . , km q of nonnegative integers
such that k1 ` k2 ` ¨ ¨ ¨ ` km “ k.
As an application, we record the following important consequence.
Proposition 12.11. If m is a positive integer, then
8 ˆ ˙
1 ÿ m`k´1 k
“ z .
p1 ´ zqm k“0
k
Proof. Since
8
1 ÿ
Apzq “ “ zk ,
1 ´ z k“0
310 12 Generating Functions
is the generating function of the constant one sequence, its m-th power is given
by
˜ ¸
8
ÿ ÿ
m
Apzq “ ak1 ak2 ¨ ¨ ¨ akm z k
k“0 k1 `k2 `¨¨¨`km “k
˜ ¸
8
ÿ ÿ
“ 1 zk
k“0 k1 `k2 `¨¨¨`km “k
as claimed.
Exercises
ř8
12.5. Let Apzq “ 1{p1 ´ zq “ k“0 z k be the generating function of the
constant one sequence p1, 1, 1, . . .q. Then Apzq2 is the generating function of
the sequence p1, 2, 3, 4, . . .q. Determine the power series of Apzq3 using the
product of Apzq2 and Apzq. The coefficients of the formal power series of
Apzq3 “ p1 ´ zq´3 should look familiar. Identify them.
12.6. Let Apzq be the generating function of the sequence pa0 , a1 , a2 , a3 , . . .q.
Determine the generating functions of the sequences
pa0 , loomoon
0, . . . , 0, a1 , loomoon
0, . . . , 0, a2 , loomoon
0, . . . , 0, a3 . . .q
m zeros m zeros m zeros
and
pa0 , 0, . . . , 0, ra1 , 0,
loomoon . . . , 0, r2 a2 , 0,
loomoon . . . , 0, r3 a3 . . .q,
loomoon
m zeros m zeros m zeros
p1, 0, 1, 0, 1, 0, ¨ ¨ ¨ q
in closed form (that is, as a rational function) and find its multiplicative inverse.
12.8. Determine the generating function of the sequence
in closed form (that is, the generating function should be given as a rational
function).
12.3 Elementary Generating Functions 311
ř8
12.9. Let Apzq “ k“0 ak z k denote the generating function of the sequence
pa0 , a1 , a2 , . . .q. Determine the generating function of the sequences
pa0 , 0, a2 , 0, a4 , 0, . . .q and p0, a1 , 0, a3 , 0, a5 , . . .q
as a linear combination of terms of the form Aprzq, where r is a real number.
12.10. Suppose that Apzq denotes the generating function of the sequence
pa0 , a1 , a2 , . . .q. Determine the generating function of the sequence
pa0 , a1 ´ a0 , a2 ´ a1 , a3 ´ a2 , . . .q.
We obtained this result from right-shifting the sequence p1, 2, 3, 4, . . . q that has
the generating function 1{p1 ´ zq2 , as we have seen in the previous section.
Example 12.14. The sequence s “ p0, 1, 4, 9, 16, . . .q of squares has the gen-
erating function
8
zp1 ` zq ÿ
“ k2 z k .
p1 ´ zq3 k“0
Indeed, the sequence p0, 1, 2, 3, 4, . . .q has the generating function z{p1 ´ zq2 .
Taking the formal derivative yields the sequence p1, 4, 9, 16, . . .q with generating
function
d z 1`z
“ .
dz p1 ´ zq2 p1 ´ zq3
Right-shifting yields the generating function of the sequence s.
Example 12.15. The sequence p0, 11 , 12 , 13 , ¨ ¨ ¨ q of reciprocals of n has gener-
ating function
8
zk
ˆ ˙
1 ÿ
ln “ .
1´z k“1
k
312 12 Generating Functions
Example
`` ˘ ` 12.16.
˘ ` ˘ Let ˘ n be a nonnegative integer. The binomial sequence
s “ n0 , n1 , n2 , . . . has the generating function
8 ˆ ˙
ÿ n k
Spzq “ z .
k“0
k
Since the binomial coefficient nk “ 0 when k exceeds n, the power series Spzq
` ˘
as a generating function.
1 1
Example 12.20. The sequence p0, 1, 0, ´ 3! , 0, 5! , 0, . . .q has the sine function
8
x3 x5 x7 x9 ÿ x2k`1
sinpxq “ x ´ ` ´ ` ` ¨¨¨ “ p´1qk
3! 5! 7! 9! k“0
p2k ` 1q!
as a generating function.
Example 12.21. The sequence p0, 1, 0, 13 , 0, 15
2 17
, 0, 315 62
, 0, 2835 , . . .q has the gen-
erating function
1 2 17 7
tanpxq “ x ` x3 ` x5 ` x ` ¨¨¨
3 15 315
Exercises
12.11. The generating function of the sequence p1, 2, 4, 8, 16, . . .q of powers of
two is given by
ÿ8
Apzq “ 2k z k .
k“0
Find a closed form of the generating function Apzq that does not use a power
series.
12.12. Let a and d ą 0 be real numbers. Find a closed form of the generating
function of the arithmetic progression
pa, a ` d, a ` 2d, a ` 3d, . . .q.
The closed form is an expression for the generating function that does not use
a power series.
12.13. Let a and r ‰ 0 be real numbers. Find a closed form of the generating
function of the geometric progression
pa, ar, ar2 , ar3 , . . .q.
The closed form is an expression for the generating function that does not use
a power series.
12.14. Use the binomial series
` ˘to prove that the generating function of the
central binomial coefficients 2n
n is given by
8 ˆ ˙
1 ÿ 2k k
? “ z .
1 ` 4z k“0 k
314 12 Generating Functions
f0 ` f1 ` f2 ` ¨ ¨ ¨ ` fn “ fn`2 ´ 1
using generating functions. You can use the fact that the Fibonacci numbers
have the generating function
8
ÿ z
fk z k “ ,
k“0
1 ´ z ´ z2
H1 ` H2 ` ¨ ¨ ¨ ` Hn “ pn ` 1qHn ´ n.
12.4 Giving Change 315
The generating functions for the number of nickels, dimes, and quarters are
respectively given by
1 1 1
N pzq “ , Dpzq “ , Qpzq “ .
1 ´ z5 1 ´ z 10 1 ´ z 25
In principle, the answer to the counting problem is
rz c sP pzqN pzqDpzqQpzq.
This is obvious, since there are no other options than giving c pennies.
If we have pennies and nickels available, then the problem becomes a bit
more interesting. Let us write the product P pzqN pzq in the form
8
1 1 ÿ
P pzqN pzq “ “ nk z k .
1 ´ z 1 ´ z5 k“0
316 12 Generating Functions
Then
8
ÿ
P pzq “ p1 ´ z 5 qP pzqN pzq “ p1 ´ z 5 q nk z k .
k“0
Example 12.22. The number of ways to give change for c “ 11 cents using
pennies and nickels is given by t11{5u ` 1 “ 3. This makes sense, as you
have three choices: either use two nickels, merely one nickel, or no nickels
at all. Once you have decided which of the three options you would like to
choose, then there is no other option than giving the remainder in pennies,
and there is just one way to do that. By the multiplication principle, there
are 3 ˆ 1 solutions. The solutions are explicitly given by (a) 5 , 5 , 1 , (b)
5 , 1 , 1 , 1 , 1 , 1 , 1 , and (c) 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 .
If we have pennies, nickels, and dimes available, then the solutions become
quite a bit more varied, but our approach remains the same. We simply try to
reduce the problem to smaller cases. We write the product P pzqN pzqDpzq in
the form
8
1 1 1 ÿ
P pzqN pzqDpzq “ “ dk z k .
1 ´ z 1 ´ z 5 1 ´ z 10 k“0
Thus, the coefficient dk denotes the number of ways to give change to k cents
using pennies, nickels, and dimes. Multiplying by 1 ´ z 10 yields
8
ÿ
P pzqN pzq “ p1 ´ z 10 q dk z k .
k“0
Example 12.23. Suppose that we want to know the number of ways to give
change for 75 cents using pennies, nickels, dimes, and quarters. In other words,
we would like to calculate q75 . We have
d75 “ 16 ` 14 ` 12 ` 10 ` 8 ` 6 ` 4 ` 2 “ 72
d50 “ 11 ` 9 ` 7 ` 5 ` 3 ` 1 “ 36
d25 “ 6 ` 4 ` 2 “ 12
d0 “ 1
ways to make change for 75 cents using pennies, nickels, dimes, and quarters.
Exercises
12.21. In how many different ways can you make change for 89 cents using
pennies, nickels, dimes, and quarters?
12.22. Let qk denote the number of ways to give change for k cents using
pennies, nickels, dimes, and quarters. Find a structure in the generating func-
tion of pqk q which implies that if k is a nonnegative integer such that k ” 0
pmod 5q, then qk “ qk`1 “ qk`2 “ qk`3 “ qk`4 .
12.23. The country of Binoria uses 1, 2, 4, and 8 cent coins. In how many
different ways can you give change for 75 cents using the Binorian denomina-
tions?
Chapter 13
Recurrence Relations
Running away, then returning. My present was feeding on my past,
and my future was waiting for the recursive loop to complete.
— Steve Saroff, Paper Targets
I wish my wish would not be granted!
— Douglas Hofstadter, Gödel, Escher, Bach
In this chapter, we show how generating functions can be used to solve re-
currence relations. We first introduce the basic terminology and then give an
example that illustrates the method for a particularly simple recurrence rela-
tion. We obtain a closed form for the coefficients of the Fibonacci sequence.
Before generalizing this result, we review the partial fraction decomposition.
We then show how to find closed-form solutions for linear homogeneous recur-
rence relations. We illustrate how generating function can even help when the
recurrence relations are nonlinear using the recurrence for the Catalan numbers
as an example.
8 “ 2 ` 2 ` 2 ` 2 “ 2 ` 3 ` 3 “ 3 ` 2 ` 3 “ 3 ` 3 ` 2.
Exercises
13.1. The Tribonacci numbers are given by t0 “ 0, t1 “ 0, t2 “ 1, and the
recurrence relation
tn “ tn´1 ` tn´2 ` tn´3
for all integers n ě 3. Find the first 21 terms pt0 , t1 , t2 , t3 , . . . , t20 q of the
Tribonacci sequence.
13.2. Write a program that on input of an integer n calculate the n-th Tri-
bonacci number tn . Use this program to find t302 .
13.3. Give a recursive formulation of the sequence pmk qkě0 , where mk “ tk{3u.
Give the initial condition and the recurrence relation.
13.4. Find a recursive formulation of the sequence ppk qkě0 of the powers of 2,
pp0 , p1 , p2 , p3 , p4 , . . .q “ p1, 2, 4, 8, 16, . . .q.
Give the initial condition and the recurrence relation.
13.5. The centered hexagonal number is a figurate number hn that counts
a hexagon and its neighbors on a hexagonal grid as follows. The number
h1 “ 1 counts a single central hexagon. The number h2 “ 1 ` 6 “ 7 counts the
central hexagon and its six neighbors on the hexagonal grid. The number h3 “
19 counts the central hexagon, its six direct neighbors, and the neighbors of
those neighbors. The next number simply includes another layer of neighbors.
Figure 13.1 illustrates the counting numbers h1 , h2 , h3 , and h4 .
We also define h0 “ 0. Give the initial conditions and recurrence relation
for the sequence of central hexagonal counting numbers phn qně0 .
322 13 Recurrence Relations
Figure 13.1: The counting number hn counts how many fields are occupied by a
discrete hexagon on the hexagonal grid that is centered about a single hexagon and
has side length n. The aforementioned four figures illustrate from left to right the
discrete hexagons that are associated with the central hexagonal counting numbers
h1 “ 1, h2 “ 7, h3 “ 19, and h4 “ 37
and the empty product in particular as 0!! “ 1. Give the initial conditions and
the recurrence relation.
13.8. In general, there are many different recursive formulations for a given se-
quence. For example, prove that the sequence pqn qně0 satisfying the recurrence
relation qn “ qn´1 ´ qn´5 for integers n ě 5 and the initial conditions q0 “ 1,
q1 “ 1, q2 “ 1, q3 “ 2, and q4 “ 2 coincides with the Padovan sequence ppn qně0
satisfying the recurrence relation pn “ pn´2 ` pn´3 for n ě 3 and the initial
conditions p0 “ 1, p1 “ 1, and p2 “ 1. In other words, the Padovan sequence
ppn qně0 satisfies the same recurrence equation as the sequence pqn qně0 .
13.2 A Motivating Example 323
13.9. The Fibonacci sequence pfn qně0 satisfies the recurrence relation fn ´
fn´1 ´ fn´2 “ 0 for n ě 2 and the initial conditions f0 “ 0 and f1 “ 1. Form
the quotients rn “ fn`1 {fn of subsequent Fibonacci numbers.
(a) Find the numerical values of the first 10 well-defined quotients r1 , r2 , . . . , r10 ,
rounded to 3 digits.
? quotients satisfy rn “ 1 ` 1{rn´1 .
(b) Prove that the
(c) Let φ “ p1` 5q{2 « 1.618 denote the golden ratio. Show that φ “ 1`1{φ.
(d) Use parts (b) and (c) to show that |rn ´ φ| ď φ1 |rn´1 ´ φ|.
(e) Use part (d) to show that limnÑ8 |rn ´ φ| “ 0 and deduce that
fn`1
lim “ lim rn “ φ.
nÑ8 fn nÑ8
Using the definition of the coefficients hn , we can rewrite this formal power
series in the form
ÿ8
Hpzq “ h0 ` phk´1 ` 2k ´ 1qz k .
k“1
The three sums of the right-hand side are all simple variations of generating
functions that we are familiar with. The first sum is a shifted version of Hpzq,
namely
ÿ8 8
ÿ
hk´1 z k “ hk z k`1 “ zHpzq.
k“1 k“0
The second sum is a scaled version of the generating function of the sequence
p0, 1, 2, 3, 4, . . .q from Example 12.13,
8 8
ÿ ÿ 2z
2kz k “ 2 kz k “ .
k“1 k“0
p1 ´ zq2
The last sum is the negation of the generating function of the constant one
sequence from Example 12.12 shifted to the right,
8
ÿ z
p´1qz k “ ´ .
k“1
1´z
If we substitute these results back into the Eq. (13.1), then we get
2z z
Hpzq “ zHpzq ` ´ .
p1 ´ zq2 1´z
Subtracting zHpzq from both sides yields
2z z
Hpzq ´ zHpzq “ p1 ´ zqHpzq “ ´ .
p1 ´ zq2 1´z
Dividing by 1 ´ z and bringing to a common denominator gives us
2z ´ zp1 ´ zq zpz ` 1q
Hpzq “ “ .
p1 ´ zq3 p1 ´ zq3
We recognize this generating function from Example 12.14. It is simply the
generating function of the sequence of squares p0, 1, 4, 9, 16, . . .q. In other words,
we have
8
ÿ
Hpzq “ k2 z k .
k“0
hn “ n2
Exercises
13.10. (a) Find a closed form of the generating function of the sequence
phn q8
n“0 given by the recurrence relation
If we use the distributive law and the fact that f0 “ 0, then we can rewrite
this in the form
8
ÿ 8
ÿ
F pzq “ z ` fk´1 z k ` fk´2 z k
k“1 k“2
“ z ` zF pzq ` z 2 F pzq.
c ` d “ 0,
´ρ2 c ´ ρ1 d “ 1.
? ?
It follows that ρ2 d ´ ρ1 d “ pρ2 ´ ρ1 qd “ 1, so d “ ´1{ 5 and c “ 1{ 5.
Therefore, we found the coefficients c and d of the representation (13.2).
The reason why we chose the representation (13.2) is that the terms
c d
and
1 ´ ρ1 z 1 ´ ρ2 z
are easy to expand into power series with explicitly known coefficients, since
they are just given by geometric series
8 8
c ÿ d ÿ
“c ρk1 z k and “d ρk2 z k .
1 ´ ρ1 z k“0
1 ´ ρ2 z k“0
˜ˆ ? ˙k ˆ ? ˙k ¸
1 1` 5 1´ 5
fk “ ? ´
5 2 2
Exercises
ˆ ? ˙n
1 1` 5
fn „ ? .
5 2
13.13. Let us denote by rxu the nearest integer function given by rxu “
tx ` 1{2u. Show that
S ˆ ? ˙n _
1 1` 5
fn “ ?
5 2
13.14. Derive a closed form for the generating function for the sequence
pf2n q8
n“0 of even-indexed Fibonacci numbers. [Hint: Use the fact that the
generating function of the sequence pfn q8
n“0 of Fibonacci numbers is given by
F pzq “ z{p1 ´ z ´ z 2 q.]
8
ÿ fn
.
n“0
2n
where ai and bi are complex numbers, ai ‰ 0, and the roots ri “ ´bi {ai of the
linear terms are pairwise distinct. In other words, the root ri “ ´bi {ai occurs
with multiplicity di in the polynomial qpzq.
The partial fraction decomposition expresses the rational function ppzq{qpzq
as a linear combination of the partial fractions
1
,
paj z ` bj qmj
where mj is an integer in the range 1 ď mj ď dj and the integer j is an integer
in the range 1 ď j ď k.
The precise statement of the partial fraction decomposition is given in the
next proposition. We adapt the inductive argument given in Walter [78] to the
slightly more general form of the partial fraction decomposition that we use
here.
Proposition 13.3. Let ppzq{qpzq be a rational function such that deg p ă deg q
and qpzq is a polynomial with the factorization (13.3). Then there exist complex
numbers Ci,j such that
k ˆ ˙
ppzq ÿ Ci,1 Ci,2 Ci,di
“ ` ` ¨ ¨ ¨ ` .
qpzq i“1 ai z ` bi pai z ` bi q2 pai z ` bi qdi
Proof. We will prove the claim about the existence of the partial fraction de-
composition by strong induction on the degree n “ deg qpzq of the polynomial
qpzq in the denominator.
Induction Basis When the polynomial qpzq has degree n “ 1, then ppzq must
have degree 0, so it must be a constant. Therefore, ppzq{qpzq is of the claimed
form.
Induction Step Suppose that every proper rational function with denominator
polynomial of degree less than n has a decomposition of the claimed form.
13.4 Partial Fractions 329
Suppose further that we are given a proper rational function ppzq{qpzq with
n “ deg q. Let r1 “ ´b1 {a1 denote a root of the polynomial qpzq of multiplicity
d1 ě 1. This means that we can factor qpzq in the form
Since r1 is a root of the numerator, we can rewrite this expression in the form
ppzq ppzq
“
qpzq pa1 z ` b1 qd1 apzq
Since the decompositions are different, there must exist some index μ such that
Cμ,j “ Dμ,j does not hold for all indices j. Let cμ denote the largest index
330 13 Recurrence Relations
such that Cμ,cμ ‰ Dμ,cμ . If we multiply both sides of the previous equation by
paμ z ` bμ qcμ and let z Ñ rμ “ ´bμ {aμ , then we get
k ÿ di
ÿ pCi,j ´ Di,j qpaμ z ` bμ qcμ
lim “ 0.
zÑrμ
i“1 j“1
pai z ` bi qj
Let us now examine the behavior of the individual terms of this expression.
Since paμ z ` bμ qcμ {pai z ` bi qj Ñ 0 as z Ñ rμ for all i ‰ μ, and pai z `
bμ qcμ {pai z ` bμ qj Ñ 0 as z Ñ rμ for all j ă cμ , we can conclude that
k ÿ di
ÿ pCi,j ´ Di,j qpaμ z ` bμ qcμ
lim “ Cμ,cμ ´ Dμ,cμ “ 0,
zÑrμ
i“1 j“1
pai z ` bi qj
Exercises
13.16. Find the partial fraction decomposition of
2z ` 1
.
z2 ` z
13.17. Find the partial fraction decomposition of
3z 2 ` 7z ` 1
.
zpz ` 1q2
13.18. Find the partial fraction decomposition of
2z ` 36
.
z2 ` 4
13.19. Find the partial fraction decomposition of
z`1
.
1 ´ 4z ` 3z 2
13.20. Find the partial fraction decomposition of
1
.
1 ´ x2
for some pairwise distinct complex numbers ak and positive integers dk such
that d1 ` d2 ` ¨ ¨ ¨ ` dm “ d.
332 13 Recurrence Relations
for some complex numbers ak that are pairwise distinct and positive integers
dk such that d1 ` d2 ` ¨ ¨ ¨ ` dm “ d. Since the reciprocal polynomial of cR pzq
is given by cpzq, we have
m ˆ ˙d k m
ź 1 ź
cpzq “ z d cR p1{zq “ z d ´ ak “ p1 ´ ak zqdk ,
k“1
z k“1
as claimed.
Example 13.6. For the Fibonacci sequence, the polynomial cpzq “ 1 ´ z ´ z 2 .
Factoring the reciprocal polynomial cR pzq “ z 2 cp1{zq yields
ˆ ? ˙ˆ ? ˙
R 2 1` 5 1´ 5
c pzq “ z ´ z ´ 1 “ z ´ z´ .
2 2
Therefore, we recover the factorization
ˆ ? ˙ˆ ? ˙
1` 5 1´ 5
cpzq “ 1 ´ z 1´ z
2 2
that we have used in Sect. 13.3.
Exercises
13.21. Show that a nonzero complex number r is a root of the polynomial cpzq
if and only if r´1 is a root of the reciprocal polynomial cR pzq.
13.22. Let cpzq “ 1 ´ 8z ` 15z 2 . Find complex numbers a1 and a2 such that
cpzq “ p1 ´ a1 zqp1 ´ a2 zq
by factoring the reciprocal polynomial cR pzq.
13.23. Let cpzq “ 1 ` 2z ` 3z 2 . Find complex numbers a1 and a2 such that
cpzq “ p1 ´ a1 zqp1 ´ a2 zq
by factoring the reciprocal polynomial cR pzq.
13.24. Let cpzq “ 1 ´ 6z ` 11z 2 ´ 6z 3 . Find complex numbers a1 , a2 and a3
such that
cpzq “ p1 ´ a1 zqp1 ´ a2 zqp1 ´ a3 zq
by factoring the reciprocal polynomial cR pzq.
13.25. A polynomial cpzq is called a palindromic polynomial if and only if
it coincides with its reciprocal polynomial, cpzq “ cR pzq. Let cn pzq “ pz ´ 1qn .
Determine the set of all positive integers n such that cn pzq is palindromic.
13.6 Linear Homogeneous Recurrence Relations 333
holds for all n ě d. What can we say about the generating function of the
sequence? The next proposition gives an answer to this question.
Proposition 13.7. Suppose that a sequence pg0 , g1 , g2 , . . .q satisfies the linear
homogeneous
ř8 recurrence relation (13.4) of order d. Then its generating function
Gpzq “ k“0 gk z k is a rational function
ppzq
Gpzq “ ,
cpzq
where ppzq is a polynomial of degree less than d and cpzq is the polynomial of
degree d given by
cpzq “ 1 ` c1 z ` c2 z 2 ` ¨ ¨ ¨ ` cd z d ,
which is formed by the coefficients of the recurrence relation (13.4).
Proof. We are going to show that the coefficient rz n scpzqGpzq “ 0 for all n ě d.
Since this implies that cpzqGpzq “ ppzq for some polynomial ppzq of degree less
than d, this will prove our claim.
Let us first consider the generating function Gpzq and its shifted and scaled
versions ck z k Gpzq for 1 ď k ď d. We have
ppzq
Gpzq “ ,
cpzq
where ppzq is a polynomial of degree less than d and cpzq is the polynomial of
degree d given by
cpzq “ 1 ` c1 z ` c2 z 2 ` ¨ ¨ ¨ ` cd z d ,
which is formed by the coefficients of the recurrence relation (13.4). There exist
pairwise distinct complex numbers ai such that the polynomial cpzq factors into
the form
źm
cpzq “ p1 ´ ak zqdk .
k“1
Note that each term in the sum is of a known form, see Examples 13.8 and 13.9.
13.6 Linear Homogeneous Recurrence Relations 335
Proof. It follows from the previous proposition that the generating function
Gpzq is a rational function of the claimed form. Since the constant coefficient
of the denominator polynomial cpzq is equal to 1, we can factor cpzq in the form
m
ź
cpzq “ p1 ´ ak zqdk
k“1
Exercises
13.26. Suppose that a sequence pa0 , a1 , a2 , . . .q of real numbers satisfies the
recurrence relation an ´ 5an´1 ` 6an´2 “ 0 for all n ě 2.
(a) What is the order of the linear recurrence relation?
(b) Express the generating function of the sequence as a rational function.
(c) Find a generic closed-form solution for this recurrence relation.
(d) Find the terms a0 , a1 , . . . , a5 of this sequence when the initial conditions
are given by a0 “ 2 and a1 “ 5.
(e) Find the closed-form solution when a0 “ 2 and a1 “ 5.
13.27. Suppose that a sequence pa0 , a1 , a2 , . . .q of real numbers satisfies the
recurrence relation an ` 7an´1 ` 10an´2 “ 0 for all n ě 2.
(a) Express the generating function of the sequence as a rational function.
(b) Find a generic closed-form solution for this recurrence relation.
(c) Find the terms a0 , a1 , . . . , a4 of this sequence when the initial conditions
are given by a0 “ 1 and a1 “ 4.
(d) Find the closed-form solution when a0 “ 1 and a1 “ 4.
?
13.28. The Pell sequence can be used to approximate 2. Show that
pn´1 ` pn ?
„ 2.
pn
It follows from Example 13.9 that the n-th coefficient of ppzq{cpzq is of the form
m ˆ ˆ ˙ ˆ ˙ ˆ ˙ ˙
n ppzq ÿ n n n`1 n n ` dk ´ 1 n
rz s “ Ck,1 a ` Ck,2 ak ` ¨ ¨ ¨ ` Ck,dk ak .
qpzq k“1 n k n n
is a polynomial of degree dk ´ 1 in n.
for all n ě 0.
Proof. This follows from the previous proposition by considering the special
case when all roots of the characteristic polynomial have multiplicity 1, so
d1 “ d2 “ ¨ ¨ ¨ “ dk “ 1.
Let us have a look at some examples that illustrate the previous corollary
and proposition.
338 13 Recurrence Relations
By Corollary 13.13, the closed form for the coefficients gn must be of the form
gn “ C1 3n ` C2 7n
for some complex numbers C1 and C2 . We can find the value of the constants
C1 and C2 in this generic solution using the two known initial conditions
g 0 “ 1 “ C1 ` C2 ,
g1 “ 2 “ C1 3 ` C2 7.
Solving this system of linear equations yields C1 “ 5{4 and C2 “ ´1{4. There-
fore, we can conclude that
5 n 1 n
gn “ 3 ´ 7
4 4
χpzq “ z 2 ´ 6z ` 9 “ pz ´ 3q2 .
By Proposition 13.12, the closed form for the coefficients gn must be of the
form
gn “ D1,1 3n ` D1,2 n3n
for some complex coefficients D1,1 and D1,2 . If we substitute the initial condi-
tions into this generic solution, we get the system of equations
g0 “ 1 “ D1,1 ,
g1 “ 2 “ D1,1 3 ` D1,2 3.
Solving this system of equations yields D1,1 “ 1 and D1,2 “ ´1{3. Therefore,
we can conclude that
gn “ 3n ´ n3n´1
Exercises
13.29. Let Gpzq “ ppzq{cpzq denote the generating function of a sequence sat-
isfying a linear homogeneous recurrence relation of order d. How is the charac-
teristic polynomial χpzq of the recurrence relation related to the polynomials
ppzq and cpzq?
13.30. Use the characteristic equation to find a closed form solution for the
coefficients of the sequence pg0 , g1 , g2 , . . .q satisfying g0 “ 2, g1 “ 1, and gn ´
7gn´1 ` 12gn´2 “ 0 for all n ě 2.
13.31. Use the characteristic equation to find a closed-form solution for the
coefficients of the sequence pg0 , g1 , g2 , . . .q satisfying g0 “ 2, g1 “ 2, and gn ´
2gn´1 ´ 15gn´2 “ 0 for all n ě 2.
13.32. Use the characteristic equation to find a closed-form solution for the
coefficients of the sequence pg0 , g1 , g2 , . . .q satisfying g0 “ 1, g1 “ 1, and gn ´
10gn´1 ` 25gn´2 “ 0 for all n ě 2.
13.33. Use the characteristic equation to find a closed-form solution for the
coefficients of the sequence pg0 , g1 , g2 , . . .q satisfying g0 “ 1, g1 “ 5, and gn ´
14gn´1 ` 49gn´2 “ 0 for all n ě 2.
pn ´ 2pn´1 ´ pn´2 “ 0
Proof. Let cpzq denote the reciprocal polynomial of the characteristic polyno-
mial
ř8 χc pzq, so cpzq “ χR
c pzq. By assumption, the generating function Gpzq “
k
k“0 g k z of the sequence g satisfies
rz n scpzqGpzq “ f pnq
rz n sdpzqF pzq “ 0
Therefore,
rz n sdpzqcpzqGpzq “ rz n sdpzqtpzq ` rz n sdpzqF pzq.
342 13 Recurrence Relations
If n ě degf pzq ` degc pzq, then both terms on the right-hand side are equal to
0, so
rz n sdpzqcpzqGpzq “ 0.
In other words, Gpzq satisfies a linear homogeneous recurrence relation with
characteristic polynomial χf pzqχc pzq “ dR pzqcR pzq, as claimed.
Example 13.19. The Tower of Hanoi is a puzzle consisting of three rods and
n discs of different diameters that can slide on the rods. Initially, all discs are
stacked on the leftmost rod in decreasing order of diameter with the largest
disc at the bottom and the smallest of the n discs at the top. The goal is to
transfer the stack of discs from the leftmost rod to the rightmost rod. One is
allowed to move one disc at a time, removing the upper disc of one stack and
placing it on top of another stack at a different rod. It is not allowed to place
a larger disc on top of a smaller disc.
Let tn denote the minimal number of moves that are needed to transfer n
discs from one rod to another. The minimal number of moves is given by the
recurrence relation tn “ 2tn´1 ` 1, as the top n ´ 1 discs are moved to the
middle rod in tn´1 moves, then the largest disc is moved from the leftmost to
the rightmost rod in a single move, and finally, the n ´ 1 discs from the middle
rod are moved to the rightmost rod in tn´1 moves.
We would like to find the closed form for the inhomogeneous recurrence
relation
tn ´ 2tn´1 “ 1.
The associated homogeneous recurrence tn ´ 2tn´1 “ 0 has the characteristic
polynomial z ´ 2, and the inhomogeneous part has the characteristic polyno-
mial z ´ 1. Therefore, the sequence ph0 , h1 , h2 , . . .q of the minimal number of
Hanoi tower moves has the characteristic polynomial χpzq “ pz ´ 2qpz ´ 1q.
Consequently, a closed form solution for tn must be of the form
tn “ C1 2n ` C2 1n “ C1 2n ` C2
for some constants C1 and C2 . Since the initial conditions are t0 “ 0 and
t1 “ 1, we obtain the following system of linear equations
0 “ C1 ` C2
1 “ C1 21 ` C2
Solving this system of equations yields C1 “ 1 and C2 “ ´1, so the closed form
solution is given by
tn “ 2n ´ 1
for all n ě 0.
One can extend Proposition 13.18 to other types of functions f pnq, but all
known results have some limitations on f pnq. One can always use generating
functions to solve an inhomogeneous recurrence relations, as in Sect. 13.2.
13.9 Catalan Numbers 343
Exercises
13.34. Solve the recurrence tn ´ 3tn´1 “ 2 for n ě 1 with initial condition
t0 “ 1 using characteristic polynomials. As an aside, the number tn gives the
number of triangles in the Sierpinski graph.
13.35. Let fn denote the n-th Fibonacci numbers, so f0 “ 0, f1 “ 1, and
fn “ fn´1 ` fn´2 for n ě 2. Solve the recurrence tn ´ 2tn´1 “ fn for n ě 1
with initial condition t0 “ 1 using characteristic polynomials.
13.36. Solve the recurrence relation given by tn ´ tn´1 “ n for n ě 1 and
t0 “ 0 using generating functions.
The paths are completely specified by their so-called Dyck words that de-
scribe the moves. The five paths correspond to the Dyck words URURUR, URUURR,
UURRUR, UURURR, and UUURRR.
344 13 Recurrence Relations
The basic principle of constructing the paths should now be apparent. Let
us have a look at a few more examples. We have C0 “ 1, since there is only
one way to construct a path of length 0. Similarly, we have C1 “ 1, since every
Dyck word must start with an up move U and end with a right move R. Finally,
we have C2 “ 2, since the only two valid paths from p0, 0q to p2, 2q are given
by the Dyck words URUR and UURR. Larger examples are a bit tedious without
a systematic way of enumerating the number of paths.
We can find a recursion for the Catalan number Cn by splitting the path
into two parts. Let pm, mq denote the first coordinate where the path meets the
line y “ x for the first time when starting from p0, 0q. Then we get an initial
path from p0, 0q to pm, mq, and a second path from pm, mq to pn, nq. The
initial path segment is a bit more constrained, since it does not meet the line
y “ x at any point pa, aq for any integer a in the range 0 ă a ă m. Figure 13.2
illustrates the main idea behind this approach to counting the paths that define
a Catalan number. This figure might be helpful when reading the explanation
in the following text.
Figure 13.2: Counting Catalan numbers that meet the line y “ x for the first time
at pm, mq “ p3, 3q. The Cm´1 initial paths are in the first dashed box on the lower
left, and the second segment of the path is within the upper right dashed box. The
possible initial paths start with U and end with R, and within the dashed box they
follow either URUR or UURR. The possible second paths are in this example URUR or
UURR
The initial path segment must go up U, then follow some Dyck word, before
it ends in a right move R and then meets the coordinate pm, mq. All we need
to do is count the number of paths from p0, 1q to pm ´ 1, mq that do not go
below the line y “ x ` 1. The offset by 1 is a result of the fact that the initial
path will not meet the line y “ x before pm, mq. Evidently, there are Cm´1
such initial paths, since this is simply a smaller Catalan counting problem in
a shifted grid.
Counting the number of second paths is much simpler. Indeed, the number
of paths from pm, mq to pn, nq is given by Cn´m , since it follows the same
constraints as our original problem, except that we start from pm, mq instead
of p0, 0q.
Let us now put our observations together. The number of paths from p0, 0q
that meet the line y “ x for the first time at pm, mq for some integer m in the
range 1 ď m ď n is given by Cm´1 Cn´m . Therefore, the Catalan number Cn
13.9 Catalan Numbers 345
for all nonnegative integers n. Multiplying both sides by z n and summing over
all nonnegative integers n yields
Cpzq ´ 1
“ Cpzq2 .
z
It follows that the generating function satisfies the quadratic equation
zCpzq2 ´ Cpzq ` 1 “ 0.
Solving for Cpzq yields by the quadratic formula
?
1 ˘ 1 ´ 4z
Cpzq “ .
2z
We will have to find out which choice of sign is appropriate. By the Binomial
series, we have
8 ˆ1˙
? ÿ
1 ´ 4z “ 2 p´1qk 4k z k “ 1 ´ 2z ` ´ ¨ ¨ ¨ .
k“0
k
346 13 Recurrence Relations
If we were to take the positive sign in the quadratic formula, we would obtain
?
1 ` 1 ´ 4z 1 ` p1 ´ 2z ` ¨ ¨ ¨ q 1
“ “ ´ 1 ` ¨¨¨ .
2z 2z z
However, this is not a formal power series, so we can rule out this choice.
We can conclude that
?
1 ´ 1 ´ 4z
Cpzq “ ,
2z
as claimed.
k“0
k
We first notice that all the signs cancel. If we collect the n ` 1 factors of 1{2,
then we get
1 1 ¨ 3 ¨ 5 ¨ ¨ ¨ p2n ´ 1q n`1
Cn “ 2
2 pn ` 1q!
1 ¨ 3 ¨ 5 ¨ ¨ ¨ p2n ´ 1q n
“ 2
pn ` 1q!
13.10 Notes 347
Exercises
13.37. Show that the Catalan number Cn is also given by
ˆ ˙ ˆ ˙
2n 2n
Cn “ ´ .
n n`1
13.38. Suppose that there is a group of 2n people that all have different
heights. We want to take a group photo. For the photo, we would like to
have two rows of n people each. The photographer requests that the height in
each row increases from left to right, and that every person in the second row
is taller than the person positioned directly in front. Show that there are
ˆ ˙
1 2n
Cn “
n`1 n
ways to arrange the 2n people for the photo.
13.39. A stack is a useful data structure in computer science. There are two
operations that can manipulate a stack. A pushpmq operation that will place
an element m on the top of the stack and a pop operation that will retrieve
and remove an element from the top of the stack. There is one restriction,
though. A pop operation should never be issued to an empty stack. In how
many different ways can you issue n push and n pop operations (in any order)
such that an initially empty stack will be again empty after these 2n operations,
and none of the intermediate pop operation will be issued to an empty stack.
13.10 Notes
Generating functions are an extremely useful tool in the solution of recurrence
relations. You can find a more in-depth treatment of this method in books on
enumerative combinatorics. We recommend the books by Aigner [3], Graham,
Knuth, and Patashnik [30] and Stanley [72] for further reading.
The Catalan numbers were introduced by Euler, who discussed and solved
the number of triangulations of a regular pn ` 2q-gon. They were rediscovered
by the Belgian mathematician Eugène Catalan. The Catalan numbers occur
frequently in combinatorial problems. You can find much more material about
Catalan numbers in the delightful books by Koshy [53] and Stanley [74]. Stan-
ley gives more than 200 combinatorial interpretations of Catalan numbers, so
there is a myriad of applications where these numbers occur.
Chapter 14
Graphs
The four-color conjecture was easy to state and easy to understand,
no large amount of technical mathematics is needed to attack it, and
errors in proposed proofs are hard to see, even for professionals;
what an ideal combination to attract cranks!
— Underwood Dudley, Mathematical Cranks
In this chapter, we will study the basics of undirected graphs. Graphs are
widely used to abstractly model networks, circuits, friendship relations, and
more. They find many applications in mathematics and computer science. We
focus on fundamental examples and basic principles. We introduce common
graphs and a few graph constructions, discuss connected graphs and trees. We
also include a brief discussion of planar graphs and vertex coloring of graphs,
paying tribute to the map coloring problem that inspired a large part of graph
theory.
Figure 14.1: The subway map of a fictional city. The circles denote subway stations.
We omitted the names of the stations. The different colors correspond to different
subway lines
of the salient features of the subway map, for instance, whether one station is
next to another.
Recall that in a visual representation of a graph, its vertices are depicted
by points in the plane, and its edges are represented by line segments or curves
connecting the points of the two vertices representing the edge. For instance, in
the subway example, we can represent the subway stations as vertices and edges
between any two subway stations that can be reached by a subway without
intermediate stops at other stations. Figure 14.2 gives the visual representation
of a graph corresponding to the subway map from Fig. 14.1.
Let us have a closer look at an even simpler example.
Example 14.1. Suppose that we are given the graph with four vertices and
five edges with the following visual representation
The graph pV, Eq corresponding to this visual representation has the set
14.1 Undirected Graphs 351
Figure 14.2: The graph corresponding to the subway map. There is an edge between
two vertices if and only if they correspond to adjacent subway stops
It is often very helpful to illustrate concepts in graph theory with small exam-
ples that have a succinct visual representation.
Two vertices that are connected by an edge are called adjacent. A vertex
v is called incident with an edge e if and only if v P e. Given a vertex v, the
neighborhood N pvq in a graph is the set of all vertices that are adjacent to
v in G. In other words, N pvq “ tu P V | tu, vu P Eu. The neighborhood N pvq
of v does not contain v itself. The closed neighborhood N rvs of v is defined
as the neighborhood of v with the node v included, N rvs “ N pvq Y tvu.
The degree deg v of a node v is the cardinality of its neighborhood, so
deg v “ |N pvq|.
Example 14.2. We continue our previous example. The node v1 has the neigh-
borhood N pv1 q “ tv2 , v3 , v4 u. Since the neighborhood of v1 consists of three
nodes, we have deg v1 “ 3. The node v2 has degree 2, since its neighborhood
N pv2 q contains only the two nodes v1 and v4 .
Given a graph G “ pV, Eq with finite vertex set V , we denote by δpGq the
minimal degree of the graph G, which is defined as
δpGq “ mintdeg v | v P V u.
352 14 Graphs
ΔpGq “ maxtdeg v | v P V u.
since we counted every handshake twice. Of course, we could have counted the
number h of handshakes directly, since they are recorded by the set of edges,
so we have
h “ |E|.
This double counting argument gives us the relation
In particular, the minimum degree δpGq and the maximum degree ΔpGq satisfy
the bound
δpGq ď t2m{nu and ΔpGq ě r2m{ns .
Proof. The same argument as in the previous example shows the equality
ÿ
2m “ deg v.
vPV
Since the degree of each of the n vertices is lower-bounded by δpGq and upper-
bounded by ΔpGq, we have
ÿ
nδpGq ď deg v “ 2m ď nΔpGq.
vPV
14.1 Undirected Graphs 353
Exercises
14.1. Suppose that an undirected graph G has n vertices. What is the largest
number of edges that the graph G can have?
14.5. Tony explains to his friend that he constructed a graph with five vertices,
where 2 of the vertices have degree 3, and the other three vertices have degree
2. Tony’s little brother brags that he constructed a graph with five vertices
such that two of the vertices have degree 4, and three of the vertices have
degree 3. Fact check the claim by Tony’s little brother.
14.7. Show that a graph cannot have an odd number of vertices that have odd
degree.
14.8. Suppose that five couples meet at a party. One of the couples is the host
and hostess of the party. The host asks everyone, including his wife, how many
people they shook hands with. Curiously, everyone questioned shook hands
with a different number of people. Naturally, the host did not ask himself the
question. We also know that none of the people shook hands with his or her
partner. How many people shook hands with the hostess? (Source: Zeitz)
14.10. Let G be a graph of order n, where n ě 2. Show that there must exist
two vertices in G that have the same degree.
14.11. A triangle in a graph is a subset of three distinct edges that all pairwise
intersect, meaning that they are of the form ta, bu, tb, cu, tc, au. Show that a
graph G of order n and size m has at least
ˆ ˙
m 1 2
m´ n
n 4
triangles. In particular, this shows that any graph of order n at least 3 and
size m ą n2 {4 must have at least one triangle.
Figure 14.3: The empty graph E5 with five vertices. It does not have any edges
The path graph Pn is the graph with vertex set V “ tv0 , v1 , . . . , vn´1 u
and edge set
E “ ttvk , vk`1 u | 0 ď k ă n ´ 1u.
The degree of the vertices v0 and vn´1 is 1, and the degree of vertex vk is 2
when 1 ď k ă n ´ 1. Thus, Pn is not a regular graph when n ą 2. By contrast,
14.2 Common Graphs 355
Figure 14.4: The path P5 with five vertices. There is an edge between successive
nodes
the graph P1 is 0-regular and the graph P2 is 1-regular. Figure 14.4 shows a
typical example of a path graph.
For an integer n ě 3, the cycle graph Cn is the graph with vertex set
V “ tv0 , v1 , . . . , vn´1 u and edge set
We can obtain the graph Cn from the path graph Pn by adding the edge
tvn´1 , v0 u connecting the last vertex vn´1 to the first vertex v0 . Examples of
cycle graphs are shown in Fig. 14.5.
Figure 14.7: The cycle graph Cn is bipartite if and only if n is even. For instance,
the figure on the left shows the cycle graph C6 with vertices in V1 depicted as ˝ and
vertices in V2 depicted as ‚, so this is a bipartite graph as each edge is incident to
one ˝ node and one ‚ node. The figure on the right shows the cycle graph C5 . No
matter how you partition the vertices, there is always one vertex whose neighborhood
contains both ˝ and ‚ nodes, which simply means that the graph C5 is not bipartite
One special case is worth noting. The complete bipartite graph K1,n is also
called a star graph. Figure 14.9 shows the star graph K1,6 .
Figure 14.10: The graph C5 is shown on the left and its complementary graph C5
on the right
Figure 14.11: The Cartesian product of the path graphs P4 and P3 is shown on the
right. It is self-explanatory why the Cartesian product P4 P3 is called a grid graph
If G has order n and size m, then kG has order kn and size km.
Exercises
14.12. Determine the subset B of positive integers n such that Kn is bipartite,
B “ tn | Kn is bipartiteu.
You need to prove your result. In other words, for each n, you need to give an
argument whether or not Kn P B holds.
14.13. Suppose that G is a graph of order n and size m. What is the order
and the size of its complementary graph G?
14.14. Show that the Cartesian product of graphs is associative.
14.15. Suppose that G1 is a graph of order n1 with e1 edges and G2 is a graph
of order n2 with e2 edges. Show that the Cartesian product graph G1 G2 is
a graph of order n1 n2 with n1 e2 ` n2 e1 edges.
14.16. Prove that the hypercube Qn is an n-regular graph of order 2n and size
n2n´1 .
Figure 14.13: The figure on the left shows the grid graph P3 P2 . A walk from v4
to v0 is given by
pv4 , tv4 , v1 u, v1 , tv1 , v2 u, v2 , tv2 , v3 u, v3 , tv3 , v4 u, v4 , tv4 , v1 u, v1 , tv1 , v0 u, v0 q.
The steps of this walk of length 6 are depicted in the six figures on the right. This
walk is not a trail, since it uses the edge tv4 , v1 u twice
Figure 14.14: The figure on the left shows the grid graph P3 P2 . A trail from v1
to v0 is given by
pv1 , tv1 , v4 u, v4 , tv4 , v3 u, v3 , tv3 , v2 u, v2 , tv2 , v1 u, v1 , tv1 , v0 u, v0 q.
This is indeed a trail, since it does not pass any edge twice, but it is not a path, since
it visits the vertex v1 twice
Figure 14.15: The figure on the left shows the grid graph P3 P2 . A path from v4
to v1 is given by
pv4 , tv4 , v5 u, v5 , tv5 , v0 u, v0 , tv0 , v1 u, v1 q
contain repeated vertices with the exception that the first vertex is equal to
the last vertex. Figure 14.15 gives an example of a path.
A graph G “ pV, Eq is called connected if and only if for any two distinct
vertices u and v in V there exists some path from u to v.
The next proposition gives a simple sufficient condition for connectedness.
Proposition 14.6. Let G “ pV, Eq be a graph of order n. If every pair of
non-adjacent vertices u and v in V satisfy the degree-constraint
deg u ` deg v ě n ´ 1,
360 14 Graphs
Proof. Suppose that u and v are distinct vertices in V . We are going to show
that there must exist a path between them. We distinguish the cases whether
the vertices u and v are adjacent or not.
(a) If u and v are adjacent, then there exists a path of length 1 between them.
(b) If u and v are non-adjacent vertices, then there are n´2 vertices in V ztu, vu.
By the degree constraint, the sum of the degrees of u and v is given by
deg u ` deg v ě n ´ 1. Thus, by the pigeonhole principle, there must
exist a vertex w in V ztu, vu that is adjacent to both vertices u and v. In
other words, there exists a path of length 2 between any two non-adjacent
vertices.
In conclusion, we have shown that there exists a path between any two vertices
of G, so the graph G is connected.
Cu “ tv P V | u ” vu.
Example 14.8. The empty graph En with n vertices has n “ kpEn q compo-
nents. Each component contains just a single vertex.
14.3 Connected Graphs 361
Exercises
14.17. Show that if a graph G “ pV, Eq contains a walk from a vertex u to a
vertex v, then it contains a path from u to v.
14.19. Show that a graph G of order n and size m has at least n ´ m compo-
nents; in other words, kpGq ě n ´ m.
14.4 Trees
A tree is a connected graph that does not contain any cycles. Typical examples
of trees include the star graphs K1,n for n ě 1 and the path graphs Pn for n ě 1.
Another simple example of a tree is illustrated in Fig. 14.16.
By inspecting the tree in Fig. 14.16, you might notice that there is only
one path from one vertex to another. The next proposition shows that this
property is shared by all trees.
Proposition 14.9. In a tree, any two vertices are connected by a unique path.
Proof. Let P denote a path of maximal length in T that starts from a vertex
u and ends at a vertex v. The nodes u and v cannot be adjacent to any
vertex that is not contained in P , since this would allow us to extend the path,
contradicting the maximality of the length of P . The vertex u (and similarly
the vertex v) is adjacent to precisely one vertex in P , since otherwise we would
have a cycle in T . Therefore, u and v are both vertices of degree 1, so they are
two distinct leaves.
n ` 1 “ a ` b.
By induction hypothesis, Ta has size a ´ 1 and Tb has size b ´ 1. Since the set
of edges of the tree T is given by
pa ´ 1q ` pb ´ 1q ` 1 “ a ` b ´ 1 “ n.
Exercises
14.24. Show that a graph G is a tree if there is a unique path between any
two vertices.
14.25. A graph without cycles is called a forest. Show that if a forest F of
order n has kpF q components, then it has size n ´ kpF q.
14.26. Prove that a connected graph G is a tree if and only if every edge is a
bridge.
364 14 Graphs
Example 14.15. The following planar graph G has five vertices, eight edges,
and five faces. The faces F0 , F1 , F2 , F3 , and F4 are shown in different colors.
The face F0 is the unbounded face surrounding the graph, whereas the faces
F1 to F4 are each bounded by three edges forming a triangle.
n ´ m ` f “ 2.
n ´ pm ´ 1q ` pf ´ 1q “ 2.
366 14 Graphs
Corollary 14.18. Every planar graph has at least one vertex of degree 5 or
less.
Example 14.19.
` ˘ The complete graph K5 is a connected graph of order n “ 5
and size m “ 52 “ 10. If K5 were planar, then it would satisfy m ď 3n ´ 6.
However, here we have 10 “ m ą 3n ´ 6 “ 9, so K5 cannot be a planar graph.
Exercises
14.29. Show that if n ě 5, then the complete graph Kn is not a planar graph.
14.30. Show that the complete bipartite graph K3,3 is not a planar graph.
14.6 Graph Coloring 367
14.31. Show that the Petersen graph of order 10 and size 15 (shown below) is
not a planar graph.
14.32. Let G be a planar graph of order n. Recall that ΔpGq denotes the
maximal degree of G. Let nk denote the number of vertices of degree k for
0 ď k ď ΔpGq. Show that
5
ÿ ΔpGq
ÿ
p6 ´ kqnk ě pk ´ 6qnk ` 12.
k“0 k“7
Note that this implies that G must contain a vertex of degree 5 or less.
14.33. Let G be a graph of order n ě 11. Show that either G or its complement
G is not planar.
Figure 14.17: A map of the western half of the United States. It is colored with
four different colors
planar graph. Here we require the vertices of the graph to have different colors
whenever they are adjacent. For instance, Fig. 14.18 shows the graph that is
associated with the map given in Fig. 14.17. In this example, we assigned the
same colors to the vertices that were used in the map. We will explain the
vertex color problem for arbitrary (not necessarily planar) graphs in the next
paragraph.
A vertex coloring of a graph G “ pV, Eq is an assignment of colors to the
vertices in V such that no two adjacent vertices receive the same color. Since
we merely care about the number of distinct colors rather than the particular
choice of colors, we might as well choose the elements of an arbitrary finite set
C as colors. In other words, we have no qualms using the numbers 1, 2, 3, and
4 as “colors,” since we can replace them with actual colors such as green, blue,
red, and yellow.
In other words, a vertex coloring of a graph G “ pV, Eq is a map c : V Ñ C
such that cpuq ‰ cpvq whenever u and v are adjacent vertices. If u and v are
nonadjacent vertices, then there are no restrictions on the choice of colors for
u and v.
It is easy to color any graph with a large number of colors. It is a challenge to
find a coloring that has the smallest possible number of colors. The chromatic
number χpGq of a graph G is the smallest number of colors that can be used
in any vertex coloring of G that assigns different colors to adjacent vertices.
Let us have a look at some examples.
Example 14.20. The empty graph En on n vertices has the chromatic number
χpEn q “ 1. In fact, any graph G on n vertices with χpGq “ 1 must be the
empty graph, since the existence of a single edge in G would require at least
two colors in any vertex coloring.
14.6 Graph Coloring 369
Figure 14.18: The graph corresponding to the map of the western half of the United
States. Each state is a vertex, and there is an edge between two states if and only if
they share a border (not just a corner). The vertices are colored in the same colors
as the map in Fig. 14.17. Any admissible coloring of the vertices uses different colors
for adjacent vertices
Example 14.21. The path graph Pn has chromatic number χpPn q “ 2 for all
n ě 2. Indeed, we can give the color black to the vertices with even index and
the color white to the vertices with odd index, so χpPn q ď 2. For instance, the
path graph P5 on five vertices has the vertex coloring
two colors, since Cn is not bipartite when n is odd. Therefore, χpCn q “ 3 when
n is odd and n ě 3.
Proof. Choose a coloring of G with χpGq colors and restrict it to V pHq. Then
this is a valid coloring of H with at most χpGq colors, so χpHq ď χpGq.
χpGq ě k.
The clique number ωpGq of a graph G denotes the size of a clique in G with
maximum size. Thus, the chromatic number is lower-bounded by the clique
number, χpGq ě ωpGq.
An upper bound on the chromatic number χpGq is given in the next propo-
sition.
Proposition 14.25. Let G be a graph with maximal degree ΔpGq. Then the
chromatic number of G satisfies
χpGq ď ΔpGq ` 1.
Therefore, it is not surprising that we can find lower and upper bounds on the
chromatic number of a graph in terms of its independence number.
χpGq ď n ´ αpGq ` 1.
For the lower bound, consider any vertex coloring c of G with χpGq colors
in t1, 2, . . . , χpGqu. Let Ik denote the subset of vertices with color k. Then Ik
is an independent set. Furthermore, the set of vertices V pGq is partitioned by
the sets
V pGq “ I1 Y I2 Y ¨ ¨ ¨ Y IχpGq .
Since |Ik | ď αpGq, we get
n ď χpGqαpGq.
Dividing all sides by αpGq and realizing that χpGq is an integer yields the
claimed lower bound on χpGq.
We will now prove that all planar graphs can be colored with at most five
colors. This means that all maps can be colored with at most five colors.
Proof. We argue by induction over the number of vertices. The claim certainly
holds for all planar graphs of order 5 or less.
Suppose that the claim holds for all planar graphs of order n. Consider now
a planar graph G of order n ` 1. We are going to show that G can be colored
with five colors.
The graph G contains a vertex v of degree deg v ď 5 by Corollary 14.18. If
we delete v from G, then the resulting graph G ´ v can be colored with at most
five colors by induction hypothesis. If deg v is actually strictly less than 5 or if
two neighbors of v are colored the same in this coloring of G ´ v, then there is
a color available so that we can extend the coloring of G ´ v to a coloring of G.
372 14 Graphs
It remains to deal with the case that v has degree 5 and all five neighboring
nodes u1 , u2 , u3 , u4 , u5 of v have been assigned different colors in the coloring
of G ´ v. It will ease our discussion if we assume that u1 , u2 , u3 , u4 , and u5
are respectively assigned the colors1 1, 2, 3, 4, and 5. Figure 14.19 shows the
neighborhood of v in one particular embedding of G in the plane.
Let us denote by Ha,b the induced subgraph of G ´ v consisting of the
nodes that are colored with the colors a and b, where 1 ď a, b ď 5. We will use
these subgraphs to identify ways to change our coloring of G ´ v so that we
can extend it to a five coloring of G. We begin by considering the subgraph
H1,4 . There is nothing special about the choice of the colors 1 and 4, except
that the nodes u1 and u4 are not both adjacent to the same face. We will
now distinguish whether u1 and u4 are in a different component in the induced
subgraph H1,4 or not.
Case 1. If u1 and u4 are contained in different components of H1,4 , then
we can swap the colors of 1 and 4 in the component of H1,4 that contains u1 .
This leads to another valid coloring of G ´ v that has the color 1 available at v,
see Fig. 14.20. Coloring v with the color 1 leads to the desired coloring of G
with five colors.
Figure 14.20: If u1 and u4 in different components in H1,4 , then we can swap the
colors 1 and 4 in the component that contains u1 . The right-hand side shows the
recolored neighborhood of v, which permits us to color v with the color 1
1 Of course, you are welcome to substitute your favorite five colors for the numbers from
1 to 5.
14.6 Graph Coloring 373
Figure 14.21: If u1 and u4 are in the same component of H1,4 , then there is a cycle
of nodes colored either with 1 or 4 that encloses the vertices u2 and u3 (shown on the
left) or the vertex u5 (shown on the right). In either case, this implies that there is
no path from u2 to u5 in H2,5 . In other words, u2 and u5 are in different components
in H2,5 , so we can recolor the component of u2 in H2,5 to make a color available at v
cycle C of G that encloses either u5 or both u2 and u3 . Figure 14.21 shows the
two possible resulting situations in plane embeddings.
In either case, this implies that in H2,5 there is no path from u2 to u5 ,
as this path would have to cross the cycle C, which is impossible in a planar
graph. Put differently, the vertices u2 and u5 lie in different components in
H2,5 so we can swap the colors 2 and 5 in the component containing u2 , so
the color 2 becomes available at v. We can then color v with 2 to obtain the
desired five coloring of G.
It follows by induction that any planar graph can be colored with five colors,
as claimed.
Exercises
14.34. The map shown in Fig. 14.17 was colored with four colors. It is not
surprising that we were able to do that given that the four color theorem asserts
that any map can be colored with at most four colors. Yet, some maps can
be colored with fewer colors. Show that the map given in Fig. 14.17 cannot be
colored with less than four colors. [Hint: Look at Nevada and its neighboring
states.]
14.35. Show that a graph G of order n that is not a complete graph has
chromatic number χpGq ă n.
14.36. Determine the chromatic number χpQn q of the hypercube graph on 2n
vertices with n ě 2.
14.37. Let G be a graph of size m. Show that
χpGqpχpGq ´ 1q ď 2m.
14.38. Show that a graph G has chromatic number χpGq “ 2 if and only if G
does not contain a cycle with an odd number of vertices.
374 14 Graphs
Figure 14.22: The graph on the left is Hamiltonian. Indeed, a Hamiltonian cycle
is given by pv0 , v1 , v2 , v3 , v4 , v5 , v0 q. The graph on the right is not Hamiltonian
pv1 , v2 , . . . , vn q,
14.7 Hamiltonian Cycles and Paths 375
The four interior faces are shaded, and the three outside faces are not
shaded. Notice that the unbounded face surrounding this graph is one of the
outside faces. The plane graph G has three interior and two exterior chords.
An essential role in Grinberg’s theorem are the following numerical charac-
teristics of a plane graph with a Hamiltonian cycle. For a plane graph G with
Hamiltonian cycle C, we denote by
• fk the number of interior faces of G that have k edges on their boundary,
• fk1 the number of exterior faces of G that have k edges on their boundary.
We continue our previous example to illustrate these notions.
Example 14.30 (Continued). In the plane graph G of the previous example,
there are four interior faces with four edges on their boundary, but merely one
exterior face with four edges on its boundary. The first line of the following
equations states these facts more succinctly,
f4 “ 4, f41 “ 1,
f5 “ 0, f51 “ 2.
The characteristics shown in the second line tell us that there are two exterior
faces with five edges on their boundary, but there is no interior face that has
fives edges on its boundary.
Grinberg’s theorem gives a numerical invariant that plane graphs with a
Hamiltonian cycle have to satisfy.
Theorem 14.31 (Grinberg). A plane graph G of order n with a Hamiltonian
cycle C must satisfy
n
ÿ
pk ´ 2qpfk ´ fk1 q “ 0. (14.3)
k“3
Each face has a certain number of edges on their boundary. Summing all edges
as the summation ranges over all interior (respectively exterior) faces yields
n
ÿ n
ÿ
kfk “ n ` 2c and kfk1 “ n ` 2c1 .
k“3 k“3
14.7 Hamiltonian Cycles and Paths 377
Indeed, the first sum counts each of the n edges on C once and the interior
chords twice. Similarly, the second sum counts each of the n edges on C once
and the exterior chords twice. Substituting our expressions for c and c1 in the
previous equations yields
˜ ¸ ˜ ¸
ÿn ÿn ÿn ÿn
1 1
kfk “ n ` 2 fk ´ 1 and kfk “ n ` 2 fk ´ 1 .
k“3 k“3 k“3 k“3
The equation (14.3) is called the Grinberg equation. The next example
illustrates how we can use the Grinberg equation to show that a plane graph
does not have a Hamiltonian cycle.
Example 14.32. Consider the plane graph G of order 9 and size 12 shown as
follows.
We observe that there are two faces with three edges, and three faces with
six edges. Seeking a contradiction, we assume that the graph has a Hamiltonian
cycle C. It follows that the plane graph G must satisfy the Grinberg equation
The graph contains two faces with three edges on their boundary, f3 `f31 “ 2. In
other words, the possible values of the term 1pf3 ´ f31 q are t´2, 0, 2u. Reducing
the Grinberg equation modulo 4 shows that f3 ´ f31 ” 0 pmod 4q. Therefore,
we can conclude that one of the triangular faces must be interior and the other
exterior, so f3 “ 1 “ f31 . Therefore, the Grinberg equation reduces to
4pf6 ´ f61 q “ 0.
378 14 Graphs
We can conclude that f6 “ f61 , so there must be the same number of faces
with six edges on their boundary lying in the interior of C as the ones lying
in the exterior of C. In particular, there must be an even number of faces
with six edges on their boundary. This contradicts the fact that there are
f6 ` f61 “ 3 such faces in G. This contradiction shows that the plane graph G
cannot possess a Hamiltonian cycle C.
Exercises
14.40. Lady Hamilton is having a dinner party. She wants to seat her guests at
a big round table such that everyone is seated next to good friends. There are
18 guests and two hosts, so a total of twenty people altogether. She realized
that she invited five people belonging to the astronomy society (a0, . . . , a4),
five people from the bowling club (b0, . . . , b4), five people from the cat club
(c0, . . . , c4), and five mechanics disciples (d0, . . . , d4) that adore her husband’s
work.
She drew a line between any two people that liked each other. Since this
resulted in merely 30 friendships, she was getting a bit worried about her plan.
Can Lady Hamilton seat her guests around the table? Give a solution if one
exists.
14.41. For what values of n does the hypercube graph Qn have a Hamiltonian
cycle?
14.42. For what values of the parameters does the complete bipartite graph
Km,n have a Hamilonian cycle?
14.7 Hamiltonian Cycles and Paths 379
14.43. Show that the graph on the right in Fig. 14.22 cannot have a Hamilto-
nian cycle.
14.44. Let G “ pV, Eq be a Hamiltonian graph. Let k be a positive integer.
Show that if k vertices are deleted from G (along with incident edges), then
the resulting graph has at most k different components. [By contrast, a non-
Hamiltonian graph can possibly decompose into more than k components when
k vertices are deleted.]
14.45. We call a graph G Hamiltonian-connected if and only if there is a
Hamiltonian path between any two vertices of G. Show that a Hamiltonian-
connected graph must contain a Hamiltonian cycle.
14.46. A vertex v in a graph G is called a cut-vertex if and only if the removal
of the vertex v and adjacent edges from G will result in a disconnected graph.
Show that a graph G with a cut-vertex cannot be a Hamiltonian graph.
14.47. Show that the Ore condition is sharp in the sense that there exists a
graph G with n vertices satisfying
deg u ` deg v ě n ´ 1
for all non-adjacent vertices, but G does not contain a Hamiltonian cycle.
14.48. Deduce with the help of Grinberg’s theorem that the plane graph
14.51. Give an example of a plane graph that is not Hamiltonian, but satisfies
Grinberg’s criterion.
14.52. Find two plane graphs of order 8 and size 12, one with a Hamiltonian
cycle and the other without, such that each face in both graphs have degree 4,
meaning that there are four edges on the boundary of each face. What does
this tell you about Grinberg’s criterion?
14.53. Follow in Grinberg’s footsteps and show that the plane graph of order
44 given below does not have a Hamiltonian cycle.
Probability Theory
The 50–50–90 rule: Anytime you have a 50–50 chance of getting
something right, there’s a 90 percent probability you’ll get it wrong.
— Andy Rooney
|A| 3 1
PrrAs “ “ “ .
|Ω| 6 2
1 6
Prrtkus “ .
k2 π2
The sum over all positive integers k shows that
8 8
ÿ ÿ 1 6
PrrΩs “ Prrtkus “ 2 π2
“ 1,
k“1 k“1
k
Proof.
(a) Let E1 “ Ω and Ek “ H for all k ě 2. Then these events are pairwise
disjoint. By countable additivity, we have
8
ÿ
1 “ PrrΩs “ PrrEk s.
k“1
The next proposition gives a very simple yet often useful bound on the
probability of union of events. We call it the union bound, but it is also
known as Boole’s inequality or simply as subadditivity of the probability
measure.
Proposition 15.5 (Union Bound). Let E1 , E2 , . . . be a finite or countably
infinite number of events. Then
« ff
ď ÿ
Pr Ek ď PrrEk s.
k k
Exercises
15.1. Let E1 , E2 , . . . be a finite or countably infinite number of events that
are not necessarily disjoint. Show that the probability measure is subadditive,
meaning that « ff
ď ÿ
Pr Ek ď PrrEk s.
k k
15.2. Let Ω be a sample space, and let ω be a fixed element of Ω. Show that
Pr : P pΩq Ñ r0, 1s given by
#
1 if ω P A,
PrrAs “
0 otherwise.
is a probability measure.
` ¨ ¨ ¨ ` p´1qn`1 PrrE1 X E2 X ¨ ¨ ¨ X En s
15.5. Let Ω be a countably infinite sample space. Show that one cannot define
a uniform probability measure on Ω such that Prrtxus “ Prrtyus for all x, y in
Ω.
|E|
PrrEs “ .
|Ω|
386 15 Probability Theory
Marbles. Suppose that you have a bag full of marbles. There are 23 red
marbles and 27 blue marbles in the bag, so a total of 50 marbles overall. If you
grab without replacement 8 marbles overall, what is the probability that you
get 5 red marbles?
We can answer this question by carefully considering the number of ways
in which we can end up with precisely five red marbles when we grab eight
marbles overall. We contrast this with the number of ways we can grab eight
marbles from the bag. The quotient of these two counting numbers then gives
us the probability
` ˘ that we are looking for.
There are 23 5 ways to select 5 red marbles from the 23 available red mar-
bles.` Let us not forget that the 8 ´ 5 “ 3 other marbles must be blue. There
are 27
˘
3 ways to select the remaining 3 blue marbles from the 27 available blue
marbles. In other words, there are 23
` ˘`27˘
5 3 ways to end up with precisely five
red marbles when we grab eight marbles
` ˘ from the bag.
On the other hand, there are 50 8 ways to choose 8 marbles from the 50
marbles in the bag. So this time we counted every possibility without restricting
the number of red or blue marbles in any way.
Therefore, the probability to get precisely five red marbles when grabbing
eight marbles from the bag is given by
`23˘`27˘
5
Prrget 5 red marbles from the bags “ `50˘3 .
8
The numerical evaluation of this probability is
33649 ¨ 80730
Prrget 5 red marbles from the bags “ « 0.183.
536878650
Pairing Up Socks. Mr. Bocks is quite enamored with his socks. He has n
pairs in a drawer in his walk-in closet. None of the pairs are the same, so he
got quite the variety.
Recently, the light bulb in his closet burned out, so it is completely dark in
there. Regrettably, Mr. Bocks has the unfortunate habit that he does not pair
up his socks, but simply tosses them into the drawer after washing. How likely
15.2 Combinatorial Probability 387
is it that Mr. Bocks will get at least one matching pair of socks if he randomly
grabs r socks?
Since the drawer contains 2n socks, he will get at least one pair with cer-
tainty if he grabs r ě n ` 1 socks. However, if the number n of socks is large,
then this seems to be a bit unreasonable.
So let’s assume that Mr. Bocks is a bit more adventurous and chooses at
most r ď n socks. Of course, in this case it might happen that he comes out of
the closet with r different socks, and none of them match up to a pair. What
are the odds of that event?
Let us first count the number of ways to pick r socks from the drawer.
There are 2n ways to pick the first sock, 2n ´ 1 to pick the second, and so on.
So there is a total of 2np2n ´ 1qp2n ´ 2q ¨ ¨ ¨ p2n ´ r ` 1q ways to pick r socks.
Next we count the number of ways to pick r socks from the drawer so that
we do not get any matching pair. There are 2n ways to pick the first sock.
The second sock should be different from the first sock that we chose, so there
are 2n ´ 2 ways to choose such a sock. For the next sock, we need to carefully
avoid the two socks that will give a pair, but can choose any of the remaining
2n ´ 4 socks. The number of ways to pick r socks that cannot be matched in
pairs is 2np2n ´ 2qp2n ´ 4q ¨ ¨ ¨ p2n ´ 2r ` 2q.
Therefore, the probability that none of the r socks match is given by
2np2n ´ 2qp2n ´ 4q ¨ ¨ ¨ p2n ´ 2r ` 2q
Prrnone of the r socks matchs “ .
2np2n ´ 1qp2n ´ 2q ¨ ¨ ¨ p2n ´ r ` 1q
Our original goal was to find the probability that we do get a matching pair of
socks. This is the probability of the complementary event. Since you either do
or do not get a pair of matching socks, the two probabilities need to add up to
one. Thus, the probability that he does get at least one pair of matching socks
is given by
2np2n ´ 2qp2n ´ 4q ¨ ¨ ¨ p2n ´ 2r ` 2q
Prrget at least one matching pairs “ 1 ´ .
2np2n ´ 1qp2n ´ 2q ¨ ¨ ¨ p2n ´ r ` 1q
For example, if Mr. Bocks has n “ 10 pairs of socks in his drawer, and he
randomly grabs r “ 6 socks, then the probability that he gets a matching pair
is
20 ¨ 18 ¨ 16 ¨ 14 ¨ 12 ¨ 10
Prrget at least one matching pairs “ 1 ´ ě 0.65.
20 ¨ 19 ¨ 18 ¨ 17 ¨ 16 ¨ 15
So in this case it is more likely that he will end up with a matching pair of
socks than without one.
Ducks in a Row. Every year, the small town of Canard organizes a duck
race. There are n teams entering the race. Each team must flip a fair coin to
decide whether to enter a Baseball Duck or a Duck in Black.
388 15 Probability Theory
If there are n “ 3 teams, then there are five starting lineups that do not
contain two adjacent Ducks in Black, since any of the 8 “ 23 possible starting
lineups work with the exception of the following three choices:
We could keep going, but it starts to become too tedious to list all config-
urations. Let us denote by Sn the number of start lineups that do not contain
two adjacent teams. We already determined that
S1 “ 2, S2 “ 3, S3 “ 5.
For larger values of n, we can set up a recurrence relation. If the n-th team
puts in a Baseball Duck, then there are Sn´1 lineups on the first n´1 positions
that avoid adjacent Ducks in Black. If the n-th team puts in a Duck in Black,
then there must be a Baseball Duck on position n ´ 1, and any of the Sn´2
starting lineups on the first n ´ 2 positions that avoid adjacent Ducks in Black.
In summary, we have
Sn “ Sn´1 ` Sn´2
for all integers n such that n ě 3. So S4 “ 8, S5 “ 13, S6 “ 21, and so on.
In other words, the number Sn of starting line ups that do not contain two
adjacent Ducks in Black is given by the Fibonacci number Sn “ fn`2 .
Therefore, the probability that the duck selection of the n teams will create
a starting lineup without two adjacent Duck in Black is given by
Sn fn`2
Prrno adjacent Ducks in Blacks “ n
“ n .
2 2
So asymptotically, we have
ˆ ˙n
1 φn`2 φ2 φ
Prrno adjacent Ducks in Blacks „ ? n
“? ,
5 2 5 2
15.3 Conditional Probabilities 389
?
where φ “ p1 ` 5q{2 is the golden ratio. Since the fraction φ{2 is a positive
real number less than 1, we have pφ{2qn Ñ 0 as n Ñ 8.
Therefore, the probability that we get a starting lineup with no two adjacent
Ducks in Black is very small when a large number of teams enter. Knowing
this fact, the organizers allow for plenty of time until the race gets started.
Exercises
15.6. What is the sample space when drawing socks from a drawer containing
n pairs of socks?
15.8. Suppose that we flip a fair coin five times. We record heads by H and
tails by T . So pH, T, T, H, Hq means that we got heads in the first try, followed
by tails in the next two tries, and the last two flips showed both heads.
(a) Formally describe the sample space of this experiment.
(b) Describe the event that there are more heads than tails in the five coin
flips.
(c) What is the probability of the event that there are more heads than tails?
15.10. Suppose that you have 50 marbles in a bag, where 23 marbles are red
and 27 marbles are blue. If you grab eight marbles from the bag without
replacement, what is the probability to get at least six red marbles. Explain
your result.
PrrE X F s
PrrE |F s “ .
PrrF s
390 15 Probability Theory
The value PrrE |F s is interpreted as the probability that the event E oc-
curs, assuming that the event F has occurred. By definition, PrrE X F s “
PrrE |F s PrrF s, and this simple multiplication formula often turns out to be
useful.
Example 15.7. Suppose that we have a spinner, and the hand of the spinner
can land in one of 36 fields. The spinner is subdivided into three different areas
that contain 12 fields each. The probabilities to land on a field in a given area
are given by
1 1 1
Prrarea 1s “ , Prrarea 2s “ , Prrarea 3s “ .
3 3 3
Suppose now that someone tells us that the hand of the spinner landed in an
area above the dashed line.
Example 15.8. Suppose that someone rolls a die twice. Before showing us
the result, she reveals that in one of the two rolls the die showed a face value
of six. What is the probability that the result will be a pair of sixes?
The outcome of the experiment is a pair of face values. Let P denote the
event to get a pair of sixes and S the event that the pair of dices shows at least
one six. Then our goal is to determine the conditional probability PrrP | Ss,
which is the conditional probability to roll a pair of sixes given that at least
one die shows the value 6. ` ˘
The event P of rolling a pair of sixes is given by the set P “ t , u.
The event S ““at least one die shows a six” consists of the following 11 pairs:
` ˘ ` ˘ ` ˘ ` ˘ ` ˘ ` ˘
S“t , , , , , , , , , , , ,
` ˘ ` ˘ ` ˘ ` ˘ ` ˘
, , , , , , , , , u.
The probability PrrP s to get a pair of sixes is given by PrrP s “ 1{36 and the
probability to roll at least one six is given by PrrSs “ 11{36. Since the event
P is a subset of the event S, we have S X P “ P . Therefore, we have
PrrP X Ss PrrP s 1
PrrP | Ss “ “ “ .
PrrSs PrrSs 11
The next result shows how to express PrrA | Bs in terms of PrrB | As.
We can use the law of total probability to express the denominator PrrBs
in Bayes’ theorem in a different form. Rather than memorizing the next result,
you should memorize how to derive it from the previous two propositions.
PrrB | As PrrAs
PrrA | Bs “ .
PrrB | As PrrAs ` PrrB | AA s PrrAA s
Similarly, PrrC3 |M2 s “ 2{3. In conclusion, if she sticks with her decision, then
the probability to get the car is 1/3. If she switches, then the probability is
2/3. This means that it is advisable that she switches doors.
There are many websites dedicated to this problem, and one finds heated
discussions about the Monty Hall problem on the internet. You will notice
that there exist different solutions, depending on the exact assumptions about
Monty’s knowledge and his strategy.
15.3 Conditional Probabilities 393
Exercises
15.11. Let Ω be a discrete sample space and A an event in P pΩq such that
PrrAs ą 0. Show that the conditional probability Prr ¨ | A s is a probability
measure on A.
15.12. A mother has two children. At birth, each child has an equal chance
to be a boy or a girl. Given that one child is a girl, what are the chances that
the other child will be a girl as well?
15.13. Suppose that five fair coins are tossed. If at least one coin shows heads,
what is the probability that precisely three of the five coins show heads?
15.14. A doctor suspects that his patient suffers from snark disease. The
disease is rare, just 1 in 10,000 people carry the disease. The doctor administers
a test that has a low probability for false negatives, namely there is a 1%
probability of a carrier testing negative. The probability for a false positive
is a bit higher but still very low, as there is a 2% probability of a non-carrier
testing positive. The patient tests positive. What are the chances that the
patient suffers from snark disease?
15.15. Suppose that F1 , . . . , Fn are events that partition the sample space Ω
such that PrrFk s ą 0 holds for all k in the range 1 ď k ď n. Show that
n
ÿ
PrrE s “ PrrE |Fk s PrrFk s
k“1
holds for any event E. This fact is attributed to Reverend Thomas Bayes.
15.16. Suppose that A1 , . . . , An are events that partition the sample space Ω.
Let B be an event with PrrBs ą 0. Show that
PrrB|A1 s PrrA1 s
PrrA1 |Bs “ n .
ÿ
PrrB|Ak s PrrAk s
k“1
15.19. Show that if A and B are events such that PrrBs ą 0, then
PrrAs
PrrA | Bs ď .
PrrBs
15.20. The Sure Thing Principle states that if A, B, and C are events such
that PrrA | Cs ě PrrB | Cs and PrrA | C A s ě PrrB | C A s, then PrrAs ě PrrBs.
Prove the Sure Thing Principle.
15.4 Independence
Two events A and B are called independent if and only if
holds. We call the event A and B dependent if and only if they are not
independent.
If the probabilities PrrAs and PrrBs are nonzero, this means that
PrrA X Bs PrrB X As
PrrA | Bs “ “ PrrAs and PrrB | As “ “ PrrBs.
PrrBs PrrAs
In other words, two events are independent if the occurrence of one event does
not change the probability of the other.
Example 15.13. Suppose that we roll a die twice. Let A be the event that in
first roll the die shows a 5 or 6. Let B be the event that in the second roll the
dies shows 4, 5, or 6. The probabilities of these events are
1 1
PrrAs “ and PrrBs “ .
3 2
The joint event A X B is given by
` ˘ ` ˘ ` ˘ ` ˘ ` ˘ ` ˘
AXB “t , , , , , , , , , , , u.
We have
6 1 1
PrrA X Bs “ “ ¨ “ PrrAs PrrBs,
36 3 2
so the two events A and B are independent.
We can extend the notion of independence to entire families of events. Let
I be an arbitrary index set and Ak , k P I, a family of events. This family of
events is called independent if and only if for every finite subset F of the
index set I, we have « ff
č ź
Pr Ak “ PrrAk s.
kPF kPF
It should be stressed that even if the index set I is infinite, the product formula
must only hold for all finite subsets of the index set.
15.4 Independence 395
Example 15.14. Four students fill out a questionnaire about the likes and
dislikes of the subjects: mathematics, history, and language arts. A student
checks L if they like the subject and D if they dislike the subject. Alice likes
only mathematics, so she writes pL, D, Dq. Beatrix likes only history, so she
writes pD, L, Dq. Claire is into language arts but dislikes the others, so she
writes pD, D, Lq. Dave likes all three subjects, so he writes pL, L, Lq. They put
their answers into a hat and draw uniformly at random questionnaires. Then
1 1 1
Prrlikes maths “ , Prrlikes historys “ , Prrlikes language artss “ .
2 2 2
The probability to like two different subjects is 1/4, as only Dave likes different
subjects. We have
1
Prrlikes math X likes historys “ “ Prrlikes maths Prrlikes historys.
4
So the events “likes math” and “likes history” are independent. In fact, any pair
of subjects are liked independently. However, these three events are dependent,
as the probability to like all three is given by
1
Prrlikes math X likes history X likes language artss “ ,
4
but this is not equal to the product
1
Prrlikes maths Prrlikes historys Prrlikes language artss “ .
8
This shows that it does not suffice to check pairwise independence, but one
needs to verify the product law for all finite subsets of these three events.
We conclude this section by exploring the behavior of a sequence of events
such as an infinite sequence of coin tosses. We might be interested in the event
En “ tHu that the coin turns up heads at the n-th coin toss. However, let
us assume that the coin will get increasingly more biased, say, PrrEn s “ 1{na
for some fixed exponent a ą 0. So for large n, the probability that the coin in
the n-th coin toss comes up tails approaches 1. How likely is it that an infinite
number of heads turn up in this infinite sequence of coin tosses? The next
result shows that the probability of this event is either 0 or 1.
Let E1 , E2 , . . . be events on a discrete sample space Ω. Then we can form
the event
č8 ď 8
E˚ “ Ek .
n“1 k“n
˚
Ť8
An outcome ω is contained in E if and only if ω is contained in k“n Ek for
all n. In other words, ω is contained in E ˚ if and only if ω is contained in Ek
for an infinite number of indices k.
Even though it might seem that deriving the probability of the limiting
event E ˚ is difficult, the next result gives remarkably simple conditions that
can establish PrrE ˚ s.
396 15 Probability Theory
which expresses that none of the events Ek with k ě n occur. The com-
plement of the event E ˚ is given by
8 č
ď 8 8
ď
pE ˚ qA “ EkA “ FnA .
n“1 k“n n“1
where in the last inequality we used that 1 ´ x ď e´x holds for all real
numbers x. We can conclude that
« ff ˜ ¸
m
č 8
ÿ
A A
PrrFn s “ lim Pr Ek ď exp ´ PrrEk s .
mÑ8
k“n k“n
Exercises
15.21. Consider a standard deck of 52 cards. Let A be the event to draw an
ace, and B the event to draw a card of diamonds. Are the events A and B
independent? Prove your result.
15.22. Two events A and B are disjoint if and only if A X B “ H. When are
A and B independent?
15.23. Let Ω “ tH, T u ˆ tH, T u ˆ tH, T u be the sample space of three suc-
cessive independent coin flips. Suppose that the probability to get heads in a
single toss is p, and the probability to get tails is 1 ´ p. Consider the events
and B “ tpH, H, Hq, pT, T, T qu. For what choice of the parameter p in the
range 0 ď p ď 1 are the two events A and B independent? Prove your result.
15.24. Let A and B be events such that PrrAs ‰ 0 and PrrBs ‰ 0. Show that
if PrrA | Bs ą PrrAs, then PrrB | As ą PrrBs.
15.25. Let Ω be a finite sample space. Let A be an event in P pΩq. Show that
if A is independent of all events B P P pΩq, then PrrAs “ 0 or PrrAs “ 1.
15.30. Show that if we omit the independence of the events in part (b) of the
Borel-Cantelli proposition, then the limiting event E ˚ can occur with proba-
bility p such that p ‰ 0 and p ‰ 1. Give a simple example.
15.31. Lev Nicolayevich Tolstoy’s epic “War and Peace” has 3,230,047 char-
acters. Suppose that a Monkey types an infinite string of letters uniformly
at random on a standard typewriter with 88 characters. A biologist observes
that the Monkey’s written text contains the complete “War and Peace” epic
exactly—character by character—not just once, but several times. Since the
probability to write Tolstoy’s epic is exceedingly small (after all, the probabil-
ity 1{883,230,047 ă 10´1,000,000 ), the biologist concludes that the Monkey must
be a genius. Show that the result is not surprising at all, and the result can be
reproduced by a simple machine that depresses the keys uniformly at random.
How often will “War and Peace” occur in the infinite stream of letters?
Example 15.16. Consider rolling a die twice. The sample space Ω contains
36 pairs of face values. Let X denote the random variable that gives the sum
of face values. Then the event that the face values sum to 8 or 9 is specified
by X ´1 pr8, 9sq. This is more concise than writing the event in the form
` ˘ ` ˘ ` ˘ ` ˘ ` ˘
t , , , , , , , , , ,
` ˘ ` ˘ ` ˘ ` ˘
, , , , , , , u.
Associating numerical values with events can have other benefits as well, as we
will see shortly.
The reason for this notation is simple: for instance, writing X P t8, 9u looks
less cluttered than X ´1 pt8, 9uq. If B “ txu is a singleton set, then we often
write X “ x as a shorthand for X ´1 ptxuq.
Example 15.17. Let Ω “ tH, T u ˆ tH, T u ˆ tH, T u be the sample space of
tossing a coin three times. Let X : Ω Ñ t0, 1, 2, 3u be the random variable
counting the number of heads. Then X “ 2 denotes the event
tpT, H, Hq, pH, T, Hq, pH, H, T qu,
and X “ 3 the event tpH, H, Hqu.
Among the simplest examples of random variables are indicator random
variables, which have merely two different values.
Example 15.18. Let Ω be a discrete sample space. For an event A P P pΩq,
we define the function
#
1 when x P A,
IA pxq “
0 when x R A.
Then IA is called the indicator random variable of the event A. Suppose
that p “ PrrAs is the probability of the event A. Then
PrrIA “ 1s “ p and PrrIA “ 0s “ 1 ´ p.
More elaborate random variables are often composed of weighted sums or prod-
ucts of indicator random variables.
Example 15.19. Consider the sample space Ω “ tH, T u ˆ tH, T u ˆ tH, T u
of a sequence of three coin tosses. Let IH1 , IH2 , IH3 be the indicator random
variables of the events that the first, second, or third coin toss shows heads,
respectively. Then the sum X “ IH1 ` IH2 ` IH3 of these three indicator
random variables is the random variable counting the total number of heads
that we have seen in Example 15.17.
A random variable X : Ω Ñ R on a discrete sample space Ω has a finite or
countably infinite set of values. Therefore, the values attained by X can be
indexed by positive integers
tXpωq | ω P Ωu “ tα1 , α2 , α3 , . . .u.
We can assume without loss of generality that the values αk are pairwise dis-
tinct. Let us denote the probability of the event X “ αk by
pk “ PrrX “ αk s.
The probabilities pk allow us to express the probability of the event X P B for
any subset B of the set of real numbers. Indeed, since the events X “ αk and
X “ α are disjoint when k ‰ , we obtain
ÿ
PrrX P Bs “ PrrX P B X tα1 , α2 , . . .us “ pk ,
αk PB
400 15 Probability Theory
Example 15.20. Let us consider once more the indicator random variable
IA of an event A in a discrete sample space. Suppose that p “ PrrAs is the
probability of the event A, whence
One can reconstruct the probability mass function ppxq “ PrrIA “ xs of the
indicator random variable from the distribution function.
Exercises
15.32. The nomenclature “random variable” was introduced before the mod-
ern definition of probability theory. Use the definition of the random variable
to explain why the slogan “A random variable is neither random nor a variable”
is correct.
15.33. Consider the measurable space pΩ, P pΩqq, where the sample space de-
scribes the outcomes of three successive coin tosses, so
Let X be the random variable counting the number of heads. Explicitly de-
scribe the events given by
(a) X ě 2,
(b) X “ 1,
(c) X ă 1.
15.6 Expectation 401
15.34. Let X denote the number of heads on three independent coin flips of
a biased coin that turns up heads with probability p. Give the distribution
function FX of X.
15.35. Suppose that two dice are rolled. Let X be the random variable that
gives the larger of the two face values. Determine Prr3 ď X ď 4s.
15.36. Suppose that we toss a fair coin until the coin shows heads. Let X
denote the number of coin tosses. So we have X “ 1 when the coin shows head
after the first toss, X “ 2 when the coin showed tails and then heads in the
second try.
(a) Determine PrrX “ ns.
(b) Determine the distribution function FX .
15.6 Expectation
Random variables specify events using the values of the random variable. The
expected value of a random variable is essentially an average of its values.
Despite being an average, the expected value often gives us some insights about
the behavior of the probability distribution of a random variable.
Let X be a random variable on a discrete sample space Ω. The expectation
value of X is defined to be
ÿ
ErXs “ α PrrX “ αs,
αPXpΩq
Example 15.21. Suppose that n persons give their hats to the hat check girl.
She is distraught and hands the hats back uniformly at random. We want to
answer the following question: On average, how many persons get their own
hat back?
We take Ω “ t1, . . . , nu as sample space and allow all subsets of Ω as events,
F “ 2Ω . Let Xk : Ω Ñ R be the random variable defined by Xk pkq “ 1 and
Xk pxq “ 0 for all x ‰ k. Hence, Xk “ 1 denotes the event that person k
receives her own hat. The probability that the kth person receives her own hat
back is PrrXk “ 1s “ 1{n, since she will receive one of n possible hats.
Let X “ X1 ` ¨ ¨ ¨ ` Xn denote the number of persons receiving their own
hats. We have
n
ÿ n
ÿ
ErXs “ ErXk s “ 1 ¨ PrrXk “ 1s “ np1{nq “ 1,
k“1 k“1
ErXs
PrrX ě ts ď .
t
Proof. Let Y denote the random variable
"
0 if Xpωq ă t,
Y pωq “
1 if Xpωq ě t,
varrX ` Xs “ 4 varrXs
15.6 Expectation 403
n`1 n2 ´ 1
ErXs “ , varrXs “ .
2 12
The expectation value follows from the definition. We can verify the variance
by noting that
n
ÿ 1 2 1 np1 ` nqp1 ` 2nq p1 ` nqp1 ` 2nq
ErX 2 s “ k “ “ ,
k“1
n n 6 6
1 1´p
ErXs “ , varrXs “ .
p p2
It is possible to derive these facts directly from the definitions. For the expec-
tation value, this can be done without too much effort, but for the variance,
this is cumbersome. In the next section, we will introduce a tool that can
significantly simplify such calculations.
λk ´λ
PrrX “ ks “ e , k “ 0, 1, 2, . . . .
k!
The Poisson distribution can be used to approximate the Binomial distribution
if n is large and p is small. Indeed, suppose that limnÑ8 npn “ λ, then
λk
ˆ ˙
n k
lim pn p1 ´ pn qn´k “ e´λ .
nÑ8 k k!
This formula is frequently used when the evaluation of the binomial distribution
is not feasible.
Exercises
15.37. Let X be a discrete random variable that has nonnegative integer val-
ues. Show that
ÿ8
ErXs “ PrrX ě ns.
n“1
15.40. Suppose that you have a biased coin that produces heads with probabil-
ity p, where 0 ă p ă 1, but unfortunately this probability is not known to you.
Von Neumann showed that it is possible to use such a biased coin to construct
a source for fair coin flips. Derive a scheme such that the expected number
of biased coin flips does not exceed 1{ppp1 ´ pqq. [Hint: Consider consecutive
pairs of biased coin flips.]
406 15 Probability Theory
15.42. Let us continue the previous exercise. Let X denote the random vari-
able counting the number of boxes required to collect at least one character of
each type. Calculate the variance varrXs.
15.43. A geometric random variable describes how many times we have to flip
a biased coin until we obtain heads. Suppose that we have n such coins and we
toss all of them once in one round. Let X denote the random variable counting
the number of rounds until heads have occurred at least once for all n coins.
Show that
8 ´ ´ ¯n ¯ 8
ÿ ÿ ˘n ˘
1 ´ 1 ´ p1 ´ qqm 1 ´ 1 ´ pm
` `
ErXs “ “ . (15.3)
m“0 m“0
Here q denotes the probability that the coin shows heads and p “ p1 ´ qq.
15.44. We continue the previous exercise. Derive from equation (15.3) the
alternate expression
n ˆ ˙
ÿ n 1
ErXs “ p´1qk`1 .
k“1
k 1 ´ p1 ´ qqk
Proof. Any coloring of Kn either has (a) one or more red (=solid) edges, so it
contains a red K2 , or (b) it does not contain any red edges, but then it contains
a blue (=dashed) Kn .
In other words, this graph does not have an induced red K3 subgraph, nor
an induced blue K3 subgraph.
408 15 Probability Theory
Proof. It suffices to show that Rp3, 3q ď 6. Let G “ pV, Eq be the red induced
subgraph of the complete graph K6 , and recall that red models acquaintance.
Let u P V be an arbitrary vertex. Then there are two cases:
(a) Suppose that the set N puq “ tv P V |pu, vq P Eu has at least 3 elements.
Then either N puq is an independent set of strangers and the claim holds,
or we have two adjacent vertices v1 , v2 P N puq, in which case tu, v1 , v2 u is
a clique of mutually acquainted people and the claim also holds.
(b) Suppose that the set N puq “ tv P V |pu, vq P Eu has at most two elements.
Then there are three vertices x, y, z in V zN rus. If those three are mutually
acquainted, then we are done. Otherwise, if two of the vertices x, y, z are
not acquainted, let us say x and y are strangers, then tu, x, yu are mutually
strangers, and the claim also holds.
In any case, we have established that Rp3, 3q ď 6, as claimed.
One can show that Rp4, 4q “ 18, but determining the exact value of Rp5, 5q
is already an open problem. The reason is that the corresponding graphs get
large and enumerating all colorings becomes infeasible.
Erdős proved the following remarkable lower bound on the Ramsey num-
bers.
k
Proposition 15.27 (Erdős). If nk 21´p2q ă 1, then Rpk, kq ą n.
` ˘
1 1 k
PrrMS s “ PrrS reds ` PrrS blues “ k ` k “ 21´p2q .
p
2 2 q p
2 2 q
By the union bound, the probability that some k-subset forms a monochromatic
k
subgraph is at most nk 21´p2q .
` ˘
`n˘ 1´pkq
Since k 2 2 ă 1, there exists some 2-coloring for which there is no
monochromatic Kk . Therefore, we can conclude that the Ramsey number
Rpk, kq ą n.
Corollary 15.28. For all integers k such that k ě 3, the Ramsey number
Rpk, kq ą 2k{2 .
15.7 The Probabilistic Method 409
nk {k! yields
` k{2 ˘k
nk 1´ kpk´1q
ˆ ˙
n 1´pk2q 2 k2 k
2 ď 2 2 ď 21´ 2 ` 2 .
k k! k!
Large Cuts. Given an undirected graph G “ pV, Eq, a partition of the vertex
set V into disjoint subsets A and B is called a cut. In other words, two subsets
A and B form a cut of G if and only if
A X B “ H and A Y B “ V.
The size of the cut pA, Bq in the graph G is given by the number of edges
crossing the cut pA, Bq. In other words,
contradiction.
Proof. For each vertex, flip a fair coin and put the vertex in A if the coin shows
heads, and put the vertex in B if the coin shows tails. Let e1 , e2 , . . . , em be an
enumeration of the edges in E. Define the indicator random variable Xk by
#
1 if edge k crosses the cut pA, Bq,
Xk “
0 otherwise
The probability that the edge crosses the cut pA, Bq is 1/2; hence,
1
ErXk s “ .
2
Let sizepA, Bq denote the size of the cut pA, Bq. Then
« ff
m m
ÿ ÿ m
ErsizepA, Bqs “ E Xk “ ErXk s “ .
k“1 k“1
2
Exercises
15.45. Determine the Ramsey number Rp2, 2q.
by induction on k.
15.47. Show that the Ramsey numbers Rpa, bq satisfy the bound
15.48. Use the previous exercise to show that the Ramsey number Rpa, bq
satisfies the upper bound
ˆ ˙
a`b´2
Rpa, bq ď
a´1
15.49. Use the previous exercise to show that the diagonal Ramsey number
Rpk, kq is bounded from above by
Rpk, kq ď 4k´1 .
15.8 Notes 411
15.50. Suppose that n players play a tennis tournament, where each player
plays against all other players. Players either win or loose. The tournament
graph contains a vertex for each player and an edge pa, bq if player a won against
player b. A tournament has property Pk if and only if for every
` ˘ set of k players,
there exists one player who beats them all. Show that if nk p1 ´ 2´k qn´k ă 1,
then there exists a tournament of n players that has property Pk .
15.51. Use the probabilistic method to show that every graph G “ pV, EG q
has a bipartite subgraph H “ pV, EH q such that |EH | ě 12 |EG |.
15.8 Notes
There exist an abundance of good introductory text on probability theory. The
book by Chung and AitSahlia [13] is a very well-written introduction to elemen-
tary probability theory that also briefly discusses some more advanced topics.
Feller [27] is a wonderful classic. The book by Grimmett and Stirzaker [31]
gives a well-rounded introduction and contains numerous excellent exercises.
The book by Ross [65] is an easily readable introduction, which contains a
well-chosen number of interesting applications.
If you want to make further progress, then you need to learn more about
measure-theoretic aspects of probability theory. The books by Gut [32], Jacod
and Protter [40], Klenke [46], Rosenthal [64], Williams [80] all give solid but
accessible measure-theoretic introductions to probability theory. These books
will give you a good start, and all contain at least a brief discussion of the
Lebesque integral and related topics. All of the previous books are accessible
to undergraduate students.
Probability generating functions, and much more, are discussed in Graham
et al. [30]. The book by Alon and Spencer [5] contains numerous applications
illustrating the probabilistic method.
Bibliography
[1] A.V. Aho, J.E. Hopcroft, and J. Ullman. The Design and Analysis of
Computer Algorithms. Addison-Wesley Longman Publishing Co., Inc.,
Boston, MA, USA, 1st edition, 1974.
[2] M. Aigner. Combinatorial theory. Classics in Mathematics. Springer-
Verlag, Berlin, 1997. Reprint of the 1979 original.
[3] M. Aigner. A course in enumeration, volume 238 of Graduate Texts in
Mathematics. Springer, Berlin, 2007.
[4] M. Aigner. Discrete mathematics. American Mathematical Society, Prov-
idence, R.I., 2007.
[5] N. Alon and J. Spencer. The Probabilistic Method. John Wiley & Sons,
New York, 2nd edition, 2000.
[6] T. Andreescu and V. Crişan. Mathematical Induction – A powerful and
elegant method of proof. XYZ Press, 2017.
[7] P. Bachmann. Die Analytische Zahlentheorie. Teubner, 1894.
[8] R.A. Beeler. How to count. Springer, Cham, 2015. An introduction to
combinatorics and its applications.
[9] A.T. Benjamin and J.J. Quinn. Proofs that really count, volume 27 of The
Dolciani Mathematical Expositions. Mathematical Association of Amer-
ica, Washington, DC, 2003. The art of combinatorial proof.
[10] G. Boole. A treatise on the calculus of finite differences. Dover Publica-
tions, New York, 2nd edition, 1960.
[11] G. Cantor. Gesammelte Abhandlungen mathematischen und philosophis-
chen Inhalts. Springer-Verlag, Berlin-New York, 1980. Reprint of the 1932
original.
[12] N. Caspard, B. Leclerc, and B. Monjardet. Finite ordered sets, volume
144 of Encyclopedia of Mathematics and its Applications. Cambridge Uni-
versity Press, Cambridge, 2012. Concepts, results and uses.
[16] T.H. Cormen, C.E. Leiserson, R.L. Rivest, and C. Stein. Introduction to
Algorithms. The MIT Press, 3rd edition, 2009.
[24] H.B. Enderton. Elements of set theory. Academic Press [Harcourt Brace
Jovanovich, Publishers], New York-London, 1977.
[26] L. Euler. Solution d’une question curieuse que ne paroit soumise à aucune
analyse. Mémoire de l’Academie des Sciences de Berlin, 15:310–337, 1759
(published 1766).
[28] J.H. Gallier. Logic for Computer Science – Foundations for Automatic
Theorem Proving. John Wiley and Sons, 1987.
[29] D. Goldrei. Propositional and Predicate Calculus – A Model of Argument.
Springer, 2005.
[36] K. Hrbacek and T. Jech. Introduction to set theory, volume 220 of Mono-
graphs and Textbooks in Pure and Applied Mathematics. Marcel Dekker,
Inc., New York, third edition, 1999.
[37] M. Huth and M. Ryan. Logic in Computer Science: Modelling and Rea-
soning About Systems. Cambridge University Press, New York, NY, USA,
2nd edition, 2004.
[42] K. Jordán. Calculus of finite differences. Chelsea Pub. Co., New York,
3rd edition, 1965.
[44] V.G. Kac and P. Cheung. Quantum calculus. Universitext. Springer, New
York, 2002.
[45] I. Kaplansky. Set theory and metric spaces. Chelsea Publishing Co., New
York, second edition, 1977.
[47] D.E. Knuth. Big omicron and big omega and big theta. SIGACT News,
8(2):18–24, 1976.
[50] D.E. Knuth. Sorting and Searching, volume 3 of The Art of Computer
Programming. Addison-Wesley, Reading, Massachusetts, second edition,
1998.
[55] E. Landau. Handbuch der Lehre von der Verteilung der Primzahlen.
Teubner, Leipzig, 1909. 2 volumes. Reprinted by Chelsea, New York,
1953.
[57] C.H.C. Little, K.L. Teo, and B. Van Brunt. The Number Systems of
Analysis. World Scientific, 2003.
[63] S. Roman. Lattices and ordered sets. Springer, New York, 2008.
[64] J.S. Rosenthal. Rigorous Probability Theory: A First Look. World Scien-
tific, 2nd edition, 2006.
[68] R.M. Smullyan. First-order logic. Dover Publications, Inc., New York,
1995. Corrected reprint of the 1968 original.
[70] R.M. Smullyan and M. Fitting. Set theory and the continuum problem,
volume 34 of Oxford Logic Guides. The Clarendon Press, Oxford Univer-
sity Press, New York, 1996. Oxford Science Publications.
[74] R.P. Stanley. Catalan numbers. Cambridge University Press, New York,
2015.
[76] W.T. Trotter. Combinatorics and partially ordered sets. Johns Hopkins
Series in the Mathematical Sciences. Johns Hopkins University Press,
Baltimore, MD, 1992. Dimension theory.
[77] D.J. Velleman. How to prove it. Cambridge University Press, Cambridge,
second edition, 2006. A structured approach.
© The Editor(s) (if applicable) and The Author(s), under exclusive 419
license to Springer Nature Switzerland AG 2025
A. Klappenecker, H. Lee, Discrete Structures, Undergraduate Texts in
Mathematics, https://doi.org/10.1007/978-3-031-73434-2
420 INDEX
set, 4, 52 symmetric, 71
countable, 84 symmetric difference, 65
finite, 83
inductive, 79 T
transitive, 81 tautology, 21
uncountable, 84 telescoping sum, 96
set complement, 64 total order, 146
set difference, 63 transitive, 71
set equality, 52 trapdoor function, 203
set intersection, 62 tree, 362
set union, 60, 62 triangle, 354
shift operator, 214 Tribonacci numbers, 321
sine function, 313
singleton set, 53 U
size of a cut, 409 unimodal sequence, 283
spanning subgraph, 363 union bound, 384
spanning tree, 363 unit, 44
square-free, 202 universal quantifier, 36
star graph, 356 universe, 35
statement, 11 universe of discourse, 35
Stirling numbers unordered k-selection with
of the second kind, 222 repetitions, 285
strict asymptotic lower upper bound, 157
bound, 259 upper envelope, 243
strict asymptotic upper
V
bound, 256
vacuously true, 14
strictly ordered set, 147
valid, 26
strict order, 147
valuation, 20
subadditivity, 384
variance, 402
subgraph, 363
vertex coloring, 368
subset, 5, 54
vertices, 5
substitution technique, 23
successor, 79 W
sum of power walk, 5
series, 304 length, 358
supremum, 159 well-ordered set, 161
surjective, 75 worst-case running time, 261