Announcements CS311H: Discrete Mathematics More Number Theory

Announcements
CS311H: Discrete Mathematics
More Number Theory
I¸sıl Dillig
I¸sıl Dillig,
CS311H: Discrete Mathematics
More Number Theory
Suppose a and b are integers, not both 0.
I
Then, the largest integer d such that d |a and d |b is called
greatest common divisor of a and b, written gcd(a,b).
I
Example: gcd(24, 36) =
I
Example: gcd(23 5, 22 3) =
I
Example: gcd(14, 25) =
I
Two numbers whose gcd is 1 are called relatively prime.
I
Example: 14 and 25 are relatively prime
More Number Theory
3/32
I
Mean: 49 out of 65
CS311H: Discrete Mathematics
More Number Theory
2/32
I
The least common multiple of a and b, written lcm(a,b), is
the smallest integer c such that a|c and b|c.
I
Example: lcm(9, 12)=
I
Example: lcm(23 35 72 , 24 33 )=
CS311H: Discrete Mathematics
More Number Theory
4/32
Proof, cont.
I
Theorem: Let a and b be positive integers. Then,
ab = gcd(a, b) · lcm(a, b)
I
Proof: Let a = p1i1 p2i2 . . . pnin and b = p1j1 p2j2 . . . pnjn
I
Then, ab = p1i1 +j1 p2i2 +j2 . . . pnin +jn
I
gcd(a, b) = p1
I
lcm(a, b) = p1
I
Thus, we need to show ik + jk = min(ik , jk ) + max (ik , jk )
min(i1 ,j1 ) min(i2 ,j2 )
min(in ,jn )
p2
. . . pn
max (i1 ,j1 ) max (i2 ,j2 )
max (in ,jn )
p2
. . . pn
CS311H: Discrete Mathematics
Midterm 1 graded: solutions on Piazza, grades on Canvas
I¸sıl Dillig,
Theorem about LCM and GCD
I¸sıl Dillig,
I
Least Common Multiple
I
CS311H: Discrete Mathematics
Homework 4 out today – due on Thursday, Oct 16
I¸sıl Dillig,
1/32
Greatest Common Divisors
I¸sıl Dillig,
I
More Number Theory
I¸sıl Dillig,
5/32
1
I
Show ik + jk = min(ik , jk ) + max (ik , jk )
I
Either (i) ik < jk or (ii) ik ≥ jk
I
If (i), then min(ik , jk ) = ik and max (ik , jk ) = jk
I
Thus, ik + jk = min(ik , jk ) + max (ik , jk )
I
If (ii), then min(ik , jk ) = jk and max (ik , jk ) = ik
I
Hence min(ik , jk ) + max (ik , jk ) = ik + jk
CS311H: Discrete Mathematics
More Number Theory
6/32
Computing GCDs
I
Insight Behind Euclid’s Algorithm
Simple algorithm to compute gcd of a, b:
I
Factorize a as p1i1 p2i2 . . . pnin
I
Factorize b as p1j1 p2j2 . . . pnjn
I
gcd(a, b) =
min(i1 ,j1 ) min(i2 ,j2 )
p2
p1
But this algorithm is not very practical because prime
factorization is computationally expensive!
I
Much more efficient algorithm to compute gcd, called the
Euclidian algorithm
I¸sıl Dillig,
CS311H: Discrete Mathematics
More Number Theory
Theorem: Let a = bq + r . Then, gcd(a, b) = gcd(b, r )
I
Proof: We’ll show that a, b and b, r have the same common
divisors – implies they have the same gcd.
⇒ Suppose d is a common divisor of a, b, i.e., d |a and d |b
min(in ,jn )
. . . pn
I
I
I
By theorem we proved earlier, this implies d |a − bq
I
Since a − bq = r , d |r . Hence d is common divisor of b, r .
⇐ Now, suppose d |b and d |r . Then, d |bq + r
I
Hence, d |a and d is common divisor of a, b
I¸sıl Dillig,
7/32
Using this Theorem
CS311H: Discrete Mathematics
More Number Theory
8/32
Euclidian Algorithm
Theorem: Let a = bq + r . Then, gcd(a, b) = gcd(b, r )
I
Theorem suggests following strategy to compute gcd(a, b):
I
Compute r1 = a mod b (gcd(a, b) = gcd(b, r1 ))
I
Compute r2 = b mod r1 (gcd(a, b) = gcd(r1 , r2 ))
I
Compute r3 = r1 mod r2 (gcd(a, b) = gcd(r2 , r3 ))
I
Repeat until remainder becomes 0
(gcd(a, b) = gcd(rn , 0) = rn )
I
I¸sıl Dillig,
Find gcd of 72 and 20
I
12 = 72%20
I
8 = 20%12
I
4 = 12%8
I
0 = 8%4
I
gcd is 4!
The last non-zero remainder is the gcd of a and b!
CS311H: Discrete Mathematics
More Number Theory
I¸sıl Dillig,
9/32
Euclidian Algorithm Example
I¸sıl Dillig,
I
CS311H: Discrete Mathematics
CS311H: Discrete Mathematics
More Number Theory
10/32
GCD as Linear Combination
I
Find gcd of 662 and 414
I
248 = 662%414
I
166 = 414%248
I
82 = 248%166
I
2 = 166%82
I
0 = 82%2
I
gcd is 2!
More Number Theory
I
gcd(a, b) can be expressed as a linear combination of a and b
I
Theorem: If a and b are positive integers, then there exist
integers s and t such that:
gcd(a, b) = s · a + t · b
I
I¸sıl Dillig,
11/32
2
Furthermore, Euclidian algorithm gives us a way to compute
these integers s and t
CS311H: Discrete Mathematics
More Number Theory
12/32
Example
Example, cont.
I
Express gcd(252, 198) as a linear combination of 252 and 198
I
First apply Euclid’s algorithm (write a = bq + r at each step):
18 = (252 − 1 · 198) − 1(198 − 3 · (252 − 1 · 198))
I
1. 252 = 1 · 198 + 54
Now, let’s simplify this:
18 = 252 − 1 · 198 − 1 · 198 + 3 · 252 − 3 · 198
2. 198 = 3 · 54 + 36
3. 54 = 1 · 36 + 18
I
4. 36 = 2 · 18 + 0 ⇒ gcd is 18
I
Now, using (3), write 18 as 54 − 1 · 36
I
Using (2), write 18 as 54 − 1 · (198 − 3 · 54)
I
Using (1), we have 54 = 252 − 1 · 198, thus:
18 = 4 · 252 − 5 · 198
I
CS311H: Discrete Mathematics
More Number Theory
I
This is known as the extended Euclidian algorithm
I¸sıl Dillig,
13/32
Exercise
CS311H: Discrete Mathematics
More Number Theory
14/32
A Useful Result
Use the extended Euclid algorithm to compute gcd(38, 16).
I¸sıl Dillig,
Trace steps of Euclid’s algorithm backwards to derive s, t:
gcd(a, b) = s · a + t · b
18 = (252 − 1 · 198) − 1(198 − 3 · (252 − 1 · 198))
I¸sıl Dillig,
Now, collect all 252 and 198 terms together:
CS311H: Discrete Mathematics
More Number Theory
15/32
I
Lemma: If a, b are relatively prime and a|bc, then a|c.
I
Proof: Since a, b are relatively prime gcd(a, b) = 1
I
By previous theorem, there exists s, t such that 1 = s · a + t · b
I
Multiply both sides by c: c = csa + ctb
I
By earlier theorem, since a|bc, a|ctb
I
Also, by earlier theorem, a|csa
I
Therefore, a|csa + ctb, which implies a|c since c = csa + ctb
I¸sıl Dillig,
Example
CS311H: Discrete Mathematics
More Number Theory
16/32
Question
I
Lemma: If a, b are relatively prime and a|bc, then a|c.
Suppose ca ≡ cb (mod m). Does this imply a ≡ b (mod m)?
I
I
Suppose 15 | 16 · x
I
I
Here 15 and 16 are relatively prime
I
I
Thus, previous theorem implies: 15|x
I
I
I¸sıl Dillig,
CS311H: Discrete Mathematics
More Number Theory
17/32
I¸sıl Dillig,
3
CS311H: Discrete Mathematics
More Number Theory
18/32
Another Useful Result
I
Examples
Theorem: If ca ≡ cb (mod m) and gcd(c, m) = 1, then
a ≡ b (mod m)
I
If 15x ≡ 15y (mod 4), is x ≡ y (mod 4)?
I
If 8x ≡ 8y (mod 4), is x ≡ y (mod 4)?
I
I
I
I
I
I¸sıl Dillig,
CS311H: Discrete Mathematics
More Number Theory
19/32
I¸sıl Dillig,
Linear Congruences
CS311H: Discrete Mathematics
A congruence of the form ax ≡ b (mod m) where a, b, m are
integers and x a variable is called a linear congruence.
I
Given such a linear congruence, often need to answer:
1. Are there any solutions?
I
Theorem: The linear congruence ax ≡ b (mod m) has
solutions iff gcd(a, m)|b.
I
Proof involves two steps:
2. What are the solutions?
1. If ax ≡ b (mod m) has solutions, then gcd(a, m)|b.
I
Example: Does 8x ≡ 2 (mod 4) have any solutions?
I
Example: Does 8x ≡ 2 (mod 7) have any solutions?
I
Question: Is there a systematic way to solve linear
congruences?
CS311H: Discrete Mathematics
More Number Theory
2. If gcd(a, m)|b, then ax ≡ b (mod m) has solutions.
I
First prove (1), then (2).
I¸sıl Dillig,
21/32
Proof, Part I
CS311H: Discrete Mathematics
More Number Theory
22/32
Proof, Part II
If gcd(a, m)|b, then ax ≡ b (mod m) has solutions.
If ax ≡ b (mod m) has solutions, then gcd(a, m)|b.
I¸sıl Dillig,
20/32
Determining Existence of Solutions
I
I¸sıl Dillig,
More Number Theory
I
Suppose c is a solution, i.e., ac ≡ b (mod m)
I
Then, m|(ac − b)
I
Means there is a k such that ac − b = mk
I
Rewrite as b = ac − mk
I
gcd(a, m)|a and gcd(a, m)|m; hence, gcd(a, m) | (ac − mk )
I
Since b = ac − mk , we have gcd(a, m)|b
CS311H: Discrete Mathematics
More Number Theory
23/32
I¸sıl Dillig,
4
I
Let d = gcd(a, m) and suppose d |b
I
Then, there is a k such that b = dk
I
By earlier theorem, there exist s, t such that d = s · a + t · m
I
Multiply both sides by k : dk = a · (sk ) + m · (tk )
I
Since b = dk , we have b − a · (sk ) = m · tk
I
Thus, b ≡ a · (sk ) (mod m)
I
Hence, sk is a solution.
CS311H: Discrete Mathematics
More Number Theory
24/32
Examples
Examples
I
Does 5x ≡ 7 (mod 15) have any solutions?
I
Does 3x ≡ 4 (mod 7) have any solutions?
I
Note: This result generalizes to linear Diophantine equations
I
Equality a1 x1 + a2 x2 + . . . + an xn = b has integer solutions iff
I
Does 77x + 42y = 35 have integer solutions?
I
Does 6x + 9y + 12z = 7 have integer solutions?
gcd(a1 , a2 , . . . , an )|b
I
Previous result just an instance of this because
ax ≡ b (mod m) can be written as ax − mk = b
I¸sıl Dillig,
CS311H: Discrete Mathematics
More Number Theory
25/32
I¸sıl Dillig,
Finding Solutions
CS311H: Discrete Mathematics
More Number Theory
26/32
Example
Let d = gcd(a, m) = sa + tm. If d |b, then the solutions to
ax ≡ b (mod m) are given by:
I
Can determine existence of solutions, but how to find them?
I
Theorem: Let d = gcd(a, m) = sa + tm. If d |b, then the
solutions to ax ≡ b (mod m) are given by:
x=
x=
I
sb
m
+ u where u ∈ Z
d
d
What are the solutions to the linear congruence 3x ≡ 4 (mod 7)?
I
sb
m
+ u where u ∈ Z
d
d
I
I
I
I¸sıl Dillig,
CS311H: Discrete Mathematics
More Number Theory
I¸sıl Dillig,
27/32
Another Example
I
28/32
What are the solutions to the linear congruence 3x ≡ 1 (mod 7)?
I
Theorem: Inverse of a modulo m exists if and only if a and m
are relatively prime.
I
Proof: Inverse must satisfy ax ≡ 1 (mod m)
I
I
I
I
I
CS311H: Discrete Mathematics
More Number Theory
The inverse of a modulo m, written a has the property:
aa ≡ 1 (mod m)
m
sb
x=
+ u where u ∈ Z
d
d
I¸sıl Dillig,
More Number Theory
Inverse Modulo m
Let d = gcd(a, m) = sa + tm. If d |b, then the solutions to
ax ≡ b (mod m) are given by:
I
CS311H: Discrete Mathematics
29/32
I¸sıl Dillig,
5
Does 3 have an inverse modulo 7?
CS311H: Discrete Mathematics
More Number Theory
30/32
Example
Example 2
I
Find an inverse of 3 modulo 7.
I
An inverse is any solution to 3x ≡ 1 (mod 7)
I
Earlier, we already computed solutions for this equation as:
x = −2 + 7u
I¸sıl Dillig,
I
Thus, −2 is an inverse of 3 modulo 7
I
5, 12, −9, . . . are also inverses
CS311H: Discrete Mathematics
More Number Theory
I
Find inverse of 2 modulo 5.
I
Need to solve the congruence 2x ≡ 1 (mod 5)
I
What are s, t such that 2s + 5t = 1?
I
I
31/32
I¸sıl Dillig,
6
CS311H: Discrete Mathematics
More Number Theory
32/32