My Project
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);
52
53/// p_GetShortExpVector of p * pp
54unsigned long p_GetShortExpVector(const poly p, const poly pp, const ring r);
55
56#ifdef HAVE_RINGS
57/*! divisibility check over ground ring (which may contain zero divisors);
58 TRUE iff LT(f) divides LT(g), i.e., LT(f)*c*m = LT(g), for some
59 coefficient c and some monomial m;
60 does not take components into account
61 */
62BOOLEAN p_DivisibleByRingCase(poly f, poly g, const ring r);
63#endif
64
65/***************************************************************
66 *
67 * Misc things on polys
68 *
69 ***************************************************************/
70
71poly p_One(const ring r);
72
73int p_MinDeg(poly p,intvec *w, const ring R);
74
75long p_DegW(poly p, const int *w, const ring R);
76
77/// return TRUE if all monoms have the same component
78BOOLEAN p_OneComp(poly p, const ring r);
79
80/// return i, if head depends only on var(i)
81int p_IsPurePower(const poly p, const ring r);
82
83/// return i, if poly depends only on var(i)
84int p_IsUnivariate(poly p, const ring r);
85
86/// set entry e[i] to 1 if var(i) occurs in p, ignore var(j) if e[j]>0
87/// return #(e[i]>0)
88int p_GetVariables(poly p, int * e, const ring r);
89
90/// returns the poly representing the integer i
91poly p_ISet(long i, const ring r);
92
93/// returns the poly representing the number n, destroys n
94poly p_NSet(number n, const ring r);
95
96void p_Vec2Polys(poly v, poly**p, int *len, const ring r);
97poly p_Vec2Poly(poly v, int k, const ring r);
98
99/// julia: vector to already allocated array (len=p_MaxComp(v,r))
100void p_Vec2Array(poly v, poly *p, int len, const ring r);
101
102/***************************************************************
103 *
104 * Copying/Deletion of polys: args may be NULL
105 *
106 ***************************************************************/
107
108// simply deletes monomials, does not free coeffs
109void p_ShallowDelete(poly *p, const ring r);
110
111
112
113/***************************************************************
114 *
115 * Copying/Deleteion of polys: args may be NULL
116 * - p/q as arg mean a poly
117 * - m a monomial
118 * - n a number
119 * - pp (resp. qq, mm, nn) means arg is constant
120 * - p (resp, q, m, n) means arg is destroyed
121 *
122 ***************************************************************/
123
124poly p_Sub(poly a, poly b, const ring r);
125
126poly p_Power(poly p, int i, const ring r);
127
128
129/***************************************************************
130 *
131 * PDEBUG stuff
132 *
133 ***************************************************************/
134#ifdef PDEBUG
135// Returns TRUE if m is monom of p, FALSE otherwise
136BOOLEAN pIsMonomOf(poly p, poly m);
137// Returns TRUE if p and q have common monoms
138BOOLEAN pHaveCommonMonoms(poly p, poly q);
139
140// p_Check* routines return TRUE if everything is ok,
141// else, they report error message and return false
142
143// check if Lm(p) is from ring r
144BOOLEAN p_LmCheckIsFromRing(poly p, ring r);
145// check if Lm(p) != NULL, r != NULL and initialized && Lm(p) is from r
146BOOLEAN p_LmCheckPolyRing(poly p, ring r);
147// check if all monoms of p are from ring r
148BOOLEAN p_CheckIsFromRing(poly p, ring r);
149// check r != NULL and initialized && all monoms of p are from r
150BOOLEAN p_CheckPolyRing(poly p, ring r);
151// check if r != NULL and initialized
152BOOLEAN p_CheckRing(ring r);
153// only do check if cond
154
155
156#define pIfThen(cond, check) do {if (cond) {check;}} while (0)
157
158BOOLEAN _p_Test(poly p, ring r, int level);
159BOOLEAN _p_LmTest(poly p, ring r, int level);
160BOOLEAN _pp_Test(poly p, ring lmRing, ring tailRing, int level);
161
162#define p_Test(p,r) _p_Test(p, r, PDEBUG)
163#define p_LmTest(p,r) _p_LmTest(p, r, PDEBUG)
164#define pp_Test(p, lmRing, tailRing) _pp_Test(p, lmRing, tailRing, PDEBUG)
165
166#else // ! PDEBUG
167
168#define pIsMonomOf(p, q) (TRUE)
169#define pHaveCommonMonoms(p, q) (TRUE)
170#define p_LmCheckIsFromRing(p,r) (TRUE)
171#define p_LmCheckPolyRing(p,r) (TRUE)
172#define p_CheckIsFromRing(p,r) (TRUE)
173#define p_CheckPolyRing(p,r) (TRUE)
174#define p_CheckRing(r) (TRUE)
175#define P_CheckIf(cond, check) (TRUE)
176
177#define p_Test(p,r) (TRUE)
178#define p_LmTest(p,r) (TRUE)
179#define pp_Test(p, lmRing, tailRing) (TRUE)
180
181#endif
182
183/***************************************************************
184 *
185 * Misc stuff
186 *
187 ***************************************************************/
188/*2
189* returns the length of a polynomial (numbers of monomials)
190*/
191static inline unsigned pLength(poly a)
192{
193 unsigned l = 0;
194 while (a!=NULL)
195 {
196 pIter(a);
197 l++;
198 }
199 return l;
200}
201
202// returns the length of a polynomial (numbers of monomials) and the last mon.
203// respect syzComp
204poly p_Last(const poly a, int &l, const ring r);
205
206/*----------------------------------------------------*/
207
208void p_Norm(poly p1, const ring r);
209void p_Normalize(poly p,const ring r);
210void p_ProjectiveUnique(poly p,const ring r);
211
212void p_ContentForGB(poly p, const ring r);
213void p_Content(poly p, const ring r);
214void p_Content_n(poly p, number &c,const ring r);
215#if 1
216// currently only used by Singular/janet
217void p_SimpleContent(poly p, int s, const ring r);
218number p_InitContent(poly ph, const ring r);
219#endif
220
221poly p_Cleardenom(poly p, const ring r);
222void p_Cleardenom_n(poly p, const ring r,number &c);
223//number p_GetAllDenom(poly ph, const ring r);// unused
224
225int p_Size( poly p, const ring r );
226
227// homogenizes p by multiplying certain powers of the varnum-th variable
228poly p_Homogen (poly p, int varnum, const ring r);
229
230BOOLEAN p_IsHomogeneous (poly p, const ring r);
231
232// Setm
233static inline void p_Setm(poly p, const ring r)
234{
235 p_CheckRing2(r);
236 r->p_Setm(p, r);
237}
238
239p_SetmProc p_GetSetmProc(const ring r);
240
241poly p_Subst(poly p, int n, poly e, const ring r);
242
243// TODO:
244#define p_SetmComp p_Setm
245
246// component
247static inline unsigned long p_SetComp(poly p, unsigned long c, ring r)
248{
250 if (r->pCompIndex>=0) __p_GetComp(p,r) = c;
251 return c;
252}
253// sets component of poly a to i
254static 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
281static 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)
292static 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 {
302 pIter(p);
303 if(p==NULL) break;
304 i = p_GetComp(p, tailRing);
305 if (i>result) result = i;
306 }
307 }
308 return result;
309}
310
311static inline long p_MaxComp(poly p,ring lmRing) {return p_MaxComp(p,lmRing,lmRing);}
312
313static 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 {
323 pIter(p);
324 if(p==NULL) break;
325 i = p_GetComp(p,tailRing);
326 if (i<result) result = i;
327 }
328 }
329 return result;
330}
331
332static inline long p_MinComp(poly p,ring lmRing) {return p_MinComp(p,lmRing,lmRing);}
333
334
335static 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}
352void 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
361void p_String0(poly p, ring lmRing, ring tailRing);
362char* p_String(poly p, ring lmRing, ring tailRing);
363void p_Write(poly p, ring lmRing, ring tailRing);
364void p_Write0(poly p, ring lmRing, ring tailRing);
365void p_wrp(poly p, ring lmRing, ring tailRing);
366
367/// print p in a short way, if possible
368void p_String0Short(const poly p, ring lmRing, ring tailRing);
369
370/// print p in a long way
371void 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
380static inline long p_FDeg(const poly p, const ring r) { return r->pFDeg(p,r); }
381static inline long p_LDeg(const poly p, int *l, const ring r) { return r->pLDeg(p,l,r); }
382
383long p_WFirstTotalDegree(poly p, ring r);
384long p_WTotaldegree(poly p, const ring r);
385long p_WDegree(poly p,const ring r);
386long pLDeg0(poly p,int *l, ring r);
387long pLDeg0c(poly p,int *l, ring r);
388long pLDegb(poly p,int *l, ring r);
389long pLDeg1(poly p,int *l, ring r);
390long pLDeg1c(poly p,int *l, ring r);
391long pLDeg1_Deg(poly p,int *l, ring r);
392long pLDeg1c_Deg(poly p,int *l, ring r);
393long pLDeg1_Totaldegree(poly p,int *l, ring r);
394long pLDeg1c_Totaldegree(poly p,int *l, ring r);
395long pLDeg1_WFirstTotalDegree(poly p,int *l, ring r);
396long pLDeg1c_WFirstTotalDegree(poly p,int *l, ring r);
397
398BOOLEAN p_EqualPolys(poly p1, poly p2, const ring r);
399
400/// same as the usual p_EqualPolys for polys belonging to *equal* rings
401BOOLEAN p_EqualPolys(poly p1, poly p2, const ring r1, const ring r2);
402
403long p_Deg(poly a, const ring r);
404
405
406/***************************************************************
407 *
408 * Primitives for accessing and setting fields of a poly
409 *
410 ***************************************************************/
411
412static inline number p_SetCoeff(poly p, number n, ring r)
413{
415 n_Delete(&(p->coef), r->cf);
416 (p)->coef=n;
417 return n;
418}
419
420// order
421static inline long p_GetOrder(poly p, ring r)
422{
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
447static inline unsigned long p_AddComp(poly p, unsigned long v, ring r)
448{
451 return __p_GetComp(p,r) += v;
452}
453static inline unsigned long p_SubComp(poly p, unsigned long v, ring r)
454{
457 _pPolyAssume2(__p_GetComp(p,r) >= v,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!
469static 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
488static 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
509static 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
521static 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
533static 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
555static inline long p_GetExp(const poly p, const ring r, const int VarOffset)
556{
558 pAssume2(VarOffset != -1);
559 return p_GetExp(p, r->bitmask, VarOffset);
560}
561
562static inline long p_SetExp(poly p, const long e, const ring r, const int VarOffset)
563{
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
572static inline long p_GetExp(const poly p, const int v, const ring r)
573{
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
582static inline long p_SetExp(poly p, const int v, const long e, const ring r)
583{
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
591static inline long p_IncrExp(poly p, int v, ring r)
592{
594 int e = p_GetExp(p,v,r);
595 e++;
596 return p_SetExp(p,v,e,r);
597}
598static inline long p_DecrExp(poly p, int v, ring r)
599{
601 int e = p_GetExp(p,v,r);
602 pAssume2(e > 0);
603 e--;
604 return p_SetExp(p,v,e,r);
605}
606static inline long p_AddExp(poly p, int v, long ee, ring r)
607{
609 int e = p_GetExp(p,v,r);
610 e += ee;
611 return p_SetExp(p,v,e,r);
612}
613static inline long p_SubExp(poly p, int v, long ee, ring r)
614{
616 long e = p_GetExp(p,v,r);
617 pAssume2(e >= ee);
618 e -= ee;
619 return p_SetExp(p,v,e,r);
620}
621static 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
629static 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}
635static 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
640static 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);
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)
662static inline poly p_New(const ring r, omBin bin)
663#else
664static 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
675static inline poly p_New(ring r)
676{
677 return p_New(r, r->PolyBin);
678}
679
680#if (PDEBUG > 2) || defined(XALLOC_BIN)
681static inline void p_LmFree(poly p, ring r)
682#else
683static inline void p_LmFree(poly p, ring)
684#endif
685{
687 #ifdef XALLOC_BIN
688 omFreeBin(p,r->PolyBin);
689 #else
691 #endif
692}
693#if (PDEBUG > 2) || defined(XALLOC_BIN)
694static inline void p_LmFree(poly *p, ring r)
695#else
696static inline void p_LmFree(poly *p, ring)
697#endif
698{
700 poly h = *p;
701 *p = pNext(h);
702 #ifdef XALLOC_BIN
703 omFreeBin(h,r->PolyBin);
704 #else
706 #endif
707}
708#if (PDEBUG > 2) || defined(XALLOC_BIN)
709static inline poly p_LmFreeAndNext(poly p, ring r)
710#else
711static inline poly p_LmFreeAndNext(poly p, ring)
712#endif
713{
715 poly pnext = pNext(p);
716 #ifdef XALLOC_BIN
717 omFreeBin(p,r->PolyBin);
718 #else
720 #endif
721 return pnext;
722}
723static inline void p_LmDelete(poly p, const ring r)
724{
726 n_Delete(&pGetCoeff(p), r->cf);
727 #ifdef XALLOC_BIN
728 omFreeBin(p,r->PolyBin);
729 #else
731 #endif
732}
733static inline void p_LmDelete0(poly p, const ring r)
734{
736 if (pGetCoeff(p)!=NULL) n_Delete(&pGetCoeff(p), r->cf);
737 #ifdef XALLOC_BIN
738 omFreeBin(p,r->PolyBin);
739 #else
741 #endif
742}
743static inline void p_LmDelete(poly *p, const ring r)
744{
746 poly h = *p;
747 *p = pNext(h);
748 n_Delete(&pGetCoeff(h), r->cf);
749 #ifdef XALLOC_BIN
750 omFreeBin(h,r->PolyBin);
751 #else
753 #endif
754}
755static inline poly p_LmDeleteAndNext(poly p, const ring r)
756{
758 poly pnext = pNext(p);
759 n_Delete(&pGetCoeff(p), r->cf);
760 #ifdef XALLOC_BIN
761 omFreeBin(p,r->PolyBin);
762 #else
764 #endif
765 return pnext;
766}
767
768/***************************************************************
769 *
770 * Misc routines
771 *
772 ***************************************************************/
773
774/// return the maximal exponent of p in form of the maximal long var
775unsigned long p_GetMaxExpL(poly p, const ring r, unsigned long l_max = 0);
776
777/// return monomial r such that GetExp(r,i) is maximum of all
778/// monomials in p; coeff == 0, next == NULL, ord is not set
779poly p_GetMaxExpP(poly p, ring r);
780
781static inline unsigned long p_GetMaxExp(const unsigned long l, const ring r)
782{
783 unsigned long bitmask = r->bitmask;
784 unsigned long max = (l & bitmask);
785 unsigned long j = r->ExpPerLong - 1;
786
787 if (j > 0)
788 {
789 unsigned long i = r->BitsPerExp;
790 long e;
791 loop
792 {
793 e = ((l >> i) & bitmask);
794 if ((unsigned long) e > max)
795 max = e;
796 j--;
797 if (j==0) break;
798 i += r->BitsPerExp;
799 }
800 }
801 return max;
802}
803
804static inline unsigned long p_GetMaxExp(const poly p, const ring r)
805{
806 return p_GetMaxExp(p_GetMaxExpL(p, r), r);
807}
808
809static inline unsigned long
810p_GetTotalDegree(const unsigned long l, const ring r, const int number_of_exps)
811{
812 const unsigned long bitmask = r->bitmask;
813 unsigned long sum = (l & bitmask);
814 unsigned long j = number_of_exps - 1;
815
816 if (j > 0)
817 {
818 unsigned long i = r->BitsPerExp;
819 loop
820 {
821 sum += ((l >> i) & bitmask);
822 j--;
823 if (j==0) break;
824 i += r->BitsPerExp;
825 }
826 }
827 return sum;
828}
829
830/***************************************************************
831 *
832 * Dispatcher to r->p_Procs, they do the tests/checks
833 *
834 ***************************************************************/
835/// returns a copy of p (without any additional testing)
836static inline poly p_Copy_noCheck(poly p, const ring r)
837{
838 /*assume(p!=NULL);*/
839 assume(r != NULL);
840 assume(r->p_Procs != NULL);
841 assume(r->p_Procs->p_Copy != NULL);
842 return r->p_Procs->p_Copy(p, r);
843}
844
845/// returns a copy of p
846static inline poly p_Copy(poly p, const ring r)
847{
848 if (p!=NULL)
849 {
850 p_Test(p,r);
851 const poly pp = p_Copy_noCheck(p, r);
852 p_Test(pp,r);
853 return pp;
854 }
855 else
856 return NULL;
857}
858
859/// copy the (leading) term of p
860static inline poly p_Head(const poly p, const ring r)
861{
862 if (p == NULL) return NULL;
864 poly np;
865 omTypeAllocBin(poly, np, r->PolyBin);
866 p_SetRingOfLm(np, r);
867 memcpy(np->exp, p->exp, r->ExpL_Size*sizeof(long));
868 pNext(np) = NULL;
869 pSetCoeff0(np, n_Copy(pGetCoeff(p), r->cf));
870 return np;
871}
872
873/// like p_Head, but allow NULL coeff
874poly p_Head0(const poly p, const ring r);
875
876/// like p_Head, but with coefficient 1
877poly p_CopyPowerProduct(const poly p, const ring r);
878
879/// like p_Head, but with coefficient n
880poly p_CopyPowerProduct0(const poly p, const number n, const ring r);
881
882/// returns a copy of p with Lm(p) from lmRing and Tail(p) from tailRing
883static inline poly p_Copy(poly p, const ring lmRing, const ring tailRing)
884{
885 if (p != NULL)
886 {
887#ifndef PDEBUG
888 if (tailRing == lmRing)
889 return p_Copy_noCheck(p, tailRing);
890#endif
891 poly pres = p_Head(p, lmRing);
892 if (pNext(p)!=NULL)
893 pNext(pres) = p_Copy_noCheck(pNext(p), tailRing);
894 return pres;
895 }
896 else
897 return NULL;
898}
899
900// deletes *p, and sets *p to NULL
901static inline void p_Delete(poly *p, const ring r)
902{
903 assume( p!= NULL );
904 assume( r!= NULL );
905 if ((*p)!=NULL) r->p_Procs->p_Delete(p, r);
906}
907
908static inline void p_Delete(poly *p, const ring lmRing, const ring tailRing)
909{
910 assume( p!= NULL );
911 if (*p != NULL)
912 {
913#ifndef PDEBUG
914 if (tailRing == lmRing)
915 {
916 p_Delete(p, tailRing);
917 return;
918 }
919#endif
920 if (pNext(*p) != NULL)
921 p_Delete(&pNext(*p), tailRing);
922 p_LmDelete(p, lmRing);
923 }
924}
925
926// copys monomials of p, allocates new monomials from bin,
927// deletes monomials of p
928static inline poly p_ShallowCopyDelete(poly p, const ring r, omBin bin)
929{
931 pAssume2(omSizeWOfBin(r->PolyBin) == omSizeWOfBin(bin));
932 return r->p_Procs->p_ShallowCopyDelete(p, r, bin);
933}
934
935// returns p+q, destroys p and q
936static inline poly p_Add_q(poly p, poly q, const ring r)
937{
938 assume( (p != q) || (p == NULL && q == NULL) );
939 if (q==NULL) return p;
940 if (p==NULL) return q;
941 int shorter;
942 return r->p_Procs->p_Add_q(p, q, shorter, r);
943}
944
945/// like p_Add_q, except that if lp == pLength(lp) lq == pLength(lq) then lp == pLength(p+q)
946static inline poly p_Add_q(poly p, poly q, int &lp, int lq, const ring r)
947{
948 assume( (p != q) || (p == NULL && q == NULL) );
949 if (q==NULL) return p;
950 if (p==NULL) { lp=lq; return q; }
951 int shorter;
952 poly res = r->p_Procs->p_Add_q(p, q, shorter, r);
953 lp += lq - shorter;
954 return res;
955}
956
957// returns p*n, destroys p
958static inline poly p_Mult_nn(poly p, number n, const ring r)
959{
960 if (p==NULL) return NULL;
961 if (n_IsOne(n, r->cf))
962 return p;
963 else if (n_IsZero(n, r->cf))
964 {
965 p_Delete(&p, r); // NOTE: without p_Delete - memory leak!
966 return NULL;
967 }
968 else
969 return r->p_Procs->p_Mult_nn(p, n, r);
970}
971#define __p_Mult_nn(p,n,r) r->p_Procs->p_Mult_nn(p, n, r)
972
973static inline poly p_Mult_nn(poly p, number n, const ring lmRing,
974 const ring tailRing)
975{
976 assume(p!=NULL);
977#ifndef PDEBUG
978 if (lmRing == tailRing)
979 return p_Mult_nn(p, n, tailRing);
980#endif
981 poly pnext = pNext(p);
982 pNext(p) = NULL;
983 p = lmRing->p_Procs->p_Mult_nn(p, n, lmRing);
984 if (pnext!=NULL)
985 {
986 pNext(p) = tailRing->p_Procs->p_Mult_nn(pnext, n, tailRing);
987 }
988 return p;
989}
990
991// returns p*n, does not destroy p
992static inline poly pp_Mult_nn(poly p, number n, const ring r)
993{
994 if (p==NULL) return NULL;
995 if (n_IsOne(n, r->cf))
996 return p_Copy(p, r);
997 else if (n_IsZero(n, r->cf))
998 return NULL;
999 else
1000 return r->p_Procs->pp_Mult_nn(p, n, r);
1001}
1002#define __pp_Mult_nn(p,n,r) r->p_Procs->pp_Mult_nn(p, n, r)
1003
1004// test if the monomial is a constant as a vector component
1005// i.e., test if all exponents are zero
1006static inline BOOLEAN p_LmIsConstantComp(const poly p, const ring r)
1007{
1008 //p_LmCheckPolyRing(p, r);
1009 int i = r->VarL_Size - 1;
1010
1011 do
1012 {
1013 if (p->exp[r->VarL_Offset[i]] != 0)
1014 return FALSE;
1015 i--;
1016 }
1017 while (i >= 0);
1018 return TRUE;
1019}
1020
1021// test if monomial is a constant, i.e. if all exponents and the component
1022// is zero
1023static inline BOOLEAN p_LmIsConstant(const poly p, const ring r)
1024{
1025 if (p_LmIsConstantComp(p, r))
1026 return (p_GetComp(p, r) == 0);
1027 return FALSE;
1028}
1029
1030// returns Copy(p)*m, does neither destroy p nor m
1031static inline poly pp_Mult_mm(poly p, poly m, const ring r)
1032{
1033 if (p==NULL) return NULL;
1034 if (p_LmIsConstant(m, r))
1035 return __pp_Mult_nn(p, pGetCoeff(m), r);
1036 else
1037 return r->p_Procs->pp_Mult_mm(p, m, r);
1038}
1039
1040// returns m*Copy(p), does neither destroy p nor m
1041static inline poly pp_mm_Mult(poly p, poly m, const ring r)
1042{
1043 if (p==NULL) return NULL;
1044 if (p_LmIsConstant(m, r))
1045 return __pp_Mult_nn(p, pGetCoeff(m), r);
1046 else
1047 return r->p_Procs->pp_mm_Mult(p, m, r);
1048}
1049
1050// returns p*m, destroys p, const: m
1051static inline poly p_Mult_mm(poly p, poly m, const ring r)
1052{
1053 if (p==NULL) return NULL;
1054 if (p_LmIsConstant(m, r))
1055 return __p_Mult_nn(p, pGetCoeff(m), r);
1056 else
1057 return r->p_Procs->p_Mult_mm(p, m, r);
1058}
1059
1060// returns m*p, destroys p, const: m
1061static inline poly p_mm_Mult(poly p, poly m, const ring r)
1062{
1063 if (p==NULL) return NULL;
1064 if (p_LmIsConstant(m, r))
1065 return __p_Mult_nn(p, pGetCoeff(m), r);
1066 else
1067 return r->p_Procs->p_mm_Mult(p, m, r);
1068}
1069
1070static inline poly p_Minus_mm_Mult_qq(poly p, const poly m, const poly q, int &lp, int lq,
1071 const poly spNoether, const ring r)
1072{
1073 int shorter;
1074 const poly res = r->p_Procs->p_Minus_mm_Mult_qq(p, m, q, shorter, spNoether, r);
1075 lp += lq - shorter;
1076// assume( lp == pLength(res) );
1077 return res;
1078}
1079
1080// return p - m*Copy(q), destroys p; const: p,m
1081static inline poly p_Minus_mm_Mult_qq(poly p, const poly m, const poly q, const ring r)
1082{
1083 int shorter;
1084
1085 return r->p_Procs->p_Minus_mm_Mult_qq(p, m, q, shorter, NULL, r);
1086}
1087
1088
1089// returns p*Coeff(m) for such monomials pm of p, for which m is divisble by pm
1090static inline poly pp_Mult_Coeff_mm_DivSelect(poly p, const poly m, const ring r)
1091{
1092 int shorter;
1093 return r->p_Procs->pp_Mult_Coeff_mm_DivSelect(p, m, shorter, r);
1094}
1095
1096// returns p*Coeff(m) for such monomials pm of p, for which m is divisble by pm
1097// if lp is length of p on input then lp is length of returned poly on output
1098static inline poly pp_Mult_Coeff_mm_DivSelect(poly p, int &lp, const poly m, const ring r)
1099{
1100 int shorter;
1101 poly pp = r->p_Procs->pp_Mult_Coeff_mm_DivSelect(p, m, shorter, r);
1102 lp -= shorter;
1103 return pp;
1104}
1105
1106// returns -p, destroys p
1107static inline poly p_Neg(poly p, const ring r)
1108{
1109 return r->p_Procs->p_Neg(p, r);
1110}
1111
1112extern poly _p_Mult_q(poly p, poly q, const int copy, const ring r);
1113// returns p*q, destroys p and q
1114static inline poly p_Mult_q(poly p, poly q, const ring r)
1115{
1116 assume( (p != q) || (p == NULL && q == NULL) );
1117
1118 if (p == NULL)
1119 {
1120 p_Delete(&q, r);
1121 return NULL;
1122 }
1123 if (q == NULL)
1124 {
1125 p_Delete(&p, r);
1126 return NULL;
1127 }
1128
1129 if (pNext(p) == NULL)
1130 {
1131 q = r->p_Procs->p_mm_Mult(q, p, r);
1132 p_LmDelete(&p, r);
1133 return q;
1134 }
1135
1136 if (pNext(q) == NULL)
1137 {
1138 p = r->p_Procs->p_Mult_mm(p, q, r);
1139 p_LmDelete(&q, r);
1140 return p;
1141 }
1142#if defined(HAVE_PLURAL) || defined(HAVE_SHIFTBBA)
1143 if (rIsNCRing(r))
1144 return _nc_p_Mult_q(p, q, r);
1145 else
1146#endif
1147 return _p_Mult_q(p, q, 0, r);
1148}
1149
1150// returns p*q, does neither destroy p nor q
1151static inline poly pp_Mult_qq(poly p, poly q, const ring r)
1152{
1153 if (p == NULL || q == NULL) return NULL;
1154
1155 if (pNext(p) == NULL)
1156 {
1157 return r->p_Procs->pp_mm_Mult(q, p, r);
1158 }
1159
1160 if (pNext(q) == NULL)
1161 {
1162 return r->p_Procs->pp_Mult_mm(p, q, r);
1163 }
1164
1165 poly qq = q;
1166 if (p == q)
1167 qq = p_Copy(q, r);
1168
1169 poly res;
1170#if defined(HAVE_PLURAL) || defined(HAVE_SHIFTBBA)
1171 if (rIsNCRing(r))
1172 res = _nc_pp_Mult_qq(p, qq, r);
1173 else
1174#endif
1175 res = _p_Mult_q(p, qq, 1, r);
1176
1177 if (qq != q)
1178 p_Delete(&qq, r);
1179 return res;
1180}
1181
1182// returns p + m*q destroys p, const: q, m
1183static inline poly p_Plus_mm_Mult_qq(poly p, poly m, poly q, int &lp, int lq,
1184 const ring r)
1185{
1186#ifdef HAVE_PLURAL
1187 if (rIsPluralRing(r))
1188 return nc_p_Plus_mm_Mult_qq(p, m, q, lp, lq, r);
1189#endif
1190
1191// this should be implemented more efficiently
1192 poly res;
1193 int shorter;
1194 number n_old = pGetCoeff(m);
1195 number n_neg = n_Copy(n_old, r->cf);
1196 n_neg = n_InpNeg(n_neg, r->cf);
1197 pSetCoeff0(m, n_neg);
1198 res = r->p_Procs->p_Minus_mm_Mult_qq(p, m, q, shorter, NULL, r);
1199 lp = (lp + lq) - shorter;
1200 pSetCoeff0(m, n_old);
1201 n_Delete(&n_neg, r->cf);
1202 return res;
1203}
1204
1205static inline poly p_Plus_mm_Mult_qq(poly p, poly m, poly q, const ring r)
1206{
1207 int lp = 0, lq = 0;
1208 return p_Plus_mm_Mult_qq(p, m, q, lp, lq, r);
1209}
1210
1211// returns merged p and q, assumes p and q have no monomials which are equal
1212static inline poly p_Merge_q(poly p, poly q, const ring r)
1213{
1214 assume( (p != q) || (p == NULL && q == NULL) );
1215 return r->p_Procs->p_Merge_q(p, q, r);
1216}
1217
1218// like p_SortMerge, except that p may have equal monimals
1219static inline poly p_SortAdd(poly p, const ring r, BOOLEAN revert= FALSE)
1220{
1221 if (revert) p = pReverse(p);
1222 return sBucketSortAdd(p, r);
1223}
1224
1225// sorts p using bucket sort: returns sorted poly
1226// assumes that monomials of p are all different
1227// reverses it first, if revert == TRUE, use this if input p is "almost" sorted
1228// correctly
1229static inline poly p_SortMerge(poly p, const ring r, BOOLEAN revert= FALSE)
1230{
1231 if (revert) p = pReverse(p);
1232 return sBucketSortMerge(p, r);
1233}
1234
1235/***************************************************************
1236 *
1237 * I/O
1238 *
1239 ***************************************************************/
1240static inline char* p_String(poly p, ring p_ring)
1241{
1242 return p_String(p, p_ring, p_ring);
1243}
1244static inline void p_String0(poly p, ring p_ring)
1245{
1246 p_String0(p, p_ring, p_ring);
1247}
1248static inline void p_Write(poly p, ring p_ring)
1249{
1250 p_Write(p, p_ring, p_ring);
1251}
1252static inline void p_Write0(poly p, ring p_ring)
1253{
1254 p_Write0(p, p_ring, p_ring);
1255}
1256static inline void p_wrp(poly p, ring p_ring)
1257{
1258 p_wrp(p, p_ring, p_ring);
1259}
1260
1261
1262#if PDEBUG > 0
1263
1264#define _p_LmCmpAction(p, q, r, actionE, actionG, actionS) \
1265do \
1266{ \
1267 int _cmp = p_LmCmp(p,q,r); \
1268 if (_cmp == 0) actionE; \
1269 if (_cmp == 1) actionG; \
1270 actionS; \
1271} \
1272while(0)
1273
1274#else
1275
1276#define _p_LmCmpAction(p, q, r, actionE, actionG, actionS) \
1277 p_MemCmp_LengthGeneral_OrdGeneral(p->exp, q->exp, r->CmpL_Size, r->ordsgn, \
1278 actionE, actionG, actionS)
1279
1280#endif
1281
1282#define pDivAssume(x) do {} while (0)
1283
1284
1285
1286/***************************************************************
1287 *
1288 * Allocation/Initalization/Deletion
1289 *
1290 ***************************************************************/
1291// adjustments for negative weights
1292static inline void p_MemAdd_NegWeightAdjust(poly p, const ring r)
1293{
1294 if (r->NegWeightL_Offset != NULL)
1295 {
1296 for (int i=r->NegWeightL_Size-1; i>=0; i--)
1297 {
1298 p->exp[r->NegWeightL_Offset[i]] -= POLY_NEGWEIGHT_OFFSET;
1299 }
1300 }
1301}
1302static inline void p_MemSub_NegWeightAdjust(poly p, const ring r)
1303{
1304 if (r->NegWeightL_Offset != NULL)
1305 {
1306 for (int i=r->NegWeightL_Size-1; i>=0; i--)
1307 {
1308 p->exp[r->NegWeightL_Offset[i]] += POLY_NEGWEIGHT_OFFSET;
1309 }
1310 }
1311}
1312// ExpVextor(d_p) = ExpVector(s_p)
1313static inline void p_ExpVectorCopy(poly d_p, poly s_p, const ring r)
1314{
1315 p_LmCheckPolyRing1(d_p, r);
1316 p_LmCheckPolyRing1(s_p, r);
1317 memcpy(d_p->exp, s_p->exp, r->ExpL_Size*sizeof(long));
1318}
1319
1320static inline poly p_Init(const ring r, omBin bin)
1321{
1322 p_CheckRing1(r);
1323 pAssume1(bin != NULL && omSizeWOfBin(r->PolyBin) == omSizeWOfBin(bin));
1324 poly p;
1325 omTypeAlloc0Bin(poly, p, bin);
1327 p_SetRingOfLm(p, r);
1328 return p;
1329}
1330static inline poly p_Init(const ring r)
1331{
1332 return p_Init(r, r->PolyBin);
1333}
1334
1335static inline poly p_LmInit(poly p, const ring r)
1336{
1338 poly np;
1339 omTypeAllocBin(poly, np, r->PolyBin);
1340 p_SetRingOfLm(np, r);
1341 memcpy(np->exp, p->exp, r->ExpL_Size*sizeof(long));
1342 pNext(np) = NULL;
1343 pSetCoeff0(np, NULL);
1344 return np;
1345}
1346static inline poly p_LmInit(poly s_p, const ring s_r, const ring d_r, omBin d_bin)
1347{
1348 p_LmCheckPolyRing1(s_p, s_r);
1349 p_CheckRing(d_r);
1350 pAssume1(d_r->N <= s_r->N);
1351 poly d_p = p_Init(d_r, d_bin);
1352 for (unsigned i=d_r->N; i!=0; i--)
1353 {
1354 p_SetExp(d_p, i, p_GetExp(s_p, i,s_r), d_r);
1355 }
1356 if (rRing_has_Comp(d_r))
1357 {
1358 p_SetComp(d_p, p_GetComp(s_p,s_r), d_r);
1359 }
1360 p_Setm(d_p, d_r);
1361 return d_p;
1362}
1363static inline poly p_LmInit(poly s_p, const ring s_r, const ring d_r)
1364{
1365 pAssume1(d_r != NULL);
1366 return p_LmInit(s_p, s_r, d_r, d_r->PolyBin);
1367}
1368
1369// set all exponents l..k to 0, assume exp. k+1..n and 1..l-1 are in
1370// different blocks
1371// set coeff to 1
1372static inline poly p_GetExp_k_n(poly p, int l, int k, const ring r)
1373{
1374 if (p == NULL) return NULL;
1376 poly np;
1377 omTypeAllocBin(poly, np, r->PolyBin);
1378 p_SetRingOfLm(np, r);
1379 memcpy(np->exp, p->exp, r->ExpL_Size*sizeof(long));
1380 pNext(np) = NULL;
1381 pSetCoeff0(np, n_Init(1, r->cf));
1382 int i;
1383 for(i=l;i<=k;i++)
1384 {
1385 //np->exp[(r->VarOffset[i] & 0xffffff)] =0;
1386 p_SetExp(np,i,0,r);
1387 }
1388 p_Setm(np,r);
1389 return np;
1390}
1391
1392// simialar to p_ShallowCopyDelete but does it only for leading monomial
1393static inline poly p_LmShallowCopyDelete(poly p, const ring r)
1394{
1396 pAssume1(omSizeWOfBin(bin) == omSizeWOfBin(r->PolyBin));
1397 poly new_p = p_New(r);
1398 memcpy(new_p->exp, p->exp, r->ExpL_Size*sizeof(long));
1399 pSetCoeff0(new_p, pGetCoeff(p));
1400 pNext(new_p) = pNext(p);
1402 return new_p;
1403}
1404
1405/***************************************************************
1406 *
1407 * Operation on ExpVectors
1408 *
1409 ***************************************************************/
1410// ExpVector(p1) += ExpVector(p2)
1411static inline void p_ExpVectorAdd(poly p1, poly p2, const ring r)
1412{
1413 p_LmCheckPolyRing1(p1, r);
1414 p_LmCheckPolyRing1(p2, r);
1415#if PDEBUG >= 1
1416 for (int i=1; i<=r->N; i++)
1417 pAssume1((unsigned long) (p_GetExp(p1, i, r) + p_GetExp(p2, i, r)) <= r->bitmask);
1418 pAssume1(p_GetComp(p1, r) == 0 || p_GetComp(p2, r) == 0);
1419#endif
1420
1421 p_MemAdd_LengthGeneral(p1->exp, p2->exp, r->ExpL_Size);
1423}
1424// ExpVector(pr) = ExpVector(p1) + ExpVector(p2)
1425static inline void p_ExpVectorSum(poly pr, poly p1, poly p2, const ring r)
1426{
1427 p_LmCheckPolyRing1(p1, r);
1428 p_LmCheckPolyRing1(p2, r);
1429 p_LmCheckPolyRing1(pr, r);
1430#if PDEBUG >= 1
1431 for (int i=1; i<=r->N; i++)
1432 pAssume1((unsigned long) (p_GetExp(p1, i, r) + p_GetExp(p2, i, r)) <= r->bitmask);
1433 pAssume1(p_GetComp(p1, r) == 0 || p_GetComp(p2, r) == 0);
1434#endif
1435
1436 p_MemSum_LengthGeneral(pr->exp, p1->exp, p2->exp, r->ExpL_Size);
1438}
1439// ExpVector(p1) -= ExpVector(p2)
1440static inline void p_ExpVectorSub(poly p1, poly p2, const ring r)
1441{
1442 p_LmCheckPolyRing1(p1, r);
1443 p_LmCheckPolyRing1(p2, r);
1444#if PDEBUG >= 1
1445 for (int i=1; i<=r->N; i++)
1446 pAssume1(p_GetExp(p1, i, r) >= p_GetExp(p2, i, r));
1447 pAssume1(p_GetComp(p1, r) == 0 || p_GetComp(p2, r) == 0 ||
1448 p_GetComp(p1, r) == p_GetComp(p2, r));
1449#endif
1450
1451 p_MemSub_LengthGeneral(p1->exp, p2->exp, r->ExpL_Size);
1453}
1454
1455// ExpVector(p1) += ExpVector(p2) - ExpVector(p3)
1456static inline void p_ExpVectorAddSub(poly p1, poly p2, poly p3, const ring r)
1457{
1458 p_LmCheckPolyRing1(p1, r);
1459 p_LmCheckPolyRing1(p2, r);
1460 p_LmCheckPolyRing1(p3, r);
1461#if PDEBUG >= 1
1462 for (int i=1; i<=r->N; i++)
1463 pAssume1(p_GetExp(p1, i, r) + p_GetExp(p2, i, r) >= p_GetExp(p3, i, r));
1464 pAssume1(p_GetComp(p1, r) == 0 ||
1465 (p_GetComp(p2, r) - p_GetComp(p3, r) == 0) ||
1466 (p_GetComp(p1, r) == p_GetComp(p2, r) - p_GetComp(p3, r)));
1467#endif
1468
1469 p_MemAddSub_LengthGeneral(p1->exp, p2->exp, p3->exp, r->ExpL_Size);
1470 // no need to adjust in case of NegWeights
1471}
1472
1473// ExpVector(pr) = ExpVector(p1) - ExpVector(p2)
1474static inline void p_ExpVectorDiff(poly pr, poly p1, poly p2, const ring r)
1475{
1476 p_LmCheckPolyRing1(p1, r);
1477 p_LmCheckPolyRing1(p2, r);
1478 p_LmCheckPolyRing1(pr, r);
1479#if PDEBUG >= 2
1480 for (int i=1; i<=r->N; i++)
1481 pAssume1(p_GetExp(p1, i, r) >= p_GetExp(p2, i, r));
1482 pAssume1(!rRing_has_Comp(r) || p_GetComp(p1, r) == p_GetComp(p2, r));
1483#endif
1484
1485 p_MemDiff_LengthGeneral(pr->exp, p1->exp, p2->exp, r->ExpL_Size);
1487}
1488
1489static inline BOOLEAN p_ExpVectorEqual(poly p1, poly p2, const ring r)
1490{
1491 p_LmCheckPolyRing1(p1, r);
1492 p_LmCheckPolyRing1(p2, r);
1493
1494 unsigned i = r->ExpL_Size;
1495 unsigned long *ep = p1->exp;
1496 unsigned long *eq = p2->exp;
1497
1498 do
1499 {
1500 i--;
1501 if (ep[i] != eq[i]) return FALSE;
1502 }
1503 while (i!=0);
1504 return TRUE;
1505}
1506
1507static inline long p_Totaldegree(poly p, const ring r)
1508{
1510 unsigned long s = p_GetTotalDegree(p->exp[r->VarL_Offset[0]],
1511 r,
1512 r->ExpPerLong);
1513 for (unsigned i=r->VarL_Size-1; i!=0; i--)
1514 {
1515 s += p_GetTotalDegree(p->exp[r->VarL_Offset[i]], r,r->ExpPerLong);
1516 }
1517 return (long)s;
1518}
1519
1520static inline void p_GetExpV(poly p, int *ev, const ring r)
1521{
1523 for (unsigned j = r->N; j!=0; j--)
1524 ev[j] = p_GetExp(p, j, r);
1525
1526 ev[0] = p_GetComp(p, r);
1527}
1528// p_GetExpVL is used in Singular,jl
1529static inline void p_GetExpVL(poly p, int64 *ev, const ring r)
1530{
1532 for (unsigned j = r->N; j!=0; j--)
1533 ev[j-1] = p_GetExp(p, j, r);
1534}
1535// p_GetExpVLV is used in Singular,jl
1536static inline int64 p_GetExpVLV(poly p, int64 *ev, const ring r)
1537{
1539 for (unsigned j = r->N; j!=0; j--)
1540 ev[j-1] = p_GetExp(p, j, r);
1541 return (int64)p_GetComp(p,r);
1542}
1543// p_GetExpVL is used in Singular,jl
1544static inline void p_SetExpV(poly p, int *ev, const ring r)
1545{
1547 for (unsigned j = r->N; j!=0; j--)
1548 p_SetExp(p, j, ev[j], r);
1549
1550 if(ev[0]!=0) p_SetComp(p, ev[0],r);
1551 p_Setm(p, r);
1552}
1553static inline void p_SetExpVL(poly p, int64 *ev, const ring r)
1554{
1556 for (unsigned j = r->N; j!=0; j--)
1557 p_SetExp(p, j, ev[j-1], r);
1558 p_SetComp(p, 0,r);
1559
1560 p_Setm(p, r);
1561}
1562
1563// p_SetExpVLV is used in Singular,jl
1564static inline void p_SetExpVLV(poly p, int64 *ev, int64 comp, const ring r)
1565{
1567 for (unsigned j = r->N; j!=0; j--)
1568 p_SetExp(p, j, ev[j-1], r);
1569 p_SetComp(p, comp,r);
1570
1571 p_Setm(p, r);
1572}
1573
1574/***************************************************************
1575 *
1576 * Comparison w.r.t. monomial ordering
1577 *
1578 ***************************************************************/
1579
1580static inline int p_LmCmp(poly p, poly q, const ring r)
1581{
1583 p_LmCheckPolyRing1(q, r);
1584
1585 const unsigned long* _s1 = ((unsigned long*) p->exp);
1586 const unsigned long* _s2 = ((unsigned long*) q->exp);
1587 REGISTER unsigned long _v1;
1588 REGISTER unsigned long _v2;
1589 const unsigned long _l = r->CmpL_Size;
1590
1591 REGISTER unsigned long _i=0;
1592
1593 LengthGeneral_OrdGeneral_LoopTop:
1594 _v1 = _s1[_i];
1595 _v2 = _s2[_i];
1596 if (_v1 == _v2)
1597 {
1598 _i++;
1599 if (_i == _l) return 0;
1600 goto LengthGeneral_OrdGeneral_LoopTop;
1601 }
1602 const long* _ordsgn = (long*) r->ordsgn;
1603#if 1 /* two variants*/
1604 if (_v1 > _v2)
1605 {
1606 return _ordsgn[_i];
1607 }
1608 return -(_ordsgn[_i]);
1609#else
1610 if (_v1 > _v2)
1611 {
1612 if (_ordsgn[_i] == 1) return 1;
1613 return -1;
1614 }
1615 if (_ordsgn[_i] == 1) return -1;
1616 return 1;
1617#endif
1618}
1619
1620// The coefficient will be compared in absolute value
1621static inline int p_LtCmp(poly p, poly q, const ring r)
1622{
1623 int res = p_LmCmp(p,q,r);
1624 if(res == 0)
1625 {
1626 if(p_GetCoeff(p,r) == NULL || p_GetCoeff(q,r) == NULL)
1627 return res;
1628 number pc = n_Copy(p_GetCoeff(p,r),r->cf);
1629 number qc = n_Copy(p_GetCoeff(q,r),r->cf);
1630 if(!n_GreaterZero(pc,r->cf))
1631 pc = n_InpNeg(pc,r->cf);
1632 if(!n_GreaterZero(qc,r->cf))
1633 qc = n_InpNeg(qc,r->cf);
1634 if(n_Greater(pc,qc,r->cf))
1635 res = 1;
1636 else if(n_Greater(qc,pc,r->cf))
1637 res = -1;
1638 else if(n_Equal(pc,qc,r->cf))
1639 res = 0;
1640 n_Delete(&pc,r->cf);
1641 n_Delete(&qc,r->cf);
1642 }
1643 return res;
1644}
1645
1646// The coefficient will be compared in absolute value
1647static inline int p_LtCmpNoAbs(poly p, poly q, const ring r)
1648{
1649 int res = p_LmCmp(p,q,r);
1650 if(res == 0)
1651 {
1652 if(p_GetCoeff(p,r) == NULL || p_GetCoeff(q,r) == NULL)
1653 return res;
1654 number pc = p_GetCoeff(p,r);
1655 number qc = p_GetCoeff(q,r);
1656 if(n_Greater(pc,qc,r->cf))
1657 res = 1;
1658 if(n_Greater(qc,pc,r->cf))
1659 res = -1;
1660 if(n_Equal(pc,qc,r->cf))
1661 res = 0;
1662 }
1663 return res;
1664}
1665
1666#ifdef HAVE_RINGS
1667// This is the equivalent of pLmCmp(p,q) != -currRing->OrdSgn for rings
1668// It is used in posInLRing and posInTRing
1669static inline int p_LtCmpOrdSgnDiffM(poly p, poly q, const ring r)
1670{
1671 if(r->OrdSgn == 1)
1672 {
1673 return(p_LtCmp(p,q,r) == 1);
1674 }
1675 else
1676 {
1677 return(p_LmCmp(p,q,r) == -1);
1678 }
1679}
1680#endif
1681
1682#ifdef HAVE_RINGS
1683// This is the equivalent of pLmCmp(p,q) != currRing->OrdSgn for rings
1684// It is used in posInLRing and posInTRing
1685static inline int p_LtCmpOrdSgnDiffP(poly p, poly q, const ring r)
1686{
1687 if(r->OrdSgn == 1)
1688 {
1689 return(p_LmCmp(p,q,r) == -1);
1690 }
1691 else
1692 {
1693 return(p_LtCmp(p,q,r) != -1);
1694 }
1695
1696}
1697#endif
1698
1699#ifdef HAVE_RINGS
1700// This is the equivalent of pLmCmp(p,q) == -currRing->OrdSgn for rings
1701// It is used in posInLRing and posInTRing
1702static inline int p_LtCmpOrdSgnEqM(poly p, poly q, const ring r)
1703{
1704 return(p_LtCmp(p,q,r) == -r->OrdSgn);
1705}
1706#endif
1707
1708#ifdef HAVE_RINGS
1709// This is the equivalent of pLmCmp(p,q) == currRing->OrdSgn for rings
1710// It is used in posInLRing and posInTRing
1711static inline int p_LtCmpOrdSgnEqP(poly p, poly q, const ring r)
1712{
1713 return(p_LtCmp(p,q,r) == r->OrdSgn);
1714}
1715#endif
1716
1717/// returns TRUE if p1 is a skalar multiple of p2
1718/// assume p1 != NULL and p2 != NULL
1719BOOLEAN p_ComparePolys(poly p1,poly p2, const ring r);
1720
1721
1722/***************************************************************
1723 *
1724 * Comparisons: they are all done without regarding coeffs
1725 *
1726 ***************************************************************/
1727#define p_LmCmpAction(p, q, r, actionE, actionG, actionS) \
1728 _p_LmCmpAction(p, q, r, actionE, actionG, actionS)
1729
1730// returns 1 if ExpVector(p)==ExpVector(q): does not compare numbers !!
1731#define p_LmEqual(p1, p2, r) p_ExpVectorEqual(p1, p2, r)
1732
1733// pCmp: args may be NULL
1734// returns: (p2==NULL ? 1 : (p1 == NULL ? -1 : p_LmCmp(p1, p2)))
1735static inline int p_Cmp(poly p1, poly p2, ring r)
1736{
1737 if (p2==NULL)
1738 {
1739 if (p1==NULL) return 0;
1740 return 1;
1741 }
1742 if (p1==NULL)
1743 return -1;
1744 return p_LmCmp(p1,p2,r);
1745}
1746
1747static inline int p_CmpPolys(poly p1, poly p2, ring r)
1748{
1749 if (p2==NULL)
1750 {
1751 if (p1==NULL) return 0;
1752 return 1;
1753 }
1754 if (p1==NULL)
1755 return -1;
1756 return p_ComparePolys(p1,p2,r);
1757}
1758
1759
1760/***************************************************************
1761 *
1762 * divisibility
1763 *
1764 ***************************************************************/
1765/// return: FALSE, if there exists i, such that a->exp[i] > b->exp[i]
1766/// TRUE, otherwise
1767/// (1) Consider long vars, instead of single exponents
1768/// (2) Clearly, if la > lb, then FALSE
1769/// (3) Suppose la <= lb, and consider first bits of single exponents in l:
1770/// if TRUE, then value of these bits is la ^ lb
1771/// if FALSE, then la-lb causes an "overflow" into one of those bits, i.e.,
1772/// la ^ lb != la - lb
1773static inline BOOLEAN _p_LmDivisibleByNoComp(poly a, poly b, const ring r)
1774{
1775 int i=r->VarL_Size - 1;
1776 unsigned long divmask = r->divmask;
1777 unsigned long la, lb;
1778
1779 if (r->VarL_LowIndex >= 0)
1780 {
1781 i += r->VarL_LowIndex;
1782 do
1783 {
1784 la = a->exp[i];
1785 lb = b->exp[i];
1786 if ((la > lb) ||
1787 (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask)))
1788 {
1790 return FALSE;
1791 }
1792 i--;
1793 }
1794 while (i>=r->VarL_LowIndex);
1795 }
1796 else
1797 {
1798 do
1799 {
1800 la = a->exp[r->VarL_Offset[i]];
1801 lb = b->exp[r->VarL_Offset[i]];
1802 if ((la > lb) ||
1803 (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask)))
1804 {
1806 return FALSE;
1807 }
1808 i--;
1809 }
1810 while (i>=0);
1811 }
1812/*#ifdef HAVE_RINGS
1813 pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == n_DivBy(p_GetCoeff(b, r), p_GetCoeff(a, r), r->cf));
1814 return (!rField_is_Ring(r)) || n_DivBy(p_GetCoeff(b, r), p_GetCoeff(a, r), r->cf);
1815#else
1816*/
1818 return TRUE;
1819//#endif
1820}
1821
1822static inline BOOLEAN _p_LmDivisibleByNoComp(poly a, const ring r_a, poly b, const ring r_b)
1823{
1824 int i=r_a->N;
1825 pAssume1(r_a->N == r_b->N);
1826
1827 do
1828 {
1829 if (p_GetExp(a,i,r_a) > p_GetExp(b,i,r_b))
1830 return FALSE;
1831 i--;
1832 }
1833 while (i);
1834/*#ifdef HAVE_RINGS
1835 return n_DivBy(p_GetCoeff(b, r_b), p_GetCoeff(a, r_a), r_a->cf);
1836#else
1837*/
1838 return TRUE;
1839//#endif
1840}
1841
1842#ifdef HAVE_RATGRING
1843static inline BOOLEAN _p_LmDivisibleByNoCompPart(poly a, const ring r_a, poly b, const ring r_b,const int start, const int end)
1844{
1845 int i=end;
1846 pAssume1(r_a->N == r_b->N);
1847
1848 do
1849 {
1850 if (p_GetExp(a,i,r_a) > p_GetExp(b,i,r_b))
1851 return FALSE;
1852 i--;
1853 }
1854 while (i>=start);
1855/*#ifdef HAVE_RINGS
1856 return n_DivBy(p_GetCoeff(b, r_b), p_GetCoeff(a, r_a), r_a->cf);
1857#else
1858*/
1859 return TRUE;
1860//#endif
1861}
1862static inline BOOLEAN _p_LmDivisibleByPart(poly a, const ring r_a, poly b, const ring r_b,const int start, const int end)
1863{
1864 if (p_GetComp(a, r_a) == 0 || p_GetComp(a,r_a) == p_GetComp(b,r_b))
1865 return _p_LmDivisibleByNoCompPart(a, r_a, b, r_b,start,end);
1866 return FALSE;
1867}
1868static inline BOOLEAN p_LmDivisibleByPart(poly a, poly b, const ring r,const int start, const int end)
1869{
1871 pIfThen1(a != NULL, p_LmCheckPolyRing1(b, r));
1872 if (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r))
1873 return _p_LmDivisibleByNoCompPart(a, r, b, r,start, end);
1874 return FALSE;
1875}
1876#endif
1877static inline BOOLEAN _p_LmDivisibleBy(poly a, poly b, const ring r)
1878{
1879 if (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r))
1880 return _p_LmDivisibleByNoComp(a, b, r);
1881 return FALSE;
1882}
1883static inline BOOLEAN _p_LmDivisibleBy(poly a, const ring r_a, poly b, const ring r_b)
1884{
1885 if (p_GetComp(a, r_a) == 0 || p_GetComp(a,r_a) == p_GetComp(b,r_b))
1886 return _p_LmDivisibleByNoComp(a, r_a, b, r_b);
1887 return FALSE;
1888}
1889static inline BOOLEAN p_LmDivisibleByNoComp(poly a, poly b, const ring r)
1890{
1891 p_LmCheckPolyRing1(a, r);
1893 return _p_LmDivisibleByNoComp(a, b, r);
1894}
1895
1896static inline BOOLEAN p_LmDivisibleByNoComp(poly a, const ring ra, poly b, const ring rb)
1897{
1898 p_LmCheckPolyRing1(a, ra);
1899 p_LmCheckPolyRing1(b, rb);
1900 return _p_LmDivisibleByNoComp(a, ra, b, rb);
1901}
1902
1903static inline BOOLEAN p_LmDivisibleBy(poly a, poly b, const ring r)
1904{
1906 pIfThen1(a != NULL, p_LmCheckPolyRing1(b, r));
1907 if (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r))
1908 return _p_LmDivisibleByNoComp(a, b, r);
1909 return FALSE;
1910}
1911
1912static inline BOOLEAN p_DivisibleBy(poly a, poly b, const ring r)
1913{
1915 pIfThen1(a!=NULL, p_LmCheckPolyRing1(a, r));
1916
1917 if (a != NULL && (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r)))
1918 return _p_LmDivisibleByNoComp(a,b,r);
1919 return FALSE;
1920}
1921static inline BOOLEAN p_DivisibleBy(poly a, const ring r_a, poly b, const ring r_b)
1922{
1924 pIfThen1(a!=NULL, p_LmCheckPolyRing1(a, r_a));
1925 if (a != NULL) {
1926 return _p_LmDivisibleBy(a, r_a, b, r_b);
1927 }
1928 return FALSE;
1929}
1930static inline BOOLEAN p_LmDivisibleBy(poly a, const ring r_a, poly b, const ring r_b)
1931{
1932 p_LmCheckPolyRing(a, r_a);
1933 p_LmCheckPolyRing(b, r_b);
1934 return _p_LmDivisibleBy(a, r_a, b, r_b);
1935}
1936
1937static inline BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a,
1938 poly b, unsigned long not_sev_b, const ring r)
1939{
1940 p_LmCheckPolyRing1(a, r);
1942#ifndef PDIV_DEBUG
1943 _pPolyAssume2(p_GetShortExpVector(a, r) == sev_a, a, r);
1944 _pPolyAssume2(p_GetShortExpVector(b, r) == ~ not_sev_b, b, r);
1945
1946 if (sev_a & not_sev_b)
1947 {
1949 return FALSE;
1950 }
1951 return p_LmDivisibleBy(a, b, r);
1952#else
1953 return pDebugLmShortDivisibleBy(a, sev_a, r, b, not_sev_b, r);
1954#endif
1955}
1956
1957static inline BOOLEAN p_LmShortDivisibleByNoComp(poly a, unsigned long sev_a,
1958 poly b, unsigned long not_sev_b, const ring r)
1959{
1960 p_LmCheckPolyRing1(a, r);
1962#ifndef PDIV_DEBUG
1963 _pPolyAssume2(p_GetShortExpVector(a, r) == sev_a, a, r);
1964 _pPolyAssume2(p_GetShortExpVector(b, r) == ~ not_sev_b, b, r);
1965
1966 if (sev_a & not_sev_b)
1967 {
1969 return FALSE;
1970 }
1971 return p_LmDivisibleByNoComp(a, b, r);
1972#else
1973 return pDebugLmShortDivisibleByNoComp(a, sev_a, r, b, not_sev_b, r);
1974#endif
1975}
1976
1977static inline BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a, const ring r_a,
1978 poly b, unsigned long not_sev_b, const ring r_b)
1979{
1980 p_LmCheckPolyRing1(a, r_a);
1981 p_LmCheckPolyRing1(b, r_b);
1982#ifndef PDIV_DEBUG
1983 _pPolyAssume2(p_GetShortExpVector(a, r_a) == sev_a, a, r_a);
1984 _pPolyAssume2(p_GetShortExpVector(b, r_b) == ~ not_sev_b, b, r_b);
1985
1986 if (sev_a & not_sev_b)
1987 {
1988 pAssume1(_p_LmDivisibleByNoComp(a, r_a, b, r_b) == FALSE);
1989 return FALSE;
1990 }
1991 return _p_LmDivisibleBy(a, r_a, b, r_b);
1992#else
1993 return pDebugLmShortDivisibleBy(a, sev_a, r_a, b, not_sev_b, r_b);
1994#endif
1995}
1996
1997/***************************************************************
1998 *
1999 * Misc things on Lm
2000 *
2001 ***************************************************************/
2002
2003
2004/// like the respective p_LmIs* routines, except that p might be empty
2005static inline BOOLEAN p_IsConstantComp(const poly p, const ring r)
2006{
2007 if (p == NULL) return TRUE;
2008 return (pNext(p)==NULL) && p_LmIsConstantComp(p, r);
2009}
2010
2011static inline BOOLEAN p_IsConstant(const poly p, const ring r)
2012{
2013 if (p == NULL) return TRUE;
2014 return (pNext(p)==NULL) && p_LmIsConstant(p, r);
2015}
2016
2017/// either poly(1) or gen(k)?!
2018static inline BOOLEAN p_IsOne(const poly p, const ring R)
2019{
2020 if (p == NULL) return FALSE; /* TODO check if 0 == 1 */
2021 p_Test(p, R);
2022 return (p_IsConstant(p, R) && n_IsOne(p_GetCoeff(p, R), R->cf));
2023}
2024
2025static inline BOOLEAN p_IsConstantPoly(const poly p, const ring r)
2026{
2027 p_Test(p, r);
2028 poly pp=p;
2029 while(pp!=NULL)
2030 {
2031 if (! p_LmIsConstantComp(pp, r))
2032 return FALSE;
2033 pIter(pp);
2034 }
2035 return TRUE;
2036}
2037
2038static inline BOOLEAN p_IsUnit(const poly p, const ring r)
2039{
2040 if (p == NULL) return FALSE;
2041 if (rField_is_Ring(r))
2042 return (p_LmIsConstant(p, r) && n_IsUnit(pGetCoeff(p),r->cf));
2043 return p_LmIsConstant(p, r);
2044}
2045
2046static inline BOOLEAN p_LmExpVectorAddIsOk(const poly p1, const poly p2,
2047 const ring r)
2048{
2049 p_LmCheckPolyRing(p1, r);
2050 p_LmCheckPolyRing(p2, r);
2051 unsigned long l1, l2, divmask = r->divmask;
2052 int i;
2053
2054 for (i=0; i<r->VarL_Size; i++)
2055 {
2056 l1 = p1->exp[r->VarL_Offset[i]];
2057 l2 = p2->exp[r->VarL_Offset[i]];
2058 // do the divisiblity trick
2059 if ( (l1 > ULONG_MAX - l2) ||
2060 (((l1 & divmask) ^ (l2 & divmask)) != ((l1 + l2) & divmask)))
2061 return FALSE;
2062 }
2063 return TRUE;
2064}
2065void p_Split(poly p, poly * r); /*p => IN(p), r => REST(p) */
2066BOOLEAN p_HasNotCF(poly p1, poly p2, const ring r);
2067BOOLEAN p_HasNotCFRing(poly p1, poly p2, const ring r);
2068poly p_mInit(const char *s, BOOLEAN &ok, const ring r); /* monom s -> poly, interpreter */
2069const char * p_Read(const char *s, poly &p,const ring r); /* monom -> poly */
2070poly p_MDivide(poly a, poly b, const ring r);
2071poly p_DivideM(poly a, poly b, const ring r);
2072poly pp_DivideM(poly a, poly b, const ring r);
2073poly p_Div_nn(poly p, const number n, const ring r);
2074
2075// returns the LCM of the head terms of a and b in *m, does not p_Setm
2076void p_Lcm(const poly a, const poly b, poly m, const ring r);
2077// returns the LCM of the head terms of a and b, does p_Setm
2078poly p_Lcm(const poly a, const poly b, const ring r);
2079
2080#ifdef HAVE_RATGRING
2081poly p_LcmRat(const poly a, const poly b, const long lCompM, const ring r);
2082poly p_GetCoeffRat(poly p, int ishift, ring r);
2083void p_LmDeleteAndNextRat(poly *p, int ishift, ring r);
2084void p_ContentRat(poly &ph, const ring r);
2085#endif /* ifdef HAVE_RATGRING */
2086
2087
2088poly p_Diff(poly a, int k, const ring r);
2089poly p_DiffOp(poly a, poly b,BOOLEAN multiply, const ring r);
2090int p_Weight(int c, const ring r);
2091
2092/// assumes that p and divisor are univariate polynomials in r,
2093/// mentioning the same variable;
2094/// assumes divisor != NULL;
2095/// p may be NULL;
2096/// assumes a global monomial ordering in r;
2097/// performs polynomial division of p by divisor:
2098/// - afterwards p contains the remainder of the division, i.e.,
2099/// p_before = result * divisor + p_afterwards;
2100/// - if needResult == TRUE, then the method computes and returns 'result',
2101/// otherwise NULL is returned (This parametrization can be used when
2102/// one is only interested in the remainder of the division. In this
2103/// case, the method will be slightly faster.)
2104/// leaves divisor unmodified
2105poly p_PolyDiv(poly &p, const poly divisor, const BOOLEAN needResult, const ring r);
2106
2107/* syszygy stuff */
2108BOOLEAN p_VectorHasUnitB(poly p, int * k, const ring r);
2109void p_VectorHasUnit(poly p, int * k, int * len, const ring r);
2110poly p_TakeOutComp1(poly * p, int k, const ring r);
2111// Splits *p into two polys: *q which consists of all monoms with
2112// component == comp and *p of all other monoms *lq == pLength(*q)
2113// On return all components pf *q == 0
2114void p_TakeOutComp(poly *p, long comp, poly *q, int *lq, const ring r);
2115
2116// This is something weird -- Don't use it, unless you know what you are doing
2117poly p_TakeOutComp(poly * p, int k, const ring r);
2118
2119void p_DeleteComp(poly * p,int k, const ring r);
2120
2121/*-------------ring management:----------------------*/
2122
2123// resets the pFDeg and pLDeg: if pLDeg is not given, it is
2124// set to currRing->pLDegOrig, i.e. to the respective LDegProc which
2125// only uses pFDeg (and not pDeg, or pTotalDegree, etc).
2126// If you use this, make sure your procs does not make any assumptions
2127// on ordering and/or OrdIndex -- otherwise they might return wrong results
2128// on strat->tailRing
2129void pSetDegProcs(ring r, pFDegProc new_FDeg, pLDegProc new_lDeg = NULL);
2130// restores pFDeg and pLDeg:
2131void pRestoreDegProcs(ring r, pFDegProc old_FDeg, pLDegProc old_lDeg);
2132
2133/*-------------pComp for syzygies:-------------------*/
2134void p_SetModDeg(intvec *w, ring r);
2135
2136/*------------ Jet ----------------------------------*/
2137poly pp_Jet(poly p, int m, const ring R);
2138poly p_Jet(poly p, int m,const ring R);
2139poly pp_JetW(poly p, int m, int *w, const ring R);
2140poly p_JetW(poly p, int m, int *w, const ring R);
2141
2142poly n_PermNumber(const number z, const int *par_perm, const int OldPar, const ring src, const ring dst);
2143
2144poly p_PermPoly (poly p, const int * perm,const ring OldRing, const ring dst,
2145 nMapFunc nMap, const int *par_perm=NULL, int OldPar=0,
2146 BOOLEAN use_mult=FALSE);
2147
2148/*----------------------------------------------------*/
2149poly p_Series(int n,poly p,poly u, intvec *w, const ring R);
2150
2151/*----------------------------------------------------*/
2152int p_Var(poly mi, const ring r);
2153/// the minimal index of used variables - 1
2154int p_LowVar (poly p, const ring r);
2155
2156/*----------------------------------------------------*/
2157/// shifts components of the vector p by i
2158void p_Shift (poly * p,int i, const ring r);
2159/*----------------------------------------------------*/
2160
2161int p_Compare(const poly a, const poly b, const ring R);
2162
2163/// polynomial gcd for f=mon
2164poly p_GcdMon(poly f, poly g, const ring r);
2165
2166/// divide polynomial by monomial
2167poly p_Div_mm(poly p, const poly m, const ring r);
2168
2169
2170/// max exponent of variable x_i in p
2171int p_MaxExpPerVar(poly p, int i, const ring r);
2172#endif // P_POLYS_H
2173
long int64
Definition: auxiliary.h:68
int BOOLEAN
Definition: auxiliary.h:87
#define TRUE
Definition: auxiliary.h:100
#define FALSE
Definition: auxiliary.h:96
CanonicalForm FACTORY_PUBLIC pp(const CanonicalForm &)
CanonicalForm pp ( const CanonicalForm & f )
Definition: cf_gcd.cc:676
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:4082
int p
Definition: cfModGcd.cc:4078
g
Definition: cfModGcd.cc:4090
CanonicalForm b
Definition: cfModGcd.cc:4103
FILE * f
Definition: checklibs.c:9
Definition: intvec.h:23
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:451
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
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
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
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
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
Definition: coeffs.h:464
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:455
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
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
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition: coeffs.h:73
static FORCE_INLINE BOOLEAN n_IsOne(number n, const coeffs r)
TRUE iff 'n' represents the one element.
Definition: coeffs.h:468
return result
Definition: facAbsBiFact.cc:75
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
if(yy_init)
Definition: libparse.cc:1420
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:387
#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: mpr_complex.cc:357
Definition: lq.h:40
#define omTypeAlloc0Bin(type, addr, bin)
Definition: omAllocDecl.h:204
#define omTypeAllocBin(type, addr, bin)
Definition: omAllocDecl.h:203
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
#define omFreeBinAddr(addr)
Definition: omAllocDecl.h:258
#define omSizeWOfBin(bin_ptr)
#define NULL
Definition: omList.c:12
omBin_t * omBin
Definition: omStructs.h:12
#define REGISTER
Definition: omalloc.h:27
BOOLEAN pDebugLmShortDivisibleByNoComp(poly p1, unsigned long sev_1, ring r_1, poly p2, unsigned long not_sev_2, ring r_2)
Definition: pDebug.cc:389
BOOLEAN pDebugLmShortDivisibleBy(poly p1, unsigned long sev_1, ring r_1, poly p2, unsigned long not_sev_2, ring r_2)
Definition: pDebug.cc:366
BOOLEAN p_DebugLmDivisibleByNoComp(poly a, poly b, ring r)
Definition: pDebug.cc:141
#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:1107
void p_Content_n(poly p, number &c, const ring r)
Definition: p_polys.cc:2349
poly p_Diff(poly a, int k, const ring r)
Definition: p_polys.cc:1894
long pLDeg1c_WFirstTotalDegree(poly p, int *l, ring r)
Definition: p_polys.cc:1068
static int p_CmpPolys(poly p1, poly p2, ring r)
Definition: p_polys.h:1747
long pLDeg0(poly p, int *l, ring r)
Definition: p_polys.cc:739
poly p_DivideM(poly a, poly b, const ring r)
Definition: p_polys.cc:1574
int p_IsPurePower(const poly p, const ring r)
return i, if head depends only on var(i)
Definition: p_polys.cc:1226
static long p_GetExpDiff(poly p1, poly p2, int i, ring r)
Definition: p_polys.h:635
static void p_ExpVectorSum(poly pr, poly p1, poly p2, const ring r)
Definition: p_polys.h:1425
poly pp_Jet(poly p, int m, const ring R)
Definition: p_polys.cc:4423
static poly p_Add_q(poly p, poly q, const ring r)
Definition: p_polys.h:936
static void p_LmDelete(poly p, const ring r)
Definition: p_polys.h:723
static poly p_Mult_q(poly p, poly q, const ring r)
Definition: p_polys.h:1114
void pSetDegProcs(ring r, pFDegProc new_FDeg, pLDegProc new_lDeg=NULL)
Definition: p_polys.cc:3715
BOOLEAN pIsMonomOf(poly p, poly m)
Definition: pDebug.cc:165
BOOLEAN p_LmCheckPolyRing(poly p, ring r)
Definition: pDebug.cc:120
static void p_MemAdd_NegWeightAdjust(poly p, const ring r)
Definition: p_polys.h:1292
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:212
static void p_ExpVectorAdd(poly p1, poly p2, const ring r)
Definition: p_polys.h:1411
static unsigned long p_SubComp(poly p, unsigned long v, ring r)
Definition: p_polys.h:453
long pLDeg1_Deg(poly p, int *l, ring r)
Definition: p_polys.cc:910
BOOLEAN p_CheckIsFromRing(poly p, ring r)
Definition: pDebug.cc:102
void pRestoreDegProcs(ring r, pFDegProc old_FDeg, pLDegProc old_lDeg)
Definition: p_polys.cc:3727
long pLDeg1_WFirstTotalDegree(poly p, int *l, ring r)
Definition: p_polys.cc:1038
static long p_SubExp(poly p, int v, long ee, ring r)
Definition: p_polys.h:613
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:1862
poly p_Sub(poly a, poly b, const ring r)
Definition: p_polys.cc:1986
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:1866
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:2005
int p_Size(poly p, const ring r)
Definition: p_polys.cc:3318
static long p_AddExp(poly p, int v, long ee, ring r)
Definition: p_polys.h:606
static poly p_LmInit(poly p, const ring r)
Definition: p_polys.h:1335
poly p_GcdMon(poly f, poly g, const ring r)
polynomial gcd for f=mon
Definition: p_polys.cc:5006
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:4641
static long p_FDeg(const poly p, const ring r)
Definition: p_polys.h:380
static unsigned long p_GetMaxExp(const unsigned long l, const ring r)
Definition: p_polys.h:781
int p_LowVar(poly p, const ring r)
the minimal index of used variables - 1
Definition: p_polys.cc:4745
poly p_CopyPowerProduct0(const poly p, const number n, const ring r)
like p_Head, but with coefficient n
Definition: p_polys.cc:5044
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:1638
poly p_Homogen(poly p, int varnum, const ring r)
Definition: p_polys.cc:3335
static void p_ExpVectorCopy(poly d_p, poly s_p, const ring r)
Definition: p_polys.h:1313
poly p_Subst(poly p, int n, poly e, const ring r)
Definition: p_polys.cc:4023
static void p_LmDelete0(poly p, const ring r)
Definition: p_polys.h:733
long pLDeg1c_Deg(poly p, int *l, ring r)
Definition: p_polys.cc:941
static int p_Cmp(poly p1, poly p2, ring r)
Definition: p_polys.h:1735
BOOLEAN _p_LmTest(poly p, ring r, int level)
Definition: pDebug.cc:323
#define __pp_Mult_nn(p, n, r)
Definition: p_polys.h:1002
static void p_SetExpVL(poly p, int64 *ev, const ring r)
Definition: p_polys.h:1553
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:1329
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:841
poly p_CopyPowerProduct(const poly p, const ring r)
like p_Head, but with coefficient 1
Definition: p_polys.cc:5056
static void p_SetExpV(poly p, int *ev, const ring r)
Definition: p_polys.h:1544
void p_ShallowDelete(poly *p, const ring r)
static poly pp_mm_Mult(poly p, poly m, const ring r)
Definition: p_polys.h:1041
static poly pp_Mult_mm(poly p, poly m, const ring r)
Definition: p_polys.h:1031
static int p_LtCmpNoAbs(poly p, poly q, const ring r)
Definition: p_polys.h:1647
static void p_MemSub_NegWeightAdjust(poly p, const ring r)
Definition: p_polys.h:1302
poly pp_DivideM(poly a, poly b, const ring r)
Definition: p_polys.cc:1629
long p_WFirstTotalDegree(poly p, ring r)
Definition: p_polys.cc:596
int p_Weight(int c, const ring r)
Definition: p_polys.cc:705
static int p_Comp_k_n(poly a, poly b, int k, ring r)
Definition: p_polys.h:640
poly p_ISet(long i, const ring r)
returns the poly representing the integer i
Definition: p_polys.cc:1297
static int p_LtCmpOrdSgnEqP(poly p, poly q, const ring r)
Definition: p_polys.h:1711
void p_ContentForGB(poly p, const ring r)
Definition: p_polys.cc:2420
void p_Vec2Polys(poly v, poly **p, int *len, const ring r)
Definition: p_polys.cc:3703
poly p_DiffOp(poly a, poly b, BOOLEAN multiply, const ring r)
Definition: p_polys.cc:1969
static void p_SetCompP(poly p, int i, ring r)
Definition: p_polys.h:254
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:488
poly p_Jet(poly p, int m, const ring R)
Definition: p_polys.cc:4451
poly p_TakeOutComp1(poly *p, int k, const ring r)
Definition: p_polys.cc:3462
static void p_ExpVectorDiff(poly pr, poly p1, poly p2, const ring r)
Definition: p_polys.h:1474
const char * p_Read(const char *s, poly &p, const ring r)
Definition: p_polys.cc:1370
static long p_MinComp(poly p, ring lmRing, ring tailRing)
Definition: p_polys.h:313
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:4771
static long p_GetExpSum(poly p1, poly p2, int i, ring r)
Definition: p_polys.h:629
poly p_Power(poly p, int i, const ring r)
Definition: p_polys.cc:2193
poly p_Div_nn(poly p, const number n, const ring r)
Definition: p_polys.cc:1501
static poly p_mm_Mult(poly p, poly m, const ring r)
Definition: p_polys.h:1061
void p_Normalize(poly p, const ring r)
Definition: p_polys.cc:3879
void p_DeleteComp(poly *p, int k, const ring r)
Definition: p_polys.cc:3622
poly p_MDivide(poly a, poly b, const ring r)
Definition: p_polys.cc:1488
void p_Content(poly p, const ring r)
Definition: p_polys.cc:2291
void p_ProjectiveUnique(poly p, const ring r)
Definition: p_polys.cc:3208
void p_ContentRat(poly &ph, const ring r)
Definition: p_polys.cc:1740
void p_Norm(poly p1, const ring r)
Definition: p_polys.cc:3797
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
Definition: p_polys.h:247
poly p_Div_mm(poly p, const poly m, const ring r)
divide polynomial by monomial
Definition: p_polys.cc:1534
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:1138
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:1267
static long p_IncrExp(poly p, int v, ring r)
Definition: p_polys.h:591
int p_MinDeg(poly p, intvec *w, const ring R)
Definition: p_polys.cc:4513
static void p_ExpVectorSub(poly p1, poly p2, const ring r)
Definition: p_polys.h:1440
static unsigned long p_AddComp(poly p, unsigned long v, ring r)
Definition: p_polys.h:447
int p_MaxExpPerVar(poly p, int i, const ring r)
max exponent of variable x_i in p
Definition: p_polys.cc:5068
int p_Var(poly mi, const ring r)
Definition: p_polys.cc:4721
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:313
int p_Compare(const poly a, const poly b, const ring R)
Definition: p_polys.cc:4972
static void p_Setm(poly p, const ring r)
Definition: p_polys.h:233
#define p_SetmComp
Definition: p_polys.h:244
poly p_mInit(const char *s, BOOLEAN &ok, const ring r)
Definition: p_polys.cc:1442
void p_LmDeleteAndNextRat(poly *p, int ishift, ring r)
Definition: p_polys.cc:1696
static poly p_Copy_noCheck(poly p, const ring r)
returns a copy of p (without any additional testing)
Definition: p_polys.h:836
static number p_SetCoeff(poly p, number n, ring r)
Definition: p_polys.h:412
static poly p_SortMerge(poly p, const ring r, BOOLEAN revert=FALSE)
Definition: p_polys.h:1229
static poly p_LmShallowCopyDelete(poly p, const ring r)
Definition: p_polys.h:1393
static poly pReverse(poly p)
Definition: p_polys.h:335
static poly p_Merge_q(poly p, poly q, const ring r)
Definition: p_polys.h:1212
long pLDegb(poly p, int *l, ring r)
Definition: p_polys.cc:811
static void p_GetExpVL(poly p, int64 *ev, const ring r)
Definition: p_polys.h:1529
static int p_LtCmp(poly p, poly q, const ring r)
Definition: p_polys.h:1621
static BOOLEAN p_LmIsConstantComp(const poly p, const ring r)
Definition: p_polys.h:1006
static poly p_Head(const poly p, const ring r)
copy the (leading) term of p
Definition: p_polys.h:860
static int p_LmCmp(poly p, poly q, const ring r)
Definition: p_polys.h:1580
poly p_Series(int n, poly p, poly u, intvec *w, const ring R)
Definition: p_polys.cc:4563
long p_WTotaldegree(poly p, const ring r)
Definition: p_polys.cc:613
static BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a, poly b, unsigned long not_sev_b, const ring r)
Definition: p_polys.h:1937
long p_DegW(poly p, const int *w, const ring R)
Definition: p_polys.cc:690
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:469
static BOOLEAN p_LmIsConstant(const poly p, const ring r)
Definition: p_polys.h:1023
p_SetmProc p_GetSetmProc(const ring r)
Definition: p_polys.cc:560
static long p_MultExp(poly p, int v, long ee, ring r)
Definition: p_polys.h:621
static BOOLEAN p_LmDivisibleByNoComp(poly a, poly b, const ring r)
Definition: p_polys.h:1889
static BOOLEAN p_IsOne(const poly p, const ring R)
either poly(1) or gen(k)?!
Definition: p_polys.h:2018
static BOOLEAN p_IsConstant(const poly p, const ring r)
Definition: p_polys.h:2011
static void p_SetExpVLV(poly p, int64 *ev, int64 comp, const ring r)
Definition: p_polys.h:1564
BOOLEAN p_OneComp(poly p, const ring r)
return TRUE if all monoms have the same component
Definition: p_polys.cc:1208
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:1843
BOOLEAN p_CheckRing(ring r)
Definition: pDebug.cc:128
poly p_Cleardenom(poly p, const ring r)
Definition: p_polys.cc:2910
static BOOLEAN _p_LmDivisibleBy(poly a, poly b, const ring r)
Definition: p_polys.h:1877
static unsigned long p_GetTotalDegree(const unsigned long l, const ring r, const int number_of_exps)
Definition: p_polys.h:810
BOOLEAN p_LmCheckIsFromRing(poly p, ring r)
Definition: pDebug.cc:71
static poly p_New(const ring, omBin bin)
Definition: p_polys.h:664
void p_Split(poly p, poly *r)
Definition: p_polys.cc:1320
poly n_PermNumber(const number z, const int *par_perm, const int OldPar, const ring src, const ring dst)
Definition: p_polys.cc:4092
static poly p_GetExp_k_n(poly p, int l, int k, const ring r)
Definition: p_polys.h:1372
static BOOLEAN p_LmShortDivisibleByNoComp(poly a, unsigned long sev_a, poly b, unsigned long not_sev_b, const ring r)
Definition: p_polys.h:1957
static poly pp_Mult_nn(poly p, number n, const ring r)
Definition: p_polys.h:992
poly p_GetCoeffRat(poly p, int ishift, ring r)
Definition: p_polys.cc:1718
BOOLEAN p_VectorHasUnitB(poly p, int *k, const ring r)
Definition: p_polys.cc:3406
poly p_Vec2Poly(poly v, int k, const ring r)
Definition: p_polys.cc:3651
static BOOLEAN p_LmDivisibleBy(poly a, poly b, const ring r)
Definition: p_polys.h:1903
poly p_LcmRat(const poly a, const poly b, const long lCompM, const ring r)
Definition: p_polys.cc:1673
static BOOLEAN p_DivisibleBy(poly a, poly b, const ring r)
Definition: p_polys.h:1912
static BOOLEAN p_ExpVectorEqual(poly p1, poly p2, const ring r)
Definition: p_polys.h:1489
long pLDeg1_Totaldegree(poly p, int *l, ring r)
Definition: p_polys.cc:975
void p_SetModDeg(intvec *w, ring r)
Definition: p_polys.cc:3751
static poly p_ShallowCopyDelete(poly p, const ring r, omBin bin)
Definition: p_polys.h:928
static int64 p_GetExpVLV(poly p, int64 *ev, const ring r)
Definition: p_polys.h:1536
void p_TakeOutComp(poly *p, long comp, poly *q, int *lq, const ring r)
Definition: p_polys.cc:3574
static long p_MaxComp(poly p, ring lmRing, ring tailRing)
Definition: p_polys.h:292
static poly p_Mult_nn(poly p, number n, const ring r)
Definition: p_polys.h:958
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:901
BOOLEAN p_HasNotCFRing(poly p1, poly p2, const ring r)
Definition: p_polys.cc:1345
poly p_One(const ring r)
Definition: p_polys.cc:1313
static long p_DecrExp(poly p, int v, ring r)
Definition: p_polys.h:598
static int p_LtCmpOrdSgnDiffM(poly p, poly q, const ring r)
Definition: p_polys.h:1669
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:1773
void p_VectorHasUnit(poly p, int *k, int *len, const ring r)
Definition: p_polys.cc:3429
static unsigned pLength(poly a)
Definition: p_polys.h:191
static void p_GetExpV(poly p, int *ev, const ring r)
Definition: p_polys.h:1520
BOOLEAN p_CheckPolyRing(poly p, ring r)
Definition: pDebug.cc:112
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:1005
static long p_GetOrder(poly p, ring r)
Definition: p_polys.h:421
int p_IsUnivariate(poly p, const ring r)
return i, if poly depends only on var(i)
Definition: p_polys.cc:1247
poly p_NSet(number n, const ring r)
returns the poly representing the number n, destroys n
Definition: p_polys.cc:1469
static poly pp_Mult_qq(poly p, poly q, const ring r)
Definition: p_polys.h:1151
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:4195
static int p_LtCmpOrdSgnEqM(poly p, poly q, const ring r)
Definition: p_polys.h:1702
static poly p_LmFreeAndNext(poly p, ring)
Definition: p_polys.h:711
#define pDivAssume(x)
Definition: p_polys.h:1282
static poly p_Mult_mm(poly p, poly m, const ring r)
Definition: p_polys.h:1051
void p_Cleardenom_n(poly p, const ring r, number &c)
Definition: p_polys.cc:3019
long p_WDegree(poly p, const ring r)
Definition: p_polys.cc:714
long pLDeg1c(poly p, int *l, ring r)
Definition: p_polys.cc:877
poly p_Last(const poly a, int &l, const ring r)
Definition: p_polys.cc:4686
static void p_LmFree(poly p, ring)
Definition: p_polys.h:683
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:1070
static poly p_Plus_mm_Mult_qq(poly p, poly m, poly q, int &lp, int lq, const ring r)
Definition: p_polys.h:1183
void pEnlargeSet(poly **p, int length, int increment)
Definition: p_polys.cc:3774
static BOOLEAN p_IsUnit(const poly p, const ring r)
Definition: p_polys.h:2038
static poly p_Init(const ring r, omBin bin)
Definition: p_polys.h:1320
BOOLEAN p_IsHomogeneous(poly p, const ring r)
Definition: p_polys.cc:3384
poly p_Head0(const poly p, const ring r)
like p_Head, but allow NULL coeff
Definition: p_polys.cc:5062
static poly p_LmDeleteAndNext(poly p, const ring r)
Definition: p_polys.h:755
BOOLEAN pHaveCommonMonoms(poly p, poly q)
Definition: pDebug.cc:175
unsigned long p_GetShortExpVector(const poly a, const ring r)
Definition: p_polys.cc:4846
static poly pp_Mult_Coeff_mm_DivSelect(poly p, const poly m, const ring r)
Definition: p_polys.h:1090
poly pp_JetW(poly p, int m, int *w, const ring R)
Definition: p_polys.cc:4468
static BOOLEAN p_LmDivisibleByPart(poly a, poly b, const ring r, const int start, const int end)
Definition: p_polys.h:1868
long p_Deg(poly a, const ring r)
Definition: p_polys.cc:587
static poly p_SortAdd(poly p, const ring r, BOOLEAN revert=FALSE)
Definition: p_polys.h:1219
void p_SimpleContent(poly p, int s, const ring r)
Definition: p_polys.cc:2629
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition: p_polys.h:846
static long p_LDeg(const poly p, int *l, const ring r)
Definition: p_polys.h:381
number p_InitContent(poly ph, const ring r)
Definition: p_polys.cc:2700
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:3673
static long p_Totaldegree(poly p, const ring r)
Definition: p_polys.h:1507
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:1175
static BOOLEAN p_LmExpVectorAddIsOk(const poly p1, const poly p2, const ring r)
Definition: p_polys.h:2046
static int p_LtCmpOrdSgnDiffP(poly p, poly q, const ring r)
Definition: p_polys.h:1685
BOOLEAN _pp_Test(poly p, ring lmRing, ring tailRing, int level)
Definition: pDebug.cc:333
void p_Lcm(const poly a, const poly b, poly m, const ring r)
Definition: p_polys.cc:1651
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:162
#define __p_Mult_nn(p, n, r)
Definition: p_polys.h:971
poly p_JetW(poly p, int m, int *w, const ring R)
Definition: p_polys.cc:4495
static BOOLEAN p_IsConstantPoly(const poly p, const ring r)
Definition: p_polys.h:2025
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:4577
long pLDeg0c(poly p, int *l, ring r)
Definition: p_polys.cc:770
static void p_ExpVectorAddSub(poly p1, poly p2, poly p3, const ring r)
Definition: p_polys.h:1456
BOOLEAN rOrd_SetCompRequiresSetm(const ring r)
return TRUE if p_SetComp requires p_Setm
Definition: ring.cc:1993
void(* p_SetmProc)(poly p, const ring r)
Definition: ring.h:39
static BOOLEAN rIsPluralRing(const ring r)
we must always have this test!
Definition: ring.h:400
long(* pFDegProc)(poly p, ring r)
Definition: ring.h:38
long(* pLDegProc)(poly p, int *length, ring r)
Definition: ring.h:37
@ ro_syz
Definition: ring.h:60
@ ro_cp
Definition: ring.h:58
@ ro_wp_neg
Definition: ring.h:56
@ ro_am
Definition: ring.h:54
@ ro_syzcomp
Definition: ring.h:59
static BOOLEAN rIsNCRing(const ring r)
Definition: ring.h:421
#define rField_is_Ring(R)
Definition: ring.h:486
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:75