1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /*************************************************************** |
---|
5 | * File: pInline1.h |
---|
6 | * Purpose: implementation of poly procs which iter over ExpVector |
---|
7 | * Author: obachman (Olaf Bachmann) |
---|
8 | * Created: 8/00 |
---|
9 | * Version: $Id$ |
---|
10 | *******************************************************************/ |
---|
11 | #ifndef PINLINE1_H |
---|
12 | #define PINLINE1_H |
---|
13 | |
---|
14 | #ifndef PDIV_DEBUG |
---|
15 | // define to enable debugging/statistics of pLmShortDivisibleBy |
---|
16 | // #define PDIV_DEBUG |
---|
17 | #endif |
---|
18 | #include <mylimits.h> |
---|
19 | #include "p_MemCmp.h" |
---|
20 | #include "structs.h" |
---|
21 | #include "ring.h" |
---|
22 | #include <coeffs.h> |
---|
23 | |
---|
24 | #if PDEBUG > 0 || defined(NO_PINLINE1) |
---|
25 | |
---|
26 | #define _p_LmCmpAction(p, q, r, actionE, actionG, actionS) \ |
---|
27 | do \ |
---|
28 | { \ |
---|
29 | int _cmp = p_LmCmp(p,q,r); \ |
---|
30 | if (_cmp == 0) actionE; \ |
---|
31 | if (_cmp == 1) actionG; \ |
---|
32 | actionS; \ |
---|
33 | } \ |
---|
34 | while(0) |
---|
35 | |
---|
36 | #else |
---|
37 | |
---|
38 | #define _p_LmCmpAction(p, q, r, actionE, actionG, actionS) \ |
---|
39 | p_MemCmp_LengthGeneral_OrdGeneral(p->exp, q->exp, r->CmpL_Size, r->ordsgn, \ |
---|
40 | actionE, actionG, actionS) |
---|
41 | |
---|
42 | #endif |
---|
43 | |
---|
44 | #ifdef PDIV_DEBUG |
---|
45 | BOOLEAN pDebugLmShortDivisibleBy(poly p1, unsigned long sev_1, const ring r_1, |
---|
46 | poly p2, unsigned long not_sev_2, const ring r_2); |
---|
47 | BOOLEAN p_DebugLmDivisibleByNoComp(poly a, poly b, const ring r); |
---|
48 | #define pDivAssume pAssume |
---|
49 | #else |
---|
50 | #define pDivAssume(x) ((void)0) |
---|
51 | #endif |
---|
52 | |
---|
53 | #if !defined(NO_PINLINE1) || defined(PINLINE1_CC) |
---|
54 | |
---|
55 | #include <omalloc.h> |
---|
56 | #include <coeffs.h> |
---|
57 | #include "p_polys.h" |
---|
58 | #include "p_MemAdd.h" |
---|
59 | #include "p_MemCopy.h" |
---|
60 | |
---|
61 | /*************************************************************** |
---|
62 | * |
---|
63 | * Allocation/Initalization/Deletion |
---|
64 | * |
---|
65 | ***************************************************************/ |
---|
66 | // adjustments for negative weights |
---|
67 | PINLINE1 void p_MemAdd_NegWeightAdjust(poly p, const ring r) |
---|
68 | { |
---|
69 | if (r->NegWeightL_Offset != NULL) |
---|
70 | { |
---|
71 | for (int i=r->NegWeightL_Size-1; i>=0; i--) |
---|
72 | { |
---|
73 | p->exp[r->NegWeightL_Offset[i]] -= POLY_NEGWEIGHT_OFFSET; |
---|
74 | } |
---|
75 | } |
---|
76 | } |
---|
77 | PINLINE1 void p_MemSub_NegWeightAdjust(poly p, const ring r) |
---|
78 | { |
---|
79 | if (r->NegWeightL_Offset != NULL) |
---|
80 | { |
---|
81 | for (int i=r->NegWeightL_Size-1; i>=0; i--) |
---|
82 | { |
---|
83 | p->exp[r->NegWeightL_Offset[i]] += POLY_NEGWEIGHT_OFFSET; |
---|
84 | } |
---|
85 | } |
---|
86 | } |
---|
87 | // ExpVextor(d_p) = ExpVector(s_p) |
---|
88 | PINLINE1 void p_ExpVectorCopy(poly d_p, poly s_p, const ring r) |
---|
89 | { |
---|
90 | p_LmCheckPolyRing1(d_p, r); |
---|
91 | p_LmCheckPolyRing1(s_p, r); |
---|
92 | p_MemCopy_LengthGeneral(d_p->exp, s_p->exp, r->ExpL_Size); |
---|
93 | } |
---|
94 | |
---|
95 | PINLINE1 poly p_Init(const ring r, omBin bin) |
---|
96 | { |
---|
97 | p_CheckRing1(r); |
---|
98 | pAssume1(bin != NULL && omSizeWOfBin(r->PolyBin) == omSizeWOfBin(bin)); |
---|
99 | poly p; |
---|
100 | omTypeAlloc0Bin(poly, p, bin); |
---|
101 | p_MemAdd_NegWeightAdjust(p, r); |
---|
102 | p_SetRingOfLm(p, r); |
---|
103 | return p; |
---|
104 | } |
---|
105 | PINLINE1 poly p_Init(const ring r) |
---|
106 | { |
---|
107 | return p_Init(r, r->PolyBin); |
---|
108 | } |
---|
109 | |
---|
110 | PINLINE1 poly p_LmInit(poly p, const ring r) |
---|
111 | { |
---|
112 | p_LmCheckPolyRing1(p, r); |
---|
113 | poly np; |
---|
114 | omTypeAllocBin(poly, np, r->PolyBin); |
---|
115 | p_SetRingOfLm(np, r); |
---|
116 | p_MemCopy_LengthGeneral(np->exp, p->exp, r->ExpL_Size); |
---|
117 | pNext(np) = NULL; |
---|
118 | pSetCoeff0(np, NULL); |
---|
119 | return np; |
---|
120 | } |
---|
121 | PINLINE1 poly p_LmInit(poly s_p, const ring s_r, const ring d_r, omBin d_bin) |
---|
122 | { |
---|
123 | p_LmCheckPolyRing1(s_p, s_r); |
---|
124 | p_CheckRing(d_r); |
---|
125 | pAssume1(d_r->N <= s_r->N); |
---|
126 | poly d_p = p_Init(d_r, d_bin); |
---|
127 | for (int i=d_r->N; i>0; i--) |
---|
128 | { |
---|
129 | p_SetExp(d_p, i, p_GetExp(s_p, i,s_r), d_r); |
---|
130 | } |
---|
131 | if (rRing_has_Comp(d_r)) |
---|
132 | { |
---|
133 | p_SetComp(d_p, p_GetComp(s_p,s_r), d_r); |
---|
134 | } |
---|
135 | p_Setm(d_p, d_r); |
---|
136 | return d_p; |
---|
137 | } |
---|
138 | PINLINE1 poly p_LmInit(poly s_p, const ring s_r, const ring d_r) |
---|
139 | { |
---|
140 | pAssume1(d_r != NULL); |
---|
141 | return p_LmInit(s_p, s_r, d_r, d_r->PolyBin); |
---|
142 | } |
---|
143 | PINLINE1 poly p_Head(poly p, const ring r) |
---|
144 | { |
---|
145 | if (p == NULL) return NULL; |
---|
146 | p_LmCheckPolyRing1(p, r); |
---|
147 | poly np; |
---|
148 | omTypeAllocBin(poly, np, r->PolyBin); |
---|
149 | p_SetRingOfLm(np, r); |
---|
150 | p_MemCopy_LengthGeneral(np->exp, p->exp, r->ExpL_Size); |
---|
151 | pNext(np) = NULL; |
---|
152 | pSetCoeff0(np, n_Copy(pGetCoeff(p), r)); |
---|
153 | return np; |
---|
154 | } |
---|
155 | // set all exponents l..k to 0, assume exp. k+1..n and 1..l-1 are in |
---|
156 | // different blocks |
---|
157 | // set coeff to 1 |
---|
158 | PINLINE1 poly p_GetExp_k_n(poly p, int l, int k, const ring r) |
---|
159 | { |
---|
160 | if (p == NULL) return NULL; |
---|
161 | p_LmCheckPolyRing1(p, r); |
---|
162 | poly np; |
---|
163 | omTypeAllocBin(poly, np, r->PolyBin); |
---|
164 | p_SetRingOfLm(np, r); |
---|
165 | p_MemCopy_LengthGeneral(np->exp, p->exp, r->ExpL_Size); |
---|
166 | pNext(np) = NULL; |
---|
167 | pSetCoeff0(np, n_Init(1, r)); |
---|
168 | int i; |
---|
169 | for(i=l;i<=k;i++) |
---|
170 | { |
---|
171 | //np->exp[(r->VarOffset[i] & 0xffffff)] =0; |
---|
172 | p_SetExp(np,i,0,r); |
---|
173 | } |
---|
174 | p_Setm(np,r); |
---|
175 | return np; |
---|
176 | } |
---|
177 | |
---|
178 | /*************************************************************** |
---|
179 | * |
---|
180 | * Operation on ExpVectors |
---|
181 | * |
---|
182 | ***************************************************************/ |
---|
183 | // ExpVector(p1) += ExpVector(p2) |
---|
184 | PINLINE1 void p_ExpVectorAdd(poly p1, poly p2, const ring r) |
---|
185 | { |
---|
186 | p_LmCheckPolyRing1(p1, r); |
---|
187 | p_LmCheckPolyRing1(p2, r); |
---|
188 | #if PDEBUG >= 1 |
---|
189 | for (int i=1; i<=r->N; i++) |
---|
190 | pAssume1((unsigned long) (p_GetExp(p1, i, r) + p_GetExp(p2, i, r)) <= r->bitmask); |
---|
191 | pAssume1(p_GetComp(p1, r) == 0 || p_GetComp(p2, r) == 0); |
---|
192 | #endif |
---|
193 | |
---|
194 | p_MemAdd_LengthGeneral(p1->exp, p2->exp, r->ExpL_Size); |
---|
195 | p_MemAdd_NegWeightAdjust(p1, r); |
---|
196 | } |
---|
197 | // ExpVector(p1) -= ExpVector(p2) |
---|
198 | PINLINE1 void p_ExpVectorSub(poly p1, poly p2, const ring r) |
---|
199 | { |
---|
200 | p_LmCheckPolyRing1(p1, r); |
---|
201 | p_LmCheckPolyRing1(p2, r); |
---|
202 | #if PDEBUG >= 1 |
---|
203 | for (int i=1; i<=r->N; i++) |
---|
204 | pAssume1(p_GetExp(p1, i, r) >= p_GetExp(p2, i, r)); |
---|
205 | pAssume1(p_GetComp(p1, r) == 0 || p_GetComp(p2, r) == 0 || |
---|
206 | p_GetComp(p1, r) == p_GetComp(p2, r)); |
---|
207 | #endif |
---|
208 | |
---|
209 | p_MemSub_LengthGeneral(p1->exp, p2->exp, r->ExpL_Size); |
---|
210 | p_MemSub_NegWeightAdjust(p1, r); |
---|
211 | |
---|
212 | } |
---|
213 | // ExpVector(p1) += ExpVector(p2) - ExpVector(p3) |
---|
214 | PINLINE1 void p_ExpVectorAddSub(poly p1, poly p2, poly p3, const ring r) |
---|
215 | { |
---|
216 | p_LmCheckPolyRing1(p1, r); |
---|
217 | p_LmCheckPolyRing1(p2, r); |
---|
218 | p_LmCheckPolyRing1(p3, r); |
---|
219 | #if PDEBUG >= 1 |
---|
220 | for (int i=1; i<=r->N; i++) |
---|
221 | pAssume1(p_GetExp(p1, i, r) + p_GetExp(p2, i, r) >= p_GetExp(p3, i, r)); |
---|
222 | pAssume1(p_GetComp(p1, r) == 0 || |
---|
223 | (p_GetComp(p2, r) - p_GetComp(p3, r) == 0) || |
---|
224 | (p_GetComp(p1, r) == p_GetComp(p2, r) - p_GetComp(p3, r))); |
---|
225 | #endif |
---|
226 | |
---|
227 | p_MemAddSub_LengthGeneral(p1->exp, p2->exp, p3->exp, r->ExpL_Size); |
---|
228 | // no need to adjust in case of NegWeights |
---|
229 | } |
---|
230 | |
---|
231 | // ExpVector(pr) = ExpVector(p1) + ExpVector(p2) |
---|
232 | PINLINE1 void p_ExpVectorSum(poly pr, poly p1, poly p2, const ring r) |
---|
233 | { |
---|
234 | p_LmCheckPolyRing1(p1, r); |
---|
235 | p_LmCheckPolyRing1(p2, r); |
---|
236 | p_LmCheckPolyRing1(pr, r); |
---|
237 | #if PDEBUG >= 1 |
---|
238 | for (int i=1; i<=r->N; i++) |
---|
239 | pAssume1((unsigned long) (p_GetExp(p1, i, r) + p_GetExp(p2, i, r)) <= r->bitmask); |
---|
240 | pAssume1(p_GetComp(p1, r) == 0 || p_GetComp(p2, r) == 0); |
---|
241 | #endif |
---|
242 | |
---|
243 | p_MemSum_LengthGeneral(pr->exp, p1->exp, p2->exp, r->ExpL_Size); |
---|
244 | p_MemAdd_NegWeightAdjust(pr, r); |
---|
245 | } |
---|
246 | // ExpVector(pr) = ExpVector(p1) - ExpVector(p2) |
---|
247 | PINLINE1 void p_ExpVectorDiff(poly pr, poly p1, poly p2, const ring r) |
---|
248 | { |
---|
249 | p_LmCheckPolyRing1(p1, r); |
---|
250 | p_LmCheckPolyRing1(p2, r); |
---|
251 | p_LmCheckPolyRing1(pr, r); |
---|
252 | #if PDEBUG >= 2 |
---|
253 | for (int i=1; i<=r->N; i++) |
---|
254 | pAssume1(p_GetExp(p1, i, r) >= p_GetExp(p2, i, r)); |
---|
255 | pAssume1(!rRing_has_Comp(r) || p_GetComp(p1, r) == p_GetComp(p2, r)); |
---|
256 | #endif |
---|
257 | |
---|
258 | p_MemDiff_LengthGeneral(pr->exp, p1->exp, p2->exp, r->ExpL_Size); |
---|
259 | p_MemSub_NegWeightAdjust(pr, r); |
---|
260 | } |
---|
261 | |
---|
262 | PINLINE1 BOOLEAN p_ExpVectorEqual(poly p1, poly p2, const ring r) |
---|
263 | { |
---|
264 | p_LmCheckPolyRing1(p1, r); |
---|
265 | p_LmCheckPolyRing1(p2, r); |
---|
266 | |
---|
267 | int i = r->ExpL_Size; |
---|
268 | unsigned long *ep = p1->exp; |
---|
269 | unsigned long *eq = p2->exp; |
---|
270 | |
---|
271 | do |
---|
272 | { |
---|
273 | i--; |
---|
274 | if (ep[i] != eq[i]) return FALSE; |
---|
275 | } |
---|
276 | while (i); |
---|
277 | return TRUE; |
---|
278 | } |
---|
279 | |
---|
280 | PINLINE1 long p_Totaldegree(poly p, const ring r) |
---|
281 | { |
---|
282 | p_LmCheckPolyRing1(p, r); |
---|
283 | unsigned long s = p_GetTotalDegree(p->exp[r->VarL_Offset[0]], |
---|
284 | r, |
---|
285 | r->MinExpPerLong); |
---|
286 | for (int i=r->VarL_Size-1; i>0; i--) |
---|
287 | { |
---|
288 | s += p_GetTotalDegree(p->exp[r->VarL_Offset[i]], r); |
---|
289 | } |
---|
290 | return (long)s; |
---|
291 | } |
---|
292 | |
---|
293 | PINLINE1 void p_GetExpV(poly p, int *ev, const ring r) |
---|
294 | { |
---|
295 | p_LmCheckPolyRing1(p, r); |
---|
296 | for (int j = r->N; j; j--) |
---|
297 | ev[j] = p_GetExp(p, j, r); |
---|
298 | |
---|
299 | ev[0] = p_GetComp(p, r); |
---|
300 | } |
---|
301 | PINLINE1 void p_SetExpV(poly p, int *ev, const ring r) |
---|
302 | { |
---|
303 | p_LmCheckPolyRing1(p, r); |
---|
304 | for (int j = r->N; j; j--) |
---|
305 | p_SetExp(p, j, ev[j], r); |
---|
306 | |
---|
307 | p_SetComp(p, ev[0],r); |
---|
308 | p_Setm(p, r); |
---|
309 | } |
---|
310 | |
---|
311 | /*************************************************************** |
---|
312 | * |
---|
313 | * Comparison w.r.t. monomial ordering |
---|
314 | * |
---|
315 | ***************************************************************/ |
---|
316 | PINLINE1 int p_LmCmp(poly p, poly q, const ring r) |
---|
317 | { |
---|
318 | p_LmCheckPolyRing1(p, r); |
---|
319 | p_LmCheckPolyRing1(q, r); |
---|
320 | |
---|
321 | p_MemCmp_LengthGeneral_OrdGeneral(p->exp, q->exp, r->CmpL_Size, r->ordsgn, |
---|
322 | return 0, return 1, return -1); |
---|
323 | } |
---|
324 | |
---|
325 | |
---|
326 | /*************************************************************** |
---|
327 | * |
---|
328 | * divisibility |
---|
329 | * |
---|
330 | ***************************************************************/ |
---|
331 | // return: FALSE, if there exists i, such that a->exp[i] > b->exp[i] |
---|
332 | // TRUE, otherwise |
---|
333 | // (1) Consider long vars, instead of single exponents |
---|
334 | // (2) Clearly, if la > lb, then FALSE |
---|
335 | // (3) Suppose la <= lb, and consider first bits of single exponents in l: |
---|
336 | // if TRUE, then value of these bits is la ^ lb |
---|
337 | // if FALSE, then la-lb causes an "overflow" into one of those bits, i.e., |
---|
338 | // la ^ lb != la - lb |
---|
339 | static inline BOOLEAN _p_LmDivisibleByNoComp(poly a, poly b, const ring r) |
---|
340 | { |
---|
341 | int i=r->VarL_Size - 1; |
---|
342 | unsigned long divmask = r->divmask; |
---|
343 | unsigned long la, lb; |
---|
344 | |
---|
345 | if (r->VarL_LowIndex >= 0) |
---|
346 | { |
---|
347 | i += r->VarL_LowIndex; |
---|
348 | do |
---|
349 | { |
---|
350 | la = a->exp[i]; |
---|
351 | lb = b->exp[i]; |
---|
352 | if ((la > lb) || |
---|
353 | (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask))) |
---|
354 | { |
---|
355 | pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == FALSE); |
---|
356 | return FALSE; |
---|
357 | } |
---|
358 | i--; |
---|
359 | } |
---|
360 | while (i>=r->VarL_LowIndex); |
---|
361 | } |
---|
362 | else |
---|
363 | { |
---|
364 | do |
---|
365 | { |
---|
366 | la = a->exp[r->VarL_Offset[i]]; |
---|
367 | lb = b->exp[r->VarL_Offset[i]]; |
---|
368 | if ((la > lb) || |
---|
369 | (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask))) |
---|
370 | { |
---|
371 | pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == FALSE); |
---|
372 | return FALSE; |
---|
373 | } |
---|
374 | i--; |
---|
375 | } |
---|
376 | while (i>=0); |
---|
377 | } |
---|
378 | #ifdef HAVE_RINGS |
---|
379 | pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == nDivBy(p_GetCoeff(b, r), p_GetCoeff(a, r))); |
---|
380 | return (!rField_is_Ring(r)) || nDivBy(p_GetCoeff(b, r), p_GetCoeff(a, r)); |
---|
381 | #else |
---|
382 | pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == TRUE); |
---|
383 | return TRUE; |
---|
384 | #endif |
---|
385 | } |
---|
386 | |
---|
387 | static inline BOOLEAN _p_LmDivisibleByNoComp(poly a, const ring r_a, poly b, const ring r_b) |
---|
388 | { |
---|
389 | int i=r_a->N; |
---|
390 | pAssume1(r_a->N == r_b->N); |
---|
391 | |
---|
392 | do |
---|
393 | { |
---|
394 | if (p_GetExp(a,i,r_a) > p_GetExp(b,i,r_b)) |
---|
395 | return FALSE; |
---|
396 | i--; |
---|
397 | } |
---|
398 | while (i); |
---|
399 | #ifdef HAVE_RINGS |
---|
400 | return nDivBy(p_GetCoeff(b, r), p_GetCoeff(a, r)); |
---|
401 | #else |
---|
402 | return TRUE; |
---|
403 | #endif |
---|
404 | } |
---|
405 | |
---|
406 | #ifdef HAVE_RATGRING |
---|
407 | static inline BOOLEAN _p_LmDivisibleByNoCompPart(poly a, const ring r_a, poly b, const ring r_b,const int start, const int end) |
---|
408 | { |
---|
409 | int i=end; |
---|
410 | pAssume1(r_a->N == r_b->N); |
---|
411 | |
---|
412 | do |
---|
413 | { |
---|
414 | if (p_GetExp(a,i,r_a) > p_GetExp(b,i,r_b)) |
---|
415 | return FALSE; |
---|
416 | i--; |
---|
417 | } |
---|
418 | while (i>=start); |
---|
419 | #ifdef HAVE_RINGS |
---|
420 | return nDivBy(p_GetCoeff(b, r), p_GetCoeff(a, r)); |
---|
421 | #else |
---|
422 | return TRUE; |
---|
423 | #endif |
---|
424 | } |
---|
425 | static inline BOOLEAN _p_LmDivisibleByPart(poly a, const ring r_a, poly b, const ring r_b,const int start, const int end) |
---|
426 | { |
---|
427 | if (p_GetComp(a, r_a) == 0 || p_GetComp(a,r_a) == p_GetComp(b,r_b)) |
---|
428 | return _p_LmDivisibleByNoCompPart(a, r_a, b, r_b,start,end); |
---|
429 | return FALSE; |
---|
430 | } |
---|
431 | PINLINE1 BOOLEAN p_LmDivisibleByPart(poly a, poly b, const ring r,const int start, const int end) |
---|
432 | { |
---|
433 | p_LmCheckPolyRing1(b, r); |
---|
434 | pIfThen1(a != NULL, p_LmCheckPolyRing1(b, r)); |
---|
435 | if (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r)) |
---|
436 | return _p_LmDivisibleByNoCompPart(a, r, b, r,start, end); |
---|
437 | return FALSE; |
---|
438 | } |
---|
439 | #endif |
---|
440 | static inline BOOLEAN _p_LmDivisibleBy(poly a, poly b, const ring r) |
---|
441 | { |
---|
442 | if (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r)) |
---|
443 | return _p_LmDivisibleByNoComp(a, b, r); |
---|
444 | return FALSE; |
---|
445 | } |
---|
446 | static inline BOOLEAN _p_LmDivisibleBy(poly a, const ring r_a, poly b, const ring r_b) |
---|
447 | { |
---|
448 | if (p_GetComp(a, r_a) == 0 || p_GetComp(a,r_a) == p_GetComp(b,r_b)) |
---|
449 | return _p_LmDivisibleByNoComp(a, r_a, b, r_b); |
---|
450 | return FALSE; |
---|
451 | } |
---|
452 | PINLINE1 BOOLEAN p_LmDivisibleByNoComp(poly a, poly b, const ring r) |
---|
453 | { |
---|
454 | p_LmCheckPolyRing1(a, r); |
---|
455 | p_LmCheckPolyRing1(b, r); |
---|
456 | return _p_LmDivisibleByNoComp(a, b, r); |
---|
457 | } |
---|
458 | PINLINE1 BOOLEAN p_LmDivisibleBy(poly a, poly b, const ring r) |
---|
459 | { |
---|
460 | p_LmCheckPolyRing1(b, r); |
---|
461 | pIfThen1(a != NULL, p_LmCheckPolyRing1(b, r)); |
---|
462 | if (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r)) |
---|
463 | return _p_LmDivisibleByNoComp(a, b, r); |
---|
464 | return FALSE; |
---|
465 | } |
---|
466 | |
---|
467 | PINLINE1 BOOLEAN p_DivisibleBy(poly a, poly b, const ring r) |
---|
468 | { |
---|
469 | pIfThen1(b!=NULL, p_LmCheckPolyRing1(b, r)); |
---|
470 | pIfThen1(a!=NULL, p_LmCheckPolyRing1(a, r)); |
---|
471 | |
---|
472 | if (a != NULL && (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r))) |
---|
473 | return _p_LmDivisibleByNoComp(a,b,r); |
---|
474 | return FALSE; |
---|
475 | } |
---|
476 | PINLINE1 BOOLEAN p_DivisibleBy(poly a, const ring r_a, poly b, const ring r_b) |
---|
477 | { |
---|
478 | pIfThen1(b!=NULL, p_LmCheckPolyRing1(b, r_b)); |
---|
479 | pIfThen1(a!=NULL, p_LmCheckPolyRing1(a, r_a)); |
---|
480 | if (a != NULL) { |
---|
481 | return _p_LmDivisibleBy(a, r_a, b, r_b); |
---|
482 | } |
---|
483 | return FALSE; |
---|
484 | } |
---|
485 | PINLINE1 BOOLEAN p_LmDivisibleBy(poly a, const ring r_a, poly b, const ring r_b) |
---|
486 | { |
---|
487 | p_LmCheckPolyRing(a, r_a); |
---|
488 | p_LmCheckPolyRing(b, r_b); |
---|
489 | return _p_LmDivisibleBy(a, r_a, b, r_b); |
---|
490 | } |
---|
491 | PINLINE1 BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a, |
---|
492 | poly b, unsigned long not_sev_b, const ring r) |
---|
493 | { |
---|
494 | p_LmCheckPolyRing1(a, r); |
---|
495 | p_LmCheckPolyRing1(b, r); |
---|
496 | #ifndef PDIV_DEBUG |
---|
497 | pPolyAssume2(p_GetShortExpVector(a, r) == sev_a, a, r); |
---|
498 | pPolyAssume2(p_GetShortExpVector(b, r) == ~ not_sev_b, b, r); |
---|
499 | |
---|
500 | if (sev_a & not_sev_b) |
---|
501 | { |
---|
502 | pAssume1(p_LmDivisibleByNoComp(a, b, r) == FALSE); |
---|
503 | return FALSE; |
---|
504 | } |
---|
505 | return p_LmDivisibleBy(a, b, r); |
---|
506 | #else |
---|
507 | return pDebugLmShortDivisibleBy(a, sev_a, r, b, not_sev_b, r); |
---|
508 | #endif |
---|
509 | } |
---|
510 | |
---|
511 | PINLINE1 BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a, const ring r_a, |
---|
512 | poly b, unsigned long not_sev_b, const ring r_b) |
---|
513 | { |
---|
514 | p_LmCheckPolyRing1(a, r_a); |
---|
515 | p_LmCheckPolyRing1(b, r_b); |
---|
516 | #ifndef PDIV_DEBUG |
---|
517 | pPolyAssume2(p_GetShortExpVector(a, r_a) == sev_a, a, r_a); |
---|
518 | pPolyAssume2(p_GetShortExpVector(b, r_b) == ~ not_sev_b, b, r_b); |
---|
519 | |
---|
520 | if (sev_a & not_sev_b) |
---|
521 | { |
---|
522 | pAssume1(_p_LmDivisibleByNoComp(a, r_a, b, r_b) == FALSE); |
---|
523 | return FALSE; |
---|
524 | } |
---|
525 | return _p_LmDivisibleBy(a, r_a, b, r_b); |
---|
526 | #else |
---|
527 | return pDebugLmShortDivisibleBy(a, sev_a, r_a, b, not_sev_b, r_b); |
---|
528 | #endif |
---|
529 | } |
---|
530 | |
---|
531 | /*************************************************************** |
---|
532 | * |
---|
533 | * Misc things on Lm |
---|
534 | * |
---|
535 | ***************************************************************/ |
---|
536 | // test if the monomial is a constant as a vector component |
---|
537 | // i.e., test if all exponents are zero |
---|
538 | PINLINE1 BOOLEAN p_LmIsConstantComp(const poly p, const ring r) |
---|
539 | { |
---|
540 | //p_LmCheckPolyRing(p, r); |
---|
541 | int i = r->VarL_Size - 1; |
---|
542 | |
---|
543 | do |
---|
544 | { |
---|
545 | if (p->exp[r->VarL_Offset[i]] != 0) |
---|
546 | return FALSE; |
---|
547 | i--; |
---|
548 | } |
---|
549 | while (i >= 0); |
---|
550 | return TRUE; |
---|
551 | } |
---|
552 | // test if monomial is a constant, i.e. if all exponents and the component |
---|
553 | // is zero |
---|
554 | PINLINE1 BOOLEAN p_LmIsConstant(const poly p, const ring r) |
---|
555 | { |
---|
556 | if (p_LmIsConstantComp(p, r)) |
---|
557 | return (p_GetComp(p, r) == 0); |
---|
558 | return FALSE; |
---|
559 | } |
---|
560 | |
---|
561 | // like the respective p_LmIs* routines, except that p might be empty |
---|
562 | PINLINE1 BOOLEAN p_IsConstantComp(const poly p, const ring r) |
---|
563 | { |
---|
564 | if (p == NULL) return TRUE; |
---|
565 | return (pNext(p)==NULL) && p_LmIsConstantComp(p, r); |
---|
566 | } |
---|
567 | |
---|
568 | PINLINE1 BOOLEAN p_IsConstant(const poly p, const ring r) |
---|
569 | { |
---|
570 | if (p == NULL) return TRUE; |
---|
571 | return (pNext(p)==NULL) && p_LmIsConstant(p, r); |
---|
572 | } |
---|
573 | |
---|
574 | PINLINE1 BOOLEAN p_IsUnit(const poly p, const ring r) |
---|
575 | { |
---|
576 | if (p == NULL) return FALSE; |
---|
577 | #ifdef HAVE_RINGS |
---|
578 | if (rField_is_Ring(currRing)) |
---|
579 | return (p_LmIsConstant(p, r) && nIsUnit(pGetCoeff(p))); |
---|
580 | #endif |
---|
581 | return p_LmIsConstant(p, r); |
---|
582 | } |
---|
583 | |
---|
584 | PINLINE1 BOOLEAN p_LmExpVectorAddIsOk(const poly p1, const poly p2, |
---|
585 | const ring r) |
---|
586 | { |
---|
587 | p_LmCheckPolyRing(p1, r); |
---|
588 | p_LmCheckPolyRing(p2, r); |
---|
589 | unsigned long l1, l2, divmask = r->divmask; |
---|
590 | int i; |
---|
591 | |
---|
592 | for (i=0; i<r->VarL_Size; i++) |
---|
593 | { |
---|
594 | l1 = p1->exp[r->VarL_Offset[i]]; |
---|
595 | l2 = p2->exp[r->VarL_Offset[i]]; |
---|
596 | // do the divisiblity trick |
---|
597 | if ( (l1 > ULONG_MAX - l2) || |
---|
598 | (((l1 & divmask) ^ (l2 & divmask)) != ((l1 + l2) & divmask))) |
---|
599 | return FALSE; |
---|
600 | } |
---|
601 | return TRUE; |
---|
602 | } |
---|
603 | #else |
---|
604 | PINLINE1 BOOLEAN p_IsUnit(const poly p, const ring r); |
---|
605 | |
---|
606 | #endif // !defined(NO_PINLINE1) || defined(PINLINE1_CC) |
---|
607 | #endif // PINLINE1_CC |
---|