Week 1: Logic Lecture 1, 8/21 (Sections 1.1 and 1.3)

advertisement
Week 1: Logic
Lecture 1, 8/21 (Sections 1.1 and 1.3)
Examples of theorems and proofs
Theorem (Pythagoras). Let !ABC be a right triangle, with legs of lengths a and b, and hypotenuse of
length c. Then a2 + b2 = c2 .
Proof. Proof by picture.
Theorem. For every positive integer n, the sum of the positive integers from 1 to n is
n(n+1)
.
2
Proof. If n is even, add the numbers in pairs: 1 + n, 2 + (n − 1), 3 + (n − 2), and so on. Each sum is n + 1
and the number of pairs is n2 , so the sum of all the numbers is n(n+1)
.
2
If n is odd, pairing up the numbers as before leaves the middle number n+1
unpaired. There are n−1
2
2
(n−1)(n+1)
n(n+1)
n+1
+
=
.
pairs, so the sum of all the numbers is
2
2
2
Introduction to logic
• Proposition: a sentence that is either true or false, not both. For instance: “Horses are mammals”
or “1 + 2 = −7”. Ask for more examples!
• The truth value of a proposition is written as either T (true) or F (false).
• Propositional variables: We use letters like P and Q to represent arbitrary propositions. Their
truth values can vary because the propositions they represent vary.
• Draw truth tables for the following propositions as they are introduced.
• “Not”: Given a proposition P , we write ¬P (“not P ”) for the new proposition “It is not true that
P ”. For instance, “Horses are not mammals” or 1 + 2 #= −7. ¬P is true whenever P is false, and vice
versa.
• “And”: The proposition P ∧ Q (“P and Q”) is true when both P and Q are true, and false otherwise.
For example, “Horses are mammals and 1 + 2 = −7” is a false statement because 1 + 2 = −7 is false.
• “Or”: The proposition P ∨ Q (“P or Q”) is true when either P or Q (or both) are true and false when
both P and Q are false. Let me emphasize that the logical “or” is true even when both P and Q are
true. Unlike the logical “or”, we sometimes use “or” in everyday language to express a choice between
two options: “I will buy you a lollipop or I will buy you a Honeycrisp apple”, with the intention that
you can’t have both. But this is ambiguous, and it’s better to say “either ... or ...” if this is intended.
• “Implies”: The proposition P =⇒ Q (“P implies Q” or “if P , then Q”; sometimes denoted
“P → Q”) is true except in the case when P is true and Q is false. A father might say to his daughter:
“My dear, if you get an ‘A’ in astrophysics, then I will buy you a bicycle”. When has the father upheld
his word? If the daughter gets an ‘A’ and father buys the bike, then all is well. If the daughter fails
to get an ‘A’, then father need not buy a bike, though he might get it anyway as consolation. But if
the daughter gets the ‘A’ and father does not buy her the bicycle, then the daughter has a reason to
be upset, and we would say daddy has been dishonest.
1
• The converse of P =⇒ Q is Q =⇒ P . This is very different! Look at the truth tables.
• The contrapositive of P =⇒ Q is ¬Q =⇒ ¬P , and is equivalent to P
propositions have the same truth table!).
=⇒ Q (the two
• “If and only if ”: P ⇐⇒ Q (“P if and only if Q”, or “P iff Q”, or “P is equivalent to Q”) is true if
P and Q have the same truth value, and false otherwise. For instance P ⇐⇒ (P ∧ P ) is always true.
Think of the proposition “I will move to India if and only if you will move to India”. I am claiming
that we will either move together or not at all, and I will be wrong if one of us goes while the other
stays.
• De Morgan’s Laws, ¬(P ∧ Q) ⇐⇒ ¬P ∨ ¬Q and ¬(P ∨ Q) ⇐⇒ ¬P ∧ ¬Q are always true (prove
using truth tables).
Lecture 2, 8/23 (Sections 1.4 and 1.6)
Propositions involving variables
• A statement containing a variable, like “x is greater than 3”, is not a proposition since its truth value
depends on the value of the variable. The variable x is the subject of the predicate (property) “is
greater than 3”.
• A statement like “x > 3” is a propositional function, denoted P (x), which becomes a proposition
when you plug in a value for x, and then has a truth value.
• Note: I’ll say much more about functions in the next two weeks.
• Propositional functions can have many input variables, such as the statement “x = y + 3”, which we
could denote Q(x, y). (Think of values for x and y making the statement true, and values making it
false.)
• Another way to turn a statement involving variables into a proposition is to use quantifiers. For this
we need to specify what values of each variable are allowed, which we call its domain. For example,
two possible domains for x that would make the statement x > 3 make sense are Z and R.
• Universal quantifier: ∀x P (x) is the proposition that for all x in the domain, P (x) is true. For
instance, ∀x (x > 3) is true if the domain is integers ≥ 4, but false if it is integers ≥ 3 (we say 3 is a
counterexample since 3 > 3 is false).
• Existential quantifier: ∃x P (x) is the proposition that for at least one value of x in the domain,
P (x) is true. For instance, ∃x (x > 3) is true if the domain for x is all integers, but false if the domain
is only negative integers.
• A compound proposition is a sentence built out of propositional variables (like P and Q), logical
symbols (¬, ∧, ∨, =⇒ , ⇐⇒ ), and quantified propositional functions (like ∀x P (x) and ∃x Q(x)).
Arguments
• An argument is a list of propositions, called premises, followed by one additional proposition, called
the conclusion. For instance,
! Premise 1: If you like tomatoes, you like pizza.
! Premise 2: You like tomatoes.
! Conclusion: You like pizza.
2
• An argument is valid provided that if the premises are true, then the conclusion is true. The above
argument is valid (if neither of the premises is false, then together they imply that you like pizza).
Note that by definition, any argument with a false premise is valid, and any argument with a true
conclusion is valid. The only way an argument can fail to be valid is if all the premises are true and
the conclusion is false.
• In logic, instead of studying studying specific arguments, one studies an abstract version. An argument form is a list of compound propositions, called premises, followed by one additional compound
proposition, called the conclusion. An argument form is valid provided that for any assignment of
truth values to the propositional variables that occur, if the premises are true then the conclusion is
true. The only way an argument form can be invalid is if there is an assignment of truth values to the
propositional variables such that the premises are true while the conclusion is false.
• To pass from an argument to an argument form, substitute a distinct propositional variable for each
distinct proposition that occurs in the argument. The argument form corresponding to the above
argument is the following:
! Premise 1: P =⇒ Q
! Premise 2: P
! Conclusion: Q.
This argument form is valid!
• If an argument form is valid, then any argument obtained by substituting propositions for the propositional variables is also valid!
• A silly valid argument:
! Premise 1: P
! Premise 2: ¬P
! Conclusion: Q.
As an argument, this could be: (ask class for two propositions). If the premises lead to a contradiction,
then the argument or argument form is guaranteed to be valid!
• Is the following argument form using the universal quantifier valid?
!
"
! Premise 1: ∀x P (x) =⇒ Q(x) , x in some domain.
! Premise 2: ¬Q(a), where a is a particular element in the domain.
! Conclusion: ¬P (a).
(Yes, it is. Prove using truth tables or contrapositive.)
3
Week 2: Proofs
Lecture 3, 8/28 (Sections 1.6 and 1.7)
Review of argument, validity. Recall that an argument or argument form is valid provided that if all the
premises are true, then the conclusion is true.
Rules of inference
• A formal proof is used to show an argument form is valid. One kind of proof is using a truth table,
but this can get very complicated when there are many propositional variables. A more useful method
of proof is to construct a chain of implications from the premises to the conclusion, using rules of
inference, which are tautologies (statements that are always true) of the form
{compound proposition} =⇒ {compound proposition}.
• Examples of rules of inference (p. 72 and 76), each of which can be thought of as a small valid argument:
(P ∧ Q) =⇒ P
P =⇒ (P ∨ Q)
!
"
(P ∨ Q) ∧ ¬P =⇒ Q
!
"
(P =⇒ Q) ∧ P =⇒ Q
(P =⇒ Q) =⇒ (¬Q =⇒ ¬P )
∀x P (x) =⇒ P (c), c any element of domain;
(1)
(2)
(3)
(4)
(5)
(6)
P (c) for arbitrary c =⇒ ∀x P (x)
(7)
P (c) for some element c =⇒ ∃x P (x).
(9)
∃x P (x) =⇒ P (c) for some element c
(8)
Think about what these are saying: most of them are obvious! Prove these for yourself using truth
tables. Then you can apply them whenever you like!
• With these rules of inference, we can prove the validity of slightly more complicated argument forms:
! Premise 1: P =⇒ Q
! Premise 2: ¬Q
! Conclusion: ¬P
Proof. By (5), premise 1 implies that ¬Q =⇒ ¬P . Combining this with premise 2, (4) implies
¬P .
! Premise 1: ∀x (P (x) =⇒ Q(x))
! Premise 2: ∃x P (x)
! Conclusion: ∃x Q(x)
Proof. By (8), premise 2 implies P (c) for some element c. By (6), premise 1 implies P (c) =⇒ Q(c).
By (4), P (c) and P (c) =⇒ Q(c) imply Q(c). Now we use (9) to conclude that ∃x Q(x).
4
Proofs in mathematics
• Mathematics begins with definitions and statements assumed to be true, called axioms or postulates. For example, the axioms of plane geometry.
• The starting point for this class: the integers, Z = {. . . , −2, −1, 0, 1, 2, . . . }, with the operations of
addition (+) and multiplication (·), and the real numbers R, with multiplication and addition. See
(A1-A6) for a discussion of the axioms.
• A theorem is a valid argument (premises and conclusion). A proof is used to demonstrate the
validity of a theorem. Starting with the premises of the theorem, one uses axioms and previously
proved theorems as rules of inference to reach the conclusion. As theorems accumulate, mathematics
grows ever lusher.
• Less important theorems are also called propositions, results, facts. A lemma is a theorem whose
main importance is that it is used in the proof of other theorems. A corollary is a theorem that
follows directly from another theorem.
Definition 1. An integer n is even if there exists an integer k such that n = 2k. An integer n is odd if
there exists an integer k such that n = 2k + 1. (Note that n is either even or odd, but not both; think about
how you would prove this! See Theorem 3 below.)
Let’s take a look at our first theorem!
Theorem 1. If n is an odd integer, then n2 is odd.
Is “n is an odd integer” a proposition? No! There is an implicit quantifier at work. In logical notation,
let P (n) be the propositional function “n is odd”, where the domain for n is Z. As an argument, the theorem
is
! No premises!
!
"
! Conclusion: ∀n P (n) =⇒ P (n2 ) .
We saw earlier that to prove a ∀n Q(n) claim, it suffices to show Q(n) for arbitrary n. So in terms of
mathematics, we suppress the quantifier, think of n as arbitrary but fixed (so that P (n) is a proposition!),
and the argument becomes
! Premise: No premises!
! Conclusion: P (n) =⇒ P (n2 ),
which is logically the same as the more typical
! Premise: P (n).
! Conclusion: P (n2 ).
How do we prove this argument is valid?
Lecture 4, 8/30 (more Section 1.7)
Outline for writing proofs
• Step 1: Before you attempt a proof, convince yourself that the theorem is correct! Checking easy
cases is often a good idea.
• Step 2: On scratch paper, write down the premises (“given”) at the top of the page, and the conclusion
(“want”) at the bottom of the page. Make sure you know what you want to show before you try to
show it!
5
• Step 3: Fill in the (both physical and logical) space between the “given” and “want”. Use definitions,
axioms (mainly arithmetic in our case), and previously proved theorems to deduce the “want” from
the “given”. This is an attempt at a direct proof: if you get stuck, try a proof by contraposition or
contradiction instead (I’ll define these terms below).
• Step 4: Once you have an outline of the proof on your scratch paper, convert it into precise, crisp
English sentences. Label it “proof”, draw your favorite symbol at the end, and you have yourself a
proof!
In the theorem above, our “given” is that n is odd, namely that there exists an integer k such that
n = 2k + 1. Our “want” is to show that n2 is odd, which means finding an integer j such that n2 = 2j + 1.
How do we find this j? We need some way to use our information about n to deduce something about n2 .
We have an equation for n, so square it! This gives us n2 = (2k + 1)2 = 4k 2 + 4k + 1 = 2(2k 2 + 2k) + 1. So
setting j = 2k 2 + 2k, which is an integer, we see that n2 = 2j + 1, so n2 is odd. So here is the theorem, with
its proof:
Theorem 1. If n is an odd integer, then n2 is odd.
Proof. Since n is odd, there is an integer k such that n = 2k + 1. Then n2 = (2k + 1)2 = 4k 2 + 4k + 1 =
2(2k 2 + 2k) + 1. Since 2k 2 + 2k is an integer, n2 is odd by definition.
The preceding proof is called a direct proof. We started with the premise and deduced the conclusion.
Sometimes direct proofs are difficult:
Theorem 2. If n is an integer and n2 is odd, then n is odd.
√
Attempt at a direct proof: n2 is odd, so n2 = 2k + 1. Thus n = ± 2k + 1. Now what? Instead, use a
proof by contraposition, namely show the contrapositive is true (recall that an implication P =⇒ Q is
logically equivalent to its contrapositive ¬Q =⇒ ¬P ).
Proof. We prove the contrapositive, namely “if n is even, then n2 is even”. Since n is even, n = 2k for some
integer k. Then n2 = (2k)2 = 4k 2 = 2(2k 2 ), so n2 is even by definition.
Another useful type of proof is proof by contradiction. To prove an argument with premises P1 , P2
(or any number of premises) and conclusion Q, instead take P1 , P2 , ¬Q as premises, and try to prove that
they imply a contradiction, which is a proposition, say R, that is false. (Often the negation of Q can be
used to deduce the negation of one of the premises, so that the contradiction R is of the form P1 ∧ ¬P1 .)
What is the point of this? Suppose we have shown that the modified argument
! Premises: P1 , P2 , ¬Q
! Conclusion: R
is valid, where R is a false proposition. I claim that this implies that our original argument
! Premises: P1 , P2
! Conclusion: Q
is valid. For the only way an argument with a false conclusion can be valid is if one of the premises is false.
But if we assume P1 , P2 are true for the sake of our original argument, then the only way for the modified
argument to be valid is if ¬Q is false, namely Q is true.
To set up a proof by contradiction, take the negation of the conclusion, add it to the premises, and try
to derive something false (a contradiction).
Theorem 3. If n is an integer, then it is either even or odd (not both).
Proof. To see that every integer is even or odd, note that we can write the set of integers as {. . . , (−1) ·
2, (−1) · 2 + 1, 0 · 2, (0 · 2) + 1, 1 · 2, . . . }. To see that an integer n cannot be both even and odd, we use a
proof by contradiction. Assume for contradiction that n is even and odd. Since n is even, n = 2k for some
integer k. Since n is odd, n = 2j + 1 for some integer j. Then 2k = 2j + 1, so 2(k − j) = 1. Now there are
three possibilities for k − j:
6
(1) k − j ≥ 1. But then 2(k − j) ≥ 2, contradicting 2(k − j) = 1.
(2) k − j = 0. But then 2(k − j) = 0 #= 1.
(3) k − j ≤ −1. But then 2(k − j) ≤ −2, contradicting 2(k − j) = 1.
So it cannot be that 2(k − j) = 1. Thus our assumption, which led to the contradiction, must be false. So
n cannot be both even and odd.
7
Week 3: More Proofs; Sets and
Functions
Lecture 5, 9/04 (even more Section 1.7)
Next I will show you a famous proof by contradiction. The statement of the theorem requires a definition:
Definition 2. A real number r is rational if there exist integers a and b with b #= 0 such that r = a/b.
A real number that is not rational is called irrational. Rational numbers can be written in lowest terms,
meaning r = a/b and a, b have no common factors.
√
Theorem 4. 2 is irrational.
I don’t know where to start for a direct proof, and proof by contraposition makes no sense here. But
proof by contradiction works! This proof is more difficult than the other proofs in this section.
√
√
Proof. Suppose for contradiction that the claim is false, so that 2 is rational. Then 2 = ab , and we may
assume a and b are not both even (write the rational number in lowest terms). Squaring both sides gives
2
2 = ab2 , or 2b2 = a2 . So a2 is even, from which it follows that a is even (contrapositive of Theorem 3!). Then
a = 2k, so 2b2 = (2k)2 = 4k 2 . Dividing both sides by 2, we get b2 = 2k 2 , so b2 is even. But this implies b is
even, so we have shown that both a and b are even, which is a contradiction. Since assuming the claim was
false led to a contradiction, the claim must be true.
Proving equivalence. In math, we have many ways of saying the same thing. We can express the statement
P =⇒ Q as:
(i) “P implies Q”;
(ii) “if P , then Q”;
(iii) “Q if P ;
(iv) “P only if Q;
(v) “P is sufficient for Q”;
(vi) “Q is necessary for P ”.
For this reason, we can express P ⇐⇒ Q, which means P =⇒ Q and Q =⇒ P , as “P if and only if Q”
or sometimes “P is necessary and sufficient for Q”.
Theorem 5. An integer n is even if and only if n + 2 is even.
We need to prove “n is even if n + 2 is even” (this means “if n + 2 is even, then n is even”) and “n is
even only if n + 2 is even” (“if n is even, then n + 2 is even”).
Proof. If n is even, then n = 2k for some integer k. Then n + 2 = 2k + 2 = 2(k + 1), so n + 2 is even. On
the other hand, if n + 2 is even, then n + 2 = 2k for some integer k. Thus n = 2k − 2 = 2(k − 1), so n is
even.
8
Lecture 6, 9/06 (Sections 2.1, 2.3)
Sets and functions
Definition 3. A set is an unordered collection of objects, called elements of the set. A set is said to
contain its elements. If A is a set, we write a ∈ A to denote that a is an element of A, and a ∈
/ A if a is not
an element of A.
To describe a set, either list all of its elements or state defining properties for an object to be in the set.
Some examples of sets are:
• The set with no elements, called the “empty set” and denoted ∅;
• {kiwi, dragon, shark, turtle, penguin};
• Z = {. . . , −2, −1, 0, 1, 2, . . . }, the set of integers;
• Z≥1 = {1, 2, 3, . . . } = {n ∈ Z | n ≥ 1}, the set of positive integers (sometimes called “natural
numbers”);
• Z≥0 = {0, 1, 2, . . . }, the set of non-negative integers (sometimes called “natural numbers”);
• R, the set of real numbers;
• (0, 1] = {x ∈ R | 0 < x ≤ 1};
Definition 4. Let A and B be sets. We say A is a subset of B (A ⊆ B) if every element of A is an element
of B. Two sets A and B are equal (A = B) if A and B have the exactly same elements. Note that A = B
if and only if both A ⊆ B and B ⊆ A. If two sets are not equal we write A #= B. We say A is a proper
subset of B (A ! B) if A is a subset of B and A #= B.
For example, the empty set is a subset of every set and a proper subset of every set other than itself.
The second set listed above is a subset of the set of all mythical and real animals that are not mammals.
We also have Z+ ! Z≥0 ! Z ! R and (0, 1] ! R.
Now for what may be the most important object in all of mathematics:
f
!B,
Definition 5. Let A and B be sets. A function (or map) f from A to B, written f : A → B or A
is an assignment of exactly one element of B to each element of A. If a ∈ A, we write f (a) = b or a 1→ b if
b is the unique element of B assigned by the function f to the a. We call A the domain of f and B the
codomain of f . If f (a) = b, then we say b is the image of a and a is a preimage of b. The set of all images
of f is called the image (or range) of f ; it is a subset of B.
To describe a function, either state explicitly which element of B is being assigned to each element of A,
or give a rule (or several rules) that specifies the assignment. Examples:
f
! {dolphin, cardamom, 99} given by giraffe 1→ 99, 10 1→ 99, cardamom 1→
• {giraffe, 10, cardamom}
dolphin. The image of f is {dolphin, 99}.
• Z
f
! Z given by n 1→ n2 . Or Z
g
! Z≥0 with the same rule.
We should think about the two functions in the last example above as different, so we define:
Definition 6. Two functions A
for all a ∈ A = C.
f
! B and C
g
f
! D are equal if A = C, B = D, and f (a) = g(a)
! B is injective (one-to-one) if f maps no two distinct elements of A to
Definition 7. A function A
the same element B. Expressed in notation, this means that if a1 , a2 ∈ A and a1 #= a2 , then f (a1 ) #= f (a2 ).
(Another common way of expressing this is by the contrapositive: if f (a1 ) = f (a2 ), then a1 = a2 .)
9
Week 4: More Sets and Functions
Lecture 7, 9/11 (Section 2.3)
f
! B is surjective (onto) if the image of f is the entire codomain B. This
Definition 8. A function A
means that for every b ∈ B there is an element a ∈ A such that f (a) = b .
f
! B is bijective if it is both injective and surjective. This means that f
Definition 9. A function A
establishes a perfect correspondence of the elements of A with the elements of B.
Examples:
• For any set A, the identity function A
• The function Z
f
g
Definition 10. Given functions A
g◦f
! A is the bijective map defined by a 1→ a for all a ∈ A.
! Z given by f (n) = n + 3.
• The exponential function R
A
idA
! R>0 given by x 1→ 2x .
f
g
! B and B
! C , the composition of f and g is the function
! C given by (g ◦ f )(a) = g(f (a)).
Examples:
• For any set A, idA ◦ idA = idA .
• Given Z
f
! Z defined by f (n) = n + 3 and Z
g
! Z defined by g(n) = 2n, Z
g◦f
! Z is the
map (g ◦ f )(n) = g(f (n)) = g(n + 3) = 2(n + 3) = 2n + 6. Composing in the other order, Z
is the map (f ◦ g)(n) = f (g(n)) = f (2n) = 2n + 3. Note that f ◦ g #= g ◦ f !
f ◦g
!Z
f
! B and B g ! A be functions such that g ◦ f = idA and f ◦ g = idB . Then
Definition 11. Let A
we say f and g are inverse functions. We also say f is invertible and that f has g as an inverse, and
often denote that inverse by f −1 .
Examples:
• The inverse of idA is idA .
• The inverse of the function Z
f −1 (n) = n − 3.
f
! Z given by f (n) = n + 3 is the function Z
• The inverse of the exponential function R
that maps x 1→ log2 x.
Theorem 6. A function A
f
g
f −1
! Z given by
! R>0 given by x 1→ 2x is the logarithm R>0
! B has an inverse if and only if it is bijective.
10
g −1
!R
g
Proof. Suppose f has an inverse B
! A . We check that f is injective. Suppose f (a1 ) = f (a2 ). Then
a1 = idA (a1 ) = (g ◦ f )(a1 ) = g(f (a1 )) = g(f (a2 )) = (g ◦ f )(a2 ) = idA (a2 ) = a2 ,
so f is injective. To see that f is surjective, suppose b ∈ B. Then g(b) ∈ A and
f (g(b)) = (f ◦ g)(b) = idB (b) = b,
so f is surjective. Thus f is bijective.
g
! A to be the map that assigns to each element
Conversely, suppose f is bijective. Then define B
b ∈ B the unique element a ∈ A such that f (a) = b. Such an element a exists since f is surjective, and is
unique since f is injective. Now we use this definition of g to compute
(g ◦ f )(a) = g(f (a)) = a,
(f ◦ g)(b) = f (g(b)) = b.
Thus g ◦ f = idA and f ◦ g = idB , so g is the inverse of f .
Lecture 8, 9/13 (Section 2.2)
Here is an example of a proof involving an inverse function.
Theorem 7. The function R
f
! R given by f (x) = x3 is bijective.
Proof. We will construct a function that is the inverse of f . Since an invertible function must be bijective,
g
! R mapping x 1→ x1/3 , which is a function
this will prove that f is bijective. Consider the function R
since the cube root of any real number makes sense. We check the compositions. R
g◦f
! R is the map
x 1→ (g ◦ f )(x) = g(f (x)) = g(x3 ) = (x3 )1/3 = x, so g ◦ f = idR . Similarly, R
(f ◦ g)(x) = f (g(x)) = f (x1/3 ) = (x1/3 )3 = x, so f ◦ g = idR .
f ◦g
! R is the map
Combining sets
Notation: from now on, I’ll make heavy use of the notation “:=” when I’m defining something.
Definition 12. Let A and B be sets. The union of A and B is the set A ∪ B := {x | x ∈ A or x ∈ B}.
The intersection of A and B is the set A ∩ B := {x | x ∈ A and x ∈ B}. A and B are called disjoint if
A ∩ B = ∅. The difference of A and B (or the complement of B in A) is the set A − B := {x ∈ A | x ∈
/ B}.
Examples:
• Draw Venn diagrams.
• Let E be the even integers and O be the odd integers. Then E ∩ O = ∅, so E and O are disjoint.
E ∪ O = Z, Z − E = O, and E − Z = ∅.
We can take unions and intersections of an arbitrary number of sets.
#∞
Definition 13. $
Let A1 , A2 , . . . be sets. Then their union is i=1 Ai := {x | x ∈ Ai for some i} and their
∞
intersection is i=1 Ai := {x | x ∈ Ai for all Ai }.
Examples:
#∞
≥0
• Set
$∞ [a, b) := {x ∈ R | a ≤ x < b}. Then n=0 [n, n + 1) = [0, ∞) = R . On the other hand,
n=0 [n, ∞) = ∅.
#∞
• Set (a, b) := {x ∈ R | a < x < b}. Then n=1 ( n1 , ∞) = (0, ∞).
Definition 14. Let A and B be sets. The product of A and B is the set of ordered pairs A × B := {(a, b) |
a ∈ A, b ∈ B}.
Note: we could have defined a function from A to B to be a subset S of A × B such that each a ∈ A is
f
! B by f (a) = b would recover our original definition.
in exactly one pair (a, b) ∈ S. Defining A
11
Week 5: Infinity
Lecture 9, 9/18 (Section 2.5)
Comments on the quiz.
Hilbert’s hotel
David Hilbert was a great man, but perhaps an even greater hotelier. Hilbert owned a grand hotel with
infinitely many rooms, numbered by Z≥0 . One day, the hotel was full. A guest arrived, and was dismayed
to see there were no empty rooms. But lo and behold: the hotel staff simply asked each current resident to
shift one room up (in number), freeing room 0 for the new guest. Next, a crowd of 100 guests arrived, and
they too could be accommodated: everyone else shifted up 100 rooms. But then a horde of infinitely many
guests arrived, one for each element of Z≥0 . The hotel staff started to worry, but Hilbert just smiled as he
instructed each current resident to move to the room with twice their current room number, thereby freeing
up all the odd-numbered rooms. Then he put the first guest in room 1, the second in room 3, the third in
room 5, and so on, and all the guests received lodging!
Can Hilbert’s hotel accommodate any number of new guests? What if a crowd of guests arrives, one for
each rational number? How about one for each real number between 0 and 1? To find out, we develop the
theory of cardinality for distinguishing different sizes of infinity.
Cardinality
Definition 15. Let A be a set. If A has exactly n elements, for some positive integer n, then we say A is a
finite set and the cardinality of A (denoted |A|) is n. A set that is not finite is said to be infinite.
Example. If A and B are finite sets, then |A × B| = |A| · |B|. Also, |A ∪ B| = |A| + |B| − |A ∩ B|.
For infinite sets, cardinality is a relative measure, used to compare sizes of infinite sets:
Definition 16. Two sets A and B have the same cardinality (written |A| = |B|) if there is a bijective
function A
f
! B . If there is an injective function A
f
! B , then the cardinality of A is less than or
equal to the cardinality of B (we write |A| ≤ |B|). If |A| ≤ |B| and there is no bijective function A
then A has smaller cardinality than B (write |A| < |B|).
f
!B,
Using cardinality, we now establish two different sizes of infinity: the cardinality of Z≥0 , and bigger
cardinalities.
Definition 17. An infinite set that has the same cardinality as Z≥0 is said to be countable. A set that is
not countable is uncountable.
Remark. A set A is countable if and only if it can be written as an infinite list. To see this, note that a
bijection Z≥0
Example.
f
! A gives a natural way to construct a list, namely A = {f (0), f (1), f (2), f (3), . . . }.
• Z≥0 = {0, 1, 2, . . . } is countable, with bijection Z≥0
12
idZ≥0
! Z≥0 .
• Z≥1 = {1, 2, 3, . . . } is countable, with bijection Z≥0
• Z≥100 is countable, with bijection Z≥0
f
f
! Z≥1 given by f (n) = n + 1.
! Z≥100 given by f (n) = n + 100.
f
! E given
• The non-negative even integers E = {0, 2, 4, 6, . . . } are countable, with bijection Z≥0
by f (n) = 2n.
Note that the bijective functions in the last three examples correspond to the ways the staff in Hilbert’s
hotel made room for new guests. Each of these bijections is a bijection from Z≥0 onto a proper subset of
Z≥0 , which means every current resident of the hotel could be moved to a new room, while freeing up 1,
100, or infinitely (countably) many rooms for the new guests.
Theorem 8. Z is countable.
Proof. We can put the integers in a list {0, 1, −1, 2, −2, . . . }. This corresponds to the bijection Z
given by
%
2n − 1 if n > 0;
f (n) =
−2n
if n ≤ 0.
f
! Z≥0
Lecture 10, 9/20 (More section 2.5 and a little 2.4)
Theorem 9. If A and B are countable, then A ∪ B is countable.
Proof. Since A and B are countable, we can label their elements as A = {a0 , a1 , a2 , . . . } and B = {b0 , b1 , b2 , . . . }.
Then A ∪ B = {a0 , b0 , a1 , b2 , a2 , . . . }, so after eliminating redundant elements from the list, we see that A ∪ B
is countable.
This theorem gives us another proof that Z is countable. Namely, write Z = Z≥0 ∪ Z≤0 and note that
each of the sets in the union is countable.
Theorem 10. The set of rational numbers is countable.
Proof. Use the diagram on page 173 to argue that the positive rational numbers are countable. Adding zero
at the front of the list, we see that the non-negative rational numbers are countable. Similarly, the negative
rational numbers are countable. Thus by the previous theorem, the rational numbers are countable.
#∞
Theorem 11. If A1 , A2 , . . . are countable sets, then i=0 Ai is countable.
Proof. Since each Ai is countable, write Ai = {ai,0 , ai,1 , ai,2 , . . . }. Then use the same trick as for the rational
numbers.
Are all infinite sets countable? No!
Theorem 12. The set of real numbers is uncountable.
Proof. Suppose for contradiction that R is countable. Then the open interval (0, 1) is also countable, so
we may write (0, 1) = {x1 , x2 , x3 , . . . }. Now write the decimal expansions of the xi and use Cantor’s
diagonalization trick (p. 173-4) to construct an element x ∈ (0, 1) that cannot be in the list. Contradiction.
This is an astonishing result: the rational numbers are dense on the real line (for any real number, there
are rational numbers arbitrarily close to it), yet there are far more (in the sense of cardinality) irrational
numbers! The quantity of real numbers is a larger infinity than the quantity of rational numbers!
13
Zeno’s paradox
Suppose you want to get up and leave the room. Zeno the Greek philosopher says you cannot! Not just that
you may not, but that you physically cannot! Here’s why. The door is some distance, say 2 meters, away.
You start walking and get halfway there, but you’re still 1 meter away. You keep going, but after another
1
1
1
1
2 meter, you’re still one 2 meter short of your target. After another 4 meter, you still have 4 meter to go.
And so on: each time you cross half the remaining distance you get closer and closer, but you never quite
reach the door!
We’ll see shortly how mathematics solves the paradox.
Sequences and series
Definition 18. A sequence is a function from a subset of Z (usually Z≥0 or Z>0 to a set S. We denote the
image of the integer n by an ∈ S (we can also use some other letter instead of a). We think of a sequence
as a list (a0 , a1 , a2 , . . . ) of elements of S, and denote a sequence by (an )n≥0 , where we specify the domain
by the inequality subscript.
Note that a sequence is an ordered list, which may have repeated elements, two things that distinguish
it from a set.
Example. Consider the sequence (an )n≥1 , where an =
1
n
∈ Q. It begins with 1, 12 , 13 , . . . .
Definition 19. A geometric progression is a sequence of the form (a, ar, ar2 , ar3 , . . . , arn , . . . ), where
the initial term a and the ratio r are real numbers.
Definition 20. An arithmetic progression is a sequence of the form a, a + d, a + 2d, a + 3d, . . . , a + nd, . . . ,
where the initial term a and the difference d are real numbers.
&n
Notation. Given a finite sequence (a1 , a2 , . . . , an ), we use summation notation j=1 aj to denote the
sum a1 + a2 + · · · + an .
Theorem 13. If r ∈ R, then the sum of the finite geometric series with initial term 1 and ratio r is
%
n
1−r n+1
'
if r #= 1;
j
1−r
r =
n
+
1
if r = 1.
j=0
Proof. The case when r = 1 is obvious. If r #= 1, note that
(1 − r)(1 + r + r2 + r3 ) = 1 − r + r − r2 + r2 − r3 + r3 − r4 = 1 − r4 .
Similarly, we see that
(1 − r)(1 + r + r2 + · · · + rn ) = 1 − rn+1 .
Now since r #= 1, we can divide both sides by 1 − r to get the formula.
Now we investigate when we can take the sum of an infinite geometric series with ratio r #= 1. For this
we need the notion of limit, which I won’t define rigorously, so use your intuition from calculus. We want to
take a limit
n
'
lim
rj .
n→∞
j=0
When is this limit finite? By the previous theorem, this limit is equal to
1 − rn+1
.
n→∞
1−r
lim
If |r| > 1, the term rn+1 blows up as n → ∞, so the limit is ±∞, which we don’t want. If r = −1, then rn+1
oscillates between −1 and 1 depending on whether n + 1 is odd or even, so the limit doesn’t exist. Since
r #= 1 by assumption, the only remaining case is when |r| < 1, and in this case rn+1 goes to 0 as n goes to
∞! Thus:
14
Theorem 14. If r ∈ R and |r| < 1, then
∞
'
rj =
j=0
1
.
1−r
Note that when r > 0, the infinitely many positive numbers have a finite sum! This is the key to Zeno’s
paradox. Suppose you move at a rate of 1 meter per second. Then it takes you 1 second to cross the first
meter that gets you halfway to the door, 12 second for the next 12 meter to the door, 14 second to cross the
next 14 meter, 18 second for the next 18 meter, and so on. Thus the total number of seconds it takes you to
get to the door is
∞
'
1
1
1
=
1 = 1/2 = 2,
n
2
1
−
2
j=0
a finite number, which is certainly within your capabilities!
15
Week 6: Basics of Number Theory
Lecture 11, 9/25 (Sections 4.1 and 4.3)
Number theory is the study of the integers. We start with the basic definitions.
Division and Primes
Definition 21. If a, b ∈ Z with a #= 0, then a divides b (we write a | b) if there is an integer c such that
b = ac. We then call a a factor or divisor of b, and b a multiple of a.
Example.
• If n ∈ Z, then 2 | n if and only if n is even.
• 1 | a for every a ∈ Z.
• a | 0 for every nonzero a ∈ Z.
Some easy properties of divisibility are:
Theorem 15. Let a, b, c ∈ Z, with a #= 0. Then
(i) if a | b and a | c, then a | (b + c)
(ii) if a | b, then a | bc for all integers c;
(iii) if a | b and b | c, then a | c.
Proof. For (i), since a | b, there is s ∈ Z such that b = as. Since a | c, there is t ∈ Z such that c = at. Then
b + c = as + at = a(s + t), so a | (b + c).
(ii) and (iii) are homework exercises!
Corollary 1. If a, b, c ∈ Z with a #= 0, such that a | b and a | c, then a | mb + nc for any m, n ∈ Z.
Now let’s get reacquainted with our old friends from elementary school, the prime numbers:
Definition 22. An integer p > 1 is prime if its only positive factors are 1 and p. An integer greater than
1 is called composite if it is not prime.
Note: 1 is not prime! We’ll see in a moment why we want to exclude 1.
Example. The set of primes less than 100 is
{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97}.
Why are primes important? They are the building blocks of all positive integers!
Theorem 16 (Fundamental theorem of arithmetic). Let n ∈ Z>1 . Then there is a unique sequence of primes
p1 ≤ p2 ≤ · · · ≤ pr such that n = p1 p2 · · · pr .
We call the expression n = p1 p2 · · · pr the prime factorization of n. Note that if 1 were a prime, then
the prime factorization would not be unique since we could take any number of 1’s as factors!
16
Proof. Sadly I have to postpone this crucial proof until we have learned proof by induction (Ch. 5)!
To find the prime factorization of a number n, check whether any of the primes less than n divide n. As
soon as you find a prime p such that p | n, add p to your factorization, and repeat the process for np .
Example. 2 = 2 is prime! 6 = 2 · 3. 63 = 3 · 3 · 7. 100 = 2 · 2 · 5 · 5.
Remark. Note that an integer > 1 is composite if and only if its prime factorization has at least two primes
(possibly the same prime twice)!
How many primes are there? Plenty!
Theorem 17. There are infinitely many primes.
Proof. Assume for contradiction that there are only finitely many primes, say {p1 , p2 , . . . , pn }. Then consider
N = p1 p2 · · · pn + 1.
Since N has a prime factorization, there is a pi that divides N . But pi also divides p1 p2 · · · pn , so pi divides
N − p1 p2 · · · pn = 1 by Theorem 15 (i). This is a contradiction since no prime can divide 1.
Remark. We can use the sieve of Eratosthenes (p.259-60) to compute all the primes less than a given
number. See the additional problem in the homework.
Lecture 12, 9/27 (More sections 4.1 and 4.3)
More Review of Elementary School Math
Definition 23. For a, b ∈ Z, the largest integer d such that d | a and d | b is called the greatest common
divisor of a and b and is denoted by gcd(a, b). We say a and b are relatively prime if gcd(a, b) = 1.
Remark. You can compute gcd(a, b) by taking the “intersection” of the prime factorizations of a and b.
For example, 36 = 2 · 2 · 3 · 3 and 84 = 2 · 2 · 3 · 7 have gcd(36, 84) = 2 · 2 · 3 = 12.
Definition 24. The least common multiple of a, b ∈ Z>0 , denoted lcm(a, b), is the smallest positive
integer m such that a | m and b | m.
Remark. You can also compute lcm(a, b) from the prime factorizations: take the “union” of the prime
factorizations for a and b. For instance, lcm(36, 84) = 2 · 2 · 3 · 3 · 7.
Theorem 18. Let a, b ∈ Z>0 . Then ab = gcd(a, b) · lcm(a, b).
Proof. Idea: think about the description of gcd(a, b) and lcm(a, b) in terms of prime factorizations!
Technical Machinery
Recall division with remainder from elementary school:
23
3
= 5 + = 5 R3.
4
4
Since we don’t have fractions when working with just Z, we clear denominators and formalize this as:
Theorem 19 (Division algorithm). Let a, d ∈ Z with d > 0. Then there are unique integers q, r with
0 ≤ r < d such that a = dq + r.
Proof. Idea: keep adding or subtracting d from a until you end up in the set {0, 1, . . . , d − 1}. Think of
dividing a by d and finding the remainder!
Definition 25. In the equality a = dq + r in the division algorithm, d is the divisor, a is the dividend, q
is the quotient, and r is the remainder.
Example. Note that the remainder must be non-negative! So applying the division algorithm to a = −7
and d = 6, we get q = −2 and r = 5, namely −7 = 6 · (−2) + 5.
We’ll see much, much more about the remainder next week!
17
Euclidean Algorithm
For large numbers, it is hard to find the prime factorizations. But there is an efficient method for finding
the gcd of two positive integers a, b, called the Euclidean algorithm. The idea is to repeatedly use the
division algorithm, first on a and b to get a = bq + r, then on b and r, and so on, until the remainder is 0.
The point is that the gcd is preserved from one step to the next:
Lemma 1. Let a = bq + r, where a, b, q, r ∈ Z. Then gcd(a, b) = gcd(b, r).
Proof. It suffices to show that the common divisors of a and b are the same as the common divisors of b and
r. If d | a and d | b, then d | a − bq = r by the corollary to Theorem 15. Similarly, if d | b and d | r, then
d | bq + r = a.
With each step, the numbers get smaller, so that by the end the gcd becomes obvious: it is the last
non-zero remainder! This is because the last non-zero remainder divides the last dividend, so the gcd of the
two is just that last non-zero remainder.
The Euclidean algorithm actually gives us more than just the gcd of a and b. It allows us to express that
gcd as a sum of multiples of a and b, which will be very, very useful next week when we want to solve linear
congruences!
Example. Find gcd(123, 45) using the Euclidean algorithm. Running the algorithm, we compute:
123 = 45 · 2 + 33
45 = 33 · 1 + 12
33 = 12 · 2 + 9
12 = 9 · 1 + 3
9 = 3 · 3 + 0.
The last nonzero remainder is 3, so gcd(123, 45) = 3!
Theorem 20. For a, b ∈ Z>0 , there exist s, t ∈ Z such that gcd(a, b) = sa + tb.
We say that gcd(a, b) can be expressed as a linear combination of a and b, with integer coefficients.
Proof. Idea: use the output of the Euclidean algorithm to find s and t. For example, when a = 123 and
b = 45, solving for the remainders in the output of the algorithm and repeatedly substituting, starting from
the bottom, yields:
3 = 12 − 9 · 1
= 12 − (33 − 12 · 2) · 1 = 12 · 3 − 33
= (45 − 33 · 1) · 3 − 33 = 45 · 3 − 33 · 4
= 45 · 3 − (123 − 45 · 2) · 4 = 45 · 9 − 123 · 4.
So s = −4 and t = 9.
The Euclidean algorithm and the substitution process are essential. That is why I’ve asked you to run
the algorithm a full 18 times in the homework. We will rely heavily on both parts next week, so make sure
it is a well-honed tool in your arsenal!
18
Week 7: Modular Arithmetic
Lecture 13, 10/02 (More section 4.1)
Modular Arithmetic
In some situations we care only about remainders. For instance, what time will it be 50 hours from now? One
way to find the answer is to compute the remainder of 50 divided by 24, and add that to the current time.
Working with remainders is surprisingly interesting mathematically, and has amazingly powerful applications
to cryptography, as we will see next week.
Recall the division algorithm:
Theorem (Division algorithm). Let a, d ∈ Z with d > 0. Then there are unique integers q, r with 0 ≤ r < d
such that a = dq + r.
We call this unique r the remainder. (The book denotes it a mod d, but we will not use this notation.)
Definition 26. If a, b ∈ Z and m ∈ Z>0 , then a is congruent to b modulo m (written a ≡ b (mod m))
if a and b have the same remainder when divided by m. We say that a ≡ b (mod m) is a congruence and
that m is its modulus. If a and b are not congruent modulo m, we write a #≡ b (mod m).
Example. 11 ≡ 7 ≡ 3 ≡ −1 ≡ −5 (mod 4) because all these numbers have remainder 3 when divided by 4.
For example, −1 = 4 · −1 + 3 (recall that by definition the remainder is non-negative!).
Remark. As in the previous example, we write “(mod m)” only once per line of congruences. Writing
“(mod m)” simply means that one is working in a special setting where numbers are considered “congruent”
if they have the same remainders when they are divided by m.
Remark. A useful equivalent form of the definition is as follows: a ≡ b (mod m) if and only if there is an
integer k such that a = b + km (prove this is equivalent!). Another way of saying this is that m divides a − b,
or that a and b differ by a multiple of m. The point is that adding a multiple of m to a number doesn’t
change its remainder when divided by m.
Remark. Let a ∈ Z and d ∈ Z>0 . Then d | a if and only if a ≡ 0 (mod d).
Remark. Congruence modulo m divides the integers into m congruence classes, one for each possible
remainder r ∈ {0, 1, 2, . . . , m − 1}. The class corresponding to the remainder r, written as a set, is {r + mk |
k ∈ Z}, and we sometimes denote it by r̄ (“r bar”). For example, if m = 2, the congruence classes are the
even numbers (0̄) and the odd numbers (1̄).
A useful result that makes computations modulo m easy is the following:
Theorem 21. Let m ∈ Z>0 . If a ≡ b (mod m) and c is any integer, then
a+c≡b+c
(mod m)
and
ac ≡ bc
(mod m).
Proof. Since a ≡ b (mod m), there is an integer s such that a = b + sm. Then a + c = b + c + sm, so
a + c ≡ b + c (mod m), and ac = (b + sm)c = bc + (sc)m, so ac ≡ bc (mod m).
19
Remark. What the theorem says is this: if we are working modulo m, then we can replace any number
in a sum or product by any other number with the same remainder (in the same congruence class). This
makes computations easy, because we can replace big numbers by small numbers, such as those between 0
and m, or sometimes small negative numbers. For instance, what are the remainders when 12100 or 10100
are divided by 11? Congruence makes the computation incredibly easy. Since 12 ≡ 1 (mod 11), we apply
the theorem repeatedly, replacing the factors of 12 by 1 one at a time, to see that
12100 ≡ 1100 ≡ 1
(mod 11).
Similarly, since 10 ≡ −1 (mod 11), we can replace each factor of 10 by −1 to get
10100 ≡ (−1)100 ≡ 1
(mod 11).
Remark. To summarize, arithmetic modulo m works just like normal arithmetic, except that you can
replace numbers being added or multiplied (but not exponents!) by congruent numbers modulo m. This
makes modular arithmetic much easier, because you can keep the numbers smaller than the modulus!
Example. Find a ∈ Z with 0 ≤ a < 7 such that a ≡ 3100 (mod 7). There’s no trick quite as easy as in
the previous examples, but the small modulus still makes things easy. Start by finding a power of 3 that is
particularly easy to work with modulo 7: note that 33 ≡ −1 (mod 7). Then compute
3100 = 3 · (33 )33 ≡ 3 · (−1)33 = −3 ≡ 4
(mod 7),
so a = 4.
Congruences can be used to give easy proofs of criteria for divisibility.
Theorem 22. Let a ∈ Z and let D be the sum of the digits of a. Then 3 | a if and only if 3 | D.
Proof. Write a = an an−1 . . . a0 , where the ai denote the digits of a. Then since 10 ≡ 1 (mod 3),
a = a0 + 10a1 + 102 a2 + · · · + 10n an ≡ a0 + a1 + · · · + an = D
(mod 3).
Thus a ≡ 0 (mod 3) if and only if D ≡ 0 (mod 3).
Lecture 14, 10/04 (Section 4.4)
Fermat’s Little Theorem
Last time, we used some tricks to compute large powers of integers modulo m. The following theorem takes
care of must such problems:
Theorem 23 (Fermat’s little theorem, often abbreviated FLT). If p is prime and a is an integer not divisible
by p, then
ap−1 ≡ 1 (mod p).
The theorem is saying that for any a not divisible by p, p divides ap−1 − 1. For instance, if 3 " a, then
3|(a2 − 1). Indeed, 3 divides 12 − 1 = 0, 22 − 1 = 3, 42 − 1 = 15, 52 − 1 = 24, and so on.
Proof. An outline is given in Exercise 19 of Section 4.4. This is an optional homework problem!
Example. Find the remainder of 3100 when divided by 7. Since gcd(3, 7) = 1, we can apply Fermat’s little
theorem to compute
3100 = 34 · (36 )16 ) ≡ 34 · (1)16 = 34 ≡ 4 (mod 7),
which is the same answer we got earlier!
One of the things you learn in your first algebra class is how to solve linear equations like 3x + 4 = 0
for x. One first subtracts 4 (adds −4), to obtain 3x = −4. Then one divides by 3, which really means
multiplying by 13 . The key is that the coefficient of x, namely 3, has a multiplicative inverse, namely 13 ,
which is a number such that 13 · 3 = 1. The multiplicative inverse allows you change the coefficient of x to 1.
20
Linear Congruences
A natural question is whether we can solve the congruence analog of linear equations.
Definition 27. A linear congruence is a congruence of the form ax + b ≡ 0 (mod m), where a, b ∈ Z,
m ∈ Z>0 , and x is a variable.
We want to solve for all integer values of x that satisfy the congruence.
Example. Solve the linear congruence 3x + 1 ≡ 0 (mod 5). First, we add −1 (which is congruent to 4) to
both sides, to get 3x ≡ 4 (mod 5). Now we want to remove the coefficient of x. For this, we need to find
a multiplicative inverse of 3 modulo 5, namely some c ∈ Z such that c · 3 ≡ 1 (mod 5). Guess and check
reveals that 2 works: 2 · 3 ≡ 1 (mod 5). So we multiply our equation by 2 on both sides, to get 2 · 3x ≡ 2 · 4
(mod 5), which simplifies to x ≡ 3 (mod 5). Now we can read off the solutions to our linear congruence: x
can be anything with remainder 3 modulo 5, namely any integer of the form 3 + 5k for k ∈ Z. So we can
write the solution set as {3 + 5k | k ∈ Z}. Instead of just one value for x, our solution is a whole congruence
class modulo 5!
The only tricky part of solving the congruence in the example was the existence of a multiplicative inverse
for 3. The natural question to ask is: When does a have a multiplicative inverse modulo m, and how can
we find it if it exists?
Here is the answer:
Theorem 24. Let a ∈ Z and m ∈ Z>1 . If gcd(a, m) = 1, then a has an inverse modulo m.
We’ve done all the hard work already by studying the Euclidean algorithm and substitution process. The
substitution process, in particular, will give the multiplicative inverse. It is time to reap the rewards!
Proof. Since gcd(a, m) = 1, by Theorem 20 there exist s, t ∈ Z such that 1 = sa+tm. Thus sa ≡ 1 (mod m),
so s is a multiplicative inverse of a.
So we can solve any linear congruence ax + b ≡ 0 (mod m) for which gcd(a, m) = 1. For instance:
Example. Solve 3x + 6 ≡ 0 (mod 10). We run the Euclidean algorithm on 3 and 10:
10 = 3 · 3 + 1
3 = 1 · 3 + 0.
So gcd(3, 10) = 1. Moreover, 1 = 10 − 3 · 3, so the multiplicative inverse of 3 modulo 10 is −3, which is
congruent to 7. So we add 4 to both sides, then multiply by 7 to get
x≡7·4≡8
(mod 10),
so the set of solutions is {8 + 10k | k ∈ Z}.
But what if gcd(a, m) = d > 1? For instance:
Example. Solve 2x ≡ 1 (mod 6). Here gcd(2, 6) = 2, so we cannot find an inverse for 2 modulo 6. Test
some numbers for x, and you’ll find none of them work! That’s because if x were a solution, then 2x = 1 + 6k
for some k, but 2 | 2x and 2 | 6k, so necessarily 2|(2x − 6k), which is a contradiction since 2 " 1. So there are
no solutions!
The problem in the above example was that gcd(a, m) " b, which makes it impossible to find a solution.
So what happens if gcd(a, m) | b?
Example. Solve 4x + 2 ≡ 0 (mod 6). As before, gcd(4, 6) = 2, and this time b = 2 and 2 | 2. x is a solution
if 4x + 2 = 6k, which implies that 2x + 1 = 3k. So we see that the solutions to 4x + 2 ≡ 0 (mod 6) are the
same as the solutions to 2x + 1 ≡ 0 (mod 3), which we can solve since gcd(2, 3) = 1.
We summarize all of this:
Theorem 25. Let a, b ∈ Z and m ∈ Z>1 and set d = gcd(a, m). Then the linear congruence ax + b ≡ 0
(mod m) has solutions if and only if d | b, in which case the solutions are the same as the solutions of
a m
the congruence ad x + db ≡ 0 (mod m
d ). Since gcd( d , d ) = 1, this latter system can be solved by finding a
a
m
multiplicative inverse for d modulo d .
21
Week 8: Cryptography
Lecture 15, 10/16 (Section 4.6)
Cryptography
Have you ever solved a cryptogram? You see an encrypted phrase like
XBZZA, LBALZB!
which is the result of taking a phrase and performing a letter substitution, such as replacing A by T , B by
L, and so on. In this case, analyzing the punctuation and letter patterns could lead you to the solution
HELLO, PEOPLE!
To make a simple cryptogram, choose a short message, let’s call it M, written in capital letters with
φE
! {A, B, C, . . . , Z} .
spaces but no punctuation, and a bijective (one-to-one) function {A, B, C, . . . , Z}
Then “encrypt” the message M by applying the function to each letter in M, to obtain an encrypted message
φE (M). To “decrypt” an encrypted message, simply apply the inverse of φE : φ−1
E (φE (M)) = M. We call
M the message, φE the encryption key, and φ−1
E the decryption key.
Suppose you want to communicate with a friend via written messages, in such a way that no third party
who intercepts the messages will be able to read them. You and your friend get together in utmost secrecy
and agree on an encryption key φE and a decryption key φD , which could be much more complicated than
the bijection above (for instance, choose one bijection for the first word of the message, a different bijection
for the second word, etc.). Now as long as you keep these keys secret, third parties who intercept encrypted
messages φE (M) will have trouble decrypting them.
But what if you have no way to secretly share the encryption and decryption keys?
Public key cryptography is a way for strangers to communicate securely. The future message recipient,
say Amazon.com, publishes an encryption key φE , which anyone can see, but keeps the decryption key φD
private. When making a purchase, a shopper uses the encryption key to encrypt the details M of the order
(especially the credit card number!), and the encrypted message φE (M) is sent to Amazon. Amazon then
decrypts the message φD (φE (M)) = M and draws money from the account. Since the encryption key is
public, any snooping third party has access to it. So security hinges on whether decryption is a much harder
process than encryption: the encryption key should not reveal the decryption key! Note that this is not the
case in the cryptogram example above, where φD = φ−1
E , namely the decryption key was easy to compute
from the encryption key.
A famous public key cryptosystem used extensively online is called the RSA cryptosystem. RSA is
based on number theory, so the first step is to convert letters into numbers. We can do this by the easy
substitution A 1→ 01, B 1→ 02, C 1→ 03, ..., Z 1→ 26. We also want to keep track of spaces, so we replace
each space by “00”.
RSA Encryption
Here is a simple example to illustrate how RSA works. Amazon publishes two carefully chosen numbers,
say n = 28907 and e = 11 (in reality these will be much larger), which will be used for encryption. For
22
convenience, set # to be the number of digits of n, in this case # = 5. You, the shopper, can see all of this
public information, and you encode your order as follows. Suppose part of the order is
DISCRETE MATH.
First, you convert this text into numbers, by the above substitution, to get
04091903180520050013012008.
Next, you chop this number into blocks of length # − 1 = 4, namely
m1 = 0409, m2 = 1903, m3 = 1805, m4 = 2005, m5 = 0013, m6 = 0120, m7 = 0800
(pad m7 with extra zeros to ensure all blocks are the same length). Now you compute the remainder ri
of each mei modulo n, write each ri as a 5-digit number (padding the front with 0’s if necessary), and
concatenate everything into a long string, which gets sent to Amazon. The computations are
040911 ≡ 20557
1903
11
1805
11
2005
11
0013
11
0120
11
0800
11
(mod 28907),
≡ 21779
(mod 28907),
≡ 04448
(mod 28907),
≡ 11232
(mod 28907),
≡ 06299
(mod 28907),
≡ 20166
(mod 28907),
≡ 11558
(mod 28907),
so the remainders are
r1 = 20557, r2 = 21779, r3 = 06299, r4 = 04448, r5 = 20166, r6 = 11232, r7 = 11558.
The string sent to Amazon is
20557217790629904448201661123211558.
To summarize the encryption process φE of a string M, using n and e:
1. Convert M into a numbers in the usual way.
2. Break the result into blocks mi of length # − 1 (pad the end of the last block with 0’s).
3. Compute the remainder ri of each mei modulo n.
4. Consider each ri as having length # (pad the front of each ri with 0’s).
5. Concatenate the ri to obtain φE (M).
Any third party who knows n and e and intercepts φE (M) will trouble decrypting the message because
modular exponentiation (step 3) is not easy to invert in general. But the situation is not general, and only
Amazon knows why!
RSA Decryption
Only Amazon knows the prime factorization of n, which is 28907 = 137 · 211. Amazon chose e = 11 to
be relatively prime to (137 − 1) · (211 − 1) = 28560. Thus Amazon can use the Euclidean algorithm with
substitution to find a linear combination of 11 and 28560 that equals 1:
28560 = 11 · 2596 + 4
11 = 4 · 2 + 3
4=3·1+1
3 = 1 · 3 + 0,
23
so that
1 = 4 − 3 = 4 − (11 − 4 · 2) = 4 · 3 − 11 = (28560 − 11 · 2596) · 3 − 11 = 3 · 28560 − 7789 · 11.
Thus −7789 is a multiplicative inverse of 11 modulo 28560, and so is −7789 + 28560 = 20771. Set d = 20771;
this is the magic number that will allow Amazon to decrypt the message!
Now Amazon breaks φE (M) into blocks ri of length #, and simply computes the remainders si of each
mdi modulo n, considering each as an (# − 1)-digit number. Thus to decrypt the string Amazon received in
the previous example, Amazon computes
2055720771 ≡ 0409
20771
21779
20771
06299
20771
04448
20771
20166
20771
11232
20771
11558
(mod 28907),
≡ 1903
(mod 28907),
≡ 2005
(mod 28907),
≡ 0120
(mod 28907),
≡ 1805
(mod 28907),
≡ 0013
(mod 28907),
≡ 0800
(mod 28907),
namely
s1 = 0409, s2 = 1903, s3 = 1805, s4 = 2005, s5 = 0013, s6 = 0120, s7 = 0800.
Finally, Amazon concatenates all the si to obtain
0409190318052005001301200800,
and then converts this back into letters by the usual substitution, ending with the original message:
DISCRETE MATH .
To summarize the decryption process φD of an encrypted string φE (M) using d, a multiplicative inverse
of e modulo (p1 − 1)(p2 − 1), where n = p1 p2 is the prime factorization of n:
1. Break φE (M) into blocks ri of length #.
2. Compute the remainder si of each rid modulo n.
3. Think of si as an (# − 1)-digit number (in fact, si = mi !)
4. Convert the mi into letters in the usual way.
5. Concatenate the results to obtain φD (φE (M)).
As in the example, φD (φE (M)) = M, as we will prove next time!
In practice, Amazon chooses two extremely large distinct prime numbers p1 and p2 (at least 200 digits
each) and picks e to be some positive integer relatively prime to (p1 − 1)(p2 − 1). Amazon publishes n = p1 p2
and e, and keeps the two prime factors of n secret. The number n is so large that there is no hope of
finding its prime factors! Decryption relies on computing d, which cannot be done without knowing the
prime factors, so a snooping third party that knows only n, e, and an encrypted message can’t decrypt the
message.
Lecture 16, 10/18 (Section 4.6)
Why RSA Decryption Works
Why does RSA decryption recover the original message? The key step in encryption is to encrypt a block
m by finding the remainder r of me modulo n, and the key step in decryption is to compute the remainder
s of rd modulo n. Thus
s ≡ rd ≡ (me )d ≡ med (mod n),
so RSA will recover the original block if s ≡ m (mod n). Thus we want to prove the theorem:
24
Theorem 26 (RSA decryption works). Let p1 , p2 be distinct primes, let e ∈ Z>0 satisfy gcd(e, (p1 − 1)(p2 −
1)) = 1, and let d ∈ Z>0 be a multiplicative inverse of e modulo (p1 − 1)(p2 − 1). Then
med ≡ m
(mod p1 p2 )
for any m ∈ Z.
The challenge in proving the theorem is that the modulus p1 p2 is a product of primes, whereas we are
best at working modulo a prime, when we can use powerful tools like FLT. We want to prove that med is a
solution of the congruence x ≡ m (mod p1 p2 ), and we do this as follows.
Proof. We break the proof into three steps.
Step 1: Split the congruence x ≡ m (mod p1 p2 ) into the system of two congruences
x≡m
x≡m
(mod p1 )
(mod p2 ).
We say an integer is a solution of the system if it satisfies both congruences.
Step 2: Show that any solution of the system must also be a solution of the original congruence.
Step 3: Show that med is a solution of the system.
Step 1 does not require any work, so we begin by showing Step 2. Suppose a is a solution of the system.
Then any a + kp1 p2 is also a solution of the system, since the term kp1 p2 is congruent to 0 modulo p1 and
modulo p2 . Thus the remainder r of a modulo p1 p2 is a solution of the system. Note that 0 ≤ r < p1 p2 .
The system also has the obvious solution m, and by the same argument the remainder s of m modulo p1 p2
is also a solution of the system, and 0 ≤ s < p1 p2 . But by the Chinese Remainder Theorem (abbreviated
CRT), which I will state in a moment, the system has a unique solution in the interval 0 ≤ x < p1 p2 , thus
we must have r = s. But this implies
a≡r=s≡m
(mod p1 p2 ),
so a satisfies the original congruence, as claimed.
Here is the statement of the mighty CRT, which I will prove after completing Step 3.
Theorem 27 (Chinese Remainder Theorem, abbreviated CRT). Let p1 , p2 be distinct primes, and let a1 , a2 ∈
Z. Then the system of congruences
x ≡ a1
x ≡ a2
(mod p1 ),
(mod p2 )
has a unique solution in the interval 0 ≤ x < p1 p2 .
To finish the proof that RSA decryption works, we now complete Step 3, namely we must show that med ≡
m (mod p1 ) and med ≡ m (mod p2 ). The argument is the same for each congruence up to interchanging
the roles of p1 and p2 , so we will only prove that med ≡ m (mod p1 ). An easy case is when p1 | m, in which
case m ≡ 0 (mod p1 ), so med ≡ 0 ≡ m (mod p1 ) is what we are trying to show. So assume p1 " m, which
will allow us to use FLT. We will now finally use the properties of e and d. Since d is a multiplicative inverse
of e modulo (p1 − 1)(p2 − 1), ed ≡ 1 (mod (p1 − 1)(p2 − 1)), namely de = 1 + k(p1 − 1)(p2 − 1) for some
k ∈ Z. Thus by FLT,
med = m1+k(p1 −1)(p2 −1) = m · (mp1 −1 )
k(p2 −1)
so we are done.
25
≡ m · 1k(p2 −1) = m (mod p1 ),
Chinese Remainder Theorem
To prove the CRT, stated above, we need an easy lemma. Remember the exercise asking for a counterexample
to the claim that if a, b, d ∈ Z with d | ab, then d | a or d | b? (For instance, take a = 2, b = 3, d = 6.) The
claim does hold if d is prime:
Lemma 2. Let a, b, p ∈ Z with p prime, and suppose p | ab. Then p | a or p | b.
Proof. Suppose p " a. Then gcd(p, a) = 1, so by Theorem 20, there are r, s ∈ Z such that rp + sa = 1.
Multiplying both sides by b, we get rpb + sab = b. Since p | ab by assumption, p | sab, and also p | rpb, thus
p | (rpb + sab) = b, which completes the proof.
Proof of the CRT. Since p1 and p2 are distinct primes, gcd(p1 , p2 ) = 1, so there exist r1 , r2 ∈ Z such that
r1 p1 + r2 p2 = 1 (Euclidean algorithm with substitution; see Theorem 20). Then x = a1 r2 p2 + a2 r1 p1 is
a solution to the system of congruences, and finding the remainder modulo p1 p2 gives a solution in the
interval 0 ≤ x < p1 p2 . To see that the solution is unique, suppose that 0 ≤ x, y < p1 p2 are two solutions.
Then x ≡ a1 ≡ y (mod p1 ) and x ≡ a2 ≡ y (mod p2 ), so there are k1 , k2 ∈ Z such that x = y + k1 p1 and
x = y + k2 p2 . Thus k1 p1 = k2 p2 , so p1 | k2 p2 . Since p1 " p2 , the lemma implies p1 | k2 , namely there
is some l ∈ Z such that k2 = lp1 . Thus x = y + lp1 p2 , so x ≡ y (mod p1 p2 ), which implies x = y since
0 ≤ x, y < p1 p2 .
26
Week 9: Proof by Induction
Lecture 17, 10/23 (Section 5.1)
Introduction to Induction
Have you ever set up a domino rally? You place dominoes upright in a line, then knock over the first
domino, which knocks over the second, which knocks over the third, and so on. Keep this image in mind
while learning about mathematical induction, because the basic idea of induction is that of the domino rally.
Mathematical induction is a powerful technique for proving a propositional function is true for all
positive (or nonnegative) integers. Here is a typical proof by induction:
Theorem 28. Let n ∈ Z>0 . The sum of the first n odd positive integers is n2 .
Proof. Induction on n. For the base case n = 1, we simply note that 1 = 12 . Now suppose the theorem is
true for some n = k ∈ Z>0 . Then
1 + 3 + · · · + (2k − 3) + (2k − 1) = k 2
by assumption. Adding 2k + 1 to both sides, we get
1 + 3 + · · · + (2k − 3) + (2k − 1) + (2k + 1) = k 2 + (2k + 1) = (k + 1)2 ,
which shows that the theorem is true for n = k + 1. Thus we are done by induction.
Why did the previous argument prove the theorem? Consider the propositional function “the sum of the
first n odd positive integers is n2 ”, which we denote P (n). The theorem is stating that P (n) is true for all
n ∈ Z>0 . To prove this, we argue as follows:
(1) Prove the “base case” P (1). (Knock over the first domino.)
(2) Prove that P (k) implies P (k + 1) for arbitrary k ∈ Z>0 . (Show that a falling domino knocks over the
next domino.)
These two steps prove the theorem because (1) establishes P (1), while (2) establishes the chain of implications
P (1) =⇒ P (2) =⇒ P (3) =⇒ P (4) =⇒ · · · .
Since P (1) is true, so is P (2). Since P (2) is true, so is P (3). And so on. Each falling domino knocks over
the next domino in line, so all of the infinitely many dominoes get knocked over.
Remark. Note that we do not use the P (n) notation when writing a proof! Instead of writing P (k), for
instance, we refer to the theorem being true for n = k, as in the proof of Theorem 28 above.
Lecture 18, 10/25 (More Section 5.1)
More Induction
Let’s try another proof by induction.
27
Theorem 29. Let n ∈ Z>0 . Then
1 + 2 + ··· + n =
n(n + 1)
.
2
Proof. Induction on n. For the base case n = 1, note that 1 = 1(1+1)
. Now suppose the theorem is true for
2
some n = k ∈ Z>0 . Thus
k(k + 1)
1 + 2 + ··· + k =
.
2
Adding k + 1 to both sides, we get
1 + 2 + · · · + k + (k + 1) =
k(k + 1)
k 2 + k + 2k + 2
(k + 1)(k + 2)
+ (k + 1) =
=
,
2
2
2
so the theorem is true for n = k + 1. So we are done by induction.
Here’s another less abstract proof by induction.
Theorem. In any set S of horses, all the horses are the same color.
Proof. Proof by induction on n, the number of horses in S. The base case n = 1 holds since there is only
one horse in the set. Now suppose that for some k ∈ Z>0 , any set of k horses has all horses the same color.
Given a set S of k + 1 horses, pick two different subsets A1 , A2 of S with k horses each. By assumption, all
the horses of A1 are the same color and all the horses of A2 are the same color. But the intersection A ∩ B
contains k − 1 horses, hence the color of the horses in A is the same as the color of the horses in B. By
induction, we have proved the theorem.
Wait, what did we just prove?! Analyze the proof carefully and try to find an error. Hint: there is a gap
in the proof that P (k) =⇒ P (k + 1) when k = 1. The above theorem is a flawed proof by induction: don’t
write proofs like this!
Thus the base case holds, but the rest of the proof falls apart! The first domino gets knocked over, but
the falling first domino fails to knock over the second domino, so no other dominoes fall. Note that a small
mistake in one case of this proof by induction is the difference between the theorem being true for all n ≥ 2
and being false for all n ≥ 2. So we must be careful when trying to prove a theorem by induction!
28
Week 10: More Induction, Intro to
Combinatorics
Lecture 19, 10/30 (Section 5.2)
Strong Induction and the FTA
Our goal today is to prove the theorem
Theorem (Fundamental theorem of arithmetic). Let n ∈ Z>1 . Then
(a) n can be written as a product of primes n = p1 p2 · · · pr ;
(b) this prime factorization is unique if we insist that p1 ≤ p2 ≤ · · · ≤ pr .
For the proof of (a), we will use a slightly different version of induction, called strong induction, which
is logically equivalent to induction, but sometimes makes a proof easier. The two steps for using strong
induction are:
(1) Prove the “base case” P (1). (Knock over the first domino.)
(2) For arbitrary k ∈ Z>0 , prove that P (i) for all i ≤ k implies P (k + 1). (Show that if all the dominoes up
to a certain point have fallen over, then the next one gets knocked over.)
Here is how we can use strong induction to prove (a):
Proof of (a). Strong induction on n. For the base case n = 2, note that 2 is prime, hence factors uniquely
into primes as 2 = 2. Now assume that for some k ∈ Z>1 , any integer i in the range 2 ≤ i ≤ k can be written
as a product of primes. Then either k + 1 is prime, in which case k + 1 = k + 1 is a prime factorization, or
k + 1 is composite, in which case it has a divisor d in the interval 2 ≤ d ≤ k. Since d | k + 1, there is an
e ∈ Z such that k + 1 = de, and the bounds on d imply that 2 ≤ e ≤ k. Thus by assumption, d = p1 · · · ps
and e = ps+1 · · · pr , so combining these factorizations yields k + 1 = de = p1 · · · ps ps+1 · · · pr . By strong
induction, I have proved that every n ∈ Z>1 has a prime factorization.
For the proof of (b), I need a pair of lemmas. The first is a repeat of Lemma 2 above:
Lemma. Let a, b, p ∈ Z with p prime, and suppose p | ab. Then p | a or p | b.
Proof. Suppose p " a. Then gcd(p, a) = 1, so by Theorem 20, there are r, s ∈ Z such that rp + sa = 1.
Multiplying both sides by b, we get rpb + sab = b. Since p | ab by assumption, p | sab, and also p | rpb, thus
p | (rpb + sab) = b, which completes the proof.
With this, we can prove the stronger result:
Lemma 3. If p is prime and p | a1 a2 · · · an where each ai ∈ Z, then p | ai for some i.
Proof. Induction on n. For the base case n = 1, p | a1 implies p | a1 . Now suppose the lemma is true
for some k ∈ Z≥1 . Then if p | a1 a2 · · · ak ak+1 , we can write this as p | (a1 a2 · · · ak )(ak ), a product of two
integers. By the previous lemma, we see that p | ak or p | a1 a2 · · · ak ; in the latter case our assumption
ensures that p | ai for some 1 ≤ i ≤ k. Either way, p | ai for some i, so we are done by induction.
29
Now I am ready to prove the uniqueness claim (b) of the FTA.
Proof of (b). To see that a prime factorization n = p1 p2 · · · pr is unique when we insist that p1 ≤ p2 ≤ · · · ≤
pr , suppose for contradiction that there is a different prime factorization n = q1 q2 · · · qs with q1 ≤ q2 ≤ · · · ≤
qs . Removing prime factors that appear in both factorizations, the leftover primes give an equation
p i 1 pi 2 · · · p i u = q j 1 q j 2 · · · q j v ,
where no prime appears on both sides. But pi1 divides the left side, hence also the right side, so by Lemma
3, pi1 | qjl for some l, hence pi1 = qjl since qjl is prime, which is a contradiction.
Lecture 20, 11/01 (Section 6.1)
Basic Counting
Let’s start with a very easy counting problem.
Example. Suppose you have 7 candy bars and 11 lollipops. In how many ways can you choose one piece of
candy?
Solution: You can choose either a candy bar or a lollipop. Since there are 7 candy bars and 11 lollipops,
you have 7 + 11 = 18 different choices of a piece of candy.
The simple principle at work here is the following:
Theorem 30 (Sum rule). If a task can be done either in one of n1 ways or in one of n2 ways, where none
of the set of n1 ways is the same as any of the set of n2 ways, then there are n1 + n2 ways to do the task.
Here’s a trickier kind of problem.
Example. Now suppose you have 3 pointy hats, 2 bloody shirts, 1 coal-black pair of pants, and 3 ghoulinfested pairs of socks. How many different costumes of 1 hat, 1 shirt, 1 pair of pants, and 1 pair of socks
can you make?
Solution: Draw a tree diagram. Starting with a point (the root of the tree), draw 3 branches, one for
each choice of hat. From the end of each hat branch, draw 2 branches, one for each type of shirt. From the
end of each shirt branch, draw 1 branch, since there is only one choice of pants. Now for each pants branch,
draw 3 branches, one for each pair of socks. Each path from the root of the tree to the end of a socks branch
corresponds to a costume. Counting the branches, there are a total of 3 · 2 · 1 · 3 = 18 different costumes.
We can formalize this method of drawing a tree diagram to obtain:
Theorem 31 (Product rule). Suppose a procedure consists of independent tasks T1 , . . . , Tr . Suppose there
are ni ways of doing the task Ti for each 1 ≤ i ≤ r. Then there are n1 n2 · · · nr ways to do the procedure.
Remark. The word “independent” means that the number of ways of doing task Ti does not depend on
which way the other tasks are being done. For instance, in the example, the number of ways to pick a shirt
did not depend on the hat that was chosen.
Now I’ll give some more examples.
Example. How many different 6-letter “words” are possible? (By “word” I mean any string of 6 letters.)
Solution: Think of choosing a word as a procedure with 6 tasks T1 , T2 , . . . , T6 , where each Ti is the task
of choosing the ith letter of the word. Since there are 26 letters, there are 26 ways to do each Ti , thus by
the product rule there are 266 6-letter words. That’s over 300 million possibilities! Of course most of these,
like “orltkq”, are not (yet!) words in the English language.
Here’s a related, but more abstract, example.
30
Example. How many functions are there from a set A = {a1 , a2 , a3 } with three elements to a set B =
{b1 , b2 , b3 , b4 } with four elements?
f
! B , we need to specify an image for each ai . Think of this as a
Solution: To define a function A
procedure with three tasks T1 , T2 , T3 , where each Ti is the task of specifying an image for ai . Then there are
4 ways of doing each Ti since there are 4 elements in B. Thus by the product rule, the number of functions
A
f
! B is 4 · 4 · 4 = 64.
Here’s a slight modification of the previous example.
Example. How many injective (one-to-one) functions are there from A = {a1 , a2 , a3 } to B = {b1 , b2 , b3 , b4 }?
f
! B , we need to specify an image for each ai ∈ A, and
Solution: To define an injective function A
none of these images can be the same. As before, let Ti be the task of specifying an image for ai , and think
of doing T1 , then T2 , and then T3 . Then there are 4 ways to do T1 , but only 3 ways to do T2 , because a2
can’t map to the image you chose for T1 . Similarly, there are only 2 ways to do T3 , because you cannot map
a3 to the images of a1 or a2 . Thus by the product rule, the number of injective functions is 4 · 3 · 2 = 24.
Remark. Note that in the previous example, the choice of image for a1 did affect the possible images for
a2 . For instance, if a1 1→ b1 , then a2 can only map to b2 , b3 , or b4 , whereas if a1 1→ b2 , then a2 can only map
to b1 , b3 , or b4 . But the crucial point is that the number of ways of choosing an image of a2 is 3, regardless
of which image for a1 you chose. Thus the tasks of choosing the images for the ai are independent, allowing
us to use the product rule.
31
Week 11: Combinatorics
Lecture 21, 11/6 (Section 6.3)
Permutations
Definition 28. An r-permutation of a set S is a sequence of r distinct elements of S.
Example. The 1-permutations of {a, b, c} are (a), (b), and (c). The 2-permutations are (a, b), (b, a), (a, c),
(c, a), (b, c), (c, b). The 3-permutations are (a, b, c), (a, c, b), (b, a, c), (b, c, a), (c, a, b), (c, b, a). There is
exactly one 0-permutation of {a, b, c}, namely the empty sequence (), and there are no 4-permutations.
Remark. Note that we write permutations in parentheses since they are sequences, not sets. In particular,
the order in which the elements of a sequence are listed is important, whereas the order in which the elements
of a set are written is irrelevant.
How many r-permutations of a set S of n elements are there? Equivalently, we want to count the number
of ways to do the procedure
! Procedure: choose a sequence of r elements of S.
(How many ways?)
To count the ways, we break up the procedure into r tasks:
• T 1: choose the first element of the sequence.
(n ways)
• T 2: choose the second element of the sequence.
(n − 1 ways)
..
.
• T r: choose the rth element of the sequence.
(n − r + 1 ways)
Thus by the product rule, we get
Theorem 32. Let n, r ∈ Z≥0 with r ≤ n. Then the number of r-permutations of a set with n elements is
P (n, r) = n(n − 1)(n − 2) · · · (n − r + 1).
A useful way to express this product is using factorial notation.
Definition 29. Let n ∈ Z>0 . Then define n factorial, written n!, to be the product n! := n(n−1)(n−2) · · · 1.
It is also convenient to define 0! := 1.
Example. 0! = 1, 1! = 1, 2! = 2, 3! = 6, 4! = 24, 5! = 120, 6! = 720, 7! = 5040, 10! = 3628800.
With this notation we get:
Corollary 2. Let n, r ∈ Z≥0 with r ≤ n. Then P (n, r) =
n!
(n−r)! .
Remark. Note that P (n, n) = n!. That is, the number of ways to order all n elements of a set is n!.
32
Combinations
Suppose now that we don’t care about the order in which choices are made.
Example. What are the possible 3-person teams in a group of 5 people? Equivalently, what are the 3element subsets of a set with 5 elements, say {a, b, c, d, e}? The 10 possibilities are
{a, b, c}, {a, b, d}, {a, b, e}, {a, c, d}, {a, c, e}, {a, d, e}, {b, c, d}, {b, c, e}, {b, d, e}, {c, d, e}.
Definition 30. An r-combination of a set S is an r-element subset of S.
How many r-combinations of a set S of n elements are there? We can deduce this from our study
of permutations. The only difference between an r-permutation and an r-combination is that in an rpermutation, the chosen elements are given an order. This observation inspires the following analysis:
! Procedure: choose an r-permutation of S.
(P (n, r) ways)
Now we cleverly break up the procedure into 2 tasks:
• T 1: choose an r-combination of S.
(How many ways?)
• T 2: choose an order for the r-combination, namely an r-permutation of the r-combination. (P (r, r)
ways)
Thus, by the product rule, the number C(n, r) (which we read as “n choose r”) of r-combinations satisfies
P (n, r) = C(n, r) · P (r, r).
Solving for C(n, r), we get
C(n, r) =
P (n, r)
n!/(n − r)!
n!
=
=
.
P (r, r)
r!
(n − r)! r!
Thus we have proved:
Theorem 33. Let n, r ∈ Z≥0 and r ≤ n. Then the number of r-combinations of a set with n elements is
C(n, r) =
n!
.
(n − r)! r!
Example. Returning to the previous example, the number of 3-person teams in a group of 5 people is
C(5, 3) =
5!
= 10,
(5 − 3)! 3!
which agrees with the list we compiled.
Example. How many distinct 5-card hands are possible in a deck of 52 cards? Simply compute:
C(52, 5) =
52!
52 · 51 · 50 · 49 · 48
=
= 52 · 51 · 10 · 49 · 2 = 2598960.
47! 5!
5·4·3·2·1
Example. How many 5-card hands are a flush (have all 5 cards of the same suit)? Think of choosing a
flush! as
" a procedure consisting of two tasks: first choose a suit, then choose 5 cards from that suit. There
are 41 ways to choose a suit, and C(13, 5) ways to choose 5 cards from that suit, so by the product rule the
number of flush hands is
( ) ( )
4
13
13!
13 · 12 · 11 · 10 · 9
·
=4·
=4·
= 13 · 12 · 11 · 3 = 5148.
1
5
8! 5!
5·4·3·2·1
An easy corollary of the theorem is
Corollary 3. C(n, r) = C(n − r, r).
This is intuitive because choosing a subset of r elements of a set n is equivalent to choosing the n − r
elements to leave out of the subset.
33
Lecture 22, 11/8 (Section 6.4)
Binomial Theorem
The binomial theorem is a formula for expanding powers of the form (x + y)n . As we will see, the formula
is intimately related to combinations.
Definition 31. A binomial is the sum of two terms, for instance x + y.
We want to study powers of the binomial x + y. The first few of these are
(x + y)1 = x + y,
(x + y)2 = x2 + 2xy + y 2 ,
(x + y)4 = x4 + 4x3 y + 6x2 y 2 + 4xy 3 + y 4 ,
(x + y)3 = x3 + 3x2 y + 3xy 2 + y 3 ,
(x + y)5 = x5 + 5x4 y + 10x3 y 2 + 10x2 y 3 + 5xy 4 + y 5 .
Let’s try to find a general formula for (x + y)n . Expand the power (x + y)n as a product of n factors
(x + y)(x + y) · · · (x + y).
If we multiply this out without grouping like terms, then every term arises from a choice of either x or y in
each factor of x + y. For example, for (x + y)(x + y), choosing x in both factors yields x2 , choosing x in the
first and y in the second yields xy, choosing y in the first and x in the second yields yx (which is the same as
xy), and choosing y in both yields y 2 . Note that we got xy twice, because there were two ways of choosing
one x and one y.
Let’s return to the product of n factors of (x + y). The possible terms are xn , xn−1 y, xn−2 y 2 , . . . , y n . We
want to count how many times each one occurs. Pick a term, say xn−j y j , and focus on the power of y of
that term. In order to get exactly the jth power of y, you have to choose y in exactly j of the n factors (all
the rest will be x), and there are C(n, j) ways to do this. For instance, when j = 0, the term is xn , and
there is only C(n, 0) = 1 way to choose y in 0 of the factors. Likewise, when j = 1, there are C(n, 1) = n
ways to choose y in just one factor.
Thus for each 0 ≤ j ≤ n, the! coefficient
of xn−j y j is C(n, j). These C(n, j) are so important that we
"
n
use a special notation for them: j . We call them binomial coefficients because in this notation, we can
write our result as:
Theorem 34 (Binomial theorem). Let x and y be variables, and n ∈ Z>0 . Then
(x + y)n =
n ( )
'
n
j=0
j
xn−j y j =
( )
( )
( )
( )
n n
n n−1
n n−2 2
n n
x +
x
y+
x
y + ··· +
y .
0
1
2
n
The binomial theorem is a fantastic way to compute powers of binomials. Check that the binomial theorem
gives the same results as the powers of x + y above! We can also compute powers of other binomials by
substituting whatever we like for x and y:
Example. Compute (x + 1)4 . We just replace y by 1 in the binomial theorem, to get
( )
( )
( )
( )
( )
4 4 0
4 3 1
4 2 2
4 1 3
4 0 4
(x + 1)4 =
x 1 +
x 1 +
x 1 +
x 1 +
x 1
0
1
2
3
4
= x4 + 4x3 + 6x2 + 4x + 1.
Example. Compute (2x − 3)4 . For this, we replace x by 2x and y by −3 in the binomial theorem. This
yields
( )
( )
( )
( )
( )
4
4
4
4
4
(2x − 3)4 =
(2x)4 (−3)0 +
(2x)3 (−3)1 +
(2x)2 (−3)2 +
(2x)1 (−3)3 +
(2x)0 (−3)4
0
1
2
3
4
= 16x4 − 96x3 + 216x2 − 216x + 81.
Setting x = y = 1 in the binomial theorem, we get an identity relating 2n to a sum of binomial coefficients:
34
Corollary 4. Let n ∈ Z>0 . Then 2n =
&n
j=0
! n"
j
.
Example. How many subsets does a set S = {a1 , . . . , an!} "with n elements have? The total number of
n
subsets is! the
" number of subsets with 0 elements, namely 0 , plus the number of subsets with 1 element,
n
which is 1 , plus the number of subsets with 2 elements, and so on. By Corollary 4, adding up all these
binomial coefficients gives 2n .
The number of subsets of S can also be computed using just the product rule. Think of choosing a subset
as a procedure, consisting of tasks T1 , . . . , Tn , where the task Ti is choosing whether or not to include ai in
the subset. There are two ways to do each Ti (either include ai or don’t), so the total number of ways to do
the procedure is 2 · 2 · · · · · 2 = 2n .
We can obtain another identity by setting x = 1 and y = −1 in the binomial theorem:
Corollary 5. Let n ∈ Z>0 . Then
0=
n
'
(−1)j
j=0
( )
n
.
j
! " ! n "
This is not surprising when n is odd because the symmetry nj = n−j
and the alternating signs will cause
all the terms to cancel in pairs. But it is an interesting identity when n is even!
Pascal’s Triangle
There is a beautiful way to generate the binomial coefficients, called Pascal’s triangle. The first row is
an infinite row of 0s with a single 1 in the middle. The second row is obtained as follows: for every pair of
adjacent entries of the first row, add the two numbers, and write the sum below the midpoint of the two
numbers, in the second row. The third row is obtained by taking sums of pairs of entries in the second row,
and so on. Here are the first 9 rows of the triangle, with the 0s omitted:
1
1
1
1
3
1
1
1
1
4
5
1
6
7
6
15
28
1
4
1
10
20
35
56
1
3
10
21
8
1
2
5
15
35
70
1
6
1
21
56
7
28
1
8
1
The amazing thing is that the numbers in Pascal’s triangle are exactly the binomial coefficients! Namely,
we can also write Pascal’s triangle as:
!0"
0
!1"
! 1"
0
1
! 2"
! 2"
! 2"
0
1
2
! 3"
! 3"
! 3"
! 3"
0
1
2
3
!4"
! 4"
! 4"
! 4"
! 4"
0
1
2
3
4
!5"
! 5"
! 5"
! 5"
! 5"
! 5"
0
1
2
3
4
5
!6"
! 6"
! 6"
! 6"
! 6"
! 6"
! 6"
0
1
2
3
4
5
6
!7"
! 7"
! 7"
! 7"
! 7"
! 7"
! 7"
! 7"
0
1
2
3
4
5
6
7
!8"
! 8"
! 8"
! 8"
! 8"
! 8"
! 8"
! 8"
! 8"
0
1
2
3
! n"
4
! n"
5
6
7
8
The reason this works is because the 0 = n = 1 for all n, so the diagonal edges of the triangle are all 1s.
Moreover, the following identity ensures that the triangle of binomial coefficients satisfies the same addition
properties as Pascal’s triangle:
35
Theorem 35 (Pascal’s identity). Let n, k ∈ Z≥0 with k ≤ n. Then
( ) (
) (
)
n
n
n+1
+
=
.
k
k+1
k+1
Computational proof. We simply find a common denominator to compute
)
( ) (
n!
n
n
n!
"
=
+
+!
k
k+1
(n − k)! k!
n − (k + 1) ! (k + 1)!
(k + 1) + (n − k)
(n − k)! (k + 1)!
n+1
= n!
(n − k)! (k + 1)!
(n + 1)!
"
=!
(n + 1) − (k + 1) ! (k + 1)!
(
)
n+1
=
.
k+1
= n!
"
!
Combinatorial proof. We can also prove the identity by finding a different way to count the n+1
k+1 subsets
of k + 1 elements of a set S = {a1 , a2 , . . . , an+1 } of n + 1 elements. First, we count the subsets with k + 1
elements that contain a1 . Since
! " a1 is in the subset, the subset must contain k of the remaining n elements
{a2 , . . . , an+1 }, so there are nk such subsets. Second, we count the subsets that do not contain
! n a"1 . Such
a subset must contain k + 1 of the remaining n elements, thus the number of such subsets is k+1 . Since
every subset! of" k +
either contains a1 or doesn’t contain a1 , the total number of subsets of k + 1
! 1n elements
"
elements is nk + k+1
, which proves the identity.
Remark. If you don’t feel like messing with factorials, Pascal’s triangle can be a painless way to find the
binomial coefficients!
We can also use Pascal’s identity to give another proof of the binomial theorem, using induction:
Theorem (Binomial theorem). Let x and y be variables, and n ∈ Z>0 . Then
( )
( )
( )
( )
n ( )
'
n n−j j
n n
n n−1
n n−2 2
n n
n
(x + y) =
x
y =
x +
x
y+
x
y + ··· +
y .
j
0
1
2
n
j=0
1
Inductive! proof
"
!of"the binomial theorem. Induction on n. For the base case n = 1, note that (x + y) =
x + y = 10 x + 11 y. Now suppose the binomial theorem holds for some k ∈ Z>0 , namely that
( )
( )
( )
( )
k k
k k−1
k k−2 2
k k
k
(x + y) =
x +
x
y+
x
y + ··· +
y .
0
1
2
k
Multiplying both sides by (x + y), we get
( )
( )
( )
( )
k k+1
k k
k k−1 2
k
(x + y)k+1 =
x
+
x y+
x
y + ··· +
xy k
0
1
2
k
( )
( )
(
)
( )
k k
k k−1 2
k
k k+1
+
x y+
x
y + ··· +
xy k +
y
.
0
1
k−1
k
! "
! "
! "
! "
We can replace k0 by k+1
and kk by k+1
0
k+1 since these binomial coefficients are all equal to 1. Moreover,
we can group each pair of like terms and apply Pascal’s identity to the sum of their coefficients, to obtain
(
)
(
)
(
)
(
)
(
)
k + 1 k+1
k+1 k
k + 1 k−1 2
k+1
k + 1 k+1
(x + y)k+1 =
x
+
x y+
x
y + ··· +
xy k +
y
.
0
1
2
k
k+1
This is the statement of the binomial theorem for n = k + 1, so we are done by induction.
36
Week 12: More Combinatorics and
Introduction to Graph Theory
Lecture 23, 11/13
Application of Combinations: 5-Card Poker Hands
What is the probability (chance, likelihood) of getting a pair (two cards of the same rank), a triple, a
quadruple, 2-pair, a full house (a pair and a triple), a flush (five cards of the same suit), a straight (five
consecutive ranks), or a straight flush in a 5-card poker hand from a standard 52-card deck? We assume the
5-card hand is completely random. Then we can calculate the probability P (H) of getting a particular kind
of hand H by counting the number N (H) of such hands and then dividing by the total number N of 5-card
hands. Namely,
N (H)
P (H) =
.
N
Note that the probability of getting a particular kind of hand will always be a real number between 0 and 1
since 0 ≤ N (H) ≤ N .
Since we are considering 5-card hands coming from a 52-card deck, the total number of hands is
( )
52
N=
= 2598960.
5
Using combinatorics, we will compute the values in the following table:
Type of Hand H
Number of Hands N (H)
Pair
1098240
Triple
54912
Quadruple
624
2-pair
Full house
Straight flush
Flush
Combinatorial Expression for N (H)
!13"!4"!12"!4"3
1296420
1
0.42257
1
3
2
1
0.02113
1
4
1
1
2
2
1
1
!13"!4"!12"!4"
1
3
1
!10"!4"5
1
!4"!13"
5108
Total
3
!13"!4"2 !11"!4"
40
10200
2
!13"!4"!12"!4"
3744
Straight
1
!13"!4"!12"!4"2
123552
1
5
!10"!4"5
1
1
2
1
−
!10"!4"
−
Now we’ll show how some of the values N (H) can be computed.
37
Probability P (H)
1
1
!10"!4"
1
1
0.00024
0.04754
0.00144
0.00002
0.00197
0.00392
0.49882
Pair
! Procedure: Choose a hand with a pair (exactly two cards of the same rank).
Choose the pair.
• T 1: Choose a rank for the pair:
!13"
ways.
! 4"
• T 2: Choose two cards of that rank: 2 ways.
1
Choose the remaining three cards.
• T 3: Choose three other ranks:
!12"
3
ways.
!4"3
• T 4: Choose one card for each of those three ranks:
1
ways.
! "!4"!12"!4"3
Thus by the product rule, N (pair) = 13
1
2
3
1 .
Note that by choosing the remaining three cards to be of different ranks, we ensure that the hand does
not have a triple or two-pair. Also, a flush is impossible since the two cards of the same rank we chose for
the pair must have different
for
the
"!10
" three remaining
! " suits. One important detail is that we chose the ranks
!12"!11
cards all at once (using 12
),
instead
of
choosing
those
ranks
one-by-one
(using
1
1 ). This is crucial,
3
1
because choosing one-by-one imposes an order on our choices that results in overcounting.
2-pair
! Procedure: Choose a hand with two pairs.
First, choose the two pairs:
• T 1: Choose two ranks for the two pairs:
!13"
2
• T 2: Choose two cards of each of those ranks:
Then choose the last card:
• T 3: Choose one other rank:
ways.
!4"2
2
ways.
!11"
ways.
!"
• T 4: Choose one card of that rank: 41 ways.
1
! "!4"2 !11"!4"
So by the product rule, N (2-pair) = 13
1
1 .
2
2
Once again, it is crucial that we choose the ranks of the pairs at once, otherwise we would be imposing
an unwanted order on the two pairs that would result in overcounting.
Straight flush
! Procedure: Choose a hand with a straight flush.
The trick is that the ranks occurring in the straight are determined by the highest rank, which can be 5, 6,
7, 8, 9, 10, J, Q, K, A. (We allow the straight A 2 3 4 5.)
! "
• T 1: Choose the highest card of the straight: 10
1 ways.
!4"
• T 2: Choose the suit: 1 ways.
! "!4"
So N (straight flush) = 10
1
1 .
38
Flush
! Procedure: Choose a hand with a flush.
First, we count how many hands have a flush.
!"
• T 1: Choose the suit for the flush: 41 ways.
! "
• T 2: Choose 5 cards of that suit: 13
5 ways.
!10"!4"
We also have to exclude the number 1 1 of straight flushes, since those count as a straight flush rather
than just a flush. Thus
( )( ) ( )( )
4 13
10 4
N (flush) =
−
.
1
5
1
1
The rest
Compute combinatorial expressions for the remaining special hands yourself! Write down tasks and use the
product rule! You can check your answers in the table above.
Getting nothing
How many hands are not one of the above special hands? We can simply take the total number of hands
and subtract the number of special hands:
N (nothing) = 2598960 − 1296420 = 1302540.
Another way to compute N (nothing) is as follows. The main idea is that to get nothing, the ranks of the
five cards have to be different. The only special hands with all ranks different are the flushes, straights, and
straight flushes, so we just have to subtract the numbers of those from the number of hands with five cards
of different ranks. Thus we get
( )( )5
13 4
N (nothing) =
− N (flush) − N (straight) − N (straight flush) = 1302540,
5
1
as before.
Lecture 24, 11/15
Introduction to Graph Theory
Let’s start a brand new topic, called graph theory! The kinds of graphs studied in graph theory are
completely different from graphs of functions; instead, a graph is a collection of points in the plane, called
vertices, with some lines drawn between them, called edges. Here are two examples:
•
•
•
•
•
•
•
•
•
•
•
•
•
In a graph:
39
We care about
We don’t care about
The number of vertices.
How the vertices are placed in the plane.
The number of edges.
How the edges are drawn.
Which vertices are connected by which edges.
Edge crossings at points that are not vertices.
Thus we consider the following three graphs to be the same:
•
Same:
•
•
•
•
•
•
•
•
Graphs may have multiple edges between two vertices, as well as loops, which are edges that are connected
to only one vertex. For example:
•
•
•
•
•
•
We want to study the properties of graphs rigorously and prove things about them. For this we need to
formulate a more careful definition of what a graph is. The goal of our new definition is to capture the
information we care about, while ignoring the data we don’t care about.
A More Rigorous Definition of Graph
A common theme in pure mathematics is the following: in order to study a geometric object, it is useful
to define its structure abstractly. For instance, above we couldn’t precisely define what it should mean for
graphs to be the “same”, but we will be able to do this with our new definition.
Definition 32. A (finite, undirected) graph G = (VG , EG , φG ) consists of a set VG , whose elements are
φ
! ΣG , where ΣG is the
called vertices, a set EG , whose elements are called edges, and a function EG
set of all one or two element subsets of VG , which assigns one or two vertices, called endpoints, to each
edge. We say an edge is incident to its endpoints. If φG (e) = {v, w}, we say e connects the vertices v and
w. If φG (e) is a single vertex, then we call e a loop. The degree deg(v) of a vertex v is the number of edges
incident to it, with loops counted twice.
Note that this definition captures the data in the “We care about” column of the above table, while
throwing out what “We don’t care about”.
Remark. We sometimes write V, E, φ, Σ instead of VG , EG , φG , ΣG when it is clear which graph G is being
discussed.
Example. Let G be the graph with VG = {u, v, w}, EG = {e, f }, and the map EG
e 1→ {u, v}, f 1→ {v, w}. We have deg(u) = 1, deg(v) = 2, and deg(w) = 1.
Example. Let H be the graph with VH = {x}, EH = {c, d}, and the map EH
c 1→ {x}, d 1→ {x}. For this graph, deg(x) = 4, since loops are counted twice.
φG
φH
! ΣG defined by
! ΣH defined by
This definition of graph is terribly abstract, but there is an easy procedure to recover the geometric
picture:
Definition 33. A drawing of a graph is obtained by:
• Drawing each vertex as a point in the plane.
• Drawing each edge as a line connecting its endpoints.
40
Example. One way to draw the graph G from the example above is
•
•
•
One way to draw H is
•
There are many ways to draw a graph, but fortunately:
Remark. Any two drawings of a graph are the “same”, in terms of the criteria in the table above. In other
words, any two drawings of a given graph differ only in where the vertices are drawn in the plane and how
the edges are drawn.
Forging a Correspondence Between Graphs and Drawings
Intuitively, we want to think about graphs in terms of their drawings, without explicitly thinking about the
sets VG and EG and the function φG . To justify this, we need to think hard about the connection between
the abstract definition of a graph and the data inherent in a drawing of a graph. Because any two drawings
of a graph are the “same”, we get a function
{graphs}
draw the graph
! {drawings up to “sameness”}.
(Recall that a function maps each element of the domain to exactly one element of the codomain. Thus to
get a function, we need a “unique” way of drawing the graph, which we have because any two drawings of
a graph are the “same”.)
Our goal is to get a function going the other direction, ideally an inverse of the “draw the graph” function.
How can we get a graph from a drawing?
Remark. Given a drawing of a graph, we can define sets V and E and a function φ. For instance, we can
choose a labeling of vertices and edges
v1
•
e1
v2
•
e2
v3
•
and then write V = {v1 , v2 , v3 } and E = {e1 , e2 } and define E
{v2 , v3 }.
φ
! Σ by φ(e1 ) = {v1 , v2 } and φ(e2 ) =
So we have a way of going from a drawing to a graph. Unfortunately, this will not give us the function
we want, because there are many, many ways to choose labels for a given drawing. The problem isn’t in our
way of labeling a drawing, but rather in our definition of graph, which has too much information. In order
to define a graph, you have to choose a set of vertices and a set of edges, which forces you to choose names
for your vertices and edges.
Should the exact labeling be so important? Mathematically, no! When studying graphs, we care mostly
about the relative arrangement of vertices and edges, and much less about the exact labels chosen. Unfortunately, the natural definition of “sameness” for graphs is:
Definition 34. Two graphs G = (VG , EG , φG ) and H = (VH , EH , φH ) are equal if VG = VH , EG = EH ,
and φG = φH .
Equality of graphs is too strict, because if the names of the elements in VG and VH are different, then
VG =
# VH . So we need a different notion of when graphs are the “same”.
Graph Isomorphism
Here is the notion of “sameness” for graphs that we want. It is constructed exactly so that different labelings
of the same drawing can be considered the “same”.
Definition 35. An isomorphism of two graphs G = (VG , EG , φG ) and H = (VH , EH , φH ) is a pair of
ν !
# !
bijections VG
VH and EG
EH such for that all e ∈ EG , φH ($(e)) = {ν(v1 ), ν(v2 )}, where
φG (e) = {v1 , v2 }.
41
What the last condition means is that for each edge e of G, with endpoints {v1 , v2 }, the endpoints of the
corresponding edge $(e) in H are {ν(v1 ), ν(v2 )}. In other words, the bijection of the edges is “compatible”
with the bijection of the vertices with regard to how edges connect vertices.
Definition 36. Two graphs are isomorphic if there is an isomorphism between them.
Example. Let’s show that the graphs corresponding to any two labelings
v1
•
e1
•
v2
w1
f1
e2
•
e3
•
•
v3
f2
f3
w2
•
w3
are isomorphic. Let φ1 denote the map from the edges of the left graph to their endpoints, and let φ2 be
the corresponding map for the right graph. The most obvious isomorphism is given by
ν(v1 ) = w1 , ν(v2 ) = w2 , ν(v3 ) = w3
$(e1 ) = f1 , $(e2 ) = f2 , $(e3 ) = f3 .
Since φ1 (e1 ) = {v1 , v2 } and φ2 (f1 ) = {w1 , w2 }, we see that φ2 ($(e1 )) = {w1 , w2 } = {ν(v1 ), ν(v2 )}, so the
isomorphism condition holds for e1 . Checking the condition for e2 and e3 is similar.
This is only one possible isomorphism for these two graphs. In fact, there are six such isomorphisms.
Can you see why? (Hint: the isomorphism is determined by the map ν on the vertices.)
As the example shows, it is very tedious to explicitly write down isomorphisms and check all the conditions. Fortunately, the following theorem (which is obvious if you understand the definitions!) guarantees
that we need not worry about which labeling we choose for a given drawing. Moreover, isomorphic graphs
have the same drawings.
Theorem 36. Any two graphs obtained by labeling a given drawing are isomorphic. Any two drawings of
two isomorphic graphs are the “same”.
Thus we finally get our map in the opposite direction:
{graphs up to isomorphism} "
draw the graph
!
label the drawing
{drawings up to “sameness”}.
(We get a function “label the drawing” because any drawing gives us a unique graph when we consider
isomorphic graphs to be the same.)
In fact,
Theorem 37. The maps “draw the graph” and “label the drawing” are inverses, and thus give a bijection
between the set of graphs up to isomorphism and the set of drawings up to “sameness”.
Remark. From now on, we will always consider graphs to be the “same” if they are isomorphic. Thus
the previous theorem allows us to refer to drawings of graphs as graphs, since each drawing of a graph
corresponds naturally to a unique graph. Conversely, we can always think about a graph in terms of a
drawing. The bijection also allows us to use the rigorous language of graph isomorphism, which is defined
very precisely above, instead of referring to our fuzzy notion of “sameness” of drawings.
We’ll end the section with few more examples of isomorphic graphs.
Example. The following two graphs are isomorphic:
•
•
•
•
•
•
•
•
42
Think about which bijections of the sets of vertices could give an isomorphism. Note that the bijection of
the vertices in a graph isomorphism determines the bijection of the edges (to see where to map an edge, look
at where its endpoints are being mapped!).
Another pair of isomorphic graphs is
•
•
•
•
•
•
•
•
•
•
Which bijections of the sets of vertices can give the isomorphism?
Remark. As in the example, we like to think of graphs visually in terms of their drawings. But the abstract
definition is still crucially important because it is the foundation for rigorous proofs. We will prove plenty
of things about graphs in the coming weeks, and you will see how important it is to have set descriptions of
the vertices and edges of graphs.
43
Week 13: Graph Theory
Lecture 25, 11/20
Whenever you see a new definition in mathematics, try to write down examples! This both forces you to
think about each part of the definition and also gives you something to visualize when the definitions start
to pile up (which they always do!).
Definition 37. A subgraph of a graph G = (VG , EG , φG ) is a graph H = (VH , EH , φH ) such that VH ⊆ VG ,
φG
EH ⊆ EG , and φH is the restriction of the function EG
! ΣG to the domain EH and codomain ΣH .
Example. Six of the subgraphs of
v1
•
e1
G=
•
e2
•
e3
v2
v3
are
v1
e1
H1 =
•
•
e2
v1
•
e1
H2 =
•
e3
v2
v1
•
v3
•
e2
H3 =
•
v2
•
v3
v2
•
v3
v1
e1
H4 =
•
v2
•
H5 =
H6 =
•
•
e3
v2
v3
•
v3
•
v2
Since we usually consider isomorphic graphs to be the same, we may also think of a graph like
u
•
e
v
•
f
w
•
as a subgraph of G, as long as we specify an isomorphism onto a subgraph, for instance onto H2 .
Remark. When describing a subgraph H of a graph G, we often don’t explicitly define the function φH
since it is fully determined by φG .
Remark. Let G and H be graphs. Then G = H if and only if G is a subgraph of H and H is a subgraph
of G.
Definition 38. Let H1 , H2 be subgraphs of a graph G. The union of H1 and H2 , denoted H1 ∪ H2 , is the
subgraph of G with vertex set VH1 ∪ VH2 and edge set EH1 ∪ EH2 . The intersection of H1 and H2 , denoted
H1 ∩ H2 , is the subgraph of G with vertex set VH1 ∩ VH2 and edge set EH1 ∩ EH2 .
44
Example. Returning to the previous example,
v1
e1
v1
•
∪
•
•
v2
=
•
•
e3
v2
v3
e1
•
v3
v2
•
•
e3
v3
and
v1
e1
•
∩
=
•
•
•
e3
v2
v3
v2
•
v3
•
v2
•
v3
Definition 39. A walk W in a graph G = (V, E, φ) is a sequence (v0 , e1 , v1 , e2 , v2 , . . . , en , vn ), where
n ∈ Z≥0 , each vi ∈ V , each ei ∈ E, and φ(ei ) = {vi−1 , vi }. We say that W connects v0 and vn and that W
is a walk from v0 to vn .
Think of a walk as an actual walk: imagine standing at a vertex, then walking along an edge emanating
from that vertex, arriving at another vertex, walking along another edge, etc.
Example. Some walks in the graph
v1
e1
•
•
e2
•
e3
v2
v3
are
(v1 ),
(v1 , e2 , v3 ),
(v2 , e1 , v1 , e1 , v2 ),
(v3 , e2 , v1 , e1 , v2 , e3 , v3 ).
Example. Some walks in the graph
e
v
•
f
are
(v),
(v, e, v, e, v),
(v, f, v, e, v, f, v).
Definition 40. A graph G = (V, E, φ) is connected if for every pair of vertices v, w ∈ G, there is a walk
in G from v to w.
This is just the formal way of saying that every vertex is “connected” to every other vertex by some
sequence of edges.
Example. The graphs H1 , H2 , H5 , H6 in the example above are connected. The graphs H3 , H4 are not
connected.
Here’s a first easy theorem. Think up some examples to convince yourself this is correct!
Theorem 38. Let H1 , H2 be connected subgraphs of a graph G and suppose H1 and H2 have a common
vertex. Then H1 ∪ H2 is connected.
Proof. Exercise.
Definition 41. A connected component of a graph G is a maximal connected subgraph of G. (“Maximal”
means not contained in any strictly larger connected subgraph.)
45
Theorem 39. Let G = (V, E, φ) be a graph. For any vertex v, the subgraph C of G defined by
VC = {w ∈ V | there is a walk in G from v to w}
and
EC = {e ∈ E | φ(e) ⊆ VC }
is a connected component of G containing v.
Proof. We have to prove that (i) v ∈ VC , (ii) C is connected, and (iii) C is maximal.
(i) Since (v) is a walk in G from v to v, v ∈ VC .
(ii) Suppose u, w ∈ VC . Then there is a walk (v, e1 , v1 , e2 , v2 , . . . , er , u) in G from v to u and a walk
(v, f1 , w1 , f2 , w2 , . . . , fs , w) in G from v to w. In fact, each of these walks is also a walk in C. To see
this, note that each vi is in C because we can stop the first walk at vi , hence obtaining a walk in G
from v to vi . Similarly, each wi is in C. But then all the edges in the walks are also in C since their
endpoints are vertices in the walk, which are in VC . Thus both walks are in C.
Now we can construct a walk from u to w by walking from u to v (the reverse of the walk from v to
u), then from v to w:
(u, er , . . . , v1 , e1 , v, f1 , w1 , . . . , fs , w).
Since each of the two walks was in C, this new walk is in C. Thus C is connected.
(iii) Let C ' be a connected subgraph of G containing C. Suppose for contradiction that C ' is strictly larger
than C. Then C ' must have a vertex not contained in C (C ' cannot just have an extra edge since
EC already contains all possible edges whose endpoints are in VC ); call it w. Since C ' contains C, C '
contains v. Since C ' is connected, there must be a walk W in C from v to w. But W is also a walk in
G, so w ∈ VC , contradicting how we chose w.
46
Download