intf.red 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. module intf;
  2. COMMENT
  3. #####################################
  4. ### ###
  5. ### INTERFACE TO ALGEBRAIC MODE ###
  6. ### ###
  7. #####################################
  8. There are two types of procedures :
  9. The first type takes polynomial lists or polynomial matrices as
  10. input, converts them into dpmats, computes the result and
  11. reconverts it to algebraic mode.
  12. The second type is property driven, i.e. Basis, Gbasis, Syzygies
  13. etc. are attached via properties to an identifier.
  14. For them, the 'ring property watches, that cali!=basering hasn't
  15. changed (including the term order). Otherwise the results must be
  16. reevaluated using setideal(name,name) or setmodule(name,name) since
  17. otherwise results may become wrong.
  18. The switch "noetherian" controls whether the term order satisfies
  19. the chain condition (default is "on") and chooses either the
  20. groebner algorithm or the local standard basis algorithm.
  21. END COMMENT;
  22. % ----- The properties managed upto now ---------
  23. fluid '(intf!=properties);
  24. intf!=properties:='(basis ring gbasis syzygies resolution hs
  25. independentsets);
  26. % --- Some useful common symbolic procedures --------------
  27. symbolic procedure intf!=clean u;
  28. % Removes all properties.
  29. for each x in intf!=properties do remprop(u,x);
  30. symbolic procedure intf_test m;
  31. if (length m neq 1)or(not idp car m) then typerr(m,"identifier");
  32. symbolic procedure intf_get m;
  33. % Get the 'basis.
  34. begin scalar c;
  35. if not (c:=get(m,'basis)) then typerr(m,"dpmat variable");
  36. if not equal(get(m,'ring),cali!=basering) then
  37. rederr"invalid base ring";
  38. cali!=degrees:=dpmat_coldegs c;
  39. return c;
  40. end;
  41. symbolic procedure intf!=set(m,v);
  42. % Attach the dpmat value v to the variable m.
  43. << put(m,'ring,cali!=basering);
  44. put(m,'basis,v);
  45. if dpmat_cols v = 0 then
  46. << put(m,'rtype,'list); put(m,'avalue,'list.{dpmat_2a v})>>
  47. else
  48. <<put(m,'rtype,'matrix); put(m,'avalue,'matrix.{dpmat_2a v})>>;
  49. >>;
  50. % ------ setideal -------------------
  51. put('setideal,'psopfn,'intf!=setideal);
  52. symbolic procedure intf!=setideal u;
  53. % setideal(name,base list)
  54. begin scalar l;
  55. if length u neq 2 then rederr "Syntax : setideal(identifier,ideal)";
  56. if not idp car u then typerr(car u,"ideal name");
  57. l:=reval cadr u;
  58. if not eqcar(l,'list) then typerr(l,"ideal basis");
  59. intf!=clean(car u);
  60. put(car u,'ring,cali!=basering);
  61. put(car u,'basis,l:=dpmat_from_a l);
  62. put(car u,'avalue,'list.{l:=dpmat_2a l});
  63. put(car u,'rtype,'list);
  64. return l;
  65. end;
  66. % --------------- setmodule -----------------------
  67. put('setmodule,'psopfn,'intf!=setmodule);
  68. symbolic procedure intf!=setmodule u;
  69. % setmodule(name,matrix)
  70. begin scalar l;
  71. if length u neq 2 then
  72. rederr "Syntax : setmodule(identifier,module basis)";
  73. if not idp car u then typerr(car u,"module name");
  74. l:=reval cadr u;
  75. if not eqcar(l,'mat) then typerr(l,"module basis");
  76. intf!=clean(car u);
  77. put(car u,'ring,cali!=basering);
  78. put(car u,'basis,dpmat_from_a l);
  79. put(car u,'avalue,'matrix.{l});
  80. put(car u,'rtype,'matrix);
  81. return l;
  82. end;
  83. % ------------ setring ------------------------
  84. put('setring,'psopfn,'intf!=setring);
  85. % Setring(vars,term order degrees,tag <,ecart>) sets the internal
  86. % variable cali!=basering. The term order is at first by the degrees
  87. % and then by the tag. The tag must be LEX or REVLEX.
  88. % If ecart is not supplied the ecart is set to the default, i.e. the
  89. % first degree vector (noetherian degree order) or to (1 1 .. 1).
  90. % The ring may also be supplied as a list of its arguments as e.g.
  91. % output by "getring".
  92. symbolic procedure intf!=setring u;
  93. begin
  94. if length u = 1 then u:=cdr reval car u;
  95. if not memq(length u,'(3 4)) then
  96. rederr "Syntax : setring(vars,term order,tag[,ecart])";
  97. setring!* ring_from_a ('list . u);
  98. return ring_2a cali!=basering;
  99. end;
  100. % ----------- getring --------------------
  101. put('getring,'psopfn,'intf!=getring);
  102. % Get the base ring of an object as the algebraic list
  103. % {vars,tord,tag,ecart}.
  104. symbolic procedure intf!=getring u;
  105. if null u then ring_2a cali!=basering
  106. else begin scalar c; c:=get(car u,'ring);
  107. if null c then typerr(car u,"dpmat variable");
  108. return ring_2a c;
  109. end;
  110. % ------- The algebraic interface -------------
  111. symbolic operator ideal2mat;
  112. symbolic procedure ideal2mat m;
  113. % Convert the list of polynomials m into a matrix column.
  114. if !*mode='symbolic then rederr"only for algebraic mode"
  115. else if not eqcar(m,'list) then typerr(m,'list)
  116. else 'mat . for each x in cdr m collect {x};
  117. symbolic operator mat2list;
  118. symbolic procedure mat2list m;
  119. % Flatten the matrix m.
  120. if !*mode='symbolic then rederr"only for algebraic mode"
  121. else if not eqcar(m,'mat) then typerr(m,'matrix)
  122. else 'list . for each x in cdr m join for each y in x collect y;
  123. put('setgbasis,'psopfn,'intf!=setgbasis);
  124. symbolic procedure intf!=setgbasis m;
  125. % Say that the basis is already a Gbasis.
  126. begin scalar c;
  127. intf_test m; m:=car m; c:=intf_get m;
  128. put(m,'gbasis,c);
  129. return reval m;
  130. end;
  131. symbolic operator setdegrees;
  132. symbolic procedure setdegrees m;
  133. % Set a term list as actual column degrees. Execute this before
  134. % setmodule to supply a module with prescribed column degrees.
  135. if !*mode='symbolic then rederr"only for algebraic mode"
  136. else begin scalar i,b;
  137. b:=moid_from_a reval m; i:=0;
  138. cali!=degrees:= for each x in b collect <<i:=i+1; i . x>>;
  139. return moid_2a for each x in cali!=degrees collect cdr x;
  140. end;
  141. put('getdegrees,'psopfn,'intf!=getdegrees);
  142. symbolic procedure intf!=getdegrees m;
  143. begin
  144. if m then <<intf_test m; intf_get car m>>;
  145. return moid_2a for each x in cali!=degrees collect cdr x
  146. end;
  147. symbolic operator getecart;
  148. symbolic procedure getecart;
  149. if !*mode='algebraic then makelist ring_ecart cali!=basering
  150. else ring_ecart cali!=basering;
  151. put('gbasis,'psopfn,'intf!=gbasis);
  152. symbolic procedure intf!=gbasis m;
  153. begin scalar c,c1;
  154. intf_test m; m:=car m; c1:=intf_get m;
  155. if (c:=get(m,'gbasis)) then return dpmat_2a c;
  156. c:=gbasis!* c1;
  157. put(m,'gbasis,c);
  158. return dpmat_2a c;
  159. end;
  160. symbolic operator setmonset;
  161. symbolic procedure setmonset m;
  162. if !*mode='algebraic then makelist setmonset!* cdr reval m
  163. else setmonset!* m;
  164. symbolic procedure setmonset!* m;
  165. if subsetp(m,ring_names cali!=basering) then cali!=monset:=m
  166. else typerr(m,"monset list");
  167. symbolic operator getmonset;
  168. symbolic procedure getmonset(); makelist cali!=monset;
  169. put('resolve,'psopfn,'intf!=resolve);
  170. symbolic procedure intf!=resolve m;
  171. begin scalar c,c1,d;
  172. intf_test m; if length m=2 then d:=reval cadr m else d:=10;
  173. m:=car m; c1:=intf_get m;
  174. if ((c:=get(m,'resolution)) and (car c >= d)) then
  175. return makelist for each x in cdr c collect dpmat_2a x;
  176. c:=Resolve!*(c1,d);
  177. put(m,'resolution,d.c);
  178. if not get(m,'syzygies) then put(m,'syzygies,cadr c);
  179. return makelist for each x in c collect dpmat_2a x;
  180. end;
  181. put('syzygies,'psopfn,'intf!=syzygies);
  182. symbolic procedure intf!=syzygies m;
  183. begin scalar c,c1;
  184. intf_test m; m:=car m; c1:=intf_get m;
  185. if (c:=get(m,'syzygies)) then return dpmat_2a c;
  186. c:=syzygies!* c1;
  187. put(m,'syzygies,c);
  188. return dpmat_2a c;
  189. end;
  190. put('indepvarsets,'psopfn,'intf!=indepvarsets);
  191. symbolic procedure intf!=indepvarsets m;
  192. begin scalar c;
  193. intf_test m; m:=car m; intf_get m;
  194. if (c:=get(m,'independentsets)) then
  195. return makelist for each x in c collect makelist x;
  196. if not (c:=get(m,'gbasis)) then
  197. put(m,'gbasis,c:=gbasis!* get(m,'basis));
  198. c:=indepvarsets!* c;
  199. put(m,'independentsets,c);
  200. return makelist for each x in c collect makelist x;
  201. end;
  202. put('getleadterms,'psopfn,'intf_getleadterms);
  203. symbolic procedure intf_getleadterms m;
  204. begin scalar c;
  205. intf_test m; m:=car m; intf_get m;
  206. if not (c:=get(m,'gbasis)) then
  207. put(m,'gbasis,c:=gbasis!* get(m,'basis));
  208. c:=getleadterms!* c;
  209. return dpmat_2a c;
  210. end;
  211. put('hilbertseries,'psopfn,'intf!=hilbertseries);
  212. symbolic procedure intf!=hilbertseries m;
  213. % Returns the Hilbert series of m.
  214. begin scalar c;
  215. intf_test m; m:=car m; intf_get m;
  216. if (c:=get(m,'hs)) then return mk!*sq c;
  217. if not(c:=get(m,'gbasis)) then
  218. put(m,'gbasis,c:=gbasis!* get(m,'basis));
  219. put(m,'hs,c:=hilbertseries!* c);
  220. return mk!*sq c;
  221. end;
  222. put('degree,'psopfn,'intf_getmult);
  223. symbolic procedure intf_getmult m;
  224. % Returns the multiplicity of m.
  225. begin scalar c;
  226. intf_test m; m:=car m; intf_get m;
  227. if (c:=get(m,'hs)) then return hf_mult c;
  228. if not(c:=get(m,'gbasis)) then
  229. put(m,'gbasis,c:=gbasis!* get(m,'basis));
  230. put(m,'hs,c:=hilbertseries!* c);
  231. return hf_mult c;
  232. end;
  233. put('dim,'psopfn,'intf!=dim);
  234. put('codim,'psopfn,'intf!=codim);
  235. symbolic procedure intf!=dim m;
  236. % Returns the dimension of coker m.
  237. begin scalar c;
  238. intf_test m; m:=car m; intf_get m;
  239. if (c:=get(m,'hs)) then return hf_dim c;
  240. if (c:=get(m,'independentsets)) then return length moid_max c;
  241. if not(c:=get(m,'gbasis)) then
  242. put(m,'gbasis,c:=gbasis!* get(m,'basis));
  243. c:=indepvarsets!* c; put(m,'independentsets,c);
  244. return length moid_max c;
  245. end;
  246. symbolic procedure intf!=codim m;
  247. % Returns the codimension of coker m.
  248. length ring_names cali!=basering - intf!=dim m;
  249. put('BettiNumbers,'psopfn,'intf!=BettiNumbers);
  250. symbolic procedure intf!=BettiNumbers m;
  251. begin scalar c;
  252. intf_test m; m:=car m; intf_get m;
  253. if (c:=get(m,'resolution)) then return makelist BettiNumbers!* cdr c
  254. else rederr"Compute a resolution first";
  255. end;
  256. put('GradedBettiNumbers,'psopfn,'intf!=GradedBettiNumbers);
  257. symbolic procedure intf!=GradedBettiNumbers m;
  258. begin scalar c;
  259. intf_test m; m:=car m; intf_get m;
  260. if (c:=get(m,'resolution)) then return
  261. makelist for each x in GradedBettiNumbers!* cdr c collect makelist x
  262. else rederr"Compute a resolution first";
  263. end;
  264. put('degsfromresolution,'psopfn,'intf!=degsfromresolution);
  265. symbolic procedure intf!=degsfromresolution m;
  266. begin scalar c;
  267. intf_test m; m:=car m;
  268. if not equal(get(m,'ring),cali!=basering) then
  269. rederr"invalid base ring";
  270. if not (c:=get(m,'resolution)) then
  271. rederr"compute a resolution first";
  272. return makelist for each x in cdr c collect
  273. moid_2a for each y in dpmat_coldegs x collect cdr y;
  274. end;
  275. symbolic operator sieve;
  276. symbolic procedure sieve(m,vars);
  277. % Sieve out all base elements from m containing one of the variables
  278. % in vars in their leading term.
  279. if !*mode='algebraic then
  280. dpmat_2a dpmat_sieve(dpmat_from_a reval m,cdr vars,nil)
  281. else dpmat_sieve(m,vars,nil);
  282. endmodule; % intf
  283. end;