GCD is a linear combination Mathematics for Computer Science MIT 6.042J/18.062J Theorem: GCD’s & linear gcd(a,b) is an integer combinations: linear combination of a and b . The Pulverizer gcd(a,b) = sa + tb Albert R Meyer March 6, 2015 pulverizer. 1 Albert R Meyer March 6, 2015 pulverizer. 2 gcd(a,b) = sa + tb GCD is a linear combination Proof: Show how to find Corollary: coefficients s,t. The multiples of gcd(a,b) Method : apply Euclidean are exactly the linear algorithm, finding combinations of a and b . coefficients as you go. Albert R Meyer March 6, 2015 pulverizer. 3 Albert R Meyer March 6, 2015 pulverizer. 4 1
Extending Euclid Extending Euclid In Euclid have In Euclid have gcd(x,y) = gcd(a,b) . gcd(x,y) = gcd(a,b) . Track coeff’s c,d,e,f Track coeff’s c,d,e,f ca + db = x and ea + fb = y ca + db = x and ea + fb = y to start: x = a = 1a + 0b Albert R Meyer March 6, 2015 pulverizer. 5 Albert R Meyer March 6, 2015 pulverizer. 6 Extending Euclid Extending Euclid In Euclid have x next = y = ea + fb gcd(x,y) = gcd(a,b) . y next = rem(x,y) = Track coeff’s c,d,e,f x - qy = ca + db = x and ea + fb = y to start: ca + db - q(ea + fb) y = b = 0a + 1b Albert R Meyer March 6, 2015 pulverizer. 7 Albert R Meyer March 6, 2015 pulverizer. 8 2
Finding s and t Extending Euclid Example: a = 899, b=493 x next = y = ea + fb 899 = 1·493 + 406 so 406 = 1 ·a + -1·b so 87 = 1· b – 1·406 493 = 1·406 + 87 y next = rem(x,y) = = -1· a + 2· b 406 = 4·87 + 58 so 58 = 1·406 - 4·87 x - qy = = 5· a + -9· b 87 = 1·58 + 29 so 29 = 1·87 – 1·58 = -6· a + 11· b (c - - qe)a + (d - qf)b 58 = 2·29 + 0 done, gcd = 29 Albert R Meyer March 6, 2015 pulverizer. 9 Albert R Meyer March 6, 2015 pulverizer. 10 Finding s and t Finding s > 0 and t Example: a = 899, b=493 899 = 1·493 + 406 so 406 = 1 ·a + -1·b gcd(899,493) = - - 6·899 + 11·493 493 = 1·406 + 87 so 87 = 1· b – 1·406 get positive coeff. for 899?: = -1· a + 2· b 406 = 4·87 + 58 =(-6+493k)·899 + (11-899k)·493 so 58 = 1·406 - 4·87 = 5· a + -9· b let k be 1: 87 = 1·58 + 29 so 29 = 1·87 – 1·58 = -6· a + 11· b = 487·899 - 888·493 58 = 2·29 + 0 done, gcd = 29 the Pulverizer s = -6, t = 11 Albert R Meyer March 6, 2015 pulverizer. 11 Albert R Meyer March 6, 2015 pulverizer. 12 3
Pulverizer is efficient Pulverizer is efficient Same number of transitions as Same number of transitions as Euclid Euclid, a few more adds/mults per transition. So halts after at most 10log 2 b operations Albert R Meyer March 6, 2015 pulverizer. 13 Albert R Meyer March 6, 2015 pulverizer. 14 4
MIT OpenCourseWare http s ://ocw.mit.edu 6.042J / 18.062J Mathematics for Computer Science Spring 20 15 For information about citing these materials or our Terms of Use, visit: http s ://ocw.mit.edu/terms.
Recommend
More recommend