a mod m b
play

a (mod m ) b is congruent to modulo a m b mod - PDF document

Number Theory and its Applications Modular Exponentiation Euclidean Algorithm for GCD Solving Linear Congruences Chinese Remainder Theorem and Application to Arithmetic with large numbers Covered in Sections 3.6 and 3.7 Based


  1. Number Theory and its Applications • Modular Exponentiation • Euclidean Algorithm for GCD • Solving Linear Congruences • Chinese Remainder Theorem and Application to Arithmetic with large numbers • Covered in Sections 3.6 and 3.7 Based on Rosen and slides by K. Busch 1 Modular Arithmetic Recap  Z   , m a b Z a  (mod m ) b “ is congruent to modulo ” a m b  mod mod a m b m Examples: 1   13 (mod 12 ) 0 (mod ) m m 11    5 (mod 6 ) 0 (mod ) k m m 2 1

  2. Equivalent statements a  (mod m ) b  mod mod a m b m  | m a b     , k Z a b km 3  3 mod 8 3 0 7 1 3 6 2 3 5 4 Length of line represents number 4 2

  3.  11 mod 8 3 0 7 1 11 6 2 3 5 4 Length of line represents number 5  19 mod 8 3 0 7 1 19 6 2 3 5 4 Length of line represents number 6 3

  4.   3 11 19 (mod 8 ) 0 0 0 7 1 7 1 7 1 11 3 19 6 2 6 2 6 2 3 5 3 5 3 5 4 4 4 All lines terminate in same number 7 “Congruence class” of modulo : a m   { | (mod )} S a b a b m There are congruence classes: m  , , , S S S  0 1 m 1 8 4

  5. Closure under addition: a  (mod m ) b    (mod m ) a c b d c  (mod m ) d Proof sketch: a    (mod m ) b a b sm     (  ) a c d b s t m c    (mod m ) d c d tm 9 Closure under multiplication: a  (mod m ) b    (mod m ) a c b d c  (mod m ) d Proof sketch: a    (mod m ) b a b sm     ( )( ) a c b sm d tm     bd ( ) m bt ds stm c    (mod m ) d c d tm 10 5

  6. Closure under mod:  mod ( mod ) mod a m a m m (Follows from definition of mod)  ( 7 mod 5 ) 2   ( 7 mod 5 ) mod 5 2 mod 5 2 11 Useful results for arithmetic with large numbers:    ( ) mod (( mod ) ( mod )) mod a b m a m b m m  mod (( mod )( mod )) mod ab m a m b m m (Follows from previous slides) Example:   57 55 mod 50 (( 57 mod 50 )( 55 mod 50 )) mod 50   7 5 mod 50  35 12 6

  7. Modular exponentiation b n mod Compute efficiently using m small numbers Binary expansion of n       k 1  k 1 2  2 2 2 n a a a a a a    b b b b b k 1 1 0 k 1 1 0 n mod b m   k 1 a 2 2 a  a  mod b b b m k 1 1 0  1  k    2 2 a  a a ((  mod ) ( mod ) ( mod )) mod b m b m b m m k 1 1 0 13  Example: 3 644 mod 645 36     9 7 2 644 1010000100 2 2 2  9  7  2  9 7 2 644 2 2 2 2 2 2 3 3 3 3 3 644 3 mod 645  9 7 2 2 2 2 ( 3 3 3 ) mod 645  9 7 2 2 2 2 (( 3 mod 645 )( 3 mod 645 )( 3 mod 645 ) mod 645 ) 14 7

  8. Compute the powers of 3 efficiently   2 3 mod 645 9 mod 645 9   2  2     2 2 2 2 3 mod 645 3 mod 645 (( 3 mod 645 )( 3 mod 645 )) mod 645 ( 9 9 mod 645 ) 81   2 3  2  2 2    2 2 2 2 3 mod 645 3 mod 645 (( 3 mod 645 )( 3 mod 645 )) mod 645 81 81 mod 645 111  Use the powers of 3 to get result efficiently 644 3  9 7 2 2 2 2 ( 3 3 3 mod 645 )  9 7 2  9 7 2 2 2 2 2 ( 3 3 ( 3 mod 645 ) mod 645 ) ( 3 3 81 mod 645 )  9 7  9   9  2 2 2 2 ( 3 ((( 3 mod 645 ) 81 ) mod 645 ) mod 645 ) ( 3 (( 396 81 ) mod 645 ) mod 645 ) ( 3 471 mod 645 )  9     2 ((( 3 mod 645 ) 471 ) mod 645 ) 111 471 mod 645 36 15 Modular_Exponentiation( ) { , , b n m   ( ) n a a a a   1 2 1 0 2 n n  1 x  mod power b m for to {   0 1 i k  (  if ( )  ) mod 1 x x power m a i   ( ) mod power power power m } return n ( mod ) x b m } 16 8

  9. Recall: Greatest Common Divisor  largest integer gcd( , ) a b d such that and d | d | a b  , a b Z   | | | | 0 a b  Examples: gcd( 24 , 36 ) 12 Common divisors of 24, 36: 1, 2, 3, 4, 6, 12  gcd( 17 , 22 ) 1 Common divisors of 17, 22: 1 17 Trivial cases:  gcd( , 1 ) 1 m   gcd( , 0 ) 0 m m m  If then are relatively prime gcd ( , ) 1 a , a b b and have no common factors a b Example: 21, 22 are relatively prime  gcd( 21 , 22 ) 1 18 9

  10. How do we compute GCD efficiently? (Finding prime factorization is slow) 19    Theorem:  r  If a b q r 0 b then  gcd( , ) gcd( , ) a b b r Proof:   a  ( ) r d s tq d | d | a ds r b  b  d | d | b dt dt b Thus, and have ( , ) ( , ) a b b r the same set of common divisors End of proof 20 10

  11. a  b  remainder divisions r r 0 1     0 r r q r r r 0 / r r 0 1 1 2 2 1 1     0 r r q r r r 1 / r r 1 2 2 3 3 2 2        0 2 / r r q r r r r r       1 n n n 2 n 1 n 1 n n n 1   / 0 r r r r q   1 n n 1 n n n first zero result     gcd( , ) gcd( , ) gcd( , ) gcd( , ) a b r r r r r r 0 1 1 2 2 3      gcd( , ) gcd( , ) gcd( , 0 ) r r r r r r    2 1 1 n n n n n n 21   662 414 a b       662 414 1 248 248 414 r r 2 1       414 248 1 166 166 248 r r 3 2       248 166 1 82 82 166 r r 4 3       166 82 2 2 2 82 r r 5 4    82 2 41 0 result   gcd( 662 , 414 ) gcd( 414 , 248 ) gcd( 248 , 166 )     gcd( 166 , 82 ) gcd( 82 , 2 ) gcd( 2 , 0 ) 2 22 11

  12. Euclidean Algorithm for GCD gcd( ) { a , a b x  y  b  while ( ) { 0 y  mod r x y x  y y  r } return x } 23 Useful Result regarding GCDs s    Z if then there are such that , t Z a , b   gcd( , ) a b sa tb (i.e., gcd is a linear combination of a and b)       Example: gcd( 6 , 14 ) 2 ( 2 ) 6 1 14 24 12

  13. The linear combination can be found by reversing the Euclidian algorithm steps      gcd( 252 , 198 ) 18 4 252 5 198    252 1 198 54    198 3 54 36    54 1 36 18    36 2 18 0  gcd( 252 , 198 ) 18         54 1 36 54 1 ( 198 3 54 )           4 54 1 198 4 ( 252 1 198 ) 1 198     4 252 5 198 25 Linear congruences We want to solve this equation for x   (mod m ) a x b x  ? (mod ) m 26 13

  14. a  1 (mod ) Inverse of : a a m   (mod m ) a x b   (mod m ) a a x a b  mod a a m a  1 (mod ) a m    1 (mod ) a a x x m x  (mod m ) x x  (mod m ) a b 27 Theorem: If and are relatively prime a m then the inverse modulo exists a m  1   (linear combo Proof: gcd( , ) a m sa tm theorem) sa  (Def. of 1 (mod ) m mod) a  (Def. of inverse s mod m) End of proof 28 14

  15. 3  Example: solve equation 4 (mod 7 ) x    3 , 4 , 7 a b m Inverse of 3:          gcd( 3 , 7 ) 1 2 3 1 7 2 3 1 (mod ) m   2 a x  (mod m ) a b       2 4 (mod 7 ) 8 (mod 7 ) 6 mod 7 x 29 A Chinese Puzzle (by Sun-Tzu, 300-500 AD) I have some things whose number you don’t know. If divided by 3, the remainder is 2 If divided by 5, the remainder is 3 If divided by 7, the remainder is 2 How many things do I have? 30 15

  16. Sun- Tzu’s Puzzle  2 (mod 3 ) x  3 (mod 5 ) x  2 (mod 7 ) x What is x ? 31 Chinese remainder theorem (CRT) :pairwise relatively prime  , , , m m m 1 2 n x  (mod ) a m 1 1 x  (mod ) a m 2 2  x  (mod ) a m n n Has unique solution for modulo  1  x  m m m m 2 n 32 16

  17. Unique solution modulo :  1   m m m m 2 n      x a M y a M y a M y 1 1 1 2 2 2 n n n m M  where k m k :inverse of modulo y M m k k k 33 Explanation: :inverse of modulo y M m k k k  1 mod m M y m M  k k k k m k = 1:  1 mod M y m k 1 1 1 0 (mod ) 0 (mod ) m m 1 1      x a M y a M y a M y 1 1 1 2 2 2 n n n   0 (mod ) M k m (mod ) x a M y m  1 1 1 1 1 1 i.e., x satisfies 1 st equation  (mod ) x a m 1 1 Similar for any m j 34 17

Recommend


More recommend