source: git/Singular/kutil.h @ 32f320

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