triang.red 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. module triang;
  2. COMMENT
  3. ##########################################
  4. ## ##
  5. ## Solving zerodimensional systems ##
  6. ## Triangular systems ##
  7. ## ##
  8. ##########################################
  9. Zerosolve returns lists of dpmats in prefix form, that consist of
  10. triangular systems in the sense of Lazard, provided the input is
  11. radical. For the corresponding definitions and concepts see
  12. [Lazard] D. Lazard: Solving zero dimensional algebraic systems.
  13. J. Symb. Comp. 13 (1992), 117 - 131.
  14. and
  15. [EFGB] H.-G. Graebe: Triangular systems and factorized Groebner
  16. bases. Report Nr. 7 (1995), Inst. f. Informatik,
  17. Univ. Leipzig.
  18. The triangularization of zerodim. ideal bases is done by Moeller's
  19. approach, see
  20. [Moeller] H.-M. Moeller : On decomposing systems of polynomial
  21. equations with finitely many solutions.
  22. J. AAECC 4 (1993), 217 - 230.
  23. We present three implementations :
  24. -- the pure lex gb (zerosolve)
  25. -- the "slow turn to pure lex" (zerosolve1)
  26. and
  27. -- the mix with [FGLM] (zerosolve2)
  28. END COMMENT;
  29. symbolic procedure triang!=trsort(a,b);
  30. mo_dlexcomp(dp_lmon a,dp_lmon b);
  31. symbolic procedure triang!=makedpmat x;
  32. makelist for each p in x collect dp_2a p;
  33. % =================================================================
  34. % The pure lex approach.
  35. symbolic operator zerosolve;
  36. symbolic procedure zerosolve m;
  37. if !*mode='algebraic then makelist zerosolve!* dpmat_from_a m
  38. else zerosolve!* m;
  39. symbolic procedure zerosolve!* m;
  40. % Solve a zerodimensional dpmat ideal m, first groebfactor it and then
  41. % triangularize it. Returns a list of dpmats in prefix form.
  42. if (dpmat_cols m>0) or (dim!* m>0) then
  43. rederr"ZEROSOLVE only for zerodimensional ideals"
  44. else if not !*noetherian or ring_degrees cali!=basering then
  45. rederr"ZEROSOLVE only for pure lex. term orders"
  46. else for each x in groebfactor!*(m,nil) join triang_triang car x;
  47. symbolic procedure triang_triang m;
  48. % m must be a zerodim. ideal gbasis (recommended to be radical)
  49. % wrt. a pure lex term order.
  50. % Returns a list l of dpmats in triangular form.
  51. if (dpmat_cols m>0) or (dim!* m>0) then
  52. rederr"Triangularization only for zerodimensional ideals"
  53. else if not !*noetherian or ring_degrees cali!=basering then
  54. rederr"Triangularization only for pure lex. term orders"
  55. else for each x in triang!=triang(m,ring_names cali!=basering) collect
  56. triang!=makedpmat x;
  57. symbolic procedure triang!=triang(A,vars);
  58. % triang!=triang(A,vars)={f1.x for x in triang!=triang(B,cdr vars)}
  59. % \union triang!=triang(A:<B>,vars)
  60. % where A={f1,...,fr}, B={f2~,...fr~}, see [Moeller].
  61. % Returns a list of polynomial lists.
  62. if dpmat_unitideal!? A then nil
  63. else begin scalar x,f1,m1,m2,B;
  64. x:=car vars;
  65. m1:=sort(for each x in dpmat_list A collect bas_dpoly x,
  66. function triang!=trsort);
  67. if length m1 = length vars then return {m1};
  68. f1:=car m1;
  69. m2:=for each y in cdr m1 collect bas_make(1,dp_xlt(y,x));
  70. B:=interreduce!* dpmat_make(length m2,0,m2,nil,nil);
  71. return append(
  72. for each u in triang!=triang(B,cdr vars) collect (f1 . u),
  73. triang!=triang(matstabquot!*(A,B),vars));
  74. end;
  75. % =================================================================
  76. % Triangularization wrt. an arbitrary term order
  77. symbolic operator zerosolve1;
  78. symbolic procedure zerosolve1 m;
  79. if !*mode='algebraic then makelist zerosolve1!* dpmat_from_a m
  80. else zerosolve1!* m;
  81. symbolic procedure zerosolve1!* m;
  82. for each x in groebfactor!*(m,nil) join triang_triang1 car x;
  83. symbolic procedure triang_triang1 m;
  84. % m must be a zerodim. ideal gbasis (recommended to be radical)
  85. % Returns a list l of dpmats in triangular form.
  86. if (dpmat_cols m>0) or (dim!* m>0) then
  87. rederr"Triangularization only for zerodimensional ideals"
  88. else if not !*noetherian then
  89. rederr"Triangularization only for noetherian term orders"
  90. else for each x in triang!=triang1(m,ring_names cali!=basering) collect
  91. triang!=makedpmat x;
  92. symbolic procedure triang!=triang1(A,vars);
  93. % triang!=triang(A,vars)={f1.x for x in triang!=triang1(B,cdr vars)}
  94. % \union triang!=triang1(A:<B>,vars)
  95. % where A={f1,...,fr}, B={f2~,...fr~}, see [Moeller].
  96. % Returns a list of polynomial lists.
  97. if dpmat_unitideal!? A then nil
  98. else if length vars = 1 then {{bas_dpoly first dpmat_list A}}
  99. else (begin scalar u,x,f1,m1,m2,B,vars1,res;
  100. x:=car vars; vars1:=ring_names cali!=basering;
  101. setring!* ring_define(vars1,eliminationorder!*(vars1,{x}),
  102. 'revlex,ring_ecart cali!=basering);
  103. a:=groebfactor!*(dpmat_neworder(a,nil),nil);
  104. % Constraints in dimension zero may be skipped :
  105. a:=for each x in a collect car x;
  106. for each u in a do
  107. << m1:=sort(for each x in dpmat_list u collect bas_dpoly x,
  108. function triang!=trsort);
  109. f1:=car m1;
  110. m2:=for each y in cdr m1 collect bas_make(1,dp_xlt(y,x));
  111. B:=interreduce!* dpmat_make(length m2,0,m2,nil,nil);
  112. res:=nconc(append(
  113. for each v in triang!=triang1(B,cdr vars) collect (f1 . v),
  114. triang!=triang1a(matstabquot!*(u,B),vars)),res);
  115. >>;
  116. return res;
  117. end) where cali!=basering=cali!=basering;
  118. symbolic procedure triang!=triang1a(A,vars);
  119. % triang!=triang(A,vars)={f1.x for x in triang!=triang1(B,cdr vars)}
  120. % \union triang!=triang1(A:<B>,vars)
  121. % where A is already a gr basis wrt. the elimination order.
  122. % Returns a list of polynomial lists.
  123. if dpmat_unitideal!? A then nil
  124. else if length vars = 1 then {{bas_dpoly first dpmat_list A}}
  125. else begin scalar u,x,f1,m1,m2,B;
  126. x:=car vars;
  127. m1:=sort(for each x in dpmat_list a collect bas_dpoly x,
  128. function triang!=trsort);
  129. f1:=car m1;
  130. m2:=for each y in cdr m1 collect bas_make(1,dp_xlt(y,x));
  131. B:=interreduce!* dpmat_make(length m2,0,m2,nil,nil);
  132. return append(
  133. for each u in triang!=triang1(B,cdr vars) collect (f1 . u),
  134. triang!=triang1a(matstabquot!*(A,B),vars));
  135. end;
  136. % =================================================================
  137. % Triangularization wrt. an arbitrary term order and FGLM approach.
  138. symbolic operator zerosolve2;
  139. symbolic procedure zerosolve2 m;
  140. if !*mode='algebraic then makelist zerosolve2!* dpmat_from_a m
  141. else zerosolve2!* m;
  142. symbolic procedure zerosolve2!* m;
  143. % Solve a zerodimensional dpmat ideal m, first groebfactoring it and
  144. % secondly triangularizing it.
  145. for each x in groebfactor!*(m,nil) join triang_triang2 car x;
  146. symbolic procedure triang_triang2 m;
  147. % m must be a zerodim. ideal gbasis (recommended to be radical)
  148. % Returns a list l of dpmats in triangular form.
  149. if (dpmat_cols m>0) or (dim!* m>0) then
  150. rederr"Triangularization only for zerodimensional ideals"
  151. else if not !*noetherian then
  152. rederr"Triangularization only for noetherian term orders"
  153. else for each x in triang!=triang2(m,ring_names cali!=basering)
  154. collect triang!=makedpmat x;
  155. symbolic procedure triang!=triang2(A,vars);
  156. % triang!=triang(A,vars)={f1.x for x in triang!=triang2(B,cdr vars)}
  157. % \union triang!=triang2(A:<B>,vars)
  158. % where A={f1,...,fr}, B={f2~,...fr~}, see [Moeller].
  159. % Returns a list of polynomial lists.
  160. if dpmat_unitideal!? A then nil
  161. else if length vars = 1 then {{bas_dpoly first dpmat_list A}}
  162. else (begin scalar u,x,f1,m1,m2,B,vars1,vars2,extravars,res,c1;
  163. x:=car vars; vars1:=ring_names cali!=basering;
  164. extravars:=dpmat_from_a('list . (vars2:=setdiff(vars1,vars)));
  165. % We need this to make A truely zerodimensional.
  166. c1:=ring_define(vars1,eliminationorder!*(vars1,{x}),
  167. 'revlex,ring_ecart cali!=basering);
  168. a:=matsum!* {extravars,a};
  169. u:=change_termorder!*(a,c1);
  170. a:=groebfactor!*(dpmat_sieve(u,vars2,nil),nil);
  171. % Constraints in dimension zero may be skipped :
  172. a:=for each x in a collect car x;
  173. for each u in a do
  174. << m1:=sort(for each x in dpmat_list u collect bas_dpoly x,
  175. function triang!=trsort);
  176. f1:=car m1;
  177. m2:=for each y in cdr m1 collect bas_make(1,dp_xlt(y,x));
  178. B:=interreduce!* dpmat_make(length m2,0,m2,nil,nil);
  179. res:=nconc(append(
  180. for each v in triang!=triang2(B,cdr vars) collect (f1 . v),
  181. triang!=triang2a(matstabquot!*(u,B),vars)),res);
  182. >>;
  183. return res;
  184. end) where cali!=basering=cali!=basering;
  185. symbolic procedure triang!=triang2a(A,vars);
  186. % triang!=triang(A,vars)={f1.x for x in triang!=triang2(B,cdr vars)}
  187. % \union triang!=triang2(A:<B>,vars)
  188. % where A is already a gr basis wrt. the elimination order.
  189. % Returns a list of polynomial lists.
  190. if dpmat_unitideal!? A then nil
  191. else if length vars = 1 then {{bas_dpoly first dpmat_list A}}
  192. else begin scalar u,x,f1,m1,m2,B;
  193. x:=car vars;
  194. m1:=sort(for each x in dpmat_list a collect bas_dpoly x,
  195. function triang!=trsort);
  196. f1:=car m1;
  197. m2:=for each y in cdr m1 collect bas_make(1,dp_xlt(y,x));
  198. B:=interreduce!* dpmat_make(length m2,0,m2,nil,nil);
  199. return append(
  200. for each u in triang!=triang2(B,cdr vars) collect (f1 . u),
  201. triang!=triang2a(matstabquot!*(A,B),vars));
  202. end;
  203. endmodule; % triang
  204. end;