source: git/Singular/kutil.h @ b98976

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