Changeset 967543 in git
- Timestamp:
- Jan 9, 2007, 1:44:33 PM (17 years ago)
- Branches:
- (u'spielwiese', '17f1d200f27c5bd38f5dfc6e8a0879242279d1d8')
- Children:
- e19002f9deb88fd1159c864fac5fdee7d9e0a293
- Parents:
- 3d4a5a6feb25d26d6b5353dab0cea5db6d585dab
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/LIB/modstd.lib
r3d4a5a r967543 1 1 //GP, last modified 23.10.06 2 2 /////////////////////////////////////////////////////////////////////////////// 3 version="$Id: modstd.lib,v 1. 1 2007-01-09 10:31:49 Singular Exp $";3 version="$Id: modstd.lib,v 1.2 2007-01-09 12:44:33 pfister Exp $"; 4 4 category="Commutative Algebra"; 5 5 info=" … … 18 18 19 19 20 20 21 PROCEDURES: 21 modStd(I ,1); compute the reduced Groebnerbasis of I using modular methods22 modS(I,L); liftings to Q of Groebner bases of I mod p for p in L22 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 23 24 primeList(n); list of n primes <= 2134567879 in decreasing order 24 25 "; 25 26 26 LIB "crypto.lib"; 27 /////////////////////////////////////////////////////////////////////////////// 28 proc modStd(ideal I,list #) 29 "USAGE: modStd(I,[k]); I ideal (an optional integer k) 30 RETURN: if # is empty: 31 an ideal which is with high probability a reduced Groebner basis of I; 32 it is not tested whether the result is a Groebner basis and 33 it is not tested whether the result contains I. 34 if #[1]=1: 35 a Groebner basis which contains I if no warning appears; 36 if I is homogeneous it is a Groebner basis of I 37 NOTE: the procedure computes the reduced Groebner basis of I (over the 38 rational numbers) by using modular methods. If #[1]=1 and a 39 warning appears then the result is a Groebner basis with no defined 40 relation to I; this is a sign that not enough prime numbers have 27 LIB "poly.lib"; 28 LIB "krypto.lib"; 29 /////////////////////////////////////////////////////////////////////////////// 30 proc modStd(ideal I) 31 "USAGE: modStd(I); 32 RETURN: a standard basis of I if no warning appears; 33 NOTE: the procedure computes a standard basis of I (over the 34 rational numbers) by using modular methods. If a 35 warning appears then the result is a standard basis with no defined 36 relation to I; this is a sign that not enough prime numbers have 41 37 been used. For further experiments see procedure modS. 42 38 EXAMPLE: example modStd; shows an example 43 39 " 44 40 { 41 int aa=timer; 45 42 def R0=basering; 46 43 list rl=ringlist(R0); … … 50 47 } 51 48 int l,j,k,q; 49 int en=2134567879; 50 int an=1000000000; 51 intvec hi,hl,hc,hpl,hpc; 52 52 list T,TT; 53 53 list L=primeList(5); 54 L[6]=prime(random( 1000000000,2000000000));54 L[6]=prime(random(an,en)); 55 55 ideal J,cT,lT,K; 56 ideal I0=I; 57 56 ideal I0=I; 57 int h=homog(I); 58 if((!h)&&(ord_test(R0)==0)) 59 { 60 ERROR("input is not homogeneous and ordering is not local"); 61 } 62 if(h) 63 { 64 execute("ring gn="+string(L[6])+",x(1.."+string(nvars(R0))+"),dp;"); 65 ideal I=fetch(R0,I); 66 ideal J=std(I); 67 hi=hilb(J,1); 68 setring R0; 69 } 58 70 for (j=1;j<=size(L);j++) 59 71 { … … 63 75 ideal I=fetch(R0,I); 64 76 option(redSB); 65 ideal I1=groebner(I); 77 if(h) 78 { 79 ideal I1=std(I,hi); 80 } 81 else 82 { 83 if(ord_test(R0)==-1) 84 { 85 ideal I1=std(I); 86 } 87 else 88 { 89 matrix M; 90 ideal I1=liftstd(I,M); 91 } 92 } 66 93 setring R0; 67 94 T[j]=fetch(oro,I1); … … 70 97 //================= delete unlucky primes ==================== 71 98 // unlucky iff the leading ideal is wrong 72 lT=lead(T[size(T)]); 73 for (j=1;j<size(T);j++) 74 { 75 cT=lead(T[j]); 76 for(k=1;k<=size(lT);k++) 77 { 78 if(lT[k]<cT[k]){lT=cT;break;} 79 } 80 if(size(lT)<size(cT)){lT=cT;} 81 } 82 j=1; 83 attrib(lT,"isSB",1); 84 while(j<=size(T)) 85 { 86 cT=lead(T[j]); 87 attrib(cT,"isSB",1); 88 if((size(reduce(cT,lT))!=0)||(size(reduce(lT,cT))!=0)) 89 { 90 T=delete(T,j); 91 L=delete(L,j); 92 j--; 93 } 94 j++; 95 } 99 list LL=deleteUnluckyPrimes(T,L); 100 T=LL[1]; 101 L=LL[2]; 102 lT=LL[3]; 96 103 //============ now all leading ideals are the same ============ 97 104 for(j=1;j<=ncols(T[1]);j++) … … 101 108 TT[k]=T[k][j]; 102 109 } 103 J[j]=liftPoly(TT,L); 110 J[j]=liftPoly(TT,L); 104 111 } 105 112 //=========== chooses more primes up to the moment the result becomes stable … … 107 114 { 108 115 k=0; 109 q=prime(random( 2000000011,2100000000));116 q=prime(random(an,en)); 110 117 while(k<size(L)) 111 118 { … … 114 121 { 115 122 k=0; 116 q=prime(random( 1000000,2100000000));123 q=prime(random(an,en)); 117 124 } 118 125 } … … 123 130 ideal i=fetch(R0,I); 124 131 option(redSB); 125 i=groebner(i); 132 if(h) 133 { 134 i=std(i,hi); 135 } 136 else 137 { 138 if(ord_test(R0)==-1) 139 { 140 i=std(i); 141 } 142 else 143 { 144 matrix M; 145 i=liftstd(i,M); 146 } 147 } 126 148 setring R0; 127 149 T[size(T)+1]=fetch(@r,i); … … 146 168 } 147 169 k=1; 148 for(j=1;j<=size(K);j++){if(K[j]-J[j]!=0){k=0;break;}} 170 for(j=1;j<=size(K);j++) 171 { 172 if(K[j]-J[j]!=0) 173 { 174 k=0; 175 J=K; 176 break; 177 } 178 } 149 179 } 150 180 if(k){break;} 151 181 } 152 //============ optional test for standard basis and I=J ======= 153 if(size(#)>0) 154 { 155 J=std(J); 156 I0=reduce(I0,J); 157 if(size(I0)>0){"WARNING: The input ideal is not contained 182 //============ test for standard basis and I=J ======= 183 "computed";timer-aa;aa=timer; 184 J=std(J); 185 I0=reduce(I0,J); 186 if(size(I0)>0){"WARNING: The input ideal is not contained 158 187 in the ideal generated by the standardbasis";} 159 }160 188 attrib(J,"isSB",1); 189 "verification";timer-aa; 161 190 return(J); 162 191 } … … 167 196 ideal J=modStd(I); 168 197 J; 169 } 170 /////////////////////////////////////////////////////////////////////////////// 171 proc modS(ideal I, list L )198 } 199 /////////////////////////////////////////////////////////////////////////////// 200 proc modS(ideal I, list L, list #) 172 201 "USAGE: modS(I,L); I ideal, L list of primes 202 if size(#)>0 std is used instead of groebner 173 203 RETURN: an ideal which is with high probability a standard basis 174 204 NOTE: This procedure is designed for fast experiments. … … 195 225 ideal i=fetch(R0,I); 196 226 option(redSB); 197 i=groebner(i); 227 if(size(#)>0) 228 { 229 i=std(i); 230 } 231 else 232 { 233 i=groebner(i) 234 } 198 235 setring R0; 199 236 T[j]=fetch(@r,i); … … 202 239 //================= delete unlucky primes ==================== 203 240 // unlucky iff the leading ideal is wrong 204 lT=lead(T[1]); 205 for (j=2;j<=size(T);j++) 206 { 207 cT=lead(T[j]); 208 for(k=1;k<=size(lT);k++) 209 { 210 if(lT[k]<cT[k]){lT=cT;break;} 211 } 212 if(size(lT)<size(cT)){lT=cT;} 213 } 214 j=1; 215 attrib(lT,"isSB",1); 216 while(j<=size(T)) 217 { 218 cT=lead(T[j]); 219 attrib(cT,"isSB",1); 220 if((size(reduce(cT,lT))!=0)||(size(reduce(lT,cT))!=0)) 221 { 222 T=delete(T,j); 223 L=delete(L,j); 224 j--; 225 } 226 j++; 227 } 241 list LL=deleteUnluckyPrimes(T,L); 242 T=LL[1]; 243 L=LL[2]; 228 244 //============ now all leading ideals are the same ============ 229 245 for(j=1;j<=ncols(T[1]);j++) … … 233 249 TT[k]=T[k][j]; 234 250 } 235 J[j]=liftPoly(TT,L); 236 251 J[j]=liftPoly(TT,L); 237 252 } 238 253 attrib(J,"isSB",1); … … 246 261 ideal J=modS(I,L); 247 262 J; 248 } 263 } 264 /////////////////////////////////////////////////////////////////////////////// 265 proc deleteUnluckyPrimes(list T,list L) 266 "USAGE: deleteUnluckyPrimes(T,L);T list of polys, L list of primes 267 RETURN: list L,T with T list of polys, L list of primes 268 EXAMPLE: example deleteUnluckyPrimes; shows an example 269 NOTE: works only for homogeneous ideals with global orderings or 270 for ideals with local orderings 271 " 272 { 273 int j,k; 274 intvec hl,hc; 275 ideal cT,lT; 276 277 lT=lead(T[size(T)]); 278 attrib(lT,"isSB",1); 279 hl=hilb(lT,1); 280 for (j=1;j<size(T);j++) 281 { 282 cT=lead(T[j]); 283 attrib(cT,"isSB",1); 284 hc=hilb(cT,1); 285 if(hl==hc) 286 { 287 for(k=1;k<=size(lT);k++) 288 { 289 if(lT[k]<cT[k]){lT=cT;break;} 290 if(lT[k]>cT[k]){break;} 291 } 292 } 293 else 294 { 295 if(hc<hl){lT=cT;hl=hilb(lT,1);} 296 } 297 } 298 j=1; 299 attrib(lT,"isSB",1); 300 while(j<=size(T)) 301 { 302 cT=lead(T[j]); 303 attrib(cT,"isSB",1); 304 if((size(reduce(cT,lT))!=0)||(size(reduce(lT,cT))!=0)) 305 { 306 T=delete(T,j); 307 L=delete(L,j); 308 j--; 309 } 310 j++; 311 } 312 return(list(T,L,lT)); 313 } 314 example 315 { "EXAMPLE:"; echo = 2; 316 list L=2,3,5,7,11; 317 ring r=0,(y,x),Dp; 318 ideal I1=y2x,y6; 319 ideal I2=yx2,y3x,x5,y6; 320 ideal I3=y2x,x3y,x5,y6; 321 ideal I4=y2x,x3y,x5; 322 ideal I5=y2x,yx3,x5,y6; 323 list T=I1,I2,I3,I4,I5; 324 list TT=deleteUnluckyPrimes(T,L); 325 TT; 326 } 249 327 /////////////////////////////////////////////////////////////////////////////// 250 328 proc liftPoly(list T, list L) … … 259 337 list TT; 260 338 number n; 261 339 262 340 number N=L[1]; 263 341 for(i=2;i<=size(L);i++) … … 288 366 } 289 367 } 290 n=chineseR(TT,L );291 n=Farey(N,n); 368 n=chineseR(TT,L,N); 369 n=Farey(N,n); 292 370 result=result+n*p; 293 371 } … … 300 378 liftPoly(T,L); 301 379 } 380 /////////////////////////////////////////////////////////////////////////////// 381 proc fareyIdeal(ideal I,list L) 382 { 383 poly result,p; 384 int i,j; 385 number n; 386 number N=L[1]; 387 for(i=2;i<=size(L);i++) 388 { 389 N=N*L[i]; 390 } 391 392 for(i=1;i<=size(I);i++) 393 { 394 p=I[i]; 395 result=lead(p); 396 while(1) 397 { 398 if (p==0) {break;} 399 p=p-lead(p); 400 n=Farey(N,leadcoef(p)); 401 result=result+n*leadmonom(p); 402 } 403 I[i]=result; 404 } 405 return(I); 406 } 302 407 /////////////////////////////////////////////////////////////////////////////// 303 408 proc Farey (number P, number N) 304 409 "USAGE: Farey (P,N); P, N number; 305 RETURN: a rational number a/b such that a/b=N mod P 410 RETURN: a rational number a/b such that a/b=N mod P 306 411 and |a|,|b|<(P/2)^{1/2} 307 412 " … … 314 419 while (N!=0) 315 420 { 316 if (2*N^2<P){return(N/B);} 317 D=E mod N; 318 C=A-(E-E mod N)/N*B; 319 E=N; 320 N=D; 321 A=B; 322 B=C; 421 if (2*N^2<P) 422 { 423 return(N/B); 424 } 425 D=E mod N; 426 C=A-(E-E mod N)/N*B; 427 E=N; 428 N=D; 429 A=B; 430 B=C; 323 431 } 324 432 return(0); … … 329 437 Farey(32003,12345); 330 438 } 331 ///////////////////////////////////////////////////////////////////////////////332 proc chineseR(list T,list L )333 "USAGE: chineseR em(T,L);439 /////////////////////////////////////////////////////////////////////////////// 440 proc chineseR(list T,list L,number N) 441 "USAGE: chineseR(T,L); 334 442 RETURN: x such that x = T[i] mod L[i] 335 443 NOTE: chinese remainder theorem 336 EXAMPLE:example chineseR em; shows an example444 EXAMPLE:example chineseR; shows an example 337 445 " 338 446 { … … 341 449 { 342 450 x=T[1] mod L[1]; 343 if(x>L[1]/2){x=x-L[1];}344 451 return(x); 345 452 } 346 453 int i; 347 454 int n=size(L); 348 number N=1;349 for(i=1;i<=n;i++)350 {351 N=N*L[i];352 }353 455 list M; 354 456 for(i=1;i<=n;i++) … … 362 464 } 363 465 x=x mod N; 364 if (x>N/2) { x=x-N; }365 466 return(x); 366 467 } … … 368 469 { "EXAMPLE:"; echo = 2; 369 470 ring R = 0,x,dp; 370 chineseRem(list(24,15,7),list(2,3,5)); 371 } 471 chineseR(list(24,15,7),list(2,3,5)); 472 } 473 372 474 /////////////////////////////////////////////////////////////////////////////// 373 475 proc primeList(int n) 374 476 "USAGE: primeList(n); 375 RETURN: the list of n greatest primes <= 2134567879 477 RETURN: the list of n greatest primes <= 2134567879 376 478 EXAMPLE:example primList; shows an example 377 479 " … … 392 494 size(L); 393 495 L[size(L)]; 394 } 496 } 395 497 /////////////////////////////////////////////////////////////////////////////// 396 498 /* … … 416 518 ideal i = s1, s2, s3, s4; 417 519 418 ring r=0,x(1..4),lp; 419 ideal i=cyclic(4); 520 int n = 6; 521 ring r = 0,(x(1..n)),lp; 522 ideal i = cyclic(n); 523 ring s=0,(x(1..n),t),lp; 524 ideal i=imap(r,i); 525 i=homog(i,t); 420 526 421 527 ring r=0,(x(1..4),s),(dp(4),dp); … … 426 532 poly s5 = x(4) + s^31* x(1)* x(2)* x(3)* x(4); 427 533 ideal i = s1, s2, s3, s4, s5; 534 535 ring r=0,(x,y,z),ds; 536 int a =16; 537 int b =15; 538 int c =4; 539 int t =1; 540 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; 541 ideal i= jacob(f); 542 543 ring r=0,(x,y,z),ds; 544 int a =25; 545 int b =25; 546 int c =5; 547 int t =1; 548 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; 549 ideal i= jacob(f),f; 550 551 ring r=0,(x,y,z),ds; 552 int a=10; 553 poly f =xyz*(x+y+z)^2 +(x+y+z)^3 +x^a+y^a+z^a; 554 ideal i= jacob(f); 555 556 ring r=0,(x,y,z),ds; 557 int a =6; 558 int b =8; 559 int c =10; 560 int alpha =5; 561 int beta= 5; 562 int t= 1; 563 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; 564 ideal i= jacob(f); 565 428 566 */
Note: See TracChangeset
for help on using the changeset viewer.