Presentation is loading. Please wait.

Presentation is loading. Please wait.

An Analysis of Lehmer’s Euclidean GCD Algorithm Jonathan Sorenson Proceedings of the 1995 international symposium on Symbolic and algebraic computation.

Similar presentations


Presentation on theme: "An Analysis of Lehmer’s Euclidean GCD Algorithm Jonathan Sorenson Proceedings of the 1995 international symposium on Symbolic and algebraic computation."— Presentation transcript:

1 An Analysis of Lehmer’s Euclidean GCD Algorithm Jonathan Sorenson Proceedings of the 1995 international symposium on Symbolic and algebraic computation Speaker: 張圻毓

2 Outline  An example for Lehmer’s GCD  An example for Algorithm ML  Analysis Algorithm ML  Experiment  Conclusion

3 An example for Lehmer’s GCD x 0 = 768,454,923 y 0 = 542,167,814 b = 10 3 x’y’x”y”ax 0 +by 0 cx 0 +dy 0 q’q” 7695427685431x 0 +0y 0 0x 0 +1y 0 11 5422275432250x 0 +1y 0 1x 0 -1y 0 22 22788225931x 0 -1y 0 -2x 0 +3y 0 22 88519339-2x 0 +3y 0 5x 0 -7y 0 12

4 An example for Lehmer’s GCD x 1 = -2x 0 +3y 0 = 89,593,596 y 1 = 5x 0 -7y 0 = 47,099,917 GCD(x 0,y 0 )= GCD(x 1,y 1 ) x’y’x”y”ax 1 +by 1 cx 1 +dy 1 q’q” 904789481x 1 +0y 1 0x 1 +1y 1 11 474348410x 1 +1y 1 1x 1 -1y 1 11 4344171x 1 -1y 1 -1x 1 +2y 1 105

5 An example for Lehmer’s GCD x 2 = 1x 1 -1y 1 = 42,493,679 y 2 = -1x 1 +2y 1 = 4,606,238 GCD(x 0,y 0 )= GCD(x 1,y 1 )= GCD(x 2,y 2 ) x’y’x”y”ax 2 +by 2 cx 2 +dy 2 q’q” 4344251x 2 +0y 2 0x 2 +1y 2 108

6 An example for Lehmer’s GCD x 3 = y 2 = 4,606,238 y 3 = x 2 mod y 2 = 1,037,537 GCD(x 0,y 0 )= GCD(x 1,y 1 )= GCD(x 2,y 2 )= GCD(x 3,y 3 ) x’y’x”y”ax 3 +by 3 cx 3 +dy 3 q’q” 51421x 3 +0y 3 0x 3 +1y 3 52

7 An example for Lehmer’s GCD x 4 = y 3 = 1,037,537 y 4 = x 3 mod y 3 = 456,090 GCD(x 0,y 0 )= … = GCD(x 4,y 4 ) x’y’x”y”ax 4 +by 4 cx 4 +dy 4 q’q” 20111x 4 +0y 4 0x 4 +1y 4 --

8 An example for Lehmer’s GCD x 5 = y 4 = 456,090 y 5 = x 4 mod y 4 = 125,357 GCD(x 0,y 0 )= … = GCD(x 5,y 5 ) x’y’x”y”ax 5 +by 5 cx 5 +dy 5 q’q” 4571254561261x5+0y51x5+0y5 0x5+1y50x5+1y5 33 12582126780x5+1y50x5+1y5 1x5-3y51x5-3y5 11 824378481x 5 -3y 5 -1x 5 +4y 5 11 43394830-1x 5 +4y 5 2x5-7y52x5-7y5 11 39430182x5-7y52x5-7y5 - 3x 5 +11y 5 91

9 An example for Lehmer’s GCD x 6 = 2x 5 -7y 5 = 34,681 y 6 = -3x 5 +11y 5 = 10,657 GCD(x 0,y 0 )= … = GCD(x 6,y 6 ) x’y’x”y”ax 6 +by 6 cx 6 +dy 6 q’q” 351034111x6+0y61x6+0y6 0x6+1y60x6+1y6 33 1051110x6+1y60x6+1y6 1x 6 -3y 6 211

10 An example for Lehmer’s GCD x 7 = 0x 6 +1y 6 = 10,657 y 7 = 1x 6 -3y 6 = 2,710 GCD(x 0,y 0 )= … =GCD(x 7,y 7 ) x’y’x”y”ax 7 +by 7 cx 7 +dy 7 q’q” 1121031x7+0y71x7+0y7 0x7+1y70x7+1y7 53

11 An example for Lehmer’s GCD x 8 = y 7 = 2,710 y 8 = x 7 mod y 7 = 2,527 GCD(x 0,y 0 )= … =GCD(x 8,y 8 ) x’y’x”y”ax 8 +by 8 cx 8 +dy 8 q’q” 32231x8+0y81x8+0y8 0x8+1y80x8+1y8 10

