1 | #ifndef POLYS_IMPL_H |
---|
2 | #define POLYS_IMPL_H |
---|
3 | /**************************************** |
---|
4 | * Computer Algebra System SINGULAR * |
---|
5 | ****************************************/ |
---|
6 | /* $Id: polys-impl.h,v 1.48 2000-08-24 14:24:51 Singular Exp $ */ |
---|
7 | |
---|
8 | /*************************************************************** |
---|
9 | * |
---|
10 | * File: polys-impl.h |
---|
11 | * Purpose: low-level definition and declarations for polys |
---|
12 | * |
---|
13 | * If you touch anything here, you better know what you are doing. |
---|
14 | * What is here should not be used directly from other routines -- the |
---|
15 | * encapsulations in polys.h should be used, instead. |
---|
16 | * |
---|
17 | ***************************************************************/ |
---|
18 | #include "tok.h" |
---|
19 | #include "structs.h" |
---|
20 | #include <omalloc.h> |
---|
21 | |
---|
22 | /*************************************************************** |
---|
23 | * |
---|
24 | * definition of the poly structure and its fields |
---|
25 | * |
---|
26 | ***************************************************************/ |
---|
27 | |
---|
28 | #ifndef NDEBUG |
---|
29 | #define VARS (10) /*max. number of variables as constant*/ |
---|
30 | #else |
---|
31 | #define VARS (0) |
---|
32 | #endif |
---|
33 | union s_exp |
---|
34 | { |
---|
35 | #ifdef HAVE_SHIFTED_EXPONENTS |
---|
36 | unsigned long l[VARS +1]; |
---|
37 | #else |
---|
38 | Exponent_t e[VARS +1]; |
---|
39 | unsigned long l[(VARS +1)/(sizeof(long)/sizeof(Exponent_t))]; |
---|
40 | #endif |
---|
41 | }; |
---|
42 | |
---|
43 | typedef s_exp monomial; |
---|
44 | typedef Exponent_t* Exponent_pt; |
---|
45 | |
---|
46 | typedef unsigned long Order_t; |
---|
47 | struct spolyrec |
---|
48 | { |
---|
49 | poly next; // next needs to be the first field |
---|
50 | number coef; // and coef the second --- do not change this !!! |
---|
51 | monomial exp; // make sure that exp is aligned |
---|
52 | }; |
---|
53 | |
---|
54 | /*************************************************************** |
---|
55 | * |
---|
56 | * variables/defines used for managment of monomials |
---|
57 | * |
---|
58 | ***************************************************************/ |
---|
59 | |
---|
60 | #define POLYSIZE (sizeof(poly) + sizeof(number)) |
---|
61 | #define POLYSIZEW (POLYSIZE / sizeof(long)) |
---|
62 | #define MAX_EXPONENT_NUMBER ((MAX_BLOCK_SIZE - POLYSIZE) / SIZEOF_EXPONENT) |
---|
63 | |
---|
64 | // number of Variables |
---|
65 | extern int pVariables; |
---|
66 | // size of a monom in bytes - always a multiple of sizeof(void*) |
---|
67 | extern int pMonomSize; |
---|
68 | // size of a monom in units of sizeof(void*) -- i.e. in words |
---|
69 | extern int pMonomSizeW; |
---|
70 | // Ceiling((pVariables+1) / sizeof(void*)) == length of exp-vector in words |
---|
71 | // extern int pVariables1W; |
---|
72 | // Ceiling((pVariables) / sizeof(void*)) |
---|
73 | // extern int pVariablesW; |
---|
74 | extern int *pVarOffset; |
---|
75 | // extern int pVarLowIndex; |
---|
76 | // extern int pVarHighIndex; |
---|
77 | // extern int pVarCompIndex; |
---|
78 | extern omBin currPolyBin; |
---|
79 | |
---|
80 | /*************************************************************** |
---|
81 | * |
---|
82 | * Primitives for determening/setting the way exponents are arranged |
---|
83 | * |
---|
84 | ***************************************************************/ |
---|
85 | #define _pExpIndex(i) (currRing->VarOffset[(i)]) |
---|
86 | #define _pRingExpIndex(r, i) (r)->VarOffset[(i)] |
---|
87 | |
---|
88 | #define _pCompIndex (currRing->pCompIndex) |
---|
89 | #define _pRingCompIndex(r) ((r)->pCompIndex) |
---|
90 | |
---|
91 | /*************************************************************** |
---|
92 | * |
---|
93 | * Primitives for accessing and setting fields of a poly |
---|
94 | * |
---|
95 | ***************************************************************/ |
---|
96 | #define _pNext(p) ((p)->next) |
---|
97 | #define _pIter(p) ((p) = (p)->next) |
---|
98 | |
---|
99 | #define _pGetCoeff(p) ((p)->coef) |
---|
100 | #define _pSetCoeff(p,n) {nDelete(&((p)->coef));(p)->coef=n;} |
---|
101 | #define _pSetCoeff0(p,n) (p)->coef=n |
---|
102 | |
---|
103 | //#ifdef HAVE_SHIFTED_EXPONENTS |
---|
104 | //#define _pGetOrder(p) ((p)->exp.l[currRing->pOrdIndex]-0x40000000) |
---|
105 | //#else |
---|
106 | #define _pGetOrder(p) ((p)->exp.l[currRing->pOrdIndex]) |
---|
107 | //#endif |
---|
108 | |
---|
109 | #if defined(PDEBUG) && PDEBUG > 1 |
---|
110 | extern Exponent_t pPDSetExp(poly p, int v, Exponent_t e, char* f, int l); |
---|
111 | extern Exponent_t pPDGetExp(poly p, int v, char* f, int l); |
---|
112 | extern Exponent_t pPDIncrExp(poly p, int v, char* f, int l); |
---|
113 | extern Exponent_t pPDDecrExp(poly p, int v, char* f, int l); |
---|
114 | extern Exponent_t pPDAddExp(poly p, int v, Exponent_t e, char* f, int l); |
---|
115 | extern Exponent_t pPDMultExp(poly p, int v, Exponent_t e, char* f, int l); |
---|
116 | extern Exponent_t pPDSubExp(poly p, int v, Exponent_t e, char* f, int l); |
---|
117 | |
---|
118 | extern Exponent_t pPDRingSetExp(ring r,poly p,int v,Exponent_t e,char* f,int l); |
---|
119 | extern Exponent_t pPDRingGetExp(ring r,poly p, int v, char* f, int l); |
---|
120 | |
---|
121 | extern Exponent_t pDBSetComp(poly p, Exponent_t k, int l, char* f, int l); |
---|
122 | extern Exponent_t pDBDecrComp(poly p, char* f, int l); |
---|
123 | extern Exponent_t pDBAddComp(poly p, Exponent_t k, int l, char* f, int l); |
---|
124 | extern Exponent_t pDBSubComp(poly p, Exponent_t k, char* f, int l); |
---|
125 | extern Exponent_t pDBRingSetComp(ring r, poly p, Exponent_t k, char* f, int l); |
---|
126 | |
---|
127 | |
---|
128 | #define _pSetExp(p,v,e) pPDSetExp(p,v,e,__FILE__,__LINE__) |
---|
129 | #define _pGetExp(p,v) pPDGetExp(p,v,__FILE__,__LINE__) |
---|
130 | #define _pIncrExp(p,v) pPDIncrExp(p,v,__FILE__,__LINE__) |
---|
131 | #define _pDecrExp(p,v) pPDDecrExp(p,v,__FILE__,__LINE__) |
---|
132 | #define _pAddExp(p,i,v) pPDAddExp(p,i,v,__FILE__,__LINE__) |
---|
133 | #define _pSubExp(p,i,v) pPDSubExp(p,i,v,__FILE__,__LINE__) |
---|
134 | #define _pMultExp(p,i,v) pPDMultExp(p,i,v,__FILE__,__LINE__) |
---|
135 | |
---|
136 | #define _pRingSetExp(r,p,v,e) pPDRingSetExp(r,p,v,e,__FILE__,__LINE__) |
---|
137 | #define _pRingGetExp(r,p,v) pPDRingGetExp(r,p,v,__FILE__,__LINE__) |
---|
138 | |
---|
139 | #define _pSetComp(p,k) pDBSetComp(p, k, 0, __FILE__, __LINE__) |
---|
140 | #define _pDecrComp(p) pDBDecrComp(p, __FILE__, __LINE__) |
---|
141 | #define _pAddComp(p,v) pDBAddComp(p,v, 0, __FILE__, __LINE__) |
---|
142 | #define _pSubComp(p,v) pDBSubComp(p,v, __FILE__, __LINE__) |
---|
143 | #define _pRingSetComp(r,p,k) pDBRingSetComp(r, p, k, __FILE__, __LINE__) |
---|
144 | |
---|
145 | #define pSetCompS(p, k, l) pDBSetComp(p, k, l, __FILE__, __LINE__) |
---|
146 | |
---|
147 | #else // ! (defined(PDEBUG) && PDEBUG > 1) |
---|
148 | #ifndef HAVE_SHIFTED_EXPONENTS |
---|
149 | |
---|
150 | #define _pSetExp(p,v,E) (p)->exp.e[_pExpIndex(v)]=(E) |
---|
151 | #define _pGetExp(p,v) (p)->exp.e[_pExpIndex(v)] |
---|
152 | #define _pIncrExp(p,v) ((p)->exp.e[_pExpIndex(v)])++ |
---|
153 | #define _pDecrExp(p,v) ((p)->exp.e[_pExpIndex(v)])-- |
---|
154 | #define _pAddExp(p,i,v) ((p)->exp.e[_pExpIndex(i)]) += (v) |
---|
155 | #define _pSubExp(p,i,v) ((p)->exp.e[_pExpIndex(i)]) -= (v) |
---|
156 | #define _pMultExp(p,i,v) ((p)->exp.e[_pExpIndex(i)]) *= (v) |
---|
157 | |
---|
158 | #define _pRingSetExp(r,p,e_i,e_v) (p)->exp.e[_pRingExpIndex(r,e_i)]=(e_v) |
---|
159 | #define _pRingGetExp(r,p,v) (p)->exp.e[_pRingExpIndex(r,v)] |
---|
160 | #else |
---|
161 | inline Exponent_t pSGetExp(poly p, int v, ring r) |
---|
162 | { |
---|
163 | assume(v>0); |
---|
164 | assume(v<=r->N); |
---|
165 | return (p->exp.l[(r->VarOffset[v] & 0xffffff)] >> (r->VarOffset[v] >> 24)) |
---|
166 | & r->bitmask; |
---|
167 | } |
---|
168 | |
---|
169 | inline Exponent_t pSSetExp(poly p, int v, int e, ring r) |
---|
170 | { |
---|
171 | assume(e>=0); |
---|
172 | assume(v>0); |
---|
173 | assume(v<=r->N); |
---|
174 | assume(e<=((int)r->bitmask)); |
---|
175 | |
---|
176 | // shift e to the left: |
---|
177 | register int shift = r->VarOffset[v] >> 24; |
---|
178 | unsigned long ee = ((unsigned long)e) << shift /*(r->VarOffset[v] >> 24)*/; |
---|
179 | // clear the bits in the exponent vector: |
---|
180 | register int offset = (r->VarOffset[v] & 0xffffff); |
---|
181 | p->exp.l[offset] &= |
---|
182 | ~( r->bitmask << shift ); |
---|
183 | // insert e with | |
---|
184 | p->exp.l[ offset ] |= ee; |
---|
185 | return e; |
---|
186 | } |
---|
187 | |
---|
188 | inline Exponent_t pSIncrExp(poly p, int v, ring r) |
---|
189 | { |
---|
190 | assume(v>0); |
---|
191 | assume(v<=r->N); |
---|
192 | |
---|
193 | Exponent_t e=pSGetExp(p,v,r); |
---|
194 | e++; |
---|
195 | return pSSetExp(p,v,e,r); |
---|
196 | } |
---|
197 | |
---|
198 | inline Exponent_t pSDecrExp(poly p, int v, ring r) |
---|
199 | { |
---|
200 | assume(v>0); |
---|
201 | assume(v<=r->N); |
---|
202 | |
---|
203 | Exponent_t e=pSGetExp(p,v,r); |
---|
204 | e--; |
---|
205 | return pSSetExp(p,v,e,r); |
---|
206 | } |
---|
207 | |
---|
208 | inline Exponent_t pSAddExp(poly p, int v, Exponent_t e, ring r) |
---|
209 | { |
---|
210 | assume(v>0); |
---|
211 | assume(v<=r->N); |
---|
212 | |
---|
213 | Exponent_t ee=pSGetExp(p,v,r); |
---|
214 | ee+=e; |
---|
215 | return pSSetExp(p,v,ee,r); |
---|
216 | } |
---|
217 | |
---|
218 | inline Exponent_t pSSubExp(poly p, int v, Exponent_t e, ring r) |
---|
219 | { |
---|
220 | assume(v>0); |
---|
221 | assume(v<=r->N); |
---|
222 | |
---|
223 | Exponent_t ee=pSGetExp(p,v,r); |
---|
224 | ee-=e; |
---|
225 | return pSSetExp(p,v,ee,r); |
---|
226 | } |
---|
227 | |
---|
228 | inline Exponent_t pSMultExp(poly p, int v, Exponent_t e, ring r) |
---|
229 | { |
---|
230 | assume(v>0); |
---|
231 | assume(v<=r->N); |
---|
232 | |
---|
233 | Exponent_t ee=pSGetExp(p,v,r); |
---|
234 | ee*=e; |
---|
235 | return pSSetExp(p,v,ee,r); |
---|
236 | } |
---|
237 | |
---|
238 | #define _pSetExp(p,v,E) pSSetExp(p,v,E,currRing) |
---|
239 | #define _pGetExp(p,v) pSGetExp(p,v,currRing) |
---|
240 | #define _pIncrExp(p,v) pSIncrExp(p,v,currRing) |
---|
241 | #define _pDecrExp(p,v) pSDecrExp(p,v,currRing) |
---|
242 | #define _pAddExp(p,i,v) pSAddExp(p,i,v,currRing) |
---|
243 | #define _pSubExp(p,i,v) pSSubExp(p,i,v,currRing) |
---|
244 | #define _pMultExp(p,i,v) pSMultExp(p,i,v,currRing) |
---|
245 | |
---|
246 | #define _pRingSetExp(r,p,e_i,e_v) pSSetExp(p,e_i,e_v,r) |
---|
247 | #define _pRingGetExp(r,p,v) pSGetExp(p,v,r) |
---|
248 | #endif |
---|
249 | |
---|
250 | #define _pSetComp(p,k) _pGetComp(p) = (k) |
---|
251 | #define _pDecrComp(p) _pGetComp(p)-- |
---|
252 | #define _pAddComp(p,v) _pGetComp(p) += (v) |
---|
253 | #define _pSubComp(p,v) _pGetComp(p) -= (v) |
---|
254 | #define _pRingSetComp(r,p,k) (_pRingGetComp(r, p) = (k)) |
---|
255 | #define pSetCompS(p, k,l) _pSetComp(p, k) |
---|
256 | |
---|
257 | #endif // defined(PDEBUG) && PDEBUG > 1 |
---|
258 | |
---|
259 | #ifndef HAVE_SHIFTED_EXPONENTS |
---|
260 | |
---|
261 | #define _pGetComp(p) ((p)->exp.e[_pCompIndex]) |
---|
262 | #define _pIncrComp(p) _pGetComp(p)++ |
---|
263 | #define _pRingGetComp(r,p) ((p)->exp.e[_pRingCompIndex(r)]) |
---|
264 | |
---|
265 | inline Exponent_t _pGetExpSum(poly p1, poly p2, int i) |
---|
266 | { |
---|
267 | int index = _pExpIndex(i); |
---|
268 | return p1->exp.e[index] + p2->exp.e[index]; |
---|
269 | } |
---|
270 | inline Exponent_t _pGetExpDiff(poly p1, poly p2, int i) |
---|
271 | { |
---|
272 | int index = _pExpIndex(i); |
---|
273 | return p1->exp.e[index] - p2->exp.e[index]; |
---|
274 | } |
---|
275 | |
---|
276 | #else //--------------------------------------------- |
---|
277 | |
---|
278 | #define _pGetComp(p) ((p)->exp.l[_pCompIndex]) |
---|
279 | #define _pIncrComp(p) _pGetComp(p)++ |
---|
280 | #define _pRingGetComp(r,p) ((p)->exp.l[_pRingCompIndex(r)]) |
---|
281 | |
---|
282 | inline Exponent_t _pGetExpSum(poly p1, poly p2, int i) |
---|
283 | { |
---|
284 | return _pGetExp(p1,i) + _pGetExp(p2,i); |
---|
285 | } |
---|
286 | inline Exponent_t _pGetExpDiff(poly p1, poly p2, int i) |
---|
287 | { |
---|
288 | return _pGetExp(p1,i) - _pGetExp(p2,i); |
---|
289 | } |
---|
290 | #endif |
---|
291 | |
---|
292 | inline void _pGetExpV(poly p, Exponent_t *ev) |
---|
293 | { |
---|
294 | for (int j = pVariables; j; j--) |
---|
295 | ev[j] = _pGetExp(p, j); |
---|
296 | |
---|
297 | ev[0] = _pGetComp(p); |
---|
298 | } |
---|
299 | |
---|
300 | extern pSetmProc pSetm; |
---|
301 | inline void _pSetExpV(poly p, Exponent_t *ev) |
---|
302 | { |
---|
303 | for (int j = pVariables; j; j--) |
---|
304 | _pSetExp(p, j, ev[j]); |
---|
305 | |
---|
306 | _pSetComp(p, ev[0]); |
---|
307 | pSetm(p); |
---|
308 | } |
---|
309 | |
---|
310 | /*************************************************************** |
---|
311 | * |
---|
312 | * Storage Managament Routines |
---|
313 | * |
---|
314 | ***************************************************************/ |
---|
315 | #define prAllocMonom(p, r) omTypeAllocBin(poly, p, r->PolyBin) |
---|
316 | #define _pNew(h) (poly) omAllocBin(h) |
---|
317 | #define _pInit(h) (poly) omAlloc0Bin(h) |
---|
318 | #define _pFree1(a, h) omFreeBin((void*) a, h) |
---|
319 | #define _pRingFree1(r, a) omFreeBin((void*) a, r->PolyBin) |
---|
320 | |
---|
321 | extern void _pDelete(poly * a, omBin h); |
---|
322 | extern void _pDelete1(poly * a, omBin h); |
---|
323 | |
---|
324 | extern poly _pCopy(poly a); |
---|
325 | extern poly _pCopy(omBin h, poly a); |
---|
326 | extern poly _pCopy1(poly a); |
---|
327 | extern poly _pHead(omBin h, poly a); |
---|
328 | extern poly _pHead0(poly a); |
---|
329 | extern poly _pShallowCopyDeleteHead(omBin d_h, poly *s_p, omBin s_h); |
---|
330 | extern poly _pShallowCopyDelete(omBin d_h, poly *s_p, omBin s_h); |
---|
331 | #define _pCopy2(p1, p2) omMemcpyW(p1, p2, pMonomSizeW) |
---|
332 | |
---|
333 | |
---|
334 | /*************************************************************** |
---|
335 | * |
---|
336 | * Routines which work on vectors instead of single exponents |
---|
337 | * |
---|
338 | ***************************************************************/ |
---|
339 | // Here is a handy Macro which disables inlining when run with |
---|
340 | // profiling and enables it otherwise |
---|
341 | |
---|
342 | #ifdef DO_DEEP_PROFILE |
---|
343 | |
---|
344 | #ifndef POLYS_IMPL_CC |
---|
345 | |
---|
346 | #define DECLARE(type, arglist) type arglist; \ |
---|
347 | static type dummy_##arglist |
---|
348 | #else |
---|
349 | #define DECLARE(type, arglist) type arglist |
---|
350 | #endif // POLYS_IMPL_CC |
---|
351 | |
---|
352 | #else //! DO_DEEP_PROFILE |
---|
353 | |
---|
354 | #define DECLARE(type, arglist ) inline type arglist |
---|
355 | |
---|
356 | #endif // DO_DEEP_PROFILE |
---|
357 | |
---|
358 | |
---|
359 | #if defined(PDEBUG) && PDEBUG > 1 |
---|
360 | #define _pMonAddOn(p1, p2) pDBMonAddOn(p1, p2, __FILE__, __LINE__) |
---|
361 | extern void pDBMonAddOn(poly p1, poly p2, char* f, int l); |
---|
362 | inline void __pMonAddOn(poly p1, poly p2) |
---|
363 | #else |
---|
364 | DECLARE(void, _pMonAddOn(poly p1, poly p2)) |
---|
365 | #endif // defined(PDEBUG) && PDEBUG > 1 |
---|
366 | { |
---|
367 | int i = currRing->ExpLSize; |
---|
368 | unsigned long* s1 = &(p1->exp.l[0]); |
---|
369 | const unsigned long* s2 = &(p2->exp.l[0]); |
---|
370 | for (;;) |
---|
371 | { |
---|
372 | *s1 += *s2; |
---|
373 | i--; |
---|
374 | if (i==0) break; |
---|
375 | s1++; |
---|
376 | s2++; |
---|
377 | } |
---|
378 | } |
---|
379 | |
---|
380 | #if defined(PDEBUG) && PDEBUG > 1 |
---|
381 | #define _pMonSubFrom(p1, p2) pDBMonSubFrom(p1, p2, __FILE__, __LINE__) |
---|
382 | extern void pDBMonSubFrom(poly p1, poly p2, char* f, int l); |
---|
383 | inline void __pMonSubFrom(poly p1, poly p2) |
---|
384 | #else |
---|
385 | DECLARE(void, _pMonSubFrom(poly p1, poly p2)) |
---|
386 | #endif // defined(PDEBUG) && PDEBUG > 1 |
---|
387 | { |
---|
388 | int i = currRing->ExpLSize; |
---|
389 | unsigned long* s1 = &(p1->exp.l[0]); |
---|
390 | const unsigned long* s2 = &(p2->exp.l[0]); |
---|
391 | |
---|
392 | for (;;) |
---|
393 | { |
---|
394 | *s1 -= *s2; |
---|
395 | i--; |
---|
396 | if (i==0) break; |
---|
397 | s1++; |
---|
398 | s2++; |
---|
399 | } |
---|
400 | } |
---|
401 | |
---|
402 | // Makes p1 a copy of p2 and adds on exponents of p3 |
---|
403 | #if defined(PDEBUG) && PDEBUG > 1 |
---|
404 | #define _prMonAdd(p1, p2, p3, r) pDBMonAdd(p1, p2, p3, r, __FILE__, __LINE__) |
---|
405 | extern void prDBMonAdd(poly p1, poly p2, poly p3, ring r, char* f, int l); |
---|
406 | inline void __prMonAdd(poly p1, poly p2, poly p3, ring r) |
---|
407 | #else |
---|
408 | DECLARE(void, _prMonAdd(poly p1, poly p2, poly p3, ring r)) |
---|
409 | #endif // defined(PDEBUG) && PDEBUG > 1 |
---|
410 | { |
---|
411 | unsigned long* s1 = &(p1->exp.l[0]); |
---|
412 | const unsigned long* s2 = &(p2->exp.l[0]); |
---|
413 | const unsigned long* s3 = &(p3->exp.l[0]); |
---|
414 | const unsigned long* const ub = s3 + r->ExpLSize; |
---|
415 | |
---|
416 | for (;;) |
---|
417 | { |
---|
418 | *s1 = *s2 + *s3; |
---|
419 | s3++; |
---|
420 | if (s3 == ub) break; |
---|
421 | s1++; |
---|
422 | s2++; |
---|
423 | } |
---|
424 | } |
---|
425 | |
---|
426 | |
---|
427 | #if SIZEOF_LONG == 4 |
---|
428 | |
---|
429 | #if SIZEOF_EXPONENT == 1 |
---|
430 | #define P_DIV_MASK 0x80808080 |
---|
431 | #define EXPONENT_MAX 0x7f |
---|
432 | #else // SIZEOF_EXPONENT == 2 |
---|
433 | #define P_DIV_MASK 0x80008000 |
---|
434 | #define EXPONENT_MAX 0x7fff |
---|
435 | #endif |
---|
436 | |
---|
437 | #else // SIZEOF_LONG == 8 |
---|
438 | |
---|
439 | #if SIZEOF_EXPONENT == 1 |
---|
440 | #define P_DIV_MASK 0x8080808080808080 |
---|
441 | #define EXPONENT_MAX 0x7f |
---|
442 | #elif SIZEOF_EXPONENT == 2 |
---|
443 | #define P_DIV_MASK 0x8000800080008000 |
---|
444 | #define EXPONENT_MAX 0x7fff |
---|
445 | #else // SIZEOF_EXPONENT == 4 |
---|
446 | #define P_DIV_MASK 0x8000000080000000 |
---|
447 | #define EXPONENT_MAX 0x7fffffff |
---|
448 | #endif |
---|
449 | |
---|
450 | #endif |
---|
451 | |
---|
452 | // #define LONG_MONOMS |
---|
453 | |
---|
454 | #ifdef LONG_MONOMS |
---|
455 | DECLARE(BOOLEAN, __pDivisibleBy(poly a, poly b)) |
---|
456 | { |
---|
457 | const unsigned long* const lb = (unsigned long*) &(a->exp.l[currRing->pDivLow]); |
---|
458 | const unsigned long* s1 = (unsigned long*) &(a->exp.l[currRing->pDivHigh]); |
---|
459 | const unsigned long* s2 = (unsigned long*) &(b->exp.l[currRing->pDivHigh]); |
---|
460 | |
---|
461 | for (;;) |
---|
462 | { |
---|
463 | // Yes, the following is correct, provided that the exponents do |
---|
464 | // not have their first bit set |
---|
465 | if ((*s2 - *s1) & P_DIV_MASK) return FALSE; |
---|
466 | if (s1 == lb) return TRUE; |
---|
467 | s1--; |
---|
468 | s2--; |
---|
469 | } |
---|
470 | } |
---|
471 | #else |
---|
472 | DECLARE(BOOLEAN, __pDivisibleBy(poly a, poly b)) |
---|
473 | { |
---|
474 | int i=pVariables; // assume i>0 |
---|
475 | |
---|
476 | for (;;) |
---|
477 | { |
---|
478 | if (_pGetExp(a,i) > _pGetExp(b,i)) |
---|
479 | return FALSE; |
---|
480 | i--; |
---|
481 | if (i==0) |
---|
482 | return TRUE; |
---|
483 | } |
---|
484 | } |
---|
485 | #endif |
---|
486 | |
---|
487 | #if defined(PDEBUG) && PDEBUG > 1 |
---|
488 | #define _pDivisibleBy(a,b) pDBDivisibleBy(a, b, __FILE__, __LINE__) |
---|
489 | extern BOOLEAN pDBDivisibleBy(poly p1, poly p2, char* f, int l); |
---|
490 | inline BOOLEAN _pDivisibleBy_orig(poly a, poly b) |
---|
491 | #else |
---|
492 | inline BOOLEAN _pDivisibleBy(poly a, poly b) |
---|
493 | #endif // defined(PDEBUG) && PDEBUG > 1 |
---|
494 | { |
---|
495 | if ((a!=NULL)&&((_pGetComp(a)==0) || (_pGetComp(a) == _pGetComp(b)))) |
---|
496 | { |
---|
497 | return __pDivisibleBy(a,b); |
---|
498 | } |
---|
499 | return FALSE; |
---|
500 | } |
---|
501 | |
---|
502 | #if defined(PDEBUG) && PDEBUG > 1 |
---|
503 | #define _pDivisibleBy1(a,b) pDBDivisibleBy1(a, b, __FILE__, __LINE__) |
---|
504 | extern BOOLEAN pDBDivisibleBy1(poly p1, poly p2, char* f, int l); |
---|
505 | inline BOOLEAN _pDivisibleBy1_orig(poly a, poly b) |
---|
506 | #else |
---|
507 | inline BOOLEAN _pDivisibleBy1(poly a, poly b) |
---|
508 | #endif // defined(PDEBUG) && PDEBUG > 1 |
---|
509 | { |
---|
510 | if (_pGetComp(a) == 0 || _pGetComp(a) == _pGetComp(b)) |
---|
511 | return __pDivisibleBy(a,b); |
---|
512 | return FALSE; |
---|
513 | } |
---|
514 | |
---|
515 | #if defined(PDEBUG) && PDEBUG > 1 |
---|
516 | #define _pDivisibleBy2(a,b) pDBDivisibleBy2(a, b, __FILE__, __LINE__) |
---|
517 | extern BOOLEAN pDBDivisibleBy2(poly p1, poly p2, char* f, int l); |
---|
518 | #else |
---|
519 | #define _pDivisibleBy2(a,b) __pDivisibleBy(a,b) |
---|
520 | #endif // defined(PDEBUG) && PDEBUG > 1 |
---|
521 | |
---|
522 | #ifdef PDEBUG |
---|
523 | #define _pEqual(p, q) mmDBEqual(p, q, __FILE__, __LINE__) |
---|
524 | BOOLEAN mmDBEqual(poly p, poly q, char* file, int line); |
---|
525 | #else |
---|
526 | #define _pEqual __pEqual |
---|
527 | #endif |
---|
528 | |
---|
529 | DECLARE(BOOLEAN, __pEqual(poly p1, poly p2)) |
---|
530 | { |
---|
531 | const unsigned long *s1 = (unsigned long*) &(p1->exp.l[0]); |
---|
532 | const unsigned long *s2 = (unsigned long*) &(p2->exp.l[0]); |
---|
533 | const unsigned long* const lb = s1 + currRing->ExpLSize; |
---|
534 | |
---|
535 | for(;;) |
---|
536 | { |
---|
537 | if (*s1 != *s2) return FALSE; |
---|
538 | s1++; |
---|
539 | if (s1 == lb) return TRUE; |
---|
540 | s2++; |
---|
541 | } |
---|
542 | } |
---|
543 | |
---|
544 | /*************************************************************** |
---|
545 | * |
---|
546 | * Misc. things |
---|
547 | * |
---|
548 | * |
---|
549 | ***************************************************************/ |
---|
550 | // Divisiblity tests based on Short Exponent Vectors |
---|
551 | // define to enable debugging of this |
---|
552 | // #define PDIV_DEBUG |
---|
553 | #if defined(PDEBUG) && ! defined(PDIV_DEBUG) |
---|
554 | #define PDIV_DEBUG |
---|
555 | #endif |
---|
556 | |
---|
557 | #ifdef PDIV_DEBUG |
---|
558 | #define _pShortDivisibleBy(a, sev_a, b, not_sev_b) \ |
---|
559 | pDBShortDivisibleBy(a, sev_a, b, not_sev_b, __FILE__, __LINE__) |
---|
560 | BOOLEAN pDBShortDivisibleBy(poly p1, unsigned long sev_1, |
---|
561 | poly p2, unsigned long not_sev_2, |
---|
562 | char* f, int l); |
---|
563 | #else |
---|
564 | #define _pShortDivisibleBy(a, sev_a, b, not_sev_b) \ |
---|
565 | ( ! (sev_a & not_sev_b) && pDivisibleBy(a, b)) |
---|
566 | #endif |
---|
567 | |
---|
568 | |
---|
569 | /*************************************************************** |
---|
570 | * |
---|
571 | * Routines which implement low-level manipulations/operations |
---|
572 | * on exponents and "are allowed" to access single exponetns |
---|
573 | * |
---|
574 | ***************************************************************/ |
---|
575 | |
---|
576 | #ifdef LONG_MONOMS |
---|
577 | DECLARE(int, __pExpQuerSum2(poly p, int from, int to)) |
---|
578 | { |
---|
579 | int j = 0; |
---|
580 | int i = from ; |
---|
581 | |
---|
582 | for(;;) |
---|
583 | { |
---|
584 | if (i > to) break; |
---|
585 | j += p->exp.e[i]; |
---|
586 | i++; |
---|
587 | } |
---|
588 | if (from <= _pCompIndex && to >= _pCompIndex) |
---|
589 | return j - _pGetComp(p); |
---|
590 | return j; |
---|
591 | } |
---|
592 | |
---|
593 | #define _pExpQuerSum(p) __pExpQuerSum2(p, currRing->pVarLowIndex, currRing->pVarHighIndex) |
---|
594 | |
---|
595 | inline int _pExpQuerSum2(poly p,int from,int to) |
---|
596 | { |
---|
597 | int ei_to = _pExpIndex(to); |
---|
598 | int ei_from = _pExpIndex(from); |
---|
599 | |
---|
600 | if (ei_from > ei_to) |
---|
601 | return __pExpQuerSum2(p, ei_to, ei_from); |
---|
602 | else |
---|
603 | return __pExpQuerSum2(p, ei_from, ei_to); |
---|
604 | } |
---|
605 | |
---|
606 | #else |
---|
607 | DECLARE(int, _pExpQuerSum(poly p)) |
---|
608 | { |
---|
609 | int s = 0; |
---|
610 | int i = pVariables; |
---|
611 | for (;;) |
---|
612 | { |
---|
613 | s += _pGetExp(p, i); |
---|
614 | i--; |
---|
615 | if (i==0) return s; |
---|
616 | } |
---|
617 | } |
---|
618 | #endif |
---|
619 | |
---|
620 | #endif // POLYS_IMPL_H |
---|