+ All Categories
Home > Documents > Modular ArithmeticCongruence (modulo m) Informally: Two integers are congruent modulo a natural...

Modular ArithmeticCongruence (modulo m) Informally: Two integers are congruent modulo a natural...

Date post: 08-Aug-2020
Category:
Upload: others
View: 0 times
Download: 0 times
Share this document with a friend
43
Modular Arithmetic CS 2800: Discrete Structures, Fall 2014 Sid Chaudhuri
Transcript
Page 1: Modular ArithmeticCongruence (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

Modular Arithmetic

CS 2800: Discrete Structures, Fall 2014

Sid Chaudhuri

Page 2: Modular ArithmeticCongruence (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

Follow-up exercise

Read up on Euclid's Algorithm for fnding the Greatest Common Divisor of

two natural numbers

Page 3: Modular ArithmeticCongruence (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

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

Page 4: Modular ArithmeticCongruence (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

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!

Page 5: Modular ArithmeticCongruence (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

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)

Page 6: Modular ArithmeticCongruence (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

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

Page 7: Modular ArithmeticCongruence (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

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

Page 8: Modular ArithmeticCongruence (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

300m ≡ 9900m (modulo 400)

Page 9: Modular ArithmeticCongruence (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

300m ≡ 9900m (modulo 400)

Discards absolute information (days, hours, laps...)!

Page 10: Modular ArithmeticCongruence (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

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

Page 11: Modular ArithmeticCongruence (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

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

Page 12: Modular ArithmeticCongruence (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

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

Page 13: Modular ArithmeticCongruence (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

Congruence ⇔ Same remainder

● Claim: a ≡ b (mod m) if a mod m = b mod m

Page 14: Modular ArithmeticCongruence (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

Congruence ⇔ Same remainder

● Claim: a ≡ b (mod m) if a mod m = b mod m

● Proof:(⇐)

Given: a mod m = b mod m

Page 15: Modular ArithmeticCongruence (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

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

Page 16: Modular ArithmeticCongruence (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

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)

Page 17: Modular ArithmeticCongruence (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

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

Page 18: Modular ArithmeticCongruence (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

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)

Page 19: Modular ArithmeticCongruence (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

Congruence ⇔ Same remainder

● Proof: (⇒) Given: a ≡ b (mod m)

Page 20: Modular ArithmeticCongruence (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

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

Page 21: Modular ArithmeticCongruence (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

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!

Page 22: Modular ArithmeticCongruence (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

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!

Page 23: Modular ArithmeticCongruence (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

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!

Page 24: Modular ArithmeticCongruence (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

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)

Page 25: Modular ArithmeticCongruence (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

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)

Page 26: Modular ArithmeticCongruence (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

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)

Page 27: Modular ArithmeticCongruence (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

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)

Page 28: Modular ArithmeticCongruence (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

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)

Page 29: Modular ArithmeticCongruence (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

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)

Page 30: Modular ArithmeticCongruence (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

a ≡ b (mod m), c ≡ d (mod m)⇒ a + c ≡ b + d (mod m)

Page 31: Modular ArithmeticCongruence (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

a ≡ b (mod m), c ≡ d (mod m)⇒ a + c ≡ b + d (mod m)

Proof: a ≡ b (mod m), c ≡ d (mod m)

Page 32: Modular ArithmeticCongruence (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

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

Page 33: Modular ArithmeticCongruence (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

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))

Page 34: Modular ArithmeticCongruence (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

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)

Page 35: Modular ArithmeticCongruence (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

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)

Page 36: Modular ArithmeticCongruence (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

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)

Page 37: Modular ArithmeticCongruence (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

a ≡ b (mod m), c ≡ d (mod m)⇒ ac ≡ bd (mod m)

Page 38: Modular ArithmeticCongruence (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

a ≡ b (mod m), c ≡ d (mod m)⇒ ac ≡ bd (mod m)

Proof: a ≡ b (mod m), c ≡ d (mod m)

Page 39: Modular ArithmeticCongruence (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

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'

Page 40: Modular ArithmeticCongruence (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

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

Page 41: Modular ArithmeticCongruence (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

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

Page 42: Modular ArithmeticCongruence (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

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

Page 43: Modular ArithmeticCongruence (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

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)


Recommended