########这是Groebner基的一个辅助文件,主要有两个程序。 ###程序1: 判定一个多项式是否在一个理想中,如果是,则将该多项式写成生成元的线性组合。 ###调用方法representation(p,F,ord); 程序说明和例子,请见下面 ###程序2: 计算一个多项式模的Groebner基,输入一个多项式向量组,返回它的Groebner基。 ###调用方法ModuleGB(Vector_set, Position_set, ModOrder); 程序说明和例子,请见下面 ####因为程序很小,所有例子就放到一起了。 restart; #######输入:p 一个多项式, F=[f1,...,fs]一个多项式列表, ord 一个单项式序 ; #######输出: 如果p在中中,输出列表 [a1,...,as] , 使得p=a1*f1+...+as*fs 如果 ; ###########: 如果p不在中,输出"p不在理想中"。 ; representation:=proc(p, F, ord) local s, Elist, PS,pord, FullOrder, i,G,r, Q, Deg2PositionPol, AllPol; s:=nops(F); Elist:=[seq(E[i],i=0..s)]; PS:=[]; for i to nops(F) do PS:=[op(PS), E[i]+F[i]*E[0]]; od; FullOrder:=prod(plex(op(Elist)),ord); Deg2PositionPol:=ListProduct(Elist,Elist); AllPol:={op(PS), op(Deg2PositionPol)}; G:=Groebner[Basis]({op(PS), op(Deg2PositionPol)},FullOrder); r:=Groebner[NormalForm](-p*E[0], G, FullOrder); if degree(r, E[0])=0 then return [coeffs(r, Elist[2..s+1])] else print("the polynomial is not in the ideal") end if; end proc; # # # ListProduct:=proc(List1, List2) local i,j, res; res:={}; for i in List1 do for j in List2 do res:={op(res), i*j}; od; od; return res; end proc: ### 1. Onedegree_polys: select elements from GB of the module whose degrees of the position variables are one,and convert them into corresponding vector form ### ## Input: GB--- a minimal CGS on some branch ## ## Position_set--- a set of position variables (or called the placeholder variables ) ## ## Output: a set of vectors whose degrees of all position variables are one ## Onedegree_polys:=proc (GB, Position_set) local MGB,p,v,i; MGB:={}; for p in GB do if degree(p, Position_set)=1 then v:=[]; for i to nops(Position_set) do v:=[op(v),coeff(p,Position_set[i])]; od; MGB:=MGB union {v}; fi; od; return MGB; end proc: ######计算一个模的Groebner基###### ######输入:向量集Vectors_set,是一个多项式向量。 位置变量集Position_set=[e1,...,es],模的序ModOrder要包含变元x,y,z的序和位置变量的序e1,e2,e3###### ######输出:模的Groebner基, 也是一个多项式向量##### ModuleGB:=proc(Vector_set, Position_set, ModOrder) local n,m,Poly_set,i,j,G,k,MCGS; n:=nops(Vectors_set); m:=nops(Position_set); ## first convert polynomial vectors to polynomials in a set of variables and position variables ## Poly_set:={seq(ListTools[DotProduct](Vectors_set[i], Position_set),i=1..n)}; ## regard the position variables as normal variables, then convert vectors to polynomials in a set of variables and position variables (i.e., f:=a*x*e[1]+b*x*y*e[2], e[1],e[2] are the position variables)## Poly_set:=Poly_set union ListProduct(Position_set,Position_set) ; G:=Groebner[Basis]( Poly_set, ModOrder); #print(G); MCGS:=Onedegree_polys(G, Position_set); ## convert the polynomials back to polynomial vectors ## return MCGS; end proc: F := [x^2-2*x*z+5, y*z^3+x*y^2, -8*z^3+3*y^2]; p := -18*x*y^5*z-96*x*y^4*z^2+9*x*y^4-592*x*y^3*z+45*y^5+240*y^4*z+320*x*y^2+1600*y^3; G:=Groebner[Basis](F,tdeg(x,y,z)); trace(representation); R:=representation(p,F,tdeg(x,y,z)); #上述返回的就是多项式p在理想F中生成的系数。 ; #下面来验证这个结论 ; p-expand(ListTools[DotProduct](R,F)); 换一个序试试 ; R:=representation(p,F,plex(x,y,z)); p-expand(ListTools[DotProduct](R,F)); #仍然正确 ; trace(ModuleGB); Vectors_set := {[x^2-b, 0, 1], [a*x+x^2+1, 1, 0]}; Position_set:=[e1,e2,e3]; ModOrder:=prod(plex(e1,e2,e3), plex(x)); ###要特别注意位置变量是列表,而且必须出现在序中, 这个序来确定模的序是TOP和POT. ModuleGB(Vector_set, Position_set, ModOrder);