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

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