590 likes | 598 Views
Learn about calculating inverses, GCDs, and their properties. Understand Euclid’s Division Theorem and the GCD Algorithm. Explore multiplicative inverses and efficient computation methods.
E N D
L14: Inverses and GCDs • Objective: • When does have an inverse? • How to compute the inverse? • Need: Greatest common dividers (GCDs) • Results will be used in L15. • Reading • Textbook, pp. 105-120
Inverses and GCDs • Greatest Common Divisors (GCDs) • Definitions • Euclid’s Division Theorem • The GCD Algorithm • Multiplicative Inverses • Definition and Properties • Link to GCD • The extended GCD algorithm. • Computing inverses
Page 4 Prime Numbers
Relatively Prime • How to calculate gcd(m, n)? • Need Euclid’s division theorem
Inverses and GCDs • Greatest Common Divisors (GCDs) • Definitions • Euclid’s Division Theorem • The GCD Algorithm • Multiplicative Inverses • Definition and Properties • Link to GCD • The extended GCD algorithm. • Computing inverses
Choose the smallest such m Equation (*) not true for m and any q, r Equation (*) true for m’ <m and some q, r • Need to prove: For any m ≥0 , Exist q & r , s. t . m = qn + r ( 0 ≤ r < n) * Proof by contradiction * Assume exists m ≥ 0 , s . t . m = qn + r( * ) Not true for any q , r ( 0 ≤ r < n ) * Two cases: m < n , m ≥ n
* If m < n , m = 0 · n + m ( 0 ≤ m <n ) ( q = 0 , r = m ) Satisfies m = qn + r ( 0 ≤ r < n ) Contradicts the choice of m ! * If m ≥ n , • Let m’ = m – n , m’ ≥ 0 • m’ < m There must exist q’ , r’ s. t. m’ = q’ n + r’ ( 0 ≤ r’ < n ) => m – n = q’n + r’ => m = ( 1 + q’ ) n + r’ Contradicts the choice of m ! Proof completed
Page 13 Proof by Smallest Counter Example
Proof of Theorem 2.12 2nd Step * Need to prove: m = qn + r ( 0≤r <n ) ( * ) m = q’n + r’ ( 0 ≤r’<n) ( ** ) => q = q’ , r = r’ ∣r’ – r ∣< n * Subtract ( * ) and ( ** ) 0 = ( q – q’ ) n + r – r’ => ∣q’ – q∣ n < n ☆ => ∣q’ - q∣ = 0 => ( q – q’ ) n = r’ – r => q’ = q => ∣q – q’ ∣n = ∣r’ – r ∣ => r’ = r Proved
Inverses and GCDs • Greatest Common Divisors (GCDs) • Definitions • Euclid’s Division Theorem • The GCD Algorithm • Multiplicative Inverses • Definition and Properties • Link to GCD • The extended GCD algorithm. • Computing inverses .
A Lemma • This lemma gives us a way to calculate GCDs. • Example • 10 = 4 * 2 + 2 • gcd(10, 4) = 2 = gcd(4, 2)
Proof * Case 1: r = 0 => k = jq , j ︱k Always have j︱j , gcd ( j , k ) ≤ j => gcd( j , k ) = j j︱j , j︱0 , gcd ( j , 0 ) ≤ j => gcd ( j , 0 ) = j => gcd ( j , k ) = gcd ( j , r )
* Case 2 : r > 0 Will show : d︱j , d︱k <=> d︱j , d︱r (*) => gcd ( j , k ) = gcd ( r , j ) “=>” : d | j , d | k Proof of (*) => k = i1 d , j = i2 d => r = k -j q = i1 d - i2 d q = ( i1 – i2q ) d => d | r => d︱j , d︱r . proved “<=” : Similar Lemma proved
Euclid’s GCD algorithm • The 2nd argument is nonnegative • Decreases in each recursive call • Becomes 0 in a finite number of steps
Inverses and GCDs • Greatest Common Divisors (GCDs) • Definitions • Euclid’s Division Theorem • The GCD Algorithm • Multiplicative Inverses • Definition and Properties • Link to GCD • The extended GCD algorithm. • Computing inverses
Determine Inverses from Multiplication Table • Which nonzero elements of have multiplicative inverses?
Determine Inverses from Multiplication Table • Which nonzero elements of have multiplicative inverses?
Determine Inverses from Multiplication Table • It seems determining inverses is simple • Just scan multiplication tables • But do you see a problem with this method? • Yes, too complex… • For e-commerce, we need to determine inverse of integers of more 200 or 300 digits… • Computationally . • Next: • Show a way to prove inverse does not exist. • Develop efficient way to calculate inverses if they exist.
First, uniqueness Proof * Let b and c be two inverses of a . Zn b = b ·n 1 = b ·n (a ·nc) = (b ·na ) ·nc = 1·nc = c. So, the inverse is unique.
Proving Inverse does not Exist * Lemma 2 . 5 a has inverse => a ·n x = b in zn has unique solution for ANY b • Gives us a way to prove that inverse does not exist
Proving Inverse does not Exist Page 32 3has inverse inz6? * 3 ·6 x = 2 ( * ) => 3x : multiple of 3 => 3x mod 6 : multiple of 3 => Can never be 2 => ( * ) has no solution => 3 has no inverse in Z6 • Will the proof go through with 3 ·6 x = 4?
Proving Inverse does not Exist * 6has no inverse inz9? 6 ·9 x = 2 ( * * ) => 6x : multiple of 3 => 6x mod 9 : multiple of 3 => ( ** ) has no solution => 6 has no inverse in Z9
Inverses and GCDs • Greatest Common Divisors (GCDs) • Definitions • Euclid’s Division Theorem • The GCD Algorithm • Multiplicative Inverses • Definition and Properties • Link to GCD • The extended GCD algorithm. • Computing inverses
Link to GCD • Objective: • Show the following two important results
Lemma 2. 8 : a ·nx = 1 has solution in zn Modular Equations and Normal Equations <=> a x + n y = 1 for some integers x & y Proof : “=>” : Exist b ∈ zn , a ·n b = 1 => a b mod n = 1 => a b = q n + 1 => a b + n ( - q ) = 1 => a x + n y = 1 : x = b ,y = -q
Lemma 2 . 8 : a ·nx = 1 has soln in zn <=> a x + n y = 1 for some integers x & y . Proof : “<=” : Exist x & y , a x + n y = 1 => a x = ( - y ) n + 1 => a x mod n = 1 => ( a ( x mod n ) ) mod n = 1 Let b = x mod n => a b mod n = 1 => a ·n b = 1 , b ∈ zn Proved
Exist x & y , a x + n y = 1 => a x = ( - y )n + 1 => a x mod n = 1 => ( a ( x mod n )) mod n = 1 => a b mod n = 1 => a ·n b = 1 , b ∈ zn Let b = x mod n Clue on Finding Inverse • Second part of the proof of Lemma 2.8: • Does this give us a way to find the inverse of a? • Yes, b = x mod n
Clue on Finding Inverse • So, given a and n, if we can find x and y, such that a x + ny =1 (*) Then, we find inverse of a, i.e., x mod n • Given a and n, how do we find x and y, to satisfy (*)? • Link to GCD
Link to GCD Proof : Supposek|a , k|n , k > 0 => a = sk, n = qk, form some s, q 1 = ax + ny = skx + qky = (sx + qy)k ★ => k|1 => k = 1 => gcd ( a , n ) = 1 Proved .
Inverses and GCDs • Greatest Common Divisors (GCDs) • Definitions • Euclid’s Division Theorem • The GCD Algorithm • Multiplicative Inverses • Definition and Properties • Link to GCD • The extended GCD algorithm. • Computing inverses
Page 43 Extended GCD Algo ﹡ Input : a , n > 0 , integers ﹡ Output : - gcd (a , n) - x , y s . t . ax + ny = gcd ( a , n ) • gcd(a, n)=1 • a have inverse in Zn, it is x mod n • gcd(a, n) \= 1 • a does not have inverse in Zn.
Page 44 The GCD algorithm Revisited • Computes GCD, but nothing else
The Extended GCD Algorithm/Base Case • Base case: k=jq gcd(k, j) = j j * 1 + k * 0 = gcd(k, j),x=1, y=0 How to calculate: gcd, x, y?
Need to find x , y s.t. j x + k y = gcd ( k , j ) (*) The Extended GCD Algorithm/Induction • Induction: k \= jq k = jq + r ① Recursive call GCD( j, r ) Returns gcd ( j , r ) x’ , y’ : rx’ + jy’ = gcd ( j , r )② Know : gcd ( k , j ) = gcd ( j , r )
Need to find x . y s. t. jx + ky = gcd ( j, r )* So, Equation (* ) is satisfied we set x = y’ – qx’ , y = x’ k = jq + r ① x’ , y’ : r x’ + j y’ = gcd ( j , r ) ② ① => r = k - jq ③ ③ + ② => (k – jq )x’ + jy’ = gcd ( j , r ) => j ( y’ – qx’ ) + kx’ = gcd ( j , r ) = gcd ( k, j ) Remember: Swap x & y, subtract qx’ from x
Page 49 The Extended GCD Algorithm/Example
Without remembering: Easy Manual Way to Find x and y