source: git/libpolys/polys/monomials/p_polys.h @ 6e11aa9

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