12 An example for Lehmer’s GCD x 9 = y 8 = 2,527 y 9 = x 8 mod y 8 = 183 GCD(x 0,y 0 )= … =GCD(x 9,y 9 ) Euclid’s Algorithm …

13 An example for Algorithm ML x 0 = 768,454,923 y 0 = 542,167,814 令 k=3 INPUT:Intergers U,V,k U ≧ V > 0 and k > 0 while V ≠ 0 if len(U)-len(V) ≦ k/2 ML(U,V,K); end if; R=U mod V; U=V; V=R; end while; output(U,V);

14 An example for Algorithm ML  If i is even then  done = b < -X i+1 or a – b < Y i+1 -Y i ;  else  done = b < -Y i+1 or a – b < X i+1 -X i; a= 768 b= 542 (x i,y i ) (1,0) (x i+1,y i+1 ) (0,1) (x i+2,y i+2 ) (1,-1) Q= 1 比較 否 542226(0,1)(1,-1)(-2,3)2 否 22690(1,-1)(-2,3)(5,-7)2 否 9046 (-2 , 3) (5,-7)(-7,10)1 否 4644(5,-7)(-7,10)(12,-17)1 否 442(-7,10)(12,-17)1 2 < 17

15 An example for Algorithm ML  U = 47,099,917 V = 42,493,679 a= 470 b= 424 (x i,y i ) (1,0) (x i+1,y i+1 ) (0,1) (x i+2,y i+2 ) (1,-1) Q= 1 比較 否 42446(0,1)(1,1)(-9,10)9 否 4610(1,-1)(-9,10)(37,-41)4 否 106(-9,10)(37,-41)16<37

16 An example for Algorithm ML  U = 4,606,238 V = 1,037,537 a= 460 b= 103 (x i,y i ) (1,0) (x i+1,y i+1 ) (0,1) (x i+2,y i+2 ) (1,-1) Q= 4 比較 否 10348(0,1)(1,-1)(-2,9)2 否 487(1,-1)(-2,9)(13,-58)6 否 76(-2,9)(13,-58)1 6 < 58

17 An example for Algorithm ML  U = 456,090 V = 125,357 a= 456 b= 125 (x i,y i ) (1,0) (x i+1,y i+1 ) (0,1) (x i+2,y i+2 ) (1,-3) Q= 3 比較 否 12581(0,1)(1,-3)(-1,4)1 否 8144(1,-3)(-1,4)(2,-7)1 否 4437(-1,4)(2,7)(-3,11)1 否 377(2,7)(-3,11)(17,-62)5 否 72(-3,11)(17,-62)3 2 < 62

18 An example for Algorithm ML  U = 34,681 V = 10,657 a= 346 b= 106 (x i,y i ) (1,0) (x i+1,y i+1 ) (0,1) (x i+2,y i+2 ) (1,-3) Q= 3 比較 否 10628(0,1)(1,-3)(-3,10)3 否 2822(1,-3)(-3,10)(4,-13)1 否 226(-3,10)(4,-13)36<13

19 An example for Algorithm ML  U =2,710 V = 2,527 a= 271 b= 252 (x i,y i ) (1,0) (x i+1,y i+1 ) (0,1) (x i+2,y i+2 ) (1,-1) Q= 1 比較 否 25219(0,1)(1,-1)(-13,14)13 否 195(1,-1)(-13,14)35<14

20 An example for Algorithm ML  U = 2527 V = 183  計算完畢即為 183 a= 252 b= 18 (x i,y i ) (1,0) (x i+1,y i+1 ) (0,1) (x i+2,y i+2 ) (1,-14) Q= 14 比較 否 180(0,1)(1,-14)0 否

21 Analysis Algorithm ML  a i+1 ≧ |v i+1 | and a i+1 – a i ≧ |v i+1 +v i |,for all i ≦ k  Algorithm ML computes gcd(u,v), u>v using at most iterations of its main loop.

22 Analysis Algorithm ML  Algorithm ML computes gcd(u,v), u>v using at most bit operations and space.  u,v at most n bits, setting k = obtain an algorithm with a subquadratic runing time of using space

23 Experiment

24

25 Conclusion  K 值得取決大小適當會直接影響執行的速 率,如果取決大小不好,可能會比原來的 Lehmer’s 的演算法還慢並且多繞了一圈, 因為 Lehmer’s 在同時間已經直接 Mod 解決 不需再判斷。  運算中當 a 與 b 值瞬間拉大時,下一行運算 將會出現比較結果成立。


Download ppt "An Analysis of Lehmer’s Euclidean GCD Algorithm Jonathan Sorenson Proceedings of the 1995 international symposium on Symbolic and algebraic computation."

Similar presentations


Ads by Google