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