Download as pdf or txt
Download as pdf or txt
You are on page 1of 133

DISCRETE

STRUCTURES
Cấu Trúc Rời Rạc

TS Nguyễn Thị Huỳnh Trâm


Logical Equivalences

(~p → r)  (q→ r)  (p → q) → r

(~p → r)  (q → r)
 ( p  r )  (~ q  r) (if – then law)
 ( p ~ q )  r (distributive law)
 ~(~p  q )  r (De Morgan)
 ~( p → q )  r (if – then law)
 ( p → q ) → r (if – then law)

12. If – then law


p → q  ~p  q Representation of If-Then as Or
 ~q → ~ p Contrapositive

Valid and Invalid Arguments


Notations Z = {0,1,-1,2,-2,…} The set of all integers.

Q = {m/n | m,n  Z, n≠0 } The set of all


real numbers rational numbers

R: The set of all real number.


rational numbers
All integers are rationals
integers.

All rationals are reals.

∃ : There exists ...


∃! : There exists a unique ...
∀ : For all ...
∈ : Member of (a set) ...
∋ : such that
Notations Z = {0,1,-1,2,-2,…} The set of all integers.

R: The set of all real number.

∃ : There exists ...


∃! : There exists a unique ...
∀ : For all ...
∈ : Member of (a set) ...
There exists an integer x such that 𝑥 2 = 4
∋ : such that
∃𝑥 ∈ 𝑍 ∋ 𝑥 2 = 4

For all real numbers y, there is a unique real z such that y + z = 0.


or
Every real number y has exactly one real z such that y + z = 0
∀𝑦 ∈ 𝑅, ∃! 𝑧 ∈ 𝑅 ∋ 𝑦 + 𝑧 =0
Properties of numbers
We will also assume, without proof, the usual properties of numbers
Closure (Đóng): integers are closed under addition and multiplication

i.e ∀𝑥, 𝑦 ∈ 𝑍, 𝑥 + 𝑦 ∈ 𝑍 and xy ∈ 𝑍


For all real numbers a,b and c

Commutativity (Giao hoán): a + b = b + a and ab = ba

Distributivity (Phân phối): a(b + c) = ab + ac and (b + c)a = ba + ca

Trichotomy (Tam phân): exactly one of the following is true: a < b, or b <a, or a = b
PROPERTIES OF THE REAL NUMBERS
Appendix A of Epp’s textbook for all the properties.
PROPERTIES OF THE REAL NUMBERS
PROPERTIES OF THE REAL NUMBERS
PROPERTIES OF THE REAL NUMBERS
PROPERTIES OF THE REAL NUMBERS
PROPERTIES OF THE REAL NUMBERS
PROPERTIES OF THE REAL NUMBERS
PROPERTIES OF THE REAL NUMBERS
What is Proof
A proof is a concise, polished argument explaining the validity of a statement to a
skeptic (người nghi ngờ) (usually, you).
• Concise (ngắn gọn) means there are no irrelevant details. It also means to use
few words.
• Polished (đánh bóng) means it should be the final draft, i.e. you need to revise it
to make it understandable, like writing an essay.
• Argument (tranh luận) means every step should follow logically from all previous
steps.
• A proof is not an attempt to determine whether or not something is true. That is
your scratch work. You should be convinced the statement is true before you write
your proof.
Lượng từ Khi nào đúng Khi nào sai
x P(x) P(x) đúng với mọi x Có một giá trị x để P (x) là sai
x P(x) Có một x sao cho P (x) là đúng P(x) sai với mọi x

Phủ định các lượng từ


Phủ định Mệnh đề tương đương Khi nào phủ định là đúng Khi nào là sai
~∃𝑥 P(x) ∀𝑥 ~P(x) P(x) sai với mọi x Có một x để P(x) là đúng
~∀𝑥 P(x) ∃𝑥 ~P(x) Có một x để P(x) sai P(x) đúng với mọi x

Mệnh đề Khi nào đúng Khi nào sai


x y p(x,y) p(x,y) đúng với mọi cặp (x,y) Có một cặp (x,y) đối với nó p(x,y) là sai
y x p(x,y)
x y p(x,y) Với mọi x, có một y sao cho p(x,y) là đúng Có một x sao cho p(x,y) là sai với mọi y
x y p(x,y) Có một x sao cho p(x,y) đúng với mọi y Với mọi x, có một y sao cho p(x,y) là sai
x y p(x,y) Có một cặp (x,y) sao cho p(x,y) là đúng p(x,y) đúng với mọi cặp (x,y)
y x p(x,y)
Proof by Construction
Prove the following: ∃𝑥 ∈ 𝑍 ∋ 𝑥 > 2 𝑎𝑛𝑑 𝑥 2 − 5𝑥 + 6 > 0

That is, there exists an integer x such that x > 2 and x2 - 5x + 6 > 0.
Proof: 1. Note that 1000 ∈ Z and 1000 > 2.
2. Also, 10002 - 5(1000) + 6 = 995006 > 0

• In the proof, there is no need to explain how 1000 was obtained. You just need to show
that 1000 has the said properties. Of course, many integers satisfy the same properties (as
you can easily verify), and any one of these will suffice for the proof.
• This style of proof - where you explicitly find the value with the correct properties - is called
a proof by construction. It is the most direct way to prove that something exists.
Lượng từ Khi nào đúng Khi nào sai
x P(x) P(x) đúng với mọi x Có một giá trị x để P (x) là sai
x P(x) Có một x sao cho P (x) là đúng P(x) sai với mọi x
Existence Proof 2
Prove that there exist irrational numbers p and q such pq is rational.
𝑎
Recall that a number x is rational if it can be written as a ratio of two integers: x = ,
𝑏

where a, b ∈ Z and b ≠ 0. A number that is not rational is irrational.

Lượng từ Khi nào đúng Khi nào sai


x P(x) P(x) đúng với mọi x Có một giá trị x để P (x) là sai
x P(x) Có một x sao cho P (x) là đúng P(x) sai với mọi x
Disproof (Phản chứng)
To disprove a statement, you are arguing why the statement is not true. You may use the same
type of argument as in a proof. But sometimes, it is easier just to show a counterexample.
+
Disprove this statement: ∀𝑥, 𝑦 ∈ 𝑍 𝑥+𝑦 = 𝑥+ 𝑦
In other words, for all positive integers x and y, 𝑥 + 𝑦 = 𝑥 + 𝑦
Z+ denotes the set of nonnegative integers, i.e. {1, 2, 3,…}
1. Let x = y = 2. Clearly, they are nonnegative integers.
Disproof by counterexample is
2. Then 𝑥 + 𝑦 = 2 + 2 = 2,
particularly useful for
3. But, 𝑥 + 𝑦 = 2 + 2 = 2 2 = 2.828427…
statements involving ∀.
4. Thus 𝑥 + 𝑦 ≠ 𝑥 + 𝑦 , and the statement is false.
Lượng từ Khi nào đúng Khi nào sai
x P(x) P(x) đúng với mọi x Có một giá trị x để P (x) là sai
x P(x) Có một x sao cho P (x) là đúng P(x) sai với mọi x
Jigsaw Analogy

