1 # -*- mode: maplev; -*-
\r
6 #########################################################
\r
7 #11111111111111111111111111111111111111111111111111111111
\r
9 #Part I: The basic functions
\r
10 # Class, Leader, Initial
\r
11 #########################################################
\r
15 _field_characteristic_:=0;
\r
18 # the class of poly f wrt variable ordering ord
\r
19 Class := proc(dp,ord)
\r
21 options remember,system;
\r
23 for i to nops(ord) do
\r
24 if member(ord[i], idt) then RETURN(nops(ord)-i+1) fi
\r
28 # the highest order of the indeterminate var in dp
\r
31 # var: an indeterminate
\r
32 # OUTPUT: the order
\r
34 dOrder:=proc(dp,var)
\r
36 options remember,system;
\r
41 if dvar=-1 or type(dvar,symbol)
\r
42 or ( ( not type(i,symbol) ) and ( op(1,i) > op(1,dvar) ) ) then
\r
48 elif type(dvar,symbol) then 0
\r
49 else if nops(dvar) =1 then op(1,dvar)
\r
50 else [op(1..nops(dvar),dvar)]
\r
57 local i,indet_d,idt;
\r
58 options remember,system;
\r
60 indet_d:=indets(dp);
\r
62 if POLY_MODE='Algebraic' then RETURN(indet_d) fi;
\r
64 for i in indet_d do
\r
65 if type(i,symbol) then idt:={op(idt),i} else idt:={op(idt),op(0,i)} fi;
\r
70 # the initial of poly f wrt ord
\r
74 options remember,system;
\r
75 if Class(f,ord) = 0 then 1
\r
76 else lcoeff(f,Leader(f,ord));
\r
80 # the separant of poly f wrt ord
\r
84 options remember,system;
\r
85 if Class(f,ord) = 0 then 1
\r
86 else diff(f,Leader(f,ord));
\r
92 options remember,system;
\r
93 pol:=Separant(p,ord);
\r
94 if Class(pol,ord)=0 then RETURN(1) fi;
\r
98 # the set of all nonconstant factors of separants of polys in as
\r
100 Septs:=proc(bset,ord)
\r
102 options remember,system;
\r
104 for i in bset do list:=list union Factorlist(Sept(i,ord)) od;
\r
105 for i in list do if Class(i,ord)=0 then list:=list minus {i} fi od;
\r
115 local cf,cg,cmp,df,dg,leadf,leadg;
\r
116 options remember,system;
\r
117 cf := Class(f,ord);
\r
118 cg := Class(g,ord);
\r
119 if type(f,integer) then
\r
121 elif type(g,integer) then
\r
128 leadf:=Leader(f,ord);
\r
129 leadg:=Leader(g,ord);
\r
131 cmp:=dercmp(leadf,leadg,ord);
\r
137 df := degree(f,leadf);
\r
138 dg := degree(g,leadg);
\r
142 Lessp(Initial(f,ord),Initial(g,ord),ord)
\r
154 options remember,system;
\r
157 for i from 2 to nops( ps ) do
\r
158 if Lessp(op(i,ps),lpol,ord) then lpol:=op(i,ps) fi;
\r
164 #############################################4 Reduced Definitions########################3
\r
168 local mvar,var,idt;
\r
169 options remember,system;
\r
171 mvar:=Leader(q,ord);
\r
172 if type(mvar,symbol) then var:=mvar else var:=op(0,mvar) fi;
\r
174 if POLY_MODE='Algebraic' then
\r
175 ###############Algebraic mode#################################
\r
176 if nargs <4 or T='std_asc' then
\r
177 if Class(p,ord) > Class(q,ord) and degree(p,mvar) < degree(q,mvar) then 1 else 0 fi;
\r
178 elif T='wu_asc' then
\r
179 if Class(p,ord) > Class(q,ord) and degree(Initial(p,ord),mvar) < degree(q,mvar) then 1 else 0 fi;
\r
180 elif T='gao_asc' then
\r
181 ###########################in the following case , q is a list#################
\r
182 if Class(p,ord) > Class(op(1,q),ord) and Premas(Initial(p,ord),q,ord,'std_asc') <>0 then 1 else 0 fi;
\r
183 elif T='tri_asc' then
\r
184 if Class(p,ord) > Class(q,ord) then 1 else 0 fi;
\r
186 ###############Algebraic mode#################################
\r
187 elif POLY_MODE='Ordinary_Differential' then
\r
188 ###############ODE mode#################################
\r
189 if nargs <4 or T='std_asc' then
\r
191 if Class(p,ord) > Class(q,ord) and degree(p,mvar) < degree(q,mvar)
\r
192 and dOrder(p,var) <= dOrder(q,var) then
\r
197 elif T='wu_asc' then
\r
198 if Class(p,ord) > Class(q,ord) and degree(Initial(p,ord),mvar) < degree(q,mvar) then 1 else 0 fi;
\r
199 elif T='gao_asc' then
\r
200 ###########################in the following case , q is a list#################
\r
201 if Class(p,ord) > Class(op(1,q),ord) and Premas(Initial(p,ord),q,ord,'std_asc') <>0 then 1 else 0 fi;
\r
202 elif T='tri_asc' then
\r
203 if Class(p,ord) > Class(q,ord) then 1 else 0 fi;
\r
206 ###############ODE mode#################################
\r
207 elif POLY_MODE='Partial_Differential' then
\r
208 ###############PDE mode#################################
\r
209 if nargs <4 or T='std_asc' then
\r
212 if dercmp(Leader(p,ord), mvar, ord)=-1 and degree(p,mvar) < degree(q,mvar)
\r
213 and (not member(true, map(Is_proper_derivative,idt,mvar)) ) then
\r
218 elif T='wu_asc' then
\r
219 if Class(p,ord) > Class(q,ord) and degree(Initial(p,ord),mvar) < degree(q,mvar) then 1 else 0 fi;
\r
220 elif T='gao_asc' then
\r
221 ###########################in the following case , q is a list#################
\r
222 if Class(p,ord) > Class(op(1,q),ord) and Premas(Initial(p,ord),q,ord,'std_asc') <>0 then 1 else 0 fi;
\r
223 elif T='tri_asc' then
\r
224 if Class(p,ord) > Class(q,ord) then 1 else 0 fi;
\r
229 ###############PDE mode#################################
\r
233 #############################
\r
235 # Name: Reducedset
\r
236 # Input: ps: a poly set
\r
238 # OUTPUT: redset:={q | q is in ps, q is rReduced to p }
\r
239 #############################
\r
245 options remember,system;
\r
248 if Reducedp(i,p,ord,T)=1 then redset:={i,op(redset)} fi;
\r
253 ##############################################################################
\r
254 ##############################################################################
\r
255 # the basic set of polyset ps
\r
260 options remember,system;
\r
261 if nops(ps) < 2 then [op(ps)]
\r
265 while (nops(qs) <>0) do
\r
268 if T='gao_asc' then
\r
269 qs :=Reducedset(qs,bs,ord,T);
\r
271 qs :=Reducedset(qs,b,ord,T);
\r
278 ##############################################################
\r
279 # modified pseudo division: I1^s1...Ir^sr*uu = q*vv + r,
\r
280 # where I1, ..., I_r are all distinct factors of lcoeff(vv,x)
\r
281 # and s1, ..., sr are chosen to be the smallest
\r
282 ##############################################################
\r
286 local r,v,dr,dv,l,t,lu,lv,gcd0;
\r
287 options remember,system;
\r
288 if type(vv/x,integer) then subs(x = 0,uu)
\r
291 dr := degree(r,x);
\r
293 dv := degree(v,x);
\r
294 if dv <= dr then l := coeff(v,x,dv); v := expand(v-l*x^dv)
\r
297 while dv <= dr and r <> 0 do
\r
298 # gcd0:=gcd(l,coeff(r,x,dr),'lu','lv');
\r
299 gcd0:=gcd(l,coeff(r,x,dr));
\r
300 lu:=simplify(l/gcd0);
\r
301 lv:=simplify(coeff(r,x,dr)/gcd0);
\r
303 lv:=coeff(r,x,dr);
\r
304 t := expand(x^(dr-dv)*v*lv);
\r
305 if dr = 0 then r := 0 else r := subs(x^dr = 0,r) fi;
\r
306 r := expand(lu*r)-t;
\r
314 ###################################################################################
\r
315 ##############################################################
\r
316 # modified pseudo division: I1^s1...Ir^sr*uu = q*vv + r,
\r
317 # where I1, ..., I_r are all distinct factors of lcoeff(vv,x)
\r
318 # and s1, ..., sr are chosen to be the smallest
\r
319 ##############################################################
\r
323 local r,v,dr,dv,l,t,lu,lv,gcd0;
\r
324 options remember,system;
\r
325 global _field_characteristic_;
\r
326 if type(vv/x,integer) then subs(x = 0,uu)
\r
329 dr := degree(r,x);
\r
331 dv := degree(v,x);
\r
332 if dv <= dr then l := coeff(v,x,dv); v := expand(v-l*x^dv)
\r
335 while dv <= dr and r <> 0 do
\r
336 # gcd0:=gcd(l,coeff(r,x,dr),'lu','lv');
\r
337 gcd0:=gcd(l,coeff(r,x,dr));
\r
338 lu:=simplify(l/gcd0);
\r
339 lv:=simplify(coeff(r,x,dr)/gcd0);
\r
341 lv:=coeff(r,x,dr);
\r
342 t := expand(x^(dr-dv)*v*lv) mod _field_characteristic_;
\r
343 if dr = 0 then r := 0 else r := subs(x^dr = 0,r) mod _field_characteristic_ fi;
\r
344 r := expand(lu*r)-t mod _field_characteristic_;
\r
345 # r :=finite_simplify(r,ord,_field_characteristic_);
\r
351 #################################################
\r
352 finite_simplify:=proc(r,ord,p)
\r
355 for i to nops(ord) do
\r
356 res:=subs(ord[i]^p=ord[i],res) mod p;
\r
362 ###################################################################################
\r
363 ###################################################################################
\r
365 # pseudo remainder of poly f wrt ascending set as
\r
371 options remember,system;
\r
372 if nargs < 4 then asc:='std_asc' else asc:=T fi;
\r
373 r0:=Premas_a(f,as,ord,asc);
\r
374 if POLY_MODE <> 'Partial_Differential' then RETURN(r0) fi;
\r
376 r1:=Premas_a(r0,as,ord,asc);
\r
379 r1:=Premas_a(r0,as,ord,asc);
\r
391 local remd,i,degenerate;
\r
392 options remember,system;
\r
393 global _field_characteristic_ ;
\r
395 #################ÏÂÃæרÃÅ´¦ÀíÓÐÏÞÓòµÄÇéÐÎ############
\r
396 if (_field_characteristic_ <> 0) then
\r
397 for i to nops(as) do
\r
400 remd := NPremfinite(remd,as[i],Leader(as[i],ord),ord);
\r
407 #######################################################
\r
410 for i to nops(as) do
\r
413 remd := NewPrem(remd,as[i],Leader(as[i],ord));
\r
418 elif T='std_asc' then
\r
420 for i to nops(as) do
\r
422 remd := NewPrem(remd,as[i],Leader(as[i],ord));
\r
426 elif T='tri_asc' then
\r
428 for i to nops(as) do
\r
429 if Class(remd,ord) = Class(as[i],ord) then
\r
430 remd := NewPrem(remd,as[i],Leader(as[i],ord));
\r
435 ###########for wu ascending set#############
\r
436 elif T='wu_asc' then
\r
438 for i to nops(as) do
\r
439 remd := WuPrem(remd,as[i],Leader(as[i],ord),ord,'degenerate');
\r
440 if degenerate=1 then RETURN( Premas(remd,as,ord,T)) fi;
\r
442 ##################################################
\r
444 elif T='gao_asc' then
\r
446 if Premas( Initial(remd,ord), as,ord,'std_asc' ) =0 then RETURN( Premas(remd,as,ord,'std_asc') ) fi;
\r
447 for i to nops(as) do
\r
448 if Class(remd,ord) = Class(as[i],ord) then
\r
449 remd := NewPrem(remd,as[i],Leader(as[i],ord));
\r
450 if Premas( Initial(remd,ord), as,ord,'std_asc' ) =0 then RETURN( Premas(remd,as,ord,'std_asc') ) fi;
\r
458 if remd <> 0 then numer(remd/lcoeff(remd)) else 0 fi
\r
462 ###################################################################################
\r
463 ###################################################################################
\r
465 # set of non-zero remainders of polys in ps wrt ascending set as
\r
469 local i,set,pset,r;
\r
470 options remember,system;
\r
473 pset:={op(ps)} minus {op(as)};
\r
475 if POLY_MODE='Partial_Differential' then pset := pset union spolyset(as,ord) fi;
\r
477 # print("pset=",pset);
\r
479 for i in pset do r:=Premas(i,as,ord,T);
\r
480 if r <>0 and Class(r,ord) =0
\r
482 else set:=set union {r} fi
\r
486 ###############################misc procedures###########
\r
487 Reverse:=proc(list)
\r
489 n := nops(list); list1 := [seq(list[n-i+1],i = 1 .. n)]; list1
\r
494 ###################################################################################
\r
495 # Factor the polynomials in Remaider set
\r
496 ###################################################################################
\r
498 Produce:=proc(rs,ord,test)
\r
500 options remember,system;
\r
501 local i,j,list1,list2;
\r
504 list1 := Nonumber(Factorlist(i),ord);
\r
505 remfac := remfac union (list1 intersect test);
\r
506 list1 := list1 minus test;
\r
508 if Class(j,ord) = 0 then list1 := list1 minus {j} fi
\r
510 list2 := list2 union {list1}
\r
512 for j in list2 do if j = {} then RETURN({}) fi od;
\r
516 Nonumber:=proc(list,ord)
\r
518 options remember,system;
\r
520 for i in list do if 0 < Class(i,ord) then ls := ls union {i} fi od;
\r
524 Factorlist:=proc(pol)
\r
525 local i,list1,list2;
\r
526 options remember,system;
\r
527 if (_field_characteristic_ <>0) then
\r
528 list1:=(Factors(pol) mod _field_characteristic_)[2];
\r
530 list1 := factors(pol)[2];
\r
533 for i in list1 do list2 := list2 union {numer(i[1])} od;
\r
537 #input two poly set set1,set2
\r
539 Ltl:=proc(list1,list2)
\r
541 options remember,system;
\r
543 for i in list1 do for j in list2 do set := set union {{j,i}} od od
\r
546 Lltl:=proc(llist1,list2)
\r
548 options remember,system;
\r
550 for i in llist1 do
\r
551 for j in list2 do set := set union {i union {j}} od
\r
556 #input a polynomial set RS:={R1,R2,...,Rn}
\r
557 #output a set in which every element is a poly set. set:={set1,set2,...,sets}
\r
559 Nrs:=proc(rs,ord,test)
\r
560 local rm,rss,l1,i,j,rset;
\r
561 options remember,system;
\r
562 rss := Produce(rs,ord,test);
\r
563 if rss={} then RETURN({}) fi;
\r
564 # print("rss=");print(rss);
\r
565 rset:=LProduct(rss);
\r
569 LProduct:=proc(inlist) # ÊäÈëÊǼ¯ºÏµÄ¼¯ºÏ£¬Êä³öÒ²ÊǼ¯ºÏµÄ¼¯ºÏ
\r
570 local i,j,k,m,n,B,C,D,T;
\r
571 options remember,system;
\r
573 for i from 1 to nops(op(1,inlist)) do
\r
574 B:=[op(B),{op(i,op(1,inlist))}];
\r
576 for i from 2 to nops(inlist) do
\r
578 for j from 1 to nops(B) do
\r
579 if ((B[j] intersect op(i,inlist))<>{}) then
\r
581 else D:=[op(D),B[j]];
\r
585 for m from 1 to nops(D) do
\r
587 for n from 1 to nops(C) do
\r
588 if (nops(C[n] minus D[m])=1) then
\r
589 T:=T minus (C[n] minus D[m]);
\r
592 for k from 1 to nops(T) do
\r
593 B:= [op(B),D[m] union {op(k,T)}];
\r
600 LProduct_wdk:=proc(list1)
\r
601 local len,lls,i,j;
\r
602 options remember,system;
\r
604 if len=0 then RETURN(list1) fi;
\r
606 for i in op(1,list1) do
\r
607 lls:=lls union { {i} }
\r
609 if len=1 then RETURN (lls) fi;
\r
610 for j from 2 to len do
\r
611 lls:=Lltl(lls, op(j,list1));
\r
616 Lltl:=proc(lls,ls)
\r
617 local res,i,j,l1,rm;
\r
618 options remember,system;
\r
621 if i intersect ls ={} then
\r
623 res:= res union { i union {j} };
\r
626 res:=res union {i};
\r
633 for j from i+1 to l1 do
\r
634 if op(i,res) minus op(j,res) = {} then
\r
635 rm := rm union {op(j,res)}
\r
637 if op(j,res) minus op(i,res) = {} then
\r
638 rm := rm union {op(i,res)}
\r
642 res := res minus rm;
\r
646 #######################################################
\r
650 ######################################################
\r
651 Nums:=proc(ps,ord)
\r
653 options remember,system;
\r
656 if Class(i,ord)=1 and POLY_MODE='Algebraic' then n:=n+1 fi ;
\r
657 if Class(i,ord)=1 and (POLY_MODE='Partial_Differential' or POLY_MODE='Ordinary_Differential') and torder(Leader(i,ord))=0 then n:=n+1 fi;
\r
662 Emptyset:=proc(ds,as,ord)
\r
664 options remember,system;
\r
666 if {op(ds)} intersect {op(as)} <> {} then RETURN(1) fi;
\r
667 # for i in ds do if grobner[normalf](i,as,tdeg(op(ord)))=0 then RETURN(1) fi od;
\r
671 Non0Constp:=proc(ps,ord)
\r
673 options remember,system;
\r
674 for i in ps do if Class(i,ord)=0 and i <> 0 then RETURN(1) fi od;
\r
679 TestQ:=proc(ps,as,ord)
\r
682 options remember,system;
\r
684 for i in ps do if grobner[normalf](i,as,ord) = 0 then remfac:=remfac union {i};RETURN(1) fi od;
\r
690 options remember,system;
\r
691 pol:=Initial(p,ord);
\r
692 if Class(pol,ord)=0 then RETURN(1) fi;
\r
696 JInitials:=proc(bset,ord)
\r
697 local pol, product;
\r
698 options remember,system;
\r
700 for pol in bset do
\r
701 product:=product*Initial(pol,ord);
\r
707 Inits:=proc(bset,ord)
\r
709 options remember,system;
\r
711 for i in bset do list:=list union Factorlist(Init(i,ord)) od;
\r
712 for i in list do if Class(i,ord)=0 then list:=list minus {i} fi od;
\r
716 #The following will be used in algebraci case ONLY!!!
\r
718 Inits1:=proc(bset,ord)
\r
720 options remember,system;
\r
722 for i in bset do if Class(Init(i,ord),ord)>1 then list:=list union Factorlist(Init(i,ord)) fi od;
\r
723 ### remove the the factors with class <2
\r
724 for i in list do if Class(i,ord) < 2 then list:=list minus {i} fi od;
\r
728 #######################################################################
\r
729 #######################################################################
\r
730 # Compute the Characteristic set with FACTORIZATION
\r
731 #######################################################################
\r
732 #######################################################################
\r
735 # INPUT: ps: a polynomial set, Suppose each pol in ps is irreducible over Q.
\r
736 # ord: indeterminate ordering. if ord:=[z,y,x] means z>y>x;
\r
737 # nzero: a polynomial set. Each pol in nzero is NOT equal to 0
\r
739 # test: a polynomial set, which is NOT equal to 0.
\r
740 # T: a symbol to decide to use which kind of ascending set
\r
741 # T: r_asc, w_asc,g_asc,q_asc=t_asc
\r
742 # OUTPUT: a list of ascending set
\r
743 #####################################################################
\r
745 Cs_a:=proc(ps,ord,nzero,test,T)
\r
746 global asc_set,INDEX,time_bs,time_rs, time_f,__testp__;
\r
747 local asc,i,j,rm,cset,test1,ps1,bset,rset, ltime_b,ltime_r,ltime_f;
\r
748 options remember,system;
\r
750 if Nums(ps,ord)>1 then RETURN({}) fi;
\r
753 if {op(ps)} intersect nzero <> {} then RETURN({}) fi;
\r
754 if POLY_MODE='Algebraic' then
\r
755 if nops(nzero) <> 0 and Emptyset(nzero,ps,ord) = 1 then print("An empty set");RETURN({}) fi;
\r
757 if __testp__= 1 and nops(test) <> 0 and TestQ(test ,ps,ord) = 1 then
\r
758 print("One factor of an initial has been found and it will be appended to the original polynomial set ");
\r
759 # print("remfac=",remfac);
\r
764 # print("ps=",ps);
\r
766 bset := Basicset(ps,ord,T);
\r
767 # print("bset=",bset);
\r
768 time_bs:=time_bs+time()-ltime_b;
\r
772 rset := Remset([op(ps)],bset,ord,T);
\r
773 # print("rset=",rset);
\r
774 time_rs:=time_rs+time()-ltime_r;
\r
777 if rset={1} then RETURN({}) fi;
\r
778 # for i in rset do if Class(i,ord)=0 then RETURN({}) fi od;
\r
781 asc_set[INDEX] := bset;
\r
782 print(`A New Component`);
\r
785 # for i in rset do
\r
786 # if (Class(i,ord) = 0) and (i <> 0) then RETURN({}) fi
\r
790 if POLY_MODE='Algebraic' and __testp__= 1 then
\r
791 test1 := test union Inits(bset,ord);
\r
799 rset := Nrs(rset,ord,nzero union test1);
\r
800 time_f:=time_f+time()-ltime_f;
\r
801 if rset = {} then RETURN({}) fi;
\r
802 cset:=map(Cs_a,map(`union`,rset,{op(bset)}),ord,nzero,test1,T);
\r
806 #######################################################################
\r
807 #######################################################################
\r
810 # INPUT: ps: a polynomial set, Suppose each pol in ps is irreducible over Q.
\r
811 # ord: indeterminate ordering. if ord:=[z,y,x] means z>y>x;
\r
812 # nzero: a polynomial set. Each pol in nzero is NOT equal to 0
\r
814 # T: a symbol to decide to use which kind of ascending set
\r
815 # T: r_asc, w_asc,g_asc,q_asc=t_asc
\r
816 # OUTPUT: a list of ascending set
\r
817 #####################################################################
\r
819 charset_a:=proc(ps,ord,nzero,T)
\r
820 global asc_set,INDEX,time_bs,time_rs, time_f;
\r
821 local asc,i,j,rm,cset,test1,ps1,bset,rset, ltime_b,ltime_r,ltime_f;
\r
822 options remember,system;
\r
823 # if Nums(ps,ord)>1 then RETURN({}) fi;
\r
826 if {op(ps)} intersect nzero <> {} then RETURN({}) fi;
\r
828 if nops(nzero) <> 0 and Emptyset(nzero,ps,ord) = 1 then print("An empty set");RETURN({}) fi;
\r
831 # print("ps=",ps);
\r
833 bset := Basicset(ps,ord,T);
\r
834 # print("bset=",bset);
\r
835 time_bs:=time_bs+time()-ltime_b;
\r
837 rset := Remset([op(ps)],bset,ord,T);
\r
838 rset := map(primpart,rset,ord);
\r
839 # print("rset=",rset);
\r
840 time_rs:=time_rs+time()-ltime_r;
\r
843 if rset={1} or Non0Constp(rset,ord)=1 then RETURN([]) fi;
\r
844 # for i in rset do if Class(i,ord)=0 then RETURN({}) fi od;
\r
847 asc_set[INDEX] := bset;
\r
848 print(`A New Component`);
\r
851 # for i in rset do
\r
852 # if (Class(i,ord) = 0) and (i <> 0) then RETURN({}) fi
\r
854 # test1 := test union Inits(bset,ord);
\r
856 # rset := Nrs(rset,ord,nzero union test1);
\r
857 time_f:=time_f+time()-ltime_f;
\r
858 # if rset = {} then RETURN({}) fi;
\r
860 cset:=charset_a({op(bset)} union rset,ord,nzero,T);
\r
864 charset_b:=proc(ps,ord,nzero,T)
\r
866 options remember,system;
\r
868 cset := charset_a(ps,ord,nzero,T);
\r
869 rs:=Remset([op(ps)],cset,ord,T);
\r
870 # rs:=map(primpart,rs,ord);
\r
872 if rs={} then RETURN(cset) fi;
\r
873 if rs={1} then RETURN([]) fi;
\r
874 if cset=[] then RETURN([]) fi;
\r
875 # #lprint("kkkkkkkkkkkkk");
\r
876 # cset:=charset_b({op(ps)} union {op(cset)} union rs,ord,nzero,T);
\r
878 cset:=charset_a({op(cset)} union rs, ord,nzero,T);
\r
879 #####we should consider the the following special case which cset=[]
\r
880 if nops(cset)=0 then RETURN(cset) fi;
\r
881 rs:=Remset(ps,cset,ord,T);
\r
886 CS_a:=proc(ps,ord,nzero,T)
\r
887 local pset,cset,order,nonzero,asc;
\r
888 options remember, system;
\r
889 if nargs < 1 then ERROR(`too few arguments`)
\r
890 elif nargs>4 then ERROR(`too many arguments`)
\r
892 if nargs<2 then order:=[op(indets(ps))] else order:=[op(ord)] fi;
\r
893 if nargs<3 then nonzero:={} else nonzero:=nzero fi;
\r
894 if nargs<4 then asc:=`` else asc:=T fi;
\r
896 pset:=Nrs(ps,order,nonzero);
\r
897 cset:=map(Cs_a,pset,order,nonzero,{},asc);
\r
898 [op(map(op,cset))];
\r
901 #######################################################################
\r
904 # INPUT: ps: a polynomial set, Suppose each pol in ps is irreducible over Q.
\r
905 # ord: indeterminate ordering. if ord:=[z,y,x] means z>y>x;
\r
906 # nzero: a polynomial set. Each pol in nzero is NOT equal to 0
\r
908 # test: a polynomial set, which is NOT equal to 0.
\r
909 # T: a symbol to decide to use which kind of ascending set
\r
910 # T: r_asc, w_asc,g_asc,q_asc=t_asc
\r
911 # OUTPUT: a list of ascending set
\r
912 #####################################################################
\r
914 Cs_b:=proc(ps,ord,nzero,test,T)
\r
915 local cset,cset1,i,j,rs,rs1;
\r
916 options remember,system;
\r
917 if Nums(ps,ord)>1 then RETURN({}) fi;
\r
919 cset := Cs_a(ps,ord,nzero,test,T);
\r
921 for i in cset1 do rs:=Remset([op(ps)],i,ord,'std_asc');
\r
923 # for i in cset1 do rs:=Remset([op(ps)],i,ord,T);
\r
924 # if rs<>{} then if rs <> {1} then rs1:=rs1 union {rs union {op(i)} } fi;
\r
925 if rs<>{} then if rs <> {1} then rs:=Nrs(rs,ord,nzero union test); rs1:=rs1 union map(`union`,rs , {op(i)} ) fi;
\r
926 cset:=cset minus {i} fi
\r
928 if rs1={} then RETURN(cset) fi;
\r
929 for j in rs1 do cset:=cset union Cs_b(ps union j,ord,nzero,test,T) od;
\r
933 #######################################################################
\r
936 # INPUT: ps: a polynomial set, Suppose each pol in ps is irreducible over Q.
\r
937 # ord: indeterminate ordering. if ord:=[z,y,x] means z>y>x;
\r
938 # nzero: a polynomial set. Each pol in nzero is NOT equal to 0
\r
940 # test: a polynomial set, which is NOT equal to 0.
\r
941 # T: a symbol to decide to use which kind of ascending set
\r
942 # T: r_asc, w_asc,g_asc,q_asc=t_asc
\r
943 # OUTPUT: a list of ascending set
\r
944 #####################################################################
\r
945 Cs_c:=proc(ps,ord,nzero,T)
\r
946 local cset,remf,ps1,i,nzeros;
\r
948 options remember,system;
\r
950 if Nums(ps,ord)>1 then RETURN({}) fi;
\r
952 cset:=Cs_b({op(ps)},ord,{op(nzero)},{},T);
\r
953 remf:=remfac minus {op(nzero)};
\r
956 for i to nops(remf) do
\r
959 ps1 := {op(ps)} union {remf[i]};
\r
960 if i = 1 then nzeros := {op(nzero)} else nzeros := nzeros union {remf[i-1]} fi;
\r
961 cset := cset union Cs_c(ps1,ord,nzeros,T)
\r
966 CS:=proc(ps,ord,nzero,T)
\r
967 local i,pset,cset,order,nonzero,asc;
\r
968 options remember, system;
\r
969 if nargs < 1 then ERROR(`too few arguments`)
\r
970 elif nargs > 4 then ERROR(`too many arguments`)
\r
972 if nargs < 2 then order:=[op(indets(ps))] else order:=[op(ord)] fi;
\r
973 if nargs < 3 then nonzero:={} else nonzero:=realfac({op(nzero)},ord) fi;
\r
974 if nargs < 4 then asc:='std_asc' else asc:=T fi;
\r
976 pset:=Nrs(ps,order,nonzero);
\r
977 for i to nops(pset) do cset:=cset union Cs_c(pset[i],order,nonzero,asc) od;
\r
982 Css:=proc(ps,ord,nzero,T)
\r
983 global remfac,checknum;
\r
984 local cset1,cset,i,j,nzero1, ps1,ps2,Is,Ninits;
\r
985 options remember,system;
\r
986 checknum:=checknum+1;
\r
988 cset1 := Cs_c(ps,ord,nzero,T);
\r
992 # print(nops(cset1));
\r
995 if Class(i[nops(i)],ord)=1 and POLY_MODE='Algebraic' then Is:=Inits1(i,ord) else Is := Inits(i,ord) fi;
\r
996 if POLY_MODE='Partial_Differential' or POLY_MODE='Ordinary_Differential' then Is := Is union Septs(i,ord) fi;
\r
997 Ninits := Is minus {op(nzero)};
\r
998 # print("checknum=",checknum, "Ninits=",Ninits);
\r
999 for j to nops(Ninits) do
\r
1000 ps1 := ({op(ps)} union {op(i)}) union {Ninits[j]};
\r
1001 if j = 1 then nzero1 := {op(nzero)}
\r
1002 else nzero1 := nzero1 union {Ninits[j-1]}
\r
1004 cset := cset union Css(ps1,ord,nzero1,T)
\r
1010 realfac:=proc(ps,ord)
\r
1012 options remember,system;
\r
1013 s:=Produce(ps,ord,{});
\r
1016 res:=res union i;
\r
1021 Degenerate:=proc(ds,as,ord)
\r
1023 options remember,system;
\r
1025 r:=Premas(i,as,ord,'std_asc');
\r
1026 if r =0 then return 1 fi;
\r
1031 ### POLY_MODE:= one of ['Algebraic','Ordinary_Differential','Partial_Differential']
\r
1032 ### depend_relation is like : [[x,y],[t]];
\r
1033 #### T:= one of ['std_asc','norm_asc','wu_asc','gao_asc','tri_asc']
\r
1034 CSS:=proc(ps,ord,nzero,T)
\r
1035 global factor_time,prem_time, t_time,time_bs,time_rs,time_f;
\r
1036 local asc,i,pset,cset,nonzero,order,result,wm;
\r
1037 options remember,system;
\r
1038 if nargs < 2 then order:=[op(indets(ps))] else order:=[op(ord)] fi;
\r
1039 if nargs < 3 then nonzero:={} else nonzero:=realfac({op(nzero)},ord) fi;
\r
1040 if nargs < 4 then asc:='std_asc' else asc:=T fi;
\r
1041 if asc='norm_asc' then return Dec({op(ps)},order,nonzero,'std_asc');fi;
\r
1050 pset:=Nrs(ps,order,nonzero);
\r
1053 if asc='norm_asc' then
\r
1054 for i to nops(pset) do cset:=cset union Dec(pset[i],order,nonzero,'std_asc') od;
\r
1056 for i to nops(pset) do cset:=cset union Css(pset[i],order,nonzero,asc) od;
\r
1059 for i in cset do if Degenerate(nonzero,i,order)<>1 then result:=[op(result),i]; fi od;
\r
1060 #lprint("Timing","Total", time()-t_time, "Factoring", factor_time,"Prem",prem_time);
\r
1061 #lprint("BasicSet",time_bs,"RS",time_rs,"factor",time_f);
\r
1066 charset:=proc(ps,ord,nzero,T)
\r
1067 global factor_time,prem_time, t_time,time_bs,time_rs,time_f;
\r
1068 local asc,nonzero,order,result,cm;
\r
1069 options remember,system;
\r
1070 if nargs < 2 then order:=[op(indets(ps))] else order:=[op(ord)] fi;
\r
1071 if nargs < 3 then nonzero:={} else nonzero:=realfac({op(nzero)},ord) fi;
\r
1072 if nargs < 4 then asc:='std_asc' else asc:=T fi;
\r
1081 result:=charset_b({op(ps)}, order,nonzero,asc);
\r
1082 # result:=charset_b(map(primpart,{op(ps)},order),order,nonzero,asc);
\r
1084 #lprint("Timing","Total", time()-t_time, "BasicSet",time_bs,"Prem",prem_time);
\r
1090 Css1:=proc(ps,ord,test,type)
\r
1091 local cset,i,j,septs,cset1,nonzero,vv;
\r
1092 options remember,system;
\r
1093 cset:=CSS(ps,ord,test,type);
\r
1096 nonzero:={op(test)};
\r
1097 for i in cset1 do
\r
1098 septs:=Septs(i,ord) minus Inits(i,ord);
\r
1101 for j in septs do
\r
1102 vv:= {op(Css1(ps union {op(i)} union {j},ord,nonzero,type))};
\r
1103 nonzero:={op(nonzero),j};
\r
1104 cset:={op(cset)} union vv ;
\r
1111 Gsolve:=proc(ps,ord,test)
\r
1112 gsolve(ps,ord,test)
\r
1115 e_val:=proc(ps,ord,test,T)
\r
1116 global factor_time,prem_time, t_time,time_bs,time_rs,time_f;
\r
1117 local asc,nonzero,order,result,cm;
\r
1118 options remember,system;
\r
1119 if nargs < 2 then error("The input should have at least 2 parameters") fi;
\r
1120 if nargs < 3 then nonzero:={} else nonzero:=realfac({op(nzero)},ord) fi;
\r
1121 if nargs < 4 then asc:='std_asc' else asc:=T fi;
\r
1127 result:=Css1({op(ps)}, ord,nonzero,asc);
\r
1128 #lprint("Timing","Total", time()-t_time, "BasicSet",time_bs,"Prem",prem_time);
\r
1137 global POLY_MODE;
\r
1138 POLY_MODE:='Algebraic';
\r
1143 od_wsolve:=proc()
\r
1145 global POLY_MODE,depend_relation;
\r
1146 POLY_MODE:='Ordinary_Differential';
\r
1147 if type(depend_relation,'list') and nops(depend_relation) >1 and
\r
1148 type(depend_relation[2],'list') and nops(depend_relation[2])=1 then
\r
1151 #lprint("Please set depend_relation:=[[x,y,...],[t]] first, if x,y,... depend on t");
\r
1157 pd_wsolve:=proc()
\r
1159 global POLY_MODE,depend_relation;
\r
1160 POLY_MODE:='Partial_Differential';
\r
1161 if type(depend_relation,'list') and nops(depend_relation) >1 and
\r
1162 type(depend_relation[2],'list') and nops(depend_relation[2])>1 then
\r
1165 #lprint("Please set depend_relation:=[[x1,x2,...],[t1,t2,...]] first, if x1,x2,... depend on t1,t2,...");
\r
1179 POLY_MODE:=Algebraic:
\r
1180 RANKING_MODE:='cls_ord_var':
\r
1182 # Test Program for Differentiation
\r
1185 #----------------------------------------
\r
1186 # Global dependence
\r
1187 #----------------------------------------
\r
1189 #########################################################
\r
1190 #11111111111111111111111111111111111111111111111111111111
\r
1192 #Part IV: The basic functions for differential poly
\r
1194 #########################################################
\r
1196 #Diff_Var:=[u,v,w]; # Declare variables;
\r
1198 #Diff_Indets:=[X1,X2,X3]; # Declare Diff ndeterminates;
\r
1200 #Lvar:=nops(Diff_Var);
\r
1202 #----------------------------------------------------------
\r
1204 #----------------------------------------------------------
\r
1206 dDiff:=proc(dp,var,n)
\r
1208 options remember,system;
\r
1210 if nargs=2 then RETURN (DF(dp,var)) fi;
\r
1217 #==========================================================
\r
1219 # dq <- DF(dp, var)
\r
1221 # (differetiating a diff polynomial)
\r
1224 # Input: dp, a diff polynomial;
\r
1225 # var, the variable w.r.t which to be differentiate
\r
1227 # Output: dq, the result after differentiating dp w.r.t var;
\r
1229 #===========================================================
\r
1231 DF:=proc(dp, var)
\r
1232 local dq, dp1, dp2;
\r
1233 options remember,system;
\r
1235 #Step1 [Recursive base]
\r
1237 if op(0,dp) <> `+` then
\r
1238 dq:=DF_prod(dp,var);
\r
1242 #Step2 [Recursion]
\r
1245 dp2:=normal(dp-dp1);
\r
1246 dq:=normal(DF_prod(dp1,var)+DF(dp2,var));
\r
1248 #Step3 [Prepare for return]
\r
1254 #------------------------------------------
\r
1256 #------------------------------------------
\r
1258 #=========================================================
\r
1261 # der <- DF_indet(indet, var)
\r
1263 # (differentiate a differential indeterminante)
\r
1265 # Input: indet, a differential indeterminate which is a
\r
1266 # derivative of symobls in Diff_Indets w.r.t
\r
1267 # some variables in Diff_Var;
\r
1269 # var, the variable w.r.t which to be differeniated
\r
1271 # Output: der, the derivative of indet w.r.t var
\r
1273 #===========================================================
\r
1275 DF_indet:=proc(indet, var)
\r
1276 local der, p, i, index, j,Diff_Var,Diff_Indets,Lvar;
\r
1277 global depend_relation;
\r
1278 options remember,system;
\r
1280 #STEP0 [Initiation diffs];
\r
1282 Diff_Var:=depend_relation[2];
\r
1283 Diff_Indets:=depend_relation[1];
\r
1284 Lvar:=nops(Diff_Var);
\r
1286 #STEP1 [Special cases]
\r
1288 if not member(var, Diff_Var, 'p') then
\r
1289 der := diff(indet, var);
\r
1293 if not member(indet, Diff_Indets) and
\r
1294 not member(op(0,indet), Diff_Indets) then
\r
1295 der := diff(indet, var);
\r
1301 index:=NULL; #Initialization
\r
1303 if member(indet, Diff_Indets) then
\r
1305 # build a derivative from a diff indet
\r
1307 for i from 1 to Lvar do
\r
1314 der:=indet[index];
\r
1317 # modify a derivative from a given one
\r
1319 for i from 1 to Lvar do
\r
1322 index:=index,(j+1);
\r
1327 der:=op(0,indet)[index]
\r
1330 #STEP3 [Prepare for return]
\r
1336 #========================================================
\r
1338 # dq <- DF_power(dp, var)
\r
1340 # (differentiating a power of a drivative of a diff indet)
\r
1342 # input: dp, a power of a diff indet
\r
1343 # var, the variable w.r.t which to be differentiated
\r
1345 # output: dq, the result after differentiating dp w.r.t var
\r
1347 #=========================================================
\r
1349 DF_power:=proc(dp, var)
\r
1350 local dq, indet, expon;
\r
1351 options remember,system;
\r
1353 #Step1 [Special cases]
\r
1362 # indeterminate case
\r
1364 if op(0,dp) <> `^` then
\r
1365 dq := DF_indet(dp, var);
\r
1373 dq:=expon*indet^(expon-1)*DF_indet(indet,var);
\r
1375 #Step3 [Prepare for return]
\r
1381 #=========================================================
\r
1383 # dq <- DF_prod(dp, var)
\r
1385 # (differentiating a product of derivatives of some diff indets)
\r
1387 # input: dp, a product of derivatives of some diff indets
\r
1388 # var, the variable w.r.t which to be differentiated
\r
1390 # output: dq, the result after differentiating dp w.r.t var;
\r
1392 #==========================================================
\r
1394 DF_prod:=proc(dp, var)
\r
1395 local dq, dp1, dp2;
\r
1396 options remember,system;
\r
1398 #Step1 [Recursive base]
\r
1400 if op(0,dp) <> `*` then
\r
1401 dq := DF_power(dp, var);
\r
1405 #Step2 [Recursion]
\r
1408 dp2:=normal(dp/dp1);
\r
1410 dq:=normal(DF_power(dp1,var)*dp2+dp1*DF_prod(dp2,var));
\r
1412 #Step3 [Prepare for return]
\r
1418 #===============================================================
\r
1420 # ord <- torder(der)
\r
1422 # computing the order of a derivative of a diff indet
\r
1424 # input: der, a derivative of a diff indet
\r
1426 # output: ord, ord is the order of der.
\r
1428 #=================================================================
\r
1430 torder:=proc(der)
\r
1431 local ord,i,Diff_Var,Lvar;
\r
1432 global depend_relation;
\r
1433 options remember,system;
\r
1435 #STEP1 [Initialize]
\r
1437 if type(der,symbol) then RETURN(0) fi;
\r
1444 for i from 1 to nops(der) do
\r
1445 ord := ord + op(i, der);
\r
1451 #==================================================================
\r
1453 # lead <- Leader(dp, ranking,ord, _cls, _ord)
\r
1455 # Input: dp, a nonzero diff poly;
\r
1456 # ranking, a specified ranking;
\r
1458 # Output: the Leader w.r.t. ranking;
\r
1460 # Option: _cls, the class of the lead;
\r
1461 # _ord,, the order of the lead;
\r
1463 #===================================================================
\r
1464 Mainvar:=proc(p,ord)
\r
1465 options remember,system;
\r
1469 Leader := proc(dp, ord, _cls, _ord)
\r
1470 local lead, cls, order, L, l, der, clsord, i, j, cls1, ord1,Diff_Var,Lvar;
\r
1471 global depend_relation;
\r
1472 options remember,system;
\r
1474 #Step1 [Initialize]
\r
1476 Diff_Var:=depend_relation[2];
\r
1477 Lvar:=nops(Diff_Var);
\r
1478 L:=indets(dp); l:=nops(L);
\r
1483 #Step 2 [Algebraic mode]
\r
1485 if POLY_MODE='Algebraic' then
\r
1486 for i to nops(ord) do
\r
1487 if member(ord[i],L) then RETURN(ord[i]) fi
\r
1491 #Step2 [cls_ord_var case]
\r
1493 if RANKING_MODE = cls_ord_var then
\r
1494 for i from 1 to l do
\r
1497 cls1:=Class(der,ord);
\r
1498 ord1:=torder(der);
\r
1500 if cls1 > cls or (cls1 = cls and ord1 > order) then
\r
1505 if cls1 = cls and ord1 = order and ord1 > 0 then
\r
1506 for j from 1 to Lvar do
\r
1507 if op(j, lead) < op(j, der) then
\r
1513 if op(j, lead) > op(j, der) then;
\r
1523 #Step3 [ord_cls_var case]
\r
1525 if RANKING_MODE = ord_cls_var then
\r
1526 for i from 1 to l do
\r
1528 cls1:=Class(der,ord);
\r
1529 ord1:=torder(der);
\r
1530 if ord1 > order or (ord1 = order and cls1 > cls) then
\r
1534 elif ord1 = order and cls1 = cls and ord1 > 0 then
\r
1535 for j from 1 to Lvar do
\r
1536 if op(j, lead) < op(j, der) then
\r
1541 elif op(j, lead) > op(j, der) then;
\r
1550 #STEP3 [Prepare for return]
\r
1553 if nargs > 2 then
\r
1556 if nargs > 3 then
\r
1570 depend:=proc(l1,l2)
\r
1571 global depend_relation;
\r
1572 depend_relation:=[l1,l2];
\r
1575 #============================================================
\r
1577 # {1,-1,0} <- dercmp(der1, der2)
\r
1579 # input: der1, der2, two derivatives;
\r
1582 # output: 0 if der1 = der2
\r
1583 # 1 if der1 < der2
\r
1584 # -1 if der1 > der2
\r
1586 #============================================================
\r
1587 dercmp:=proc(der1, der2,ord)
\r
1589 options remember,system;
\r
1591 if der1=der2 then RETURN(0) fi;
\r
1593 dp := der1 + der2;
\r
1594 lead:=Leader(dp,ord);
\r
1595 if lead = der1 then
\r
1603 #if der1 is a derivative of der2 then return true else false
\r
1604 Is_derivative:=proc(der1, der2)
\r
1605 local dt1,dt2,i, l1,l2;
\r
1606 options remember,system;
\r
1609 if type(der1,symbol) then dt1:=der1 else dt1:=op(0,der1) fi;
\r
1610 if type(der2,symbol) then dt2:=der2 else dt2:=op(0,der2) fi;
\r
1611 if dt1<>dt2 then RETURN(false) fi;
\r
1612 if der1=der2 then RETURN(true) fi;
\r
1614 if torder(der2)=0 then
\r
1616 elif torder(der1)=0 then
\r
1619 l1:=dOrder(der1,dt1);
\r
1620 l2:=dOrder(der2,dt1);
\r
1621 for i to nops(l1) do
\r
1622 if op(i,l1) < op(i,l2) then RETURN(false) fi;
\r
1629 #if der1 is a proper derivative of der2 then return true else false
\r
1630 Is_proper_derivative:=proc(der1, der2)
\r
1631 local dt1,dt2,i, l1,l2;
\r
1632 options remember,system;
\r
1635 if type(der1,symbol) then dt1:=der1 else dt1:=op(0,der1) fi;
\r
1636 if type(der2,symbol) then dt2:=der2 else dt2:=op(0,der2) fi;
\r
1637 if dt1<>dt2 then RETURN(false) fi;
\r
1638 if der1=der2 then RETURN(false) fi;
\r
1640 if torder(der2)=0 then
\r
1642 elif torder(der1)=0 then
\r
1645 l1:=dOrder(der1,dt1);
\r
1646 l2:=dOrder(der2,dt1);
\r
1647 for i to nops(l1) do
\r
1648 if op(i,l1) < op(i,l2) then RETURN(false) fi;
\r
1655 #return all the derivatives in dp of der
\r
1656 proper_derivatives:=proc(dp,der)
\r
1657 local i,idt,dets;
\r
1658 options remember,system;
\r
1663 if Is_proper_derivative(i,der) then
\r
1664 dets:={i,op(dets)};
\r
1675 #sometimes, Maple's GCD is NOT valid for parameters which has indexes such a[1],a[2];
\r
1680 local r,v,dr,dv,lcv,rtv,g,lu,lv;
\r
1681 options remember,system;
\r
1682 if degree(vv,xx)=0 then RETURN(0) fi;
\r
1683 if type(vv/xx,integer) then coeff(uu,xx,0)
\r
1686 dr := degree(r,xx);
\r
1688 dv := degree(v,xx);
\r
1690 lcv:=lcoeff(v,xx);
\r
1691 # rtv:=sterm(v,xx);
\r
1692 rtv:=v-expand(lcoeff(v,xx)*xx^degree(v,xx));
\r
1694 while dv <= dr and r <> 0 do
\r
1696 # g:=gcd(lcv,coeff(r,xx,dr));
\r
1700 lv:=coeff(r,xx,dr);
\r
1702 r:=expand(lu*(r-expand(lcoeff(r,xx)*xx^degree(r,xx)))-lv*rtv*xx^(dr-dv));
\r
1703 dr := degree(r,xx)
\r
1710 #######±äÁ¿yÓÐÁ½ÖÖÇéÐÎ.y and y[1]ËùÒÔҪСÐÄ.
\r
1716 local u,x,dv,du,d,t,var;
\r
1717 global depend_relation;
\r
1718 options remember,system;
\r
1720 t:=depend_relation[2][1];
\r
1721 var:=depend_relation[1];
\r
1723 # if dClass(uu,var)=0 then RETURN(uu) fi;
\r
1726 if type(y,symbol) then x:=y else x:=op(0,y) fi;
\r
1727 dv:=dOrder(vv,x);
\r
1730 if d<0 then RETURN(uu) fi;
\r
1731 #the following program is for ordinary differential case
\r
1734 u:=NPremO(u,dDiff(vv,t,d), x[du]);
\r
1739 if dv =0 then NPremO(u,vv,x) else NPremO(u,vv,x[dv]) fi;
\r
1748 local u,x,dv,du,d,t,var;
\r
1749 global depend_relation;
\r
1750 options remember,system;
\r
1752 if POLY_MODE='Algebraic' then
\r
1756 elif POLY_MODE='Ordinary_Differential' then
\r
1760 elif POLY_MODE='Partial_Differential' then
\r
1770 Headder:=proc(idts)
\r
1772 options remember,system;
\r
1773 hder:=op(1,idts);
\r
1775 # if type(hder,symbol) then var:=hder else var:=op(0,hder) fi;
\r
1779 if torder(i) > torder(hder) then
\r
1781 elif torder(i)=torder(her) then
\r
1782 for j to nops(hder) do
\r
1783 if op(j,i) > op(j,hder) then hder:=i;break;
\r
1784 elif op(j,i) < op(j,hder) then break;
\r
1796 PDPrem:=proc(dp, dq, y)
\r
1797 local Diff_Indets,Diff_Var, var,dr, idt,l2,lder,da,l1,i,s;
\r
1798 options remember,system;
\r
1800 #Step1 [Special case]
\r
1803 Diff_Indets:=depend_relation[1];
\r
1804 Diff_Var:=depend_relation[2];
\r
1806 if y=1 then RETURN(0) fi;
\r
1808 if type(y,symbol) then var:=y else var:=op(0,y) fi;
\r
1812 idt:=proper_derivatives(dr,y);
\r
1813 l2:=dOrder(y,var);
\r
1815 #Step2 [Recursive base]
\r
1817 while nops(idt)<>0 do
\r
1820 lder:=Headder(idt);
\r
1826 l1:=dOrder(lder,var);
\r
1830 for i to nops(l1) do
\r
1832 if l2=0 then s:=op(i,l1) else s:=op(i,l1) -op(i,l2) fi;
\r
1834 da := dDiff(da, Diff_Var[i],s);
\r
1838 dr := NPremO(dr, da, lder);
\r
1840 idt:=proper_derivatives(dr,y);
\r
1844 dr:=NPremO(dr,dq,y) ;
\r
1846 #Step4 [Prepare for return]
\r
1859 local p,q, ls,set1;
\r
1860 options remember,system;
\r
1866 set1:=set1 minus {p};
\r
1868 ls:={op(ls),[p,q]}
\r
1875 ######## modified Nov.6 ########
\r
1878 spolyset:=proc(as,ord)
\r
1879 local res,bs,l,p,cls,i,poly;
\r
1880 options remember,system;
\r
1885 if l <= 1 then RETURN(res) fi;
\r
1888 cls:=Class(Leader(p,ord),ord);
\r
1889 bs:=bs minus {p};
\r
1891 while nops(bs) <>0 do
\r
1893 if Class(Leader(i,ord),ord) = cls then poly:=PD_spoly(i,p,ord); res:=res union {poly} fi;
\r
1898 cls:=Class(Leader(p,ord),ord);
\r
1899 bs:=bs minus {p};
\r
1912 PD_spoly:=proc(p,q,ord)
\r
1913 local leadp,leadq,var,l1,l2,ml,dp,dq,i,Diff_Var;
\r
1914 global depend_relation;
\r
1915 options remember,system;
\r
1916 leadp:=Leader(p,ord);
\r
1917 leadq:=Leader(q,ord);
\r
1919 var:=op(0,leadp);
\r
1920 Diff_Var:=depend_relation[2];
\r
1922 l1:=dOrder(leadp,var);
\r
1923 l2:=dOrder(leadq,var);
\r
1925 ml:=maxlist(l1,l2);
\r
1930 for i to nops(ml) do
\r
1931 dp:=dDiff(dp,Diff_Var[i],ml[i]-l1[i]);
\r
1932 dq:=dDiff(dq,Diff_Var[i],ml[i]-l2[i]);
\r
1935 ######Ö±¾õ¾õµÃ¿ÉÒÔÖ±½ÓÓÃPDPrem(dp,q,Leader(q,ord)) ¸üºÃ¡£¶øÕâÀïÓõÄÊDZê×¼µÄ·½·¨¡£
\r
1936 NPremO(dp,dq, Leader(dq,ord));
\r
1941 maxlist:=proc(l1,l2)
\r
1943 options remember,system;
\r
1945 for i to nops(l1) do
\r
1946 list:=[op(list), max(l1[i],l2[i])];
\r
1951 #torder Is_deriv Reducedp Leader Head Leader PDE map Num spoly NewPrem
\r
1953 # the class of poly f wrt variable ordering ord
\r
1954 MainVariables := proc(ps,ord)
\r
1956 options remember,system;
\r
1959 set:=set union {Leader(i,ord)};
\r
1964 PNormalp:=proc(p,as,ord)
\r
1965 local i,idts,mvs,initp;
\r
1966 options remember,system;
\r
1967 initp:=Initial(p,ord);
\r
1968 idts:=indets(initp);
\r
1969 if idts={} then RETURN(true) fi;
\r
1970 mvs:=MainVariables(as,ord);
\r
1972 if member(i,mvs) then RETURN(false) fi;
\r
1977 ASNormalp:=proc(ps,ord)
\r
1979 options remember,system;
\r
1981 if l=1 then RETURN(true) fi;
\r
1983 for i from l-1 to 1 by -1 do
\r
1985 if not PNormalp(p,as,ord) then RETURN(false) fi;
\r
1991 Dec:=proc(ps,ord,nzero,T)
\r
1992 global remfac,checknum;
\r
1993 local i,cset1,cset;
\r
1994 options remember,system;
\r
1996 cset1:=Cs_c(ps,ord,nzero,T);
\r
1998 for i in cset1 do
\r
1999 if ASNormalp(i,ord) then
\r
2000 cset:=cset union NormDec1(ps,i,ord,nzero,T);
\r
2002 cset:=cset union NormDec2(ps,i,ord,nzero,T);
\r
2008 NormDec1:=proc(ps,as,ord,nzero,T)
\r
2009 local cset,j,nzero1, ps1,ps2,Is,Ninits;
\r
2010 options remember,system;
\r
2013 if Class(as[nops(as)],ord)=1 then Is:=Inits1(as,ord) else Is := Inits(as,ord) fi;
\r
2014 Ninits := Is minus {op(nzero)};
\r
2016 for j to nops(Ninits) do
\r
2017 ps1 := ({op(ps)} union {op(as)}) union {Ninits[j]};
\r
2018 if j = 1 then nzero1 := {op(nzero)}
\r
2019 else nzero1 := nzero1 union {Ninits[j-1]}
\r
2021 cset := cset union Dec(ps1,ord,nzero1,T)
\r
2026 NormDec2:=proc(ps,as,ord,nzero,T)
\r
2027 local cset,i,j,l,regas,p,initp,lp,pol,r1,r2,Is,Ninits,l2,ps1,nzero1,mvar,vars,mv,d,f,g;
\r
2028 options remember,system;
\r
2034 for i from 2 to l do
\r
2036 mvar:=Leader(p,ord);
\r
2037 d:=degree(p,mvar);
\r
2038 if PNormalp(p,regas,ord) then
\r
2039 regas:= [p,op(regas)]
\r
2041 initp:=Initial(p,ord);
\r
2042 vars:=indets(initp);
\r
2047 mv:=Leader(pol,ord);
\r
2048 if member(mv,vars) then
\r
2049 # ×¢ÒâResultantº¯Êý
\r
2051 r1:=NResultantE(initp,pol, Leader(pol,ord),'f','g');
\r
2052 r2:=Premas(r1,regas,ord,'std_asc');
\r
2055 if Class(as[nops(regas)],ord)=1 then Is:=Inits1(regas,ord) else Is := Inits(regas,ord) fi;
\r
2056 Ninits := Is minus {op(nzero)};
\r
2058 l2:=nops(Ninits);
\r
2059 nzero1:={op(nzero)};
\r
2062 ps1 := ({op(ps)} union {op(as)}) union {Ninits[j]};
\r
2064 nzero1 := nzero1 union {Ninits[j-1]}
\r
2066 cset := cset union Dec(ps1,ord,nzero1,T)
\r
2068 print("kkkkkkkkkk");
\r
2069 if l2 <> 0 then nzero1:=nzero1 union {Ninits[l2]} fi;
\r
2071 # print("cset=",cset);
\r
2072 # print("ps=",ps);
\r
2073 # print("as=", as);
\r
2074 # print("regas=",regas);
\r
2076 cset:=cset union Dec(ps union {op(as)} union {op(regas)} union {f},ord,nzero1,T) union Dec(ps union {op(as)} union {op(regas)} union {initp},ord,nzero1,T);
\r
2081 p:=expand(f*p+g*pol*mvar^d);
\r
2082 p:=Premas(p,regas,ord,'std_asc');
\r
2083 initp:=Initial(p,ord);
\r
2084 vars:=indets(initp);
\r
2089 regas:=[p,op(regas)]
\r
2092 cset:=NormDec1(ps,regas,ord,nzero,T);
\r
2097 #Èç¹ûÊ×ÏîϵÊý±ä³É0£¬¶øÓàʽ²»ÊÇ0ÔòÖÃdegenerateΪ1·ñÔòΪ0¡£
\r
2100 proc(uu,vv,x,ord,degenerate)
\r
2101 local r,init,lead,lmono,red,init_r,s,t;
\r
2102 options remember,system;
\r
2104 if uu=0 then RETURN(0) fi;
\r
2106 if Class(uu,ord) = Class(vv,ord) then
\r
2107 r:= NPrem(uu,vv,x);
\r
2108 elif Class(uu,ord) > Class(vv,ord) then
\r
2109 init:=Initial(uu,ord);
\r
2110 if degree(init,x) >0 and Reducedp(init, vv,ord,'std_asc') = 0 then
\r
2111 lead:=Leader(uu,ord);
\r
2112 # collect(uu,lead);
\r
2113 lmono:=lead^degree(uu,lead);
\r
2114 red:=expand(uu-init*lmono);
\r
2115 init_r:=NPremE(init,vv,x,'s','t');
\r
2116 r:=expand(init_r*lmono+s*red);
\r
2117 if init_r=0 and r <>0 then degenerate:=1 fi;
\r
2118 # collect(r,lead);
\r
2126 proc(uu,vv,x,s1,t1)
\r
2127 local r,v,dr,dv,l,t,lu,lv,s0,t0;
\r
2128 options remember,system;
\r
2133 dr := degree(r,x);
\r
2135 dv := degree(v,x);
\r
2136 if dv <= dr then l := coeff(v,x,dv); v := expand(v-l*x^dv)
\r
2139 while dv <= dr and r <> 0 do
\r
2140 gcd(l,coeff(r,x,dr),'lu','lv');
\r
2142 t0:=lu*t0+lv*x^(dr-dv);
\r
2143 t := expand(x^(dr-dv)*v*lv);
\r
2144 if dr = 0 then r := 0 else r := subs(x^dr = 0,r) fi;
\r
2145 r := expand(lu*r)-t;
\r
2146 dr := degree(r,x)
\r
2153 #This function is for ascending set normalization.
\r
2154 #in fact, it is not a resultant for 2 pols with indeterminate x.
\r
2155 #for two polys uu,vv with indeterminate x
\r
2156 #it has the property m*uu+n*vv=r with degree(r,x)=0;
\r
2159 proc(uu,vv,x,m,n)
\r
2160 local r,s,t,r0,s0,t0,r1,s1,t1,tmpr,tmps,tmpt;
\r
2161 options remember,system;
\r
2168 if degree(r0,x)=0 then m:=1;n:=0;RETURN(r0) fi;
\r
2169 if degree(r1,x)=0 then m:=0;n:=1;RETURN(r1) fi;
\r
2171 while degree(r1,x) >= 1 do
\r
2172 r:=NPremE(r0,r1,x,'s','t');
\r
2191 ##############################################################################
\r
2192 # Name: SylvesterResultant
\r
2193 # Calling sequence: SylvesterResultant(f, g, x, u, v)
\r
2194 # Input: f, g two polynomials in x with positive degrees
\r
2196 # Output: the Sylvester resultant of f and g with respect to x
\r
2197 # Optional: u, v, such that
\r
2198 # u*f+v*g = resultant
\r
2199 ###############################################################################
\r
2201 #SylvesterResultant := proc(f, g, x, u, v)
\r
2202 NResultantE := proc(f, g, x, u, v)
\r
2203 local df, dg, deg, A, a, b, U, V, i, m, Q, l, e, s, us, vs;
\r
2205 #-------------------------------------------
\r
2207 #-------------------------------------------
\r
2209 (df, dg) := degree(f, x), degree(g, x);
\r
2210 if df = 0 or dg = 0 then
\r
2211 error "input polynomials should be of positive degrees";
\r
2214 #---------------------------------------------
\r
2216 #---------------------------------------------
\r
2219 (A[1], A[2]) := f, g;
\r
2220 (deg[1], deg[2]) := df, dg;
\r
2222 (A[1], A[2]) := g, f;
\r
2223 (deg[1], deg[2]) := dg, df;
\r
2227 (U[1], U[2]) := 1, 0;
\r
2229 (V[1], V[2]) := 0, 1;
\r
2233 (a[1], b[1], a[2], b[2]) := (1, 1, lcoeff(A[2],x), lcoeff(A[2], x)^(deg[1]-deg[2]));
\r
2236 l[i] := deg[i-1]-deg[i]+1;
\r
2238 #----------------------------------------------
\r
2240 #----------------------------------------------
\r
2245 #-------------------------------
\r
2246 # form extraneous factor
\r
2247 #-------------------------------
\r
2249 e[i] := (-1)^l[i-1]*a[i-2]*b[i-2];
\r
2251 #--------------------------------
\r
2252 # compute remainder
\r
2253 #--------------------------------
\r
2256 A[i] := evala(Simplify(prem(A[i-2], A[i-1], x)/e[i]));
\r
2258 A[i] := evala(Simplify(prem(A[i-2], A[i-1], x, 'm', 'Q')/e[i]));
\r
2259 U[i] := evala(Simplify((m*U[i-2] - Q*U[i-1])/e[i]));
\r
2261 V[i] := evala(Simplify((m*V[i-2] - Q*V[i-1])/e[i]));
\r
2265 #-----------------------------------
\r
2266 # Resultant is zero
\r
2267 #-----------------------------------
\r
2279 #------------------------------------
\r
2280 # update auxiliary sequences
\r
2281 #------------------------------------
\r
2283 deg[i] := degree(A[i], x);
\r
2284 l[i] := deg[i-1]-deg[i]+1;
\r
2285 a[i] := lcoeff(A[i], x);
\r
2286 b[i] := evala(Simplify(a[i]^(l[i]-1)/b[i-1]^(l[i]-2)));
\r
2289 #-------------------------------------------
\r
2290 # Resultant is nonzero
\r
2291 #-------------------------------------------
\r
2293 if deg[i] = 0 then
\r
2295 s := evala(Simplify(b[i]/a[i]));
\r
2296 us := evala(Simplify(U[i]*s));
\r
2298 vs := evala(Simplify(V[i]*s));
\r
2306 u := (-1)^(df*dg)*vs;
\r
2308 v := (-1)^(df*dg)*us;
\r
2315 return (-1)^(df*dg)*b[i];
\r
2323 #printf(" Pls type 'with(linalg)' firstly before calling function 'Resultant_E' ");
\r
2325 ##The following is to compute the resultant of 2 pols via computing the determinant directly.
\r
2326 # input: M is a list of lists , whereby to denote a matrix;
\r
2327 # i,j are two integer numbers;
\r
2328 # output:sM is a new list of lists, obtained by removing
\r
2329 # the ith row and jth column of L,
\r
2330 SubM:=proc(M,i,j)
\r
2331 local row,tmp,sM;
\r
2332 if i<1 or i>nops(M)
\r
2333 then error "Input row index %1 broke bounds",i;fi;
\r
2334 if j<1 or j>nops(M[1])
\r
2335 then error "Input column index %1 broke bounds",j;fi;
\r
2337 tmp:=subsop(i=NULL,M);
\r
2339 do row:=subsop(j=NULL,row);
\r
2340 sM:=[op(sM),row];
\r
2348 # with(linalg) firstly
\r
2349 # input: A,B are two polynomials, v is a variable;
\r
2350 # output:[R,T,U]; R,T,U are three polynomials, where R is the resultant
\r
2351 # of A,B w.r.t v, so that A*T+B*U=R
\r
2353 NResultantE_Matrix:=proc(A,B,v,TA,UB)
\r
2354 local m,n,d1,d2,cA,cB,row,i,j,syl,msyl,sM,sign,R,T,U,result;
\r
2355 # #lprint("nargs=",nargs);
\r
2357 if (nargs <> 3) and (nargs <> 5) then error "Number of parameters should be 3 or 5" fi;
\r
2361 if m=0 then error "InPut Polynomial %1 Has No Variable %2",A,v;fi;
\r
2362 if n=0 then error "InPut Polynomial %1 Has No Variable %2",B,v;fi;
\r
2364 # to get coefficients of A and B
\r
2366 for d1 from 0 to m
\r
2367 do cA:=[coeff(A,v,d1),op(cA)];
\r
2370 for d2 from 0 to n
\r
2371 do cB:=[coeff(B,v,d2),op(cB)];
\r
2374 # initialize sylvester matrix
\r
2377 for i from 1 to n
\r
2379 for j from 1 to i-1
\r
2380 do row:=[0,op(row)];od;
\r
2381 for j from 1 to n-i
\r
2382 do row:=[op(row),0];od;
\r
2383 syl:=[op(syl),row];
\r
2386 for i from 1 to m
\r
2388 for j from 1 to i-1
\r
2389 do row:=[0,op(row)];od;
\r
2390 for j from 1 to m-i
\r
2391 do row:=[op(row),0];od;
\r
2392 syl:=[op(syl),row];
\r
2395 msyl:=linalg[matrix](m+n,m+n,syl);
\r
2397 # to get resultant of A,B w.r.t v
\r
2398 R:=linalg[det](msyl);
\r
2400 if nargs=3 then RETURN(R) fi;
\r
2404 for d1 from 1 to n
\r
2406 sign:=(-1)^(d1+m+n mod 2);
\r
2407 sM:=SubM(syl,d1,m+n);
\r
2408 T:=T+(v^(n-d1))*expand(sign*linalg[det](linalg[matrix](m+n-1,m+n-1,sM)));
\r
2414 for d2 from 1 to m
\r
2416 sign:=(-1)^(d2+m mod 2);
\r
2417 sM:=SubM(syl,d2+n,m+n);
\r
2418 U:=U+(v^(m-d2))*expand(sign*linalg[det](linalg[matrix](m+n-1,m+n-1,sM)));
\r
2421 if nargs=5 then TA:=T; UB:=U fi;
\r
2425 ###########################################################################################
\r
2426 ###########################################################################################
\r
2427 ############## computing partioned-parametric Grobner basis 2005.11.4###################
\r
2428 ##ÐèÒª¡¡¡°wsolve¡± ºÍ¡¡¡°project¡±
\r
2429 ##Îĺó¸¶ÓÐÖ÷Òªº¯Êýµ÷ÓõÄÀý×Ó
\r
2430 ###########################################################################################
\r
2431 ###########################################################################################
\r
2432 ###########################################################################################
\r
2434 interface(warnlevel=0);
\r
2438 ########pÔÚÔ¼ÊøZero(a11/a12)ÏÂÒ»¶¨²»Îª£°,ordÊDzαäÔª##########
\r
2439 NotZeroUnderCons:=proc(a11,a12,p,ord)
\r
2441 RETURN(IsEmpty({op(a11),p},a12,ord));
\r
2444 ########pÔÚÔ¼ÊøZero(a11/a12)ÏÂÒ»¶¨Îª£°,ordÊDzαäÔª##########
\r
2445 IsZeroUnderCons:=proc(a11,a12,p,ord)
\r
2447 RETURN(IsEmpty(a11,{op(a12),p},ord));
\r
2450 ########Ô¼Êø¶àÏîʽconspolysetÐÎʽ:[[{a11}£¬{a12}]£¬[{a21}£¬{a22}]]##
\r
2451 UnAmbiguous:=proc(conspolyset,var_para::list,term_order)
\r
2452 local p,vp,result,a11,a12,a21,a22,newa11,newa22,lc,vars,paras,reduct;
\r
2454 vars:=var_para[1];
\r
2455 paras:=var_para[2];
\r
2457 a11:=conspolyset[1][1];
\r
2458 a12:=conspolyset[1][2];
\r
2459 a21:=conspolyset[2][1];
\r
2460 a22:=conspolyset[2][2];
\r
2461 if a22={} then RETURN ({conspolyset}); fi;
\r
2464 newa22:=a22 minus {p};
\r
2466 if nops(a21) <>0 then p:=numer(normalf(p,a21,term_order(op(vars)))); fi;
\r
2469 if (_field_characteristic_ <>0 ) then p :=expand(p) mod _field_characteristic_ fi;
\r
2471 if nops(a11) <>0 then p:=numer(normalf(p,a11,term_order(op(paras)))); fi;
\r
2473 if (_field_characteristic_ <>0 ) then p :=expand(p) mod _field_characteristic_ fi;
\r
2476 #########Èç¹ûpÊÇ0¶àÏîʽ############
\r
2477 if p=0 then result:=UnAmbiguous([[a11,a12],[a21,newa22]],var_para,term_order); RETURN(result); fi;
\r
2479 ##########Èç¹ûpÊÇ·Ç0³£Êý##############
\r
2480 if (p <> 0) and ( type(p,'constant') ) then RETURN ( {[conspolyset[1],[{1},{} ] ]}); fi;
\r
2482 #lprint("p="); #lprint(p);
\r
2483 lc:=leadcoeff(p,term_order(op(vars)));
\r
2484 #lprint("lc="); #lprint(lc);
\r
2485 reduct:=expand(p-lc*leadterm(p,term_order(op(vars))));
\r
2488 #######Èç¹ûpº¬ÓбäÔª############
\r
2489 if (vp intersect {op(vars)}) <> {} then
\r
2490 if(type(lc,'constant')=true) then
\r
2491 result:=UnAmbiguous([[a11,a12],[a21 union {p}, newa22]],var_para,term_order);
\r
2493 elif NotZeroUnderCons(a11,a12,lc,paras)
\r
2494 then result:=UnAmbiguous([[a11,a12],[a21 union {p}, newa22]],var_para,term_order);
\r
2496 elif IsZeroUnderCons(a11,a12,lc,paras)
\r
2497 then result:=UnAmbiguous([[a11,a12],[a21,newa22 union {reduct}]],var_para,term_order);
\r
2500 lc:=CutNozeroFactors(lc,a12);
\r
2501 newa11:=CutPolyByFactor(a11,lc);
\r
2502 result:=UnAmbiguous([[{op(newa11),lc},a12],[a21,newa22 union {reduct}]],var_para,term_order)
\r
2503 union UnAmbiguous([[a11,a12 union FactorList(lc)],[a21 union {p}, newa22]],var_para,term_order);
\r
2508 #######Èç¹ûp²»º¬±äÔª£¬Ö»º¬²ÎÊý############
\r
2510 if NotZeroUnderCons(a11,a12,p,paras) then result:={[conspolyset[1],[{1},{} ]]};
\r
2511 elif IsZeroUnderCons(a11,a12,p,paras) then result:=UnAmbiguous([[a11,a12],[a21,newa22]],var_para,term_order) ;
\r
2514 lc:=CutNozeroFactors(lc,a12);
\r
2515 newa11:=CutPolyByFactor(a11,lc);
\r
2516 result:=UnAmbiguous([[{op(newa11),lc},a12],[a21,newa22]],var_para,term_order)
\r
2517 union UnAmbiguous([[a11,a12 union FactorList(lc)],[{1}, {}]],var_para,term_order);
\r
2529 ######pol¶Ôlist1ÖеĶàÏîʽÖð¸ö×ö³ý·¨£¬·µ»ØÉÌ#######
\r
2530 DivideList:=proc(pol,list1)
\r
2534 if divide(rt,i,'q') then rt:=q; fi;
\r
2539 ###<1>list1ÖеĶàÏîʽÒѲ»¿ÉÔ¼
\r
2540 ###<2>È¥µôpolÖÐÔÚlist1ÀïÁгöµÄÒò×ÓÇÒºöÂÔÖØÊý
\r
2541 CutNozeroFactors:=proc(pol,list1)
\r
2542 local i,q,sqf_pol,rt;
\r
2543 sqf_pol:=sqrfree(pol);
\r
2544 sqf_pol:=sqf_pol[2];
\r
2545 for i from 1 to nops(sqf_pol) do
\r
2546 sqf_pol[i][1]:=DivideList(sqf_pol[i][1],list1);
\r
2549 for i from 1 to nops(sqf_pol) do
\r
2550 rt:=rt*(sqf_pol[i][1]);
\r
2555 ###È¥µôlist1ÖÐÒÔpolΪÒò×ӵĶàÏîʽ
\r
2556 CutPolyByFactor:=proc(list1,pol)
\r
2560 if not divide(p,pol,'q') then rt:={op(rt),p};fi;
\r
2567 ##<1>ͨ¹ýgb¶ÔµÈÓÚÁãµÄÔ¼Êø²¿·Ö×önormalformÀ´»¯¼ò
\r
2568 ##<2>ÒòΪgbµÄÊ×ϵÊýÒ»¶¨²»ÎªÁ㣬ͨ¹ý¶Ôgb×öprimpartÀ´»¯¼ò
\r
2569 SimplifyConsgb:=proc(consgb,var_para,term_order)
\r
2570 local rt,i,temp,paras,vars;
\r
2571 vars:=var_para[1];
\r
2572 paras:=var_para[2];
\r
2574 for i in consgb do
\r
2575 temp:=map(normalf,i[2],i[1][1],term_order(op(paras)));
\r
2576 temp:=map(primpart,map(numer,temp),vars);
\r
2577 rt:={op(rt),[i[1],temp]};
\r
2583 FactorList:=proc(pol)
\r
2584 local i,list1,list2;
\r
2585 list1 := factors(pol)[2];
\r
2587 for i in list1 do list2 := {op(list2),i[1]}; od;
\r
2592 #######Èç¹ûpÔÚconstrainµÄÌõ¼þÏÂΪ0ÔÚ·µ»Ø1,np=0
\r
2593 #######Èç¹ûpÔÚconstrainµÄÌõ¼þÏÂΪ·Ç0µÄ³£Êý·µ»Ø10,np=10
\r
2594 #######Èç¹ûpÔÚconstrainµÄÌõ¼þÏÂÊ×ÏîϵÊýÒ»¶¨²»ÊÇ0Ôò·µ»Ø-1
\r
2595 #######ÆäËûÇéÐηµ»Ø0¡£np=pol
\r
2596 ########paracons=[ [part=0 ],[part <>0]] ÊDzÎÊýµÄÔ¼Êø;
\r
2598 nonzerolc:=proc(pol,paracons,var_para,np,term_order)
\r
2599 local lc,vars,paras,cons1,cons2,np0,t,pol2;
\r
2600 global _field_characteristic_ ;
\r
2601 vars:=var_para[1];
\r
2602 paras:=var_para[2];
\r
2603 cons1:=paracons[1];
\r
2604 cons2:=paracons[2];
\r
2605 lc:=leadcoeff(pol,term_order(op(vars)));
\r
2606 if pol=0 then np:=0; RETURN(1); fi;
\r
2607 if type(pol,'constant') then np:=10; RETURN(10); fi;
\r
2608 if type(lc,'constant') then np:=pol; RETURN(-1); fi;
\r
2611 ##########lcÔÚÔ¼ÊøÏÂÒ»¶¨Îª£°#######
\r
2612 if IsZeroUnderCons(cons1,cons2,lc,paras) then
\r
2613 pol2:=reductum(pol,term_order(op(vars)));
\r
2614 if (_field_characteristic_ <>0 ) then pol2:=pol2 mod _field_characteristic_ fi;
\r
2615 t:=nonzerolc(pol2,paracons,var_para,'np0',term_order);
\r
2619 ##########lcÔÚÔ¼ÊøÏÂÒ»¶¨²»Îª£°#######
\r
2620 elif NotZeroUnderCons(cons1,cons2,lc,paras) then
\r
2621 if lc=pol then np:=10; RETURN(10);
\r
2622 else np:=pol; RETURN(-1);
\r
2631 reductum:=proc(p,ord)
\r
2633 expand(p-leadcoeff(p,ord)*leadterm(p,ord));
\r
2636 gb:=proc(ps,var_para,term_order)
\r
2638 res:=gb0([[{},{}],[{},{op(ps)}]],var_para,term_order);
\r
2639 res:=SimplifyConsgb(res,var_para,term_order);
\r
2644 gb0:=proc(conspolyset,var_para,term_order)
\r
2645 local i,branches, res,temp;
\r
2647 branches:=UnAmbiguous(conspolyset,var_para,term_order);
\r
2648 for i in branches do
\r
2649 temp:=gb1(i,var_para,term_order);
\r
2650 res:=res union temp;
\r
2655 #################Step 1########################
\r
2656 gb1:=proc(conspolyset,var_para,term_order)
\r
2657 local i,j,T,paracons,pset,pset0,pset1,pol,pset3,l,nonzerosp,sp,bs2,vars,newpol,cr,nf,np;
\r
2658 global _field_characteristic_;
\r
2660 vars:=var_para[1];
\r
2661 paracons:=conspolyset[1];
\r
2662 pset:=conspolyset[2][1];
\r
2667 if nops(pset)=0 then RETURN({[paracons,[0]]}) fi;
\r
2669 if nops(pset) =1 then RETURN({[paracons,[op(pset)]]}) fi;
\r
2671 #################Step 2----- Normalization------#####################
\r
2673 pset0:=pset0 minus {i};
\r
2674 nf:=normalf(i,pset0 union pset1,term_order(op(vars)));
\r
2675 pol:=expand(numer(nf ));
\r
2676 cr:=nonzerolc(pol,paracons,var_para,'newpol',term_order);
\r
2678 newpol:=numer(normalf(newpol,pset0 union pset1,term_order(op(vars))));
\r
2680 if (_field_characteristic_ <>0 ) then newpol :=expand(newpol) mod _field_characteristic_ fi;
\r
2681 #lprint("newpol=");#lprint(newpol);
\r
2683 elif cr=10 then RETURN( { [paracons,[1]] });
\r
2684 elif cr=-1 then if newpol <>0 then pset1:=pset1 union {newpol} fi;
\r
2686 pset3:=[paracons,[ pset0 union pset1 ,{newpol} ]];
\r
2687 RETURN( gb0(pset3,var_para,term_order) );
\r
2691 ##############Step 3----- S-polynomial------####################################
\r
2693 if l=1 then RETURN( {[paracons,[op(pset1)]] }) fi;
\r
2697 for j from i+1 to l do
\r
2698 sp:=expand(numer(normalf(spoly(pset1[i],pset1[j],term_order(op(vars))),pset1,term_order(op(vars)))));
\r
2699 if( _field_characteristic_ <>0) then sp:= expand(sp) mod _field_characteristic_ fi;
\r
2700 #lprint("sp="); #lprint(sp);
\r
2701 if (nonzerolc(sp,paracons,var_para,'np',term_order)<>1) then nonzerosp:=nonzerosp union {np} fi;
\r
2705 if nonzerosp={} then RETURN( {[paracons,inter_reduce([op(pset1)],term_order(op(vars)) )] } ) ;
\r
2707 bs2:=[paracons,[{op(pset1)},nonzerosp ]];
\r
2708 T:=T union gb0(bs2,var_para,term_order);
\r
2715 #############################
\r
2716 ### solution number ####
\r
2717 #############################
\r
2719 basis:=proc(a,b,ord)
\r
2720 local i,j,k1,k;k:={};
\r
2722 k1:=normalf(i,b,ord);
\r
2733 if b={} then return a; fi;
\r
2742 create:=proc(a,b,num)
\r
2743 local i,j,k,k1,b1;
\r
2746 k1:=b1 union mulset(a,b1);
\r
2747 if num=0 then return k1;fi;
\r
2748 k:=create(a,k1,num-1);
\r
2752 havefinitesolution:=proc(l,var)
\r
2756 lvs:=indets(i) intersect {op(var)};
\r
2757 if nops(lvs)=1 then lv1:=lv1 union lvs; fi;
\r
2760 if ({op(var)} minus lv1 )={} then return true;
\r
2761 else return false;
\r
2767 local i,j,k,l;k:={};
\r
2778 getmostdegree:=proc(l)
\r
2785 k2:=k2 union {op(j)};
\r
2791 ltt:=proc(l,vorder)
\r
2794 for i to nops(l) do
\r
2795 k:={leadterm(l[i],vorder)} union k;
\r
2800 GetDim:=proc(lts,vars)
\r
2801 local i,branch,l,rt;
\r
2803 branch:=Nrs(lts,[op(vars)],{});
\r
2804 branch:=[op(branch)];
\r
2805 for i to nops(branch) do
\r
2806 l:=nops(branch[i]);
\r
2807 if l<rt then rt:=l;fi;
\r
2809 return nops(vars)-rt;
\r
2813 ##for reduced groebner basis
\r
2814 sumofdegree:=proc(lts)
\r
2818 if nops(indets(i))=1 then
\r
2825 solution1:=proc(ps,ord,term_order)
\r
2826 local i,j,k,cgb,lt,mosttotaldeg,dim;
\r
2827 cgb:=gb(ps,ord,term_order);
\r
2829 for i to nops(cgb) do
\r
2830 lt:=ltt(cgb[i][2],term_order(op(ord[1])));
\r
2831 if havefinitesolution(lt,ord[1]) then
\r
2832 mosttotaldeg:=sumofdegree(lt);
\r
2833 k:=basis(create({op(ord[1])},{},mosttotaldeg),lt,term_order(op(ord[1])));
\r
2834 cgb[i]:=[op(cgb[i]),k,cat("finite solution with number: ", nops(k))];
\r
2836 elif cgb[i][2]=[1] then cgb[i]:=[op(cgb[i]),"no solution"];
\r
2837 elif cgb[i][2]=[0] then cgb[i]:=[op(cgb[i]),cat("infinite solution with dimension: ",nops(ord[1]))];
\r
2839 dim:=GetDim(lt,ord[1]);
\r
2840 cgb[i]:=[op(cgb[i]),[lt],cat("infinite solution with dimension: ", dim)];
\r
2847 ##µÚ4¸ö²ÎÊý¿ÉÊ¡,Èç¹ûÓÐ,±ØÐë¼Óµ¥ÒýºÅ!
\r
2848 solution:=proc(ps,ord,term_order,pgb)
\r
2849 local i,j,k,cgb,lt,mosttotaldeg,dim;
\r
2850 cgb:=gb(ps,ord,term_order);
\r
2852 if nargs=4 then pgb:={op(cgb)};fi;
\r
2853 for i to nops(cgb) do
\r
2854 lt:=ltt(cgb[i][2],term_order(op(ord[1])));
\r
2855 if havefinitesolution(lt,ord[1]) then
\r
2856 mosttotaldeg:=sumofdegree(lt);
\r
2857 k:=basis(create({op(ord[1])},{},mosttotaldeg),lt,term_order(op(ord[1])));
\r
2858 cgb[i][2]:=cat("finite solution with number: ", nops(k));
\r
2859 elif cgb[i][2]=[1] then cgb[i][2]:="no solution";
\r
2860 elif cgb[i][2]=[0] then cgb[i][2]:=cat("infinite solution with dimension: ",nops(ord[1]));
\r
2862 dim:=GetDim(lt,ord[1]);
\r
2863 cgb[i][2]:= cat("infinite solution with dimension: ", dim);
\r
2869 FindRightGB:=proc(paragb)
\r
2870 local gb,pgb,rt,i,j;
\r
2872 pgb:=[op(paragb)];
\r
2873 for i to nops(pgb) do
\r
2875 if nops(gb[1][1])=0 then gb[1][1]:={0} fi;
\r
2876 if nops(gb[1][2])=0 then gb[1][2]:={1} fi;
\r
2877 if {op(gb[1][1])}={0} and (gb[1][2] intersect {0})<>{0} then
\r
2882 if j<>1 then print("ambiguous occur!");fi;
\r
2886 EvalAll:=proc(op,vars,vals)
\r
2889 for i to nops(vars) do
\r
2890 rt:=eval(rt,vars[i]=vals[i]);
\r
2896 #°ÑpsÖеĶàÏîʽÉè³ÉÊ×ÏîϵÊýΪ£±
\r
2900 for i to nops(ps) do
\r
2902 if p=0 then rt:={op(rt),p};
\r
2912 ###¼ìÑéÔ¼Êøgroebnerbasis³ÌÐòµÄÕýÈ·ÐÔ
\r
2913 check:=proc(paravalue,paragb,ps,ord,term_order)
\r
2914 local i,gb,gb1,spec_paragb,spec_ps;
\r
2915 if nops(paravalue)<>nops(ord[2]) then return "Error in parameter assignment: parameter number is NOT matched!" fi;
\r
2917 spec_ps:=EvalAll(ps,ord[2],paravalue);
\r
2918 spec_ps:={op(spec_ps)} minus {0};
\r
2919 spec_ps:=[op(spec_ps)];
\r
2920 gb1:=gbasis(spec_ps,term_order(op(ord[1])));
\r
2922 spec_paragb:=EvalAll(paragb,ord[2],paravalue);
\r
2923 gb:=FindRightGB(spec_paragb);
\r
2925 if SetLC1(gb)=SetLC1(gb1) then print( "two results are the same polynomial set!");
\r
2926 else print("two results are NOT the same polynomial set!");
\r
2929 print("greobner basis gotten by parameter assignment at begin:");
\r
2932 print("greobner basis gotten by CGB method:");
\r
2938 ######## Àý×Ó ######################
\r
2940 #ps:=[a*x^2-b*x,b*y^2-c*x,c*z^2-a*x+b];
\r
2941 #ord:=[[x,y,z],[a,b,c]];
\r
2943 #'pgb';¡¡ÊÇÒ»¸ö±äÁ¿Ãû£¬¸Ã²ÎÊý¿Éȱʡ
\r
2946 #gb(ps,ord,termord)
\r
2948 #psµÄÔ¼ÊøGroebnerBasis
\r
2951 #solution(ps,ord,termord,'pgb');¡¡
\r
2953 #psµÄ²»Í¬Ô¼ÊøϽâµÄ¸öÊý¡£
\r
2954 #pgbΪpsµÄÔ¼ÊøGroebnerBasis
\r
2957 #solution1(ps,ord,termord);¡¡
\r
2959 #psµÄÔ¼ÊøGroebnerBasis¼°ÏàÓ¦½âµÄ¸öÊý£¨ÈôÓÐÏÞ£¬»¹Áгö²»ÊôÓÚÊ×ÀíÏëµÄµ¥Ïîʽ£©¡£
\r
2962 #paraval:=[1,2,3];¡¡ÊDzÎÊý[a,b,c]µÄÌض¨Öµ
\r
2963 #pgb; psµÄÔ¼ÊøGroebnerBasis
\r
2966 # check(paraval,pgb,ps,ord,termord);
\r
2967 #¸Ãº¯Êý±È½ÏpgbÔÚÌض¨²ÎÊýÖµparavalϵÄGroebnerBasisÓëÏȶԲÎÊýÈ¡ÖµºóÔÙÇóµÄGroebnerBasisÊÇ·ñÏàͬ¡£
\r
2968 #ͬʱҲÁгöÕâÁ½¸öGroebnerBasis¡£´Ëº¯Êý¿É×öΪȫÎĵIJâÊÔº¯Êý¡£
\r
2970 #pgbÔÚÌض¨²ÎÊýÖµparavalϵÄGroebnerBasis
\r
2973 ###########################################################################################
\r
2974 ###########################################################################################
\r
2975 ############## computing partioned-parametric Grobner basis 2005.11.4 #####################
\r
2976 ############## END END END END END END END END END END END END END END#####################
\r
2977 ###########################################################################################
\r
2978 ###########################################################################################
\r
2979 ###########################################################################################
\r
2982 ########################for computing the projection of quasi-variety 2005.11.4###############
\r
2983 ### read "wsolve.txt" firstly ###
\r
2984 if not type(wsolve,procedure) then
\r
2985 #lprint(" Warning: please read 'wsolve.txt' firstly ! "):
\r
2988 ##-----main function------------------------------------------------
\r
2989 ##Project(ps,ds,ord,pord) //old main function
\r
2990 ##Sproject(result_of_project,pord) //no component is redundant
\r
2991 ##Example: [[ASC,[a,b]],...] == (ASC=0 and a*b<>0 ) or ...
\r
2993 ##Proj(ps,ds,ord,pord) //new main function
\r
2994 ##Sproj(result_of_project,pord) //no component is redundant
\r
2995 ##Example: [[ASC,[a,b]],...] == (ASC=0 and ( a<>0 or b<>0) ) or ...
\r
2996 ##-------------------------------------------------------------------
\r
2999 #-----------Part1------<algebraic case>---------------
\r
3000 # project(ps,ds,ord,pord)
\r
3001 # ord:= all variables (descending order list)
\r
3002 # pord:=variables to eliminate (as above)
\r
3003 #-----------------------------------------------------
\r
3004 #QV (QuasiVariety) ; ASC (ascendant characteristic set)
\r
3006 # get the product of the initials of cs
\r
3008 Mainvar := proc(f,ord)
\r
3010 options remember,system;
\r
3011 for i to nops(ord) do
\r
3012 if has(f,ord[i]) then RETURN(ord[i]) fi
\r
3014 #lprint(`Warning: lvar is called with constant`);
\r
3018 GetIP:=proc(cs,ord)
\r
3021 for i from 1 to nops(cs) do
\r
3022 rt:=rt*Initial(cs[i],ord);
\r
3027 # get the product of the polys in ds.
\r
3028 GetProduct:=proc(ds)
\r
3037 #get the union of two lists, denoted as list also.
\r
3038 ListUnion:=proc(list1,list2)
\r
3040 rt:={op(list1)} union {op(list2)};
\r
3045 Inverse:=proc(lis)
\r
3048 for i from nops(lis) to 1 by -1
\r
3049 do result:=[op(result),lis[i]];
\r
3054 # inverse every list in a list.
\r
3055 InverseAll:=proc(lislis)
\r
3058 for l in lislis do
\r
3059 rt:=[op(rt),Inverse(l)];
\r
3063 # eliminate such ASC in cslist that Premas(jds,ASC,ord)=0
\r
3064 Newcslist:=proc(cslist,jds,ord)
\r
3067 for cs in cslist do
\r
3068 if Premas(jds,cs,ord)<>0
\r
3069 then rt:=[op(rt),cs]
\r
3075 # factors of a polynomial w.r.t ord;
\r
3076 # facts(x^2*y+x*y-x,[x,y]); [x,x*y+y-1]
\r
3077 # facts(x^2*y+x*y-x,[y]); [x*y+y-1]
\r
3078 # facts(x^2*y+x*y-x,[u,v,w]); []
\r
3079 Ordfacts:=proc(pol,ord)
\r
3080 local i,temp,facl,result;
\r
3081 if type(pol,polynom) then
\r
3083 facl:=factors(pol);
\r
3085 if facl=[] then RETURN([]) fi;
\r
3086 for i from 1 to nops(facl)
\r
3088 if dClass(temp[1],ord)<>0 then
\r
3089 result:=[op(result),temp[1]];
\r
3094 #lprint(`Warning: facts is called with no polynomial`);
\r
3099 # put p to proper position in notzerolist s.t. MV(ASC[i-1])<=MV(p)<MV(ASC[i])
\r
3100 PutToNotZero:=proc(p,notzerolist,mvl,ord)
\r
3103 cp:=Class(p,ord);
\r
3104 if cp=0 then RETURN(rt);fi;
\r
3105 for i from 1 to nops(mvl) do
\r
3106 if cp<mvl[i] then rt:=subsop(i=rt[i]*p,rt);break;
\r
3110 if i=nops(mvl)+1 then
\r
3111 rt:=subsop(-1=rt[-1]*p,rt) ;
\r
3116 # all factors(noted fpolys) of polys in ds and initials,
\r
3117 # notzerolist[i]= the product of p,
\r
3118 # s.t. <1> p in fpolys and <2> MV(ASC[i-1])<=MV(p)<MV(ASC[i])
\r
3119 CreatNotZeroList:=proc(cs,ds,mvl,ord)
\r
3120 local i,fs,p,notzerolist;
\r
3123 for i from 0 to nops(cs) do
\r
3124 notzerolist:=[op(notzerolist),1];
\r
3129 fs:=ListUnion(fs,Ordfacts(p,ord));
\r
3132 notzerolist:=PutToNotZero(p,notzerolist,mvl,ord);
\r
3137 #a front part of ASC whose polynomials contain no variables in pord
\r
3138 SubASC:=proc(asc,pord)
\r
3141 for i from 1 to nops(asc)
\r
3142 do if Class(asc[i],pord)=0
\r
3143 then result:=[op(result),asc[i]];
\r
3150 #judge the result of ProjectASC
\r
3151 #if it is [[...],1] return 1;
\r
3152 #if it is [[...],0] return 0;
\r
3154 IsTrival:=proc(qv,ord)
\r
3156 if nops(qv)<>2 then rt:=3;
\r
3157 elif not type(qv[2],polynom) then rt:=3;
\r
3158 elif Class(qv[2],ord)<>0 then rt:=3;
\r
3159 elif qv[2]=0 then rt:=0;
\r
3165 # get variables of pol which are of higher order then the highest
\r
3166 # polynomial in asc.
\r
3167 HigherOrdVars:=proc(pol,mvl,len,ord)
\r
3168 local vl,rt,var,index;
\r
3169 vl:=indets(pol) intersect {op(pord)};
\r
3171 if len<=1 then RETURN(rt);fi;
\r
3173 index:=Class(var,ord);
\r
3174 if index>mvl[len-1] then
\r
3181 # decompose the pol in [[ASC],pol] to ['UN',[[ASC],pol1],...]
\r
3182 # so as to eliminate variables in varl.
\r
3183 DecompList:=proc(qv,subasc,notzerolist,varList,ord)
\r
3184 local i,flag,lenasc,rt,pol,coeffsList,coeff;
\r
3185 if varList=[] then RETURN(qv);fi;
\r
3188 if pol=0 then rt:=[subasc,pol];
\r
3191 lenasc:=nops(qv[1]);
\r
3192 for i from 1 to lenasc do
\r
3193 if notzerolist[i]!=1 then flag:=1; break;fi;
\r
3195 coeffsList:=[coeffs(expand(pol),varList)];
\r
3196 if nops(coeffsList)>1 then rt:=["UN"];
\r
3199 for coeff in coeffsList do
\r
3200 if Class(coeff,ord)=0 and flag=0 then
\r
3201 RETURN([subasc,1]);
\r
3203 rt:=[op(rt),[qv[1],coeff]];
\r
3207 if nops(rt)=1 then rt:=rt[1];fi;
\r
3212 #when ASC has no variables in varl .
\r
3213 # decompose the pol in [[ASC],pol] to ['UN',[[ASC],pol1],...]
\r
3214 # so as to eliminate variables in varl
\r
3215 DecompList1:=proc(qv,subasc,notzerolist,varList,ord)
\r
3216 local i,flag,lenasc,rt,pol,coeffsList,coeff;
\r
3217 if varList=[] then RETURN(qv);fi;
\r
3220 if pol=0 then rt:=[subasc,pol];
\r
3223 lenasc:=nops(qv[1]);
\r
3224 for i from 1 to lenasc do
\r
3225 flag:=flag*notzerolist[i] ;
\r
3228 coeffsList:=[coeffs(expand(pol),varList)];
\r
3229 if nops(coeffsList)>1 then rt:=["UN"];
\r
3232 for coeff in coeffsList do
\r
3233 if Class(coeff,ord)=0 and flag=1 then
\r
3234 RETURN([subasc,1]);
\r
3236 rt:=[op(rt),[qv[1],coeff*flag]];
\r
3240 if nops(rt)=1 then rt:=rt[1];fi;
\r
3245 # eliminate the highest polynomial in ASC, within [[ASC],pol]
\r
3246 ElimPoly:=proc(qv,notzerolist,mvl,subasc,ord,pord)
\r
3247 local rt,newasc,asc,pol,hPol,hVar,hDeg,rem,newPol,tempList,varList,len;
\r
3250 newasc:=subsop(len=NULL,asc);
\r
3253 hVar:=Mainvar(hPol,ord);
\r
3254 hDeg:=degree(hPol,hVar);
\r
3255 if degree(pol,hVar)=0 then
\r
3256 rt:=[newasc,pol*notzerolist[len]];
\r
3259 rem:=sprem(pol^hDeg,hPol,hVar);
\r
3264 newPol:=rem*notzerolist[len];
\r
3265 tempList:=[newasc,newPol];
\r
3266 varList:=HigherOrdVars(newPol,mvl,len,ord,pord);
\r
3267 rt:=DecompList(tempList,subasc,notzerolist,varList,ord);
\r
3272 # project wth one QV formed by one ASC(prepair share done by ProjASC)
\r
3273 ProjectASC:=proc(qv,notzerolist,mvl,subasc,lensub,ord,pord)
\r
3274 local pol,asc,nproj,tempList,sign,rt,nozero,i;
\r
3278 # get the nonzero polynomial to prject with here.
\r
3280 for i from 1 to nops(asc) do
\r
3281 nozero:=nozero*notzerolist[i];
\r
3284 # recursion ending conditions
\r
3285 if nops(asc)=0 or nops(asc)=lensub then
\r
3286 if Class(nozero,pord)>0 then
\r
3287 rt:=DecompList1(qv,subasc,notzerolist,pord,ord);
\r
3288 elif Class(nozero,ord)>0 then
\r
3291 rt:=[asc,Get1or0(nozero)];
\r
3294 elif Class(nozero,pord)=0 then
\r
3295 if Class(nozero,ord)>0 then rt:=[subasc,nozero];
\r
3297 rt:=[subasc,Get1or0(nozero)];
\r
3302 # eliminate the highest polynomial in asc of QV.
\r
3303 tempList:=ElimPoly(qv,notzerolist,mvl,subasc,ord,pord);
\r
3305 # whether have many branchs in the result of ElimPoly.
\r
3306 if not type(tempList[1],string) then
\r
3307 rt:=ProjectASC(tempList,notzerolist,mvl,subasc,lensub,ord,pord);
\r
3309 rt:=[tempList[1]];
\r
3310 for i from 2 to nops(tempList) do
\r
3311 nproj:=ProjectASC(tempList[i],notzerolist,mvl,subasc,lensub,ord,pord);
\r
3313 # deal with trival cases.
\r
3314 sign:=IsTrival(nproj,ord);
\r
3315 if sign=0 then next;
\r
3316 elif sign=1 then rt:= [subasc,1];break;
\r
3317 else rt:=[op(rt),nproj];
\r
3322 if nops(rt)=1 then rt:=[subasc,0]; fi;
\r
3324 # rt:=["UN",[...]]
\r
3325 if nops(rt)=2 and type(rt[2],list) then rt:=rt[2];fi;
\r
3330 # project with one QV formed by one ASC
\r
3331 ProjASC:=proc(cs,ds,ord,pord)
\r
3332 local mvl,notzerolist,p,qv,subasc,lensub,rt;
\r
3334 # mainvars order list
\r
3337 mvl:=[op(mvl),Class(p,ord)];
\r
3340 notzerolist:=CreatNotZeroList(cs,ds,mvl,ord);
\r
3342 qv:=[cs,notzerolist[-1]];
\r
3343 subasc:=SubASC(cs,pord);
\r
3344 lensub:=nops(subasc);
\r
3345 rt:=ProjectASC(qv,notzerolist,mvl,subasc,lensub,ord,pord);
\r
3350 #whether input QuasiVariety is [[[],[1]]]
\r
3351 QVIsTruth:=proc(qv)
\r
3352 if qv=[[[],[1]]] then RETURN(true);
\r
3353 else RETURN(false);
\r
3357 #----main func.-------
\r
3358 # project with the QV [ps,ds], eliminate variables in pord
\r
3359 # return [] if zero(ps) is empty
\r
3360 # return [[[],[0]]] if zero(ps/ds) is empty
\r
3361 # else return [ [[ASC],[p1,p2,...]] , ...]
\r
3362 Project:=proc(ps,ds,ord,pord)
\r
3363 local jds,cslist,cs,p,ini,qvs,newds,subasc,rt;
\r
3364 jds:=GetProduct(ds);
\r
3365 cslist:=wsolve(ps,ord);
\r
3366 #printf("The characteristic sets are:");
\r
3369 if nops(cslist)<>0 then
\r
3370 cslist:=Newcslist(cslist,jds,ord);
\r
3371 if nops(cslist)=0 then RETURN([]);
\r
3373 cslist:=InverseAll(cslist);
\r
3374 for cs in cslist do
\r
3376 #add initials to ds
\r
3379 ini:=Initial(p,ord);
\r
3380 if Class(ini,ord)>0 then
\r
3381 newds:={op(newds),ini};
\r
3384 newds:=[op(newds)];
\r
3386 qvs:=ProjASC(cs,newds,ord,pord);
\r
3387 subasc:=qvs[1][1];
\r
3388 qvs:=Simplify1(qvs,subasc,ord);
\r
3389 if QVIsTruth(qvs) then rt:=qvs; RETURN(rt);
\r
3391 rt:=ListUnion(qvs,rt);
\r
3395 if nops(rt)=0 then RETURN([[[],[0]]]); fi;
\r
3401 ## the subasc in qvs is the same one
\r
3402 AddQVS:=proc(rt,qvs)
\r
3403 local newrt,i,j,subasc;
\r
3407 for i from 1 to nops(newrt) do
\r
3408 if subasc=newrt[i][1] then newrt[i][2]:=ListUnion(qvs[2],newrt[i][2]); j:=1; break;fi;
\r
3410 if j=0 then newrt:=[op(newrt),qvs];fi;
\r
3414 SqfreeList:=proc(plist)
\r
3415 local j,p,q,rt,sq;
\r
3430 SqfreeGB:=proc(plist,ord)
\r
3433 gb2:=Groebner[gbasis](gb1,plex(op(ord)));
\r
3434 gb2:=SqfreeList(gb2);
\r
3435 while(gb1<>gb2) do
\r
3437 gb2:=Groebner[gbasis](gb1,plex(op(ord)));
\r
3438 gb2:=SqfreeList(gb2);
\r
3443 GBsimplify:=proc(qvs,ord)
\r
3447 rt:=[op(rt),[qv[1],SqfreeGB(qv[2],ord) ] ];
\r
3453 local rt,qv,notzero;
\r
3456 notzero:=[op(notzero),qv[2]];
\r
3458 notzero:={op(notzero)};
\r
3459 notzero:=[op(notzero)];
\r
3460 rt:=[qvs[1][1],notzero];
\r
3464 Proj:=proc(ps,ds,ord,pord)
\r
3465 local jds,cslist,cs,p,ini,qvs,newds,subasc,rt;
\r
3466 jds:=GetProduct(ds);
\r
3467 cslist:=wsolve(ps,ord);
\r
3468 #printf("The characteristic sets are:");
\r
3471 if nops(cslist)<>0 then
\r
3472 cslist:=Newcslist(cslist,jds,ord);
\r
3473 if nops(cslist)=0 then RETURN("Characteristic Set is empty set");
\r
3475 cslist:=InverseAll(cslist);
\r
3476 for cs in cslist do
\r
3478 #add initials to ds
\r
3481 ini:=Initial(p,ord);
\r
3482 if Class(ini,ord)>0 then
\r
3483 newds:={op(newds),ini};
\r
3486 newds:=[op(newds)];
\r
3488 qvs:=ProjASC(cs,newds,ord,pord);
\r
3489 subasc:=qvs[1][1];
\r
3491 qvs:=Simplify2(qvs,subasc,ord);
\r
3492 if qvs=[[[],1]] then RETURN([[[],[1]]]);
\r
3495 rt:=AddQVS(rt,qvs);
\r
3499 if nops(rt)=0 then RETURN([[[],[0]]]); fi;
\r
3500 rt:=GBsimplify(rt,ord);
\r
3505 # return 1 if zero(ps,ds)=empty
\r
3507 IsEmpty:=proc(ps,ds,ord)
\r
3508 local jds,cslist,cs,p,ini,qvs,newds,subasc;
\r
3509 if nops(ps)=0 then RETURN(false);fi;
\r
3510 jds:=GetProduct(ds);
\r
3511 cslist:=wsolve(ps,ord);
\r
3512 #printf("The characteristic sets are:");
\r
3514 if nops(cslist)<>0 then
\r
3515 cslist:=Newcslist(cslist,jds,ord);
\r
3516 if nops(cslist)=0 then RETURN(true);
\r
3518 cslist:=InverseAll(cslist);
\r
3519 for cs in cslist do
\r
3521 #add initials to ds
\r
3524 ini:=Initial(p,ord);
\r
3525 if Class(ini,ord)>0 then
\r
3526 newds:=[op(ds),ini];
\r
3530 qvs:=ProjASC(cs,newds,ord,ord);
\r
3531 subasc:=qvs[1][1];
\r
3532 qvs:=Simplify1(qvs,subasc,ord);
\r
3533 if QVIsTruth(qvs) then RETURN(false);
\r
3540 #return -1 if zero([ ps, [op(ds),p] ])=empty
\r
3541 #return 1 if zero([ [op(ps),p],ds ])=empty
\r
3543 whichcase:=proc(ps0,ds0,p,ord)
\r
3547 if IsEmpty(ps,[op(ds),p],ord,ord) then RETURN(-1) fi;
\r
3548 if IsEmpty([op(ps),p],ds,ord,ord) then RETURN(1) fi;
\r
3553 #---------------- Format1(qvs)-----------------
\r
3555 #when the input is as:["UN",...]
\r
3556 #step1: formated all the branchs of "UN".
\r
3557 #step2: Union all the branchs.
\r
3558 FormatUN:=proc(qvs)
\r
3561 for i from 2 to nops(qvs) do
\r
3562 temp:=Format1(qvs[i]);
\r
3563 rt:=ListUnion(rt,temp);
\r
3568 # when the input is as:[[ASC],pol]
\r
3569 # output [[[ASC],pol]]
\r
3570 FormatList:=proc(qv)
\r
3574 # format the result of ProjectASC()
\r
3575 # to the form: [[[ASC],pol1],[[ASC],pol2],...];
\r
3576 Format1:=proc(qvs)
\r
3578 if type(qvs[1],string) then
\r
3579 rt:=FormatUN(qvs);
\r
3581 rt:=FormatList(qvs);
\r
3587 #-----------------Simplify1(qvs)---------------
\r
3588 #for every qausi variety in the result of Project() call doRem1
\r
3589 #for empty set , return []; the result form: [[[ASC],[p1,p2,...]],...]
\r
3590 #p1<>0 and p2<>0 and ...
\r
3591 Simplify1:=proc(qvs,subasc,ord)
\r
3592 local qv,rt,newqv;
\r
3595 newqv:=doRem1(qv,subasc,ord);
\r
3596 if newqv<>[] then
\r
3597 if member(1,newqv[2]) then RETURN([[subasc,[1]]]);fi;
\r
3599 rt:=[op(rt),newqv];
\r
3604 # a qausi variety is denoted as: [[asc],pol]
\r
3605 # rem=premas(pol,asc,ord)
\r
3606 # notZero:= all factors of rem of dClass w.r.t ord zero.
\r
3607 # return [[asc], [notZero]]
\r
3608 doRem1:=proc(qv,subasc,ord)
\r
3609 local pol,rem,notZero,rt;
\r
3611 # modified 2003.3.21
\r
3612 # if nops(subasc)=0 or Class(pol,ord)=0 then
\r
3613 # if pol=0 then rt:=[];
\r
3614 # else rt:=[subasc,[1]];
\r
3618 rem:=Premas(pol,Inverse(subasc),ord);
\r
3619 if rem=0 then rt:=[];
\r
3621 notZero:=Factorlist_chen(rem,ord);
\r
3622 rt:=[subasc,notZero];
\r
3626 #-----------------Simplify2(qvs)---------------
\r
3627 #for every qausi variety in the result of Project() call doRem2
\r
3628 #for empty set , return []; the result form: [[[ASC],[p1,p2,...]],...]
\r
3629 #p1<>0 or p2<>0 or ...
\r
3631 #for every qausi variety in the result of Project() call doRem
\r
3632 #for empty set , return []; the result form: [[[ASC],[p1,p2,...]],...]
\r
3633 Simplify2:=proc(qvs,subasc,ord)
\r
3634 local qv,rt,newqv;
\r
3637 newqv:=doRem2(qv,subasc,ord);
\r
3638 if newqv<>[] then
\r
3639 if newqv[2]=1 then RETURN([[subasc,1]]);fi;
\r
3641 rt:=[op(rt),newqv];
\r
3646 # a qausi variety is denoted as: [[asc],pol]
\r
3647 # rem=premas(pol,asc,ord)
\r
3648 # return [[asc], rem]
\r
3649 doRem2:=proc(qv,subasc,ord)
\r
3650 local pol,rem,notZero,rt;
\r
3653 rem:=Premas(pol,Inverse(subasc),ord);
\r
3654 if rem=0 then rt:=[];
\r
3656 notZero:=Factorlist_chen(rem,ord);
\r
3657 rt:=[subasc,GetProduct(notZero)];
\r
3663 # if 0 return 0 else return 1
\r
3666 if p=0 then rt:=0;
\r
3673 # p=3*(x+y)^2*(x-y)*u; ord=[x,y]; result=[x+y,x-y];
\r
3674 # p=2; result=[1]; p=0; result=[0]
\r
3675 Factorlist_chen:=proc(p,ord)
\r
3676 local i,j,fl,pair,fact,rt;
\r
3677 if Class(p,ord)=0 then rt:=[Get1or0(p)];
\r
3684 if Class(fact,ord)<>0 then
\r
3685 rt:=[op(rt),fact];
\r
3692 #########----------Simplify----------###########
\r
3695 ###----- computation of QV---------- ############
\r
3698 # judge whether or not Zero(ps/ds) is empty
\r
3701 # judge whether or not Zero(ps1/ds1) is included in Zero(ps2/ds2)
\r
3702 # QVInclude:=proc(ps1,ds1,ps2,ds2)
\r
3705 #------Simplify the output of Project--------#
\r
3706 # whether or not QV is included in the union of QVS
\r
3707 # output: 1(yes), 0(not included)
\r
3708 QVSInclude:=proc(QV,QVS,ord)
\r
3709 local D,newQVS,rt,temp,i,ass,proj,ps,ds,newucs;
\r
3710 #if QVS=[] then return 0;fi;
\r
3711 D:=GetProduct(QV[2]);
\r
3713 for i from 1 to nops(QVS) do
\r
3714 newQVS[i]:=[op(newQVS[i][1]),GetProduct(newQVS[i][2])];
\r
3716 ass:=AllSorts(newQVS,ord);
\r
3717 for i from 1 to nops(ass) do
\r
3719 ds:=[D,op(temp[2])];
\r
3720 if temp[1]<>[] then
\r
3721 ps:=[op(QV[1]),op(temp[1])];
\r
3722 proj:=Project(ps,ds,ord,ord);
\r
3723 # case :not empty set
\r
3724 if proj<>[] and proj[1][2][1]<>0 then RETURN(0);fi;
\r
3726 proj:=ProjASC(QV[1],ds,ord,ord);
\r
3727 # case: not empty set
\r
3728 if proj[1][2]<>0 then RETURN(0);fi;
\r
3734 # if every QV in QVS is included in the union of the others
\r
3735 # then expunge it.
\r
3736 Sproject:=proc(QVS,ord)
\r
3737 local i,rt,UQV,len;
\r
3740 for i from 1 to len do
\r
3741 if i=len then UQV:=[]; fi;
\r
3742 UQV:=QVS[i+1..len];
\r
3743 UQV:=[op(rt),op(UQV)];
\r
3744 if UQV=[] then rt:=[QVS[i]];break ;fi;
\r
3745 if QVSInclude(QVS[i],UQV,ord)=0 then
\r
3746 rt:=[op(rt),QVS[i]];
\r
3752 Sproj:=proc(qvs,ord)
\r
3753 local temprt,rt, tempqvs,qv,nozerop;
\r
3755 #change to old form
\r
3757 for nozerop in qv[2] do
\r
3758 tempqvs:=[op(tempqvs), [ qv[1],[nozerop] ] ];
\r
3761 temprt:=Sproject(tempqvs,ord);
\r
3763 #return to new form
\r
3764 for qv in temprt do
\r
3765 rt:=AddQVS(rt,qv);
\r
3770 #------Simplify the output of wsolve--------#
\r
3771 #AllSort([[a1,a3],[c1,c2,c3]]);
\r
3772 #output:[ [[],[c1,a1]], [[],[c2,a1]], [[c3],[a1]], [[a3],[c1]],
\r
3773 # [[a3],[c2]], [[c3,a3],[]] ]
\r
3774 AllSorts:=proc(lists,ord)
\r
3775 local ls,C,ls_len,p,i,reculist,list,onesort,rt;
\r
3779 ls_len:=nops(lists[1]);
\r
3781 C:=Class(ls[ls_len],ord);
\r
3783 if nops(lists)=1 then
\r
3784 for i from 1 to ls_len-1 do
\r
3789 rt:=[op(rt),[[ls[ls_len]],[]]];
\r
3794 reculist:=AllSorts(subsop(1=NULL,lists),ord);
\r
3796 for i from 1 to ls_len-1 do
\r
3797 for list in reculist do
\r
3799 onesort[2]:=[op(onesort[2]),ls[i]];
\r
3800 rt:=[op(rt),onesort];
\r
3804 for list in reculist do
\r
3806 onesort[1]:=[op(onesort[1]),ls[ls_len]];
\r
3807 rt:=[op(rt),onesort];
\r
3813 # whether or not cs is included in the union of ucs
\r
3814 # output: 1(yes), 0(not included)
\r
3815 CSSInclude:=proc(cs,ucs,ord)
\r
3816 local proj,IP,ass,rt,temp,i,ps,ds,newucs;
\r
3817 if ucs=[] then return 0;fi;
\r
3818 IP:=GetIP(cs,ord);
\r
3820 for i from 1 to nops(ucs) do
\r
3821 newucs[i]:=[op(newucs[i]),GetIP(newucs[i],ord)];
\r
3823 ass:=AllSorts(newucs,ord);
\r
3824 for i from 1 to nops(ass) do
\r
3826 ds:=[IP,op(temp[2])];
\r
3827 if temp[1]<>[] then
\r
3828 ps:=[op(cs),op(temp[1])];
\r
3829 proj:=Project(ps,ds,ord,ord);
\r
3830 # case :not empty set
\r
3831 if proj<>[] and proj[1][2][1]<>0 then RETURN(0);fi;
\r
3833 proj:=ProjASC(cs,ds,ord,ord);
\r
3834 # case: not empty set
\r
3835 if proj[1][2]<>0 then RETURN(0);fi;
\r
3842 # if every cs in css is included in the union of the others
\r
3843 # then expunge it.
\r
3844 Swsolve:=proc(css,ord)
\r
3845 local i,rt,newcss,UCS,len;
\r
3847 newcss:=InverseAll(css);
\r
3848 len:=nops(newcss);
\r
3849 for i from 1 to len do
\r
3850 UCS:=newcss[i+1..len];
\r
3851 UCS:=[op(rt),op(UCS)];
\r
3852 if CSSInclude(newcss[i],UCS,ord)=0 then
\r
3853 rt:=[op(rt),newcss[i]];
\r