source: git/libpolys/polys/monomials/p_polys.h @ 0ec309

spielwiese
Last change on this file since 0ec309 was 0ec309, checked in by Hans Schoenemann <hannes@…>, 7 years ago
add: singclap_pmult and use it in p_Mult_q
  • Property mode set to 100644
File size: 53.5 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  assume( r!= NULL );
847  r->p_Procs->p_Delete(p, r);
848}
849
850static inline void p_Delete(poly *p,  const ring lmRing, const ring tailRing)
851{
852  assume( p!= NULL );
853  if (*p != NULL)
854  {
855#ifndef PDEBUG
856    if (tailRing == lmRing)
857    {
858      p_Delete(p, tailRing);
859      return;
860    }
861#endif
862    if (pNext(*p) != NULL)
863      p_Delete(&pNext(*p), tailRing);
864    p_LmDelete(p, lmRing);
865  }
866}
867
868// copys monomials of p, allocates new monomials from bin,
869// deletes monomoals of p
870static inline poly p_ShallowCopyDelete(poly p, const ring r, omBin bin)
871{
872  p_LmCheckPolyRing2(p, r);
873  pAssume2(omSizeWOfBin(r->PolyBin) == omSizeWOfBin(bin));
874  return r->p_Procs->p_ShallowCopyDelete(p, r, bin);
875}
876
877// returns p+q, destroys p and q
878static inline poly p_Add_q(poly p, poly q, const ring r)
879{
880  assume( (p != q) || (p == NULL && q == NULL) );
881  int shorter;
882  return r->p_Procs->p_Add_q(p, q, shorter, r);
883}
884
885/// like p_Add_q, except that if lp == pLength(lp) lq == pLength(lq) then lp == pLength(p+q)
886static inline poly p_Add_q(poly p, poly q, int &lp, int lq, const ring r)
887{
888  assume( (p != q) || (p == NULL && q == NULL) );
889  int shorter;
890  poly res = r->p_Procs->p_Add_q(p, q, shorter, r);
891  lp = (lp + lq) - shorter;
892  return res;
893}
894
895// returns p*n, destroys p
896static inline poly p_Mult_nn(poly p, number n, const ring r)
897{
898  if (n_IsOne(n, r->cf))
899    return p;
900  else if (n_IsZero(n, r->cf))
901  {
902    r->p_Procs->p_Delete(&p, r); // NOTE: without p_Delete - memory leak!
903    return NULL;
904  } else
905    return r->p_Procs->p_Mult_nn(p, n, r);
906}
907
908static inline poly p_Mult_nn(poly p, number n, const ring lmRing,
909                        const ring tailRing)
910{
911#ifndef PDEBUG
912  if (lmRing == tailRing)
913    return p_Mult_nn(p, n, tailRing);
914#endif
915  poly pnext = pNext(p);
916  pNext(p) = NULL;
917  p = lmRing->p_Procs->p_Mult_nn(p, n, lmRing);
918  pNext(p) = tailRing->p_Procs->p_Mult_nn(pnext, n, tailRing);
919  return p;
920}
921
922// returns p*n, does not destroy p
923static inline poly pp_Mult_nn(poly p, number n, const ring r)
924{
925  if (n_IsOne(n, r->cf))
926    return p_Copy(p, r);
927  else
928    return r->p_Procs->pp_Mult_nn(p, n, r);
929}
930
931// test if the monomial is a constant as a vector component
932// i.e., test if all exponents are zero
933static inline BOOLEAN p_LmIsConstantComp(const poly p, const ring r)
934{
935  //p_LmCheckPolyRing(p, r);
936  int i = r->VarL_Size - 1;
937
938  do
939  {
940    if (p->exp[r->VarL_Offset[i]] != 0)
941      return FALSE;
942    i--;
943  }
944  while (i >= 0);
945  return TRUE;
946}
947
948// test if monomial is a constant, i.e. if all exponents and the component
949// is zero
950static inline BOOLEAN p_LmIsConstant(const poly p, const ring r)
951{
952  if (p_LmIsConstantComp(p, r))
953    return (p_GetComp(p, r) == 0);
954  return FALSE;
955}
956
957// returns Copy(p)*m, does neither destroy p nor m
958static inline poly pp_Mult_mm(poly p, poly m, const ring r)
959{
960  if (p_LmIsConstant(m, r))
961    return pp_Mult_nn(p, pGetCoeff(m), r);
962  else
963  {
964    return r->p_Procs->pp_Mult_mm(p, m, r);
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
977static inline poly p_Minus_mm_Mult_qq(poly p, const poly m, const poly q, int &lp, int lq,
978                                      const poly spNoether, const ring r)
979{
980  int shorter;
981  const poly res = r->p_Procs->p_Minus_mm_Mult_qq(p, m, q, shorter, spNoether, r);
982  lp += lq - shorter;
983//  assume( lp == pLength(res) );
984  return res;
985}
986
987// return p - m*Copy(q), destroys p; const: p,m
988static inline poly p_Minus_mm_Mult_qq(poly p, const poly m, const poly q, const ring r)
989{
990  int shorter;
991
992  return r->p_Procs->p_Minus_mm_Mult_qq(p, m, q, shorter, NULL, r);
993}
994
995
996// returns p*Coeff(m) for such monomials pm of p, for which m is divisble by pm
997static inline poly pp_Mult_Coeff_mm_DivSelect(poly p, const poly m, const ring r)
998{
999  int shorter;
1000  return r->p_Procs->pp_Mult_Coeff_mm_DivSelect(p, m, shorter, r);
1001}
1002
1003// returns p*Coeff(m) for such monomials pm of p, for which m is divisble by pm
1004// if lp is length of p on input then lp is length of returned poly on output
1005static inline poly pp_Mult_Coeff_mm_DivSelect(poly p, int &lp, const poly m, const ring r)
1006{
1007  int shorter;
1008  poly pp = r->p_Procs->pp_Mult_Coeff_mm_DivSelect(p, m, shorter, r);
1009  lp -= shorter;
1010  return pp;
1011}
1012
1013// returns -p, destroys p
1014static inline poly p_Neg(poly p, const ring r)
1015{
1016  return r->p_Procs->p_Neg(p, r);
1017}
1018
1019extern poly  _p_Mult_q(poly p, poly q, const int copy, const ring r);
1020// returns p*q, destroys p and q
1021static inline poly p_Mult_q(poly p, poly q, const ring r)
1022{
1023  assume( (p != q) || (p == NULL && q == NULL) );
1024
1025  if (p == NULL)
1026  {
1027    r->p_Procs->p_Delete(&q, r);
1028    return NULL;
1029  }
1030  if (q == NULL)
1031  {
1032    r->p_Procs->p_Delete(&p, r);
1033    return NULL;
1034  }
1035
1036  if (pNext(p) == NULL)
1037  {
1038#ifdef HAVE_PLURAL
1039    if (rIsPluralRing(r))
1040      q = nc_mm_Mult_p(p, q, r);
1041    else
1042#endif /* HAVE_PLURAL */
1043      q = r->p_Procs->p_Mult_mm(q, p, r);
1044
1045    r->p_Procs->p_Delete(&p, r);
1046    return q;
1047  }
1048
1049  if (pNext(q) == NULL)
1050  {
1051    p = r->p_Procs->p_Mult_mm(p, q, r);
1052    r->p_Procs->p_Delete(&q, r);
1053    return p;
1054  }
1055#ifdef HAVE_PLURAL
1056  if (rIsPluralRing(r))
1057    return _nc_p_Mult_q(p, q, r);
1058  else
1059#endif
1060  return _p_Mult_q(p, q, 0, r);
1061}
1062
1063// returns p*q, does neither destroy p nor q
1064static inline poly pp_Mult_qq(poly p, poly q, const ring r)
1065{
1066  if (p == NULL || q == NULL) return NULL;
1067
1068  if (pNext(p) == NULL)
1069  {
1070#ifdef HAVE_PLURAL
1071    if (rIsPluralRing(r))
1072      return nc_mm_Mult_pp(p, q, r);
1073#endif
1074    return r->p_Procs->pp_Mult_mm(q, p, r);
1075  }
1076
1077  if (pNext(q) == NULL)
1078  {
1079    return r->p_Procs->pp_Mult_mm(p, q, r);
1080  }
1081
1082  poly qq = q;
1083  if (p == q)
1084    qq = p_Copy(q, r);
1085
1086  poly res;
1087#ifdef HAVE_PLURAL
1088  if (rIsPluralRing(r))
1089    res = _nc_pp_Mult_qq(p, qq, r);
1090  else
1091#endif
1092    res = _p_Mult_q(p, qq, 1, r);
1093
1094  if (qq != q)
1095    p_Delete(&qq, r);
1096  return res;
1097}
1098
1099// returns p + m*q destroys p, const: q, m
1100static inline poly p_Plus_mm_Mult_qq(poly p, poly m, poly q, int &lp, int lq,
1101                                const ring r)
1102{
1103#ifdef HAVE_PLURAL
1104  if (rIsPluralRing(r))
1105    return nc_p_Plus_mm_Mult_qq(p, m, q, lp, lq, r);
1106#endif
1107
1108// this should be implemented more efficiently
1109  poly res;
1110  int shorter;
1111  number n_old = pGetCoeff(m);
1112  number n_neg = n_Copy(n_old, r->cf);
1113  n_neg = n_InpNeg(n_neg, r->cf);
1114  pSetCoeff0(m, n_neg);
1115  res = r->p_Procs->p_Minus_mm_Mult_qq(p, m, q, shorter, NULL, r);
1116  lp = (lp + lq) - shorter;
1117  pSetCoeff0(m, n_old);
1118  n_Delete(&n_neg, r->cf);
1119  return res;
1120}
1121
1122static inline poly p_Plus_mm_Mult_qq(poly p, poly m, poly q, const ring r)
1123{
1124  int lp = 0, lq = 0;
1125  return p_Plus_mm_Mult_qq(p, m, q, lp, lq, r);
1126}
1127
1128// returns merged p and q, assumes p and q have no monomials which are equal
1129static inline poly p_Merge_q(poly p, poly q, const ring r)
1130{
1131  assume( (p != q) || (p == NULL && q == NULL) );
1132  return r->p_Procs->p_Merge_q(p, q, r);
1133}
1134
1135// like p_SortMerge, except that p may have equal monimals
1136static inline poly p_SortAdd(poly p, const ring r, BOOLEAN revert= FALSE)
1137{
1138  if (revert) p = pReverse(p);
1139  return sBucketSortAdd(p, r);
1140}
1141
1142// sorts p using bucket sort: returns sorted poly
1143// assumes that monomials of p are all different
1144// reverses it first, if revert == TRUE, use this if input p is "almost" sorted
1145// correctly
1146static inline poly p_SortMerge(poly p, const ring r, BOOLEAN revert= FALSE)
1147{
1148  if (revert) p = pReverse(p);
1149  return sBucketSortMerge(p, r);
1150}
1151
1152/***************************************************************
1153 *
1154 * I/O
1155 *
1156 ***************************************************************/
1157static inline char*     p_String(poly p, ring p_ring)
1158{
1159  return p_String(p, p_ring, p_ring);
1160}
1161static inline void     p_String0(poly p, ring p_ring)
1162{
1163  p_String0(p, p_ring, p_ring);
1164}
1165static inline void      p_Write(poly p, ring p_ring)
1166{
1167  p_Write(p, p_ring, p_ring);
1168}
1169static inline void      p_Write0(poly p, ring p_ring)
1170{
1171  p_Write0(p, p_ring, p_ring);
1172}
1173static inline void      p_wrp(poly p, ring p_ring)
1174{
1175  p_wrp(p, p_ring, p_ring);
1176}
1177
1178
1179#if PDEBUG > 0
1180
1181#define _p_LmCmpAction(p, q, r, actionE, actionG, actionS)  \
1182do                                                          \
1183{                                                           \
1184  int _cmp = p_LmCmp(p,q,r);                                \
1185  if (_cmp == 0) actionE;                                   \
1186  if (_cmp == 1) actionG;                                   \
1187  actionS;                                                  \
1188}                                                           \
1189while(0)
1190
1191#else
1192
1193#define _p_LmCmpAction(p, q, r, actionE, actionG, actionS)                      \
1194 p_MemCmp_LengthGeneral_OrdGeneral(p->exp, q->exp, r->CmpL_Size, r->ordsgn,    \
1195                                   actionE, actionG, actionS)
1196
1197#endif
1198
1199#define pDivAssume(x)   do {} while (0)
1200
1201
1202
1203/***************************************************************
1204 *
1205 * Allocation/Initalization/Deletion
1206 *
1207 ***************************************************************/
1208// adjustments for negative weights
1209static inline void p_MemAdd_NegWeightAdjust(poly p, const ring r)
1210{
1211  if (r->NegWeightL_Offset != NULL)
1212  {
1213    for (int i=r->NegWeightL_Size-1; i>=0; i--)
1214    {
1215      p->exp[r->NegWeightL_Offset[i]] -= POLY_NEGWEIGHT_OFFSET;
1216    }
1217  }
1218}
1219static inline void p_MemSub_NegWeightAdjust(poly p, const ring r)
1220{
1221  if (r->NegWeightL_Offset != NULL)
1222  {
1223    for (int i=r->NegWeightL_Size-1; i>=0; i--)
1224    {
1225      p->exp[r->NegWeightL_Offset[i]] += POLY_NEGWEIGHT_OFFSET;
1226    }
1227  }
1228}
1229// ExpVextor(d_p) = ExpVector(s_p)
1230static inline void p_ExpVectorCopy(poly d_p, poly s_p, const ring r)
1231{
1232  p_LmCheckPolyRing1(d_p, r);
1233  p_LmCheckPolyRing1(s_p, r);
1234  memcpy(d_p->exp, s_p->exp, r->ExpL_Size*sizeof(long));
1235}
1236
1237static inline poly p_Init(const ring r, omBin bin)
1238{
1239  p_CheckRing1(r);
1240  pAssume1(bin != NULL && omSizeWOfBin(r->PolyBin) == omSizeWOfBin(bin));
1241  poly p;
1242  omTypeAlloc0Bin(poly, p, bin);
1243  p_MemAdd_NegWeightAdjust(p, r);
1244  p_SetRingOfLm(p, r);
1245  return p;
1246}
1247static inline poly p_Init(const ring r)
1248{
1249  return p_Init(r, r->PolyBin);
1250}
1251
1252static inline poly p_LmInit(poly p, const ring r)
1253{
1254  p_LmCheckPolyRing1(p, r);
1255  poly np;
1256  omTypeAllocBin(poly, np, r->PolyBin);
1257  p_SetRingOfLm(np, r);
1258  memcpy(np->exp, p->exp, r->ExpL_Size*sizeof(long));
1259  pNext(np) = NULL;
1260  pSetCoeff0(np, NULL);
1261  return np;
1262}
1263static inline poly p_LmInit(poly s_p, const ring s_r, const ring d_r, omBin d_bin)
1264{
1265  p_LmCheckPolyRing1(s_p, s_r);
1266  p_CheckRing(d_r);
1267  pAssume1(d_r->N <= s_r->N);
1268  poly d_p = p_Init(d_r, d_bin);
1269  for (unsigned i=d_r->N; i!=0; i--)
1270  {
1271    p_SetExp(d_p, i, p_GetExp(s_p, i,s_r), d_r);
1272  }
1273  if (rRing_has_Comp(d_r))
1274  {
1275    p_SetComp(d_p, p_GetComp(s_p,s_r), d_r);
1276  }
1277  p_Setm(d_p, d_r);
1278  return d_p;
1279}
1280static inline poly p_LmInit(poly s_p, const ring s_r, const ring d_r)
1281{
1282  pAssume1(d_r != NULL);
1283  return p_LmInit(s_p, s_r, d_r, d_r->PolyBin);
1284}
1285
1286// set all exponents l..k to 0, assume exp. k+1..n and 1..l-1 are in
1287// different blocks
1288// set coeff to 1
1289static inline poly p_GetExp_k_n(poly p, int l, int k, const ring r)
1290{
1291  if (p == NULL) return NULL;
1292  p_LmCheckPolyRing1(p, r);
1293  poly np;
1294  omTypeAllocBin(poly, np, r->PolyBin);
1295  p_SetRingOfLm(np, r);
1296  memcpy(np->exp, p->exp, r->ExpL_Size*sizeof(long));
1297  pNext(np) = NULL;
1298  pSetCoeff0(np, n_Init(1, r->cf));
1299  int i;
1300  for(i=l;i<=k;i++)
1301  {
1302    //np->exp[(r->VarOffset[i] & 0xffffff)] =0;
1303    p_SetExp(np,i,0,r);
1304  }
1305  p_Setm(np,r);
1306  return np;
1307}
1308
1309// simialar to p_ShallowCopyDelete but does it only for leading monomial
1310static inline poly p_LmShallowCopyDelete(poly p, const ring r)
1311{
1312  p_LmCheckPolyRing1(p, r);
1313  pAssume1(omSizeWOfBin(bin) == omSizeWOfBin(r->PolyBin));
1314  poly new_p = p_New(r);
1315  memcpy(new_p->exp, p->exp, r->ExpL_Size*sizeof(long));
1316  pSetCoeff0(new_p, pGetCoeff(p));
1317  pNext(new_p) = pNext(p);
1318  omFreeBinAddr(p);
1319  return new_p;
1320}
1321
1322/***************************************************************
1323 *
1324 * Operation on ExpVectors
1325 *
1326 ***************************************************************/
1327// ExpVector(p1) += ExpVector(p2)
1328static inline void p_ExpVectorAdd(poly p1, poly p2, const ring r)
1329{
1330  p_LmCheckPolyRing1(p1, r);
1331  p_LmCheckPolyRing1(p2, r);
1332#if PDEBUG >= 1
1333  for (int i=1; i<=r->N; i++)
1334    pAssume1((unsigned long) (p_GetExp(p1, i, r) + p_GetExp(p2, i, r)) <= r->bitmask);
1335  pAssume1(p_GetComp(p1, r) == 0 || p_GetComp(p2, r) == 0);
1336#endif
1337
1338  p_MemAdd_LengthGeneral(p1->exp, p2->exp, r->ExpL_Size);
1339  p_MemAdd_NegWeightAdjust(p1, r);
1340}
1341// ExpVector(pr) = ExpVector(p1) + ExpVector(p2)
1342static inline void p_ExpVectorSum(poly pr, poly p1, poly p2, const ring r)
1343{
1344  p_LmCheckPolyRing1(p1, r);
1345  p_LmCheckPolyRing1(p2, r);
1346  p_LmCheckPolyRing1(pr, r);
1347#if PDEBUG >= 1
1348  for (int i=1; i<=r->N; i++)
1349    pAssume1((unsigned long) (p_GetExp(p1, i, r) + p_GetExp(p2, i, r)) <= r->bitmask);
1350  pAssume1(p_GetComp(p1, r) == 0 || p_GetComp(p2, r) == 0);
1351#endif
1352
1353  p_MemSum_LengthGeneral(pr->exp, p1->exp, p2->exp, r->ExpL_Size);
1354  p_MemAdd_NegWeightAdjust(pr, r);
1355}
1356// ExpVector(p1) -= ExpVector(p2)
1357static inline void p_ExpVectorSub(poly p1, poly p2, const ring r)
1358{
1359  p_LmCheckPolyRing1(p1, r);
1360  p_LmCheckPolyRing1(p2, r);
1361#if PDEBUG >= 1
1362  for (int i=1; i<=r->N; i++)
1363    pAssume1(p_GetExp(p1, i, r) >= p_GetExp(p2, i, r));
1364  pAssume1(p_GetComp(p1, r) == 0 || p_GetComp(p2, r) == 0 ||
1365          p_GetComp(p1, r) == p_GetComp(p2, r));
1366#endif
1367
1368  p_MemSub_LengthGeneral(p1->exp, p2->exp, r->ExpL_Size);
1369  p_MemSub_NegWeightAdjust(p1, r);
1370}
1371
1372// ExpVector(p1) += ExpVector(p2) - ExpVector(p3)
1373static inline void p_ExpVectorAddSub(poly p1, poly p2, poly p3, const ring r)
1374{
1375  p_LmCheckPolyRing1(p1, r);
1376  p_LmCheckPolyRing1(p2, r);
1377  p_LmCheckPolyRing1(p3, r);
1378#if PDEBUG >= 1
1379  for (int i=1; i<=r->N; i++)
1380    pAssume1(p_GetExp(p1, i, r) + p_GetExp(p2, i, r) >= p_GetExp(p3, i, r));
1381  pAssume1(p_GetComp(p1, r) == 0 ||
1382           (p_GetComp(p2, r) - p_GetComp(p3, r) == 0) ||
1383           (p_GetComp(p1, r) == p_GetComp(p2, r) - p_GetComp(p3, r)));
1384#endif
1385
1386  p_MemAddSub_LengthGeneral(p1->exp, p2->exp, p3->exp, r->ExpL_Size);
1387  // no need to adjust in case of NegWeights
1388}
1389
1390// ExpVector(pr) = ExpVector(p1) - ExpVector(p2)
1391static inline void p_ExpVectorDiff(poly pr, poly p1, poly p2, const ring r)
1392{
1393  p_LmCheckPolyRing1(p1, r);
1394  p_LmCheckPolyRing1(p2, r);
1395  p_LmCheckPolyRing1(pr, r);
1396#if PDEBUG >= 2
1397  for (int i=1; i<=r->N; i++)
1398    pAssume1(p_GetExp(p1, i, r) >= p_GetExp(p2, i, r));
1399  pAssume1(!rRing_has_Comp(r) || p_GetComp(p1, r) == p_GetComp(p2, r));
1400#endif
1401
1402  p_MemDiff_LengthGeneral(pr->exp, p1->exp, p2->exp, r->ExpL_Size);
1403  p_MemSub_NegWeightAdjust(pr, r);
1404}
1405
1406static inline BOOLEAN p_ExpVectorEqual(poly p1, poly p2, const ring r)
1407{
1408  p_LmCheckPolyRing1(p1, r);
1409  p_LmCheckPolyRing1(p2, r);
1410
1411  unsigned i = r->ExpL_Size;
1412  unsigned long *ep = p1->exp;
1413  unsigned long *eq = p2->exp;
1414
1415  do
1416  {
1417    i--;
1418    if (ep[i] != eq[i]) return FALSE;
1419  }
1420  while (i!=0);
1421  return TRUE;
1422}
1423
1424static inline long p_Totaldegree(poly p, const ring r)
1425{
1426  p_LmCheckPolyRing1(p, r);
1427  unsigned long s = p_GetTotalDegree(p->exp[r->VarL_Offset[0]],
1428                                     r,
1429                                     r->ExpPerLong);
1430  for (unsigned i=r->VarL_Size-1; i!=0; i--)
1431  {
1432    s += p_GetTotalDegree(p->exp[r->VarL_Offset[i]], r,r->ExpPerLong);
1433  }
1434  return (long)s;
1435}
1436
1437static inline void p_GetExpV(poly p, int *ev, const ring r)
1438{
1439  p_LmCheckPolyRing1(p, r);
1440  for (unsigned j = r->N; j!=0; j--)
1441      ev[j] = p_GetExp(p, j, r);
1442
1443  ev[0] = p_GetComp(p, r);
1444}
1445static inline void p_SetExpV(poly p, int *ev, const ring r)
1446{
1447  p_LmCheckPolyRing1(p, r);
1448  for (unsigned j = r->N; j!=0; j--)
1449      p_SetExp(p, j, ev[j], r);
1450
1451  p_SetComp(p, ev[0],r);
1452  p_Setm(p, r);
1453}
1454
1455/***************************************************************
1456 *
1457 * Comparison w.r.t. monomial ordering
1458 *
1459 ***************************************************************/
1460
1461static inline int p_LmCmp(poly p, poly q, const ring r)
1462{
1463  p_LmCheckPolyRing1(p, r);
1464  p_LmCheckPolyRing1(q, r);
1465
1466  const unsigned long* _s1 = ((unsigned long*) p->exp);
1467  const unsigned long* _s2 = ((unsigned long*) q->exp);
1468  REGISTER unsigned long _v1;
1469  REGISTER unsigned long _v2;
1470  const unsigned long _l = r->CmpL_Size;
1471
1472  REGISTER unsigned long _i=0;
1473
1474  LengthGeneral_OrdGeneral_LoopTop:
1475  _v1 = _s1[_i];
1476  _v2 = _s2[_i];
1477  if (_v1 == _v2)
1478  {
1479    _i++;
1480    if (_i == _l) return 0;
1481    goto LengthGeneral_OrdGeneral_LoopTop;
1482  }
1483  const long* _ordsgn = (long*) r->ordsgn;
1484  if (_v1 > _v2)
1485  {
1486    if (_ordsgn[_i] == 1) return 1;
1487    return -1;
1488  }
1489  if (_ordsgn[_i] == 1) return -1;
1490  return 1;
1491
1492}
1493
1494// The coefficient will be compared in absolute value
1495static inline int p_LtCmp(poly p, poly q, const ring r)
1496{
1497  int res = p_LmCmp(p,q,r);
1498  if(res == 0)
1499  {
1500    if(p_GetCoeff(p,r) == NULL || p_GetCoeff(q,r) == NULL)
1501      return res;
1502    number pc = n_Copy(p_GetCoeff(p,r),r->cf);
1503    number qc = n_Copy(p_GetCoeff(q,r),r->cf);
1504    if(!n_GreaterZero(pc,r->cf))
1505      pc = n_InpNeg(pc,r->cf);
1506    if(!n_GreaterZero(qc,r->cf))
1507      qc = n_InpNeg(qc,r->cf);
1508    if(n_Greater(pc,qc,r->cf))
1509      res = 1;
1510    else if(n_Greater(qc,pc,r->cf))
1511      res = -1;
1512    else if(n_Equal(pc,qc,r->cf))
1513      res = 0;
1514    n_Delete(&pc,r->cf);
1515    n_Delete(&qc,r->cf);
1516  }
1517  return res;
1518}
1519
1520// The coefficient will be compared in absolute value
1521static inline int p_LtCmpNoAbs(poly p, poly q, const ring r)
1522{
1523  int res = p_LmCmp(p,q,r);
1524  if(res == 0)
1525  {
1526    if(p_GetCoeff(p,r) == NULL || p_GetCoeff(q,r) == NULL)
1527      return res;
1528    number pc = p_GetCoeff(p,r);
1529    number qc = p_GetCoeff(q,r);
1530    if(n_Greater(pc,qc,r->cf))
1531      res = 1;
1532    if(n_Greater(qc,pc,r->cf))
1533      res = -1;
1534    if(n_Equal(pc,qc,r->cf))
1535      res = 0;
1536  }
1537  return res;
1538}
1539
1540#ifdef HAVE_RINGS
1541// This is the equivalent of pLmCmp(p,q) != -currRing->OrdSgn for rings
1542// It is used in posInLRing and posInTRing
1543static inline int p_LtCmpOrdSgnDiffM(poly p, poly q, const ring r)
1544{
1545  if(r->OrdSgn == 1)
1546  {
1547    return(p_LtCmp(p,q,r) == 1);
1548  }
1549  else
1550  {
1551    return(p_LmCmp(p,q,r) == -1);
1552  }
1553}
1554#endif
1555
1556#ifdef HAVE_RINGS
1557// This is the equivalent of pLmCmp(p,q) != currRing->OrdSgn for rings
1558// It is used in posInLRing and posInTRing
1559static inline int p_LtCmpOrdSgnDiffP(poly p, poly q, const ring r)
1560{
1561  if(r->OrdSgn == 1)
1562  {
1563    return(p_LmCmp(p,q,r) == -1);
1564  }
1565  else
1566  {
1567    return(p_LtCmp(p,q,r) != -1);
1568  }
1569
1570}
1571#endif
1572
1573#ifdef HAVE_RINGS
1574// This is the equivalent of pLmCmp(p,q) == -currRing->OrdSgn for rings
1575// It is used in posInLRing and posInTRing
1576static inline int p_LtCmpOrdSgnEqM(poly p, poly q, const ring r)
1577{
1578  return(p_LtCmp(p,q,r) == -r->OrdSgn);
1579}
1580#endif
1581
1582#ifdef HAVE_RINGS
1583// This is the equivalent of pLmCmp(p,q) == currRing->OrdSgn for rings
1584// It is used in posInLRing and posInTRing
1585static inline int p_LtCmpOrdSgnEqP(poly p, poly q, const ring r)
1586{
1587  return(p_LtCmp(p,q,r) == r->OrdSgn);
1588}
1589#endif
1590
1591/// returns TRUE if p1 is a skalar multiple of p2
1592/// assume p1 != NULL and p2 != NULL
1593BOOLEAN p_ComparePolys(poly p1,poly p2, const ring r);
1594
1595
1596/***************************************************************
1597 *
1598 * Comparisons: they are all done without regarding coeffs
1599 *
1600 ***************************************************************/
1601#define p_LmCmpAction(p, q, r, actionE, actionG, actionS) \
1602  _p_LmCmpAction(p, q, r, actionE, actionG, actionS)
1603
1604// returns 1 if ExpVector(p)==ExpVector(q): does not compare numbers !!
1605#define p_LmEqual(p1, p2, r) p_ExpVectorEqual(p1, p2, r)
1606
1607// pCmp: args may be NULL
1608// returns: (p2==NULL ? 1 : (p1 == NULL ? -1 : p_LmCmp(p1, p2)))
1609static inline int p_Cmp(poly p1, poly p2, ring r)
1610{
1611  if (p2==NULL)
1612    return 1;
1613  if (p1==NULL)
1614    return -1;
1615  return p_LmCmp(p1,p2,r);
1616}
1617
1618
1619/***************************************************************
1620 *
1621 * divisibility
1622 *
1623 ***************************************************************/
1624/// return: FALSE, if there exists i, such that a->exp[i] > b->exp[i]
1625///         TRUE, otherwise
1626/// (1) Consider long vars, instead of single exponents
1627/// (2) Clearly, if la > lb, then FALSE
1628/// (3) Suppose la <= lb, and consider first bits of single exponents in l:
1629///     if TRUE, then value of these bits is la ^ lb
1630///     if FALSE, then la-lb causes an "overflow" into one of those bits, i.e.,
1631///               la ^ lb != la - lb
1632static inline BOOLEAN _p_LmDivisibleByNoComp(poly a, poly b, const ring r)
1633{
1634  int i=r->VarL_Size - 1;
1635  unsigned long divmask = r->divmask;
1636  unsigned long la, lb;
1637
1638  if (r->VarL_LowIndex >= 0)
1639  {
1640    i += r->VarL_LowIndex;
1641    do
1642    {
1643      la = a->exp[i];
1644      lb = b->exp[i];
1645      if ((la > lb) ||
1646          (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask)))
1647      {
1648        pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == FALSE);
1649        return FALSE;
1650      }
1651      i--;
1652    }
1653    while (i>=r->VarL_LowIndex);
1654  }
1655  else
1656  {
1657    do
1658    {
1659      la = a->exp[r->VarL_Offset[i]];
1660      lb = b->exp[r->VarL_Offset[i]];
1661      if ((la > lb) ||
1662          (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask)))
1663      {
1664        pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == FALSE);
1665        return FALSE;
1666      }
1667      i--;
1668    }
1669    while (i>=0);
1670  }
1671/*#ifdef HAVE_RINGS
1672  pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == n_DivBy(p_GetCoeff(b, r), p_GetCoeff(a, r), r->cf));
1673  return (!rField_is_Ring(r)) || n_DivBy(p_GetCoeff(b, r), p_GetCoeff(a, r), r->cf);
1674#else
1675*/
1676  pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == TRUE);
1677  return TRUE;
1678//#endif
1679}
1680
1681static inline BOOLEAN _p_LmDivisibleByNoComp(poly a, const ring r_a, poly b, const ring r_b)
1682{
1683  int i=r_a->N;
1684  pAssume1(r_a->N == r_b->N);
1685
1686  do
1687  {
1688    if (p_GetExp(a,i,r_a) > p_GetExp(b,i,r_b))
1689      return FALSE;
1690    i--;
1691  }
1692  while (i);
1693/*#ifdef HAVE_RINGS
1694  return n_DivBy(p_GetCoeff(b, r_b), p_GetCoeff(a, r_a), r_a->cf);
1695#else
1696*/
1697  return TRUE;
1698//#endif
1699}
1700
1701#ifdef HAVE_RATGRING
1702static inline BOOLEAN _p_LmDivisibleByNoCompPart(poly a, const ring r_a, poly b, const ring r_b,const int start, const int end)
1703{
1704  int i=end;
1705  pAssume1(r_a->N == r_b->N);
1706
1707  do
1708  {
1709    if (p_GetExp(a,i,r_a) > p_GetExp(b,i,r_b))
1710      return FALSE;
1711    i--;
1712  }
1713  while (i>=start);
1714/*#ifdef HAVE_RINGS
1715  return n_DivBy(p_GetCoeff(b, r_b), p_GetCoeff(a, r_a), r_a->cf);
1716#else
1717*/
1718  return TRUE;
1719//#endif
1720}
1721static inline BOOLEAN _p_LmDivisibleByPart(poly a, const ring r_a, poly b, const ring r_b,const int start, const int end)
1722{
1723  if (p_GetComp(a, r_a) == 0 || p_GetComp(a,r_a) == p_GetComp(b,r_b))
1724    return _p_LmDivisibleByNoCompPart(a, r_a, b, r_b,start,end);
1725  return FALSE;
1726}
1727static inline BOOLEAN p_LmDivisibleByPart(poly a, poly b, const ring r,const int start, const int end)
1728{
1729  p_LmCheckPolyRing1(b, r);
1730  pIfThen1(a != NULL, p_LmCheckPolyRing1(b, r));
1731  if (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r))
1732    return _p_LmDivisibleByNoCompPart(a, r, b, r,start, end);
1733  return FALSE;
1734}
1735#endif
1736static inline BOOLEAN _p_LmDivisibleBy(poly a, poly b, const ring r)
1737{
1738  if (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r))
1739    return _p_LmDivisibleByNoComp(a, b, r);
1740  return FALSE;
1741}
1742static inline BOOLEAN _p_LmDivisibleBy(poly a, const ring r_a, poly b, const ring r_b)
1743{
1744  if (p_GetComp(a, r_a) == 0 || p_GetComp(a,r_a) == p_GetComp(b,r_b))
1745    return _p_LmDivisibleByNoComp(a, r_a, b, r_b);
1746  return FALSE;
1747}
1748static inline BOOLEAN p_LmDivisibleByNoComp(poly a, poly b, const ring r)
1749{
1750  p_LmCheckPolyRing1(a, r);
1751  p_LmCheckPolyRing1(b, r);
1752  return _p_LmDivisibleByNoComp(a, b, r);
1753}
1754
1755static inline BOOLEAN p_LmDivisibleByNoComp(poly a, const ring ra, poly b, const ring rb)
1756{
1757  p_LmCheckPolyRing1(a, ra);
1758  p_LmCheckPolyRing1(b, rb);
1759  return _p_LmDivisibleByNoComp(a, ra, b, rb);
1760}
1761
1762static inline BOOLEAN p_LmDivisibleBy(poly a, poly b, const ring r)
1763{
1764  p_LmCheckPolyRing1(b, r);
1765  pIfThen1(a != NULL, p_LmCheckPolyRing1(b, r));
1766  if (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r))
1767    return _p_LmDivisibleByNoComp(a, b, r);
1768  return FALSE;
1769}
1770
1771static inline BOOLEAN p_DivisibleBy(poly a, poly b, const ring r)
1772{
1773  pIfThen1(b!=NULL, p_LmCheckPolyRing1(b, r));
1774  pIfThen1(a!=NULL, p_LmCheckPolyRing1(a, r));
1775
1776  if (a != NULL && (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r)))
1777      return _p_LmDivisibleByNoComp(a,b,r);
1778  return FALSE;
1779}
1780static inline BOOLEAN p_DivisibleBy(poly a, const ring r_a, poly b, const ring r_b)
1781{
1782  pIfThen1(b!=NULL, p_LmCheckPolyRing1(b, r_b));
1783  pIfThen1(a!=NULL, p_LmCheckPolyRing1(a, r_a));
1784  if (a != NULL) {
1785      return _p_LmDivisibleBy(a, r_a, b, r_b);
1786  }
1787  return FALSE;
1788}
1789static inline BOOLEAN p_LmDivisibleBy(poly a, const ring r_a, poly b, const ring r_b)
1790{
1791  p_LmCheckPolyRing(a, r_a);
1792  p_LmCheckPolyRing(b, r_b);
1793  return _p_LmDivisibleBy(a, r_a, b, r_b);
1794}
1795
1796static inline BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a,
1797                                    poly b, unsigned long not_sev_b, const ring r)
1798{
1799  p_LmCheckPolyRing1(a, r);
1800  p_LmCheckPolyRing1(b, r);
1801#ifndef PDIV_DEBUG
1802  _pPolyAssume2(p_GetShortExpVector(a, r) == sev_a, a, r);
1803  _pPolyAssume2(p_GetShortExpVector(b, r) == ~ not_sev_b, b, r);
1804
1805  if (sev_a & not_sev_b)
1806  {
1807    pAssume1(p_LmDivisibleByNoComp(a, b, r) == FALSE);
1808    return FALSE;
1809  }
1810  return p_LmDivisibleBy(a, b, r);
1811#else
1812  return pDebugLmShortDivisibleBy(a, sev_a, r, b, not_sev_b, r);
1813#endif
1814}
1815
1816static inline BOOLEAN p_LmShortDivisibleByNoComp(poly a, unsigned long sev_a,
1817                                           poly b, unsigned long not_sev_b, const ring r)
1818{
1819  p_LmCheckPolyRing1(a, r);
1820  p_LmCheckPolyRing1(b, r);
1821#ifndef PDIV_DEBUG
1822  _pPolyAssume2(p_GetShortExpVector(a, r) == sev_a, a, r);
1823  _pPolyAssume2(p_GetShortExpVector(b, r) == ~ not_sev_b, b, r);
1824
1825  if (sev_a & not_sev_b)
1826  {
1827    pAssume1(p_LmDivisibleByNoComp(a, b, r) == FALSE);
1828    return FALSE;
1829  }
1830  return p_LmDivisibleByNoComp(a, b, r);
1831#else
1832  return pDebugLmShortDivisibleByNoComp(a, sev_a, r, b, not_sev_b, r);
1833#endif
1834}
1835
1836static inline BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a, const ring r_a,
1837                                      poly b, unsigned long not_sev_b, const ring r_b)
1838{
1839  p_LmCheckPolyRing1(a, r_a);
1840  p_LmCheckPolyRing1(b, r_b);
1841#ifndef PDIV_DEBUG
1842  _pPolyAssume2(p_GetShortExpVector(a, r_a) == sev_a, a, r_a);
1843  _pPolyAssume2(p_GetShortExpVector(b, r_b) == ~ not_sev_b, b, r_b);
1844
1845  if (sev_a & not_sev_b)
1846  {
1847    pAssume1(_p_LmDivisibleByNoComp(a, r_a, b, r_b) == FALSE);
1848    return FALSE;
1849  }
1850  return _p_LmDivisibleBy(a, r_a, b, r_b);
1851#else
1852  return pDebugLmShortDivisibleBy(a, sev_a, r_a, b, not_sev_b, r_b);
1853#endif
1854}
1855
1856/***************************************************************
1857 *
1858 * Misc things on Lm
1859 *
1860 ***************************************************************/
1861
1862
1863// like the respective p_LmIs* routines, except that p might be empty
1864static inline BOOLEAN p_IsConstantComp(const poly p, const ring r)
1865{
1866  if (p == NULL) return TRUE;
1867  return (pNext(p)==NULL) && p_LmIsConstantComp(p, r);
1868}
1869
1870static inline BOOLEAN p_IsConstant(const poly p, const ring r)
1871{
1872  if (p == NULL) return TRUE;
1873  p_Test(p, r);
1874  return (pNext(p)==NULL) && p_LmIsConstant(p, r);
1875}
1876
1877/// either poly(1)  or gen(k)?!
1878static inline BOOLEAN p_IsOne(const poly p, const ring R)
1879{
1880  p_Test(p, R);
1881  return (p_IsConstant(p, R) && n_IsOne(p_GetCoeff(p, R), R->cf));
1882}
1883
1884static inline BOOLEAN p_IsConstantPoly(const poly p, const ring r)
1885{
1886  p_Test(p, r);
1887  poly pp=p;
1888  while(pp!=NULL)
1889  {
1890    if (! p_LmIsConstantComp(pp, r))
1891      return FALSE;
1892    pIter(pp);
1893  }
1894  return TRUE;
1895}
1896
1897static inline BOOLEAN p_IsUnit(const poly p, const ring r)
1898{
1899  if (p == NULL) return FALSE;
1900  if (rField_is_Ring(r))
1901    return (p_LmIsConstant(p, r) && n_IsUnit(pGetCoeff(p),r->cf));
1902  return p_LmIsConstant(p, r);
1903}
1904
1905static inline BOOLEAN p_LmExpVectorAddIsOk(const poly p1, const poly p2,
1906                                      const ring r)
1907{
1908  p_LmCheckPolyRing(p1, r);
1909  p_LmCheckPolyRing(p2, r);
1910  unsigned long l1, l2, divmask = r->divmask;
1911  int i;
1912
1913  for (i=0; i<r->VarL_Size; i++)
1914  {
1915    l1 = p1->exp[r->VarL_Offset[i]];
1916    l2 = p2->exp[r->VarL_Offset[i]];
1917    // do the divisiblity trick
1918    if ( (l1 > ULONG_MAX - l2) ||
1919         (((l1 & divmask) ^ (l2 & divmask)) != ((l1 + l2) & divmask)))
1920      return FALSE;
1921  }
1922  return TRUE;
1923}
1924void      p_Split(poly p, poly * r);   /*p => IN(p), r => REST(p) */
1925BOOLEAN p_HasNotCF(poly p1, poly p2, const ring r);
1926poly      p_mInit(const char *s, BOOLEAN &ok, const ring r); /* monom s -> poly, interpreter */
1927const char *    p_Read(const char *s, poly &p,const ring r); /* monom -> poly */
1928poly      p_Divide(poly a, poly b, const ring r);
1929poly      p_DivideM(poly a, poly b, const ring r);
1930poly      p_Div_nn(poly p, const number n, const ring r);
1931
1932// returns the LCM of the head terms of a and b in *m, does not p_Setm
1933void p_Lcm(const poly a, const poly b, poly m, const ring r);
1934// returns the LCM of the head terms of a and b, does p_Setm
1935poly p_Lcm(const poly a, const poly b, const ring r);
1936
1937#ifdef HAVE_RATGRING
1938poly p_LcmRat(const poly a, const poly b, const long lCompM, const ring r);
1939poly p_GetCoeffRat(poly p, int ishift, ring r);
1940void p_LmDeleteAndNextRat(poly *p, int ishift, ring r);
1941void p_ContentRat(poly &ph, const ring r);
1942#endif /* ifdef HAVE_RATGRING */
1943
1944
1945poly      p_Diff(poly a, int k, const ring r);
1946poly      p_DiffOp(poly a, poly b,BOOLEAN multiply, const ring r);
1947int       p_Weight(int c, const ring r);
1948
1949///   assumes that p and divisor are univariate polynomials in r,
1950///   mentioning the same variable;
1951///   assumes divisor != NULL;
1952///   p may be NULL;
1953///   assumes a global monomial ordering in r;
1954///   performs polynomial division of p by divisor:
1955///     - afterwards p contains the remainder of the division, i.e.,
1956///       p_before = result * divisor + p_afterwards;
1957///     - if needResult == TRUE, then the method computes and returns 'result',
1958///       otherwise NULL is returned (This parametrization can be used when
1959///       one is only interested in the remainder of the division. In this
1960///       case, the method will be slightly faster.)
1961///   leaves divisor unmodified
1962poly      p_PolyDiv(poly &p, const poly divisor, const BOOLEAN needResult, const ring r);
1963
1964/* syszygy stuff */
1965BOOLEAN   p_VectorHasUnitB(poly p, int * k, const ring r);
1966void      p_VectorHasUnit(poly p, int * k, int * len, const ring r);
1967poly      p_TakeOutComp1(poly * p, int k, const ring r);
1968// Splits *p into two polys: *q which consists of all monoms with
1969// component == comp and *p of all other monoms *lq == pLength(*q)
1970// On return all components pf *q == 0
1971void p_TakeOutComp(poly *p, long comp, poly *q, int *lq, const ring r);
1972
1973// This is something weird -- Don't use it, unless you know what you are doing
1974poly      p_TakeOutComp(poly * p, int k, const ring r);
1975
1976void      p_DeleteComp(poly * p,int k, const ring r);
1977
1978/*-------------ring management:----------------------*/
1979
1980// resets the pFDeg and pLDeg: if pLDeg is not given, it is
1981// set to currRing->pLDegOrig, i.e. to the respective LDegProc which
1982// only uses pFDeg (and not pDeg, or pTotalDegree, etc).
1983// If you use this, make sure your procs does not make any assumptions
1984// on ordering and/or OrdIndex -- otherwise they might return wrong results
1985// on strat->tailRing
1986void pSetDegProcs(ring r, pFDegProc new_FDeg, pLDegProc new_lDeg = NULL);
1987// restores pFDeg and pLDeg:
1988void pRestoreDegProcs(ring r, pFDegProc old_FDeg, pLDegProc old_lDeg);
1989
1990/*-------------pComp for syzygies:-------------------*/
1991void p_SetModDeg(intvec *w, ring r);
1992
1993/*------------ Jet ----------------------------------*/
1994poly pp_Jet(poly p, int m, const ring R);
1995poly p_Jet(poly p, int m,const ring R);
1996poly pp_JetW(poly p, int m, short *w, const ring R);
1997poly p_JetW(poly p, int m, short *w, const ring R);
1998
1999poly n_PermNumber(const number z, const int *par_perm, const int OldPar, const ring src, const ring dst);
2000
2001poly p_PermPoly (poly p, const int * perm,const ring OldRing, const ring dst,
2002                     nMapFunc nMap, const int *par_perm=NULL, int OldPar=0,
2003                     BOOLEAN use_mult=FALSE);
2004
2005/*----------------------------------------------------*/
2006poly p_Series(int n,poly p,poly u, intvec *w, const ring R);
2007
2008/*----------------------------------------------------*/
2009int   p_Var(poly mi, const ring r);
2010/// the minimal index of used variables - 1
2011int   p_LowVar (poly p, const ring r);
2012
2013/*----------------------------------------------------*/
2014/// shifts components of the vector p by i
2015void p_Shift (poly * p,int i, const ring r);
2016/*----------------------------------------------------*/
2017
2018int p_Compare(const poly a, const poly b, const ring R);
2019
2020/// polynomial gcd for f=mon
2021poly p_GcdMon(poly f, poly g, const ring r);
2022
2023/// divide polynomial by monomial
2024poly p_Div_mm(poly p, const poly m, const ring r);
2025#endif // P_POLYS_H
2026
Note: See TracBrowser for help on using the repository browser.