[35aab3] | 1 | /**************************************** |
---|
| 2 | * Computer Algebra System SINGULAR * |
---|
| 3 | ****************************************/ |
---|
| 4 | /*************************************************************** |
---|
[b84b400] | 5 | * File: p_polys.h |
---|
[35aab3] | 6 | * Purpose: declaration of poly stuf which are independent of |
---|
| 7 | * currRing |
---|
| 8 | * Author: obachman (Olaf Bachmann) |
---|
| 9 | * Created: 9/00 |
---|
| 10 | *******************************************************************/ |
---|
[4f0f42] | 11 | /*************************************************************** |
---|
| 12 | * Purpose: implementation of poly procs which iter over ExpVector |
---|
| 13 | * Author: obachman (Olaf Bachmann) |
---|
| 14 | * Created: 8/00 |
---|
| 15 | *******************************************************************/ |
---|
[35aab3] | 16 | #ifndef P_POLYS_H |
---|
| 17 | #define P_POLYS_H |
---|
| 18 | |
---|
[b2ca85] | 19 | #include "misc/mylimits.h" |
---|
| 20 | #include "misc/intvec.h" |
---|
| 21 | #include "coeffs/coeffs.h" |
---|
[4f0f42] | 22 | |
---|
[b2ca85] | 23 | #include "polys/monomials/monomials.h" |
---|
| 24 | #include "polys/monomials/ring.h" |
---|
[4f0f42] | 25 | |
---|
[b2ca85] | 26 | #include "polys/templates/p_MemAdd.h" |
---|
| 27 | #include "polys/templates/p_MemCmp.h" |
---|
| 28 | #include "polys/templates/p_Procs.h" |
---|
[4f0f42] | 29 | |
---|
[b2ca85] | 30 | #include "polys/sbuckets.h" |
---|
[35aab3] | 31 | |
---|
[4f0f42] | 32 | #ifdef HAVE_PLURAL |
---|
[b2ca85] | 33 | #include "polys/nc/nc.h" |
---|
[4f0f42] | 34 | #endif |
---|
| 35 | |
---|
[0b0bc3] | 36 | poly p_Farey(poly p, number N, const ring r); |
---|
| 37 | /* |
---|
| 38 | * xx,q: arrays of length 0..rl-1 |
---|
| 39 | * xx[i]: SB mod q[i] |
---|
| 40 | * assume: char=0 |
---|
| 41 | * assume: q[i]!=0 |
---|
| 42 | * destroys xx |
---|
| 43 | */ |
---|
[a1f17b] | 44 | poly p_ChineseRemainder(poly *xx, number *x,number *q, int rl, CFArray &inv_cache, const ring R); |
---|
[35aab3] | 45 | /*************************************************************** |
---|
| 46 | * |
---|
| 47 | * Divisiblity tests, args must be != NULL, except for |
---|
| 48 | * pDivisbleBy |
---|
| 49 | * |
---|
| 50 | ***************************************************************/ |
---|
[a576b0] | 51 | unsigned long p_GetShortExpVector(const poly a, const ring r); |
---|
[cf02b22] | 52 | |
---|
[00f64a] | 53 | /// p_GetShortExpVector of p * pp |
---|
| 54 | unsigned long p_GetShortExpVector(const poly p, const poly pp, const ring r); |
---|
| 55 | |
---|
[260672] | 56 | #ifdef HAVE_RINGS |
---|
| 57 | /*! divisibility check over ground ring (which may contain zero divisors); |
---|
[3d0808] | 58 | TRUE iff LT(f) divides LT(g), i.e., LT(f)*c*m = LT(g), for some |
---|
| 59 | coefficient c and some monomial m; |
---|
[260672] | 60 | does not take components into account |
---|
| 61 | */ |
---|
[3d0808] | 62 | BOOLEAN p_DivisibleByRingCase(poly f, poly g, const ring r); |
---|
| 63 | #endif |
---|
[35aab3] | 64 | |
---|
| 65 | /*************************************************************** |
---|
| 66 | * |
---|
| 67 | * Misc things on polys |
---|
| 68 | * |
---|
| 69 | ***************************************************************/ |
---|
[028192] | 70 | |
---|
| 71 | poly p_One(const ring r); |
---|
| 72 | |
---|
[ba0fc3] | 73 | int p_MinDeg(poly p,intvec *w, const ring R); |
---|
| 74 | |
---|
| 75 | long p_DegW(poly p, const short *w, const ring R); |
---|
| 76 | |
---|
[260672] | 77 | /// return TRUE if all monoms have the same component |
---|
[cf02b22] | 78 | BOOLEAN p_OneComp(poly p, const ring r); |
---|
[2f0d83f] | 79 | |
---|
[260672] | 80 | /// return i, if head depends only on var(i) |
---|
[35aab3] | 81 | int p_IsPurePower(const poly p, const ring r); |
---|
| 82 | |
---|
[260672] | 83 | /// return i, if poly depends only on var(i) |
---|
[2f0d83f] | 84 | int p_IsUnivariate(poly p, const ring r); |
---|
| 85 | |
---|
[260672] | 86 | /// set entry e[i] to 1 if var(i) occurs in p, ignore var(j) if e[j]>0 |
---|
| 87 | /// return #(e[i]>0) |
---|
[f46646] | 88 | int p_GetVariables(poly p, int * e, const ring r); |
---|
[95450e] | 89 | |
---|
[260672] | 90 | /// returns the poly representing the integer i |
---|
[2f3764] | 91 | poly p_ISet(long i, const ring r); |
---|
[2f0d83f] | 92 | |
---|
[260672] | 93 | /// returns the poly representing the number n, destroys n |
---|
[cf02b22] | 94 | poly p_NSet(number n, const ring r); |
---|
| 95 | |
---|
| 96 | void p_Vec2Polys(poly v, poly**p, int *len, const ring r); |
---|
[1dc0f49] | 97 | poly p_Vec2Poly(poly v, int k, const ring r); |
---|
[35aab3] | 98 | |
---|
[239d73] | 99 | /// julia: vector to already allocated array (len=p_MaxComp(v,r)) |
---|
| 100 | void p_Vec2Array(poly v, poly *p, int len, const ring r); |
---|
| 101 | |
---|
[35aab3] | 102 | /*************************************************************** |
---|
| 103 | * |
---|
| 104 | * Copying/Deletion of polys: args may be NULL |
---|
| 105 | * |
---|
| 106 | ***************************************************************/ |
---|
| 107 | |
---|
| 108 | // simply deletes monomials, does not free coeffs |
---|
| 109 | void p_ShallowDelete(poly *p, const ring r); |
---|
| 110 | |
---|
[f550e86] | 111 | |
---|
[35aab3] | 112 | |
---|
| 113 | /*************************************************************** |
---|
| 114 | * |
---|
| 115 | * Copying/Deleteion of polys: args may be NULL |
---|
| 116 | * - p/q as arg mean a poly |
---|
| 117 | * - m a monomial |
---|
| 118 | * - n a number |
---|
| 119 | * - pp (resp. qq, mm, nn) means arg is constant |
---|
| 120 | * - p (resp, q, m, n) means arg is destroyed |
---|
| 121 | * |
---|
| 122 | ***************************************************************/ |
---|
| 123 | |
---|
[bf183f] | 124 | poly p_Sub(poly a, poly b, const ring r); |
---|
| 125 | |
---|
| 126 | poly p_Power(poly p, int i, const ring r); |
---|
[5948a8] | 127 | |
---|
| 128 | |
---|
| 129 | /*************************************************************** |
---|
| 130 | * |
---|
| 131 | * PDEBUG stuff |
---|
| 132 | * |
---|
| 133 | ***************************************************************/ |
---|
| 134 | #ifdef PDEBUG |
---|
| 135 | // Returns TRUE if m is monom of p, FALSE otherwise |
---|
| 136 | BOOLEAN pIsMonomOf(poly p, poly m); |
---|
| 137 | // Returns TRUE if p and q have common monoms |
---|
| 138 | BOOLEAN pHaveCommonMonoms(poly p, poly q); |
---|
| 139 | |
---|
| 140 | // p_Check* routines return TRUE if everything is ok, |
---|
| 141 | // else, they report error message and return false |
---|
| 142 | |
---|
| 143 | // check if Lm(p) is from ring r |
---|
| 144 | BOOLEAN p_LmCheckIsFromRing(poly p, ring r); |
---|
| 145 | // check if Lm(p) != NULL, r != NULL and initialized && Lm(p) is from r |
---|
| 146 | BOOLEAN p_LmCheckPolyRing(poly p, ring r); |
---|
| 147 | // check if all monoms of p are from ring r |
---|
| 148 | BOOLEAN p_CheckIsFromRing(poly p, ring r); |
---|
| 149 | // check r != NULL and initialized && all monoms of p are from r |
---|
| 150 | BOOLEAN p_CheckPolyRing(poly p, ring r); |
---|
| 151 | // check if r != NULL and initialized |
---|
| 152 | BOOLEAN p_CheckRing(ring r); |
---|
| 153 | // only do check if cond |
---|
| 154 | |
---|
| 155 | |
---|
| 156 | #define pIfThen(cond, check) do {if (cond) {check;}} while (0) |
---|
| 157 | |
---|
| 158 | BOOLEAN _p_Test(poly p, ring r, int level); |
---|
| 159 | BOOLEAN _p_LmTest(poly p, ring r, int level); |
---|
| 160 | BOOLEAN _pp_Test(poly p, ring lmRing, ring tailRing, int level); |
---|
| 161 | |
---|
| 162 | #define p_Test(p,r) _p_Test(p, r, PDEBUG) |
---|
| 163 | #define p_LmTest(p,r) _p_LmTest(p, r, PDEBUG) |
---|
| 164 | #define pp_Test(p, lmRing, tailRing) _pp_Test(p, lmRing, tailRing, PDEBUG) |
---|
| 165 | |
---|
| 166 | #else // ! PDEBUG |
---|
| 167 | |
---|
[390d66] | 168 | #define pIsMonomOf(p, q) (TRUE) |
---|
| 169 | #define pHaveCommonMonoms(p, q) (TRUE) |
---|
| 170 | #define p_LmCheckIsFromRing(p,r) (TRUE) |
---|
| 171 | #define p_LmCheckPolyRing(p,r) (TRUE) |
---|
| 172 | #define p_CheckIsFromRing(p,r) (TRUE) |
---|
| 173 | #define p_CheckPolyRing(p,r) (TRUE) |
---|
| 174 | #define p_CheckRing(r) (TRUE) |
---|
| 175 | #define P_CheckIf(cond, check) (TRUE) |
---|
| 176 | |
---|
| 177 | #define p_Test(p,r) (TRUE) |
---|
| 178 | #define p_LmTest(p,r) (TRUE) |
---|
| 179 | #define pp_Test(p, lmRing, tailRing) (TRUE) |
---|
[5948a8] | 180 | |
---|
| 181 | #endif |
---|
| 182 | |
---|
[35aab3] | 183 | /*************************************************************** |
---|
| 184 | * |
---|
| 185 | * Misc stuff |
---|
| 186 | * |
---|
| 187 | ***************************************************************/ |
---|
[c1a2b20] | 188 | /*2 |
---|
[ba2359] | 189 | * returns the length of a polynomial (numbers of monomials) |
---|
[c1a2b20] | 190 | */ |
---|
[6e11aa9] | 191 | static inline unsigned pLength(poly a) |
---|
[c1a2b20] | 192 | { |
---|
[117ae9] | 193 | unsigned l = 0; |
---|
[c1a2b20] | 194 | while (a!=NULL) |
---|
| 195 | { |
---|
| 196 | pIter(a); |
---|
| 197 | l++; |
---|
| 198 | } |
---|
[6e11aa9] | 199 | return l; |
---|
[c1a2b20] | 200 | } |
---|
| 201 | |
---|
[a497a1] | 202 | // returns the length of a polynomial (numbers of monomials) and the last mon. |
---|
| 203 | // respect syzComp |
---|
[0d1a36] | 204 | poly p_Last(const poly a, int &l, const ring r); |
---|
[a497a1] | 205 | |
---|
| 206 | /*----------------------------------------------------*/ |
---|
| 207 | |
---|
[71ba5b8] | 208 | void p_Norm(poly p1, const ring r); |
---|
[8d1d30c] | 209 | void p_Normalize(poly p,const ring r); |
---|
[dc42daf] | 210 | void p_ProjectiveUnique(poly p,const ring r); |
---|
[8d1d30c] | 211 | |
---|
[df63e69] | 212 | void p_ContentForGB(poly p, const ring r); |
---|
[8d1d30c] | 213 | void p_Content(poly p, const ring r); |
---|
[f323dd1] | 214 | #if 1 |
---|
[e48172] | 215 | // currently only used by Singular/janet |
---|
[fe66ba8] | 216 | void p_SimpleContent(poly p, int s, const ring r); |
---|
[793bd8] | 217 | number p_InitContent(poly ph, const ring r); |
---|
[e48172] | 218 | #endif |
---|
[8d1d30c] | 219 | |
---|
| 220 | poly p_Cleardenom(poly p, const ring r); |
---|
| 221 | void p_Cleardenom_n(poly p, const ring r,number &c); |
---|
[cb157a] | 222 | //number p_GetAllDenom(poly ph, const ring r);// unused |
---|
[8d1d30c] | 223 | |
---|
[b27c052] | 224 | int p_Size( poly p, const ring r ); |
---|
[fbf8a6] | 225 | |
---|
[4e8ef90] | 226 | // homogenizes p by multiplying certain powers of the varnum-th variable |
---|
| 227 | poly p_Homogen (poly p, int varnum, const ring r); |
---|
[a30a39a] | 228 | |
---|
[4e8ef90] | 229 | BOOLEAN p_IsHomogeneous (poly p, const ring r); |
---|
| 230 | |
---|
[bc9d2e] | 231 | // Setm |
---|
| 232 | static inline void p_Setm(poly p, const ring r) |
---|
| 233 | { |
---|
| 234 | p_CheckRing2(r); |
---|
| 235 | r->p_Setm(p, r); |
---|
| 236 | } |
---|
| 237 | |
---|
| 238 | p_SetmProc p_GetSetmProc(const ring r); |
---|
[35aab3] | 239 | |
---|
[71ba5b8] | 240 | poly p_Subst(poly p, int n, poly e, const ring r); |
---|
| 241 | |
---|
[35aab3] | 242 | // TODO: |
---|
| 243 | #define p_SetmComp p_Setm |
---|
| 244 | |
---|
[20d9284] | 245 | // component |
---|
| 246 | static inline unsigned long p_SetComp(poly p, unsigned long c, ring r) |
---|
| 247 | { |
---|
| 248 | p_LmCheckPolyRing2(p, r); |
---|
[190da3] | 249 | if (r->pCompIndex>=0) __p_GetComp(p,r) = c; |
---|
[20d9284] | 250 | return c; |
---|
| 251 | } |
---|
[a28cb4f] | 252 | // sets component of poly a to i |
---|
[a22a82] | 253 | static inline void p_SetCompP(poly p, int i, ring r) |
---|
[5a3ae8] | 254 | { |
---|
| 255 | if (p != NULL) |
---|
| 256 | { |
---|
[a28cb4f] | 257 | p_Test(p, r); |
---|
[5a3ae8] | 258 | if (rOrd_SetCompRequiresSetm(r)) |
---|
| 259 | { |
---|
| 260 | do |
---|
| 261 | { |
---|
| 262 | p_SetComp(p, i, r); |
---|
| 263 | p_SetmComp(p, r); |
---|
| 264 | pIter(p); |
---|
| 265 | } |
---|
| 266 | while (p != NULL); |
---|
| 267 | } |
---|
| 268 | else |
---|
| 269 | { |
---|
| 270 | do |
---|
| 271 | { |
---|
| 272 | p_SetComp(p, i, r); |
---|
| 273 | pIter(p); |
---|
| 274 | } |
---|
| 275 | while(p != NULL); |
---|
| 276 | } |
---|
| 277 | } |
---|
| 278 | } |
---|
| 279 | |
---|
[a22a82] | 280 | static inline void p_SetCompP(poly p, int i, ring lmRing, ring tailRing) |
---|
[5a3ae8] | 281 | { |
---|
| 282 | if (p != NULL) |
---|
| 283 | { |
---|
| 284 | p_SetComp(p, i, lmRing); |
---|
| 285 | p_SetmComp(p, lmRing); |
---|
| 286 | p_SetCompP(pNext(p), i, tailRing); |
---|
| 287 | } |
---|
| 288 | } |
---|
[c462b55] | 289 | |
---|
| 290 | // returns maximal column number in the modul element a (or 0) |
---|
| 291 | static inline long p_MaxComp(poly p, ring lmRing, ring tailRing) |
---|
| 292 | { |
---|
| 293 | long result,i; |
---|
| 294 | |
---|
| 295 | if(p==NULL) return 0; |
---|
| 296 | result = p_GetComp(p, lmRing); |
---|
| 297 | if (result != 0) |
---|
| 298 | { |
---|
| 299 | loop |
---|
| 300 | { |
---|
| 301 | pIter(p); |
---|
| 302 | if(p==NULL) break; |
---|
| 303 | i = p_GetComp(p, tailRing); |
---|
| 304 | if (i>result) result = i; |
---|
| 305 | } |
---|
| 306 | } |
---|
| 307 | return result; |
---|
| 308 | } |
---|
| 309 | |
---|
| 310 | static inline long p_MaxComp(poly p,ring lmRing) {return p_MaxComp(p,lmRing,lmRing);} |
---|
| 311 | |
---|
| 312 | static inline long p_MinComp(poly p, ring lmRing, ring tailRing) |
---|
| 313 | { |
---|
| 314 | long result,i; |
---|
| 315 | |
---|
| 316 | if(p==NULL) return 0; |
---|
| 317 | result = p_GetComp(p,lmRing); |
---|
| 318 | if (result != 0) |
---|
| 319 | { |
---|
| 320 | loop |
---|
| 321 | { |
---|
| 322 | pIter(p); |
---|
| 323 | if(p==NULL) break; |
---|
| 324 | i = p_GetComp(p,tailRing); |
---|
| 325 | if (i<result) result = i; |
---|
| 326 | } |
---|
| 327 | } |
---|
| 328 | return result; |
---|
| 329 | } |
---|
| 330 | |
---|
| 331 | static inline long p_MinComp(poly p,ring lmRing) {return p_MinComp(p,lmRing,lmRing);} |
---|
[35aab3] | 332 | |
---|
[45d2332] | 333 | |
---|
[20d9284] | 334 | static inline poly pReverse(poly p) |
---|
| 335 | { |
---|
| 336 | if (p == NULL || pNext(p) == NULL) return p; |
---|
| 337 | |
---|
| 338 | poly q = pNext(p), // == pNext(p) |
---|
| 339 | qn; |
---|
| 340 | pNext(p) = NULL; |
---|
| 341 | do |
---|
| 342 | { |
---|
| 343 | qn = pNext(q); |
---|
| 344 | pNext(q) = p; |
---|
| 345 | p = q; |
---|
| 346 | q = qn; |
---|
| 347 | } |
---|
| 348 | while (qn != NULL); |
---|
| 349 | return p; |
---|
| 350 | } |
---|
[c6a3eb2] | 351 | void pEnlargeSet(poly**p, int length, int increment); |
---|
[35aab3] | 352 | |
---|
| 353 | |
---|
| 354 | /*************************************************************** |
---|
| 355 | * |
---|
| 356 | * I/O |
---|
| 357 | * |
---|
| 358 | ***************************************************************/ |
---|
[ce1f78] | 359 | /// print p according to ShortOut in lmRing & tailRing |
---|
[538512] | 360 | void p_String0(poly p, ring lmRing, ring tailRing); |
---|
[ce1f78] | 361 | char* p_String(poly p, ring lmRing, ring tailRing); |
---|
[35aab3] | 362 | void p_Write(poly p, ring lmRing, ring tailRing); |
---|
| 363 | void p_Write0(poly p, ring lmRing, ring tailRing); |
---|
| 364 | void p_wrp(poly p, ring lmRing, ring tailRing); |
---|
| 365 | |
---|
[ce1f78] | 366 | /// print p in a short way, if possible |
---|
[538512] | 367 | void p_String0Short(const poly p, ring lmRing, ring tailRing); |
---|
[ce1f78] | 368 | |
---|
| 369 | /// print p in a long way |
---|
[538512] | 370 | void p_String0Long(const poly p, ring lmRing, ring tailRing); |
---|
[ce1f78] | 371 | |
---|
| 372 | |
---|
[35aab3] | 373 | /*************************************************************** |
---|
| 374 | * |
---|
| 375 | * Degree stuff -- see p_polys.cc for explainations |
---|
| 376 | * |
---|
| 377 | ***************************************************************/ |
---|
[aa450d] | 378 | |
---|
| 379 | static inline long p_FDeg(const poly p, const ring r) { return r->pFDeg(p,r); } |
---|
| 380 | static inline long p_LDeg(const poly p, int *l, const ring r) { return r->pLDeg(p,l,r); } |
---|
| 381 | |
---|
[19ae652] | 382 | long p_WFirstTotalDegree(poly p, ring r); |
---|
| 383 | long p_WTotaldegree(poly p, const ring r); |
---|
[bf183f] | 384 | long p_WDegree(poly p,const ring r); |
---|
[35aab3] | 385 | long pLDeg0(poly p,int *l, ring r); |
---|
| 386 | long pLDeg0c(poly p,int *l, ring r); |
---|
| 387 | long pLDegb(poly p,int *l, ring r); |
---|
| 388 | long pLDeg1(poly p,int *l, ring r); |
---|
| 389 | long pLDeg1c(poly p,int *l, ring r); |
---|
| 390 | long pLDeg1_Deg(poly p,int *l, ring r); |
---|
| 391 | long pLDeg1c_Deg(poly p,int *l, ring r); |
---|
| 392 | long pLDeg1_Totaldegree(poly p,int *l, ring r); |
---|
| 393 | long pLDeg1c_Totaldegree(poly p,int *l, ring r); |
---|
| 394 | long pLDeg1_WFirstTotalDegree(poly p,int *l, ring r); |
---|
| 395 | long pLDeg1c_WFirstTotalDegree(poly p,int *l, ring r); |
---|
[55e2df0] | 396 | |
---|
[f82bd3] | 397 | BOOLEAN p_EqualPolys(poly p1, poly p2, const ring r); |
---|
[c6a3eb2] | 398 | |
---|
[55e2df0] | 399 | /// same as the usual p_EqualPolys for polys belonging to *equal* rings |
---|
| 400 | BOOLEAN p_EqualPolys(poly p1, poly p2, const ring r1, const ring r2); |
---|
| 401 | |
---|
[c6a3eb2] | 402 | long p_Deg(poly a, const ring r); |
---|
[35aab3] | 403 | |
---|
| 404 | |
---|
[a04c5e] | 405 | /*************************************************************** |
---|
| 406 | * |
---|
| 407 | * Primitives for accessing and setting fields of a poly |
---|
| 408 | * |
---|
| 409 | ***************************************************************/ |
---|
| 410 | |
---|
| 411 | static inline number p_SetCoeff(poly p, number n, ring r) |
---|
| 412 | { |
---|
| 413 | p_LmCheckPolyRing2(p, r); |
---|
[8a8c9e] | 414 | n_Delete(&(p->coef), r->cf); |
---|
[a04c5e] | 415 | (p)->coef=n; |
---|
| 416 | return n; |
---|
| 417 | } |
---|
| 418 | |
---|
| 419 | // order |
---|
| 420 | static inline long p_GetOrder(poly p, ring r) |
---|
| 421 | { |
---|
| 422 | p_LmCheckPolyRing2(p, r); |
---|
| 423 | if (r->typ==NULL) return ((p)->exp[r->pOrdIndex]); |
---|
| 424 | int i=0; |
---|
| 425 | loop |
---|
| 426 | { |
---|
| 427 | switch(r->typ[i].ord_typ) |
---|
| 428 | { |
---|
[788fdf] | 429 | case ro_am: |
---|
[a04c5e] | 430 | case ro_wp_neg: |
---|
[4d47990] | 431 | return ((p->exp[r->pOrdIndex])-POLY_NEGWEIGHT_OFFSET); |
---|
[a04c5e] | 432 | case ro_syzcomp: |
---|
| 433 | case ro_syz: |
---|
| 434 | case ro_cp: |
---|
| 435 | i++; |
---|
| 436 | break; |
---|
| 437 | //case ro_dp: |
---|
| 438 | //case ro_wp: |
---|
| 439 | default: |
---|
| 440 | return ((p)->exp[r->pOrdIndex]); |
---|
| 441 | } |
---|
| 442 | } |
---|
| 443 | } |
---|
| 444 | |
---|
[20d9284] | 445 | |
---|
[a04c5e] | 446 | static inline unsigned long p_AddComp(poly p, unsigned long v, ring r) |
---|
| 447 | { |
---|
| 448 | p_LmCheckPolyRing2(p, r); |
---|
| 449 | pAssume2(rRing_has_Comp(r)); |
---|
| 450 | return __p_GetComp(p,r) += v; |
---|
| 451 | } |
---|
| 452 | static inline unsigned long p_SubComp(poly p, unsigned long v, ring r) |
---|
| 453 | { |
---|
| 454 | p_LmCheckPolyRing2(p, r); |
---|
| 455 | pAssume2(rRing_has_Comp(r)); |
---|
[8a8c9e] | 456 | _pPolyAssume2(__p_GetComp(p,r) >= v,p,r); |
---|
[a04c5e] | 457 | return __p_GetComp(p,r) -= v; |
---|
| 458 | } |
---|
| 459 | |
---|
| 460 | #ifndef HAVE_EXPSIZES |
---|
| 461 | |
---|
| 462 | /// get a single variable exponent |
---|
| 463 | /// @Note: |
---|
| 464 | /// the integer VarOffset encodes: |
---|
| 465 | /// 1. the position of a variable in the exponent vector p->exp (lower 24 bits) |
---|
| 466 | /// 2. number of bits to shift to the right in the upper 8 bits (which takes at most 6 bits for 64 bit) |
---|
| 467 | /// Thus VarOffset always has 2 zero higher bits! |
---|
| 468 | static inline long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset) |
---|
| 469 | { |
---|
| 470 | pAssume2((VarOffset >> (24 + 6)) == 0); |
---|
| 471 | #if 0 |
---|
| 472 | int pos=(VarOffset & 0xffffff); |
---|
| 473 | int bitpos=(VarOffset >> 24); |
---|
| 474 | unsigned long exp=(p->exp[pos] >> bitmask) & iBitmask; |
---|
| 475 | return exp; |
---|
| 476 | #else |
---|
| 477 | return (long) |
---|
| 478 | ((p->exp[(VarOffset & 0xffffff)] >> (VarOffset >> 24)) |
---|
| 479 | & iBitmask); |
---|
| 480 | #endif |
---|
| 481 | } |
---|
| 482 | |
---|
| 483 | |
---|
| 484 | /// set a single variable exponent |
---|
| 485 | /// @Note: |
---|
| 486 | /// VarOffset encodes the position in p->exp @see p_GetExp |
---|
| 487 | static inline unsigned long p_SetExp(poly p, const unsigned long e, const unsigned long iBitmask, const int VarOffset) |
---|
| 488 | { |
---|
| 489 | pAssume2(e>=0); |
---|
| 490 | pAssume2(e<=iBitmask); |
---|
| 491 | pAssume2((VarOffset >> (24 + 6)) == 0); |
---|
| 492 | |
---|
| 493 | // shift e to the left: |
---|
[b2ca85] | 494 | REGISTER int shift = VarOffset >> 24; |
---|
[a04c5e] | 495 | unsigned long ee = e << shift /*(VarOffset >> 24)*/; |
---|
| 496 | // find the bits in the exponent vector |
---|
[b2ca85] | 497 | REGISTER int offset = (VarOffset & 0xffffff); |
---|
[a04c5e] | 498 | // clear the bits in the exponent vector: |
---|
| 499 | p->exp[offset] &= ~( iBitmask << shift ); |
---|
| 500 | // insert e with | |
---|
| 501 | p->exp[ offset ] |= ee; |
---|
| 502 | return e; |
---|
| 503 | } |
---|
| 504 | |
---|
| 505 | |
---|
| 506 | #else // #ifdef HAVE_EXPSIZES // EXPERIMENTAL!!! |
---|
| 507 | |
---|
| 508 | static inline unsigned long BitMask(unsigned long bitmask, int twobits) |
---|
| 509 | { |
---|
| 510 | // bitmask = 00000111111111111 |
---|
| 511 | // 0 must give bitmask! |
---|
| 512 | // 1, 2, 3 - anything like 00011..11 |
---|
| 513 | pAssume2((twobits >> 2) == 0); |
---|
| 514 | static const unsigned long _bitmasks[4] = {-1, 0x7fff, 0x7f, 0x3}; |
---|
| 515 | return bitmask & _bitmasks[twobits]; |
---|
| 516 | } |
---|
| 517 | |
---|
| 518 | |
---|
| 519 | /// @Note: we may add some more info (6 ) into VarOffset and thus encode |
---|
| 520 | static inline long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset) |
---|
| 521 | { |
---|
| 522 | int pos =(VarOffset & 0xffffff); |
---|
| 523 | int hbyte= (VarOffset >> 24); // the highest byte |
---|
| 524 | int bitpos = hbyte & 0x3f; // last 6 bits |
---|
| 525 | long bitmask = BitMask(iBitmask, hbyte >> 6); |
---|
| 526 | |
---|
| 527 | long exp=(p->exp[pos] >> bitpos) & bitmask; |
---|
| 528 | return exp; |
---|
| 529 | |
---|
| 530 | } |
---|
| 531 | |
---|
| 532 | static inline long p_SetExp(poly p, const long e, const unsigned long iBitmask, const int VarOffset) |
---|
| 533 | { |
---|
| 534 | pAssume2(e>=0); |
---|
| 535 | pAssume2(e <= BitMask(iBitmask, VarOffset >> 30)); |
---|
| 536 | |
---|
| 537 | // shift e to the left: |
---|
[b2ca85] | 538 | REGISTER int hbyte = VarOffset >> 24; |
---|
[a04c5e] | 539 | int bitmask = BitMask(iBitmask, hbyte >> 6); |
---|
[b2ca85] | 540 | REGISTER int shift = hbyte & 0x3f; |
---|
[a04c5e] | 541 | long ee = e << shift; |
---|
| 542 | // find the bits in the exponent vector |
---|
[b2ca85] | 543 | REGISTER int offset = (VarOffset & 0xffffff); |
---|
[a04c5e] | 544 | // clear the bits in the exponent vector: |
---|
| 545 | p->exp[offset] &= ~( bitmask << shift ); |
---|
| 546 | // insert e with | |
---|
| 547 | p->exp[ offset ] |= ee; |
---|
| 548 | return e; |
---|
| 549 | } |
---|
| 550 | |
---|
| 551 | #endif // #ifndef HAVE_EXPSIZES |
---|
| 552 | |
---|
| 553 | |
---|
| 554 | static inline long p_GetExp(const poly p, const ring r, const int VarOffset) |
---|
| 555 | { |
---|
| 556 | p_LmCheckPolyRing2(p, r); |
---|
| 557 | pAssume2(VarOffset != -1); |
---|
| 558 | return p_GetExp(p, r->bitmask, VarOffset); |
---|
| 559 | } |
---|
| 560 | |
---|
| 561 | static inline long p_SetExp(poly p, const long e, const ring r, const int VarOffset) |
---|
| 562 | { |
---|
| 563 | p_LmCheckPolyRing2(p, r); |
---|
| 564 | pAssume2(VarOffset != -1); |
---|
| 565 | return p_SetExp(p, e, r->bitmask, VarOffset); |
---|
| 566 | } |
---|
| 567 | |
---|
| 568 | |
---|
| 569 | |
---|
| 570 | /// get v^th exponent for a monomial |
---|
| 571 | static inline long p_GetExp(const poly p, const int v, const ring r) |
---|
| 572 | { |
---|
| 573 | p_LmCheckPolyRing2(p, r); |
---|
| 574 | pAssume2(v>0 && v <= r->N); |
---|
| 575 | pAssume2(r->VarOffset[v] != -1); |
---|
| 576 | return p_GetExp(p, r->bitmask, r->VarOffset[v]); |
---|
| 577 | } |
---|
| 578 | |
---|
| 579 | |
---|
| 580 | /// set v^th exponent for a monomial |
---|
| 581 | static inline long p_SetExp(poly p, const int v, const long e, const ring r) |
---|
| 582 | { |
---|
| 583 | p_LmCheckPolyRing2(p, r); |
---|
| 584 | pAssume2(v>0 && v <= r->N); |
---|
| 585 | pAssume2(r->VarOffset[v] != -1); |
---|
| 586 | return p_SetExp(p, e, r->bitmask, r->VarOffset[v]); |
---|
| 587 | } |
---|
| 588 | |
---|
| 589 | // the following should be implemented more efficiently |
---|
| 590 | static inline long p_IncrExp(poly p, int v, ring r) |
---|
| 591 | { |
---|
| 592 | p_LmCheckPolyRing2(p, r); |
---|
| 593 | int e = p_GetExp(p,v,r); |
---|
| 594 | e++; |
---|
| 595 | return p_SetExp(p,v,e,r); |
---|
| 596 | } |
---|
| 597 | static inline long p_DecrExp(poly p, int v, ring r) |
---|
| 598 | { |
---|
| 599 | p_LmCheckPolyRing2(p, r); |
---|
| 600 | int e = p_GetExp(p,v,r); |
---|
| 601 | pAssume2(e > 0); |
---|
| 602 | e--; |
---|
| 603 | return p_SetExp(p,v,e,r); |
---|
| 604 | } |
---|
| 605 | static inline long p_AddExp(poly p, int v, long ee, ring r) |
---|
| 606 | { |
---|
| 607 | p_LmCheckPolyRing2(p, r); |
---|
| 608 | int e = p_GetExp(p,v,r); |
---|
| 609 | e += ee; |
---|
| 610 | return p_SetExp(p,v,e,r); |
---|
| 611 | } |
---|
| 612 | static inline long p_SubExp(poly p, int v, long ee, ring r) |
---|
| 613 | { |
---|
| 614 | p_LmCheckPolyRing2(p, r); |
---|
| 615 | long e = p_GetExp(p,v,r); |
---|
| 616 | pAssume2(e >= ee); |
---|
| 617 | e -= ee; |
---|
| 618 | return p_SetExp(p,v,e,r); |
---|
| 619 | } |
---|
| 620 | static inline long p_MultExp(poly p, int v, long ee, ring r) |
---|
| 621 | { |
---|
| 622 | p_LmCheckPolyRing2(p, r); |
---|
| 623 | long e = p_GetExp(p,v,r); |
---|
| 624 | e *= ee; |
---|
| 625 | return p_SetExp(p,v,e,r); |
---|
| 626 | } |
---|
| 627 | |
---|
| 628 | static inline long p_GetExpSum(poly p1, poly p2, int i, ring r) |
---|
| 629 | { |
---|
| 630 | p_LmCheckPolyRing2(p1, r); |
---|
| 631 | p_LmCheckPolyRing2(p2, r); |
---|
| 632 | return p_GetExp(p1,i,r) + p_GetExp(p2,i,r); |
---|
| 633 | } |
---|
| 634 | static inline long p_GetExpDiff(poly p1, poly p2, int i, ring r) |
---|
| 635 | { |
---|
| 636 | return p_GetExp(p1,i,r) - p_GetExp(p2,i,r); |
---|
| 637 | } |
---|
| 638 | |
---|
[5948a8] | 639 | static inline int p_Comp_k_n(poly a, poly b, int k, ring r) |
---|
| 640 | { |
---|
| 641 | if ((a==NULL) || (b==NULL) ) return FALSE; |
---|
| 642 | p_LmCheckPolyRing2(a, r); |
---|
| 643 | p_LmCheckPolyRing2(b, r); |
---|
| 644 | pAssume2(k > 0 && k <= r->N); |
---|
| 645 | int i=k; |
---|
| 646 | for(;i<=r->N;i++) |
---|
| 647 | { |
---|
| 648 | if (p_GetExp(a,i,r) != p_GetExp(b,i,r)) return FALSE; |
---|
| 649 | // if (a->exp[(r->VarOffset[i] & 0xffffff)] != b->exp[(r->VarOffset[i] & 0xffffff)]) return FALSE; |
---|
| 650 | } |
---|
| 651 | return TRUE; |
---|
| 652 | } |
---|
| 653 | |
---|
[a04c5e] | 654 | |
---|
| 655 | /*************************************************************** |
---|
| 656 | * |
---|
| 657 | * Allocation/Initalization/Deletion |
---|
| 658 | * |
---|
| 659 | ***************************************************************/ |
---|
[e37661] | 660 | #if (OM_TRACK > 2) && defined(OM_TRACK_CUSTOM) |
---|
[0276c1] | 661 | static inline poly p_New(const ring r, omBin bin) |
---|
| 662 | #else |
---|
[2e4ec14] | 663 | static inline poly p_New(const ring /*r*/, omBin bin) |
---|
[0276c1] | 664 | #endif |
---|
[a04c5e] | 665 | { |
---|
| 666 | p_CheckRing2(r); |
---|
[aa2b525] | 667 | pAssume2(bin != NULL && omSizeWOfBin(r->PolyBin) == omSizeWOfBin(bin)); |
---|
[a04c5e] | 668 | poly p; |
---|
| 669 | omTypeAllocBin(poly, p, bin); |
---|
| 670 | p_SetRingOfLm(p, r); |
---|
| 671 | return p; |
---|
| 672 | } |
---|
| 673 | |
---|
| 674 | static inline poly p_New(ring r) |
---|
| 675 | { |
---|
| 676 | return p_New(r, r->PolyBin); |
---|
| 677 | } |
---|
| 678 | |
---|
[0276c1] | 679 | #if PDEBUG > 2 |
---|
[a04c5e] | 680 | static inline void p_LmFree(poly p, ring r) |
---|
[0276c1] | 681 | #else |
---|
| 682 | static inline void p_LmFree(poly p, ring) |
---|
| 683 | #endif |
---|
[a04c5e] | 684 | { |
---|
| 685 | p_LmCheckPolyRing2(p, r); |
---|
| 686 | omFreeBinAddr(p); |
---|
| 687 | } |
---|
[0276c1] | 688 | #if PDEBUG > 2 |
---|
[a04c5e] | 689 | static inline void p_LmFree(poly *p, ring r) |
---|
[0276c1] | 690 | #else |
---|
[f323dd1] | 691 | static inline void p_LmFree(poly *p, ring) |
---|
[0276c1] | 692 | #endif |
---|
[a04c5e] | 693 | { |
---|
| 694 | p_LmCheckPolyRing2(*p, r); |
---|
| 695 | poly h = *p; |
---|
| 696 | *p = pNext(h); |
---|
| 697 | omFreeBinAddr(h); |
---|
| 698 | } |
---|
[0276c1] | 699 | #if PDEBUG > 2 |
---|
[a04c5e] | 700 | static inline poly p_LmFreeAndNext(poly p, ring r) |
---|
[0276c1] | 701 | #else |
---|
| 702 | static inline poly p_LmFreeAndNext(poly p, ring) |
---|
| 703 | #endif |
---|
[a04c5e] | 704 | { |
---|
| 705 | p_LmCheckPolyRing2(p, r); |
---|
| 706 | poly pnext = pNext(p); |
---|
| 707 | omFreeBinAddr(p); |
---|
| 708 | return pnext; |
---|
| 709 | } |
---|
[8a8c9e] | 710 | static inline void p_LmDelete(poly p, const ring r) |
---|
[a04c5e] | 711 | { |
---|
| 712 | p_LmCheckPolyRing2(p, r); |
---|
[8a8c9e] | 713 | n_Delete(&pGetCoeff(p), r->cf); |
---|
[a04c5e] | 714 | omFreeBinAddr(p); |
---|
| 715 | } |
---|
[8a8c9e] | 716 | static inline void p_LmDelete(poly *p, const ring r) |
---|
[a04c5e] | 717 | { |
---|
| 718 | p_LmCheckPolyRing2(*p, r); |
---|
| 719 | poly h = *p; |
---|
| 720 | *p = pNext(h); |
---|
[8a8c9e] | 721 | n_Delete(&pGetCoeff(h), r->cf); |
---|
[a04c5e] | 722 | omFreeBinAddr(h); |
---|
| 723 | } |
---|
[8a8c9e] | 724 | static inline poly p_LmDeleteAndNext(poly p, const ring r) |
---|
[a04c5e] | 725 | { |
---|
| 726 | p_LmCheckPolyRing2(p, r); |
---|
| 727 | poly pnext = pNext(p); |
---|
[8a8c9e] | 728 | n_Delete(&pGetCoeff(p), r->cf); |
---|
[a04c5e] | 729 | omFreeBinAddr(p); |
---|
| 730 | return pnext; |
---|
| 731 | } |
---|
| 732 | |
---|
| 733 | /*************************************************************** |
---|
| 734 | * |
---|
| 735 | * Misc routines |
---|
| 736 | * |
---|
| 737 | ***************************************************************/ |
---|
[20d9284] | 738 | |
---|
[21c6b3] | 739 | /// return the maximal exponent of p in form of the maximal long var |
---|
| 740 | unsigned long p_GetMaxExpL(poly p, const ring r, unsigned long l_max = 0); |
---|
[a04c5e] | 741 | |
---|
[21c6b3] | 742 | /// return monomial r such that GetExp(r,i) is maximum of all |
---|
| 743 | /// monomials in p; coeff == 0, next == NULL, ord is not set |
---|
| 744 | poly p_GetMaxExpP(poly p, ring r); |
---|
[a04c5e] | 745 | |
---|
| 746 | static inline unsigned long p_GetMaxExp(const unsigned long l, const ring r) |
---|
| 747 | { |
---|
| 748 | unsigned long bitmask = r->bitmask; |
---|
| 749 | unsigned long max = (l & bitmask); |
---|
| 750 | unsigned long j = r->ExpPerLong - 1; |
---|
| 751 | |
---|
| 752 | if (j > 0) |
---|
| 753 | { |
---|
| 754 | unsigned long i = r->BitsPerExp; |
---|
| 755 | long e; |
---|
| 756 | loop |
---|
| 757 | { |
---|
| 758 | e = ((l >> i) & bitmask); |
---|
| 759 | if ((unsigned long) e > max) |
---|
| 760 | max = e; |
---|
| 761 | j--; |
---|
| 762 | if (j==0) break; |
---|
| 763 | i += r->BitsPerExp; |
---|
| 764 | } |
---|
| 765 | } |
---|
| 766 | return max; |
---|
| 767 | } |
---|
| 768 | |
---|
[21c6b3] | 769 | static inline unsigned long p_GetMaxExp(const poly p, const ring r) |
---|
| 770 | { |
---|
| 771 | return p_GetMaxExp(p_GetMaxExpL(p, r), r); |
---|
| 772 | } |
---|
| 773 | |
---|
[a04c5e] | 774 | static inline unsigned long |
---|
| 775 | p_GetTotalDegree(const unsigned long l, const ring r, const int number_of_exps) |
---|
| 776 | { |
---|
| 777 | const unsigned long bitmask = r->bitmask; |
---|
| 778 | unsigned long sum = (l & bitmask); |
---|
| 779 | unsigned long j = number_of_exps - 1; |
---|
| 780 | |
---|
| 781 | if (j > 0) |
---|
| 782 | { |
---|
| 783 | unsigned long i = r->BitsPerExp; |
---|
| 784 | loop |
---|
| 785 | { |
---|
| 786 | sum += ((l >> i) & bitmask); |
---|
| 787 | j--; |
---|
| 788 | if (j==0) break; |
---|
| 789 | i += r->BitsPerExp; |
---|
| 790 | } |
---|
| 791 | } |
---|
| 792 | return sum; |
---|
| 793 | } |
---|
| 794 | |
---|
| 795 | /*************************************************************** |
---|
| 796 | * |
---|
| 797 | * Dispatcher to r->p_Procs, they do the tests/checks |
---|
| 798 | * |
---|
| 799 | ***************************************************************/ |
---|
[5b45a4] | 800 | /// returns a copy of p (without any additional testing) |
---|
| 801 | static inline poly p_Copy_noCheck(poly p, const ring r) |
---|
| 802 | { |
---|
[127208] | 803 | /*assume(p!=NULL);*/ |
---|
| 804 | assume(r != NULL); |
---|
| 805 | assume(r->p_Procs != NULL); |
---|
| 806 | assume(r->p_Procs->p_Copy != NULL); |
---|
[5b45a4] | 807 | return r->p_Procs->p_Copy(p, r); |
---|
| 808 | } |
---|
| 809 | |
---|
| 810 | /// returns a copy of p |
---|
[a04c5e] | 811 | static inline poly p_Copy(poly p, const ring r) |
---|
| 812 | { |
---|
[127208] | 813 | if (p!=NULL) |
---|
| 814 | { |
---|
| 815 | p_Test(p,r); |
---|
| 816 | const poly pp = p_Copy_noCheck(p, r); |
---|
| 817 | p_Test(pp,r); |
---|
| 818 | return pp; |
---|
| 819 | } |
---|
| 820 | else |
---|
| 821 | return NULL; |
---|
[a04c5e] | 822 | } |
---|
| 823 | |
---|
[d59bc4] | 824 | /// copy the i(leading) term of p |
---|
[20d9284] | 825 | static inline poly p_Head(poly p, const ring r) |
---|
| 826 | { |
---|
| 827 | if (p == NULL) return NULL; |
---|
| 828 | p_LmCheckPolyRing1(p, r); |
---|
| 829 | poly np; |
---|
| 830 | omTypeAllocBin(poly, np, r->PolyBin); |
---|
| 831 | p_SetRingOfLm(np, r); |
---|
[304ad9b] | 832 | memcpy(np->exp, p->exp, r->ExpL_Size*sizeof(long)); |
---|
[20d9284] | 833 | pNext(np) = NULL; |
---|
| 834 | pSetCoeff0(np, n_Copy(pGetCoeff(p), r->cf)); |
---|
| 835 | return np; |
---|
| 836 | } |
---|
| 837 | |
---|
[d59bc4] | 838 | /// like p_Head, but with coefficient 1 |
---|
| 839 | poly p_CopyPowerProduct(poly p, const ring r); |
---|
| 840 | |
---|
| 841 | /// returns a copy of p with Lm(p) from lmRing and Tail(p) from tailRing |
---|
[a04c5e] | 842 | static inline poly p_Copy(poly p, const ring lmRing, const ring tailRing) |
---|
| 843 | { |
---|
| 844 | if (p != NULL) |
---|
| 845 | { |
---|
[eb55f8a] | 846 | #ifndef PDEBUG |
---|
| 847 | if (tailRing == lmRing) |
---|
[5b45a4] | 848 | return p_Copy_noCheck(p, tailRing); |
---|
[eb55f8a] | 849 | #endif |
---|
[a04c5e] | 850 | poly pres = p_Head(p, lmRing); |
---|
[127208] | 851 | if (pNext(p)!=NULL) |
---|
| 852 | pNext(pres) = p_Copy_noCheck(pNext(p), tailRing); |
---|
[a04c5e] | 853 | return pres; |
---|
| 854 | } |
---|
| 855 | else |
---|
| 856 | return NULL; |
---|
| 857 | } |
---|
| 858 | |
---|
| 859 | // deletes *p, and sets *p to NULL |
---|
| 860 | static inline void p_Delete(poly *p, const ring r) |
---|
| 861 | { |
---|
[fea494] | 862 | assume( p!= NULL ); |
---|
[42f46c] | 863 | assume( r!= NULL ); |
---|
[127208] | 864 | if ((*p)!=NULL) r->p_Procs->p_Delete(p, r); |
---|
[a04c5e] | 865 | } |
---|
| 866 | |
---|
| 867 | static inline void p_Delete(poly *p, const ring lmRing, const ring tailRing) |
---|
| 868 | { |
---|
[fea494] | 869 | assume( p!= NULL ); |
---|
[a04c5e] | 870 | if (*p != NULL) |
---|
| 871 | { |
---|
[eb55f8a] | 872 | #ifndef PDEBUG |
---|
| 873 | if (tailRing == lmRing) |
---|
| 874 | { |
---|
| 875 | p_Delete(p, tailRing); |
---|
| 876 | return; |
---|
| 877 | } |
---|
| 878 | #endif |
---|
[a04c5e] | 879 | if (pNext(*p) != NULL) |
---|
[eb55f8a] | 880 | p_Delete(&pNext(*p), tailRing); |
---|
[a04c5e] | 881 | p_LmDelete(p, lmRing); |
---|
| 882 | } |
---|
| 883 | } |
---|
| 884 | |
---|
[20d9284] | 885 | // copys monomials of p, allocates new monomials from bin, |
---|
[b440c7] | 886 | // deletes monomials of p |
---|
[a04c5e] | 887 | static inline poly p_ShallowCopyDelete(poly p, const ring r, omBin bin) |
---|
| 888 | { |
---|
| 889 | p_LmCheckPolyRing2(p, r); |
---|
[aa2b525] | 890 | pAssume2(omSizeWOfBin(r->PolyBin) == omSizeWOfBin(bin)); |
---|
[a04c5e] | 891 | return r->p_Procs->p_ShallowCopyDelete(p, r, bin); |
---|
| 892 | } |
---|
| 893 | |
---|
| 894 | // returns p+q, destroys p and q |
---|
| 895 | static inline poly p_Add_q(poly p, poly q, const ring r) |
---|
| 896 | { |
---|
[5f4015a] | 897 | assume( (p != q) || (p == NULL && q == NULL) ); |
---|
[04b7a73] | 898 | if (q==NULL) return p; |
---|
| 899 | if (p==NULL) return q; |
---|
[a04c5e] | 900 | int shorter; |
---|
| 901 | return r->p_Procs->p_Add_q(p, q, shorter, r); |
---|
| 902 | } |
---|
| 903 | |
---|
[20d9284] | 904 | /// like p_Add_q, except that if lp == pLength(lp) lq == pLength(lq) then lp == pLength(p+q) |
---|
[0d1a36] | 905 | static inline poly p_Add_q(poly p, poly q, int &lp, int lq, const ring r) |
---|
[a04c5e] | 906 | { |
---|
[5f4015a] | 907 | assume( (p != q) || (p == NULL && q == NULL) ); |
---|
[04b7a73] | 908 | if (q==NULL) return p; |
---|
| 909 | if (p==NULL) { lp=lq; return q; } |
---|
[a04c5e] | 910 | int shorter; |
---|
| 911 | poly res = r->p_Procs->p_Add_q(p, q, shorter, r); |
---|
[7abd61] | 912 | lp += lq - shorter; |
---|
[a04c5e] | 913 | return res; |
---|
| 914 | } |
---|
[35aab3] | 915 | |
---|
[a04c5e] | 916 | // returns p*n, destroys p |
---|
| 917 | static inline poly p_Mult_nn(poly p, number n, const ring r) |
---|
| 918 | { |
---|
[04b7a73] | 919 | if (p==NULL) return NULL; |
---|
[8a8c9e] | 920 | if (n_IsOne(n, r->cf)) |
---|
[a04c5e] | 921 | return p; |
---|
[1c5671] | 922 | else if (n_IsZero(n, r->cf)) |
---|
[235b2a] | 923 | { |
---|
[127208] | 924 | p_Delete(&p, r); // NOTE: without p_Delete - memory leak! |
---|
[bc9d2e] | 925 | return NULL; |
---|
[04b7a73] | 926 | } |
---|
| 927 | else |
---|
[a04c5e] | 928 | return r->p_Procs->p_Mult_nn(p, n, r); |
---|
| 929 | } |
---|
[3d1222a] | 930 | #define __p_Mult_nn(p,n,r) r->p_Procs->p_Mult_nn(p, n, r) |
---|
[a04c5e] | 931 | |
---|
| 932 | static inline poly p_Mult_nn(poly p, number n, const ring lmRing, |
---|
| 933 | const ring tailRing) |
---|
| 934 | { |
---|
[04b7a73] | 935 | assume(p!=NULL); |
---|
[a04c5e] | 936 | #ifndef PDEBUG |
---|
| 937 | if (lmRing == tailRing) |
---|
| 938 | return p_Mult_nn(p, n, tailRing); |
---|
| 939 | #endif |
---|
| 940 | poly pnext = pNext(p); |
---|
| 941 | pNext(p) = NULL; |
---|
| 942 | p = lmRing->p_Procs->p_Mult_nn(p, n, lmRing); |
---|
[4809565] | 943 | if (pnext!=NULL) |
---|
| 944 | { |
---|
| 945 | pNext(p) = tailRing->p_Procs->p_Mult_nn(pnext, n, tailRing); |
---|
| 946 | } |
---|
[a04c5e] | 947 | return p; |
---|
| 948 | } |
---|
| 949 | |
---|
| 950 | // returns p*n, does not destroy p |
---|
| 951 | static inline poly pp_Mult_nn(poly p, number n, const ring r) |
---|
| 952 | { |
---|
[04b7a73] | 953 | if (p==NULL) return NULL; |
---|
[8a8c9e] | 954 | if (n_IsOne(n, r->cf)) |
---|
[a04c5e] | 955 | return p_Copy(p, r); |
---|
[3d1222a] | 956 | else if (n_IsZero(n, r->cf)) |
---|
| 957 | return NULL; |
---|
[a04c5e] | 958 | else |
---|
| 959 | return r->p_Procs->pp_Mult_nn(p, n, r); |
---|
| 960 | } |
---|
[3d1222a] | 961 | #define __pp_Mult_nn(p,n,r) r->p_Procs->pp_Mult_nn(p, n, r) |
---|
[a04c5e] | 962 | |
---|
[20d9284] | 963 | // test if the monomial is a constant as a vector component |
---|
| 964 | // i.e., test if all exponents are zero |
---|
| 965 | static inline BOOLEAN p_LmIsConstantComp(const poly p, const ring r) |
---|
| 966 | { |
---|
| 967 | //p_LmCheckPolyRing(p, r); |
---|
| 968 | int i = r->VarL_Size - 1; |
---|
| 969 | |
---|
| 970 | do |
---|
| 971 | { |
---|
| 972 | if (p->exp[r->VarL_Offset[i]] != 0) |
---|
| 973 | return FALSE; |
---|
| 974 | i--; |
---|
| 975 | } |
---|
| 976 | while (i >= 0); |
---|
| 977 | return TRUE; |
---|
| 978 | } |
---|
| 979 | |
---|
| 980 | // test if monomial is a constant, i.e. if all exponents and the component |
---|
| 981 | // is zero |
---|
| 982 | static inline BOOLEAN p_LmIsConstant(const poly p, const ring r) |
---|
| 983 | { |
---|
| 984 | if (p_LmIsConstantComp(p, r)) |
---|
| 985 | return (p_GetComp(p, r) == 0); |
---|
| 986 | return FALSE; |
---|
| 987 | } |
---|
| 988 | |
---|
[a04c5e] | 989 | // returns Copy(p)*m, does neither destroy p nor m |
---|
| 990 | static inline poly pp_Mult_mm(poly p, poly m, const ring r) |
---|
| 991 | { |
---|
[04b7a73] | 992 | if (p==NULL) return NULL; |
---|
[a04c5e] | 993 | if (p_LmIsConstant(m, r)) |
---|
[3d1222a] | 994 | return __pp_Mult_nn(p, pGetCoeff(m), r); |
---|
[a04c5e] | 995 | else |
---|
[abe5c8] | 996 | return r->p_Procs->pp_Mult_mm(p, m, r); |
---|
[a04c5e] | 997 | } |
---|
| 998 | |
---|
| 999 | // returns p*m, destroys p, const: m |
---|
| 1000 | static inline poly p_Mult_mm(poly p, poly m, const ring r) |
---|
| 1001 | { |
---|
[04b7a73] | 1002 | if (p==NULL) return NULL; |
---|
[a04c5e] | 1003 | if (p_LmIsConstant(m, r)) |
---|
[3d1222a] | 1004 | return __p_Mult_nn(p, pGetCoeff(m), r); |
---|
[a04c5e] | 1005 | else |
---|
| 1006 | return r->p_Procs->p_Mult_mm(p, m, r); |
---|
| 1007 | } |
---|
| 1008 | |
---|
[0d1a36] | 1009 | static inline poly p_Minus_mm_Mult_qq(poly p, const poly m, const poly q, int &lp, int lq, |
---|
| 1010 | const poly spNoether, const ring r) |
---|
[a497a1] | 1011 | { |
---|
[abe5c8] | 1012 | int shorter; |
---|
| 1013 | const poly res = r->p_Procs->p_Minus_mm_Mult_qq(p, m, q, shorter, spNoether, r); |
---|
[a497a1] | 1014 | lp += lq - shorter; |
---|
[98b2b91] | 1015 | // assume( lp == pLength(res) ); |
---|
[a497a1] | 1016 | return res; |
---|
[a04c5e] | 1017 | } |
---|
| 1018 | |
---|
[a497a1] | 1019 | // return p - m*Copy(q), destroys p; const: p,m |
---|
| 1020 | static inline poly p_Minus_mm_Mult_qq(poly p, const poly m, const poly q, const ring r) |
---|
[a04c5e] | 1021 | { |
---|
| 1022 | int shorter; |
---|
[a497a1] | 1023 | |
---|
[abe5c8] | 1024 | return r->p_Procs->p_Minus_mm_Mult_qq(p, m, q, shorter, NULL, r); |
---|
[a04c5e] | 1025 | } |
---|
| 1026 | |
---|
[a497a1] | 1027 | |
---|
[20d9284] | 1028 | // returns p*Coeff(m) for such monomials pm of p, for which m is divisble by pm |
---|
[a04c5e] | 1029 | static inline poly pp_Mult_Coeff_mm_DivSelect(poly p, const poly m, const ring r) |
---|
| 1030 | { |
---|
| 1031 | int shorter; |
---|
| 1032 | return r->p_Procs->pp_Mult_Coeff_mm_DivSelect(p, m, shorter, r); |
---|
| 1033 | } |
---|
| 1034 | |
---|
[20d9284] | 1035 | // returns p*Coeff(m) for such monomials pm of p, for which m is divisble by pm |
---|
| 1036 | // if lp is length of p on input then lp is length of returned poly on output |
---|
[a04c5e] | 1037 | static inline poly pp_Mult_Coeff_mm_DivSelect(poly p, int &lp, const poly m, const ring r) |
---|
| 1038 | { |
---|
| 1039 | int shorter; |
---|
| 1040 | poly pp = r->p_Procs->pp_Mult_Coeff_mm_DivSelect(p, m, shorter, r); |
---|
| 1041 | lp -= shorter; |
---|
| 1042 | return pp; |
---|
| 1043 | } |
---|
| 1044 | |
---|
| 1045 | // returns -p, destroys p |
---|
| 1046 | static inline poly p_Neg(poly p, const ring r) |
---|
| 1047 | { |
---|
| 1048 | return r->p_Procs->p_Neg(p, r); |
---|
| 1049 | } |
---|
| 1050 | |
---|
| 1051 | extern poly _p_Mult_q(poly p, poly q, const int copy, const ring r); |
---|
| 1052 | // returns p*q, destroys p and q |
---|
| 1053 | static inline poly p_Mult_q(poly p, poly q, const ring r) |
---|
| 1054 | { |
---|
[5f4015a] | 1055 | assume( (p != q) || (p == NULL && q == NULL) ); |
---|
[f323dd1] | 1056 | |
---|
[a04c5e] | 1057 | if (p == NULL) |
---|
| 1058 | { |
---|
[127208] | 1059 | p_Delete(&q, r); |
---|
[a04c5e] | 1060 | return NULL; |
---|
| 1061 | } |
---|
| 1062 | if (q == NULL) |
---|
| 1063 | { |
---|
[127208] | 1064 | p_Delete(&p, r); |
---|
[a04c5e] | 1065 | return NULL; |
---|
| 1066 | } |
---|
| 1067 | |
---|
| 1068 | if (pNext(p) == NULL) |
---|
| 1069 | { |
---|
[a9277b] | 1070 | q = r->p_Procs->p_mm_Mult(q, p, r); |
---|
[127208] | 1071 | p_LmDelete(&p, r); |
---|
[a04c5e] | 1072 | return q; |
---|
| 1073 | } |
---|
| 1074 | |
---|
| 1075 | if (pNext(q) == NULL) |
---|
| 1076 | { |
---|
[0ec309] | 1077 | p = r->p_Procs->p_Mult_mm(p, q, r); |
---|
[127208] | 1078 | p_LmDelete(&q, r); |
---|
[a04c5e] | 1079 | return p; |
---|
| 1080 | } |
---|
| 1081 | #ifdef HAVE_PLURAL |
---|
[7b6acd] | 1082 | if (rIsNCRing(r)) |
---|
[a04c5e] | 1083 | return _nc_p_Mult_q(p, q, r); |
---|
| 1084 | else |
---|
| 1085 | #endif |
---|
| 1086 | return _p_Mult_q(p, q, 0, r); |
---|
| 1087 | } |
---|
| 1088 | |
---|
| 1089 | // returns p*q, does neither destroy p nor q |
---|
| 1090 | static inline poly pp_Mult_qq(poly p, poly q, const ring r) |
---|
| 1091 | { |
---|
| 1092 | if (p == NULL || q == NULL) return NULL; |
---|
| 1093 | |
---|
| 1094 | if (pNext(p) == NULL) |
---|
| 1095 | { |
---|
[63f34f] | 1096 | return r->p_Procs->pp_mm_Mult(q, p, r); |
---|
[a04c5e] | 1097 | } |
---|
| 1098 | |
---|
| 1099 | if (pNext(q) == NULL) |
---|
| 1100 | { |
---|
[abe5c8] | 1101 | return r->p_Procs->pp_Mult_mm(p, q, r); |
---|
[a04c5e] | 1102 | } |
---|
| 1103 | |
---|
| 1104 | poly qq = q; |
---|
| 1105 | if (p == q) |
---|
| 1106 | qq = p_Copy(q, r); |
---|
| 1107 | |
---|
| 1108 | poly res; |
---|
| 1109 | #ifdef HAVE_PLURAL |
---|
| 1110 | if (rIsPluralRing(r)) |
---|
| 1111 | res = _nc_pp_Mult_qq(p, qq, r); |
---|
| 1112 | else |
---|
| 1113 | #endif |
---|
| 1114 | res = _p_Mult_q(p, qq, 1, r); |
---|
| 1115 | |
---|
| 1116 | if (qq != q) |
---|
| 1117 | p_Delete(&qq, r); |
---|
| 1118 | return res; |
---|
| 1119 | } |
---|
| 1120 | |
---|
| 1121 | // returns p + m*q destroys p, const: q, m |
---|
[0d1a36] | 1122 | static inline poly p_Plus_mm_Mult_qq(poly p, poly m, poly q, int &lp, int lq, |
---|
[a04c5e] | 1123 | const ring r) |
---|
| 1124 | { |
---|
| 1125 | #ifdef HAVE_PLURAL |
---|
| 1126 | if (rIsPluralRing(r)) |
---|
| 1127 | return nc_p_Plus_mm_Mult_qq(p, m, q, lp, lq, r); |
---|
| 1128 | #endif |
---|
| 1129 | |
---|
| 1130 | // this should be implemented more efficiently |
---|
[abe5c8] | 1131 | poly res; |
---|
[a04c5e] | 1132 | int shorter; |
---|
| 1133 | number n_old = pGetCoeff(m); |
---|
[8a8c9e] | 1134 | number n_neg = n_Copy(n_old, r->cf); |
---|
[ec89bb4] | 1135 | n_neg = n_InpNeg(n_neg, r->cf); |
---|
[a04c5e] | 1136 | pSetCoeff0(m, n_neg); |
---|
[abe5c8] | 1137 | res = r->p_Procs->p_Minus_mm_Mult_qq(p, m, q, shorter, NULL, r); |
---|
[a04c5e] | 1138 | lp = (lp + lq) - shorter; |
---|
| 1139 | pSetCoeff0(m, n_old); |
---|
[8a8c9e] | 1140 | n_Delete(&n_neg, r->cf); |
---|
[a04c5e] | 1141 | return res; |
---|
| 1142 | } |
---|
| 1143 | |
---|
| 1144 | static inline poly p_Plus_mm_Mult_qq(poly p, poly m, poly q, const ring r) |
---|
| 1145 | { |
---|
[0d1a36] | 1146 | int lp = 0, lq = 0; |
---|
[a04c5e] | 1147 | return p_Plus_mm_Mult_qq(p, m, q, lp, lq, r); |
---|
| 1148 | } |
---|
| 1149 | |
---|
[20d9284] | 1150 | // returns merged p and q, assumes p and q have no monomials which are equal |
---|
[a04c5e] | 1151 | static inline poly p_Merge_q(poly p, poly q, const ring r) |
---|
| 1152 | { |
---|
[5f4015a] | 1153 | assume( (p != q) || (p == NULL && q == NULL) ); |
---|
[a04c5e] | 1154 | return r->p_Procs->p_Merge_q(p, q, r); |
---|
| 1155 | } |
---|
| 1156 | |
---|
[20d9284] | 1157 | // like p_SortMerge, except that p may have equal monimals |
---|
| 1158 | static inline poly p_SortAdd(poly p, const ring r, BOOLEAN revert= FALSE) |
---|
[a04c5e] | 1159 | { |
---|
| 1160 | if (revert) p = pReverse(p); |
---|
| 1161 | return sBucketSortAdd(p, r); |
---|
| 1162 | } |
---|
| 1163 | |
---|
[20d9284] | 1164 | // sorts p using bucket sort: returns sorted poly |
---|
| 1165 | // assumes that monomials of p are all different |
---|
| 1166 | // reverses it first, if revert == TRUE, use this if input p is "almost" sorted |
---|
| 1167 | // correctly |
---|
| 1168 | static inline poly p_SortMerge(poly p, const ring r, BOOLEAN revert= FALSE) |
---|
[a04c5e] | 1169 | { |
---|
| 1170 | if (revert) p = pReverse(p); |
---|
| 1171 | return sBucketSortMerge(p, r); |
---|
| 1172 | } |
---|
| 1173 | |
---|
| 1174 | /*************************************************************** |
---|
| 1175 | * |
---|
| 1176 | * I/O |
---|
| 1177 | * |
---|
| 1178 | ***************************************************************/ |
---|
| 1179 | static inline char* p_String(poly p, ring p_ring) |
---|
| 1180 | { |
---|
| 1181 | return p_String(p, p_ring, p_ring); |
---|
| 1182 | } |
---|
[538512] | 1183 | static inline void p_String0(poly p, ring p_ring) |
---|
[a04c5e] | 1184 | { |
---|
[538512] | 1185 | p_String0(p, p_ring, p_ring); |
---|
[a04c5e] | 1186 | } |
---|
| 1187 | static inline void p_Write(poly p, ring p_ring) |
---|
| 1188 | { |
---|
| 1189 | p_Write(p, p_ring, p_ring); |
---|
| 1190 | } |
---|
| 1191 | static inline void p_Write0(poly p, ring p_ring) |
---|
| 1192 | { |
---|
| 1193 | p_Write0(p, p_ring, p_ring); |
---|
| 1194 | } |
---|
| 1195 | static inline void p_wrp(poly p, ring p_ring) |
---|
| 1196 | { |
---|
| 1197 | p_wrp(p, p_ring, p_ring); |
---|
| 1198 | } |
---|
| 1199 | |
---|
| 1200 | |
---|
| 1201 | #if PDEBUG > 0 |
---|
| 1202 | |
---|
| 1203 | #define _p_LmCmpAction(p, q, r, actionE, actionG, actionS) \ |
---|
| 1204 | do \ |
---|
| 1205 | { \ |
---|
| 1206 | int _cmp = p_LmCmp(p,q,r); \ |
---|
| 1207 | if (_cmp == 0) actionE; \ |
---|
| 1208 | if (_cmp == 1) actionG; \ |
---|
| 1209 | actionS; \ |
---|
| 1210 | } \ |
---|
| 1211 | while(0) |
---|
| 1212 | |
---|
| 1213 | #else |
---|
| 1214 | |
---|
| 1215 | #define _p_LmCmpAction(p, q, r, actionE, actionG, actionS) \ |
---|
| 1216 | p_MemCmp_LengthGeneral_OrdGeneral(p->exp, q->exp, r->CmpL_Size, r->ordsgn, \ |
---|
| 1217 | actionE, actionG, actionS) |
---|
| 1218 | |
---|
| 1219 | #endif |
---|
| 1220 | |
---|
[d101b1] | 1221 | #define pDivAssume(x) do {} while (0) |
---|
[a04c5e] | 1222 | |
---|
[4f0f42] | 1223 | |
---|
[a04c5e] | 1224 | |
---|
| 1225 | /*************************************************************** |
---|
| 1226 | * |
---|
| 1227 | * Allocation/Initalization/Deletion |
---|
| 1228 | * |
---|
| 1229 | ***************************************************************/ |
---|
| 1230 | // adjustments for negative weights |
---|
| 1231 | static inline void p_MemAdd_NegWeightAdjust(poly p, const ring r) |
---|
| 1232 | { |
---|
| 1233 | if (r->NegWeightL_Offset != NULL) |
---|
| 1234 | { |
---|
| 1235 | for (int i=r->NegWeightL_Size-1; i>=0; i--) |
---|
| 1236 | { |
---|
| 1237 | p->exp[r->NegWeightL_Offset[i]] -= POLY_NEGWEIGHT_OFFSET; |
---|
| 1238 | } |
---|
| 1239 | } |
---|
| 1240 | } |
---|
| 1241 | static inline void p_MemSub_NegWeightAdjust(poly p, const ring r) |
---|
| 1242 | { |
---|
| 1243 | if (r->NegWeightL_Offset != NULL) |
---|
| 1244 | { |
---|
| 1245 | for (int i=r->NegWeightL_Size-1; i>=0; i--) |
---|
| 1246 | { |
---|
| 1247 | p->exp[r->NegWeightL_Offset[i]] += POLY_NEGWEIGHT_OFFSET; |
---|
| 1248 | } |
---|
| 1249 | } |
---|
| 1250 | } |
---|
| 1251 | // ExpVextor(d_p) = ExpVector(s_p) |
---|
| 1252 | static inline void p_ExpVectorCopy(poly d_p, poly s_p, const ring r) |
---|
| 1253 | { |
---|
| 1254 | p_LmCheckPolyRing1(d_p, r); |
---|
| 1255 | p_LmCheckPolyRing1(s_p, r); |
---|
[304ad9b] | 1256 | memcpy(d_p->exp, s_p->exp, r->ExpL_Size*sizeof(long)); |
---|
[a04c5e] | 1257 | } |
---|
| 1258 | |
---|
| 1259 | static inline poly p_Init(const ring r, omBin bin) |
---|
| 1260 | { |
---|
| 1261 | p_CheckRing1(r); |
---|
[aa2b525] | 1262 | pAssume1(bin != NULL && omSizeWOfBin(r->PolyBin) == omSizeWOfBin(bin)); |
---|
[a04c5e] | 1263 | poly p; |
---|
| 1264 | omTypeAlloc0Bin(poly, p, bin); |
---|
| 1265 | p_MemAdd_NegWeightAdjust(p, r); |
---|
| 1266 | p_SetRingOfLm(p, r); |
---|
| 1267 | return p; |
---|
| 1268 | } |
---|
| 1269 | static inline poly p_Init(const ring r) |
---|
| 1270 | { |
---|
| 1271 | return p_Init(r, r->PolyBin); |
---|
| 1272 | } |
---|
| 1273 | |
---|
| 1274 | static inline poly p_LmInit(poly p, const ring r) |
---|
| 1275 | { |
---|
| 1276 | p_LmCheckPolyRing1(p, r); |
---|
| 1277 | poly np; |
---|
| 1278 | omTypeAllocBin(poly, np, r->PolyBin); |
---|
| 1279 | p_SetRingOfLm(np, r); |
---|
[304ad9b] | 1280 | memcpy(np->exp, p->exp, r->ExpL_Size*sizeof(long)); |
---|
[a04c5e] | 1281 | pNext(np) = NULL; |
---|
| 1282 | pSetCoeff0(np, NULL); |
---|
| 1283 | return np; |
---|
| 1284 | } |
---|
| 1285 | static inline poly p_LmInit(poly s_p, const ring s_r, const ring d_r, omBin d_bin) |
---|
| 1286 | { |
---|
| 1287 | p_LmCheckPolyRing1(s_p, s_r); |
---|
| 1288 | p_CheckRing(d_r); |
---|
| 1289 | pAssume1(d_r->N <= s_r->N); |
---|
| 1290 | poly d_p = p_Init(d_r, d_bin); |
---|
[f8041a] | 1291 | for (unsigned i=d_r->N; i!=0; i--) |
---|
[a04c5e] | 1292 | { |
---|
| 1293 | p_SetExp(d_p, i, p_GetExp(s_p, i,s_r), d_r); |
---|
| 1294 | } |
---|
| 1295 | if (rRing_has_Comp(d_r)) |
---|
| 1296 | { |
---|
| 1297 | p_SetComp(d_p, p_GetComp(s_p,s_r), d_r); |
---|
| 1298 | } |
---|
| 1299 | p_Setm(d_p, d_r); |
---|
| 1300 | return d_p; |
---|
| 1301 | } |
---|
| 1302 | static inline poly p_LmInit(poly s_p, const ring s_r, const ring d_r) |
---|
| 1303 | { |
---|
| 1304 | pAssume1(d_r != NULL); |
---|
| 1305 | return p_LmInit(s_p, s_r, d_r, d_r->PolyBin); |
---|
| 1306 | } |
---|
[20d9284] | 1307 | |
---|
[f550e86] | 1308 | // set all exponents l..k to 0, assume exp. k+1..n and 1..l-1 are in |
---|
[a04c5e] | 1309 | // different blocks |
---|
| 1310 | // set coeff to 1 |
---|
| 1311 | static inline poly p_GetExp_k_n(poly p, int l, int k, const ring r) |
---|
| 1312 | { |
---|
| 1313 | if (p == NULL) return NULL; |
---|
| 1314 | p_LmCheckPolyRing1(p, r); |
---|
| 1315 | poly np; |
---|
| 1316 | omTypeAllocBin(poly, np, r->PolyBin); |
---|
| 1317 | p_SetRingOfLm(np, r); |
---|
[304ad9b] | 1318 | memcpy(np->exp, p->exp, r->ExpL_Size*sizeof(long)); |
---|
[a04c5e] | 1319 | pNext(np) = NULL; |
---|
[8a8c9e] | 1320 | pSetCoeff0(np, n_Init(1, r->cf)); |
---|
[a04c5e] | 1321 | int i; |
---|
| 1322 | for(i=l;i<=k;i++) |
---|
| 1323 | { |
---|
| 1324 | //np->exp[(r->VarOffset[i] & 0xffffff)] =0; |
---|
| 1325 | p_SetExp(np,i,0,r); |
---|
| 1326 | } |
---|
| 1327 | p_Setm(np,r); |
---|
| 1328 | return np; |
---|
| 1329 | } |
---|
| 1330 | |
---|
[20d9284] | 1331 | // simialar to p_ShallowCopyDelete but does it only for leading monomial |
---|
[0276c1] | 1332 | static inline poly p_LmShallowCopyDelete(poly p, const ring r) |
---|
[a04c5e] | 1333 | { |
---|
| 1334 | p_LmCheckPolyRing1(p, r); |
---|
[aa2b525] | 1335 | pAssume1(omSizeWOfBin(bin) == omSizeWOfBin(r->PolyBin)); |
---|
[a04c5e] | 1336 | poly new_p = p_New(r); |
---|
[304ad9b] | 1337 | memcpy(new_p->exp, p->exp, r->ExpL_Size*sizeof(long)); |
---|
[a04c5e] | 1338 | pSetCoeff0(new_p, pGetCoeff(p)); |
---|
| 1339 | pNext(new_p) = pNext(p); |
---|
| 1340 | omFreeBinAddr(p); |
---|
| 1341 | return new_p; |
---|
| 1342 | } |
---|
| 1343 | |
---|
| 1344 | /*************************************************************** |
---|
| 1345 | * |
---|
| 1346 | * Operation on ExpVectors |
---|
| 1347 | * |
---|
| 1348 | ***************************************************************/ |
---|
| 1349 | // ExpVector(p1) += ExpVector(p2) |
---|
| 1350 | static inline void p_ExpVectorAdd(poly p1, poly p2, const ring r) |
---|
| 1351 | { |
---|
| 1352 | p_LmCheckPolyRing1(p1, r); |
---|
| 1353 | p_LmCheckPolyRing1(p2, r); |
---|
| 1354 | #if PDEBUG >= 1 |
---|
| 1355 | for (int i=1; i<=r->N; i++) |
---|
| 1356 | pAssume1((unsigned long) (p_GetExp(p1, i, r) + p_GetExp(p2, i, r)) <= r->bitmask); |
---|
| 1357 | pAssume1(p_GetComp(p1, r) == 0 || p_GetComp(p2, r) == 0); |
---|
| 1358 | #endif |
---|
| 1359 | |
---|
| 1360 | p_MemAdd_LengthGeneral(p1->exp, p2->exp, r->ExpL_Size); |
---|
| 1361 | p_MemAdd_NegWeightAdjust(p1, r); |
---|
| 1362 | } |
---|
[304ad9b] | 1363 | // ExpVector(pr) = ExpVector(p1) + ExpVector(p2) |
---|
| 1364 | static inline void p_ExpVectorSum(poly pr, poly p1, poly p2, const ring r) |
---|
| 1365 | { |
---|
| 1366 | p_LmCheckPolyRing1(p1, r); |
---|
| 1367 | p_LmCheckPolyRing1(p2, r); |
---|
| 1368 | p_LmCheckPolyRing1(pr, r); |
---|
| 1369 | #if PDEBUG >= 1 |
---|
| 1370 | for (int i=1; i<=r->N; i++) |
---|
| 1371 | pAssume1((unsigned long) (p_GetExp(p1, i, r) + p_GetExp(p2, i, r)) <= r->bitmask); |
---|
| 1372 | pAssume1(p_GetComp(p1, r) == 0 || p_GetComp(p2, r) == 0); |
---|
| 1373 | #endif |
---|
| 1374 | |
---|
| 1375 | p_MemSum_LengthGeneral(pr->exp, p1->exp, p2->exp, r->ExpL_Size); |
---|
| 1376 | p_MemAdd_NegWeightAdjust(pr, r); |
---|
| 1377 | } |
---|
[a04c5e] | 1378 | // ExpVector(p1) -= ExpVector(p2) |
---|
| 1379 | static inline void p_ExpVectorSub(poly p1, poly p2, const ring r) |
---|
| 1380 | { |
---|
| 1381 | p_LmCheckPolyRing1(p1, r); |
---|
| 1382 | p_LmCheckPolyRing1(p2, r); |
---|
| 1383 | #if PDEBUG >= 1 |
---|
| 1384 | for (int i=1; i<=r->N; i++) |
---|
| 1385 | pAssume1(p_GetExp(p1, i, r) >= p_GetExp(p2, i, r)); |
---|
| 1386 | pAssume1(p_GetComp(p1, r) == 0 || p_GetComp(p2, r) == 0 || |
---|
| 1387 | p_GetComp(p1, r) == p_GetComp(p2, r)); |
---|
| 1388 | #endif |
---|
| 1389 | |
---|
| 1390 | p_MemSub_LengthGeneral(p1->exp, p2->exp, r->ExpL_Size); |
---|
| 1391 | p_MemSub_NegWeightAdjust(p1, r); |
---|
| 1392 | } |
---|
[7fcc5b1] | 1393 | |
---|
[a04c5e] | 1394 | // ExpVector(p1) += ExpVector(p2) - ExpVector(p3) |
---|
[3a9e92a] | 1395 | static inline void p_ExpVectorAddSub(poly p1, poly p2, poly p3, const ring r) |
---|
| 1396 | { |
---|
| 1397 | p_LmCheckPolyRing1(p1, r); |
---|
| 1398 | p_LmCheckPolyRing1(p2, r); |
---|
| 1399 | p_LmCheckPolyRing1(p3, r); |
---|
| 1400 | #if PDEBUG >= 1 |
---|
| 1401 | for (int i=1; i<=r->N; i++) |
---|
| 1402 | pAssume1(p_GetExp(p1, i, r) + p_GetExp(p2, i, r) >= p_GetExp(p3, i, r)); |
---|
[7e2f2d] | 1403 | pAssume1(p_GetComp(p1, r) == 0 || |
---|
[3a9e92a] | 1404 | (p_GetComp(p2, r) - p_GetComp(p3, r) == 0) || |
---|
| 1405 | (p_GetComp(p1, r) == p_GetComp(p2, r) - p_GetComp(p3, r))); |
---|
| 1406 | #endif |
---|
| 1407 | |
---|
| 1408 | p_MemAddSub_LengthGeneral(p1->exp, p2->exp, p3->exp, r->ExpL_Size); |
---|
| 1409 | // no need to adjust in case of NegWeights |
---|
| 1410 | } |
---|
[a04c5e] | 1411 | |
---|
| 1412 | // ExpVector(pr) = ExpVector(p1) - ExpVector(p2) |
---|
| 1413 | static inline void p_ExpVectorDiff(poly pr, poly p1, poly p2, const ring r) |
---|
| 1414 | { |
---|
| 1415 | p_LmCheckPolyRing1(p1, r); |
---|
| 1416 | p_LmCheckPolyRing1(p2, r); |
---|
| 1417 | p_LmCheckPolyRing1(pr, r); |
---|
| 1418 | #if PDEBUG >= 2 |
---|
| 1419 | for (int i=1; i<=r->N; i++) |
---|
| 1420 | pAssume1(p_GetExp(p1, i, r) >= p_GetExp(p2, i, r)); |
---|
| 1421 | pAssume1(!rRing_has_Comp(r) || p_GetComp(p1, r) == p_GetComp(p2, r)); |
---|
| 1422 | #endif |
---|
| 1423 | |
---|
| 1424 | p_MemDiff_LengthGeneral(pr->exp, p1->exp, p2->exp, r->ExpL_Size); |
---|
| 1425 | p_MemSub_NegWeightAdjust(pr, r); |
---|
| 1426 | } |
---|
| 1427 | |
---|
| 1428 | static inline BOOLEAN p_ExpVectorEqual(poly p1, poly p2, const ring r) |
---|
| 1429 | { |
---|
| 1430 | p_LmCheckPolyRing1(p1, r); |
---|
| 1431 | p_LmCheckPolyRing1(p2, r); |
---|
| 1432 | |
---|
[f8041a] | 1433 | unsigned i = r->ExpL_Size; |
---|
[a04c5e] | 1434 | unsigned long *ep = p1->exp; |
---|
| 1435 | unsigned long *eq = p2->exp; |
---|
| 1436 | |
---|
| 1437 | do |
---|
| 1438 | { |
---|
| 1439 | i--; |
---|
| 1440 | if (ep[i] != eq[i]) return FALSE; |
---|
| 1441 | } |
---|
[f8041a] | 1442 | while (i!=0); |
---|
[a04c5e] | 1443 | return TRUE; |
---|
| 1444 | } |
---|
| 1445 | |
---|
| 1446 | static inline long p_Totaldegree(poly p, const ring r) |
---|
| 1447 | { |
---|
| 1448 | p_LmCheckPolyRing1(p, r); |
---|
| 1449 | unsigned long s = p_GetTotalDegree(p->exp[r->VarL_Offset[0]], |
---|
| 1450 | r, |
---|
[e6d9cb5] | 1451 | r->ExpPerLong); |
---|
[f8041a] | 1452 | for (unsigned i=r->VarL_Size-1; i!=0; i--) |
---|
[a04c5e] | 1453 | { |
---|
[e6d9cb5] | 1454 | s += p_GetTotalDegree(p->exp[r->VarL_Offset[i]], r,r->ExpPerLong); |
---|
[a04c5e] | 1455 | } |
---|
| 1456 | return (long)s; |
---|
| 1457 | } |
---|
| 1458 | |
---|
| 1459 | static inline void p_GetExpV(poly p, int *ev, const ring r) |
---|
| 1460 | { |
---|
| 1461 | p_LmCheckPolyRing1(p, r); |
---|
[f8041a] | 1462 | for (unsigned j = r->N; j!=0; j--) |
---|
[a04c5e] | 1463 | ev[j] = p_GetExp(p, j, r); |
---|
| 1464 | |
---|
| 1465 | ev[0] = p_GetComp(p, r); |
---|
| 1466 | } |
---|
[231285] | 1467 | // p_GetExpVL is used in Singular,jl |
---|
[327a00] | 1468 | static inline void p_GetExpVL(poly p, int64 *ev, const ring r) |
---|
[1481e69] | 1469 | { |
---|
| 1470 | p_LmCheckPolyRing1(p, r); |
---|
| 1471 | for (unsigned j = r->N; j!=0; j--) |
---|
[051aa82] | 1472 | ev[j-1] = p_GetExp(p, j, r); |
---|
[1481e69] | 1473 | } |
---|
[a04c5e] | 1474 | static inline void p_SetExpV(poly p, int *ev, const ring r) |
---|
| 1475 | { |
---|
| 1476 | p_LmCheckPolyRing1(p, r); |
---|
[f8041a] | 1477 | for (unsigned j = r->N; j!=0; j--) |
---|
[a04c5e] | 1478 | p_SetExp(p, j, ev[j], r); |
---|
| 1479 | |
---|
[7abd61] | 1480 | if(ev[0]!=0) p_SetComp(p, ev[0],r); |
---|
[a04c5e] | 1481 | p_Setm(p, r); |
---|
| 1482 | } |
---|
[231285] | 1483 | // p_SetExpVL is used in Singular,jl |
---|
[327a00] | 1484 | static inline void p_SetExpVL(poly p, int64 *ev, const ring r) |
---|
| 1485 | { |
---|
| 1486 | p_LmCheckPolyRing1(p, r); |
---|
| 1487 | for (unsigned j = r->N; j!=0; j--) |
---|
| 1488 | p_SetExp(p, j, ev[j], r); |
---|
| 1489 | |
---|
| 1490 | if(ev[0]!=0) p_SetComp(p, ev[0],r); |
---|
| 1491 | p_Setm(p, r); |
---|
| 1492 | } |
---|
[a04c5e] | 1493 | |
---|
| 1494 | /*************************************************************** |
---|
| 1495 | * |
---|
| 1496 | * Comparison w.r.t. monomial ordering |
---|
| 1497 | * |
---|
| 1498 | ***************************************************************/ |
---|
[304ad9b] | 1499 | |
---|
[a04c5e] | 1500 | static inline int p_LmCmp(poly p, poly q, const ring r) |
---|
| 1501 | { |
---|
| 1502 | p_LmCheckPolyRing1(p, r); |
---|
| 1503 | p_LmCheckPolyRing1(q, r); |
---|
| 1504 | |
---|
[304ad9b] | 1505 | const unsigned long* _s1 = ((unsigned long*) p->exp); |
---|
| 1506 | const unsigned long* _s2 = ((unsigned long*) q->exp); |
---|
[b2ca85] | 1507 | REGISTER unsigned long _v1; |
---|
| 1508 | REGISTER unsigned long _v2; |
---|
[304ad9b] | 1509 | const unsigned long _l = r->CmpL_Size; |
---|
| 1510 | |
---|
[b2ca85] | 1511 | REGISTER unsigned long _i=0; |
---|
[304ad9b] | 1512 | |
---|
| 1513 | LengthGeneral_OrdGeneral_LoopTop: |
---|
| 1514 | _v1 = _s1[_i]; |
---|
| 1515 | _v2 = _s2[_i]; |
---|
| 1516 | if (_v1 == _v2) |
---|
| 1517 | { |
---|
| 1518 | _i++; |
---|
| 1519 | if (_i == _l) return 0; |
---|
| 1520 | goto LengthGeneral_OrdGeneral_LoopTop; |
---|
| 1521 | } |
---|
| 1522 | const long* _ordsgn = (long*) r->ordsgn; |
---|
[075bc5] | 1523 | #if 1 /* two variants*/ |
---|
[304ad9b] | 1524 | if (_v1 > _v2) |
---|
| 1525 | { |
---|
[ccc9976] | 1526 | return _ordsgn[_i]; |
---|
[304ad9b] | 1527 | } |
---|
[ccc9976] | 1528 | return -(_ordsgn[_i]); |
---|
| 1529 | #else |
---|
| 1530 | if (_v1 > _v2) |
---|
| 1531 | { |
---|
| 1532 | if (_ordsgn[_i] == 1) return 1; |
---|
| 1533 | return -1; |
---|
| 1534 | } |
---|
| 1535 | if (_ordsgn[_i] == 1) return -1; |
---|
| 1536 | return 1; |
---|
| 1537 | #endif |
---|
[a04c5e] | 1538 | } |
---|
| 1539 | |
---|
[094031] | 1540 | // The coefficient will be compared in absolute value |
---|
| 1541 | static inline int p_LtCmp(poly p, poly q, const ring r) |
---|
| 1542 | { |
---|
| 1543 | int res = p_LmCmp(p,q,r); |
---|
| 1544 | if(res == 0) |
---|
| 1545 | { |
---|
[a35d3d7] | 1546 | if(p_GetCoeff(p,r) == NULL || p_GetCoeff(q,r) == NULL) |
---|
| 1547 | return res; |
---|
[094031] | 1548 | number pc = n_Copy(p_GetCoeff(p,r),r->cf); |
---|
| 1549 | number qc = n_Copy(p_GetCoeff(q,r),r->cf); |
---|
| 1550 | if(!n_GreaterZero(pc,r->cf)) |
---|
| 1551 | pc = n_InpNeg(pc,r->cf); |
---|
| 1552 | if(!n_GreaterZero(qc,r->cf)) |
---|
| 1553 | qc = n_InpNeg(qc,r->cf); |
---|
| 1554 | if(n_Greater(pc,qc,r->cf)) |
---|
| 1555 | res = 1; |
---|
[cd3e96] | 1556 | else if(n_Greater(qc,pc,r->cf)) |
---|
[094031] | 1557 | res = -1; |
---|
[cd3e96] | 1558 | else if(n_Equal(pc,qc,r->cf)) |
---|
[094031] | 1559 | res = 0; |
---|
| 1560 | n_Delete(&pc,r->cf); |
---|
| 1561 | n_Delete(&qc,r->cf); |
---|
| 1562 | } |
---|
| 1563 | return res; |
---|
| 1564 | } |
---|
| 1565 | |
---|
[459ec94] | 1566 | // The coefficient will be compared in absolute value |
---|
| 1567 | static inline int p_LtCmpNoAbs(poly p, poly q, const ring r) |
---|
| 1568 | { |
---|
| 1569 | int res = p_LmCmp(p,q,r); |
---|
| 1570 | if(res == 0) |
---|
| 1571 | { |
---|
| 1572 | if(p_GetCoeff(p,r) == NULL || p_GetCoeff(q,r) == NULL) |
---|
| 1573 | return res; |
---|
| 1574 | number pc = p_GetCoeff(p,r); |
---|
| 1575 | number qc = p_GetCoeff(q,r); |
---|
| 1576 | if(n_Greater(pc,qc,r->cf)) |
---|
| 1577 | res = 1; |
---|
| 1578 | if(n_Greater(qc,pc,r->cf)) |
---|
| 1579 | res = -1; |
---|
| 1580 | if(n_Equal(pc,qc,r->cf)) |
---|
| 1581 | res = 0; |
---|
| 1582 | } |
---|
| 1583 | return res; |
---|
| 1584 | } |
---|
| 1585 | |
---|
[bdebb8] | 1586 | #ifdef HAVE_RINGS |
---|
[5efbf9] | 1587 | // This is the equivalent of pLmCmp(p,q) != -currRing->OrdSgn for rings |
---|
| 1588 | // It is used in posInLRing and posInTRing |
---|
| 1589 | static inline int p_LtCmpOrdSgnDiffM(poly p, poly q, const ring r) |
---|
| 1590 | { |
---|
| 1591 | if(r->OrdSgn == 1) |
---|
| 1592 | { |
---|
[cd3e96] | 1593 | return(p_LtCmp(p,q,r) == 1); |
---|
[5efbf9] | 1594 | } |
---|
| 1595 | else |
---|
| 1596 | { |
---|
[bdebb8] | 1597 | return(p_LmCmp(p,q,r) == -1); |
---|
[5efbf9] | 1598 | } |
---|
| 1599 | } |
---|
[bdebb8] | 1600 | #endif |
---|
[5efbf9] | 1601 | |
---|
[bdebb8] | 1602 | #ifdef HAVE_RINGS |
---|
[5efbf9] | 1603 | // This is the equivalent of pLmCmp(p,q) != currRing->OrdSgn for rings |
---|
| 1604 | // It is used in posInLRing and posInTRing |
---|
| 1605 | static inline int p_LtCmpOrdSgnDiffP(poly p, poly q, const ring r) |
---|
| 1606 | { |
---|
| 1607 | if(r->OrdSgn == 1) |
---|
| 1608 | { |
---|
[bdebb8] | 1609 | return(p_LmCmp(p,q,r) == -1); |
---|
[5efbf9] | 1610 | } |
---|
| 1611 | else |
---|
| 1612 | { |
---|
| 1613 | return(p_LtCmp(p,q,r) != -1); |
---|
| 1614 | } |
---|
[bdebb8] | 1615 | |
---|
[5efbf9] | 1616 | } |
---|
[bdebb8] | 1617 | #endif |
---|
[5efbf9] | 1618 | |
---|
[bdebb8] | 1619 | #ifdef HAVE_RINGS |
---|
[5efbf9] | 1620 | // This is the equivalent of pLmCmp(p,q) == -currRing->OrdSgn for rings |
---|
| 1621 | // It is used in posInLRing and posInTRing |
---|
| 1622 | static inline int p_LtCmpOrdSgnEqM(poly p, poly q, const ring r) |
---|
| 1623 | { |
---|
| 1624 | return(p_LtCmp(p,q,r) == -r->OrdSgn); |
---|
| 1625 | } |
---|
[bdebb8] | 1626 | #endif |
---|
[5efbf9] | 1627 | |
---|
[bdebb8] | 1628 | #ifdef HAVE_RINGS |
---|
[5efbf9] | 1629 | // This is the equivalent of pLmCmp(p,q) == currRing->OrdSgn for rings |
---|
| 1630 | // It is used in posInLRing and posInTRing |
---|
| 1631 | static inline int p_LtCmpOrdSgnEqP(poly p, poly q, const ring r) |
---|
| 1632 | { |
---|
| 1633 | return(p_LtCmp(p,q,r) == r->OrdSgn); |
---|
| 1634 | } |
---|
[bdebb8] | 1635 | #endif |
---|
[5efbf9] | 1636 | |
---|
[32d07a5] | 1637 | /// returns TRUE if p1 is a skalar multiple of p2 |
---|
| 1638 | /// assume p1 != NULL and p2 != NULL |
---|
| 1639 | BOOLEAN p_ComparePolys(poly p1,poly p2, const ring r); |
---|
[a04c5e] | 1640 | |
---|
[bb6c8a] | 1641 | |
---|
| 1642 | /*************************************************************** |
---|
| 1643 | * |
---|
| 1644 | * Comparisons: they are all done without regarding coeffs |
---|
| 1645 | * |
---|
| 1646 | ***************************************************************/ |
---|
| 1647 | #define p_LmCmpAction(p, q, r, actionE, actionG, actionS) \ |
---|
| 1648 | _p_LmCmpAction(p, q, r, actionE, actionG, actionS) |
---|
| 1649 | |
---|
| 1650 | // returns 1 if ExpVector(p)==ExpVector(q): does not compare numbers !! |
---|
| 1651 | #define p_LmEqual(p1, p2, r) p_ExpVectorEqual(p1, p2, r) |
---|
| 1652 | |
---|
| 1653 | // pCmp: args may be NULL |
---|
| 1654 | // returns: (p2==NULL ? 1 : (p1 == NULL ? -1 : p_LmCmp(p1, p2))) |
---|
| 1655 | static inline int p_Cmp(poly p1, poly p2, ring r) |
---|
| 1656 | { |
---|
| 1657 | if (p2==NULL) |
---|
[c8d0eb] | 1658 | { |
---|
| 1659 | if (p1==NULL) return 0; |
---|
[bb6c8a] | 1660 | return 1; |
---|
[c8d0eb] | 1661 | } |
---|
[bb6c8a] | 1662 | if (p1==NULL) |
---|
| 1663 | return -1; |
---|
| 1664 | return p_LmCmp(p1,p2,r); |
---|
| 1665 | } |
---|
| 1666 | |
---|
[c8d0eb] | 1667 | static inline int p_CmpPolys(poly p1, poly p2, ring r) |
---|
| 1668 | { |
---|
| 1669 | if (p2==NULL) |
---|
| 1670 | { |
---|
| 1671 | if (p1==NULL) return 0; |
---|
| 1672 | return 1; |
---|
| 1673 | } |
---|
| 1674 | if (p1==NULL) |
---|
| 1675 | return -1; |
---|
| 1676 | return p_ComparePolys(p1,p2,r); |
---|
| 1677 | } |
---|
| 1678 | |
---|
[bb6c8a] | 1679 | |
---|
[a04c5e] | 1680 | /*************************************************************** |
---|
| 1681 | * |
---|
| 1682 | * divisibility |
---|
| 1683 | * |
---|
| 1684 | ***************************************************************/ |
---|
[48ca29] | 1685 | /// return: FALSE, if there exists i, such that a->exp[i] > b->exp[i] |
---|
| 1686 | /// TRUE, otherwise |
---|
| 1687 | /// (1) Consider long vars, instead of single exponents |
---|
| 1688 | /// (2) Clearly, if la > lb, then FALSE |
---|
| 1689 | /// (3) Suppose la <= lb, and consider first bits of single exponents in l: |
---|
| 1690 | /// if TRUE, then value of these bits is la ^ lb |
---|
| 1691 | /// if FALSE, then la-lb causes an "overflow" into one of those bits, i.e., |
---|
| 1692 | /// la ^ lb != la - lb |
---|
[a04c5e] | 1693 | static inline BOOLEAN _p_LmDivisibleByNoComp(poly a, poly b, const ring r) |
---|
| 1694 | { |
---|
| 1695 | int i=r->VarL_Size - 1; |
---|
| 1696 | unsigned long divmask = r->divmask; |
---|
| 1697 | unsigned long la, lb; |
---|
| 1698 | |
---|
| 1699 | if (r->VarL_LowIndex >= 0) |
---|
| 1700 | { |
---|
| 1701 | i += r->VarL_LowIndex; |
---|
| 1702 | do |
---|
| 1703 | { |
---|
| 1704 | la = a->exp[i]; |
---|
| 1705 | lb = b->exp[i]; |
---|
| 1706 | if ((la > lb) || |
---|
| 1707 | (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask))) |
---|
| 1708 | { |
---|
| 1709 | pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == FALSE); |
---|
| 1710 | return FALSE; |
---|
| 1711 | } |
---|
| 1712 | i--; |
---|
| 1713 | } |
---|
| 1714 | while (i>=r->VarL_LowIndex); |
---|
| 1715 | } |
---|
| 1716 | else |
---|
| 1717 | { |
---|
| 1718 | do |
---|
| 1719 | { |
---|
| 1720 | la = a->exp[r->VarL_Offset[i]]; |
---|
| 1721 | lb = b->exp[r->VarL_Offset[i]]; |
---|
| 1722 | if ((la > lb) || |
---|
| 1723 | (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask))) |
---|
| 1724 | { |
---|
| 1725 | pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == FALSE); |
---|
| 1726 | return FALSE; |
---|
| 1727 | } |
---|
| 1728 | i--; |
---|
| 1729 | } |
---|
| 1730 | while (i>=0); |
---|
| 1731 | } |
---|
[1d85ccd] | 1732 | /*#ifdef HAVE_RINGS |
---|
[152e71c] | 1733 | pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == n_DivBy(p_GetCoeff(b, r), p_GetCoeff(a, r), r->cf)); |
---|
[8a8c9e] | 1734 | return (!rField_is_Ring(r)) || n_DivBy(p_GetCoeff(b, r), p_GetCoeff(a, r), r->cf); |
---|
[a04c5e] | 1735 | #else |
---|
[1d85ccd] | 1736 | */ |
---|
[a04c5e] | 1737 | pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == TRUE); |
---|
| 1738 | return TRUE; |
---|
[1d85ccd] | 1739 | //#endif |
---|
[a04c5e] | 1740 | } |
---|
| 1741 | |
---|
| 1742 | static inline BOOLEAN _p_LmDivisibleByNoComp(poly a, const ring r_a, poly b, const ring r_b) |
---|
| 1743 | { |
---|
| 1744 | int i=r_a->N; |
---|
| 1745 | pAssume1(r_a->N == r_b->N); |
---|
| 1746 | |
---|
| 1747 | do |
---|
| 1748 | { |
---|
| 1749 | if (p_GetExp(a,i,r_a) > p_GetExp(b,i,r_b)) |
---|
| 1750 | return FALSE; |
---|
| 1751 | i--; |
---|
| 1752 | } |
---|
| 1753 | while (i); |
---|
[1d85ccd] | 1754 | /*#ifdef HAVE_RINGS |
---|
[8a8c9e] | 1755 | return n_DivBy(p_GetCoeff(b, r_b), p_GetCoeff(a, r_a), r_a->cf); |
---|
[a04c5e] | 1756 | #else |
---|
[1d85ccd] | 1757 | */ |
---|
[a04c5e] | 1758 | return TRUE; |
---|
[1d85ccd] | 1759 | //#endif |
---|
[a04c5e] | 1760 | } |
---|
| 1761 | |
---|
| 1762 | #ifdef HAVE_RATGRING |
---|
| 1763 | static inline BOOLEAN _p_LmDivisibleByNoCompPart(poly a, const ring r_a, poly b, const ring r_b,const int start, const int end) |
---|
| 1764 | { |
---|
| 1765 | int i=end; |
---|
| 1766 | pAssume1(r_a->N == r_b->N); |
---|
| 1767 | |
---|
| 1768 | do |
---|
| 1769 | { |
---|
| 1770 | if (p_GetExp(a,i,r_a) > p_GetExp(b,i,r_b)) |
---|
| 1771 | return FALSE; |
---|
| 1772 | i--; |
---|
| 1773 | } |
---|
| 1774 | while (i>=start); |
---|
[1d85ccd] | 1775 | /*#ifdef HAVE_RINGS |
---|
[152e71c] | 1776 | return n_DivBy(p_GetCoeff(b, r_b), p_GetCoeff(a, r_a), r_a->cf); |
---|
[a04c5e] | 1777 | #else |
---|
[1d85ccd] | 1778 | */ |
---|
[a04c5e] | 1779 | return TRUE; |
---|
[1d85ccd] | 1780 | //#endif |
---|
[a04c5e] | 1781 | } |
---|
| 1782 | static inline BOOLEAN _p_LmDivisibleByPart(poly a, const ring r_a, poly b, const ring r_b,const int start, const int end) |
---|
| 1783 | { |
---|
| 1784 | if (p_GetComp(a, r_a) == 0 || p_GetComp(a,r_a) == p_GetComp(b,r_b)) |
---|
| 1785 | return _p_LmDivisibleByNoCompPart(a, r_a, b, r_b,start,end); |
---|
| 1786 | return FALSE; |
---|
| 1787 | } |
---|
| 1788 | static inline BOOLEAN p_LmDivisibleByPart(poly a, poly b, const ring r,const int start, const int end) |
---|
| 1789 | { |
---|
| 1790 | p_LmCheckPolyRing1(b, r); |
---|
| 1791 | pIfThen1(a != NULL, p_LmCheckPolyRing1(b, r)); |
---|
| 1792 | if (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r)) |
---|
| 1793 | return _p_LmDivisibleByNoCompPart(a, r, b, r,start, end); |
---|
| 1794 | return FALSE; |
---|
| 1795 | } |
---|
| 1796 | #endif |
---|
| 1797 | static inline BOOLEAN _p_LmDivisibleBy(poly a, poly b, const ring r) |
---|
| 1798 | { |
---|
| 1799 | if (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r)) |
---|
| 1800 | return _p_LmDivisibleByNoComp(a, b, r); |
---|
| 1801 | return FALSE; |
---|
| 1802 | } |
---|
| 1803 | static inline BOOLEAN _p_LmDivisibleBy(poly a, const ring r_a, poly b, const ring r_b) |
---|
| 1804 | { |
---|
| 1805 | if (p_GetComp(a, r_a) == 0 || p_GetComp(a,r_a) == p_GetComp(b,r_b)) |
---|
| 1806 | return _p_LmDivisibleByNoComp(a, r_a, b, r_b); |
---|
| 1807 | return FALSE; |
---|
| 1808 | } |
---|
| 1809 | static inline BOOLEAN p_LmDivisibleByNoComp(poly a, poly b, const ring r) |
---|
| 1810 | { |
---|
| 1811 | p_LmCheckPolyRing1(a, r); |
---|
| 1812 | p_LmCheckPolyRing1(b, r); |
---|
| 1813 | return _p_LmDivisibleByNoComp(a, b, r); |
---|
| 1814 | } |
---|
[85bcd6] | 1815 | |
---|
| 1816 | static inline BOOLEAN p_LmDivisibleByNoComp(poly a, const ring ra, poly b, const ring rb) |
---|
| 1817 | { |
---|
| 1818 | p_LmCheckPolyRing1(a, ra); |
---|
| 1819 | p_LmCheckPolyRing1(b, rb); |
---|
| 1820 | return _p_LmDivisibleByNoComp(a, ra, b, rb); |
---|
| 1821 | } |
---|
| 1822 | |
---|
[a04c5e] | 1823 | static inline BOOLEAN p_LmDivisibleBy(poly a, poly b, const ring r) |
---|
| 1824 | { |
---|
| 1825 | p_LmCheckPolyRing1(b, r); |
---|
| 1826 | pIfThen1(a != NULL, p_LmCheckPolyRing1(b, r)); |
---|
| 1827 | if (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r)) |
---|
| 1828 | return _p_LmDivisibleByNoComp(a, b, r); |
---|
| 1829 | return FALSE; |
---|
| 1830 | } |
---|
| 1831 | |
---|
| 1832 | static inline BOOLEAN p_DivisibleBy(poly a, poly b, const ring r) |
---|
| 1833 | { |
---|
| 1834 | pIfThen1(b!=NULL, p_LmCheckPolyRing1(b, r)); |
---|
| 1835 | pIfThen1(a!=NULL, p_LmCheckPolyRing1(a, r)); |
---|
| 1836 | |
---|
| 1837 | if (a != NULL && (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r))) |
---|
| 1838 | return _p_LmDivisibleByNoComp(a,b,r); |
---|
| 1839 | return FALSE; |
---|
| 1840 | } |
---|
| 1841 | static inline BOOLEAN p_DivisibleBy(poly a, const ring r_a, poly b, const ring r_b) |
---|
| 1842 | { |
---|
| 1843 | pIfThen1(b!=NULL, p_LmCheckPolyRing1(b, r_b)); |
---|
| 1844 | pIfThen1(a!=NULL, p_LmCheckPolyRing1(a, r_a)); |
---|
| 1845 | if (a != NULL) { |
---|
| 1846 | return _p_LmDivisibleBy(a, r_a, b, r_b); |
---|
| 1847 | } |
---|
| 1848 | return FALSE; |
---|
| 1849 | } |
---|
| 1850 | static inline BOOLEAN p_LmDivisibleBy(poly a, const ring r_a, poly b, const ring r_b) |
---|
| 1851 | { |
---|
| 1852 | p_LmCheckPolyRing(a, r_a); |
---|
| 1853 | p_LmCheckPolyRing(b, r_b); |
---|
| 1854 | return _p_LmDivisibleBy(a, r_a, b, r_b); |
---|
| 1855 | } |
---|
[85bcd6] | 1856 | |
---|
[a04c5e] | 1857 | static inline BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a, |
---|
| 1858 | poly b, unsigned long not_sev_b, const ring r) |
---|
| 1859 | { |
---|
| 1860 | p_LmCheckPolyRing1(a, r); |
---|
| 1861 | p_LmCheckPolyRing1(b, r); |
---|
| 1862 | #ifndef PDIV_DEBUG |
---|
[8a8c9e] | 1863 | _pPolyAssume2(p_GetShortExpVector(a, r) == sev_a, a, r); |
---|
| 1864 | _pPolyAssume2(p_GetShortExpVector(b, r) == ~ not_sev_b, b, r); |
---|
[a04c5e] | 1865 | |
---|
| 1866 | if (sev_a & not_sev_b) |
---|
| 1867 | { |
---|
| 1868 | pAssume1(p_LmDivisibleByNoComp(a, b, r) == FALSE); |
---|
| 1869 | return FALSE; |
---|
| 1870 | } |
---|
| 1871 | return p_LmDivisibleBy(a, b, r); |
---|
| 1872 | #else |
---|
| 1873 | return pDebugLmShortDivisibleBy(a, sev_a, r, b, not_sev_b, r); |
---|
| 1874 | #endif |
---|
| 1875 | } |
---|
| 1876 | |
---|
[85bcd6] | 1877 | static inline BOOLEAN p_LmShortDivisibleByNoComp(poly a, unsigned long sev_a, |
---|
| 1878 | poly b, unsigned long not_sev_b, const ring r) |
---|
| 1879 | { |
---|
| 1880 | p_LmCheckPolyRing1(a, r); |
---|
| 1881 | p_LmCheckPolyRing1(b, r); |
---|
| 1882 | #ifndef PDIV_DEBUG |
---|
| 1883 | _pPolyAssume2(p_GetShortExpVector(a, r) == sev_a, a, r); |
---|
| 1884 | _pPolyAssume2(p_GetShortExpVector(b, r) == ~ not_sev_b, b, r); |
---|
| 1885 | |
---|
| 1886 | if (sev_a & not_sev_b) |
---|
| 1887 | { |
---|
| 1888 | pAssume1(p_LmDivisibleByNoComp(a, b, r) == FALSE); |
---|
| 1889 | return FALSE; |
---|
| 1890 | } |
---|
| 1891 | return p_LmDivisibleByNoComp(a, b, r); |
---|
| 1892 | #else |
---|
| 1893 | return pDebugLmShortDivisibleByNoComp(a, sev_a, r, b, not_sev_b, r); |
---|
| 1894 | #endif |
---|
| 1895 | } |
---|
| 1896 | |
---|
[a04c5e] | 1897 | static inline BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a, const ring r_a, |
---|
| 1898 | poly b, unsigned long not_sev_b, const ring r_b) |
---|
| 1899 | { |
---|
| 1900 | p_LmCheckPolyRing1(a, r_a); |
---|
| 1901 | p_LmCheckPolyRing1(b, r_b); |
---|
| 1902 | #ifndef PDIV_DEBUG |
---|
[8a8c9e] | 1903 | _pPolyAssume2(p_GetShortExpVector(a, r_a) == sev_a, a, r_a); |
---|
| 1904 | _pPolyAssume2(p_GetShortExpVector(b, r_b) == ~ not_sev_b, b, r_b); |
---|
[a04c5e] | 1905 | |
---|
| 1906 | if (sev_a & not_sev_b) |
---|
| 1907 | { |
---|
| 1908 | pAssume1(_p_LmDivisibleByNoComp(a, r_a, b, r_b) == FALSE); |
---|
| 1909 | return FALSE; |
---|
| 1910 | } |
---|
| 1911 | return _p_LmDivisibleBy(a, r_a, b, r_b); |
---|
| 1912 | #else |
---|
| 1913 | return pDebugLmShortDivisibleBy(a, sev_a, r_a, b, not_sev_b, r_b); |
---|
| 1914 | #endif |
---|
| 1915 | } |
---|
| 1916 | |
---|
| 1917 | /*************************************************************** |
---|
| 1918 | * |
---|
| 1919 | * Misc things on Lm |
---|
| 1920 | * |
---|
| 1921 | ***************************************************************/ |
---|
| 1922 | |
---|
| 1923 | |
---|
[bdcd67] | 1924 | /// like the respective p_LmIs* routines, except that p might be empty |
---|
[a04c5e] | 1925 | static inline BOOLEAN p_IsConstantComp(const poly p, const ring r) |
---|
| 1926 | { |
---|
| 1927 | if (p == NULL) return TRUE; |
---|
| 1928 | return (pNext(p)==NULL) && p_LmIsConstantComp(p, r); |
---|
| 1929 | } |
---|
| 1930 | |
---|
| 1931 | static inline BOOLEAN p_IsConstant(const poly p, const ring r) |
---|
| 1932 | { |
---|
| 1933 | if (p == NULL) return TRUE; |
---|
[eb55f8a] | 1934 | p_Test(p, r); |
---|
[a04c5e] | 1935 | return (pNext(p)==NULL) && p_LmIsConstant(p, r); |
---|
| 1936 | } |
---|
| 1937 | |
---|
[5602268] | 1938 | /// either poly(1) or gen(k)?! |
---|
| 1939 | static inline BOOLEAN p_IsOne(const poly p, const ring R) |
---|
| 1940 | { |
---|
[eb55f8a] | 1941 | p_Test(p, R); |
---|
[5602268] | 1942 | return (p_IsConstant(p, R) && n_IsOne(p_GetCoeff(p, R), R->cf)); |
---|
| 1943 | } |
---|
| 1944 | |
---|
[20d9284] | 1945 | static inline BOOLEAN p_IsConstantPoly(const poly p, const ring r) |
---|
| 1946 | { |
---|
[eb55f8a] | 1947 | p_Test(p, r); |
---|
[20d9284] | 1948 | poly pp=p; |
---|
| 1949 | while(pp!=NULL) |
---|
| 1950 | { |
---|
| 1951 | if (! p_LmIsConstantComp(pp, r)) |
---|
| 1952 | return FALSE; |
---|
| 1953 | pIter(pp); |
---|
| 1954 | } |
---|
| 1955 | return TRUE; |
---|
| 1956 | } |
---|
| 1957 | |
---|
[a04c5e] | 1958 | static inline BOOLEAN p_IsUnit(const poly p, const ring r) |
---|
| 1959 | { |
---|
| 1960 | if (p == NULL) return FALSE; |
---|
| 1961 | if (rField_is_Ring(r)) |
---|
[cf5c05] | 1962 | return (p_LmIsConstant(p, r) && n_IsUnit(pGetCoeff(p),r->cf)); |
---|
[a04c5e] | 1963 | return p_LmIsConstant(p, r); |
---|
| 1964 | } |
---|
| 1965 | |
---|
| 1966 | static inline BOOLEAN p_LmExpVectorAddIsOk(const poly p1, const poly p2, |
---|
| 1967 | const ring r) |
---|
| 1968 | { |
---|
| 1969 | p_LmCheckPolyRing(p1, r); |
---|
| 1970 | p_LmCheckPolyRing(p2, r); |
---|
| 1971 | unsigned long l1, l2, divmask = r->divmask; |
---|
| 1972 | int i; |
---|
| 1973 | |
---|
| 1974 | for (i=0; i<r->VarL_Size; i++) |
---|
| 1975 | { |
---|
| 1976 | l1 = p1->exp[r->VarL_Offset[i]]; |
---|
| 1977 | l2 = p2->exp[r->VarL_Offset[i]]; |
---|
| 1978 | // do the divisiblity trick |
---|
| 1979 | if ( (l1 > ULONG_MAX - l2) || |
---|
| 1980 | (((l1 & divmask) ^ (l2 & divmask)) != ((l1 + l2) & divmask))) |
---|
| 1981 | return FALSE; |
---|
| 1982 | } |
---|
| 1983 | return TRUE; |
---|
| 1984 | } |
---|
[f34215] | 1985 | void p_Split(poly p, poly * r); /*p => IN(p), r => REST(p) */ |
---|
| 1986 | BOOLEAN p_HasNotCF(poly p1, poly p2, const ring r); |
---|
[070ab6] | 1987 | BOOLEAN p_HasNotCFRing(poly p1, poly p2, const ring r); |
---|
[f34215] | 1988 | poly p_mInit(const char *s, BOOLEAN &ok, const ring r); /* monom s -> poly, interpreter */ |
---|
| 1989 | const char * p_Read(const char *s, poly &p,const ring r); /* monom -> poly */ |
---|
[c796c8] | 1990 | poly p_MDivide(poly a, poly b, const ring r); |
---|
[fb4075b] | 1991 | poly p_DivideM(poly a, poly b, const ring r); |
---|
[b27c052] | 1992 | poly p_Div_nn(poly p, const number n, const ring r); |
---|
[f7a3f2] | 1993 | |
---|
[17c315] | 1994 | // returns the LCM of the head terms of a and b in *m, does not p_Setm |
---|
[f7a3f2] | 1995 | void p_Lcm(const poly a, const poly b, poly m, const ring r); |
---|
[17c315] | 1996 | // returns the LCM of the head terms of a and b, does p_Setm |
---|
| 1997 | poly p_Lcm(const poly a, const poly b, const ring r); |
---|
[f7a3f2] | 1998 | |
---|
[152e71c] | 1999 | #ifdef HAVE_RATGRING |
---|
| 2000 | poly p_LcmRat(const poly a, const poly b, const long lCompM, const ring r); |
---|
| 2001 | poly p_GetCoeffRat(poly p, int ishift, ring r); |
---|
| 2002 | void p_LmDeleteAndNextRat(poly *p, int ishift, ring r); |
---|
| 2003 | void p_ContentRat(poly &ph, const ring r); |
---|
| 2004 | #endif /* ifdef HAVE_RATGRING */ |
---|
| 2005 | |
---|
| 2006 | |
---|
[ac0bd6] | 2007 | poly p_Diff(poly a, int k, const ring r); |
---|
[5162db] | 2008 | poly p_DiffOp(poly a, poly b,BOOLEAN multiply, const ring r); |
---|
[bf183f] | 2009 | int p_Weight(int c, const ring r); |
---|
| 2010 | |
---|
[20c540] | 2011 | /// assumes that p and divisor are univariate polynomials in r, |
---|
| 2012 | /// mentioning the same variable; |
---|
| 2013 | /// assumes divisor != NULL; |
---|
| 2014 | /// p may be NULL; |
---|
| 2015 | /// assumes a global monomial ordering in r; |
---|
| 2016 | /// performs polynomial division of p by divisor: |
---|
| 2017 | /// - afterwards p contains the remainder of the division, i.e., |
---|
| 2018 | /// p_before = result * divisor + p_afterwards; |
---|
| 2019 | /// - if needResult == TRUE, then the method computes and returns 'result', |
---|
| 2020 | /// otherwise NULL is returned (This parametrization can be used when |
---|
| 2021 | /// one is only interested in the remainder of the division. In this |
---|
| 2022 | /// case, the method will be slightly faster.) |
---|
| 2023 | /// leaves divisor unmodified |
---|
| 2024 | poly p_PolyDiv(poly &p, const poly divisor, const BOOLEAN needResult, const ring r); |
---|
[ba2359] | 2025 | |
---|
[cd246b] | 2026 | /* syszygy stuff */ |
---|
| 2027 | BOOLEAN p_VectorHasUnitB(poly p, int * k, const ring r); |
---|
| 2028 | void p_VectorHasUnit(poly p, int * k, int * len, const ring r); |
---|
| 2029 | poly p_TakeOutComp1(poly * p, int k, const ring r); |
---|
[74021a] | 2030 | // Splits *p into two polys: *q which consists of all monoms with |
---|
| 2031 | // component == comp and *p of all other monoms *lq == pLength(*q) |
---|
| 2032 | // On return all components pf *q == 0 |
---|
[0d1a36] | 2033 | void p_TakeOutComp(poly *p, long comp, poly *q, int *lq, const ring r); |
---|
[74021a] | 2034 | |
---|
| 2035 | // This is something weird -- Don't use it, unless you know what you are doing |
---|
[1a20e5] | 2036 | poly p_TakeOutComp(poly * p, int k, const ring r); |
---|
[74021a] | 2037 | |
---|
| 2038 | void p_DeleteComp(poly * p,int k, const ring r); |
---|
| 2039 | |
---|
[5c39a9] | 2040 | /*-------------ring management:----------------------*/ |
---|
| 2041 | |
---|
[949e57] | 2042 | // resets the pFDeg and pLDeg: if pLDeg is not given, it is |
---|
| 2043 | // set to currRing->pLDegOrig, i.e. to the respective LDegProc which |
---|
| 2044 | // only uses pFDeg (and not pDeg, or pTotalDegree, etc). |
---|
| 2045 | // If you use this, make sure your procs does not make any assumptions |
---|
| 2046 | // on ordering and/or OrdIndex -- otherwise they might return wrong results |
---|
| 2047 | // on strat->tailRing |
---|
[8a8c9e] | 2048 | void pSetDegProcs(ring r, pFDegProc new_FDeg, pLDegProc new_lDeg = NULL); |
---|
[949e57] | 2049 | // restores pFDeg and pLDeg: |
---|
[8a8c9e] | 2050 | void pRestoreDegProcs(ring r, pFDegProc old_FDeg, pLDegProc old_lDeg); |
---|
[949e57] | 2051 | |
---|
[5bc2461] | 2052 | /*-------------pComp for syzygies:-------------------*/ |
---|
| 2053 | void p_SetModDeg(intvec *w, ring r); |
---|
[949e57] | 2054 | |
---|
[f550e86] | 2055 | /*------------ Jet ----------------------------------*/ |
---|
| 2056 | poly pp_Jet(poly p, int m, const ring R); |
---|
| 2057 | poly p_Jet(poly p, int m,const ring R); |
---|
| 2058 | poly pp_JetW(poly p, int m, short *w, const ring R); |
---|
| 2059 | poly p_JetW(poly p, int m, short *w, const ring R); |
---|
[deca086] | 2060 | |
---|
[83a1714] | 2061 | poly n_PermNumber(const number z, const int *par_perm, const int OldPar, const ring src, const ring dst); |
---|
[deca086] | 2062 | |
---|
[83a1714] | 2063 | poly p_PermPoly (poly p, const int * perm,const ring OldRing, const ring dst, |
---|
[a934fb3] | 2064 | nMapFunc nMap, const int *par_perm=NULL, int OldPar=0, |
---|
| 2065 | BOOLEAN use_mult=FALSE); |
---|
[deca086] | 2066 | |
---|
[a4081e5] | 2067 | /*----------------------------------------------------*/ |
---|
| 2068 | poly p_Series(int n,poly p,poly u, intvec *w, const ring R); |
---|
[aa450d] | 2069 | |
---|
| 2070 | /*----------------------------------------------------*/ |
---|
[d914cf0] | 2071 | int p_Var(poly mi, const ring r); |
---|
[73ad0c] | 2072 | /// the minimal index of used variables - 1 |
---|
[d914cf0] | 2073 | int p_LowVar (poly p, const ring r); |
---|
[aa450d] | 2074 | |
---|
[1fdb6e] | 2075 | /*----------------------------------------------------*/ |
---|
[b7cfaf] | 2076 | /// shifts components of the vector p by i |
---|
| 2077 | void p_Shift (poly * p,int i, const ring r); |
---|
[8222d6] | 2078 | /*----------------------------------------------------*/ |
---|
| 2079 | |
---|
| 2080 | int p_Compare(const poly a, const poly b, const ring R); |
---|
[9f93d9] | 2081 | |
---|
| 2082 | /// polynomial gcd for f=mon |
---|
| 2083 | poly p_GcdMon(poly f, poly g, const ring r); |
---|
[7b4ca1f] | 2084 | |
---|
| 2085 | /// divide polynomial by monomial |
---|
| 2086 | poly p_Div_mm(poly p, const poly m, const ring r); |
---|
[35aab3] | 2087 | #endif // P_POLYS_H |
---|
| 2088 | |
---|