discrete mathematics section 3.7 applications of number theory 大葉大學 資訊工程系...

19
Discrete Mathematics Section 3.7 Applications of Number Theory 大大大大 大大大大大 大大大

Upload: camilla-mcdonald

Post on 18-Jan-2016

243 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Discrete Mathematics Section 3.7 Applications of Number Theory 大葉大學 資訊工程系 黃鈴玲

Discrete Mathematics

Section 3.7 Applications of Number Theory

大葉大學 資訊工程系 黃鈴玲

Page 2: Discrete Mathematics Section 3.7 Applications of Number Theory 大葉大學 資訊工程系 黃鈴玲

Ch3-2

3.6 Integers and Algorithms

※The Euclidean Algorithm ( 輾轉相除法求 gcd )

Example : Find gcd(91,287)

Sol:

287 = 91 3 + 14

91 = 14 6 + 7

14 = 7 2

∴ gcd(91,287) = 7

Lemma 1 Let a = bq + r, where a, b, q, and r Z.Then gcd(a, b) = gcd (b, r).

if x|91 & x|287 x|14∴gcd (91,287) = gcd(91,14)

gcd (91,14) = gcd (14,7) gcd (14,7) = 7

Page 3: Discrete Mathematics Section 3.7 Applications of Number Theory 大葉大學 資訊工程系 黃鈴玲

Ch3-3

3.7 Applications of Number Theory

Theorem 1. If a and b are positive integers, then there exist integers s and t such that gcd(a,b) = sa+tb.

gcd(a,b) can be expressed as a linear combination with integer coefficients of a and b.

※將 gcd(a,b) 寫成 a 跟 b的線性組合: The extended Euclidean Algorithm

Page 4: Discrete Mathematics Section 3.7 Applications of Number Theory 大葉大學 資訊工程系 黃鈴玲

Ch3-4

Example 1 Express gcd(252, 198) =18 as a linear combination of 252 and 198.

Sol:252 = 1 198 + 54

198 = 3 54 + 36 54 = 1 36 + 18 36 = 2 18 ∴ gcd(252, 198) = 18

18 = 54 – 1 36

36 =198 – 3 54

54 =252 – 1 198

18 = 54 – 1 36 = 54 – 1 (198 – 3 54 )

= 4 54 – 1 198 = 4 (252 – 1 198) – 1 198

= 4 252 – 5 198Exercise : 1(g)

Page 5: Discrete Mathematics Section 3.7 Applications of Number Theory 大葉大學 資訊工程系 黃鈴玲

Ch3-5

Lemma 1. If a, b and c are positive integers such that gcd(a,b) = 1 and a | bc, then a | c.

Lemma 2. If p is a prime and p | a1a2…an, where each ai is an integer, then p | ai for some i.

Example 2 14 8 (mod 6), 但的左右兩邊同除以 2 後不成立because 14/2=7, 8/2=4, but 7 4(mod 6).

Q: 何時可以讓 的左右同除以一數後還成立呢?

另 , 14 8 (mod 3), 同除以 2 後 , 7 4 (mod 3) 成立

Page 6: Discrete Mathematics Section 3.7 Applications of Number Theory 大葉大學 資訊工程系 黃鈴玲

Ch3-6

Theorem 2. Let m be a positive integer and let a, b, and c be integers. If ac bc (mod m) and gcd(c, m) = 1, then a b (mod m).

※ Linear Congruences

A congruence ( 同餘式 ) of the form ax b (mod m), wherem is a positive integer, a and b are integers, and x is a variable, is called a linear congruence.

How can we solve the linear congruence ax b (mod m)?Def: If ax 1 (mod m), and let a be an answer of x, a is called an inverse ( 反元素 ) of a modulo m

Page 7: Discrete Mathematics Section 3.7 Applications of Number Theory 大葉大學 資訊工程系 黃鈴玲

Ch3-7

Theorem 3. If a and m are relatively prime integers and m>1, then an inverse of a modulo m exists. Furthermore, this inverse is unique modulo m.

Proof. (existence) (unique 的部分是 exercise)

By Thm 1, because gcd(a, m) = 1, there exist integers s and t such that sa + tm =1.

sa + tm 1 (mod m).

Because tm 0 (mod m), sa 1 (mod m),

s is an inverse of a modulo m.

Page 8: Discrete Mathematics Section 3.7 Applications of Number Theory 大葉大學 資訊工程系 黃鈴玲

Ch3-8

Example 3 Find an inverse of 3 modulo 7.

Sol. Because gcd(3, 7) = 1, find s, t such that 3s + 7t =1.

2 is an inverse of 3 modulo 7.

