[35aab3] | 1 | #ifndef KUTIL_H |
---|
| 2 | #define KUTIL_H |
---|
| 3 | /**************************************** |
---|
| 4 | * Computer Algebra System SINGULAR * |
---|
| 5 | ****************************************/ |
---|
[ca371d] | 6 | /* $Id: kutil.h,v 1.43 2009-03-18 16:56:02 Singular Exp $ */ |
---|
[35aab3] | 7 | /* |
---|
| 8 | * ABSTRACT: kernel: utils for kStd |
---|
| 9 | */ |
---|
| 10 | |
---|
| 11 | |
---|
| 12 | #include <string.h> |
---|
| 13 | #include <mylimits.h> |
---|
| 14 | |
---|
| 15 | #include "structs.h" |
---|
| 16 | #include "omalloc.h" |
---|
| 17 | #include "ring.h" |
---|
| 18 | #include "structs.h" |
---|
| 19 | #include "pShallowCopyDelete.h" |
---|
| 20 | |
---|
| 21 | #if 1 |
---|
| 22 | #define setmax 16 |
---|
[425d94c] | 23 | #define setmaxL ((4096-12)/sizeof(LObject)) |
---|
| 24 | #define setmaxLinc ((4096)/sizeof(LObject)) |
---|
[939847] | 25 | |
---|
| 26 | #define setmaxT 64 |
---|
| 27 | #define setmaxTinc 32 |
---|
[35aab3] | 28 | #else |
---|
| 29 | #define setmax 16 |
---|
| 30 | #define setmaxL 16 |
---|
| 31 | #define setmaxLinc 16 |
---|
| 32 | #define setmaxT 16 |
---|
| 33 | #define setmaxTinc 16 |
---|
| 34 | #endif |
---|
| 35 | |
---|
| 36 | // define if you want std computations as in Singular version < 2 |
---|
| 37 | // This disbales RedThrough, tailReductions against T (bba), |
---|
| 38 | // sets posInT = posInT15 (bba, strat->honey), and enables redFirst with LDeg |
---|
| 39 | // NOTE: the same effect can be achieved with option(oldStd) |
---|
| 40 | // #define HAVE_OLD_STD |
---|
| 41 | |
---|
| 42 | #ifdef HAVE_OLD_STD |
---|
| 43 | #define K_TEST_OPT_REDTHROUGH 0 |
---|
| 44 | #define K_TEST_OPT_OLDSTD 1 |
---|
| 45 | #else |
---|
| 46 | #define K_TEST_OPT_REDTHROUGH TEST_OPT_REDTHROUGH |
---|
| 47 | #define K_TEST_OPT_OLDSTD TEST_OPT_OLDSTD |
---|
| 48 | #endif |
---|
| 49 | |
---|
| 50 | #undef NO_KINLINE |
---|
| 51 | #if !defined(KDEBUG) && !defined(NO_INLINE) |
---|
| 52 | #define KINLINE inline |
---|
| 53 | #else |
---|
| 54 | #define KINLINE |
---|
| 55 | #define NO_KINLINE 1 |
---|
| 56 | #endif |
---|
| 57 | |
---|
| 58 | typedef int* intset; |
---|
[58ebad] | 59 | typedef int64 wlen_type; |
---|
[fe5ad5] | 60 | typedef wlen_type* wlen_set; |
---|
| 61 | |
---|
[35aab3] | 62 | typedef class sTObject TObject; |
---|
| 63 | typedef class sLObject LObject; |
---|
| 64 | typedef TObject * TSet; |
---|
| 65 | typedef LObject * LSet; |
---|
| 66 | |
---|
| 67 | class sTObject |
---|
| 68 | { |
---|
| 69 | public: |
---|
| 70 | poly p; // Lm(p) \in currRing Tail(p) \in tailRing |
---|
| 71 | poly t_p; // t_p \in tailRing: as monomials Lm(t_p) == Lm(p) |
---|
| 72 | poly max; // p_GetMaxExpP(pNext(p)) |
---|
[ad07b8] | 73 | ring tailRing; |
---|
[35aab3] | 74 | long FDeg; // pFDeg(p) |
---|
| 75 | int ecart, |
---|
| 76 | length, // as of pLDeg |
---|
| 77 | pLength, // either == 0, or == pLength(p) |
---|
| 78 | i_r; // index of TObject in R set, or -1 if not in T |
---|
| 79 | BOOLEAN is_normalized; // true, if pNorm was called on p, false otherwise |
---|
| 80 | |
---|
| 81 | // initialization |
---|
| 82 | KINLINE void Init(ring r = currRing); |
---|
| 83 | KINLINE sTObject(ring tailRing = currRing); |
---|
| 84 | KINLINE sTObject(poly p, ring tailRing = currRing); |
---|
| 85 | KINLINE sTObject(poly p, ring c_r, ring tailRing); |
---|
| 86 | KINLINE sTObject(sTObject* T, int copy); |
---|
| 87 | |
---|
| 88 | KINLINE void Set(ring r=currRing); |
---|
| 89 | KINLINE void Set(poly p_in, ring r=currRing); |
---|
| 90 | KINLINE void Set(poly p_in, ring c_r, ring t_r); |
---|
| 91 | |
---|
| 92 | // Frees the polys of T |
---|
| 93 | KINLINE void Delete(); |
---|
| 94 | // Sets polys to NULL |
---|
| 95 | KINLINE void Clear(); |
---|
| 96 | // makes a copy of the poly of T |
---|
| 97 | KINLINE void Copy(); |
---|
| 98 | |
---|
| 99 | // ring-dependent Lm access: these might result in allocation of monomials |
---|
| 100 | KINLINE poly GetLmCurrRing(); |
---|
| 101 | KINLINE poly GetLmTailRing(); |
---|
| 102 | KINLINE poly GetLm(ring r); |
---|
| 103 | // this returns Lm and ring r (preferably from tailRing), but does not |
---|
| 104 | // allocate a new poly |
---|
| 105 | KINLINE void GetLm(poly &p, ring &r) const; |
---|
[585bbcb] | 106 | |
---|
| 107 | #ifdef OLIVER_PRIVAT_LT |
---|
| 108 | // routines for calc. with rings |
---|
| 109 | KINLINE poly GetLtCurrRing(); |
---|
| 110 | KINLINE poly GetLtTailRing(); |
---|
| 111 | KINLINE poly GetLt(ring r); |
---|
| 112 | KINLINE void GetLt(poly &p, ring &r) const; |
---|
| 113 | #endif |
---|
| 114 | |
---|
[35aab3] | 115 | KINLINE BOOLEAN IsNull() const; |
---|
| 116 | |
---|
| 117 | KINLINE int GetpLength(); |
---|
| 118 | |
---|
| 119 | // makes sure that T.p exists |
---|
| 120 | KINLINE void SetLmCurrRing(); |
---|
| 121 | |
---|
| 122 | // Iterations |
---|
| 123 | // simply get the next monomial |
---|
| 124 | KINLINE poly Next(); |
---|
| 125 | KINLINE void LmDeleteAndIter(); |
---|
| 126 | |
---|
| 127 | // deg stuff |
---|
| 128 | // computes pFDeg |
---|
| 129 | KINLINE long pFDeg() const; |
---|
| 130 | // computes and sets FDeg |
---|
| 131 | KINLINE long SetpFDeg(); |
---|
| 132 | // gets stored FDeg |
---|
| 133 | KINLINE long GetpFDeg() const; |
---|
| 134 | |
---|
| 135 | // computes pLDeg |
---|
| 136 | KINLINE long pLDeg(); |
---|
| 137 | // sets length, FDeg, returns LDeg |
---|
| 138 | KINLINE long SetDegStuffReturnLDeg(); |
---|
| 139 | |
---|
| 140 | // arithmetic |
---|
| 141 | KINLINE void Mult_nn(number n); |
---|
| 142 | KINLINE void ShallowCopyDelete(ring new_tailRing, omBin new_tailBin, |
---|
| 143 | pShallowCopyDeleteProc p_shallow_copy_delete, |
---|
| 144 | BOOLEAN set_max = TRUE); |
---|
| 145 | // manipulations |
---|
| 146 | KINLINE void pNorm(); |
---|
| 147 | KINLINE void pCleardenom(); |
---|
| 148 | |
---|
| 149 | #ifdef KDEBUG |
---|
| 150 | void wrp(); |
---|
| 151 | #endif |
---|
| 152 | }; |
---|
| 153 | |
---|
[2d9e1e] | 154 | #ifndef NDEBUG |
---|
| 155 | extern int strat_nr; |
---|
| 156 | extern int strat_fac_debug; |
---|
| 157 | #endif |
---|
| 158 | |
---|
[35aab3] | 159 | class sLObject : public sTObject |
---|
| 160 | { |
---|
| 161 | |
---|
| 162 | public: |
---|
| 163 | unsigned long sev; |
---|
[63e7d6c] | 164 | poly p1,p2; /*- the pair p comes from, |
---|
| 165 | lm(pi) in currRing, tail(pi) in tailring -*/ |
---|
[35aab3] | 166 | |
---|
| 167 | poly lcm; /*- the lcm of p1,p2 -*/ |
---|
| 168 | poly last; // pLast(p) during reductions |
---|
| 169 | kBucket_pt bucket; |
---|
| 170 | int i_r1, i_r2; |
---|
| 171 | |
---|
| 172 | // initialization |
---|
| 173 | KINLINE void Init(ring tailRing = currRing); |
---|
| 174 | KINLINE sLObject(ring tailRing = currRing); |
---|
| 175 | KINLINE sLObject(poly p, ring tailRing = currRing); |
---|
| 176 | KINLINE sLObject(poly p, ring c_r, ring tailRing); |
---|
| 177 | |
---|
| 178 | // Frees the polys of L |
---|
| 179 | KINLINE void Delete(); |
---|
| 180 | KINLINE void Clear(); |
---|
| 181 | |
---|
| 182 | // Iterations |
---|
| 183 | KINLINE void LmDeleteAndIter(); |
---|
| 184 | KINLINE poly LmExtractAndIter(); |
---|
| 185 | |
---|
| 186 | // spoly related things |
---|
| 187 | // preparation for reduction if not spoly |
---|
| 188 | KINLINE void PrepareRed(BOOLEAN use_bucket); |
---|
| 189 | KINLINE void SetLmTail(poly lm, poly new_p, int length, |
---|
| 190 | int use_bucket, ring r, poly last); |
---|
| 191 | KINLINE void Tail_Minus_mm_Mult_qq(poly m, poly qq, int lq, poly spNoether); |
---|
| 192 | KINLINE void Tail_Mult_nn(number n); |
---|
| 193 | // deletes bucket, makes sure that p and t_p exists |
---|
| 194 | KINLINE poly GetP(omBin lmBin = NULL); |
---|
| 195 | // similar, except that only t_p exists |
---|
| 196 | KINLINE poly GetTP(); |
---|
| 197 | |
---|
| 198 | // does not delete bucket, just canonicalizes it |
---|
| 199 | // returned poly is such that Lm(p) \in currRing, Tail(p) \in tailRing |
---|
| 200 | KINLINE poly CanonicalizeP(); |
---|
| 201 | |
---|
| 202 | // makes a copy of the poly of L |
---|
| 203 | KINLINE void Copy(); |
---|
| 204 | // gets the poly and makes a copy of it |
---|
| 205 | KINLINE poly CopyGetP(); |
---|
| 206 | |
---|
| 207 | KINLINE int GetpLength(); |
---|
| 208 | KINLINE long pLDeg(BOOLEAN use_last); |
---|
| 209 | KINLINE long pLDeg(); |
---|
| 210 | KINLINE int SetLength(BOOLEAN lengt_pLength = FALSE); |
---|
| 211 | KINLINE long SetDegStuffReturnLDeg(); |
---|
| 212 | KINLINE long SetDegStuffReturnLDeg(BOOLEAN use_last); |
---|
| 213 | |
---|
| 214 | // returns minimal component of p |
---|
| 215 | KINLINE long MinComp(); |
---|
| 216 | // returns component of p |
---|
| 217 | KINLINE long Comp(); |
---|
| 218 | |
---|
| 219 | KINLINE void ShallowCopyDelete(ring new_tailRing, |
---|
| 220 | pShallowCopyDeleteProc p_shallow_copy_delete); |
---|
| 221 | |
---|
| 222 | // sets sev |
---|
| 223 | KINLINE void SetShortExpVector(); |
---|
| 224 | |
---|
| 225 | // enable assignment from TObject |
---|
| 226 | KINLINE sLObject& operator=(const sTObject&); |
---|
| 227 | |
---|
| 228 | // get T's corresponding to p1, p2: they might return NULL |
---|
| 229 | KINLINE TObject* T_1(const skStrategy* strat); |
---|
| 230 | KINLINE TObject* T_2(const skStrategy* strat); |
---|
| 231 | KINLINE void T_1_2(const skStrategy* strat, |
---|
| 232 | TObject* &T_1, TObject* &T_2); |
---|
[88f583] | 233 | |
---|
| 234 | // simplify coefficients |
---|
| 235 | KINLINE void Normalize(); |
---|
| 236 | KINLINE void HeadNormalize(); |
---|
[35aab3] | 237 | }; |
---|
| 238 | |
---|
| 239 | |
---|
| 240 | extern int HCord; |
---|
| 241 | |
---|
| 242 | class skStrategy; |
---|
| 243 | typedef skStrategy * kStrategy; |
---|
| 244 | class skStrategy |
---|
| 245 | { |
---|
| 246 | public: |
---|
| 247 | kStrategy next; |
---|
| 248 | int (*red)(LObject * L,kStrategy strat); |
---|
| 249 | void (*initEcart)(LObject * L); |
---|
| 250 | int (*posInT)(const TSet T,const int tl,LObject &h); |
---|
| 251 | int (*posInL)(const LSet set, const int length, |
---|
| 252 | LObject* L,const kStrategy strat); |
---|
[b130fb] | 253 | void (*enterS)(LObject h, int pos,kStrategy strat, int atR/* =-1*/ ); |
---|
[35aab3] | 254 | void (*initEcartPair)(LObject * h, poly f, poly g, int ecartF, int ecartG); |
---|
| 255 | int (*posInLOld)(const LSet Ls,const int Ll, |
---|
| 256 | LObject* Lo,const kStrategy strat); |
---|
[6c55ae] | 257 | void (*enterOnePair) (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR /*= -1*/); |
---|
| 258 | void (*chainCrit) (poly p,int ecart,kStrategy strat); |
---|
[35aab3] | 259 | pFDegProc pOrigFDeg; |
---|
| 260 | pLDegProc pOrigLDeg; |
---|
| 261 | pFDegProc pOrigFDeg_TailRing; |
---|
| 262 | pLDegProc pOrigLDeg_TailRing; |
---|
| 263 | |
---|
| 264 | LObject P; |
---|
| 265 | ideal Shdl; |
---|
| 266 | ideal D; /*V(S) is in D(D)*/ |
---|
| 267 | ideal M; /*set of minimal generators*/ |
---|
| 268 | polyset S; |
---|
| 269 | intset ecartS; |
---|
| 270 | intset lenS; |
---|
[fe5ad5] | 271 | wlen_set lenSw; /* for tgb.ccc */ |
---|
[35aab3] | 272 | intset fromQ; |
---|
| 273 | unsigned long* sevS; |
---|
| 274 | unsigned long* sevT; |
---|
| 275 | TSet T; |
---|
| 276 | LSet L; |
---|
| 277 | LSet B; |
---|
| 278 | poly kHEdge; |
---|
| 279 | poly kNoether; |
---|
| 280 | poly t_kHEdge; // same polys in tailring |
---|
| 281 | KINLINE poly kNoetherTail(); |
---|
| 282 | poly t_kNoether; |
---|
| 283 | BOOLEAN * NotUsedAxis; |
---|
[660ed3] | 284 | BOOLEAN * pairtest;/*used for enterOnePair*/ |
---|
[35aab3] | 285 | poly tail; |
---|
| 286 | leftv kIdeal; |
---|
| 287 | intvec * kModW; |
---|
| 288 | intvec * kHomW; |
---|
| 289 | // procedure for ShalloCopy from tailRing to currRing |
---|
| 290 | pShallowCopyDeleteProc p_shallow_copy_delete; |
---|
| 291 | // pointers to Tobjects R[i] is ith Tobject which is generated |
---|
| 292 | TObject** R; |
---|
| 293 | // S_2_R[i] yields Tobject which corresponds to S[i] |
---|
| 294 | int* S_2_R; |
---|
| 295 | ring tailRing; |
---|
| 296 | omBin lmBin; |
---|
| 297 | omBin tailBin; |
---|
[2d9e1e] | 298 | #ifndef NDEBUG |
---|
| 299 | int nr; |
---|
| 300 | #endif |
---|
[35aab3] | 301 | int cp,c3; |
---|
[1c473f] | 302 | int cv; // in shift bases: counting V criterion |
---|
[35aab3] | 303 | int sl,mu; |
---|
| 304 | int tl,tmax; |
---|
| 305 | int Ll,Lmax; |
---|
| 306 | int Bl,Bmax; |
---|
| 307 | int ak,LazyDegree,LazyPass; |
---|
| 308 | int syzComp; |
---|
| 309 | int HCord; |
---|
| 310 | int lastAxis; |
---|
| 311 | int newIdeal; |
---|
| 312 | int minim; |
---|
| 313 | BOOLEAN interpt; |
---|
| 314 | BOOLEAN homog; |
---|
[aef1b86] | 315 | #ifdef HAVE_PLURAL |
---|
| 316 | BOOLEAN z2homog; // Z_2 - homogeneous input allows product criterion in commutative and SCA cases! |
---|
| 317 | #endif |
---|
[35aab3] | 318 | BOOLEAN kHEdgeFound; |
---|
| 319 | BOOLEAN honey,sugarCrit; |
---|
| 320 | BOOLEAN Gebauer,noTailReduction; |
---|
| 321 | BOOLEAN fromT; |
---|
| 322 | BOOLEAN noetherSet; |
---|
| 323 | BOOLEAN update; |
---|
| 324 | BOOLEAN posInLOldFlag; |
---|
| 325 | BOOLEAN use_buckets; |
---|
| 326 | BOOLEAN interred_flag; |
---|
| 327 | // if set, pLDeg(p, l) == (pFDeg(pLast(p), pLength) |
---|
| 328 | BOOLEAN LDegLast; |
---|
| 329 | // if set, then L.length == L.pLength |
---|
| 330 | BOOLEAN length_pLength; |
---|
| 331 | // if set, then posInL does not depend on L.length |
---|
| 332 | BOOLEAN posInLDependsOnLength; |
---|
| 333 | /*FALSE, if posInL == posInL10*/ |
---|
[a794e7] | 334 | #ifdef HAVE_PLURAL |
---|
[cce4a2f] | 335 | // set this flag to 1 to stop the product criteria |
---|
| 336 | // use ALLOW_PROD_CRIT(strat) to test |
---|
[a794e7] | 337 | BOOLEAN no_prod_crit; |
---|
[cce4a2f] | 338 | #define ALLOW_PROD_CRIT(A) (!(A)->no_prod_crit) |
---|
[a794e7] | 339 | #else |
---|
[cce4a2f] | 340 | #define ALLOW_PROD_CRIT(A) (1) |
---|
[a794e7] | 341 | #endif |
---|
[35aab3] | 342 | char redTailChange; |
---|
| 343 | char news; |
---|
| 344 | char newt;/*used for messageSets*/ |
---|
[660ed3] | 345 | char noClearS; |
---|
[b57694] | 346 | char completeReduce_retry; |
---|
[35aab3] | 347 | |
---|
| 348 | skStrategy(); |
---|
| 349 | ~skStrategy(); |
---|
| 350 | |
---|
| 351 | // return TObject corresponding to S[i]: assume that it exists |
---|
| 352 | // i.e. no error checking is done |
---|
| 353 | KINLINE TObject* S_2_T(int i); |
---|
| 354 | // like S_2_T, except that NULL is returned if it can not be found |
---|
| 355 | KINLINE TObject* s_2_t(int i); |
---|
| 356 | }; |
---|
| 357 | |
---|
| 358 | void deleteHC(poly *p, int *e, int *l, kStrategy strat); |
---|
| 359 | void deleteHC(LObject* L, kStrategy strat, BOOLEAN fromNext = FALSE); |
---|
| 360 | void deleteInS (int i,kStrategy strat); |
---|
| 361 | void cleanT (kStrategy strat); |
---|
[e259fe] | 362 | static inline LSet initL (int nr=setmaxL) |
---|
| 363 | { return (LSet)omAlloc(nr*sizeof(LObject)); }; |
---|
[35aab3] | 364 | void deleteInL(LSet set, int *length, int j,kStrategy strat); |
---|
| 365 | void enterL (LSet *set,int *length, int *LSetmax, LObject p,int at); |
---|
| 366 | void enterSBba (LObject p,int atS,kStrategy strat, int atR = -1); |
---|
| 367 | void initEcartPairBba (LObject* Lp,poly f,poly g,int ecartF,int ecartG); |
---|
| 368 | void initEcartPairMora (LObject* Lp,poly f,poly g,int ecartF,int ecartG); |
---|
[391323] | 369 | int posInS (const kStrategy strat, const int length, const poly p, |
---|
| 370 | const int ecart_p); |
---|
[35aab3] | 371 | int posInT0 (const TSet set,const int length,LObject &p); |
---|
| 372 | int posInT1 (const TSet set,const int length,LObject &p); |
---|
| 373 | int posInT2 (const TSet set,const int length,LObject &p); |
---|
| 374 | int posInT11 (const TSet set,const int length,LObject &p); |
---|
| 375 | int posInT110 (const TSet set,const int length,LObject &p); |
---|
| 376 | int posInT13 (const TSet set,const int length,LObject &p); |
---|
| 377 | int posInT15 (const TSet set,const int length,LObject &p); |
---|
| 378 | int posInT17 (const TSet set,const int length,LObject &p); |
---|
| 379 | int posInT19 (const TSet set,const int length,LObject &p); |
---|
| 380 | int posInT_EcartpLength(const TSet set,const int length,LObject &p); |
---|
| 381 | |
---|
| 382 | #ifdef HAVE_MORE_POS_IN_T |
---|
| 383 | int posInT_EcartFDegpLength(const TSet set,const int length,LObject &p); |
---|
| 384 | int posInT_FDegpLength(const TSet set,const int length,LObject &p); |
---|
| 385 | int posInT_pLength(const TSet set,const int length,LObject &p); |
---|
| 386 | #endif |
---|
| 387 | |
---|
| 388 | |
---|
| 389 | void reorderS (int* suc,kStrategy strat); |
---|
| 390 | int posInL0 (const LSet set, const int length, |
---|
| 391 | LObject* L,const kStrategy strat); |
---|
| 392 | int posInL11 (const LSet set, const int length, |
---|
| 393 | LObject* L,const kStrategy strat); |
---|
| 394 | int posInL13 (const LSet set, const int length, |
---|
| 395 | LObject* L,const kStrategy strat); |
---|
| 396 | int posInL15 (const LSet set, const int length, |
---|
| 397 | LObject* L,const kStrategy strat); |
---|
| 398 | int posInL17 (const LSet set, const int length, |
---|
| 399 | LObject* L,const kStrategy strat); |
---|
| 400 | int posInL10 (const LSet set, const int length, |
---|
| 401 | LObject* L,const kStrategy strat); |
---|
[015bba] | 402 | KINLINE poly redtailBba (poly p,int pos,kStrategy strat,BOOLEAN normalize=FALSE); |
---|
| 403 | poly redtailBba (LObject *L, int pos,kStrategy strat, |
---|
| 404 | BOOLEAN withT = FALSE,BOOLEAN normalize=FALSE); |
---|
| 405 | poly redtailBba (TObject *T, int pos,kStrategy strat); |
---|
[35aab3] | 406 | poly redtail (poly p,int pos,kStrategy strat); |
---|
| 407 | poly redtail (LObject *L,int pos,kStrategy strat); |
---|
[ab1c36] | 408 | poly redNF (poly h,int & max_ind,int nonorm,kStrategy strat); |
---|
[35aab3] | 409 | int redNF0 (LObject *P,kStrategy strat); |
---|
| 410 | poly redNFTail (poly h,const int sl,kStrategy strat); |
---|
| 411 | int redHoney (LObject* h, kStrategy strat); |
---|
[206e158] | 412 | #ifdef HAVE_RINGS |
---|
[093f30e] | 413 | int redRing (LObject* h,kStrategy strat); |
---|
[f92547] | 414 | void enterExtendedSpoly(poly h,kStrategy strat); |
---|
| 415 | void superenterpairs (poly h,int k,int ecart,int pos,kStrategy strat, int atR = -1); |
---|
[6d09f28] | 416 | poly kCreateZeroPoly(long exp[], long cabsind, poly* t_p, ring leadRing, ring tailRing); |
---|
[206e158] | 417 | #endif |
---|
| 418 | #ifdef HAVE_RING2TOM |
---|
| 419 | long ind2(long arg); |
---|
| 420 | long ind_fact_2(long arg); |
---|
| 421 | long twoPow(long arg); |
---|
[6d09f28] | 422 | ideal createG0(); |
---|
[585bbcb] | 423 | #endif |
---|
[35aab3] | 424 | int redLazy (LObject* h,kStrategy strat); |
---|
| 425 | int redHomog (LObject* h,kStrategy strat); |
---|
| 426 | void enterpairs (poly h, int k, int ec, int pos,kStrategy strat, int atR = -1); |
---|
| 427 | void entersets (LObject h); |
---|
| 428 | void pairs (); |
---|
| 429 | void message (int i,int* reduc,int* olddeg,kStrategy strat,int red_result); |
---|
| 430 | void messageStat (int srmax,int lrmax,int hilbcount,kStrategy strat); |
---|
| 431 | #ifdef KDEBUG |
---|
| 432 | void messageSets (kStrategy strat); |
---|
| 433 | #else |
---|
| 434 | #define messageSets(s) ((void) 0) |
---|
| 435 | #endif |
---|
| 436 | |
---|
| 437 | void initEcartNormal (LObject* h); |
---|
| 438 | void initEcartBBA (LObject* h); |
---|
| 439 | void initS (ideal F, ideal Q,kStrategy strat); |
---|
| 440 | void initSL (ideal F, ideal Q,kStrategy strat); |
---|
| 441 | void updateS(BOOLEAN toT,kStrategy strat); |
---|
| 442 | void enterT (LObject p,kStrategy strat, int atT = -1); |
---|
[5572c1] | 443 | void cancelunit (LObject* p,BOOLEAN inNF=FALSE); |
---|
[35aab3] | 444 | void HEckeTest (poly pp,kStrategy strat); |
---|
| 445 | void initBuchMoraCrit(kStrategy strat); |
---|
| 446 | void initHilbCrit(ideal F, ideal Q, intvec **hilb,kStrategy strat); |
---|
| 447 | void initBuchMoraPos(kStrategy strat); |
---|
| 448 | void initBuchMora (ideal F, ideal Q,kStrategy strat); |
---|
| 449 | void exitBuchMora (kStrategy strat); |
---|
| 450 | void updateResult(ideal r,ideal Q,kStrategy strat); |
---|
[4d43ff] | 451 | void completeReduce (kStrategy strat, BOOLEAN withT=FALSE); |
---|
[35aab3] | 452 | void kFreeStrat(kStrategy strat); |
---|
[6c55ae] | 453 | void enterOnePairNormal (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR); |
---|
| 454 | void chainCritNormal (poly p,int ecart,kStrategy strat); |
---|
[35aab3] | 455 | BOOLEAN homogTest(polyset F, int Fmax); |
---|
| 456 | BOOLEAN newHEdge(polyset S, kStrategy strat); |
---|
| 457 | // returns index of p in TSet, or -1 if not found |
---|
| 458 | int kFindInT(poly p, TSet T, int tlength); |
---|
| 459 | |
---|
| 460 | // return -1 if no divisor is found |
---|
| 461 | // number of first divisor, otherwise |
---|
| 462 | int kFindDivisibleByInT(const TSet &T, const unsigned long* sevT, |
---|
| 463 | const int tl, const LObject* L, const int start=0); |
---|
| 464 | // same with S |
---|
[391323] | 465 | int kFindDivisibleByInS(const kStrategy strat, int *max_ind, LObject* L); |
---|
[35aab3] | 466 | |
---|
[7ba059] | 467 | int kFindNextDivisibleByInS(const kStrategy strat, int start,int max_ind, LObject* L); |
---|
[35aab3] | 468 | TObject* |
---|
| 469 | kFindDivisibleByInS(kStrategy strat, int pos, LObject* L, TObject *T, |
---|
| 470 | long ecart = LONG_MAX); |
---|
| 471 | |
---|
| 472 | /*************************************************************** |
---|
| 473 | * |
---|
| 474 | * stuff to be inlined |
---|
| 475 | * |
---|
| 476 | ***************************************************************/ |
---|
| 477 | |
---|
| 478 | KINLINE TSet initT (); |
---|
| 479 | KINLINE TObject** initR(); |
---|
| 480 | KINLINE unsigned long* initsevT(); |
---|
| 481 | KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing, omBin bin); |
---|
| 482 | KINLINE poly k_LmInit_tailRing_2_currRing(poly p, ring tailRing, omBin bin); |
---|
| 483 | KINLINE poly k_LmShallowCopyDelete_currRing_2_tailRing(poly p, ring tailRing, omBin bin); |
---|
| 484 | KINLINE poly k_LmShallowCopyDelete_tailRing_2_currRing(poly p, ring tailRing, omBin bin); |
---|
| 485 | |
---|
| 486 | KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing); |
---|
| 487 | KINLINE poly k_LmInit_tailRing_2_currRing(poly p, ring tailRing); |
---|
| 488 | KINLINE poly k_LmShallowCopyDelete_currRing_2_tailRing(poly p, ring tailRing); |
---|
| 489 | KINLINE poly k_LmShallowCopyDelete_tailRing_2_currRing(poly p, ring tailRing); |
---|
| 490 | |
---|
| 491 | // if exp bound is not violated, return TRUE and |
---|
| 492 | // get m1 = LCM(LM(p1), LM(p2))/LM(p1) |
---|
| 493 | // m2 = LCM(LM(p1), LM(p2))/LM(p2) |
---|
| 494 | // return FALSE and m1 == NULL, m2 == NULL , otherwise |
---|
| 495 | KINLINE BOOLEAN k_GetLeadTerms(const poly p1, const poly p2, const ring p_r, |
---|
| 496 | poly &m1, poly &m2, const ring m_r); |
---|
[d681e8] | 497 | #ifdef HAVE_RINGS |
---|
[ca371d] | 498 | KINLINE void k_GetStrongLeadTerms(const poly p1, const poly p2, const ring leadRing, |
---|
[d681e8] | 499 | poly &m1, poly &m2, poly &lcm, const ring taiRing); |
---|
| 500 | #endif |
---|
[35aab3] | 501 | #ifdef KDEBUG |
---|
| 502 | // test strat |
---|
| 503 | BOOLEAN kTest(kStrategy strat); |
---|
| 504 | // test strat, and test that S is contained in T |
---|
| 505 | BOOLEAN kTest_TS(kStrategy strat); |
---|
| 506 | // test LObject |
---|
| 507 | BOOLEAN kTest_L(LObject* L, ring tailRing = NULL, |
---|
| 508 | BOOLEAN testp = FALSE, int lpos = -1, |
---|
| 509 | TSet T = NULL, int tlength = -1); |
---|
| 510 | // test TObject |
---|
| 511 | BOOLEAN kTest_T(TObject* T, ring tailRing = NULL, int tpos = -1, char TN = '?'); |
---|
| 512 | // test set strat->SevS |
---|
| 513 | BOOLEAN kTest_S(kStrategy strat); |
---|
| 514 | #else |
---|
| 515 | #define kTest(A) ((void)0) |
---|
| 516 | #define kTest_TS(A) ((void)0) |
---|
| 517 | #define kTest_T(T) ((void)0) |
---|
| 518 | #define kTest_S(T) ((void)0) |
---|
| 519 | #define kTest_L(T) ((void)0) |
---|
| 520 | #endif |
---|
| 521 | |
---|
| 522 | |
---|
| 523 | /*************************************************************** |
---|
| 524 | * |
---|
| 525 | * From kstd2.cc |
---|
| 526 | * |
---|
| 527 | ***************************************************************/ |
---|
[a6889e] | 528 | poly kFindZeroPoly(poly input_p, ring leadRing, ring tailRing); |
---|
[35aab3] | 529 | ideal bba (ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat); |
---|
| 530 | poly kNF2 (ideal F, ideal Q, poly q, kStrategy strat, int lazyReduce); |
---|
| 531 | ideal kNF2 (ideal F,ideal Q,ideal q, kStrategy strat, int lazyReduce); |
---|
| 532 | void initBba(ideal F,kStrategy strat); |
---|
| 533 | |
---|
| 534 | /*************************************************************** |
---|
| 535 | * |
---|
| 536 | * From kSpolys.cc |
---|
| 537 | * |
---|
| 538 | ***************************************************************/ |
---|
| 539 | // Reduces PR with PW |
---|
| 540 | // Assumes PR != NULL, PW != NULL, Lm(PW) divides Lm(PR) |
---|
| 541 | // Changes: PR |
---|
| 542 | // Const: PW |
---|
| 543 | // If coef != NULL, then *coef is a/gcd(a,b), where a = LC(PR), b = LC(PW) |
---|
| 544 | // If strat != NULL, tailRing is changed if reduction would violate exp bound |
---|
| 545 | // of tailRing |
---|
| 546 | // Returns: 0 everything ok, no tailRing change |
---|
| 547 | // 1 tailRing has successfully changed (strat != NULL) |
---|
| 548 | // 2 no reduction performed, tailRing needs to be changed first |
---|
| 549 | // (strat == NULL) |
---|
| 550 | // -1 tailRing change could not be performed due to exceeding exp |
---|
| 551 | // bound of currRing |
---|
| 552 | int ksReducePoly(LObject* PR, |
---|
| 553 | TObject* PW, |
---|
| 554 | poly spNoether = NULL, |
---|
| 555 | number *coef = NULL, |
---|
| 556 | kStrategy strat = NULL); |
---|
| 557 | |
---|
| 558 | // Reduces PR at Current->next with PW |
---|
| 559 | // Assumes PR != NULL, Current contained in PR |
---|
| 560 | // Current->next != NULL, LM(PW) devides LM(Current->next) |
---|
| 561 | // Changes: PR |
---|
| 562 | // Const: PW |
---|
| 563 | // Return: see ksReducePoly |
---|
| 564 | int ksReducePolyTail(LObject* PR, |
---|
| 565 | TObject* PW, |
---|
| 566 | poly Current, |
---|
| 567 | poly spNoether = NULL); |
---|
| 568 | |
---|
| 569 | KINLINE int ksReducePolyTail(LObject* PR, TObject* PW, LObject* Red); |
---|
| 570 | |
---|
| 571 | // Creates S-Poly of Pair |
---|
| 572 | // Const: Pair->p1, Pair->p2 |
---|
| 573 | // Changes: Pair->p == S-Poly of p1, p2 |
---|
| 574 | // Assume: Pair->p1 != NULL && Pair->p2 |
---|
| 575 | void ksCreateSpoly(LObject* Pair, poly spNoether = NULL, |
---|
| 576 | int use_buckets=0, ring tailRing=currRing, |
---|
| 577 | poly m1 = NULL, poly m2 = NULL, TObject** R = NULL); |
---|
| 578 | |
---|
| 579 | /*2 |
---|
| 580 | * creates the leading term of the S-polynomial of p1 and p2 |
---|
| 581 | * do not destroy p1 and p2 |
---|
| 582 | * remarks: |
---|
| 583 | * 1. the coefficient is 0 (nNew) |
---|
| 584 | * 2. pNext is undefined |
---|
| 585 | */ |
---|
| 586 | poly ksCreateShortSpoly(poly p1, poly p2, ring tailRing); |
---|
| 587 | |
---|
| 588 | |
---|
| 589 | /* |
---|
| 590 | * input - output: a, b |
---|
| 591 | * returns: |
---|
| 592 | * a := a/gcd(a,b), b := b/gcd(a,b) |
---|
| 593 | * and return value |
---|
| 594 | * 0 -> a != 1, b != 1 |
---|
| 595 | * 1 -> a == 1, b != 1 |
---|
| 596 | * 2 -> a != 1, b == 1 |
---|
| 597 | * 3 -> a == 1, b == 1 |
---|
| 598 | * this value is used to control the spolys |
---|
| 599 | */ |
---|
| 600 | int ksCheckCoeff(number *a, number *b); |
---|
| 601 | |
---|
| 602 | // old stuff |
---|
| 603 | KINLINE poly ksOldSpolyRed(poly p1, poly p2, poly spNoether = NULL); |
---|
| 604 | KINLINE poly ksOldSpolyRedNew(poly p1, poly p2, poly spNoether = NULL); |
---|
| 605 | KINLINE poly ksOldCreateSpoly(poly p1, poly p2, poly spNoether = NULL, ring r = currRing); |
---|
| 606 | KINLINE void ksOldSpolyTail(poly p1, poly q, poly q2, poly spNoether, ring r = currRing); |
---|
| 607 | |
---|
| 608 | /*************************************************************** |
---|
| 609 | * |
---|
| 610 | * Routines related for ring changes during std computations |
---|
| 611 | * |
---|
| 612 | ***************************************************************/ |
---|
| 613 | // return TRUE and set m1, m2 to k_GetLcmTerms, |
---|
| 614 | // if spoly creation of strat->P does not violate |
---|
| 615 | // exponent bound of strat->tailRing |
---|
| 616 | // FALSE, otherwise |
---|
| 617 | BOOLEAN kCheckSpolyCreation(LObject* L, kStrategy strat, poly &m1, poly &m2); |
---|
[7245240] | 618 | #ifdef HAVE_RINGS |
---|
| 619 | // return TRUE if gcdpoly creation of R[atR] and S[atS] does not violate |
---|
| 620 | // exponent bound of strat->tailRing |
---|
| 621 | // FALSE, otherwise |
---|
| 622 | BOOLEAN kCheckStrongCreation(int atR, poly m1, int atS, poly m2, kStrategy strat); |
---|
| 623 | #endif |
---|
[35aab3] | 624 | // change strat->tailRing and adjust all data in strat, L, and T: |
---|
| 625 | // new tailRing has larger exponent bound |
---|
| 626 | // do nothing and return FALSE if exponent bound increase would result in |
---|
| 627 | // larger exponent bound that that of currRing |
---|
| 628 | BOOLEAN kStratChangeTailRing(kStrategy strat, |
---|
| 629 | LObject* L = NULL, TObject* T = NULL, |
---|
| 630 | // take this as new_expbound: if 0 |
---|
| 631 | // new expbound is 2*expbound of tailRing |
---|
| 632 | unsigned long new_expbound = 0); |
---|
| 633 | // initiate a change of the tailRing of strat -- should be called |
---|
| 634 | // right before main loop in bba |
---|
| 635 | void kStratInitChangeTailRing(kStrategy strat); |
---|
| 636 | |
---|
[ec69aa] | 637 | KINLINE void clearS (poly p, unsigned long p_sev, int* at, int* k, |
---|
| 638 | kStrategy strat); |
---|
[35aab3] | 639 | #include "kInline.cc" |
---|
| 640 | |
---|
[cb0fbe] | 641 | /* shiftgb stuff */ |
---|
| 642 | #include "shiftgb.h" |
---|
[35aab3] | 643 | |
---|
[4d2ab5c] | 644 | poly pMove2CurrTail(poly p, kStrategy strat); |
---|
| 645 | |
---|
| 646 | poly pMoveCurrTail2poly(poly p, kStrategy strat); |
---|
| 647 | |
---|
| 648 | poly pCopyL2p(LObject h, kStrategy strat); |
---|
| 649 | |
---|
[37a4c3] | 650 | void enterTShift(LObject p, kStrategy strat, int atT, int uptodeg, int lV); |
---|
[cb0fbe] | 651 | |
---|
[37a4c3] | 652 | void initBuchMoraShift (ideal F,ideal Q,kStrategy strat); |
---|
| 653 | |
---|
| 654 | void enterOnePairManyShifts (int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int uptodeg, int lV); // ok |
---|
| 655 | |
---|
| 656 | void enterOnePairSelfShifts (poly qq, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int uptodeg, int lV); |
---|
| 657 | |
---|
[4d2ab5c] | 658 | void enterOnePairShift (poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS, int uptodeg, int lV); // ok |
---|
[37a4c3] | 659 | |
---|
| 660 | void enterpairsShift (poly h,int k,int ecart,int pos,kStrategy strat, int atR,int uptodeg, int lV); |
---|
| 661 | |
---|
| 662 | void initenterpairsShift (poly h,int k,int ecart,int isFromQ,kStrategy strat, int atR,int uptodeg, int lV); |
---|
| 663 | |
---|
| 664 | void updateSShift(kStrategy strat,int uptodeg,int lV); |
---|
[cb0fbe] | 665 | |
---|
| 666 | void initBbaShift(ideal F,kStrategy strat); |
---|
| 667 | |
---|
[37a4c3] | 668 | poly redtailBbaShift (LObject* L, int pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize); |
---|
| 669 | |
---|
| 670 | int redFirstShift (LObject* h,kStrategy strat); // ok |
---|
[cb0fbe] | 671 | |
---|
| 672 | ideal freegb(ideal I, int uptodeg, int lVblock); |
---|
[1c473f] | 673 | |
---|
| 674 | ideal bbaShift(ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat, int uptodeg, int lV); |
---|
[35aab3] | 675 | #endif |
---|