source: git/Singular/kutil.h @ fc83e4

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