• Doing a proof is like solving a jigsaw puzzle. No two jigsaws are alike; no two proofs
are alike.
• Sometimes you solve large chunks quickly; other times you get stuck. You don’t have
to solve from top to bottom.
• Some strategies are useful eg. fixing the border of the puzzle first. Likewise, there
are useful strategies for proofs
If-then statements
Many statements to be proven take the form: if P then Q
One strategy is to use a direct proof:
1) Assume P is true, then combine this with other known facts F and theorems T to
conclude that Q must be true.
2) Think of P as the starting point, and Q the destination.
The other known facts F and theorems T make up the route that go from P to Q.
Each step of the route must be logically connected.
In your draft, you can work forwards from P, or backwards from Q, but be careful
never to assume Q to be true.
In your final, polished proof, you must argue only forwards, not backwards
NUMBER THEORY
Definition 1.1.1 (Colorful)
An integer n is said to be colorful if there exists some integer k such that n = 3k:
This terminology colorful is non-standard; used only in this class.

Questions:
• Is 1353 colorful?
• What about (208 - 201)?
• 0?
NUMBER THEORY
Definition 1.1.1 (Colorful)
An integer n is said to be colorful if there exists some integer k such that n = 3k:
This terminology colorful is non-standard; used only in this class.
Questions:
• Is 1353 colorful?
• What about (208 - 201)?
• 0?
• Yes, 1353 is colorful because 1353 = 3 × 451.
• No, because 208 - 201 = 7, and there is no integer k such that 7 = 3k.
• Yes, 0 is colorful because 0 = 3 × 0
Prove that: if x, y are colorful integers, then so is x + 2y
Identify P and Q to be: P : x, y are colorful integers
Q : x + 2y is colorful
We can immediately write down the start and end of the proof, as follows:
Draft proof: Assume P is true, then combine this with
1. Assume that x; y are colorful integers. other known facts F and theorems T to
2. … conclude that Q must be true.
3. And thus x + 2y is colorful. Think of P as the starting point, and Q the
The next logical thing is to
destination.
use the definition of colorful.
Prove that: if x; y are colorful integers, then so is x + 2y
Identify P and Q to be: P : x, y are colorful integers
Q : x + 2y is colorful
We can immediately write down the start and end of the proof, as follows:
Draft proof:
1. Assume that x; y are colorful integers.
2. Then by definition of colorful, ∃a, b ∈ Z such that x = 3a and y = 3b
3… -The other known facts F
4. So ∃c ∈ Z such that x + 2y = 3c. and theorems T make up the
5. And thus x + 2y is colorful, by definition of colorful route that go from P to Q.
-Each step of the route must
be logically connected.
Draft proof:
1. Assume that x; y are colorful integers.
2. Then by definition of colorful, ∃a, b ∈ Z such that x = 3a and y = 3b
3…
4. So ∃c ∈ Z such that x + 2y = 3c.
5. And thus x + 2y is colorful, by definition of colorful
This means we need to connect c to a and b. Obviously, we should try writing (x + 2y) in
terms of a; b:
x + 2y = 3a + 2(3b) by substitution In your draft, you can
= 3a + (2 · 3)b by associativity
work forwards from P, or
= 3a + (3 · 2)b by commutativity
= 3a + 3(2b) by associativity backwards from Q, but
= 3(a + 2b) by distributivity
be careful never to
Aha! It is clear what c should be now. So here’s our final proof
assume Q to be true.
Prove that: if x; y are colorful integers, then so is x + 2y
Proof.
1. Assume that x; y are colorful integers.
2. Then by definition of colorful, ∃a, b ∈ Z such that x = 3a and y = 3b
3. Now, x + 2y = 3a + 2(3b) by substitution
4. = 3a + 3(2b) by commutativity and associativity
5. = 3(a + 2b) by distributivity
6. Let c = a + 2b. Note that a + 2b ∈ Z because integers are closed under addition and
multiplication.
Closure (Đóng): integers are closed
7. So ∃c ∈ Z such that x + 2y = 3c.
under addition and multiplication i.e
8. And thus x + 2y is colorful, by definition of colorful. ∀𝑥, 𝑦 ∈ 𝑍, 𝑥 + 𝑦 ∈ 𝑍 and xy ∈ 𝑍

In your final, polished proof, you must argue only forwards, not backwards
DIVISIBILITY
Definition 1.3.1 (Divisibility)

e.g. Clearly 3 | 6 (3 divides 6), but 4 ł 11 (4 does not divide 11)


DIVISIBILITY

For integers a, b, c, it is clear that if a | b and a | c, then a | (b + c).


Reason: if a is a factor of b and c, then it is a factor of the sum.
Trivial example: 2 | 6 and 2 | 8. Also, 2 | (6 + 8).
• But the inverse is not true.
That is, if a ł b and a ł c, then it is still possible to have a | (b + c).
Trivial example: 3 ł 10 and 3 ł 14, but 3 | (10 + 14).
• Finally, it should be obvious that a | ab, for any b.
Warning!
Do NOT use division. There is no concept of division in Number Theory. The notation a | b
simply means a is a factor of b. No actual division is performed.
DIVISIBILITY

That is, when dealing with positive integers, a divisor of a number cannot be larger
than the number.
Note that the theorem is silent for the case b = 0, because 0 is not positive.
When doing proofs, it is often helpful to keep track of what we are given and what
our goals are. Since the statement to be proven is an if-then statement, we can
quickly write the P as our givens and the Q as our goal.
DIVISIBILITY
From the definition of a | b, we know that b = ak for some integer k. We may add this to
our givens.

• So we now have one equality in our givens, but our goal involves an inequality.
How do we achieve this?
• Intuitively, the equality says that if a needs to be multiplied by something to get b,
then b must be larger than a. But this requires k to be positive. Fortunately, rule T25
of Appendix A (Epp) assures this.
DIVISIBILITY

• So what we want is to argue that since ak = b and k is positive, we may “drop" k to get
a ≤ b. Although this is intuitively true, none of the rules in Appendix A (Epp) justifies this
argument. We need another approach.
• Since k is a positive integer, we have the inequality 1 ≤ k for “free", which we can add to
our givens. We can now invoke rule T20 to multiply both sides of this inequality by a
(which is positive), to get a ≤ ak. The right hand side is now b, which is our goal. Hence
our proof:
DIVISIBILITY

1. Assume a, b ∈ Z+, and a | b.


2. So by definition of divisibility, b = ak for some k ∈ Z.
3. Since a; b > 0, and b = ak, we deduce k is positive by rule T25 of Appendix A (Epp).
4. Thus 1 ≤ k.
5. Using rule T20, multiply the inequality by a to get a ≤ ak = b
That is, if a divides both b and c, then it also divides (bx + cy), for any integers x, y.
The following is an attempted disproof of the statement. Let’s play detective and
determine if it is right or wrong.
For-all statements
The strategy for proving such statements is to prove from the particular to the general.
That is, take x to be a particular, but arbitrarily chosen, value.
Prove that P(x) is true.
Conclude that since P(x) is true for this particular x (which has no other special
properties), it must be true for all x.

