source: git/Singular/kutil.h @ bef194

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