You might prefer this version of gcdex, though it takes
an additional argument, the main variable..., it does
not require that expressions be univariate.
gcdex1(m,n,x):=
/* Given 2 expressions m and n in x, we compute their
GCD and two multipliers a and b such that a*m+b*n=d.
Knuth vol 1 algorithm E */
block([ap,b,bp,r:1,q],
[ap,b,a,bp,m,n]:[1,1,0,0,rat(m,x),rat(n,x)],
loop, [q,r]:divide(m,n,x),
if(r=0) then [a,b,n]/content(n,x)[1]
else
([m,n,t]:[n,r,ap],
[ap,a,t,bp]: [a,t-q*a,bp,b],
b:t-q*b,
go (loop)))$
Here's a checking program.. which should return 0.
checkg(m,n,x):= ([a,b,d]: gcdex1(m,n,x), a*m+b*n=d)
checkg (a*z+1,b*z-1,z);
the results, but not checkg, are different if you
choose as main variable a or b...
PS, apologizes for the goto.. Knuth uses it..
RJF