Ex: Prove “All CS students take CTRR


You pick Nam, a typical CS student.
Now you show that Nam is taking (or has taken) CTRR.
You then argue that, since Tom is representative of CS students, what is true about him
must be true of all other CS students.
And thus the statement is true.
For-all statements to prove from the particular to the general

Line 1: if instead we
had said: Take positive
integers a; b; c, then
the proof would still be
valid until Line 6.

But in Line 7, we
would not be able to
generalize to all
integers, because our
proof thus far was
valid only for positive
integers.
For-all statements

Likewise, we cannot
assume a ≤ b or b ≤ c
or a ≤ c, since
this is an unnecessary
restriction
For-all statements

Another common
mistake is to say, in
Line 3: b = ar and
c = br. This forces b
and c to be the same
multiple, which
again restricts our
proof.
For-all statements

We will usually omit


Line 7, since it is
understood.
Proof by Contraposition
If not q then not p if p then q if q then p If not p then not q

(Phản đảo) (Đảo) (Nghịch Đảo)

Note that ∼ P means not P, the negation of P.


If P is True, then ∼ P is False, and vice versa.
Both statements are logically equivalent; that is, they are True and False for exactly
the same truth values of P and Q.
Thus, instead of proving an if-then statement directly, we may prove it indirectly by
proving its contrapositive.
Proof by Contraposition

Closure (Đóng): integers are


closed under addition and
multiplication i.e ∀𝑥, 𝑦 ∈ 𝑍, 𝑥 +
𝑦 ∈ 𝑍 and xy ∈ 𝑍
Proof by Contraposition

Remarks:
• To prove the statement directly, you would have to start by assuming x2 is irrational.
That is, x2 ≠ a/b for all integer a and nonzero integer b.
The unequality ≠ makes it difficult to continue. What form can you let x2 take? Irrationality
is defined by the absence, rather than the presence, of a form. If you cannot write down
a form for x2, then you cannot manipulate it to get a form for x. The proof cannot proceed
• By using the contrapositive, you instead deal with rationals, rather than irrationals. You
can thus exploit the form of rationals in your proof.
• Thus, whenever you encounter an if-then statement involving the absence of a form,
you should consider proving by contraposition instead
Proof by Contradiction
Remarks:
• To prove a statement S by contradiction, you first assume that ∼ S is true. Based on
this, you use known facts and theorems to arrive at a contradiction. Since every step of
your argument thus far is logically correct, the problem must lie in your assumption.
Thus, you conclude that ∼ S is false, and hence S is true.
• A formal definition of contradiction will be given in the chapter on logic; for now, it
suffices to say that a contradiction is something that is logically impossible. For example,
at the start of your proof, you may assume (or deduce) that x ≥ 5. Then later you deduce
that x < 5. These two facts are clearly contradictory.
• In a proof by contradiction, the contradictory facts need not be directly related to S. As
long as you contradict any known thing in mathematics, eg. 1 = 0, your proof has
succeeded.
It is difficult to use a direct proof because irrationality is the absence of a form.
On the other hand, proving by contradiction begins by assuming that 2 is rational,
thereby allowing us to exploit the form of a rational number.
The resulting proof is a mathematical classic.
Proof by contradiction
1. Assume that 2 is rational.
2. Then by definition of rationals, there exists integers m, n, with n ≠ 0, such that

2 = m/n.
3. Further, we may assume that m/n is reduced to lowest terms, ie. the only common
factor of m, n is 1.
4. From Line 2, m2 = 2n2, by basic algebra.
5. So m2 is even, by definition of even, and because n2 is an integer by the closure
property.
6. => m is even, by Proposition 4.6.4 (Epp)
7. => Ǝ k ∈ Z ∋ m = 2k, by definition of even.
8. Subtituting into Line 4: (2k)2 = 2n2.
9. => 2.k2 = n2, by basic algebra.
10. So n2 is even, by definition of even, and because k2 is an integer by the
closure property.
11. => n is even by Proposition 4.6.4 (Epp).
12. But this means 2 is a common factor of m, n, contradicting Line 3.
13. Hence 2 must be irrational.
Proof. [Proof by contradiction]
1. Suppose 7 is colorful.
2. Then, by definition of colorful, 7 = 3k for some integer k.
3. => 6 = 3k - 1, by basic algebra.
4. => 1 = 3(k - 2), by basic algebra.
5. Since k - 2 is an integer by the closure property, the above means that 3 |1, by
definition of divisibility.
6. Then by Theorem 4.3.1 (Epp), this means 3 ≤ 1.
7. Clearly, this is absurd, so the Proposition is true.
Remarks:
• It is wrong to say: “7 is not colorful” because 7:3 = 2:333…, which is not an integer."
There is no concept of division in Number Theory.
Moreover, the definition of colorful does not use division, but instead uses the existence
of an integer.
• It is also wrong to say: I cannot find an integer k such 7 = 3k, therefore 7 is not colorful.“
If you cannot find it, it doesn’t mean no such integer exists.
• The irrefutable way to prove the non-existence of something is to show that if it exists,
then it will lead to an absurd conclusion.
This is the essence of a proof by contradiction
Proofs
• Construction: find the value with the correct properties (Ǝ 𝑡𝑟𝑢𝑒 ∀(𝑓𝑎𝑙𝑠𝑒))

• If-then statements: assume P is true, then combine this with other known facts F and
theorems T to conclude that Q must be true.

• For-all statements: prove from the particular to the general

• Contraposition: instead of proving an if-then statement directly, we may prove it


indirectly by proving its contrapositive

• Contradiction: + assume that ∼ S is true


+ use known facts and theorems to arrive at a contradiction

+conclude that ∼ S is false, and hence S is true


a | b and a | c, then a | (b + c). a | ab, for any b.
Summary
• Proofs are at the heart of mathematics.
• Proving a statement is like solving a jigsaw puzzle. No two proofs are alike. Some
strategies are useful.
• These lecture notes illustrate strategies for dealing with: existence proofs, if-then and
for-all statements, disproof by counterexample, proof by contraposition and contradiction.
• For a given proof, which strategy to use will come with experience. For longer proofs,
multiple strategies may be combined.
• Two more proof techniques | Induction and Diagonalization | will be covered in future
lectures
DIVISIBILITY

Proof.
1. For any a, b, c ∈ Z:
2. If a | b and a | c:
3. Let k ∈ Z such that b = ak. (by definition of divisibility)
4. Let m ∈ Z such that c = am. (by definition of divisibility)
5. For any x, y ∈ Z:
6. bx + cy = (ak)x + (am)y = a(kx + my). (by basic algebra)
7. Note that kx + my ∈ Z. (by closure of addition and multiplication
over integers)
8. Thus a | bx + cy. (by definition of divisibility)
Primes
Primes

