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 <kernel/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 | // used by iparith.cc (pHead as proc) |
---|
69 | extern poly pHeadProc(poly p); |
---|
70 | |
---|
71 | /*************************************************************** |
---|
72 | * |
---|
73 | * Operation on ExpVectors: assumes polys != NULL |
---|
74 | * |
---|
75 | ***************************************************************/ |
---|
76 | |
---|
77 | #define pExpVectorCopy(d_p, s_p) p_ExpVectorCopy(d_p, s_p, currRing) |
---|
78 | #define pExpVectorAdd(p1, p2) p_ExpVectorAdd(p1, p2, currRing) |
---|
79 | #define pExpVectorSub(p1, p2) p_ExpVectorSub(p1, p2, currRing) |
---|
80 | #define pExpVectorAddSub(p1, p2, p3)p_ExpVectorAddSub(p1, p2, p3, currRing) |
---|
81 | #define pExpVectorSum(pr, p1, p2) p_ExpVectorSum(pr, p1, p2, currRing) |
---|
82 | #define pExpVectorDiff(pr, p1, p2) p_ExpVectorDiff(pr, p1, p2, currRing) |
---|
83 | #define pExpVectorEqual(p1, p2) p_ExpVectorEqual(p1, p2, currRing) |
---|
84 | |
---|
85 | // Gets a copy of (resp. set) the exponent vector, where e is assumed |
---|
86 | // to point to (r->N +1)*sizeof(long) memory. Exponents are |
---|
87 | // filled in as follows: comp, e_1, .., e_n |
---|
88 | #define pGetExpV(p, e) p_GetExpV(p, e, currRing) |
---|
89 | #define pSetExpV(p, e) p_SetExpV(p, e, currRing) |
---|
90 | |
---|
91 | /*************************************************************** |
---|
92 | * |
---|
93 | * Comparisons: they are all done without regarding coeffs |
---|
94 | * |
---|
95 | ***************************************************************/ |
---|
96 | // returns 0|1|-1 if p=q|p>q|p<q w.r.t monomial ordering |
---|
97 | #define pLmCmp(p,q) p_LmCmp(p,q,currRing) |
---|
98 | // executes axtionE|actionG|actionS if p=q|p>q|p<q w.r.t monomial ordering |
---|
99 | // action should be a "goto ..." |
---|
100 | #define pLmCmpAction(p,q, actionE, actionG, actionS) \ |
---|
101 | _p_LmCmpAction(p,q,currRing, actionE, actionG,actionS) |
---|
102 | |
---|
103 | #define pLmEqual(p1, p2) pExpVectorEqual(p1, p2) |
---|
104 | |
---|
105 | // pCmp: args may be NULL |
---|
106 | // returns: (p2==NULL ? 1 : (p1 == NULL ? -1 : p_LmCmp(p1, p2))) |
---|
107 | #define pCmp(p1, p2) p_Cmp(p1, p2, currRing) |
---|
108 | |
---|
109 | |
---|
110 | /*************************************************************** |
---|
111 | * |
---|
112 | * Divisiblity tests, args must be != NULL, except for |
---|
113 | * pDivisbleBy |
---|
114 | * |
---|
115 | ***************************************************************/ |
---|
116 | // returns TRUE, if leading monom of a divides leading monom of b |
---|
117 | // i.e., if there exists a expvector c > 0, s.t. b = a + c; |
---|
118 | #define pDivisibleBy(a, b) p_DivisibleBy(a,b,currRing) |
---|
119 | // like pDivisibleBy, except that it is assumed that a!=NULL, b!=NULL |
---|
120 | #define pLmDivisibleBy(a,b) p_LmDivisibleBy(a,b,currRing) |
---|
121 | // like pLmDivisibleBy, does not check components |
---|
122 | #define pLmDivisibleByNoComp(a, b) p_LmDivisibleByNoComp(a,b,currRing) |
---|
123 | // Divisibility tests based on Short Exponent vectors |
---|
124 | // sev_a == pGetShortExpVector(a) |
---|
125 | // not_sev_b == ~ pGetShortExpVector(b) |
---|
126 | #define pLmShortDivisibleBy(a, sev_a, b, not_sev_b) \ |
---|
127 | p_LmShortDivisibleBy(a, sev_a, b, not_sev_b, currRing) |
---|
128 | #define pLmRingShortDivisibleBy(a, sev_a, b, not_sev_b) \ |
---|
129 | p_LmRingShortDivisibleBy(a, sev_a, b, not_sev_b, currRing) |
---|
130 | // returns the "Short Exponent Vector" -- used to speed up divisibility |
---|
131 | // tests (see polys-impl.cc ) |
---|
132 | #define pGetShortExpVector(a) p_GetShortExpVector(a, currRing) |
---|
133 | #ifdef HAVE_RINGS |
---|
134 | /* divisibility check over ground ring (which may contain zero divisors); |
---|
135 | TRUE iff LT(f) divides LT(g), i.e., LT(f)*c*m = LT(g), for some |
---|
136 | coefficient c and some monomial m; |
---|
137 | does not take components into account */ |
---|
138 | BOOLEAN pDivisibleByRingCase(poly f, poly g); |
---|
139 | #endif |
---|
140 | |
---|
141 | /*************************************************************** |
---|
142 | * |
---|
143 | * Copying/Deleteion of polys: args may be NULL |
---|
144 | * |
---|
145 | ***************************************************************/ |
---|
146 | // return a copy of the poly |
---|
147 | #define pCopy(p) p_Copy(p, currRing) |
---|
148 | #define pDelete(p_ptr) p_Delete(p_ptr, currRing) |
---|
149 | |
---|
150 | /*************************************************************** |
---|
151 | * |
---|
152 | * Copying/Deletion of polys: args may be NULL |
---|
153 | * - p/q as arg mean a poly |
---|
154 | * - m a monomial |
---|
155 | * - n a number |
---|
156 | * - pp (resp. qq, mm, nn) means arg is constant |
---|
157 | * - p (resp, q, m, n) means arg is destroyed |
---|
158 | * |
---|
159 | ***************************************************************/ |
---|
160 | #define pNeg(p) p_Neg(p, currRing) |
---|
161 | #define ppMult_nn(p, n) pp_Mult_nn(p, n, currRing) |
---|
162 | #define pMult_nn(p, n) p_Mult_nn(p, n, currRing) |
---|
163 | #define ppMult_mm(p, m) pp_Mult_mm(p, m, currRing) |
---|
164 | #define pMult_mm(p, m) p_Mult_mm(p, m, currRing) |
---|
165 | #define pAdd(p, q) p_Add_q(p, q, currRing) |
---|
166 | #define pPower(p, q) p_Power(p, q, currRing) |
---|
167 | #define pMinus_mm_Mult_qq(p, m, q) p_Minus_mm_Mult_qq(p, m, q, currRing) |
---|
168 | #define pPlus_mm_Mult_qq(p, m, q) p_Plus_mm_Mult_qq(p, m, q, currRing) |
---|
169 | #define pMult(p, q) p_Mult_q(p, q, currRing) |
---|
170 | #define ppMult_qq(p, q) pp_Mult_qq(p, q, currRing) |
---|
171 | // p*Coeff(m) for such monomials pm of p, for which m is divisble by pm |
---|
172 | #define ppMult_Coeff_mm_DivSelect(p, m) pp_Mult_Coeff_mm_DivSelect(p, m, currRing) |
---|
173 | /************************************************************************* |
---|
174 | * |
---|
175 | * Sort routines |
---|
176 | * |
---|
177 | *************************************************************************/ |
---|
178 | // sorts p, assumes all monomials in p are different |
---|
179 | #define pSortMerger(p) p_SortMerge(p, currRing) |
---|
180 | #define pSort(p) p_SortMerge(p, currRing) |
---|
181 | |
---|
182 | // sorts p, p may have equal monomials |
---|
183 | #define pSortAdd(p) p_SortAdd(p, currRing) |
---|
184 | |
---|
185 | |
---|
186 | // Assume: If considerd only as poly in any component of p |
---|
187 | // (say, monomials of other components of p are set to 0), |
---|
188 | // then p is already sorted correctly |
---|
189 | #define pSortCompCorrect(p) pSort(p) |
---|
190 | |
---|
191 | /*************************************************************** |
---|
192 | * |
---|
193 | * Predicates on polys/Lm's |
---|
194 | * |
---|
195 | ***************************************************************/ |
---|
196 | // return true if all p is eihter NULL, or if all exponents |
---|
197 | // of p are 0 and Comp of p is zero |
---|
198 | #define pIsConstantComp(p) p_IsConstantComp(p, currRing) |
---|
199 | // like above, except that Comp might be != 0 |
---|
200 | #define pIsConstant(p) p_IsConstant(p,currRing) |
---|
201 | // return true if the Lm is a constant <>0 |
---|
202 | #define pIsUnit(p) p_IsUnit(p,currRing) |
---|
203 | // like above, except that p must be != NULL |
---|
204 | #define pLmIsConstantComp(p) p_LmIsConstantComp(p, currRing) |
---|
205 | #define pLmIsConstant(p) p_LmIsConstant(p,currRing) |
---|
206 | |
---|
207 | // return TRUE if all monomials of p are constant |
---|
208 | #define pIsConstantPoly(p) p_IsConstantPoly(p, currRing) |
---|
209 | |
---|
210 | #define pIsPurePower(p) p_IsPurePower(p, currRing) |
---|
211 | #define pIsUnivariate(p) p_IsUnivariate(p, currRing) |
---|
212 | #define pIsVector(p) (pGetComp(p)>0) |
---|
213 | #define pGetVariables(p,e) p_GetVariables(p, e, currRing) |
---|
214 | |
---|
215 | /*************************************************************** |
---|
216 | * |
---|
217 | * Old stuff |
---|
218 | * |
---|
219 | ***************************************************************/ |
---|
220 | |
---|
221 | typedef poly* polyset; |
---|
222 | extern int pOrdSgn; |
---|
223 | extern BOOLEAN pLexOrder; |
---|
224 | extern poly ppNoether; |
---|
225 | extern BOOLEAN pVectorOut; |
---|
226 | |
---|
227 | /*-------------predicate on polys ----------------------*/ |
---|
228 | #define pHasNotCF(p1,p2) p_HasNotCF(p1,p2,currRing) |
---|
229 | /*has no common factor ?*/ |
---|
230 | #define pSplit(p,r) p_Split(p,r) |
---|
231 | /*p => IN(p), r => REST(p) */ |
---|
232 | |
---|
233 | |
---|
234 | |
---|
235 | /*-------------ring management:----------------------*/ |
---|
236 | extern void pSetGlobals(const ring r, BOOLEAN complete = TRUE); |
---|
237 | |
---|
238 | // resets the pFDeg and pLDeg: if pLDeg is not given, it is |
---|
239 | // set to currRing->pLDegOrig, i.e. to the respective LDegProc which |
---|
240 | // only uses pFDeg (and not pDeg, or pTotalDegree, etc). |
---|
241 | // If you use this, make sure your procs does not make any assumptions |
---|
242 | // on ordering and/or OrdIndex -- otherwise they might return wrong results |
---|
243 | // on strat->tailRing |
---|
244 | extern void pSetDegProcs(pFDegProc new_FDeg, pLDegProc new_lDeg = NULL); |
---|
245 | // restores pFDeg and pLDeg: |
---|
246 | extern void pRestoreDegProcs(pFDegProc old_FDeg, pLDegProc old_lDeg); |
---|
247 | |
---|
248 | /*-----------the ordering of monomials:-------------*/ |
---|
249 | #define pSetm(p) p_Setm(p, currRing) |
---|
250 | // TODO: |
---|
251 | #define pSetmComp(p) p_Setm(p, currRing) |
---|
252 | |
---|
253 | /*************************************************************** |
---|
254 | * |
---|
255 | * Degree stuff -- see p_polys.cc for explainations |
---|
256 | * |
---|
257 | ***************************************************************/ |
---|
258 | extern pLDegProc pLDeg; |
---|
259 | extern pFDegProc pFDeg; |
---|
260 | int pWeight(int c, const ring r = currRing); |
---|
261 | long pDeg(poly p,const ring r = currRing); |
---|
262 | static inline long pTotaldegree(poly p) { return p_Totaldegree(p,currRing); } |
---|
263 | long pWTotaldegree(poly p,const ring r = currRing); |
---|
264 | long pWDegree(poly p,const ring r = currRing); |
---|
265 | long pLDeg0(poly p,int *l,const ring r = currRing); |
---|
266 | long pLDeg0c(poly p,int *l,const ring r = currRing); |
---|
267 | long pLDegb(poly p,int *l,const ring r = currRing); |
---|
268 | long pLDeg1(poly p,int *l,const ring r = currRing); |
---|
269 | long pLDeg1c(poly p,int *l,const ring r = currRing); |
---|
270 | long pLDeg1_Deg(poly p,int *l,const ring r = currRing); |
---|
271 | long pLDeg1c_Deg(poly p,int *l,const ring r = currRing); |
---|
272 | long pLDeg1_Totaldegree(poly p,int *l,const ring r = currRing); |
---|
273 | long pLDeg1c_Totaldegree(poly p,int *l,const ring r = currRing); |
---|
274 | long pLDeg1_WFirstTotalDegree(poly p,int *l,const ring r=currRing); |
---|
275 | long pLDeg1c_WFirstTotalDegree(poly p,int *l,const ring r=currRing); |
---|
276 | |
---|
277 | /*-------------pComp for syzygies:-------------------*/ |
---|
278 | |
---|
279 | void pSetModDeg(intvec *w); |
---|
280 | |
---|
281 | |
---|
282 | |
---|
283 | |
---|
284 | /*-------------operations on polynomials:------------*/ |
---|
285 | poly pSub(poly a, poly b); |
---|
286 | poly p_Power(poly p, int i, const ring r); |
---|
287 | #define pmInit(a,b) p_mInit(a,b,currRing) |
---|
288 | |
---|
289 | // ----------------- define to enable new p_procs -----*/ |
---|
290 | |
---|
291 | poly p_Divide(poly a, poly b, const ring r); |
---|
292 | poly p_DivideM(poly a, poly b, const ring r); |
---|
293 | void pLcm(poly a, poly b, poly m); |
---|
294 | poly pDiff(poly a, int k); |
---|
295 | poly pDiffOp(poly a, poly b,BOOLEAN multiply); |
---|
296 | |
---|
297 | #define pMaxComp(p) p_MaxComp(p, currRing) |
---|
298 | #define pMinComp(p) p_MinComp(p, currRing) |
---|
299 | int pMaxCompProc(poly p); |
---|
300 | |
---|
301 | #define pOneComp(p) p_OneComp(p, currRing) |
---|
302 | #define pSetCompP(a,i) p_SetCompP(a, i, currRing) |
---|
303 | |
---|
304 | // let's inline those, so that we can call them from the debugger |
---|
305 | inline char* pString(poly p) {return p_String(p, currRing, currRing);} |
---|
306 | inline char* pString0(poly p) {return p_String0(p, currRing, currRing);} |
---|
307 | inline void pWrite(poly p) {p_Write(p, currRing, currRing);} |
---|
308 | inline void pWrite0(poly p) {p_Write0(p, currRing, currRing);} |
---|
309 | inline void wrp(poly p) {p_wrp(p, currRing, currRing);} |
---|
310 | |
---|
311 | void pEnlargeSet(polyset *p, int length, int increment); |
---|
312 | #define pISet(i) p_ISet(i,currRing) |
---|
313 | #define pNSet(n) p_NSet(n,currRing) |
---|
314 | |
---|
315 | poly p_One(const ring r); |
---|
316 | #define pOne() p_One(currRing) |
---|
317 | |
---|
318 | void p_Content(poly p, const ring r); |
---|
319 | void pSimpleContent(poly p, int s); |
---|
320 | poly p_Cleardenom(poly p, const ring r); |
---|
321 | void p_Cleardenom_n(poly p, const ring r,number &c); |
---|
322 | void p_Normalize(poly p,const ring r); |
---|
323 | number p_GetAllDenom(poly ph, const ring r); |
---|
324 | #define pNormalize(p) p_Normalize(p,currRing) |
---|
325 | int pSize( poly p ); |
---|
326 | |
---|
327 | |
---|
328 | // homogenizes p by multiplying certain powers of the varnum-th variable |
---|
329 | poly pHomogen (poly p, int varnum); |
---|
330 | |
---|
331 | BOOLEAN pIsHomogeneous (poly p); |
---|
332 | |
---|
333 | poly pPermPoly (poly p, int * perm,const ring OldRing, nMapFunc nMap, |
---|
334 | int *par_perm=NULL, int OldPar=0); |
---|
335 | |
---|
336 | /*BOOLEAN pVectorHasUnitM(poly p, int * k);*/ |
---|
337 | BOOLEAN pVectorHasUnitB(poly p, int * k); |
---|
338 | void pVectorHasUnit(poly p, int * k, int * len); |
---|
339 | poly pTakeOutComp1(poly * p, int k); |
---|
340 | // Splits *p into two polys: *q which consists of all monoms with |
---|
341 | // component == comp and *p of all other monoms *lq == pLength(*q) |
---|
342 | // On return all components pf *q == 0 |
---|
343 | void pTakeOutComp(poly *p, long comp, poly *q, int *lq); |
---|
344 | |
---|
345 | // This is something weird -- Don't use it, unless you know what you are doing |
---|
346 | poly pTakeOutComp(poly * p, int k); |
---|
347 | void pSetPolyComp(poly p, int comp); |
---|
348 | void pDeleteComp(poly * p,int k); |
---|
349 | void pNorm(poly p); |
---|
350 | poly pSubst(poly p, int n, poly e); |
---|
351 | poly ppJet(poly p, int m); |
---|
352 | poly pJet(poly p, int m); |
---|
353 | poly ppJetW(poly p, int m, short * iv); |
---|
354 | poly pJetW(poly p, int m, short * iv); |
---|
355 | int pMinDeg(poly p,intvec *w=NULL); |
---|
356 | poly pSeries(int n,poly p,poly u=NULL,intvec *w=NULL); |
---|
357 | poly pInvers(int n, poly p,intvec *w=NULL); |
---|
358 | // maximum weigthed degree of all monomials of p, w is indexed from |
---|
359 | // 1..pVariables |
---|
360 | long pDegW(poly p, const short *w); |
---|
361 | |
---|
362 | /*-----------type conversions ----------------------------*/ |
---|
363 | //poly pPolys2Vec(polyset p, int len); |
---|
364 | void pVec2Polys(poly v, polyset *p, int *len); |
---|
365 | int p_Var(poly mi,const ring r); |
---|
366 | #define pVar(m) p_Var(m,currRing) |
---|
367 | |
---|
368 | /*-----------specials for spoly-computations--------------*/ |
---|
369 | BOOLEAN pCompareChain (poly p,poly p1,poly p2,poly lcm); |
---|
370 | BOOLEAN pCompareChainPart (poly p,poly p1,poly p2,poly lcm); |
---|
371 | #define pEqualPolys(p1,p2) p_EqualPolys(p1,p2,currRing) |
---|
372 | BOOLEAN pComparePolys(poly p1,poly p2); |
---|
373 | |
---|
374 | |
---|
375 | |
---|
376 | /*************************************************************** |
---|
377 | * |
---|
378 | * PDEBUG stuff |
---|
379 | * |
---|
380 | ***************************************************************/ |
---|
381 | #ifdef PDEBUG |
---|
382 | #define pTest(p) _p_Test(p, currRing, PDEBUG) |
---|
383 | #define pLmTest(p) _p_LmTest(p, currRing, PDEBUG) |
---|
384 | |
---|
385 | #else // ! PDEBUG |
---|
386 | |
---|
387 | #define pTest(p) ((void)0) |
---|
388 | #define pLmTest(p) ((void)0) |
---|
389 | #endif |
---|
390 | |
---|
391 | #endif // POLYS_H |
---|