groebman.red 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. module groebman; % Operators for manipulation of bases and
  2. % polynomials in Groebner style.
  3. flag ('(groebrestriction groebresmax gvarslast groebprotfile gltb),'share);
  4. % control of the polynomial arithmetic actually loaded
  5. symbolic procedure gsorteval pars;
  6. % reformat a polynomial or a list of polynomials by a distributive
  7. % ordering; a list will be sorted and zeros are elimiated
  8. begin scalar vars,u,v,w,oldorder,nolist,!*factor,!*exp,!*gsugar;
  9. integer n,pcount!*;!*exp:=t;
  10. n:=length pars;
  11. u:=reval car pars;
  12. v:=if n>1 then reval cadr pars else nil;
  13. if not eqcar(u,'list) then
  14. <<nolist:=t;u:=list('list,u)>>;
  15. w:= for each j in groerevlist u
  16. collect if eqexpr j then !*eqn2a j else j;
  17. vars:=groebnervars(w,v);
  18. if not vars then vdperr 'gsort;
  19. oldorder:= vdpinit vars;
  20. !*vdpinteger:=nil;
  21. w:=for each j in w collect a2vdp j;
  22. w:=vdplsort w;
  23. w:=for each x in w collect vdp2a x;
  24. while member(0,w) do w:=delete(0,w);
  25. setkorder oldorder;
  26. return if nolist and w then car w else 'list.w end;
  27. put('gsort,'psopfn,'gsorteval);
  28. symbolic procedure gspliteval pars;
  29. % split a polynomial into leading monomial and reductum;
  30. begin scalar vars,x,u,v,w,oldorder,!*factor,!*exp,!*gsugar;
  31. integer n,pcount!*;!*exp:=t;
  32. n:=length pars;
  33. u:=reval car pars;
  34. v:=if n>1 then reval cadr pars else nil;
  35. u:=list('list,u);
  36. w:=for each j in groerevlist u
  37. collect if eqexpr j then !*eqn2a j else j;
  38. vars:=groebnervars(w,v);
  39. if not vars then vdperr 'gsplit;
  40. oldorder:=vdpinit vars;
  41. !*vdpinteger:=nil;
  42. w:=a2vdp car w;
  43. if vdpzero!? w then x:=w else
  44. <<x:=vdpfmon(vdplbc w,vdpevlmon w);w:=vdpred w>>;
  45. w:={'list,vdp2a x,vdp2a w};
  46. setkorder oldorder;return w end;
  47. put('gsplit,'psopfn,'gspliteval);
  48. symbolic procedure gspolyeval pars;
  49. % calculate the S Polynomial from two given polynomials
  50. begin scalar vars,u,u1,u2,v,w,oldorder,!*factor,!*exp,!*gsugar;
  51. integer n,pcount!*;!*exp:=t;
  52. n:=length pars;
  53. if n<2 or n#>3 then
  54. rerror(groebnr2,1,"gspoly, illegal number or parameters");
  55. u1:= car pars;u2:= cadr pars;
  56. u:={'list,u1,u2};
  57. v:=if n>2 then groerevlist caddr pars else nil;
  58. w:=for each j in groerevlist u
  59. collect if eqexpr j then !*eqn2a j else j;
  60. vars:=groebnervars(w,v);
  61. if not vars then vdperr 'gspoly;
  62. groedomainmode();
  63. oldorder:=vdpinit vars;
  64. w:=for each j in w collect f2vdp numr simp j;
  65. w:=vdp2a groebspolynom3 (car w,cadr w);
  66. setkorder oldorder;return w end;
  67. put('gspoly,'psopfn,'gspolyeval);
  68. symbolic procedure gvarseval u;
  69. % u is a list of polynomials; gvars extracts the variables from u
  70. begin integer n;scalar v,!*factor,!*exp,!*gsugar;!*exp:=t;
  71. n:=length u;
  72. v:=for each j in groerevlist reval car u collect
  73. if eqexpr j then !*eqn2a j else j;
  74. v:=groebnervars(v,nil);
  75. v:=if n=2 then
  76. intersection (v,groerevlist reval cadr u) else v;
  77. return 'list.v end;
  78. put('gvars,'psopfn,'gvarseval);
  79. symbolic procedure greduceeval pars;
  80. % Polynomial reduction modulo a Groebner basis driver. u is an
  81. % expression and v a list of expressions. Greduce calculates the
  82. % polynomial u reduced wrt the list of expressions v reduced to a
  83. % groebner basis modulo using the optional caddr argument as the
  84. % order of variables.
  85. % 1 expression to be reduced
  86. % 2 polynomials or equations; base for reduction
  87. % 3 optional: list of variables
  88. begin scalar vars,x,u,v,w,np,oldorder,!*factor,!*groebfac,!*exp;
  89. scalar !*gsugar;
  90. integer n,pcount!*;!*exp:=t;
  91. if !*groebprot then groebprotfile:={'list};
  92. n:=length pars;
  93. x:=reval car pars;
  94. u:=reval cadr pars;
  95. v:=if n>2 then reval caddr pars else nil;
  96. w:=for each j in groerevlist u
  97. collect if eqexpr j then !*eqn2a j else j;
  98. if null w then rerror(groebnr2,2,"Empty list in greduce");
  99. vars:=groebnervars(w,v);
  100. if not vars then vdperr 'greduce;
  101. oldorder:=vdpinit vars;
  102. groedomainmode();
  103. % cancel common denominators
  104. w:=for each j in w collect reorder numr simp j;
  105. % optimize varable sequence if desired
  106. if !*groebopt then<<w:=vdpvordopt (w,vars);vars:=cdr w;
  107. w:=car w;vdpinit vars>>;
  108. w:=for each j in w collect f2vdp j;
  109. if !*groebprot then w:=for each j in w collect vdpenumerate j;
  110. if not !*vdpinteger then
  111. <<np:=t;
  112. for each p in w do
  113. np:=if np then vdpcoeffcientsfromdomain!? p
  114. else nil;
  115. if not np then <<!*vdpmodular:= nil;!*vdpinteger:=t>> >>;
  116. w:=groebner2(w,nil);x:=a2vdp x;
  117. if !*groebprot then
  118. <<w:=for each j in w collect vdpenumerate j;
  119. groebprotsetq('candidate,vdp2a x);
  120. for each j in w do groebprotsetq(mkid('poly,vdpnumber j),
  121. vdp2a j)>>;
  122. w:=car w;
  123. !*vdpinteger:=nil;
  124. w:=groebnormalform(x,w,'sort);
  125. w:=vdp2a w;
  126. setkorder oldorder;
  127. gvarslast:='list.vars;
  128. return if w then w else 0 end;
  129. put('greduce,'psopfn,'greduceeval);
  130. put('preduce,'psopfn,'preduceeval);
  131. endmodule;;end;