%mathpiper,def="DivTermList"

// Implements the division of polynomials!

Function("DivTermList",{a,b})
[
 Local(q,nq,t,c,begining);
 q := {};
 // a[1][1] is the degree of a, b[1][1] is the degree of b
 While ((a!={}) And a[1][1]>=b[1][1])
  [
     begining := 1;
     If(InVerboseMode(),Echo("degree=",a[1][1]));
     nq := {a[1][1]-b[1][1],a[1][2]/b[1][2]}; // a new term of the quotient
     DestructiveAppend(q,nq);
     // We compute a:= a - nq* b
     ForEach (t,b)
       begining := AddTerm(a,{t[1]+nq[1],-t[2]*nq[2]},begining);
   ];
   // a is the rest at the end
 q;
];

%/mathpiper