source: git/kernel/kutil.h @ b130fb

spielwiese
Last change on this file since b130fb was b130fb, checked in by Hans Schönemann <hannes@…>, 19 years ago
*hannes: gcc-3.4 git-svn-id: file:///usr/local/Singular/svn/trunk@7733 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 18.7 KB
Line 
1#ifndef KUTIL_H
2#define KUTIL_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/* $Id: kutil.h,v 1.3 2005-02-17 09:42:21 Singular Exp $ */
7/*
8* ABSTRACT: kernel: utils for kStd
9*/
10
11
12#include <string.h>
13#include "mod2.h"
14#include <mylimits.h>
15
16#include "structs.h"
17#include "omalloc.h"
18#include "ring.h"
19#include "structs.h"
20#include "pShallowCopyDelete.h"
21
22#if 1
23#define setmax 16
24#define setmaxL 56
25#define setmaxLinc 32
26#define setmaxT 64
27#define setmaxTinc 32
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
58typedef int* intset;
59typedef class sTObject TObject;
60typedef class sLObject LObject;
61typedef TObject * TSet;
62typedef LObject * LSet;
63
64class sTObject
65{
66public:
67  poly p;       // Lm(p) \in currRing Tail(p) \in tailRing
68  poly t_p;     // t_p \in tailRing: as monomials Lm(t_p) == Lm(p)
69  ring tailRing;
70  poly max;     // p_GetMaxExpP(pNext(p))
71  long FDeg;    // pFDeg(p)
72  int ecart,
73    length,     // as of pLDeg
74    pLength,    // either == 0, or == pLength(p)
75    i_r;        // index of TObject in R set, or -1 if not in T
76  BOOLEAN is_normalized; // true, if pNorm was called on p, false otherwise
77
78  // initialization
79  KINLINE void Init(ring r = currRing);
80  KINLINE sTObject(ring tailRing = currRing);
81  KINLINE sTObject(poly p, ring tailRing = currRing);
82  KINLINE sTObject(poly p, ring c_r, ring tailRing);
83  KINLINE sTObject(sTObject* T, int copy);
84
85  KINLINE void Set(ring r=currRing);
86  KINLINE void Set(poly p_in, ring r=currRing);
87  KINLINE void Set(poly p_in, ring c_r, ring t_r);
88
89  // Frees the polys of T
90  KINLINE void Delete();
91  // Sets polys to NULL
92  KINLINE void Clear();
93  // makes a copy of the poly of T
94  KINLINE void Copy();
95
96  // ring-dependent Lm access: these might result in allocation of monomials
97  KINLINE poly GetLmCurrRing();
98  KINLINE poly GetLmTailRing();
99  KINLINE poly GetLm(ring r);
100  // this returns Lm and ring r (preferably from tailRing), but does not
101  // allocate a new poly
102  KINLINE void GetLm(poly &p, ring &r) const;
103  KINLINE BOOLEAN IsNull() const;
104
105  KINLINE int GetpLength();
106
107  // makes sure that T.p exists
108  KINLINE void SetLmCurrRing();
109
110  // Iterations
111  // simply get the next monomial
112  KINLINE poly Next();
113  KINLINE void LmDeleteAndIter();
114
115  // deg stuff
116  // computes pFDeg
117  KINLINE long pFDeg() const;
118  // computes and sets FDeg
119  KINLINE long SetpFDeg();
120  // gets stored FDeg
121  KINLINE long GetpFDeg() const;
122
123  // computes pLDeg
124  KINLINE long pLDeg();
125  // sets length, FDeg, returns LDeg
126  KINLINE long SetDegStuffReturnLDeg();
127
128  // arithmetic
129  KINLINE void Mult_nn(number n);
130  KINLINE void ShallowCopyDelete(ring new_tailRing, omBin new_tailBin,
131                                 pShallowCopyDeleteProc p_shallow_copy_delete,
132                                 BOOLEAN set_max = TRUE);
133  // manipulations
134  KINLINE void pNorm();
135  KINLINE void pCleardenom();
136
137#ifdef KDEBUG
138  void wrp();
139#endif
140};
141
142class sLObject : public sTObject
143{
144
145public:
146  unsigned long sev;
147  poly  p1,p2; /*- the pair p comes from -*/
148
149  poly  lcm;   /*- the lcm of p1,p2 -*/
150  poly last;   // pLast(p) during reductions
151  kBucket_pt bucket;
152  int   i_r1, i_r2;
153
154  // initialization
155  KINLINE void Init(ring tailRing = currRing);
156  KINLINE sLObject(ring tailRing = currRing);
157  KINLINE sLObject(poly p, ring tailRing = currRing);
158  KINLINE sLObject(poly p, ring c_r, ring tailRing);
159
160  // Frees the polys of L
161  KINLINE void Delete();
162  KINLINE void Clear();
163
164  // Iterations
165  KINLINE void LmDeleteAndIter();
166  KINLINE poly LmExtractAndIter();
167
168  // spoly related things
169  // preparation for reduction if not spoly
170  KINLINE void PrepareRed(BOOLEAN use_bucket);
171  KINLINE void SetLmTail(poly lm, poly new_p, int length,
172                         int use_bucket, ring r, poly last);
173  KINLINE void Tail_Minus_mm_Mult_qq(poly m, poly qq, int lq, poly spNoether);
174  KINLINE void Tail_Mult_nn(number n);
175  // deletes bucket, makes sure that p and t_p exists
176  KINLINE poly GetP(omBin lmBin = NULL);
177  // similar, except that only t_p exists
178  KINLINE poly GetTP();
179
180  // does not delete bucket, just canonicalizes it
181  // returned poly is such that Lm(p) \in currRing, Tail(p) \in tailRing
182  KINLINE poly CanonicalizeP();
183
184  // makes a copy of the poly of L
185  KINLINE void Copy();
186  // gets the poly and makes a copy of it
187  KINLINE poly CopyGetP();
188
189  KINLINE int GetpLength();
190  KINLINE long pLDeg(BOOLEAN use_last);
191  KINLINE long pLDeg();
192  KINLINE int SetLength(BOOLEAN lengt_pLength = FALSE);
193  KINLINE long SetDegStuffReturnLDeg();
194  KINLINE long SetDegStuffReturnLDeg(BOOLEAN use_last);
195
196  // returns minimal component of p
197  KINLINE long MinComp();
198  // returns component of p
199  KINLINE long Comp();
200
201  KINLINE void ShallowCopyDelete(ring new_tailRing,
202                                 pShallowCopyDeleteProc p_shallow_copy_delete);
203
204  // sets sev
205  KINLINE void SetShortExpVector();
206
207  // enable assignment from TObject
208  KINLINE sLObject& operator=(const sTObject&);
209
210  // get T's corresponding to p1, p2: they might return NULL
211  KINLINE TObject* T_1(const skStrategy* strat);
212  KINLINE TObject* T_2(const skStrategy* strat);
213  KINLINE void     T_1_2(const skStrategy* strat,
214                         TObject* &T_1, TObject* &T_2);
215
216  // simplify coefficients
217  KINLINE void Normalize();
218  KINLINE void HeadNormalize();
219};
220
221
222extern int HCord;
223
224class skStrategy;
225typedef skStrategy * kStrategy;
226class skStrategy
227{
228public:
229  kStrategy next;
230  int (*red)(LObject * L,kStrategy strat);
231  void (*initEcart)(LObject * L);
232  int (*posInT)(const TSet T,const int tl,LObject &h);
233  int (*posInL)(const LSet set, const int length,
234                LObject* L,const kStrategy strat);
235  void (*enterS)(LObject h, int pos,kStrategy strat, int atR/* =-1*/ );
236  void (*initEcartPair)(LObject * h, poly f, poly g, int ecartF, int ecartG);
237  int (*posInLOld)(const LSet Ls,const int Ll,
238                   LObject* Lo,const kStrategy strat);
239  pFDegProc pOrigFDeg;
240  pLDegProc pOrigLDeg;
241  pFDegProc pOrigFDeg_TailRing;
242  pLDegProc pOrigLDeg_TailRing;
243
244  LObject P;
245  ideal Shdl;
246  ideal D; /*V(S) is in D(D)*/
247  ideal M; /*set of minimal generators*/
248  polyset S;
249  intset ecartS;
250  intset lenS;
251  intset lenSw; /* for tgb.ccc */
252  intset fromQ;
253  unsigned long* sevS;
254  unsigned long* sevT;
255  TSet T;
256  LSet L;
257  LSet    B;
258  poly    kHEdge;
259  poly    kNoether;
260  poly    t_kHEdge; // same polys in tailring
261  KINLINE poly    kNoetherTail();
262  poly    t_kNoether;
263  BOOLEAN * NotUsedAxis;
264  poly tail;
265  leftv kIdeal;
266  intvec * kModW;
267  intvec * kHomW;
268  // procedure for ShalloCopy from tailRing  to currRing
269  pShallowCopyDeleteProc p_shallow_copy_delete;
270  // pointers to Tobjects R[i] is ith Tobject which is generated
271  TObject**  R;
272  // S_2_R[i] yields Tobject which corresponds to S[i]
273  int*      S_2_R;
274  ring tailRing;
275  omBin lmBin;
276  omBin tailBin;
277  int cp,c3;
278  int sl,mu;
279  int tl,tmax;
280  int Ll,Lmax;
281  int Bl,Bmax;
282  int ak,LazyDegree,LazyPass;
283  int syzComp;
284  int HCord;
285  int lastAxis;
286  int newIdeal;
287  int minim;
288  BOOLEAN interpt;
289  BOOLEAN homog;
290  BOOLEAN kHEdgeFound;
291  BOOLEAN honey,sugarCrit;
292  BOOLEAN Gebauer,noTailReduction;
293  BOOLEAN fromT;
294  BOOLEAN noetherSet;
295  BOOLEAN update;
296  BOOLEAN posInLOldFlag;
297  BOOLEAN use_buckets;
298  BOOLEAN interred_flag;
299  BOOLEAN *pairtest;/*used for enterOnePair*/
300  // if set, pLDeg(p, l) == (pFDeg(pLast(p), pLength)
301  BOOLEAN LDegLast;
302  // if set, then L.length == L.pLength
303  BOOLEAN length_pLength;
304  // if set, then posInL does not depend on L.length
305  BOOLEAN posInLDependsOnLength;
306  /*FALSE, if posInL == posInL10*/
307  char    redTailChange;
308  char    news;
309  char    newt;/*used for messageSets*/
310
311  skStrategy();
312  ~skStrategy();
313
314  // return TObject corresponding to S[i]: assume that it exists
315  // i.e. no error checking is done
316  KINLINE TObject* S_2_T(int i);
317  // like S_2_T, except that NULL is returned if it can not be found
318  KINLINE TObject* s_2_t(int i);
319};
320
321void deleteHC(poly *p, int *e, int *l, kStrategy strat);
322void deleteHC(LObject* L, kStrategy strat, BOOLEAN fromNext = FALSE);
323void deleteInS (int i,kStrategy strat);
324void cleanT (kStrategy strat);
325LSet initL ();
326void deleteInL(LSet set, int *length, int j,kStrategy strat);
327void enterL (LSet *set,int *length, int *LSetmax, LObject p,int at);
328void enterSBba (LObject p,int atS,kStrategy strat, int atR = -1);
329void initEcartPairBba (LObject* Lp,poly f,poly g,int ecartF,int ecartG);
330void initEcartPairMora (LObject* Lp,poly f,poly g,int ecartF,int ecartG);
331int posInS (kStrategy strat,int length,poly p, int ecart_p);
332int posInT0 (const TSet set,const int length,LObject &p);
333int posInT1 (const TSet set,const int length,LObject &p);
334int posInT2 (const TSet set,const int length,LObject &p);
335int posInT11 (const TSet set,const int length,LObject &p);
336int posInT110 (const TSet set,const int length,LObject &p);
337int posInT13 (const TSet set,const int length,LObject &p);
338int posInT15 (const TSet set,const int length,LObject &p);
339int posInT17 (const TSet set,const int length,LObject &p);
340int posInT19 (const TSet set,const int length,LObject &p);
341int posInT_EcartpLength(const TSet set,const int length,LObject &p);
342
343#ifdef HAVE_MORE_POS_IN_T
344int posInT_EcartFDegpLength(const TSet set,const int length,LObject &p);
345int posInT_FDegpLength(const TSet set,const int length,LObject &p);
346int posInT_pLength(const TSet set,const int length,LObject &p);
347#endif
348
349
350void reorderS (int* suc,kStrategy strat);
351int posInL0 (const LSet set, const int length,
352             LObject* L,const kStrategy strat);
353int posInL11 (const LSet set, const int length,
354             LObject* L,const kStrategy strat);
355int posInL13 (const LSet set, const int length,
356             LObject* L,const kStrategy strat);
357int posInL15 (const LSet set, const int length,
358             LObject* L,const kStrategy strat);
359int posInL17 (const LSet set, const int length,
360             LObject* L,const kStrategy strat);
361int posInL10 (const LSet set, const int length,
362             LObject* L,const kStrategy strat);
363KINLINE poly redtailBba (poly p,int pos,kStrategy strat);
364poly redtailBba (LObject *L, int pos,kStrategy strat, BOOLEAN withT = FALSE);
365poly redtailBba (TObject *T, int pos,kStrategy strat, BOOLEAN withT = FALSE);
366poly redtail (poly p,int pos,kStrategy strat);
367poly redtail (LObject *L,int pos,kStrategy strat);
368poly redNF (poly h,kStrategy strat);
369int redNF0 (LObject *P,kStrategy strat);
370poly redNFTail (poly h,const int sl,kStrategy strat);
371int redHoney (LObject* h, kStrategy strat);
372int redLazy (LObject* h,kStrategy strat);
373int redHomog (LObject* h,kStrategy strat);
374void enterpairs (poly h, int k, int ec, int pos,kStrategy strat, int atR = -1);
375void entersets (LObject h);
376void pairs ();
377void message (int i,int* reduc,int* olddeg,kStrategy strat,int red_result);
378void messageStat (int srmax,int lrmax,int hilbcount,kStrategy strat);
379#ifdef KDEBUG
380void messageSets (kStrategy strat);
381#else
382#define messageSets(s)  ((void) 0)
383#endif
384
385void initEcartNormal (LObject* h);
386void initEcartBBA (LObject* h);
387void initS (ideal F, ideal Q,kStrategy strat);
388void initSL (ideal F, ideal Q,kStrategy strat);
389void updateS(BOOLEAN toT,kStrategy strat);
390void enterT (LObject p,kStrategy strat, int atT = -1);
391void cancelunit (LObject* p);
392void HEckeTest (poly pp,kStrategy strat);
393void initBuchMoraCrit(kStrategy strat);
394void initHilbCrit(ideal F, ideal Q, intvec **hilb,kStrategy strat);
395void initBuchMoraPos(kStrategy strat);
396void initBuchMora (ideal F, ideal Q,kStrategy strat);
397void exitBuchMora (kStrategy strat);
398void updateResult(ideal r,ideal Q,kStrategy strat);
399void completeReduce (kStrategy strat);
400void kFreeStrat(kStrategy strat);
401BOOLEAN homogTest(polyset F, int Fmax);
402BOOLEAN newHEdge(polyset S, kStrategy strat);
403// returns index of p in TSet, or -1 if not found
404int kFindInT(poly p, TSet T, int tlength);
405
406// return -1 if no divisor is found
407//        number of first divisor, otherwise
408int kFindDivisibleByInT(const TSet &T, const unsigned long* sevT,
409                        const int tl, const LObject* L, const int start=0);
410// same with S
411int kFindDivisibleByInS(const polyset &S, const unsigned long* sev,
412                        const int sl, LObject* L);
413
414TObject*
415kFindDivisibleByInS(kStrategy strat, int pos, LObject* L, TObject *T,
416                    long ecart = LONG_MAX);
417
418
419/***************************************************************
420 *
421 * stuff to be inlined
422 *
423 ***************************************************************/
424
425KINLINE TSet initT ();
426KINLINE TObject** initR();
427KINLINE unsigned long* initsevT();
428KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing, omBin bin);
429KINLINE poly k_LmInit_tailRing_2_currRing(poly p, ring tailRing, omBin bin);
430KINLINE poly k_LmShallowCopyDelete_currRing_2_tailRing(poly p, ring tailRing, omBin bin);
431KINLINE poly k_LmShallowCopyDelete_tailRing_2_currRing(poly p, ring tailRing,  omBin bin);
432
433KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing);
434KINLINE poly k_LmInit_tailRing_2_currRing(poly p, ring tailRing);
435KINLINE poly k_LmShallowCopyDelete_currRing_2_tailRing(poly p, ring tailRing);
436KINLINE poly k_LmShallowCopyDelete_tailRing_2_currRing(poly p, ring tailRing);
437
438// if exp bound is not violated, return TRUE and
439//                               get m1 = LCM(LM(p1), LM(p2))/LM(p1)
440//                                   m2 = LCM(LM(p1), LM(p2))/LM(p2)
441// return FALSE and m1 == NULL, m2 == NULL     , otherwise
442KINLINE BOOLEAN k_GetLeadTerms(const poly p1, const poly p2, const ring p_r,
443                               poly &m1, poly &m2, const ring m_r);
444#ifdef KDEBUG
445// test strat
446BOOLEAN kTest(kStrategy strat);
447// test strat, and test that S is contained in T
448BOOLEAN kTest_TS(kStrategy strat);
449// test LObject
450BOOLEAN kTest_L(LObject* L, ring tailRing = NULL,
451                 BOOLEAN testp = FALSE, int lpos = -1,
452                 TSet T = NULL, int tlength = -1);
453// test TObject
454BOOLEAN kTest_T(TObject* T, ring tailRing = NULL, int tpos = -1, char TN = '?');
455// test set strat->SevS
456BOOLEAN kTest_S(kStrategy strat);
457#else
458#define kTest(A)        ((void)0)
459#define kTest_TS(A)     ((void)0)
460#define kTest_T(T)      ((void)0)
461#define kTest_S(T)      ((void)0)
462#define kTest_L(T)      ((void)0)
463#endif
464
465
466/***************************************************************
467 *
468 * From kstd2.cc
469 *
470 ***************************************************************/
471ideal bba (ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat);
472poly kNF2 (ideal F, ideal Q, poly q, kStrategy strat, int lazyReduce);
473ideal kNF2 (ideal F,ideal Q,ideal q, kStrategy strat, int lazyReduce);
474void initBba(ideal F,kStrategy strat);
475
476/***************************************************************
477 *
478 * From kSpolys.cc
479 *
480 ***************************************************************/
481// Reduces PR with PW
482// Assumes PR != NULL, PW != NULL, Lm(PW) divides Lm(PR)
483// Changes: PR
484// Const:   PW
485// If coef != NULL, then *coef is a/gcd(a,b), where a = LC(PR), b = LC(PW)
486// If strat != NULL, tailRing is changed if reduction would violate exp bound
487// of tailRing
488// Returns: 0 everything ok, no tailRing change
489//          1 tailRing has successfully changed (strat != NULL)
490//          2 no reduction performed, tailRing needs to be changed first
491//            (strat == NULL)
492//         -1 tailRing change could not be performed due to exceeding exp
493//            bound of currRing
494int ksReducePoly(LObject* PR,
495                 TObject* PW,
496                 poly spNoether = NULL,
497                 number *coef = NULL,
498                 kStrategy strat = NULL);
499
500// Reduces PR at Current->next with PW
501// Assumes PR != NULL, Current contained in PR
502//         Current->next != NULL, LM(PW) devides LM(Current->next)
503// Changes: PR
504// Const:   PW
505// Return: see ksReducePoly
506int ksReducePolyTail(LObject* PR,
507                     TObject* PW,
508                     poly Current,
509                     poly spNoether = NULL);
510
511KINLINE int ksReducePolyTail(LObject* PR, TObject* PW, LObject* Red);
512
513// Creates S-Poly of Pair
514// Const:   Pair->p1, Pair->p2
515// Changes: Pair->p == S-Poly of p1, p2
516// Assume:  Pair->p1 != NULL && Pair->p2
517void ksCreateSpoly(LObject* Pair, poly spNoether = NULL,
518                   int use_buckets=0, ring tailRing=currRing,
519                   poly m1 = NULL, poly m2 = NULL, TObject** R = NULL);
520
521/*2
522* creates the leading term of the S-polynomial of p1 and p2
523* do not destroy p1 and p2
524* remarks:
525*   1. the coefficient is 0 (nNew)
526*   2. pNext is undefined
527*/
528poly ksCreateShortSpoly(poly p1, poly p2, ring tailRing);
529
530
531/*
532* input - output: a, b
533* returns:
534*   a := a/gcd(a,b), b := b/gcd(a,b)
535*   and return value
536*       0  ->  a != 1,  b != 1
537*       1  ->  a == 1,  b != 1
538*       2  ->  a != 1,  b == 1
539*       3  ->  a == 1,  b == 1
540*   this value is used to control the spolys
541*/
542int ksCheckCoeff(number *a, number *b);
543
544// old stuff
545KINLINE poly ksOldSpolyRed(poly p1, poly p2, poly spNoether = NULL);
546KINLINE poly ksOldSpolyRedNew(poly p1, poly p2, poly spNoether = NULL);
547KINLINE poly ksOldCreateSpoly(poly p1, poly p2, poly spNoether = NULL, ring r = currRing);
548KINLINE void ksOldSpolyTail(poly p1, poly q, poly q2, poly spNoether, ring r = currRing);
549
550/***************************************************************
551 *
552 * Routines related for ring changes during std computations
553 *
554 ***************************************************************/
555// return TRUE and set m1, m2 to k_GetLcmTerms,
556//             if spoly creation of strat->P does not violate
557//             exponent bound of strat->tailRing
558//      FALSE, otherwise
559BOOLEAN kCheckSpolyCreation(LObject* L, kStrategy strat, poly &m1, poly &m2);
560// change strat->tailRing and adjust all data in strat, L, and T:
561// new tailRing has larger exponent bound
562// do nothing and return FALSE if exponent bound increase would result in
563// larger exponent bound that that of currRing
564BOOLEAN kStratChangeTailRing(kStrategy strat,
565                             LObject* L = NULL, TObject* T = NULL,
566                             // take this as new_expbound: if 0
567                             // new expbound is 2*expbound of tailRing
568                             unsigned long new_expbound = 0);
569// initiate a change of the tailRing of strat -- should be called
570// right before main loop in bba
571void kStratInitChangeTailRing(kStrategy strat);
572
573#include "kInline.cc"
574
575
576#endif
Note: See TracBrowser for help on using the repository browser.