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