[0e1846] | 1 | /**************************************** |
---|
| 2 | * Computer Algebra System SINGULAR * |
---|
| 3 | ****************************************/ |
---|
[734b9a] | 4 | /* $Id: kstd2.cc,v 1.42 2000-03-31 12:15:01 Singular Exp $ */ |
---|
[0e1846] | 5 | /* |
---|
| 6 | * ABSTRACT - Kernel: alg. of Buchberger |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | #include "mod2.h" |
---|
[ca7a56] | 10 | #include "tok.h" |
---|
[0e1846] | 11 | #include "mmemory.h" |
---|
| 12 | #include "polys.h" |
---|
| 13 | #include "ideals.h" |
---|
| 14 | #include "febase.h" |
---|
| 15 | #include "kutil.h" |
---|
| 16 | #include "kstd1.h" |
---|
| 17 | #include "khstd.h" |
---|
| 18 | #include "cntrlc.h" |
---|
| 19 | #include "weight.h" |
---|
| 20 | #include "ipid.h" |
---|
| 21 | #include "ipshell.h" |
---|
| 22 | #include "intvec.h" |
---|
[51c163] | 23 | |
---|
[64ced6] | 24 | // #include "timer.h" |
---|
[0e1846] | 25 | |
---|
| 26 | /*2 |
---|
| 27 | * consider the part above syzComp: |
---|
| 28 | * (assume the polynomial comes from a syz computation) |
---|
| 29 | * - it is a constant term: return a copy of it |
---|
| 30 | * - else: return NULL |
---|
| 31 | */ |
---|
| 32 | static poly kFromInput(poly p,kStrategy strat) |
---|
| 33 | { |
---|
| 34 | poly q=p; |
---|
| 35 | |
---|
| 36 | if (pGetComp(q)>strat->syzComp) return NULL; |
---|
| 37 | while ((q!=NULL) && (pGetComp(q)<=strat->syzComp)) pIter(q); |
---|
| 38 | if (pIsConstantComp(q)) |
---|
| 39 | return pHead(q); |
---|
| 40 | return NULL; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | /*2 |
---|
| 44 | * reduction procedure for the homogeneous case |
---|
| 45 | * and the case of a degree-ordering |
---|
| 46 | */ |
---|
[942846] | 47 | static int redHomog (LObject* h,kStrategy strat) |
---|
[0e1846] | 48 | { |
---|
[942846] | 49 | if (strat->tl<0) return 1; |
---|
[51c163] | 50 | #ifdef KDEBUG |
---|
[7d423e] | 51 | if (TEST_OPT_DEBUG) |
---|
| 52 | { |
---|
| 53 | PrintS("red:"); |
---|
| 54 | wrp(h->p); |
---|
| 55 | PrintS(" "); |
---|
[51c163] | 56 | } |
---|
[7d423e] | 57 | #endif |
---|
| 58 | int j; |
---|
[b7b08c] | 59 | unsigned long not_sev; |
---|
[7d423e] | 60 | while (1) |
---|
[51c163] | 61 | { |
---|
[7d423e] | 62 | j = 0; |
---|
[b7b08c] | 63 | h->sev = pGetShortExpVector(h->p); |
---|
| 64 | not_sev = ~ h->sev; |
---|
[7d423e] | 65 | while ( j <= strat->tl) |
---|
| 66 | { |
---|
[b7b08c] | 67 | if (pShortDivisibleBy(strat->T[j].p, strat->T[j].sev, |
---|
| 68 | h->p, not_sev)) break; |
---|
[7d423e] | 69 | j++; |
---|
| 70 | } |
---|
[0d3f08] | 71 | |
---|
[942846] | 72 | if (j > strat->tl) return 1; |
---|
[0e1846] | 73 | |
---|
[7d423e] | 74 | // now we found one which is divisible |
---|
[e56c23] | 75 | ksReducePoly(h, &(strat->T[j]), strat->kNoether); |
---|
[51c163] | 76 | #ifdef KDEBUG |
---|
[7d423e] | 77 | if (TEST_OPT_DEBUG) |
---|
| 78 | { |
---|
| 79 | PrintS("\nto "); |
---|
| 80 | wrp(h->p); |
---|
| 81 | PrintLn(); |
---|
| 82 | } |
---|
[51c163] | 83 | #endif |
---|
[7d423e] | 84 | if (h->p == NULL) |
---|
| 85 | { |
---|
| 86 | if (h->lcm!=NULL) pFree1((*h).lcm); |
---|
[51c163] | 87 | #ifdef KDEBUG |
---|
[7d423e] | 88 | (*h).lcm=NULL; |
---|
[51c163] | 89 | #endif |
---|
[942846] | 90 | return 0; |
---|
[7d423e] | 91 | } |
---|
[0e1846] | 92 | } |
---|
| 93 | } |
---|
| 94 | |
---|
[51c163] | 95 | |
---|
[0e1846] | 96 | /*2 |
---|
| 97 | * reduction procedure for the inhomogeneous case |
---|
| 98 | * and not a degree-ordering |
---|
| 99 | */ |
---|
[942846] | 100 | static int redLazy (LObject* h,kStrategy strat) |
---|
[0e1846] | 101 | { |
---|
[942846] | 102 | if (strat->tl<0) return 1; |
---|
[0e1846] | 103 | int at,d,i; |
---|
| 104 | int j = 0; |
---|
| 105 | int pass = 0; |
---|
| 106 | int reddeg = pFDeg((*h).p); |
---|
[b7b08c] | 107 | int not_sev; |
---|
[0e1846] | 108 | |
---|
[b7b08c] | 109 | h->sev = pGetShortExpVector(h->p); |
---|
| 110 | not_sev = ~ h->sev; |
---|
[7d423e] | 111 | while (1) |
---|
[0e1846] | 112 | { |
---|
[7d423e] | 113 | j = 0; |
---|
| 114 | while (j <= strat->tl) |
---|
[0e1846] | 115 | { |
---|
[b7b08c] | 116 | if (pShortDivisibleBy(strat->T[j].p,strat->T[j].sev, |
---|
| 117 | h->p, not_sev)) |
---|
| 118 | break; |
---|
[7d423e] | 119 | j++; |
---|
| 120 | } |
---|
[0d3f08] | 121 | |
---|
[942846] | 122 | if (j>strat->tl) return 1; |
---|
[7d423e] | 123 | |
---|
| 124 | if (TEST_OPT_DEBUG) |
---|
| 125 | { |
---|
| 126 | PrintS("red:"); |
---|
| 127 | wrp(h->p); |
---|
| 128 | PrintS(" with "); |
---|
| 129 | wrp(strat->T[j].p); |
---|
| 130 | } |
---|
[942846] | 131 | |
---|
[d14712] | 132 | ksReducePoly(h, &(strat->T[j]), strat->kNoether); |
---|
[942846] | 133 | |
---|
[7d423e] | 134 | if (TEST_OPT_DEBUG) |
---|
| 135 | { |
---|
| 136 | PrintS("\nto "); |
---|
| 137 | wrp(h->p); |
---|
| 138 | PrintLn(); |
---|
| 139 | } |
---|
[942846] | 140 | |
---|
[7d423e] | 141 | if ((*h).p == NULL) |
---|
| 142 | { |
---|
| 143 | if (h->lcm!=NULL) pFree1((*h).lcm); |
---|
[0e1846] | 144 | #ifdef KDEBUG |
---|
[7d423e] | 145 | (*h).lcm=NULL; |
---|
[0e1846] | 146 | #endif |
---|
[942846] | 147 | return 0; |
---|
[7d423e] | 148 | } |
---|
[b7b08c] | 149 | h->sev = pGetShortExpVector(h->p); |
---|
| 150 | not_sev = ~ h->sev; |
---|
[7d423e] | 151 | /*- try to reduce the s-polynomial -*/ |
---|
| 152 | pass++; |
---|
| 153 | d = pFDeg((*h).p); |
---|
| 154 | if ((strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass))) |
---|
| 155 | { |
---|
| 156 | at = posInL11(strat->L,strat->Ll,*h,strat); |
---|
| 157 | if (at <= strat->Ll) |
---|
[0e1846] | 158 | { |
---|
[7d423e] | 159 | i=strat->sl+1; |
---|
| 160 | do |
---|
[0e1846] | 161 | { |
---|
[7d423e] | 162 | i--; |
---|
[942846] | 163 | if (i<0) return 1; |
---|
[0e1846] | 164 | } |
---|
[b7b08c] | 165 | while (!pShortDivisibleBy(strat->S[i], strat->sevS[i], |
---|
| 166 | h->p, not_sev)); |
---|
[7d423e] | 167 | if (TEST_OPT_DEBUG) Print(" ->L[%d]\n",at); |
---|
| 168 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
| 169 | (*h).p = NULL; |
---|
[942846] | 170 | return -1; |
---|
[0e1846] | 171 | } |
---|
| 172 | } |
---|
[7d423e] | 173 | else if ((TEST_OPT_PROT) && (strat->Ll < 0) && (d != reddeg)) |
---|
[0e1846] | 174 | { |
---|
[7d423e] | 175 | Print(".%d",d);mflush(); |
---|
| 176 | reddeg = d; |
---|
[0e1846] | 177 | } |
---|
| 178 | } |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | /*2 |
---|
| 182 | * reduction procedure for the sugar-strategy (honey) |
---|
| 183 | * reduces h with elements from T choosing first possible |
---|
| 184 | * element in T with respect to the given ecart |
---|
| 185 | */ |
---|
[942846] | 186 | static int redHoney (LObject* h,kStrategy strat) |
---|
[0e1846] | 187 | { |
---|
[942846] | 188 | if (strat->tl<0) return 1; |
---|
[0e1846] | 189 | |
---|
| 190 | poly pi; |
---|
[7d423e] | 191 | int i,j,at,reddeg,d,pass,ei, ii; |
---|
[b7b08c] | 192 | unsigned long not_sev; |
---|
[0e1846] | 193 | |
---|
| 194 | pass = j = 0; |
---|
| 195 | d = reddeg = pFDeg((*h).p)+(*h).ecart; |
---|
[b7b08c] | 196 | h->sev = pGetShortExpVector(h->p); |
---|
| 197 | not_sev = ~ h->sev; |
---|
[0d3f08] | 198 | loop |
---|
[0e1846] | 199 | { |
---|
[7d423e] | 200 | j = 0; |
---|
| 201 | while (j<= strat->tl) |
---|
[0e1846] | 202 | { |
---|
[b7b08c] | 203 | if (pShortDivisibleBy(strat->T[j].p, strat->T[j].sev, |
---|
| 204 | h->p, not_sev)) break; |
---|
[7d423e] | 205 | j++; |
---|
| 206 | } |
---|
[0d3f08] | 207 | |
---|
[7d423e] | 208 | if (j > strat->tl) |
---|
| 209 | { |
---|
[b7b08c] | 210 | h->sev = ~ not_sev; |
---|
[942846] | 211 | return 1; |
---|
[7d423e] | 212 | } |
---|
[0d3f08] | 213 | |
---|
[7d423e] | 214 | pi = strat->T[j].p; |
---|
| 215 | ei = strat->T[j].ecart; |
---|
| 216 | ii = j; |
---|
| 217 | /* |
---|
| 218 | * the polynomial to reduce with (up to the moment) is; |
---|
| 219 | * pi with ecart ei |
---|
| 220 | */ |
---|
| 221 | i = j; |
---|
[0d3f08] | 222 | loop |
---|
[7d423e] | 223 | { |
---|
| 224 | /*- takes the first possible with respect to ecart -*/ |
---|
| 225 | i++; |
---|
| 226 | if (i > strat->tl) |
---|
| 227 | break; |
---|
[734b9a] | 228 | if ((!TEST_OPT_REDBEST) && (ei <= (*h).ecart)) |
---|
[7d423e] | 229 | break; |
---|
[b7b08c] | 230 | if ((strat->T[i].ecart < ei) && |
---|
| 231 | pShortDivisibleBy(strat->T[i].p, strat->T[i].sev, |
---|
| 232 | h->p, not_sev)) |
---|
[0e1846] | 233 | { |
---|
| 234 | /* |
---|
[7d423e] | 235 | * the polynomial to reduce with is now; |
---|
| 236 | */ |
---|
| 237 | pi = strat->T[i].p; |
---|
| 238 | ei = strat->T[i].ecart; |
---|
| 239 | ii = i; |
---|
[0e1846] | 240 | } |
---|
[7d423e] | 241 | } |
---|
| 242 | |
---|
| 243 | /* |
---|
| 244 | * end of search: have to reduce with pi |
---|
| 245 | */ |
---|
| 246 | if ((pass!=0) && (ei > (*h).ecart)) |
---|
| 247 | { |
---|
[0e1846] | 248 | /* |
---|
[7d423e] | 249 | * It is not possible to reduce h with smaller ecart; |
---|
| 250 | * if possible h goes to the lazy-set L,i.e |
---|
| 251 | * if its position in L would be not the last one |
---|
| 252 | */ |
---|
| 253 | if (strat->Ll >= 0) /* L is not empty */ |
---|
[0e1846] | 254 | { |
---|
| 255 | at = strat->posInL(strat->L,strat->Ll,*h,strat); |
---|
[7d423e] | 256 | if(at <= strat->Ll) |
---|
| 257 | /*- h will not become the next element to reduce -*/ |
---|
[0e1846] | 258 | { |
---|
| 259 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
[7d423e] | 260 | if (TEST_OPT_DEBUG) Print(" ecart too big: -> L%d\n",at); |
---|
[0e1846] | 261 | (*h).p = NULL; |
---|
[942846] | 262 | return -1; |
---|
[0e1846] | 263 | } |
---|
| 264 | } |
---|
[7d423e] | 265 | if (TEST_OPT_MOREPAIRS) |
---|
[0e1846] | 266 | { |
---|
[7d423e] | 267 | /*put the polynomial also in the pair set*/ |
---|
| 268 | strat->fromT = TRUE; |
---|
| 269 | if (!TEST_OPT_INTSTRATEGY) pNorm((*h).p); |
---|
| 270 | enterpairs((*h).p,strat->sl,(*h).ecart,0,strat); |
---|
[0e1846] | 271 | } |
---|
| 272 | } |
---|
[7d423e] | 273 | if (TEST_OPT_DEBUG) |
---|
| 274 | { |
---|
| 275 | PrintS("red:"); |
---|
| 276 | wrp(h->p); |
---|
| 277 | PrintS(" with "); |
---|
| 278 | wrp(pi); |
---|
| 279 | } |
---|
| 280 | if (strat->fromT) |
---|
| 281 | { |
---|
| 282 | strat->fromT=FALSE; |
---|
| 283 | h->p = pCopy(h->p); |
---|
| 284 | } |
---|
[d14712] | 285 | ksReducePoly(h, &(strat->T[ii]), strat->kNoether); |
---|
[7d423e] | 286 | if (TEST_OPT_DEBUG) |
---|
| 287 | { |
---|
| 288 | PrintS("\nto "); |
---|
| 289 | wrp(h->p); |
---|
| 290 | PrintLn(); |
---|
| 291 | } |
---|
| 292 | if ((*h).p == NULL) |
---|
| 293 | { |
---|
| 294 | if (h->lcm!=NULL) pFree1((*h).lcm); |
---|
| 295 | #ifdef KDEBUG |
---|
| 296 | (*h).lcm=NULL; |
---|
| 297 | #endif |
---|
[942846] | 298 | return 0; |
---|
[7d423e] | 299 | } |
---|
[b7b08c] | 300 | h->sev = pGetShortExpVector(h->p); |
---|
| 301 | not_sev = ~ h->sev; |
---|
[7d423e] | 302 | /* compute the ecart */ |
---|
| 303 | if (ei <= (*h).ecart) |
---|
| 304 | (*h).ecart = d-pFDeg((*h).p); |
---|
[0e1846] | 305 | else |
---|
[7d423e] | 306 | (*h).ecart = d-pFDeg((*h).p)+ei-(*h).ecart; |
---|
| 307 | /* |
---|
| 308 | * try to reduce the s-polynomial h |
---|
| 309 | *test first whether h should go to the lazyset L |
---|
| 310 | *-if the degree jumps |
---|
| 311 | *-if the number of pre-defined reductions jumps |
---|
| 312 | */ |
---|
| 313 | pass++; |
---|
| 314 | d = pFDeg((*h).p)+(*h).ecart; |
---|
| 315 | if ((strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass))) |
---|
[0e1846] | 316 | { |
---|
[7d423e] | 317 | at = strat->posInL(strat->L,strat->Ll,*h,strat); |
---|
| 318 | if (at <= strat->Ll) |
---|
[0e1846] | 319 | { |
---|
[7d423e] | 320 | /*test if h is already standardbasis element*/ |
---|
| 321 | i=strat->sl+1; |
---|
| 322 | do |
---|
[0e1846] | 323 | { |
---|
[7d423e] | 324 | i--; |
---|
[942846] | 325 | if (i<0) return 1; |
---|
[b7b08c] | 326 | } while (!pShortDivisibleBy(strat->S[i], strat->sevS[i], |
---|
| 327 | h->p, not_sev)); |
---|
[7d423e] | 328 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
| 329 | if (TEST_OPT_DEBUG) |
---|
| 330 | Print(" degree jumped: -> L%d\n",at); |
---|
| 331 | (*h).p = NULL; |
---|
[942846] | 332 | return -1; |
---|
[0e1846] | 333 | } |
---|
[7d423e] | 334 | } |
---|
| 335 | else if (TEST_OPT_PROT && (strat->Ll < 0) && (d > reddeg)) |
---|
| 336 | { |
---|
| 337 | reddeg = d; |
---|
| 338 | Print(".%d",d); mflush(); |
---|
[0e1846] | 339 | } |
---|
| 340 | } |
---|
| 341 | } |
---|
| 342 | |
---|
| 343 | /*2 |
---|
| 344 | * reduction procedure for tests only |
---|
| 345 | * reduces with elements from T and chooses the best possible |
---|
| 346 | */ |
---|
[942846] | 347 | static int redBest (LObject* h,kStrategy strat) |
---|
[0e1846] | 348 | { |
---|
[942846] | 349 | if (strat->tl<0) return 1; |
---|
[0e1846] | 350 | int j,jbest,at,reddeg,d,pass; |
---|
| 351 | poly p,ph; |
---|
| 352 | pass = j = 0; |
---|
| 353 | |
---|
| 354 | if (strat->honey) |
---|
| 355 | reddeg = pFDeg((*h).p)+(*h).ecart; |
---|
| 356 | else |
---|
| 357 | reddeg = pFDeg((*h).p); |
---|
| 358 | loop |
---|
| 359 | { |
---|
| 360 | if (pDivisibleBy(strat->T[j].p,(*h).p)) |
---|
| 361 | { |
---|
[c3c413] | 362 | //if (strat->interpt) test_int_std(strat->kIdeal); |
---|
[0e1846] | 363 | /* compute the s-polynomial */ |
---|
| 364 | if (!TEST_OPT_INTSTRATEGY) pNorm((*h).p); |
---|
[d14712] | 365 | p = ksCreateShortSpoly(strat->T[j].p,(*h).p); |
---|
[0e1846] | 366 | /* computes only the first monomial of the spoly */ |
---|
| 367 | if (p) |
---|
| 368 | { |
---|
| 369 | jbest = j; |
---|
| 370 | /* looking for the best possible reduction */ |
---|
| 371 | if ((strat->syzComp==0) || (pMinComp(p) <= strat->syzComp)) |
---|
| 372 | { |
---|
| 373 | loop |
---|
| 374 | { |
---|
| 375 | j++; |
---|
| 376 | if (j > strat->tl) |
---|
| 377 | break; |
---|
| 378 | if (pDivisibleBy(strat->T[j].p,(*h).p)) |
---|
| 379 | { |
---|
[d14712] | 380 | ph = ksCreateShortSpoly(strat->T[j].p,(*h).p); |
---|
[0e1846] | 381 | if (ph==NULL) |
---|
| 382 | { |
---|
| 383 | pFree1(p); |
---|
| 384 | pDelete(&((*h).p)); |
---|
| 385 | if (h->lcm!=NULL) pFree1((*h).lcm); |
---|
| 386 | #ifdef KDEBUG |
---|
| 387 | (*h).lcm=NULL; |
---|
| 388 | #endif |
---|
[942846] | 389 | return 0; |
---|
[0e1846] | 390 | } |
---|
| 391 | else if (pComp0(ph,p) == -1) |
---|
| 392 | { |
---|
| 393 | pFree1(p); |
---|
| 394 | p = ph; |
---|
| 395 | jbest = j; |
---|
| 396 | } |
---|
| 397 | else |
---|
| 398 | { |
---|
| 399 | pFree1(ph); |
---|
| 400 | } |
---|
| 401 | } |
---|
| 402 | } |
---|
| 403 | } |
---|
| 404 | pFree1(p); |
---|
[d14712] | 405 | (*h).p = ksOldSpolyRed(strat->T[jbest].p,(*h).p,strat->kNoether); |
---|
[0e1846] | 406 | } |
---|
| 407 | else |
---|
| 408 | { |
---|
| 409 | if (h->lcm!=NULL) pFree1((*h).lcm); |
---|
| 410 | #ifdef KDEBUG |
---|
| 411 | (*h).lcm=NULL; |
---|
| 412 | #endif |
---|
| 413 | (*h).p = NULL; |
---|
[942846] | 414 | return 0; |
---|
[0e1846] | 415 | } |
---|
| 416 | if (strat->honey && pLexOrder) |
---|
| 417 | strat->initEcart(h); |
---|
| 418 | if (strat->honey || pLexOrder) |
---|
| 419 | { |
---|
| 420 | pass++; |
---|
| 421 | d = pFDeg((*h).p); |
---|
| 422 | if (strat->honey) |
---|
| 423 | d += (*h).ecart; |
---|
| 424 | if ((strat->Ll >= 0) && ((pass > strat->LazyPass) || (d > reddeg))) |
---|
| 425 | { |
---|
| 426 | at = strat->posInL(strat->L,strat->Ll,*h,strat); |
---|
| 427 | if (at <= strat->Ll) |
---|
| 428 | { |
---|
| 429 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
| 430 | (*h).p = NULL; |
---|
[942846] | 431 | return -1; |
---|
[0e1846] | 432 | } |
---|
| 433 | } |
---|
| 434 | else if (TEST_OPT_PROT && (strat->Ll < 0) && (d != reddeg)) |
---|
| 435 | { |
---|
| 436 | reddeg = d; |
---|
| 437 | Print("%d."); |
---|
| 438 | mflush(); |
---|
| 439 | } |
---|
| 440 | } |
---|
| 441 | j = 0; |
---|
| 442 | } |
---|
| 443 | else |
---|
| 444 | { |
---|
[942846] | 445 | if (j >= strat->tl) return 1; |
---|
[0e1846] | 446 | j++; |
---|
| 447 | } |
---|
| 448 | } |
---|
| 449 | } |
---|
| 450 | |
---|
| 451 | /*2 |
---|
| 452 | * reduction procedure for the normal form |
---|
| 453 | */ |
---|
| 454 | |
---|
| 455 | static poly redNF (poly h,kStrategy strat) |
---|
| 456 | { |
---|
| 457 | int j = 0; |
---|
| 458 | int z = 3; |
---|
[b7b08c] | 459 | unsigned long not_sev; |
---|
[0e1846] | 460 | |
---|
[5528c4] | 461 | if (0 > strat->sl) |
---|
[0e1846] | 462 | { |
---|
| 463 | return h; |
---|
| 464 | } |
---|
[b7b08c] | 465 | not_sev = ~ pGetShortExpVector(h); |
---|
[0e1846] | 466 | loop |
---|
| 467 | { |
---|
[b7b08c] | 468 | if (pShortDivisibleBy(strat->S[j], strat->sevS[j], h, not_sev)) |
---|
[0e1846] | 469 | { |
---|
[c3c413] | 470 | //if (strat->interpt) test_int_std(strat->kIdeal); |
---|
[0e1846] | 471 | /*- compute the s-polynomial -*/ |
---|
| 472 | if (TEST_OPT_DEBUG) |
---|
| 473 | { |
---|
[743c32] | 474 | PrintS("red:"); |
---|
| 475 | wrp(h); |
---|
| 476 | PrintS(" with "); |
---|
| 477 | wrp(strat->S[j]); |
---|
[0e1846] | 478 | } |
---|
[d14712] | 479 | h = ksOldSpolyRed(strat->S[j],h,strat->kNoether); |
---|
[0e1846] | 480 | if (TEST_OPT_DEBUG) |
---|
| 481 | { |
---|
| 482 | PrintS("\nto:"); |
---|
| 483 | wrp(h); |
---|
[7b4121] | 484 | PrintLn(); |
---|
[0e1846] | 485 | } |
---|
| 486 | if (h == NULL) return NULL; |
---|
| 487 | z++; |
---|
| 488 | if (z>=10) |
---|
| 489 | { |
---|
| 490 | z=0; |
---|
| 491 | pNormalize(h); |
---|
| 492 | } |
---|
| 493 | /*- try to reduce the s-polynomial -*/ |
---|
| 494 | j = 0; |
---|
[b7b08c] | 495 | not_sev = ~ pGetShortExpVector(h); |
---|
[0e1846] | 496 | } |
---|
| 497 | else |
---|
| 498 | { |
---|
| 499 | if (j >= strat->sl) return h; |
---|
| 500 | j++; |
---|
| 501 | } |
---|
| 502 | } |
---|
| 503 | } |
---|
| 504 | |
---|
| 505 | void initBba(ideal F,kStrategy strat) |
---|
| 506 | { |
---|
| 507 | int i; |
---|
| 508 | idhdl h; |
---|
| 509 | /* setting global variables ------------------- */ |
---|
| 510 | strat->enterS = enterSBba; |
---|
[734b9a] | 511 | if ((TEST_OPT_REDBEST) && (!strat->honey)) |
---|
[0e1846] | 512 | strat->red = redBest; |
---|
| 513 | else if (strat->honey) |
---|
| 514 | strat->red = redHoney; |
---|
| 515 | else if (pLexOrder && !strat->homog) |
---|
| 516 | strat->red = redLazy; |
---|
| 517 | else |
---|
| 518 | strat->red = redHomog; |
---|
| 519 | if (pLexOrder && strat->honey) |
---|
| 520 | strat->initEcart = initEcartNormal; |
---|
| 521 | else |
---|
| 522 | strat->initEcart = initEcartBBA; |
---|
| 523 | if (strat->honey) |
---|
| 524 | strat->initEcartPair = initEcartPairMora; |
---|
| 525 | else |
---|
| 526 | strat->initEcartPair = initEcartPairBba; |
---|
| 527 | strat->kIdeal = NULL; |
---|
| 528 | //if (strat->ak==0) strat->kIdeal->rtyp=IDEAL_CMD; |
---|
| 529 | //else strat->kIdeal->rtyp=MODUL_CMD; |
---|
| 530 | //strat->kIdeal->data=(void *)strat->Shdl; |
---|
| 531 | if ((TEST_OPT_WEIGHTM)&&(F!=NULL)) |
---|
| 532 | { |
---|
| 533 | //interred machen Aenderung |
---|
| 534 | pFDegOld=pFDeg; |
---|
| 535 | pLDegOld=pLDeg; |
---|
| 536 | h=ggetid("ecart"); |
---|
| 537 | if ((h!=NULL) && (IDTYP(h)==INTVEC_CMD)) |
---|
| 538 | { |
---|
| 539 | ecartWeights=iv2array(IDINTVEC(h)); |
---|
| 540 | } |
---|
| 541 | else |
---|
| 542 | { |
---|
| 543 | ecartWeights=(short *)Alloc((pVariables+1)*sizeof(short)); |
---|
| 544 | /*uses automatic computation of the ecartWeights to set them*/ |
---|
| 545 | kEcartWeights(F->m,IDELEMS(F)-1,ecartWeights); |
---|
| 546 | } |
---|
| 547 | pFDeg=totaldegreeWecart; |
---|
| 548 | pLDeg=maxdegreeWecart; |
---|
| 549 | for(i=1; i<=pVariables; i++) |
---|
| 550 | Print(" %d",ecartWeights[i]); |
---|
| 551 | PrintLn(); |
---|
| 552 | mflush(); |
---|
| 553 | } |
---|
| 554 | } |
---|
| 555 | |
---|
[942846] | 556 | void kinitBbaHeaps(kStrategy heap) |
---|
| 557 | { |
---|
| 558 | #if 0 |
---|
| 559 | // use extra heap for monoms of T, if not syzcomp |
---|
| 560 | if (!strat->red == redSyz) |
---|
| 561 | { |
---|
| 562 | strat->THeap = mmCreateTempHeap(); |
---|
| 563 | } |
---|
| 564 | #endif |
---|
| 565 | } |
---|
| 566 | |
---|
[0e1846] | 567 | ideal bba (ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat) |
---|
| 568 | { |
---|
[942846] | 569 | int srmax,lrmax, red_result; |
---|
[0e1846] | 570 | int olddeg,reduc; |
---|
| 571 | int hilbeledeg=1,hilbcount=0,minimcnt=0; |
---|
| 572 | |
---|
| 573 | initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/ |
---|
[09d74fe] | 574 | initBuchMoraPos(strat); |
---|
[0e1846] | 575 | initHilbCrit(F,Q,&hilb,strat); |
---|
| 576 | initBba(F,strat); |
---|
| 577 | /*set enterS, spSpolyShort, reduce, red, initEcart, initEcartPair*/ |
---|
| 578 | /*Shdl=*/initBuchMora(F, Q,strat); |
---|
[942846] | 579 | if (strat->minim>0) strat->M=idInit(IDELEMS(F),F->rank); |
---|
| 580 | kinitBbaHeaps(strat); |
---|
[0e1846] | 581 | srmax = strat->sl; |
---|
| 582 | reduc = olddeg = lrmax = 0; |
---|
| 583 | /* compute------------------------------------------------------- */ |
---|
[6f1610] | 584 | kTest_TS(strat); |
---|
[0e1846] | 585 | while (strat->Ll >= 0) |
---|
| 586 | { |
---|
| 587 | if (strat->Ll > lrmax) lrmax =strat->Ll;/*stat.*/ |
---|
| 588 | if (TEST_OPT_DEBUG) messageSets(strat); |
---|
| 589 | if (strat->Ll== 0) strat->interpt=TRUE; |
---|
| 590 | if (TEST_OPT_DEGBOUND |
---|
[e56c23] | 591 | && ((strat->honey && (strat->L[strat->Ll].ecart+pFDeg(strat->L[strat->Ll].p)>Kstd1_deg)) |
---|
| 592 | || ((!strat->honey) && (pFDeg(strat->L[strat->Ll].p)>Kstd1_deg)))) |
---|
[0e1846] | 593 | { |
---|
| 594 | /* |
---|
[e56c23] | 595 | *stops computation if |
---|
| 596 | * 24 IN test and the degree +ecart of L[strat->Ll] is bigger then |
---|
| 597 | *a predefined number Kstd1_deg |
---|
| 598 | */ |
---|
[0e1846] | 599 | while (strat->Ll >= 0) deleteInL(strat->L,&strat->Ll,strat->Ll,strat); |
---|
| 600 | break; |
---|
| 601 | } |
---|
| 602 | /* picks the last element from the lazyset L */ |
---|
| 603 | strat->P = strat->L[strat->Ll]; |
---|
| 604 | strat->Ll--; |
---|
[942846] | 605 | |
---|
[0e1846] | 606 | if (pNext(strat->P.p) == strat->tail) |
---|
| 607 | { |
---|
| 608 | /* deletes the short spoly and computes */ |
---|
| 609 | pFree1(strat->P.p); |
---|
| 610 | /* the real one */ |
---|
[d14712] | 611 | ksCreateSpoly(&(strat->P), |
---|
[7d423e] | 612 | strat->kNoether); |
---|
[0e1846] | 613 | } |
---|
[942846] | 614 | if((strat->P.p1==NULL) && (strat->minim>0)) strat->P.p2=pCopy(strat->P.p); |
---|
| 615 | |
---|
| 616 | if (TEST_OPT_PROT) |
---|
| 617 | message((strat->honey ? strat->P.ecart : 0) + pFDeg(strat->P.p), |
---|
| 618 | &olddeg,&reduc,strat); |
---|
| 619 | |
---|
[6f1610] | 620 | kTest_TS(strat); |
---|
[e56c23] | 621 | /* reduction of the element choosen from L */ |
---|
[942846] | 622 | red_result = strat->red(&strat->P,strat); |
---|
| 623 | |
---|
| 624 | // reduktion to non-zero new poly |
---|
| 625 | if (red_result == 1) |
---|
[0e1846] | 626 | { |
---|
[6f1610] | 627 | kTest_TS(strat); |
---|
[e56c23] | 628 | /* statistic */ |
---|
| 629 | if (TEST_OPT_PROT) PrintS("s"); |
---|
| 630 | /* enter P.p into s and L */ |
---|
| 631 | { |
---|
| 632 | int pos=posInS(strat->S,strat->sl,strat->P.p); |
---|
[942846] | 633 | if (TEST_OPT_INTSTRATEGY) |
---|
[e56c23] | 634 | { |
---|
[942846] | 635 | pCleardenom(strat->P.p); |
---|
[fc4782a] | 636 | if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL)) |
---|
| 637 | { |
---|
| 638 | strat->P.p = redtailBba(strat->P.p,pos-1,strat); |
---|
| 639 | pCleardenom(strat->P.p); |
---|
| 640 | } |
---|
[942846] | 641 | } |
---|
| 642 | else |
---|
| 643 | { |
---|
| 644 | pNorm(strat->P.p); |
---|
[fc4782a] | 645 | if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL)) |
---|
| 646 | strat->P.p = redtailBba(strat->P.p,pos-1,strat); |
---|
[942846] | 647 | } |
---|
| 648 | |
---|
| 649 | if (TEST_OPT_DEBUG){PrintS("new s:");wrp(strat->P.p);PrintLn();} |
---|
| 650 | |
---|
| 651 | if ((strat->P.p1==NULL) && (strat->minim>0)) |
---|
| 652 | { |
---|
| 653 | if (strat->minim==1) |
---|
[e56c23] | 654 | { |
---|
[942846] | 655 | strat->M->m[minimcnt]=pCopy(strat->P.p); |
---|
| 656 | pDelete(&strat->P.p2); |
---|
[e56c23] | 657 | } |
---|
[942846] | 658 | else |
---|
[e56c23] | 659 | { |
---|
[942846] | 660 | strat->M->m[minimcnt]=strat->P.p2; |
---|
| 661 | strat->P.p2=NULL; |
---|
[e56c23] | 662 | } |
---|
[942846] | 663 | minimcnt++; |
---|
[e56c23] | 664 | } |
---|
[942846] | 665 | |
---|
| 666 | // put stuff into T-Set |
---|
| 667 | enterTBba(strat->P, strat->posInT(strat->T,strat->tl,strat->P), |
---|
| 668 | strat); |
---|
| 669 | enterpairs(strat->P.p,strat->sl,strat->P.ecart,pos,strat); |
---|
[c1489f2] | 670 | // posInS only depends only onthe leading term |
---|
| 671 | strat->enterS(strat->P, pos, strat); |
---|
[e56c23] | 672 | if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat); |
---|
| 673 | } |
---|
| 674 | if (strat->P.lcm!=NULL) pFree1(strat->P.lcm); |
---|
[0e1846] | 675 | if (strat->sl>srmax) srmax = strat->sl; |
---|
| 676 | } |
---|
| 677 | #ifdef KDEBUG |
---|
| 678 | strat->P.lcm=NULL; |
---|
| 679 | #endif |
---|
[7d423e] | 680 | kTest_TS(strat); |
---|
[0e1846] | 681 | } |
---|
| 682 | if (TEST_OPT_DEBUG) messageSets(strat); |
---|
| 683 | /* complete reduction of the standard basis--------- */ |
---|
| 684 | if (TEST_OPT_REDSB) completeReduce(strat); |
---|
| 685 | /* release temp data-------------------------------- */ |
---|
| 686 | exitBuchMora(strat); |
---|
| 687 | if (TEST_OPT_WEIGHTM) |
---|
| 688 | { |
---|
| 689 | pFDeg=pFDegOld; |
---|
| 690 | pLDeg=pLDegOld; |
---|
| 691 | if (ecartWeights) |
---|
| 692 | { |
---|
| 693 | Free((ADDRESS)ecartWeights,(pVariables+1)*sizeof(short)); |
---|
| 694 | ecartWeights=NULL; |
---|
| 695 | } |
---|
| 696 | } |
---|
| 697 | if (TEST_OPT_PROT) messageStat(srmax,lrmax,hilbcount,strat); |
---|
| 698 | if (Q!=NULL) updateResult(strat->Shdl,Q,strat); |
---|
| 699 | return (strat->Shdl); |
---|
| 700 | } |
---|
| 701 | |
---|
| 702 | poly kNF2 (ideal F,ideal Q,poly q,kStrategy strat, int lazyReduce) |
---|
| 703 | { |
---|
| 704 | poly p; |
---|
| 705 | int i; |
---|
| 706 | |
---|
| 707 | if ((idIs0(F))&&(Q==NULL)) |
---|
| 708 | return pCopy(q); /*F=0*/ |
---|
| 709 | strat->ak = idRankFreeModule(F); |
---|
| 710 | /*- creating temp data structures------------------- -*/ |
---|
| 711 | BITSET save_test=test; |
---|
| 712 | test|=Sy_bit(OPT_REDTAIL); |
---|
| 713 | initBuchMoraCrit(strat); |
---|
| 714 | strat->initEcart = initEcartBBA; |
---|
| 715 | strat->enterS = enterSBba; |
---|
| 716 | /*- set S -*/ |
---|
| 717 | strat->sl = -1; |
---|
| 718 | /*- init local data struct.---------------------------------------- -*/ |
---|
| 719 | /*Shdl=*/initS(F,Q,strat); |
---|
| 720 | /*- compute------------------------------------------------------- -*/ |
---|
| 721 | if ((TEST_OPT_INTSTRATEGY)&&(lazyReduce==0)) |
---|
| 722 | { |
---|
| 723 | for (i=strat->sl;i>=0;i--) |
---|
| 724 | pNorm(strat->S[i]); |
---|
| 725 | } |
---|
| 726 | kTest(strat); |
---|
[7b4121] | 727 | if (TEST_OPT_PROT) { PrintS("r"); mflush(); } |
---|
[0e1846] | 728 | p = redNF(pCopy(q),strat); |
---|
| 729 | if ((p!=NULL)&&(lazyReduce==0)) |
---|
| 730 | { |
---|
[7b4121] | 731 | if (TEST_OPT_PROT) { PrintS("t"); mflush(); } |
---|
[0e1846] | 732 | p = redtailBba(p,strat->sl,strat); |
---|
| 733 | } |
---|
| 734 | /*- release temp data------------------------------- -*/ |
---|
[b7b08c] | 735 | if (strat->ecartS != NULL) |
---|
| 736 | Free((ADDRESS)strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int)); |
---|
| 737 | if (strat->sevS != NULL) |
---|
| 738 | Free((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long)); |
---|
[0e1846] | 739 | idDelete(&strat->Shdl); |
---|
| 740 | test=save_test; |
---|
[7b4121] | 741 | if (TEST_OPT_PROT) PrintLn(); |
---|
[0e1846] | 742 | return p; |
---|
| 743 | } |
---|
| 744 | |
---|
| 745 | ideal kNF2 (ideal F,ideal Q,ideal q,kStrategy strat, int lazyReduce) |
---|
| 746 | { |
---|
| 747 | poly p; |
---|
| 748 | int i; |
---|
| 749 | ideal res; |
---|
| 750 | |
---|
| 751 | if (idIs0(q)) |
---|
| 752 | return idInit(1,q->rank); |
---|
| 753 | if ((idIs0(F))&&(Q==NULL)) |
---|
| 754 | return idCopy(q); /*F=0*/ |
---|
| 755 | strat->ak = idRankFreeModule(F); |
---|
| 756 | /*- creating temp data structures------------------- -*/ |
---|
| 757 | BITSET save_test=test; |
---|
| 758 | test|=Sy_bit(OPT_REDTAIL); |
---|
| 759 | initBuchMoraCrit(strat); |
---|
| 760 | strat->initEcart = initEcartBBA; |
---|
| 761 | strat->enterS = enterSBba; |
---|
| 762 | /*- set S -*/ |
---|
| 763 | strat->sl = -1; |
---|
| 764 | /*- init local data struct.---------------------------------------- -*/ |
---|
| 765 | /*Shdl=*/initS(F,Q,strat); |
---|
| 766 | /*- compute------------------------------------------------------- -*/ |
---|
| 767 | res=idInit(IDELEMS(q),q->rank); |
---|
| 768 | if ((TEST_OPT_INTSTRATEGY)&&(lazyReduce==0)) |
---|
| 769 | { |
---|
| 770 | for (i=strat->sl;i>=0;i--) |
---|
| 771 | pNorm(strat->S[i]); |
---|
| 772 | } |
---|
| 773 | for (i=IDELEMS(q)-1; i>=0; i--) |
---|
| 774 | { |
---|
| 775 | if (q->m[i]!=NULL) |
---|
| 776 | { |
---|
[7b4121] | 777 | if (TEST_OPT_PROT) { PrintS("r");mflush(); } |
---|
[0e1846] | 778 | p = redNF(pCopy(q->m[i]),strat); |
---|
| 779 | if ((p!=NULL)&&(lazyReduce==0)) |
---|
| 780 | { |
---|
[7b4121] | 781 | if (TEST_OPT_PROT) { PrintS("t"); mflush(); } |
---|
[0e1846] | 782 | p = redtailBba(p,strat->sl,strat); |
---|
| 783 | } |
---|
| 784 | res->m[i]=p; |
---|
| 785 | } |
---|
| 786 | //else |
---|
| 787 | // res->m[i]=NULL; |
---|
| 788 | } |
---|
| 789 | /*- release temp data------------------------------- -*/ |
---|
[b7b08c] | 790 | if (strat->ecartS != NULL) |
---|
| 791 | Free((ADDRESS)strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int)); |
---|
| 792 | if (strat->sevS != NULL) |
---|
| 793 | Free((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long)); |
---|
[0e1846] | 794 | idDelete(&strat->Shdl); |
---|
| 795 | test=save_test; |
---|
[7b4121] | 796 | if (TEST_OPT_PROT) PrintLn(); |
---|
[0e1846] | 797 | return res; |
---|
| 798 | } |
---|
| 799 | |
---|
| 800 | static ideal bbared (ideal F, ideal Q,kStrategy strat) |
---|
| 801 | { |
---|
| 802 | |
---|
| 803 | /* complete reduction of the standard basis--------- */ |
---|
| 804 | completeReduce(strat); |
---|
| 805 | /* release temp data-------------------------------- */ |
---|
| 806 | exitBuchMora(strat); |
---|
| 807 | if (TEST_OPT_WEIGHTM) |
---|
| 808 | { |
---|
| 809 | pFDeg=pFDegOld; |
---|
| 810 | pLDeg=pLDegOld; |
---|
| 811 | if (ecartWeights) |
---|
| 812 | { |
---|
| 813 | Free((ADDRESS)ecartWeights,(pVariables+1)*sizeof(short)); |
---|
| 814 | ecartWeights=NULL; |
---|
| 815 | } |
---|
| 816 | } |
---|
| 817 | if (Q!=NULL) updateResult(strat->Shdl,Q,strat); |
---|
| 818 | return (strat->Shdl); |
---|
| 819 | } |
---|
| 820 | |
---|
| 821 | ideal stdred(ideal F, ideal Q, tHomog h,intvec ** w) |
---|
| 822 | { |
---|
| 823 | ideal r; |
---|
| 824 | BOOLEAN b=pLexOrder,toReset=FALSE; |
---|
| 825 | BOOLEAN delete_w=(w==NULL); |
---|
[b7b08c] | 826 | kStrategy strat=(kStrategy)Alloc0SizeOf(skStrategy); |
---|
[0e1846] | 827 | |
---|
[8a150b] | 828 | if (rField_has_simple_inverse()) |
---|
[be0d84] | 829 | strat->LazyPass=20; |
---|
| 830 | else |
---|
| 831 | strat->LazyPass=2; |
---|
[0e1846] | 832 | strat->LazyDegree = 1; |
---|
[1caa72] | 833 | strat->ak = idRankFreeModule(F); |
---|
[0e1846] | 834 | if ((h==testHomog)) |
---|
| 835 | { |
---|
[f003a9] | 836 | if (strat->ak==0) |
---|
[0e1846] | 837 | { |
---|
| 838 | h = (tHomog)idHomIdeal(F,Q); |
---|
| 839 | w=NULL; |
---|
| 840 | } |
---|
| 841 | else |
---|
| 842 | h = (tHomog)idHomModule(F,Q,w); |
---|
| 843 | } |
---|
| 844 | if (h==isHomog) |
---|
| 845 | { |
---|
| 846 | if ((w!=NULL) && (*w!=NULL)) |
---|
| 847 | { |
---|
| 848 | kModW = *w; |
---|
[f003a9] | 849 | strat->kModW = *w; |
---|
[0e1846] | 850 | pOldFDeg = pFDeg; |
---|
| 851 | pFDeg = kModDeg; |
---|
| 852 | toReset = TRUE; |
---|
| 853 | } |
---|
| 854 | pLexOrder = TRUE; |
---|
| 855 | strat->LazyPass*=2; |
---|
| 856 | } |
---|
| 857 | strat->homog=h; |
---|
| 858 | initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/ |
---|
| 859 | initBuchMoraPos(strat); |
---|
| 860 | if (pOrdSgn==1) |
---|
| 861 | initBba(F,strat); |
---|
| 862 | else |
---|
| 863 | initMora(F,strat); |
---|
| 864 | initBuchMora(F, Q,strat); |
---|
| 865 | //initS(F,Q,strat); |
---|
| 866 | // Ende der Initalisierung |
---|
| 867 | r=bbared(F,Q,strat); |
---|
| 868 | #ifdef KDEBUG |
---|
| 869 | int i; |
---|
| 870 | for (i=0; i<IDELEMS(r); i++) pTest(r->m[i]); |
---|
| 871 | #endif |
---|
| 872 | // Ende: aufraeumen |
---|
| 873 | if (toReset) |
---|
| 874 | { |
---|
| 875 | kModW = NULL; |
---|
| 876 | pFDeg = pOldFDeg; |
---|
| 877 | } |
---|
| 878 | pLexOrder = b; |
---|
[942846] | 879 | kFreeStrat(strat); |
---|
[0e1846] | 880 | if ((delete_w)&&(w!=NULL)&&(*w!=NULL)) delete *w; |
---|
| 881 | idSkipZeroes(r); |
---|
| 882 | return r; |
---|
| 883 | } |
---|