0% found this document useful (0 votes)
519 views429 pages

Klappenecker A., Lee H. Discrete Structures 2025

The document outlines the structure and content of the book 'Discrete Structures' aimed at undergraduate mathematics students. It covers various topics in discrete mathematics, including logic, set theory, proofs, number theory, and combinatorial methods, with a focus on providing a coherent understanding of these subjects. The book includes numerous exercises to enhance learning and is designed for students with a precalculus background.

Uploaded by

cchamp sedigo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
519 views429 pages

Klappenecker A., Lee H. Discrete Structures 2025

The document outlines the structure and content of the book 'Discrete Structures' aimed at undergraduate mathematics students. It covers various topics in discrete mathematics, including logic, set theory, proofs, number theory, and combinatorial methods, with a focus on providing a coherent understanding of these subjects. The book includes numerous exercises to enhance learning and is designed for students with a precalculus background.

Uploaded by

cchamp sedigo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 429

Undergraduate Texts in Mathematics

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

Colin Adams, Williams College, Williamstown, MA, USA


Jayadev S. Athreya, University of Washington, Seattle, WA, USA
Nathan Kaplan, University of California, Irvine, CA, USA
Jill Pipher, Brown University, Providence, RI, USA
Jeremy Tyson, University of Illinois at Urbana-Champaign, Urbana, IL, USA

Undergraduate Texts in Mathematics are generally aimed at third- and fourth-


year undergraduate mathematics students at North American universities. These texts
strive to provide students and teachers with new perspectives and novel approaches.
The books include motivation that guides the reader to an appreciation of interrela-
tions among different aspects of the subject. They feature examples that illustrate key
concepts as well as exercises that strengthen understanding.
Andreas Klappenecker • Hyunyoung Lee

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

ISSN 0172-6056 ISSN 2197-5604 (electronic)


Undergraduate Texts in Mathematics
ISBN 978-3-031-73433-5 ISBN 978-3-031-73434-2 (eBook)
https://doi.org/10.1007/978-3-031-73434-2

Mathematics Subject Classification: 68R01, 68R05, 05-01, 39-01

© 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

If disposing of this product, please recycle the paper.


Preface

Discrete mathematics is concerned with the study of finite or countably infinite


objects. It is a mélange of topics from logic, set theory, algebra, combinatorics,
number theory, and other areas of mathematics rather than a mathematical
discipline itself. Computer scientists pragmatically characterize it as the sub-
ject that provides the mathematical foundation for computing. In particular,
it supplies the tools to analyze algorithms and data structures.
Since discrete mathematics consists of many different subjects, it uses a
great variety of methods to solve problems. The aim of this book is to bring
some coherency into these seemingly incongruent subjects. We begin by laying
a solid foundation for the study of discrete structures by discussing logic, sets,
and mathematical proofs. We systematically develop methods to find the closed
form for finite sums. We deduce combinatorial methods from the foundations
that we have laid.
The methods of discrete mathematics are often seemingly simple. For ex-
ample, anyone can immediately grasp the pigeonhole principle, but may be
dazzled by the sophisticated applications of the principle. Generally, it re-
quires a lot of practice until one is able to master the methods. We have
included 690 exercises of various levels of difficulty in this book. We encour-
age the reader to study the examples in the text and solve many of these
exercises.

Chapter Synopses. The first chapter of this book discusses recreational


problems that is meant to excite students. The solutions to these recreational
problems illustrates the virtue of abstract methods. The reader should pay
close attention to the proofs given in this chapter, as they illustrate styles of
mathematical reasoning that will be examined in greater depth later.
The second chapter discusses propositional logic and a little bit of predi-
cate logic, before exposing the student to the main principles of mathematical
arguments.
The axiomatic method is illustrated by giving a brief introduction to Zermelo-
Fraenkel set theory. As an application, we show how set theory can be used to
derive profound limitations of computing.
The book contains an entire chapter devoted to proofs by induction, giving
a thorough exposition to this fundamental proof technique.

v
vi Preface

In Chapter 5, we discuss equivalence relations and their application to the


construction of number systems. We construct the set of integers and the set of
rational numbers. Furthermore, we discuss the basics of modular arithmetic.
In Chapter 6, we discuss partial orders, strict orders, and cover relations.
We give an introduction to lower and upper bounds, infima and suprema, and
lattices.
The ubiquitous floor and ceiling functions are discussed in Chapter 7. These
functions allow us for example to derive the number of digits of a positive
integer that is written in base b, among other applications. This chapter eases
the reader into topics in number theory.
Chapter 8 contains a more thorough discussion of topics in number theory.
We discuss greatest common divisors and their applications in solving linear
Diophantine equations. We discuss the RSA public key cryptosystem after
introducing linear congruence equations and the Chinese remainder theorem.
The second part of the book concerns sums and asymptotic notations. We
discuss the calculus of finite differences in Chapter 9. We will see that many
sums can be turned into telescoping sums that are easy to evaluate.
We discuss asymptotic notations in Chapter 10. These notations allow us
to characterize the limiting behavior of a function in terms of simpler functions.
The main benefit is that bounds on the growth of function can be expressed in
terms of functions that are easier to understand.
The last part of the book is concerned with combinatorial methods. In
Chapter 11, we discuss fundamental counting principles. The chapter intro-
duces combinatorial proofs that are often more insightful than inductive ar-
guments. The combinatorial interpretation of falling factorials, binomial co-
efficients, Stirling numbers and other counting coefficients gives the student a
deeper appreciation of their significance.
The next two chapters are concerned with generating functions and re-
currence relations. Chapter 12 introduces the basic operations on generating
functions and illustrates how they can simplify the solution to some counting
problems. In Chapter 13, generating functions are used to solve recurrence
relations.
Chapter 14 is concerned with undirected graphs. We discuss basic notions
of graph theory and common examples of graphs. Simple graph-theoretic ar-
guments are illustrated for connected graphs, trees, and planar graphs. A
section on graph coloring provides an interesting problem that inspired many
developments in graph theory.
In Chapter 15 we give an introduction of probability theory. We confine
ourselves to countable sample spaces, so the entire theory can be developed
without the need for measure-theoretic tools. We begin with combinatorial
probability theory, which is essentially a variation on counting. Then we discuss
the most important notions of elementary probability theory. A brief discussion
of the probabilistic method concludes this chapter.
Preface vii

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.

For the Instructor. As an audience, we had undergraduate students in mind


that have at least mastered precalculus. In a few instances, we made some
remarks (and included a few exercises) for the benefit of students that have
already taken calculus. These remarks and exercises are clearly marked, and
can be ignored without loss of continuity. Furthermore, some more advanced
viii Preface

material is contained in starred sections. The starred sections can be skipped


at first reading without interrupting the flow.
The general outline of chapter dependencies is outlined in the chapter de-
pendency graph. The order of the first four chapters is fairly fixed. Chap-
ters 5, 6, and 7 are fairly independent, so they can be studied in any order.
However, we recommend studying Chapter 5 before Chapter 6, as this is a
natural progression in difficulty. Also, it should be noted that some exercises
in Chapter 7 require material from Chapter 6. Chapter 8 is optional, as no
other chapter depends on it. It should be evident from the chapter dependency
graph that there is more flexibility in choosing the order of study for the later
parts of the book.
We have taught this material in many different versions. For a semester
course, we have taught for instance Chapters 1–7, Chapters 10–13, and Chap-
ter 14. For more advanced students (such as an honors section), one could
include the starred sections in Chapter 4 and end the course with Chapter 15
instead of Chapter 14. Of course, many other variations are possible.
When teaching in a quarter system, covering Chapters 1–7 followed by a
selection of about two more advanced chapters is a good choice for a single
term. One can accommodate a faster pace by omitting starred sections. The
entire content of this text can be comfortably covered in two terms of the
quarter system.
College Station, Texas, 2024 Andreas Klappenecker and Hyunyoung Lee

Acknowledgements. We thank our students who gave us feedback in nu-


merous seminars and courses on discrete structures over the years. In par-
ticular, we would like to thank Andrew Nemec for many detailed comments.
We also would like to thank the developers of perusall.com, especially Brian
Lukoff, for allowing our students to directly comment on the manuscript. This
feedback proved to be invaluable!
We would also like to thank the anonymous referees and the series editors of
UTM for very valuable feedback. Above all, our heartfelt thanks go to Loretta
Bartolini and Elizabeth Loew for their advice, guidance, and patience!
Contents

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

5 Equivalence Relations 133


5.1 Generalities 133
5.2 Integers 139
5.3 Modular Arithmetic 140
5.4 Rational Numbers 142
5.5 Notes 144

6 Partial Orders and Lattices 145


6.1 Partial Orders 145
6.2 Strict Order 147
6.3 Cover Relations and Hasse Diagrams 149
6.4 Dilworth’s Theorem 152
6.5 Lower and Upper Bounds 157
6.6 Extensions of Partial Orders 161
6.7 Monotonic Functions 164
6.8 Lattices 166
6.9 Notes 169

7 Floor and Ceiling Functions 171


7.1 Rounding Up and Down 171
7.2 Divisibility and Primes 177
7.3 Functions of Floors and Ceilings 180
7.4 Notes 184

8 Number Theory 185


8.1 Divisibility 185
8.2 The Greatest Common Divisor 187
8.3 Linear Diophantine Equations 191
8.4 Linear Congruence Equations 196
8.5 The Chinese Remainder Theorem 198
8.6 The RSA Public Key Cryptosystem 202
8.7 Notes 205
CONTENTS xi

II Summation and Asymptotics 207

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

10 Asymptotic Analysis 237


10.1 Asymptotic Equality 237
10.2 Limit Superior and Limit Inferior 243
10.3 Asymptotically Tight Bounds 250
10.4 Asymptotic Upper Bounds 254
10.5 Asymptotic Lower Bounds 259
10.6 Analysis of Algorithms 260
10.7 Notes 264

III Combinatorics 265

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

12 Generating Functions 301


12.1 The Basic Concept 301
12.2 Operations on Generating Functions 303
12.3 Elementary Generating Functions 311
12.4 Giving Change 315

13 Recurrence Relations 319


13.1 Recurrence Relations 319
13.2 A Motivating Example 323
13.3 Fibonacci Sequence 325
13.4 Partial Fractions 328
13.5 Reciprocal Polynomials 331
13.6 Linear Homogeneous Recurrence Relations 333
xii CONTENTS

13.7 Characteristic Polynomials 336


13.8 Inhomogeneous Linear Recurrence Relations 339
13.9 Catalan Numbers 343
13.10Notes 347

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

15 Probability Theory 381


15.1 Probability Spaces 381
15.2 Combinatorial Probability 385
15.3 Conditional Probabilities 389
15.4 Independence 394
15.5 Random Variables 398
15.6 Expectation 401
15.7 The Probabilistic Method 406
15.8 Notes 411

Bibliography 413

Index 419
Notation

Logic

A^B conjunction, A and B


A_B disjunction, A or B
A negation, not A
AÑB implication, A implies B
AØB equivalence, A if and only if B
vA a valuation v of the Boolean formula A
A”B logical equivalence, so vA “ vB for all valuations v
tP1 , . . . , Pn u ( A A is a logical consequence of the premises P1 , . . . , Pn
tP1 , . . . , Pn u $ A A can be deduced from the premises P1 , . . . , Pn
@n P pnq the predicate P pnq holds for all n in the universe
Dn P pnq the predicate P pnq holds for some n in the universe

Sets

N0 the set of nonnegative integers t0, 1, 2, 3, . . .u


N1 the set of positive integers t1, 2, 3, . . .u
Q the set of rational numbers
R the set of real numbers
Z the set of integers
H the empty set
AĎB A is a subset of the set B
AĹB A is a proper subset of the set B
AXB intersection of the sets A and B
AYB union of the sets A and B
A´B set of elements in A that are not in the set B, same as A  B
AB set of elements in A that are not in the set B, same as A ´ B
AA complement of A with respect to a universe U , so AA “ U  A
P pAq power set of A, the set of all subsets of A,
2A alternate notation for power sets, 2A “ P pAq
|A| cardinality of the set A

xiii
xiv Notation

Functions

f: AÑB function with domain A and codomain B


dompf q domain of the function f
ranpf q range of the function, ranpf q “ tf pxq | x P dompf quˇ
f æX restriction of the function to X, also denoted as f ˇX
f ´1 inverse of the function f or preimage of f
g˝f composition of functions, g ˝ f pxq “ gpf pxqq
iA identity map on a set A

Sums and Products

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

a|b integer a divides the integer b


ab integer a does not divide the integer b
a ” b pmod nq the integer a ´ b is a multiple of n

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

V pGq vertex set of a graph G


EpGq edge set of a graph G
N pvq neighborhood of the vertex v
N rvs closed neighborhood of the vertex v
deg v degree of the vertex v
δpGq minimal degree of a graph G
ΔpGq maximal degree of a graph G
dpu, vq distance between vertices u and v
dpGq diameter of the graph G
αpGq independence number of G
χpGq chromatic number of G
ωpGq clique number of G
kpGq number of components of G
En empty graph with n nodes
Pn path graph with n nodes
Cn cycle graph with n nodes
Kn complete graph with n nodes
Km,n complete bipartite graph with m ` n nodes
Qn hypercube graph with 2n nodes
G complementary graph of G
GH Cartesian product of the graphs G and H

Probability Theory

Ω a sample space, assumed to be finite or countable


Pr probability measure, sometimes denoted by μ
PrrAs probability of event A
PrrA | Bs conditional probability of A given B
ErXs expected value of X
Part I

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.

1.1 Knight’s Tour


A knight can move on a chessboard either two squares in horizontal direction
and one square in vertical direction or alternatively one square in horizontal
direction and two squares in vertical direction. Thus, there are up to eight
possible knight moves from a given square, as shown in Fig. 1.1. In other
words, the knight moves according to the rules of the game of chess.

© The Author(s), under exclusive license to Springer Nature 3


Switzerland AG 2025
A. Klappenecker, H. Lee, Discrete Structures, Undergraduate Texts in
Mathematics, https://doi.org/10.1007/978-3-031-73434-2 1
4 1 Introduction

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.

Figure 1.2: A knight’s tour on a 3 ˆ 4 chessboard starting at a2 and ending at d2.


This tour is not closed, though

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,

and the set E of edges by

E “ tta1,b3u, ta1,c2u, ta4,b2u, ta4,c3u, ta2,c1u, ta2,c3u, ta2,b4u, ta3,c2u,


ta3,c4u, ta3,b1u, tb1,d2u, tb1,c3u, tb2,d1u, tb2,d3u, tb2,c4u, tb3,c1u,
tb3,d2u, tb3,d4u, tb4,c2u, tb4,d3u, tc1,d3u, tc2,d4u, tc3,d1u, tc4,d2uu.

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.

A walk in a graph pV, Eq is a sequence of edges e1 , . . . , ek in E such that


ei “ tvi , vi`1 u. Notice that the edge ei and the subsequent edge ei`1 share the
vertex vi`1 . So a walk models a sequence of vertices

pv1 , v2 , . . . , vk , vk`1 q

that are connected by traveling along the edges from e1 , e2 , . . . , ek . In a walk,


a vertex might be visited multiple times.

Example 1.2. One walk on the knight graph of the 4 ˆ 4 chessboard is, for
instance, given by

pta1,c2u, tc2, b4u, tb4, d3u, td3, b4u, tb4, a2uq.


6 1 Introduction

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

For example, suppose that we want to find a knight’s tour on a 3 ˆ 4


chessboard starting from the square a3. Then after nine knight moves, one
arrives at the configuration shown on the left in the next figure.

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

In this chapter, we will discuss the structure of mathematical arguments.


We begin with an overview of propositional logic. We first introduce propo-
sitions and logical operators. Then we discuss tautologies, satisfiability, and
logical equivalence. We discuss a propositional calculus that gives us a first
glimpse into the method of formal proofs. We sketch the rudiments of predi-
cate logic including universal and existential quantifiers, predicates, and their
interpretations. We conclude this chapter with a discussion of basic proof tech-
niques. Furthermore, we will learn how to properly negate statements and how
to leverage this knowledge in proofs by contradiction.

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

© The Author(s), under exclusive license to Springer Nature 11


Switzerland AG 2025
A. Klappenecker, H. Lee, Discrete Structures, Undergraduate Texts in
Mathematics, https://doi.org/10.1007/978-3-031-73434-2 2
12 2 Mathematical Arguments

The number 2e is irrational

is a mathematical statement, since it is certainly either true or false. However,


so far nobody has been able to settle whether 2e is a rational number of not.
There are many similar mathematical statements that suffer from the same
predicament.
In general, how do we go about proving a mathematical statement? We
assume some assertions that are believed to be true as axioms. Then we use
logical reasoning to derive the statement from these axioms. Euclid nicely
illustrated this deductive method in his Elements, a most influential textbook
written around 300BC that developed the foundations of Euclidean geometry
and the beginnings of number theory.
It should be self-evident that one needs to understand the rules of logic to
construct a valid mathematical argument. Therefore, we give a brief discussion
of symbolic logic. We conclude this chapter by discussing some proof strategies
that illustrate how to apply the logical reasoning in mathematical arguments.

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

2.5. Consider the statement “This statement is false.” Is it true or false?


Discuss.

2.2 Logical Operations


Logical operations allow one to combine several statements into a new com-
pound statement. We discuss the disjunction, conjunction, negation, implica-
tion, and equivalence operations. You need to be aware of the precise meaning
of these operations so that you can properly follow a mathematical argument.

Disjunction. Let A and B be statements. When is “A or B” true? In


English, the word “or” is sometimes used in the inclusive sense “A or B, or
both” and sometimes in the exclusive sense “either A or B, but not both.” For
example, if a restaurant offers complimentary coffee or tea after a meal, they
don’t expect you to choose both. If they offer milk or sugar with your coffee,
then it is meant that you can select milk, sugar, or both.
In mathematics, one cannot have this kind of ambiguity. Mathematicians
agreed that the disjunction “A or B” is always understood in the inclusive
way “A or B, or both.” For instance, if we consider a real number x, then

x ď 0 or xě0

is a true statement, even though x “ 0 fulfills both x ď 0 and x ě 0.


In symbolic logic, we write A _ B for the mathematical statement A or B.
The statements A and B can each be true or false, so there are four possibilities
in all for the arguments of the disjunction. Writing T for true and F for false,
we can express the behavior of the disjunction by the truth table

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.

Conjunction. The conjunction “A and B” is true if and only if both A is


true and B is true. The conjunction is also written as A ^ B. The truth table
14 2 Mathematical Arguments

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.

Negation. Let A be a statement. Then “not A” or “A” is the negation of


the statement. For instance, if A is the statement “We do serve breakfast until
11:00am,” then the negation A is “We do not serve breakfast until 11:00am.”
The statement A is true if and only if the negated statement A is false. The
truth table is given by
A A
F T
T F

Implication. The implication “A implies B” is particularly important in


proofs. It is often written in the form “If A, then B.” We will also denote it
as A Ñ B. We call A the hypothesis and B the conclusion.
If the hypothesis A is true and the conclusion B is true, then “A implies B”
ought to be true. If the hypothesis A is true and the conclusion B is false, then
“A implies B” ought to be false, since we do not want to conclude something
that is false from a true hypothesis.
However, it is not so clear what the truth value of the implication should
be if the hypothesis is false. Mathematicians agreed on the convention that an
implication is true if its hypothesis is false. If the hypothesis A is false, then
we say that the implication A Ñ B is vacuously true. Thus, the truth table
of the implication is given by

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

“blueberries are blue,” then the implication A Ñ B is true. Evidently, the


correctness of 1 ` 1 “ 2 does not cause blueberries to be blue. So merely the
truth of the statements A and B determine whether the implication A Ñ B is
true.

Equivalence. If an implication A Ñ B and its converse B Ñ A are both


true, then we say that A and B are equivalent and we write A Ø B. The
truth table of an equivalence is given by

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.

Boolean Formulas. A Boolean variable is a variable that can take on the


values T for true and F for false. We can construct Boolean formulas as
follows.

B1. Every Boolean variable is a Boolean formula.

B2. If A is a Boolean formula, then so is A.

B3. If A and B are Boolean formulas, then pA _ Bq, pA ^ Bq, pA Ñ Bq, and
pA Ø Bq are Boolean formulas.

A Boolean formula is formed by applying B1–B3 a finite number of times.

Example 2.1. We claim that

ppA ^ Bq Ñ pA _ Bqq

is a Boolean formula. Indeed, the Boolean variables A and B are Boolean


formulas by B1. It follows that A is a Boolean formula by B2. By B3,
pA ^ Bq and pA _ Bq are Boolean formulas. Using B3 once more, we can
conclude that ppA ^ Bq Ñ pA _ Bqq is a Boolean formula.

By building up Boolean formulas starting from Boolean variables, their


negations, and more and more complicated compound formulas, we can unravel
the syntactic structure of the Boolean formula. However, this also allows us to
form the truth table that assigns truth values to the Boolean variables. After
a truth value is assigned to a Boolean variable, we can deduce the value of its
negation. If the truth values are known for subformulas A and B, then we can
deduce the truth value for expressions such as pA _ Bq, pA ^ Bq, pA Ñ Bq, and
pA Ø Bq.
16 2 Mathematical Arguments

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

ppA ^ Bq Ñ pA _ Bqq.

The resulting truth table is given by


A B A pA ^ Bq pA _ Bq ppA ^ Bq Ñ pA _ Bqq
F F T F T T
F T T T T T
T F F F F T
T T F F T T
We observe that regardless of the assignment of truth values to A and B, the
Boolean formula ppA ^ Bq Ñ pA _ Bqq always evaluates to true.

 The definition of Boolean formulas mainly governs the syntactical as-


pect of the formulas. In other words, it determines whether a string
of symbols forms a valid Boolean formula. We are able to give meaning to a
Boolean formula by presenting its truth table. However, this approach does not
scale well, as it is limited to Boolean formulas with a small number of Boolean
variables. For this reason, we will introduce the notion of a valuation in the
next section. A valuation is a useful abstraction of a row of a truth table, but
it is more convenient to use when we reason about the meaning of Boolean
formulas.

Knights and Knaves. The inimitable Raymond Smullyan popularized a


great variety of amusing logic puzzles that are perfect to hone your skills in
logical reasoning, see [67]. Imagine an island that has two kinds of inhabitants
called knights and knaves. The knights have the property that they always
speak the truth and the knaves have the peculiar property that they invariably
lie. The problem is that one cannot tell the knights and knaves apart.
Now let us suppose you meet on the island two people A and B. Person A
says, “I am a knave but B is not.” What can you conclude about A and B?
For brevity, let us write A for the statement “A is a knight.” and B for the
statement “B is a knight.” So A made the statement A ^ B. This statement
is true if A is a knight, but it is false if A is a knave. However, we can combine
both facts into the single statement

A Ø pA ^ Bq, (2.1)

which is always true by definition of the equivalence operator. The solution to


the puzzle can now be found by considering the truth table of the statement
2.2 Logical Operations 17

(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

ppA Ñ Bq Ø pA ^ Bqq.

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

Notation Equivalent formulation Truth table Name


AKB (1) FFFF Falsehood
A^B (2) FFFT Conjunction
AÛB (3) FFTF Nonimplication
A B (4) FFTT Left projection
AÚB (5) FTFF Converse nonimplication
Y

A B (6) FTFT Right projection


A‘B (7) FTTF Exclusive or
A_B (8) FTTT Inclusive or
A_¯B (9) TFFF Nor
AØB (10) TFFT Equivalence
A¯B
Y

(11) TFTF Right complementation


AÐB (12) TFTT Converse implication
A¯B (13) TTFF Left complementation
AÑB (14) TTFT Implication
A^¯B (15) TTTF Nand
AJB (16) TTTT Tautology
Table 2.1: A table listing all 16 logical binary operators. The values of the truth
tables are listed by respectively evaluating the operators for the arguments pA, Bq in
the order pF, F q, pF, T q, pT, F q, and pT, T q

(a) A Û B using S “ t^, _, u,


(b) A_B using S “ t, Ñu,
(c) A^B using S “ t, Ñu,
(d) A Ð B using S “ t^, _, u.
In each case, prove your claim using a truth table.
2.17. Suppose Peter visits the island of knights and knaves. Peter plans to
ask every person he meets the question “Are you a knave?” Explain to Peter
why his question is useless.
2.18. Suppose that A and B are inhabitants of the island of knights and knaves.
Suppose that A says “I am a knave or B is a knight” and B does not say
anything. What can you say about A and B?
2.19. Suppose that we visit the island of knights and knaves and meet A and
B. If A says “We are both knaves” and B says nothing, what can you conclude
about A and B?
2.20. Suppose that we visit the island of knights and knaves. We meet the
friendly inhabitants A and B. Then A tells us that “B is a knight” and B
asserts that “the two of us are of opposite type.” What are the types of A and
B?
2.21. Suppose that you visit the island of knights and knaves. You meet four
people A, B, C, and D. First A declares, “If B is a knave, then D is a knave.”
20 2 Mathematical Arguments

Then B adds, “If D is a knight, then A is a knave”. Finally, C utters, “A is a


knave or B is a knight”. The last person D does not say anything and looks
rather grim. Who is a knight and who is a knave?
2.22. Suppose that you visit the island of knights and knaves. You meet a
group of five people and ask them: How many of you are knaves? The first
answers that one of them is a knave, the second answers that two are knaves,
the third answers that three of them are knaves, the fourth answers that there
are four knaves, and the fifth person answers—unsurprisingly—that there are
five knaves. At first, you might think that this question was quite useless, given
the variety of answers. At second thought, you realize that you can actually
figure out how many knaves there are. So how many are there? [Hint: You
can easily obtain the answer by logical reasoning.]

2.3 Logical Equivalence


We call two Boolean formulas equivalent if and only if they evaluate to the
same truth values for all possible truth assignments. We begin by introducing
the concept of a valuation that generalizes a row of a truth table to an arbitrary
number of Boolean variables.
A valuation v is a function from the set of Boolean formulas to the set of
truth values such that it assigns to propositional variables a truth value and is
compatible with the usual interpretation of the logical operators, namely
V1. vA “ vA,
V2. vA _ B “ vA _ vB,
V3. vA ^ B “ vA ^ vB,
V4. vA Ñ B “ vA Ñ vB,
V5. vA Ø B “ vA Ø vB.
The valuations are conceptually simple. Essentially, the truth values are as-
signed to the variables and consistently extended to Boolean formulas.
Example 2.2. Suppose that we are given the Boolean formula A Ø pB ^Cq.
If a valuation v assigns the truth values

vA “ F, vB “ T, vC “ F,

then we can deduce vC “ vC “ T . Furthermore,

vB ^ C “ vB ^ vC “ T ^ T “ T.

Therefore, we can conclude that the valuation v must assign to the Boolean
formula A Ø pB ^ Cq the truth value

vA Ø pB ^ Cq “ vA Ø pvB ^ Cq “ F Ø T “ F.


2.3 Logical Equivalence 21

As long as we restrict ourselves to one particular Boolean formula, then after


assigning truth values to the variables that occur in the formula, the truth
value of the formula is determined by this assignment.

A Boolean formula A is called a tautology if and only if vA “ T holds


for all valuations v. In other words, A is a tautology if and only if T is the
value of A in every row of its truth table.
A Boolean formula A is called satisfiable if and only if vA “ T holds for
some valuation v. Put differently, the Boolean formula A is satisfiable if and
only if in the truth table of A, there exists some row such that A evaluates to
T.
We call two Boolean formulas A and B logically equivalent if and only
if vA “ vB holds for all valuations v. We write A ” B if and only if A and
B are logically equivalent. For example, the double negation A is logically
equivalent to A, so A ” A.

Proposition 2.3. Let A and B be statements. Then A Ñ B ” A _ B.

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

holds for all valuations v, which is equivalent to saying that A Ø B is a


tautology.

Proof. It suffices to show that pA Ñ Bq Ø pA _ Bq is a tautology. Indeed,


consider the truth table
A B AÑB A _ B pA Ñ Bq Ø pA _ Bq
F F T T T
F T T T T
T F F F T
T T T T T

Therefore, pA Ñ Bq Ø pA _ Bq is a tautology, which means that A Ñ B ”


A _ B, as claimed.

The contrapositive of an implication A Ñ B is the implication B Ñ A.


Remarkably, the contrapositive of an implication expresses the same logical
operation as the implication itself, as the next proposition shows.
22 2 Mathematical Arguments

Proposition 2.4. An implication A Ñ B and its contrapositive B Ñ A


are logically equivalent, A Ñ B ” B Ñ A.

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

We notice that the implication A Ñ B and its contrapositive B Ñ A are


false precisely when A is true and B is false.

 The converse of an implication A Ñ B is the implication B Ñ A.


The truth of one implication does not say anything about the truth of
the other. For example, the implication

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.

Proposition 2.5. Let A, B, and C be Boolean formulas. Then


(a) A ^ pB ^ Cq ” pA ^ Bq ^ C (associative law)
(b) A ^ B ” B ^ A (commutative law)
(c) A ^ A ” A (idempotence law)
(d) A ^ T ” A (identity law)
(e) A ^ F ” F (domination law)

Proof. One can use truth tables to prove these laws, see Exercise 2.28.

The disjunction operation has very similar laws.

Proposition 2.6. Let A, B, and C be Boolean formulas. Then


(a) A _ pB _ Cq ” pA _ Bq _ C (associative law)
(b) A _ B ” B _ A (commutative law)
(c) A _ A ” A (idempotence law)
(d) A _ F ” A (identity law)
2.3 Logical Equivalence 23

(e) A _ T ” T (domination law)

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.

Proposition 2.7 (De Morgan’s Laws). Let A and B be Boolean formulas.


Then
(a) pA ^ Bq ” A _ B,
(b) pA _ Bq ” A ^ B.

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.

Applying the not operator to both sides, we obtain pA _ Bq ” A ^ B,


which proves our claim (b).

Suppose that C is a Boolean formula containing A as a subformula. Given


a logical equivalence A ” B, we can substitute the expression B for A in C and
obtain a new formula C 1 . Since A and B take on the same truth values for all
valuations, we can conclude that C ” C 1 . We will call this the substitution
technique.
In the proof of the next proposition, we will illustrate how to use this sub-
stitution technique repeatedly to prove the claims (b) and (c) after establishing
that conjunction distributes over disjunction.

Proposition 2.8. Let A, B, and C be Boolean formulas. We have


(a) A^pB_Cq ” pA^Bq_pA^Cq (conjunction distributes over disjunction)
(b) A_pB^Cq ” pA_Bq^pA_Cq (disjunction distributes over conjunction)
(c) A ^ pA _ Bq ” A (absorption law for conjunction)
(d) A _ pA ^ Bq ” A (absorption law for disjunction)
24 2 Mathematical Arguments

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

vA ^ pB _ Cq “ vpA ^ Bq _ pA ^ Cq,

so the claimed logical equivalence A ^ pB _ Cq ” pA ^ Bq _ pA ^ Cq holds.


(b) We can deduce the second distributive law using the distributive law from
part (a) and repeated application of de Morgan’s law,

A _ pB ^ Cq ” pA _ pB ^ Cqq by double negation


” pA ^ pB ^ Cqq by de Morgan’s law
” pA ^ pB _ Cqq by de Morgan’s law
” ppA ^ Bq _ pA ^ Cqq by the distributive law (a)
” pA ^ Bq ^ pA ^ Cq by de Morgan’s law
” pA _ Bq ^ pA _ Cq by de Morgan and double negation

(c) We can show the absorption law for conjunction using a series of known
logical equivalences. Indeed,

A ^ pA _ Bq ” pA _ F q ^ pA _ Bq by the identity law


” A _ pF ^ Bq by the distributive law
” A _ F by the domination law
” A by the identity law

(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.25. Show that pA Ñ Bq ^ pB Ñ Aq and A Ø B are logically equivalent.


2.4 Logical Consequence 25

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.

2.4 Logical Consequence


In this section, we will start to formalize the notion of valid logical arguments.
These arguments must entail the conclusion from one or more premises. A
valid argument must ensure that its conclusion is true whenever the premises
are true. We will formalize this using the notion of logical consequence.
Let S be a set of Boolean formulas. We say that a Boolean formula C is
a logical consequence of S if and only if for all valuations v, the condition
vP  “ T for all P in S implies vC “ T . We write
S(C
to express that C is a logical consequence of S. In other words, we write
S ( C if and only if there does not exist a valuation v such that vC “ F
when vP  “ T holds for all formulas P in S.
26 2 Mathematical Arguments

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

equivalent to the nonexistence of a valuation v such that vP1 ^ ¨ ¨ ¨ ^ Pn  “ T


and vC “ F . In other words, there does not exist a valuation v such that
vP1 ^ ¨ ¨ ¨ ^ Pn Ñ C “ F , which is simply a different way of expressing that
the formula pP1 ^ P2 ^ ¨ ¨ ¨ ^ Pn q Ñ C is a tautology.

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

is a valid argument by proving that pP1 ^ P2 ^ ¨ ¨ ¨ ^ Pn q Ñ C is a tautology,


regardless of the complexity of the argument. However, this is impractical, as
the number of rows in the truth table grows exponentially with the number of
Boolean variables that occur in the premises and conclusion.
In general, we will verify the logical consequence for a few simple rules such
as the resolution rule or the modus ponens. We will then compose an argument
as a sequence of steps, where each step uses either an axiom or a rule whose
correctness we have established. The advantage of this modular approach is
that it is easier to verify the correctness of such a proof. In the next section,
we will give a first taste of such formal proofs.

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

2.37. Determine whether the following is a valid argument:

A ( pA ^ Bq.

2.38. Determine whether the following is a valid argument:

tpA _ Bq, pA _ Cqu ( pA ^ Cq.

2.39. Determine whether the following is a valid argument:

tpA Ñ pB _ Cqq, pB Ñ Cqu ( pA Ñ Cq.

2.40. Determine whether the following argument is valid:

tpA Ñ pB _ Cqq, pB Ñ pA ^ Cqqu ( pA Ñ Cq.

2.41. Let P1 , P2 , . . . , Pn and A be Boolean formulas. Show that tP1 , P2 , . . . , Pn u (


A if and only if tP1 , P2 , . . . , Pn u Y tAu is not satisfiable.

2.42. What is a potential practical problem when formulating an argument


about propositional logic in the form tP1 , P2 , . . . , Pn u ( C?

2.5 Formal Arguments


In this section, we will study a propositional calculus that allows us to
formally deduce a conclusion C from premises P1 , . . . , Pn using an argument
that consists of several steps. In each step, we use an axiom, the premises,
or some already established result and apply some inference rule until we can
conclude C. This mimics the style of mathematical arguments, but is more
detailed and more formal.
A propositional calculus is a special type of formal system. A formal
system consists of a formal language, a set of axioms, and a set of inference
rules. We will now introduce these three components for the propositional
calculus.

Formal Language. We will confine ourselves in our formal language to


Boolean formulas that contain operators from the set t, Ñu. This does not
restrict expressiveness, since all other logical operators can be defined with the
help of negation and implication, see Exercises 2.43 and 2.45. However, our
exposition is simplified by restricting to these two logical operators.

Axioms. Let A, B, and C denote Boolean formulas. Then we have the


following three axiom schemes:

A1. A Ñ pB Ñ Aq,

A2. pA Ñ pB Ñ Cqq Ñ ppA Ñ Bq Ñ pA Ñ Cqq,


2.5 Formal Arguments 29

A3. pB Ñ Aq Ñ pA Ñ Bq.

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,

and additionally Sm coincides with the desired conclusion C.


Notation. If P consists of a single premise P “ tAu, then we write A $H C
instead of the more cumbersome tAu $H C. If the set P of premises is empty,
then we write shortly $H C instead of H $H C.
We will use a very small example to illustrate this style of formal argument.

Example 2.12. We will formally prove that A $H pA Ñ Aq. In other words,


we will deduce pA Ñ Aq from the assumption A. We can take advantage of
30 2 Mathematical Arguments

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

P Y tAu $H B if and only if P $H A Ñ B.

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

By the deduction theorem, this statement is equivalent to

tA Ñ B, A Ñ pB Ñ Cq, Au $H C

However, proving the latter claim is simple, as

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

holds. This means that there exists a sequence of Boolean formulas

S1 , S2 , . . . , S m

satisfying F1, F2, or F3 for each index k in the range 1 ď k ď m and Sm “ C.


Let v be any valuation such that vA “ T holds for all premises A P P .
We claim that vSk  “ T holds for all k in the range 1 ď k ď m.
We use a proof by contradiction to prove this claim. Seeking a contradiction,
let us assume that k is the smallest index in the range 1 ď k ď m such that
vSk  “ F . The step Sk in the proof can arise from F1, F2, or F3. So let us
examine each of these three cases.
(1) If Sk results from F1, then Sk is an axiom, hence it is a tautology by
Exercise 2.46, which means that vSk  must evaluate to true.
(2) If Sk results from F2, then Sk is a premise, so satisfies vSk  “ T by
assumption.
(3) If Sk “ B results from F3, then it was obtained from prior steps Si “ A
and Sj “ A Ñ B using the modus ponens rule R1. Since the indices i
and j are smaller than k, we have vSi  “ T and vSj  “ T . However, the
modus ponens is a valid argument by Example 2.9. Therefore, we must
have vSk  “ T .
In all three cases, we get a contradiction to vSk  “ F . Therefore, we can
conclude that vSk  “ T holds for all k in the range 1 ď k ď m. In particular,
we can conclude that vSm  “ vC “ T .
Since v was an arbitrary valuation, this means that P ( C, as claimed.

The propositional calculus satisfies a rather remarkable property. One can


show that the three axiom schemes and modus ponens alone suffice to prove
every valid argument.
Theorem 2.18 (Completeness Theorem). Let P be a set of Boolean formulas
and C a Boolean formula. If P ( C, then P $H C. In other words, every
valid argument of propositional logic can be proved in the formal system H.
The proof of the completeness theorem is more involved than the proof of
the soundness theorem. We will not discuss a proof here, as this would lead
us too far astray. The interested reader can find a proof in most textbooks on
logic, such as Goldrei [29].

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

Modus Tollens Disjunctive Syllogism


AÑB A_B
B A
A B
Reductio ad Absurdum Resolution Rule
AÑB A_B
A Ñ B A _ C
A B_C
Weakening of a Conjunction Weakening to a Disjunction
A^B A^B A B
or or
A B A_B A_B

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.

Proposition 2.19 (Modus Tollens). If A and B are Boolean formulas, then

tA Ñ B, Bu $H A.

Proof. We have

p1q $H pA Ñ Bq Ñ pB Ñ Aq by axiom A3


p2q A Ñ B $H B Ñ A by the deduction theorem
p3q tA Ñ B, Bu $H A by the deduction theorem,

as claimed.

One example should suffice to illustrate this argument form.

Example 2.20. Consider the argument: If it rains in Texas, then it pours. It


does not pour. Therefore, it does not rain in Texas. If we denote the statement
“It rains in Texas” by A and “It pours” by B, then we see that the argument
is of the form

AÑB If it rains in T exas, then it pours.


B It does not pour.
A It does not rain in T exas.

This example is a typical use of the modus tollens inference rule.


34 2 Mathematical Arguments

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.

2.6 Predicates and Quantifiers


The propositional logic that we have discussed so far is not expressive enough to
formulate most mathematical proofs. We will now study first-order languages
that generalize propositional logic and form an appropriate framework for most
mathematical arguments. We will informally explain the two main concepts
on which first-order languages are based.
2.6 Predicates and Quantifiers 35

Predicates. We often like to express statements that depend on one or more


parameters. For example, let P pnq have the interpretation

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

the fact that if n is positive, then n ` 1 must be positive. This implication is


true for all integers n.
The parameters of a predicate can take on values from the universe of
discourse, or shortly called the universe. The universe comprises elements
that one wants to refer to in the predicates. For example, the universe could
be the set of integers, the set of real numbers, the set of all people, or the like.
A predicate can have several arguments. A predicate P px1 , . . . , xn q with
n arguments is called a predicate of degree n or an n-ary predicate. An
interpretation of a predicate of degree n decides for which n-tuples of elements
from the universe the predicate is supposed to be true. In the language of set
theory of the next chapter, a predicate is then interpreted as a characteristic
function of an n-ary relation.
Example 2.21. Suppose that the universe of discourse is the set of points in
the Euclidean plane. If the predicate Cpx, yq has the interpretation x2 `y 2 ď 1,
then Cpx, yq evaluates to true for any point px, yq that belongs to the unit circle
about p0, 0q, and false for any point that lies outside this circle (Fig. 2.1).

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

Quantifiers. We frequently want to express that a predicate is true for all


elements of the universe. Suppose that a predicate P pnq has the interpretation
pn!q2 ě nn , where n! is the factorial function that is the product of the first n
positive integers, n! “ 1 ¨ 2 ¨ . . . ¨ n. A typical mathematical statement is

f or all positive integers n, the inequality pn!q2 ě nn holds.

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

DnpP pnq ^ P pn ` 1qq

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

@a@b ppn “ a ¨ bq Ñ ppa “ 1q _ pb “ 1qqq ^ pn ą 1q,

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.

 A formula may have a variable that occurs both as a bound variable


in one subexpression and as a free variable in another. For instance,
the variable x in the expression

p@xP pxqq ^ Qpxq,

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,

is equivalent, but less confusing.

If an expression is quantified by two universal quantifiers such as

@a@bP pa, bq,

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.55. Express each of the following statements in first-order predicate logic.


Specify the universe of discourse and predicates when needed.
(a) Every integer is a rational number.
(b) The square of any real number does not equal ´1.
(c) There exists an integer that is equal to its own square.
(d) There do not exist positive integers x, y, and z such that x3 ` y 3 “ z 3
(e) For every positive real number x, there exists a positive real number y such
that x “ y 2 .

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.25. Suppose that A is the statement “the triangle DEF is


an isosceles triangle” and B the statement “the triangle DEF is a right
triangle.” Then A ^ B means
The triangle DEF is an isosceles triangle and a right triangle.
When we negate this statement, we have to be careful where we insert the word
“not” to obtain the correct negation pA ^ Bq of the statement. One correct
version is “It is not the case that the triangle DEF is an isosceles triangle
and a right triangle.” De Morgan’s law leads to the more transparent version
“The triangle DEF is not an isosceles triangle or is not a right triangle.”

Sometimes we will need to negate an implication. Since A Ñ B ” A _ B,


the negation yields
N4. pA Ñ Bq ” pA _ Bq ” A ^ B
by de Morgan’s law. Thus, the negation of an implication is the conjunction
of the hypothesis with the negated conclusion.

 The negation of an implication can never be an implication! This is a


common error that beginners are prone to make.

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.”

The negation of an equivalence A Ø B is given by


N5. pA Ø Bq ” A Ø B.
40 2 Mathematical Arguments

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.

The negation of statements that involve existential or universal quantifiers


is fairly straightforward as well. If P pxq is a predicate, then
N6. @x P pxq ” Dx P pxq,
N7. D xP pxq ” @x P pxq.
We justify the previous two laws in the next proposition.

Proposition 2.28. The negation laws N6 and N7 for quantified expressions


are valid.

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.”

The formalism shines when we want to determine the negation of expres-


sions with multiple quantifiers. In such cases, we rely on repeated application
of the laws N6 and N7. The next example illustrates this for the negation of
a statement with three quantifiers.

Example 2.31. Suppose that we want to negate the expression

@xDy@zCpx, y, zq.
2.7 Negations 41

Then repeatedly applying the rules for negation yields

@xDy@z Cpx, y, zq ” DxDy@z Cpx, y, zq


” Dx@y@z Cpx, y, zq
” Dx@yDz Cpx, y, zq.

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

(a) Reformulate the definition of a limit in predicate logic.


(b) Negate the resulting statement.
(c) Rewrite the condition for the nonexistence of a limit in plain English.

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.

Terminology. Before we proceed, it might be helpful to clarify some math-


ematical terminology. Mathematical statements are often called theorems,
propositions, lemmas, corollaries, or scholia. The name helps the reader judge
how important a statement is. By convention, a mathematical statement is
usually called a proposition. If we want to emphasize the importance of a
proposition, then we call it a theorem. A lemma is a statement that is used in
the course of a proof of another proposition or theorem. If a proposition is a
simple consequence of another proposition or theorem that hardly requires a
proof, then it is called a corollary. A commentary on an important theorem is
called a scholium.

Direct Proofs. Many mathematical statements are of the form A Ñ B. In


a direct proof of A Ñ B, we assume that the hypothesis A is true and deduce
the conclusion B. This is a valid proof technique, since A Ñ B is vacuously
true when A is false.

Direct Proof To prove that a claim “If A, then B” holds, we


can proceed as follows.
Proof Suppose that A holds.
..
.
Deduce B using axioms, rules of inference, and prior results.

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.

Proposition 2.32. If n is an odd integer, then n2 is an odd integer as well.

Proof. If n is an odd integer, then by definition there must exist an integer k


such that n “ 2k ` 1. It follows that n2 “ p2k ` 1q2 . Expanding the right-hand
side yields
n2 “ 4k 2 ` 4k ` 1 “ 2p2k 2 ` 2kq ` 1.
2.8 Proofs 43

Since 2k 2 ` 2k is an integer, it follows that n2 is an odd integer, which proves


the claim.

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.

Proof. If n is an odd integer, then there exists by definition an integer k such


that n “ 2k ` 1. Then adding 0 “ k 2 ´ k 2 to n “ 2k ` 1 yields

n “ 2k ` 1 “ k 2 ` 2k ` 1 ´ k 2
“ pk ` 1q2 ´ k 2 ,

which is a difference between two perfect squares, as claimed.

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

The number 1 is a unit. A positive integer p ą 1 whose only positive


divisors are 1 and itself is called a prime number. An integer c ą 1 that is
not a prime number is called a composite number. The difference between
two successive prime numbers is called a prime gap. For example, if we look
at the first few prime numbers,

2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37,

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.

Proof. For all integers k in the range 2 ď k ď n ` 1, the integer pn ` 1q! ` k


is divisible by k. Therefore, there exists a sequence of n consecutive composite
numbers, for instance, none of the 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.

The triangle inequality is a simple observation that is often useful.

Proposition 2.37 (Triangle Inequality). If a and b are real numbers, then

|a ` b| ď |a| ` |b|.

Proof. We observe that the square of the left-hand side is equal to

|a ` b|2 “ pa ` bq2 “ a2 ` 2ab ` b2


“ |a|2 ` 2ab ` |b|2
2
ď |a|2 ` 2|a| |b| ` |b|2 “ p|a| ` |b|q

By taking the square root of both sides, we obtain the claim.


2.8 Proofs 45

Proofs by Contraposition. If we want to prove that an implication A Ñ


B is true, then it suffices to show that B Ñ A is true, since the two
implications are logically equivalent. This is called a proof by contraposition.

Proof by Contraposition To prove that a claim “If A, then


B” holds, we can proceed as follows.
Proof (By Contraposition)
Suppose that B holds.
..
.
Deduce A using axioms, rules of inference, and prior results.

An example will make this proof strategy clear.

Proposition 2.38. If n2 is an even integer, then n is an even integer.

Proof. (By Contraposition.) Let n be an integer. Suppose that n is not even.


Therefore, n is odd. By Proposition 2.32, it follows that n2 is an odd integer.
The claim follows, since we proved its contrapositive.

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.

Proof. (By Contraposition.) We are going to prove the contrapositive of the


claim: if a divides b or a divides c, then a divides bc. We will discuss the two
cases (a) a divides b and (b) a divides c separately.
(a) Suppose that a divides b. This means that there exists an integer q such
that b “ aq. Then bc “ aqc, so a | bc.
(b) Suppose that a divides c. This means that there exists an integer p such
that c “ ap. Then bc “ bap “ abp, so a | bc.
We can conclude that a divides bc. Therefore, we have proved the claim by
contraposition.

Proposition 2.40. Let n be a positive integer. If 4n ´ 1 is prime, then n is


odd.

Proof. We prove the contrapositive: if n is even, then 4n ´ 1 is composite.


If n is even, then there must exist a positive integer k such that n “ 2k.
Then 4n ´ 1 “ 42k ´ 1 “ p4k ´ 1qp4k ` 1q is composite, which proves the claim
by contraposition.
46 2 Mathematical Arguments

Proofs by Contradiction. In a proof by contradiction, our goal is to prove


a mathematical statement A by assuming its negation A as a hypothesis and
deriving a contradiction. Put differently, we prove A by showing that A Ñ F
is true. Since the implication A Ñ F can only evaluate to true when A is
false, it must be the case that the statement A is true.

Proof by Contradiction To prove that a claim A holds, we


can proceed as follows.
Proof Seeking a contradiction, suppose that A holds.
..
.
Deduce falsity F .

 If you want to prove a statement A using a proof by contradiction,


then you need to make sure that your hypothesis is the negation A
of the statement that you would like to prove. A common mistake is to start
with a statement that is not precisely the negation of A.

Let us have a look at a simple example. A rational number is a fraction


of two integers such as 1{3 or 2{17. The claim is that there cannot exist a
smallest positive rational number. This means that the set of positive rational
numbers is qualitatively different from the set of positive integers, where 1 is
evidently the smallest positive integer.
In general, it is a good idea to warn the reader that the proof will be by
contradiction, for instance, by starting your proof with the phrase “Seeking a
contradiction, we assume.”

Proposition 2.41. There does not exist a smallest positive rational number.

Proof. Seeking a contradiction, we assume that there exists a smallest positive


rational number s. Then s{2 is a positive rational number that is smaller
than s, which contradicts our choice of s.

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.

Proposition 2.43. Any integer m ą 1 can be factored into a product of primes.

Proof. Seeking a contradiction, let us assume that m is the smallest integer


m ą 1 that cannot be factored into a product of primes. In particular, m
cannot be a prime and must be composite. Thus, m “ ab for some positive
2.8 Proofs 47

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 

such that a1 , a2 , . . . , ak and b1 , b2 , . . . , b are primes. This would mean that m “


a1 a2 ¨ ¨ ¨ ak b1 b2 ¨ ¨ ¨ b is a product of primes, contradicting our assumption.

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.

Let us conclude this chapter with a particularly striking application of a


proof by contradiction. The game of hex was invented by the Danish mathe-
matician, scientist, and poet Piet Hein and later rediscovered by John Nash.
It is a board game that is played by two players on an n ˆ n rhombus-shaped
grid with hexagonal fields. Two opposing sides of the game board are labeled
white and the other two are labeled black. The four corner hexagons belong
to either side. A 4 ˆ 4 game board is depicted on the left of Fig. 2.3.
One player plays white playing pieces and the other plays black. The players
take turns placing a single playing piece of their color into an empty hexagon
cell anywhere on the game board. The goal of each player is to connect the
two sides of their color with a connected path of playing pieces of their color.
The first player to connect the two regions of their color wins. Figure 2.3 on
the right shows a game that ends with White winning after a total of 7 moves.
One can show that the game of hex cannot end in a tie. Nash proved in
1952 that the first player has a winning strategy assuming optimal play. We
give his argument here.
Theorem 2.46. The first player in a hex game has a winning strategy.
48 2 Mathematical Arguments

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.

2.67. Let n be a positive even integer. Show that

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

|a| ` |b| ď |a ` b| ` |a ´ b|.

2.70. Let m and n be integers. Use a proof by contraposition to show that if


their sum m ` n ą 100, then m ą 40 or n ą 60.

2.71. Let n be a positive integer. Use a proof by contraposition to show that


if n ě ab for some positive integers a and b, then a ď n1{2 or b ď n1{2 .

2.72. Let m be an integer. Use a proof by contraposition to show that if 5m`7


is even, then m is odd.

2.73. Let n be a positive integer. Use a proof by contraposition to show that


if 2n ´ 1 is prime, then n must be prime. [A prime Mn of the form Mn “ 2n ´ 1
is called a Mersenne prime.]

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.

3.1 Background and Motivation


A set is a collection of distinct objects. The objects contained in a set are
called its elements. For instance,

t1, 2, 3u

is the set containing three elements, namely 1, 2, and 3. Another set is


tA, B, C, D, Eu that contains the five elements A, B, C, D, and E.
Sets were implicitly used by mathematicians since antiquity. However, they
were not seriously studied in their own right before Cantor conceived his theory
of sets. Set theory quickly flourished and soon became an established math-
ematical area. Nowadays, sets are commonly used as a foundation for most
mathematical theories.
Sets can have a finite number of elements or an infinite number of elements.
One of the key insights by Cantor was that infinite sets can come in different
sizes (or, in technical terms, cardinalities). One of the many consequences of
this fact is a simple proof for the existence of functions on the natural numbers

© The Author(s), under exclusive license to Springer Nature 51


Switzerland AG 2025
A. Klappenecker, H. Lee, Discrete Structures, Undergraduate Texts in
Mathematics, https://doi.org/10.1007/978-3-031-73434-2 3
52 3 Sets

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.

3.2 Fundamental Concepts


The central concept of mathematics is a set. A set is an abstraction of a
container. The objects contained in it are called its elements. We write

aPA

to denote that a is an element of the set A. If a is not an element of A, then


we write a R A. Put differently, a R A is the negation of a P A.
The first axiom asserts that there exists a set that does not contain any
elements.

S1. There exists a set that does not have any elements.

We call it the empty set and denote it by H, or by tu. The membership


relation a P H is always false. The empty set occurs more often than you
might think. Its role in set theory is similar to the role of 0 in the integers.
The second axiom asserts that the membership relation completely deter-
mines the equality of sets.

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.

S3. Let a1 , . . . , an be sets. Then there exists a set S such that


x P S if and only if x “ a1 or x “ a2 or ¨ ¨ ¨ or x “ an .
3.2 Fundamental Concepts 53

The set S is commonly denoted by listing its elements in curly braces,

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.

Example 3.1. The four sets

S1 “ tHu, S2 “ tH, Hu, S3 “ tH, H, Hu, S4 “ tH, H, H, Hu

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

S1 “ tH, tHu, tH, tHuuu, S2 “ tH, tH, tHuu, tHuu,


S3 “ ttHu, H, tH, tHuuu, S4 “ ttHu, tH, tHuu, Hu,
S5 “ ttH, tHuu, H, tHuu, S6 “ ttH, tHuu, tHu, Hu.

Each set S1 , S2 , . . . , S6 is equal to S, as the order of elements does not matter


by axiom S2.
54 3 Sets

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.

The idea of defining a nonnegative integer n by a set with n elements goes


back to von Neumann. We will explore his construction in depth later on.
One can apply the same principle to other objects. The next example briefly
sketches one possible set-theoretic representation of ASCII characters.

Example 3.5. If we want to reason about sets of ASCII characters, then we


can use von Neumann’s idea and represent the upper case A with ASCII code
65 by a set with 65 elements, the lower case a with ASCII code 97 by a set
with 97 elements, and so on. This allows us to form sets of characters such as
tA, B, Cu.

A set A is called a subset of a set B if and only if all elements of A are


also elements of B. We write A Ď B to denote that A is a subset of B. If A is
a subset of B, but not equal to B, then we call A a proper subset of B. We
write A Ĺ B to denote that A is a proper subset of B.

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.

Proof. Since A Ď B, x P A implies x P B. Since B Ď A, x P B implies x P A.


Therefore, x P A if and only if x P B, which means that 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.

Proposition 3.8. The empty set is a subset of each set.


3.2 Fundamental Concepts 55

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.

The most common way to specify a subset of a set A is by defining a


property Spxq that an element x of A may or may not have.

S4. Let Spxq be a property of x. For a set A, there exists a set


B such that x P B if and only if x is an element of A that
has property Spxq.

The set B is commonly denoted by

tx P A | Spxqu.

The main point of the construction is that a subset of A is obtained by filtering


out all elements x that do not satisfy Spxq. What remains is evidently a subset
of A, and it contains precisely the elements x of A that do satisfy the property
Spxq.
There are some technicalities to keep in mind. We need to be able to specify
the property Spxq using a formula in the first-order language of set theory that
has only x as a free variable. Furthermore, the formula Spxq cannot reference
the set B, so that circular definitions are avoided. In other words, Spxq is
constructed using the equality “ and the membership relation P, the logical
operators , ^, _, Ñ, and Ø, as well as the quantifiers @ and D using the rules
of first-order languages.
The next example illustrates this principle.

Example 3.9. Let A denote the set

A “ tH, tHu, tH, tHuu, tH, tHu, tH, tHuuuu

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

tx P A | Spxqu “ tx P A | tHu P xu “ ttH, tHuu, tH, tHu, tH, tHuuuu

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 element, namely H, but this element is different from tHu.


56 3 Sets

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

A “ tH, tHu, tH, tHuu, tH, tHu, tH, tHuuuu

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

tx P S | x is a prime factor of 1947u

is equal to the set t3, 11, 59u.


Remark 3.12. The idea behind set comprehension has also inspired set and list
comprehension in programming languages, including Haskell, Python, Ruby,
and many others.
So let us get back to set theory. In the next axiom, we postulate that one
can collect all of the subsets of a set into a set.

S5. For a set A, there exists a set that contains all subsets of A
as elements.

We call this set the power set of A and denote it by P pAq.


The power set P pAq contains the empty set H as well as the set A and any
set in between these two extremes.
Example 3.13. We offer three small examples.
(a) The power set of the empty set is given by P pHq “ tHu.
3.2 Fundamental Concepts 57

(b) The power set of a singleton set is given by P ptauq “ tH, tauu.

(c) The power set of a set with two elements is given by

P pta, buq “ tH, tau, tbu, ta, buu.

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

H, tau, tbu, ta, bu.

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

tcu, ta, cu, tb, cu, ta, b, cu.

Therefore, the power set P pta, b, cuq is given by

P pta, b, cuq “ tH, tau, tbu, ta, bu, tcu, ta, cu, tb, cu, ta, b, cuu.

So P pta, b, cuq contains twice as many elements as P pta, buq.

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.

Theorem 3.15. A set having all sets as elements cannot exist.

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.

of U . Since C is both an element of U and a subset of U , we have two choices:


either the element C belongs to the subset C or it does not belong to it. Let
us carefully inspect both cases.

(a) If C P C, then we have C R C by definition of C, which is absurd.


(b) If C R C, then we have C P C by definition of C, which is also absurd.

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

Some readers might not feel comfortable with the definition

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.

S6. 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.

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.5. Show that if S is a set, then S P P pSq.

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.]

3.11. Let A and B be sets. Show that P pAq “ P pBq implies A “ B.

3.12. Let A be a set containing elements a, b, and c. Show that

ttau, ta, bu, ta, b, cuu

is an element of P pP pAqq.

3.13. Show that a set cannot contain its power set.

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

holds for all positive integers n.


60 3 Sets

3.3 Intersections and Unions


Given two sets A and B, we can form the subset

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

A X B “ t2, 4u, A X C “ t1, 3, 5u, B X C “ H.

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

Proof. We have x P A X pB X Cq if and only if x P A and x P pB X Cq.


The latter condition holds if and only if x P A and x P B and x P C. The
condition x P A and x P B and x P C holds if and only if x P pA X Bq and
x P C, and the latter condition is equivalent to x P pA X Bq X C. Therefore,
A X pB X Cq “ pA X Bq X C.
The proof for the associativity of unions is similar.
One can use a similar style of proof to show that set intersection and set
union are commutative operations, so
A X B “ B X A and AYB “BYA
hold for all sets A and B. The operations are idempotent,
A X A “ A and A Y A “ A.
The empty set is a zero element for the intersection operation
A X H “ H X A “ H,
and a neutral element for the union operation
A Y H “ H Y A “ A.

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

It is interesting to see how the two set operations interact.


Proposition 3.19. Set intersection and set union satisfy the distributive laws
A X pB Y Cq “ pA X Bq Y pA X Cq,
A Y pB X Cq “ pA Y Bq X pA Y Cq,
for all sets A, B, and C.
62 3 Sets

Proof. We have x P A X pB Y Cq if and only if x P A and x P pB Y Cq if and


only if x P A and (x P B or x P C). This is equivalent to (x P A and x P B) or
(x P A and x P Cq and this holds if and only if x P pA X Bq Y pA X Cq.
We leave the proof of the second assertion to the reader. A visual “proof”
motivating the correctness of the assertion is given in Fig. 3.2.

General Intersections and Unions. Set intersections and unions can be


extended to an arbitrary
Ş number of sets. The sets are collected in a family S.
The intersection S of a nonempty family S is defined to be the set
č
S “ tx P X | for all A P S, x P Au,

where X is an element of S. The intersection of S contains the elements that


are common to all members of the family S.

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.

The next axiom postulates the existence of the union of 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|.

3.4 Differences and Symmetric Differences


In this section, we introduce the set difference operation that singles out ele-
ments that belong to one set but not another. The set difference between a
fixed large set and a subset is called a complement, which has a convenient
notation. The final operation that we introduce is the symmetric difference
that has nicer properties than the set difference.

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.

The set difference can characterize subsets, since

A´B “H if and only if A Ď B;


64 3 Sets

and disjoint sets, because

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.

Proposition 3.23. For all sets A, B, and C, the de Morgan’s laws

C ´ pA X Bq “ pC ´ Aq Y pC ´ Bq,
C ´ pA Y Bq “ pC ´ Aq X pC ´ Bq

hold.

Proof. We have x P C ´ pA X Bq if and only if x P C and x R A X B. The latter


condition is equivalent to x P C and not px P A X Bq or equivalently x P C and
not (x P A and x P B). We can rewrite this condition in the logically equivalent
form x P C and (x R A or x R B), which can also be expressed in the form (x P C
and x R A) or (x P C and x R B). In other words, this condition is equivalent
to x P pC ´ Aq or x P C ´ B, which can be rewritten as x P pC ´ Aq Y pC ´ Bq.
Therefore, we can conclude that C ´ pA X Bq “ pC ´ Aq Y pC ´ Bq.
We leave the proof of the second de Morgan’s law to the reader.

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

pA X BqA “ AA Y B A and pA Y BqA “ AA X B A .

Furthermore, we have the identities

A Y AA “ U and A X AA “ H,

as well as the double complement identity pAA qA “ A. The complement notation


often allows one to simplify proofs. For example, let the universe U contain
both A and B. Then
A ´ B “ A X BA.

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

Symmetric Difference. The symmetric difference between A and B is


the set A  B defined by

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

The symmetric difference has the empty set as a neutral element, so

AH “ HA “ A

holds for all sets A. Every set A is its own inverse

A  A “ H.

The symmetric difference is commutative, so

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.

The symmetric difference A  B consists of the elements in A Y B that do


not belong to A X B. This is evident from the Venn diagram in Fig. 3.3. We
will now give a formal proof that uses algebraic manipulation to derive the set
identity given in the next lemma.

Lemma 3.24. We have

A  B “ pA Y Bq ´ pA X Bq.
66 3 Sets

Proof. Let U “ A Y B be the universe. Then

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,

which proves the claim.

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.

Proposition 3.25. The symmetric difference is an associative operation, so

A pB  Cq “ pA  Bq  C

holds for all sets A, B, and C.

Proof. Let U “ A Y B Y C be the universe. We have

A pB  Cq “ pA X pB  CqA q Y pAA X pB  Cqq.

Expanding the symmetric difference B  C in two different ways, we get

pB  CqA “ ppB Y Cq ´ pB X CqqA


“ ppB Y Cq X pB X CqA qA “ pB A X C A q Y pB X Cq

and B  C “ pB ´ Cq Y pC ´ Bq “ pB X C A q Y pB A X Cq. This yields

A pB  Cq “ pA X B A X C A q Y pA X B X Cq Y pAA X B X C A q Y pAA X B A X Cq.

Since the latter expression is symmetric in A and C, we have A pB  Cq “


C pB  Aq. By commutativity of the symmetric difference, we get

A pB  Cq “ C pB  Aq “ C pA  Bq “ 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.25. Show that A X pB ´ Cq “ pA X Bq ´ C.

3.26. Show that A X pB ´ Cq “ pA X Bq ´ pA X Cq.

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.

3.28. Show that for all sets A, B, and C, we have


(a) A ´ pB ´ Cq “ pA ´ Bq Y pA X Cq,
(b) pA ´ Bq ´ C “ A ´ pB Y Cq.

3.29. Let A be a set. Show that the “complement” of A given by all x R A


cannot exist. [This explains why we used some set U relative to which we form
the complement]

3.30. Show that the distributive law A X pB  Cq “ pA X Bq pA X Cq holds


for all sets A, B, and C.

3.5 Cartesian Products


The pair ta, bu contains in general two elements. Since ta, bu “ tb, au, this pair
is not ordered. Our goal is to introduce an ordered pair pa, bq that allows us
to distinguish the first coordinate a from the second coordinate b. One could
introduce such ordered pairs as primitives. However, Kuratowski has shown
that one can define ordered pairs in terms of unordered pairs, and this is a
good example that can test your understanding of the power set.

Construction. We define an ordered pair pa, bq by the set

pa, bq “ ttau, ta, buu.

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.

Proof. If a “ c and b “ d, then

pa, bq “ ttau, ta, buu “ ttcu, tc, duu “ pc, dq.

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

(i) If a ‰ b, then tau “ tcu, hence a “ c; furthermore, the equality of the


sets ta, bu “ tc, du “ ta, du implies b “ d.
(ii) If a “ b, then ttau, ta, auu “ ttauu, so tcu “ tau implies a “ c, and
tc, du “ tau implies d “ a “ b.
Therefore, pa, bq “ pc, dq implies a “ c and b “ d in both cases.
Let A and B be sets. We would like to construct a set A ˆ B containing all
pairs pa, bq for a P A and b P B. Since tau and ta, bu are elements of the power
set P pA Y Bq, the pair pa, bq “ ttau, ta, buu must be a subset of P pA Y Bq.
Therefore, pa, bq “ ttau, ta, buu is an element of P pP pA Y Bqq. Since each pair
pa, bq “ ttau, ta, buu can be understood as an element of P pP pA Y Bqq, we can
define the set A ˆ B as the subset
A ˆ B “ tpa, bq P P pP pA Y Bqq | a P A and b P Bu.
We call A ˆ B the Cartesian product of the sets A and B.

Usage. The Cartesian product A ˆ B of two sets A and B is easily under-


stood as the set of ordered pairs with the first coordinate ranging through the
elements of A and the second coordinate ranging through the elements of the
set B. The next example illustrates a simple case.
Example 3.27. Let A “ ta1 , a2 , a3 u and B “ tb1 , b2 u. Then
A ˆ B “ tpa1 , b1 q, pa1 , b2 q, pa2 , b1 q, pa2 , b2 q, pa3 , b1 q, pa3 , b2 qu
The first coordinate is given by the three elements of A, and the second coor-
dinate is given by the two elements of B. Therefore, we get a total of 6 “ 3 ¨ 2
ordered pairs in A ˆ B. An illustration of the set A ˆ B is depicted in Fig. 3.4.

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

One point of potential confusion is when one of the sets A or B is empty.


How many elements are then in A ˆ B? The answer is none, as the next
proposition shows.
3.6 Relations 69

Proposition 3.28. The Cartesian product A ˆ B “ H if and only if A “ H


or B “ H.

Proof. If A “ H or B “ H, then one cannot form any pair pa, bq with a P A


and b P B, so A ˆ B “ H.
If A ‰ H and B ‰ H, then there exists elements a P A and b P B such that
pa, bq P A ˆ B; in particular, A ˆ B ‰ H. It follows by contraposition that
A ˆ B “ H implies A “ H or B “ H.

EXERCISES
3.31. Let A “ ta, b, cu and B “ t1, 2u. Determine A ˆ B.

3.32. Show that the Cartesian product is in general not commutative, so

A ˆ B ‰ B ˆ A.

3.33. Show that pA Y Bq ˆ C “ pA ˆ Cq Y pB ˆ Cq holds for all sets A, B,


and C.

3.34. Show that pA X Bq ˆ C “ pA ˆ Cq X pB ˆ Cq holds for all sets A, B,


and C.

3.35. Show that pA ´ Bq ˆ C “ pA ˆ Cq ´ pB ˆ Cq holds for all sets A, B,


and C.

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

Example 3.29. The relation on the set of positive integers N1 “ t1, 2, 3, . . .u


given by
tpx, yq | there exists positive integer z such that x ` z “ yu
is the usual strict inequality and is denoted by ă. We write 3 ă 4 to express
that 3 is strictly less than 4 rather than writing that p3, 4q is an element of ă.
Example 3.30. Let S denote the set of strings over the alphabet
ta, . . . , zu. We define x ď y to mean that the string x comes before the string
y in lexicographic order or that the two strings are equal. So aardvark ď
aasvogel.
Example 3.31. Let A be a finite set and S “ P pAq its power set. We can
define a relation „ on S such that X „ Y if and only if X and Y are two
subsets of A that have the same number of elements.
Relations occur very frequently in applications. Therefore, it is good to
know the standard terminology for some of their most important properties.
A binary relation R on a set A is called reflexive if and only if x R x holds
for all x P A. For example, the relation „ in Example 3.31 is reflexive, since
X „ X holds for all subsets X of A. A reflexive relation on a set A contains
the equality relation on A as a subset.
We call a binary relation R on a set A irreflexive if and only if xRx does
not hold for any x P A. The strict inequality ă on the set of positive integers
is an example of an irreflexive relation. A relation that fails to be reflexive is
not necessarily irreflexive. Irreflexivity refers to the fact that no element x P A
is related to itself.
 It is a common mistake to think that these notions are negations of each
other. However, a reflexive relation on a set A contains all diagonal
pairs px, xq with x P A, whereas an irreflexive relation contains none of the
diagonal pairs. You should pause for a moment and construct a relation that
is neither reflexive nor irreflexive.
A binary relation R on a set A is called asymmetric if and only if for
all x, y in A, px, yq P R implies py, xq R R. The strict inequality ă on the
set of positive integers is an example of an asymmetric relation. Any relation
satisfying x R x for some x in A cannot be asymmetric.
Example 3.32. Let P denote the set of players in a tennis tournament. We
define a relation ă on P such that x ă y if and only if x beats y in the
tournament. Then ă is an asymmetric relation, since there are no ties. Thus,
for all players x and y, either x ă y or y ă x.
A binary relation R on a set A is called antisymmetric if and only if for
all x, y in A, x R y and y R x implies x “ y. Every asymmetric relation is
antisymmetric, but not conversely. Indeed, the divisibility relation on the set
of positive integers is an example of an antisymmetric relation that is not an
asymmetric relation.
3.6 Relations 71

Proposition 3.33. An irreflexive and antisymmetric relation is asymmetric.


Proof. Let ă be an irreflexive and antisymmetric relation on a set A. Seeking
a contradiction, we assume that there exist elements x and y in A such that
x ă y and y ă x. By antisymmetry, this implies x “ y, contradicting the
irreflexivity of ă. Therefore, ă is asymmetric, as claimed.
A binary relation R on a set A is called symmetric if and only if x R y
implies y R x. The relation „ from Example 3.31 is a symmetric relation.

 A relation that is not symmetric does not have to be asymmetric or


antisymmetric. The relation R “ tp1, 2q, p2, 1q, p1, 3q, p1, 1qu on A “
t1, 2, 3u is not symmetric since it does not contain p3, 1q. However, the relation
R is not asymmetric, since it contains p1, 1q. It is not antisymmetric either,
since it contains p2, 1q and p1, 2q, but 1 ‰ 2.

A binary relation R on a set A is called transitive if and only if for all x,


y, z in A, x R y and y R z implies x R z. The strict inequality ă on the set of
positive integers is an example of a transitive relation.
An irreflexive and symmetric relation on a set V describes the edges of an
undirected graph on the set of vertices V . So undirected graphs are essentially
a study of irreflexive and symmetric relations. A relation that is reflexive,
symmetric, and transitive is called an equivalence relation, and such relations
are fundamental in the construction of number systems and other mathematical
objects, see Chap. 5. A relation that is reflexive, antisymmetric, and transitive
is called a partial order. Partial orders have many applications in computer
science and mathematics, see Chap. 6.

Important Terminology
A binary relation R on a set A is called

reflexive if and only if xRx for all x in A,

irreflexive if and only if xRx does not hold for any x in A,

asymmetric if and only if px, yq P R implies py, xq R R,


antisymmetric if and only if xRy and yRx implies x “ y,

symmetric if and only if xRy implies yRx,

transitive if and only if xRy and yRz implies xRz.

We will now introduce some other general operations on relations. Given


a relation R that is a subset of a Cartesian product A ˆ B, then the inverse
relation is defined as
R´1 “ tw P B ˆ A | w “ py, xq and px, yq P Ru.
72 3 Sets

In other words, px, yq P R if and only if py, xq P R´1 .


Let A, B, and C be sets. If a relation R is a subset of A ˆ B and a relation
S is a subset of B ˆ C, then the composition S ˝ R, read S after R, is the
relation
S ˝R “ tpa, cq P AˆC | there exists b P B such that pa, bq P R and pb, cq P Su.
This notation follows the convention used for the composition of functions.
If R is a relation on a set A, then we define Rn to be the relation that is
recursively defined by
#
n R if n “ 1,
R “ n´1
R ˝ R if n ą 1,
In other words, R2 “ R ˝ R is the composition of R with itself, R3 “ R ˝ R ˝ R,
and so on.
We will study relations in more depth in subsequent chapters. The next
section discusses one particularly important special case, namely functions.

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

has the underlying relation


tpx, 1q | x P Qu Y tpx, 0q | RzQu.
One can also express χQ using elementary functions and limits, but that is less
straightforward.
74 3 Sets

Notation. Sometimes the function f : A Ñ B is denoted as

pF paq | a P Aq.

In some contexts, the venerable notation f pxq is replaced by an index notation


fx . Then the notations

pfa | a P Aq or pfa qaPA

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

is a function f æ X : A X X Ñ B, called the restriction of f to X. Usually,


X is chosen as a subsetˇ of the domain A. Another common notation for the
restriction f æ X is f ˇX .
Let f : A Ñ B be a function and X a subset of B. The preimage f ´1 pXq
of f is given by
f ´1 pXq “ tx P A | f pxq P Xu.
The notation f ´1 is also used to denote the inverse function that will be intro-
duced shortly, but the meaning should always be clear from the context.
Let f : A Ñ B and g : B Ñ C. The composition g ˝ f of the functions
is given by pg ˝ f qpaq “ gpf paqq for all a P A. Note that this coincides in our
case with the composition of the relations, but in the literature the definitions
sometimes clash. The composition of functions is an associative operation,
meaning that h ˝ pg ˝ f q “ ph ˝ gq ˝ f .
A function iA : A Ñ A is called the identity map on A if and only if
iA paq “ a holds for all a P A. Given a function f : A Ñ B, we have

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

Example 3.37. The function g : Rě0 Ñ R given by gpxq “ x2 is an injec-


tive function. Indeed, g is the restriction of the function f from the previ-
ous example to the set of nonnegative real numbers. For any two nonnega-
tive ?
real numbers
a x and y, if f pxq “ f pyq, then x2 “ y 2 , so we must have
2 2
x “ x “ y “ y. This shows that g is an injective function.

As the next proposition shows, injective functions have the crucial property
that they possess an inverse function.

Proposition 3.38. Let f be a function from A to B. Then the inverse relation


f ´1 is a function from ranpf q to A if and only if f is an injective function.

Proof. If the inverse relation f ´1 is a function, then f ´1 pf paqq “ a holds for


all a P A. For all x, y P A, the equality f pxq “ f pyq implies x “ f ´1 pf pxqq “
f ´1 pf pyqq “ y. It follows that the function f is injective.
Conversely, suppose that f is injective. If pb, a1 q P f ´1 and pb, a2 q P f ´1 ,
then f pa1 q “ b “ f pa2 q, so a1 “ a2 by the injectivity of f . Therefore, f ´1 is a
function.

Given an injective function f , we call f ´1 the inverse function of f .

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.

A function is called bijective if and only if it is surjective and injective.

Proposition 3.41. Let A and B be nonempty sets. If there exists an injective


function f : A Ñ B, then there exists a surjective function g : B Ñ A such that
g ˝ f “ iA .
76 3 Sets

Proof. Let f : A Ñ B be an injective function. Then


f ´1 “ tpy, xq P ranpf q ˆ A | px, yq P f u
is a function f ´1 : ranpf q Ñ A by Proposition 3.38. Since A is not empty, we
can choose a fixed element a1 P A. Define g : B Ñ A by
#
a1 if b P B ´ ranpf q,
gpbq “ ´1
f pbq if b P ranpf q.

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.

S8. Let Fpx, yq be a functional property. For each set A, there


exists a set B such that y P B if and only if Fpx, yq holds
for some x P A.
3.7 Functions 77

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,

where f pxq denotes the unique set y associated with x.


The axiom of replacement S8 is a convenient tool in specifying sets.

Example 3.44. Let S “ t1, 2, . . . , 100u. Then

tx2 | x P Su

is the set of the first 100 perfect squares in the set of positive integers.

Given a set system S of nonempty sets, we call a function f on S a choice


function if and only if f pXq P X holds for all sets X P S. In other words, for
each set X in the set system, the choice function selects an element f pXq from
X. The next axiom postulates the existence of choice functions.

S9. There exists a choice function for each collection of


nonempty sets.

The proof of the next proposition uses the Axiom of Replacement S8 and
the Axiom of Choice S9.

Proposition 3.45. Let A and B be nonempty sets, and f : A Ñ B a surjective


function. Then there exists an injective function g : B Ñ A such that f ˝g “ iB .

Proof. Consider the set system

S “ tf ´1 ptyuq | y P Bu

of preimages of singleton sets tyu with y P B. Since f is surjective, each element


of S is a nonempty set. Let s be a choice function on S. We define g : B Ñ A
by
gpyq “ spf ´1 ptyuqq,

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.

Numbers via Sets. John von Neumann gave a set-theoretic description of


the nonnegative integers. He defined 0 to be the empty set, 1 to be a set
with 1 element, 2 to be a set with two elements, and so forth. Specifically, his
definitions of 0, 1, 2, and 3 are given by
0 “ H,
1 “ tHu,
2 “ tH, tHuu,
3 “ tH, tHu, tH, tHuuu.

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

In general, we define 0 “ H, and n ` 1 “ n Y tnu for all positive integers.


In other words, von Neumann defined a nonnegative integer n as the set that
contains all previous numbers, so m ă n if and only if m P n.
A vexing issue is that we can construct any nonnegative integer, but the
axioms that we have given so far do not allow us to collect them all into a
single set. In fact, there does not seem to be a way to construct an infinite set.
Let us define the successor of a set X to be X Y tXu. We call a set S
inductive if and only if H P S and for all X P S, the successor X Y tXu is
contained in S. Thus, an inductive set contains all the von Neumann numbers,
but perhaps also other sets. The Axiom of Infinity asserts the existence of an
inductive set.

S10. There exists an inductive set.

Let S be an inductive set. We define the set of nonnegative integers N0 to be


the set
N0 “ tx P S | x P I for all inductive sets Iu.
We will now show that N0 is inductive; hence it is the smallest inductive set.

Proposition 3.46. The set N0 is inductive.

Proof. By definition, the empty set H is contained in N0 . If X P N0 , then


X YtXu is contained in every inductive set, so X YtXu P N0 . We can conclude
that N0 is an inductive set.

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.

Theorem 3.47 (The Induction Principle). Let P pxq be a property. Suppose


that
(1) P p0q holds,
(2) For all n P N0 , P pnq implies P pn ` 1q.
Then the property P pnq holds for all nonnegative integers n.

Proof. The set S “ tn P N0 | P pnqu is an inductive set by the assumptions (1)


and (2). Therefore, N0 Ď S, which proves the claim.

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

Figure 3.6: The figure illustrates the triangular numbers T1 “ 1, T2 “ 1 ` 2 “ 3,


T3 “ 1 ` 2 ` 3 “ 6 and T4 “ 1 ` 2 ` 3 ` 4 “ 10

Proposition 3.48. For all nonnegative integers n, we have

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

Tn`1 “ 1 ` 2 ` ¨ ¨ ¨ ` n ` pn ` 1q (by definition of Tn`1 q


“ Tn ` n ` 1 (by definition of Tn q
npn ` 1q
“ `n`1 (as P(n) is true).
2
The right-hand side can be simplified to

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.

The following variation on the induction principle is often more convenient


to use.

Theorem 3.49 (The Strong Induction Principle). Let P pxq be a property.


Suppose that we can establish for all nonnegative integers n the principle

If P pkq holds for all k ă n, then P pnq. (3.1)

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.

A least element of a set A of nonnegative integers is an element of A


satisfying a ď x for all x P A. We will use a proof by strong induction to prove
that every nonempty subset of N0 has a least element. This might seem like an
obvious fact. However, you might want to keep in mind that the set of integers
has subsets that do not have a least element.

Theorem 3.50 (The Well-Ordering Principle). Every nonempty subset of the


set of nonnegative integers has a least element.

Proof. Let S be a nonempty subset of N0 . We will prove by strong induction


that S has a least element a. For each n P N0 , we define P pnq to be the
statement: if n P S, then S has a least element.
The statement P p0q is certainly true. Indeed, if 0 P S, then the least
element of S is of course 0.
Let us assume that P pmq is true for all m ď n. If n ` 1 R S, then P pn ` 1q
is vacuously true. Therefore, let us suppose that S contains n ` 1. We can now
distinguish two cases:
Case 1. Suppose that there exists a nonnegative number m ď n such that
m P S. Since P pmq is true, the set S has a least element.
Case 2. Suppose that there does not exist a nonnegative number m ď n such
that m P S. Then n ` 1 is the least element of S.
Therefore, we can conclude by strong induction that P pnq holds for all n P N0 .
Since S is not empty, it follows that S contains a least element.

EXERCISES
3.48. Explicitly give von Neumann’s definition of 4 and 5 in terms of sets.

A set S is called transitive if and only if every element of an element of


S is itself an element of S. In other words, S is called transitive if and only if
A P B and B P S implies A P S. The notion of a transitive set should not be
confused with a transitive relation.

3.49. Which of the following sets are transitive? Explain.


(a) H,
(b) tH, tHuu,
(c) tH, ttHuuu,
(d) tH, tHu, tH, tHuuu.
82 3 Sets

3.50. Show that Ť


(a) S is a transitive set if and only if S Ď S.
(b) S is a transitive set if and only if B P S implies B Ď S.
(c) S is a transitive set if and only if S Ď P pSq.
3.51. Show that if X is a transitive set, then
ď
pX Y tXuq “ X.

3.52. Show that every element of the set N0 of nonnegative numbers is a


transitive set.
3.53. For all n, m P N0 , show that if the successor n Y tnu of n is equal to the
successor m Y tmu of m, then n “ m.
3.54. Let Qpxq be a property. Suppose that k is nonnegative integer and
(1) Qpkq holds,
(2) For all nonnegative integers n ě k, Qpnq implies Qpn ` 1q.
Show that the property Qpnq holds for all nonnegative integers n ě k. [This
simple variation of the induction principle gives some flexibility.]
3.55. Give three distinct subsets of the set of integers that do not have a least
element.
3.56. Does the set tx P R | 0 ă xu have a least element? Either determine the
least element or prove that this set does not have a least element.

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

Proposition 3.51. Let A, B, and C be sets. Then


(a) |A| “ |A|,
(b) if |A| ď |B| and |B| ď |A|, then |A| “ |B|,
(c) if |A| ď |B| and |B| ď |C|, then |A| ď |C|.
Proof. (a) The identity map iA on A is a bijective map, hence |A| “ |A|.
(b) We can reformulate the second claim as follows. If f : A Ñ B and
g : B Ñ A are injective maps, then there exists a bijective map h : A Ñ B.
This is a major theorem known as the Schröder-Bernstein theorem. We could
prove it now, but an elementary proof is tedious, see [36]. We will prove it
in Theorem 6.46, since the methods of Chap. 6 allow us to give a shorter and
more elegant proof.
(c) By assumption, there exist injective maps f : A Ñ B and g : B Ñ C.
Consider the function composition g ˝ f . If pg ˝ f qpa1 q “ pg ˝ f qpa2 q, then
gpf pa1 qq “ gpf pa2 qq. Since g is injective, it follows that f pa1 q “ f pa2 q. As f is
injective, it follows that a1 “ a2 , which proves that g ˝f is injective. Therefore,
we can conclude that |A| ď |B| and |B| ď |C| implies |A| ď |C|.
A set A is called finite if and only if there exists a nonnegative integer n
such that |n| “ |A|. If |n| “ |A|, then we say that A has n elements and write
the cardinality in the more pleasing form n “ |A|.
The next proposition implies that there cannot be two different cardinalities
of a finite set.
Proposition 3.52 (Pigeonhole Principle). There is no injective mapping from
n “ t0, 1, . . . , n ´ 1u onto a proper subset of n.
A more whimsical formulation of this proposition is that it is impossible to
place n pigeons into fewer than n pigeonholes without occupying at least one
pigeonhole twice. For instance, it is impossible to place five pigeons

into four pigeonholes

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

(a) If n P S, then there exists some nonnegative integer m ď n such that


n “ f pmq. We define a new function
#
f piq for all i P t0, . . . , n ´ 1u such that i ‰ m,
gpiq “
f pnq if i “ m and m ‰ n.

Then g : t0, . . . , n ´ 1u Ñ S ´ tnu is an injective map, contradicting P pnq.


(b) If n R S, then the restriction f æ n maps n “ t0, . . . , n ´ 1u onto the proper
subset S ´ tf pnqu, contradicting P pnq.
Therefore, P pn ` 1q is true. We can conclude by induction that the claim holds
for all nonnegative integers n.

There are many applications of the pigeonhole principle, especially in com-


binatorics. We will discuss numerous applications of this important proof prin-
ciple in Chaps. 11 and 14.
Remark 3.53. Dedekind realized that for any infinite set A, one can find an
injective map onto a proper subset of A. For example, the map s : N0 Ñ
N0 zt0u given by spnq “ n ` 1 is injective and maps N0 to the proper subset
of positive integers. It follows from the pigeonhole principle and Dedekind’s
observation that a set S is infinite if and only if one can find an injective map
from S onto a proper subset.
A set A satisfying |A| ď |N0 | is called a countable set. In other words,
it suffices to find an injective function from A into N0 to prove that A is
countable. Alternatively, we can prove that A is countable if we can find a
surjection from N0 onto A, see Proposition 3.45. A set A that is not countable
is called uncountable.

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

Proposition 3.54. Suppose that A and B are countable sets. Then A ˆ B is


a countable set.

Proof. By assumption, there exist injective maps f : A Ñ N0 and g : B Ñ N0 .


Therefore, the function h : A ˆ B Ñ N0 ˆ N0 given by hpx, yq “ pf pxq, gpyqq
is an injective function. Therefore, it suffices to show that the set N0 ˆ N0 is
countable.
Let us follow Cantor and define a function k : N0 ˆ N0 Ñ N0 by
1
kpx, yq “ px ` y ` 1qpx ` yq ` y. (3.2)
2
The first few values of kpx, yq are illustrated in Fig. 3.7.
Note that kpx, yq “ Tn ` y, ř where n “ x ` y designates the diagonal to
n
which px, yq belongs and Tn “ k“1 k is the n-th triangular number, which
counts the number of elements on all previous diagonals. The function kpx, yq
is bounded by the triangular numbers,

Tx`y ď kpx, yq “ Tx`y ` y ă Tx`y ` x ` y ` 1 “ Tx`y`1 .

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.

We encourage you to explore further properties of Cantor’s function k, see


Exercise 3.62.

Proposition 3.55. Let S “ tAi | i P Iu beŤa family of countable sets Ai such


that I is a nonempty countable set. Then S is a countable set.

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.

Proof. Given any function f : A Ñ P pAq, we can construct the set

S “ tx P A | x R f pxqu.

Seeking a contradiction, let us assume that there exists an element a P A such


that f paq “ S. Then we have a P f paq if and only if a R f paq, which is a
contradiction. Thus, f is not surjective.

Corollary 3.57. Let A be a set. Then |A| ă |P pAq|.

Proof. The function f : A Ñ P pAq given by f pxq “ txu is injective, so |A| ď


|P pAq|. By the previous proposition, there cannot exist any surjective map
from A onto P pAq. Therefore, |A| ă |P pAq|.

A remarkable consequence of the previous corollary is that one can construct


sets of larger and larger cardinality.
Let us denote by 2N0 the set of all functions from the nonnegative integers
to the set t0, 1u with two elements.
Proposition 3.58. The power set P pN0 q and the set 2N0 are equipotent,

|2N0 | “ |P pN0 q|.

Proof. Define a function f : P pN0 q Ñ 2N0 by

f pAq “ χA

where χA is the characteristic function of A defined by


#
1 nPA
χA pnq “
0 nRA

Then f is a bijection. Indeed, if two characteristic functions χA and χB are the


same, then A “ B; thus, f is injective. The function f is surjective, since every
function in 2N0 is a characteristic function of its set of arguments yielding the
value 1.

Consider functions that takes a nonnegative integer as an argument and


have a single bit as a value. It might seem that one can compute any such
function with a suitable computer program given enough time. However, noth-
ing could be further from the truth. We will now sketch the proof that for
most functions in 2N0 one cannot write a program that will compute it.
Choose a programming language L of your preference that is expressive
enough to compute functions. For instance, the while language and the λ-
calculus are primitive choices. We call a function f in 2N0 computable in L
if and only if there exists a program that for each input n P N0 will compute
f pnq.
3.9 Cardinality 87

Theorem 3.59. There exist functions in 2N0 that cannot be computed in L.

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.58. Let (a) A0 “ tx P R | 0 ă x ă 1u, (b) A1 “ tx P R | 0 ď x ă 1u,


(c) A2 “ tx P R | 0 ă x ď 1u, (d) A3 “ tx P R | 0 ď x ď 1u. Show that all
four sets have the same cardinality using Proposition 3.51 (b).

3.59. Let A “ tx P R | 0 ă x ă 1u and B “ R. Show that |A| “ |B| by giving


an explicit bijection from A onto B.

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.62. Show that Cantor’s function k : N0 ˆ N0 Ñ N0 defined in Eq. (3.2) is


surjective. This means that k is a bijective function.

3.63. Show that |P pN0 q| “ |P pN0 ˆ N0 q|.

3.64. Show that the following sets are countable:


(a) The set of nonnegative even integers.
(b) The set of prime numbers.
(c) The set of (positive and negative) integers.

3.65. Show that a subset of a countable set is countable.


88 3 Sets

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.

— Michael Berg, in an MAA Book Review, 2017

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.

4.1 Perfect Squares


The perfect squares are given by

12 “ 1, 22 “ 4, 32 “ 9, 42 “ 16, . . .

Figure 4.1 depicts the perfect squares graphically.

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 Author(s), under exclusive license to Springer Nature 89


Switzerland AG 2025
A. Klappenecker, H. Lee, Discrete Structures, Undergraduate Texts in
Mathematics, https://doi.org/10.1007/978-3-031-73434-2 4
90 4 Proofs by Induction

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.

Principle of Induction. To prove that a property P pnq holds


for all positive integers n, it suffices to prove the base case and the
inductive step.

Base case. The property P p1q holds.

Inductive step. For all positive integers n, P pnq implies P pn ` 1q.

The property P pnq is in our case the equality


n
ÿ
n2 “ p2k ´ 1q.
k“1

So let us prove that P pnq holds for all integers n ě 1.

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

Proof. Base Case The claim P pnq holds for n “ 1, since


1
ÿ
12 “ 1 “ p2k ´ 1q.
k“1

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

which proves that the implication (4.1) is true.


Therefore, we can conclude by induction that P pnq holds for all n ě 1,
which proves the claim.

Induction Hypothesis In the induction step, you have to show


that the implications P pnq Ñ P pn ` 1q hold for all n ě 1. Here
P pnq is called the induction hypothesis. Since the implication
is trivially true if the induction hypothesis is false, the usual
proof pattern is:
Assume that the induction hypothesis P pnq is true.
Then deduce P pn ` 1q by logical deduction.
Note that this is the proof principle for @npP pnq Ñ P pn ` 1qq.

 One of the most common confusions about the induction principle is


that inductive step seems to be similar to the claim. Far from it! The
claim is to prove that P pnq holds for all n ě 1, which we can also express as

@nP pnq.
92 4 Proofs by Induction

On the other hand, the inductive step seeks to show

@npP pnq Ñ P pn ` 1qq.

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

for all positive integers n.

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.

4.8. Suppose that A1 , A2 , . . . , An are sets satisfying A1 Ě A2 Ě ¨ ¨ ¨ Ě An .


(a) Show that A1 ´ A2 ´ ¨ ¨ ¨ ´ An “ pA1 ´ A2 q Y pA3 ´ A4 q Y ¨ ¨ ¨ Y pAn´1 ´ An q
if n is even.
4.2 Bernoulli’s Inequality 93

(b) Show that A1 ´ A2 ´ ¨ ¨ ¨ ´ An “ pA1 ´ A2 q Y pA3 ´ A4 q Y ¨ ¨ ¨ Y pAn´2 ´


An´1 q Y An if n is odd.
Here we assume that the set difference is right associative, so A ´ B ´ C is
interpreted as pA ´ pB ´ Cqq. Hint: Use Exercise 3.28 and prove the claims by
induction.

4.9. (Requires calculus) Show that


ż8
xn e´x dx “ n! (4.6)
0

holds for all integers n ě 0.

4.2 Bernoulli’s Inequality


Inequalities are frequently proved by induction. We illustrate this for an in-
equality by Jacob Bernoulli. This inequality is frequently useful, especially
when dealing with probabilities.
What we want to establish is that the inequality

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

P p0q, P p1q, P p2q, . . .

hold, meaning that we seek to establish the validity of the inequalities

p1 ` xq0 ě 1 ` 0x, p1 ` xq1 ě 1 ` 1x, p1 ` xq2 ě 1 ` 2x, . . .

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.

Proposition 4.2 (Bernoulli’s Inequality). Let n denote a nonnegative integer


and x a real number such that x ě ´1. Then

p1 ` xqn ě 1 ` nx. (4.8)


94 4 Proofs by Induction

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

p1 ` xqn`1 “ p1 ` xqp1 ` xqn


ě p1 ` xqp1 ` nxq (by induction hypthesis)
ě 1 ` pn ` 1qx (since nx2 is nonnegative)

which proves P pn ` 1q. Therefore, the claim follows by induction on n.

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.

The Modus Ponens Omnibus It is educational (though not


entirely rigorous) to view induction as a repeated application of
modus ponens. We establish in the base case the property P p1q,
and in the inductive step the implications

P p1q Ñ P p2q, P p2q Ñ P p3q, P p3q Ñ P p4q, . . .

Now let’s repeatedly use modus ponens:


P p1q and P p1q Ñ P p2q allow us to deduce P p2q,
P p2q and P p2q Ñ P p3q allow us to deduce P p3q, . . .
You will gain a better understanding by unraveling a proof by
induction in this way. Of course, we cannot replace induction by
repeated modus ponens, since proofs must be of finite length!

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)

holds. The implication P p0q Ñ P p1q is established by multiplying both sides


of this inequality with p1 ` xq, which led to

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

p1 ` xq2 ě 1 ` 2x. (4.11)


4.3 Fibonacci Numbers 95

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.

 So what could go wrong in a proof by induction? The base case is


often so simple that people do not pay much attention to it and may
even omit it. This is dangerous, since the entire proof falls apart when the
base case is wrong. In the inductive step, we established P pnq Ñ P pn ` 1q for
all n. For Bernoulli’s inequality, it was crucial that we restricted ourselves to
x ě ´1. Indeed, if x ă ´1, then 1 ` x is negative and multiplication with the
term would reverse the inequality. So be careful about each step in a proof!

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 .

4.13. Let b ą 1 be a real number. Deduce from Bernoulli’s inequality that


there exists a positive constant L such that

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.]

4.3 Fibonacci Numbers


The Fibonacci numbers are defined as the sequence given by

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

for all integers n ě 3. We define f0 “ 0 to ease the formulation of some results.


There are many interesting identities that can be derived for these numbers.
For example, let us rewrite the elements in the form
f3 ´ f2 “ f1
f4 ´ f3 “ f2
..
.
fn`2 ´ fn`1 “ fn
If we sum the elements of the right-hand side, then we obtain the sum of the
first n Fibonacci numbers. If we sum the elements of the left-hand side, then
we obtain a sum in which most elements cancel, namely
pfn`2 ´ fn`1 q ` pfn`1 ´ fn q ` ¨ ¨ ¨ ` pf3 ´ f2 q “ fn`2 ´ f2 “ fn`2 ´ 1.
A sum in which subsequent terms cancel such that just an initial and a final
term remain is called a telescoping sum.
Proposition 4.3. The Fibonacci numbers satisfy
f1 ` f2 ` ¨ ¨ ¨ ` fn “ fn`2 ´ 1. (4.12)
for all n ě 1.
Proof. We use a proof by induction to verify the claim. Let us denote by F pnq
the Eq. (4.12).
Base Case The claim F pnq holds for n “ 1, since
f1 “ 1 “ 2 ´ 1 “ f1`2 ´ 1.
Inductive Step We claim that the implication F pnq Ñ F pn ` 1q holds for all
n ě 1. Indeed, suppose that F pnq is true. Then
f1 ` f2 ` ¨ ¨ ¨ ` fn `fn`1
loooooooooomoooooooooon “ fn`2 ´ 1 ` fn`1 by F pnq
“ fn`3 ´ 1 by definition of fn`3 ,
so F pn ` 1q holds. Therefore, the implication F pnq Ñ F pn ` 1q holds for all
n ě 1.
It follows by induction that F pnq holds for all n ě 1.

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.

4.4 Geometric Series


A sequence of numbers that have a fixed common ratio x is called a geometric
series. For example, the sequence
2, 6, 18, 54, 162, 486, 1458, . . .
has the property that a term divided by its previous term has the ratio x “ 3.
The next proposition shows how to sum a finite geometric series.
Proposition 4.4. Let x be a real number such that x ‰ 1, and c a real number.
If n is a nonnegative integer, then
n
1 ´ xn`1
ÿ ˆ ˙
k
cx “ c . (4.16)
k“0
1´x

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

by induction hypothesis. Bringing to a common denominator and simplifying


yields
n`1
1 ´ xn`1 ` xn`1 ´ xn`2 1 ´ xn`2
ÿ ˆ ˙ ˆ ˙
k
cx “ c “c ,
k“0
1´x 1´x
98 4 Proofs by Induction

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.

4.20. Evaluate the geometric series


8
ÿ 9
k“1
10k

and explain its significance for the decimal number system.


4.21. Let us define some geometric figures as follows. The figure K0 is defined
as an equilateral triangle with side length 1 (shown on the left). For all n ě 1,
the figure Kn is obtained from the figure Kn´1 by subdividing each line seg-
ment into three equal parts and replacing the middle segment by two segments
of the same length pointing outward. So K1 is a 12 sided polygon. The figures
K0 , K1 , K2 , and K3 are shown here:
4.5 Binomial Theorem 99

(a) Determine the number Nn of sides of the polygon Kn .


(b) Determine the length Ln of a line segment in the polygon Kn , assuming
that the line segments in K0 have unit length, L0 “ 1.
(c) Determine the perimeter Pn of Kn .
(d) Determine the area An of Kn .
(e) Determine the area and the perimeter of the Koch snowflake limnÑ8 Kn .

4.5 Binomial Theorem


Given two variables x and y, the binomial theorem explicitly describes the
expansion of the term px ` yqn for any nonnegative integer n. For example,
the distributive law yields

px ` yq2 “ px ` yqpx ` yq “ x2 ` 2xy ` y 2 .

Multiplying with another px ` yq term yields

px ` yq3 “ x3 ` 3x2 y ` 3xy 2 ` y 3 .

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!

It follows from this definition that


ˆ ˙ ˆ ˙
n n
“ 1, “ 1.
0 n

A direct computation yields Pascal’s identity


ˆ ˙ ˆ ˙ ˆ ˙
n n´1 n´1
“ `
k k´1 k

for 1 ď k ď n.

Proposition 4.6. Let x and y be variables. Then


n ˆ ˙
ÿ n k n´k
px ` yqn “ x y (4.17)
k“0
k

holds for all nonnegative integers n.


100 4 Proofs by Induction

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.

Therefore, the equation P p0q is true.


Induction Step We are going to show that the implication P ř pnq Ñ` P˘pn ` 1q
n
holds for all n ě 0. Suppose that P pnq is true, so px ` yqn “ k“0 nk xk y n´k
holds. By multiplying with x and with y, we respectively get

ypx ` yqn “ n0 x0 y n`1 ` n1 x1 y n ` n2 x2 y n´1 ` ¨ ¨ ¨ ` nn xn y,


` ˘ ` ˘ ` ˘ ` ˘
`n˘ 1 n `n˘ 2 n´1 ` n ˘ n
xpx ` yqn “ x y ` nn xn`1 .
` ˘
0 x y ` 1 x y ` ¨ ¨ ¨ ` n´1

Adding these two sums yields

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 .

4.25. Use the binomial theorem to expand


ˆ ˙3
1
1´ .
x
4.26. Show that
n ˆ ˙
ÿ n
(a) “ 2n .
k“0
k
4.6 Strong Induction 101
n ˆ ˙
ÿ n
(b) p´1qk “ 0.
k“0
k
n ˆ ˙
ÿ n k
(c) 2 “ 3n .
k“0
k

4.27. Evaluate the sum


499 ˆ ˙
ÿ
k 999
p´1q
k“0
2k
and simplify the result to a power of an integer. [Hint: The path to the real
solution is literally complex. Just don’t get fooled into believing
? it is difficult.
Have a look at the powers of p1 ` iq and p1 ´ iq for i “ ´1.]
4.28. Let p be a prime number. Use induction to show that for all positive
integers n, the prime p divides np ´ n. This enormously useful result is known
as Fermat’s Little Theorem. [In the notation of Chap. 5, we can state this
divisibility result as the congruence np ” n pmod pq.]

4.6 Strong Induction


In the principle of strong induction, we still have to prove the base case, but
we grant ourselves a much more generous induction hypothesis. We assume
the induction hypothesis P p1q ^ P p2q ^ ¨ ¨ ¨ ^ P pnq and show that it implies
P pn ` 1q.

Principle of Strong Induction. To prove that a property P pnq


holds for all positive integers n, it suffices to prove the base case
and the inductive step.

Base case. The property P p1q holds.


Inductive step. If P pkq holds for all k in the range 1 ď k ď n,
then P pn ` 1q holds.

The Fibonacci sequence

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

fak ` fak´1 ` . . . ` fa1

where the indices ak ą ak´1 ą ¨ ¨ ¨ ą a1 are pairwise distinct positive integers.


For example, the numbers 4, 6, 7, and 9 are missing from the Fibonacci se-
quence, but we can express them as sums of Fibonacci numbers with distinct
102 4 Proofs by Induction

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

for some nonnegative integer m and coefficients ck being 0 or 1.


4.6 Strong Induction 103

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

We necessarily have c0 “ 0, since n is an even integer. It follows that


m
ÿ m
ÿ
n`1“ ck 2k ` 1 “ dk 2k
k“0 k“0

with d0 “ 1 and dk “ ck for k in the range 1 ď k ď n. Therefore, P pn ` 1q


holds.
We can conclude by the principle of strong induction that P pnq holds for
all positive integers n.

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.

(a) If a ă b, then a “ qb ` r with q “ 0 and r “ a ă b. So P paq holds.

(b) If a ě b, then a1 “ a ´ b satisfies P pa1 q. Thus, there exist nonnegative


integers q 1 and r1 such that a1 “ q 1 b ` r1 with 0 ď r1 ă b. Then a “ a1 ` b “
pq 1 ` 1qb ` r1 , so a divided by b has quotient q “ q 1 ` 1 and remainder
r “ r1 . Therefore, P paq holds.

We can conclude by strong induction that P paq holds for all a ě 0.

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.

Proposition 4.10. Every integer n ą 1 can be written as a product

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

is a product of primes, so P pnq holds.


The claim follows by the principle of strong induction.

Sometimes it is convenient to establish several base cases to ease the for-


mulation of the inductive step. We illustrate this in the proof of the next
proposition.

Proposition 4.11. For all positive integers n, the number n4 ´ n2 is divisible


by 12.

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

Therefore, P p1q, P p2q, P p3q, P p4q, P p5q, and P p6q hold.


Inductive step. Let n ě 6, Suppose that P pkq holds for all k in the range
1 ď k ď n. We are going to show that P pn ` 1q must hold.
Let k “ n ` 1 ´ 6. By induction hypothesis, P pkq holds, so k 4 ´ k 2 is a
multiple of 12. Thus,

pn ` 1q4 ´ pn ` 1q2 “ pk ` 6q4 ´ pk ` 6q2


“ pk 4 ` 24k 3 ` 216k 2 ` 864k ` 1296q ´ pk 2 ` 12k ` 36q.

If we rearrange terms and factor out 12, we get

pn ` 1q4 ´ pn ` 1q2 “ pk 4 ´ k 2 q ` p24k 3 ` 216k 2 ` 852k ` 1260q


“ pk 4 ´ k 2 q ` 12p2k 3 ` 18k 2 ` 71k ` 105q.

Since k 4 ´ k 2 is a multiple of 12, it follows that pn ` 1q4 ´ pn ` 1q2 is a multiple


of 12 as well. Therefore, P pn ` 1q holds.
The claim follows by the principle of strong induction.

Base Cases The number of base cases depends on the formu-


lation of the inductive step. In the previous proposition, we
essentially used P pkq Ñ P pk ` 6q. Therefore, we needed six
base cases to anchor the induction for numbers that respectively
have remainders 1, 2, 3, 4, 5, and 0 when divided by 6. We rec-
ommend to first formulate the inductive step and then determine
all bases cases that are needed.

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

The Fibonacci numbers fn given by f1 “ 1, f2 “ 1, and fn “ fn´1 ` fn´2


satisfy the lower bound
fn ě φn´2
for all n ě 2.
4.33. Let z be a real number such that z ` 1{z is an integer. Prove by strong
induction that z n ` 1{z n is an integer for all positive integer exponents n.

∗4.7 Well-founded Induction


In this section, we give a generalization of the induction principle that is appli-
cable in a wider variety of situations. It encompasses the principles of induc-
tion and strong induction as special cases. However, well-founded induction is
a much more powerful tool.
Let S be an arbitrary set. Recall that a relation  on S is a subset of the
set S ˆ S of ordered pairs with elements from S. We will use the infix notation
s  s1 to denote that a pair ps, s1 q is an element of the relation .
Let T be a nonempty subset of S. We say that an element m in T is -
minimal in T if and only if there does not exist an element t in T such that
t  m. Note that there might exist an element s in S such that s  m, but s
cannot belong to T .
A relation  over S is called well-founded if and only if every nonempty
subset T of S has a -minimal element.
Example 4.12. The successor relation  “ tpn, n ` 1q | n P N1 u on the set
N1 of positive integers is a well-founded relation. Indeed, the smallest element
of a nonempty subset T of N1 is a -minimal element. For example, 2 is a -
minimal element of t2, 3u. A subset might have even more than one -minimal
element. For instance, 2 and 4 are -minimal elements of t2, 4, 5u.
Example 4.13. The strictly-less-than relation  “ tpm, nq | m ă nu on the
set N1 of positive integers is a well-founded relation. The smallest element of
a nonempty subset T of the set of positive integers is a -minimal element.
Example 4.14. The strict lexicographic order  on the set N0 ˆ N0 of pairs
of nonnegative integers is given by pa, bq  pa1 , b1 q if and only if a ă a1 , or a “ a1
and b ă b1 . The relation  is wellfounded. Indeed, given a nonempty subset T
of N0 ˆ N0 , we can choose the element pa0 , b0 q such that a0 “ minta P N0 |
pa, bq P T u and b0 “ mintb P N0 | pa0 , bq P T u. Then pa0 , b0 q is a -minimal
element of T .
We write y  x if and only if x  y. We say that a relation  has an infinite
descending chain if and only if there exist elements ak with k P N1 such that
a1  a 2  a 3  ¨ ¨ ¨
The next proposition gives an alternative characterization of well-founded
relations in terms of the absence of infinite descending chains.
4.7 Well-founded Induction 107

Proposition 4.15. A relation  on a set S is well-founded if and only if there


does not exist an infinite sequence pa1 , a2 , a3 , . . .q of elements in S such that
ak`1  ak holds for all integers k ě 1. In other words,  is well-founded if and
only if there does not exist an infinite descending chain

a1  a2  a3  ¨ ¨ ¨

of elements in S.

Proof. Let  be a well-founded relation on a set S. Seeking a contradiction,


suppose that there exists an infinite sequence pa1 , a2 , a3 , . . .q of elements in S
such that ak`1  ak holds for all integers k ě 1. Then T “ tak | k P N1 u
would be a nonempty subset of S without a -minimal element, contradicting
the well-foundedness of .
Conversely, suppose that there does not exist an infinite sequence

pa1 , a2 , a3 , . . .q

of elements in S such that ak`1  ak holds for all integers k ě 1. Seeking a


contradiction, suppose that T is a nonempty subset of S without a -minimal
element, meaning that for every element t in T , there exist an element s in T
such that s  t. Choose an arbitrary element a1 in T . Thus, there exists an
element a2 in T such that a2  a1 . Given any finite sequence pa1 , a2 , . . . , an q of
elements in T such that an  an´1  ¨ ¨ ¨  a2  a1 , we can find an element an`1
such that an`1  an . Inductively, we obtain an infinite sequence pa1 , a2 , a3 , . . .q
of elements in T Ď S such that ak`1  ak , contradicting our assumption that
such sequences cannot exist. Therefore, T must contain a -minimal element.

Well-founded relations are for example used in termination proofs of pro-


grams. We can also use it to show that some games finish in a finite number
of steps, as the next example shows.
Example 4.16. Ernie has a bag full of red and blue chips. He plays a game
all morning. Bert gets curious and asks him about the rules of the game. Ernie
explains, “You always draw two random chips from the bag. Your goal is to
get the bag empty.” Bert asks, “What if there is only one chip left?” “You
take that chip and the game is finished,” Ernie replies. He continues, “If one of
the two chips is blue, you discard a blue chip and put the other chip back into
the bag.” Bert mumbles, “Seems boring.” Ernie adds, “If both chips are red,
then you discard one red chip and put the other red chip and five blue chips
into the bag.” Bert sneers, “Ernie, that game might never finish!” “Not at all!
If we have r red balls and b blue balls, then we go from pr, bq to

pr, b ´ 1q  pr, bq

or
pr ´ 1, b ` 5q  pr, bq
108 4 Proofs by Induction

in the strict lexicographic order. Since this is a wellfounded relation, we will


always finish in a finite number of steps.” Ernie replies and chuckles.

The next theorem justifies the principle of wellfounded induction (also


known as the principle of Noetherian induction).

Theorem 4.17 (Well-Founded Induction). Let  be a well-founded relation


on a set S. In order to show that a property P pxq holds for all elements x in
S, it suffices to show that

(a) Induction Basis. P pmq holds for all -minimal elements m of S.

(b) Inductive Step. If x in S is not a -minimal element of S, and P paq


holds for all elements a P S such that a  x, then P pxq holds.

Proof. Seeking a contradiction, suppose that the subset

T “ tx P S | P pxq is falseu

is not empty. Since  is a well-founded relation on S, the set T must contain


a -minimal element m. By the induction basis, the element m cannot be a
-minimal element of S. The elements a in S such that a  m do not belong
to T , so the property P paq holds for all of them. Therefore, the inductive step
guarantees that P pmq must hold, contradicting the fact that m is an element
of T . Therefore, T must be empty and thus P pxq holds for all x P S.

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

if A and B are Boolean formulas, then

A  A,
A, B  pA _ Bq,
A, B  pA ^ Bq,
A, B  pA Ñ Bq,
A, B  pA Ø Bq,

and no other relations hold. For instance,

A  pA Ñ Bq  ppA Ñ Bq ^ Cq,

but A  ppA Ñ Bq ^ Cq does not hold.

Proposition 4.18. In a Boolean formula, the number of opening parentheses


is equal to the number of closing parentheses.

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.

We could have proven this proposition by induction or strong induction,


but it would have required us to introduce an auxiliary depth function that
assigns a nonnegative integer to each Boolean formula. The argument using
wellfounded induction is more direct, so it is often the preferred method of
proof.
Our next example shows that well-founded induction can be applied in
situations where it is difficult or impossible to apply mathematical induction
or strong induction.
110 4 Proofs by Induction

Ackermann Function. We will illustrate well-founded induction by looking


at some properties of the following recursively defined function:
$
&y ` 1
’ if x “ 0,
Apx, yq “ Apx ´ 1, 1q if x ‰ 0 and y “ 0,

Apx ´ 1, Apx, y ´ 1qq if x ‰ 0 and y ‰ 0.
%

This function is known as Ackermann’s function. The function Apx, yq is de-


fined for nonnegative integer arguments x and y.
The definition of Apx, yq might appear a bit enigmatic. It is instructive to
see this recursion in action. For instance, evaluating Ap1, 2q yields
Ap1, 2q “ Ap0, Ap1, 1qq as x “ 1 ‰ 0 and y “ 2 ‰ 0
“ Ap0, Ap0, Ap1, 0qqq as x “ 1 ‰ 0 and y “ 1 ‰ 0
“ Ap0, Ap0, Ap0, 1qqq as x “ 1 ‰ 0 and y “ 0
“ Ap0, Ap0, 2qq as Ap0, 1q “ 2
“ Ap0, 3q as Ap0, 2q “ 3
“ 4.
Unfortunately, most arguments lead to prohibitively long evaluation chains
and large results. For example, one can show that
2
Ap4, 0q “ 22 ´ 3 “ 13,
22
Ap4, 1q “ 22 ´ 3 “ 65533,
2
22
Ap4, 2q “ 22 ´ 3 “ 265,536 ´ 3.
The number of atoms in the observable universe is estimated to be around 1082 ,
so the value of Ap4, 2q vastly exceeds this number.
In general, the nested levels of recursion are so high that not even a com-
puter is of much use in experimentation with Apx, yq, especially when the
arguments get larger.
We can demystify the function by taking advantage of the well-founded
relation from Example 4.14. We notice that when A is used on the right-
hand side of the definition, then the arguments of Apx ´ 1, 1q, Apx, y ´ 1q, and
Apx ´ 1, Apx, y ´ 1qq satisfy
px ´ 1, 1q  px, yq,
px, y ´ 1q  px, yq
px ´ 1, Apx, y ´ 1qq  px, yq.
As  is a well-founded relation, this means that there are just a finite number
of recursive calls possible, for otherwise we would obtain an infinite descending
chain of arguments.
Let us now use well-founded induction to formally prove that Ackermann’s
function is well-defined and never goes into an infinite recursion for all nonneg-
ative integer arguments.
4.7 Well-founded Induction 111

Proposition 4.19. Ackermann’s function Apx, yq is a well-defined function


that yields for each input px, yq P N0 ˆ N0 a nonnegative integer value.

Proof. Let  denote the strict lexicographic order on N0 ˆ N0 , that is,


#
m1 ă n1 ,
pm1 , m2 q  pn1 , n2 q if and only if
m1 “ n1 and m2 ă n2 .

Then  is a well-founded relation on N0 ˆ N0 . The element p0, 0q is the only


-minimal element of N0 ˆ N0 .
Induction Basis The value Ap0, 0q is defined and equal to 1.
Inductive Step Let us assume that Apm1 , n1 q is defined for all pm1 , n1 q  pm, nq.
Then we have the following three cases for Apm, nq:
(a) If m “ 0, then Ap0, nq is defined and equal to n ` 1, since Ap0, yq “ y ` 1.
(b) If m ‰ 0 and n “ 0, then pm ´ 1, 1q  pm, 0q, so Apm ´ 1, 1q is defined by
induction hypothesis; hence Apm, 0q is defined and equal to Apm ´ 1, 1q.
(c) If m ‰ 0 and n ‰ 0, then pm, n ´ 1q  pm, nq, so Apm, n ´ 1q is defined;
furthermore, pm ´ 1, yq  pm, nq for all y in N0 , so by induction hypothesis
Apm ´ 1, Apm, n ´ 1qq is defined. However, this is precisely Apm, nq, so
Apm, nq is defined as well.
Therefore, the Ackermann function yields a nonnegative integer value for
all inputs from N0 ˆ N0 .

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.

(c) If m ‰ 0 and n ‰ 0, then pm, n ´ 1q  pm, nq, so Apm, n ´ 1q ą n ´ 1;


furthermore, pm ´ 1, yq  pm, nq for all y in N0 , so by induction hypothesis
Apm ´ 1, Apm, n ´ 1qq ą Apm, n ´ 1q. It follows that

Apm, nq “ Apm ´ 1, Apm, n ´ 1qq ą Apm ´ 1, n ´ 1q ą n ´ 1.


112 4 Proofs by Induction

Thus, Apm ´ 1, n ´ 1q is at least n, allowing us to deduce that

Apm, nq “ Apm ´ 1, Apm, n ´ 1qq ą n.

Therefore, the claim follows by well-founded induction on .

The impenetrable recursive definition of the Ackermann function obscures


the fact that its function values can be described without too much difficulty.
Most values of the Ackermann function are simply of the form

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.

In other words, the notation x Òm n yields

x Òm n “ x Òm´1 px Òm´1 px Òm´1 p¨ ¨ ¨ px Òm´1 xq ¨ ¨ ¨ qqq,

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,

where the last number is the unfathomably large iterated power


¨2
¨¨
22

consisting of 65,536 terms of 2s. For larger m, the repeated expansion of Òm


yields humongous numbers.
It will be convenient to extend the notation Òm to exponents less than 1.
We define the up-arrow Òm for m P t´2, ´1, 0u as
(a) x Ò0 n “ xn (multiplication),
(b) x Ò´1 n “ x ` n (addition),
(c) x Ò´2 n “ 1 ` n (increment).
Lemma 4.22. For all integers m and n such that m ě ´1 and n ě 2, the
up-arrow operator satisfies

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,

which proves the claim.

Proposition 4.23. The Ackermann function satisfies

Apx, yq “ 2 Òx´2 py ` 3q ´ 3.

for all nonnegative integer arguments x and y.

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 “ Apx ´ 1, 1q “ 2 Òx´3 4 ´ 3.

Since p2 Òm 2q “ 4 for all m ě ´1, we can rewrite 2 Òx´3 4 as

2 Òx´3 4 “ 2 Òx´3 p2 Òx´2 2q “ 2 Òx´2 3.

This allows us to conclude that

Apx, 0q “ 2 Òx´2 3 ´ 3,

so the claim holds in this case as well.


If x ą 0 and y ą 0, then

Apx, yq “ Apx ´ 1, Apx, y ´ 1qq by definition


x´3
“2Ò pApx, y ´ 1q ` 3q ´ 3 by Induction Hyp.
x´3
“2Ò p2 Òx´2 py ` 2qq ´ 3 by Induction Hyp.
x´2
“2Ò py ` 3q ´ 3 by Lemma 4.22,

so the claim holds in this case as well.


By well-founded induction, we can conclude that

Apx, yq “ 2 Òx´2 py ` 3q ´ 3

holds for all px, yq P N0 ˆ N0 .

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

have a  b. If the strings are of unequal length, we append blank spaces to


the shorter string, where we assume that  a and  b. Given the strings
s1 s2 ¨ ¨ ¨ sm and t1 t2 ¨ ¨ ¨ tn , we have

s 1 s 2 ¨ ¨ ¨ s m  t1 t2 ¨ ¨ ¨ tm

if and only if s1 “ t1 , . . . sk´1 “ tk´1 , and sk  tk for some integer k in the


range 1 ď k ď m. For example, ab  b and b  ba, but pbb  baq and pbb  bbq.
4.38. Let 1 be a well-founded relation on a set A, and 2 a well-founded
relation on a set B. Let the product relation  on A ˆ B be given by pa, bq 
pa1 , b1 q if and only if a 1 a1 and b 2 b1 . Show that  is a well-founded relation
on A ˆ B.
4.39. A relation ! on S is called transitive if and only if a ! b and b ! c implies
a ! c. Let  be a well-founded relation on a set S. Let ` denote the smallest
transitive relation on S containing . Show that ` is a wellfounded relation
on S as well. [Remark: The relation ` is irreflexive and transitive, and such
a relation is called a strict order. We will study strict orders in Sect. 6.2.]
4.40. Let  denote the successor relation  “ tpn, n ` 1q | n P N1 u on the set
of positive integers. Show that the smallest transitive relation ` containing 
is given by the usual strict inequality relation ă on the set of positive integers.
4.41. Let S and S 1 be sets and let f : S Ñ S 1 be a function from S to S 1 .
Suppose that 1 is a well-founded relation on S 1 . Define a relation  on S by

ab if and only if f paq 1 f pbq.

Show that  is a well-founded relation on S.


4.42. Show that it is possible to formulate the principle of well-founded in-
duction using a single condition (replacing the induction basis and inductive
step):
For all x in S, show that P pxq holds under the assumption that
P paq holds for all a in S such that a  x.
Then P pxq holds for all x P S.
Explain why this form of well-founded induction is equivalent to the well-
founded induction principle stated in this section.
4.43. Let S be a set and  a well-founded relation on S. For an element s in
S, let us call predpsq “ tt P S | t  su the set of predecessors of s.
Show that if T is a subset of S that contains an element s in S whenever
it contains its set predpsq of predecessors, then T cannot be a proper subset of
S, meaning that T “ S.
4.44. Show that well-founded induction over the set of positive integers using
the successor relation  from Example 4.12 is the familiar induction principle
over the positive integers.
116 4 Proofs by Induction

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.

Let S “ tpx, yq P N0 ˆ N0 | x ě y and px, yq ‰ p0, 0qu.


(a) Show that the relation  on S given by

px1 , y 1 q  px, yq if and only if y1 ă y

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.

Figure 4.2: Suppose that we are given an pn ´ 1q ˆ pn ´ 1q square such as the 3 ˆ 3


square shown above. We need to add pn ´ 1q ` 1 ` pn ´ 1q “ 2n ´ 1 empty squares
(3 ` 1 ` 3 “ 7 in the example shown) to obtain an n ˆ n square

So another definition of the square function s on the set of positive integers


is given by #
1 if n “ 1,
spnq “
spn ´ 1q ` 2n ´ 1 if n ą 1.

The function spnq is recursively defined in terms of a function g that depends


on n and previously defined terms (here spn ´ 1q), namely

gpn, spn ´ 1qq “ spn ´ 1q ` 2n ´ 1.

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

arguments. Applying the recurrence spnq “ spn ´ 1q ` 2n ´ 1 repeatedly yields

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.

 As a caveat, notice that we did not define the recursion as

wpnq “ wpn ` 1q ´ p2n ` 1q,

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.

So how can we establish that s is defined in a sensible way? If someone


is unaware of the motivation that gave rise to the recursive definition of spnq,
then the equality spnq “ n2 might come as a surprise. Yet, verifying that this
equality holds is not difficult. The functions spnq and n2 are both equal to 1 for
the base case n “ 1. For n ą 1, they both satisfy the same recursive relation,

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.

Theorem 4.24 (Recursion Theorem). Let S be a nonempty set, s an element


of S, and g : N0 ˆ S Ñ N0 a function. Then there exists a unique function
f : N0 Ñ S satisfying
(a) f p0q “ s (the base case),
(b) f pnq “ gpn, f pn ´ 1qq (the recursive step).

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

values or to the Ackermann function that depends on two parameters. We will


prove a General Recursion Theorem that relies on a well-founded relation to
ensure that the recursion terminates in a finite number of steps.
Let  be a well-founded relation on a set S. The initial segment seg x of
an element x from S is defined as

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.

Theorem 4.25 (The General Recursion Theorem). Let  be a well-founded


relation on the set S and g : S ˆ seq S Ñ S. Then there is a unique function f
on S such that
f pxq “ gpx, f æ seg xq,
for all x P 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

hpxq “ gpx, h æ seg xq

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

C “ tx P dom h1 X dom h2 | h1 pxq ‰ h2 pxqu

of contradictory values is not empty. Let m be a -minimal element of C. Then


s  m implies that s is in the domain of both h1 and h2 , as both functions
are admissible. Furthermore, h1 psq “ h2 psq, as s does not belong to C. Put
differently, the values of h1 and h2 coincide on seg x. Therefore, we can conclude
that
h1 pxq “ gpx, h1 æ seg xq “ gpx, h2 æ seg xq “ h2 pxq,
which contradicts that x is an element of C.
Viewing the elements of A as sets of argument/value pairs, we can form the
union ď
f“ A.
120 4 Proofs by Induction

The resulting relation is a function with domain


ď
dom f “ dom h.
hPA

If x is in the domain of f , then it must be in the domain of some admissible


function h in A. Therefore,

f pxq “ hpxq “ gpx, h æ seg xq “ gpx, f æ seg xq.

It remains to show that dom f “ S. Seeking a contradiction, suppose that


dom f is a proper subset of S. Let m be a -minimal element of S ´ dom f .
So seg m Ď dom f . Then D “ dom f Y tmu is closed, meaning that the initial
segment seg x Ď D for all x P D. We can define a function h : D Ñ S by
#
f pxq if x P dom f,
hpxq “
gpm, f æ seg mq if x “ m.

Evidently, h P A, so h Ď f , and m P dom f , which contradicts the choice of m.


Therefore, we can conclude that dom f “ S.
One can show the uniqueness of f using the same argument that we used
to show that h1 and h2 take on the same values.

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 .

4.52. The function f : N1 Ñ N1 is recursively defined by


#
1 if n “ 1,
f pnq “
1 ´ f pn ´ 1q if n ą 1.

Describe the function f without recursion.

4.53. The function f : N1 Ñ N1 is recursively defined by


#
1 if n “ 1,
f pnq “
nf pn ´ 1q if n ą 1.

Describe the function f without recursion.


4.8 Recursion 121

4.54. The function f : N0 Ñ N0 is recursively defined by


#
1 if n “ 0,
f pnq “
2f pn ´ 1q if n ą 0.

Describe the function f without recursion and prove equality using the Recur-
sion Theorem.

4.55. Show that the function f : N0 Ñ N0 given by


#
0 if n “ 0,
f pnq “
f pn ´ 1q ` 2n if n ą 0.

defines the oblong numbers f pnq “ n2 ` n for all nonnegative integers n. Prove
your result using the Recursion Theorem.

4.56. Give a self-contained proof of the Recursion Theorem (Theorem 4.24)


without appealing to Theorem 4.25.

4.57. The function f : N0 Ñ N0 is recursively defined by


$
&1
’ if n “ 0,
f pnq “ 2 if n “ 1,

f pn ´ 1q ` 2f pn ´ 2q if n ą 1.
%

Describe the function f without recursion and prove equality using the General
Recursion Theorem.

4.58. The function f : N0 Ñ Z is recursively defined by


#
´4 if n “ 0 or 1,
f pnq “
´3f pn ´ 1q ` 4f pn ´ 2q if n ą 1.

Describe the function f without recursion and prove equality using the General
Recursion Theorem.

4.59. Show that the function f : N0 Ñ N0 given by


$

’0 if n “ 0,

&1 if n “ 1,
f pnq “


’´1 if n “ 2,
´f pn ´ 1q ` f pn ´ 2q ` f pn ´ 3q if n ě 3.
%

Describe the function f without recursion and prove your result using the
General Recursion Theorem.
122 4 Proofs by Induction

∗4.9 Recursively Defined Sets


In this section, we will detail how to define a set using recursion. This approach
to defining sets is widely used in computer science. We will also show how to
prove properties of such recursively defined sets using a proof principle that is
known as structural 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.

Example 4.26. Let us consider as the universe U the set N0 of nonnegative


integers. We can define a subset S of N0 by asserting that
(a) the number 3 is an element of S (so B “ t3u is our base set),
(b) If n is an element of S, then f pnq “ n ` 3 is an element of S. This
construction rule is the recursive part of the definition, and the function
f pnq “ n ` 3 is called a constructor of the set S.
Which set S is described by these rules? We know that 3 is an element of S by
part (a). Since n “ 3 is an element of S, we can deduce that n ` 3 “ 6 is an
element of S as well due to the rule (b). By repeated applications of the rule
(b), we can infer that 9, 12, 15, and so on are also elements of S. In fact, we
claim that the subset S described by these rules1 is given by the set of positive
integers that are multiples of 3, so S “ t3m | m P N1 u.
In this example, the constructor f pnq “ n`3 depends on a single argument.
In the general case, a constructor can depend on more than one argument, but
always on at most a finite number of arguments. So another constructor could
be the function f pm, nq “ m ` 2n that “constructs” a new element m ` 2n of
the set given two known elements m and n.

1 At least when properly interpreted as the smallest possible set satisfying these rules.
4.9 Recursively Defined Sets 123

Recursively Defined Sets. A recursively defined set S is defined as a subset


of a universe U using explicitly given elements of the set S that belong to a
nonempty subset B of the universe U that is known as the base set. The
remaining elements of S are defined by repeatedly applying constructors from
a finite set C of constructors.
A constructor f in C is a function f : U n Ñ U that relates n known
elements to one or more new elements in the set, where the parameter n is a
positive integer that depends on the function f . We call n the arity of the
constructor f .
The subset S of the universe U recursively defined (or inductively
defined) by the base set B and the set C of constructors is the smallest subset
of the universe U such that

R1. the base set B is a subset of S,

R2. If x1 , x2 , . . . , xn are elements in S and f is an n-ary constructor in C,


then f px1 , x2 , . . . , xn q P S.

The rule R2 can also be expressed more compactly as f pS n q Ď S.


Let us now rigorously show the existence of the recursively defined set S.
There are many subsets S 1 of the universe U that satisfy the conditions R1
and R2 if we ignore the stipulation that S 1 is supposed to be the smallest such
set. For instance, the universe U itself satisfies the rules R1 and R2. Consider
the family
F “ tS 1 P P pU q | S 1 satisfies R1 and R2u
of all subsets S 1 of the universe U satisfying the conditions R1 and R2. Then
their intersection č
S“ F
is a set satisfying R1 and R2, so the set S itself belongs to the family F. Since
S is a subset of every set in the family F, it is clearly the smallest possible set
satisfying R1 and R2. In particular, this means that S does not contain any
extraneous elements that are not implied by the defining rules R1 and R2.
There is also a more constructive way to obtain the recursively defined set
S. We define level sets Lk for nonnegative integers k as follows. Let

L0 “ B

be the base set. For any nonnegative integer k, let


ď
Lk`1 “ Lk Y f ppLk qn q.
f PC

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

strings by juxtaposition. So ab concatenated with aab yields abaab. For any


string x P U , concatenation with the empty string yields xλ “ x “ λx.
We can recursively define a subset S of the universe U “ ta, bu˚ by the
base set B “ tλu containing the empty string, and set C “ tf, g, hu containing
the three constructors
‚ f pxq “ axb,
‚ gpxq “ bxa,
‚ hpx, yq “ xy,
where the constructors f and g concatenate the given string x with a and b in
the stated way. The constructor hpx, yq concatenates the two given strings x
and y.
Since the empty string λ is contained in the base set B Ď S, and f pλq “
aλb “ abq, it follows that ab P S. Similarly, g applied to λ shows that ba is
contained in S. Applying h to x “ ba and y “ ba shows that hpx, yq “ baba is
contained in S. Applying h to x “ ab and y “ ba shows that hpx, yq “ abba P
S. One can show that the set S consists of all strings in the universe U that
have the same number of a’s and b’s.

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.

Proof. Let M “ tx P S | P pxq holds u be the subset of elements of S for which


P pxq holds. By the induction basis, P pbq holds for all b P B, so M satisfies
R1. By the induction step, M contains the value f px1 , x2 , . . . , xn q of any
constructor f , given that it contains the arguments x1 , x2 , . . . , xn . Therefore,
M satisfies R2. It follows that M must contain S. We can conclude that S
and M must be equal, which shows that P pxq holds for all x P S.

The proof strategy of structural induction is to show that every element in


the base set satisfies the property P . In the induction step, one must show that
every constructor preserves the truth in the sense that if all arguments satisfy
the property P , then the element created by the constructor must satisfy P as
well. It should be stressed that the induction step must make the argument
for every constructor in the set C of constructors.
The next example illustrates the structural induction proof principle.

Example 4.31. Let U “ Z ˆ Z be the set consisting of pairs of integers.


We define S to be the smallest subset of the universe U with base set B “
126 4 Proofs by Induction

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.

Freely Generated Sets. Our next goal is to define functions on a recursively


defined set. Before we deal with that topic, it might be worthwhile to point
out that the elements of a recursively defined set are not necessarily created in
a unique way, as the next example shows.
Example 4.33. In Example 4.28, we defined the set of even integers using a
base set B “ t0u and constructors f4 pxq “ x ` 4 and f´6 pxq “ x ´ 6. Applying
the constructor f4 three times and then the constructor f´6 twice yields

f´6 pf´6 pf4 pf4 pf4 pxqqqqq “ x.


4.9 Recursively Defined Sets 127

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

f´6 pf´6 pf4 pf4 pf4 p0qqqqq “ 0.

In fact, any sequence consisting of 2m constructors f´6 and 3m constructors


f4 will create 0.

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.

Example 4.34. Let U “ Z be the universe of integers. Let S be recursively


defined by the base set B “ t0u and the set C “ thu consisting of the single
constructor h : Z Ñ Z given by
#
´n ` 2 if n ď 0,
hpnq “
´n if n ą 0.

In this case, the set S is created by repeatedly applying the constructor h, so

t0, hp0q, hphp0qq, hphphp0qqq, hphphphp0qqqq, . . . u “ t0, 2, ´2, 4, ´4, . . .u.

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.

Let S be a set that is recursively defined by a base set B and a set C of


constructors. The recursive definition of S is called free if and only if for every
element x in S, either x belongs to the base set B or there is just one constructor
f and one n-tuple of arguments x1 , x2 , . . . , xn such that x “ f px1 , x2 , . . . , xn q.
Equivalently, a recursive definition of S is free if and only if the base set
B and the sets f pS n q for all constructors f in C are pairwise disjoint, and
the restriction f æ S n of each constructor to arguments in S is an injective
function.
The key feature of a free recursive definition is that each element is con-
structed in an essentially unique way. If an element x of S belongs to the base
set, then this element cannot be produced by a constructor. If x is the value
of a constructor f , then no other constructor can produce it, and there is just
one tuple of arguments of f that yields x.

Example 4.35. In the previous example, the constructor h æ 2Z is an injective


function, and hp2Zq “ 2Zzt0u has an image that is disjoint from B “ t0u.
Therefore, the previous example gives a free recursive definition of the set of
even integers.
128 4 Proofs by Induction

Functions. If we are given a recursively defined set S, then it is tempting to


also recursively define functions on S. Naturally, one would like to exploit the
recursive structure of the domain S in the recursive definition of the function
as well. It turns out that some care is needed to ensure the success of this
approach.
Let U denote the universe of argument values. In addition, let V denote
the universe of function values. Let S be a subset of the universe U that is
recursively defined by a base set B and a set C of constructors. Suppose that
we want to recursively define a function g : S Ñ V .
We can proceed as follows. We map each element x in the base set B to
an element F pxq of V , and each n-ary constructor f : U n Ñ U to a function
F pf q : V n Ñ V . Then g is defined by

T1. gpyq “ F pyq for all y in the base set B

T2. If f is an n-ary constructor in C, and x1 , x2 , . . . , xn are elements in S with


value y “ f px1 , x2 , . . . , xn q, then gpyq “ F pf qpgpx1 q, gpx2 q, . . . , gpxn qq.

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.

Example 4.37. Let U “ A˚ be the universe of strings over the alphabet


A “ t0, 1, x, p, q, `, ˚u. Let S be the subset of U that is recursively defined by
the base set B “ t0, 1, xu and the set of constructors C “ ta, mu given by

ape1 , e2 q “ pe1 `e2 q,

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

The strings in S do not have a value. However, we can recursively define a


function g : S Ñ N0 that evaluates these expressions for instance by

F p0q “ 0, F p1q “ 1, F pxq “ 7,

and assigning to the constructor a the usual addition function on N0 , and to


the constructor m the usual multiplication function on N0 . Then the function
g defined by the rules T1 and T2 yields for instance

gp pp1 ` xq ˚ xq q “ gp p1 ` xq qgp x q “ pgp1q ` gpxqqgp x q,

which evaluates to

gp pp1 ` xq ˚ xq q “ p1 ` 7q7 “ 56.

This value of g is uniquely defined, as the underlying set S is given by a free


recursive definition.
We have already seen recursively defined functions similar to the evaluation
function g in the previous example, namely the valuation function v in propo-
sition logic, see Sect. 2.3. Many other examples can be found in the computer
science literature.
Even though it is often quite routine to verify that the recursive definition
of S is free, it should not be omitted when a function g is recursively defined
on S. If S is not defined by a free recursive definition, then we cannot rely
on Proposition 4.36 to guarantee that g is well-defined. Unfortunately, the
argument that the set S has a free recursive definition is often omitted in the
literature.

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.71. Show that every proof by structural induction can be replaced by a


proof by strong induction. [Hint: Introduce a suitable notion of depth for the
elements of the recursively defined set.]

4.72. Show by structural induction that 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. [Hint: For the
induction basis, argue that no other value than the one given by T1 can be
assigned to an argument in the base set B. For the induction step, argue that
if y “ f px1 , x2 , . . . , xn q and gpyq is the value given in T2, then no other value
can be assigned to y. The freeness of the recursive definition is the key in these
arguments.]
4.10 Notes 131

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:

E1. For all x in S, we have x „ x (reflexivity).

E2. For all x, y in S, if x „ y, then y „ x (symmetry).

E3. For all x, y, z in S, if x „ y and y „ z, then x „ z (transitivity).

An equivalence relation allows us to describe what elements of a set we consider


to be “essentially the same,” so it broadens the concept of an equality.

Example 5.1. The identity relation “ on a set S is an equivalence relation.


It is given by the set of pairs tpx, xq | x P Su.

1 You might recall that we introduced these notions in Chap. 3. In this chapter, we will

study this important trio of properties in more detail.

© The Author(s), under exclusive license to Springer Nature 133


Switzerland AG 2025
A. Klappenecker, H. Lee, Discrete Structures, Undergraduate Texts in
Mathematics, https://doi.org/10.1007/978-3-031-73434-2 5
134 5 Equivalence Relations

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.

Proposition 5.9. Let P be a partition of a nonempty set S. For x, y in S,


we define x ” y if and only if x in C and y in C for some C in P . Then ” is
an equivalence relation on S and P is its set of equivalence classes.

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.

Example 5.10. Consider the partition

P “ tt1, 2u, t3u, t4, 5uu.

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.

For instance, 1 ” 2 in the equivalence relation ”, since 1 and 2 belong to the


same block in the partition P .

Given an equivalence relation „ on a set S, we denote by S{„ the set

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

Example 5.11. Consider the set

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.

The equivalence relation identifies the line segment L0 “ tpx, 0q | 0 ď x ď 2u


with the line segment L1 “ tpx, 1q | 0 ď x ď 2u by identifying the points
px, 0q „ px, 1q for all x in the range 0 ď x ď 2. We can think of the quotient
space R{„ as a cylinder that is obtained from the rectangle R by gluing the
line segments L0 and L1 together.

Of course, we cannot take this representation too literally, but it conveys


the idea of the identification of the points on the top and bottom border of the
rectangle. In topology, this identification is actually made precise.

Equivalence relations permeate all areas of computer science and mathe-


matics. In the subsequent sections, we show how to obtain integers, rational
numbers, and more using equivalence relations.

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.4. We define on the set N1 “ t1, 2, 3, ¨ ¨ ¨ u of positive integers a relation „


such that two positive integers x and y satisfy x „ y if and only if x{y “ 2k
for some integer k. Show that „ is an equivalence relation.
5.5. Consider the set S “ R2 ztp0, 0qu consisting of the points in the Euclidean
plane without the origin. We define a relation „ on S by px1 , y1 q „ px2 , y2 q if
and only if there exists a nonzero real number λ such that px2 , y2 q “ pλx1 , λy1 q.
(a) Show that the relation „ is an equivalence relation on S. (b) Describe the
equivalence class rpx, yqs of a point px, yq in S.
5.6. The set of integers Z can be partitioned in the following three subsets:
the set of positive integers, the singleton set t0u containing 0, and the set of
negative integers. Describe the equivalence relation ” on Z that corresponds
to this partition.
5.7. Show that every equivalence relation „ on a set S can be defined by a
function f : S Ñ S such that for all x, y in S, we have
x„y if and only if f pxq “ f pyq.
5.8. Let ”c and ”s denote the equivalence relations on the set of real numbers
respectively induced by the cosine function and the sine function. In other
words, x ”c y if and only if cospxq “ cospyq, and x ”s y if and only if
sinpxq “ sinpyq. Are the equivalence relations ”c and ”s the same or different?
Prove your claim.
5.9. Suppose that an equivalence relation ”f on the set of real numbers is
induced by a function f , meaning that x ”f y if and only if f pxq “ f pyq.
Determine the equivalence classes of ”f , when
(a) f pxq “ x2 ,
(b) f pxq “ x3 ,
(c) f is an injective function,
(d) f is a constant function.
5.10. Consider the set S “ t1, 2, . . . , 6u. Find the equivalence relations that
correspond to the following partitions of S:
(a) P1 “ tt1, 2u, t3u, t4, 5, 6uu,
(b) P2 “ tt1, 4u, t3, 5u, t2, 6uu.
5.11. Consider the set
R “ tpx, yq P R2 | 0 ď x ď 2, 0 ď y ď 1u
of points that form a rectangle in the Euclidean plane, as in Example 5.11.
Define an equivalence relation ” on R that models gluing of the left and right
border line segments, and gluing of the top and bottom line segments.
138 5 Equivalence Relations

So the equivalence relation identifies the corresponding points on the left


and right border line segments, and identifies points on the top and bottom
border line segments. (a) Explicitly give the equivalence class rpx, yqs for each
point px, yq. (b) Find a geometrically inspired interpretation of the quotient
space R{”.

5.12. Determine all equivalence relations on the set ta, bu with two distinct
elements a and b.

5.13. Determine all equivalence relations on the set ta, b, cu.

5.14. Determine the number of different equivalence relations on ta, b, c, du.


You do not need to give the equivalence relations themselves, but merely count
their number.

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.16. Let R1 and R2 be equivalence relations on a nonempty set S. Is their


union R1 Y R2 an equivalence relation? Prove your claim or give a counter
example.

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.

5.19. Let R be a relation on a nonempty set S. Then the relation given by


8
ď
MR “ pR Y R´1 qk
k“0

is equal to the minimal equivalence relation containing R.


Here we follow the convention that pR Y R´1 q0 is the identity relation on
S. For k ě 1, the relation pR Y R´1 qk is the k-fold composition of R Y R´1
with itself.

5.20. Show that the relation „ on the set Z of integers given by

x „ y if and only if x ` 2y is divisible by 3

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

pa, bq „ pc, dq if and only if a ` d “ b ` c. (5.1)

Since a ´ b is undefined when a ă b, we simply rewrote c ´ d “ a ´ b into the


equivalent form a ` d “ b ` c. Let us verify that the relation „ is indeed an
equivalence relation.
Proposition 5.12. The relation „ defined by (5.1) is an equivalence relation.

Proof. The relation is reflexive, since a ` b “ b ` a, hence pa, bq „ pa, bq.


The relation is symmetric. Indeed, since pa, bq „ pc, dq implies a ` d “ b ` c,
we obtain by commutativity of addition the equation c ` b “ d ` a. It follows
that pc, dq „ pa, bq.
Finally, we are going to prove that the relation „ is transitive. Suppose
that pa1 , b1 q „ pa2 , b2 q and pa2 , b2 q „ pa3 , b3 q hold. The first relation implies
a1 ` b2 “ b1 ` a2 . Adding b3 to both sides yields

pa1 ` b3 q ` b2 “ b1 ` pa2 ` b3 q. (5.2)

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

pa1 ` b3 q ` b2 “ b1 ` pb2 ` a3 q “ pb1 ` a3 q ` b2 .

Subtracting b2 from both sides yields a1 ` b3 “ b1 ` a3 , which implies pa1 , b1 q „


pa3 , b3 q. Therefore, the relation is transitive.

We define the set Z of integers as the quotient set

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.

Our goal was to obtain a representation of negative integers. We accomplished


this goal by representing ´2 by any pair where the second coordinate is two
more than the first coordinate, so p0, 2q and p5, 7q both represent the value ´2.
The equivalence class of ´k is given by

´k “ tpn, n ` kq | n P N0 u.

 Perhaps you find it bewildering to represent a single integer value by an


infinite number of pairs of nonnegative integers. However, most people
have no qualms about the fact that the rational number 2{3 really represents
an infinite set
t2k{3k|k P Z, k ‰ 0u
of equivalent representations. In both cases, we use equivalence classes of
numbers. Of course, the representative 2{3 in lowest terms is in many ways
preferable, but allowing non-reduced representations such as 165{935 instead
of 3{17 can save time when conversions to the representatives are somewhat
costly. Exercise 5.21 shows how to identify canonical representatives of integers.

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.

5.3 Modular Arithmetic


Consider the set Z of integers and a positive integer n. We follow Gauss and
write
x ” y pmod nq,
if and only if x and y are two integers such that x ´ y is an integer multiple
of n. We call this relation the congruence modulo n on the set of integers.
The notation is a bit idiosyncratic but turns out to be convenient, since the
modulus is more readable than in the alternate subscript form ”n .
Proposition 5.13. Let n be a positive integer. The congruence modulo n is
an equivalence relation on the set of integers.
5.3 Modular Arithmetic 141

Proof. The relation is reflexive, since x ´ x “ 0n, so x ” x pmod nq holds for


all integers x. The relation is symmetric, since x ” y pmod nq implies that
there exist some integer k such that x ´ y “ kn, but then y ´ x “ ´kn, which
implies y ” x pmod nq. The relation is transitive, since x ” y pmod nq and
y ” z pmod nq imply that there exist integers k and  such that x ´ y “ kn
and y ´ z “ n, so x ´ z “ x ´ y ` y ´ z “ pk ` qn, hence x ” z pmod nq.
Therefore, the congruence modulo n is an equivalence relation on the set of
integers, as claimed.

The equivalence class of an integer x for the congruence modulo n is given


by
rxs “ ty P Z | x ” y pmod nqu.
Explicitly, this equivalence class is given by the set rxs “ tx ` kn | k P Zu.
The integer x can be expressed in the form x “ qn ` r with 0 ď r ă n, hence
rxs “ rrs. Therefore, the quotient set S{ „ is given by

S{ „ “ trxs | 0 ď x ď n ´ 1u.

The set S{ „ is usually denoted by Z{nZ.


The congruence modulo n is more than just an equivalence relation, since
it is compatible with addition and multiplication of integers.

Proposition 5.14. Suppose that x1 , x2 , y1 , y2 are integers such that x1 ” x2


pmod nq and y1 ” y2 pmod nq. Then

x 1 ` y1 ” x 2 ` y2 pmod nq,
x 1 y1 ” x 2 y2 pmod nq.

Proof. By assumption there exist integers k and  such that x1 ´ x2 “ kn and


y1 ´ y2 “ n. Adding these equalities, we get px1 ` y1 q ´ px2 ` y2 q “ pk ` qn,
which implies x1 ` y1 ” x2 ` y2 pmod nq.
For the second equation, we notice that x1 ´ x2 “ kn and y1 ´ y2 “ n
imply px1 ´ x2 qy1 “ y1 kn and py1 ´ y2 qx2 “ x2 n. Adding the latter two
equations yields px1 ´ x2 qy1 ` py1 ´ y2 qx2 “ py1 k ` x2 qn. Canceling terms, we
get x1 y1 ´ y2 x2 “ pky1 ` x2 qn, which implies x1 y1 ” x2 y2 pmod nq.

As a consequence of this proposition, we can define an addition and a


multiplication operation on Z{nZ by defining for integers x and y the operations

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?

5.4 Rational Numbers


For integers b and a with b ‰ 0, it is not always possible to solve the equation
bx “ a
in the integers. This suggests to use a larger domain to solve the equation. We
will introduce the rational numbers a{b for this purpose.
Let us define the set of pairs
Q “ tpx, yq P Z ˆ Z | y ‰ 0u,
where x represents the numerator and y the denominator of the rational num-
ber, so y is assumed to be nonzero. We define a relation „ on Q such that
pa, bq „ pc, dq if and only if ad “ bc. We claim that this is an equivalence
relation (which, unsurprisingly, realizes the cross-multiplication check for the
equality of rational numbers).
5.4 Rational Numbers 143

Proposition 5.15. The relation „ is an equivalence relation on Q.

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.

The set Q of rational numbers is defined to be the quotient set Q{ „.


The equivalence class rpa, bqs of a pair pa, bq is usually denoted in the fraction
notation a{b. For example, the rational number 1{2 represents the equivalence
class
1
“ tpk, 2kq | k P Z, k ‰ 0u,
2
so the equivalence class 1{2 contains for instance the numerator and denomi-
nator pairs p´2, ´4q, p´1, ´2q, p1, 2q, and p2, 4q, among others.
We define on the set Q of rational numbers two binary operations. The
addition of two rational numbers is defined as
a c ad ` bc
` “ .
b d bd
Since there are several different ways to represent the same rational number,
one needs to worry that this definition depends on the particular choice of the
representatives. Exercise 5.31 shows that this is not the case. The product of
two rational numbers is defined as
a c ac
¨ “ .
b d bd
Here one can show as well that the definition does not depend on the repre-
sentatives of the equivalence classes, see Exercise 5.32.

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

Partial Orders and Lattices


Order is the sanity of the mind, the health of the body, the peace of
the city, the security of the state. As the beams to a house, as the
bones to a microcosm of man, so is the order to all things.
— Robert Southey, The Doctor etc.

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.

6.1 Partial Orders


Let S be a set. A relation1 ď on S is called a partial order if and only if it
satisfies the following three properties:
O1. For all x in S, we have x ď x (reflexivity).
O2. For all x and y in S, x ď y and y ď x imply x “ y (antisymmetry).
O3. For all x, y, z in S, x ď y and y ď z imply x ď z (transitivity).
If a relation ď on S satisfies the properties O1–O3, then pS, ďq is called a
partially ordered set.
On occasion, we will encounter relations that are reflexive and transitive,
but not necessarily antisymmetric. Such a relation is called a preorder.
1 You might recall that we introduced relations in Chap. 3. Relations satisfying this trio

of properties are particularly important in practice.

© The Author(s), under exclusive license to Springer Nature 145


Switzerland AG 2025
A. Klappenecker, H. Lee, Discrete Structures, Undergraduate Texts in
Mathematics, https://doi.org/10.1007/978-3-031-73434-2 6
146 6 Partial Orders and Lattices

Notation. A relation is often denoted by a capital letter such as R, but for


partial orders, it is customary to use symbols that resemble the inequality
sign. Aside from ď, common symbols to denote partial orders are ď, Ď, and
Ď.
A prototypical example of a partial order is given by the power set ordered
by set inclusion.
Example 6.1. Let A be a set and S “ P pAq its power set. The set inclusion
Ď defines a partial order on S. Indeed, the set inclusion is reflexive, since every
set is a subset of itself. For two sets X and Y in S, if X Ď Y and Y Ď X
holds, then the sets X and Y must be the same, so Ď is antisymmetric. For
all sets X, Y, Z in S, the inclusions X Ď Y and Y Ď Z imply that X Ď Z, so
the relation is transitive.
Two elements x and y of a partially ordered set pS, ďq are called compara-
ble if and only if x ď y or x ě y. In a partial order, there might exist elements
that are not comparable, as the next example illustrates.
Example 6.2. Let S “ P pAq be the power set of a set A ordered by inclusion.
Then two elements X and Y of S are comparable if and only if X is a subset
of Y or Y is a subset of X. For example, if A “ t1, 2, 3u, then the subsets
X “ t1, 2u and Y “ t2, 3u are not comparable, as none is a subset of the other.
A subset T of a partially ordered set S is called a chain if and only if every
two elements of T are comparable. If S is finite, then the height of S is defined
to be the maximum cardinality of any chain in S.
If the entire set S is a chain, then it is also called a total order or a linear
order.
Example 6.3. The set R of real numbers with its natural order ď is a total
order.
Example 6.4. The set t1, 2, . . . , nu of the first n positive integers is a total
ordered set under the natural order 1 ď 2 ď ¨ ¨ ¨ ď n.
If two elements x and y of a partially ordered set pS, ďq are not comparable,
then they are called incomparable. A subset A of a partially ordered set S
is called an antichain if and only if any two elements of A are incomparable.
The next example shows the rather extreme case that a partially ordered set S
itself is an antichain; this is also known as the discrete partial order on S.
Example 6.5. Let S be a set. The identity relation “ on S is a partial
order called the discrete partial order on S. This relation is explicitly given by
tpx, xq|x P Su. It relates every element x of S to itself, but distinct elements
are incomparable.
Example 6.6. Tom likes to eat fruits for dessert. Among the choices
F “ tgrapefruit, apple, orange, strawberryu,
his preference relation ď is
grapefruit ď apple, grapefruit ď orange,
apple ď strawberry, orange ď strawberry,
6.2 Strict Order 147

and grapefruit ď strawberry, as well as f ď f for all fruits f P F . This is a


partial order. Apples and oranges are incomparable, as Tom has no preference
of one over the other.

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.

6.2 Strict Order


Let S be a set. A relation ă on S is called a strict order if and only if it
satisfies the following two properties
SO1. the relation is irreflexive, meaning that x ă x does not hold for any x
in S,
SO2. the relation is transitive, that is, x ă y and y ă z imply that x ă z
holds for all x, y, and z in S.
If a relation ă on S satisfies the properties SO1 and SO2, then pS, ăq is called
a strictly ordered set. Strict orders cannot be partial orders, but the two
concepts are closely related as we will see. We offer a few typical examples of
strict orders.
148 6 Partial Orders and Lattices

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.

Example 6.9. In distributed computing, one often considers a collection of


processes that communicate by sending messages. A process is understood
to be a totally ordered sequence of events (such as machine instructions, the
sending or receiving of messages). Lamport defined the happened-before
relation Ñ on the events in the distributed system as follows:
(a) Suppose that a and b are events that belong to the same process. Then
a Ñ b if and only if the event a happened before the event b.
(b) Let a be the event of sending a message and b the event of receiving the
same message. Then a Ñ b.
(c) The relation a Ñ a does not hold for any event a.
(d) For all events a, b, c, if a Ñ b and b Ñ c, then a Ñ c.
The happened-before relation Ñ is irreflexive by property (c) and transitive by
property (d); hence, it is a strict order. Events that are not comparable are
potentially concurrent events.

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.

Proposition 6.10. Let ď be a partial order on a set S. We can define a


relation ă on S by setting x ă y if and only if x ď y and x ‰ y. Then the
relation ă is a strict order on S.

Proof. The relation ă is by construction irreflexive. Suppose that x ă y and


y ă z holds. This means that x ď y and y ď z, as well as x ‰ y and y ‰ z hold.
It follows from the transitivity of ď that x ď z holds. Seeking a contradiction,
let us assume that x “ z; this would mean that x ď y and y ď x hold, so by
the antisymmetry of the partial order ď, we must have x “ y, contradicting
the fact that x ‰ y. Thus, x ă y and y ă z imply that x ď z and x ‰ z,
so x ă z. Therefore, ă is transitive. This shows that ă is a strict order, as
claimed.

We record a simple observation before proving our next proposition.

Lemma 6.11. A strict partial order ă on a set S is an asymmetric relation,


meaning that x ă y implies that y ă x cannot hold.

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

Proposition 6.12. Let ă be a strict order on a set S. Define a relation ď on


S by setting x ď y if and only if x ă y or x “ y. Then ď is a partial order
relation.

Proof. By definition, ď is reflexive.


The relation ď is antisymmetric, since x ď y and y ď x implies x “ y. This
is evident when x “ y. If x and y are distinct elements of S, then this follows
from the asymmetry of the strict order relation ă.
Suppose that x ď y and y ď z. If x “ y or y “ z, then it immediately
follows that x ď z. If x ‰ y and y ‰ z, then x ă y and y ă z holds, which
implies x ă z by transitivity of the strict order; hence, x ď z. Therefore, ď is
a transitive relation.

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.7. Show that an asymmetric and transitive relation is a strict order.

6.8. Is an irreflexive and asymmetric relation also transitive? Prove it or give


a counter example.

6.9. Construct the smallest strict order.

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.

6.3 Cover Relations and Hasse Diagrams


Let pS, ďq be a partially ordered set. We say that an element z in S covers
an element x in S if and only if x ă z, and there does not exist an element y
in S such that x ă y ă z. We write x 㨠z to denote that z covers x.
150 6 Partial Orders and Lattices

Example 6.13. Let P “ t1, 2, 3, 6u be a set partially ordered by the relation

ď “ tp1, 1q, p1, 2q, p1, 3q, p1, 6q, p2, 2q, p2, 6q, p3, 3q, p3, 6q, p6, 6qu.

The cover relation is given by

㨠“ tp1, 2q, p1, 3q, p2, 6q, p3, 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

x ă y must hold. Choose a chain of maximal length in pS, ďq such that


x “ z1 ă z2 ă ¨ ¨ ¨ ă zn “ y. Then zk 㨠zk`1 holds for all k in the range
1 ď k ă n. It follows that px, yq “ pz1 , zn q is in the reflexive and transitive
closure T of the cover relation, which is a contradiction.

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.17. Let S “ t1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12u be a set of integers par-


tially ordered by divisibility. The Hasse diagrams for pS, |q are shown below.

There is an edge between 3 and 6, since 3 is a proper divisor of 6, and


these two numbers differ by a single prime factor. So p3, 6q belongs to the
cover relation of the divisibility relation |. There is no edge between 3 and 12,
since that is implied by the divisibility relation 3 | 6 and 6 | 12, thus p3, 12q
does not belong to the cover relation of pS, |q. The cover relation consists of
pairs pa, bq such that both are elements of S and b can be obtained from a by
multiplication with a single prime factor.

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

Since the direction of an edge is determined by the upward direction, arrows


are not needed. This is advantageous for large lecture rooms, where a Hasse
diagram is easier to read than a cover graph with directed arrows.

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.14. Determine the cover relation of pP pt1, 2, 3u, Ďq.

6.15. Draw the Hasse diagram for the divisibility relation on the set

t1, 2, . . . , 10u

of positive integers from 1 to 10.

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.

6.4 Dilworth’s Theorem


Arguably, the simplest partially ordered set is a chain. If a partially ordered
set is not a chain, then we can still ask how many chains are needed to cover
all elements. Evidently, if not all elements are comparable, we need more than
one chain. Dilworth gave a surprisingly simple characterization of the fewest
number of chains that cover a finite partially ordered set S. He showed that
this figure coincides with the cardinality of the largest antichain in S.
We begin with a simple example that illustrates this fact.
6.4 Dilworth’s Theorem 153

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.

Let S be a partially ordered set. The maximal cardinality of an antichain


in S is called the width of S. If S has width m, then any partition of S into
pairwise disjoint chains C1 , . . . , Cn satisfies n ě m, see Exercise 6.17. Dilworth
showed the remarkable result that there always exist as few as n “ m pairwise
disjoint chains that partition S. This is an example of a so-called min-max
theorem, as it shows that the minimal number of chains that partition S is
equal to the maximal number of elements in an antichain of S.

Theorem 6.20 (Dilworth’s Theorem). Let pS, ďq be a finite partially ordered


set. Then the minimal number n of chains that partition S is equal to the
maximal cardinality m of an antichain in S.

Proof. By Exercise 6.17, the width m of S satisfies m ď n. We will show that


m ě n using a proof by induction.
If |S| “ 0, then no chains are needed to cover S and the maximal cardinality
of an antichain is 0, so the claim holds in this case.
Let us assume that the claim holds for all partially ordered sets of cardinality
|S| ă k. Consider a partially ordered set of cardinality |S| “ k, and let C be a
maximal chain of S.

Case 1. If the chain C meets every maximal antichain in S of cardinality m,


then the cardinality of a maximal antichain in SzC is m´1. By induction
hypothesis, SzC can be partitioned into m´1 chains. So adding the chain
C, we can conclude that S can be partitioned into n “ m chains.
154 6 Partial Orders and Lattices

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

Ad “ tx P S | there exists an a in A such that x ď au,

and its upward closure Au by

Au “ tx P S | there exists an a in A such that x ě au.

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.

In summary, we can conclude that S can always be covered with m chains.

The next example illustrates the second case of the previous proof.
6.4 Dilworth’s Theorem 155

Example 6.21. Let S “ ta, b, c, d, e, f u be a partially ordered set given by the


Hasse diagram Fig. 6.1. In other words, pS, ĺq is the reflexive and transitive
closure of the order relations a ă b ă c, d ă e ă f , and e ă b. Consider
the maximal chain C “ td, e, b, cu. This chain does not meet the antichain
A “ ta, f u. So this is an example where the second case in the proof of
Dilworth’s theorem applies. The upward closure Au of the antichain A is given
by Au “ ta, b, c, f u, and the downward closure Ad of the antichain A is given
by Ad “ ta, d, e, f u.

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 Ad and Au are proper subsets of S, they can be partitioned into


chains by the induction hypothesis. The downward closure Ad of the antichain
A is partitioned into the chains Ca “ tau and Cf “ td, e, f u. The upward
closure Au of A is partitioned into the chains Da “ ta, b, cu and Df “ tf u.
Therefore, the partially ordered set S can be partitioned into the two chains
Ca Y Da “ ta, b, cu and Cf Y Df “ td, e, f u.
Corollary 6.22. Let m and n be positive integers. Any partially ordered set
pS, ďq with mn`1 or more elements has a chain of length m`1 or an antichain
with n ` 1 elements.
Proof. Seeking a contradiction, let us suppose that each chain in S has at most
m elements and each antichain has at most n elements. Therefore, the width
of S is at most n, so S is covered by n or fewer chains. Since each chain has at
most m elements, the total number of elements in the chain cover is at most
mn, contradicting the fact that S has mn ` 1 or more elements.
Dilworth’s theorem has many consequences in combinatorics and computer
science. We give one playful application.
Suppose that you have m different gifts g1 , g2 , . . . , gm . You want to give
each of your n friends f1 , f2 , . . . , fn one gift that they like. Suppose that your
156 6 Partial Orders and Lattices

friend fk likes a subset Lk of the set of gifts tg1 , g2 , . . . , gm u. Is it possible to


get everyone a gift that they like? Frustratingly, this is not always possible, as
the next example shows.
Example 6.23. Suppose that you have five gifts G “ tg1 , g2 , . . . , g5 u. Your
friends f1 , f2 , f3 , and f4 respectively like the gifts

L1 “ tg1 u, L2 “ tg1 , g3 , g5 u, L3 “ tg2 u, L4 “ tg1 , g2 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.

Proof. We define a partial order ď on the set

M “ tg1 , g2 , . . . , gm , f1 , f2 , . . . , fn u

by the reflexive relation that satisfies gk ď f if and only if gk P L . Distinct


gifts are not comparable and distinct friends are not comparable either. A
chain in M either consists of a single element or of a gift liked by a friend,
g k ď f .
An antichain in M is given by tg1 , g2 , . . . , gm u. We claim that this is a
maximal antichain in pM, ďq. Indeed, seeking a contradiction, suppose that
there is an antichain A in M that contains a gifts and more than m ´ a friends,
so |A| ą m. The union of the gifts liked by the friends must contain more
than m ´ a gifts, but it cannot contain any of the a gifts contained in A. This
contradicts the fact that there are only m gifts. In other words, a maximal
antichain contains m elements. By Dilworth’s theorem, this means that we can
cover M with m chains.
Each gift is either covered by a chain of length 1, which means that the gift
is not given to anyone, or it is covered by a chain of length 2, in which case one
friend receives the gift. Therefore, after re-indexing any partition of M into
chains can be written in the form

ttg1 ď f1 u, tg2 , ď f2 u, . . . , tgk ď fk u, tgk`1 u, . . . , tgm u, tfk`1 u, . . . , tfn uu.


6.5 Lower and Upper Bounds 157

In other words, a partition into merely m chains must be of the form

ttg1 ď f1 u, tg2 , ď f2 u, . . . , tgk ď fk u, tgk`1 u, . . . , tgm uu,

so it cannot contain any friends that do not receive a gift.

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 .

6.19. Let n be a positive integer. Let A “ pa1 , a2 , . . . , an2 `1 q be some permu-


tation of the integers from 1 to n2 ` 1. Show that there exist pairwise distinct
indices i1 ă i2 ă . . . ă in`1 such that pai1 , ai2 , . . . , ain`1 q is either increasing
or decreasing subsequence of A.

6.20. Let n be a positive integer. Let I denote a set of n2 ` 1 open intervals


on the set R of real numbers. Prove that I either contains n ` 1 intervals that
overlap or n ` 1 intervals that are pairwise disjoint.

6.21. Let pP, ďq be a partial order of height h and width w with n “ |P |


elements. Show that n ď hw.

6.5 Lower and Upper Bounds

Let pS, ďq be a partially ordered set and X a subset of S. An element u in S is


called an upper bound for X if and only if x ď u holds for all x in X. Notice
that the upper bound u does not have to belong to the set X. A subset X of S
is called bounded above if and only if there exists an upper bound u for X.
The greatest element of a subset X of a partially ordered set S is an upper
bound that is contained in X itself. The greatest element of X is uniquely
determined if it exists.

Example 6.25. Let S “ t1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12u be a set of integers par-


tially ordered by divisibility. Two Hasse diagrams for pS, |q are shown as follows.
158 6 Partial Orders and Lattices

Consider the subset X “ t2, 4u of S. It is shaded red in the left Hasse


diagram. The elements 4, 8, and 12 are upper bounds of X in S. The element
4 is the greatest element of X. On the other hand, consider the subset Y “
t2, 3u of S in the right Hasse diagram. It has 6 and 12 as upper bounds.
However, Y does not have a greatest element, since 2 and 3 do not divide each
other.

An element  in S is called a lower bound for X if and only if  ď x holds


for all x in X. A subset X of S is called bounded below if and only if there
exists a lower bound for X. The least element of a subset X of S is a lower
bound for X that is contained in X. The least element of a subset X of S does
not need to exist, but if it does, then it is uniquely determined.

Example 6.26. We keep the notation of the previous example. We illustrate


lower bound in the two Hasse diagrams as follows.

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.

Let X be a subset of a partially ordered set S. We denote by U pXq the


set of all upper bounds for X in S. The least element of U pXq is called the
least upper bound or the supremum of X in S. The least upper bound of
X in S is uniquely determined if it exists. The least upper bound of X in S is
denoted by ł
sup X or X.
S S

The subscript S is omitted if it


Žis clear from the context. For sets X “ tx, yu
with two elements, we denote X also in the infix notation x _ y.

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.

Let X be a subset of a partially ordered set S. We denote by LpXq the set


of lower bounds of X in S. The greatest element of LpXq is called the greatest
lower bound or the infimum of X in S. The greatest lower bound of X in
S is denoted by ľ
inf X or X.
S
S

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.

Let pS, ďq be a partially ordered set. An element m of S is called maximal


if and only if for all x in S the relation m ď x implies m “ x. In other words,
a maximal element is not succeeded by any other element. There might exist
several different maximal elements or none at all in a partially ordered set.
An element w of S is called minimal if and only if for all x in S the relation
x ď w implies x “ w. In other words, a minimal element is not preceded by
any other element. Minimal elements, if they exist, are in general not unique.
160 6 Partial Orders and Lattices

Example 6.31. Let S “ t1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12u be a set of integers par-


tially ordered by divisibility. Two Hasse diagrams for pS, |q are shown below.

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.

The supremum of c and d is J “ c _ d, but the infimum of c and d does


not exist.

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.32. Let pS, ďq be a partially ordered set. Suppose that X is a subset of S.


Let U pXq denote the set of upper bound of X in S. Suppose that b is an upper
bound of X that is a minimum in U pXq. Does this mean that b is a least upper
bound for X? Prove your answer or give a counter example.

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.

6.6 Extensions of Partial Orders


Given two partial orders P and Q on a set S, we say that Q extends P if
and only if P Ď Q holds. In this section, we are going to show that each
partial order can be extended to a total order. These results have numerous
applications.

Proposition 6.33. Let ď be a partial order on a set S. Let a and b be incom-


parable elements of S. Then there exists a partial order Ď extending ď such
that a Ď b.

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

We define the relation Î to be the Cartesian product A ˆ B. Hence, the


elements in A precede the elements in B under Î; in particular, a Î b. We
define Ď as the union of the relations ď and Î. In other words, the relation Ď
consists of the set of pairs

tpx, yq P S ˆ S | x ď yu Y pA ˆ Bq.

It remains to show that Ď is a partial order. The relation Ď is reflexive, since


it contains the reflexive relation ď.
Seeking a contradiction, let us assume that Ď is not antisymmetric, that is,
there must exist distinct elements x and y in S such that x Ď y and y Ď x.
These relations can arise from x ď y or x Î y and from y ď x or y Î x, so we
distinguish four cases. (a) If x ď y and y ď x, then x “ y by antisymmetry of
the relation ď, which contradicts that x is distinct from y. (b) If x ď y and
y Î x, then b ď x, x ď y, y ď a, so by transitivity b ď a, which contradicts
the incomparability of a and b. (c) If x Î y and y ď x, then b ď y, y ď x,
x ď a, so by transitivity b ď a, which contradicts the incomparability of a
and b. (d) If x Î y and y Î x, then b ď x and x ď a, so by transitivity
b ď a, which once again contradicts the incomparability of a and b. Since we
arrived at a contradiction in each of the four cases, we can conclude that Ď is
antisymmetric.
For the transitivity, we need to show that x Ď y and y Ď z implies x Ď z.
We will distinguish for x Ď y the cases x ď y and x Î y and for y Ď z the
cases y ď z and y Î z, leading to a total of four cases. (a) If x ď y and y ď z,
then x ď z by transitivity. (b) If x ď y and y Î z, then x ď y, y ď a, so
by transitivity x ď a, which implies that the element x lies in A, and as z is
contained in B, we have x Î z, hence, x Ď z. (c) If x Î y and y ď z, then
b ď y and y ď z, which implies b ď z, so z is an element of B. As x is in A,
we have x Î z. (d) If x Î y and y Î z, then x is in A and z is in B, so x Î z.
In all four cases, we can conclude that x Ď z.

The next result is known as Zorn’s Lemma. It is frequently used to establish


the existence of maximal elements in infinite partially ordered sets.

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].

Zorn’s lemma is often used as an axiom, since it is equivalent to the axiom


of choice. The appeal of Zorn’s lemma is that it can be applied quite easily.
The proof of the next theorem is a typical example.

Theorem 6.35. Every partial order can be extended to a total order.


6.6 Extensions of Partial Orders 163

Proof. Let P be a partial order on a set S. We can define the family F of


partial orders by

F “ tQ | Q is a partial order on S containing P u.

The set family F is partially ordered


Ť by set inclusion. For every chain C in
F , a least upper bound is given by C. By Zorn’s lemma, there must exist a
maximal element M in F . It follows from Proposition 6.33 that M must be a
total order.

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

get up ď shirt ď socks ď pants ď jacket ď shoes ď head out.

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.

6.38. A function f : S Ñ S from a partially ordered set pS, ďq to itself is called


inflationary if and only if x ď f pxq holds for all x P S. Suppose that pS, ďq
is a partially ordered set such that every nonempty chain has an upper bound.
Show that an inflationary function f of S into itself has a fixed point. In other
words, show that there exists an element y in S such that y “ f pyq.

6.7 Monotonic Functions


Let pA, ďA q and pB, ďB q be partially ordered sets. A function f : A Ñ B is
called monotonic if and only if x ďA y implies f pxq ďB f pyq for all elements x,
y in A. In other words, if x precedes y, then f pxq must precede f pyq; however,
if x and y are incomparable, then there is no restriction on the ordering of their
images f pxq and f pyq.

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.

The identity function f : S Ñ S given by f pxq “ x is a monotonic function


from pS, ďA q to pS, ďB q.

Example 6.38. Let X be a set. A monotonic function from the partially


ordered set pP pXq, Ďq to the reversely ordered set pP pXq, Ěq is given by f pAq “
XzA. Indeed, if A Ď B are subsets of X, then f pAq “ XzA contains f pBq “
XzB.

A function f : A Ñ B is called an embedding of the partial order pA, ďA q


into the partial order pB, ďB q if and only if for all x, y in A, we have x ďA y
if and only if f pxq ďB f pyq.
A function f : A Ñ B is called an isomorphism of the partial orders
pA, ďA q and pB, ďB q if and only if f is a bijective function and an embedding.
The next theorem shows that any partially ordered set pA, ďq can be em-
bedded into the power set P pAq ordered by set inclusion.

Theorem 6.39. Let pA, ďq be a partially ordered set. Let f : A Ñ P pAq be


the function given by
f pyq “ tx P A|x ď yu.
Then f is an embedding of the partially ordered set pA, ďq into pP pAq, Ďq.

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

f pyq “ tx P A | x ď yu Ď f pzq “ tx P A | x ď zu.


6.7 Monotonic Functions 165

Therefore, the function f is monotonic.


On the other hand, suppose that f pyq Ď f pzq holds. By reflexivity of the
relation ď, the set f pyq contains y. Thus, we can conclude that y P f pyq Ď f pzq.
Hence, it follows from the definition of the set f pzq that y ď z.
Thus, we have shown that x ď z if and only if f pxq Ď f pzq.

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.42. We can order the Boolean value by declaring F ď T . Moreover, we can


partially order vectors x and y in tF, T un by defining x ď y if and only if xk ď
yk for all k in the range 1 ď k ď n. A Boolean function f : tF, T un Ñ tF, T u
is monotone if and only if x ď y implies f pxq ď f pyq. Which of the following
Boolean functions are monotone? In each case, explain why or why not the
function is monotone.
(a) x ^ y
(b) x _ y
(c) x ‘ y
(d) x _ y

6.43. The set N1 “ t1, 2, 3, . . .u of positive integers is partially ordered by the


divisibility relation |, where a | c if and only if there exist an integer b such that
c “ ab. The power set P pN1 q is partially ordered by the subset relation Ď.
Consider the function f that maps a positive integer to its set of prime factors,
so, for instance, f p1q “ H and f p18q “ t2, 3u.
(a) Show that f : pN1 , |q Ñ pP pN1 q, Ďq is a monotone function
(b) Is f an embedding of partial orders?
(c) Is f an isomorphism of partial orders?

6.44. Prove or disprove the following statements.


(a) A monotone function of partial orders preserves maxima and minima.
(b) An embedding of partial orders preserves maxima and minima.
(c) An isomorphism of partial orders preserves maxima and minima.

6.45. (a) Show that a monotone function maps chains to chains.


(b) Does a monotone function map antichains to antichains? Prove or disprove.
166 6 Partial Orders and Lattices

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.

Proof. Let X be a subset of S and U pXq the set of upper bounds of X in S.


The set X belongs to the set of lower bounds of U pXq. If we set b “ inf U pXq,
then x ď b for all x in X, as b is the greatest lower bound of U pXq. For any
other upper bound d in U pXq, we have b ď d by definition of the infimum.
Therefore, b “ sup X is the least upper bound of X. Thus, S is a complete
lattice, since inf X and sup X exist for each subset X of S.

Lemma 6.43. Let X “ tx1 , . . . , xn u be a finite nonempty subset of a lattice


L. Then the infimum of X exists and is given by

inf X “ p¨ ¨ ¨ ppx1 ^ x2 q ^ x3 q ^ ¨ ¨ ¨ ^ xn q.

Proof. We prove this by induction on the number n of elements in X. If


X “ tx1 u contains a single element, then inf X “ x1 . Let us assume that d “
inftx1 , . . . , xn´1 u exists and is of the form d “ p¨ ¨ ¨ ppx1 ^x2 q^x3 q^¨ ¨ ¨^xn´1 q.
We form
e “ p¨ ¨ ¨ ppx1 ^ x2 q ^ x3 q ^ ¨ ¨ ¨ ^ xn q “ d ^ xn .
We have d ď x1 , . . . , d ď xn´1 , since d is a greatest lower bound, e ď d and
e ď xn . By transitivity, we get e ď x1 , . . . , e ď xn . Let f be any lower bound
of tx1 , . . . , xn u. Since f is a lower bound for xn and tx1 , . . . , xn´1 u and d is the
greatest lower bound for the latter set, we have f ď xn and f ď d. Therefore,

f ď e “ d ^ xn

and we can conclude that e “ inftx1 , . . . , xn u, as claimed.


6.8 Lattices 167

Proposition 6.44. Every finite lattice is complete.

Proof. Let L be a finite lattice. By Proposition 6.42, it suffices to show that


every subset X of L has an infimum. The infimum of the empty set is given
by inf H “ sup L, see Example 6.30. Furthermore, every nonempty subset X
of L has an infimum by Lemma 6.43. Therefore, the lattice L is complete.

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.

Theorem 6.45 (Knaster-Tarski). Let pP, ďq be a complete lattice. A mono-


tonic map f : P Ñ P has a nonempty set of fixed points, and a least and
greatest fixed point exists.

Proof. Consider the set A “ tx P P | f pxq ď xu of elements that are preceded


by their image under f and set α “ inf A. Then for each x in A, we have
α ď x, so f pαq ď f pxq ď x, and we conclude that f pαq is a lower bound for
A. However, then f pαq ď α “ inf A, so α is an element in A. Since f is
monotonic, we get f pf pαqq ď f pαq, whence f pαq is an element of A, which
means α “ inf A ď f pαq, and we can conclude that α “ f pαq is a fixed point.
Similarly, consider the set W “ tx P P | x ď f pxqu of elements that precede
their image under f and set ω “ sup W . Then for each x in A, we have x ď ω,
so x ď f pxq ď f pωq, and f pωq is an upper bound for W . Since ω is the least
upper bound of W , we have ω ď f pωq, and we can conclude that ω is an
element of W . Applying the monotonic function f , we get f pωq ď f pf pωqq, so
f pωq is an element of W . Therefore, f pωq ď ω and as ω ď f pωq holds, we can
conclude that ω “ f pωq is a fixed point.
Since each fixed point p of f is contained in both sets A and W , we have
α ď p ď ω. Therefore, α is the least fixed point and ω is the greatest fixed
point of f .

The power set of a set is a complete lattice. As a consequence of the


previous theorem, we obtain a relative simple proof2 of the celebrated Schröder–
Bernstein theorem.

Theorem 6.46 (Schröder–Bernstein). Let A and B be sets. If there exists an


injective map f : A Ñ B and an injective map g : B Ñ A, then there exists a
bijective map h : A Ñ B.

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

Therefore, the map m : P pAq Ñ P pAq given by mpXq “ A ´ gpB ´ f pXqq is


monotonic.
Since the power set P pAq is a complete lattice, the function m has a fixed
point F by the Knaster–Tarski theorem, so mpF q “ F “ A ´ gpB ´ f pF qq. We
define a map h : A Ñ B by
#
f pxq if x P F,
hpxq “
g ´1 pxq if x P A ´ F “ gpB ´ f pF qq.

The function h is surjective. Indeed, consider an element b P B. If b P f pF q,


then there exists an x P F such that b “ f pxq “ hpxq by the first case of
the definition of h. If b P B ´ f pF q, then gpbq P gpB ´ f pF qq “ A ´ F , so
b “ g ´1 pgpbqq “ hpgpbqq by the second case of the definition of h.
The function h is injective. Indeed, suppose that x and y are distinct
elements of A. If x and y are both elements of F , then hpxq “ f pxq ‰ f pyq “
hpyq by injectivity of f . If x and y are both elements of A ´ F , then hpxq “
g ´1 pxq ‰ g ´1 pyq “ hpyq by the injectivity of g ´1 . If x P F and y P A ´ F “
gpB ´ f pF qq, then hpxq P hpF q “ f pF q and hpyq P hpA ´ F q “ g ´1 pgpB ´
f pF qqq “ B ´ f pF q, so hpxq ‰ hpyq. Hence, for all distinct x and y in A, we
have hpxq ‰ hpyq.

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

Floor and Ceiling Functions


Are you really sure that a floor can’t also be a ceiling?
— Maurits C. Escher, On Being a Graphic Artist

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.

7.1 Rounding Up and Down


The floor is a function from the set R of real numbers to the set Z of integers
that maps a real number x to the greatest integer n not exceeding x. The
floor function of a real number x is denoted by txu. In other words, the floor
function of a real number x is defined to be equal to the integer n “ txu if and
only if n ď x ă n ` 1.
The floor function txu rounds the real number x down to the greatest integer
that is smaller or equal to x. If we restrict the floor function to the set of
integers, then it is the identity; thus, tnu “ n for all integers n. The graph of
the floor function is shown in Fig. 7.1.

Example 7.1. We have t0.3u “ 0, t0.5u “ 0, t0.9999u “ 0, and t1.01u “ 1. For


negative numbers, one should pay attention to the fact that rounding down
does not mean rounding toward 0. Indeed, t´0.3u “ ´1, t´0.7u “ ´1, and
t´1.1u “ ´2.

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

© The Author(s), under exclusive license to Springer Nature 171


Switzerland AG 2025
A. Klappenecker, H. Lee, Discrete Structures, Undergraduate Texts in
Mathematics, https://doi.org/10.1007/978-3-031-73434-2 7
172 7 Floor and Ceiling Functions

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.

Example 7.2. We have r0.1s “ 1, r0.5s “ 1, r0.999s “ 1, and r1.1s “ 2. For


negative numbers, we have r´0.3s “ 0, r´0.7s “ 0, and r´1.1s “ ´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.

Proposition 7.3. For all real numbers x, we have

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

tx ` ku “ txu ` k, and rx ` ks “ rxs ` k.

Proof. By definition of the floor function, we have txu ď x ă txu ` 1. Adding


the integer k to each term yields

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

illusions of M.C. Escher.


7.1 Rounding Up and Down 173

Therefore, we can conclude that tx ` ku is equal to the integer txu ` k, which


proves our first claim.
By the previous proposition and the first claim, we have

rx ` ks “ ´ t´x ´ ku “ ´pt´xu ´ kq “ ´ t´xu ` k “ rxs ` k,

which proves the second claim.

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.

Proposition 7.5. Suppose that 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.

Proof. See Exercise 7.4.

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.

Proposition 7.6. For any integer n, we have


Yn] QnU
n“ ` .
2 2
Proof. If n is an even integer, then there exists an integer k such that n “ 2k.
It follows that tn{2u “ k “ rn{2s, so n “ 2k “ tn{2u ` rn{2s .
If n is an odd integer, then there exists an integer k such that n “ 2k ` 1.
It follows that tn{2u “ tk ` 1{2u “ k and rn{2s “ rk ` 1{2s “ k ` 1, so

n “ 2k ` 1 “ k ` pk ` 1q “ tn{2u ` rn{2s .

Since an integer is either even or odd, this proves the claim.

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

tlog2 1000u ` 1 “ t9.9657 ¨ ¨ ¨ u ` 1 “ 10

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.

Proposition 7.7. The number d of digits of a positive integer n in base b is


given by
d “ tlogb nu ` 1 and d “ rlogb pn ` 1qs .

Proof. Suppose that a positive integer n has d digits in base b. Then it is of


the form
d´1
ÿ
n“ a k bk ,
k“0

where ak is some integer in the range 0 ď ak ă b. It follows that

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.

Therefore, d ´ 1 “ tlogb nu or d “ tlogb nu ` 1, as claimed.


For the version with the ceiling function, we add 1 to the terms in (7.1) and
deduce the inequalities
bd´1 ă n ` 1 ď bd
as a consequence. Applying the logarithm to base b yields

d ´ 1 ă logb pn ` 1q ď d.

Therefore, d “ rlogb pn ` 1qs, which proves our second claim.

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.6. Show that for all real numbers x, we have

2 txu ď t2xu ď 2 txu ` 1.

7.7. Let n be an integer and m a positive integer. Show that


Z ^ Q U
n`m´1 n
“ .
m m

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

holds for all positive integers n.


176 7 Floor and Ceiling Functions

7.9. Show that for any real number x, we have

0 ď t2xu ´ 2 txu ď 1.

7.10. Let f : N1 Ñ N1 be the function on the set of positive integers given by


Z ^
? 1
f pxq “ n ` n ` .
2

Show that if m R ranpf q, then m must be a perfect square.

7.11. In January 2016, the largest known prime was

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

7.13. Evaluate the sum


2
nÿ ´1 Y? ]
k .
k“1
Y? ]
Hint: First determine the range of positive integers k satisfying a “ k .

7.14. (a) Prove by induction that


n
ÿ
k2k “ pn ´ 1q2n`1 ` 2
k“0

holds for all nonnegative integers n.


(b) Evaluate the sum
ÿn
tlog2 ku .
k“1

7.15. Show that for all nonnegative integers n, we have


8 Z
n ` 2k
ÿ ^
“ n.
k“0
2k`1

(Source: 1968 IMO Problem 6)


7.2 Divisibility and Primes 177

7.16. Show that the function f : R Ñ R given by


Y ]
2
f pxq “ lim pcospn!xπqq
nÑ8

satisfies #
1 if x P Q,
f pxq “
0 if x P RzQ.
(Source: de Koninck, Mercier [18])

7.2 Divisibility and Primes


The next proposition determines the number of positive integer multiples of a
positive integer k that do not exceed a bound x.
Proposition 7.8. Let x be a real number and k a positive integer such that
k ď x. Then the number m of positive integers that are divisible by k and do
not exceed x is given by Yx]
m“ .
k
Proof. By definition of the floor function, we have
Yx] x Yx]
ď ă ` 1.
k k k
Multiplying the terms of these inequalities by k, we get
Yx] ´Y x ] ¯
kďxă ` 1 k.
k k
In other words, multiplying k by m “ tx{ku does not exceed x, but pm ` 1qk
does. Therefore, the number of positive integers that are divisible by k and do
not exceed x are given by m, as claimed.
For example, the number of integers in the range from 1 to 100 that are
multiples of the prime 13 is given by t100{13u “ 7. Indeed, the multiples of 13
in this range are explicitly given by
13, 26, 39, 52, 65, 78, and 91.
Let us now turn to a different question. Recall that each positive integer n
can be written as a product of primes
ź
n“ pvp pnq
p

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

Example 7.9. The number n “ 12 has the factorization 12 “ 22 ¨3. Therefore,


v2 p12q “ 2, v3 p12q “ 1, and vp p12q “ 0 for all other primes p ą 3.
For a positive integer n, we now want to focus on the question to determine
the highest power of a prime p that divides n! “ 1 ¨ 2 ¨ 3 ¨ . . . ¨ pn ´ 1q ¨ n. So we
would like to determine
n
ÿ
vp pn!q “ vp pkq.
k“1

It is a good idea to study an example before trying to settle this question.


Example 7.10. Let us determine the 3-adic valuation of 13! “ 6, 227, 020, 800.
Fortunately, there is no need to factorize such large numbers, as

v3 p13!q “ v3 p1q ` v3 p2q ` v3 p3q ` ¨ ¨ ¨ ` v3 p13q.

Since vp pkq “ 0 unless k is a multiple of 3, we have

v3 p13!q “ v3 p3q ` v3 p6q ` v3 p9q ` v3 p12q “ 1 ` 1 ` 2 ` 1 “ 5.

The 3-adic valuation of 9 “ 32 is greater than 1, since it is divisible by 32 . We


do not have any 3-adic valuations greater than 2, since none of the numbers k
in the range 1 ď k ď 13 is divisible by 33 “ 27.
Proposition 7.11. Let n be a positive integer and p a prime. Then

tlog p nu Z ^
ÿ n
vp pn!q “ .
k“1
pk

Proof. Since n! is the product of the integers k in the range 1 ď k ď n, we


have
ÿn
vp pn!q “ vp pkq.
k“1

By Proposition 7.8, the number of integers\ that contribute a factor of p is given


2
X
by tn{pu. Among thoseX numbers, n{p contribute a second prime factor p.
Among those numbers n{p3 contribute a third factor, etc.
\

We have pm ą n if and only if m ą log n{ log p “ logp n if and only if


X \
m ą logp n . Therefore, the sum

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

Proposition 7.12. A positive integer n is prime if and only if


?
tÿnu ˆY ] Z ^˙
n n´1
´ “ 0. (7.2)
k“2
k k

Proof. We can express n in the form n “ qk ` r with 0 ď r ă k. If k does not


divide n, then the remainder r satisfies 1 ď r ă k and we have
Y n ] Z n ´ 1 ^ Z qk ` r ^ Z qk ` r ´ 1 ^
´ “ ´ “ q ´ q “ 0.
k k k k

If k divides n, then the remainder r “ 0 and we have


Y n ] Z n ´ 1 ^ Z qk ^ Z pq ´ 1qk ` k ´ 1 ^
´ “ ´ “ q ´ pq ´ 1q “ 1.
k k k k

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.

7.19. Let n and k be nonnegative integers suchXthat n ě k, m\ an integer such


that m ą nk , and  be the
`ninteger
˘ given by  “ pm ` 1qn {mk . Show that the
division of  by m yields k as a remainder. In other
` ˘ words, if we express  in
the form  “ qm ` r with 0 ď r ă m, then r “ nk . [Hint: Use the binomial
theorem to expand pm ` 1qn .]

7.20. Determine the number of terminating zeros of 1000!.

7.21. Does there exist a prime p such that vp p46!q “ 42?


180 7 Floor and Ceiling Functions
řm
7.22. Let n be a positive integer and p a prime. Suppose that n “ k“0 nk pk
is the base p expressionX of n, so\ the digits nk are in the range 0 ď nk ă p for
all indices k, and m “ logp pnq . Show that

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.25. Let n be`an˘integer such that n ą 1.


(a) Show that 2nn ˘ ” 0 pmod 2q
`2n
(b) Show that n ” 0 pmod 4q unless n is a power of 2.
[Hint: You can use Exercise 7.22.]

7.26. Use Proposition 7.12 to show that 113 is a prime number.

7.27. Explain why Proposition 7.12 does not lead to a fast check for primality.

7.28. Let n be a positive integer. Show that


#
X? \ X? \ 1 if n is a perfect square,
n ´ n´1 “
0 otherwise.

7.3 Functions of Floors and Ceilings


If a function has a floor or ceiling applied to its argument and value, then
it requires sometimes delicate arguments to fully analyze the behavior of the
resulting function. In other words, if we are given a function f pxq, we might
be interested in the behavior of

tf ptxuqu , tf prxsqu , rf ptxuqs , or rf prxsqs .

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.

Proposition 7.13. For all nonnegative real numbers, we have


Ya ] X? \
txu “ x .
Ya ]
Proof. Suppose that n “ txu . This means that
a
nď txu ă n ` 1.
7.3 Functions of Floors and Ceilings 181

Squaring the terms of these inequalities yields

n2 ď txu ă pn ` 1q2 .

Since the bounds are integers, it follows from Proposition 7.5 that

n2 ď x ă pn ` 1q2

holds. Taking square roots yields


?
nď x ă n ` 1,
?
so n “ t xu. We can conclude that
Ya ] X? \
txu “ n “ x ,

as claimed.

The next theorem is a vast generalization of the previous proposition. This


result is due to McEliece. The domain of the function is an interval I Ď R that
is closed under taking floors for the first claim and closed under taking ceilings
in the second claim.
Theorem 7.14. Let f be a continuous, monotonically strictly increasing real-
valued function such that f ´1 pZq Ď Z. Then

tf pxqu “ tf ptxuqu and rf pxqs “ rf prxsqs .

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 .

Seeking a contradiction, let us suppose that tf ptxuqu ă tf pxqu, so equality


does not hold. This implies the inequality f ptxuq ă tf pxqu, whence we have
f ptxuq ă tf pxqu ď f pxq. Since f is a continuous function, it follows by the
intermediate value theorem that there must exist an element y in the range
txu ď y ă x such that tf pxqu “ f pyq. As f pyq is an integer, it follows from the
hypothesis that y must be an integer. We must have txu ‰ y, since tf ptxuqu is
supposed to be different from f pyq “ tf pxqu. However, there cannot exist an
integer y satisfying txu ă y ă x, which is our desired contradiction. Therefore,
we can conclude that we must have tf ptxuqu “ tf pxqu.
The argument for the second claim is similar, so we omit it here.

We collect some consequences of this theorem.


Corollary 7.15. Let n be an integer satisfying n ě 2. Then
Ya ] X? \ Qa U P? T
n n
txu “ n x and rxs “ n x .
182 7 Floor and Ceiling Functions
?
Proof. The function f pxq “? n x is continuous and monotonically strictly in-
creasing. If the value m “ n x is an integer, then its argument x “ mn is an
integer as well. Therefore, the claim follows from the previous theorem.

Corollary 7.16. Let b be an integer satisfying b ą 1. Then

tlogb txuu “ tlogb xu and rlogb rxss “ rlogb xs .

Proof. The function f pxq “ logb x is continuous and monotonically strictly


increasing. If the value m “ logb x is an integer, then the argument x “ bm is
an integer as well. Therefore, the claim follows from the previous theorem.

Corollary 7.17. Suppose that n is a positive integer. Then


Z ^ Y ] R V Q U
txu x rxs x
“ and “ .
n n n n

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.

We can slightly generalize the previous corollary.


Corollary 7.18. Suppose that n is a positive integer and m an arbitrary in-
teger. Then
Z ^ Z ^ R V R V
txu ` m x`m rxs ` m x`m
“ and “
n n n n

Proof. The function f pxq “ px ` mq{n is continuous and monotonically strictly


increasing. If the function value f pxq “ k is an integer, then the argument
x “ kn´m is an integer as well. Therefore, the claim follows from the previous
theorem.

We can extend the previous theorem to monotonically strictly decreasing


functions. We assume that the domain of the function is an interval I Ď R
that is closed under taking floors for the first claim and closed under taking
ceilings in the second claim.
Theorem 7.19. Let f be a continuous, monotonically strictly decreasing real-
valued function such that f ´1 pZq Ď Z. Then

rf pxqs “ rf ptxuqs and tf pxqu “ tf prxsqu .

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

Seeking a contradiction, let us suppose that rf ptxuqs ą rf pxqs, so equality


does not hold. This implies the inequality f ptxuq ą rf pxqs, whence we have
f ptxuq ą rf pxqs ě f pxq. Since f is a continuous function, it follows by the
intermediate value theorem that there must exist an element y in the range
txu ď y ă x such that rf pxqs “ f pyq. As f pyq is an integer, it follows from the
hypothesis that y must be an integer. We must have txu ‰ y, since rf ptxuqs is
supposed to be different from f pyq “ rf pxqs. However, there cannot exist an
integer y satisfying txu ă y ă x, which is our desired contradiction. Therefore,
we can conclude that we must have rf ptxuqs “ rf pxqs.
The argument for the second claim is similar, so we omit it here.

EXERCISES
7.29. Carl was floored when he saw the following expression in a program:

ttttx{10u {10u {10u {10u .

Help him rewrite it using a single floor function.

7.30. Let n be an integer and ξ a real number in the range 0 ď ξ ă 1. The


function r` : R Ñ R rounds a real number towards infinity, so
#
n if 0 ď ξ ă 1{2,
r` pn ` ξq “
n ` 1 if 1{2 ď ξ ă 1.

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.

Example 8.1. We have 4 | 12, since 12 “ 4 ¨ 3. Similarly, we have 3 | 9, since


9 “ 3 ¨ 3. However, 6  9, since the equation 9 “ 6x does not have a solution x
in the set of integers.

Example 8.2. For all integers a, we have 1 | a and ´1 | a, since 1 ¨ a “ a and


´1 ¨ p´aq “ a. On the other hand, a | 1 implies that a “ 1 or a “ ´1, as we
will prove shortly.

Example 8.3. The relation b | 0 holds for all integers b, since 0 “ b ¨ 0. On


the other hand, 0 | a holds if and only if a “ 0.

© The Author(s), under exclusive license to Springer Nature 185


Switzerland AG 2025
A. Klappenecker, H. Lee, Discrete Structures, Undergraduate Texts in
Mathematics, https://doi.org/10.1007/978-3-031-73434-2 8
186 8 Number Theory

Proposition 8.4. If a and b are integers and a ‰ 0, then b | a implies 1 ď


|b| ď |a|.
Proof. Since b | a there must exist an integer c such that a “ bc. Since a ‰ 0,
we must have b ‰ 0 and c ‰ 0. It follows that |b| ě 1 and |c| ě 1. Furthermore,
we have |b| ď |b||c| “ |a|. Combining these inequalities yields the claim.
Proposition 8.5. For all integers a, b, c, we have
D1. a | a

D2. a | b and b | a if and only if a “ ˘b,

D3. c | b and b | a implies c | a,

D4. c | a implies c | am for all integers m.

D5. c | a and c | b implies c | pax ` byq for all integers x and y.

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.

Proof. Since a “ a ¨ 1, we have a | a. Therefore, property D1 holds.


The proof of property D2 is more interesting. If a “ ˘b, then evidently
a | b and b | a. Conversely, suppose that a | b and b | a hold. This immediately
implies that if one of a or b is equal to 0, then so is the other. Thus, we may
now assume that both a and b are nonzero. By the previous proposition, a | b
implies |a| ď |b| and b | a implies |b| ď |a|. Therefore, |a| “ |b|, and we can
conclude that a “ ˘b. This shows that property D2 holds.
Properties D3 and D4 follow directly from the definition of divisibility.
If c | a and c | b, then there exist integers ma and mb such that a “ cma and
b “ cmb . Therefore, ax ` by “ cma x ` cmb y “ cpma x ` mb yq, so c | ax ` by.
Thus, property D5 holds as well.

Corollary 8.6. If an integer a satisfies a | 1, then a “ 1 or a “ ´1.

Proof. For any integer a, we have 1 | a and by assumption a | 1, so a “ ˘1 by


property D2 of the previous proposition.

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.4. Let a and b be odd integers. Prove that 4 | pa2 ´ b2 q.

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.6.` ˘Show that if p is a prime and k is an integer in the range 1 ă k ă p, then


p | kp .

8.7. Prove that for all integers n, we have 120 | pn5 ´ 5n3 ` 4nq.

8.8. Let q, m, and n be positive integers.


(a) Show that pq ´ 1q | pq n ´ 1q.
(b) Show that m | n implies pq m ´ 1q | pq n ´ 1q.

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.

8.2 The Greatest Common Divisor


Suppose that a and b are integers, not both zero. The greatest common
divisor of a and b is an integer d satisfying the following three conditions

G1. d is a common divisor of a and b, so d divides a and d divides b,

G2. if d1 is a common divisor of a and b, then d1 divides d,

G3. d ą 0.

The greatest common divisor d is denoted by gcdpa, bq. In texts on number


theory, the greatest common divisor is sometimes simply denoted by pa, bq.
Conditions G2 and G3 ensure that the greatest common divisor is larger
than any other common divisor. It is usually formulated as a divisibility con-
dition, since this generalizes to other domains that are not totally ordered.

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.

Listing all divisors of an integer is too tedious. If the prime factorization of


a and b is known, then we can easily determine the greatest common divisor,
as the following proposition shows.
188 8 Number Theory

Proposition 8.8. Let a and b be nonzero integers. Let p1 , p2 , . . . , pn denote


all prime divisors of a and b. If a is of the form a “ ˘pa1 1 pa2 2 ¨ ¨ ¨ pann and b is
of the form b “ ˘pb11 pb22 ¨ ¨ ¨ pbnn , then the greatest common divisor of a and b
equals
minta1 ,b1 u minta2 ,b2 u
gcdpa, bq “ p1 p2 ¨ ¨ ¨ pminta
n
n ,bn u
.

Proof. By definition, d ą 0, so G3 is satisfied. Furthermore, d is a common


divisor of a and b, so G1 holds. Finally, if d1 is another positive common divisor
of a and b, then any prime dividing d1 must divide both a and b. Therefore,
we can write d1 in the form

d1 “ pc11 pc22 ¨ ¨ ¨ pcnn

for some nonnegative integers ck with 1 ď k ď n. Since d1 is a common divisor


of a and b, we must have 0 ď ck ď mintak , bk u for all k in the range 1 ď k ď n.
It follows that d1 divides d, so property G2 is satisfied as well.

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

gcdpa, bq “ 2mint3,2u 3mint1,3u “ 22 ¨ 3 “ 12,

according to the previous proposition.

One practical drawback of this approach is that finding the factorization of


an integer into primes is not an easy task. In fact, no fast algorithms are known
that can accomplish this task efficiently on a classical computer. Fortunately,
Euclid gave a very simple algorithm to quickly find the greatest common divisor
of two integers.
The main idea behind the Euclidean algorithm is the following observation
that reduces the calculation of the greatest common divisor of a and b to a
simpler problem with smaller numbers.

Proposition 8.10. Let a and b be integers such that 0 ă b ă a. If the division


of a by b yields a quotient q and remainder r, so a “ qb ` r with 0 ď r ă b,
then
gcdpa, bq “ gcdpb, rq.

Proof. If d is a common divisor of a and b, then d divides a ´ qb “ r. In other


words, any common divisor of a and b must be a common divisor of b and r.
Conversely, if d1 is a common divisor of b and r, then d1 divides qb ` r “ a.
Therefore, any common divisor of b and r is a common divisor of a and b.
Since the set of common divisors of a and b and the set of common divisors
of b and r are the same, we can conclude that gcdpa, bq “ gcdpb, rq.
8.2 The Greatest Common Divisor 189

We can repeatedly use the previous proposition to ease the calculations.


The next example illustrates this idea.

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

There remains a rectangle of dimension 42 ˆ 12 that is not yet tiled by


squares, and the dimension of this rectangle corresponds to the arguments of
gcdp42, 12q. Since 42 “ 3 ¨ 12 ` 6, we can fit into this rectangle three squares
of dimension 12 ˆ 12.

There remains an area of dimension 12 ˆ 6 that is not yet tiled by squares,


and this corresponds to the arguments of gcdp12, 6q. As 12 “ 2 ¨ 6, we can use
two squares of dimension 6 ˆ 6 to tile the remaining area.

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.19. Show that for all nonzero integers a, b, c, we have

gcdpgcdpa, bq, cq “ gcdpa, gcdpb, cqq.

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.

8.3 Linear Diophantine Equations


A Diophantine equation is a polynomial equation in several variables with
integral coefficients that are solved for integer solutions (or sometimes non-
negative integer solutions or positive integer solutions). Some Diophantine
equations can be difficult to solve. For example, Fermat conjectured that there
are no positive integers x, y, and z satisfying the equation

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.

We will now investigate when a linear diophantine equation has integer


solutions. The next lemma shows when we cannot find solutions.
192 8 Number Theory

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

does not have any integer solutions px, yq P Z2 .


Proof. For any integers x and y, the greatest common divisor of gcdpa, bq di-
vides ax ` by. Therefore, if the linear diophantine equation can be solved, then
d must divide c. The claim is the contrapositive of this statement.
It turns out that we can always solve the Diophantine equation ax ` by “ c
when gcdpa, bq divides the integer c. We first focus on the case when c is
equal to gcdpa, bq, and then obtain the general case as a consequence. The
proof technique used in this proposition is particularly important, as it takes
advantage of the concept of an ideal. You can explore ideals a bit further in
the exercises.
Proposition 8.15. Let a and b be integers that are not both zero. Let d “
gcdpa, bq. Then d is the smallest positive linear combination of a and b. This
means that there exist integers x0 and y0 such that

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.

The set I is not empty, since it contains the positive integer a2 ` b2 .


Let d denote the smallest positive integer that is contained in I. So d is of
the form d “ ax0 `by0 for some integers x0 and y0 . We claim that d “ gcdpa, bq.
We prove this claim by establishing the three properties G1–G3 of the greatest
common divisor of a and b.
By definition, the integer d is positive, so it satisfies G3.
Let d1 be a common divisor of a and b. Then there exist integers a0 and b0
such that d1 a0 “ a and d1 b0 “ b. Then

d “ ax0 ` by0 “ d1 a0 x0 ` d1 b0 y0 “ d1 pa0 x0 ` b0 y0 q,

so d1 divides d. Therefore, property G2 holds.


Using the division algorithm, we can write a and b in the form

a “ qa d ` ra , and b “ qb d ` rb

for some integers qa , ra and qb , rb such that 0 ď ra ă d and 0 ď rb ă d. This


means that we can express ra and rb as an integer linear combination of a and
b. Indeed,

ra “ a ´ qa d “ a ´ qa pax0 ` by0 q “ a ¨ p1 ´ qa x0 q ` b ¨ p´qa y0 q


8.3 Linear Diophantine Equations 193

and

rb “ b ´ qb d “ b ´ qb pax0 ` by0 q “ a ¨ p´qb x0 q ` b ¨ p1 ´ qb y0 q,

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.

Corollary 8.16. Let a, b, and c be integers. If gcdpa, bq divides c, then

ax ` by “ c

has an integer solution.

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.

We will summarize our findings in the next theorem.

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

Since gcdpa, bq “ d, we have gcdpa{d, b{dq “ 1. As b{d divides pa{dqpx0 ´ x1 q,


we can conclude using Exercise 8.25 that b{d must divide x0 ´ x1 . So there
exists an integer z such that pb{dqz “ x0 ´ x1 . It follows that

a b b
z “ py1 ´ y0 q.
d d d

Dividing both sides by b{d shows that

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

which proves our second claim.

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.

Example 8.18. Let us consider the linear Diophantine equation 96x`42y “ 6.


Using the Euclidean algorithm, we can calculate the greatest common divisor
gcdp96, 42q by

96 “ 2 ¨ 42 ` 12 (8.1)
42 “ 3 ¨ 12 ` 6 (8.2)
12 “ 2 ¨ 6 ` 0 (8.3)

It follows that gcdp96, 42q “ 6, so the Diophantine equation 96x ` 42y “ 6


can be solved. By ignoring the last equation and working our way backward
in the Euclidean algorithm, we can actually find the integers x and y. Indeed,
it follows from Eq. (8.2) that 6 “ 42 ´ 3 ¨ 12. Equation (8.1) shows that we
can express 12 in the form 12 “ 96 ´ 2 ¨ 42. Substituting this in the previous
equation yields

6 “ 42 ´ 3 ¨ 12 “ 42 ´ 3 ¨ p96 ´ 2 ¨ 42q “ 96 ¨ p´3q ` 42 ¨ 7.

Therefore, x “ ´3 and y “ 7 is a solution to 96x ` 42y “ 6.


8.3 Linear Diophantine Equations 195

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.

8.23. Determine all solutions to the linear Diophantine equation 7x ` 9y “ 4


in integers x and y.

8.24. Determine all solutions to the linear Diophantine equation 15x`21y “ 9


in integers x and y.

8.25. Let a, b, and c be integers such that gcdpa, bq “ 1. Show that a | bc


implies a | c.

8.26. The Euclidean algorithm applied to integers a and b such that a ě b ě 0


yields a chain of divisions with remainders

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)

An ideal I in the integers is a subset I of the set of integers Z such that


(a) I contains 0, (b) if I contains elements a and b, then it contains a ˘ b, (c)
if m P Z and a P I, then ma P I.

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.29. Let a and b be integers. Show that a | b if and only if aZ Ě bZ.

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

8.31. Let a and b be integers. Show that the set I “ tax ` by | x, y P Zu of


integral linear combinations of a and b is an ideal in Z.
8.32. Let a and b be integers such that ab ‰ 0. Show that
(a) aZ ` bZ “ gcdpa, bqZ,
(b) aZ X bZ “ lcmpa, bqZ.

8.4 Linear Congruence Equations


Recall that two integers a and b are called congruent modulo a positive integer
m if and only if their difference a ´ b is divisible by m. We write this relation
in the form a ” b pmod mq. A linear congruence equation is an equation
of the form
ax ” b pmod mq,
where a and b are given integers, the modulus m is a given positive integer,
and our goal is to find an integer x solving this congruence.
Proposition 8.19. Let a and b be integers, and m a positive integer. Let
d “ gcdpa, mq. The congruence
ax ” b pmod mq
has a solution if and only if d divides b.
Proof. Suppose that the congruence equation has a solution x0 . Then ax0 ” b
pmod mq implies that m divides ax0 ´ b, meaning there must exist an integer
k such that ax0 ´ b “ km. Rewriting the latter equation, we get ax0 ´ km “ b.
Since d divides the left-hand side of the equation, it follows that d divides b.
Conversely, suppose that d “ gcdpa, mq divides b. This means there exist
integers x0 and y0 such that ax0 ` my0 “ b. Reducing modulo m, we get
ax0 ” b pmod mq,
so the congruence equation ax ” b pmod mq can be solved.
Example 8.20. The linear congruence equation
6x ” 9 pmod 15q,
has a solution, since d “ gcdp6, 15q “ 3 divides 9. One solution is given by
x0 “ 4, as 6 ¨ 4 ” 24 ” 9 pmod 15q.
Example 8.21. The linear congruence equation
5x ” 1 pmod 10q
does not have a solution, as d “ gcdp5, 10q “ 5 does not divide 1. Indeed, the
least significant digit of an integer multiple of 5 is either 0 or 5. Therefore, we
have 5x ” 0 or 5 pmod 10q for all integers x, which means that no integer x
satisfies the congruence 5x ” 1 pmod 10q.
8.4 Linear Congruence Equations 197

If we are given a solution x0 to the linear congruence equation ax ” b


pmod mq, then any other integer x1 such that x1 ” x0 pmod mq solves the
congruence equation as well. Indeed, we can express x1 in the form x1 “
x0 ` km for some integer k, so ax1 ” apx0 ` kmq ” ax0 pmod mq. It follows
that
ax1 ” ax0 ” b pmod mq.
In other words, if there exists a solution x0 to a linear congruence equation,
then there exist infinitely many, namely the entire congruence class

rx0 s “ tx0 ` km | k P Zu.

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

has the solutions x0 “ 4, x1 “ 9, and x2 “ 14. There are no other integer


solutions x in the range 0 ď x ď 14. Thus, there are three non-equivalent
solutions. Any solution belongs to one of the three congruence classes

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

has d inequivalent solutions. If one solution is given by x0 , then the d inequiv-


alent solutions are given by
m
xk “ x0 ` k ,
d
where k is an integer in the range 0 ď k ď d ´ 1.
Proof. The congruence equation ax ” b pmod mq is equivalent to the linear
Diophantine equation
ax ` my “ b.
If d “ gcdpa, mq divides b, then there exist integers x0 and y0 such that ax0 `
my0 “ b. All solutions to the linear Diophantine equation are given by
m a
x “ x0 ` z, y “ y0 ´ z,
d d
where z is an integer. Reducing modulo m, we obtain the claim.
198 8 Number Theory

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

f pa1 , a2 , . . . , an q ” f pb1 , b2 , . . . , bn q pmod mq

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.

8.5 The Chinese Remainder Theorem


The Chinese Remainder Theorem concerns the solution of a system of congru-
ence equations. A specific instance of the theorem was already stated in the
third century in a book by the Chinese mathematician Sunzi Suanjing. We
discuss it in the next example.
Example 8.24. Sunzi Suanjing stated the following problem: There are cer-
tain things whose number is unknown. If we count them by threes, we have
two left over; by fives, we have three left over; and by sevens, two are left over.
How many things are there? If we express this in congruence notation, then we
look for an integer such that the following congruence equations are satisfied:

x”2 pmod 3q,


x”3 pmod 5q,
x”2 pmod 7q.

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.

Any two solutions x to this system of congruences are congruent modulo m.

Proof. The integers m{mi and mi are coprime, so gcdpm{mi , mi q “ 1. There-


fore, there exist integers ai and bi such that
ˆ ˙
m
ai ` mi bi “ 1.
mi
It follows that ˆ ˙
m
ai ” 1 pmod mi q.
mi
If we multiply both sides of the congruence by ri , we get
ˆ ˙
m
ai ri ” ri pmod mi q.
mi
We claim that a solution x to the system of congruences is given by
n ˆ ˙
ÿ m
x“ ak rk .
k“1
mk

Indeed, we have m{mk ” 0 pmod mi q whenever the index k is different from


i, since in this case m{mk is a multiple of mi . Therefore,
n ˆ ˙ ˆ ˙
ÿ m m
x“ ak rk ” ai ri ” ri pmod mi q
k“1
m k m i
200 8 Number Theory

for all indices i in the range 1 ď i ď n.


Any two solutions x and x1 of the system of congruences satisfy

x ” x1 pmod mi q

for all i in the range 1 ď i ď n. Therefore,

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

x”7 pmod 10q,


x”8 pmod 11q,
x ” 12 pmod 13q.

The product m of the moduli is given by m “ 10 ¨ 11 ¨ 13 “ 1430. Since the


integers pm{mk q and mk are coprime, we can find integers ak and bk such that
pm{mk qak ` mk bk “ 1, namely
ˆ ˙
m
a1 ` m1 b1 “ 143p´3q ` 10 ¨ 43 “ 1,
m1
ˆ ˙
m
a2 ` m2 b2 “ 130 ¨ p5q ` 11 ¨ p´59q “ 1,
m2
ˆ ˙
m
a3 ` m3 b3 “ 110p´2q ` 13 ¨ 17 “ 1.
m3

The residues are given by r1 “ 7, r2 “ 8, and r3 “ 12. We form


ˆ ˙ ˆ ˙ ˆ ˙
m m m
x“ a1 r1 ` a2 r2 ` a3 r3
m1 m2 m3
“ 143 ¨ p´3q ¨ 7 ` 130 ¨ 5 ¨ 8 ` 110 ¨ p´2q ¨ 12
“ ´443.

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,

x ” ´443 ` 1430 ” 987 pmod 1430q

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.39. Tom has a large collection of quarters. If he arranges them in rows of


10, he will have 3 left over. If he arranges them in rows of 13, then he will have
5 left over. How many quarters does he have, if the total number is less than
130?

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

(b) Show that x ” s1 ` s2 ` s3 pmod mq is a solution to the original system


of congruences.
(c) Use Joe’s method to solve the system of congruences

x”1 pmod 11q,


x”2 pmod 13q,
x”3 pmod 17q.

8.42. Recall that an integer is called square-free if and only if it is not


divisible by any perfect square other than 1. So 6 “ 2 ¨ 3 is square-free, but
18 “ 2 ¨ 32 is not square-free. Show that there exist one million consecutive
integers that are not square-free.

8.6 The RSA Public Key Cryptosystem


We will discuss in this section the basic principles of the RSA public-key cryp-
tosystem, a system that is used in countless e-commerce applications. The RSA
public-key cryptosystem nicely illustrates the number-theoretic principles that
we have learned so far.
Suppose that Alice seeks a way that people can send her confidential mes-
sages by e-mail. The RSA cryptosystem allows her to publish a key that ev-
eryone can use to send her an encrypted message, but that is hard to decipher
without a secret that is only known to her.
We need some notation before stating the protocol. Euler’s totient func-
tion ϕ : N Ñ N is defined as
źˆ 1
˙
ϕpnq “ n 1´ ,
p
p|n

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.

• She selects an odd integer e ą 0 such that gcdpe, ϕpnqq “ 1. Thus,


there exist integers d and k such that ed ´ kϕpnq “ 1. Put differently,
ϕpnq “ pp ´ 1qpq ´ 1q divides ed ´ 1.

• 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

Encryption and Decryption:

• For simplicity, we assume that a message is encoded as an integer M in


the range 2 ď M ă n.

• If Bob wants to send a message M to Alice, then he looks up Alice’s


public key and sends her the number

C ” Me pmod nq.

• Alice uses her secret key to compute

C d ” M ed pmod nq.

It turns out that M ed ” M pmod nq, so she recovers Bob’s message.

It might be instructive to look at a simple example that illustrates the RSA


protocol.

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

gcdpe, ϕpnqq “ 1 “ 7d ´ ϕpnqk “ 7 ¨ 307, 183 ´ 1, 075, 140 ¨ 2.

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

1737 ” 955, 441 pmod 1, 077, 217q.

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

C 307,183 ” 955, 441307,183 ” 127 pmod 1, 077, 217q.

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.

When Bob intends to send a message M to Alice, he encodes the message


M into the ciphertext C ” M e pmod nq. When Alice receives the ciphertext
C, she attempts to decode C by forming C d ” M ed pmod nq. We will now
show that M ed is indeed congruent to M modulo n, so Alice does receive the
correct message. The next theorem proves the correctness of this protocol.
Theorem 8.29. Let n “ pq be a product of two distinct primes p and q. Let
e, d, and k be positive integers satisfying ed “ 1 ` kϕpnq. Then

M ed ” M pmod nq

holds for all integers M .

Proof. It suffices to show that the two congruences

M ed ” M pmod pq and M ed ” M pmod qq

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,

M ed ” M 1`kϕpnq ” M pM p´1 qkpq´1q ” M 1kpq´1q ” M pmod pq.

Therefore, M ed ” M pmod pq holds for all integers M . Replacing p by q in


the previous argument shows that M ed ” M pmod qq for all integers M .

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

theory by Weissman [79]. Elementary number theory by Dudley [20] is another


good option. A bit more advanced but still very accessible is A Classical
Introduction to Modern Number Theory by Ireland and Rosen [38].
Part II

Summation and Asymptotics

207
Chapter 9

Sums
The art of doing mathematics consists in finding that special case
which contains all the germs of generality.
— David Hilbert

In this chapter, we will learn how to systematically evaluate sums such as

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.

9.1 A Motivating Example


Suppose that we want to find the value of the sum
n
ÿ 1 1 1 1
“ ` ` ¨¨¨ ` “?
k“1
kpk ` 1q 1 ¨ 2 2 ¨ 3 npn ` 1q

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

© The Author(s), under exclusive license to Springer Nature 209


Switzerland AG 2025
A. Klappenecker, H. Lee, Discrete Structures, Undergraduate Texts in
Mathematics, https://doi.org/10.1007/978-3-031-73434-2 9
210 9 Sums

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,

then we can rewrite our sum in the form


n
ÿ n
ÿ
f pkq “ pF pk ` 1q ´ F pkqq.
k“1 k“1

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

Reindexing the first sum of the right-hand side yields


n
ÿ n`1
ÿ n
ÿ
pF pk ` 1q ´ F pkqq “ F pkq ´ F pkq.
k“1 k“2 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

Therefore, we succeeded in transforming the given sum into a nice telescoping


sum that is easy to evaluate
n n
ÿ 1 ÿ
“ pF pk ` 1q ´ F pkqq “ F pn ` 1q ´ F p1q.
k“1
kpk ` 1q k“1

Of course, it remains to find such a miraculous function F pkq that satisfies


1
“ F pk ` 1q ´ F pkq.
kpk ` 1q
If we define
1
F pkq “ ´
k
then we can verify that the difference
1 1 ´k ` k ` 1 1
F pk ` 1q ´ F pkq “ ´ ` “ “ ,
k`1 k kpk ` 1q kpk ` 1q
as claimed. In summary, we can rewrite the sum as follows:
n n ˆ ˙
ÿ 1 ÿ 1 1 1 1 n
“ ´ ` “´ ` “ .
k“1
kpk ` 1q k“1
k ` 1 k n ` 1 1 n ` 1
9.2 Difference Calculus 211

Motivation. In the subsequent sections, we show how to generalize this ap-


proach. The pattern is similar to what you might know from calculus.1 The
sums correspond to definite integrals. If you want to evaluate a definite integral
żb
f pxq dx,
a

then you need to determine the indefinite integral


ż
F pxq “ f pxq dx

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.

9.2 Difference Calculus


Let f be a function from the set of integers to the set of real numbers. The
difference operator Δ (or forward difference operator to be precise) is
defined as
Δf pxq “ f px ` 1q ´ f pxq.

1 If you have not taken calculus yet, then simply skip to the next section.
212 9 Sums

The operator Δ serves as a discrete version of the derivative that is studied in


calculus, but it has a much simpler definition.
Recall that the differential operator d{dx conceived by Leibniz acts on a
function f : R Ñ R by

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.

Figure 9.1: The function f pxq “ 12 x2 ´ 2x ` 3 has the derivative dx d


f pxq “ x ´ 2
and the difference Δf pxq “ x ´ 32 . The figure on the left shows the tangent line
d
through the point p2, f p2qq “ p2, 1q of slope p dx f qp2q “ 0, so this illustrates the
geometric interpretation of the derivative. The figure on the right shows a secant line
through the points p2, f p2qq and p3, f p3qq of slope pΔf qp2q “ 12 , so this illustrates the
geometric interpretation of the difference operator

Examples. There are many similarities between the differential operator


d{dx and the difference operator Δ. For example, the difference and differ-
ential operators behave the same on polynomials of degree 1 or less.

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.

Example 9.4. The function f pxq “ x3 has the difference

Δx3 “ px ` 1q3 ´ x3 “ 3x2 ` 3x ` 1.

Example 9.5. Let α be a real number such that α ‰ 1. Then

Δαx “ αx`1 ´ αx “ pα ´ 1qαx .

In particular, α “ 2 satisfies Δ2x “ 2x . Thus, the function 2x plays the same


role in difference calculus as the exponential function ex in calculus.
Since the difference operator does not use a limiting process, it is defined
whenever the function arguments are defined.
Example 9.6. The absolute value f pxq “ |x| has the difference

Δ|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

Δpcf pxqq “ cf px ` 1q ´ cf pxq


“ cpf px ` 1q ´ f pxqq “ cΔf pxq

holds.
214 9 Sums

(b) The difference operator is additive, since

Δpf pxq ` gpxqq “ pf px ` 1q ` gpx ` 1qq ´ pf pxq ` gpxqq


“ f px ` 1q ´ f pxq ` gpx ` 1q ´ gpxq
“ Δf pxq ` Δgpxq

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

Δf pxq “ Δx3 ´ 2Δx ` Δ1


“ p3x2 ` 3x ` 1q ´ 2 ˆ 1 ` 0 “ 3x2 ` 3x ´ 1.

Perhaps you find the difference of polynomials of degree 2 or 3 a bit confusing.


We will see in the next section that there is a simple pattern, even though it
might not be apparent now.

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.

For instance, Sx2 “ px ` 1q2 “ x2 ` 2x ` 1.

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:

Δpf gq “ pΔf qg ` f Δg ` pΔf qpΔgq (9.1)


Δpf gq “ pΔf qSg ` f Δg (9.2)
Δpf gq “ pΔf qg ` pSf qΔg (9.3)

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

pΔf qg ` f Δg ` pΔf qpΔgq “ pf px ` 1q ´ f pxqqgpxq ` f pxqpgpx ` 1q ´ gpxqq


` pf px ` 1q ´ f pxqqpgpx ` 1q ´ gpxqq
“ f px ` 1qgpx ` 1q ´ f pxqgpxq.
9.2 Difference Calculus 215

So both sides are indeed the same, as claimed.


For the second product rule (9.2), we observe that

Δpf gq “ f px ` 1qgpx ` 1q ´ f pxqgpxq


“ f px ` 1qgpx ` 1q looooooooooooooooooomooooooooooooooooooon
´f pxqgpx ` 1q ` f pxqgpx ` 1q ´f pxqgpxq
we inserted an expression equal to 0

“ pΔf pxqqgpx ` 1q ` f pxqΔgpxq,

which proves the product rule given in Eq. (9.2).


We can obtain the third product rule (9.3) from the second product rule (9.2)
by exchanging the role of f and g.

Example 9.10. In Examples 9.2 and 9.5, we established that Δx “ 1 and


Δ2x “ 2x . By the first product rule of the previous proposition, we have

Δpx2x q “ pΔxq2x ` xpΔ2x q ` pΔxqpΔ2x q


“ 2x ` x2x ` 2x
“ 2x`1 ` x2x .

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

The latter expression implies the claimed quotient rule.

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

Alternatively, we could have used a calculation directly based on the definition,


ˆ x˙
2 2x`1 2x 2x`1 x2 ´ 2x px ` 1q2
Δ 2
“ 2
´ 2 “
x px ` 1q x x2 px ` 1q2
2x px2 ´ 2x ´ 1q
“ ,
x2 px ` 1q2

to arrive at the same conclusion.

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.3. Let c be a nonzero real number. Show that


ˆ ˙
1
Δ logpcxq “ log 1 ` .
x

9.4. Show that


1 1
Δ “´ .
x xpx ` 1q
9.5. Show that
a
` ˘ `a˘
(a) Δ sinpaxq “ 2 cos ax
` ` 2 asin
˘ 2` a. ˘
(b) Δ cospaxq “ ´2 sin ax ` 2 sin 2 .

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.7. Use the first product rule to determine Δpx2 5x q.

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.

9.10. Use the first product rule to determine ΔpHx ¨ Hx q.

9.11. Use the quotient rule to determine Δp2x {xq.


9.3 Falling Factorial Powers 217

9.3 Falling Factorial Powers


In this section, our goal is to understand the difference operator a bit better.
We discover a family of functions that is essentially2 mapped to itself by the
difference operator. The functions in this family are called falling factorial
powers. Their main benefit is that the action of the difference operator on
polynomials is easy to understand once polynomials are expressed in terms of
falling factorial powers. We will also get a useful interpretation of binomial
coefficients in terms of falling factorial powers.
Recall that a polynomial with real coefficients in the indeterminate x is
an expression
f pxq “ ak xk ` ak´1 xk´1 ` ¨ ¨ ¨ ` a1 x ` a0
such that the coefficients a0 , . . . , ak are real numbers. The degree of a nonzero
polynomial f pxq is defined as deg f pxq “ maxti | ai ‰ 0u, and by convention
deg 0 “ ´8. The coefficient a0 is called the constant term of the polynomial.
The largest index k such that ak ‰ 0 is called the leading coefficient of f pxq
and ak xk is called the leading term.
If we apply the difference operator Δ to a polynomial ppxq of degree k ą 0,
then
Δppxq “ ppx ` 1q ´ ppxq
is a polynomial of degree k ´ 1. Examples 9.3 and 9.4 show that the difference
operator Δ applied to a monomial does not lead to a multiple of a monomial.
Fortunately, there exists a family of polynomials on which Δ acts in a simple
fashion, and we will define these polynomials next.
For a nonnegative integer k, we define xk to be the polynomial of degree k
given by
xk “ xpx ´ 1q ¨ ¨ ¨ px ´ k ` 1q,
where it is understood that the empty product is 1, meaning that x0 “ 1. We
call xk a falling factorial power and pronounce it as “x to the k falling.”

Proposition 9.13. For nonnegative integers k, we have

Δxk “ kxk´1 .

Proof. It follows from the definitions that

Δxk “ px ` 1qk ´ xk “ px ` 1qxk´1 ´ xk´1 px ´ k ` 1q.

Factoring out the term xk´1 yields

Δxk “ ppx ` 1q ´ px ´ k ` 1qqxk´1 “ kxk´1 ,

which proves the claim.

2 By “essentially” we actually mean “up to multiplication by a scalar”.


218 9 Sums

The next proposition shows that every polynomial can be expressed as a


linear combination of falling factorial powers.

Proposition 9.14. A polynomial of degree n can be expressed in the form


n
ÿ
ppxq “ ak x k
k“0

for some uniquely determined coefficients a0 , . . . , an in R.

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

rpxq :“ ppxq ´ an`1 xn`1

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

for some real numbers a0 , a1 , . . . , an and b0 , b1 , . . . , bn . Then


n
ÿ
0 “ ppxq ´ ppxq “ pbk ´ ak qxk
k“0

shows that the terms of degree n must cancel, so bn “ an must hold.


Therefore,
n´1
ÿ n´1
ÿ
ak x k “ 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

B “ txk | k is a nonnegative integer u

forms a basis of the vector space of polynomials in the indeterminate x with


real coefficients. The advantage of using the basis B instead of the set

txk | k is a nonnegative integer u

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 .

This extends the claim of Proposition 9.13 to all integers k.

Proof. For n ą 0, we have


1 1
Δx´n “ ´
px ` 2qpx ` 3q ¨ ¨ ¨ px ` n ` 1q px ` 1qpx ` 2q ¨ ¨ ¨ px ` nq
px ` 1q ´ px ` n ` 1q
“ “ ´nx´n´1
px ` 1qpx ` 2q ¨ ¨ ¨ px ` n ` 1q

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.

The binomial coefficient is defined as


xk
ˆ ˙
x
“ .
k k!
220 9 Sums

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

where the difference is formed in the argument x.

Proof. By definition,

px ` 1qk ´ xk ppx ` 1q ´ px ´ k ` 1qqxk´1


ˆ ˙ ˆ ˙ ˆ ˙
x x`1 x
Δ “ ´ “ “
k k k k! k!
kxk´1 x
` ˘
and the latter expression can be simplified to k! “ k´1 .

Corollary 9.18. The previous proposition implies the recurrence relation


ˆ ˙ ˆ ˙ ˆ ˙
x`1 x x
“ `
k k k´1

that governs the construction of Pascal’s triangle.

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.]

9.19. Show that


n
ÿ pΔk f qpaq
f pxq “ px ´ aqk
k“0
k!

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.

9.4 Stirling Numbers


In this section, we show how to express a monomial xn in terms of falling
factorial powers. The linear combination is given using the so-called Stirling
numbers of the second kind. These numbers are interesting in their own right,
but for now their main benefit is that they enable us to change quickly from
the usual polynomial representation in terms of monomials to the falling power
representation.
222 9 Sums

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

Combining the two sums, we get


n´1
ÿ´ ¯
xn “ Spn ´ 1, k ´ 1q ` Spn ´ 1, kqk xk ` Spn, nqxn .
k“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.

Example 9.20. By definition of the Stirling numbers, we have

x2 “ Sp2, 2qx2 ` Sp2, 1qx1 ` Sp2, 0qx0 .

It remains to explicitly determine the values of these Stirling numbers. By the


previous proposition, we have Sp2, 2q “ 1 and Sp2, 0q “ 0. The recurrence
relation allows one to calculate Sp2, 1q in the form

Sp2, 1q “ Sp1, 0q ` 1Sp1, 1q “ 0 ` 1 “ 1.

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.

9.5 The Fundamental Theorem of Summation


Let f be a function from the set of integers to the set of real numbers, and a
and b integers such that a ď b. We want to derive a method to evaluate sums
of the form
ÿb
f pkq “ f paq ` f pa ` 1q ` ¨ ¨ ¨ ` f pbq.
k“a
9.5 The Fundamental Theorem of Summation 225

A function F is called an antidifference of f (or the indefinite sum of f )


if and only if ΔF “ f holds. In other words, an antidifference F of f satisfies

ΔF pxq “ F px ` 1q ´ F pxq “ f pxq.

We write Δ´1 f to denote an antidifference of f . Antidifferences play the same


role in summation as indefinite integrals in integration.
If we know an antidifference F of the function f , then we can transform a
partial sum of f into a nicely summable sum of the telescoping kind. Indeed,
we have by definition
b
ÿ b
ÿ b
ÿ
f pkq “ ΔF pkq “ pF pk ` 1q ´ F pkqq .
k“a k“a k“a

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

Proof. By definition of an antidifference, we have


b
ÿ b
ÿ
f pkq “ pF pk ` 1q ´ F pkqq “ F pb ` 1q ´ F paq,
k“a 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

If we know an antidifference F pkq of f pkq, then by definition


ΔF pkq “ F pk ` 1q ´ F pkq “ f pkq.
Using the antidifference, we can express the aforementioned sum in the form

f p1q ` f p2q ` f p3q ` f p4q “


pF p2q´F p1qq ` pF p3q´F p2qq ` pF p4q´F p3qq ` pF p5q´F p4qq.
226 9 Sums

Reordering the terms on the right-hand side, we obtain

f p1q ` f p2q ` f p3q ` f p4q


“ F p5q ` F p4q ´ F p4q ` F p3q ´ F p3q ` F p2q ´ F p2q ´ F p1q

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

f p1q ` f p2q ` f p3q ` f p4q “ F p5q ´ F p1q.

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.

Example 9.23. What is the value of the sum

1 ¨ 2 ¨ 3 ` 2 ¨ 3 ¨ 4 ` 3 ¨ 4 ¨ 5 ` ¨ ¨ ¨ ` npn ` 1qpn ` 2q?

Using falling factorials, we can express this sum in the form


n`2
ÿ n`2
ÿ
k3 “ kpk ´ 1qpk ´ 2q.
k“3 k“3

By Proposition 9.13, an antidifference of f pkq “ k 3 is given by

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

This approach is easy, as long as you can find the antidifference.

How can we find antidifferences? Known difference relations are our main
source, at least initially. For instance, we have shown that

Δx2 “ 2x1 “ 2x.

Therefore, it follows that we can choose Δ´1 x to be 12 x2 “ 12 xpx ´ 1q. We


collect a few such results in Fig. 9.2.
In the remainder of this section, we give more applications of the previous
theorem and prove the less straightforward claims of Fig. 9.2.
9.5 The Fundamental Theorem of Summation 227

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

As we have noted earlier, an antidifference of f pxq “ x is given by F pxq “


x2 {2 “ xpx ´ 1q{2. By the Fundamental Theorem of Summation, we have
n
ÿ pn ` 1qn 1 ¨ 0 pn ` 1qn
k “ F pn ` 1q ´ F p1q “ ´ “ .
k“1
2 2 2

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

It follows from Example 9.5 that an antidifference of f pxq “ αx is given by


F pxq “ αx {pα ´ 1q. By the Fundamental Theorem of Summation, we have
b
ÿ αb`1 ´ αa
αk “ .
k“a
α´1

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 C is a constant function when restricted to the integers.


1
Proof. For k ‰ ´1, we have Δp k`1 xk`1 ` Cq “ xk by Proposition 9.16. For
k “ ´1, we have ΔpHx `Cq “ x´1 . Applying the antidifference operator yields
the result.
9.5 The Fundamental Theorem of Summation 229

We can use falling factorial powers to obtain antidifferences of ordinary


power functions such as squares x2 and cubes x3 .

Proposition 9.27. For any positive integer n, we have


n
ÿ Spn, kq k`1
Δ´1 xn “ x `C
k“0
k`1

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

of the first n cubes. By the previous proposition, the antidifference of x3 is


given by

Sp3, 3q 4 Sp3, 2q 3 Sp3, 1q 2 1 3 1


Δ´1 x3 “ x ` x ` x “ x4 ` x3 ` x2
4 3 2 4 3 2
By the Fundamental Theorem of Summation, we get
n ˆ ˙
ÿ 1 1 1 4 1
k3 “ pn ` 1q4 ` pn ` 1q3 ` pn ` 1q2 ´ 1 ` 13 ` 12 .
k“1
4 2 4 2

The last term in parentheses is equal to 0. After expanding the remaining


terms and a bit of algebra, the right-hand side simplifies to
n ˆ ˙2
ÿ
3 npn ` 1q
k “ .
k“1
2

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 .

9.32. Use the Fundamental Theorem of Summation to show that


npn ` 1qp2n ` 1q
12 ` 22 ` ¨ ¨ ¨ ` n2 “ .
6
9.33. Use the Fundamental Theorem of Summation to show that
1 1 1 1
` ` ¨¨¨ ` “1´ .
1¨2 2¨3 npn ` 1q n`1

9.34. The Fibonacci sequence is defined as F1 “ 1, F2 “ 1, and Fn “ Fn´1 `


Fn´2 for n ě 3. Calculate the sum

F 1 ` F 2 ` ¨ ¨ ¨ ` Fn

using the Fundamental Theorem of Summation.

9.35. Determine the sum


n ˆ ˙ ˆ ˙ ˆ ˙ ˆ ˙ ˆ ˙
ÿ x 0 1 2 n
“ ` ` ` ¨¨¨ `
x“0
k k k k k

in closed form using the Fundamental Theorem of Summation.


9.6 Analysis of Programs 231

9.36. Madame L’Orange wants to decorate her supermarket by stacking or-


anges into triangular pyramids. It occurs to her that she should know whether
she has enough oranges before attempting to build a pyramid of n layers of
oranges. Let Pn denote the number of oranges in a triangular pyramid of n
layers of oranges. For a single layer, she figures that a single orange suffices,
P1 “ 1. For two layers, she reasons that a single orange should be stacked on
top of three oranges, so P2 “ 4. For three layers, Madame L’Orange pictures
a single orange on top of three oranges that are stacked on six oranges, so
P3 “ 10. Now she recognized the pattern. The number Pn of oranges in n
layers is given by
ÿn
Pn “ Tk ,
k“1

where Tk is the triangular number Tk “ kpk ` 1q{2.


(a) Find the antidifference of the triangular numbers

Sk “ Δ´1 Tk .

(b) Use the Fundamental Theorem of Summation to express Pn in closed form


(that is, express Pn with a formula that does not contain summation signs
Σ or ellipses).

9.37. Determine a closed form of the sum

1 ¨ 1! ` 2 ¨ 2! ` 3 ¨ 3! ` ¨ ¨ ¨ ` pn ´ 1q ¨ pn ´ 1q!

using the Fundamental Theorem of Summation.

9.38.

(a) Show that an antidifference of tx{2u is given by


Yx] Zx ´ 1^
.
2 2

(b) Find the value of the sum


n Z ^
ÿ k
k“1
2

using the Fundamental Theorem of Summation.

∗9.6 Analysis of Programs


In this section, we will illustrate how sums occur naturally in the analysis of
algorithms.
232 9 Sums

Example 9.29. In this first example, we consider a simple version of bub-


blesort, which is given by the following implementation in the programming
language Ruby:3
class Array
def bubblesort
n = self.length - 1;
for i in 1..n
for k in 0..n - i
self[k], self[k+1] = self[k+1], self[k] if self[k] > self[k+1]
end
end
self
end
end

The method is called on a given array as follows:


[4,3,2,1,5,6].bubblesort
and it returns the sorted array [1,2,3,4,5,6].
The program consists of two nested loops. In the first iteration of the outer
loop, the inner loop swaps elements until the largest element in the sorting
order is at the correct place. In the second iteration of the outer loop, the
elements are swapped by the inner loop until the second largest element is at
the correct place, and so on.
Let  be the length of the array, so  is equal to self.length. The number
Bi of comparisons self[k]>self[k+1] in the i-th iteration of the outer loop
is given by Bi “  ´ i. The total number of comparisons in all iterations is
given by
´1
ÿ ´1
ÿ
Bi “ p ´ iq.
i“1 i“1
´1 1 1 2
Since Δ p ´ xq “ x ´ 2x
“ x ´ xpx ´ 1q{2, we obtain by the Fundamental
Theorem of Summation a total of
´1
ÿ p ´ 1q 1p1 ´ 1q p ´ 1q
p ´ iq “ 2 ´ ´¨1` “
i“1
2 2 2

comparisons. This does not come as a surprise, since the sum


´1
ÿ
p ´ iq “ p ´ 1q ` p ´ 2q ` ¨ ¨ ¨ ` 2 ` 1
i“1

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

Example 9.30. We use the well-known quicksort algorithm by C.A.R. Hoare


as an example that illustrates how sums emerge in an analysis of the average-
case running time. Consider the following simple4 but complete implementa-
tion of quicksort in Ruby:
class Array
def quicksort
return self if self.length <= 1
pivot = self.shift
left, right = self.partition {|e| e < pivot }
left.quicksort + [pivot] + right.quicksort
end
end
If the input array is of length ď 1, then there is nothing to do and the input
array is returned. Otherwise, it selects the leftmost element of the array as a
pivot element, partitions the array into a left part containing all elements that
are smaller than the pivot, and a right part containing all elements that are
greater or equal to the pivot. The left and right parts are recursively sorted.
The resulting sorted array is composed of the sorted left part, the pivot, and
the sorted right part. This extension to the Array class allow us to sort an
array in the form
[7,5,6,3,4,8,1,2].quicksort
and this yields the result
[1,2,3,4,5,6,7,8]
A simple measure for the expected running time is the expected number Cn of
comparisons e < pivot with the pivot element. Let us assume that the input
is chosen uniformly at random from all possible permutations. The partition
operation will use n ´ 1 comparisons for an input of length n. If the correct
sorting order of the pivot element is the k-th position in the array, then the
left array will have k´1 elements and the right array will have n´k elements.
Since the input is assumed to be uniformly distributed, the sorting order of the
pivot element is uniformly distributed as well. This means that the average
number of comparison satisfies the recurrence relation
# řn
n ´ 1 ` n1 k“1 pCk´1 ` Cn´k q if n ą 0,
Cn “
0 if n “ 0.
We can simplify this recurrence relation to the form
# řn´1
n ´ 1 ` n2 k“0 Ck if n ą 0,
Cn “
0 if n “ 0.
4 In production code, it is recommended to use an implementation of quicksort that uses

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

If we multiply both sides of the recurrence by n, then we get


n´1
ÿ
nCn “ npn ´ 1q ` 2 Ck
k“0

and consequently
n´2
ÿ
pn ´ 1qCn´1 “ pn ´ 1qpn ´ 2q ` 2 Ck .
k“0

Subtracting these two equations yields the much simpler recurrence


nCn ´ pn ´ 1qCn´1 “ 2pn ´ 1q ` 2Cn´1 .
After collecting terms, dividing by npn ` 1q, and substituting various values
for n, we get the chain of equations:
1 2pn ´ 1q 1
Cn “ ` Cn´1
n`1 npn ` 1q n
1 2pn ´ 2q 1
Cn´1 “ ` Cn´2
n pn ´ 1qn n ´ 1
..
.
1 2¨1 1
C2 “ ` C1
3 2¨3 2
Since C1 “ 0, we can unroll this chain of equations into a single sum:
n n´1
ÿ k´1 ÿ k
Cn “ 2pn ` 1q “ 2pn ` 1q .
k“2
kpk ` 1q k“1
pk ` 1qpk ` 2q

We can simplify the summand by rewriting it in the form


k 2 1
“ ´ .
pk ` 1qpk ` 2q k`2 k`1
This yields
˜ ¸
n´1
ÿˆ ˙ n`1 n
2 1 ÿ 2 ÿ 1
Cn “ 2pn ` 1q ´ “ 2pn ` 1q ´ .
k“1
k`2 k`1 k“3
k k“2 k

Since the antidifference of 1{x is Hx´1 , the Fundamental Theorem of Summa-


tion yields
Cn “ 2pn ` 1q pp2Hn`1 ´ 2H2 q ´ pHn ´ H1 qq .
As 2Hn`1 “ 2Hn ` 2{pn ` 1q, we can simplify this expression to
Cn “ 2pn ` 1qHn ´ 4n.
The significance of this average number Cn of comparisons with the pivot is
that the average running time of quicksort is bounded by a constant times Cn .
9.7 Notes 235

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.

10.1 Asymptotic Equality


Let f and g be functions from the set of positive integers to the set of real
numbers. We write f „ g and say that f is asymptotically equal to g if and
only if
f pnq
lim “1
nÑ8 gpnq

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.

© The Author(s), under exclusive license to Springer Nature 237


Switzerland AG 2025
A. Klappenecker, H. Lee, Discrete Structures, Undergraduate Texts in
Mathematics, https://doi.org/10.1007/978-3-031-73434-2 10
238 10 Asymptotic Analysis

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

Perhaps the best known example is given by Stirling’s approximation, which


relates the function n! to a function that allows one to understand the asymp-
totic growth much better.
Example 10.3. The Stirling approximation of n! is given by
? ´ n ¯n
n! „ 2πn .
e
The function f pnq “ n! grows less rapidly than nn . Dividing nn by en yields a
better approximation of n!, but pn{eqn is ? always an underestimate for n!. By
multiplication
? ` ˘n with the corrective term 2πn, we obtain the function gpnq “
2πn ne that has asymptotically the same growth as the factorial function
f pnq “ n!. The approximation works well even for relatively? small numbers n.
For instance, if we approximate f p10q “ 10! by gp10q “ 2π 10 p10{eq10 , then
the error  of the approximation is
ˇ ˇ
ˇ 10! ˇ
` 10 ˘10 ´ 1ˇ ă  ă 1.009.
ˇ ˇ
ˇ?
ˇ 2π10 ˇ
e

So the multiplicative error of Stirling’s approximation of 10! is less than 1%.


One advantage of the asymptotic equality „ is that the expression can
be simplified quite a bit. The next proposition illustrates this in the case of
polynomials.
řm
Proposition 10.4. Let ppxq “ k“0 ak xk be a nonzero polynomial of degree
m with real coefficients. Then ppxq is asymptotically equal to its leading term,

ppxq „ am xm .

Proof. By assumption, the leading coefficient am ‰ 0. By expanding terms,


we get
ˆ ˙
ppxq am´1 a1 a0
lim “ lim 1 ` ` ¨¨¨ ` ` “ 1,
xÑ8 am xm xÑ8 am x am xm´1 am x m

which proves the claim.

The leading term of a polynomial dominates the growth. The advantage


of the asymptotic notation „ is that we can dramatically simplify expressions
such as ppxq “ x3 ` 3x2 ` 2x ` 1 when considering large x, since the relation
x3 ` 3x2 ` 2x ` 1 „ x3 tells us that the polynomial ppxq grows like x3 . The
notation brings clarity and gives us more compact expressions. Naturally, one
can derive similar propositions for many other classes of functions.
The definition of f „ g by a limit means that all the techniques that you
have learned in calculus can be applied. You can apply the knowledge that
you have gained in calculus to deduce asymptotic equality in situations that
are not entirely obvious. As an example, we give a convenient criterion for
240 10 Asymptotic Analysis

asymptotic equality of expressions that are of the form f pn ` kq ´ f pnq for


some constant k. It is a slight generalization of a lemma given in Koecher [52,
Chap. II.1.7]. The use of the mean value theorem in the proof is particularly
noteworthy, since you can apply similar methods in other contexts as well.

Proposition 10.5. Let c be a positive real number. Let f be a continuously


differentiable function from the set of positive real numbers to the set of real
numbers such that its derivative f 1 is monotonic, nonzero, and satisfies

lim f 1 pn ` cq{f 1 pnq “ 1.


nÑ8

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

f pn ` cq ´ f pnq “ pn ` c ´ nqf 1 pn ` θq “ cf 1 pn ` θq.

If f 1 is monotonically increasing (or monotonically decreasing), then

cf 1 pnq ď f pn ` cq ´ f pnq ď cf 1 pn ` cq.


pěq pěq

Dividing by cf 1 pnq yields by assumption

cf 1 pnq cf 1 pn ` cq
lim “1 and lim “ 1.
nÑ8 cf 1 pnq nÑ8 cf 1 pnq

Therefore, by the squeeze theorem for limits, we have

f pn ` cq ´ f pnq
lim “ 1,
nÑ8 cf 1 pnq

which proves our claim.

Example 10.6. Let c be a positive constant. Then


? ? c
n`c´ n„ ? .
2 n
?
Indeed, if we set f pxq “ x, then f is a continuously? differentiable function on
the positive real numbers. Its derivative f 1 pxq “ 1{p2 xq is nonzero, monoton-
ically decreasing, and satisfies limnÑ8 f 1 pn ` cq{f 1 pnq “ 1. The claim follows
from Proposition 10.5.

Example 10.7. Let k be a positive real number. Then


ˆ ˙k
1 k
ln 1 ` „ .
n n
10.1 Asymptotic Equality 241

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

it follows from Proposition 10.5 that


ˆ ˙k
1 k
ln 1 ` “ k lnpn ` 1q ´ k lnpnq „ .
n n
We conclude this section by illustrating how the asymptotic equality can
simplify the calculation of limits.
Proposition 10.8. If f1 „ g1 and f2 „ g2 , then
f1 pnq g1 pnq
lim “ lim
nÑ8 f2 pnq nÑ8 g2 pnq
provided either of these limits exist (the proviso is important!).
Proof. We multiply the limit of f1 {f2 by 1, here written in the form 1 “
pg1 g2 q{pg1 g2 q. This yields
f1 pnq f1 pnq g1 pnq g2 pnq
lim “ lim
nÑ8 f2 pnq nÑ8 g1 pnq g2 pnq f2 pnq
ˆ ˙ˆ ˙ˆ ˙
f1 pnq g1 pnq g2 pnq
“ lim lim lim ,
nÑ8 g1 pnq nÑ8 g2 pnq nÑ8 f2 pnq

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

which proves the claim.


Example 10.9. Let us try to calculate the limit
?
3n15 ` 7n14 ` 8n2 ` ln n
lim ? .
nÑ8 4n15 ` 2n7 ` 2n ln n
Since the numerator and the denominator are both unbounded, we could apply
l’Hôpital’s rule?15 times1 and calculate the limit. observe that 3n15 `
? If we 15
14 2 15 15 7
7n ` 8n ` ln n „ 3n and 4n ` 2n ` 2n ln n „ 4n , then the previous
proposition yields the limit
?
3n15 ` 7n14 ` 8n2 ` ln n 3n15 3
lim ? “ lim “
nÑ8 4n15 ` 2n7 ` 2n ln n nÑ8 4n15 4
in a straightforward fashion.
1 Of course, there are also other ways to solve this problem. Focus on the explanation

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

10.2 Limit Superior and Limit Inferior


The asymptotic equality is sometimes a bit too strict, especially when trying to
work out the asymptotic behavior of sequences that fluctuate between different
values. In this case, it is often better to settle for asymptotic bounds. Before
embarking on the discussion of asymptotic bounds, we recall the notions of
upper and lower limits from calculus. These notions turn out to be useful
when trying to establish asymptotic bounds.

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

uf pnq “ suptf pnq, f pn ` 1q, f pn ` 2q, . . .u,

and the lower envelope  of the function f is defined by

f pnq “ inftf pnq, f pn ` 1q, f pn ` 2q, . . .u.

Example 10.10. Let f pnq denote the function given by


#
2 ` 1{n if n is even,
f pnq “
1 ´ 1{n if n is odd.

Then the upper envelope uf pnq of the function f pnq is given by

uf p1q “ suptf p1q, f p2q, f p3q, . . .u “ f p2q “ 2 ` 1{2,


uf p2q “ suptf p2q, f p3q, f p4q, . . .u “ f p2q “ 2 ` 1{2,
uf p3q “ suptf p3q, f p4q, f p5q, . . .u “ f p4q “ 2 ` 1{4,
uf p4q “ suptf p4q, f p5q, f p6q, . . .u “ f p4q “ 2 ` 1{4, . . .

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

for all positive integers n.


The lower envelope f pnq of the function f pnq is given by

f p1q “ inftf p1q, f p2q, f p3q, . . .u “ f p1q “ 1 ´ 1{1,


f p2q “ inftf p2q, f p3q, f p4q, . . .u “ f p3q “ 1 ´ 1{3,
f p3q “ inftf p3q, f p4q, f p5q, . . .u “ f p3q “ 1 ´ 1{3,
f p4q “ inftf p4q, f p5q, f p6q, . . .u “ f p5q “ 1 ´ 1{5, . . .
244 10 Asymptotic Analysis

The general term of the lower envelope f pnq is given by

1
f pnq “ f p2 tn{2u ` 1q “ 1 ´
2 tn{2u ` 1

for all positive integers n.


Figure 10.1 depicts the function f and its upper and lower envelope.

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

and the limit inferior lim inf nÑ8 f pnq is defined as


´ ¯
lim inf f pnq “ lim inftf 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

Example 10.13. Suppose that f pnq “ n. Then lim supnÑ8 f pnq “ 8.


If the function f approaches ´8 as n Ñ 8, then we define
lim sup f pnq “ ´8.
nÑ8

Example 10.14. Suppose that f pnq “ ´n. Then


uf pnq “ supt´n, ´pn ` 1q, ´pn ` 2q, . . .u “ ´n,
so lim supnÑ8 f pnq “ limnÑ8 uf pnq “ ´8.
Example 10.15. We should stress the limit superior will not be ´8 when
merely a subsequence approaches ´8. Indeed, suppose that
#
0 if n is even,
f pnq “
´n if n is odd.

Then uf pnq “ suptf pnq, f pn ` 1q, f pn ` 2q, . . .u “ 0, so the limit superior


lim sup f pnq “ 0,
nÑ8

even though f p2n ` 1q Ñ ´8 as n Ñ 8.


Similarly, if the function f does not have a lower bound, then the infima
inftf pnq, f pn ` 1q, f pn ` 2q, . . .q “ ´8 for all n, and we define
lim inf f pnq “ ´8.
nÑ8

Example 10.16. Let the function f : N1 Ñ R be given by


#
0 if n is even,
f pnq “
´n if n is odd.

Then lim inf nÑ8 f pnq “ ´8 and lim supnÑ8 f pnq “ 0.


If the function f diverges to `8 as n Ñ 8, then we define
lim inf f pnq “ `8.
nÑ8

Example 10.17. The function f pnq “ n has the limit inferior


lim inf n “ `8.
nÑ8

Example 10.18. If merely a subsequence converges to `8, then the limit


inferior is in general not `8. For instance, the function
#
42 if n is even,
f pnq “
n if n is odd

has the subsequence f p2n ` 1q Ñ 8 as n Ñ 8. However, the limit inferior of


f pnq is given by lim inf nÑ8 f pnq “ 42.
10.2 Limit Superior and Limit Inferior 247

Accumulation Points. We will now give a characterization of the finite


values of the limit superior and limit inferior in terms of accumulation values.
Recall that a real number a is an accumulation value of a function f : N1 Ñ R
if and only if for each real number  ą 0 there exist an infinite number of
function values f pnq such that

|f pnq ´ a| ă .

For example, if the limit  “ limnÑ8 f pnq exists, then  is an accumulation


value of f . If a bounded function f does not have a limit as n Ñ 8, then it
still has accumulation points. For instance, the function f from Example 10.10
has two accumulation points, namely a “ 1 and a “ 2.
Let f be a function from the set of positive integers to the set of real
numbers. The real number u is an upper accumulation point of f if and
only if the following two conditions are met:

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 ` .

Evidently, an upper accumulation point is an accumulation point. If an upper


accumulation point of f exists, then it is unique.
The function f is called bounded above if and only if there exists a real
number u such that f pnq ď u holds for all positive integers n. If f has an
upper accumulation point, then it is bounded above.

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,

lim sup f pnq “ lim uf pnq ą u ` ,


nÑ8 nÑ8
248 10 Asymptotic Analysis

contradicting our assumption. Consequently, for each real number  ą 0


there exist at most finitely many positive integers such that f pnq ą u ` ,
so U2 holds.
(ð). Suppose that u is an upper accumulation point of f . It follows from
U1 that u ´  ď uf pnq. Furthermore, it follows from U2 that there exists
a positive integer n such that uf pkq ď u `  for all k ě n. Therefore, we
can conclude that for all  ą 0, we have

lim sup f pnq “ lim uf pnq P ru ´ , u ` s,


nÑ8 nÑ8

so lim supnÑ8 f pnq “ u.

The limit superior of f can now be characterized as


$
&`8
’ if f is not bounded above,
lim sup f pnq “ u if the upper accumulation point u of f exists,
nÑ8 ’
´8 otherwise.
%

Example 10.20. Let f pnq denote the function given by


#
2 ` 1{n if n is even
f pnq “
1 ´ 1{n if n is odd

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

The real number  is called a lower accumulation point of f if and only


if the following two conditions are met:
L1. For each real number  ą 0, there exist infinitely many positive integers
n such that f pnq ă  ` ,
10.2 Limit Superior and Limit Inferior 249

L2. For each real number  ą 0, there exist at most finitely many positive
integers such that f pnq ă  ´ .

If a lower accumulation point of f exists, then it is unique. Figure 10.3 gives an


example of the lower accumulation point for the function f from Example 10.20.

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.

Proposition 10.21. Let f be a function from the set of positive integers to


the set of real numbers that is bounded below and does not diverge to 8. Then
the real number  is equal to lim inf nÑ8 f pnq if and only if  is the lower
accumulation point of f .

Proof. Since lim inf nÑ8 f pnq “ ´ lim supnÑ8 ´f pnq, the claim is a direct con-
sequence of Proposition 10.19.

As a consequence of the previous proposition, the limit inferior of f can be


characterized as
$
&´8 if f is not bounded below,

lim inf f pnq “  if the lower accumulation point  of f exists,
nÑ8 ’
`8 otherwise.
%

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

(a) f pnq “ p´1qn ,


(b) f pnq “ n1 ,
(c) f pnq “ p1 ` p´1qn qn,
(d) f pnq “ p´1qn p2n ` 1q{pn ` 1q.
10.13. Show that if lim supnÑ8 f pnq “ L and lim inf nÑ8 f pnq “ L, then the
limit limnÑ8 f pnq exists and is equal to L.
10.14. Show that every bounded function f : N1 Ñ R has an accumulation
point. This result is due to Bolzano and Weierstrass.

10.3 Asymptotically Tight Bounds


The asymptotic equality is often a bit too strict. Sometimes it is desirable
to relax the constraints and consider the growth up to a constant factor and
without the need for the existence of a limit. In this section, we discuss so-called
asymptotically tight bounds that provide both upper and lower asymptotic
bounds for a function, yet often allow one to use very simple functions to
describe the growth.
Let f and g denote functions from the set of positive integers to the set of
real numbers. We say that f and g have the same order of growth and write
f — g if and only if there exist positive real constants c and C and a positive
integer n0 such that
c|gpnq| ď |f pnq| ď C|gpnq|
holds for all n ě n0 . The notation f — g goes back to Hardy [34] and is popular
in mathematics. Computer scientists like to express this in the form f P Θpgq,
where
Θpgq “ tf : N1 Ñ R | f — gu
is the set of functions that have the same order of growth as g, see Knuth [47].
If f P Θpgq or f — g, then we also say that g is an asymptotically tight
bound for f .

 In the literature, you will frequently find that f P Θpgq is written in


the form f “ Θpgq. Evidently, a function f cannot be “equal” to a set
Θpgq. In the early days, the notation Θpgq simply meant a given but unspecified
representative of the set Θpgq. Even though Θpgq is now understood as a set,
the notation f “ Θpgq is commonly used instead of the more proper notation
f P Θpgq. You will need to get used to this idiosyncratic notation.

Example 10.22. As a first example, let us consider the function


1 2 12
f pnq “ n ` .
9 10n
1 2
We compare this function with two scalar multiples of n2 , namely 10 n and
1 2
8 n . Then
1 2 1
n ď f pnq ď n2
10 8
10.3 Asymptotically Tight Bounds 251

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.

Figure 10.4: The function f pnq “ 19 n2 ` 10n 12


is shown with dots. The lower bound is
1 2 1 2
given by 10 n and the upper bound by 8 n , both shown with solid graphs even though
1 2
only the values at integer arguments are relevant. The inequality 10 n ď f pnq ď 18 n2
holds for all n ě 5. Therefore, f pnq P Θpn2 q. It is okay that the first few function
values f p1q, f p2q, f p3q, and f p4q are not within the bounds, since the inequality is
required to hold only for large arguments

When we want to prove that f P Θpgq holds, we need to find three constants
n0 , c, and C such that

c|gpnq| ď |f pnq| ď C|gpnq|

holds for all n ě n0 . It can be a bit cumbersome to verify this definition.


The next proposition gives a convenient sufficient condition for establishing
f P Θpgq, but unfortunately it is not always applicable.
Proposition 10.23. Let f and g be functions from the set of positive integers
to the set of real numbers. If g is a positive function and the limit
|f pnq|
d “ lim
nÑ8 |gpnq|
exists and is a nonzero real number d, then f P Θpgq.

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

for all n ě n . In other words, for the constants c “ d ´  and C “ d `  there


exists an n such that c|gpnq| ď |f pnq| ď C|gpnq| holds for all n ě n , which
proves f P Θpgq.

If f and g are asymptotically equal, then the limit of their quotient is 1.


We record this simple observation in the next corollary.

Corollary 10.24. If two functions f and g are asymptotically equal, f „ g,


then they have the same order of growth, so f — g.

Example 10.25. Recall that the expected number of comparisons in random-


ized Quicksort is given by 2pn ` 1qHn ´ 4n. Since Hn „ ln n, it follows that

2pn ` 1qHn ´ 4n 2pn ` 1q ln n ´ 4n


lim “ lim
nÑ8 n ln n nÑ8 n ln n
2n ln n ` 2 ln n ´ 4n
“ lim “ 2.
nÑ8 n ln n
It follows from Proposition 10.23 that the expected number of comparisons of
Quicksort is given by Θpn ln nq. Even though the expression 2pn ` 1qHn ´ 4n
is more exact, it is probably better to use the more straightforward bound
Θpn ln nq when communicating to fellow programmers.

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|

does not exist, as the quotient fluctuates between 3 and 1, but

|gpnq| ď |f pnq| ď 3|gpnq|

holds for all n ě 1; hence, f P Θpgq.

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.

Proposition 10.27. 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
integers to the set of real numbers. Then f P Θpgq if and only if

|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

c :“ lim inf |f pnq|{|gpnq| ą 0 and C :“ lim sup |f pnq|{|gpnq| ă 8.


nÑ8 nÑ8

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.

Example 10.28. On input of a positive integer n, a program executes a block


of code T pnq times, where
#
2n when n is even,
T pnq “
2n`10`plog2 nq{n when n is odd.

We claim that T pnq P Θp2n q. Indeed, let us calculate the limit inferior and
limit superior of T pnq{2n . We have

pT p1q{21 , T p2q{22 , T p3q{23 , . . .q “


p210`log2 p1q , 1, 210`log2 p3q{3 , 1, 210`log2 p5q{5 , 1, 210`log2 p7q{7 , . . .q.

In other words, the quotient T pnq{2n “ 1 when n is even and T pnq{2n “


210`plog2 nq{n when n is odd. Therefore, we get
T pnq T pnq
lim inf “ 1 and lim sup “ 210 .
nÑ8 2n nÑ8 2n
Since the limit inferior and the limit superior are both positive real numbers,
it follows from Proposition 10.27 that T pnq P Θp2n q.
A characteristic of an asymptotically tight bound f P Θpgq is that f pnq
cannot fluctuate too much in comparison to gpnq. In general, we want to keep
the functions g simple. For instance, gpnq “ nk for some positive integer k,
gpnq “ bn for some positive integer b, or similar elementary functions. A given
function f might not be as nicely behaved as the simple functions that we use
for comparison. Then we might be forced to use separate simple functions as
upper and lower asymptotic bounds. We describe the appropriate asymptotic
bounds in the next sections.
254 10 Asymptotic Analysis

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

10.20. Show that for all positive integers k, we have

1k ` 2k ` ¨ ¨ ¨ ` nk “ Θpnk`1 q.

10.4 Asymptotic Upper Bounds


The asymptotic equality and asymptotic tight bounds classify functions of sim-
ilar growth. In this and the next section, we are concerned with relating func-
tions of different growths.
Let f and g be functions from the set of positive integers to the set of real
numbers. We say that g is an asymptotic upper bound for f and write
f P Opgq if and only if there exists a positive real constant C and a positive
integer n0 such that
|f pnq| ď C|gpnq|
holds for all n ě n0 .
We denote by Opgq the set of all functions f : N1 Ñ R such that g is an
asymptotic upper bound for f .

 The relation f P Opgq is often written as f “ Opgq in the literature.


Even worse, subset relations such as Opnq Ď Opn2 q are often denoted
as Opnq “ Opn2 q. These idiosyncratic notations are here to stay, so you need
to get used to them. If you read statements in the literature such as ln n “
Opnq “ Opn2 q, simply translate the equalities into the usual “element of” and
“subset relations”, such as ln n P Opnq Ď Opn2 q.
10.4 Asymptotic Upper Bounds 255

The asymptotic upper bound relation f P Opgq allows us to compare the


growth of functions for large arguments n. Figure 10.5 shows the graphs of
three functions. While it is possible to gain some insights into the growth of
functions, it is easy to be misled by such graphs, as they show the values for
the functions for some sets of small values of n. Yet the asymptotic upper
bound is concerned with the behavior of the functions at large values of their
arguments. For this reason, it is preferable to give a proof for the bounds.

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

Example 10.29. We have n P Opn2 q. Indeed, for all integers n ě 1, multi-


plying both sides by n yields n ď n2 . Therefore, we have

|n| ď 1|n2 |.

for all n ě 1. The same argument shows that |n| ď 1| ´ n2 |, so n P Op´n2 q.


For positive functions, there is no need to use absolute values.

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.

The next proposition gives a convenient necessary and sufficient condition


to establish an asymptotic upper bound f P Opgq.
256 10 Asymptotic Analysis

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|

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|

exists and is finite, then f P Opgq.

Example 10.33. Let us consider the functions ln n and n. We claim that


ln n P Opnq. Since both ln n Ñ 8 and n Ñ 8 as n Ñ 8, we can use l’Hôpital’s
rule to deduce that
ln n 1
lim “ lim “ 0.
nÑ8 n nÑ8 n

Therefore, it follows from Corollary 10.32 that ln n P Opnq, as claimed.

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|

holds for all n ě n . By definition, f P opgq implies that f P Opgq.


If f P opgq, then f is asymptotically much smaller than g. This property is
nicely explained by the next proposition.

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|

holds for all n ě n . In other words, (10.11) is equivalent to f P opgq.


258 10 Asymptotic Analysis

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|

10.24. Prove the idempotency rule given by Eq. (10.4).


10.25. Prove the multiplication rules (10.5) and (10.6).
10.26. Prove the absorption rule (10.7) and the power rule (10.8).
10.27. Prove the linear combination rule given in (10.9).
10.28. Prove the rule (10.10).
10.29. Find at least five examples of an erroneous usage of the Big Oh notation
in recent papers or books of Computer Science.
10.30. Suppose that ppnq “ a0 ` a1 n ` ¨ ¨ ¨ ` am nm is a polynomial of degree
m with complex coefficients. Show that ppnq “ Opnk q for all k ě m, and
ppnq ‰ Opn q for 0 ď  ă m.
10.31. Show that for fixed k, we have
nk nk
ˆ ˙ ˆ ˙
n k´1 n`k
P ` Opn q and P ` Opnk´1 q,
k k! k k!
where nk “ npn ´ 1qpn ´ 2q ¨ ¨ ¨ pn ´ k ` 1q{k! is the binomial coefficient.
` ˘
10.5 Asymptotic Lower Bounds 259

10.32. Show that n{pn ` 1q P 1 ` Op1{nq.


10.33. Let f, g, and h be functions from the set of positive integers to the set
of real numbers. We write f ĺ g if and only if f P Opgq. Show that
(i) f ĺ f
(ii) f ĺ g and g ĺ h implies f ĺ h
(iii) there exist functions f and g such that neither f ĺ g nor g ĺ f holds.
In the language of set theory, properties (i) and (ii) mean that ĺ is a preorder.
The third property shows that the asymptotic growth of functions is not always
comparable.
10.34. Prove or disprove: en P Op2n q.
2
10.35. Prove or disprove: nln n P Opepln nq q.
10.36. Show that f P Opgq and f R opgq does not imply that f P Θpgq.
10.37. Show that f pxq P gpxq ` Op1q implies that exppf pxqq — exppgpxqq.

10.5 Asymptotic Lower Bounds


In this section, we define asymptotic lower bounds, which complement the
notions that we have defined in the previous section.
Let f and g be functions from the set of positive integers to the set of
real numbers. We say that g is an asymptotic lower bound to f and write
f P Ωpgq if and only if there exists a positive constant c and a positive integer
n0 such that
c|gpnq| ď |f pnq|
holds for all n ě n0 . This formalizes the notion that f pnq grows at least as fast
as a constant multiple of gpnq for large n.
This asymptotic lower bound is related to the asymptotic upper bound in
the following way.
Proposition 10.37. Let f and g be functions from the set of positive integers
to the set of real numbers. We have f P Ωpgq if and only if g P Opf q.
Proof. We have f P Ωpgq if and only if there exists a positive constant c and
a positive integer n0 such that c|gpnq| ď |f pnq| holds for all n ě n0 . Dividing
both sides by c shows that there exist a positive constant C “ 1{c and a positive
integer n0 such that |gpnq| ď 1c |f pnq| “ C|f pnq| holds for all n ě n0 . However,
this is nothing but the definition of g P Opf q.
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 lower bound to f and write
f P ωpgq if and only if for all positive constants c there exists a positive integer
n0 such that
c|gpnq| ď |f pnq|
holds for all n ě n0 .
260 10 Asymptotic Analysis

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|

which proves the claim.

10.6 Analysis of Algorithms


In this section, we will give a brief exposition of the analysis of algorithms.
The purpose of the analysis is to get some insights into the running time or the
space requirements of the computation. Since too many details of the compiler
and computer architecture affect the precise time or space requirements, one
has to settle for the more modest goal of obtaining reasonable bounds on these
quantities. We will focus on the analysis of the running time of an algorithm.
Since we are settling for bounds on the running time rather than a precise
estimate, we can use a simplified model of computation such as the random
access machine. A random access machine is a very simple single-processor
machine that executes instructions one after another without pipelining, spec-
ulative execution, branch prediction, or parallelism. It even lacks a memory
hierarchy. We could now precisely define the instructions of the random access
machine and their costs, as in Aho, Hopcroft, and Ullman [1]. However, we
follow the approach taken in Cormen, Leiserson, Rivest, and Stein [16] and
assume that elementary operations take a constant—yet unspecified—amount
of time. Then there is no need to translate the pseudocode into random access
machine instructions, which simplifies matters.
The running time of an algorithm is measured as a function of the size of
the input. What is the size of the input? Unfortunately, the answer to this
question depends on the application. We assume that we are given a function
s that associates to an input x its size spxq. For instance, if the input to a
sorting algorithm is an array x with n elements, then spxq “ n would be a
natural measure for the size of the input. If the input x is an integer, then
spxq “ tlog10 xu`1 may be a good measure of input size for algorithms that deal
10.6 Analysis of Algorithms 261

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

sup ttA pxq | x P I, spxq “ nu.

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.

A1. Elementary operations have constant running time.

Examples of elementary operations include assignments, arithmetic with ma-


chine size words, Boolean operations, comparisons, and array access, among
others. The axiom says that they all have Θp1q running time.
The running time of a compound statement is bounded by the sum of the
running times of the individual component statements.

A2. If the statements S1 and S2 respectively have worst-case running time


T pS1 q and T pS2 q on an input of size n, then the compound statement
S1 ; S2 has worst-case running time

T pS1 ; S2 q ď T pS1 q ` T pS2 q

The next axiom gives a coarse-grained view of the running-time of a condi-


tional statement. We should add that sometimes it makes sense to distinguish
cases depending on the value of the condition C.

A3. The conditional statement

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

A4. The running-time of a for-loop statement S given by

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

T pSq ď pb ´ a ` 1qΘpT pS1 qq ` pb ´ a ` 2qc.

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

ppxq “ p¨ ¨ ¨ ppan x ` an´1 qx ` an´2 qx ` ¨ ¨ ¨ a1 qx ` a0 .

The following algorithm is based on the Horner scheme:


10.6 Analysis of Algorithms 263

horner(a, n, x) cost times


res = a[n] c1 1
for k = n´1 down to 0 do c2 n+1
res = res * x + a[k] c3 n
end c4 n
return res c5 1
end c6 1

The worst-case running time of the algorithm is given by

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).

// search a key in an array a[1..n] of length n


search(a, n, key) cost times
for k in (1..n) do
if a[k]=key then
return k
end
return false

Determine the worst-case complexity of this algorithm.

10.39. Analyze the running time of the following algorithm using a step count
analysis (as in the Horner scheme).

// determine the number of digits of an integer num


binary digits(num) cost times
int cnt = 1
while (numą1) do
cnt = cnt + 1
num = floor(num/2.0)
end
return cnt

(a) Give an axiom for the running time of a while loop.


(b) Determine the asymptotic running-time of this algorithm.

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?

— Anonymous, In: The Oxford Dictionary of Nursery Rhymes

Enumerative combinatorics is concerned with counting the number of combi-


natorial objects such as permutations, combinations, multisets, partitions of
sets, partitions of numbers, and the like. The counting techniques are simple
but are often applied in a skillful way to great effect. The very large num-
ber of applications of enumerative combinatorics in computer science led to a
resurgence of the field.

11.1 Fundamental Counting Principles


In combinatorics, one does not count the number of objects by listing them,
but rather by using an abstract method to determine their number. The basic
principles are simple, but choosing the correct approach can be a challenge at
times.
We begin with a simple counting principle that is inspired by set theory.
Recall that if we are given two sets A and B, then the cardinality of their union
satisfies
|A Y B| “ |A| ` |B| ´ |A X B|.
If A and B are disjoint sets, then the term |A X B| “ 0 and can be omitted.
The next principle is a straightforward generalization of this simple case.

© The Author(s), under exclusive license to Springer Nature 267


Switzerland AG 2025
A. Klappenecker, H. Lee, Discrete Structures, Undergraduate Texts in
Mathematics, https://doi.org/10.1007/978-3-031-73434-2 11
268 11 Counting

Summation Principle If a finite set S is the union of m pair-


m
ÿ
wise disjoint sets S1 , S2 , . . . , Sm , then |S| “ |Sk |.
k“1

We can rephrase the summation principle as follows. If there are m mutually


exclusive tasks and the k-th task can be done in nk different ways, then the
number of ways to do one of these tasks is given by

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

x77777, 7x7777, 77x777, 777x77, 7777x7, 77777x,

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.

Multiplication Principle I If a finite set S is the Cartesian


m
ź
product S “ S1 ˆ S2 ˆ ¨ ¨ ¨ ˆ Sm of m sets, then |S| “ |Sk |.
k“1

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.

Sometimes we need to consider dependencies among the choices. The se-


lection for the first task might influence the choices for the second task. For
instance, if we select Amy to be the winner of a science fair, then the runner
up should be one of the other students. If we select Bert to be the winner, then
the runner up should be someone other than Bert. However, if the number of
choices remains the same for each selection, then the multiplication principle
still holds in this more general situation.

Multiplication Principle II Let S denote a set consisting of


sequences ps1 , s2 , . . . , sm q that are constructed as follows. There
are n1 different ways to choose s1 . For each k in the range
1 ď k ă m, after having chosen s1 , s2 , . . . , sk , there are precisely
nk`1 choices for the sequence element sk`1 . Then the number
|S| of such sequences is given by

|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

tpepperoni, olives, mushroomsu,

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.

In many counting problems, the solution may require a combination of the


multiplication and summation principles, as the next two examples show.

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

Subtraction Principle Let S be a finite set with a subset T .


Then |S z T | “ |S| ´ |T |.

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

100 ´ t100{6u “ 100 ´ 16 “ 84.

The subtraction method led to a straightforward solution.


Example 11.10. How many integers x P t1, 2, . . . , 1000u have at least two
different digits? We will use the subtraction principle. Therefore, we need to
determine how many integers in the set S “ t1, 2, . . . , 1000u have all digits
equal to the same value? The set T of all such integers is given by

T “ t1, 2, . . . , 9, 11, 22, . . . , 99, 111, 222, . . . , 999u,

so there are |T | “ 27. Therefore, |S z T | “ |S| ´ |T | “ 1000 ´ 27 “ 973 integers


have at least two different digits.

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

way to evaluate this geometric series?


272 11 Counting

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

11.2 Permutations and Combinations


In this section, we introduce partial permutations and combinations. The
counting coefficients for the number of partial permutations and combinations
are helpful when solving counting problems. We identify the binomial coeffi-
cients as the counting coefficients of combinations. The combinatorial inter-
pretation of binomial coefficients has many interesting consequences that are
explored in the subsequent sections.
Let S be a finite set with n elements. Recall that a bijective function on
S is also called a permutation. If S “ t1, 2, 3u, then there are six different
permutations, namely
ˆ ˙ ˆ ˙ ˆ ˙
1 2 3 1 2 3 1 2 3
, , ,
1 2 3 2 1 3 3 2 1
ˆ ˙ ˆ ˙ ˆ ˙
1 2 3 1 2 3 1 2 3
, , .
1 3 2 2 3 1 3 1 2
The set of all permutations on a set with n elements is denoted by Sn . We
have |Sn | “ n!, as we will prove shortly.
We can generalize the concept of a permutation as follows. An injective
function from a set with k elements to a set S with n elements is called a
k-permutation. In other words, a k-permutation is a partial permutation. If
S “ ta, b, cu, then all 2-permutations are given by
ˆ ˙ ˆ ˙ ˆ ˙ ˆ ˙ ˆ ˙ ˆ ˙
1 2 1 2 1 2 1 2 1 2 1 2
, , , , , .
a b a c b a b c c a c b

It is common to identify the injective functions with ordered sequences that


simply list the images. In this interpretation, the six 2-permutations of the set
S “ ta, b, cu are given by

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.

We denote by P pn, kq the number of k-permutations. The next proposition


shows that the answer can be easily formulated in terms of the falling factorial

nk “ npn ´ 1q ¨ ¨ ¨ pn ´ k ` 1q,

where n0 “ 1.

Proposition 11.12. The number of k-permutations of a set with n elements


is given by
n!
P pn, kq “ nk “ .
pn ´ kq!

Proof. We prove the claim by induction on k. For k “ 0, there exists just a


single k-permutation, namely the empty sequence. So the claim P pn, 0q “ 1 “
n0 is correct.
Suppose that the claim holds for P pn, k ´ 1q. A pk ´ 1q-permutation of a
set with n elements can be extended to a k-permutation by selecting one of
the n ´ pk ´ 1q elements of S that do not yet occur in the sequence. By the
multiplication principle,

P pn, kq “ P pn, k ´ 1qpn ´ k ` 1q “ nk´1 pn ´ k ` 1q “ nk ,

as claimed.

In a k-permutation, the order of the selected k elements matters. If we


want to ignore the order, then we arrive at the notion of a k-combination.
Specifically, a k-combination of a finite set S with n elements is a subset of
S of cardinality k. For instance, the set S “ ta, b, cu has the following three
2-combinations
ta, bu, ta, cu, tb, cu.
We denote by Cpn, kq the number of k-combinations of a set with n ele-
ments. Since any k-permutation can be obtained by ordering a k-combination,
and there exist k! different ways to order a set of k elements, we have

P pn, kq “ k!Cpn, kq.

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

Proposition 11.13. The number of k-combination of a set with n elements is


given by
ˆ ˙
n
Cpn, kq “ .
k

Proof. Since k!Cpn, kq “ P pn, kq and P pn, kq “ nk , we can deduce that

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.22. A student organization consists of 20 students of mathematics and 30


students of engineering. They need to select two students of mathematics and
three students of engineering to help at a middle school science fair. In how
many different ways can they select the students for this task?

11.23. Let S be a set of n distinct points on a circle. How many different


nondegenerate triangles can be formed from these points?
276 11 Counting

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?

11.3 Combinatorial Proofs


In the previous section, we learned that the number of subsets with k elements
of a set with n elements are counted by the binomial coefficient
ˆ ˙
n
.
k

This combinatorial interpretation suggests to use a combinatorial argument


for proofs. A combinatorial argument establishes an equality A “ B of two
formulas either by the bijection principle or by double counting. In this section,
we will explain both proof principles.
The idea underlying the bijection principle is simple. The bijection principle
finds a set S such that A “ |S| and a set T such that B “ |T |. If a bijection
can be established between the sets S and T , then A “ B is proved.

Bijection Principle If S and T are finite sets and there exists


a bijection from S onto T , then |S| “ |T |.

At first glance, the bijection principle might appear to be almost frivolous.


However, finding an appropriate bijection to solve a counting problem can lead
to insightful proofs. The next example gives a first taste.

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

P “ tpa, c, k, pq | 0 ď a, c, k, p ď 10, a ` c ` k ` p “ 10u.

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

that consists of a initial zeros, followed by a 1, then c zeros, followed by a 1, k


zeros, followed by a 1, and finally, p zeros. As every string in B is 13 bits long
and contains three 1s, there must be 10 zeros. Evidently, this is a bijection
from P onto B. While ` it˘ might not have been obvious how to count P , it is
clear that B contains 13 3 bit strings, as these are the number of ways to choose
the positions of the three bits equal to 1. By the bijection principle, there are
ˆ ˙
13
|P | “ |B| “ “ 286
3
different ways to order 10 pies from a selection of four different kinds of pies.
In the algebraic definition of binomial coefficients, it is not too difficult to
arrive at the equality ˆ ˙ ˆ ˙
n n
“ .
k n´k
In the combinatorial interpretation of binomial coefficients, this equality claims
that the number of ways to select subsets with k elements from a set with n
elements is equal to the number of ways to select subsets with n ´ k elements
from a set with n elements. The proof of the next proposition shows how to
use the bijection principle to establish this fact.
Proposition 11.15. Let n be a nonnegative integer and k an integer in the
range 0 ď k ď n. Then ˆ ˙ ˆ ˙
n n
“ .
k n´k
Proof. Let S be a set with n elements. Let Fk “ tK|K Ď S and |K| “ ku
denote the set of subsets of S that have cardinality k and Fn´k the set of
subsets of S that have cardinality n ´ k. Since the complement Ac of a set A
with k elements has n ´ k elements, and pAc qc “ A, taking the complement
maps Fk bijectively` onto Fn´k . Therefore, |Fk | “ |Fn´k |. The claim follows
from the fact that nk “ |Fk | and n´k
˘ ` n ˘
“ |Fn´k |.

The next counting principle is even more straightforward. Given a set, if


one way to count its elements yields A, and another way to count its elements
yields B, then we must have A “ B.

Double Counting If two formulas count the elements of the


same set in two different ways, then they must be equal.
278 11 Counting

The next example illustrates the double counting technique.


Example 11.16. Suppose that we want to prove the equation
n
ÿ npn ` 1q
k“ .
k“1
2

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

Subtracting pn ` 1q from both sides and dividing by 2 yields


n
ÿ pn ` 1q2 ´ pn ` 1q npn ` 1q
k“ “ ,
k“1
2 2

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

In the next proposition, we illustrate the double counting principle by count-


ing the elements of the power set of a set with n elements in two different ways.
Proposition 11.17. The sum of the binomial coefficients
n ˆ ˙
ÿ n
“ 2n .
k“0
k

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

counts the number of elements in P pSq according to their cardinality k.


Each of the n elements of S can be either included in or excluded from a
subset, so there are two choices per element. There are 2n choices overall by the
product rule. Therefore, we have a total of 2n subsets of S, so |P pSq| “ 2n .

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

Proof. If we expand the left-hand side, we get a product of n terms

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

px ` yq3 “ px ` yqpx ` yqpx ` yq

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

collecting terms with like x-exponents yields


ˆ ˙ ˆ ˙ ˆ ˙ ˆ ˙
3 2 2 3 3 3 3 2 3 2 3 3
x ` 3x y ` 3xy ` y “ x ` x y` xy ` y .
3 2 1 0

The following important special case is obtained by setting y “ 1 in the


binomial theorem.2
Corollary 11.19. For all nonnegative integers n, we have
n ˆ ˙
n
ÿ n k
px ` 1q “ x .
k“0
k

Binomial coefficients are used in a myriad number of expressions. Let us


collect some of the simplest consequences of the binomial theorem. If we sub-
stitute x “ 1 and y “ 1 in the binomial theorem, then we obtain yet another
proof of the following fact
n ˆ ˙
n n
ÿ n
2 “ p1 ` 1q “ .
k“0
k

Substituting x “ ´1 and y “ 1 in the binomial theorem reveals that binomial


coefficients with alternating signs sum to 0, since
n ˆ ˙
k n
ÿ
n
0 “ p´1 ` 1q “ p´1q .
k“0
k

Substituting x “ 2 and y “ 1 in the binomial theorem yields


n ˆ ˙
ÿ n k
3n “ p2 ` 1qn “ 2 .
k“0
k

Proposition 11.20 (Vandermonde’s Identity). For nonnegative integers m,


n, and k, we have
ˆ ˙ ÿ k ˆ ˙ˆ ˙
m`n m n
“ .
k i“0
i k´i

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

counts all subsets of size k from S Y T .

Proposition 11.21 (Pascal’s Identity). The recurrence


ˆ ˙ ˆ ˙ ˆ ˙
n n´1 n´1
“ `
k k k´1

holds for all k in the range 1 ď k ď n.

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.
` ˘

Let x denote a fixed element of S. The subsets of S with k elements either


contain the element x `or do ˘ not contain this element. If we include x in the
subset, then there are n´1 k´1 ways to choose the remaining elements. If we do
`n´1˘
not include the element x, then there are k ways to choose k elements from
the remaining n ´ 1 elements of S.
Comparing these two ways of counting the k-subsets of S, we can conclude
that ˆ ˙ ˆ ˙ ˆ ˙
n n´1 n´1
“ ` ,
k k´1 k
as claimed.

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

(a) using the definition of the binomial coefficients


(b) using a combinatorial proof (count the number of ways to choose a team
of fixed size and their team captain).
11.28. Prove the subset of a subset identity
ˆ ˙ˆ ˙ ˆ ˙ˆ ˙
n m n n´k
“ .
m k k m´k

(a) using the definition of the binomial coefficients,


(b) using a combinatorial proof.
11.29. Prove thatˆ ˙
n
ÿ n
(a) Epnq “ “ 2n´1 ,
k“0
k
k even
n ˆ ˙
ÿ n
(b) Opnq “ “ 2n´1 .
k“0
k
k odd
holds for all n ě 1.
11.30. Show that
n ˆ ˙
ÿ n
k “ n2n´1
k“1
k
holds. [Hint: Use the absorption identity.]
11.3 Combinatorial Proofs 283

11.31. Let n be a positive odd integer. Show that


pn´1q{2
ÿ ˆ ˙
n
“ 2n´1 .
k“0
k

11.32. Deduce Pascal’s identity


ˆ ˙ ˆ ˙ ˆ ˙
n n´1 n´1
“ `
k k k´1

from Vandermonde’s identity.

11.33. Show that ˆ ˙ n ˆ ˙2


2n ÿ n
“ .
n k“0
k

11.34. Show that the n-th row of Pascal’s triangle satisfies


ˆ ˙ ˆ ˙ ˆ ˙ ˆ ˙ ˆ ˙ ˆ ˙
n n n n n n
ă ă ¨¨¨ ă “ ą ¨¨¨ ą ą .
0 1 tn{2u rn{2s n´1 n

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.

11.35. Show that


nn
ˆ ˙
n
ď
k pn ´ kqn´k k k
holds for all integers k in the range 0 ď k ď n.
? ` ˘n
11.36. Deduce from Stirling’s approximation n! „ 2πn ne the following
asymptotic estimate of the central binomial coefficient

2n`1
ˆ ˙
n
„?
n{2 2πn

for even n.

11.37. Let n be a nonnegative integer and m an integer in the range 0 ď m ď n.


Show that
m ˆ ˙ ´ en ¯m
ÿ n
ď .
k“0
k m
xk
ř8
[Hint: Recall that for all real numbers x, we have exppxq “ k“0 k! . Therefore,
řm k
em “ exppmq ě k“0 mk! .]
284 11 Counting

11.4 Selections with Repetitions


In Sect. 11.2, we discussed the enumeration of k distinct elements from a set S
with n elements (using k-permutations for ordered selections and k-combina-
tions for unordered selections). In this section, we will discuss the ordered and
unordered selection of k elements from S that do not need to be distinct.

Ordered Selection with Repetition. Let K “ t1, 2, . . . , ku and S a set


with n elements. An ordered k-selection with repetition over a set S with
n elements is a function f : K Ñ S.
The definition is easily understood by comparing it with k-permutations.
Recall that a k-permutation over S is an injective function from K to S. Since
we now want to allow repetitions, we give up injectivity and consider a function
from K to S.
If we fix the natural order 1 ă 2 ă ¨ ¨ ¨ ă k on K, then we can identify a
function f : K Ñ S with the sequence

s “ pf p1q, f p2q, . . . , f pkqq.

Since the sequence contains all function values of f on K, we can recover f


from the sequence. We will use a function f and its corresponding sequence s
interchangeably when studying ordered k-selections with repetitions.

Example 11.22. The functions from K “ t1, 2u to S “ ta, b, cu yield the


sequences

pa, aq, pa, bq, pa, cq, pb, aq, pb, bq, pb, cq, pc, aq, pc, bq, pc, cq.

A sequence px1 , x2 q corresponds to the function f : K Ñ S with f p1q “ x1 and


f p2q “ x2 , so functions and ordered sequences are in one-to-one correspon-
dence.

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 .

Proof. For an argument x P K, there are n possible images. By the product


rule, we get a total of nk different functions.

Unordered Selection with Repetition. We will now turn to the more


challenging problem of counting the number of unordered selections with k
elements from a set of n elements with repetitions allowed.
11.4 Selections with Repetitions 285

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.

In the previous example, we used the concept of a multiset. A multiset


is a generalization of the concept of a set, where the order of the elements
does not matter (as in the case of sets), but each element can occur multiple
times. For instance, M “ ta, a, b, c, c, cu is a multiset that contains the element
a twice, the element b once, and the element c three times. The multiset M
coincides with ta, b, c, a, c, cu but differs from ta, b, cu. The number of elements
of a multiset is the sum of the multiplicities of its elements, so M contains
6 “ 2 ` 1 ` 3 elements.
An unordered k-selection with repetitions over a set S with n elements
is a multiset with k elements from S. The number M pn, kq of unordered k-
selections with repetitions is determined in the next proposition.

Proposition 11.25. The number M pn, kq of multisets with k elements taken


from a set with n elements is given by
ˆ ˙
n`k´1
M pn, kq “ .
k

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

σpT q “ tm1 , m2 ` 1, . . . , mk ` k ´ 1u.

Adding j ´ 1 to mj ensures that m1 ă m2 ` 1 ă ¨ ¨ ¨ ă mk ` k ´ 1, so σpT q is


a set with k distinct elements.
The map σ is injective and surjective. Indeed, we note that its inverse
function σ ´1 : B Ñ A is given by

σ ´1 ptn1 , n2 , . . . , nk uq “ tn1 , n2 ´ 1, n3 ´ 2, . . . , nk ´ pk ´ 1qu,

where n1 ă n2 ă . . . ă nk . Therefore, |A| “ |B|.


286 11 Counting

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.

Permutations of Multisets. Let M be a multiset that contains element


a1 with multiplicity m1 , element a2 with multiplicity m2 , . . ., and element
an with multiplicity mn . Thus, counting all repetitions, the multiset contains
m “ m1 ` m2 ` ¨ ¨ ¨ ` mn elements.
We can rearrange the elements of M in m! ways, but not all permutations
can be distinguished. Indeed, we can permute the elements ak among them-
selves in mk ! different ways, but the rearrangements are not distinguishable.
The number of multiset permutations of M that can be distinguished is given
by the multinomial coefficient
ˆ ˙
m m!
“ .
m 1 , m2 , . . . , m n m1 !m2 ! ¨ ¨ ¨ mn !
Let us have a look at an example.
Example 11.27. Suppose that we have 3 blue tokens, 2 green tokens, and 4
red tokens. We want to line up the tokens in a single row and count in how
many ways we can rearrange these three different types of tokens. Abstractly,
we can model the tokens as elements of the multiset M “ tb, b, b, g, g, r, r, r, ru.
Although there are 9! “ 362880 different ways to arrange these nine tokens in
a row, we can merely distinguish
ˆ ˙
9 9! 362880
“ “ “ 1260
3, 2, 4 3!2!4! 6 ˆ 2 ˆ 24
11.4 Selections with Repetitions 287

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.

Example 11.28. Consider the variables x1 , x2 , and x3 . Expanding the ex-


pression px1 ` x2 ` x3 q4 in product form yields

px1 ` x2 ` x3 qpx1 ` x2 ` x3 qpx1 ` x2 ` x3 qpx1 ` x2 ` x3 q.

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 .

By expanding the more general term px1 ` x2 ` ¨ ¨ ¨ ` xm qn , we can obtain


the multinomial theorem.

Proposition 11.29 (Multinomial Theorem). For positive integers n and m,


and variables x1 , x2 , . . . , xm , we have
ˆ ˙
ÿ n
px1 ` x2 ` ¨ ¨ ¨ ` xm q “ n
xn1 1 xn2 2 ¨ ¨ ¨ xnmm .
n `n `¨¨¨`n “n
n1 , n2 , . . . , n m
1 2 m

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

11.39. Determine the coefficient of x2 y 3 z 4 of p3x ´ 2y ` 4zq9 .


11.40. Prove that for all positive integers n and all nonnegative integers
n1 , . . . , nm `such that ˘n1 ` ¨ ¨ ¨ ` nm “ n, one can express the multinomial
coefficient n1 ,n2n,...,nm as a product of binomial coefficients as follows:
ˆ ˙ ˆ ˙ˆ ˙ˆ ˙ ˆ řm´1 ˙
n n n ´ n1 n ´ n1 ´ n2 n ´ k“1 nk
“ ¨¨¨ .
n1 , n2 , . . . , nm n1 n2 n3 nm
11.41. Prove that for all positive integers n and all nonnegative integers
n1 , . . . , nm such that n1 ` ¨ ¨ ¨ ` nm “ n, the following generalization of Pascal’s
identity
ˆ ˙ m ˆ ˙
n ÿ n´1

n1 , n2 , . . . , nm k“1
n1 , . . . , nk´1 , nk ´ 1, nk`1 , . . . , nm

holds. [Hint: Use the multinomial theorem in two different ways.]


11.42. We can use the multinomial theorem to give another proof of Fer-
mat’s Little Theorem. Recall that Fermat’s Little Theorem asserts that np ”
n pmod pq holds for all integers n and all primes p.
(a) Let p be a prime and p1 , p2 , . . . , pn nonnegative integers such that p1 ` p2 `
¨ ¨ ¨ ` pn “ p. When is the multinomial coefficient
ˆ ˙
p
,
p 1 , p2 , . . . , p n
divisible by p? What is the value of this multinomial coefficient modulo p,
when the multinomial coefficient is not divisible by p?
(b) Let p be a prime and n an integer. Show that

np ” p1 ` 1 ` ¨ ¨ ¨ ` 1qp ” p1 ` 1 ` ¨ ¨ ¨ ` 1q ” n pmod pq,

where each sum of 1s consists of n terms.

11.5 Set Partitions


The number of partitions of a set S with n elements into k nonempty parts is
denoted by " *
n
.
k
Furthermore, we define
" * " * " *
0 k 0
“ 1 and “ “0
0 0 k
for all integers k ą 0.
We illustrate the definition with a small example.
11.5 Set Partitions 289

Example 11.30. We have 42 “ 7, since all the partitions of S “ t1, 2, 3, 4u


(

into two nonempty parts are given by

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

Proof. Let S be a set with n elements. We fix an element x P S. The number of


partitions in which
 txu( is a singleton block in a partition of S with k nonempty
parts is given by n´1
k´1 .
The number of partitions ( in which x is part of block with more than one
element is given by k n´1

k , since we can take any partition of Sztxu with k
nonempty parts and add x to any of the k blocks of the partition.
Therefore, we can conclude that the number of partitions nk of a set with
 (

n elements into k nonempty parts can be also expressed as n´1


 ( n´1(
k´1 `k 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

holds for all positive integers k.


The number of set partitions nk of a set with n elements into k nonempty
 (

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

Proposition 11.34. For all nonnegative integers n and k, we have


" *
n
Spn, kq “ .
k

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
(  (

for all integers k ą 0. Thus, the claim P pnq holds for n “ 0.


Inductive Step For all positive integers n, we will show that P pn ´ 1q implies
P pnq. Assuming that P pn´1q holds means that the equality Spn´1, kq “ n´1
 (
k
holds for all nonnegative integers k. It follows that
" * " * " *
n n´1 n
Spn, kq “ Spn ´ 1, k ´ 1q ` kpn ´ 1, kq “ `k “
k´1 k k

holds for all positive integersk.( Since Spn, 0q “ 0 “ n0 holds for n ą 0, we


 (

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
 (

argument (in other words, by counting suitable sets).

11.44. Determine the number of equivalence classes on a set with n elements.

11.45. Show that " * n´1


ÿ ˆn ´ 1˙" i *
n
“ .
k i“k´1
i k´1

[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.]

11.6 The Inclusion-Exclusion Principle


Given a finite set S and properties P1 , . . . , Pm that its elements may or may not
have, it is often an interesting question to determine how many elements of S do
not have any of the m properties. If we denote by Sk the subset of S comprising
all elements that satisfy property Pk , that is, Sk “ tx P S | x has property Pk u,
11.6 The Inclusion-Exclusion Principle 291

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

Since |S1 Y S2 | “ |S1 | ` |S2 | ´ |S1 X S2 |, we have

|SzpS1 Y S2 q| “ |S| ´ |S1 Y S2 | “ |S| ´ |S1 | ´ |S2 | ` |S1 X S2 |.

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

|SzpS1 Y S2 q| “ |S| ´ |S1 | ´ |S2 | ` |S1 X S2 |

gives the correct number of elements of the set.


It might not be immediately obvious why the inclusion-exclusion formula
can be attractive. Therefore, we offer a simple example that we will generalize
later.

Example 11.35. Suppose that we want to determine the number of integers


k in the range 1 ď k ď n for n “ 20 “ 22 5 that are not divisible by the prime
factors 2 and 5. Let S “ t1, 2, . . . , 20u, P1 be the property of being divisible
by 2, and P2 the property of being divisible by 5. Then

S1 “ tx P S | x is divisible by 2u “ t2x | 1 ď x ď 10u


292 11 Counting

is a set with |S1 | “ 10 elements and

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

|SzpS1 Y S2 q| “ |S| ´ |S1 | ´ |S2 | ` |S1 X S2 | “ 20 ´ 10 ´ 4 ` 2 “ 8.

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.

Theorem 11.36 (Inclusion-Exclusion Formula). Let S be a finite set with m


pairwise different subsets S1 , S2 , . . . , Sm . Then
ˇ ˇ
ˇ m
ď ˇ ÿ
ˇS z Sk ˇ “ p´1q|I| |SI |.
ˇ ˇ
ˇ ˇ
k“1 IĎt1,2,...,mu

Proof. For a subset T of S, we denote by IT the indicator function of T ,


meaning that IT pxq “ 1 for x P T and IT pxq “ 0 for x P SzT . Then
ˇ ˇ
ˇ ďm ˇ ÿ ź m
S z S “ p1 ´ ISk pxqq.
ˇ ˇ
ˇ kˇ
ˇ ˇ xPS
k“1 k“1

We can expand the right-hand side in the form


ˇ ˇ
ˇ m
ď ˇ ÿ ÿ ź ÿ
ˇS z Sk ˇ “ p´1q|I| ISk pxq “ p´1q|I| |SI |,
ˇ ˇ
ˇ ˇ xPS
k“1 IĎt1,...,mu kPI IĎt1,...,mu
ś
where weŞused the fact that kPI ISk pxq is the characteristic function of the
set SI “ kPI Sk .

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

power. Let S “ t1, 2, . . . , 100u. We denote by S1 the subset of perfect squares


of S, by S2 the subset of perfect cubes, and by S3 the subset of perfect fourth
powers. Then |S1 | “ |t12 , 22 , . . . , 102 u| “ 10, |S2 | “ |t13 , 23 , 33 , 43 u| “ 4, and
|S3 | “ t14 , 24 , 34 u| “ 3. Furthermore,
|S1 X S2 | “ 2, |S1 X S3 | “ 3, |S2 X S3 | “ 1, and |S1 X S2 X S3 | “ 1.
The inclusion-exclusion formula for m “ 3 yields
|S zpS1 Y S2 Y S3 q|
“ |S| ´ |S1 | ´ |S2 | ´ |S3 | ` |S1 X S2 |
`|S1 X S3 | ` |S2 X S3 | ´ |S1 X S2 X S3 |
“ 100 ´ 10 ´ 4 ´ 3 ` 2 ` 3 ` 1 ´ 1 “ 88.
Thus, 88 numbers from 1 to 100 are neither a perfect square nor a perfect cube
nor a perfect fourth power.
It is worth noting a particular special case of the inclusion-exclusion for-
mula.
Corollary 11.38. Let S be a finite set and S1 , . . . , Sm be pairwise distinct
subsets of S. If the cardinality Ck of the intersection Si1 X Si2 X ¨ ¨ ¨ X Sik de-
pends only on k and not on the particular indices, then the inclusion-exclusion
formula simplifies to
ˇ ˇ
m m ˆ ˙
k m
ˇ ď ˇ ÿ
ˇS z Sk ˇ “ p´1q Ck .
ˇ ˇ
ˇ
k“1
ˇ
k“0
k
We will now present some applications. We begin by counting the number
of surjective maps from a finite set to another.
Proposition 11.39. The number of surjective mappings from a finite set A
with n elements to a finite set B with m elements is given by
m ˆ ˙
ÿ m
p´1qk pm ´ kqn
k“0
k
when n ě m.
Proof. Let S denote the set of all maps from A to B “ tb1 , . . . , bm u. Let Sk
denote the subset of maps in S that do not have the element bk in their range,
where k is in the range 1 ď k ď m. For an index set I Ď t1, 2, . . . , mu of
cardinality k, we have
|SI | “ pm ´ kqn ,
since there are m´k remaining elements from B that can be selected for each of
the n arguments in the set of functions in SI . By Corollary 11.38, the number
of surjective functions is given by
m ˆ ˙
ÿ m
p´1qk pm ´ kqn ,
k“0
k
as claimed.
294 11 Counting

An important consequence is a formula for the Stirling numbers of the


second kind.
Corollary 11.40. A Stirling number of the second kind can be expressed as
follows: " * m ˆ ˙
n 1 ÿ k m
“ p´1q pm ´ kqn .
m m! k“0 k

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

which implies the claim.

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!

which proves the claim.

For a positive integer n, Euler’s totient function ϕpnq is defined as the


number of integers in the set t1, 2, . . . , nu that are relatively prime to n. For
instance, ϕp4q “ 2, since 1 and 3 are relatively prime to 4.
11.6 The Inclusion-Exclusion Principle 295

Theorem 11.42. Suppose that p1 , p2 , . . . , pm are all prime factors of n. Then


m ˆ ˙
ź 1
ϕpnq “ n 1´ .
k“1
pk

Proof. We prove the claim using the inclusion-exclusion formula. Let S “


t1, 2, . . . , nu. We denote by Sk “ tjpk | 1 ď j ď n{pk u the subset of S
consisting of the multiples of the prime pk . For a subset ti1 , i2 , . . . , i u of
t1, 2, . . . , mu, the subset Si1 X Si2 X ¨ ¨ ¨ X Si of S consists of all multiples
of pi1 pi2 ¨ ¨ ¨ pi . Therefore, it is a set of cardinality |Si1 X Si2 X ¨ ¨ ¨ X Si | “
n{pi1 pi2 ¨ ¨ ¨ pi . By the inclusion-exclusion formula,
ˇ ˇ
ˇ ďm ˇ ÿ
ϕpnq “ ˇS z Sk ˇ “ p´1q|I| |SI |
ˇ ˇ
ˇ ˇ
k“1 IĎt1,2,...,mu
ÿ ź 1
“ n p´1q|I|
kPI k
p
IĎt1,2,...,mu
ÿ źˆ 1 ˙
“ n ´
kPI
pk
IĎt1,2,...,mu

Since the identity


m
ź ÿ ź
p1 ` xk q “ xk
k“1 IĎt1,2,...,mu kPI

holds for all real numbers x1 , . . . , xm by Exercise 11.48, substituting xk “


´1{pk allows one to deduce the claim from the previous equation for ϕpnq.

Exercises
11.46. How many bit strings of length 8 start with 1 or end with 00?

11.47. Deduce the formula for the inclusion-exclusion principle for m “ 3,


ˇ ˇ
ˇ 3
ď ˇ
ˇS z Sk ˇ “ |S|´|S1 |´|S2 |´|S3 |`|S1 XS2 |`|S1 XS3 |`|S2 XS3 |´|S1 XS2 XS3 |,
ˇ ˇ
ˇ ˇ
k“1

from the inclusion-exclusion principle for m “ 2,

|S zpS1 Y S2 q| “ |S| ´ |S1 | ´ |S2 | ` |S1 X S2 |.

11.48. Prove that


m
ź ÿ ź
p1 ` xk q “ xk
k“1 IĎt1,2,...,mu kPI

holds for all real numbers x1 , . . . , xm .


296 11 Counting

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.

11.7 Pigeonhole Principle


Recall that the pigeonhole principle states the self-evident fact that it is im-
possible to place n pigeons into fewer than n pigeonholes without occupying at
least one pigeonhole more than once. Despite the simplicity of this principle,
some applications never fail to astound people.
Example 11.43. The number of hairs on a human head can reach up to
240,000. Since 2014, the population of the metropolitan area of Aggieland
exceeds 240,000 people. Therefore, the pigeonhole principle implies that there
exist now two people in Aggieland that have the same number of hairs on their
head.
Example 11.44. Let n be an integer n ě 2. Any set P of n positive integers
contains at least two elements such that their difference is divisible by n ´ 1.
Indeed, let us form the congruence classes of the n integers in P modulo n ´ 1.
There exist n ´ 1 different congruence classes, so there must exist two elements
a and b in P that are in the same equivalence class, meaning that a ” b
pmod n ´ 1q. Therefore, a ´ b is divisible by n ´ 1.
Example 11.45. Given five points on a sphere, there must be a closed hemi-
sphere that contains four of them, see Fig. 11.5. Indeed, if we arbitrarily pick
two points on the sphere, there must be at least one great circle C passing
through these points (and in the case of antipodal points, there are even in-
finitely many). Now one of the two closed hemispheres defined by the great
circle C contains at least two of the remaining three points by the pigeonhole
principle, so this hemisphere with border C contains at least four points.

Theorem 11.46 (Strong Pigeonhole Principle). Let n, k be positive integers.


If n pigeons sit in k pigeonholes and n ą k, then at least one pigeonhole must
contain at least rn{ks pigeons.
Proof. Seeking a contradiction, let us suppose that every pigeonhole contains
less than rn{ks pigeons. Since there are at most`Prn{ks
T ´˘ 1 pigeons in a pi-
geonhole, the total number of pigeons is at most k nk ´ 1 , which is bounded
by ´Q n U ´´ n
¯ ¯ ¯ n
k ´1 ăk ` 1 ´ 1 “ k “ n.
k k k
However, this means that there are fewer than n pigeons total, contrary to our
assumption.
11.7 Pigeonhole Principle 297

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

initials. By the Strong Pigeonhole Principle, any audience attending a concert


must have at least R V
2840
“5
676
people with the same first and last initials.

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.58. Let T be a subset with n ` 1 elements of the set S “ t1, 2, . . . , 2nu.


Show that
(a) there are two elements in T that are coprime,
(b) there are two elements in T such that one divides the other.

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.60. In this exercise, we formulate a more general version of the pigeonhole


principle.
(a) Let n1 , n2 , . . . , nk be positive integers. Show that if n pigeons with n ě
n1 ` n2 ` ¨ ¨ ¨ ` nk ´ k ` 1 are distributed among k pigeonholes, then there
exists a pigeonhole j with 1 ď j ď k that contains at least nj pigeons.
(b) Derive the pigeonhole principle as a consequence of the generalized pigeon-
hole principle given in part (a).
(c) Suppose that you have a glass jar full of fasteners of three different types.
You want to reattach a fence picket. You will either need two long screws
of type S1 or three medium length screws of type S2 or four short length
screws of type S3 . You want to attach the fence picket with just one type of
screws for a uniform look. How many screws do you need to grab from the
jar to guarantee that you have either two screws of type S1 , three screws
of type S2 , or four screws of type S3 .

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.

12.1 The Basic Concept


Given a sequence of real numbers a “ pa0 , a1 , a2 , a3 , . . .q, the ordinary gener-
ating function of a, or generating function for short, is given by the power
series
8
ÿ
Apzq “ ak z k “ a0 ` a1 z ` a 2 z 2 ` a3 z 3 ` ¨ ¨ ¨ .
k“0
Informally, one can view a power series as a generalization of a polynomial with
an infinite number of terms. A power series is a polynomial if all but a finite
number of the coefficients ak are equal to zero.
We will denote by rz k s the operator that extracts the k-th coefficient from
the generating function,
rz k sApzq “ ak .
What is the benefit of using a generating function when it apparently en-
codes the same information as the sequence? One advantage of generating

© The Author(s), under exclusive license to Springer Nature 301


Switzerland AG 2025
A. Klappenecker, H. Lee, Discrete Structures, Undergraduate Texts in
Mathematics, https://doi.org/10.1007/978-3-031-73434-2 12
302 12 Generating Functions

functions is that they allow us to do algebraic manipulations. Viewing the


sequences in this way can give us considerable insight, as we will see. Let us
have a look at an example to give you a first taste of this tool.
Example 12.1. A six-sided normal die has the face values

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:

However, it might be easy to overlook a combination, so this approach does


not scale well to larger problems. Let’s see how we can use generating functions
to solve the problem. For each pair pa, bq of values of the dice, the product
z a z b “ z a`b yields the sum a ` b of the values in the exponent. Therefore, if
we form the product of the generating polynomials of the two dice, Dpzq2 “
DpzqDpzq, then the coefficient of z a`b “ z 7 of the resulting polynomial counts
the number of pairs that sum to 7. In this case, we have

Dpzq2 “ z 2 ` 2z 3 ` 3z 4 ` 4z 5 ` 5z 6 ` 6z 7 ` 5z 8 ` 4z 9 ` 3z 10 ` 2z 11 ` z 12 .

Therefore, we have rz 7 sDpzq2 “ 6 different pairs of die values that sum to 7,


confirming that our aforementioned enumeration of such pairs is complete.
Example 12.2. Sam has a pair of six-sided crazy dice. The first die has the
following six sides

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

Cpzq “ z ` 2z 2 ` 2z 3 ` z 4 and W pzq “ z ` z 3 ` z 4 ` z 5 ` z 6 ` z 8 .


12.2 Operations on Generating Functions 303

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.3. Determine the number of ways to obtain a sum of 12 when rolling 3


six-sided normal (fair) dice using generating functions.

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?

12.2 Operations on Generating Functions


Let Apzq and Bpzq denote the power series
8
ÿ 8
ÿ
Apzq “ ak z k and Bpzq “ bk z k ,
k“0 k“0
304 12 Generating Functions

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

The product ApzqBpzq of two power series is defined as


˜ ¸
8
ÿ ÿk
ApzqBpzq “ ak´ b z k .
k“0 “0

We denote by Rrrzss the set of all formal power series


# +
8
ÿ
ˇ

ˇ
Rrrzss “ ak z ˇ ak P R for all k P N0 .
k“0

 A formal power series does not need to be convergent. A power series


that is not convergent cannot be used as a function. However, we can
still algebraically manipulate the formal power series, since for instance, sum
and product are defined for all formal power series, convergent or not. We can
often prove remarkable facts about the sequences using formal power series,
even though they might lack any convergence properties.

We say that a power series Bpzq is a multiplicative inverse of the power


series Apzq if and only if their product satisfies

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

Adding a0 bk on both sides yields


k
ÿ
a bk´ “ 0,
“0

as it should. It follows by induction that all coefficients bk are defined and


satisfy ApzqBpzq “ 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

In view of the previous example, we have


8
1 ÿ
“ pk ` 1qz k .
p1 ´ zq2 k“0

Thus, p1 ´ zq´2 is the generating function of the sequence p1, 2, 3, . . .q.


We can generalize the previous example as follows.
Proposition 12.6. Let Apzq denote the generating function of the sequence
pa0 , a1 , a2 , . . .q. Then
1
Apzq
1´z
is the generating function of the associated sequence of partial sums

pa0 , a0 ` a1 , a0 ` a1 ` a2 , a0 ` a1 ` a2 ` a3 , . . .q.

Proof. By definition, the product of 1{p1 ´ zq and Apzq yields


˜ ¸˜ ¸
8 8
1 ÿ
k
ÿ

Apzq “ z a z
1´z k“0 “0
˜ ¸
ÿ8 ÿk
“ 1 ¨ a z k
k“0 “0
˜ ¸
8
ÿ k
ÿ
“ a zk .
k“0 “0

The right-hand side is the generating function of

pa0 , a0 ` a1 , a0 ` a1 ` a2 , a0 ` a1 ` a2 ` a3 , . . .q,

as claimed.

Another useful operation is the multiplication of coefficients by powers of a


real number r.
Proposition 12.7. Let Apzq denote the generating function of the sequence
pa0 , a1 , a2 , a3 , . . .q and let r denote a real number. Then Aprzq is the generating
function of the sequence pa0 , ra1 , r2 a2 , r3 a3 , . . .q.
12.2 Operations on Generating Functions 307

Proof. If we expand the formal power series Aprzq, then we get


8
ÿ 8
ÿ
Aprzq “ ak przqk “ ak r k z k ,
k“0 k“0

which is the generating function of pa0 , ra1 , r2 a2 , r3 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

has the generating function z k Apzq.


Similarly, the left-shifted sequence pak , ak`1 , ak`2 , . . .q has the generat-
ing function
Apzq ´ ak´1 z k´1 ´ ¨ ¨ ¨ ´ a1 z ´ a0
.
zk
Example 12.8. The generating function of the sequence p1, 2, 3, . . .q is given
by
1
Apzq “ .
p1 ´ zq2
The generating function of the left-shifted sequence is given by

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.

Given a formal power series


8
ÿ
Apzq “ ak z k ,
k“0

we can define its formal derivative by


8 8
d ÿ ÿ
Apzq “ kak z k´1 “ pk ` 1qak`1 z k .
dz k“1 k“0

In other words, if a sequence pa0 , a1 , a2 , . . .q has the generating function Apzq,


then the sequence

b “ pb0 , b1 , b2 , . . .q “ pa1 , 2a2 , 3a3 , . . .q


d
has the generating function dz Apzq.
308 12 Generating Functions

 Let Apzq denote the generating function of a sequence

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

is the generating function of the sequence pnan qně0 . It follows that


8
ÿ
pzDqm Apzq “ k m ak z k
k“0

is the generating function of the sequence pnm an qně0 . ř


m
Consequently, if we are given a polynomial P pxq “ k“0 ck xk , then
m
ÿ
P pzDqApzq “ ck pzDqk Apzq
k“0

is the generating function of the sequence


˜ ¸
m
ÿ
k
c k n an “ pP pnqan qně0 ,
k“0 ně0

as claimed.

Given a formal power series


8
ÿ
Apzq “ ak z k ,
k“0
12.2 Operations on Generating Functions 309

we can define its formal integral by


żz 8 8
ÿ ak k`1 ÿ ak´1 k
Apxqdx “ z “ z
0 k“0
k ` 1 k“1
k

In other words, if a sequence pa0 , a1 , a2 , . . .q has the generating function Apzq,


then the sequence
a0 a1 a2
b “ pb0 , b1 , b2 , b3 , . . .q “ p0, , , , . . .q
1 2 3
şz
has the generating function 0 Apxqdx. This shifts the sequence to the right
and divides it by a proportionality factor such that
ak´1
bk “
k
holds for all k ě 1 and b0 “ 0.
Example 12.10. If we formally integrate the generating function
8
1 ÿ
“ zk
1 ´ z k“0

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

By Corollary 11.26, the number of nonnegative


˘ integer solutions to the equation
k1 ` k2 ` ¨ ¨ ¨ ` km “ k is given by m`k´1
`
k . Therefore, we can conclude that
8 ˆ ˙
ÿ m`k´1 k
Apzqm “ z ,
k“0
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

where r is a real number.


12.7. Determine the generating function of the sequence

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

p1, ´1, 1, ´1, 1, ´1, ¨ ¨ ¨ q

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.

12.3 Elementary Generating Functions


We will need a little dictionary that collects the generating functions for a few
well-known sequences. We have already derived some, so it will be good to
collect them in one place for better reference.
Example 12.12. We have seen that the constant sequence p1, 1, 1, 1, . . .q has
the generating function
8
1 ÿ
“ zk .
1 ´ z k“0
The left-hand side can be interpreted as a convenient shorthand.
Example 12.13. The sequence p0, 1, 2, 3, 4, . . .q has the generating function
8 8
z ÿ
k
ÿ
“ z pk ` 1qz “ kz k .
p1 ´ zq2 k“0 k“0

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
` ˘

is equal to the polynomial


n ˆ ˙
ÿ n k
Spzq “ z .
k“0
k
By the binomial theorem, we have
Spzq “ p1 ` zqn .
This fact is particularly useful. Many binomial coefficient identities can be
derived using the fact that p1 ` zqn is the generating function of the binomial
coefficient sequence.
There exists a useful generalization of the previous example to noninteger
exponents n.
Example 12.17. Let x be a real number. The function f pzq “ p1 ` zqx
can be differentiated arbitrarily often. The first derivative of f pzq is given by
f p1q pzq “ xp1`zqx´1 , the second derivative by f p2q pzq “ xpx´1qp1`zqx´2 , and
in general, the k-th derivative is given by f pkq pzq “ xk p1 ` zqx´k . Therefore,
the Taylor series of f pzq about z “ 0 is given by
8 8
ÿ f pkq p0q k ÿ xk k
p1 ` zqx “ z “ z .
k“0
k! k“0
k!
The falling power of x divided by k! equals the generalized binomial coefficient
xk
`x ˘
k! “ k . Therefore, we have
8 ˆ ˙
ÿ x k
p1 ` zqx “ z .
k“0
k
This binomial series has in general infinitely many nonzero terms, but it
converges for all z satisfying |z| ă 1. The binomial
? series allows one to derive
the formal power series for expressions such as 1 ` z “ p1 ` zq1{2 .
We can use results from calculus to expand our repertoire of generating
functions.
1 1 1 1 1
Example 12.18. The sequence p 0! , 1! , 2! , 3! , 4! , ¨ ¨ ¨ q of reciprocals of the fac-
torials has the exponential function
8
ÿ xk
exppxq “
k“0
k!
as a generating function.
12.3 Elementary Generating Functions 313
1 1
Example 12.19. The sequence p1, 0, ´ 2! , 0, 4! , 0, . . .q has the cosine function
8
x2 x4 x6 x8 ÿ x2k
cospxq “ 1 ´ ` ´ ` ` ¨¨¨ “ p´1qk
2! 4! 6! 8! k“0
p2kq!

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

12.15. Let n be a nonnegative integer. Use the generating function of the


binomial sequence ˆˆ ˙ ˆ ˙ ˆ ˙ ˆ ˙˙
n n n n
, , ,...,
0 1 2 n
to prove that
n ˆ ˙
ÿ n
“ 2n .
k“0
k

12.16. Let n be a nonnegative integer. Use the generating function of the


binomial sequence ˆˆ ˙ ˆ ˙ ˆ ˙ ˆ ˙˙
n n n n
, , ,...,
0 1 2 n
to prove that
n ˆ ˙
ÿ n
p´1qk “ 0.
k“0
k

12.17. Let n be a nonnegative integer. Use the generating function of the


binomial sequence ˆˆ ˙ ˆ ˙ ˆ ˙ ˆ ˙˙
n n n n
, , ,...,
0 1 2 n
to prove that
n ˆ ˙
ÿ nk
2 “ 3n .
k“0
k

12.18. Deduce Vandermonde’s identity


ˆ ˙ ÿ k ˆ ˙ˆ ˙
m`n m n

k i“0
i k´i

from rz k sp1 ` zqm`n “ rz k sp1 ` zqm p1 ` zqn .


12.19. Show that the sum of the Fibonacci numbers is given by

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

as we will show in the next chapter.


12.20. Use generating functions to show that the sum of the first n Harmonic
numbers is given by

H1 ` H2 ` ¨ ¨ ¨ ` Hn “ pn ` 1qHn ´ n.
12.4 Giving Change 315

12.4 Giving Change


Let us conclude this chapter with a classical application of generating functions.
Suppose that you want to determine in how many different ways one can give
change for an amount of c cents using pennies, nickels, dimes, and quarters.
In other words, we need to find the number of nonnegative integer solutions to
the equation
c “ p ` 5n ` 10d ` 25q,
where p denote the number of pennies, n the number of nickels, d the number
of dimes, and q the number of quarters. Counting the number of such solutions
can be a bit tedious if we approach it directly.
Let us reformulate the problem using generating functions. The generating
function listing the different possibilities for the number of pennies is given by
8
1 ÿ
P pzq “ “ zk .
1 ´ z k“0

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.

But how can we extract the coefficient of z c in


1 1 1 1
.
1 ´ z 1 ´ z 5 1 ´ z 10 1 ´ z 25
We do not want to expand the terms directly, as this leads to a mess when c is
large. Instead, we follow a slightly more principled approach and solve simpler
problems by restricting the available denominations.
If we only have pennies available, then the problem is very simple. The
number of ways to give change for the amount of c cents when only pennies
are available is given by
8
1 ÿ
rz c sP pzq “ rz c s “ rz c s z k “ 1.
1´z k“0

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

Applying rz k s to both sides yields 1 “ nk ´ nk´5 or nk “ nk´5 ` 1 when k ě 5,


and nk “ 1 when k is in the range 0 ď k ă 5. Therefore, nk “ tk{5u ` 1 for all
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

Applying rz k s to both sides yields nk “ dk ´ dk´10 or dk “ dk´10 ` nk when


k ě 10, and dk “ nk when k is in the range 0 ď k ă 10.
Finally, if we have pennies, nickels, dimes, and quarters available, then the
number of ways qk to give change for k cents has the generating function
8
ÿ
P pzqN pzqDpzqQpzq “ qk z k
k“0

By now it should be entirely routine. We multiply by 1 ´ z 25 to obtain


8
ÿ
P pzqN pzqDpzq “ p1 ´ z 25 q qk z k .
k“0

Applying rz k s to both sides yields dk “ qk ´ qk´25 or qk “ dk ` qk´25 when


k ě 25, and qk “ dk when 0 ď k ă 25.
12.4 Giving Change 317

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

q75 “ d75 ` q50 “ d75 ` d50 ` q25 “ d75 ` d50 ` d25 ` d0 .

We can expand the dk ’s in terms of nk terms

d75 “ n75 ` n65 ` n55 ` n45 ` n35 ` n25 ` n15 ` n5


d50 “ n50 ` n40 ` n30 ` n20 ` n10 ` n0
d25 “ n25 ` n15 ` n5
d0 “ n0

Since nk “ tk{5u ` 1, we get

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

Therefore, we can conclude that there are

q75 “ d75 ` d50 ` d25 ` d0 “ 72 ` 36 ` 12 ` 1 “ 121

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.

13.1 Recurrence Relations


A sequence satisfies a recursive formula if we can describe the next term of
a sequence using preceding terms of the sequence. Familiar examples are the
interest earned on a bank account, modeling the growth of a population, and
estimating the running time of a recursive algorithm.
In many applications, it is not difficult to find a recursive formula that
determines a sequence. For instance, for all positive integers n, let pn denote
the number of ways to write the number n ` 2 as an ordered sum in which each
term is either 2 or 3. By an ordered sum, we mean that we will count 2 ` 3
and 3 ` 2 separately. For example, p6 “ 4, since we can express 6 ` 2 “ 8 in
four different ways as a sum of 2 or 3, namely

8 “ 2 ` 2 ` 2 ` 2 “ 2 ` 3 ` 3 “ 3 ` 2 ` 3 “ 3 ` 3 ` 2.

© The Author(s), under exclusive license to Springer Nature 319


Switzerland AG 2025
A. Klappenecker, H. Lee, Discrete Structures, Undergraduate Texts in
Mathematics, https://doi.org/10.1007/978-3-031-73434-2 13
320 13 Recurrence Relations

In the same vein, we get


p0 “ 1, since 2 “ 2,
p1 “ 1, since 3 “ 3,
p2 “ 1, since 4 “ 2 ` 2,
p3 “ 2, since 5 “ 2 ` 3 “ 3 ` 2,
p4 “ 2, since 6 “ 2 ` 2 ` 2 “ 3 ` 3,
p5 “ 3, since 7 “ 2 ` 2 ` 3 “ 2 ` 3 ` 2 “ 3 ` 2 ` 2.
We could continue to list subsequent terms, but enumerating all choices gets
tedious for larger n. There is an easier way to calculate the numbers pn . When
calculating pn , we can distinguish the number of sums that start with 2 and
the number of sums that start with 3. If the first term is 2, then there are
pn´2 ways to write the remaining terms, and if the first term is 3, then there
are pn´3 ways to write the remaining terms. Thus, we have
pn “ pn´2 ` pn´3
for all integers n ą 2. Using the initial terms, p0 “ p1 “ p2 “ 1 and this
recurrence relation, we can quickly calculate the first few terms
pp0 , p1 , p2 , p3 , p4 , . . .q “ p1, 1, 1, 2, 2, 3, 4, 5, 7, 9, 12, 16, . . .q.
This sequence is called the Padovan sequence, which was named after the
architect Richard Padovan, who popularized it in works about mathematical
properties of architectural proportions.
The recurrence relation is good for computations as long as n does not
become too large. If you would like to know more about the behavior of pn
for large n, then a formula for pn that does not depend on previous terms
would be preferable. In this chapter, we will see how to derive such closed-
form expressions for certain recurrence relations. Before we get into this topic,
we need to settle some terminology.
Let a “ pa0 , a1 , a2 , . . .q be a sequence of real numbers. We say that the
sequence satisfies a recurrence relation of finite history if and only if there
exists a nonnegative integer d and a function f : Rd Ñ R such that
an “ f pan´1 , . . . , an´d q
holds for all n ě d. We call d the degree of the recurrence relation.
We say that a satisfies a linear recurrence relation of order d with
constant coefficients if and only if there exist real numbers c1 , c2 , . . . , cd with
cd ‰ 0 and a function g : N0 Ñ R such that
an ` c1 an´1 ` c2 an´2 ` ¨ ¨ ¨ ` cd an´d “ gpnq
holds for all n ě d. The recurrence is called homogeneous if and only if
gpnq “ 0 holds for all n ě d. If gpnq is not identically 0, then the linear
recurrence is called inhomogeneous.
In general, an infinite number of sequences satisfy a homogeneous linear
recurrence relation. One needs to specify the initial conditions a0 , . . . , ad´1
and the recurrence relation to specify the sequence a.
13.1 Recurrence Relations 321

Example 13.1. The Fibonacci sequence satisfies the recurrence relation


fn ´ fn´1 ´ fn´2 “ 0
for all n ě 2 and has the initial conditions f0 “ 0 and f1 “ 1. This is a
homogeneous linear recurrence relation of degree 2.
Example 13.2. The sequence of squares satisfies the recurrence relation
hn ´ hn´1 “ 2n ´ 1
for all n ě 1. This is an inhomogeneous linear recurrence relation of degree 1.
The goal of this chapter is to show how generating functions can help to
find closed-form solutions to recurrence relations. By a closed form, we mean
an expression that explicitly gives the value of the coefficients of the sequence.
For instance, the recurrence given in the previous example has the closed-form
solution
hn “ n2
for all positive integers n. The recurrence relation might be a perfectly rea-
sonable way to calculate the value of hn , but a closed-form solution might give
additional information such as the asymptotic growth of the coefficients hn .

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

13.6. There is a simple non-recursive expression for the centered hexagonal


counting numbers hn . This exercise guides you to discover and prove it yourself.
(a) Form the sequence of the partial sums of the centered hexagonal numbers
and numerically evaluate the first 10 terms
ph0 , h0 ` h1 , h0 ` h1 ` h2 , . . . , h0 ` h1 ` . . . ` h9 q.
(b) Guess a simple formula for the n-th partial sum sn of centered hexagonal
numbers,
n
ÿ
sn “ hk ,
k“0
based on your observations in part (a).
(c) Express hn for n ě 1 as a difference of two successive terms of the sequence
given in parts (a) and (b).
(d) Prove the formula that you have found for hn in part (c) by strong induc-
tion.
13.7. Find a recursive formulation of the sequence pn!!qně0 of double factorials.
The double factorial is defined as
r n2ź
s´1
n!! “ pn ´ 2kq,
k“0

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

13.2 A Motivating Example


The recursive formulation of a sequence can be convenient when calculating a
few terms, but the dependency of a term on previous terms can be a nuisance
when analyzing the behavior of the sequence. Therefore, we often strive to find
a non-recursive formulation for the value of the coefficients of a sequence given
by a recurrence. The problem is that guessing such a formula can be difficult.
Generating functions are often a good tool to find a non-recursive formulation of
the sequence coefficients. In this section, we illustrate how generating functions
can help with this task.
Suppose that you are given a sequence ph0 , h1 , h2 , . . .q such that its coeffi-
cients are defined by the recurrence relation
#
0 when n “ 0,
hn “
hn´1 ` 2n ´ 1 when n ě 1.
You will hardly need any special methods to solve such a simple recurrence,
especially after reading the previous section. However, let us pretend for the
moment that we do not know the answer. Our goal is to find a closed-form
solution using the tool of generating functions.
The ordinary generating function of the sequence ph0 , h1 , h2 , . . .q is given
by the formal power series
8
ÿ
Hpzq “ hk z k .
k“0

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

Keeping in mind that h0 “ 0, the distributive law yields


8
ÿ 8
ÿ 8
ÿ
Hpzq “ hk´1 z k ` 2kz k ` p´1qz k . (13.1)
k“1 k“1 k“1
324 13 Recurrence Relations

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

Comparing coefficients, we can conclude that

hn “ n2

holds for all n ě 0.


The beauty of this approach is that we can solve much more difficult re-
currence relations in essentially the same way. In general, the solution is a
linear combination of elementary generating functions with known coefficient
sequences. The advantage of generating functions is that we can use familiar
algebraic methods to find the linear combinations. In the next section, we give
an example that illustrates this approach.
13.3 Fibonacci Sequence 325

Exercises
13.10. (a) Find a closed form of the generating function of the sequence
phn q8
n“0 given by the recurrence relation

h0 “ 1 and hn “ 2hn´1 ` 1 when n ě 1.

(b) Find a closed form for the coefficients.


13.11. (a) Find a closed form of the generating function of the sequence
phn q8
n“0 given by the recurrence relation

h0 “ 1 and hn “ hn´1 ` n ` 3 when n ě 1.

(b) Find a closed form for the coefficients.

13.3 Fibonacci Sequence


Recall that the first few terms of the Fibonacci sequence (with the term f0 “ 0
included) are given by

pf0 , f1 , f2 , f3 , f4 , f5 , f6 , f7 . . .q “ p0, 1, 1, 2, 3, 5, 8, 13, . . .q.

This sequence is defined by the recurrence relation


$
&0
’ when n “ 0,
fn “ 1 when n “ 1,

fn´1 ` fn´2 when n ě 2.
%

If we denote the ordinary generating function of the sequence pfn q8


n“0 by F pzq,
then we have
ÿ8
F pzq “ fk z k .
k“0

Using the definition of the recurrence, we obtain


8
ÿ 8
ÿ
F pzq “ fk z k “ z ` pfk´1 ` fk´2 qz k .
k“0 k“2

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.

Subtracting zF pzq ` z 2 F pzq from both sides, it follows that

F pzq ´ zF pzq ´ z 2 F pzq “ F pzqp1 ´ z ´ z 2 q “ z.


326 13 Recurrence Relations

Dividing both sides by 1 ´ z ´ z 2 , we can conclude that the ordinary generating


function of the Fibonacci sequence is given by
z
F pzq “ .
1 ´ z ´ z2
We can do even better and find a closed form solution for the Fibonacci
numbers fn with n ě 0. For this purpose, we factor the polynomial 1 ´ z ´ z 2
and write it in the form
1 ´ z ´ z 2 “ p1 ´ ρ1 zqp1 ´ ρ2 zq,
where ρ1 is the golden ratio and ρ2 its conjugate root,
? ?
1` 5 1´ 5
ρ1 “ and ρ2 “ .
2 2
We claim that there exist real numbers c and d such that
z c d
F pzq “ “ ` . (13.2)
1 ´ z ´ z2 1 ´ ρ1 z 1 ´ ρ2 z
Indeed, bringing the fractions to the common denominator 1 ´ z ´ z 2 yields
z cp1 ´ ρ2 zq dp1 ´ ρ1 zq
2
“ ` .
1´z´z 1 ´ z ´ z2 1 ´ z ´ z2
Therefore, c ` d ´ pρ2 c ` ρ1 dqz “ z. Comparing coefficients shows that the real
numbers c and d must satisfy the system of linear equations

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

So let us now substitute the calculated values for the variables ρ1 , ρ2 , c,


and d into (13.2). Using the aforementioned power series expansion yields the
remarkable generating function
8
˜ˆ ? ˙k ˆ ? ˙k ¸
ÿ 1 1` 5 1´ 5
F pzq “ ? ´ zk .
k“0
5 2 2
13.3 Fibonacci Sequence 327

In conclusion, the Fibonacci number fk is given by

˜ˆ ? ˙k ˆ ? ˙k ¸
1 1` 5 1´ 5
fk “ ? ´
5 2 2

for all nonnegative integers k. The latter expression is known as Binet’s


formula for the Fibonacci coefficients.

Exercises

13.12. Show that the n-th Fibonacci number is asymptotically equal to

ˆ ? ˙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

holds for all n ě 0.

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.]

13.15. Let fn denote the Fibonacci numbers given by f0 “ 0, f1 “ 1 and


fn “ fn´1 ` fn´2 for n ě 2. Determine the value of the infinite sum

8
ÿ fn
.
n“0
2n

[Hint: Use generating functions.]


328 13 Recurrence Relations

13.4 Partial Fractions


We can generalize the method to find a closed-form solution of the Fibonacci
recurrence to a much wider class of recurrence relations. We will need an
essential tool: the partial fraction decomposition of rational functions. You
might have encountered the partial fraction decomposition in calculus, when
calculating integrals of rational functions. In this section, we review the partial
fraction decomposition, but we formulate it in a form that will be convenient
for solving recurrence relations.
Suppose that we are given a rational function ppzq{qpzq, where ppzq and
qpzq are polynomials with real or complex coefficients and ppzq has smaller
degree than qpzq. Suppose that qpzq factors into linear terms

qpzq “ pa1 z ` b1 qd1 pa2 z ` b2 qd2 ¨ ¨ ¨ pak z ` bk qdk , (13.3)

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

This decomposition of the rational function ppzq{qpzq is unique.

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

qpzq “ pa1 z ` b1 qd1 apzq,

where apzq is a polynomial of degree n ´ d1 satisfying apr1 q ‰ 0. We will now


show that ppzq{qpzq has a partial fraction decomposition of the claimed form.
Let us first consider the related rational function
ppzq ppr1 q ppzqapr1 q ´ ppr1 qapzq
´ “ .
apzq apr1 q apzqapr1 q

Since r1 is a root of the numerator, we can rewrite this expression in the form

ppzq ppr1 q pa1 z ` b1 qbpzq


´ “ ,
apzq apr1 q apzq

where bpzq is a polynomial of degree deg bpzq ď n ´ 2. It follows that

ppzq ppr1 q bpzq


d
´ d
“ .
pa1 z ` b1 q apzq pa1 z ` b1 q apr1 q
1 1 pa1 z ` b1 qd1 ´1 apzq

Since deg b ď n ´ 2 and deg pa1 z ` b1 qd1 ´1 apzq ď n ´ 1, we can express


` ˘

the right-hand side by induction hypothesis in the claimed form. Adding


apr1 q´1 ppr1 q
pa1 z`b1 qd1
to both sides of the equation shows that

ppzq ppzq

qpzq pa1 z ` b1 qd1 apzq

can be expressed in the claimed form as well.


Therefore, the existence of the partial fraction decomposition follows by
strong induction on n “ deg q.
We will now prove the uniqueness of the partial fraction decomposition.
Seeking a contradiction, let us assume that there exist two different decompo-
sitions of ppzq{qpzq, say
k ÿdi k ÿ di
ppzq ÿ Ci,j ÿ Di,j
“ j
“ .
qpzq i“1 j“1 pai z ` bi q i“1 j“1
pai z ` bi qj

Subtracting one decomposition from the other, we obtain


k ÿ di
ÿ Ci,j ´ Di,j
“ 0.
i“1 j“1
pai z ` bi qj

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

so Cμ,cμ “ Dμ,cμ , which contradicts the choice Cμ,cμ ‰ Dμ,cμ .


Therefore, Ci,j must equal Di,j for all indices i and j, so the partial fraction
decomposition is unique.
The previous theorem states the form of the partial fraction decomposition
of a rational function ppzq{qpzq. After factoring the polynomial qpzq of the
denominator, the overall form of the decomposition is known. Finding the
particular coefficients Ci,j amounts to solving a system of linear equations.
The next example is rather typical and illustrates the standard approach to
find the partial fraction decomposition.
Example 13.4. Suppose that ppzq “ z 2 ` 5 and qpzq “ pz ´ 1qpz ´ 3q2 . By the
partial fraction decomposition, there must exist complex constants such that
z2 ` 5 C1,1 C2,1 C2,2
2
“ ` ` .
pz ´ 1qpz ´ 3q z ´ 1 pz ´ 3q pz ´ 3q2
Multiplying both sides by qpzq yields
z 2 ` 5 “ C1,1 pz ´ 3q2 ` C2,1 pz ´ 1qpz ´ 3q ` C2,2 pz ´ 1q.
Expanding the terms on the right-hand side yields
z 2 ` 5 “ C1,1 pz 2 ´ 6z ` 9q ` C2,1 pz 2 ´ 4z ` 3q ` C2,2 pz ´ 1q.
If we compare coefficients on both sides of this equation, then we obtain the
following system of linear equations,
9C1,1 ` 3C2,1 ´ C2,2 “ 5
´6C1,1 ´ 4C2,1 ` C2,2 “ 0
C1,1 ` C2,1 “ 1
Solving this system of equations yields C1,1 “ 3{2, C2,1 “ ´1{2, and C2,2 “ 7.
In other words, the partial fraction decomposition of ppzq{qpzq is given by
z2 ` 5 3 1 7
“ ´ ` .
pz ´ 1qpz ´ 3q2 2pz ´ 1q 2pz ´ 3q pz ´ 3q2
13.5 Reciprocal Polynomials 331

In general, the factorization of the polynomial qpzq completely determines the


form of the partial fraction decomposition. Finding the coefficients of this par-
tial fraction decomposition can be done by comparing coefficients and solving
the resulting linear system of equations, as we have shown in this example.

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

13.5 Reciprocal Polynomials


We need to establish some terminology that will help us to formulate our
proofs. For a given polynomial, we can find a new polynomial by reversing the
order of the coefficients. In this section, we give a few basic facts about such
polynomials.
For a polynomial gpzq “ g0 ` g1 z ` g2 z 2 ` ¨ ¨ ¨ ` gd z d , its reciprocal poly-
nomial or reflected polynomial g R pzq is defined as
g R pzq “ z d gp1{zq.
The polynomial g R is called the reflected polynomial, since it is of the form
g R pzq “ gd ` gd´1 z ` ¨ ¨ ¨ ` g0 z d , with the coefficients of gpzq in reverse order.
Lemma 13.5. Suppose that cpzq is a polynomial of the form cpzq “ 1 ` c1 z `
¨ ¨ ¨ ` cd z d with cd ‰ 0. Then cpzq can be written in the form
m
ź
cpzq “ p1 ´ ak zqdk
k“1

for some pairwise distinct complex numbers ak and positive integers dk such
that d1 ` d2 ` ¨ ¨ ¨ ` dm “ d.
332 13 Recurrence Relations

Proof. By the fundamental theorem of algebra, we can factor the reciprocal


polynomial cR pzq of the polynomial cpzq into linear factors
m
ź
cR pzq “ pz ´ ak qdk
k“1

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

13.6 Linear Homogeneous Recurrence Relations


Suppose that we are given a sequence pg0 , g1 , g2 , . . .q satisfying a linear homo-
geneous recurrence relation of order d with constant coefficients, that is, there
exist coefficients c1 , c2 , . . . , cd such that

gn ` c1 gn´1 ` ¨ ¨ ¨ ` cd gn´d “ 0 (13.4)

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

Gpzq “ g0 ` g1 z ` g2 z 2 ` ¨¨¨ ` gn z n ` ¨¨¨


c1 zGpzq “ c1 g 0 z ` c1 g 1 z 2 ` ¨¨¨ ` c1 gn´1 z n ` ¨¨¨
c2 z 2 Gpzq “ c2 g0 z 2 ` ¨¨¨ ` c2 gn´2 z n ` ¨¨¨
.. .. .. ..
. . . .
cd z d Gpzq “ ¨¨¨ ` cd gn´d z n ` ¨¨¨

Since the sum of these equations is equal to cpzqGpzq, we get

rz n scpzqGpzq “ gn ` c1 gn´1 ` ¨ ¨ ¨ ` cd gn´d “ 0

for all integers n satisfying n ě d.


Thus, cpzqGpzq “ ppzq for some polynomial ppzq of degree less than d, which
implies that the generating function Gpzq “ ppzq{cpzq, as claimed.

The previous proposition shows that a sequence satisfying a linear homo-


geneous recurrence relation has a fairly simple generating function, namely a
rational function. We will now exploit this fact to express the coefficients of
the sequence in closed form.
Let us first take a look at some key examples that will guide the way.
334 13 Recurrence Relations

Example 13.8. If the generating function Gpzq is a rational function of the


form
ppzq 1
“ ,
cpzq 1 ´ az
then gk “ ak for all k ě 0. This follows from Example 12.12.

Example 13.9. If the generating function Gpzq is a rational function of the


form
ppzq 1
“ ,
cpzq p1 ´ azqm

for some integer m ě 1, then gk “ k`m´1


` ˘ k
k a for all k ě 0. Indeed, this follows
from Proposition 12.11. Note that for m “ 1, we recover the previous example
as a special case.

The generating function Gpzq of a homogeneous linear recurrence of degree d


might not be of the form given by the previous examples. However, it can
always be written as a linear combination of terms that are of the form given
by the previous two examples. This means that we can find an explicit form
for the coefficients gk of the generating function of every homogeneous linear
recurrence with constant coefficients! The next proposition shows how to find
the closed-form expression for the coefficients.

Proposition 13.10. 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). There exist
pairwise distinct complex numbers ai such that the polynomial cpzq factors into
the form
źm
cpzq “ p1 ´ ak zqdk .
k“1

Then there exist complex numbers Ci,j such that


m ˆ ˙
ppzq ÿ Ck,1 Ck,2 Ck,dk
“ ` ` ¨ ¨ ¨ ` .
cpzq k“1 1 ´ ak z p1 ´ ak zq2 p1 ´ ak zqdk

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

by Lemma 13.5. By the partial fraction decomposition, there exist complex


numbers Ci,j such that
m ˆ ˙
ppzq ÿ Ck,1 Ck,2 Ck,dk
“ ` ` ¨¨¨ ` ,
cpzq k“1 1 ´ ak z p1 ´ ak zq2 p1 ´ ak zqdk
as claimed.
Let us have a look at an example.
Example 13.11. The Pell sequence pp0 , p1 , p2 , p3 , . . .q has the initial conditions
p0 “ 1 and p1 “ 2 and satisfies the linear homogeneous recurrence relation of
order 2 given by
pn ´ 2pn´1 ´ pn´2 “ 0
for all n ě 2. The first few terms of the Pell sequence are given by
p1, 2, 5, 12, 29, 70, . . .q.
The generating function Gpzq of the Pell sequence satisfies
rz n sp1 ´ 2z ´ z 2 qGpzq “ 0
for all n ě 2. Furthermore, the initial conditions imply that
rz 0 sp1 ´ 2z ´ z 2 qGpzq “ 1 and rz 1 sp1 ´ 2z ´ z 2 qGpzq “ 0.
Therefore,
1
Gpzq “ .
1 ´ 2z ´ z 2
The reciprocal polynomial of the?denominator ? polynomial has the factorization
cR pzq “ z 2 ´ 2z ´ 1 “ pz ´ p1 ` ? 2qqpz ´ p1 ´ 2qq. R
? The polynomial c pzq has
the two distinct roots a1 “ 1 ` 2 and a2 “ 1 ´ 2. Therefore, Gpzq is of the
form
C1,1 C2,1
Gpzq “ ? ` ? .
1 ´ p1 ` 2qz 1 ´ p1 ´ 2qz
By performing the partial fraction decomposition, we get
ˆ ? ? ˙
1 2` 2 2´ 2
Gpzq “ ? ` ? .
4 1 ´ p1 ` 2qz 1 ´ p1 ´ 2qz
Therefore, the closed form of the coefficient pn is given by
1´ ? ? ? ? ¯
pn “ rz n sGpzq “ p2 ` 2qp1 ` 2qn ` p2 ´ 2qp1 ´ 2qn
4
for all n ě 0.
336 13 Recurrence Relations

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

13.7 Characteristic Polynomials


We can also find the closed-form solution of a linear homogeneous recurrence
relation using a different approach. We seemingly eschew generating functions
and obtain the coefficients as linear combinations of the roots of a polynomial.
However, it is simply a reformulation of the results from the previous section.
Let pg0 , g1 , g2 , . . .q be a sequence satisfying a linear homogenous recurrence
relation of order d with constant coefficients

gn ` c1 gn´1 ` c2 gn´2 ` ¨ ¨ ¨ ` cd´1 gn´d`1 ` cd gn´d “ 0 (13.5)

for all integers n such that n ě d. We define the characteristic polynomial


χpzq of this recurrence relation by

χpzq “ z d ` c1 z d´1 ` c2 z d´2 ` ¨ ¨ ¨ ` cd´1 z ` cd .

The closed form of the recurrence relation is essentially obtained by a linear


combination of the roots of the characteristic polynomial.
Proposition 13.12. Let pg0 , g1 , g2 , . . .q be a sequence satisfying the homoge-
neous linear recurrence relation (13.5) of order d. If the characteristic polyno-
mial χpzq of this recurrence has the factorization
m
ź
χpzq “ pz ´ ai qdk ,
k“1
13.7 Characteristic Polynomials 337

where the root ak occurs with multiplicity dk , then


m
ÿ
gn “ pk pnqank ,
k“1

where pk pnq is a polynomial of degree dk ´ 1. In particular, if each root ak has


multiplicity dk “ 1, then gn is a linear combination of the n-th powers of the
roots an .

Proof. By Proposition 13.10, the generating function of the sequence is a ra-


tional function of the form
m ˆ ˙
ppzq ÿ Ck,1 Ck,2 Ck,dk
“ ` ` ¨¨¨ ` .
cpzq k“1 1 ´ ak z p1 ´ ak zq2 p1 ´ ak zqdk

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

The claim follows, since


ˆ ˙ ˆ ˙ ˆ ˙
n n`1 n ` dk ´ 1
pk pnq “ Ck,1 ` Ck,2 ` ¨ ¨ ¨ ` Ck,dk
n n n

is a polynomial of degree dk ´ 1 in n.

The following special case is particularly easy to understand.

Corollary 13.13. We keep the notations of the previous proposition. If the


roots of the characteristic polynomial are pairwise distinct, then gn is the linear
combination of the n-th powers of the roots of the characteristic polynomial
χpzq. In other words, there exist complex coefficients Ck such that
m
ÿ
gn “ Ck ank
k“1

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

Example 13.14. Let pg0 , g1 , g2 , . . .q be a sequence of real numbers such that


g0 “ 1 and g1 “ 2 and gn ´ 10gn´1 ` 21gn´2 “ 0 for all n ě 2. This sequence
has the characteristic function

χpzq “ z 2 ´ 10z ` 21 “ pz ´ 3qpz ´ 7q.

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

is the closed-form solution to the recurrence relation.

Example 13.15. Let pg0 , g1 , g2 , . . .q be a sequence of real numbers such that


g0 “ 1 and g1 “ 2 and gn ´ 6gn´1 ` 9gn´2 “ 0 for all n ě 2. This sequence
has the characteristic function

χ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

is the closed-form solution to the recurrence relation.


13.8 Inhomogeneous Linear Recurrence Relations 339

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.

13.8 Inhomogeneous Linear Recurrence Relations


A sequence pg0 , g1 , g2 , . . .q satisfies an inhomogeneous linear recurrence rela-
tion of order d with constant coefficients if and only if there exist constants
c1 , c2 , . . . , cd with cd ‰ 0 and a nonzero function f : N0 Ñ R such that
gn ` c1 gn´1 ` c2 gn´2 ` ¨ ¨ ¨ ` cd gn´d “ f pnq (13.6)
holds for all n ě d. The associated homogeneous linear recurrence relation is
given by
gn ` c1 gn´1 ` c2 gn´2 ` ¨ ¨ ¨ ` cd gn´d “ 0. (13.7)
Proposition 13.16. Two solutions to an inhomogeneous linear recurrence
relation of order d with constant coefficients differ by a solution to the associated
homogeneous recurrence relation.
Proof. Let pg0 , g1 , g2 , . . .q and pg01 , g11 , g21 , . . .q be two solutions to the inhomo-
geneous linear recurrence relation (13.6), so
gn ` c1 gn´1 ` c2 gn´2 ` ¨ ¨ ¨ ` cd gn´d “ f pnq,
gn1 ` c1 gn´1
1 1
` c2 gn´2 1
` ¨ ¨ ¨ ` cd gn´d “ f pnq,
hold for all n ě d. Subtracting the two equations yields

pgn ´ gn1 q ` c1 pgn´1 ´ gn´1


1 1
q ` c2 pgn´2 ´ gn´2 1
q ` ¨ ¨ ¨ ` cd pgn´d ´ gn´d q
“ f pnq ´ f pnq “ 0,
340 13 Recurrence Relations

so the sequence ph0 , h1 , h2 , . . .q of differences hn “ gn ´ gn1 is a solution to the


associated homogeneous recurrence relation (13.7).

In the previous sections, we showed how homogeneous linear recurrence


relation with constant coefficients can be solved. If you know one particular
solution s to an inhomogeneous recurrence relation, then the previous proposi-
tion implies that you can obtain all other solutions by adding solutions to the
associated homogeneous linear recurrence relation to your solution s.
The main question is now: How can we find one solution to an inhomoge-
neous recurrence relation? The answer to this question depends on the nature
of the function f pnq in the inhomogeneous part of the recurrence. Fortunately,
there are some types of functions f pnq for which it is possible to solve inho-
mogeneous linear recurrence relations by reducing it to a linear homogeneous
recurrence relation.
Let us have a look at an example that illustrates the approach.
Example 13.17. Let us consider the inhomogeneous recurrence relation

pn ´ 2pn´1 ´ pn´2 “ f pnq

with f pnq “ 54 3n ´ 14 7n . The associated homogeneous recurrence relation

pn ´ 2pn´1 ´ pn´2 “ 0

is the Pell sequence recurrence. The inhomogeneous part f pnq “ 54 3n ´ 14 7n is


a function that satisfies a recurrence relation itself, namely

f pnq ´ 10f pn ´ 1q ` 21f pn ´ 2q “ 0

for all n ě 2, as we have seen in Example 13.14.


In this case, we can homogenize the inhomogeneous recurrence relation,
meaning that we can derive a homogeneous recurrence relation for the sequence.
Indeed, we express the three terms f pnq, ´10f pn ´ 1q, and 21f pn ´ 2q using
the Pell recurrence

pn ´ 2pn´1 ´ pn´2 “ f pnq


´10ppn´1 ´ 2pn´2 ´ pn´3 q “ ´10f pn ´ 1q
21ppn´2 ´ 2pn´3 ´ pn´4 q “ 21f pn ´ 2q

Adding the three equations yields the homogeneous recurrence relation

pn ´ 12pn´1 ` 40pn´2 ´ 32pn´3 ´ 21pn´4 “


f pnq ´ 10f pn ´ 1q ` 21f pn ´ 2q “ 0.

Since this is a homogeneous linear recurrence relation, we know at least in


principle how to find a closed-form solution.
Let us use the characteristic polynomials to find the form of the closed
solution. The characteristic polynomial of the Pell sequence recurrence (which
13.8 Inhomogeneous Linear Recurrence Relations 341

is the associated homogeneous recurrence relation) is given by χp pzq “ z 2 ´


2z ´ 1 and the characteristic function of the inhomogeneous part is χf pzq “
z 2 ´ 10z ` 21. A short calculation shows that the characteristic polynomial
χpzq of the sequence pp0 , p1 , p2 , . . .q is given by the product

χpzq “ z 4 ´ 12z 3 ` 40z 2 ´ 32z ´ 21 “ χp pzqχf pzq


? ?
Therefore, χpzq “ pz ´ p1 ` 2qqpz ´ p1 ´ 2qqpz ´ 3qpz ´ 7q, so there exist
complex numbers C1 , C2 , C3 , and C4 such that
? ?
pn “ C1 p1 ` 2qn ` C2 p1 ´ 2qn ` C3 3n ` C4 7n .

Proposition 13.18. Let f : N0 Ñ R be a function satisfying a linear ho-


mogeneous recurrence relation with characteristic polynomial χf pzq. Let g “
pg0 , g1 , g2 , . . .q be any sequence satisfying the inhomogeneous linear recurrence
relation
gn ` c1 gn´1 ` c2 gn´2 ` ¨ ¨ ¨ ` cd gn´d “ f pnq
with constant coefficients c1 , c2 , . . . , cd and cd ‰ 0 such that the associated
homogeneous linear recurrence relation has the characteristic polynomial χc pzq.
Then the sequence g satisfies a linear homogeneous recurrence relation with
characteristic polynomial χc pzqχf pzq.

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

for all n ě χc pzq.


Similarly, let dpzq denote the reciprocal polynomial of the characteristic
polynomial χf pzq, so dpzq “ χRf pzq. Therefore, the generating function F pzq “
ř8 k
k“0 f pkqz of the function f satisfies

rz n sdpzqF pzq “ 0

for all n ě deg χf pzq.


The generating function cpzqGpzq is almost the same as the generating
function F pzq, except for a few initial terms. Specifically, the difference between
the generating functions cpzqGpzq and F pzq is a polynomial tpzq of degree less
than deg χc pzq, namely the tail polynomial tpzq given by

tpzq “ cpzqGpzq ´ F pzq.

Since cpzqGpzq “ tpzq ` F pzq, we can conclude that

dpzqcpzqGpzq “ dpzqtpzq ` dpzqF pzq.

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.

13.9 Catalan Numbers


In this section, we will study the Catalan numbers that occur in surprisingly
many combinatorial counting problems. We will introduce them as numbers
Cn that count certain paths in the upper real plane.
Specifically, we will count paths that connect the origin p0, 0q with the
point pn, nq, where n is a nonnegative integer. The path travels along integer
coordinates by going either one step up or one step to the right. In other words,
from a point with coordinates pa, bq, one can travel up
U pa, bq “ pa, b ` 1q
or right
Rpa, bq “ pa ` 1, bq.
Additionally, we require that the path never goes below the line y “ x. This
means that the coordinates of all points pa, bq on the path must satisfy
0 ď a ď b ď n.
The Catalan number Cn is defined as the number of different paths from
p0, 0q to pn, nq that use n moves U and n moves R and never go below the line
y “ x.
Example 13.20. The Catalan number C3 “ 5, since there are five ways to
connect the origin p0, 0q to p3, 3q using three moves U and three moves R in
any order, as long as the path does not go below the line y “ x. Indeed, we
have the following five paths.

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 n ě 1 satisfies the recurrence


Cn “ C0 Cn´1 ` C1 Cn´2 ` C2 Cn´3 ` ¨ ¨ ¨ ` Cn´1 C0 .
Let us verify our previous computations of the Catalan numbers using this
recurrence formula. We have
C0 “ 1,
C1 “ C0 C0 “ 1 ¨ 1 “ 1,
C2 “ C0 C1 ` C1 C0 “ 1 ¨ 1 ` 1 ¨ 1 “ 2,
C3 “ C0 C2 ` C1 C1 ` C2 C0 “ 1 ¨ 2 ` 1 ¨ 1 ` 2 ¨ 1 “ 5.
In principle, we can use this recurrence formula to calculate the Catalan num-
bers for arbitrary n. However, we can do even better and use generating
functions to find an expression for Catalan numbers in terms of binomial coef-
ficients.
In the next lemma, we find a closed-form expression for the generating
function ÿ
Cpzq “ Cn z n
n“0
of the Catalan numbers.
Lemma 13.21. The generating function of the Catalan numbers is given by
?
1 ´ 1 ´ 4z
Cpzq “ .
2z
Proof. We can express the Catalan number recurrence in the form
n
ÿ
Cn`1 “ C0 Cn ` C1 Cn´1 ` ¨ ¨ ¨ ` Cn C0 “ Cm Cn´m
m“0

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.

Proposition 13.22. The Catalan number Cn is given by


ˆ ˙
1 2n
Cn “
n`1 n

for all nonnegative integers n.

Proof. The Binomial series yields


8 ˆ1˙
? ÿ
1 ´ 4z “ 2 p´1qk 4k z k .

k“0
k

Therefore, the generating function Cpzq of the Catalan numbers satisfies


?
1 ´ 1 ´ 4z
Cpzq “
2z
8 ˆ ˙
1 ÿ 12
“´ p´1qk 4k z k´1 .
2 k“1 k

It follows that the n-th Catalan number is given by


ˆ 1 ˙
1
Cn “ rz n sCpzq “ ´ 2 p´1qn`1 4n`1 .
2 n`1

In other words, we have

1 p1{2qp´1{2qp´3{2q ¨ ¨ ¨ pp´2n ` 1q{2q


Cn “ ´ p´1qn`1 4n`1 .
2 pn ` 1q!

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

If we multiply the numerator and denominator by n! and keep in mind that


n!2n “ 2 ¨ 4 ¨ 6 ¨ ¨ ¨ 2n, then we can rewrite this expression in the form
ˆ ˙
p2nq! 1 2n
Cn “ “ ,
pn ` 1q!n! n`1 n
which proves our claim.

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.

14.1 Undirected Graphs


Recall that a graph is a pair pV, Eq of sets such that the 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 the edges of the graph. Given a graph G, we will
denote by V pGq the set of vertices and by EpGq the set of edges. This notation
is particularly useful when dealing with multiple graphs at the same time.
We will focus on graphs that have a finite number of vertices. The number
of vertices of a graph is called the order of the graph, and the number of edges
is called the size of the graph.
Graphs have an abundance of applications. For instance, subway maps are
often colorful depictions of graphs. They rarely give an accurate representation
of distances, but show how to get from one station to another. Figure 14.1
shows a small example of a subway map. The underlying graph distills some

© The Author(s), under exclusive license to Springer Nature 349


Switzerland AG 2025
A. Klappenecker, H. Lee, Discrete Structures, Undergraduate Texts in
Mathematics, https://doi.org/10.1007/978-3-031-73434-2 14
350 14 Graphs

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

V “ tv1 , v2 , v3 , v4 u of vertices and the edge set

E “ ttv1 , v2 u, tv1 , v3 u, tv1 , v4 u, tv2 , v4 u, tv3 , v4 uu.

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

We denote by ΔpGq the maximal degree of G, which is defined as

ΔpGq “ maxtdeg v | v P V u.

The next example illustrates a relationship between the number of edges


and the sum of the degrees of the vertices of a graph.
Example 14.3. Suppose that there are n people p1 , p2 , . . . , pn at a party. We
keep track of who shook hands with whom by a graph pV, Eq. Thus, the vertex
set V is given by the set of people V “ tp1 , p2 , . . . , pn u that attended the party.
The edge set E contains a pair tpk , p u if and only if pk and p shook hands.
In general, not everyone will shake hands with everyone else. So how can we
count the number h of handshakes? We certainly could ask every person how
many hands they shook, so this gives us the degree of every person. Adding
them all up gives us

2h “ deg p1 ` deg p2 ` ¨ ¨ ¨ ` deg pn ,

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

2|E| “ deg p1 ` deg p2 ` ¨ ¨ ¨ ` deg pn

between the number of edges and the sum of the degrees in G.


The handshake example applies to arbitrary graphs with a finite number of
vertices.
Proposition 14.4 (Handshaking Lemma). Let G “ pV, Eq be a graph of order
n and size m. Then ÿ
2m “ deg v.
vPV

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

Dividing all terms by n yields

δpGq ď 2m{n ď ΔpGq,

which implies δpGq ď t2m{nu and ΔpGq ě r2m{ns.

Let G “ pV, Eq be a graph with a finite set V of vertices. The graph G is


called k-regular if and only if every vertex has degree k. In other words, a
graph G is k-regular if and only if k “ δpGq “ ΔpGq.

Corollary 14.5. Let G “ pV, Eq be a k-regular graph with n vertices. Then G


has kn{2 edges.

Proof. By the Handshaking Lemma, the number m of edges of G satisfies


ÿ
2m “ deg v “ kn,
vPV

which implies the claim.

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.2. How many graphs are there that have n vertices?

14.3. Does there exist an undirected graph G with seven vertices v1 , v2 , . . . , v7


such that
deg v1 “ 1, deg v2 “ 2, deg v3 “ 3, . . . , deg v7 “ 7?
Explain your answer.

14.4. Does there exist an undirected graph G with seven vertices v1 , v2 , . . . , v7


such that

deg v1 “ 0, deg v2 “ 2, deg v3 “ 2, deg v4 “ 4, deg v5 “ 4, deg v6 “ 4, deg v7 “ 6?

Explain your answer.

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.6. Suppose that G is a graph with 12 vertices and 30 edges. It contains 2


vertices of degree 4, 1 vertex of degree 5, 4 vertices of degree 6, and 2 vertices
of degree 7. All other vertices have the same degree d. What is the degree d?
354 14 Graphs

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.9. Let a and b be adjacent vertices in a graph G.


(a) How many vertices can be in N paq Y N pbq?
(b) How many vertices can be in N paq X N pbq?

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.

14.2 Common Graphs


In this section, we will discuss a number of families of graphs that occur fre-
quently in applications. These families of graphs are part of the basic vocabu-
lary of graph theory. We will also introduce some basic constructions of graphs
that allow us to form more elaborate graphs from such basic primitives.
We begin with a very simple example. The empty graph En is a graph
with n vertices and no edges. Distinct vertices are not adjacent in the empty
graph En . Since every vertex has degree 0, this is a 0-regular graph. Figure 14.3
shows an example of an empty graph.

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

E “ ttvk , vk`1 pmodnq u | 0 ď k ď n ´ 1u.

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.5: The cycle graphs C3 , C4 , C5 , and C6

The complete graph Kn on n vertices is a graph with vertex set V “


t0, 1, . . . , n ´ 1u and edge set E “ tta, bu | a, b P V, a ‰ bu. The complete graph
contains an edge between any two distinct vertices. The complete graph Kn is
pn ´ 1q-regular, since each vertex is adjacent to each of the other n ´ 1 vertices.
Figure 14.6 shows some examples of small complete graphs.

Figure 14.6: The complete graphs K1 , K2 , K3 , K4 , and K5

A graph G “ pV, Eq is called bipartite if and only if the set of vertices


can be partitioned into two disjoint subsets V1 and V2 such that every edge
joins a vertex in V1 with a vertex in V2 . In other words, the set of edges is
restricted such that no edge connects two vertices in V1 and no edge connects
two vertices in V2 . This implies that the neighbors of a vertex in V1 are in V2 ,
and the neighbors of a vertex in V2 are in V1 . The sets V1 and V2 are called
the partite classes of the bipartite graph. Figure 14.7 illustrates the concept
of bipartite graph in the case of cyclic graphs.
356 14 Graphs

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

The complete bipartite graph Km,n has the vertex set


V “ ta1 , a2 , . . . , am u Y tb1 , b2 , . . . , bn u
and the edge set E “ ttak , b u | 1 ď k ď m, 1 ď  ď nu. The graph Km,n
is indeed bipartite, since every edge is incident with one a-vertex and one b-
vertex. The graph Km,n has order m ` n and size mn. Figure 14.8 shows the
complete bipartite graph K3,5 .

Figure 14.8: The complete bipartite graph K3,5

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.9: The graph K1,6 is also known as a star graph

There are various operations that allow us to construct more elaborate


graphs from one or more given graphs.
Let T denote the set of all 2-element subsets of V . The complement of a
graph G “ pV, Eq is the graph G “ pV, T zEq that has the same vertex set and
the edges that are missing in G as an edge set. In other words, two vertices are
adjacent in the complementary graph G if and only if they are not adjacent
in the graph G. For instance, the complement of the empty graph En is the
complete graph Kn “ En . Another example of a graph and its complement is
shown in Fig. 14.10.
14.2 Common Graphs 357

Figure 14.10: The graph C5 is shown on the left and its complementary graph C5
on the right

Suppose that G1 “ pV1 , E1 q and G2 “ pV2 , E2 q are two undirected graphs.


The Cartesian product G1  G2 is the graph with vertex set V1 ˆ V2 such
that two vertices pu1 , v1 q and pu2 , v2 q in V1 ˆ V2 are adjacent if and only if
either (a) u1 “ u2 and pv1 , v2 q P E2 or (b) pu1 , u2 q P E1 and v1 “ v2 holds.
For instance, the product of the path graph Pm and the path graph Pn is
the grid graph Pm  Pn . An example of the grid graph is shown in Fig. 14.11.

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

The n-dimensional hypercube graph Qn is the graph of order 2n that


is obtained by repeatedly forming the Cartesian product of n copies of the
complete graph K2 , so
K2  K 2  ¨ ¨ ¨  K 2 .
Qn “ loooooooooooomoooooooooooon
n copies of K2

The hypercube Qn is an n-regular graph of order 2n and size n2n´1 . Fig-


ure 14.12 shows some examples of hypercube graphs of small dimension.

Figure 14.12: The figure shows the hypercubes Q1 , Q2 , Q3 , and Q4

Given a graph G and a positive integer k, we denote by kG the graph given


by the disjoint union of k copies of G. We can also construct kG by forming
the Cartesian product of the empty graph Ek with G,
kG “ Ek  G.
358 14 Graphs

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 .

14.3 Connected Graphs


Exploring a graph by walking along the edges in various ways can give valuable
insights about the nature of the graph. We introduce the important class of
connected graphs and some sufficient conditions that ensure connectivity.
A walk from a vertex u to a vertex v in an undirected graph G “ pV, Eq
is an alternating sequence of vertices and edges that begins with the vertex u
and ends with the vertex v such that each edge is incident with the vertices
preceding and following the edge. In other words, a walk from u to v is a
sequence
pv0 , e1 , v1 , e2 , v2 , . . . , ek , vk q (14.1)
of vertices v0 , v1 , . . . , vk in V and edges e1 , e2 , . . . , ek in E such that the start
vertex v0 equals u and the end vertex vk equals v and the edges are of the form
em “ tvm´1 , vm u for all m in the range 1 ď m ď k. One should note that an
edge or a vertex can occur multiple times in a walk. The number of edges that
are traversed on a walk is called the length of the walk. For instance, the walk
given in (14.1) has length k. Figure 14.13 illustrates a walk in a grid graph.
A trail from a vertex u to a vertex v is a walk from u to v that does not
contain repeated edges. A trail might still contain a vertex multiple times. A
circuit is a trail from a vertex u to itself. By definition, a circuit does not
contain an edge twice, but may contain repeated vertices (even in addition to
the vertex u). Figure 14.14 gives an example of a trail in a grid graph.
A path from a vertex u to a vertex v in a graph is a walk without repeated
vertices. A path is in particular a trail. A cycle is a circuit that does not
14.3 Connected Graphs 359

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

then G is a connected graph.

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.

The next proposition is in a similar spirit, but has a hypothesis that is


easier to check.

Proposition 14.7. Let G “ pV, Eq be a graph of order n. If ΔpGq ` δpGq ě


n ´ 1, then G is a connected graph.

Proof. Let v be a vertex of maximal degree, deg v “ ΔpGq. It suffices to show


that for every vertex u in V ztvu, there exists a path from u to v.
Let u be an arbitrary vertex in V ztvu. If u is adjacent to v, then there is a
path from u to v.
If u is not adjacent to v, then deg u ` deg v ě δpGq ` ΔpGq ě n ´ 1. Since
there are n ´ 2 nodes in V ztu, vu, and the number of edges from tu, vu to
V ztu, vu is at least n ´ 1, there must be at least one vertex w in V ztu, vu that
is adjacent to both u and v by the pigeonhole principle. Thus, there is a path
from u to v.
If u and u1 are arbitrary vertices of G, then there is a path from u to the
vertex v of maximal degree that we have singled out, and one from this vertex v
to u1 , so there is a path from u to u1 . Therefore, the graph G is connected.

Given a graph G “ pV, Eq and vertices u and v in V , we write u ” v if and


only if there is a path from u to v. The relation ” is reflexive, symmetric, and
transitive. Therefore, ” is an equivalence relation on V . We encourage the
reader to prove this simple fact, see Exercise 14.18. The equivalence class Cu
containing a vertex u is called a component of the graph. We have

Cu “ tv P V | u ” vu.

We denote by kpGq the number of components of the graph G.

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

Suppose that G “ pV, Eq is an undirected graph and e is an edge of G. We


denote by G ´ e the graph pV, Ezteuq. In other words, G ´ e has the same
vertex set as G and all the edges of G with the exception of e.
We call an edge e of a graph G a bridge if and only if kpG ´ eq ą kpGq.
Evidently, an edge e of a graph G is a bridge if and only if it is not part of any
cycle in G.
The distance dpu, vq between vertices u and v of a graph is the length of
the shortest path between them. We set dpu, vq “ 8 if and only if there does
not exist a path from u to v.
In a connected graph G “ pV, Eq, the distance is a metric, since the distance
is a nonnegative function V ˆ V Ñ R such that for all vertices u, v, w in V it
satisfies

M1. the identity of indiscernibles, meaning dpu, vq “ 0 if and only if u “ v,

M2. the symmetry condition dpu, vq “ dpv, uq,

M3. and the triangle inequality, dpu, vq ` dpv, wq ě dpu, wq.

The diameter dpGq of a graph G is the maximum distance between any


two vertices
dpGq “ max dpu, vq.
u,vPV pGq

In a connected graph G, the diameter of G is the maximum length among all


shortest paths between any pair of vertices in G.

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.18. Let G “ pV, Eq be an undirected graph. Let ” be the relation on the


set of vertices V given by u ” v if and only if there is path from u to v. Show
that ” is an equivalence relation.

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.20. Let G “ pV, Eq be `a graph


˘ of order n and size m. Show that if the size
of the graph satisfies m ą n´1
2 , then G must be connected.

14.21. Suppose that G “ pV, Eq is a disconnected graph. Prove that its


complementary graph G must be connected.

14.22. Suppose that G “ pV, Eq is a connected graph. Prove or disprove: The


complementary graph G is disconnected.

14.23. Determine the diameter of


(a) the empty graph En ,
362 14 Graphs

(b) the path graph Pn ,


(c) the cycle graph Cn ,
(d) the complete graph Kn ,
(e) the complete bipartite graph Km,n ,
(f) the hypercube Qn of order 2n .
You can assume that m and n are positive integers.

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.

Figure 14.16: A tree of order 7 and size 6

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. Seeking a contradiction, let us assume that T “ pV, Eq is a tree that


has two vertices u and v, which are connected by two distinct paths A and
B. This implies that there exists a cycle consisting of edges from A and B,
contradicting the fact that a tree does not contain any cycles.

In a tree, a vertex of degree 1 is called a leaf . A vertex in a tree that is


not a leaf is called an internal vertex or internal node.

Proposition 14.10. A tree T of order n ě 2 has at least two leaves.

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.

Figure 14.16 shows an example of a tree with 7 vertices and 6 “ 7 ´ 1 edges.


In general, any tree of order n will have size n´1, as the next proposition shows.
14.4 Trees 363

Proposition 14.11. A tree of order n must have size m “ n ´ 1.

Proof. We prove the claim by induction on the order n.


Induction Basis If the order of the tree is n “ 1, then there are no edges, so
the size of the tree is indeed n ´ 1 “ 0.
Induction Step Let us suppose that the claim holds for all trees of order n or
less. Suppose that T is a tree of order n ` 1. Let e be an edge of T . Since the
edge e is not part of any cycle, it must be a bridge. Therefore, T ´e decomposes
into two components Ta and Tb . Since each component is cycle-free, they are
both trees. Suppose that the order of Ta is a and the order of Tb is b. The sum
of these orders give us the order of T , so

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

EpT q “ EpTa q Y EpTb q Y teu,

the size of T is given by

pa ´ 1q ` pb ´ 1q ` 1 “ a ` b ´ 1 “ n.

Therefore, the claim follows by induction on n.

A graph H is called a subgraph of a graph G if and only if its set of


vertices satisfies V pHq Ď V pGq and its set of edges satisfies EpHq Ď EpGq. A
subgraph H of G is called spanning if and only if their vertex sets are the
same, V pHq “ V pGq. A spanning subgraph that happens to be a tree is called
a spanning tree.
Proposition 14.12. Every connected graph G has at least one spanning tree.

Proof. Let S denote the family of connected spanning subgraphs of G, ordered


by inclusion. Choose a minimal element T of S. Then T must be a spanning
tree of G. Indeed, if T would contain a cycle, then we could delete an edge e
from this cycle and T ´ e would be a connected spanning graph, contradicting
the minimality of T .

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

14.27. Show that a connected graph G of order n and size n ´ 1 must be a


tree.
14.28. Determine the set consisting of all trees T such that their complement
T is a tree as well.

14.5 Planar Graphs


A graph G is called planar if and only if it can be represented in the plane
such that edges do not intersect except in end points. Even though some
representations of the graph might have intersections of edges, the definition
of a planar graph guarantees that there exists some way of drawing the edges
using curves that do not intersect.
Example 14.13. The complete graph K4 of order 4 is planar. Indeed, the
next figure shows on the left-hand side how we drew K4 earlier with two edges
crossing. However, the right-hand side illustrates that there is a way to draw
K4 without crossing edges.

We can conclude that K4 is a planar graph.


Example 14.14. The complete graph K5 of order 5 is not planar.

Any representation of K5 in the plane requires that some edges cross. We


will later discover a simple proof of this fact.
14.5 Planar Graphs 365

If a planar graph is represented in the plane without edges crossing, then


it divides the plane into regions that are called faces. The faces are maximal
open regions of the plane that are bounded by the edges of the graph. There
exists always one face that is unbounded, surrounding the graph. The concept
of faces is best illustrated with a small example.

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.

A drawing of a planar graph in the plane without crossings is called a plane


graph. So a plane graph is one particular representation of a planar graph.

Proposition 14.16 (Euler’s Formula). If a connected plane graph G has order


n, size m, and f faces, then

n ´ m ` f “ 2.

Proof. We will argue by induction on the number of faces. If we have a single


face, so f “ 1, then the graph G cannot contain a cycle. In other words, G
must be a tree. A tree with n vertices has m “ n ´ 1 edges. Therefore, we
indeed have
n ´ m ` f “ n ´ pn ´ 1q ` 1 “ 2,
so Euler’s formula holds in this case.
Suppose that we have more than one face, f ą 1, and the result holds for
a smaller number of faces. Since we have more than one face, there must be a
cycle. Choose an edge e “ tu, vu in a cycle of G. The cycle encloses a face. Let
us create a new graph G ´ e that is obtained from G by removal of the edge e.
The edge e must have separated two faces, so the graph G ´ e has order n, size
m ´ 1 and f ´ 1 faces. By induction hypothesis, G ´ e satisfies Euler’s formula

n ´ pm ´ 1q ` pf ´ 1q “ 2.
366 14 Graphs

Simplifying shows that


n´m`f “2
holds, which is Euler’s formula for the graph G.

It follows from the previous proposition that any two representations of a


planar graph by plane graphs must have the same number of faces.
A maximal planar graph is a planar graph to which one cannot add
any edge without losing planarity. Maximal planar graphs with at least three
vertices have the property that the boundary of every
` face
˘ is a triangle.
In general, a graph G of order n has at most n2 “ Θpn2 q edges. By
contrast, a connected planar graph of order n has at most Opnq edges as the
next proposition shows.

Proposition 14.17. Let G be a planar graph of order n and size m, where


n ě 3. Then
m ď 3n ´ 6.
If G is a maximal planar graph, then equality holds.

Proof. Without loss of generality, we may assume that G is a maximal planar


graph. Indeed, if G is not a maximal planar graph, then we can add edges
without changing the order of the graph.
In a plane embedding of a maximal planar graph, every face is bounded by
exactly three edges. On the other hand, every edge is on the boundary of two
faces. Therefore, the number of (face, edge) pairs satisfies 3f “ 2m. By Euler’s
formula, n ´ m ` f “ 2, so n ´ m ` 23 m “ n ´ 13 m “ 2. Multiplying both sides
of this equality by 3, we get 3n ´ m “ 6 or m “ 3n ´ 6. We can conclude that
an arbitrary (not necessarily maximal) planar graph satisfies m ď 3n ´ 6.

Corollary 14.18. Every planar graph has at least one vertex of degree 5 or
less.

Proof. Seeking a contradiction, let’s assume that G is a planar graph of order


n and size m such that every vertex has degree 6 or more. By the Handshaking
Lemma, we would have 2m ě 6n, so m ě 3n. However, any planar graph
satisfies m ď 3n ´ 6, leading to the contradiction 3n ď 3n ´ 6.

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.

14.6 Graph Coloring


A political map is supposed to show the governmental boundaries of countries,
states, or counties. Good maps use several distinct colors so that one can
easily differentiate between countries, states, or counties. Figure 14.17 shows
the states of the western half of the United States. The states are colored such
that neighboring states do not share the same color, except when they merely
share a corner. Remarkably, very few colors are needed to color any map. This
was observed in 1852 by the student Francis Guthrie, and his brother related
the observation to De Morgan. Soon it was mathematical folklore that any
map can be colored with at most four colors, but a proof remained elusive. In
fact, it took more than a 100 years until it was proven in 1977 by Haken and
Appel using a computer-aided proof. The proof remained a bit controversial,
since it was too long to be checked by humans. Meanwhile, Gonthier obtained
a shorter computer-aided formal proof.
The search for a proof of the four-color theorem spurred the development of
graph theory. One can easily relate the map coloring problem to the coloring
of planar graphs. For a given map of states, we can find an associated graph as
follows. Each state is represented by a vertex. Two vertices are joined by an
edge if and only if the corresponding states share a border. The map coloring
problem is now translated in a vertex coloring problem of the corresponding
368 14 Graphs

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

We must use at least two colors in any vertex coloring of Pn with n ě 2,


since the graph has at least one edge. Therefore, χpPn q “ 2, as claimed.

Example 14.22. The complete graph Kn on n vertices has chromatic number


χpKn q “ n. Indeed, since there is an edge between any pair of vertices, the
colors for the vertices must be pairwise different. Therefore, n different colors
are needed in a vertex coloring of Kn .

Example 14.23. The cycle graph Cn with an even number n ě 2 of vertices


has chromatic number χpCn q “ 2, since we obtain a valid vertex coloring if we
assign vertices with even index the color black and with odd index the color
white, so χpCn q ď 2. Furthermore, Cn contains an edge, so χpCn q ě 2.
The cycle graph Cn with an odd number n ě 3 of vertices has chromatic
number χpCn q “ 3. Indeed, we can color Cn with three colors by assigning the
vertex with index 0 to be gray, the vertices with even nonzero index the color
black, and the vertices with odd indices the color white, whence χpCn q ď 3.
Since Cn has an edge, we have χpCn q ě 2. We cannot color Cn with merely
370 14 Graphs

two colors, since Cn is not bipartite when n is odd. Therefore, χpCn q “ 3 when
n is odd and n ě 3.

Let’s have a look at some general properties of vertex colorings. We begin


with a very simple observation.

Proposition 14.24. Let H be a subgraph of a graph G. Then χpHq ď χpGq.

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.

A clique in a graph G is a subgraph of G that happens to be a complete


graph. An immediate consequence of the previous proposition is that if a graph
G contains a clique of order k, then

χ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.

Proof. Suppose that the vertex set of G is of the form tv1 , v2 , . . . , vn u. We


choose C “ t1, 2, . . . , ΔpGq ` 1u as a set of colors. We are going to assign
colors from C to the vertices in the order of the indices.
We assign v1 the color 1. We can inductively assign colors to the re-
maining vertices. Suppose that we already have colored the vertices Pk´1 “
tv1 , v2 , . . . , vk´1 u. Then we can color the vertex vk with the smallest color in C
that is not contained in the colors of its neighboring vertices in N pvk q X Pk´1 .
Since vk has at most ΔpGq neighbors in N pvk q X Pk´1 , there is always a color
available.
This vertex coloring shows that G can be colored with at most 1 ` ΔpGq
colors. Therefore, we can conclude that χpGq ď 1 ` ΔpGq, as claimed.

A subset I of the set of vertices of a graph G is called independent if and


only if no two vertices in I are adjacent. A maximum independent set is an
independent set of largest possible cardinality in a graph. The independence
number αpGq of a graph is the cardinality of a maximum independent set in
the graph G.
If c : V Ñ C is vertex coloring of a graph, then the set Vk of all vertices of
color k,
Vk “ tv | cpvq “ ku,
14.6 Graph Coloring 371

is a color class of G. Each color class is an independent set. Furthermore,


the set V pGq is partitioned into pairwise disjoint color classes
ď
V pGq “ Vk .
kPC

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.

Proposition 14.26. Let G be a graph with n vertices. Then the chromatic


number χpGq is bounded by
R V
n
ď χpGq ď n ´ αpGq ` 1.
αpGq

Proof. Let I be a maximal independent set of G. We can color all vertices in I


with the same color, say 1. The remaining n´αpGq vertices can be colored with
pairwise distinct numbers greater than 1. This is a coloring with n ´ αpGq ` 1
colors, which shows that

χ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.

Proposition 14.27. A planar graph can be colored with at most 5 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

Figure 14.19: One particular embedding of the neighborhood of v in the plane

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

Case 2. If u1 and u4 are contained in the same component of H1,4 , then


there must exist a path P from u1 to u4 consisting of nodes that are alternat-
ingly colored 1 and 4. The path P together with the path pu4 , v, u1 q forms a

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

14.39. A graph G is called a k-critical graph if and only if χpGq “ k, but


χpHq ă k for all subgraphs H of G. Show that a k-critical graph satisfies
δpGq ě k ´ 1.

14.7 Hamiltonian Cycles and Paths


A Hamiltonian cycle in a graph G is a cycle that contains every vertex of G.
A graph G that contains a Hamiltonian cycle is called a Hamiltonian graph.
In the first chapter, we encountered Hamiltonian cycles on knight graphs in
the form of closed knight’s tours.

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

A path in a graph G that contains every vertex of G is called a Hamilto-


nian path. Every Hamiltonian graph contains a Hamiltonian path, as simply
deleting one edge of the Hamiltonian cycle yields a Hamiltonian path. On the
other hand, there exist graphs that contain a Hamiltonian path, but do not
have a Hamiltonian cycle. Indeed, the graph on the right in Fig. 14.22 has the
Hamiltonian path pv6 , v1 , v0 , v5 , v4 , v3 , v2 q, but does not contain a Hamiltonian
cycle.
The next theorem gives a sufficient condition for the existence of a Hamil-
tonian cycle given that the graph contains sufficiently many edges. However,
the edges need to be distributed well-enough. The Norwegian mathematician
Øystein Ore formulated a condition that looks at two non-adjacent vertices.
Since they are not directly connected by an edge, Ore ensured that they can
be reached by connecting them to at least n other vertices. If one of the two
nodes has a small degree, then the other node must offer a high degree.
Theorem 14.28 (Øystein Ore). Let G “ pV, Eq be a graph with n ě 3 vertices
that satisfies
deg u ` deg v ě n (14.2)
for all non-adjacent vertices u and v in V . Then G is a Hamiltonian graph.

Proof. Seeking a contradiction, suppose that G is a graph satisfying the Ore


condition (14.2) that does not contain a Hamiltonian cycle. We may assume
that G contains a maximal number of edges among all graphs with n vertices
that satisfy (14.2) and do not have a Hamiltonian cycle.
Then G is extremal in the sense that it contains a Hamiltonian path, say

pv1 , v2 , . . . , vn q,
14.7 Hamiltonian Cycles and Paths 375

but not a Hamiltonian cycle. Indeed, a graph G without even a Hamiltonian


path would allow one to add an edge to G without creating a Hamiltonian
cycle, contradicting the maximality of the number of edges in G.
Since the graph G is not Hamiltonian, the vertices v1 and vn are not ad-
jacent, as this would imply the existence of a Hamiltonian cycle. By the Ore
condition,
deg v1 ` deg vn ě n.
Now consider all n ´ 1 pairs of vertices P “ tpvk´1 , vk q | 2 ď k ď nu on
the Hamiltonian path. By the Pigeonhole principle, there must exist a pair
pvk´1 , vk q in P such that vk´1 is adjacent to vn , and vk is adjacent to v1 . It
follows that the cycle

pv1 , v2 , . . . , vk´1 , vn , vn´1 , . . . , vk , v1 q

is a Hamiltonian cycle, contradicting the assumption that G does not contain


a Hamiltonian cycle.

Ore’s theorem allows us to assert the existence of a Hamiltonian cycle in


a graph. All we need to check is that the sum of the degrees of pairs of non-
adjacent vertices is large. If a graph does not have such a large number of edges,
then deciding whether the graph has a Hamiltonian cycle can become a chal-
lenge. In particular, the proof that a given graph does not have a Hamiltonian
cycle can become quite involved.
There exists a remarkable theorem by the Latvian mathematician Emanuel
Grinberg that gives a necessary condition for the existence of Hamiltonian
cycles for planar graphs. Grinberg’s theorem can be used to show that a planar
graph does not have a Hamiltonian cycle.
Let G be a plane graph with a Hamiltonian cycle C. An edge of G that
does not lie on the Hamiltonian cycle C is called a chord. A chord either lies
in the interior or exterior of C. Similarly, every face of the plane graph G is
either inside or outside of C.
Example 14.29. Consider the plane graph G with 10 vertices and 15 edges
shown below. This graph has a Hamiltonian cycle that is shown with thick
edges.
376 14 Graphs

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

Proof. Suppose that c chords of G lie in the interior of C and c1 chords of G


lie in the exterior of C. Then there are c ` 1 faces interior to C and c1 ` 1 faces
exterior to C. Therefore, we can conclude that
n
ÿ n
ÿ
fk “ c ` 1 and fk1 “ c1 ` 1.
k“3 k“3
1
In other words, c and c can be expressed in the form
n
ÿ n
ÿ
c“ fk ´ 1 and c1 “ fk1 ´ 1.
k“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

We can rewrite these equations in the form


n
ÿ n
ÿ
pk ´ 2qfk “ n ´ 2 and pk ´ 2qfk1 “ n ´ 2.
k“3 k“3

From these two equations, we can deduce


n
ÿ
pk ´ 2qpfk ´ fk1 q “ pn ´ 2q ´ pn ´ 2q “ 0,
k“3

which proves our claim.

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

1pf3 ´ f31 q ` 4pf6 ´ f61 q “ 0.

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

does not have a Hamiltonian cycle.


14.49. Deduce with the help of Grinberg’s theorem that the plane graph

does not have a Hamiltonian cycle.


14.50. Suppose that G is a plane graph such that its unbounded face has a
border with 15 edges. All other faces are bordered by 4-cycles, 6-cycles, or
8-cycles. Use Grinberg’s Theorem to show that the graph G cannot contain a
Hamiltonian cycle.
380 14 Graphs

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.

[Hint: After setting up Grinberg’s equation, it is a good strategy to find


a positive integer M such that reducing the equation modulo M yields few
terms.]
Chapter 15

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

In this chapter, we will introduce basic notions of probability theory. We discuss


sample spaces and probability measures. We introduce conditional probabil-
ities and discuss independent events. Then we explore random variables and
expectation. We conclude the chapter with some examples that illustrate the
probabilistic method.

15.1 Probability Spaces


Probability theory allows us to deal with uncertainty in a quantitative way.
The main object of study in probability theory is experiments with outcomes
that are subject to chance. For example, tossing a coin yields either heads or
tails as outcomes. Rolling a die yields the face values 1, 2, 3, 4, 5, or 6 as
outcomes. These experiments have in common that one cannot predict with
certainty the outcome of the experiment.
The set of outcomes of an experiment is called its sample space. We will
typically denote the sample space by Ω. In this chapter, we will assume that
the sample spaces are discrete, meaning Ω is either finite or countably infinite.
This simplifies the theory a little bit.
A subset of the sample space is called an event. For instance, the sub-
set A “ t1, 3, 5u of the sample space Ω “ t1, 2, 3, 4, 5, 6u describes the event
that the outcome of rolling a die results in an odd face value. The event
B “ t1, 2, 3, 4u describes the event that the face value of the die is at most 4.
Events given by singleton sets are called elementary events. For instance,
the elementary event t6u describes that face value of 6 is the outcome of a die
roll.

© The Author(s), under exclusive license to Springer Nature 381


Switzerland AG 2025
A. Klappenecker, H. Lee, Discrete Structures, Undergraduate Texts in
Mathematics, https://doi.org/10.1007/978-3-031-73434-2 15
382 15 Probability Theory

The sample space Ω can be viewed as an event, as it is a subset of itself,


and is referred to as the certain event. The empty set H is also an event,
called the impossible event. Two events A and B are called disjoint if and
only if no outcome is common to both events; in other words, A and B are
disjoint if and only if A X B “ H.
A probability measure is a function that assigns to an event the probability
of this event. In more detail, a probability measure Pr on a sample space Ω
is a function Pr : P pΩq Ñ r0, 1s satisfying the following two axioms
P1 The certain event satisfies PrrΩs “ 1.
P2 If the events E1 , E2 , . . . in P pΩq are pairwise disjoint (meaning that the
events Ei and Ek do not have elements in common when the indices i and
k are not the same), then
8
ď ÿ8
Prr Ek s “ PrrEk s.
k“1 k“1
The two axioms are there to ensure consistency among these assignments of
probabilities. For instance, we will see shortly that if A and B are events such
that A Ď B, then PrrAs ď PrrBs. So the probability measure is monotonic.
The largest values must thus be assigned to the sample space, which contains
all events. The axiom P1 ensures that the largest probability is normalized to
PrrΩs “ 1.
Since a discrete sample space is a countable set, it is a countable union of
elementary events, cf. Proposition 3.55. Therefore, all probability measures on
a discrete sample space can be obtained by assigning probabilities to elementary
events. This is detailed in the next remark.
Remark 15.1. Let Ω be a finite or countably infinite nonempty set. Let p : Ω Ñ
r0, 1s be a function such that
ÿ
ppxq “ 1.
xPΩ
For a subset A of Ω, we define
ÿ
PrrAs “ ppxq.
xPA
Then Pr is a probability measure on Ω. In particular, an elementary event
txu, with x P Ω, is assigned the probability ppxq. Since a discrete sample space
is the countable union of elementary events, the sum of the probabilities of
elementary events must add up to 1.
For a finite sample space, this method of assigning probabilities to elemen-
tary events is particularly straightforward. The next example details the simple
instance of rolling a die.
Example 15.2. Let Ω “ t1, 2, 3, 4, 5, 6u be the sample space of face values of
a die. If we assign the same probabilities to each of the elementary events,
1 1 1
Prrt1us “ , Prrt2us “ , . . . , Prrt6us “ ,
6 6 6
15.1 Probability Spaces 383

then the compound event A “ t1, 3, 5u has the probability

|A| 3 1
PrrAs “ “ “ .
|Ω| 6 2

More generally, an arbitrary subset B of Ω has probability |B|{|Ω| “ |B|{6, the


number of elements in the compound event B divided by 6.
More generally, we can define a probability measure on any finite sample
space by assigning each elementary event the probability 1{|Ω|. We will study
such uniform probability distributions in the next section.
On a countably infinite sample space, one cannot assign a uniform proba-
bility to elementary events. However, one can use convergent series to define
probability measures, as the next example shows in a particular instance.
Example 15.3. Let Ω “ N1 be the set of positive integers. Leonard Euler
famously showed that the sum of the squares of the reciprocals of positive
integers converges to π 2 {6, so
8
ÿ 1 1 1 1 π2
2
“ 2 ` 2 ` 2 ` ¨¨¨ “ .
k“1
k 1 2 3 6

Therefore, we can obtain a probability measure on Ω “ N1 by assigning to the


elementary event tku, where k is a positive integer, the probability

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

so PrrΩs has the proper normalization to 1.

Kolmogorov introduced these remarkably simple axioms of probability the-


ory. There is a remarkable amount of information packed into the axioms P1
and P2, as will become evident in the next few propositions.

Proposition 15.4. Let Ω be a discrete sample space.


(a) The impossible event H satisfies PrrHs “ 0.
(b) Let n be a positive integer and E1 , E2 , . . . , En be disjoint events in P pΩq.
Then
ÿn
PrrE1 Y E2 Y ¨ ¨ ¨ Y En s “ PrrEk s.
k“1
A
(c) An event E satisfies PrrE s “ 1 ´ PrrEs.
(d) The probability measure is monotonic, meaning that if A and B are events
such that A Ď B, then PrrAs ď PrrBs.
384 15 Probability Theory

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

As PrrE1 s “ 1, we must have PrrEk s “ 0 for all k ě 2. So PrrHs “ 0.


(b) In axiom P2, if we choose Ek “ H for all k ě n ` 1, then
« ff
8
ď ÿ8 n
ÿ
PrrE1 Y E2 Y ¨ ¨ ¨ Y En s “ Pr Ek “ PrrEk s “ PrrEk s,
k“1 k“1 k“1

where we used part (a) in the last equality.


(c) We have PrrEs ` PrrE A s “ PrrE Y E A s “ PrrΩs “ 1. This implies the
claim.
(d) The set B is the disjoint union of A and AA X B. Therefore,
PrrBs “ PrrA Y pAA X Bqs “ PrrAs ` PrrAA X Bs.
It follows that PrrAs ď PrrBs.

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

Proof. The proof is simple but instructive, see Exercise 15.1.


Another consequence is a simple form of the inclusion-exclusion principle.
Proposition 15.6. Let E and F be events. Then
PrrE Y F s “ PrrEs ` PrrF s ´ PrrE X F s,
This fact can be convenient when calculating probabilities.
Proof. We can decompose E Y F into the disjoint union of the three events
EzpE X F q, E X F , and F zpE X F q. Therefore, we have
PrrE Y F s “ PrrEzpE X F qs ` PrrE X F s ` PrrF zpE X F qs
“ PrrEs ` PrrF zpE X F qs ` pPrrE X F s ´ PrrE X F sq
“ PrrEs ` PrrF s ´ PrrE X F s,
where the second equality holds, since 0 “ PrrE X F s ´ PrrE X F s.
15.2 Combinatorial Probability 385

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.

15.3. Let E1 , E2 , . . . , En be events. Show that


« ff « ff
n
ď čn
Pr Ek ` Pr EkA “ 1.
k“1 k“1

15.4. Let n be an integer satisfying n ě 2. Let E1 , E2 , . . . , En be events. Show


that the general inclusion-exclusion principle
« ff
ďn ÿn ÿ ÿ
Pr Ek “ PrrEk s ´ PrrEi X Ej s ` PrrEi X Ej X Ek s
k“1 k“1 iăj iăjăk

` ¨ ¨ ¨ ` p´1qn`1 PrrE1 X E2 X ¨ ¨ ¨ X En s

holds. Use a proof by induction.

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
Ω.

15.2 Combinatorial Probability


In this section, we confine ourselves to a particularly simple situation. We
consider experiments that have a finite number of different outcomes that are
all equally likely. The prototypical example is the flipping of a fair coin that
has the same odds of showing heads as it has showing tails.
In general, suppose that the experiment has outcomes that belong to a
finite set Ω that we will call the sample space. The probability PrrEs that the
outcome of the experiment will belong to a subset E of Ω is given by

|E|
PrrEs “ .
|Ω|
386 15 Probability Theory

We call Pr the uniform probability measure.


Since the uniform probability measure is nothing but a normalized counting
measure, it is not surprising that determining PrrEs often boils down to a
counting argument.

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

Now everyone knows that it is difficult to keep your ducks in a row. It is


nearly impossible when two Ducks in Black are next to each other, since they
quip so much in fowl language that this delays the start of the race. So the
organizers want to know: How likely is it that the starting lineup does not
contain two adjacent Ducks in Black?
There are two choices for each of the n positions, so there are a total of 2n
different starting lineups.
How many of these starting lineups do not contain adjacent Ducks in Black?
If there is just one team participating, then both possible starting lineups do
not contain adjacent Ducks in Black. If there are n “ 2 teams, then there are
exactly three starting lineups that do not contain two adjacent Ducks in Black,
namely

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.7. Suppose that you flip a fair coin three times.


(a) Determine the sample space of this random experiment (use H to denote
heads and T to denote tails).
(b) What is the probability to get all heads?
(c) What is the probability to get two heads?
(d) What is the probability to get one head?
(e) What is the probability to get at least two heads?
(f) What is the probability to get at most one head?

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.9. Suppose that you roll a pair of dice.


(a) What is the sample space of this random experiment?
(b) What is the event that the sum of the two face values is 5?
(c) What is the probability of the event that the sum of the face values is 5?
(d) What is the probability of the event that the sum of the face values is at
least 5?

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.

15.3 Conditional Probabilities


Let E and F be events over a sample space Ω such that PrrF s ą 0. The
conditional probability PrrE |F s of the event E given F is defined by

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.

It is immediately clear that the conditional probability to land on area 3 is


given by
Prrarea 3 | above lines “ 0,
as area 3 is entirely below the dashed line. If the spinner landed above the
dashed line, then
2 1
Prrarea 1 | above lines “ , Prrarea 2 | above lines “ .
3 3
In other words, the spinner is twice as likely to be in area 1 than in area 2
given that it landed above the dashed line.
We can obtain these results by straightforward calculation. For example,
the joint event of landing above the dashed line and in area 2 has probability
Prrarea 2 X above lines “ 1{6 and the probability to land above the line is
Prrabove lines “ 1{2, whence

Prrarea 2 X above lines 1


Prrarea 2 | above lines “ “ ,
Prrabove lines 3

confirming our aforementioned claim.

We have to be careful, though, as our intuition may fail us when considering


conditional probabilities.
15.3 Conditional Probabilities 391

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

It is essential to carefully calculate conditional probabilities, as it can be diffi-


cult to develop the right intuition for their value.

The next result shows how to express PrrA | Bs in terms of PrrB | As.

Proposition 15.9 (Bayes’ Theorem). Let A and B be events with PrrBs ą 0.


Then
PrrB | As PrrAs
PrrA | Bs “ .
PrrBs

Proof. By definition, we have

PrrA | Bs PrrBs “ PrrA X Bs “ PrrB X As “ PrrB | As PrrAs.

Dividing by PrrBs yields the claim.

Bayes’ Theorem is at the heart of many algorithms in machine learning,


e-mail spam detection, and countless other applications. There are a num-
ber of variations of this theorem that use the next proposition or some of its
generalizations.

Proposition 15.10 (Law of Total Probability, Simple Version). Let Ω be a


sample space, and let A and B be events. Then

PrrBs “ PrrB X As ` PrrB X AA s


“ PrrB | As PrrAs ` PrrB | AA s PrrAA s
392 15 Probability Theory

Proof. The events A and AA are disjoint and satisfy Ω “ A Y AA . Therefore,


we have
PrrBs “ PrrB X As ` PrrB X AA s.
The second equality follows directly from the definition of conditional proba-
bility.

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.

Corollary 15.11. Let A and B be events with PrrBs ą 0. Then

PrrB | As PrrAs
PrrA | Bs “ .
PrrB | As PrrAs ` PrrB | AA s PrrAA s

Example 15.12. We illustrate the virtue of conditional probabilities with the


help of the notorious car and goats problem, which got famous through the
Monty Hall game show. At the end of this show, a contestant was shown three
closed doors. She was told that behind one door is a new car and behind the
other two are goats. If the contestant chooses the door hiding the car, then she
can keep the car. Once she has made her choice, the game show host—knowing
which door conceals the car—opens one of the other two doors to reveal a goat.
Monty then asks her whether she would like to switch doors. The question is:
Should she switch?
Without loss of generality, let us assume that the contestant has chosen
door 1, Monty has opened door 2, and now the contestant has to choose between
doors 1 and 3. Let C1 denote the event that the car is behind door 1, C3 the
event that the car is behind door 3, and M2 the event that Monty opened
door 2, hence contains a goat.
It is apparent that PrrC1 s “ 1{3 and PrrC3 s “ 1{3. Assuming that
Monty will choose a door at random if both doors conceal goats, we get
PrrM2 |C1 s “ 1{2. We certainly have PrrM2 |C3 s “ 1, because Monty has
no choice in this case. Recall that our goal is to compare the conditional prob-
abilities PrrC1 |M2 s and PrrC3 |M2 s. We can use Bayes’ rule to determine these
probabilities. Indeed,

PrrM2 |C1 s PrrC1 s 1{6


PrrC1 |M2 s “ “ “ 1{3.
PrrM2 |C1 s PrrC1 s ` PrrM2 |C3 s PrrC3 s 1{6 ` 1{3

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

This fact is due to Reverend Thomas Bayes.


15.17. Suppose that there are three bags of marbles. The first one contains
30 red and 20 yellow marbles. The second bag contains 35 red and 15 green
marbles. The third bag contains 40 red and 10 blue marbles. If you choose one
of the bags uniformly at random and then randomly select one marble from
the bag, what is the probability that the marble will be red?
15.18. We can often use conditional probabilities to calculate the probabilities
of joint events. Let A1 , A2 , . . . , An be events satisfying PrrA1 X A2 X ¨ ¨ ¨ X
An´1 s ą 0. Then
PrrA1 X A2 X ¨ ¨ ¨ X An s “ PrrA1 s PrrA2 | A1 s PrrA3 | A1 X A2 s ¨ ¨ ¨
¨ ¨ ¨ PrrAn | A1 X A2 X ¨ ¨ ¨ X An´1 s.
394 15 Probability Theory

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

PrrA X Bs “ PrrAs PrrBs

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

Proposition 15.15 (Borel-Cantelli). Let E1 , E2 , . . . be events and denote by


E ˚ “ lim supnÑ8 En the event that infinitely many of the events En occur.
8
ÿ
(a) If PrrEk s ă 8, then PrrE ˚ s “ 0. In other words, with probability 1,
k“1
only finitely many events En will occur.
8
ÿ
(b) If PrrEk s “ 8 and E1 , E2 , . . . are independent events, then PrrE ˚ s “ 1.
k“1

Proof. (a) We notice that


« ff « ff
8 ď
č 8 8
ď 8
ÿ
˚
PrrE s “ Pr Ek ď Pr Ek ď Pr rEk s “: Rn .
n“1 k“n k“n k“n
ř8
Since the sum k“1 PrrEk s converges, the right-hand side terms Rn Ñ 0,
as n Ñ 8. We can conclude that PrrE ˚ s “ 0.
(b) We denote by FnA the event
8
č
FnA “ EkA ,
k“n

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

Therefore, it suffices to show that PrrFnA s “ 0.


Let us look at the probability of finite approximations to FnA . The in-
dependence of the events Ek implies the independence of the events EkA .
Therefore, we get
« ff ˜ ¸
m
č m
ź m
ź ÿm
A A
Pr Ek “ PrrEk s “ p1 ´ PrrEk sq ď exp ´ PrrEk s ,
k“n k“n k“n k“n

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

As the sum diverges, it follows that


PrrFnA s “ 0.
By the union bound, we can conclude that
« ff
8
ď 8
ÿ
PrrpE ˚ qA s “ Pr FnA ď PrrFnA s “ 0,
n“1 k“1
15.4 Independence 397

so PrrE ˚ s “ 1 ´ PrrpE ˚ qA s “ 1, as claimed.

The independence of events in part (b) is necessary, as Exercise 15.30 shows.


A fun consequence is the occurrence of any text in an infinite string of letters
generated uniformly at random, see Exercise 15.31.

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

A “ tpH, H, Hq, pH, H, T q, pH, T, Hq, pT, H, Hqu,

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.26. Let A and B be independent events. Show that


(a) AA and B are independent events.
(b) AA and B A are independent events.

15.27. Let n be an integer such that n ě 2. Let E1 , E2 , . . . , En be independent


events. Show that
(a) the events E1A , E2 , . . . , En are independent,
(b) the events E1A , E2A , . . . , EnA are independent.

15.28. Let n be an integer such that n ě 2. Let E1 , E2 , . . . , En be independent


events. Show that the probabilistic inclusion-exclusion formula for independent
events can be written in the form
n
ź
PrrE1 Y E2 Y ¨ ¨ ¨ Y En s “ 1 ´ p1 ´ PrrEk sq.
k“1

This is much simpler to prove than the general formula.


398 15 Probability Theory

15.29. Let n be an integer such that n ě 2. Let E1 , E2 , . . . , En be independent


events. Show that
« ff ˜ ¸
n
ď ÿn
Pr Ek ě 1 ´ exp PrrEk s .
k“1 k“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?

15.5 Random Variables


In this section, we are going to introduce random variables, which are a con-
venient way to specify events. A random variable is a function that associates
a numerical value to each outcome of an experiment. For instance, if we roll a
pair of dice, then the sum of the two face values is a random variable.
Let Ω be a discrete sample space. A random variable X is a function
from the sample space Ω to the set of real numbers. In essence, the random
variable translates cumbersome specifications of events in P pΩq to the familiar
language of subsets of real numbers.

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.

Probability theorists often use the notation X P B to express the event

X ´1 pBq “ tω P Ω | Xpωq P Bu.


15.5 Random Variables 399

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

where the sum extends over all indices k P N1 such that αk P B.


We define the distribution function FX pxq of the random variable X by

FX pxq “ PrrX P p´8, xs s “ PrrX ď xs,

where X ď x is the commonly used shorthand for X P p´8, xs. Sometimes


this is also called the cumulative distribution function of the random vari-
able X.

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

PrrIA “ 1s “ p and PrrIA “ 0s “ 1 ´ p.

The distribution function FIA pxq of the random variable IA is given by


$
&0
’ when x ă 0,
FIA pxq “ 1 ´ p when 0 ď x ă 1,

1 when x ě 1.
%

One can reconstruct the probability mass function ppxq “ PrrIA “ xs of the
indicator random variable from the distribution function.

We call two random variables X and Y independent if and only if the


events X “ x and Y “ y are independent for all values x and y, meaning

PrrX “ x, Y “ ys “ PrrX “ xs PrrY “ ys.

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

Ω “ tH, T u ˆ tH, T u ˆ tH, T u.

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

when this sum is unconditionally convergent in R, the extended real numbers.


The expectation value is also called the mean of X. If X is a random variable
with nonnegative integer values, then the expectation can be calculated by
8
ÿ
ErXs “ PrrX ě xs,
x“1

which is often convenient. If X and Y are two arbitrary discrete random


variables, then
EraX ` bY s “ a ErXs ` b ErY s,
that is, the expectation operator is linear. This is an extremely useful result.
If X and Y are independent discrete random variables, then

ErXY s “ ErXs ErY s.

Caveat: If X and Y are not independent, then this is in general false.


We suggest that you formally prove the last three claims, see Exercises 15.37–
15.39.
The next example illustrates how linearity of expectation can ease compu-
tations, especially when a random variable can be expressed as sum of indicator
random variables.
402 15 Probability Theory

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

by linearity of expectation, and by definition of the expectation value. This


means that on average one person gets her own hat back.

The expectation can be used to bound probabilities, as the following simple


but fundamental result shows:

Theorem 15.22 (Markov’s Inequality). If X is a nonnegative random variable


and t a positive real number, then

ErXs
PrrX ě ts ď .
t
Proof. Let Y denote the random variable
"
0 if Xpωq ă t,
Y pωq “
1 if Xpωq ě t,

hence Y “ 1 denotes the event X ě t. The expectation value of X satisfies

ErXs ě ErtY s “ t ErY s “ t PrrX ě ts,

which proves the claim.

Variance. The variance varrXs of a discrete random variable X is defined


by
varrXs “ ErpX ´ ErXsq2 s “ ErX 2 s ´ ErXs2 ,
whenever this expression is well-defined. The variance measures the squared
deviation from the expected value ErXs.
It is easy to see that variance is not a linear operator, since

varrX ` Xs “ 4 varrXs
15.6 Expectation 403

holds, to mention just one example. Moreover, varraX ` bs “ a2 varrXs for


all a, b P R. If X and Y are independent random variables, then the variance
satisfies
varrX ` Y s “ varrXs ` varrY s. (15.1)
The random variable X will rarely deviate from the expectation value if the
variance is small. This is a consequence of the Chebyshev’s useful inequality:

Theorem 15.23 (Chebyshev’s Inequality). Let Y be an integrable random


variable. Then
varrY s
Prr|Y ´ ErY s| ě βs ď . (15.2)
β2

Proof. Define a nonnegative random variable X by setting X “ pY ´ ErY sq2 .


Then
ErXs varrY s
Prr|Y ´ ErY s| ě βs “ PrrX ě β 2 s ď “ ,
β2 β2

where we used Markov’s inequality.

Bernoulli Distribution. Tossing a biased coin can be described by a ran-


dom variable X that takes the value 1 if the outcome of the experiment is
head, and the value 0 if the outcome is tail. Assume that PrrX “ 1s “ p and
PrrX “ 0s “ 1 ´ p for some real number p P p0, 1q. The random variable X is
said to have the Bernoulli distribution with parameter p. We can compute the
expectation value and the variance as follows:

ErXs “ p, varrXs “ ErX 2 s ´ ErXs2 “ p ´ p2 “ pp1 ´ pq.

Binomial Distribution. Let X1 , . . . , Xn denote independent identically dis-


tributed random variables, all having a Bernoulli distribution with parameter p.
Then the random variable X “ X1 `¨ ¨ ¨`Xn describes the number of heads in a
sequence of n coin flips. The expectation of X can be immediately computed by
linearity of expectation, and, since the random variables Xk are independent,
we can compute the variance using (15.1):

ErXs “ np, varrXs “ npp1 ´ pq.

The probability of the event X “ x, for integers in the range 0 ď x ď n, is


ˆ ˙
n x
PrrX “ xs “ p p1 ´ pqn´x .
x

Indeed, choose x positions in a sequence of length n. The probability that the


x n´x
sequence will show heads`n˘at exactly these positions is p p1 ´ pq . The result
follows, since there are x ways to choose x positions in a sequence of length n.
404 15 Probability Theory

Uniform Distribution. Let X be a random variable that takes integer val-


ues in t1, . . . , nu. Such a random variable is said to be uniformly distributed
if PrrX “ ks “ 1{n for all integers k in the range 1 ď k ď n. The expectation
value and the variance of X are respectively given by

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

p1 ` nqp1 ` 2nq pn ` 1q2


hence varrXs “ ErX 2 s ´ ErXs2 “ ´ “ pn2 ´ 1q{12.
6 4

Geometric Distribution. Suppose we keep tossing a biased coin, which


has the Bernoulli distribution with parameter p, until the event head occurs.
Let the random variable X denote the number of coin flips needed in this
experiment. We say that X is geometrically distributed with parameter p.
The density function of X is given by

pX pxq “ PrrX “ xs “ pp1 ´ pqx´1

for x “ 1, 2, . . . , and pX pxq “ 0 otherwise. The expectation value and the


variance of X are given by

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.

Negative Binomial Distribution. Let X1 , . . . , Xn be independent random


variables, all having geometric distribution with parameter p. The random
variable X “ X1 `¨ ¨ ¨`Xn describes the number of coin flips that are necessary
until n heads occur, when heads has probability p. The random variable X is
said to have negative binomial distribution with parameters n and p. Linearity
of expectation and additivity of variance for independent random variables
show that
n n
ÿ n ÿ np1 ´ pq
ErXs “ ErXk s “ , varrXs “ varrXk s “ .
k“1
p k“1
p2
15.6 Expectation 405

The probability of the event X “ k is


ˆ ˙
k´1 n
PrrX “ ks “ p p1 ´ pqk´n , k ě n.
n´1

Indeed, a sequence of k coin flips that contains exactly n heads at specified


n k´n
`k´1p˘ p1 ´ pq
positions has probability . By specification, the last position is a
head, hence there are n´1 other positions that can be chosen for the heads.

Poisson Distribution. A random variable X with non-negative integer val-


ues is said to be Poisson distributed with parameter λ ą 0 if

λ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.38. Let X and Y be random variables on discrete sample spaces. Show


that expectation is a linear operator, that is, for all real numbers a and b, we
have
EraX ` bY s “ a ErXs ` b ErY s.

15.39. Let X and Y be two independent random variables on discrete sample


spaces. Show that ErXY s “ ErXs ErY s. [Note that some dependent random
variables are also multiplicative, but the relation does not hold in general.]

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.41. Alice is a compulsive coupon collector. Currently, she is collecting


charming Harry Potter characters that are contained in overpriced cereal boxes.
There are n different characters, and each box contains one character. She
wants to get the complete set. Show that she must expect to buy nHn cereal
boxes, where Hn denotes the Harmonic number Hn “ 1 ` 1{2 ` 1{3 ` ¨ ¨ ¨ ` 1{n.

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

15.7 The Probabilistic Method


Suppose that we want to prove the existence of a combinatorial object that has
certain properties. In the probabilistic method, we approach this problem by
defining a sample space of combinatorial objects and showing that a randomly
chosen element of this space has the desired properties with positive probabil-
ity. Paul Erdős showed that this simple idea can lead to spectacular results.
An interesting aspect is that one can apply the probabilistic method to solve
problems that do not seem to call for probabilistic solutions. We discuss some
well-known results that nicely illustrate this method.

Ramsey Numbers. What is the smallest number n “ Rpa, bq such that in


any set of n people there must be
(a) a mutually acquainted people or
(b) b mutual strangers?
The numbers Rpa, bq are called Ramsey numbers.
In general, computing Rpa, bq can be remarkably difficult. Among n people,
n
there are 2p 2 q possible acquaintance/stranger relations. To show that n “
n
Rpa, bq, we must verify that all 2p 2 q choices satisfy the conditions (a) and (b)
15.7 The Probabilistic Method 407

above. Furthermore, we must show that there is one particular set of n ´ 1


people that satisfies neither (a) nor (b).
We can translate this problem into graph-theoretic terms. We can model
the set of n people by a complete graph. We can use a coloring of the graph
with two colors red and blue. However, this time we will color the edges rather
than the vertices. We color an edge pi, jq red (and depict it by a solid arc) if i
and j are acquainted, and color it blue (and depict it by a dashed arc) if i and
j are strangers. In this language, the Ramsey number Rpa, bq is the smallest
integer n such that in any edge-coloring of Kn with the two colors red and
blue, there exists
(a) an induced red (solid) Ka subgraph or
(b) an induced blue (dashed) Kb subgraph.
We can gain some insight into this problem by having a look at a few simple
instances. Let us begin with one of the simplest cases.
Proposition 15.24. Let n be an integer satisfying n ě 2. Then the Ramsey
number Rp2, nq is given by
Rp2, nq “ n.

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 .

We can also formulate it as follows. At a party with n people, there are


either two people knowing each other or they are all mutual strangers.

Exchanging acquaintances and strangers, we get Rpn, 2q “ n. The next


larger case is already more difficult to argue, so we start with just a lower
bound.
Proposition 15.25. The Ramsey number Rp3, 3q ą 5.

Proof. Consider the graph K5 with the edge-coloring:

In other words, this graph does not have an induced red K3 subgraph, nor
an induced blue K3 subgraph.
408 15 Probability Theory

Loosely speaking, the previous proposition asserts that in a particular party


of five people, it can happen that there are no three people that are mutually
acquainted and no three people that are mutually strangers. The next propo-
sition shows that this can never happen in a party of six people.

Proposition 15.26. The Ramsey number Rp3, 3q “ 6.

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.
` ˘

Proof. Consider Kn and a random 2-coloring on its edges, namely we color an


edge red with probability 1/2, and blue with probability 1/2. For any k-subset
S of the set of vertices, let MS be the event that the induced subgraph on S is
monochromatic. Then,

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

Proof. Given an integer k, we define n “ 2k{2 . The simple estimate nk ď


X \ ` ˘

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!

Simplifying the right-hand side gives the bound


k
21` 2
ˆ ˙
n 1´pk2q
2 ď .
k k!
k
For k ě 3, the right-hand side satisfies 21` 2 {k! ă 1,X see \Exercise 15.46. It
follows from the previous proposition that Rpk, kq ą 2k{2 . Since Rpk, kq is
an integer, it even follows that Rpk, kq ą 2k{2 .

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,

sizepA, Bq “ |tpu, vq P E | u P A, v P Bu|.

Finding a cut of maximum size is a computationally hard problem. However,


we can use the probabilistic method to prove the existence of large cuts.
The key in the argument is the following probabilistic version of the pigeon-
hole principle.
Proposition 15.29. The values of a discrete random variable cannot always
be less than its expected value.

Proof. Seeking a contradiction, suppose that X is a discrete random variable


that has values always less than μ “ ErXs. Then
ÿ ÿ
ErXs “ α PrrX “ αs ă μ PrrX “ αs “ ErXs,
αPXpΩq αPXpΩq

contradiction.

Similarly, a random variable cannot always be larger than its expected


value.
Proposition 15.30. Given an undirected graph G “ pV, Eq with m edges,
there exists a partition of V into two disjoint sets A and B such that at least
m{2 edges cross the cut pA, Bq.
410 15 Probability Theory

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

By Proposition 15.29, there exists a cut pA, Bq of size m{2 or larger.

Exercises
15.45. Determine the Ramsey number Rp2, 2q.

15.46. For any integer k such that k ě 3, prove that


k
21` 2 ď k!

by induction on k.

15.47. Show that the Ramsey numbers Rpa, bq satisfy the bound

Rpa, bq ď Rpa ´ 1, bq ` Rpa, b ´ 1q

for all integers a and b such that a ě 3 and b ě 3.

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

for all integers a and b such that a ě 2 and b ě 2.

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.

© The Author(s), under exclusive license to Springer Nature 413


Switzerland AG 2025
A. Klappenecker, H. Lee, Discrete Structures, Undergraduate Texts in
Mathematics, https://doi.org/10.1007/978-3-031-73434-2
414 BIBLIOGRAPHY

[13] K.L. Chung and F. AitSahlia. Elementary Probability Theory: With


Stochastic Processes and an Introduction to Mathematical Finance. Un-
dergraduate Texts in Mathematics. Springer New York, 4th edition, 2010.

[14] P. M. Cohn. Universal algebra, volume 6 of Mathematics and its Applica-


tions. D. Reidel Publishing Co., Dordrecht-Boston, Mass., second edition,
1981.

[15] P.M. Cohn. Basic Algebra. Springer London, 2003.

[16] T.H. Cormen, C.E. Leiserson, R.L. Rivest, and C. Stein. Introduction to
Algorithms. The MIT Press, 3rd edition, 2009.

[17] B. A. Davey and H. A. Priestley. Introduction to lattices and order. Cam-


bridge University Press, New York, second edition, 2002.

[18] J.-M. De Koninck and A. Mercier. 1001 problems in classical number


theory. American Mathematical Society, Providence, RI, 2007. Translated
from the 2004 French original by De Koninck.

[19] O. Deiser. Einführung in die Mengenlehre. Springer-Lehrbuch. [Springer


Textbook]. Springer-Verlag, Berlin, second edition, 2004. Die Mengen-
lehre Georg Cantors und ihre Axiomatisierung durch Ernst Zermelo. [The
set theory of Georg Cantor and its axiomization by Ernst Zermelo].

[20] U. Dudley. Elementary Number Theory. Dover Books on Mathematics.


Dover Publications, 2nd edition, 2012.

[21] H.-D. Ebbinghaus. Einführung in die Mengenlehre. Spektrum Academis-


cher Verlag, Heidelberg, fourth edition, 2003.

[22] H.D. Ebbinghaus, J. Flum, and W. Thomas. Mathematical Logic. Under-


graduate Texts in Mathematics. Springer New York, 1996.

[23] P.J. Eccles. An introduction to mathematical reasoning. Cambridge Uni-


versity Press, Cambridge, 1997. Numbers, sets and functions.

[24] H.B. Enderton. Elements of set theory. Academic Press [Harcourt Brace
Jovanovich, Publishers], New York-London, 1977.

[25] H.B. Enderton. A mathematical introduction to logic. Har-


court/Academic Press, Burlington, MA, second edition, 2001.

[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).

[27] William Feller. An Introduction to Probability Theory and Its Applica-


tions, volume 1. Wiley, 1968.
BIBLIOGRAPHY 415

[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.

[30] R.L. Graham, D.E. Knuth, and O. Patashnik. Concrete mathematics: a


foundation for computer science. Addison-Wesley, Reading, Mass., 2nd
edition, 1994.

[31] G. Grimmett and D. Stirzaker. Probability and Random Processes. Oxford


University Press, Oxford, 3rd edition, 2001.

[32] A. Gut. Probability: A Graduate Course. Springer, 2005.

[33] P.R. Halmos. Naive set theory. Springer-Verlag, New York-Heidelberg,


1974. Reprint of the 1960 edition, Undergraduate Texts in Mathematics.

[34] G.H. Hardy. Orders of infinity, the ‘infinitärcalül’ of Paul Du Bois-


Reymond. Cambridge University press, Cambridge, 1910.

[35] J. Herman, R. Kučera, and J. Šimša. Equations and Inequalities –


Elementary Problems and Theoremsin Algebra and Number Theory.
Springer-Verlag New York, 2000.

[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.

[38] K. Ireland and M. Rosen. A Classical Introduction to Modern Number


Theory. Graduate Texts in Mathematics. Springer, 1990.

[39] N. Jacobson. Basic Algebra I. Basic Algebra. Dover Publications, 2nd


edition, 2009.
[40] J. Jacod and P. Protter. Probability Essentials. Springer-Verlag, Berlin,
2000.

[41] T. Jech. Set theory. Springer Monographs in Mathematics. Springer-


Verlag, Berlin, 2003. The third millennium edition, revised and expanded.

[42] K. Jordán. Calculus of finite differences. Chelsea Pub. Co., New York,
3rd edition, 1965.

[43] S. Jukna. Extremal combinatorics. Texts in Theoretical Computer Sci-


ence. An EATCS Series. Springer-Verlag, Berlin, 2001. With applications
in computer science.
416 BIBLIOGRAPHY

[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.

[46] A. Klenke. Probability Theory: A Comprehensive Course. Universitext.


Springer, 2nd edition, 2013.

[47] D.E. Knuth. Big omicron and big omega and big theta. SIGACT News,
8(2):18–24, 1976.

[48] D.E. Knuth. Fundamental Algorithms, volume 1 of The Art of Computer


Programming. Addison-Wesley, Reading, Massachusetts, third edition,
1997.

[49] D.E. Knuth. Seminumerical Algorithms, volume 2 of The Art of Com-


puter Programming. Addison-Wesley, Reading, Massachusetts, third edi-
tion, 1997.

[50] D.E. Knuth. Sorting and Searching, volume 3 of The Art of Computer
Programming. Addison-Wesley, Reading, Massachusetts, second edition,
1998.

[51] D.E. Knuth. Combinatorial Algorithms: Part 1, volume 4A of The Art of


Computer Programming. Addison-Wesley, Reading, Massachusetts, first
edition, 2011.

[52] M. Koecher. Klassische Elementare Analysis. Springer Basel AG, 1987.

[53] Thomas Koshy. Catalan numbers with applications. Oxford University


Press, Oxford, 2009.

[54] K. Kunen. Set theory, volume 34 of Studies in Logic (London). College


Publications, London, 2011.

[55] E. Landau. Handbuch der Lehre von der Verteilung der Primzahlen.
Teubner, Leipzig, 1909. 2 volumes. Reprinted by Chelsea, New York,
1953.

[56] E. Landau. Foundations of Analysis. AMS Chelsea Publishing Series.


American Mathematical Society, 2001.

[57] C.H.C. Little, K.L. Teo, and B. Van Brunt. The Number Systems of
Analysis. World Scientific, 2003.

[58] J. Loeckx and K. Sieber. The Foundations of Program Verification. Wiley


and Teubner, 1984.

[59] Z. Manna. Mathematical Theory of Computation. McGraw-Hill, 1974.


BIBLIOGRAPHY 417

[60] E. Mendelson. Introduction to Mathematical Logic. Chapman &


Hall/CRC, 6th edition, 2015.
[61] L.M. Milne-Thomson. The calculus of finite differences. AMS Chelsea
Pub., Providence, R.I., 2000.

[62] V.H. Moll. Numbers and Functions: From a Classical-experimental Math-


ematician’s Point of View. Student mathematical library. American
Mathematical Society, 2012.

[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.

[65] S.R. Ross. Introduction to Probability Models. Academic Press, San


Diego, 7th edition, 2000.

[66] R. Schindler. Logische Grundlagen der Mathematik. Springer, Berlin,


2009.

[67] R.M. Smullyan. Forever Undecided: A Puzzle Guide to Gödel. Oxford


University Press, 1987.

[68] R.M. Smullyan. First-order logic. Dover Publications, Inc., New York,
1995. Corrected reprint of the 1968 original.

[69] R.M. Smullyan. A beginners guide to mathematical logic. Dover, 2014.

[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.

[71] J. Spencer. Asymptopia. Student Mathematical Library. American Math-


ematical Society, 2014.
[72] R.P. Stanley. Enumerative combinatorics. Vol. 1, volume 49 of Cam-
bridge Studies in Advanced Mathematics. Cambridge University Press,
Cambridge, 1997. With a foreword by Gian-Carlo Rota, Corrected reprint
of the 1986 original.

[73] R.P. Stanley. Enumerative combinatorics. Vol. 2, volume 62 of Cam-


bridge Studies in Advanced Mathematics. Cambridge University Press,
Cambridge, 1999. With a foreword by Gian-Carlo Rota and appendix 1
by Sergey Fomin.

[74] R.P. Stanley. Catalan numbers. Cambridge University Press, New York,
2015.

[75] J. Stopple. A primer of analytic number theory: from Pythagoras to Rie-


mann. Cambridge University Press, 2003.
418 BIBLIOGRAPHY

[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.

[78] W. Walter. Analysis I. Springer, Berlin, 1985.

[79] M.H. Weissman. An Illustrated Theory of Numbers. American Mathe-


matical Society, 2017.

[80] D. Williams. Probability with Martingales. Cambridge University Press,


1991.
Index

Symbols bipartite, 355


k-combination, 274 block, 134
k-permutation, 273 Boolean formulas, 15
n-ary predicate, 35 Boolean function
p-adic valuation, 177 monotone, 165
Boolean variable, 15
A
Boole’s inequality, 384
accumulation point bound, 36
lower, 248 bounded above, 157, 247
upper, 247
bounded below, 158, 249
adjacent, 351
antichain, 146 C
antidifference, 225 canonical disjunctive normal
antisymmetric, 70 form, 34
arity, 123 cardinality
assertion, 11 equal, 82
asymmetric, 70 less than or equal to, 82
asymptotically equal, 237 Cartesian product, 68
asymptotically tight bound, 250 Catalan number, 343
asymptotic lower bound, 259 ceiling, 171
asymptotic upper bound, 254 centered hexagonal number, 321
axioms, 12 certain event, 382
B chain, 146
base set, 123 characteristic polynomial, 336
Big Theta, 250 choice function, 77
bi-implication, 15 chord, 375
bijective, 75 chromatic number, 368
Binet’s formula, 327 clique, 370
binomial coefficient, 99, 219 clique number, 370
binomial series, 312 closed neighborhood, 351
binomial theorem, 99 codomain, 73

© 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

color class, 371 E


comparable, 146 edges, 5
complementary element, 4, 52
counting, 271 elementary events, 381
complete bipartite graph, 356 embedding, 164
complete graph, 355 empty graph, 354
complete lattice, 166 empty set, 52
component number, 360 equipotent, 82
composite number, 44 equivalence class, 134
composition, 72, 74 equivalence relation, 133
conclusion, 14, 26 equivalent, 15
conditional probability, 389 Euler’s totient function, 294
congruence modulo n, 140 even integer, 42
conjunction, 13 event, 381
constructor, 123 existential quantifier, 36
contrapositive, 21 expectation value, 401
converse, 22 exponential function, 312
cosine function, 313
countable set, 84 F
faces, 365
cover graph, 151
factorial, 219
covers, 149
factorial function, 99
critical graph, 374
falling factorial power, 217
cumulative distribution
Fermat’s Little Theorem, 101
function, 400
Fibonacci numbers, 95
cut, 409
floor, 171
cut-vertex, 379
forest, 363
cycle, 6
formal derivative, 307
cycle graph, 355
formal integral, 309
formal system, 28
D forward difference operator, 211
degree, 351 free, 127
dependent, 394 free variables, 36
derangement, 294 function, 73
difference operator, 211 bijective, 75
Diophantine equation, 191 eventually nonzero, 252
discrete partial order, 146 injective, 74
disjoint sets, 60 one-to-one, 74
disjunction, 13 onto, 75
distance, 361 preimage, 74
distribution function, 400 restriction, 74
cumulative, 400 surjective, 75
divides, 43 functionally complete set, 34
division of integers, 185 functional property, 76
divisor, 185 Fundamental Theorem of Difference
domain, 73 Calculus, 221
INDEX 421

G indicator random variable, 399


generating function, 301 induction hypothesis, 91
geometric series, 97 inductively defined, 123
graph, 5 infimum, 159
bridge, 361 inflationary, 164
Cartesian product, 357 inhomogeneous linear recurrence
circuit, 358 relation, 320
connected, 359 initial segment, 119
cycle, 358 injective, 74
diameter, 361 input size, 260
order, 349 internal node, 362
path, 358 internal vertex, 362
size, 349 intersection, 60
trail, 358 inverse function, 75
walk, 358 inverse relation, 71
graph complement, 356 irreflexive, 70
greatest common divisor, 187 isomorphism, 164
greatest element, 157
greatest lower bound, 159 K
Grinberg equation, 377 knight graph, 5
knight moves, 3
H knight’s tour, 4
Hamiltonian-connected, 379 closed, 4
Hamiltonian cycle, 6, 374
Hamiltonian graph, 374 L
Hamiltonian path, 6, 374 lattice, 166
happened-before, 148 leaf, 362
harmonic number, 228 least element, 81, 158
Hasse diagram, 151 least upper bound, 159
homogeneous linear recurrence re- left-shifted sequence, 307
lation, 320 limit, 41
hypercube graph, 357 limit inferior, 244
hypotheses, 26 limit superior, 244
hypothesis, 14 linear congruence equation, 196
linear order, 146
I linear recurrence relation, 320
ideal, 195 logical consequence, 25
identity map, 74 logically equivalent, 21
implication, 14 lower bound, 158
impossible event, 382 lower envelope, 243
incident, 351
incomparable, 146 M
indefinite sum, 225 maximal, 159
independence number, 370 maximal degree, 352
independent, 394 maximal planar graph, 366
independent set, 370 maximum independent set, 370
422 INDEX

mean, 401 power set, 56


Mersenne prime, 49 predicate, 35
minimal, 106, 159 predicate of degree n, 35
minimal degree, 351 premises, 26
modus ponens, 26 prime, 104
monotonic, 164 prime gap, 44
multinomial coefficient, 286 prime number, 44
multiple, 185 principal ideal, 195
multiplicative inverse, 304 probability measure, 382
product of power
N series, 304
natural map, 135 proper subset, 54
negation, 14 proposition, 11
neighborhood, 351 propositional calculus, 28
nodes, 5 propositional
function, 35
O
odd integer, 42 Q
operator quotient, 103
difference, 211 quotient set, 135
shift, 214
ordered k-selection with R
repetition, 284 Ramsey numbers, 406
ordered pair, 67 random variable, 398
order extension, 161 independent, 400
indicator, 399
P range, 73
Padovan sequence, 320 rational numbers, 143
palindromic polynomial, 332 reciprocal polynomial, 331
partially ordered set, 145 recurrence relation, 320
height, 146 degree, 320
width, 153 recursively defined, 123
partial order, 145 reflected polynomial, 331
partite classes, 355 reflexive, 70
partition, 134 reflexive and transitive
path, 6 closure, 150
path graph, 354 regular, 353
perfect square, 43 relation, 69
planar graph, 364 binary, 69
plane graph, 365 wellfounded, 106
polynomial, 217 remainder, 103
constant term, 217 right-shifted sequence, 307
degree, 217
leading coefficient, 217 S
leading term, 217 sample space, 381
power, 309 satisfiable, 21
INDEX 423

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy