Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project!

## maxima-commits

 [Maxima-commits] CVS: maxima/share/algebra gcdex.mac,1.2,1.3 From: Andrej Vodopivec - 2007-12-26 10:13:27 ```Update of /cvsroot/maxima/maxima/share/algebra In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv29476 Modified Files: gcdex.mac Log Message: Extended gcdex to work with integers. Index: gcdex.mac =================================================================== RCS file: /cvsroot/maxima/maxima/share/algebra/gcdex.mac,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- gcdex.mac 5 Jun 2001 09:05:14 -0000 1.2 +++ gcdex.mac 26 Dec 2007 10:13:23 -0000 1.3 @@ -17,36 +17,42 @@ remainder(g,ans[3],v)]); */ -gcdex(f,g,[var]):=block([q0,q1,ok:true,lis1,lis2,lis3,q,tem, result], +gcdex(f,g,[var]):=block([q0,q1,ok:true,lis1,lis2,lis3,q,tem,result], + if integerp(f) and integerp(g) then return( igcdex(f, g) ), if (var = []) then var:listofvars([f,g]), if not (length(var) = 1) - then (if (f=0 and g=0) then return([0,0,0]), - error("Specify one main variable or give univariate polynomials") - ), + then (if (f=0 and g=0) then return([0,0,0]), + error("Specify one main variable or give univariate polynomials") + ), var:var[1], f:rat(f),g:rat(g), q0:divide(f,g,var), /* divide(f,g) ==> [q:quotient(f,g),remainder:f-g*q] */ - /* if f/g is 0 then we reverse them */ + /* if f/g is 0 then we reverse them */ if (q0[1]=0) then - /* the deg f < deg g */ - (lis2:gcdex(g,f,var),return([lis2[2],lis2[1],lis2[3]])), + /* the deg f < deg g */ + (lis2:gcdex(g,f,var),return([lis2[2],lis2[1],lis2[3]])), if (q0[2]=0) then lis2:[0,1,g] + else ( + q1:divide(g,q0[2],var), + lis1:[1,-q0[1],q0[2]], + if (q1[2]=0) then lis2:lis1 else ( - q1:divide(g,q0[2],var), - lis1:[1,-q0[1],q0[2]], - if (q1[2]=0) then lis2:lis1 - else ( /* lisi are always perpendicular to [f,g,-1] */ - lis2:[-q1[1],1+q0[1]*q1[1], q1[2]], - while(ok) do - ( q:divide(lis1[3],lis2[3],var), - lis3:lis1-lis2*q[1], - if(lis3[3] = 0) then ok:false - else (lis1:lis2, - lis2:lis3/content(lis3[3],var)[1]) - ))), - if freeof(var,lis2[3]) then lis2/lis2[3] else lis2); - - - + lis2:[-q1[1],1+q0[1]*q1[1], q1[2]], + while(ok) do + ( q:divide(lis1[3],lis2[3],var), + lis3:lis1-lis2*q[1], + if(lis3[3] = 0) then ok:false + else (lis1:lis2, + lis2:lis3/content(lis3[3],var)[1]) + ))), + if freeof(var,lis2[3]) then lis2/lis2[3] else lis2); +igcdex(a,b) := block( + [x:0, lx:1, y:1, ly:0, q, r], + while b#0 do ( + [q,r]:divide(a,b), + [a,b]:[b,r], + [x,lx]:[lx-q*x,x], + [y,ly]:[ly-q*y,y]), + [lx,ly,a])\$ ```