• 1 is neither prime nor composite.


• The first few primes are: 2; 3; 5; 7; 11; 13; 17; 19.
• The first few composites are: 4; 6; 8; 9; 10; 12; 14; 15
Primes
Primes Properties
Primes have interesting properties, some of which we will now study. We begin with the
property that if one prime divides another, then they must be equal.

Note that this property does not hold for composites, e.g. 4 | 8 but 4 ≠ 8.
Primes
Primes
Primes

Proof: (by Contradiction)


1. Suppose the set of primes is finite: a total of k primes.
2. Then we may list all the primes: p1, p2, p3,…, pk
3. Let N be the product of all primes plus 1: N = p1p2p3 · · · pk + 1:
4. Clearly, N > 1, and thus by Theorem 4.3.4 (Epp), there exists a prime q such that q|N.
5. Now q | p1p2p3 · · · pk because q is one of the factors in the product.

6. Then by Proposition 4.7.3 (Epp), q ł N, which contradicts Line 4 which says q | N.


7. Thus by the Contradiction Rule, the statement is true.
Primes
• This proof shows that if you form the product of all primes up to some point and add 1,
the result, N, is divisible by a prime not in the list.
• Note that this does not mean that N is prime.
As an exercise, try to find an N constructed in this way that is not prime
So now we know that primes do not end. Ever larger primes can always be found.
But they seem fewer and fewer as we examine larger integers.
For example, there are 4 primes under 10, but 25 primes under 100. To get the
thousandth prime, you need to search up to about 8000; to get the millionth prime,
your search goes to about 15.5 million.
The Prime Number Theorem tells us that the number of primes less than or equal to
integer x is approximately x= log(x)
Primes

For example, consider 2 × 3 × 6 = 36:


Clearly, 3 is prime, and 3 | 36 and 3 | 6.
However, the theorem does not hold for composites, e.g. 4 is composite and 4 | 36.
But 4 ł 2, and 4 ł 3 and 4 ł 6.
This theorem shows that a prime factor of a product must be completely “inside" one of
the factors of the product.
The prime cannot be “split" into several of the factors.
Primes
Primes

That is, every positive integer greater than 1 can be uniquely factorized into a product of
prime numbers.
This is also called The Fundamental Theorem of Arithmetic.
It is standard practice to sort the primes from smallest to largest.
Examples: 24 = 2 × 2 × 2 × 3 = 23 · 3.
90 = 2 × 3 × 3 × 5 = 2 · 32 · 5
Primes
Primes
1. Suppose you encode m; n by inserting a 0 between their decimal representations,
e.g. 1234 and 768 gets encoded to 12340768
Clearly, this won’t work if m or n contains 0.
2. Suppose you try s = m + n. This doesn’t work either. Why?
3. Next, you try s = 1000m + n. Will this work?
4. Clearly, s = mn also doesn’t work.
5. Luckily, you remember CS1231, so you try s = 2m3n.
This works because the prime factorization of s guarantees that we can get back m
and n uniquely!
Question: how would you handle negative m and n?
Python code for encode and decode
def encode(m, n): def isEven(x):
return 2**m * 3**n # x is even if its remainder is 0
def decode(s): # when divided by 2
# Repeatedly divide s by 2, and count return x % 2 == 0
number of times def isColorful(x):
# this can be done. Do the same for 3. # x is colorful if its remainder is 0
# when divided by 3
m=0 return x % 3 == 0
while isEven(s):
s=s/2
m=m+1
n=0
while isColorful(s):
s=s/3
n=n+1
return m,n
Primality test
Primality test
Of course, one way to check if a number n is prime is to see if n can be found in a list, L,
of primes.
To generate L, an ancient method called the Sieve of Eratosthenes may be used:
1. Start by listing all integers greater than 1. Call this list C. Also, let L be an empty list.
2. Take the first number p = 2 in C, and add it to L. This is the first prime.
3. In C, cross out all multiples of p.
4. Let p be the next uncrossed number in C. This is the next prime. Add it to L, and
repeat from Step 3
Well Ordering Principle

Note that this definition does not require b to be a member of X .


Moreover, there may be more than one lower bound (ie. the lower bound is not unique).
Examples: Does each of the following sets have a lower bound?
• A = {𝑥 ∈ Z | x2 ≤ 38}.
• B = {𝑥 ∈ Z |x is a multiple of 3}.
• C = {𝑥 ∈ Z | x2 ≤ 100x}.
Well Ordering Principle
A = {𝒙 ∈ Z | x2 ≤ 38}.
• We may list all the elements of the set.
A = {-6, -5,…, 5, 6}. Thus, any integer less than or equal to -6 is a lower bound.

B = {𝐱 ∈ Z |x is a multiple of 3}.
• There is no lower bound. To see this, suppose not; suppose the lower bound is some
integer c. Then one of c – 1, c – 2, c - 3 must be divisible by 3.

But all of them are less than c, contradicting the fact that c is a lower bound.

C = {𝐱 ∈ Z | x2 ≤ 100x}.
• If x2 ≤ 100x then x(x - 100) ≤ 0, by basic algebra. Thus C is the set of integers x such
that 0 ≤ x ≤ 100. Thus any integer m ≤ 0 is a lower bound
Well Ordering Principle

Examples: Does each set below have a least element? If so, what is it? If not, explain
why there is no violation of the Well Ordering Principle.
• The set of all positive real numbers.
• The set of all non-negative integers n such that n2 < n.
• The set of all non-negative integers of the form 46 - 7k, where k is any integer
Well Ordering Principle
• The set of all positive real numbers.

There is no least (smallest) positive real number. To see this, suppose x ∈ R+, then x/2
∈ R+ and x=2 < x. There is no violation of the Well Ordering Principle because the
principle concerns only sets of integers, not real numbers.
• The set of all non-negative integers n such that n2 < n.

This set is empty! Thus there is no least element, and no violation of the Well Ordering
Principle.
• The set of all non-negative integers of the form 46 - 7k, where k is any integer

Now, 46 - 7k ≥ 0 implies 7k ≤ 46, which means k ≤ 6.57. When k = 6, 46 - 7(6) = 4,


which is therefore the least element
The usual way to prove the uniqueness of a solution is to say that if A and B are both
solutions, then A = B.
First let’s define what it means to be a least element:
The least element x of a set S is one that satisfies:
(i) x ∈ S.
(ii) ∀𝑦 ∈ S; x ≤ y.
T
T
Proof:
1. Let R be the set of “remainders": R = {∀𝑥 ∈ 𝑁| a = by + x for some 𝑦 ∈ Z }.
2. (Claim: R is not empty.)
3. If a ≥ 0:
4. Then a = b · 0 + a ≥ 0, and thus a ∈ R.
5. Else a < 0:
6. Then a - ab = a(1 - b) ≥ 0 [because a < 0 and (1 - b) ≤ 0, so their product ≥ 0.]
7. Thus (a - ab) ∈ R by definition of R.
8. In either case, R has at least one element.
9. Thus R is a non-empty subset of integers, and there exists a least element r ∈ R, by
the Well Ordering Principle.
10. Then there exists q ∈ Z such that a = bq + r, since r ∈ R.
11. Suppose r ≥ b:

