[35aab3] | 1 | /**************************************** |
---|
| 2 | * Computer Algebra System SINGULAR * |
---|
| 3 | ****************************************/ |
---|
| 4 | /* |
---|
| 5 | * ABSTRACT - Kernel: alg. of Buchberger |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | // #define PDEBUG 2 |
---|
[645a19] | 9 | |
---|
| 10 | // TODO: why the following is here instead of mod2.h??? |
---|
| 11 | |
---|
[35aab3] | 12 | // define to enable tailRings |
---|
[60eb1d] | 13 | #define HAVE_TAIL_RING |
---|
[645a19] | 14 | |
---|
[16f511] | 15 | #ifdef HAVE_CONFIG_H |
---|
[ba5e9e] | 16 | #include "singularconfig.h" |
---|
[16f511] | 17 | #endif /* HAVE_CONFIG_H */ |
---|
[599326] | 18 | #include <kernel/mod2.h> |
---|
[645a19] | 19 | |
---|
| 20 | #ifndef NDEBUG |
---|
| 21 | # define MYTEST 0 |
---|
| 22 | #else /* ifndef NDEBUG */ |
---|
| 23 | # define MYTEST 0 |
---|
| 24 | #endif /* ifndef NDEBUG */ |
---|
| 25 | |
---|
[8d679fd] | 26 | #if MYTEST |
---|
[645a19] | 27 | # ifdef HAVE_TAIL_RING |
---|
| 28 | # undef HAVE_TAIL_RING |
---|
| 29 | # endif // ifdef HAVE_TAIL_RING |
---|
| 30 | #endif |
---|
| 31 | |
---|
[35aab3] | 32 | // define if no buckets should be used |
---|
| 33 | // #define NO_BUCKETS |
---|
| 34 | |
---|
[cbc616] | 35 | #ifdef HAVE_PLURAL |
---|
| 36 | #define PLURAL_INTERNAL_DECLARATIONS 1 |
---|
| 37 | #endif |
---|
[83be980] | 38 | |
---|
[b3e94aa] | 39 | /*********************************************** |
---|
| 40 | * SBA stuff -- start |
---|
| 41 | ***********************************************/ |
---|
[83be980] | 42 | #define DEBUGF50 0 |
---|
| 43 | #define DEBUGF51 0 |
---|
| 44 | |
---|
| 45 | #ifdef DEBUGF5 |
---|
| 46 | #undef DEBUGF5 |
---|
| 47 | //#define DEBUGF5 1 |
---|
| 48 | #endif |
---|
| 49 | |
---|
[15b211] | 50 | #define F5C 1 |
---|
[83be980] | 51 | #if F5C |
---|
[f9d20d7] | 52 | #define F5CTAILRED 1 |
---|
[83be980] | 53 | #endif |
---|
| 54 | |
---|
[f1cef21] | 55 | #define SBA_TAIL_RED 1 |
---|
[f59aaa] | 56 | #define SBA_PRODUCT_CRITERION 0 |
---|
[6d77472] | 57 | #define SBA_PRINT_ZERO_REDUCTIONS 0 |
---|
| 58 | #define SBA_PRINT_REDUCTION_STEPS 0 |
---|
| 59 | #define SBA_PRINT_OPERATIONS 0 |
---|
| 60 | #define SBA_PRINT_SIZE_G 0 |
---|
| 61 | #define SBA_PRINT_SIZE_SYZ 0 |
---|
[f59aaa] | 62 | #define SBA_PRINT_PRODUCT_CRITERION 0 |
---|
| 63 | |
---|
| 64 | // counts sba's reduction steps |
---|
[f7f084] | 65 | #if SBA_PRINT_REDUCTION_STEPS |
---|
[f9d20d7] | 66 | long sba_reduction_steps; |
---|
[f59aaa] | 67 | long sba_interreduction_steps; |
---|
[6d77472] | 68 | #endif |
---|
| 69 | #if SBA_PRINT_OPERATIONS |
---|
| 70 | long sba_operations; |
---|
[f59aaa] | 71 | long sba_interreduction_operations; |
---|
[6d77472] | 72 | #endif |
---|
| 73 | |
---|
[b3e94aa] | 74 | /*********************************************** |
---|
| 75 | * SBA stuff -- done |
---|
| 76 | ***********************************************/ |
---|
| 77 | |
---|
[599326] | 78 | #include <kernel/kutil.h> |
---|
[0f401f] | 79 | #include <misc/options.h> |
---|
[b1dfaf] | 80 | #include <omalloc/omalloc.h> |
---|
[737a68] | 81 | #include <kernel/polys.h> |
---|
[599326] | 82 | #include <kernel/ideals.h> |
---|
| 83 | #include <kernel/febase.h> |
---|
| 84 | #include <kernel/kstd1.h> |
---|
| 85 | #include <kernel/khstd.h> |
---|
[210e07] | 86 | #include <polys/kbuckets.h> |
---|
[fee33e] | 87 | #include <polys/prCopy.h> |
---|
[35aab3] | 88 | //#include "cntrlc.h" |
---|
[76cfef] | 89 | #include <polys/weight.h> |
---|
[210e07] | 90 | #include <misc/intvec.h> |
---|
[35aab3] | 91 | #ifdef HAVE_PLURAL |
---|
[210e07] | 92 | #include <polys/nc/nc.h> |
---|
[35aab3] | 93 | #endif |
---|
| 94 | // #include "timer.h" |
---|
| 95 | |
---|
[cb0fbe] | 96 | /* shiftgb stuff */ |
---|
[599326] | 97 | #include <kernel/shiftgb.h> |
---|
[cb0fbe] | 98 | |
---|
[57fad3a] | 99 | int (*test_PosInT)(const TSet T,const int tl,LObject &h); |
---|
| 100 | int (*test_PosInL)(const LSet set, const int length, |
---|
| 101 | LObject* L,const kStrategy strat); |
---|
| 102 | |
---|
[35aab3] | 103 | // return -1 if no divisor is found |
---|
| 104 | // number of first divisor, otherwise |
---|
| 105 | int kFindDivisibleByInT(const TSet &T, const unsigned long* sevT, |
---|
| 106 | const int tl, const LObject* L, const int start) |
---|
| 107 | { |
---|
| 108 | unsigned long not_sev = ~L->sev; |
---|
| 109 | int j = start; |
---|
[dd2855] | 110 | poly p=L->p; |
---|
| 111 | ring r=currRing; |
---|
[35aab3] | 112 | L->GetLm(p, r); |
---|
| 113 | |
---|
| 114 | pAssume(~not_sev == p_GetShortExpVector(p, r)); |
---|
| 115 | |
---|
| 116 | if (r == currRing) |
---|
| 117 | { |
---|
| 118 | loop |
---|
| 119 | { |
---|
| 120 | if (j > tl) return -1; |
---|
| 121 | #if defined(PDEBUG) || defined(PDIV_DEBUG) |
---|
| 122 | if (p_LmShortDivisibleBy(T[j].p, sevT[j], |
---|
| 123 | p, not_sev, r)) |
---|
| 124 | return j; |
---|
| 125 | #else |
---|
| 126 | if (!(sevT[j] & not_sev) && |
---|
| 127 | p_LmDivisibleBy(T[j].p, p, r)) |
---|
| 128 | return j; |
---|
| 129 | #endif |
---|
| 130 | j++; |
---|
| 131 | } |
---|
| 132 | } |
---|
| 133 | else |
---|
| 134 | { |
---|
| 135 | loop |
---|
| 136 | { |
---|
| 137 | if (j > tl) return -1; |
---|
| 138 | #if defined(PDEBUG) || defined(PDIV_DEBUG) |
---|
| 139 | if (p_LmShortDivisibleBy(T[j].t_p, sevT[j], |
---|
| 140 | p, not_sev, r)) |
---|
| 141 | return j; |
---|
| 142 | #else |
---|
| 143 | if (!(sevT[j] & not_sev) && |
---|
| 144 | p_LmDivisibleBy(T[j].t_p, p, r)) |
---|
| 145 | return j; |
---|
| 146 | #endif |
---|
| 147 | j++; |
---|
| 148 | } |
---|
| 149 | } |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | // same as above, only with set S |
---|
[391323] | 153 | int kFindDivisibleByInS(const kStrategy strat, int* max_ind, LObject* L) |
---|
[35aab3] | 154 | { |
---|
| 155 | unsigned long not_sev = ~L->sev; |
---|
| 156 | poly p = L->GetLmCurrRing(); |
---|
| 157 | int j = 0; |
---|
| 158 | |
---|
| 159 | pAssume(~not_sev == p_GetShortExpVector(p, currRing)); |
---|
[dd60f3c] | 160 | #if 1 |
---|
| 161 | int ende; |
---|
[fe89b98] | 162 | if ((strat->ak>0) || currRing->pLexOrder) ende=strat->sl; |
---|
[dd60f3c] | 163 | else ende=posInS(strat,*max_ind,p,0)+1; |
---|
[f41bd9] | 164 | if (ende>(*max_ind)) ende=(*max_ind); |
---|
| 165 | #else |
---|
[e690a91] | 166 | int ende=strat->sl; |
---|
[b2c236] | 167 | #endif |
---|
[391323] | 168 | (*max_ind)=ende; |
---|
[35aab3] | 169 | loop |
---|
| 170 | { |
---|
[efb860] | 171 | if (j > ende) return -1; |
---|
[35aab3] | 172 | #if defined(PDEBUG) || defined(PDIV_DEBUG) |
---|
[efb860] | 173 | if (p_LmShortDivisibleBy(strat->S[j], strat->sevS[j], |
---|
[35aab3] | 174 | p, not_sev, currRing)) |
---|
| 175 | return j; |
---|
| 176 | #else |
---|
[efb860] | 177 | if ( !(strat->sevS[j] & not_sev) && |
---|
| 178 | p_LmDivisibleBy(strat->S[j], p, currRing)) |
---|
[35aab3] | 179 | return j; |
---|
| 180 | #endif |
---|
| 181 | j++; |
---|
| 182 | } |
---|
| 183 | } |
---|
| 184 | |
---|
[7ba059] | 185 | int kFindNextDivisibleByInS(const kStrategy strat, int start,int max_ind, LObject* L) |
---|
| 186 | { |
---|
| 187 | unsigned long not_sev = ~L->sev; |
---|
| 188 | poly p = L->GetLmCurrRing(); |
---|
| 189 | int j = start; |
---|
| 190 | |
---|
| 191 | pAssume(~not_sev == p_GetShortExpVector(p, currRing)); |
---|
| 192 | #if 1 |
---|
| 193 | int ende=max_ind; |
---|
| 194 | #else |
---|
| 195 | int ende=strat->sl; |
---|
| 196 | #endif |
---|
| 197 | loop |
---|
| 198 | { |
---|
| 199 | if (j > ende) return -1; |
---|
| 200 | #if defined(PDEBUG) || defined(PDIV_DEBUG) |
---|
| 201 | if (p_LmShortDivisibleBy(strat->S[j], strat->sevS[j], |
---|
| 202 | p, not_sev, currRing)) |
---|
| 203 | return j; |
---|
| 204 | #else |
---|
| 205 | if ( !(strat->sevS[j] & not_sev) && |
---|
| 206 | p_LmDivisibleBy(strat->S[j], p, currRing)) |
---|
| 207 | return j; |
---|
| 208 | #endif |
---|
| 209 | j++; |
---|
| 210 | } |
---|
| 211 | } |
---|
| 212 | |
---|
[c90b43] | 213 | #ifdef HAVE_RINGS |
---|
[a09a42] | 214 | poly kFindZeroPoly(poly input_p, ring leadRing, ring tailRing) |
---|
| 215 | { |
---|
[cea6f3] | 216 | // m = currRing->ch |
---|
| 217 | |
---|
[a6889e] | 218 | if (input_p == NULL) return NULL; |
---|
| 219 | |
---|
| 220 | poly p = input_p; |
---|
[cea6f3] | 221 | poly zeroPoly = NULL; |
---|
[994445] | 222 | NATNUMBER a = (NATNUMBER) pGetCoeff(p); |
---|
[cea6f3] | 223 | |
---|
[fe7f527] | 224 | int k_ind2 = 0; |
---|
| 225 | int a_ind2 = ind2(a); |
---|
[cea6f3] | 226 | |
---|
[6909cfb] | 227 | // NATNUMBER k = 1; |
---|
[6d09f28] | 228 | // of interest is only k_ind2, special routine for improvement ... TODO OLIVER |
---|
[fe7f527] | 229 | for (int i = 1; i <= leadRing->N; i++) |
---|
[a09a42] | 230 | { |
---|
[fe7f527] | 231 | k_ind2 = k_ind2 + ind_fact_2(p_GetExp(p, i, leadRing)); |
---|
[cea6f3] | 232 | } |
---|
[fe7f527] | 233 | |
---|
[994445] | 234 | a = (NATNUMBER) pGetCoeff(p); |
---|
[cea6f3] | 235 | |
---|
| 236 | number tmp1; |
---|
| 237 | poly tmp2, tmp3; |
---|
[fe7f527] | 238 | poly lead_mult = p_ISet(1, tailRing); |
---|
[e533660] | 239 | if (n_GetChar(leadRing->cf) <= k_ind2 + a_ind2) |
---|
[a09a42] | 240 | { |
---|
[e533660] | 241 | int too_much = k_ind2 + a_ind2 - n_GetChar(leadRing->cf); |
---|
[fe7f527] | 242 | int s_exp; |
---|
[a6889e] | 243 | zeroPoly = p_ISet(a, tailRing); |
---|
[a09a42] | 244 | for (int i = 1; i <= leadRing->N; i++) |
---|
| 245 | { |
---|
[fe7f527] | 246 | s_exp = p_GetExp(p, i,leadRing); |
---|
[388f91e] | 247 | if (s_exp % 2 != 0) |
---|
[fe7f527] | 248 | { |
---|
| 249 | s_exp = s_exp - 1; |
---|
| 250 | } |
---|
| 251 | while ( (0 < ind2(s_exp)) && (ind2(s_exp) <= too_much) ) |
---|
| 252 | { |
---|
| 253 | too_much = too_much - ind2(s_exp); |
---|
| 254 | s_exp = s_exp - 2; |
---|
| 255 | } |
---|
[388f91e] | 256 | p_SetExp(lead_mult, i, p_GetExp(p, i,leadRing) - s_exp, tailRing); |
---|
[994445] | 257 | for (NATNUMBER j = 1; j <= s_exp; j++) |
---|
[a09a42] | 258 | { |
---|
[cea6f3] | 259 | tmp1 = nInit(j); |
---|
[a6889e] | 260 | tmp2 = p_ISet(1, tailRing); |
---|
| 261 | p_SetExp(tmp2, i, 1, tailRing); |
---|
| 262 | p_Setm(tmp2, tailRing); |
---|
[a09a42] | 263 | if (nIsZero(tmp1)) |
---|
[fe7f527] | 264 | { // should nowbe obsolet, test ! TODO OLIVER |
---|
[a6889e] | 265 | zeroPoly = p_Mult_q(zeroPoly, tmp2, tailRing); |
---|
[cea6f3] | 266 | } |
---|
[a09a42] | 267 | else |
---|
| 268 | { |
---|
[f92547] | 269 | tmp3 = p_NSet(nCopy(tmp1), tailRing); |
---|
[fe7f527] | 270 | zeroPoly = p_Mult_q(zeroPoly, p_Add_q(tmp3, tmp2, tailRing), tailRing); |
---|
[cea6f3] | 271 | } |
---|
| 272 | } |
---|
| 273 | } |
---|
[fe7f527] | 274 | p_Setm(lead_mult, tailRing); |
---|
[388f91e] | 275 | zeroPoly = p_Mult_mm(zeroPoly, lead_mult, tailRing); |
---|
[f92547] | 276 | tmp2 = p_NSet(nCopy(pGetCoeff(zeroPoly)), leadRing); |
---|
[977f94] | 277 | for (int i = 1; i <= leadRing->N; i++) |
---|
| 278 | { |
---|
[a725dae] | 279 | pSetExp(tmp2, i, p_GetExp(zeroPoly, i, tailRing)); |
---|
[cea6f3] | 280 | } |
---|
[7f06cca] | 281 | p_Setm(tmp2, leadRing); |
---|
| 282 | zeroPoly = p_LmDeleteAndNext(zeroPoly, tailRing); |
---|
[cea6f3] | 283 | pNext(tmp2) = zeroPoly; |
---|
| 284 | return tmp2; |
---|
| 285 | } |
---|
[994445] | 286 | /* NATNUMBER alpha_k = twoPow(leadRing->ch - k_ind2); |
---|
[977f94] | 287 | if (1 == 0 && alpha_k <= a) |
---|
| 288 | { // Temporarly disabled, reducing coefficients not compatible with std TODO Oliver |
---|
[7f06cca] | 289 | zeroPoly = p_ISet((a / alpha_k)*alpha_k, tailRing); |
---|
[977f94] | 290 | for (int i = 1; i <= leadRing->N; i++) |
---|
| 291 | { |
---|
[994445] | 292 | for (NATNUMBER j = 1; j <= p_GetExp(p, i, leadRing); j++) |
---|
[977f94] | 293 | { |
---|
[7f06cca] | 294 | tmp1 = nInit(j); |
---|
| 295 | tmp2 = p_ISet(1, tailRing); |
---|
| 296 | p_SetExp(tmp2, i, 1, tailRing); |
---|
| 297 | p_Setm(tmp2, tailRing); |
---|
[977f94] | 298 | if (nIsZero(tmp1)) |
---|
| 299 | { |
---|
[7f06cca] | 300 | zeroPoly = p_Mult_q(zeroPoly, tmp2, tailRing); |
---|
| 301 | } |
---|
[977f94] | 302 | else |
---|
| 303 | { |
---|
[994445] | 304 | tmp3 = p_ISet((NATNUMBER) tmp1, tailRing); |
---|
[7f06cca] | 305 | zeroPoly = p_Mult_q(zeroPoly, p_Add_q(tmp2, tmp3, tailRing), tailRing); |
---|
| 306 | } |
---|
| 307 | } |
---|
| 308 | } |
---|
[994445] | 309 | tmp2 = p_ISet((NATNUMBER) pGetCoeff(zeroPoly), leadRing); |
---|
[977f94] | 310 | for (int i = 1; i <= leadRing->N; i++) |
---|
| 311 | { |
---|
[a725dae] | 312 | pSetExp(tmp2, i, p_GetExp(zeroPoly, i, tailRing)); |
---|
[7f06cca] | 313 | } |
---|
| 314 | p_Setm(tmp2, leadRing); |
---|
| 315 | zeroPoly = p_LmDeleteAndNext(zeroPoly, tailRing); |
---|
| 316 | pNext(tmp2) = zeroPoly; |
---|
| 317 | return tmp2; |
---|
[6d09f28] | 318 | } */ |
---|
[cea6f3] | 319 | return NULL; |
---|
| 320 | } |
---|
[206e158] | 321 | #endif |
---|
[a6889e] | 322 | |
---|
[206e158] | 323 | |
---|
| 324 | #ifdef HAVE_RINGS |
---|
[585bbcb] | 325 | /*2 |
---|
| 326 | * reduction procedure for the ring Z/2^m |
---|
| 327 | */ |
---|
[093f30e] | 328 | int redRing (LObject* h,kStrategy strat) |
---|
[585bbcb] | 329 | { |
---|
[8d679fd] | 330 | if (h->IsNull()) return 0; // spoly is zero (can only occure with zero divisors) |
---|
| 331 | if (strat->tl<0) return 1; |
---|
[cea6f3] | 332 | |
---|
[6909cfb] | 333 | int at/*,i*/; |
---|
[d5564f8] | 334 | long d; |
---|
[585bbcb] | 335 | int j = 0; |
---|
| 336 | int pass = 0; |
---|
[6909cfb] | 337 | // poly zeroPoly = NULL; |
---|
[cea6f3] | 338 | |
---|
[388f91e] | 339 | // TODO warum SetpFDeg notwendig? |
---|
[cea6f3] | 340 | h->SetpFDeg(); |
---|
| 341 | assume(h->pFDeg() == h->FDeg); |
---|
[388f91e] | 342 | long reddeg = h->GetpFDeg(); |
---|
[585bbcb] | 343 | |
---|
[fe7f527] | 344 | h->SetShortExpVector(); |
---|
[585bbcb] | 345 | loop |
---|
| 346 | { |
---|
[8d679fd] | 347 | j = kFindDivisibleByInT(strat->T, strat->sevT, strat->tl, h); |
---|
| 348 | if (j < 0) return 1; |
---|
[585bbcb] | 349 | |
---|
[94ebce] | 350 | ksReducePoly(h, &(strat->T[j]), NULL, NULL, strat); // with debug output |
---|
[585bbcb] | 351 | |
---|
| 352 | if (h->GetLmTailRing() == NULL) |
---|
| 353 | { |
---|
[a539ad] | 354 | if (h->lcm!=NULL) pLmDelete(h->lcm); |
---|
[585bbcb] | 355 | #ifdef KDEBUG |
---|
| 356 | h->lcm=NULL; |
---|
| 357 | #endif |
---|
[8d679fd] | 358 | h->Clear(); |
---|
[585bbcb] | 359 | return 0; |
---|
| 360 | } |
---|
| 361 | h->SetShortExpVector(); |
---|
| 362 | d = h->SetpFDeg(); |
---|
| 363 | /*- try to reduce the s-polynomial -*/ |
---|
| 364 | pass++; |
---|
[228b631] | 365 | if (!TEST_OPT_REDTHROUGH && |
---|
[585bbcb] | 366 | (strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass))) |
---|
| 367 | { |
---|
| 368 | h->SetLmCurrRing(); |
---|
[8d679fd] | 369 | if (strat->posInLDependsOnLength) |
---|
| 370 | h->SetLength(strat->length_pLength); |
---|
[585bbcb] | 371 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
| 372 | if (at <= strat->Ll) |
---|
| 373 | { |
---|
| 374 | #ifdef KDEBUG |
---|
| 375 | if (TEST_OPT_DEBUG) Print(" ->L[%d]\n",at); |
---|
| 376 | #endif |
---|
[cea6f3] | 377 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); // NOT RING CHECKED OLIVER |
---|
[585bbcb] | 378 | h->Clear(); |
---|
| 379 | return -1; |
---|
| 380 | } |
---|
| 381 | } |
---|
[8d679fd] | 382 | if (d != reddeg) |
---|
[585bbcb] | 383 | { |
---|
[d5564f8] | 384 | if (d >= strat->tailRing->bitmask) |
---|
[f7feb7] | 385 | { |
---|
[8d679fd] | 386 | if (h->pTotalDeg() >= strat->tailRing->bitmask) |
---|
| 387 | { |
---|
| 388 | strat->overflow=TRUE; |
---|
[d5564f8] | 389 | //Print("OVERFLOW in redRing d=%ld, max=%ld\n",d,strat->tailRing->bitmask); |
---|
[8d679fd] | 390 | h->GetP(); |
---|
| 391 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
| 392 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
| 393 | h->Clear(); |
---|
[d5564f8] | 394 | return -1; |
---|
| 395 | } |
---|
[f7feb7] | 396 | } |
---|
| 397 | else if ((TEST_OPT_PROT) && (strat->Ll < 0)) |
---|
| 398 | { |
---|
[dd8a7d] | 399 | Print(".%ld",d);mflush(); |
---|
[f7feb7] | 400 | reddeg = d; |
---|
| 401 | } |
---|
[585bbcb] | 402 | } |
---|
| 403 | } |
---|
| 404 | } |
---|
| 405 | #endif |
---|
| 406 | |
---|
[35aab3] | 407 | /*2 |
---|
| 408 | * reduction procedure for the homogeneous case |
---|
| 409 | * and the case of a degree-ordering |
---|
| 410 | */ |
---|
| 411 | int redHomog (LObject* h,kStrategy strat) |
---|
| 412 | { |
---|
[bdde4f4] | 413 | if (strat->tl<0) return 1; |
---|
| 414 | //if (h->GetLmTailRing()==NULL) return 0; // HS: SHOULD NOT BE NEEDED! |
---|
| 415 | assume(h->FDeg == h->pFDeg()); |
---|
| 416 | |
---|
| 417 | poly h_p; |
---|
[225d94] | 418 | int i,j,at,pass, ii; |
---|
[bdde4f4] | 419 | unsigned long not_sev; |
---|
[cd4f24] | 420 | // long reddeg,d; |
---|
[bdde4f4] | 421 | |
---|
| 422 | pass = j = 0; |
---|
[cd4f24] | 423 | // d = reddeg = h->GetpFDeg(); |
---|
[bdde4f4] | 424 | h->SetShortExpVector(); |
---|
| 425 | int li; |
---|
| 426 | h_p = h->GetLmTailRing(); |
---|
| 427 | not_sev = ~ h->sev; |
---|
[35aab3] | 428 | loop |
---|
| 429 | { |
---|
| 430 | j = kFindDivisibleByInT(strat->T, strat->sevT, strat->tl, h); |
---|
[bdde4f4] | 431 | if (j < 0) return 1; |
---|
| 432 | |
---|
| 433 | li = strat->T[j].pLength; |
---|
| 434 | ii = j; |
---|
| 435 | /* |
---|
| 436 | * the polynomial to reduce with (up to the moment) is; |
---|
| 437 | * pi with length li |
---|
| 438 | */ |
---|
| 439 | i = j; |
---|
| 440 | #if 1 |
---|
[8c36a9] | 441 | if (TEST_OPT_LENGTH) |
---|
[bdde4f4] | 442 | loop |
---|
[35aab3] | 443 | { |
---|
[bdde4f4] | 444 | /*- search the shortest possible with respect to length -*/ |
---|
| 445 | i++; |
---|
| 446 | if (i > strat->tl) |
---|
| 447 | break; |
---|
| 448 | if (li<=1) |
---|
| 449 | break; |
---|
| 450 | if ((strat->T[i].pLength < li) |
---|
| 451 | && |
---|
| 452 | p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i], |
---|
| 453 | h_p, not_sev, strat->tailRing)) |
---|
| 454 | { |
---|
| 455 | /* |
---|
| 456 | * the polynomial to reduce with is now; |
---|
| 457 | */ |
---|
| 458 | li = strat->T[i].pLength; |
---|
| 459 | ii = i; |
---|
| 460 | } |
---|
[35aab3] | 461 | } |
---|
[bdde4f4] | 462 | #endif |
---|
[35aab3] | 463 | |
---|
[bdde4f4] | 464 | /* |
---|
| 465 | * end of search: have to reduce with pi |
---|
| 466 | */ |
---|
| 467 | #ifdef KDEBUG |
---|
| 468 | if (TEST_OPT_DEBUG) |
---|
| 469 | { |
---|
| 470 | PrintS("red:"); |
---|
| 471 | h->wrp(); |
---|
| 472 | PrintS(" with "); |
---|
| 473 | strat->T[ii].wrp(); |
---|
| 474 | } |
---|
| 475 | #endif |
---|
| 476 | assume(strat->fromT == FALSE); |
---|
| 477 | |
---|
| 478 | ksReducePoly(h, &(strat->T[ii]), NULL, NULL, strat); |
---|
[6d77472] | 479 | #if SBA_PRINT_REDUCTION_STEPS |
---|
[f59aaa] | 480 | sba_interreduction_steps++; |
---|
| 481 | #endif |
---|
[6d77472] | 482 | #if SBA_PRINT_REDUCTION_OPERATIONS |
---|
[f59aaa] | 483 | sba_interreduction_operations += pLength(strat->T[ii].p); |
---|
| 484 | #endif |
---|
[35aab3] | 485 | |
---|
| 486 | #ifdef KDEBUG |
---|
| 487 | if (TEST_OPT_DEBUG) |
---|
| 488 | { |
---|
[bdde4f4] | 489 | PrintS("\nto "); |
---|
[35aab3] | 490 | h->wrp(); |
---|
| 491 | PrintLn(); |
---|
| 492 | } |
---|
| 493 | #endif |
---|
[bdde4f4] | 494 | |
---|
| 495 | h_p = h->GetLmTailRing(); |
---|
| 496 | if (h_p == NULL) |
---|
[35aab3] | 497 | { |
---|
| 498 | if (h->lcm!=NULL) pLmFree(h->lcm); |
---|
| 499 | #ifdef KDEBUG |
---|
| 500 | h->lcm=NULL; |
---|
| 501 | #endif |
---|
| 502 | return 0; |
---|
| 503 | } |
---|
[bdde4f4] | 504 | h->SetShortExpVector(); |
---|
| 505 | not_sev = ~ h->sev; |
---|
| 506 | /* |
---|
| 507 | * try to reduce the s-polynomial h |
---|
| 508 | *test first whether h should go to the lazyset L |
---|
| 509 | *-if the degree jumps |
---|
| 510 | *-if the number of pre-defined reductions jumps |
---|
| 511 | */ |
---|
| 512 | pass++; |
---|
[228b631] | 513 | if (!TEST_OPT_REDTHROUGH && (strat->Ll >= 0) && (pass > strat->LazyPass)) |
---|
[0188fa] | 514 | { |
---|
| 515 | h->SetLmCurrRing(); |
---|
[bdde4f4] | 516 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
[0188fa] | 517 | if (at <= strat->Ll) |
---|
| 518 | { |
---|
[bdde4f4] | 519 | int dummy=strat->sl; |
---|
| 520 | if (kFindDivisibleByInS(strat, &dummy, h) < 0) |
---|
| 521 | return 1; |
---|
| 522 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
[0188fa] | 523 | #ifdef KDEBUG |
---|
[bdde4f4] | 524 | if (TEST_OPT_DEBUG) |
---|
| 525 | Print(" lazy: -> L%d\n",at); |
---|
[0188fa] | 526 | #endif |
---|
| 527 | h->Clear(); |
---|
| 528 | return -1; |
---|
| 529 | } |
---|
| 530 | } |
---|
[35aab3] | 531 | } |
---|
| 532 | } |
---|
| 533 | |
---|
[fbc7cb] | 534 | KINLINE int ksReducePolyTailSig(LObject* PR, TObject* PW, LObject* Red) |
---|
| 535 | { |
---|
| 536 | BOOLEAN ret; |
---|
| 537 | number coef; |
---|
| 538 | |
---|
| 539 | assume(PR->GetLmCurrRing() != PW->GetLmCurrRing()); |
---|
| 540 | Red->HeadNormalize(); |
---|
| 541 | /* |
---|
| 542 | printf("------------------------\n"); |
---|
| 543 | pWrite(Red->GetLmCurrRing()); |
---|
| 544 | */ |
---|
| 545 | ret = ksReducePolySig(Red, PW, 1, NULL, &coef); |
---|
| 546 | |
---|
| 547 | |
---|
| 548 | if (!ret) |
---|
| 549 | { |
---|
| 550 | if (! n_IsOne(coef, currRing->cf)) |
---|
| 551 | { |
---|
| 552 | PR->Mult_nn(coef); |
---|
| 553 | // HANNES: mark for Normalize |
---|
| 554 | } |
---|
| 555 | n_Delete(&coef, currRing->cf); |
---|
| 556 | } |
---|
| 557 | return ret; |
---|
| 558 | } |
---|
| 559 | |
---|
[83be980] | 560 | /*2 |
---|
| 561 | * reduction procedure for signature-based standard |
---|
| 562 | * basis algorithms: |
---|
| 563 | * all reductions have to be sig-safe! |
---|
| 564 | * |
---|
| 565 | * 2 is returned if and only if the pair is rejected by the rewritten criterion |
---|
| 566 | * at exactly this point of the computations. This is the last possible point |
---|
| 567 | * such a check can be done => checks with the biggest set of available |
---|
| 568 | * signatures |
---|
| 569 | */ |
---|
| 570 | int redSig (LObject* h,kStrategy strat) |
---|
| 571 | { |
---|
| 572 | if (strat->tl<0) return 1; |
---|
| 573 | //if (h->GetLmTailRing()==NULL) return 0; // HS: SHOULD NOT BE NEEDED! |
---|
| 574 | //printf("FDEGS: %ld -- %ld\n",h->FDeg, h->pFDeg()); |
---|
| 575 | assume(h->FDeg == h->pFDeg()); |
---|
| 576 | //#if 1 |
---|
| 577 | #ifdef DEBUGF5 |
---|
| 578 | Print("------- IN REDSIG -------\n"); |
---|
| 579 | Print("p: "); |
---|
| 580 | pWrite(pHead(h->p)); |
---|
| 581 | Print("p1: "); |
---|
| 582 | pWrite(pHead(h->p1)); |
---|
| 583 | Print("p2: "); |
---|
| 584 | pWrite(pHead(h->p2)); |
---|
| 585 | Print("---------------------------\n"); |
---|
| 586 | #endif |
---|
| 587 | poly h_p; |
---|
| 588 | int i,j,at,pass, ii; |
---|
| 589 | int start=0; |
---|
| 590 | int sigSafe; |
---|
| 591 | unsigned long not_sev; |
---|
[cd4f24] | 592 | // long reddeg,d; |
---|
[83be980] | 593 | |
---|
| 594 | pass = j = 0; |
---|
[cd4f24] | 595 | // d = reddeg = h->GetpFDeg(); |
---|
[83be980] | 596 | h->SetShortExpVector(); |
---|
| 597 | int li; |
---|
| 598 | h_p = h->GetLmTailRing(); |
---|
| 599 | not_sev = ~ h->sev; |
---|
| 600 | loop |
---|
| 601 | { |
---|
| 602 | j = kFindDivisibleByInT(strat->T, strat->sevT, strat->tl, h, start); |
---|
| 603 | if (j < 0) |
---|
| 604 | { |
---|
| 605 | return 1; |
---|
| 606 | } |
---|
| 607 | |
---|
| 608 | li = strat->T[j].pLength; |
---|
| 609 | ii = j; |
---|
| 610 | /* |
---|
| 611 | * the polynomial to reduce with (up to the moment) is; |
---|
| 612 | * pi with length li |
---|
| 613 | */ |
---|
| 614 | i = j; |
---|
| 615 | #if 1 |
---|
| 616 | if (TEST_OPT_LENGTH) |
---|
| 617 | loop |
---|
| 618 | { |
---|
| 619 | /*- search the shortest possible with respect to length -*/ |
---|
| 620 | i++; |
---|
| 621 | if (i > strat->tl) |
---|
| 622 | break; |
---|
| 623 | if (li<=1) |
---|
| 624 | break; |
---|
| 625 | if ((strat->T[i].pLength < li) |
---|
| 626 | && |
---|
| 627 | p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i], |
---|
| 628 | h_p, not_sev, strat->tailRing)) |
---|
| 629 | { |
---|
| 630 | /* |
---|
| 631 | * the polynomial to reduce with is now; |
---|
| 632 | */ |
---|
| 633 | li = strat->T[i].pLength; |
---|
| 634 | ii = i; |
---|
| 635 | } |
---|
| 636 | } |
---|
| 637 | start = ii+1; |
---|
| 638 | #endif |
---|
| 639 | |
---|
| 640 | /* |
---|
| 641 | * end of search: have to reduce with pi |
---|
| 642 | */ |
---|
| 643 | #ifdef KDEBUG |
---|
| 644 | if (TEST_OPT_DEBUG) |
---|
| 645 | { |
---|
| 646 | PrintS("red:"); |
---|
| 647 | h->wrp(); |
---|
| 648 | PrintS(" with "); |
---|
| 649 | strat->T[ii].wrp(); |
---|
| 650 | } |
---|
| 651 | #endif |
---|
| 652 | assume(strat->fromT == FALSE); |
---|
| 653 | //#if 1 |
---|
| 654 | #ifdef DEBUGF5 |
---|
| 655 | Print("BEFORE REDUCTION WITH %d:\n",ii); |
---|
| 656 | Print("--------------------------------\n"); |
---|
| 657 | pWrite(h->sig); |
---|
| 658 | pWrite(strat->T[ii].sig); |
---|
| 659 | pWrite(h->GetLmCurrRing()); |
---|
| 660 | pWrite(pHead(h->p1)); |
---|
| 661 | pWrite(pHead(h->p2)); |
---|
| 662 | pWrite(pHead(strat->T[ii].p)); |
---|
| 663 | Print("--------------------------------\n"); |
---|
| 664 | printf("INDEX OF REDUCER T: %d\n",ii); |
---|
| 665 | #endif |
---|
| 666 | sigSafe = ksReducePolySig(h, &(strat->T[ii]), strat->S_2_R[ii], NULL, NULL, strat); |
---|
[f9d20d7] | 667 | #if SBA_PRINT_REDUCTION_STEPS |
---|
[15b211] | 668 | if (sigSafe != 3) |
---|
| 669 | sba_reduction_steps++; |
---|
| 670 | #endif |
---|
| 671 | #if SBA_PRINT_OPERATIONS |
---|
| 672 | if (sigSafe != 3) |
---|
| 673 | sba_operations += pLength(strat->T[ii].p); |
---|
[f9d20d7] | 674 | #endif |
---|
[83be980] | 675 | // if reduction has taken place, i.e. the reduction was sig-safe |
---|
| 676 | // otherwise start is already at the next position and the loop |
---|
| 677 | // searching reducers in T goes on from index start |
---|
| 678 | //#if 1 |
---|
| 679 | #ifdef DEBUGF5 |
---|
| 680 | Print("SigSAFE: %d\n",sigSafe); |
---|
| 681 | #endif |
---|
| 682 | if (sigSafe != 3) |
---|
| 683 | { |
---|
| 684 | // start the next search for reducers in T from the beginning |
---|
| 685 | start = 0; |
---|
| 686 | #ifdef KDEBUG |
---|
| 687 | if (TEST_OPT_DEBUG) |
---|
| 688 | { |
---|
| 689 | PrintS("\nto "); |
---|
| 690 | h->wrp(); |
---|
| 691 | PrintLn(); |
---|
| 692 | } |
---|
| 693 | #endif |
---|
| 694 | |
---|
| 695 | h_p = h->GetLmTailRing(); |
---|
| 696 | if (h_p == NULL) |
---|
| 697 | { |
---|
| 698 | if (h->lcm!=NULL) pLmFree(h->lcm); |
---|
| 699 | #ifdef KDEBUG |
---|
| 700 | h->lcm=NULL; |
---|
| 701 | #endif |
---|
| 702 | return 0; |
---|
| 703 | } |
---|
| 704 | h->SetShortExpVector(); |
---|
| 705 | not_sev = ~ h->sev; |
---|
| 706 | /* |
---|
| 707 | * try to reduce the s-polynomial h |
---|
| 708 | *test first whether h should go to the lazyset L |
---|
| 709 | *-if the degree jumps |
---|
| 710 | *-if the number of pre-defined reductions jumps |
---|
| 711 | */ |
---|
| 712 | pass++; |
---|
| 713 | if (!TEST_OPT_REDTHROUGH && (strat->Ll >= 0) && (pass > strat->LazyPass)) |
---|
| 714 | { |
---|
| 715 | h->SetLmCurrRing(); |
---|
| 716 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
| 717 | if (at <= strat->Ll) |
---|
| 718 | { |
---|
| 719 | int dummy=strat->sl; |
---|
| 720 | if (kFindDivisibleByInS(strat, &dummy, h) < 0) |
---|
| 721 | { |
---|
| 722 | return 1; |
---|
| 723 | } |
---|
| 724 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
| 725 | #ifdef KDEBUG |
---|
| 726 | if (TEST_OPT_DEBUG) |
---|
| 727 | Print(" lazy: -> L%d\n",at); |
---|
| 728 | #endif |
---|
| 729 | h->Clear(); |
---|
| 730 | return -1; |
---|
| 731 | } |
---|
| 732 | } |
---|
| 733 | } |
---|
| 734 | } |
---|
| 735 | } |
---|
| 736 | |
---|
[fbc7cb] | 737 | // tail reduction for SBA |
---|
| 738 | poly redtailSba (LObject* L, int pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize) |
---|
| 739 | { |
---|
| 740 | #define REDTAIL_CANONICALIZE 100 |
---|
| 741 | strat->redTailChange=FALSE; |
---|
| 742 | if (strat->noTailReduction) return L->GetLmCurrRing(); |
---|
| 743 | poly h, p; |
---|
| 744 | p = h = L->GetLmTailRing(); |
---|
| 745 | if ((h==NULL) || (pNext(h)==NULL)) |
---|
| 746 | return L->GetLmCurrRing(); |
---|
| 747 | |
---|
| 748 | TObject* With; |
---|
| 749 | // placeholder in case strat->tl < 0 |
---|
| 750 | TObject With_s(strat->tailRing); |
---|
| 751 | |
---|
| 752 | LObject Ln(pNext(h), strat->tailRing); |
---|
| 753 | Ln.sig = L->sig; |
---|
| 754 | Ln.sevSig = L->sevSig; |
---|
| 755 | Ln.pLength = L->GetpLength() - 1; |
---|
| 756 | |
---|
| 757 | pNext(h) = NULL; |
---|
| 758 | if (L->p != NULL) pNext(L->p) = NULL; |
---|
| 759 | L->pLength = 1; |
---|
| 760 | |
---|
| 761 | Ln.PrepareRed(strat->use_buckets); |
---|
| 762 | |
---|
| 763 | int cnt=REDTAIL_CANONICALIZE; |
---|
| 764 | while(!Ln.IsNull()) |
---|
| 765 | { |
---|
| 766 | loop |
---|
| 767 | { |
---|
| 768 | Ln.SetShortExpVector(); |
---|
| 769 | if (withT) |
---|
| 770 | { |
---|
| 771 | int j; |
---|
| 772 | j = kFindDivisibleByInT(strat->T, strat->sevT, strat->tl, &Ln); |
---|
| 773 | if (j < 0) break; |
---|
| 774 | With = &(strat->T[j]); |
---|
| 775 | } |
---|
| 776 | else |
---|
| 777 | { |
---|
| 778 | With = kFindDivisibleByInS(strat, pos, &Ln, &With_s); |
---|
| 779 | if (With == NULL) break; |
---|
| 780 | } |
---|
| 781 | cnt--; |
---|
| 782 | if (cnt==0) |
---|
| 783 | { |
---|
| 784 | cnt=REDTAIL_CANONICALIZE; |
---|
| 785 | /*poly tmp=*/Ln.CanonicalizeP(); |
---|
| 786 | if (normalize) |
---|
| 787 | { |
---|
| 788 | Ln.Normalize(); |
---|
| 789 | //pNormalize(tmp); |
---|
| 790 | //if (TEST_OPT_PROT) { PrintS("n"); mflush(); } |
---|
| 791 | } |
---|
| 792 | } |
---|
| 793 | if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p)))) |
---|
| 794 | { |
---|
| 795 | With->pNorm(); |
---|
| 796 | } |
---|
| 797 | strat->redTailChange=TRUE; |
---|
| 798 | int ret = ksReducePolyTailSig(L, With, &Ln); |
---|
| 799 | #if SBA_PRINT_REDUCTION_STEPS |
---|
| 800 | if (ret != 3) |
---|
| 801 | sba_reduction_steps++; |
---|
| 802 | #endif |
---|
| 803 | #if SBA_PRINT_OPERATIONS |
---|
| 804 | if (ret != 3) |
---|
| 805 | sba_operations += pLength(With->p); |
---|
| 806 | #endif |
---|
| 807 | if (ret) |
---|
| 808 | { |
---|
| 809 | // reducing the tail would violate the exp bound |
---|
| 810 | // set a flag and hope for a retry (in bba) |
---|
| 811 | strat->completeReduce_retry=TRUE; |
---|
| 812 | if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL; |
---|
| 813 | do |
---|
| 814 | { |
---|
| 815 | pNext(h) = Ln.LmExtractAndIter(); |
---|
| 816 | pIter(h); |
---|
| 817 | L->pLength++; |
---|
| 818 | } while (!Ln.IsNull()); |
---|
| 819 | goto all_done; |
---|
| 820 | } |
---|
| 821 | if (Ln.IsNull()) goto all_done; |
---|
| 822 | if (! withT) With_s.Init(currRing); |
---|
| 823 | } |
---|
| 824 | pNext(h) = Ln.LmExtractAndIter(); |
---|
| 825 | pIter(h); |
---|
| 826 | pNormalize(h); |
---|
| 827 | L->pLength++; |
---|
| 828 | } |
---|
| 829 | |
---|
| 830 | all_done: |
---|
| 831 | Ln.Delete(); |
---|
| 832 | if (L->p != NULL) pNext(L->p) = pNext(p); |
---|
| 833 | |
---|
| 834 | if (strat->redTailChange) |
---|
| 835 | { |
---|
| 836 | L->length = 0; |
---|
| 837 | } |
---|
| 838 | |
---|
| 839 | //if (TEST_OPT_PROT) { PrintS("N"); mflush(); } |
---|
| 840 | //L->Normalize(); // HANNES: should have a test |
---|
| 841 | assume(kTest_L(L)); |
---|
| 842 | return L->GetLmCurrRing(); |
---|
| 843 | } |
---|
| 844 | |
---|
[35aab3] | 845 | /*2 |
---|
| 846 | * reduction procedure for the inhomogeneous case |
---|
| 847 | * and not a degree-ordering |
---|
| 848 | */ |
---|
| 849 | int redLazy (LObject* h,kStrategy strat) |
---|
| 850 | { |
---|
| 851 | if (strat->tl<0) return 1; |
---|
[d5564f8] | 852 | int at,i,ii,li; |
---|
[35aab3] | 853 | int j = 0; |
---|
| 854 | int pass = 0; |
---|
| 855 | assume(h->pFDeg() == h->FDeg); |
---|
| 856 | long reddeg = h->GetpFDeg(); |
---|
[d5564f8] | 857 | long d; |
---|
[225d94] | 858 | unsigned long not_sev; |
---|
[35aab3] | 859 | |
---|
| 860 | h->SetShortExpVector(); |
---|
[225d94] | 861 | poly h_p = h->GetLmTailRing(); |
---|
| 862 | not_sev = ~ h->sev; |
---|
[35aab3] | 863 | loop |
---|
| 864 | { |
---|
| 865 | j = kFindDivisibleByInT(strat->T, strat->sevT, strat->tl, h); |
---|
| 866 | if (j < 0) return 1; |
---|
[533634] | 867 | |
---|
[225d94] | 868 | li = strat->T[j].pLength; |
---|
[f0b6c9] | 869 | #if 0 |
---|
| 870 | if (li==0) |
---|
| 871 | { |
---|
| 872 | li=strat->T[j].pLength=pLength(strat->T[j].p); |
---|
| 873 | } |
---|
| 874 | #endif |
---|
[225d94] | 875 | ii = j; |
---|
| 876 | /* |
---|
| 877 | * the polynomial to reduce with (up to the moment) is; |
---|
| 878 | * pi with length li |
---|
| 879 | */ |
---|
| 880 | |
---|
| 881 | i = j; |
---|
| 882 | #if 1 |
---|
[8c36a9] | 883 | if (TEST_OPT_LENGTH) |
---|
[225d94] | 884 | loop |
---|
| 885 | { |
---|
| 886 | /*- search the shortest possible with respect to length -*/ |
---|
| 887 | i++; |
---|
| 888 | if (i > strat->tl) |
---|
| 889 | break; |
---|
| 890 | if (li<=1) |
---|
| 891 | break; |
---|
[f0b6c9] | 892 | #if 0 |
---|
| 893 | if (strat->T[i].pLength==0) |
---|
| 894 | { |
---|
| 895 | PrintS("!"); |
---|
| 896 | strat->T[i].pLength=pLength(strat->T[i].p); |
---|
| 897 | } |
---|
| 898 | #endif |
---|
[225d94] | 899 | if ((strat->T[i].pLength < li) |
---|
| 900 | && |
---|
| 901 | p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i], |
---|
| 902 | h_p, not_sev, strat->tailRing)) |
---|
| 903 | { |
---|
| 904 | /* |
---|
| 905 | * the polynomial to reduce with is now; |
---|
| 906 | */ |
---|
[533634] | 907 | PrintS("+"); |
---|
[225d94] | 908 | li = strat->T[i].pLength; |
---|
| 909 | ii = i; |
---|
| 910 | } |
---|
| 911 | } |
---|
| 912 | #endif |
---|
| 913 | |
---|
| 914 | /* |
---|
| 915 | * end of search: have to reduce with pi |
---|
| 916 | */ |
---|
| 917 | |
---|
[35aab3] | 918 | |
---|
| 919 | #ifdef KDEBUG |
---|
| 920 | if (TEST_OPT_DEBUG) |
---|
| 921 | { |
---|
| 922 | PrintS("red:"); |
---|
| 923 | h->wrp(); |
---|
| 924 | PrintS(" with "); |
---|
[225d94] | 925 | strat->T[ii].wrp(); |
---|
[35aab3] | 926 | } |
---|
| 927 | #endif |
---|
| 928 | |
---|
[225d94] | 929 | ksReducePoly(h, &(strat->T[ii]), NULL, NULL, strat); |
---|
[6d77472] | 930 | #if SBA_PRINT_REDUCTION_STEPS |
---|
[f59aaa] | 931 | sba_interreduction_steps++; |
---|
| 932 | #endif |
---|
[6d77472] | 933 | #if SBA_PRINT_REDUCTION_OPERATIONS |
---|
[f59aaa] | 934 | sba_interreduction_operations += pLength(strat->T[ii].p); |
---|
| 935 | #endif |
---|
[35aab3] | 936 | |
---|
| 937 | #ifdef KDEBUG |
---|
| 938 | if (TEST_OPT_DEBUG) |
---|
| 939 | { |
---|
| 940 | PrintS("\nto "); |
---|
| 941 | h->wrp(); |
---|
| 942 | PrintLn(); |
---|
| 943 | } |
---|
| 944 | #endif |
---|
| 945 | |
---|
[225d94] | 946 | h_p=h->GetLmTailRing(); |
---|
| 947 | |
---|
| 948 | if (h_p == NULL) |
---|
[35aab3] | 949 | { |
---|
| 950 | if (h->lcm!=NULL) pLmFree(h->lcm); |
---|
| 951 | #ifdef KDEBUG |
---|
| 952 | h->lcm=NULL; |
---|
| 953 | #endif |
---|
| 954 | return 0; |
---|
| 955 | } |
---|
| 956 | h->SetShortExpVector(); |
---|
[225d94] | 957 | not_sev = ~ h->sev; |
---|
[35aab3] | 958 | d = h->SetpFDeg(); |
---|
| 959 | /*- try to reduce the s-polynomial -*/ |
---|
| 960 | pass++; |
---|
[228b631] | 961 | if (//!TEST_OPT_REDTHROUGH && |
---|
[35aab3] | 962 | (strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass))) |
---|
| 963 | { |
---|
| 964 | h->SetLmCurrRing(); |
---|
[0188fa] | 965 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
[35aab3] | 966 | if (at <= strat->Ll) |
---|
| 967 | { |
---|
[e690a91] | 968 | #if 1 |
---|
| 969 | int dummy=strat->sl; |
---|
| 970 | if (kFindDivisibleByInS(strat, &dummy, h) < 0) |
---|
[35aab3] | 971 | return 1; |
---|
[0188fa] | 972 | #endif |
---|
[35aab3] | 973 | #ifdef KDEBUG |
---|
| 974 | if (TEST_OPT_DEBUG) Print(" ->L[%d]\n",at); |
---|
| 975 | #endif |
---|
| 976 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
| 977 | h->Clear(); |
---|
| 978 | return -1; |
---|
| 979 | } |
---|
| 980 | } |
---|
[f7feb7] | 981 | else if (d != reddeg) |
---|
[35aab3] | 982 | { |
---|
[f7feb7] | 983 | if (d>=strat->tailRing->bitmask) |
---|
| 984 | { |
---|
[8d679fd] | 985 | if (h->pTotalDeg() >= strat->tailRing->bitmask) |
---|
| 986 | { |
---|
| 987 | strat->overflow=TRUE; |
---|
[d5564f8] | 988 | //Print("OVERFLOW in redLazy d=%ld, max=%ld\n",d,strat->tailRing->bitmask); |
---|
[8d679fd] | 989 | h->GetP(); |
---|
| 990 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
| 991 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
| 992 | h->Clear(); |
---|
[d5564f8] | 993 | return -1; |
---|
| 994 | } |
---|
[f7feb7] | 995 | } |
---|
| 996 | else if ((TEST_OPT_PROT) && (strat->Ll < 0)) |
---|
| 997 | { |
---|
[dd8a7d] | 998 | Print(".%ld",d);mflush(); |
---|
[f7feb7] | 999 | reddeg = d; |
---|
| 1000 | } |
---|
[35aab3] | 1001 | } |
---|
| 1002 | } |
---|
| 1003 | } |
---|
| 1004 | /*2 |
---|
| 1005 | * reduction procedure for the sugar-strategy (honey) |
---|
| 1006 | * reduces h with elements from T choosing first possible |
---|
| 1007 | * element in T with respect to the given ecart |
---|
| 1008 | */ |
---|
| 1009 | int redHoney (LObject* h, kStrategy strat) |
---|
| 1010 | { |
---|
| 1011 | if (strat->tl<0) return 1; |
---|
[c5f67b5] | 1012 | //if (h->GetLmTailRing()==NULL) return 0; // HS: SHOULD NOT BE NEEDED! |
---|
[35aab3] | 1013 | assume(h->FDeg == h->pFDeg()); |
---|
| 1014 | poly h_p; |
---|
| 1015 | int i,j,at,pass,ei, ii, h_d; |
---|
| 1016 | unsigned long not_sev; |
---|
| 1017 | long reddeg,d; |
---|
| 1018 | |
---|
| 1019 | pass = j = 0; |
---|
| 1020 | d = reddeg = h->GetpFDeg() + h->ecart; |
---|
| 1021 | h->SetShortExpVector(); |
---|
[b2c236] | 1022 | int li; |
---|
[35aab3] | 1023 | h_p = h->GetLmTailRing(); |
---|
| 1024 | not_sev = ~ h->sev; |
---|
[f53fdf] | 1025 | |
---|
| 1026 | h->PrepareRed(strat->use_buckets); |
---|
[35aab3] | 1027 | loop |
---|
| 1028 | { |
---|
[f53fdf] | 1029 | j=kFindDivisibleByInT(strat->T, strat->sevT, strat->tl, h); |
---|
[35aab3] | 1030 | if (j < 0) return 1; |
---|
| 1031 | |
---|
| 1032 | ei = strat->T[j].ecart; |
---|
[b2c236] | 1033 | li = strat->T[j].pLength; |
---|
[35aab3] | 1034 | ii = j; |
---|
| 1035 | /* |
---|
| 1036 | * the polynomial to reduce with (up to the moment) is; |
---|
| 1037 | * pi with ecart ei |
---|
| 1038 | */ |
---|
| 1039 | i = j; |
---|
[8c36a9] | 1040 | if (TEST_OPT_LENGTH) |
---|
[35aab3] | 1041 | loop |
---|
| 1042 | { |
---|
| 1043 | /*- takes the first possible with respect to ecart -*/ |
---|
| 1044 | i++; |
---|
| 1045 | if (i > strat->tl) |
---|
| 1046 | break; |
---|
[f0b6c9] | 1047 | //if (ei < h->ecart) |
---|
| 1048 | // break; |
---|
[bdde4f4] | 1049 | if (li<=1) |
---|
[35aab3] | 1050 | break; |
---|
[f0b6c9] | 1051 | if ((((strat->T[i].ecart < ei) && (ei> h->ecart)) |
---|
[b2c236] | 1052 | || ((strat->T[i].ecart <= h->ecart) && (strat->T[i].pLength < li))) |
---|
| 1053 | && |
---|
[35aab3] | 1054 | p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i], |
---|
| 1055 | h_p, not_sev, strat->tailRing)) |
---|
| 1056 | { |
---|
| 1057 | /* |
---|
| 1058 | * the polynomial to reduce with is now; |
---|
| 1059 | */ |
---|
| 1060 | ei = strat->T[i].ecart; |
---|
[b2c236] | 1061 | li = strat->T[i].pLength; |
---|
[35aab3] | 1062 | ii = i; |
---|
| 1063 | } |
---|
| 1064 | } |
---|
| 1065 | |
---|
| 1066 | /* |
---|
| 1067 | * end of search: have to reduce with pi |
---|
| 1068 | */ |
---|
[228b631] | 1069 | if (!TEST_OPT_REDTHROUGH && (pass!=0) && (ei > h->ecart)) |
---|
[35aab3] | 1070 | { |
---|
[f53fdf] | 1071 | h->GetTP(); // clears bucket |
---|
[35aab3] | 1072 | h->SetLmCurrRing(); |
---|
| 1073 | /* |
---|
| 1074 | * It is not possible to reduce h with smaller ecart; |
---|
| 1075 | * if possible h goes to the lazy-set L,i.e |
---|
| 1076 | * if its position in L would be not the last one |
---|
| 1077 | */ |
---|
| 1078 | if (strat->Ll >= 0) /* L is not empty */ |
---|
| 1079 | { |
---|
| 1080 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
| 1081 | if(at <= strat->Ll) |
---|
| 1082 | /*- h will not become the next element to reduce -*/ |
---|
| 1083 | { |
---|
| 1084 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
| 1085 | #ifdef KDEBUG |
---|
| 1086 | if (TEST_OPT_DEBUG) Print(" ecart too big: -> L%d\n",at); |
---|
| 1087 | #endif |
---|
| 1088 | h->Clear(); |
---|
| 1089 | return -1; |
---|
| 1090 | } |
---|
| 1091 | } |
---|
| 1092 | } |
---|
| 1093 | #ifdef KDEBUG |
---|
| 1094 | if (TEST_OPT_DEBUG) |
---|
| 1095 | { |
---|
| 1096 | PrintS("red:"); |
---|
| 1097 | h->wrp(); |
---|
| 1098 | PrintS(" with "); |
---|
| 1099 | strat->T[ii].wrp(); |
---|
| 1100 | } |
---|
| 1101 | #endif |
---|
| 1102 | assume(strat->fromT == FALSE); |
---|
| 1103 | |
---|
[f53fdf] | 1104 | number coef; |
---|
| 1105 | ksReducePoly(h,&(strat->T[ii]),strat->kNoetherTail(),&coef,strat); |
---|
[6d77472] | 1106 | #if SBA_PRINT_REDUCTION_STEPS |
---|
[f59aaa] | 1107 | sba_interreduction_steps++; |
---|
| 1108 | #endif |
---|
[6d77472] | 1109 | #if SBA_PRINT_REDUCTION_OPERATIONS |
---|
[f59aaa] | 1110 | sba_interreduction_operations += pLength(strat->T[ii].p); |
---|
| 1111 | #endif |
---|
[35aab3] | 1112 | #ifdef KDEBUG |
---|
| 1113 | if (TEST_OPT_DEBUG) |
---|
| 1114 | { |
---|
[f53fdf] | 1115 | PrintS("\nto:"); |
---|
[35aab3] | 1116 | h->wrp(); |
---|
| 1117 | PrintLn(); |
---|
| 1118 | } |
---|
| 1119 | #endif |
---|
[f53fdf] | 1120 | if(h->IsNull()) |
---|
[35aab3] | 1121 | { |
---|
[f53fdf] | 1122 | h->Clear(); |
---|
[35aab3] | 1123 | if (h->lcm!=NULL) pLmFree(h->lcm); |
---|
[f53fdf] | 1124 | #ifdef KDEBUG |
---|
[35aab3] | 1125 | h->lcm=NULL; |
---|
[f53fdf] | 1126 | #endif |
---|
[35aab3] | 1127 | return 0; |
---|
| 1128 | } |
---|
| 1129 | h->SetShortExpVector(); |
---|
| 1130 | not_sev = ~ h->sev; |
---|
| 1131 | h_d = h->SetpFDeg(); |
---|
| 1132 | /* compute the ecart */ |
---|
| 1133 | if (ei <= h->ecart) |
---|
| 1134 | h->ecart = d-h_d; |
---|
[822aa3a] | 1135 | else |
---|
[35aab3] | 1136 | h->ecart = d-h_d+ei-h->ecart; |
---|
[f53fdf] | 1137 | |
---|
[35aab3] | 1138 | /* |
---|
| 1139 | * try to reduce the s-polynomial h |
---|
| 1140 | *test first whether h should go to the lazyset L |
---|
| 1141 | *-if the degree jumps |
---|
| 1142 | *-if the number of pre-defined reductions jumps |
---|
| 1143 | */ |
---|
| 1144 | pass++; |
---|
| 1145 | d = h_d + h->ecart; |
---|
[228b631] | 1146 | if (!TEST_OPT_REDTHROUGH && (strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass))) |
---|
[35aab3] | 1147 | { |
---|
[f53fdf] | 1148 | h->GetTP(); // clear bucket |
---|
[35aab3] | 1149 | h->SetLmCurrRing(); |
---|
| 1150 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
| 1151 | if (at <= strat->Ll) |
---|
| 1152 | { |
---|
[391323] | 1153 | int dummy=strat->sl; |
---|
| 1154 | if (kFindDivisibleByInS(strat, &dummy, h) < 0) |
---|
[35aab3] | 1155 | return 1; |
---|
| 1156 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
| 1157 | #ifdef KDEBUG |
---|
| 1158 | if (TEST_OPT_DEBUG) |
---|
| 1159 | Print(" degree jumped: -> L%d\n",at); |
---|
| 1160 | #endif |
---|
| 1161 | h->Clear(); |
---|
| 1162 | return -1; |
---|
| 1163 | } |
---|
| 1164 | } |
---|
[f7feb7] | 1165 | else if (d > reddeg) |
---|
[35aab3] | 1166 | { |
---|
[f7feb7] | 1167 | if (d>=strat->tailRing->bitmask) |
---|
| 1168 | { |
---|
[8d679fd] | 1169 | if (h->pTotalDeg()+h->ecart >= strat->tailRing->bitmask) |
---|
| 1170 | { |
---|
| 1171 | strat->overflow=TRUE; |
---|
[d5564f8] | 1172 | //Print("OVERFLOW in redHoney d=%ld, max=%ld\n",d,strat->tailRing->bitmask); |
---|
[8d679fd] | 1173 | h->GetP(); |
---|
| 1174 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
| 1175 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
| 1176 | h->Clear(); |
---|
[d5564f8] | 1177 | return -1; |
---|
| 1178 | } |
---|
[f7feb7] | 1179 | } |
---|
| 1180 | else if (TEST_OPT_PROT && (strat->Ll < 0) ) |
---|
| 1181 | { |
---|
| 1182 | //h->wrp(); Print("<%d>\n",h->GetpLength()); |
---|
| 1183 | reddeg = d; |
---|
| 1184 | Print(".%ld",d); mflush(); |
---|
| 1185 | } |
---|
[35aab3] | 1186 | } |
---|
| 1187 | } |
---|
| 1188 | } |
---|
[22579cf] | 1189 | |
---|
[35aab3] | 1190 | /*2 |
---|
| 1191 | * reduction procedure for the normal form |
---|
| 1192 | */ |
---|
| 1193 | |
---|
[ab1c36] | 1194 | poly redNF (poly h,int &max_ind,int nonorm,kStrategy strat) |
---|
[35aab3] | 1195 | { |
---|
| 1196 | if (h==NULL) return NULL; |
---|
| 1197 | int j; |
---|
[391323] | 1198 | max_ind=strat->sl; |
---|
[35aab3] | 1199 | |
---|
| 1200 | if (0 > strat->sl) |
---|
| 1201 | { |
---|
| 1202 | return h; |
---|
| 1203 | } |
---|
| 1204 | LObject P(h); |
---|
| 1205 | P.SetShortExpVector(); |
---|
| 1206 | P.bucket = kBucketCreate(currRing); |
---|
| 1207 | kBucketInit(P.bucket,P.p,pLength(P.p)); |
---|
[c5f67b5] | 1208 | kbTest(P.bucket); |
---|
[40d3462] | 1209 | #ifdef HAVE_RINGS |
---|
| 1210 | BOOLEAN is_ring = rField_is_Ring(currRing); |
---|
| 1211 | #endif |
---|
[9e8da7] | 1212 | #ifdef KDEBUG |
---|
| 1213 | if (TEST_OPT_DEBUG) |
---|
| 1214 | { |
---|
| 1215 | PrintS("redNF: starting S: "); |
---|
| 1216 | for( j = 0; j <= max_ind; j++ ) |
---|
| 1217 | { |
---|
| 1218 | Print("S[%d] (of size: %d): ", j, pSize(strat->S[j])); |
---|
| 1219 | pWrite(strat->S[j]); |
---|
| 1220 | } |
---|
| 1221 | }; |
---|
| 1222 | #endif |
---|
| 1223 | |
---|
[35aab3] | 1224 | loop |
---|
| 1225 | { |
---|
[d772c3] | 1226 | j=kFindDivisibleByInS(strat,&max_ind,&P); |
---|
[35aab3] | 1227 | if (j>=0) |
---|
| 1228 | { |
---|
[40d3462] | 1229 | #ifdef HAVE_RINGS |
---|
| 1230 | if (!is_ring) |
---|
| 1231 | { |
---|
| 1232 | #endif |
---|
[ab1c36] | 1233 | int sl=pSize(strat->S[j]); |
---|
| 1234 | int jj=j; |
---|
| 1235 | loop |
---|
[7ba059] | 1236 | { |
---|
[ab1c36] | 1237 | int sll; |
---|
| 1238 | jj=kFindNextDivisibleByInS(strat,jj+1,max_ind,&P); |
---|
| 1239 | if (jj<0) break; |
---|
| 1240 | sll=pSize(strat->S[jj]); |
---|
[08ab82] | 1241 | if (sll<sl) |
---|
| 1242 | { |
---|
| 1243 | #ifdef KDEBUG |
---|
| 1244 | if (TEST_OPT_DEBUG) Print("better(S%d:%d -> S%d:%d)\n",j,sl,jj,sll); |
---|
| 1245 | #endif |
---|
[a589e6] | 1246 | //else if (TEST_OPT_PROT) { PrintS("b"); mflush(); } |
---|
[19408c] | 1247 | j=jj; |
---|
| 1248 | sl=sll; |
---|
[08ab82] | 1249 | } |
---|
[7ba059] | 1250 | } |
---|
[1863d8] | 1251 | if ((nonorm==0) && (!nIsOne(pGetCoeff(strat->S[j])))) |
---|
[ab1c36] | 1252 | { |
---|
| 1253 | pNorm(strat->S[j]); |
---|
| 1254 | //if (TEST_OPT_PROT) { PrintS("n"); mflush(); } |
---|
| 1255 | } |
---|
[40d3462] | 1256 | #ifdef HAVE_RINGS |
---|
| 1257 | } |
---|
| 1258 | #endif |
---|
[35aab3] | 1259 | nNormalize(pGetCoeff(P.p)); |
---|
| 1260 | #ifdef KDEBUG |
---|
| 1261 | if (TEST_OPT_DEBUG) |
---|
| 1262 | { |
---|
| 1263 | PrintS("red:"); |
---|
| 1264 | wrp(h); |
---|
| 1265 | PrintS(" with "); |
---|
| 1266 | wrp(strat->S[j]); |
---|
| 1267 | } |
---|
| 1268 | #endif |
---|
| 1269 | #ifdef HAVE_PLURAL |
---|
| 1270 | if (rIsPluralRing(currRing)) |
---|
| 1271 | { |
---|
[c5f67b5] | 1272 | number coef; |
---|
[19370c] | 1273 | nc_kBucketPolyRed(P.bucket,strat->S[j],&coef); |
---|
[c5f67b5] | 1274 | nDelete(&coef); |
---|
[35aab3] | 1275 | } |
---|
| 1276 | else |
---|
| 1277 | #endif |
---|
| 1278 | { |
---|
| 1279 | number coef; |
---|
| 1280 | coef=kBucketPolyRed(P.bucket,strat->S[j],pLength(strat->S[j]),strat->kNoether); |
---|
| 1281 | nDelete(&coef); |
---|
| 1282 | } |
---|
[cea6f3] | 1283 | h = kBucketGetLm(P.bucket); // FRAGE OLIVER |
---|
[35aab3] | 1284 | if (h==NULL) |
---|
| 1285 | { |
---|
| 1286 | kBucketDestroy(&P.bucket); |
---|
[9e8da7] | 1287 | |
---|
| 1288 | #ifdef KDEBUG |
---|
| 1289 | if (TEST_OPT_DEBUG) |
---|
| 1290 | { |
---|
| 1291 | PrintS("redNF: starting S: "); |
---|
| 1292 | for( j = 0; j <= max_ind; j++ ) |
---|
| 1293 | { |
---|
| 1294 | Print("S[%d] (of size: %d): ", j, pSize(strat->S[j])); |
---|
| 1295 | pWrite(strat->S[j]); |
---|
| 1296 | } |
---|
| 1297 | }; |
---|
| 1298 | #endif |
---|
[e91ba4] | 1299 | |
---|
[35aab3] | 1300 | return NULL; |
---|
| 1301 | } |
---|
[c5f67b5] | 1302 | kbTest(P.bucket); |
---|
[35aab3] | 1303 | P.p=h; |
---|
| 1304 | P.t_p=NULL; |
---|
| 1305 | P.SetShortExpVector(); |
---|
| 1306 | #ifdef KDEBUG |
---|
| 1307 | if (TEST_OPT_DEBUG) |
---|
| 1308 | { |
---|
| 1309 | PrintS("\nto:"); |
---|
| 1310 | wrp(h); |
---|
| 1311 | PrintLn(); |
---|
| 1312 | } |
---|
| 1313 | #endif |
---|
| 1314 | } |
---|
| 1315 | else |
---|
| 1316 | { |
---|
| 1317 | P.p=kBucketClear(P.bucket); |
---|
| 1318 | kBucketDestroy(&P.bucket); |
---|
| 1319 | pNormalize(P.p); |
---|
[9e8da7] | 1320 | |
---|
| 1321 | #ifdef KDEBUG |
---|
| 1322 | if (TEST_OPT_DEBUG) |
---|
| 1323 | { |
---|
| 1324 | PrintS("redNF: starting S: "); |
---|
| 1325 | for( j = 0; j <= max_ind; j++ ) |
---|
| 1326 | { |
---|
| 1327 | Print("S[%d] (of size: %d): ", j, pSize(strat->S[j])); |
---|
| 1328 | pWrite(strat->S[j]); |
---|
| 1329 | } |
---|
| 1330 | }; |
---|
| 1331 | #endif |
---|
| 1332 | |
---|
[35aab3] | 1333 | return P.p; |
---|
| 1334 | } |
---|
| 1335 | } |
---|
| 1336 | } |
---|
| 1337 | |
---|
| 1338 | #ifdef KDEBUG |
---|
| 1339 | static int bba_count = 0; |
---|
[645a19] | 1340 | #endif /* KDEBUG */ |
---|
[79d3879] | 1341 | void kDebugPrint(kStrategy strat); |
---|
[35aab3] | 1342 | |
---|
| 1343 | ideal bba (ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat) |
---|
| 1344 | { |
---|
| 1345 | #ifdef KDEBUG |
---|
| 1346 | bba_count++; |
---|
| 1347 | int loop_count = 0; |
---|
[645a19] | 1348 | #endif /* KDEBUG */ |
---|
[930ea8] | 1349 | int red_result = 1; |
---|
[35aab3] | 1350 | int olddeg,reduc; |
---|
| 1351 | int hilbeledeg=1,hilbcount=0,minimcnt=0; |
---|
| 1352 | BOOLEAN withT = FALSE; |
---|
[3772383] | 1353 | BITSET save; |
---|
| 1354 | SI_SAVE_OPT1(save); |
---|
[35aab3] | 1355 | |
---|
| 1356 | initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/ |
---|
| 1357 | initBuchMoraPos(strat); |
---|
| 1358 | initHilbCrit(F,Q,&hilb,strat); |
---|
| 1359 | initBba(F,strat); |
---|
| 1360 | /*set enterS, spSpolyShort, reduce, red, initEcart, initEcartPair*/ |
---|
| 1361 | /*Shdl=*/initBuchMora(F, Q,strat); |
---|
| 1362 | if (strat->minim>0) strat->M=idInit(IDELEMS(F),F->rank); |
---|
[930ea8] | 1363 | reduc = olddeg = 0; |
---|
[35aab3] | 1364 | |
---|
| 1365 | #ifndef NO_BUCKETS |
---|
| 1366 | if (!TEST_OPT_NOT_BUCKETS) |
---|
| 1367 | strat->use_buckets = 1; |
---|
| 1368 | #endif |
---|
| 1369 | |
---|
| 1370 | // redtailBBa against T for inhomogenous input |
---|
[228b631] | 1371 | if (!TEST_OPT_OLDSTD) |
---|
[35aab3] | 1372 | withT = ! strat->homog; |
---|
| 1373 | |
---|
| 1374 | // strat->posInT = posInT_pLength; |
---|
[d101b1] | 1375 | assume(kTest_TS(strat)); |
---|
[35aab3] | 1376 | |
---|
[645a19] | 1377 | #ifdef KDEBUG |
---|
| 1378 | #if MYTEST |
---|
[9982049] | 1379 | if (TEST_OPT_DEBUG) |
---|
[8d679fd] | 1380 | { |
---|
[9982049] | 1381 | PrintS("bba start GB: currRing: "); |
---|
| 1382 | // rWrite(currRing);PrintLn(); |
---|
| 1383 | rDebugPrint(currRing); |
---|
| 1384 | PrintLn(); |
---|
[645a19] | 1385 | } |
---|
| 1386 | #endif /* MYTEST */ |
---|
| 1387 | #endif /* KDEBUG */ |
---|
| 1388 | |
---|
[35aab3] | 1389 | #ifdef HAVE_TAIL_RING |
---|
[e533660] | 1390 | if(!idIs0(F) &&(!rField_is_Ring(currRing))) // create strong gcd poly computes with tailring and S[i] ->to be fixed |
---|
[645a19] | 1391 | kStratInitChangeTailRing(strat); |
---|
[35aab3] | 1392 | #endif |
---|
[d5564f8] | 1393 | if (BVERBOSE(23)) |
---|
[57fad3a] | 1394 | { |
---|
| 1395 | if (test_PosInT!=NULL) strat->posInT=test_PosInT; |
---|
| 1396 | if (test_PosInL!=NULL) strat->posInL=test_PosInL; |
---|
| 1397 | kDebugPrint(strat); |
---|
| 1398 | } |
---|
| 1399 | |
---|
[35aab3] | 1400 | |
---|
[8d679fd] | 1401 | #ifdef KDEBUG |
---|
| 1402 | //kDebugPrint(strat); |
---|
| 1403 | #endif |
---|
[35aab3] | 1404 | /* compute------------------------------------------------------- */ |
---|
| 1405 | while (strat->Ll >= 0) |
---|
| 1406 | { |
---|
[08ab82] | 1407 | #ifdef KDEBUG |
---|
| 1408 | loop_count++; |
---|
| 1409 | if (TEST_OPT_DEBUG) messageSets(strat); |
---|
| 1410 | #endif |
---|
[35aab3] | 1411 | if (strat->Ll== 0) strat->interpt=TRUE; |
---|
| 1412 | if (TEST_OPT_DEGBOUND |
---|
[e533660] | 1413 | && ((strat->honey && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg)) |
---|
| 1414 | || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg)))) |
---|
[35aab3] | 1415 | { |
---|
| 1416 | /* |
---|
| 1417 | *stops computation if |
---|
| 1418 | * 24 IN test and the degree +ecart of L[strat->Ll] is bigger then |
---|
| 1419 | *a predefined number Kstd1_deg |
---|
| 1420 | */ |
---|
[939847] | 1421 | while ((strat->Ll >= 0) |
---|
[977f94] | 1422 | && (strat->L[strat->Ll].p1!=NULL) && (strat->L[strat->Ll].p2!=NULL) |
---|
[e533660] | 1423 | && ((strat->honey && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg)) |
---|
| 1424 | || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))) |
---|
[977f94] | 1425 | ) |
---|
[019649] | 1426 | deleteInL(strat->L,&strat->Ll,strat->Ll,strat); |
---|
| 1427 | if (strat->Ll<0) break; |
---|
[3957e37] | 1428 | else strat->noClearS=TRUE; |
---|
[35aab3] | 1429 | } |
---|
| 1430 | /* picks the last element from the lazyset L */ |
---|
| 1431 | strat->P = strat->L[strat->Ll]; |
---|
| 1432 | strat->Ll--; |
---|
| 1433 | |
---|
| 1434 | if (pNext(strat->P.p) == strat->tail) |
---|
| 1435 | { |
---|
| 1436 | // deletes the short spoly |
---|
[a539ad] | 1437 | #ifdef HAVE_RINGS |
---|
| 1438 | if (rField_is_Ring(currRing)) |
---|
| 1439 | pLmDelete(strat->P.p); |
---|
| 1440 | else |
---|
| 1441 | #endif |
---|
| 1442 | pLmFree(strat->P.p); |
---|
[35aab3] | 1443 | strat->P.p = NULL; |
---|
| 1444 | poly m1 = NULL, m2 = NULL; |
---|
| 1445 | |
---|
| 1446 | // check that spoly creation is ok |
---|
| 1447 | while (strat->tailRing != currRing && |
---|
| 1448 | !kCheckSpolyCreation(&(strat->P), strat, m1, m2)) |
---|
| 1449 | { |
---|
| 1450 | assume(m1 == NULL && m2 == NULL); |
---|
| 1451 | // if not, change to a ring where exponents are at least |
---|
| 1452 | // large enough |
---|
[7ae94b] | 1453 | if (!kStratChangeTailRing(strat)) |
---|
| 1454 | { |
---|
[8d679fd] | 1455 | WerrorS("OVERFLOW..."); |
---|
[7ae94b] | 1456 | break; |
---|
| 1457 | } |
---|
[35aab3] | 1458 | } |
---|
| 1459 | // create the real one |
---|
| 1460 | ksCreateSpoly(&(strat->P), NULL, strat->use_buckets, |
---|
| 1461 | strat->tailRing, m1, m2, strat->R); |
---|
| 1462 | } |
---|
| 1463 | else if (strat->P.p1 == NULL) |
---|
| 1464 | { |
---|
| 1465 | if (strat->minim > 0) |
---|
| 1466 | strat->P.p2=p_Copy(strat->P.p, currRing, strat->tailRing); |
---|
| 1467 | // for input polys, prepare reduction |
---|
| 1468 | strat->P.PrepareRed(strat->use_buckets); |
---|
| 1469 | } |
---|
| 1470 | |
---|
[977f94] | 1471 | if (strat->P.p == NULL && strat->P.t_p == NULL) |
---|
| 1472 | { |
---|
[cea6f3] | 1473 | red_result = 0; |
---|
| 1474 | } |
---|
| 1475 | else |
---|
| 1476 | { |
---|
| 1477 | if (TEST_OPT_PROT) |
---|
| 1478 | message((strat->honey ? strat->P.ecart : 0) + strat->P.pFDeg(), |
---|
| 1479 | &olddeg,&reduc,strat, red_result); |
---|
[35aab3] | 1480 | |
---|
[cea6f3] | 1481 | /* reduction of the element choosen from L */ |
---|
| 1482 | red_result = strat->red(&strat->P,strat); |
---|
[d5564f8] | 1483 | if (errorreported) break; |
---|
| 1484 | } |
---|
| 1485 | |
---|
| 1486 | if (strat->overflow) |
---|
| 1487 | { |
---|
| 1488 | if (!kStratChangeTailRing(strat)) { Werror("OVERFLOW.."); break;} |
---|
[cea6f3] | 1489 | } |
---|
[35aab3] | 1490 | |
---|
| 1491 | // reduction to non-zero new poly |
---|
| 1492 | if (red_result == 1) |
---|
| 1493 | { |
---|
| 1494 | // get the polynomial (canonicalize bucket, make sure P.p is set) |
---|
| 1495 | strat->P.GetP(strat->lmBin); |
---|
[3dc79f5] | 1496 | // in the homogeneous case FDeg >= pFDeg (sugar/honey) |
---|
| 1497 | // but now, for entering S, T, we reset it |
---|
| 1498 | // in the inhomogeneous case: FDeg == pFDeg |
---|
| 1499 | if (strat->homog) strat->initEcart(&(strat->P)); |
---|
[35aab3] | 1500 | |
---|
[d5564f8] | 1501 | /* statistic */ |
---|
| 1502 | if (TEST_OPT_PROT) PrintS("s"); |
---|
| 1503 | |
---|
[35aab3] | 1504 | int pos=posInS(strat,strat->sl,strat->P.p,strat->P.ecart); |
---|
| 1505 | |
---|
[645a19] | 1506 | #ifdef KDEBUG |
---|
| 1507 | #if MYTEST |
---|
[f29ab6] | 1508 | PrintS("New S: "); p_DebugPrint(strat->P.p, currRing); PrintLn(); |
---|
[645a19] | 1509 | #endif /* MYTEST */ |
---|
| 1510 | #endif /* KDEBUG */ |
---|
| 1511 | |
---|
[35aab3] | 1512 | // reduce the tail and normalize poly |
---|
[521349] | 1513 | // in the ring case we cannot expect LC(f) = 1, |
---|
| 1514 | // therefore we call pContent instead of pNorm |
---|
| 1515 | if ((TEST_OPT_INTSTRATEGY) || (rField_is_Ring(currRing))) |
---|
[35aab3] | 1516 | { |
---|
| 1517 | strat->P.pCleardenom(); |
---|
| 1518 | if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL)) |
---|
| 1519 | { |
---|
| 1520 | strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT); |
---|
| 1521 | strat->P.pCleardenom(); |
---|
| 1522 | } |
---|
| 1523 | } |
---|
| 1524 | else |
---|
| 1525 | { |
---|
| 1526 | strat->P.pNorm(); |
---|
| 1527 | if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL)) |
---|
| 1528 | strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT); |
---|
| 1529 | } |
---|
| 1530 | |
---|
| 1531 | #ifdef KDEBUG |
---|
| 1532 | if (TEST_OPT_DEBUG){PrintS("new s:");strat->P.wrp();PrintLn();} |
---|
[645a19] | 1533 | #if MYTEST |
---|
[f29ab6] | 1534 | PrintS("New (reduced) S: "); p_DebugPrint(strat->P.p, currRing); PrintLn(); |
---|
[645a19] | 1535 | #endif /* MYTEST */ |
---|
| 1536 | #endif /* KDEBUG */ |
---|
[35aab3] | 1537 | |
---|
| 1538 | // min_std stuff |
---|
| 1539 | if ((strat->P.p1==NULL) && (strat->minim>0)) |
---|
| 1540 | { |
---|
| 1541 | if (strat->minim==1) |
---|
| 1542 | { |
---|
| 1543 | strat->M->m[minimcnt]=p_Copy(strat->P.p,currRing,strat->tailRing); |
---|
| 1544 | p_Delete(&strat->P.p2, currRing, strat->tailRing); |
---|
| 1545 | } |
---|
| 1546 | else |
---|
| 1547 | { |
---|
| 1548 | strat->M->m[minimcnt]=strat->P.p2; |
---|
| 1549 | strat->P.p2=NULL; |
---|
| 1550 | } |
---|
| 1551 | if (strat->tailRing!=currRing && pNext(strat->M->m[minimcnt])!=NULL) |
---|
| 1552 | pNext(strat->M->m[minimcnt]) |
---|
| 1553 | = strat->p_shallow_copy_delete(pNext(strat->M->m[minimcnt]), |
---|
| 1554 | strat->tailRing, currRing, |
---|
| 1555 | currRing->PolyBin); |
---|
| 1556 | minimcnt++; |
---|
| 1557 | } |
---|
| 1558 | |
---|
| 1559 | // enter into S, L, and T |
---|
[b981502] | 1560 | //if ((!TEST_OPT_IDLIFT) || (pGetComp(strat->P.p) <= strat->syzComp)) |
---|
[f0b6c9] | 1561 | enterT(strat->P, strat); |
---|
[206e158] | 1562 | #ifdef HAVE_RINGS |
---|
| 1563 | if (rField_is_Ring(currRing)) |
---|
[f92547] | 1564 | superenterpairs(strat->P.p,strat->sl,strat->P.ecart,pos,strat, strat->tl); |
---|
| 1565 | else |
---|
| 1566 | #endif |
---|
| 1567 | enterpairs(strat->P.p,strat->sl,strat->P.ecart,pos,strat, strat->tl); |
---|
[35aab3] | 1568 | // posInS only depends on the leading term |
---|
| 1569 | strat->enterS(strat->P, pos, strat, strat->tl); |
---|
[f0b6c9] | 1570 | #if 0 |
---|
[b2c236] | 1571 | int pl=pLength(strat->P.p); |
---|
| 1572 | if (pl==1) |
---|
| 1573 | { |
---|
| 1574 | //if (TEST_OPT_PROT) |
---|
| 1575 | //PrintS("<1>"); |
---|
| 1576 | } |
---|
| 1577 | else if (pl==2) |
---|
| 1578 | { |
---|
| 1579 | //if (TEST_OPT_PROT) |
---|
| 1580 | //PrintS("<2>"); |
---|
| 1581 | } |
---|
[f0b6c9] | 1582 | #endif |
---|
[35aab3] | 1583 | if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat); |
---|
| 1584 | // Print("[%d]",hilbeledeg); |
---|
[1e36c5] | 1585 | if (strat->P.lcm!=NULL) |
---|
| 1586 | #ifdef HAVE_RINGS |
---|
| 1587 | pLmDelete(strat->P.lcm); |
---|
| 1588 | #else |
---|
| 1589 | pLmFree(strat->P.lcm); |
---|
| 1590 | #endif |
---|
[35aab3] | 1591 | } |
---|
| 1592 | else if (strat->P.p1 == NULL && strat->minim > 0) |
---|
| 1593 | { |
---|
| 1594 | p_Delete(&strat->P.p2, currRing, strat->tailRing); |
---|
| 1595 | } |
---|
[a539ad] | 1596 | |
---|
[35aab3] | 1597 | #ifdef KDEBUG |
---|
| 1598 | memset(&(strat->P), 0, sizeof(strat->P)); |
---|
[645a19] | 1599 | #endif /* KDEBUG */ |
---|
[d101b1] | 1600 | assume(kTest_TS(strat)); |
---|
[35aab3] | 1601 | } |
---|
| 1602 | #ifdef KDEBUG |
---|
[645a19] | 1603 | #if MYTEST |
---|
| 1604 | PrintS("bba finish GB: currRing: "); rWrite(currRing); |
---|
| 1605 | #endif /* MYTEST */ |
---|
[35aab3] | 1606 | if (TEST_OPT_DEBUG) messageSets(strat); |
---|
[645a19] | 1607 | #endif /* KDEBUG */ |
---|
| 1608 | |
---|
[07b1cf] | 1609 | if (TEST_OPT_SB_1) |
---|
| 1610 | { |
---|
| 1611 | int k=1; |
---|
| 1612 | int j; |
---|
| 1613 | while(k<=strat->sl) |
---|
| 1614 | { |
---|
| 1615 | j=0; |
---|
| 1616 | loop |
---|
| 1617 | { |
---|
| 1618 | if (j>=k) break; |
---|
| 1619 | clearS(strat->S[j],strat->sevS[j],&k,&j,strat); |
---|
| 1620 | j++; |
---|
| 1621 | } |
---|
| 1622 | k++; |
---|
| 1623 | } |
---|
| 1624 | } |
---|
| 1625 | |
---|
[93f4bb] | 1626 | /* complete reduction of the standard basis--------- */ |
---|
[533634] | 1627 | if (TEST_OPT_REDSB) |
---|
[b57694] | 1628 | { |
---|
[533634] | 1629 | completeReduce(strat); |
---|
[cbc616] | 1630 | #ifdef HAVE_TAIL_RING |
---|
[b57694] | 1631 | if (strat->completeReduce_retry) |
---|
| 1632 | { |
---|
[533634] | 1633 | // completeReduce needed larger exponents, retry |
---|
| 1634 | // to reduce with S (instead of T) |
---|
| 1635 | // and in currRing (instead of strat->tailRing) |
---|
[b57694] | 1636 | cleanT(strat);strat->tailRing=currRing; |
---|
| 1637 | int i; |
---|
| 1638 | for(i=strat->sl;i>=0;i--) strat->S_2_R[i]=-1; |
---|
| 1639 | completeReduce(strat); |
---|
| 1640 | } |
---|
[cbc616] | 1641 | #endif |
---|
[b57694] | 1642 | } |
---|
[5accf0] | 1643 | else if (TEST_OPT_PROT) PrintLn(); |
---|
[533634] | 1644 | |
---|
[35aab3] | 1645 | /* release temp data-------------------------------- */ |
---|
| 1646 | exitBuchMora(strat); |
---|
[e533660] | 1647 | // if (TEST_OPT_WEIGHTM) |
---|
| 1648 | // { |
---|
| 1649 | // pRestoreDegProcs(currRing,pFDegOld, pLDegOld); |
---|
| 1650 | // if (ecartWeights) |
---|
| 1651 | // { |
---|
| 1652 | // omFreeSize((ADDRESS)ecartWeights,((currRing->N)+1)*sizeof(short)); |
---|
| 1653 | // ecartWeights=NULL; |
---|
| 1654 | // } |
---|
| 1655 | // } |
---|
[930ea8] | 1656 | if (TEST_OPT_PROT) messageStat(hilbcount,strat); |
---|
[3772383] | 1657 | SI_RESTORE_OPT1(save); |
---|
[35aab3] | 1658 | if (Q!=NULL) updateResult(strat->Shdl,Q,strat); |
---|
[645a19] | 1659 | |
---|
| 1660 | #ifdef KDEBUG |
---|
| 1661 | #if MYTEST |
---|
| 1662 | PrintS("bba_end: currRing: "); rWrite(currRing); |
---|
| 1663 | #endif /* MYTEST */ |
---|
| 1664 | #endif /* KDEBUG */ |
---|
| 1665 | idTest(strat->Shdl); |
---|
| 1666 | |
---|
[35aab3] | 1667 | return (strat->Shdl); |
---|
| 1668 | } |
---|
[83be980] | 1669 | ideal sba (ideal F0, ideal Q,intvec *w,intvec *hilb,kStrategy strat) |
---|
| 1670 | { |
---|
| 1671 | // ring order stuff: |
---|
| 1672 | // in sba we have (until now) two possibilities: |
---|
| 1673 | // 1. an incremental computation w.r.t. (C,monomial order) |
---|
[601105] | 1674 | // 2. a (possibly non-incremental) computation w.r.t. the |
---|
[83be980] | 1675 | // induced Schreyer order. |
---|
| 1676 | // The corresponding orders are computed in sbaRing(), depending |
---|
[f7f084] | 1677 | // on the flag strat->sbaOrder |
---|
[6d77472] | 1678 | #if SBA_PRINT_ZERO_REDUCTIONS |
---|
[f59aaa] | 1679 | long zeroreductions = 0; |
---|
[6d77472] | 1680 | #endif |
---|
| 1681 | #if SBA_PRINT_PRODUCT_CRITERION |
---|
[f59aaa] | 1682 | long product_criterion = 0; |
---|
[6d77472] | 1683 | #endif |
---|
| 1684 | #if SBA_PRINT_SIZE_G |
---|
[f59aaa] | 1685 | long size_g = 0; |
---|
[6d77472] | 1686 | #endif |
---|
| 1687 | #if SBA_PRINT_SIZE_SYZ |
---|
[f59aaa] | 1688 | long size_syz = 0; |
---|
[6d77472] | 1689 | #endif |
---|
[f9d20d7] | 1690 | // global variable |
---|
[6d77472] | 1691 | #if SBA_PRINT_REDUCTION_STEPS |
---|
[f59aaa] | 1692 | sba_reduction_steps = 0; |
---|
| 1693 | sba_interreduction_steps = 0; |
---|
[6d77472] | 1694 | #endif |
---|
| 1695 | #if SBA_PRINT_OPERATIONS |
---|
| 1696 | sba_operations = 0; |
---|
[f59aaa] | 1697 | sba_interreduction_operations = 0; |
---|
[6d77472] | 1698 | #endif |
---|
[b3e94aa] | 1699 | |
---|
[83be980] | 1700 | ideal F = F0; |
---|
| 1701 | ring sRing, currRingOld; |
---|
[601105] | 1702 | currRingOld = currRing; |
---|
[f7f084] | 1703 | if (strat->sbaOrder == 1) |
---|
[83be980] | 1704 | { |
---|
| 1705 | sRing = sbaRing(strat); |
---|
| 1706 | if (sRing!=currRingOld) |
---|
| 1707 | { |
---|
| 1708 | rChangeCurrRing (sRing); |
---|
[fee33e] | 1709 | F = idrMoveR (F0, currRingOld, currRing); |
---|
[83be980] | 1710 | } |
---|
| 1711 | } |
---|
| 1712 | #if 0 |
---|
| 1713 | printf("SBA COMPUTATIONS DONE IN THE FOLLOWING RING:\n"); |
---|
| 1714 | rWrite (currRing); |
---|
| 1715 | printf("\n"); |
---|
| 1716 | #endif |
---|
| 1717 | #ifdef KDEBUG |
---|
| 1718 | bba_count++; |
---|
| 1719 | int loop_count = 0; |
---|
| 1720 | #endif /* KDEBUG */ |
---|
| 1721 | int srmax,lrmax, red_result = 1; |
---|
| 1722 | int olddeg,reduc; |
---|
| 1723 | int hilbeledeg=1,hilbcount=0,minimcnt=0; |
---|
| 1724 | LObject L; |
---|
[576f5b] | 1725 | BOOLEAN withT = TRUE; |
---|
[83be980] | 1726 | strat->max_lower_index = 0; |
---|
| 1727 | |
---|
| 1728 | //initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/ |
---|
| 1729 | initSbaCrit(strat); /*set Gebauer, honey, sugarCrit*/ |
---|
| 1730 | initSbaPos(strat); |
---|
| 1731 | //initBuchMoraPos(strat); |
---|
| 1732 | initHilbCrit(F,Q,&hilb,strat); |
---|
| 1733 | initSba(F,strat); |
---|
| 1734 | /*set enterS, spSpolyShort, reduce, red, initEcart, initEcartPair*/ |
---|
| 1735 | /*Shdl=*/initSbaBuchMora(F, Q,strat); |
---|
| 1736 | if (strat->minim>0) strat->M=idInit(IDELEMS(F),F->rank); |
---|
| 1737 | srmax = strat->sl; |
---|
| 1738 | reduc = olddeg = lrmax = 0; |
---|
| 1739 | |
---|
| 1740 | #ifndef NO_BUCKETS |
---|
| 1741 | if (!TEST_OPT_NOT_BUCKETS) |
---|
| 1742 | strat->use_buckets = 1; |
---|
| 1743 | #endif |
---|
| 1744 | |
---|
| 1745 | // redtailBBa against T for inhomogenous input |
---|
[cd4f24] | 1746 | // if (!TEST_OPT_OLDSTD) |
---|
| 1747 | // withT = ! strat->homog; |
---|
[83be980] | 1748 | |
---|
| 1749 | // strat->posInT = posInT_pLength; |
---|
[d101b1] | 1750 | assume(kTest_TS(strat)); |
---|
[83be980] | 1751 | |
---|
| 1752 | #ifdef KDEBUG |
---|
| 1753 | #if MYTEST |
---|
| 1754 | if (TEST_OPT_DEBUG) |
---|
| 1755 | { |
---|
| 1756 | PrintS("bba start GB: currRing: "); |
---|
| 1757 | // rWrite(currRing);PrintLn(); |
---|
| 1758 | rDebugPrint(currRing); |
---|
| 1759 | PrintLn(); |
---|
| 1760 | } |
---|
| 1761 | #endif /* MYTEST */ |
---|
| 1762 | #endif /* KDEBUG */ |
---|
| 1763 | |
---|
| 1764 | #ifdef HAVE_TAIL_RING |
---|
[fee33e] | 1765 | if(!idIs0(F) &&(!rField_is_Ring(currRing))) // create strong gcd poly computes with tailring and S[i] ->to be fixed |
---|
[83be980] | 1766 | kStratInitChangeTailRing(strat); |
---|
| 1767 | #endif |
---|
| 1768 | if (BVERBOSE(23)) |
---|
| 1769 | { |
---|
| 1770 | if (test_PosInT!=NULL) strat->posInT=test_PosInT; |
---|
| 1771 | if (test_PosInL!=NULL) strat->posInL=test_PosInL; |
---|
| 1772 | kDebugPrint(strat); |
---|
| 1773 | } |
---|
| 1774 | |
---|
| 1775 | |
---|
| 1776 | #ifdef KDEBUG |
---|
| 1777 | //kDebugPrint(strat); |
---|
| 1778 | #endif |
---|
| 1779 | /* compute------------------------------------------------------- */ |
---|
| 1780 | while (strat->Ll >= 0) |
---|
| 1781 | { |
---|
| 1782 | if (strat->Ll > lrmax) lrmax =strat->Ll;/*stat.*/ |
---|
| 1783 | #ifdef KDEBUG |
---|
| 1784 | loop_count++; |
---|
| 1785 | if (TEST_OPT_DEBUG) messageSets(strat); |
---|
| 1786 | #endif |
---|
| 1787 | if (strat->Ll== 0) strat->interpt=TRUE; |
---|
| 1788 | if (TEST_OPT_DEGBOUND |
---|
[fee33e] | 1789 | && ((strat->honey && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg)) |
---|
| 1790 | || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg)))) |
---|
[83be980] | 1791 | { |
---|
| 1792 | /* |
---|
| 1793 | *stops computation if |
---|
| 1794 | * 24 IN test and the degree +ecart of L[strat->Ll] is bigger then |
---|
| 1795 | *a predefined number Kstd1_deg |
---|
| 1796 | */ |
---|
| 1797 | while ((strat->Ll >= 0) |
---|
| 1798 | && (strat->L[strat->Ll].p1!=NULL) && (strat->L[strat->Ll].p2!=NULL) |
---|
[fee33e] | 1799 | && ((strat->honey && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg)) |
---|
| 1800 | || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))) |
---|
[83be980] | 1801 | ) |
---|
| 1802 | deleteInL(strat->L,&strat->Ll,strat->Ll,strat); |
---|
| 1803 | if (strat->Ll<0) break; |
---|
| 1804 | else strat->noClearS=TRUE; |
---|
| 1805 | } |
---|
[f7f084] | 1806 | if (strat->sbaOrder == 1 && pGetComp(strat->L[strat->Ll].sig) != strat->currIdx) |
---|
[83be980] | 1807 | { |
---|
| 1808 | strat->currIdx = pGetComp(strat->L[strat->Ll].sig); |
---|
| 1809 | #if F5C |
---|
| 1810 | // 1. interreduction of the current standard basis |
---|
| 1811 | // 2. generation of new principal syzygy rules for syzCriterion |
---|
[601105] | 1812 | f5c ( strat, olddeg, minimcnt, hilbeledeg, hilbcount, srmax, |
---|
[83be980] | 1813 | lrmax, reduc, Q, w, hilb ); |
---|
| 1814 | #endif |
---|
[601105] | 1815 | // initialize new syzygy rules for the next iteration step |
---|
[83be980] | 1816 | initSyzRules(strat); |
---|
| 1817 | } |
---|
| 1818 | /********************************************************************* |
---|
| 1819 | * interrreduction step is done, we can go on with the next iteration |
---|
| 1820 | * step of the signature-based algorithm |
---|
| 1821 | ********************************************************************/ |
---|
| 1822 | /* picks the last element from the lazyset L */ |
---|
| 1823 | strat->P = strat->L[strat->Ll]; |
---|
| 1824 | strat->Ll--; |
---|
| 1825 | //#if 1 |
---|
| 1826 | #ifdef DEBUGF5 |
---|
| 1827 | Print("SIG OF NEXT PAIR TO HANDLE IN SIG-BASED ALGORITHM\n"); |
---|
| 1828 | Print("-------------------------------------------------\n"); |
---|
| 1829 | pWrite(strat->P.sig); |
---|
| 1830 | pWrite(pHead(strat->P.p)); |
---|
| 1831 | pWrite(pHead(strat->P.p1)); |
---|
| 1832 | pWrite(pHead(strat->P.p2)); |
---|
| 1833 | Print("-------------------------------------------------\n"); |
---|
| 1834 | #endif |
---|
| 1835 | if (pNext(strat->P.p) == strat->tail) |
---|
| 1836 | { |
---|
| 1837 | // deletes the short spoly |
---|
| 1838 | #ifdef HAVE_RINGS |
---|
| 1839 | if (rField_is_Ring(currRing)) |
---|
| 1840 | pLmDelete(strat->P.p); |
---|
| 1841 | else |
---|
| 1842 | #endif |
---|
| 1843 | pLmFree(strat->P.p); |
---|
| 1844 | |
---|
| 1845 | // TODO: needs some masking |
---|
| 1846 | // TODO: masking needs to vanish once the signature |
---|
| 1847 | // sutff is completely implemented |
---|
| 1848 | strat->P.p = NULL; |
---|
| 1849 | poly m1 = NULL, m2 = NULL; |
---|
| 1850 | |
---|
| 1851 | // check that spoly creation is ok |
---|
| 1852 | while (strat->tailRing != currRing && |
---|
| 1853 | !kCheckSpolyCreation(&(strat->P), strat, m1, m2)) |
---|
| 1854 | { |
---|
| 1855 | assume(m1 == NULL && m2 == NULL); |
---|
| 1856 | // if not, change to a ring where exponents are at least |
---|
| 1857 | // large enough |
---|
| 1858 | if (!kStratChangeTailRing(strat)) |
---|
| 1859 | { |
---|
| 1860 | WerrorS("OVERFLOW..."); |
---|
| 1861 | break; |
---|
| 1862 | } |
---|
| 1863 | } |
---|
| 1864 | // create the real one |
---|
| 1865 | ksCreateSpoly(&(strat->P), NULL, strat->use_buckets, |
---|
| 1866 | strat->tailRing, m1, m2, strat->R); |
---|
| 1867 | |
---|
| 1868 | } |
---|
| 1869 | else if (strat->P.p1 == NULL) |
---|
| 1870 | { |
---|
| 1871 | if (strat->minim > 0) |
---|
| 1872 | strat->P.p2=p_Copy(strat->P.p, currRing, strat->tailRing); |
---|
| 1873 | // for input polys, prepare reduction |
---|
| 1874 | strat->P.PrepareRed(strat->use_buckets); |
---|
| 1875 | } |
---|
| 1876 | |
---|
| 1877 | if (strat->P.p == NULL && strat->P.t_p == NULL) |
---|
| 1878 | { |
---|
| 1879 | red_result = 0; |
---|
| 1880 | } |
---|
| 1881 | else |
---|
| 1882 | { |
---|
| 1883 | if (TEST_OPT_PROT) |
---|
| 1884 | message((strat->honey ? strat->P.ecart : 0) + strat->P.pFDeg(), |
---|
| 1885 | &olddeg,&reduc,strat, red_result); |
---|
| 1886 | |
---|
| 1887 | //#if 1 |
---|
| 1888 | #ifdef DEBUGF5 |
---|
| 1889 | Print("Poly before red: "); |
---|
| 1890 | pWrite(strat->P.p); |
---|
| 1891 | #endif |
---|
| 1892 | /* reduction of the element choosen from L */ |
---|
[b3e94aa] | 1893 | if (!strat->rewCrit2(strat->P.sig, ~strat->P.sevSig, strat, strat->P.checked+1)) { |
---|
| 1894 | #if SBA_PRODUCT_CRITERION |
---|
| 1895 | if (strat->P.checked == 3) { |
---|
| 1896 | product_criterion++; |
---|
| 1897 | enterSyz(strat->P, strat); |
---|
| 1898 | if (strat->P.lcm!=NULL) |
---|
| 1899 | pLmFree(strat->P.lcm); |
---|
| 1900 | red_result = 2; |
---|
| 1901 | } else { |
---|
| 1902 | red_result = strat->red(&strat->P,strat); |
---|
| 1903 | } |
---|
| 1904 | #else |
---|
| 1905 | red_result = strat->red(&strat->P,strat); |
---|
| 1906 | #endif |
---|
| 1907 | } else { |
---|
[83be980] | 1908 | if (strat->P.lcm!=NULL) |
---|
| 1909 | pLmFree(strat->P.lcm); |
---|
| 1910 | red_result = 2; |
---|
| 1911 | } |
---|
| 1912 | if (errorreported) break; |
---|
| 1913 | } |
---|
| 1914 | |
---|
| 1915 | if (strat->overflow) |
---|
| 1916 | { |
---|
| 1917 | if (!kStratChangeTailRing(strat)) { Werror("OVERFLOW.."); break;} |
---|
| 1918 | } |
---|
| 1919 | |
---|
| 1920 | // reduction to non-zero new poly |
---|
| 1921 | if (red_result == 1) |
---|
| 1922 | { |
---|
| 1923 | // get the polynomial (canonicalize bucket, make sure P.p is set) |
---|
| 1924 | strat->P.GetP(strat->lmBin); |
---|
[601105] | 1925 | |
---|
| 1926 | // sig-safe computations may lead to wrong FDeg computation, thus we need |
---|
[83be980] | 1927 | // to recompute it to make sure everything is alright |
---|
| 1928 | (strat->P).FDeg = (strat->P).pFDeg(); |
---|
| 1929 | // in the homogeneous case FDeg >= pFDeg (sugar/honey) |
---|
| 1930 | // but now, for entering S, T, we reset it |
---|
| 1931 | // in the inhomogeneous case: FDeg == pFDeg |
---|
| 1932 | if (strat->homog) strat->initEcart(&(strat->P)); |
---|
| 1933 | |
---|
| 1934 | /* statistic */ |
---|
| 1935 | if (TEST_OPT_PROT) PrintS("s"); |
---|
| 1936 | |
---|
| 1937 | //int pos=posInS(strat,strat->sl,strat->P.p,strat->P.ecart); |
---|
| 1938 | // in F5E we know that the last reduced element is already the |
---|
| 1939 | // the one with highest signature |
---|
| 1940 | int pos = strat->sl+1; |
---|
| 1941 | |
---|
| 1942 | #ifdef KDEBUG |
---|
| 1943 | #if MYTEST |
---|
| 1944 | PrintS("New S: "); pDebugPrint(strat->P.p); PrintLn(); |
---|
| 1945 | #endif /* MYTEST */ |
---|
| 1946 | #endif /* KDEBUG */ |
---|
| 1947 | |
---|
| 1948 | // reduce the tail and normalize poly |
---|
| 1949 | // in the ring case we cannot expect LC(f) = 1, |
---|
| 1950 | // therefore we call pContent instead of pNorm |
---|
[b085fba] | 1951 | #if SBA_TAIL_RED |
---|
[83be980] | 1952 | if ((TEST_OPT_INTSTRATEGY) || (rField_is_Ring(currRing))) |
---|
| 1953 | { |
---|
| 1954 | strat->P.pCleardenom(); |
---|
| 1955 | if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL)) |
---|
| 1956 | { |
---|
[b085fba] | 1957 | strat->P.p = redtailSba(&(strat->P),pos-1,strat, withT); |
---|
[83be980] | 1958 | strat->P.pCleardenom(); |
---|
| 1959 | } |
---|
| 1960 | } |
---|
| 1961 | else |
---|
| 1962 | { |
---|
| 1963 | strat->P.pNorm(); |
---|
| 1964 | if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL)) |
---|
[b085fba] | 1965 | strat->P.p = redtailSba(&(strat->P),pos-1,strat, withT); |
---|
[83be980] | 1966 | } |
---|
[b085fba] | 1967 | #endif |
---|
[576f5b] | 1968 | |
---|
| 1969 | // remove sigsafe label since it is no longer valid for the next element to |
---|
| 1970 | // be reduced |
---|
[f7f084] | 1971 | if (strat->sbaOrder == 1) |
---|
[576f5b] | 1972 | { |
---|
| 1973 | for (int jj = 0; jj<strat->tl+1; jj++) |
---|
| 1974 | { |
---|
| 1975 | if (pGetComp(strat->T[jj].sig) == strat->currIdx) |
---|
| 1976 | { |
---|
| 1977 | strat->T[jj].is_sigsafe = FALSE; |
---|
| 1978 | } |
---|
| 1979 | } |
---|
| 1980 | } |
---|
| 1981 | else |
---|
| 1982 | { |
---|
| 1983 | for (int jj = 0; jj<strat->tl+1; jj++) |
---|
| 1984 | { |
---|
| 1985 | strat->T[jj].is_sigsafe = FALSE; |
---|
| 1986 | } |
---|
| 1987 | } |
---|
[83be980] | 1988 | #ifdef KDEBUG |
---|
| 1989 | if (TEST_OPT_DEBUG){PrintS("new s:");strat->P.wrp();PrintLn();} |
---|
| 1990 | #if MYTEST |
---|
| 1991 | //#if 1 |
---|
| 1992 | PrintS("New (reduced) S: "); pDebugPrint(strat->P.p); PrintLn(); |
---|
| 1993 | #endif /* MYTEST */ |
---|
| 1994 | #endif /* KDEBUG */ |
---|
| 1995 | |
---|
| 1996 | // min_std stuff |
---|
| 1997 | if ((strat->P.p1==NULL) && (strat->minim>0)) |
---|
| 1998 | { |
---|
| 1999 | if (strat->minim==1) |
---|
| 2000 | { |
---|
| 2001 | strat->M->m[minimcnt]=p_Copy(strat->P.p,currRing,strat->tailRing); |
---|
| 2002 | p_Delete(&strat->P.p2, currRing, strat->tailRing); |
---|
| 2003 | } |
---|
| 2004 | else |
---|
| 2005 | { |
---|
| 2006 | strat->M->m[minimcnt]=strat->P.p2; |
---|
| 2007 | strat->P.p2=NULL; |
---|
| 2008 | } |
---|
| 2009 | if (strat->tailRing!=currRing && pNext(strat->M->m[minimcnt])!=NULL) |
---|
| 2010 | pNext(strat->M->m[minimcnt]) |
---|
| 2011 | = strat->p_shallow_copy_delete(pNext(strat->M->m[minimcnt]), |
---|
| 2012 | strat->tailRing, currRing, |
---|
| 2013 | currRing->PolyBin); |
---|
| 2014 | minimcnt++; |
---|
| 2015 | } |
---|
| 2016 | |
---|
| 2017 | // enter into S, L, and T |
---|
| 2018 | //if ((!TEST_OPT_IDLIFT) || (pGetComp(strat->P.p) <= strat->syzComp)) |
---|
[f7f084] | 2019 | if(!strat->sbaOrder == 1) |
---|
[83be980] | 2020 | { |
---|
| 2021 | BOOLEAN overwrite = TRUE; |
---|
| 2022 | for (int tk=0; tk<strat->sl+1; tk++) |
---|
| 2023 | { |
---|
| 2024 | if (pGetComp(strat->sig[tk]) == pGetComp(strat->P.sig)) |
---|
| 2025 | { |
---|
| 2026 | //printf("TK %d / %d\n",tk,strat->sl); |
---|
| 2027 | overwrite = FALSE; |
---|
| 2028 | break; |
---|
| 2029 | } |
---|
| 2030 | } |
---|
| 2031 | //printf("OVERWRITE %d\n",overwrite); |
---|
| 2032 | if (overwrite) |
---|
| 2033 | { |
---|
| 2034 | int cmp = pGetComp(strat->P.sig); |
---|
| 2035 | int* vv = (int*)omAlloc((currRing->N+1)*sizeof(int)); |
---|
| 2036 | pGetExpV (strat->P.p,vv); |
---|
| 2037 | pSetExpV (strat->P.sig, vv); |
---|
| 2038 | pSetComp (strat->P.sig,cmp); |
---|
| 2039 | |
---|
| 2040 | strat->P.sevSig = pGetShortExpVector (strat->P.sig); |
---|
| 2041 | for(int ps=0;ps<strat->sl+1;ps++) |
---|
| 2042 | { |
---|
| 2043 | int i = strat->syzl; |
---|
| 2044 | |
---|
| 2045 | strat->newt = TRUE; |
---|
| 2046 | if (strat->syzl == strat->syzmax) |
---|
| 2047 | { |
---|
| 2048 | pEnlargeSet(&strat->syz,strat->syzmax,setmaxTinc); |
---|
| 2049 | strat->sevSyz = (unsigned long*) omRealloc0Size(strat->sevSyz, |
---|
| 2050 | (strat->syzmax)*sizeof(unsigned long), |
---|
| 2051 | ((strat->syzmax)+setmaxTinc) |
---|
| 2052 | *sizeof(unsigned long)); |
---|
| 2053 | strat->syzmax += setmaxTinc; |
---|
| 2054 | } |
---|
| 2055 | strat->syz[i] = pCopy(strat->P.sig); |
---|
| 2056 | // add LM(F->m[i]) to the signature to get a Schreyer order |
---|
| 2057 | // without changing the underlying polynomial ring at all |
---|
[601105] | 2058 | p_ExpVectorAdd (strat->syz[i],strat->S[ps],currRing); |
---|
[83be980] | 2059 | // since p_Add_q() destroys all input |
---|
[601105] | 2060 | // data we need to recreate help |
---|
[83be980] | 2061 | // each time |
---|
| 2062 | // ---------------------------------------------------------- |
---|
[601105] | 2063 | // in the Schreyer order we always know that the multiplied |
---|
[83be980] | 2064 | // module monomial strat->P.sig gives the leading monomial of |
---|
| 2065 | // the corresponding principal syzygy |
---|
| 2066 | // => we do not need to compute the "real" syzygy completely |
---|
| 2067 | poly help = pCopy(strat->sig[ps]); |
---|
[601105] | 2068 | p_ExpVectorAdd (help,strat->P.p,currRing); |
---|
[83be980] | 2069 | strat->syz[i] = p_Add_q(strat->syz[i],help,currRing); |
---|
| 2070 | //printf("%d. SYZ ",i+1); |
---|
| 2071 | //pWrite(strat->syz[i]); |
---|
| 2072 | strat->sevSyz[i] = p_GetShortExpVector(strat->syz[i],currRing); |
---|
| 2073 | strat->syzl++; |
---|
| 2074 | } |
---|
| 2075 | } |
---|
| 2076 | } |
---|
[601105] | 2077 | enterT(strat->P, strat); |
---|
| 2078 | strat->T[strat->tl].is_sigsafe = FALSE; |
---|
[83be980] | 2079 | #ifdef HAVE_RINGS |
---|
| 2080 | if (rField_is_Ring(currRing)) |
---|
| 2081 | superenterpairs(strat->P.p,strat->sl,strat->P.ecart,pos,strat, strat->tl); |
---|
| 2082 | else |
---|
| 2083 | #endif |
---|
| 2084 | enterpairsSig(strat->P.p,strat->P.sig,strat->sl+1,strat->sl,strat->P.ecart,pos,strat, strat->tl); |
---|
| 2085 | // posInS only depends on the leading term |
---|
| 2086 | strat->enterS(strat->P, pos, strat, strat->tl); |
---|
[576f5b] | 2087 | //#if 1 |
---|
| 2088 | #if DEBUGF50 |
---|
[83be980] | 2089 | printf("---------------------------\n"); |
---|
| 2090 | Print(" %d. ELEMENT ADDED TO GCURR:\n",strat->sl+1); |
---|
| 2091 | Print("LEAD POLY: "); pWrite(pHead(strat->S[strat->sl])); |
---|
| 2092 | Print("SIGNATURE: "); pWrite(strat->sig[strat->sl]); |
---|
| 2093 | #endif |
---|
| 2094 | /* |
---|
| 2095 | if (newrules) |
---|
| 2096 | { |
---|
| 2097 | newrules = FALSE; |
---|
| 2098 | } |
---|
| 2099 | */ |
---|
| 2100 | #if 0 |
---|
| 2101 | int pl=pLength(strat->P.p); |
---|
| 2102 | if (pl==1) |
---|
| 2103 | { |
---|
| 2104 | //if (TEST_OPT_PROT) |
---|
| 2105 | //PrintS("<1>"); |
---|
| 2106 | } |
---|
| 2107 | else if (pl==2) |
---|
| 2108 | { |
---|
| 2109 | //if (TEST_OPT_PROT) |
---|
| 2110 | //PrintS("<2>"); |
---|
| 2111 | } |
---|
| 2112 | #endif |
---|
| 2113 | if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat); |
---|
| 2114 | // Print("[%d]",hilbeledeg); |
---|
| 2115 | if (strat->P.lcm!=NULL) |
---|
| 2116 | #ifdef HAVE_RINGS |
---|
| 2117 | pLmDelete(strat->P.lcm); |
---|
| 2118 | #else |
---|
| 2119 | pLmFree(strat->P.lcm); |
---|
| 2120 | #endif |
---|
| 2121 | if (strat->sl>srmax) srmax = strat->sl; |
---|
| 2122 | } |
---|
| 2123 | else |
---|
| 2124 | { |
---|
| 2125 | // adds signature of the zero reduction to |
---|
| 2126 | // strat->syz. This is the leading term of |
---|
| 2127 | // syzygy and can be used in syzCriterion() |
---|
| 2128 | // the signature is added if and only if the |
---|
| 2129 | // pair was not detected by the rewritten criterion in strat->red = redSig |
---|
| 2130 | if (red_result!=2) { |
---|
[6d77472] | 2131 | #if SBA_PRINT_ZERO_REDUCTIONS |
---|
[83be980] | 2132 | zeroreductions++; |
---|
[6d77472] | 2133 | #endif |
---|
[83be980] | 2134 | enterSyz(strat->P,strat); |
---|
| 2135 | //#if 1 |
---|
| 2136 | #ifdef DEBUGF5 |
---|
| 2137 | Print("ADDING STUFF TO SYZ : "); |
---|
| 2138 | pWrite(strat->P.p); |
---|
| 2139 | pWrite(strat->P.sig); |
---|
| 2140 | #endif |
---|
| 2141 | } |
---|
| 2142 | if (strat->P.p1 == NULL && strat->minim > 0) |
---|
| 2143 | { |
---|
| 2144 | p_Delete(&strat->P.p2, currRing, strat->tailRing); |
---|
| 2145 | } |
---|
| 2146 | } |
---|
| 2147 | |
---|
| 2148 | #ifdef KDEBUG |
---|
| 2149 | memset(&(strat->P), 0, sizeof(strat->P)); |
---|
| 2150 | #endif /* KDEBUG */ |
---|
[d101b1] | 2151 | assume(kTest_TS(strat)); |
---|
[83be980] | 2152 | } |
---|
| 2153 | #ifdef KDEBUG |
---|
| 2154 | #if MYTEST |
---|
| 2155 | PrintS("bba finish GB: currRing: "); rWrite(currRing); |
---|
| 2156 | #endif /* MYTEST */ |
---|
| 2157 | if (TEST_OPT_DEBUG) messageSets(strat); |
---|
| 2158 | #endif /* KDEBUG */ |
---|
| 2159 | |
---|
| 2160 | if (TEST_OPT_SB_1) |
---|
| 2161 | { |
---|
| 2162 | int k=1; |
---|
| 2163 | int j; |
---|
| 2164 | while(k<=strat->sl) |
---|
| 2165 | { |
---|
| 2166 | j=0; |
---|
| 2167 | loop |
---|
| 2168 | { |
---|
| 2169 | if (j>=k) break; |
---|
| 2170 | clearS(strat->S[j],strat->sevS[j],&k,&j,strat); |
---|
| 2171 | j++; |
---|
| 2172 | } |
---|
| 2173 | k++; |
---|
| 2174 | } |
---|
| 2175 | } |
---|
| 2176 | |
---|
| 2177 | /* complete reduction of the standard basis--------- */ |
---|
| 2178 | if (TEST_OPT_REDSB) |
---|
| 2179 | { |
---|
| 2180 | completeReduce(strat); |
---|
| 2181 | #ifdef HAVE_TAIL_RING |
---|
| 2182 | if (strat->completeReduce_retry) |
---|
| 2183 | { |
---|
| 2184 | // completeReduce needed larger exponents, retry |
---|
| 2185 | // to reduce with S (instead of T) |
---|
| 2186 | // and in currRing (instead of strat->tailRing) |
---|
| 2187 | cleanT(strat);strat->tailRing=currRing; |
---|
| 2188 | int i; |
---|
| 2189 | for(i=strat->sl;i>=0;i--) strat->S_2_R[i]=-1; |
---|
| 2190 | completeReduce(strat); |
---|
| 2191 | } |
---|
| 2192 | #endif |
---|
| 2193 | } |
---|
| 2194 | else if (TEST_OPT_PROT) PrintLn(); |
---|
| 2195 | |
---|
[b3e94aa] | 2196 | #if SBA_PRINT_SIZE_G |
---|
| 2197 | size_g = strat->sl+1; |
---|
| 2198 | #endif |
---|
| 2199 | #if SBA_PRINT_SIZE_SYZ |
---|
| 2200 | size_syz = strat->syzl+1; |
---|
| 2201 | #endif |
---|
| 2202 | |
---|
[83be980] | 2203 | exitSba(strat); |
---|
[fee33e] | 2204 | // if (TEST_OPT_WEIGHTM) |
---|
| 2205 | // { |
---|
| 2206 | // pRestoreDegProcs(pFDegOld, pLDegOld); |
---|
| 2207 | // if (ecartWeights) |
---|
| 2208 | // { |
---|
| 2209 | // omFreeSize((ADDRESS)ecartWeights,(pVariables+1)*sizeof(short)); |
---|
| 2210 | // ecartWeights=NULL; |
---|
| 2211 | // } |
---|
| 2212 | // } |
---|
| 2213 | if (TEST_OPT_PROT) messageStat(hilbcount,strat); |
---|
[83be980] | 2214 | if (Q!=NULL) updateResult(strat->Shdl,Q,strat); |
---|
| 2215 | |
---|
| 2216 | #ifdef KDEBUG |
---|
| 2217 | #if MYTEST |
---|
| 2218 | PrintS("bba_end: currRing: "); rWrite(currRing); |
---|
| 2219 | #endif /* MYTEST */ |
---|
| 2220 | #endif /* KDEBUG */ |
---|
| 2221 | // using F5C it is possible that there is some data stored in the last |
---|
| 2222 | // entries of strat->Shdl which are dirty, i.e. not correct, but also not NULL |
---|
| 2223 | // => we need to delete them before return the ideal |
---|
| 2224 | #if F5C |
---|
| 2225 | for(int i=strat->sl+1;i<IDELEMS(strat->Shdl);i++) |
---|
| 2226 | { |
---|
| 2227 | //pDelete (&strat->Shdl->m[i]); |
---|
| 2228 | strat->Shdl->m[i] = NULL; |
---|
| 2229 | } |
---|
| 2230 | #endif |
---|
[f7f084] | 2231 | if (strat->sbaOrder == 1 && sRing!=currRingOld) |
---|
[83be980] | 2232 | { |
---|
| 2233 | rChangeCurrRing (currRingOld); |
---|
[fee33e] | 2234 | F0 = idrMoveR (F, sRing, currRing); |
---|
| 2235 | strat->Shdl = idrMoveR_NoSort (strat->Shdl, sRing, currRing); |
---|
[83be980] | 2236 | rDelete (sRing); |
---|
| 2237 | } |
---|
| 2238 | idTest(strat->Shdl); |
---|
| 2239 | |
---|
| 2240 | #ifdef DEBUGF5 |
---|
| 2241 | printf("SIZE OF SHDL: %d\n",IDELEMS(strat->Shdl)); |
---|
| 2242 | int oo = 0; |
---|
| 2243 | while (oo<IDELEMS(strat->Shdl)) |
---|
| 2244 | { |
---|
| 2245 | printf(" %d. ",oo+1); |
---|
| 2246 | pWrite(pHead(strat->Shdl->m[oo])); |
---|
| 2247 | oo++; |
---|
| 2248 | } |
---|
| 2249 | #endif |
---|
[b3e94aa] | 2250 | #if SBA_PRINT_ZERO_REDUCTIONS |
---|
[f59aaa] | 2251 | printf("----------------------------------------------------------\n"); |
---|
| 2252 | printf("ZERO REDUCTIONS: %ld\n",zeroreductions); |
---|
[6d77472] | 2253 | zeroreductions = 0; |
---|
[b3e94aa] | 2254 | #endif |
---|
[f9d20d7] | 2255 | #if SBA_PRINT_REDUCTION_STEPS |
---|
[f59aaa] | 2256 | printf("----------------------------------------------------------\n"); |
---|
[6d77472] | 2257 | printf("S-REDUCTIONS: %ld\n",sba_reduction_steps); |
---|
[f59aaa] | 2258 | #endif |
---|
| 2259 | #if SBA_PRINT_OPERATIONS |
---|
| 2260 | printf("OPERATIONS: %ld\n",sba_operations); |
---|
| 2261 | #endif |
---|
[6d77472] | 2262 | #if SBA_PRINT_REDUCTION_STEPS |
---|
[f59aaa] | 2263 | printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n"); |
---|
| 2264 | printf("INTERREDUCTIONS: %ld\n",sba_interreduction_steps); |
---|
| 2265 | #endif |
---|
[6d77472] | 2266 | #if SBA_PRINT_REDUCTION_OPERATIONS |
---|
[f59aaa] | 2267 | printf("INTERREDUCTION OPERATIONS: %ld\n",sba_interreduction_operations); |
---|
| 2268 | #endif |
---|
[6d77472] | 2269 | #if SBA_PRINT_REDUCTION_STEPS |
---|
[f59aaa] | 2270 | printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n"); |
---|
| 2271 | printf("ALL REDUCTIONS: %ld\n",sba_reduction_steps+sba_interreduction_steps); |
---|
[6d77472] | 2272 | sba_interreduction_steps = 0; |
---|
| 2273 | sba_reduction_steps = 0; |
---|
[f9d20d7] | 2274 | #endif |
---|
[6d77472] | 2275 | #if SBA_PRINT_OPERATIONS |
---|
[f59aaa] | 2276 | printf("ALL OPERATIONS: %ld\n",sba_operations+sba_interreduction_operations); |
---|
[6d77472] | 2277 | sba_interreduction_operations = 0; |
---|
| 2278 | sba_operations = 0; |
---|
[15b211] | 2279 | #endif |
---|
[b3e94aa] | 2280 | #if SBA_PRINT_SIZE_G |
---|
[f59aaa] | 2281 | printf("----------------------------------------------------------\n"); |
---|
| 2282 | printf("SIZE OF G: %ld\n",size_g); |
---|
[6d77472] | 2283 | size_g = 0; |
---|
[b3e94aa] | 2284 | #endif |
---|
| 2285 | #if SBA_PRINT_SIZE_SYZ |
---|
[f59aaa] | 2286 | printf("SIZE OF SYZ: %ld\n",size_syz); |
---|
| 2287 | printf("----------------------------------------------------------\n"); |
---|
[6d77472] | 2288 | size_syz = 0; |
---|
[b3e94aa] | 2289 | #endif |
---|
| 2290 | #if SBA_PRINT_PRODUCT_CRITERION |
---|
[f59aaa] | 2291 | printf("PRODUCT CRITERIA: %ld\n",product_criterion); |
---|
[6d77472] | 2292 | product_criterion = 0; |
---|
[f59aaa] | 2293 | #endif |
---|
[83be980] | 2294 | return (strat->Shdl); |
---|
| 2295 | } |
---|
| 2296 | |
---|
| 2297 | poly kNF2 (ideal F,ideal Q,poly q,kStrategy strat, int lazyReduce) |
---|
| 2298 | { |
---|
| 2299 | assume(q!=NULL); |
---|
| 2300 | assume(!(idIs0(F)&&(Q==NULL))); // NF(q, std(0) in polynomial ring? |
---|
| 2301 | |
---|
| 2302 | // lazy_reduce flags: can be combined by | |
---|
| 2303 | //#define KSTD_NF_LAZY 1 |
---|
| 2304 | // do only a reduction of the leading term |
---|
| 2305 | //#define KSTD_NF_NONORM 4 |
---|
| 2306 | // only global: avoid normalization, return a multiply of NF |
---|
| 2307 | poly p; |
---|
| 2308 | |
---|
| 2309 | //if ((idIs0(F))&&(Q==NULL)) |
---|
| 2310 | // return pCopy(q); /*F=0*/ |
---|
| 2311 | //strat->ak = idRankFreeModule(F); |
---|
| 2312 | /*- creating temp data structures------------------- -*/ |
---|
[d30a399] | 2313 | BITSET save1; |
---|
| 2314 | SI_SAVE_OPT1(save1); |
---|
| 2315 | si_opt_1|=Sy_bit(OPT_REDTAIL); |
---|
[83be980] | 2316 | initBuchMoraCrit(strat); |
---|
| 2317 | strat->initEcart = initEcartBBA; |
---|
| 2318 | strat->enterS = enterSBba; |
---|
| 2319 | #ifndef NO_BUCKETS |
---|
| 2320 | strat->use_buckets = (!TEST_OPT_NOT_BUCKETS) && (!rIsPluralRing(currRing)); |
---|
| 2321 | #endif |
---|
| 2322 | /*- set S -*/ |
---|
| 2323 | strat->sl = -1; |
---|
| 2324 | /*- init local data struct.---------------------------------------- -*/ |
---|
| 2325 | /*Shdl=*/initS(F,Q,strat); |
---|
| 2326 | /*- compute------------------------------------------------------- -*/ |
---|
| 2327 | //if ((TEST_OPT_INTSTRATEGY)&&(lazyReduce==0)) |
---|
| 2328 | //{ |
---|
| 2329 | // for (i=strat->sl;i>=0;i--) |
---|
| 2330 | // pNorm(strat->S[i]); |
---|
| 2331 | //} |
---|
[d101b1] | 2332 | assume(kTest(strat)); |
---|
[83be980] | 2333 | if (TEST_OPT_PROT) { PrintS("r"); mflush(); } |
---|
| 2334 | if (BVERBOSE(23)) kDebugPrint(strat); |
---|
| 2335 | int max_ind; |
---|
| 2336 | p = redNF(pCopy(q),max_ind,lazyReduce & KSTD_NF_NONORM,strat); |
---|
| 2337 | if ((p!=NULL)&&((lazyReduce & KSTD_NF_LAZY)==0)) |
---|
| 2338 | { |
---|
| 2339 | if (TEST_OPT_PROT) { PrintS("t"); mflush(); } |
---|
| 2340 | #ifdef HAVE_RINGS |
---|
| 2341 | if (rField_is_Ring(currRing)) |
---|
| 2342 | { |
---|
| 2343 | p = redtailBba_Z(p,max_ind,strat); |
---|
| 2344 | } |
---|
| 2345 | else |
---|
| 2346 | #endif |
---|
| 2347 | { |
---|
[d30a399] | 2348 | si_opt_1 &= ~Sy_bit(OPT_INTSTRATEGY); |
---|
[83be980] | 2349 | p = redtailBba(p,max_ind,strat,(lazyReduce & KSTD_NF_NONORM)==0); |
---|
| 2350 | } |
---|
| 2351 | } |
---|
| 2352 | /*- release temp data------------------------------- -*/ |
---|
[e14e025] | 2353 | assume(strat->L==NULL); /* strat->L unused */ |
---|
| 2354 | assume(strat->B==NULL); /* strat->B unused */ |
---|
| 2355 | omFree(strat->sevS); |
---|
| 2356 | omFree(strat->ecartS); |
---|
| 2357 | assume(strat->T==NULL);//omfree(strat->T); |
---|
| 2358 | assume(strat->sevT==NULL);//omfree(strat->sevT); |
---|
| 2359 | assume(strat->R==NULL);//omfree(strat->R); |
---|
[83be980] | 2360 | omfree(strat->S_2_R); |
---|
| 2361 | omfree(strat->fromQ); |
---|
| 2362 | idDelete(&strat->Shdl); |
---|
[d30a399] | 2363 | SI_RESTORE_OPT1(save1); |
---|
[83be980] | 2364 | if (TEST_OPT_PROT) PrintLn(); |
---|
| 2365 | return p; |
---|
| 2366 | } |
---|
| 2367 | |
---|
| 2368 | ideal kNF2 (ideal F,ideal Q,ideal q,kStrategy strat, int lazyReduce) |
---|
| 2369 | { |
---|
| 2370 | assume(!idIs0(q)); |
---|
| 2371 | assume(!(idIs0(F)&&(Q==NULL))); |
---|
| 2372 | // lazy_reduce flags: can be combined by | |
---|
| 2373 | //#define KSTD_NF_LAZY 1 |
---|
| 2374 | // do only a reduction of the leading term |
---|
| 2375 | //#define KSTD_NF_NONORM 4 |
---|
| 2376 | // only global: avoid normalization, return a multiply of NF |
---|
| 2377 | poly p; |
---|
| 2378 | int i; |
---|
| 2379 | ideal res; |
---|
| 2380 | int max_ind; |
---|
| 2381 | |
---|
| 2382 | //if (idIs0(q)) |
---|
| 2383 | // return idInit(IDELEMS(q),si_max(q->rank,F->rank)); |
---|
| 2384 | //if ((idIs0(F))&&(Q==NULL)) |
---|
| 2385 | // return idCopy(q); /*F=0*/ |
---|
| 2386 | //strat->ak = idRankFreeModule(F); |
---|
| 2387 | /*- creating temp data structures------------------- -*/ |
---|
[d30a399] | 2388 | BITSET save1; |
---|
| 2389 | SI_SAVE_OPT1(save1); |
---|
| 2390 | si_opt_1|=Sy_bit(OPT_REDTAIL); |
---|
[83be980] | 2391 | initBuchMoraCrit(strat); |
---|
| 2392 | strat->initEcart = initEcartBBA; |
---|
| 2393 | strat->enterS = enterSBba; |
---|
| 2394 | /*- set S -*/ |
---|
| 2395 | strat->sl = -1; |
---|
| 2396 | #ifndef NO_BUCKETS |
---|
| 2397 | strat->use_buckets = (!TEST_OPT_NOT_BUCKETS) && (!rIsPluralRing(currRing)); |
---|
| 2398 | #endif |
---|
| 2399 | /*- init local data struct.---------------------------------------- -*/ |
---|
| 2400 | /*Shdl=*/initS(F,Q,strat); |
---|
| 2401 | /*- compute------------------------------------------------------- -*/ |
---|
| 2402 | res=idInit(IDELEMS(q),si_max(q->rank,F->rank)); |
---|
[d30a399] | 2403 | si_opt_1 &= ~Sy_bit(OPT_INTSTRATEGY); |
---|
[83be980] | 2404 | for (i=IDELEMS(q)-1; i>=0; i--) |
---|
| 2405 | { |
---|
| 2406 | if (q->m[i]!=NULL) |
---|
| 2407 | { |
---|
| 2408 | if (TEST_OPT_PROT) { PrintS("r");mflush(); } |
---|
| 2409 | p = redNF(pCopy(q->m[i]),max_ind,lazyReduce & KSTD_NF_NONORM,strat); |
---|
| 2410 | if ((p!=NULL)&&((lazyReduce & KSTD_NF_LAZY)==0)) |
---|
| 2411 | { |
---|
| 2412 | if (TEST_OPT_PROT) { PrintS("t"); mflush(); } |
---|
| 2413 | #ifdef HAVE_RINGS |
---|
| 2414 | if (rField_is_Ring(currRing)) |
---|
| 2415 | { |
---|
| 2416 | p = redtailBba_Z(p,max_ind,strat); |
---|
| 2417 | } |
---|
| 2418 | else |
---|
| 2419 | #endif |
---|
| 2420 | { |
---|
| 2421 | p = redtailBba(p,max_ind,strat,(lazyReduce & KSTD_NF_NONORM)==0); |
---|
| 2422 | } |
---|
| 2423 | } |
---|
| 2424 | res->m[i]=p; |
---|
| 2425 | } |
---|
| 2426 | //else |
---|
| 2427 | // res->m[i]=NULL; |
---|
| 2428 | } |
---|
| 2429 | /*- release temp data------------------------------- -*/ |
---|
[e14e025] | 2430 | assume(strat->L==NULL); /* strat->L unused */ |
---|
| 2431 | assume(strat->B==NULL); /* strat->B unused */ |
---|
| 2432 | omFree(strat->sevS); |
---|
| 2433 | omFree(strat->ecartS); |
---|
| 2434 | assume(strat->T==NULL);//omfree(strat->T); |
---|
| 2435 | assume(strat->sevT==NULL);//omfree(strat->sevT); |
---|
| 2436 | assume(strat->R==NULL);//omfree(strat->R); |
---|
[83be980] | 2437 | omfree(strat->S_2_R); |
---|
[35aab3] | 2438 | omfree(strat->fromQ); |
---|
| 2439 | idDelete(&strat->Shdl); |
---|
[d30a399] | 2440 | SI_RESTORE_OPT1(save1); |
---|
[35aab3] | 2441 | if (TEST_OPT_PROT) PrintLn(); |
---|
| 2442 | return res; |
---|
| 2443 | } |
---|
[dd2855] | 2444 | |
---|
[83be980] | 2445 | #if F5C |
---|
| 2446 | /********************************************************************* |
---|
| 2447 | * interrreduction step of the signature-based algorithm: |
---|
| 2448 | * 1. all strat->S are interpreted as new critical pairs |
---|
| 2449 | * 2. those pairs need to be completely reduced by the usual (non sig- |
---|
| 2450 | * safe) reduction process (including tail reductions) |
---|
| 2451 | * 3. strat->S and strat->T are completely new computed in these steps |
---|
| 2452 | ********************************************************************/ |
---|
[601105] | 2453 | void f5c (kStrategy strat, int& olddeg, int& minimcnt, int& hilbeledeg, |
---|
[83be980] | 2454 | int& hilbcount, int& srmax, int& lrmax, int& reduc, ideal Q, |
---|
| 2455 | intvec *w,intvec *hilb ) |
---|
| 2456 | { |
---|
| 2457 | int Ll_old, red_result = 1; |
---|
| 2458 | int pos = 0; |
---|
| 2459 | hilbeledeg=1; |
---|
| 2460 | hilbcount=0; |
---|
| 2461 | minimcnt=0; |
---|
| 2462 | srmax = 0; // strat->sl is 0 at this point |
---|
| 2463 | reduc = olddeg = lrmax = 0; |
---|
| 2464 | // we cannot use strat->T anymore |
---|
| 2465 | //cleanT(strat); |
---|
| 2466 | //strat->tl = -1; |
---|
| 2467 | Ll_old = strat->Ll; |
---|
| 2468 | while (strat->tl >= 0) |
---|
| 2469 | { |
---|
| 2470 | if(!strat->T[strat->tl].is_redundant) |
---|
| 2471 | { |
---|
| 2472 | LObject h; |
---|
| 2473 | h.p = strat->T[strat->tl].p; |
---|
| 2474 | h.tailRing = strat->T[strat->tl].tailRing; |
---|
| 2475 | h.t_p = strat->T[strat->tl].t_p; |
---|
| 2476 | if (h.p!=NULL) |
---|
| 2477 | { |
---|
[fee33e] | 2478 | if (currRing->OrdSgn==-1) |
---|
[83be980] | 2479 | { |
---|
[601105] | 2480 | cancelunit(&h); |
---|
[83be980] | 2481 | deleteHC(&h, strat); |
---|
| 2482 | } |
---|
| 2483 | if (h.p!=NULL) |
---|
| 2484 | { |
---|
| 2485 | if (TEST_OPT_INTSTRATEGY) |
---|
| 2486 | { |
---|
| 2487 | //pContent(h.p); |
---|
| 2488 | h.pCleardenom(); // also does a pContent |
---|
| 2489 | } |
---|
| 2490 | else |
---|
| 2491 | { |
---|
| 2492 | h.pNorm(); |
---|
| 2493 | } |
---|
| 2494 | strat->initEcart(&h); |
---|
| 2495 | pos = strat->Ll+1; |
---|
| 2496 | h.sev = pGetShortExpVector(h.p); |
---|
| 2497 | enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos); |
---|
| 2498 | } |
---|
| 2499 | } |
---|
| 2500 | } |
---|
| 2501 | strat->tl--; |
---|
| 2502 | } |
---|
| 2503 | strat->sl = -1; |
---|
| 2504 | #if 0 |
---|
| 2505 | //#ifdef HAVE_TAIL_RING |
---|
| 2506 | if(!rField_is_Ring()) // create strong gcd poly computes with tailring and S[i] ->to be fixed |
---|
| 2507 | kStratInitChangeTailRing(strat); |
---|
| 2508 | #endif |
---|
| 2509 | //enterpairs(pOne(),0,0,-1,strat,strat->tl); |
---|
| 2510 | //strat->sl = -1; |
---|
| 2511 | /* picks the last element from the lazyset L */ |
---|
| 2512 | while (strat->Ll>Ll_old) |
---|
| 2513 | { |
---|
| 2514 | strat->P = strat->L[strat->Ll]; |
---|
| 2515 | strat->Ll--; |
---|
| 2516 | //#if 1 |
---|
| 2517 | #ifdef DEBUGF5 |
---|
| 2518 | Print("NEXT PAIR TO HANDLE IN INTERRED ALGORITHM\n"); |
---|
| 2519 | Print("-------------------------------------------------\n"); |
---|
| 2520 | pWrite(pHead(strat->P.p)); |
---|
| 2521 | pWrite(pHead(strat->P.p1)); |
---|
| 2522 | pWrite(pHead(strat->P.p2)); |
---|
| 2523 | printf("%d\n",strat->tl); |
---|
| 2524 | Print("-------------------------------------------------\n"); |
---|
| 2525 | #endif |
---|
| 2526 | if (pNext(strat->P.p) == strat->tail) |
---|
| 2527 | { |
---|
| 2528 | // deletes the short spoly |
---|
| 2529 | #ifdef HAVE_RINGS |
---|
| 2530 | if (rField_is_Ring(currRing)) |
---|
| 2531 | pLmDelete(strat->P.p); |
---|
| 2532 | else |
---|
| 2533 | #endif |
---|
| 2534 | pLmFree(strat->P.p); |
---|
| 2535 | |
---|
| 2536 | // TODO: needs some masking |
---|
| 2537 | // TODO: masking needs to vanish once the signature |
---|
| 2538 | // sutff is completely implemented |
---|
| 2539 | strat->P.p = NULL; |
---|
| 2540 | poly m1 = NULL, m2 = NULL; |
---|
| 2541 | |
---|
| 2542 | // check that spoly creation is ok |
---|
| 2543 | while (strat->tailRing != currRing && |
---|
| 2544 | !kCheckSpolyCreation(&(strat->P), strat, m1, m2)) |
---|
| 2545 | { |
---|
| 2546 | assume(m1 == NULL && m2 == NULL); |
---|
| 2547 | // if not, change to a ring where exponents are at least |
---|
| 2548 | // large enough |
---|
| 2549 | if (!kStratChangeTailRing(strat)) |
---|
| 2550 | { |
---|
| 2551 | WerrorS("OVERFLOW..."); |
---|
| 2552 | break; |
---|
| 2553 | } |
---|
| 2554 | } |
---|
| 2555 | // create the real one |
---|
| 2556 | ksCreateSpoly(&(strat->P), NULL, strat->use_buckets, |
---|
| 2557 | strat->tailRing, m1, m2, strat->R); |
---|
| 2558 | } |
---|
| 2559 | else if (strat->P.p1 == NULL) |
---|
| 2560 | { |
---|
| 2561 | if (strat->minim > 0) |
---|
| 2562 | strat->P.p2=p_Copy(strat->P.p, currRing, strat->tailRing); |
---|
| 2563 | // for input polys, prepare reduction |
---|
| 2564 | strat->P.PrepareRed(strat->use_buckets); |
---|
| 2565 | } |
---|
| 2566 | |
---|
| 2567 | if (strat->P.p == NULL && strat->P.t_p == NULL) |
---|
| 2568 | { |
---|
| 2569 | red_result = 0; |
---|
| 2570 | } |
---|
| 2571 | else |
---|
| 2572 | { |
---|
| 2573 | if (TEST_OPT_PROT) |
---|
| 2574 | message((strat->honey ? strat->P.ecart : 0) + strat->P.pFDeg(), |
---|
| 2575 | &olddeg,&reduc,strat, red_result); |
---|
| 2576 | |
---|
| 2577 | #ifdef DEBUGF5 |
---|
| 2578 | Print("Poly before red: "); |
---|
| 2579 | pWrite(strat->P.p); |
---|
| 2580 | #endif |
---|
| 2581 | /* complete reduction of the element choosen from L */ |
---|
| 2582 | red_result = strat->red2(&strat->P,strat); |
---|
| 2583 | if (errorreported) break; |
---|
| 2584 | } |
---|
| 2585 | |
---|
| 2586 | if (strat->overflow) |
---|
| 2587 | { |
---|
| 2588 | if (!kStratChangeTailRing(strat)) { Werror("OVERFLOW.."); break;} |
---|
| 2589 | } |
---|
| 2590 | |
---|
| 2591 | // reduction to non-zero new poly |
---|
| 2592 | if (red_result == 1) |
---|
| 2593 | { |
---|
| 2594 | // get the polynomial (canonicalize bucket, make sure P.p is set) |
---|
| 2595 | strat->P.GetP(strat->lmBin); |
---|
| 2596 | // in the homogeneous case FDeg >= pFDeg (sugar/honey) |
---|
| 2597 | // but now, for entering S, T, we reset it |
---|
| 2598 | // in the inhomogeneous case: FDeg == pFDeg |
---|
| 2599 | if (strat->homog) strat->initEcart(&(strat->P)); |
---|
| 2600 | |
---|
| 2601 | /* statistic */ |
---|
| 2602 | if (TEST_OPT_PROT) PrintS("s"); |
---|
| 2603 | |
---|
| 2604 | int pos=posInS(strat,strat->sl,strat->P.p,strat->P.ecart); |
---|
| 2605 | |
---|
| 2606 | #ifdef KDEBUG |
---|
| 2607 | #if MYTEST |
---|
| 2608 | PrintS("New S: "); pDebugPrint(strat->P.p); PrintLn(); |
---|
| 2609 | #endif /* MYTEST */ |
---|
| 2610 | #endif /* KDEBUG */ |
---|
| 2611 | |
---|
| 2612 | // reduce the tail and normalize poly |
---|
| 2613 | // in the ring case we cannot expect LC(f) = 1, |
---|
| 2614 | // therefore we call pContent instead of pNorm |
---|
| 2615 | #if F5CTAILRED |
---|
[15b211] | 2616 | BOOLEAN withT = TRUE; |
---|
[83be980] | 2617 | if ((TEST_OPT_INTSTRATEGY) || (rField_is_Ring(currRing))) |
---|
| 2618 | { |
---|
| 2619 | strat->P.pCleardenom(); |
---|
| 2620 | if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL)) |
---|
| 2621 | { |
---|
| 2622 | strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT); |
---|
| 2623 | strat->P.pCleardenom(); |
---|
| 2624 | } |
---|
| 2625 | } |
---|
| 2626 | else |
---|
| 2627 | { |
---|
| 2628 | strat->P.pNorm(); |
---|
| 2629 | if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL)) |
---|
| 2630 | strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT); |
---|
| 2631 | } |
---|
| 2632 | #endif |
---|
| 2633 | #ifdef KDEBUG |
---|
| 2634 | if (TEST_OPT_DEBUG){PrintS("new s:");strat->P.wrp();PrintLn();} |
---|
| 2635 | #if MYTEST |
---|
| 2636 | //#if 1 |
---|
| 2637 | PrintS("New (reduced) S: "); pDebugPrint(strat->P.p); PrintLn(); |
---|
| 2638 | #endif /* MYTEST */ |
---|
| 2639 | #endif /* KDEBUG */ |
---|
| 2640 | |
---|
| 2641 | // min_std stuff |
---|
| 2642 | if ((strat->P.p1==NULL) && (strat->minim>0)) |
---|
| 2643 | { |
---|
| 2644 | if (strat->minim==1) |
---|
| 2645 | { |
---|
| 2646 | strat->M->m[minimcnt]=p_Copy(strat->P.p,currRing,strat->tailRing); |
---|
| 2647 | p_Delete(&strat->P.p2, currRing, strat->tailRing); |
---|
| 2648 | } |
---|
| 2649 | else |
---|
| 2650 | { |
---|
| 2651 | strat->M->m[minimcnt]=strat->P.p2; |
---|
| 2652 | strat->P.p2=NULL; |
---|
| 2653 | } |
---|
| 2654 | if (strat->tailRing!=currRing && pNext(strat->M->m[minimcnt])!=NULL) |
---|
| 2655 | pNext(strat->M->m[minimcnt]) |
---|
| 2656 | = strat->p_shallow_copy_delete(pNext(strat->M->m[minimcnt]), |
---|
| 2657 | strat->tailRing, currRing, |
---|
| 2658 | currRing->PolyBin); |
---|
| 2659 | minimcnt++; |
---|
| 2660 | } |
---|
| 2661 | |
---|
| 2662 | // enter into S, L, and T |
---|
| 2663 | // here we need to recompute new signatures, but those are trivial ones |
---|
| 2664 | //if ((!TEST_OPT_IDLIFT) || (pGetComp(strat->P.p) <= strat->syzComp)) |
---|
| 2665 | enterT(strat->P, strat); |
---|
| 2666 | // posInS only depends on the leading term |
---|
| 2667 | strat->enterS(strat->P, pos, strat, strat->tl); |
---|
| 2668 | //#if 1 |
---|
| 2669 | #ifdef DEBUGF5 |
---|
| 2670 | Print("ELEMENT ADDED TO GCURR DURING INTERRED: "); |
---|
| 2671 | pWrite(pHead(strat->S[strat->sl])); |
---|
| 2672 | pWrite(strat->sig[strat->sl]); |
---|
| 2673 | #endif |
---|
| 2674 | if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat); |
---|
| 2675 | // Print("[%d]",hilbeledeg); |
---|
| 2676 | if (strat->P.lcm!=NULL) |
---|
| 2677 | #ifdef HAVE_RINGS |
---|
| 2678 | pLmDelete(strat->P.lcm); |
---|
| 2679 | #else |
---|
| 2680 | pLmFree(strat->P.lcm); |
---|
| 2681 | #endif |
---|
| 2682 | if (strat->sl>srmax) srmax = strat->sl; |
---|
| 2683 | } |
---|
| 2684 | else |
---|
| 2685 | { |
---|
| 2686 | // adds signature of the zero reduction to |
---|
| 2687 | // strat->syz. This is the leading term of |
---|
| 2688 | // syzygy and can be used in syzCriterion() |
---|
| 2689 | // the signature is added if and only if the |
---|
| 2690 | // pair was not detected by the rewritten criterion in strat->red = redSig |
---|
| 2691 | if (strat->P.p1 == NULL && strat->minim > 0) |
---|
| 2692 | { |
---|
| 2693 | p_Delete(&strat->P.p2, currRing, strat->tailRing); |
---|
| 2694 | } |
---|
| 2695 | } |
---|
| 2696 | |
---|
| 2697 | #ifdef KDEBUG |
---|
| 2698 | memset(&(strat->P), 0, sizeof(strat->P)); |
---|
| 2699 | #endif /* KDEBUG */ |
---|
| 2700 | } |
---|
| 2701 | int cc = 0; |
---|
| 2702 | while (cc<strat->tl+1) |
---|
| 2703 | { |
---|
| 2704 | strat->T[cc].sig = pOne(); |
---|
| 2705 | p_SetComp(strat->T[cc].sig,cc+1,currRing); |
---|
| 2706 | strat->T[cc].sevSig = pGetShortExpVector(strat->T[cc].sig); |
---|
| 2707 | strat->sig[cc] = strat->T[cc].sig; |
---|
| 2708 | strat->sevSig[cc] = strat->T[cc].sevSig; |
---|
[601105] | 2709 | strat->T[cc].is_sigsafe = TRUE; |
---|
[83be980] | 2710 | cc++; |
---|
| 2711 | } |
---|
| 2712 | strat->max_lower_index = strat->tl; |
---|
| 2713 | // set current signature index of upcoming iteration step |
---|
| 2714 | // NOTE: this needs to be set here, as otherwise initSyzRules cannot compute |
---|
| 2715 | // the corresponding syzygy rules correctly |
---|
| 2716 | strat->currIdx = cc+1; |
---|
| 2717 | for (int cd=strat->Ll; cd>=0; cd--) |
---|
| 2718 | { |
---|
| 2719 | p_SetComp(strat->L[cd].sig,cc+1,currRing); |
---|
| 2720 | cc++; |
---|
| 2721 | } |
---|
| 2722 | //#if 1 |
---|
| 2723 | #if DEBUGF5 |
---|
| 2724 | Print("------------------- STRAT S ---------------------\n"); |
---|
| 2725 | cc = 0; |
---|
| 2726 | while (cc<strat->tl+1) |
---|
| 2727 | { |
---|
| 2728 | pWrite(pHead(strat->S[cc])); |
---|
| 2729 | pWrite(strat->sig[cc]); |
---|
| 2730 | printf("- - - - - -\n"); |
---|
| 2731 | cc++; |
---|
| 2732 | } |
---|
| 2733 | Print("-------------------------------------------------\n"); |
---|
| 2734 | Print("------------------- STRAT T ---------------------\n"); |
---|
| 2735 | cc = 0; |
---|
| 2736 | while (cc<strat->tl+1) |
---|
| 2737 | { |
---|
| 2738 | pWrite(pHead(strat->T[cc].p)); |
---|
| 2739 | pWrite(strat->T[cc].sig); |
---|
| 2740 | printf("- - - - - -\n"); |
---|
| 2741 | cc++; |
---|
| 2742 | } |
---|
| 2743 | Print("-------------------------------------------------\n"); |
---|
| 2744 | Print("------------------- STRAT L ---------------------\n"); |
---|
| 2745 | cc = 0; |
---|
| 2746 | while (cc<strat->Ll+1) |
---|
| 2747 | { |
---|
| 2748 | pWrite(pHead(strat->L[cc].p)); |
---|
| 2749 | pWrite(pHead(strat->L[cc].p1)); |
---|
| 2750 | pWrite(pHead(strat->L[cc].p2)); |
---|
| 2751 | pWrite(strat->L[cc].sig); |
---|
| 2752 | printf("- - - - - -\n"); |
---|
| 2753 | cc++; |
---|
| 2754 | } |
---|
| 2755 | Print("-------------------------------------------------\n"); |
---|
| 2756 | printf("F5C DONE\nSTRAT SL: %d -- %d\n",strat->sl, strat->currIdx); |
---|
| 2757 | #endif |
---|
| 2758 | |
---|
| 2759 | } |
---|
| 2760 | #endif |
---|
| 2761 | |
---|
[cb0fbe] | 2762 | /* shiftgb stuff */ |
---|
[037df4] | 2763 | #ifdef HAVE_SHIFTBBA |
---|
[37a4c3] | 2764 | |
---|
[07625cb] | 2765 | |
---|
[cb0fbe] | 2766 | ideal bbaShift(ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat, int uptodeg, int lV) |
---|
| 2767 | { |
---|
| 2768 | #ifdef KDEBUG |
---|
| 2769 | bba_count++; |
---|
| 2770 | int loop_count = 0; |
---|
| 2771 | #endif |
---|
[930ea8] | 2772 | int red_result = 1; |
---|
[cb0fbe] | 2773 | int olddeg,reduc; |
---|
| 2774 | int hilbeledeg=1,hilbcount=0,minimcnt=0; |
---|
[4d43ff] | 2775 | BOOLEAN withT = TRUE; // very important for shifts |
---|
[cb0fbe] | 2776 | |
---|
[37a4c3] | 2777 | initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit, NO CHANGES */ |
---|
| 2778 | initBuchMoraPos(strat); /*NO CHANGES YET: perhaps later*/ |
---|
| 2779 | initHilbCrit(F,Q,&hilb,strat); /*NO CHANGES*/ |
---|
| 2780 | initBbaShift(F,strat); /* DONE */ |
---|
[cb0fbe] | 2781 | /*set enterS, spSpolyShort, reduce, red, initEcart, initEcartPair*/ |
---|
[37a4c3] | 2782 | /*Shdl=*/initBuchMoraShift(F, Q,strat); /* updateS with no toT, i.e. no init for T */ |
---|
| 2783 | updateSShift(strat,uptodeg,lV); /* initializes T */ |
---|
| 2784 | |
---|
[cb0fbe] | 2785 | if (strat->minim>0) strat->M=idInit(IDELEMS(F),F->rank); |
---|
[930ea8] | 2786 | reduc = olddeg = 0; |
---|
[bbf50e] | 2787 | strat->lV=lV; |
---|
[cb0fbe] | 2788 | |
---|
| 2789 | #ifndef NO_BUCKETS |
---|
| 2790 | if (!TEST_OPT_NOT_BUCKETS) |
---|
| 2791 | strat->use_buckets = 1; |
---|
| 2792 | #endif |
---|
| 2793 | |
---|
| 2794 | // redtailBBa against T for inhomogenous input |
---|
[228b631] | 2795 | // if (!TEST_OPT_OLDSTD) |
---|
[37a4c3] | 2796 | // withT = ! strat->homog; |
---|
[cb0fbe] | 2797 | |
---|
| 2798 | // strat->posInT = posInT_pLength; |
---|
[d101b1] | 2799 | assume(kTest_TS(strat)); |
---|
[cb0fbe] | 2800 | |
---|
| 2801 | #ifdef HAVE_TAIL_RING |
---|
| 2802 | kStratInitChangeTailRing(strat); |
---|
| 2803 | #endif |
---|
| 2804 | |
---|
| 2805 | /* compute------------------------------------------------------- */ |
---|
| 2806 | while (strat->Ll >= 0) |
---|
| 2807 | { |
---|
| 2808 | #ifdef KDEBUG |
---|
| 2809 | loop_count++; |
---|
| 2810 | if (TEST_OPT_DEBUG) messageSets(strat); |
---|
| 2811 | #endif |
---|
| 2812 | if (strat->Ll== 0) strat->interpt=TRUE; |
---|
| 2813 | if (TEST_OPT_DEGBOUND |
---|
[e533660] | 2814 | && ((strat->honey && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg)) |
---|
| 2815 | || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg)))) |
---|
[cb0fbe] | 2816 | { |
---|
| 2817 | /* |
---|
| 2818 | *stops computation if |
---|
| 2819 | * 24 IN test and the degree +ecart of L[strat->Ll] is bigger then |
---|
| 2820 | *a predefined number Kstd1_deg |
---|
| 2821 | */ |
---|
| 2822 | while ((strat->Ll >= 0) |
---|
| 2823 | && (strat->L[strat->Ll].p1!=NULL) && (strat->L[strat->Ll].p2!=NULL) |
---|
[e533660] | 2824 | && ((strat->honey && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg)) |
---|
| 2825 | || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))) |
---|
[cb0fbe] | 2826 | ) |
---|
| 2827 | deleteInL(strat->L,&strat->Ll,strat->Ll,strat); |
---|
| 2828 | if (strat->Ll<0) break; |
---|
| 2829 | else strat->noClearS=TRUE; |
---|
| 2830 | } |
---|
| 2831 | /* picks the last element from the lazyset L */ |
---|
| 2832 | strat->P = strat->L[strat->Ll]; |
---|
| 2833 | strat->Ll--; |
---|
| 2834 | |
---|
| 2835 | if (pNext(strat->P.p) == strat->tail) |
---|
| 2836 | { |
---|
| 2837 | // deletes the short spoly |
---|
| 2838 | pLmFree(strat->P.p); |
---|
| 2839 | strat->P.p = NULL; |
---|
| 2840 | poly m1 = NULL, m2 = NULL; |
---|
| 2841 | |
---|
| 2842 | // check that spoly creation is ok |
---|
| 2843 | while (strat->tailRing != currRing && |
---|
| 2844 | !kCheckSpolyCreation(&(strat->P), strat, m1, m2)) |
---|
| 2845 | { |
---|
| 2846 | assume(m1 == NULL && m2 == NULL); |
---|
| 2847 | // if not, change to a ring where exponents are at least |
---|
| 2848 | // large enough |
---|
| 2849 | kStratChangeTailRing(strat); |
---|
| 2850 | } |
---|
| 2851 | // create the real one |
---|
| 2852 | ksCreateSpoly(&(strat->P), NULL, strat->use_buckets, |
---|
| 2853 | strat->tailRing, m1, m2, strat->R); |
---|
| 2854 | } |
---|
| 2855 | else if (strat->P.p1 == NULL) |
---|
| 2856 | { |
---|
| 2857 | if (strat->minim > 0) |
---|
| 2858 | strat->P.p2=p_Copy(strat->P.p, currRing, strat->tailRing); |
---|
| 2859 | // for input polys, prepare reduction |
---|
| 2860 | strat->P.PrepareRed(strat->use_buckets); |
---|
| 2861 | } |
---|
| 2862 | |
---|
[ad1c3b] | 2863 | poly qq; |
---|
| 2864 | |
---|
| 2865 | /* here in the nonhomog case we shrink the new spoly */ |
---|
[eed827] | 2866 | |
---|
[ad1c3b] | 2867 | if ( ! strat->homog) |
---|
| 2868 | { |
---|
| 2869 | strat->P.GetP(strat->lmBin); // because shifts are counted with .p structure |
---|
| 2870 | /* in the nonhomog case we have to shrink the polynomial */ |
---|
| 2871 | assume(strat->P.t_p!=NULL); |
---|
| 2872 | qq = p_Shrink(strat->P.t_p, lV, strat->tailRing); // direct shrink |
---|
| 2873 | if (qq != NULL) |
---|
| 2874 | { |
---|
| 2875 | /* we're here if Shrink is nonzero */ |
---|
| 2876 | // strat->P.p = NULL; |
---|
[eed827] | 2877 | // strat->P.Delete(); /* deletes P.p and P.t_p */ //error |
---|
[ad1c3b] | 2878 | strat->P.p = NULL; // is not set by Delete |
---|
| 2879 | strat->P.t_p = qq; |
---|
| 2880 | strat->P.GetP(strat->lmBin); |
---|
| 2881 | // update sev and length |
---|
| 2882 | strat->initEcart(&(strat->P)); |
---|
| 2883 | strat->P.sev = pGetShortExpVector(strat->P.p); |
---|
| 2884 | // strat->P.FDeg = strat->P.pFDeg(); |
---|
| 2885 | // strat->P.length = strat->P.pLDeg(); |
---|
| 2886 | // strat->P.pLength =strat->P.GetpLength(); //pLength(strat->P.p); |
---|
| 2887 | } |
---|
| 2888 | else |
---|
| 2889 | { |
---|
| 2890 | /* Shrink is zero, like y(1)*y(2) - y(1)*y(3)*/ |
---|
| 2891 | #ifdef KDEBUG |
---|
| 2892 | if (TEST_OPT_DEBUG){PrintS("nonzero s shrinks to 0");PrintLn();} |
---|
| 2893 | #endif |
---|
[eed827] | 2894 | // strat->P.Delete(); // cause error |
---|
| 2895 | strat->P.p = NULL; |
---|
| 2896 | strat->P.t_p = NULL; |
---|
[ad1c3b] | 2897 | // strat->P.p = NULL; // or delete strat->P.p ? |
---|
| 2898 | } |
---|
| 2899 | } |
---|
| 2900 | /* end shrinking poly in the nonhomog case */ |
---|
| 2901 | |
---|
[cb0fbe] | 2902 | if (strat->P.p == NULL && strat->P.t_p == NULL) |
---|
| 2903 | { |
---|
| 2904 | red_result = 0; |
---|
| 2905 | } |
---|
| 2906 | else |
---|
| 2907 | { |
---|
| 2908 | if (TEST_OPT_PROT) |
---|
| 2909 | message((strat->honey ? strat->P.ecart : 0) + strat->P.pFDeg(), |
---|
| 2910 | &olddeg,&reduc,strat, red_result); |
---|
| 2911 | |
---|
| 2912 | /* reduction of the element choosen from L */ |
---|
| 2913 | red_result = strat->red(&strat->P,strat); |
---|
| 2914 | } |
---|
| 2915 | |
---|
| 2916 | // reduction to non-zero new poly |
---|
| 2917 | if (red_result == 1) |
---|
| 2918 | { |
---|
| 2919 | /* statistic */ |
---|
| 2920 | if (TEST_OPT_PROT) PrintS("s"); |
---|
| 2921 | |
---|
| 2922 | // get the polynomial (canonicalize bucket, make sure P.p is set) |
---|
| 2923 | strat->P.GetP(strat->lmBin); |
---|
| 2924 | |
---|
| 2925 | int pos=posInS(strat,strat->sl,strat->P.p,strat->P.ecart); |
---|
| 2926 | |
---|
| 2927 | // reduce the tail and normalize poly |
---|
| 2928 | if (TEST_OPT_INTSTRATEGY) |
---|
| 2929 | { |
---|
| 2930 | strat->P.pCleardenom(); |
---|
| 2931 | if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL)) |
---|
| 2932 | { |
---|
| 2933 | strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT); |
---|
| 2934 | strat->P.pCleardenom(); |
---|
| 2935 | } |
---|
| 2936 | } |
---|
| 2937 | else |
---|
| 2938 | { |
---|
| 2939 | strat->P.pNorm(); |
---|
| 2940 | if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL)) |
---|
| 2941 | strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT); |
---|
| 2942 | } |
---|
| 2943 | |
---|
[ad1c3b] | 2944 | // here we must shrink again! and optionally reduce again |
---|
| 2945 | // or build shrink into redtailBba! |
---|
| 2946 | |
---|
[cb0fbe] | 2947 | #ifdef KDEBUG |
---|
| 2948 | if (TEST_OPT_DEBUG){PrintS("new s:");strat->P.wrp();PrintLn();} |
---|
| 2949 | #endif |
---|
| 2950 | |
---|
| 2951 | // min_std stuff |
---|
| 2952 | if ((strat->P.p1==NULL) && (strat->minim>0)) |
---|
| 2953 | { |
---|
| 2954 | if (strat->minim==1) |
---|
| 2955 | { |
---|
| 2956 | strat->M->m[minimcnt]=p_Copy(strat->P.p,currRing,strat->tailRing); |
---|
| 2957 | p_Delete(&strat->P.p2, currRing, strat->tailRing); |
---|
| 2958 | } |
---|
| 2959 | else |
---|
| 2960 | { |
---|
| 2961 | strat->M->m[minimcnt]=strat->P.p2; |
---|
| 2962 | strat->P.p2=NULL; |
---|
| 2963 | } |
---|
| 2964 | if (strat->tailRing!=currRing && pNext(strat->M->m[minimcnt])!=NULL) |
---|
| 2965 | pNext(strat->M->m[minimcnt]) |
---|
| 2966 | = strat->p_shallow_copy_delete(pNext(strat->M->m[minimcnt]), |
---|
| 2967 | strat->tailRing, currRing, |
---|
| 2968 | currRing->PolyBin); |
---|
| 2969 | minimcnt++; |
---|
| 2970 | } |
---|
| 2971 | |
---|
[ad1c3b] | 2972 | /* here in the nonhomog case we shrink the reduced poly AGAIN */ |
---|
[eed827] | 2973 | |
---|
[ad1c3b] | 2974 | if ( ! strat->homog) |
---|
| 2975 | { |
---|
| 2976 | strat->P.GetP(strat->lmBin); // because shifts are counted with .p structure |
---|
| 2977 | /* assume strat->P.t_p != NULL */ |
---|
| 2978 | /* in the nonhomog case we have to shrink the polynomial */ |
---|
| 2979 | assume(strat->P.t_p!=NULL); // poly qq defined above |
---|
| 2980 | qq = p_Shrink(strat->P.t_p, lV, strat->tailRing); // direct shrink |
---|
| 2981 | if (qq != NULL) |
---|
| 2982 | { |
---|
| 2983 | /* we're here if Shrink is nonzero */ |
---|
| 2984 | // strat->P.p = NULL; |
---|
[eed827] | 2985 | // strat->P.Delete(); /* deletes P.p and P.t_p */ //error |
---|
[ad1c3b] | 2986 | strat->P.p = NULL; // is not set by Delete |
---|
| 2987 | strat->P.t_p = qq; |
---|
| 2988 | strat->P.GetP(strat->lmBin); |
---|
| 2989 | // update sev and length |
---|
| 2990 | strat->initEcart(&(strat->P)); |
---|
| 2991 | strat->P.sev = pGetShortExpVector(strat->P.p); |
---|
| 2992 | } |
---|
| 2993 | else |
---|
| 2994 | { |
---|
| 2995 | /* Shrink is zero, like y(1)*y(2) - y(1)*y(3)*/ |
---|
| 2996 | #ifdef PDEBUG |
---|
| 2997 | if (TEST_OPT_DEBUG){PrintS("nonzero s shrinks to 0");PrintLn();} |
---|
| 2998 | #endif |
---|
[eed827] | 2999 | // strat->P.Delete(); // cause error |
---|
| 3000 | strat->P.p = NULL; |
---|
| 3001 | strat->P.t_p = NULL; |
---|
[ad1c3b] | 3002 | // strat->P.p = NULL; // or delete strat->P.p ? |
---|
[eed827] | 3003 | goto red_shrink2zero; |
---|
[ad1c3b] | 3004 | } |
---|
| 3005 | } |
---|
| 3006 | /* end shrinking poly AGAIN in the nonhomog case */ |
---|
| 3007 | |
---|
| 3008 | |
---|
[cb0fbe] | 3009 | // enter into S, L, and T |
---|
| 3010 | //if ((!TEST_OPT_IDLIFT) || (pGetComp(strat->P.p) <= strat->syzComp)) |
---|
[37a4c3] | 3011 | // enterT(strat->P, strat); // this was here before Shift stuff |
---|
| 3012 | //enterTShift(LObject p, kStrategy strat, int atT, int uptodeg, int lV); // syntax |
---|
[4d2ab5c] | 3013 | // the default value for atT = -1 as in bba |
---|
[eed827] | 3014 | /* strat->P.GetP(); */ |
---|
[ad1c3b] | 3015 | // because shifts are counted with .p structure // done before, but ? |
---|
[37a4c3] | 3016 | enterTShift(strat->P,strat,-1,uptodeg, lV); |
---|
| 3017 | enterpairsShift(strat->P.p,strat->sl,strat->P.ecart,pos,strat, strat->tl,uptodeg,lV); |
---|
[4d2ab5c] | 3018 | // enterpairsShift(vw,strat->sl,strat->P.ecart,pos,strat, strat->tl,uptodeg,lV); |
---|
[cb0fbe] | 3019 | // posInS only depends on the leading term |
---|
[1c35568] | 3020 | strat->enterS(strat->P, pos, strat, strat->tl); |
---|
[ad1c3b] | 3021 | |
---|
[cb0fbe] | 3022 | if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat); |
---|
| 3023 | // Print("[%d]",hilbeledeg); |
---|
| 3024 | if (strat->P.lcm!=NULL) pLmFree(strat->P.lcm); |
---|
| 3025 | } |
---|
[eed827] | 3026 | else |
---|
[cb0fbe] | 3027 | { |
---|
[ad1c3b] | 3028 | red_shrink2zero: |
---|
| 3029 | if (strat->P.p1 == NULL && strat->minim > 0) |
---|
| 3030 | { |
---|
[eed827] | 3031 | p_Delete(&strat->P.p2, currRing, strat->tailRing); |
---|
[ad1c3b] | 3032 | } |
---|
[cb0fbe] | 3033 | } |
---|
| 3034 | #ifdef KDEBUG |
---|
| 3035 | memset(&(strat->P), 0, sizeof(strat->P)); |
---|
| 3036 | #endif |
---|
[d101b1] | 3037 | assume(kTest_TS(strat)); |
---|
[cb0fbe] | 3038 | } |
---|
| 3039 | #ifdef KDEBUG |
---|
| 3040 | if (TEST_OPT_DEBUG) messageSets(strat); |
---|
| 3041 | #endif |
---|
| 3042 | /* complete reduction of the standard basis--------- */ |
---|
[d5564f8] | 3043 | /* shift case: look for elt's in S such that they are divisible by elt in T */ |
---|
[4c4979] | 3044 | // if (TEST_OPT_SB_1) |
---|
| 3045 | if (TEST_OPT_REDSB) |
---|
[cb0fbe] | 3046 | { |
---|
[4c4979] | 3047 | int k=0; |
---|
| 3048 | int j=-1; |
---|
[cb0fbe] | 3049 | while(k<=strat->sl) |
---|
| 3050 | { |
---|
[4c4979] | 3051 | // loop |
---|
| 3052 | // { |
---|
| 3053 | // if (j>=k) break; |
---|
| 3054 | // clearS(strat->S[j],strat->sevS[j],&k,&j,strat); |
---|
| 3055 | // j++; |
---|
| 3056 | // } |
---|
| 3057 | LObject Ln (strat->S[k],currRing, strat->tailRing); |
---|
| 3058 | Ln.SetShortExpVector(); |
---|
| 3059 | j = kFindDivisibleByInT(strat->T, strat->sevT, strat->tl, &Ln, j+1); |
---|
| 3060 | if (j<0) { k++; j=-1;} |
---|
| 3061 | else |
---|
[cb0fbe] | 3062 | { |
---|
[4c4979] | 3063 | if ( pLmCmp(strat->S[k],strat->T[j].p) == 0) |
---|
| 3064 | { |
---|
| 3065 | j = kFindDivisibleByInT(strat->T, strat->sevT, strat->tl, &Ln, j+1); |
---|
| 3066 | if (j<0) { k++; j=-1;} |
---|
| 3067 | else |
---|
| 3068 | { |
---|
| 3069 | deleteInS(k,strat); |
---|
| 3070 | } |
---|
| 3071 | } |
---|
| 3072 | else |
---|
| 3073 | { |
---|
| 3074 | deleteInS(k,strat); |
---|
| 3075 | } |
---|
[cb0fbe] | 3076 | } |
---|
| 3077 | } |
---|
| 3078 | } |
---|
| 3079 | |
---|
| 3080 | if (TEST_OPT_REDSB) |
---|
[4c4979] | 3081 | { completeReduce(strat, TRUE); //shift: withT = TRUE |
---|
[cb0fbe] | 3082 | if (strat->completeReduce_retry) |
---|
| 3083 | { |
---|
| 3084 | // completeReduce needed larger exponents, retry |
---|
| 3085 | // to reduce with S (instead of T) |
---|
| 3086 | // and in currRing (instead of strat->tailRing) |
---|
| 3087 | cleanT(strat);strat->tailRing=currRing; |
---|
| 3088 | int i; |
---|
| 3089 | for(i=strat->sl;i>=0;i--) strat->S_2_R[i]=-1; |
---|
[4d43ff] | 3090 | completeReduce(strat, TRUE); |
---|
[cb0fbe] | 3091 | } |
---|
| 3092 | } |
---|
[5accf0] | 3093 | else if (TEST_OPT_PROT) PrintLn(); |
---|
[cb0fbe] | 3094 | |
---|
| 3095 | /* release temp data-------------------------------- */ |
---|
| 3096 | exitBuchMora(strat); |
---|
[e533660] | 3097 | // if (TEST_OPT_WEIGHTM) |
---|
| 3098 | // { |
---|
| 3099 | // pRestoreDegProcs(currRing,pFDegOld, pLDegOld); |
---|
| 3100 | // if (ecartWeights) |
---|
| 3101 | // { |
---|
| 3102 | // omFreeSize((ADDRESS)ecartWeights,((currRing->N)+1)*sizeof(short)); |
---|
| 3103 | // ecartWeights=NULL; |
---|
| 3104 | // } |
---|
| 3105 | // } |
---|
[930ea8] | 3106 | if (TEST_OPT_PROT) messageStat(hilbcount,strat); |
---|
[cb0fbe] | 3107 | if (Q!=NULL) updateResult(strat->Shdl,Q,strat); |
---|
| 3108 | return (strat->Shdl); |
---|
| 3109 | } |
---|
| 3110 | |
---|
[1c473f] | 3111 | |
---|
[cb0fbe] | 3112 | ideal freegb(ideal I, int uptodeg, int lVblock) |
---|
| 3113 | { |
---|
| 3114 | /* todo main call */ |
---|
| 3115 | |
---|
[37a4c3] | 3116 | /* assume: ring is prepared, ideal is copied into shifted ring */ |
---|
| 3117 | /* uptodeg and lVblock are correct - test them! */ |
---|
| 3118 | |
---|
[dabe365] | 3119 | /* check whether the ideal is in V */ |
---|
[9f5fca] | 3120 | |
---|
[db0c264] | 3121 | // if (0) |
---|
| 3122 | if (! ideal_isInV(I,lVblock) ) |
---|
[dabe365] | 3123 | { |
---|
[9f5fca] | 3124 | WerrorS("The input ideal contains incorrectly encoded elements! "); |
---|
[dabe365] | 3125 | return(NULL); |
---|
| 3126 | } |
---|
| 3127 | |
---|
[1c473f] | 3128 | // kStrategy strat = new skStrategy; |
---|
[cb0fbe] | 3129 | /* ideal bbaShift(ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat, int uptodeg, int lV) */ |
---|
| 3130 | /* at the moment: |
---|
| 3131 | - no quotient (check) |
---|
| 3132 | - no *w, no *hilb |
---|
| 3133 | */ |
---|
[1c473f] | 3134 | /* ideal F, ideal Q, tHomog h,intvec ** w, intvec *hilb,int syzComp, |
---|
| 3135 | int newIdeal, intvec *vw) */ |
---|
| 3136 | ideal RS = kStdShift(I,NULL, testHomog, NULL,NULL,0,0,NULL, uptodeg, lVblock); |
---|
| 3137 | //bbaShift(I,NULL, NULL, NULL, strat, uptodeg, lVblock); |
---|
[4d2ab5c] | 3138 | idSkipZeroes(RS); |
---|
[cb0fbe] | 3139 | return(RS); |
---|
| 3140 | } |
---|
[37a4c3] | 3141 | |
---|
| 3142 | /*2 |
---|
| 3143 | *reduces h with elements from T choosing the first possible |
---|
| 3144 | * element in t with respect to the given pDivisibleBy |
---|
| 3145 | */ |
---|
| 3146 | int redFirstShift (LObject* h,kStrategy strat) |
---|
| 3147 | { |
---|
| 3148 | if (h->IsNull()) return 0; |
---|
| 3149 | |
---|
| 3150 | int at, reddeg,d; |
---|
| 3151 | int pass = 0; |
---|
| 3152 | int j = 0; |
---|
| 3153 | |
---|
| 3154 | if (! strat->homog) |
---|
| 3155 | { |
---|
| 3156 | d = h->GetpFDeg() + h->ecart; |
---|
| 3157 | reddeg = strat->LazyDegree+d; |
---|
| 3158 | } |
---|
| 3159 | h->SetShortExpVector(); |
---|
| 3160 | loop |
---|
| 3161 | { |
---|
| 3162 | j = kFindDivisibleByInT(strat->T, strat->sevT, strat->tl, h); |
---|
| 3163 | if (j < 0) |
---|
| 3164 | { |
---|
| 3165 | h->SetDegStuffReturnLDeg(strat->LDegLast); |
---|
| 3166 | return 1; |
---|
| 3167 | } |
---|
| 3168 | |
---|
| 3169 | if (!TEST_OPT_INTSTRATEGY) |
---|
| 3170 | strat->T[j].pNorm(); |
---|
| 3171 | #ifdef KDEBUG |
---|
| 3172 | if (TEST_OPT_DEBUG) |
---|
| 3173 | { |
---|
| 3174 | PrintS("reduce "); |
---|
| 3175 | h->wrp(); |
---|
| 3176 | PrintS(" with "); |
---|
| 3177 | strat->T[j].wrp(); |
---|
| 3178 | } |
---|
| 3179 | #endif |
---|
| 3180 | ksReducePoly(h, &(strat->T[j]), strat->kNoetherTail(), NULL, strat); |
---|
[0724284] | 3181 | if (!h->IsNull()) |
---|
| 3182 | { |
---|
| 3183 | poly qq=p_Shrink(h->GetTP(),strat->lV,strat->tailRing); |
---|
| 3184 | h->p=NULL; |
---|
| 3185 | h->t_p=qq; |
---|
| 3186 | if (qq!=NULL) h->GetP(strat->lmBin); |
---|
| 3187 | } |
---|
[d5564f8] | 3188 | |
---|
[37a4c3] | 3189 | #ifdef KDEBUG |
---|
| 3190 | if (TEST_OPT_DEBUG) |
---|
| 3191 | { |
---|
| 3192 | PrintS(" to "); |
---|
| 3193 | wrp(h->p); |
---|
| 3194 | PrintLn(); |
---|
| 3195 | } |
---|
| 3196 | #endif |
---|
| 3197 | if (h->IsNull()) |
---|
| 3198 | { |
---|
| 3199 | if (h->lcm!=NULL) pLmFree(h->lcm); |
---|
| 3200 | h->Clear(); |
---|
| 3201 | return 0; |
---|
| 3202 | } |
---|
| 3203 | h->SetShortExpVector(); |
---|
| 3204 | |
---|
| 3205 | #if 0 |
---|
| 3206 | if ((strat->syzComp!=0) && !strat->honey) |
---|
| 3207 | { |
---|
| 3208 | if ((strat->syzComp>0) && |
---|
| 3209 | (h->Comp() > strat->syzComp)) |
---|
| 3210 | { |
---|
| 3211 | assume(h->MinComp() > strat->syzComp); |
---|
| 3212 | #ifdef KDEBUG |
---|
| 3213 | if (TEST_OPT_DEBUG) PrintS(" > syzComp\n"); |
---|
| 3214 | #endif |
---|
| 3215 | if (strat->homog) |
---|
| 3216 | h->SetDegStuffReturnLDeg(strat->LDegLast); |
---|
| 3217 | return -2; |
---|
| 3218 | } |
---|
| 3219 | } |
---|
| 3220 | #endif |
---|
| 3221 | if (!strat->homog) |
---|
| 3222 | { |
---|
[228b631] | 3223 | if (!TEST_OPT_OLDSTD && strat->honey) |
---|
[37a4c3] | 3224 | { |
---|
| 3225 | h->SetpFDeg(); |
---|
| 3226 | if (strat->T[j].ecart <= h->ecart) |
---|
| 3227 | h->ecart = d - h->GetpFDeg(); |
---|
| 3228 | else |
---|
| 3229 | h->ecart = d - h->GetpFDeg() + strat->T[j].ecart - h->ecart; |
---|
| 3230 | |
---|
| 3231 | d = h->GetpFDeg() + h->ecart; |
---|
| 3232 | } |
---|
| 3233 | else |
---|
| 3234 | d = h->SetDegStuffReturnLDeg(strat->LDegLast); |
---|
| 3235 | /*- try to reduce the s-polynomial -*/ |
---|
| 3236 | pass++; |
---|
| 3237 | /* |
---|
| 3238 | *test whether the polynomial should go to the lazyset L |
---|
| 3239 | *-if the degree jumps |
---|
| 3240 | *-if the number of pre-defined reductions jumps |
---|
| 3241 | */ |
---|
[228b631] | 3242 | if (!TEST_OPT_REDTHROUGH && (strat->Ll >= 0) |
---|
[37a4c3] | 3243 | && ((d >= reddeg) || (pass > strat->LazyPass))) |
---|
| 3244 | { |
---|
| 3245 | h->SetLmCurrRing(); |
---|
| 3246 | if (strat->posInLDependsOnLength) |
---|
| 3247 | h->SetLength(strat->length_pLength); |
---|
| 3248 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
| 3249 | if (at <= strat->Ll) |
---|
| 3250 | { |
---|
| 3251 | int dummy=strat->sl; |
---|
[eed827] | 3252 | /* if (kFindDivisibleByInS(strat,&dummy, h) < 0) */ |
---|
[37a4c3] | 3253 | if (kFindDivisibleByInT(strat->T,strat->sevT, dummy, h) < 0) |
---|
| 3254 | return 1; |
---|
| 3255 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
| 3256 | #ifdef KDEBUG |
---|
| 3257 | if (TEST_OPT_DEBUG) Print(" degree jumped; ->L%d\n",at); |
---|
[07625cb] | 3258 | #endif |
---|
[37a4c3] | 3259 | h->Clear(); |
---|
| 3260 | return -1; |
---|
| 3261 | } |
---|
| 3262 | } |
---|
| 3263 | if ((TEST_OPT_PROT) && (strat->Ll < 0) && (d >= reddeg)) |
---|
| 3264 | { |
---|
| 3265 | reddeg = d+1; |
---|
| 3266 | Print(".%d",d);mflush(); |
---|
| 3267 | } |
---|
| 3268 | } |
---|
| 3269 | } |
---|
| 3270 | } |
---|
| 3271 | |
---|
[2e4ec14] | 3272 | void initBbaShift(ideal /*F*/,kStrategy strat) |
---|
[37a4c3] | 3273 | { |
---|
| 3274 | /* setting global variables ------------------- */ |
---|
| 3275 | strat->enterS = enterSBba; /* remains as is, we change enterT! */ |
---|
| 3276 | |
---|
| 3277 | strat->red = redFirstShift; /* no redHomog ! */ |
---|
| 3278 | |
---|
[fe89b98] | 3279 | if (currRing->pLexOrder && strat->honey) |
---|
[37a4c3] | 3280 | strat->initEcart = initEcartNormal; |
---|
| 3281 | else |
---|
| 3282 | strat->initEcart = initEcartBBA; |
---|
| 3283 | if (strat->honey) |
---|
| 3284 | strat->initEcartPair = initEcartPairMora; |
---|
| 3285 | else |
---|
| 3286 | strat->initEcartPair = initEcartPairBba; |
---|
[e533660] | 3287 | // if ((TEST_OPT_WEIGHTM)&&(F!=NULL)) |
---|
| 3288 | // { |
---|
| 3289 | // //interred machen Aenderung |
---|
| 3290 | // pFDegOld=currRing->pFDeg; |
---|
| 3291 | // pLDegOld=pLDeg; |
---|
| 3292 | // //h=ggetid("ecart"); |
---|
| 3293 | // //if ((h!=NULL) /*&& (IDTYP(h)==INTVEC_CMD)*/) |
---|
| 3294 | // //{ |
---|
| 3295 | // // ecartWeights=iv2array(IDINTVEC(h)); |
---|
| 3296 | // //} |
---|
| 3297 | // //else |
---|
| 3298 | // { |
---|
| 3299 | // ecartWeights=(short *)omAlloc(((currRing->N)+1)*sizeof(short)); |
---|
| 3300 | // /*uses automatic computation of the ecartWeights to set them*/ |
---|
| 3301 | // kEcartWeights(F->m,IDELEMS(F)-1,ecartWeights,currRing); |
---|
| 3302 | // } |
---|
| 3303 | // pRestoreDegProcs(currRing,totaldegreeWecart, maxdegreeWecart); |
---|
| 3304 | // if (TEST_OPT_PROT) |
---|
| 3305 | // { |
---|
[d30a399] | 3306 | // for(int i=1; i<=rVar(currRing); i++) |
---|
[e533660] | 3307 | // Print(" %d",ecartWeights[i]); |
---|
| 3308 | // PrintLn(); |
---|
| 3309 | // mflush(); |
---|
| 3310 | // } |
---|
| 3311 | // } |
---|
[37a4c3] | 3312 | } |
---|
[037df4] | 3313 | #endif |
---|