bas.red 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. module bas;
  2. COMMENT
  3. #######################
  4. #### ####
  5. #### IDEAL BASES ####
  6. #### ####
  7. #######################
  8. Ideal bases are lists of vector polynomials (with additional
  9. information), constituting the rows of a dpmat (see below). In a
  10. rep. part there can be stored vectors representing each base element
  11. according to a fixed basis. Usually rep=nil.
  12. Informal syntax :
  13. <bas> ::= list of base elements
  14. <base element> ::= list(nr dpoly length ecart rep)
  15. END COMMENT;
  16. % -------- Reference operators for the base element b ---------
  17. symbolic procedure bas_dpoly b; cadr b;
  18. symbolic procedure bas_dplen b; caddr b;
  19. symbolic procedure bas_nr b; car b;
  20. symbolic procedure bas_dpecart b; cadddr b;
  21. symbolic procedure bas_rep b; nth(b,5);
  22. % ----- Elementary constructors for the base element be --------
  23. symbolic procedure bas_newnumber(nr,be);
  24. % Returns be with new number part.
  25. nr . cdr be;
  26. symbolic procedure bas_make(nr,pol);
  27. % Make base element with rep=nil.
  28. list(nr,pol, length pol,dp_ecart pol,nil);
  29. symbolic procedure bas_make1(nr,pol,rep);
  30. % Make base element with prescribed rep.
  31. list(nr,pol, length pol,dp_ecart pol,rep);
  32. symbolic procedure bas_getelement(i,bas);
  33. % Returns the base element with number i from bas (or nil).
  34. if null bas then list(i,nil,0,0,nil)
  35. else if eqn(i,bas_nr car bas) then car bas
  36. else bas_getelement(i,cdr bas);
  37. % ---------- Operations on base lists ---------------
  38. symbolic procedure bas_sort b;
  39. % Sort the base list b.
  40. sort(b,function red_better);
  41. symbolic procedure bas_print u;
  42. % Prints a list of distributive polynomials using dp_print.
  43. begin terpri();
  44. if null u then print 'empty
  45. else for each v in u do
  46. << write bas_nr v, " --> "; dp_print2 bas_dpoly v >>
  47. end;
  48. symbolic procedure bas_renumber u;
  49. % Renumber base list u.
  50. if null u then nil
  51. else begin scalar i; i:=0;
  52. return for each x in u collect <<i:=i+1; bas_newnumber(i,x) >>
  53. end;
  54. symbolic procedure bas_setrelations u;
  55. % Set in the base list u the relation part rep of base element nr. i
  56. % to e_i (provided i>0).
  57. for each x in u do
  58. if bas_nr x > 0 then rplaca(cddddr x, dp_from_ei bas_nr x);
  59. symbolic procedure bas_removerelations u;
  60. % Remove relation parts.
  61. for each x in u do rplaca(cddddr x, nil);
  62. symbolic procedure bas_getrelations u;
  63. % Returns the relations of the base list u as a separate base list.
  64. begin scalar w;
  65. for each x in u do w:=bas_make(bas_nr x,bas_rep x) . w;
  66. return reversip w;
  67. end;
  68. symbolic procedure bas_from_a u;
  69. % Converts the algebraic (prefix) form u to a base list clearing
  70. % denominators. Only for lists.
  71. bas_renumber for each v in cdr u collect
  72. bas_make(0,dp_from_a prepf numr simp v);
  73. symbolic procedure bas_2a u;
  74. % Converts the base list u to its algebraic prefix form.
  75. append('(list),for each x in u collect dp_2a bas_dpoly x);
  76. symbolic procedure bas_neworder u;
  77. % Returns reordered base list u (e.g. after change of term order).
  78. for each x in u collect
  79. bas_make1(bas_nr x,dp_neworder bas_dpoly x,
  80. dp_neworder bas_rep x);
  81. symbolic procedure bas_zerodelete u;
  82. % Returns base list u with zero elements deleted but not renumbered.
  83. if null u then nil
  84. else if null bas_dpoly car u then bas_zerodelete cdr u
  85. else car u.bas_zerodelete cdr u;
  86. symbolic procedure bas_simpelement b;
  87. % Returns (b_new . z) with
  88. % bas_dpoly b_new having leading coefficient 1 or
  89. % gcd(dp_content bas_poly,dp_content bas_rep) canceled out
  90. % and dpoly_old = z * dpoly_new , rep_old= z * rep_new.
  91. if null bas_dpoly b then b . bc_fi 1
  92. else begin scalar z,z1,pol,rep;
  93. if (z:=bc_inv (z1:=dp_lc bas_dpoly b)) then
  94. return bas_make1(bas_nr b,
  95. dp_times_bc(z,bas_dpoly b),
  96. dp_times_bc(z,bas_rep b))
  97. . z1;
  98. % -- now we assume that base coefficients are a gcd domain ----
  99. z:=bc_gcd(dp_content bas_dpoly b,dp_content bas_rep b);
  100. if bc_minus!? z1 then z:=bc_neg z;
  101. pol:=for each x in bas_dpoly b collect
  102. car x . car bc_divmod(cdr x,z);
  103. rep:=for each x in bas_rep b collect
  104. car x . car bc_divmod(cdr x,z);
  105. return bas_make1(bas_nr b,pol,rep) . z;
  106. end;
  107. symbolic procedure bas_simp u;
  108. % Applies bas_simpelement to each dpoly in the base list u.
  109. for each x in u collect car bas_simpelement x;
  110. symbolic procedure bas_zero!? b;
  111. % Test whether all base elements are zero.
  112. null b or (null bas_dpoly car b and bas_zero!? cdr b);
  113. symbolic procedure bas_sieve(bas,vars);
  114. % Sieve out all base elements from the base list bas with leading
  115. % term containing a variable from the list of var. names vars and
  116. % renumber the result.
  117. begin scalar m; m:=mo_zero();
  118. for each x in vars do
  119. if member(x,ring_names cali!=basering) then
  120. m:=mo_sum(m,mo_from_a x)
  121. else typerr(x,"variable name");
  122. return bas_renumber for each x in bas_zerodelete bas join
  123. if mo_zero!? mo_gcd(m,dp_lmon bas_dpoly x) then {x};
  124. end;
  125. symbolic procedure bas_homogenize(b,var);
  126. % Homogenize the base list b using the var. name var.
  127. % Note that the rep. part is correct only upto a power of var !
  128. for each x in b collect
  129. bas_make1(bas_nr x,dp_homogenize(bas_dpoly x,var),
  130. dp_homogenize(bas_rep x,var));
  131. symbolic procedure bas_dehomogenize(b,var);
  132. % Set the var. name var in the base list b equal to one.
  133. begin scalar u,v;
  134. if not member(var,v:=ring_all_names cali!=basering) then
  135. typerr(var,"dpoly variable");
  136. u:=setdiff(v,list var);
  137. return for each x in b collect
  138. bas_make1(bas_nr x,dp_seed(bas_dpoly x,u),
  139. dp_seed(bas_rep x,u));
  140. end;
  141. % ---------------- Special tools for local algebra -----------
  142. symbolic procedure bas!=factorunits p;
  143. if null p then nil
  144. else bas!=delprod
  145. for each y in cdr (fctrf numr simp dp_2a p where !*factor=t)
  146. collect (dp_from_a prepf car y . cdr y);
  147. symbolic procedure bas!=delprod u;
  148. begin scalar p; p:=dp_fi 1;
  149. for each x in u do
  150. if not dp_unit!? car x then p:=dp_prod(p,dp_power(car x,cdr x));
  151. return p
  152. end;
  153. symbolic procedure bas!=detectunits p;
  154. if null p then nil
  155. else if listtest(cdr p,dp_lmon p,
  156. function(lambda(x,y);not mo_vdivides!?(y,car x))) then p
  157. else list dp_term(bc_fi 1,dp_lmon p);
  158. symbolic procedure bas_factorunits b;
  159. bas_make(bas_nr b,bas!=factorunits bas_dpoly b);
  160. symbolic procedure bas_detectunits b;
  161. bas_make(bas_nr b,bas!=detectunits bas_dpoly b);
  162. endmodule; % bas
  163. end;