330 likes | 787 Vues
Modular Arithmetic. Lecture 9: Oct 5. Modular Arithmetic. Def : a b (mod n) iff n|( a - b) iff a mod n = b mod n. e.g. 12 2 (mod 10) 107 207 (mod 10) 7 1 (mod 2) 1 -1 (mod 2) 13 -1 (mod 7) -15 0 (mod 5). Modular Addition.
E N D
Modular Arithmetic Lecture 9: Oct 5
Modular Arithmetic Def:a b (mod n) iff n|(a - b) iff a mod n = b mod n. e.g. 12 2 (mod 10) 107 207 (mod 10) 7 1 (mod 2) 1 -1 (mod 2) 13 -1 (mod 7) -15 0 (mod 5)
Modular Addition Lemma: If a c (mod n), and b d (mod n) then a+b c+d (mod n). Example 1 12 2 (mod 10), 25 5 (mod 10) => 12 + 25 (mod 10) 2 + 5 (mod 10) 7 (mod 10) Example 2 87 2 (mod 17), 222 1 (mod 17) => 87 + 222 (mod 17) 2 + 1 (mod 17) 3 (mod 17) Example 3 101 2 (mod 11), 141 -2 (mod 11) => 101 + 141 (mod 11) 0 (mod 11)
Modular Addition Lemma: If a c (mod n), and b d (mod n) then a+b c+d (mod n). a c (mod n) => a = c + nx for some integer x b d (mod n) => b = d + ny for some integer y To show a+b c+d (mod n), it is equivalent to showing that n | (a+b-c-d). Consider a+b-c-d. a+b-c-d = (c+nx) + (d+ny) – c –d = nx + ny. It is clear that n | nx + ny. Therefore, n | a+b-c-d. We conclude that a+b c+d (mod n). Proof
Modular Multiplication Lemma: If a c (mod n), and b d (mod n) then ab cd (mod n). Example 1 9876 6 (mod 10), 17642 2 (mod 10) => 9876 * 17642 (mod 10) 6 * 2 (mod 10) 2 (mod 10) Example 2 10987 1 (mod 2), 28663 1 (mod 2) => 10987 * 28663 (mod 2) 1 (mod 2) Example 3 999 5 (mod 7), 674 2 (mod 7) => 999 * 674 (mod 7) 5 * 2 (mod 7) 3 (mod 7)
Modular Multiplication Lemma: If a c (mod n), and b d (mod n) then ab cd (mod n). Proof a c (mod n) => a = c + nx for some integer x b d (mod n) => b = d + ny for some integer y To show ab cd (mod n), it is equivalent to showing that n | (ab-cd). Consider ab-cd. ab-cd = (c+nx) (d+ny) – cd = cd + dnx + cny + n2xy – cd = n(dx + cy + nxy). It is clear that n | n(dx + cy + nxy). Therefore, n | ab-cd. We conclude that ab cd (mod n).
Exercise 1444 mod 713 = 144 * 144 * 144 * 144 mod 713 = 20736 * 144 * 144 mod 713 = 59 * 144 * 144 mod 713 = 8496 * 144 mod 713 = 653 * 144 mod 713 = 94032 mod 713 = 629 mod 713 20736 * 20736 mod 713 = 59 * 59 mod 713 = 3481 mod 713 = 629 mod 713
Application Is a number written in decimal evenly divisible by 9 if and only if the sum of its digits is a multiple of 9? Example 1. 9333234513171 is divisible by 9. 9+3+3+3+2+3+4+5+1+3+1+7+1 = 45 is divisible by 9. Example 2. 128573649683 is not divisible by 9. 1+2+8+5+7+3+6+4+9+6+8+3 = 62 is not divisible by 9. NO A coincidence? This can be proved easily using modular arithmetic.
Application Claim. A number written in decimal is divisible by 9 if and only if the sum of its digits is a multiple of 9? Hint: 10 1 (mod 9). Let the decimal representation of n be dkdk-1dk-2…d1d0. This means that n = dk10k + dk-110k-1 + … + d110 + d0 Note that di10i mod 9 = (di mod 9) (10i mod 9) mod 9 = (di mod 9) (10 mod 9) (10 mod 9) … (10 mod 9) mod 9 = (di mod 9) (1 mod 9) (1 mod 9) … (1 mod 9) mod 9 = di mod 9 i terms
Application Claim. A number written in decimal is divisible by 9 if and only if the sum of its digits is a multiple of 9? Hint: 10 1 (mod 9). Let the decimal representation of n be dkdk-1dk-2…d1d0. This means that n = dk10k + dk-110k-1 + … + d110 + d0 Note that di10i mod 9 = di mod 9. Hence n mod 9 = (dk10k + dk-110k-1 + … + d110 + d0) mod 9 = (dk10k mod 9 + dk-110k-1 mod 9 + … + d110 mod 9 + d0 mod 9) mod 9 = (dk mod 9 + dk-1 mod 9 + … + d1 mod 9 + d0 mod 9) mod 9 = (dk + dk-1 + … + d1 + d0) mod 9
Multiplication Inverse The multiplicative inverse of a number a is another number a’ such that: a · a’ 1 (mod n) For real numbers, every nonzero number has a multiplicative inverse. For integers, only 1 has a multiplicative inverse. An interesting property of modular arithmetic is that there are multiplicative inverse for intgers. For example, 2 * 5 = 1 mod 3, so 5 is a multiplicative inverse for 2 under modulo 3 (and vice versa). Does every number has a multiplicative inverse in modular arithmetic?
Multiplication Inverse Does every number has a multiplicative inverse in modular arithmetic?
Multiplication Inverse What is the pattern?
Multiplication Inverse Why 2 does not have a multiplicative inverse under modulo 6? Suppose it has a multiplicative inverse y. 2y 1 (mod 6) => 2y = 1 + 6x for some integer x => y = ½ + 3x This is a contradiction since both x and y are integers. Claim. An integer k does not have an multiplicative inverse under modulo n, if k and n have a common factor >= 2 (gcd(k,n) >= 2). Proof. Same as above. Leave it as an exercise.
Multiplication Inverse What about if gcd(k,n)=1? Would k always have an multiplicative inverse under modulo n? Theorem. If gcd(k,n)=1, then have k’ k·k’ 1 (mod n). k’ is an inversemod n of k gcd(k,n)=spc(k,n) Proof: Since gcd(k,n)=1, there exist s and t so that sk + tn = 1. So tn = 1 - sk This means n | 1 – sk. This means that 1 – sk 0 (mod n). This means that 1 = sk (mod n). So k’ = s is an multiplicative inverse for k.
Cancellation Note that (mod n) a lot like =. If a b (mod n), then a+c b+c (mod n). If a b (mod n), then ac bc (mod n) However, if ac bc (mod n), it is not necessarily true that a b (mod n). For example, 4·2 1·2 (mod 6), but 4 1 (mod 6) There is no general cancellation in modular arithmetic.
Cancellation Why a·k b·k (mod n) when a ≠ b? Without loss of generality, assume 0 < a < n and 0 < b < n. Because if a·k b·k (mod n), then also (a mod n)·k (b mod n)·k (mod n). smaller than n. This means that ak = bk + nx. This means that (a-b)k = nx, which means a-b=(nx)/k. Since 0 < a < n and 0 < b < n, it implies that –n < a-b < n. Therefore, nx/k must be < n. For this to happen, n and k must have a common divisor >= 2! Okay, so, can we say something when gcd(n,k)=1?
Cancellation Claim: If i·k j·k (mod n), andgcd(k,n) = 1, then i j (mod n) For example, multiplicative inverse always exists if n is a prime! Proof. Since gcd(k,n) = 1, there exists k’ such that kk’ 1 (mod n). i·k j·k (mod n). => i·k·k’ j·k·k’ (mod n). => i j (mod n) This makes arithmetic modulo prime a field, a structure that “behaves like” real numbers. Arithmetic modulo prime is very useful in coding theory.
Fermat’s Little Theorem If p is prime & k not a multiple of p, then we can cancel k. So k mod p, 2k mod p, …, (p-1)k mod p are all different. This means that k mod p, 2k mod p,…,(p-1)k mod p must be a permutation of 1, 2, ···, (p-1) (each number appears exactly once)
Fermat’s Little Theorem Theorem: If p is prime & k not a multiple of p 1 kp-1 (mod p) Proof. 1·2···(p-1) (k mod p · 2k mod p··· (p-1)k mod p) mod p (k·2k ··· (p-1)k) mod p (kp-1)·1·2 ··· (p-1) (mod p) So, by cancelling 1·2 ··· (p-1) on both sides, we have 1 kp-1 (mod p) A permutation
Wilson’s Theorem Theorem:p is a prime if and only if (p-1)! -1(mod p) First we consider the easy direction. If p is not a prime, assume p >= 5, (for p=4, 3! 2 (mod 4) ) Then p=qr for some 2 <= q < p and 2 <= r < p. If q ≠ r, then both q and r appear in (p-1)!, and so (p-1)! 0 (mod p). If q = r, then p = q2 > 2q (since we assume p > 5 and thus q > 2). then both q and 2q are in (p-1)!, and so again (p-1)! 0 (mod p).
Wilson’s Theorem Theorem:p is a prime if and only if (p-1)! -1(mod p) To prove the more interesting direction, first we need a lemma. Lemma. If p is a prime number, x2 1 (mod p) if and only if x 1 (mod p) or x -1 (mod p) Proof. x2 1 (mod p) iff p | x2- 1 iff p | (x– 1)(x + 1) iff p | (x – 1) or p | (x+1) iff x 1 (mod p) or x -1 (mod p) Lemma:p prime and p|a·b iffp|a or p|b.
Wilson’s Theorem Theorem:p is a prime if and only if (p-1)! -1(mod p) Let’s get the proof idea by considering a concrete example. 10! 1·2·3·4·5·6·7·8·9·10 mod 11 1·10·(2·6)·(3·4)·(5·9)·(7·8) mod 11 1·-1·(1)·(1)·(1)·(1) mod 11 -1 mod 11 Besides 1 and 10, the remaining numbers are paired up into multiplicative inverse!
Wilson’s Theorem Theorem:p is a prime if and only if (p-1)! -1(mod p) Proof. Since p is a prime, every number from 1 to p-1 has a multiplicative inverse. By the Lemma, every number 2 <= k <= p-2 has an inverse k’ with k≠k’. Since p is odd, the numbers from 2 to p-2 can be grouped into pairs (a1,b1),(a2,b2),…,(a(p-3)/2,b(p-3)/2) so that aibi 1 (mod p) Therefore, (p-1)! 1·(p-1)·2·3·····(p-3)·(p-2) (mod p) 1·(p-1)·(a1b1)·(a2b2)·····(a(p-3)/2b(p-3)/2) (mod p) 1·(-1)·(1)·(1)·····(1) (mod p) -1 (mod p)