12. Re-write: a = b(q + 1) + (r - b) by basic algebra.

13. Thus (r - b) ∈ R, by definition of R.

14. But r - b < r, contradicting the fact the r is the least element.

15. Thus 0 ≤ r < b.

16. Furthermore, r, as the least element, is unique by Proposition 4.3.3.

17. And since a = bq + r, this means q is unique also.

Line 17 could be more rigorously justified.


Note that neither the theorem nor the proof says how to calculate q and r
from a, b. They merely say q, r exist.
Most programming lanauges have operations called div and mod, which compute the
quotient and remainder, respectively, for positive integers a, b.
In C/C++ and Java the integer division “/" computes the quotient, while “%" computes
the remainder. However, these do not give the correct answer if a is negative, e.g. C
gives q = -13; r = -2 when a = -54; b = 4. Thus some caution is advised.
Division Algorithm
def division(a, b):
#assumes a>=0, b > 0
q=0
r=a
while r >= b:
r=r-b
q=q+1
return q,r

This algorithm computes the quotient and remainder for non-negative integer a and
positive integer b.

The key idea is to repeatedly subtract b from a until the result is less than b, and to
count the number of subtractions
Representation of Integers
The Quotient-Remainder Theorem provides the basis for writing an integer n as a
sequence of digits in a base b.
For example, our usual way of writing the number
n = 3 · 102 + 3 · 101 + 4·100 is: 334. This is in decimal (base 10) because it uses powers
of 10. The same number n could be represented using a different base.

More generally, given any positive integer n and base b, we may repeatedly apply the
n = bq0 + r0 334 = 10 x 33 + 4
Quotient-Remainder Theorem to get:
q0 = bq1 + r1 33 = 10 x 3 + 3
q1 = bq2 + r2 3 = 10 x 0 + 3
...
qm-1 = bqm + rm
n = bq0 + r0 334 = 10 x 33 + 4
q0 = bq1 + r1 33 = 10 x 3 + 3
q1 = bq2 + r2 3 = 10 x 0 + 3
... n = 3 · 102 + 3 · 101 + 4·100

qm-1 = bqm + rm
n = rmbm + rm-1bm-1 + : : : + r1b + r0
• Each remainder ri is one of the integers 0,1,..,b - 1, and the process stops when qm = 0.
• By eliminating the quotients qi, we get: n = rmbm + rm-1bm-1 + : : : + r1b + r0
which may be written more compactly as: n = σ𝑚 𝑟
𝑖=0 𝑖 𝑏 𝑖

• In turn, we may write n more compactly in base b as a sequence of the digits ri.
That is: n = (rmrm-1 … r1r0)b
This positional notation is convenient. When b = 10 we usually omit it, which gives us
our usual decimal representation for integers
Example: Express (109)10 in base 2.
Answer: Dividing repeatedly by 2 we obtain:
109 = 2 × 54 + 1 n = bq0 + r0
54 = 2 × 27 + 0 q0 = bq1 + r1

27 = 2 × 13 + 1 q1 = bq2 + r2

13 = 2 × 6 + 1 ...
qm-1 = bqm + rm
6=2×3+0
3=2×1+1
1=2×0+1
Hence, by reading the remainders from bottom up, (109)10 = (1101101)2.

Base 2 (or binary) representation is especially useful for computers to manipulate.


Another useful base for computer manipulation is 16, called hexadecimal.
Here, we need new symbols to represent the decimal digits 10, 11,…, 15 in base 16.
The usual convention is: A=10, B=11, C=12, D=13, E=14, F=15
For the previous example of (109)10, we may repeatedly divide by 16 to get:
(109)10 = (6D)16.
But a quicker way is to use the binary notation: starting from the right, take the bits
(binary digits) in groups of 4, and convert each group to base 16 using this table:
0000 = 0 0001 = 1 0010 = 2 0011 = 3
0100 = 4 0101 = 5 0110 = 6 0111 = 7
1000 = 8 1001 = 9 1010 = A 1011 = B
1100 = C 1101 = D 1110 = E 1111 = F
Thus (109)10 = (0110 1101)2 = (6D)16.
Convert (10110101)2 to:
(a) decimal (base 10)
(b) octal (base 8)
(a) (10110101)2 = 27 + 25 + 24 + 22 + 20
= 128 + 32 + 16 + 4 + 1 = (181)10.
(b) (10 110 101)2 = (265)8. By taking groups of three bits.
Greatest Common Divisor (GCD)
Ước số chung lớn nhất
Definition 4.5.1 (Greatest Common Divisor)
Let a and b be integers, not both zero. The greatest common divisor of a and b, denoted
gcd(a, b), is the integer d satisfying:
(i) d | a and d | b.
(ii) ∀𝑐 ∈ 𝑍 , if c | a and c| b then c ≤ d.

The greatest common divisor is also called the highest common factor.

Examples: Find gcd(72; 63) and gcd(1020; 630).


• Using prime factorization: 72 = 23 · 32, and 63 = 32 · 7. The gcd is therefore 32 = 9.
• Using prime factorization: 1020 = 220 · 520, and 630 = 230 · 330.Thus, gcd is 220.
The definition of gcd does not guarantee its existence. Hence,
Proposition 4.5.2 (Existence of gcd)
For any integers a, b, not both zero, their gcd exists and is unique.

Proof:
1. Let D = {all common divisors of a, b}.
2. Clearly, 1 ∈ D, and D ⊆ Z.
3. By assumption, one of a, b is non-zero. Let it be a, since gcd(a, b) = gcd(b, a) by its
definition, so we can swap the numbers to make a the non-zero number.
4. Also, |a| is an upper bound for D, since no common divisor of a, b can be larger than
this.
5. Thus by Well Ordering 2, there exists a greatest element d in D.
6. By Proposition 4.3.4, d is unique
Euclid’s algorithm
In practice, computing the gcd by prime factorization is too slow, especially when the
numbers are large. Luckily, an efficient algorithm was given by Euclid way back in the
year 300BC. n = bq0 + r0
q0 = bq1 + r1
The key idea to find gcd(a, b) is based on two facts:
q1 = bq2 + r2
(i) gcd(a, 0) = a.
...
(ii) gcd(a, b) = gcd(b, r), where r is the remainder of a=b. qm-1 = bqm + rm
Line (i) was explained in the previous slide. n = rmbm + rm-1bm-1 + : : : + r1b + r0

