Euclidean Algorithm Applied Symbolic Computation CS 567 Jeremy Johnson
Dec 14, 2015
Unique Factorization
• p|ab p|a or p|b
• a = p1 pt = q1 qs s = t and i j: pi= qj
• a = p1e1 pt
et
• b = p1f1 pt
ft
• gcd(a,b) = p1min(e1,f1) pt
min(et,ft)
Iterative Algorithm
g = gcd(a,b) a1 = a; a2 = b; while (a2 0) a3 = a1 mod a2; a1 = a2; a2 = a3; } return a1;
Remainder Sequence
a1 = a, a2 = b
a1 = q3 a2 + a3, 0 a3 < a2
ai = qi ai+1 + ai+2, 0 ai+2 < ai+1
an= qn an+1
gcd(a,b) = an+1
Bounding Number of Divisions
Theorem. Let a b 0 and n = number of divisions required by the Euclidean algorithm to compute gcd(a,b). Then n < 2lg(a).
Maximum Number of Divisions
Theorem. The smallest pair of integers that require n divisions to compute their gcd is Fn+2 and Fn+1.
Maximum Number of Divisions
Theorem. Let a b 0 and n = number of divisions required by the Euclidean algorithm to compute gcd(a,b). Then n < 1.44 lg(a).
Extended Euclidean Algorithm
g = gcd(a,b,*x,*y) a1 = a; a2 = b; x1 = 1; x2 = 0; y1 = 0; y2 = 1; while (a2 0) a3 = a1 mod a2; q = floor(a1/a2); x3 = x1 – q*x2; y3 = y1 – q*y2; a1 = a2; a2 = a3; x1 = x2; x2 = x3; y1 = y2; y2 = y3; } return a1;