source: git/kernel/GBEngine/kutil.h @ 9017bae

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