1 | // $Id: |
---|
2 | //GMG, last modified 28.9.01 |
---|
3 | /////////////////////////////////////////////////////////////////////////////// |
---|
4 | version="$Id: teachstd.lib,v 1.2 2006-05-19 10:27:07 Singular Exp $"; |
---|
5 | category="Teaching"; |
---|
6 | info=" |
---|
7 | LIBRARY: teachstd.lib Procedures for teaching standard bases |
---|
8 | AUTHOR: G.-M. Greuel, greuel@mathematik.uni-kl.de |
---|
9 | |
---|
10 | ecart(f); ecart of f |
---|
11 | tail(f); tail of f |
---|
12 | sameComponent(f,g); test for same module component of lead(f) and lead(g) |
---|
13 | leadmonomial(f); leading monomial as poly (also for vectors) |
---|
14 | monomialLcm(m,n); lcm of monomials m and n as poly (also for vectors) |
---|
15 | spoly(f[,1]); s-polynomial of f [symmetric form] |
---|
16 | minEcart(T,h); element g from T of minimal ecart s.t. LM(g)|LM(h) |
---|
17 | NFMora(i); normal form of i w.r.t Mora algorithm |
---|
18 | prodcrit(f,g); test for product criterion |
---|
19 | chaincrit(f,g,h); test for chain criterion |
---|
20 | pairset(G); pairs form G neither satifying prodcrit nor chaincrit |
---|
21 | updatePairs(P,S,h); pairset P enlarded by not useless pairs (h,f), f in S |
---|
22 | standard(id); standard basis of ideal/module |
---|
23 | localstd(id); local standard basis of id using Lazard's method |
---|
24 | [parameters in square brackets are optional] |
---|
25 | |
---|
26 | NOTE: The library is intended to be used for teaching purposes but not |
---|
27 | for serious computations. Sufficiently high printlevel allows to |
---|
28 | control each step, thus illustrating the algorithms at work. |
---|
29 | The procedures are implemented exatly as described in the book |
---|
30 | 'A SINGULAR Introduction to Commutative Algebra' by G.-M. Greuel and |
---|
31 | G. Pfister (Springer 2002). |
---|
32 | "; |
---|
33 | |
---|
34 | LIB "poly.lib"; |
---|
35 | |
---|
36 | /////////////////////////////////////////////////////////////////////////////// |
---|
37 | proc ecart(f) |
---|
38 | "USAGE: ecart(f); f poly or vector |
---|
39 | RETURN: the ecart e of f of type int |
---|
40 | EXAMPLE: example ecart; shows an example |
---|
41 | " |
---|
42 | { |
---|
43 | int e = maxdeg1(f)-maxdeg1(lead(f)); |
---|
44 | return(e); |
---|
45 | } |
---|
46 | example |
---|
47 | { "EXAMPLE:"; echo = 2; |
---|
48 | ring r=0,(x,y,z),ls; |
---|
49 | ecart((y+z+x+xyz)**2); |
---|
50 | ring s=0,(x,y,z),dp; |
---|
51 | ecart((y+z+x+xyz)**2); |
---|
52 | } |
---|
53 | /////////////////////////////////////////////////////////////////////////////// |
---|
54 | proc leadmonomial(f) |
---|
55 | "USAGE: leadmonomial(f); f poly or vector |
---|
56 | RETURN: the leading monomial of f of type poly |
---|
57 | NOTE: if f is of type poly, leadmonomial(f)=leadmonom(f), if f is of type |
---|
58 | vector and if leadmonom(f)=m*gen(i) then leadmonomial(f)=m |
---|
59 | EXAMPLE: example leadmonomial; shows an example |
---|
60 | " |
---|
61 | { |
---|
62 | int e; |
---|
63 | poly m; |
---|
64 | if(typeof(f) == "vector") |
---|
65 | { |
---|
66 | e=leadexp(f)[nvars(basering)+1]; |
---|
67 | m=leadmonom(f)[e,1]; |
---|
68 | } |
---|
69 | if(typeof(f) == "poly") |
---|
70 | { |
---|
71 | m=leadmonom(f); |
---|
72 | } |
---|
73 | return(m); |
---|
74 | } |
---|
75 | example |
---|
76 | { "EXAMPLE:"; echo = 2; |
---|
77 | ring s=0,(x,y,z),(c,dp); |
---|
78 | leadmonomial((y+z+x+xyz)**2); |
---|
79 | leadmonomial([(y+z+x+xyz)**2,xyz5]); |
---|
80 | } |
---|
81 | /////////////////////////////////////////////////////////////////////////////// |
---|
82 | proc tail(f) |
---|
83 | "USAGE: tail(f); f poly or vector |
---|
84 | RETURN: f-lead(f), the tail of f of type poly |
---|
85 | EXAMPLE: example tail; shows an example |
---|
86 | " |
---|
87 | { |
---|
88 | def t = f-lead(f); |
---|
89 | return(t); |
---|
90 | } |
---|
91 | example |
---|
92 | { "EXAMPLE:"; echo = 2; |
---|
93 | ring r=0,(x,y,z),ls; |
---|
94 | tail((y+z+x+xyz)**2); |
---|
95 | ring s=0,(x,y,z),dp; |
---|
96 | tail((y+z+x+xyz)**2); |
---|
97 | } |
---|
98 | /////////////////////////////////////////////////////////////////////////////// |
---|
99 | proc sameComponent(f,g) |
---|
100 | "USAGE: sameComponent(f,g); f,g poly or vector |
---|
101 | RETURN: 1 if f and g are of type poly or if f and g are of type vector and |
---|
102 | their leading monomials involve the same module component, |
---|
103 | 0 if not |
---|
104 | EXAMPLE: example sameComponent; shows an example |
---|
105 | " |
---|
106 | { |
---|
107 | if(typeof(f) != typeof(g)) |
---|
108 | { |
---|
109 | ERROR("** arguments must be of same type"); |
---|
110 | } |
---|
111 | if(typeof(f) == "vector") |
---|
112 | { |
---|
113 | if( leadexp(f)[nvars(basering)+1] != leadexp(g)[nvars(basering)+1] ) |
---|
114 | { |
---|
115 | return(0); |
---|
116 | } |
---|
117 | } |
---|
118 | return(1); |
---|
119 | } |
---|
120 | example |
---|
121 | { "EXAMPLE:"; echo = 2; |
---|
122 | ring r=0,(x,y,z),dp; |
---|
123 | sameComponent([y+z+x,xyz],[z2,xyz]); |
---|
124 | sameComponent([y+z+x,xyz],[z4,xyz]); |
---|
125 | sameComponent(y+z+x+xyz, xy+z5); |
---|
126 | } |
---|
127 | /////////////////////////////////////////////////////////////////////////////// |
---|
128 | proc monomialLcm(m,n) |
---|
129 | "USAGE: monomialLcm(m,n); m,n of type poly or vector |
---|
130 | RETURN: least common multiple of leading monomials of m and n, of type poly |
---|
131 | NOTE: if m = (x1...xr)^(a1,...,ar)*gen(i) (gen(i)=1 if m is of type poly) |
---|
132 | and n = (x1...xr)^(b1,...,br)*gen(j), then the proc returns |
---|
133 | (x1,...,xr)^(max(a1,b1),...,max(ar,br)) if i=j and 0 if i!=j. |
---|
134 | EXAMPLE: example monomialLcm; shows an example |
---|
135 | " |
---|
136 | { |
---|
137 | if(typeof(n) != typeof(m)) |
---|
138 | { |
---|
139 | ERROR("** arguments must be of same type"); |
---|
140 | } |
---|
141 | |
---|
142 | poly u ; |
---|
143 | if(sameComponent(m,n) == 0) //leading term of vectors involve |
---|
144 | { //different module components |
---|
145 | return(u); |
---|
146 | } |
---|
147 | |
---|
148 | intvec v = leadexp(m); //now start to compute lcm |
---|
149 | intvec w = leadexp(n); |
---|
150 | u=1; |
---|
151 | int i; |
---|
152 | for (i=1; i<=nvars(basering); i++) |
---|
153 | { |
---|
154 | if(v[i]>=w[i]) |
---|
155 | { |
---|
156 | u = u*var(i)**v[i]; |
---|
157 | } |
---|
158 | else |
---|
159 | { |
---|
160 | u = u*var(i)**w[i]; |
---|
161 | } |
---|
162 | } |
---|
163 | return(u); |
---|
164 | } |
---|
165 | example |
---|
166 | { "EXAMPLE:"; echo = 2; |
---|
167 | ring r=0,(x,y,z),ds; |
---|
168 | monomialLcm(xy2,yz3); |
---|
169 | monomialLcm([xy2,xz],[yz3]); |
---|
170 | monomialLcm([xy2,xz3],[yz3]); |
---|
171 | } |
---|
172 | /////////////////////////////////////////////////////////////////////////////// |
---|
173 | proc spoly(f,g,list #) |
---|
174 | "USAGE: spoly(f,g[,s]); f,g poly or vector, s int |
---|
175 | RETURN: the s-polynomial of f and g, of type poly or vector |
---|
176 | if s!=0 the symmetric s-polynomial (without division) is returned |
---|
177 | EXAMPLE: example spoly; shows an example |
---|
178 | " |
---|
179 | { |
---|
180 | if(typeof(f) != typeof(g)) |
---|
181 | { |
---|
182 | ERROR("** arguments must be of same type"); |
---|
183 | } |
---|
184 | if(size(#) == 0) |
---|
185 | { |
---|
186 | #[1]=0; |
---|
187 | } |
---|
188 | |
---|
189 | int e; |
---|
190 | poly o = monomialLcm(f,g); |
---|
191 | if( o == 0) //can only happen, if vectors f and g involve |
---|
192 | { //different module components |
---|
193 | vector sp; |
---|
194 | return(sp); |
---|
195 | } |
---|
196 | |
---|
197 | poly m=leadmonomial(f); //compute the leading monomial as poly |
---|
198 | poly n=leadmonomial(g); |
---|
199 | |
---|
200 | if (#[1]==0) //the asymmetric s-poly |
---|
201 | { |
---|
202 | def sp = (o/m)*f - (leadcoef(f)/leadcoef(g))*(o/n)*g; |
---|
203 | } |
---|
204 | else //the symmetric s-poly, avoiding division |
---|
205 | { |
---|
206 | def sp = leadcoef(g)*(o/m)*f - leadcoef(f)*(o/n)*g; |
---|
207 | } |
---|
208 | return(sp); |
---|
209 | } |
---|
210 | example |
---|
211 | { "EXAMPLE:"; echo = 2; |
---|
212 | ring r=0,(x,y,z),ls; |
---|
213 | spoly(2x2+x2y,3y3+xyz); |
---|
214 | ring s=0,(x,y,z),(c,dp); |
---|
215 | spoly(2x2+x2y,3y3+xyz); |
---|
216 | spoly(2x2+x2y,3y3+xyz,1); //symmetric s-poly without division |
---|
217 | spoly([5x2+x2y,z5],[x2,y3,y4]); //s-poly for vectors |
---|
218 | } |
---|
219 | /////////////////////////////////////////////////////////////////////////////// |
---|
220 | proc minEcart(T,h) |
---|
221 | "USAGE: minEcart(T,h); T ideal or module, h poly or vector |
---|
222 | RETURN: element g from T such that leadmonom(g) divides leadmonom(h) |
---|
223 | ecart(g) is minimal with this property (if T != 0); |
---|
224 | return 0 if T is 0 or h = 0 |
---|
225 | EXAMPLE: example minEcart; shows an example |
---|
226 | " |
---|
227 | { |
---|
228 | int i,k,e; |
---|
229 | if (size(T)==0 or h==0 ) //trivial cases |
---|
230 | { |
---|
231 | h = 0; |
---|
232 | return(h); |
---|
233 | } |
---|
234 | //---- check whether some element in T has the same module component as h ---- |
---|
235 | int v; |
---|
236 | intvec w; |
---|
237 | T = simplify(T,2); |
---|
238 | |
---|
239 | if (typeof(h) == "vector") |
---|
240 | { |
---|
241 | e=1; |
---|
242 | v = leadexp(h)[nvars(basering)+1]; |
---|
243 | for( i=1; i<=size(T); i++) |
---|
244 | { |
---|
245 | w[i]=leadexp(T[i])[nvars(basering)+1]; |
---|
246 | if(v == w[i]) |
---|
247 | { |
---|
248 | e=0; //some element in T involves the same component as h |
---|
249 | } |
---|
250 | } |
---|
251 | } |
---|
252 | if ( e == 1 ) //no element in T involves the same component as h |
---|
253 | { |
---|
254 | h = 0; |
---|
255 | return(h); |
---|
256 | } |
---|
257 | |
---|
258 | if (typeof(h) == "poly") //for polys v=w[i] for all i |
---|
259 | { |
---|
260 | v = 1; |
---|
261 | w[size(T)]=0; |
---|
262 | w=w+1; |
---|
263 | } |
---|
264 | |
---|
265 | //------ check whether for some g in T leadmonom(g) divides leadmonom(h) ----- |
---|
266 | def g = T[1]; |
---|
267 | poly f = leadmonomial(h); |
---|
268 | |
---|
269 | for( i=1; i<=size(T); i++) |
---|
270 | { |
---|
271 | if( f/leadmonomial(T[i]) != 0 and v==w[i] ) |
---|
272 | { |
---|
273 | g=T[i]; |
---|
274 | k=i; |
---|
275 | break; |
---|
276 | } |
---|
277 | } |
---|
278 | if (k == 0) //no leadmonom(g) divides leadmonom(h) |
---|
279 | { |
---|
280 | g = 0; |
---|
281 | return(g); |
---|
282 | } |
---|
283 | //--look for T[i] with minimal ecart s.t.leadmonom(T[i]) divides leadmonom(h)-- |
---|
284 | |
---|
285 | for( i=k+1; i<=size(T); i++) |
---|
286 | { |
---|
287 | if( f/leadmonomial(T[i]) != 0 and v==w[i] ) |
---|
288 | { |
---|
289 | if (ecart(T[i]) < ecart(g)) |
---|
290 | { |
---|
291 | g=T[i]; |
---|
292 | } |
---|
293 | } |
---|
294 | } |
---|
295 | return(g); |
---|
296 | } |
---|
297 | example |
---|
298 | { "EXAMPLE:"; echo = 2; |
---|
299 | ring R=0,(x,y,z),dp; |
---|
300 | ideal T = x2y+x2,y3+xyz,xyz2+z4; |
---|
301 | poly h = x2y2z2+x5+yx3+z6; |
---|
302 | minEcart(T,h);""; |
---|
303 | ring S=0,(x,y,z),(c,ds); |
---|
304 | module T = [x2+x2y,y2],[y3+xyz,x3-z3],[x3y+z4,0,x2]; |
---|
305 | vector h = [x3y+x5+x2y2z2+z6,x3]; |
---|
306 | minEcart(T,h); |
---|
307 | } |
---|
308 | /////////////////////////////////////////////////////////////////////////////// |
---|
309 | proc NFMora(f,G,list #) |
---|
310 | "USAGE: NFMora(f,G[,s]); f poly or vector,G ideal or module, s int |
---|
311 | RETURN: the Mora normal form of f w.r.t. G, same type as f |
---|
312 | if s!=0 the symmetric s-polynomial (without division) is used |
---|
313 | NOTE: Show comments if printlevel > 0, pauses computation if printlevel > 1 |
---|
314 | EXAMPLE: example NFMora; shows an example |
---|
315 | " |
---|
316 | { |
---|
317 | if(size(#) == 0) |
---|
318 | { |
---|
319 | #[1]=0; |
---|
320 | } |
---|
321 | |
---|
322 | int y = printlevel - voice + 2; |
---|
323 | if( f==0 or size(G) ==0 ) |
---|
324 | { |
---|
325 | if (y>0) |
---|
326 | { |
---|
327 | "// 1st or 2nd argument 0"; |
---|
328 | } |
---|
329 | return(f); |
---|
330 | } |
---|
331 | |
---|
332 | int i,e; |
---|
333 | def h = f; |
---|
334 | def T = G; |
---|
335 | // -------------------- start with f to be reduced by G -------------------- |
---|
336 | if (y>0) |
---|
337 | {""; |
---|
338 | "// Input for NFMora is (f,T):"; |
---|
339 | "// f:"; f; |
---|
340 | "// T:"; T; |
---|
341 | "// Reduce f with T, eventually enlarging T for local ordering"; |
---|
342 | } |
---|
343 | |
---|
344 | // ----------------------- enter the reduction loop ------------------------ |
---|
345 | def g = minEcart(T,h); |
---|
346 | while (h!=0 and g!=0) |
---|
347 | { |
---|
348 | if (y>0) |
---|
349 | { ""; |
---|
350 | "// Reduction-step in NFMora:",i; |
---|
351 | "// h = (f after",i,"reductions) reduction with g from T:"; |
---|
352 | "// g = element of minimal ecart in T s.t. LM(g)|LM(h):"; |
---|
353 | "// h:";h; |
---|
354 | "// g:";g; |
---|
355 | } |
---|
356 | if (y>1) |
---|
357 | { |
---|
358 | pause("press <return> to continue"); |
---|
359 | "// T, set used for reduction:"; T; |
---|
360 | pause("press <return> to continue"); |
---|
361 | } |
---|
362 | e=0; |
---|
363 | if( ecart(g) > ecart(h) ) |
---|
364 | { |
---|
365 | T=T,h; e=1; |
---|
366 | } |
---|
367 | if (y>0 ) |
---|
368 | { |
---|
369 | "// T-set enlarged for next reduction? (yes/no = 1/0): ", e; |
---|
370 | if( e==1 ) |
---|
371 | { |
---|
372 | "// T-set for next reduction got enlarged by h:"; |
---|
373 | "// h:";h; |
---|
374 | if (y>1) |
---|
375 | { |
---|
376 | pause("press <return> to continue"); |
---|
377 | } |
---|
378 | } |
---|
379 | } |
---|
380 | h = spoly(h,g,#[1]); |
---|
381 | g = minEcart(T,h); |
---|
382 | i=i+1; |
---|
383 | } |
---|
384 | if(y>0) |
---|
385 | { ""; |
---|
386 | "// normal form is:"; |
---|
387 | } |
---|
388 | return(h); |
---|
389 | } |
---|
390 | example |
---|
391 | { "EXAMPLE:"; echo = 2; |
---|
392 | ring r=0,(x,y,z),dp; |
---|
393 | poly f = x2y2z2+x5+yx3+z6-3y3; |
---|
394 | ideal G = x2y+x2,y3+xyz,xyz2+z6; |
---|
395 | NFMora(f,G);""; |
---|
396 | ring s=0,(x,y,z),ds; |
---|
397 | poly f = x3y+x5+x2y2z2+z6; |
---|
398 | ideal G = x2+x2y,y3+xyz,x3y2+z4; |
---|
399 | NFMora(f,G);""; |
---|
400 | vector v = [f,x2+x2y]; |
---|
401 | module M = [x2+x2y,f],[y3+xyz,y3],[x3y2+z4,z2]; |
---|
402 | NFMora(v,M); |
---|
403 | } |
---|
404 | /////////////////////////////////////////////////////////////////////////////// |
---|
405 | proc prodcrit(f,g) |
---|
406 | "USAGE: prodcrit(f,g); f,g poly or vector |
---|
407 | RETURN: 1 if product criterion applies in the same module component, |
---|
408 | 2 if lead(f) and lead(g) involve different components, 0 else |
---|
409 | NOTE: if product criterion applies we can delete (f,g) from pairset |
---|
410 | EXAMPLE: example prodcrit; shows an example |
---|
411 | " |
---|
412 | { |
---|
413 | if(typeof(f)=="poly") //product criterion for polynomials |
---|
414 | { |
---|
415 | if( monomialLcm(f,g)==leadmonom(f)*leadmonom(g)) |
---|
416 | { |
---|
417 | return(1); |
---|
418 | } |
---|
419 | return(0); |
---|
420 | } |
---|
421 | // ------------------- product criterion for modules --------------------- |
---|
422 | if(sameComponent(f,g)==1) |
---|
423 | { |
---|
424 | if( monomialLcm(f,g)==leadmonomial(f)*leadmonomial(g) ) |
---|
425 | { |
---|
426 | int c = leadexp(f)[nvars(basering)+1]; //component involving lead(f) |
---|
427 | if((f-f[c]*gen(c))-(g-g[c]*gen(c))==0) //other components are 0 |
---|
428 | { |
---|
429 | return(1); |
---|
430 | } |
---|
431 | } |
---|
432 | return(0); |
---|
433 | } |
---|
434 | return(2); |
---|
435 | } |
---|
436 | example |
---|
437 | { "EXAMPLE:"; echo = 2; |
---|
438 | ring r=0,(x,y,z),dp; |
---|
439 | poly f = y3z3+x5+yx3+z6; |
---|
440 | poly g = x5+yx3; |
---|
441 | prodcrit(f,g); |
---|
442 | vector v = x3z2*gen(1)+x3y*gen(1)+x2y*gen(2); |
---|
443 | vector w = y4*gen(1)+y3*gen(2)+xyz*gen(1); |
---|
444 | prodcrit(v,w); |
---|
445 | } |
---|
446 | /////////////////////////////////////////////////////////////////////////////// |
---|
447 | proc chaincrit(f,g,h) |
---|
448 | "USAGE: chaincrit(f,g,h); f,g,h poly or module |
---|
449 | RETURN: 1 if chain criterion applies, 0 else |
---|
450 | NOTE: if chain criterion applies to f,g,h we can delete (g,h) from pairset |
---|
451 | EXAMPLE: example chaincrit; shows an example |
---|
452 | " |
---|
453 | { |
---|
454 | if(sameComponent(f,g) and sameComponent(f,h)) |
---|
455 | { |
---|
456 | if( monomialLcm(g,h)/leadmonomial(f) !=0 ) |
---|
457 | { |
---|
458 | return(1); |
---|
459 | } |
---|
460 | } |
---|
461 | return(0); |
---|
462 | } |
---|
463 | example |
---|
464 | { "EXAMPLE:"; echo = 2; |
---|
465 | ring r=0,(x,y,z),dp; |
---|
466 | poly f = x2y2z2+x5+yx3+z6; |
---|
467 | poly g = x5+yx3; |
---|
468 | poly h = y2z5+x5+yx3; |
---|
469 | chaincrit(f,g,h); |
---|
470 | vector u = [x2y3-z2,x2y]; |
---|
471 | vector v = [x2y2+z2,x2-y2]; |
---|
472 | vector w = [x2y4+z3,x2+y2]; |
---|
473 | chaincrit(u,v,w); |
---|
474 | } |
---|
475 | /////////////////////////////////////////////////////////////////////////////// |
---|
476 | proc pairset(G) |
---|
477 | "USAGE: pairset(G); G ideal or module |
---|
478 | RETURN: list L, |
---|
479 | L[1] = the pairset of G as list (not containing pairs for |
---|
480 | which the product or the chain criterion applies) |
---|
481 | L[2] = intvec v, v[1]= # product criterion, v[2]= # chain criterion |
---|
482 | EXAMPLE: example pairset; shows an example |
---|
483 | " |
---|
484 | { |
---|
485 | int i,j,k,s,c,ccrit,pcrit,pr; |
---|
486 | int y = printlevel - voice + 2; |
---|
487 | G = simplify(G,10); |
---|
488 | def g = G; |
---|
489 | ideal pair; |
---|
490 | list P,I; //P=pairlist of G, I=list of corresponding indices of pairs |
---|
491 | for (i=1; i<=size(G); i++) |
---|
492 | { |
---|
493 | for(j = i+1; j<=size(G); j++) |
---|
494 | { |
---|
495 | pr = prodcrit(G[i],G[j]); //check first product criterion |
---|
496 | if( pr != 0 ) |
---|
497 | { |
---|
498 | pcrit=pcrit+(pr==1); |
---|
499 | } |
---|
500 | else |
---|
501 | { |
---|
502 | s = size(P); //now check chain criterion |
---|
503 | for(k=1; k<=s; k++) |
---|
504 | { |
---|
505 | if( i==I[k][2] ) |
---|
506 | { |
---|
507 | if ( chaincrit(P[k][1],P[k][2],G[j]) ) |
---|
508 | { //need not include (G[i],G[j]) in P |
---|
509 | c=1; ccrit=ccrit+1; |
---|
510 | break; |
---|
511 | } |
---|
512 | } |
---|
513 | if( j==I[k][1] and c==0 ) |
---|
514 | { |
---|
515 | "########### enter pairset2 #############"; |
---|
516 | if ( chaincrit(G[i],P[k][1],P[k][2]) ) |
---|
517 | { //can delete P[k]=(P[k][1],P[k][2]) |
---|
518 | ccrit=ccrit+1; |
---|
519 | P = delete(P,k); |
---|
520 | s = s-1; |
---|
521 | } |
---|
522 | } |
---|
523 | } |
---|
524 | if ( c==0 ) |
---|
525 | { |
---|
526 | g = G[i],G[j]; |
---|
527 | P[s+1]=g; |
---|
528 | I[s+1]=intvec(i,j); |
---|
529 | } |
---|
530 | c=0; |
---|
531 | } |
---|
532 | } |
---|
533 | } |
---|
534 | if (y>0) |
---|
535 | { ""; |
---|
536 | "// product criterion:",pcrit," chain criterion:",ccrit; |
---|
537 | } |
---|
538 | intvec v = pcrit,ccrit; |
---|
539 | P=P,v; |
---|
540 | return(P); |
---|
541 | } |
---|
542 | example |
---|
543 | { "EXAMPLE:"; echo = 2; |
---|
544 | ring r=0,(x,y,z),dp; |
---|
545 | ideal G = x2y+x2,y3+xyz,xyz2+z4; |
---|
546 | pairset(G);""; |
---|
547 | module T = [x2y3-z2,x2y],[x2y2+z2,x2-y2],[x2y4+z3,x2+y2]; |
---|
548 | pairset(T); |
---|
549 | } |
---|
550 | /////////////////////////////////////////////////////////////////////////////// |
---|
551 | proc updatePairs(P,S,h) |
---|
552 | "USAGE: updatePairs(P,S,h); P list, S ideal or module, h poly or vector |
---|
553 | P a list of pairs of polys or vectors (obtained from pairset) |
---|
554 | RETURN: list Q, |
---|
555 | Q[1] = the pairset P enlarged by all pairs (f,h), f from S, |
---|
556 | without pairs for which the product or the chain criterion applies |
---|
557 | Q[2] = intvec v, v[1]= # product criterion, v[2]= # chain criterion |
---|
558 | EXAMPLE: example updatePairs; shows an example |
---|
559 | " |
---|
560 | { |
---|
561 | int i,j,k,s,r,c,ccrit,pcrit,pr; |
---|
562 | int y = printlevel - voice + 2; |
---|
563 | ideal pair; |
---|
564 | list Q = P; //Q will become enlarged pairset |
---|
565 | s = size(P); |
---|
566 | r = size(Q); //r will grow with Q |
---|
567 | list R; |
---|
568 | def g = S; //give g the correct type ideal/module |
---|
569 | for (i=1; i<=size(S); i++) |
---|
570 | { |
---|
571 | pr = prodcrit(h,S[i]); |
---|
572 | if( pr != 0 ) //check product criterion |
---|
573 | { |
---|
574 | pcrit=pcrit+(pr==1); //count product criterion in same component |
---|
575 | } |
---|
576 | else |
---|
577 | { //prodcrit did not apply, check for chaincrit |
---|
578 | r=size(Q); |
---|
579 | for(k=1; k<=r; k++) |
---|
580 | { |
---|
581 | if( Q[k][2]==S[i] ) //S[i]=Q[k][2] |
---|
582 | { |
---|
583 | if( chaincrit(Q[k][1],S[i],h) ) |
---|
584 | { //can forget (S[i],h) |
---|
585 | c=1; ccrit=ccrit+1; |
---|
586 | break; |
---|
587 | } |
---|
588 | } |
---|
589 | } |
---|
590 | if ( c==0 ) |
---|
591 | { |
---|
592 | g = S[i],h; //add pair (S[i],h) |
---|
593 | Q[r+1] = g; |
---|
594 | } |
---|
595 | c=0; |
---|
596 | } |
---|
597 | } |
---|
598 | if (y>0) |
---|
599 | { "";; |
---|
600 | "// product criterion:",pcrit," chain criterion:",ccrit; |
---|
601 | } |
---|
602 | intvec v = pcrit,ccrit; |
---|
603 | Q = Q,v; |
---|
604 | return(Q); |
---|
605 | } |
---|
606 | example |
---|
607 | { "EXAMPLE:"; echo = 2; |
---|
608 | ring R1=0,(x,y,z),(c,dp); |
---|
609 | ideal S = x2y+x2,y3+xyz; |
---|
610 | poly h = x2y+xyz; |
---|
611 | list P = pairset(S)[1]; |
---|
612 | P;""; |
---|
613 | updatePairs(P,S,h);""; |
---|
614 | module T = [x2y3-z2,x2y],[x2y4+z3,x2+y2]; |
---|
615 | P = pairset(T)[1]; |
---|
616 | P;""; |
---|
617 | updatePairs(P,T,[x2+x2y,y3+xyz]); |
---|
618 | } |
---|
619 | /////////////////////////////////////////////////////////////////////////////// |
---|
620 | proc standard(id, list #) |
---|
621 | "USAGE: standard(i[,s]); id ideal or module, s int |
---|
622 | RETURN: a standard basis of id, using generalized Mora's algorithm |
---|
623 | which is Buchberger's algorithm for global monomial orderings. |
---|
624 | If s!=0 the symmetric s-polynomial (without division) is used |
---|
625 | NOTE: Show comments if printlevel > 0, pauses computation if printlevel > 1 |
---|
626 | EXAMPLE: example standard; shows an example |
---|
627 | " |
---|
628 | { |
---|
629 | if(size(#) == 0) |
---|
630 | { |
---|
631 | #[1]=0; |
---|
632 | } |
---|
633 | |
---|
634 | def S = id; //S will become the standard basis of id |
---|
635 | def h = S[1]; |
---|
636 | int i,z; |
---|
637 | int y = printlevel - voice + 2; |
---|
638 | if(y>0) |
---|
639 | { ""; |
---|
640 | "// the set S, to become a standard basis:"; S; |
---|
641 | if(y>1) |
---|
642 | { |
---|
643 | "// create pairset, i.e. pairs from S,"; |
---|
644 | "// after application of product and chain criterion"; |
---|
645 | } |
---|
646 | } |
---|
647 | list P = pairset(S); //create pairset of S=id |
---|
648 | intvec v = P[2]; |
---|
649 | P = P[1]; |
---|
650 | //-------------------------- Main loop in SB lgorithm ---------------------- |
---|
651 | while (size(P) !=0) |
---|
652 | { z=z+1; |
---|
653 | if(y>0) |
---|
654 | { ""; |
---|
655 | "// Enter NFMora for next pair, count",z; |
---|
656 | "// size of partial standard basis S: (",size(S),")"; |
---|
657 | "// number of pairs of S after updating: (",size(P),")"; |
---|
658 | if(y>1) |
---|
659 | { |
---|
660 | "// 1st pair of new pairset:"; P[1]; |
---|
661 | "// set T=S used for reduction:";S; |
---|
662 | "// apply NFMora to (spoly,S), spoly = spoly(1st pair)"; |
---|
663 | } |
---|
664 | } |
---|
665 | //-------------------- apply NFMora = Mora's normal form ------------- |
---|
666 | h = spoly(P[1][1],P[1][2],#[1]); |
---|
667 | if(y>1) |
---|
668 | { |
---|
669 | "// spoly:";h; |
---|
670 | } |
---|
671 | h = NFMora(h,S,#[1]); |
---|
672 | if(h==0) //normal form is 0 |
---|
673 | { |
---|
674 | if(y==1) |
---|
675 | { |
---|
676 | "// pair has reduced to 0"; |
---|
677 | } |
---|
678 | if(y>1) |
---|
679 | { h;""; |
---|
680 | pause("press <return> to continue"); |
---|
681 | } |
---|
682 | } |
---|
683 | P = delete(P,1); //spoly of pair reduced to 0, pair can be deleted |
---|
684 | //--- spoly of pair did not reduce to 0, update S and paiset of S ---- |
---|
685 | if( h != 0) |
---|
686 | { |
---|
687 | if(y==1) |
---|
688 | { |
---|
689 | "// ** new spoly in degree **:", deg(h); |
---|
690 | } |
---|
691 | if(y>1) |
---|
692 | { h;""; |
---|
693 | pause("press <return> to continue"); |
---|
694 | "// update pairset"; |
---|
695 | } |
---|
696 | P=updatePairs(P,S,h); //update P (=paisert of S) |
---|
697 | v=v+P[2]; //with useful pairs (g,h), g from S |
---|
698 | P=P[1]; |
---|
699 | S=S,h; //update S, will become the standard basis |
---|
700 | } |
---|
701 | } |
---|
702 | //------------------------------ finished --------------------------------- |
---|
703 | if( find(option(),"prot") or y>0 ) |
---|
704 | { ""; //show how often prodcrit and chaincrit applied |
---|
705 | "// product criterion:",v[1]," chain criterion:",v[2]; |
---|
706 | ""; |
---|
707 | "// Final standard basis:"; |
---|
708 | } |
---|
709 | return(S); |
---|
710 | } |
---|
711 | example |
---|
712 | { "EXAMPLE:"; echo = 2; |
---|
713 | ring r=0,(x,y,z),dp; |
---|
714 | ideal G = x2y+x2,y3+xyz,xyz2+z4; |
---|
715 | standard(G);""; |
---|
716 | ring s=0,(x,y,z),(c,ds); |
---|
717 | ideal G = 2x2+x2y,y3+xyz,3x3y+z4; |
---|
718 | standard(G);""; |
---|
719 | standard(G,1);""; //use symmetric s-poly without division |
---|
720 | module M = [2x2,x3y+z4],[3y3+xyz,y3],[5z4,z2]; |
---|
721 | standard(M); |
---|
722 | } |
---|
723 | /////////////////////////////////////////////////////////////////////////////// |
---|
724 | proc localstd (id) |
---|
725 | "USAGE: localstd (id); id = ideal |
---|
726 | RETURN: A standard basis for a local degree ordering, using Lazard's method. |
---|
727 | NOTE: The procedure homogenizes id w.r.t. a new 1st variable local@t, |
---|
728 | computes a SB wrt (dp(1),dp) and substitutes local@t by 1. |
---|
729 | Hence the result is a SB with respect to an ordering which sorts |
---|
730 | first w.r.t. the subdegree of the original variables and then refines |
---|
731 | it with dp. This is the local degree ordering ds. |
---|
732 | localstd may be used in order to avoid cancellation of units and thus |
---|
733 | to be able to use option(contentSB) also for local orderings. |
---|
734 | EXAMPLE: example localstd; shows an example |
---|
735 | " |
---|
736 | { |
---|
737 | int ii; |
---|
738 | def bas = basering; |
---|
739 | execute("ring @r_locstd |
---|
740 | =("+charstr(bas)+"),(local@t,"+varstr(bas)+"),(dp(1),dp);"); |
---|
741 | ideal id = imap(bas,id); |
---|
742 | ideal hid = homog(id,local@t); |
---|
743 | hid = std(hid); |
---|
744 | hid = subst(hid,local@t,1); |
---|
745 | setring bas; |
---|
746 | def hid = imap(@r_locstd,hid); |
---|
747 | attrib(hid,"isSB",1); |
---|
748 | kill @r_locstd; |
---|
749 | return(hid); |
---|
750 | } |
---|
751 | example |
---|
752 | { "EXAMPLE:"; echo = 2; |
---|
753 | ring R = 0,(x,y,z),ds; |
---|
754 | ideal i = xyz+z5,2x2+y3+z7,3z5+y5; |
---|
755 | localstd(i); |
---|
756 | } |
---|
757 | /////////////////////////////////////////////////////////////////////////////// |
---|
758 | |
---|
759 | /* |
---|
760 | // some examples: |
---|
761 | LIB"teachstd.lib"; |
---|
762 | option(prot); printlevel=3; |
---|
763 | ring r0 = 0,(t,x,y),lp; |
---|
764 | ideal i = x-t2,y-t3; |
---|
765 | standard(i); |
---|
766 | |
---|
767 | printlevel=1; |
---|
768 | standard(i); |
---|
769 | |
---|
770 | option(prot); printlevel =1; |
---|
771 | ring r1 = (0,a,b),(x,y,z),(c,ds); |
---|
772 | module M = [ax2,bx3y+z4],[a3y3+xyz,by3],[5az4,(a+b)*z2]; |
---|
773 | module N1= std(M); |
---|
774 | module N2 = standard(M,1); |
---|
775 | NF(lead(N2),lead(N1)); |
---|
776 | NF(lead(N1),lead(N2));rom T |
---|
777 | ring r2 = 0,(x,y,z),dp; |
---|
778 | ideal I = x2y+x2,y3+xyz,xyz2+z4; |
---|
779 | option(prot); |
---|
780 | int tt = timer; |
---|
781 | ideal J = standard(I); |
---|
782 | timer -tt; //4sec, product criterion: 9 chain criterion: 6 |
---|
783 | ideal J1 = std(I); |
---|
784 | NF(lead(J),lead(J1)); |
---|
785 | NF(lead(J1),lead(J)); |
---|
786 | |
---|
787 | ring r3 = 0,(x,y,z),ds; |
---|
788 | poly f = x3*y4+z5+xyz; |
---|
789 | ideal I = f,jacob(f); |
---|
790 | option(prot); |
---|
791 | int tt = timer; |
---|
792 | ideal J = standard(I); |
---|
793 | timer -tt; //3sec, product criterion: 1 chain criterion: 3 |
---|
794 | ideal J1 = std(I); |
---|
795 | NF(lead(J),lead(J1)); |
---|
796 | NF(lead(J1),lead(J)); |
---|
797 | |
---|
798 | //Becker: |
---|
799 | ring r4 = 32003,(x,y,z),lp; |
---|
800 | ideal I = x3-1, y3-1, |
---|
801 | -27x3-243x2y+27x2z-729xy2+162xyz-9xz2-729y3+243y2z-27yz2+z3-27; |
---|
802 | option(prot); |
---|
803 | int tt = timer; |
---|
804 | ideal J = standard(I); |
---|
805 | timer -tt; //201sec, product criterion: 42 chain criterion: 33 |
---|
806 | ideal J1 = std(I); |
---|
807 | NF(lead(J),lead(J1)); |
---|
808 | NF(lead(J1),lead(J)); |
---|
809 | |
---|
810 | //Alex |
---|
811 | ring r5 = 32003,(x,y,z,t),dp; |
---|
812 | ideal I = |
---|
813 | 2t3xy2z+x2ty+2x2y, |
---|
814 | 2tz+y3x2t+z2t3y2x; |
---|
815 | option(prot); printlevel =1; |
---|
816 | ideal J1 = std(I); |
---|
817 | int tt = timer; |
---|
818 | ideal J = standard(I); |
---|
819 | timer -tt; //15sec product criterion: 0 chain criterion: 12 |
---|
820 | NF(lead(J),lead(J1)); |
---|
821 | NF(lead(J1),lead(J)); |
---|
822 | |
---|
823 | ring r6 = 32003,(x,y,z,t),dp; //is already SB for ds, for dp too long |
---|
824 | ideal I= |
---|
825 | 9x8+y7t3z4+5x4y2t2+2xy2z3t2, |
---|
826 | 9y8+7xy6t+2x5y4t2+2x2yz3t2, |
---|
827 | 9z8+3x2y3z2t4; |
---|
828 | option(prot); |
---|
829 | int tt = timer; |
---|
830 | ideal J = standard(I); |
---|
831 | timer -tt; //0sec, product criterion: 3 chain criterion: 0 |
---|
832 | ideal J1 = std(I); |
---|
833 | NF(lead(J),lead(J1)); |
---|
834 | NF(lead(J1),lead(J)); |
---|
835 | |
---|
836 | |
---|
837 | */ |
---|
838 | |
---|