7 = 2 3 + 1

1 = 2 3 + 1 7

(Note that every integer congruent to 2 modulo 7 is also an inverse of 3, such as 5, 9, 12, and so on. )

Exercise : 5

Page 9: Discrete Mathematics Section 3.7 Applications of Number Theory 大葉大學 資訊工程系 黃鈴玲

Ch3-9

Example 4 What are the solutions of the linear congruence 3x 4 (mod 7)?

Sol. By Example 3 2 is an inverse of 3 modulo 7

If x is a solution, then x 8 6 (mod 7).

2 3x 2 4 (mod 7)

Because 6 1 (mod 7), and 8 6 (mod 7),

We need to determine whether every x with x 6 (mod 7)is a solution. Assume x 6 (mod 7), then 3x 6 = 18 4 (mod 7).

Therefore every such x is a solution: x = 6, 13, 20, …, and 1, 8, 15, …. Exercise : 11

將 3x 4 (mod 7) 左右同乘 2

6x (mod 7)

3 (2) 1 (mod 7)

Page 10: Discrete Mathematics Section 3.7 Applications of Number Theory 大葉大學 資訊工程系 黃鈴玲

Ch3-10

Example 5. 孫子算經 : 「某物不知其數,三三數之餘二,五五數之餘三,七七數之餘二,問物幾何 ? 」 ( 又稱為「韓信點兵」問題 )

i.e. x ≡ 2 (mod 3) x ≡ 3 (mod 5) x = ? x ≡ 2 (mod 7)

Theorem 4. (The Chinese Remainder Theorem)Let m1,m2,…,mn be pairwise relatively prime positive integers and a1, a2, …, an arbitrary integers. Then the system

x ≡ a1 (mod m1)x ≡ a2 (mod m2)

:x ≡ an (mod mn)

has a unique solution modulo m = m1m2…mn.( 即有一解 x, where 0 x < m , 且所有其他解 mod m 都等於 x)

The Chinese Remainder Theorem ( 中國餘數定理 )

Page 11: Discrete Mathematics Section 3.7 Applications of Number Theory 大葉大學 資訊工程系 黃鈴玲

Ch3-11

Proof of Thm 4:

Let Mk = m / mk 1 k n

∵ m1, m2,…, mn are pairwise relatively prime

∴ gcd (Mk , mk) = 1

integer yk s.t. Mk yk ≡ 1 (mod mk)

( by Thm. 3)

ak Mk yk ≡ ak (mod mk) , 1 k n

Let x = a1 M1 y1+a2 M2 y2+…+an Mn yn

∵ mi | Mj , i ≠ j

∴ x ≡ ak Mk yk ≡ ak (mod mk) 1 k n

x is a solution.

All other solution y satisfies y ≡ x (mod mk).

x ≡ a1 (mod m1)x ≡ a2 (mod m2):x ≡ an (mod mn)

m = m1m2…mn

Page 12: Discrete Mathematics Section 3.7 Applications of Number Theory 大葉大學 資訊工程系 黃鈴玲

Ch3-12

Example 6. (Solve the system in Example 5)Let m = m1m2m3 = 357 = 105 M1 = m / m1 = 105 / 3 = 35 ( 也就是 m2m3) M2 = m / m2 = 105 / 5 = 21 M3 = m / m3 = 105 / 7 = 15

35 ≡ 2 (mod 3) 35 2 ≡ 2 2 ≡ 1 (mod 3)

21 ≡ 1 (mod 5) 21 1 ≡ 1 (mod 5)

15 ≡ 1 (mod 7) 15 1 ≡ 1 (mod 7)

∴ x = a1M1y1 + a2M2y2 + a3M3y3

= 2 35 2 + 3 21 1 + 2 15 1 = 233 ≡ 23 (mod 105)∴ 最小的解為 23 ,其餘解都等於 23+105t for some tZ+

M1 y1

M2 y2

M3 y3

x ≡ 2 (mod 3)x ≡ 3 (mod 5) x = ?x ≡ 2 (mod 7)

找 y1 使得 M1y1 = 1 (mod 3)

Page 13: Discrete Mathematics Section 3.7 Applications of Number Theory 大葉大學 資訊工程系 黃鈴玲

Ch3-13

Exercise 18. Find all solutions to the system of congruences x ≡ 2 (mod 3)

x ≡ 1 (mod 4) x ≡ 3 (mod 5)Sol : a1=2 , a2=1 , a3=3, m1=3 , m2=4 , m3=5 m=345=60 M1=20 , M2=15 , M3=12 20≡2 (mod 3) 202≡1 (mod 3) 15≡3 (mod 4) 153≡1 (mod 4) 12≡2 (mod 5) 123≡1 (mod 5) ∴ x = 2202+1153+3123 = 80+45+108=233≡53 (mod 60)

