1 / 24

Modular Arithmetic

Modular Arithmetic. Lecture 13: Oct 24. (based on slides in MIT 6.042). Last Time. Euclid’s algorithm to compute gcd(a,b). gcd(a,b) = sa + tb. Use this to solve Die Hard’s water jug problem. How to find s and t so that gcd(a,b) = sa + tb??. Method: apply Euclidean algorithm, finding

Download Presentation

Modular Arithmetic

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Modular Arithmetic Lecture 13: Oct 24 (based on slides in MIT 6.042)

  2. Last Time • Euclid’s algorithm to compute gcd(a,b). • gcd(a,b) = sa + tb. • Use this to solve Die Hard’s water jug problem. How to find s and t so that gcd(a,b) = sa + tb?? Method: apply Euclidean algorithm, finding coefficients as you go.

  3. GCD Algorithm Example: a = 899, b=493 899 = 1·493 + 406 493 = 1·406 + 87 406 = 4·87 + 58 87 = 1·58 + 29 58 = 2·29 + 0 done, gcd = 29

  4. Extended GCD Algorithm Example: a = 899, b=493 899 = 1·493 + 406 so 406 = 1·899 + -1·493 493 = 1·406 + 87 so 87 = 493 –1·406 = -1·899 + 2·493 406 = 4·87 + 58 so 58 = 406 - 4·87 = 5·899 + -9·493 87 = 1·58 + 29 so 29 = 87 – 1·58 = -6·899 + 11·493 58 = 2·29 + 0 done, gcd = 29

  5. Extended GCD Algorithm Example: a = 899, b=493 899 = 1·493 + 406 so 406 = 1·899 + -1·493 493 =1·406 + 87 so 87 = 493 – 1·406 = -1·899 + 2·493 406 = 4·87 + 58 so 58 = 406 - 4·87 = 5·899 + -9·493 87 =1·58 + 29 so 29 = 87 – 58 = -6·899 + 11·493 58 = 2·29 + 0 done, gcd = 29 s = -6, t = 11

  6. Another Example

  7. Die Hard Given jug of 21 and jug of 26, is it possible to have exactly 11 gallons in one jug? • gcd(21,26) = 1 • 5x21 – 4x26 = 1 • 55x21 – 44x26 = 11 Can we save some water?? • 26x21 – 21x26 = 0 • 52x21 – 42x26 = 0 Therefore, 3x21 – 2x26 = 11.

  8. Prime Divisibility Lemma:p prime and p|a·b implies p|a or p|b. pf: say p does not divide a. so gcd(p,a)=1. So by the Theorem, there exist s and t such that sa + tp = 1 (sa)b + (tp)b = b p| p| p| Cor : If p is prime, and p| a1·a2···amthen p|aifor some i.

  9. Fundamental Theorem of Arithmetic Every integer, n>1, has a unique factorization into primes: p0≤ p1 ≤ ··· ≤ pk p0p1 ··· pk = n Example: 61394323221 = 3·3·3·7·11·11·37·37·37·53

  10. Prime Products Claim: Every integer > 1 is a product of primes. Proof:(by contradiction) Supposenot. Then set of non-products is nonempty. By WOP, there is a least n > 1 that is not a product of primes. In particular, n is not prime. • So n = k·m for integers k, m where n > k,m >1. • Since k,m smaller than the leastnonproduct, • both are prime products, eg., • k = p1 p2p94 • m = q1 q2   q214

  11. Prime Products Claim: Every integer > 1 is a product of primes. …So n = k m = p1 p2p94q1q2 q214 is a prime product, a contradiction.  The set of nonproducts > 1 must be empty. QED

  12. Unique Factorization Claim: There is a unique factorization. pf: suppose not. choose smallestn >1: n = p1·p2···pk = q1·q2···qm p1p2···pk q1q2···qm can assume q1 < p1 so q1  pi all i

  13. Unique Factorization Claim: There is a unique factorization. pf: n = p1·p2···pk = q1·q2···qm now p1|n, soby Cor., p1|qi . so p1 = qi with i >1. so p2···pk = q1·q2···qi-1·qi+1···qm and q1  p2 contradiction! Cor : if n = p1·p2···pk , and m|n,then

  14. Modular Arithmetic Def:a  b (mod n) iff n|(a - b). For example, 15  29 (mod 7). Theorem. a  b (mod n) iff rem(a, n) = rem(b, n). • a = qn + r • b = q’n + r’ • n | (a-b) iff r = r’ Corollary. a  rem(a,n) (mod n)

  15. Modular Addition Lemma: If a  a’ (mod n), and b  b’ (mod n) then a+b  a’+b’ (mod n). pf: n| (a – a’) and n| (b – b’) implies n| ((a+b) – (a’+b’))

  16. Modular Multiplication Lemma: If a  a’ (mod n), and b  b’ (mod n) then ab  a’b’ (mod n). • pf: n| (a – a’) and n| (b – b’) implies • a – a’ = pn and b – b’ = qn implies • ab = (pn + a’)(qn + b’) • = pqn + a’qn + b’pn + a’b’ • = (pq+aq’+b’p)n + a’b’ • n | (ab – a’b’)

  17. Application Why is a number written in decimal evenly divisible by 9 if and only if the sum of its digits is a multiple of 9? Hint: 10  1 (mod 9).

  18. Multiplication Inverse The multiplicative inverse of a number a is another number a’ such that: a · a’ = 1 (mod n) Does every number has a multiplicative inverse in modular arithmetic?

  19. Multiplication Inverse Does every number has a multiplicative inverse in modular arithmetic? Nope…

  20. Multiplication Inverse What is the pattern?

  21. Multiplication Inverse Theorem. If gcd(k,n)=1, then have k’ k·k’  1 (mod n). k’ is an inversemod n of k pf: sk + tn = 1. So tn = 1 - sk This means n | 1 - sk just let k’ = s .

  22. Cancellation So  (mod n) a lot like =. main diff: can’t cancel 4·2  1·2 (mod 6) 4  1 (mod 6) No general cancellation Cor: If i·k  j·k (mod n), andgcd(k,n) = 1, then i  j (mod n) pf: multiply inverse of k to both sides.

  23. Fermat’s Little Theorem If p is prime & k not a multiple of p, can cancel k. So k, 2k, …, (p-1)k are all different (mod p). So their remainders on division by p are all different (mod p). This means that rem(k, p), rem(2k, p),…,rem((p-1)k, p) must be a permutation of 1, 2, ···, (p-1)

  24. Fermat’s Little Theorem so 1·2···(p-1) = rem(k,p)·rem(2k,p)···rem((p-1)k,p)  (k)·(2k) ··· ((p-1)k) (mod p)  (kp-1)·1·2 ··· (p-1) (mod p) so 1  kp-1 (mod p)

More Related