(* The output of this procedure is: If f = x[1]x[2]^3 + 5 x[1]x[2]x[3]^2 + 7x[2]^2 and V = {x[1],x[2],x[3]} then Monomials[f,V]={{{1, 3, 0}, 1}, {{1, 1, 2}, 5}, {{0, 2, 0}, 7}}. Notice that the terms are given in Lex order and the coefficient is the second term in each pair. *) Monomials[f_, V_] := Block[{M}, InputForm[M = Internal`DistributedTermsList[f, V]]; M[[1]]] (* The leading monomial in Lex of f withrespect to the variables V in Lex is *) LeadMon[f_,V_] := Monomials[f,V][[1,1]] (* The leading coefficient relative to Lex is *) LeadCoeff[f_,V_] := Monomials[f,V][[1,2]] (* Given a set of polynomials L in the variables V this outputs the set of lead monomials realtive to Lex *) MkLeads[L_,V_] := Block[{M,i,j,f}, p = Length[L]; M = {}; For[i=1,i<=p,i++, f = Monomials[L[[i]],V]; M = Append[M,f[[1,1]]]]; M] (* Once one has a Groebner basis relative to Lex and one has applied MkLeads to get L this procedure gives the dimension *) Dim[L_,n_] := Block[{j,s,d,u,TMP,TMP1,Z,z}, If[Length[L]<=0, Return[n]]; If[n==1,If[MemberQ[L,{0}],Return[-1]];Return[0]]; Z = Array[z,n]; Z = 0 Z; If[MemberQ[L,Z], Return[-1]]; s = Length[L]; TMP = {}; TMP1 = {}; For[j=1,j<=s,j++, If[L[[j,1]]==0, TMP = Append[TMP,Delete[L[[j]],1]]]; TMP1 = Append[TMP1,Delete[L[[j]],1]]]; d = Dim[TMP,n-1]; u = Dim[TMP1,n-1] + 1; Max[d,u]] (* This outputs the hilbert series same steps as for dimension but the output is unreadable use Hilb instead.*) hilb[L_,n_] := Block[{m,p,i,j,t,Z,TMP}, If[Length[L]<=0,Return[1/(1-q)^n]]; Z=Array[0 # &,n]; If[MemberQ[L,Z],Return[0]]; p = Length[L]; If[n==1,m = L[[1,1]]; For[i=2,i<=p,i++,If[L[[i,1]]m,m = L[[i,1]]]]; t=0; For[i=0,i