an analysis of lehmer’s euclidean gcd algorithm jonathan sorenson proceedings of the 1995...

25
An Analysis of Lehmer’s Euc lidean GCD Algorithm Jonathan Sorenson Proceedings of the 1995 international symposi um on Symbolic and algebraic computation Speaker: 張張張

Post on 21-Dec-2015

221 views

Category:

Documents


2 download

TRANSCRIPT

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

An Analysis of Lehmer’s Euclidean GCD Algorithm

Jonathan SorensonProceedings of the 1995 international symposium on Symboli

c and algebraic computation

Speaker: 張圻毓

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

Outline

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

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

An example for Lehmer’s GCD

x0= 768,454,923 y0= 542,167,814 b = 103

x’ y’ x” y” ax0+by0 cx0+dy0 q’ q”

769 542 768 543 1x0+0y0 0x0+1y0 1 1

542 227 543 225 0x0+1y0 1x0-1y0 2 2

227 88 225 93 1x0-1y0 -2x0+3y0 2 2

88 51 93 39 -2x0+3y0 5x0-7y0 1 2

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

An example for Lehmer’s GCD

x1= -2x0+3y0= 89,593,596 y1= 5x0-7y0= 47,099,917

GCD(x0,y0)= GCD(x1,y1)

x’ y’ x” y” ax1+by1 cx1+dy1 q’ q”

90 47 89 48 1x1+0y1 0x1+1y1 1 1

47 43 48 41 0x1+1y1 1x1-1y1 1 1

43 4 41 7 1x1-1y1 -1x1+2y1 10 5

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

An example for Lehmer’s GCD

x2= 1x1-1y1= 42,493,679 y2= -1x1+2y1 = 4,606,238

GCD(x0,y0)= GCD(x1,y1)= GCD(x2,y2)

x’ y’ x” y” ax2+by2 cx2+dy2 q’ q”

43 4 42 5 1x2+0y2 0x2+1y2 10 8

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

An example for Lehmer’s GCD

x3= y2= 4,606,238 y3= x2 mod y2 = 1,037,537

GCD(x0,y0)= GCD(x1,y1)= GCD(x2,y2)= GCD(x3,y3)

x’ y’ x” y” ax3+by3 cx3+dy3 q’ q”

5 1 4 2 1x3+0y3 0x3+1y3 5 2

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

An example for Lehmer’s GCD

x4= y3= 1,037,537 y4= x3 mod y3 = 456,090

GCD(x0,y0)= … = GCD(x4,y4)

x’ y’ x” y” ax4+by4 cx4+dy4 q’ q”

2 0 1 1 1x4+0y4 0x4+1y4 - -

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

An example for Lehmer’s GCD

x5= y4= 456,090 y5= x4 mod y4 = 125,357

GCD(x0,y0)= … = GCD(x5,y5)

x’ y’ x” y” ax5+by5 cx5+dy5 q’ q”

457 125 456 126 1x5+0y5 0x5+1y5 3 3

125 82 126 78 0x5+1y5 1x5-3y5 1 1

82 43 78 48 1x5-3y5 -1x5+4y5 1 1

43 39 48 30 -1x5+4y5 2x5-7y5 1 1

39 4 30 18 2x5-7y5 -3x5+11y5

9 1

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

An example for Lehmer’s GCD

x6= 2x5-7y5 = 34,681 y6= -3x5+11y5 = 10,657

GCD(x0,y0)= … = GCD(x6,y6)

x’ y’ x” y” ax6+by6 cx6+dy6 q’ q”

35 10 34 11 1x6+0y6 0x6+1y6 3 3

10 5 11 1 0x6+1y6 1x6-3y6 2 11

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

An example for Lehmer’s GCD

x7= 0x6+1y6 = 10,657 y7= 1x6-3y6 = 2,710

GCD(x0,y0)= … =GCD(x7,y7)

x’ y’ x” y” ax7+by7 cx7+dy7 q’ q”

11 2 10 3 1x7+0y7 0x7+1y7 5 3

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

An example for Lehmer’s GCD

x8= y7 = 2,710 y8= x7 mod y7 = 2,527

GCD(x0,y0)= … =GCD(x8,y8)

x’ y’ x” y” ax8+by8 cx8+dy8 q’ q”

3 2 2 3 1x8+0y8 0x8+1y8 1 0

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

