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