source: git/Singular/kutil.h @ 584f84d

spielwiese
Last change on this file since 584f84d was 19df79, checked in by Olaf Bachmann <obachman@…>, 23 years ago
* towards tailRings for local case git-svn-id: file:///usr/local/Singular/svn/trunk@4975 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 17.8 KB
Line 
1#ifndef KUTIL_H
2#define KUTIL_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/* $Id: kutil.h,v 1.53 2000-12-21 16:37:51 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, or -1 if not in T
63  BOOLEAN is_normalized; // true, if pNorm 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 pOrigFDeg_TailRing;
221  pLDegProc pOrigLDeg_TailRing;
222
223  ideal Shdl;
224  ideal D; /*V(S) is in D(D)*/
225  ideal M; /*set of minimal generators*/
226  polyset S;
227  intset ecartS;
228  intset fromQ;
229  unsigned long* sevS;
230  unsigned long* sevT;
231  TSet T;
232  LSet L;
233  LSet    B;
234  poly    kHEdge;
235  poly    kNoether;
236  poly    t_kHEdge; // same polys in tailring
237  KINLINE poly    kNoetherTail();
238  poly    t_kNoether;
239  BOOLEAN * NotUsedAxis;
240  LObject P;
241  poly tail;
242  leftv kIdeal;
243  intvec * kModW;
244  intvec * kHomW;
245  // procedure for ShalloCopy from tailRing  to currRing
246  pShallowCopyDeleteProc p_shallow_copy_delete;
247  BOOLEAN *pairtest;/*used for enterOnePair*/
248  // if set, pLDeg(p, l) == (pFDeg(pLast(p), pLength)
249  BOOLEAN LDegLast;
250  // if set, then L.length == L.pLength
251  BOOLEAN length_pLength;
252  // if set, then posInL does not depend on L.length
253  BOOLEAN posInLDependsOnLength;
254  int cp,c3;
255  int sl,mu;
256  int tl,tmax;
257  int Ll,Lmax;
258  int Bl,Bmax;
259  int ak,LazyDegree,LazyPass;
260  int syzComp;
261  int HCord;
262  int lastAxis;
263  int newIdeal;
264  int minim;
265  BOOLEAN interpt;
266  BOOLEAN homog;
267  BOOLEAN kHEdgeFound;
268  BOOLEAN honey,sugarCrit;
269  BOOLEAN Gebauer,noTailReduction;
270  BOOLEAN fromT;
271  BOOLEAN noetherSet;
272  BOOLEAN update;
273  BOOLEAN posInLOldFlag;
274  BOOLEAN use_buckets;
275  ring tailRing;
276  omBin lmBin;
277  omBin tailBin;
278  /*FALSE, if posInL == posInL10*/
279  char    redTailChange;
280  char    news;
281  char    newt;/*used for messageSets*/
282
283  // pointers to Tobjects R[i] is ith Tobject which is generated
284  TObject**  R; 
285  // S_2_R[i] yields Tobject which corresponds to S[i]
286  int*      S_2_R; 
287 
288  skStrategy();
289  ~skStrategy();
290
291  // return TObject corresponding to S[i]: assume that it exists
292  // i.e. no error checking is done
293  KINLINE TObject* S_2_T(int i);
294  // like S_2_T, except that NULL is returned if it can not be found
295  KINLINE TObject* s_2_t(int i);
296};
297
298void deleteHC(poly *p, int *e, int *l, kStrategy strat);
299void deleteHC(LObject* L, kStrategy strat, BOOLEAN fromNext = FALSE);
300void deleteInS (int i,kStrategy strat);
301void cleanT (kStrategy strat);
302LSet initL ();
303void deleteInL(LSet set, int *length, int j,kStrategy strat);
304void enterL (LSet *set,int *length, int *LSetmax, LObject p,int at);
305void enterSBba (LObject p,int atS,kStrategy strat, int atR = -1);
306void initEcartPairBba (LObject* Lp,poly f,poly g,int ecartF,int ecartG);
307void initEcartPairMora (LObject* Lp,poly f,poly g,int ecartF,int ecartG);
308int posInS (polyset set,int length,poly p);
309int posInT0 (const TSet set,const int length,LObject &p);
310int posInT1 (const TSet set,const int length,LObject &p);
311int posInT2 (const TSet set,const int length,LObject &p);
312int posInT11 (const TSet set,const int length,LObject &p);
313int posInT13 (const TSet set,const int length,LObject &p);
314int posInT15 (const TSet set,const int length,LObject &p);
315int posInT17 (const TSet set,const int length,LObject &p);
316int posInT19 (const TSet set,const int length,LObject &p);
317int posInT_EcartpLength(const TSet set,const int length,LObject &p);
318
319#ifdef HAVE_MORE_POS_IN_T
320int posInT_EcartFDegpLength(const TSet set,const int length,LObject &p);
321int posInT_FDegpLength(const TSet set,const int length,LObject &p);
322int posInT_pLength(const TSet set,const int length,LObject &p);
323#endif
324
325
326void reorderS (int* suc,kStrategy strat);
327int posInL0 (const LSet set, const int length,
328             LObject* L,const kStrategy strat);
329int posInL11 (const LSet set, const int length,
330             LObject* L,const kStrategy strat);
331int posInL13 (const LSet set, const int length,
332             LObject* L,const kStrategy strat);
333int posInL15 (const LSet set, const int length,
334             LObject* L,const kStrategy strat);
335int posInL17 (const LSet set, const int length,
336             LObject* L,const kStrategy strat);
337int posInL10 (const LSet set, const int length,
338             LObject* L,const kStrategy strat);
339KINLINE poly redtailBba (poly p,int pos,kStrategy strat);
340poly redtailBba (LObject *L, int pos,kStrategy strat, BOOLEAN withT = FALSE);
341poly redtailBba (TObject *T, int pos,kStrategy strat, BOOLEAN withT = FALSE);
342poly redtail (poly p,int pos,kStrategy strat);
343poly redtail (LObject *L,int pos,kStrategy strat);
344void enterpairs (poly h, int k, int ec, int pos,kStrategy strat, int atR = -1);
345void entersets (LObject h);
346void pairs ();
347void message (int i,int* reduc,int* olddeg,kStrategy strat,int red_result);
348void messageStat (int srmax,int lrmax,int hilbcount,kStrategy strat);
349#ifdef KDEBUG
350void messageSets (kStrategy strat);
351#else
352#define messageSets(s)  ((void) 0)
353#endif
354
355void initEcartNormal (LObject* h);
356void initEcartBBA (LObject* h);
357void initS (ideal F, ideal Q,kStrategy strat);
358void initSL (ideal F, ideal Q,kStrategy strat);
359void updateS(BOOLEAN toT,kStrategy strat);
360void enterT (LObject p,kStrategy strat, int atT = -1);
361void cancelunit (LObject* p);
362void HEckeTest (poly pp,kStrategy strat);
363void initBuchMoraCrit(kStrategy strat);
364void initHilbCrit(ideal F, ideal Q, intvec **hilb,kStrategy strat);
365void initBuchMoraPos(kStrategy strat);
366void initBuchMora (ideal F, ideal Q,kStrategy strat);
367void exitBuchMora (kStrategy strat);
368void updateResult(ideal r,ideal Q,kStrategy strat);
369void completeReduce (kStrategy strat);
370void kFreeStrat(kStrategy strat);
371BOOLEAN homogTest(polyset F, int Fmax);
372BOOLEAN newHEdge(polyset S, int ak,kStrategy strat);
373// returns index of p in TSet, or -1 if not found
374int kFindInT(poly p, TSet T, int tlength);
375
376// return -1 if no divisor is found
377//        number of first divisor, otherwise
378int kFindDivisibleByInT(const TSet &T, const unsigned long* sevT, 
379                        const int tl, const LObject* L, const int start=0);
380// same with S
381int kFindDivisibleByInS(const polyset &S, const unsigned long* sev, 
382                        const int sl, LObject* L);
383
384
385
386/***************************************************************
387 *
388 * stuff to be inlined
389 *
390 ***************************************************************/
391
392KINLINE TSet initT ();
393KINLINE TObject** initR();
394KINLINE unsigned long* initsevT();
395KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing, omBin bin);
396KINLINE poly k_LmInit_tailRing_2_currRing(poly p, ring tailRing, omBin bin);
397KINLINE poly k_LmShallowCopyDelete_currRing_2_tailRing(poly p, ring tailRing, omBin bin);
398KINLINE poly k_LmShallowCopyDelete_tailRing_2_currRing(poly p, ring tailRing,  omBin bin);
399
400KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing);
401KINLINE poly k_LmInit_tailRing_2_currRing(poly p, ring tailRing);
402KINLINE poly k_LmShallowCopyDelete_currRing_2_tailRing(poly p, ring tailRing);
403KINLINE poly k_LmShallowCopyDelete_tailRing_2_currRing(poly p, ring tailRing);
404
405// if exp bound is not violated, return TRUE and
406//                               get m1 = LCM(LM(p1), LM(p2))/LM(p1)
407//                                   m2 = LCM(LM(p1), LM(p2))/LM(p2)
408// return FALSE and m1 == NULL, m2 == NULL     , otherwise
409KINLINE BOOLEAN k_GetLeadTerms(const poly p1, const poly p2, const ring p_r, 
410                               poly &m1, poly &m2, const ring m_r);
411#ifdef KDEBUG
412// test strat
413BOOLEAN kTest(kStrategy strat);
414// test strat, and test that S is contained in T
415BOOLEAN kTest_TS(kStrategy strat);
416// test LObject
417BOOLEAN kTest_L(LObject* L, ring tailRing = NULL,
418                 BOOLEAN testp = FALSE, int lpos = -1,
419                 TSet T = NULL, int tlength = -1);
420// test TObject
421BOOLEAN kTest_T(TObject* T, ring tailRing = NULL, int tpos = -1, char T = '?');
422// test set strat->SevS
423BOOLEAN kTest_S(kStrategy strat);
424#else
425#define kTest(A)        ((void)0)
426#define kTest_TS(A)     ((void)0)
427#define kTest_T(T)      ((void)0)
428#define kTest_S(T)      ((void)0)
429#define kTest_L(T)      ((void)0)
430#endif
431
432
433/***************************************************************
434 *
435 * From kstd2.cc
436 *
437 ***************************************************************/
438ideal bba (ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat);
439poly kNF2 (ideal F, ideal Q, poly q, kStrategy strat, int lazyReduce);
440ideal kNF2 (ideal F,ideal Q,ideal q, kStrategy strat, int lazyReduce);
441void initBba(ideal F,kStrategy strat);
442
443/***************************************************************
444 *
445 * From kSpolys.cc
446 *
447 ***************************************************************/
448// Reduces PR with PW
449// Assumes PR != NULL, PW != NULL, Lm(PW) divides Lm(PR)
450// Changes: PR
451// Const:   PW
452// If coef != NULL, then *coef is a/gcd(a,b), where a = LC(PR), b = LC(PW)
453// If strat != NULL, tailRing is changed if reduction would violate exp bound
454// of tailRing
455// Returns: 0 everything ok, no tailRing change
456//          1 tailRing has successfully changed (strat != NULL)
457//          2 no reduction performed, tailRing needs to be changed first
458//            (strat == NULL)
459//         -1 tailRing change could not be performed due to exceeding exp
460//            bound of currRing
461int ksReducePoly(LObject* PR,
462                 TObject* PW,
463                 poly spNoether = NULL,
464                 number *coef = NULL, 
465                 kStrategy strat = NULL);
466
467// Reduces PR at Current->next with PW
468// Assumes PR != NULL, Current contained in PR
469//         Current->next != NULL, LM(PW) devides LM(Current->next)
470// Changes: PR
471// Const:   PW
472// Return: see ksReducePoly
473int ksReducePolyTail(LObject* PR,
474                     TObject* PW,
475                     poly Current,
476                     poly spNoether = NULL);
477
478KINLINE int ksReducePolyTail(LObject* PR, TObject* PW, LObject* Red);
479
480// Creates S-Poly of Pair
481// Const:   Pair->p1, Pair->p2
482// Changes: Pair->p == S-Poly of p1, p2
483// Assume:  Pair->p1 != NULL && Pair->p2
484void ksCreateSpoly(LObject* Pair, poly spNoether = NULL, 
485                   int use_buckets=0, ring tailRing=currRing, 
486                   poly m1 = NULL, poly m2 = NULL, TObject** R = NULL);
487
488/*2
489* creates the leading term of the S-polynomial of p1 and p2
490* do not destroy p1 and p2
491* remarks:
492*   1. the coefficient is 0 (nNew)
493*   2. pNext is undefined
494*/
495poly ksCreateShortSpoly(poly p1, poly p2, ring tailRing);
496
497
498/*
499* input - output: a, b
500* returns:
501*   a := a/gcd(a,b), b := b/gcd(a,b)
502*   and return value
503*       0  ->  a != 1,  b != 1
504*       1  ->  a == 1,  b != 1
505*       2  ->  a != 1,  b == 1
506*       3  ->  a == 1,  b == 1
507*   this value is used to control the spolys
508*/
509int ksCheckCoeff(number *a, number *b);
510
511// old stuff
512KINLINE poly ksOldSpolyRed(poly p1, poly p2, poly spNoether = NULL);
513KINLINE poly ksOldSpolyRedNew(poly p1, poly p2, poly spNoether = NULL);
514KINLINE poly ksOldCreateSpoly(poly p1, poly p2, poly spNoether = NULL, ring r = currRing);
515KINLINE void ksOldSpolyTail(poly p1, poly q, poly q2, poly spNoether, ring r = currRing);
516
517/***************************************************************
518 *
519 * Routines related for ring changes during std computations
520 *
521 ***************************************************************/
522// return TRUE and set m1, m2 to k_GetLcmTerms,
523//             if spoly creation of strat->P does not violate
524//             exponent bound of strat->tailRing
525//      FALSE, otherwise
526BOOLEAN kCheckSpolyCreation(LObject* L, kStrategy strat, poly &m1, poly &m2);
527// change strat->tailRing and adjust all data in strat, L, and T:
528// new tailRing has larger exponent bound
529// do nothing and return FALSE if exponent bound increase would result in
530// larger exponent bound that that of currRing
531BOOLEAN kStratChangeTailRing(kStrategy strat, 
532                             LObject* L = NULL, TObject* T = NULL,
533                             // take this as new_expbound: if 0
534                             // new expbound is 2*expbound of tailRing
535                             unsigned long new_expbound = 0);
536// initiate a change of the tailRing of strat -- should be called
537// right before main loop in bba
538void kStratInitChangeTailRing(kStrategy strat);
539
540#include "kInline.cc"
541
542
543#endif
Note: See TracBrowser for help on using the repository browser.