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