groebman.red 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. module groebman; % Operators for manipulation of bases and
  2. % polynomials in Groebner style.
  3. fluid '(!*factor !*complex !*exp); % standard REDUCE switch
  4. fluid '( % switches from the user interface
  5. !*groebopt !*groebfac !*groebres !*trgroeb !*trgroebs !*groebrm
  6. !*trgroeb1 !*trgroebr !*groebprereduce groebrestriction!*
  7. !*fullreduction !*groebstat !*groebprot !*gltbasis
  8. !*groebsubs
  9. !*vdpinteger !*vdpmodular % indicating type of algorithm
  10. vdpsortmode!* % term ordering mode
  11. secondvalue!* thirdvalue!* % auxiliary: multiple return values
  12. fourthvalue!*
  13. factortime!* % computing time spent in factoring
  14. factorlvevel!* % bookkeeping of factor tree
  15. pairsdone!* % list of pairs already calculated
  16. probcount!* % counting subproblems
  17. vbccurrentmode!* % current domain for base coeffs.
  18. vbcmodule!* % for modular calculation: current prime
  19. );
  20. global '(groebrestriction % interface: name of function
  21. groebresmax % maximum number of internal results
  22. gvarslast % output: variable list
  23. groebprotfile
  24. gltb
  25. );
  26. flag ('(groebrestriction groebresmax gvarslast groebprotfile
  27. gltb),'share);
  28. % variables for counting and numbering
  29. fluid '(hcount!* pcount!* mcount!* fcount!* bcount!* b4count!*
  30. basecount!* hzerocount!*);
  31. % control of the polynomial arithmetic actually loaded
  32. fluid '(currentvdpmodule!*);
  33. symbolic procedure gsorteval pars;
  34. % reformat a polynomial or a list of polynomials by a distributive
  35. % ordering; a list will be sorted and zeros are elimiated
  36. begin scalar vars,u,v,w,oldorder,nolist,!*factor,!*exp,!*gsugar;
  37. integer n,pcount!*; !*exp := t;
  38. n := length pars;
  39. u := reval car pars;
  40. v := if n>1 then reval cadr pars else nil;
  41. if not eqcar(u,'list) then
  42. <<nolist := t; u := list('list,u)>>;
  43. w := for each j in groerevlist u
  44. collect if eqexpr j then !*eqn2a j else j;
  45. vars :=vars := groebnervars(w,v);
  46. if not vars then vdperr 'gsort;
  47. oldorder := vdpinit vars;
  48. !*vdpinteger :=nil;
  49. w := for each j in w collect a2vdp j;
  50. w := vdplsort w;
  51. w := for each x in w collect vdp2a x;
  52. while member(0,w) do w := delete(0,w);
  53. setkorder oldorder;
  54. return if nolist and w then car w else 'list . w;
  55. end;
  56. put('gsort,'psopfn,'gsorteval);
  57. symbolic procedure gspliteval pars;
  58. % split a polynomial into leading monomial and reductum;
  59. begin scalar vars,x,u,v,w,oldorder,!*factor,!*exp,!*gsugar;
  60. integer n,pcount!*; !*exp := t;
  61. n := length pars;
  62. u := reval car pars;
  63. v := if n>1 then reval cadr pars else nil;
  64. u := list('list,u);
  65. w := for each j in groerevlist u
  66. collect if eqexpr j then !*eqn2a j else j;
  67. vars :=vars := groebnervars(w,v);
  68. if not vars then vdperr 'gsplit;
  69. oldorder := vdpinit vars;
  70. !*vdpinteger :=nil;
  71. w := a2vdp car w;
  72. if vdpzero!? w then x := w else
  73. <<x := vdpfmon(vdplbc w,vdpevlmon w);
  74. w := vdpred w>>;
  75. w := list('list,vdp2a x,vdp2a w);
  76. setkorder oldorder;
  77. return w;
  78. end;
  79. put('gsplit,'psopfn,'gspliteval);
  80. symbolic procedure gspolyeval pars;
  81. % calculate the S Polynomial from two given polynomials
  82. begin scalar vars,u,u1,u2,v,w,oldorder,!*factor,
  83. !*exp,!*gsugar;
  84. integer n,pcount!*; !*exp := t;
  85. n := length pars;
  86. if n<2 or n#>3 then
  87. rerror(groebnr2,1,"GSpoly, illegal number or parameters");
  88. u1:= car pars; u2:= cadr pars;
  89. u := list('list,u1,u2);
  90. v := if n>2 then groerevlist caddr pars else nil;
  91. w := for each j in groerevlist u
  92. collect if eqexpr j then !*eqn2a j else j;
  93. vars := vars := groebnervars(w,v);
  94. if not vars then vdperr 'gspoly;
  95. groedomainmode();
  96. oldorder := vdpinit vars;
  97. w := for each j in w collect f2vdp numr simp j;
  98. w := vdp2a groebspolynom3 (car w,cadr w);
  99. setkorder oldorder;
  100. return w;
  101. end;
  102. put('gspoly,'psopfn,'gspolyeval);
  103. symbolic procedure gvarseval u;
  104. % u is a list of polynomials; gvars extracts the variables from u
  105. begin integer n; scalar v,!*factor,!*exp,!*gsugar; !*exp := t;
  106. n := length u;
  107. v := for each j in groerevlist reval car u collect
  108. if eqexpr j then !*eqn2a j else j;
  109. v := groebnervars(v,nil);
  110. v := if n= 2 then
  111. intersection (v,groerevlist reval cadr u) else v;
  112. return 'list . v
  113. end;
  114. put('gvars,'psopfn,'gvarseval);
  115. symbolic procedure greduceeval pars;
  116. % Polynomial reduction modulo a Groebner basis driver. u is an
  117. % expression and v a list of expressions. Greduce calculates the
  118. % polynomial u reduced wrt the list of expressions v reduced to a
  119. % groebner basis modulo using the optional caddr argument as the
  120. % order of variables.
  121. % 1 expression to be reduced
  122. % 2 polynomials or equations; base for reduction
  123. % 3 optional: list of variables
  124. begin scalar vars,x,u,v,w,np,oldorder,!*factor,!*groebfac,!*exp;
  125. scalar !*gsugar;
  126. integer n,pcount!*; !*exp := t;
  127. if !*groebprot then groebprotfile := list 'list;
  128. n := length pars;
  129. x := reval car pars;
  130. u := reval cadr pars;
  131. v := if n>2 then reval caddr pars else nil;
  132. w := for each j in groerevlist u
  133. collect if eqexpr j then !*eqn2a j else j;
  134. if null w then rerror(groebnr2,2,"Empty list in Greduce");
  135. vars := groebnervars(w,v);
  136. if not vars then vdperr 'greduce;
  137. oldorder := vdpinit vars;
  138. groedomainmode();
  139. % cancel common denominators
  140. w := for each j in w collect reorder numr simp j;
  141. % optimize varable sequence if desired
  142. if !*groebopt then<< w:=vdpvordopt (w,vars); vars := cdr w;
  143. w := car w; vdpinit vars>>;
  144. w := for each j in w collect f2vdp j;
  145. if !*groebprot then w := for each j in w collect vdpenumerate j;
  146. if not !*vdpinteger then
  147. <<np := t;
  148. for each p in w do
  149. np := if np then vdpcoeffcientsfromdomain!? p
  150. else nil;
  151. if not np then <<!*vdpmodular:= nil; !*vdpinteger := t>>;
  152. >>;
  153. w := groebner2(w,nil);
  154. x := a2vdp x;
  155. if !*groebprot then
  156. <<w := for each j in w collect vdpenumerate j;
  157. groebprotsetq('candidate,vdp2a x);
  158. for each j in w do groebprotsetq(mkid('poly,vdpnumber j),
  159. vdp2a j)>>;
  160. w := car w;
  161. !*vdpinteger := nil;
  162. w := groebnormalform(x , w, 'sort);
  163. w := vdp2a w;
  164. setkorder oldorder;
  165. gvarslast := 'list . vars;
  166. return if w then w else 0;
  167. end;
  168. put('greduce,'psopfn,'greduceeval);
  169. % preduceeval moved to groesolv.red
  170. put('preduce,'psopfn,'preduceeval);
  171. endmodule;
  172. end;