[35aab3] | 1 | /**************************************** |
---|
| 2 | * Computer Algebra System SINGULAR * |
---|
| 3 | ****************************************/ |
---|
[36b9ef] | 4 | /* $Id: gr_kstd2.cc,v 1.23 2008-07-29 13:16:44 Singular Exp $ */ |
---|
[35aab3] | 5 | /* |
---|
| 6 | * ABSTRACT - Kernel: noncomm. alg. of Buchberger |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | #include "mod2.h" |
---|
[5a9e7b] | 10 | |
---|
[f2f460] | 11 | #ifdef HAVE_PLURAL |
---|
[5a9e7b] | 12 | |
---|
[86016d] | 13 | #define PLURAL_INTERNAL_DECLARATIONS |
---|
[5a9e7b] | 14 | |
---|
[35aab3] | 15 | #include "omalloc.h" |
---|
| 16 | #include "polys.h" |
---|
| 17 | #include "ideals.h" |
---|
| 18 | #include "febase.h" |
---|
| 19 | #include "kutil.h" |
---|
| 20 | #include "kstd1.h" |
---|
| 21 | #include "khstd.h" |
---|
[07b1cf] | 22 | #include "kutil.h" |
---|
[35aab3] | 23 | //#include "spolys.h" |
---|
[f599636] | 24 | //#include "cntrlc.h" |
---|
[35aab3] | 25 | #include "weight.h" |
---|
| 26 | #include "intvec.h" |
---|
[4bbe3b] | 27 | #include "structs.h" |
---|
[35aab3] | 28 | #include "gring.h" |
---|
[5a9e7b] | 29 | #include "sca.h" |
---|
[342c80] | 30 | #include "ratgring.h" |
---|
[35aab3] | 31 | |
---|
[5a9e7b] | 32 | #if 0 |
---|
| 33 | /*3 |
---|
| 34 | * reduction of p2 with p1 |
---|
| 35 | * do not destroy p1 and p2 |
---|
| 36 | * p1 divides p2 -> for use in NF algorithm |
---|
[35aab3] | 37 | */ |
---|
[5a9e7b] | 38 | poly gnc_ReduceSpolyNew(const poly p1, poly p2/*,poly spNoether*/, const ring r) |
---|
[35aab3] | 39 | { |
---|
[5a9e7b] | 40 | return(nc_ReduceSPoly(p1,p_Copy(p2,r)/*,spNoether*/,r)); |
---|
[35aab3] | 41 | } |
---|
[5a9e7b] | 42 | #endif |
---|
[35aab3] | 43 | |
---|
| 44 | /*2 |
---|
| 45 | *reduces h with elements from T choosing the first possible |
---|
| 46 | * element in t with respect to the given pDivisibleBy |
---|
| 47 | */ |
---|
| 48 | int redGrFirst (LObject* h,kStrategy strat) |
---|
| 49 | { |
---|
| 50 | int at,reddeg,d,i; |
---|
| 51 | int pass = 0; |
---|
| 52 | int j = 0; |
---|
| 53 | |
---|
[b130fb] | 54 | d = pFDeg((*h).p,currRing)+(*h).ecart; |
---|
[35aab3] | 55 | reddeg = strat->LazyDegree+d; |
---|
| 56 | loop |
---|
| 57 | { |
---|
| 58 | if (j > strat->sl) |
---|
| 59 | { |
---|
[d42b51] | 60 | #ifdef KDEBUG |
---|
[35aab3] | 61 | if (TEST_OPT_DEBUG) PrintLn(); |
---|
[d42b51] | 62 | #endif |
---|
[35aab3] | 63 | return 0; |
---|
| 64 | } |
---|
[d42b51] | 65 | #ifdef KDEBUG |
---|
[35aab3] | 66 | if (TEST_OPT_DEBUG) Print("%d",j); |
---|
[d42b51] | 67 | #endif |
---|
[35aab3] | 68 | if (pDivisibleBy(strat->S[j],(*h).p)) |
---|
| 69 | { |
---|
[d42b51] | 70 | #ifdef KDEBUG |
---|
[35aab3] | 71 | if (TEST_OPT_DEBUG) PrintS("+\n"); |
---|
[d42b51] | 72 | #endif |
---|
[35aab3] | 73 | /* |
---|
| 74 | * the polynomial to reduce with is; |
---|
| 75 | * T[j].p |
---|
| 76 | */ |
---|
| 77 | if (!TEST_OPT_INTSTRATEGY) |
---|
| 78 | pNorm(strat->S[j]); |
---|
[d42b51] | 79 | #ifdef KDEBUG |
---|
[35aab3] | 80 | if (TEST_OPT_DEBUG) |
---|
| 81 | { |
---|
| 82 | wrp(h->p); |
---|
| 83 | PrintS(" with "); |
---|
| 84 | wrp(strat->S[j]); |
---|
| 85 | } |
---|
[d42b51] | 86 | #endif |
---|
[19370c] | 87 | (*h).p = nc_ReduceSpoly(strat->S[j],(*h).p, currRing); |
---|
[35aab3] | 88 | //spSpolyRed(strat->T[j].p,(*h).p,strat->kNoether); |
---|
| 89 | |
---|
[d42b51] | 90 | #ifdef KDEBUG |
---|
[35aab3] | 91 | if (TEST_OPT_DEBUG) |
---|
| 92 | { |
---|
| 93 | PrintS(" to "); |
---|
| 94 | wrp(h->p); |
---|
| 95 | } |
---|
[d42b51] | 96 | #endif |
---|
[35aab3] | 97 | if ((*h).p == NULL) |
---|
| 98 | { |
---|
| 99 | if (h->lcm!=NULL) p_LmFree((*h).lcm, currRing); |
---|
| 100 | return 0; |
---|
| 101 | } |
---|
| 102 | if (TEST_OPT_INTSTRATEGY) |
---|
| 103 | { |
---|
[e36a2c0] | 104 | if (rField_is_Zp_a()) pContent(h->p); |
---|
| 105 | else pCleardenom(h->p);// also does a pContent |
---|
[35aab3] | 106 | } |
---|
| 107 | /*computes the ecart*/ |
---|
[b130fb] | 108 | d = pLDeg((*h).p,&((*h).length),currRing); |
---|
| 109 | (*h).FDeg=pFDeg((*h).p,currRing); |
---|
[35aab3] | 110 | (*h).ecart = d-(*h).FDeg; /*pFDeg((*h).p);*/ |
---|
| 111 | if ((strat->syzComp!=0) && !strat->honey) |
---|
| 112 | { |
---|
| 113 | if ((strat->syzComp>0) && (pMinComp((*h).p) > strat->syzComp)) |
---|
| 114 | { |
---|
[d42b51] | 115 | #ifdef KDEBUG |
---|
[35aab3] | 116 | if (TEST_OPT_DEBUG) PrintS(" > sysComp\n"); |
---|
[d42b51] | 117 | #endif |
---|
[35aab3] | 118 | return 0; |
---|
| 119 | } |
---|
| 120 | } |
---|
| 121 | /*- try to reduce the s-polynomial -*/ |
---|
| 122 | pass++; |
---|
| 123 | /* |
---|
| 124 | *test whether the polynomial should go to the lazyset L |
---|
| 125 | *-if the degree jumps |
---|
| 126 | *-if the number of pre-defined reductions jumps |
---|
| 127 | */ |
---|
| 128 | if ((strat->Ll >= 0) |
---|
| 129 | && ((d >= reddeg) || (pass > strat->LazyPass)) |
---|
| 130 | && !strat->homog) |
---|
| 131 | { |
---|
| 132 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
| 133 | if (at <= strat->Ll) |
---|
| 134 | { |
---|
| 135 | i=strat->sl+1; |
---|
| 136 | do |
---|
| 137 | { |
---|
| 138 | i--; |
---|
| 139 | if (i<0) return 0; |
---|
| 140 | } while (!pDivisibleBy(strat->S[i],(*h).p)); |
---|
| 141 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
[d42b51] | 142 | #ifdef KDEBUG |
---|
[35aab3] | 143 | if (TEST_OPT_DEBUG) Print(" degree jumped; ->L%d\n",at); |
---|
[d42b51] | 144 | #endif |
---|
[35aab3] | 145 | (*h).p = NULL; |
---|
| 146 | return 0; |
---|
| 147 | } |
---|
| 148 | } |
---|
| 149 | if ((TEST_OPT_PROT) && (strat->Ll < 0) && (d >= reddeg)) |
---|
| 150 | { |
---|
| 151 | reddeg = d+1; |
---|
| 152 | Print(".%d",d);mflush(); |
---|
| 153 | } |
---|
| 154 | j = 0; |
---|
[d42b51] | 155 | #ifdef KDEBUG |
---|
[35aab3] | 156 | if TEST_OPT_DEBUG PrintLn(); |
---|
[d42b51] | 157 | #endif |
---|
[35aab3] | 158 | } |
---|
| 159 | else |
---|
| 160 | { |
---|
[d42b51] | 161 | #ifdef KDEBUG |
---|
[35aab3] | 162 | if (TEST_OPT_DEBUG) PrintS("-"); |
---|
[d42b51] | 163 | #endif |
---|
[35aab3] | 164 | j++; |
---|
| 165 | } |
---|
| 166 | } |
---|
| 167 | } |
---|
[737e25] | 168 | void ratGB_divide_out(poly p) |
---|
| 169 | { |
---|
| 170 | if (p==NULL) return; |
---|
| 171 | poly root=p; |
---|
| 172 | assume(currRing->real_var_start>0); |
---|
| 173 | poly f=pHead(p); |
---|
| 174 | int i; |
---|
| 175 | for (i=currRing->real_var_start;i<=currRing->real_var_end;i++) |
---|
| 176 | { |
---|
| 177 | pSetExp(f,i,0); |
---|
| 178 | } |
---|
| 179 | loop |
---|
| 180 | { |
---|
| 181 | pIter(p); |
---|
| 182 | if (p==NULL) { pSetm(f); break;} |
---|
| 183 | for (i=1;i<=rVar(currRing);i++) |
---|
| 184 | { |
---|
| 185 | pSetExp(f,i,si_min(pGetExp(f,i),pGetExp(p,i))); |
---|
| 186 | } |
---|
| 187 | } |
---|
| 188 | if (!pIsConstant(f)) |
---|
| 189 | { |
---|
[d42b51] | 190 | #ifdef KDEBUG |
---|
[737e25] | 191 | if (TEST_OPT_DEBUG) |
---|
| 192 | { |
---|
| 193 | PrintS("divide out:");p_wrp(f,currRing); |
---|
| 194 | PrintS(" from ");pWrite(root); |
---|
| 195 | } |
---|
[d42b51] | 196 | #endif |
---|
[737e25] | 197 | p=root; |
---|
| 198 | loop |
---|
| 199 | { |
---|
| 200 | if (p==NULL) break; |
---|
| 201 | for (i=1;i<=rVar(currRing);i++) |
---|
| 202 | { |
---|
| 203 | pSetExp(p,i,pGetExp(p,i)-pGetExp(f,i)); |
---|
| 204 | } |
---|
| 205 | pSetm(p); |
---|
| 206 | pIter(p); |
---|
| 207 | } |
---|
| 208 | } |
---|
| 209 | pDelete(&f); |
---|
| 210 | } |
---|
| 211 | /*2 |
---|
| 212 | *reduces h with elements from T choosing the first possible |
---|
| 213 | * element in t with respect to the given pDivisibleBy |
---|
| 214 | * for use in ratGB |
---|
| 215 | */ |
---|
| 216 | int redGrRatGB (LObject* h,kStrategy strat) |
---|
| 217 | { |
---|
| 218 | int at,reddeg,d,i; |
---|
| 219 | int pass = 0; |
---|
| 220 | int j = 0; |
---|
[0047ec] | 221 | int c_j=-1, c_e=-2; |
---|
[737e25] | 222 | poly c_p=NULL; |
---|
| 223 | assume(strat->tailRing==currRing); |
---|
| 224 | |
---|
| 225 | ratGB_divide_out((*h).p); |
---|
| 226 | d = pFDeg((*h).p,currRing)+(*h).ecart; |
---|
| 227 | reddeg = strat->LazyDegree+d; |
---|
| 228 | if (!TEST_OPT_INTSTRATEGY) |
---|
| 229 | { |
---|
| 230 | if (rField_is_Zp_a()) pContent(h->p); |
---|
| 231 | else pCleardenom(h->p);// also does a pContent |
---|
| 232 | } |
---|
| 233 | loop |
---|
| 234 | { |
---|
| 235 | if (j > strat->sl) |
---|
| 236 | { |
---|
| 237 | if (c_j>=0) |
---|
| 238 | { |
---|
| 239 | /* |
---|
| 240 | * the polynomial to reduce with is; |
---|
| 241 | * S[c_j] |
---|
| 242 | */ |
---|
| 243 | if (!TEST_OPT_INTSTRATEGY) |
---|
| 244 | pNorm(strat->S[c_j]); |
---|
[d42b51] | 245 | #ifdef KDEBUG |
---|
| 246 | if (TEST_OPT_DEBUG) |
---|
[737e25] | 247 | if (TEST_OPT_DEBUG) |
---|
| 248 | { |
---|
| 249 | wrp(h->p); |
---|
[c7a127] | 250 | Print(" with S[%d]= ",c_j); |
---|
[737e25] | 251 | wrp(strat->S[c_j]); |
---|
| 252 | } |
---|
[d42b51] | 253 | #endif |
---|
[737e25] | 254 | //poly hh = nc_CreateSpoly(strat->S[c_j],(*h).p, currRing); |
---|
[36b9ef] | 255 | if(c_e==-1) |
---|
| 256 | c_p = nc_CreateSpoly(pCopy(strat->S[c_j]),pCopy((*h).p), currRing); |
---|
| 257 | else |
---|
| 258 | c_p=nc_rat_ReduceSpolyNew(pCopy(strat->S[c_j]), |
---|
| 259 | pCopy((*h).p),currRing->real_var_start-1,currRing); |
---|
[a13cae] | 260 | pDelete(&((*h).p)); |
---|
[36b9ef] | 261 | (*h).p=c_p; |
---|
[737e25] | 262 | if (!TEST_OPT_INTSTRATEGY) |
---|
| 263 | { |
---|
| 264 | if (rField_is_Zp_a()) pContent(h->p); |
---|
| 265 | else pCleardenom(h->p);// also does a pContent |
---|
| 266 | } |
---|
| 267 | |
---|
[d42b51] | 268 | #ifdef KDEBUG |
---|
[737e25] | 269 | if (TEST_OPT_DEBUG) |
---|
| 270 | { |
---|
| 271 | PrintS(" to "); |
---|
[9a001d] | 272 | wrp(h->p); |
---|
[c7a127] | 273 | PrintLn(); |
---|
[737e25] | 274 | } |
---|
[d42b51] | 275 | #endif |
---|
[737e25] | 276 | if ((*h).p == NULL) |
---|
| 277 | { |
---|
| 278 | if (h->lcm!=NULL) p_LmFree((*h).lcm, currRing); |
---|
| 279 | return 0; |
---|
| 280 | } |
---|
| 281 | ratGB_divide_out((*h).p); |
---|
| 282 | d = pLDeg((*h).p,&((*h).length),currRing); |
---|
| 283 | (*h).FDeg=pFDeg((*h).p,currRing); |
---|
| 284 | (*h).ecart = d-(*h).FDeg; /*pFDeg((*h).p);*/ |
---|
| 285 | /*- try to reduce the s-polynomial again -*/ |
---|
| 286 | pass++; |
---|
[a13cae] | 287 | j=0; |
---|
[36b9ef] | 288 | c_j=-1; c_e=-2; c_p=NULL; |
---|
[737e25] | 289 | } |
---|
| 290 | else |
---|
| 291 | { // nothing found |
---|
| 292 | return 0; |
---|
| 293 | } |
---|
| 294 | } |
---|
[0047ec] | 295 | // first try usal division |
---|
| 296 | if (p_LmDivisibleBy(strat->S[j],(*h).p,currRing)) |
---|
| 297 | { |
---|
[d42b51] | 298 | #ifdef KDEBUG |
---|
[0047ec] | 299 | if(TEST_OPT_DEBUG) |
---|
| 300 | { |
---|
| 301 | p_wrp(h->p,currRing); Print(" divisibly by S[%d]=",j); |
---|
| 302 | p_wrp(strat->S[j],currRing); PrintS(" e=-1\n"); |
---|
| 303 | } |
---|
[d42b51] | 304 | #endif |
---|
[342c80] | 305 | if ((c_j<0)||(c_e>=0)) |
---|
[0047ec] | 306 | { |
---|
| 307 | c_e=-1; c_j=j; |
---|
| 308 | } |
---|
| 309 | } |
---|
| 310 | else |
---|
[737e25] | 311 | if (p_LmDivisibleByPart(strat->S[j],(*h).p,currRing, |
---|
| 312 | currRing->real_var_start,currRing->real_var_end)) |
---|
| 313 | { |
---|
| 314 | int a_e=(pTotaldegree(strat->S[j],currRing)-pFDeg(strat->S[j],currRing)); |
---|
[d42b51] | 315 | #ifdef KDEBUG |
---|
[a13cae] | 316 | if(TEST_OPT_DEBUG) |
---|
| 317 | { |
---|
| 318 | p_wrp(h->p,currRing); Print(" divisibly by S[%d]=",j); |
---|
[c7a127] | 319 | p_wrp(strat->S[j],currRing); Print(" e=%d\n",a_e); |
---|
[a13cae] | 320 | } |
---|
[d42b51] | 321 | #endif |
---|
[342c80] | 322 | if ((c_j<0)||(c_e>a_e)) |
---|
[737e25] | 323 | { |
---|
| 324 | c_e=a_e; c_j=j; |
---|
[342c80] | 325 | //c_p = nc_CreateSpoly(pCopy(strat->S[c_j]),pCopy((*h).p), currRing); |
---|
[737e25] | 326 | } |
---|
| 327 | /*computes the ecart*/ |
---|
| 328 | if ((strat->syzComp!=0) && !strat->honey) |
---|
| 329 | { |
---|
| 330 | if ((strat->syzComp>0) && (pMinComp((*h).p) > strat->syzComp)) |
---|
| 331 | { |
---|
[d42b51] | 332 | #ifdef KDEBUG |
---|
[737e25] | 333 | if (TEST_OPT_DEBUG) PrintS(" > sysComp\n"); |
---|
[d42b51] | 334 | #endif |
---|
[737e25] | 335 | return 0; |
---|
| 336 | } |
---|
| 337 | } |
---|
| 338 | } |
---|
| 339 | else |
---|
| 340 | { |
---|
[d42b51] | 341 | #ifdef KDEBUG |
---|
[a13cae] | 342 | if(TEST_OPT_DEBUG) |
---|
| 343 | { |
---|
| 344 | p_wrp(h->p,currRing); Print(" not divisibly by S[%d]=",j); |
---|
| 345 | p_wrp(strat->S[j],currRing); PrintLn(); |
---|
| 346 | } |
---|
[d42b51] | 347 | #endif |
---|
[737e25] | 348 | } |
---|
| 349 | j++; |
---|
| 350 | } |
---|
| 351 | } |
---|
[35aab3] | 352 | |
---|
| 353 | /*2 |
---|
| 354 | * reduction procedure for the homogeneous case |
---|
| 355 | * and the case of a degree-ordering |
---|
| 356 | */ |
---|
[4bbe3b] | 357 | static int nc_redHomog (LObject* h,kStrategy strat) |
---|
[35aab3] | 358 | { |
---|
| 359 | if (strat->tl<0) |
---|
| 360 | { |
---|
| 361 | enterT((*h),strat); |
---|
| 362 | return 1; |
---|
| 363 | } |
---|
| 364 | |
---|
| 365 | int j = 0; |
---|
| 366 | |
---|
| 367 | if (TEST_OPT_DEBUG) |
---|
| 368 | { |
---|
| 369 | PrintS("red:"); |
---|
| 370 | wrp(h->p); |
---|
| 371 | PrintS(" "); |
---|
| 372 | } |
---|
| 373 | loop |
---|
| 374 | { |
---|
| 375 | if (TEST_OPT_DEBUG) Print("%d",j); |
---|
| 376 | if (pDivisibleBy(strat->S[j],(*h).p)) |
---|
| 377 | { |
---|
| 378 | if (TEST_OPT_DEBUG) |
---|
| 379 | { |
---|
| 380 | PrintS("+\nwith "); |
---|
| 381 | wrp(strat->S[j]); |
---|
| 382 | } |
---|
| 383 | /*- compute the s-polynomial -*/ |
---|
[19370c] | 384 | (*h).p = nc_ReduceSpoly(strat->S[j],(*h).p,currRing); |
---|
[35aab3] | 385 | if ((*h).p == NULL) |
---|
| 386 | { |
---|
| 387 | if (TEST_OPT_DEBUG) PrintS(" to 0\n"); |
---|
| 388 | if (h->lcm!=NULL) pLmFree((*h).lcm); |
---|
| 389 | (*h).lcm=NULL; |
---|
| 390 | return 0; |
---|
| 391 | } |
---|
| 392 | /* |
---|
| 393 | * else if (strat->syzComp) |
---|
| 394 | * { |
---|
| 395 | * if (pMinComp((*h).p) > strat->syzComp) |
---|
| 396 | * { |
---|
| 397 | * enterT((*h),strat); |
---|
| 398 | * return; |
---|
| 399 | * } |
---|
| 400 | * } |
---|
| 401 | */ |
---|
| 402 | /*- try to reduce the s-polynomial -*/ |
---|
| 403 | j = 0; |
---|
| 404 | } |
---|
| 405 | else |
---|
| 406 | { |
---|
| 407 | if (j >= strat->sl) |
---|
| 408 | { |
---|
| 409 | enterT((*h),strat); |
---|
| 410 | return 1; |
---|
| 411 | } |
---|
| 412 | j++; |
---|
| 413 | } |
---|
| 414 | } |
---|
| 415 | } |
---|
| 416 | |
---|
[5a9e7b] | 417 | #if 0 |
---|
[35aab3] | 418 | /*2 |
---|
| 419 | * reduction procedure for the homogeneous case |
---|
| 420 | * and the case of a degree-ordering |
---|
| 421 | */ |
---|
[4bbe3b] | 422 | static int nc_redHomog0 (LObject* h,kStrategy strat) |
---|
[35aab3] | 423 | { |
---|
| 424 | if (strat->tl<0) |
---|
| 425 | { |
---|
| 426 | enterT((*h),strat); |
---|
| 427 | return 0; |
---|
| 428 | } |
---|
| 429 | |
---|
| 430 | int j = 0; |
---|
| 431 | int k = 0; |
---|
| 432 | |
---|
| 433 | if (TEST_OPT_DEBUG) |
---|
| 434 | { |
---|
| 435 | PrintS("red:"); |
---|
| 436 | wrp(h->p); |
---|
| 437 | PrintS(" "); |
---|
| 438 | } |
---|
| 439 | loop |
---|
| 440 | { |
---|
| 441 | if (TEST_OPT_DEBUG) Print("%d",j); |
---|
| 442 | if (pDivisibleBy(strat->T[j].p,(*h).p)) |
---|
| 443 | { |
---|
| 444 | if (TEST_OPT_DEBUG) |
---|
| 445 | { |
---|
| 446 | PrintS("+\nwith "); |
---|
| 447 | wrp(strat->S[j]); |
---|
| 448 | } |
---|
| 449 | /*- compute the s-polynomial -*/ |
---|
[4bbe3b] | 450 | (*h).p = nc_ReduceSpoly(strat->T[j].p,(*h).p,strat->kNoether,currRing); |
---|
[35aab3] | 451 | if ((*h).p == NULL) |
---|
| 452 | { |
---|
| 453 | if (TEST_OPT_DEBUG) PrintS(" to 0\n"); |
---|
| 454 | if (h->lcm!=NULL) pLmFree((*h).lcm); |
---|
| 455 | (*h).lcm=NULL; |
---|
| 456 | return 0; |
---|
| 457 | } |
---|
[e36a2c0] | 458 | else |
---|
[35aab3] | 459 | { |
---|
[e36a2c0] | 460 | if (TEST_OPT_INTSTRATEGY) |
---|
[35aab3] | 461 | { |
---|
[e36a2c0] | 462 | if (rField_is_Zp_a()) pContent(h->p); |
---|
| 463 | else pCleardenom(h->p);// also does a pContent |
---|
| 464 | } |
---|
| 465 | if (strat->syzComp!=0) |
---|
| 466 | { |
---|
| 467 | if ((strat->syzComp>0) && (pMinComp((*h).p) > strat->syzComp)) |
---|
| 468 | { |
---|
[35aab3] | 469 | /* |
---|
[e36a2c0] | 470 | * (*h).length=pLength0((*h).p); |
---|
[35aab3] | 471 | */ |
---|
[e36a2c0] | 472 | enterT((*h),strat); |
---|
| 473 | return 0; |
---|
| 474 | } |
---|
[35aab3] | 475 | } |
---|
| 476 | } |
---|
| 477 | /*- try to reduce the s-polynomial -*/ |
---|
| 478 | j = 0; |
---|
| 479 | } |
---|
| 480 | else |
---|
| 481 | { |
---|
| 482 | if (j >= strat->tl) |
---|
| 483 | { |
---|
[e36a2c0] | 484 | if (TEST_OPT_INTSTRATEGY) |
---|
| 485 | { |
---|
| 486 | if (rField_is_Zp_a()) pContent(h->p); |
---|
| 487 | else pCleardenom(h->p);// also does a pContent |
---|
| 488 | } |
---|
[35aab3] | 489 | /* |
---|
| 490 | * (*h).length=pLength0((*h).p); |
---|
| 491 | */ |
---|
| 492 | enterT((*h),strat); |
---|
| 493 | return 0; |
---|
| 494 | } |
---|
| 495 | j++; |
---|
| 496 | } |
---|
| 497 | } |
---|
| 498 | } |
---|
| 499 | |
---|
| 500 | /*2 |
---|
| 501 | * reduction procedure for the inhomogeneous case |
---|
| 502 | * and not a degree-ordering |
---|
| 503 | */ |
---|
[4bbe3b] | 504 | static int nc_redLazy (LObject* h,kStrategy strat) |
---|
[35aab3] | 505 | { |
---|
| 506 | if (strat->tl<0) |
---|
| 507 | { |
---|
| 508 | enterT((*h),strat); |
---|
| 509 | return 0; |
---|
| 510 | } |
---|
| 511 | |
---|
| 512 | int at,d,i; |
---|
| 513 | int j = 0; |
---|
| 514 | int pass = 0; |
---|
[b130fb] | 515 | int reddeg = pFDeg((*h).p,currRing); |
---|
[35aab3] | 516 | |
---|
| 517 | if (TEST_OPT_DEBUG) |
---|
| 518 | { |
---|
| 519 | PrintS("red:"); |
---|
| 520 | wrp(h->p); |
---|
| 521 | PrintS(" "); |
---|
| 522 | } |
---|
| 523 | loop |
---|
| 524 | { |
---|
| 525 | if (TEST_OPT_DEBUG) Print("%d",j); |
---|
| 526 | if (pDivisibleBy(strat->S[j],(*h).p)) |
---|
| 527 | { |
---|
| 528 | if (TEST_OPT_DEBUG) |
---|
| 529 | { |
---|
| 530 | PrintS("+\nwith "); |
---|
| 531 | wrp(strat->S[j]); |
---|
| 532 | } |
---|
| 533 | /*- compute the s-polynomial -*/ |
---|
[4bbe3b] | 534 | (*h).p = nc_ReduceSpoly(strat->S[j],(*h).p,strat->kNoether,currRing); |
---|
[35aab3] | 535 | if ((*h).p == NULL) |
---|
| 536 | { |
---|
| 537 | if (TEST_OPT_DEBUG) PrintS(" to 0\n"); |
---|
| 538 | if (h->lcm!=NULL) pLmFree((*h).lcm); |
---|
| 539 | (*h).lcm=NULL; |
---|
| 540 | return 0; |
---|
| 541 | } |
---|
| 542 | // else if (strat->syzComp) |
---|
| 543 | // { |
---|
| 544 | // if ((strat->syzComp>0) && (pMinComp((*h).p) > strat->syzComp)) |
---|
| 545 | // { |
---|
| 546 | // if (TEST_OPT_DEBUG) PrintS(" > syzComp\n"); |
---|
| 547 | // if (TEST_OPT_INTSTRATEGY) pContent(h->p); |
---|
| 548 | // enterTBba((*h),strat->tl+1,strat); |
---|
| 549 | // return; |
---|
| 550 | // } |
---|
| 551 | // } |
---|
[e36a2c0] | 552 | else |
---|
[35aab3] | 553 | { |
---|
[e36a2c0] | 554 | if (TEST_OPT_DEBUG) |
---|
| 555 | { |
---|
| 556 | PrintS("to:"); |
---|
| 557 | wrp((*h).p); |
---|
| 558 | PrintLn(); |
---|
| 559 | } |
---|
| 560 | if (TEST_OPT_INTSTRATEGY) |
---|
| 561 | { |
---|
| 562 | pContent(h->p); |
---|
| 563 | //pCleardenom(h->p);// also does a pContent |
---|
| 564 | } |
---|
[35aab3] | 565 | } |
---|
| 566 | /*- try to reduce the s-polynomial -*/ |
---|
| 567 | pass++; |
---|
[b130fb] | 568 | d = pFDeg((*h).p,currRing); |
---|
[35aab3] | 569 | if ((strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass))) |
---|
| 570 | { |
---|
| 571 | at = posInL11(strat->L,strat->Ll,h,strat); |
---|
| 572 | if (at <= strat->Ll) |
---|
| 573 | { |
---|
| 574 | i=strat->sl+1; |
---|
| 575 | do |
---|
| 576 | { |
---|
| 577 | i--; |
---|
| 578 | if (i<0) |
---|
| 579 | { |
---|
| 580 | enterT((*h),strat); |
---|
| 581 | return 0; |
---|
| 582 | } |
---|
| 583 | } |
---|
[e36a2c0] | 584 | while (!pDivisibleBy(strat->S[i],(*h).p)); |
---|
[35aab3] | 585 | if (TEST_OPT_DEBUG) Print(" ->L[%d]\n",at); |
---|
| 586 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
| 587 | (*h).p = NULL; |
---|
| 588 | return 0; |
---|
| 589 | } |
---|
| 590 | } |
---|
| 591 | else if ((TEST_OPT_PROT) && (strat->Ll < 0) && (d != reddeg)) |
---|
| 592 | { |
---|
| 593 | Print(".%d",d);mflush(); |
---|
| 594 | reddeg = d; |
---|
| 595 | } |
---|
| 596 | j = 0; |
---|
| 597 | } |
---|
| 598 | else |
---|
| 599 | { |
---|
| 600 | if (TEST_OPT_DEBUG) PrintS("-"); |
---|
| 601 | if (j >= strat->sl) |
---|
| 602 | { |
---|
| 603 | if (TEST_OPT_DEBUG) PrintLn(); |
---|
| 604 | if (TEST_OPT_INTSTRATEGY) |
---|
| 605 | { |
---|
[e36a2c0] | 606 | if (rField_is_Zp_a()) pContent(h->p); |
---|
| 607 | else pCleardenom(h->p);// also does a pContent |
---|
[35aab3] | 608 | } |
---|
| 609 | enterT((*h),strat); |
---|
| 610 | return 0; |
---|
| 611 | } |
---|
| 612 | j++; |
---|
| 613 | } |
---|
| 614 | } |
---|
| 615 | } |
---|
| 616 | |
---|
| 617 | /*2 |
---|
| 618 | * reduction procedure for the sugar-strategy (honey) |
---|
| 619 | * reduces h with elements from T choosing first possible |
---|
| 620 | * element in T with respect to the given ecart |
---|
| 621 | */ |
---|
[4bbe3b] | 622 | static int nc_redHoney (LObject* h,kStrategy strat) |
---|
[35aab3] | 623 | { |
---|
| 624 | if (strat->tl<0) |
---|
| 625 | { |
---|
| 626 | enterT((*h),strat); |
---|
| 627 | return 0; |
---|
| 628 | } |
---|
| 629 | |
---|
| 630 | poly pi; |
---|
| 631 | int i,j,at,reddeg,d,pass,ei; |
---|
| 632 | |
---|
| 633 | pass = j = 0; |
---|
[b130fb] | 634 | d = reddeg = pFDeg((*h).p,currRing)+(*h).ecart; |
---|
[35aab3] | 635 | if (TEST_OPT_DEBUG) |
---|
| 636 | { |
---|
| 637 | PrintS("red:"); |
---|
| 638 | wrp((*h).p); |
---|
| 639 | } |
---|
| 640 | loop |
---|
| 641 | { |
---|
| 642 | if (TEST_OPT_DEBUG) Print("%d",j); |
---|
| 643 | if (pDivisibleBy(strat->T[j].p,(*h).p)) |
---|
| 644 | { |
---|
| 645 | if (TEST_OPT_DEBUG) PrintS("+"); |
---|
| 646 | pi = strat->T[j].p; |
---|
| 647 | ei = strat->T[j].ecart; |
---|
| 648 | /* |
---|
| 649 | * the polynomial to reduce with (up to the moment) is; |
---|
| 650 | * pi with ecart ei |
---|
| 651 | */ |
---|
| 652 | i = j; |
---|
| 653 | loop |
---|
| 654 | { |
---|
| 655 | /*- takes the first possible with respect to ecart -*/ |
---|
| 656 | i++; |
---|
| 657 | if (i > strat->tl) |
---|
| 658 | break; |
---|
| 659 | if ((!BTEST1(20)) && (ei <= (*h).ecart)) |
---|
| 660 | break; |
---|
| 661 | if (TEST_OPT_DEBUG) Print("%d",i); |
---|
| 662 | if ((strat->T[i].ecart < ei) && pDivisibleBy(strat->T[i].p,(*h).p)) |
---|
| 663 | { |
---|
| 664 | if (TEST_OPT_DEBUG) PrintS("+"); |
---|
| 665 | /* |
---|
| 666 | * the polynomial to reduce with is now; |
---|
| 667 | */ |
---|
| 668 | pi = strat->T[i].p; |
---|
| 669 | ei = strat->T[i].ecart; |
---|
| 670 | } |
---|
| 671 | else if (TEST_OPT_DEBUG) PrintS("-"); |
---|
| 672 | } |
---|
| 673 | |
---|
| 674 | /* |
---|
| 675 | * end of search: have to reduce with pi |
---|
| 676 | */ |
---|
| 677 | if (ei > (*h).ecart) |
---|
| 678 | { |
---|
| 679 | /* |
---|
| 680 | * It is not possible to reduce h with smaller ecart; |
---|
| 681 | * if possible h goes to the lazy-set L,i.e |
---|
| 682 | * if its position in L would be not the last one |
---|
| 683 | */ |
---|
| 684 | if (strat->Ll >= 0) /* L is not empty */ |
---|
| 685 | { |
---|
| 686 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
| 687 | if(at <= strat->Ll) |
---|
| 688 | /*- h will not become the next element to reduce -*/ |
---|
| 689 | { |
---|
| 690 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
| 691 | if (TEST_OPT_DEBUG) Print(" ecart too big: -> L%d\n",at); |
---|
| 692 | (*h).p = NULL; |
---|
| 693 | return 0; |
---|
| 694 | } |
---|
| 695 | } |
---|
| 696 | } |
---|
| 697 | if (TEST_OPT_DEBUG) |
---|
| 698 | { |
---|
| 699 | PrintS("\nwith "); |
---|
| 700 | wrp(pi); |
---|
| 701 | } |
---|
| 702 | if (strat->fromT) |
---|
| 703 | { |
---|
| 704 | strat->fromT=FALSE; |
---|
[52e2f6] | 705 | (*h).p = nc_ReduceSpoly(pi,(*h).p,strat->kNoether,currRing); |
---|
[35aab3] | 706 | } |
---|
| 707 | else |
---|
[4bbe3b] | 708 | (*h).p = nc_ReduceSpoly(pi,(*h).p,strat->kNoether,currRing); |
---|
[35aab3] | 709 | if (TEST_OPT_DEBUG) |
---|
| 710 | { |
---|
| 711 | PrintS(" to "); |
---|
| 712 | wrp((*h).p); |
---|
| 713 | PrintLn(); |
---|
| 714 | } |
---|
| 715 | if ((*h).p == NULL) |
---|
| 716 | { |
---|
| 717 | if (h->lcm!=NULL) pLmFree((*h).lcm); |
---|
| 718 | (*h).lcm=NULL; |
---|
| 719 | return 0; |
---|
| 720 | } |
---|
[e36a2c0] | 721 | if (TEST_OPT_INTSTRATEGY) |
---|
| 722 | { |
---|
| 723 | //pContent(h->p); |
---|
| 724 | pCleardenom(h->p);// also does a pContent |
---|
| 725 | } |
---|
[35aab3] | 726 | /* compute the ecart */ |
---|
| 727 | if (ei <= (*h).ecart) |
---|
[b130fb] | 728 | (*h).ecart = d-pFDeg((*h).p,currRing); |
---|
[35aab3] | 729 | else |
---|
[b130fb] | 730 | (*h).ecart = d-pFDeg((*h).p,currRing)+ei-(*h).ecart; |
---|
[35aab3] | 731 | // if (strat->syzComp) |
---|
| 732 | // { |
---|
| 733 | // if ((strat->syzComp>0) && (pMinComp((*h).p) > strat->syzComp)) |
---|
| 734 | // { |
---|
| 735 | // if (TEST_OPT_DEBUG) |
---|
| 736 | // PrintS(" >syzComp\n"); |
---|
| 737 | // if (TEST_OPT_INTSTRATEGY) pContent(h->p); |
---|
| 738 | // at=strat->posInT(strat->T,strat->tl,(*h)); |
---|
| 739 | // enterTBba((*h),at,strat); |
---|
| 740 | // return; |
---|
| 741 | // } |
---|
| 742 | // } |
---|
| 743 | /* |
---|
| 744 | * try to reduce the s-polynomial h |
---|
| 745 | *test first whether h should go to the lazyset L |
---|
| 746 | *-if the degree jumps |
---|
| 747 | *-if the number of pre-defined reductions jumps |
---|
| 748 | */ |
---|
| 749 | pass++; |
---|
[b130fb] | 750 | d = pFDeg((*h).p,currRing)+(*h).ecart; |
---|
[35aab3] | 751 | if ((strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass))) |
---|
| 752 | { |
---|
| 753 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
| 754 | if (at <= strat->Ll) |
---|
| 755 | { |
---|
| 756 | /*test if h is already standardbasis element*/ |
---|
| 757 | i=strat->sl+1; |
---|
| 758 | do |
---|
| 759 | { |
---|
| 760 | i--; |
---|
| 761 | if (i<0) |
---|
| 762 | { |
---|
| 763 | enterT((*h),strat); |
---|
| 764 | return 0; |
---|
| 765 | } |
---|
| 766 | } while (!pDivisibleBy(strat->S[i],(*h).p)); |
---|
| 767 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
| 768 | if (TEST_OPT_DEBUG) |
---|
| 769 | Print(" degree jumped: -> L%d\n",at); |
---|
| 770 | (*h).p = NULL; |
---|
| 771 | return 0; |
---|
| 772 | } |
---|
| 773 | } |
---|
| 774 | else if (TEST_OPT_PROT && (strat->Ll < 0) && (d > reddeg)) |
---|
| 775 | { |
---|
| 776 | reddeg = d; |
---|
| 777 | Print(".%d",d); mflush(); |
---|
| 778 | } |
---|
| 779 | j = 0; |
---|
| 780 | } |
---|
| 781 | else |
---|
| 782 | { |
---|
| 783 | if (TEST_OPT_DEBUG) PrintS("-"); |
---|
| 784 | if (j >= strat->tl) |
---|
| 785 | { |
---|
| 786 | if (TEST_OPT_DEBUG) PrintLn(); |
---|
| 787 | if (TEST_OPT_INTSTRATEGY) |
---|
| 788 | { |
---|
| 789 | //pContent(h->p); |
---|
| 790 | pCleardenom(h->p);// also does a pContent |
---|
| 791 | } |
---|
| 792 | enterT((*h),strat); |
---|
| 793 | return 0; |
---|
| 794 | } |
---|
| 795 | j++; |
---|
| 796 | } |
---|
| 797 | } |
---|
| 798 | } |
---|
| 799 | |
---|
| 800 | /*2 |
---|
| 801 | * reduction procedure for tests only |
---|
| 802 | * reduces with elements from T and chooses the best possible |
---|
| 803 | */ |
---|
[4bbe3b] | 804 | static int nc_redBest (LObject* h,kStrategy strat) |
---|
[35aab3] | 805 | { |
---|
| 806 | if (strat->tl<0) |
---|
| 807 | { |
---|
| 808 | enterT((*h),strat); |
---|
| 809 | return 0; |
---|
| 810 | } |
---|
| 811 | |
---|
| 812 | int j,jbest,at,reddeg,d,pass; |
---|
| 813 | poly p,ph; |
---|
| 814 | pass = j = 0; |
---|
| 815 | |
---|
| 816 | if (strat->honey) |
---|
[b130fb] | 817 | reddeg = pFDeg((*h).p,currRing)+(*h).ecart; |
---|
[35aab3] | 818 | else |
---|
[b130fb] | 819 | reddeg = pFDeg((*h).p,currRing); |
---|
[35aab3] | 820 | loop |
---|
| 821 | { |
---|
| 822 | if (pDivisibleBy(strat->T[j].p,(*h).p)) |
---|
| 823 | { |
---|
| 824 | /* compute the s-polynomial */ |
---|
| 825 | if (!TEST_OPT_INTSTRATEGY) pNorm((*h).p); |
---|
| 826 | #ifdef SDRING |
---|
| 827 | // spSpolyShortBba will not work in the SRING case |
---|
| 828 | if (pSDRING) |
---|
| 829 | { |
---|
| 830 | p=spSpolyCreate(strat->T[j].p,(*h).p,strat->kNoether); |
---|
| 831 | if (p!=NULL) pDelete(&pNext(p)); |
---|
| 832 | } |
---|
| 833 | else |
---|
| 834 | #endif |
---|
[4bbe3b] | 835 | p = nc_CreateShortSpoly(strat->T[j].p,(*h).p); |
---|
[35aab3] | 836 | /* computes only the first monomial of the spoly */ |
---|
| 837 | if (p) |
---|
| 838 | { |
---|
| 839 | jbest = j; |
---|
| 840 | /* looking for the best possible reduction */ |
---|
| 841 | if ((strat->syzComp==0) || (pMinComp(p) <= strat->syzComp)) |
---|
| 842 | { |
---|
| 843 | loop |
---|
| 844 | { |
---|
| 845 | j++; |
---|
| 846 | if (j > strat->tl) |
---|
| 847 | break; |
---|
| 848 | if (pDivisibleBy(strat->T[j].p,(*h).p)) |
---|
| 849 | { |
---|
| 850 | #ifdef SDRING |
---|
| 851 | // spSpolyShortBba will not work in the SRING case |
---|
| 852 | if (pSDRING) |
---|
| 853 | { |
---|
| 854 | ph=spSpolyCreate(strat->T[j].p,(*h).p,strat->kNoether); |
---|
| 855 | if (ph!=NULL) pDelete(&pNext(ph)); |
---|
| 856 | } |
---|
| 857 | else |
---|
| 858 | #endif |
---|
[4bbe3b] | 859 | ph = nc_CreateShortSpoly(strat->T[j].p,(*h).p); |
---|
[35aab3] | 860 | if (ph==NULL) |
---|
| 861 | { |
---|
| 862 | pLmFree(p); |
---|
| 863 | pDelete(&((*h).p)); |
---|
| 864 | if (h->lcm!=NULL) |
---|
| 865 | { |
---|
| 866 | pLmFree((*h).lcm); |
---|
| 867 | (*h).lcm=NULL; |
---|
| 868 | } |
---|
| 869 | return 0; |
---|
| 870 | } |
---|
| 871 | else if (pLmCmp(ph,p) == -1) |
---|
| 872 | { |
---|
| 873 | pLmFree(p); |
---|
| 874 | p = ph; |
---|
| 875 | jbest = j; |
---|
| 876 | } |
---|
| 877 | else |
---|
| 878 | { |
---|
| 879 | pLmFree(ph); |
---|
| 880 | } |
---|
| 881 | } |
---|
| 882 | } |
---|
| 883 | } |
---|
| 884 | pLmFree(p); |
---|
[4bbe3b] | 885 | (*h).p = nc_ReduceSpoly(strat->T[jbest].p,(*h).p,strat->kNoether,currRing); |
---|
[35aab3] | 886 | } |
---|
| 887 | else |
---|
| 888 | { |
---|
| 889 | if (h->lcm!=NULL) |
---|
| 890 | { |
---|
| 891 | pLmFree((*h).lcm); |
---|
| 892 | (*h).lcm=NULL; |
---|
| 893 | } |
---|
| 894 | (*h).p = NULL; |
---|
| 895 | return 0; |
---|
| 896 | } |
---|
| 897 | if (strat->honey && pLexOrder) |
---|
| 898 | strat->initEcart(h); |
---|
| 899 | /* h.length:=l; */ |
---|
| 900 | /* try to reduce the s-polynomial */ |
---|
| 901 | // if (strat->syzComp) |
---|
| 902 | // { |
---|
| 903 | // if ((strat->syzComp>0) && (pMinComp((*h).p) > strat->syzComp)) |
---|
| 904 | // { |
---|
| 905 | // if (TEST_OPT_DEBUG) |
---|
| 906 | // PrintS(" >syzComp\n"); |
---|
| 907 | // if (TEST_OPT_INTSTRATEGY) pContent(h->p); |
---|
| 908 | // at=strat->posInT(strat->T,strat->tl,(*h)); |
---|
| 909 | // enterTBba((*h),at,strat); |
---|
| 910 | // return; |
---|
| 911 | // } |
---|
| 912 | // } |
---|
| 913 | if (strat->honey || pLexOrder) |
---|
| 914 | { |
---|
| 915 | pass++; |
---|
[b130fb] | 916 | d = pFDeg((*h).p,currRing); |
---|
[35aab3] | 917 | if (strat->honey) |
---|
| 918 | d += (*h).ecart; |
---|
| 919 | if ((strat->Ll >= 0) && ((pass > strat->LazyPass) || (d > reddeg))) |
---|
| 920 | { |
---|
| 921 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
| 922 | if (at <= strat->Ll) |
---|
| 923 | { |
---|
| 924 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
| 925 | (*h).p = NULL; |
---|
| 926 | return 0; |
---|
| 927 | } |
---|
| 928 | } |
---|
| 929 | else if (TEST_OPT_PROT && (strat->Ll < 0) && (d != reddeg)) |
---|
| 930 | { |
---|
| 931 | reddeg = d; |
---|
| 932 | Print("%d."); |
---|
| 933 | mflush(); |
---|
| 934 | } |
---|
| 935 | } |
---|
| 936 | j = 0; |
---|
| 937 | } |
---|
| 938 | else |
---|
| 939 | { |
---|
| 940 | if (j >= strat->tl) |
---|
| 941 | { |
---|
| 942 | if (TEST_OPT_INTSTRATEGY) |
---|
| 943 | { |
---|
| 944 | //pContent(h->p); |
---|
| 945 | pCleardenom(h->p);// also does a pContent |
---|
| 946 | } |
---|
| 947 | enterT((*h),strat); |
---|
| 948 | return 0; |
---|
| 949 | } |
---|
| 950 | j++; |
---|
| 951 | } |
---|
| 952 | } |
---|
| 953 | } |
---|
| 954 | |
---|
[5a9e7b] | 955 | #endif |
---|
| 956 | |
---|
[86016d] | 957 | void nc_gr_initBba(ideal F, kStrategy strat) |
---|
[35aab3] | 958 | { |
---|
[5a9e7b] | 959 | assume(rIsPluralRing(currRing)); |
---|
| 960 | |
---|
[35aab3] | 961 | int i; |
---|
| 962 | idhdl h; |
---|
| 963 | /* setting global variables ------------------- */ |
---|
| 964 | strat->enterS = enterSBba; |
---|
[5a9e7b] | 965 | |
---|
| 966 | /* |
---|
[35aab3] | 967 | if ((BTEST1(20)) && (!strat->honey)) |
---|
[4bbe3b] | 968 | strat->red = nc_redBest; |
---|
[35aab3] | 969 | else if (strat->honey) |
---|
[4bbe3b] | 970 | strat->red = nc_redHoney; |
---|
[35aab3] | 971 | else if (pLexOrder && !strat->homog) |
---|
[4bbe3b] | 972 | strat->red = nc_redLazy; |
---|
[35aab3] | 973 | else if (TEST_OPT_INTSTRATEGY && strat->homog) |
---|
[4bbe3b] | 974 | strat->red = nc_redHomog0; |
---|
[35aab3] | 975 | else |
---|
[4bbe3b] | 976 | strat->red = nc_redHomog; |
---|
[5a9e7b] | 977 | */ |
---|
| 978 | |
---|
| 979 | // if (rIsPluralRing(currRing)) |
---|
[35aab3] | 980 | strat->red = redGrFirst; |
---|
[737e25] | 981 | if (currRing->real_var_start>0) |
---|
[4debf02] | 982 | { |
---|
[36b9ef] | 983 | int ii=IDELEMS(F)-1; |
---|
| 984 | int jj; |
---|
| 985 | BOOLEAN is_rat_id=FALSE; |
---|
| 986 | for(;ii>=0;ii--) |
---|
| 987 | { |
---|
| 988 | for(jj=currRing->real_var_start;jj<=currRing->real_var_end;jj++) |
---|
| 989 | { |
---|
| 990 | if(pGetExp(F->m[ii],jj)>0) { is_rat_id=TRUE; break; } |
---|
| 991 | } |
---|
| 992 | if (is_rat_id) break; |
---|
| 993 | } |
---|
| 994 | if (is_rat_id) strat->red=redGrRatGB; |
---|
[4debf02] | 995 | } |
---|
[5a9e7b] | 996 | |
---|
[35aab3] | 997 | if (pLexOrder && strat->honey) |
---|
| 998 | strat->initEcart = initEcartNormal; |
---|
| 999 | else |
---|
| 1000 | strat->initEcart = initEcartBBA; |
---|
| 1001 | if (strat->honey) |
---|
| 1002 | strat->initEcartPair = initEcartPairMora; |
---|
| 1003 | else |
---|
| 1004 | strat->initEcartPair = initEcartPairBba; |
---|
| 1005 | strat->kIdeal = NULL; |
---|
| 1006 | //if (strat->ak==0) strat->kIdeal->rtyp=IDEAL_CMD; |
---|
| 1007 | //else strat->kIdeal->rtyp=MODUL_CMD; |
---|
| 1008 | //strat->kIdeal->data=(void *)strat->Shdl; |
---|
| 1009 | if ((TEST_OPT_WEIGHTM)&&(F!=NULL)) |
---|
| 1010 | { |
---|
[4bbe3b] | 1011 | //interred machen Aenderung |
---|
| 1012 | pFDegOld=pFDeg; |
---|
| 1013 | pLDegOld=pLDeg; |
---|
| 1014 | // h=ggetid("ecart"); |
---|
| 1015 | // if ((h!=NULL) && (IDTYP(h)==INTVEC_CMD)) |
---|
| 1016 | // { |
---|
| 1017 | // ecartWeights=iv2array(IDINTVEC(h)); |
---|
| 1018 | // } |
---|
| 1019 | // else |
---|
[35aab3] | 1020 | { |
---|
| 1021 | ecartWeights=(short *)omAlloc((pVariables+1)*sizeof(short)); |
---|
| 1022 | /*uses automatic computation of the ecartWeights to set them*/ |
---|
| 1023 | kEcartWeights(F->m,IDELEMS(F)-1,ecartWeights); |
---|
| 1024 | } |
---|
| 1025 | pFDeg=totaldegreeWecart; |
---|
| 1026 | pLDeg=maxdegreeWecart; |
---|
| 1027 | for(i=1; i<=pVariables; i++) |
---|
| 1028 | Print(" %d",ecartWeights[i]); |
---|
| 1029 | PrintLn(); |
---|
| 1030 | mflush(); |
---|
| 1031 | } |
---|
| 1032 | } |
---|
| 1033 | |
---|
[52e2f6] | 1034 | #define MYTEST 0 |
---|
| 1035 | |
---|
[5a9e7b] | 1036 | ideal gnc_gr_bba(const ideal F, const ideal Q, const intvec *, const intvec *, kStrategy strat) |
---|
[35aab3] | 1037 | { |
---|
[52e2f6] | 1038 | #if MYTEST |
---|
| 1039 | PrintS("<gnc_gr_bba>\n"); |
---|
| 1040 | #endif |
---|
| 1041 | |
---|
| 1042 | #ifdef HAVE_PLURAL |
---|
| 1043 | #if MYTEST |
---|
| 1044 | PrintS("currRing: \n"); |
---|
| 1045 | rWrite(currRing); |
---|
| 1046 | #ifdef RDEBUG |
---|
| 1047 | rDebugPrint(currRing); |
---|
| 1048 | #endif |
---|
| 1049 | |
---|
| 1050 | PrintS("F: \n"); |
---|
[737e25] | 1051 | idPrint(F); |
---|
| 1052 | PrintS("Q: \n"); |
---|
[52e2f6] | 1053 | idPrint(Q); |
---|
| 1054 | #endif |
---|
| 1055 | #endif |
---|
| 1056 | |
---|
| 1057 | |
---|
[737e25] | 1058 | |
---|
[5a9e7b] | 1059 | assume(pOrdSgn != -1); // no mora!!! it terminates only for global ordering!!! (?) |
---|
| 1060 | |
---|
[35aab3] | 1061 | intvec *w=NULL; |
---|
| 1062 | intvec *hilb=NULL; |
---|
| 1063 | int srmax,lrmax; |
---|
| 1064 | int olddeg,reduc; |
---|
| 1065 | int red_result=1; |
---|
| 1066 | int hilbeledeg=1,hilbcount=0,minimcnt=0; |
---|
| 1067 | |
---|
| 1068 | initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/ |
---|
| 1069 | // initHilbCrit(F,Q,&hilb,strat); |
---|
| 1070 | /* in plural we don't need Hilb yet */ |
---|
[86016d] | 1071 | nc_gr_initBba(F,strat); |
---|
[35aab3] | 1072 | initBuchMoraPos(strat); |
---|
[4debf02] | 1073 | if (currRing->real_var_start>0) |
---|
| 1074 | { |
---|
| 1075 | strat->posInL=posInL0; // by pCmp of lcm |
---|
| 1076 | } |
---|
[0047ec] | 1077 | /*set enterS, spSpolyShort, reduce, red, initEcart, initEcartPair*/ |
---|
| 1078 | /*Shdl=*/initBuchMora(F, Q,strat); |
---|
| 1079 | strat->posInT=posInT110; |
---|
[35aab3] | 1080 | srmax = strat->sl; |
---|
| 1081 | reduc = olddeg = lrmax = 0; |
---|
[52e2f6] | 1082 | |
---|
[35aab3] | 1083 | /* compute------------------------------------------------------- */ |
---|
| 1084 | while (strat->Ll >= 0) |
---|
| 1085 | { |
---|
| 1086 | if (strat->Ll > lrmax) lrmax =strat->Ll;/*stat.*/ |
---|
[52e2f6] | 1087 | |
---|
[35aab3] | 1088 | if (TEST_OPT_DEBUG) messageSets(strat); |
---|
[52e2f6] | 1089 | |
---|
[35aab3] | 1090 | if (strat->Ll== 0) strat->interpt=TRUE; |
---|
| 1091 | if (TEST_OPT_DEGBOUND |
---|
[b130fb] | 1092 | && ((strat->honey |
---|
| 1093 | && (strat->L[strat->Ll].ecart+pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg)) |
---|
| 1094 | || ((!strat->honey) && (pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg)))) |
---|
[35aab3] | 1095 | { |
---|
| 1096 | /* |
---|
| 1097 | *stops computation if |
---|
| 1098 | * 24 IN test and the degree +ecart of L[strat->Ll] is bigger then |
---|
| 1099 | *a predefined number Kstd1_deg |
---|
| 1100 | */ |
---|
| 1101 | while (strat->Ll >= 0) deleteInL(strat->L,&strat->Ll,strat->Ll,strat); |
---|
| 1102 | break; |
---|
| 1103 | } |
---|
| 1104 | /* picks the last element from the lazyset L */ |
---|
| 1105 | strat->P = strat->L[strat->Ll]; |
---|
| 1106 | strat->Ll--; |
---|
[626431] | 1107 | //kTest(strat); |
---|
[52e2f6] | 1108 | |
---|
| 1109 | if (strat->P.p != NULL) |
---|
[35aab3] | 1110 | if (pNext(strat->P.p) == strat->tail) |
---|
| 1111 | { |
---|
| 1112 | /* deletes the short spoly and computes */ |
---|
| 1113 | pLmFree(strat->P.p); |
---|
| 1114 | /* the real one */ |
---|
[52e2f6] | 1115 | if (ncRingType(currRing)==nc_lie) /* prod crit */ |
---|
| 1116 | if(pHasNotCF(strat->P.p1,strat->P.p2)) |
---|
| 1117 | { |
---|
| 1118 | // strat->cp++; |
---|
| 1119 | /* prod.crit itself in nc_CreateSpoly */ |
---|
| 1120 | } |
---|
[737e25] | 1121 | |
---|
[52e2f6] | 1122 | strat->P.p = nc_CreateSpoly(strat->P.p1,strat->P.p2,currRing); |
---|
| 1123 | |
---|
| 1124 | #ifdef PDEBUG |
---|
| 1125 | p_Test(strat->P.p, currRing); |
---|
| 1126 | #endif |
---|
| 1127 | |
---|
| 1128 | #if MYTEST |
---|
| 1129 | if (TEST_OPT_DEBUG) |
---|
[35aab3] | 1130 | { |
---|
[52e2f6] | 1131 | PrintS("p1: "); pWrite(strat->P.p1); |
---|
| 1132 | PrintS("p2: "); pWrite(strat->P.p2); |
---|
| 1133 | PrintS("SPoly: "); pWrite(strat->P.p); |
---|
[35aab3] | 1134 | } |
---|
[737e25] | 1135 | #endif |
---|
[35aab3] | 1136 | } |
---|
[52e2f6] | 1137 | |
---|
[737e25] | 1138 | |
---|
[35aab3] | 1139 | if (strat->P.p != NULL) |
---|
| 1140 | { |
---|
| 1141 | if (TEST_OPT_PROT) |
---|
[52e2f6] | 1142 | message((strat->honey ? strat->P.ecart : 0) + strat->P.pFDeg(), |
---|
[35aab3] | 1143 | &olddeg,&reduc,strat, red_result); |
---|
[52e2f6] | 1144 | |
---|
| 1145 | #if MYTEST |
---|
| 1146 | if (TEST_OPT_DEBUG) |
---|
| 1147 | { |
---|
| 1148 | PrintS("p1: "); pWrite(strat->P.p1); |
---|
| 1149 | PrintS("p2: "); pWrite(strat->P.p2); |
---|
| 1150 | PrintS("SPoly before: "); pWrite(strat->P.p); |
---|
| 1151 | } |
---|
| 1152 | #endif |
---|
| 1153 | |
---|
[35aab3] | 1154 | /* reduction of the element chosen from L */ |
---|
| 1155 | strat->red(&strat->P,strat); |
---|
[52e2f6] | 1156 | |
---|
| 1157 | #if MYTEST |
---|
| 1158 | if (TEST_OPT_DEBUG) |
---|
| 1159 | { |
---|
| 1160 | PrintS("red SPoly: "); pWrite(strat->P.p); |
---|
| 1161 | } |
---|
| 1162 | #endif |
---|
| 1163 | |
---|
[35aab3] | 1164 | } |
---|
| 1165 | if (strat->P.p != NULL) |
---|
| 1166 | { |
---|
| 1167 | /* statistic */ |
---|
| 1168 | if (TEST_OPT_PROT) |
---|
| 1169 | { |
---|
| 1170 | PrintS("s\n"); |
---|
| 1171 | } |
---|
| 1172 | /* enter P.p into s and L */ |
---|
| 1173 | { |
---|
| 1174 | strat->P.sev=0; |
---|
| 1175 | int pos=posInS(strat,strat->sl,strat->P.p, strat->P.ecart); |
---|
| 1176 | { |
---|
| 1177 | if (TEST_OPT_INTSTRATEGY) |
---|
| 1178 | { |
---|
| 1179 | if ((strat->syzComp==0)||(!strat->homog)) |
---|
| 1180 | { |
---|
| 1181 | strat->P.p = redtailBba(strat->P.p,pos-1,strat); |
---|
| 1182 | } |
---|
| 1183 | pCleardenom(strat->P.p); |
---|
| 1184 | } |
---|
| 1185 | else |
---|
| 1186 | { |
---|
| 1187 | pNorm(strat->P.p); |
---|
| 1188 | if ((strat->syzComp==0)||(!strat->homog)) |
---|
| 1189 | { |
---|
| 1190 | strat->P.p = redtailBba(strat->P.p,pos-1,strat); |
---|
| 1191 | } |
---|
| 1192 | } |
---|
| 1193 | // PLURAL debug |
---|
| 1194 | /* should be used only internally!!! */ |
---|
| 1195 | |
---|
| 1196 | //pWrite(strat->P.p); |
---|
| 1197 | |
---|
| 1198 | if (TEST_OPT_DEBUG) |
---|
| 1199 | { |
---|
[52e2f6] | 1200 | PrintS("new s:"); wrp(strat->P.p); |
---|
[35aab3] | 1201 | PrintLn(); |
---|
[52e2f6] | 1202 | #if MYTEST |
---|
| 1203 | Print("s: "); pWrite(strat->P.p); |
---|
| 1204 | #endif |
---|
[737e25] | 1205 | |
---|
[35aab3] | 1206 | } |
---|
| 1207 | // kTest(strat); |
---|
| 1208 | // |
---|
| 1209 | enterpairs(strat->P.p,strat->sl,strat->P.ecart,pos,strat); |
---|
[737e25] | 1210 | |
---|
[35aab3] | 1211 | if (strat->sl==-1) pos=0; |
---|
| 1212 | else pos=posInS(strat,strat->sl,strat->P.p,strat->P.ecart); |
---|
[737e25] | 1213 | |
---|
[b130fb] | 1214 | strat->enterS(strat->P,pos,strat,-1); |
---|
[35aab3] | 1215 | } |
---|
[86016d] | 1216 | // if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat); |
---|
[35aab3] | 1217 | } |
---|
| 1218 | if (strat->P.lcm!=NULL) pLmFree(strat->P.lcm); |
---|
| 1219 | if (strat->sl>srmax) srmax = strat->sl; |
---|
| 1220 | } |
---|
| 1221 | #ifdef KDEBUG |
---|
| 1222 | strat->P.lcm=NULL; |
---|
| 1223 | #endif |
---|
[626431] | 1224 | //kTest(strat); |
---|
[35aab3] | 1225 | } |
---|
| 1226 | if (TEST_OPT_DEBUG) messageSets(strat); |
---|
[86016d] | 1227 | |
---|
[35aab3] | 1228 | /* complete reduction of the standard basis--------- */ |
---|
[07b1cf] | 1229 | if (TEST_OPT_SB_1) |
---|
| 1230 | { |
---|
| 1231 | int k=1; |
---|
| 1232 | int j; |
---|
| 1233 | while(k<=strat->sl) |
---|
| 1234 | { |
---|
| 1235 | j=0; |
---|
| 1236 | loop |
---|
| 1237 | { |
---|
| 1238 | if (j>=k) break; |
---|
| 1239 | clearS(strat->S[j],strat->sevS[j],&k,&j,strat); |
---|
| 1240 | j++; |
---|
| 1241 | } |
---|
| 1242 | k++; |
---|
| 1243 | } |
---|
[86016d] | 1244 | } |
---|
| 1245 | |
---|
[07b1cf] | 1246 | if (TEST_OPT_REDSB) |
---|
| 1247 | completeReduce(strat); |
---|
[35aab3] | 1248 | /* release temp data-------------------------------- */ |
---|
| 1249 | exitBuchMora(strat); |
---|
| 1250 | if (TEST_OPT_WEIGHTM) |
---|
| 1251 | { |
---|
| 1252 | pFDeg=pFDegOld; |
---|
| 1253 | pLDeg=pLDegOld; |
---|
| 1254 | if (ecartWeights) |
---|
| 1255 | { |
---|
| 1256 | omFreeSize((ADDRESS)ecartWeights,(pVariables+1)*sizeof(short)); |
---|
| 1257 | ecartWeights=NULL; |
---|
| 1258 | } |
---|
| 1259 | } |
---|
| 1260 | if (TEST_OPT_PROT) messageStat(srmax,lrmax,hilbcount,strat); |
---|
| 1261 | if (Q!=NULL) updateResult(strat->Shdl,Q,strat); |
---|
[86016d] | 1262 | |
---|
| 1263 | |
---|
[e38e91] | 1264 | #ifdef PDEBUG |
---|
| 1265 | /* for counting number of pairs [enterL] in Plural */ |
---|
| 1266 | /* extern int zaehler; */ |
---|
| 1267 | /* Print("Total pairs considered:%d\n",zaehler); zaehler=0; */ |
---|
[7447d8] | 1268 | #endif /*PDEBUG*/ |
---|
[52e2f6] | 1269 | |
---|
| 1270 | #if MYTEST |
---|
| 1271 | PrintS("</gnc_gr_bba>\n"); |
---|
| 1272 | #endif |
---|
| 1273 | |
---|
[35aab3] | 1274 | return (strat->Shdl); |
---|
| 1275 | } |
---|
[5a9e7b] | 1276 | |
---|
| 1277 | ideal gnc_gr_mora(const ideal, const ideal, const intvec *, const intvec *, kStrategy) |
---|
| 1278 | { |
---|
| 1279 | PrintS("Sorry, non-commutative mora is not yet implemented!"); |
---|
| 1280 | PrintLn(); |
---|
| 1281 | |
---|
| 1282 | // Not yet! |
---|
| 1283 | return NULL; |
---|
| 1284 | } |
---|
| 1285 | |
---|
[f2f460] | 1286 | #endif |
---|
[5a9e7b] | 1287 | |
---|