0% found this document useful (0 votes)
1 views243 pages

Disc Math

The document is a textbook titled 'Discrete Mathematics With Logic' authored by Martin Milanič, Brigitte Servatius, and Herman Servatius, published by Elsevier in 2024. It is designed for first or second-year students in mathematics or computer science, covering key topics such as set theory, formal logic, induction, and number theory, with an emphasis on exercises and case studies. The book aims to facilitate understanding through practical examples and structured exercises, while also providing a comprehensive overview of discrete mathematics concepts.
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)
1 views243 pages

Disc Math

The document is a textbook titled 'Discrete Mathematics With Logic' authored by Martin Milanič, Brigitte Servatius, and Herman Servatius, published by Elsevier in 2024. It is designed for first or second-year students in mathematics or computer science, covering key topics such as set theory, formal logic, induction, and number theory, with an emphasis on exercises and case studies. The book aims to facilitate understanding through practical examples and structured exercises, while also providing a comprehensive overview of discrete mathematics concepts.
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

Discrete Mathematics With Logic

This book belongs to Connor Dunkley


(cadunkley@[Link])

Copyright Elsevier 2024


This page intentionally left blank

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Discrete Mathematics
With Logic

Martin Milanič
Brigitte Servatius

Herman Servatius

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Academic Press is an imprint of Elsevier
125 London Wall, London EC2Y 5AS, United Kingdom
525 B Street, Suite 1650, San Diego, CA 92101, United States
50 Hampshire Street, 5th Floor, Cambridge, MA 02139, United States
The Boulevard, Langford Lane, Kidlington, Oxford OX5 1GB, United Kingdom
Copyright © 2024 Elsevier Inc. All rights reserved.
No part of this publication may be reproduced or transmitted in any form or by any means,
electronic or mechanical, including photocopying, recording, or any information storage and
retrieval system, without permission in writing from the publisher. Details on how to seek
permission, further information about the Publisher’s permissions policies and our arrangements
with organizations such as the Copyright Clearance Center and the Copyright Licensing Agency,
can be found at our website: [Link]/permissions.
This book and the individual contributions contained in it are protected under copyright by the
Publisher (other than as may be noted herein).
Notices
Knowledge and best practice in this field are constantly changing. As new research and
experience broaden our understanding, changes in research methods, professional practices, or
medical treatment may become necessary.
Practitioners and researchers must always rely on their own experience and knowledge in
evaluating and using any information, methods, compounds, or experiments described herein. In
using such information or methods they should be mindful of their own safety and the safety of
others, including parties for whom they have a professional responsibility.
To the fullest extent of the law, neither the Publisher nor the authors, contributors, or editors,
assume any liability for any injury and/or damage to persons or property as a matter of products
liability, negligence or otherwise, or from any use or operation of any methods, products,
instructions, or ideas contained in the material herein.

ISBN: 978-0-443-18782-7

For information on all Academic Press publications


visit our website at [Link]

Publisher: Katey Birtcher


Editorial Project Manager: Ali Afzal-Khan
Publishing Services Manager: Shereen Jameel
Production Project Manager: Gayathri S.
Cover Designer: Matthew Limbert
Typeset by VTeX

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Dedication
is here encoded, but not encrypted:

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


This page intentionally left blank

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Contents

Preface xi

1. Discreteness
1.1 What is discrete mathematics? 1
1.2 The Multiplicative Principle 6
1.3 Binomial coefficients 8
1.4 Pascal’s Triangle 10
1.5 Binary numbers 12
1.6 Base conversion 14
1.7 Case study: Towers of Hanoi 17
1.8 Case study: The Binomial Theorem 18
1.9 Case study: The Guarini Problem 20
1.10 Case study: Red rum and murder 21
1.11 Case study: Tit for tat, nim 22
1.12 Summary exercises 24

2. Basic set theory


2.1 Introduction to sets 27
2.2 The power set 30
2.3 Set operations 33
2.4 Set identities 35
2.5 Double inclusion 37
2.6 Russell’s paradox 40
2.7 Case study: Polyhedra 42
2.8 Case study: The missing region problem 45
2.9 Case study: Soma 46
2.10 Summary exercises 48

3. Working with finite sets


3.1 Cardinality of finite sets 51
3.2 Bit vectors and ordering subsets 52
3.3 Inclusion/exclusion 54
3.4 Multiple Cartesian products and strings 56

vii

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


viii Contents

3.5 Lexicographical order 59


3.6 Ordering permutations 61
3.7 Delisting permutations† 64
3.8 Case study: Wolf-Goat-Cabbage 66
3.9 Case study: The Gray code 67
3.10 Case study: The forgetful waitress problem 68
3.11 Summary exercises 70

4. Formal logic
4.1 Statements and truth value 73
4.2 Logical operations 74
4.3 Implications 76
4.4 Double implication 79
4.5 Working with Boolean algebra 81
4.6 Boolean functions 83
4.7 DNF and CNF† 84
4.8 Case study: Classic logic puzzles 86
4.9 Case study: Spies 87
4.10 Case study: Pirates and cannonballs 89
4.11 Summary exercises 91

5. Induction
5.1 Predicate logic 93
5.2 Existential and universal quantification 95
5.3 The theory of induction 97
5.4 Induction practice 100
5.5 Strong induction 103
5.6 Sets versus logic 105
5.7 Case study: Decoding the Gray code 106
5.8 Case study: The 14–15 puzzle 107
5.9 Case study: Towers of Hanoi 109
5.10 Case study: The Fibonacci numbers 111
5.11 Summary exercises 113

6. Set structures
6.1 Relations 115
6.2 Functional relations 117
6.3 Counting functions on finite sets 119
6.4 Working with functional relations 120
6.5 Functions on infinite sets† 122
6.6 Cardinality of infinite sets† 124
6.7 Symmetry, reflexivity, transitivity 127
6.8 Orderings and equivalence 130
6.9 Case study: The developer’s problem 132

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Contents ix

6.10 Case study: Wolf-Goat-Cabbage II 133


6.11 Case study: The non-transitive dice 135
6.12 Case study: The developer’s problem II 137
6.13 Case study: The missing region problem II 138
6.14 Summary exercises 140

7. Elementary number theory


7.1 Primality, the Sieve of Eratosthenes 143
7.2 Common divisors, the Euclidean Algorithm 145
7.3 Extended Euclidean Algorithm 147
7.4 Modular arithmetic 149
7.5 Multiplicative inverses 151
7.6 The Chinese Remainder Theorem 153
7.7 Case study: Diophantus 155
7.8 Case study: The Indian formulas 157
7.9 Case study: Unique prime factorization 158
7.10 Summary exercises 160

8. Codes and cyphers


8.1 Exponentials modulo n 163
8.2 Prime modulus 165
8.3 Cyphers and codes 167
8.4 RSA encryption 170
8.5 Little-o notation 172
8.6 Fast exponentiation 173
8.7 Case study: A Little Fermat proof 175
8.8 Case study: The Prüfer code 176
8.9 Summary exercises 178

9. Graphs and trees


9.1 Graphs 181
9.2 Trees 184
9.3 Searching and sorting 188
9.4 Planarity 193
9.5 Eulerian graphs 198
9.6 Hamiltonian graphs 202
9.7 Case study: Fáry’s theorem 205
9.8 Case study: Towers of Hanoi 208
9.9 Case study: Anchuria 210
9.10 Summary exercises 211

Selected answers and solutions 213


Index 221

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


This page intentionally left blank

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Preface

This book is designed to be read by modern students.


This book is neither an encyclopedia of discrete mathematics, nor a dictio-
nary. The text is written to be read in support of the accompanying exercises,
and the exercises have been written specifically to illustrate key definitions and
techniques of discrete mathematics, particularly those of interest to computer
scientist majors.
The topics have been chosen to make up a course in Discrete Mathematics
for first or second year students of mathematics or computer science. The essen-
tial chapters are Chapter 2, on basic set theory, Chapter 4, on basic formal logic,
and Chapter 5 on induction. These chapters contain the three proof forms which
students must write examples of in our course, “double inclusion”, “double im-
plication”, and induction. They produce these either individually or, for a large
class, in groups. The essential material in Chapter 1 is at the high school level,
but experience says it is best not to skip it.
Every chapter has at least six main sections, the optional ones marked with
a †. Each main section contains three exercises specifically designed to rein-
force the definitions in the section. There are always exactly three because even
a moderately curious student seeing three exercises will try to do them. Most
students encountering a long list of exercises will not try a single one, and will
instead wait for an assignment. Interspersed in the text one finds the symbol ,
which is a signal that the reader should stop reading and think before continuing.
The main sections have all the material that the student needs to understand
for the quizzes and tests.
Following the main sections are sections labeled “Case studies”. Case stud-
ies use and expand upon the material in the main sections, or anticipate ideas
which come later. Some introduce new material, some focus on interesting prob-
lems, some provide proofs of the more difficult theorems, but only if the proof
illustrates important ideas. We avoid proofs for proof’s sake. Case studies have
no exercises. All case studies are optional both from the point of view of the
teacher, and the instructor. While it is possible to skip all the case studies, we
believe that it is an important aspect of the course to have discussions about
topics without the distraction of homework, grades, and tests. The summary ex-
ercises at the end of the chapter never refer to the case studies, and the list of
“concepts that should have been learned” never refer to them either.

xi

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


xii Preface

The case studies have been placed so that, by the time they appear, all back-
ground concepts have been covered, but many work well in earlier or later
chapters, and covering them in between main sections is just as effective as
waiting until the main material is done. Some are very easy, some are more
challenging, and all are to some degree open ended. The case studies also work
very well for individual or group student presentations.
The book contains few citations and almost no bibliography. Students should
have no trouble finding sources for the material presented if desired. On the
other hand, for many problems and results we have deliberately altered the
names and the framing (e.g., “Euclid’s Coin Problem”) so that the student cannot
easily just “google it”, and will perhaps think it through on their own instead.
The pace of the class should be to cover two sections, main or case studies,
in each 50-minute class period.
For our students we always use all five of the initial chapters, varying only
the choice of case studies. On average we use two case studies per chapter, either
those in the text or others written in the same format, the choice depending on
class interest. The last week or two is devoted to some selection of the later
material.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Chapter 1

Discreteness
1.1 What is discrete mathematics?
Defining discrete mathematics is not as easy as defining many other branches
of study. In biology you study living things, in astronomy you study heavenly
bodies, in vector calculus you study calculus on vectors. For discrete mathemat-
ics, the question is not only what is being studied, but how it is being studied.
The easiest way to answer the question “What is discrete mathematics?” is to
consider a variety of problems, mathematical and non-mathematical, and to ex-
amine for each of them to what extent we would consider it to be part of discrete
mathematics.

Problem list
1. Maximize
√ x 3 − 100x on the interval [−5, 21].
2. Is 2 rational?
3. Pythagoras’s problem: Show that for any right triangle, the square of the
hypotenuse is equal to the sum of the squares of the other two sides.
4. The Nantucket Map Problem: There is a large map of Nantucket pinned to a
bulletin board. Someone pins a small map of Nantucket on top of the large
map. Find a point to place a pin so that it marks the same location on both
maps.
5. The Wolf-Goat-Cabbage Problem: Can a man transport three items, a wolf,
a goat, and a basket of cabbages, across a river using a boat which is only
large enough for him to transport one item of cargo at a time, and keeping in
mind that, if left unguarded, the wolf will kill the goat and the goat will eat
the cabbage.
6. Albertson’s Magic Trick: An MC asks a victim from the audience to pick a
number from 1 to 31 and then answer truthfully whether or not it lies on each
of the following five cards.

16 18 20 22 8 10 12 14 4 6 12 14
17 19 21 23 9 11 13 15 5 7 13 15
24 26 28 30 24 26 28 30 20 22 28 30
25 27 29 31 25 27 29 31 21 23 29 31

Discrete Mathematics With Logic. [Link] 1


Copyright © 2024 Elsevier Inc. All rights reserved.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


2 Discrete Mathematics With Logic

2 6 10 14 1 5 9 13
3 7 11 15 3 7 11 15
18 22 26 30 17 21 25 39
19 23 27 31 19 23 27 31

Given the answers, how can the MC determine the number?


7. The Presidential Problem: What was George Washington really like?
First of all, which of these problems is even mathematical? Clearly the first
three problems are. The others seem questionable. Albertson’s Magic Trick has
numbers in it, but are they actually part of the problem? Would the trick be
any different if, instead of numbers, the cards contained 31 cartoon characters?
On the other hand, the Nantucket Map Problem has no numbers at all, but the
solution might involve geometry, which is certainly part of mathematics. The
rest of the problems on the list seem to be essentially non-mathematical.
What about discreteness? Most people use the word discreet in the sense of
tactful, or unobtrusive.1 That is not our meaning at all. In this subject, discrete
is to be understood in the sense of separated or granulated, as opposed to that
which is smooth or continuous. In electronics, a digital signal would be con-
sidered discrete, whereas an analog signal would be not. We think of a box of
billiard balls as a discrete collection of objects, but a bucket of water as con-
taining a non-discrete fluid. What, you might ask, about a bucket of sand? Is it
discrete, continuous or somehow lying on the boundary? On the one hand, we
can draw on the surface with our fingers, on the other we can pick out individual
grains with tweezers. If we are pouring sand, it seems continuous, acting as a
fluid, but once poured, it doesn’t flow into a puddle, like water, but forms a heap
whose shape is determined by the size and type of grains. So which is it?
In this class, we will have many mathematical definitions. Learning how to
manage mathematical definitions is a key skill to be developed, but discreteness
has not been defined mathematically. Discreteness is an important idea, one that
shapes our subject, but deciding whether or not a particular idea or phenomenon
is discrete might depend on your experience or point of view. It is for this reason
that this first section of the text seems more philosophical, than mathematical.
Let’s try to apply this idea to the numbers we know. On the one hand, we
have the natural numbers, N = {0, 1, 2, 3, 4, . . .}, which are perfectly appropri-
ate for dealing with discrete objects, such as counting the number of billiard
balls, and the related integers, Z = {. . . , −3, −2, −1, 0, 1, 2, 3, . . .}. More gen-
erally we have the real numbers, R, which include .5, π, −e, and in fact all
numbers with a decimal representation, that is, which lie on the continuous num-
ber line.
aa aa  -
vs. −2 −1 0 1

1 Discrete mathematics is using your calculator on a test when the proctor is not looking.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Discreteness Chapter | 1 3

So the first problem on our list, optimizing a continuous function of a continuous


variable, is definitely a problem in continuous and not discrete mathematics.
The second problem involves rational numbers, Q, numbers whose decimal
representations are finite or repeating. At first glance the rational numbers don’t
seem quite so discrete as the integers since they are packed so close together
on the number line, but since every rational number is associated with just two
integers, the numerator and the denominator of a fractional representation, it
seems we must √ classify the rational numbers as discrete. Problem 2 requires
us to show that 2 is irrational. To do this directly looks intimidating, √ since it
seems impossible to first generate the entire decimal representation of 2 and
then show that it is infinite
√ and non-repeating. If however, we hadn’t been given
the hint in advance that 2 is irrational, we might √ try instead to show that it is
rational, for instance by finding p and q so that 2 = p/q. That, at least, looks
like discrete mathematics. To make sure there is exactly one p and q to be found,
let’s√assume that p/q is in lowest terms, so p and q have no common factor. So
set 2 = p/q and let’s try to solve. Squaring gives, 2 = p 2 /q 2 , or 2q 2 = p 2 .
So p 2 must be an even number, hence p itself must be even. So we can set
p = 2k and we have 2q 2 = (2k)2 = 4k 2 , or q 2 = 2k 2 , so q 2 is even and hence
q itself must be even. But now p and √ q both have a common factor, 2. This is a
contradiction. Hence
√ we conclude 2 = p/q has no solutions with integers in
lowest terms, so 2 is irrational. The second problem is solved, and even more,
the problem was solved discretely. We used only simple algebra, properties of
that very useful number 2, and logic. So it seems we should classify problem 2
as belonging to discrete mathematics.
But wait, if we think back to the calculus problem that we rejected earlier
as non-discrete, its solution actually looks similar. There the problem is defined
by just a few numbers: 3, 100, −5 and 21, and the solution involves computing
the derivative. The derivative is computed by just pushing the symbols around
according to a prescribed method, e.g., x 3 turns into 3x 2 . Although the prob-
lem is continuous, the solution is via a sequence of separate distinct operations.
Indeed the word calculus comes from the Latin word for pebble, with the idea
that solving problems in differential calculus is analogous to counting pebbles
out of a bowl. So there seems to be something discrete about the first problem
after all.
The wolf-goat-cabbage story has both continuous and discrete aspects but,
according to the rules of the problem, the continuous aspects (the weight of the
boat, the speed of the river, or the height of the man) are not relevant to the so-
lution. Solving the problem quickly reduces to considering a discrete collection
of situations, or “states”, each indicating on which side of the river the man,
goat, wolf, and cabbage are. So at least Problem 5 is a discrete problem, and
you should be easily able to solve it by trial and error, perhaps on a table with
five coins to represent the characters.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


4 Discrete Mathematics With Logic

Let’s now consider the magic trick. We will violate the fundamental rule of
magic and reveal the secret of the trick. Each card has an active region:

16 18 20 22 8 10 12 14 4 6
17 19 21 23 9 11 13 15 5 7
24 26 28 30
25 27 29 31

2 1
3

The numbers have been placed on the cards so that, for the first card for which
the answer is yes, the secret number will not only be on that card, but in the
active region. So if the answers are no, no, no, no, yes; then the active region
on the fifth card is only a single number, and the secret number is 1. Each sub-
sequent answer allows us to divide and shrink the active region in half, until at
the end it contains only the required number. Each time the region is shrunk,
it is shaped like the next active region. The secret number will be on the left
(top) half if the answer is no, and on the right (bottom) half if the answer is yes.
Shrinking the active region in this way will always yield a single number by the
fifth question.
Let’s try it out. If the number is 6, the answers would be: no, no, yes, yes,

no. So the active region starts out as 4 6 for the yes to question 3, and then
5 7

shrinks to the right half 6 for the next yes, and to the top 6 for the last no.
7
You should try the secret method with some other numbers to convince yourself
that it works. With just a little practice as MC you can give the answer before
the victim has even finished saying the last answer. That’s the magic. Nobody
would be impressed if the MC wrote down all the answers, thought for a few
minutes, and then answered correctly. Now, to decide if the method works, we
just have to try it with all thirty-one numbers. If it doesn’t work, we are done,
but what if it does work? We will still not know why it works, and have no clue
how the trick was ever designed in the first place.
So, just as with Wolf-Goat-Cabbage, we have a discrete problem, but is it
a problem in discrete mathematics? So far, the answer for both is no. What
is missing is the mathematical analysis of the problems. Just playing around
with discrete objects does not constitute mathematics, whether the objects are
numbers or not. And mathematical analysis is to be meant in the most general
sense, as in Problem 2, whose solution involved only evenness, oddness, and

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Discreteness Chapter | 1 5

logic. To start the analysis, in order to make these problems mathematical, we


should ask and answer some mathematical questions about these problems.
Let’s start with Albertson’s Magic Trick. There are many questions we could
ask about whether it works, or why it works. For instance, can we add some new
numbers to the cards? Or perhaps we want to make a version of the trick with the
31 numbers replaced with the 50 states. Is that possible? One restriction is that,
no matter how we arrange the 50 states on the cards and no matter what clever
active regions we have come up with, if the victim has the same five answers for
Illinois as for Hawaii, say, (yes, yes, no, yes, no), then it will be impossible for
the MC to decide correctly between them. So the number of states we can place
on the cards to make an effective trick is restricted by the number of answer
sequences. How many are sequences are there? There are two possible answers
for the first question, and for each of these there are two possible answers for
the second question 2 · 2 = 4, and for each of these there are two answers for the
third question (2 · 2) · 2 = 23 and so on, giving us 25 = 32 answer sequences.
So a version with all 50 U.S. states is impossible with just five cards and yes-no
questions.
Does this show that the trick works? No. We have not counted the yes-no se-
quences in the trick, just the number of sequences in general – the sequences you
would get if you didn’t show the victim the cards at all but just asked random
questions. So all we have shown is that the trick is plausible, that it is not im-
possible from this point of view. Even though we have not solved the problem,
we are now applying mathematics to the discrete problem, and that is discrete
mathematics.
We can use this sequence counting idea, called the Multiplicative Principle,
for the Wolf-Goat-Cabbage problem as well. How many different states are there
in the problem? For each object in the story we can ask the question “Which side
of the river is it on?”, and record the answers to the questions. So for man, the
boat and the three articles of cargo we have 25 possible states, by the same
principle we used before. Does this solve the problem? No. But the analysis has
started, and you may be getting ideas on how to attack it.
Finally, consider the Presidential Problem which we found to be neither dis-
crete nor mathematical, and so the least likely of any of the problems to be
of interest in a course of Discrete Mathematics. The question concerns George
Washington’s character. Game developer Gary Gygax described the following
system to mathematically classify and analyze character, dividing the concept
into six major traits, to be assigned a number from 3 to 18, (since in the game
the character traits could be assigned by rolling three dice), and two alignments
allowing three states each, see Table 1.1. This system reduces the Presidential
Problem to determining to which of the (multiplicative principle yet again!)
166 · 32 = 452,984,832 Gygax character types George Washington belongs.
In summary, it seems that any problem can be approached mathematically if
we are willing and able to define and analyze it rigorously, and that is what we
must do if we are ever going to really solve it. In addition, the fact that we have

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


6 Discrete Mathematics With Logic

TABLE 1.1 Dungeons and Dragons character discretization.


Strength Intelligence Wisdom Constitution Dexterity Charisma
3-18 3-18 3-18 3-18 3-18 3-18
Alignments
Good-Neutral-Evil Lawful-Neutral-Chaotic

a solution means we have reduced the problem somehow to a sequence of steps,


calculations, or procedures; that is, something discrete. So it is not surprising
that discrete mathematics almost always appears in the end-game of a solv-
able problem; that discrete mathematics therefore is a gigantic subject; that it is
found throughout our technological society. That said, all our problems do not
end in discrete mathematics, by any means, since most of the important prob-
lems in life are not solvable, and are the province of poets, artists, philosophers,
etc.

Exercises
1. Order the problems in the list discussed in this section from least to most
discrete.
2. Consider methods people have of communicating. Identify three which are
essentially discrete.
Identify three which are essentially non-discrete.
Justify your responses.
3. Consider the following outdoor activities. Order them from least to most
discrete: jump-rope, frisbee, hopscotch, pogostick. Justify your ordering in a
few words.

1.2 The Multiplicative Principle


Sequences of independent choices
In Section 1.1 we used the multiplicative principle three times as a tool to ana-
lyze a problem. So we state it formally here:

Theorem 1.1 (The Multiplicative Principle). The number of sequences of n


independent choices, (c1 , c2 , c3 , . . . , cn ), where the number of options for choice
ci at stage i is Oi is the product of all the numbers of options:

O1 · O2 · · · · · On

if the choices are either independent or weakly independent.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Discreteness Chapter | 1 7

The result seems clear, but when we applied it earlier no mention was made
of independence.2 If you have taken a course in probability, then the indepen-
dence idea is essentially the same. We say that the kth choice is independent of
the earlier choices if there is no sequence of choices c1 , c2 , . . . , ck−1 , such that
the kth choice is at all restricted from the full Ok options.
Were the choices in the Magic Trick independent? You would have to look
carefully at the cards to tell. But before you peak, just suppose that every number
occurring on the fourth card occurred at least once on one of the three previous
cards. Then the fourth choice would not be independent because it would not be
possible, after answering (no, no, no, _, _) for the first three cards, to answer yes
for the fourth card. In that situation, the choices would not be independent.
For the actual cards, we know that the answers must be dependent since the
victim chooses a number from 1 to 31, but the multiplicative principle predicts
25 = 32, so some sequence of choices does not occur.
In the absence of independence (or weak independence), the multiplicative
principle merely gives us an upper bound on the sequence of choices.

Exercises
1. An online order form for a winter coat allows you to choose up to four colors
for the coat, and four colors for an optional hood, and either ordinary or Red-
Sox themed buttons.
First give a guess as to the number of types of coats which can be ordered.
Then compute the number of different types of coats which can be ordered
2. You are in a restaurant and order the special, which has three choices of
appetizer, one of which is a salad with three choices of salad dressing. There
is a vegetarian option to the entrée and three choices of dessert.
Would you guess that ten different meals are possible?
Compute how many different meals can be ordered. Justify your response.
3. It is your first day of class and you have to fill out four feedback surveys orig-
inating from four different administrative offices, to measure your happiness
and efficiency.
The first survey has six true/false questions. The second and third surveys
were obviously edited with the same survey composition app, and both
have large animated smiley faces which read aloud to you twelve multiple
choice questions whose four alternatives are labeled comfortingly “choco-
late”, “sunsets”, “cuddle”, and “joy”. The fourth survey is exactly the same
as the first survey with the order of the questions shuffled – but it must be
filled out anyway.
How many different survey responses are possible?
The student must complete all surveys and nothing can be left blank.

2 We will discuss weak independence in Section 1.3.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


8 Discrete Mathematics With Logic

1.3 Binomial coefficients


Weakly independent choices
Suppose you have 15 billiard balls and want to place them in the rack. How
many ways are there to do that? The balls are numbered from 1 to 15, and the
rack is just an oriented triangular array.

5
6 9
10 11 1
3 15 2 14
7 4 8 12 13

Imagine placing the balls one by one from top to bottom, since any ball can be
in any position, it is tempting to take the number of options for the ith ball to
be Oi = 15. We will then get 1515 which will be a very generous upper bound
since the choices are not independent. Only the first placement has the full 15
options since no ball can be placed twice.
But it is not hard to see what to do next. Reset the number of options to take
into account the decreasing range of choice

O1 = 15, O2 = 14, O3 = 13, ..., O14 = 2, O15 = 1.

We have almost solved the problem, but there is an interesting subtlety. Once,
say, ball 5 is chosen for the first position, that ball is no longer an allowable
choice to be placed in any of the other positions. But it would have been avail-
able if a different ball had been chosen initially. The available second choice is
dependent on the first one, and so are all the subsequent ones. On the other hand,
although the particular choices change, the number, Oi , of subsequent options
at each stage does not. Regardless of which ball was chosen first, there is the
same steadily decreasing number of choices after the first one; so by the same
argument we used before, the number of ways to rack the balls is the same as
the number of sequences of allowable choices, 15 · 14 · 13 · · · 2 · 1 = 15!.
We say that the kth choice is weakly independent of the earlier choices if,
regardless of what has been chosen so far, there are always Ok options available.
So the calculation above actually does follow from the Multiplicative Principle
(Theorem 1.1) as stated in the previous section.
Theorem 1.2. The number of ways to order n objects, with n > 0, is n!.
The factorial is defined by the familiar equations

1 k=0
k! = (1.1)
(k)(k − 1) · · · (1) k > 0

for k ≥ 0. The fact that 0! = 1 looks peculiar, but is absolutely necessary.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Discreteness Chapter | 1 9

Choosing
Suppose we have a class of 11 kindergartners, and want to choose five of them
to take a bunch of flowers to the principal. How many ways are there to do
that? The teacher asks for volunteers, and all the kids raise their hands and wait
expectantly to be chosen. The teacher chooses the first kid, 11 choices, then for
each of these a second, weak independence giving 11 · 10, then a third 11 · 10 · 9,
a fourth 11 · 10 · 9 · 8, and finally a fifth 11 · 10 · 9 · 8 · 7. In particular, for little
Julie, it is very important to her not only to be chosen, but to be chosen first. If
she is not among the first three chosen, she might even throw a tantrum, and not
even be comforted if she is later selected fourth or fifth.
When the kids take the flowers down to the office, the principal notices of
course who has been chosen to bring the flowers, but has no interest in the order
in which they were chosen. All the 5! ways which the teacher had of choosing
those five kids, so important to little Julie, would be considered the same to the
principal.
So we have two answers to the counting problem. From Julie’s point of view,
there are
11!
11 · 10 · 9 · 8 · 7 =
6!
ways of choosing, in which the actual process of choosing is important, and for
the principal there are

11 · 10 · 9 · 8 · 7 11!
=
5! 5!6!
ways in which the manner of choosing not considered, only who was chosen.
The first is often called the ordered selection, and the second the unordered
selection. There
 is a special notation for the unordered selection, in this case it
would be 11 = 11!/5!6!. Other notations, such as C 11 , are sometimes seen.
5   5
The numbers nk have been around for a very long time, and have been re-
discovered in many different contexts, so the notation and languagewhich  has
evolved around them is a hodgepodge of that history. The number nk is most
often called a binomial coefficient, and the particular one referred to here is read
off as “n choose k”. That is often the source of many student, and non-student,
errors since the mathematical language does not mesh with the natural language
we use to express
  the problems. So Julie, who cares so much about the choice,
does not use 11 5 to count from her point of view, but the other one. In English
 
you can get over this difficulty by, just to yourself, thinking of 11 5 not as “n
choose k”, but “n grab k”, since ‘grabbing’ has much more the connotation of
selecting altogether than ‘choosing’. (But don’t expect that if you say “n grab
k” that anyone else will know what you are talking about.)

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


10 Discrete Mathematics With Logic

Here is a summary:

Theorem 1.3 (Counting Selections). The number   of ways to perform an un-


ordered selection of k objects from n objects is nk .
The number
n of ways to perform an ordered selection of k objects from n
objects is k k!.

Example 1.4. How many four-letter words have two vowels?


First, by vowel is meant one of the five letters a, e, i, o, and u. Also, for
problems of this type, we are not to be hunting through a dictionary to determine
actual words, so lite and xoox count. We have four letter positions and
we want to choose letters to fill them. What you don’t want to do is to let the
word “choose” prompt you to take a binomial coefficient prematurely, without
thinking first if that is the appropriate measurement. Also, it is often a mistake to
start “choosing” before considering how those choices will combine with other
parts of the problem. Here, the problem is very difficult to approach strictly left
to right, since the choices in method are dependent. Actually, it is best not to
start choosing any letters, but rather the positions to be occupied
 by vowels. For
this one chooses (grabs) two of the four positions in 42 ways, say the 1st and
4th, .
The word to be constructed has now been organized for the placement of
letters, but is still empty. Note that, as required by the multiplicative principle,
the number of choices we make in now filling in the word does not depend
on which organization we have specified. Now select vowels for the two vowel
positions, left to right, say e a, and consonants for the two consonant positions,

say etba, and we are done. We have determined 42 52 (26 − 5)2 possibilities.

Exercises
1. How many 10-digit decimal numbers (zeros in front ok) have at least five
1’s?
2. How many 10-digit decimal numbers (zeros in front ok) have exactly five
even digits (0, 2, 4, 6, 8)?
3. There is a drawer with three compartments, one filled with oil, one with
water, and one with gold paint. 15 billiard balls are to be distributed into the
drawers. How many ways are there to do this?

1.4 Pascal’s Triangle


The binomial coefficients may be arranged in a convenient pattern:

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Discreteness Chapter | 1 11

0
0
1 1
0 1
2 2 2
0 1 2
3 3 3 3
0 1 2 3
4 4 4 4 4
0 1 2 3 4
5 5 5 5 5 5
0 1 2 3 4 5
6 6 6 6 6 6 6
0 1 2 3 4 5 5
..
.

which is called Pascal’s Triangle. It is important to note that we will follow


common computer
 science practice and label ordered objects starting from 0.
So the entry 42 , which you may regard as occupying the 3rd position in the 5th
row, we prefer to regard as being in the 2nd position of the 4th row, which fits
the notation much better. We do have to get used to the fact that the top entry
  is
the whole 0th row, and that the nth row has n + 1 entries, from the 0th, n0 , to
 
the nth, nn .
Just as important as the rows, the entries of Pascal’s Triangle are organized
in forward diagonals, the “choose 0’s”, the “choose 1’s”, the “choose 2’s”, etc.
The 0th diagonal is entirely made up of 1’s, since n0 = 1, and the first diagonal
 
identifies the row number, since n1 = n – except for the 0th row, which has no
first entry.
If we look at Pascal’s Triangle with the binomial coefficients computed, we
have this familiar array of numbers

1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
 
in which you must not fail to identify the 20 at the bottom as 63 not 64 , since
it is only the 3rd entry on that row, “counting from 0”. The computed triangle
also makes plain the obvious mirror symmetry, because the number of ways to
grab k things from n things is exactly the same as the number of ways of letting
n − k things remain ungrabbed:
   
n n
= .
k n−k

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


12 Discrete Mathematics With Logic

It is also easy to show that the entries in each row increase to the middle, and
then decrease:
   
n n
< for k ≤ (n − 1)/2 (1.2)
k k+1
Computing the entries may seem tedious, since it involves so many multipli-
cations, and the numbers get big rather quickly. (How quickly? — Later.) But
there is an important shortcut for generating them. Each entry in Pascal’s trian-
gle which is not on the boundary, is the sum of the two entries right above it, one
to the left, and one to the right. For a binomial  coefficient
 not on the boundary,
n+1 
both entries are at least 1, so let’s write it as n+1
k+1 The entry above k+1 and to
the right
 n is
 on the same forward diagonal, and  so is in the same choose group,
so is k+1 , and the one to the left must be nk ; so we are claiming that
     
n n n+1
+ = . (1.3)
k k+1 k+1
There are several proofs of
 this
 key result. The one which follows now was
my professor’s favorite: For n+1
k+1 you want to grab k + 1 objects from n + 1
objects. Assume that one is precious, that
 nit is made of gold. Either you grab the
golden object, or you don’t. There are k+1 ways to avoid the golden one. On
 
the other hand, once you have the golden one, there are nk to grab the ordinary
ones.
The preceding four sections are taken from a branch of discrete mathematics
called combinatorics. It is very useful, and your university probably has several
courses in just that.

Exercises
1. Write out
  the
 first 8rows
 of Pascal’s triangle.
Circle 72 , 75 , and 84 .
  100
2. Show that 10049 < 50 .
[Hint: decide if the
 ratio
100is larger or smaller than 1.]
What about 100 50 < 51 ?
3. Check that
                
8 4 4 4 4 4 4 4 4 4 4
= + + + +
4 4 0 3 1 2 2 1 3 0 4
Can you find an explanation for this “coincidence”?
 
Can you find a similar statement for 12
6 ?

1.5 Binary numbers


In discrete mathematics, and in computer science, it is often convenient to use
the numbers expressed in other bases than our usual one, base 10. Just to recall,

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Discreteness Chapter | 1 13

a decimal number like 1776 is represented by just four digits, the “digit” coming
from the Latin word for finger, by the clever system of scaling each of the digits
by a power of 10:

1776 = 1 · 103 + 7 · 102 + 7 · 101 + 6 · 100 .

The number 10 is not a digit in the decimal system, but 0 is.


Analogously, in the binary system, the number 2 is not a binary digit, or bit.
The only bits are 0 and 1. A binary number is represented by a sequence of zeros
and ones, like

110,010,111 = 1 · 28 + 1 · 27 + 0 · 26 + 0 · 25 + 1 · 24 + 0 · 23 + 1 · 22 + 1 · 21 + 1 · 20 .

There is no standard about placing commas, and they are usually left out. Some-
times one adds a subscript, in this case 2, to indicate the number base of the
representation, especially if the base is not clear from the context: 810 = 108 =
223 = 10002 , which is somewhat inconsistent since the subscript is usually still
in base 10, but no system is perfect.
If you have never done so, it is instructive to list the 16 four-digit binary
numbers from 0000 to 1111 in order, and observe the developing pattern of 0’s
and 1’s, comparing it to what you would expect from the list of base 10 numbers.
You have probably heard that computers are fundamentally binary because
0 and 1 can represent “off” and “on”. And that still by and large is true, since
electrical circuits can easily be built like that, but many other architectures are
also possible. But even without that consideration, binary numbers would still
be of interest because of other fundamental dichotomies like “no” and “yes”,
“negative” and “positive”, “false” and “true”, etc.
For example, binary numbers play a fundamental role in Albertson’s Magic
trick, one of the problems we considered in Section 1.1. The “magic” was in
associating the sequences of yes’s and no’s for the five cards with the sequences
of bits of the binary numbers from 000012 to 111112 . So the number 2510 =
110012 would be associated with the object pictured on the zero’th, third, and
fourth card, but not on the first and second. The trick as presented takes as
objects the numbers themselves, undisguised beyond that they are represented
in base 10. The zero’th card consists of all five bit numbers whose zero’th bit is
1, the first card those whose first bit is 1, etc.
One can also do arithmetic on binary numbers. Binary numbers are added
and multiplied in the same way as decimal numbers, yet with many fewer digit
facts to be known, but many more carries. So 13 + 7 = 20 and 5 · 5 = 25 would
be done as follows:

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


14 Discrete Mathematics With Logic

1 0 1
× 1 0 1
11 11 01 1
1 0 1
+ 1 1 1
0
1 0 1 0 0
1 0 1
1 1 0 0 1

While it is true that the number bases 2 and 10 are by far the most popular, a
facility with others is often quite handy, or even essential.

Exercises
1. Let n = 1101101101 and m = 1110110110, be binary numbers.
Compute n + m, m − n, n/2, and n2 + 1 in binary format.
Compute 12123 + 21213 and 12123 × 21213 in trinary format.
2. How many 12-digit binary numbers between 100000000000 and 111111111
111 have at least 4 zeros?
4 2
3. Express 2(2 ) in binary. Express 2(4 ) in binary.
8 2
Try the same with 2(2 ) and 2(8 ) .

1.6 Base conversion


Conversion of decimal to binary – forward method
If you have a decimal number, say 1776, and you wish to convert it to bi-
nary, it may help to first determine the required bits, that is the binary digits.
It seems natural to be most interested in the bits with the largest place values,
since those seem to be the most important to the number. So notice first that,
since 2048 > 1776, and 2048 = 211 , we will be looking for, at longest, a binary
number b10 b9 b8 b7 b6 b5 b4 b3 b2 b1 b0 with 11 bits, so that

1776 = b10 210 + b9 29 + b8 28 + b7 27 + b6 26 + b5 25 + b4 24 + b3 23 + b2 22


+ b1 21 + b0 20 .

Since 1776 ≥ 210 , we must have that b10 = 1. That gets the first bit, and to
find the others, subtract 210 and continue in the same fashion for the remainder
1776 − 1024 = 754. In general, for the ith bit, if the number m remaining sat-
isfies 2i+1 > m ≥ 2i , we set the ith bit to one, and subtract 2i , otherwise we set
the ith bit to 0 and proceed with the same m, stopping only when the bit b0 is
determined.
Here is the precise description:

Algorithm 1.5 (Forward Method of Base Conversion). Let xn be given, with


2n+1 > xn ≥ 2n . We want to express xn = bn 2n + bn−1 2n−1 + · · · b1 21 + b0 20

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Discreteness Chapter | 1 15

by generating the two sequences xn , xn−1 , . . . , x0 and bn , bn−1 , . . . , b0 in n + 1


steps, starting with the 0th step.
At the ith step set bn−i = 1 and xn−i−1 = xn−i − 2n−i if xn−i ≥ 2n−i ; and
set bn−i = 0 and xn−i−1 = xn−i if xn−i < 2n−i . ♥
The method described above is an example of an algorithm, at each step all
possible cases are considered and the procedure indicated, with attention paid
to how to start, and when the method is finished. The study of algorithms is an
important part of discrete mathematics, and we will consider several algorithms
in this text. If you are studying computer science, you will certainly take at least
one class completely devoted to algorithms.
The algorithm starts with the knowledge of how many bits an integer x has
when expressed in base 2. The key to that is in the inequality 2n+1 > x ≥ 2n
which is true of any n + 1 bit number which cannot be written with fewer bits. It
follows that n + 1 > log2 (x) ≥ n, since log2 (x) is an increasing function. Since
log2 (x) = n we have the following
Theorem 1.6. The positive natural number x has log2 (x) + 1 bits.
The expression in Theorem 1.6 uses the popular floor function defined by
setting x = n if n + 1 > x ≥ n. The ceiling, written x is also useful, x = n
if n ≥ x > n − 1. Note that for any integer n we have x = x = n.
Eq. (1.4) also uses the hugely important logarithm function in one of its im-
portant roles in discrete mathematics: the logarithm to base b, with b an integer
b > 1, roughly measures the length of the number in that base. The precise for-
mula for the number of base b digits of a non-negative integer x is

logb (n) + 1. (1.4)

Conversion of decimal to binary – backward method


This method seems backwards because we start with what one considers the
least important bit, the one’s bit. Changing the one’s bit has the least effect on
the value of the number. But in binary it does govern an important aspect –
whether the number is even or odd. Since 1776 is even, its 20 bit is 0.
In general, you can also decide evenness by dividing by 2 and checking the
remainder: 1776 = 2 · 888 + 0. The next thing to notice is that, multiplying by
2 in binary, is just like multiplying by 10 in decimal: you shift all the bits one
place to the left and add a zero at the end. If we knew 888 in binary, we could
add a zero at the end and have the binary expression for 1776. Of course, finding
the bits for 888 is the same mathematical problem, applied to a smaller number.
We find that we just need to keep dividing by two, and recording the remainders.
As we continue, we will be recording the bits of 1776 is reverse order:

1776 = 2 · 888 + 0
888 = 2 · 444 + 0

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


16 Discrete Mathematics With Logic

444 = 2 · 222 + 0
222 = 2 · 111 + 0
111 = 2 · 55 + 1
55 = 2 · 27 + 1
27 = 2 · 13 + 1
13 = 2 · 6 + 1
6=2·3+0
3=2·1+1
1=2·0+1

We find that, 177610 = 110111100002 , or 1776 = 210 + 29 + 27 + 26 + 25 + 24 .


In general, given a number m, we convert it to binary by dividing by two,
recording the remainder, and continuing the same procedure with the quotient,
stopping only when the quotient is zero. The remainders record the bits of the
number m in reverse order.
A procedure of this kind, which “calls itself”, is referred to as recursive.
Notice that this second method does not require us start by computing how many
bits are required. That information is discovered along the way. Where? On the
other hand, in compensation, we need to check a stopping condition.
Algorithm 1.7 (Backward Method of Base Conversion). Let x0 ≥ 0 be given.
We want to express x0 = bn 2n + bn−1 2n−1 + · · · b1 21 + b0 20 .
Starting with the 0th step, generate b0 , b1 , b2 , . . . and x0 , x1 , . . . using divi-
sion with remainder at the ith step: xi = 2 · xi+1 + bi ; stop the procedure when
xi+1 = 0. ♥
The forward method, where we know a priori what is to be done and how
often to do it, is often called iterative, with the instructions at each step being
iterated.

Other number bases


Converting a number to other bases is done analogously. For example, to convert
1776 to base 9 by the backward algorithm you would do

1776 = 9 · 197 + 3
197 = 9 · 21 + 8
21 = 9 · 2 + 3
2=9·0+2

giving 1776 = 2 · 93 + 3 · 92 + 8 · 91 + 3 · 90 = 23839 .


For the forward method, we start with Eq. (1.4) which tells us that we need
4 base 9 digits. Base 9 has more than two digits, so it is not enough, as with

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Discreteness Chapter | 1 17

binary, to simply start by subtracting 93 and moving on immediately to the lower


powers. You would either repeatedly subtract, as many as eight times, or divide
by 93 , noting the quotient and remainder before moving on to divide by 92 ,
etc. This seems to make the backward method look more attractive since there
you divide repeatedly by an unchanging smaller number, the base. Why not try
writing out the general alogorithm explicity?

Exercises
1. Convert 6464 (decimal) to binary, using both methods. Show your work.
Convert 6464 also to base 8 (octal) and base 16 (hex, or hexadecimal. Use
A, B, C, D, E, F , for ‘digits’ 10, 11, 12, 13, 14, and 15). Use any method
you like. If you think for a minute or two, you might see that there is a trick.
2. Convert 6464 to base 3 and to base 5.
3. For base 3, you don’t have to use remainders 0, 1 and 2. Instead, you could
take remainders 0, 1, and −1. Since −1 is ugly to look at as a digit, we’ll
invent a font: one ↑ for 1; none 0 for 0; and mone (pronounced mun) ↓, for
−1.
So one mone none mone, or ↑↓ 0 ↓, or [1][−1][0][−1], represents the num-
ber 33 − 32 − 30 = 17.
Write out the first 20 numbers in one/mone notation.
Convert 1776 to the one/mone system.

1.7 Case study: Towers of Hanoi


If you like mathematical puzzles, or know someone who does, you proba-
bly have seen a model of the Towers of Hanoi. There are many versions, and
variants. This is how I first encountered it. There are three posts, representing
heaven, hell, and earth. There are seven round flat disks of various sizes which
fit over the posts, representing parts of society.

The disks start all stacked, largest to smallest, on the post representing hell, and
your task is to move them, one at a time, from one post to another, so that in the
end the whole tower is moved to heaven. The restriction is, that you must never
place a larger disk on top of a smaller disc. So, for example, the merchant may
never be placed on top of the knight.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


18 Discrete Mathematics With Logic

Can the task be done in fewer than 100 moves? What about 50 moves? What
is the most efficient method of solution?
As a first step, since the discs are stacked in decreasing size, and each legal
move preserves that property, we know that the configuration after any number
of legal moves has the discs stacked in decreasing size on the three poles. How
many such legal configurations are there? It is possible to use the multiplicative
principle to compute that number, and it is an upper bound on the number of
moves that it takes to complete the puzzle – why?

1.8 Case study: The Binomial Theorem


We looked earlier at Pascal’s Triangle, one of the most famous discrete arrange-
ments of numbers. It is not at all surprising that those numbers are conveniently
arranged in a triangle, nor that the numbers in the triangle have a mirror sym-
metry about the center line. But there are many curious relations in this triangle,
which are harder to explain. Here is one, which I have heard called the two-three
relation:

If you add up the rows of Pascal’s Triangle, from left to right, with each entry
scaled by an increasing power of two, they will sum to a power of three.

Let’s try:
         
4 0 4 1 4 2 4 3 4 4
2 + 2 + 2 + 2 + 2
0 1 2 3 4
= 1 · 1 + 4 · 2 + 6 · 4 + 4 · 8 + 1 · 16 = 81 = 34 .

Puzzling?
Here is another curious relation. You have certainly noticed that the rows of
Pascal’s triangle appear when multiplying polynomials:

(a + b)2 = 1a 2 + 2ab + 1b2


(x + 1)4 = x 4 + 4x 3 + 6x 2 + 4x + 1
(y − z)5 = x 5 − 5x 4 y 1 + 10x 3 y 2 − 10x 2 y 3 + 5x 4 y − y 5

noting that the 1 on either end of the row is often not written explicitly. These
two phenomena are coming from the same source, the Binomial Theorem. Bi-
nomial is not the name of a famous mathematician, it refers to a polynomial with
two terms, say p and q, so written as (p + q). The terms p and q may be individ-
ual letters, or something much more complicated, but regardless, the question
the Binomial Theorem addresses is, what happens when we take (p + q) to an
integral power?

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Discreteness Chapter | 1 19

Theorem 1.8. Let p and q be algebraic terms and let n be a positive integer.
Then
n  
n k n−k
(p + q) =
n
p q .
k
k=0

By algebraic terms, we are being purposely vague, intending the result to


apply, to numbers, variables, expressions, etc., in fact, to any situation where
addition and multiplication make sense, are commutative and the distributive
law holds.
If you want to actually do the multiplication required by the integral power:

(p + q)n = (p + q)(p + q)(p + q) · · · (p + q),

the distributive law requires that you get one term resulting from, for each of
the n terms, a choice of p versus q. If n = 6 and you were alternating in your
choices, that would give you the term pqpqpq = p 3 q 3 . In general, if the number
of p’s you choose is k, then you have the term p k q n−k . How many times does
that
n
occur? Once for each way to choose k factors from all n factors, that is
. That is why, gathering them all together in the product, we have the term
nk  k n−k
k p q .
This proof of the Binomial Theorem is only convincing if you have a thor-
ough understanding of how the distributive law works. We will see another proof
later on. The binomial theorem explains the two-three relation completely:

n  
 n  
n k n−k  n k
3n = (2 + 1)n = 2 1 = 2 .
k k
k=0 k=0

Here are two others:


n  
 n
2n = (1 + 1)n = (1.5)
k
k=0
n  
n
0 = (1 − 1) =n
(−1)k (1.6)
k
k=0

which state that the sum of the entries in any row in Pascal’s Triangle is 2 to the
power of that row number, and the alternating sum of the entries in any row of
Pascal’s Triangle must be 0. The last is obvious for odd rows by cancellation,
e.g., 1 − 3 + 3 − 1 = 0, but is certainly not obvious for the even rows like the
4th, which says, 1 − 4 + 6 − 4 + 1 = 0. There is a non-algebraic explanation for
this oddity in the next chapter.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


20 Discrete Mathematics With Logic

1.9 Case study: The Guarini Problem


The Guarini Problem is a centuries old problem involving the movement of
chess pieces. The starting position is four knights placed on the corners of a
3 × 3 section of a chessboard, with the black knights occupying the top two
corners, and the white knights opposing them on the bottom two corners. The
problem is to move the knights so that the black knights end on the bottom two
corners and the white knights are on the top two. The knights must never leave
the 3 × 3 area, and each move must be a legal knight move, but they do not have
to take turns. So you can move the same knight several times in a row if you
like.
The problem is certainly discrete. The issue is how, or whether, mathematics
is involved, that is, how the problem is to be approached. If you just start moving
pieces, you will discover that the problem is quite tricky, and the goal cannot be
achieved in just a few moves. As the number of moves which you try increases,
your choices are:
• Continue to just move at random, hoping to hit on a solution.
• Give up.
• Impose an order on your search.
• Analyze the problem.
Only with the final two can you be said to be doing discrete mathematics.
It is best to try the problem out for yourself before you read on. In this book
we have a special symbol for this:

Whenever you see it, you are encouraged to pause and think before reading on.
A favorite analysis is something like the following. There are nine squares
in the 3 × 3 array, with 8 on the outside, forming a ring. If you mentally deform
the ring, keeping the connections as they are, you can turn the 3 × 3 board into
a circle

and you can ignore the color of the central region, corresponding to the middle
square, since the knights never go there. They always stay on the boundary.
What does a knight’s move mean in this less familiar territory? If the moves
correspond to something very complicated, not matching the uniformity of the
circle, then this problem transformation will not be very helpful. (But even then,
the whole idea of “problem transformation” may make you think of something
even more clever!)

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Discreteness Chapter | 1 21

If you are ahead of me and have already tried it, then you have discovered
that knight moves on the 3 × 3 board transform very nicely indeed to rotations
of the knight around the ring by 135◦ , 3/8 of the way around, clockwise, or
counterclockwise. And that is just the hint you need. It says that the natural
thing to do is not to try to reflect the knights across the line of symmetry, but to
turn them around 180◦ degrees. As in the diagram below:

That means 4 moves for each knight, 16 altogether. That seems like a lot of
moves for this little problem, but if you paused at the  symbol and tried on
your own, you probably gave up after many more moves than that! It is natural
to start trying to move the knights directly across, since an individual knight
with nothing in the way requires only two moves to cross, but the group of four
get in each other’s way very badly with that approach.

1.10 Case study: Red rum and murder


The fact that “murder” spelled backwards gives “red rum” was noticed long ago,
and seemed compelling to those reformers over a century ago who wanted to ban
alcoholic beverages. The wordplay appeared in a newspaper puzzle, arranged in
a diamond grid as shown in Fig. 1.1a, with the object of the puzzle being to
count all the ways to spell out the slogan, moving one letter at a time, one letter
up or down, left or right.

FIGURE 1.1 a) An ancient puzzle. b) Reduction: Spelling “murder” in the (SE) quadrant.

As you start to think of how to count the ways, you quickly abandon the idea
of actually listing them all. A methodical counting is clearly required. And as
you work out a strategy, pay particular attention to how the puzzle might involve
the multiplicative principle, and Pascal’s Triangle.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


22 Discrete Mathematics With Logic

Here are some insights:


• With the plus sign, the slogan redrum+murder is palindromic, that is, it reads
the same forwards and backwards.
• You must start and end on the outer ring of R’s.
This is because the inner ring of R’s is separated from the letter E except across
a diagonal.
• You must be in the center of the puzzle when you are half way through.
These insights give you the first reduction of the puzzle.
The only way to spell out the slogan, is to start on the outer ring of R’s, move
to the middle, and return.
So for each way from the exterior to the center, you can continue with any
path from the center to the exterior, and these are the reverses of one another, the
multiplicative principle applies. You need only count the paths from the center
to the exterior, and square that.
You might ask, which is better, to count the paths from the interior to the
center or from the center to the exterior? Each has its advantages. Here is an
insight which is harder to see or express the other way:
• As you move from the exterior to the center, if you ever enter the long vertical
expression of the slogan in the middle, or the long horizontal one, you can
never leave it.
That means that, if you start in one of the four quadrants, call them (N E),
(N W ), (SE), and (SW ), then you can never leave that quadrant. This tells us
that we should use this symmetry to first focus completely on one quadrant, in
one direction, and then assemble the full solution, see Fig. 1.1b.
Perhaps that is the only hint you need. We’ll come back to this case study
later.

1.11 Case study: Tit for tat, nim


Simple two person games are a good source of discrete problems. To play cram-
check you only need a checkerboard and an ample supply of checkers. The two
players take turns placing one checker on the board. A player loses if there is
no room for him to place a checker. Of course, the checkers are not restricted
to be placed only within the marked squares – that would be no fun at all. See
Fig. 1.2a. A simple strategy for the first player to win cramcheck is to initially
place the first checker exactly in the middle, and thereafter to place each checker
at the same distance from the center as the previously placed checker, but 180◦
around the board. If the first player consistently follows that strategy, each of
his moves leaves the array of checkers such that it is symmetric with respect to
turning the board 180◦ . So, using this tit-for-tat strategy, if the second player
can find a place for a checker, symmetry insures that the first player can match
the placement on the other side of the board in his next move, see Fig. 1.2b. Do
you see why the first checker must be placed exactly in the middle?

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Discreteness Chapter | 1 23

FIGURE 1.2 Cramming checkers on a board. b) and c) are symmetrically placed.

It is because the center is the only location to place a single checker so that the
board has rotational symmetry. Most people have a poor eye for 180◦ symmetry,
and so it is possible for this simple strategy to go undiscovered by the opponent.
On the other hand, you may find that 180◦ may be awkward to adhere to. Mirror
symmetry is much simpler to recognize and employ, but it is possible for the
second player to defeat a mirror image strategy. How?
It is said that Catherine de’ Medici knew and used the 180◦ strategy, but was
stymied when it was proposed to play the game with eggs instead of checkers.
She was at a loss for a first move until she thought of jamming the first egg,
hard boiled, firmly upright on its end in the middle of the board. After that, she
proceeded to win, tit-for-tat.
Cramcheck has continuous and discrete aspects, but the game of nim is com-
pletely discrete and has a similar tit-for-tat strategy. Nim starts with a quantity of
coins, distributed into piles. The two opponents take turns. Each player selects
one pile, and removes from that pile as many coins as he pleases, being sure to
take a least one. He may take the whole pile, but he may not alter any other pile
in that turn. The winner is the one who takes the very last coin. The game may
be played with large numbers of coins, say 50 coins in 10 piles of 5, or just a
few, say 15 coins in piles of 1, 2, 3, 4, and 5. Why not try?

If there are an even number of piles, with the numbers of coins occurring in
pairs, like 22, 75, 75, and 22, then the second player can win by copying the first
player, tit-for-tat. If the piles are almost balanced in pairs, like 22, 75, 100, and
22, then the first player can win by balancing the collection, that is, taking 25
coins from the pile of 100, and then following his opponent tit-for-tat.
But what if the piles are more random, like 65, 85, 19, and 21? The piles of
coins seem so far out of balance that we might have to consider several layers of
moves and countermoves. But, actually, the first player can “balance” them in a
single move! The balancing principle is not obvious. It is hidden in the binary
representations of the numbers of coins in the piles.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


24 Discrete Mathematics With Logic

p1: 65 1000001 | 65 1000001 | 65 1000001 | 65 1000001


p2: 85 1010101 | 71 1000111 | 85 1010101 | 85 1010101
p3: 19 0010011 | 19 0010011 | 1 0000001 | 19 0010011
p4: 21 0010101 | 21 0010101 | 21 0010101 | 7 0000111

Given k piles of coins with pi coins in pile i, the collection of piles is in balance
if the number of 1’s in each bit position of the binary representations of p1 , p2 ,
. . ., pk is even.
In the example, the four piles are out of balance because of the bits in the
21 and 23 positions. Changing the bit in the largest out-of-balance position, 23 ,
from a 1 to a 0, such as for 85, 19 and 21, means decreasing the number of coins
in the altered pile, even if bits in smaller positions are increased from 0 to 1.
Once the pile to be altered is chosen, the number of coins to be left in that
pile follows the rule: The bit in position 2i is set to be 1 if the number of 1’s in
the 2i position for the remaining piles is odd. It is set to be 0 otherwise. This
balances the piles, and if balancing requires the largest bit to be altered being
changed from 1 to 0, the new value is smaller, and the change is made by taking
away coins.
Note that an odd number of piles can be in balance!
For the example, you get to a balanced position, and are on your way to
winning the game, if you take 14 coins from either the pile with 85 or the pile
with 21; or if you take 18 coins from the pile with 19. (If you apply the balance
rule to the pile with 65 you can balance the piles, but by adding 10 coins!)
If the opponent makes a move with the piles in balance, no matter which pile
he chooses or how much he takes, the result leaves the piles out of balance. Then
the next player can restore them to balance in the same way as before, ending
with the piles being put into balance by the taking of the last coin. The player
balancing the piles has won the game.
The tit-for-tat strategy for Nim is not practical without practice or without
being completely comfortable with binary numbers. For good simple test cases
to try with a partner, piles with three consecutive two digit numbers are recom-
mended, like 22, 23, and 24.

1.12 Summary exercises


You should have learned about:
• Discreteness
• Mathematics
• The Multiplicative Principle
• Independence and Weak Independence
• Ordered and Unordered Selections
• Binomial Coefficients and Pascal’s Triangle
• The recursive formula for Binomial Coefficients
• The Binary Number System, and other number bases

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Discreteness Chapter | 1 25

• The idea of algorithm


1. Order the following musical instruments with respect to discreteness: gui-
tar, violin, piano, tuba, bugle, trombone, bass drum, and clarinet. Justify
your choice.
2. The statement “Lightning never strikes twice in the same place” is asserting
that lightning strikes are
a) additive c) dependent
b) multiplicative d) independent
3. A user PIN for the website [Link] is a string of 5 digits, the
0th digit of which must be 0 and the digits in odd positions must themselves
be odd.
Can a hacker discover your PIN in one hour by trying 1 pin per second?
Show your reasoning.
4. A Las Vegas slot machine called EXTAZY! has 6 tumblers, each with 6
positions corresponding to the 6 letters of “extazy”. The machine pays out
if all tumblers return either x, y, or z. The machine is designed so that there
is always at least one x, y, or y returned among the 6 tumblers.
How many different results can the machine return? How many different
winning results can the machine return? Should you play it?
In each case justify briefly your answer.
5. How many seven-digit numbers only contain odd digits? How many of
them have 1 as the last digit? How many of them contain 7 exactly once?
6. How many n-digit numbers only contain odd digits? How many of them
have 1 as the last digit? How many of them contain the digit 7 exactly
once?
7. Flip a coin n times and record H if the coin lands on its head and T if
it lands on its tail. How many outcomes are possible? How many pos-
sible outcomes have at least as many H s as T s? How many outcomes
have equally as many heads and tails? Check your answers for n = 2, 3, 5,
and 10.  n  n
8. Show algebraically that k+1 / k = (n − k)/(k + 1). Use that to show
 n  n
k+1 / k ≥ 1 if k ≤ (n − 1)/2, proving Theorem 1.2.
9. a) How many anagrams of ‘alligator’ are there? and b) How many ana-
grams of ‘alligator’ do not have all the vowels clumped together, like
‘llaiaogtr’.
10. Convert 1000 (decimal) to binary, using both methods. Show your work.
Convert 1000 (decimal) to trinary, using both methods. Show your work.
5 2
11. Express 2(2 ) in binary. Express 2(5 ) in binary.
12. Find a base b for which the one’s digit of the representation of 10! in base
b is not 0.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


This page intentionally left blank

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Chapter 2

Basic set theory


2.1 Introduction to sets
A set is a collection of objects.
For instance, we may consider the set of letters used in spelling Mississippi.
Let’s call this set X, since one often uses capitals to denote sets. In the collection
we have both letters s and i but not the letter t. We say s and i are both elements,
or members, of X and write s ∈ X to express s is an element of X. We also write,
π∈ / X, or b ∈ / X.
No other issue need be considered in the definition of a set; membership is
all. For a set with very few members, it is common to simply list them all. For
our initial example we may write X = {m, i, s, p}, always using “curly braces”
to enclose the list of members. The letter m is the first element written on my
list, but that does not mean that it is the first element of the set X, even though it
is the first letter of the word “Mississippi”. I could just as well list the elements
in alphabetical order and still specify the same set, X = {i, m, p, s}. If I am not
paying attention, or if the elements of the set are being listed by a computer
which has not been programmed to remove the duplicates, the same set X could
be correctly notated as X = {m, i, s, s, i, s, s, i, p, p, i}. We are not saying that
these are different sets which refer to the letters in “Mississippi”, we are saying
that these are different ways of notating exactly the same set X:

X = {m , i , s , p } = {i , m , p , s } = {m , i , s , s , i , s , s , i , p , p , i }

Each expression accomplished the necessary goal of specifying which objects


are elements of the set.
Every set must be well-defined, that is, the requirements of membership must
be clear. It is easy to write the set of words in the English language, and we might
continue to chat along merrily for quite some time as if we know what we are
talking about, but that phrase is not sufficient to define a set. Is ain’t an English
word? It is in most dictionaries now, but so what. Who put dictionary editors
in charge? Maybe we should ask the Poet Laureate of the United States, or the
King of England, or the Supreme Court? The point is not how we could resolve
the question, if the question is interesting to us. The one defining the set has the
burden to making the definition clear in the beginning. Writing the set of words
in the English language is not to define a bad set, or a problematic set, it is a
failure – it doesn’t define a set at all.

Discrete Mathematics With Logic. [Link] 27


Copyright © 2024 Elsevier Inc. All rights reserved.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


28 Discrete Mathematics With Logic

Requiring sets to be well-defined means that it is actually quite difficult to


define and use sets in the real world, with all its exceptional cases, and using
the natural language which we speak, with all its ambiguities and shifting and
evolving definitions. The clarity required to specify sets is most easily found
in artificial worlds governed by abstract rules written in a rigidly controlled
language – mathematics, computer science, games, and the law.
For a set to be well-defined, it is not necessary that membership be easy to
determine, or even possible. The set P of prime numbers, integers which are at
least 2 and which have no positive integer factors except themselves and 1, is
/ P, but what about 2(10 !) +1? That
10
clearly specified. We know that 7 ∈ P and 8 ∈
number is so big that it might never be practical to ever determine if it is prime
or not. But it is still clear what we have to decide to make that determination.
The set P is well-defined, but there are many numbers whose membership in P
is unknown to us.

The cardinality of a finite set


For a finite set, S, the number of distinct elements in the set is called its cardi-
nality, and we denote it by |S|. So |{m, i, s, p}| = 4, which seems obvious until
you write |{m, i, s, s, i, s, s, i, p, p, i}| = 4.

Special sets
The following sets are used throughout mathematics and computer science and
each has a special symbol. Most of our sets will be built from these.
Naturals The set of all natural numbers, the non-negative whole numbers, is
denoted by N = {0, 1, 2, 3, . . .}. So 3, 0, 1776 ∈ N and −1, 3/4 ∈ / N. (Beware
that we are taking 0 ∈ N. Other texts may differ.)
Integers The set of all integers, positive and negative whole numbers, is de-
noted by Z = {. . . , −3, −2, −1, 0, 1, 2, 3, . . .}. So 3, 0, −2223 ∈ Z, but −22−23 ,
−π/4, and ∞ are not elements of Z.
Rationals The set of all rational numbers, described as integer fractions or as
those decimals numbers which, after the √ decimal point, are finite or repeating,
is denoted by Q. So −1 ,
2 7
22
, 0.3532 ∈ Q. 2∈ / Q.

Reals
√ The set of all real numbers is denoted by R. So π, e, γ , 17762 ∈ R.
−1 ∈ / R.
The Empty Set The empty set is the set with no elements. It is written {} or,
preferably, with the special symbol ∅. The empty set is an essential component
in the theory of sets, and it must be handled and notated correctly. The empty
set has cardinality zero, |∅| = 0.
In addition to these, the following sets, primes, digits, bits, letters, will ap-
pear throughout this text.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Basic set theory Chapter | 2 29

Primes The set of all prime numbers, P, natural numbers at least 2 whose only
non-negative factors are themselves and 1.
Digits The set of all (decimal) digits, D = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}.
Bits The set of all (binary) bits, B = {0, 1}.
Alphabet The set of all 26 characters in the Roman alphabet, A = {a, b, c, d, e,
. . . , x, y, z}.

Bracket notation
In the previous section the listing notation started to fail us. A list which relies
on ellipses, the . . ., cannot really be said to properly specify its contents. Part of
this difficulty we will resolve later, when we specify sets recursively. In general,
a more valuable notation for an infinite set, or a large finite set, is the bracket
notation. One specifies first either the notation for the elements to be specified,
or a known set where the elements are to be taken from, and ends with a list of
properties which determine the membership in the set to be defined. Separating
the two parts is the | symbol, which is to be read as “such that”. So the notation
looks like this:
{x ∈ A | property 1; property 2; . . .}
or
{x | property 1; property 2; . . .}.
So {n ∈ Z | n < 10; n ≥ 0} describes precisely the set D.
Using this notation, we can specify the rationals in terms of the integers by
writing
Q = {p/q | p ∈ Z; q ∈ N; q = 0}.
If instead we write

Q = {p/q | p ∈ Z; q ∈ Z; q = 0}

then we get exactly the same set, but with more duplicates, more elements of
the set satisfying the conditions of membership in different ways.

Exercises
1. Which of the following sets are, in your opinion, well-defined? Justify your
response in a word or two.
— The set of football teams
— The set of ping pong balls
— The set of hairs on your head
— The set of laws in the USA
2. Which of the following sets are, in your opinion, well-defined? Justify your
response in a word or two.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


30 Discrete Mathematics With Logic

a.
The set of integers which are products of two primes.
b.
The set of game positions in chess.
The set of all real numbers whose absolute value is greater than −1.
c.
d.
The set of integers which are useful in the study of the game Go.
e.
The set of integers which, when spoken aloud, cause a genie to appear
and grant you three wishes.
3. Write each of the following in set notation, without words if possible: (Your
answers will vary.)
a. A, the set of odd integers
b. B, the set of real numbers whose square is an odd integer
c. C, the set of rational numbers which are an integer power of π
d. D, the set of real numbers with a decimal representation using only digits
5 and 6

2.2 The power set


Subsets
We say that A is a subset of B, and write A ⊆ B if every element x ∈ A is also
an element of B. In terms of our special sets we have P ⊆ N ⊆ Z ⊆ Q ⊆ R.
Notice that it is not true that P ∈ N ∈ Z ∈ Q ∈ R. If we say P is in N, or N
contains P we are making a vague statement which is true or false depending on
whether containment is to be understood in terms of being a subset or an element
of the set in question. Many problems are avoided if we discipline ourselves
to use the words specifically chosen just for set theory, “an element of” or “a
subset of”. If you want to talk or write more informally, try to always ground
things with the precise unambiguous mathematical notation: “The digits are in
the rationals, D ⊆ Q”.
There is also a notion of a proper subset, where A ⊆ B but A = B, and this is
often notated as A ⊂ B, but some texts use ⊂ for ⊆, so there is some ambiguity.
We will not use the ⊂ symbol in this text.

Showing A ⊆ B
To show that A ⊆ B, one must check every single element of A for membership
in the set B. This is fine for very small sets, but is not generally practical. What
is more effective is, if A is given by properties, you consider a general element
of A, (“Let a ∈ A”); then note the properties which a must satisfy because of
its membership in A; then show that, because of those properties, a satisfies the
properties required for membership in B; allowing you to finally conclude that
a ∈ B.
So, for instance, let’s establish that Z ⊆ Q. Recall that Q = {p/q | p ∈ Z; q ∈
N; q = 0}. Let k ∈ Z. We also have 1 ∈ N, and since k = k/1, and 1 = 0, we have
k ∈ Q, as required.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Basic set theory Chapter | 2 31

Definition 2.1. The power set of a set A, denoted by P(A), is the set of all
subsets of A, P(A) = {X | X ⊆ A}. ♠
So the elements of P(A) are themselves sets. This is not an unusual situa-
tion, or a weird special case. It often arises, and makes even more essential that
you are careful about using the correct vocabulary for the different notions of
containment.
Example 2.2. If X is a finite set, say X = {i, m, p, s}, then X has only a finite
number of subsets and we can easily list them all. Of course X ⊆ X. Don’t let
the “sub” in subset mislead you. Equality is clearly allowed by the definition.
The subsets with smaller cardinality are obtained by removing elements of X;
cardinality 3, {i, m, p}, {i, m, s}, {i, p, s}, and {m, p, s}; cardinality 2, {i, m},
{i, p}, {i, s}, {m, p} {m, s} and {p, s}; cardinality 1, {i}, {m}, {p}, and {s}; and
finally we are forced to consider the set with all elements removed, the empty
set, {}.

P(X) = {{i, m, p, s}, {i, m, p}, {i, m, s}, {i, p, s}, {m, p, s},
{i, m}, {i, p}, {i, s}, {m, p}, {m, s}, {p, s}, {i}, {m}, {p}, {s}, {}}.

The last subset considered, {}, cannot be omitted. In total |P(X)| = 16. ♦
For any set A, it is true that ∅ ⊆ A, since ∅ contains no elements to violate
the subset condition. As we saw in the previous example, it can also happen that
the empty set is an element of a set. So ∅ ∈/ {i, s, m, p}, but ∅ ∈ P({i, s, m, p}).
The set P({i, s, m, p}) has sixteen distinct elements, and one of them is ∅,
so ∅ ∈ P(X), {∅} ⊆ P(X) and, look carefully at this, |{∅}| = 1. The empty set
is not “nothing”. It is a set, so the fact that it is an element of {∅} counts. In
particular, ∅ = {∅}!
Definition 2.3. The set of k-subsets of a set A is defined by

Pk (A) = {Y ∈ P(A) | |Y | = k}. ♠

For example, P2 ({i, s, m, p}) = {{i, m}, {i, p}, {i, s}, {m, p}, {m, s}, {p, s}},
and the set Pk (A) will be empty if |A| < k. What is Pk (A) for k = 0?

Cardinality of power sets


By the multiplicative principle, if A is a finite set then

|P(A)| = 2|A|

since you can choose independently for each element of A whether or not it is
in the subset to be considered, and membership is the defining quality for any
set. Notice that choosing no for each element A is counted as a legal sequence
of choices, and that would be specifying the empty set.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


32 Discrete Mathematics With Logic

To compute the cardinality of the set of k-subsets, |Pk (A)|, with k ≤ |A|, we
can also use the multiplicative principle. In fact, we have already done so, since
those subsets may be regarded as being obtained by an unordered selection of k
objects from |A| objects;
 
|A|
|Pk (A)| = .
k

In fact, this gives us a much better insight into many problems than the idea of
unordered selection. We don’t have to imagine artificially choosing the elements
of the subset. They are just there in the subset.
We can use the formula for the cardinality of the power set to predict the
number of elements in the sets P(∅), P(P(∅)), P(P(P(∅))), etc. We have al-
ready noted that |P(∅)| = 1 = 2|∅| , so it is consistent with that formula. There-
fore we must have |P(P(∅))| = 21 = 2. What are the two elements? We know
that the whole set, and the empty set must be subsets of every set, and for ∅ they
are the same set. For {∅} they are different: P(P(∅)) = {{∅}, ∅}. Continuing,
|P(P(P(∅)))| = 22 = 4. Try to write all four of them down. Be very careful of
the notation. (You will see that {∅} and {{∅}} are also different!)
Nothing prevents us from going further, and finding |P(P(P(P(∅))))| =
24 = 16, and then |P(P(P(P(P(∅)))))| = 216 = 65,536. You can stop there,
because the power set of that set has 265,536 elements, which I learned in school
was more than the number of atoms in the whole universe, but the universe
might have gotten bigger since then. We can hardly avoid being awestruck at
the progression, creating an increasingly complex variety of concepts from just
the contemplation of the empty set. This mathematical “big bang” was attention
getting when first discovered for the same reason that big bang is compelling in
physics. Mathematicians, logicians, and philosophers contemplated being able
to generate all of the intellectual universe from nothing. (It’s not so easy!)

Exercises
1. a) List all the elements in P({a, b, c, d}).
b) List all the elements in P2 ({a, b, c, d, e}).
2. Find three distinct elements in each of the following sets: You must use cor-
rect notation.
• P(P({a, b}))
• P2 (P(Z))
• P3 (P2 (P1 (Z)))
• P(P(P(∅)))
3. Show that P2 ({1, 2, 3, 4}) ⊆ P({1, 2, 3, 4, 5, 6}).
Is P2 ({1, 2, 3, 4}) ⊆ {1, 2, 3, 4, 5, 6}?

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Basic set theory Chapter | 2 33

2.3 Set operations


In this section we consider how to create new sets from known ones. You can
regard the powerset, which takes a known set A and produces a new set P(A),
as defining an operation on sets. Using that one operation and our basic sets D,
A, etc., we have plenty of well-defined sets to study. But we need more.
In this section we describe four other essential operations, the union, the
intersection, the complement, and the Cartesian product. (There are lots more.)

Definition 2.4. The union of two sets A and B, notated A ∪ B, is defined by


A ∪ B = {x | x ∈ A or x ∈ B}. ♠

It is important to understand that the “or” used in the bracket notation of the
definition is meant in the scientific default, in other words, one, or the other, or
both. This is the inclusive or, which is contrasted with the exclusive or which
one hears in the restaurant when you are asked if you would like the vegetarian
or the non-vegetarian entré. In this text, specifically, every “or” is presumed to
be meant inclusively.

Example 2.5. Let A = {1, 0, a} and B = {a, b, c, 0, π}. Then A ∪ B = {1, 0,


a, a, b, c, 0, π} = {1, 0, a, b, c, π}, where it is equally valid to write the mem-
bership list with or without duplicates. ♦

The union operation is both commutative and associative; so A ∪ B = B ∪ A,


and (A ∪ B) ∪ C = A ∪ (B ∪ C). If A and B are finite, then the cardinality of
the union satisfies max(|A|, |B|) ≤ |A ∪ B| ≤ |A| + |B|.
The intersection is a similar construction, with “or” replaced by “and”. That
is good since “and” seems less ambiguous in natural language.

Definition 2.6. The intersection of two sets A and B, notated A ∩ B, is defined


by A ∩ B = {x | x ∈ A and x ∈ B}. ♠

Example 2.7. With the same example A = {1, 0, a}, and B = {a, b, c, 0, π}, it
is not so easy to simply write down the intersection. It requires work. I must
check each candidate element of A for membership in the set B before it can be
placed in the intersection. A ∩ B = {0, a} records the result. ♦

The intersection operation is also both commutative and associative; A ∩


B = B ∩A, (A∩B)∩C = A∩(B ∩C). If A and B are finite, then the cardinality
of the intersection satisfies 0 ≤ |A ∩ B| ≤ min(|A|, |B|).
So, as a general idea, both the union and the intersection are obviously useful
and easy to describe – the union consisting of those elements which are in A and
B, and the intersection being made up of those elements which are in A and B.
But before you go reading merrily along, read that last sentence again. I hope it
made perfect sense to you when you read it, and it seems correct to me now as I
proofread it, but do you notice that almost exactly the same words were used to
describe the two different situations? It made sense because, in each case, you

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


34 Discrete Mathematics With Logic

knew what was meant, and chose automatically which of the meanings to take,
probably not even noticing the ambiguity. And that ambiguity was not in the
sketchy word “or”, but in our good friend “and”. This is normal. It happens all
the time if we communicate in natural language, which we must if we want to
work on problems which occur in the natural world. One of the purposes of the
use of set theory is to give us an unambiguous mathematical vocabulary to avoid
confusion. You lose all the advantage if you always take the precise set theoretic
formulation and re-express it back in familiar natural language and work with
that. You will end up just fooling yourself. You want to gain a facility with the
proper use of this new vocabulary, so don’t try to avoid it.
Definition 2.8. The complement of the set A, denoted by Ac , is defined by
Ac = {x | x ∈
/ A}. ♠
The complement is a unary operation, like the power set, in that it acts on a
single set to create a new set. The union and intersection are both called binary
operations. The complement has a few issues in its definition and requires some
care, and the notation for the complement has not reached the same degree of
standardization as the union and intersection. Another popular notation is Ā, but
there are other important concepts competing for the overbar.
Example 2.9. Let A = {1, 0, a}, and B = {a, b, c, 0, π} again. Clearly we have
π ∈ Ac , and a ∈ / B c . But we have
√ some curious things happening here, too.
We have ∅ ∈ B c , {∅, {∅}} ∈ B c , −1 ∈ Ac , and P ⊆ Ac . Yes, these are truly
gigantic sets, which they have to be. For Ac , the query as to membership will be
answered almost always “yes” except for the three queries associated with the
number 1, the number 0 and the letter a, where the answer as to membership in
Ac is “no”. ♦
The situation of the previous example suits many situations which mathe-
maticians encounter. But, practically, the complement is often encountered in
the context of a particular collection of elements outside of which we have no
interest. You may have restricted your attention to words in a computer program
which you are writing, or characters in a game you are developing. This par-
ticular set is called the universe, and usually denoted by U. If you are working
with a universal set, then all elements from all sets you consider while working
in that universe are drawn just from that universal set, U. You can work in a
large numerical universe consisting of numbers and sets of numbers, such as
R ∪ P(R) ∪ P(P(R)) ∪ . . ., or you may prefer to do work in a tiny universe
like U = D ∪ A. For that tiny one, Ac = {x ∈ U | x ∈ / A} and consists of just
33 elements, i.e., those digits and letters not equal to 0, 1, or 1a, which for
that universe is a lot. For this meaning of the complement it is also said that
Ac is the complement of A relative to U. If the universe is a finite set, then
|Ac | = |U| − |A|.
Definition 2.10. The Cartesian product of two sets A and B, notated A × B, is
defined by A × B = {(a, b) | a ∈ A; b ∈ B}. ♠

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Basic set theory Chapter | 2 35

The Cartesian product is another binary operation but, like the power set, the
Cartesian product results not only in a new set of elements, but in a set whose
elements are a new type of thing, ordered pairs, of existing elements.

Example 2.11. Again with the same example sets A = {1, 0, a}, and B =
{a, b, c, 0, π}, in order to create A × B we have to, for each of the three el-
ements allowed to be in the first coordinate of the pair, place any of the five
allowable elements of B into the second coordinate, so A × B will have fifteen
elements

A × B = {(1, a), (1, b), (1, c), (1, 0), (1, π), (0, a), (0, b), (0, c), (0, 0), (0, π),
(a, a), (a, b), (a, c), (a, 0), (a, π)}.

Notice particularly that (a, a) and (0, 0) are included because a, 0 ∈ A ∩ B, but
no other pair of identical coordinates is included. Notice also that, even though
(a, a) ∈ A × B, a ∈/ A × B. ♦

If A and B are finite, then |A × B| = |A| · |B| by the multiplicative princi-


ple. You should observe that the Cartesian product is not commutative and not
associative.

Exercises
1. Let X = {0, ∅} and Y = {∅, π}.
a. List all elements of P2 (X ∪ Y ).
b. List all elements of P2 (X ∩ Y ).
c. List all elements of P2 (X × Y ).
2. Let A = {0, 2, 4, 6, 8}, and B = {1, 3, 5, 7, 9}.
a. List five different elements of A × (B × (A ∪ B)).
b. How many elements does this set have? (Use the multiplicative princi-
ple)
3. Let P = {a, b, c}, Q = {c, d, e} and R = {e, f, a}.
a. Find all elements of P((P ∩ Q) × (Q ∩ R) × (R ∩ P )).
b. Find all elements of P(P ∩ Q) × P(Q ∩ R) × P(R ∩ P ).

2.4 Set identities


Basic laws
As noted above, the union and intersection are both commutative and asso-
ciative, and have a special relation with ∅. These properties can be written as
identities. For all sets A, B, and C:

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


36 Discrete Mathematics With Logic

A∪A = A A∩A = A
A∪∅ = A A∩∅ = ∅
A∪B = B ∪A A∩B = B ∩A
A ∪ (B ∪ C) = (A ∪ B) ∪ C A ∩ (B ∩ C) = (A ∩ B) ∩ C
(Ac )c = A ∅c = U
(2.1)

Distributive laws
Just like in ordinary algebra, where multiplication distributes over addition and
gives the identity a(b +c) = ab +ac, the set operations also satisfy a distributive
law. For sets the law works more generally in that ∩ distributes over ∪ and also
∪ distributes over ∩. So, for sets A, B and C:

A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C)
A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C)

De Morgan’s laws
The interaction of the complement with the basic operations is expressed in De
Morgan’s laws. For all sets A and B:

(A ∩ B)c = Ac ∪ B c (A ∪ B)c = Ac ∩ B c (2.2)

Condition for set equality


The next result might not look like an identity now, and might not seem impor-
tant enough to mention, but for us it is the most important. Some authors think
of it as a key definition, but we express it as a theorem.

Theorem 2.12 (Condition for Set Equality). Two sets A and B are equal if and
only if A ⊆ B and B ⊆ A are both true.

Proof. The assertion hardly merits a proof. If the sets are equal, then the subset
relations hold because every set is a subset of itself. On the other hand, if each is
a subset of the other, then neither can have any element which the other does not
have, so the sets have the same elements, which means that they are the same
set.

The reason this obvious result comes up so often is that, generally, deciding
whether two collections are exactly the same requires us to divide our attention
between two sets, possibly different, at least specified in different ways, com-
paring all their many elements having perhaps many duplicate specifications. It
is very easy to get confused. Dividing the task into two parts helps right there,
but even more, showing the subset relation, instead of set equality, allows us

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Basic set theory Chapter | 2 37

to focus our attention on one element and its properties, rather than the whole
set. Using the theorem in this way is such an essential trick that we call it the
Double Inclusion Method. This method comes up very often when people sus-
pect that they are looking at the same thing in two different ways. We devote
the next section to the method, where we apply it to simple examples mostly
based on the identities stated in this section. But keep in mind, it is Condition
for Set Equality, Theorem 2.12, which is important, and it is the double inclu-
sion method which we are trying to get practice using, not the simple identities
we are applying it to.

Exercises
1. Suppose A ⊆ B ⊆ C. Show that (A × B) ⊆ (B × C).
a. Use the method we discussed of showing the subset relation.
b. Need it be true that (B × C) ⊆ (A × B)?
2. As part of using the double inclusion method to show that A ∪ (B ∩ C) =
(A ∪ B) ∩ (A ∪ C) we would have to show A ∪ (B ∩ C) ⊆ (A ∪ B) ∩ (A ∪ C)
for any sets A, B and C.
Show A ∪ (B ∩ C) ⊆ (A ∪ B) ∩ (A ∪ C).
3. As part of using the double inclusion method to show that A ∪ (B ∩ C) =
(A ∪ B) ∩ (A ∪ C) we would have to show A ∪ (B ∩ C) ⊇ (A ∪ B) ∩ (A ∪ C)
for any sets A, B and C.
Show (A ∪ B) ∩ (A ∪ C) ⊆ A ∪ (B ∩ C).
[Hint: The two cases x ∈ A, and x ∈
/ A make the argument simpler.]

2.5 Double inclusion


In this section we will be illustrating how to prove identities using the double
inclusion method. We will illustrate the method three times. The first is with a
less familiar identity, not found in the previous section. We will give the identity,
then a proof, and then provide a long commentary on that proof.
Theorem 2.13. Let A and B be sets. Then P(A) ∩ P(B) = P(A ∩ B).
Proof. We first show P(A) ∩ P(B) ⊆ P(A ∩ B). Let x ∈ P(A) ∩ P(B). Then
x ∈ P(A) and x ∈ P(B). The first fact implies x ⊆ A. The second fact implies
x ⊆ B. So x ⊆ A ∩ B, and x ∈ P(A ∩ B), as required.
We next show that P(A ∩ B) ⊆ P(A) ∩ P(B). Let y ∈ P(A ∩ B). So y ⊆
A ∩ B. Since y ⊆ A ∩ B, it follows that y ⊆ A, and as well that y ⊆ B. So we
have that y ∈ P(A) and y ∈ P(B). Thus y ∈ P(A) ∩ P(B), finishing the second
demonstration.
Since each set is contained in the other, the identity is true by Theorem 2.12.

Commentary: The first thing to notice is “Let x”. You want to show that
the subset relation holds, so you have to show that each element of P(A) is

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


38 Discrete Mathematics With Logic

contained in the other set. You cannot do it by checking elements one by one.
You don’t even know which set A is referred to. Instead, you take a general
element, call it something, x, and then restrict your attention to that x, and the
properties it inherits from membership in P(A). Then you use those properties
of x in order to show that x also has the qualities required for membership in the
other set. This is the power of the double inclusion method mentioned at the end
of the last section; that we can focus on an individual element and its properties,
instead of the two sets and their many elements.
The second thing to notice is “as required”. Required by whom? If you are
the proof writer, then it is you who made that requirement when you announced
that you were going to show set containment, and made the first “let”.
The third thing to notice is that you can probably think of many ways that
you might have written this proof differently; maybe easier to follow, perhaps
shorter. Maybe you don’t like that I chose x for the general element when, since
it turned out to be a set, it could be clearer to use X. Maybe you think there
should be a little more detail, or a little less. Even in model proofs like this there
is room for expression, personality, and style. How do you avoid freezing up,
paralyzed by the choices? I think it helps tremendously to turn your attention
from yourself to the reader, and what the reader needs to be told. All a proof
is, ultimately, is a convincing argument – an argument convincing to an open
minded, but sceptical reader – someone willing to be persuaded, but only after
being convinced that the argument is sound and in which every detail is actually
correct. That is how you should listen to proofs.
And what if you, the reader, don’t agree? What then? It can happen that you
see an error and you can explain the problem. But probably not. Likely as not
you don’t follow the argument because it is too complicated for you, or because
the writer is confused and has made a mistake, or because there are differing
definitions. But whatever the reason, you cannot accept the result as having been
proven. That doesn’t mean you can conclude the assertion is false, just that you
are unconvinced by that argument.
Next, I will show you how to completely destroy the first half of the proof:
. . . . . . P(A) ∩ P(B) ⊆ P(A ∩ B). x ∈ P(A) ∩ P(B), x ∈ P(A), x ∈ P(B), x ⊆ A,
x ⊆ B, x ⊆ A ∩ B, x ∈ P(A ∩ B) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

This is by far the most common student mistake. The idea seems to be that a
proof gets more mathematical, and shorter, and truer, if you just leave all those
non-mathematical words out. But if you leave the words out, you leave the whole
argument out! Look at all those bare equations, some of which were goals to be
done, some just assumptions for the sake of argument, some conclusions. They
are now just asserted altogether as bare facts. As a proof, it must be wrong. You
cannot convince without an argument. So you might as well try putting in the
words and risk making a poor argument, rather than leaving them out and be
sure that it fails.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Basic set theory Chapter | 2 39

Another point: that jumbled mess of equations in the previous paragraph


does look an awful lot like what you see on the black board, or whiteboard,
or slides of professionals, professors and other experts. Don’t be fooled. For
a presentation, the presenter is speaking, weaving those ingredients together to
present a convincing argument. The slides alone are often a woefully inadequate
substitute.
One last word of commentary. As you write a proof, your goal is to convince
the reader. Who is this reader? It is much easier to write anything if you can
imagine to whom you are writing. It is a huge mistake to tailor any argument
to convince a person who you believe knows much more than you do. That
is a hopeless task. So don’t imagine that you are writing to your professor, or
the smartest person in the room. Don’t imagine, contrariwise, that your reader
knows nothing. The reader who knows nothing is not interested in your proof.
In general, you should imagine the reader as one of your colleagues, someone
who is about at your level but who just doesn’t know about this particular thing
which you want to explain, say your own self as you were last week.
Now let’s prove one of the set identities from the previous section by the
double inclusion method,

A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C)

and then there will be a very short commentary.

Proof. First we will show that A ∩ (B ∪ C) ⊆ (A ∩ B) ∪ (A ∩ C). Let d ∈


A ∩ (B ∪ C), so d ∈ A and d ∈ B ∪ C. From the second fact, we are led to
consider two cases:
Case 1: d ∈ B. Here, since d ∈ A, we have d ∈ A ∩ B, so d ∈ (A ∩ B) ∪
(A ∩ C).
Case 2: d ∈ C. Now d ∈ A implies d ∈ A ∩ C, so again d ∈ (A ∩ B) ∪
(A ∩ C).
In either case, d ∈ (A ∩ B) ∪ (A ∩ C), as required.
Next we want to check (A ∩ B) ∪ (A ∩ C) ⊆ A ∩ (B ∪ C) and assume e ∈
(A ∩ B) ∪ (A ∩ C). So we consider on the one hand that e ∈ (A ∩ B), in which
case e ∈ A and e ∈ B hence e ∈ B ∪ C and conclude e ∈ A ∩ (B ∪ C); and on
the other side you might have e ∈ (A ∩ B), and get that both e ∈ A and e ∈ B
leading me to the same ending. Therefore (A ∩ B) ∪ (A ∩ C) ⊆ A ∩ (B ∪ C)
and the identity is proved.

Commentary: The two halves are written in different styles, as if in a team


with several authors. The first part is crisply laid out into cases. The second part
is mostly one long run-on sentence with shifting voice, inconsistent punctuation,
and other errors. As writing it may be horribly ugly, but it is valid, and that is
the only mathematically important issue. You may be wondering about the ‘third
case’, when d is in both sets – then both cases apply, so the conclusion certainly

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


40 Discrete Mathematics With Logic

holds, and you would be wasting your time to add a third case to handle what
has already been done twice, even though it is valid to do so.
Our third proof moves us just a bit beyond the set identities which we are
using for practice. X will be the set of all even natural numbers, and Y and Z
those numbers divisible by 3 and 6.

Theorem 2.14. Let X = {x | x = 2i; i ∈ N}, Y = {y | y = 3j ; j ∈ N}, and Z =


{z | z = 6k; k ∈ N}. Then Z = X ∩ Y .

Proof. First let z ∈ Z. Then z = 6k for some k ∈ N, and 6k = 2(3k) = 3(2k).


Setting i = 3k ∈ N implies x = 2i ∈ X, and setting j = 2k ∈ N implies x = 3j ∈
Y. Thus z ∈ X ∩ Y as required.
Now let z ∈ X ∩ Y . So z = 2i = 3j . Since z = 2i, z is even. Since z = 3j , j
must be even. So j = 2k for some k ∈ N, and z = 3(2k) = 6k. This says z ∈ Z,
as required.

Commentary: Many people don’t like that the letter z from the first half was
recycled in the second half for a different number. But one finds that in double
inclusion proofs quite often.

Exercises
Assertion: Let A be a set. Then A = P(A).
Proof: Part 1: Clearly A is in P(A), so A ⊆ P(A).
Part 2: Now to show P(A) ⊆ A. Let X be contained in P(A). Then every
element of X is contained in A, so X is contained in A. Since everything in
P(A) is contained in A, P(A) ⊆ A.
Part 3: Since P(A) ⊆ A and A ⊆ P(A), we have P(A) = A.
1. Find any flaws in Part 1 that you can.
2. Find any flaws in Part 2 that you can.
3. Find any flaws in Part 3 that you can.

2.6 Russell’s paradox


Recall when defining the complement we talked about a universal set. It is com-
mon to work with a universal set containing all the elements which you are
interested in, a universal set tailored to a problem or collection of problems. The
only difficulty with that is that some of the standard operations, like P and ×,
create sets with elements of new types, and these elements might be “outside
the universe”, like in a science fiction movie. One way to avoid this is to try to
define a really gigantic universe from which there is no escape. A good place to
start might be

S — The set of all sets

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Basic set theory Chapter | 2 41

Once we have the set of all sets, we can easily construct a universal set big
enough to suit to anybody anywhere by

U = {x ∈ S | S ∈ S}.

But S has a property not seen in any of the sets we have considered so far.
The set S is an element of itself: S ∈ S. This looks familiar, but isn’t. It is the
relation A ⊆ A which is true for all sets; every set is a subset of itself. What
about power sets? For any of the sets we have considered, X ∈ P(X), but we
have never had P(X) ∈ P(X), instead having P(X) ∈ P(P(X)).
Let’s try to build a small example, a set containing just itself and the num-
ber 1. So 1 ∈ X and X ∈ X, which gives X = {1, X}. That looks ok at first, but
then that says X = {1, {1, X}} = {1, {1, {1, {1, . . .}}}} and it is hard to figure out
what the . . . even means. After all, what is that other element? We seem to be
stuck. These guys seem not so easy to construct.
Suppose you are a conservative person, and this property makes you uncom-
fortable, and you don’t want to consider such sets. You might want a restrict
yourself to sets which are more ordinary:

R = {X ∈ S | X ∈
/ X}.

R looks much safer than S. R contains precisely those sets which are not ele-
ments of themselves.
But what about R itself, is R ∈ R? On the one hand if R ∈ R, then R fails to
satisfy the property specified in its definition for membership, so we would have
to conclude, contradictorily, that R ∈ / R. On the other hand, if you surrender and
accept that R ∈/ R, then R passes the requirement for being an element of the set
R, and we are confronted again with the reverse, R ∈ R. So we have arrived at
an impasse, a contradiction. Normally that is ok. Arriving at a contradiction just
means that some assumption which we have made is incorrect. Identifying the
false assumption is progress. But here we don’t seem to have assumed anything
at all. We were just getting started constructing things.
If this makes you scratch your head, you are not alone. This conundrum
was a bucket of cold water in the face of many people when Bertrand Russell
expounded it a century ago, and it is called Russell’s paradox. The problem was
quickly identified as resulting from the fact that the set S refers to itself in its
own definition; a trick used in other linguistic problems long known to logicians
and philosophers. That is what we encountered with {1, {1, {1, {1, {1, ????}}}}}.
There are essentially three ways out of this problem. One is to avoid self-
reference by forcing sets to be in a hierarchy, in other words, elements belong
to sets, sets belong to classes, classes belong to super-classes, etc. The second
way out is to make set theory axiomatic, as is done with Euclidean geometry,
where you seem to be proving theorems about points and lines in space, but you
are actually proving things about “points”, and “lines”, in a closed system of as-
sumptions. We will follow the third way, which is what is done by most people

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


42 Discrete Mathematics With Logic

who simply want to use sets to solve practical problems – which is to start with
the elements we are interested in, numbers, sets of numbers, letters, game char-
acters, words in a computer program, etc.; then expand this working universe as
necessary, and not even attempt to contemplate a whole and complete system.
So the moral of this very abstract story is, beware of definitions which refer
to themselves and, the universe is actually important.

Exercises
1. Overheard conversation between Pat and Mike:
Pat: Mike, you always lie.
Mike: Yeah, and I am lying right now.
Who is telling the truth?
2. Sign at the bus stop:
The sentence below is true.
The sentence above is false.
Which of these lines is true?
3. Which of these three problems involve self-reference?

2.7 Case study: Polyhedra


If you have ever played a game needing exotic dice, or investigated three dimen-
sional symmetric objects, then you have seen the five Platonic solids,

perhaps better rendered than in this hand drawing by Johannes Kepler from back
in the day when four elements, earth, water, air and fire, seemed plenty. Other-
wise, all but one of these interesting objects, the common cube, are probably
unfamiliar to you.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Basic set theory Chapter | 2 43

One of the reasons people have been fascinated by these five objects is the
fact that there are only five. There may be an infinite number of interesting three
dimensional solids, but these are the only ones all of whose hedra, faces, are
congruent regular polygons, with the same number of polygons coming together
at each vertex.
In general, polyhedra may be thought of as being obtained by starting
with all of continuous three dimensional space, and methodically cutting away
chunks of it, leaving a solid with a finite number of flat faces on its surface where
the cuts were made. Of course, most polyhedra will not be regular or symmetric,
but in this case study we will only look at symmetric examples.
How do we make this idea of cutting away space precise? With set theory.
Instead of a knife, we use a set called a half-plane and instead cutting, we in-
tersect. A plane does “cut through space” with points on either side. Let v be a
point not at the origin, and let Pv denote the plane through v and perpendicular,
or orthogonal, to the segment from the origin to v. If you know some vector
algebra, Pv = {x ∈ R3 | x · v = v · v}, and the half-plane which Pv bounds and
which contains the origin is Hv = {x ∈ R3 | x · v ≤ v · v}. The cube can now be
expressed as the set C = Hi ∩ Hj ∩ Hk ∩ H−i ∩ H−j ∩ H−k . This is more than
a mere description. The set theoretic interplay of six cutting planes of C holds
the key to C’s “cubyness”. The top square face of the cube is fk = Pk ∩ C, just
one of the six faces of C.
The surface of the polyhedron, besides the finite set of faces, F , also has a
finite set of edges, E, line segments obtained from the intersection of two inci-
dent faces. For example, in C, find fk ∩ f−j . There is also a finite set of vertices,
V, whose elements are singleton sets of the form v = {(x, y, z)} corresponding
to isolated points where three or more faces have an non-empty intersection, see
Fig. 2.1, where faces f1 and f2 intersect in edge e, and f1 ∩ f2 ∩ f3 = v.

FIGURE 2.1 a) A dodecahedron and b) a cube with labeled vertices.

Given a set of labels of one type of object, set operations allow us to generate
natural labels for the others. For example, for the cube, take the eight vertex
labels to be V = {a, b, c, d, A, B, C, D}, always choosing the capital and lower
case version of the same letter to be opposite, and never labeling the endpoint
of any edge with letters of the same case.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


44 Discrete Mathematics With Logic

Once the vertex labels are chosen, it is natural to label the elements of the
edge set E from the set P2 (V), labeling each edge with the pairs of vertex labels
for the endpoints of that edge. For our cube, the elements of the set E consist
of pairs, one upper case and one lower case, never belonging to the same letter.
The twelve edges have labels:

E ={{A, b}, {A, c}, {A, d}, {B, a}, {B, c}, {B, d},
{C, a}, {C, b}, {C, d}, {D, a}, {D, b}, {D, c}}.

Following this system, the face labels of a polyhedron will naturally be


elements of P(V), with each face labeled by the subset of vertex labels cor-
responding to the set of vertices it contains. Since the polygon with the fewest
vertices is a triangle, every face label will be a subset of V of cardinality at least
three, and no face label will also be an edge label. For the cube all faces   are
squares, hence the face labels are elements of P4 (V) and consist of all 42 pairs
of the four capitals {A, B, C, D} together with the complementary pair of lower
case letters. So F consists of

{{A, B, c, d}, {A, C, b, d}, {A, D, b, c}, {B, C, a, d}, {B, D, a, c}, {C, D, a, b}}.

The tetrahedron of Fig. 2.2a with vertexset V = {A, B, C, D} is an extreme


case in which the edge set is labeled by all 42 elements of P2 (V),

{{A, B}, {A, C}, {A, D}, {B, C}, {B, D}, {C, D}}.

and the triangular faces are labeled by all 43 elements of P3 (V) = {{A, B, C},
{A, B, D}, {A, C, D}, {B, C, D}}.

FIGURE 2.2 a) A tetrahedron and b) an octahedron with labeled vertices.

The elements of V = {A, B, C, a, b, c}, vertices of the octahedron labeled


as in Fig. 2.2b, contribute to eight triangular faces, F ⊆ P3 (V). Each has a
representative of each letter, and all possible choices of capital and lower case
occur.

{{a, b, c}, {a, b, C}, {a, B, c}, {a, B, C},


{A, b, c}, {A, b, C}, {A, B, c}, {A, B, C}}.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Basic set theory Chapter | 2 45


There are 62 = 15 2-subsets of V, and all correspond to edges except {A, a},
{B, b}, and {C, c}.
Nice labeling choices for the icosahedron and the dodecahedron exist, but
are harder to motivate and describe.
No matter how their constituent parts are labeled, the five platonic solids all
satisfy
|V| − |E| + |F | = 2,
which turns out to be true not only for the five platonic solids, but all three-
dimensional polyhedra (cf. Theorem 9.14).

2.8 Case study: The missing region problem


Related to the problem of describing polyhedra is the problem of dissecting
the plane into regions. This is an important, well-studied problem. Here is one
version.
Consider a circle C in the plane and a finite subset V ⊆ C. Let D, for “disc”,
be the union of C with the set of all points in the interior of C. For each element
of P2 (V ), draw the line segment joining them, their chord. You now have a
circle with |V2 | chords. Into how many regions is D divided by these chords?
The answer should depend on the cardinality of V as well as how the points
are placed on the circle. For some preliminary data look at Fig. 2.3. If n is even
and the elements of the set V are equally spaced, then there are |V |/2 diameters
meeting at the center of the circle, as in the case of the square and the hexagon
in Fig. 2.3, and the number of regions are divisible by 4 and 6 respectively. It is
mildly surprising that the fivefold symmetry of the pentagon/pentagram yields
a number of regions, 16, which is not divisible by 5, but that is because of the
exceptional central five-fold symmetric region. Other than that, the regions do
come in three symmetric subsets containing 5 elements each, giving 3 · 5 + 1 =
16 regions all together.

FIGURE 2.3 Dividing the circle into regions.

It seems no more than a coincidence that the number of regions for 5 points
is a power of 2, until one notices that the same is true for all the examples in
Fig. 2.3 except the last one. In fact, the first five cases all follow the simple
formula 2|V |−1 for the number of regions. Unfortunately, it is easy to count that
the last one has only 30 regions, not 32, which would be the next power of 2.
The last diagram does have that special point, the point in the very center,
where three diameters meet. Perhaps we have that special point at the cost of

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


46 Discrete Mathematics With Logic

some extra regions. Perhaps instead of looking at very symmetric elements of


P6 (C), we should look in the other direction, asymmetric, generic, or random
subsets of cardinality 6 of the circle. If the set of regular points on the circle C
are perturbed a little, as in Fig. 2.4, none of the other counts are changed, but
the last one does get yet one more region.

FIGURE 2.4 Dividing the circle into uglier regions.

The Missing Region Problem asks: Can we perturb again so that the missing
32nd region appears?

2.9 Case study: Soma


Soma is a dissection puzzle invented by Piet Hein, patented in the 1930’s as
a 3D puzzle. It has been in production ever since. Soma is built from 27 little
cubes glued permanently into seven distinct irregular pieces. Since 33 = 27, it is
conceivable that the 7 irregular pieces can be assembled into a 3 × 3 × 3 cube,
and that is one of the more popular objectives of the puzzle, see Fig. 2.6.

FIGURE 2.5 Non-convex assemblies of four or fewer cubes.

FIGURE 2.6 One view of an assembled Soma cube.

A reasonably attentive adult with no special mathematical skills can often


solve the puzzle in less than ten minutes. It often happens, however, that another
person will remain stymied by the Soma cube for hours or even days. If that
happens, it is of course frustrating, but this is part of the charm of the puzzle.
We will see shortly why it is that some people find themselves stumped so much
longer than many others.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Basic set theory Chapter | 2 47

The method most people use is to try various combinations mostly at ran-
dom. A generally successful approach of this kind is to fill in first about half the
pieces, and then try to methodically vary the placement of the remainder to com-
plete the cube. For many puzzles, committing to a partial solution and trying to
complete from there would be a very bad strategy since it is common for puzzle
designers to allow only for a unique solution. But Soma has 240 ‘solutions’.
One question is whether mathematics helps speed up the solution process.
A more ambitious problem is to find and enumerate all possible solutions up
to symmetry. A quick and dirty computer program could be written to exam-
ine all the combinations of possible positions of each of the pieces and check
for compatibility. Unfortunately, unless one takes care, this approach yields a
combinatorial explosion. You may compute that the second piece in Fig. 2.5,
for instance, may be placed in the 3 × 3 × 3 cube in 144 ways. A more success-
ful approach is to apply a “branch and bound” strategy to avoid reconsidering
rejected configurations for different reasons. The most sophisticated computer
to have completely enumerated all possible solutions consisted of two self-
programming parallel organic processors, John Horton Conway and Michael
J.T. Guy, coming together in 1961, the job taking all of a Saturday to com-
plete.
The most important observation to simplify this problem is to notice that
the set S of 27 subcubes of a solution is partitioned into 4 subsets, S = V ∪
E ∪ F ∪ C, having empty intersection with one another, corresponding to the
different parts of the cube. The set V contains the 8 subcubes at the vertices of
the large cube, the set E the 12 subcubes at the edges, the set F the 6 subcubes
at the face centers, and C the one subcube at the center. It helps to imagine the
subcubes of different sets in different colors. Another interesting partition is the
‘checkerboard partition’, S = (V ∪ F ) ∪ (E ∪ C). The set V ∪ F has cardinality
14 and we’ll imagine its elements colored red, and the set F ∪ C has cardinality
13 and we’ll imagine its elements colored blue.
Let’s consider the red/blue coloring with regard to the individual Soma
pieces. There is a 4-subset of the set of pieces which must be colored two blue
and two red in any solution, see Fig. 2.7. That leaves 6 red and 5 blue to be
accounted for with the three elements of the complement, the subset of biased
pieces. Two elements of that subset, look in Fig. 2.5 for which ones, must have
either three red and one blue, or the reverse. They both cannot be biased in the
same way, since then those two pieces would account for 6 cubes of one color
all by themselves.

FIGURE 2.7 These four pieces have only balanced two-colorings.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


48 Discrete Mathematics With Logic

Thus the two larger biased pieces must be biased oppositely, their bias can-
celing one another out. Therefore it must be true that the little piece must be
biased in favor of red.
So we have found two conditions which obstruct a partial solution ever being
completed. (There is another nice one you can find by considering the corners
alone.) If the two larger biased pieces are placed so that their biases do not
cancel, it is impossible to complete the Soma cube, just like if the smallest piece
is not placed to be biased in favor of vertex/face positions. If your start has
violated either of these, you may as well disassemble and restart from scratch.

2.10 Summary exercises


You should have learned about:
• Basics about sets, the power set of a set and its cardinality
• Set operations – how to build new sets from existing ones
• Set identities: basic laws, distributive laws, De Morgan’s laws
• How to prove set identities using the double inclusion methods
• What is Russell’s paradox and why it is a paradox
1. Compute |{n/m ∈ Q | n ∈ N; m ∈ N; 1 ≤ n ≤ m ≤ 3}|.
2. Use the bracket notation to describe each of the following sets.
a) Odd integers.
b) Integers whose remainder is 1 when divided by 3.
c) Rational numbers whose denominator can be expressed as a power  of 2.
3. Consider the set X = D ∪ P(D). Find a subset with cardinality 2 83 + 13.
4. Let S = {z2 − 4z + 44 | z ∈ Z}. Prove that S ⊆ N.
5. Let A, B, C, and D be subsets of Z. Show that

(A ∩ B ∩ C) ⊆ (A ∪ D) ∩ (B ∪ D) ∩ (C ∪ D).

Give an example to show that

(A ∪ D) ∩ (B ∪ D) ∩ (C ∪ D) ⊆ (A ∩ B ∩ C)

need not be true.


6. Let A, B, and C be sets. Show using the set identities that

(A ∪ B) ∩ (C ∪ Ac ) = (A ∩ C) ∪ (B ∩ C) ∪ (Ac ∩ B).

7. Let A, B, and C be sets. Show by the double inclusion method that

(A ∪ B) ∩ (C ∪ Ac ) = (A ∩ C) ∪ (B ∩ C) ∪ (Ac ∩ B).

[Hint: For one direction it helps to consider the cases x ∈ A versus x ∈


/ A.]
8. Let X, Y , and Z be sets. Prove using the double inclusion method that

X ∪ (Z ∪ Y ) = (Y ∪ X) ∪ Z.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Basic set theory Chapter | 2 49

9. Let A and B be sets. Prove carefully by the double inclusion method that

Ac ∩ B c = (A ∪ B)c .

10. Let X, Y , and Z be sets. Prove using the double inclusion method that

X ∩ (Y ∪ Z) = (X ∩ Y ) ∪ (X ∩ Z).

11. Let X, Y , and Z be sets. Prove using the double inclusion method that

X ∪ (Y ∩ Z) = (X ∪ Y ) ∩ (X ∪ Z).

12. Let A and B be sets. Either prove carefully by the double inclusion method
that
B ∪ Ac = (Ac ∩ B)c
is true, or give an example of two sets for which the equation is false.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


This page intentionally left blank

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Chapter 3

Working with finite sets


3.1 Cardinality of finite sets
Each set operation which was defined in the previous chapter was associated
with an observation, valid if the sets were finite, about the cardinalities of the
sets involved. Here they all are gathered together:

|∅| = 0 (3.1)
max(|A|, |B|) ≤ |A ∪ B| ≤ |A| + |B| (3.2)
0 ≤ |A ∩ B| ≤ min(|A|, |B|) (3.3)
|A | = |U| − |A|
c
(3.4)
|A × B| = |A| · |B| (3.5)
|A|
|P(A)| = 2 (3.6)
 
|A|
|Pk (A)| = (3.7)
k
 n 
n n
2 =
n
= |Pk ({1, 2, . . . , n})| (3.8)
k
k=0 k=0
n    n
k n
0= (−1) = (−1)k |Pk ({1, 2, . . . , n})| , n>0
k
k=0 k=0
(3.9)

These results were justified by some application of the multiplicative principle,


and at this point you should not only find each of them familiar, but be able to
justify each of them to yourself with an explanation that is convincing to you.
For instance, some people like to think of the last two as applications of the
binomial theorem. Eq. (3.8) can also be understood as saying that the number
of subsets of an n-set can be determined by adding up the number of subsets of
the different possible cardinalities.
Eq. (3.9) states that, for any non-empty set, the number of subsets of even
cardinality is always precisely balanced by the number of subsets of odd cardi-
nality. This fact can be justified by a golden argument. If the set is non-empty,
there is one element which can be distinguished as the golden one. This golden
element allows us to pair each subset that contains the golden element to the

Discrete Mathematics With Logic. [Link] 51


Copyright © 2024 Elsevier Inc. All rights reserved.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


52 Discrete Mathematics With Logic

subset obtained by removing that golden element. In this match, one subset has
even cardinality, and the other odd, so the two types of subsets are in balance.

Exercises
1. Let X and Y be sets. Suppose 25 ≤ |X| ≤ 26 and 24 ≤ |Y | ≤ 27 .
a. What can you conclude about |X ∪ Y |?
b. What can you conclude about |X ∩ Y |?
2. Let A = {1, 2, 3, 4}, B = {a, b, c, d, e}.
a. Compute |P(P2 (A) × (B × A))|.
b. Compute |P2 (P(A) × (B × A))| + |P3 (A ∩ B)|.
|A∪B|
c. Compute k=0 (−1)k |Pk (A ∪ B)|.
3. Find the 10th and 11th rows of Pascal’s triangle. Verify that the sum of all
the entries in each row is a power of 2, and that the alternating sum of each
row is 0.

3.2 Bit vectors and ordering subsets


The formula |P(A)| = 2|A| was justified using the multiplicative principle by
associating each subset of the sequence of answers, for each element of A, to
the query of membership. We can go further with this idea and take this sequence
of answers as an encoding of that subset.
So, for example, if we have four flavors, chocolate, vanilla, strawberry, and
cherry, then there are 24 subsets of those four flavors. If we query each subset
about the membership of each of the four flavors in the order listed above, then
subset {vanilla, strawberry} would be recorded by the answer sequence no-yes-
yes-no. The awkwardness is eased by recording “yes” and “no” with the bits 1
and 0, respectively, so {vanilla, strawberry} could be recorded as (0, 1, 1, 0), or
even more compactly as 0110. If instead we query the subsets about the flavors
alphabetically, then the same subset would be recorded as 0011.
A bit vector of length n is a sequence of n bits, and may be notated in
sequence notation, like the 9 bit sequence (0, 1, 1, 0, 1, 1, 1, 1, 0), or with the
parentheses and commas suppressed for clarity, like 011011110.
Given a finite set A, with |A| = n and a particular ordering on the elements
of A,
A = {a1 , a2 , a3 , . . . , an }, ai < aj if i < j,
the bit vector of a subset X ⊆ A is (B(an ), B(an−1 ), . . . , B(a1 )) with B(ai ) = 1
if ai ∈ X, and B(ai ) = 0 otherwise.
As anticipated, the bit vector depends on the ordering chosen. It is also to
be noticed that the bit-vector associated with a subset seems to go backwards.
You’ll see why in the next example.
The bit vectors of length n are naturally associated with the binary numbers
between 0 and 2n − 1. This association gives us, along with our subset encoding,
a natural and useful ordering on those subsets.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Working with finite sets Chapter | 3 53

Example 3.1. Let A = {a, b, c}. There are 23 = 8 subsets in P({a, b, c}) and so
the 23 bit vectors of length 3 are associated and ordered as follows:

∅: 000
{a} : 001
{b} : 010
{a, b} : 011
{c} : 100
{a, c} : 101
{b, c} : 110
{a, b, c} : 111

As you can see, the ordering on the bit vectors, thought of as binary numbers,
naturally starts with 0 recording ∅, which we will regard as the “least”, and
proceeds to 001, recording a subset with the single element a, the least in the
ordering on A. If we had ordered the queries (B(a), B(b), B(c)), then the set
following the empty set would be {c}, and that would seem backwards to most
people, though not in any sense incorrect. ♦
Example 3.2. What is 1776th subset of A in the bit vector ordering, using the
alphabetical ordering of A?

For this, we naturally want to first either recall or compute that 1776 in bi-
nary is 11011110000. Written as a binary number, 1776 can be written with
only 11 bits, but as a bit vector for subsets of A one should write 1776 as a
string of length 26 = |A|, 00000000000000011011110000, and that bit vector
encodes the subset {e, f, g, h, j, k}. The next three subsets following that one
are {a, e, f, g, h, j, k}, {b, e, f, g, h, j, k}, and {a, b, e, f, g, h, j, k}. Notice that
the answer depended on our decision, made earlier, to always order from 0. So
the first subset is {a}, not ∅. The zeroth subset is ∅. (If you try to rewrite our
description of the encoding to accommodate ordering from 1, then you will ap-
preciate the simplification.) ♦
When sets were defined, it was emphasized that membership in a set imposed
no ordering on the elements, and you might have expected that order would not
play a role in set theory. As you have now seen, it plays in fact a key role. The
fundamental assumption that the elements come with no ordering a priori leaves
one free to consider not just one hardwired order, but any convenient or useful
order; or perhaps several at once, comparing and contrasting them.

Exercises
1. List the sixteen subsets of {a, b, c, d} in bit-vector order, using the usual
ordering on the letters.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


54 Discrete Mathematics With Logic

2. List the elements of P2 ({1, 2, 3, 4, 5}) in bit vector order. Give the subsets,
the bit vectors, and the decimal equivalents.
3. What is the 999th subset of {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} in bit vector order,
(starting from 0 for ∅) using the usual ordering on the set of digits?
Give the next 6 subsets as well.

3.3 Inclusion/exclusion
The cardinality of a union of two finite sets A and B, follows

max(|A|, |B|) ≤ |A ∪ B| ≤ |A| + |B|

with equality on the left if one set is a subset of the other, and equality on the
right if the two sets A and B are disjoint, that is, that A ∩ B = ∅. In between
those two extremes, the two sets just have a non-empty intersection, and every
element in that intersection is double counted in the expression |A| + |B|. That
observation of double counting leads us to the identity

|A ∪ B| = |A| + |B| − |A ∩ B|.

Here is the formula for the cardinality of the union of three sets,

|A ∪ B ∪ C| = |A| + |B| + |C| − |A ∩ B| − |A ∩ C| − |B ∩ C| + |A ∩ B ∩ C|,

which can be justified by using the top formula twice, along with the associative
law of set union. (Try it if you are interested.) Alternatively, we can consider
which elements are over-counted in |A| + |B| + |C|. The expression −|A ∩ B| −
|A ∩ C| − |B ∩ C| removes all the over-counts, no matter what the cause, with
the only problem being that those elements in all three sets have been removed
three times. Those same elements were included three times in |A| + |B| + |C|,
so excluding them three times leaves them totally uncounted, that is until the
last term |A ∩ B ∩ C| includes them once in the end. So the 7-term expression
counts each element exactly once overall. This justification gives the formula its
name, the inclusion/exclusion principle, called a principle and not a formula by
virtue of its use in solving practical and theoretical problems.
There is an inclusion/exclusion principle for any number of sets. In general,
for n finite sets A1 , A2 , . . . An , we have

|A1 ∪ A2 ∪ · · · ∪ An | = |A1 | + |A2 | + · · · |An |


− [|A1 ∩ A2 | − |A1 ∩ A3 | − |A2 ∩ A3 | − · · · |An−1 ∩ An |]
+ [|A1 ∩ A2 ∩ A3 | − |A1 ∩ A2 ∩ A4 | − · · · |An−2 ∩ An−1 ∩ An |]
..
.
+ (−1)n+1 |A1 ∩ A2 ∩ · · · ∩ An |

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Working with finite sets Chapter | 3 55

and if you don’t see how to fill in the “. . . ”, here is the principle of inclusion/ex-
clusion written more precisely:
 n   
    
  |I |+1  
 Ak  = (−1)  Ai  (3.10)
   
k=1 ∅=I ⊆{1,2,3,...,n} i∈I

In this form, it is a bit intimidating. Let us leave it and a general explanation for
a bit. First let’s see how it is used. Student exercises mostly use the principle
with at most four sets.
Even then, you may think that the inclusion/exclusion formula is just ridicu-
lous. A simple count should tell you that, in computing |A1 ∪ A2 ∪ · · · ∪ An |
by inclusion/exclusion you would have to accurately compute the cardinalities
of 2n − 1 different sets, and do all the accounting assembling the results, and
not making any sign error. Even for n = 3 that is seven intersections, the cardi-
nalities of seven sets to compute, seven terms to keep track of. How could that
ever be simpler than simply computing the cardinality of |A1 ∪ A2 ∪ · · · ∪ An |
directly?

Example 3.3. How many six letter words on A either start with an a, like
abcabc, or end with a b, like xxbbbb, or repeat in pairs, like xyxyxy?

As individual problems, each is a simple exercise in the multiplicative principle.


But by accepting words which satisfy any one of the conditions, we cannot
just solve it as three separate problems because the conditions interact. But we
can apply inclusion/exclusion, the first step being not to start computing, but to
define the sets which transform the problem into one of set cardinality. Let A
be the set of six letter words on A which start with an a, let B be the set of
six letter words on A which end with letter b, and let C be the set of six letter
words on A which repeat in pairs. We can now compute |A|, |B| and |C| by the
multiplicative principle: |A| = 265 , |B| = 265 , and C = 262 . Better than that,
the intersections we need can also be so attacked: |A ∩ B| = 264 , |A ∩ C| = 26,
|B ∩ C| = 26. Even A ∩ B ∩ C has a computable cardinality, |A ∩ B ∩ C| = 1.
Now inclusion/exclusion gives the final result:

265 + 265 + 262 − 264 − 26 − 26 + 1.

So, actually, we were quite happy to trade the single complicated union cardi-
nality problem for the 7 routine intersection cardinality problems. ♦

This doesn’t exactly refute the objection above. That objection noticed that
applying inclusion/exclusion would involve us in a combinatorial explosion,
that is, a situation where each incremental increase in the size of the problem
multiplies our work in solving it by an unyielding factor. That explosion is there,

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


56 Discrete Mathematics With Logic

and using inclusion/exclusion does not cure that explosion at all, but at least it
does help us to manage it as efficiently as can be expected.
Now, to justify the general result in Eq. (3.10) we fix an element x and,
to examine how often x is included and excluded, we consider the set B =
{X ∈ {A1 , A2 , . . . , An } | x ∈ X} of those Ai which contain x. The expression
in Eq. (3.10) counts x only in intersections containing only elements of B. The
expression counts x once with a positive sign for every non-empty subset of B
with an odd cardinality, and once with a negative for each non-empty subset of B
with an even cardinality. Adding up all those inclusions and exclusions doesn’t
give 0 as you might think from the alternating row sum of Pascal’s triangle,
since the empty set, an even subset, is excluded. So x is counted overall exactly
once.
Also, using De Morgan’s laws, you can discover an analogous formula which
rewrites the cardinality of an intersection of many sets as an alternating sum of
cardinalities of unions. The formula, which you will discover, will be true but
not very useful in solving practical problems, at least not useful enough to give
it a catchy name.

Exercises
1. How many strings of length 5 on {a, b, c, d, e} either start with a, end in a,
or have all the same letter?
2. How many strings of length 5 on {a, b, c, d, e} either start with three iden-
tical characters, end with three identical characters, or have c exactly in the
middle?
3. How many strings of length 25 on {a, b, c, d, e, . . . , z} either start with 5
identical characters, repeat every 5, (like acadcacadcacadcacadcacadc)
or are palindromic, that is, read the same forwards and backwards (like
aabbbbbbccacacaccbbbbbbaa)?

3.4 Multiple Cartesian products and strings


For the collection and organization of information, the binary Cartesian prod-
uct of sets is theoretically sufficient. For many applications, however, the bi-
nary form is inconvenient since the levels of nested parentheses may serve no
purpose, but still require careful attention. The multiple product is a valuable
alternative.

Definition 3.4. Let A1 , . . . AN be sets. The N -fold Cartesian product of those


sets is defined as

A1 × A2 × · · · × AN = {(a1 , a2 , a3 , . . . , an ) | ai ∈ Ai for all 1 ≤ i ≤ N }. ♠

So the elements of the product are N -tuples, or sequences of N elements


where the coordinates, or entries, are matched one by one to the set of which

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Working with finite sets Chapter | 3 57

they are a member. By the multiplicative principle, if all the sets are finite, then

|A1 × A2 × · · · × AN | = |A1 | · |A2 | · · · |AN |.

Example 3.5. Consider the product {Z × {+, −, ×, ÷} × Z × {=, ≤, <, ≥, >} ×


Z}. Elements of this set, like (1, +, 1, =, 2) model simple arithmetic statements,
and of course include as well such gems as (5, ×, 5, ≤, 0), but not (1, 1, +,
=, 2). ♦
It is still possible that the individual elements of a multiple Cartesian product
are themselves tuples. If you wanted to model paths joining 5 locations on an
8 × 8 grid, you might first set X = {1, 2, . . . 8} × {1, 2, . . . 8} to establish the
locations, and then use X × X × X × X × X = X 5 to model the paths, with
a typical element in the set being ((1, 1), (3, 4), (8, 7), (3, 4), (8, 6)). Note that
for this structure, the entries in the tuple are both ordered (left to right) and may
have multiplicities.
If there is no confusion, it is common in a multiple Cartesian product, as with
the bit vectors, to suppress the commas and the parentheses to give a cleaner
look. We would certainly do this with the elements in the arithmetic example,
writing 5 + 5 = 10 instead of (5, +, 5, =, 10), and even in the grid path example
one can imagine writing (1, 1)(3, 4)(4, 4)(3, 3)(8, 6) or even 1134443386 with-
out difficulty, but if it was a 16 × 16 grid, it would be difficult to know what to
do with 11111111111111.
An important special case is the N -fold Cartesian product of a set A with
itself, A × A × A · · · × A = AN . Please be warned that the exponent here is a
bit perilous, since (A5 )2 = (A2 )5 = A10 as sets, although by the multiplicative
principle their cardinalities satisfy |(A5 )2 | = |(A2 )5 | = |A|10 .
For a finite set, , an element of the product  N is termed a string of length
N on the alphabet , and the set of all strings on  is


∗ = k .
k=0

The use of the ∗ above is called the Kleene Star. Do not be misled by the ∞
symbol: k takes every integer value from 0 up to but not including ∞, so every
string in  ∗ belongs to one of the sets Ak , and therefore must have length k. That
is, every string has finite length. Another thing to notice, at the other end of the
union, is the case when k = 0.  0 is defined to be the empty string, commonly
denoted by  or λ or the empty tuple (). Strings, beyond their mathematical
applications, are a fundamental object of study in theoretical computer science,
modeling not only the typical input and output of computer programs, but the
programs themselves.
For a completely different application, while it is sufficient theoretically to
distribute two sets at a time, using A ∪ (B ∩ C) or A ∩ (B ∪ C), practically it
is much better to have a more general rule describing how to handle multiple

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


58 Discrete Mathematics With Logic

terms at once. Up until now, however, we have not had the notation to write the
rule down efficiently. The multiple Cartesian product is the last piece that we
need.
Theorem 3.6 (General Distributive Law for Sets). Let X1 , . . . Xn be non-empty
sets such that each element of each set is itself a set. Then the following hold;
⎡ ⎤ 
n   
n
⎣ X⎦ = Xi , (3.11)
i=1 X∈Xi (X1 ,...,Xn )∈X1 ×···Xn i=1
⎡ ⎤ 

n   
n
⎣ X⎦ = Xi . (3.12)
i=1 X∈Xi (X1 ,...,Xn )∈X1 ×···Xn i=1

This useful rule uses three different forms of notation for general union
and intersection. The easiest are the two on the left, where the multiple union
and intersections are indexed by either a set of consecutive natural numbers,
{1, 2, . . . , n}, or a more general set. On the right hand side the format of the
‘dummy variable’ is used to specify the required term.
Example 3.7. X1 = {A, B, C}, X2 = {D}, and X3 = {A, E}, the left side of
Eq. (3.11) gives
⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤
3    
⎣ X⎦ = ⎣ X⎦ ∪ ⎣ X⎦ ∪ ⎣ X⎦
i=1 X∈Xi X∈X1 X∈X2 X∈X3

= (A ∩ B ∩ C) ∪ D ∪ (A ∩ E).

Decoding the right hand side gives



 3 
Xi = (X1 ∪ X2 ∪ X3 )
(X1 ,X2 ,X3 )∈X1 ×X2 ×X3 i=1 (X1 ,X2 ,X3 )∈X1 ×X2 ×X3
= (A ∪ D ∪ A) ∩ (A ∪ D ∪ E) ∩ (B ∪ D ∪ A)
∩ (B ∪ D ∪ E) ∩ (C ∪ D ∪ A) ∩ (C ∪ D ∪ E),

exactly what is implied by algebra and the basic distributive law. ♦


As remarked, the general distributive law follows from the basic laws, and
the commutativity and associativity of the intersection and union. It also is fairly
straightforward to show it directly with the double inclusion method.

Exercises
1. Let A = {1, 2, 3}.
a. Find 5 elements in A5 × A × P(A).

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Working with finite sets Chapter | 3 59

b. What is the cardinality of A5 × A × P(A)?


2. Consider the set (({a, b, c}2 )2 )2 .
a. Find 5 elements of the set. Do not suppress any commas or parentheses.
b. What is the cardinality of the whole set?
3. Find 5 elements of {P , B, T , D} × {u, o} × {s, z}2 × {a, e} × {y, t} suppress-
ing all commas and parentheses. What is the cardinality of the whole set?

3.5 Lexicographical order


Lexicographic order on multiple products
Given two strings of the same length on A, we know how to order them alpha-
betically, by comparing the first letters. If the first two letters are different, the
string starting with the larger letter is larger. If the first two letters are the same,
then we compare the second letters, from left to right, comparing the second let-
ters and so on. Alphabetic order is also called dictionary order, or lexicographic
order. So “cat”, precedes “dog”, and “dog” precedes “dot”. The same method
extends to strings of fixed length, and multiple Cartesian products in general.
Given a collection of sets Ai , and an ordering on each set, it is possible
to extend those orderings lexicographically to the set A1 × A2 × · · · × AN .
Comparing two elements in this set lexicographically, (x1 , x2 , . . . , xN ) versus
(x1 , x2 , . . . , xN
 ), we define the lexicographic order on the elements, writing

(x1 , x2 , . . . , xN ) < (x1 , x2 , . . . , xN


 ), if there is a 1 ≤ k ≤ N with x = x  for
i i
all i < k and xk < xk . 

Under this definition, the order on the elements of a multiple product de-
pends only on the relative order of the first differing coordinate, just as do the
words in the dictionary.
So for example, set D × {−, +} × D × {≤, =, ≥} × D, which we used to
model first grade arithmetic, contains 6000 elements. If we take the usual order-
ing on D and the order in the listing for the other two sets, the first element
in lexicographic order is 0 − 0 ≤ 0, and the last one is 9 + 9 ≥ 9, both of
which happen to be true. For any choice of the first four coordinates, there are
10 choices of the final coordinate, ordered sequentially in lexicographic order,
say from 5 + 7 = 0 to 5 + 7 = 9, all of which are false, but that is not the is-
sue. Incrementing 5 + 7 = 9, we have 5 + 7 ≥ 0, and then the sequence of 10
restarts. Incrementing any element, say 5 + 7 ≥ 9, involves moving ahead in the
rightmost coordinate for which that is possible, 5 + 8__, and resetting all the
coordinates further to the right to the least element in the relevant set, 5 + 8 ≤ 0.
We see that the lexicographic list is organized in the same way that the list of
natural numbers in base 10 is organized, except that instead of the columns being
sequences of 10 identical characters in the 10’s place, and 102 identical charac-
ters in the 102 ’s place, etc., there will be 10 identical characters in the {≤, =, ≥}
place, 3 · 10 identical characters in the middle D place, 10 · 3 · 10 identical char-
acters in the middle {−, +} place, etc. And it is no surprise that the backwards
method of computing a number to a different base adapts easily to this situation.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


60 Discrete Mathematics With Logic

Theorem 3.8. Suppose we have a collection of N sets A0 , . . . AN −1 and an


ordering on each set, and a number m < |A0 | · · · |AN −1 |. Let {mi } and {ri }
be defined by setting m0 = m, and the divisions by |Ai | with remainder mi =
mi+1 |Ai | + ri . Then the m th element of AN −1 × · · · × A0 in lexicographic order
is aN −1 · · · a0 with each ai the ri th element of Ai , (ordering from the 0th).
On the other hand, given an element aN −1 aN2 · · · a1 a0 ∈ AN −1 × · · · × A0 ,
that element has position

rN −1 |AN −2 | · · · |A0 | + · · · + r3 |A2 ||A1 ||A0 | + r2 |A1 ||A0 | + r1 |A0 | + r0 ,

with each ai the ri th element of Ai , ordering from the 0th.


If we now want to determine the 1776th element along the list of 6000 ele-
ments of D × {−, +} × D × {≤, =, ≥} × D, we compute 1776 = 177 · 10 + 6,
then 177 = 59 · 3 + 0, then 59 = 5 · 10 + 9, then 5 = 2 · 2 + 1, and then fi-
nally 2 = 0 · 10 + 2. The remainders in reverse order of the computations,
(2, 1, 9, 0, 6), record the element required: 2 + 9 ≤ 6. It is important to be care-
ful in the final step if you are not yet used to ordering from 0; the 1st element
of {−, +} is +, since − is the 0th. Reversing the process we would find that
5 + 9 ≤ 6 is the 2 · 2 · 10 · 3 · 10 + 1 · 10 · 3 · 10 + 9 · 3 · 10 + 0 · 10 + 6th, which
you can check is 1776, as required.

Lexicographic order on  k
Lexicographic order on a multiple Cartesian product has a nice interpretation
in the case where all the sets in the product are the same, for example when
considering strings of length k and an alphabet . To find the mth string in  k ,
the divisions with remainder are all done with respect to the same number, ||.
In fact, we can observe that, in the special case of ordering strings of length
k from an alphabet , the problem is essentially the same as counting k-digit
numbers in base ||, (and one can even regard the ordered elements of  as the
digits!)
Theorem 3.9 (Lexicographically Ordering Strings). Let  = {a0 , a1 , . . . aN −1 }
be a set of cardinality N with ordering a0 < a1 < · · · < aN −1 on its elements.
Let m = dN −1 N k−1 + dN −2 N k−2 + · · · + d1 N 1 + d0 N 0 , with each dj sat-
isfying 0 ≤ di < N , be the representation of the number m as a k digit num-
ber in base N . Then the mth string in  k , regarding a0 a0 · a0 as the 0th, is
(adN−1 , adN−2 , . . . , ad0 ), or more compactly adN−1 adN−2 · · · ad1 ad0 .

Example
Let  = {a, b, c, d, e, f, g, h, i, j } be an alphabet of 10 letters, and the usual or-
dering. The 5280th string of  4 in lexicographic order is f cia, because 5280 is
already represented in base 10 and the entries of f cia are the 5th, 2nd, 8th,
and 0th characters of . The 5280th string of  8 in lexicographic order is
aaaaf cia.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Working with finite sets Chapter | 3 61

If we reduce the alphabet to   = {a, b, c, d, e, f } and want the 5280th string


of length 8, we have to first convert 5280 to base 6. By the backwards method
of Section 1.6 we just have to repeatedly divide by 6 and get 5280 = 402406 , or
5280 = 0 · 67 + 0 · 66 + 0 · 65 + 4 · 64 + 0 · 63 + 2 · 62 + 4 · 61 + 0 · 60 . That
yields the string aaaeacea. The formula of Theorem 3.9 works just as well for
the opposite problem, which is called delisting.
Given the string abccebef ∈  8 , what position does it have on the list
of strings in  8 in lexicographic order? If the string aaaaaaaa is the 0th,
abccebef is string 0 · 67 + 1 · 66 + 2 · 65 + 2 · 64 + 4 · 63 + 1 · 62 + 4 · 61 + 5 · 60 .

Varying the length


Decimal numbers, binary numbers, and ordinary words of varying length may
all be ordered lexicographically by adapting our mathematical lexicographical
order, yet the methods used are quite different. In comparing numbers of dif-
ferent digit length, the shorter number is padded on the left with zeros. So
69 and 5280 are compared just as 0069 and 5280, ignoring the fact that, ac-
cording to first non-zero digits, 6 > 5. Words not of the same length, however,
are compared lexicographically by padding the shorter word on the right with
blanks, with the blank regarded as less than any letter for purposes of indi-
vidual comparison. For example, blackie and blackbird are compared via
blackbird < blackie__, not __blackie < blackbird.

Exercises
1. Let B = {a, b}.
How many strings are between abbbb and baaaa in the lexicographic order
on all strings of length 5 on B?
2. Which number is the string γ αγ αββ in lexicographical order on the
strings of length 10 on {α, β, γ , δ, }?
3. Let A = {1, 2, 3} and B = {a, b}. Taking the usual ordering on the elements
of both sets, what is the 88th element of A × B × A × B × A × B × A in
lexicographic order?

3.6 Ordering permutations


Subsets of multiple Cartesian products
We have seen how we can list and delist the elements of a multiple Carte-
sian product of finite sets. In particular, we have a close relationship be-
tween the lexicographic ordering on the strings of length k on an alphabet ,
and the k-digit numbers written in base ||. What about subsets of a multi-
ple Cartesian product? Can we solve the listing and delisting problem when
the elements are restricted? For example, for the multiple Cartesian product
D × {−, +} × D × {≤, =, ≥} × D whose elements model simple digit arith-

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


62 Discrete Mathematics With Logic

metic problems, what if we want to restrict to those elements for which the
mathematical expression is true?

T = {x ∈ D × {−, +} × D × {≤, =, ≥} × D | x is true}

So 9 + 1 > 0 ∈ T , but 2 + 2 = 5 ∈ / T . So we could ask, how many elements of


T are ahead of 9 + 1 > 0 in lexicographic order? Or we could ask which digit
fact is 1776th in the ordering? Both questions look very difficult, in fact, it looks
difficult to determine if there even are 1776 elements in T . In general, in order
to get a complete answer for a subset of a multiple Cartesian product, that subset
would have to be quite regularly constructed.

Permutations
The set of permutations of the six characters in  = {a, b, c, d, e, f } can be
regarded as a subset of  6 , specifically the subset

P () = {σ1 σ2 σ3 σ4 σ5 σ6 ∈  6 | σi = σj for all i = j }.

If P () is ordered lexicographically, the 0th element is abcdef , followed


by abcdf e, etc., until the (6! − 1)th element f edcba.
abcdef abdcef abecdf abfcde acbdef acdbef acebdf fedabc
abcdfe abdcfe abecfd abfced acbdfe acdbfe acebfd fedacb
abcedf abdecf abedcf abfdce acbedf acdebf acedbf ... fedbac
abcefd abdefe abedfc abfdec acbefd acdefb acedfb fedbca
abcfde abdfce abefcd abfecd acbfde acdfbe acefbd fedcab
abcfed abdfec abefdc abfedc acbfed acdfeb acefdb fedcba

You may take a general element of P (), say df beca, and ask what follows it
in P () in lexicographic order. You cannot increment just the final a, because
it is forced by the first part of the string. You cannot increment the c next to it
because, fixing the characters to the left, it is already the highest value among
a and c. You cannot increment the e next door for the same reason. It is the b
which may be incremented, holding the initial df fixed, to c. So the next permu-
tation after df beca in lexicographic order is df cade, taking the leftover letters
{a, d, e} in order. (After that come df caed, df cdae, df cdea, . . . ). Observing
the list above we see the pattern that, reading from right to left, the rightmost
coordinate has no freedom at all, its neighbor to the left has two alternatives
it must cycle through, and its neighbor to the left has three alternatives it must
cycle through in pairs, so its neighbor to the left must cycle through its four
possibilities in groups of 2 · 3 = 3!, etc.
How many permutations are ahead of a general permutation σ1 σ2 σ3 σ4 σ5 σ6 ?
We ask first how many permutations were on the list before σ1 appeared in
the first position? Each element of {σ2 , σ3 , σ4 , σ5 , σ6 } which is smaller than σ1
occupied the first position ahead of σ1 , and for each one, there were (6 − 1)! per-
mutations. So if we set r1 to be the number of elements in {σ2 , σ3 , σ4 , σ5 , σ6 } less

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Working with finite sets Chapter | 3 63

than σ1 , there were r1 (6 − 1)! permutations before σ1 appeared in first position.


After that, how many permutations were there before σ2 appeared in the second
spot? With σ1 fixed in the front, each element of {σ3 , σ4 , σ5 , σ6 } which is less
than σ2 had to occupy second position first, and for each one there were (6 − 2)!
permutations. So, setting, r2 to be the number of element of {σ3 , σ4 , σ5 , σ6 }
which are less than σ2 , we have r2 (6 − 2)! additional permutation ahead of
σ1 σ2 σ3 σ4 σ5 σ6 . The argument continues in this manner, computing r3 , r4 , r5 .
The final result is r1 (6 − 1)! + r2 (6 − 2)! + r3 (6 − 1)! + r4 (6 − 4)! + r5 (6 − 5)!.
Here is the general result, however, it will look nicer, and help us later, if the
permutation is indexed in the other direction, starting from 0.

Theorem 3.10. Let  be a finite ordered set of N elements, and let σN −1 · · · σ1 σ0


∈ P () ⊆  N be a permutation of . Set ri to be the number of elements in
{σ0 , . . . , σi−1 } which are less than σi in the ordering on . Then the number of
permutations in P () which are less than σN −1 · · · σ0 ∈ P () ⊆  N in lexico-
graphic order is

rN −1 · (N − 1)! + rN −2 · (N − 2)! + · · · + r1 · 1! + r0 · 0!.

Notice that if we compute the number of elements ahead of σN −1 · · · σ1 σ0 ∈


P () ⊆  N to be k, then σN −1 · · · σ1 σ0 ∈ P () ⊆  N is the kth permutation
on a lexicographically ordered list of the elements of P () since natural order
is our 0th permutation (just as the day you are born is your 0th birthday and on
your 20th birthday you have previously lived 20 years).

Example 3.11. How many permutations of {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} are ahead


of 5824971063?

There are 5 numbers ahead of 5, r9 = 5; and there are 7 numbers ahead of 8
excluding 5, r8 = 7; and there are 2 numbers ahead of 2 excluding 5 and 8,
r7 = 2; and continuing r6 = 3, r5 = 5, r4 = 3, r3 = 1, r2 = 0, r1 = 1, and of
course r0 = 0. Altogether, the number of permutations is

5 · 9! + 7 · 8! + 2 · 7! + 3 · 6! + 5 · 5! + 3 · 4! + 1 · 3! + 0 · 2! + 1 · 1! + 0 · 0!

Exercises
1. List all 24 permutations of {a, b, c, d} in lexicographical order.
2. How many numbers with 10 distinct decimal digits are less than 8,214,
596,073? (The smallest such number is 0,123,456,789.)
3. Starting with 8,214,596,073, what are the next 12 numbers with distinct dig-
its in order?

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


64 Discrete Mathematics With Logic

3.7 Delisting permutations†


We have seen that, if a finite set , || = N has an ordering, then the N ! per-
mutations of that set may be regarded as a subset of  N =  || and sorted
in lexicographic order. We also saw in Theorem 3.9 how, given a permutation,
one can determine quickly its place on the lexicographic list without running
through the whole list.
In this section we want to show how to reverse the process, to see how to
find for any number 0 ≤ m < N ! the mth permutation on the lexicographic list.
This is done in a two stage process. First, we discover how, given m, to find
the numbers r0 , r1 , . . . of Theorem 3.9, and then, given those numbers, how to
assemble the permutation.
We will use the same type of backwards procedure we used for multiple
Cartesian products. Remember, lexicographic order is biased to the left of the
string, and our natural bias is to consider the terms in the string from left to
right, but it is preferable to index from right to left, σN −1 · · · σ1 σ0 just as is done
with decimal numbers. For the final term in the permutation, since it is forced
by the ones before, r0 is always 0. The work starts with r1 . Given what is to
its left, the 1st term from the right has two alternatives, with the permutations
in even positions on the lexicographical list taking the smaller alternative, and
those in odd position taking the larger. So if we use division with remainder,
setting m = m1 , the division by 2 yields r1 via m1 = 2 · m2 + r1 . Moving on to
the left, the next term has three alternatives, these appear in pairs going down on
the list, smallest to largest, so again division with remainder m2 = 3 · m3 + r2
gives us m3 and r2 . We continue in this fashion generating r3 , . . . rN −1 .
To make the general description smoother, we can set m0 = m = m1 make
an initial division by 1, with remainder r0 = 0. So we are following exactly the
procedure for multiple Cartesian products in the situations where the cardinal-
ities of the sets decrease steadily from N to 1. As a side benefit, we get the
interesting formula for m in terms of the remainders ri :

m = rN −1 · (N − 1)! + rN −2 · (N − 2)! + · · · + r2 · 2! + r1 · 1! + r0 · 0!

Here is the general description.


Theorem 3.12. For the mth permutation of  in lexicographic order, in order
to find the numbers ri of Theorem 3.9, set m0 = m, and perform || divisions
with remainder, mi = (i + 1) · mi+1 + ri .
Example 3.13. To find the 1776th permutation of {a, b, c, d, e, f, g, h, i, j }, we
do
1776 = 1 * 1776 + 0 14 = 6 * 2 + 2
1776 = 2 * 888 + 0 2 = 7 * 0 + 2
888 = 3 * 296 + 0 0 = 8 * 0 + 0
296 = 4 * 74 + 0 0 = 9 * 0 + 0
74 = 5 * 14 + 4 0 = 10 * 0 + 0

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Working with finite sets Chapter | 3 65

in ten divisions. This shows that the only remainders which are non-zero are
r4 = 4 and r5 = r6 = 2, and we may check that, indeed, 1776 = 2 · 6! + 2 · 5! +
4 · 4!.
To complete the process, we have to find, given r0 , r1 , . . . , the desired per-
mutation σN −1 σN −2 · · · σ1 σ0 . So far we have been working backwards, from
right to left, but this will no longer help us. The fact that r0 = 0 only tells us that
σ0 is forced by the coordinates to the left. We need to find those first, and so we
better work now from left to right.
For the N − 1th position, take the rN −1 th element from the N elements in
. For the N − 2th position, take the rN −2 th element from the N − 1 elements
remaining, and at each stage both fill the coordinate position, and remove that
value from the next and all subsequent choices. ♦
Example 3.14. Continuing with our example, we have r9 = r8 = r7 = 0, so we
start the permutation with abc, very much at the front of our dictionary, which
is to be expected since it has 10! = 3, 628, 800 entries, and we are only looking
for the 1776th. The entries remaining are {d, e, f, g, h, i, j }, and r6 = 2, and the
2nd from the left, ordering from the 0th, is f , so abcf . Next we want the 2nd
from {d, e, g, h, i, j }, which is g, and form abcf g. Next we want the 4th from
{d, e, h, i, j } which is j , and so form abcf gj . All the remaining r’s are 0, we
put in the remaining {d, e, h, i} in order, and form at last abcf gj dehi. ♦
The general description we are leaving as an exercise. A hint is, in the pre-
vious general description, it was done by introducing the sequences of numbers
ri and mi , here one of the sequences of objects to be introduced are strings, and
the other are sets. To get you started, here is another example whose answer can
be checked from the list begun in Section 3.6.
Example 3.15. What is the 32nd permutation of {a, b, c, d, e, f }? We begin by
finding the sequence of remainders:
32 = 1 * 32 + 0 5 = 4 * 1 + 1
32 = 2 * 16 + 0 1 = 5 * 0 + 1
15 = 3 * 5 + 1 0 = 6 * 0 + 0

and check that 32 = 1 · 4! + 1 · 3! + 1 · 2!. Since r5 = 0, the permutation starts a.


For the next three letters, since r2 = r3 = r4 , we skip b, and form acde, with the
last two letters {b, f } appearing in order, acdebf . If you look on the list, you
will find it in the correct spot, remembering that abcdef is the 0th. ♦

Exercises
1. Compute with the backwards method the 0th, 10th, and 20th permutations
of {α, β, γ , δ} in lexicographical order.
Verify your results by listing them.
2. What is the 720th permutation of {a, b, c, d, e, f, g} in lexicographical order,
counting from 0?

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


66 Discrete Mathematics With Logic

3. What is the 666th natural number, counting from 0, in order of increasing


size, that has 10 distinct decimal digits?
(The smallest is 0,123,456,789.)

3.8 Case study: Wolf-Goat-Cabbage


In Chapter 1 we considered the classic Wolf-Goat-Cabbage problem.
Can a man cross a river with three items, a wolf, a goat, and a basket of
cabbages, in a boat which is just large enough for him to take at most one item
of cargo at a time, keeping in mind that, if left unguarded, the wolf will kill the
goat, and the goat will eat the cabbage.
It was introduced as an example of a discrete problem which could be studied
mathematically if one cared to analyze it carefully, instead of just playing idly
with it. Our example was to use the multiplicative principle to count the number
of relevant puzzle positions, the number of states by considering the yes/no
questions which asked whether each of the man, wolf, goat and cabbage was on
the near side of the river or not, and concluded that the number of relevant states
was at most 24 = 16.
Later, when sets were introduced, we could have noticed that these yes/no
questions were essentially bit vectors, and that the states could be naturally iden-
tified with one of the 24 subsets of {Man, Wolf, Goat, Cabbage}, in other words,
the states could be regarded as elements of P({Man, Wolf, Goat, Cabbage}). In
this encoding, the initial puzzle position is {Man, Wolf, Goat, Cabbage} and the
happy ending is ∅.
We can also use strings to study solutions and even possible solutions and
partial solutions. The alphabet will be the set  = {∅, w, g, c}, which we will
regard as a single action of the Viking crossing the fjord with the indicated
article w, g or c, or all alone for ∅. Then any sequence of actions, any attempt
of the Viking to solve the puzzle, can be regarded as an element of  ∗ . So a
string starting g∅c . . ., would be interpreted to mean that the Viking first crosses
with the goat, then returns with the goat left alone on the far side, and then
crosses with the cabbages to the other side. A string starting w∅c∅ . . . would be
interpreted as the Viking crossing the fjord with the wolf and returning for the
cabbage, but this string cannot be the initial segment of any solution because,
according the rule, the cabbage would no longer be there.
There are other issues one encounters in applying these action strings to
the problem. A string starting g∅g . . . is impossible to interpret even though no
mayhem has been committed because, when the man returns to the near shore,
there is no goat to cross with.
You might object that  ∗ is unnecessarily huge, and that  16 is certainly
sufficient by the bound on the number of states. It depends on what you want to
study. That sounds persuasive if you want to find the shortest possible solution.
But other people might want to allow for the puzzling Viking to start his solution
ggggggg . . .

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Working with finite sets Chapter | 3 67

We will return to the case study for more analysis, but most readers I think
will have a solution in  7 before then.

3.9 Case study: The Gray code


We found in the bit vectors BN a very convenient encoding of the subsets of a
set of cardinality N , and the encoding of those bit vectors as binary numbers
gave us a familiar ordering on those subsets. But that ordering is not necessarily
the most convenient. Suppose you have 15 billiard balls, and you just wanted to
photograph each subset of balls, putting each subset in turn in a box on which
your camera is focused. You first photograph the empty box, click, then the 1
ball alone in the box, click, swap the 1 and 2 balls, click, put the 1 ball back,
click, empty the box and put in the 3 ball, click, etc. Of course, there are 215
subsets, so it will take you a long time, but before every power of two, you must
empty the box of all the balls you have been using so far to include just the new
ball all alone. Perhaps there is a better way.
Here is a similar problem. You have a line of 15 switches on the wall, and
want to pass through all possible combinations of those switches being on and
off. If you use the binary number order on the bit vectors of those switches, you
will quite often have to flip many switches at the same time. Can you cut that
down? Can you arrange the bit vectors so that, in fact, you never have to flip
more than one switch at a time?
The answer is yes. There are several ways and all the methods are based
on the following trick. If you have a method for k switches, you can extend it
to k + 1 switches by using your method on the first k switches, then flipping
just the k + 1 switch, and then reversing your method with the first k switches,
leaving the k + 1st switch on. Since half the positions have the k + 1st switch
on, and half have it off, all possible positions with k + 1 switches are covered.
Let’s try this, starting with four switches, moving from bottom to top, with
initial position 1011. The second version is identical to the first, except that the
switch to be flipped is indicated with an x.

1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 x 0
0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 x x 0
1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 x x x x 1
1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1x x x x x x x x1

If now we noticed that there was a fifth switch above these, say, 01011, we
could extend by flipping that now, and reverse the flips of the other four:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0x1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1x0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0x1 1 1 1 1 1 1 1
0 0 0 0x1 1 1 1 1 1 1 1x0 0 0 0 0 0 0 0x1 1 1 1 1 1 1 1x0 0 0 0
1 1x0 0 0 0x1 1 1 1x0 0 0 0x1 1 1 1x0 0 0 0x1 1 1 1x0 0 0 0x1 1
1x0 0x1 1x0 0x1 1x0 0x1 1x0 0x1 1x0 0x1 1x0 0x1 1x0 0x1 1x0 0x1

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


68 Discrete Mathematics With Logic

If we follow this procedure starting with 00000, the resulting sequence of bit
vectors is called the Gray code, and for five bits it is

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0x1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0x1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1x0 0 0 0 0 0 0 0
0 0 0 0x1 1 1 1 1 1 1 1x0 0 0 0 0 0 0 0x1 1 1 1 1 1 1 1x0 0 0 0
0 0x1 1 1 1x0 0 0 0x1 1 1 1x0 0 0 0x1 1 1 1x0 0 0 0x1 1 1 1x0 0
0x1 1x0 0x1 1x0 0x1 1x0 0x1 1x0 0x1 1x0 0x1 1x0 0x1 1x0 0x1 1x0

We would like to figure out what the kth configuration of switches in


the Gray code is. Let the number k be represented by bits in binary as
bN −1 bN −2 . . . b1 b0 , and we would like to determine the Gray encoding gN −1
gN −2 . . . g1 g0 .
A backwards method applies here, and we consider determine first the 0th
Gray bit. Notice the 0th bit repeats in pairs in binary, but repeats in groups of
four in the Gray code. They don’t match exactly. But the last two bits in binary
repeat every four, in the order 00, 01, 10, 11, which is sufficient to determine the
0th bit of the Gray code, 00 and 11 giving 0, and 10 and 01 giving 1. A more
compact description is

0 if b0 = b1
g0 =
1 if b0 = b1
But the same consideration holds between g1 and the next pair of binary bits,
b1 and b2 . The pattern takes twice as long to repeat for both, but only because it
develops in identical pairs, so it is still true that

0 if b1 = b2
g1 =
1 if b1 = b2

with the general encoding given by



0 if bk = bk+1
gk =
1 if bk = bk+1

So, for example, if you want the 13th element of the Gray code, you first
express 13 in binary 13 = 11012 , then, moving from right to left, record all the
places where 0 switches to 1 and vice versa in 01101, so 01011.
Decoding from a Gray string back to a binary string will have to wait.

3.10 Case study: The forgetful waitress problem


The problem concerns a waitress in a restaurant, and a dozen customers at one
of her tables. A good waitress, one who wants a big tip, will get to know her
customers and try to, when she returns with the customers’ meals, distribute the

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Working with finite sets Chapter | 3 69

orders to the proper customer without asking who ordered what. Our forget-
ful waitress is very busy and has other things on her mind. Everybody ordered
something different and she has forgotten completely who ordered what, but
still she doesn’t want to ask, so she distributes the orders randomly, hoping
that she will guess correctly. Her probability of success is an easy exercise in
the multiplicative principle. The Forgetful Waitress Problem, however, asks the
probability that nobody gets the correct order.

The number of ways to distribute the orders is 12!, the number of permuta-
tions, so we need only compute the number permutations of, say, abcdef ghiklm
such that no letter is in its correct alphabetical position.
A permutation of this type is called a derangement. So we are asking what
fraction of permutations of 12 elements are derangements.
That problem also looks like an easy problem for the multiplicative principle,
but a naive left to right approach won’t work. There are 11 choices for the first
position, true. But then the number of choices for second position depends. If
you picked b for first position, a legal choice, then any of the remaining eleven
letters can be placed in second position. If, on the other hand, you picked c, then
there would be only 10 choices for second position, since both b and c would be
forbidden. You can split into two cases, but then it gets even worse further on.
A clever trick is to, first of all, count the complement – the number of per-
mutations for which at least someone gets the correct order, and secondly, to
count that with inclusion/exclusion. This is a bit more difficult than our exercise
problems, but follows the same pattern. First we have to define our sets. Let Pi
be the number of permutations of abcdef ghiklm such that the ith letter is fixed.
So P0 if the set of those permutations which start with a and P11 is the set of
those which end in m. We want to count |P0 ∪ P1 ∪ · · · P10 ∪ P11 |.
With 12 sets, inclusion/exclusion will involve us with 212 − 1 = 4, 095 cardi-
nality of intersection problems, but don’t panic! First |Pi | = (12 − 1)!, since one
letter is fixed and the rest are permuted. There are 12 such sets, so the first posi-
tive terms in the inclusion/exclusion formula give us, altogether, 12 · (12 − 1)!.
For the pairwise intersection |Pi ∩ Pj | = (12 − 2)! since 2 elements are fixed,
 
and the rest are permuted. There are 12 2 terms like this, and they are all sub-
12
tracted so − 2 (12 − 2)! altogether are excluded.
  case for an intersection of k, we have (12 − k)!
Skipping ahead to the general
permutations, and there are 12 k such terms, and they are subtracted if k is even,
12
k (12 − k)!. You were right not to panic, by
and added if k is odd, i.e. (−1) k−1

gathering all thelike terms together, we only have 11 terms, and not 4,095. For
k = 6, since 12 6 = 924 we were able to handle almost one thousand of those
4095 sets all at once!
 clean up the first one, which was 12 · (12 − 1)! and rewrite it as
Let’s
(−1)0 12 1 (12 − 1)!, so that it fits the pattern. Now we add:

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


70 Discrete Mathematics With Logic


12  
k−1 12
(−1) (12 − k)!
k
k=1

Before you program that in, recall that these are the permutations we do not
want, the ones where somebody does get the
 correct order. We have to subtract
these from 12!, which we will write as 120 (12 − 0)! to make it fit the pattern.
With that, the number of derangements is


12  
12
(−1)k (12 − k)!
k
k=0

(Note that the sum now goes from 0.)


Now, for the probability that nobody gets the ordered meal, we divide by 12!
and we get

    
12 (12 − k)!  (12 − k)! 
12 12 12
12! 1
(−1)k = (−1)k = (−1)k
k 12! k!(12 − k)! 12! k!
k=0 k=0 k=0

Now you can program it in.


But if you have taken Calculus, you might not want to, since there it is shown
that

 1
e =
x
xk ,
k!
k=0

so the number we will get for the finite sum is very close to e−1 = 1e , a little
more than 1/3 of the time. Moreover, the more people at the table, the closer
the probability that nobody receives what they ordered gets to 1/e. Except that
it doesn’t, unless you have a science fiction restaurant where billions of people
can order billions of different things.
But mathematically, we can still say that the fraction of permutations which
are derangements approaches 1/e as the number of objects permuted approaches
infinity.

3.11 Summary exercises


You should have learned about:
• Basic facts about cardinalities of finite sets
• How to order all the subsets of a given set using bit vectors
• The inclusion/exclusion principle and its applications
• The Cartesian product of any number of sets and the general distributive law
for sets
• How to list and delist permutations

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Working with finite sets Chapter | 3 71

1. Let A = {1, 2, 3, 4}, B = {a, b, c, d, e}.


a) Compute |P(P2 (A × (B × A))|.
b) Compute |P3 (A ∩ B)|.
|A∪B|
c) Compute k=0 (−1)k |Pk (A ∪ B)|.
2. You have a problem that you want to solve by inclusion/exclusion. You
define 8 sets, A1 , . . . A8 . What is the set whose cardinality is your ultimate
objective to find? How many sets do you have to count to achieve your goal
via inclusion/exclusion?
3. What is the 48th subset of D in bit vector order, taking the usual ordering
on the digits. (∅ is the 0th subset, and {0} is the 1st.)
4. Let A = {a, b, c, d, e, f, g}.
a) Taking ∅ as the 0th subset of A and {a} as the 1st, what the 101st subset
of A in bit vector order.
b) Compute |A ∪ P2 (A)|.
5. Consider the set of numbers A = {1, 2, . . . , 100}. How many numbers in A
are either even, evenly divisible by 5, or evenly divisible by 7?
6. How many 8 letter words on A either start with three vowels (a, e, i, o, u)
or end with two vowels?
7. How many strings in A12 are either three repetitions of strings of 4, such as
af czaf czaf cz, or four repetitions of strings of 3, such as gj igj igj igj i?
8. How many strings in A12 are either 2 repetitions of strings of 6, such as
pwertypwerty, or three repetitions of strings of 4, such as grokgrokgrok?
9. How many strings in A30 are either 2 repetitions of strings of 15, 3 repeti-
tions of strings of 10, or 5 repetitions of strings of 6?
10. Consider the strings of length 5 on {a, b, c, d}. What are the 10 strings
following abbbb in lexicographical order?
11. What is the 1888th element of the set ({α, β, γ , δ, })10 in lexicographic
order, taking the Greek letters in alpha-beta-ical order. (The order above.)
12. In considering the permutations of D in lexicographic order, with 01234567
89 the 0th, which permutation is 9! + 8! + 7! + 6! + 5! + 4! + 3! + 2! + 1!?
Which permutation is 9! + 8! + 7! + 6! + 5! + 4! + 3! + 2! + 1! + 0!?

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


This page intentionally left blank

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Chapter 4

Formal logic
4.1 Statements and truth value
The study of logic begins well into the text because, at least in some sense,
we are all familiar with its informal application. Logic is the use of careful
reasoning applied to statements. Considering statements in terms of grammar,
you might conclude that statements are very common, with any sentence being
classified as either a question or a statement. But most non-questions are not
statements in the sense of logic. For logic, a statement is either true or false.
Sherlock Holmes applies logic to solve crimes. He reasons that Sir Albert is
the only man on the island who is left-handed, has knowledge of firearms, and
knew where the rubies were hidden, and therefore, Sir Albert is the murderer.
But Sherlock Holmes has a huge advantage over the police; not because he
is well-educated and incredibly smart; but because he is a fictional character.
Holmes inhabits a world of rigid facts created by an author. In the real world,
there are right-handed people who sometimes use their left hand, there are war
veterans who can’t or won’t use firearms, and there are men who look right at a
heap of rubies hidden in a drawer but just don’t notice them.
In the real world, treating facts as “facts” is a dangerous game which can
let you build a structure as fragile as a house of cards. In detective fiction, the
pleasure is often in the description of a long sequence of logical card houses
built by minor characters and then blown down by new “clues”, until the final
structure is constructed by the protagonist. And that final one is only not blown
away because the book is over.
The simplest assertion in natural language can have hidden problems which
make it problematical. “Puerto Rico is a state” – True or False? What are we
to say? It is not one of the fifty states of the United States, but it is a state
in the sense of being a governmental unit. Right away we have two different
reasonable interpretations. The problem is not that it is questionable whether
the sentence is true or not. The problem is that it is not clear what is meant.
Without context, it is not a logical statement at all.
It is much easier to find statements on which to apply logic in mathematics,
games, or the law – areas where we humans make the rules and control the
language which is used to express them.
• In chess, the bishop moves diagonally. (TRUE)
• π
√ > 3. (TRUE)
• 2 is rational. (FALSE)

Discrete Mathematics With Logic. [Link] 73


Copyright © 2024 Elsevier Inc. All rights reserved.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


74 Discrete Mathematics With Logic

• <listy>, </listy> are list item delimiters in HTML. (FALSE)


The third statement was concluded over two millennia ago, but the logical struc-
ture establishing it still stands because the foundational statements are firm.
In formal logic we study how logical statements interact. The statements,
also called propositions, are indicated by variables, p, q, r, . . . , and each has a
truth value of TRUE, or FALSE.
It often helps to think of our logical variables as being replaced by a simple
statement in natural language, e.g., r: “It is raining”, p: “Paul is smart”, but
beware of slippery language and ambiguity.
More recently logic was given a more mathematical look by associating the
truth values TRUE and FALSE with the bits 1 and 0 respectively, writing p = 0
instead of p is FALSE. In this formulation, p is called a Boolean variable, and
0 and 1 are called Boolean values.
One advantage of the Boolean formation is that it places TRUE and FALSE
more on an equal footing. It is natural for us to love truth, and hate falsehood –
to collect and cherish true statements and discard and scorn false ones. But that
is not the point of view in logic. In logic, false statements are just as valuable as
true ones. You can reason equally well from the knowledge that “7 is prime” is
true, as from knowing that “6 is prime” is false.

Exercises
1. For each of the following, argue whether or not it qualifies as a statement in
the sense of logic.
a) Gas burns. b) Canada is a peaceful nation.
c) You can get anything you want at Alice’s restaurant.
2. For each of the following, argue whether or not it qualifies as a statement in
the sense of logic.
a) The derivative of x 5 is 5x 4 . b) Every rational number is a real number.
100
c) π (2 )  is prime.
3. Suppose that p, q, and r are statements. The expression “p and q or r” is
ambiguous. Explain why.
It may help if you let p stand for “Eddie has a penny”, q stand for “Eddie
has a quarter”, and r stand for “Eddie has a ruby”.

4.2 Logical operations


The statements of formal logic, the Boolean variables taking values 0 and 1, are
not just considered in isolation. There are many logical operators connecting
them, the most important being AND, OR, and NOT, symbolically ∧, ∨, and ¬.

Definition 4.1. Let p and q be statements, that is, Boolean variables.


The statement “p AND q”, equivalently p ∧ q, asserts that both p and q are
TRUE, i.e., have Boolean value 1.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Formal logic Chapter | 4 75

The statement “p OR q”, equivalently p ∨ q, asserts that either p or q is


TRUE, i.e., has Boolean value 1.
The statement “NOT p, equivalently ¬p, asserts that p is false, i.e., has
Boolean value 0. ♠
In the definition of OR, it must be emphasized that we are using “or” inclu-
sively, the default in this book, so the OR statement asserts that one, or the other,
or both are TRUE.
With these operators, we can now form Boolean expressions, like (p ∧ q) ∨
(¬p ∧ q ∧ ¬r), creating an algebra of logical propositions, or a Boolean algebra.
It is useful to compare this Boolean algebra to the algebra you learned in high
school for real numbers.

Real Algebra Boolean Algebra


Values 0, −2/3, π , etc. 0, 1
Variables x, y, z, . . . p, q, r, . . .
Operations +, ×, − ∧, ∨, ¬
Expression r ×t =d r ∧ (h ∨ u)
Natural World Rate × Time = Distance It is raining and I need a hat or an um-
brella

Basic Boolean identities


Here are some basic identities which govern Boolean algebra and connect the
operators.

¬(¬p) = p double negation


p ∨ ¬p = 1 p ∧ ¬p = 0
p∨0=p p∨1=1 unit laws
p∧0=0 p∧1=p
p∧p=p∨p=p idempotence (4.1)
p ∧ q = q ∧ p; p ∧ q = q ∧ p commutativity
p ∧ (q ∧ r) = (p ∧ q) ∧ r p ∨ (q ∨ r) = (p ∨ q) ∨ r associativity
p ∧ (q ∨ r) = (p ∧ q) ∨ (p ∧ r) Distributive law
p ∨ (q ∧ r) = (p ∨ q) ∧ (p ∨ r) Distributive law
¬(p ∨ q) = ¬p ∧ ¬q De Morgan’s law
¬(p ∧ q) = ¬p ∨ ¬q De Morgan’s law

In particular, just as with ∩ and ∪, each operator distributes over the other,
making them more on an equal footing than + and ×. In terms of order of
operations, the negation ¬ gets the highest preference, just as −, so ¬p ∨ r is
read as (¬p) ∨ r, not ¬(p ∨ r). For the binary operators ∧ and ∨, however, we

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


76 Discrete Mathematics With Logic

will make no preference, so p ∨ q ∧ r is regarded as an ill-formed expression,


since (p ∨ q) ∧ r and p ∨ (q ∧ r) are not equal.
Just as in numerical algebra, one encounters problems where one searches
for values of variables which make an expression true. Unlike real algebra, in
Boolean algebra there are only two possible values per variable, so for N vari-
ables, it is possible to simply check all 2N possibilities. For small examples this
may be organized in a “truth table”, but this is tedious and impractical in general.
Example 4.2. Find a truth assignment which makes each of the following
Boolean expressions true.

(p ∧ ¬q ∧ r) ∨ (q ∧ p ∧ ¬r) ∨ (¬p ∧ ¬q)


(p ∨ ¬q ∨ r) ∧ (q ∨ p ∨ ¬r) ∧ (¬p ∨ ¬q)


First we should notice that the upper one is much easier to parse. Each term,
or clause, is connected by an OR, so each clause may be examined separately.
Since p = r = 1 and q = 0 makes the first clause TRUE, that assignment makes
the whole expression TRUE.
For the second one, all three clauses must be TRUE so none can be ignored.
Each clause is an OR statement, so can be satisfied in different ways. But we do
not have to resort to checking all possibilities. Instead we look for commonal-
ities and notice that p is an alternative for the first two terms, so taking p = 1
makes both of those terms TRUE, and leaves freedom in assigning q for the
third term. Assigning p = 1 and q = 0 works independently of the truth value
of r. ♦

Exercises
1. Suppose p and q are TRUE and r is false. Determine the truth value of each
of the following:
a) (p ∨ ¬q) ∧ (¬q ∨ r) b) (p ∧ ¬q) ∨ (¬q ∧ r)
2. Suppose p = 0, q = 0, r = 1, and s = 0. Find the Boolean value of each of
the following:
a) (p ∧ ¬s) ∨ (¬q ∧ r) b) (p ∨ ¬s) ∧ (¬q ∨ r)
3. Find Boolean values of each of p, q, r and s so that

(p ∨ ¬q) ∧ (q ∨ ¬r) ∧ (r ∨ ¬s) ∧ (s ∨ ¬p)

is true. Can you find a second assignment that works?

4.3 Implications
The logical operations that form the building blocks of Boolean algebra are ∨,
∧, and ¬. There are several other minor operations which we will not concern

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Formal logic Chapter | 4 77

ourselves with. But there is one other operation which we must learn: the im-
plication. It is the fundamental underpinning of logic as it is used in arguments
and reasoning, and it must be carefully studied to avoid common mistakes. Its
definition in logic often comes as a surprise.
Definition 4.3. The implication, symbolically ⇒, is a binary logical operation.
The statement p ⇒ q asserts that q is true or p is false:

(p ⇒ q) = (q ∨ ¬p). ♠

In the expression p ⇒ q, p is referred to as the antecedent, or the hypothesis,


and q is termed the consequence or the conclusion. So the definition of the
implication above can be stated:

The consequence is true, or the antecedent is false.

In text, the implication p ⇒ q can be variously expressed as, “p implies q”, “if
p then q”, or “q is a consequence of p”.
Beware that implications, are often not used the same way in logic as in
natural language, so there are many pitfalls in understanding their meaning. In
particular
• No Temporality: Unless time is part of the statement, the conclusion is not
thought of becoming true after the antecedent is true, as is meant by saying
“If you will just read this book then you will be rich.”
• No Causality: In logic, the implication does not require that the truth of the
antecedent causes the truth of the consequence. The connection is in truth
value alone. In natural language, if you say “If you don’t pay your taxes
then you go to jail”, the jail term is understood to be a consequence of tax
avoidance.
Temporality is usually not a confusion in mathematical statements, but
causality definitely is a common source of error.

(π > 3) ⇒ (3 is prime)

is a perfectly valid implication, since the consequence is true, but one is tempted
to reject it as false because there is no obvious causal link.
This is even more pronounced in the equally valid

(27 is prime) ⇒ (3 is prime)

which logic requires us to accept before we even read the consequence, since
the hypothesis is false; and the frankly disturbing

(27 is prime) ⇒ (1 + 1 = 7)

which is valid for the same reason.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


78 Discrete Mathematics With Logic

Since the implication is an OR statement, it can be satisfied in many ways.


The only way an implication can be false is if the hypothesis is true, and the
consequence is false. This oddity in definition and meaning is not the result
of the implication being flawed or old fashioned, it is source of its power. To
understand that, it is necessary to distinguish how the implication is established,
and how it is then used.

How to establish the implication p ⇒ q


First assume p to be true, then show, under that assumption, that q is true.
In showing the consequence, you may use the assumed truth of the an-
tecedent, but you need not. Also, you are free to use anything else not specified
in the implication, as long as it is true. After the consequence is concluded and
the implication is established, the assumption that p be true is withdrawn, as
well as the consequent conclusion that q is true. All that has been proved is
p ⇒ q, the implication itself.
This establishment method works because of the nature of the OR statement
q ∨ ¬p. The reason you are allowed to assume p to be true is that, if p were
false the OR would be satisfied, so p being true is the only case left to check.

Example 4.4. Suppose we wanted to prove that

If Empire apples are deadly poison, then you should not eat them.

You would start your argument by asking the reader to grant you the truth of
the hypothesis for the sake of the argument. “Let Empire apples be deadly poi-
son”, you say, to the consternation of the apple industry. Once the hypothesis is
granted, the argument to the conclusion is very easy, since you should not eat
anything which is deadly poison, whatever it is. Now that the implication is es-
tablished, our knowledge of the nature of an Empire apple returns to its former
state, both with regard to it being poison, and the injunction not to eat it. Only
the truth of the implication remains. ♦

How to use the implication p ⇒ q


Show p. Then q follows immediately from the truth of p ⇒ q.
So, to use the implication, you do work to show logically that the antecedent
is actually true. In that work, you need not concern yourself with q at all. If you
are successful, and p is shown to be true, then the implication p ⇒ q establishes
that q is also true. It is equally valid, and maybe more convenient, to assume q
is false and under that assumption show that p is false.
What makes this formulation so valuable is this division of labor. On the
one hand, in the establishment, you show q without concern as to whether or
why p should be true, and then, in the use, you are allowed to concentrate only
on p without worrying about q at all. This is the reason that mathematicians,

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Formal logic Chapter | 4 79

and those who use mathematics, are careful to preserve this ancient and rigid
formulation of the implication despite natural language’s drift in giving it other
connotations. The implication in its pure form is too practically useful to alter.

Exercises
1. Which of the following implications do you regard as true?
a) If it snowed in Boston last year then there will be a full moon there some-
time next August.
b) If you eat cauliflower every day then smoking cigarettes is a bad idea.
c) If a leprechaun appears on St. Patrick’s Day and gives you a pot of gold
then U.S. federal law requires you to give all that gold to your parents.
2. Establish the following implications.
a) If 18 is odd, then 20 is odd.
b) If π is irrational, then 20 is even.
3. Establish the following implications:
a) (p ∨ ¬p) ⇒ (q ∨ ¬q)
b) (p ∧ q) ⇒ (q ∨ r)

4.4 Double implication


If p ⇒ q and q ⇒ p are both true, sometimes written p ⇔ q, then p and q
must have the same truth value. Here is why. If either p or q is true, one or the
other implication shows that the other is true is well, so both are true. The only
situation left, which must not be neglected, is if both p and q are false. By the
definition of the implication, p ⇒ q and q ⇒ p are both true in this case as well,
since for both the antecedent is false.
So p ⇔ q says exactly that either p = q = 0 or p = q = 1. For this reason,
the ⇔ symbol is often used in logic in place of the equality symbol =. We will
use both symbols synonymously:

[p = q] = [p ⇔ q] = [(p ⇒ q) ∧ (q ⇒ p)]

This identity justifies a technique that, like the double inclusion we studied ear-
lier, is widely used, fundamental, and gives good practice in logical thinking and
using logical notation. In this text it is called the double implication method of
showing logical equivalence.
Definition 4.5. To establish the equivalence of two logical expressions p and
q by the double implication method, show separately that p ⇒ q and q ⇒ p.

As a first application of the double implication method, we will show one of
the distributive laws,

[p ∧ (q ∨ r)] ⇔ [(p ∧ q) ∨ (p ∧ r)]

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


80 Discrete Mathematics With Logic

to be followed by a short commentary.

Proof. First we show [p ∧ (q ∨ r)] ⇒ [(p ∧ q) ∨ (p ∧ r)], so we assume p ∧


(q ∨ r) is true. Thus p and q ∨ r are both true. Since q ∨ r is true, there are two
cases.
Case 1. q is true. In that case p ∧ q is true. Therefore (p ∧ q) ∨ (p ∧ r) is
true.
Case 2. r is true. In that case p ∧ r is true. Therefore (p ∧ q) ∨ (p ∧ r) is
true.
So in either case, (p ∧ q) ∨ (p ∧ r), as required.
Next we show [(p ∧ q) ∨ (p ∧ q)] ⇒ [p ∧ (q ∨ r)]. Let (p ∧ q) ∨ (p ∧ q)
be true. Then there are two cases.
Case 1. p ∧ q is true, so both p and q are true. Since q, we have q ∨ r, hence
p ∧ (q ∨ r).
Case 2. p ∧ r is true, so both p and r are true. Since r, we have q ∨ r, hence
p ∧ (q ∨ r) in this case as well.
Thus, in either case, p ∧ (q ∨ r), as required.
Therefore the identity is true.

Commentary: The pattern is in the same form as the double inclusion proof,
but the language and notation are different. Specifically, the requirement at each
stage is different. Notice that to assert p, is the same as saying p is true, and,
though not appearing in the argument above, to assert ¬p, is to say p is false.
You could rewrite the whole argument without the words true and false, and
substitute their bit equivalents 1 and 0.
Like with double inclusion, you should learn to write proofs of this form, and
the best practice is using basic logical identities. But keep in mind, we are not
concerned with reproving well-known identities. It is implication, and double
implication that we are practicing.

Inverse, converse, and contrapositive


Given an implication p ⇒ q, the implication you would want to pair with it in
the double implication method q ⇒ p is called the converse of p ⇒ q. There
are two others which have names:
• q ⇒ p is the converse of p ⇒ q.
• ¬p ⇒ ¬q is the inverse of p ⇒ q.
• ¬q ⇒ ¬p is the contrapositive of p ⇒ q.
We have already seen that an implication and its converse are logically distinct,
the two halves of the double implication method. However, every implication is
logically equivalent to its contrapositive, and that implies that the inverse and
converse are also logically equivalent to one another.

[p ⇒ q] ⇔ [¬q ⇒ ¬p] [q ⇒ p] ⇔ [¬p ⇒ ¬q]. (4.2)

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Formal logic Chapter | 4 81

Eq. (4.2) can quickly be shown from Definition 4.3 and Boolean algebra. In-
stead, it is instructive to prove [p ⇒ q] ⇐⇒ [¬q ⇒ ¬p] as another example of
the double implication method.

Proof. We will show first that [p ⇒ q] ⇒ [¬q ⇒ ¬p], so suppose that p ⇒ q.


We now have to show the implication ¬q ⇒ ¬p so let ¬q be true, so q is false.
Our objective is to show ¬p, that is, p is false. If p were true, then since p ⇒ q,
we would have q, but q is false. Therefore p must be false, i.e., ¬p. We have
shown ¬q ⇒ ¬p, ♥ concluding the proof that [p ⇒ q] ⇒ [¬q ⇒ ¬p]. ♦
The other half is left as an exercise.

Commentary. The argument is tricky because, inside the proof of one im-
plication you have to prove a different implication, and that in different places
in the argument you have to correctly establish and use implications. Notice
what is known and what hypotheticals have been granted at ♥. The implication
¬q ⇒ ¬p has been shown, so the assumption ¬q and the consequence ¬p are
no longer to be granted in the argument, as well as anything concluded from
them except ¬q ⇒ ¬p. The overall implication [p ⇒ q] ⇒ [¬q ⇒ ¬p] is still
being argued, so at ♥ the hypothesis p ⇒ q is still granted to be true. Fortu-
nately, we have just what we need to establish the desired implication, and once
that is done, at ♦, the first half of the argument is over, and the granted hypothet-
ical p ⇒ q and the concluded ¬q ⇒ ¬p are released. All that remains proven
is [p ⇒ q] ⇒ [¬q ⇒ ¬p].

Exercises
1. Prove by double inclusion the associative law for ∧, the AND operator:

[p ∧ (q ∧ r)] ⇔ [(p ∧ q) ∧ r].

2. Prove one of De Morgan’s Laws for formal logic, or one of the distributive
laws, see Eq. (4.1), by the double implication method.
3. Consider the implication a ∧ (b ∨ c) ⇒ d.
a) Which of a, b, c, and d can you immediately assume to be true?
b) What is the consequence of the implication?
c) What is the antecedent of the contrapositive?
d) What is the hypothesis of the converse?
e) What is the conclusion of the inverse?

4.5 Working with Boolean algebra


The algebra of Boolean expressions is based on ∨, ∧, and ¬ and follows the
commutative, associative, distributive laws, and De Morgan’s laws, and other
equations listed in Eq. (4.1). Boolean algebra is the most direct way of working
with complex logical expressions.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


82 Discrete Mathematics With Logic

Example 4.6. Is the negation of the implication p ⇒ q its inverse, its converse,
or its contrapositive?

Actually, none of these, since ¬(p ⇒ q) = ¬(q ∨ ¬p) = ¬q ∧ ¬(¬p) = p ∧
¬q, so the negation of an implication is not an OR statement at all, and is a
stronger AND statement. ♦

For a more complicated illustration of the algebraic approach, we will ex-


amine a Boolean identity once with double implication, and once with Boolean
algebra:
[p ⇒ (q ⇒ r)] ⇐⇒ [(p ∧ q) ⇒ r]

Proof. (by double implication) We first show [p ⇒ (q ⇒ r)] =⇒ [(p ∧ q) ⇒


r]. Assume p ⇒ (q ⇒ r). We need to show (p ∧ q) ⇒ r and so assume p ∧ q.
So p and q are both true, and since p ⇒ (q ⇒ r) we have q ⇒ r. Now, since q
is true, we have r, as required to establish (p ∧ q) ⇒ r.
We next show [(p ∧ q) ⇒ r] =⇒ [p ⇒ (q ⇒ r)]. Assume (p ∧ q) ⇒ r. To
show p ⇒ (q ⇒ r) we may assume p and have to show q ⇒ r. To show q ⇒ r
we may assume q. ♥ Since we have p and q, we have p ∧ q and (p ∧ q) ⇒ r
allows us to conclude r. Since assuming q allowed us to conclude r, we have
q ⇒ r, and that conclusion allows us to say that p ⇒ (q ⇒ r) as required in
proving [(p ∧ q) ⇒ r] ⇐⇒ [p ⇒ (q ⇒ r)].

Commentary. In the second part, count how many implications and hypo-
theticals we are juggling at ♥. This is certainly the most complicated double
implication proof one would ever want to read. But remember, we are not study-
ing double implication to play with identities, but to learn the reasoning method
to use later on other discrete problems. If you can get through this example,
you can really say that you have mastered that method, and understand how
implications work.
Here is the same expression approached via Boolean algebra, which is de-
signed exactly to fit this type of problem.

[p ⇒ (q ⇒ r)] = [(q ⇒ r) ∨ ¬p]


= [(r ∨ ¬q) ∨ ¬p]
= [r ∨ (¬q ∨ ¬p)]
= [r ∨ ¬(q ∧ p)]
= [r ∨ ¬(p ∧ q)]
= [(p ∧ q) ⇒ r]

You should definitely justify each step in the “calculation” above from the list
in Eq. (4.1), and note the name of the property used.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Formal logic Chapter | 4 83

Exercises
1. Express p ⇒ (q ⇒ (r ⇒ s)) only in terms of ∨, ∧, and ¬.
2. Express p = (q ⇒ r) only in terms of ∨, ∧, and ¬.
3. Express (p ⇒ q) = (q ⇒ p) only in terms of ∨, ∧, and ¬.

4.6 Boolean functions


If we pursue the analogy between ordinary algebra and Boolean algebra, the
next object to consider is the function. In ordinary algebra, you considered func-
tions like f (x) = 1 − 2x 2 , g(x, y) = x 2 + y 2 , or f (x, y, z) = (x − z)(y − x),
you looked at their graphs, and studied their behavior. For each assignment of
values to the independent variables, these functions determine the output value,
which for these examples is just a single real number.
We can create the same structure in Boolean algebra and, in fact, we have al-
ready done so. Each Boolean expression we have examined, like p ⇒ (q ⇒ r)
determines for each set of Boolean values assigned to p, q, and r, an output
Boolean value of 0 or 1, that is, TRUE or FALSE. We can make the situa-
tion look more like the algebra with which you are more familiar by writing
b(p, q, r) = [p ⇒ (q ⇒ r)], and noting that b(0, 0, 0) = b(1, 1, 1) = 1, and
b(1, 1, 0) = 0. In logic, however, is it not very common to use the standard
mathematical notation b(p, q, r) to specify a Boolean function, but to simply
note that an expression like p ∨ q ∧ (r ∨ ¬p) defines a Boolean function.
Definition 4.7. A Boolean function on the Boolean variables p, q, r, . . . , is a
rule which assigns a bit, or TRUE or FALSE, to each assignment of bits to the
variables p, q, r, . . . . ♠
Since there are 2n possible ways to assign bits to n Boolean variables, the
multiplicative principle gives us the following.
n)
Theorem 4.8. There are 2(2 different Boolean functions on n Boolean vari-
ables, p1 , . . . pn .
That’s a lot of functions. So far, we have been specifying a Boolean func-
tion by choosing Boolean variables and forming an expression using any of the
logical operators which we have defined, ∨, ∧, and ¬. (We don’t need ⇒ since
the implication can be always rewritten with ∨ and ¬.) So it would seem that
¬, ∨, and ∧ will need to be augmented, as is done in ordinary functions when
you added exotic functions like ln(x) and sin(x), to express them all. But for
Boolean functions, no exotic functions are required.
Theorem 4.9. Every Boolean function corresponds to a Boolean expression in
the Boolean variables using only the operations ∨, ∧, and ¬.
We will illustrate the result for four Boolean variables, p, q, r, and s. Defin-
ing the function requires us to assign an output bit to each bit assignment of

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


84 Discrete Mathematics With Logic

p, q, r, and s. Suppose first, for a simple example, that we wanted to assign


bit 1 in the situation p = 1, q = 0, r = 1, and s = 1, and assign 0 to all the
other 24 − 1 input assignments. That is easily accomplished by the AND clause
p ∧ ¬q ∧ r ∧ s, and the same clause would assign FALSE to any other particular
bit assignment to p, q, r, and s. If instead you had several input assignments to
return TRUE, you can connect the individual AND clauses with ∨. With this
4
trick you may express any of the 2(2 ) Boolean functions. We can do a numeri-
cal check: there are 24 possible AND clauses, and for each of them, one chooses
4
whether or not to include it in the final OR clause, so we compute 2(2 ) different
expressions of that type.
Example 4.10. Express a Boolean function on p, q, r, s and t which is TRUE
when exactly one of the input variables is FALSE.

Assigning TRUE if just p is false corresponds to the AND clause ¬p ∧ q ∧ r ∧


s ∧ t, and the function can be expressed by

(¬p ∧ q ∧ r ∧ s ∧ t) ∨ (p ∧ ¬q ∧ r ∧ s ∧ t) ∨ (p ∧ q ∧ ¬r ∧ s ∧ t)∨
(p ∧ q ∧ r ∧ ¬s ∧ t) ∨ (p ∧ q ∧ r ∧ s ∧ ¬t) 

Exercises
1. For p, q, r and s, express “they can’t all be true” in terms of ∨, ∧, and ¬.
2. For p, q, r and s, express “all are true or none are true” in terms of ∨, ∧,
and ¬.
3. For p, q, r and s, express “any three imply the fourth” in terms of ∨, ∧,
and ¬.

4.7 DNF and CNF†


Disjunctive normal form
By Theorem 4.9 every Boolean function may be expressed in terms of Boolean
variables and ∧, ∨, and ¬, but in the explanation, we actually showed that this
could always be done in a special form, called a normal form.
Definition 4.11. An AND clause on the Boolean variables p1 , . . . pN is a
Boolean expression of the form x1 ∧ x2 ∧ · · · ∧ xn , where each xi is either pi or
its negation xi ∈ {pi , ¬pi }.
A Boolean expression is said to be in disjunctive normal form (DNF) if it
can be written A1 ∨ A2 ∨ · · · ∨ AK , where each Ai is an AND clause. ♠
The remarks following Theorem 4.9 actually show that

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Formal logic Chapter | 4 85

Theorem 4.12. Every Boolean function can be expressed in disjunctive normal


form.

An expression in disjunctive normal form is slightly more general than the


types thought of so far, in which each of the AND clauses had the same number
of variables. The Boolean function (p ∧ q) ∨ (p ∧ ¬q ∧ r) ∨ (p ∧ ¬q ∧ ¬r ∧ s) is
also in disjunctive normal form. Also (p ∧¬q ∧r)∨(s ∧¬t)∨u is in disjunctive
normal form, and notice the very short AND clause u at the very end.

Conjunctive normal form


We can consider the situation with AND and OR reversed.

Definition 4.13. An OR clause on the Boolean variables p1 , . . . pN is a Boolean


expression of the form x1 ∨ x2 ∨ · · · ∨ xn , where each xi is either pi or its
negation, xi ∈ {pi , ¬pi }.
A Boolean expression is said to be in conjunctive normal form (CNF) if it
can be written O1 ∧ O2 ∧ · · · ∧ OK , where each Oi is an OR clause. ♠

If you have an expression in conjunctive normal form, like

(p ∨ ¬q ∨ s) ∧ (q ∨ ¬t ∨ z) ∧ (r ∨ s ∨ t) ∧ (¬p ∨ ¬r ∨ t)

it can be quite difficult to find a Boolean assignment to the variables which


makes the expression TRUE. And, more concerning, the problem seems to
get exponentially worse, the longer the expression gets, even though checking
whether any assignment does or does not yield true is very quick. On the other
hand, it is not known if there is some subtle trick which would allow us to solve
the problem in a simpler way than, essentially, checking all possible assign-
ments. Problems of this type are now well-studied, and are called NP-complete.

Theorem 4.14. Every Boolean function can be expressed in conjunctive normal


form.

This follows either from first expressing the negation in disjunctive nor-
mal form, and then negating that expression in disjunctive normal form using
De Morgan’s laws, thereby switching all the ANDs to ORs, all the ORs to
ANDs, and reversing which variables are negated in each clause. A second way
to see this, is start with an expression of the desired Boolean function in disjunc-
tive normal form, and use the distributive law to “multiply it out”, just like you
would multiply out (x + y + z)(x − y + w)(−x + w + t). You can do that in
reverse to convert a conjunctive normal form into an, easy to solve, disjunctive
normal form, but that doesn’t solve the NP-completeness problem since, in gen-
eral, by the multiplicative principle, multiplying out the algebraic expression is
still a lot of work.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


86 Discrete Mathematics With Logic

Example 4.15. Write (p ∧ ¬q ∧ r) ∨ (¬p ∧ q) ∨ (p ∧ s) in CNF.

Multiplying out, by the multiplicative principle, will involve 3 · 2 · 2 = 12 OR


clauses. Here they are arranged “lexicographically” to make sure we don’t get
lost: (r ∨ q ∨ s) ∧ (r ∨ q ∨ p) ∧ (r ∨ ¬p ∨ s) ∧ (r ∨ ¬p ∨ p) ∧ (¬q ∨ q ∨
s) ∧ (¬q ∨ q ∨ p) ∧ (¬q ∨ ¬p ∨ s) ∧ (¬q ∨ ¬p ∨ p) ∧ (p ∨ q ∨ s) ∧ (p ∨ q ∨
p) ∧ (p ∨ ¬p ∨ s) ∧ (p ∨ ¬p ∨ p). It really seems like we are not done. The
expression contains OR clauses like r ∨ ¬p ∨ p which ought to be simplified,
(how?) but it is in CNF. ♦

Exercises
1. For p, q, r, and s, express “they can’t all be true” in boolean notation.
a. Rewrite in DNF.
b. Rewrite in CNF.
2. For p, q, r, and s, express “all are true or none are true” in boolean notation.
a. Rewrite in DNF.
b. Rewrite in CNF.
3. For p, q, r, and s, express “any three imply the fourth” in boolean notation.
a. Rewrite in DNF.
b. Rewrite in CNF.

4.8 Case study: Classic logic puzzles


Logic puzzles have been published on websites and blogs since the internet
was created, and before that were a regular feature in newspapers for over a
century. I first saw these problems given below in a paperback puzzle book
published in the 1970’s. The oldest version I can find cites a philosophy text by
Copi from the 1960’s, but I doubt that is the original source – from the wording
of the problems it seems likely that they are at least 30 years older than that.
They must be good problems because they usually appear together with only
trivial alterations. I have tried to give you the problems in their most original
formulations. (For solutions, usually bad ones, you can just Google the text, but
where is the fun in that?)

Benno Torelli, genial host of Jamtrack’s most exclusive supper club, was
shot and killed by a racketeer because he fell behind in his protection payments.
When questioned by the police, each of the men made three statements, two
true and one false.
Lefty: “I did not kill Torelli. I never owned a revolver. Spike did it.”
Red: “I did not kill Torelli. I never owned a revolver. The other guys are all
passing the buck.”

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Formal logic Chapter | 4 87

Dopey: “I am innocent. I never saw Butch before. Spike is guilty.”


Spike: “I am innocent. Butch is the guilty man. Lefty lied when he said I did
it.”
Butch: “I did not kill Torelli. Red is the guilty man. Dopey and I are old
pals.”



Daniel Kilraine was killed on a lonely road, two miles from Pontiac, at
3:30am on March 17. Otto, Curly, Slim, Mickey, and The Kid were arrested
a week later in Detroit and questioned.
Each of the five made four statements, three of which were true, and one of
which was false.
One of these men killed Kilraine. The statements were:
Otto: “I was in Chicago when Kilraine was murdered. I never killed anyone.
The Kid is the guilty man. Mickey and I are pals.”
Curly: “I did not kill Kilraine. I never owned a revolver in my life. The Kid
knows me. I was in Detroit the night of March 17.”
Slim: “Curly lied when he said he never owned a revolver. The murder was
committed on St. Patrick’s day. Otto was in Chicago at this time. One of us is
guilty.”
Mickey: “I did not kill Kilraine. The Kid has never been in Pontiac. I never
saw Otto before. Curly was in Detroit with me on the night of March 17.”
The Kid: “I did not kill Kilraine. I have never been in Pontiac. I never saw
Curly before. Otto lied when he said I am guilty.”



The employees of a small loan company are Mr. Black, Mr. White, Mrs. Cof-
fee, Miss Ambrose, Mr. Kelly, and Miss Earnshaw. The positions they occupy
are manager, assistant manager, cashier, stenographer, teller, and clerk, though
not necessarily in that order.
The assistant manager is the manager’s grandson, the cashier is the stenog-
rapher’s son-in-law, Mr. Black is a bachelor, Mr. White is twenty-two years old,
Miss Ambrose is the teller’s stepsister, and Mr. Kelly is the manager’s neighbor.
Who holds each position?

4.9 Case study: Spies


Suppose you were designing a spy game. To make the game interesting, your
spies can be equipped with a variety of unique gadgets. So far you have pro-
grammed in the following:

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


88 Discrete Mathematics With Logic

a antigravity belt with signal flairs


b brick of gold
c car with 100K£ in the glove box
d dagger with diamond hilt
e pearl earring with hidden transmitter
f faithful sidekick
g gun with silver bullets
h helicopter with missile launcher

Each spy will not be given all these fancy gadgets, just a subset. But the spy
must have enough gear to be survivable. To be survivable he must have among
his gadgets a weapon, something valuable, a method of communication, and
transport. {a, b, c, d, e, f, g, h} are Boolean variables which are true if the spy
possesses the corresponding gadget, and false otherwise.
Here is a proposed survivability function:

(b ∨ d ∨ g ∨ h) ∧ (b ∨ c ∨ d ∨ e ∨ g) ∧ (a ∨ e) ∧ (a ∨ c ∨ h)

Each of the four OR clauses has a meaning in the game. Can you identify which
is which?

Each represents one of the four conditions of survivability, possession of
weapon, valuables communicator, and transport respectively. So the brick of
gold is a valuable which the spy, at necessity, could use as a weapon, but not for
transport or for communication. Of course, the faithful sidekick doesn’t help the
spy survive at all, and doesn’t occur in the survivability function.
The survivability function, which is naturally and easily written in CNF, il-
lustrates that CNF is not nearly so useless as it seemed when considering the
Boolean function only from the point of view of finding Boolean values which
evaluate it to TRUE.
The negation, and a little Boolean algebra, quickly gets us an expression for
the non-survivable function in DN F :

(¬b ∧¬d ∧¬g ∧¬h)∨(¬b ∧¬c ∧¬d ∧¬e ∧¬g)∨(¬a ∧¬e)∨(¬a ∧¬c ∧¬h)

Multiplying out to find the CNF of non-survivability will involve us in 4 · 5 ·


2 · 3 terms, a large number but we expected that, which then would be culled for
duplicates.
An interesting question would be, since the OR clauses of the survivability
function in CNF, neatly expressed, have meaning in the game, why shouldn’t
the OR clauses of the CNF for non-survivability also have some meaning? Does
that CNF hold other concepts of strategic value, perhaps known to us already,
perhaps revealing a new insight?

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Formal logic Chapter | 4 89

4.10 Case study: Pirates and cannonballs


Pirates seem always to be popular, adventurously sailing the high seas, looting
and plundering and being in every way perfectly admirable folk. Some people
have favorite pirate heroes, fictional or actual, Long John Silver or Blackbeard.
But asked who was the greatest sea pirate of them all, if you judge fairly you
would certainly have to settle on a woman, Queen Elizabeth I of England. Her
privateers were hugely successful, filled the treasury of England with heaps of
gold, and included titled noblemen such as Sir Walter Raleigh, famous also for
spreading his cloak in the mire.
Sir Walter, personally, was so successful as a pirate that he could afford such
luxuries on his ship as a mathematician, who did work on the problem we are
considering in this case study.
Suppose that you have plenty of gunpowder and cannonballs, all prepared
to help persuade any ships you encounter to hand over their treasure. The can-
nonballs are neatly arranged in a stack with a square wooden frame containing
n × n balls. In the chinks between the balls of the bottom layer, there are places
for (n − 1) × (n − 1) balls in the next layer, and so on to the next layer and
the next until a single cannonball is placed on top. The question is, how many
cannonballs are in the stack?
The internet being intermittent aboard ship, the answer is difficult to look up,
so they start making a table, recording first the different heights from 1 to 10,
then the number of balls in each layer, and with a little trouble, they fill in the
third column, the number of balls in each stack from 1 to 10. We can imagine Sir
Walter and his employee looking for a pattern in values of column 3 of Table 4.1
in order to figure out the general formula. But, at least at first, they don’t see one.
Do you?

TABLE 4.1 Stacking cannonballs with a


square base.
n
n n2 12 + ··· + n2 i=1 i
2

1 1 1 1
2 4 5 5
3 9 14 2·7
4 16 30 2·3·5
5 25 55 5 · 11
6 36 91 7 ·13
7 49 140 22 · 5 · 7
8 64 204 22 · 3 · 17
9 81 285 3 · 5 · 19
10 100 385 5 · 7 · 11

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


90 Discrete Mathematics With Logic

After a while, in desperation, they factor each of the totals into their prime fac-
tors, placing the results in column 4, and are quite disappointed with the results.
But there is a sort of pattern, intermittent but persistent, like a glimpsed shadow
in the fog which might be a prize ship to be attacked. The pattern is underlined
in column 4: skip the first entry, 5, 7, skip, 11, 13, skip, 17, 19, skip.
We would be happy to fill in the pattern even with non-primes to get 3, 5, 7,
9, 11, 13, 15, 17, 19, 21, but each of those skipped entries is missing a factor
of 3. So, to make the pattern work, and at a loss for anything better to do, they
add a factor of three to all entries, dividing it right back out again, so that the
number is unaltered. The result is column 4 in Table 4.2, with the numbers in
the desired pattern in parentheses.

TABLE 4.2 The pattern coming into focus.


n n
n n2 12 + ··· + n2 i=1 i
2
i=1 i
2

1 1 1 1 · (3)/3 [1] · 1 · (3)/3


2 4 5 (5) · 3/3 [1] · 3 · (5)/3
3 9 14 2 · (7) · 3/3 [2] · 3 · (7)/3
4 16 30 2 · (9) · 5/3 [2] · 5 · (9)/3
5 25 55 5 · (11) · 3/3 [3] · 5 · (11)/3
6 36 91 7 · (13) · 3/3 [3] · 7 · (13)/3
7 49 140 22 · 7 · (15)/3 [4] · 7 · (15)/3
8 64 204 22 · 3 · (17) · 3/3 [4] · 9 · (17)3
9 81 285 3 · 5 · (19) · 3/3 [5] · 9 · (19)/3
10 100 385 5 · 11 · (21)/3 [5] · 11 · (21)/3

Looking for a pattern in the numbers not in parentheses is still quite disap-
pointing. But something is there, again not a regularly ascending or descending
sequence, but one hobbling along in twos – from bottom to top you see 5, 5, 4,
4, 3, 3, 2, 2, skip 1. The pirates add the missing factor of 1 at no cost and isolate
those numbers in square brackets. That takes them to column 5, with the leftover
numbers in angular brackets. In the angular brackets we have another hobbling
pattern, bottom to top 11, 9, 9, 7, 7, 5, 5, 3, 3, 1, but this is actually progress.
Why not write down separate formulas for the even and odd cases? For the even
height stacks they quickly get (n/2)(n + 1)(2n + 1)(1/3). For the odd height
stacks get n((n + 1)/2)(2n + 1)(1/3).
Break out the rum – algebraically it is the same formula in both cases!
The next thing they do is just what you or I would do. They add 112 to 385
to get 385 + 121 = 506 for a stack of height 11. Then they compute

11(11 + 1)(2 · 11 + 1)
= 506
6
and find – hurrah! – that their formula works!

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Formal logic Chapter | 4 91

Hurrah! – but now they are completely stuck. They can check their formula
against new cases, 12, 13, 14, . . . , but that does not provide a convincing logical
argument to prove the general formula. Their “successful” method started with
the pattern of primes – for which they had no formula in 1600, and there is no
formula even now. So those pirates, even with the help of logic, had no way
scaling their method to show that their formula was true in the general case.
But that mathematician had a way. That will have to wait until the next chap-
ter.

4.11 Summary exercises


You should have learned about:
• Statements and formal logic
• Proper notation in formal logic
• Formal logic operations, ∨, ∧, and ¬
• Expressing formal logical statements in the Boolean algebra
• The implication ⇒ in formal logic
• That an implication is equivalent to its contrapositive
• How to establish versus how to use an implication
• How to write a double implication proof
1. Discuss whether each of the following qualifies as a statement, and if so,
whether it is true or false.
a) In chess, the bishop moves diagonally.
b) Napoleon Bonaparte is alive and hiding in the International Space Sta-
tion.
c) π > 2.
d) π 2 is rational.
e) π is wonderful.
f) Pluto is a planet.
g) SpaceX launches bomb because of snarky TV commentators.
2. Let p0 , p1 , p2 , and p3 be Boolean variables. Express “at most 2 are true”
as a Boolean expression.
3. For each of the following sentences, rewrite it as a standard implication and
decide whether the implication is true in the logical sense: Say whether the
sentence in natural language involves temporality, causality, or both.
a) “If you can’t stand the heat, get out of the kitchen.”
b) “If you are not part of the solution, then you are part of the problem.”
c) “Choosy mothers choose JIFF.”
d) “Even if you’re on the right track, you’ll get run over if you just sit
there.”
e) “If you can read this, then you are too close.”
4. Find two assignments of truth values for the variables p, q, and r which
make p ⇒ (q ∨ ¬r) true.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


92 Discrete Mathematics With Logic

5. If you wanted to prove directly the contrapositive of (r ∨ p) ⇒ (q ∨ ¬r),


what would you be allowed to assume?
6. What is the antecedent of the implication p ⇒ (q ⇒ (r ∨ p))? What is the
conclusion of the contrapositive? What is the hypothesis of the contrapos-
itive?
7. Write the negation of (r ∨ p) ⇒ (q ∨ ¬r) so that no parenthetical expres-
sion is negated.
8. Write the negation of p ⇒ (q ⇒ (r ∨ p)) as a Boolean function so that no
parenthetical expression is negated.
9. Find two Boolean assignments for p, q, and r for which p ⇒ (q ∨ ¬r) and
¬p ∨ ¬q ∨ ¬r are both true.
10. Use the distributive law to write (((a ∧ b) ∨ c) ∧ d) ∨ (d ∧ e) so that no
symbol ∨ is inside any parenthesis.
11. Use the distributive law to write (((a ∧ b) ∨ c) ∧ d) ∨ (d ∧ e) so that no
symbol ∧ is inside any parenthesis.
12. Let B(p, q, r) = (1 − pq)2 (1 − (1 − q)(1 − pr)). Verify that for p, q,
r ∈ B, that B(p, q, r) ∈ B. Rewrite B(p, q, r) using ∨, ∧, and ¬.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Chapter 5

Induction
5.1 Predicate logic
Formal logic is based on statements, equivalently propositions, equivalently
Boolean variables. Predicate logic is based on predicates. You may know the
word predicate from grammar, the study of languages in which sentences are
taken apart and their structure analyzed. A sentence may be decomposed gram-
matically into a subject, a noun phrase; followed by a predicate, consisting of
most everything else – the verb, the objects, the prepositional phrases, and all
the other parts of speech which come together in the sentence to express what
you want to say about the subject.
“Benedict Arnold is a filthy traitor and ought to be tarred and feathered.”
This is a simple sentence with the subject in bold and the predicate in italics.
Logically the sentence might stand for a proposition which could be true or
false depending on your opinion of Benedict Arnold.
In predicate logic, the idea is to hold the predicate fixed, and to vary the
subject.
“John Adams is a filthy traitor and ought to be tarred and feathered.”
“Wyatt Earp is a filthy traitor and ought to be tarred and feathered.”
“John Philip Sousa is a filthy traitor and ought to be tarred and feathered.”
This idea of predicate may be conveyed by using a generic unspecified subject,
a pronoun indicating the set of people under consideration: “The accused is
a filthy traitor and ought to be tarred and feathered.” The particular instances
above are said to have been instantiated, or quantified from this general version.
Here is a more mathematical example, “The number is a prime number”;
which may be quantified to be true, “Twenty-three is a prime number”, or false
“Avogadro’s number is a prime number”.
This linguistic game is how predicate logic got its name, but mathematically
it is more efficient to regard the predicate as a function which assigns a truth
value, that is, a Boolean value to each element of the set of subjects.
Definition 5.1. A Boolean function P on a set S is an assignment P (s) ∈ B for
each element s ∈ S. ♠
Note, P (s) is often written as Ps .
The Boolean functions we had in formal logic fit this scheme as a special
case. For example for r ∨ (p ⇒ q) the elements of S are triples of Boolean
values, and r ∨ (p ⇒ q) is TRUE if quantified with r = p = q = 1, and FALSE

Discrete Mathematics With Logic. [Link] 93


Copyright © 2024 Elsevier Inc. All rights reserved.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


94 Discrete Mathematics With Logic

if instantiated with r = p = 0 and q = 1. The new, more general concept of


Boolean function allows us to bridge the gap between the formal logic we have
been studying, and sets we have been designing to help solve problems. With
predicate logic, sets and logic can be made to work together and support one
another.
When the predicate is described in the terminology and notation of Boolean
functions, the Boolean function is usually said to be evaluated, rather than in-
stantiated or quantified, although all three terms are acceptable.
Consider the set N of natural numbers, with n ∈ N, and set P (n) = [n ≥ π].
So P (0) = P (1) = P (2) = P (3) = 0, or FALSE, with all other values evaluat-
ing to 1 or TRUE.
Another example on the natural numbers is Q(n) = [n2 + 10 = 7n], for
which Q(2) = Q(5) = 1, with all other natural numbers evaluating to FALSE. It
is a little odd that the equals sign is occurring twice in two different senses in the
definition of Q(n). For this reason some prefer to use an alternate symbol, such
as Q(n) := [n2 + 10 = 7n], which we will often follow. Note: it is a common
mistake to evaluate Q(5) as 35, since both sides of the equality evaluate as 35.
Instead Q(5) evaluates to 1 indicating that the equality 52 + 10 = 7 · 5 is true.
Here is another example on a different set, P(D). Suppose we want to
consider whether or not subsets of D have even cardinality or not. R(A) :=
[|A| is even], So R(∅) = R({1, 2, 3, 4}) = R(D) = 1, and R({1, 3, 4}) = 0.

Example 5.2. With predicate logic, you may see even greater utility in the def-
inition of the implication in logic: the consequence is true or the antecedent is
false; since there are various instantiations to compare.

“The customer over six feet tall may not rent a rowboat.”

The rule is TRUE for Hans who is 6’8” and may not rent a rowboat (antecedent
and consequence both true). It is true for Ignaz, who is 5’2” and may rent a
rowboat (antecedent false and consequence false). It is valid also for Jörg, who
is 5’1” but may not rent a rowboat because he weighs 288 lbs. (antecedent false
and consequence true). The company violates the height rule if it rents a rowboat
to Hans. It does not violate the height rule if it rents rowboats to Ignaz and Jörg,
or refuses to do so. The point of this example is not to focus just on Hans, but on
the totality of customers. The implication should be valid for all, but is written
solely to prevent tall people from renting rowboats. ♦

Exercises
1. Underline the predicate of each of the following, and instantiate each subject
twice, once resulting in TRUE, once resulting in FALSE.
a. The man was born after 1888.
b. The state is north of North Carolina.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Induction Chapter | 5 95

2. Underline the predicate of each of the following, and instantiate each sub-
ject twice, once resulting in TRUE, once resulting in FALSE. Context: Our
universe are the natural numbers.
a. The number is the sum of three distinct cubes.
b. The number is the product of three primes.
3. The point lies between one and two units from either (1, 1) or (−1, −1).
Draw a sketch of the points in the plane in which the points making this
Boolean function true are colored red, and those making it false are colored
blue.

5.2 Existential and universal quantification


The general Boolean functions we have introduced only become statements and
have a truth value when they are evaluated. They have no truth value in and of
themselves, just as f (x) = x 2 + 1 has no numerical value, while f (42) does.
Boolean functions defined on the same set may be combined with our log-
ical operators ∧, ∨, ¬, and ⇒. So, if we have defined P (n) := [n2 > 42] and
Q(n) := [n3 ≥ 1000], then P (n) ∧ ¬Q(n) would evaluate to true for n = 7 and
false for n = 1.
The logical operators of formal logic, when applied to Boolean functions,
satisfy all the Boolean identities listed in Eq. (4.1). In particular, De Morgan’s
laws and the distributive laws hold. So there is an algebra of Boolean functions
extending our formal Boolean algebra in just the same way that the ordinary
algebra of numbers was extended to an algebra of real functions in high school.

Algebra of real functions Algebra of Boolean functions


Values 0, −2/3, π , etc. 0, 1
Variables x, y, z ∈ R s∈S
Operations f (x) + g(x), f (x)g(x), −f (z) Ps ∧ Qs , Ps ∨ ¬Qs

One difference between the algebra of real functions and general Boolean
algebra is that predicate logic has two very important special forms of evalua-
tion.
Definition 5.3. The universal quantification of the Boolean function P defined
on the set S is the statement that P (s) is true for all elements s ∈ S. ♠
There is a special logical symbol ∀, read as “for all”, defined by
 

[∀s ∈ S; P (s)] = P (s)
s∈S

which is used for universal quantification.


Notice that ∀s ∈ S; P (s) is a simple statement – it is either true or false – and
does not “depend on s”. All predicates in the expression have been quantified
already.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


96 Discrete Mathematics With Logic


So ∀n ∈ N; n2 > 20 is simply false, while ∀n ∈ Q; n2 = 2 is true, since 2
is irrational. How about ∀n ∈ N; n3 − n is divisible by 3? Can you determine its
truth value?
In contrast to universal quantification is existential quantification, which
sounds very exotic and intimidating, but is just the OR version of the previous
concept:

Definition 5.4. The existential quantification of the Boolean function P defined


on the set S is the statement that there exists some s ∈ S such that P (s) is true.

There is a special logical symbol ∃, read as “there exists”, and defined by


 

[∃s ∈ S; P (s)] = P (s)
s∈S

which is used for existential quantification.


Again ∃s ∈ S; P (s) is either true or false. ∃n ∈ N; [n2 + 4 = 4n] is true since
2 + 4 = 4 · 2, and√∃n ∈ Z; [n2 + 1 = 0] is false even if you believe in complex
2

numbers, because −1 ∈ / Z.

Establishing a universally quantified statement (∀s ∈ S; Ps )


For a small finite set S you might be able to check Ps for every single element
s ∈ S. Otherwise you have to show Ps for a generic s. You start let s ∈ S be
given, and then prove Ps , with the proof being valid regardless of which subject
s was given. You may need cases, but other than that you may only use the
properties accruing to s by the fact that s ∈ S. No further assumptions about s
are allowed.

Using a universally quantified statement (∀s ∈ S; P (s))


Given the universally quantified statement, you may choose whichever s ∈ S
you prefer. The universally quantified statement guarantees that Ps is true. And
if you pick a different subject, s  ∈ S, Ps  is also true.

Establishing an existentially quantified statement (∃s ∈ S; Ps )


Now you may choose any s ∈ S. You may choose a particular s you know well,
or you may construct an s from ingredients you know exist, but don’t know
specifically, like the 30 trillionth prime number. There is no restriction on s
beyond that it is an element of S. Then you only need to prove Ps for your
chosen s. That done, the existentially quantified statement is true. (You might
want to make a note that, for your chosen s, Ps is true, since you cannot recover
that fact just from knowing ∃s ∈ S; Ps .)

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Induction Chapter | 5 97

Using an existentially quantified statement (∃s ∈ S; Ps )


You may assume the existence of an s ∈ S for which P (s) is true. From [∃s ∈
S; Ps ] you have absolutely no control over which s, or whether there is more
than one. In particular, if you have already chosen s ∈ S, you may not conclude
Ps is true because [∃s ∈ S; Ps ] is true. Don’t be thrown off because you are
already considering an element of S actually called s. The letter s in [∃s ∈ S; Ps ]
is a “dummy variable”, having no connection to the value of any variable outside
the brackets of the statement. It should be clear that

[∃s ∈ S; Ps ] ⇐⇒ [∃ ∈ S; P ]

The universally and existentially quantified predicates are defined in terms


of ∧ and ∨, so they simply follow De Morgan’s laws and the distributive laws.

¬[∀s ∈ S; Ps ] = [∃s ∈ S; ¬Ps ], ¬[∃s ∈ S; Ps ] = [∀s ∈ S; ¬Ps ]

Exercises
1. Decide whether or not the following is true or false, and prove it.

∃n ∈ N; n2 + 5 = 6n

2. Decide whether or not the following is true or false. If it is true, then prove
it.
∀n ∈ N; n2 is even or n3 is odd
3. State whether the expression is a statement or merely a predicate. If a state-
ment, state whether or not it is true.
a. ∀n ∈ N; ∃m ∈ N; n3 ≥ m2
b. ∃m ∈ N; ∀n ∈ N; n3 ≥ m2
c. ∃n ∈ N; ∀m ∈ N; n3 ≥ m2
d. ∀m ∈ N; ∃n ∈ N; n3 ≥ m2
e. ∀n ∈ N; ∀m ∈ N; n3 ≥ m2
f. ∃n ∈ N; ∃m ∈ N; n3 ≥ m2

5.3 The theory of induction


In the previous section we noted that, among the four tasks associated with uni-
versally and existentially quantified predicates, the hardest one was to establish
a universally quantified statement over a large set. In this section, we show how
to prove the universal quantification of a predicate over the infinite set N using
the method of induction.
Induction may seem tricky and difficult at first, but you should not be sur-
prised if, after a time, it has become your favorite proof technique. For now,
your objective as a student should be to understand how and why induction

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


98 Discrete Mathematics With Logic

works theoretically; how to critically listen to inductive arguments and be able


to spot any flaws if there are any; to be convinced by inductive arguments if they
are valid; and even be able write simple induction proofs yourself.

Definition 5.5. A proof by induction is an argument that [∀n ∈ N; Pn ] is true


because the statement [P0 ∧ (∀ n ∈ N; Pn ⇒ Pn+1 )] is true. ♠

The induction procedure requires, instead of the proof of all instances of Pn ,


the establishment of the implications Pn ⇒ Pn+1 . Theoretically, implications
are weaker statements and hence “easier” to prove. Practically, you can only
make use of that advantage if you understand how to establish implications.
Some people prefer to see Eq. (5.1) in slightly different notation.
∞ 

Pn = [P0 ∧ (∀ n ∈ N; Pn ⇒ Pn+1 )]
n=0
= [P0 ∧ (P0 ⇒ P1 ) ∧ (P1 ⇒ P2 ) ∧ (P2 ⇒ P3 ) ∧ · · · ] (5.1)
∞ 

= P0 ∧ [Pn ⇒ Pn+1 ]
n=0

You may use the version you like best.


Here is some helpful terminology which is commonly used. In the inductive
formation P0 ∧ [∀n ∈ N; (Pn ⇒ Pn+1 )], the proposition P0 is called the base
case. It must be shown separately from the other, more intimidating term. To
prove [∀ n ∈ N; Pn ⇒ Pn+1 ], as with any universally quantified statement, we
start by letting a general n ∈ N be given, and then show, for that given n, the
truth of the implication Pn ⇒ Pn+1 . At that point, the implication Pn ⇒ Pn+1
is called the induction step, and the instance Pn , which you may assume to be
true in its establishment, is called the induction hypothesis.

Proof of Eq. (5.1). This is to show why induction is a valid method. We use the
double implication method. If the left hand side is true then all instances Pi are
true, in which case P0 is true and for any given n the implication Pn ⇒ Pn+1 is
true because the consequence is true. (That was fast.)
Now suppose the right hand side is true. So P0 is true and every instance
of the implication Pn ⇒ Pn+1 is true as well. Now we want to use those im-
plications to show that all the individual instances of Pi are also true. Since P0
is true, we know that at least some of the Pi ’s are true. If any are false, there
must be a smallest number k, with Pk false. Since k is the smallest, and k = 0,
Pk−1 is true. But we have the implication Pk−1 ⇒ P(k−1)+1 , which means that
Pk cannot be false after all, a contradiction. Thus [∀n ∈ N; Pn ] is true.

If you don’t like that formal approach, at least you notice that it is the second
half of the double implication method, which is the difficult part. A more direct
argument is: P0 is true, and because P0 ⇒ P1 , we conclude P1 is true; but now,

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Induction Chapter | 5 99

because P1 ⇒ P2 is true, we conclude P2 is true too. But now, because P2 ⇒ P3


is true, we conclude . . . .
So eventually all the Pn are true.
We know there is no “eventually” in logic, but still the second version prob-
ably seems more convincing, even with the vague “. . . ” to finish it off.
Example 5.6. Suppose you have [∀ n ∈ N; Pn ⇒ Pn+1 ]. What can you con-
clude?

In the first place, if P0 is true, then that is the missing base case, and we conclude
that all instances Pn are true by induction, [∀ n ∈ N; Pn ].
But what if P0 is false? In fact, what if they are all false? Then by the prop-
erties of the implication, Pn ⇒ Pn+1 is TRUE. So both scenarios are possible,
all instances if Pn true, and all Pn false.
Does that mean that anything can happen? No. If P77 is true, then the im-
plications imply P78 , P79 , P80 , . . . and so on for all values of n ≥ 77. The
number 77 acts as a base case for an inductive argument, and we conclude
[∀ n ≥ 77; Pn ]. What about P76 ? Could that be false? Actually, yes. The im-
plication P76 ⇒ P77 is true since the consequence is true, so both truth values
for P76 are consistent with everything we have so far.
However, if we accept ¬P76 there can be no n < 76 with Pn TRUE. If, say
P23 were true, then P23 would act as the base case of an inductive argument,
and Pn would be true for all n ≥ 23, including n = 76. So if we allow P77 to be
TRUE and P76 to be FALSE, then this is the one tipping point. Pn is TRUE for
all n ≥ 77, and Pn is FALSE for all n ≤ 76.
So, given [∀ n ∈ N; Pn ⇒ Pn+1 ], there are three types of scenarios possible
for the individual instances: all instances true, all instances false, or a finite
sequence of falsehood, followed by an endless sequence of truth. ♦

Exercises
1. Suppose you wanted to prove by induction that 3 · n! > n2 for all n ≥ 0.
What is the base case?
What implication would you have to show for the induction step?
What induction hypothesis would you be allowed to assume to prove the
induction step?
2. Suppose you wanted to prove by induction that, for every natural number,
(2n + 3)! ≥ 102(n+2) .
What is the base case?
What implication would you have to show for the induction step?
What induction hypothesis would you be allowed to assume to prove the
induction step?
3. Suppose Pn is a predicate defined on n ∈ N. Suppose that ∀n ∈ N; [Pn ⇒
Pn+1 ], and that P21 ∧ ¬P12 is true. For each of the following, state whether

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


100 Discrete Mathematics With Logic

it must be true, must be false, or cannot be concluded from the information


given: P5 , P15 , P25 , P35 , and P45 .

5.4 Induction practice


Now let’s try out the method of induction on a real predicate of interest, and
we should start with the equation which was left hanging from Section 4.10, the
case study on pirates and cannonballs:


n
n(n + 1)(2n + 1)
k2 =
6
k=0

If you read that, we left off with a formula which we strongly suspected was
true for all n, but for which we had no argument whatever, which applied in the
general case.
We will give an inductive proof and then a commentary.

Proof. Base case: For n = 0 (♥0 ) the left hand side of the formula is 02 and the
right hand side is 0(0 + 1)(2 · 0 + 1)/6 = 0. So they
 are equal.
Induction step: Let n be given and suppose nk=0 k 2 = n(n+1)(2n+1) (♥1 ).
n+1 2 (n+1)(n+2)(2n+3) 6
We want to show that k=0 k = 6 (♥2 ). Isolating the last term
of the sum, we have
 n 

n+1  n(n + 1)(2n + 1)
k =
2
k + (n + 1)2 =
2
+ (n + 1)2
6
k=0 k=0

by the induction hypothesis (♥3 ). Clearly n(n+1)(2n+1) + (n + 1)2 =


 6
(n+1)(n+2)(2n+3)
6 (♥4 ) so we have n+1 k=0 k =
2 (n+1)(n+2)(2n+3)
6 (♥5 ) as required,
completing the induction step.
Thus the identity is true for all n by induction.
Commentary: At ♥0 you notice that the induction variable is n, not k. We
want to show the equation is true for all n. The letter k is just an index defining
the sum. The identity does not “depend on the value of k”. In the induction step,
the assumption at ♥1 , the induction hypothesis, is made for the one particular
value of n just given, and only for the purpose of showing the implication. It is
not assumed “for all n”. That would be a circular argument, assuming what you
want to prove.
The equation at (♥2 ) is not an assumption at all, nor a conclusion. It is an
objective to be shown, the consequence of the implication to be established. It
is often helpful to the reader to specify a goal, and essential to the writer to
know it also, whether it is written into the proof or not. Notice that, yet again,
if you leave off the words, the proof is ruined! Since ♥2 is neither assumed nor
concluded, you may not use this statement later in the argument.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Induction Chapter | 5 101

The core of the argument is at ♥3 . The algebraic assertion at ♥4 closing the


deal is shockingly short to both those who are weak in algebra, and also to those
who glory in it. But the algebraic minutia are not the heart of this proof. The
heart is the inductive structure. At ♥5 the induction step is just completed, and,
in the notation of Definition 5.5, we have established the implication Pn ⇒ Pn+1
for the given n. At this point, we release the assumption that Pn is true, as well as
the conclusion that Pn+1 is true. Only the implication itself is held to be proved.
Now, for the final paragraph of the proof, since the implication Pn ⇒ Pn+1
was shown for any given n, we actually have ∀n : Pn ⇒ Pn+1 , and can match
that with the base case to conclude that the identity is true for all n ≥ 0 by
induction.

Another induction example


Here is an unlikely assertion: The difference between a cubic number and its
cube root is always divisible by 6. At least it seems unlikely until you try a few
small cases: 23 − 2 = 6, 33 − 3 = 24, 43 − 4 = 60, 53 − 5 = 120, and skipping
ahead, 103 − 10 = 990 = 2 · 32 · 5 · 11. Like with the cannonball identity, you
cannot check every case one by one, but you can try induction.

Proof. The base case is trivial. Suppose that n3 − n = 6k ♥0 . We need to show


that under this condition also (n + 1)3 − (n + 1) is divisible by 6. Multiplying
out we get (n + 1)3 − (n + 1) = (n3 − n) + 3(n2 + n) = 6k + 3(n2 + n) ♥1
which is clearly divisible by 3. Moreover, n2 + n must be even since n2 and n
are either both even or both odd.

Commentary: This proof is much harder to read and follow since it leaves
much of the inductive structure to the reader to fill in. It is also much harder
to write since all the aspects which have been left off must be considered and
checked by the writer. The only hint that the proof is an inductive argument is
in the sentence preceding the proof. The reader is presumed to be able in fill all
in the missing details, and most will.
The most annoying feature of this argument is that the proof refers to a vari-
able n which is not mentioned in the statement of the problem at all! It is often
the case, when composing an inductive argument, that the statement to be proved
must be recast in terms of a variable on which induction can be done. In this case
it would be pn : For all n ∈ N, n3 − n is divisible by 6.
The author leaves all the algebra to the reader, ♥2 , which is ok for some
readers, and at least makes sure that the reader knows that the equation at ♥1
is only assumed. But the reader is never alerted that the induction step is over
and the final conclusion is left off as well, so an inexperienced reader has the
impression that the proof is unexpectedly over.
But the skeleton is there, and when confronted with an argument like this, the
unconvinced reader should at least write out specifically the implication being

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


102 Discrete Mathematics With Logic

shown in the body of the argument: Pn ⇒ Pn+1 : If n3 − n is divisible by 6,


then (n + 1)3 − (n + 1) is divisible by 6.
A last bit of commentary. If you want to help out the reader by putting in
more algebra details, do not do it like this:

(n + 1)3 − (n + 1) = (n3 − n) + 3(n2 + n)


n
3
+ 3n
2
+ 3n
 +
1 −
n −
1 = n
3
−
n + 3n
2
+ 3n

0 = 0.

The problem is not that it is ugly, but that it does not show what is intended. It
shows the implication

[(n + 1)3 − (n + 1) = (n3 − n) + 3(n2 + n)] ⇒ [0 = 0],

which is trivial because the consequence is true. That implication does not show
that (n + 1)3 − (n + 1) = (n3 − n) + 3(n2 + n). Something valid in a similar
style is

(n + 1)3 − (n + 1) = n3 + 3n2 + 3n +
1 − n −
1
= (n3 − n) + 3(n2 + n)

Now that the commentary is over, here is an alternative, non-inductive proof:


The expression n3 − n = n(n2 − 1) = (n − 1)n(n + 1) is the product of three
consecutive integers. So at least one factor is divisible by 3, and at least one is
even. Hence n3 − n must be divisible by 6.
The non-inductive proof, for the reader, is simpler, more convincing, and
gives greater insight. And it proves the result for negative values of n too! For
the writer, however, this more direct argument is more difficult to come up with
in the first place. For the writer, the inductive argument is easier to make since
the implication is easier to show than just the consequence alone. That is why
an inductive proof is often the first one to appear for new results, with direct
arguments following later, each providing a different bit of insight.

Exercises
1. Rewrite both the statement and the proof of the second example in the style
of the first one.
2. Weave the following bit of algebra

(n + 1)2 − (n + 1) = n2 + 2n +
1 −
1 = (n2 − n) + 2n

into an induction proof that n2 − n is always even. Write out carefully the
statement to be proved, identify and prove the base case. Include explicitly
the implication you establish in the induction step.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Induction Chapter | 5 103

3. Suppose the predicate Pn , defined on n ∈ N, is such that P15 is true, P14 is


false, and Pn ⇒ Pn+2 for all n ∈ N.
For each of the following, decide whether it is true, false, or cannot be deter-
mined from the given information:
a) P0 , b) P4 , c) P2100 , d) P55555 .

5.5 Strong induction


Suppose we have a sequence of numbers gn defined by g0 = 1, g1 = 2, and after
that the subsequent values are computed by the formula gn+1 = gn + 6gn−1 .
This type of sequence is called recursive. We don’t have a closed formula for
gn , but any particular value can be computed by starting from the “bottom”
and working up. So the initial values of the sequence are easily computed as
1, 2, 8, 20, 68 . . . .
Let’s try to prove by induction that gn ≥ 3n .
Proof. For the base case we have to show that g0 ≥ 30 which is true since
g0 = 1.
Now, let n ≥ 0 be given and assume gn ≥ 3n . We may now compute

gn+1 = gn + gn−1 ≥ 3n + 6 · 3n−1 = 3n−1 (3 + 6) = 3n−1 · 32 = 3n+1

So gn+1 ≥ 3n+1 , concluding the induction step.


Therefore the statement is true for all n ≥ 0 by induction.
Except that it isn’t. g4 = 68, but 34 = 81. In fact, you probably noticed al-
ready that the assertion goes bad right away, since g1 = 2 which is less than 31 .
So our predicate is not true for all n. But what is wrong with the proof?
The alert reader may have noticed that the induction step used just a bit more
than the induction hypothesis, that gn ≥ 3n . We also used that gn−1 ≥ 3n−1 . This
assumption is not allowed according to induction as defined in Definition 5.5,
but actually is a common practice, sometimes called strong induction. Here is
how it works. Strong induction, in the induction step, assumes not merely that
the nth statement is true, but all the previous statements as well.
In equations:
∞   ∞  n 
  
Pn = P0 ∧ Pk ⇒ Pn+1 (5.2)
n=0 n=0 k=0

or, if you don’t want to decode all those indices,



⎫ P0 ⎪

P0 ⎬ ⎪

P0 P1
P0 , P0 ⇒ P1 , ⇒ P2 , P1 ⇒ P3 , ⇒ P4 , . . . (5.3)
P1 ⎭ P2 ⎪

P2 ⎪

P3

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


104 Discrete Mathematics With Logic

The strong induction procedure is justified exactly as the standard version.


If all the Pn ’s are true, then all the implications in Eq. (5.2) are true since the
consequences are true. On the other hand, since the base case is true, if any were
false, there would be a smallest value of n with P n+1 false,
 but that would mean
n
P0 ∧ · · · ∧ Pn is true, violating the implication k=0 Pk ⇒ Pn+1 .
So strong induction is valid. But what is wrong with the proof we started
this section with? The base case is valid, and the induction step is completely
valid too if we are allowed to assume both pn and pn−1 . And strong induction
grants you that assumption for all n except n = 0, where you have to show that
P0 ⇒ P1 . That is the problem. The argument for the induction step considers
gn+1 = gn + gn−1 , but there is no gn−1 for n = 0. We need there a special
argument for n = 0, the first implication to be shown, and it turns out there isn’t
one because the result is false. But the rest is perfectly valid reasoning, and can
be reused in a slightly different example, in which the induction step for n = 0
actually works.
Theorem 5.7. Let hn defined by h0 = 1 and h1 = 4 with hn+1 = hn + 6hn−1 .
Then hn ≥ 3n for all n.
Proof. The base cases are that h0 = 1 ≥ 30 and h1 = 4 ≥ 31 = 3, which are both
true.
Now, let n ≥ 1 be given and assume hk ≥ 3k for all 0 ≤ k ≤ n. We want to
show hn+1 ≥ 3n+1 . We may now compute

hn+1 = hn + hn−1 ≥ 3n + 6 · 3n−1 = 3n−1 (3 + 6) = 3n−1 · 32 = 3n+1 ,

so hn+1 ≥ 3n+1 , concluding the induction step.


Therefore the statement is true for all n ≥ 0 by (strong) induction.
Notice that the n = 0 instance of the induction step was folded into the base
case, which reads clearer.
Most people using the method of Eq. (5.2) will label their argument an “in-
duction”, rather than “strong induction”. As we have seen, both methods are
equally valid in the sense that any result provable under one method, can be
proved, under the other, with at most a variation in how the statement is phrased
and indexed. The moral is not to pick one over the other, but to use the one
which is convenient to the task.

Exercises

 you can show Pn is true for all n ≥ 0 by strong induction.


1. Suppose
Show nk=0 Pk is true for all n ≥ 0 by ordinary induction.
2. Let the recursive sequence gn be defined by g0 = 1, g1 = 3 and satisfying
gn+1 = 3gn − 2gn−1 for all n ≥ 1. Show that gn ≤ 2n+1 for all n ≥ 0.
3. Let the recursive sequence hn be defined by h0 = 2, h1 = 3 and satisfying
hn+1 = 3hn − 2hn−1 for all n ≥ 1. Show that hn = 2n+1 + 1 for all n ≥ 0.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Induction Chapter | 5 105

5.6 Sets versus logic


If you have been reading this text from the beginning, you certainly must have
the feeling that you have done the same thing twice. It’s déjà vu all over again.
When sets were introduced, we had the notion of well-definition, based on
the dichotomy of membership. The key set operations, union, intersection, and
complement were introduced. Those operations were connected by identities.
Those identities were established using the double inclusion method, and that
method was based on the essential ⊆.
But later we considered formal logic, with the dichotomy of TRUE/FALSE
and operations AND, OR, and NOT. Virtually the same identities were es-
tablished with the double implication method, and that method relied on the
tricky ⇒.
Looked at side by side, it is hard to avoid having the idea that logic and sets
are just “the same thing”. But, on the other hand, they have a different history,
and different notation. Operationally, they seem identical, but conceptionally the
subjects are very different. With sets we are considering objects. Linguistically
sets and their members are nouns – things we can imagine touching and holding.
In set theory we are collecting, distinguishing, arranging, and ordering. With
logic, we seem to be in a more abstract, higher realm. In logic we are discussing
the truth and falsity of ideas. We feel we are are evaluating, speculating, and
judging.
With formal logic, the two subjects, set theory and logic, seem to live in two
similar but separate spheres. They seem merely to behave with analogous rules,
like baseball and cricket.
With predicate logic, however, we can finally illustrate how, actually, these
subjects are connected. Consider predicate logic with predicates defined over
the natural numbers. In other words, Boolean functions defined on the set N.
Each such Boolean function assigns a value of 0 or 1 to each of the elements of
N and we can imagine the graph of that function as a sequence of 0’s and 0. The
graph for the predicate n ≤ 10 would be

1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

and isn’t that just how we would write the bit vector for the set {n ∈ N | n ≤ 10}.
That is the connection. Predicate logic, with the predicates confined to the natu-
ral numbers, is equivalent to Boolean functions defined on the natural numbers.
That in turn is directly linked by the bit vectors to sets defined on the universe
U = N. Here we really can completely link ∪ and ∨, ∩ and ∧, (−)c and ¬, and
mostly importantly, ⊆ and ⇒.
Yes, the subjects are different in total, but with the correct restrictions, they
are exactly the same.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


106 Discrete Mathematics With Logic

Exercises
1. Write the set whose bit vector corresponds to the predicate (n < 4) ∧ (n = 2)
for n ∈ D.
2. Consider the true implication, “If n is prime and n is even, then n = 2”. Try
to express this using set theory alone.
3. Consider the set X = {n ∈ N | n = 5k + 1; k ∈ N}. Re-express it as a Boolean
function.

5.7 Case study: Decoding the Gray code


The case study of Section 3.9 introduced Gray code gn gn−1 · · · g1 g0 of the bi-
nary number with bits bn bn−1 · · · b1 b0 . It is given by the formula

0 if bk = bk+1
gk =
1 if bk = bk+1

Note that we naturally take bn+1 = 0. An alternative, if you want to interpret the
0 and 1 as FALSE and TRUE, is to write gk := [bk = bk+1 ]. Either formulation
allows us to find the bits of the Gray code.
What if we wanted to reverse the process and determine from gn gn−1 · · · g1 g0
which ordinal it had, in other words, how many bit vectors are ahead of it in the
Gray code order. It is natural to look for a formula for n in terms of its binary
bits, bj , and a bit of trial and error would take you to the following:
Theorem 5.8. bk = 0 if the number of 1’s in the sequence gk , gk+1 , gk+2 , . . . is
even, and bk = 1 otherwise.
Let’s do a quick check. Start with 1776 in binary, 11011110000, and translate
to the Gray code using gk := [bk = bk+1 ], giving 10110001000. Now, following
the reverse procedure of Theorem 5.8, move from left to right recording at each
bit the number of 1’s encountered so far, which gives 11233334444, and then
using 0 and 1 to record even versus odd returns us to 11011110000 as predicted.
The actual proof of the theorem is by induction, but in this case it is a back-
wards induction, starting from the nth bit, and proceeding to the 0th. Of course,
we may use in the proof the relation we already have between the bits in the
Gray code gk and the binary bits bk , namely that gk := [bk = bk+1 ].
Proof. Base case: For the nth bit of an n digit binary number, or n digit Gray
code, the nth bits correspond, and the claim is true in this case.
Induction step. Let k be given, n ≥ k > 0, and suppose bk satisfies the claim.
There are four cases for the pair bk and bk−1 .
If bk = bk−1 = 0 or bk = bk−1 = 1 then it follows that gk−1 = 0, and the
number of 1’s in the sequence gk , gk+1 , gk+2 , . . . is exactly the same as in
gk−1 , gk , gk+1 , gk+2 , . . ., and bk−1 = bk correctly records whether that number
is even or odd by the induction hypothesis.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Induction Chapter | 5 107

On the other hand, if bk = bk−1 , then gk−1 = 1, and the number of 1’s
in the sequence gk , gk+1 , gk+2 , . . . is exactly one fewer than that in gk−1 , gk ,
gk+1 , gk+2 , . . ., since bk correctly measured the evenness of the number of ones
in the first sequence by the induction hypothesis and bk−1 = bk , bk−1 correctly
measures the parity of the number of 1’s in the second.

There is a fast direct proof which uses some number theory but even that one
requires care. Here there are two different binary strings and an index set to be
kept in line, together with the inductive variable, so you should not be surprised
if you need to read it through more than once to get the complete picture.

5.8 Case study: The 14–15 puzzle


We know that it is often important to distinguish between even and odd numbers.
It turns out that permutations also come in two distinct types, also called even
and odd. Even or oddness of a string of distinct characters depends on whether
the number of pairs of characters in the string that are out of order is even or
odd.

Definition 5.9. Given a permutation σ = σ1 σ2 . . . σn of the ordered set x1 <


x2 < · · · xn , we say σ is even if the number of pairs (i, j ) with i < j but σi > σj
is even. Otherwise σ is said to be odd. ♠

So for example abcde is even because  all pairs are in order. For edcba all
pairs are out of order, but there are 52 = 10 of them, so edcba is also even. Re-

versing four characters dcba is also even since the 42 = 6 is even, but f edcba
6
is odd because 2 is 15. The number of out of order pairs is called the inversion
number of the permutation. In general it can be computed by counting, for each
character, how many characters to the right of it precede it in the ordering on
the set. So for bcedf ga we have 1 + 1 + 2 + 1 + 1 + 1 + 0 = 7 which tells
us it is an odd permutation. You may recognize the numbers in the sum since
we computed exactly the same values to determine that bcedf ga had exactly
1 · 6! + 1 · 5! + 2 · 4! + 1 · 3! + 1 · 2! + 1 · 1! + 0 · 0! permutations ahead of it in
lexicographic order.
There is a key observation about the evenness of permutations, which we
may prove by induction, which involves transposing pairs in a string. Transpos-
ing two characters in permutations exchanges their positions. So transposing 3
and 5 in 6234157 gives the permutation 6254137. Of course, if you transpose a
pair twice, you return to the original.

Theorem 5.10. Given any permutation, transposing any two characters trans-
forms the permutation from even to odd, or vice versa.

Proof. Suppose we have a permutation σ of n characters. We will do induction


on how far apart the characters being transposed are.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


108 Discrete Mathematics With Logic

Base case. If the characters transposed are next to one another, then trans-
posing them puts them in order if they were out of order, and puts them out of
order if they were in order. Other than that, all other pairs have the same relative
position and have the same order type they had before. Thus the total number of
misordered pairs is changed by exactly one, and the inversion number is changed
from even to odd, or the reverse.
Induction step. Let k be given and suppose the result is true for all transpo-
sitions separated by k characters. Suppose the pair σi and σj are separated by
k + 1 characters. Then the permutation σ can be written σ = Xσi Y σm σj Z with
the string Y having k characters. Make the following three transpositions:

Xσi Y σm σj z → Xσm Y σi σj z → Xσm Y σj σi z → Xσj Y σm σi Z.

Each transposition switches the evenness/oddness of the inversion number, ei-


ther due to the base case or the induction hypothesis. So, having been switched
three times, if the permutation was odd it is now even, and vice versa.
Thus the result holds for all transpositions of σ by induction.
It is not hard to see, and there is an easy proof by induction, that every
permutation can be obtained by a sequence of transpositions. A similar argument
shows that it is possible to do the job in at most n − 1 transpositions. Try it.
Since every permutation can be made just using transpositions, and since the
start is the even permutation of all the characters in the correct order, we have
an alternate way of viewing the evenness and oddness of a permutation.
Theorem 5.11. Every permutation is even or odd depending on whether the
number of transpositions needed to express it is even or odd.
A more dramatic way of saying this is to notice that every permutation can
either be created using an even number of transpositions, or an odd number of
transpositions, but never both. Most people find this result quite strange, even if
they can follow the proof.
In the 14–15 puzzle, Sam Loyd, the puzzle master of the 1800’s made cu-
rious device with 15 sliding numbered squares and one blank, held loosely in
a 4 × 4 frame. Because of the blank, it was possible to slide the pieces about
and achieve many permutations of the original configuration of numbers. Loyd
offered a large cash prize to anyone who could take the puzzle from the initial
state in which he sold it, with the numbered squares in order except that the final
squares 14 and 15 were transposed, to a completely ordered state. See Fig. 5.1.
Loyd knew that he was asking the solver to effect an odd permutation of the
squares. He also knew that every move the solver made was to transpose the
blank with some actual tile. Also, he knew that if the blank was to return to its
original position, no matter what happened, the number of times it moved up
had to match exactly the number of times it moved down, and the number of
times it moved to the left had to match the number of times it moved back to the
right. So the only way to return the blank to its original position was through

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Induction Chapter | 5 109

FIGURE 5.1 Sam Loyd’s 14–15 puzzle. Initial position on the left.

an even number of transpositions. Loyd knew not only that it was impossible
for anybody to ever be able to bring the squares into order and collect the prize
money, but also that very few people would be able to understand why it was
impossible and why they were failing over and over and over.
It is easy to find inexpensive plastic versions of the sliding squares mecha-
nism, but they are always sold with the squares in the proper order, with the idea
that children can amuse themselves by disordering and reordering the squares.
If you want to use one of these toys but achieve the same feeling of frustration
that Loyd’s contestants did, then try to return the blank to the original position
with
15 the squares in reverse order. That is an odd permutation of the squares since
2 = 105.

5.9 Case study: Towers of Hanoi


In the previous case study on the Towers of Hanoi we used the multiplicative
principle to conclude that, for 7 disks, there are 37 legal states. If we label the
three posts, left to right, as 0 for hell, 1 for earth, and 2 for heaven, then the states
correspond to the 7 digit numbers in base three, see Fig. 5.2. Let’s consider one
of the key problems: is it possible to move all the disks from hell, state 0000000,
to heaven, state 2222222, and if so, in how many moves?

FIGURE 5.2 The Towers of Hanoi with 7 disks in states 0000000 and 2100212.

Counterintuitively, one way to simplify the problem is to expand the setup to


include versions with the number disks not restricted to seven. In other words, to
consider the same problem, still with three posts, but with d disks, d ∈ N. While
this expands the range of possibilities, it allows for an inductive approach.
Now it takes just a few seconds to determine that you can solve the problem
with 1 disk in 1 move, and the problem with 2 disks in 3 moves. Since there are
three posts, you might expect that three disks will require 9 moves, and indeed
it can be done in 9 moves, but you can also do it in only 7. Not much of a saving
– or is it?


This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


110 Discrete Mathematics With Logic

If you have paused to come up with a formula on your own, you probably got
the formula 2d − 1, and that is what we will prove.

Theorem 5.12. In the d-disk Towers of Hanoi problem, the disks may be moved
from state 0 to state 3d − 1 in at most 2d − 1 moves.

Note that, since the states are encoded with ternary numbers, state 3d − 1
has all d disks on post 2, and state 0 has all d disks on post 0. As expected, the
proof is by induction on d, and the base case will be d = 1. (Even though the
formula sort of works for d = 0 too.)

Proof. For d = 1, the disk is unrestricted and can be moved from hell to heaven
in one move.
Let d be given and suppose the theorem is true for d disks. We want to
show that a tower of d + 1 disks can be moved in at most 2d+1 − 1 moves.
Temporarily swapping the labels on posts 1 and 2, the induction hypothesis says
that we can move the top d disks from hell to earth in at most 2d − 1 moves.
Now the bottom disk is free to be moved to heaven, where it can stay for the
remainder of the procedure without violating any rules. Then, relabeling posts 1
and 0, the induction hypothesis allows us to move the d disks on earth to heaven
in at most another 2d − 1 moves. See Fig. 5.3.

FIGURE 5.3 a → b: 2d − 1 moves. b → c: 1 move. c → d: 2d − 1 moves.

Altogether we have taken at most (2d − 1) + 1 + (2d − 1) = 2 · 2d − 1 =


2d+1 − 1, as required.
So the theorem is true for all d ≥ 1.

Virtually the same proof, and the same figure, proves the following compan-
ion observation. This is a tribute to the power of the inductive method, which,
with a little care, can leverage many results from one very small insight.

Theorem 5.13. In the d-disk Towers of Hanoi problem, the disks cannot be
moved from state 0 to state 3d − 1 in fewer than 2d − 1 moves.

Try to write out the proof. You just need to modify the words in the first
proof, leaving all the equations and variables right where they are. These two
theorems work together to tell us that the optimal solution takes exactly 2d − 1
moves.
Can you show it is the unique optimal solution?

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Induction Chapter | 5 111

So, what if we start in some other legal position? Here is an informal induc-
tion that we can again stack everything on post 0 in at most 2d − 1 moves. The
base case is trivial. Assume it works for d disks, and suppose we have a legal
position with d + 1 disks. If the largest disk is on post 2, leave it there, and we
can move the remaining disks on top of it in at most 2d − 1 moves by the induc-
tion hypothesis, and 2d − 1 < 2d+1 − 1. If the largest disk is not on post 2 then,
by the induction hypothesis, we can move all the other disks legally on the other
post, not 2 and not the one containing the largest disk. Then move the largest
disk onto post 2, and use the induction hypothesis again to pile the smaller disks
on top of it, altogether a total of, at most, (2d − 1) + 1 + (2d − 1) = 2d+1 − 1
moves.
This is essentially the same argument again! Now, what if the disks are
stacked illegally, say an evil Genie randomly dropped the disks on the posts
regardless of the rules, but we still want to move them to heaven using only
legal moves. Can it be done? How quickly?
Here is a completely different question. For d = 7, the fraction of legal states
used in the optimal solution is (2/3)7 , less than 6% of the states. How do we
recognize the states in the optimal solution? Or, given a state, what is the best
move to make? How many problems can be solved by just tweaking the original
inductive proof? There are so many interesting questions one can ask.

5.10 Case study: The Fibonacci numbers


The recursive sequences in Section 5.5 might have reminded you of the Fi-
bonacci sequence. The sequence is thought of as being generated by the monthly
population of mathematical rabbits whose numbers are strictly governed by the
following simple rule: Each month, every pair of rabbits which is at least one
month old mates and generates a pair of leverets (baby rabbits) one month later.
Since the rabbits have no predators, in fact are presumed to be immortal and
require no food, the population grows and grows. At month 0 the population
is zero, but at month 1 the first pair of leverets arrive (by mail order) and the
process begins.
By the rule, the number of pairs of leverets produced at the end of month
n + 1 is equal to the number of pairs of rabbits mating during month n, which
is the same as the number of pairs existing in month n − 1. Also, the number of
pairs of adult rabbits in month n + 1 is equal to the number of pairs of rabbits
of any kind existing in month n. Adding these gives the total number of pairs
alive in month n + 1. Letting fn be the number of pairs of rabbits in month n,
the situation is summarized in the following recursive definition.

Definition 5.14. The Fibonacci sequence is obtained recursively from the equa-
tions

f0 = 0, f1 = 1, fn+1 = fn + fn−1 . ♠

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


112 Discrete Mathematics With Logic

The sequence starts innocently enough, and at the end of six months the
number of pairs is still in the single digits, but after only two years there are
almost fifty thousand pairs:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377,


610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368 . . .

The growth looks exponential, and that is one way of analyzing the behavior. In
any case, the growth depends on the fraction of the population which is at least
one month old, fn−1 /fn , which, after the first few months have passed, seems
to be about 2/3, and is at least 1/2.
Theorem 5.15. For n ≥ 2, fn−1 /fn ≥ 1/2.
Of course we prove this by induction.
Proof. Base case: If n = 2 then f1 /f2 = 1/2, which is spot on, and for n = 3,
then f2 /f3 = 2/3 ≥ 1/2.
Induction step: Let n ≥ 3 be given and assume fn−1 /fn ≥ 1/2 and
fn−2 /fn−1 ≥ 1/2. Rearranging the inequalities gives fn ≤ 2fn−1 and fn−1 ≤
2fn−2 , and adding these gives fn + fn−1 ≤ 2fn−1 + 2fn−2 , or fn+1 ≤ 2fn
using the recursive formula. Thus fn /fn+1 ≥ 1/2, as required.
So the theorem is proved by induction.
You should check that the inductive argument is correct, that the base cases
are correct and fit together with the strong induction step.
By the theorem, for months beyond 2, the next month’s rabbits will be at
least the current month’s rabbits, plus the number of leverets born to at least
half the population, altogether at least 1 + 1/2 = 3/2 of the current population.
This gives an exponential lower bound on the Fibonacci sequence:

fn+2 ≥ f2 (3/2)n .

Perhaps one of the most surprising results about the Fibonacci numbers is
the equation
√ √
(1 + 5)n − (1 − 5)n
fn = √ (5.4)
2n 5
The proof by induction just follows the model above, but it takes persistence
and there is some tricky algebra. Even if you get through the proof, the result
still looks quite mad. Only the cases n = 0 and n = 1 seem easy to verify. Still,
it is a good exercise to verify that
√ √
(1 + 5)5 − (1 − 5)5
f5 = 5 = √
25 5
using the Binomial Theorem. And, if you really like algebra, you can try to find
a direct non-inductive proof of Eq. (5.4) using only the Binomial Theorem.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Induction Chapter | 5 113

5.11 Summary exercises


You should have learned about:
• Predicates and Boolean functions on general sets.
• Quantification of Predicates, and Evaluations of Boolean functions.
• Universal and Existential Quantification.
• What are the requirements of an induction proof.
• Why an induction proof is valid.
• The requirements of a strong induction proof.
• Why a strong induction proof is valid.
• How to write a simple induction proof.
• How to follow an argument that is based on induction.

1. Let P (n) be the predicate nk=0 k 2 = n(n+1)(2n+1)
6 . Show each of the fol-
lowing:
a) ∃n ∈ N; P (n), b) P (10) ⇒ P (11), c) P (22) ⇒ P (11).
[Hint: You can show all three by checking the validity of P (n) for a single
value n ∈ N, and it is not n = 0.]  
2. For n ∈ N, let An be a set and let Pn be the predicate “|An | < 3n+1
n+1 ”.
Write out each of the following:
a) P0 b) P9 c) Pn ∧ Pn+2 d)Pn ⇒ Pn+1 .
3. Suppose you wanted to prove that nk=1 (2k − 1) = n2 .
Identify the inductive variable.
What is the base case?
What implication would you have to show for the induction step?
4. Suppose pn and qn are predicates defined for all n ≥ 0, and you wanted to
show ∀n ∈ N; (pn2 +1 ∨ q2n ) by induction.
What would you have to show for the base case?
What would you have to show for the induction step?
What would be the induction hypothesis?
5. Let P (n) be a predicate defined on the natural numbers.
Suppose ∀n ∈ N; [P (n) ⇒ P (n + 1)] and suppose P (10) is false, P (100)
is false and P (1000) is true. Label each of the following T if it must be
true, F if it must be false, and X if it cannot be certainly concluded. Give
a word of explanation:
P (15), P (150), P (1500), P (1776).
6. (pn ⇒ pn+2 ) ∧ (pn ⇒ pn+3 ). What can we conclude by induction? Why?
7. Suppose p0 is true and that for all n ∈ N, we have (pn ⇒ pn+5 ) ∧ (pn ⇒
pn+11 ). What can we conclude by induction? Why?
8. Suppose p0 and ∀n ≥ 1; [(pn ⇒ pn+1 ) ∨ (pn−1 ⇒ pn+1 )]. Which pn can
we conclude are true? Why?
9. Suppose you have a predicate pn for n ∈ N. Suppose that p0 is true and
suppose that, for all n ≥ 0, we have pn ⇒ (pn+1 ∨ pn+2 ∨ pn+3 ).
Prove by induction that pn ∨ pn+1 ∨ pn+2 is true for all n.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


114 Discrete Mathematics With Logic

10. Let e0 = 1 and e1 = 3, and define en+1 = 5en − 6en−1 for n ≥ 1. Prove
en = 3n for all n ≥ 0.
11. Let e0 = 0 and e1 = 1, and define en+1 = 5en − 6en−1 for n ≥ 1. Prove
en = 3n − 2n for all n ≥ 0.
12. Let the recursive sequence gn be defined by g0 = 2, g1 = 5 and satisfying
gn+1 = gn + 6gn−1 for all n ≥ 1. Show that for all n ≥ 0, the formula
gn = [3n+2 + (−2)n ]/5 is valid.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Chapter 6

Set structures
6.1 Relations
With mathematical sets to describe our objects of interest, and predicate logic
to communicate what is true about them, we can now be said to have reached
a critical juncture in our study of discrete mathematics, “this is not the end,
this is not even the beginning of the end, this is just perhaps the end of the
beginning”. From here one can see, stretching out in many directions and with
much intertwining, the many and various branches of discrete mathematics. But
wherever you travel, logic and sets will be the underpinning.
This chapter is the introduction to a huge area of set structures, in which
sets and their elements are not just to be thought of in isolation, but in con-
cert with other sets. There are many forms of set structures; a vast array of data
structures, algebraic structures, combinatorial structures, geometrical and topo-
logical structures, only a few of which we will touch upon. We have already
seen several set structures, such as strings and bit vectors, both data structures.
Those are key examples because they illustrate the two most common ways of
building set structures – via subsets and via the Cartesian product.
In this chapter we will concentrate on relations, arguably the most basic ex-
ample. ‘Set structure’ is an idea, like discreteness, but in mathematics “relation”
is not the vague term which floats about in natural language, it has a set mathe-
matical definition, which you must learn.

Definition 6.1. A (binary) relation, R, between sets A and B is a subset R ⊆


A × B. If (a, b) ∈ R then we say a is related to b by R. ♠

That seems very innocent, but it is surprisingly powerful. If you are program-
ming a chess game, then you have many sets of interest, certainly the pieces P
and the set of squares S. The most basic relation would be the board relation
B ⊂ P × S with the elements of B being those pairs (p, s) for which piece p is
currently on square s.
Here is a more mathematical example:

L = {(n, m) ∈ Z × Z | n < m}

So 3 is related to 5 but 5 is not related to 3 by L. You should recognize this


relation as “less than”. A relation which becomes established over time is usu-
ally not notated as a set, but acquires a special symbol, in this case <. One

Discrete Mathematics With Logic. [Link] 115


Copyright © 2024 Elsevier Inc. All rights reserved.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


116 Discrete Mathematics With Logic

also commonly writes 2L18 or 2 < 18, with the symbol infix, instead of writing
(2, 18) ∈ L or the, admittedly ugly, (2, 18) ∈ <. Many of the common math-
ematical symbols you know, ∈, ⊆, =, etc. are examples of relations, and are
usually written in infix notation.
Another common notation, which is particularly valuable for small sets, is
the relation diagram: You place a labeled point for each element a ∈ A, and for
each element b ∈ B, and draw an arrow between the points associated with a
and b if a is related to b by R, that is if (a, b) ∈ R, that is, if aRb.

Example 6.2. In Fig. 6.1 we have a set of four common household ingredients
and a set of four recipes in which they are used, and the diagram defines a
relation U . So we have that (eggs, treacle) ∈
/ U , but milkU ice cream. For small
sets it is not hard to make a diagram which is far easier to understand than listing
the elements in the relation set. ♦

FIGURE 6.1 A relation graph.

The same relational information may be conveyed by (a, b) ∈ R (set the-


oretic), a is related to b by R (textural), aRb (infix), and the diagrammatic
a b
notation may even be used in a paragraph, like •−→• (diagrammatic).
Relations are used so widely they come in many special forms. In the rest of
this chapter we consider various special types of relations.

Exercises
1. Let R ⊆ A × D be the relation between the set A of letters and the set D of
digits by setting aRd if the letter a occurs in the spelling of the English word
for the digit d.
Draw the relation diagram for R.
2. Let ♥ be the relation between P3 ({0, 1, 2, 3, 4}) and P2 ({2, 4, 6, 8}) by set-
ting A♥B if two elements of A sum to an element of B. Draw the relation
diagram of ♥.
3. Consider all relations between the set X = {2, 4, 8} and itself. How many
relations do not have any element related to itself?

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Set structures Chapter | 6 117

6.2 Functional relations


Definition 6.3. A relation F ⊆ D × T is said to be functional if D = ∅ and for
each element d ∈ D there exists exactly one element t ∈ T to which it is related.
The set D is called the domain set, and the set T is called the target set. ♠
The relation diagrams of functional relations have the property that there is
exactly one outgoing arrow from each element of the domain set. There is no
condition on the incoming arrows to the target set. In Fig. 6.2 the third relation
is not functional because domain element d3 is unrelated, and the fourth relation
is non-functional because the domain element d2 is trebly related.

FIGURE 6.2 Four relations, two functional and two non-functional.

If the relation F ⊆ D × T is functional, it is often called simply a function,


and the notation F : D → T is used to specify the domain and target sets. Also,
the functional restriction, focusing so much attention on the domain side, gives
rise to two other notations for the related elements. If (d, t) ∈ F , then we write
F (d) = t in the operator notation and Fd = t in the subscript notation.
The operator notation is by far the most common notation for functional
relations (functions) as found in high school algebra, pre-calculus, and calcu-
lus. Please note, functions in high school and calculus are almost always given
by an algebraic expression, which is hugely important there, while the specific
domain and target sets are usually of secondary importance. In discrete mathe-
matics, most of our functional relations are not given by formulas or algebraic
expressions, and the domain and target sets are often the main objects of interest.
In particular, the functional definition above, and the definitions of one-to-one
and onto which you find below, cannot be glossed over in discrete mathematics.
The successful student must attend to their precise definitions.
The notions of one-to-one and onto arise from applying the two aspects of
the functional relation condition to the target set, rather than the domain.
Definition 6.4. A functional relation F ⊆ D × T is said to be onto if for each
element t ∈ T there exists at least one element d ∈ D to which it is related.
A functional relation F ⊆ D × T is said to be one-to-one if for each element
t ∈ T there exists at most one element d ∈ D to which it is related.
A functional relation F ⊆ D × T is said to be one-to-one and onto if for
each element t ∈ T there exists exactly one element d ∈ D to which it is related.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


118 Discrete Mathematics With Logic

Note that these notions are only defined for functional relations. In Fig. 6.3
we see the diagrammatic features of the one-to-one and onto functional rela-
tions. The onto relation has at least one incoming arrow at each target node,
and the arrows of the one-to-one diagram are all completely separated from one
another.

FIGURE 6.3 Four functional relations, one onto, and one one-to-one.

Example 6.5. For the set of pieces in play in the game of chess, the relation
between those pieces and the 82 positions they can occupy on the board is func-
tional, because each piece occupies exactly one square on the board. The relation
is also one to one because each square on the board can have at most one piece.
The relation is not onto, because, no matter the configuration, there are sixty-
four positions and at most thirty-two pieces in play. So there will always be
target positions without pieces.
The relation between the pieces in play and the colors black and white, indi-
cating to which side the piece belongs, is also functional. Each piece is assigned
exactly one of the two colors. The relation is also onto since the two kings,
one of each color, are never removed from the board, so both target colors are
represented. The only way for the relation to be one-to-one is in a stalemate
configuration with only the two kings, one of each color.
If the positional relation is expanded to the whole set of 32 chess pieces, the
positional relation will often fail to be functional. As soon as a piece is captured,
that piece is removed from the board and so has no position related to it. (If a
competing chess analyst insists on a functional relationship, he may define a
special 65th position, off the board, to act as the “graveyard” for the captured
pieces.) ♦
The obvious cardinality conditions mentioned in the example occur quite
often, and are stated here as a theorem.
Theorem 6.6. Let D and T be finite sets. If |D| > |T |, then there can be no
one-to-one function f : D → T . If |D| < |T |, then there can be no onto function
g :D →T.

Exercises
1. Define a relation on Z × Z which has no element related to itself, and is not
functional.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Set structures Chapter | 6 119

2. Define an onto function g : P(N) → N.


Is your function one-to-one?
3. Define a function z : N → N × N by setting z(n) = (a, b) with a the number
obtained by deleting the digits in the even positions of the decimal repre-
sentation of n, and b the number obtained by deleting the digits in the odd
positions of the decimal representation of n. So z(5280) = (58, 20).
Is the function z onto? Is the function z one-to-one? (Hey! – Is it a function?)

6.3 Counting functions on finite sets


In Example 6.5 we saw that whether a relation is functional or not depends not
just on the nature of the relationship between the elements, but exactly which
sets are considered to be related. In this section we count the number of func-
tions of each type that can exist between a finite domain, and a finite target.
All sets in this section are finite.

Theorem 6.7. Let D and T be finite sets. The number of functions with domain
D and target T is |T ||D| .
|T |!
Of those, if |D| ≤ |T |, there will be one-to-one functions.
(|T | − |D|)!
|T |  
k |T |
If |D| ≥ |T |, then (−1) (|T | − k)|D| functions will be onto.
k
k=0
If |D| = |T |, then |D|! = |T |! will be both one-to-one and onto.

The results for general functions and the one-to-one functions are an easy
consequence of the multiplicative principle, choosing target elements for each
domain element, using straight independence for general functions, and weak
independence for one-to-one.
For a function that is both one-to-one and onto, we must have that |D| = |T |,
and |T |!/(|T | − |D|)! = |T |!. In this case we also have the following special
situation, whose proof is left as an exercise.

Theorem 6.8. For finite sets with |D| = |T |. Every one-to-one function is also
onto, and every onto function is also one-to-one.

It is a common error to misread this; the theorem does not say that, if |D| =
|T |, then all functions are one-to-one and onto. The only case where all functions
are one-to-one is |D| = 1, and the only case where all functions are onto is
|T | = 1.
Counting the number of onto functions has been left for last, because that
is the hardest case. Let us compute the number of non-onto functions by inclu-
sion/exclusion. Let t ∈ T and define Ft to be set of all functions D → T for
which the target element t is unrelated.
 The set we want to count, the set of
non-onto functions, is the union t∈T Ft and inclusion/exclusion gives, taking

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


120 Discrete Mathematics With Logic

T = {1, 2, 3, . . . , n} for simplicity.


 
 
 
 Ft  = |F1 | + |F2 | + · · · + |Fn |
 
t∈T
− |F1 ∩ F2 | − |F1 ∩ F3 | − · · · − |Fn−1 ∩ Fn |
+ |F1 ∩ F2 ∩ F3 | + |F1 ∩ F2 ∩ F4 | − · · · + |Fn−2 ∩ Fn−1 ∩ Fn |
..
.
+ (−1)n−1 |F1 ∩ F2 ∩ · · · ∩ Fn |

The k-fold intersection terms, like |F1 ∩ F2 ∩ . . . ∩ Fk |, count the functions


|D|
n k elements from the target. Each has cardinality (|T | − k) , and
which omit
there are k such terms, so for the k-fold terms we are altogether including or

excluding (|T | − k)|D| nk . This justifies the last formula of Theorem 6.7.
Example 6.9. Consider the two sets A = {1, 2, 3, 4} and B = {a, b, c, d, e}.
There are 54 functions with domain A and target B, and 45 functions with do-
main B and target A.
There are 5! one-to-one functions with domain A and target B, and no onto
functions.
There are
1 · 4 5 − 4 · 35 + 6 · 25 − 4 · 15 + 1 · 05
onto functions with domain B and target A, and no one-to-one functions. ♦

Exercises
1. Let A = {1, 2, 3, 4, 5} and B = {a, b, c, d}.
How many functions are there from P2 (A) to P2 (B)?
How many are one-to-one?
How many are onto?
How many are one-to-one and onto?
2. How many functions are there with domain and target both P(P(P(∅)))?
How many are one-to-one?
How many are onto?
How many are one-to-one and onto?
3. Let A = {a, b, c, d, e}, and B = {1, 10, 100, 1000}. How many functions are
there from B × B to A × A which are one-to-one but not onto?

6.4 Working with functional relations


The functional condition is often split into two aspects,

∀d ∈ D;∃t ∈ T ; (d, t) ∈ f, (6.1)

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Set structures Chapter | 6 121

∀d ∈ D; [((d, t) ∈ f ) ∧ ((d, t  ) ∈ f )] =⇒ (t = t  ) , (6.2)

the existence of the related target element, Eq. (6.1) and the uniqueness of the
related target element, Eq. (6.2).
These conditions, with domain and target reversed, are the conditions for
one-to-one and onto. A function f : D → T is one-to-one if

∀t ∈ T ; [((d, t) ∈ f ) ∧ ((d  , t) ∈ f )] =⇒ (d = d  ) , (6.3)

and the function f is onto if

∀t ∈ T ;∃d ∈ D; (d, t) ∈ f. (6.4)

So, to properly understand how to work with these definitions, it is enough to


understand how the last two work.
To show a function is onto, that is to show that Condition (6.3) is true: Let
the target element be given, show it is related to some domain element.
To show a function is not onto: Exhibit any target element not related to a
domain element.

Example 6.10. Let f : P(D) → D be defined by relating each non-empty set


A ⊆ D to be the smallest element in A. So f ({3, 4, 5}) = 3. In order for f to be
functional, a value must be assigned to ∅, so define f (∅) = 0.
To show f is onto, let n ∈ D be given, then f ({n}) = n. Note that we only
have to produce one element of the domain whose function value is the gen-
eral target digit n. For the onto question we don’t to consider whether there are
others. Of course, there may be many other quite different but valid arguments.

Example 6.11. Let g : D → P(D) be defined by mapping each digit d to the


set of even digits if d is even and to the set of odd digits if d is odd. Con-
vince yourself that g is a function. It is neither one-to-one nor onto. Since
the cardinality of the target set is larger than the cardinality of the domain,
g cannot be onto. On the other hand, g is not one-to-one, because g(1) =
g(3) = g(5) = g(7) = g(9) = {1, 3, 5, 7, 9}. It is equally valid to note only that
g(2) = g(4) = {0, 2, 4, 6, 8}. ♦

To show a function is one-to-one: Let two domain elements be given with the
same target, f (d) = f (d  ), and show those two domain elements must coincide,
d = d .
To show a function is not one-to-one: Exhibit any pair of distinct domain
elements which are related to the same target element.
Neither of the previous examples were one-to-one. For f , we have the
violating pair f ({1}) = f ({1, 2, 3}) = 1. For g, we can take g(1) = g(3) =
{1, 3, 5, 7, 9}.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


122 Discrete Mathematics With Logic

Example 6.12. Let h : D → P(D) be defined by h(d) = {0, 1, . . . , d}. So h(0) =


{0} and h(9) = D. The function h is not onto since no digit is related to {1}.
Indeed, 0 ∈ h(d) for all digits d.
To show h is one-to-one, let h(d) = h(d  ) be given. So {0, 1, 2, . . . , d} =
{0, 1, 2, . . . , d  } and, since the sets have the same largest elements, d = d  , as
required. ♦

Exercises
1. Let D = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}. Define a function

h : P8 (D) → P2 (D)

by setting h(X) to be the subset consisting of the largest and smallest ele-
ments of X. So h({0, 1, 2, 3, 4, 5, 6, 7}) = {0, 7}.
Show that h is not onto.
Define any onto function, g, from P8 (D) → P2 (D).
2. For the function h of the previous exercise, show that h is not one-to-one.
3. Let D = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}. Define a function f : P(D) → N by set-
ting f (∅) = 0 and f (A) to be the number of different numbers which can
be expressed in some base b, with 1 < b ≤ 10 using the digits in A, each at
most twice.
So, for f ({1, 2}), we would consider numbers like 2 or 22 or 1212 all in base
10, or 5 in base 3, 5 = 123 , or 10 in base 8, 10 = 128 , 56 = 2115 , etc.
Show that f is not onto.

6.5 Functions on infinite sets†


Working with functions on infinite sets is in many ways similar to the finite case.

Example 6.13. Let the function f : Z → N be defined by

2n n>0
f (n) = .
3−n n≤0

Show that f is one-to-one.


Suppose f (n) = f (n ). If m = f (n) is even then it is a power of 2, thus
 
2 = 2n , so 2n−n = 1, and n − n = 0, so n = n , as required. On the other
n

hand, if f (n) is odd, then it can only be a power of 3, and the same algebra

starting with m = 3−n = 3−n , gives the result in this case as well. ♦

Example 6.14. Let the function f : N → Z be defined by

n/2 if n is even
g(n) = .
−(n + 1)/2 if n is odd

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Set structures Chapter | 6 123

Show that f is onto.


Let m ∈ Z be given. If m ≥ 0, then 2m is an even natural number and
g(2m) = m. If m < 0, then −(2m − 1) is an odd natural number, and g(−(2m −
1)) = −((−2m − 1) + 1)/2 = −(−2m)/2 = m. So m is related to an element of
the domain in either case and g is onto. ♦

Both of these examples are counterintuitive, in the sense that, for the first,
we have a one-to-one function from a set to a smaller subset, and in the second,
an onto function from a subset to a larger set. This situation could not happen
for finite sets, and is sometimes called a Hilbert’s Hotel phenomenon.
You can think of the first example as a way of assigning an infinite number
of guests, labeled by the integers, to the infinite number of beds, labeled just
by the natural numbers, in the Hilbert Hotel. Each guest is assigned exactly one
bed, so the relation is functional. Moreover, at least for the function f , no bed
is assigned to two people – a one-to-one function. It sounds impossible, since
there are infinitely many more guests than beds. But the one-to-one function
f manages the task and even has an infinite number of beds left over! The
sequence of beds labeled from 100 to 200 is almost completely unused. The
only power of 2 in that range is 27 = 128. So the 7th positive guest has that
whole wing to himself since the powers of 3 skip those beds completely, going
from bed 34 = 81 to bed 35 = 243.
The second example seems just as strange in the hotel interpretation. Here
the guests are labeled by the natural numbers, and they show up at an even big-
ger Hilbert Hotel with beds labeled from the set of integers. But the function
g is onto, so somehow, under this assignment, the guests labeled by the natu-
ral numbers fill up the entire hotel, filling every single positive bed and all the
negative beds too!
We end this curious section with yet one more curiosity.

Example 6.15. Let A be a set and let h : A → P(A) be any function from A to
its powerset. So for each a ∈ A we have h(a) ⊆ A.
Define now another subset of A by Ch = {a ∈ A | a ∈ / h(a)}. The curious
property of this definition is that, for any element a ∈ A, we must have Ch =
h(a). This is because the subsets Ch and h(a) disagree over the membership of
the element a. Since the subset Ch is not any of the sets h(a), the function h
cannot be onto. ♦

You may think this is not much of a curiosity. After all, if A = {a, b, c} then
|A| = 3 and |P(A)| = 23 = 8, so the domain is simply too small to support
an onto function to the target. So for finite sets, the fact that there is no onto
function A → P(A) is not a surprise since |A| is always far too small.
But the argument in the example is valid for any domain set, even an infinite
set. There is no onto function N → P(N) either. But how can it be true that the
set of natural numbers is too small? There is an infinite number of them. There
are so many that, in the Hilbert Hotel example, we can fit in all the integers and

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


124 Discrete Mathematics With Logic

have plenty of room left over. But there is no way to fill a hotel with beds labeled
by P(N) if you only have enough guests to be labeled by N. We are forced to
write |N| < |P(N)| and to accept the fact that there are different types of infinite
sets, and that they are compared by one-to-one and onto functions.

Exercises
1. Define f : Z → P(Z) by f (n) = {m ∈ Z | m ≥ n2 }.
Define Cf by Cf = {n ∈ Z | n ∈ / f (n)} and verify that Cf is not f (n) for
any n.
2. Define a function f : {a, b, c, d, e, f, g} → P({a, b, c, d, e, f, g}) so that
Cf = {a, d, e, g}.
3. Here is a “proof” that P(N) is countably infinite. What’s wrong with it?
We define an one-to-one function f : P(N) → N as follows. Pick a set in
P(N) at random, A, assign f (A) = 0. Continue inductively, at the nth step,
choose any set you haven’t chosen already, X, and assign f (X) = n. There
are an infinite number of sets in P(N), so you don’t run out, and the function
is one-to-one since you never reuse a number. So |P(N)| ≤ |N|, hence, since
we already know |P(N)| ≥ |N|, Cantor is an idiot and |P(N)| = |N|.

6.6 Cardinality of infinite sets†


The moral of the mental experiments of Section 6.5 is that the idea of “number
of elements” is too slippery to be useful for infinite sets, it leads to many seri-
ous errors. This approach has long been abandoned by mathematicians in favor
of the more precise notion of cardinality which, while synonymous with the
number of elements for finite sets, veers radically away for infinite sets. Infinite
cardinals are not evaluated, like finite cardinals, where we write |{a, b, c}| = 3.
Mathematicians will not write |Z| = ∞, since ∞ is not a symbol for a cardinal.1
Instead of being evaluated, infinite cardinals are compared, the comparison be-
ing done by the existence or non-existence of one-to-one and onto functions.
If there exists a one-to-one function f : A → B, then we write |A| ≤ |B|,
otherwise, if none exists, we say |B| > |A|.
Equivalently, if there exists an onto function f : A → B, then we write |A| ≥
|B|, otherwise, if none exists, we say |B| < |A|.
It is true, but not obvious, that the one-to-one version and the onto version
are equivalent. If |A| ≤ |B| and |B| ≤ |A| we write |A| = |B|, and say that A
and B have equal cardinality. If |A| = |B| then it is true, but again not obvious,
that there is a function f : A → B which is both one-to-one and onto. It is not
too hard to prove, most people take only two or three hours to work out all the
tricks needed.

1 You may sometimes see the notation |N| = ℵ , but we will not use this. Look up “infinite cardi-
0
nals” if you are curious.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Set structures Chapter | 6 125

Naively we would expect that all infinite sets have equal cardinality, but this
is contradicted by our general cardinality result that |A| < |P(A)|, which is valid
even for infinite sets. In fact, there must then be an infinite number of different
cardinalities of infinite sets, for instance

|N| < |P(N)| < |P(P(N))| < |P(P(P(N)))| < · · ·

For discrete mathematics, we are most interested in distinguishing the least


infinite cardinal from all the rest, and the common terminology of the subject
supports this approach. We say that the cardinality of N is countably infinite,
and all the other types of infinite cardinals are lumped together under the label
uncountable. If a set is called countable, then its cardinality is either finite or
countably infinite. If a set is uncountable, it is often of little interest to distin-
guish it further.
There are other uncountable sets besides P(N). From |A| < |P(A)| we see
that the power set of any infinite set is uncountable. It is true, but not obvious,
that
|P(N)| = |P(Z)| = |R| = |C|,
with the equalities established by producing a one-to-one function of the cor-
rect type. It has been unknown for more than a century whether there is any
uncountable set with cardinality strictly less than these.
Uncountability is a strange property. By any reasonable measure, “most”
infinite sets are uncountable, but most of the sets we actually work with are
countable, either finite or countably infinite. So it is natural to presume by fa-
miliarity that an unknown set A is countable and write “Let the elements of A
be denoted a0 , a1 , a2 , a3 , . . . ”, however, this may lead to a huge error since, if
A is uncountable, the elements of A can have no such naming scheme – N is
merely countable and there wouldn’t be enough subscripts!
The set of natural numbers has the smallest infinite cardinal, so |N| ≤ |A| for
an any infinite set A. For the integers we have |N| ≤ |Z|, and both the Hilbert
Hotel functions in Section 6.5 show |Z| ≤ |N|, so |N| = |Z|, and the set of inte-
gers Z is also said to be countably infinite.
A surprisingly important example is the set of dots in a square array in the
plane, see Fig. 6.4. The set of dots is easily counted (by an onto function from N)
via the meandering diagonal path pictured. Since the dots can be labeled with
the coordinates (n, m), with n, m ∈ N, this says that N × N is countable. But
perhaps n is just the index of a countable set A and m is the index of a countable
set B, so the dot at (n, m) actually refers to the element (an , bm ) ∈ A × B.
Now our meandering onto function is establishing that the Cartesian product of
any two countable sets is countable. Or perhaps n is the index for a countably
infinite collection of countable sets, A1 , A2 , A3 , . . . , and m is the index for
counting within each set, so the dot (n, m) refers to the mth element of the nth
set, an,m ∈ An . Now our onto function is asserting that a countable union of
countable sets is countable.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


126 Discrete Mathematics With Logic

FIGURE 6.4 A countably infinite array of dots.

Let’s conclude this section by listing our conclusions about cardinality which
relate to infinite sets.
Theorem 6.16 (Cantor’s Theorem). There is no onto function f : X → P(X).
Definition 6.17. We write |X| ≤ |Y | if either of the following is true.
• There exists a function f : X → Y which is onto.
• There exists a function g : Y → X which is one-to-one.
If |X| ≤ |Y | is false, we write |X| > |Y |. ♠
Please note that this definition signals a new use of the familiar symbol ≤,
extending its meaning for ordinary numbers, 1 ≤ 17, or for cardinalities of finite
sets |B| ≤ |D| to the new territory of cardinality of infinite sets. We have seen
that it has hidden subtleties and should not be taken for granted.
There is an infinite number of distinct infinite cardinals:

|N| < |P(N)| < |P(P(N))| < |P(P(P(N)))| < · · · .

All sets A with cardinality |A| ≤ |N| are said to be countable. If |X| > |N|,
we say X is uncountable.
Theorem 6.18 (Useful Countability Results). The sets N, Z, and Q are all
countably infinite, |N| = |Z| = |Q|.
If A ⊆ B and B is countable, then A is countable.
A subset of a countable set is countable.
If A is countable and k ∈ N, then Pk (A) is countable.
A countable union of countable sets is countable. That is, if I is countable,
and for each i ∈ I , Ai is countable, then

Ai
i∈I

is countable.
If A and B are countable, then A × B is countable.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Set structures Chapter | 6 127

Theorem 6.19 (Useful Uncountability Results). The sets R and C are both
uncountable.
If A is an infinite set, then P(A) is uncountable.
If A ⊆ B and A is uncountable, then B is uncountable.
The set of all infinite sequences of 0’s and 1’s is uncountable.

Exercises
1. Decide whether R × R is countable or not, and give an explanation. You can
use any of the properties we discussed.
2. Decide whether P5 (Z) is countable or not, and give an explanation. You can
use any of the properties we discussed.
3. Consider the set of all real numbers x, with 0 ≤ x < 1), which are expressible
as decimals in base 10 such that digits do not decrease as you proceed to
the right, like 0.00000112233344444444444444444777777777 . . . . Decide
if this set is countable or not, and give an explanation. You can use any of
the properties we discussed.
Note. The numbers like 0.5 and 0.2224 with invisible zeros at the end are in
the set, since 0.5 = 0.49999 . . . and 0.2224 = 0.222399999 . . . .

6.7 Symmetry, reflexivity, transitivity


We started on an examination of set structures, concentrated on relations, and
have now spent several sections examining relations of functional type. Recall
that in general a relation R is simply a subset of the Cartesian product of two
sets. In this section, we will be considering the special case where the two sets
are the same.
Let X be a set, a relation on X is a subset R ⊆ X × X. As with ordinary
relations, we may use set notation, (x, x  ) ∈ R, or infix notation xRx  or our
diagrammatic notation x• −→ •x  . For these self-relations, the relation diagram
may be more compactly rendered. For example the one on the left of Fig. 6.5
contains no more information than the reduced relation diagram on the right, in
which there is just a single dot for every element of the set X. In the reduced
form it is particularly important to not omit the arrowheads. A diagram of this
type is also called a directed graph. Self-relations in the guise of directed graphs,
have been studied extensively, both in their own right, and in the form of flow
charts, circuit diagrams, social networks, etc.
In this section we are considering self-relations in the context of three im-
portant properties, reflexivity, symmetry, and transitivity.

Definition 6.20. A relation R ⊆ X × X is said to be reflexive if ∀x ∈ X; xRx.


A relation R ⊆ X × X is said to be symmetric if ∀x, x  ∈ X; [xRx  ⇒ x  Rx].
A relation R ⊆ X × X is said to be transitive if ∀x, y, z ∈ X; [(xRy ∧
yRz) ⇒ xRz]. ♠

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


128 Discrete Mathematics With Logic

FIGURE 6.5 A relation, and its reduced diagram.

It is important to note the universal quantifications in the definition. Given a


relation, that relation as a whole is either reflexive, or not, or symmetric, or not,
or transitive, or not. One violator is enough to sink the property for the whole
relation – for example one element in X with (x, x) ∈ / R allows you to conclude
that R is not reflexive. It is also important to consider these as three separate
properties, three qualities that a relation might have.
Reflexivity: This is the easiest one. The definition requires all elements of
the set X be related to themselves, or, that each node in the relation diagram has
a loop. The relation in Fig. 6.5 is not reflexive since there is no loop at a. The
fact that there is a loop at d does not change that. Examples of reflexive relations
are ≤ and ≥ for both numbers and cardinality. Also ⊆ on P(N) and the relation
⇒ on Boolean functions defined on the same set are both reflexive.
Symmetry: This property has to be checked for each pair of elements x and
x  in X. It requires that either both pairs (x, x  ) and (x  , x) are elements of
R, or neither. The relation in Fig. 6.5 is not symmetric because (a, b) ∈ R but
(b, a) ∈ R. None of the examples of reflexive relations above are symmetric. An
example of a symmetric relation on {2, 3, 4, . . . 9} is having no common divisor
greater than 1, see Fig. 6.6. For symmetric relations the arrows must occur in
matching but reversed pairs, and it makes sense to draw a single straight arrow
with two arrowheads as on the left of Fig. 6.6, or, even better, to leave off the
arrowheads completely, as on the right.

FIGURE 6.6 A symmetric relation and its reduced diagrams.

Symmetry and reflexivity have important anti-versions.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Set structures Chapter | 6 129

Definition 6.21. A relation R ⊆ X × X is said to be anti-reflexive if ∀x ∈


X; ¬xRx.
A relation R ⊆ X × X is said to be anti-symmetric if

∀x, x  ∈ X; [(xRx  ∧ x  Rx) ⇒ x  = x]. ♠

Notice the second one, anti-symmetry, in particular. It has a nice familiar


form which we will discuss in the next section, but it is not worded as we might
expect from the word “anti-symmetric”. It does not quite say that it is impossible
for both xRx  and x  Rx to be true.
Transitivity: This one seems natural in many contexts, but is the most dif-
ficult to establish, even with the help of a diagram. It requires, at each y ∈ X,
that for every incoming and outgoing pair (x, y), and (y, z) in R there exists
a “shortcut” (x, z) in the diagram, connecting x directly to z, see Fig. 6.7, not
neglecting situations as on the right where some of the elements coincide.

FIGURE 6.7 Transitivity diagrammatically.

Exercises
1. Consider the relation ⊆ on P(N).
Which of the named properties, (reflexive/symmetric/transitive) does it
have? Explain.
2. Consider the relation on six elements whose reduced relation diagram is

a) Which of the named properties does it have? Explain.


b) Suppose that these are just some of the arrows of a transitive relation on
six elements. Add all additional arrows to the diagram which are the conse-
quence of transitivity.
3. (The 2 out of 3 problem) Draw reduced relation diagrams for each of the
following situations:
A relation which is reflexive and symmetric, but not transitive.
A relation which is symmetric and transitive, but not reflexive.
A relation which is transitive and reflexive, but not symmetric.
[Hint: diagrams with 3 points work fine.]

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


130 Discrete Mathematics With Logic

6.8 Orderings and equivalence


Many types of relations are defined in terms of reflexivity, symmetry, tran-
sitivity, and their anti-versions. It has already been noted that a self-relation
is equivalent to a directed graph. If the relation is also symmetric and anti-
reflexive, then the relation defines a simple graph. These will be considered
in more detail later.
A relation which is reflexive, anti-symmetric, and transitive is called a par-
tial order. The set on which it is defined is often called a partially ordered set,
or a poset for short. Examples of partial order relations are ≤, ≥, |, ⊆, and the
implication ⇒. At least so far in this text, the least familiar is |, or “divides”,
which defines a partial order the set of positive natural numbers in which we
say n | m if there exists a k ∈ N, such that n · k = m. So 1 divides all positive
naturals, 2 divides all positive even numbers, and 10 divides all positive integers
whose decimal representation ends in a 0.

Example 6.22. The relation divides, |, is a partial order on the set X = {n ∈ N |


n > 0}. We just have to check each of the properties. Remember, each property is
stated in terms of universal quantification over the ground set, and most involve
implications.
Reflexivity: Let n ∈ X be given. n = 1 · n, so n | n.
Anti-symmetry: Let n, m ∈ X be given. Suppose n | m and m | n. So m = kn
and n = k  m. Combining these, we get n = kk  n. Since n > 0, we may cancel
and have 1 = kk  , so k = ±1, and since k ∈ N we have n = m.
Transitivity: Let x, x  , x  ∈ X be given with x = kx  and x  = j x  . So x  =
j (kx) = (j k)x, and x | x  , as required.
It is common for partial order diagrams to omit both the loops and those
arrows which are consequences of transitivity, see Fig. 6.8. Perhaps you see why
such a relation is called partial order. “Horizontally” the elements are ordered
by the arrows, moving from left to right, while “vertically”, the elements are not
comparable, like all the prime numbers directly related to 1. ♦

FIGURE 6.8 The partial order divides on {1, 2, 3, . . . , 11}.

A completely different type of structure is obtained if we drop “anti-” in


anti-symmetry. A relation E ⊆ X × X is called an equivalence relation if it is

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Set structures Chapter | 6 131

reflexive, symmetric, and transitive. Equivalence relations occur throughout all


of modern mathematics, and working with them is an essential skill in discrete
mathematics.
Suppose we have an equivalence relation E on a set X. Let x ∈ X and set
Ex = {y ∈ X | yEx} to be the set of all elements related to x. By symmetry,
Ex is the same set as the set of all elements to which x is related, Ex = {y ∈
X | xEy}. By reflexivity, x ∈ Ex , so Ex = ∅. Also, every pair of elements in
Ex is related to one another by transitivity: y, y  ∈ Ex implies yEx ad xEy  , so
yEy  and by symmetry y  Ey too. So every possible arrow must exist between
the elements of Ex . On the other hand, no element of Ex can be related to any
element z outside of Ex , since then, by transitivity, x would have to be related
to z, violating the definition of Ex . The set Ex is called the equivalence class of
x. By the above, if x and y are related, then Ex = Ey . If x and y are not related,
then Ex ∩ Ey = ∅.
Theorem 6.23. Every equivalence
 relation on X partitions the elements of X
into equivalence classes, X = x∈X Ex with |Ex | ≥ 1 for all x ∈ X, and for
each x and y ∈ X, either Ex = Ey or Ex ∩ Ey = ∅.
So a typical equivalence relation has a diagram like Fig. 6.9, in which there
are four equivalence classes. Within each class, all possible relations exist, and
between different classes – nothing. Diagrams, if required, for equivalence re-
lations usually omit all the arrows and instead just focus on the separation into
equivalence classes.

FIGURE 6.9 An equivalence relation on {1, 2, 3, . . . , 10} and the corresponding equivalence
classes.

Equivalence relations are very common and are often denoted by symbols
.
such as ≡, ∼, , , ≈, ∼ =, =, ⇔, ↔, , etc. The same pair of objects may be
equivalent in one sense and non-equivalent in another, or equivalent in several
different senses. So, for example, two bishops b and b in chess might be equiv-
alent in the sense they are both black, b ∼
= b , or that they both move on black
. 
squares, b = b , or that they are among the bishops, b  b . Analyzing or pro-
gramming a chess game probably involves several equivalence relations among
the pieces.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


132 Discrete Mathematics With Logic

Exercises
1. Draw the reduced relation diagram of an equivalence relation with equiva-
lence classes {a, b, c}, {e}, and {d, f }.
For any equivalence relation on {a, b, c, d, e, f }, how many arrows can it
have? List all possibilities.
2. Define a relation ∝ on Z by setting n ∝ m if there is a k ∈ Z with n − m =
10k.
Show that ∝ is an equivalence relation and describe the equivalence classes.
3. Define a relation  on Z by setting n  m if there is a k ∈ Z with n + m =
10k.
Decide whether or not  is an equivalence relation. If it is, give the equiva-
lence classes. If not, show why not.

6.9 Case study: The developer’s problem


A developer has a plot of land that he wants to split up for houses. It is a 6 × 6
grid which he wants to divide into 1 × 2 blocks, around which houses are to
be built. Between every pair of blocks, there will be a road. The current design,
Fig. 6.10a has a long straight east/west road cutting through the development,
which the developer does not like. Through-roads become busy, and people pay
less for houses on busy roads. He has a design for an 8 × 8 development with no
through-roads, and would like a design for a 6 × 6 grid with the same property.

FIGURE 6.10 Can we improve the design?

This is a geometric puzzle, and it does not hurt to take out a set of dominoes
and try to arrange them in a 6 × 6 grid with no through-roads. It might take you
just a few minutes to succeed. But what if you don’t. Maybe the solution is very
tricky, or maybe it cannot be done. Either way, it is time to analyze the problem
mathematically.
We have plenty of sets which look promising. There is the set of points
in the plane, R2 , the set 10 of possible through-roads, call them R = {e1 , e2 ,
e3 , e4 , e5 , n1 , n2 , n3 , n4 , n5 }, the set of 62 = 36 squares in the grid which are nat-
urally arranged as a Cartesian product, {1, 2, 3, 4, 5, 6}2 , the set B of 18 blocks
with which the grid is to be tiled. We have many relationships we can model.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Set structures Chapter | 6 133

For instance, the 36 squares are not occurring in isolation. Some pairs share a
side and so could be made into a block. Other pairs do not and can not. This
relation of adjacency is obviously important to the problem.
However, let’s focus on one particular relation, that of obstruction. Once
you have designed an arrangement of blocks, some roads become obstructed by
some blocks, since the road can only go around, and not pass though the block.
In the diagram above, the blocks have been placed so that block 8 obstructs road
n2 . Each block arrangement comes with an obstruction relation

O = {(b, r) ∈ B × R | the line of the road r cuts through block b}.

Is the relation O functional? And, if it is, we certainly want to know if it is


one-to-one, or if it is onto.
Functionality would mean that the relation has the property that each block
obstructs exactly one road. Since the blocks are 1 × 2, they cannot obstruct those
roads running parallel to their alignment, and each can and must obstruct exactly
one road running perpendicular to its alignment. But, you may say, the block
may be somewhere in the middle of the design, so it doesn’t obstruct anything
because the road is obstructed before it ever gets close to the block. To resolve
this question we have to use the actual mathematical definition of the relation
O, not our general feeling for the word obstruct. In the definition, the road r is
related to all blocks its line cuts through, not just the ones it encounters first. So
the relation O is functional. Notice that if we had flipped the Cartesian product
to R × B, that obstruction relation would not be functional.
One to one: This would mean that each road can be obstructed by at most one
block, but we have already seen in the example design that road n2 is obstructed
by 2 blocks. In fact, there are 10 roads and 18 blocks, so it is impossible for any
obstruction function to be one-to-one.
Onto: Onto would require that each road is obstructed by at least one block.
That is not always true either, since road e3 in the sample development is not
obstructed. So the design need not be onto. But wait – before we move on, we
should pause to notice that this is related to the problem which we want to solve.
We don’t want to show that every obstruction function is onto. We want to find
one that is onto, a development that obstructs every road. So we haven’t solved
the problem, but we have put it on a mathematical foundation:
 Is there a development so that the obstruction function is onto? 
The domain of O has 18 elements, and the target has 10, so from that point
of view an onto obstruction function looks plausible.

6.10 Case study: Wolf-Goat-Cabbage II


Let’s consider the Wolf-Goat-Cabbage problem of Sections 1.1 and 3.8 again
from the point of view of relations.
Our first analysis of the problem mathematically was to encode the 24
states of the problem as one of the elements of P({M, W, G, C}), the elements

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


134 Discrete Mathematics With Logic

of the subset recording which objects are on the initial side of the fjord. So
{M, W, G, C} is the initial state, and the solution state is ∅.

FIGURE 6.11 The relation diagram of Wolf-Goat-Cabbage.

Now we want to define a relation which encodes when two states are con-
nected by the man starting in a stable state and traveling across the fjord exactly
once. If he traverses the fjord alone, then the new state is obtained from the old
state by either adding or removing M from the state. If he takes object X, then
that object also is added or removed from the state set. We call this the travers-
ing relation and use the symbol . If (A, B) is in the traversing relation set, we
write A  B.
So starting from the state {M, W, G, C} we have the sequence of related
pairs
{M, W, G, C}  {W, C}  {M, W, C}  {C}  {M, C}
taking us to state {M, C} where we must stop, because {M, C} is not a stable
state, since the Wolf and the Goat are alone on the opposite shore, and no moves
are defined for unstable states. The complete relation diagram for the traversing
relation is shown in Fig. 6.11 where the reader should see the huge advantage of
relation diagrams. So much of the hidden structure of this problem is revealed
first by encoding the problem as a relation, and second by viewing the relation
diagrammatically. It is now not only easy to solve the problem, but also possible
to study and compare different solutions.
Here is a question you can now answer. Suppose someone advises the Viking
to adopt the following strategy. “Only move to a stable state, and, if there is a
choice of stable states, just choose the one you prefer”. Will this result in the

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Set structures Chapter | 6 135

Viking always finding a solution and crossing the river?

Unfortunately, a viking who really loved his goat and following this strategy
could be caught up in an infinite loop like

{M, W, G, C}  {W, C}  {M, W, G, C}  {W, C}


 {M, W, G, C} · · ·

in which he rows the goat back and forth and never does anything else. To avoid
this, the strategist adds the rule “Never perform the same action twice in a row”.
Now must the Viking win?

6.11 Case study: The non-transitive dice


A important relationship is “being better than”. You have certainly seen many
contests and playoffs which purport to decide which player or team is the best.
If we have a set of teams, the relationship we want is x  y, that team x beats
team y in the playoffs. We should expect the relation  to be a strict partial
order, that is, to be anti-reflexive, anti-symmetric, and transitive. Anti-reflexive
since no team beats itself, anti-symmetric since the game is played so there is a
clear winner and no tie, and transitive since the skill level should determine the
outcome.
So lets say we design a playoff among just four teams, Westfield, Schenec-
tady, Rheinbeck, and Lake Placid, i.e., W , S, R, and P . Suppose on the first day
of the playoff that two games are played, with results P  R and W  S. To find
the winner, we need a playoff of P versus W , and to identify the worst team,
we can also play R versus S at a different venue. That determines the overall
winner, but will leave open the question of how to rank the middle two teams.
If that is important, perhaps because it will affect next year’s recruiting, you can
schedule the last pair for a game on day three. But, with the championship al-
ready decided, that will not be a popular game. It will be poorly attended and
there may even be a conflict as to whether the contestants want to win or lose
such a game.
So the organizers decide instead, for the second day, to have a match pitting
the two winners of the first day against the two losers they haven’t played yet;
P vs. S and W vs. R. If both winners win again, then an exciting third day-three
match-up is required between the two clear winners, and the two clear losers.
On the other hand, if just one of the previous winners wins, say P  S,
but R  W , then we know that, since P  R  W , we must have P  W by
transitivity, so P wins the playoff. In this case we have also ranked the teams
since P  R  W  S. In this case the playoff is all done in two days. The only
odd thing for those who follow sports is that P has emerged victorious on day

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


136 Discrete Mathematics With Logic

two by winning against the worst team in the league, not against the second
ranked team.
The only case left is if both winners actually lose on day two. Again, those
who watch sports would not be overly surprised, since there is always some
element of chance. Nevertheless it would be regarded as a fluke, an unexpected
result, something outside the game, if the results so far looked like

P ≺ S


R  W

Such a configuration of results violates our presumption about how a game of


skill should behave, since it violates transitivity and anti-symmetry. Given the
game results P  R  W , transitivity requires P  W , and transitivity with
W  S  P requires W  P . But if P  W and W  P then anti-symmetry
requires P = W , which is false.
If this should happen, the commentators will be happy to explain how the
complexities of the game, the rules, the penalties and the configurations of
the teams involved, all contribute to make this possible. But should we believe
them?
Here is a very simple game that does not take any more than the multiplica-
tive principle to analyze. Instead of teams there are four dice constructed as in
Fig. 6.12. The dice are rolled and the higher score wins. The dice are a little un-
usual, but they look fair in that each die has 24 pips. The 24 pips are distributed
so that no two dice have the same numbers, hence no ties are possible. There are
62 possible outcomes for rolling two dice, and if for more than half that number,
die a beats die b, we write a  b.

FIGURE 6.12 Magic Dice: {2, 2, 2, 2, 8, 8}, {3, 3, 4, 4, 5, 5}, {0, 0, 6, 6, 6, 6}, {1, 1, 1, 7, 7, 7}.

We might expect that such a simple match-up must have results in a strict
partial order, but it is easy to check that

{2, 2, 2, 2, 8, 8}  {1, 1, 1, 7, 7, 7}


{3, 3, 4, 4, 5, 5} ≺ {0, 0, 6, 6, 6, 6}

with 24 wins to 12 losses in each victory. So the relationship cannot be a strict


partial order, even in this simple contest.
And we are not talking about chance occurrences either, since the ordering
with its non-transitivity is defined by the most likely outcome in each case. Even

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Set structures Chapter | 6 137

with dice whose numbers seem to have only two aspects; the extreme values on
the die versus how often those extreme values are represented; we have non-
transitivity. Just those two aspects are enough to explode the notion of “skill
level” which makes the strict partial order seem to be the obvious relation type
to expect for sport tournaments. ‘Skill level’ is one of those ideas which leads
us to expect a one-dimensional result, but even for our simple dice we find a
multi-dimensional phenomenon.
So even in something so direct and pure as four sailors on a submarine
contesting by arm wrestling, there are enough aspects, bicep strength versus
arm length, to make the contest results interesting, complex, and perhaps non-
transitive.

6.12 Case study: The developer’s problem II


Let us return to the developer’s problem of Section 6.9. We want to find an
arrangement of blocks on a 6 × 6 grid so that the obstruction function O is onto.
There are plenty of blocks to obstruct the roads, but the issue is that, in most of
the easy examples to construct, many blocks seem to be obstructing the same
road. So let’s define another relation to cover the situation of a block obstructing
a road already obstructed by another block.

E = {(b, b ) ∈ B × B | [∃r ∈ R; ((b, r) ∈ O) ∧ ((b , r) ∈ O)]}.

In other words, some road obstructed by b is also obstructed by b .


This can be a very tricky relation for blocks of arbitrary shape, but because
they are all 1 × 2, the obstruction relation is actually an equivalence relation.
Reflexivity: Each block obstructs a road, so each block is related to itself.
Symmetry: This is obvious from the commutativity of ∧ in the definition.
Transitivity: If blocks i and j obstruct road r, and blocks j and k obstruct
road r  , then block j only obstructs one road, so r = r  and so (i, k) ∈ E, as
required.
Here are the six equivalence classes for another development design.

FIGURE 6.13 Obstruction classes.

Notice in Fig. 6.13 that each equivalence class has even cardinality. Let prove
that true in general by induction. You might ask, what is the “for all n” statement
that we want to prove? The induction will be very short. We will show that each
of the 5 north/south roads is obstructed by an even number of blocks.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


138 Discrete Mathematics With Logic

Base case: The leftmost road. The first column of squares is filled partially by
some north/south aligned blocks, which uses up an even number of squares, and
partially by some east/west aligned blocked, which stick out and obstruct road
one. Since the north/south aligned used up an even number of the six squares in
column one, road one is obstructed by an even number of blocks.
Inductive step. Suppose the nth road is obstructed by an even number of
blocks. Consider the column of squares on its right edge. An even number of
squares are used up by the north/south aligned blocks, and an even number of
stick out to the west obstructing road n by the inductive hypothesis, so there are
an even number left to stick out to the right and obstruct road n + 1.
So all 5 north/south roads are obstructed by an even number of roads by
induction. The same finite inductive argument works for the five east/west roads.
This completes the proof.
Now let’s define a new obstruction function O  whose domain is the set of
equivalence classes, to the set of roads, assigning each class to the road which
each element in the class obstructs. Again, we want to know if it is possible for
O  to be onto, and obstruct all the roads.
How many equivalence classes can there be? Equivalence classes are never
empty, and these are of even cardinality, so the 18 blocks can be in at most 9
equivalence classes. But there are 10 roads. So the new obstruction function O 
can never be onto for any design, and so it is impossible to obstruct all 10 roads.
Observe that in Fig. 6.13 the blocks are partitioned into 6 equivalence
classes, so four roads are unblocked. Can you find them? In a sense, the de-
sign in Fig. 6.10 is optimal since there is only one unblocked road.
Note that for the 8 × 8 grid we have, by the same arguments, 16 possible
equivalence classes and only 14 roads to block. Identify the 14 equivalence
classes for the 8 × 8 design in Fig. 6.10.

6.13 Case study: The missing region problem II


In Section 2.8 you read about a circle C in the plane bounding a disc D, a finite
subset V ⊆ C, all the |V2 | chords joining the elements of V , and the set of
regions R into which they cut the circle. The problem was to find |R|.
In this section we want to define a relation  ⊆ (P0 (V ) ∪ P2 (V ) ∪ P4 (V )) ×
R between certain subsets of V and the set of regions R.

Definition 6.24. A set X ∈ P0 (V ) ∪ P2 (V ) ∪ P4 (V ) is related to region r ∈ R


by , or Xr, if one of the following holds:
• X ∈ P4 (V ) and the lowest point of r is both an interior point of the circle,
and the intersection of two chords whose endpoints are in X.
• X ∈ P2 (V ), the lowest point of r is an element of X, the chord c joining the
two elements of X contains more than one point of the boundary of r, and
the chord c separates r from the lowest point of the circle.
• X is empty, X ∈ P0 (V ), and r contains the lowest point the circle. ♠

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Set structures Chapter | 6 139

The relation  can be a bit quirky in some special situations. So, if nec-
essary, turn the figure slightly so that the lowest point of the circle is not an
element of V , and so that no chord is either horizontal or vertical. Also, we
know that we don’t get the maximum number of regions in situations like the
regular hexagon, where all the chords meet in the middle, so let’s only consider
the situation where at most two chords meet at any interior point. Call this a
general collection of chords, see Fig. 6.14.

FIGURE 6.14 Illustrating the relation  for non-empty sets of a general collection. The region r
is shaded.

Theorem 6.25. For a general figure, the relation  is functional.

Proof. If X ∈ P4 (V ), and the elements of X are labeled a, b, c, and d as you go


clockwise around the circle, then only chords ac and bd intersect in the interior
of the circle, and since the figure is general, exactly four regions meet there, and
for exactly one is the intersection point the lowest point of the region.
If X ∈ P2 (V ), then its elements a and b, with b lower than a, define a chord.
The chord is divided into segments by the other chords, and the segment at b
separates exactly two regions, one on the side of the lowest point of the circle,
and one on the other side, so X is related to exactly one region of r.
Since the figure is general, the lowest point on the circle is not in V , and ∅
is related to exactly one region.

So, for general figures, the relation  is functional,  : P0 (V ) ∪ P2 (V ) ∪


P4 (V ) → R and we can write (X). The function  is evaluated in Fig. 6.15
for an example.
Of course, you must suspect what comes next:

Theorem 6.26. For general figures, the function  is one-to-one and onto.

Proof.  is onto: Let r be a region. It has a lowest point. If that lowest point
is an interior point of the circle, then it is the intersection of two chords, which
have four endpoints {a, b, c, d}, and ({a, b, c, d}) = r. On the other hand, if
the lowest point is on the boundary, that lowest point is either an element of V ,
or it is the very lowest point of the circle. If it is an element b ∈ V , then either
one or two chords at b are boundaries of r, and one of them, ab, separates r
from the lowest point, so ({a, b}) = r. Lastly, if the lowest point of r is the
lowest point of the circle, then (∅) = r.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


140 Discrete Mathematics With Logic

FIGURE 6.15 The relation  for 6 boundary points.

 is one-to-one: Suppose (X) = (Y ) = r. Since for a general figure each


region can have only one lowest point, and it is either on the boundary or in the
interior, we must have |X| = |Y |. If |X| = |Y | = 4, then the two chords meeting
at the lowest point of r have only 4 endpoints, so X = Y . If |X| = |Y | = 2, and
the lowest point b of r is an element of both sets, and since there is just one
chord at b separating r from the lowest point of the circle, the oppositive point
of the chord must be in both sets as well, so X = Y . Lastly, if |X| = |Y | = 0,
then X = Y = ∅.
Now that we have a one-to-one and onto function we know that
     
|V | |V | |V |
|R| = |P0 (V ) ∪ P2 (V ) ∪ P4 (V )| = + + (6.5)
0 2 4
and this explains exactly the missing region problem. For |V | ≤ 5, the regions
of a general figure correspond exactly to the even subsets of the set V , which are
half of all the subsets and given by 2|V |−1 . So the number of regions advances
geometrically for the first five terms. After that, for |V | ≥ 6, the regions corre-
spond only to the small even subsets of |V |, those of cardinality at most 4, and
the geometric progression is broken.
We also see from Eq. (6.5) that the number of regions of a general figure
does not grow exponentially with the cardinality of V , but only as a 4th de-
gree polynomial. As a side benefit, we have an efficient method for labeling the
regions inside a general figure.

6.14 Summary exercises


You should have learned about:
• The definition of a binary relation.
• How to create and interpret a relation diagram.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Set structures Chapter | 6 141

• The abstract definition of a function.


• The precise formulations of one-to-one and onto.
• The connection between one-to-one, onto, and cardinality for finite sets.
• How to count the number of functions of various types between finite sets.
• How to show a function is one-to-one or onto.
• How infinite cardinals are compared by one-to-one or onto functions† .
• The distinction between Countable and Uncountable sets† .
• Basic properties of Countable sets† .
• Basic properties of Uncountable sets† .
• The reduced diagrams for self-relations.
• The meaning of reflexivity, anti-reflexivity, symmetry, anti-symmetry, and
transitivity.
• The definition of a partially ordered set.
• The Equivalence Relation and its structure.
• How to determine equivalence classes.
1. a) Define a function f : P2 (N) → Pf (N) which is one-to-one.
b) Define a function g : Pf (N) → P2 (N) which is one-to-one. In each case,
draw the correct conclusion about cardinalities.
2. How many relations are there from set {a, b, c} to set {1, 2, 3}? How many
are of functional type? How many are one-to-one functions? How many
are one-to-one and onto functions?
3. Let X = {a, b, c} and consider the relation ⊂ on P(X) × P(X) defined by
A ⊂ B if A ⊆ B and A = B. Draw the relation diagram.
Is ⊂ of functional type? Why or why not?
4. How many relations on the finite set X have at least one element related to
itself?
[Hint: Use inclusion/exclusion.]
5. Define a function f : N → P(N) By setting f (n) to be the set of all num-
bers which occur as consecutive strings in the decimal representation of n.
Example: f (5280) = {0, 2, 5, 8, 52, 28, 80, 528, 280, 5280}.
Is f one-to-one or not? If so, prove it. If not, provide a counterexample.
Is f onto or not? If so, prove it. If not, provide a counterexample.
What do these functions imply about the cardinality of P(N)
6. Define a one to one function with domain {a, b, c, d, e, f } and target
P({a, b, c, d, e, f }).
7. Find a one-to-one and onto function from P2 ({1, 2, 3, 4, 5}) to P3 ({1, 2,
3, 4, 5, 6}), or show that one does not exist.
8. Find an onto function from P2 ({1, 2, 3, 4, 5, 6}) to P({2, 4, 6}), or show
that one does not exist.
9. Let X be a finite set and define f : X → P(P(X)) by setting

f (x) = {A ⊆ X | x ∈ A}

Show whether or not f is one-to-one.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


142 Discrete Mathematics With Logic

Show whether or not f is onto.


10. Show that for any 16 subsets of 0,1,2,3,4,5,6 with at most 3 elements, there
are at least two of these subsets with equal sums of elements, like {1, 3, 5}
and {2, 3, 4}.
11. Let A = {1, 2, 3, 4, 5} and B = {1, 2, 3, 4, 5, 6, 7, 8}. How many onto func-
tions are there from A to B?
How many onto functions are there from B to A?
12. Our multiple Cartesian products always result in tuples with a finite number
of coordinates. What if we wanted an infinite number, like this:


M= An
n=0

What if the An ’s were all countable. Must M be countable?

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Chapter 7

Elementary number theory


7.1 Primality, the Sieve of Eratosthenes
If you’ve ever read an account of the origin of numbers, it probably went some-
thing like this: Prehistoric people, “cavemen”, invented the natural numbers (N)
for counting their goats. As time passed, their primitive idea of number was ex-
panded, adding negatives (Z) for accounting, fractions (Q) for proportions, then
the rest of the real numbers (R) for geometry, and later complex (C) and even
more exotic numbers used in modern engineering and physics. Accepting this
story of unimpeded mathematical progress, we should no more want to go back
and restrict ourselves to those primitive numbers than we would want to walk
around wearing bear skins.
But our study of discrete mathematics tells us that we should do just that,
since many important discrete problems do involve just counting and integers.
Early in the text we considered Z merely as a set of interesting objects. In
number theory, the arithmetic of the integers plays the major role, specifically
addition and multiplication.
You should know from algebra that addition and multiplication are both
commutative; i + j = j + i, ij = j i, associative i + (j + k) = (i + j ) + k,
(ij )k = i(j k); that multiplication distributes over addition, i(j + k) = ij + ik; 0
is the additive unit i + 0 = i and 1 is the multiplicative unit, 1j = j ; and finally
that every integer i has an additive inverse −i, with i + (−i) = 0.
The presence of the additive inverse makes subtraction possible.
Multiplicative inverses in Z, however, are very rare. In Z, only 1 and −1
have multiplicative inverses: 1 · 1 = (−1)(−1) = 1. So division in Z requires
special attention.
Definition 7.1. Division with remainder is an integer equation n = mq + r with
0 ≤ r < m. The number q is the quotient of n with respect to m, and r is called
the remainder. If r = 0, then we say m divides n, and write m | n. ♠
If p ≥ 2, and its only divisors are 1 and p, then p is a prime. The set of all
primes is denoted by P, as mentioned previously.
Given a number n, the most obvious way to determine whether it is prime,
n ∈ P, is to check whether m | n for all values m in the range 2 ≤ m < p. There
are two ways to improve this naive approach. The first is to note that you only
have to check n for prime divisors.√The second is to note that if n = ab, then a
and b cannot both be greater than n. This gives us

Discrete Mathematics With Logic. [Link] 143


Copyright © 2024 Elsevier Inc. All rights reserved.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


144 Discrete Mathematics With Logic

Theorem 7.2. If n > 1 is not prime, then n has a prime divisor no larger than
the square root of n.
Theorem 7.2 is the basis for a method of determining primes known as
the Sieve of Eratosthenes. You start with a list of all primes up to N , P1 =
{2, 3, 5, . . . } and then form a second list L of all values in N up to N 2 . Then
cross off from L the values 0, 1 and all multiples of elements in P1 . When that
is done, all remaining elements of L are added to P1 to form P2 , which by
Theorem 7.2 contains all the primes up to N 2 .
Example 7.3. If P1 = {2, 3, 5, 7}, which are all the primes up to N = 10, then,
indicating the crossed out terms with subscripts, the sieved list L

0x 1x 22 33 42 55 62,3 77 82 93
102,5 11 122,3 13 142,7 153,5 162 17 182,3 19
202,5 213,7 222 23 242,3 255 262 273 282,3,7 29
302,3,5 31 322 333 342 355,7 362,3 37 382 393
402,5 41 422,3,7 43 442 453,5 462 47 482,3 497
502,5 513 522 53 542,3 555 562,7 573 582,3 59
602,3,5 61 622 633,7 642 655 662,3 67 682 693
702,5,7 71 722,3 73 742 753,5 762 777 782,3 79
802,5 813 822 83 842,3,7 855 862 873 882,3 89
902,3,5 917 922 933 942 955 962,3 97 982,7 993
records all the primes P2 = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47,
53, 59, 61, 67, 71, 73, 79, 83, 89, 97} up to 102 = 100. ♦
We could now use the list in the example to sieve out a list of the primes up to
1002 = 10, 000. In doing so, we certainly would use a computer, but historically
the automation has been done also with various mechanical methods, such as
strips of paper with appropriately punched holes – ‘the sieves’.
Example 7.4. The 132 problem. Show that 132 = 11 · 19 using only the primal-
ity of 11, 13, and 19.
Of course, you can multiply, 132 = 169 and 11 · 19 = 209, but that is “cheat-
ing”. The solution should look more like what you naturally will do to show
that 52 = 2 · 13, where you don’t multiply at all and just note that the number
on the left is odd, and the number on the right is even. So we are looking for an
argument that only uses the fact that 11, 13, and 19 are primes. ♦
Primality arguments involve the unique factorization of an integer into
primes, and the 132 problem highlights that this fact is not obvious.
1. Use the Sieve of Eratosthenes to find all the primes up to 166.
2. Suppose you wanted to decide if 507 was prime. What is the largest prime
you need to check?
Is 507 prime? If not, give a prime factorization.
3. Give a prime factorization of 1776. Begin as efficiently as possible.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Elementary number theory Chapter | 7 145

7.2 Common divisors, the Euclidean Algorithm


It might seem that Theorem 7.2 made the determination of primality very easy.
After all, to determine
√ if a number on the order of 10,000 is prime, we only have
to check at most 10,000 = 100 factors – and half of those are even numbers,
for all of which only the factor 2 needs to be checked.
But we should not be too happy about the fact that 100 is so much less than
10,000. Our benchmark for dealing with numbers must take into account that we
have a very efficient way of encoding numbers using, say, the binary or decimal
number system. When we do arithmetic, adding and multiplying, we do that by
working with the digits or the bits alone, not the number itself. To add two N -bit
numbers persuades us to do N bit-additions, and then handle at most N carries.
Ignoring details of implementation, we expect to do about 2N little tasks. For
multiplication there is more work to do. We gather the results of multiplying
each bit of one factor by all the bits of the other factor, and adding the shifted
results. So we expect, say, 2N 2 little tasks. That sounds like an awful lot until
you realize that the numbers we are talking about, N -bit numbers, are of size
roughly 2N .
Now consider, for an N -bit number, if we want to use Theorem 7.2 √ and
just
√ N check primality by looking for small factors, we are talking about 2N =
( 2) divisions, an amount of work which is exponential in the number of bits,
and that is very bad for scaling. What we would want is a method in which the
work required is proportional to, or even a polynomial in, the number of bits.
No test for divisors comes close to that. Not so for common divisors.
Definition 7.5. Given integers d, n, m > 0, the integer d is said to be a common
divisor of n and m if d | n and d | m.
The greatest common divisor of n and m, written gcd(n, m), is a common
divisor with the property that d ≤ gcd(n, m) for all common divisors d of n
and m. ♠
If gcd(n, m) = 1, then n and m are said to be relatively prime, or coprime.
Example 7.6. Let’s compute gcd(1776, 5280).

Factoring, 1776 = 2 · 888 = 24 · 111 = 24 · 3 · 37, and 5280 = 8 · 660 = 8 · 6 ·


11 · 10 = 25 · 3 · 5 · 11. So gcd(1776, 5280) = 24 · 3 = 48. ♦
The solution of the previous example used unique prime factorization, which
we have only hinted at so far, but even if that is correct, it is not a good general
method. We just saw that, if you want to factor a number into its prime factors,
just expect to do a lot of work.
Theorem 7.7. Let n = m · q + r be division with remainder of n by m with
quotient q and remainder r > 0. Then gcd(n, m) = gcd(m, r).

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


146 Discrete Mathematics With Logic

Proof. We will show that, in fact, the pair {n, m} has the same set of common
divisors as the pair {m, r}, and we’ll use the double inclusion method.
Let d be a common divisor of m and r, so m = id and r = j d. Then n =
mq + r = idq + j d = (iq + j )d, and d | n, and so d is a common divisor of n
and m.
On the other hand, let d be a common divisor of n and m, so n = ud and
m = vd . Then ud = vd q + r, so r = ud − vd q = (u − vq)d , and so d is a
common divisor of m and r.

Example 7.8. To compute gcd(1776, 5280) using Theorem 7.7, divide 5280 =
1776 · 2 + 1728 giving gcd(5280, 1776) = gcd(1776, 1728). But don’t stop
there. Divide again 1776 = 1728 · 1 + 48 giving gcd(1776, 1728) = gcd(1728,
48). Then 1728 = 48 · 36 + 0, so 48 | 1728, and of course gcd(1728, 48) = 48.
And that means gcd(1776, 5280) = 48. ♦

This repeated use of Theorem 7.7, as in Example 7.8, is called the Euclidean
Algorithm.

Algorithm 7.9 (Euclidean Algorithm). To compute gcd(n0 , n1 ) with n0 > n1 >


0; in the kth step, k ≥ 0, perform division with remainder nk = nk+1 · qk+1 +
nk+2 to define the new value nk+2 . The procedure halts at the Kth step when
nK+2 = 0. Then gcd(n0 , n1 ) = nK+1 . ♥

So which do we use? The direct method of Example 7.6 or the Euclidean


Algorithm as in Example 7.8? Nobody likes to divide, so what is the worst case
for the Euclidean Algorithm? In division with remainder n = m · q + r there are
two possibilities, either m is small, m ≤ n/2, in which case the remainder which
is yet smaller than m, satisfies r < n/2; or m is large, n/2 < m < n, in which
case division with remainder removes just one m from n and r = n − m < n/2.
In either case, r < n/2, or in terms of the binary numbers, one bit fewer.
For the Euclidean Algorithm, this means that nk+2 has at least one bit fewer
than nk , and an N -bit number has at most 2N divisions required. In the example,
5280 is a 13-bit number, we would have felt unlucky indeed had it taken 26
divisions, but even √then, the 2N is proportional to the number of bits, and is the
clear winner over ( 2)N for large examples, and for most small examples, too.

Exercises
1. Use the Euclidean Algorithm to find the greatest common divisor of 123 and
321.
2. Use the Euclidean Algorithm to find gcd(988887, 888887). Take any short-
cuts you like. (But only hand calculations.)
3. Show using the Euclidean algorithm that 100 and 169 are coprime.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Elementary number theory Chapter | 7 147

7.3 Extended Euclidean Algorithm


Example 7.10 (Euclid’s Coin Problem). Suppose Alexander the Great orders
his treasury to make only two types of coin, one with his own picture, the A coin,
and a less valuable one with the picture of the only other figure of importance
in his empire, his horse Bucephalus, the B coin. They are to be the only coins
in the land, and they must be used to make change for any amount of Talents.
What whole number values of Talents can A and B have? ♦
If A = 16 and B = 1 then the system clearly works, and any system with
B = 1 works since you really don’t need the A coins except for convenience. If
A = 10 and B = 9, then that system also works, since you can pay a bill of a
single talent by giving one A coin, and taking a B coin in change. If you can pay
1 talent then you can pay any number, and the system works.
Euclid’s Coin Problem comes down to, given two positive integers A and B,
finding integers s and t so that sA + tB = 1.
From that equation we see that it does not work to take A = 25 and B = 15,
because then it would only be possible to pay in multiples of their common
divisor, 5 talents. We must have gcd(A, B) = 1, the values A and B must be
coprime. Is that condition sufficient?
Example 7.11. Let A = 58 and B = 21. Using the Euclidean Algorithm:

58 = 21 · 2 + 16 (scale by 4)
21 = 16 · 1 + 5 (scale by −3)
16 = 5·3+1 (scale by 1)
5 = 1·5+0

we find that gcd(58, 21) = 1, that is, the coins A and B are coprime, so it is
conceivable that there is a solution.
In fact, the four equations above for the divisions with remainder in the Eu-
clidean algorithm hold the key to finding the solution to Euclid’s coin problem.
Adding the three upper equations, appropriately scaled, will cause the terms in
the unwanted remainders, 5 and 16, to cancel out. The surviving terms combine
into (4)(58) + (−3)(21) = (8)(21) + 1, or (4)(58) + (−11)(21) = 1. So with
coins A = 58 and B = 21 we can pay one talent by paying 4 Alexanders, and
getting back 11 Bucephaluses in change.
How were the scaling factors chosen? Bottom to top. Factor 1 was chosen so
that the gcd(58, 21) = 1 would not be altered. Scaling factor −3 was chosen to
cancel out the two terms for remainder 5. Then scaling factor 4 was chosen to
cancel out the three terms for remainder 16. ♦
Euclid’s Coin Problem is not just recreational mathematics. It turns out to
be an important problem in understanding number theory, and the Euclidean
Algorithm has an extension specifically designed to compute the scaling factors
needed to solve the coin problem. This is an alternative to the linear algebra
approach of the previous example.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


148 Discrete Mathematics With Logic

Algorithm 7.12 (Extended Euclidean Algorithm). To find gcd(n0 , n1 ) with


n0 > n1 ; in the kth step, k ≥ 0, perform division with remainder nk = nk+1 ·
qk+1 + nk+2 to define the new value nk+2 . The procedure halts at the Kth step
when nK+2 = 0. Then gcd(n0 , n1 ) = nK+1 .
Now set sK = 1 and sK−1 = −qK , and compute SK−2 , . . . , S0 using sk =
−sk+1 · qk+1 + sk+2 , halting at s0 . Then s0 n1 + s1 n0 = gcd(n0 , n1 ). ♥

Here is the same example done via the extended algorithm,

58 = 21 · 2 + 16 s0 = (−11) = −(4) · 2 + (−3)


21 = 16 · 1 + 5 s1 = (4) = −(−3) · 1 + (1)
16 = 5·3+1 s2 = (−3) s3 = (1);
5 = 1·5+0

So 4 · 58 − 11 · 21 = 1. The extension is a little bit more work because of the


negatives, but there is no division.
To show that the extended algorithm is correct and the scaling factors sk are
chosen correctly, we use a backward induction, with the statement being that, at
the kth step of the extension, sk nk+1 + sk+1 nk = gcd(n0 , n1 ).

Proof. For the base case, k = K − 1, we have nK−1 = nK qk + gcd(n0 , n1 ),


or nK−1 + (−qK )nK = gcd(n0 , n1 ), or sK nK−1 + sK−1 nK = gcd(n0 , n1 ), as
required.
For the inductive step, let k be given and assume that sk+2 nk+1 + sk+1 nk+2 =
gcd(n0 , n1 ). We have sk = −sk+1 · qk+1 + sk+2 and nk = nk+1 · qk+1 + nk+2 ,
so substituting in sk+2 and nk+2 gives (sk + sk+1 qk+1 )nk+1 + sk+1 (nk −
nk+1 qk+1 ) = gcd(n0 , n1 ). Then canceling sk+1 qk+1 nk+1 gives sk nk+1 + sk+1 nk
= gcd(n0 , n1 ), as required.

Theorem 7.13. Given positive integers A and B, there exist integers s and t
with sA + tB = n if and only if gcd(A, B) | n.

So we not only know when the coin problem has a solution, using the ex-
tended Euclidean algorithm, we can find the required numbers “quickly.”
Let’s now return to the 132 problem. Why, just by the primality of 11, 13,
and 19 is it impossible that 132 = 11 · 19?
We may not know much more about primality, but we now know a lot more
about coprimality. The numbers 13 and 19 are coprime, so we can solve Euclid’s
Coin Problem: there are numbers s and t with s · 13 + t · 19 = 1. Multiplying
both sides by 13 gives s · 132 + t · 19 · 13 = 13. But if 132 = 11 · 19, then we
could substitute: s · 11 · 19 + t · 19 · 13 = 13, or (s · 11 + t · 13)19 = 13, which
says 19 | 13, violating 13’s primality.
Notice that we did no arithmetic, and we did not even bother to actually
figure out the solution to the coin problem. We just used the fact that there was
a solution.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Elementary number theory Chapter | 7 149

The argument solving the 132 problem, with just a little attention to detail is
used in Section 7.9 to show that integers satisfy unique prime factorization.

Theorem 7.14. Every integer n, n > 1 factors uniquely into primes.

Exercises
1. Suppose Alexander is worth 34 talents and the Bucephalus is worth 21 tal-
ents. How can you pay a bill of 7 talents?
2. Find s and t such that s · 449 + t · 106 = 1.
3. Find s and t such that s · 111 + t · 99 = 1 or prove that none exists.

7.4 Modular arithmetic


When solving mathematical problems and puzzles, it is often the case that an
argument or insight will turn on the fact that some particular number is even or
odd. This is not simply because there are two classes, the even numbers divisible
by 2, and the odd numbers not. There are lots of other ways to split the numbers
into two classes. Evenness and oddness is special because integer arithmetic
respects it. You have seen this fact written in pseudo-equations like

Even + Even = Even Even × Even = Even


Odd + Odd = Even Odd × Odd = Odd
Even + Odd = Odd Even × Odd = Even

Why not try the same split to express threeness, and call those numbers di-
visible by 3 “threven”, and those not “throdd”. But that setup does not respect
the arithmetic: 2 and 3 are throdd, and 2 + 3 = 5, which would say that adding
two throdds gives a throdd, but 4 and 5 are also both throdd, and 4 + 5 = 9,
threven.
You have probably already anticipated from division with remainder that
we need three classes. So let’s redefine throdd as those numbers which, when
divided by 3, leave a remainder of 1, and invent a new word thweird, for those
which leave a remainder of 2. Threven numbers have remainder 0 when divided
by 3, so now every number is in exactly one of the classes – threven, throdd, or
thwierd. Now we have new pseudo equations and if you test, you find that they
all actually do work, like

Threven + Threven = Threven Threven × Threven = Threven


Throdd + Throdd = Thwierd Throdd × Throdd = Throdd
Throdd + Thweird = Threven Throdd × Thweird = Thweird

and there are several more. Everything favors pursuing this analogy in the study
of the trinary aspects of the natural world except the notation. Not only are the

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


150 Discrete Mathematics With Logic

words ugly and awkward, we will need many more of them, since we will also
want to pursue the fourfold analogy, and the fivefold . . . .
So let’s proceed immediately to the general case, to the n-fold analogy to
even/odd in which the number n is called the modulus. Two integers a and b
are said to be congruent modulo n, and we write a ≡ b mod n, if a = b + kn
for some k ∈ Z. Congruence modulo n is a relation which is reflexive, symmet-
ric, and transitive; hence congruence modulo n is an equivalence relation. We
are particularly interested in the equivalence classes since they are exactly the
sets of numbers which have the same remainder when divided by n. There are n
equivalence classes, one for each remainder 0, 1, 2, . . . (n − 1), and those sym-
bols are used to denote the equivalence classes. The set of equivalence classes
for modulus n is denoted by Zn = {0, 1, 2, . . . , n − 1}.
For modulus 2, the equivalences classes are the even and odd numbers,
with the even numbers denoted by 0 and the odd numbers denoted by 1, Z2 =
{0, 1}.
For modulus 3, Z3 = {0, 1, 2}, and the symbol 1 stands for the equivalence
class of numbers whimsically called throdd above. This abuse of notation ac-
tually causes less confusion that you might imagine, but you should still be
cautious. We know that the number 1 is not equal to the set of odd numbers, and
the set of odd numbers is not equal to the set of numbers which have remainder
1 when divided by 3; but we are now using the symbol “1” for all three of them,
and many others.
But the set theory is secondary. What gives the numbers modulo n so much
power is the arithmetic. The classes with the same modulus can be added and
multiplied consistently, just as the even and odd numbers can.

Theorem 7.15. If a ≡ a mod n and b ≡ b mod n then a + b ≡ a + b mod n


and ab ≡ a b mod n.

Proof. We have a = a + kn and b = b + j n for some integers k and j . Adding


gives a + b = a + kn + b + j n = (a + b ) + (k + j )n, which implies a + b ≡
a +b mod n. Multiplying gives ab = (a +kn)(b +j n) = a b +b kn+a j n+
kj n2 = a b + (b k + a j + kj n)n, so ab ≡ a b mod n.

Even better, this modular arithmetic inherits all the important properties of
arithmetic in Z. Addition and multiplication in Zn is commutative and asso-
ciative, and the distributive law holds. There is an additive unit, always written
with symbol 0, and a multiplicative unit, with symbol 1. You will have to prac-
tice this new arithmetic, in which 7 + 6 ≡ 13 mod 20, 7 + 6 ≡ 0 mod 13, and
7 + 6 ≡ 4 mod 9. Each set Zn has its own addition and multiplication table, such
as the ones below for Z5 .

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Elementary number theory Chapter | 7 151

+ 0 1 2 3 4 × 0 1 2 3 4
0 0 1 2 3 4 0 0 0 0 0 0
1 1 2 3 4 0 1 0 1 2 3 4
2 2 3 4 0 1 2 0 2 4 1 3
3 3 4 0 1 2 3 0 3 1 4 2
4 4 0 1 2 3 4 0 4 3 2 1

Note that, if the modulus is clear from the context, many authors will abbreviate
17 + 6 ≡ 10 mod 13 to 17 + 6 ≡ 10, or often just 17 + 6 = 10.

Exercises
1. For each of the following, compute the results modulo 2, 3, 5, 10, and 11. In
each case express the answer from 0 to the modulus minus one: 6 + 7, 8 + 8
2 · 8, 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9, 5280 + (65)(88), 5280 − (65)(88).
2. Make addition and multiplication tables modulo 7. Find all pairs of additive
and multiplicative inverses.
3. Make addition and multiplication tables modulo 8.
Find all pairs of additive and multiplicative inverses.

7.5 Multiplicative inverses


In Z, every element k has an additive inverse −k, since k +(−k) = 0. In Zn every
element k has the additive inverse n − k, since k + (n − k) = n ≡ 0 mod n.
In Z, only 1 and −1 have multiplicative inverses, and that is only because
12 = (−1)2 = 1. Otherwise, if you want to divide, you have to move to the
rational numbers where division is always possible except by 0.
In Zn , the situation is in between that of Z and Q. If i and j are multiplicative
inverses modulo n, then ij ≡ 1 mod n, or there exists a k ∈ Z so that ij = 1+kn,
or ij + (−k)n = 1. So, given n and i, we want to find integers j and k so that
ij + (−k)n = 1. But that is exactly Euclid’s Coin Problem, and we already
know that there is a solution exactly when gcd(i, n) = 1, and then we can use
the Extended Euclidean Algorithm to find it.

Theorem 7.16. The number k has a multiplicative inverse in Zn if and only if


gcd(k, n) = 1.

Example 7.17. Find the multiplicative inverse of 1776 modulo 2021. Find a
few other pairs of multiplicative inverses in Z2021 .

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


152 Discrete Mathematics With Logic

For 1776, we use the Extended Euclidean Algorithm:

2021 = 1776 · 1 + 245 (−33) = −(29) · 1 + (−4)


1776 = 245 · 7 + 61 (29) = −(−4) · 7 + (1)
245 = 61 · 4 + 1 s2 = (−4); s3 = (1)

So (29)(2021) + (−33)(1776) = 1, which says (−33)(1776) ≡ 1 mod 2021, or


the multiplicative inverse of 1776 in Z2021 is 2021 − 33 = 1988.
To find some other pairs, we could pick some numbers at random, and
follow the same procedure, but consider that we want to “factor 1”, and 1 ≡
2022 mod 2021. Factoring 2022 = 2 · 1011 = 2 · 3 · 337. So we have multi-
plicative inverses (2)(1011) = (3)(674) = (6)(337). Another trick is to note
that −1 ≡ 2020 mod 2021, also easy to factor: 2020 = 202 · 10 = 22 · 5 · 101.
That gives us multiplicative inverses (4)(−505) = (−5)(505) = (20)(−101) =
(101)(−20), or (4)(1516), (2016)(505), (20)(1920), and (101)(2001), respec-
tively.
Some elements in Z2021 have no multiplicative inverse because 2021 is not
prime, having prime factorization 2021 = 43 · 47. So no multiple of 43 or 47 can
have a multiplicative inverse modulo 2021. ♦

Multiplicative inverses are the key to division in Zn , just as in Q where


i/j = i · j −1 . Another way of looking at it, without the negative exponents,
is that dividing, 2/3 = x, is the same as solving the equation 3 · x = 2 for x,
which you do by multiplying both sides by the reciprocal of 3, that is, by its
multiplicative inverse.

Example 7.18. Compute 2/3 in Z11 and in Z12 . Equivalently, solve 3x = 2 in


Z11 and Z12 .

For Z11 , we need the multiplicative inverse of 3. We can always use the Ex-
tended Euclidean Algorithm, but it is never a bad idea to look for a quick
shortcut first. 1 ≡ 12 mod 11, and 12 = 3 · 4, so the multiplicative inverse of
3 in Z11 is 4. So 3x = 2 gives 4 · 3x = 4 · 2. Modulo eleven we have

(4 · 3)x ≡ x ≡ 2 · 4 ≡ 8 mod 11 hence 2/3 ≡ 8 mod 11.

In Z12 , the number 3 has no multiplicative inverse. But maybe we can solve
3x ≡ 2 mod 12 anyway. That would mean 3x = 2 + k · 12 for some k. That
would give us 3x − 12k = 2 or 3(x − 4k) = 2, which is impossible since 3 does
not divide 2. We conclude that 2/3 cannot be defined in Z12 , and the equation
3x ≡ 2 mod 12 has no solution. (The obstruction was that 2 was not divisible by
3. What about the solving 3x ≡ 9 mod 12?) ♦

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Elementary number theory Chapter | 7 153

Exercises
1. Find the multiplicative inverse of 5 modulo 66.
Solve the equation 5x = 3 in Z66 .
2. Find the multiplicative inverse of 12 modulo 25.
Compute 5/12 modulo 25.
3. Find all multiplicative inverses in Z25 .

7.6 The Chinese Remainder Theorem


Suppose that on Chinese New Year there was a marching band on parade. On
Main Street the band was marching eight abreast, but on Park Avenue the band
had to reorganize and was marching eleven abreast. What can you say about the
number of musicians in the band?

The number of musicians is a multiple of 8 and of 11, so n = 23 k = 11j . By


unique prime factorization we conclude n is divisible by 23 11 = 88.

Theorem 7.19. If a and b are coprime and a | n and b | n, then ab | n.

Proof. We have n = ai = bj . Create a prime factorization of n by multiplying


prime factorizations of a and i. Form a second one by multiplying prime fac-
torizations of b and j . By unique prime factorization, Theorem 7.14, the prime
factorizations of n are the same up to reordering. Since gcd(a, b) = 1, none of
the primes for a occur in the factorization of b, so the primes in the prime fac-
torization for a must all be in the prime factorization for j , and a | j , that is
j = ak for some k ∈ Z, hence n = b(ak) = (ab)k.

Let’s return to the parade problem. Suppose that, on more careful examina-
tion, it is found that on Main Street the last row was short, having only three
men, while on Park Avenue the last row was also short, having only two men.
Would those few men change anything?

The number theoretic equations change. From the information on Main Street
we have n ≡ 3 mod 8 and from Park Avenue we know n ≡ 2 mod 11.
One way to proceed is to check one by one all the integers consistent with
Main Street, 3 + k · 8, so 3, 11, 19, 27, 35, . . . , against the requirement of Park
Avenue. This is sufficient for a small problem like this, but will not scale.
It is more effective to take the general expression 3 + k · 8 for the solutions
for Main Street and to solve 3 + k · 8 ≡ 2 mod 11 for k to find which also work
for Park Avenue. We quickly get k · 8 ≡ −1 mod 11, and the next step to isolate

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


154 Discrete Mathematics With Logic

k is to multiply by the multiplicative inverse of 8 modulo 11:

11 = 8·1+3 −4 = −(3) · 1 + (−1)


8 = 3·2+2 3 = −(−1) · 2 + (1)
3 = 2·1+1 s2 = −1 s3 = 1;
2 = 1·2+0

So 3 · 11 − 4 · 8 = 1, and the multiplicative inverse of 8 is −4. Now we can solve


for k by k · 8(−4) ≡ (−1)(−4) ≡ 4 mod 11, so k = 4. We find that the number
of musicians in the parade could be 3 + 4 · 8 = 35. That is less than half the
minimum computed for the first version of the problem, so obviously those few
stray men at the end do make a difference.
It seems amazing that you can figure out the number of musicians from such
scanty information, but in fact we did no such thing. We just found the minimum
possible. Any multiple of 88 can be added to get another possible population for
the band: 35 + j · 88. So maybe the band had 123 members, but no number in
between 35 and 123 is possible.
Theorem 7.20 (Chinese Remainder Theorem). Given two simultaneous con-
gruences: x ≡ a mod n and x ≡ b mod m with gcd(n, m) = 1. If s · n + t · m = 1
for some s, t ∈ Z, then the solutions are

bs · n + at · m + knm

for k ∈ Z.
Proof. The equation guaranteed by the Extended Euclidean Algorithm s · n +
t · m = 1 implies that bs · n ≡ b mod m and bs · n ≡ 0 mod n; while at · m ≡
0 mod m and at ·m ≡ a mod n. Adding them x = bs ·n+at ·m gives the desired
result modulo n and modulo m.
So x is one solution. If y is another, then x − y ≡ a − a ≡ 0 mod n, so
n | x − y, and also m | x − y. Since gcd(n, m) = 1, nm | x − y, and y = bs · n +
at · m + knm.
What if the two moduli are not coprime? There may be a solution: n ≡
11 mod 45 and n ≡ 38 mod 63 has solution n = 101. On the other hand, there
may not: n ≡ 16 mod 45 and n ≡ 32 mod 63 has no solution whatsoever.
This aspect of the problem was also worked out hundreds of years ago and
with the advantage of our modern notation, you have a pretty good chance of
figuring it out.

Exercises
1. Find any integer n such that n ≡ 17 mod 19 and n ≡ 11 mod 13.
2. Find all integers n such that n ≡ 2 mod 19 and n ≡ 5 mod 13.
3. Find any integer n such that 3n ≡ 17 mod 19 and 5n ≡ 11 mod 13.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Elementary number theory Chapter | 7 155

7.7 Case study: Diophantus


Diophantus was a mathematician living in the 3rd century AD in Alexandria,
when that Egyptian city had long been Greek, although part of the Roman Em-
pire, for over a century. Algebraic equations for which integer solutions are
required, such as a 2 + b2 = c2 with solution 32 + 42 = 52 , were his speciality
and are still called Diophantine after him.
Long after Diophantus passed away, the writer Metrodoros heard the fol-
lowing number theoretic puzzle, and included it into his collection of epigrams,
about one and a half millennia ago. This is Paton’s close translation from Greek.

Diophantus
This tomb holds Diophantus. Ah, how great a marvel!
The tomb tells scientifically the measure of his life.
God granted him to be a boy for the sixth part of his life,
and adding a twelfth part to this,
He clothed his cheeks with down;

He lit him the light of wedlock after a seventh part,


and five years after his marriage he granted him a son.
Alas! Late-born wretched child;
after attaining the measure of half of his father’s full life,
chill Fate took him.

After consoling his grief by this science of numbers for four years
he ended his life.
Metrodoros, Epigram 126

Metrodoros gave his epigrams in Greek verse, so you might prefer this more
modern poetical rendering without the strange Greek idioms:

“Here lies Diophantus,” the wonder behold.


Through art algebraic, the stone tells how old:
“God gave him his boyhood one-sixth of his life,
One twelfth more as youth while whiskers grew rife;
And then yet one-seventh ere marriage begun;
In five years there came a bouncing new son.

Alas, the dear child of master and sage


Met fate at just half of his dad’s final age
Four years yet his studies gave solace from grief:
Then leaving scenes earthly he, too, found relief.”

which was old when reprinted in the “Yearbook” of the National Council of
Teachers of Mathematics, 1926.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


156 Discrete Mathematics With Logic

The challenge is to work out the chronology of the life of Diophantus, ideally
without resorting to a computer or even the use of pencil and paper.

This first key to the puzzle is to understand that the solution is to be a whole
number of years, and approach it as a Diophantine problem, not as one in which
we want to measure his life on a continuous time scale. The second is to notice
that in one couplet his age in years is declared divisible by 12, and another to
be divisible by 7. Since gcd(7, 12) = 1, unique prime factorization requires his
age to be divisible by 7 · 12 = 84. Unless Diophantus were truly marvelously
old, that gives his age as 84, and the remaining spans of years are then easy to
unravel. No equations and algebra, just number theory.
One can also use number theory on the Guarini Problem, the case study
of Section 1.9, a problem in recreational mathematics inspired by chess. The
problem can be successfully recast and attacked using Z9 . Try it.
Consider also the next puzzle which Sam Loyd syndicated in the newspapers
of his day, about the turn of the previous century. Loyd asked “How can you
score exactly 50 points?”

Modular arithmetic holds the key both to how the puzzle was designed, the
way to a super fast solution, and the fact that the solution is unique. Pedestrian
puzzlists trying methodically
  10 each selection of 3 or 4 dolls and adding their tags
will be looking at 10
3 + 4 = 120 + 210 = 330 tasks.

Looking at the puzzle modulo 2, the sum of the dolls must be congruent to 0,
and you conclude that you need an even number of odd dolls – but that is not
the best modulus. . .

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Elementary number theory Chapter | 7 157

Ready for more, or want to design your own? New and original puzzles
involving number theory appear all the time. The Pi Mu Epsilon Journal, for
example, always has a section for new and original problems accessible to stu-
dents.

7.8 Case study: The Indian formulas


Most people know that the lengths of the √ sides of a right triangle follow Pythago-
ras’s Theorem, c2 = a 2 + b2 , or c = a 2 + b2 . Because of the square root, the
length of the hypotenuse is expected to be irrational
√ even if the leg-lengths are
integers, like for a triangle with sides 1, 1, and 2. Since 32 + 42 = 52 , however,
there is at least one right triangle, the 3-4-5 triangle, for which all three sides are
integers. Are there any others? Yes. They have been known for a long time to
those who study number theory and are called Pythagorean Triples.
The method in this case study is to start with the assumption that we have
a Pythagorean Triple, work out what properties the numbers in the triple must
have, and eventually derive a formula for them. If some of the steps seem hap-
hazard or arbitrary, it is probably because they are very clever shortcuts, worked
out over a very long time, from a much longer journey.
Suppose a, b, and c are all natural numbers, and suppose c2 = a 2 + b2 . Any
prime which divides two of them, divides the third and simply expands the size
of the triangle by an integer factor, which is not very interesting. So let’s assume
that gcd(a, b) = 1, and that means gcd(a, c) = gcd(b, c) = 1 as well.
Consider the equation c2 = a 2 + b2 modulo 4. (Shortcut!) Modulo 4, odd
numbers have square 1, since (2k + 1)2 = 4k 2 + 4k + 1 ≡ 1 mod 4, and even
numbers have square 0, since (2k)2 = 4k 2 ≡ 0 mod 4. That means that a and b
cannot be both odd, since then c2 ≡ 1 + 1 ≡ 2 mod 4, which is not possible for
a square. To avoid duplicates, assume from now on that b is the even leg of the
triangle, and since gcd(a, b) = 1, leg a must be odd, and so the hypotenuse c
must also be odd.
Write b2 = c2 − a 2 = (c + a)(c − a). Since a and c are both odd, c + a and
c − a are both even. So (c + a)/2 and (c − a)/2 are both integers.
The integers (c + a)/2 and (c − a)/2 must be coprime. That is because
any prime dividing both of them would divide their sum and their difference.
But (c + a)/2 + (c − a)/2 = c and (c + a)/2 − (c − a)/2 = a. And we know
gcd(a, c) = 1.
The integer b2 /4 is a perfect square, so its prime factors come in pairs. By
unique prime factorization, those primes make up the prime factors of (c + a)/2
and (c − a)/2, since b2 /4 = [(c + a)/2][(c − a)/2]. But (c + a)/2 and (c − a)/2
are coprime, so each also has prime factors grouped in pairs, so each one must
also be a perfect square.
Now write (c + a)/2 = n2 and (c − a)/2 = m2 and since b2 /4 = n2 m2 ,
b = 2nm. Now, reusing a trick from above, c = (c + a)/2 + (c − a)/2 = n2 + m2
and a = (c + a)/2 − (c − a)/2 = n2 − m2 .

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


158 Discrete Mathematics With Logic

So every Pythagorean Triple is obtained from two natural numbers n and m,


using the Indian formulas.

a = n2 − m2 , b = 2nm, c = n2 + m2 . (7.1)

Does every n and m work? Look!

(n2 − m2 )2 + (2nm)2 = (n4 − 2n2 m2 + m4 ) + 4n2 m2


= n4 + 2n2 m2 + m4 = (n2 + m2 )2

so any choice of n and m yield by Eq. (7.1) numbers a, b, and c with a 2 + b2 =


c2 . And we just saw that all Pythagorean Triples come from such an n and m.
So is there anything left? Yes. We wanted specifically those Pythagorean
Triples with gcd(a, b) = 1. Not all n and m do that. We’ll leave it as a puzzle
for the reader to show that for this last bit we want gcd(n, m) = 1, and also that
n or m should be even.
Anyway, there are lots of triples! So let’s make some. If n = 2 and m = 1,
that gives the 3–4–5 triangle. If n = 4 and m = 1, then the triangle is 15–8–17.
If n = 5 and m = 4, then the triangle is 9–40–41. If n = 5 and m = 2, then the
triangle is 21–20–29.
The last one is interesting, since it is very close to a right triangle with angle
45◦ . It turns out that there are so many Pythagorean triples that for any acute
angle, there is a Pythagorean Triple approximating that angle to any desired
accuracy. But that would be yet another case study.
Since there are infinitely many solutions of the Diophantine equation c2 =
a + b2 , it is natural to wonder about integer solutions to c3 = a 3 + b3 , or c4 =
2

a 4 + b4 , or . . . . Can we solve those? People wondered about that even though


there is no obvious application, as there is with Pythagorean Triples. But there
aren’t any.

Theorem 7.21 (Fermat’s Last Theorem). If n > 2, then the equation cn = a n +


bn has no positive integer solutions.

7.9 Case study: Unique prime factorization


The solution to the 132 problem illustrated the main reason why integers are
uniquely factorable into primes. In this case study, we want to examine this
issue in more detail. The following theorem contains the heart of the matter.

Theorem 7.22. Let p ∈ P and p > 1.

∀n, m ∈ N; [p = nm] ⇒ [(n = 1) ∨ (m = 1)]



∀n, m ∈ N; [p | nm] ⇒ [(p | n) ∨ (p | m)]

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Elementary number theory Chapter | 7 159

Reading through the logical notation, you might recognize that the upper
condition simply expresses the definition of the primality of p, that is, that p
only factors as p times 1. The second condition, is just what we needed for the
132 problem.
The theorem says that the two conditions are equivalent. That equivalence
implies that the lower condition could also function as the definition of primality.
Actually, in more algebraic expositions, that is exactly what is done. So the
lower condition may be regarded as the definition of primality, and the upper
condition the definition of being irreducible, and the theorem would then be
stating that, for Z, primes and irreducibles are the same.
Of course, the proof will use the double implication method.

Proof. Suppose the lower condition is true. To prove the upper one, let n, and
m be given, and assume that p = nm. So p = 1 · nm and p | nm. From the
lower condition we know that p | n or p | m. If p | n, then n = kp for some
k ∈ Z, and p = kpm. Canceling p gives km = 1. Thus k and m are both 1 and
(n = 1) ∨ (m = 1), as required. If p | m, exactly the same argument applies. So
[p = nm] ⇒ [(n = 1) ∨ (m = 1)], completing the first half. (That was the easy
half.)
Suppose now that the upper condition is true. To prove the lower one, let n
and m be given, and assume that p | nm, that is pk = nm for some integer k.
Case 1: p | n. Then (p | n) ∨ (p | m).
Case 2: ¬(p | n). Then gcd(p, n) = 1. So (Euclid’s Coin Problem again!)
there are integers s and t with sp + tn = 1. Multiplying by m, we have spm +
tnm = m, and substituting pk = nm gives spm + tpk = m, or p(sm + tk) = m.
So p | m, hence (p | n) ∨ (p | m).
So [p | nm] ⇒ [(p | n) ∨ (p | m)], concluding the second part.

Now we can show unique prime factorization! We just had a fancy exercise in
the double inclusion method and implications. The next proof is a fancy exercise
in induction.

Theorem 7.23. Let p1 p2 · · · pk = p1 p2 · · · pk be an equation with all prime


factors. Then k = k , and the prime factors are the same except for permuting
their order.

Proof. The proof will be by induction on k + k and we have to show the propo-
sition is true for all k + k ≥ 2.
Base case: k + k = 2. Since neither side can be 1, each side contains a prime,
so k = k = 1, and p1 = p1 .
Inductive step. Let k + k be given and assume the strong induction hypothe-
sis, that is, unique factorization holds true for all shorter prime expressions. We
have p1 | p1 p2 · · · pk .
Let’s prove by induction on k that p1 is one of the primes in the product
p1 p2 · · · pk for all k ≥ 1. If k = 1, there is nothing to show, establishing the

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


160 Discrete Mathematics With Logic

base case. Now p1 | p1 p2 · · · pk = (p1 )(p2 · · · pk ), so by Theorem 7.22 p1 | p1


or p1 | (p2 · · · pk ). If the first is true, then p1 = p1 . If the second is true, then
p1 is one of the primes in the product p2 · · · pk by the induction hypothesis. So
in either case, p1 is one of the primes on the list.
Now, to continue with the main induction, p1 = pi for some i. So we can
cancel those two primes and get a shorter expression which, by the (main) in-
ductive hypothesis is just the same primes up to permuting the factors. Thus the
same is true replacing the factors p1 = pi .
One induction inside the induction step of another induction! What could be
fancier than that?

7.10 Summary exercises


You should have learned about:
• The definition of prime number.
• The sieve method for finding primes.
• The use of the Euclidean Algorithm to compute gcd(n, m), and its efficiency.
• The use of the Extended Euclidean Algorithm to compute s and t so that
sn + tm = gcd(n, m).
• Basic modular arithmetic.
• How to compute multiplicative inverses modulo n, that is, in Zn .
• That for p a prime, division makes sense in Zp .
• How to solve equations of the type ax ≡ b mod n.
• How to use the Chinese Remainder Theorem to solve pairs ax ≡ b mod n,
cx ≡ d mod m of congruences if gcd(n, m) = 1.
1. Let p and q be primes. Show that p 2 − q 2 is not prime.
2. How many integers are there that are not divisible by any prime larger than
64 and not divisible by the cube of any prime?
Show all your work.
3. Show that gcd(n, m) = gcd(n − m, m). Give an example to show that
gcd(n, m) = gcd(n − m, n + m) is not always true. Can it ever be true?
4. Let n ≥ 5. What can you say about k = gcd(n + 2, n − 2)? How many
different values can k have? Give an example of each type.
5. Suppose a country has coins in denominations 5, 15, and 27 Tzarlinkas.
Can you find a way to use them to pay a 101 Tzarlinka bill?
6. Let p, q, and r be three distinct primes. Show that spq 2 + tqp 2 = r has no
solutions s and t in the integers.
7. Show that the multiplicative inverse of n − 1 is always n − 1 modulo n.
8. A band of trombones tries to march in rows of 8 but the last row has only
4 members. It is reorganized to march in rows of 11 but then there are only
10 members in the final row. What is the fewest number of members this
band can have?
9. Find a number m such that m ≡ 3 mod 5, m ≡ 5 mod 7, and m ≡ 7 mod 11.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Elementary number theory Chapter | 7 161

10. Let k be given. Find two numbers n and m, n > m, such that n ≡ m mod 3k
but n ≡ m mod 3k+1 .
11. Many people know the equation 32 +42 = 52 . Show that every Pythagorean
triple, a 2 + b2 = c2 with a, b, c ∈ N, has one side divisible by 3, one side
divisible by 4, and one side divisible by 5.
12. Let N be a fixed natural number. Define a relation ≡ on the integers by
setting n ≡ m (mod N ) if n − m is evenly divisible by N .
Show that this relation is an equivalence relation.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


This page intentionally left blank

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Chapter 8

Codes and cyphers

8.1 Exponentials modulo n


Suppose we wanted to compute 85 mod 3. We can try to simplify the exponent,
take 5 ≡ 2 mod 3 and use 82 = 64 ≡ 1 mod 3. That is certainly easier, but wait.
Suppose we follow a different path, note that the base satisfies 8 ≡ 2 mod 3 and
compute 85 ≡ 25 = 32 ≡ 2 mod 3. There seems to be a discrepancy. Do we have
a contradiction to Theorem 7.15? Is the answer 1 or 2?

It is 2. The first path was invalid. Theorem 7.15 says that modular equivalence
respects addition and multiplication, but says nothing about exponents. The ‘dis-
crepancy’ above illustrates that we must not assume that a i and a j are equivalent
modulo n just because the exponents satisfy i ≡ j mod n. It is the bases of an
exponential which behave as expected, as in the next example.

Example 8.1 (The Rule of Nine). The remainder of a number modulo 9 is same
as the remainder of the sum of its digits.

Let n be a k digit decimal, n = dk−1 · · · d0 , so we may write n = k−1 i
i=0 di 10 .
Since 10 ≡ 1 mod 9, we have 10i ≡ 1i ≡ 1 mod 9. So n ≡ d0 + d1 + · · · dk−1
mod 9.
So 10607 has the same remainder modulo 9 as 1 + 6 + 7 = 14, or 5. ♦

What can we say about a j focusing on the exponents as independent vari-


ables? Here is a table of modulo 10, which is easy to check since multiplication
modulo 10 in base 10 simply ignores all but the 1’s digit:

Discrete Mathematics With Logic. [Link] 163


Copyright © 2024 Elsevier Inc. All rights reserved.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


164 Discrete Mathematics With Logic

Z10 a1 a2 a3 a4 a5 a6 a7 a8 a9 a 10 a 11 a 12 ···
0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1
2 2 4 8 6 2 4 8 6 2 4 8 6
3 3 9 7 1 3 9 7 1 3 9 7 1
4 4 6 4 6 4 6 4 6 4 6 4 6
5 5 5 5 5 5 5 5 5 5 5 5 5
6 6 6 6 6 6 6 6 6 6 6 6 6
7 7 9 3 1 7 9 3 1 7 9 3 1
8 8 4 2 6 8 4 2 6 8 4 2 6
9 9 1 9 1 9 1 9 1 9 1 9 1

You see various behaviors for the different elements a ∈ Z10 , but one thing is
common, as one keeps multiplying by a, sooner or later a duplicate appears,
establishing a pattern, and that pattern must continue forever.
So if we want to compute 888888 in Z10 , we reduce the base, not the expo-
nent, and compute instead 8888 . Then, since the powers of 8 repeat every four,
we use the fact that 888 ≡ 4 mod 4, and use 8888 = 84 ≡ 6 mod 10. Of course
666666 ≡ 6 mod 10, since the powers of 6 never seem to get off the ground
modulo 10.
Notice in the table above that the exponentials modulo 10 all return to their
starting values in the a 9 column. It would be nice if that type of thing happened
generally, but exponentials can be stranger still. Here is the table for Z8 .

Z8 a1 a2 a3 a4 a5 a6 a7 a8 ···
0 0 0 0 0 0 0 0 0 ···
1 1 1 1 1 1 1 1 1 ···
2 2 4 0 0 0 0 0 0 ···
3 3 1 3 1 3 1 3 1 ···
4 4 0 0 0 0 0 0 0 ···
5 5 1 5 1 5 1 5 1 ···
6 6 4 0 0 0 0 0 0 ···
7 7 1 7 1 7 1 7 1 ···

in which we see the powers of 6 just drop to 0 and where, of course, they must
stay forever, and the sequence never returns to 6.
You see more regular behavior if the base a is coprime to the modulus, so
the base has a multiplicative inverse modulo n. For such a base, we see in both
Z10 and Z8 that the sequence of powers passes through a sequence of distinct
values until it reaches 1, and then the sequence repeats forever. This is always
true.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Codes and cyphers Chapter | 8 165

Theorem 8.2. Let n ≥ 2 be an integer and let a ∈ Zn . Then a has a multiplica-


tive inverse if and only if there is a number k < n so that a k ≡ 1, and a i ≡ a j
for 1 ≤ i < j ≤ k.

The proof is by double implication.

Proof. Suppose first that a has a multiplicative inverse b. If a = 1 then take


k = 1, so assume a = 1.
We first show that 1 does occur in the list of powers of a. Zn has finite
cardinality, so the list a 1 , a 2 , . . . eventually must have a duplicate, say a j ≡ a i
with j > i. Let b be the multiplicative inverse of a and multiply both sides by bi ,
giving a j bi ≡ a i bi , or a j −i ≡ 1 for an exponent j − i smaller than the duplicate
a j . So take k to be the smallest positive value for which a k ≡ 1.
For the other direction, suppose a k ≡ 1. If k = 1, then a = 1, and a is its
own multiplicative inverse. Otherwise k > 1 and aa k−1 ≡ 1, so a k−1 is the mul-
tiplicative inverse.

The number k is called the multiplicative order of a in Zn . The multiplicative


order is only defined for elements with multiplicative inverses. Also, if a has a
multiplicative inverse, we write its multiplicative inverse as a −1 , and the usual
rules of negative exponents apply, including a 0 = 1.

Exercises
1. Compute 10200 modulo 11.
2. a) Compute the first 12 powers of 2 modulo 12. Use what you discover to
compute 21776 modulo 12.
b) Compute the first 17 powers of 2 modulo 17. Use what you discover to
compute 21776 modulo 17.
3. Compute 21776 modulo 33.

8.2 Prime modulus


When people want to define a modular system for some application, say the 24
hours on a clock, or the 60 seconds on a clock, or the 360 angular degrees around
a circle, they seem always to prefer a modulus with many divisors. Whenever
such a choice is made, you can be pretty sure that the system is being used
primarily additively, that multiplication plays a lesser role. If multiplication is
important, then so is division, and every divisor of the modulus loses multi-
plicative inverses, and that makes the work of solving equations more difficult,
or ambiguous, if not impossible.
If you are choosing a modulus, and multiplication is important, you want as
few divisors of the modulus as possible. Ideally, you should choose the modulus
to be a prime p. In Zp , every non-zero element has a multiplicative inverse, and
so the arithmetic is just the same as it is in Q or R.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


166 Discrete Mathematics With Logic

Even the tricky exponents are better behaved if the modulus is prime. In
Z11 , since every non-zero element has a multiplicative inverse, we have from
Theorem 8.2 that the list of powers of every non-zero element will have a 1
before a 11 . Check that in the table below.

a a0 a1 a2 a3 a4 a5 a6 a7 a8 a 9 a 10 a 11
0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1
2 1 2 4 8 5 10 9 7 3 6 1 2
3 1 3 9 5 4 1 3 9 5 4 1 3
4 1 4 5 9 3 1 4 5 9 3 1 4
5 1 5 3 4 9 1 5 3 4 9 1 5
6 1 6 3 7 9 10 5 8 4 2 1 6
7 1 7 5 2 3 10 4 6 9 8 1 7
8 1 8 9 6 4 10 3 2 5 7 1 8
9 1 9 4 3 5 1 9 4 3 5 1 9
10 1 10 1 10 1 10 1 10 1 10 1 10

One thing which is striking about this table is the column of 1’s precisely at a 10 .
We see the same phenomenon in the table of exponents modulo the prime 13.

a a0 a1 a2 a3 a4 a5 a6 a7 a8 a 9 a 10 a 11 a 12 ...
0 0 0 0 0 0 0 0 0 0 0 0 0 ...
1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 1 2 4 8 3 6 12 11 9 5 10 7 1
3 1 3 9 1 3 9 1 3 9 1 3 9 1
4 1 4 3 12 9 10 1 4 3 12 9 10 1
5 1 5 12 8 1 5 12 8 1 5 12 8 1
6 1 6 10 8 9 2 12 7 3 5 4 11 1
7 1 7 10 5 9 11 12 6 3 8 4 2 1
8 1 8 12 5 1 8 12 5 1 8 12 5 1
9 1 9 3 1 9 3 1 9 3 1 9 3 1
10 1 10 9 12 3 4 1 10 9 12 3 4 1
11 1 11 4 5 3 6 1 11 4 5 3 6 1
12 1 12 1 12 1 12 1 12 1 12 1 12 1

You see some occurrences of 1 scattered about earlier, but always in the column
for a 12 for every element except 0.
This behavior of exponentials for prime modulus was noticed for centuries.
The mathematician Fermat was able to prove the general statement. The result
has come to be called his “little theorem”, and sometimes his “little lemma”,
that is, his little minor result.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Codes and cyphers Chapter | 8 167

Theorem 8.3 (Fermat’s Little Theorem). For p a prime, a p−1 ≡ 1 mod p for
every non-zero element a ∈ Zp .
Some people prefer to word it this way,
Theorem 8.4 (Fermat’s Little Theorem). For p a prime and for all a ∈ Zp ,
a p ≡ a mod p.
Example 8.5. What is 512303 mod 101?

The base we can reduce immediately. 512303 ≡ 7303 mod 101, but do not reduce
the exponent to 0 because 303 ≡ 0 mod 101. Instead, note that 101 is prime and
so 7100 ≡ 1 mod 101. Thus 7303 ≡ 7300 · 73 ≡ (7100 )3 · 73 ≡ 73 mod 101.
You may balk at 73 , but you have to admit that it is a lot better than 512303 ,
you might find it faster to compute 73 = 343 ≡ 40 mod 101 with pencil and
paper than to punch the problem into a computer. ♦
You may wonder, what is Fermat’s “Big Theorem”? Most people think it
was his “Last Theorem”, which was so big that its proof was too large to pencil
into the margin of Fermat’s notebook. The full written up proof had to wait for
centuries of effort by many famous mathematicians, and was only finished rela-
tively recently. It is Theorem 7.21 in Section 7.8, the case study on Pythagorean
Triples. After all that work, now that we know that Fermat’s Last Super Gigantic
Theorem is true, what is the consequence? Well, not much – so far it is mostly
just a cute story. But Fermat’s Little Lemma? That is much more important. It
is hugely consequential in coding theory and cryptography, as we will see soon.

Exercises
1. In the previous exercise set we found that 102n ≡ 1 mod 11. Is that consistent
with Fermat’s Little Theorem?
2. Make a table of all the powers in Z7 , and show it is consistent with Fermat’s
Little Theorem.
3. a) Compute 71252 mod 13.
b) Compute 21710 modulo 101.

8.3 Cyphers and codes


Everybody likes secret codes, those are the brass tacks, from the bottle and stop-
per to the baked bean. These mathematical looking symbols were chalked on
trees and fences as part of a hobo code in the 1920’s,

 – Ill tempered man lives here; ⊗ – Good place for a handout;



– You can camp here; ∼ – Don’t drink the water.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


168 Discrete Mathematics With Logic

and you might have heard the artful dodgers of the day whispering Ixnay, Op-
perscay, Amscray!
Mathematicians and computer scientists do not use the word ‘code’ in this
way. Mathematically a code is just a way of cataloging information for process-
ing, like Morse code for letters, or the Gray code for bit vectors, or bit vectors
for subsets, or the Prüfer code for labeled trees. Basically, a code is just a one-
to-one and onto function from a set to a code set. If secrecy is needed, then the
code is called a cypher, and the data is said to be encrypted.
The hobo markings, Cockney rhyming slang, and pig Latin are not very se-
cure as cyphers. Over time their meaning is discovered. But, since such cyphers
require effort to devise and learn, they are hard to change.
Example 8.6. Caesar’s Cypher was used by Julius Caesar in his wars with
the Gauls. In the language of modular arithmetic it may be described as follows.
Start with an encoding of the letters of the alphabet A into Z26 . Simply assigning
a to 0, b to 1, etc., is fine since the encryption comes later. Once encoded, the
message, M, which started out as a string on the alphabet A, has been encoded
as string of elements of Z26 .
Now pick an encoding key, , to be kept secret from the enemy, and encrypt
the coded message by adding  to each element of Z26 in the message. The
resulting encrypted message M is also a string in Z26 . M can be decoded back
into a string of A. That will probably be a string of unreadable text which can
be sent by courier without fear of it being intercepted and read by the enemy.
When the encrypted message is received, it is re-encoded to M , and the
decrypting key, δ = 26 −  is applied to each element of Z26 in the string to
recover M, which is then decoded to yield the original text.
The message happy birthday with encoding key  = 5 would be sent as the
encrypted string mfuud gnwymifd. ♦
The reason Caesar’s Cypher was so successful is the existence of the keys.
There are 26! permutations of A, that is, 26! one-to-one and onto functions
A → A, most of which could work very well as an encryption function. But
how are such functions to be communicated and used efficiently? The mere 26
different functions associated to the encoding and decoding keys make the code
description fast, make encoding/decoding efficient, and can be changed with
little trouble.
Using number theory, we can create more complex systems with the same
flavor as Caesar’s Cypher.
Example 8.7. A Multiplicative Cypher has a different encryption step than
Caesar’s cypher. The permutation of Z26 is accomplished by the function
f : Z26 → Z26 defined by f (n) = n · . There is still an encryption key, but
it is applied multiplicatively.
There is also a decryption key, δ, which is the multiplicative inverse of  in
Z26 , and the decryption function is g(n) = n · δ, and that works since g(f (n)) =
(n · ) · δ = n(δ) ≡ n mod 26.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Codes and cyphers Chapter | 8 169

For Caesar’s additive cypher, any of the elements of Z26 can be used as
an encryption key, since each element in Z26 has an additive inverse. For the
multiplicative cypher, not every element has a multiplicative inverse. Using  =
10 will not work in Z26 since gcd(10, 26) = 2 = 1. But there are many pairs
which do work,  = 3 and δ = 9, for instance. ♦

One way to get more keys is to expand the alphabet set so that it has prime
cardinality. If we add five punctuation marks to the alphabet, say [.,:;?], then
we can work instead in the prime modulus 31. That is what we will do for our
third example.

Example 8.8. An Exponential Cypher has an exponential encryption step,


f (n) = n , and an exponential decryption step g(n) = nδ . In order for it to
work, we must have (n )δ = nδ ≡ 1 mod 31.
Since 31 is prime, we know from Fermat’s Little Theorem that n30 ≡ 1 mod
31 for n ≡ 0. Thus  and δ should be chosen to be multiplicative inverses modulo
30. With that choice δ = 1 + 30k, and nδ = nn30k ≡ n(n30 )k ≡ n mod 31 by
Little Fermat. ♦

Which of these three is the best, the additive (Caesar’s) cypher, or the mul-
tiplicative, or the exponential versions? Unfortunately, they are all three more
or less equally bad. The first problem is – there are too few keys. There are so
few keys that the enemy, more sophisticated than the ‘barbarians’ Caesar was
faced with, can simply try them all. Even if we abandon keys and the modular
arithmetic approach and use one of the 26! other possible codes, the result is still
insecure since, as Sherlock Holmes describes in “The Adventure of the Dancing
Men”, any letter code can be easily broken noting that different letters occur
differently often – the frequency attack.
In order for any version to be credible, the text message must be broken into
much larger blocks, not individual letters but hundreds of characters per block,
so that one is working not in Z31 but in ZN where the modulus N has hundreds,
or even thousands of bits in its binary representation. That is the absolute bare
minimum for this type of encryption.
In the examples and exercises of this and the next section, all the primes
are chosen to be very small, but the method is meant to be applied using large
primes, essentially as large as one can handle.

Exercises
1. Encode “WPI” in Z26 and encrypt it additively with key  = 7, and multi-
plicatively with key  = 7.
Find the decoding keys, δ for each, and check that they work.
2. For the 11 letter alphabet {a, b, c, d, e, g, h, i, j, k, l} encode “da” and en-
crypt it exponentially with key  = 7. Find the decoding key, δ, and check
that it works.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


170 Discrete Mathematics With Logic

3. Find all values in Z11 which do not work as exponential encoding keys.
Find all values in Z11 which do not work as multiplicative encoding keys.
Find all values in Z11 which do not work as additive encoding keys.

8.4 RSA encryption


Julius Caesar had many loyal centurions to encrypt and decrypt his messages.
For mathematical cryptography, encryption and decryption is done by a com-
puter or phone almost certainly connected to the internet, and you can judge for
yourself whether such machines are loyal. Even though done by a machine, it is
common to think of the calculations as being done by people, with the encrypter
called Bob and the decrypter called Alice.
The problem which we want to address in this section is that, for any of the
three methods we have considered, Alice and Bob must agree on a cryptographic
method before they start communicating. What if that is not the case? If Bob is
a first time customer and wants to purchase something from Alice, and Alice
sends Bob the modulus N and the key  for encrypting his credit card number,
anyone eavesdropping on their communications will be able to compute the
decrypting key δ, and be able to decrypt the credit card number just as well
as Alice can.
Of course, it is best to prevent eavesdroppers from listening. But prudently,
one should try to design a system that works even if eavesdroppers succeed.
Public key cryptography presumes that the attacker knows both the modulus
and the encoding key and yet the message remains secure. In the extreme, Alice
should be able to publish it openly: “Anyone sending secret messages to me
today please use modulus N and encryption key ”.
The RSA system1 accomplishes this. It is an exponential system and uses
a modulus N = pq, which is the product of exactly two distinct primes. So
encrypting is done by f (n) = n , and decrypting is done by g(n) = nδ . The
system will work if  and δ are multiplicative inverses modulo (p − 1)(q − 1).
Before showing why that condition on the encrypting and decrypting keys is
correct, we should discus why the design of Rivest, Shamir, and Adleman gives
us a public key system. Here is what all the participants know.
• Alice knows p, q, N = pq, , δ.
• Bob: Knows N, .
• Attacker: Knows N, .
Given any message element n, Bob can compute n modulo N and send it.
Receiving n , Alice can compute (n )δ modulo N and read the message since
(n )δ ≡ n mod N , as we will see later.
The attacker knows N and  and has heard the encrypted secret n . To decode
he must find δ by computing the multiplicative inverse of  modulo (p − 1)(q −
1). But the attacker doesn’t know p and q. He only knows N . To find p and

1 Rivest/Shamir/Adleman, U.S. Patent No. 4405829, 1983.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Codes and cyphers Chapter | 8 171

q he must factor N into prime factors. If Alice was clever enough to pick large
enough primes p and q, the task of factoring will be too difficult for the attacker.
Example 8.9. Here is a toy example to illustrate what the issues are. Suppose
Alice has chosen p = 11, q = 7, with  = 13 and δ = 37.
Bob has been given the encoding key 13, has been told the modulus, 77, and
he wants to send the secret message (10, 20, 30). He computes x = 1013 mod
77, y = 2013 mod 77, z = 3013 mod 77 and sends (x, y, z) to Alice.
The attacker hears (x, y, z) and knows about 77 and 13. In this tiny toy exam-
ple, the attacker factors 77 = 7·11 and concludes that he needs the multiplicative
inverse of 13 modulo (7 − 1)(11 − 1) = 60. That is done with the Extended Eu-
clidean Algorithm, starting with division with remainder on 60:

60 = 13 · 4 + 8 (−23) = −(5) · 4 + (−3)


13 = 8·1+5 (5) = −(−3) · 1 + (2)
8 = 5·1+3 (−3) = −(2) · 1 + (−1)
5 = 3·1+2 (2) = −(−1) · 1 + (1)
3 = 2·1+1 s4 = (−1), s5 = (1)

So (5)60 + (−23) · 13 = 1 and δ = 60 − 23 = 37.


But if the attacker hadn’t been able to find the factors of 77, he would not
be able to know with what number to begin Euclid’s algorithm. He would not
have been able to find the decoding key δ, and be now in a position to read the
message: (x 37 mod 77, y 37 mod 77, z37 mod 77). ♦
If in the example, Alice had picked just slightly larger primes, like p =
22222223 and q = 10010101. Then the modulus which the attacker would have
to factor would have been N = 222446696674523. Can you do it?
Theorem 8.10. If p and q are distinct primes and  and δ are multiplicative
inverses modulo (p − 1)(q − 1), then nδ ≡ n mod pq.
Proof. Suppose  and δ are multiplicative inverses modulo (p − 1)(q − 1), so
δ ≡ 1 mod (p − 1)(q − 1), that is, δ = 1 + k(p − 1)(q − 1).
Modulo p we have nδ−1 = nk(p−1)(q−1) = (np−1 )k(q−1) ≡ 1k(q−1) mod p
by Fermat’s Little Theorem. In the same way we have nδ−1 = nk(p−1)(q−1) =
(nq−1 )k(p−1) ≡ 1k(p−1) mod q.
So p | (nδ−1 − 1) and q | (nδ−1 − 1), so by unique prime factorization, or
Theorem 7.19, pq | (nδ−1 − 1). Thus nδ−1 ≡ 1 mod pq, and multiplying both
sides by n gives the result.

Exercises
1. Suppose we have an RSA Scheme with primes p = 13 and q = 17. Suppose
the encoding key is  = 5. What is the decoding key δ?
2. In the scheme above, encode (010, 020, 030).

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


172 Discrete Mathematics With Logic

3. Suppose we have an RSA scheme based on 303. Suppose Alice has encoding
key 67. What is Bob’s decoding key?

8.5 Little-o notation


In order for RSA to be effective, the attacker must not be able to factor N = pq
and discover p and q, so Alice naturally wants the number of bits, b, in p and
q very large. But the larger she makes b, the harder her own work is in working
with the system. If the attacker, Vladimir, has much better resources than Alice,
for instance if Vladimir has a decent laptop and Alice does all her computations
with pencil and paper, there is no way for Alice to choose a manageable b so
that Vladimir cannot factor N and read all her secrets.
If they have comparable access to resources, the situation is different. If
Ca (b) is Alice’s cost for working with a b-bit RSA scheme, and Cv (b) is
Vladimir’s cost for factoring the product of two b-bit primes, Then RSA would
be reasonable if
Ca (b)
lim = 0.
b→∞ Cv (b)

Alice could be able to pick a b for which her cost was reasonable, but Vladimir’s
cost was prohibitive. In the situation above, we say Ca (b) = o(Cv (b)) in the
little-o notation.

Definition 8.11. Let f (n) and g(n) be functions, f, g : N → N. Then we say


f (n) = o(g(n)) if for all ε > 0 there is an n0 such that f (n) ≤ εg(n) for all
n ≥ n0 . ♠

The o notation is widely used although the notation is eccentric for many
reasons. In the expression o(g(n)), o is not a function, even though it is written
like one, and o(g(n)) has no value, so when you see f (n) = o(g(n)) it does
not mean that the value of f (n) is equal to the value of o(g(n)). It is easy to
check that n2 = o(n3 ) and 3n2 + 5 = o(n3 ) but of course n2 = 3n2 + 5, and
even n2 = o(3n2 + 5).
Instead, the o notation defines a relation on functions which is not reflexive,
not symmetric, but is transitive, since f (n) = o(g(n)) and g(n) = o(h(n)) im-
plies f (n) = o(h(n)), as is easy to check. If f (n) = o(g(n)) then it means that,
as n gets large, not only is f (n) eventually smaller than g(n), but it is even-
tually smaller than (1/2)g(n), (1/4)g(n), (1/8)g(n), eventually smaller than
(1/2n )g(n) for any n. So f (n) is vanishingly small relative to g(n) as n grows.
In the language of limits

f (n)
lim = 0 ⇒ f (n) = o(g(n))
n→∞ g(n)

and the converse is true if g(n) > 0.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Codes and cyphers Chapter | 8 173

Example 8.12. If f is a quadratic polynomial, f (n) = an2 + bn + c with a, b,


c > 0, then f (n) = o(n3 ) since

an2 + bn + c 1 1 1
lim 3
= lim a + b 2 + c 3 = 0
n→∞ n n→∞ n n n
if you like limits, otherwise you have to do more algebra. ♦

The transitive nature of the relation gives us a hierarchy on the growth of


functions, so for instance ln(n) = o(n), n = o(n2 ), nk = o(nk+1 ), nk = o(2n ),
2n = o(3n ), a n = o(n!), and n! = o(nn ) (a, k ∈ N).
Returning to RSA, Alice is concerned about the work required in comput-
ing  and δ in a system with b bits. Division with remainder is essentially a
multiplication with a subtraction. The number of computations to be performed
is a quadratic in the number of bits: Ab2 + Bb + C, and there are at most 2b
divisions with remainder to be performed.
So Alice has to allow for on (2b)(Ab2 + Bb + C) divisions in computing,
and takes (2Ab3 + 2Bb2 + 2Cb) as her cost.
If Vladimir wants to use old fashioned prime factoring, a version of Eratos-
√ √ b
thenes’s sieve, then he has to work with 2b = 2 tasks, and is dismayed to
√ b
find that 2Ab3 + 2Bb + 2Cb = o( 2 ). √
3
If Vladimir switches to √ the latest methods, he can achieve eC b , but still
3
2Ab3 + 2Bb + 2Cb = o(eC b ), and Alice wins, so RSA wins.

Exercises
1. Suppose we want to compute gcd(5280, 1117) in 100 steps. Is that possible?
What about 10 steps?
2. Show that 500n5 + 1000n3 = o(n6 ).
3. Show that 2n + 3n = o(5n ).

8.6 Fast exponentiation


In Example 8.9 we considered the computations an attacker would have to do
to factor the modulus N , find the decryption key δ from the encryption key ,
and be able to decode the message. But in that example did you notice that we
did not encrypt or decrypt the message? If you tried to do it yourself you might
have been frustrated. To encode the message you would have had to compute
(1013 , 2013 , 3013 ), which would take 3 · 13 multiplications. That seems like a
lot of work.
How many multiplications are we talking about? The √ keys  and δ belong
to Z(p−1)(q−1) . The primes p and q are on the order of N. The product N is

a 2b bit number, N a b bit number, so working modulo (p − 1)(q − 1) we
have to allow for exponents of size (2b − 1)(2b − 1) and 22b − 2 · 2b + 1. Even

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


174 Discrete Mathematics With Logic


if Vladimir uses ancient sieve and factors with n = 2b divisions, the little-o
comparison gives 2b = o(22b − 2 · 2b + 1), and Vladimir wins by a lot.
We saw before that, in modular arithmetic, exponentiation must be handled
specially. Reducing the exponent using Fermat’s Little Theorem will not help
us because the exponents are already reduced.
Fortunately, there is an algorithm which saves RSA. This is the idea. Suppose
you wanted to compute
71776 mod 2027.
That is 1776 − 1 multiplications, but 1776 = 2 · 888. If you write 71776 =
(72·888 ) = (7888 )2 , that calls for only 888 multiplications, 887 for the inside
exponent and just one for the square at the end. If you apply the trick a second
time, you have 71776 = 72·888 = (7888 )2 = ((7444 )2 )2 there are only 445 multi-
plications.
That is fine for even exponents, but what if it is odd? 71783 = 7 · 71782 =
7 · 72·891 = 7 · 72 · (7890 )2 = 7 · 72 · ((7445 )2 )2 with 449 multiplications, still
fantastic savings – and we can continue to get more. Using these hints, you
might be able to write up the multiplication saving algorithm on your own.

Algorithm 8.13 (Fast Exponentiation). Let n ∈ N. To compute x e set P0 = 1,


x0 = x, and e0 = e.
At the kth step set Pk+1 = Pk , xk+1 = xk2 , and ek+1 = ek /2 if ek is even, and
set Pk+1 = Pk xk , xk+1 = xk2 , and ek+1 = (ek − 1)/2 if ek is odd.
The algorithm halts when eK = 0, and then x e = PK . ♥

We will prove that the algorithm correctly computes x e by using induction


to show, for all 0 ≤ k ≤ K, that x e = Pk xkek .

Proof. Base case. For k = 0, P0 x0e0 = 1x e as required.


Inductive Step. Let k ≥ 0 be given and suppose Pk xkek = x e . If ek = 0, the
algorithm has halted, k = K, and there is nothing to show. If ek = 0, there are
two cases.
ek+1
If ek is even, then ek+1 = ek /2, Pk+1 = Pk , and xk+1 = xk2 . Then Pk+1 xk+1
2e /2
= Pk (xk2 )ek /2 = Pk xk k = Pk xkek = x e by the induction hypothesis.
If ek is odd, then 2ek+1 = (ek − 1)/2, Pk+1 = Pk x k , and xk+1 = xk2 . Then
2(e −1)/2 e −1
= Pk x k (xk2 )(ek −1)/2 = Pk x k xk k
ek+1 e
Pk+1 xk+1 = Pk xk xk k Pk = xk k = x e by
the induction hypothesis.
So the result is true for all 0 ≤ k ≤ K by induction.

Notice that the algorithm is essentially computing the binary representation


of the exponent e by one of our first algorithms. If the exponent is already in
binary, we can save that step.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Codes and cyphers Chapter | 8 175

Algorithm 8.14. Let n ∈ N. To compute x e set with e a K-bit binary number


with binary representation e = bK−1 · · · b0 . Set P0 = 1 and x0 = x.
At the kth step set Pk+1 = Pk , xk+1 = xk2 , if bk = 0, and set Pk+1 = Pk xk ,
xk+1 = xk2 , if bk = 1.
The algorithm halts at the (K − 1)th step, and then x e = PK . ♥
The number of steps in the algorithm is the number of bits in e, and the
number of multiplications in each step is 1 if bk = 0 and 2 if bk = 1. So the
worst case is 2b, twice the number of bits.
To encode a message of J blocks requires 2J b multiplications and 2J b =
o(2b/2 ) and Vladimir √
loses, and he loses with the best factoring algorithm as
3
well, 2J b = o(e C b ).
Let us finish Example 8.9 using fast exponentiation to compute [1013 , 2013 ,
3013 ] modulo 77. Since 13 is 1101 in binary, the algorithm gives P0 = 1,
x0 = x, P1 = 1 · x, x1 = x 2 , P2 = P1 = x, x2 = (x 2 )2 , P3 = P2 · x2 = x · (x 2 )2 ,
x3 = ((x 2 )2 )2 , and finally P4 = x · ((x)2 )2 · (((x 2 )2 )2 = x · x 4 · x 8 . Plugging
in 10, 20, 30 for x, performing 5 multiplications each and reducing modulo
77 yields [10, 48, 72]. The binary representation of 37 is 100101, which means
more work, but not as much as you might have feared. Try it decoding and see
if you get [10, 20, 30].
As a side note you might have noticed that 1013 ≡ 10 mod 77, so 10 was not
encrypted at all! In each RSA scheme there are actually numbers, for example
common multiples of p −1 and q −1, which do not get encrypted, but in practice
this is not a problem.

Exercises
1. Suppose we want to compute 1776666 . Naively we need 665 multiplications
of 1776.
How many are required by fast exponentiation?
Give an algebraic expression that illustrates how this is to be done.
Do not compute the result.
2. Use fast exponentiation to compute 722 mod 100.
3. We know from little Fermat, that 2100 ≡ 1 mod 101. Verify this with fast
exponentiation.

8.7 Case study: A Little Fermat proof


There are many ways to show Fermat’s Little Theorem. In this case study we
show the result by examining multiplicative inverses in general, and using what
we know about relations and cardinality.
Let n ≥ 2 be a fixed modulus for the remainder of this section, and let X ⊆
Zn be the set of all elements in Zn that have multiplicative inverses, and let
a ∈ X. We know from Theorem 8.2 that there is a k such that the powers of
a ∈ Zn are a, a 2 , . . . , a k , all distinct, and a k = 1.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


176 Discrete Mathematics With Logic

a a
Define a relation ≈ on X by setting x ≈ y if y ≡ xa j for some j ∈ Z.
a
The relation ≈ is reflexive since, for all x ∈ X we have x ≡ xa k .
a a
The relation ≈ is symmetric: Let x, y ∈ X, with x ≈ y. So y ≡ xa j and,
multiplying both sides by a k−j we have ya k−j ≡ xa j a k−j ≡ xa k ≡ x, which
a
says y ≈ x.
a a a
The relation ≈ is transitive: Let x, y, z ∈ X, with x ≈ y, and y ≈ z. So y ≡
a
xa i and z ≡ ya j . Substituting z ≡ (xa i )a j ≡ x(a i a j ) ≡ x(a i+j ) and x ≈ z.
a
Since ≈ is reflexive, symmetric, and transitive, it is an equivalence relation
and, as always, we are interested in the equivalence classes.
a
Let E be an equivalence class of the relation ≈ and let b ∈ E. Define a func-
tion f : {1, 2, . . . , k} → E by setting f (i) = ba i . The function is well defined
since each element ba i is equivalent to b.
The function f is onto. Every element e ∈ E is equivalent to b, and so of the
form ba i for some i, and since the powers of a i repeat after k by Theorem 8.2,
we can assume i ≤ k, so f (i) = e.
The function f is one-to-one. Let i, j ∈ {1, 2, . . . , k} be given and suppose
f (i) = f (j ). Then ba i ≡ ba j . Since b ∈ X, the element b has multiplicative
inverse c, with cb ≡ 1. So cba i ≡ cba j , and a i ≡ a j . By Theorem 8.2, i = j
and the function f is one-to-one.
a
Since f is one-to-one and onto, |E| = k. So every equivalence class of ≈
has cardinality k. If there are m equivalence classes, then |X| = km. Thus

a |X| = a km = (a k )m ≡ 1m ≡ 1 mod n. (8.1)

What does this mean if n = p is prime? In that case every non-zero element
in Zp has a multiplicative inverse, and |X| = p − 1. Thus a p−1 ≡ 1 mod p,
establishing Fermat’s Little Theorem.

8.8 Case study: The Prüfer code


Not all codes involve sophisticated number theory, as we have seen with the
Gray code and the bit vectors. Some are just based on sets and relations.
Sometime in the 1980’s, before the world-wide-web, paper posters appeared
attached with thumbtacks to the graduate student bulletin boards at Syracuse
University. Each poster announced a talk on the Prüfer code and contained the
decoration of Fig. 8.1a. The lecture was well attended, perhaps because the dec-
oration contained a coded message readable to anyone who knew the Prüfer
code. If a student paused at the decoration and decoded the message, you could
be sure that the student was studying mathematics, electrical engineering, or
computer and information science.
The decoration is the reduced relation diagram of a special and important
type called a tree. A tree is connected and has no cycles. The Prüfer code is

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Codes and cyphers Chapter | 8 177

FIGURE 8.1 a) A symmetric relation on 10 letters, a “tree”. b) The relation after four removals.

a way of encoding symmetric relations whose reduced diagram is a tree. The


Prüfer code depends on the elements related being ordered, as the letters in
the decoration are ordered alphabetically. The encoding algorithm is a simple
recursion.
Algorithm 8.15 (Prüfer Encoding). For a tree relating just two objects, do noth-
ing, and the output string is empty.
For k ≥ 1 and a tree relating k + 2 objects, form an output string of length k
on the objects related as follows. Find the largest object, say z, which is related
to exactly one other object, say y. Remove z from the relation and record y
as the first entry in the string. Then fill the remaining entries by applying this
algorithm to the tree with the node labeled z removed. ♥
According to the algorithm, the Prüfer code of the 10 letter decoration will
be a string of 8 letters starting with f , since the set of letters with exactly one at-
tachment is {a, c, d, s, t, u}, with the largest, u, related to f . Next to be removed
are t, s, and f , recording r, e, and e respectively, and the string at this point is
f ree . The remainder of the code is found from applying the algorithm to the
remaining diagram, Fig. 8.1b. The algorithm halts with an encoded 8 character
a r
message and the leftover tree ◦ ◦.
How was the original decoration created? In order to be useful, and to qualify
as a code, we must be able to decode. We must be able to start with a string and
recreate the original relation diagram. The usual decoding algorithm starts with
a r
◦ ◦ and recursively builds up the smaller relation trees produced by the
encoding algorithm.
a b
There is a much simpler decoding method which starts with ◦ ◦ and
builds up a completely different set of intermediate trees. These intermediate
trees have the property that each letter at an end node is smaller than all the
letters of the alphabet not yet appearing in the tree.
Suppose you have an alphabet  = {a, b, c, d, e, f, r, s, t, u} of 10 charac-
ters and have the code string f reebeer, which you should have found from
a b
completing the encoding algorithm on the example above. We start with ◦ ◦
which encodes as the empty string, then make a new relation which encodes as
r, then another as er, then eer, . . . . At each step we add a new alphabet element
to the tree either by subdividing the edge to the largest end node with the next
letter of the message, or adding a new end node to the next letter in the message
labeled with the smallest letter unused so far.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


178 Discrete Mathematics With Logic

a b a r
To encode r, since r does not occur in ◦ ◦, we subdivide to form ◦ ◦
b
◦. You can check that Algorithm 8.15 encodes this as r, and the end nodes
a and b are smaller than all the unused letters, as required.
To encode er, since e does not occur in the tree for r, we subdivide the edge
a r e b
to end node b with the node labeled e to form ◦ ◦ ◦ ◦. The algorithm
encodes this as er, and the end nodes are still a and b.
To encode eer, we must change strategy since e already labels a node in
the diagram. In that case, we take the smallest unused letter, in this case c, and
attach it to the node labeled e. Since c is larger than a and b, it will be the first
node removed under the algorithm, recording e, then continuing as before to
eer. The end nodes are now labeled a, b, and c, each satisfying the smallness
requirement.
The same thing must be done continuing to beer, since the letter b is also
already in the diagram. The end nodes will then be labeled a, c, and d.
So we continue. The steps are illustrated in Fig. 8.2.

FIGURE 8.2 Intermediate trees: beer, ebeer, eebeer, reebeer, and f reebeer.

If you want to try a harder one, try “Danger ahead, go back!” on the alphabet
of letters from a to s.

d a k c b o g e
You should have ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ when you get to
“go back”, after 4 subdivision and 2 additional moves. The final answer is in
Fig. 8.3.

FIGURE 8.3 The Prüfer decoded relation tree for “Danger Ahead, Go Back!”

8.9 Summary exercises


You should have learned:
• That exponents in Zn cannot be reduced modulo n.
• That in Zp , with p a prime, you can divide by any non-zero value.
• That for a prime p and a ∈ Z, a = 0 we have a p−1 ≡ 1 mod p (Fermat’s
Little Theorem).

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Codes and cyphers Chapter | 8 179

• How to determine the multiplicative order of an element of Zn .


• Additive, multiplicative, and exponential encryption schemes.
• The RSA encryption scheme.
• Fast Exponentiation.
• How to work with the little-o notation.
1. Show that for a prime p, and any a such that 0 < a < p, it must be true that
a p −1 ≡ 1 mod p.
2

2. Find 51861 mod 31.


3. Find 21601 mod 13.
4. Compute 2101010101010 mod 101. (Exponent is not written in binary.)
5. What are the possible multiplicative orders of elements in Z101 ?
6. Compute each of the following:
a) Multiplicative inverse of 100 modulo 139.
b) (11112)11112 modulo 11.
c) (87)219 modulo 109.
7. Suppose in RSA that pq = 17947 and suppose that poor Alice has been
captured, and has revealed that her encoding key is 49. What is Bob’s de-
coding key?
8. Suppose we have an RSA scheme in which p = 13 and q = 17. Suppose
Alice’s encoding key is 19. What is Bob’s decoding key? How many pos-
sible encoding keys could Alice have been assigned?
[Hint: use inclusion/exclusion.]
9. Suppose we have an RSA scheme with primes of at least 20 digits. Let p
and q be two twin primes, so q = p + 2. Show that neither Alice nor Bob
can have a key that is divisible by 3.
10. You have an RSA Scheme with primes 5 and 11. Alice has an encoding
key of 17. What is the decoding key? What is the encoding of the message
(10, 11)? You can write your encoded message as an algebraic expression,
provided it requires fewer than√12 multiplications to√accomplish.
11. Let f (n) = ln(n) and g(n) = n. Show ln(n) = o( n).
12. Use fast exponentiation to compute 1018 mod 13.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


This page intentionally left blank

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Chapter 9

Graphs and trees


9.1 Graphs
In this chapter we will discuss graphs; not graphs of functions, but graphs as
discrete objects. A graph consists of a set V of vertices, a set E of edges, and a
function ψ called an incidence function that associates to each edge e ∈ E a set
of one or two vertices of the graph called the endpoints of the edge e. Given a
graph G = (V , E, ψ), we denote its vertex set V with V (G) and its edge set E
with E(G).
To specify a graph, we need to specify all three parts of the graph: the vertex
set, the edge set, and the incidence function.

Example 9.1. Let V = {1, 2, 3, 4, 5, 6}, E = {e1 , e2 , . . . , e8 }, and let ψ : V →


P1 (V ) ∪ P2 (V ) be given by the following table.

i 1 2 3 4 5 6 7 8
ψ(ei ) {1,2} {1} {2,3} {2,4} {4,5} {3,6} {1,4} {2,4}

Then G = (V , E, ψ) is a graph. ♦

Note that graphs are discrete, not geometric objects. However, if the graph
does not have too many vertices and edges, it can be conveniently represented
with a diagram of dots and lines connecting them. See Fig. 9.1a for an example
of such a representation of the graph from Example 9.1.

FIGURE 9.1 A graph (a) and a simple graph (b) on the same vertex set.

Given a graph G = (V , E, ψ), we say that an edge e ∈ E is a loop if it


has only one endpoint, that is, if |ψ(e)| = 1. Furthermore, two distinct edges
e, e ∈ E are multiple edges in G if they have the same endpoints, that is, if
ψ(e) = ψ(e ). Multiple edges are also called parallel edges. A graph (V , E, ψ)

Discrete Mathematics With Logic. [Link] 181


Copyright © 2024 Elsevier Inc. All rights reserved.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


182 Discrete Mathematics With Logic

is said to be simple if it has no loops and no multiple edges, that is, if ψ is a


one-to-one function such that |ψ(e)| = 2 for all e ∈ E. The graph represented
in Fig. 9.1a is not simple; it has exactly one loop, namely the edge e2 , and
exactly one pair of multiple edges, namely e4 and e8 . A simple graph G is fully
described with its vertex set V (G) and its edge set E(G), provided that we are
willing to give up on edge names and identify each edge e ∈ E(G) with the set
of its two endpoints. In this case, we write G = (V , E) where E ⊆ P2 (V ).
Notice the similarity between the diagram from Fig. 9.1a and the reduced
diagrams of symmetric relations discussed in Section 6.7. This is not a coinci-
dence: a graph in which the function ψ is one-to-one corresponds to a reduced
diagram of a symmetric relation. Furthermore, as anticipated in Section 6.8, a
relation that is symmetric and anti-reflexive defines a simple graph.
Example 9.2. If we take the graph from Example 9.1, delete from it the loop
and one of its multiple edges, forget about edge names and identify each edge
with the set of its two endpoints, we obtain the simple graph G = (V , E  )
where V = {1, 2, 3, 4, 5, 6} and E  = {{1, 2}, {2, 3}, {2, 4}, {4, 5}, {3, 6}, {1, 4}},
see Fig. 9.1b. ♦
Let G = (V , E, ψ) be a graph. Two distinct vertices v, w ∈ V are said to be
adjacent, or neighbors (of each other), if they are the endpoints of some edge
e ∈ E. The degree of a vertex v ∈ V is the number of edges e such that v is an
endpoint of e, with each loop with endpoint v counted twice. A walk in G is a
sequence
v0 , e1 , v1 , e2 , v2 , . . . , vm−1 , em , vm
such that for all i ∈ {1, . . . , m}, ei is an edge in G with endpoints vi−1 and vi .
Such a walk is said to be a v0 , vm -walk. The number m of edges in a walk is its
length. A walk is closed if v0 = vm . The following special kinds of walks will
be particularly important:
• A path in G is a walk without repeated vertices.
• A cycle in G is a closed walk of positive length without repeated vertices,
except that v0 = vm .
A graph is acyclic if it contains no cycle.
Given two graphs G = (V , E, ψ) and G = (V  , E  , ψ  ), we say that G is a
subgraph of G if V  ⊆ V , E  ⊆ E and ψ  (e) = ψ(e) for all e ∈ E  . A subgraph
G of G is a spanning subgraph if V (G ) = V (G), that is, if G can be obtained
from G by removing some edges. Deleting a vertex v from a graph G means
deleting v from the vertex set, deleting every edge having v as an endpoint from
the edge set; the resulting subgraph of G is denoted by G − v. For a set of
vertices S ⊆ V (G), we denote by G − S the graph obtained from G by deleting
all vertices contained in S. In particular, a path in G is a subgraph of G, and so
is a cycle in G.
Let G be a graph. Two vertices v, w ∈ V (G) are said to be connected by
a walk (resp. by a path) if there exists a v, w-walk (resp., a v, w-path) in G.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Graphs and trees Chapter | 9 183

A shortest v, w-walk is necessarily a path, since otherwise, assuming that some


vertex x repeats, we could obtain a shorter v, w-walk by replacing the sub-walk
between two consecutive occurrences of x with a single x. Therefore, two ver-
tices are connected by a walk if and only if they are connected by a path. This
equivalence implies that the connectedness relation, , defined on V (G) by
the rule

x  y if and only if vertices x and y are connected by a path in G

is an equivalence relation, and hence its equivalence classes partition the vertex
set of the graph. A graph is said to be connected if the connectedness relation
has only one equivalence class, that is, if any two vertices are connected by a
path. See Fig. 9.2. The connected components of a graph G are its maximal
connected subgraphs. Note that the vertices of a connected component of G =
(V , E) always comprise an equivalence class of V under .

FIGURE 9.2 Two connected graphs and one disconnected.

Given a positive integer n, the complete graph of order n is the simple graph
Kn with exactly n vertices, any two of which are adjacent. Every finite simple
graph can be regarded as the subgraph of a complete graph. Given two positive
integers m and n, the complete bipartite graph Km,n is a graph with vertex
set V = B ∪ W , with |B| = m, |W | = n, B ∩ W = ∅, and E = {{b, w} | b ∈
B, w ∈ W }. You should think of the vertices in B as colored black, and those in
W as colored white. The subgraphs of the complete bipartite graph are called
bipartite, or 2-colorable. One of the graphs of Fig. 9.2 is bipartite.

Exercises
1. How many edges can a simple graph on 5 vertices have? How many edges
can a simple graph on n vertices have? What about a general graph on n
vertices?
2. Consider the graph G(V , E, ψ) of Example 9.1. Let V  = {1, 3, 6} and E  =
{e6 }. Specify ψ  such that G(V  , E  , ψ  ) is a subgraph of G. Draw G . How
many connected components does G have?
3. Consider the graph G(V , E, ψ) of Example 9.1. Let V  = {1, 3, 6} and E  =
{e1 }. Can you specify ψ  such that G(V  , E  , ψ  ) is a subgraph of G? Justify
your answer!

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


184 Discrete Mathematics With Logic

9.2 Trees
We have already encountered trees as reduced diagrams of certain special sym-
metric relations when discussing the Prüfer code in Section 8.8. We now give
a characterization of trees and discuss their importance in a practical scenario
arising in network design.

Two out of three


Theorem 9.3. Let G be a graph on n vertices. If G satisfies two of the following
three properties, then it also satisfies the third.
(a) G is connected.
(b) G has n − 1 edges.
(c) G is acyclic.
We call a graph satisfying any two of the conditions (and hence all three) a
tree. Using this two-out-of-three theorem, we can say that a tree is a connected
acyclic graph, or we can, equivalently, say a tree is an acyclic graph on n vertices
and n − 1 edges, or a tree is a connected graph on n vertices and n − 1 edges.
To see that the three conditions are quite different from each other, let us
take a small n, say n = 3, and draw a few examples of graphs that satisfy (a) in
Fig. 9.3. Since there is no condition on the number of edges, the set of graphs on
3 vertices satisfying (a) is infinite. However, if we consider graphs with exactly
two edges, i.e., satisfying (b) for n = 3, we get only finitely many types of graphs
up to relabeling the vertices (how many?), in Fig. 9.4 there are a few examples.
There are even fewer acyclic graphs on 3 vertices, since in this case loops or
parallel edges are not allowed. Fig. 9.5 shows the three types of graphs that we
get in this case (up to relabeling the vertices).

FIGURE 9.3 Some connected graphs on three vertices.

Spanning trees
In Section 8.8 we learned about the Prüfer code, a way to encode any tree relat-
ing k + 2 objects with an output string of length k. Since any string of this type
can be realized this way and also uniquely decoded, this yields a one-to-one and
onto functional relation between the set Tk+2 of all trees relating a given set of

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Graphs and trees Chapter | 9 185

FIGURE 9.4 Three graphs on three vertices and two edges.

FIGURE 9.5 All the acyclic graphs on three vertices.

k + 2 objects and the set Sk of all strings of length k over an alphabet of size
k + 2. By the multiplicative principle, the number of such strings is (k + 2)k . We
therefore have |Tk+2 | = |Sk | = (k + 2)k . Writing n for k + 2 and considering
the special case n = 1 separately, we obtain the following result, also known as
Cayley’s formula.
Theorem 9.4. For every positive integer n, the number of trees with a given set
of n vertices is nn−2 .
A spanning tree in a graph G is any spanning subgraph of G that is a tree.
Thus, Cayley’s formula can be equivalently phrased as follows: For every posi-
tive integer n, the complete graph Kn with a given set of n vertices has exactly
nn−2 spanning trees. The sequence of numbers nn−2 grows very fast. Its first ten
terms are 1, 1, 3, 16, 125, 1296, 16807, 262144, 4782969, and 100000000; in
particular, there are 108 trees with 10 vertices.
Cayley’s formula was discovered in the late 19th century, approximately
around the time when the car was invented. Clearly, cars could only become
widely popular after the cities and villages around the world became sufficiently
well connected by road networks. This brings us to problems such as the follow-
ing one. In a rural area there are 20 villages. We would like to connect them by
roads. The distance between any two villages is known, and the area is geo-
graphically sufficiently simple that the cost of building a direct road connection
between two villages is proportional to the distance between them. What is the
cheapest way of connecting all the 20 villages?
We can represent the desired road network with a connected graph whose
vertices are the 20 villages, an edge joining two villages A and B means that

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


186 Discrete Mathematics With Logic

there will be a direct road connection between A and B, and the cost of such an
edge will be given by the distance between A and B. Our goal is to construct
a graph of this type such that the total sum of the costs of the edges will be as
small as possible.
Can such a graph have a cycle? If it did, then one of the edges in a cycle
could be removed from the graph, without losing connectivity, but resulting in
a decrease in the total cost of the road network. We are therefore looking for
an acyclic connected graph, that is, a tree, connecting the given villages and of
smallest total edge cost. Such a tree is called a minimum spanning tree, and the
problem is known as the Minimum Spanning Tree problem.
Is this a difficult problem? According to Cayley’s formula, we are looking for
an optimal tree out of 2018 trees. This looks hopeless. However, in the 1920’s–
1950’s, several efficient methods for solving this problem were developed that
avoid an explicit enumeration of all possible trees. Here is a particularly simple
one.
Algorithm 9.5 (Kruskal’s algorithm). We are given a set V of vertices and
a non-negative cost function c({i, j }) on all possible edges {i, j } joining two
vertices in V .
Sort the edge costs from the smallest to the largest and set F = ∅.
Keep adding to F one edge at a time until the graph (V , F ) becomes con-
nected. At every step, add to F a cheapest edge whose endpoints are not yet
connected by a path consisting of edges from F .
Return (V , F ). ♥
Theorem 9.6. Kruskal’s algorithm correctly computes a minimum spanning
tree.
Example 9.7. Consider a set of five villages {a, b, c, d, e} and the following
distances between them:

edge cost of edge edge cost of edge


{a, b} 11 {b, d} 7
{a, c} 10 {b, e} 16
{a, d} 12 {c, d} 9
{a, e} 14 {c, e} 13
{b, c} 8 {d, e} 15

Apply Kruskal’s algorithm to compute a minimum spanning tree connecting the


five villages.

The algorithm sorts the edges according to their costs and first adds to F the
cheapest edge, {b, d}, of cost 7. The next edge considered for addition is the
edge {b, c}, of cost 8. It is added since at this point the set F contains only the

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Graphs and trees Chapter | 9 187

edge {b, d}, which means that b and c are not yet connected by a path consisting
only of edges chosen so far. The next edge considered for addition is the edge
{c, d}, of cost 9. However, since its endpoints c and d are already connected to
each other via the vertex b using only of edges in F , the edge {c, d} is not added
to F . The next edge considered for addition is the edge {a, c}, of cost 10. This
edge is added. The next edge considered for addition, {a, b}, is not added, and
neither is {a, d}. The last edge added is the edge {c, e}, at which point the tree
in Fig. 9.6 is computed. As the graph is connected, no further edges are added.
The total cost of the road network is 7 + 8 + 10 + 13 = 38. ♦

FIGURE 9.6 The cheapest way to connect five villages by roads using Kruskal’s algorithm.

Since any connected graph admits a spanning tree, Kruskal’s algorithm can
be applied to any connected graph equipped with a weight function on the
edges.

Exercises
1. Given a set S of positive integers, let us denote by RS the symmetric relation
on the set S in which two elements a, b ∈ S are related if and only if one
of them divides the other one and their quotient is prime. For example, if
S = {2, 3, 6, 8}, then there are only two pairs of elements in relation, namely
{2, 6} and {3, 6}; two distinct elements may be unrelated for two reasons:
either none of them divides the other (for example, 2 and 3) or their quotient
is not prime (for example, 8 and 2).
Decide for which of the following sets Si the reduced diagram Gi of the
symmetric relation RSi is a tree.
(a) S1 = {1, 2, 3, . . . , 9},
(b) S2 = {2, 3, 4, . . . , 9},
(c) S3 = {1, 2, 3, 5, 6, 7, 8, 9},
(d) S4 = {1, 2, 3, 5, 6, 7, 8, 9, 10},
(e) S5 = {1, 2, 3, 5, 6, 7, 8, 27},
(f) S6 = {1, 2, 3, 4, 5, 7, 8, 9}.
2. In a vast remote land, there are four tiny villages a, b, c, d, with 15, 16,
18, and 20 inhabitants, respectively. These villages have a peculiar property
that the distance in miles between any two of them equals the product of
their numbers of inhabitants. Solve the Minimum Spanning Tree problem
for these four villages.
3. Draw all trees with vertex set {a, b, c, d}.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


188 Discrete Mathematics With Logic

9.3 Searching and sorting


Trees have many applications. In this section we discuss two: searching through
a graph and sorting a list of objects using pairwise comparisons.

Searching
When working with a large graph, we usually do not have a convenient drawing
of the graph available; all we know is the set of its vertices and the set of its
edges, along with their endpoints. Equivalently, the graph can be represented
with adjacency lists, that is, a list of its vertices and, for each vertex v, a list of
edges having v as an endpoint along with the other endpoint of the correspond-
ing edge. When the graph is simple (it has no loops and no multiple edges),
this information for a vertex v can be represented simply with a list of vertices
adjacent to v.
Example 9.8. In Fig. 9.7 we show a simple graph with vertex set {a, b, c, . . . , r}
and an adjacency list representation of the graph. ♦

FIGURE 9.7 A simple graph and its adjacency list representation (in two parts).

It is often useful if we are able to systematically search the graph, that is,
examine all the vertices of a graph in such a way that, whenever possible, each
newly visited vertex is adjacent to at least one of the already visited vertices.
There are two basic ways in which this can be achieved efficiently, both us-
ing trees: the so-called breadth-first search (BFS) and depth-first search (DFS).
What these two graph searches have in common is that they both start at some
vertex s in a given graph G and compute a tree T with the following properties:
• The vertices of T are exactly the vertices v such that there exists a path from
s to v in G.
• Every edge in T is an edge in G.
However, as the names suggest, these two graph searches differ in one important
aspect:
• In BFS, the graph (or, more precisely, the connected component of the graph
containing the starting vertex s) is explored “in breadth”, meaning that upon

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Graphs and trees Chapter | 9 189

reaching some vertex v, we first visit all of its yet unvisited neighbors before
visiting the neighbors of the neighbors of v. This results in the vertices being
examined in order of their distance from the starting vertex s.
• In DFS, the connected component of the graph containing s is explored “in
depth”, meaning that upon reaching some vertex v, we first visit one of its
neighbors and then proceed recursively on that neighbor, before moving on
to another neighbor of v.
The resulting trees are called a BFS tree and a DFS tree of G, respectively.

Example 9.9 (continued). Let us run the two searches on the graph from Fig. 9.7
from the vertex a. The algorithms are not completely specified, in the sense that
we may have some freedom when choosing the next yet unvisited neighbor of
the currently visited vertex. So, in principle, even for the same starting vertex,
there may be many possible outcomes – many possible BFS and DFS trees. For
this particular example, let us agree that we will break any such ties by always
choosing the alphabetically smallest yet unvisited neighbor of the current vertex.
Using this rule, can you compute the corresponding BFS and DFS trees?

Fig. 9.8 shows the corresponding trees. ♦

FIGURE 9.8 A BFS tree (left) and a DFS tree (right) of the same graph. The numbers in paren-
theses denote the ordering of the vertices in which they were visited by the search.

BFS and DFS graph traversals have many applications. Breadth-first search
is used for computing shortest paths, for computing the connected components
of a graph, and as a subroutine in various more complicated algorithms on
graphs, the discussion on which is beyond the scope of this textbook. Depth-first
search is useful for computing the connected components of a graph, testing if
a graph is planar (see Section 9.4), searching for cycles, determining if a graph
remains connected upon deleting at most any one vertex or any set of at most
two vertices, etc.

Sorting
As you know, any two integer numbers (and, more generally, any two real num-
bers) a and b are comparable with respect to the “less than or equal” relation: it

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


190 Discrete Mathematics With Logic

must be the case that either a ≤ b or b ≤ a (or both if a = b; in the language of


Section 6.7, the relation is anti-symmetric). Two positive integers a and b with
at most kdigits are easy to compare. If they are written in the decimal system,
say, a = ki=1 ri · 10i and b = ki=1 si · 10i , with ri , si ∈ D for all i ∈ {1, . . . , k},
then a ≤ b if and only if either rk < sk or the minimum position j ∈ {1, . . . , k}
such that ri = si for all i ∈ {j, j + 1, . . . , k} satisfies j = 1 or rj −1 < sj −1 .
Since the task of comparing two given positive integers is easily solved, let
us consider it as a basic computational task that takes one unit of time. What
if instead we have a list of n positive integers, a1 , . . . , an , which we want to
sort? That is, we want to permute the list into a sorted list, that is, a sequence
ai1 , . . . , ain such that aij ≤ aik for all j < k. With how many comparisons can
this be done?
One approach that would do the job is the following. We search through the
whole list, always keeping track of the minimum number seen so far, to find the
minimum number on the list. This number is put at the beginning of the sorted
list that we are constructing. We proceed inductively with the rest of the list
and eventually end up with a sorted list. How many comparisons do we need
with this approach? In the first traversal of the list, we always need to compare
the currently smallest number with the next number on the list, for a total of
n − 1 comparisons of two numbers. More generally, during the j -th traversal
of
n−1the list we need to perform n − j comparisons. Overall, this would result in
n−1
j =1 (n − j ) = k=1 k = n(n − 1)/2 comparisons.
But we can do much better, with a procedure called merge sort. The idea of
the procedure is that instead of sorting the entire list a1 , . . . , an , we break the list
into two approximately equal lists, one consisting of the first n/2 elements of
the list, the other one of the remaining n/2 elements, we recursively call the
same method on these shorter lists, and then combine the two sorted lists into a
single sorted list. Of course, we need to explain how to combine two sorted lists
into a single sorted list. But let us first illustrate on a concrete example how the
calculation can be conveniently organized into a tree structure.

Example 9.10. Consider the following list of 13 integers: 3, 19, 6, 8, 12, 11,
10, 22, 4, 1, 7, 9, 18. The list is broken into smaller and smaller lists, until we
obtain lists of size 1, which are trivial to sort, see Fig. 9.9. ♦

FIGURE 9.9 Simplifying the problem of sorting a list of integers.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Graphs and trees Chapter | 9 191

Let us now explain how to combine two sorted lists into a single sorted list.
Suppose that we have two sorted lists of integers, b1 , . . . , bk and c1 , . . . , c . We
create a new list L which is initially empty but will eventually become a single
sorted list combining the two given sorted lists. We introduce a pair of indices i
and j , each responsible for traversing one of the two initial lists. We traverse the
two lists in parallel, always keeping track of the next element for each list that is
the candidate for extending the current partially built list L. We initialize i = 1
and j = 1. If we have not yet exhausted any of the two lists, that is, if i ≤ k and
j ≤ , then we compare the current elements bi and cj . If bi ≤ cj , we append bi
at the end of L and increase i by 1. Otherwise, we append cj at the end of L and
increase j by 1. Sooner or later one of the two original lists will be completely
traversed, at which point we add the remaining elements of the other list at the
end of L. More precisely, if i ≤ k and j > , we append bi at the end of L and
increase i by 1, and if i > k and j ≤ , we append cj at the end of L and increase
j by 1. The algorithm stops when i > k and j > , at which point L is a sorted
list of integers that appeared in the combined list b1 , . . . , bk , c1 , . . . , c . Since at
every step exactly one of the indices i and j is increased by one, we conclude
that the total number of comparisons performed is bounded by the sum k +  of
the lengths of the two lists.
Example 9.11. Consider the following two lists: (b1 , . . . , b7 ) = (3, 6, 8, 10,
11, 12, 19) and (c1 , . . . , c6 ) = (1, 4, 7, 9, 18, 22). The steps of the merging al-
gorithm are as follows:
• Initialization: L = (), i = j = 1.
• c1 = 1 < b1 = 3, we append c1 at the end of L to obtain L = (c1 ) = (1); we
increase the value of j to 2.
• b1 = 3 ≤ c2 = 4, we append b1 at the end of L to obtain L = (1, 3); we
increase the value of i to 2.
• The next values appended at the end of L are, in order: c2 = 4, b2 = 6, c3 = 7,
b3 = 8, c4 = 9, b4 = 10, b5 = 11, b6 = 12, c5 = 18, and b7 = 19.
• At this point we have i = 8, meaning that we have used up all the elements
from the first list. We append the remaining elements from the other list (in
this case only one, c6 = 22) at the end of L, to obtain final the merged list
L = (1, 3, 4, 6, 7, 8, 9, 10, 11, 12, 18, 19, 22). ♦
Now that we have explained how to merge two sorted lists, the algorithm
is clear: we traverse the tree that we constructed in the first step, when break-
ing down the problem to simpler subproblems, in the opposite direction, from
smaller to larger problems. At each step, we merge two sorted lists using the
procedure we described above. Once the procedure is finished, we will have
sorted the initial list.
How many comparisons do we need in the worst case? If we denote by T (n)
the number of comparisons needed in the worst case by the merge sort procedure
when sorting a list of n integers, then the following holds: T (1) = 0 and for all
n > 1, we have T (n) ≤ T ( n/2 ) + T (n/2) + n. Using induction on k, it can

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


192 Discrete Mathematics With Logic

be shown that for all k ≥ 0, we have T (2k ) ≤ k · 2k (see Exercise 2 at the end
of the section). Thus, if we denote by k the smallest integer such that n ≤ 2k ,
then 2k−1 < n, or equivalently k < log n + 1 and 2k < 2n, and we infer that
T (n) ≤ T (2k ) ≤ k · 2k < 2n · (log n + 1). This implies the following:
Theorem 9.12. The merge sort algorithm sorts a list of n positive integers with
fewer than 2n · (log n + 1) comparisons.
This is much better than n(n − 1)/2 comparisons. For example, for n = 100,
we have at most 1528 comparisons instead of at most 4950, but the larger the
value of n, the more dramatic the difference; in fact 2n · (log n + 1) = o(n(n −
1)/2).
Let us also note that the above theorem holds in a much more general setting,
namely for sorting objects from any set S equipped with a partial order  such
that any two objects a, b ∈ S are comparable (that is, at least one of a  b or
b  a holds).
In conclusion, we return to our working example, Example 9.10.
Example 9.13 (continued). We now traverse the tree from Fig. 9.9 bottom up
and at every step merge two sorted lists into a larger sorted list. See Fig. 9.10.

FIGURE 9.10 Merging the sorted lists iteratively from bottom to top.

As you have probably noticed, the last merging is the one from Exam-
ple 9.11. ♦

Exercises
1. Sort the following list of integers using merge sort:

12, 22, 53, 17, 4, 9, 17, 99, 0, 8, 11, 20, 7, 18, 33, 21, 24, 5, 28, 42 .

Show all your work.


2. Let T be a function mapping positive integers to nonnegative integers such
that T (1) = 0 and T (2k ) ≤ 2T (2k−1 ) + 2k for all k ≥ 0. Show using induc-
tion on k that T (2k ) ≤ k · 2k for all k ≥ 0.
3. Among all orderings of {1, 2, 3, 4} find the one for which mergesort uses the
largest number of comparisons.
Repeat this for {1, 2, . . . , 8} and {1, 2, . . . , 16}.
Can you generalize to {1, 2, . . . , 2k }?

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Graphs and trees Chapter | 9 193

9.4 Planarity
In Section 9.2, we learned how to connect a given set of geographical locations
(for example, cities or villages) by roads in a cheapest possible way. In reality,
once the roads are built, the network typically contains many more roads than
predicted by a solution to the Minimum Spanning Tree problem. This is because
we want the network not only to be connected but to allow for overall fast travel
times between different cities. On a more local scale, a similar phenomenon
occurs also in networks of streets within a city.
Imagine a situation where we have five important cities that we would like to
pairwise connect withdirect
 road connections. While we are prepared to build
all the corresponding 52 = 10 roads, we would like to do so without incurring
additional expenses and risks related to building bridges or tunnels. Can this be
achieved?

If you try to solve this puzzle with paper and pencil, you will quickly realize
that it is not possible to achieve the desired design of roads; at least one pair
of cities must remain unconnected if bridges and tunnels are to be avoided. See
Fig. 9.11 for an example, where, with the other roads in place, Zurich and Bled
cannot be connected by a direct road, even if the last road were not required to
be straight.

FIGURE 9.11 Five cities and roads between them.

A similar situation can occur even without requiring all possible pairs of
cities to be connected. A classical mathematical puzzle known as the three util-
ities problem or sometimes water, gas, and electricity asks for non-crossing
connections to be drawn between three houses and three utility companies. (Try
it! You can place the house and companies wherever you like in the plane.)

The graph in Fig. 9.11 is planar, which means that it can be drawn in the
plane without edge crossings. The complete graph K5 and the complete bipartite
graph K3,3 are both non-planar, there is no way to draw them in the plane even
with curved edges!
When we draw a graph we represent the vertices by dots and the edges by
curves.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


194 Discrete Mathematics With Logic

In Fig. 9.12 we see a planar graph and several drawings of it, the leftmost
drawing has crossing edges.

FIGURE 9.12 Drawings of the cube graph with crossing edges and without.

Cutting along the edges of a non-crossing drawing divides the plane into
different regions which we call faces. We can describe the face set F by closed
walks in the graph by imagining walking on a face close to the cuts. The triple
G = (V , E, F ) is called a plane graph.
In Fig. 9.13 we indicate the faces by shadings. The inside white face is
described by the walk A, (A, b), b, (b, D), D, (D, c), c, (c, A), A. The outside
white face is described by the walk d, (d, C), C, (C, a), a, (a, B), (B, d), d.
Note that all these walks are actually cycles.

FIGURE 9.13 A drawing of the cube graph dividing the plane into 6 faces.

It seems intuitive that a simple graph with many edges, such as a complete
graph on n ≥ 5 vertices, will be impossible to draw without edge crossings.
To obtain a bound on the maximal number of edges in terms of the number of
vertices of a simple planar graph, we might ask the following question. How
many edges does a connected plane graph G on n vertices have if all faces are
triangles (i.e., cycles of length 3)?

Since G is connected, it contains a spanning tree T , and T has n − 1 edges.


Consider a plane drawing of G and cut along the edges of T . Your piece of paper
is still connected and you may consider it a (2n − 2)-gon, see Fig. 9.14. By a
simple inductive argument you find that k −3 diagonals are needed to triangulate

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Graphs and trees Chapter | 9 195

FIGURE 9.14 Turning the exterior of a tree inside out.

FIGURE 9.15 A triangulation.

a k-gon, see Fig. 9.15. That means G has n − 1 + 2n − 2 − 3 = 3n − 6 edges.


For instance, you can verify this count on the graph of Fig. 9.11.
Given a plane graph G = (V , E, F ) let us look at the collection F of walks.
It is clear that we have written every edge exactly twice. We can therefore define
a dual graph G∗ on the new vertex set F and on the same edge set E by defining
two faces to be adjacent if the corresponding walks contain the edge e ∈ E. In
fact, we get a plane graph G∗ (F, E, V ) by interchanging the roles of F and V .
Fig. 9.16 shows two different planar drawings of the same planar graph,
both of which have four faces: three interior faces and one exterior face (which
contains the margins of your sheet of paper).

FIGURE 9.16 Two plane graphs G1 and G2 corresponding to the same planar graph.

To understand why these two drawings are not considered equivalent to each
other, look at the faces. The graph G1 has for example a face which is a 3-cycle,
while G2 does not. This example also shows that the dual of a simple plane
graph need not be simple.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


196 Discrete Mathematics With Logic

If we have a connected plane graph and apply the dual operation twice, we
get back to the same graph.
Interestingly, as shown by the Swiss mathematician Leonhard Euler, while
a planar graph may have many non-equivalent planar drawings, the number of
faces in any such embedding is always the same; in fact, it depends only on the
number of vertices and edges of the graph.
Theorem 9.14 (Euler’s formula). Let G be a connected plane graph and denote
by n the number of vertices, by e the number of edges, and by f the number of
faces of G. Then n − e + f = 2.
Proof sketch. Consider a spanning tree T of G. If T = G, then Euler’s formula
holds as in this case e = n − 1 and f = 1. Consider the edges not in T in some
order {e1 , e2 , . . .}. Cutting along e1 cuts the face created by T into two pieces,
an interior piece, and an exterior one. Since we started with a plane graph G, e2
is completely contained in one of the faces we have created so far, hence cuts
one of the given faces into two pieces. We therefore create e − (n − 1) + 1 = f
faces.
Our proof of Euler’s formula is an induction proof, namely induction on e.
It also provides, using the two-out-of-three theorem, a remarkable property of
plane graphs: There are f − 1 edges not in T , they correspond to f − 1 edges
separating two faces – or connecting two vertices of the dual graph, so they
are the edges of a spanning tree (by count and connectivity) of the dual graph.
A pair of complementary trees for the plane graphs of Fig. 9.16 is highlighted
in Fig. 9.17.

FIGURE 9.17 Complementary trees.

Using Euler’s formula, we can now re-derive, as a check, our upper bound on
the number of edges in a simple planar graph with a given number of vertices.
The bound can be further improved if G is triangle-free, that is, it does not
contain any three pairwise adjacent vertices.
Theorem 9.15. Let G be a simple planar graph with exactly n ≥ 3 vertices and
e edges. Then e ≤ 3n − 6. Furthermore, if G is triangle-free, then e ≤ 2n − 4.
Proof. Assume first that G is connected. Fix an arbitrary planar embedding of
G and let us denote by f the number of faces. For a face F , the length of F is

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Graphs and trees Chapter | 9 197

the number of edges in the walk bounding the face (counted with multiplicities).
For example, the graph G1 in Fig. 9.16 has faces of four different lengths, 3, 4, 5,
and 6. Let us denote by S the sum of the lengths of the faces. Since n ≥ 3 and G
is simple, each face has length at least three. Thus S ≥ 3f . On the other hand,
since each edge appears on the boundary of exactly two faces (or it appears
twice on the boundary of a single face), each edge contributes exactly 2 to the
sum S, which implies that S = 2e. By Theorem 9.14, we have that e − n + 2 = f .
Multiplying by 3, we obtain 3e −3n+6 = 3f ≥ S = 2e, from which the claimed
inequality e ≤ 3n − 6 follows. If G is triangle-free, then S ≥ 4f and hence
4e − 4n + 8 = 4f ≤ S = 2e, implying e ≤ 2n − 4.
If G is not connected, then we can add edges to it to obtain a simple con-
nected planar graph G (which can be made triangle-free if G is triangle-free).
The two inequalities for G will imply the desired conclusion for G, too.

By Theorem 9.15, every simple planar graph with 5 vertices has at most
9 edges. Since the complete graph K5 has 10 edges, we conclude that it is
nonplanar. Similarly, the complete bipartite graph K3,3 is nonplanar since it is
triangle-free and has 9 edges, while every simple planar triangle-free graph with
6 vertices has at most 8 edges.
We close this section by explaining in which sense these two graphs, K5 and
K3,3 , are essentially the only reason for which a graph may fail to be planar. Let
us first describe an operation that preserves planarity. Given a graph G and an
edge e in G with endpoints u and v, the subdivision of e is the operation that
replaces the edge e in G with a path of length two; formally, it deletes the edge
e, adds a new vertex z, and adds two new edges, one with endpoints u and z, and
one with endpoints z and v. The subdivision of a graph G is any graph obtained
from G by repeatedly subdividing some (possibly none) of its edges. Given two
graphs G and G , we say that G contains G if G can be obtained from G by a,
possibly trivial, sequence of vertex and edge deletions.
Given two graphs G and G such that G is a subdivision of G, it is not
difficult to check that G is planar if and only if G is planar. In particular, all
subdivisions of K5 and K3,3 are nonplanar. Furthermore, when a vertex or an
edge is deleted from a plane graph, the resulting graph is still a plane graph.
This means that each graph contained in a planar graph is planar. We conclude
that whenever a graph contains a subdivision of K5 or K3,3 , we can be sure that
it is nonplanar. As shown by the Polish mathematician Kazimierz Kuratowski in
1930, the absence of subdivisions of K5 or K3,3 is not only a necessary condition
for planarity but also a sufficient one!

Theorem 9.16 (Kuratowski’s theorem). A graph is planar if and only if it does


not contain a subdivision of K5 or K3,3 .

What this means is that there is always a good way to certify the planarity
or nonplanarity of a given graph. If the graph is planar, we can certify this by
drawing it in the plane without edge crossings. If the graph is nonplanar, we can

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


198 Discrete Mathematics With Logic

certify this by exhibiting an appropriate subdivision of K5 or K3,3 contained in


the graph.

Exercises
1. Let G be the simple graph with vertex set {1, 2, 3, . . . , 9} in which two dis-
tinct vertices are adjacent if and only if they are coprime. The graph H is
defined similarly, except that two distinct vertices are adjacent if and only if
they are not coprime.
(a) Show that G is not planar by showing that it has too many edges / that it
contains a K3,3 / that it contains a K5 .
(b) Show that the graph H is planar by drawing a planar embedding of it.
2. Derive the bound for the maximal number of edges in a bipartite simple
planar graph.
3. Draw a plane embedding of K4 and its dual graph. Verify that for each span-
ning tree the complementary edges form the edges of a dual spanning tree.

9.5 Eulerian graphs


In this section and the next one, we will be looking at two further problems
on graphs, with obvious interpretations in practical settings where the graph
represents a network of streets within a city or a network of roads between
cities.
The first problem is the following: Given a graph G, can all the edges of G
be traversed so that no edge repeats? Graphs for which the answer is affirmative
can be described by means of a simple criterion discovered in 1736 by Euler.
The paper in which he solved the special case of the problem known as the
Seven Bridges of Königsberg (see Exercise 1 at the end of the section) is now
widely considered as the first paper of graph theory.
The problem asks about the existence of an Eulerian trail in a graph, a
traversal of all the edges such that no edge repeats. An Eulerian trail starting
and ending in the same vertex is said to be an Eulerian circuit. A more formal
definition is as follows.

Definition 9.17. Given a graph G, a trail in G is a walk

v0 , e1 , v1 , e2 , v2 , . . . , vk−1 , ek , vk

without repeated edges. An Eulerian trail in G is a trail containing all the edges
of G. An Eulerian circuit is an Eulerian trail with v0 = vk . A graph is said to be
Eulerian if it admits an Eulerian circuit. ♠

For example, the graph depicted in the left part of Fig. 9.18 is Eulerian, as
evidenced by the traversal of the edges depicted in the right part of the figure.
Note that vertex repetitions are perfectly ok.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Graphs and trees Chapter | 9 199

FIGURE 9.18 A graph with 23 edges and an Eulerian circuit in it.

An isolated vertex in a graph is a vertex that is not the endpoint of any edge.
If a graph has an isolated vertex v, then deleting v does not affect the existence
of Eulerian trails or circuits. Therefore, when addressing this problem we may
without loss of generality restrict our attention to graphs without isolated ver-
tices. Another easy observation is that if a graph has an Eulerian trail, then any
two of its edges must be connected by a path; that is, all the edges of the graph
must belong to the same connected component. (Do you see why?)
It is not difficult to construct examples of connected graphs that admit an
Eulerian trail but not an Eulerian circuit, or connected graphs that do not admit
an Eulerian trail.

Example 9.18. In Fig. 9.19, two small connected graphs G1 and G2 are de-
picted.

FIGURE 9.19 Two graphs G1 and G2 .

The graph G1 admits an Eulerian trail but not an Eulerian circuit. Traversing
the only edge in either direction yields an Eulerian trail. Since we cannot return
to the starting vertex without traversing the same edge again, the graph does not
admit an Eulerian circuit.
The graph G2 does not admit an Eulerian trail. Do you see why?

Every time an Eulerian trail in a graph visits a vertex, it either has to stop
at that vertex or it has to leave the vertex on a yet unvisited edge. Therefore,

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


200 Discrete Mathematics With Logic

the edges around every vertex, except possibly for the starting and the ending
vertex, can be grouped into disjoint pairs, one for each visit of the vertex. Since
in an Eulerian trail all the edges are traversed, we can conclude that all vertices
of the graph, except possibly two, must have an even degree. Going back to
our example graph G2 , note that all the four vertices of the graph have an odd
degree. It follows that G2 does not have any Eulerian trails. ♦

As observed above, a necessary condition for a connected graph to have an


Eulerian trail is that it has at most two vertices of odd degree. Since every graph
has an even number of vertices of odd degree (see Exercise 2 at the end of
the section), this is equivalent to the condition that the number of odd-degree
vertices is either 0 or 2. Euler showed that this obvious necessary condition for
the existence of an Eulerian trail is also sufficient. Furthermore, the absence of
odd-degree vertices leads to a criterion for the existence of an Eulerian circuit.

Theorem 9.19. Let G be a graph without isolated vertices. Then G has an Eu-
lerian trail if and only if G is connected and the number of odd-degree vertices
is either 0 or 2. Furthermore, G has an Eulerian circuit if and only if G is
connected and all its vertices have an even degree.

Proof. Assume first that G has an Eulerian trail v0 , e1 , v1 , e2 , v2 , . . . , vm−1 ,


em , vm . Since G has no isolated vertices, in order to show that G is connected,
it suffices to show that any two edges ei and ej , i < j , are connected by a walk
in G. Such a walk can be found by following the part of the Eulerian trail from
ei to ej . Thus, G is connected. We have already presented in Example 9.18 a
pairing argument showing that all the vertices of G except possibly v0 and vm
have even degree. If G has an Eulerian circuit, with v0 = vm , then the first and
the last edge in the circuit have v0 as a common endpoint, and we can also pair
these two edges up. In this case, all the vertices of G, including v0 , must have
an even degree.
Next, let us show that the conditions are sufficient. Assume first that G is
connected and all its vertices have even degree. Pick a vertex v and start travers-
ing edges in v as long as possible, subject to the condition that no edge is ever
repeated. Since the graph is finite, this process eventually stops and computes
some trail in G starting at v. Let us denote by w the final vertex of this trail,
that is, the vertex in which the process stopped. If w = v, then an odd number of
edges around w was used: one for the last visit of w (after which it was not pos-
sible to leave w), and two for each previous visit. However, since w has an even
degree, there is an edge at w that was not yet traversed, hence our traversal could
not stop at w. This contradiction shows that the process stopped at v, that is, we
obtained an Eulerian circuit of the graph formed by the edges traversed so far.
Note that we used an even number of edges around each vertex. Since all
the degrees are even, this means that the number of remaining edges around
each vertex is also even. If we already used up all the edges of the graph, then
we have constructed an Eulerian circuit. So we may assume that this is not the

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Graphs and trees Chapter | 9 201

case. Since the graph is connected, there exists a vertex z that is an endpoint of a
traversed edge as well as an endpoint of an edge that has not yet been traversed.
We now repeat the same procedure starting at the vertex z and using only the
edges not used so far. Using the same arguments as above, we obtain another
trail starting and ending at the vertex z. Combining the two trails by traversing
the first one until the vertex z, then traversing the second one, and finally contin-
uing along the first one until the end, results in an Eulerian circuit of the graph
formed by the edges traversed so far. Repeating the procedure, we eventually
obtain an Eulerian circuit in the entire graph G.
It remains to analyze the case when G is connected and has exactly two
vertices of odd degree, say u and v. Adding to G an edge e with end-
points u and v we obtain a connected graph G in which all vertices have
an even degree. Therefore, G has an Eulerian circuit. Fix an Eulerian circuit
v0 , e1 , v1 , e2 , v2 , . . . , vm−1 , em , vm in G . Since v0 = vm , we may assume, by a
circular shifting of the indices if necessary, that the edge e appears at the end of
the circuit, that is, em = e. But then v0 , e1 , v1 , e2 , v2 , . . . , vm−2 , em−1 , vm−1 is
an Eulerian trail in G.

The above proof suggests a procedure to construct an Eulerian circuit in a


connected graph in which all vertices have an even degree. It can be shown that
it is always possible to select the next edge so that the edges not yet used form
a connected graph. Following this rule, we end up with an Eulerian circuit.

Exercises
1. The city of Königsberg in Prussia (now Kaliningrad, Russia) was set on both
sides of the Pregel River. There were two large islands and two mainland por-
tions of the city, which were connected to each other by seven bridges. The
problem of the Seven Bridges of Königsberg was to devise a walk through
the city that would cross each of those bridges exactly once. Euler showed
that such a walk exists if and only if the graph depicted in Fig. 9.20 contains
an Eulerian trail. Assuming this, explain why the desired walk through the
city does not exist.

FIGURE 9.20 The graph of the seven bridges of Königsberg.

2. Show that in any graph G, the number of odd-degree vertices is even.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


202 Discrete Mathematics With Logic

3. Fig. 9.21 shows three graphs. For each of them determine if the graph con-
tains an Eulerian trail and whether it contains an Eulerian circuit. If an
Eulerian trail exists, find one.

FIGURE 9.21 Three graphs.

9.6 Hamiltonian graphs


In the previous section we considered the problem of traversing all the edges of
a given graph so that no edge repeats. Following Euler, we gave a necessary and
sufficient condition for a graph to possess such a walk. In this section we turn
to a similar question, but for vertices: Given a graph G, can all the vertices of G
be traversed so that no vertex repeats? A walk with such a property is called a
Hamiltonian path.
In the case of Eulerian trails, we allowed for the last vertex of the trail to
coincide with the first one. It is natural to allow this also for walks traversing
vertices – just think of a tourist who wants to visit all the main attractions in
the city before returning back to the hotel room. Such a walk traversing all the
vertices, without repetitions except that the first and the last vertex coincide,
is called a Hamiltonian cycle. Hamiltonian paths and cycles are named after
William Rowan Hamilton, a 19th century Irish mathematician, astronomer, and
physicist who invented a mathematical game which involves finding a Hamilto-
nian cycle in the edge graph of the dodecahedron (see Fig. 2.1 on p. 43).
Definition 9.20. Given a graph G, a Hamiltonian path in G is a path containing
all the vertices of G. A Hamiltonian cycle in G is a cycle containing all the
vertices of G. A graph is said to be traceable if it possesses a Hamiltonian path
and Hamiltonian if it possesses a Hamiltonian cycle. ♠
If we traverse any Hamiltonian cycle in a graph G and stop the traversal just
before returning to the initial vertex, we obtain a Hamiltonian path. Therefore,
every Hamiltonian graph is traceable. The converse is not true. (Do you see
why?)
Example 9.21. Consider the three connected graphs G1 , G2 , and G3 depicted
in Fig. 9.22. The graph G1 is Hamiltonian (and therefore traceable); the edges
traversed by one particular Hamiltonian cycle in G1 are depicted thick. The
graph G2 is traceable; a Hamiltonian path in G2 is depicted with thick edges.
However, the graph G2 is not Hamiltonian. The graph G3 is not traceable (and
therefore not Hamiltonian).

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Graphs and trees Chapter | 9 203

FIGURE 9.22 Three graphs that behave differently with respect to Hamiltonian paths and cycles.

Do you see why the graph G2 is not Hamiltonian and why the graph G3 is
not traceable?

Deleting any k ≥ 1 vertices from a cycle results in a graph with at most k
connected components. Consequently, if we delete any k vertices from a Hamil-
tonian graph, we obtain a graph with at most k connected components. Similarly,
deleting any k ≥ 0 vertices from a path results in a graph with at most k + 1 con-
nected components. Hence, if we delete any k vertices from a traceable graph,
the resulting graph has at most k + 1 connected components. Let us now apply
these considerations to the graphs G2 ad G3 . If we remove from the graph G2
the middle vertex, the top vertex, and the bottom vertex, we obtain a graph with
4 connected components. We conclude that G2 is not Hamiltonian. Similarly,
if we remove the middle, top, and the bottom vertices from the graph G3 , we
obtain a graph with 5 connected components, and we conclude that G3 is not
traceable. ♦

Note that if a graph G has a loop, then G is traceable if and only if the graph
obtained from G by deleting a loop is traceable, and a similar argument holds
if G contains a pair of edges with the same endpoints. Furthermore, except for
graphs with one or two vertices, similar simplifications on the graph can be done
when studying the property of being Hamiltonian. Therefore, when studying
Hamiltonian paths and cycles, it suffices to consider simple graphs.
Although perhaps surprising at first, you may have guessed from the above
examples that the problem of determining the existence of Hamiltonian paths
and cycles is much more difficult than for Eulerian trails. No simple necessary
and sufficient condition for a graph to be Hamiltonian or traceable is known,
and the problems of deciding if a given graph possesses a Hamiltonian path or
a Hamiltonian cycle are NP-complete – just like the problem we talked about in
Section 4.7, of determining if a given expression in conjunctive normal form ad-
mits a Boolean assignment to the variables which makes the expression TRUE.
This means that no fast solution methods for the Hamiltonicity and traceabil-
ity problems are known. These problems become difficult to solve already for
moderately sized graphs.
Some necessary conditions are known, as well as some sufficient ones. We
have already described in the above example the following necessary conditions.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


204 Discrete Mathematics With Logic

Theorem 9.22. If G is a traceable graph, then for every set S ⊆ V (G) the
graph G − S has at most |S| + 1 connected components. Furthermore, if G is
Hamiltonian, then for every nonempty set S ⊆ V (G) the graph G − S has at
most |S| connected components.
We would expect a simple graph to have a better chance to be Hamiltonian
if all the vertices are connected by edges to many other vertices. This is indeed
the case, as shown by the following sufficient condition for Hamiltonicity due
to Dirac.
Theorem 9.23. Let G be a simple graph with n ≥ 3 vertices such that each
vertex has degree at least n/2. Then G is Hamiltonian.
Proof. The proof uses induction in a particularly clever way. Fix a positive in-
teger n ≥ 3 and let us denote by Xn the set of all n-vertex graphs in which each
vertex has a degree at least n/2. Associate to each
 graph G ∈ Xn the number
e(G) of non-edges in G, that is, the value of n2 − |E(G)|. Then e(G) ≥ 0. To
show that each graph G ∈ Xn is Hamiltonian, we use induction on the value of
e(G).
Base case: e(G) = 0, that is, the graph G ∈ Xn contains all possible edges
between two distinct vertices. Since n ≥ 3, visiting all the vertices of G in some
order and returning back to the first vertex yields a Hamiltonian cycle.
Inductive step: Let k ≥ 0 be given and assume that every graph H ∈ Xn with
e(H ) = k is Hamiltonian. Consider a graph G ∈ Xn with e(G) = k + 1. We
need to show that G is Hamiltonian. Suppose for a contradiction that G is not
Hamiltonian. Since e(G) > 0, there exist two nonadjacent vertices in G, say u
and v. The graph H obtained from G by adding to it the edge {u, v} belongs to
Xn and satisfies e(H ) = e(G) − 1 = k. Therefore, by the induction hypothesis,
H is Hamiltonian. Fix a Hamiltonian cycle C in H . Since G is not Hamiltonian,
the cycle C must use the added edge {u, v}. We may assume that the cycle C
starts at u but not along the edge {u, v} and hence there is an ordering v1 , . . . , vn
of the vertices of G such that u = v1 , v = vn , and any two vertices that are
consecutive in the ordering are adjacent in G. (In particular, G is traceable.)
Let A denote the set of neighbors of u in G and let B = {vi+1 | 1 ≤ i ≤ n −
1 and vertices v and vi are adjacent in G}. Since each vertex in G has degree at
least n/2, we infer that |A| ≥ n/2 and, similarly, |B| ≥ n/2. Furthermore, since
u = v1 belongs to neither A nor B, we have A ∪ B ⊆ {v2 , . . . , vn } and thus
|A ∪ B| ≤ n − 1. It follows that the sets A and B cannot be disjoint, as that
would imply |A ∪ B| = |A| + |B| ≥ n. Using an arbitrary vertex vj ∈ A ∩ B,
we can now construct a Hamiltonian cycle in G, as follows. Starting at u, go to
vj (note that this is possible since vj ∈ A is adjacent to u), then continue via
vj +1 all the way up to vn = v, then go to vj −1 (note that this is possible since
vj ∈ B implies that vj −1 is adjacent in G to v), and go back all the way down to
v1 = u. We conclude that G is Hamiltonian, contradicting our assumption that
G is not Hamiltonian. This completes the inductive step and with it the proof of
the theorem.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Graphs and trees Chapter | 9 205

Despite the difficulty of the Hamiltonicity problem, variants of the problem


have many important practical applications. Of particular relevance is the Trav-
eling Salesman Problem, which is defined similarly as the Minimum Spanning
Tree but much more difficult. The traveling salesman would like to visit a num-
ber of cities before returning back to his home town. The distance between any
two cities is known. What is the least distance that the salesman must travel in
order to visit all the cities?

Exercises
1. Describe all traceable trees. Are there any Hamiltonian trees?
2. For each of the graphs in Fig. 9.23, determine whether it is traceable and
whether it is Hamiltonian. Justify your answer.

FIGURE 9.23 Three small graphs.

3. Find an example of a connected graph with 6 vertices and 8 edges that is:
(a) Eulerian but not Hamiltonian,
(b) Hamiltonian but not Eulerian,
(c) Eulerian and Hamiltonian,
(d) neither Eulerian nor Hamiltonian.
Can you always find a simple graph with the stated properties?

9.7 Case study: Fáry’s theorem


Say we have a connected planar graph and we want to draw it so that all edges
are straight line segments that do not cross (except at the endpoints). Well, if
there is a loop, this is impossible. Also parallel edges make the task impossible.
But is it possible if the graph is simple?
In a simple graph there are no cycles with fewer than three edges, so the
smallest face one can have is a triangle, that is, a 3-cycle. Not all triangles need
to be faces. If a simple plane graph has faces of larger size, we can triangulate the
drawing, adding k − 3 new edges to each face with k edges. A look at Fig. 9.24
shows a triangulation in the upper left corner drawn with curved line segments,
and re-drawn with straight line segments in the lower right. Check carefully
that every face is a triangle. There is also a triangle, namely 156, which is not
a face and contains the vertex 2 in its interior. If all faces are triangles, we
cannot add any more edges and we speak of an edge maximal planar graph

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


206 Discrete Mathematics With Logic

or a triangulation. István Fáry showed in 1948 that if a finite simple graph G


can be represented in the plane at all, then it can be represented in the plane
with straight segments as edges. We now sketch a proof of Fáry’s theorem.

FIGURE 9.24 Fáry’s induction step applied repeatedly.

Theorem 9.24. An edge maximal simple planar graph can be drawn in the
plane with non-crossing straight line segments as edges.
Proof. Consider an edge maximal simple planar graph G. We want to show by
induction on the number n of vertices that G can be drawn with straight line
segments. This is clear for n = 3. Note that in this base case, G = K3 , we have
three vertices, 3 edges, and two faces. The triangle cuts the plane into two pieces,
an interior and an exterior.
For n > 3 we want to first prove by strong induction that there always exists
a vertex v in the interior of the outside triangle and an edge e with endpoint v
such that e is contained in exactly two triangles. For n = 4, the graph is a K4
and the statement holds trivially, since any edge belongs to exactly two trian-
gles. Assume now that n > 4 and that the statement holds for all triangulations
with fewer than n vertices. Let G be a triangulation with n vertices and let v
be any vertex in the interior of the outside triangle. Take any edge e with end-
point v. If the edge e is contained in exactly two triangles, we are done. So we
may assume that the edge e is contained in two facial triangles and also in a
third triangle T . The triangle T contains exactly one of the two triangular faces
separated by e. So T contains a vertex in the interior. Let H be the subgraph of
G consisting of the triangle T and all the vertices and edges drawn in the interior
of T . Then H is an edge maximal simple planar graph with at least 4 vertices
with fewer vertices than G. By the induction hypothesis, there exists a vertex w
of H in the interior of the triangle T and an edge f ∈ E(H ) with endpoint w
such that f is contained in exactly two triangles in H . Due to the planarity of

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Graphs and trees Chapter | 9 207

the drawing, this vertex and edge satisfy the same properties also with respect
to the graph G.
Now let G be any edge maximal simple planar graph on n vertices, and
consider an edge e = {a, b} which separates the facial triangles (a, b, v1 ), and
(a, b, v2 ) and is contained in no other triangle. Identifying the two endpoints
a and b into a vertex v creates parallel edges {a, vi }, {b, vi }, i = 1, 2, but no
other parallel edges. Replacing each of these pairs of parallel edges by a single
edge {v, vi } we obtain a simple graph on n − 1 vertices that is a planar trian-
gulation and can, by induction hypothesis, be drawn with straight lines. In such
a straight line drawing consider the edges emanating from v. One of the two
angles formed by edges {v, v1 } and {v, v2 } contains all edges inherited from
G which had endpoint a in G, the other all the ones which had endpoint b
in G. So we can split v into two vertices a and b a short distance apart, draw
in the straight line segment from a to b, and split the line segments {v, vi } into
two line segments from a, resp. b, to vi . This yields a straight line drawing
of G.

Fig. 9.24 illustrates how the proof can be turned into an algorithm. The in-
duction step applied repeatedly reduces the triangulation to a triangle – and then
we may work backwards, reconstructing the graph step by step, but with straight
line edges.
Could we have started the process by identifying vertices 1 and 5? The an-
swer here is no, since the edge with endpoints 1 and 5 is contained in more
than two triangles, and identifying 1 and 5 would produce three sets of parallel
edges. However, you may want to convince yourself that e is not the only choice
for starting the procedure. Also, the straight line drawing produced is not nec-
essarily optically pleasing; you are encouraged to turn Fáry’s proof into a nice
drawing algorithm.
Note that the proof of Theorem 9.24 involves Euclidean geometry and is not
completely discrete.
We proved Fáry’s theorem for triangulations, but if we want a straight line
embedding of a plane graph that is not edge maximal, we can first triangulate
all faces that are larger than triangles, find a straight line embedding of that
triangulation and then erase the extra edges to obtain a straight line drawing
of our original graph. Triangles are always convex, but k-gons for k > 3 need
not be, so after deleting edges from a triangulation, the resulting faces need
not be convex. However, Sherman K. Stein, in 1951, proved that for a plane
graph whose faces are polygons without repeated vertices or edges, and the
intersection of two faces is connected, there always exists an embedding such
that all faces are convex. The key lemma used in the induction proof on the
number of faces is claiming the existence of two neighboring faces A and B
such that for all other faces C the set C ∩ (A ∪ B) is connected. The proof of
this lemma is essentially the same as our argument about the existence of an
edge e contained in exactly two triangles. From Stein’s result Fáry’s theorem

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


208 Discrete Mathematics With Logic

follows. Convexity is a geometric property and the faces here are considered
closed and simply connected (in the topological sense) subsets of the Euclidean
plane. We encourage you to work through Fáry’s and Stein’s original papers and
determine which of the two results is more discrete.

9.8 Case study: Towers of Hanoi


The first thing we noted about the Towers of Hanoi with n disks was that we
could encode each state with a string of n digits from {0, 1, 2}. So 2221010 has
the largest three disks on post 2 and the remaining alternating from post 1 and 0.
If we say that two states are related if there is a legal move between them,
then we have a self-relation which is anti-reflexive and symmetric, in other
words, the relation diagram can be expressed as a simple graph. What can we
say about this graph on 3n vertices? Our first reaction might be that the graph
with only 7 disks has over two thousand vertices, so only a madman would ever
want to draw or study it. But we already have been studying it. For instance,
we have shown that there is a sequence of 27 − 1 legal moves from 2222222 to
0000000. In the language of graph theory, there is a path of length 27 − 1 join-
ing vertex 2222222 to 0000000 in the Towers of Hanoi graph. We also showed
that there was a sequence of moves from any configuration to 0000000, and we
can express this graph theoretically by saying that the Towers of Hanoi graph is
connected.
Maybe it is a tree? At most states there are exactly three moves. The littlest
disk can move to either of the two posts it is not already on. Between those two
other posts, if nonempty, the smallest top disk can move, but it cannot move to
the post of the very smallest disk. That third move only fails to be possible if
all the disks are stacked under the littlest disk, i.e., for the three states 0000000,
1111111, and 2222222 when n = 7. So in the Towers of Hanoi graph, 3n − 3
vertices have degree 3 and just 3 vertices have degree 2. Counting the edges in
the usual way gives |E| = [(3n − 3)3 + 2(3)]/2 = (3n )3/2 − 1.5 > 3n − 2, too
many to be a tree even for n very small. But maybe you already saw an easier
way to explain why the graph is not acyclic? Still the graph with 7 disks has
over 3000 edges. Very big.
Let’s try to build it anyway, recursively. Take the state diagram for n disks,
and imagine a larger n + 1st disk underneath everything, but staying put on
one post. As it sits there, all the other disks n are free to move, just as before.
There are three possibilities for the lazy big disk, and each gives rise to a part
of the state diagram for the n + 1 disk graph, each is an isomorphic copy of
the n-disk graph, but with and additional number, not changing, appended to on
the left of each vertex label. We have almost drawn the whole thing! All that
is missing is that, instead of 3 vertices of degree 2, we have 9. What are they?
For the biggest disk on post 0 they are 00 · · · 0, 01 · · · 1, and 02 · · · 2. The other
six are 10 · · · 0, 11 · · · 1, 12 · · · 2. 20 · · · 0, 21 · · · 1, and 22 · · · 2. Of these 00 · · · 0,
11 · · · 1, and 22 · · · 2 have degree 2 in the n + 1 disk graph. The other six are

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Graphs and trees Chapter | 9 209

connected with the following edges: (10 · · · 0, 20 · · · 0), (01 · · · 1, 21 · · · 1), and
(02 · · · 2, 12 · · · 2).
So, recursively, we just take three copies of the n-disk graph and add three
edges between them, only joining some of the special, degree 2 vertices. What
do we start with? Just a triangle! I won’t draw it for you, in fact, in this section
you have to do all the drawing. Try. The four disk graph takes four minutes.

So now you have a beautiful picture of the Towers of Hanoi graph. It’s not
beautiful? Did you notice that the graph is planar? Before you try again, we’ll
prove that outrageous claim. We’ll do it by induction and as often happens, it is
easier to prove a somewhat stronger statement. The Towers of Hanoi graph for n
disks has a planar drawing in which all the degree 2 vertices are on the exterior
face. For the base case, the graph is a triangle, so the claim is true, every vertex
is on the exterior face. Now let n ≥ 0 be given and represent the graphs on a
piece of paper by three blobs and label the 9 special vertices wherever you like
on the three blob boundaries. Can you join them correctly by edges in just the
exterior? You might need squiggly edges, but, unlike the similar but impossible
water-gas-electric problem, this should only take you a few seconds. Now, are
all the remaining special vertices, the degree two ones, on the exterior face?
No? No problem. The blobs are only attached at two points, so they be redrawn
twisted upside down. Done. Now that you know that the graph is planar, try to
make a better picture.

Here is another fact you can prove by induction, just add it to the inductive hy-
pothesis above and it will mostly slide right through: There is a planar drawing
with the optimal path from all 0’s to all 2’s laying entirely along the exte-
rior face. Here is another, there a Hamiltonian path joining state 0000000 to
2222222. That corresponds to a sequence of moves starting with 0000000, pass-
ing exactly once through every possible state, and ending 2222222. Don’t you
wonder what it looks like?

Too bad that there isn’t a Hamiltonian cycle. But maybe there is. Why don’t you
recycle your simplified water-gas-electric blob diagram and see if that can help
you prove that there is one. All these results you can describe and prove without
the graph, or the pictures, but why would you? And while it may be true that
only a madman would actually draw a graph on two thousand vertices and three
thousand edges, a mathematician will certainly try to imagine it, and a computer
scientist will certainly try to program a computer to render it.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


210 Discrete Mathematics With Logic

9.9 Case study: Anchuria


An old Anchurian1 custom lends itself very well to a two-person adventure, or
a class experiment.
Cut six pieces of twine, each six inches in length, align them and grab them
with your fist. Have your partner tie 3 knots on top and 3 knots on the bottom,
see Fig. 9.25.

FIGURE 9.25 A two-person adventure.

Let go. What is the result? The Anchurian custom says that if the 6 strings
form a ring, you may marry your partner.
Interpreting the 6 strings as edges and the knots as vertices, we see that the
result of the experiment is a graph G on 6 vertices and 6 edges. The graph is bi-
partite, since every edge goes from top to bottom. It is also 2-regular, i.e., every
vertex is of degree 2 (since the strings were tied two by two). How can we count
the number of 2-regular bipartite graphs on six vertices? Let us first assume
that we are counting graphs whose edges are labeled   1,
. . . , 6. For tying the top
knots, by the multiplication principle, there are 62 42 22 possibilities, and we
can divide this number by 6, since we are not interested in which order the knots
were tied, only in the resulting three knots. The same holds for the bottom three
knots, so there are 152 possibilities to tie the knots. After the bottom knots are
tied, there are 15 ways to tie the top knots, we list them in Fig. 9.26. You see
that 8 out of the 15 outcomes are connected, 6 are consisting of a 4-cycle and
a 2-cycle, and one consists of three 2-cycles. Let us call two graphs isomorphic
if there is a bijection between their vertex sets preserving adjacency. Graph iso-
morphism induces an equivalence relation on the set of graphs produced by the
experiment and we see that there are three isomorphism classes.
We could consider the experiment having three different outcomes: three
2-cycles, a 2-cycle and a 4-cycle, or a 6-cycle. We can put our counting tech-
niques to work to answer the question about likelihood. What is the probability
8
to obtain a 6-cycle? It is 15 > 12 .
Now we want to discretely generalize the experiment. Instead of 6 strings
we want to consider 2n strings (why do we want an even number of strings?). It
1 Anchuria is a fictional country invented by O. Henry. A. Engel, well known for his mathematical
problem collections and pedagogy, uses this setting to describe several interesting problems.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Graphs and trees Chapter | 9 211

FIGURE 9.26 Ways to tie the knots.

is quite easy to describe the isomorphism classes of possible outcomes: bipartite


graphs on 2n vertices which are the disjoint union of (non-empty) even cycles.
But now, what is the probability of obtaining a connected graph, i.e., a cycle
of length 2n? How does this probability behave as n gets large?   2
As before, the number of tying knots on top and bottom is ( n!1 nk=0 2n−2k ) .

1 n−1 2n−2k n−1
 2
The number of ways to get a 2n-cycle is n! k=0 2 k=1 2k.
So the probability of getting a 2n-cycle is (2n−2)(2n−4)...2
(2n−1)(2n−3)...1 , which goes to zero
as n tends to infinity (remember Calculus?).
We could generalize also by taking three strings at a time and tie them into
a knot, requiring 3n strings for the experiment. Try it! Is connectivity of the
outcome likely if n gets large? How about tying k strings at a time? What the
experiment is creating is a random regular bipartite graph.
Something else occurs when you are doing this experiment. Sometimes the
cycles are linked. We are leaving the discrete world.

9.10 Summary exercises


You should have learned about:
• Graphs and subgraphs
• Paths, cycles, trees, complete graphs, bipartite graphs
• Connectivity and connected components of a graph
• Trees, their characterization, and uses in searching and sorting
• Spanning trees and how to find them
• Eulerian and Hamiltonian graphs
• Planar graphs and their duals
1. Given two simple graphs, G1 = (V1 , E1 ) and G2 = (V2 , E2 ).
If G2 is a subgraph of G1 , then V2 ⊆ V1 and E2 ⊆ E1 .
Show that the converse of the implication need not hold.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


212 Discrete Mathematics With Logic

2. G = (V , E) be a graph. Show that the connectedness relation, , defines


an equivalence relation on the vertex set.
3. Let G(V , E) be a simple graph, with both V and E non-empty, V  ⊆ V ,
and E  ⊆ E. Give examples such that G(V  , E  ) is NOT a graph. Give
examples such that G(V  , E  ) IS a graph.
4. How many connected components can a simple graph on 10 vertices and 5
(or 6 or 7) edges have at most? At least? Give examples!
5. How many connected components can a simple graph on n vertices and
k
2 , k < n edges have at most?
6. Prove that a graph G is bipartite if and only if all cycles of G have even
length.
7. Let G be a graph whose vertex set are bit strings of length 3 and two bit
strings are adjacent if they differ in exactly one bit. Draw G. Is G simple? Is
G connected? Is G planar? Is G bipartite? Is it Eulerian? Is it Hamiltonian?
8. Prove the Two-out-of-three Theorem for trees.
9. Show that the cube graph (consisting of the 8 vertices and 12 edges of the
cube) is bipartite and planar. Is it edge maximal under the conditions of
being simple, planar and bipartite?
10. Show that the cube graph plus one of the major diagonals is not planar.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Selected answers and solutions

Chapter 1 – Discreteness
1.2 Of course this is subjective, but Morse code seems discrete in a way that
hula dancing is not.
1.3 I say frissbeeee . . . to h-o-p-s-c-o-t-c-h.
2.1 Hint: If the students all answer honestly, you cannot assume indepen-
dence. Why?
2.2 You can analyze the problem by considering the no-hood option sepa-
rately, or taking “no hood” to be another color “invisible”. So the answer
is 4 · 5 · 2 = 40 or 4 · 4 · 2 + 4 · 2 = 32 + 8 = 40.
2.3 Hint: I would say that if you don’t take the entrée, you are not ordering
the special. All other courses are optional, including taking the salad with
no dressing.
  5 10 5 10 3 10 2 10 1 10 0
3.1 105 9 + 6 9 + 7 9 + 8 9 + 9 9 + 10 9 .
10
3.2 5 510 .
3.3 Billiard balls are numbered and colored. We say they are distinguishable.
So for each ball, we have to choose a compartment. These drawer com-
partments are also distinguishable. So for each ball, choose one of the
three compartments. Fifteen choices of 3 give 315 . (Not 153 .) What if
they were ping-pong balls?
4.1 The circled entries are placed symmetrically, or did you forget to count
from
  zero?
100 100!49!51! 49!51! 49!50!(51) 51
4.2 100
50 / 49 = 100!50!50! = 50!50! = 49!(50)50! = 50 > 1.
4.3 Hint: You have 8 children, 4 boys
  and 4 girls, and want to count the
number of groups of size 4, so 84 since sex is irrelevant to the question.
But what if you want to take it into account anyway?
5.1 The first two are easy. The third is a shift, notice the “binary point”. The
last should look familiar, and note that it is easier if you write the carries
also inbinary.
 11 11 11
5.2 211 − 11 3 − 2 − 1 − 0 .
5.3 First is 1 followed by 16, second has 64 zeros.

213

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


214 Selected answers and solutions

6.1 2020 in binary is 1100101000000 using either method. If you are like
most people, you add commas to make it easier to read: 1,100,101,000,
000. The numbers in between the commas are 3 digit binary numbers,
so 0 to 7, – aha – the digits in base 8, that’s the trick! Base 8: 14500,
Base 16: 1,1001,0100,0000, or 1940.
6.2 22212102 and 201324.
6.3 1776 is ↑↓↑↑ 0 ↑↓↑ 0.

Chapter 2 – Basic set theory


1.1 It is easy to find problems with each one.
1.2 It is hard to avoid problems with natural language.  (∅ is well defined.)
1.3 A = {k ∈ Z | k = 2j + 1; j ∈ Z}, D = {x ∈ R | x = K i=J di · 10 ; J, K ∈
i
K
Z; J ≤ K; di ∈ {5, 6}} ∪ {x ∈ R | x = i=−∞ di · 10i ; K ∈ Z; di ∈
{5, 6}}.

2.1 For a) there are 24 = 16 elements to be listed. For b) there are 52 = 10:
{a, b}, {a, c}, {a, d}, {a, e}, {b, c}, {b, d}, {b, e}, {c, d}, {c, e}, and {d, e}.
2.2 P3 (P2 (P1 (Z))) consists of sets of three elements, like
{{{1}, {2}}, {{1}, {3}}, {{1}, {4}}},
{{{1}, {2}}, {{1}, {3}}, {{1}, {5}}}, and
{{{1}, {2}}, {{1}, {3}}, {{1}, {6}}}.
2.3 Argue: Let X ∈ P2 ({1, 2, 3, 4}), so X = {a, b}, with 1 ≤ a, b ≤ 4. So
a, b ∈ {1, 2, 3, 4, 5, 6}, hence X = {a, b} ⊆ {1, 2, 3, 4, 5, 6}, as required.

3.1 c) Sets of the form {(a, b), (a, c), (b, b), (b, c)}. There are 42 = 6 of
them: {(0, ∅), (0, π)}, {(0, ∅), (∅, ∅)}, {(0, ∅), (∅, π)}, {(0, π), (∅, ∅)},
{(0, π), (∅, π)}, and {(∅, ∅), (∅, π)}.
3.2 a) One is (0, (1, 0)). b) (5)(5)(10).
3.3 a) {∅, {(c, e, a)}}. b) (∅, ∅, ∅), (∅, ∅, {a}), (∅, {e}, ∅), (∅, {e}, {a}), ({c},
∅, ∅), ({c}, ∅, {a}), ({c}, {e}, ∅), ({c}, {e}, {a}), and every bracket and
parenthesis is important.
4.1 a) Let x ∈ A × B. So x = (a, b) for some a ∈ A, and some b ∈ B. Since
A ⊆ B, a ∈ B. Since B ⊆ C, b ∈ C. Thus (a, b) ∈ B × C.
Therefore (A × B) ⊆ (B × C).
b) Consider if A = ∅.
5.1,2 All the flaws are coming from confusing ‘an element of’, notation ∈,
with ‘a subset of’, notation ⊆. Phrases like ‘contained in’, ‘is in’, ‘is part
of’ are vague and ambiguous, and can confuse both the reader and the
writer.
5.3 There are of course, no flaws in part three. That is a valid argument.
(Unfortunately it is based on the non-sense we concluded from the two
flawed parts. . . )
6.3 All three.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Selected answers and solutions 215

Chapter 3 – Working with finite sets


1.1 a) 25 ≤ |X ∪ Y | ≤ 26 + 27 . b) 0 ≤ |X ∩ Y | ≤ 26 .
4 4  
1.2 a) 2 2 4·5 . b) 2 24·5 + 03 . c) 0.
2.1 The tenth: 1010 = 10102 corresponds to b, d.
2.2 There are ten. {a, b}, {a, c}, . . . {c, e}, {d, e}.
2.3 99910 = 11111001112 corresponding to {0, 1, 2, 5, 6, 7, 8, 9}.
3.1 2 · 54 + 5 − 53 − 1 − 1 + 1.
3.2 53 + 53 + 54 − 52 − 52 − 5 + 1.
3.3 2621 + 265 + 2613 − 26 − 269 − 263 + 26.
4.1 a) ((1, 1, 1, 1, 1), 1, {1}), ((1, 1, 1, 1, 1), 1, {2}), ((1, 1, 1, 1, 1), 2, {2}),
((1, 1, 2, 1, 1), 1, {2}), ((2, 1, 1, 1, 1), 1, {2}) . . .
b) |(A5 ) × A × A| = |A5 | · |A| · 2|A| = 36 23 .
4.2 a) (((a, b), (a, c)), ((a, b), (a, c))), (((a, a), (a, a)), ((a, a), (a, b))), . . .
b) ((32 )2 )2 = 38 .
4.3 a) Puszat, Bozsey, . . . b) 27 .
5.1 None.
5.2 2 · 59 + 0 · 58 + 2 · 57 + 0 · 56 + 1 · 55 + 4 · 54 + 1 · 53 + 1 · 52 + 4 · 51 + 4 · 50 .
5.3 Divide alternately by 3 and 2 and take remainders: 88 = 29(3) + 1 so
last character 2, 29 = 14(2) + 1 so then b, 14 = 4(3) + 2 so then 3 4 =
2(2) + 0 so then a 2 = 0(3) + 2 so then 3.
Final result: 1a3a3b2.
6.1 Read top to bottom, left to right:
abcd bacd cabd dabc
abdc badc cadb dacb
acbd bcad cbad dbac
acdb bcda cbda dbca
adbc bdac cdab dcab
adcb bdca cdba dcba
6.2 8 · 9! + 2 · 8! + 1 · 7! + 2 · 6! + 2 · 5! + 4 · 4! + 2 · 3! + 0 · 2! + 1 · 1! + 0 · 0!.
6.3 8,214,596,073; 8,214,596,307; 8,214,596,370; 8,214,596,703; 8,214,
596,730; 8,214,597,036; 8,214,597,063; 8,214,597,306; 8,214,597,360;
8,214,597,603; 8,214,597,630; 8,214,603,579; . . .
7.1 δβαγ .
7.2 720 = 6!, so 1(6!) + 0(5!) + 0(4!) + 0(3!) + 0(2!) + 0(1!) giving bacdef g.
7.3 0,123,968,457.

Chapter 4 – Formal logic


1.1 Natural language is slippery.
1.2 But are they all true?

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


216 Selected answers and solutions

1.3 The problem seems to be if Eddie only has a ruby. . .


2.1 Both are false.
2.2 Both are true.
2.3 Only all true or all false work.
3.1 Except for quibbling, all pass. The first two conclusions are true and the
last antecedent is false.
3.2 a) The antecedent is false. b) The consequence is true.
3.3 b) Suppose p ∧ q. Then p is true and q is true. Since q is true, q ∨ r is
true, as required.
4.1 We first show [p ∧ (q ∧ r)] ⇒ [(p ∧ q) ∧ r)]. Suppose p ∧ (q ∧ r) is true.
Then p is true, and q ∧ r is true. Since q ∧ r is true, both q and r are true.
Thus p ∧ q is true, and so (p ∧ q) ∧ r is true. (Try now the second half.)
5.1 ((s ∨ ¬r) ∨ ¬q) ∨ ¬p.
5.2 [p ∧ (r ∨ ¬q)] ∨ [¬p ∧ ¬(r ∨ ¬q)].
5.3 [(¬p ∨ q) ∧ ¬(¬q ∨ p)] ∨ [¬(¬p ∨ q) ∧ (¬q ∨ p)] and many alternate
forms.
6.1 ¬(p ∧ q ∧ r).
6.2 (p ∧ q ∧ r) ∨ (¬p ∧ ¬q ∧ ¬r).
6.3 (p ∨ ¬(q ∧ r ∧ s)) ∧ (q ∨ ¬(p ∧ r ∧ s)) ∧ (r ∨ ¬(p ∧ q ∧ s)) ∧ (s ∨
¬(p ∧ q ∧ r)). There are many other ways to express these.
7.1 a) (¬p) ∨ (¬q) ∨ (¬r) ∨ (¬s) (short AND clauses). b) (¬p ∨ ¬q ∨ ¬r ∨
¬s) (just one OR clause).
7.2 a) (p ∧ q ∧ r ∧ s) ∨ (¬p ∧ ¬q ∧ ¬r ∧ ¬s). b) (p ∨ ¬p) ∧ (p ∨ ¬q) ∧ (p ∨
¬r) ∧ (p ∨ ¬s) ∧ (s ∨ ¬p) ∧ (s ∨ ¬q) ∧ (s ∨ ¬r) ∧ (s ∨ ¬s) ∧ (r ∨ ¬p) ∧
(r ∨ ¬q) ∧ (r ∨ ¬r) ∧ (r ∨ ¬s) ∧ (s ∨ ¬p) ∧ (s ∨ ¬q) ∧ (s ∨ ¬r) ∧ (s ∨ ¬s)
just using the distributive law. 
7.3 a) You cannot have just one false. So 42 terms (¬p ∧ ¬q) ∨ (¬p ∧ ¬r) ∨
(¬p ∧ ¬s) ∨ (¬q ∧ ¬r) ∨ (¬q ∧ ¬s) ∨ (¬r ∧ ¬s) ∨ (p ∧ q ∧ r ∧ s).
b) Try (¬p ∨ ¬q ∨ ¬r ∨ s) ∧ (¬p ∨ ¬q ∨ r ∨ ¬s) ∧ (¬p ∨ q ∨ ¬r ∨
¬s) ∧ (p ∨ ¬q ∨ ¬r ∨ ¬s). Why would that ever work?

Chapter 5 – Induction
1.1 a) True: Richard Feynman was born after 1888.
False: Albert Einstein was born after 1888.
1.2 a) True: 36 is the sum of three distinct cubes.
False: 35 is the sum of three distinct cubes.
1.3 It is small diagonal red “eight” in a sea of blue.
2.1 You get to choose n: Let n = 1, then 12 + 5 = 6 · 1, as required. (Where
did the 1 come from? Work had to be done but that is not part of the
proof.)
2.2 Let n ∈ N. Consider two cases, n is even, . . . . (Now you are started.)

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Selected answers and solutions 217

2.3 a) and b) are true by choosing m = 0. c) is false, since given n, you can
take m > n3 + 1.
3.1 The base case is 3 · 0! > 02 .
The induction step requires that you prove, for any given n ≥ 0, that
3 · n! > n2 implies 3 · (n + 1)! > (n + 1)2 .
The induction hypothesis, for the given n ≥ 0, is 3 · n! > n2 .
3.2 Hint: The fact that the statement is false has nothing to do what you
would do to prove it.
3.3 P5 must be true. P25 , P35 , and P45 must be false. P15 cannot be deter-
mined.
4.3 Since P15 is true, any predicate on an odd index greater than 15 is true
by induction, so P55555 is true.
Since P14 is false, any predicate on an even index less than 14 is false,
otherwise P14 would be true by induction, so P0 and P4 are both is false.
About P2100 we can make no conclusion.
6.1 {0, 1, 3} = {0, 1, 2, 3, 4} ∩ {0, 1, 3, 4, 5, 6, 7, 8, 9}.
6.2 Let the universe U = N. T = {2}. P is the set of primes. E = {n ∈ N; n =
2k; k ∈ N}. P ∩ E ⊆ T .
6.3 Define pn to be 1 is k − 1 is evenly divisible by 5 and 0 otherwise.

Chapter 6 – Set structures


1.1 Hint: Notice that very few letters are related to many digits.
1.2 Hint: Notice that the specification does not stipulate that the two elements
of A are distinct.
1.3 26 .
2.1 R = ∅?
2.2 Why not the following? And why 13? Why do we need two lines at all?

|A| if A is finite
f (A) =
13 if A is infinite

2.3 It is functional, one-to-one and onto. Can you show it?


3.1 Onto:
             
6 10 6 10 6 10 6 10 6 10 6 10 6 10
6 − 5 + 4 − 3 + 2 − 1 + 0
6 5 4 3 2 1 0
(20 ) )
3.2 Compute first 2(2 = 4. Ordinary 44 , all others 4!.
25
3.3 16 9!.
4.1 Hint: To show non-onto you may exhibit any violator.
4.2 Hint: Find two subsets with eight elements with the same maximum and
minimum elements.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


218 Selected answers and solutions

4.3 Hint: The target is an infinite set.


5.1 Cf consists of all integers except 0 and 1.
5.2 For instance f (a) = f (d) = f (e) = f (g) = ∅. and f (b) = f (c) =
f (f ) = {a, b, c, d, e, f, g}.
5.3 Hint: Besides the error of name calling, has the procedure assigned a
value to every set? Why is that in issue?
6.1 There are plenty of reasonable arguments that it is uncountable. R × R
contains R × {0} starts one.
6.2 Use finite subsets of a countable set . . .
6.3 A fun argument is to encode the numbers via placement and degree of
the digit rises. A shorter one argues the numbers are all rational.
7.1 Reflexive, anti-symmetric, and transitive.
7.2 a) Anti-reflexive, anti-symmetric, and anti-transitive. b) All 62 arrows
would be in the diagram.
7.3 Here’s one:
◦ ◦ ◦
•←→•←→•
8.2 Transitivity: Let n ∝ m and m ∝ r. Then n − m = 10k for some k ∈ Z
and m − r = 10j for some j ∈ Z. Adding the two equations gives
n − m + m − r = 10k + 10j , or n − r = 10(k + j ) so n ∝ r, and the
relation is transitive.
8.3 Here’s one:  isn’t reflexive: 7 is not related to 7 since 14 is not divisible
by 10.

Chapter 7 – Elementary number theory


1.1 You only need to sieve out primes 2, 3, 5, 7, and 11.
1.2 Don’t use a calculator. Largest prime to check is 19.
1.3 1776 = 2(888) = 2(8)(111) is one way to start.
2.1 Hint: 321 = 2 · 123 + 75 . . . 21 = 3 · 6 + 3 .
2.2 Start 988,887 = 1 · 888,887 + 100,000 then stop and note that 988,887
and 888,887 have the same common divisors as 888,887 and 100,000.
3.1 Give 7 Alexanders, and receive back 11 Bucephaluses.
3.2 17(449) + (−72)(106) = 1 can be found without calculator in less than
90 seconds.
3.3 There is no solution since 99 = 32 · 11, and 111 = 3 · 37.
4.1 Modulo 11: 6 + 7 = 13 ≡ 2 mod 11.
8 + 8 = 16 ≡ 5 mod 11.
2 · 8 ≡ 5 mod 11 is the same problem.
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 = 1 + (2 + 9) + (3 + 8) + (4 + 7) +
(5 + 6) ≡ 1 mod 11.
5280 + (65)(88) = 5280 + (65)(8)(11) = 5280 = 11(480) ≡ 0 mod 11.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Selected answers and solutions 219

4.2 Additive inverse sum to zero: 0 and 0, 1 and 6, 2 and 5, 3 and 4.


Multiplicative inverses multiply to 1: 1 and itself; 2 and 4; 3 and 5, and 6
and itself.
4.3 Additive inverse sum to zero: 0 and 0, 1 and 7, 2 and 6, 3 and 5, 4 and
itself.
Multiplicative inverses multiply to 1: 1 and 1; 3 and 3; 5 and 5, and 7 and
7 are the only pairs – weird.
5.1 From the Euclidean algorithm: (1)(66) + (5)(−13) = 1 The multiplica-
tive inverse of 5 modulo 66 is −13. Then 5x = 3 gives (−13)(5x) ≡
(−13)(3) mod 13, so x ≡ −39 ≡ 27 mod 66.
5.2 15 mod 25.
5.3 Summary: (1)(1) ≡ (2)(13) ≡ (3)(17) ≡ (4)(19) ≡ (6)(21) ≡ (7)(18) ≡
(8)(22) ≡ (9)(14) ≡ (11)(16) ≡ (12)(23) ≡ (13)(2) ≡ (14)(9) ≡
(16)(11) ≡ (17)(3) ≡ (18)(7) ≡ (19)(4) ≡ (21)(6) ≡ (22)(8) ≡
(23)(12) ≡ (24)(24) ≡ mod5.
6.1 n = (11)(−2)(19) + (17)(3)(13).
6.2 All solutions are given by 5(−2)(19) + (2)(3)(13) + k(19)(13) for some
k ∈ Z.
6.3 10(−2)(19) + (12)(3)(13).

Chapter 8 – Codes and cyphers


1.1 10200 ≡ 1 mod 11.
1.2 a) 21776 ≡ 4 mod 12. b) 21776 = (28 )222 ≡ 1222 = 1 mod 17.
1.3 21776 = 21770 25 2 ≡ 1 · (−1)(2) ≡ −2 ≡ 31 mod 33.
2.2

a0 a1 a2 a3 a4 a5 a6 a7
0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1
2 1 2 4 1 2 4 1 2
3 1 3 2 6 4 5 1 3
4 1 4 2 1 4 2 1 4
5 1 5 4 6 2 3 1 5
6 1 6 1 6 1 6 1 6
The 6th and 7th columns are just what are predicted by Fermat’s Little
Theorem.
2.3 b) 21710 = (21700 )(210 ) = (2100 )17 210 ≡ 1 · 1024 ≡ (10)(101) + 14 ≡
14 mod 101.
3.1 The multiplicative decoding key is the multiplicative inverse of 7 modulo
26 which is 15.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


220 Selected answers and solutions

3.2 Hint: The encoding and decoding keys are established modulo 10 but the
encoding and decoding are done modulo 11.
3.3 For exponential, the numbers not coprime to 10 are {0, 2, 4, 5, 6, 8, 10}.
4.1 δ = 77.
4.2 (108, 141, 166).
4.3 Hint: You need the multiplicative inverse of 67 modulo (3 − 1)(101 −
1) = 200; which is 3.
5.1 52802 = 1,0100,1010,0000, a 13 digit binary number, so the Euclidean
algorithm should take at most 26 steps by our bound.
5.2 limn→∞ 500n +1000n
5 3
n6
= limn→∞ 500n + 1000n = 0 + 0 = 0.
3
2n +3n
5.3 limn→∞ 5n = limn→∞ (2/5)n + (3/5)n = 0.
9 7 4 3 1
6.1 1776(2 ) · 1776(2 ) · 1776(2 ) · 1776(2 ) · 1776(2 ) .
6.2 722 ≡ 49 mod 100.

Chapter 9 – Graphs and trees


 
1.1 The number of edges in a simple graph on n vertices is bounded by n2 ,
since we have to choose two endpoints for every
  edge. Complete graphs
achieve this bound. K5 has 10 edges. Kn has n2 edges.
Since a graph in general can have multiple edges there is no upper bound.
2.2 The total cost of the resulting road network is 240 + 270 + 300 = 810.
2.3 Hint: By Cayley’s formula, there are exactly 42 = 16 such trees.
3.2 Base case: k = 0. We have T (20 ) = T (1) = 0 ≤ 0 · 20 , and the inequality
holds.
Induction step: Let k ≥ 0, and assume that T (2k ) ≤ k · 2k . We want to
show that T (2k+1 ) ≤ (k + 1) · 2k+1 . We have T (2k+1 ) ≤ 2T (2k ) + 2k+1 .
Using the induction hypothesis, we have T (2k ) ≤ k · 2k and therefore
T (2k+1 ) ≤ 2T (2k ) + 2k+1 ≤ 2k · 2k + 2k+1 = k · 2k+1 + 2k+1 = (k + 1) ·
2k+1 , which completes the induction step.
4.2 If G is bipartite, it only contains cycles of even length, hence is triangle-
free, and we can use Theorem 9.15. We could also provide spanning tree
argument and “quadrangulate” the (2n − 2)-gon by n − 3 “diagonals”.
5.1 The graph has four vertices of odd degree. Therefore, by Theorem 9.19,
it has no Eulerian trail.
6.1 Consider a traceable tree T and let P be a Hamiltonian path in T . Then
every edge of T must belong to P since otherwise T would contain a
cycle. Therefore, the only traceable trees are paths (that is, trees in which
all vertices have degree at most two).
As every tree is acyclic, there are no Hamiltonian trees.

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Index

A B
Action strings, 66 Backwards induction, 106
Acyclic, 208 Base
connected graph, 186 cases, 98, 104, 112
graph, 182, 184 conversion, 14
Adjacency Basic Boolean identities, 75
lists, 188 BFS, see Breadth-first search (BFS)
lists representation, 188
Billiard balls, 2, 10, 67
relation, 133
Binary
Albertson’s Magic Trick, 1, 2, 4, 5, 7, 13
bits, 68, 106
Algebra
Boolean, 75, 76, 81–83, 88, 91, 95 digits, 13, 14, 106
Boolean expressions, 81 expression, 15
real functions, 95 form, 56
Algebraic format, 14
approach, 82 logical operation, 77
assertion, 101 number, 12–14, 24, 52, 53, 61, 67, 106,
equations, 155 146
expositions, 159 number system, 145
expression, 85, 117, 175, 179 operations, 34, 35
structures, 115 relation, 115, 140
Algorithm, 15, 177 representation, 23, 24, 169, 174, 175
Alphabet, 29, 57, 60, 61, 66, 169, 177, strings, 68, 107
185 system, 13
element, 177 Binomial
letters, 169, 178
coefficient, 8–12
Roman, 29
theorem, 18, 19, 51, 112
set, 169
Bipartite, 183
Alphabetic order, 59
Alphabetical ordering, 53 Bit, 13
Anchuria, 210 assignment, 83
AND clause, 84, 85 binary, 29, 68, 106
Antecedent, 77, 78, 81, 92, 94 sequences, 13
false, 94 vector, 52, 53, 57, 66–68
Anti-reflexive, 208 order, 54, 71
Axiomatic set theory, 41 ordering, 53

221

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


222 Index

Boolean Combinatorial explosion, 55


algebra, 75, 76, 81–83, 88, 91, 95 Common divisor, 145, 146
assignment, 85, 92 Complement, 34, 36
expression, 75, 76, 83–85 Complete
algebra, 81 bipartite graph, 183, 193, 197
formation, 74 graph, 183, 185, 197, 211
function, 83–85, 88, 93–95, 113, 128 relation diagram, 134
algebra, 95 Conclusion, 77
in DNF, 85 Conjunctive normal form (CNF), 85, 86,
identity, 82 88
values, 74, 76, 83, 88 Connected, 208, 210
variables, 74, 83–85, 88, 91, 93 components, 183, 188, 189, 199
Bracket notation, 29, 33, 48 graph, 183
Breadth-first search (BFS), 188 Connectedness relation, 183, 212
tree, 189 Connectivity, 186, 196, 211
Consecutive strings, 141
C Consequence, 77
Caesar’s additive cypher, 169 Contrapositive, 80
Caesar’s cypher, 168, 169 Converse, 80
Cannonball stacking, 89, 100, 101 Coprimality, 148
Cardinality, 28, 32, 45, 51, 52, 54–56, 94, Coprime, 145–148, 153, 154, 164, 198
118, 120, 121, 124–126, 128, Countability Results, 126
137, 175, 176 Countably infinite, 124, 125
countably infinite, 125 array, 126
even, 51 collection, 125
finite, 165 Counting from 0, 11
finite set, 28 Cycle, 182, 210
for finite sets, 141
Cypher, 167, 168
intersection, 55, 69
Caesar’s, 168, 169
odd, 51
exponential, 169
union, 55
multiplicative, 168, 169
zero, 28
Cartesian product, 33–35, 56–62, 64, 115,
125, 127, 132, 133, 142 D
Cayley’s formula, 185, 186 De Morgan’s laws, 36, 56, 81, 85, 95, 97
Chess, 115, 118, 156 Decimal
game, 131 conversion, 14, 15
Chessboard, 20, 22, 47, 115 digits, 29, 63, 66, 163
Chinese Remainder Theorem, 153, 154, numbers, 13, 14, 28, 61, 64
160 point, 28
Circular argument, 100 representation, 2, 3, 30, 119, 130, 141
Classic logic puzzles, 86 system, 13
Clause, 76 Decoding key, 168, 169, 171, 172, 179
CNF, see Conjunctive normal form Decrypting key, 168, 170
(CNF) Decryption, 170
Code, 167 function, 168
Gray, 67, 68 key, 168, 173
Coin problem, 147, 148, 151, 159 step, 169

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Index 223

Delisting, 61 Dual
permutations, 64 graph, 195, 196, 198
problem, 61 operation, 196
Depth-first search (DFS), 188, 189 spanning tree, 198
tree, 189
Derangement, 69, 70 E
Developer’s problem, 132, 137 Edge, 181
DFS, see Depth-first search (DFS) Edge set, 181
Digits, 29 Elements, 27
arithmetic, 62 domain, 119, 121
binary, 13, 14, 106 for finite sets, 124
decimal, 29, 63, 66, 163 general, 30, 38, 62
Gray code, 106 golden, 51, 52
length, 61 in
numbers, 24, 109 lexicographic order, 59
Diophantine, 155 related, 117
equation, 158 remaining, 65
problem, 156 string, 168
Direct road connection, 185 target, 121
Directed graph, 127, 130 Empty
Discrete mathematics, 115, 117, 125, 131 set, 28, 31
Discreteness, 2 string, 57
Disjoint pairs, 200 Encoding, 52, 66, 67, 134, 171, 179
algorithm, 177
Disjunctive normal form (DNF), 84, 85
keys, 168, 170–172, 179
Distinct
letters, 168
domain elements, 121
numbers, 145
vertices, 182
symmetric relations, 177
Distributive law, 19, 36, 79, 81, 85, 92,
Encryption, 169, 170
95, 97, 150
function, 168
basic, 58
key, 168–170, 173
general, 58
schemes, 179
Divisible numbers, 40, 149 Endpoints, 181, 182
Division, 60, 64, 143, 145, 147–149, 151, Equivalence, 130
165, 171, 173 class, 131, 132, 137, 138
with remainder, 143, 146 relation, 130–132, 137
DNF, see Disjunctive normal form (DNF) Eratosthenes’s sieve, 143, 144, 173
Domain elements, 119, 121 Euclidean algorithm, 145–147, 160
Domain set, 117 Euclid’s Coin Problem, 147, 148, 151,
Double implication, 79–82, 91, 98, 159, 159
165 Eulerian
method, 79 circuit, 198–202
proof, 82 graphs, 198
Double inclusion, 37, 79–81 trail, 198–203
method, 37–39, 48, 49, 58, 146, 159 Euler’s formulas, 196
proof, 40, 80 Even versus odd, 4

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


224 Index

Evenness, 107, 108, 149 G


permutations, 107 Game
Existential quantification, 96 Cramcheck, 22
Existential/universal quantification, 95, nim, 23
113 General
Existentially quantified distributive law, 58
predicates, 97 element, 30, 38, 62
statement, 96, 97 Golden element, 51, 52
Exponential Graph, 181
acyclic, 182, 184
cypher, 169
connected, 183
decryption step, 169
discrete, 181
encoding keys, 170
dual, 195, 196, 198
encryption schemes, 179 planar, 193–196
modulo n, 163 plane, 194
system, 170 simple, 182
Extended Euclidean Algorithm, 147 traceable, 202–204
Exterior face, 195, 209 Gray
code, 67, 68, 106, 168, 176
F code digits, 106
Faces, 194 encoding, 68
exterior, 195 Greatest common divisor, 145, 146
Guarini problem, 20, 156
interior, 195
Gygax, Gary, 5
Factorial, 8
Fáry’s theorem, 205, 207 H
Fast exponentiation, 173 Half-plane, 43
Fermat’s Little Theorem, 167, 169, 171, Hamiltonian, 209
174–176, 178 cycle, 202
Fermat’s notebook, 167 graph, 202
Fibonacci graph traceable, 202
numbers, 111, 112 path, 202
sequence, 111, 112 Hilbert’s Hotel, 123
Finite example, 123
cardinality, 165 functions, 125
sequence, 99 Hypothesis, 77
sets, 54, 118, 119, 123, 141
sets cardinality, 51, 126
I
Implication, 76–81, 94, 98–102, 130, 211
sets Cartesian product, 61
Incidence function, 181
Floor function, 15
Inclusion/exclusion, 54–56, 69, 71, 119
Forgetful waitress problem, 68, 69 formula, 55, 69
Formal logic, 74, 81, 91, 93, 94 principle, 54, 55
logical operators, 95 Indian formulas, 157, 158
operations, 91 Induction, 209
Frequency attack, 169 example, 101
Functional hypothesis, 98–100, 103, 106–108,
relations, 117, 118, 120 110, 111, 113, 159, 160, 174,
relationship, 118 204, 206, 207

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Index 225

informal, 111 placement, 10


method, 97, 100 set, 27
practice, 100 Lexicographic
procedure, 98 list, 59, 64
proof, 102, 113, 196, 207 order, 59–64, 107
step, 98–104, 106, 108, 112, 113, 160, ordering, 61
207 Lexicographical
strong, 103, 104 list, 64
theory, 97 order, 59
variable, 100 Lexicographically
Inductive ordered list, 63
approach, 109 ordering strings, 60
argument, 98, 99, 101, 102, 112 List
formation, 98 integers, 192
method, 110 item delimiters, 74
proof, 100, 102 lexicographic, 59, 64
structure, 101 notation, 27
variable, 107, 113 Listing, 59
Infinite notation, 29
number, 125 problem, 61
sequences, 127 Little-o notation, 172, 179
sets, 122, 124–126 Logarithm, 15
sets cardinality, 124, 126 Logic, 3, 5, 73, 74, 77, 79, 94, 99, 115
Infix notation, 116 Logic puzzles, 86
Informal induction, 111 Logical
Integers, 2, 28 equivalence, 79
list, 192 expressions, 79, 81
numbers, 189 notation, 79
sorted lists, 191 operations, 74, 76
Integral power, 18, 19 operators, 74, 83, 95
Interior faces, 195 propositions algebra, 75
Intersection, 33–35, 54–56, 58, 138, 207 sense, 91
cardinality, 55, 69 statements, 73, 74, 91
operation, 33
structure, 74
Inverse, 80
symbol, 95, 96
Inversion number, 107, 108
variables, 74
Isolated vertex, 199, 200
Logically
Iterative, 16
distinct, 80
K equivalent, 80
k-subsets, 31, 32 Loop, 181
Kleene Star, 57 Loyd, Sam, 108
Kruskal’s algorithm, 186, 187
Kuratowski’s theorem, 197 M
Magic trick, 1
L Maltese cross, , 20
Letters Mathematical
alphabet, 169, 178 puzzles, 17, 193
encoding, 168 sets, 115

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


226 Index

Members, 27 natural, 2, 15
Membership, 27–31, 33, 34, 52, 53, 123 prime, 28
Membership list, 33 rational, 3
Merge sort, 190, 192 real, 28
algorithm, 192 sequence, 103, 185
Merged list, 191 sets, 34, 150
Minimum Spanning Tree, 186, 205 Numerical algebra, 76
problem, 186, 187
Misordered pairs, 108 O
Modular arithmetic, 149, 150, 156, 160, Objects
168, 169, 174 list, 188
Modulus, 150 sequences, 65
Multiple Obstruction
Cartesian product, 56, 57, 59–62 function, 133, 137, 138
edges, 181, 182 relation, 133, 137
union, 58 Oddness, 107, 108, 149
Multiplicative Operation
cypher, 168, 169 binary, 34
inverse, 143, 151–154, 164–166, unary, 34
168–171, 175, 176 Operator notation, 117
orders, 165, 179 Optimal solution, 110, 111
unique, 110
principle, 5–8, 10, 18, 21, 22, 31, 32,
Or, inclusive, 33
35, 51, 52, 55, 57, 66, 69, 83,
OR clause, 85, 86, 88
85, 86, 109, 119, 136, 185
Ordered
pairs, 35
N selection, 9
Nantucket map
Ordering, 130
problem, 1 bit vector, 53
Natural permutations, 61
language, 9, 28, 33, 34, 73, 74, 77, 79, subsets, 52
91, 115
number, 15 P
numbers, 28, 29, 40, 58, 94, 95, 113, Pairwise intersection, 69
123, 125, 130, 143, 157, 158 Palindrome, 22
numbers list, 59 Parallel edges, 181, 184, 205, 207
Non-transitive dice, 135 Partial order, 130
Nonplanarity, 197 diagrams, 130
Normal form, 84 strict, 135–137
NP-complete, 203 Pascal’s Triangle, 10–12, 18
Numbers Path, 182, 208
bases, 14, 16 Permutations, 62–65, 69, 70, 107, 108,
binary, 12–14, 24, 52, 53, 61, 67, 106, 168
146 evenness, 107
decimal, 13, 14, 28, 61, 64 Planar, 209
digits, 24, 109 Planar graph, 193–196
divisible, 40, 149 Planarity, 193, 197, 206
encoding, 145 Plane graph, 194, 195
integer, 2, 189 Platonic solids, 42, 45

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


Index 227

Playoff, 135 Related elements, 117


Power Related target element
integral, 18, 19 existence, 121
set, 30–35, 41, 123 uniqueness, 121
cardinality, 31, 32 Relation, 115
Predicate, 93 adjacency, 133
Predicate logic, 93–95, 115 anti-reflexive, 129
Presidential Problem, 2 anti-symmetric, 129, 190
Primality, 143–145, 148, 159 binary, 115, 140
arguments, 144 diagram, 116, 117, 127, 128, 134, 140,
Prime modulus, 165, 166, 169 141, 177
Prime numbers, 28, 29 reflexive, 127, 130, 176
Primes, 29, 91, 144, 149, 153, 157–160, set, 116
169, 171, 179 symmetric, 127, 176
Problem transitive, 127, 129, 176
Albertson’s Magic Trick, 1, 4 Relationship functional, 118
Anchuria, 210 Relatively prime, 145
cannonball stacking, 101 Remainder, 143
developer’s, 132, 137 sequence, 65
forgetful waitress, 68 Reversed pairs, 128
Guarini, 20 Road
Minimum Spanning Tree, 186 connection direct, 185
missing region, 45 network, 185–187
Nantucket map, 1 Roman alphabet, 29
non-transitive trournament, 135 RSA
Presidential, 2 encryption, 170
Pythagoras’s, 1 encryption scheme, 179
Red rum and murder, 21 scheme, 171, 172, 175, 179
Winning nim, 22 system, 170
Wolf-Goat-Cabbage, 1, 3, 133 Russell’s paradox, 40, 41
problem, 66 S
Proper subset, 30 Searching, 188
Prüfer code, 168, 176, 177, 184 Self-relation, 208
Public key cryptography, 170 Sequence, 3, 5–7, 13, 52, 59, 68, 99, 107,
Puzzle positions, 66 108, 111, 112, 123, 134, 164,
Pythagorean Triples, 157, 158, 161, 167 182, 197
finite, 99
Q recursive, 103
Quotient, 143, 145 remainders, 65
Set, 27
R binary Cartesian product, 56
Rational numbers, 3, 28, 30, 48, 151 finite, 54, 118, 119, 123, 141
Real numbers, 28 identities, 35
Recursion, 16, 177, 208 infinite, 122, 124–126
Recursive sequence, 103, 104, 111, 114 numbers, 34, 150
Red rum and murder, 21 operations, 33
Reduced relation diagram, 127, 129, 132 theory axiomatic, 41
Reflexivity, 127, 128, 130 well-defined, 27

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


228 Index

Sieved list, 144 Transitivity, 127


Simple Traveling Salesman Problem, 205
graph, 130, 182 Traversing relation, 134
planar graph, 196 Tree, 176, 184, 208
recursion, 177 spanning, 184, 185
Soma, 46 Triangle-free, 196
Sorted list, 190–192 Truth value, 73, 74, 76, 77, 79, 91, 93, 95,
Spanning 96, 99
subgraph, 182, 185 Twin primes, 179
trees, 184, 185
Spy game, 87 U
Strict partial order, 135–137 Unary operation, 34
String, 56, 57 Uncountability, 125
binary, 68, 107 Uncountability Results, 127
elements, 168 Uncountable sets, 125, 141
list, 61 Union, 33–35, 45, 57, 58, 119
ordering, 60 cardinality, 54–56
Strong induction, 103 operation, 33
Subdivision, 197 Unique
Subgraph, 182 optimal solution, 110
spanning, 182, 185 prime factorization, 145, 149, 158
Subject, 93 Universal quantification, 95–97
Subscript notation, 117 Universally quantified
Subset, 30 predicates, 97
Survivability function, 88 statement, 96, 98
Symmetric, 208 Universe, 34, 42
relation, 128, 182, 184, 187 Unordered selection, 9, 10, 32
Symmetry, 42, 127 Unwanted remainders, 147

T V
Target Vertex
element, 119, 121 degree, 182
set, 117 set, 181, 210
Ternary numbers, 110
Three utilities problem, 193 W
Threven numbers, 149 Walk, 182
Throdd, 149, 150 bounding, 197
Topological structures, 115 closed, 182
Towers of Hanoi, 17, 208 length, 182
Traceable traversing, 202
graph, 202–204 Weakly independent, 8
trees, 205 Wolf-Goat-Cabbage, 66, 133
Transitive, 173 problem, 1, 3
relation, 127, 129, 176 relation diagram, 134

This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024


This book belongs to Connor Dunkley (cadunkley@[Link]) Copyright Elsevier 2024

You might also like