ideals.red 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. imports idquotienteval, groebnereval, preduceeval, torder ;
  12. exports gb, gb!-equal, gb!-itersect, gb!-member, gb!-quotient, gb!-plus,
  13. gb!-subset, gb!-times, i!-setting, idealp, ideal2list, id!-equal, id!-quotient,
  14. intersection, member, over, subset ;
  15. symbolic procedure i!-setting u;
  16. begin scalar o;
  17. o := id!-vars!*;
  18. id!-vars!* := 'list . for each x in u collect reval x;
  19. gb!-list!* := nil; return o end;
  20. put('i_setting,'psopfn,'i!-setting);
  21. algebraic operator i;
  22. symbolic procedure ideal2list u; 'list . cdr test!-ideal u;
  23. symbolic operator ideal2list;
  24. symbolic procedure gb u;
  25. begin scalar v,w;
  26. u:= test!-ideal reval u;
  27. v:={u,id!-vars!*,vdpsortmode!*};
  28. w:=assoc(v,gb!-list!*);
  29. return if w then cdr w else gb!-new u 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!*; return w end;
  37. symbolic operator gb;
  38. symbolic procedure test!-ideal u;
  39. if not eqcar(id!-vars!*,'list) then
  40. typerr(id!-vars!*,"ideal setting; set variables first") else
  41. if eqcar(u,'list) then 'i.cdr u else
  42. if not eqcar(u,'i) then typerr(u,"polynomial ideal") else u;
  43. symbolic procedure idealp u; eqcar(u,'i) or eqcar(u,'list);
  44. symbolic operator idealp;
  45. newtok '((!. !=) id!-equal);
  46. algebraic operator id!-equal;
  47. infix id!-equal;
  48. precedence id!-equal,=;
  49. symbolic procedure gb!-equal(a,b); if gb a = gb b then 1 else 0;
  50. symbolic operator gb!-equal;
  51. algebraic <<let (~a .= ~b) => gb!-equal(a,b) when idealp a and idealp b>>;
  52. symbolic procedure gb!-member(p,u);
  53. if 0=preduceeval{p,ideal2list gb u,id!-vars!*} then 1 else 0;
  54. symbolic operator gb!-member;
  55. algebraic operator member;
  56. algebraic <<let ~a member ~b => gb!-member(a,b) when idealp b>>;
  57. symbolic procedure gb!-subset(a,b);
  58. begin scalar q; q:= t; a:=cdr test!-ideal reval a;
  59. b:=ideal2list gb b; for each p in a do
  60. q:=q and 0=preduceeval{p,b,id!-vars!*};
  61. return if q then 1 else 0 end;
  62. symbolic operator gb!-subset;
  63. algebraic operator subset;
  64. infix subset;
  65. precedence subset,member;
  66. algebraic <<let (~a subset ~b) => gb!-subset(a,b) when idealp a and idealp b>>;
  67. symbolic procedure gb!-plus(a,b);
  68. <<a := cdr test!-ideal reval a;
  69. b := cdr test!-ideal reval b; gb ('i.append(a,b)) >>;
  70. symbolic operator gb!-plus;
  71. algebraic operator .+;
  72. algebraic << let (~a .+ ~b) => gb!-plus(a,b) when idealp a and idealp b>>;
  73. symbolic procedure gb!-times(a,b);
  74. <<a := cdr test!-ideal reval a; b := cdr test!-ideal reval b;
  75. gb ('i. for each p in a join for each q in b collect {'times,p,q}) >>;
  76. symbolic operator gb!-times;
  77. algebraic operator .*;
  78. algebraic << let (~a .* ~b) => gb!-times(a,b) when idealp a and idealp b>>;
  79. symbolic procedure gb!-intersect(a,b);
  80. begin scalar tt,oo,q,v;
  81. tt:='!-!-t; v:= id!-vars!*;
  82. oo := eval '(torder '(lex));
  83. a := cdr test!-ideal reval a;
  84. b := cdr test!-ideal reval b;
  85. q:='i. append(
  86. for each p in a collect {'times,tt,p},
  87. for each p in b collect {'times,{'difference,1,tt},p});
  88. id!-vars!* := 'list . tt. cdr id!-vars!*;
  89. q:= errorset({'gb,mkquote q},nil,!*backtrace);
  90. id!-vars!* := v;
  91. eval{'torder,mkquote{oo}};
  92. if errorp q then rederr "ideal intersection failed";
  93. q:=for each p in cdar q join if not smemq(tt,p) then {p};
  94. return gb('i . q) end;
  95. symbolic operator gb!-intersect;
  96. algebraic operator intersection;
  97. algebraic <<let intersection (~a , ~b) => gb!-intersect(a,b)
  98. when idealp a and idealp b>>;
  99. newtok '((!. !:) id!-quotient);
  100. algebraic operator id!-quotient;
  101. infix id!-quotient;
  102. precedence id!-quotient,/;
  103. symbolic procedure gb!-quotient(a,b);
  104. <<a := test!-ideal reval a; b := test!-ideal reval b; gb!-quotient1(a,cdr b)>>;
  105. symbolic procedure gb!-quotient1(a,b);
  106. begin scalar q; q:='i.cdr idquotienteval{ideal2list a,car b,id!-vars!*};
  107. return if null cdr b then q else gb!-intersect(q,gb!-quotient1(a,cdr b)) end;
  108. symbolic operator gb!-quotient;
  109. algebraic operator over;
  110. algebraic <<let (~a ./ ~b) => gb!-quotient(a,b) when idealp a and idealp b>>;
  111. algebraic <<let (~a .: ~b) => gb!-quotient(a,b) when idealp a and idealp b>>;
  112. endmodule;;end;