source: git/Singular/kutil.h @ 48aa42

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