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

a mod m b
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

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

1 Based on Rosen and slides by K. Busch

“ is congruent to modulo ”

2

Modular Arithmetic Recap

Z b a  ,

Z m

) (mod m b a 

a b m

Examples:

) 12 (mod 13 1

) 6 (mod 5 11

m b m a mod mod 

) (mod m m k   ) (mod m m 

slide-2
SLIDE 2

2

3

) (mod m b a  km b a Z k     ,

b a m  | m b m a mod mod 

Equivalent statements

4

3 8 mod 3 

1 2 3 4 5 6 7

3 Length of line represents number

slide-3
SLIDE 3

3

5

3 8 mod 11 

1 2 3 4 5 6 7

11 Length of line represents number

6

3 8 mod 19 

1 2 3 4 5 6 7

19 Length of line represents number

slide-4
SLIDE 4

4

7 1 2 3 4 5 6 7

3

1 2 3 4 5 6 7

11

1 2 3 4 5 6 7

19

) 8 (mod 19 11 3  

All lines terminate in same number

8

)} (mod | { m b a b Sa  

“Congruence class” of modulo :

a m

There are congruence classes:

m

1 1

, , ,

 m

S S S 

slide-5
SLIDE 5

5

9

) (mod m b a 

) (mod m d c 

) (mod m d b c a   

) (mod m b a  sm b a   ) (mod m d c  tm d c   m t s b d c a ) (     

Proof sketch: Closure under addition:

10

) (mod m b a 

) (mod m d c 

) (mod m d b c a   

) (mod m b a  sm b a   ) (mod m d c  tm d c   ) ( bd ) )( ( stm ds bt m tm d sm b c a        

Proof sketch: Closure under multiplication:

slide-6
SLIDE 6

6

11

Closure under mod: m m a m a mod ) mod ( mod  2 5 mod 2 5 mod ) 5 mod 7 ( 2 ) 5 mod 7 (    (Follows from definition of mod)

12

m m b m a m b a mod )) mod ( ) mod (( mod ) (    m m b m a m ab mod )) mod )( mod (( mod 

(Follows from previous slides) Example: Useful results for arithmetic with large numbers: 35 50 mod 5 7 50 mod )) 50 mod 55 )( 50 mod 57 (( 50 mod 55 57     

slide-7
SLIDE 7

7

13

Modular exponentiation Compute efficiently using small numbers

m bn mod

1 1 1 1 1 1

2 2 2 2 a a a a a a n

b b b b b

k k k k

   

 

   Binary expansion of n

m m b m b m b m b b b m b

a a a a a a n

k k k k

mod )) mod ( ) mod ( ) mod (( mod mod

1 1 1 1 1 1

2 2 2 2

    

   

 

14

Example:

36 645 mod 3644 

2 7 9

2 2 2 1010000100 644    

2 7 9 2 7 9

2 2 2 2 2 2 644

3 3 3 3 3  

 

) 645 mod ) 645 mod 3 )( 645 mod 3 )( 645 mod 3 (( 645 mod ) 3 3 3 ( 645 mod 3

2 7 9 2 7 9

2 2 2 2 2 2 644

 

slide-8
SLIDE 8

8

15

 

 

 111 645 mod 81 81 645 mod )) 645 mod 3 )( 645 mod 3 (( 645 mod 3 645 mod 3 81 ) 645 mod 9 9 ( 645 mod )) 645 mod 3 )( 645 mod 3 (( 645 mod 3 645 mod 3 9 645 mod 9 645 mod 3

2 2 2 3 2

2 2 2 2 2 2 2 2 2 2 2

           

36 645 mod 471 111 ) 645 mod ) 471 ) 645 mod 3 ((( ) 645 mod 471 3 ( ) 645 mod ) 645 mod ) 81 396 (( 3 ( ) 645 mod ) 645 mod ) 81 ) 645 mod 3 ((( 3 ( ) 645 mod 81 3 3 ( ) 645 mod ) 645 mod 3 ( 3 3 ( ) 645 mod 3 3 3 ( 3

9 9 9 7 9 7 9 2 7 9 2 7 9

2 2 2 2 2 2 2 2 2 2 2 2 2 644

            

Compute the powers of 3 efficiently Use the powers of 3 to get result efficiently

16

Modular_Exponentiation( ) { for to { if ( ) } return }

m n b , ,

2 1 2 1

) ( a a a a n

n n

 

 1  x m b power mod   i 1  k 1 

i

a m power x x mod ) (   m power power power mod ) (   ) mod ( m b x

n

slide-9
SLIDE 9

9

17

Recall: Greatest Common Divisor

 ) , gcd( b a

largest integer such that and

d a d | b d |

Examples: Common divisors of 24, 36: 1, 2, 3, 4, 6, 12

12 ) 36 , 24 gcd(  1 ) 22 , 17 gcd( 

Common divisors of 17, 22: 1

| | | | ,    b a Z b a

18

Trivial cases:

1 ) 1 , gcd(  m m m  ) , gcd(  m

If then are relatively prime

1 ) , ( gcd  b a b a,

and have no common factors

a b

Example:

1 ) 22 , 21 gcd( 

21, 22 are relatively prime

slide-10
SLIDE 10

10

How do we compute GCD efficiently?

(Finding prime factorization is slow)

19 20

Theorem: If then

) , gcd( ) , gcd( r b b a 

r q b a   

Proof:

a d | b d | ds a  dt b  ) ( tq s d r   dt b 

) , ( b a ) , ( r b

r d | b d |

Thus, and have the same set of common divisors End of proof b r  

slide-11
SLIDE 11

11

21

1 1 1 1 2 2 3 3 2 2 1 1 2 2 1 1

             

     n n n n n n n n n

q r r r r r q r r r r r q r r r r r q r r 

r a 

1

r b 

n n n n n n

r r r r r r r r r r r r b a       

  

) , gcd( ) , gcd( ) , gcd( ) , gcd( ) , gcd( ) , gcd( ) , gcd(

1 1 2 3 2 2 1 1

  first zero result

1 0 / r

r

2 1 / r

r

1 2 /   n n

r r

n n

r r /

1 

divisions remainder

22

41 2 82 82 2 2 2 82 166 166 82 82 1 166 248 248 166 166 1 248 414 414 248 248 1 414 662

4 5 3 4 2 3 1 2

                           r r r r r r r r

662  a 414  b

2 ) , 2 gcd( ) 2 , 82 gcd( ) 82 , 166 gcd( ) 166 , 248 gcd( ) 248 , 414 gcd( ) 414 , 662 gcd(       result

slide-12
SLIDE 12

12

23

Euclidean Algorithm for GCD gcd( ) { while ( ) { } return }

b a, a x 

b y 

 y

y x r mod  y x 

r y  x

Useful Result regarding GCDs

24

if then there are such that

Z b a,

Z t s  ,

tb sa b a   ) , gcd(

Example:

14 1 6 ) 2 ( 2 ) 14 , 6 gcd(      

(i.e., gcd is a linear combination of a and b)

slide-13
SLIDE 13

13

25

The linear combination can be found by reversing the Euclidian algorithm steps

198 5 252 4 18 ) 198 , 252 gcd(     

18 2 36 18 36 1 54 36 54 3 198 54 198 1 252             198 5 252 4 198 1 ) 198 1 252 ( 4 198 1 54 4 ) 54 3 198 ( 1 54 36 1 54 18 ) 198 , 252 gcd(                       

26

Linear congruences

) (modm b x a  

We want to solve this equation for

) (mod ? m x 

x

slide-14
SLIDE 14

14

27

Inverse of :

) (mod 1 m a a 

a

) (modm b x a   m a a mod 

) (modm b a x a a  

) (modm x x 

) (mod 1 m a a  ) (mod 1 m x x a a   

) (modm b a x 

28

If and are relatively prime then the inverse modulo exists Theorem:

a

m

a

m

Proof:

tm sa m a   1 ) , gcd( ) (mod 1 m sa  s a 

End of proof

(linear combo theorem) (Def. of mod) (Def. of inverse mod m)

slide-15
SLIDE 15

15

29

Example: solve equation

) 7 (mod 4 3  x

7 1 3 2 1 ) 7 , 3 gcd(      

Inverse of 3:

) (mod 1 3 2 m    7 mod 6 ) 7 (mod 8 ) 7 (mod 4 2       x

7 , 4 , 3    m b a

) (modm b a x 

2   a 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

slide-16
SLIDE 16

16

Sun-Tzu’s Puzzle

31

) 3 (mod 2  x ) 5 (mod 3  x ) 7 (mod 2  x

What is x?

32

Chinese remainder theorem (CRT)

n

m m m , , ,

2 1

:pairwise relatively prime

) (mod

1 1

m a x 

) (mod

2 2

m a x  ) (mod

n n

m a x 

Has unique solution for modulo

x

n

m m m m 

2 1 

slide-17
SLIDE 17

17

33

Unique solution modulo :

k k

m m M 

k

y

:inverse of modulo

k

M

k

m

n n n

y M a y M a y M a x     

2 2 2 1 1 1

n

m m m m 

2 1 

 where

34

Explanation:

k k

m m M 

k k k

m y M mod 1 

:inverse of modulo

k

M

k

m

n n n

y M a y M a y M a x     

2 2 2 1 1 1

) (mod

1 1

m Mk 

) (mod

1

m ) (mod

1

m

) (mod ) (mod

1 1 1 1 1 1

m a x m y M a x  

k

y

Similar for any

j

m

k = 1:

1 1 1

mod 1 m y M 

i.e., x satisfies 1st equation

slide-18
SLIDE 18

18

35

Example:

) 3 (mod 2  x ) 5 (mod 3  x ) 7 (mod 2  x

105 7 5 3     m

15 7 / 105 7 / 21 5 / 105 5 / 35 3 / 105 3 /

3 2 1

         m M m M m M 1 1 2

3 2 1

   y y y

) 105 (mod 23 ) 7 5 3 (mod 23 233 1 15 2 1 21 3 2 35 2

3 3 3 2 2 2 1 1 1

                 y M a y M a y M a x

36

An Application of CRT Perform arithmetic with large numbers using arithmetic modulo small numbers Example: Suppose your CPU can only perform fast arithmetic for positive integers < 100, but your input numbers are huge.

slide-19
SLIDE 19

19

37

An Application of CRT Idea: Convert your large numbers to small numbers < 100 using mod, perform modular arithmetic, convert back using CRT.

95 , 97 , 98 , 99

4 3 2 1

    m m m m 930 , 403 , 89 95 97 98 99      m

Choose relatively prime numbers < 100

) 89 , 9 , 8 , 33 ( 684 , 123 

89 95 mod 684 , 123 9 97 mod 684 , 123 8 98 mod 684 , 123 33 99 mod 684 , 123    

Any number smaller than has unique Representation (CRT)

m

38

) 89 , 9 , 8 , 33 ( 684 , 123 

) 16 , 42 , 92 , 32 ( 456 , 413 

+

) 95 mod 105 , 97 mod 51 , 98 mod 100 , 99 mod 65 (

) 10 , 51 , 2 , 65 ( 140 , 537 

Obtain answer x from 65, 2, 51, 10 using the Chinese remainder theorem + + + +

Decimal Mod representation