For Line (ii), note that since a = bq + r, then any common divisor c of a, b must divide r
by Theorem 4.1.1 (r is a linear combination of a, b.)
Also, any common divisor of b; r must divide a for the same reason. So (a; b) and (b; r)
have the same set of common divisors, and thus their gcd’s must be equal
Let’s trace Euclid’s algorithm to calculate gcd(330; 156)
gcd(330; 156)
330 = 156 × 2 + 18  gcd(156; 18)
156 = 18 × 8 + 12  gcd(18; 12)
18 = 12 × 1 + 6  gcd(12; 6)
12 = 6 × 2 + 0  gcd(6; 0)
Thus gcd (330, 156)=6
6 = 18 - 12 × 1 = 18 + 12 × (-1)
= 18 + (156 - 18 × 8) × (-1) = 156 × (-1) + 18 × 9
= 156 × (-1) + (330 - 156 × 2) × 9 = 330 × 9 + 156 × (-19)
Thus 6 = 330 · 9 + 156 · (-19).
The above procedure is called the Extended Euclidean Algorithm, for obvious reasons.
Non-uniqueness of B´ezout’s Identity
There are multiple solutions x, y to the equation ax + by = d.
Once a solution pair (x, y) is found, additional pairs may be generated by
𝑘𝑏 𝑘𝑎
x+ ,𝑦 − , where k is any integer.
𝑑 𝑑

𝑘𝑏 𝑘𝑎 𝑘𝑎𝑏 𝑘𝑎𝑏
Proof sketch: a x + +𝑏 𝑦− = ax + + 𝑏𝑦 − =𝑑
𝑑 𝑑 𝑑 𝑑

6 = 330 · 9 + 156 · (-19).


1×156 1×330 210 440
k =1 => 9 + , −19 − = ,− = 35, −74
6 6 6 6

6 = 330 · 35 + 156 · (-74).


k = 2 =>
k = 3 =>
Fill a large trough in the field with exactly 1 litre of river water. Only two cans are
available to scoop water from the river: one is exactly 9 litres when full, the other 7.
Since the cans must be completely full or empty when transferring water, we is dealing
with multiples of 7 and 9 litres. In other words, we need to solve the equation:
9x + 7y = 1
Note that gcd(9; 7) = 1.
Using B´ezout’s Identity, it is straightforward to get: 9(4) + 7(-5) = 1
Thus, we need to pour in four cans of water into the trough using the 9-litre can, and
then scoop out five cans using the 7-litre can.
1)

2)

3) Hãy đổ đúng 1 lít nước sông vào một cái máng lớn trên ruộng. Chỉ có hai can để múc nước từ
sông: một can chứa đầy được đúng 13 lít, can còn lại 11 lít.
Theorem 4.2.3: If p is a prime and x1, x2,…, xn are any integers such that: p | x1x2 … xn
then p | xi, for some i (1 ≤ i ≤ n).

Proof:
(by Induction)
1. Let P(n) = ( (p | x1x2…xn) → (p | xi for some i ∈ [1; n]) )
2. (Consider the base case n = 1)
3. Clearly, P(1) is true.
4. For any k ∈ Z+: (Inductive step:)
5. Assume P(k) is true.
6. That is, (p | x1x2 …xk) → (p | xi for some i ∈ [1; k]).
7. (Consider the case k + 1:)
8. Suppose p | x1x2 : : : xk+1
Theorem 4.2.3: If p is a prime and x1, x2,…, xn are any integers such that: p | x1x2 … xn
then p | xi, for some i (1 ≤ i ≤ n).

9. Let A = x1x2 …xk, so that p | Axk+1.


10. If p | A:
11. Then p | xi for some i ∈ [1; k] by the Inductive hypothesis. So P(k + 1) is true.
12. Else p ł A:
13. Then gcd(p; A) = 1, because p is prime and p ł A.
14. Then there exist integers r, s such that pr + As = 1 by B´ezout’s Identity.
15. Now, xk+1 = 1 · xk+1 = (pr + As)xk+1 = p(rxk+1) + (Axk+1)s by basic algebra.
16. Since p divides both terms, it divides their linear combination by Theorem 4.1.1.
17. Thus, p | xk+1 and P(k + 1) is true.
18. Hence, by Mathematical Induction, the theorem is true.
Proposition 4.5.5
For any integers a, b, not both zero, if c is a common divisor of a and b, then c | gcd(a, b).
Proof:
1. Take any two integers a; b, not both zero.
2. Let d =gcd(a; b).
3. By B´ezout’s Identity, d = ax + by, for some integers x, y.
4. Suppose c is a common divisor of a, b:
Example:
5. Then c | a and c | b, by definition of divisibility. gcd(30, 45) = 15.
6. Thus c | (ax + by) by Theorem 4.1.1 30 = 2 · 3 · 5
7. Thus c | d. 45 = 32 · 5.
Thus the common divisors are 1, 3, 5, 15.
All of these common divisors divide 15.
Prove that for all positive integers a, b, a | b if, and only if, gcd(a, b) = a

