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