groebner.tst 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. % Examples of use of Groebner code.
  2. % In the Examples 1 - 3 the polynomial ring for the ideal operations
  3. % (variable sequence, term order mode) is defined globally in advance.
  4. % Example 1, Linz 85.
  5. torder ({q1,q2,q3,q4,q5,q6},lex)$
  6. groebner {q1,
  7. q2**2 + q3**2 + q4**2,
  8. q4*q3*q2,
  9. q3**2*q2**2 + q4**2*q2**2 + q4**2*q3**2,
  10. q6**2 + 1/3*q5**2,
  11. q6**3 - q5**2*q6,
  12. 2*q2**2*q6 - q3**2*q6 - q4**2*q6 + q3**2*q5 - q4**2*q5,
  13. 2*q2**2*q6**2 - q3**2*q6**2 - q4**2*q6**2 - 2*q3**2*q5*q6
  14. + 2*q4**2*q5*q6 - 2/3*q2**2*q5**2 + 1/3*q3**2*q5**2
  15. + 1/3*q4**2*q5**2,
  16. - q3**2*q2**2*q6 - q4**2*q2**2*q6 + 2*q4**2*q3**2*q6 -
  17. q3**2*q2**2*q5 + q4**2*q2**2*q5,
  18. - q3**2*q2**2*q6**2 - q4**2*q2**2*q6**2 + 2*q4**2*q3**2*q6**2
  19. + 2*q3**2*q2**2*q5*q6 - 2*q4**2*q2**2*q5*q6 + 1/3*q3**2*q2**2
  20. *q5**2 + 1/3*q4**2*q2**2*q5**2 - 2/3*q4**2*q3**2*q5**2,
  21. - 3*q3**2*q2**4*q5*q6**2 + 3*q4**2*q2**4*q5*q6**2
  22. + 3*q3**4*q2**2*q5*q6**2 - 3*q4**4*q2**2*q5*q6**2
  23. - 3*q4**2*q3**4*q5*q6**2 + 3*q4**4*q3**2*q5*q6**2
  24. + 1/3*q3**2*q2**4*q5**3 - 1/3*q4**2*q2**4*q5**3
  25. - 1/3*q3**4*q2**2*q5**3 + 1/3*q4**4*q2**2*q5**3 + 1/3*q4**2
  26. *q3**4*q5**3 - 1/3*q4**4*q3**2*q5**3};
  27. % Example 2. (Little) Trinks problem with 7 polynomials in 6 variables.
  28. trinkspolys := {45*p + 35*s - 165*b - 36,
  29. 35*p + 40*z + 25*t - 27*s,
  30. 15*w + 25*p*s + 30*z - 18*t - 165*b**2,
  31. - 9*w + 15*p*t + 20*z*s,
  32. w*p + 2*z*t - 11*b**3,
  33. 99*w - 11*s*b + 3*b**2,
  34. b**2 + 33/50*b + 2673/10000}$
  35. trinksvars := {w,p,z,t,s,b}$
  36. torder(trinksvars,lex)$
  37. groebner trinkspolys;
  38. groesolve ws;
  39. % Example 3. Hairer, Runge-Kutta 1, 6 polynomials 8 variables.
  40. torder({c2,c3,b3,b2,b1,a21,a32,a31},lex);
  41. groebnerf {c2 - a21,
  42. c3 - a31 - a32,
  43. b1 + b2 + b3 - 1,
  44. b2*c2 + b3*c3 - 1/2,
  45. b2*c2**2 + b3*c3**2 - 1/3,
  46. b3*a32*c2 - 1/6};
  47. % The examples 4 and 5 use automatic variable extraction.
  48. % Example 4.
  49. torder gradlex$
  50. g4 :=
  51. groebner({b + e + f - 1,
  52. c + d + 2*e - 3,
  53. b + d + 2*f - 1,
  54. a - b - c - d - e - f,
  55. d*e*a**2 - 1569/31250*b*c**3,
  56. c*f - 587/15625*b*d});
  57. hilbertpolynomial g4;
  58. glexconvert(g4,gvarslast,newvars={e},maxdeg=8);
  59. % Example 5.
  60. torder({u0,u2,u3,u1},lex)$
  61. groesolve({u0**2 - u0 + 2*u1**2 + 2*u2**2 + 2*u3**2,
  62. 2*u0*u1 + 2*u1*u2 + 2*u2*u3 - u1,
  63. 2*u0*u2 + u1**2 + 2*u1*u3 - u2,
  64. u0 + 2*u1 + 2*u2 + 2*u3 - 1},
  65. {u0,u2,u3,u1});
  66. % Example 6. (Big) Trinks problem with 6 polynomials in 6 variables.
  67. torder(trinksvars,lex)$
  68. btbas :=
  69. groebner {45*p + 35*s - 165*b - 36,
  70. 35*p + 40*z + 25*t - 27*s,
  71. 15*w + 25*p*s + 30*z - 18*t - 165*b**2,
  72. -9*w + 15*p*t + 20*z*s,
  73. w*p + 2*z*t - 11*b**3,
  74. 99*w - 11*b*s + 3*b**2};
  75. % The above system has dimension zero. Therefore its Hilbert polynomial
  76. % is a constant which is the number of zero points (including complex
  77. % zeros and multipliticities);
  78. hilbertpolynomial ws;
  79. % Example of Groebner with numerical postprocessing.
  80. on rounded;
  81. groesolve(trinkspolys,trinksvars);
  82. off rounded;
  83. % Additional groebner operators.
  84. % Reduce one polynomial wrt the basis of big Trinks. The result 0
  85. % is a proof for the ideal membership of the polynomial.
  86. torder(trinksvars,lex)$
  87. preduce(45*p + 35*s - 165*b - 36,btbas);
  88. % The following examples show how to work with the distributive
  89. % form of polynomials.
  90. torder({u0,u1,u2,u3},gradlex)$
  91. gsplit(2*u0*u2 + u1**2 + 2*u1*u3 - u2,{u0,u1,u2,u3});
  92. torder(trinksvars,lex)$
  93. gsort trinkspolys;
  94. gspoly(first trinkspolys, second trinkspolys);
  95. gvars trinkspolys;
  96. % Tagged basis and reduction trace. A tagged basis is a basis where
  97. % each polynomial is equated to a linear combination of the input
  98. % set. A tagged reduction shows how the result is computed by using
  99. % the basis polynomials.
  100. % First example for tagged polynomials: show how a polynomial is
  101. % represented as linear combination of the basis polynomials.
  102. % First I set up an environment for the computation.
  103. torder(trinksvars,lex)$
  104. % Then I compute an ordinary Groebner basis.
  105. bas := groebner trinkspolys$
  106. % Next I assign a tag to each basis polynomial.
  107. taggedbas := for i:= 1:length bas collect
  108. mkid(p,i) = part(bas,i);
  109. % And finally I reduce a (tagged) polynomial wrt the tagged basis.
  110. preducet(new=w*p + 2*z*t - 11*b**3,taggedbas);
  111. % Second example for tagged polynomials: representing a Groebner basis
  112. % as a combination of the input polynomials, here in a simple geometric
  113. % problem.
  114. torder({x,y},lex)$
  115. groebnert {circle=x**2 + y**2 - r**2,line = a*x + b*y};
  116. % In the third example I enter two polynomials that have no common zero.
  117. % Consequently the basis is {1}. The tagged computation gives me a proof
  118. % for the inconsistency of the system which is independent of the
  119. % Groebner formalism.
  120. groebnert {circle1=x**2 + y**2 - 10,circle2=x**2 + y**2 - 2};
  121. % Solve a special elimination task by using a blockwise elimination
  122. % order defined by a matrix. The equation set goes back to A.M.H.
  123. % Levelt (Nijmegen). The question is whether there is a member in the
  124. % ideal which depends only on two variables. Here we select x4 and y1.
  125. % The existence of such a polynomial proves that the system has exactly
  126. % one degree of freedom.
  127. % The first two rows of the term order matrix define the groupwise
  128. % elimination. The remaining lines define a secondary local
  129. % lexicographical behavior which is needed to construct an admissible
  130. % ordering.
  131. f1 := y1^2 + z1^2 -1;
  132. f2 := x2^2 + y2^2 + z2^2 -1;
  133. f3 := x3^2 + y3^2 + z3^2 -1;
  134. f4 := x4^2 + z4^2 -1;
  135. f5 := y1*y2 + z1*z2;
  136. f6 := x2*x3 + y2*y3 + z2*z3;
  137. f7 := x3*x4 + z3*z4;
  138. f8 := x2 + x3 + x4 + 1;
  139. f9 := y1 + y2 + y3 - 1;
  140. f10:= z1 + z2 + z3 + z4;
  141. eqns := {f1,f2,f3,f4,f5,f6,f7,f8,f9,f10}$
  142. vars := {x2,x3,y2,y3,z1,z2,z3,z4,x4,y1}$
  143. torder(vars,matrix,
  144. mat(
  145. (1,1,1,1,1,1,1,1,0,0),
  146. (0,0,0,0,0,0,0,0,1,1),
  147. (1,0,0,0,0,0,0,0,0,0),
  148. (0,1,0,0,0,0,0,0,0,0),
  149. (0,0,1,0,0,0,0,0,0,0),
  150. (0,0,0,1,0,0,0,0,0,0),
  151. (0,0,0,0,1,0,0,0,0,0),
  152. (0,0,0,0,0,1,0,0,0,0),
  153. (0,0,0,0,0,0,1,0,0,0),
  154. (0,0,0,0,0,0,0,0,1,0)));
  155. first reverse groebner(eqns,vars);
  156. % For a faster execution we convert the matrix into a
  157. % proper machine code routine. This step can be taken only
  158. % if there is access to a compiler.
  159. on comp;
  160. torder_compile(levelt,mat(
  161. (1,1,1,1,1,1,1,1,0,0),
  162. (0,0,0,0,0,0,0,0,1,1),
  163. (1,0,0,0,0,0,0,0,0,0),
  164. (0,1,0,0,0,0,0,0,0,0),
  165. (0,0,1,0,0,0,0,0,0,0),
  166. (0,0,0,1,0,0,0,0,0,0),
  167. (0,0,0,0,1,0,0,0,0,0),
  168. (0,0,0,0,0,1,0,0,0,0),
  169. (0,0,0,0,0,0,1,0,0,0),
  170. (0,0,0,0,0,0,0,0,1,0)));
  171. torder(vars,levelt)$
  172. first reverse groebner(eqns,vars);
  173. % For a homogeneous polynomial set we compute a graded Groebner
  174. % basis with grade limits. We use the graded term order with lex
  175. % as following order. As the grade vector has no zeros, this ordering
  176. % is functionally equivalent to a weighted ordering.
  177. torder({x,y,z},graded,{1,1,2},lex);
  178. dd_groebner(0,10,{x^10*y + y*z^5, x*y^12 + y*z^6});
  179. dd_groebner(0,50,{x^10*y + y*z^5, x*y^12 + y*z^6});
  180. dd_groebner(0,infinity,{x^10*y + y*z^5, x*y^12 + y*z^6});
  181. % Test groebner_walk
  182. trinkspolys := {45*p + 35*s - 165*b - 36,
  183. 35*p + 40*z + 25*t - 27*s,
  184. 15*w + 25*p*s + 30*z - 18*t - 165*b**2,
  185. - 9*w + 15*p*t + 20*z*s,
  186. w*p + 2*z*t - 11*b**3,
  187. 99*w - 11*s*b + 3*b**2,
  188. b**2 + 33/50*b + 2673/10000}$
  189. trinksvars := {w,p,z,t,s,b}$
  190. torder(trinksvars,gradlex)$
  191. gg := groebner trinkspolys$
  192. g := groebner_walk gg$
  193. on div$
  194. g;
  195. clear g, gg, trinkspolys, trinksvars$
  196. end;