To prove “P iff Q", we need to prove “if P then Q" and “if Q then P"
1. (Forward direction: “if P then Q")
2. For any positive integers a, b:
3. Suppose a | b:
4. Then b = ak for some integer k, by definition of divisibility.
5. Then gcd(a, b)=gcd(a, ak)= a because a is the largest common divisor.
6. (Backward direction: “if Q then P")
7. For any positive integers a, b:
8. Suppose gcd(a,b)=a:
9. Then a is a common divisor of a, b, by definition of gcd.
10. Thus, a | b.
Prove that if a, b are integers, not both zero, and d =gcd(a, b), then a=d and b=d are
integers with no common divisor that is greater than 1
Least Common Multiple
Definition 4.6.1 (Least Common Multiple)
For any non-zero integers a; b, their least common multiple, denoted lcm(a, b), is the
positive integer m such that:
(i) a | m and b | m,
(ii) for all positive integers c, if a | c and b | c, then m ≤ c.

The lcm of a, b exists because the Well Ordering Principle guarantees the existence of
the least element on the set of common multiples of a, b.
Examples: Find
• lcm(12; 18)
• lcm(22 · 3 · 5; 23 · 32)
• lcm(2800; 6125)
Examples: Find
• lcm(12; 18) • lcm(22 · 3 · 5; 23 · 32) • lcm(2800; 6125)

• 12 =2 · 2 · 3, and 18 =2 · 3 ·3. The gcd is thus 2 · 3 = 6. The lcm is made up of the


“factors other than the gcd", ie. lcm = 2 · 2 · 3 · 3 = 36.
• The two numbers are: 2 · 2 · 3 ·5, and 2 · 2 · 2 · 3 · 3.
So the gcd = 2 · 2 · 3 = 12. And the lcm = 2 · 2 · 2 · 3 · 3 · 5 = 360.
• 2800 =24· 52 · 7, and 6125 =53 · 72.
Thus gcd = 52 · 7, and lcm = 24 · 53 · 72.
From the above examples, it should be clear that gcd(a; b)· lcm(a; b) = ab.
Prove this as an exercise. Note that this provides an algorithm to compute the lcm. Write
code to do this.
Prove that for all positive integers a and b, gcd(a, b)| lcm(a; b)
Proof:
1. Take any non-zero integers a, b.
2. Let d = gcd(a, b), and m = lcm(a, b).
3. Then d | a and d | b, by definition of gcd.
4. Also, a | m and b | m, by definition of lcm.
5. Thus d | m, by the Transitivity of Divisibility (Theorem 4.3.3 (Epp)).
n = bq0 + r0 n = (rmrm-1 … r1r0)b

q0 = bq1 + r1
q1 = bq2 + r2
...
qm-1 = bqm + rm
n = rmbm + rm-1bm-1 + : : : + r1b + r0
Definition 4.5.1 (Greatest Common Divisor)
Let a and b be integers, not both zero. The greatest common divisor of a and b, denoted
gcd(a; b), is the integer d satisfying:
(i) d | a and d | b.
(ii) ∀𝑐 ∈ 𝑍 , if c | a and c| b then c ≤ d.

Proposition 4.5.2 (Existence of gcd)


For any integers a, b, not both zero, their gcd exists and is unique.

Euclid’s algorithm
The key idea to find gcd(a, b) is based on two facts:
(i) gcd(a, 0) = a.
(ii) gcd(a, b) = gcd(b, r), where r is the remainder of a=b.
Non-uniqueness of B´ezout’s Identity
There are multiple solutions x, y to the equation ax + by = d.
Once a solution pair (x, y) is found, additional pairs may be generated by
𝑘𝑏 𝑘𝑎
x+ ,𝑦 − , where k is any integer.
𝑑 𝑑

𝑘𝑏 𝑘𝑎 𝑘𝑎𝑏 𝑘𝑎𝑏
Proof sketch: a x + +𝑏 𝑦− = ax + + 𝑏𝑦 − =𝑑
𝑑 𝑑 𝑑 𝑑
Proposition 4.5.5
For any integers a, b, not both zero, if c is a common divisor of a and b, then c | gcd(a, b).

Prove that for all positive integers a, b, a | b if, and only if, gcd(a, b) = a

Prove that if a, b are integers, not both zero, and d =gcd(a, b), then a=d and b=d are
integers with no common divisor that is greater than 1
Definition 4.5.1 (Greatest Common Divisor)
Let a and b be integers, not both zero. The greatest common divisor of a and b, denoted
gcd(a; b), is the integer d satisfying:
(i) d | a and d | b.
(ii) ∀𝑐 ∈ 𝑍 , if c | a and c| b then c ≤ d.

Definition 4.6.1 (Least Common Multiple)


For any non-zero integers a; b, their least common multiple, denoted lcm(a, b), is the
positive integer m such that:
(i) a | m and b | m,
(ii) for all positive integers c, if a | c and b | c, then m ≤ c.

Prove that for all positive integers a and b, gcd(a, b)| lcm(a; b)
Definition 4.7.1 (Congruence modulo)
Let m and n be integers, and let d be a positive integer. We say that m is congruent to n
modulo d, and write: m ≡ n (mod d)
if, and only if, d | (m - n)
Symbolically: m ≡ n (mod d) ↔ d | (m - n)
Examples: Determine which of the following is true and which is false.
• 12 ≡ 7 (mod 5)
• 6 ≡ -8 (mod 4)
• 3 ≡ 3 (mod 7)
• ∀𝑎, 𝑏 ∈ 𝑍, not both zero, a ≡ b (mod gcd(a, b))
Examples: Determine which of the following is true and which is false.
• 12 ≡ 7 (mod 5)
• 6 ≡ -8 (mod 4)
• 3 ≡ 3 (mod 7)
• ∀𝑎, 𝑏 ∈ 𝑍, not both zero, a ≡ b (mod gcd(a, b))
Answer:
• True. Clearly, 5 | (12 - 7).
• False. Because 4 ł (6 - (-8)).
• False. Since 7 ł (3 - 3).
• True. Let d = gcd(a; b). Then d | (a - b) because d | a and d | b.
Theorem 8.4.1 (Epp): Modular Equivalences
Let a; b, and n be any integers and suppose n > 1.
The following statements are all equivalent:
1. n | (a - b)
2. a ≡ b (mod n)
3. a = b + kn for some integer k
4. a and b have the same (non-negative) remainder when divided by n
5. a mod n = b mod n

Note that a mod n is the non-negative remainder r, when a is divided by n.


By the Quotient-Remainder Theorem, 0 ≤ r < n.
Another name for this is the residue of a modulo n.
Arithmetic
Theorem 8.4.3 (Epp): Modulo Arithmetic
Let a, b, c, d and n be integers with n > 1, and suppose:
a ≡ c (mod n) and b ≡ d (mod n)
Then
1. (a + b) ≡ (c + d) (mod n)
2. (a - b) ≡ (c - d) (mod n)
3. ab ≡ cd (mod n)
4. am ≡ cm (mod n), for all positive integers m
Proof:
1. For any integers a, b, c, d, n with n > 1:
2. Suppose a ≡ c (mod n) and b ≡ d (mod n):
3. Then by Theorem 8.4.1 (Epp), there exist integers s, t such that
a = c + sn and b = d + tn.
4. Then ab = (c + sn)(d + tn), by substitution.
5. = cd + n(ct + sd + stn), by basic algebra.
6. Let k = (ct + sd + stn). This is an integer by the closure property.
7. Thus ab = cd + nk.
8. By Theorem 8.4.1 (Epp), ab ≡ cd (mod n)
Corollary 8.4.4 (Epp)
Let a, b, n be integers with n > 1. Then, ab ≡ [(a mod n)(b mod n)] (mod n)
or, equivalently, ab mod n = [(a mod n)(b mod n)] mod n.
In particular, if m is a positive integer, then am ≡ [(a mod n)m] (mod n)
Example: Calculate: (a) 55 · 26 mod 4; (b) 1444 mod 713
Answer: (a) 55 · 26 mod 4 = [(55 mod 4)(26 mod 4)] mod 4
= (3)(2) mod 4
= 6 mod 4 = 2
(b) 1444 mod 713 = (1442)2 mod 713
= (1442 mod 713)2 mod 713
= (20736 mod 713)2 mod 713
= 592 mod 713 = 3481 mod 713 = 629
Inverses
Normal arithmetic has the Cancellation Law for Multiplication (T7 of Appendix A (Epp)):
For integers a, b, c with a ≠ 0, if ab = ac
then
b = c.
This is not true in modulo arithmetic:
ab ≡ ac (mod n) does not imply b ≡ c (mod n)

Example:
Clearly, 3 × 1 ≡ 3 × 5 (mod 6).
But, 1 5 (mod 6).
When “cancelling" a on both sides of Equation ab=ac, we are really multiplying with the
multiplicative inverse of a. By definition, the multiplicative inverse is a number b such that
ab = 1. Thus we need a suitable inverse that works with modulo arithmetic.

Definition 4.7.2 (Multiplicative inverse modulo n)


For any integers a, n with n > 1, if an integer s is such that as ≡ 1 (mod n), then s is
called the multiplicative inverse of a modulo n. We may write the inverse as a-1.
Because the commutative law still applies in modulo arithmetic, we also have
a-1a ≡ 1 (mod n)

Note that multiplicative inverses are not unique, since if s is such an inverse, then so is
(s + kn) for any integer k (Why?)

Example: Consider a = 5 and n = 9: By inspection, 5 · 2 ≡ 1 (mod 9), so 5-1 = 2 mod 9.


Other multiplicative inverses include: 2+9 = 11; 2-9 = -7; 2 + 900 = 902.
Given any integer a, its multiplicative inverse a-1 may not exist. This next theorem tells
us exactly when it exists.
Theorem 4.7.3 (Existence of multiplicative inverse)
For any integer a, its multiplicative inverse modulo n (where n > 1), a-1, exists if, and only
if, a and n are coprime.
Recall that two numbers are coprime, or relatively prime, iff their gcd is 1.

Corollary 4.7.4 (Special case: n is prime)


If n = p is a prime number, then all integers a in the range 0 < a < p have multiplicative
inverses modulo p
Proof: (Forward direction)
1. For any integers a, n with n > 1:
2. If a-1 exists:
3. Then a-1a ≡ 1 (mod n), by definition of multiplicative inverse.
4. Then a-1a = 1 + kn, for some integer k, by Theorem 8.4.1 (Epp).
5. Re-write: aa-1 - nk = 1, by basic algebra.
6. (Claim: all common divisors of a and n are ±1.)
7. Take any common divisor, d, of a and n.
8. d | a and d | n by definition of common divisor.
9. So d | 1 by Line 5 and Theorem 4.1.1.
10. Thus, d = 1 or d = -1 by Theorem 4.3.2 (Epp).
11. Hence gcd(a; n) = 1
Proof: (Backward direction)
1. For any integers a; n with n > 1:
2. If gcd(a; n) = 1:
3. Then by B´ezout’s Identity, there exists integers s, t
such that as + nt = 1.
4. Thus as = 1 - tn, by basic algebra.
5. Then by Theorem 8.4.1 (Epp), as ≡ 1 (mod n).
Note that the above tells us how to find a multiplicative inverse for a modulo n: simply
run the Extended Euclidean Algorithm!
Example: Find 3-1 mod 40.
1. Since 3 is prime, and 40 = 23 · 5, it is easy to see that gcd(3, 40) = 1.
2. Also, note that 40 = 3(13) + 1.
3. Re-write: 3(-13) = 1 - 40.
4. Thus by Theorem 8.4.1 (Epp), 3(-13) ≡ 1 (mod 40).
5. Thus 3-1 = -13 mod 40.
But this is ugly. We prefer a positive inverse. This can be corrected
simply by adding a multiple of 40, eg. -13 + 40 = 27. Hence
3-1 = 27 mod 40
Example: Find 2-1 mod 4.
Note that gcd(2, 4) = 2, so 2 and 4 are not coprime.
Thus, by Theorem 4.7.3, 2-1 does not exist.
Indeed, we can check this:
2 · 1 ≡ 2 (mod 4),
2 · 2 ≡ 0 (mod 4),
2 · 3 ≡ 2 (mod 4),
By Theorem 8.4.3 (Epp), these calculations suffice to conclude that 2-1
does not exist
The use of multiplicative inverses leads us to a Cancellation Law for modulo arithmetic:

Theorem 8.4.9 (Epp)


For all integers a, b, c, n, with n > 1 and a and n are coprime,
if ab ≡ ac (mod n), then b ≡ c (mod n).

Proof sketch
Since a and n are coprime, Theorem 4.7.3 guarantees the existence of a multiplicative
inverse a-1.
Multiply both sides of ab ≡ ac (mod n) with a-1 gives the desired answer.
Quiz: In T7 of Appendix A (Epp) (Cancellation Law for integers), it is explicitly stated
that a ≠ 0. Yet the above theorem doesn’t seem to require this. Why not?
Example:
Solve the equation 5x + 13y = 75 for integers x, y.
1. Re-write: 5x = 75 - 13y.
2. Then 5x ≡ 75 (mod 13), by Theorem 8.4.1 (Epp).
3. Re-write: 5x ≡ 5 · 15 (mod 13).
4. Note that 5 and 13 are coprime.
5. Thus, x ≡ 15 (mod 13), by Theorem 8.4.9 (Epp).
6. Thus, x ≡ 2 (mod 13), because 15 mod 13 = 2.
7. So x = 2 is a solution.
8. Substituting back into the equation: 5(2) + 13y = 75.
9. And thus y = 5.
Other solutions include: (x; y) = (15, 0), (-11, 10), (28, -5).
Definition 4.7.1 (Congruence modulo)
Let m and n be integers, and let d be a positive integer. We say that m is congruent to n
modulo d, and write: m ≡ n (mod d)
if, and only if, d | (m - n)
Symbolically: m ≡ n (mod d) ↔ d | (m - n)

Theorem 8.4.1 (Epp): Modular Equivalences


Let a; b, and n be any integers and suppose n > 1.
The following statements are all equivalent:
1. n | (a - b) 2. a ≡ b (mod n)
3. a = b + kn for some integer k
4. a and b have the same (non-negative) remainder when divided by n
5. a mod n = b mod n
Theorem 8.4.3 (Epp): Modulo Arithmetic
Let a, b, c, d and n be integers with n > 1, and suppose:
a ≡ c (mod n) and b ≡ d (mod n)
Then
1. (a + b) ≡ (c + d) (mod n)
2. (a - b) ≡ (c - d) (mod n)
3. ab ≡ cd (mod n)
4. am ≡ cm (mod n), for all positive integers m

Corollary 8.4.4 (Epp)


Let a, b, n be integers with n > 1. Then, ab ≡ [(a mod n)(b mod n)] (mod n)
or, equivalently, ab mod n = [(a mod n)(b mod n)] mod n.
In particular, if m is a positive integer, then am ≡ [(a mod n)m] (mod n)
Normal arithmetic has the Cancellation Law for Multiplication (T7 of Appendix A (Epp)):
For integers a, b, c with a ≠ 0, if ab = ac
then
b = c.
This is not true in modulo arithmetic:
ab ≡ ac (mod n) does not imply b ≡ c (mod n)

Definition 4.7.2 (Multiplicative inverse modulo n)


For any integers a, n with n > 1, if an integer s is such that as ≡ 1 (mod n), then s is
called the multiplicative inverse of a modulo n. We may write the inverse as a-1.
Because the commutative law still applies in modulo arithmetic, we also have
a-1a ≡ 1 (mod n)
Theorem 4.7.3 (Existence of multiplicative inverse)
For any integer a, its multiplicative inverse modulo n (where n > 1), a-1, exists if, and only
if, a and n are coprime.

Corollary 4.7.4 (Special case: n is prime)


If n = p is a prime number, then all integers a in the range 0 < a < p have multiplicative
inverses modulo p

Theorem 8.4.9 (Epp)


For all integers a, b, c, n, with n > 1 and a and n are coprime,
if ab ≡ ac (mod n), then b ≡ c (mod n).
END OF FILE

You might also like