modular arithmeticcongruence (modulo m) informally: two integers are congruent modulo a natural...
TRANSCRIPT
Modular Arithmetic
CS 2800: Discrete Structures, Fall 2014
Sid Chaudhuri
Follow-up exercise
Read up on Euclid's Algorithm for fnding the Greatest Common Divisor of
two natural numbers
Congruence (modulo m)
● Informally: Two integers are congruent modulo a natural number m if and only if they have the same remainder upon division by m
Congruence (modulo m)
● Informally: Two integers are congruent modulo a natural number m if and only if they have the same remainder upon division by m
NOT the definition!
Congruence (modulo m)
● Informally: Two integers are congruent modulo a natural number m if and only if they have the same remainder upon division by m
E.g. 3 ≡ 7 (mod 2) 9 ≡ 99 (mod 10)11999 ≡ 1 (mod 10)
4am ≡ 4pm (modulo 12h)4pm Nov 12 ≡ 4pm Nov 13 (modulo 24h)
12
3
6
9
12
4
57
8
10
11 12
3
6
9
12
4
57
8
10
11
1:25 ≡ 10:25 (modulo 60 mins)
12
3
6
9
12
4
57
8
10
11 12
3
6
9
12
4
57
8
10
11
300m ≡ 9900m (modulo 400)
300m ≡ 9900m (modulo 400)
Discards absolute information (days, hours, laps...)!
The formal defnition
● Let a, b ∈ ℤ, m ∈ ℕ. a and b are said to be congruent modulo m, written a ≡ b (mod m), if and only if a – b is divisible by m– … i.e. if m | a – b
– … i.e. if there is some integer k such that a – b = km
The formal defnition
● Let a, b ∈ ℤ, m ∈ ℕ. a and b are said to be congruent modulo m, written a ≡ b (mod m), if and only if a – b is divisible by m– … i.e. if m | a – b
– … i.e. if there is some integer k such that a – b = km
Doesn't include zero
The formal defnition
● Let a, b ∈ ℤ, m ∈ ℕ. a and b are said to be congruent modulo m, written a ≡ b (mod m), if and only if a – b is divisible by m– … i.e. if m | a – b
– … i.e. if there is some integer k such that a – b = km
● Note: this does not directly say a and b have the same remainder upon division by m– That is a consequence of the defnition
Doesn't include zero
Congruence ⇔ Same remainder
● Claim: a ≡ b (mod m) if a mod m = b mod m
Congruence ⇔ Same remainder
● Claim: a ≡ b (mod m) if a mod m = b mod m
● Proof:(⇐)
Given: a mod m = b mod m
Congruence ⇔ Same remainder
● Claim: a ≡ b (mod m) if a mod m = b mod m
● Proof:(⇐)
Given: a mod m = b mod m
⇒ ∃ q1, q
2, r such that a = q
1m + r, b = q
2m + r
Congruence ⇔ Same remainder
● Claim: a ≡ b (mod m) if a mod m = b mod m
● Proof:(⇐)
Given: a mod m = b mod m
⇒ ∃ q1, q
2, r such that a = q
1m + r, b = q
2m + r
⇒ a – b = q1m – q
2m = m(q
1 – q
2)
Congruence ⇔ Same remainder
● Claim: a ≡ b (mod m) if a mod m = b mod m
● Proof:(⇐)
Given: a mod m = b mod m
⇒ ∃ q1, q
2, r such that a = q
1m + r, b = q
2m + r
⇒ a – b = q1m – q
2m = m(q
1 – q
2)
⇒ m | a – b
Congruence ⇔ Same remainder
● Claim: a ≡ b (mod m) if a mod m = b mod m
● Proof:(⇐)
Given: a mod m = b mod m
⇒ ∃ q1, q
2, r such that a = q
1m + r, b = q
2m + r
⇒ a – b = q1m – q
2m = m(q
1 – q
2)
⇒ m | a – b
⇒ a ≡ b (mod m)
Congruence ⇔ Same remainder
● Proof: (⇒) Given: a ≡ b (mod m)
Congruence ⇔ Same remainder
● Proof: (⇒) Given: a ≡ b (mod m)
Let a = q1m + r
1, b = q
2m + r
2, where 0 ≤ r
1, r
2 < m
Congruence ⇔ Same remainder
● Proof: (⇒) Given: a ≡ b (mod m)
Let a = q1m + r
1, b = q
2m + r
2, where 0 ≤ r
1, r
2 < m
Division Algorithm!
Congruence ⇔ Same remainder
● Proof: (⇒) Given: a ≡ b (mod m)
Let a = q1m + r
1, b = q
2m + r
2, where 0 ≤ r
1, r
2 < m
m | a – b
⇒ m | q1m + r
1 – q
2m – r
2
Division Algorithm!
Congruence ⇔ Same remainder
● Proof: (⇒) Given: a ≡ b (mod m)
Let a = q1m + r
1, b = q
2m + r
2, where 0 ≤ r
1, r
2 < m
m | a – b
⇒ m | q1m + r
1 – q
2m – r
2
⇒ m | r1 – r
2
Division Algorithm!
Congruence ⇔ Same remainder
● Proof: (⇒) Given: a ≡ b (mod m)
Let a = q1m + r
1, b = q
2m + r
2, where 0 ≤ r
1, r
2 < m
m | a – b
⇒ m | q1m + r
1 – q
2m – r
2
⇒ m | r1 – r
2
Division Algorithm!
Exercise: Prove thatIf a|b and a|c, then a|(b - c)
Congruence ⇔ Same remainder
● Proof: (⇒) Given: a ≡ b (mod m)
Let a = q1m + r
1, b = q
2m + r
2, where 0 ≤ r
1, r
2 < m
m | a – b
⇒ m | q1m + r
1 – q
2m – r
2
⇒ m | r1 – r
2
But – (m – 1) ≤ r1, r
2 ≤ (m – 1)
Division Algorithm!
Exercise: Prove thatIf a|b and a|c, then a|(b - c)
Congruence ⇔ Same remainder
● Proof: (⇒) Given: a ≡ b (mod m)
Let a = q1m + r
1, b = q
2m + r
2, where 0 ≤ r
1, r
2 < m
m | a – b
⇒ m | q1m + r
1 – q
2m – r
2
⇒ m | r1 – r
2
But – (m – 1) ≤ r1, r
2 ≤ (m – 1)
⇒ r1 – r
2 = 0
Division Algorithm!
Exercise: Prove thatIf a|b and a|c, then a|(b - c)
Congruence ⇔ Same remainder
● Proof: (⇒) Given: a ≡ b (mod m)
Let a = q1m + r
1, b = q
2m + r
2, where 0 ≤ r
1, r
2 < m
m | a – b
⇒ m | q1m + r
1 – q
2m – r
2
⇒ m | r1 – r
2
But – (m – 1) ≤ r1, r
2 ≤ (m – 1)
⇒ r1 – r
2 = 0
⇒ r1 = r
2
Division Algorithm!
Exercise: Prove thatIf a|b and a|c, then a|(b - c)
Congruence ⇔ Same remainder
● Proof: (⇒) Given: a ≡ b (mod m)
Let a = q1m + r
1, b = q
2m + r
2, where 0 ≤ r
1, r
2 < m
m | a – b
⇒ m | q1m + r
1 – q
2m – r
2
⇒ m | r1 – r
2
But – (m – 1) ≤ r1, r
2 ≤ (m – 1)
⇒ r1 – r
2 = 0
⇒ r1 = r
2
⇒ a mod m = b mod m
Division Algorithm!
Exercise: Prove thatIf a|b and a|c, then a|(b - c)
Properties of congruence
● If a ≡ b (mod m) and c ≡ d (mod m), then– a + c ≡ b + d (mod m)
– ac ≡ bd (mod m)
E.g. 11 ≡ 1 (mod 10) ⇒ 11999 ≡ 1999 ≡ 1 (mod 10)
9 ≡ –1 (mod 10) ⇒ 9999 ≡ (–1)999 (mod 10)
7999 ≡ 49499.7 ≡ (–1)499.7 ≡ –7 ≡ 3 (mod 10)
a ≡ b (mod m), c ≡ d (mod m)⇒ a + c ≡ b + d (mod m)
a ≡ b (mod m), c ≡ d (mod m)⇒ a + c ≡ b + d (mod m)
Proof: a ≡ b (mod m), c ≡ d (mod m)
a ≡ b (mod m), c ≡ d (mod m)⇒ a + c ≡ b + d (mod m)
Proof: a ≡ b (mod m), c ≡ d (mod m)
⇒ m | a – b and m | c – d
a ≡ b (mod m), c ≡ d (mod m)⇒ a + c ≡ b + d (mod m)
Proof: a ≡ b (mod m), c ≡ d (mod m)
⇒ m | a – b and m | c – d
⇒ m | ((a – b) + (c – d))
a ≡ b (mod m), c ≡ d (mod m)⇒ a + c ≡ b + d (mod m)
Proof: a ≡ b (mod m), c ≡ d (mod m)
⇒ m | a – b and m | c – d
⇒ m | ((a – b) + (c – d))
Exercise: Prove thatIf a|b and a|c, then a|(b + c)
a ≡ b (mod m), c ≡ d (mod m)⇒ a + c ≡ b + d (mod m)
Proof: a ≡ b (mod m), c ≡ d (mod m)
⇒ m | a – b and m | c – d
⇒ m | ((a – b) + (c – d))
⇒ m | ((a + c) – (b + d))
Exercise: Prove thatIf a|b and a|c, then a|(b + c)
a ≡ b (mod m), c ≡ d (mod m)⇒ a + c ≡ b + d (mod m)
Proof: a ≡ b (mod m), c ≡ d (mod m)
⇒ m | a – b and m | c – d
⇒ m | ((a – b) + (c – d))
⇒ m | ((a + c) – (b + d))
⇒ a + c ≡ b + d (mod m)
Exercise: Prove thatIf a|b and a|c, then a|(b + c)
a ≡ b (mod m), c ≡ d (mod m)⇒ ac ≡ bd (mod m)
a ≡ b (mod m), c ≡ d (mod m)⇒ ac ≡ bd (mod m)
Proof: a ≡ b (mod m), c ≡ d (mod m)
a ≡ b (mod m), c ≡ d (mod m)⇒ ac ≡ bd (mod m)
Proof: a ≡ b (mod m), c ≡ d (mod m)
⇒ ∃ r, r' such that
a = q1m + r b = q
2m + r
c = q'1m + r' d = q'
2m + r'
a ≡ b (mod m), c ≡ d (mod m)⇒ ac ≡ bd (mod m)
Proof: a ≡ b (mod m), c ≡ d (mod m)
⇒ ∃ r, r' such that
a = q1m + r b = q
2m + r
c = q'1m + r' d = q'
2m + r'
We proved congruence⇔ same remainder
a ≡ b (mod m), c ≡ d (mod m)⇒ ac ≡ bd (mod m)
Proof: a ≡ b (mod m), c ≡ d (mod m)
⇒ ∃ r, r' such that
a = q1m + r b = q
2m + r
c = q'1m + r' d = q'
2m + r'
⇒ ac = q1m ⋅ q'
1m + q
1m ⋅ r' + q'
1m ⋅ r + rr'
bd = q2m ⋅ q'
2m + q
2m ⋅ r' + q'
2m ⋅ r + rr'
We proved congruence⇔ same remainder
a ≡ b (mod m), c ≡ d (mod m)⇒ ac ≡ bd (mod m)
Proof: a ≡ b (mod m), c ≡ d (mod m)
⇒ ∃ r, r' such that
a = q1m + r b = q
2m + r
c = q'1m + r' d = q'
2m + r'
⇒ ac = q1m ⋅ q'
1m + q
1m ⋅ r' + q'
1m ⋅ r + rr'
bd = q2m ⋅ q'
2m + q
2m ⋅ r' + q'
2m ⋅ r + rr'
⇒ ac ≡ bd (mod m)
We proved congruence⇔ same remainder
a ≡ b (mod m), c ≡ d (mod m)⇒ ac ≡ bd (mod m)
Proof: a ≡ b (mod m), c ≡ d (mod m)
⇒ ∃ r, r' such that
a = q1m + r b = q
2m + r
c = q'1m + r' d = q'
2m + r'
⇒ ac = q1m ⋅ q'
1m + q
1m ⋅ r' + q'
1m ⋅ r + rr'
bd = q2m ⋅ q'
2m + q
2m ⋅ r' + q'
2m ⋅ r + rr'
⇒ ac ≡ bd (mod m)
We proved congruence⇔ same remainder
Note: But rr' is not in general theremainder (since it can be ≥ m)