source: git/Singular/kutil.h @ 2f436b

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