# # # based on algorithms outlined in "Ideals, Varieties & Algorithms" # (preprint) by Cox, Little, O'Shea # simple norm gpolyutil[mvnorm]:=proc(type::name,exponents::list) local i; if ( type = `grevlex` or type = `grlex` ) then RETURN(sum(exponents['i'],'i'=1..nops(exponents))); fi; ERROR(type . ` not implemented`); end: # determine whether expone>exptwo in our ordering gpolyutil[mvorder]:=proc(type::name, expone::list, exptwo::list) local normone, normtwo, newlist, i; normone := gpolyutil[mvnorm](type, expone); normtwo := gpolyutil[mvnorm](type, exptwo); if ( nops(expone) <> nops(exptwo) ) then ERROR(`invalid args`) fi; if ( type = `grevlex` ) then if ( normone < normtwo ) then RETURN(false) fi; if ( normone > normtwo ) then RETURN(true) fi; newlist:=[seq(expone[i]-exptwo[i],i=1..nops(expone))]; i:=nops(%); while(newlist[i]=0 and i>1) do i:=i-1; od; if ( newlist[i] < 0 ) then RETURN(true) else RETURN(false) fi; fi; if ( type = `grlex` ) then if ( normone <= normtwo ) then RETURN(false) fi; if ( normone > normtwo ) then RETURN(true) fi; newlist:=[seq(expone[i]-exptwo[i],i=1..nops(expone))]; i:=nops(%); while(newlist[i]=0 and i < nops(newlist)) do i:=i+1; od; if (newlist[i]>0) then RETURN(true) else RETURN(false) fi; fi; ERROR(type . ` not implemented`); end: # return the ordered max of a list. gpolyutil[mvmax]:=proc(type::name, exponents::list) local i, current; if ( nops( exponents ) = 0 ) then ERROR(`zero list`) fi; current := exponents[1]; for i from 1 to nops(exponents) do if gpolyutil[mvorder](type,exponents[i],current) then current := exponents[i]; fi; od; RETURN(current); end: # given polynomial, list of coefficients & list of variables, return # the coefficient of the corresponding monomial in the polynomial. gpolyutil[mvcoeff]:=proc(p::polynom,exps::list,v::list) local i; if ( nops(v)0 ) then coeff(%,v[i],exps[i]) fi; if ( exps[i]=0 ) then subs( v[i]=0, % ) fi; od; %; end: # given list of exponents and list of variables, construct the monomial # consisting of Prod(var[i]^(exp[i])) gpolyutil[mvmono]:=proc(exps::list,v::list) local i; if (nops(v) 0 ) do i:=1; termremoved:=false; while ((i <= nargs-3) and (not termremoved)) do if (i > nops(result)) then result:=[op(result),0] fi; if divide(gpolyutil[initf](otype,q,vars), gpolyutil[initf](otype,args[3+i],vars), 'smallres') then result[nops(result)]+smallres; result:=[op(1..nops(result)-1,result),%]; q := expand(q-smallres*args[3+i]); else i:=i+1; fi; if (q = 0) then result:=[op(result),seq(0,j=i..nargs-4)]; break fi; od; if (not termremoved) then rem := rem + gpolyutil[initf](otype,q,vars); q := q - gpolyutil[initf](otype,q,vars); fi; od; result,rem; end: