There's no problem with the answer, as it's also correct:
i8 : A = g3 // gens I
o8 = {2} | -x2y-2xy2+2y+1 |
{2} | xy2+2y3 |
2 1
o8 : Matrix R <-- R
i9 : f = g3 % gens I
o9 = 2y + 1
o9 : R
i10 : gens I * A + f
o10 = | x2y+xy2+y2 |
1 1
o10 : Matrix R <-- R
i11 : oo_(0, 0) == g3
o11 = true
The problem is that, in general, multivariate polynomial division does not give a unique answer. (That's one of the reasons for Groebner bases!) In this example, g1 and g2 do *not* form a Groebner basis for I, so it's not surprising that we might get different results if we use slightly different algorithms (e.g., changing the order of the generators of the ideal).
This looks like one of the multivariate polynomial division examples from Cox, Little, and O'Shea, and here's some code implementing their division algorithm from Section 2.3:
polynomialDivision = (f, F) -> (
s := #F;
q := new MutableList from s:0;
r := 0;
p := f;
while p != 0 do (
i := 0;
divisionOccurred := false;
while i < s and not divisionOccurred do (
if leadTerm p % leadTerm F#i == 0 then (
q#i = q#i + leadTerm p // leadTerm F#i;
p = p - (leadTerm p // leadTerm F#i) * F#i;
divisionOccurred = true)
else i = i + 1);
if not divisionOccurred then (
r = r + leadTerm p;
p = p - leadTerm p));
(toList q, r))
This gives the same answer as in the book:
i14 : polynomialDivision(g3, {g2, g1})
o14 = ({x + 1, x}, 2x + 1)