source: git/kernel/GBEngine/kutil.h @ 94b41d

spielwiese
Last change on this file since 94b41d was 94b41d, checked in by Karim Abou Zeid <karim23697@…>, 4 years ago
LP Z V1
  • Property mode set to 100644
File size: 32.4 KB
Line 
1#ifndef KUTIL_H
2#define KUTIL_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/*
7* ABSTRACT: kernel: utils for kStd
8*/
9
10
11#include <string.h>
12
13#include "omalloc/omalloc.h"
14#ifdef HAVE_OMALLOC
15#include "omalloc/omallocClass.h"
16#endif
17
18#include "misc/mylimits.h"
19
20#include "kernel/polys.h"
21#include "polys/operations/pShallowCopyDelete.h"
22
23#include "kernel/structs.h"
24#include "kernel/GBEngine/kstd1.h"   /* for s_poly_proc_t */
25
26// define if tailrings should be used
27#define HAVE_TAIL_RING
28
29#define setmax 128
30#define setmaxL ((4096-12)/sizeof(LObject))
31#define setmaxLinc ((4096)/sizeof(LObject))
32
33#define setmaxT ((4096-12)/sizeof(TObject))
34#define setmaxTinc ((4096)/sizeof(TObject))
35
36// if you want std computations as in Singular version < 2:
37// This disables RedThrough, tailReductions against T (bba),
38// sets posInT = posInT15 (bba, strat->honey), and enables redFirst with LDeg
39// NOTE: can be achieved with option(oldStd)
40
41#undef NO_KINLINE
42#if !defined(KDEBUG) && !defined(NO_INLINE)
43#define KINLINE inline
44#else
45#define KINLINE
46#define NO_KINLINE 1
47#endif
48
49typedef int* intset;
50typedef int64  wlen_type;
51typedef wlen_type* wlen_set;
52
53typedef class sTObject TObject;
54typedef class sLObject LObject;
55typedef TObject * TSet;
56typedef LObject * LSet;
57
58typedef struct denominator_list_s denominator_list_s;
59typedef denominator_list_s *denominator_list;
60
61struct denominator_list_s{number n; denominator_list next;};
62EXTERN_VAR denominator_list DENOMINATOR_LIST;
63
64class sTObject
65{
66public:
67  unsigned long sevSig;
68  poly sig;   // the signature of the element
69  poly p;       // Lm(p) \in currRing Tail(p) \in tailRing
70  poly t_p;     // t_p \in tailRing: as monomials Lm(t_p) == Lm(p)
71  poly max_exp;     // p_GetMaxExpP(pNext(p))
72  ring tailRing;
73  long FDeg;    // pFDeg(p)
74  int ecart,
75    length,     // as of pLDeg
76    pLength,    // either == 0, or == pLength(p)
77    i_r;        // index of TObject in R set, or -1 if not in T
78
79#ifdef HAVE_SHIFTBBA
80  int shift;
81#endif
82
83  /*BOOLEAN*/ char is_normalized; // true, if pNorm was called on p, false otherwise
84  // used in incremental sba() with F5C:
85  // we know some of the redundant elements in
86  // strat->T beforehand, so we can just discard
87  // them and do not need to consider them in the
88  // interreduction process
89  /*BOOLEAN*/ char is_redundant;
90  // used in sba's sig-safe reduction:
91  // sometimes we already know that a reducer
92  // is sig-safe, so no need for a real
93  // sig-safeness check
94  /*BOOLEAN*/ char is_sigsafe;
95
96
97#ifdef HAVE_PLURAL
98  /*BOOLEAN*/ char is_special; // true, it is a new special S-poly (e.g. for SCA)
99#endif
100
101  // initialization
102  KINLINE void Init(ring r = currRing);
103  KINLINE sTObject(ring tailRing = currRing);
104  KINLINE sTObject(poly p, ring tailRing = currRing);
105  KINLINE sTObject(poly p, ring c_r, ring tailRing);
106  KINLINE sTObject(sTObject* T, int copy);
107
108  KINLINE void Set(ring r=currRing);
109  KINLINE void Set(poly p_in, ring r=currRing);
110  KINLINE void Set(poly p_in, ring c_r, ring t_r);
111
112  // Frees the polys of T
113  KINLINE void Delete();
114  // Sets polys to NULL
115  KINLINE void Clear();
116  // makes a copy of the poly of T
117  KINLINE void Copy();
118
119  // ring-dependent Lm access: these might result in allocation of monomials
120  KINLINE poly GetLmCurrRing();
121  KINLINE poly GetLmTailRing();
122  KINLINE poly GetLm(ring r);
123  // this returns Lm and ring r (preferably from tailRing), but does not
124  // allocate a new poly
125  KINLINE void GetLm(poly &p, ring &r) const;
126
127#ifdef OLIVER_PRIVAT_LT
128  // routines for calc. with rings
129  KINLINE poly GetLtCurrRing();
130  KINLINE poly GetLtTailRing();
131  KINLINE poly GetLt(ring r);
132  KINLINE void GetLt(poly &p, ring &r) const;
133#endif
134
135  KINLINE BOOLEAN IsNull() const;
136
137  KINLINE int GetpLength();
138
139  // makes sure that T.p exists
140  KINLINE void SetLmCurrRing();
141
142  // Iterations
143  // simply get the next monomial
144  KINLINE poly Next();
145  KINLINE void LmDeleteAndIter();
146
147  // deg stuff
148  // compute pTotalDegree
149  KINLINE long pTotalDeg() const;
150  // computes pFDeg
151  KINLINE long pFDeg() const;
152  // computes and sets FDeg
153  KINLINE long SetpFDeg();
154  // gets stored FDeg
155  KINLINE long GetpFDeg() const;
156
157  // computes pLDeg
158  KINLINE long pLDeg();
159  // sets length, FDeg, returns LDeg
160  KINLINE long SetDegStuffReturnLDeg();
161
162  // arithmetic
163  KINLINE void Mult_nn(number n);
164  KINLINE void ShallowCopyDelete(ring new_tailRing, omBin new_tailBin,
165                                 pShallowCopyDeleteProc p_shallow_copy_delete,
166                                 BOOLEAN set_max = TRUE);
167  // manipulations
168  KINLINE void pNorm();
169  KINLINE void pCleardenom();
170
171#ifdef KDEBUG
172  void wrp();
173#endif
174};
175
176EXTERN_VAR int strat_nr;
177
178class sLObject : public sTObject
179{
180
181public:
182  unsigned long sev;
183  poly  p1,p2; /*- the pair p comes from,
184                 lm(pi) in currRing, tail(pi) in tailring -*/
185
186  poly  lcm;   /*- the lcm of p1,p2 -*/
187  kBucket_pt bucket;
188  int   i_r1, i_r2;
189  unsigned checked; // this is the index of S up to which
190                      // the corresponding LObject was already checked in
191                      // critical pair creation => when entering the
192                      // reduction process it is enough to start a second
193                      // rewritten criterion check from checked+1 onwards
194  BOOLEAN prod_crit;
195                      // NOTE: If prod_crit = TRUE then the corresponding pair is
196                      // detected by Buchberger's Product Criterion and can be
197                      // deleted
198
199  // initialization
200  KINLINE void Init(ring tailRing = currRing);
201  KINLINE sLObject(ring tailRing = currRing);
202  KINLINE sLObject(poly p, ring tailRing = currRing);
203  KINLINE sLObject(poly p, ring c_r, ring tailRing);
204
205  // Frees the polys of L
206  KINLINE void Delete();
207  KINLINE void Clear();
208
209  // Iterations
210  KINLINE void LmDeleteAndIter();
211  KINLINE poly LmExtractAndIter();
212
213  // spoly related things
214  // preparation for reduction if not spoly
215  KINLINE void PrepareRed(BOOLEAN use_bucket);
216  KINLINE void SetLmTail(poly lm, poly new_p, int length,
217                         int use_bucket, ring r);
218  KINLINE void Tail_Minus_mm_Mult_qq(poly m, poly qq, int lq, poly spNoether);
219  KINLINE void Tail_Mult_nn(number n);
220  // deletes bucket, makes sure that p and t_p exists
221  KINLINE poly GetP(omBin lmBin = (omBin)NULL);
222  // similar, except that only t_p exists
223  KINLINE poly GetTP();
224
225  // does not delete bucket, just canonicalizes it
226  // returned poly is such that Lm(p) \in currRing, Tail(p) \in tailRing
227  KINLINE void CanonicalizeP();
228
229  // makes a copy of the poly of L
230  KINLINE void Copy();
231
232  KINLINE int GetpLength();
233  KINLINE long pLDeg(BOOLEAN use_last);
234  KINLINE long pLDeg();
235  KINLINE int SetLength(BOOLEAN lengt_pLength = FALSE);
236  KINLINE long SetDegStuffReturnLDeg();
237  KINLINE long SetDegStuffReturnLDeg(BOOLEAN use_last);
238
239  // returns minimal component of p
240  KINLINE long MinComp();
241  // returns component of p
242  KINLINE long Comp();
243
244  KINLINE void ShallowCopyDelete(ring new_tailRing,
245                                 pShallowCopyDeleteProc p_shallow_copy_delete);
246
247  // sets sev
248  KINLINE void SetShortExpVector();
249
250  // enable assignment from TObject
251  KINLINE sLObject& operator=(const sTObject&);
252
253  // get T's corresponding to p1, p2: they might return NULL
254  KINLINE TObject* T_1(const skStrategy* strat);
255  KINLINE TObject* T_2(const skStrategy* strat);
256  KINLINE void     T_1_2(const skStrategy* strat,
257                         TObject* &T_1, TObject* &T_2);
258
259  // simplify coefficients
260  KINLINE void Normalize();
261  KINLINE void HeadNormalize();
262};
263
264
265EXTERN_VAR int HCord;
266
267class skStrategy
268#ifdef HAVE_OMALLOC
269                 : public omallocClass
270#endif
271{
272public:
273  kStrategy next;
274  int (*red)(LObject * L,kStrategy strat);
275  int (*red2)(LObject * L,kStrategy strat);
276  void (*initEcart)(TObject * L);
277  int (*posInT)(const TSet T,const int tl,LObject &h);
278  int (*posInLSba)(const LSet set, const int length,
279                LObject* L,const kStrategy strat);
280  int (*posInL)(const LSet set, const int length,
281                LObject* L,const kStrategy strat);
282  void (*enterS)(LObject &h, int pos,kStrategy strat, int atR/* =-1*/ );
283  void (*initEcartPair)(LObject * h, poly f, poly g, int ecartF, int ecartG);
284  int (*posInLOld)(const LSet Ls,const int Ll,
285                   LObject* Lo,const kStrategy strat);
286  void (*enterOnePair) (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR /*= -1*/);
287  void (*chainCrit) (poly p,int ecart,kStrategy strat);
288  BOOLEAN (*syzCrit) (poly sig, unsigned long not_sevSig, kStrategy strat);
289  BOOLEAN (*rewCrit1) (poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start /*= 0*/);
290  BOOLEAN (*rewCrit2) (poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start /*= 0*/);
291  BOOLEAN (*rewCrit3) (poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start /*= 0*/);
292  pFDegProc pOrigFDeg;
293  pLDegProc pOrigLDeg;
294  pFDegProc pOrigFDeg_TailRing;
295  pLDegProc pOrigLDeg_TailRing;
296  s_poly_proc_t s_poly;
297
298  LObject P;
299  ideal Shdl;
300  ideal D; /*V(S) is in D(D)*/
301  ideal M; /*set of minimal generators*/
302  polyset S;
303  polyset syz;
304  polyset sig;
305  intset ecartS;
306  intset fromS; // from which S[i] S[j] comes from
307                // this is important for signature-based
308                // algorithms
309  intset syzIdx;// index in the syz array at which the first
310                // syzygy of component i comes up
311                // important for signature-based algorithms
312  unsigned sbaOrder;
313  int currIdx;
314  int max_lower_index;
315  intset lenS;
316  wlen_set lenSw; /* for tgb.ccc */
317  intset fromQ;
318  unsigned long* sevS;
319  unsigned long* sevSyz;
320  unsigned long* sevSig;
321  unsigned long* sevT;
322  TSet T;
323  LSet L;
324  LSet    B;
325  poly    kHEdge;
326  poly    kNoether;
327  poly    t_kHEdge; // same polys in tailring
328  KINLINE poly    kNoetherTail();
329  poly    t_kNoether;
330  BOOLEAN * NotUsedAxis;
331  BOOLEAN * pairtest;/*used for enterOnePair*/
332  poly tail;
333  intvec * kModW;
334  intvec * kHomW;
335  // procedure for ShalloCopy from tailRing  to currRing
336  pShallowCopyDeleteProc p_shallow_copy_delete;
337  // pointers to Tobjects R[i] is ith Tobject which is generated
338  TObject**  R;
339  // S_2_R[i] yields Tobject which corresponds to S[i]
340  int*      S_2_R;
341  ring tailRing;
342  omBin lmBin;
343  omBin tailBin;
344  int nr;
345  int cp,c3;
346  int sl,mu;
347  int syzl,syzmax,syzidxmax;
348  int tl,tmax;
349  int Ll,Lmax;
350  int Bl,Bmax;
351  int ak,LazyDegree,LazyPass;
352  int syzComp;
353  int HCord;
354  int lastAxis;
355  int newIdeal;
356  int minim;
357  #ifdef HAVE_RINGS
358  bool sigdrop; //This is used to check sigdrop in sba over Z
359  int nrsyzcrit; // counts how many pairs are deleted by SyzCrit
360  int nrrewcrit; // counts how many pairs are deleted by FaugereRewCrit
361  int sbaEnterS; // sba over Z strategy: if sigdrop element has _*gen(sbaEnterS+1), then
362                 // add directly sbaEnterS elements into S
363  int blockred;  // counter for blocked reductions in redSig
364  int blockredmax;
365  #endif
366  #ifdef HAVE_SHIFTBBA
367  int cv; // in shift bases: counting V criterion
368  /*BOOLEAN*/ char rightGB;
369  #endif
370  /*BOOLEAN*/ char interpt;
371  /*BOOLEAN*/ char homog;
372#ifdef HAVE_PLURAL
373  /*BOOLEAN*/ char z2homog; // Z_2 - homogeneous input allows product criterion in commutative and SCA cases!
374#endif
375  /*BOOLEAN*/ char kHEdgeFound;
376  /*BOOLEAN*/ char honey,sugarCrit;
377  /*BOOLEAN*/ char Gebauer,noTailReduction;
378  /*BOOLEAN*/ char fromT;
379  /*BOOLEAN*/ char noetherSet;
380  /*BOOLEAN*/ char update;
381  /*BOOLEAN*/ char posInLOldFlag;
382  /*BOOLEAN*/ char use_buckets;
383  // if set, pLDeg(p, l) == (pFDeg(pLast(p), pLength)
384  /*BOOLEAN*/ char LDegLast;
385  // if set, then L.length == L.pLength
386  /*BOOLEAN*/ char length_pLength;
387  // if set, then posInL does not depend on L.length
388  /*BOOLEAN*/ char posInLDependsOnLength;
389  /*FALSE, if posInL == posInL10*/
390#ifdef HAVE_PLURAL
391  // set this flag to 1 to stop the product criteria
392  // use ALLOW_PROD_CRIT(strat) to test
393  /*BOOLEAN*/ char no_prod_crit;
394#define ALLOW_PROD_CRIT(A) (!(A)->no_prod_crit)
395#else
396#define ALLOW_PROD_CRIT(A) (1)
397#endif
398  char    redTailChange;
399  char    news;
400  char    newt;/*used for messageSets*/
401  char    noClearS;
402  char    completeReduce_retry;
403  char    overflow;
404
405  skStrategy();
406  ~skStrategy();
407
408  // return TObject corresponding to S[i]: assume that it exists
409  // i.e. no error checking is done
410  KINLINE TObject* S_2_T(int i);
411  // like S_2_T, except that NULL is returned if it can not be found
412  KINLINE TObject* s_2_t(int i);
413};
414
415void deleteHC(poly *p, int *e, int *l, kStrategy strat);
416void deleteHC(LObject* L, kStrategy strat, BOOLEAN fromNext = FALSE);
417void deleteInS (int i,kStrategy strat);
418void deleteInSSba (int i,kStrategy strat);
419void cleanT (kStrategy strat);
420static inline LSet initL (int nr=setmaxL)
421{ return (LSet)omAlloc(nr*sizeof(LObject)); }
422void deleteInL(LSet set, int *length, int j,kStrategy strat);
423void enterL (LSet *set,int *length, int *LSetmax, LObject p,int at);
424void enterSBba (LObject &p,int atS,kStrategy strat, int atR = -1);
425void enterSBbaShift (LObject &p,int atS,kStrategy strat, int atR = -1);
426void enterSSba (LObject &p,int atS,kStrategy strat, int atR = -1);
427void initEcartPairBba (LObject* Lp,poly f,poly g,int ecartF,int ecartG);
428void initEcartPairMora (LObject* Lp,poly f,poly g,int ecartF,int ecartG);
429int posInS (const kStrategy strat, const int length, const poly p,
430            const int ecart_p);
431int posInSMonFirst (const kStrategy strat, const int length, const poly p);
432int posInIdealMonFirst (const ideal F, const poly p,int start = 0,int end = -1);
433int posInT0 (const TSet set,const int length,LObject &p);
434int posInT1 (const TSet set,const int length,LObject &p);
435int posInT2 (const TSet set,const int length,LObject &p);
436int posInT11 (const TSet set,const int length,LObject &p);
437int posInTSig (const TSet set,const int length,LObject &p);
438int posInT110 (const TSet set,const int length,LObject &p);
439int posInT13 (const TSet set,const int length,LObject &p);
440int posInT15 (const TSet set,const int length,LObject &p);
441int posInT17 (const TSet set,const int length,LObject &p);
442int posInT17_c (const TSet set,const int length,LObject &p);
443int posInT19 (const TSet set,const int length,LObject &p);
444int posInT_EcartpLength(const TSet set,const int length,LObject &p);
445int posInT_EcartFDegpLength(const TSet set,const int length,LObject &p);
446int posInT_FDegpLength(const TSet set,const int length,LObject &p);
447int posInT_pLength(const TSet set,const int length,LObject &p);
448
449#ifdef HAVE_MORE_POS_IN_T
450int posInT_EcartFDegpLength(const TSet set,const int length,LObject &p);
451int posInT_FDegpLength(const TSet set,const int length,LObject &p);
452int posInT_pLength(const TSet set,const int length,LObject &p);
453#endif
454
455
456void reorderS (int* suc,kStrategy strat);
457int posInLF5C (const LSet set, const int length,
458               LObject* L,const kStrategy strat);
459int posInLSig (const LSet set, const int length,
460               LObject* L,const kStrategy strat);
461int posInLSigRing (const LSet set, const int length,
462               LObject* L,const kStrategy strat);
463int posInLRing (const LSet set, const int length,
464               LObject* L,const kStrategy strat);
465int posInSyz (const kStrategy strat, const poly sig);
466int posInL0 (const LSet set, const int length,
467             LObject* L,const kStrategy strat);
468int posInL11 (const LSet set, const int length,
469             LObject* L,const kStrategy strat);
470int posInL11Ring (const LSet set, const int length,
471             LObject* L,const kStrategy strat);
472int posInLF5CRing (const LSet set, int start , const int length,
473             LObject* L,const kStrategy strat);
474int posInL11Ringls (const LSet set, const int length,
475             LObject* L,const kStrategy strat);
476int posInL13 (const LSet set, const int length,
477             LObject* L,const kStrategy strat);
478int posInL15 (const LSet set, const int length,
479             LObject* L,const kStrategy strat);
480int posInL15Ring (const LSet set, const int length,
481             LObject* L,const kStrategy strat);
482int posInL17 (const LSet set, const int length,
483             LObject* L,const kStrategy strat);
484int posInL10 (const LSet set, const int length,
485             LObject* L,const kStrategy strat);
486int posInL10Ring (const LSet set, const int length,
487             LObject* L,const kStrategy strat);
488int posInL110 (const LSet set, const int length,
489             LObject* L,const kStrategy strat);
490KINLINE poly redtailBba (poly p,int end_pos,kStrategy strat,BOOLEAN normalize=FALSE);
491KINLINE poly redtailBbaBound (poly p,int end_pos,kStrategy strat,int bound,BOOLEAN normalize=FALSE);
492#ifdef HAVE_RINGS
493KINLINE poly redtailBba_Z (poly p,int end_pos,kStrategy strat);
494poly redtailBba_Z (LObject* L, int end_pos, kStrategy strat );
495void redtailBbaAlsoLC_Z (LObject* L, int end_pos, kStrategy strat );
496#endif
497poly redtailBba (LObject *L, int end_pos,kStrategy strat,
498                 BOOLEAN withT = FALSE,BOOLEAN normalize=FALSE);
499poly redtailBbaBound (LObject *L, int end_pos,kStrategy strat,int bound,
500                 BOOLEAN withT = FALSE,BOOLEAN normalize=FALSE);
501poly redtailSba (LObject *L, int end_pos,kStrategy strat,
502                 BOOLEAN withT = FALSE,BOOLEAN normalize=FALSE);
503poly redtailBba (TObject *T, int end_pos,kStrategy strat);
504poly redtail (poly p,int end_pos,kStrategy strat);
505poly redtail (LObject *L,int end_pos,kStrategy strat);
506poly redNF (poly h,int & max_ind,int nonorm,kStrategy strat);
507int redNF0 (LObject *P,kStrategy strat);
508poly redNFTail (poly h,const int sl,kStrategy strat);
509int redHoney (LObject* h, kStrategy strat);
510#ifdef HAVE_RINGS
511int redRing (LObject* h,kStrategy strat);
512int redRing_Z (LObject* h,kStrategy strat);
513int redRiloc (LObject* h,kStrategy strat);
514void enterExtendedSpoly(poly h,kStrategy strat);
515void enterExtendedSpolySig(poly h,poly hSig,kStrategy strat);
516void superenterpairs (poly h,int k,int ecart,int pos,kStrategy strat, int atR = -1);
517void superenterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int pos,kStrategy strat, int atR = -1);
518poly kCreateZeroPoly(long exp[], long cabsind, poly* t_p, ring leadRing, ring tailRing);
519long ind2(long arg);
520
521long ind_fact_2(long arg);
522long twoPow(long arg);
523ideal createG0();
524#endif
525int redLazy (LObject* h,kStrategy strat);
526int redHomog (LObject* h,kStrategy strat);
527int redSig (LObject* h,kStrategy strat);
528int redSigRing (LObject* h,kStrategy strat);
529//adds hSig to be able to check with F5's criteria when entering pairs!
530void enterpairsSig (poly h, poly hSig, int from, int k, int ec, int pos,kStrategy strat, int atR = -1);
531void enterpairs (poly h, int k, int ec, int pos,kStrategy strat, int atR = -1);
532void entersets (LObject h);
533void pairs ();
534BOOLEAN sbaCheckGcdPair (LObject* h,kStrategy strat);
535void message (int i,int* reduc,int* olddeg,kStrategy strat,int red_result);
536void messageStat (int hilbcount,kStrategy strat);
537void messageStatSBA (int hilbcount,kStrategy strat);
538#ifdef KDEBUG
539void messageSets (kStrategy strat);
540#else
541#define messageSets(s)  do {} while (0)
542#endif
543
544void initEcartNormal (TObject* h);
545void initEcartBBA (TObject* h);
546void initS (ideal F, ideal Q,kStrategy strat);
547void initSL (ideal F, ideal Q,kStrategy strat);
548void initSLSba (ideal F, ideal Q,kStrategy strat);
549/*************************************************
550 * when initializing a new bunch of principal
551 * syzygies at the beginning of a new iteration
552 * step in a signature-based algorithm we
553 * compute ONLY the leading elements of those
554 * syzygies, NOT the whole syzygy
555 * NOTE: this needs to be adjusted for a more
556 * general approach on signature-based algorithms
557 ***********************************************/
558void initSyzRules (kStrategy strat);
559void updateS(BOOLEAN toT,kStrategy strat);
560void enterSyz (LObject &p,kStrategy strat, int atT);
561void enterT (LObject &p,kStrategy strat, int atT = -1);
562void replaceInLAndSAndT(LObject &p, int tj, kStrategy strat);
563#ifdef HAVE_RINGS
564void enterT_strong (LObject &p,kStrategy strat, int atT = -1);
565#endif
566void cancelunit (LObject* p,BOOLEAN inNF=FALSE);
567void HEckeTest (poly pp,kStrategy strat);
568void initBuchMoraCrit(kStrategy strat);
569void initSbaCrit(kStrategy strat);
570void initHilbCrit(ideal F, ideal Q, intvec **hilb,kStrategy strat);
571void initBuchMoraPos(kStrategy strat);
572void initBuchMoraPosRing(kStrategy strat);
573void initSbaPos(kStrategy strat);
574void initBuchMora (ideal F, ideal Q,kStrategy strat);
575void initSbaBuchMora (ideal F, ideal Q,kStrategy strat);
576void exitBuchMora (kStrategy strat);
577void exitSba (kStrategy strat);
578void updateResult(ideal r,ideal Q,kStrategy strat);
579void completeReduce (kStrategy strat, BOOLEAN withT=FALSE);
580void kFreeStrat(kStrategy strat);
581void enterOnePairNormal (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR);
582void chainCritNormal (poly p,int ecart,kStrategy strat);
583void chainCritOpt_1 (poly,int,kStrategy strat);
584void chainCritSig (poly p,int ecart,kStrategy strat);
585BOOLEAN homogTest(polyset F, int Fmax);
586BOOLEAN newHEdge(kStrategy strat);
587BOOLEAN syzCriterion(poly sig, unsigned long not_sevSig, kStrategy strat);
588BOOLEAN syzCriterionInc(poly sig, unsigned long not_sevSig, kStrategy strat);
589KINLINE BOOLEAN arriRewDummy(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start);
590BOOLEAN arriRewCriterion(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start);
591BOOLEAN arriRewCriterionPre(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start);
592BOOLEAN faugereRewCriterion(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start);
593BOOLEAN findMinLMPair(poly sig, unsigned long not_sevSig, kStrategy strat, int start);
594
595/// returns index of p in TSet, or -1 if not found
596int kFindInT(poly p, TSet T, int tlength);
597#ifdef HAVE_SHIFTBBA
598int kFindInTShift(poly p, TSet T, int tlength);
599#endif
600
601/// return -1 if no divisor is found
602///        number of first divisor in T, otherwise
603int kFindDivisibleByInT(const kStrategy strat, const LObject* L, const int start=0);
604int kFindDivisibleByInT_Z(const kStrategy strat, const LObject* L, const int start=0);
605int kFindSameLMInT_Z(const kStrategy strat, const LObject* L, const int start=0);
606
607/// tests if T[0] divides the leading monomial of L, returns -1 if not
608int kTestDivisibleByT0_Z(const kStrategy strat, const LObject* L);
609/// return -1 if no divisor is found
610///        number of first divisor in S, otherwise
611int kFindDivisibleByInS(const kStrategy strat, int *max_ind, LObject* L);
612
613int kFindNextDivisibleByInS(const kStrategy strat, int start,int max_ind, LObject* L);
614TObject* kFindDivisibleByInS_T(kStrategy strat, int end_pos, LObject* L, TObject *T, long ecart = LONG_MAX);
615
616/***************************************************************
617 *
618 * stuff to be inlined
619 *
620 ***************************************************************/
621
622KINLINE TSet initT ();
623KINLINE TObject** initR();
624KINLINE unsigned long* initsevT();
625KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing, omBin bin);
626KINLINE poly k_LmInit_tailRing_2_currRing(poly p, ring tailRing, omBin bin);
627KINLINE poly k_LmShallowCopyDelete_currRing_2_tailRing(poly p, ring tailRing, omBin bin);
628KINLINE poly k_LmShallowCopyDelete_tailRing_2_currRing(poly p, ring tailRing,  omBin bin);
629
630KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing);
631KINLINE poly k_LmInit_tailRing_2_currRing(poly p, ring tailRing);
632KINLINE poly k_LmShallowCopyDelete_currRing_2_tailRing(poly p, ring tailRing);
633KINLINE poly k_LmShallowCopyDelete_tailRing_2_currRing(poly p, ring tailRing);
634
635// if exp bound is not violated, return TRUE and
636//                               get m1 = LCM(LM(p1), LM(p2))/LM(p1)
637//                                   m2 = LCM(LM(p1), LM(p2))/LM(p2)
638// return FALSE and m1 == NULL, m2 == NULL     , otherwise
639KINLINE BOOLEAN k_GetLeadTerms(const poly p1, const poly p2, const ring p_r,
640                               poly &m1, poly &m2, const ring m_r);
641#ifdef HAVE_RINGS
642KINLINE void k_GetStrongLeadTerms(const poly p1, const poly p2, const ring leadRing,
643                               poly &m1, poly &m2, poly &lcm, const ring taiRing);
644#endif
645#ifdef KDEBUG
646// test strat
647BOOLEAN kTest(kStrategy strat);
648// test strat, and test that S is contained in T
649BOOLEAN kTest_TS(kStrategy strat);
650// test LObject
651BOOLEAN kTest_L(LObject* L, ring tailRing,
652                 BOOLEAN testp = FALSE, int lpos = -1,
653                 TSet T = NULL, int tlength = -1);
654// test TObject
655BOOLEAN kTest_T(TObject* T, ring tailRing = NULL, int tpos = -1, char TN = '?');
656// test set strat->SevS
657BOOLEAN kTest_S(kStrategy strat);
658#else
659#define kTest(A)        (TRUE)
660#define kTest_TS(A)     (TRUE)
661#define kTest_T(T)      (TRUE)
662#define kTest_S(T)      (TRUE)
663#define kTest_L(T,R)    (TRUE)
664#endif
665
666
667/***************************************************************
668 *
669 * From kstd2.cc
670 *
671 ***************************************************************/
672poly kFindZeroPoly(poly input_p, ring leadRing, ring tailRing);
673ideal bba (ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat);
674ideal sba (ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat);
675poly kNF2 (ideal F, ideal Q, poly q, kStrategy strat, int lazyReduce);
676ideal kNF2 (ideal F,ideal Q,ideal q, kStrategy strat, int lazyReduce);
677poly kNF2Bound (ideal F, ideal Q, poly q,int bound, kStrategy strat, int lazyReduce);
678ideal kNF2Bound (ideal F,ideal Q,ideal q,int bound, kStrategy strat, int lazyReduce);
679void initBba(kStrategy strat);
680void initSba(ideal F,kStrategy strat);
681void f5c (kStrategy strat, int& olddeg, int& minimcnt, int& hilbeledeg,
682          int& hilbcount, int& srmax, int& lrmax, int& reduc, ideal Q,
683          intvec *w,intvec *hilb );
684
685/***************************************************************
686 *
687 * From kspoly.cc
688 *
689 ***************************************************************/
690// Reduces PR with PW
691// Assumes PR != NULL, PW != NULL, Lm(PW) divides Lm(PR)
692// Changes: PR
693// Const:   PW
694// If coef != NULL, then *coef is a/gcd(a,b), where a = LC(PR), b = LC(PW)
695// If strat != NULL, tailRing is changed if reduction would violate exp bound
696// of tailRing
697// Returns: 0 everything ok, no tailRing change
698//          1 tailRing has successfully changed (strat != NULL)
699//          2 no reduction performed, tailRing needs to be changed first
700//            (strat == NULL)
701//         -1 tailRing change could not be performed due to exceeding exp
702//            bound of currRing
703int ksReducePoly(LObject* PR,
704                 TObject* PW,
705                 poly spNoether = NULL,
706                 number *coef = NULL,
707                 kStrategy strat = NULL);
708
709/* like ksReducePoly, but if the reducer has only 1 term we still
710 * compute a possible coefficient multiplier for PR. this comes from
711 * a special situation in redRing_Z and it is used only there. */
712int ksReducePolyZ(LObject* PR,
713                 TObject* PW,
714                 poly spNoether = NULL,
715                 number *coef = NULL,
716                 kStrategy strat = NULL);
717
718int ksReducePolyLC(LObject* PR,
719                 TObject* PW,
720                 poly spNoether = NULL,
721                 number *coef = NULL,
722                 kStrategy strat = NULL);
723
724
725int ksReducePolyGCD(LObject* PR,
726                 TObject* PW,
727                 poly spNoether = NULL,
728                 number *coef = NULL,
729                 kStrategy strat = NULL);
730
731int ksReducePolyBound(LObject* PR,
732                 TObject* PW,
733                 int bound,
734                 poly spNoether = NULL,
735                 number *coef = NULL,
736                 kStrategy strat = NULL);
737
738// Reduces PR with PW
739// Assumes PR != NULL, PW != NULL, Lm(PW) divides Lm(PR)
740// Changes: PR
741// Const:   PW
742// If coef != NULL, then *coef is a/gcd(a,b), where a = LC(PR), b = LC(PW)
743// If strat != NULL, tailRing is changed if reduction would violate exp bound
744// of tailRing
745// Returns: 0 everything ok, no tailRing change
746//          1 tailRing has successfully changed (strat != NULL)
747//          2 no reduction performed, tailRing needs to be changed first
748//            (strat == NULL)
749//          3 no reduction performed, not sig-safe!!!
750//         -1 tailRing change could not be performed due to exceeding exp
751//            bound of currRing
752int ksReducePolySig(LObject* PR,
753                 TObject* PW,
754                 long idx,
755                 poly spNoether = NULL,
756                 number *coef = NULL,
757                 kStrategy strat = NULL);
758
759int ksReducePolySigRing(LObject* PR,
760                 TObject* PW,
761                 long idx,
762                 poly spNoether = NULL,
763                 number *coef = NULL,
764                 kStrategy strat = NULL);
765
766// Reduces PR at Current->next with PW
767// Assumes PR != NULL, Current contained in PR
768//         Current->next != NULL, LM(PW) devides LM(Current->next)
769// Changes: PR
770// Const:   PW
771// Return: see ksReducePoly
772int ksReducePolyTail(LObject* PR,
773                     TObject* PW,
774                     poly Current,
775                     poly spNoether = NULL);
776
777KINLINE int ksReducePolyTail(LObject* PR, TObject* PW, LObject* Red);
778
779// Creates S-Poly of Pair
780// Const:   Pair->p1, Pair->p2
781// Changes: Pair->p == S-Poly of p1, p2
782// Assume:  Pair->p1 != NULL && Pair->p2
783void ksCreateSpoly(LObject* Pair, poly spNoether = NULL,
784                   int use_buckets=0, ring tailRing=currRing,
785                   poly m1 = NULL, poly m2 = NULL, TObject** R = NULL);
786
787/*2
788* creates the leading term of the S-polynomial of p1 and p2
789* do not destroy p1 and p2
790* remarks:
791*   1. the coefficient is 0 (nNew)
792*   2. pNext is undefined
793*/
794poly ksCreateShortSpoly(poly p1, poly p2, ring tailRing);
795
796
797// old stuff
798KINLINE poly ksOldSpolyRed(poly p1, poly p2, poly spNoether = NULL);
799KINLINE poly ksOldSpolyRedNew(poly p1, poly p2, poly spNoether = NULL);
800KINLINE poly ksOldCreateSpoly(poly p1, poly p2, poly spNoether = NULL, ring r = currRing);
801KINLINE void ksOldSpolyTail(poly p1, poly q, poly q2, poly spNoether, ring r = currRing);
802
803/***************************************************************
804 *
805 * Routines related for ring changes during std computations
806 *
807 ***************************************************************/
808// return TRUE and set m1, m2 to k_GetLcmTerms,
809//             if spoly creation of strat->P does not violate
810//             exponent bound of strat->tailRing
811//      FALSE, otherwise
812BOOLEAN kCheckSpolyCreation(LObject* L, kStrategy strat, poly &m1, poly &m2);
813#ifdef HAVE_RINGS
814// return TRUE if gcdpoly creation of R[atR] and S[atS] does not violate
815//             exponent bound of strat->tailRing
816//      FALSE, otherwise
817BOOLEAN kCheckStrongCreation(int atR, poly m1, int atS, poly m2, kStrategy strat);
818poly preIntegerCheck(ideal F, ideal Q);
819void postReduceByMon(LObject* h, kStrategy strat);
820void postReduceByMonSig(LObject* h, kStrategy strat);
821void finalReduceByMon(kStrategy strat);
822#endif
823// change strat->tailRing and adjust all data in strat, L, and T:
824// new tailRing has larger exponent bound
825// do nothing and return FALSE if exponent bound increase would result in
826// larger exponent bound that that of currRing
827BOOLEAN kStratChangeTailRing(kStrategy strat,
828                             LObject* L = NULL, TObject* T = NULL,
829                             // take this as new_expbound: if 0
830                             // new expbound is 2*expbound of tailRing
831                             unsigned long new_expbound = 0);
832// initiate a change of the tailRing of strat -- should be called
833// right before main loop in bba
834void kStratInitChangeTailRing(kStrategy strat);
835
836/// Output some debug info about a given strategy
837void kDebugPrint(kStrategy strat);
838
839// getting sb order for sba computations
840ring sbaRing(kStrategy strat, const ring r=currRing, BOOLEAN complete=TRUE, int sgn=1);
841
842KINLINE void clearS (poly p, unsigned long p_sev, int* at, int* k,
843  kStrategy strat);
844
845#include "kernel/GBEngine/kInline.h"
846
847/* shiftgb stuff */
848#include "kernel/GBEngine/shiftgb.h"
849
850poly pMove2CurrTail(poly p, kStrategy strat);
851
852poly pMoveCurrTail2poly(poly p, kStrategy strat);
853
854poly pCopyL2p(LObject h, kStrategy strat);
855
856void enterTShift(LObject p, kStrategy strat, int atT = -1);
857
858void enterOnePairShift (poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS);
859
860void enterpairsShift (poly h,int k,int ecart,int pos,kStrategy strat, int atR);
861
862void superenterpairsShift (poly h,int k,int ecart,int pos,kStrategy strat, int atR);
863
864poly redtailBbaShift (LObject* L, int pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize);
865
866int redFirstShift (LObject* h,kStrategy strat); // ok
867
868ideal bbaShift(ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat);
869// test syz strategy: // will be removed soon
870EXTERN_VAR int (*test_PosInT)(const TSet T,const int tl,LObject &h);
871EXTERN_VAR int (*test_PosInL)(const LSet set, const int length,
872                LObject* L,const kStrategy strat);
873
874static inline void kDeleteLcm(LObject *P)
875{
876 if (P->lcm!=NULL)
877 {
878 #ifdef HAVE_RINGS
879   if (rField_is_Ring(currRing))
880     pLmDelete(P->lcm);
881   else
882 #endif
883     pLmFree(P->lcm);
884   P->lcm=NULL;
885 }
886}
887#endif
Note: See TracBrowser for help on using the repository browser.