• The following is the code to be implemented for Macaulay2 for computing polynomial division.  The inputs are polynomial f and list L of polynomials to divide f by. The outputs: quotient list "quot" and remainder "rem" of division which satisfy sum q_i*L_i+rem=f and none of the terms of rem are divisible by the leading terms of polynomials in L.

    divisionAlgo=(f,L)->(
              --get the ring in which polynomials are defined
              S := ring f;
              --initialize quotient list and remainder to zero
              quot := new MutableList from apply(L,i->0);
              rem := 0;
              p := f;
              while p != 0 do(
                  i := 0;
                  divisionoccurred := false;
                  while i<=(length(L)-1) and not divisionoccurred do(
                      diffi := (flatten exponents leadTerm(p))-(flatten exponents leadTerm(L_i));
                      if all(diffi,i->i>=0) then(
                      nqt := sub(leadTerm(p)/leadTerm(L_i),S);
                      quot#i = quot#i+nqt;
                      p = p-nqt*L_i;
                      divisionoccurred = true;
                      )else(
                      i = i+1;
                      ));
                  if not divisionoccurred then(
                      rem = rem+leadTerm(p);
                      p = p-leadTerm(p);
                  );
                  );
              (toList quot,rem)
              )

  • Let's try the code for the following division.
    S=QQ[x,y,MonomialOrder=>GLex]
    f=x^7*y^2+x^3*y^2-y+1
    L={x*y^2-x,x-y^3}
    (q,r)=divisionAlgo(f,L)--this assigns the quotient list to the variable q and the remainder to the variable r
  • There is a function called  quotientRemainder that could also be used to compute the remainder in the division. But the command actually computes a Grobner basis in the background and uses that to minimize the remainder. Let's try the following code!
    S=QQ[x,y,MonomialOrder=>GLex]
    f=matrix{{x^7*y^2+x^3*y^2-y+1}}
    L=matrix{{x*y^2-x,x-y^3}}
    (Q,R)=quotientRemainder(f,L)
  • There is also a command f%I which computes the normal form/the unique remainder upon division of f by the ideal I. This commands also computes a Groebner basis of I in the background.
Last modified: Friday, 29 January 2021, 2:25 PM