1 | //GP, last modified 23.10.06 |
---|
2 | /////////////////////////////////////////////////////////////////////////////// |
---|
3 | version="$Id: modstd.lib,v 1.13 2007-07-04 13:14:43 Singular Exp $"; |
---|
4 | category="Commutative Algebra"; |
---|
5 | info=" |
---|
6 | LIBRARY: modstd.lib Grobner basis of ideals |
---|
7 | AUTHORS: A. Hashemi, Amir.Hashemi@lip6.fr |
---|
8 | @* G. Pfister pfister@mathematik.uni-kl.de |
---|
9 | @* H. Schoenemann hannes@mathematik.uni-kl.de |
---|
10 | @* Cindy Magin, c.magin@web.de |
---|
11 | |
---|
12 | NOTE: |
---|
13 | A library for computing the Grobner basis of an ideal in the polynomial |
---|
14 | ring over the rational numbers using modular methods. The procedures are |
---|
15 | inspired by the following paper: |
---|
16 | Elizabeth A. Arnold: |
---|
17 | Modular Algorithms for Computing Groebner Bases , Journal of Symbolic |
---|
18 | Computation , April 2003, Volume 35, (4), p. 403-419. |
---|
19 | |
---|
20 | |
---|
21 | |
---|
22 | PROCEDURES: |
---|
23 | modStd(I); compute a standard basis of I using modular methods |
---|
24 | modS(I,L); liftings to Q of standard bases of I mod p for p in L |
---|
25 | primeList(n); intvec of n primes <= 2134567879 in decreasing order |
---|
26 | pStd(p,i); compute a standard basis of i using p-adic methods |
---|
27 | "; |
---|
28 | |
---|
29 | LIB "poly.lib"; |
---|
30 | LIB "crypto.lib"; |
---|
31 | /////////////////////////////////////////////////////////////////////////////// |
---|
32 | proc modStd(ideal I) |
---|
33 | "USAGE: modStd(I); |
---|
34 | RETURN: a standard basis of I if no warning appears; |
---|
35 | NOTE: the procedure computes a standard basis of I (over the |
---|
36 | rational numbers) by using modular methods. If a |
---|
37 | warning appears then the result is a standard basis with no defined |
---|
38 | relation to I; this is a sign that not enough prime numbers have |
---|
39 | been used. For further experiments see procedure modS. |
---|
40 | EXAMPLE: example modStd; shows an example |
---|
41 | " |
---|
42 | { |
---|
43 | def R0=basering; |
---|
44 | list rl=ringlist(R0); |
---|
45 | if((npars(R0)>0)||(rl[1]>0)) |
---|
46 | { |
---|
47 | ERROR("characteristic of basering should be zero"); |
---|
48 | } |
---|
49 | int l,j,k,q; |
---|
50 | int en=2134567879; |
---|
51 | int an=1000000000; |
---|
52 | intvec hi,hl,hc,hpl,hpc; |
---|
53 | list T,TT; |
---|
54 | intvec L=primeList(5); |
---|
55 | L[6]=prime(random(an,en)); |
---|
56 | ideal J,cT,lT,K; |
---|
57 | ideal I0=I; |
---|
58 | int h=homog(I); |
---|
59 | if((!h)&&(ord_test(R0)==0)) |
---|
60 | { |
---|
61 | ERROR("input is not homogeneous and ordering is not local"); |
---|
62 | } |
---|
63 | if(h) |
---|
64 | { |
---|
65 | execute("ring gn="+string(L[6])+",x(1.."+string(nvars(R0))+"),dp;"); |
---|
66 | ideal I=fetch(R0,I); |
---|
67 | ideal J=std(I); |
---|
68 | hi=hilb(J,1); |
---|
69 | setring R0; |
---|
70 | } |
---|
71 | for (j=1;j<=size(L);j++) |
---|
72 | { |
---|
73 | rl[1]=L[j]; |
---|
74 | def oro=ring(rl); |
---|
75 | setring oro; |
---|
76 | ideal I=fetch(R0,I); |
---|
77 | option(redSB); |
---|
78 | if(h) |
---|
79 | { |
---|
80 | ideal I1=std(I,hi); |
---|
81 | } |
---|
82 | else |
---|
83 | { |
---|
84 | if(ord_test(R0)==-1) |
---|
85 | { |
---|
86 | ideal I1=std(I); |
---|
87 | } |
---|
88 | else |
---|
89 | { |
---|
90 | matrix M; |
---|
91 | ideal I1=liftstd(I,M); |
---|
92 | } |
---|
93 | } |
---|
94 | setring R0; |
---|
95 | T[j]=fetch(oro,I1); |
---|
96 | kill oro; |
---|
97 | } |
---|
98 | //================= delete unlucky primes ==================== |
---|
99 | // unlucky iff the leading ideal is wrong |
---|
100 | list LL=deleteUnluckyPrimes(T,L); |
---|
101 | T=LL[1]; |
---|
102 | L=LL[2]; |
---|
103 | lT=LL[3]; |
---|
104 | //============ now all leading ideals are the same ============ |
---|
105 | for(j=1;j<=ncols(T[1]);j++) |
---|
106 | { |
---|
107 | for(k=1;k<=size(L);k++) |
---|
108 | { |
---|
109 | TT[k]=T[k][j]; |
---|
110 | } |
---|
111 | J[j]=liftPoly(TT,L); |
---|
112 | } |
---|
113 | //=========== chooses more primes up to the moment the result becomes stable |
---|
114 | while(1) |
---|
115 | { |
---|
116 | k=0; |
---|
117 | q=prime(random(an,en)); |
---|
118 | while(k<size(L)) |
---|
119 | { |
---|
120 | k++; |
---|
121 | if(L[k]==q) |
---|
122 | { |
---|
123 | k=0; |
---|
124 | q=prime(random(an,en)); |
---|
125 | } |
---|
126 | } |
---|
127 | L[size(L)+1]=q; |
---|
128 | rl[1]=L[size(L)]; |
---|
129 | def @r=ring(rl); |
---|
130 | setring @r; |
---|
131 | ideal i=fetch(R0,I); |
---|
132 | option(redSB); |
---|
133 | if(h) |
---|
134 | { |
---|
135 | i=std(i,hi); |
---|
136 | } |
---|
137 | else |
---|
138 | { |
---|
139 | if(ord_test(R0)==-1) |
---|
140 | { |
---|
141 | i=std(i); |
---|
142 | } |
---|
143 | else |
---|
144 | { |
---|
145 | matrix M; |
---|
146 | i=liftstd(i,M); |
---|
147 | } |
---|
148 | } |
---|
149 | setring R0; |
---|
150 | T[size(T)+1]=fetch(@r,i); |
---|
151 | kill @r; |
---|
152 | cT=lead(T[size(T)]); |
---|
153 | attrib(cT,"isSB",1); |
---|
154 | if((size(reduce(cT,lT))!=0)||(size(reduce(lT,cT))!=0)) |
---|
155 | { |
---|
156 | T=delete(T,size(T)); |
---|
157 | L=L[1..size(L)-1]; |
---|
158 | k=0; |
---|
159 | } |
---|
160 | else |
---|
161 | { |
---|
162 | for(j=1;j<=ncols(T[1]);j++) |
---|
163 | { |
---|
164 | for(k=1;k<=size(L);k++) |
---|
165 | { |
---|
166 | TT[k]=T[k][j]; |
---|
167 | } |
---|
168 | K[j]=liftPoly(TT,L); |
---|
169 | } |
---|
170 | k=1; |
---|
171 | for(j=1;j<=size(K);j++) |
---|
172 | { |
---|
173 | if(K[j]-J[j]!=0) |
---|
174 | { |
---|
175 | k=0; |
---|
176 | J=K; |
---|
177 | break; |
---|
178 | } |
---|
179 | } |
---|
180 | } |
---|
181 | if(k){break;} |
---|
182 | } |
---|
183 | //============ test for standard basis and I=J ======= |
---|
184 | J=std(J); |
---|
185 | I0=reduce(I0,J); |
---|
186 | if(size(I0)>0) |
---|
187 | { |
---|
188 | "WARNING: The input ideal is not contained |
---|
189 | in the ideal generated by the standardbasis"; |
---|
190 | "list of primes used:"; |
---|
191 | L; |
---|
192 | } |
---|
193 | attrib(J,"isSB",1); |
---|
194 | return(J); |
---|
195 | } |
---|
196 | example |
---|
197 | { "EXAMPLE:"; echo = 2; |
---|
198 | ring r=0,(x,y,z),dp; |
---|
199 | ideal I=3x3+x2+1,11y5+y3+2,5z4+z2+4; |
---|
200 | ideal J=modStd(I); |
---|
201 | J; |
---|
202 | } |
---|
203 | /////////////////////////////////////////////////////////////////////////////// |
---|
204 | proc modS(ideal I, intvec L, list #) |
---|
205 | "USAGE: modS(I,L); I ideal, L intvec of primes |
---|
206 | if size(#)>0 std is used instead of groebner |
---|
207 | RETURN: an ideal which is with high probability a standard basis |
---|
208 | NOTE: This procedure is designed for fast experiments. |
---|
209 | It is not tested whether the result is a standard basis. |
---|
210 | It is not tested whether the result generates I. |
---|
211 | EXAMPLE: example modS; shows an example |
---|
212 | " |
---|
213 | { |
---|
214 | int j,k; |
---|
215 | list T,TT; |
---|
216 | def R0=basering; |
---|
217 | ideal J,cT,lT,K; |
---|
218 | ideal I0=I; |
---|
219 | list rl=ringlist(R0); |
---|
220 | if((npars(R0)>0)||(rl[1]>0)) |
---|
221 | { |
---|
222 | ERROR("characteristic of basering should be zero"); |
---|
223 | } |
---|
224 | for (j=1;j<=size(L);j++) |
---|
225 | { |
---|
226 | rl[1]=L[j]; |
---|
227 | def @r=ring(rl); |
---|
228 | setring @r; |
---|
229 | ideal i=fetch(R0,I); |
---|
230 | option(redSB); |
---|
231 | if(size(#)>0) |
---|
232 | { |
---|
233 | i=std(i); |
---|
234 | } |
---|
235 | else |
---|
236 | { |
---|
237 | i=groebner(i); |
---|
238 | } |
---|
239 | setring R0; |
---|
240 | T[j]=fetch(@r,i); |
---|
241 | kill @r; |
---|
242 | } |
---|
243 | //================= delete unlucky primes ==================== |
---|
244 | // unlucky iff the leading ideal is wrong |
---|
245 | list LL=deleteUnluckyPrimes(T,L); |
---|
246 | T=LL[1]; |
---|
247 | L=LL[2]; |
---|
248 | //============ now all leading ideals are the same ============ |
---|
249 | for(j=1;j<=ncols(T[1]);j++) |
---|
250 | { |
---|
251 | for(k=1;k<=size(L);k++) |
---|
252 | { |
---|
253 | TT[k]=T[k][j]; |
---|
254 | } |
---|
255 | J[j]=liftPoly(TT,L); |
---|
256 | } |
---|
257 | attrib(J,"isSB",1); |
---|
258 | return(J); |
---|
259 | } |
---|
260 | example |
---|
261 | { "EXAMPLE:"; echo = 2; |
---|
262 | intvec L=3,5,11,13,181; |
---|
263 | ring r=0,(x,y,z),dp; |
---|
264 | ideal I=3x3+x2+1,11y5+y3+2,5z4+z2+4; |
---|
265 | ideal J=modS(I,L); |
---|
266 | J; |
---|
267 | } |
---|
268 | /////////////////////////////////////////////////////////////////////////////// |
---|
269 | proc deleteUnluckyPrimes(list T,intvec L) |
---|
270 | "USAGE: deleteUnluckyPrimes(T,L);T list of polys, L intvec of primes |
---|
271 | RETURN: list L,T with T list of polys, L intvec of primes |
---|
272 | EXAMPLE: example deleteUnluckyPrimes; shows an example |
---|
273 | NOTE: works only for homogeneous ideals with global orderings or |
---|
274 | for ideals with local orderings |
---|
275 | " |
---|
276 | { |
---|
277 | int j,k; |
---|
278 | intvec hl,hc; |
---|
279 | ideal cT,lT; |
---|
280 | |
---|
281 | lT=lead(T[size(T)]); |
---|
282 | attrib(lT,"isSB",1); |
---|
283 | hl=hilb(lT,1); |
---|
284 | for (j=1;j<size(T);j++) |
---|
285 | { |
---|
286 | cT=lead(T[j]); |
---|
287 | attrib(cT,"isSB",1); |
---|
288 | hc=hilb(cT,1); |
---|
289 | if(hl==hc) |
---|
290 | { |
---|
291 | for(k=1;k<=size(lT);k++) |
---|
292 | { |
---|
293 | if(lT[k]<cT[k]){lT=cT;break;} |
---|
294 | if(lT[k]>cT[k]){break;} |
---|
295 | } |
---|
296 | } |
---|
297 | else |
---|
298 | { |
---|
299 | if(hc<hl){lT=cT;hl=hilb(lT,1);} |
---|
300 | } |
---|
301 | } |
---|
302 | j=1; |
---|
303 | attrib(lT,"isSB",1); |
---|
304 | while(j<=size(T)) |
---|
305 | { |
---|
306 | cT=lead(T[j]); |
---|
307 | attrib(cT,"isSB",1); |
---|
308 | if((size(reduce(cT,lT))!=0)||(size(reduce(lT,cT))!=0)) |
---|
309 | { |
---|
310 | T=delete(T,j); |
---|
311 | if(j==1) { L=L[2..size(L)]; } |
---|
312 | else |
---|
313 | { |
---|
314 | if (j==size(L)) { L=L[1..size(L)-1]; } |
---|
315 | else { L=L[1..j-1],L[j+1..size(L)]; } |
---|
316 | } |
---|
317 | j--; |
---|
318 | } |
---|
319 | j++; |
---|
320 | } |
---|
321 | return(list(T,L,lT)); |
---|
322 | } |
---|
323 | example |
---|
324 | { "EXAMPLE:"; echo = 2; |
---|
325 | list L=2,3,5,7,11; |
---|
326 | ring r=0,(y,x),Dp; |
---|
327 | ideal I1=y2x,y6; |
---|
328 | ideal I2=yx2,y3x,x5,y6; |
---|
329 | ideal I3=y2x,x3y,x5,y6; |
---|
330 | ideal I4=y2x,x3y,x5; |
---|
331 | ideal I5=y2x,yx3,x5,y6; |
---|
332 | list T=I1,I2,I3,I4,I5; |
---|
333 | list TT=deleteUnluckyPrimes(T,L); |
---|
334 | TT; |
---|
335 | } |
---|
336 | /////////////////////////////////////////////////////////////////////////////// |
---|
337 | proc liftPoly(list T, intvec L) |
---|
338 | "USAGE: liftPoly(T,L); T list of polys, L intvec of primes |
---|
339 | RETURN: poly p in Q[x] such that p mod L[i]=T[i] |
---|
340 | EXAMPLE: example liftPoly; shows an example |
---|
341 | " |
---|
342 | { |
---|
343 | int i; |
---|
344 | list TT; |
---|
345 | for(i=size(T);i>0;i--) |
---|
346 | { TT[i]=ideal(T[i]); } |
---|
347 | T=TT; |
---|
348 | ideal hh=chinrem(T,L); |
---|
349 | poly h=hh[1]; |
---|
350 | poly p=lead(h); |
---|
351 | poly result; |
---|
352 | number n; |
---|
353 | number N=L[1]; |
---|
354 | for(i=size(L);i>1;i--) |
---|
355 | { |
---|
356 | N=N*L[i]; |
---|
357 | } |
---|
358 | while(h!=0) |
---|
359 | { |
---|
360 | n=Farey(N,leadcoef(h)); |
---|
361 | result=result+n*p; |
---|
362 | h=h-lead(h); |
---|
363 | p=leadmonom(h); |
---|
364 | } |
---|
365 | return(result); |
---|
366 | } |
---|
367 | example |
---|
368 | { "EXAMPLE:"; echo = 2; |
---|
369 | ring R = 0,(x,y),dp; |
---|
370 | intvec L=32003,181,241,499; |
---|
371 | list T=ideal(x2+7000x+13000),ideal(x2+100x+147y+40),ideal(x2+120x+191y+10),ideal(x2+x+67y+100); |
---|
372 | liftPoly(T,L); |
---|
373 | } |
---|
374 | /////////////////////////////////////////////////////////////////////////// |
---|
375 | proc liftPoly1(list T, intvec L) |
---|
376 | "USAGE: liftPoly1(T,L); T list of polys, L intvec of primes |
---|
377 | RETURN: poly p in Q[x] such that p mod L[i]=T[i] |
---|
378 | EXAMPLE: example liftPoly; shows an example |
---|
379 | " |
---|
380 | { |
---|
381 | poly result; |
---|
382 | int i; |
---|
383 | poly p; |
---|
384 | list TT; |
---|
385 | number n; |
---|
386 | |
---|
387 | number N=L[1]; |
---|
388 | for(i=2;i<=size(L);i++) |
---|
389 | { |
---|
390 | N=N*L[i]; |
---|
391 | } |
---|
392 | while(1) |
---|
393 | { |
---|
394 | p=leadmonom(T[1]); |
---|
395 | for(i=2;i<=size(T);i++) |
---|
396 | { |
---|
397 | if(leadmonom(T[i])>p) |
---|
398 | { |
---|
399 | p=leadmonom(T[i]); |
---|
400 | } |
---|
401 | } |
---|
402 | if (p==0) {return(result);} |
---|
403 | for(i=1;i<=size(T);i++) |
---|
404 | { |
---|
405 | if(p==leadmonom(T[i])) |
---|
406 | { |
---|
407 | TT[i]=leadcoef(T[i]); |
---|
408 | T[i]=T[i]-lead(T[i]); |
---|
409 | } |
---|
410 | else |
---|
411 | { |
---|
412 | TT[i]=0; |
---|
413 | } |
---|
414 | } |
---|
415 | n=chineseR(TT,L,N); |
---|
416 | n=Farey(N,n); |
---|
417 | result=result+n*p; |
---|
418 | } |
---|
419 | } |
---|
420 | example |
---|
421 | { "EXAMPLE:"; echo = 2; |
---|
422 | ring R = 0,(x,y),dp; |
---|
423 | intvec L=32003,181,241,499; |
---|
424 | list T=x2+7000x+13000,x2+100x+147y+40,x2+120x+191y+10,x2+x+67y+100; |
---|
425 | liftPoly1(T,L); |
---|
426 | } |
---|
427 | /////////////////////////////////////////////////////////////////////////////// |
---|
428 | proc fareyIdeal(ideal I,intvec L) |
---|
429 | { |
---|
430 | poly result,p; |
---|
431 | int i,j; |
---|
432 | number n; |
---|
433 | number N=L[1]; |
---|
434 | for(i=2;i<=size(L);i++) |
---|
435 | { |
---|
436 | N=N*L[i]; |
---|
437 | } |
---|
438 | |
---|
439 | for(i=1;i<=size(I);i++) |
---|
440 | { |
---|
441 | p=I[i]; |
---|
442 | result=lead(p); |
---|
443 | while(1) |
---|
444 | { |
---|
445 | if (p==0) {break;} |
---|
446 | p=p-lead(p); |
---|
447 | n=Farey(N,leadcoef(p)); |
---|
448 | result=result+n*leadmonom(p); |
---|
449 | } |
---|
450 | I[i]=result; |
---|
451 | } |
---|
452 | return(I); |
---|
453 | } |
---|
454 | /////////////////////////////////////////////////////////////////////////////// |
---|
455 | proc Farey (number P, number N) |
---|
456 | "USAGE: Farey (P,N); P, N number; |
---|
457 | RETURN: a rational number a/b such that a/b=N mod P |
---|
458 | and |a|,|b|<(P/2)^{1/2} |
---|
459 | " |
---|
460 | { |
---|
461 | if (P<0){P=-P;} |
---|
462 | if (N<0){N=N+P;} |
---|
463 | number A,B,C,D,E; |
---|
464 | E=P; |
---|
465 | B=1; |
---|
466 | while (N!=0) |
---|
467 | { |
---|
468 | if (2*N^2<P) |
---|
469 | { |
---|
470 | return(N/B); |
---|
471 | } |
---|
472 | D=E mod N; |
---|
473 | C=A-(E-E mod N)/N*B; |
---|
474 | E=N; |
---|
475 | N=D; |
---|
476 | A=B; |
---|
477 | B=C; |
---|
478 | } |
---|
479 | return(0); |
---|
480 | } |
---|
481 | example |
---|
482 | { "EXAMPLE:"; echo = 2; |
---|
483 | ring R = 0,x,dp; |
---|
484 | Farey(32003,12345); |
---|
485 | } |
---|
486 | /////////////////////////////////////////////////////////////////////////////// |
---|
487 | proc chineseR(list T,intvec L,number N) |
---|
488 | "USAGE: chineseR(T,L,N); |
---|
489 | RETURN: x such that x = T[i] mod L[i], N=product(L[i]) |
---|
490 | NOTE: chinese remainder theorem |
---|
491 | EXAMPLE:example chineseR; shows an example |
---|
492 | " |
---|
493 | { |
---|
494 | number x; |
---|
495 | if(size(L)==1) |
---|
496 | { |
---|
497 | x=T[1] mod L[1]; |
---|
498 | return(x); |
---|
499 | } |
---|
500 | int i; |
---|
501 | int n=size(L); |
---|
502 | list M; |
---|
503 | for(i=1;i<=n;i++) |
---|
504 | { |
---|
505 | M[i]=N/L[i]; |
---|
506 | } |
---|
507 | list S=eexgcdN(M); |
---|
508 | for(i=1;i<=n;i++) |
---|
509 | { |
---|
510 | x=x+S[i]*M[i]*T[i]; |
---|
511 | } |
---|
512 | x=x mod N; |
---|
513 | return(x); |
---|
514 | } |
---|
515 | example |
---|
516 | { "EXAMPLE:"; echo = 2; |
---|
517 | ring R = 0,x,dp; |
---|
518 | chineseR(list(24,15,7),intvec(2,3,5),30); |
---|
519 | } |
---|
520 | |
---|
521 | /////////////////////////////////////////////////////////////////////////////// |
---|
522 | proc primeList(int n) |
---|
523 | "USAGE: primeList(n); |
---|
524 | RETURN: the intvec of n greatest primes <= 2134567879 |
---|
525 | EXAMPLE:example primList; shows an example |
---|
526 | " |
---|
527 | { |
---|
528 | intvec L=0:n; |
---|
529 | int i; |
---|
530 | int p=2134567879; |
---|
531 | for(i=1;i<=n;i++) |
---|
532 | { |
---|
533 | L[i]=p; |
---|
534 | p=prime(p-1); |
---|
535 | } |
---|
536 | return(L); |
---|
537 | } |
---|
538 | example |
---|
539 | { "EXAMPLE:"; echo = 2; |
---|
540 | intvec L=primeList(10); |
---|
541 | size(L); |
---|
542 | L[size(L)]; |
---|
543 | } |
---|
544 | /////////////////////////////////////////////////////////////////////////////// |
---|
545 | proc pStd(int p,ideal i) |
---|
546 | "USAGE: pStd(p,i);p integer, i ideal; |
---|
547 | RETURN: an ideal G which is the groebner base for i |
---|
548 | EXAMPLE: example pStd; shows an example |
---|
549 | " |
---|
550 | { |
---|
551 | def r=basering; |
---|
552 | list rl=ringlist(r); |
---|
553 | rl[1]=p; |
---|
554 | def r1=ring(rl); |
---|
555 | setring r1; |
---|
556 | option(redSB); |
---|
557 | ideal j=fetch(r,i); |
---|
558 | ideal GP=groebner(j); |
---|
559 | setring r; |
---|
560 | ideal G=fetch(r1,GP); |
---|
561 | attrib(G,"isSB",1); |
---|
562 | matrix Z=transmat(p,i,G); |
---|
563 | matrix G1=gstrich1(p,Z,i,G); |
---|
564 | ideal g1=G1; |
---|
565 | ideal g22=reduce(g1,G); |
---|
566 | matrix G22=transpose(matrix(g22)); |
---|
567 | matrix M=redmat(G,G1,G22); |
---|
568 | matrix Z2=-M*Z; |
---|
569 | kill r1; |
---|
570 | number c=p; |
---|
571 | matrix G0=transpose(matrix(G)); |
---|
572 | G0= MmodN(G0+ (c)* G22,c^2); |
---|
573 | matrix GF=fareyMatrix(G0,c^2); |
---|
574 | Z=MmodN(Z+(c)*Z2,c^2); |
---|
575 | matrix C=transpose(G); |
---|
576 | int n=3; |
---|
577 | while(GF<>C) |
---|
578 | { |
---|
579 | C=GF; |
---|
580 | G1= gstrich2(c,Z,i,G0,n); |
---|
581 | g1=G1; |
---|
582 | g22=reduce(g1,G); |
---|
583 | G22=transpose(matrix(g22)); |
---|
584 | M=redmat(G,G1,G22); |
---|
585 | Z2=-M*Z; |
---|
586 | Z=MmodN(Z+(c^(n-1))*Z2,c^n); |
---|
587 | G0= MmodN(G0+ (c^(n-1))* G22,c^n); |
---|
588 | GF=fareyMatrix(G0,c^n); |
---|
589 | n++; |
---|
590 | } |
---|
591 | return(ideal(GF)); |
---|
592 | } |
---|
593 | example |
---|
594 | { "EXAMPLE:"; echo = 2; |
---|
595 | ring r=0,(x,y,z),dp; |
---|
596 | ideal I=3x3+x2+1,11y5+y3+2,5z4+z2+4; |
---|
597 | ideal J=pStd(32003,I); |
---|
598 | J; |
---|
599 | } |
---|
600 | /////////////////////////////////////////////////////////////////////////// |
---|
601 | proc transmat(int p,ideal i,ideal G) |
---|
602 | "USAGE: transmat(p,I,G); p integer, I,G ideal; |
---|
603 | RETURN: the transformationmatrix Z for the ideal i mod p and the groebner base for i mod p |
---|
604 | EXAMPLE: example transmit; shows an example |
---|
605 | " |
---|
606 | { |
---|
607 | def r=basering; |
---|
608 | int n=nvars(r); |
---|
609 | list rl=ringlist(r); |
---|
610 | rl[1]=p; |
---|
611 | def r1=ring(rl); |
---|
612 | setring r1; |
---|
613 | ideal i=fetch(r,i); |
---|
614 | ideal G=fetch(r,G); |
---|
615 | attrib(G,"isSB",1); |
---|
616 | ring rhelp=p,x(1..n),dp; |
---|
617 | list lhelp=ringlist(rhelp); |
---|
618 | list l=lhelp[3]; |
---|
619 | setring r; |
---|
620 | rl[3]=l; |
---|
621 | def r2=ring(rl); |
---|
622 | setring r2; |
---|
623 | ideal i=fetch(r,i); |
---|
624 | option(redSB); |
---|
625 | ideal j=std(i); |
---|
626 | matrix T=lift(i,j); |
---|
627 | setring r1; |
---|
628 | matrix T=fetch(r2,T); |
---|
629 | ideal j=fetch(r2,j); |
---|
630 | matrix M=lift(j,G); |
---|
631 | matrix Z=transpose(T*M); |
---|
632 | setring r; |
---|
633 | matrix Z=fetch(r1,Z); |
---|
634 | return(Z); |
---|
635 | } |
---|
636 | example |
---|
637 | { "EXAMPLE:"; echo = 2; |
---|
638 | ring r=0,(x,y,z),dp; |
---|
639 | ideal i=3x3+x2+1,11y5+y3+2,5z4+z2+4; |
---|
640 | ideal g=x3-60x2-60, z4-36z2+37, y5+33y3+66; |
---|
641 | int p=181; |
---|
642 | matrix Z=transmat(p,i,g); |
---|
643 | Z; |
---|
644 | } |
---|
645 | |
---|
646 | /////////////////////////////////////////////////////////////////////////// |
---|
647 | proc gstrich1(int p, matrix Z, ideal i, ideal gp) |
---|
648 | "USAGE: gstrich1 (p,Z,i,gp); p integer, Z matrix, i,gp ideals; |
---|
649 | RETURN: a matrix G such that (Z*F-GP)/p, where F and GP are the matrices of the ideals i and gp |
---|
650 | " |
---|
651 | { |
---|
652 | matrix F=transpose(matrix(i)); |
---|
653 | matrix GP=transpose(matrix(gp)); |
---|
654 | matrix G=(Z*F-GP)/p; |
---|
655 | return(G); |
---|
656 | } |
---|
657 | /////////////////////////////////////////////////////////////////////////// |
---|
658 | proc gstrich2(number p, matrix Z, ideal i, ideal gp, int n) |
---|
659 | "USAGE: gstrich2 (p,Z,i,gp,n); p,n integer, Z matrix, i,gp ideals; |
---|
660 | RETURN: a matrix G such that (Z*F-GP)/(p^(n-1)), where F and GP are the matrices of the ideals i and gp |
---|
661 | " |
---|
662 | { |
---|
663 | matrix F=transpose(matrix(i)); |
---|
664 | matrix GP=transpose(matrix(gp)); |
---|
665 | matrix G=(Z*F-GP)/(p^(n-1)); |
---|
666 | return(G); |
---|
667 | } |
---|
668 | /////////////////////////////////////////////////////////////////////////// |
---|
669 | proc redmat(ideal i, matrix h, matrix g) |
---|
670 | "USAGE: redmat(i,h,g); i ideal , h,g matrices; |
---|
671 | RETURN: a matrix M such that i=M*h+g |
---|
672 | " |
---|
673 | { |
---|
674 | matrix c=h-g; |
---|
675 | ideal f=transpose(c); |
---|
676 | matrix N=lift(i,f); |
---|
677 | matrix M=transpose(N); |
---|
678 | return(M); |
---|
679 | } |
---|
680 | /////////////////////////////////////////////////////////////////////////// |
---|
681 | proc fareyMatrix(matrix m,number N) |
---|
682 | "USAGE: fareyMatrix(m,y); m matrix, y integer; |
---|
683 | RETURN: a matrix k of the matrix m with Farey rational numbers a/b as coefficients |
---|
684 | EXAMPLE: example fareyMatrix; shows an example |
---|
685 | " |
---|
686 | { |
---|
687 | ideal I=m; |
---|
688 | poly result,p; |
---|
689 | int i,j; |
---|
690 | number n; |
---|
691 | for(i=1;i<=size(I);i++) |
---|
692 | { |
---|
693 | p=I[i]; |
---|
694 | result=lead(p); |
---|
695 | while(1) |
---|
696 | { |
---|
697 | if (p==0) {break;} |
---|
698 | p=p-lead(p); |
---|
699 | n=Farey(N,leadcoef(p)); |
---|
700 | result=result+n*leadmonom(p); |
---|
701 | } |
---|
702 | I[i]=result; |
---|
703 | } |
---|
704 | matrix k=transpose(I); |
---|
705 | return(k); |
---|
706 | } |
---|
707 | example |
---|
708 | {"EXAMPLE:"; echo = 2; |
---|
709 | ring r=0,(x,y,z),dp; |
---|
710 | matrix m[3][1]=x3+682794673x2+682794673,z4+204838402z2+819353608, y5+186216729y3+372433458; |
---|
711 | int p=32003; |
---|
712 | matrix b=fareyMatrix(m,p^2); |
---|
713 | b; |
---|
714 | } |
---|
715 | /////////////////////////////////////////////////////////////////////////// |
---|
716 | proc MmodN(matrix Z,number N) |
---|
717 | "USAGE: MmodN(Z,N);Z matrix, N number; |
---|
718 | RETURN: the matrix Z mod N |
---|
719 | EXAMPLE: example MmodN; |
---|
720 | " |
---|
721 | { |
---|
722 | int i,j,k; |
---|
723 | poly m,p; |
---|
724 | number c; |
---|
725 | for(i=1;i<=nrows(Z);i++) |
---|
726 | { |
---|
727 | for(j=1;j<=ncols(Z);j++) |
---|
728 | { |
---|
729 | for(k=1;k<=size(Z[i,j]);k++) |
---|
730 | { |
---|
731 | m=leadmonom(Z[i,j][k]); |
---|
732 | c=leadcoef(Z[i,j][k]) mod N; |
---|
733 | p=p+c*m; |
---|
734 | } |
---|
735 | Z[i,j]=p; |
---|
736 | p=0; |
---|
737 | } |
---|
738 | } |
---|
739 | return(Z); |
---|
740 | } |
---|
741 | example |
---|
742 | { "EXAMPLE:"; echo = 2; |
---|
743 | ring r = 0,(x,y,z),dp; |
---|
744 | matrix m[3][1]= x3+10668x2+10668, z4-12801z2+12802, y5-8728y3+14547; |
---|
745 | number p=32003; |
---|
746 | matrix b=MmodN(m,p^2); |
---|
747 | b; |
---|
748 | } |
---|
749 | /////////////////////////////////////////////////////////////////////////////// |
---|
750 | /* |
---|
751 | ring r=0,(x,y,z),lp; |
---|
752 | poly s1 = 5x3y2z+3y3x2z+7xy2z2; |
---|
753 | poly s2 = 3xy2z2+x5+11y2z2; |
---|
754 | poly s3 = 4xyz+7x3+12y3+1; |
---|
755 | poly s4 = 3x3-4y3+yz2; |
---|
756 | ideal i = s1, s2, s3, s4; |
---|
757 | |
---|
758 | ring r=0,(x,y,z),lp; |
---|
759 | poly s1 = 2xy4z2+x3y2z-x2y3z+2xyz2+7y3+7; |
---|
760 | poly s2 = 2x2y4z+x2yz2-xy2z2+2x2yz-12x+12y; |
---|
761 | poly s3 = 2y5z+x2y2z-xy3z-xy3+y4+2y2z; |
---|
762 | poly s4 = 3xy4z3+x2y2z-xy3z+4y3z2+3xyz3+4z2-x+y; |
---|
763 | ideal i = s1, s2, s3, s4; |
---|
764 | |
---|
765 | ring r=0,(x,y,z),lp; |
---|
766 | poly s1 = 8x2y2 + 5xy3 + 3x3z + x2yz; |
---|
767 | poly s2 = x5 + 2y3z2 + 13y2z3 + 5yz4; |
---|
768 | poly s3 = 8x3 + 12y3 + xz2 + 3; |
---|
769 | poly s4 = 7x2y4 + 18xy3z2 + y3z3; |
---|
770 | ideal i = s1, s2, s3, s4; |
---|
771 | |
---|
772 | int n = 6; |
---|
773 | ring r = 0,(x(1..n)),lp; |
---|
774 | ideal i = cyclic(n); |
---|
775 | ring s=0,(x(1..n),t),lp; |
---|
776 | ideal i=imap(r,i); |
---|
777 | i=homog(i,t); |
---|
778 | |
---|
779 | ring r=0,(x(1..4),s),(dp(4),dp); |
---|
780 | poly s1 =1 + s^2*x(1)*x(3) + s^8*x(2)*x(3) + s^19*x(1)*x(2)*x(4); |
---|
781 | poly s2 = x(1) + s^8 *x(1)* x(2)* x(3) + s^19* x(2)* x(4); |
---|
782 | poly s3 = x(2) + s^10*x(3)*x(4) + s^11*x(1)*x(4); |
---|
783 | poly s4 = x(3) + s^4*x(1)*x(2) + s^19*x(1)*x(3)*x(4) +s^24*x(2)*x(3)*x(4); |
---|
784 | poly s5 = x(4) + s^31* x(1)* x(2)* x(3)* x(4); |
---|
785 | ideal i = s1, s2, s3, s4, s5; |
---|
786 | |
---|
787 | ring r=0,(x,y,z),ds; |
---|
788 | int a =16; |
---|
789 | int b =15; |
---|
790 | int c =4; |
---|
791 | int t =1; |
---|
792 | poly f =x^a+y^b+z^(3*c)+x^(c+2)*y^(c-1)+x^(c-1)*y^(c-1)*z3+x^(c-2)*y^c*(y2+t*x)^2; |
---|
793 | ideal i= jacob(f); |
---|
794 | |
---|
795 | ring r=0,(x,y,z),ds; |
---|
796 | int a =25; |
---|
797 | int b =25; |
---|
798 | int c =5; |
---|
799 | int t =1; |
---|
800 | poly f =x^a+y^b+z^(3*c)+x^(c+2)*y^(c-1)+x^(c-1)*y^(c-1)*z3+x^(c-2)*y^c*(y2+t*x)^2; |
---|
801 | ideal i= jacob(f),f; |
---|
802 | |
---|
803 | ring r=0,(x,y,z),ds; |
---|
804 | int a=10; |
---|
805 | poly f =xyz*(x+y+z)^2 +(x+y+z)^3 +x^a+y^a+z^a; |
---|
806 | ideal i= jacob(f); |
---|
807 | |
---|
808 | ring r=0,(x,y,z),ds; |
---|
809 | int a =6; |
---|
810 | int b =8; |
---|
811 | int c =10; |
---|
812 | int alpha =5; |
---|
813 | int beta= 5; |
---|
814 | int t= 1; |
---|
815 | poly f =x^a+y^b+z^c+x^alpha*y^(beta-5)+x^(alpha-2)*y^(beta-3)+x^(alpha-3)*y^(beta-4)*z^2+x^(alpha-4)*y^(beta-4)*(y^2+t*x)^2; |
---|
816 | ideal i= jacob(f); |
---|
817 | |
---|
818 | */ |
---|
819 | |
---|
820 | /* |
---|
821 | ring r=0,(x,y,z),lp; |
---|
822 | poly s1 = 5x3y2z+3y3x2z+7xy2z2; |
---|
823 | poly s2 = 3xy2z2+x5+11y2z2; |
---|
824 | poly s3 = 4xyz+7x3+12y3+1; |
---|
825 | poly s4 = 3x3-4y3+yz2; |
---|
826 | ideal i = s1, s2, s3, s4; |
---|
827 | |
---|
828 | ring r=0,(x,y,z),lp; |
---|
829 | poly s1 = 2xy4z2+x3y2z-x2y3z+2xyz2+7y3+7; |
---|
830 | poly s2 = 2x2y4z+x2yz2-xy2z2+2x2yz-12x+12y; |
---|
831 | poly s3 = 2y5z+x2y2z-xy3z-xy3+y4+2y2z; |
---|
832 | poly s4 = 3xy4z3+x2y2z-xy3z+4y3z2+3xyz3+4z2-x+y; |
---|
833 | ideal i = s1, s2, s3, s4; |
---|
834 | |
---|
835 | ring r=0,(x,y,z),lp; |
---|
836 | poly s1 = 8x2y2 + 5xy3 + 3x3z + x2yz; |
---|
837 | poly s2 = x5 + 2y3z2 + 13y2z3 + 5yz4; |
---|
838 | poly s3 = 8x3 + 12y3 + xz2 + 3; |
---|
839 | poly s4 = 7x2y4 + 18xy3z2 + y3z3; |
---|
840 | ideal i = s1, s2, s3, s4; |
---|
841 | |
---|
842 | int n = 6; |
---|
843 | ring r = 0,(x(1..n)),lp; |
---|
844 | ideal i = cyclic(n); |
---|
845 | ring s=0,(x(1..n),t),lp; |
---|
846 | ideal i=imap(r,i); |
---|
847 | i=homog(i,t); |
---|
848 | |
---|
849 | ring r=0,(x(1..4),s),(dp(4),dp); |
---|
850 | poly s1 =1 + s^2*x(1)*x(3) + s^8*x(2)*x(3) + s^19*x(1)*x(2)*x(4); |
---|
851 | poly s2 = x(1) + s^8 *x(1)* x(2)* x(3) + s^19* x(2)* x(4); |
---|
852 | poly s3 = x(2) + s^10*x(3)*x(4) + s^11*x(1)*x(4); |
---|
853 | poly s4 = x(3) + s^4*x(1)*x(2) + s^19*x(1)*x(3)*x(4) +s^24*x(2)*x(3)*x(4); |
---|
854 | poly s5 = x(4) + s^31* x(1)* x(2)* x(3)* x(4); |
---|
855 | ideal i = s1, s2, s3, s4, s5; |
---|
856 | |
---|
857 | ring r=0,(x,y,z),ds; |
---|
858 | int a =16; |
---|
859 | int b =15; |
---|
860 | int c =4; |
---|
861 | int t =1; |
---|
862 | poly f =x^a+y^b+z^(3*c)+x^(c+2)*y^(c-1)+x^(c-1)*y^(c-1)*z3+x^(c-2)*y^c*(y2+t*x)^2; |
---|
863 | ideal i= jacob(f); |
---|
864 | |
---|
865 | ring r=0,(x,y,z),ds; |
---|
866 | int a =25; |
---|
867 | int b =25; |
---|
868 | int c =5; |
---|
869 | int t =1; |
---|
870 | poly f =x^a+y^b+z^(3*c)+x^(c+2)*y^(c-1)+x^(c-1)*y^(c-1)*z3+x^(c-2)*y^c*(y2+t*x)^2; |
---|
871 | ideal i= jacob(f),f; |
---|
872 | |
---|
873 | ring r=0,(x,y,z),ds; |
---|
874 | int a=10; |
---|
875 | poly f =xyz*(x+y+z)^2 +(x+y+z)^3 +x^a+y^a+z^a; |
---|
876 | ideal i= jacob(f); |
---|
877 | |
---|
878 | ring r=0,(x,y,z),ds; |
---|
879 | int a =6; |
---|
880 | int b =8; |
---|
881 | int c =10; |
---|
882 | int alpha =5; |
---|
883 | int beta= 5; |
---|
884 | int t= 1; |
---|
885 | poly f =x^a+y^b+z^c+x^alpha*y^(beta-5)+x^(alpha-2)*y^(beta-3)+x^(alpha-3)*y^(beta-4)*z^2+x^(alpha-4)*y^(beta-4)*(y^2+t*x)^2; |
---|
886 | ideal i= jacob(f); |
---|
887 | |
---|
888 | */ |
---|