1 | #ifndef KUTIL_H |
---|
2 | #define KUTIL_H |
---|
3 | /**************************************** |
---|
4 | * Computer Algebra System SINGULAR * |
---|
5 | ****************************************/ |
---|
6 | /* $Id: kutil.h,v 1.25 2000-04-27 10:07:08 obachman Exp $ */ |
---|
7 | /* |
---|
8 | * ABSTRACT: kernel: utils for kStd |
---|
9 | */ |
---|
10 | #include <string.h> |
---|
11 | #include "structs.h" |
---|
12 | #include "mmemory.h" |
---|
13 | #include "ring.h" |
---|
14 | |
---|
15 | #define setmax 16 |
---|
16 | |
---|
17 | typedef int* intset; |
---|
18 | |
---|
19 | class sTObject |
---|
20 | { |
---|
21 | public: |
---|
22 | poly p; |
---|
23 | int ecart,length, pLength; |
---|
24 | memHeap heap; |
---|
25 | unsigned long sev; |
---|
26 | sTObject() { memset((void*) this, 0, sizeof(sTObject)); heap = mm_specHeap;} |
---|
27 | inline poly SetP(poly p_new); |
---|
28 | }; |
---|
29 | |
---|
30 | class sLObject |
---|
31 | { |
---|
32 | public: |
---|
33 | poly p; |
---|
34 | poly p1,p2; /*- the pair p comes from -*/ |
---|
35 | poly lcm; /*- the lcm of p1,p2 -*/ |
---|
36 | memHeap heap; |
---|
37 | int ecart,length, pLength; |
---|
38 | unsigned long sev; |
---|
39 | sLObject() { memset((void*) this, 0, sizeof(sLObject));} |
---|
40 | }; |
---|
41 | |
---|
42 | typedef class sTObject TObject; |
---|
43 | typedef class sLObject LObject; |
---|
44 | typedef TObject * TSet; |
---|
45 | typedef LObject * LSet; |
---|
46 | |
---|
47 | extern int HCord; |
---|
48 | |
---|
49 | class skStrategy; |
---|
50 | typedef skStrategy * kStrategy; |
---|
51 | class skStrategy |
---|
52 | { |
---|
53 | public: |
---|
54 | kStrategy next; |
---|
55 | int (*red)(LObject * L,kStrategy strat); |
---|
56 | void (*initEcart)(LObject * L); |
---|
57 | int (*posInT)(const TSet T,const int tl,const LObject &h); |
---|
58 | int (*posInL)(const LSet set, const int length, |
---|
59 | const LObject &L,const kStrategy strat); |
---|
60 | void (*enterS)(LObject h, int pos,kStrategy strat); |
---|
61 | void (*initEcartPair)(LObject * h, poly f, poly g, int ecartF, int ecartG); |
---|
62 | int (*posInLOld)(const LSet Ls,const int Ll, |
---|
63 | const LObject &Lo,const kStrategy strat); |
---|
64 | pFDegProc pOldFDeg; |
---|
65 | ideal Shdl; |
---|
66 | ideal D; /*V(S) is in D(D)*/ |
---|
67 | ideal M; /*set of minimal generators*/ |
---|
68 | polyset S; |
---|
69 | intset ecartS; |
---|
70 | intset fromQ; |
---|
71 | unsigned long* sevS; |
---|
72 | TSet T; |
---|
73 | LSet L; |
---|
74 | LSet B; |
---|
75 | poly kHEdge; |
---|
76 | poly kNoether; |
---|
77 | BOOLEAN * NotUsedAxis; |
---|
78 | LObject P; |
---|
79 | poly tail; |
---|
80 | leftv kIdeal; |
---|
81 | intvec * kModW; |
---|
82 | intvec * kHomW; |
---|
83 | memHeap THeap; // if != NULL, heap for monoms of T |
---|
84 | BOOLEAN use_redheap; // if TRUE, use extra heap for reductions |
---|
85 | BOOLEAN *pairtest;/*used for enterOnePair*/ |
---|
86 | int cp,c3; |
---|
87 | int sl,mu; |
---|
88 | int tl,tmax; |
---|
89 | int Ll,Lmax; |
---|
90 | int Bl,Bmax; |
---|
91 | int ak,LazyDegree,LazyPass; |
---|
92 | int syzComp; |
---|
93 | int HCord; |
---|
94 | int lastAxis; |
---|
95 | int newIdeal; |
---|
96 | int minim; |
---|
97 | BOOLEAN interpt; |
---|
98 | BOOLEAN homog; |
---|
99 | BOOLEAN kHEdgeFound; |
---|
100 | BOOLEAN honey,sugarCrit; |
---|
101 | BOOLEAN Gebauer,noTailReduction; |
---|
102 | BOOLEAN fromT; |
---|
103 | BOOLEAN noetherSet; |
---|
104 | BOOLEAN update; |
---|
105 | BOOLEAN posInLOldFlag; |
---|
106 | /*FALSE, if posInL == posInL10*/ |
---|
107 | char redTailChange; |
---|
108 | char news; |
---|
109 | char newt;/*used for messageSets*/ |
---|
110 | }; |
---|
111 | |
---|
112 | void deleteHC(poly *p, int *e, int *l, kStrategy strat); |
---|
113 | void deleteInS (int i,kStrategy strat); |
---|
114 | void cleanT (kStrategy strat); |
---|
115 | LSet initL (); |
---|
116 | void deleteInL(LSet set, int *length, int j,kStrategy strat); |
---|
117 | void enterL (LSet *set,int *length, int *LSetmax, LObject p,int at); |
---|
118 | void initEcartPairBba (LObject* Lp,poly f,poly g,int ecartF,int ecartG); |
---|
119 | void initEcartPairMora (LObject* Lp,poly f,poly g,int ecartF,int ecartG); |
---|
120 | int posInS (polyset set,int length,poly p); |
---|
121 | int posInT0 (const TSet set,const int length,const LObject &p); |
---|
122 | int posInT1 (const TSet set,const int length,const LObject &p); |
---|
123 | int posInT2 (const TSet set,const int length,const LObject &p); |
---|
124 | int posInT11 (const TSet set,const int length,const LObject &p); |
---|
125 | int posInT13 (const TSet set,const int length,const LObject &p); |
---|
126 | int posInT15 (const TSet set,const int length,const LObject &p); |
---|
127 | int posInT17 (const TSet set,const int length,const LObject &p); |
---|
128 | int posInT19 (const TSet set,const int length,const LObject &p); |
---|
129 | void reorderS (int* suc,kStrategy strat); |
---|
130 | int posInL0 (const LSet set, const int length, |
---|
131 | const LObject &L,const kStrategy strat); |
---|
132 | int posInL11 (const LSet set, const int length, |
---|
133 | const LObject &L,const kStrategy strat); |
---|
134 | int posInL13 (const LSet set, const int length, |
---|
135 | const LObject &L,const kStrategy strat); |
---|
136 | int posInL15 (const LSet set, const int length, |
---|
137 | const LObject &L,const kStrategy strat); |
---|
138 | int posInL17 (const LSet set, const int length, |
---|
139 | const LObject &L,const kStrategy strat); |
---|
140 | poly redtailBba (poly p,int pos,kStrategy strat); |
---|
141 | poly redtailSyz (poly p,int pos,kStrategy strat); |
---|
142 | poly redtail (poly p,int pos,kStrategy strat); |
---|
143 | void enterpairs (poly h, int k, int ec, int pos,kStrategy strat); |
---|
144 | void entersets (LObject h); |
---|
145 | void pairs (); |
---|
146 | void message (int i,int* reduc,int* olddeg,kStrategy strat); |
---|
147 | void messageStat (int srmax,int lrmax,int hilbcount,kStrategy strat); |
---|
148 | void messageSets (kStrategy strat); |
---|
149 | void initEcartNormal (LObject* h); |
---|
150 | void initEcartBBA (LObject* h); |
---|
151 | void initS (ideal F, ideal Q,kStrategy strat); |
---|
152 | void initSL (ideal F, ideal Q,kStrategy strat); |
---|
153 | void updateS(BOOLEAN toT,kStrategy strat); |
---|
154 | void enterSBba (LObject p, int pos,kStrategy strat); |
---|
155 | void enterT (LObject p,kStrategy strat); |
---|
156 | void enterTBba (LObject p, int pos,kStrategy strat); |
---|
157 | void cancelunit (LObject* p); |
---|
158 | void HEckeTest (poly pp,kStrategy strat); |
---|
159 | void redtailS (poly* h,int maxIndex); |
---|
160 | void redtailMora (poly* h,int maxIndex); |
---|
161 | void kinitBbaHeaps(kStrategy heap); |
---|
162 | void initBuchMoraCrit(kStrategy strat); |
---|
163 | void initHilbCrit(ideal F, ideal Q, intvec **hilb,kStrategy strat); |
---|
164 | void initBuchMoraPos(kStrategy strat); |
---|
165 | void initBuchMora (ideal F, ideal Q,kStrategy strat); |
---|
166 | void exitBuchMora (kStrategy strat); |
---|
167 | void updateResult(ideal r,ideal Q,kStrategy strat); |
---|
168 | void completeReduce (kStrategy strat); |
---|
169 | void kFreeStrat(kStrategy strat); |
---|
170 | BOOLEAN homogTest(polyset F, int Fmax); |
---|
171 | BOOLEAN newHEdge(polyset S, int ak,kStrategy strat); |
---|
172 | |
---|
173 | inline TSet initT () { return (TSet)Alloc0(setmax*sizeof(TObject)); } |
---|
174 | |
---|
175 | #ifdef KDEBUG |
---|
176 | #define kTest(A) K_Test(__FILE__,__LINE__,A) |
---|
177 | #define kTest_TS(A) K_Test_TS(__FILE__,__LINE__,A) |
---|
178 | #define kTest_T(T) K_Test_T(__FILE__,__LINE__,T) |
---|
179 | #define kTest_L(L) K_Test_L(__FILE__,__LINE__,L) |
---|
180 | #define kTest_S(strat) K_Test_S(__FILE__,__LINE__,strat) |
---|
181 | #define kTest_Pref(L) K_Test(__FILE__,__LINE__,L, 2) |
---|
182 | BOOLEAN K_Test(char *f, int l,kStrategy strat, int pref=0); |
---|
183 | BOOLEAN K_Test_TS(char *f, int l,kStrategy strat); |
---|
184 | BOOLEAN K_Test_T(char *f, int l, TObject* T, int tpos = -1); |
---|
185 | BOOLEAN K_Test_L(char* f, int l, LObject* L, |
---|
186 | BOOLEAN testp = FALSE, int lpos = -1, |
---|
187 | TSet T = NULL, int tlength = -1); |
---|
188 | BOOLEAN K_Test_S(char* f, int l, kStrategy strat); |
---|
189 | #else |
---|
190 | #define kTest(A) (TRUE) |
---|
191 | #define kTest_Pref(A) (TRUE) |
---|
192 | #define kTest_TS(A) (TRUE) |
---|
193 | #define kTest_T(T) (TRUE) |
---|
194 | #define kTest_S(T) (TRUE) |
---|
195 | #define kTest_L(T) (TRUE) |
---|
196 | #endif |
---|
197 | #endif |
---|
198 | |
---|
199 | /*************************************************************** |
---|
200 | * |
---|
201 | * From kstd2.cc |
---|
202 | * |
---|
203 | ***************************************************************/ |
---|
204 | ideal bba (ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat); |
---|
205 | poly kNF2 (ideal F, ideal Q, poly q, kStrategy strat, int lazyReduce); |
---|
206 | ideal kNF2 (ideal F,ideal Q,ideal q, kStrategy strat, int lazyReduce); |
---|
207 | void initBba(ideal F,kStrategy strat); |
---|
208 | |
---|
209 | /*************************************************************** |
---|
210 | * |
---|
211 | * From kSpolys.cc |
---|
212 | * |
---|
213 | ***************************************************************/ |
---|
214 | // Reduces PR with PW |
---|
215 | // Assumes PR != NULL, PW != NULL, Lm(PW) divides Lm(PR) |
---|
216 | // Changes: PR |
---|
217 | // Const: PW |
---|
218 | // If coef != NULL, then *coef is a/gcd(a,b), where a = LC(PR), b = LC(PW) |
---|
219 | void ksReducePoly(LObject* PR, |
---|
220 | TObject* PW, |
---|
221 | poly spNoether = NULL, |
---|
222 | number *coef = NULL); |
---|
223 | |
---|
224 | // Reduces PR at Current->next with PW |
---|
225 | // Assumes PR != NULL, Current contained in PR |
---|
226 | // Current->next != NULL, LM(PW) devides LM(Current->next) |
---|
227 | // Changes: PR |
---|
228 | // Const: PW |
---|
229 | void ksReducePolyTail(LObject* PR, |
---|
230 | TObject* PW, |
---|
231 | poly Current, |
---|
232 | poly spNoether = NULL); |
---|
233 | |
---|
234 | // Creates S-Poly of Pair |
---|
235 | // Const: Pair->p1, Pair->p2 |
---|
236 | // Changes: Pair->p == S-Poly of p1, p2 |
---|
237 | // Assume: Pair->p1 != NULL && Pair->p2 |
---|
238 | void ksCreateSpoly(LObject* Pair, |
---|
239 | poly spNoether = NULL); |
---|
240 | |
---|
241 | |
---|
242 | /*2 |
---|
243 | * creates the leading term of the S-polynomial of p1 and p2 |
---|
244 | * do not destroy p1 and p2 |
---|
245 | * remarks: |
---|
246 | * 1. the coefficient is 0 (nNew) |
---|
247 | * 2. pNext is undefined |
---|
248 | */ |
---|
249 | poly ksCreateShortSpoly(poly p1, poly p2); |
---|
250 | |
---|
251 | |
---|
252 | /* |
---|
253 | * input - output: a, b |
---|
254 | * returns: |
---|
255 | * a := a/gcd(a,b), b := b/gcd(a,b) |
---|
256 | * and return value |
---|
257 | * 0 -> a != 1, b != 1 |
---|
258 | * 1 -> a == 1, b != 1 |
---|
259 | * 2 -> a != 1, b == 1 |
---|
260 | * 3 -> a == 1, b == 1 |
---|
261 | * this value is used to control the spolys |
---|
262 | */ |
---|
263 | int ksCheckCoeff(number *a, number *b); |
---|
264 | |
---|
265 | // old stuff |
---|
266 | poly ksOldSpolyRed(poly p1, poly p2, poly spNoether = NULL); |
---|
267 | poly ksOldSpolyRedNew(poly p1, poly p2, poly spNoether = NULL); |
---|
268 | poly ksOldCreateSpoly(poly p1, poly p2, poly spNoether = NULL); |
---|
269 | void ksOldSpolyTail(poly p1, poly q, poly q2, poly spNoether); |
---|
270 | |
---|
271 | |
---|
272 | #include "polys.h" |
---|
273 | // Methods for tobjects |
---|
274 | inline poly sTObject::SetP(poly new_p) |
---|
275 | { |
---|
276 | poly old_p = p; |
---|
277 | memset((void*) this, 0, sizeof(sTObject)); |
---|
278 | p = new_p; |
---|
279 | sev = pGetShortExpVector(p); |
---|
280 | return p; |
---|
281 | } |
---|
282 | |
---|