Changeset a14482 in git
- Timestamp:
- Feb 26, 2015, 6:55:30 PM (9 years ago)
- Branches:
- (u'spielwiese', '8e0ad00ce244dfd0756200662572aef8402f13d5')
- Children:
- e57a75c6d0050e3db7e1a87294a311d4784df43c
- Parents:
- eca8d9cc9b3584a2f5741c75f69099751c4cbe8f
- Location:
- Singular
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/LIB/modwalk.lib
reca8d9 ra14482 16 16 17 17 PROCEDURES: 18 modpWalk(ideal,int,int,int[,int,int,int,int]) standard basis conversion of I in prime characteristic 19 modWalk(ideal,int,int[,int,int,int,int]); standard basis conversion of I using modular methods (chinese remainder) 18 19 modWalk(I,#); standard basis conversion of I by Groebner Walk using modular methods 20 modrWalk(I,radius,pertdeg,#); standard basis conversion of I by Random Walk using modular methods 21 modfWalk(I,#); standard basis conversion of I by Fractal Walk using modular methods 22 modfrWalk(I,radius,#); standard basis conversion of I by Random Fractal Walk using modular methods 20 23 "; 21 24 22 LIB "poly.lib";23 LIB "ring.lib";24 LIB "parallel.lib";25 25 LIB "rwalk.lib"; 26 26 LIB "grwalk.lib"; 27 LIB "modstd.lib"; 28 29 30 //////////////////////////////////////////////////////////////////////////////// 31 32 proc modpWalk(def II, int p, int variant, int reduction, list #) 33 "USAGE: modpWalk(I,p,#); I ideal, p integer, variant integer 34 ASSUME: If size(#) > 0, then 35 #[1] is an intvec describing the current weight vector 36 #[2] is an intvec describing the target weight vector 37 RETURN: ideal - a standard basis of I mod p, integer - p 38 NOTE: The procedure computes a standard basis of the ideal I modulo p and 39 fetches the result to the basering. 40 EXAMPLE: example modpWalk; shows an example 41 " 42 { 43 option(redSB); 44 int k,nvar@r; 45 def R0 = basering; 46 string ordstr_R0 = ordstr(R0); 47 list rl = ringlist(R0); 48 int sizerl = size(rl); 49 int neg = 1 - attrib(R0,"global"); 50 if(typeof(II) == "ideal") 51 { 52 ideal I = II; 27 LIB "modular.lib"; 28 29 proc modWalk(ideal I, list #) 30 "USAGE: modWalk(I, [, v, w]); I ideal, v intvec, w intvec 31 RETURN: a standard basis of I 32 NOTE: The procedure computes a standard basis of I (over the rational 33 numbers) by using modular methods. 34 SEE ALSO: modular 35 EXAMPLE: example modWalk; shows an example" 36 { 37 /* read optional parameter */ 38 if (size(#) > 0) { 39 if (size(#) == 1) { 40 intvec w = #[1]; 41 } 42 if (size(#) == 2) { 43 intvec v = #[1]; 44 intvec w = #[2]; 45 } 46 if (size(#) > 2 || typeof(#[1]) != "intvec") { 47 ERROR("wrong optional parameter"); 48 } 49 } 50 51 /* save options */ 52 intvec opt = option(get); 53 option(redSB); 54 55 /* set additional parameters */ 56 int reduction = 1; 57 int printout = 0; 58 59 /* call modular() */ 60 if (size(#) > 0) { 61 I = modular("gwalk", list(I,reduction,printout,#)); 62 } 63 else { 64 I = modular("gwalk", list(I,reduction,printout)); 65 } 66 67 /* return the result */ 68 attrib(I, "isSB", 1); 69 option(set, opt); 70 return(I); 71 } 72 example 73 { 74 "EXAMPLE:"; 75 echo = 2; 76 ring R1 = 0, (x,y,z,t), dp; 77 ideal I = 3x3+x2+1, 11y5+y3+2, 5z4+z2+4; 78 I = std(I); 79 ring R2 = 0, (x,y,z,t), lp; 80 ideal I = fetch(R1, I); 81 ideal J = modWalk(I); 82 J; 83 } 84 85 proc modrWalk(ideal I, int radius, int pertdeg, list #) 86 "USAGE: modrWalk(I, radius, pertdeg[, v, w]); 87 I ideal, radius int, pertdeg int, v intvec, w intvec 88 RETURN: a standard basis of I 89 NOTE: The procedure computes a standard basis of I (over the rational 90 numbers) by using modular methods. 91 SEE ALSO: modular 92 EXAMPLE: example modrWalk; shows an example" 93 { 94 /* read optional parameter */ 95 if (size(#) > 0) { 96 if (size(#) == 1) { 97 intvec w = #[1]; 98 } 99 if (size(#) == 2) { 100 intvec v = #[1]; 101 intvec w = #[2]; 102 } 103 if (size(#) > 2 || typeof(#[1]) != "intvec") { 104 ERROR("wrong optional parameter"); 105 } 106 } 107 108 /* save options */ 109 intvec opt = option(get); 110 option(redSB); 111 112 /* set additional parameters */ 113 int reduction = 1; 114 int printout = 0; 115 116 /* call modular() */ 117 if (size(#) > 0) { 118 I = modular("rwalk", list(I,radius,pertdeg,reduction,printout,#)); 119 } 120 else { 121 I = modular("rwalk", list(I,radius,pertdeg,reduction,printout)); 122 } 123 124 /* return the result */ 125 attrib(I, "isSB", 1); 126 option(set, opt); 127 return(I); 128 } 129 example 130 { 131 "EXAMPLE:"; 132 echo = 2; 133 ring R1 = 0, (x,y,z,t), dp; 134 ideal I = 3x3+x2+1, 11y5+y3+2, 5z4+z2+4; 135 I = std(I); 136 ring R2 = 0, (x,y,z,t), lp; 137 ideal I = fetch(R1, I); 53 138 int radius = 2; 54 int pert_deg = 2; 55 } 56 if(typeof(II) == "list" && typeof(II[1]) == "ideal") 57 { 58 ideal I = II[1]; 59 if(size(II) == 2) 60 { 61 int radius = II[2]; 62 int pert_deg = 2; 63 } 64 if(size(II) == 3) 65 { 66 int radius = II[2]; 67 int pert_deg = II[3]; 68 } 69 } 70 rl[1] = p; 71 int h = homog(I); 72 def @r = ring(rl); 73 setring @r; 74 ideal i = fetch(R0,I); 75 string order; 76 if(system("nblocks") <= 2) 77 { 78 if(find(ordstr_R0, "M") + find(ordstr_R0, "lp") + find(ordstr_R0, "rp") <= 0) 79 { 80 order = "simple"; 81 } 82 } 83 <<<<<<< HEAD 84 ======= 85 86 //------------------------- make i homogeneous ----------------------------- 87 if(!mixedTest() && !h) 88 { 89 if(!((find(ordstr_R0, "M") > 0) || (find(ordstr_R0, "a") > 0) || neg)) 90 { 91 if(!((order == "simple") || (sizerl > 4))) 92 { 93 list rl@r = ringlist(@r); 94 nvar@r = nvars(@r); 95 intvec w; 96 for(k = 1; k <= nvar@r; k++) 97 { 98 w[k] = deg(var(k)); 99 } 100 w[nvar@r + 1] = 1; 101 rl@r[2][nvar@r + 1] = "homvar"; 102 rl@r[3][2][2] = w; 103 def HomR = ring(rl@r); 104 setring HomR; 105 ideal i = imap(@r, i); 106 i = homog(i, homvar); 107 } 108 } 109 } 110 111 >>>>>>> f533f6f7667328bccb271b19b2f603aaebe41596 112 //------------------------- compute a standard basis mod p ----------------------------- 113 if(variant == 1) 114 { 115 if(size(#)>0) 116 { 117 i = rwalk(i,radius,pert_deg,reduction,#); 118 } 119 else 120 { 121 i = rwalk(i,radius,pert_deg,reduction); 122 } 123 } 124 if(variant == 2) 125 { 126 if(size(#) == 2) 127 { 128 i = gwalk(i,reduction,#); 129 } 130 else 131 { 132 i = gwalk(i,reduction); 133 } 134 } 135 if(variant == 3) 136 { 137 if(size(#) == 2) 138 { 139 i = frandwalk(i,radius,reduction,#); 140 } 141 else 142 { 143 i = frandwalk(i,radius,reduction); 144 } 145 } 146 if(variant == 4) 147 { 148 if(size(#) == 2) 149 { 150 i=fwalk(i,#); 151 } 152 else 153 { 154 i=fwalk(i); 155 } 156 } 157 if(variant == 5) 158 { 159 if(size(#) == 2) 160 { 161 i=prwalk(i,radius,pert_deg,pert_deg,reduction,#); 162 } 163 else 164 { 165 i=prwalk(i,radius,pert_deg,pert_deg,reduction); 166 } 167 } 168 if(variant == 6) 169 { 170 if(size(#) == 2) 171 { 172 i=pwalk(i,pert_deg,pert_deg,reduction,#); 173 } 174 else 175 { 176 <<<<<<< HEAD 177 i=pwalk(i,pert_deg,pert_deg,reduction); 178 ======= 179 i=pwalk(i,pert_deg,pert_deg); 180 } 181 } 182 183 if(!mixedTest() && !h) 184 { 185 if(!((find(ordstr_R0, "M") > 0) || (find(ordstr_R0, "a") > 0) || neg)) 186 { 187 if(!((order == "simple") || (sizerl > 4))) 188 { 189 i = subst(i, homvar, 1); 190 i = simplify(i, 34); 191 setring @r; 192 i = imap(HomR, i); 193 i = interred(i); 194 kill HomR; 195 } 196 >>>>>>> f533f6f7667328bccb271b19b2f603aaebe41596 197 } 198 } 199 200 setring R0; 201 return(list(fetch(@r,i),p)); 202 } 203 example 204 { 205 "EXAMPLE:"; echo = 2; 206 option(redSB); 207 208 int p = 181; 209 intvec a = 2,1,3,4; 210 intvec b = 1,9,1,1; 211 ring ra = 0,x(1..4),(a(a),lp); 212 ideal I = std(cyclic(4)); 213 int reduction = 1; 214 ring rb = 0,x(1..4),(a(b),lp); 215 ideal I = imap(ra,I); 216 modpWalk(I,p,1,reduction,a,b); 217 std(I); 218 } 219 220 //////////////////////////////////////////////////////////////////////////////// 221 222 proc modWalk(def II, int variant, int reduction, list #) 223 "USAGE: modWalk(II); II ideal or list(ideal,int) 224 ASSUME: If variant = 225 @* - 1 the Random Walk algorithm with radius II[2] is applied 226 to II[1] if II = list(ideal, int). It is applied to II with radius 2 227 if II is an ideal. 228 @* - 2, the Groebner Walk algorithm is applied to II[1] or to II, respectively. 229 @* - 3, the Fractal Walk algorithm with random element is applied to II[1] or II, 230 respectively. 231 @* - 4, the Fractal Walk algorithm is applied to II[1] or II, respectively. 232 @* - 5, the Perturbation Walk algorithm with random element is applied to II[1] 233 or II, respectively, with radius II[3] and perturbation degree II[2]. 234 @* - 6, the Perturbation Walk algorithm is applied to II[1] or II, respectively, 235 with perturbation degree II[3]. 236 If size(#) > 0, then # contains either 1, 2 or 4 integers such that 237 @* - #[1] is the number of available processors for the computation, 238 @* - #[2] is an optional parameter for the exactness of the computation, 239 if #[2] = 1, the procedure computes a standard basis for sure, 240 @* - #[3] is the number of primes until the first lifting, 241 @* - #[4] is the constant number of primes between two liftings until 242 the computation stops. 243 RETURN: a standard basis of I if no warning appears. 244 NOTE: The procedure converts a standard basis of I (over the rational 245 numbers) from the ordering \"a(v),lp\", "dp\" or \"Dp\" to the ordering 246 \"(a(w),lp\" or \"a(1,0,...,0),lp\" by using modular methods. 247 By default the procedure computes a standard basis of I for sure, but 248 if the optional parameter #[2] = 0, it computes a standard basis of I 249 with high probability. 250 EXAMPLE: example modWalk; shows an example 251 " 252 { 253 int TT = timer; 254 int RT = rtimer; 255 int i,j,pTest,sizeTest,weighted,n1; 256 bigint N; 257 258 def R0 = basering; 259 list rl = ringlist(R0); 260 if((npars(R0) > 0) || (rl[1] > 0)) 261 { 262 ERROR("Characteristic of basering should be zero, basering should have no parameters."); 263 } 264 265 if(typeof(II) == "ideal") 266 { 267 ideal I = II; 268 kill II; 269 list II; 270 II[1] = I; 271 II[2] = 2; 272 II[3] = 2; 273 } 274 else 275 { 276 if(typeof(II) == "list" && typeof(II[1]) == "ideal") 277 { 278 ideal I = II[1]; 279 if(size(II) == 1) 280 { 281 II[2] = 2; 282 II[3] = 2; 283 } 284 if(size(II) == 2) 285 { 286 II[3] = 2; 287 } 288 289 } 290 else 291 { 292 ERROR("Unexpected type of input."); 293 } 294 } 295 296 //-------------------- Initialize optional parameters ------------------------ 297 n1 = system("--cpus"); 298 if(size(#) == 0) 299 { 300 int exactness = 1; 301 int n2 = 10; 302 int n3 = 10; 303 } 304 else 305 { 306 if(size(#) == 1) 307 { 308 if(typeof(#[1]) == "int") 309 { 310 if(#[1] < n1) 311 { 312 n1 = #[1]; 313 } 314 int exactness = 1; 315 if(n1 >= 10) 316 { 317 int n2 = n1 + 1; 318 int n3 = n1; 319 } 320 else 321 { 322 int n2 = 10; 323 int n3 = 10; 324 } 325 } 326 else 327 { 328 ERROR("Unexpected type of input."); 329 } 330 } 331 if(size(#) == 2) 332 { 333 if(typeof(#[1]) == "int" && typeof(#[2]) == "int") 334 { 335 if(#[1] < n1) 336 { 337 n1 = #[1]; 338 } 339 int exactness = #[2]; 340 if(n1 >= 10) 341 { 342 int n2 = n1 + 1; 343 int n3 = n1; 344 } 345 else 346 { 347 int n2 = 10; 348 int n3 = 10; 349 } 350 } 351 else 352 { 353 if(typeof(#[1]) == "intvec" && typeof(#[2]) == "intvec") 354 { 355 intvec curr_weight = #[1]; 356 intvec target_weight = #[2]; 357 weighted = 1; 358 int n2 = 10; 359 int n3 = 10; 360 int exactness = 1; 361 } 362 else 363 { 364 ERROR("Unexpected type of input."); 365 } 366 } 367 } 368 if(size(#) == 3) 369 { 370 if(typeof(#[1]) == "intvec" && typeof(#[2]) == "intvec" && typeof(#[3]) == "int") 371 { 372 intvec curr_weight = #[1]; 373 intvec target_weight = #[2]; 374 weighted = 1; 375 n1 = #[3]; 376 int n2 = 10; 377 int n3 = 10; 378 int exactness = 1; 379 } 380 else 381 { 382 ERROR("Unexpected type of input."); 383 } 384 } 385 if(size(#) == 4) 386 { 387 if(typeof(#[1]) == "intvec" && typeof(#[2]) == "intvec" && typeof(#[3]) == "int" 388 && typeof(#[4]) == "int") 389 { 390 intvec curr_weight = #[1]; 391 intvec target_weight = #[2]; 392 weighted = 1; 393 if(#[1] < n1) 394 { 395 n1 = #[3]; 396 } 397 int exactness = #[4]; 398 if(n1 >= 10) 399 { 400 int n2 = n1 + 1; 401 int n3 = n1; 402 } 403 else 404 { 405 int n2 = 10; 406 int n3 = 10; 407 } 408 } 409 else 410 { 411 if(typeof(#[1]) == "int" && typeof(#[2]) == "int" && typeof(#[3]) == "int" && typeof(#[4]) == "int") 412 { 413 if(#[1] < n1) 414 { 415 n1 = #[1]; 416 } 417 int exactness = #[2]; 418 if(n1 >= #[3]) 419 { 420 int n2 = n1 + 1; 421 } 422 else 423 { 424 int n2 = #[3]; 425 } 426 if(n1 >= #[4]) 427 { 428 int n3 = n1; 429 } 430 else 431 { 432 int n3 = #[4]; 433 } 434 } 435 else 436 { 437 ERROR("Unexpected type of input."); 438 } 439 } 440 } 441 if(size(#) == 6) 442 { 443 if(typeof(#[1]) == "intvec" && typeof(#[2]) == "intvec" && typeof(#[3]) == "int" && typeof(#[4]) == "int" && typeof(#[5]) == "int" && typeof(#[6]) == "int") 444 { 445 intvec curr_weight = #[1]; 446 intvec target_weight = #[2]; 447 weighted = 1; 448 if(#[3] < n1) 449 { 450 n1 = #[3]; 451 } 452 int exactness = #[4]; 453 if(n1 >= #[5]) 454 { 455 int n2 = n1 + 1; 456 } 457 else 458 { 459 int n2 = #[5]; 460 } 461 if(n1 >= #[6]) 462 { 463 int n3 = n1; 464 } 465 else 466 { 467 int n3 = #[6]; 468 } 469 } 470 else 471 { 472 ERROR("Expected list(intvec,intvec,int,int,int,int) as optional parameter list."); 473 } 474 } 475 if(size(#) == 1 || size(#) == 5 || size(#) > 6) 476 { 477 ERROR("Expected 0,2,3,4 or 5 optional arguments."); 478 } 479 } 480 if(printlevel >= 10) 481 { 482 "n1 = "+string(n1)+", n2 = "+string(n2)+", n3 = "+string(n3)+", exactness = "+string(exactness); 483 } 484 485 //------------------------- Save current options ----------------------------- 486 intvec opt = option(get); 487 //option(redSB); 488 489 //-------------------- Initialize the list of primes ------------------------- 490 int tt = timer; 491 int rt = rtimer; 492 int en = 2134567879; 493 int an = 1000000000; 494 intvec L = primeList(I,n2); 495 if(n2 > 4) 496 { 497 L[5] = prime(random(an,en)); 498 } 499 if(printlevel >= 10) 500 { 501 "CPU-time for primeList: "+string(timer-tt)+" seconds."; 502 "Real-time for primeList: "+string(rtimer-rt)+" seconds."; 503 } 504 int h = homog(I); 505 list P,T1,T2,LL,Arguments,PP; 506 ideal J,K,H; 507 508 //------------------- parallelized Groebner Walk in positive characteristic -------------------- 509 510 if(weighted) 511 { 512 for(i=1; i<=size(L); i++) 513 { 514 Arguments[i] = list(II,L[i],variant,reduction,list(curr_weight,target_weight)); 515 } 516 } 517 else 518 { 519 for(i=1; i<=size(L); i++) 520 { 521 Arguments[i] = list(II,L[i],variant,reduction); 522 } 523 } 524 P = parallelWaitAll("modpWalk",Arguments); 525 for(i=1; i<=size(P); i++) 526 { 527 T1[i] = P[i][1]; 528 T2[i] = bigint(P[i][2]); 529 } 530 531 while(1) 532 { 533 LL = deleteUnluckyPrimes(T1,T2,h); 534 T1 = LL[1]; 535 T2 = LL[2]; 536 //------------------- Now all leading ideals are the same -------------------- 537 //------------------- Lift results to basering via farey --------------------- 538 tt = timer; rt = rtimer; 539 N = T2[1]; 540 for(i=2; i<=size(T2); i++) 541 { 542 N = N*T2[i]; 543 } 544 H = chinrem(T1,T2); 545 J = parallelFarey(H,N,n1); 546 //J=farey(H,N); 547 if(printlevel >= 10) 548 { 549 "CPU-time for lifting-process is "+string(timer - tt)+" seconds."; 550 "Real-time for lifting-process is "+string(rtimer - rt)+" seconds."; 551 } 552 553 //---------------- Test if we already have a standard basis of I -------------- 554 tt = timer; rt = rtimer; 555 pTest = primeTest(J, prime(random(1000000000,2134567879))); 556 if(printlevel >= 10) 557 { 558 "CPU-time for pTest is "+string(timer - tt)+" seconds."; 559 "Real-time for pTest is "+string(rtimer - rt)+" seconds."; 560 } 561 if(pTest) 562 { 563 if(printlevel >= 10) 564 { 565 "CPU-time for computation without final tests is "+string(timer - TT)+" seconds."; 566 "Real-time for computation without final tests is "+string(rtimer - RT)+" seconds."; 567 } 568 attrib(J,"isSB",1); 569 if(exactness == 0) 570 { 571 option(set, opt); 572 return(J); 573 } 574 else 575 { 576 tt = timer; 577 rt = rtimer; 578 sizeTest = 1 - isIdealIncluded(I,J,n1); 579 if(printlevel >= 10) 580 { 581 "CPU-time for checking if I subset <G> is "+string(timer - tt)+" seconds."; 582 "Real-time for checking if I subset <G> is "+string(rtimer - rt)+" seconds."; 583 } 584 if(sizeTest == 0) 585 { 586 tt = timer; 587 rt = rtimer; 588 K = std(J); 589 if(printlevel >= 10) 590 { 591 "CPU-time for last std-computation is "+string(timer - tt)+" seconds."; 592 "Real-time for last std-computation is "+string(rtimer - rt)+" seconds."; 593 } 594 if(size(reduce(K,J)) == 0) 595 { 596 option(set, opt); 597 return(J); 598 } 599 } 600 } 601 } 602 //-------------- We do not already have a standard basis of I, therefore do the main computation for more primes -------------- 603 T1 = H; 604 T2 = N; 605 j = size(L)+1; 606 tt = timer; rt = rtimer; 607 L = primeList(I,n3,L,n1); 608 if(printlevel >= 10) 609 { 610 "CPU-time for primeList: "+string(timer-tt)+" seconds."; 611 "Real-time for primeList: "+string(rtimer-rt)+" seconds."; 612 } 613 Arguments = list(); 614 PP = list(); 615 if(weighted) 616 { 617 for(i=j; i<=size(L); i++) 618 { 619 Arguments[size(Arguments)+1] = list(II,L[i],variant,reduction,list(curr_weight,target_weight)); 620 } 621 } 622 else 623 { 624 for(i=j; i<=size(L); i++) 625 { 626 Arguments[size(Arguments)+1] = list(II,L[i],variant,reduction); 627 } 628 } 629 PP = parallelWaitAll("modpWalk",Arguments); 630 if(printlevel >= 10) 631 { 632 "parallel modpWalk"; 633 } 634 for(i=1; i<=size(PP); i++) 635 { 636 T1[size(T1) + 1] = PP[i][1]; 637 T2[size(T2) + 1] = bigint(PP[i][2]); 638 } 639 } 640 if(printlevel >= 10) 641 { 642 "CPU-time for computation with final tests is "+string(timer - TT)+" seconds."; 643 "Real-time for computation with final tests is "+string(rtimer - RT)+" seconds."; 644 } 645 } 646 647 example 648 { 649 "EXAMPLE:"; 650 echo = 2; 651 ring R=0,(x,y,z),lp; 652 ideal I= y3+xyz+y2z+xz3, 3+xy+x2y+y2z; 653 int reduction = 0; 654 ideal J = modWalk(I,1,1); 655 J; 656 } 657 658 //////////////////////////////////////////////////////////////////////////////// 659 static proc isIdealIncluded(ideal I, ideal J, int n1) 660 "USAGE: isIdealIncluded(I,J,int n1); I ideal, J ideal, n1 integer 661 " 662 { 663 if(n1 > 1) 664 { 665 int k; 666 list args,results; 667 for(k=1; k<=size(I); k++) 668 { 669 args[k] = list(ideal(I[k]),J,1); 670 } 671 results = parallelWaitAll("reduce",args); 672 for(k=1; k<=size(results); k++) 673 { 674 if(results[k] == 0) 675 { 676 return(1); 677 } 678 } 679 return(0); 680 } 681 else 682 { 683 if(reduce(I,J,1) == 0) 684 { 685 return(1); 686 } 687 else 688 { 689 return(0); 690 } 691 } 692 } 693 694 //////////////////////////////////////////////////////////////////////////////// 695 static proc parallelChinrem(list T1, list T2, int n1) 696 "USAGE: parallelChinrem(T1,T2); T1 list of ideals, T2 list of primes, n1 integer" 697 { 698 int i,j,k; 699 700 ideal H,J; 701 702 list arguments_chinrem,results_chinrem; 703 for(i=1; i<=size(T1); i++) 704 { 705 J = ideal(T1[i]); 706 attrib(J,"isSB",1); 707 arguments_chinrem[size(arguments_chinrem)+1] = list(list(J),T2); 708 } 709 results_chinrem = parallelWaitAll("chinrem",arguments_chinrem); 710 for(j=1; j <= size(results_chinrem); j++) 711 { 712 J = results_chinrem[j]; 713 attrib(J,"isSB",1); 714 if(isIdealIncluded(J,H,n1) == 0) 715 { 716 if(H == 0) 717 { 718 H = J; 719 } 720 else 721 { 722 H = H,J; 723 } 724 } 725 } 726 return(H); 727 } 728 729 //////////////////////////////////////////////////////////////////////////////// 730 static proc parallelFarey(ideal H, bigint N, int n1) 731 "USAGE: parallelFarey(H,N,n1); H ideal, N bigint, n1 integer 732 " 733 { 734 int i,j; 735 int ii = 1; 736 list arguments_farey,results_farey; 737 for(i=1; i<=size(H); i++) 738 { 739 for(j=1; j<=size(H[i]); j++) 740 { 741 arguments_farey[size(arguments_farey)+1] = list(H[i][j],N); 742 } 743 } 744 results_farey = parallelWaitAll("farey",arguments_farey); 745 ideal J,K; 746 poly f_farey; 747 while(ii<=size(results_farey)) 748 { 749 for(i=1; i<=size(H); i++) 750 { 751 f_farey = 0; 752 for(j=1; j<=size(H[i]); j++) 753 { 754 f_farey = f_farey + results_farey[ii][1]; 755 ii++; 756 } 757 K = ideal(f_farey); 758 attrib(K,"isSB",1); 759 attrib(J,"isSB",1); 760 if(isIdealIncluded(K,J,n1) == 0) 761 { 762 if(J == 0) 763 { 764 J = K; 765 } 766 else 767 { 768 J = J,K; 769 } 770 } 771 } 772 } 773 return(J); 774 } 775 776 //////////////////////////////////////////////////////////////////////////////// 777 static proc mixedTest() 778 "USAGE: mixedTest(); 779 RETURN: 1 if ordering of basering is mixed, 0 else 780 EXAMPLE: example mixedTest(); shows an example 781 " 782 { 783 int i,p,m; 784 for(i = 1; i <= nvars(basering); i++) 785 { 786 if(var(i) > 1) 787 { 788 p++; 789 } 790 else 791 { 792 m++; 793 } 794 } 795 if((p > 0) && (m > 0)) { return(1); } 796 return(0); 797 } 798 example 799 { "EXAMPLE:"; echo = 2; 800 ring R1 = 0,(x,y,z),dp; 801 mixedTest(); 802 ring R2 = 31,(x(1..4),y(1..3)),(ds(4),lp(3)); 803 mixedTest(); 804 ring R3 = 181,x(1..9),(dp(5),lp(4)); 805 mixedTest(); 806 } 139 int pertdeg = 3; 140 ideal J = modrWalk(I,radius,pertdeg); 141 J; 142 } 143 144 proc modfWalk(ideal I, list #) 145 "USAGE: modfWalk(I, [, v, w]); I ideal, v intvec, w intvec 146 RETURN: a standard basis of I 147 NOTE: The procedure computes a standard basis of I (over the rational 148 numbers) by using modular methods. 149 SEE ALSO: modular 150 EXAMPLE: example modfWalk; shows an example" 151 { 152 /* read optional parameter */ 153 if (size(#) > 0) { 154 if (size(#) == 1) { 155 intvec w = #[1]; 156 } 157 if (size(#) == 2) { 158 intvec v = #[1]; 159 intvec w = #[2]; 160 } 161 if (size(#) > 2 || typeof(#[1]) != "intvec") { 162 ERROR("wrong optional parameter"); 163 } 164 } 165 166 /* save options */ 167 intvec opt = option(get); 168 option(redSB); 169 170 /* set additional parameters */ 171 int reduction = 1; 172 int printout = 0; 173 174 /* call modular() */ 175 if (size(#) > 0) { 176 I = modular("fwalk", list(I,reduction,printout,#)); 177 } 178 else { 179 I = modular("fwalk", list(I,reduction,printout)); 180 } 181 182 /* return the result */ 183 attrib(I, "isSB", 1); 184 option(set, opt); 185 return(I); 186 } 187 example 188 { 189 "EXAMPLE:"; 190 echo = 2; 191 ring R1 = 0, (x,y,z,t), dp; 192 ideal I = 3x3+x2+1, 11y5+y3+2, 5z4+z2+4; 193 I = std(I); 194 ring R2 = 0, (x,y,z,t), lp; 195 ideal I = fetch(R1, I); 196 ideal J = modfWalk(I); 197 J; 198 } 199 200 proc modfrWalk(ideal I, int radius, list #) 201 "USAGE: modfrWalk(I, radius [, v, w]); I ideal, radius int, v intvec, w intvec 202 RETURN: a standard basis of I 203 NOTE: The procedure computes a standard basis of I (over the rational 204 numbers) by using modular methods. 205 SEE ALSO: modular 206 EXAMPLE: example modfrWalk; shows an example" 207 { 208 /* read optional parameter */ 209 if (size(#) > 0) { 210 if (size(#) == 1) { 211 intvec w = #[1]; 212 } 213 if (size(#) == 2) { 214 intvec v = #[1]; 215 intvec w = #[2]; 216 } 217 if (size(#) > 2 || typeof(#[1]) != "intvec") { 218 ERROR("wrong optional parameter"); 219 } 220 } 221 222 /* save options */ 223 intvec opt = option(get); 224 option(redSB); 225 226 /* set additional parameters */ 227 int reduction = 1; 228 int printout = 0; 229 230 /* call modular() */ 231 if (size(#) > 0) { 232 I = modular("frandwalk", list(I,radius,reduction,printout,#)); 233 } 234 else { 235 I = modular("frandwalk", list(I,radius,reduction,printout)); 236 } 237 238 /* return the result */ 239 attrib(I, "isSB", 1); 240 option(set, opt); 241 return(I); 242 } 243 example 244 { 245 "EXAMPLE:"; 246 echo = 2; 247 ring R1 = 0, (x,y,z,t), dp; 248 ideal I = 3x3+x2+1, 11y5+y3+2, 5z4+z2+4; 249 I = std(I); 250 ring R2 = 0, (x,y,z,t), lp; 251 ideal I = fetch(R1, I); 252 int radius = 2; 253 ideal J = modfrWalk(I,radius); 254 J; 255 } -
Singular/walk.cc
reca8d9 ra14482 1106 1106 if(pdeg > nV || pdeg <= 0) 1107 1107 { 1108 WerrorS("//** The perturbed degree is wrong!!");1108 WerrorS("//**MPertVectors: The perturbed degree is wrong!!"); 1109 1109 return v_null; 1110 1110 } … … 1116 1116 } 1117 1117 mpz_t *pert_vector = (mpz_t*)omAlloc(nV*sizeof(mpz_t)); 1118 //mpz_t *pert_vector1 = (mpz_t*)omAlloc(nV*sizeof(mpz_t));1119 1118 1120 1119 for(i=0; i<nV; i++) … … 1123 1122 // mpz_init_set_si(pert_vector1[i], (*ivtarget)[i]); 1124 1123 } 1125 // C alculate max1 = Max(A2)+Max(A3)+...+Max(Apdeg),1124 // Compute max1 = Max(A2)+Max(A3)+...+Max(Apdeg), 1126 1125 // where the Ai are the i-te rows of the matrix target_ord. 1127 1126 int ntemp, maxAi, maxA=0; … … 1148 1147 } 1149 1148 1150 // C alculate inveps = 1/eps, where 1/eps > totaldeg(p)*max1 for all p in G.1149 // Compute inveps = 1/eps, where 1/eps > totaldeg(p)*max1 for all p in G. 1151 1150 1152 1151 intvec* ivUnit = Mivdp(nV); … … 1180 1179 } 1181 1180 #else 1182 // PrintS("\n// the \"big\" inverse epsilon:");1181 PrintS("\n //**MPertVectors: the \"big\" inverse epsilon:"); 1183 1182 mpz_out_str(stdout, 10, inveps); 1184 1183 #endif … … 1234 1233 if(j > nV - 1) 1235 1234 { 1236 // Print("\n// MPertVectors: geaenderter vector gleich Null! \n");1235 //perturbed vector equals zero 1237 1236 delete pert_vector1; 1238 1237 goto CHECK_OVERFLOW; 1239 1238 } 1240 1239 1241 // check that the perturbed weight vector lies in the Groebner cone1240 // check that the perturbed weight vector lies in the Groebner cone 1242 1241 if(test_w_in_ConeCC(G,pert_vector1) != 0) 1243 1242 { 1244 // Print("\n// MPertVectors: geaenderter vector liegt in Groebnerkegel! \n");1245 1243 for(i=0; i<nV; i++) 1246 1244 { … … 1248 1246 } 1249 1247 } 1250 else 1251 { 1252 //Print("\n// MpertVectors: geaenderter vector liegt nicht in Groebnerkegel! \n"); 1253 } 1248 1254 1249 delete pert_vector1; 1255 1250 … … 1257 1252 intvec* result = new intvec(nV); 1258 1253 1259 / * 2147483647 is max. integer representation in SINGULAR */1254 // 2147483647 is max. integer representation in SINGULAR 1260 1255 mpz_t sing_int; 1261 1256 mpz_init_set_ui(sing_int, 2147483647); … … 1644 1639 { 1645 1640 mpz_divexact(pert_vector[i], pert_vector[i], ztmp); 1646 (* result)[i] = mpz_get_si(pert_vector[i]); 1647 } 1648 1641 (* result1)[i] = mpz_get_si(pert_vector[i]); 1642 } 1649 1643 j = 0; 1650 for(i=0; i<nV; i++) 1651 { 1652 (* result1)[i] = mpz_get_si(pert_vector[i]); 1653 (* result1)[i] = 0.1*(* result1)[i]; 1654 (* result1)[i] = floor((* result1)[i] + 0.5); 1655 if((* result1)[i] == 0) 1656 { 1657 j++; 1658 } 1659 } 1660 if(j > nV - 1) 1661 { 1662 // Print("\n// MfPertwalk: geaenderter vector gleich Null! \n"); 1663 delete result1; 1664 goto CHECK_OVERFLOW; 1665 } 1666 1667 // check that the perturbed weight vector lies in the Groebner cone 1668 if(test_w_in_ConeCC(G,result1) != 0) 1669 { 1670 // Print("\n// MfPertwalk: geaenderter vector liegt in Groebnerkegel! \n"); 1671 delete result; 1672 result = result1; 1644 while(test_w_in_ConeCC(G,result1) && j<nV) 1645 { 1646 j = 0; 1673 1647 for(i=0; i<nV; i++) 1674 1648 { 1649 (* result)[i] = (* result1)[i]; 1675 1650 mpz_set_si(pert_vector[i], (*result1)[i]); 1676 } 1677 } 1678 else 1679 { 1680 delete result1; 1681 // Print("\n// Mfpertwalk: geaenderter vector liegt nicht in Groebnerkegel! \n"); 1682 } 1651 (* result1)[i] = floor(0.1*(mpz_get_si(pert_vector[i])) + 0.5); 1652 if((* result1)[i] == 0) 1653 { 1654 j++; 1655 } 1656 } 1657 } 1658 delete result1; 1683 1659 1684 1660 CHECK_OVERFLOW: … … 4343 4319 assume(currRing != NULL && curr_weight != NULL && 4344 4320 target_weight != NULL && G->m[0] != NULL); 4345 4346 int i,weight_norm,nV = currRing->N; 4321 //PrintS("\n //**MWalkRandomNextWeight: Anfang ok!\n"); 4322 int i,k,nV = currRing->N; 4323 long weight_norm; 4347 4324 intvec* next_weight2; 4348 intvec* next_weight22 = new intvec(nV);4325 //intvec* next_weight22 = new intvec(nV); 4349 4326 intvec* result = new intvec(nV); 4327 ideal G_test; 4328 ideal G_test2; 4329 BOOLEAN random = FALSE; 4350 4330 4351 4331 intvec* next_weight1 =MkInterRedNextWeight(curr_weight,target_weight,G); 4352 4332 //compute a random next weight vector "next_weight2" 4353 while(1) 4354 { 4333 k = 1; 4334 while(k<4) 4335 { 4336 k++; 4355 4337 weight_norm = 0; 4338 intvec* next_weight22 = new intvec(nV); 4356 4339 while(weight_norm == 0) 4357 4340 { 4358 4341 //PrintS("\nWhile WeightNorm\n"); 4359 4342 for(i=0; i<nV; i++) 4360 4343 { 4361 (*next_weight22)[i] = rand() % 60000 - 30000;4344 (*next_weight22)[i] = rand() % 60000 ; 4362 4345 weight_norm = weight_norm + (*next_weight22)[i]*(*next_weight22)[i]; 4363 4346 } 4347 //Print("\n// weight_norm vor Wurzel = %d\n", weight_norm); 4364 4348 weight_norm = 1 + floor(sqrt(weight_norm)); 4365 } 4366 4349 4350 } 4351 //Print("\n// weight_norm nach Wurzel = %d\n", weight_norm); 4367 4352 for(i=0; i<nV; i++) 4368 4353 { 4369 4354 if((*next_weight22)[i] < 0) 4370 4355 { 4371 (*next_weight22)[i] = 1 + (*curr_weight)[i] + floor( weight_rad*(*next_weight22)[i]/weight_norm);4356 (*next_weight22)[i] = 1 + (*curr_weight)[i] + floor((weight_rad)*(*next_weight22)[i]/weight_norm); 4372 4357 } 4373 4358 else 4374 4359 { 4375 (*next_weight22)[i] = (*curr_weight)[i] + floor( weight_rad*(*next_weight22)[i]/weight_norm);4360 (*next_weight22)[i] = (*curr_weight)[i] + floor((weight_rad)*(*next_weight22)[i]/weight_norm); 4376 4361 } 4377 4362 } … … 4379 4364 if(test_w_in_ConeCC(G, next_weight22) == 1) 4380 4365 { 4366 //PrintS("\n //** MWalkRandomNextWeight: test ob in Kegel.\n"); 4381 4367 next_weight2 = MkInterRedNextWeight(next_weight22,target_weight,G); 4382 4368 if(MivAbsMax(next_weight2)>1147483647) … … 4395 4381 } 4396 4382 } 4397 delete next_weight22;4383 random = TRUE; 4398 4384 break; 4399 4385 } 4400 } 4401 4386 delete next_weight22; 4387 } 4388 //PrintS("\n //**MWalkRandomNextWeight: Ende while-Schleife!\n"); 4389 4402 4390 // compute "usual" next weight vector 4403 4391 intvec* next_weight = MwalkNextWeightCC(curr_weight,target_weight, G); 4404 ideal G_test = MwalkInitialForm(G, next_weight); 4405 ideal G_test2 = MwalkInitialForm(G, next_weight2); 4406 4392 G_test = MwalkInitialForm(G, next_weight); 4393 if(random == TRUE) 4394 { 4395 G_test2 = MwalkInitialForm(G, next_weight2); 4396 } 4407 4397 // compare next weights 4408 4398 if(Overflow_Error == FALSE) 4409 4399 { 4410 4400 ideal G_test1 = MwalkInitialForm(G, next_weight1); 4411 if(G_test1->m[0] != NULL && maxlengthpoly(G_test1) < maxlengthpoly(G_test))//if(IDELEMS(G_test1) < IDELEMS(G_test)) 4412 { 4413 if(G_test2->m[0] != NULL && maxlengthpoly(G_test2) < maxlengthpoly(G_test1)) //if(IDELEMS(G_test2) < IDELEMS(G_test1)) 4414 { 4415 // |G_test2| < |G_test1| < |G_test| 4401 if(G_test1->m[0] != NULL && maxlengthpoly(G_test1) < maxlengthpoly(G_test)) 4402 { 4403 if(random == TRUE && 4404 G_test2->m[0] != NULL && 4405 maxlengthpoly(G_test2) < maxlengthpoly(G_test1)) 4406 { 4416 4407 for(i=0; i<nV; i++) 4417 4408 { … … 4421 4412 else 4422 4413 { 4423 // |G_test1| < |G_test|, |G_test1| <= |G_test2|4424 4414 for(i=0; i<nV; i++) 4425 4415 { … … 4430 4420 else 4431 4421 { 4432 if(G_test2->m[0] != NULL && maxlengthpoly(G_test2) < maxlengthpoly(G_test))//if(IDELEMS(G_test2) < IDELEMS(G_test)) // |G_test2| < |G_test| <= |G_test1| 4422 if(random == TRUE && 4423 G_test2->m[0] != NULL && 4424 maxlengthpoly(G_test2) < maxlengthpoly(G_test)) 4433 4425 { 4434 4426 for(i=0; i<nV; i++) … … 4439 4431 else 4440 4432 { 4441 // |G_test| < |G_test1|, |G_test| <= |G_test2|4442 4433 for(i=0; i<nV; i++) 4443 4434 { … … 4451 4442 { 4452 4443 Overflow_Error = FALSE; 4453 if(G_test2->m[0] != NULL && maxlengthpoly(G_test2) < maxlengthpoly(G_test))//if(IDELEMS(G_test2) < IDELEMS(G_test)) 4444 if(random == TRUE && 4445 G_test2->m[0] != NULL && 4446 maxlengthpoly(G_test2) < maxlengthpoly(G_test)) 4454 4447 { 4455 4448 for(i=1; i<nV; i++) … … 4466 4459 } 4467 4460 } 4468 PrintS("\n MWalkRandomNextWeight: Ende ok!\n");4461 //PrintS("\n MWalkRandomNextWeight: Ende ok!\n"); 4469 4462 idDelete(&G_test); 4470 idDelete(&G_test2); 4463 if(random == TRUE) 4464 { 4465 idDelete(&G_test2); 4466 } 4471 4467 if(test_w_in_ConeCC(G, result) == 1) 4472 4468 { 4473 delete next_weight2; 4469 if(random == TRUE) 4470 { 4471 delete next_weight2; 4472 } 4474 4473 delete next_weight; 4475 4474 delete next_weight1; … … 4479 4478 { 4480 4479 delete result; 4481 delete next_weight2; 4480 if(random == TRUE) 4481 { 4482 delete next_weight2; 4483 } 4482 4484 delete next_weight1; 4483 4485 return next_weight; … … 6029 6031 to=clock(); 6030 6032 // compute a next weight vector 6031 next_weight = M kInterRedNextWeight(curr_weight,target_weight, G);6033 next_weight = MwalkNextWeightCC(curr_weight,target_weight,G);//MkInterRedNextWeight(curr_weight,target_weight, G); 6032 6034 tnw=tnw+clock()-to; 6033 6035 //#ifdef PRINT_VECTORS … … 7095 7097 delete next_vect; 7096 7098 next_vect = MWalkRandomNextWeight(G,omega,omega2,weight_rad,nlev); 7097 if(isNegNolVector(next_vect)==1 )7099 if(isNegNolVector(next_vect)==1 || MivSame(omega,next_vect) == 1) 7098 7100 { 7099 7101 delete next_vect; … … 7180 7182 delete next_vect; 7181 7183 next_vect = MWalkRandomNextWeight(G,omega,omega2,weight_rad,nlev); 7182 if(isNegNolVector(next_vect)==1 )7184 if(isNegNolVector(next_vect)==1 || MivSame(omega,next_vect) == 1) 7183 7185 { 7184 7186 delete next_vect; … … 7239 7241 Print("\n//** rec_r_fractal_call: Leaving the %d-th recursion with %d steps.\n", 7240 7242 nlev, nwalks); 7241 //Print(" ** Overflow_Error? (%d)", Overflow_Error); 7243 /* 7244 Print(" ** Overflow_Error? (%d)", Overflow_Error); 7245 idString(G1,"//** rec_r_fractal_call: G1"); 7246 */ 7242 7247 } 7243 7248 nnflow ++; … … 7279 7284 Print("\n//** rec_r_fractal_call: Leaving the %d-th recursion with %d steps.\n", 7280 7285 nlev, nwalks); 7281 //Print(" ** Overflow_Error? (%d)", Overflow_Error); 7286 /* 7287 Print(" ** Overflow_Error? (%d)", Overflow_Error); 7288 idString(Gt,"//** rec_r_fractal_call: Gt"); 7289 */ 7282 7290 } 7283 7291 return (Gt); … … 7382 7390 Print("\n//** rec_r_fractal_call: Leaving the %d-th recursion with %d steps.\n", 7383 7391 nlev,nwalks); 7384 //Print(" ** Overflow_Error? (%d)", Overflow_Error); 7392 /* 7393 Print(" ** Overflow_Error? (%d)", Overflow_Error); 7394 idString(G,"//** rec_r_fractal_call: G"); 7395 */ 7385 7396 } 7386 7397 if(Overflow_Error == TRUE)
Note: See TracChangeset
for help on using the changeset viewer.