source: git/libpolys/polys/monomials/p_polys.h @ 793bd8

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