An example for Lehmer’s GCD

x9= y8 = 2,527 y9= x8 mod y8 = 183

GCD(x0,y0)= … =GCD(x9,y9)

Euclid’s Algorithm

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

An example for Algorithm ML

x0= 768,454,923 y0= 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);

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

An example for Algorithm ML If i is even then done = b < -Xi+1 or a – b < Yi+1-Yi ;

else done = b < -Yi+1 or a – b < Xi+1-Xi;

a=

768

b=

542

(xi,yi)

(1,0)

(xi+1,yi+1)

(0,1)

(xi+2,yi+2)

(1,-1)

Q=

1

比較否

542 226 (0,1) (1,-1) (-2,3) 2 否

226 90 (1,-1) (-2,3) (5,-7) 2 否

90 46 (-2, 3) (5,-7) (-7,10) 1 否

46 44 (5,-7) (-7,10) (12,-17) 1 否

44 2 (-7,10) (12,-17) 1 2< 17

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

An example for Algorithm ML

U = 47,099,917 V = 42,493,679

a=

470

b=

424

(xi,yi)

(1,0)

(xi+1,yi+1)

(0,1)

(xi+2,yi+2)

(1,-1)

Q=

1

比較否

424 46 (0,1) (1,1) (-9,10) 9 否46 10 (1,-1) (-9,10) (37,-41) 4 否10 6 (-9,10) (37,-41) 1 6<37

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

An example for Algorithm ML

U = 4,606,238 V = 1,037,537

a=

460

b=

103

(xi,yi)

(1,0)

(xi+1,yi+1)

(0,1)

(xi+2,yi+2)

(1,-1)

Q=

4

比較否

103 48 (0,1) (1,-1) (-2,9) 2 否48 7 (1,-1) (-2,9) (13,-58) 6 否7 6 (-2,9) (13,-58) 1 6 < 5

8

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

An example for Algorithm ML

U = 456,090 V = 125,357

a=

456

b=

125

(xi,yi)

(1,0)

(xi+1,yi+1)

(0,1)

(xi+2,yi+2)

(1,-3)

Q=

3

比較否

125 81 (0,1) (1,-3) (-1,4) 1 否81 44 (1,-3) (-1,4) (2,-7) 1 否44 37 (-1,4) (2,7) (-3,11) 1 否37 7 (2,7) (-3,11) (17,-62) 5 否7 2 (-3,11) (17,-62) 3 2 < 6

2

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

An example for Algorithm ML

U = 34,681 V = 10,657

a=

346

b=

106

(xi,yi)

(1,0)

(xi+1,yi+1)

(0,1)

(xi+2,yi+2)

(1,-3)

Q=

3

比較否

106 28 (0,1) (1,-3) (-3,10) 3 否28 22 (1,-3) (-3,10) (4,-13) 1 否22 6 (-3,10) (4,-13) 3 6<13

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

An example for Algorithm ML

U =2,710 V = 2,527

a=

271

b=

252

(xi,yi)

(1,0)

(xi+1,yi+1)

(0,1)

(xi+2,yi+2)

(1,-1)

Q=

1

比較否

252 19 (0,1) (1,-1) (-13,14) 13 否19 5 (1,-1) (-13,14) 3 5<14

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

An example for Algorithm ML

U = 2527 V = 183 計算完畢即為 183

a=

252

b=

18

(xi,yi)

(1,0)

(xi+1,yi+1)

(0,1)

(xi+2,yi+2)

(1,-14)

Q=

14

比較否

18 0 (0,1) (1,-14) 0 否

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

Analysis Algorithm ML

ai+1 |v≧ i+1| and ai+1 – ai |v≧ i+1+vi| ,for all i k≦

Algorithm ML computes gcd(u,v), u>v using at most

iterations of its main loop.

)log

( kk

vO

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

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

)loglogloglog

( 2kuvkk

vuO

)2(log 2kkuO

4)(log n

)log( 2 nnO )(nO

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

Experiment

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

Experiment

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

Conclusion

K 值得取決大小適當會直接影響執行的速率,如果取決大小不好,可能會比原來的Lehmer’s 的演算法還慢並且多繞了一圈, 因為 Lehmer’s 在同時間已經直接 Mod 解決不需再判斷。

運算中當 a 與 b 值瞬間拉大時,下一行運算將會出現比較結果成立。