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