1 | /////////////////////////////////////////////////////////////////////////////// |
---|
2 | version="$Id: poly.lib,v 1.29 2000-12-22 14:22:23 greuel Exp $"; |
---|
3 | category="General purpose"; |
---|
4 | info=" |
---|
5 | LIBRARY: poly.lib Procedures for Manipulating Polys, Ideals, Modules |
---|
6 | AUTHORS: O. Bachmann, G.-M: Greuel, A. Fruehbis |
---|
7 | |
---|
8 | PROCEDURES: |
---|
9 | cyclic(int); ideal of cyclic n-roots |
---|
10 | katsura([i]); katsura [i] ideal |
---|
11 | freerank(poly/...) rank of coker(input) if coker is free else -1 |
---|
12 | is_homog(poly/...); int, =1 resp. =0 if input is homogeneous resp. not |
---|
13 | is_zero(poly/...); int, =1 resp. =0 if coker(input) is 0 resp. not |
---|
14 | lcm(ideal); lcm of given generators of ideal |
---|
15 | maxcoef(poly/...); maximal length of coefficient occuring in poly/... |
---|
16 | maxdeg(poly/...); int/intmat = degree/s of terms of maximal order |
---|
17 | maxdeg1(poly/...); int = [weighted] maximal degree of input |
---|
18 | mindeg(poly/...); int/intmat = degree/s of terms of minimal order |
---|
19 | mindeg1(poly/...); int = [weighted] minimal degree of input |
---|
20 | normalize(poly/...); normalize poly/... such that leading coefficient is 1 |
---|
21 | rad_con(p,I); check radical containment of poly p in ideal I |
---|
22 | content(f); content of polynomial/vector f |
---|
23 | numerator(n); numerator of number n |
---|
24 | denominator(n) denominator of number n |
---|
25 | mod2id(M,iv); conversion of a module M to an ideal |
---|
26 | id2mod(i,iv); conversion inverse to mod2id |
---|
27 | subrInterred(i1,i2,iv);interred w.r.t. a subset of variables |
---|
28 | (parameters in square brackets [] are optional) |
---|
29 | "; |
---|
30 | |
---|
31 | LIB "general.lib"; |
---|
32 | /////////////////////////////////////////////////////////////////////////////// |
---|
33 | |
---|
34 | proc cyclic (int n) |
---|
35 | "USAGE: cyclic(n); n integer |
---|
36 | RETURN: ideal of cyclic n-roots from 1-st n variables of basering |
---|
37 | EXAMPLE: example cyclic; shows examples |
---|
38 | " |
---|
39 | { |
---|
40 | //----------------------------- procedure body -------------------------------- |
---|
41 | ideal m = maxideal(1); |
---|
42 | m = m[1..n],m[1..n]; |
---|
43 | int i,j; |
---|
44 | ideal s; poly t; |
---|
45 | for ( j=0; j<=n-2; j=j+1 ) |
---|
46 | { |
---|
47 | t=0; |
---|
48 | for( i=1;i<=n;i=i+1 ) { t=t+product(m,i..i+j); } |
---|
49 | s=s+t; |
---|
50 | } |
---|
51 | s=s,product(m,1..n)-1; |
---|
52 | return (s); |
---|
53 | } |
---|
54 | //-------------------------------- examples ----------------------------------- |
---|
55 | example |
---|
56 | { "EXAMPLE:"; echo = 2; |
---|
57 | ring r=0,(u,v,w,x,y,z),lp; |
---|
58 | cyclic(nvars(basering)); |
---|
59 | homog(cyclic(5),z); |
---|
60 | } |
---|
61 | /////////////////////////////////////////////////////////////////////////////// |
---|
62 | |
---|
63 | proc katsura |
---|
64 | "USAGE: katsura([n]): n integer |
---|
65 | RETURN: katsura(n) : n-th katsura ideal of |
---|
66 | (1) newly created and set ring (32003, x(0..n), dp), if |
---|
67 | nvars(basering) < n |
---|
68 | (2) basering, if nvars(basering) >= n |
---|
69 | katsura() : katsura ideal of basering |
---|
70 | EXAMPLE: example katsura; shows examples |
---|
71 | " |
---|
72 | { |
---|
73 | int n; |
---|
74 | if ( size(#) == 1 && typeof(#[1]) == "int") |
---|
75 | { |
---|
76 | n = #[1] - 1; |
---|
77 | while (1) |
---|
78 | { |
---|
79 | if (defined(basering)) |
---|
80 | { |
---|
81 | if (nvars(basering) >= #[1]) {break;} |
---|
82 | } |
---|
83 | ring katsura_ring = 32003, x(0..#[1]), dp; |
---|
84 | keepring katsura_ring; |
---|
85 | break; |
---|
86 | } |
---|
87 | } |
---|
88 | else |
---|
89 | { |
---|
90 | n = nvars(basering) -1; |
---|
91 | } |
---|
92 | |
---|
93 | ideal s; |
---|
94 | int i, j; |
---|
95 | poly p; |
---|
96 | |
---|
97 | p = -1; |
---|
98 | for (i = -n; i <= n; i++) |
---|
99 | { |
---|
100 | p = p + kat_var(i, n); |
---|
101 | } |
---|
102 | s[1] = p; |
---|
103 | |
---|
104 | for (i = 0; i < n; i++) |
---|
105 | { |
---|
106 | p = -1 * kat_var(i,n); |
---|
107 | for (j = -n; j <= n; j++) |
---|
108 | { |
---|
109 | p = p + kat_var(j,n) * kat_var(i-j, n); |
---|
110 | } |
---|
111 | s = s,p; |
---|
112 | } |
---|
113 | return (s); |
---|
114 | } |
---|
115 | //-------------------------------- examples ----------------------------------- |
---|
116 | example |
---|
117 | { |
---|
118 | "EXAMPLE:"; echo = 2; |
---|
119 | ring r; basering; |
---|
120 | katsura(); |
---|
121 | katsura(4); basering; |
---|
122 | } |
---|
123 | |
---|
124 | proc kat_var(int i, int n) |
---|
125 | { |
---|
126 | poly p; |
---|
127 | if (i < 0) { i = -i;} |
---|
128 | if (i <= n) { p = var(i+1); } |
---|
129 | return (p); |
---|
130 | } |
---|
131 | /////////////////////////////////////////////////////////////////////////////// |
---|
132 | |
---|
133 | proc freerank |
---|
134 | "USAGE: freerank(M[,any]); M=poly/ideal/vector/module/matrix |
---|
135 | COMPUTE: rank of module presented by M in case it is free. By definition this |
---|
136 | is vdim(coker(M)/m*coker(M)) if coker(M) is free, where m = maximal |
---|
137 | ideal of basering and M is considered as matrix (the 0-module is |
---|
138 | free of rank 0) |
---|
139 | RETURN: rank of coker(M) if coker(M) is free and -1 else; |
---|
140 | in case of a second argument return a list: |
---|
141 | L[1] = rank of coker(M) or -1 |
---|
142 | L[2] = minbase(M) |
---|
143 | NOTE: freerank(syz(M)); computes the rank of M if M is free (and -1 else) |
---|
144 | EXAMPLE: example freerank; shows examples |
---|
145 | " |
---|
146 | { |
---|
147 | int rk; |
---|
148 | def M = simplify(#[1],10); |
---|
149 | resolution mre = res(M,2); |
---|
150 | intmat B = betti(mre); |
---|
151 | if ( ncols(B)>1 ) { rk = -1; } |
---|
152 | else { rk = sum(B[1..nrows(B),1]); } |
---|
153 | if (size(#) == 2) { list L=rk,mre[1]; return(L);} |
---|
154 | return(rk); |
---|
155 | } |
---|
156 | example |
---|
157 | {"EXAMPLE"; echo=2; |
---|
158 | ring r; |
---|
159 | ideal i=x; |
---|
160 | module M=[x,0,1],[-x,0,-1]; |
---|
161 | freerank(M); // should be 2, coker(M) is not free |
---|
162 | freerank(syz (M),""); // [1] should be 1, coker(syz(M))=M is free of rank 1 |
---|
163 | // [2] should be gen(2)+gen(1) (minimal relation of M) |
---|
164 | freerank(i); |
---|
165 | freerank(syz(i)); // should be 1, coker(syz(i))=i is free of rank 1 |
---|
166 | } |
---|
167 | /////////////////////////////////////////////////////////////////////////////// |
---|
168 | |
---|
169 | proc is_homog (id) |
---|
170 | "USAGE: is_homog(id); id poly/ideal/vector/module/matrix |
---|
171 | RETURN: integer which is 1 if input is homogeneous (resp. weighted homogeneous |
---|
172 | if the monomial ordering consists of one block of type ws,Ws,wp or Wp, |
---|
173 | assuming that all weights are positive) and 0 otherwise |
---|
174 | NOTE: A vector is homogeneous, if the components are homogeneous of same |
---|
175 | degree, a module/matrix is homogeneous if all column vectors are |
---|
176 | homogeneous |
---|
177 | //*** ergaenzen, wenn Matrizen-Spalten Gewichte haben |
---|
178 | EXAMPLE: example is_homog; shows examples |
---|
179 | " |
---|
180 | { |
---|
181 | //----------------------------- procedure body -------------------------------- |
---|
182 | module M = module(matrix(id)); |
---|
183 | M = simplify(M,2); // remove 0-columns |
---|
184 | intvec v = ringweights(basering); |
---|
185 | int i,j=1,1; |
---|
186 | for (i=1; i<=ncols(M); i=i+1) |
---|
187 | { |
---|
188 | if( M[i]!=jet(M[i],deg(lead(M[i])),v)-jet(M[i],deg(lead(M[i]))-1,v)) |
---|
189 | { return(0); } |
---|
190 | } |
---|
191 | return(1); |
---|
192 | } |
---|
193 | //-------------------------------- examples ----------------------------------- |
---|
194 | example |
---|
195 | { "EXAMPLE:"; echo = 2; |
---|
196 | ring r = 0,(x,y,z),wp(1,2,3); |
---|
197 | is_homog(x5-yz+y3); |
---|
198 | ideal i = x6+y3+z2, x9-z3; |
---|
199 | is_homog(i); |
---|
200 | ring s = 0,(a,b,c),ds; |
---|
201 | vector v = [a2,0,ac+bc]; |
---|
202 | vector w = [a3,b3,c4]; |
---|
203 | is_homog(v); |
---|
204 | is_homog(w); |
---|
205 | } |
---|
206 | /////////////////////////////////////////////////////////////////////////////// |
---|
207 | |
---|
208 | proc is_zero |
---|
209 | "USAGE: is_zero(M[,any]); M=poly/ideal/vector/module/matrix |
---|
210 | RETURN: integer, 1 if coker(M)=0 resp. 0 if coker(M)!=0, where M is considered |
---|
211 | as matrix |
---|
212 | if a second argument is given, return a list: |
---|
213 | L[1] = 1 if coker(M)=0 resp. 0 if coker(M)!=0 |
---|
214 | L[2] = dim(M) |
---|
215 | EXAMPLE: example is_zero; shows examples |
---|
216 | " |
---|
217 | { |
---|
218 | int d=dim(std(#[1])); |
---|
219 | int a = ( d==-1 ); |
---|
220 | if( size(#) >1 ) { list L=a,d; return(L); } |
---|
221 | return(a); |
---|
222 | } |
---|
223 | example |
---|
224 | { "EXAMPLE:"; echo=2; |
---|
225 | ring r; |
---|
226 | module m = [x],[y],[1,z]; |
---|
227 | is_zero(m,1); |
---|
228 | qring q = std(ideal(x2+y3+z2)); |
---|
229 | ideal j = x2+y3+z2-37; |
---|
230 | is_zero(j); |
---|
231 | } |
---|
232 | //////////////////////////////////////////////////////////////////////////////// |
---|
233 | |
---|
234 | proc maxcoef (f) |
---|
235 | "USAGE: maxcoef(f); f poly/ideal/vector/module/matrix |
---|
236 | RETURN: maximal length of coefficient of f of type int (by counting the |
---|
237 | length of the string of each coefficient) |
---|
238 | EXAMPLE: example maxcoef; shows examples |
---|
239 | " |
---|
240 | { |
---|
241 | //----------------------------- procedure body -------------------------------- |
---|
242 | int max,s,ii,jj; string t; |
---|
243 | ideal i = ideal(matrix(f)); |
---|
244 | i = simplify(i,6); // delete 0's and keep first of equal elements |
---|
245 | poly m = var(1); matrix C; |
---|
246 | for (ii=2;ii<=nvars(basering);ii=ii+1) { m = m*var(ii); } |
---|
247 | for (ii=1; ii<=size(i); ii=ii+1) |
---|
248 | { |
---|
249 | C = coef(i[ii],m); |
---|
250 | for (jj=1; jj<=ncols(C); jj=jj+1) |
---|
251 | { |
---|
252 | t = string(C[2,jj]); s = size(t); |
---|
253 | if ( t[1] == "-" ) { s = s - 1; } |
---|
254 | if ( s > max ) { max = s; } |
---|
255 | } |
---|
256 | } |
---|
257 | return(max); |
---|
258 | } |
---|
259 | //-------------------------------- examples ----------------------------------- |
---|
260 | example |
---|
261 | { "EXAMPLE:"; echo = 2; |
---|
262 | ring r= 0,(x,y,z),ds; |
---|
263 | poly g = 345x2-1234567890y+7/4z; |
---|
264 | maxcoef(g); |
---|
265 | ideal i = g,10/1234567890; |
---|
266 | maxcoef(i); |
---|
267 | // since i[2]=1/123456789 |
---|
268 | } |
---|
269 | /////////////////////////////////////////////////////////////////////////////// |
---|
270 | |
---|
271 | proc maxdeg (id) |
---|
272 | "USAGE: maxdeg(id); id poly/ideal/vector/module/matrix |
---|
273 | RETURN: int/intmat, each component equals maximal degree of monomials in the |
---|
274 | corresponding component of id, independent of ring ordering |
---|
275 | (maxdeg of each var is 1) |
---|
276 | of type int if id is of type poly, of type intmat else |
---|
277 | NOTE: proc maxdeg1 returns 1 integer, the absolut maximum; moreover, it has |
---|
278 | an option for computing weighted degrees |
---|
279 | EXAMPLE: example maxdeg; shows examples |
---|
280 | " |
---|
281 | { |
---|
282 | //-------- subprocedure to find maximal degree of given component ---------- |
---|
283 | proc findmaxdeg |
---|
284 | { |
---|
285 | poly c = #[1]; |
---|
286 | if (c==0) { return(-1); } |
---|
287 | //--- guess upper 'o' and lower 'u' bound, in case of negative weights ----- |
---|
288 | int d = (deg(c)>=0)*deg(c)-(deg(c)<0)*deg(c); |
---|
289 | int i = d; |
---|
290 | while ( c-jet(c,i) != 0 ) { i = 2*(i+1); } |
---|
291 | int o = i-1; |
---|
292 | int u = (d != i)*((i / 2)-1); |
---|
293 | //----------------------- "quick search" for maxdeg ------------------------ |
---|
294 | while ( (c-jet(c,i)==0)*(c-jet(c,i-1)!=0) == 0) |
---|
295 | { |
---|
296 | i = (o+1+u) / 2; |
---|
297 | if (c-jet(c,i)!=0) { u = i+1; } |
---|
298 | else { o = i-1; } |
---|
299 | } |
---|
300 | return(i); |
---|
301 | } |
---|
302 | //------------------------------ main program --------------------------------- |
---|
303 | matrix M = matrix(id); |
---|
304 | int r,c = nrows(M), ncols(M); int i,j; |
---|
305 | intmat m[r][c]; |
---|
306 | for (i=r; i>0; i=i-1) |
---|
307 | { |
---|
308 | for (j=c; j>0; j=j-1) { m[i,j] = findmaxdeg(M[i,j]); } |
---|
309 | } |
---|
310 | if (typeof(id)=="poly") { return(m[1,1]); } |
---|
311 | return(m); |
---|
312 | } |
---|
313 | //-------------------------------- examples ----------------------------------- |
---|
314 | example |
---|
315 | { "EXAMPLE:"; echo = 2; |
---|
316 | ring r = 0,(x,y,z),wp(-1,-2,-3); |
---|
317 | poly f = x+y2+z3; |
---|
318 | deg(f); //deg; returns weighted degree (in case of 1 block)! |
---|
319 | maxdeg(f); |
---|
320 | matrix m[2][2]=f+x10,1,0,f^2; |
---|
321 | maxdeg(m); |
---|
322 | } |
---|
323 | /////////////////////////////////////////////////////////////////////////////// |
---|
324 | |
---|
325 | proc maxdeg1 (id,list #) |
---|
326 | "USAGE: maxdeg1(id[,v]); id=poly/ideal/vector/module/matrix, v=intvec |
---|
327 | RETURN: integer, maximal [weighted] degree of monomials of id independent of |
---|
328 | ring ordering, maxdeg1 of i-th variable is v[i] (default: v=1..1). |
---|
329 | NOTE: This proc returns one integer while maxdeg returns, in general, |
---|
330 | a matrix of integers. For one polynomial and if no intvec v is given |
---|
331 | maxdeg is faster |
---|
332 | EXAMPLE: example maxdeg1; shows examples |
---|
333 | " |
---|
334 | { |
---|
335 | //-------- subprocedure to find maximal degree of given component ---------- |
---|
336 | proc findmaxdeg |
---|
337 | { |
---|
338 | poly c = #[1]; |
---|
339 | if (c==0) { return(-1); } |
---|
340 | intvec v = #[2]; |
---|
341 | //--- guess upper 'o' and lower 'u' bound, in case of negative weights ----- |
---|
342 | int d = (deg(c)>=0)*deg(c)-(deg(c)<0)*deg(c); |
---|
343 | int i = d; |
---|
344 | if ( c == jet(c,-1,v)) //case: maxdeg is negative |
---|
345 | { |
---|
346 | i = -d; |
---|
347 | while ( c == jet(c,i,v) ) { i = 2*(i-1); } |
---|
348 | int o = (d != -i)*((i / 2)+2) - 1; |
---|
349 | int u = i+1; |
---|
350 | int e = -1; |
---|
351 | } |
---|
352 | else //case: maxdeg is nonnegative |
---|
353 | { |
---|
354 | while ( c != jet(c,i,v) ) { i = 2*(i+1); } |
---|
355 | int o = i-1; |
---|
356 | int u = (d != i)*((i / 2)-1); |
---|
357 | int e = 1; |
---|
358 | } |
---|
359 | //----------------------- "quick search" for maxdeg ------------------------ |
---|
360 | while ( ( c==jet(c,i,v) )*( c!=jet(c,i-1,v) ) == 0 ) |
---|
361 | { |
---|
362 | i = (o+e+u) / 2; |
---|
363 | if ( c!=jet(c,i,v) ) { u = i+1; } |
---|
364 | else { o = i-1; } |
---|
365 | } |
---|
366 | return(i); |
---|
367 | } |
---|
368 | //------------------------------ main program --------------------------------- |
---|
369 | ideal M = simplify(ideal(matrix(id)),8); //delete scalar multiples from id |
---|
370 | int c = ncols(M); |
---|
371 | int i,n; |
---|
372 | if( size(#)==0 ) |
---|
373 | { |
---|
374 | int m = maxdeg(M[c]); |
---|
375 | for (i=c-1; i>0; i=i-1) |
---|
376 | { |
---|
377 | n = maxdeg(M[i]); |
---|
378 | m = (m>=n)*m + (m<n)*n; //let m be the maximum of m and n |
---|
379 | } |
---|
380 | } |
---|
381 | else |
---|
382 | { |
---|
383 | intvec v=#[1]; //weight vector for the variables |
---|
384 | int m = findmaxdeg(M[c],v); |
---|
385 | for (i=c-1; i>0; i--) |
---|
386 | { |
---|
387 | n = findmaxdeg(M[i],v); |
---|
388 | if( n>m ) { m=n; } |
---|
389 | } |
---|
390 | } |
---|
391 | return(m); |
---|
392 | } |
---|
393 | //-------------------------------- examples ----------------------------------- |
---|
394 | example |
---|
395 | { "EXAMPLE:"; echo = 2; |
---|
396 | ring r = 0,(x,y,z),wp(-1,-2,-3); |
---|
397 | poly f = x+y2+z3; |
---|
398 | deg(f); //deg returns weighted degree (in case of 1 block)! |
---|
399 | maxdeg1(f); |
---|
400 | intvec v = ringweights(r); |
---|
401 | maxdeg1(f,v); //weighted maximal degree |
---|
402 | matrix m[2][2]=f+x10,1,0,f^2; |
---|
403 | maxdeg1(m,v); //absolut weighted maximal degree |
---|
404 | } |
---|
405 | /////////////////////////////////////////////////////////////////////////////// |
---|
406 | |
---|
407 | proc mindeg (id) |
---|
408 | "USAGE: mindeg(id); id poly/ideal/vector/module/matrix |
---|
409 | RETURN: minimal degree/s of monomials of id, independent of ring ordering |
---|
410 | (mindeg of each variable is 1) of type int if id of type poly, else |
---|
411 | of type intmat. |
---|
412 | NOTE: proc mindeg1 returns one integer, the absolut minimum; moreover it |
---|
413 | has an option for computing weighted degrees. |
---|
414 | EXAMPLE: example mindeg; shows examples |
---|
415 | " |
---|
416 | { |
---|
417 | //--------- subprocedure to find minimal degree of given component --------- |
---|
418 | proc findmindeg |
---|
419 | { |
---|
420 | poly c = #[1]; |
---|
421 | if (c==0) { return(-1); } |
---|
422 | //--- guess upper 'o' and lower 'u' bound, in case of negative weights ----- |
---|
423 | int d = (ord(c)>=0)*ord(c)-(ord(c)<0)*ord(c); |
---|
424 | int i = d; |
---|
425 | while ( jet(c,i) == 0 ) { i = 2*(i+1); } |
---|
426 | int o = i-1; |
---|
427 | int u = (d != i)*((i / 2)-1); |
---|
428 | //----------------------- "quick search" for mindeg ------------------------ |
---|
429 | while ( (jet(c,u)==0)*(jet(c,o)!=0) ) |
---|
430 | { |
---|
431 | i = (o+u) / 2; |
---|
432 | if (jet(c,i)==0) { u = i+1; } |
---|
433 | else { o = i-1; } |
---|
434 | } |
---|
435 | if (jet(c,u)!=0) { return(u); } |
---|
436 | else { return(o+1); } |
---|
437 | } |
---|
438 | //------------------------------ main program --------------------------------- |
---|
439 | matrix M = matrix(id); |
---|
440 | int r,c = nrows(M), ncols(M); int i,j; |
---|
441 | intmat m[r][c]; |
---|
442 | for (i=r; i>0; i=i-1) |
---|
443 | { |
---|
444 | for (j=c; j>0; j=j-1) { m[i,j] = findmindeg(M[i,j]); } |
---|
445 | } |
---|
446 | if (typeof(id)=="poly") { return(m[1,1]); } |
---|
447 | return(m); |
---|
448 | } |
---|
449 | //-------------------------------- examples ----------------------------------- |
---|
450 | example |
---|
451 | { "EXAMPLE:"; echo = 2; |
---|
452 | ring r = 0,(x,y,z),ls; |
---|
453 | poly f = x5+y2+z3; |
---|
454 | ord(f); // ord returns weighted order of leading term! |
---|
455 | mindeg(f); // computes minimal degree |
---|
456 | matrix m[2][2]=x10,1,0,f^2; |
---|
457 | mindeg(m); // computes matrix of minimum degrees |
---|
458 | } |
---|
459 | /////////////////////////////////////////////////////////////////////////////// |
---|
460 | |
---|
461 | proc mindeg1 (id, list #) |
---|
462 | "USAGE: mindeg1(id[,v]); id=poly/ideal/vector/module/matrix, v=intvec |
---|
463 | RETURN: integer, minimal [weighted] degree of monomials of id independent of |
---|
464 | ring ordering, mindeg1 of i-th variable is v[i] (default v=1..1). |
---|
465 | NOTE: This proc returns one integer while mindeg returns, in general, |
---|
466 | a matrix of integers. For one polynomial and if no intvec v is given |
---|
467 | mindeg is faster. |
---|
468 | EXAMPLE: example mindeg1; shows examples |
---|
469 | " |
---|
470 | { |
---|
471 | //--------- subprocedure to find minimal degree of given component --------- |
---|
472 | proc findmindeg |
---|
473 | { |
---|
474 | poly c = #[1]; |
---|
475 | intvec v = #[2]; |
---|
476 | if (c==0) { return(-1); } |
---|
477 | //--- guess upper 'o' and lower 'u' bound, in case of negative weights ----- |
---|
478 | int d = (ord(c)>=0)*ord(c)-(ord(c)<0)*ord(c); |
---|
479 | int i = d; |
---|
480 | if ( jet(c,-1,v) !=0 ) //case: mindeg is negative |
---|
481 | { |
---|
482 | i = -d; |
---|
483 | while ( jet(c,i,v) != 0 ) { i = 2*(i-1); } |
---|
484 | int o = (d != -i)*((i / 2)+2) - 1; |
---|
485 | int u = i+1; |
---|
486 | int e = -1; i=u; |
---|
487 | } |
---|
488 | else //case: inded is nonnegative |
---|
489 | { |
---|
490 | while ( jet(c,i,v) == 0 ) { i = 2*(i+1); } |
---|
491 | int o = i-1; |
---|
492 | int u = (d != i)*((i / 2)-1); |
---|
493 | int e = 1; i=u; |
---|
494 | } |
---|
495 | //----------------------- "quick search" for mindeg ------------------------ |
---|
496 | while ( (jet(c,i-1,v)==0)*(jet(c,i,v)!=0) == 0 ) |
---|
497 | { |
---|
498 | i = (o+e+u) / 2; |
---|
499 | if (jet(c,i,v)==0) { u = i+1; } |
---|
500 | else { o = i-1; } |
---|
501 | } |
---|
502 | return(i); |
---|
503 | } |
---|
504 | //------------------------------ main program --------------------------------- |
---|
505 | ideal M = simplify(ideal(matrix(id)),8); //delete scalar multiples from id |
---|
506 | int c = ncols(M); |
---|
507 | int i,n; |
---|
508 | if( size(#)==0 ) |
---|
509 | { |
---|
510 | int m = mindeg(M[c]); |
---|
511 | for (i=c-1; i>0; i=i-1) |
---|
512 | { |
---|
513 | n = mindeg(M[i]); |
---|
514 | m = (m<=n)*m + (m>n)*n; //let m be the maximum of m and n |
---|
515 | } |
---|
516 | } |
---|
517 | else |
---|
518 | { |
---|
519 | intvec v=#[1]; //weight vector for the variables |
---|
520 | int m = findmindeg(M[c],v); |
---|
521 | for (i=c-1; i>0; i=i-1) |
---|
522 | { |
---|
523 | n = findmindeg(M[i],v); |
---|
524 | m = (m<=n)*m + (m>n)*n; //let m be the maximum of m and n |
---|
525 | } |
---|
526 | } |
---|
527 | return(m); |
---|
528 | } |
---|
529 | //-------------------------------- examples ----------------------------------- |
---|
530 | example |
---|
531 | { "EXAMPLE:"; echo = 2; |
---|
532 | ring r = 0,(x,y,z),ls; |
---|
533 | poly f = x5+y2+z3; |
---|
534 | ord(f); // ord returns weighted order of leading term! |
---|
535 | intvec v = 1,-3,2; |
---|
536 | mindeg1(f,v); // computes minimal weighted degree |
---|
537 | matrix m[2][2]=x10,1,0,f^2; |
---|
538 | mindeg1(m,1..3); // computes absolut minimum of weighted degrees |
---|
539 | } |
---|
540 | /////////////////////////////////////////////////////////////////////////////// |
---|
541 | |
---|
542 | proc normalize (id) |
---|
543 | "USAGE: normalize(id); id=poly/vector/ideal/module |
---|
544 | RETURN: object of same type with leading coefficient equal to 1 |
---|
545 | EXAMPLE: example normalize; shows an example |
---|
546 | " |
---|
547 | { |
---|
548 | return(simplify(id,1)); |
---|
549 | } |
---|
550 | //-------------------------------- examples ----------------------------------- |
---|
551 | example |
---|
552 | { "EXAMPLE:"; echo = 2; |
---|
553 | ring r = 0,(x,y,z),ls; |
---|
554 | poly f = 2x5+3y2+4z3; |
---|
555 | normalize(f); |
---|
556 | module m=[9xy,0,3z3],[4z,6y,2x]; |
---|
557 | normalize(m); |
---|
558 | ring s = 0,(x,y,z),(c,ls); |
---|
559 | module m=[9xy,0,3z3],[4z,6y,2x]; |
---|
560 | normalize(m); |
---|
561 | normalize(matrix(m)); // by automatic type conversion to module! |
---|
562 | } |
---|
563 | /////////////////////////////////////////////////////////////////////////////// |
---|
564 | |
---|
565 | //////////////////////////////////////////////////////////////////////////////// |
---|
566 | // Input: <ideal>=<f1,f2,...,fm> and <polynomial> g |
---|
567 | // Question: Does g lie in the radical of <ideal>? |
---|
568 | // Solution: Compute a standard basis G for <f1,f2,...,fm,gz-1> where z is a new |
---|
569 | // variable. Then g is contained in the radical of <ideal> <=> 1 is |
---|
570 | // generator in G. |
---|
571 | //////////////////////////////////////////////////////////////////////////////// |
---|
572 | proc rad_con (poly g,ideal I) |
---|
573 | " USAGE: rad_con(<poly>,<ideal>); |
---|
574 | RETURNS: 1 (TRUE) (type <int>) if <poly> is contained in the radical of |
---|
575 | <ideal>, 0 (FALSE) (type <int>) otherwise |
---|
576 | EXAMPLE: example rad_con; shows an example |
---|
577 | " |
---|
578 | { def br=basering; |
---|
579 | int n=nvars(br); |
---|
580 | int dB=degBound; |
---|
581 | degBound=0; |
---|
582 | string mp=string(minpoly); |
---|
583 | execute("ring R=("+charstr(br)+"),(x(1..n),z),dp;"); |
---|
584 | execute("minpoly=number("+mp+");"); |
---|
585 | ideal irrel=x(1..n); |
---|
586 | map f=br,irrel; |
---|
587 | poly p=f(g); |
---|
588 | ideal J=f(I)+ideal(p*z-1); |
---|
589 | J=std(J); |
---|
590 | degBound=dB; |
---|
591 | if (J[1]==1) |
---|
592 | { return(1); |
---|
593 | } |
---|
594 | else |
---|
595 | { return(0); |
---|
596 | } |
---|
597 | } |
---|
598 | example |
---|
599 | { " EXAMPLE: Sturmfels: Algorithms in Invariant Theory 2.3.7."; |
---|
600 | echo=2; |
---|
601 | ring R=0,(x,y,z),dp; |
---|
602 | ideal I=x2+y2,z2; |
---|
603 | poly f=x4+y4; |
---|
604 | rad_con(f,I); |
---|
605 | ideal J=x2+y2,z2,x4+y4; |
---|
606 | poly g=z; |
---|
607 | rad_con(g,I); |
---|
608 | } |
---|
609 | |
---|
610 | /////////////////////////////////////////////////////////////////////////////// |
---|
611 | |
---|
612 | proc lcm (ideal i) |
---|
613 | "USAGE: lcm(i); i ideal |
---|
614 | RETURN: poly = lcm(i[1],...,i[size(i)]) |
---|
615 | NOTE: |
---|
616 | EXAMPLE: example lcm; shows an example |
---|
617 | " |
---|
618 | { |
---|
619 | int k,j; |
---|
620 | poly p,q; |
---|
621 | i=simplify(i,10); |
---|
622 | for(j=1;j<=size(i);j++) |
---|
623 | { |
---|
624 | if(deg(i[j])>0) |
---|
625 | { |
---|
626 | p=i[j]; |
---|
627 | break; |
---|
628 | } |
---|
629 | } |
---|
630 | if(deg(p)==-1) |
---|
631 | { |
---|
632 | return(1); |
---|
633 | } |
---|
634 | for (k=j+1;k<=size(i);k++) |
---|
635 | { |
---|
636 | if(deg(i[k])!=0) |
---|
637 | { |
---|
638 | q=gcd(p,i[k]); |
---|
639 | if(deg(q)==0) |
---|
640 | { |
---|
641 | p=p*i[k]; |
---|
642 | } |
---|
643 | else |
---|
644 | { |
---|
645 | p=p/q; |
---|
646 | p=p*i[k]; |
---|
647 | } |
---|
648 | } |
---|
649 | } |
---|
650 | return(p); |
---|
651 | } |
---|
652 | example |
---|
653 | { "EXAMPLE:"; echo = 2; |
---|
654 | ring r = 0,(x,y,z),lp; |
---|
655 | poly p = (x+y)*(y+z); |
---|
656 | poly q = (z4+2)*(y+z); |
---|
657 | ideal l=p,q; |
---|
658 | poly pr= lcm(l); |
---|
659 | pr; |
---|
660 | l=1,-1,p,1,-1,q,1; |
---|
661 | pr=lcm(l); |
---|
662 | pr; |
---|
663 | } |
---|
664 | |
---|
665 | /////////////////////////////////////////////////////////////////////////////// |
---|
666 | |
---|
667 | proc content(f) |
---|
668 | "USAGE: content(f); f polynomial/vector |
---|
669 | RETURN: number, the content (greatest common factor of coefficients) |
---|
670 | of the polynomial/vector f |
---|
671 | EXAMPLE: example content; shows an example |
---|
672 | " |
---|
673 | { |
---|
674 | return(leadcoef(f)/leadcoef(cleardenom(f))); |
---|
675 | } |
---|
676 | example |
---|
677 | { "EXAMPLE:"; echo = 2; |
---|
678 | ring r=0,(x,y,z),(c,lp); |
---|
679 | content(3x2+18xy-27xyz); |
---|
680 | vector v=[3x2+18xy-27xyz,15x2+12y4,3]; |
---|
681 | content(v); |
---|
682 | } |
---|
683 | /////////////////////////////////////////////////////////////////////////////// |
---|
684 | |
---|
685 | |
---|
686 | proc numerator(number n) |
---|
687 | "USAGE: numerator(n); n number |
---|
688 | RETURN: number, the numerator of n |
---|
689 | SEE ALSO: denominator, content, cleardenom |
---|
690 | EXAMPLE: example numerator; shows an example |
---|
691 | " |
---|
692 | { |
---|
693 | poly p = cleardenom(n+var(1)); |
---|
694 | return (coeffs(p,var(1))[1,1]); |
---|
695 | } |
---|
696 | example |
---|
697 | { |
---|
698 | "EXAMPLE:"; echo = 2; |
---|
699 | ring r = 0,x, dp; |
---|
700 | number n = 3/2; |
---|
701 | numerator(n); |
---|
702 | } |
---|
703 | |
---|
704 | proc denominator(number n) |
---|
705 | "USAGE: denominator(n); n number |
---|
706 | RETURN: number, the denominator of n |
---|
707 | SEE ALSO: denominator, content, cleardenom |
---|
708 | EXAMPLE: example denominator; shows an example |
---|
709 | " |
---|
710 | { |
---|
711 | poly p = cleardenom(n+var(1)); |
---|
712 | return (coeffs(p,var(1))[2,1]); |
---|
713 | } |
---|
714 | example |
---|
715 | { |
---|
716 | "EXAMPLE:"; echo = 2; |
---|
717 | ring r = 0,x, dp; |
---|
718 | number n = 3/2; |
---|
719 | denominator(n); |
---|
720 | } |
---|
721 | //////////////////////////////////////////////////////////////////////// |
---|
722 | |
---|
723 | proc mod2id(matrix M,intvec vpos) |
---|
724 | "USAGE: mod2id(M,vpos); M matrix, vpos intvec |
---|
725 | ASSUME: vpos is an integer vector such that gen(i) corresponds |
---|
726 | to var(vpos[i]) |
---|
727 | the basering contains variables var(vpos[i]) which do not occur |
---|
728 | in M |
---|
729 | NOTE: this procedure should be used in the following situation: |
---|
730 | one wants to pass to a ring with new variables, say e(1),..,e(s), |
---|
731 | which correspond to the components gen(1),..,gen(s) of the |
---|
732 | module M such that e(i)*e(j)=0 for all i,j |
---|
733 | the new ring should already exist and be the current ring |
---|
734 | RETURN: ideal i in which each gen(i) from the module is replaced by |
---|
735 | var(vpos[i]) and all monomials var(vpos[i])*var(vpos[j]) have |
---|
736 | been added to the generating set of i |
---|
737 | EXAMPLE: example mod2id; shows an example" |
---|
738 | { |
---|
739 | int p = printlevel-voice+3; // p=printlevel+1 (default: p=1) |
---|
740 | //---------------------------------------------------------------------- |
---|
741 | // define the ideal generated by the var(vpos[i]) and set up the matrix |
---|
742 | // for the multiplication |
---|
743 | //---------------------------------------------------------------------- |
---|
744 | ideal vars=var(vpos[1]); |
---|
745 | for(int i=2;i<=size(vpos);i++) |
---|
746 | { |
---|
747 | vars=vars,var(vpos[i]); |
---|
748 | } |
---|
749 | matrix varm[1][size(vpos)]=vars; |
---|
750 | if (size(vpos) > nrows(M)) |
---|
751 | { |
---|
752 | matrix Mt[size(vpos)][ncols(M)]; |
---|
753 | Mt[1..nrows(M),1..ncols(M)]=M; |
---|
754 | kill M; |
---|
755 | matrix M=Mt; |
---|
756 | } |
---|
757 | //---------------------------------------------------------------------- |
---|
758 | // define the desired ideal |
---|
759 | //---------------------------------------------------------------------- |
---|
760 | ideal ret=vars^2,varm*M; |
---|
761 | return(ret); |
---|
762 | } |
---|
763 | example |
---|
764 | { "EXAMPLE:"; echo=2; |
---|
765 | ring r=0,(e(1),e(2),x,y,z),(dp(2),ds(3)); |
---|
766 | module mo=x*gen(1)+y*gen(2); |
---|
767 | intvec iv=2,1; |
---|
768 | mod2id(mo,iv); |
---|
769 | } |
---|
770 | //////////////////////////////////////////////////////////////////////// |
---|
771 | |
---|
772 | proc id2mod(ideal i,intvec vpos) |
---|
773 | "USAGE: id2mod(I,vpos); I ideal, vpos intvec |
---|
774 | NOTE: * use this procedure only makes sense if the ideal contains |
---|
775 | all var(vpos[i])*var(vpos[j]) as monomial generators and |
---|
776 | all other generators are linear combinations of the |
---|
777 | var(vpos[i]) over the ring in the other variables |
---|
778 | * this is the inverse procedure to mod2id and should be applied |
---|
779 | only to ideals created by mod2id using the same intvec vpos |
---|
780 | (possibly after a standard basis computation) |
---|
781 | RETURN: module corresponding to the ideal by replacing var(vpos[i]) by |
---|
782 | gen(i) and omitting all generators var(vpos[i])*var(vpos[j]) |
---|
783 | EXAMPLE: example id2mod; shows an example" |
---|
784 | { |
---|
785 | int p = printlevel-voice+3; // p=printlevel+1 (default: p=1) |
---|
786 | //--------------------------------------------------------------------- |
---|
787 | // Initialization |
---|
788 | //--------------------------------------------------------------------- |
---|
789 | int n=size(i); |
---|
790 | int v=size(vpos); |
---|
791 | matrix tempmat; |
---|
792 | matrix mm[v][n]; |
---|
793 | //--------------------------------------------------------------------- |
---|
794 | // Conversion |
---|
795 | //--------------------------------------------------------------------- |
---|
796 | for(int j=1;j<=v;j++) |
---|
797 | { |
---|
798 | tempmat=coeffs(i,var(vpos[j])); |
---|
799 | mm[j,1..n]=tempmat[2,1..n]; |
---|
800 | } |
---|
801 | for(j=1;j<=v;j++) |
---|
802 | { |
---|
803 | mm=subst(mm,var(vpos[j]),0); |
---|
804 | } |
---|
805 | module ret=simplify(mm,10); |
---|
806 | return(ret); |
---|
807 | } |
---|
808 | example |
---|
809 | { "EXAMPLE:"; echo=2; |
---|
810 | ring r=0,(e(1),e(2),x,y,z),(dp(2),ds(3)); |
---|
811 | ideal i=e(2)^2,e(1)*e(2),e(1)^2,e(1)*y+e(2)*x; |
---|
812 | intvec iv=2,1; |
---|
813 | id2mod(i,iv); |
---|
814 | } |
---|
815 | /////////////////////////////////////////////////////////////////////// |
---|
816 | |
---|
817 | proc subrInterred(ideal mon, ideal sm, intvec iv) |
---|
818 | "USAGE: subrInterred(mon,sm,iv); |
---|
819 | sm: ideal in a ring r with n + s variables, |
---|
820 | e.g. x_1,..,x_n and t_1,..,t_s |
---|
821 | mon: ideal with monomial generators (not divisible by |
---|
822 | one of the t_i) such that sm is contained in the module |
---|
823 | k[t_1,..,t_s]*mon[1]+..+k[t_1,..,t_s]*mon[size(mon)] |
---|
824 | iv: intvec listing the variables which are supposed to be used |
---|
825 | as x_i |
---|
826 | RETURN: list l: |
---|
827 | l[1]=the monomials from mon in the order used |
---|
828 | l[2]=their coefficients after interreduction |
---|
829 | l[3]=l[1]*l[2] |
---|
830 | (interreduced system of generators of sm seen as a submodule |
---|
831 | of k[t_1,..,t_s]*mon[1]+..+k[t_1,..,t_s]*mon[size(mon)]) |
---|
832 | EXAMPLE: example subrInterred; shows an example" |
---|
833 | { |
---|
834 | int p = printlevel-voice+3; // p=printlevel+1 (default: p=1) |
---|
835 | //----------------------------------------------------------------------- |
---|
836 | // check that mon is really generated by monomials |
---|
837 | // and sort its generators with respect to the monomial ordering |
---|
838 | //----------------------------------------------------------------------- |
---|
839 | int err; |
---|
840 | for(int i=1;i<=ncols(mon);i++) |
---|
841 | { |
---|
842 | if ( size(mon[i]) > 1 ) |
---|
843 | { |
---|
844 | err=1; |
---|
845 | } |
---|
846 | } |
---|
847 | if (err==1) |
---|
848 | { |
---|
849 | ERROR("mon has to be generated by monomials"); |
---|
850 | } |
---|
851 | intvec sv=sortvec(mon); |
---|
852 | ideal mons; |
---|
853 | for(i=1;i<=size(sv);i++) |
---|
854 | { |
---|
855 | mons[i]=mon[sv[i]]; |
---|
856 | } |
---|
857 | ideal itemp=maxideal(1); |
---|
858 | for(i=1;i<=size(iv);i++) |
---|
859 | { |
---|
860 | itemp=subst(itemp,var(iv[i]),0); |
---|
861 | } |
---|
862 | itemp=simplify(itemp,10); |
---|
863 | def r=basering; |
---|
864 | string tempstr="ring rtemp=" + charstr(basering) + ",(" + string(itemp) |
---|
865 | + "),(C,dp);"; |
---|
866 | //----------------------------------------------------------------------- |
---|
867 | // express m in terms of the generators of mon and check whether m |
---|
868 | // can be considered as a submodule of k[t_1,..,t_n]*mon |
---|
869 | //----------------------------------------------------------------------- |
---|
870 | module motemp; |
---|
871 | motemp[ncols(sm)]=0; |
---|
872 | poly ptemp; |
---|
873 | int j; |
---|
874 | for(i=1;i<=ncols(mons);i++) |
---|
875 | { |
---|
876 | for(j=1;j<=ncols(sm);j++) |
---|
877 | { |
---|
878 | ptemp=sm[j]/mons[i]; |
---|
879 | motemp[j]=motemp[j]+ptemp*gen(i); |
---|
880 | } |
---|
881 | } |
---|
882 | for(i=1;i<=size(iv);i++) |
---|
883 | { |
---|
884 | motemp=subst(motemp,var(iv[i]),0); |
---|
885 | } |
---|
886 | matrix monmat[1][ncols(mons)]=mons; |
---|
887 | ideal dummy=monmat*motemp; |
---|
888 | for(i=1;i<=size(sm);i++) |
---|
889 | { |
---|
890 | if(sm[i]-dummy[i]!=0) |
---|
891 | { |
---|
892 | ERROR("the second argument is not a submodule of the assumed structure"); |
---|
893 | } |
---|
894 | } |
---|
895 | //---------------------------------------------------------------------- |
---|
896 | // do the interreduction and convert back |
---|
897 | //---------------------------------------------------------------------- |
---|
898 | execute(tempstr); |
---|
899 | def motemp=imap(r,motemp); |
---|
900 | motemp=interred(motemp); |
---|
901 | setring r; |
---|
902 | kill motemp; |
---|
903 | def motemp=imap(rtemp,motemp); |
---|
904 | list ret=monmat,motemp,monmat*motemp; |
---|
905 | for(i=1;i<=ncols(ret[2]);i++) |
---|
906 | { |
---|
907 | ret[2][i]=cleardenom(ret[2][i]); |
---|
908 | } |
---|
909 | for(i=1;i<=ncols(ret[3]);i++) |
---|
910 | { |
---|
911 | ret[3][i]=cleardenom(ret[3][i]); |
---|
912 | } |
---|
913 | return(ret); |
---|
914 | } |
---|
915 | example |
---|
916 | { "EXAMPLE:"; echo=2; |
---|
917 | ring r=0,(x,y,z),dp; |
---|
918 | ideal i=x^2+x*y^2,x*y+x^2*y,z; |
---|
919 | ideal j=x^2+x*y^2,x*y,z; |
---|
920 | ideal mon=x^2,z,x*y; |
---|
921 | intvec iv=1,3; |
---|
922 | subrInterred(mon,i,iv); |
---|
923 | subrInterred(mon,j,iv); |
---|
924 | } |
---|
925 | //////////////////////////////////////////////////////////////////////// |
---|
926 | |
---|
927 | |
---|
928 | |
---|