source: git/libpolys/polys/monomials/p_polys.h @ ba0fc3

spielwiese
Last change on this file since ba0fc3 was ba0fc3, checked in by Hans Schoenemann <hannes@…>, 13 years ago
p_MinDeg, p_DegW -> p_polys.cc
  • Property mode set to 100644
File size: 53.0 KB
RevLine 
[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
[341696]10 *  Version: $Id$
[35aab3]11 *******************************************************************/
12#ifndef P_POLYS_H
13#define P_POLYS_H
14
[20b794]15#include <polys/monomials/ring.h>
[8a8c9e]16#include <polys/monomials/monomials.h>
[20b794]17#include <polys/monomials/polys-impl.h>
[8a8c9e]18#include <polys/templates/p_Procs.h>
19#include <polys/templates/p_Procs.h>
20#include <polys/sbuckets.h>
[35aab3]21
22/***************************************************************
23 *
24 * Primitives for accessing and setting fields of a poly
25 * poly must be != NULL
26 *
27 ***************************************************************/
28// next
[367c32]29#define pNext(p)            ((p)->next)
30#define pIter(p)            ((p) = (p)->next)
[35aab3]31
32// coeff
[367c32]33#define pGetCoeff(p)        ((p)->coef)
[35aab3]34// deletes old coeff before setting the new one
[367c32]35#define pSetCoeff0(p,n)     (p)->coef=(n)
36#define p_GetCoeff(p,r)     pGetCoeff(p)
37#define p_SetCoeff0(p,n,r)  pSetCoeff0(p,n)
[35aab3]38// deletes old p->coef and sets new one
[a04c5e]39static inline number p_SetCoeff(poly p, number n, ring r);
[35aab3]40
41// get Order
[a04c5e]42static inline long p_GetOrder(poly p, ring r);
[35aab3]43
44// Component
[a04c5e]45static inline unsigned long p_SetComp(poly p, unsigned long c, ring r);
46static inline unsigned long p_AddComp(poly p, unsigned long v, ring r);
47static inline unsigned long p_SubComp(poly p, unsigned long v, ring r);
[35aab3]48
49// Exponent
[a04c5e]50static inline long p_GetExp(poly p, int v, ring r);
51static inline long p_SetExp(poly p, int v, long e, ring r);
52static inline long p_IncrExp(poly p, int v, ring r);
53static inline long p_DecrExp(poly p, int v, ring r);
54static inline long p_AddExp(poly p, int v, long ee, ring r);
55static inline long p_SubExp(poly p, int v, long ee, ring r);
56static inline long p_MultExp(poly p, int v, long ee, ring r);
57static inline long p_GetExpSum(poly p1, poly p2, int i, ring r);
58static inline long p_GetExpDiff(poly p1, poly p2, int i, ring r);
[35aab3]59
60/***************************************************************
61 *
62 * Allocation/Initalization/Deletion
[fb82895]63 * except for pHead, all polys must be != NULL
[35aab3]64 *
65 ***************************************************************/
[a04c5e]66static inline poly p_New(ring r);
67static inline poly p_New(ring r, omBin bin);
68static inline poly p_Init(ring r);
69static inline poly p_Init(ring r, omBin bin);
70static inline poly p_LmInit(poly p, ring r);
71static inline poly p_LmInit(poly s_p, ring s_r, ring d_p);
72static inline poly p_LmInit(poly s_p, ring s_r, ring d_p, omBin d_bin);
73static inline poly p_Head(poly p, ring r);
74static inline void p_LmFree(poly p, ring r);
75static inline void p_LmFree(poly *p, ring r);
76static inline poly p_LmFreeAndNext(poly p, ring r);
77static inline void p_LmDelete(poly p, ring r);
78static inline void p_LmDelete(poly *p, ring r);
79static inline poly p_LmDeleteAndNext(poly p, ring r);
[35aab3]80
81/***************************************************************
82 *
83 * Operation on ExpVectors: assumes polys != NULL
84 *
85 ***************************************************************/
86// ExpVextor(d_p) = ExpVector(s_p)
[a04c5e]87static inline void p_ExpVectorCopy(poly d_p, poly s_p, ring r);
[35aab3]88// adjustments for negative weights
[a04c5e]89static inline void p_MemAdd_NegWeightAdjust(poly p, ring r);
90static inline void p_MemSub_NegWeightAdjust(poly p, ring r);
[35aab3]91// ExpVector(p1) += ExpVector(p2)
[a04c5e]92static inline void p_ExpVectorAdd(poly p1, poly p2, ring r);
[35aab3]93// ExpVector(p1) -= ExpVector(p2)
[a04c5e]94static inline void p_ExpVectorSub(poly p1, poly p2, ring r);
[35aab3]95// ExpVector(p1) += ExpVector(p2) - ExpVector(p3)
[a04c5e]96static inline void p_ExpVectorAddSub(poly p1, poly p2, poly p3, ring r);
[35aab3]97// ExpVector(pr) = ExpVector(p1) + ExpVector(p2)
[a04c5e]98static inline void p_ExpVectorSum(poly pr, poly p1, poly p2, ring r);
[d918007]99/// ExpVector(pr) = ExpVector(p1) + ExpVector(p2)
[a04c5e]100static inline void p_ExpVectorDiff(poly pr, poly p1, poly p2, ring r);
[d918007]101/// returns TRUE if ExpVector(p1) == ExpVector(p2), FALSE, otherwise
[a04c5e]102static inline BOOLEAN p_ExpVectorEqual(poly p1, poly p2, ring r);
[d918007]103/// compute the degree of the leading monomial of p
104/// with respect to weigths 1
105/// the ordering may not be compatible with degree so do not use p->Order
[a04c5e]106static inline long p_Totaldegree(poly p, ring r);
[35aab3]107
[a04c5e]108static inline void p_GetExpV(poly p, int *ev, ring r);
109static inline void p_SetExpV(poly p, int *ev, ring r);
[35aab3]110
111
112/***************************************************************
113 *
114 * Comparisons: they are all done without regarding coeffs
115 *
116 ***************************************************************/
[a04c5e]117static inline int p_LmCmp(poly p, poly q, ring r);
[35aab3]118#define p_LmCmpAction(p, q, r, actionE, actionG, actionS) \
119  _p_LmCmpAction(p, q, r, actionE, actionG, actionS)
120
121// returns 1 if ExpVector(p)==ExpVector(q): does not compare numbers !!
122#define p_LmEqual(p1, p2, r) p_ExpVectorEqual(p1, p2, r)
123
124// pCmp: args may be NULL
125// returns: (p2==NULL ? 1 : (p1 == NULL ? -1 : p_LmCmp(p1, p2)))
[a04c5e]126static inline int p_Cmp(poly p1, poly p2, ring r);
[35aab3]127
128
129/***************************************************************
130 *
131 * Divisiblity tests, args must be != NULL, except for
132 * pDivisbleBy
133 *
134 ***************************************************************/
[a04c5e]135static inline BOOLEAN p_DivisibleBy(poly a, poly b, ring r);
136static inline BOOLEAN p_LmDivisibleBy(poly a, poly b, ring r);
137static inline BOOLEAN p_LmDivisibleByNoComp(poly a, poly b, ring r);
[35aab3]138unsigned long p_GetShortExpVector(poly a, ring r);
[a04c5e]139static inline BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a,
[35aab3]140                                      poly b, unsigned long not_sev_b, ring r);
141
[a04c5e]142static inline BOOLEAN p_DivisibleBy(poly a, ring r_a, poly b, ring r_b);
143static inline BOOLEAN p_LmDivisibleBy(poly a, ring r_a, poly b, ring r_b);
144static inline BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a, ring r_a,
[35aab3]145                                      poly b, unsigned long not_sev_b, ring r_b);
146
147/***************************************************************
148 *
149 * Misc things on Lm
150 *
151 ***************************************************************/
152// test if the monomial is a constant as a vector component
153// i.e., test if all exponents are zero
[a04c5e]154static inline BOOLEAN p_LmIsConstantComp(const poly p, const ring r);
155static inline BOOLEAN p_LmIsConstant(const poly p, const ring r);
[35aab3]156
157// return TRUE, if p_LmExpVectorAdd stays within ExpBound of ring r,
158//       FALSE, otherwise
[a04c5e]159static inline BOOLEAN p_LmExpVectorAddIsOk(const poly p1, const poly p2, ring r);
[35aab3]160
161/***************************************************************
162 *
163 * Misc things on polys
164 *
165 ***************************************************************/
166// return the maximal exponent of p
[a04c5e]167static inline unsigned long p_GetMaxExp(poly p, ring r);
[35aab3]168// return the maximal exponent of p in form of the maximal long var
[a05493f]169unsigned long p_GetMaxExpL(poly p, const ring r, unsigned long l_max = 0);
[35aab3]170// return monomial r such that GetExp(r,i) is maximum of all
171// monomials in p; coeff == 0, next == NULL, ord is not set
172poly p_GetMaxExpP(poly p, ring r);
173
174// suppose that l is a long var in r, return maximal exponent of l
[a04c5e]175static inline unsigned long p_GetMaxExp(const unsigned long l, const ring r);
[35aab3]176
177// return the TotalDegree of the long var l
[a04c5e]178static inline unsigned long p_GetTotalDegree(const unsigned long l, const ring r);
[35aab3]179// return the total degree of the long var l containing number_of_exp exponents
[a04c5e]180static inline unsigned long p_GetTotalDegree(const unsigned long l, const ring r, const int number_of_exps);
[35aab3]181
[ba0fc3]182int p_MinDeg(poly p,intvec *w, const ring R);
183
184long p_DegW(poly p, const short *w, const ring R);
185
[35aab3]186
187// like the respective p_LmIs* routines, except that p might be empty
[a04c5e]188static inline BOOLEAN p_IsConstantComp(const poly p, const ring r);
189static inline BOOLEAN p_IsConstant(const poly p, const ring r);
[8a8c9e]190static inline BOOLEAN p_IsConstantPoly(const poly p, const ring r);
[35aab3]191
192// return TRUE if all monoms have the same component
193BOOLEAN   p_OneComp(poly p, ring r);
[2f0d83f]194
195// return i, if head depends only on var(i)
[35aab3]196int       p_IsPurePower(const poly p, const ring r);
197
[2f0d83f]198// return i, if poly depends only on var(i)
199int       p_IsUnivariate(poly p, const ring r);
200
[95450e]201// set entry e[i] to 1 if var(i) occurs in p, ignore var(j) if e[j]>0
[f46646]202// return #(e[i]>0)
203int      p_GetVariables(poly p, int * e, const ring r);
[95450e]204
[35aab3]205// returns the poly representing the integer i
206poly      p_ISet(int i, ring r);
[2f0d83f]207
[35aab3]208// returns the poly representing the number n, destroys n
209poly      p_NSet(number n, ring r);
210
211/***************************************************************
212 *
213 * Copying/Deletion of polys: args may be NULL
214 *
215 ***************************************************************/
216// returns a copy of p
[a04c5e]217static inline poly p_Copy(poly p, const ring r);
[35aab3]218// returns a copy of p with Lm(p) from lmRing and Tail(p) from tailRing
[a04c5e]219static inline poly p_Copy(poly p, const ring lmRing, const ring tailRing);
[35aab3]220// deletes *p, and sets *p to NULL
[a04c5e]221static inline void p_Delete(poly *p, const ring r);
222static inline void p_Delete(poly *p, const ring lmRing, const ring tailRing);
[35aab3]223
224// copys monomials of p, allocates new monomials from bin,
225// deletes monomoals of p
[a04c5e]226static inline poly p_ShallowCopyDelete(poly p, const ring r, omBin bin);
[35aab3]227// simial but does it only for leading monomial
[a04c5e]228static inline poly p_LmShallowCopyDelete(poly p, const ring r, omBin bin);
[35aab3]229// simply deletes monomials, does not free coeffs
230void p_ShallowDelete(poly *p, const ring r);
231
[f550e86]232
[35aab3]233
234/***************************************************************
235 *
236 * Copying/Deleteion of polys: args may be NULL
237 *  - p/q as arg mean a poly
238 *  - m a monomial
239 *  - n a number
240 *  - pp (resp. qq, mm, nn) means arg is constant
241 *  - p (resp, q, m, n)     means arg is destroyed
242 *
243 ***************************************************************/
244// returns -p, p is destroyed
[a04c5e]245static inline poly p_Neg(poly p, const ring r);
[35aab3]246
247// returns p*n, p is const (i.e. copied)
[a04c5e]248static inline poly pp_Mult_nn(poly p, number n, const ring r);
[35aab3]249// returns p*n, destroys p
[a04c5e]250static inline poly p_Mult_nn(poly p, number n, const ring r);
251static inline poly p_Mult_nn(poly p, number n, const ring lmRing, const ring tailRing);
[35aab3]252
253// returns p*m, does neither destroy p nor m
[a04c5e]254static inline poly pp_Mult_mm(poly p, poly m, const ring r);
[35aab3]255// returns p*m, destroys p, const: m
[a04c5e]256static inline poly p_Mult_mm(poly p, poly m, const ring r);
[35aab3]257
[bf183f]258/// returns p+q, destroys p and q
[a04c5e]259static inline poly p_Add_q(poly p, poly q, const ring r);
[bf183f]260/// like p_Add_q, except that if lp == pLength(lp) lq == pLength(lq) then lp == pLength(p+q)
[a04c5e]261static inline poly p_Add_q(poly p, poly q, int &lp, int lq, const ring r);
[35aab3]262
[bf183f]263poly      p_Sub(poly a, poly b, const ring r);
264
[35aab3]265// return p - m*q, destroys p; const: q,m
[a04c5e]266static inline poly p_Minus_mm_Mult_qq(poly p, poly m, poly q, const ring r);
[35aab3]267// like p_Minus_mm_Mult_qq, except that if lp == pLength(lp) lq == pLength(lq)
268// then lp == pLength(p -m*q)
[a04c5e]269static inline poly p_Minus_mm_Mult_qq(poly p, poly m, poly q, int &lp, int lq,
[35aab3]270                                 poly spNoether, const ring r);
271// returns p + m*q destroys p, const: q, m
[a04c5e]272static inline poly p_Plus_mm_Mult_qq(poly p, poly m, poly q, const ring r);
[35aab3]273
274// returns p + m*q destroys p, const: q, m
[a04c5e]275static inline poly p_Plus_mm_Mult_qq(poly p, poly m, poly q, int &lp, int lq,
[35aab3]276                                const ring r);
277
278// returns p*q, destroys p and q
[a04c5e]279static inline poly p_Mult_q(poly p, poly q, const ring r);
[35aab3]280// returns p*q, does neither destroy p nor q
[a04c5e]281static inline poly pp_Mult_qq(poly p, poly q, const ring r);
[35aab3]282
283// returns p*Coeff(m) for such monomials pm of p, for which m is divisble by pm
[a04c5e]284static inline poly pp_Mult_Coeff_mm_DivSelect(poly p, const poly m, const ring r);
[35aab3]285
286// returns p*Coeff(m) for such monomials pm of p, for which m is divisble by pm
287// if lp is length of p on input then lp is length of returned poly on output
[a04c5e]288static inline poly pp_Mult_Coeff_mm_DivSelect(poly p, int &lp, const poly m, const ring r);
[35aab3]289
290// returns merged p and q, assumes p and q have no monomials which are equal
[a04c5e]291static inline poly p_Merge_q(poly p, poly c, const ring r);
[35aab3]292// sorts p using bucket sort: returns sorted poly
293// assumes that monomials of p are all different
294// reverses it first, if revert == TRUE, use this if input p is "almost" sorted
295// correctly
[a04c5e]296static inline poly p_SortMerge(poly p, const ring r, BOOLEAN revert = FALSE);
[35aab3]297// like SortMerge, except that p may have equal monimals
[a04c5e]298static inline poly p_SortAdd(poly p, const ring r, BOOLEAN revert = FALSE);
[35aab3]299
[bf183f]300poly      p_Power(poly p, int i, const ring r);
[35aab3]301/***************************************************************
302 *
303 * Misc stuff
304 *
305 ***************************************************************/
[71ba5b8]306void      p_Norm(poly p1, const ring r);
[8d1d30c]307void      p_Normalize(poly p,const ring r);
308
309void      p_Content(poly p, const ring r);
[5698bb]310//void      p_SimpleContent(poly p, int s, const ring r);
[8d1d30c]311
312poly      p_Cleardenom(poly p, const ring r);
313void      p_Cleardenom_n(poly p, const ring r,number &c);
314number    p_GetAllDenom(poly ph, const ring r);
315
[fbf8a6]316int       pSize( poly p, const ring r );
317
[4e8ef90]318// homogenizes p by multiplying certain powers of the varnum-th variable
319poly      p_Homogen (poly p, int varnum, const ring r);
[a30a39a]320
[4e8ef90]321BOOLEAN   p_IsHomogeneous (poly p, const ring r);
322
[a04c5e]323static inline void p_Setm(poly p, const ring r);
[35aab3]324p_SetmProc p_GetSetmProc(ring r);
325
[71ba5b8]326poly      p_Subst(poly p, int n, poly e, const ring r);
327
[35aab3]328// TODO:
329#define p_SetmComp  p_Setm
330
331// sets component of poly a to i, returns length of a
[8a8c9e]332static inline   void p_SetCompP(poly a, int i, ring r);
333static inline   void p_SetCompP(poly a, int i, ring lmRing, ring tailRing);
334static inline   long p_MaxComp(poly p, ring lmRing, ring tailRing);
[35aab3]335inline long p_MaxComp(poly p,ring lmRing) {return p_MaxComp(p,lmRing,lmRing);}
[8a8c9e]336static inline   long p_MinComp(poly p, ring lmRing, ring tailRing);
[35aab3]337inline long p_MinComp(poly p,ring lmRing) {return p_MinComp(p,lmRing,lmRing);}
338
339/***************************************************************
340 *
341 * poly things which are independent of ring
342 *
343 ***************************************************************/
[8a8c9e]344static inline int       pLength(poly a);
345static inline poly      pLast(poly a, int &length);
[35aab3]346inline   poly      pLast(poly a) { int l; return pLast(a, l);}
[8a8c9e]347static inline poly pReverse(poly p);
[c6a3eb2]348void      pEnlargeSet(poly**p, int length, int increment);
[35aab3]349
350
351/***************************************************************
352 *
353 * I/O
354 *
355 ***************************************************************/
356char*     p_String(poly p, ring lmRing, ring tailRing);
357char*     p_String0(poly p, ring lmRing, ring tailRing);
358void      p_Write(poly p, ring lmRing, ring tailRing);
359void      p_Write0(poly p, ring lmRing, ring tailRing);
360void      p_wrp(poly p, ring lmRing, ring tailRing);
361
[a04c5e]362static inline char*     p_String(poly p, ring p_ring);
363static inline char*     p_String0(poly p, ring p_ring);
364static inline void      p_Write(poly p, ring p_ring);
365static inline void      p_Write0(poly p, ring p_ring);
366static inline void      p_wrp(poly p, ring p_ring);
[35aab3]367
368
369/***************************************************************
370 *
371 * Degree stuff -- see p_polys.cc for explainations
372 *
373 ***************************************************************/
374extern pLDegProc pLDeg;
375extern pFDegProc pFDeg;
[19ae652]376long p_WFirstTotalDegree(poly p, ring r);
377long p_WTotaldegree(poly p, const ring r);
[bf183f]378long p_WDegree(poly p,const ring r);
[35aab3]379long pLDeg0(poly p,int *l, ring r);
380long pLDeg0c(poly p,int *l, ring r);
381long pLDegb(poly p,int *l, ring r);
382long pLDeg1(poly p,int *l, ring r);
383long pLDeg1c(poly p,int *l, ring r);
384long pLDeg1_Deg(poly p,int *l, ring r);
385long pLDeg1c_Deg(poly p,int *l, ring r);
386long pLDeg1_Totaldegree(poly p,int *l, ring r);
387long pLDeg1c_Totaldegree(poly p,int *l, ring r);
388long pLDeg1_WFirstTotalDegree(poly p,int *l, ring r);
389long pLDeg1c_WFirstTotalDegree(poly p,int *l, ring r);
[f82bd3]390BOOLEAN p_EqualPolys(poly p1, poly p2, const ring r);
[c6a3eb2]391
392long p_Deg(poly a, const ring r);
[35aab3]393/***************************************************************
394 *
395 * PDEBUG stuff
396 *
397 ***************************************************************/
398#ifdef PDEBUG
399// Returns TRUE if m is monom of p, FALSE otherwise
400BOOLEAN pIsMonomOf(poly p, poly m);
401// Returns TRUE if p and q have common monoms
402BOOLEAN pHaveCommonMonoms(poly p, poly q);
403
404// p_Check* routines return TRUE if everything is ok,
405// else, they report error message and return false
406
407// check if Lm(p) is from ring r
408BOOLEAN p_LmCheckIsFromRing(poly p, ring r);
409// check if Lm(p) != NULL, r != NULL and initialized && Lm(p) is from r
410BOOLEAN p_LmCheckPolyRing(poly p, ring r);
411// check if all monoms of p are from ring r
412BOOLEAN p_CheckIsFromRing(poly p, ring r);
413// check r != NULL and initialized && all monoms of p are from r
414BOOLEAN p_CheckPolyRing(poly p, ring r);
415// check if r != NULL and initialized
416BOOLEAN p_CheckRing(ring r);
417// only do check if cond
[14d732]418
419
[35aab3]420#define pIfThen(cond, check) do {if (cond) {check;}} while (0)
421
422BOOLEAN _p_Test(poly p, ring r, int level);
423BOOLEAN _p_LmTest(poly p, ring r, int level);
424BOOLEAN _pp_Test(poly p, ring lmRing, ring tailRing, int level);
425
426#define p_Test(p,r)     _p_Test(p, r, PDEBUG)
427#define p_LmTest(p,r)   _p_LmTest(p, r, PDEBUG)
428#define pp_Test(p, lmRing, tailRing)    _pp_Test(p, lmRing, tailRing, PDEBUG)
429
430#else // ! PDEBUG
431
432#define pIsMonomOf(p, q)        (TRUE)
433#define pHaveCommonMonoms(p, q) (TRUE)
434#define p_LmCheckIsFromRing(p,r)  ((void)0)
435#define p_LmCheckPolyRing(p,r)    ((void)0)
436#define p_CheckIsFromRing(p,r)  ((void)0)
437#define p_CheckPolyRing(p,r)    ((void)0)
438#define p_CheckRing(r)          ((void)0)
439#define P_CheckIf(cond, check)  ((void)0)
440
[68fcc8]441#define p_Test(p,r)     (1)
442#define p_LmTest(p,r)   (1)
443#define pp_Test(p, lmRing, tailRing) (1)
[35aab3]444
445#endif
446
[a04c5e]447/***************************************************************
448 *
449 * Primitives for accessing and setting fields of a poly
450 *
451 ***************************************************************/
452
453static inline number p_SetCoeff(poly p, number n, ring r)
454{
455  p_LmCheckPolyRing2(p, r);
[8a8c9e]456  n_Delete(&(p->coef), r->cf);
[a04c5e]457  (p)->coef=n;
458  return n;
459}
460
461// order
462static inline long p_GetOrder(poly p, ring r)
463{
464  p_LmCheckPolyRing2(p, r);
465  if (r->typ==NULL) return ((p)->exp[r->pOrdIndex]);
466  int i=0;
467  loop
468  {
469    switch(r->typ[i].ord_typ)
470    {
471      case ro_wp_neg:
472        return (((long)((p)->exp[r->pOrdIndex]))-POLY_NEGWEIGHT_OFFSET);
473      case ro_syzcomp:
474      case ro_syz:
475      case ro_cp:
476        i++;
477        break;
478      //case ro_dp:
479      //case ro_wp:
480      default:
481        return ((p)->exp[r->pOrdIndex]);
482    }
483  }
484}
485
486// Setm
487static inline void p_Setm(poly p, const ring r)
488{
489  p_CheckRing2(r);
490  r->p_Setm(p, r);
491}
492
493// component
494static inline  unsigned long p_SetComp(poly p, unsigned long c, ring r)
495{
496  p_LmCheckPolyRing2(p, r);
497  pAssume2(rRing_has_Comp(r));
498  __p_GetComp(p,r) = c;
499  return c;
500}
501static inline unsigned long p_AddComp(poly p, unsigned long v, ring r)
502{
503  p_LmCheckPolyRing2(p, r);
504  pAssume2(rRing_has_Comp(r));
505  return __p_GetComp(p,r) += v;
506}
507static inline unsigned long p_SubComp(poly p, unsigned long v, ring r)
508{
509  p_LmCheckPolyRing2(p, r);
510  pAssume2(rRing_has_Comp(r));
[8a8c9e]511  _pPolyAssume2(__p_GetComp(p,r) >= v,p,r);
[a04c5e]512  return __p_GetComp(p,r) -= v;
513}
514static inline int p_Comp_k_n(poly a, poly b, int k, ring r)
515{
516  if ((a==NULL) || (b==NULL) ) return FALSE;
517  p_LmCheckPolyRing2(a, r);
518  p_LmCheckPolyRing2(b, r);
519  pAssume2(k > 0 && k <= r->N);
520  int i=k;
521  for(;i<=r->N;i++)
522  {
523    if (p_GetExp(a,i,r) != p_GetExp(b,i,r)) return FALSE;
524    //    if (a->exp[(r->VarOffset[i] & 0xffffff)] != b->exp[(r->VarOffset[i] & 0xffffff)]) return FALSE;
525  }
526  return TRUE;
527}
528
529#ifndef HAVE_EXPSIZES
530
531/// get a single variable exponent
532/// @Note:
533/// the integer VarOffset encodes:
534/// 1. the position of a variable in the exponent vector p->exp (lower 24 bits)
535/// 2. number of bits to shift to the right in the upper 8 bits (which takes at most 6 bits for 64 bit)
536/// Thus VarOffset always has 2 zero higher bits!
537static inline long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
538{
539  pAssume2((VarOffset >> (24 + 6)) == 0);
540#if 0
541  int pos=(VarOffset & 0xffffff);
542  int bitpos=(VarOffset >> 24);
543  unsigned long exp=(p->exp[pos] >> bitmask) & iBitmask;
544  return exp;
545#else
546  return (long)
547         ((p->exp[(VarOffset & 0xffffff)] >> (VarOffset >> 24))
548          & iBitmask);
549#endif
550}
551
552
553/// set a single variable exponent
554/// @Note:
555/// VarOffset encodes the position in p->exp @see p_GetExp
556static inline unsigned long p_SetExp(poly p, const unsigned long e, const unsigned long iBitmask, const int VarOffset)
557{
558  pAssume2(e>=0);
559  pAssume2(e<=iBitmask);
560  pAssume2((VarOffset >> (24 + 6)) == 0);
561
562  // shift e to the left:
563  register int shift = VarOffset >> 24;
564  unsigned long ee = e << shift /*(VarOffset >> 24)*/;
565  // find the bits in the exponent vector
566  register int offset = (VarOffset & 0xffffff);
567  // clear the bits in the exponent vector:
568  p->exp[offset]  &= ~( iBitmask << shift );
569  // insert e with |
570  p->exp[ offset ] |= ee;
571  return e;
572}
573
574
575#else // #ifdef HAVE_EXPSIZES // EXPERIMENTAL!!!
576
577static inline unsigned long BitMask(unsigned long bitmask, int twobits)
578{
579  // bitmask = 00000111111111111
580  // 0 must give bitmask!
581  // 1, 2, 3 - anything like 00011..11
582  pAssume2((twobits >> 2) == 0);
583  static const unsigned long _bitmasks[4] = {-1, 0x7fff, 0x7f, 0x3};
584  return bitmask & _bitmasks[twobits];
585}
586
587
588/// @Note: we may add some more info (6 ) into VarOffset and thus encode
589static inline long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
590{
591  int pos  =(VarOffset & 0xffffff);
592  int hbyte= (VarOffset >> 24); // the highest byte
593  int bitpos = hbyte & 0x3f; // last 6 bits
594  long bitmask = BitMask(iBitmask, hbyte >> 6);
595
596  long exp=(p->exp[pos] >> bitpos) & bitmask;
597  return exp;
598
599}
600
601static inline long p_SetExp(poly p, const long e, const unsigned long iBitmask, const int VarOffset)
602{
603  pAssume2(e>=0);
604  pAssume2(e <= BitMask(iBitmask, VarOffset >> 30));
605
606  // shift e to the left:
607  register int hbyte = VarOffset >> 24;
608  int bitmask = BitMask(iBitmask, hbyte >> 6);
609  register int shift = hbyte & 0x3f;
610  long ee = e << shift;
611  // find the bits in the exponent vector
612  register int offset = (VarOffset & 0xffffff);
613  // clear the bits in the exponent vector:
614  p->exp[offset]  &= ~( bitmask << shift );
615  // insert e with |
616  p->exp[ offset ] |= ee;
617  return e;
618}
619
620#endif // #ifndef HAVE_EXPSIZES
621
622
623static inline long p_GetExp(const poly p, const ring r, const int VarOffset)
624{
625  p_LmCheckPolyRing2(p, r);
626  pAssume2(VarOffset != -1);
627  return p_GetExp(p, r->bitmask, VarOffset);
628}
629
630static inline long p_SetExp(poly p, const long e, const ring r, const int VarOffset)
631{
632  p_LmCheckPolyRing2(p, r);
633  pAssume2(VarOffset != -1);
634  return p_SetExp(p, e, r->bitmask, VarOffset);
635}
636
637
638
639/// get v^th exponent for a monomial
640static inline long p_GetExp(const poly p, const int v, const ring r)
641{
642  p_LmCheckPolyRing2(p, r);
643  pAssume2(v>0 && v <= r->N);
644  pAssume2(r->VarOffset[v] != -1);
645  return p_GetExp(p, r->bitmask, r->VarOffset[v]);
646}
647
648
649/// set v^th exponent for a monomial
650static inline long p_SetExp(poly p, const int v, const long e, const ring r)
651{
652  p_LmCheckPolyRing2(p, r);
653  pAssume2(v>0 && v <= r->N);
654  pAssume2(r->VarOffset[v] != -1);
655  return p_SetExp(p, e, r->bitmask, r->VarOffset[v]);
656}
657
658
659
660
661
662// the following should be implemented more efficiently
663static inline  long p_IncrExp(poly p, int v, ring r)
664{
665  p_LmCheckPolyRing2(p, r);
666  int e = p_GetExp(p,v,r);
667  e++;
668  return p_SetExp(p,v,e,r);
669}
670static inline  long p_DecrExp(poly p, int v, ring r)
671{
672  p_LmCheckPolyRing2(p, r);
673  int e = p_GetExp(p,v,r);
674  pAssume2(e > 0);
675  e--;
676  return p_SetExp(p,v,e,r);
677}
678static inline  long p_AddExp(poly p, int v, long ee, ring r)
679{
680  p_LmCheckPolyRing2(p, r);
681  int e = p_GetExp(p,v,r);
682  e += ee;
683  return p_SetExp(p,v,e,r);
684}
685static inline  long p_SubExp(poly p, int v, long ee, ring r)
686{
687  p_LmCheckPolyRing2(p, r);
688  long e = p_GetExp(p,v,r);
689  pAssume2(e >= ee);
690  e -= ee;
691  return p_SetExp(p,v,e,r);
692}
693static inline  long p_MultExp(poly p, int v, long ee, ring r)
694{
695  p_LmCheckPolyRing2(p, r);
696  long e = p_GetExp(p,v,r);
697  e *= ee;
698  return p_SetExp(p,v,e,r);
699}
700
701static inline long p_GetExpSum(poly p1, poly p2, int i, ring r)
702{
703  p_LmCheckPolyRing2(p1, r);
704  p_LmCheckPolyRing2(p2, r);
705  return p_GetExp(p1,i,r) + p_GetExp(p2,i,r);
706}
707static inline long p_GetExpDiff(poly p1, poly p2, int i, ring r)
708{
709  return p_GetExp(p1,i,r) - p_GetExp(p2,i,r);
710}
711
712
713/***************************************************************
714 *
715 * Allocation/Initalization/Deletion
716 *
717 ***************************************************************/
718static inline poly p_New(ring r, omBin bin)
719{
720  p_CheckRing2(r);
721  pAssume2(bin != NULL && r->PolyBin->sizeW == bin->sizeW);
722  poly p;
723  omTypeAllocBin(poly, p, bin);
724  p_SetRingOfLm(p, r);
725  return p;
726}
727
728static inline poly p_New(ring r)
729{
730  return p_New(r, r->PolyBin);
731}
732
733static inline void p_LmFree(poly p, ring r)
734{
735  p_LmCheckPolyRing2(p, r);
736  omFreeBinAddr(p);
737}
738static inline void p_LmFree(poly *p, ring r)
739{
740  p_LmCheckPolyRing2(*p, r);
741  poly h = *p;
742  *p = pNext(h);
743  omFreeBinAddr(h);
744}
745static inline poly p_LmFreeAndNext(poly p, ring r)
746{
747  p_LmCheckPolyRing2(p, r);
748  poly pnext = pNext(p);
749  omFreeBinAddr(p);
750  return pnext;
751}
[8a8c9e]752static inline void p_LmDelete(poly p, const ring r)
[a04c5e]753{
754  p_LmCheckPolyRing2(p, r);
[8a8c9e]755  n_Delete(&pGetCoeff(p), r->cf);
[a04c5e]756  omFreeBinAddr(p);
757}
[8a8c9e]758static inline void p_LmDelete(poly *p, const ring r)
[a04c5e]759{
760  p_LmCheckPolyRing2(*p, r);
761  poly h = *p;
762  *p = pNext(h);
[8a8c9e]763  n_Delete(&pGetCoeff(h), r->cf);
[a04c5e]764  omFreeBinAddr(h);
765}
[8a8c9e]766static inline poly p_LmDeleteAndNext(poly p, const ring r)
[a04c5e]767{
768  p_LmCheckPolyRing2(p, r);
769  poly pnext = pNext(p);
[8a8c9e]770  n_Delete(&pGetCoeff(p), r->cf);
[a04c5e]771  omFreeBinAddr(p);
772  return pnext;
773}
774
775/***************************************************************
776 *
777 * Misc routines
778 *
779 ***************************************************************/
780static inline int p_Cmp(poly p1, poly p2, ring r)
781{
782  if (p2==NULL)
783    return 1;
784  if (p1==NULL)
785    return -1;
786  return p_LmCmp(p1,p2,r);
787}
788
789static inline unsigned long p_GetMaxExp(const poly p, const ring r)
790{
791  return p_GetMaxExp(p_GetMaxExpL(p, r), r);
792}
793
794static inline unsigned long p_GetMaxExp(const unsigned long l, const ring r)
795{
796  unsigned long bitmask = r->bitmask;
797  unsigned long max = (l & bitmask);
798  unsigned long j = r->ExpPerLong - 1;
799
800  if (j > 0)
801  {
802    unsigned long i = r->BitsPerExp;
803    long e;
804    loop
805    {
806      e = ((l >> i) & bitmask);
807      if ((unsigned long) e > max)
808        max = e;
809      j--;
810      if (j==0) break;
811      i += r->BitsPerExp;
812    }
813  }
814  return max;
815}
816
817static inline unsigned long
818p_GetTotalDegree(const unsigned long l, const ring r, const int number_of_exps)
819{
820  const unsigned long bitmask = r->bitmask;
821  unsigned long sum = (l & bitmask);
822  unsigned long j = number_of_exps - 1;
823
824  if (j > 0)
825  {
826    unsigned long i = r->BitsPerExp;
827    loop
828    {
829      sum += ((l >> i) & bitmask);
830      j--;
831      if (j==0) break;
832      i += r->BitsPerExp;
833    }
834  }
835  return sum;
836}
837
838static inline unsigned long
839p_GetTotalDegree(const unsigned long l, const ring r)
840{
841  return p_GetTotalDegree(l, r, r->ExpPerLong);
842}
843
844/***************************************************************
845 *
846 * Dispatcher to r->p_Procs, they do the tests/checks
847 *
848 ***************************************************************/
849// returns a copy of p
850static inline poly p_Copy(poly p, const ring r)
851{
852#ifdef PDEBUG
853  poly pp= r->p_Procs->p_Copy(p, r);
854  p_Test(pp,r);
855  return pp;
856#else
857  return r->p_Procs->p_Copy(p, r);
858#endif
859}
860
861static inline poly p_Copy(poly p, const ring lmRing, const ring tailRing)
862{
863#ifndef PDEBUG
864  if (tailRing == lmRing)
865    return tailRing->p_Procs->p_Copy(p, tailRing);
866#endif
867  if (p != NULL)
868  {
869    poly pres = p_Head(p, lmRing);
870    pNext(pres) = tailRing->p_Procs->p_Copy(pNext(p), tailRing);
871    return pres;
872  }
873  else
874    return NULL;
875}
876
877// deletes *p, and sets *p to NULL
878static inline void p_Delete(poly *p, const ring r)
879{
880  r->p_Procs->p_Delete(p, r);
881}
882
883static inline void p_Delete(poly *p,  const ring lmRing, const ring tailRing)
884{
885#ifndef PDEBUG
886  if (tailRing == lmRing)
887  {
888    tailRing->p_Procs->p_Delete(p, tailRing);
889    return;
890  }
891#endif
892  if (*p != NULL)
893  {
894    if (pNext(*p) != NULL)
895      tailRing->p_Procs->p_Delete(&pNext(*p), tailRing);
896    p_LmDelete(p, lmRing);
897  }
898}
899
900static inline poly p_ShallowCopyDelete(poly p, const ring r, omBin bin)
901{
902  p_LmCheckPolyRing2(p, r);
903  pAssume2(r->PolyBin->sizeW == bin->sizeW);
904  return r->p_Procs->p_ShallowCopyDelete(p, r, bin);
905}
906
907// returns p+q, destroys p and q
908static inline poly p_Add_q(poly p, poly q, const ring r)
909{
910  int shorter;
911  return r->p_Procs->p_Add_q(p, q, shorter, r);
912}
913
914static inline poly p_Add_q(poly p, poly q, int &lp, int lq, const ring r)
915{
916  int shorter;
917  poly res = r->p_Procs->p_Add_q(p, q, shorter, r);
918  lp = (lp + lq) - shorter;
919  return res;
920}
[35aab3]921
[a04c5e]922// returns p*n, destroys p
923static inline poly p_Mult_nn(poly p, number n, const ring r)
924{
[8a8c9e]925  if (n_IsOne(n, r->cf))
[a04c5e]926    return p;
927  else
928    return r->p_Procs->p_Mult_nn(p, n, r);
929}
930
931static inline poly p_Mult_nn(poly p, number n, const ring lmRing,
932                        const ring tailRing)
933{
934#ifndef PDEBUG
935  if (lmRing == tailRing)
936  {
937    return p_Mult_nn(p, n, tailRing);
938  }
939#endif
940  poly pnext = pNext(p);
941  pNext(p) = NULL;
942  p = lmRing->p_Procs->p_Mult_nn(p, n, lmRing);
943  pNext(p) = tailRing->p_Procs->p_Mult_nn(pnext, n, tailRing);
944  return p;
945}
946
947// returns p*n, does not destroy p
948static inline poly pp_Mult_nn(poly p, number n, const ring r)
949{
[8a8c9e]950  if (n_IsOne(n, r->cf))
[a04c5e]951    return p_Copy(p, r);
952  else
953    return r->p_Procs->pp_Mult_nn(p, n, r);
954}
955
956// returns Copy(p)*m, does neither destroy p nor m
957static inline poly pp_Mult_mm(poly p, poly m, const ring r)
958{
959  if (p_LmIsConstant(m, r))
960    return pp_Mult_nn(p, pGetCoeff(m), r);
961  else
962  {
963    poly last;
964    return r->p_Procs->pp_Mult_mm(p, m, r, last);
965  }
966}
967
968// returns p*m, destroys p, const: m
969static inline poly p_Mult_mm(poly p, poly m, const ring r)
970{
971  if (p_LmIsConstant(m, r))
972    return p_Mult_nn(p, pGetCoeff(m), r);
973  else
974    return r->p_Procs->p_Mult_mm(p, m, r);
975}
976
977// return p - m*Copy(q), destroys p; const: p,m
978static inline poly p_Minus_mm_Mult_qq(poly p, poly m, poly q, const ring r)
979{
980#ifdef HAVE_PLURAL
981  if (rIsPluralRing(r))
982  {
983    int lp, lq;
984    poly spNoether;
985    return nc_p_Minus_mm_Mult_qq(p, m, q, lp, lq, spNoether, r);
986  }
987#endif
988
989  int shorter;
990  poly last;
991
992  return r->p_Procs->p_Minus_mm_Mult_qq(p, m, q, shorter, NULL, r, last); // !!!
993}
994
995static inline poly p_Minus_mm_Mult_qq(poly p, poly m, poly q, int &lp, int lq,
996                                 poly spNoether, const ring r)
997{
998#ifdef HAVE_PLURAL
999  if (rIsPluralRing(r))
1000     return nc_p_Minus_mm_Mult_qq(p, m, q, lp, lq, spNoether, r);
1001#endif
1002
1003  int shorter;
1004  poly last,res;
1005  res = r->p_Procs->p_Minus_mm_Mult_qq(p, m, q, shorter, spNoether, r, last);
1006  lp = (lp + lq) - shorter;
1007  return res;
1008}
1009
1010static inline poly pp_Mult_Coeff_mm_DivSelect(poly p, const poly m, const ring r)
1011{
1012  int shorter;
1013  return r->p_Procs->pp_Mult_Coeff_mm_DivSelect(p, m, shorter, r);
1014}
1015
1016static inline poly pp_Mult_Coeff_mm_DivSelect(poly p, int &lp, const poly m, const ring r)
1017{
1018  int shorter;
1019  poly pp = r->p_Procs->pp_Mult_Coeff_mm_DivSelect(p, m, shorter, r);
1020  lp -= shorter;
1021  return pp;
1022}
1023
1024// returns -p, destroys p
1025static inline poly p_Neg(poly p, const ring r)
1026{
1027  return r->p_Procs->p_Neg(p, r);
1028}
1029
1030extern poly  _p_Mult_q(poly p, poly q, const int copy, const ring r);
1031// returns p*q, destroys p and q
1032static inline poly p_Mult_q(poly p, poly q, const ring r)
1033{
1034  if (p == NULL)
1035  {
1036    r->p_Procs->p_Delete(&q, r);
1037    return NULL;
1038  }
1039  if (q == NULL)
1040  {
1041    r->p_Procs->p_Delete(&p, r);
1042    return NULL;
1043  }
1044
1045  if (pNext(p) == NULL)
1046  {
1047#ifdef HAVE_PLURAL
1048    if (rIsPluralRing(r))
1049      q = nc_mm_Mult_p(p, q, r);
1050    else
1051#endif /* HAVE_PLURAL */
1052      q = r->p_Procs->p_Mult_mm(q, p, r);
1053
1054    r->p_Procs->p_Delete(&p, r);
1055    return q;
1056  }
1057
1058  if (pNext(q) == NULL)
1059  {
1060  // NEEDED
1061#ifdef HAVE_PLURAL
1062/*    if (rIsPluralRing(r))
1063      p = gnc_p_Mult_mm(p, q, r); // ???
1064    else*/
1065#endif /* HAVE_PLURAL */
1066      p = r->p_Procs->p_Mult_mm(p, q, r);
1067
1068    r->p_Procs->p_Delete(&q, r);
1069    return p;
1070  }
1071#ifdef HAVE_PLURAL
1072  if (rIsPluralRing(r))
1073    return _nc_p_Mult_q(p, q, r);
1074  else
1075#endif
1076  return _p_Mult_q(p, q, 0, r);
1077}
1078
1079// returns p*q, does neither destroy p nor q
1080static inline poly pp_Mult_qq(poly p, poly q, const ring r)
1081{
1082  poly last;
1083  if (p == NULL || q == NULL) return NULL;
1084
1085  if (pNext(p) == NULL)
1086  {
1087#ifdef HAVE_PLURAL
1088    if (rIsPluralRing(r))
1089      return nc_mm_Mult_pp(p, q, r);
1090#endif
1091    return r->p_Procs->pp_Mult_mm(q, p, r, last);
1092  }
1093
1094  if (pNext(q) == NULL)
1095  {
1096    return r->p_Procs->pp_Mult_mm(p, q, r, last);
1097  }
1098
1099  poly qq = q;
1100  if (p == q)
1101    qq = p_Copy(q, r);
1102
1103  poly res;
1104#ifdef HAVE_PLURAL
1105  if (rIsPluralRing(r))
1106    res = _nc_pp_Mult_qq(p, qq, r);
1107  else
1108#endif
1109    res = _p_Mult_q(p, qq, 1, r);
1110
1111  if (qq != q)
1112    p_Delete(&qq, r);
1113  return res;
1114}
1115
1116// returns p + m*q destroys p, const: q, m
1117static inline poly p_Plus_mm_Mult_qq(poly p, poly m, poly q, int &lp, int lq,
1118                                const ring r)
1119{
1120#ifdef HAVE_PLURAL
1121  if (rIsPluralRing(r))
1122    return nc_p_Plus_mm_Mult_qq(p, m, q, lp, lq, r);
1123#endif
1124
1125// this should be implemented more efficiently
1126  poly res, last;
1127  int shorter;
1128  number n_old = pGetCoeff(m);
[8a8c9e]1129  number n_neg = n_Copy(n_old, r->cf);
1130  n_neg = n_Neg(n_neg, r->cf);
[a04c5e]1131  pSetCoeff0(m, n_neg);
1132  res = r->p_Procs->p_Minus_mm_Mult_qq(p, m, q, shorter, NULL, r, last);
1133  lp = (lp + lq) - shorter;
1134  pSetCoeff0(m, n_old);
[8a8c9e]1135  n_Delete(&n_neg, r->cf);
[a04c5e]1136  return res;
1137}
1138
1139static inline poly p_Plus_mm_Mult_qq(poly p, poly m, poly q, const ring r)
1140{
1141  int lp = 0, lq = 0;
1142  return p_Plus_mm_Mult_qq(p, m, q, lp, lq, r);
1143}
1144
1145static inline poly p_Merge_q(poly p, poly q, const ring r)
1146{
1147  return r->p_Procs->p_Merge_q(p, q, r);
1148}
1149
1150static inline poly p_SortAdd(poly p, const ring r, BOOLEAN revert)
1151{
1152  if (revert) p = pReverse(p);
1153  return sBucketSortAdd(p, r);
1154}
1155
1156static inline poly p_SortMerge(poly p, const ring r, BOOLEAN revert)
1157{
1158  if (revert) p = pReverse(p);
1159  return sBucketSortMerge(p, r);
1160}
1161
1162/***************************************************************
1163 *
1164 * I/O
1165 *
1166 ***************************************************************/
1167static inline char*     p_String(poly p, ring p_ring)
1168{
1169  return p_String(p, p_ring, p_ring);
1170}
1171static inline char*     p_String0(poly p, ring p_ring)
1172{
1173  return p_String0(p, p_ring, p_ring);
1174}
1175static inline void      p_Write(poly p, ring p_ring)
1176{
1177  p_Write(p, p_ring, p_ring);
1178}
1179static inline void      p_Write0(poly p, ring p_ring)
1180{
1181  p_Write0(p, p_ring, p_ring);
1182}
1183static inline void      p_wrp(poly p, ring p_ring)
1184{
1185  p_wrp(p, p_ring, p_ring);
1186}
1187
1188/***************************************************************
1189 *  Purpose: implementation of poly procs which iter over ExpVector
1190 *  Author:  obachman (Olaf Bachmann)
1191 *  Created: 8/00
1192 *  Version: $Id$
1193 *******************************************************************/
[6bec87]1194#include <misc/mylimits.h>
[20b794]1195#include <polys/templates/p_MemCmp.h>
1196// #include <polys/structs.h>
1197#include <polys/monomials/ring.h>
1198#include <coeffs/coeffs.h>
[a04c5e]1199
1200#if PDEBUG > 0
1201
1202#define _p_LmCmpAction(p, q, r, actionE, actionG, actionS)  \
1203do                                                          \
1204{                                                           \
1205  int _cmp = p_LmCmp(p,q,r);                                \
1206  if (_cmp == 0) actionE;                                   \
1207  if (_cmp == 1) actionG;                                   \
1208  actionS;                                                  \
1209}                                                           \
1210while(0)
1211
1212#else
1213
1214#define _p_LmCmpAction(p, q, r, actionE, actionG, actionS)                      \
1215 p_MemCmp_LengthGeneral_OrdGeneral(p->exp, q->exp, r->CmpL_Size, r->ordsgn,    \
1216                                   actionE, actionG, actionS)
1217
1218#endif
1219
1220#define pDivAssume(x)   ((void)0)
1221
[20b794]1222#include <omalloc/omalloc.h>
1223#include <coeffs/coeffs.h>
[6bec87]1224#include <polys/monomials/p_polys.h>
[20b794]1225#include <polys/templates/p_MemAdd.h>
1226#include <polys/templates/p_MemCopy.h>
[a04c5e]1227
1228/***************************************************************
1229 *
1230 * Allocation/Initalization/Deletion
1231 *
1232 ***************************************************************/
1233// adjustments for negative weights
1234static inline void p_MemAdd_NegWeightAdjust(poly p, const ring r)
1235{
1236  if (r->NegWeightL_Offset != NULL)
1237  {
1238    for (int i=r->NegWeightL_Size-1; i>=0; i--)
1239    {
1240      p->exp[r->NegWeightL_Offset[i]] -= POLY_NEGWEIGHT_OFFSET;
1241    }
1242  }
1243}
1244static inline void p_MemSub_NegWeightAdjust(poly p, const ring r)
1245{
1246  if (r->NegWeightL_Offset != NULL)
1247  {
1248    for (int i=r->NegWeightL_Size-1; i>=0; i--)
1249    {
1250      p->exp[r->NegWeightL_Offset[i]] += POLY_NEGWEIGHT_OFFSET;
1251    }
1252  }
1253}
1254// ExpVextor(d_p) = ExpVector(s_p)
1255static inline void p_ExpVectorCopy(poly d_p, poly s_p, const ring r)
1256{
1257  p_LmCheckPolyRing1(d_p, r);
1258  p_LmCheckPolyRing1(s_p, r);
1259  p_MemCopy_LengthGeneral(d_p->exp, s_p->exp, r->ExpL_Size);
1260}
1261
1262static inline poly p_Init(const ring r, omBin bin)
1263{
1264  p_CheckRing1(r);
1265  pAssume1(bin != NULL && r->PolyBin->sizeW == bin->sizeW);
1266  poly p;
1267  omTypeAlloc0Bin(poly, p, bin);
1268  p_MemAdd_NegWeightAdjust(p, r);
1269  p_SetRingOfLm(p, r);
1270  return p;
1271}
1272static inline poly p_Init(const ring r)
1273{
1274  return p_Init(r, r->PolyBin);
1275}
1276
1277static inline poly p_LmInit(poly p, const ring r)
1278{
1279  p_LmCheckPolyRing1(p, r);
1280  poly np;
1281  omTypeAllocBin(poly, np, r->PolyBin);
1282  p_SetRingOfLm(np, r);
1283  p_MemCopy_LengthGeneral(np->exp, p->exp, r->ExpL_Size);
1284  pNext(np) = NULL;
1285  pSetCoeff0(np, NULL);
1286  return np;
1287}
1288static inline poly p_LmInit(poly s_p, const ring s_r, const ring d_r, omBin d_bin)
1289{
1290  p_LmCheckPolyRing1(s_p, s_r);
1291  p_CheckRing(d_r);
1292  pAssume1(d_r->N <= s_r->N);
1293  poly d_p = p_Init(d_r, d_bin);
1294  for (int i=d_r->N; i>0; i--)
1295  {
1296    p_SetExp(d_p, i, p_GetExp(s_p, i,s_r), d_r);
1297  }
1298  if (rRing_has_Comp(d_r))
1299  {
1300    p_SetComp(d_p, p_GetComp(s_p,s_r), d_r);
1301  }
1302  p_Setm(d_p, d_r);
1303  return d_p;
1304}
1305static inline poly p_LmInit(poly s_p, const ring s_r, const ring d_r)
1306{
1307  pAssume1(d_r != NULL);
1308  return p_LmInit(s_p, s_r, d_r, d_r->PolyBin);
1309}
1310static inline poly p_Head(poly p, const ring r)
1311{
1312  if (p == NULL) return NULL;
1313  p_LmCheckPolyRing1(p, r);
1314  poly np;
1315  omTypeAllocBin(poly, np, r->PolyBin);
1316  p_SetRingOfLm(np, r);
1317  p_MemCopy_LengthGeneral(np->exp, p->exp, r->ExpL_Size);
1318  pNext(np) = NULL;
[8a8c9e]1319  pSetCoeff0(np, n_Copy(pGetCoeff(p), r->cf));
[a04c5e]1320  return np;
1321}
[f550e86]1322// set all exponents l..k to 0, assume exp. k+1..n and 1..l-1 are in
[a04c5e]1323// different blocks
1324// set coeff to 1
1325static inline poly p_GetExp_k_n(poly p, int l, int k, const ring r)
1326{
1327  if (p == NULL) return NULL;
1328  p_LmCheckPolyRing1(p, r);
1329  poly np;
1330  omTypeAllocBin(poly, np, r->PolyBin);
1331  p_SetRingOfLm(np, r);
1332  p_MemCopy_LengthGeneral(np->exp, p->exp, r->ExpL_Size);
1333  pNext(np) = NULL;
[8a8c9e]1334  pSetCoeff0(np, n_Init(1, r->cf));
[a04c5e]1335  int i;
1336  for(i=l;i<=k;i++)
1337  {
1338    //np->exp[(r->VarOffset[i] & 0xffffff)] =0;
1339    p_SetExp(np,i,0,r);
1340  }
1341  p_Setm(np,r);
1342  return np;
1343}
1344
1345static inline poly p_LmShallowCopyDelete(poly p, const ring r, omBin bin)
1346{
1347  p_LmCheckPolyRing1(p, r);
1348  pAssume1(bin->sizeW == r->PolyBin->sizeW);
1349  poly new_p = p_New(r);
1350  p_MemCopy_LengthGeneral(new_p->exp, p->exp, r->ExpL_Size);
1351  pSetCoeff0(new_p, pGetCoeff(p));
1352  pNext(new_p) = pNext(p);
1353  omFreeBinAddr(p);
1354  return new_p;
1355}
1356
1357/***************************************************************
1358 *
1359 * Operation on ExpVectors
1360 *
1361 ***************************************************************/
1362// ExpVector(p1) += ExpVector(p2)
1363static inline void p_ExpVectorAdd(poly p1, poly p2, const ring r)
1364{
1365  p_LmCheckPolyRing1(p1, r);
1366  p_LmCheckPolyRing1(p2, r);
1367#if PDEBUG >= 1
1368  for (int i=1; i<=r->N; i++)
1369    pAssume1((unsigned long) (p_GetExp(p1, i, r) + p_GetExp(p2, i, r)) <= r->bitmask);
1370  pAssume1(p_GetComp(p1, r) == 0 || p_GetComp(p2, r) == 0);
1371#endif
1372
1373  p_MemAdd_LengthGeneral(p1->exp, p2->exp, r->ExpL_Size);
1374  p_MemAdd_NegWeightAdjust(p1, r);
1375}
1376// ExpVector(p1) -= ExpVector(p2)
1377static inline void p_ExpVectorSub(poly p1, poly p2, const ring r)
1378{
1379  p_LmCheckPolyRing1(p1, r);
1380  p_LmCheckPolyRing1(p2, r);
1381#if PDEBUG >= 1
1382  for (int i=1; i<=r->N; i++)
1383    pAssume1(p_GetExp(p1, i, r) >= p_GetExp(p2, i, r));
1384  pAssume1(p_GetComp(p1, r) == 0 || p_GetComp(p2, r) == 0 ||
1385          p_GetComp(p1, r) == p_GetComp(p2, r));
1386#endif
1387
1388  p_MemSub_LengthGeneral(p1->exp, p2->exp, r->ExpL_Size);
1389  p_MemSub_NegWeightAdjust(p1, r);
1390
1391}
1392// ExpVector(p1) += ExpVector(p2) - ExpVector(p3)
1393static inline void p_ExpVectorAddSub(poly p1, poly p2, poly p3, const ring r)
1394{
1395  p_LmCheckPolyRing1(p1, r);
1396  p_LmCheckPolyRing1(p2, r);
1397  p_LmCheckPolyRing1(p3, r);
1398#if PDEBUG >= 1
1399  for (int i=1; i<=r->N; i++)
1400    pAssume1(p_GetExp(p1, i, r) + p_GetExp(p2, i, r) >= p_GetExp(p3, i, r));
1401  pAssume1(p_GetComp(p1, r) == 0 ||
1402           (p_GetComp(p2, r) - p_GetComp(p3, r) == 0) ||
1403           (p_GetComp(p1, r) == p_GetComp(p2, r) - p_GetComp(p3, r)));
1404#endif
1405
1406  p_MemAddSub_LengthGeneral(p1->exp, p2->exp, p3->exp, r->ExpL_Size);
1407  // no need to adjust in case of NegWeights
1408}
1409
1410// ExpVector(pr) = ExpVector(p1) + ExpVector(p2)
1411static inline void p_ExpVectorSum(poly pr, poly p1, poly p2, const ring r)
1412{
1413  p_LmCheckPolyRing1(p1, r);
1414  p_LmCheckPolyRing1(p2, r);
1415  p_LmCheckPolyRing1(pr, r);
1416#if PDEBUG >= 1
1417  for (int i=1; i<=r->N; i++)
1418    pAssume1((unsigned long) (p_GetExp(p1, i, r) + p_GetExp(p2, i, r)) <= r->bitmask);
1419  pAssume1(p_GetComp(p1, r) == 0 || p_GetComp(p2, r) == 0);
1420#endif
1421
1422  p_MemSum_LengthGeneral(pr->exp, p1->exp, p2->exp, r->ExpL_Size);
1423  p_MemAdd_NegWeightAdjust(pr, r);
1424}
1425// ExpVector(pr) = ExpVector(p1) - ExpVector(p2)
1426static inline void p_ExpVectorDiff(poly pr, poly p1, poly p2, const ring r)
1427{
1428  p_LmCheckPolyRing1(p1, r);
1429  p_LmCheckPolyRing1(p2, r);
1430  p_LmCheckPolyRing1(pr, r);
1431#if PDEBUG >= 2
1432  for (int i=1; i<=r->N; i++)
1433    pAssume1(p_GetExp(p1, i, r) >= p_GetExp(p2, i, r));
1434  pAssume1(!rRing_has_Comp(r) || p_GetComp(p1, r) == p_GetComp(p2, r));
1435#endif
1436
1437  p_MemDiff_LengthGeneral(pr->exp, p1->exp, p2->exp, r->ExpL_Size);
1438  p_MemSub_NegWeightAdjust(pr, r);
1439}
1440
1441static inline BOOLEAN p_ExpVectorEqual(poly p1, poly p2, const ring r)
1442{
1443  p_LmCheckPolyRing1(p1, r);
1444  p_LmCheckPolyRing1(p2, r);
1445
1446  int i = r->ExpL_Size;
1447  unsigned long *ep = p1->exp;
1448  unsigned long *eq = p2->exp;
1449
1450  do
1451  {
1452    i--;
1453    if (ep[i] != eq[i]) return FALSE;
1454  }
1455  while (i);
1456  return TRUE;
1457}
1458
1459static inline long p_Totaldegree(poly p, const ring r)
1460{
1461  p_LmCheckPolyRing1(p, r);
1462  unsigned long s = p_GetTotalDegree(p->exp[r->VarL_Offset[0]],
1463                                     r,
1464                                     r->MinExpPerLong);
1465  for (int i=r->VarL_Size-1; i>0; i--)
1466  {
1467    s += p_GetTotalDegree(p->exp[r->VarL_Offset[i]], r);
1468  }
1469  return (long)s;
1470}
1471
1472static inline void p_GetExpV(poly p, int *ev, const ring r)
1473{
1474  p_LmCheckPolyRing1(p, r);
1475  for (int j = r->N; j; j--)
1476      ev[j] = p_GetExp(p, j, r);
1477
1478  ev[0] = p_GetComp(p, r);
1479}
1480static inline void p_SetExpV(poly p, int *ev, const ring r)
1481{
1482  p_LmCheckPolyRing1(p, r);
1483  for (int j = r->N; j; j--)
1484      p_SetExp(p, j, ev[j], r);
1485
1486  p_SetComp(p, ev[0],r);
1487  p_Setm(p, r);
1488}
1489
1490/***************************************************************
1491 *
1492 * Comparison w.r.t. monomial ordering
1493 *
1494 ***************************************************************/
1495static inline int p_LmCmp(poly p, poly q, const ring r)
1496{
1497  p_LmCheckPolyRing1(p, r);
1498  p_LmCheckPolyRing1(q, r);
1499
1500  p_MemCmp_LengthGeneral_OrdGeneral(p->exp, q->exp, r->CmpL_Size, r->ordsgn,
1501                                    return 0, return 1, return -1);
1502}
1503
1504
1505/***************************************************************
1506 *
1507 * divisibility
1508 *
1509 ***************************************************************/
1510// return: FALSE, if there exists i, such that a->exp[i] > b->exp[i]
1511//         TRUE, otherwise
1512// (1) Consider long vars, instead of single exponents
1513// (2) Clearly, if la > lb, then FALSE
1514// (3) Suppose la <= lb, and consider first bits of single exponents in l:
1515//     if TRUE, then value of these bits is la ^ lb
1516//     if FALSE, then la-lb causes an "overflow" into one of those bits, i.e.,
1517//               la ^ lb != la - lb
1518static inline BOOLEAN _p_LmDivisibleByNoComp(poly a, poly b, const ring r)
1519{
1520  int i=r->VarL_Size - 1;
1521  unsigned long divmask = r->divmask;
1522  unsigned long la, lb;
1523
1524  if (r->VarL_LowIndex >= 0)
1525  {
1526    i += r->VarL_LowIndex;
1527    do
1528    {
1529      la = a->exp[i];
1530      lb = b->exp[i];
1531      if ((la > lb) ||
1532          (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask)))
1533      {
1534        pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == FALSE);
1535        return FALSE;
1536      }
1537      i--;
1538    }
1539    while (i>=r->VarL_LowIndex);
1540  }
1541  else
1542  {
1543    do
1544    {
1545      la = a->exp[r->VarL_Offset[i]];
1546      lb = b->exp[r->VarL_Offset[i]];
1547      if ((la > lb) ||
1548          (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask)))
1549      {
1550        pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == FALSE);
1551        return FALSE;
1552      }
1553      i--;
1554    }
1555    while (i>=0);
1556  }
1557#ifdef HAVE_RINGS
1558  pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == nDivBy(p_GetCoeff(b, r), p_GetCoeff(a, r)));
[8a8c9e]1559  return (!rField_is_Ring(r)) || n_DivBy(p_GetCoeff(b, r), p_GetCoeff(a, r), r->cf);
[a04c5e]1560#else
1561  pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == TRUE);
1562  return TRUE;
1563#endif
1564}
1565
1566static inline BOOLEAN _p_LmDivisibleByNoComp(poly a, const ring r_a, poly b, const ring r_b)
1567{
1568  int i=r_a->N;
1569  pAssume1(r_a->N == r_b->N);
1570
1571  do
1572  {
1573    if (p_GetExp(a,i,r_a) > p_GetExp(b,i,r_b))
1574      return FALSE;
1575    i--;
1576  }
1577  while (i);
1578#ifdef HAVE_RINGS
[8a8c9e]1579  return n_DivBy(p_GetCoeff(b, r_b), p_GetCoeff(a, r_a), r_a->cf);
[a04c5e]1580#else
1581  return TRUE;
1582#endif
1583}
1584
1585#ifdef HAVE_RATGRING
1586static inline BOOLEAN _p_LmDivisibleByNoCompPart(poly a, const ring r_a, poly b, const ring r_b,const int start, const int end)
1587{
1588  int i=end;
1589  pAssume1(r_a->N == r_b->N);
1590
1591  do
1592  {
1593    if (p_GetExp(a,i,r_a) > p_GetExp(b,i,r_b))
1594      return FALSE;
1595    i--;
1596  }
1597  while (i>=start);
1598#ifdef HAVE_RINGS
1599  return nDivBy(p_GetCoeff(b, r), p_GetCoeff(a, r));
1600#else
1601  return TRUE;
1602#endif
1603}
1604static inline BOOLEAN _p_LmDivisibleByPart(poly a, const ring r_a, poly b, const ring r_b,const int start, const int end)
1605{
1606  if (p_GetComp(a, r_a) == 0 || p_GetComp(a,r_a) == p_GetComp(b,r_b))
1607    return _p_LmDivisibleByNoCompPart(a, r_a, b, r_b,start,end);
1608  return FALSE;
1609}
1610static inline BOOLEAN p_LmDivisibleByPart(poly a, poly b, const ring r,const int start, const int end)
1611{
1612  p_LmCheckPolyRing1(b, r);
1613  pIfThen1(a != NULL, p_LmCheckPolyRing1(b, r));
1614  if (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r))
1615    return _p_LmDivisibleByNoCompPart(a, r, b, r,start, end);
1616  return FALSE;
1617}
1618#endif
1619static inline BOOLEAN _p_LmDivisibleBy(poly a, poly b, const ring r)
1620{
1621  if (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r))
1622    return _p_LmDivisibleByNoComp(a, b, r);
1623  return FALSE;
1624}
1625static inline BOOLEAN _p_LmDivisibleBy(poly a, const ring r_a, poly b, const ring r_b)
1626{
1627  if (p_GetComp(a, r_a) == 0 || p_GetComp(a,r_a) == p_GetComp(b,r_b))
1628    return _p_LmDivisibleByNoComp(a, r_a, b, r_b);
1629  return FALSE;
1630}
1631static inline BOOLEAN p_LmDivisibleByNoComp(poly a, poly b, const ring r)
1632{
1633  p_LmCheckPolyRing1(a, r);
1634  p_LmCheckPolyRing1(b, r);
1635  return _p_LmDivisibleByNoComp(a, b, r);
1636}
1637static inline BOOLEAN p_LmDivisibleBy(poly a, poly b, const ring r)
1638{
1639  p_LmCheckPolyRing1(b, r);
1640  pIfThen1(a != NULL, p_LmCheckPolyRing1(b, r));
1641  if (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r))
1642    return _p_LmDivisibleByNoComp(a, b, r);
1643  return FALSE;
1644}
1645
1646static inline BOOLEAN p_DivisibleBy(poly a, poly b, const ring r)
1647{
1648  pIfThen1(b!=NULL, p_LmCheckPolyRing1(b, r));
1649  pIfThen1(a!=NULL, p_LmCheckPolyRing1(a, r));
1650
1651  if (a != NULL && (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r)))
1652      return _p_LmDivisibleByNoComp(a,b,r);
1653  return FALSE;
1654}
1655static inline BOOLEAN p_DivisibleBy(poly a, const ring r_a, poly b, const ring r_b)
1656{
1657  pIfThen1(b!=NULL, p_LmCheckPolyRing1(b, r_b));
1658  pIfThen1(a!=NULL, p_LmCheckPolyRing1(a, r_a));
1659  if (a != NULL) {
1660      return _p_LmDivisibleBy(a, r_a, b, r_b);
1661  }
1662  return FALSE;
1663}
1664static inline BOOLEAN p_LmDivisibleBy(poly a, const ring r_a, poly b, const ring r_b)
1665{
1666  p_LmCheckPolyRing(a, r_a);
1667  p_LmCheckPolyRing(b, r_b);
1668  return _p_LmDivisibleBy(a, r_a, b, r_b);
1669}
1670static inline BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a,
1671                                    poly b, unsigned long not_sev_b, const ring r)
1672{
1673  p_LmCheckPolyRing1(a, r);
1674  p_LmCheckPolyRing1(b, r);
1675#ifndef PDIV_DEBUG
[8a8c9e]1676  _pPolyAssume2(p_GetShortExpVector(a, r) == sev_a, a, r);
1677  _pPolyAssume2(p_GetShortExpVector(b, r) == ~ not_sev_b, b, r);
[a04c5e]1678
1679  if (sev_a & not_sev_b)
1680  {
1681    pAssume1(p_LmDivisibleByNoComp(a, b, r) == FALSE);
1682    return FALSE;
1683  }
1684  return p_LmDivisibleBy(a, b, r);
1685#else
1686  return pDebugLmShortDivisibleBy(a, sev_a, r, b, not_sev_b, r);
1687#endif
1688}
1689
1690static inline BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a, const ring r_a,
1691                                      poly b, unsigned long not_sev_b, const ring r_b)
1692{
1693  p_LmCheckPolyRing1(a, r_a);
1694  p_LmCheckPolyRing1(b, r_b);
1695#ifndef PDIV_DEBUG
[8a8c9e]1696  _pPolyAssume2(p_GetShortExpVector(a, r_a) == sev_a, a, r_a);
1697  _pPolyAssume2(p_GetShortExpVector(b, r_b) == ~ not_sev_b, b, r_b);
[a04c5e]1698
1699  if (sev_a & not_sev_b)
1700  {
1701    pAssume1(_p_LmDivisibleByNoComp(a, r_a, b, r_b) == FALSE);
1702    return FALSE;
1703  }
1704  return _p_LmDivisibleBy(a, r_a, b, r_b);
1705#else
1706  return pDebugLmShortDivisibleBy(a, sev_a, r_a, b, not_sev_b, r_b);
1707#endif
1708}
1709
1710/***************************************************************
1711 *
1712 * Misc things on Lm
1713 *
1714 ***************************************************************/
1715// test if the monomial is a constant as a vector component
1716// i.e., test if all exponents are zero
1717static inline BOOLEAN p_LmIsConstantComp(const poly p, const ring r)
1718{
1719  //p_LmCheckPolyRing(p, r);
1720  int i = r->VarL_Size - 1;
1721
1722  do
1723  {
1724    if (p->exp[r->VarL_Offset[i]] != 0)
1725      return FALSE;
1726    i--;
1727  }
1728  while (i >= 0);
1729  return TRUE;
1730}
1731// test if monomial is a constant, i.e. if all exponents and the component
1732// is zero
1733static inline BOOLEAN p_LmIsConstant(const poly p, const ring r)
1734{
1735  if (p_LmIsConstantComp(p, r))
1736    return (p_GetComp(p, r) == 0);
1737  return FALSE;
1738}
1739
1740// like the respective p_LmIs* routines, except that p might be empty
1741static inline BOOLEAN p_IsConstantComp(const poly p, const ring r)
1742{
1743  if (p == NULL) return TRUE;
1744  return (pNext(p)==NULL) && p_LmIsConstantComp(p, r);
1745}
1746
1747static inline BOOLEAN p_IsConstant(const poly p, const ring r)
1748{
1749  if (p == NULL) return TRUE;
1750  return (pNext(p)==NULL) && p_LmIsConstant(p, r);
1751}
1752
1753static inline BOOLEAN p_IsUnit(const poly p, const ring r)
1754{
1755  if (p == NULL) return FALSE;
1756#ifdef HAVE_RINGS
1757  if (rField_is_Ring(r))
1758    return (p_LmIsConstant(p, r) && nIsUnit(pGetCoeff(p),r->cf));
1759#endif
1760  return p_LmIsConstant(p, r);
1761}
1762
1763static inline BOOLEAN p_LmExpVectorAddIsOk(const poly p1, const poly p2,
1764                                      const ring r)
1765{
1766  p_LmCheckPolyRing(p1, r);
1767  p_LmCheckPolyRing(p2, r);
1768  unsigned long l1, l2, divmask = r->divmask;
1769  int i;
1770
1771  for (i=0; i<r->VarL_Size; i++)
1772  {
1773    l1 = p1->exp[r->VarL_Offset[i]];
1774    l2 = p2->exp[r->VarL_Offset[i]];
1775    // do the divisiblity trick
1776    if ( (l1 > ULONG_MAX - l2) ||
1777         (((l1 & divmask) ^ (l2 & divmask)) != ((l1 + l2) & divmask)))
1778      return FALSE;
1779  }
1780  return TRUE;
1781}
[f34215]1782void      p_Split(poly p, poly * r);   /*p => IN(p), r => REST(p) */
1783BOOLEAN p_HasNotCF(poly p1, poly p2, const ring r);
1784poly      p_mInit(const char *s, BOOLEAN &ok, const ring r); /* monom s -> poly, interpreter */
1785const char *    p_Read(const char *s, poly &p,const ring r); /* monom -> poly */
[fb4075b]1786poly      p_Divide(poly a, poly b, const ring r);
1787poly      p_DivideM(poly a, poly b, const ring r);
[a7ee69]1788void      p_Lcm(poly a, poly b, poly m, const ring r);
[ac0bd6]1789poly      p_Diff(poly a, int k, const ring r);
[5162db]1790poly      p_DiffOp(poly a, poly b,BOOLEAN multiply, const ring r);
[bf183f]1791int       p_Weight(int c, const ring r);
1792
[cd246b]1793/* syszygy stuff */
1794BOOLEAN   p_VectorHasUnitB(poly p, int * k, const ring r);
1795void      p_VectorHasUnit(poly p, int * k, int * len, const ring r);
1796poly      p_TakeOutComp1(poly * p, int k, const ring r);
[74021a]1797// Splits *p into two polys: *q which consists of all monoms with
1798// component == comp and *p of all other monoms *lq == pLength(*q)
1799// On return all components pf *q == 0
1800void p_TakeOutComp(poly *p, long comp, poly *q, int *lq, const ring r);
1801
1802// This is something weird -- Don't use it, unless you know what you are doing
1803poly      p_TakeOutComp(poly * p, int k);
1804
1805void      p_DeleteComp(poly * p,int k, const ring r);
1806
[5c39a9]1807/*-------------ring management:----------------------*/
1808void p_SetGlobals(const ring r, BOOLEAN complete = TRUE);
1809
[949e57]1810// resets the pFDeg and pLDeg: if pLDeg is not given, it is
1811// set to currRing->pLDegOrig, i.e. to the respective LDegProc which
1812// only uses pFDeg (and not pDeg, or pTotalDegree, etc).
1813// If you use this, make sure your procs does not make any assumptions
1814// on ordering and/or OrdIndex -- otherwise they might return wrong results
1815// on strat->tailRing
[8a8c9e]1816void pSetDegProcs(ring r, pFDegProc new_FDeg, pLDegProc new_lDeg = NULL);
[949e57]1817// restores pFDeg and pLDeg:
[8a8c9e]1818void pRestoreDegProcs(ring r, pFDegProc old_FDeg, pLDegProc old_lDeg);
[949e57]1819
[5bc2461]1820/*-------------pComp for syzygies:-------------------*/
1821void p_SetModDeg(intvec *w, ring r);
[949e57]1822
[f550e86]1823/*------------ Jet ----------------------------------*/
1824poly pp_Jet(poly p, int m, const ring R);
1825poly p_Jet(poly p, int m,const ring R);
1826poly pp_JetW(poly p, int m, short *w, const ring R);
1827poly p_JetW(poly p, int m, short *w, const ring R);
[deca086]1828
1829
1830poly      p_PermPoly (poly p, int * perm,const ring OldRing, const ring dst,
1831                     nMapFunc nMap, int *par_perm=NULL, int OldPar=0);
1832
[35aab3]1833#endif // P_POLYS_H
1834
Note: See TracBrowser for help on using the repository browser.