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 | bigint 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,bigint(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 | bigint 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,bigint(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 | bigint 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,bigint(leadcoef(p))); |
---|
483 | result=result+n*leadmonom(p); |
---|
484 | } |
---|
485 | I[i]=result; |
---|
486 | } |
---|
487 | return(I); |
---|
488 | } |
---|
489 | /////////////////////////////////////////////////////////////////////////////// |
---|
490 | proc Farey (bigint P, bigint 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 | bigint 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(number(N)/number(B)); |
---|
506 | } |
---|
507 | D=E mod N; |
---|
508 | C=A-(E div 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 | bigint cb=p; |
---|
584 | matrix G0=transpose(matrix(G)); |
---|
585 | G0= MmodN(G0+ (c)* G22,cb^2); |
---|
586 | matrix GF=fareyMatrix(G0,cb^2); |
---|
587 | Z=MmodN(Z+(c)*Z2,cb^2); |
---|
588 | matrix C=transpose(G); |
---|
589 | int n=3; |
---|
590 | while(GF<>C) |
---|
591 | { |
---|
592 | C=GF; |
---|
593 | G1= gstrich2(c,Z,i,G0,n); |
---|
594 | g1=G1; |
---|
595 | g22=reduce(g1,G); |
---|
596 | G22=transpose(matrix(g22)); |
---|
597 | M=redmat(G,G1,G22); |
---|
598 | Z2=-M*Z; |
---|
599 | Z=MmodN(Z+(c^(n-1))*Z2,cb^n); |
---|
600 | G0= MmodN(G0+ (c^(n-1))* G22,cb^n); |
---|
601 | GF=fareyMatrix(G0,cb^n); |
---|
602 | n++; |
---|
603 | } |
---|
604 | return(ideal(GF)); |
---|
605 | } |
---|
606 | example |
---|
607 | { "EXAMPLE:"; echo = 2; |
---|
608 | ring r=0,(x,y,z),dp; |
---|
609 | ideal I=3x3+x2+1,11y5+y3+2,5z4+z2+4; |
---|
610 | ideal J=pStd(32003,I); |
---|
611 | J; |
---|
612 | } |
---|
613 | /////////////////////////////////////////////////////////////////////////// |
---|
614 | proc transmat(int p,ideal i,ideal G) |
---|
615 | "USAGE: transmat(p,I,G); p integer, I,G ideal; |
---|
616 | RETURN: the transformationmatrix Z for the ideal i mod p and the groebner base for i mod p |
---|
617 | EXAMPLE: example transmat; shows an example |
---|
618 | " |
---|
619 | { |
---|
620 | def r=basering; |
---|
621 | int n=nvars(r); |
---|
622 | list rl=ringlist(r); |
---|
623 | rl[1]=p; |
---|
624 | def r1=ring(rl); |
---|
625 | setring r1; |
---|
626 | ideal i=fetch(r,i); |
---|
627 | ideal G=fetch(r,G); |
---|
628 | attrib(G,"isSB",1); |
---|
629 | ring rhelp=p,x(1..n),dp; |
---|
630 | list lhelp=ringlist(rhelp); |
---|
631 | list l=lhelp[3]; |
---|
632 | setring r; |
---|
633 | rl[3]=l; |
---|
634 | def r2=ring(rl); |
---|
635 | setring r2; |
---|
636 | ideal i=fetch(r,i); |
---|
637 | option(redSB); |
---|
638 | ideal j=std(i); |
---|
639 | matrix T=lift(i,j); |
---|
640 | setring r1; |
---|
641 | matrix T=fetch(r2,T); |
---|
642 | ideal j=fetch(r2,j); |
---|
643 | matrix M=lift(j,G); |
---|
644 | matrix Z=transpose(T*M); |
---|
645 | setring r; |
---|
646 | matrix Z=fetch(r1,Z); |
---|
647 | return(Z); |
---|
648 | } |
---|
649 | example |
---|
650 | { "EXAMPLE:"; echo = 2; |
---|
651 | ring r=0,(x,y,z),dp; |
---|
652 | ideal i=3x3+x2+1,11y5+y3+2,5z4+z2+4; |
---|
653 | ideal g=x3-60x2-60, z4-36z2+37, y5+33y3+66; |
---|
654 | int p=181; |
---|
655 | matrix Z=transmat(p,i,g); |
---|
656 | Z; |
---|
657 | } |
---|
658 | |
---|
659 | /////////////////////////////////////////////////////////////////////////// |
---|
660 | proc gstrich1(int p, matrix Z, ideal i, ideal gp) |
---|
661 | "USAGE: gstrich1 (p,Z,i,gp); p integer, Z matrix, i,gp ideals; |
---|
662 | RETURN: a matrix G such that (Z*F-GP)/p, where F and GP are the matrices of the ideals i and gp |
---|
663 | " |
---|
664 | { |
---|
665 | matrix F=transpose(matrix(i)); |
---|
666 | matrix GP=transpose(matrix(gp)); |
---|
667 | matrix G=(Z*F-GP)/p; |
---|
668 | return(G); |
---|
669 | } |
---|
670 | /////////////////////////////////////////////////////////////////////////// |
---|
671 | proc gstrich2(number p, matrix Z, ideal i, ideal gp, int n) |
---|
672 | "USAGE: gstrich2 (p,Z,i,gp,n); p,n integer, Z matrix, i,gp ideals; |
---|
673 | 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 |
---|
674 | " |
---|
675 | { |
---|
676 | matrix F=transpose(matrix(i)); |
---|
677 | matrix GP=transpose(matrix(gp)); |
---|
678 | matrix G=(Z*F-GP)/(p^(n-1)); |
---|
679 | return(G); |
---|
680 | } |
---|
681 | /////////////////////////////////////////////////////////////////////////// |
---|
682 | proc redmat(ideal i, matrix h, matrix g) |
---|
683 | "USAGE: redmat(i,h,g); i ideal , h,g matrices; |
---|
684 | RETURN: a matrix M such that i=M*h+g |
---|
685 | " |
---|
686 | { |
---|
687 | matrix c=h-g; |
---|
688 | ideal f=transpose(c); |
---|
689 | matrix N=lift(i,f); |
---|
690 | matrix M=transpose(N); |
---|
691 | return(M); |
---|
692 | } |
---|
693 | /////////////////////////////////////////////////////////////////////////// |
---|
694 | proc fareyMatrix(matrix m,bigint N) |
---|
695 | "USAGE: fareyMatrix(m,y); m matrix, y integer; |
---|
696 | RETURN: a matrix k of the matrix m with Farey rational numbers a/b as coefficients |
---|
697 | EXAMPLE: example fareyMatrix; shows an example |
---|
698 | " |
---|
699 | { |
---|
700 | ideal I=m; |
---|
701 | poly result,p; |
---|
702 | int i,j; |
---|
703 | number n; |
---|
704 | for(i=1;i<=size(I);i++) |
---|
705 | { |
---|
706 | p=I[i]; |
---|
707 | result=lead(p); |
---|
708 | while(1) |
---|
709 | { |
---|
710 | if (p==0) {break;} |
---|
711 | p=p-lead(p); |
---|
712 | n=Farey(N,bigint(leadcoef(p))); |
---|
713 | result=result+n*leadmonom(p); |
---|
714 | } |
---|
715 | I[i]=result; |
---|
716 | } |
---|
717 | matrix k=transpose(I); |
---|
718 | return(k); |
---|
719 | } |
---|
720 | example |
---|
721 | {"EXAMPLE:"; echo = 2; |
---|
722 | ring r=0,(x,y,z),dp; |
---|
723 | matrix m[3][1]=x3+682794673x2+682794673,z4+204838402z2+819353608, y5+186216729y3+372433458; |
---|
724 | int p=32003; |
---|
725 | matrix b=fareyMatrix(m,p^2); |
---|
726 | b; |
---|
727 | } |
---|
728 | /////////////////////////////////////////////////////////////////////////// |
---|
729 | proc MmodN(matrix Z,bigint N) |
---|
730 | "USAGE: MmodN(Z,N);Z matrix, N bigint; |
---|
731 | RETURN: the matrix Z mod N |
---|
732 | EXAMPLE: example MmodN; |
---|
733 | " |
---|
734 | { |
---|
735 | int i,j,k; |
---|
736 | poly m,p; |
---|
737 | number c; |
---|
738 | for(i=1;i<=nrows(Z);i++) |
---|
739 | { |
---|
740 | for(j=1;j<=ncols(Z);j++) |
---|
741 | { |
---|
742 | for(k=1;k<=size(Z[i,j]);k++) |
---|
743 | { |
---|
744 | m=leadmonom(Z[i,j][k]); |
---|
745 | c=bigint(leadcoef(Z[i,j][k])) mod N; |
---|
746 | p=p+c*m; |
---|
747 | } |
---|
748 | Z[i,j]=p; |
---|
749 | p=0; |
---|
750 | } |
---|
751 | } |
---|
752 | return(Z); |
---|
753 | } |
---|
754 | example |
---|
755 | { "EXAMPLE:"; echo = 2; |
---|
756 | ring r = 0,(x,y,z),dp; |
---|
757 | matrix m[3][1]= x3+10668x2+10668, z4-12801z2+12802, y5-8728y3+14547; |
---|
758 | bigint p=32003; |
---|
759 | matrix b=MmodN(m,p^2); |
---|
760 | b; |
---|
761 | } |
---|
762 | /////////////////////////////////////////////////////////////////////////////// |
---|
763 | /* |
---|
764 | ring r=0,(x,y,z),lp; |
---|
765 | poly s1 = 5x3y2z+3y3x2z+7xy2z2; |
---|
766 | poly s2 = 3xy2z2+x5+11y2z2; |
---|
767 | poly s3 = 4xyz+7x3+12y3+1; |
---|
768 | poly s4 = 3x3-4y3+yz2; |
---|
769 | ideal i = s1, s2, s3, s4; |
---|
770 | |
---|
771 | ring r=0,(x,y,z),lp; |
---|
772 | poly s1 = 2xy4z2+x3y2z-x2y3z+2xyz2+7y3+7; |
---|
773 | poly s2 = 2x2y4z+x2yz2-xy2z2+2x2yz-12x+12y; |
---|
774 | poly s3 = 2y5z+x2y2z-xy3z-xy3+y4+2y2z; |
---|
775 | poly s4 = 3xy4z3+x2y2z-xy3z+4y3z2+3xyz3+4z2-x+y; |
---|
776 | ideal i = s1, s2, s3, s4; |
---|
777 | |
---|
778 | ring r=0,(x,y,z),lp; |
---|
779 | poly s1 = 8x2y2 + 5xy3 + 3x3z + x2yz; |
---|
780 | poly s2 = x5 + 2y3z2 + 13y2z3 + 5yz4; |
---|
781 | poly s3 = 8x3 + 12y3 + xz2 + 3; |
---|
782 | poly s4 = 7x2y4 + 18xy3z2 + y3z3; |
---|
783 | ideal i = s1, s2, s3, s4; |
---|
784 | |
---|
785 | int n = 6; |
---|
786 | ring r = 0,(x(1..n)),lp; |
---|
787 | ideal i = cyclic(n); |
---|
788 | ring s=0,(x(1..n),t),lp; |
---|
789 | ideal i=imap(r,i); |
---|
790 | i=homog(i,t); |
---|
791 | |
---|
792 | ring r=0,(x(1..4),s),(dp(4),dp); |
---|
793 | poly s1 =1 + s^2*x(1)*x(3) + s^8*x(2)*x(3) + s^19*x(1)*x(2)*x(4); |
---|
794 | poly s2 = x(1) + s^8 *x(1)* x(2)* x(3) + s^19* x(2)* x(4); |
---|
795 | poly s3 = x(2) + s^10*x(3)*x(4) + s^11*x(1)*x(4); |
---|
796 | 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); |
---|
797 | poly s5 = x(4) + s^31* x(1)* x(2)* x(3)* x(4); |
---|
798 | ideal i = s1, s2, s3, s4, s5; |
---|
799 | |
---|
800 | ring r=0,(x,y,z),ds; |
---|
801 | int a =16; |
---|
802 | int b =15; |
---|
803 | int c =4; |
---|
804 | int t =1; |
---|
805 | 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; |
---|
806 | ideal i= jacob(f); |
---|
807 | |
---|
808 | ring r=0,(x,y,z),ds; |
---|
809 | int a =25; |
---|
810 | int b =25; |
---|
811 | int c =5; |
---|
812 | int t =1; |
---|
813 | 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; |
---|
814 | ideal i= jacob(f),f; |
---|
815 | |
---|
816 | ring r=0,(x,y,z),ds; |
---|
817 | int a=10; |
---|
818 | poly f =xyz*(x+y+z)^2 +(x+y+z)^3 +x^a+y^a+z^a; |
---|
819 | ideal i= jacob(f); |
---|
820 | |
---|
821 | ring r=0,(x,y,z),ds; |
---|
822 | int a =6; |
---|
823 | int b =8; |
---|
824 | int c =10; |
---|
825 | int alpha =5; |
---|
826 | int beta= 5; |
---|
827 | int t= 1; |
---|
828 | 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; |
---|
829 | ideal i= jacob(f); |
---|
830 | |
---|
831 | */ |
---|
832 | |
---|
833 | /* |
---|
834 | ring r=0,(x,y,z),lp; |
---|
835 | poly s1 = 5x3y2z+3y3x2z+7xy2z2; |
---|
836 | poly s2 = 3xy2z2+x5+11y2z2; |
---|
837 | poly s3 = 4xyz+7x3+12y3+1; |
---|
838 | poly s4 = 3x3-4y3+yz2; |
---|
839 | ideal i = s1, s2, s3, s4; |
---|
840 | |
---|
841 | ring r=0,(x,y,z),lp; |
---|
842 | poly s1 = 2xy4z2+x3y2z-x2y3z+2xyz2+7y3+7; |
---|
843 | poly s2 = 2x2y4z+x2yz2-xy2z2+2x2yz-12x+12y; |
---|
844 | poly s3 = 2y5z+x2y2z-xy3z-xy3+y4+2y2z; |
---|
845 | poly s4 = 3xy4z3+x2y2z-xy3z+4y3z2+3xyz3+4z2-x+y; |
---|
846 | ideal i = s1, s2, s3, s4; |
---|
847 | |
---|
848 | ring r=0,(x,y,z),lp; |
---|
849 | poly s1 = 8x2y2 + 5xy3 + 3x3z + x2yz; |
---|
850 | poly s2 = x5 + 2y3z2 + 13y2z3 + 5yz4; |
---|
851 | poly s3 = 8x3 + 12y3 + xz2 + 3; |
---|
852 | poly s4 = 7x2y4 + 18xy3z2 + y3z3; |
---|
853 | ideal i = s1, s2, s3, s4; |
---|
854 | |
---|
855 | int n = 6; |
---|
856 | ring r = 0,(x(1..n)),lp; |
---|
857 | ideal i = cyclic(n); |
---|
858 | ring s=0,(x(1..n),t),lp; |
---|
859 | ideal i=imap(r,i); |
---|
860 | i=homog(i,t); |
---|
861 | |
---|
862 | ring r=0,(x(1..4),s),(dp(4),dp); |
---|
863 | poly s1 =1 + s^2*x(1)*x(3) + s^8*x(2)*x(3) + s^19*x(1)*x(2)*x(4); |
---|
864 | poly s2 = x(1) + s^8 *x(1)* x(2)* x(3) + s^19* x(2)* x(4); |
---|
865 | poly s3 = x(2) + s^10*x(3)*x(4) + s^11*x(1)*x(4); |
---|
866 | 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); |
---|
867 | poly s5 = x(4) + s^31* x(1)* x(2)* x(3)* x(4); |
---|
868 | ideal i = s1, s2, s3, s4, s5; |
---|
869 | |
---|
870 | ring r=0,(x,y,z),ds; |
---|
871 | int a =16; |
---|
872 | int b =15; |
---|
873 | int c =4; |
---|
874 | int t =1; |
---|
875 | 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; |
---|
876 | ideal i= jacob(f); |
---|
877 | |
---|
878 | ring r=0,(x,y,z),ds; |
---|
879 | int a =25; |
---|
880 | int b =25; |
---|
881 | int c =5; |
---|
882 | int t =1; |
---|
883 | 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; |
---|
884 | ideal i= jacob(f),f; |
---|
885 | |
---|
886 | ring r=0,(x,y,z),ds; |
---|
887 | int a=10; |
---|
888 | poly f =xyz*(x+y+z)^2 +(x+y+z)^3 +x^a+y^a+z^a; |
---|
889 | ideal i= jacob(f); |
---|
890 | |
---|
891 | ring r=0,(x,y,z),ds; |
---|
892 | int a =6; |
---|
893 | int b =8; |
---|
894 | int c =10; |
---|
895 | int alpha =5; |
---|
896 | int beta= 5; |
---|
897 | int t= 1; |
---|
898 | 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; |
---|
899 | ideal i= jacob(f); |
---|
900 | |
---|
901 | */ |
---|
902 | |
---|