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