close Warning: Can't synchronize with repository "(default)" (The repository directory has changed, you should resynchronize the repository with: trac-admin $ENV repository resync '(default)'). Look in the Trac log for more information.

source: branches/f4grobner/grobner.demo

Last change on this file was 4556, checked in by Marek Rychlik, 8 years ago

* empty log message *

File size: 8.6 KB
Line 
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*/
22showtime:true;
23
24/* POLY_MONOMIAL_ORDER switch represents the monomial order that will globally be in effect
25 for the succeeding operations. */
26
27poly_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
34poly_expand(x,[x,y]);
35poly_expand(x+y,[x,y]);
36poly_expand(x-y,[x,y]);
37poly_expand((x-y)*(x+y),[x,y]);
38poly_expand((x+y)^2,[x,y]);
39poly_expand((x+y)^5,[x,y]);
40poly_expand(x/y-1,[x]);
41poly_expand(x^2/sqrt(y)-x*exp(y)-1,[x]);
42poly_expand(sin(x)-sin(x)^2-1,[sin(x)]);
43poly_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
49poly_add(x^2*y+z,x-z,[x,y,z]);
50poly_subtract(x^2*y+z,x-z,[x,y,z]);
51poly_multiply(x^2*y+z,x-z,[x,y,z]) - (x^2*y+z)*(x-z), expand;
52poly_expt(x-y, 3, [x,y]) - (x-y)^3, expand;
53
54/* POLY_CONTENT extracts the GCD of its coefficients */
55poly_content(21*x+35*y,[x,y]);
56
57/* POLY_PRIMITIVE_PART divides a polynomial by the GCD of its coefficients */
58poly_primitive_part(21*x+35*y,[x,y]);
59
60/* POLY_S_POLYNOMIAL computest the syzygy polynomial (S-polynomial) of two polynomials */
61poly_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. */
65poly_normal_form(x^2+y^2,[x-y,x+y],[x,y]);
66poly_pseudo_divide(2*x^2+3*y^2,[7*x-y^2,11*x+y],[x,y]);
67poly_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 */
71poly_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
76poly_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
81poly_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 */
84poly_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 */
87poly_normalize(2*x+y,[x,y]);
88
89/* POLY_NORMALIZE_LIST applies POLY_NORMALIZE to each polynomial in the list */
90
91poly_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
95poly_depends_p(x^2+y,x,[x,y,z]);
96poly_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
102poly_elimination_ideal([x+y,x-y],0,[x,y]);
103poly_elimination_ideal([x+y,x-y],1,[x,y]);
104poly_elimination_ideal([x+y,x-y],2,[x,y]);
105
106/* POLY_IDEAL_INTERSECTION returns the intersection of two ideals */
107poly_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
111poly_lcm(x*y^2-x,x^2*y+x,[x,y]);
112poly_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
117poly_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
124poly_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
130poly_grobner_subsetp([x+y,x-y],[x,y],[x,y]);
131
132/* POLY_POLYSATURATION_EXTENSION implements the famous Rabinowitz trick. */
133poly_polysaturation_extension([x,y],[x^2,y^3],[x,y],[u,v]);
134
135poly_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 : ... */
139poly_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. */
142poly_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 : ... */
146poly_ideal_polysaturation([x,y],[[x^2],[y^3]],[x,y]);
147poly_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 for every polynomial G in I there is a polynomial F in J for which H*F=G;
151 in other words, I:J = {H: H*J is contained in I} */
152
153poly_colon_ideal([x^2*y],[y],[x,y]);
154
155/* POLY_BUCHBERGER_CRITERION verifies whether a given set of polynomials is a Grobner basis with respect
156 to the current term order */
157poly_buchberger_criterion([x,y],[x,y]);
158poly_buchberger_criterion([x-y,x+y],[x,y]);
159
160/* Grobner basis associated with Enneper minimal surface */
161poly_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]);
162poly_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]);
163
164/* Cyclic roots of degree 5 */
165poly_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]);
166
167/* The next example demonstrates the use of the switch
168 POLY_RETURN_TERM_LIST, which, if set to TRUE, makes the results to
169 appear as lists of terms listed in the current monomial order rather
170 than a general form expression */
171
172block([orders:[lex,grlex,grevlex,invlex]],
173for i:1 thru length(orders) do (
174 print(ev([orders[i], poly_expand((x^2+x+y)^3,[x,y])], poly_monomial_order=orders[i]))
175 )
176), poly_return_term_list=true;
177
178/* Grobner bases can be computed over coefficient ring of maxima general expressions */
179poly_grobner([x*y-1,x+y],[x]);
180
181/* A tough example learned from Cox */
182poly_grobner([x^5+y^4+z^3-1,x^3+y^3+z^2-1], [x,y,z]);
183
184/* An even tougher example of Cox */
185poly_grobner([x^5+y^4+z^3-1,x^3+y^3+z^2-1], [x,y,z]);
186
187/* We can also perform Grobner basis calculations modulo prime */
188poly_grobner([x^5+y^4+z^3-1,x^3+y^3+z^2-1], [x,y,z]), modulus=3;
189
190/* We can also explicitly ask for the Grobner basis to be calculated using only
191 integer coefficients. An error will result if this assertion is not satisfied. */
192poly_grobner([x^5+y^4+z^3-1,x^3+y^3+z^2-1], [x,y,z]), poly_coefficient_ring='ring_of_integers;
193
194/* The following several tests demonstrate the use of jet variables useful in processing differential equations */
195
196
197/* Clear some variables */
198kill(ode,t,x,y,u,v,r);
199
200/* Set up dependencies */
201depends([x,y,u,v,r],t);
202
203/* These are equations representing mathematical pendulum */
204ode:[x^2+y^2-c,'diff(x,t)-u,'diff(y,t)-v,'diff(u,t)+r*x,'diff(v,t)+r*y+1];
205
206jet_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)));
207
208/* Define k-fold prolongation */
209prolongate(k):=apply(append,makelist(diff(ode,t,j),j,0,k));
210
211/* Define Grobner basis of k-fold prolongation */
212gb(k):=poly_reduced_grobner(prolongate(k),jet_vars(k));
213
214/* Define the l-th projection of the k-th prolongation */
215projection(l, k):=poly_elimination_ideal(prolongate(k),5*l,jet_vars(k));
216
217/* Compute some projections */
218projection(0, 0);
219projection(1, 1);
Note: See TracBrowser for help on using the repository browser.