(35S) Bézout or EGCD - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (35S) Bézout or EGCD (/thread-2673.html) |
(35S) Bézout or EGCD - Gerald H - 12-20-2014 05:05 PM Bézout (or extended Euclidean algorithm) finds integer solutions for C, E & GCD( X , Y ) in the equation C * X + E * Y = GCD( X , Y ). For example, for stack Y: 666,777 X: 777,666 The programme returns Z: 111 (our GCD) Y: -3,233 (E) X: 2,772 (C) & indeed 2,772 * 777,666 + -3,233 * 666,777 = 111 1 LBL B 2 1►E►F-1►C►D 3 R↓ 4 REGY 5 REGY 6 INT/ 7 +/- 8 ENTER 9 RCL* D 10 RCL+ E 11 x<> D 12 STO E 13 R↓ 14 ENTER 15 RCL* F 16 RCL+ C 17 x<> F 18 STO C 19 R↓ 20 REGY 21 * 22 REGZ 23 + 24 x≠0? 25 GTO B004 26 R↓ 27 RCL E 28 RCL C 29 RTN Should the GCD be 1, then E is the multiplicative inverse of Y modulo X & C the multiplicative inverse of X modulo Y. RE: HP 35S: Bézout or EGCD - Thomas Klemm - 12-21-2014 02:37 AM (12-20-2014 05:05 PM)Gerald H Wrote: Should the GCD be 1, then E is the multiplicative inverse of Y modulo X & C the multiplicative inverse of X modulo Y. You might be interested in: Solving a Single Congruence Equation (04-18-2014 05:24 PM)Thomas Klemm Wrote: Remark: Kind regards Thomas RE: HP 35S: Bézout or EGCD - Gerald H - 12-22-2014 04:32 PM Here an alternative programme to the above, same input & output. I expected the time taken for calculations to be less than with the first progamme & don't really understand why that's not the case. 1 LBL E 2 STO H 3 x<>y 4 STO G 5 [H,1] 6 [G,0] 7 REGX*[1,0] 8 x=0? 9 GTO E022 10 REGZ 11 x<>y 12 / 13 [1,0] 14 * 15 IP 16 REGY 17 * 18 REGZ 19 - 20 +/- 21 GTO E007 22 REGZ*[1,0] 23 REGT*[0,1] 24 (REGY-REGX*H)/G 25 x<>y 26 RTN RE: HP 35S: Bézout or EGCD - Tugdual - 02-17-2015 08:49 AM (12-22-2014 04:32 PM)Gerald H Wrote: Here an alternative programme to the above, same input & output. I expected the time taken for calculations to be less than with the first progamme & don't really understand why that's not the case. Q: How do you evaluate the speed of the execution? My 2 cents GCD program, nothing special here, I just like the simplicity Code: A001 LBLA RE: HP 35S: Bézout or EGCD - Gerald H - 02-17-2015 09:42 AM (02-17-2015 08:49 AM)Tugdual Wrote:(12-22-2014 04:32 PM)Gerald H Wrote: Here an alternative programme to the above, same input & output. I expected the time taken for calculations to be less than with the first progamme & don't really understand why that's not the case. I store the begin time, run the programme, & subtract present time from the stored value. RE: HP 35S: Bézout or EGCD - Tugdual - 02-17-2015 10:04 AM (02-17-2015 09:42 AM)Gerald H Wrote: I store the begin time, run the programme, & subtract present time from the stored value.You have a time function on the 35s? RE: HP 35S: Bézout or EGCD - Dieter - 02-17-2015 07:29 PM (02-17-2015 08:49 AM)Tugdual Wrote: My 2 cents GCD program, nothing special here, I just like the simplicity Whoa... 10 (ten!) steps. Obviously you never used a calculator with limited memory. ;-) Code: A001 LBLA Yes, it's the same method. Dieter RE: HP 35S: Bézout or EGCD - Tugdual - 02-17-2015 07:57 PM (02-17-2015 07:29 PM)Dieter Wrote:Oh wow I would have sworn RMDR was requiring a specific sort order...(02-17-2015 08:49 AM)Tugdual Wrote: My 2 cents GCD program, nothing special here, I just like the simplicity I like the final "A007 +" |