source: git/kernel/polys.h @ c858487

spielwiese
Last change on this file since c858487 was c858487, checked in by Frédéric Chapoton <chapoton@…>, 17 months ago
fix many typos in kernel/
  • Property mode set to 100644
File size: 16.0 KB
RevLine 
[c858487]1/*! \file kernel/polys.h Compatibility layer for legacy polynomial operations (over @ref currRing)
[fea494]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.
[89f209]5 Notice that they have different prefix: `p` instead of `p_`.
6
[c858487]7 See also related global ring variable and the correct ring changing routine:
[89f209]8 - \ref currRing
9 - \ref rChangeCurrRing
[9b0e1a]10*/
11
[35aab3]12#ifndef POLYS_H
13#define POLYS_H
14
[d2f250]15#include "polys/monomials/ring.h"
16#include "polys/monomials/p_polys.h"
[35aab3]17
[a3f0fea]18EXTERN_VAR ring currRing;
[85fd90]19void rChangeCurrRing(ring r);
20
[d2f250]21#include "coeffs/numbers.h"
[f0a8c59]22
[35aab3]23/***************************************************************
24 *
25 * Primitives for accessing and setting fields of a poly
26 * poly must be != NULL
27 *
28 ***************************************************************/
[6ed8c4]29
[89f209]30/// deletes old coeff before setting the new one
[35aab3]31#define pSetCoeff(p,n)      p_SetCoeff(p,n,currRing)
32
[89f209]33/// Order
[35aab3]34#define pGetOrder(p)        p_GetOrder(p, currRing)
35
[89f209]36/// Component
[32ad2a]37#define pGetComp(p)         (int)__p_GetComp(p, currRing)
[35aab3]38#define pSetComp(p,v)       p_SetComp(p,v, currRing)
39
[89f209]40/// Exponent
[35aab3]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)
[6ed8c4]50
[35aab3]51
52/***************************************************************
53 *
[c858487]54 * Allocation/Initialization/Deletion
[fb82895]55 * except for pHead, all polys must be != NULL
[35aab3]56 *
57 ***************************************************************/
[89f209]58/// allocates the space for a new monomial -- no initialization !!!
[35aab3]59#define pNew()          p_New(currRing)
[89f209]60/// allocates a new monomial and initializes everything to 0
[9d17f9]61#define pInit()         p_Init(currRing,currRing->PolyBin)
[89f209]62/// like pInit, except that expvector is initialized to that of p,
63/// p must be != NULL
[35aab3]64#define pLmInit(p)  p_LmInit(p, currRing)
[89f209]65/// returns newly allocated copy of Lm(p), coef is copied, next=NULL,
66/// p might be NULL
[35aab3]67#define pHead(p)        p_Head(p, currRing)
[89f209]68/// frees the space of the monomial m, assumes m != NULL
69/// coef is not freed, m is not advanced
[35aab3]70static inline void pLmFree(poly p)    {p_LmFree(p, currRing);}
[89f209]71/// like pLmFree, but advances p
[35aab3]72static inline void pLmFree(poly *p)   {p_LmFree(p, currRing);}
[89f209]73/// assumes p != NULL, deletes p, returns pNext(p)
[35aab3]74#define pLmFreeAndNext(p) p_LmFreeAndNext(p, currRing)
[89f209]75/// assume p != NULL, deletes Lm(p)->coef and Lm(p)
[35aab3]76#define pLmDelete(p)    p_LmDelete(p, currRing)
[89f209]77/// like pLmDelete, returns pNext(p)
[35aab3]78#define pLmDeleteAndNext(p) p_LmDeleteAndNext(p, currRing)
79
80/***************************************************************
81 *
82 * Operation on ExpVectors: assumes polys != NULL
83 *
84 ***************************************************************/
85
[3a9e92a]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)
[35aab3]92
[89f209]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
[35aab3]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 ***************************************************************/
[89f209]104/// returns 0|1|-1 if p=q|p>q|p<q w.r.t monomial ordering
[5efbf9]105#define pLmCmp(p,q)            p_LmCmp(p,q,currRing)
[89f209]106/// executes axtionE|actionG|actionS if p=q|p>q|p<q w.r.t monomial ordering
107/// action should be a "goto ..."
[35aab3]108#define pLmCmpAction(p,q, actionE, actionG, actionS)  \
109  _p_LmCmpAction(p,q,currRing, actionE, actionG,actionS)
110
[5c39a9]111#define pLmEqual(p1, p2)     p_ExpVectorEqual(p1, p2, currRing)
[35aab3]112
[89f209]113/// pCmp: args may be NULL
114/// returns: (p2==NULL ? 1 : (p1 == NULL ? -1 : p_LmCmp(p1, p2)))
[35aab3]115#define pCmp(p1, p2)    p_Cmp(p1, p2, currRing)
116
[5efbf9]117/***************************************************************
118 *
119 * Comparisons: these are all done regarding coeffs
120 *
121 ***************************************************************/
122
123#define pLtCmp(p,q)            p_LtCmp(p,q,currRing)
[459ec94]124#define pLtCmpNoAbs(p,q)       p_LtCmpNoAbs(p,q,currRing)
[5efbf9]125#define pLtCmpOrdSgnDiffM(p,q) p_LtCmpOrdSgnDiffM(p,q,currRing)
126#define pLtCmpOrdSgnDiffP(p,q) p_LtCmpOrdSgnDiffP(p,q,currRing)
127#define pLtCmpOrdSgnEqM(p,q)   p_LtCmpOrdSgnEqM(p,q,currRing)
128#define pLtCmpOrdSgnEqP(p,q)   p_LtCmpOrdSgnEqP(p,q,currRing)
[35aab3]129
130/***************************************************************
131 *
132 * Divisiblity tests, args must be != NULL, except for
133 * pDivisbleBy
134 *
135 ***************************************************************/
[89f209]136/// returns TRUE, if leading monom of a divides leading monom of b
137/// i.e., if there exists a expvector c > 0, s.t. b = a + c;
[35aab3]138#define pDivisibleBy(a, b)  p_DivisibleBy(a,b,currRing)
[89f209]139/// like pDivisibleBy, except that it is assumed that a!=NULL, b!=NULL
[35aab3]140#define pLmDivisibleBy(a,b)  p_LmDivisibleBy(a,b,currRing)
[89f209]141/// like pLmDivisibleBy, does not check components
[35aab3]142#define pLmDivisibleByNoComp(a, b) p_LmDivisibleByNoComp(a,b,currRing)
[89f209]143/// Divisibility tests based on Short Exponent vectors
144/// sev_a     == pGetShortExpVector(a)
145/// not_sev_b == ~ pGetShortExpVector(b)
[35aab3]146#define pLmShortDivisibleBy(a, sev_a, b, not_sev_b) \
147  p_LmShortDivisibleBy(a, sev_a, b, not_sev_b, currRing)
[cea6f3]148#define pLmRingShortDivisibleBy(a, sev_a, b, not_sev_b) \
149  p_LmRingShortDivisibleBy(a, sev_a, b, not_sev_b, currRing)
[89f209]150/// returns the "Short Exponent Vector" -- used to speed up divisibility
151/// tests (see polys-impl.cc )
[35aab3]152#define pGetShortExpVector(a)   p_GetShortExpVector(a, currRing)
[89f209]153
[a8b44d]154#ifdef HAVE_RINGS
[89f209]155/// divisibility check over ground ring (which may contain zero divisors);
156/// TRUE iff LT(f) divides LT(g), i.e., LT(f)*c*m = LT(g), for some
157/// coefficient c and some monomial m;
158/// does not take components into account */
[3d0808]159#define  pDivisibleByRingCase(f,g) p_DivisibleByRingCase(f,g,currRing)
[a8b44d]160#endif
[35aab3]161
[37cbc2]162/// polynomial division a/b, ignoring the rest
[171070]163/// via singclap_pdivide resp. idLift
[c858487]164/// destroys a,b
[d3af55]165poly p_Divide(poly a, poly b, const ring r);
[cec9624]166/// polynomial division a/b, ignoring the rest
167/// via singclap_pdivide resp. idLift
168/// does not destroy a,b
169poly pp_Divide(poly a, poly b, const ring r);
[ea9bd5]170poly p_DivRem(poly a, poly b, poly &rest, const ring r); /*julia*/
[171070]171
172/// polynomial gcd
173/// via singclap_gcd_r resp. idSyzygies
174/// destroys f and g
175poly singclap_gcd ( poly f, poly g, const ring r );
176
177
178
[35aab3]179/***************************************************************
180 *
[171070]181 * Copying/Deletion of polys: args may be NULL
[35aab3]182 *
183 ***************************************************************/
[89f209]184/// return a copy of the poly
[35aab3]185#define pCopy(p) p_Copy(p, currRing)
186#define pDelete(p_ptr)  p_Delete(p_ptr, currRing)
187
188/***************************************************************
189 *
[95450e]190 * Copying/Deletion of polys: args may be NULL
[35aab3]191 *  - p/q as arg mean a poly
192 *  - m a monomial
193 *  - n a number
194 *  - pp (resp. qq, mm, nn) means arg is constant
195 *  - p (resp, q, m, n)     means arg is destroyed
196 *
197 ***************************************************************/
198#define pNeg(p)                     p_Neg(p, currRing)
199#define ppMult_nn(p, n)             pp_Mult_nn(p, n, currRing)
200#define pMult_nn(p, n)              p_Mult_nn(p, n, currRing)
201#define ppMult_mm(p, m)             pp_Mult_mm(p, m, currRing)
202#define pMult_mm(p, m)              p_Mult_mm(p, m, currRing)
203#define pAdd(p, q)                  p_Add_q(p, q, currRing)
[690e21e]204#define pPower(p, q)                p_Power(p, q, currRing)
[35aab3]205#define pMinus_mm_Mult_qq(p, m, q)  p_Minus_mm_Mult_qq(p, m, q, currRing)
206#define pPlus_mm_Mult_qq(p, m, q)   p_Plus_mm_Mult_qq(p, m, q, currRing)
207#define pMult(p, q)                 p_Mult_q(p, q, currRing)
208#define ppMult_qq(p, q)             pp_Mult_qq(p, q, currRing)
209// p*Coeff(m) for such monomials pm of p, for which m is divisble by pm
210#define ppMult_Coeff_mm_DivSelect(p, m)   pp_Mult_Coeff_mm_DivSelect(p, m, currRing)
211/*************************************************************************
212 *
213 * Sort routines
214 *
215 *************************************************************************/
[89f209]216/// sorts p, assumes all monomials in p are different
[f34215]217#define pSortMerger(p)          p_SortMerge(p, currRing)
[35aab3]218#define pSort(p)                p_SortMerge(p, currRing)
219
[89f209]220/// sorts p, p may have equal monomials
[35aab3]221#define pSortAdd(p)             p_SortAdd(p, currRing)
222
223
[c858487]224/// Assume: If considered only as poly in any component of p
[89f209]225/// (say, monomials of other components of p are set to 0),
226/// then p is already sorted correctly
[35aab3]227#define pSortCompCorrect(p) pSort(p)
228
229/***************************************************************
230 *
231 * Predicates on polys/Lm's
232 *
233 ***************************************************************/
[bdcd67]234/// return true if p is either NULL, or if all exponents
235/// of p are 0, Comp of p might be != 0
[35aab3]236#define   pIsConstantComp(p)        p_IsConstantComp(p, currRing)
[bdcd67]237/// like above, except that Comp must be 0
[35aab3]238#define   pIsConstant(p)            p_IsConstant(p,currRing)
[89f209]239/// return true if the Lm is a constant <>0
[35aab3]240#define   pIsUnit(p)            p_IsUnit(p,currRing)
[89f209]241/// like above, except that p must be != NULL
[35aab3]242#define   pLmIsConstantComp(p)      p_LmIsConstantComp(p, currRing)
243#define   pLmIsConstant(p)          p_LmIsConstant(p,currRing)
244
[89f209]245/// return TRUE if all monomials of p are constant
[de714a7]246#define   pIsConstantPoly(p)        p_IsConstantPoly(p, currRing)
[35aab3]247
248#define   pIsPurePower(p)   p_IsPurePower(p, currRing)
[2f0d83f]249#define   pIsUnivariate(p)  p_IsUnivariate(p, currRing)
[35aab3]250#define   pIsVector(p)      (pGetComp(p)>0)
[95450e]251#define   pGetVariables(p,e)  p_GetVariables(p, e, currRing)
[35aab3]252
253/***************************************************************
254 *
255 * Old stuff
256 *
257 ***************************************************************/
258
259typedef poly*   polyset;
260
261/*-------------predicate on polys ----------------------*/
[070ab6]262#define  pHasNotCFRing(p1,p2)   p_HasNotCFRing(p1,p2,currRing)
[f34215]263#define  pHasNotCF(p1,p2)   p_HasNotCF(p1,p2,currRing)
264                                /*has no common factor ?*/
265#define  pSplit(p,r)        p_Split(p,r)
266                                /*p => IN(p), r => REST(p) */
[35aab3]267
268
269
270/*-----------the ordering of monomials:-------------*/
271#define pSetm(p)    p_Setm(p, currRing)
[89f209]272/// TODO:
[f34215]273#define pSetmComp(p)   p_Setm(p, currRing)
[35aab3]274
275/***************************************************************
276 *
[c858487]277 * Degree stuff -- see p_polys.cc for explanations
[35aab3]278 *
279 ***************************************************************/
[d69ebc4]280#define pWeight(i)       p_Weight(i,currRing)
[1f637e]281
[99bdcf]282static inline long pTotaldegree(poly p) { return p_Totaldegree(p,currRing); }
[bf183f]283#define pWTotaldegree(p) p_WTotaldegree(p,currRing)
[6bec87]284#define pWDegree(p) p_WDegree(p,currRing)
[35aab3]285
286/*-------------operations on polynomials:------------*/
[bf183f]287#define   pSub(a,b) p_Sub(a,b,currRing)
288
[f34215]289#define pmInit(a,b) p_mInit(a,b,currRing)
[35aab3]290
[89f209]291/* ----------------- define to enable new p_procs -----*/
[35aab3]292
[c796c8]293#define pMDivide(a,b) p_MDivide(a,b,currRing)
[2a38d90]294#define pDivideM(a,b) p_DivideM(a,b,currRing)
[a7ee69]295#define pLcm(a,b,m) p_Lcm(a,b,m,currRing)
[ac0bd6]296#define pDiff(a,b)  p_Diff(a,b,currRing)
[5162db]297#define pDiffOp(a,b,m) p_DiffOp(a,b,m,currRing)
[35aab3]298
299#define   pMaxComp(p)   p_MaxComp(p, currRing)
300#define   pMinComp(p)   p_MinComp(p, currRing)
301
302#define   pOneComp(p)       p_OneComp(p, currRing)
303#define   pSetCompP(a,i)    p_SetCompP(a, i, currRing)
304
305// let's inline those, so that we can call them from the debugger
306inline char*   pString(poly p)    {return p_String(p, currRing, currRing);}
[538512]307inline void    pString0(poly p)   {p_String0(p, currRing, currRing);}
[35aab3]308inline void    pWrite(poly p)     {p_Write(p, currRing, currRing);}
309inline void    pWrite0(poly p)    {p_Write0(p, currRing, currRing);}
310inline void    wrp(poly p)        {p_wrp(p, currRing, currRing);}
311
312#define   pISet(i) p_ISet(i,currRing)
313#define   pNSet(n) p_NSet(n,currRing)
[1c33e0d]314
[a88544]315#define   pOne()   p_One(currRing)
[35aab3]316
317#define   pNormalize(p) p_Normalize(p,currRing)
[fbf8a6]318#define   pSize(p)      p_Size(p,currRing)
[7ba059]319
[35aab3]320
[89f209]321/// homogenizes p by multiplying certain powers of the varnum-th variable
[4e8ef90]322#define  pHomogen(p,varnum) p_Homogen(p,varnum,currRing)
[35aab3]323
324BOOLEAN   pIsHomogeneous (poly p);
[4e8ef90]325// // replaces the maximal powers of the leading monomial of p2 in p1 by
326// // the same powers of n, utility for dehomogenization
327// #define   pDehomogen(p1,p2,n) p_Dehomgen(p1,p2,n,currRing)
328// #define   pIsHomogen(p)       p_IsHomggen(p,currRing)
[a30a39a]329#define   pIsHomogen(p)       p_IsHomogen(p,currRing)
[35aab3]330
331/*BOOLEAN   pVectorHasUnitM(poly p, int * k);*/
[cd246b]332#define   pVectorHasUnitB(p,k) p_VectorHasUnitB(p,k,currRing)
333#define   pVectorHasUnit(p,k,l) p_VectorHasUnit(p,k,l,currRing)
334#define   pTakeOutComp1(p,k)    p_TakeOutComp1(p,k,currRing)
335
[89f209]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
[0d1a36]339inline void pTakeOutComp(poly *p, long comp, poly *q, int *lq, const ring R = currRing)
[a9c298]340{
[1a20e5]341  return p_TakeOutComp(p, comp, q, lq, R);
342}
343
[ffe4fd]344
[89f209]345/// This is something weird -- Don't use it, unless you know what you are doing
[0d1a36]346inline poly      pTakeOutComp(poly * p, int k, const ring R = currRing)
[1a20e5]347{
348  return p_TakeOutComp(p, k, R);
349}
350
[74021a]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*/
[35aab3]360void      pSetPolyComp(poly p, int comp);
[74021a]361#define   pDeleteComp(p,k) p_DeleteComp(p,k,currRing)
[f0a8c59]362
[91f9f2]363inline void pNorm(poly p){ p_Norm(p, currRing); }
[0d1a36]364
[f0a8c59]365
[3b1d9a]366#define   pSubst(p,n,e) p_Subst(p,n,e,currRing)
[ba0fc3]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)
[b7cfaf]372#define   pSeries(n,p,u,w) p_Series(n,p,u,w,currRing)
[c858487]373// maximum weighted degree of all monomials of p, w is indexed from
[35aab3]374// 1..pVariables
[7415540]375
376/// Deprecated: only for compatibility with older code!
[ba0fc3]377#define    pDegW(p,w) p_DegW(p,w,currRing)
[35aab3]378
379/*-----------type conversions ----------------------------*/
[d02fff]380// void  pVec2Polys(poly v, polyset *p, int *len);
[891692]381#define   pVar(m) p_Var(m,currRing)
[35aab3]382
383/*-----------specials for spoly-computations--------------*/
[e044528]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
[152e71c]395#ifdef HAVE_RATGRING
396BOOLEAN pCompareChainPart (poly p, poly p1, poly p2, poly lcm, const ring R = currRing);
397#endif
398
399
[14d732]400#define  pEqualPolys(p1,p2) p_EqualPolys(p1,p2,currRing)
[35aab3]401
402
[e044528]403
[89f209]404/// returns the length of a polynomial (numbers of monomials)
405/// respect syzComp
[0d1a36]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); }
[35aab3]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
[d101b1]420#define pTest(p)        do {} while (0)
421#define pLmTest(p)      do {} while (0)
[35aab3]422#endif
423
424#endif // POLYS_H
Note: See TracBrowser for help on using the repository browser.