Page 14: Discrete Mathematics Section 3.7 Applications of Number Theory 大葉大學 資訊工程系 黃鈴玲

Ch3-14

※ 補充: (when mi is not prime)

Ex 20. Find all solutions, if any, to the system of congruences.

x≡5 (mod 6)x≡3 (mod 10)x≡8 (mod 15)

Sol. Rewrite the system as the following:x ≡ 1 (mod 2) x≡2 (mod 3)

i.e., x≡1 (mod 2)x≡2 (mod 3) …x≡3 (mod 5) Exercise : 做完此題

x ≡ 1 (mod 2)x ≡ 2 (mod 3)

x≡3 (mod 5)x≡3 (mod 5)

Page 15: Discrete Mathematics Section 3.7 Applications of Number Theory 大葉大學 資訊工程系 黃鈴玲

Ch3-15

※ 補充: (when mi is a prime power)

Ex 21. Find all solutions, if any, to the system of congruences.

x≡7 (mod 9)x≡4 (mod 12)x≡16 (mod 21)

Sol. Rewrite the system as the following:x≡7 (mod 9) ( 不能拆! )

x≡0 (mod 4)

i.e., x≡7 (mod 9) ( 此式取代 x≡1 (mod 3) 式子 )x≡0 (mod 4) …x≡2 (mod 7)

x≡1 (mod 3)x≡1 (mod 3) x≡2 (mod 7)

Page 16: Discrete Mathematics Section 3.7 Applications of Number Theory 大葉大學 資訊工程系 黃鈴玲

Ch3-16

Computer Arithmetic with Large Integers

Suppose that m1,m2,…,mn be pairwise relatively prime integers greater than or equal to 2 and let m = m1m2 …mn.By the Chinese Remainder Theorem, we can show that an integer a with 0 a < m can be uniquely represented by then-tuple (a mod m1, a mod m2, …, a mod mn).

Example 7 What are the pairs used to represent the nonnegativeintegers x<12 when they are represented by the order pair(x mod 3, x mod 4)?

Sol 0=(0, 0), 1=(1, 1), 2=(2, 2), 3=(0, 3), 4=(1, 0), 5=(2, 1), 6=(0, 2), 7=(1, 3), 8=(2, 0), 9=(0, 1), 10=(1, 2), 11=(2, 3).

Exercise : 37

Page 17: Discrete Mathematics Section 3.7 Applications of Number Theory 大葉大學 資訊工程系 黃鈴玲

Ch3-17

To perform arithmetic with larger integers, we selectmoduli (modulus 的複數 ) m1,m2,…,mn, whereeach mi is an integer greater than 2, gcd(mi, mj)=1 whenever i j, and m=m1m2…mn is greater than the result of the arithmetic operations we want to carry out.

Page 18: Discrete Mathematics Section 3.7 Applications of Number Theory 大葉大學 資訊工程系 黃鈴玲

Ch3-18

Example 8 Suppose that performing arithmetic with integers less than 100 on a certain processor is much quicker than doing arithmetic with larger integers. We can restrict almost all our computations to integers less than 100 if we represent integersusing their remainders modulo pairwise relatively prime integers less than 100.

For example, 99, 98, 97, and 95 are pairwise relatively prime.every nonnegative integer less than 99989795 = 89403930can be represented uniquely by its remainders when divided bythese four moduli.

E.g., 123684 = (33, 8, 9, 89), and 413456 = (32, 92, 42, 16)

123684 + 413456 = (33, 8, 9, 89) + (32, 92, 42, 16) = (65 mod 99, 100 mod 98, 51 mod 97, 105 mod 95) = (65, 2, 51, 10)

Use Chinese Remainder Thm to find this sum 537140.

Page 19: Discrete Mathematics Section 3.7 Applications of Number Theory 大葉大學 資訊工程系 黃鈴玲

Ch3-19

Theorem 5 (Fermat’s Little Theorem)If p is prime and a is an integer not divisible by p, then a p1 1 (mod p)Furthermore, for every integer a we have a p a (mod p)

Exercise 27(a) Show that 2340 1 (mod 11) by Fermat’s Little Theorem and noting that 2340 = (210)34.

Proof 11 is prime and 2 is an integer not divisible by 11.

210 1 (mod 11)

2340 1 (mod 11) by Thm 5 of Sec. 3.4 (a b (mod m) and c d (mod m) ac bd (mod m) )

Exercise : Compute 52003 (mod 7)