1 | #ifndef POLYS_H |
---|
2 | #define POLYS_H |
---|
3 | /**************************************** |
---|
4 | * Computer Algebra System SINGULAR * |
---|
5 | ****************************************/ |
---|
6 | /* $Id$ */ |
---|
7 | /* |
---|
8 | * ABSTRACT - all basic methods to manipulate polynomials of the |
---|
9 | currRing |
---|
10 | */ |
---|
11 | |
---|
12 | #include <polys/p_polys.h> |
---|
13 | |
---|
14 | /*************************************************************** |
---|
15 | * |
---|
16 | * Primitives for accessing and setting fields of a poly |
---|
17 | * poly must be != NULL |
---|
18 | * |
---|
19 | ***************************************************************/ |
---|
20 | // deletes old coeff before setting the new one |
---|
21 | #define pSetCoeff(p,n) p_SetCoeff(p,n,currRing) |
---|
22 | |
---|
23 | // Order |
---|
24 | #define pGetOrder(p) p_GetOrder(p, currRing) |
---|
25 | |
---|
26 | // Component |
---|
27 | #define pGetComp(p) _p_GetComp(p, currRing) |
---|
28 | #define pSetComp(p,v) p_SetComp(p,v, currRing) |
---|
29 | |
---|
30 | // Exponent |
---|
31 | #define pGetExp(p,i) p_GetExp(p, i, currRing) |
---|
32 | #define pSetExp(p,i,v) p_SetExp(p, i, v, currRing) |
---|
33 | #define pIncrExp(p,i) p_IncrExp(p,i, currRing) |
---|
34 | #define pDecrExp(p,i) p_DecrExp(p,i, currRing) |
---|
35 | #define pAddExp(p,i,v) p_AddExp(p,i,v, currRing) |
---|
36 | #define pSubExp(p,i,v) p_SubExp(p,i,v, currRing) |
---|
37 | #define pMultExp(p,i,v) p_MultExp(p,i,v, currRing) |
---|
38 | #define pGetExpSum(p1, p2, i) p_GetExpSum(p1, p2, i, currRing) |
---|
39 | #define pGetExpDiff(p1, p2, i) p_GetExpDiff(p1, p2, i, currRing) |
---|
40 | |
---|
41 | /*************************************************************** |
---|
42 | * |
---|
43 | * Allocation/Initalization/Deletion |
---|
44 | * except for pHead, all polys must be != NULL |
---|
45 | * |
---|
46 | ***************************************************************/ |
---|
47 | // allocates the space for a new monomial -- no initialization !!! |
---|
48 | #define pNew() p_New(currRing) |
---|
49 | // allocates a new monomial and initializes everything to 0 |
---|
50 | #define pInit() p_Init(currRing) |
---|
51 | // like pInit, except that expvector is initialized to that of p, |
---|
52 | // p must be != NULL |
---|
53 | #define pLmInit(p) p_LmInit(p, currRing) |
---|
54 | // returns newly allocated copy of Lm(p), coef is copied, next=NULL, |
---|
55 | // p might be NULL |
---|
56 | #define pHead(p) p_Head(p, currRing) |
---|
57 | // frees the space of the monomial m, assumes m != NULL |
---|
58 | // coef is not freed, m is not advanced |
---|
59 | static inline void pLmFree(poly p) {p_LmFree(p, currRing);} |
---|
60 | // like pLmFree, but advances p |
---|
61 | static inline void pLmFree(poly *p) {p_LmFree(p, currRing);} |
---|
62 | // assumes p != NULL, deletes p, returns pNext(p) |
---|
63 | #define pLmFreeAndNext(p) p_LmFreeAndNext(p, currRing) |
---|
64 | // assume p != NULL, deletes Lm(p)->coef and Lm(p) |
---|
65 | #define pLmDelete(p) p_LmDelete(p, currRing) |
---|
66 | // like pLmDelete, returns pNext(p) |
---|
67 | #define pLmDeleteAndNext(p) p_LmDeleteAndNext(p, currRing) |
---|
68 | |
---|
69 | /*************************************************************** |
---|
70 | * |
---|
71 | * Operation on ExpVectors: assumes polys != NULL |
---|
72 | * |
---|
73 | ***************************************************************/ |
---|
74 | |
---|
75 | #define pExpVectorCopy(d_p, s_p) p_ExpVectorCopy(d_p, s_p, currRing) |
---|
76 | #define pExpVectorAdd(p1, p2) p_ExpVectorAdd(p1, p2, currRing) |
---|
77 | #define pExpVectorSub(p1, p2) p_ExpVectorSub(p1, p2, currRing) |
---|
78 | #define pExpVectorAddSub(p1, p2, p3)p_ExpVectorAddSub(p1, p2, p3, currRing) |
---|
79 | #define pExpVectorSum(pr, p1, p2) p_ExpVectorSum(pr, p1, p2, currRing) |
---|
80 | #define pExpVectorDiff(pr, p1, p2) p_ExpVectorDiff(pr, p1, p2, currRing) |
---|
81 | |
---|
82 | // Gets a copy of (resp. set) the exponent vector, where e is assumed |
---|
83 | // to point to (r->N +1)*sizeof(long) memory. Exponents are |
---|
84 | // filled in as follows: comp, e_1, .., e_n |
---|
85 | #define pGetExpV(p, e) p_GetExpV(p, e, currRing) |
---|
86 | #define pSetExpV(p, e) p_SetExpV(p, e, currRing) |
---|
87 | |
---|
88 | /*************************************************************** |
---|
89 | * |
---|
90 | * Comparisons: they are all done without regarding coeffs |
---|
91 | * |
---|
92 | ***************************************************************/ |
---|
93 | // returns 0|1|-1 if p=q|p>q|p<q w.r.t monomial ordering |
---|
94 | #define pLmCmp(p,q) p_LmCmp(p,q,currRing) |
---|
95 | // executes axtionE|actionG|actionS if p=q|p>q|p<q w.r.t monomial ordering |
---|
96 | // action should be a "goto ..." |
---|
97 | #define pLmCmpAction(p,q, actionE, actionG, actionS) \ |
---|
98 | _p_LmCmpAction(p,q,currRing, actionE, actionG,actionS) |
---|
99 | |
---|
100 | #define pLmEqual(p1, p2) p_ExpVectorEqual(p1, p2, currRing) |
---|
101 | |
---|
102 | // pCmp: args may be NULL |
---|
103 | // returns: (p2==NULL ? 1 : (p1 == NULL ? -1 : p_LmCmp(p1, p2))) |
---|
104 | #define pCmp(p1, p2) p_Cmp(p1, p2, currRing) |
---|
105 | |
---|
106 | |
---|
107 | /*************************************************************** |
---|
108 | * |
---|
109 | * Divisiblity tests, args must be != NULL, except for |
---|
110 | * pDivisbleBy |
---|
111 | * |
---|
112 | ***************************************************************/ |
---|
113 | // returns TRUE, if leading monom of a divides leading monom of b |
---|
114 | // i.e., if there exists a expvector c > 0, s.t. b = a + c; |
---|
115 | #define pDivisibleBy(a, b) p_DivisibleBy(a,b,currRing) |
---|
116 | // like pDivisibleBy, except that it is assumed that a!=NULL, b!=NULL |
---|
117 | #define pLmDivisibleBy(a,b) p_LmDivisibleBy(a,b,currRing) |
---|
118 | // like pLmDivisibleBy, does not check components |
---|
119 | #define pLmDivisibleByNoComp(a, b) p_LmDivisibleByNoComp(a,b,currRing) |
---|
120 | // Divisibility tests based on Short Exponent vectors |
---|
121 | // sev_a == pGetShortExpVector(a) |
---|
122 | // not_sev_b == ~ pGetShortExpVector(b) |
---|
123 | #define pLmShortDivisibleBy(a, sev_a, b, not_sev_b) \ |
---|
124 | p_LmShortDivisibleBy(a, sev_a, b, not_sev_b, currRing) |
---|
125 | #define pLmRingShortDivisibleBy(a, sev_a, b, not_sev_b) \ |
---|
126 | p_LmRingShortDivisibleBy(a, sev_a, b, not_sev_b, currRing) |
---|
127 | // returns the "Short Exponent Vector" -- used to speed up divisibility |
---|
128 | // tests (see polys-impl.cc ) |
---|
129 | #define pGetShortExpVector(a) p_GetShortExpVector(a, currRing) |
---|
130 | #ifdef HAVE_RINGS |
---|
131 | /* divisibility check over ground ring (which may contain zero divisors); |
---|
132 | TRUE iff LT(f) divides LT(g), i.e., LT(f)*c*m = LT(g), for some |
---|
133 | coefficient c and some monomial m; |
---|
134 | does not take components into account */ |
---|
135 | BOOLEAN pDivisibleByRingCase(poly f, poly g); |
---|
136 | #endif |
---|
137 | |
---|
138 | /*************************************************************** |
---|
139 | * |
---|
140 | * Copying/Deleteion of polys: args may be NULL |
---|
141 | * |
---|
142 | ***************************************************************/ |
---|
143 | // return a copy of the poly |
---|
144 | #define pCopy(p) p_Copy(p, currRing) |
---|
145 | #define pDelete(p_ptr) p_Delete(p_ptr, currRing) |
---|
146 | |
---|
147 | /*************************************************************** |
---|
148 | * |
---|
149 | * Copying/Deletion of polys: args may be NULL |
---|
150 | * - p/q as arg mean a poly |
---|
151 | * - m a monomial |
---|
152 | * - n a number |
---|
153 | * - pp (resp. qq, mm, nn) means arg is constant |
---|
154 | * - p (resp, q, m, n) means arg is destroyed |
---|
155 | * |
---|
156 | ***************************************************************/ |
---|
157 | #define pNeg(p) p_Neg(p, currRing) |
---|
158 | #define ppMult_nn(p, n) pp_Mult_nn(p, n, currRing) |
---|
159 | #define pMult_nn(p, n) p_Mult_nn(p, n, currRing) |
---|
160 | #define ppMult_mm(p, m) pp_Mult_mm(p, m, currRing) |
---|
161 | #define pMult_mm(p, m) p_Mult_mm(p, m, currRing) |
---|
162 | #define pAdd(p, q) p_Add_q(p, q, currRing) |
---|
163 | #define pPower(p, q) p_Power(p, q, currRing) |
---|
164 | #define pMinus_mm_Mult_qq(p, m, q) p_Minus_mm_Mult_qq(p, m, q, currRing) |
---|
165 | #define pPlus_mm_Mult_qq(p, m, q) p_Plus_mm_Mult_qq(p, m, q, currRing) |
---|
166 | #define pMult(p, q) p_Mult_q(p, q, currRing) |
---|
167 | #define ppMult_qq(p, q) pp_Mult_qq(p, q, currRing) |
---|
168 | // p*Coeff(m) for such monomials pm of p, for which m is divisble by pm |
---|
169 | #define ppMult_Coeff_mm_DivSelect(p, m) pp_Mult_Coeff_mm_DivSelect(p, m, currRing) |
---|
170 | /************************************************************************* |
---|
171 | * |
---|
172 | * Sort routines |
---|
173 | * |
---|
174 | *************************************************************************/ |
---|
175 | // sorts p, assumes all monomials in p are different |
---|
176 | #define pSortMerger(p) p_SortMerge(p, currRing) |
---|
177 | #define pSort(p) p_SortMerge(p, currRing) |
---|
178 | |
---|
179 | // sorts p, p may have equal monomials |
---|
180 | #define pSortAdd(p) p_SortAdd(p, currRing) |
---|
181 | |
---|
182 | |
---|
183 | // Assume: If considerd only as poly in any component of p |
---|
184 | // (say, monomials of other components of p are set to 0), |
---|
185 | // then p is already sorted correctly |
---|
186 | #define pSortCompCorrect(p) pSort(p) |
---|
187 | |
---|
188 | /*************************************************************** |
---|
189 | * |
---|
190 | * Predicates on polys/Lm's |
---|
191 | * |
---|
192 | ***************************************************************/ |
---|
193 | // return true if all p is eihter NULL, or if all exponents |
---|
194 | // of p are 0 and Comp of p is zero |
---|
195 | #define pIsConstantComp(p) p_IsConstantComp(p, currRing) |
---|
196 | // like above, except that Comp might be != 0 |
---|
197 | #define pIsConstant(p) p_IsConstant(p,currRing) |
---|
198 | // return true if the Lm is a constant <>0 |
---|
199 | #define pIsUnit(p) p_IsUnit(p,currRing) |
---|
200 | // like above, except that p must be != NULL |
---|
201 | #define pLmIsConstantComp(p) p_LmIsConstantComp(p, currRing) |
---|
202 | #define pLmIsConstant(p) p_LmIsConstant(p,currRing) |
---|
203 | |
---|
204 | // return TRUE if all monomials of p are constant |
---|
205 | #define pIsConstantPoly(p) p_IsConstantPoly(p, currRing) |
---|
206 | |
---|
207 | #define pIsPurePower(p) p_IsPurePower(p, currRing) |
---|
208 | #define pIsUnivariate(p) p_IsUnivariate(p, currRing) |
---|
209 | #define pIsVector(p) (pGetComp(p)>0) |
---|
210 | #define pGetVariables(p,e) p_GetVariables(p, e, currRing) |
---|
211 | |
---|
212 | /*************************************************************** |
---|
213 | * |
---|
214 | * Old stuff |
---|
215 | * |
---|
216 | ***************************************************************/ |
---|
217 | |
---|
218 | typedef poly* polyset; |
---|
219 | extern int pOrdSgn; |
---|
220 | extern BOOLEAN pLexOrder; |
---|
221 | extern poly ppNoether; |
---|
222 | extern BOOLEAN pVectorOut; |
---|
223 | |
---|
224 | /*-------------predicate on polys ----------------------*/ |
---|
225 | #define pHasNotCF(p1,p2) p_HasNotCF(p1,p2,currRing) |
---|
226 | /*has no common factor ?*/ |
---|
227 | #define pSplit(p,r) p_Split(p,r) |
---|
228 | /*p => IN(p), r => REST(p) */ |
---|
229 | |
---|
230 | |
---|
231 | |
---|
232 | /*-----------the ordering of monomials:-------------*/ |
---|
233 | #define pSetm(p) p_Setm(p, currRing) |
---|
234 | // TODO: |
---|
235 | #define pSetmComp(p) p_Setm(p, currRing) |
---|
236 | |
---|
237 | /*************************************************************** |
---|
238 | * |
---|
239 | * Degree stuff -- see p_polys.cc for explainations |
---|
240 | * |
---|
241 | ***************************************************************/ |
---|
242 | static inline long pFDeg(const poly p, const ring r) { return r->pFDeg(p,r); } |
---|
243 | static inline long pLDeg(const poly p, int *l, const ring r) { return r->pLDeg(p,l,r); } |
---|
244 | #define pWeight(c) p_Weight(c,currRing) |
---|
245 | #define pDeg(p) p_Deg(p,currRing) |
---|
246 | static inline long pTotaldegree(poly p) { return p_Totaldegree(p,currRing); } |
---|
247 | #define pWTotaldegree(p) p_WTotaldegree(p,currRing) |
---|
248 | #define pWDegree(poly p) p_WDegree(p,currRing) |
---|
249 | |
---|
250 | /*-------------operations on polynomials:------------*/ |
---|
251 | #define pSub(a,b) p_Sub(a,b,currRing) |
---|
252 | |
---|
253 | #define pmInit(a,b) p_mInit(a,b,currRing) |
---|
254 | |
---|
255 | // ----------------- define to enable new p_procs -----*/ |
---|
256 | |
---|
257 | #define pDivide(a,b) p_Divide(a,b,currRing) |
---|
258 | #define pLcm(a,b,m) p_Lcm(a,b,m,currRing) |
---|
259 | #define pDiff(a,b) p_Diff(a,b,currRing) |
---|
260 | #define pDiffOp(a,b,m) p_DiffOp(a,b,m,currRing) |
---|
261 | |
---|
262 | #define pMaxComp(p) p_MaxComp(p, currRing) |
---|
263 | #define pMinComp(p) p_MinComp(p, currRing) |
---|
264 | |
---|
265 | #define pOneComp(p) p_OneComp(p, currRing) |
---|
266 | #define pSetCompP(a,i) p_SetCompP(a, i, currRing) |
---|
267 | |
---|
268 | // let's inline those, so that we can call them from the debugger |
---|
269 | inline char* pString(poly p) {return p_String(p, currRing, currRing);} |
---|
270 | inline char* pString0(poly p) {return p_String0(p, currRing, currRing);} |
---|
271 | inline void pWrite(poly p) {p_Write(p, currRing, currRing);} |
---|
272 | inline void pWrite0(poly p) {p_Write0(p, currRing, currRing);} |
---|
273 | inline void wrp(poly p) {p_wrp(p, currRing, currRing);} |
---|
274 | |
---|
275 | void pEnlargeSet(polyset *p, int length, int increment); |
---|
276 | #define pISet(i) p_ISet(i,currRing) |
---|
277 | #define pNSet(n) p_NSet(n,currRing) |
---|
278 | |
---|
279 | #define pOne() p_One(currRing) |
---|
280 | |
---|
281 | #define pNormalize(p) p_Normalize(p,currRing) |
---|
282 | #define pSize(p) p_Size(p,currRing) |
---|
283 | |
---|
284 | |
---|
285 | // homogenizes p by multiplying certain powers of the varnum-th variable |
---|
286 | #define pHomogen(p,varnum) p_Homogen(p,varnum,currRing) |
---|
287 | |
---|
288 | BOOLEAN pIsHomogeneous (poly p); |
---|
289 | // // replaces the maximal powers of the leading monomial of p2 in p1 by |
---|
290 | // // the same powers of n, utility for dehomogenization |
---|
291 | // #define pDehomogen(p1,p2,n) p_Dehomgen(p1,p2,n,currRing) |
---|
292 | // #define pIsHomogen(p) p_IsHomggen(p,currRing) |
---|
293 | #define pIsHomogen(p) p_IsHomogen(p,currRing) |
---|
294 | |
---|
295 | /*BOOLEAN pVectorHasUnitM(poly p, int * k);*/ |
---|
296 | #define pVectorHasUnitB(p,k) p_VectorHasUnitB(p,k,currRing) |
---|
297 | #define pVectorHasUnit(p,k,l) p_VectorHasUnit(p,k,l,currRing) |
---|
298 | #define pTakeOutComp1(p,k) p_TakeOutComp1(p,k,currRing) |
---|
299 | |
---|
300 | // Splits *p into two polys: *q which consists of all monoms with |
---|
301 | // component == comp and *p of all other monoms *lq == pLength(*q) |
---|
302 | // On return all components pf *q == 0 |
---|
303 | void pTakeOutComp(poly *p, long comp, poly *q, int *lq); |
---|
304 | |
---|
305 | // This is something weird -- Don't use it, unless you know what you are doing |
---|
306 | poly pTakeOutComp(poly * p, int k); |
---|
307 | /* old spielwiese |
---|
308 | #define pTakeOutComp(p,k,q,lq) p_TakeOutComp(p,k,q,lq,currRing) |
---|
309 | |
---|
310 | // Similar to pTakeOutComp, except that only those components are |
---|
311 | // taken out whose Order == order |
---|
312 | // ASSUME: monomial ordering is Order compatible, i.e., if m1, m2 Monoms then |
---|
313 | // m1 >= m2 ==> pGetOrder(m1) >= pGetOrder(m2) |
---|
314 | #define pDecrOrdTakeOutComp(p,c,o,q,lq) p_DecrOrdTakeOutComp(p,c,o,q,lq,currRing) |
---|
315 | */ |
---|
316 | void pSetPolyComp(poly p, int comp); |
---|
317 | #define pDeleteComp(p,k) p_DeleteComp(p,k,currRing) |
---|
318 | void pNorm(poly p); |
---|
319 | poly pSubst(poly p, int n, poly e); |
---|
320 | poly ppJet(poly p, int m); |
---|
321 | poly pJet(poly p, int m); |
---|
322 | poly ppJetW(poly p, int m, short * iv); |
---|
323 | poly pJetW(poly p, int m, short * iv); |
---|
324 | int pMinDeg(poly p,intvec *w=NULL); |
---|
325 | poly pSeries(int n,poly p,poly u=NULL,intvec *w=NULL); |
---|
326 | poly pInvers(int n, poly p,intvec *w=NULL); |
---|
327 | // maximum weigthed degree of all monomials of p, w is indexed from |
---|
328 | // 1..pVariables |
---|
329 | long pDegW(poly p, const short *w); |
---|
330 | |
---|
331 | /*-----------type conversions ----------------------------*/ |
---|
332 | void pVec2Polys(poly v, polyset *p, int *len); |
---|
333 | int p_Var(poly mi,const ring r); |
---|
334 | #define pVar(m) p_Var(m,currRing) |
---|
335 | |
---|
336 | /*-----------specials for spoly-computations--------------*/ |
---|
337 | BOOLEAN pCompareChain (poly p,poly p1,poly p2,poly lcm); |
---|
338 | BOOLEAN pCompareChainPart (poly p,poly p1,poly p2,poly lcm); |
---|
339 | #define pEqualPolys(p1,p2) p_EqualPolys(p1,p2,currRing) |
---|
340 | BOOLEAN pComparePolys(poly p1,poly p2); |
---|
341 | |
---|
342 | |
---|
343 | |
---|
344 | /*************************************************************** |
---|
345 | * |
---|
346 | * PDEBUG stuff |
---|
347 | * |
---|
348 | ***************************************************************/ |
---|
349 | #ifdef PDEBUG |
---|
350 | #define pTest(p) _p_Test(p, currRing, PDEBUG) |
---|
351 | #define pLmTest(p) _p_LmTest(p, currRing, PDEBUG) |
---|
352 | |
---|
353 | #else // ! PDEBUG |
---|
354 | |
---|
355 | #define pTest(p) ((void)0) |
---|
356 | #define pLmTest(p) ((void)0) |
---|
357 | #endif |
---|
358 | |
---|
359 | #endif // POLYS_H |
---|