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