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