groebidq.red 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. module groebidq;
  2. % Calculation of ideal quotient using a modified Buchberger algorithm .
  3. % Authors: H . Melenk,H . M . Moeller,W . Neun,July 1988 .
  4. switch groebfac,groebrm,trgroeb,trgroebs,trgroebr,groebstat;
  5. !*groebidqbasis:=t; % Default : basis from idq .
  6. % Variables for counting and numbering .
  7. symbolic procedure groebidq2(p,f);
  8. % Setup all global variables for the Buchberger algorithm;
  9. % printing of statistics .
  10. begin scalar groetime!*,tim1,spac,spac1,p1,
  11. pairsdone!*,!*gsugar;
  12. groetime!*:=time();
  13. vdponepol();% we construct dynamically
  14. hcount!*:=0;pcount!*:=0;mcount!*:=0;fcount!*:=0;bcount!*:=0;
  15. b4count!*:=0;hzerocount!*:=0;basecount!*:=0;
  16. if !*trgroeb then
  17. << prin2 "IDQ Calculation starting ";terprit 2 >>;
  18. spac:=gctime();p1:= groebidq3(p,f);
  19. if !*trgroeb or !*trgroebr or !*groebstat then
  20. << spac1:=gctime()-spac;terpri();
  21. prin2t "statistics for IDQ calculation";
  22. prin2t "==============================";
  23. prin2 " total computing time(including gc): ";
  24. prin2(( tim1:=time())-groetime!*);prin2t " milliseconds ";
  25. prin2 "(time spent for garbage collection: ";prin2 spac1;
  26. prin2t " milliseconds)";terprit 1;
  27. prin2 "H-polynomials total: ";prin2t hcount!*;
  28. prin2 "H-polynomials zero : ";prin2t hzerocount!*;
  29. prin2 "Crit M hits: ";prin2t mcount!*;
  30. prin2 "Crit F hits: ";prin2t fcount!*;
  31. prin2 "Crit B hits: ";prin2t bcount!*;
  32. prin2 "Crit B4 hits: ";prin2t b4count!* >>;
  33. return if !*groebidqbasis then car groebner2(p1,nil)else p1 end;
  34. symbolic procedure groebidq3(g0,fff);
  35. begin scalar result,x,g,d,d1,d2,p,p1,s,h,g99,one,gi;
  36. gi:=g0;fff:=vdpsimpcont fff;
  37. vdpputprop(fff,' number,0); % Assign number 0 .
  38. vdpputprop(fff,' cofact,a2vdp 1);% Assign cofactor 1 .
  39. x:=for each fj in g0 collect
  40. << fj:=vdpenumerate vdpsimpcont fj;
  41. vdpputprop(fj,' cofact,a2vdp 0);% Assign cofactor 0 .
  42. fj >>;
  43. g0:={ fff };
  44. for each fj in x do g0:=vdplsortin(fj,g0);
  45. % ITERATION :
  46. while(d or g0)and not one do
  47. begin if g0 then
  48. << % Take next poly from input .
  49. h:=car g0;g0:=cdr g0;p:={ nil,h,h };>>
  50. else << % Take next poly from pairs .
  51. p:=car d;d:=delete(p,d);s:=idqspolynom(cadr p, caddr p);
  52. idqmess3(p,s);h:=idqsimpcont idqnormalform(s,g99,'tree);
  53. if vdpzero!? h then
  54. << !*trgroeb and groebmess4(p,d);
  55. x:=vdpgetprop(h,'cofact);
  56. if not vdpzero!? x then
  57. if vevzero!? vdpevlmon x then one:= t else
  58. << result:=idqtoresult(x,result);idqmess0 x >>;
  59. >> >>;
  60. if vdpzero!? h then goto bott;
  61. if vevzero!? vdpevlmon h then % Base 1 found .
  62. << idqmess4(p,h);
  63. result:=gi;d:=g0:=nil;goto bott >>;
  64. s:=nil;
  65. % h polynomial is accepted now .
  66. h:=vdpenumerate h;
  67. idqmess4(p,h);
  68. % Construct new critical pairs .
  69. d1:=nil;
  70. for each f in g do
  71. << d1:=groebcplistsortin({ tt(f,h), f,h },d1);
  72. if tt(f,h)=vdpevlmon f then
  73. << g:=delete(f,g);!*trgroeb and groebmess2 f >> >>;
  74. !*trgroeb and groebmess51 d1;
  75. d2:=nil;
  76. while d1 do
  77. << d1:=groebinvokecritf d1;
  78. p1:=car d1;d1:=cdr d1;
  79. if groebbuchcrit4t(cadr p1,caddr p1)
  80. then d2:=append(d2,list p1)
  81. else
  82. << x:=idqdirectelement(cadr p1,caddr p1);
  83. if not vdpzero!? x then
  84. if vevzero!? vdpevlmon x then one:= t else
  85. << idqmess1(x,cadr p1,caddr p1);
  86. result:=idqtoresult(x,result)>> >>;
  87. d1:=groebinvokecritm(p1,d1) >>;
  88. % D:=groebInvokeCritB(h,D);
  89. d:=groebcplistmerge(d,d2);
  90. g:=h . g;
  91. g99:=groebstreeadd(h,g99);
  92. !*trgroeb and groebmess8(g,d);
  93. bott: end;% ITERATION
  94. % Now calculate groebner base from quotient base .
  95. if one then result:=list vdpfmon(a2vbc 1,vevzero());
  96. idqmess2 result;return result end;% MACROLOOP
  97. symbolic procedure idqtoresult(x,r);
  98. % X is a new element for the quotient r,
  99. % is is reduced by r and then added .
  100. << x:=groebsimpcontnormalform groebnormalform(x,r,' sort);
  101. if vdpzero!? x then r else vdplsortin(x,r)>>;
  102. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  103. %
  104. % Reduction of polynomials .
  105. %
  106. symbolic procedure idqnormalform(f,g,type);
  107. % General procedure for reduction of one polynomial from a set;
  108. % f is a polynomial, G is a Set of polynomials either in
  109. % a search tree or in a sorted list;
  110. % type describes the ordering of the set G :
  111. % 'TREE G is a search tree
  112. % 'SORT G is a sorted list
  113. % 'LIST G is a list,but not sorted;
  114. % f has to be reduced modulo G;
  115. % version for idealQuotient : doing side effect calculations for
  116. % the cofactors;only headterm reduction .
  117. begin scalar c,vev,divisor,done,fold;
  118. fold:=f;
  119. while not vdpzero!? f and g do
  120. begin vev:=vdpevlmon f;c:=vdplbc f;
  121. if type='sort then
  122. while g and vevcompless!?(vev,vdpevlmon(car g)) do g:=cdr g;
  123. divisor:=groebsearchinlist(vev,g);
  124. if divisor then done:=t;% True action indicator .
  125. if divisor and !*trgroebs then
  126. << prin2 "//-";prin2 vdpnumber divisor >>;
  127. if divisor then
  128. if !*vdpinteger then f:=idqreduceonestepint(f,nil,c,vev,divisor)
  129. else f:=idqreduceonesteprat(f,nil,c,vev,divisor)
  130. else g:=nil end;
  131. return if done then f else fold % In order to preserve history .
  132. end;
  133. % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
  134. %
  135. % Special reduction procedures .
  136. symbolic procedure idqreduceonestepint(f,dummy,c,vev,g1);
  137. % Reduction step for integer case :
  138. % calculate f=a * f-b * g a,b such that leading term vanishes
  139. % (vev of lvbc g divides vev of lvbc f)
  140. %
  141. % and calculate f1=a * f1;
  142. % return value=f,secondvalue=f1 .
  143. begin scalar vevlcm,a,b,cg,x,fcofa,gcofa;
  144. dummy:=nil;fcofa:=vdpgetprop(f,' cofact);
  145. gcofa:=vdpgetprop(g1,' cofact);vevlcm:=vevdif(vev,vdpevlmon g1);
  146. cg:=vdplbc g1;
  147. % Calculate coefficient factors .
  148. x:=vbcgcd(c,cg);a:=vbcquot(cg,x);
  149. b:=vbcquot(c,x);
  150. f:=vdpilcomb1(vdpred f,a,vevzero(),vdpred g1,vbcneg b,vevlcm);
  151. x:=vdpilcomb1(fcofa,a,vevzero(),gcofa,vbcneg b,vevlcm);
  152. vdpputprop(f,' cofact,x);return f end;
  153. symbolic procedure idqreduceonesteprat(f,dummy,c,vev,g1);
  154. % Reduction step for rational case :
  155. % calculate f=f-g / vdplbc f .
  156. begin scalar x,fcofa,gcofa,vev;
  157. dummy:=nil;fcofa:=vdpgetprop(f,' cofact);
  158. gcofa:=vdpgetprop(g1,' cofact);vev:=vevdif(vev,vdpevlmon g1);
  159. x:=vbcneg vbcquot(c,vdplbc g1);
  160. f:=vdpilcomb1(vdpred f,a2vbc 1,vevzero(),vdpred g1,x,vev);
  161. x:=vdpilcomb1(fcofa,a2vbc 1,vevzero(),gcofa,x,vev);
  162. vdpputprop(f,' cofact,x);return f end;
  163. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  164. %
  165. % Calculation of an S-polynomial and related things .
  166. %
  167. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  168. symbolic procedure idqspolynom(p1,p2);
  169. begin scalar s,ep1,ep2,ep,rp1,rp2,db1,db2,x,
  170. cofac1,cofac2;
  171. if vdpzero!? p1 then return p1;if vdpzero!? p2 then return p2;
  172. cofac1:=vdpgetprop(p1,' cofact);
  173. cofac2:=vdpgetprop(p2,' cofact);
  174. ep1:=vdpevlmon p1;ep2:=vdpevlmon p2;ep:=vevlcm(ep1,ep2);
  175. rp1:=vdpred p1;rp2:=vdpred p2;db1:=vdplbc p1;db2:=vdplbc p2;
  176. if !*vdpinteger then
  177. << x:=vbcgcd(db1,db2);
  178. db1:=vbcquot(db1,x);db2:=vbcquot(db2,x)>>;
  179. ep1:=vevdif(ep,ep1);ep2:=vevdif(ep,ep2);db2:=vbcneg db2;
  180. s:=vdpilcomb1(rp2,db1,ep2,rp1,db2,ep1);
  181. x:=vdpilcomb1(cofac2,db1,ep2,cofac1,db2,ep1);
  182. vdpputprop(s,' cofact,x);return s end;
  183. symbolic procedure idqdirectelement(p1,p2);
  184. % The s-Polynomial is reducable to zero because of
  185. % buchcrit 4 . So we can calculate the corresponing cofactor directly .
  186. ( if vdpzero!? c1 and vdpzero!? c2 then c1
  187. else vdpdif(vdpprod(p1,c2), vdpprod(p2,c1))
  188. )where c1=vdpgetprop(p1,' cofact),
  189. c2=vdpgetprop(p2,' cofact);
  190. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  191. %
  192. % Normailsation with cofactors taken into account .
  193. %
  194. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  195. symbolic procedure idqsimpcont p;
  196. if !*vdpinteger then idqsimpconti p else idqsimpcontr p;
  197. % Routines for integer coefficient case :
  198. % Calculation of contents and dividing all coefficients by it .
  199. symbolic procedure idqsimpconti p;
  200. % Calculate the contents of p and divide all coefficients by it .
  201. begin scalar res,num,cofac;
  202. if vdpzero!? p then return p;
  203. cofac:=vdpgetprop(p,' cofact);num:=car vdpcontenti p;
  204. if not vdpzero!? cofac then num:=vbcgcd(num,car vdpcontenti cofac);
  205. if not vbcplus!? num then num:=vbcneg num;
  206. if not vbcplus!? vdplbc p then num:=vbcneg num;
  207. if vbcone!? num then return p;
  208. res:=vdpreduceconti(p,num,nil);
  209. if not vdpzero!? cofac then cofac:=vdpreduceconti(cofac,num,nil);
  210. res:=vdpputprop(res,' cofact,cofac);
  211. return res end;
  212. % Routines for rational coefficient case :
  213. % calculation of contents and dividing all coefficients by it .
  214. symbolic procedure idqsimpcontr p;
  215. % Calculate the contents of p and divide all coefficients by it .
  216. begin scalar res,cofac;
  217. cofac:=vdpgetprop(p,' cofact);
  218. if vdpzero!? p then return p;
  219. if vbcone!? vdplbc p then return p;
  220. res:=vdpreduceconti(p,vdplbc p,nil);
  221. if not vdpzero!? cofac then
  222. cofac:=vdpreduceconti(cofac,vdplbc p,nil);
  223. res:=vdpputprop(res,' cofact,cofac);return res end;
  224. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  225. %
  226. % Trace messages .
  227. %
  228. symbolic procedure idqmess0 x;
  229. if !*trgroeb then
  230. << prin2t "adding member to intermediate quotient basis:";
  231. vdpprint x;terpri() >>;
  232. symbolic procedure idqmess1(x,p1,p2);
  233. if !*trgroeb then
  234. << prin2 "pair(";prin2 vdpnumber p1;prin2 ",";
  235. prin2 vdpnumber p2;
  236. prin2t ") adding member to intermediate quotient basis:";
  237. vdpprint x;terpri() >>;
  238. symbolic procedure idqmess2 b;
  239. if !*trgroeb then
  240. << prin2t "---------------------------------------------------";
  241. prin2 "the full intermediate base of the ideal quotient is:";
  242. for each x in b do vdpprin3t x;
  243. prin2t "---------------------------------------------------";
  244. terpri() >>;
  245. symbolic procedure idqmess3(p,s);
  246. if !*trgroebs then
  247. << prin2 "S-polynomial from ";groebpairprint p;vdpprint s;
  248. prin2t "with cofactor";vdpprint vdpgetprop(s,' cofact);
  249. groetimeprint();terprit 3 >>;
  250. symbolic procedure idqmess4(p,h);
  251. if car p then % Print for true h-Polys .
  252. << hcount!*:=hcount!* #+ 1;
  253. if !*trgroeb then << terpri();prin2 "H-polynomial ";
  254. prin2 pcount!*;
  255. groebmessff(" from pair(",cadr p,nil);
  256. groebmessff(",",caddr p,")");vdpprint h;
  257. prin2t "with cofactor";vdpprint vdpgetprop(h,' cofact);
  258. groetimeprint() >> >>
  259. else
  260. if !*trgroeb then << % Print for input polys .
  261. prin2t "candidate from input:";
  262. vdpprint h;
  263. groetimeprint() >>;
  264. endmodule;;end;