1 | /* -*- Mode: Maxima -*- */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | **
|
---|
5 | ** Copyright (C) 1999, 2002, 2009 Marek Rychlik <rychlik@u.arizona.edu>
|
---|
6 | **
|
---|
7 | ** This program is free software; you can redistribute it and/or modify
|
---|
8 | ** it under the terms of the GNU General Public License as published by
|
---|
9 | ** the Free Software Foundation; either version 2 of the License, or
|
---|
10 | ** (at your option) any later version.
|
---|
11 | **
|
---|
12 | ** This program is distributed in the hope that it will be useful,
|
---|
13 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | ** GNU General Public License for more details.
|
---|
16 | **
|
---|
17 | ** You should have received a copy of the GNU General Public License
|
---|
18 | ** along with this program; if not, write to the Free Software
|
---|
19 | ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
20 | **
|
---|
21 | */
|
---|
22 | showtime:true;
|
---|
23 |
|
---|
24 | /* POLY_MONOMIAL_ORDER switch represents the monomial order that will globally be in effect
|
---|
25 | for the succeeding operations. */
|
---|
26 |
|
---|
27 | poly_monomial_order:'lex;
|
---|
28 |
|
---|
29 | /* POLY_EXPAND parses polynomials to internal form and back. It can be used to test
|
---|
30 | whether an expression correctly parses to the internal representation.
|
---|
31 | The following examples illustrate that indexed and transcendental function variables
|
---|
32 | are allowed. */
|
---|
33 |
|
---|
34 | poly_expand(x,[x,y]);
|
---|
35 | poly_expand(x+y,[x,y]);
|
---|
36 | poly_expand(x-y,[x,y]);
|
---|
37 | poly_expand((x-y)*(x+y),[x,y]);
|
---|
38 | poly_expand((x+y)^2,[x,y]);
|
---|
39 | poly_expand((x+y)^5,[x,y]);
|
---|
40 | poly_expand(x/y-1,[x]);
|
---|
41 | poly_expand(x^2/sqrt(y)-x*exp(y)-1,[x]);
|
---|
42 | poly_expand(sin(x)-sin(x)^2-1,[sin(x)]);
|
---|
43 | poly_expand((x[2]/sin(y[3])-1)^5,[x[2]]),poly_return_term_list:true;
|
---|
44 |
|
---|
45 | /* POLY_ADD, POLY_SUBTRACT, POLY_MULTIPLY and POLY_EXPT are the arithmetical operations on polynomials.
|
---|
46 | These are performed using the internal representation, but the results are converted back to the
|
---|
47 | Maxima general form */
|
---|
48 |
|
---|
49 | poly_add(x^2*y+z,x-z,[x,y,z]);
|
---|
50 | poly_subtract(x^2*y+z,x-z,[x,y,z]);
|
---|
51 | poly_multiply(x^2*y+z,x-z,[x,y,z]) - (x^2*y+z)*(x-z), expand;
|
---|
52 | poly_expt(x-y, 3, [x,y]) - (x-y)^3, expand;
|
---|
53 |
|
---|
54 | /* POLY_CONTENT extracts the GCD of its coefficients */
|
---|
55 | poly_content(21*x+35*y,[x,y]);
|
---|
56 |
|
---|
57 | /* POLY_PRIMITIVE_PART divides a polynomial by the GCD of its coefficients */
|
---|
58 | poly_primitive_part(21*x+35*y,[x,y]);
|
---|
59 |
|
---|
60 | /* POLY_S_POLYNOMIAL computest the syzygy polynomial (S-polynomial) of two polynomials */
|
---|
61 | poly_s_polynomial(x+y,x-y,[x,y]);
|
---|
62 |
|
---|
63 |
|
---|
64 | /* POLY_NORMAL_FORM finds the normal form of a polynomial with respect to a set of polynomials. */
|
---|
65 | poly_normal_form(x^2+y^2,[x-y,x+y],[x,y]);
|
---|
66 | poly_pseudo_divide(2*x^2+3*y^2,[7*x-y^2,11*x+y],[x,y]);
|
---|
67 | poly_exact_divide((x+y)^2,x+y,[x,y]);
|
---|
68 |
|
---|
69 | /* POLY_BUCHBERGER performs the Buchberger algorithm on a list of polynomials and returns
|
---|
70 | the resulting Grobner basis */
|
---|
71 | poly_buchberger([x^2-y*x,x^2+y+x*y^2],[x,y]);
|
---|
72 |
|
---|
73 | /* POLY_REDUCTION reduces a set of polynomials, so that
|
---|
74 | each polynomial is fully reduced with respect to the other polynomials */
|
---|
75 |
|
---|
76 | poly_reduction([x^2-x*y,x*y^2+y+x^2,x*y^2+x*y+y,x*y-y^2,y^3+y^2+y],[x,y]);
|
---|
77 |
|
---|
78 | /* POLY_MINIMIZATION selects a subset of a set of polynomials, so that no leading monomial is divisible by
|
---|
79 | another leading monomial */
|
---|
80 |
|
---|
81 | poly_minimization([x^2-x*y,x*y^2+y+x^2,x*y^2+x*y+y,x*y-y^2,y^3+y^2+y],[x,y]);
|
---|
82 |
|
---|
83 | /* POLY_REDUCED_GROBNER returns a reduced Grobner basis */
|
---|
84 | poly_reduced_grobner([x^2-y*x,x^2+y+x*y^2],[x,y]);
|
---|
85 |
|
---|
86 | /* POLY_NORMALIZE divides a polynomial by its leading coefficient */
|
---|
87 | poly_normalize(2*x+y,[x,y]);
|
---|
88 |
|
---|
89 | /* POLY_NORMALIZE_LIST applies POLY_NORMALIZE to each polynomial in the list */
|
---|
90 |
|
---|
91 | poly_normalize_list([2*x+y,3*x^2+7],[x,y]);
|
---|
92 |
|
---|
93 | /* POLY_DEPENDS_P tests whether a polynomial depends on a variable */
|
---|
94 |
|
---|
95 | poly_depends_p(x^2+y,x,[x,y,z]);
|
---|
96 | poly_depends_p(x^2+y,z,[x,y,z]);
|
---|
97 |
|
---|
98 |
|
---|
99 | /* POLY_ELIMINATION_IDEAL returns the grobner basis of the K-th elimination ideal of an
|
---|
100 | ideal specified as a list of generating polynomials (not necessarily Grobner basis */
|
---|
101 |
|
---|
102 | poly_elimination_ideal([x+y,x-y],0,[x,y]);
|
---|
103 | poly_elimination_ideal([x+y,x-y],1,[x,y]);
|
---|
104 | poly_elimination_ideal([x+y,x-y],2,[x,y]);
|
---|
105 |
|
---|
106 | /* POLY_IDEAL_INTERSECTION returns the intersection of two ideals */
|
---|
107 | poly_ideal_intersection([x^2+y,x^2-y],[x,y^2],[x,y]);
|
---|
108 |
|
---|
109 | /* POLY_LCM and POLY_GCD are the Grobner versions of LCM and GCD */
|
---|
110 |
|
---|
111 | poly_lcm(x*y^2-x,x^2*y+x,[x,y]);
|
---|
112 | poly_gcd(x*y^2-x,x^2*y+x,[x,y]);
|
---|
113 |
|
---|
114 | /* POLY_GROBNER_MEMBER tests whether a polynomial belongs to an ideal generated by a list of polynomials,
|
---|
115 | which is assumed to be a Grobner basis. Equivalent to NORMAL_FORM being 0. */
|
---|
116 |
|
---|
117 | poly_grobner_member(x+y,[x,y],[x,y]);
|
---|
118 |
|
---|
119 | /* POLY_GROBNER_EQUAL tests whether two Grobner bases generate the same ideal.
|
---|
120 | This is equivalent to checking that every polynomial of the first basis reduces to 0
|
---|
121 | modulo the second basis and vice versa. Note that in the example below the
|
---|
122 | first list is not a Grobner basis, and thus the result is FALSE. */
|
---|
123 |
|
---|
124 | poly_grobner_equal([x+y,x-y],[x,y],[x,y]);
|
---|
125 |
|
---|
126 | /* POLY_GROBNER_SUBSETP tests whether an ideal generated by the first list of polynomials
|
---|
127 | is contained in the ideal generated by the second list. For this test to always succeed,
|
---|
128 | the second list must be a Grobner basis */
|
---|
129 |
|
---|
130 | poly_grobner_subsetp([x+y,x-y],[x,y],[x,y]);
|
---|
131 |
|
---|
132 | /* POLY_POLYSATURATION_EXTENSION implements the famous Rabinowitz trick. */
|
---|
133 | poly_polysaturation_extension([x,y],[x^2,y^3],[x,y],[u,v]);
|
---|
134 |
|
---|
135 | poly_saturation_extension([x,y],[x^2,y^3],[x,y],[u,v]);
|
---|
136 |
|
---|
137 | /* POLY_IDEAL_POLYSATURATION1 for a given ideal I and polynomials f, g, ..., finds
|
---|
138 | the colon ideal I : f^inf : g^inf : ... */
|
---|
139 | poly_ideal_polysaturation1([x,y],[x^2,y^3],[x,y]);
|
---|
140 |
|
---|
141 | /* POLY_IDEAL_SATURATION for given ideals I and J computes the ideal I : J^inf. */
|
---|
142 | poly_ideal_saturation([x,y],[x^2,y^3],[x,y]);
|
---|
143 |
|
---|
144 | /* POLY_IDEAL_POLYSATURATION for a given ideal I and a sequence of ideals J1, J2, J3, ...,
|
---|
145 | finds the ideal I : J1^inf : J2^inf : J3^inf : ... */
|
---|
146 | poly_ideal_polysaturation([x,y],[[x^2],[y^3]],[x,y]);
|
---|
147 | poly_ideal_polysaturation([x^4-y^4], [[x-y],[x^2+y^2, x+y]],[x,y]);
|
---|
148 |
|
---|
149 | /* POLY_COLON_IDEAL finds the reduced Grobner basis of the colon ideal I:J, i.e. the set of polynomials H
|
---|
150 | such that there is a polynomial F in J for which H*F is in I */
|
---|
151 |
|
---|
152 | poly_colon_ideal([x^2*y],[y],[x,y]);
|
---|
153 |
|
---|
154 | /* POLY_BUCHBERGER_CRITERION verifies whether a given set of polynomials is a Grobner basis with respect
|
---|
155 | to the current term order */
|
---|
156 | poly_buchberger_criterion([x,y],[x,y]);
|
---|
157 | poly_buchberger_criterion([x-y,x+y],[x,y]);
|
---|
158 |
|
---|
159 | /* Grobner basis associated with Enneper minimal surface */
|
---|
160 | poly_grobner([x-3*u-3*u*v^2+u^3,y-3*v-3*u^2*v+v^3,z-3*u^2+3*v^2],[u,v,x,y,z]);
|
---|
161 | poly_reduced_grobner([x-3*u-3*u*v^2+u^3,y-3*v-3*u^2*v+v^3,z-3*u^2+3*v^2],[u,v,x,y,z]);
|
---|
162 |
|
---|
163 | /* Cyclic roots of degree 5 */
|
---|
164 | poly_reduced_grobner([x+y+z+u+v,x*y+y*z+z*u+u*v+v*x,x*y*z+y*z*u+z*u*v+u*v*x+v*x*y,x*y*z*u+y*z*u*v+z*u*v*x+u*v*x*y+v*x*y*z,x*y*z*u*v-1],[u,v,x,y,z]);
|
---|
165 |
|
---|
166 | /* The next example demonstrates the use of the switch
|
---|
167 | POLY_RETURN_TERM_LIST, which, if set to TRUE, makes the results to
|
---|
168 | appear as lists of terms listed in the current monomial order rather
|
---|
169 | than a general form expression */
|
---|
170 |
|
---|
171 | block([orders:[lex,grlex,grevlex,invlex]],
|
---|
172 | for i:1 thru length(orders) do (
|
---|
173 | print(ev([orders[i], poly_expand((x^2+x+y)^3,[x,y])], poly_monomial_order=orders[i]))
|
---|
174 | )
|
---|
175 | ), poly_return_term_list=true;
|
---|
176 |
|
---|
177 | /* Grobner bases can be computed over coefficient ring of maxima general expressions */
|
---|
178 | poly_grobner([x*y-1,x+y],[x]);
|
---|
179 |
|
---|
180 | /* A tough example learned from Cox */
|
---|
181 | poly_grobner([x^5+y^4+z^3-1,x^3+y^3+z^2-1], [x,y,z]);
|
---|
182 |
|
---|
183 | /* An even tougher example of Cox */
|
---|
184 | poly_grobner([x^5+y^4+z^3-1,x^3+y^3+z^2-1], [x,y,z]);
|
---|
185 |
|
---|
186 | /* We can also perform Grobner basis calculations modulo prime */
|
---|
187 | poly_grobner([x^5+y^4+z^3-1,x^3+y^3+z^2-1], [x,y,z]), modulus=3;
|
---|
188 |
|
---|
189 | /* We can also explicitly ask for the Grobner basis to be calculated using only
|
---|
190 | integer coefficients. An error will result if this assertion is not satisfied. */
|
---|
191 | poly_grobner([x^5+y^4+z^3-1,x^3+y^3+z^2-1], [x,y,z]), poly_coefficient_ring='ring_of_integers;
|
---|
192 |
|
---|
193 | /* The following several tests demonstrate the use of jet variables useful in processing differential equations */
|
---|
194 |
|
---|
195 |
|
---|
196 | /* Clear some variables */
|
---|
197 | kill(ode,t,x,y,u,v,r);
|
---|
198 |
|
---|
199 | /* Set up dependencies */
|
---|
200 | depends([x,y,u,v,r],t);
|
---|
201 |
|
---|
202 | /* These are equations representing mathematical pendulum */
|
---|
203 | ode:[x^2+y^2-c,'diff(x,t)-u,'diff(y,t)-v,'diff(u,t)+r*x,'diff(v,t)+r*y+1];
|
---|
204 |
|
---|
205 | jet_vars(k):=apply(append,reverse(makelist(['diff(x,t,j),'diff(y,t,j),'diff(u,t,j),'diff(v,t,j),'diff(r,t,j)],j,0,k+1)));
|
---|
206 |
|
---|
207 | /* Define k-fold prolongation */
|
---|
208 | prolongate(k):=apply(append,makelist(diff(ode,t,j),j,0,k));
|
---|
209 |
|
---|
210 | /* Define Grobner basis of k-fold prolongation */
|
---|
211 | gb(k):=poly_reduced_grobner(prolongate(k),jet_vars(k));
|
---|
212 |
|
---|
213 | /* Define the l-th projection of the k-th prolongation */
|
---|
214 | projection(l, k):=poly_elimination_ideal(prolongate(k),5*l,jet_vars(k));
|
---|
215 |
|
---|
216 | /* Compute some projections */
|
---|
217 | projection(0, 0);
|
---|
218 | projection(1, 1);
|
---|