ideals.red 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. module ideals; % operators for polynomial ideals.
  2. % Author: Herbert Melenk.
  3. % Copyright (c) 1992 The RAND Corporation and Konrad-Zuse-Zentrum.
  4. % All rights reserved.
  5. create!-package('(ideals),'(contrib groebner));
  6. imports groebner;
  7. load!-package 'groebner;
  8. fluid '(gb!-list!*);
  9. global '(id!-vars!*);
  10. share id!-vars!*;
  11. symbolic procedure i!-setting u;
  12. begin scalar o;
  13. o := id!-vars!*;
  14. id!-vars!* := 'list . for each x in u collect reval x;
  15. gb!-list!* := nil;
  16. return o;
  17. end;
  18. put('i_setting,'psopfn,'i!-setting);
  19. algebraic operator I;
  20. symbolic procedure ideal2list u;
  21. 'list . cdr test!-ideal u;
  22. symbolic operator ideal2list;
  23. symbolic procedure GB u;
  24. begin scalar v,w;
  25. u:= test!-ideal reval u;
  26. v:={u,id!-vars!*,vdpsortmode!*};
  27. w:=assoc(v,gb!-list!*);
  28. return if w then cdr w else GB!-new u;
  29. end;
  30. symbolic procedure GB!-new u;
  31. begin scalar v,w;
  32. u:= test!-ideal reval u;
  33. v:={u,id!-vars!*,vdpsortmode!*};
  34. w:='I . cdr groebnereval{'list . cdr u,id!-vars!*};
  35. gb!-list!* := (v.w) . gb!-list!*;
  36. gb!-list!* := ((w.cdr v).w) . gb!-list!*;
  37. return w;
  38. end;
  39. symbolic operator GB;
  40. symbolic procedure test!-ideal u;
  41. if not eqcar(id!-vars!*,'list) then
  42. typerr(id!-vars!*,"ideal setting; set variables first")
  43. else
  44. if eqcar(u,'LIST) then 'I.cdr u
  45. else
  46. if not eqcar(u,'I) then typerr(u,"polynomial ideal")
  47. else u;
  48. symbolic procedure idealp u;
  49. eqcar(u,'I) or eqcar(u,'list);
  50. symbolic operator idealp;
  51. newtok '((!. !=) id!-equal);
  52. algebraic operator id!-equal;
  53. infix id!-equal;
  54. precedence id!-equal,=;
  55. symbolic procedure GB!-equal(a,b);
  56. if gb a = gb b then 1 else 0;
  57. symbolic operator GB!-equal;
  58. algebraic << let (~a .= ~b) => GB!-equal(a,b)
  59. when idealp a and idealp b>>;
  60. symbolic procedure GB!-member(p,u);
  61. if 0=preduceeval{p,ideal2list GB u,id!-vars!*} then 1 else 0;
  62. symbolic operator GB!-member;
  63. algebraic operator member;
  64. algebraic << let ~a member ~b => GB!-member(a,b)
  65. when idealp b>>;
  66. symbolic procedure GB!-subset(a,b);
  67. begin scalar q;
  68. q:= t;
  69. a:=cdr test!-ideal reval a;
  70. b:=ideal2list GB b;
  71. for each p in a do
  72. q:=q and 0=preduceeval{p,b,id!-vars!*};
  73. return if q then 1 else 0;
  74. end;
  75. symbolic operator GB!-subset;
  76. algebraic operator subset;
  77. infix subset;
  78. precedence subset,member;
  79. algebraic << let (~a subset ~b) => GB!-subset(a,b)
  80. when idealp a and idealp b>>;
  81. symbolic procedure GB!-plus(a,b);
  82. <<a := cdr test!-ideal reval a;
  83. b := cdr test!-ideal reval b;
  84. gb ('I.append(a,b))
  85. >>;
  86. symbolic operator GB!-plus;
  87. algebraic operator .+;
  88. algebraic << let (~a .+ ~b) => GB!-plus(a,b)
  89. when idealp a and idealp b>>;
  90. symbolic procedure GB!-times(a,b);
  91. <<a := cdr test!-ideal reval a;
  92. b := cdr test!-ideal reval b;
  93. gb ('I.
  94. for each p in a join
  95. for each q in b collect
  96. {'times,p,q})
  97. >>;
  98. symbolic operator GB!-times;
  99. algebraic operator .*;
  100. algebraic << let (~a .* ~b) => GB!-times(a,b)
  101. when idealp a and idealp b>>;
  102. symbolic procedure GB!-intersect(a,b);
  103. begin scalar tt,oo,q,v;
  104. tt:='!-!-t; v:= id!-vars!*;
  105. oo := eval '(torder '(lex));
  106. a := cdr test!-ideal reval a;
  107. b := cdr test!-ideal reval b;
  108. q:='I. append(
  109. for each p in a collect {'times,tt,p},
  110. for each p in b collect {'times,{'difference,1,tt},p});
  111. id!-vars!* := 'list . tt. cdr id!-vars!*;
  112. q:= errorset({'gb,mkquote q},nil,!*backtrace);
  113. id!-vars!* := v;
  114. eval{'torder,mkquote{oo}};
  115. if errorp q then rederr "ideal intersection failed";
  116. q:=for each p in cdar q join if not smemq(tt,p) then {p};
  117. return gb('I . q);
  118. end;
  119. symbolic operator GB!-intersect;
  120. algebraic operator intersection;
  121. algebraic << let intersection (~a , ~b) => GB!-intersect(a,b)
  122. when idealp a and idealp b>>;
  123. newtok '((!. !:) id!-quotient);
  124. algebraic operator id!-quotient;
  125. infix id!-quotient;
  126. precedence id!-quotient,/;
  127. symbolic procedure GB!-quotient(a,b);
  128. <<a := test!-ideal reval a;
  129. b := test!-ideal reval b;
  130. GB!-quotient1(a,cdr b)>>;
  131. symbolic procedure GB!-quotient1(a,b);
  132. begin scalar q;
  133. q:='I.cdr idquotienteval{ideal2list a,car b,id!-vars!*};
  134. return if null cdr b then q else
  135. GB!-intersect(q,GB!-quotient1(a,cdr b));
  136. end;
  137. symbolic operator GB!-quotient;
  138. algebraic operator over;
  139. algebraic << let (~a ./ ~b) => GB!-quotient(a,b)
  140. when idealp a and idealp b>>;
  141. algebraic << let (~a .: ~b) => GB!-quotient(a,b)
  142. when idealp a and idealp b>>;
  143. endmodule;
  144. end;