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