# $Id$ # # Extended GCD matextgcd := function(v) local m, q, qr, l; m := [[1,0],[0,1]]; l := 2; while v[l] <> 0 do qr := QuotientRemainder(v[l-1],v[l]); Add(v,qr[2]); l := l+1; q := qr[1]; m := [[0,1],[1,-q]] * m; od; return [m[1][1],m[1][2],v[l-1]]; end;