Discrete Mathematics Assignments and Solutions
Discrete Mathematics Assignments and Solutions
MAT 253
Discrete Structures
UNCG
Dan Yasaki
Contents
List of Figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . v
List of Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii
List of Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
Chapter 1. Logic and Proofs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1. Propositional logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2. Propositional equivalence . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.3. Predicates and quantifiers . . . . . . . . . . . . . . . . . . . . . . . . . . 22
1.4. Introduction to proofs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Chapter 2. Basic Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
2.1. Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
2.2. Set operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
2.3. Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
2.4. Sequences and summations . . . . . . . . . . . . . . . . . . . . . . . . . 70
Chapter 3. Number Theory and Applications . . . . . . . . . . . . . . . . . 81
3.1. Divisibility and modular arithmetic . . . . . . . . . . . . . . . . . . . 81
3.2. Integer representations and applications . . . . . . . . . . . . . . . . 89
3.3. Primes and greatest common divisors . . . . . . . . . . . . . . . . . . 98
3.4. Solving congruences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
3.5. Cryptography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Chapter 4. Induction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
iii
iv Contents
List of Figures
vi List of Figures
List of Tables
vii
List of Symbols
ix
x List of Symbols
Preface
This document grew from lecture notes following the seventh edition of
Discrete Mathematics and its Applications by Rosen [5]. I used various
versions of the notes in conjunction with the book over the years whenever I
taught MAT 253 Discrete Structures. I will continue to develop this document
incorporating feedback from readers. This version was last modified: February
16, 2021. The most current version is available on my webpage.
https://www.uncg.edu/mat/faculty/d_yasaki/
MAT 253 core course in the mathematics curriculum designed for mathe-
matics majors as an early introduction to discrete mathematical structures,
rigorous proof techniques, and mathematical programming.
Catalogue description: A rigorous introduction to discrete mathematical
structures, proof techniques, and programming. Topics include sets, functions,
sequences, relations, induction, propositional and predicate logic, modular
arithmetic, and mathematical programming.
Student learning outcomes: Upon successful completion of this course,
students will be able to:
xi
xii Preface
Preface xiii
will give you a good idea of the language’s flavor and style. After reading
it, you will be able to read and write Python modules and programs,
and you will be ready to learn more about the various Python library
modules described in The Python Standard Library. This will be the
main source of information for the programming assignments in the
Appendix.
https://docs.python.org/3/tutorial/
• Non-Programmer’s Tutorial for Python 3: The Non-Programmers’ Tu-
torial For Python 3 is a tutorial designed to be an introduction to the
Python programming language. This guide is for someone with no
programming experience.
https://en.wikibooks.org/wiki/Non-Programmer%27s_Tutorial_
for_Python_3
• Python for Non-Programmers: If you’ve never programmed before, the
tutorials on this page are recommended for you; they don’t assume that
you have previous experience.
https://wiki.python.org/moin/BeginnersGuide/NonProgrammers
• Python for Programmers: The tutorials on this page are aimed at people
who have previous experience with other programming languages (C,
Perl, Lisp, Visual Basic, etc.).
https://wiki.python.org/moin/BeginnersGuide/Programmers
• The Python Wiki: This Wiki is a community place to gather and
organize all things about Python. Feel free to exercise your editorial
skills and expertise to make it a useful knowledge base and up-to-date
reference on all Python-related topics.
https://wiki.python.org/moin/FrontPage
• Learn Python the Hard Way: This book instructs you in Python by
slowly building and establishing skills through techniques like practice
and memorization, then applying them to increasingly difficult problems.
By the end of the book you will have the tools needed to begin learning
more complex programming topics.
https://learnpythonthehardway.org/book/
I thank Office of the Provost and the University Libraries for the Open
Educational Resources Mini-Grant in summer 2018 that allowed me the extra
time to adjust the course syllabus to accommodate this text.
Thanks to Cliff Smyth and Sebastian Pauli for piloting the use of these
notes in their courses. Thanks to others that found typos and mistakes,
including H. Parlaman.
Please submit errata and suggestions for improvement:
https://goo.gl/forms/1KyKylptFg3K6SX62
xiv Preface
Dan Yasaki
February 16, 2021
Chapter 1
In this chapter, we discuss logic and proofs. The rules of logic specify the
meaning of mathematical statements. These rules help us understand and
reason with these statements to construct arguments to justify the truth of
certain statements. Once we prove a mathematical statement true, we call it
a theorem. The argument of justification is called a proof .
Clear reasoning and communication of ideas is important in all disciplines.
We restrict ourselves to a small, but important corner of mathematics where
we can completely describe the theory with minimal prerequisites. The skills
you gain are applicable to many other situations.
1.1.1. Propositions.
Let’s first look at some statements that are not propositions. These fall
outside the scope of our study of propositional logic.
Example 1.1.2 (Question). Consider the statement “Where is the book-
store?” This is an interrogative, not declarative, statement. Questions are
not propositions.
Example 1.1.3 (Command). Consider the statement “Tie your shoe.” This
is an imperative, not declarative, statement. Commands are not propositions.
Example 1.1.4 (Paradox). Consider the statement “This statement is false.”
This is a declarative statement, but it is not a proposition. This is more
The last example is a bit more subtle. Here, the statement is not a
proposition because there are variables in the statement that are not quantified.
We will see how to deal with such things in detail in §1.3.
Example 1.1.5 (Unquantified). Consider the statement “x + 1 = 3.” This is
a declarative statement, but it is not a proposition. Why? The truthfulness
of the sentence depends on the value of the variable x, so it does not have a
well-defined truth value. For example, it is true when x = 2, but it is false
when x = 3. This sort of ambiguous statement is not a proposition.
We also allow statements that declare facts for which we may not know
the truth value.
Example 1.1.9. Consider the statement “Bob is taller than Alice.” This is
a proposition since it is a declarative statement that is either true or false,
but not both. It does not bother us that we don’t know if it is true or false.
The statement is a proposition because it declares a fact that is either true
or false.
Table 1.1.1 gives the truth table for negation. If p is true, then ¬p is false.
If p is false, then ¬p is true.
Example 1.1.11. Consider the proposition p = “2 + 3 = 5.” The negation
¬p is the proposition
¬p = “It is not the case that 2 + 3 = 5.”
More directly, ¬p can be expressed as “2 + 3 6= 5.” The original proposition
is true, so the negation is false.
Example 1.1.12. Consider the proposition q = “23 = 5.” The negation ¬q
is the proposition
¬q = “It is not the case that 23 = 5.”
More directly, ¬p can be expressed as “23 =
6 5.” The original proposition is
true, so the negation is false.
The conjunction is often referred to as and . Table 1.1.1 gives the truth
table for conjunction. If p is true and q is true, then p ∧ q is true. If p or q are
false (including the case where both p and q are false), then the conjunction
p ∧ q is false.
Example 1.1.14. Let p be the proposition “1 + 2 = 3,” and let q be the
proposition “3 + 4 = 7.” Since p and q are both true, the conjunction p ∧ q is
true. The conjunction can be expressed as
p ∧ q = “1 + 2 = 3 and 3 + 4 = 7.”
Example 1.1.15. Let p be the proposition “5 < 3,” and let q be the propo-
sition “4 = 7.” Both p and q are false. The conjunction p ∧ q is false. The
conjunction can be expressed as
p ∧ q = “5 < 3 and 4 = 7.”
Example 1.1.16. Let p be the proposition “5 < 5,” and let q be the propo-
sition “10 = 5 · 2.” The conjunction p ∧ q is false because p is false. The fact
that q is true is not enough to make the conjunction true. The conjunction
can be expressed as
p ∧ q = “5 < 5 and 10 = 5 · 2.”
p q p∧q
p ¬p T T T
T F T F F
F T F T F
F F F
Negation Conjunction
(not p) (p and q)
p q p∨q p q p⊕q
T T T T T F
T F T T F T
F T T F T T
F F F F F F
Disjunction Exclusive Disjunction
(p or q) (p xor q)
Example 1.1.27. The conditional of “52 = 10” and “3 · 4 = 12” is “if 52 = 10,
then 3 · 4 = 12.” The conditional is true because the the hypothesis is false.
Similarly, the conditional “if 52 = 10, then 3 · 4 = 13,” is also true.
p q p→q p q p↔q
T T T T T T
T F F T F F
F T T F T F
F F T F F T
Conditional Biconditional
(if p then q) (p if and only if q)
1.1.3. Truth tables. The truth table for a compound proposition gives
the possible truth values of a compound proposition in terms of the truth
values of the original propositions.
Remark 1.1.35. In general, if a compound proposition involves k proposi-
tional variables, the truth table will have 2k rows.
The truth tables for the converse, contrapositive, and inverse of a condi-
tional statement are given in Table 1.1.4.
Example 1.1.38. Consider the conditional “If I studied, then I passed the
course.”
• The converse is the conditional “If I passed the course, then I studied.”
• The contrapositive is the conditional “If I did not pass the course, then
I did not study.”
• The inverse is the conditional “If I did not study, then I did not pass
the course.”
Operator Precedence
¬ 1
∧ 2
∨ 3
→ 4
↔ 5
Remark 1.1.39. Table 1.1.4 shows that a conditional and its contrapositive
have the same truth values. It also shows that the inverse of a conditional
has the same truth values as the converse.
1.1.6. English is hard. The English language is tricky and subtle. There
are many ways to say the same thing, and there are many preconceptions
that people have that must be let go when studying logic. In this section, we
give lots of examples and highlight some of the common misconceptions.
Example 1.1.40. Let p be the proposition “It is raining,” and let q be the
proposition “I am happy.” Then the following are some of the correct ways
to express p ∧ q.
• It is raining, and I am happy.
• It is raining, but I am happy.
• It is raining, yet I am happy.
• Although it is raining, I am happy.
• If p, then q. • q whenever p.
• If p, q. • q if p.
• p implies q. • q follows from p.
• p only if q. • q unless ¬p.
• p is sufficient for q. • A sufficient condition for q is p.
• A necessary condition for p is q. • q is necessary for p.
Note that “p only if q” says that p cannot be true when q is not true.
Similarly, “q unless ¬p” says that if ¬p is false, then q must be true. Looking
at the truth tables, we see that they are restatements of if p, then q.
Example 1.1.41. “If the sun comes up in the morning, then 2 + 2 = 4.”
This conditional is true since the hypothesis and conclusion are true. The
conditional does not say anything about causation.
Example 1.1.46. An island has two tribes, truth-tellers and liars. You
encounter two people, Alice and Bob, on the island. Alice says “Bob is a
truth-teller,” and Bob says, “We are from different tribes.” Let’s figure out
who is from which tribe.
Let a and b be the propositions
a = “Alice is a truth-teller,”
b = “Bob is a truth-teller.”
Then Alice’s statement is b. Bob’s statement is that a and b have opposite
truth values, so his statement is a ↔ ¬b. Note that Alice’s statement must
have the same truth value as a because her statement is true if and only if
she is a truth-teller. That means a ↔ b must be true. Analogously, Bob’s
statement has the same truth value as b, so (a ↔ ¬b) ↔ b must be true.
Let’s work out the truth table. We are looking for a row where a ↔ b
and (a ↔ ¬b) ↔ b are both true.
a b ¬b a ↔ ¬b a ↔ b (a ↔ ¬b) ↔ b
T T F F T F
T F T T F F
F T F T F T
F F T F T T
From the last two columns, we see that b ↔ a and (a ↔ ¬b) ↔ b are both
true in the row where a and b are false. In other words, we have that Alice
and Bob are both liars.
Exercises
1. Give the definition for these terms. Be sure to set up any notation that
is required.
(a) proposition
(b) negation of a proposition
(c) conjunction of two propositions
(d) disjunction of two propositions
(e) exclusive disjunction of two propositions
(f) conditional of two propositions
(g) biconditional of two propositions
(h) converse of a conditional
(i) contrapositive of a conditional
(j) inverse of a conditional
2. Complete the following truth table.
p q p∨q p⊕q p∧q p→q p↔q
T T
T F
F T
F F
3. Identify each of the following as a proposition or not. For each proposition,
give the truth value.
(a) Greensboro is the capital of North Carolina.
(b) Let’s meet at the dining hall at 7pm.
(c) Squares have three sides.
(d) 2 · 5 = 11.
(e) a2 + b2 = c2 .
4. Identify each of the following as a proposition or not. For each proposition,
give the truth value.
(a) 1 + 1 = 2
r = “It is raining.”
w = “The ground is wet.”
Example 1.2.12. Let’s negate the statement “Jake is wearing khakis and
sounds hideous.” Let
j = “Jake is wearing khakis,”
h = “Jake sounds hideous.”
Then the original statement is j ∧ h. By De Morgan’s law, the negation is
¬(j ∧ h) = ¬j ∨ ¬h.
This is, “Jake is not wearing khakis, or he does not sound hideous.”
Proof. Exercise. Just compute the truth tables and verify the corresponding
columns are the same.
Proof. Exercise. Just compute the truth tables and verify the corresponding
columns are the same.
Proof. Exercise. Just compute the truth tables and verify the corresponding
columns are the same.
Since both statements are equivalent to s ∨ (¬f ∨ ¬r), the statements are
equivalent to each other.
Exercises
1. Give the definition for these terms. Be sure to set up any notation that
is required.
(a) tautology
(b) contradiction
(c) contingency
(d) logically equivalent propositions
2. State precisely De Morgan’s laws for propositions. Be sure to set up any
notation that is required.
3. Use De Morgan’s laws to find the negation of these statements.
(a) Alice will go to graduate school or get a job in industry.
(b) Bob majored in math and computer science.
(c) Carl is tall and thin.
(d) Dan has a laptop and a desktop.
(e) Eve or Frank will pick you up at the airport.
4. Show that each of these conditional statements is a tautology by using
truth tables.
(a) p → (p ∨ q)
(b) (p ∧ q) → p
(c) (p ∧ q) → (p → q)
(d) (¬p ∧ (p ∨ q)) → q
(e) ¬p → (p → q)
5. Complete the following truth table. Is p → q is logically equivalent to
¬p ∨ q? Justify. Be sure to say what portion of the computation explains
your response.
p q ¬p ¬p ∨ q p→q
T T
T F
F T
F F
6. Verify each associative law using a truth table. Which columns show the
logical equivalence?
(a) (p ∨ q) ∨ r ≡ p ∨ (q ∨ r)
(b) (p ∧ q) ∧ r ≡ p ∧ (q ∧ r)
7. Verify each absorption law using a truth table. Which columns show the
logical equivalence?
(a) p ∨ (p ∧ q) ≡ p
(b) p ∧ (p ∨ q) ≡ p
8. Show that ¬(p ⊕ q) and p ↔ q are logically equivalent.
9. Show that (p → q) ∨ (p → r) and p → (q ∨ r) are logically equivalent.
10. Show that (p ∧ q) → r and (p → r) ∧ (q ∧ r) are not logically equivalent.
11. Show that p ↔ q and ¬p ↔ ¬q are logically equivalent.
12. Prove the proposition identities in Theorem 1.2.13.
13. Prove the proposition identities in Theorem 1.2.14.
14. Prove the proposition identities in Theorem 1.2.15.
Example 1.3.1. Let P (x) be the statement “x > 3.” Then P (2) is the
proposition “2 > 3,” which is false. The proposition P (4) is the statement
“4 > 3”, which is true.
Then P (Alice, Bob, Carl) is the proposition “Alice, Bob, and Carl live in the
same dorm.”
Proof Technique 1.3.6 (To show ∀xP (x) is false). Suppose P is a propo-
sitional function, and we want to prove the universal quantification ∀xP (x)
is false.
(1) Find a counterexample. Specifically, find x0 in the domain of P such
that P (x0 ) is false.
(2) Conclude ∀xP (x) is false.
Example 1.3.8. Let P (x) = “x > 0” with domain R. Then ∀xP (x) is false.
To show this, it is enough to provide a single counterexample. Consider the
real number x0 = −2. Note that −2 6> 0, so P (−2) is false. Thus ∀xP (x) is
false.
Example 1.3.9. Consider the statement “All dogs have brown fur.” This
universally quantified statement is false. My dog Duey provides a counterex-
ample.
Let’s examine this in more detail. Let B(x) = “x has brown fur,” with
domain the set of all dogs. The universally quantified statement “All dogs
have brown fur,” can be written as ∀xB(x). This is false, because we can
produce a counterexample, namely my dog Duey. He is a dog, so he is in the
domain of B. He does not have brown fur, so B(Duey) is false. Thus ∀xB(x)
is false. In other words, not all dogs have brown fur.
Proof Technique 1.3.10 (To show ∀xP (x) is true). Suppose P is a propo-
sitional function, and we want to prove the universal quantification ∀xP (x)
is true.
(1) Fix a generic element x in the domain of P .
(2) Show P (x) is true for this fixed generic element.
(3) Conclude ∀xP (x) is true.
Example 1.3.11. Let P (x) = “x2 ≥ 0” with domain R. Then ∀xP (x) is
true. To see this, fix a generic real number x. Then x2 is non-negative since
the square of any real number is non-negative. Thus ∀xP (x) is true.
1.3.3. Existential quantification.
Proof Technique 1.3.15 (To show ∃xP (x) is true). Suppose P is a propo-
sitional function, and we want to prove the existential quantification ∃xP (x)
is true.
(1) Find a witness. Specifically, find an element x0 in the domain of P such
that P (x0 ) is true.
(2) Conclude ∃xP (x) is true.
Example 1.3.18. Let N (x) = “x was born in NC,” with domain the MAT
253 students.
(1) ∀xN (x)
(2) ∃xN (x)
What are the truth values of the two propositions above? Do you need to
discuss this with your classmates to determine the truth values?
(1) ∀xN (x) says “Every student in MAT 253 was born in NC.” To prove
this statement false, it is enough to produce a counterexample. We need
to just find one student in MAT 253 that was not born in NC. To prove
this statement true, we need to check that every MAT 253 student was
born in NC.
(2) ∃xN (x) says “There is a student in MAT 253 that was born in NC.” To
prove this statement true, it is enough to produce a witness. We need
to find just find one student in MAT 253 that was not born in NC.
Proof. Let’s prove the first statement and leave the proof of the second as
an exercise.
We want to show
¬∀xP (x) ≡ ∃x¬P (x).
We just need to show that the left side and the right side have the same truth
values, independent of what P or x actually is. The left side is the negation
of ∀xP (x). Thus the left side is true if ∀xP (x) is false. Thus ∀xP (x) must
have a counterexample x0 . Then P (x0 ) is false, which means ¬P (x0 ) is true.
Thus x0 provides the example showing ∃x¬P (x) is true. Therefore the right
side is true as well.
Similarly, now suppose the left side is false. Then ∀xP (x) is true. It
follows that ¬P (x) is never true, so the existential statement of the right side
is also false.
Example 1.3.21. Consider the statement “No one is perfect.” Translate it
into a logical expression using predicates and quantifiers. Then use De
Morgan’s laws to rewrite it.
The statement is that there does not exist a person that is perfect. Let
P (x) = “x is perfect,” with domain the set of all people. Then the statement
is ¬∃xP (x). By De Morgan’s laws
¬∃xP (x) ≡ ∀x¬P (x),
which says that everyone is imperfect.
Example 1.3.22 (Lewis Carroll).
(1) All lions are fierce.
(2) Some lions do not drink coffee.
(3) Some fierce creatures do not drink coffee.
Let’s write the three statements into logical expression using predicates
and quantifiers.
Let L, F , and C be propositional functions
L(x) = “x is a lion,”
F (x) = “x is fierce,”
C(x) = “x drinks coffee,”
with domain all creatures. Then the sentences can be expressed follows.
(1) ∀x(L(x) → F (x))
(2) ∃x(L(x) ∧ ¬C(x))
(3) ∃x(F (x) ∧ ¬C(x))
Suppose we know that the first two statements are true. Does this allow
us to deduce the third statement? We will see more examples in the following
section, but let’s examine this particular example more closely first.
Suppose the first two statements are true. The second statement guaran-
tees the existence of a creature, we’ll call him Bob, such that L(Bob) and
¬C(Bob) are both true. Since L(Bob) is true, the conditional in the first
statement tells us that F (Bob) is true. Since F (Bob) and ¬C(Bob) are both
true, Bob provides the example to show the third statement is true.
In other words, since some lions do not drink coffee, there must be a lion
that does not drink coffee. Let’s call him Bob. Then since all lions are fierce,
we have that Bob is fierce. Since Bob is fierce and does not drink coffee, we
know that some fierce creatures do not drink coffee.
Exercises
1. Give the definition for these terms. Be sure to set up any notation that
is required.
(a) universal quantification of a propositional function
14. Alice was overheard saying, “I will go out with Bob when pigs fly.” Rewrite
this in the form “if p, then q.” Assuming that Alice speaks the truth, use
propositional logic to explain what, if any, implications this has for Alice
and Bob.
15. Suppose we have the following rules for Alice.
Taylor’s rule: Alice eats her veggies, or she can’t have dessert.
Leslie’s rule: If Alice eats her veggies, then she can have dessert.
Alex’s rule: Alice can have her dessert, when she eats her veggies.
Cameron’s rule: Alice can have her dessert, only if she eats her
veggies.
Alice’s rule: Alice can have her dessert.
If Alice’s parents agree on a rule, what are their names? (They do not
have the same name. There may be more than one correct answer.)
Goals. To introduce the notion of proof and basic methods of proof, in-
cluding direct proof, proof by contraposition, and proof by contradiction.
Furthermore, to learn how to distinguish between correct and incorrect
arguments, and to understand and construct basic types of proofs.
1.4.1. Direct proof. Recall the conditional p → q has the following truth
table.
p q p→q
T T T
T F F
F T T
F F T
It follows that if we want to prove that p → q is true, we need to show
that the second row (p = T, q = F) does not occur. One approach, called
the direct proof is constructed when we start by assuming p is true. Then
we show that q is true.
(2) When we want to prove a statement of the form “if p, then q” directly,
we assume p is true and try to show q. This is commonly where we set
some notation as well. Let a and b be odd integers.
(3) Next we need to recall what an odd integer is. An integer n is odd if
there exists an integer k such that n = 2k + 1.
(4) Now apply the definition to our situation. Since a is odd, there
exists an integer k such that a = 2k + 1.
(5) Since b is odd, there exists an integer ℓ such that b = 2ℓ + 1.
(6) Check back above to be sure that the two integers whose existence is
guaranteed have different names. They need different names because
they need not be the same integer.
(7) Now look back to the goal that we set in 1. Since we want to say
something about a + b, it makes sense to Compute a + b and simplify.
a + b = 2k + 1 + 2ℓ + 1
= 2k + 2ℓ + 2
= 2(k + ℓ + 1).
(8) The line above should prove a + b is even, provided the bit in the
parentheses is an integer. Make some remark noting that, and we are
done. Since k and ℓ are integers, we have k + ℓ + 1 is an integer,
and so a + b is even.
Putting that all together yields the following.
Proof. Let a and b be odd integers. Since a is odd, there exists an integer
k such that a = 2k + 1. Since b is odd, there exists an integer ℓ such that
a = 2ℓ + 1. Compute a + b and simplify.
a + b = 2k + 1 + 2ℓ + 1
= 2k + 2ℓ + 2
= 2(k + ℓ + 1).
Since k and ℓ are integers, we have k + ℓ + 1 is an integer, and so a + b is
even.
Example 1.4.12. Prove that the product of two even integers is even.
Proof. Let m and n be even integers. Then there exist integers k and ℓ such
that m = 2k and n = 2ℓ. Then
mn = 2k · 2ℓ = 4kℓ = 2(2kℓ).
Since k and ℓ are integers, 2kℓ is an integer. Thus m + n is even.
Example 1.4.13. Let m and n be real numbers. Prove that m2 = n2 if and
only if m = n or m = −n.
Proof. Suppose not. Suppose there is a rational number r = a/b such that
r3 + r + 1 = 0, where we write a/b is lowest terms so that a and b have no
common factors. Then a 3 a
+ + 1 = 0.
b b
Multiplying both sides by b3 , we get
a3 + ab2 + b3 = 0.
There are four cases to consider, depending on the parity (even/odd) of a
and b.
a and b both even: Contradiction! We have a/b in lowest terms, but
they have a common factor of 2.
a and b both odd: Then a3 , ab2 , and b3 are all odd. The sum of three
odd numbers is odd. Contradiction! 0 is even.
a is even b is odd: Then a3 and ab2 are even, and b3 is odd. The sum of
two even integers and an odd integer is odd. Contradiction! 0 is even.
a is odd b is even: Then a3 is odd, and ab2 and b3 are even. The sum of
an odd integer and two even integers is odd. Contradiction! 0 is even.
Thus there is not rational number r such that r3 + r + 1 = 0.
Example 1.4.21. Prove there is an integer that can be written as the sum
of cubes of positive integers in two different ways.
There are some proofs of existence that do not produce a witness. These
are called nonconstructive proofs.
Example 1.4.23. Prove there exist irrational numbers a and b such that ab
is rational.
√
Proof. We have already seen that 2 is irrational in Example 1.4.19. If
√ √2 √ √
2 is rational, then a = 2, b = 2 is our witness, and we are done.
√ √2
Otherwise, 2 is irrational. In this case,
√
√ 2 √2 √ 2
( 2 ) = 2 = 2,
√
√ 2 √
which is rational, so a = 2 ,b = 2 is our witness.
Note that this proof does not tell us which case occurs, so it is noncon-
structive.
• ax
This is not a sentence.
• ax = b has a solution.
This is a sentence, but it is not true or false. We need to know more
about a and b.
• Let a ∈ R, a 6= 0. Then ax = b has a solution.
This is a bit better. The first sentence sets notation, but the second
sentence is still neither true nor false since we have not specified the
universe for b.
• Let a ∈ R, a 6= 0. Then ax = b has a solution for every b ∈ R.
The first sentence sets notation. All of the notation is defined. The
second sentence is true.
Exercises
1. Give the definition for these terms. Be sure to set up any notation that
is required.
(a) even integer
(b) odd integer
(c) rational number
2. Use a direct proof to show that the sum of two odd integers is even.
3. Use a direct proof to show that the sum of two even integers is even.
4. Use a direct proof to show that the product of two odd integers is odd.
5. Use a proof by contradiction to prove that the sum of an irrational number
and a rational number is irrational.
6. Use a direct proof to show the product of two rational numbers is a
rational number.
7. Prove each of these statements is false by providing a counterexample.
(a) The product of two irrational numbers is irrational.
(b) The sum of two irrational numbers is irrational.
(c) Every positive integer can be written as the sum of the squares of
three integers.
(d) If n is an integer, then n2 > n.
(e) If a and b are rational number, then ab is also rational.
8. Let P (n) be the proposition “n2 ≥ n.” Prove P (1) is true.
9. Use a proof by contradiction to prove that if n is an integer and n3 + 5
is odd, then n is even.
10. Prove there is a right triangle with all three sides having rational lengths.
11. Prove there exists a pair of consecutive integers such that one of these
integers is a perfect square and the other is a perfect cube.
12. Go to
http://link.springer.com/book/10.1007%2F978-1-4419-7023-7
while on campus and download The Art of Proof by Matthias Beck and
Ross Geoghegan. Read carefully Chapters 1–7.
Chapter 2
Basic Structures
2.1. Sets
41
42 2. Basic Structures
Example 2.1.4. Let A = {1, 2, 2, 5}, and let B = {1, 2, 5}. Then A = B.
Why? For every element x, the truth value of x ∈ A is the same as the truth
value of x ∈ B. Thus A = B by definition.
To show two sets are equal, we use subsets as described later in Proof
Technique 2.1.14. It is more straightforward to show two sets are not equal.
Since set equality is defined as the universal quantification (“for all”) of a
biconditional (“if and only if”), to show two sets are not equal, it is enough
to find any counterexample to the biconditional. In particular, we just need
to produce any element that they do not share.
Proof Technique 2.1.5 (To show A 6= B). Suppose A and B are sets,
and we want to prove A is not equal to B.
(1) Find a particular element a in A that is not a member of B; or find a
particular element b in B that is not a member of A.
(2) Conclude A 6= B.
Definition 2.1.6. The empty set, denoted ∅, is the set with no elements.
2.1. Sets 43
Proof Technique 2.1.11 (To show A ⊆ B). Suppose A and B are sets,
and we want to prove A is a subset of B.
(1) Let x be a generic element of A.
(2) Show that x is in B.
(3) Conclude A ⊆ B.
It seems like we just ran around in circles in the proof above. Read it
over again, paying attention to what it is we need to show.
For a set A to be a proper subset of set B, we need A to be a subset of
B that is not equal to B.
Proof Technique 2.1.13 (To show A ⊂ B). Suppose A and B are sets,
and we want to prove A is a proper subset of B.
(1) Use Proof Technique 2.1.5 to show A 6= B.
(2) Use Proof Technique 2.1.11 to show A ⊆ B.
(3) Conclude A ⊂ B.
44 2. Basic Structures
By definition, two sets are equal if they have the same elements. This
implies that each one is a subset of the other. We can turn this into a proof
technique for showing two sets are equal.
Proof Technique 2.1.14 (To show A = B). Suppose A and B are sets,
and we want to show A is equal to B.
(1) Use Proof Technique 2.1.11 to show A ⊆ B.
(2) Use Proof Technique 2.1.11 to show B ⊆ A.
(3) Conclude A = B.
We discuss sets that are not finite and their cardinality in §5.1. The
notion if infinity is subtle; there are different sizes of infinity.
Example 2.1.16. The empty set ∅ has size 0
|∅| = 0
since {} has no elements.
Example 2.1.17. Let E be the even integers between −5 and 5, not including
−5 and 5. Then we can compute the size of E by writing E using the roster
method and counting.
E = {−4, −2, 0, 2, 4},
so |E| = 5.
Example 2.1.18. Let C be the set of consonants in the English alphabet.
Instead of listing the elements of C in roster method, we note that there are
26 letters in the English alphabet. Of these, 5 are vowels and the rest are
consonants. Thus
|C| = 26 − 5 = 21.
Example 2.1.20. Suppose A = {2, x, π}. The power set of A is the set of
all subsets of A. Let’s work out the subsets systematically, ordered by size.
Size 0: There is only 1 subset of size 0. It is the empty set: ∅.
2.1. Sets 45
Size 1: These singleton sets each contain one element of A. Since there
are 3 elements in A, there are 3 subsets of size 1: {2}, {x}, and {π}.
Size 2: Subsets of A of size 2 can be constructed by omitting one element.
Since there are 3 elements in A, there are 3 subsets of size 2: {2, x},
{2, π}, and {x, π}.
Size 3: There is only 1 subset of size 3. It is the set A itself: {2, x, π}.
Size > 3: Since |A| = 3, there are no subsets of A that have size larger
than 3.
Thus the power set of A is
P(A) = {∅, {2}, {x}, {π}, {2, x}, {2, π}, {x, π}, {2, x, π}}.
Example 2.1.23. Let A = {0, 1}, and let B = {4, 5, 6}. Then the Cartesian
product A × B is the set of all ordered pairs (a, b), where a is an element
from A and b is an element of B. Thus
A × B = {(0, 4), (0, 5), (0, 6), (1, 4), (1, 5), (1, 6)}.
Analogously, the Cartesian product B × A is the set of all ordered pairs (b, a),
where b is an element of B and a is an element of A. Thus
B × A = {(4, 0), (4, 1), (5, 0), (5, 1), (6, 0), (6, 1)}.
More generally, we can define the Cartesian product of more than two
set.
Definition 2.1.24. The Cartesian product of sets A1 , A2 , . . . , An , de-
noted A1 × A2 × · · · × An is the set of ordered n-tuples (a1 , a2 , . . . , an ) where
ai ∈ Ai for i = 1, 2, . . . , n. That is,
A1 × A2 × · · · × An = {(a1 , a2 , . . . , an ) | ai ∈ Ai for i = 1, 2, . . . , n}.
46 2. Basic Structures
Exercises
1. Give the definition for these terms. Be sure to set up any notation that
is required.
(a) set
(b) equal sets
(c) empty set
(d) subset
(e) proper subset
(f) cardinality of a set
(g) power set of a set
(h) Cartesian product of sets
(i) relation
2. Write each set in roster notation.
(a) {n ∈ Z | n is odd and n ≤ 10}
(b) {n ∈ Z | |n| ≤ 3}
(c) the set of positive, even integers less than 6
(d) {x ∈ R | x2 − x − 1 = 0}
(e) {x ∈ R | x is the square of an integer and x < 100}
(f) {x ∈ R | x2 = −1}
3. Use set builder notation to give a description of each of these sets.
(a) {2, 3, 4, 5, 6, 7, 8}
(b) {0, 3, 6, 9, 12}
(c) {−2, −1, 0, 1, 2}
(d) {0, 4, 9, 16, 25, 36}
4. For each of these pairs of sets, determine whether the first is a subset of
the second, the second is a subset of the first, or neither is a subset of
the other.
(a) the set of dogs; the set of mammals
(b) the set of people who speak English; the set of people who speak
Japanese
(c) the set of math majors; the set of computer science majors
(d) the set of people over 6 feet tall; the set of people over 5 feet tall
(e) the set of animals; the set of alligators
5. For each of these sets, determine whether 3 is an element of that set.
(a) {1, 3, 5, 7, 9}
(b) {{3, 5}, {2, 4}}
Goals. To show how set identities are established and to introduce the
most important such identities.
48 2. Basic Structures
U U
A B A B
Union: A ∪ B Intersection: A ∩ B
Example 2.2.2. Let A = {1, 2, 3, 5, 10}, and let B = {2, 3, 4, 5}. To compute
the union A ∪ B, we combine all of the elements of A together with all of the
elements of B into one set. The union of A and B is
A ∪ B = {1, 2, 3, 4, 5, 10}.
Example 2.2.4. Let A = {1, 2, 3, 5, 10}, and let B = {2, 3, 4, 5}. To compute
the intersection A ∩ B, we take the elements of A that are also elements of
B. In other words, we only keep elements that A and B have in common.
The intersection of A and B is
A ∩ B = {2, 3, 5}.
Example 2.2.6. Let A = {1, 2, 3, 5, 10}, and let B = {2, 3, 4, 5}. The
difference of A and B consists of members of A that are not also members of
B, so we take all the elements of A and throw out the ones that are in B.
That gives
A − B = {1, 10}.
U U
A B A B
Difference: A − B Difference: B − A
A B
Symmetric Difference: A ⊕ B
Example 2.2.8. Let A = {1, 2, 3, 5, 10}, and let B = {2, 3, 4, 5}. To compute
the symmetric difference of A and B, we combine the elements of A and B,
and them remove the elements that are members of both A and B. Thus
A ⊕ B = {1, 4}.
50 2. Basic Structures
Complement: A
Example 2.2.10. Let A = {1, 2, 3, 5, 10}, and let B = {2, 3, 4, 5}. Suppose
U = {1, 2, . . . , 10}. Then the complement of A consists of elements in U that
are not in A. We can compute it by taking all of the elements of U and
throwing out the elements of A. That gives
A = {4, 6, 7, 8, 9}.
Analogously, the complement of B is consists of members of U that are not
in B, so
B = {1, 6, 7, 8, 9, 10}.
Example 2.2.12. Let A = {1, 3, 5, 7}, and let B = {2, 4, 6}. Then A and B
have no elements in common, so A ∩ B = ∅. Thus A and B are disjoint.
Example 2.2.13. Prove if A ⊆ B, then A ∩ B = A.
A B
B C
B C
52 2. Basic Structures
Theorem 2.2.19 (Set identities I). Let A be a set with universal set U .
Identity laws: A ∩ U = A; A ∪ ∅ = A
Domination laws: A ∪ U = U ; A ∩ ∅ = ∅
Idempotent laws: A ∪ A = A; A ∩ A = A
Complementation law : A = A
Complement laws: A ∪ A = U ; A∩A=∅
We prove the associative law for intersection in several ways and leave
the rest as an exercise. Let A and B be sets. We want to show
(A ∩ B) ∩ C = A ∩ (B ∩ C).
54 2. Basic Structures
Theorem 2.2.22 (De Morgan’s laws for sets). Let A and B be sets.
(1) A ∪ B = A ∩ B
(2) A ∩ B = A ∪ B
Exercises
1. Give the definition for these terms. Be sure to set up any notation that
is required.
(a) union of sets
(b) intersection of sets
(c) difference of sets
(d) complement of a set
(e) disjoint sets
2. State precisely De Morgan’s laws for sets. Be sure to set up any notation
that is required.
3. Let C = {r, s, t, l, n, e}, and let W = {f, o, r, t, u, n, e}. Compute each of
these sets.
(a) C ∩ W
(b) C ∪ W
(c) C ⊕ W
(d) C − W
(e) W − C
4. Let A, B, C be sets. Shade the portion of the Venn diagram corresponding
to each of these sets.
U
B C
(a) A ∪ (B ∩ C)
(b) A ∩ (B ∩ C)
(c) A ∩ (B ∪ C)
(d) (A ∩ B) ∪ C
(e) (A − B) − C
(f) (A − B) ∪ (A − C) ∪ (B − C)
5. Let A = {1, 3, 5, 7, 9}, and let B = {1, 2, 3, 4, 5}. Compute the following
sets.
(a) A ∩ B
(b) A − B
(c) A ∪ B
(d) B − A
(e) B ⊕ A
6. Let A and B be sets. Prove that if A ⊆ B, then A ∪ B = B.
7. Prove the set identities in Theorem 2.2.19.
8. Prove the set identities in Theorem 2.2.20.
9. Prove the set identities in Theorem 2.2.21.
10. Prove De Morgan’s laws for sets.
11. Let A and B be sets. Prove A ⊕ B = (A − B) ∪ (B − A).
12. Let A and B be sets.
(a) Prove if A ⊆ B then B ⊆ A.
(b) Prove if B ⊆ A then A ⊆ B.
56 2. Basic Structures
f
A B
2.3. Functions
A function must output a value for every input from the domain. Not
every element in the codomain needs to be an image, though.
Example 2.3.3. Consider f (x) = x2 + 3. Then f defines a function from R
to R. We write f : R → R. The domain is R. The codomain is R.
√
On the other hand, g(x) = x is not a function from R to R. This is
because, for example, −2 is an element of R, but the formula does not define
a value for g(−2). We can view g as a function from R≥0 to R.
2.3. Functions 57
58 2. Basic Structures
• The image or range of the function f the same as the image of the
domain A under f . This is {1, 3, 4}, since
We can think about functions in terms of objects and arrows, where each
arrow joins an element a in A to the corresponding element f (a) in B as
show in the next example.
Example 2.3.9. On the left, we represent the function Example 2.3.8 graph-
ically using objects and arrows. On the right, we give the representation for
a different function. Note that in each case, each element of A is assigned
to a unique element of B. An element of B may be the image of 1, none, or
several elements of A.
1 1
1 1
2 2
2 2
3 3
3 3
4 4
Function Function
2.3. Functions 59
1 1
1 1
2 2
2 2
3 3
3 3
4 4
Example 2.3.14. The floor ⌊2.7⌋ = 2, since 2 is the largest integer that is
less than or equal to 2.7.
Example 2.3.15. The floor ⌊−2.7⌋ = −3, since −3 is the largest integer
that is less than or equal to −2.7.
60 2. Basic Structures
Example 2.3.18. The ceiling ⌈2.7⌉ = 3, since 3 is the smallest integer that
is greater than or equal to 2.7.
Example 2.3.19. The ceiling ⌈−2.7⌉ = −2, since −2 is the smallest integer
that is greater than or equal to −2.7.
Example 2.3.20. The ceiling of an integer is the integer itself, so ⌈3⌉ = 3,
⌈−3⌉ = −3, and ⌈0⌉ = 0.
Remark 2.3.21. If we think of x as a point on the usual real number line,
then the floor of x is the integer that is directly to the left of x, unless x
itself is an integer. The ceiling of x is the integer that is directly to the right
of x, unless x itself is an integer.
2.3. Functions 61
Example 2.3.23 shows the general technique for showing a function is not
injective.
Example 2.3.25. The function U denote the set of UNCG students, and
consider the function id : U → Z that assigns to each student their university
ID. In other words, id(x) is the university ID of x. These ID numbers are
unique by design so that so that no two students have the same university ID.
Specifically, the only way to have id(student a) = id(student â) is to have
student a be the same student as â. The id function is injective.
For an injective function, every element in the codomain can have at most
one preimage.
Example 2.3.26. These are graphical representations of injective functions.
In each instance, each element in the codomain has at most one preimage.
1 1 1
1
2 2 2
2
3 3 3
3
4 4 4
Injective Injective
Example 2.3.27. These are graphical representations of functions that are
not injective. In each instance, there is an element in the codomain has
more than one preimage. On the left, both 1 and 4 map to 2, so 2 has two
preimages. On the right, 2, 3, and 4 map to 3, so 3 has three preimages.
62 2. Basic Structures
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
(1) First, we will rewrite what we want to show in the form “if p, then q.”
This will involve giving names to objects, and recalling the definition
of injective. We want to prove f is injective, which means we want to
prove: If f (a1 ) = f (a2 ), then a1 = a2 .
(2) As before, to prove a statement of the form “if p, then q” directly, we
assume p is true and try to show q. This is commonly where we set
some notation as well. It is also a good place to remind the reader what
we want to show. e.g., Let a1 and a2 be real numbers such that
f (a1 ) = f (a2 ). We want to show that a1 = a2 .
(3) Now look back at the goal. It should be some relationship between a1
and a2 . It makes sense to write out what we know and simplify to see if
we get what we want.
f (a1 ) = f (a2 )
3a1 − 2 = 3a2 − 2
3a1 = 3a2
a1 = a2
(4) The part above should complete the proof. Since we chose generic a1
and a2 from the domain of f , the argument covers all a1 and a2 in the
domain of f .
2.3. Functions 63
Example 2.3.31 shows the general technique for proving a function is not
surjective.
64 2. Basic Structures
1 1 1
1
2 2 2
2
3 3 3
3
4 4 4
Surjective Surjective
Example 2.3.35. These are graphical representations of functions that are
not surjective. In each instance, there is an element in the codomain has has
no preimage. On the left, there is no element that maps to 4, so 4 has no
preimage. On the right, no elements map to 2 or 4, so both 2 and 4 have no
preimages.
1 1 1
1
2 2 2
2
3 3 3
3
4 4 4
2.3. Functions 65
(1) First we recall the definition of surjective. At the same time, we give
names to things. We want to prove: For every b in R (the codomain
of f ), there exists a in R (the domain of f ) such that f (a) = b.
(2) Now this still does not look like a “if p, then q” type of statement. What
helps is the same thing as the previous exercise. Namely, if we pick
a generic b in R, then the argument will work for every b in R. That
means we want to prove the statement: If b ∈ R, then there exists
a ∈ R such that f (a) = b.
(3) As before, to prove a statement of the form “if p, then q” directly, we
assume p is true and try to show q. This is commonly where we set
some notation as well. It is also a good place to remind the reader what
we want to show. e.g., Let b ∈ R. We want to find a ∈ R such that
f (a) = b.
(4) Since we want to find a, we should write out the conditions that a must
satisfy, and see if we can solve for a.
f (a) = b
3a − 2 = b
3a = b + 2
b+2
a= .
3
(5) We have found a as desired. Since b is generic, the argument holds for
all b in R. That completes the proof.
66 2. Basic Structures
f
A B
f −1
Remark 2.3.41. If A and B are finite sets of the same size, a function
f : A → B is surjective if and only if f is injective. Furthermore, if |A| < |B|
then f cannot be surjective. If |B| < |A| then f cannot be injective.
Example 2.3.42. The area of a circle is a function of its radius. This
function is injective, because if the area of a circle of radius r is equal to
the area of a circle of radius r′ , we must have r = r′ . This function is not
surjective, when viewed as a function from R>0 to R, since there is no radius
that would give rise to area −1. When we restrict the codomain to R>0 , this
function is surjective since we can construct a circle for any given area.
Remark 2.3.45.
2.3. Functions 67
Thus g is the inverse of f . (Note: This also shows that f is the inverse of g.)
68 2. Basic Structures
f g
A B C
g◦f
Exercises
1. Give the definition for these terms. Be sure to set up any notation that
is required.
(a) function
(b) image of an element
2.3. Functions 69
70 2. Basic Structures
Remark 2.4.2. Note the notation conflicts with our notation for sets. The
context will make it clear which we are discussing.
Example 2.4.3. The sequence {an }, where an = n12 for n = 1, 2, 3, . . . has
terms
1 1 1 1 1 1
1, , , , , . . . , 2 , ,....
4 9 16 25 n (n + 1)2
2.4.2. Geometric and arithmetic sequences.
72 2. Basic Structures
f0 =0
f1 =1
f2 = f1 + f0 =1+0=1
f3 = f2 + f1 =1+1=2
f4 = f3 + f2 =2+1=3
f5 = f4 + f3 =3+2=5
Using linear algebra, we can also find an explicit formula, called a closed
formula for the terms of this sequence.
74 2. Basic Structures
We can use these properties to break down complicated sums into simpler
ones.
Example 2.4.25. Break down the summation
100
X
(3k 2 − 5k + 2)
k=0
to a sum of simpler summations.
We use the properties in Theorem 2.4.24
100
X 100
X 100
X 100
X
(3k 2 − 5k + 2) = 3k 2 − 5k + 2
k=0 i=0 k=0 k=0
100
X 100
X 100
X
=3 k2 − 5 k+2 1.
k=0 k=0 k=0
76 2. Basic Structures
Proof. If r = 1, then
n
X n
X
ari = a = a + a + · · · + a = (n + 1)a.
| {z }
i=0 i=0 n + 1 times
Pn i.
Now suppose r 6= 1. Let s = i=0 ar Then
n
X n+1
X
i+1
rs = ar = ari .
i=0 i=1
Then
n+1
X n
X
i
s(r − 1) = rs − s = ar − ari = arn+1 − a.
i=1 i=0
1 1 1
1+ + 2 + · · · + 100 .
2 2 2
Proof. We prove the first two formulae here. We reprove the second and
prove the latter two later in the section on mathematical induction §4.1.
We have
Xn
1 = 1 + 1 + · · · + 1 = n.
| {z }
k=1 n times
Suppose n is even. Then
n
X n n n(n + 1)
k = (1 + n) + (2 + (n − 1)) + · · · + ( + ( + 1)) = .
2 2 2
k=1 | {z }
n
2
pairs that sum to n + 1
78 2. Basic Structures
P
First, let’s compute 100 2
k=0 k . We break off piece that starts at k = 1 so
we can use Theorem 2.4.28,
100
X 100
X
k 2 = 02 + k2 .
k=0 k=1
P100
Since 02= 0, this is just k=1 k2 , which matches the formula in the theorem
using n = 100. Thus
100
X 100(100 + 1)(2(100) + 1)
k2 = 0 + = 338,350.
6
k=0
Similarly, we write
100
X 100
X
k =0+ k.
k=0 k=1
We use Theorem 2.4.28 with n = 100 to get
100
X 100(100 + 1)
k =0+ = 5050.
2
k=0
Finally,
100
X 100
X
1=1+ 1,
k=0 k=1
so by Theorem 2.4.28,
100
X
1 = 1 + 100 = 101.
k=0
Example 2.4.30.
500
X 500
X 500
X
(7k + 3) = 7 k+ 3
k=1 k=1 k=1
500(501)
=7· + 3(500)
2
= 878,250.
Exercises
1. Give the definition for these terms. Be sure to set up any notation that
is required.
(a) sequence
(b) geometric progression, common ratio, initial term
(c) arithmetic progression, common difference, initial term
80 2. Basic Structures
Chapter 3
3.1.1. Divisibility.
Example 3.1.2.
3 divides 12: 3 | 12 since 12 = 3 · 4.
81
Proof.
(1) Suppose a | b and a | c. Then there exists integers m and n such that
b = am and c = an. We want to show a | (b + c). We compute
b + c = am + an = a(m + n).
Since m and n are integers, m + n is an integer. Thus a | (b + c).
(2) Suppose a | b. Then there exists an integer n such that b = an. We
want to show a | bc. We compute
bc = (an)c = a(nc).
Since n and c are integers, nc is an integer. Thus a | bc.
(3) Suppose a | b and b | c. Then there exist integers m and n such that
b = am and c = bn. We want to show a | c. We compute
c = bn = (am)n = a(mn).
Since m and n are integers, mn is an integer. Thus a | mn.
Corollary 3.1.4. Let a, b, c ∈ Z with a 6= 0. If a | b and a | c, then
a | (sb + tc) for all s, t ∈ Z.
Remark 3.1.14. This notion is different (but related) to the mod represent-
ing the remainder from the division algorithm. For example, if a = b mod m,
then a is an integer with 0 ≤ a < m. In particular, b mod m is an integer.
On the other hand, a ≡ b (mod m) asserts a relationship between a and b.
We never write b (mod m) by itself.
Since â, b̂, k, m, and ℓ are integers, (k b̂ + ℓâ + kℓm) is an integer. Thus
ab ≡ âb̂ (mod m) by Theorem 3.1.15.
The result says that we can take any element in the congruence class of
a and add it to any element in the congruence class of b, and we will get
an element of the congruence class of a + b, and the analogous result for
multiplication. The division algorithm ensures that each congruence class
modulo m will contain a unique representative 0 ≤ a < m, so we can transfer
the arithmetic on congruence classes to an arithmetic on congruence class
representatives.
a2 − b ≡ 52 − 2 ≡ 23 ≡ 3 (mod 10).
Exercises
1. Give the definition for these terms. Be sure to set up any notation that
is required.
(a) divides
(b) factor
(c) multiple
(d) divisor
(e) dividend
(f) quotient
(g) remainder
(h) two integers are congruent modulo an integer
(i) congruence class of an integer modulo an integer
(j) Zm
(k) primitive root
2. State precisely the Division algorithm. Be sure to set up any notation
that is required.
3. Does 13 divide these numbers? Justify.
(a) 39
(b) −26
(c) 0
(d) 1
(e) 57
4. What is the quotient and remainder for these?
(a) 44 divided by 7
(b) −123 divided by 12
(c) 253 divided by 15
(d) 0 divided by 17
(e) −100 divided by 100
5. Suppose a and b are integers such that a ≡ 11 (mod 17), and b ≡ 3
(mod 17). Find the integer c with 0 ≤ c ≤ 16 such that satisfies these.
(a) c ≡ 13a (mod 17)
(b) c ≡ 5a (mod 17)
(c) c ≡ −2a + 3b (mod 17)
(d) c ≡ ab (mod 17)
(e) c ≡ a3 − b2 (mod 17)
6. Evaluate these quantities.
(a) −15 mod 6
(b) −2 mod 12
(c) 124 mod 7
(d) 244 mod 24
(e) 1245 mod 3
7. Find a primitive root modulo 11.
8. What is the congruence class of 5 modulo 7?
9. Compute the addition and multiplication table for Z5 .
10. Let a, b, c be integers, where a, b 6= 0. Follow the steps below to prove
that if a | b and b | c, then a | c.
(a) First, we recognize what we want to prove is in the form “if p, then
q.” What is hypothesis p? What is the conclusion q?
(b) When we want to prove a statement of the form “if p, then q” directly,
we assume p is true and try to show q. This is commonly where we
k
X
Definition 3.2.2. The expression ai bi of the theorem is known as a
i=0
base b expansion, denoted (ak ak−1 . . . a1 a0 )b .
Example 3.2.3.
For b > 10, we move to other symbols to represent the digits. For example,
in hexadecimal (base 16), the digits are
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
Example 3.2.4.
i q ai
0 325 0
1 65 0
2 13 3
3 2 2
4 0 −
Then divide the result by m to get the remainder. There are at least two
problems with this in practice. The first is that computing bn in this way
requires n − 1 multiplications. If n is large, this is slow. We can get around
this using fast exponentiation. We will develop the algorithm by first
looking at an example.
Example 3.2.11. Compute 311 .
First, we compute the binary expansion of 11 = (1011)2 . Then
3 +21 +1
311 = 32 = 38 · 32 · 3.
We can save even more time when we only care about the remainder
modulo some integer.
Example 3.2.12. Compute 311 mod 7.
As in Example 3.2.11, we will use the square and multiply technique to
get the exponentiation faster. As before, we compute the binary expansion
of 11 = (1011)2 . Then
3 +21 +1
311 mod 7 = 32 mod 7 = (38 · 32 · 3) mod 7.
We make additional time and memory savings by keeping the integers small.
We achieve this by reducing mod 7 at every stage, since we only want the
result modulo 7.
We have by repeated squarings,
3 mod 7 = 3
32 mod 7 = 2
34 mod 7 = 22 mod 7 = 4
38 mod 7 = 42 mod 7 = 2.
i ai pi x
0 1 3 mod 253 = 3 1 · 3 mod 253 = 3 ←
1 1 32 mod 253 = 9 3 · 9 mod 253 = 27 ←
2 0 92 mod 253 = 81 27
3 2
0 81 mod 253 = 236 27
4 0 2362 mod 253 = 36 27
5 0 362 mod 253 = 31 27
6 2
1 31 mod 253 = 202 27 · 202 mod 253 = 141 ←
so that
N = an 10n + an−1 10n−1 + · · · + a1 10 + a0 .
It follows immediately that
Remark 3.2.18. This result is the reason the casting out nines technique
for checking arithmetic works. See the video Casting Out Nines - Numberphile
for additional details.
https://youtu.be/FlndIiQa20o
Exercises
1. Give the definition for these terms. Be sure to set up any notation that
is required.
(a) base b expansion
(b) binary
(c) decimal
(d) hexadecimal
2. Compute the base 5 expansion of 253.
3. Watch the following videos
• How to count to 1000 on two hands posted by 3Blue1Brown
https://youtu.be/1SMmc9gQmHQ
• How high can you count on your fingers? (Spoiler: much higher than
10) - James Tanton posted by TED-Ed
https://youtu.be/UixU1oRW64Q
and learn to count in binary on your hands.
4. Compute the integer representing the ASCII encoding of these messages.
(a) apple
(b) Radiohead
(c) discrete math
(d) secret
5. These integers represent messages encoded in ASCII as described in
§3.2.2. Decode these messages.
(a) 6582119
(b) 280991720293
(c) 311107740793
(d) 22107779118197813113556726561
(e) The following is an integer that is too long to fit in a line.
1971486178880874921204775823582727213754122745
127854714387549425398830
6. Compute 12321 mod 456. Follow the steps below if you get stuck.
(a) Compute the base 2 expansion of 321.
(b) Check that you got 321 = (101000001)2 .
(c) Compute the successive powers pi , remembering to reduce mod 456.
Did you notice anything that helps this computation go faster?
(d) Multiply the correct terms together to compute 12321 mod 456.
7. Compute 7447 mod 645.
8. Compute 3447 mod 645.
9. Convert the decimal expansion of each of these integers to a binary
expansion. i.e., Convert base 10 to base 2.
(a) 1
(b) 156
(c) 765
(d) 23
(e) 245
10. Convert the decimal expansion of each of these integers to a hexadecimal
expansion. i.e., Convert base 10 to base 16.
(a) 123
(b) 45326
(c) 12
(d) 157
(e) 149987
11. Convert the binary expansion of each of these integers to a decimal
expansion. i.e., Convert base 2 to base 10.
(a) (10011)2
(b) (111)2
(c) (101010)2
(d) (111000)2
(e) (1011011)2
12. Convert the hexadecimal expansion of each of these integers to a decimal
expansion. i.e., Convert base 16 to base 10.
(a) (A123B)16
(b) (81C)16
(c) (ABBA)16
(d) (DA3)16
(e) (253)16
13. Prove that a positive integer is divisible by 5 if and only if the last digit
is divisible by 5.
14. Prove that a positive integer is divisible by 3 if and only if the sum of its
decimal digits is divisible by 3.
15. Prove that a positive integer is divisible by 11 if and only if the alternating
sum of its decimal digits is divisible by 11.
3.3.1. Primes.
Remark 3.3.2. In later courses, we extend the notion of prime to all integers.
For simplicity, in this course we restrict the prime versus composite distinction
to integers greater than 1. Even in the extended notion, 1 is not prime.
Example 3.3.5.
100 = 2 · 2 · 5 · 5 = 22 52
253 = 11 · 13
7007 = 7 · 7 · 11 · 13 = 72 · 11 · 13
23,498,357,349 = 3 · 53 · 397 · 372,263
2 3 4 5 6 7 2 3 4 5 6 7
Primes:
8 9 10 11 12 13 14 8 9 10 11 12 13 14 2
15 16 17 18 19 20 21 15 16 17 18 19 20 21
22 23 24 25 26 27 28 22 23 24 25 26 27 28
29 30 31 32 33 34 35 29 30 31 32 33 34 35
36 37 38 39 40 41 42 36 37 38 39 40 41 42
43 44 45 46 47 48 49 43 44 45 46 47 48 49
2 3 4 5 6 7
Primes: 2 3 4 5 6 7
Primes:
8 9 10 11 12 13 14 2, 3 8 9 10 11 12 13 14 2, 3, 5
15 16 17 18 19 20 21 15 16 17 18 19 20 21
22 23 24 25 26 27 28 22 23 24 25 26 27 28
29 30 31 32 33 34 35 29 30 31 32 33 34 35
36 37 38 39 40 41 42 36 37 38 39 40 41 42
43 44 45 46 47 48 49 43 44 45 46 47 48 49
2 3 4 5 6 7
Primes: 2 3 4 5 6 7 Primes:
8 9 10 11 12 13 14 2, 3, 5, 7 8 9 10 11 12 13 14 2, 3, 5, 7,
11, 13, 17,
15 16 17 18 19 20 21 15 16 17 18 19 20 21 19, 23, 29,
22 23 24 25 26 27 28 22 23 24 25 26 27 28 31, 37, 41,
43, 47
29 30 31 32 33 34 35 29 30 31 32 33 34 35
36 37 38 39 40 41 42 36 37 38 39 40 41 42
43 44 45 46 47 48 49 43 44 45 46 47 48 49
)
bound (N ) # of primes (π(N )) percentage ( π(N
N %)
10 4 40.0000%
100 25 25.0000%
1000 168 16.8000%
10,000 1229 12.2900%
100,000 9592 9.5920%
1,000,000 78,498 7.8498%
10,000,000 664,579 6.6458%
100,000,000 5,761,455 5.7615%
1,000,000,000 50,847,534 5.0848%
bound, they no longer occur. This is not the case, as was known to the
Greeks over 2000 years ago. The first known proof is due to Euclid (c. 300
)
BC). See Theorem 3.3.8. It turns out, the proportion π(N
N of integers up to
N that are prime does decrease, but at an ever decreasing rate. If you are
interested, you can read more about the Prime Number Theorem and its
fascinating history.
http://mathworld.wolfram.com/PrimeNumberTheorem.html
Though we were able to prove there are infinitely many primes, there are
several open questions about primes.
While the twin prime conjecture is still open, there have been several
amazing recent advances in this direction. See the video Gaps between Primes
- Numberphile for some of this story.
https://www.youtube.com/watch?v=vkMXdShDdtY
Another famous open problem in number theory concerns decomposing
integers into sums of primes. In a letter to Leonhard Euler in 1742, Christian
Goldbach conjectured that every odd integer n, n > 5, is the sum of three
primes. Euler replied that this conjecture is equivalent to the conjecture that
every even integer n, n > 2, is the sum of two primes. For example, 4 = 2 + 2,
6 = 3 + 3, 8 = 3 + 5, 10 = 3 + 7, . . . . Although no proof of the Goldbach
conjecture has been found, the conjecture has been computationally checked
to hold up to 4 · 1018 [3].
Conjecture 3.3.11 (Goldbach conjecture). Every even integer n, n > 2, is
the sum of two primes.
Example 3.3.16. There are four positive integers less than 10 that are
relatively prime to 10: {1, 3, 7, 9}. Thus φ(10) = 4.
Example 3.3.17. There are six positive integers less than 7 that are relatively
prime to 7: {1, 2, 3, 4, 5, 6}. Thus φ(7) = 6.
Remark 3.3.18. For p prime, it is easy to show that φ(p) = p − 1. One can
also show that for p and q distinct primes, φ(pq) = (p − 1)(q − 1).
For integers we can factor, or for small integers where we can use trial
division, it is straightforward to compute greatest common divisors and least
common multiples.
Example 3.3.20. Let’s compute the greatest common divisor and least
common multiple of 24 and 30. We have that 24 = 23 · 3, and 30 = 2 · 3 · 5.
They have 2 · 3 in common, so greatest common divisor is
gcd(30, 24) = 2 · 3 = 6.
For the least common multiple, we need to include all the prime factors that
arise and keep the larger exponent, so the least common multiple is
lcm(30, 24) = 23 · 3 · 5 = 120.
Note that 24 · 30 = 720 = 6 · 120 so that
24 · 30 = gcd(30, 24) lcm(30, 24).
This turns out to be true in general. See Theorem 3.3.21.
Proof. Try this at home. Hint: Use the prime factorizations of a and b
guaranteed from the Fundamental Theorem of Arithmetic. Express the gcd
and lcm of a and b in terms of the factorizations. Compare the product of
these with the prime factorization of the product of a and b.
It may look like the Lemma does not help, as it just turns one gcd
computation into another. The real power here comes from two facts:
• gcd(a, b) = gcd(b, a), so we can arrange that b is less a; (Note: if a = b,
then gcd(a, b) = a so we would only really use this lemma when a = 6 b.)
• a mod b is strictly less than b.
That means that Lemma 3.3.22 allows us to compute gcd(a, b) by computing
gcd(A, B), where A and B are smaller than a and b. Nothing prevents us
from repeatedly using this result, so we can keep using the result until we
are computing gcd(d, 0), which is equal to d.
Example 3.3.23. Let’s compute gcd(252, 198) using Lemma 3.3.22.
Since 252 mod 198 = 54,
gcd(252, 198) = gcd(198, 54).
Since 198 mod 54 = 36, we have
gcd(198, 54) = gcd(54, 36).
q r s t
r1 s 1 t1
q r2 s 2 t2
q r s t
252 1 0
1 198 0 1
54 1 −1
This step may be easier to understand in a more general setting. The
general pattern is repeated throughout the computation, so we go
through it in more detail here. We have the table filled out as below.
We just computed the quotient q shown in bold below. We want to
compute the boxed quantities r3 , s3 and t3 .
q r s t
r1 s1 t1
q r2 s2 t2
r3 s3 t3
To do so, we compute
r3 = r1 − qr2
s3 = s1 − qs2
t3 = t1 − qt2 .
You can also think of it as
(r3 , s3 , t3 ) = (r1 , s1 , t1 ) − q(r2 , s2 , t2 ).
Enter these values in the boxed spots in the table as shown.
Step 4: Now the bottom two rows look like the table at the end of Step
1, so we proceed to compute the next quotient as in Step 2
198
198 div 54 = = 3,
54
and enter the value in the box in the q column as shown.
q r s t
252 1 0
1 198 0 1
3 54 1 −1
Step 5: Now the bottom two rows look like the table at end of Step 2, so
we proceed to compute the next values of r, s, and t as in Step 3
(198, 0, 1) − 3(54, 1, −1) = (36, −3, 4),
and enter the values in their respective boxes as shown.
q r s t
252 1 0
1 198 0 1
3 54 1 −1
36 −3 4
Step 6: Compute the next quotient
54
54 div 36 = = 1.
36
q r s t
252 1 0
1 198 0 1
3 54 1 −1
1 36 −3 4
Step 7: Compute the next row of r, s, and t
(54, 1, −1) − 1(36, −3, 4) = (18, 4, −5).
q r s t
252 1 0
1 198 0 1
3 54 1 −1
1 36 −3 4
18 4 −5
q r s t
252 1 0
1 198 0 1
3 54 1 −1
1 36 −3 4
2 18 4 −5
Step 9: Compute the next row of r, s, and t. We can get by with less
work in this step because in the r column, 36 − 2 · 18 = 0. That signals
us that the computation is done, and the row above is the one we want.
We can signify this in the table by entering 0 in the r column and
putting − in the s and t columns, since those values do not matter.
q r s t
252 1 0
1 198 0 1
3 54 1 −1
1 36 −3 4
2 18 4 −5
0 − −
Step 10: Draw the conclusion. We have the following table computed.
How do we interpret it?
q r s t
252 1 0
1 198 0 1
3 54 1 −1
1 36 −3 4
2 18 4 −5
0 − −
We look in the row above the row where we have a 0 in the r column.
The r value is gcd(252, 198), and the values of s and t in that row satisfy
gcd(252, 198) = 252s + 198t.
Thus we have shown that gcd(252, 198) = 18 , and that
18 = 252 · 4 + 198 · −5 .
q r s t
1184339 1 0
8 137632 0 1
1 83283 1 −8
1 54349 −1 9
1 28934 2 −17
1 25415 −3 26
7 3519 5 −43
4 782 −38 327
2 391 157 −1351
0 − −
Python Code Snippet 3.3.27. Here is Python code that will do Extended
Euclidean Algorithm to find a solution to the Bézout equation.
def XGCD(a,b):
’’’
Return [d,s,t], where d = (a,b) and s, t are integers such
that d = as + bt. Uses Extended Euclidean Algorithm.
’’’
# set up first 2 rows
r1, s1, t1, r2, s2, t2 = a, 1, 0, b, 0, 1
r = r2
while r!= 0: # while remainder is not 0
q, r = divmod(r1,r2) # compute quotient and remainder
s = s1 - q*s2
t = t1 - q*t2
# now shift everything
r1, s1, t1, r2, s2, t2 = r2, s2, t2, r, s, t
# want data just before remainder 0
return [r1, s1, t1]
Exercises
1. Give the definition for these terms. Be sure to set up any notation that
is required.
(a) prime
(b) composite
(c) twin primes
(d) greatest common divisor of integers
(e) relatively prime or coprime integers
(f) least common multiple
(g) Euler phi function
2. State precisely the Fundamental Theorem of Arithmetic. Be sure to set
up any notation that is required.
3. State precisely Bézout’s theorem. Be sure to set up any notation that is
required.
4. Compute φ(15).
5. Compute φ(24).
6. Which positive integers less than 12 are relatively prime to 12?
7. Which positive integers less than 25 are relatively prime to 25?
8. Determine whether these integers are prime.
(a) 21
(b) 100
(c) 101
(d) 253
(e) 91
9. Compute the greatest common divisor and least common multiple of the
following integers.
(a) 131 and 19
(b) 260 and 77
(c) 46 and 34
(d) 132 and 192
(e) 293 and 37
(f) 15 and 87
(g) 57 and 93
10. Compute the greatest common divisor and least common multiple of the
following integers.
(a) 36503 and 5017
(b) 8479 and 12017
(c) 15089 and 16999
(d) 11371 and 10541
(e) 14453 and 26671
11. Compute the greatest common divisor and least common multiple of the
following integers.
(a) 3599 and 5917
(b) 9701 and 8633
(c) 23707 and 5809
(d) 8413 and 12709
(e) 19303 and 5917
12. Show that gcd(75, 53) = 1. Find integers s and t such that
75s + 53t = 1.
Use these to find an integral solution to
75x + 53y = 13.
Check your solutions by plugging back in.
13. Show that gcd(75, 10) = 5. Use this to show that
75x + 10y = 13
has no integral solutions.
14. Explain why there are no integers s and t such that 25s + 30t = 1.
15. Find integers s and t such that 2018s + 253t = 1.
16. Use the Extended Euclidean Algorithm to find integers s and t such that
4321s + 12367t = 149.
Check your solution by plugging back in.
17. Use the Extended Euclidean Algorithm to find integers s and t such that
5293s + 8509t = 67.
Check your solution by plugging back in.
18. Use the Extended Euclidean Algorithm to find integers s and t such that
27263s + 44377t = 199.
Check your solution by plugging back in.
19. Use the Sieve of Eratosthenes to find primes up to 100. (You should find
25 primes less than 100.)
Using modular arithmetic, we can see a few things that will simplify
computations. Suppose gcd(a, m) = 1 so that a has an inverse modulo m.
An inverse of a will be an inverse for every integer in the congruence class
of a modulo m. We can use this to simplify our problem when |a| > m.
Furthermore, once an inverse is found, every integer in the congruence class
of the inverse is also an inverse. This is helpful when we want to find an
inverse with additional properties. For example, we may want to find an
inverse that is positive and “small” since we are doing computations by hand.
Example 3.4.5. Let’s find a positive integer that is an inverse of 253 modulo
8.
Since 253 mod 8 = 5, this reduces to finding an inverse of 5 modulo 8.
Since 3 · 5 ≡ 15 ≡ −1 (mod 8), we have that −3 is an inverse of 5 modulo
8. Every integer in the congruence class [−3] is also an inverse. We want a
positive inverse, so we can take −3 + 8 = 5 as an inverse. In fact, since the
inverse is unique modulo 8, we just proved that this is the smallest positive
integer that is an inverse of 253 modulo 8.
Then
1 ≡ as (mod m).
faith in you. He reports that there is an odd number left. When you tell him
that is not enough information, he reports that there is 1 left over if he lines
them up 5 at a time, 2 left over if he lines the up 7 at a time, and 3 left over
if he lines them up 9 at a time. How many action figures does he have?
Let x be the number of action figures my son has. Then
a1 = 1, m1 = 2 a2 = 1, m2 = 5 a3 = 2, m3 = 7 a4 = 3, m4 = 9.
(2) We compute
m = m1 m2 m3 m4 = 630
w1 = m2 m3 m4 = 315
w2 = m1 m3 m4 = 126
w3 = m1 m2 m4 = 90
w4 = m1 m2 m3 = 70.
(3) t1 : The inverse of 315 modulo 2 is the same as the inverse of 1 modulo
2, which is 1 by inspection. Specifically, we choose t1 = 1.
t2 : The inverse of 126 modulo 5 is the same as the inverse of 1 modulo
5, which is 1 by inspection. Specifically, we choose t2 = 1.
t3 : The inverse of 90 modulo 7 is the same as the inverse of −1 modulo
7, which is −1. Specifically, we choose t3 = −1 (Note: Some of
you will instead say the inverse of 90 modulo 7 is the same as the
inverse of 6 modulo 7, which is 6. That is fine as well. My way
just keeps the numbers smaller if you are willing to use negative
numbers.)
t4 : The inverse of 70 modulo 9 is the same as the inverse of 7 modulo
9, which is 4 by inspection. Specifically, t4 = 4.
(4) We compute
x ≡ a 1 t1 w 1 + a 2 t 2 w 2 + a 3 t 3 w 3 + a 4 t 4 w 4 (mod 630)
≡ (1 · 1 · 315) + (1 · 1 · 126) + (2 · (−1) · 90) + (3 · 4 · 70) (mod 630)
≡ 1101 (mod 630)
≡ 471 (mod 630).
In other words, x = 471 + 630k for some integer k. Since my son has less
than 500 action figures, he must have 471 action figures.
222 = 22 · 10 + 2
Exercises
1. Give the definition for these terms. Be sure to set up any notation that
is required.
(a) linear congruence
(b) inverse of an integer modulo an integer
2. State precisely the Chinese Remainder Theorem. Be sure to set up any
notation that is required.
3. State precisely the Fermat’s little theorem and Euler’s generalization. Be
sure to set up any notation that is required.
4. Show that 25 is an inverse of 13 modulo 36.
5. Find an inverse of 5 modulo 7 by inspection.
6. Use the Extended Euclidean Algorithm to find an inverse of 68 modulo
253.
18. Suppose you collected shells on the beach with your daughter. When you
arrange them in piles of 15, there are 13 left over. When you arrange
them in piles of 19, there are 6 leftover. Use the Chinese Remainder
Theorem to figure out how many shells you collected. Give the smallest
positive solution.
3.5. Cryptography
Definition 3.5.1. The Caesar cipher is the shift cipher, where we shift
forward by three.
A B C D E F G H I J K L M
D E F G H I J K L M N O P
N O P Q R S T U V W X Y Z
Q R S T U V W X Y Z A B C
(1) Replace each letter in the message by an element of Z26 equal to 1 less
than its position in the alphabet. e.g., A is replaced by 0, B is replaced
by 1, . . . , Z is replaced by 25. In this step, we are encoding the message
as a list of integers.
(2) Replace each number p by (p + 3) mod 26. Equivalently, apply the
function f : Z26 → Z26 defined by f (x) = x + 3 mod 26 to each number.
This step does the encrypting .
(3) Translate the numbers back to letters. This step does the decoding .
Example 3.5.2. Let’s encrypt CAT using the Caesar cipher.
First, we change CAT to numbers, we get 2 0 19. Apply f to get 5 3 22.
Translate back to letters to get FDW.
encode encrypt decode
C −−−−→ 2 −−−−→ 5 −−−−→ F
encode encrypt decode
A −−−−→ 0 −−−−→ 3 −−−−→ D
encode encrypt decode
T −−−−→ 19 −−−−→ 22 −−−−→ W
If we were going to encrypt longer messages, it would be faster to pre-
compute a lookup table as shown in Table 3.5.1.
3.5.2. RSA. First, we give a bit of history. Ron Rivest, Adi Shamir,
and Leonard Adleman (shown in Figure 3.5.2) first publicly described this
algorithm for public key encryption in 19781[4]. They posted one of the first
1Clifford Cocks described an equivalent system in 1973, but it was classified by the UK
intelligence agency GCHQ until 1997
Figure 3.5.2. Rivest, Shamir, and Adleman. Ron Rivest, Adi Shamir,
and Leonard Adleman (left to right), inventors of the RSA encryption
scheme.
public-key encryption messages using a 129 digit number which later became
known as RSA-129 [2].
RSA-129 =1143816257578888676692357799761466120102182967212
4236256256184293570693524573389783059712356395870
5058989075147599290026879543541
=3490529510847650949147849619903898133417764638493
387843990820577
×3276913299326670954996198819083446141317764296799
2942539798288533.
They offered a $100 prize and remarked that using technology and fac-
toring techniques available at that time, it would take 40 quadrillion years to
crack. Advances in factoring techniques and computers cracked the code in
April 1994 [1] to find that the secret message was:
The Magic Words are Squeamish Ossifrage 2
Suppose Alice wants to send Bob an encrypted message. Bob lets her
know his public key, a pair of integers (N, e).
Remark 3.5.5. RSA encryption works when the messages are integers
between 1 and N . As we saw in §3.2.2, ASCII encoding allows us to encode
a message string into an integer. After the message is encoded as an integer,
we can encrypt it with RSA encryption.
Before proving that RSA works in general, let’s look at a small example.
Example 3.5.7. Suppose Bob has public key (N, e) = (55, 3). For the
purposes of this example, pretend 55 is so large that Eve cannot factor it.
Then Alice can encrypt any number from 1 to 55. Suppose Alice wants to
send M = 18. She computes
C = M e mod N = 183 mod 55 = 2.
How does Bob decrypt C? He knows that φ(55) = 40, since he created
the key. The decryption exponent d is the inverse if e modulo φ(N ), so
it satisfies ed ≡ 1 (mod φ(N )). Bob can compute d ≡ −13 (mod 40) by
Extended Euclidean Algorithm
q r s t
40 1 0
13 3 0 1
3 1 1 −13
0 −3 40
or by observing that 3 · 13 = 39 ≡ −1 (mod 40). Thus d = −13 mod 40 = 27.
To decrypt C = 2, Bob computes
M = C d mod N = 227 mod 55 = 18.
What are some of the problems with this example? i.e., What kind of
attacks should Eve try to decrypt the message?
First, the value N = 55 is too easy to factor. Once Eve knows 55 = 5 · 11,
CRT tells her that
φ(55) = φ(5)φ(11) = (5 − 1)(11 − 1) = 40.
Then she can compute d using Euclidean algorithm just as Bob did to decrypt
any intercepted message.
Next, the message space is too small. Notice that if Eve could solve x3 ≡ 2
(mod 55), she can find Alice’s message. The message space {1, 2, . . . , 55} is
small enough that Eve could just compute x3 mod 55 for several values of x
and quickly find an answer.
φ(N ). As long as Bob keeps the factors p and q secret then computing φ(N )
is hard.
In the days of early commercial cryptography, many companies offered
“challenges” to measure the state of progress in practical cryptanalysis. RSA
used a Factoring Challenge. More information can be found at
https://en.wikipedia.org/wiki/RSA_Factoring_Challenge.
They posted a set of eight challenge numbers, ranging in size from 576 bits
(174 decimal digits) to 2048 bits (617 decimal digits) that made up the
challenge3. Each number is the product of two large primes, similar to the
modulus of an RSA key pair. The first person to submit a correct factorization
for any of the challenge numbers was eligible for a cash prize. To date, only
four of the eight challenge numbers have been factored.
3The RSA numbers were generated on a computer with no network connection of any kind.
The computer’s hard drive was subsequently destroyed so that no record would exist, anywhere, of
the solution to the factoring challenge. Not even the people at RSA knew the factorizations.
A reasonable RSA key to use is 1024 bits. Their RSA-1024 has 309
decimal digits.
N =135066410865995223349603216278805969938881475605667027524485
143851526510604859533833940287150571909441798207282164471551
373680419703964191743046496589274256239341020864383202110372
958725762358509643110564073501508187510676594629205563685529
475213500852879416377328533906109750544334999811150056977236
890927563
Exercises
1. Give the definition for these terms. Be sure to set up any notation that
is required.
(a) Caesar cipher
(b) RSA public encryption key
(c) RSA encryption exponent
(d) RSA decryption exponent
2. Encrypt the message UNCG SPARTANS by translating the letters into
numbers, applying the given encryption function, then translating the
numbers back into letters.
(a) f (p) = p + 3 mod 26
(b) f (p) = p + 22 mod 26
(c) f (p) = −3p mod 26
(d) f (p) = 5p + 7 mod 26
3. Encrypt the message MIDNIGHT by translating the letters into numbers,
applying the given encryption function, then translating the numbers
back into letters.
(a) f (p) = p + 17 mod 26
(b) f (p) = p − 4 mod 26
(c) f (p) = −7p mod 26
(d) f (p) = 3p + 12 mod 26
4. Decrypt these messages that were encrypted using the Caesar cipher.
(a) KHOS
(b) VSDUWDQV
(c) VHFUHW
(d) DEVTXDWXODWH
(e) VXUUHSWLWLRXV
(f) DOLFH ORYHV ERE
5. Decrypt these messages that were encrypted using the encryption function
f (p) = 5p − 3 mod 26.
(a) OGERR
(b) LKYLJLCAR
(c) XKPKNFPTJ
(d) CPC APYRJ RYR
6. Decrypt these messages that were encrypted using the encryption function
f (p) = p + 10 mod 26.
(a) LVEO
(b) LKXKXK
(c) CYVSNKBSDI
(d) OFO VYFOC KVSMO
7. Suppose the ciphertext HVS ZONM RCU XIADG CJSF HVS EIWQY
PFCKB TCL was produced by encrypting a plaintext message using a
shift cipher. What is the original plaintext message?
8. My RSA public key is (N, e) = (85, 3). Encrypt the number M = 23.
9. Encrypt the message M = 253 using the RSA encryption scheme with
public key (N, e) = (391, 17).
10. Encrypt the current year using the RSA encryption scheme with public
key (N, e) = (343751, 23).
11. Show that the RSA public key (N, e) = (527, 13) is too small by computing
the decryption exponent.
12. Alice encodes her birthday as an 8-digit number yyyymmdd. Suppose she
encrypts it using the RSA encryption scheme with public key
(N, e) = (25736197, 29),
resulting in the ciphertext C = 8141408. What is her birthday?
Chapter 4
Induction
129
130 4. Induction
132 4. Induction
We proceed by induction on n.
Basis step: P (1): It is clear that in any set with 1 person, they are the
same age.
Inductive step: Fix k ≥ 1. Assume P (k) is true so that any set of k
people are the same age. Let S be a set of k + 1 people. We have to show that
everyone in S is the same age. Pick one person X in S. Let T = S − {X}.
Then |T | = k, so by the inductive hypothesis everyone in T is the same age,
call it a. Pick another person X ′ in S, X 6= X ′ . Let T ′ = S − {X ′ }. Then
|T ′ | = k, so by the inductive hypothesis everyone in T ′ is the same age, call
it a′ . Notice that we have a = a′ since T and T ′ have some members in
common. Furthermore, T ∪ T ′ = S. Thus everyone in S is the same age.
Therefore by mathematical induction, any set of n people are all the same
age.
134 4. Induction
Exercises
136 4. Induction
138 4. Induction
Proof. For simplicity, just think about the most basic form, as described
before Theorem 4.1.1. We proceed by contradiction. Suppose not. Then
the set S of positive integers for which P (n) is false is nonempty. By the
well-ordering property, S must have a least element. Let m be the least
element in S. Then m is not 1, since P (1) is true by the basis step. Because
m is positive and not 1, we must have that m is at least 2. Then m − 1
is a positive integer less than m, and P (m − 1) is true. By the inductive
step, we know that P (m − 1) implies P (m), so P (m) must be true as well.
Contradiction! Thus induction is valid.
The proof the more general case as well as strong-induction is similar.
Exercises
140 4. Induction
Chapter 5
Counting
Goals. To introduce basic counting rules and to show how they are used
to solve a variety of counting problems.
Recall that the cardinality of a finite set is defined earlier in §2.1.3. This
definition of counting is exactly what we show children when we teach them
to count to answer “how many” type questions, though not in this language.
141
142 5. Counting
♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥
Most likely, you pointed to each heart, one-by-one, and recited: “one, two,
three, four, . . . , thirteen, fourteen.” In doing so, you created a bijection
between the set of hearts and {1, 2, . . . , 14}. From this, you cam deduce that
there are 14 hearts.
Notice that we do not need to have constructed the same bijection in
order to get the right number for the cardinality. The key point is that we
create a function that is both injective and surjective. Do you see why?
We can generalize the definition for counting and cardinality to include
some infinite sets. An infinite set is any set that is does not have a finite
cardinality. It turns out, there are different sizes of infinity.
Definition 5.1.2. Two sets A and B have the same cardinality , denoted
|A| = |B| if there is a bijection from A to B.
Definition 5.1.3. A countable set is either finite or has the same cardi-
nality as the set of positive integers. An uncountable set is any set that is
not countable.
Notice that this gives at least two different “sizes” for infinite sets. Some
sets are infinite, but we can count them by constructing a bijection to the
positive integers. Other infinite sets are so large that we cannot even construct
such a bijection to the positive integers.
n−1
If n is odd, then 2 is a positive integer, and so
n−1 n−1
f( ) = 2( ) + 1 = n.
2 2
Thus f is surjective.
To see f is injective, fix generic integers a and â such that f (a) = f (â). If
f (a) is even, then f (â) is also even, and so both a and â are negative. Then
f (a) = −2a, and f (â) = −2â. Since f (a) = f (â), we have −2a = −2â so
a = â. Now suppose f (a) is odd. Then f (â) is also odd, and so both a and â
are nonnegative. Then f (a) = 2a + 1, and f (â) = 2â + 1. Since f (a) = f (â),
we have 2a + 1 = 2â + 1 so a = â. Thus f is injective.
Since f is injective and surjective, f is bijective and so Z is countable.
In Example 5.1.4 that shows the set of integers is countable, the sequence
that is inverse the bijection given is
0, −1, 1, −2, 2, −3, 3, . . . .
Sometimes it is easier to think of a sequence instead of a formula for the
function.
Since the composition of bijective functions is bijective, to show an infinite
set A is countable it is enough to find a bijection from A to Z. If we have
such a bijection, we compose it with the bijection from Z to {1, 2, . . .} given
in Example 5.1.4 to get the desired bijection from A to {1, 2, . . .}. Using this
idea, it is clear that the set of even integers 2Z is countable, since f : 2Z → Z
given by f (x) = x2 is a bijection from 2Z to Z. A similar argument shows the
set of odd integers is countable.
144 5. Counting
1 1 1 1 1 1 ···
1 2 3 4 5 6
2 2 2 2 2 2 ···
1 2 3 4 5 6
3 3 3 3 3 3 ···
1 2 3 4 5 6
4 4 4 4 4 4 ···
1 2 3 4 5 6
5 5 5 5 5 5 ···
1 2 3 4 5 6
.. .. .. .. .. ..
. . . . . .
What about the set of rational numbers? Surely there are more rational
numbers than integers? It turns out, the set of rational numbers is also
countable.
One may start to think that every infinite set is countable. In fact, there
are sets that are larger. In 1879, Georg Cantor produced a proof using
a technique now known as the Cantor diagonalization argument, that
proves the set of real numbers is not countable.
There is a subtle point that not every real number has a unique decimal
representation. For example, 0.5000 . . . is the same real number as
0.4999 . . . . We avoid this issue by choosing d to have digits only involving 3
and 4 to be sure we are producing a number that has only one representation,
so that we can be sure it is not in the sequence.
146 5. Counting
each of the remaining 5 bits. The Product Rule says there are 25 = 32 such
bit strings.
Example 5.1.13. Suppose there are 22 people in the class. How likely is it
that two share a birthday?
First, let’s count the number of ways the birthdays could be arranged,
assuming no one was born on February 29. We order the 22 people, and
break this own into 22 tasks. The ith task is choosing a birthday for the ith
person. There are 365 ways to complete each task, regardless of how previous
tasks were done. By the Product Rule, the number of birthday arrangements
is
36522 ≈ 2.346621351 × 1056 .
Next, let’s compute the number of ways the birthdays could be arranged,
assuming no one was born on February 29 and no two people share a birthday.
Again, we break this into 22 tasks, where the ith task is choosing the birthday
for the ith person. The difference is in the number of ways to complete each
task. There are 365 was to complete the first task. There are only 364 ways
to complete the second task, since we cannot choose the same birthday as the
first person. Notice that the number of ways does not depend on what day
was chosen for the first person. Similarly, there are 353 ways to complete the
second task, and so on. In general, there are 365 − (i − 1) ways to complete
the ith task. By the Product Rule, the number of birthday arrangements so
that no two share a birthday is
56
|365 · 364 ·{z363 . . . 344} ≈ 1.230344586 × 10 .
22 terms
148 5. Counting
150 5. Counting
Example 5.1.23. Seat four people at a circular table. Two seating arrange-
ments are the same if each person has the same left and right neighbor. In
other words, two seating arrangements are the same if one can be rotated
into the other.
By the Product Rule there are 4 · 3 · 2 · 1 = 24 ways to arrange the
four people around the table. For each way, exactly four give the same
seating arrangement. By the Division Rule, there are 24
4 = 6 different seating
arrangements.
Exercises
1. State precisely the following rules. Be sure to set up any notation that is
required.
(a) Product Rule
(b) Sum Rule
(c) Principle of Inclusion-Exclusion
(d) Division Rule
2. How many bit strings of length eight contain exactly three 0s? Hint:
Think about choosing locations for the 0s.
3. How many answer keys are possible for a twenty question multiple choice
test, where each question has exactly six choices?
4. Suppose there are 350 undergraduates in an auditorium. Of these, 220
are computer science majors, 147 are math majors, and 51 are double
majoring in computer science and math. How many are neither computer
science nor math majors?
5. Let A = {a, b, c, d}, and let N = {1, 2, 3, 4, 5, 6, 7}.
(a) How many functions are there from A to N ? How many functions
are there from N to A?
(b) How many injective functions are there from A to N ? How many
injective functions are there from N to A?
(c) How many surjective functions are there from A to N ? It is a trickier
problem to determine the number of surjective functions from N to
A.
6. Suppose a multiple choice exam consists of 20 questions, each with choices
A, B, C, D.
(a) How many possible answer keys are there?
(b) In how many ways can a student answer the questions on the test,
if the student answers every question?
(c) In how many ways can a student answer the questions on the test,
if the student student can leave answers blank?
The basic idea is really simple. For example, if we have three boxes and
want to put away four or more toys, there must be at least one box containing
two or more toys. The technique can be used cleverly to prove statements
that are not so trivial.
152 5. Counting
Example 5.2.2. In any group of 27 English words, at least two must start
with the same letter, since there are only 26 letters in the English alphabet.
Example 5.2.3. Assume no human has more than 200,000 hairs on his/her
head. Since there are more than 200,000 people in Greensboro, there are at
least two people in Greensboro with exactly the same number of hairs on
their head.
Theorem 5.2.4. If A and B are nonempty sets with |B| = k and |A| ≥ k+1,
then there are no injective functions from A to B.
n multiple
2 10
3 111
4 100
5 10
6 1110
7 1001
.. ..
. .
100
Example 5.2.7. In a group of 100 people, there are at least 12 = 9 born
in the same month.
Exercises
154 5. Counting
4. Suppose the final exam is graded on a scale from 0 to 100 points. How
many students must be in the class to guarantee that at least two students
receive the same score on the final exam?
5. How many numbers must be selected from the set {1, 3, 5, 7, 9, 11, 13, 15}
to guarantee at least one pair of these numbers add up to 16?
6. What is the minimum number of people required to be sure that at least
four will have birthdays in the same month?
7. A standard deck of cards consists of 52 cards. Each card is one of thirteen
ranks (A, 2, 3, . . . , J, Q, K) and one of four suits (♣, ♠, ♥, ♦).
(a) How many cards must be selected to guarantee that at least three
of the same suit are chosen?
(b) How many cards must be selected to guarantee that at least three
of the same rank are selected?
8. A standard deck of cards consists of 52 cards. Each card is one of thirteen
ranks (A, 2, 3, . . . , J, Q, K) and one of four suits (♣, ♠, ♥, ♦).
(a) How many cards must be selected to guarantee that at least two
hearts (♥) are selected?
(b) How many cards must be selected to guarantee that at least three
spades (♠) are selected?
(c) How many cards must be selected to guarantee that at least two
hearts (♥) and three spades (♠) are selected?
9. Alice selects clips randomly from a bowl that contains ten large paper
clips and thirty small paper clips.
(a) How many must she select to be sure of having at least three of the
same size?
(b) How many must she select to be sure of having at least five of the
same size?
10. Show that there are at least seventeen people in Greensboro (population
285,000) with the same three initials, assuming everyone has a first,
middle, and last initial.
11. There are 38 different time periods during which classes can be scheduled.
If there are 650 different classes, how many different rooms will be needed?
12. Show that among any group of five integers, there are at least two with
the same remainder when divided by 4.
13. There are 50 baskets of apples. Each basket contains at least one apple and
no more than 24 apples. Show that there are at least 3 baskets containing
the same number of apples. If you use the Pigeonhole Principle or its
extension, be sure to tell me what are the pigeons and what are the boxes.
Hint: The apples are not pigeons. The baskets are not boxes.
5.3.1. Permutations.
Definition 5.3.1. A permutation of a set of distinct objects is an ordered
arrangement of these objects.
156 5. Counting
Example 5.3.8. Suppose there are eight runners in a race. How many
different ways can we Gold/Silver/Bronze finishers, assuming no ties?
We want to count the number of 3-permutations of the runners. Since
there are eight runners, we have
✭
✭
8! 8! 5 ·✭
8 · 7 · 6 ·✭ 4✭· 3✭· ✭
2·1
P (8, 3) = = = ✭
✭ = 336.
(8 − 3)! 5! ✭5 ·✭4·3·2·1
✭ ✭ ✭
S ′ = {abc, d, e, f, . . . , x, y, z}.
Example 5.3.12. How many ways are there to arrange seven people in from
a group of ten (including me) in a row if I need to be one of the seven?
We break this into tasks. First select the position for me. There are 7
choices. The remaining spots are ordered. We need a 6-permutation of the
set of 9 remaining people. There are
9!
P (9, 6) = = 9 · 8 · 7 · 6 · 7 · 6 = 60,480
(9 − 6)!
such permutations. By the Product Rule, there are 7 · 60480 = 423,360
arrangements.
5.3.2. Combinations.
Proof. We can carry out the last of listing the r-combinations by listing the
n!
r-permutations. By Theorem 5.3.6, there are (n−r)! ways to do this. For each
of these ways, exactly r! of the ways correspond to the same way. The result
then follows by the Division Rule.
Example 5.3.17. How many poker hands (5 cards) are in a standard deck
of 52 cards?
We want to count 5-combinations of cards. Since there are 52 cards, the
number of 5-combinations is
52 52 52 · 51 · 50 · 49 · 48
C(52, 5) = = = = 2,598,960.
5!(52 − 5)! 5!47! 5·4·3·2·1
158 5. Counting
Example 5.3.19. Suppose there are 9 males and 11 females in MAT 253.
How many different final exam committees can be made if a committee
consists of 3 males and 4 females?
The procedure of choosing a committee can be broken down into two
tasks—selecting the male members and selecting the female members. The
number of ways to select male members is
9! 9! 9·8·7
C(9, 3) = − = = 84.
3!(9 − 6)! 3!6! 3·2·1
The number of ways to select female members is
11! 11! 11 · 10 · 9 · 8
C(11, 4) = = = = 330.
4!(11 − 4)! 4!7! 4·3·2·1
Then by the Product Rule, the number of different committees is
84 · 330 = 27,720.
Example 5.3.20. How many bit strings of length ten have exactly three 0s?
We can describe a bit string with exactly three 0s by specifying the
location of the three 0s. There are ten possible places for them to go, and
we cannot distinguish the three 0s, so the order does not matter. Thus the
number of bit strings with exactly three 0s is
10! 10! 10 · 9 · 8
C(10, 3) = = = = 120.
3!(10 − 3)! 3!7! 3·2·1
Example 5.3.21. Thirteen people on a soccer team show up for a game. Of
the thirteen that show up, three are women. How many ways are there to
choose ten players to take the field if at least one of these players must be a
woman?
Which of the following computations is correct?
(1) There are C(3, 1) = 3 ways to choose a woman. Then there are 12
remaining players, and we need to choose 9 of them. The number of
ways to choose 9 from 12 is
12! 12! 12 · 11 · 10
C(12, 9) = = = = 220.
9!(12 − 9)! 9!3! 3·2·1
Exercises
1. Give the definition for these terms. Be sure to set up any notation that
is required.
(a) permutation
(b) r-permutation
(c) combination
(d) r-combination
160 5. Counting
2. A local pizza shop offers their pies in small, medium, large, or extra
large. For toppings, they offer: pepperoni, sausage, bacon, olives, onions,
peppers, and anchovies. How many different pizzas can they make that
have exactly three (different) toppings?
3. Compute the following.
(a) P (7, 3)
(b) C(7, 3)
(c) C(8, 0)
(d) P (8, 5)
(e) C(8, 3)
4. Fifteen people on a softball team show up for a game.
(a) How many ways are there to select 9 to take the field?
(b) How many ways are there to assign the 9 positions?
5. How many permutations of the letters ABCDEFGH contain the string
ABC?
6. In how many different orders can ten runners finish a race if no ties are
allowed?
7. List all the permutations of {1, 2, 3}
8. List all the 3-combinations of {a, e, i, o, u}.
9. List all the 3-permutations of {1, 2, 3, 4, 5, 6}.
10. In how many ways can a set of four letters be selected from the English
alphabet?
11. How many ways are there for 10 women and 6 men to stand in a line if
so that no two men stand next to each other? (Hint: First position the
women and then consider the possible positions for the men.)
12. Harry, Hermione, Ron, Fred, George, Ginny, Luna, Neville, Seamus, and
Hagrid go to some pictures taken.
(a) How many ways are there to arrange four people from that group in
a row for the picture?
(b) Suppose Harry is willing to pay for any picture that he is in. How
many ways are there to arrange four people from that group in a
row for the picture, if Harry must be one of the four?
Chapter 6
Relations
161
162 6. Relations
164 6. Relations
(1) Since a ≤ a for every integer a, we have aRa for every integer a. Thus,
R is reflexive.
(2) Since 1 ≤ 2, but 2 6≤ 1, we have 1R2 but not 2R1. Thus, R is not
symmetric.
(3) Whenever a ≤ b and b ≤ a, we must have a = b. That means whenever
aRb and bRa, we must have a = b. Thus R is antisymmetric.
(4) Whenever a ≤ b and b ≤ c, we must have a ≤ c. Then, whenever aRb
and bRc, we must have aRc. Thus R is transitive.
Example 6.1.18. Let R be the relation on {1, 2, 3, 4} that is given by
R = {(2, 2), (2, 3), (2, 4), (3, 2), (3, 3), (3, 4)}.
Then R is not reflexive since (1, 1) is not in R. It is not symmetric since (2, 4)
is in R but (4, 2) is not in R. It is not antisymmetric since (2, 3) is in R and
(3, 2) is in R, but 2 6= 3. It is transitive since if (a, b) is in R and (b, c) is in
R, then (a, c) is in R.
Example 6.1.19. Let R be the relation on {1, 2, 3, 4} that is given by
R = {(1, 3), (1, 4), (2, 3), (2, 4), (3, 1), (3, 4)}.
Then R is not reflexive since (1, 1) is not in R. It is not symmetric since (1, 4)
is in R, but (4, 1) is not in R. It is not antisymmetric since (1, 3) is in R and
(3, 1) is in R, but 1 6= 3. It is not transitive since (1, 3) is in R and (3, 1) is in
R, but (1, 1) is not in R.
Example 6.1.20. Let R be the relation on {1, 2, 3, 4} that is given by
R = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 3), (4, 4)}.
Then R is reflexive since (1, 1), (2, 2), (3, 3), and (4, 4) are all in R. It is
symmetric because whenever (a, b) is in R, we have (b, a) is in R. It is
transitive since if (a, b) is in R and (b, c) is in R, then (a, c) is in R. It is not
antisymmetric since (1, 2) is in R and (2, 1) is in R, but 1 6= 2.
6.1.3. Combining binary relations. Since relations are sets, we can take
unions, intersections, differences, and complements of relations.
Example 6.1.21. Let S be the set of students at UNCG, and let C be the
set of courses at UNCG. Let T and N be the relations from S to C,
T = {(s, c) ∈ S × C | s has taken c};
N = {(s, c) ∈ S × C | s needs c to graduate}.
Then
T ∩ N = {(s, c) ∈ S × C | s has taken c and needs c to graduate};
T − N = {(s, c) ∈ S × C | s has taken c but does not need c to graduate}.
166 6. Relations
1 1
2 2
3 3
4 4
5 5
6 6
Example 6.1.24. Let A = {1, 2, 3}, B = {1, 2, 3, 4}, and C = {0, 1, 2}. Let
R be the relation from A to B
R = {(1, 1), (1, 4), (2, 3), (3, 1), (3, 4)},
R S
A B C
S◦R
1
1 0
2
2 1
3
3 2
4
Then
S ◦ R = {(1, 0), (2, 1), (2, 2), (1, 1), (3, 0), (3, 1)}.
Exercises
1. Give the definition for these terms. Be sure to set up any notation that
is required.
(a) binary relation from one set to another
(b) relation on a set
(c) reflexive relation
(d) symmetric relation
(e) antisymmetric relation
(f) transitive relation
(g) composition of relations
2. Consider the relation R = {(a, b) | a divides b} on the set {1, 2, 3, 4}.
(a) List all of the ordered pairs in R.
168 6. Relations
(b) R ∩ S
(c) R − S
(d) S − R
8. Let R and S be relations on {1, 2, 3, 4} defined by
R = {(2, 2), (2, 3), (3, 4), (4, 4)}
S = {(1, 2), (2, 1), (2, 4), (3, 1), (3, 4)}.
Compute the following relations.
(a) R ◦ R
(b) R ◦ S
(c) R ◦ R
(d) S ◦ S
9. Let P be the relation on the set of people consisting of pairs (a, b), where
a is a parent of b. Let S be the relation consisting of pairs (a, b), where a
and b are siblings (brothers or sisters). Describe the composition relations
P ◦ S and S ◦ P .
10. Let B be the relation on the set of states in the US consisting of pairs
(a, b) where a shares a land border with b.
(a) Give three examples of elements in B.
(b) Give three examples of elements not in B.
(c) Is B symmetric?
(d) Is B transitive?
11. Give an example of a relation on a set that is reflexive, but not symmetric.
12. Give an example of a relation on a set that is symmetric, but not reflexive.
13. Give an example of a relation on a set that is reflexive and symmetric,
but not transitive.
Definition 6.2.2. Two elements a and b are equivalent if they are related
by an equivalence relation.
170 6. Relations
This is a notion that makes precise when two thing are “the same” up to
differences that we are willing to ignore. We have seen this before.
For example, we regularly think of a $1 note as “the same” as four quarters,
though they are different. According to the United States Mint, a quarter
is 5.670 grams. That means $1000 in quarters weighs about 50 pounds. On
the other hand, a $1 note weighs about 1 gram, so $1000 in $1 notes weighs
about 2.2 pounds. Would you rather run a race carrying $1000 in $1 notes
or quarters?
For a more mathematical example, we think of 26 as equal to 13 . In what
sense are they the same? In this case, two objects are equal as rational
numbers, but differ in representation.
Remark 6.2.3. We often use ∼ instead for equivalence relations, so if a and
b are equivalent, we might write a ∼ b.
172 6. Relations
a = b + km = (c + ℓm) + km = c + (ℓ + k)m.
Remark 6.2.9. Since equivalence relations are symmetric, this is the same
as
[a] = {b ∈ A | bRa}.
A1
A4
A2 A5
A3
Proof. We prove 1 → 2 → 3 → 1.
174 6. Relations
Exercises
1. Give the definition for these terms. Be sure to set up any notation that
is required.
(a) equivalence relation
(b) equivalent elements
(c) equivalence class
(d) partition of a set
2. Define an equivalence relation on the set of restaurants in Greensboro.
3. Define an equivalence relation on the set of classes offered at UNCG.
2A person who is related to another through a common ancestor, and not by marriage or
adoption.
Appendix A
Programming
assignments
https://docs.python.org/3/tutorial/
177
P2: SETS
P3: FUNCTIONS
2 P3: FUNCTIONS
(3) There are 9,592 actual primes less than or equal to 100,000. How many composite
integers faked their way past your probablyprime test? Hint: len(P) will return
the number of elements in P.
Rubric
10–9 pts: Script runs without errors. All required components are correctly addressed.
The difference between 9 and 10 comes from coding style (comments, structure) and
writing style (grammar and spelling in responses).
8–6 pts: Script runs without errors but some required component is missing or incor-
rect. The score in this range depends on the what is missed.
5 pts: Script does not run because of errors.
0 pts: No submission.
RSA EXERCISE
1. Some history
Rivest, Shamir, and Adleman first publicly described this algorithm for public key encryp-
tion in 19781. They posted one of the first public-key encryption messages using a 129 digit
number which later became known as RSA-129.
RSA-129 = 114381625757888867669235779976146612010218296721242362562
561842935706935245733897830597123563958705058989075147599290026879543541
= 3490529510847650949147849619903898133417764638493387843990820577
× 32769132993266709549961988190834461413177642967992942539798288533.
They offered a $100 prize and remarked that using technology and factoring techniques
available at that time, it would take 40 quadrillion years to crack. Advances in factoring
techniques and computers cracked the code in April 1994 to find that the secret message was:
The Magic Words are Squeamish Ossifrage
According to Wikipedia,
Ossifrage is an older name for the lammergeier, a scavenging vulture that is
famous for dropping animal bones and live tortoises onto rocks to crack them
open. It might perhaps be considered among the least squeamish of creatures.
2. The set-up
Suppose Alice wants to send Bob an encrypted message. Bob lets her know his public key.
Definition 2.1. The RSA public encryption key consists of a pair of integers (N, e), where
N is the product of two distinct primes.
The set of integers {1, · · · , N } is the set of possible messages, but we will see that you do
not want the message to be 1 or N . To encrypt a message M , Alice computes
C = M e mod N.
Notice that with fast exponentiation, this is fast.
If a Eve captures C while it is being transmitted, she will have a hard time computing the
original message M . See the lecture notes for more information.
How is it any easier for Bob? The trick is that Bob has a bit of extra information. When
constructing the key, Bob chooses N to be a product of two distinct primes p and q. Then
φ(N ) = φ(pq) = (p − 1)(q − 1). This is the Euler-phi function at N , the number of positive
integers less than or equal to N that are relatively prime to N . The exponent e is chosen so
that gcd(e, φ(N )) = 1. Then using the Euclidean algorithm, Bob can compute an inverse
to e modulo φ(N ), an integer d such that ed ≡ 1 (mod φ(N )). Then there is an integer k
1Clifford
Cocks described an equivalent system in 1973, but it was classified by the UK intelligence agency
GCHQ until 1997
1
2 RSA EXERCISE
so that ed = 1 + kφ(N ). Now Euler’s generalization to Fermat’s little theorem says that if
gcd(C, N ) = 1,
C d ≡ (M e )d (mod N )
≡ M 1+kφ(N ) (mod N )
≡ M · (M φ(N ) )k (mod N )
≡M (mod N ).
In other words, to decrypt the message, Bob does not need to take an eth root of C modulo
N . Instead, he can raise C to the dth power and achieve the same result, where d is an
inverse of e modulo φ(N ). Thank you, Euler! Again, with fast exponentiation, this is fast.
Note: Choose d to be a positive integer since our fast exponentiation algorithm requires the
exponent to be positive.
3. ASCII encoding
ASCII is a standard way to represent characters as numbers. For example, a space is
represented by 32, a comma is 44, and a period is 46. The capital letters are also 2 digit
integers, starting with 65 for A and going to 90 for Z. The Python functions chr and ord to
convert the ASCII to characters. e.g., chr(66) returns the string A. If you want to go the
other way, ord(’A’) returns the integer 65. This is known as encoding.
In order to encode messages longer than one character, we will view each number as a digit
in a base 256 expansion of an integer M . For example, suppose I want to send the message
Help!. We have
ord(H) = 72, ord(e) = 101, ord(l) = 108, ord(p) = 112, ord(!) = 33,
RSA EXERCISE 3
4. Exercises
(1) Encode your birthday using ASCII as described above to get an integer M .
(2) Use my public key
N = 913336127711006102170609898942942716906241096981411826716803
e = 65537
to encrypt your message to get an integer C. Enter this integer on the assignment in
Canvas.
(3) Go to http://magma.maths.usyd.edu.au/calc/ and enter
Factorization(913336127711006102170609898942942716906241096981411826716803);
and click ‘Submit’ to find a factorization of N = pq. Note: The fact that the computer
can factor my public key is an indication that the key is too small.
(4) Use your knowledge of the factorization to compute φ(N ) = (p − 1)(q − 1).
(5) Use Extended Euclidean Algorithm to find the decryption exponent d, which is a
positive integer that is an inverse of e modulo φ(N ).
(6) Use the decryption exponent to decrypt my secret message.
C = 902366426828977962222652187660968416915888050115990141594121
(7) Use the decoding procedure described above to convert the integer to a string. Post
this string to the Discussion Board in Python for RSA.
Bibliography
[1] D. Atkins, M. Graff, A. K. Lenstra, and P. C. Leyland, The magic words are
squeamish ossifrage (extended abstract), Advances in cryptology—ASIACRYPT
’94 (Wollongong, 1994), Lecture Notes in Comput. Sci., vol. 917, Springer, Berlin,
1995, pp. 263–277.
[2] M. Gardner, Mathematical games: A new kind of cipher that would take millions
of years to break, Scientific American (August 1977), 120–124.
[3] T. Oliveira e Silva, S. Herzog, and S. Pardi, Empirical verification of the even
Goldbach conjecture and computation of prime gaps up to 4 · 1018 , Math. Comp.
83 (2014), no. 288, 2033–2060.
[4] R. L. Rivest, A. Shamir, and L. Adleman, A method for obtaining digital
signatures and public-key cryptosystems, Comm. ACM 21 (1978), no. 2, 120–126.
[5] K. H. Rosen, Discrete mathematics and its applications, McGraw-Hill Higher
Education, 2012.
195
Index
197
198 Index
difference, 48 hexadecimal, 90
direct proof, 30 hypothesis, 6
discrete log problem, 123
disjoint, 50 Idempotent laws, 19, 53
disjunction, 5 Identity laws, 19, 53
Distributive laws, 19, 53 if and only if, 7
dividend, 83 if then, 6
divides, 81 iff, 7
Division algorithm, 82 image, 56, 57
Division Rule, 149 inductive hypothesis, 130
divisor, 83 inductive step, 130
domain, 23, 56 Infinitude of primes, 102
Domination laws, 19, 53 initial term, 70, 71
Double negation law, 19 injection, 61
injective, 61
elements, 41 injectivity, 60
empty set, 42 integers, 41
encoding, 121 integers mod m, 85
encrypting, 121 intersection, 48
encryption exponent, 122 inverse, 9, 66, 113
equal, 42 irrational, 34
equivalence class, 172
equivalence relation, 169 least common multiple, 104
equivalent, 169 linear congruence, 113
Euclidean algorithm, 105 logically equivalent, 18
Euler phi function, 104 mapping, 56
Euler totient function, 104 mathematical induction, 129, 130
Euler’s generalization, 118 members, 41
even, 31 membership table, 52
exclusive disjunction, 6 modular arithmetic, 83
exclusive or, 6 multiple, 81
existential quantification, 24
existential quantifier, 24 negation, 4
Extended Pigeonhole Principle, 153 Negation law, 19
Extended Euclidean Algorithm, 106 nonconstructive proofs, 36
number theory, 81
factor, 81
fast exponentiation, 92–94 odd, 31
Fermat’s little theorem, 118 one-to-one, 61
Fibonacci sequence, 73 one-to-one correspondence, 65
finite set, 44 onto, 63
floor, 59 or, 5
function, 56
partition, 173
geometric progression, 70 permutation, 155
Goldbach conjecture, 103 Pigeonhole Principle, 152
graph, 163 power set, 44
greatest common divisor, 103 predicate, 22
Index 199
sequence, 70
set, 41
set builder notation, 41
shift cipher, 121
Sieve of Eratosthenes, 100
solution, 72
strong induction, 136
subject, 22
subset, 42
Subtraction Rule, 149
sum, 74
Sum Rule, 148
surjection, 63
surjective, 63
surjectivity, 63