hf.red 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. module hf;
  2. COMMENT
  3. ###################################
  4. ## ##
  5. ## WEIGHTED HILBERT SERIES ##
  6. ## ##
  7. ###################################
  8. This module supports (weighted) Hilbert series computations and
  9. related topics. It contains
  10. - Two algorithms computing Hilbert series of ideals and
  11. modules.
  12. Lit.:
  13. [BS] Bayer, Stillman : J. Symb. Comp. 14 (1992), 31 - 50.
  14. [BCRT] Bigatti, Conti, Robbiano, Traverso . LNCS 673 (1993), 76 - 88.
  15. The version of the algorithm is chosen through the 'hf!=hf entry on
  16. the property list of 'cali.
  17. END COMMENT;
  18. % Choosing the version of the algorithm and first initialization :
  19. put('cali,'hf!=hf,'hf!=whilb1);
  20. symbolic operator hftestversion;
  21. symbolic procedure hftestversion n;
  22. if member(n,{1,2}) then
  23. put('cali,'hf!=hf,mkid('hf!=whilb,n));
  24. % --- first variant : [BS]
  25. symbolic procedure hf!=whilb1(m,w);
  26. % Compute the weighted Hilbert series of the moideal m by the rule
  27. % H(m + (M)) = H((M)) - t^ec(m) * H((M):m)
  28. if null m then dp_fi 1
  29. else begin scalar m1,m2;
  30. for each x in m do
  31. if mo_linear x then m1:=x . m1 else m2:=x . m2;
  32. if null m2 then return hf!=whilbmon(m1,w)
  33. else if null cdr m2 then return hf!=whilbmon(car m2 . m1,w)
  34. else if hf!=powers m2 then return hf!=whilbmon(append(m1,m2),w)
  35. else return dp_prod(hf!=whilbmon(m1,w),
  36. dp_diff(hf!=whilb1(cdr m2,w),
  37. dp_times_mo(mo_wconvert(car m2,w),
  38. hf!=whilb1(moid_quot(cdr m2,car m2),w))));
  39. end;
  40. symbolic procedure hf!=whilbmon(m,w);
  41. % Returns the product of the converted dpolys 1 - mo for the
  42. % monomials mo in m.
  43. if null m then dp_fi 1
  44. else begin scalar p;
  45. m:=for each x in m collect
  46. dp_sum(dp_fi 1,list dp_term(bc_fi(-1),mo_wconvert(x,w)));
  47. p:=car m;
  48. for each x in cdr m do p:=dp_prod(p,x);
  49. return p;
  50. end;
  51. symbolic procedure hf!=powers m;
  52. % m contains only powers of variables.
  53. if null m then t
  54. else (length mo_support car m<2) and hf!=powers cdr m;
  55. Comment
  56. Second variant : by induction on the number of variables using the
  57. exactness of the sequence
  58. 0 --> S/(I:(x))[-deg x] --> S/I --> S/(I+(x)) --> 0
  59. [BCRT] do even better, choosing x not as variable, but as splitting
  60. monomial. I hope to return to that later on.
  61. end Comment;
  62. symbolic procedure hf!=whilb2(m,w);
  63. if null m then dp_fi 1
  64. else begin scalar m1,m2,x,p;
  65. for each x in m do
  66. if mo_linear x then m1:=x . m1 else m2:=x . m2;
  67. if null m2 then return hf!=whilbmon(m1,w)
  68. else if null cdr m2 then return hf!=whilbmon(car m2 . m1,w)
  69. else if hf!=powers m2 then return hf!=whilbmon(append(m1,m2),w)
  70. else begin scalar x;
  71. x:=mo_from_a car mo_support car m2;
  72. p:=dp_prod(hf!=whilbmon(m1,w),
  73. dp_sum(hf!=whilb2(moid_red(x . m2),w),
  74. dp_times_mo(mo_wconvert(x,w),
  75. hf!=whilb2(moid_quot(m2,x),w))))
  76. end;
  77. return p;
  78. end;
  79. % -------- Weighted Hilbert series from a free resolution --------
  80. symbolic procedure hf_whilb3(u,w);
  81. % Weighted Hilbert series numerator from the resolution u.
  82. begin scalar sgn,p; sgn:=t;
  83. for each x in u do
  84. << if sgn then p:=dp_sum(p,hf!=whilb3(x,w))
  85. else p:=dp_diff(p,hf!=whilb3(x,w));
  86. sgn:=not sgn;
  87. >>;
  88. return p;
  89. end;
  90. symbolic procedure hf!=whilb3(u,w);
  91. % Convert column degrees of the dpmat u to a generating polynomial.
  92. (if length c = dpmat_cols u then
  93. begin scalar p;
  94. for each x in c do
  95. p:=dp_sum(p,{dp_term(bc_fi 1,mo_wconvert(cdr x,w))});
  96. return p
  97. end else dp_fi max(1,dpmat_cols u))
  98. where c:=dpmat_coldegs u;
  99. % ------- The common interface ----------------
  100. symbolic procedure hf_whilb(m,wt);
  101. % Returns the weighted Hilbert series numerator of the dpmat m as
  102. % a dpoly using the internal Hilbert series computation
  103. % get('cali,'hf!=hf) for moideals. m must be a Groebner basis.
  104. (begin scalar fn,w,lt,p,p1; integer i;
  105. if null(fn:=get('cali,'hf!=hf)) then
  106. rederr"No version for the Hilbert function algorithm chosen";
  107. if dpmat_cols m = 0 then
  108. return apply2(fn,moid_from_bas dpmat_list m,wt);
  109. lt:=moid_from_dpmat m;
  110. for i:=1:dpmat_cols m do
  111. << p1:=atsoc(i,lt);
  112. if null p1 then rederr"WHILB with wrong leading term list"
  113. else p1:=apply2(fn,cdr p1,wt);
  114. w:=atsoc(i,cali!=degrees);
  115. if w then p1:=dp_times_mo(mo_wconvert(cdr w,wt),p1);
  116. p:=dp_sum(p,p1);
  117. >>;
  118. return p;
  119. end) where cali!=degrees:=dpmat_coldegs m;
  120. symbolic procedure hf!=whilb2hs(h,w);
  121. % Converts the Hilbert series numerator h into a rational expression
  122. % with denom = prod ( 1-w(x) | x in ringvars ) and cancels common
  123. % factors. Uses gcdf and returns a s.q.
  124. begin scalar a,g,den,num;
  125. num:=numr simp dp_2a h; % This is the numerator as a s.f.
  126. den:=1;
  127. for each x in ring_names cali!=basering do
  128. << a:=numr simp dp_2a hf!=whilbmon({mo_from_a x},w);
  129. g:=gcdf!*(num,a);
  130. num:=quotf(num,g); den:=multf(den,quotf(a,g));
  131. >>;
  132. return num ./ den;
  133. end;
  134. symbolic procedure weightedhilbertseries!*(m,w);
  135. % m must be a Gbasis.
  136. hf!=whilb2hs(hf_whilb(m,w),w);
  137. symbolic procedure hf_whs_from_resolution(u,w);
  138. % u must be a resolution.
  139. hf!=whilb2hs(hf_whilb3(u,w),w);
  140. symbolic procedure hilbertseries!* m;
  141. % m must be a Gbasis.
  142. weightedhilbertseries!*(m,{ring_ecart cali!=basering});
  143. % --------- Multiplicity and dimension ---------------------
  144. symbolic procedure hf_mult n;
  145. % Get the sum of the coefficients of the s.f. (car n). For homogeneous
  146. % ideals and "good" weight vectors this is the multiplicity.
  147. prepf absf hf!=sum_up car n;
  148. symbolic procedure hf!=sum_up f;
  149. if numberp f then f else hf!=sum_up car subf(f,list (mvar f . 1));
  150. symbolic procedure hf_dim f;
  151. % Returns the dimension as the pole order at 1 of the HF f.
  152. if domainp denr f then 0
  153. else begin scalar g,x,d; integer n;
  154. f:=denr f; x:=mvar f; n:=0; d:=(((x.1).-1).1);
  155. while null cdr (g:=qremf(f,d)) do
  156. << n:=n+1; f:=car g >>;
  157. return n;
  158. end;
  159. symbolic procedure degree!* m; hf_mult hilbertseries!* m;
  160. % ------- Algebraic Mode Interface for weighted Hilbert series.
  161. symbolic operator weightedhilbertseries;
  162. symbolic procedure weightedhilbertseries(m,w);
  163. % m must be a gbasis, w a list of weight lists.
  164. if !*mode='algebraic then
  165. begin scalar w1,l;
  166. w1:=for each x in cdr reval w collect cdr x;
  167. l:=length ring_names cali!=basering;
  168. for each x in w1 do
  169. if (not numberlistp x) or (length x neq l)
  170. then typerr(w,"weight list");
  171. m:=dpmat_from_a reval m;
  172. l:=mk!*sq weightedhilbertseries!*(m,w1);
  173. return l;
  174. end else weightedhilbertseries!*(m,w);
  175. endmodule; % hf
  176. end;