My Project
Loading...
Searching...
No Matches
p_polys.cc
Go to the documentation of this file.
1/****************************************
2* Computer Algebra System SINGULAR *
3****************************************/
4/***************************************************************
5 * File: p_polys.cc
6 * Purpose: implementation of ring independent poly procedures?
7 * Author: obachman (Olaf Bachmann)
8 * Created: 8/00
9 *******************************************************************/
10
11#include <ctype.h>
12
13#include "misc/auxiliary.h"
14
15#include "misc/options.h"
16#include "misc/intvec.h"
17
18
19#include "coeffs/longrat.h" // snumber is needed...
20#include "coeffs/numbers.h" // ndCopyMap
21
23
24#define TRANSEXT_PRIVATES
25
28
29#include "polys/weight.h"
30#include "polys/simpleideals.h"
31
32#include "ring.h"
33#include "p_polys.h"
34
38
39
40#ifdef HAVE_PLURAL
41#include "nc/nc.h"
42#include "nc/sca.h"
43#endif
44
45#ifdef HAVE_SHIFTBBA
46#include "polys/shiftop.h"
47#endif
48
49#include "clapsing.h"
50
51/*
52 * lift ideal with coeffs over Z (mod N) to Q via Farey
53 */
54poly p_Farey(poly p, number N, const ring r)
55{
56 poly h=p_Copy(p,r);
57 poly hh=h;
58 while(h!=NULL)
59 {
60 number c=pGetCoeff(h);
61 pSetCoeff0(h,n_Farey(c,N,r->cf));
62 n_Delete(&c,r->cf);
63 pIter(h);
64 }
65 while((hh!=NULL)&&(n_IsZero(pGetCoeff(hh),r->cf)))
66 {
67 p_LmDelete(&hh,r);
68 }
69 h=hh;
70 while((h!=NULL) && (pNext(h)!=NULL))
71 {
72 if(n_IsZero(pGetCoeff(pNext(h)),r->cf))
73 {
74 p_LmDelete(&pNext(h),r);
75 }
76 else pIter(h);
77 }
78 return hh;
79}
80/*2
81* xx,q: arrays of length 0..rl-1
82* xx[i]: SB mod q[i]
83* assume: char=0
84* assume: q[i]!=0
85* x: work space
86* destroys xx
87*/
88poly p_ChineseRemainder(poly *xx, number *x,number *q, int rl, CFArray &inv_cache,const ring R)
89{
90 poly r,h,hh;
91 int j;
92 poly res_p=NULL;
93 loop
94 {
95 /* search the lead term */
96 r=NULL;
97 for(j=rl-1;j>=0;j--)
98 {
99 h=xx[j];
100 if ((h!=NULL)
101 &&((r==NULL)||(p_LmCmp(r,h,R)==-1)))
102 r=h;
103 }
104 /* nothing found -> return */
105 if (r==NULL) break;
106 /* create the monomial in h */
107 h=p_Head(r,R);
108 /* collect the coeffs in x[..]*/
109 for(j=rl-1;j>=0;j--)
110 {
111 hh=xx[j];
112 if ((hh!=NULL) && (p_LmCmp(h,hh,R)==0))
113 {
114 x[j]=pGetCoeff(hh);
115 hh=p_LmFreeAndNext(hh,R);
116 xx[j]=hh;
117 }
118 else
119 x[j]=n_Init(0, R->cf);
120 }
121 number n=n_ChineseRemainderSym(x,q,rl,TRUE,inv_cache,R->cf);
122 for(j=rl-1;j>=0;j--)
123 {
124 x[j]=NULL; // n_Init(0...) takes no memory
125 }
126 if (n_IsZero(n,R->cf)) p_Delete(&h,R);
127 else
128 {
129 //Print("new mon:");pWrite(h);
130 p_SetCoeff(h,n,R);
131 pNext(h)=res_p;
132 res_p=h; // building res_p in reverse order!
133 }
134 }
135 res_p=pReverse(res_p);
136 p_Test(res_p, R);
137 return res_p;
138}
139
140/***************************************************************
141 *
142 * Completing what needs to be set for the monomial
143 *
144 ***************************************************************/
145// this is special for the syz stuff
149
151
152#ifndef SING_NDEBUG
153# define MYTEST 0
154#else /* ifndef SING_NDEBUG */
155# define MYTEST 0
156#endif /* ifndef SING_NDEBUG */
157
158void p_Setm_General(poly p, const ring r)
159{
161 int pos=0;
162 if (r->typ!=NULL)
163 {
164 loop
165 {
166 unsigned long ord=0;
167 sro_ord* o=&(r->typ[pos]);
168 switch(o->ord_typ)
169 {
170 case ro_dp:
171 {
172 int a,e;
173 a=o->data.dp.start;
174 e=o->data.dp.end;
175 for(int i=a;i<=e;i++) ord+=p_GetExp(p,i,r);
176 p->exp[o->data.dp.place]=ord;
177 break;
178 }
179 case ro_wp_neg:
180 ord=POLY_NEGWEIGHT_OFFSET; // no break;
181 case ro_wp:
182 {
183 int a,e;
184 a=o->data.wp.start;
185 e=o->data.wp.end;
186 int *w=o->data.wp.weights;
187#if 1
188 for(int i=a;i<=e;i++) ord+=((unsigned long)p_GetExp(p,i,r))*((unsigned long)w[i-a]);
189#else
190 long ai;
191 int ei,wi;
192 for(int i=a;i<=e;i++)
193 {
194 ei=p_GetExp(p,i,r);
195 wi=w[i-a];
196 ai=ei*wi;
197 if (ai/ei!=wi) pSetm_error=TRUE;
198 ord+=ai;
199 if (ord<ai) pSetm_error=TRUE;
200 }
201#endif
202 p->exp[o->data.wp.place]=ord;
203 break;
204 }
205 case ro_am:
206 {
208 const short a=o->data.am.start;
209 const short e=o->data.am.end;
210 const int * w=o->data.am.weights;
211#if 1
212 for(short i=a; i<=e; i++, w++)
213 ord += ((*w) * p_GetExp(p,i,r));
214#else
215 long ai;
216 int ei,wi;
217 for(short i=a;i<=e;i++)
218 {
219 ei=p_GetExp(p,i,r);
220 wi=w[i-a];
221 ai=ei*wi;
222 if (ai/ei!=wi) pSetm_error=TRUE;
223 ord += ai;
224 if (ord<ai) pSetm_error=TRUE;
225 }
226#endif
227 const int c = p_GetComp(p,r);
228
229 const short len_gen= o->data.am.len_gen;
230
231 if ((c > 0) && (c <= len_gen))
232 {
233 assume( w == o->data.am.weights_m );
234 assume( w[0] == len_gen );
235 ord += w[c];
236 }
237
238 p->exp[o->data.am.place] = ord;
239 break;
240 }
241 case ro_wp64:
242 {
243 int64 ord=0;
244 int a,e;
245 a=o->data.wp64.start;
246 e=o->data.wp64.end;
247 int64 *w=o->data.wp64.weights64;
248 int64 ei,wi,ai;
249 for(int i=a;i<=e;i++)
250 {
251 //Print("exp %d w %d \n",p_GetExp(p,i,r),(int)w[i-a]);
252 //ord+=((int64)p_GetExp(p,i,r))*w[i-a];
253 ei=(int64)p_GetExp(p,i,r);
254 wi=w[i-a];
255 ai=ei*wi;
256 if(ei!=0 && ai/ei!=wi)
257 {
259 #if SIZEOF_LONG == 4
260 Print("ai %lld, wi %lld\n",ai,wi);
261 #else
262 Print("ai %ld, wi %ld\n",ai,wi);
263 #endif
264 }
265 ord+=ai;
266 if (ord<ai)
267 {
269 #if SIZEOF_LONG == 4
270 Print("ai %lld, ord %lld\n",ai,ord);
271 #else
272 Print("ai %ld, ord %ld\n",ai,ord);
273 #endif
274 }
275 }
276 #if SIZEOF_LONG == 4
277 int64 mask=(int64)0x7fffffff;
278 long a_0=(long)(ord&mask); //2^31
279 long a_1=(long)(ord >>31 ); /*(ord/(mask+1));*/
280
281 //Print("mask: %x, ord: %d, a_0: %d, a_1: %d\n"
282 //,(int)mask,(int)ord,(int)a_0,(int)a_1);
283 //Print("mask: %d",mask);
284
285 p->exp[o->data.wp64.place]=a_1;
286 p->exp[o->data.wp64.place+1]=a_0;
287 #elif SIZEOF_LONG == 8
288 p->exp[o->data.wp64.place]=ord;
289 #endif
290// if(p_Setm_error) PrintS("***************************\n"
291// "***************************\n"
292// "**WARNING: overflow error**\n"
293// "***************************\n"
294// "***************************\n");
295 break;
296 }
297 case ro_cp:
298 {
299 int a,e;
300 a=o->data.cp.start;
301 e=o->data.cp.end;
302 int pl=o->data.cp.place;
303 for(int i=a;i<=e;i++) { p->exp[pl]=p_GetExp(p,i,r); pl++; }
304 break;
305 }
306 case ro_syzcomp:
307 {
308 long c=__p_GetComp(p,r);
309 long sc = c;
310 int* Components = (_componentsExternal ? _components :
311 o->data.syzcomp.Components);
312 long* ShiftedComponents = (_componentsExternal ? _componentsShifted:
313 o->data.syzcomp.ShiftedComponents);
314 if (ShiftedComponents != NULL)
315 {
316 assume(Components != NULL);
317 assume(c == 0 || Components[c] != 0);
318 sc = ShiftedComponents[Components[c]];
319 assume(c == 0 || sc != 0);
320 }
321 p->exp[o->data.syzcomp.place]=sc;
322 break;
323 }
324 case ro_syz:
325 {
326 const unsigned long c = __p_GetComp(p, r);
327 const short place = o->data.syz.place;
328 const int limit = o->data.syz.limit;
329
330 if (c > (unsigned long)limit)
331 p->exp[place] = o->data.syz.curr_index;
332 else if (c > 0)
333 {
334 assume( (1 <= c) && (c <= (unsigned long)limit) );
335 p->exp[place]= o->data.syz.syz_index[c];
336 }
337 else
338 {
339 assume(c == 0);
340 p->exp[place]= 0;
341 }
342 break;
343 }
344 // Prefix for Induced Schreyer ordering
345 case ro_isTemp: // Do nothing?? (to be removed into suffix later on...?)
346 {
347 assume(p != NULL);
348
349#ifndef SING_NDEBUG
350#if MYTEST
351 Print("p_Setm_General: ro_isTemp ord: pos: %d, p: ", pos); p_wrp(p, r);
352#endif
353#endif
354 int c = p_GetComp(p, r);
355
356 assume( c >= 0 );
357
358 // Let's simulate case ro_syz above....
359 // Should accumulate (by Suffix) and be a level indicator
360 const int* const pVarOffset = o->data.isTemp.pVarOffset;
361
362 assume( pVarOffset != NULL );
363
364 // TODO: Can this be done in the suffix???
365 for( int i = 1; i <= r->N; i++ ) // No v[0] here!!!
366 {
367 const int vo = pVarOffset[i];
368 if( vo != -1) // TODO: optimize: can be done once!
369 {
370 // Hans! Please don't break it again! p_SetExp(p, ..., r, vo) is correct:
371 p_SetExp(p, p_GetExp(p, i, r), r, vo); // copy put them verbatim
372 // Hans! Please don't break it again! p_GetExp(p, r, vo) is correct:
373 assume( p_GetExp(p, r, vo) == p_GetExp(p, i, r) ); // copy put them verbatim
374 }
375 }
376#ifndef SING_NDEBUG
377 for( int i = 1; i <= r->N; i++ ) // No v[0] here!!!
378 {
379 const int vo = pVarOffset[i];
380 if( vo != -1) // TODO: optimize: can be done once!
381 {
382 // Hans! Please don't break it again! p_GetExp(p, r, vo) is correct:
383 assume( p_GetExp(p, r, vo) == p_GetExp(p, i, r) ); // copy put them verbatim
384 }
385 }
386#if MYTEST
387// if( p->exp[o->data.isTemp.start] > 0 )
388 PrintS("after Values: "); p_wrp(p, r);
389#endif
390#endif
391 break;
392 }
393
394 // Suffix for Induced Schreyer ordering
395 case ro_is:
396 {
397#ifndef SING_NDEBUG
398#if MYTEST
399 Print("p_Setm_General: ro_is ord: pos: %d, p: ", pos); p_wrp(p, r);
400#endif
401#endif
402
403 assume(p != NULL);
404
405 int c = p_GetComp(p, r);
406
407 assume( c >= 0 );
408 const ideal F = o->data.is.F;
409 const int limit = o->data.is.limit;
410 assume( limit >= 0 );
411 const int start = o->data.is.start;
412
413 if( F != NULL && c > limit )
414 {
415#ifndef SING_NDEBUG
416#if MYTEST
417 Print("p_Setm_General: ro_is : in rSetm: pos: %d, c: %d > limit: %d\n", c, pos, limit);
418 PrintS("preComputed Values: ");
419 p_wrp(p, r);
420#endif
421#endif
422// if( c > limit ) // BUG???
423 p->exp[start] = 1;
424// else
425// p->exp[start] = 0;
426
427
428 c -= limit;
429 assume( c > 0 );
430 c--;
431
432 if( c >= IDELEMS(F) )
433 break;
434
435 assume( c < IDELEMS(F) ); // What about others???
436
437 const poly pp = F->m[c]; // get reference monomial!!!
438
439 if(pp == NULL)
440 break;
441
442 assume(pp != NULL);
443
444#ifndef SING_NDEBUG
445#if MYTEST
446 Print("Respective F[c - %d: %d] pp: ", limit, c);
447 p_wrp(pp, r);
448#endif
449#endif
450
451 const int end = o->data.is.end;
452 assume(start <= end);
453
454
455// const int st = o->data.isTemp.start;
456
457#ifndef SING_NDEBUG
458#if MYTEST
459 Print("p_Setm_General: is(-Temp-) :: c: %d, limit: %d, [st:%d] ===>>> %ld\n", c, limit, start, p->exp[start]);
460#endif
461#endif
462
463 // p_ExpVectorAdd(p, pp, r);
464
465 for( int i = start; i <= end; i++) // v[0] may be here...
466 p->exp[i] += pp->exp[i]; // !!!!!!!! ADD corresponding LT(F)
467
468 // p_MemAddAdjust(p, ri);
469 if (r->NegWeightL_Offset != NULL)
470 {
471 for (int i=r->NegWeightL_Size-1; i>=0; i--)
472 {
473 const int _i = r->NegWeightL_Offset[i];
474 if( start <= _i && _i <= end )
475 p->exp[_i] -= POLY_NEGWEIGHT_OFFSET;
476 }
477 }
478
479
480#ifndef SING_NDEBUG
481 const int* const pVarOffset = o->data.is.pVarOffset;
482
483 assume( pVarOffset != NULL );
484
485 for( int i = 1; i <= r->N; i++ ) // No v[0] here!!!
486 {
487 const int vo = pVarOffset[i];
488 if( vo != -1) // TODO: optimize: can be done once!
489 // Hans! Please don't break it again! p_GetExp(p/pp, r, vo) is correct:
490 assume( p_GetExp(p, r, vo) == (p_GetExp(p, i, r) + p_GetExp(pp, r, vo)) );
491 }
492 // TODO: how to check this for computed values???
493#if MYTEST
494 PrintS("Computed Values: "); p_wrp(p, r);
495#endif
496#endif
497 } else
498 {
499 p->exp[start] = 0; //!!!!????? where?????
500
501 const int* const pVarOffset = o->data.is.pVarOffset;
502
503 // What about v[0] - component: it will be added later by
504 // suffix!!!
505 // TODO: Test it!
506 const int vo = pVarOffset[0];
507 if( vo != -1 )
508 p->exp[vo] = c; // initial component v[0]!
509
510#ifndef SING_NDEBUG
511#if MYTEST
512 Print("ELSE p_Setm_General: ro_is :: c: %d <= limit: %d, vo: %d, exp: %d\n", c, limit, vo, p->exp[vo]);
513 p_wrp(p, r);
514#endif
515#endif
516 }
517
518 break;
519 }
520 default:
521 dReportError("wrong ord in rSetm:%d\n",o->ord_typ);
522 return;
523 }
524 pos++;
525 if (pos == r->OrdSize) return;
526 }
527 }
528}
529
530void p_Setm_Syz(poly p, ring r, int* Components, long* ShiftedComponents)
531{
532 _components = Components;
533 _componentsShifted = ShiftedComponents;
535 p_Setm_General(p, r);
537}
538
539// dummy for lp, ls, etc
540void p_Setm_Dummy(poly p, const ring r)
541{
543}
544
545// for dp, Dp, ds, etc
546void p_Setm_TotalDegree(poly p, const ring r)
547{
549 p->exp[r->pOrdIndex] = p_Totaldegree(p, r);
550}
551
552// for wp, Wp, ws, etc
553void p_Setm_WFirstTotalDegree(poly p, const ring r)
554{
556 p->exp[r->pOrdIndex] = p_WFirstTotalDegree(p, r);
557}
558
560{
561 // covers lp, rp, ls,
562 if (r->typ == NULL) return p_Setm_Dummy;
563
564 if (r->OrdSize == 1)
565 {
566 if (r->typ[0].ord_typ == ro_dp &&
567 r->typ[0].data.dp.start == 1 &&
568 r->typ[0].data.dp.end == r->N &&
569 r->typ[0].data.dp.place == r->pOrdIndex)
570 return p_Setm_TotalDegree;
571 if (r->typ[0].ord_typ == ro_wp &&
572 r->typ[0].data.wp.start == 1 &&
573 r->typ[0].data.wp.end == r->N &&
574 r->typ[0].data.wp.place == r->pOrdIndex &&
575 r->typ[0].data.wp.weights == r->firstwv)
577 }
578 return p_Setm_General;
579}
580
581
582/* -------------------------------------------------------------------*/
583/* several possibilities for pFDeg: the degree of the head term */
584
585/* compatible with ordering */
586long p_Deg(poly a, const ring r)
587{
588 p_LmCheckPolyRing(a, r);
589// assume(p_GetOrder(a, r) == p_WTotaldegree(a, r)); // WRONG assume!
590 return p_GetOrder(a, r);
591}
592
593// p_WTotalDegree for weighted orderings
594// whose first block covers all variables
595long p_WFirstTotalDegree(poly p, const ring r)
596{
597 int i;
598 long sum = 0;
599
600 for (i=1; i<= r->firstBlockEnds; i++)
601 {
602 sum += p_GetExp(p, i, r)*r->firstwv[i-1];
603 }
604 return sum;
605}
606
607/*2
608* compute the degree of the leading monomial of p
609* with respect to weights from the ordering
610* the ordering is not compatible with degree so do not use p->Order
611*/
612long p_WTotaldegree(poly p, const ring r)
613{
615 int i, k;
616 long j =0;
617
618 // iterate through each block:
619 for (i=0;r->order[i]!=0;i++)
620 {
621 int b0=r->block0[i];
622 int b1=r->block1[i];
623 switch(r->order[i])
624 {
625 case ringorder_M:
626 for (k=b0 /*r->block0[i]*/;k<=b1 /*r->block1[i]*/;k++)
627 { // in jedem block:
628 j+= p_GetExp(p,k,r)*r->wvhdl[i][k - b0 /*r->block0[i]*/]*r->OrdSgn;
629 }
630 break;
631 case ringorder_am:
632 b1=si_min(b1,r->N); /* no break, continue as ringorder_a*/
633 case ringorder_a:
634 for (k=b0 /*r->block0[i]*/;k<=b1 /*r->block1[i]*/;k++)
635 { // only one line
636 j+= p_GetExp(p,k,r)*r->wvhdl[i][k - b0 /*r->block0[i]*/];
637 }
638 return j*r->OrdSgn;
639 case ringorder_wp:
640 case ringorder_ws:
641 case ringorder_Wp:
642 case ringorder_Ws:
643 for (k=b0 /*r->block0[i]*/;k<=b1 /*r->block1[i]*/;k++)
644 { // in jedem block:
645 j+= p_GetExp(p,k,r)*r->wvhdl[i][k - b0 /*r->block0[i]*/];
646 }
647 break;
648 case ringorder_lp:
649 case ringorder_ls:
650 case ringorder_rs:
651 case ringorder_dp:
652 case ringorder_ds:
653 case ringorder_Dp:
654 case ringorder_Ds:
655 case ringorder_rp:
656 for (k=b0 /*r->block0[i]*/;k<=b1 /*r->block1[i]*/;k++)
657 {
658 j+= p_GetExp(p,k,r);
659 }
660 break;
661 case ringorder_a64:
662 {
663 int64* w=(int64*)r->wvhdl[i];
664 for (k=0;k<=(b1 /*r->block1[i]*/ - b0 /*r->block0[i]*/);k++)
665 {
666 //there should be added a line which checks if w[k]>2^31
667 j+= p_GetExp(p,k+1, r)*(long)w[k];
668 }
669 //break;
670 return j;
671 }
672 default:
673 #if 0
674 case ringorder_c: /* nothing to do*/
675 case ringorder_C: /* nothing to do*/
676 case ringorder_S: /* nothing to do*/
677 case ringorder_s: /* nothing to do*/
678 case ringorder_IS: /* nothing to do */
679 case ringorder_unspec: /* to make clang happy, does not occur*/
680 case ringorder_no: /* to make clang happy, does not occur*/
681 case ringorder_L: /* to make clang happy, does not occur*/
682 case ringorder_aa: /* ignored by p_WTotaldegree*/
683 #endif
684 break;
685 /* no default: all orderings covered */
686 }
687 }
688 return j;
689}
690
691long p_DegW(poly p, const int *w, const ring R)
692{
693 p_Test(p, R);
694 assume( w != NULL );
695 long r=-LONG_MAX;
696
697 while (p!=NULL)
698 {
699 long t=totaldegreeWecart_IV(p,R,w);
700 if (t>r) r=t;
701 pIter(p);
702 }
703 return r;
704}
705
706int p_Weight(int i, const ring r)
707{
708 if ((r->firstwv==NULL) || (i>r->firstBlockEnds))
709 {
710 return 1;
711 }
712 return r->firstwv[i-1];
713}
714
715long p_WDegree(poly p, const ring r)
716{
717 if (r->firstwv==NULL) return p_Totaldegree(p, r);
719 int i;
720 long j =0;
721
722 for(i=1;i<=r->firstBlockEnds;i++)
723 j+=p_GetExp(p, i, r)*r->firstwv[i-1];
724
725 for (;i<=rVar(r);i++)
726 j+=p_GetExp(p,i, r)*p_Weight(i, r);
727
728 return j;
729}
730
731
732/* ---------------------------------------------------------------------*/
733/* several possibilities for pLDeg: the maximal degree of a monomial in p*/
734/* compute in l also the pLength of p */
735
736/*2
737* compute the length of a polynomial (in l)
738* and the degree of the monomial with maximal degree: the last one
739*/
740long pLDeg0(poly p,int *l, const ring r)
741{
742 p_CheckPolyRing(p, r);
743 long unsigned k= p_GetComp(p, r);
744 int ll=1;
745
746 if (k > 0)
747 {
748 while ((pNext(p)!=NULL) && (__p_GetComp(pNext(p), r)==k))
749 {
750 pIter(p);
751 ll++;
752 }
753 }
754 else
755 {
756 while (pNext(p)!=NULL)
757 {
758 pIter(p);
759 ll++;
760 }
761 }
762 *l=ll;
763 return r->pFDeg(p, r);
764}
765
766/*2
767* compute the length of a polynomial (in l)
768* and the degree of the monomial with maximal degree: the last one
769* but search in all components before syzcomp
770*/
771long pLDeg0c(poly p,int *l, const ring r)
772{
773 assume(p!=NULL);
774 p_Test(p,r);
775 p_CheckPolyRing(p, r);
776 long o;
777 int ll=1;
778
779 if (! rIsSyzIndexRing(r))
780 {
781 while (pNext(p) != NULL)
782 {
783 pIter(p);
784 ll++;
785 }
786 o = r->pFDeg(p, r);
787 }
788 else
789 {
790 long unsigned curr_limit = rGetCurrSyzLimit(r);
791 poly pp = p;
792 while ((p=pNext(p))!=NULL)
793 {
794 if (__p_GetComp(p, r)<=curr_limit/*syzComp*/)
795 ll++;
796 else break;
797 pp = p;
798 }
799 p_Test(pp,r);
800 o = r->pFDeg(pp, r);
801 }
802 *l=ll;
803 return o;
804}
805
806/*2
807* compute the length of a polynomial (in l)
808* and the degree of the monomial with maximal degree: the first one
809* this works for the polynomial case with degree orderings
810* (both c,dp and dp,c)
811*/
812long pLDegb(poly p,int *l, const ring r)
813{
814 p_CheckPolyRing(p, r);
815 long unsigned k= p_GetComp(p, r);
816 long o = r->pFDeg(p, r);
817 int ll=1;
818
819 if (k != 0)
820 {
821 while (((p=pNext(p))!=NULL) && (__p_GetComp(p, r)==k))
822 {
823 ll++;
824 }
825 }
826 else
827 {
828 while ((p=pNext(p)) !=NULL)
829 {
830 ll++;
831 }
832 }
833 *l=ll;
834 return o;
835}
836
837/*2
838* compute the length of a polynomial (in l)
839* and the degree of the monomial with maximal degree:
840* this is NOT the last one, we have to look for it
841*/
842long pLDeg1(poly p,int *l, const ring r)
843{
844 p_CheckPolyRing(p, r);
845 long unsigned k= p_GetComp(p, r);
846 int ll=1;
847 long t,max;
848
849 max=r->pFDeg(p, r);
850 if (k > 0)
851 {
852 while (((p=pNext(p))!=NULL) && (__p_GetComp(p, r)==k))
853 {
854 t=r->pFDeg(p, r);
855 if (t>max) max=t;
856 ll++;
857 }
858 }
859 else
860 {
861 while ((p=pNext(p))!=NULL)
862 {
863 t=r->pFDeg(p, r);
864 if (t>max) max=t;
865 ll++;
866 }
867 }
868 *l=ll;
869 return max;
870}
871
872/*2
873* compute the length of a polynomial (in l)
874* and the degree of the monomial with maximal degree:
875* this is NOT the last one, we have to look for it
876* in all components
877*/
878long pLDeg1c(poly p,int *l, const ring r)
879{
880 p_CheckPolyRing(p, r);
881 int ll=1;
882 long t,max;
883
884 max=r->pFDeg(p, r);
885 if (rIsSyzIndexRing(r))
886 {
887 long unsigned limit = rGetCurrSyzLimit(r);
888 while ((p=pNext(p))!=NULL)
889 {
890 if (__p_GetComp(p, r)<=limit)
891 {
892 if ((t=r->pFDeg(p, r))>max) max=t;
893 ll++;
894 }
895 else break;
896 }
897 }
898 else
899 {
900 while ((p=pNext(p))!=NULL)
901 {
902 if ((t=r->pFDeg(p, r))>max) max=t;
903 ll++;
904 }
905 }
906 *l=ll;
907 return max;
908}
909
910// like pLDeg1, only pFDeg == pDeg
911long pLDeg1_Deg(poly p,int *l, const ring r)
912{
913 assume(r->pFDeg == p_Deg);
914 p_CheckPolyRing(p, r);
915 long unsigned k= p_GetComp(p, r);
916 int ll=1;
917 long t,max;
918
919 max=p_GetOrder(p, r);
920 if (k > 0)
921 {
922 while (((p=pNext(p))!=NULL) && (__p_GetComp(p, r)==k))
923 {
924 t=p_GetOrder(p, r);
925 if (t>max) max=t;
926 ll++;
927 }
928 }
929 else
930 {
931 while ((p=pNext(p))!=NULL)
932 {
933 t=p_GetOrder(p, r);
934 if (t>max) max=t;
935 ll++;
936 }
937 }
938 *l=ll;
939 return max;
940}
941
942long pLDeg1c_Deg(poly p,int *l, const ring r)
943{
944 assume(r->pFDeg == p_Deg);
945 p_CheckPolyRing(p, r);
946 int ll=1;
947 long t,max;
948
949 max=p_GetOrder(p, r);
950 if (rIsSyzIndexRing(r))
951 {
952 long unsigned limit = rGetCurrSyzLimit(r);
953 while ((p=pNext(p))!=NULL)
954 {
955 if (__p_GetComp(p, r)<=limit)
956 {
957 if ((t=p_GetOrder(p, r))>max) max=t;
958 ll++;
959 }
960 else break;
961 }
962 }
963 else
964 {
965 while ((p=pNext(p))!=NULL)
966 {
967 if ((t=p_GetOrder(p, r))>max) max=t;
968 ll++;
969 }
970 }
971 *l=ll;
972 return max;
973}
974
975// like pLDeg1, only pFDeg == pTotoalDegree
976long pLDeg1_Totaldegree(poly p,int *l, const ring r)
977{
978 p_CheckPolyRing(p, r);
979 long unsigned k= p_GetComp(p, r);
980 int ll=1;
981 long t,max;
982
983 max=p_Totaldegree(p, r);
984 if (k > 0)
985 {
986 while (((p=pNext(p))!=NULL) && (__p_GetComp(p, r)==k))
987 {
988 t=p_Totaldegree(p, r);
989 if (t>max) max=t;
990 ll++;
991 }
992 }
993 else
994 {
995 while ((p=pNext(p))!=NULL)
996 {
997 t=p_Totaldegree(p, r);
998 if (t>max) max=t;
999 ll++;
1000 }
1001 }
1002 *l=ll;
1003 return max;
1004}
1005
1006long pLDeg1c_Totaldegree(poly p,int *l, const ring r)
1007{
1008 p_CheckPolyRing(p, r);
1009 int ll=1;
1010 long t,max;
1011
1012 max=p_Totaldegree(p, r);
1013 if (rIsSyzIndexRing(r))
1014 {
1015 long unsigned limit = rGetCurrSyzLimit(r);
1016 while ((p=pNext(p))!=NULL)
1017 {
1018 if (__p_GetComp(p, r)<=limit)
1019 {
1020 if ((t=p_Totaldegree(p, r))>max) max=t;
1021 ll++;
1022 }
1023 else break;
1024 }
1025 }
1026 else
1027 {
1028 while ((p=pNext(p))!=NULL)
1029 {
1030 if ((t=p_Totaldegree(p, r))>max) max=t;
1031 ll++;
1032 }
1033 }
1034 *l=ll;
1035 return max;
1036}
1037
1038// like pLDeg1, only pFDeg == p_WFirstTotalDegree
1039long pLDeg1_WFirstTotalDegree(poly p,int *l, const ring r)
1040{
1041 p_CheckPolyRing(p, r);
1042 long unsigned k= p_GetComp(p, r);
1043 int ll=1;
1044 long t,max;
1045
1047 if (k > 0)
1048 {
1049 while (((p=pNext(p))!=NULL) && (__p_GetComp(p, r)==k))
1050 {
1051 t=p_WFirstTotalDegree(p, r);
1052 if (t>max) max=t;
1053 ll++;
1054 }
1055 }
1056 else
1057 {
1058 while ((p=pNext(p))!=NULL)
1059 {
1060 t=p_WFirstTotalDegree(p, r);
1061 if (t>max) max=t;
1062 ll++;
1063 }
1064 }
1065 *l=ll;
1066 return max;
1067}
1068
1069long pLDeg1c_WFirstTotalDegree(poly p,int *l, const ring r)
1070{
1071 p_CheckPolyRing(p, r);
1072 int ll=1;
1073 long t,max;
1074
1076 if (rIsSyzIndexRing(r))
1077 {
1078 long unsigned limit = rGetCurrSyzLimit(r);
1079 while ((p=pNext(p))!=NULL)
1080 {
1081 if (__p_GetComp(p, r)<=limit)
1082 {
1083 if ((t=p_Totaldegree(p, r))>max) max=t;
1084 ll++;
1085 }
1086 else break;
1087 }
1088 }
1089 else
1090 {
1091 while ((p=pNext(p))!=NULL)
1092 {
1093 if ((t=p_Totaldegree(p, r))>max) max=t;
1094 ll++;
1095 }
1096 }
1097 *l=ll;
1098 return max;
1099}
1100
1101/***************************************************************
1102 *
1103 * Maximal Exponent business
1104 *
1105 ***************************************************************/
1106
1107static inline unsigned long
1108p_GetMaxExpL2(unsigned long l1, unsigned long l2, const ring r,
1109 unsigned long number_of_exp)
1110{
1111 const unsigned long bitmask = r->bitmask;
1112 unsigned long ml1 = l1 & bitmask;
1113 unsigned long ml2 = l2 & bitmask;
1114 unsigned long max = (ml1 > ml2 ? ml1 : ml2);
1115 unsigned long j = number_of_exp - 1;
1116
1117 if (j > 0)
1118 {
1119 unsigned long mask = bitmask << r->BitsPerExp;
1120 while (1)
1121 {
1122 ml1 = l1 & mask;
1123 ml2 = l2 & mask;
1124 max |= ((ml1 > ml2 ? ml1 : ml2) & mask);
1125 j--;
1126 if (j == 0) break;
1127 mask = mask << r->BitsPerExp;
1128 }
1129 }
1130 return max;
1131}
1132
1133static inline unsigned long
1134p_GetMaxExpL2(unsigned long l1, unsigned long l2, const ring r)
1135{
1136 return p_GetMaxExpL2(l1, l2, r, r->ExpPerLong);
1137}
1138
1139poly p_GetMaxExpP(poly p, const ring r)
1140{
1141 p_CheckPolyRing(p, r);
1142 if (p == NULL) return p_Init(r);
1143 poly max = p_LmInit(p, r);
1144 pIter(p);
1145 if (p == NULL) return max;
1146 int i, offset;
1147 unsigned long l_p, l_max;
1148 unsigned long divmask = r->divmask;
1149
1150 do
1151 {
1152 offset = r->VarL_Offset[0];
1153 l_p = p->exp[offset];
1154 l_max = max->exp[offset];
1155 // do the divisibility trick to find out whether l has an exponent
1156 if (l_p > l_max ||
1157 (((l_max & divmask) ^ (l_p & divmask)) != ((l_max-l_p) & divmask)))
1158 max->exp[offset] = p_GetMaxExpL2(l_max, l_p, r);
1159
1160 for (i=1; i<r->VarL_Size; i++)
1161 {
1162 offset = r->VarL_Offset[i];
1163 l_p = p->exp[offset];
1164 l_max = max->exp[offset];
1165 // do the divisibility trick to find out whether l has an exponent
1166 if (l_p > l_max ||
1167 (((l_max & divmask) ^ (l_p & divmask)) != ((l_max-l_p) & divmask)))
1168 max->exp[offset] = p_GetMaxExpL2(l_max, l_p, r);
1169 }
1170 pIter(p);
1171 }
1172 while (p != NULL);
1173 return max;
1174}
1175
1176unsigned long p_GetMaxExpL(poly p, const ring r, unsigned long l_max)
1177{
1178 unsigned long l_p, divmask = r->divmask;
1179 int i;
1180
1181 while (p != NULL)
1182 {
1183 l_p = p->exp[r->VarL_Offset[0]];
1184 if (l_p > l_max ||
1185 (((l_max & divmask) ^ (l_p & divmask)) != ((l_max-l_p) & divmask)))
1186 l_max = p_GetMaxExpL2(l_max, l_p, r);
1187 for (i=1; i<r->VarL_Size; i++)
1188 {
1189 l_p = p->exp[r->VarL_Offset[i]];
1190 // do the divisibility trick to find out whether l has an exponent
1191 if (l_p > l_max ||
1192 (((l_max & divmask) ^ (l_p & divmask)) != ((l_max-l_p) & divmask)))
1193 l_max = p_GetMaxExpL2(l_max, l_p, r);
1194 }
1195 pIter(p);
1196 }
1197 return l_max;
1198}
1199
1200
1201
1202
1203/***************************************************************
1204 *
1205 * Misc things
1206 *
1207 ***************************************************************/
1208// returns TRUE, if all monoms have the same component
1209BOOLEAN p_OneComp(poly p, const ring r)
1210{
1211 if(p!=NULL)
1212 {
1213 long i = p_GetComp(p, r);
1214 while (pNext(p)!=NULL)
1215 {
1216 pIter(p);
1217 if(i != p_GetComp(p, r)) return FALSE;
1218 }
1219 }
1220 return TRUE;
1221}
1222
1223/*2
1224*test if a monomial /head term is a pure power,
1225* i.e. depends on only one variable
1226*/
1227int p_IsPurePower(const poly p, const ring r)
1228{
1229 int i,k=0;
1230
1231 for (i=r->N;i;i--)
1232 {
1233 if (p_GetExp(p,i, r)!=0)
1234 {
1235 if(k!=0) return 0;
1236 k=i;
1237 }
1238 }
1239 return k;
1240}
1241
1242/*2
1243*test if a polynomial is univariate
1244* return -1 for constant,
1245* 0 for not univariate,s
1246* i if dep. on var(i)
1247*/
1248int p_IsUnivariate(poly p, const ring r)
1249{
1250 int i,k=-1;
1251
1252 while (p!=NULL)
1253 {
1254 for (i=r->N;i;i--)
1255 {
1256 if (p_GetExp(p,i, r)!=0)
1257 {
1258 if((k!=-1)&&(k!=i)) return 0;
1259 k=i;
1260 }
1261 }
1262 pIter(p);
1263 }
1264 return k;
1265}
1266
1267// set entry e[i] to 1 if var(i) occurs in p, ignore var(j) if e[j]>0
1268int p_GetVariables(poly p, int * e, const ring r)
1269{
1270 int i;
1271 int n=0;
1272 while(p!=NULL)
1273 {
1274 n=0;
1275 for(i=r->N; i>0; i--)
1276 {
1277 if(e[i]==0)
1278 {
1279 if (p_GetExp(p,i,r)>0)
1280 {
1281 e[i]=1;
1282 n++;
1283 }
1284 }
1285 else
1286 n++;
1287 }
1288 if (n==r->N) break;
1289 pIter(p);
1290 }
1291 return n;
1292}
1293
1294
1295/*2
1296* returns a polynomial representing the integer i
1297*/
1298poly p_ISet(long i, const ring r)
1299{
1300 poly rc = NULL;
1301 if (i!=0)
1302 {
1303 rc = p_Init(r);
1304 pSetCoeff0(rc,n_Init(i,r->cf));
1305 if (n_IsZero(pGetCoeff(rc),r->cf))
1306 p_LmDelete(&rc,r);
1307 }
1308 return rc;
1309}
1310
1311/*2
1312* an optimized version of p_ISet for the special case 1
1313*/
1314poly p_One(const ring r)
1315{
1316 poly rc = p_Init(r);
1317 pSetCoeff0(rc,n_Init(1,r->cf));
1318 return rc;
1319}
1320
1321void p_Split(poly p, poly *h)
1322{
1323 *h=pNext(p);
1324 pNext(p)=NULL;
1325}
1326
1327/*2
1328* pair has no common factor ? or is no polynomial
1329*/
1330BOOLEAN p_HasNotCF(poly p1, poly p2, const ring r)
1331{
1332
1333 if (p_GetComp(p1,r) > 0 || p_GetComp(p2,r) > 0)
1334 return FALSE;
1335 int i = rVar(r);
1336 loop
1337 {
1338 if ((p_GetExp(p1, i, r) > 0) && (p_GetExp(p2, i, r) > 0))
1339 return FALSE;
1340 i--;
1341 if (i == 0)
1342 return TRUE;
1343 }
1344}
1345
1346BOOLEAN p_HasNotCFRing(poly p1, poly p2, const ring r)
1347{
1348
1349 if (p_GetComp(p1,r) > 0 || p_GetComp(p2,r) > 0)
1350 return FALSE;
1351 int i = rVar(r);
1352 loop
1353 {
1354 if ((p_GetExp(p1, i, r) > 0) && (p_GetExp(p2, i, r) > 0))
1355 return FALSE;
1356 i--;
1357 if (i == 0) {
1358 if (n_DivBy(pGetCoeff(p1), pGetCoeff(p2), r->cf) ||
1359 n_DivBy(pGetCoeff(p2), pGetCoeff(p1), r->cf)) {
1360 return FALSE;
1361 } else {
1362 return TRUE;
1363 }
1364 }
1365 }
1366}
1367
1368/*2
1369* convert monomial given as string to poly, e.g. 1x3y5z
1370*/
1371const char * p_Read(const char *st, poly &rc, const ring r)
1372{
1373 if (r==NULL) { rc=NULL;return st;}
1374 int i,j;
1375 rc = p_Init(r);
1376 const char *s = n_Read(st,&(p_GetCoeff(rc, r)),r->cf);
1377 if (s==st)
1378 /* i.e. it does not start with a coeff: test if it is a ringvar*/
1379 {
1380 j = r_IsRingVar(s,r->names,r->N);
1381 if (j >= 0)
1382 {
1383 p_IncrExp(rc,1+j,r);
1384 while (*s!='\0') s++;
1385 goto done;
1386 }
1387 }
1388 while (*s!='\0')
1389 {
1390 char ss[2];
1391 ss[0] = *s++;
1392 ss[1] = '\0';
1393 j = r_IsRingVar(ss,r->names,r->N);
1394 if (j >= 0)
1395 {
1396 const char *s_save=s;
1397 s = eati(s,&i);
1398 if (((unsigned long)i) > r->bitmask/2)
1399 {
1400 // exponent to large: it is not a monomial
1401 p_LmDelete(&rc,r);
1402 return s_save;
1403 }
1404 p_AddExp(rc,1+j, (long)i, r);
1405 }
1406 else
1407 {
1408 // 1st char of is not a varname
1409 // We return the parsed polynomial nevertheless. This is needed when
1410 // we are parsing coefficients in a rational function field.
1411 s--;
1412 break;
1413 }
1414 }
1415done:
1416 if (n_IsZero(pGetCoeff(rc),r->cf)) p_LmDelete(&rc,r);
1417 else
1418 {
1419#ifdef HAVE_PLURAL
1420 // in super-commutative ring
1421 // squares of anti-commutative variables are zeroes!
1422 if(rIsSCA(r))
1423 {
1424 const unsigned int iFirstAltVar = scaFirstAltVar(r);
1425 const unsigned int iLastAltVar = scaLastAltVar(r);
1426
1427 assume(rc != NULL);
1428
1429 for(unsigned int k = iFirstAltVar; k <= iLastAltVar; k++)
1430 if( p_GetExp(rc, k, r) > 1 )
1431 {
1432 p_LmDelete(&rc, r);
1433 goto finish;
1434 }
1435 }
1436#endif
1437
1438 p_Setm(rc,r);
1439 }
1440finish:
1441 return s;
1442}
1443poly p_mInit(const char *st, BOOLEAN &ok, const ring r)
1444{
1445 poly p;
1446 char *sst=(char*)st;
1447 BOOLEAN neg=FALSE;
1448 if (sst[0]=='-') { neg=TRUE; sst=sst+1; }
1449 const char *s=p_Read(sst,p,r);
1450 if (*s!='\0')
1451 {
1452 if ((s!=sst)&&isdigit(sst[0]))
1453 {
1455 }
1456 ok=FALSE;
1457 if (p!=NULL)
1458 {
1459 if (pGetCoeff(p)==NULL) p_LmFree(p,r);
1460 else p_LmDelete(p,r);
1461 }
1462 return NULL;
1463 }
1464 p_Test(p,r);
1465 ok=!errorreported;
1466 if (neg) p=p_Neg(p,r);
1467 return p;
1468}
1469
1470/*2
1471* returns a polynomial representing the number n
1472* destroys n
1473*/
1474poly p_NSet(number n, const ring r)
1475{
1476 if (n_IsZero(n,r->cf))
1477 {
1478 n_Delete(&n, r->cf);
1479 return NULL;
1480 }
1481 else
1482 {
1483 poly rc = p_Init(r);
1484 pSetCoeff0(rc,n);
1485 return rc;
1486 }
1487}
1488/*2
1489* assumes that LM(a) = LM(b)*m, for some monomial m,
1490* returns the multiplicant m,
1491* leaves a and b unmodified
1492*/
1493poly p_MDivide(poly a, poly b, const ring r)
1494{
1495 assume((p_GetComp(a,r)==p_GetComp(b,r)) || (p_GetComp(b,r)==0));
1496 int i;
1497 poly result = p_Init(r);
1498
1499 for(i=(int)r->N; i; i--)
1500 p_SetExp(result,i, p_GetExp(a,i,r)- p_GetExp(b,i,r),r);
1501 p_SetComp(result, p_GetComp(a,r) - p_GetComp(b,r),r);
1502 p_Setm(result,r);
1503 return result;
1504}
1505
1506poly p_Div_nn(poly p, const number n, const ring r)
1507{
1508 pAssume(!n_IsZero(n,r->cf));
1509 p_Test(p, r);
1510 poly result = p;
1511 poly prev = NULL;
1512 if (!n_IsOne(n,r->cf))
1513 {
1514 while (p!=NULL)
1515 {
1516 number nc = n_Div(pGetCoeff(p),n,r->cf);
1517 if (!n_IsZero(nc,r->cf))
1518 {
1519 p_SetCoeff(p,nc,r);
1520 prev=p;
1521 pIter(p);
1522 }
1523 else
1524 {
1525 if (prev==NULL)
1526 {
1527 p_LmDelete(&result,r);
1528 p=result;
1529 }
1530 else
1531 {
1532 p_LmDelete(&pNext(prev),r);
1533 p=pNext(prev);
1534 }
1535 }
1536 }
1537 p_Test(result,r);
1538 }
1539 return(result);
1540}
1541
1542poly p_Div_mm(poly p, const poly m, const ring r)
1543{
1544 p_Test(p, r);
1545 p_Test(m, r);
1546 poly result = p;
1547 poly prev = NULL;
1548 number n=pGetCoeff(m);
1549 while (p!=NULL)
1550 {
1551 number nc = n_Div(pGetCoeff(p),n,r->cf);
1552 n_Normalize(nc,r->cf);
1553 if (!n_IsZero(nc,r->cf))
1554 {
1555 p_SetCoeff(p,nc,r);
1556 prev=p;
1557 p_ExpVectorSub(p,m,r);
1558 pIter(p);
1559 }
1560 else
1561 {
1562 if (prev==NULL)
1563 {
1564 p_LmDelete(&result,r);
1565 p=result;
1566 }
1567 else
1568 {
1569 p_LmDelete(&pNext(prev),r);
1570 p=pNext(prev);
1571 }
1572 }
1573 }
1574 p_Test(result,r);
1575 return(result);
1576}
1577
1578/*2
1579* divides a by the monomial b, ignores monomials which are not divisible
1580* assumes that b is not NULL, destroys b
1581*/
1582poly p_DivideM(poly a, poly b, const ring r)
1583{
1584 if (a==NULL) { p_Delete(&b,r); return NULL; }
1585 poly result=a;
1586
1587 if(!p_IsConstant(b,r))
1588 {
1589 if (rIsNCRing(r))
1590 {
1591 WerrorS("p_DivideM not implemented for non-commuative rings");
1592 return NULL;
1593 }
1594 poly prev=NULL;
1595 while (a!=NULL)
1596 {
1597 if (p_DivisibleBy(b,a,r))
1598 {
1599 p_ExpVectorSub(a,b,r);
1600 prev=a;
1601 pIter(a);
1602 }
1603 else
1604 {
1605 if (prev==NULL)
1606 {
1607 p_LmDelete(&result,r);
1608 a=result;
1609 }
1610 else
1611 {
1612 p_LmDelete(&pNext(prev),r);
1613 a=pNext(prev);
1614 }
1615 }
1616 }
1617 }
1618 if (result!=NULL)
1619 {
1620 number inv=pGetCoeff(b);
1621 //if ((!rField_is_Ring(r)) || n_IsUnit(inv,r->cf))
1622 if (rField_is_Zp(r))
1623 {
1624 inv = n_Invers(inv,r->cf);
1625 __p_Mult_nn(result,inv,r);
1626 n_Delete(&inv, r->cf);
1627 }
1628 else
1629 {
1630 result = p_Div_nn(result,inv,r);
1631 }
1632 }
1633 p_Delete(&b, r);
1634 return result;
1635}
1636
1637poly pp_DivideM(poly a, poly b, const ring r)
1638{
1639 if (a==NULL) { return NULL; }
1640 // TODO: better implementation without copying a,b
1641 return p_DivideM(p_Copy(a,r),p_Head(b,r),r);
1642}
1643
1644#ifdef HAVE_RINGS
1645/* TRUE iff LT(f) | LT(g) */
1646BOOLEAN p_DivisibleByRingCase(poly f, poly g, const ring r)
1647{
1648 int exponent;
1649 for(int i = (int)rVar(r); i>0; i--)
1650 {
1651 exponent = p_GetExp(g, i, r) - p_GetExp(f, i, r);
1652 if (exponent < 0) return FALSE;
1653 }
1654 return n_DivBy(pGetCoeff(g), pGetCoeff(f), r->cf);
1655}
1656#endif
1657
1658// returns the LCM of the head terms of a and b in *m
1659void p_Lcm(const poly a, const poly b, poly m, const ring r)
1660{
1661 for (int i=r->N; i; --i)
1662 p_SetExp(m,i, si_max( p_GetExp(a,i,r), p_GetExp(b,i,r)),r);
1663
1664 p_SetComp(m, si_max(p_GetComp(a,r), p_GetComp(b,r)),r);
1665 /* Don't do a pSetm here, otherwise hres/lres chockes */
1666}
1667
1668poly p_Lcm(const poly a, const poly b, const ring r)
1669{
1670 poly m=p_Init(r);
1671 p_Lcm(a, b, m, r);
1672 p_Setm(m,r);
1673 return(m);
1674}
1675
1676#ifdef HAVE_RATGRING
1677/*2
1678* returns the rational LCM of the head terms of a and b
1679* without coefficient!!!
1680*/
1681poly p_LcmRat(const poly a, const poly b, const long lCompM, const ring r)
1682{
1683 poly m = // p_One( r);
1684 p_Init(r);
1685
1686// const int (currRing->N) = r->N;
1687
1688 // for (int i = (currRing->N); i>=r->real_var_start; i--)
1689 for (int i = r->real_var_end; i>=r->real_var_start; i--)
1690 {
1691 const int lExpA = p_GetExp (a, i, r);
1692 const int lExpB = p_GetExp (b, i, r);
1693
1694 p_SetExp (m, i, si_max(lExpA, lExpB), r);
1695 }
1696
1697 p_SetComp (m, lCompM, r);
1698 p_Setm(m,r);
1699 p_GetCoeff(m, r)=NULL;
1700
1701 return(m);
1702};
1703
1704void p_LmDeleteAndNextRat(poly *p, int ishift, ring r)
1705{
1706 /* modifies p*/
1707 // Print("start: "); Print(" "); p_wrp(*p,r);
1708 p_LmCheckPolyRing2(*p, r);
1709 poly q = p_Head(*p,r);
1710 const long cmp = p_GetComp(*p, r);
1711 while ( ( (*p)!=NULL ) && ( p_Comp_k_n(*p, q, ishift+1, r) ) && (p_GetComp(*p, r) == cmp) )
1712 {
1713 p_LmDelete(p,r);
1714 // Print("while: ");p_wrp(*p,r);Print(" ");
1715 }
1716 // p_wrp(*p,r);Print(" ");
1717 // PrintS("end\n");
1718 p_LmDelete(&q,r);
1719}
1720
1721
1722/* returns x-coeff of p, i.e. a poly in x, s.t. corresponding xd-monomials
1723have the same D-part and the component 0
1724does not destroy p
1725*/
1726poly p_GetCoeffRat(poly p, int ishift, ring r)
1727{
1728 poly q = pNext(p);
1729 poly res; // = p_Head(p,r);
1730 res = p_GetExp_k_n(p, ishift+1, r->N, r); // does pSetm internally
1731 p_SetCoeff(res,n_Copy(p_GetCoeff(p,r),r),r);
1732 poly s;
1733 long cmp = p_GetComp(p, r);
1734 while ( (q!= NULL) && (p_Comp_k_n(p, q, ishift+1, r)) && (p_GetComp(q, r) == cmp) )
1735 {
1736 s = p_GetExp_k_n(q, ishift+1, r->N, r);
1737 p_SetCoeff(s,n_Copy(p_GetCoeff(q,r),r),r);
1738 res = p_Add_q(res,s,r);
1739 q = pNext(q);
1740 }
1741 cmp = 0;
1742 p_SetCompP(res,cmp,r);
1743 return res;
1744}
1745
1746
1747
1748void p_ContentRat(poly &ph, const ring r)
1749// changes ph
1750// for rat coefficients in K(x1,..xN)
1751{
1752 // init array of RatLeadCoeffs
1753 // poly p_GetCoeffRat(poly p, int ishift, ring r);
1754
1755 int len=pLength(ph);
1756 poly *C = (poly *)omAlloc0((len+1)*sizeof(poly)); //rat coeffs
1757 poly *LM = (poly *)omAlloc0((len+1)*sizeof(poly)); // rat lead terms
1758 int *D = (int *)omAlloc0((len+1)*sizeof(int)); //degrees of coeffs
1759 int *L = (int *)omAlloc0((len+1)*sizeof(int)); //lengths of coeffs
1760 int k = 0;
1761 poly p = p_Copy(ph, r); // ph will be needed below
1762 int mintdeg = p_Totaldegree(p, r);
1763 int minlen = len;
1764 int dd = 0; int i;
1765 int HasConstantCoef = 0;
1766 int is = r->real_var_start - 1;
1767 while (p!=NULL)
1768 {
1769 LM[k] = p_GetExp_k_n(p,1,is, r); // need LmRat instead of p_HeadRat(p, is, currRing); !
1770 C[k] = p_GetCoeffRat(p, is, r);
1771 D[k] = p_Totaldegree(C[k], r);
1772 mintdeg = si_min(mintdeg,D[k]);
1773 L[k] = pLength(C[k]);
1774 minlen = si_min(minlen,L[k]);
1775 if (p_IsConstant(C[k], r))
1776 {
1777 // C[k] = const, so the content will be numerical
1778 HasConstantCoef = 1;
1779 // smth like goto cleanup and return(pContent(p));
1780 }
1781 p_LmDeleteAndNextRat(&p, is, r);
1782 k++;
1783 }
1784
1785 // look for 1 element of minimal degree and of minimal length
1786 k--;
1787 poly d;
1788 int mindeglen = len;
1789 if (k<=0) // this poly is not a ratgring poly -> pContent
1790 {
1791 p_Delete(&C[0], r);
1792 p_Delete(&LM[0], r);
1793 p_ContentForGB(ph, r);
1794 goto cleanup;
1795 }
1796
1797 int pmindeglen;
1798 for(i=0; i<=k; i++)
1799 {
1800 if (D[i] == mintdeg)
1801 {
1802 if (L[i] < mindeglen)
1803 {
1804 mindeglen=L[i];
1805 pmindeglen = i;
1806 }
1807 }
1808 }
1809 d = p_Copy(C[pmindeglen], r);
1810 // there are dd>=1 mindeg elements
1811 // and pmideglen is the coordinate of one of the smallest among them
1812
1813 // poly g = singclap_gcd(p_Copy(p,r),p_Copy(q,r));
1814 // return naGcd(d,d2,currRing);
1815
1816 // adjoin pContentRat here?
1817 for(i=0; i<=k; i++)
1818 {
1819 d=singclap_gcd(d,p_Copy(C[i], r), r);
1820 if (p_Totaldegree(d, r)==0)
1821 {
1822 // cleanup, pContent, return
1823 p_Delete(&d, r);
1824 for(;k>=0;k--)
1825 {
1826 p_Delete(&C[k], r);
1827 p_Delete(&LM[k], r);
1828 }
1829 p_ContentForGB(ph, r);
1830 goto cleanup;
1831 }
1832 }
1833 for(i=0; i<=k; i++)
1834 {
1835 poly h=singclap_pdivide(C[i],d, r);
1836 p_Delete(&C[i], r);
1837 C[i]=h;
1838 }
1839
1840 // zusammensetzen,
1841 p=NULL; // just to be sure
1842 for(i=0; i<=k; i++)
1843 {
1844 p = p_Add_q(p, p_Mult_q(C[i],LM[i], r), r);
1845 C[i]=NULL; LM[i]=NULL;
1846 }
1847 p_Delete(&ph, r); // do not need it anymore
1848 ph = p;
1849 // aufraeumen, return
1850cleanup:
1851 omFree(C);
1852 omFree(LM);
1853 omFree(D);
1854 omFree(L);
1855}
1856
1857
1858#endif
1859
1860
1861/* assumes that p and divisor are univariate polynomials in r,
1862 mentioning the same variable;
1863 assumes divisor != NULL;
1864 p may be NULL;
1865 assumes a global monomial ordering in r;
1866 performs polynomial division of p by divisor:
1867 - afterwards p contains the remainder of the division, i.e.,
1868 p_before = result * divisor + p_afterwards;
1869 - if needResult == TRUE, then the method computes and returns 'result',
1870 otherwise NULL is returned (This parametrization can be used when
1871 one is only interested in the remainder of the division. In this
1872 case, the method will be slightly faster.)
1873 leaves divisor unmodified */
1874poly p_PolyDiv(poly &p, const poly divisor, const BOOLEAN needResult, const ring r)
1875{
1876 assume(divisor != NULL);
1877 if (p == NULL) return NULL;
1878
1879 poly result = NULL;
1880 number divisorLC = p_GetCoeff(divisor, r);
1881 int divisorLE = p_GetExp(divisor, 1, r);
1882 while ((p != NULL) && (p_Deg(p, r) >= p_Deg(divisor, r)))
1883 {
1884 /* determine t = LT(p) / LT(divisor) */
1885 poly t = p_ISet(1, r);
1886 number c = n_Div(p_GetCoeff(p, r), divisorLC, r->cf);
1887 n_Normalize(c,r->cf);
1888 p_SetCoeff(t, c, r);
1889 int e = p_GetExp(p, 1, r) - divisorLE;
1890 p_SetExp(t, 1, e, r);
1891 p_Setm(t, r);
1892 if (needResult) result = p_Add_q(result, p_Copy(t, r), r);
1893 p = p_Add_q(p, p_Neg(p_Mult_q(t, p_Copy(divisor, r), r), r), r);
1894 }
1895 return result;
1896}
1897
1898/*2
1899* returns the partial differentiate of a by the k-th variable
1900* does not destroy the input
1901*/
1902poly p_Diff(poly a, int k, const ring r)
1903{
1904 poly res, f, last;
1905 number t;
1906
1907 last = res = NULL;
1908 while (a!=NULL)
1909 {
1910 if (p_GetExp(a,k,r)!=0)
1911 {
1912 f = p_LmInit(a,r);
1913 t = n_Init(p_GetExp(a,k,r),r->cf);
1914 pSetCoeff0(f,n_Mult(t,pGetCoeff(a),r->cf));
1915 n_Delete(&t,r->cf);
1916 if (n_IsZero(pGetCoeff(f),r->cf))
1917 p_LmDelete(&f,r);
1918 else
1919 {
1920 p_DecrExp(f,k,r);
1921 p_Setm(f,r);
1922 if (res==NULL)
1923 {
1924 res=last=f;
1925 }
1926 else
1927 {
1928 pNext(last)=f;
1929 last=f;
1930 }
1931 }
1932 }
1933 pIter(a);
1934 }
1935 return res;
1936}
1937
1938static poly p_DiffOpM(poly a, poly b,BOOLEAN multiply, const ring r)
1939{
1940 int i,j,s;
1941 number n,h,hh;
1942 poly p=p_One(r);
1943 n=n_Mult(pGetCoeff(a),pGetCoeff(b),r->cf);
1944 for(i=rVar(r);i>0;i--)
1945 {
1946 s=p_GetExp(b,i,r);
1947 if (s<p_GetExp(a,i,r))
1948 {
1949 n_Delete(&n,r->cf);
1950 p_LmDelete(&p,r);
1951 return NULL;
1952 }
1953 if (multiply)
1954 {
1955 for(j=p_GetExp(a,i,r); j>0;j--)
1956 {
1957 h = n_Init(s,r->cf);
1958 hh=n_Mult(n,h,r->cf);
1959 n_Delete(&h,r->cf);
1960 n_Delete(&n,r->cf);
1961 n=hh;
1962 s--;
1963 }
1964 p_SetExp(p,i,s,r);
1965 }
1966 else
1967 {
1968 p_SetExp(p,i,s-p_GetExp(a,i,r),r);
1969 }
1970 }
1971 p_Setm(p,r);
1972 /*if (multiply)*/ p_SetCoeff(p,n,r);
1973 if (n_IsZero(n,r->cf)) p=p_LmDeleteAndNext(p,r); // return NULL as p is a monomial
1974 return p;
1975}
1976
1977poly p_DiffOp(poly a, poly b,BOOLEAN multiply, const ring r)
1978{
1979 poly result=NULL;
1980 poly h;
1981 for(;a!=NULL;pIter(a))
1982 {
1983 for(h=b;h!=NULL;pIter(h))
1984 {
1985 result=p_Add_q(result,p_DiffOpM(a,h,multiply,r),r);
1986 }
1987 }
1988 return result;
1989}
1990/*2
1991* subtract p2 from p1, p1 and p2 are destroyed
1992* do not put attention on speed: the procedure is only used in the interpreter
1993*/
1994poly p_Sub(poly p1, poly p2, const ring r)
1995{
1996 return p_Add_q(p1, p_Neg(p2,r),r);
1997}
1998
1999/*3
2000* compute for a monomial m
2001* the power m^exp, exp > 1
2002* destroys p
2003*/
2004static poly p_MonPower(poly p, int exp, const ring r)
2005{
2006 int i;
2007
2008 if(!n_IsOne(pGetCoeff(p),r->cf))
2009 {
2010 number x, y;
2011 y = pGetCoeff(p);
2012 n_Power(y,exp,&x,r->cf);
2013 n_Delete(&y,r->cf);
2014 pSetCoeff0(p,x);
2015 }
2016 for (i=rVar(r); i!=0; i--)
2017 {
2018 p_MultExp(p,i, exp,r);
2019 }
2020 p_Setm(p,r);
2021 return p;
2022}
2023
2024/*3
2025* compute for monomials p*q
2026* destroys p, keeps q
2027*/
2028static void p_MonMult(poly p, poly q, const ring r)
2029{
2030 number x, y;
2031
2032 y = pGetCoeff(p);
2033 x = n_Mult(y,pGetCoeff(q),r->cf);
2034 n_Delete(&y,r->cf);
2035 pSetCoeff0(p,x);
2036 //for (int i=pVariables; i!=0; i--)
2037 //{
2038 // pAddExp(p,i, pGetExp(q,i));
2039 //}
2040 //p->Order += q->Order;
2041 p_ExpVectorAdd(p,q,r);
2042}
2043
2044/*3
2045* compute for monomials p*q
2046* keeps p, q
2047*/
2048static poly p_MonMultC(poly p, poly q, const ring rr)
2049{
2050 number x;
2051 poly r = p_Init(rr);
2052
2053 x = n_Mult(pGetCoeff(p),pGetCoeff(q),rr->cf);
2054 pSetCoeff0(r,x);
2055 p_ExpVectorSum(r,p, q, rr);
2056 return r;
2057}
2058
2059/*3
2060* create binomial coef.
2061*/
2062static number* pnBin(int exp, const ring r)
2063{
2064 int e, i, h;
2065 number x, y, *bin=NULL;
2066
2067 x = n_Init(exp,r->cf);
2068 if (n_IsZero(x,r->cf))
2069 {
2070 n_Delete(&x,r->cf);
2071 return bin;
2072 }
2073 h = (exp >> 1) + 1;
2074 bin = (number *)omAlloc0(h*sizeof(number));
2075 bin[1] = x;
2076 if (exp < 4)
2077 return bin;
2078 i = exp - 1;
2079 for (e=2; e<h; e++)
2080 {
2081 x = n_Init(i,r->cf);
2082 i--;
2083 y = n_Mult(x,bin[e-1],r->cf);
2084 n_Delete(&x,r->cf);
2085 x = n_Init(e,r->cf);
2086 bin[e] = n_ExactDiv(y,x,r->cf);
2087 n_Delete(&x,r->cf);
2088 n_Delete(&y,r->cf);
2089 }
2090 return bin;
2091}
2092
2093static void pnFreeBin(number *bin, int exp,const coeffs r)
2094{
2095 int e, h = (exp >> 1) + 1;
2096
2097 if (bin[1] != NULL)
2098 {
2099 for (e=1; e<h; e++)
2100 n_Delete(&(bin[e]),r);
2101 }
2102 omFreeSize((ADDRESS)bin, h*sizeof(number));
2103}
2104
2105/*
2106* compute for a poly p = head+tail, tail is monomial
2107* (head + tail)^exp, exp > 1
2108* with binomial coef.
2109*/
2110static poly p_TwoMonPower(poly p, int exp, const ring r)
2111{
2112 int eh, e;
2113 long al;
2114 poly *a;
2115 poly tail, b, res, h;
2116 number x;
2117 number *bin = pnBin(exp,r);
2118
2119 tail = pNext(p);
2120 if (bin == NULL)
2121 {
2122 p_MonPower(p,exp,r);
2123 p_MonPower(tail,exp,r);
2124 p_Test(p,r);
2125 return p;
2126 }
2127 eh = exp >> 1;
2128 al = (exp + 1) * sizeof(poly);
2129 a = (poly *)omAlloc(al);
2130 a[1] = p;
2131 for (e=1; e<exp; e++)
2132 {
2133 a[e+1] = p_MonMultC(a[e],p,r);
2134 }
2135 res = a[exp];
2136 b = p_Head(tail,r);
2137 for (e=exp-1; e>eh; e--)
2138 {
2139 h = a[e];
2140 x = n_Mult(bin[exp-e],pGetCoeff(h),r->cf);
2141 p_SetCoeff(h,x,r);
2142 p_MonMult(h,b,r);
2143 res = pNext(res) = h;
2144 p_MonMult(b,tail,r);
2145 }
2146 for (e=eh; e!=0; e--)
2147 {
2148 h = a[e];
2149 x = n_Mult(bin[e],pGetCoeff(h),r->cf);
2150 p_SetCoeff(h,x,r);
2151 p_MonMult(h,b,r);
2152 res = pNext(res) = h;
2153 p_MonMult(b,tail,r);
2154 }
2155 p_LmDelete(&tail,r);
2156 pNext(res) = b;
2157 pNext(b) = NULL;
2158 res = a[exp];
2159 omFreeSize((ADDRESS)a, al);
2160 pnFreeBin(bin, exp, r->cf);
2161// tail=res;
2162// while((tail!=NULL)&&(pNext(tail)!=NULL))
2163// {
2164// if(nIsZero(pGetCoeff(pNext(tail))))
2165// {
2166// pLmDelete(&pNext(tail));
2167// }
2168// else
2169// pIter(tail);
2170// }
2171 p_Test(res,r);
2172 return res;
2173}
2174
2175static poly p_Pow(poly p, int i, const ring r)
2176{
2177 poly rc = p_Copy(p,r);
2178 i -= 2;
2179 do
2180 {
2181 rc = p_Mult_q(rc,p_Copy(p,r),r);
2182 p_Normalize(rc,r);
2183 i--;
2184 }
2185 while (i != 0);
2186 return p_Mult_q(rc,p,r);
2187}
2188
2189static poly p_Pow_charp(poly p, int i, const ring r)
2190{
2191 //assume char_p == i
2192 poly h=p;
2193 while(h!=NULL) { p_MonPower(h,i,r);pIter(h);}
2194 return p;
2195}
2196
2197/*2
2198* returns the i-th power of p
2199* p will be destroyed
2200*/
2201poly p_Power(poly p, int i, const ring r)
2202{
2203 poly rc=NULL;
2204
2205 if (i==0)
2206 {
2207 p_Delete(&p,r);
2208 return p_One(r);
2209 }
2210
2211 if(p!=NULL)
2212 {
2213 if ( (i > 0) && ((unsigned long ) i > (r->bitmask))
2214 #ifdef HAVE_SHIFTBBA
2215 && (!rIsLPRing(r))
2216 #endif
2217 )
2218 {
2219 Werror("exponent %d is too large, max. is %ld",i,r->bitmask);
2220 return NULL;
2221 }
2222 switch (i)
2223 {
2224// cannot happen, see above
2225// case 0:
2226// {
2227// rc=pOne();
2228// pDelete(&p);
2229// break;
2230// }
2231 case 1:
2232 rc=p;
2233 break;
2234 case 2:
2235 rc=p_Mult_q(p_Copy(p,r),p,r);
2236 break;
2237 default:
2238 if (i < 0)
2239 {
2240 p_Delete(&p,r);
2241 return NULL;
2242 }
2243 else
2244 {
2245#ifdef HAVE_PLURAL
2246 if (rIsNCRing(r)) /* in the NC case nothing helps :-( */
2247 {
2248 int j=i;
2249 rc = p_Copy(p,r);
2250 while (j>1)
2251 {
2252 rc = p_Mult_q(p_Copy(p,r),rc,r);
2253 j--;
2254 }
2255 p_Delete(&p,r);
2256 return rc;
2257 }
2258#endif
2259 rc = pNext(p);
2260 if (rc == NULL)
2261 return p_MonPower(p,i,r);
2262 /* else: binom ?*/
2263 int char_p=rInternalChar(r);
2264 if ((char_p>0) && (i>char_p)
2265 && ((rField_is_Zp(r,char_p)
2266 || (rField_is_Zp_a(r,char_p)))))
2267 {
2268 poly h=p_Pow_charp(p_Copy(p,r),char_p,r);
2269 int rest=i-char_p;
2270 while (rest>=char_p)
2271 {
2272 rest-=char_p;
2273 h=p_Mult_q(h,p_Pow_charp(p_Copy(p,r),char_p,r),r);
2274 }
2275 poly res=h;
2276 if (rest>0)
2277 res=p_Mult_q(p_Power(p_Copy(p,r),rest,r),h,r);
2278 p_Delete(&p,r);
2279 return res;
2280 }
2281 if ((pNext(rc) != NULL)
2282 || rField_is_Ring(r)
2283 )
2284 return p_Pow(p,i,r);
2285 if ((char_p==0) || (i<=char_p))
2286 return p_TwoMonPower(p,i,r);
2287 return p_Pow(p,i,r);
2288 }
2289 /*end default:*/
2290 }
2291 }
2292 return rc;
2293}
2294
2295/* --------------------------------------------------------------------------------*/
2296/* content suff */
2297//number p_InitContent(poly ph, const ring r);
2298
2299void p_Content(poly ph, const ring r)
2300{
2301 if (ph==NULL) return;
2302 const coeffs cf=r->cf;
2303 if (pNext(ph)==NULL)
2304 {
2305 p_SetCoeff(ph,n_Init(1,cf),r);
2306 return;
2307 }
2308 if ((cf->cfSubringGcd==ndGcd)
2309 || (cf->cfGcd==ndGcd)) /* trivial gcd*/
2310 return;
2311 number h;
2312 if ((rField_is_Q(r))
2313 || (rField_is_Q_a(r))
2314 || (rField_is_Zp_a)(r)
2315 || (rField_is_Z(r))
2316 )
2317 {
2318 h=p_InitContent(ph,r); /* first guess of a gcd of all coeffs */
2319 }
2320 else
2321 {
2322 h=n_Copy(pGetCoeff(ph),cf);
2323 }
2324 poly p;
2325 if(n_IsOne(h,cf))
2326 {
2327 goto content_finish;
2328 }
2329 p=ph;
2330 // take the SubringGcd of all coeffs
2331 while (p!=NULL)
2332 {
2334 number d=n_SubringGcd(h,pGetCoeff(p),cf);
2335 n_Delete(&h,cf);
2336 h = d;
2337 if(n_IsOne(h,cf))
2338 {
2339 goto content_finish;
2340 }
2341 pIter(p);
2342 }
2343 // if found<>1, divide by it
2344 p = ph;
2345 while (p!=NULL)
2346 {
2347 number d = n_ExactDiv(pGetCoeff(p),h,cf);
2348 p_SetCoeff(p,d,r);
2349 pIter(p);
2350 }
2351content_finish:
2352 n_Delete(&h,r->cf);
2353 // and last: check leading sign:
2354 if(!n_GreaterZero(pGetCoeff(ph),r->cf)) ph = p_Neg(ph,r);
2355}
2356
2357#define CLEARENUMERATORS 1
2358
2359void p_ContentForGB(poly ph, const ring r)
2360{
2361 if(TEST_OPT_CONTENTSB) return;
2362 assume( ph != NULL );
2363
2364 assume( r != NULL ); assume( r->cf != NULL );
2365
2366
2367#if CLEARENUMERATORS
2368 if( 0 )
2369 {
2370 const coeffs C = r->cf;
2371 // experimentall (recursive enumerator treatment) of alg. Ext!
2372 CPolyCoeffsEnumerator itr(ph);
2373 n_ClearContent(itr, r->cf);
2374
2375 p_Test(ph, r); n_Test(pGetCoeff(ph), C);
2376 assume(n_GreaterZero(pGetCoeff(ph), C)); // ??
2377
2378 // if(!n_GreaterZero(pGetCoeff(ph),r->cf)) ph = p_Neg(ph,r);
2379 return;
2380 }
2381#endif
2382
2383
2384#ifdef HAVE_RINGS
2385 if (rField_is_Ring(r))
2386 {
2387 if (rField_has_Units(r))
2388 {
2389 number k = n_GetUnit(pGetCoeff(ph),r->cf);
2390 if (!n_IsOne(k,r->cf))
2391 {
2392 number tmpGMP = k;
2393 k = n_Invers(k,r->cf);
2394 n_Delete(&tmpGMP,r->cf);
2395 poly h = pNext(ph);
2396 p_SetCoeff(ph, n_Mult(pGetCoeff(ph), k,r->cf),r);
2397 while (h != NULL)
2398 {
2399 p_SetCoeff(h, n_Mult(pGetCoeff(h), k,r->cf),r);
2400 pIter(h);
2401 }
2402// assume( n_GreaterZero(pGetCoeff(ph),r->cf) );
2403// if(!n_GreaterZero(pGetCoeff(ph),r->cf)) ph = p_Neg(ph,r);
2404 }
2405 n_Delete(&k,r->cf);
2406 }
2407 return;
2408 }
2409#endif
2410 number h,d;
2411 poly p;
2412
2413 if(pNext(ph)==NULL)
2414 {
2415 p_SetCoeff(ph,n_Init(1,r->cf),r);
2416 }
2417 else
2418 {
2419 assume( pNext(ph) != NULL );
2420#if CLEARENUMERATORS
2421 if( nCoeff_is_Q(r->cf) )
2422 {
2423 // experimentall (recursive enumerator treatment) of alg. Ext!
2424 CPolyCoeffsEnumerator itr(ph);
2425 n_ClearContent(itr, r->cf);
2426
2427 p_Test(ph, r); n_Test(pGetCoeff(ph), r->cf);
2428 assume(n_GreaterZero(pGetCoeff(ph), r->cf)); // ??
2429
2430 // if(!n_GreaterZero(pGetCoeff(ph),r->cf)) ph = p_Neg(ph,r);
2431 return;
2432 }
2433#endif
2434
2435 n_Normalize(pGetCoeff(ph),r->cf);
2436 if(!n_GreaterZero(pGetCoeff(ph),r->cf)) ph = p_Neg(ph,r);
2437 if (rField_is_Q(r)||(getCoeffType(r->cf)==n_transExt)) // should not be used anymore if CLEARENUMERATORS is 1
2438 {
2439 h=p_InitContent(ph,r);
2440 p=ph;
2441 }
2442 else
2443 {
2444 h=n_Copy(pGetCoeff(ph),r->cf);
2445 p = pNext(ph);
2446 }
2447 while (p!=NULL)
2448 {
2449 n_Normalize(pGetCoeff(p),r->cf);
2450 d=n_SubringGcd(h,pGetCoeff(p),r->cf);
2451 n_Delete(&h,r->cf);
2452 h = d;
2453 if(n_IsOne(h,r->cf))
2454 {
2455 break;
2456 }
2457 pIter(p);
2458 }
2459 //number tmp;
2460 if(!n_IsOne(h,r->cf))
2461 {
2462 p = ph;
2463 while (p!=NULL)
2464 {
2465 //d = nDiv(pGetCoeff(p),h);
2466 //tmp = nExactDiv(pGetCoeff(p),h);
2467 //if (!nEqual(d,tmp))
2468 //{
2469 // StringSetS("** div0:");nWrite(pGetCoeff(p));StringAppendS("/");
2470 // nWrite(h);StringAppendS("=");nWrite(d);StringAppendS(" int:");
2471 // nWrite(tmp);Print(StringEndS("\n")); // NOTE/TODO: use StringAppendS("\n"); omFree(s);
2472 //}
2473 //nDelete(&tmp);
2474 d = n_ExactDiv(pGetCoeff(p),h,r->cf);
2475 p_SetCoeff(p,d,r);
2476 pIter(p);
2477 }
2478 }
2479 n_Delete(&h,r->cf);
2480 if (rField_is_Q_a(r))
2481 {
2482 // special handling for alg. ext.:
2483 if (getCoeffType(r->cf)==n_algExt)
2484 {
2485 h = n_Init(1, r->cf->extRing->cf);
2486 p=ph;
2487 while (p!=NULL)
2488 { // each monom: coeff in Q_a
2489 poly c_n_n=(poly)pGetCoeff(p);
2490 poly c_n=c_n_n;
2491 while (c_n!=NULL)
2492 { // each monom: coeff in Q
2493 d=n_NormalizeHelper(h,pGetCoeff(c_n),r->cf->extRing->cf);
2494 n_Delete(&h,r->cf->extRing->cf);
2495 h=d;
2496 pIter(c_n);
2497 }
2498 pIter(p);
2499 }
2500 /* h contains the 1/lcm of all denominators in c_n_n*/
2501 //n_Normalize(h,r->cf->extRing->cf);
2502 if(!n_IsOne(h,r->cf->extRing->cf))
2503 {
2504 p=ph;
2505 while (p!=NULL)
2506 { // each monom: coeff in Q_a
2507 poly c_n=(poly)pGetCoeff(p);
2508 while (c_n!=NULL)
2509 { // each monom: coeff in Q
2510 d=n_Mult(h,pGetCoeff(c_n),r->cf->extRing->cf);
2511 n_Normalize(d,r->cf->extRing->cf);
2512 n_Delete(&pGetCoeff(c_n),r->cf->extRing->cf);
2513 pGetCoeff(c_n)=d;
2514 pIter(c_n);
2515 }
2516 pIter(p);
2517 }
2518 }
2519 n_Delete(&h,r->cf->extRing->cf);
2520 }
2521 /*else
2522 {
2523 // special handling for rat. functions.:
2524 number hzz =NULL;
2525 p=ph;
2526 while (p!=NULL)
2527 { // each monom: coeff in Q_a (Z_a)
2528 fraction f=(fraction)pGetCoeff(p);
2529 poly c_n=NUM(f);
2530 if (hzz==NULL)
2531 {
2532 hzz=n_Copy(pGetCoeff(c_n),r->cf->extRing->cf);
2533 pIter(c_n);
2534 }
2535 while ((c_n!=NULL)&&(!n_IsOne(hzz,r->cf->extRing->cf)))
2536 { // each monom: coeff in Q (Z)
2537 d=n_Gcd(hzz,pGetCoeff(c_n),r->cf->extRing->cf);
2538 n_Delete(&hzz,r->cf->extRing->cf);
2539 hzz=d;
2540 pIter(c_n);
2541 }
2542 pIter(p);
2543 }
2544 // hzz contains the gcd of all numerators in f
2545 h=n_Invers(hzz,r->cf->extRing->cf);
2546 n_Delete(&hzz,r->cf->extRing->cf);
2547 n_Normalize(h,r->cf->extRing->cf);
2548 if(!n_IsOne(h,r->cf->extRing->cf))
2549 {
2550 p=ph;
2551 while (p!=NULL)
2552 { // each monom: coeff in Q_a (Z_a)
2553 fraction f=(fraction)pGetCoeff(p);
2554 NUM(f)=__p_Mult_nn(NUM(f),h,r->cf->extRing);
2555 p_Normalize(NUM(f),r->cf->extRing);
2556 pIter(p);
2557 }
2558 }
2559 n_Delete(&h,r->cf->extRing->cf);
2560 }*/
2561 }
2562 }
2563 if(!n_GreaterZero(pGetCoeff(ph),r->cf)) ph = p_Neg(ph,r);
2564}
2565
2566// Not yet?
2567#if 1 // currently only used by Singular/janet
2568void p_SimpleContent(poly ph, int smax, const ring r)
2569{
2570 if(TEST_OPT_CONTENTSB) return;
2571 if (ph==NULL) return;
2572 if (pNext(ph)==NULL)
2573 {
2574 p_SetCoeff(ph,n_Init(1,r->cf),r);
2575 return;
2576 }
2577 if (pNext(pNext(ph))==NULL)
2578 {
2579 return;
2580 }
2581 if (!(rField_is_Q(r))
2582 && (!rField_is_Q_a(r))
2583 && (!rField_is_Zp_a(r))
2584 && (!rField_is_Z(r))
2585 )
2586 {
2587 return;
2588 }
2589 number d=p_InitContent(ph,r);
2590 number h=d;
2591 if (n_Size(d,r->cf)<=smax)
2592 {
2593 n_Delete(&h,r->cf);
2594 //if (TEST_OPT_PROT) PrintS("G");
2595 return;
2596 }
2597
2598 poly p=ph;
2599 if (smax==1) smax=2;
2600 while (p!=NULL)
2601 {
2602#if 1
2603 d=n_SubringGcd(h,pGetCoeff(p),r->cf);
2604 n_Delete(&h,r->cf);
2605 h = d;
2606#else
2607 n_InpGcd(h,pGetCoeff(p),r->cf);
2608#endif
2609 if(n_Size(h,r->cf)<smax)
2610 {
2611 //if (TEST_OPT_PROT) PrintS("g");
2612 n_Delete(&h,r->cf);
2613 return;
2614 }
2615 pIter(p);
2616 }
2617 p = ph;
2618 if (!n_GreaterZero(pGetCoeff(p),r->cf)) h=n_InpNeg(h,r->cf);
2619 if(n_IsOne(h,r->cf))
2620 {
2621 n_Delete(&h,r->cf);
2622 return;
2623 }
2624 if (TEST_OPT_PROT) PrintS("c");
2625 while (p!=NULL)
2626 {
2627#if 1
2628 d = n_ExactDiv(pGetCoeff(p),h,r->cf);
2629 p_SetCoeff(p,d,r);
2630#else
2631 STATISTIC(n_ExactDiv); nlInpExactDiv(pGetCoeff(p),h,r->cf); // no such function... ?
2632#endif
2633 pIter(p);
2634 }
2635 n_Delete(&h,r->cf);
2636}
2637#endif
2638
2639number p_InitContent(poly ph, const ring r)
2640// only for coefficients in Q and rational functions
2641#if 0
2642{
2644 assume(ph!=NULL);
2645 assume(pNext(ph)!=NULL);
2646 assume(rField_is_Q(r));
2647 if (pNext(pNext(ph))==NULL)
2648 {
2649 return n_GetNumerator(pGetCoeff(pNext(ph)),r->cf);
2650 }
2651 poly p=ph;
2652 number n1=n_GetNumerator(pGetCoeff(p),r->cf);
2653 pIter(p);
2654 number n2=n_GetNumerator(pGetCoeff(p),r->cf);
2655 pIter(p);
2656 number d;
2657 number t;
2658 loop
2659 {
2660 nlNormalize(pGetCoeff(p),r->cf);
2661 t=n_GetNumerator(pGetCoeff(p),r->cf);
2662 if (nlGreaterZero(t,r->cf))
2663 d=nlAdd(n1,t,r->cf);
2664 else
2665 d=nlSub(n1,t,r->cf);
2666 nlDelete(&t,r->cf);
2667 nlDelete(&n1,r->cf);
2668 n1=d;
2669 pIter(p);
2670 if (p==NULL) break;
2671 nlNormalize(pGetCoeff(p),r->cf);
2672 t=n_GetNumerator(pGetCoeff(p),r->cf);
2673 if (nlGreaterZero(t,r->cf))
2674 d=nlAdd(n2,t,r->cf);
2675 else
2676 d=nlSub(n2,t,r->cf);
2677 nlDelete(&t,r->cf);
2678 nlDelete(&n2,r->cf);
2679 n2=d;
2680 pIter(p);
2681 if (p==NULL) break;
2682 }
2683 d=nlGcd(n1,n2,r->cf);
2684 nlDelete(&n1,r->cf);
2685 nlDelete(&n2,r->cf);
2686 return d;
2687}
2688#else
2689{
2690 /* ph has al least 2 terms */
2691 number d=pGetCoeff(ph);
2692 int s=n_Size(d,r->cf);
2693 pIter(ph);
2694 number d2=pGetCoeff(ph);
2695 int s2=n_Size(d2,r->cf);
2696 pIter(ph);
2697 if (ph==NULL)
2698 {
2699 if (s<s2) return n_Copy(d,r->cf);
2700 else return n_Copy(d2,r->cf);
2701 }
2702 do
2703 {
2704 number nd=pGetCoeff(ph);
2705 int ns=n_Size(nd,r->cf);
2706 if (ns<=2)
2707 {
2708 s2=s;
2709 d2=d;
2710 d=nd;
2711 s=ns;
2712 break;
2713 }
2714 else if (ns<s)
2715 {
2716 s2=s;
2717 d2=d;
2718 d=nd;
2719 s=ns;
2720 }
2721 pIter(ph);
2722 }
2723 while(ph!=NULL);
2724 return n_SubringGcd(d,d2,r->cf);
2725}
2726#endif
2727
2728//void pContent(poly ph)
2729//{
2730// number h,d;
2731// poly p;
2732//
2733// p = ph;
2734// if(pNext(p)==NULL)
2735// {
2736// pSetCoeff(p,nInit(1));
2737// }
2738// else
2739// {
2740//#ifdef PDEBUG
2741// if (!pTest(p)) return;
2742//#endif
2743// nNormalize(pGetCoeff(p));
2744// if(!nGreaterZero(pGetCoeff(ph)))
2745// {
2746// ph = pNeg(ph);
2747// nNormalize(pGetCoeff(p));
2748// }
2749// h=pGetCoeff(p);
2750// pIter(p);
2751// while (p!=NULL)
2752// {
2753// nNormalize(pGetCoeff(p));
2754// if (nGreater(h,pGetCoeff(p))) h=pGetCoeff(p);
2755// pIter(p);
2756// }
2757// h=nCopy(h);
2758// p=ph;
2759// while (p!=NULL)
2760// {
2761// d=n_Gcd(h,pGetCoeff(p));
2762// nDelete(&h);
2763// h = d;
2764// if(nIsOne(h))
2765// {
2766// break;
2767// }
2768// pIter(p);
2769// }
2770// p = ph;
2771// //number tmp;
2772// if(!nIsOne(h))
2773// {
2774// while (p!=NULL)
2775// {
2776// d = nExactDiv(pGetCoeff(p),h);
2777// pSetCoeff(p,d);
2778// pIter(p);
2779// }
2780// }
2781// nDelete(&h);
2782// if ( (nGetChar() == 1) || (nGetChar() < 0) ) /* Q[a],Q(a),Zp[a],Z/p(a) */
2783// {
2784// pTest(ph);
2785// singclap_divide_content(ph);
2786// pTest(ph);
2787// }
2788// }
2789//}
2790#if 0
2791void p_Content(poly ph, const ring r)
2792{
2793 number h,d;
2794 poly p;
2795
2796 if(pNext(ph)==NULL)
2797 {
2798 p_SetCoeff(ph,n_Init(1,r->cf),r);
2799 }
2800 else
2801 {
2802 n_Normalize(pGetCoeff(ph),r->cf);
2803 if(!n_GreaterZero(pGetCoeff(ph),r->cf)) ph = p_Neg(ph,r);
2804 h=n_Copy(pGetCoeff(ph),r->cf);
2805 p = pNext(ph);
2806 while (p!=NULL)
2807 {
2808 n_Normalize(pGetCoeff(p),r->cf);
2809 d=n_Gcd(h,pGetCoeff(p),r->cf);
2810 n_Delete(&h,r->cf);
2811 h = d;
2812 if(n_IsOne(h,r->cf))
2813 {
2814 break;
2815 }
2816 pIter(p);
2817 }
2818 p = ph;
2819 //number tmp;
2820 if(!n_IsOne(h,r->cf))
2821 {
2822 while (p!=NULL)
2823 {
2824 //d = nDiv(pGetCoeff(p),h);
2825 //tmp = nExactDiv(pGetCoeff(p),h);
2826 //if (!nEqual(d,tmp))
2827 //{
2828 // StringSetS("** div0:");nWrite(pGetCoeff(p));StringAppendS("/");
2829 // nWrite(h);StringAppendS("=");nWrite(d);StringAppendS(" int:");
2830 // nWrite(tmp);Print(StringEndS("\n")); // NOTE/TODO: use StringAppendS("\n"); omFree(s);
2831 //}
2832 //nDelete(&tmp);
2833 d = n_ExactDiv(pGetCoeff(p),h,r->cf);
2834 p_SetCoeff(p,d,r->cf);
2835 pIter(p);
2836 }
2837 }
2838 n_Delete(&h,r->cf);
2839 //if ( (n_GetChar(r) == 1) || (n_GetChar(r) < 0) ) /* Q[a],Q(a),Zp[a],Z/p(a) */
2840 //{
2841 // singclap_divide_content(ph);
2842 // if(!n_GreaterZero(pGetCoeff(ph),r)) ph = p_Neg(ph,r);
2843 //}
2844 }
2845}
2846#endif
2847/* ---------------------------------------------------------------------------*/
2848/* cleardenom suff */
2849poly p_Cleardenom(poly p, const ring r)
2850{
2851 if( p == NULL )
2852 return NULL;
2853
2854 assume( r != NULL );
2855 assume( r->cf != NULL );
2856 const coeffs C = r->cf;
2857
2858#if CLEARENUMERATORS
2859 if( 0 )
2860 {
2862 n_ClearDenominators(itr, C);
2863 n_ClearContent(itr, C); // divide out the content
2864 p_Test(p, r); n_Test(pGetCoeff(p), C);
2865 assume(n_GreaterZero(pGetCoeff(p), C)); // ??
2866// if(!n_GreaterZero(pGetCoeff(p),C)) p = p_Neg(p,r);
2867 return p;
2868 }
2869#endif
2870
2871 number d, h;
2872
2873 if (rField_is_Ring(r))
2874 {
2875 if(!n_GreaterZero(pGetCoeff(p),C)) p = p_Neg(p,r);
2876 return p;
2877 }
2878
2880 {
2881 if(!n_GreaterZero(pGetCoeff(p),C)) p = p_Neg(p,r);
2882 return p;
2883 }
2884
2885 assume(p != NULL);
2886
2887 if(pNext(p)==NULL)
2888 {
2889 if (!TEST_OPT_CONTENTSB)
2890 p_SetCoeff(p,n_Init(1,C),r);
2891 else if(!n_GreaterZero(pGetCoeff(p),C))
2892 p = p_Neg(p,r);
2893 return p;
2894 }
2895
2896 assume(pNext(p)!=NULL);
2897 poly start=p;
2898
2899#if 0 && CLEARENUMERATORS
2900//CF: does not seem to work that well..
2901
2902 if( nCoeff_is_Q(C) || nCoeff_is_Q_a(C) )
2903 {
2905 n_ClearDenominators(itr, C);
2906 n_ClearContent(itr, C); // divide out the content
2907 p_Test(p, r); n_Test(pGetCoeff(p), C);
2908 assume(n_GreaterZero(pGetCoeff(p), C)); // ??
2909// if(!n_GreaterZero(pGetCoeff(p),C)) p = p_Neg(p,r);
2910 return start;
2911 }
2912#endif
2913
2914 if(1)
2915 {
2916 // get lcm of all denominators ----------------------------------
2917 h = n_Init(1,C);
2918 while (p!=NULL)
2919 {
2922 n_Delete(&h,C);
2923 h=d;
2924 pIter(p);
2925 }
2926 /* h now contains the 1/lcm of all denominators */
2927 if(!n_IsOne(h,C))
2928 {
2929 // multiply by the lcm of all denominators
2930 p = start;
2931 while (p!=NULL)
2932 {
2933 d=n_Mult(h,pGetCoeff(p),C);
2934 n_Normalize(d,C);
2935 p_SetCoeff(p,d,r);
2936 pIter(p);
2937 }
2938 }
2939 n_Delete(&h,C);
2940 p=start;
2941
2942 p_ContentForGB(p,r);
2943#ifdef HAVE_RATGRING
2944 if (rIsRatGRing(r))
2945 {
2946 /* quick unit detection in the rational case is done in gr_nc_bba */
2947 p_ContentRat(p, r);
2948 start=p;
2949 }
2950#endif
2951 }
2952
2953 if(!n_GreaterZero(pGetCoeff(p),C)) p = p_Neg(p,r);
2954
2955 return start;
2956}
2957
2958void p_Cleardenom_n(poly ph,const ring r,number &c)
2959{
2960 const coeffs C = r->cf;
2961 number d, h;
2962
2963 assume( ph != NULL );
2964
2965 poly p = ph;
2966
2967#if CLEARENUMERATORS
2968 if( 0 )
2969 {
2970 CPolyCoeffsEnumerator itr(ph);
2971
2972 n_ClearDenominators(itr, d, C); // multiply with common denom. d
2973 n_ClearContent(itr, h, C); // divide by the content h
2974
2975 c = n_Div(d, h, C); // d/h
2976
2977 n_Delete(&d, C);
2978 n_Delete(&h, C);
2979
2980 n_Test(c, C);
2981
2982 p_Test(ph, r); n_Test(pGetCoeff(ph), C);
2983 assume(n_GreaterZero(pGetCoeff(ph), C)); // ??
2984/*
2985 if(!n_GreaterZero(pGetCoeff(ph),C))
2986 {
2987 ph = p_Neg(ph,r);
2988 c = n_InpNeg(c, C);
2989 }
2990*/
2991 return;
2992 }
2993#endif
2994
2995
2996 if( pNext(p) == NULL )
2997 {
2999 {
3000 c=n_Invers(pGetCoeff(p), C);
3001 p_SetCoeff(p, n_Init(1, C), r);
3002 }
3003 else
3004 {
3005 c=n_Init(1,C);
3006 }
3007
3008 if(!n_GreaterZero(pGetCoeff(ph),C))
3009 {
3010 ph = p_Neg(ph,r);
3011 c = n_InpNeg(c, C);
3012 }
3013
3014 return;
3015 }
3016 if (TEST_OPT_CONTENTSB) { c=n_Init(1,C); return; }
3017
3018 assume( pNext(p) != NULL );
3019
3020#if CLEARENUMERATORS
3021 if( nCoeff_is_Q(C) || nCoeff_is_Q_a(C) )
3022 {
3023 CPolyCoeffsEnumerator itr(ph);
3024
3025 n_ClearDenominators(itr, d, C); // multiply with common denom. d
3026 n_ClearContent(itr, h, C); // divide by the content h
3027
3028 c = n_Div(d, h, C); // d/h
3029
3030 n_Delete(&d, C);
3031 n_Delete(&h, C);
3032
3033 n_Test(c, C);
3034
3035 p_Test(ph, r); n_Test(pGetCoeff(ph), C);
3036 assume(n_GreaterZero(pGetCoeff(ph), C)); // ??
3037/*
3038 if(!n_GreaterZero(pGetCoeff(ph),C))
3039 {
3040 ph = p_Neg(ph,r);
3041 c = n_InpNeg(c, C);
3042 }
3043*/
3044 return;
3045 }
3046#endif
3047
3048
3049
3050
3051 if(1)
3052 {
3053 h = n_Init(1,C);
3054 while (p!=NULL)
3055 {
3058 n_Delete(&h,C);
3059 h=d;
3060 pIter(p);
3061 }
3062 c=h;
3063 /* contains the 1/lcm of all denominators */
3064 if(!n_IsOne(h,C))
3065 {
3066 p = ph;
3067 while (p!=NULL)
3068 {
3069 /* should be: // NOTE: don't use ->coef!!!!
3070 * number hh;
3071 * nGetDenom(p->coef,&hh);
3072 * nMult(&h,&hh,&d);
3073 * nNormalize(d);
3074 * nDelete(&hh);
3075 * nMult(d,p->coef,&hh);
3076 * nDelete(&d);
3077 * nDelete(&(p->coef));
3078 * p->coef =hh;
3079 */
3080 d=n_Mult(h,pGetCoeff(p),C);
3081 n_Normalize(d,C);
3082 p_SetCoeff(p,d,r);
3083 pIter(p);
3084 }
3085 if (rField_is_Q_a(r))
3086 {
3087 loop
3088 {
3089 h = n_Init(1,C);
3090 p=ph;
3091 while (p!=NULL)
3092 {
3094 n_Delete(&h,C);
3095 h=d;
3096 pIter(p);
3097 }
3098 /* contains the 1/lcm of all denominators */
3099 if(!n_IsOne(h,C))
3100 {
3101 p = ph;
3102 while (p!=NULL)
3103 {
3104 /* should be: // NOTE: don't use ->coef!!!!
3105 * number hh;
3106 * nGetDenom(p->coef,&hh);
3107 * nMult(&h,&hh,&d);
3108 * nNormalize(d);
3109 * nDelete(&hh);
3110 * nMult(d,p->coef,&hh);
3111 * nDelete(&d);
3112 * nDelete(&(p->coef));
3113 * p->coef =hh;
3114 */
3115 d=n_Mult(h,pGetCoeff(p),C);
3116 n_Normalize(d,C);
3117 p_SetCoeff(p,d,r);
3118 pIter(p);
3119 }
3120 number t=n_Mult(c,h,C);
3121 n_Delete(&c,C);
3122 c=t;
3123 }
3124 else
3125 {
3126 break;
3127 }
3128 n_Delete(&h,C);
3129 }
3130 }
3131 }
3132 }
3133
3134 if(!n_GreaterZero(pGetCoeff(ph),C))
3135 {
3136 ph = p_Neg(ph,r);
3137 c = n_InpNeg(c, C);
3138 }
3139
3140}
3141
3142 // normalization: for poly over Q: make poly primitive, integral
3143 // Qa make poly integral with leading
3144 // coefficient minimal in N
3145 // Q(t) make poly primitive, integral
3146
3147void p_ProjectiveUnique(poly ph, const ring r)
3148{
3149 if( ph == NULL )
3150 return;
3151
3152 const coeffs C = r->cf;
3153
3154 number h;
3155 poly p;
3156
3157 if (nCoeff_is_Ring(C))
3158 {
3159 p_ContentForGB(ph,r);
3160 if(!n_GreaterZero(pGetCoeff(ph),C)) ph = p_Neg(ph,r);
3161 assume( n_GreaterZero(pGetCoeff(ph),C) );
3162 return;
3163 }
3164
3166 {
3167 if(!n_GreaterZero(pGetCoeff(ph),C)) ph = p_Neg(ph,r);
3168 return;
3169 }
3170 p = ph;
3171
3172 assume(p != NULL);
3173
3174 if(pNext(p)==NULL) // a monomial
3175 {
3176 p_SetCoeff(p, n_Init(1, C), r);
3177 return;
3178 }
3179
3180 assume(pNext(p)!=NULL);
3181
3182 if(!nCoeff_is_Q(C) && !nCoeff_is_transExt(C))
3183 {
3184 h = p_GetCoeff(p, C);
3185 number hInv = n_Invers(h, C);
3186 pIter(p);
3187 while (p!=NULL)
3188 {
3189 p_SetCoeff(p, n_Mult(p_GetCoeff(p, C), hInv, C), r);
3190 pIter(p);
3191 }
3192 n_Delete(&hInv, C);
3193 p = ph;
3194 p_SetCoeff(p, n_Init(1, C), r);
3195 }
3196
3197 p_Cleardenom(ph, r); //removes also Content
3198
3199
3200 /* normalize ph over a transcendental extension s.t.
3201 lead (ph) is > 0 if extRing->cf == Q
3202 or lead (ph) is monic if extRing->cf == Zp*/
3203 if (nCoeff_is_transExt(C))
3204 {
3205 p= ph;
3206 h= p_GetCoeff (p, C);
3207 fraction f = (fraction) h;
3208 number n=p_GetCoeff (NUM (f),C->extRing->cf);
3209 if (rField_is_Q (C->extRing))
3210 {
3211 if (!n_GreaterZero(n,C->extRing->cf))
3212 {
3213 p=p_Neg (p,r);
3214 }
3215 }
3216 else if (rField_is_Zp(C->extRing))
3217 {
3218 if (!n_IsOne (n, C->extRing->cf))
3219 {
3220 n=n_Invers (n,C->extRing->cf);
3221 nMapFunc nMap;
3222 nMap= n_SetMap (C->extRing->cf, C);
3223 number ninv= nMap (n,C->extRing->cf, C);
3224 p=__p_Mult_nn (p, ninv, r);
3225 n_Delete (&ninv, C);
3226 n_Delete (&n, C->extRing->cf);
3227 }
3228 }
3229 p= ph;
3230 }
3231
3232 return;
3233}
3234
3235#if 0 /*unused*/
3236number p_GetAllDenom(poly ph, const ring r)
3237{
3238 number d=n_Init(1,r->cf);
3239 poly p = ph;
3240
3241 while (p!=NULL)
3242 {
3243 number h=n_GetDenom(pGetCoeff(p),r->cf);
3244 if (!n_IsOne(h,r->cf))
3245 {
3246 number dd=n_Mult(d,h,r->cf);
3247 n_Delete(&d,r->cf);
3248 d=dd;
3249 }
3250 n_Delete(&h,r->cf);
3251 pIter(p);
3252 }
3253 return d;
3254}
3255#endif
3256
3257int p_Size(poly p, const ring r)
3258{
3259 int count = 0;
3260 if (r->cf->has_simple_Alloc)
3261 return pLength(p);
3262 while ( p != NULL )
3263 {
3264 count+= n_Size( pGetCoeff( p ), r->cf );
3265 pIter( p );
3266 }
3267 return count;
3268}
3269
3270/*2
3271*make p homogeneous by multiplying the monomials by powers of x_varnum
3272*assume: deg(var(varnum))==1
3273*/
3274poly p_Homogen (poly p, int varnum, const ring r)
3275{
3276 pFDegProc deg;
3277 if (r->pLexOrder && (r->order[0]==ringorder_lp))
3278 deg=p_Totaldegree;
3279 else
3280 deg=r->pFDeg;
3281
3282 poly q=NULL, qn;
3283 int o,ii;
3284 sBucket_pt bp;
3285
3286 if (p!=NULL)
3287 {
3288 if ((varnum < 1) || (varnum > rVar(r)))
3289 {
3290 return NULL;
3291 }
3292 o=deg(p,r);
3293 q=pNext(p);
3294 while (q != NULL)
3295 {
3296 ii=deg(q,r);
3297 if (ii>o) o=ii;
3298 pIter(q);
3299 }
3300 q = p_Copy(p,r);
3301 bp = sBucketCreate(r);
3302 while (q != NULL)
3303 {
3304 ii = o-deg(q,r);
3305 if (ii!=0)
3306 {
3307 p_AddExp(q,varnum, (long)ii,r);
3308 p_Setm(q,r);
3309 }
3310 qn = pNext(q);
3311 pNext(q) = NULL;
3312 sBucket_Add_m(bp, q);
3313 q = qn;
3314 }
3315 sBucketDestroyAdd(bp, &q, &ii);
3316 }
3317 return q;
3318}
3319
3320poly p_HomogenDP (poly p, int varnum, const ring r)
3321{
3322 poly q=NULL, qn;
3323 int o,ii;
3324 sBucket_pt bp;
3325
3326 if (p!=NULL)
3327 {
3328 if ((varnum < 1) || (varnum > rVar(r)))
3329 {
3330 return NULL;
3331 }
3332 o=p_Totaldegree(p,r);
3333 q=pNext(p);
3334 while (q != NULL)
3335 {
3336 ii=p_Totaldegree(q,r);
3337 if (ii>o) o=ii;
3338 pIter(q);
3339 }
3340 q = p_Copy(p,r);
3341 bp = sBucketCreate(r);
3342 while (q != NULL)
3343 {
3344 ii = o-p_Totaldegree(q,r);
3345 if (ii!=0)
3346 {
3347 p_AddExp(q,varnum, (long)ii,r);
3348 p_Setm(q,r);
3349 }
3350 qn = pNext(q);
3351 pNext(q) = NULL;
3352 sBucket_Add_m(bp, q);
3353 q = qn;
3354 }
3355 sBucketDestroyAdd(bp, &q, &ii);
3356 }
3357 return q;
3358}
3359
3360/*2
3361*tests if p is homogeneous with respect to the actual weights
3362*/
3363BOOLEAN p_IsHomogeneous (poly p, const ring r)
3364{
3365 poly qp=p;
3366 int o;
3367
3368 if ((p == NULL) || (pNext(p) == NULL)) return TRUE;
3369 pFDegProc d;
3370 if (r->pLexOrder && (r->order[0]==ringorder_lp))
3371 d=p_Totaldegree;
3372 else
3373 d=r->pFDeg;
3374 o = d(p,r);
3375 do
3376 {
3377 if (d(qp,r) != o) return FALSE;
3378 pIter(qp);
3379 }
3380 while (qp != NULL);
3381 return TRUE;
3382}
3383
3384/*2
3385*tests if p is homogeneous with respect to totaldegree
3386*/
3387BOOLEAN p_IsHomogeneousDP (poly p, const ring r)
3388{
3389 poly qp=p;
3390 int o;
3391
3392 if ((p == NULL) || (pNext(p) == NULL)) return TRUE;
3393 o = p_Totaldegree(p,r);
3394 do
3395 {
3396 if (p_Totaldegree(qp,r) != o) return FALSE;
3397 pIter(qp);
3398 }
3399 while (qp != NULL);
3400 return TRUE;
3401}
3402
3403/*2
3404*tests if p is homogeneous with respect to the given weights
3405*/
3406BOOLEAN p_IsHomogeneousW (poly p, const intvec *w, const ring r)
3407{
3408 poly qp=p;
3409 long o;
3410
3411 if ((p == NULL) || (pNext(p) == NULL)) return TRUE;
3412 pIter(qp);
3413 o = totaldegreeWecart_IV(p,r,w->ivGetVec());
3414 do
3415 {
3416 if (totaldegreeWecart_IV(qp,r,w->ivGetVec()) != o) return FALSE;
3417 pIter(qp);
3418 }
3419 while (qp != NULL);
3420 return TRUE;
3421}
3422
3423BOOLEAN p_IsHomogeneousW (poly p, const intvec *w, const intvec *module_w, const ring r)
3424{
3425 poly qp=p;
3426 long o;
3427
3428 if ((p == NULL) || (pNext(p) == NULL)) return TRUE;
3429 pIter(qp);
3430 o = totaldegreeWecart_IV(p,r,w->ivGetVec())+(*module_w)[p_GetComp(p,r)];
3431 do
3432 {
3433 long oo=totaldegreeWecart_IV(qp,r,w->ivGetVec())+(*module_w)[p_GetComp(qp,r)];
3434 if (oo != o) return FALSE;
3435 pIter(qp);
3436 }
3437 while (qp != NULL);
3438 return TRUE;
3439}
3440
3441/*----------utilities for syzygies--------------*/
3442BOOLEAN p_VectorHasUnitB(poly p, int * k, const ring r)
3443{
3444 poly q=p,qq;
3445 long unsigned i;
3446
3447 while (q!=NULL)
3448 {
3449 if (p_LmIsConstantComp(q,r))
3450 {
3451 i = __p_GetComp(q,r);
3452 qq = p;
3453 while ((qq != q) && (__p_GetComp(qq,r) != i)) pIter(qq);
3454 if (qq == q)
3455 {
3456 *k = i;
3457 return TRUE;
3458 }
3459 }
3460 pIter(q);
3461 }
3462 return FALSE;
3463}
3464
3465void p_VectorHasUnit(poly p, int * k, int * len, const ring r)
3466{
3467 poly q=p,qq;
3468 int j=0;
3469 long unsigned i;
3470
3471 *len = 0;
3472 while (q!=NULL)
3473 {
3474 if (p_LmIsConstantComp(q,r))
3475 {
3476 i = __p_GetComp(q,r);
3477 qq = p;
3478 while ((qq != q) && (__p_GetComp(qq,r) != i)) pIter(qq);
3479 if (qq == q)
3480 {
3481 j = 0;
3482 while (qq!=NULL)
3483 {
3484 if (__p_GetComp(qq,r)==i) j++;
3485 pIter(qq);
3486 }
3487 if ((*len == 0) || (j<*len))
3488 {
3489 *len = j;
3490 *k = i;
3491 }
3492 }
3493 }
3494 pIter(q);
3495 }
3496}
3497
3498poly p_TakeOutComp(poly * p, int k, const ring r)
3499{
3500 poly q = *p,qq=NULL,result = NULL;
3501 unsigned long kk=(unsigned long)k;
3502
3503 if (q==NULL) return NULL;
3504 BOOLEAN use_setmcomp=rOrd_SetCompRequiresSetm(r);
3505 if (__p_GetComp(q,r)==kk)
3506 {
3507 result = q;
3508 if (UNLIKELY(use_setmcomp))
3509 {
3510 do
3511 {
3512 p_SetComp(q,0,r);
3513 p_SetmComp(q,r);
3514 qq = q;
3515 pIter(q);
3516 }
3517 while ((q!=NULL) && (__p_GetComp(q,r)==kk));
3518 }
3519 else
3520 {
3521 do
3522 {
3523 p_SetComp(q,0,r);
3524 qq = q;
3525 pIter(q);
3526 }
3527 while ((q!=NULL) && (__p_GetComp(q,r)==kk));
3528 }
3529
3530 *p = q;
3531 pNext(qq) = NULL;
3532 }
3533 if (q==NULL) return result;
3534 if (__p_GetComp(q,r) > kk)
3535 {
3536 p_SubComp(q,1,r);
3537 if (use_setmcomp) p_SetmComp(q,r);
3538 }
3539 poly pNext_q;
3540 while ((pNext_q=pNext(q))!=NULL)
3541 {
3542 unsigned long c=__p_GetComp(pNext_q,r);
3543 if (/*__p_GetComp(pNext_q,r)*/c==kk)
3544 {
3545 if (result==NULL)
3546 {
3547 result = pNext_q;
3548 qq = result;
3549 }
3550 else
3551 {
3552 pNext(qq) = pNext_q;
3553 pIter(qq);
3554 }
3555 pNext(q) = pNext(pNext_q);
3556 pNext(qq) =NULL;
3557 p_SetComp(qq,0,r);
3558 if (use_setmcomp) p_SetmComp(qq,r);
3559 }
3560 else
3561 {
3562 /*pIter(q);*/ q=pNext_q;
3563 if (/*__p_GetComp(q,r)*/c > kk)
3564 {
3565 p_SubComp(q,1,r);
3566 if (use_setmcomp) p_SetmComp(q,r);
3567 }
3568 }
3569 }
3570 return result;
3571}
3572
3573// Splits *p into two polys: *q which consists of all monoms with
3574// component == comp and *p of all other monoms *lq == pLength(*q)
3575void p_TakeOutComp(poly *r_p, long comp, poly *r_q, int *lq, const ring r)
3576{
3577 spolyrec pp, qq;
3578 poly p, q, p_prev;
3579 int l = 0;
3580
3581#ifndef SING_NDEBUG
3582 int lp = pLength(*r_p);
3583#endif
3584
3585 pNext(&pp) = *r_p;
3586 p = *r_p;
3587 p_prev = &pp;
3588 q = &qq;
3589
3590 while(p != NULL)
3591 {
3592 while (__p_GetComp(p,r) == (unsigned long)comp)
3593 {
3594 pNext(q) = p;
3595 pIter(q);
3596 p_SetComp(p, 0,r);
3597 p_SetmComp(p,r);
3598 pIter(p);
3599 l++;
3600 if (p == NULL)
3601 {
3602 pNext(p_prev) = NULL;
3603 goto Finish;
3604 }
3605 }
3606 pNext(p_prev) = p;
3607 p_prev = p;
3608 pIter(p);
3609 }
3610
3611 Finish:
3612 pNext(q) = NULL;
3613 *r_p = pNext(&pp);
3614 *r_q = pNext(&qq);
3615 *lq = l;
3616#ifndef SING_NDEBUG
3617 assume(pLength(*r_p) + pLength(*r_q) == lp);
3618#endif
3619 p_Test(*r_p,r);
3620 p_Test(*r_q,r);
3621}
3622
3623void p_DeleteComp(poly * p,int k, const ring r)
3624{
3625 poly q;
3626 long unsigned kk=k;
3627
3628 while ((*p!=NULL) && (__p_GetComp(*p,r)==kk)) p_LmDelete(p,r);
3629 if (*p==NULL) return;
3630 q = *p;
3631 if (__p_GetComp(q,r)>kk)
3632 {
3633 p_SubComp(q,1,r);
3634 p_SetmComp(q,r);
3635 }
3636 while (pNext(q)!=NULL)
3637 {
3638 unsigned long c=__p_GetComp(pNext(q),r);
3639 if (/*__p_GetComp(pNext(q),r)*/c==kk)
3640 p_LmDelete(&(pNext(q)),r);
3641 else
3642 {
3643 pIter(q);
3644 if (/*__p_GetComp(q,r)*/c>kk)
3645 {
3646 p_SubComp(q,1,r);
3647 p_SetmComp(q,r);
3648 }
3649 }
3650 }
3651}
3652
3653poly p_Vec2Poly(poly v, int k, const ring r)
3654{
3655 poly h;
3656 poly res=NULL;
3657 long unsigned kk=k;
3658
3659 while (v!=NULL)
3660 {
3661 if (__p_GetComp(v,r)==kk)
3662 {
3663 h=p_Head(v,r);
3664 p_SetComp(h,0,r);
3665 pNext(h)=res;res=h;
3666 }
3667 pIter(v);
3668 }
3669 if (res!=NULL) res=pReverse(res);
3670 return res;
3671}
3672
3673/// vector to already allocated array (len>=p_MaxComp(v,r))
3674// also used for p_Vec2Polys
3675void p_Vec2Array(poly v, poly *p, int len, const ring r)
3676{
3677 poly h;
3678 int k;
3679
3680 for(int i=len-1;i>=0;i--) p[i]=NULL;
3681 while (v!=NULL)
3682 {
3683 h=p_Head(v,r);
3684 k=__p_GetComp(h,r);
3685 if (k>len) { Werror("wrong rank:%d, should be %d",len,k); }
3686 else
3687 {
3688 p_SetComp(h,0,r);
3689 p_Setm(h,r);
3690 pNext(h)=p[k-1];p[k-1]=h;
3691 }
3692 pIter(v);
3693 }
3694 for(int i=len-1;i>=0;i--)
3695 {
3696 if (p[i]!=NULL) p[i]=pReverse(p[i]);
3697 }
3698}
3699
3700/*2
3701* convert a vector to a set of polys,
3702* allocates the polyset, (entries 0..(*len)-1)
3703* the vector will not be changed
3704*/
3705void p_Vec2Polys(poly v, poly* *p, int *len, const ring r)
3706{
3707 *len=p_MaxComp(v,r);
3708 if (*len==0) *len=1;
3709 *p=(poly*)omAlloc((*len)*sizeof(poly));
3710 p_Vec2Array(v,*p,*len,r);
3711}
3712
3713//
3714// resets the pFDeg and pLDeg: if pLDeg is not given, it is
3715// set to currRing->pLDegOrig, i.e. to the respective LDegProc which
3716// only uses pFDeg (and not p_Deg, or pTotalDegree, etc)
3717void pSetDegProcs(ring r, pFDegProc new_FDeg, pLDegProc new_lDeg)
3718{
3719 assume(new_FDeg != NULL);
3720 r->pFDeg = new_FDeg;
3721
3722 if (new_lDeg == NULL)
3723 new_lDeg = r->pLDegOrig;
3724
3725 r->pLDeg = new_lDeg;
3726}
3727
3728// restores pFDeg and pLDeg:
3729void pRestoreDegProcs(ring r, pFDegProc old_FDeg, pLDegProc old_lDeg)
3730{
3731 assume(old_FDeg != NULL && old_lDeg != NULL);
3732 r->pFDeg = old_FDeg;
3733 r->pLDeg = old_lDeg;
3734}
3735
3736/*-------- several access procedures to monomials -------------------- */
3737/*
3738* the module weights for std
3739*/
3743
3744static long pModDeg(poly p, ring r)
3745{
3746 long d=pOldFDeg(p, r);
3747 int c=__p_GetComp(p, r);
3748 if ((c>0) && ((r->pModW)->range(c-1))) d+= (*(r->pModW))[c-1];
3749 return d;
3750 //return pOldFDeg(p, r)+(*pModW)[p_GetComp(p, r)-1];
3751}
3752
3753void p_SetModDeg(intvec *w, ring r)
3754{
3755 if (w!=NULL)
3756 {
3757 r->pModW = w;
3758 pOldFDeg = r->pFDeg;
3759 pOldLDeg = r->pLDeg;
3760 pOldLexOrder = r->pLexOrder;
3762 r->pLexOrder = TRUE;
3763 }
3764 else
3765 {
3766 r->pModW = NULL;
3768 r->pLexOrder = pOldLexOrder;
3769 }
3770}
3771
3772/*2
3773* handle memory request for sets of polynomials (ideals)
3774* l is the length of *p, increment is the difference (may be negative)
3775*/
3776void pEnlargeSet(poly* *p, int l, int increment)
3777{
3778 poly* h;
3779
3780 if (increment==0) return;
3781 if (*p==NULL)
3782 {
3783 h=(poly*)omAlloc0(increment*sizeof(poly));
3784 }
3785 else
3786 {
3787 h=(poly*)omReallocSize((poly*)*p,l*sizeof(poly),(l+increment)*sizeof(poly));
3788 if (increment>0)
3789 {
3790 memset(&(h[l]),0,increment*sizeof(poly));
3791 }
3792 }
3793 *p=h;
3794}
3795
3796/*2
3797*divides p1 by its leading coefficient
3798*/
3799void p_Norm(poly p1, const ring r)
3800{
3801 if (UNLIKELY(p1==NULL)) return;
3802 if (rField_is_Ring(r))
3803 {
3804 if(!n_GreaterZero(pGetCoeff(p1),r->cf)) p1 = p_Neg(p1,r);
3805 if (!n_IsUnit(pGetCoeff(p1), r->cf)) return;
3806 // Werror("p_Norm not possible in the case of coefficient rings.");
3807 }
3808 else //(p1!=NULL)
3809 {
3810 if (!n_IsOne(pGetCoeff(p1),r->cf))
3811 {
3812 if (UNLIKELY(pNext(p1)==NULL))
3813 {
3814 p_SetCoeff(p1,n_Init(1,r->cf),r);
3815 return;
3816 }
3817 number k = pGetCoeff(p1);
3818 pSetCoeff0(p1,n_Init(1,r->cf));
3819 poly h = pNext(p1);
3820 if (LIKELY(rField_is_Zp(r)))
3821 {
3822 if (r->cf->ch>32003)
3823 {
3824 number inv=n_Invers(k,r->cf);
3825 while (h!=NULL)
3826 {
3827 number c=n_Mult(pGetCoeff(h),inv,r->cf);
3828 // no need to normalize
3829 p_SetCoeff(h,c,r);
3830 pIter(h);
3831 }
3832 // no need for n_Delete for Zp: n_Delete(&inv,r->cf);
3833 }
3834 else
3835 {
3836 while (h!=NULL)
3837 {
3838 number c=n_Div(pGetCoeff(h),k,r->cf);
3839 // no need to normalize
3840 p_SetCoeff(h,c,r);
3841 pIter(h);
3842 }
3843 }
3844 }
3845 else if(getCoeffType(r->cf)==n_algExt)
3846 {
3847 n_Normalize(k,r->cf);
3848 number inv=n_Invers(k,r->cf);
3849 while (h!=NULL)
3850 {
3851 number c=n_Mult(pGetCoeff(h),inv,r->cf);
3852 // no need to normalize
3853 // normalize already in nMult: Zp_a, Q_a
3854 p_SetCoeff(h,c,r);
3855 pIter(h);
3856 }
3857 n_Delete(&inv,r->cf);
3858 n_Delete(&k,r->cf);
3859 }
3860 else
3861 {
3862 n_Normalize(k,r->cf);
3863 while (h!=NULL)
3864 {
3865 number c=n_Div(pGetCoeff(h),k,r->cf);
3866 // no need to normalize: Z/p, R
3867 // remains: Q
3868 if (rField_is_Q(r)) n_Normalize(c,r->cf);
3869 p_SetCoeff(h,c,r);
3870 pIter(h);
3871 }
3872 n_Delete(&k,r->cf);
3873 }
3874 }
3875 else
3876 {
3877 //if (r->cf->cfNormalize != nDummy2) //TODO: OPTIMIZE
3878 if (rField_is_Q(r))
3879 {
3880 poly h = pNext(p1);
3881 while (h!=NULL)
3882 {
3883 n_Normalize(pGetCoeff(h),r->cf);
3884 pIter(h);
3885 }
3886 }
3887 }
3888 }
3889}
3890
3891/*2
3892*normalize all coefficients
3893*/
3894void p_Normalize(poly p,const ring r)
3895{
3896 const coeffs cf=r->cf;
3897 /* Z/p, GF(p,n), R, long R/C, Nemo rings */
3898 if (cf->cfNormalize==ndNormalize)
3899 return;
3900 while (p!=NULL)
3901 {
3902 // no test before n_Normalize: n_Normalize should fix problems
3904 pIter(p);
3905 }
3906}
3907
3908// splits p into polys with Exp(n) == 0 and Exp(n) != 0
3909// Poly with Exp(n) != 0 is reversed
3910static void p_SplitAndReversePoly(poly p, int n, poly *non_zero, poly *zero, const ring r)
3911{
3912 if (p == NULL)
3913 {
3914 *non_zero = NULL;
3915 *zero = NULL;
3916 return;
3917 }
3918 spolyrec sz;
3919 poly z, n_z, next;
3920 z = &sz;
3921 n_z = NULL;
3922
3923 while(p != NULL)
3924 {
3925 next = pNext(p);
3926 if (p_GetExp(p, n,r) == 0)
3927 {
3928 pNext(z) = p;
3929 pIter(z);
3930 }
3931 else
3932 {
3933 pNext(p) = n_z;
3934 n_z = p;
3935 }
3936 p = next;
3937 }
3938 pNext(z) = NULL;
3939 *zero = pNext(&sz);
3940 *non_zero = n_z;
3941}
3942/*3
3943* substitute the n-th variable by 1 in p
3944* destroy p
3945*/
3946static poly p_Subst1 (poly p,int n, const ring r)
3947{
3948 poly qq=NULL, result = NULL;
3949 poly zero=NULL, non_zero=NULL;
3950
3951 // reverse, so that add is likely to be linear
3952 p_SplitAndReversePoly(p, n, &non_zero, &zero,r);
3953
3954 while (non_zero != NULL)
3955 {
3956 assume(p_GetExp(non_zero, n,r) != 0);
3957 qq = non_zero;
3958 pIter(non_zero);
3959 qq->next = NULL;
3960 p_SetExp(qq,n,0,r);
3961 p_Setm(qq,r);
3962 result = p_Add_q(result,qq,r);
3963 }
3964 p = p_Add_q(result, zero,r);
3965 p_Test(p,r);
3966 return p;
3967}
3968
3969/*3
3970* substitute the n-th variable by number e in p
3971* destroy p
3972*/
3973static poly p_Subst2 (poly p,int n, number e, const ring r)
3974{
3975 assume( ! n_IsZero(e,r->cf) );
3976 poly qq,result = NULL;
3977 number nn, nm;
3978 poly zero, non_zero;
3979
3980 // reverse, so that add is likely to be linear
3981 p_SplitAndReversePoly(p, n, &non_zero, &zero,r);
3982
3983 while (non_zero != NULL)
3984 {
3985 assume(p_GetExp(non_zero, n, r) != 0);
3986 qq = non_zero;
3987 pIter(non_zero);
3988 qq->next = NULL;
3989 n_Power(e, p_GetExp(qq, n, r), &nn,r->cf);
3990 nm = n_Mult(nn, pGetCoeff(qq),r->cf);
3991#ifdef HAVE_RINGS
3992 if (n_IsZero(nm,r->cf))
3993 {
3994 p_LmFree(&qq,r);
3995 n_Delete(&nm,r->cf);
3996 }
3997 else
3998#endif
3999 {
4000 p_SetCoeff(qq, nm,r);
4001 p_SetExp(qq, n, 0,r);
4002 p_Setm(qq,r);
4003 result = p_Add_q(result,qq,r);
4004 }
4005 n_Delete(&nn,r->cf);
4006 }
4007 p = p_Add_q(result, zero,r);
4008 p_Test(p,r);
4009 return p;
4010}
4011
4012
4013/* delete monoms whose n-th exponent is different from zero */
4014static poly p_Subst0(poly p, int n, const ring r)
4015{
4016 spolyrec res;
4017 poly h = &res;
4018 pNext(h) = p;
4019
4020 while (pNext(h)!=NULL)
4021 {
4022 if (p_GetExp(pNext(h),n,r)!=0)
4023 {
4024 p_LmDelete(&pNext(h),r);
4025 }
4026 else
4027 {
4028 pIter(h);
4029 }
4030 }
4031 p_Test(pNext(&res),r);
4032 return pNext(&res);
4033}
4034
4035/*2
4036* substitute the n-th variable by e in p
4037* destroy p
4038*/
4039poly p_Subst(poly p, int n, poly e, const ring r)
4040{
4041#ifdef HAVE_SHIFTBBA
4042 // also don't even use p_Subst0 for Letterplace
4043 if (rIsLPRing(r))
4044 {
4045 poly subst = p_LPSubst(p, n, e, r);
4046 p_Delete(&p, r);
4047 return subst;
4048 }
4049#endif
4050
4051 if (e == NULL) return p_Subst0(p, n,r);
4052
4053 if (p_IsConstant(e,r))
4054 {
4055 if (n_IsOne(pGetCoeff(e),r->cf)) return p_Subst1(p,n,r);
4056 else return p_Subst2(p, n, pGetCoeff(e),r);
4057 }
4058
4059#ifdef HAVE_PLURAL
4060 if (rIsPluralRing(r))
4061 {
4062 return nc_pSubst(p,n,e,r);
4063 }
4064#endif
4065
4066 int exponent,i;
4067 poly h, res, m;
4068 int *me,*ee;
4069 number nu,nu1;
4070
4071 me=(int *)omAlloc((rVar(r)+1)*sizeof(int));
4072 ee=(int *)omAlloc((rVar(r)+1)*sizeof(int));
4073 if (e!=NULL) p_GetExpV(e,ee,r);
4074 res=NULL;
4075 h=p;
4076 while (h!=NULL)
4077 {
4078 if ((e!=NULL) || (p_GetExp(h,n,r)==0))
4079 {
4080 m=p_Head(h,r);
4081 p_GetExpV(m,me,r);
4082 exponent=me[n];
4083 me[n]=0;
4084 for(i=rVar(r);i>0;i--)
4085 me[i]+=exponent*ee[i];
4086 p_SetExpV(m,me,r);
4087 if (e!=NULL)
4088 {
4089 n_Power(pGetCoeff(e),exponent,&nu,r->cf);
4090 nu1=n_Mult(pGetCoeff(m),nu,r->cf);
4091 n_Delete(&nu,r->cf);
4092 p_SetCoeff(m,nu1,r);
4093 }
4094 res=p_Add_q(res,m,r);
4095 }
4096 p_LmDelete(&h,r);
4097 }
4098 omFreeSize((ADDRESS)me,(rVar(r)+1)*sizeof(int));
4099 omFreeSize((ADDRESS)ee,(rVar(r)+1)*sizeof(int));
4100 return res;
4101}
4102
4103/*2
4104 * returns a re-ordered conversion of a number as a polynomial,
4105 * with permutation of parameters
4106 * NOTE: this only works for Frank's alg. & trans. fields
4107 */
4108poly n_PermNumber(const number z, const int *par_perm, const int , const ring src, const ring dst)
4109{
4110#if 0
4111 PrintS("\nSource Ring: \n");
4112 rWrite(src);
4113
4114 if(0)
4115 {
4116 number zz = n_Copy(z, src->cf);
4117 PrintS("z: "); n_Write(zz, src);
4118 n_Delete(&zz, src->cf);
4119 }
4120
4121 PrintS("\nDestination Ring: \n");
4122 rWrite(dst);
4123
4124 /*Print("\nOldPar: %d\n", OldPar);
4125 for( int i = 1; i <= OldPar; i++ )
4126 {
4127 Print("par(%d) -> par/var (%d)\n", i, par_perm[i-1]);
4128 }*/
4129#endif
4130 if( z == NULL )
4131 return NULL;
4132
4133 const coeffs srcCf = src->cf;
4134 assume( srcCf != NULL );
4135
4136 assume( !nCoeff_is_GF(srcCf) );
4137 assume( src->cf->extRing!=NULL );
4138
4139 poly zz = NULL;
4140
4141 const ring srcExtRing = srcCf->extRing;
4142 assume( srcExtRing != NULL );
4143
4144 const coeffs dstCf = dst->cf;
4145 assume( dstCf != NULL );
4146
4147 if( nCoeff_is_algExt(srcCf) ) // nCoeff_is_GF(srcCf)?
4148 {
4149 zz = (poly) z;
4150 if( zz == NULL ) return NULL;
4151 }
4152 else if (nCoeff_is_transExt(srcCf))
4153 {
4154 assume( !IS0(z) );
4155
4156 zz = NUM((fraction)z);
4157 p_Test (zz, srcExtRing);
4158
4159 if( zz == NULL ) return NULL;
4160 if( !DENIS1((fraction)z) )
4161 {
4162 if (!p_IsConstant(DEN((fraction)z),srcExtRing))
4163 WarnS("Not defined: Cannot map a rational fraction and make a polynomial out of it! Ignoring the denominator.");
4164 }
4165 }
4166 else
4167 {
4168 assume (FALSE);
4169 WerrorS("Number permutation is not implemented for this data yet!");
4170 return NULL;
4171 }
4172
4173 assume( zz != NULL );
4174 p_Test (zz, srcExtRing);
4175
4176 nMapFunc nMap = n_SetMap(srcExtRing->cf, dstCf);
4177
4178 assume( nMap != NULL );
4179
4180 poly qq;
4181 if ((par_perm == NULL) && (rPar(dst) != 0 && rVar (srcExtRing) > 0))
4182 {
4183 int* perm;
4184 perm=(int *)omAlloc0((rVar(srcExtRing)+1)*sizeof(int));
4185 for(int i=si_min(rVar(srcExtRing),rPar(dst));i>0;i--)
4186 perm[i]=-i;
4187 qq = p_PermPoly(zz, perm, srcExtRing, dst, nMap, NULL, rVar(srcExtRing)-1);
4188 omFreeSize ((ADDRESS)perm, (rVar(srcExtRing)+1)*sizeof(int));
4189 }
4190 else
4191 qq = p_PermPoly(zz, par_perm-1, srcExtRing, dst, nMap, NULL, rVar (srcExtRing)-1);
4192
4193 if(nCoeff_is_transExt(srcCf)
4194 && (!DENIS1((fraction)z))
4195 && p_IsConstant(DEN((fraction)z),srcExtRing))
4196 {
4197 number n=nMap(pGetCoeff(DEN((fraction)z)),srcExtRing->cf, dstCf);
4198 qq=p_Div_nn(qq,n,dst);
4199 n_Delete(&n,dstCf);
4200 p_Normalize(qq,dst);
4201 }
4202 p_Test (qq, dst);
4203
4204 return qq;
4205}
4206
4207
4208/*2
4209*returns a re-ordered copy of a polynomial, with permutation of the variables
4210*/
4211poly p_PermPoly (poly p, const int * perm, const ring oldRing, const ring dst,
4212 nMapFunc nMap, const int *par_perm, int OldPar, BOOLEAN use_mult)
4213{
4214#if 0
4215 p_Test(p, oldRing);
4216 PrintS("p_PermPoly::p: "); p_Write(p, oldRing, oldRing);
4217#endif
4218 const int OldpVariables = rVar(oldRing);
4219 poly result = NULL;
4220 poly result_last = NULL;
4221 poly aq = NULL; /* the map coefficient */
4222 poly qq; /* the mapped monomial */
4223 assume(dst != NULL);
4224 assume(dst->cf != NULL);
4225 #ifdef HAVE_PLURAL
4226 poly tmp_mm=p_One(dst);
4227 #endif
4228 while (p != NULL)
4229 {
4230 // map the coefficient
4231 if ( ((OldPar == 0) || (par_perm == NULL) || rField_is_GF(oldRing) || (nMap==ndCopyMap))
4232 && (nMap != NULL) )
4233 {
4234 qq = p_Init(dst);
4235 assume( nMap != NULL );
4236 number n = nMap(p_GetCoeff(p, oldRing), oldRing->cf, dst->cf);
4237 n_Test (n,dst->cf);
4238 if ( nCoeff_is_algExt(dst->cf) )
4239 n_Normalize(n, dst->cf);
4240 p_GetCoeff(qq, dst) = n;// Note: n can be a ZERO!!!
4241 }
4242 else
4243 {
4244 qq = p_One(dst);
4245// aq = naPermNumber(p_GetCoeff(p, oldRing), par_perm, OldPar, oldRing); // no dst???
4246// poly n_PermNumber(const number z, const int *par_perm, const int P, const ring src, const ring dst)
4247 aq = n_PermNumber(p_GetCoeff(p, oldRing), par_perm, OldPar, oldRing, dst);
4248 p_Test(aq, dst);
4249 if ( nCoeff_is_algExt(dst->cf) )
4250 p_Normalize(aq,dst);
4251 if (aq == NULL)
4252 p_SetCoeff(qq, n_Init(0, dst->cf),dst); // Very dirty trick!!!
4253 p_Test(aq, dst);
4254 }
4255 if (rRing_has_Comp(dst))
4256 p_SetComp(qq, p_GetComp(p, oldRing), dst);
4257 if ( n_IsZero(pGetCoeff(qq), dst->cf) )
4258 {
4259 p_LmDelete(&qq,dst);
4260 qq = NULL;
4261 }
4262 else
4263 {
4264 // map pars:
4265 int mapped_to_par = 0;
4266 for(int i = 1; i <= OldpVariables; i++)
4267 {
4268 int e = p_GetExp(p, i, oldRing);
4269 if (e != 0)
4270 {
4271 if (perm==NULL)
4272 p_SetExp(qq, i, e, dst);
4273 else if (perm[i]>0)
4274 {
4275 #ifdef HAVE_PLURAL
4276 if(use_mult)
4277 {
4278 p_SetExp(tmp_mm,perm[i],e,dst);
4279 p_Setm(tmp_mm,dst);
4280 qq=p_Mult_mm(qq,tmp_mm,dst);
4281 p_SetExp(tmp_mm,perm[i],0,dst);
4282
4283 }
4284 else
4285 #endif
4286 p_AddExp(qq,perm[i], e/*p_GetExp( p,i,oldRing)*/, dst);
4287 }
4288 else if (perm[i]<0)
4289 {
4290 number c = p_GetCoeff(qq, dst);
4291 if (rField_is_GF(dst))
4292 {
4293 assume( dst->cf->extRing == NULL );
4294 number ee = n_Param(1, dst);
4295 number eee;
4296 n_Power(ee, e, &eee, dst->cf); //nfDelete(ee,dst);
4297 ee = n_Mult(c, eee, dst->cf);
4298 //nfDelete(c,dst);nfDelete(eee,dst);
4299 pSetCoeff0(qq,ee);
4300 }
4301 else if (nCoeff_is_Extension(dst->cf))
4302 {
4303 const int par = -perm[i];
4304 assume( par > 0 );
4305// WarnS("longalg missing 3");
4306#if 1
4307 const coeffs C = dst->cf;
4308 assume( C != NULL );
4309 const ring R = C->extRing;
4310 assume( R != NULL );
4311 assume( par <= rVar(R) );
4312 poly pcn; // = (number)c
4313 assume( !n_IsZero(c, C) );
4314 if( nCoeff_is_algExt(C) )
4315 pcn = (poly) c;
4316 else // nCoeff_is_transExt(C)
4317 pcn = NUM((fraction)c);
4318 if (pNext(pcn) == NULL) // c->z
4319 p_AddExp(pcn, -perm[i], e, R);
4320 else /* more difficult: we have really to multiply: */
4321 {
4322 poly mmc = p_ISet(1, R);
4323 p_SetExp(mmc, -perm[i], e, R);
4324 p_Setm(mmc, R);
4325 number nnc;
4326 // convert back to a number: number nnc = mmc;
4327 if( nCoeff_is_algExt(C) )
4328 nnc = (number) mmc;
4329 else // nCoeff_is_transExt(C)
4330 nnc = ntInit(mmc, C);
4331 p_GetCoeff(qq, dst) = n_Mult((number)c, nnc, C);
4332 n_Delete((number *)&c, C);
4333 n_Delete((number *)&nnc, C);
4334 }
4335 mapped_to_par=1;
4336#endif
4337 }
4338 }
4339 else
4340 {
4341 /* this variable maps to 0 !*/
4342 p_LmDelete(&qq, dst);
4343 break;
4344 }
4345 }
4346 }
4347 if ( mapped_to_par && (qq!= NULL) && nCoeff_is_algExt(dst->cf) )
4348 {
4349 number n = p_GetCoeff(qq, dst);
4350 n_Normalize(n, dst->cf);
4351 p_GetCoeff(qq, dst) = n;
4352 }
4353 }
4354 pIter(p);
4355
4356#if 0
4357 p_Test(aq,dst);
4358 PrintS("aq: "); p_Write(aq, dst, dst);
4359#endif
4360
4361
4362#if 1
4363 if (qq!=NULL)
4364 {
4365 p_Setm(qq,dst);
4366
4367 p_Test(aq,dst);
4368 p_Test(qq,dst);
4369
4370#if 0
4371 PrintS("qq: "); p_Write(qq, dst, dst);
4372#endif
4373
4374 if (aq!=NULL)
4375 qq=p_Mult_q(aq,qq,dst);
4376 aq = qq;
4377 while (pNext(aq) != NULL) pIter(aq);
4378 if (result_last==NULL)
4379 {
4380 result=qq;
4381 }
4382 else
4383 {
4384 pNext(result_last)=qq;
4385 }
4386 result_last=aq;
4387 aq = NULL;
4388 }
4389 else if (aq!=NULL)
4390 {
4391 p_Delete(&aq,dst);
4392 }
4393 }
4394 result=p_SortAdd(result,dst);
4395#else
4396 // if (qq!=NULL)
4397 // {
4398 // pSetm(qq);
4399 // pTest(qq);
4400 // pTest(aq);
4401 // if (aq!=NULL) qq=pMult(aq,qq);
4402 // aq = qq;
4403 // while (pNext(aq) != NULL) pIter(aq);
4404 // pNext(aq) = result;
4405 // aq = NULL;
4406 // result = qq;
4407 // }
4408 // else if (aq!=NULL)
4409 // {
4410 // pDelete(&aq);
4411 // }
4412 //}
4413 //p = result;
4414 //result = NULL;
4415 //while (p != NULL)
4416 //{
4417 // qq = p;
4418 // pIter(p);
4419 // qq->next = NULL;
4420 // result = pAdd(result, qq);
4421 //}
4422#endif
4423 p_Test(result,dst);
4424#if 0
4425 p_Test(result,dst);
4426 PrintS("result: "); p_Write(result,dst,dst);
4427#endif
4428 #ifdef HAVE_PLURAL
4429 p_LmDelete(&tmp_mm,dst);
4430 #endif
4431 return result;
4432}
4433/**************************************************************
4434 *
4435 * Jet
4436 *
4437 **************************************************************/
4438
4439poly pp_Jet(poly p, int m, const ring R)
4440{
4441 poly r=NULL;
4442 poly t=NULL;
4443
4444 while (p!=NULL)
4445 {
4446 if (p_Totaldegree(p,R)<=m)
4447 {
4448 if (r==NULL)
4449 r=p_Head(p,R);
4450 else
4451 if (t==NULL)
4452 {
4453 pNext(r)=p_Head(p,R);
4454 t=pNext(r);
4455 }
4456 else
4457 {
4458 pNext(t)=p_Head(p,R);
4459 pIter(t);
4460 }
4461 }
4462 pIter(p);
4463 }
4464 return r;
4465}
4466
4467poly pp_Jet0(poly p, const ring R)
4468{
4469 poly r=NULL;
4470 poly t=NULL;
4471
4472 while (p!=NULL)
4473 {
4474 if (p_LmIsConstantComp(p,R))
4475 {
4476 if (r==NULL)
4477 r=p_Head(p,R);
4478 else
4479 if (t==NULL)
4480 {
4481 pNext(r)=p_Head(p,R);
4482 t=pNext(r);
4483 }
4484 else
4485 {
4486 pNext(t)=p_Head(p,R);
4487 pIter(t);
4488 }
4489 }
4490 pIter(p);
4491 }
4492 return r;
4493}
4494
4495poly p_Jet(poly p, int m,const ring R)
4496{
4497 while((p!=NULL) && (p_Totaldegree(p,R)>m)) p_LmDelete(&p,R);
4498 if (p==NULL) return NULL;
4499 poly r=p;
4500 while (pNext(p)!=NULL)
4501 {
4502 if (p_Totaldegree(pNext(p),R)>m)
4503 {
4504 p_LmDelete(&pNext(p),R);
4505 }
4506 else
4507 pIter(p);
4508 }
4509 return r;
4510}
4511
4512poly pp_JetW(poly p, int m, int *w, const ring R)
4513{
4514 poly r=NULL;
4515 poly t=NULL;
4516 while (p!=NULL)
4517 {
4518 if (totaldegreeWecart_IV(p,R,w)<=m)
4519 {
4520 if (r==NULL)
4521 r=p_Head(p,R);
4522 else
4523 if (t==NULL)
4524 {
4525 pNext(r)=p_Head(p,R);
4526 t=pNext(r);
4527 }
4528 else
4529 {
4530 pNext(t)=p_Head(p,R);
4531 pIter(t);
4532 }
4533 }
4534 pIter(p);
4535 }
4536 return r;
4537}
4538
4539poly p_JetW(poly p, int m, int *w, const ring R)
4540{
4541 while((p!=NULL) && (totaldegreeWecart_IV(p,R,w)>m)) p_LmDelete(&p,R);
4542 if (p==NULL) return NULL;
4543 poly r=p;
4544 while (pNext(p)!=NULL)
4545 {
4547 {
4548 p_LmDelete(&pNext(p),R);
4549 }
4550 else
4551 pIter(p);
4552 }
4553 return r;
4554}
4555
4556/*************************************************************/
4557int p_MinDeg(poly p,intvec *w, const ring R)
4558{
4559 if(p==NULL)
4560 return -1;
4561 int d=-1;
4562 while(p!=NULL)
4563 {
4564 int d0=0;
4565 for(int j=0;j<rVar(R);j++)
4566 if(w==NULL||j>=w->length())
4567 d0+=p_GetExp(p,j+1,R);
4568 else
4569 d0+=(*w)[j]*p_GetExp(p,j+1,R);
4570 if(d0<d||d==-1)
4571 d=d0;
4572 pIter(p);
4573 }
4574 return d;
4575}
4576
4577/***************************************************************/
4578static poly p_Invers(int n,poly u,intvec *w, const ring R)
4579{
4580 if(n<0)
4581 return NULL;
4582 number u0=n_Invers(pGetCoeff(u),R->cf);
4583 poly v=p_NSet(u0,R);
4584 if(n==0)
4585 return v;
4586 int *ww=iv2array(w,R);
4587 poly u1=p_JetW(p_Sub(p_One(R),__p_Mult_nn(u,u0,R),R),n,ww,R);
4588 if(u1==NULL)
4589 {
4590 omFreeSize((ADDRESS)ww,(rVar(R)+1)*sizeof(int));
4591 return v;
4592 }
4593 poly v1=__p_Mult_nn(p_Copy(u1,R),u0,R);
4594 v=p_Add_q(v,p_Copy(v1,R),R);
4595 for(int i=n/p_MinDeg(u1,w,R);i>1;i--)
4596 {
4597 v1=p_JetW(p_Mult_q(v1,p_Copy(u1,R),R),n,ww,R);
4598 v=p_Add_q(v,p_Copy(v1,R),R);
4599 }
4600 p_Delete(&u1,R);
4601 p_Delete(&v1,R);
4602 omFreeSize((ADDRESS)ww,(rVar(R)+1)*sizeof(int));
4603 return v;
4604}
4605
4606
4607poly p_Series(int n,poly p,poly u, intvec *w, const ring R)
4608{
4609 int *ww=iv2array(w,R);
4610 if(p!=NULL)
4611 {
4612 if(u==NULL)
4613 p=p_JetW(p,n,ww,R);
4614 else
4615 p=p_JetW(p_Mult_q(p,p_Invers(n-p_MinDeg(p,w,R),u,w,R),R),n,ww,R);
4616 }
4617 omFreeSize((ADDRESS)ww,(rVar(R)+1)*sizeof(int));
4618 return p;
4619}
4620
4621BOOLEAN p_EqualPolys(poly p1,poly p2, const ring r)
4622{
4623 while ((p1 != NULL) && (p2 != NULL))
4624 {
4625 if (! p_LmEqual(p1, p2,r))
4626 return FALSE;
4627 if (! n_Equal(p_GetCoeff(p1,r), p_GetCoeff(p2,r),r->cf ))
4628 return FALSE;
4629 pIter(p1);
4630 pIter(p2);
4631 }
4632 return (p1==p2);
4633}
4634
4635static inline BOOLEAN p_ExpVectorEqual(poly p1, poly p2, const ring r1, const ring r2)
4636{
4637 assume( r1 == r2 || rSamePolyRep(r1, r2) );
4638
4639 p_LmCheckPolyRing1(p1, r1);
4640 p_LmCheckPolyRing1(p2, r2);
4641
4642 int i = r1->ExpL_Size;
4643
4644 assume( r1->ExpL_Size == r2->ExpL_Size );
4645
4646 unsigned long *ep = p1->exp;
4647 unsigned long *eq = p2->exp;
4648
4649 do
4650 {
4651 i--;
4652 if (ep[i] != eq[i]) return FALSE;
4653 }
4654 while (i);
4655
4656 return TRUE;
4657}
4658
4659BOOLEAN p_EqualPolys(poly p1,poly p2, const ring r1, const ring r2)
4660{
4661 assume( r1 == r2 || rSamePolyRep(r1, r2) ); // will be used in rEqual!
4662 assume( r1->cf == r2->cf );
4663
4664 while ((p1 != NULL) && (p2 != NULL))
4665 {
4666 // returns 1 if ExpVector(p)==ExpVector(q): does not compare numbers !!
4667 // #define p_LmEqual(p1, p2, r) p_ExpVectorEqual(p1, p2, r)
4668
4669 if (! p_ExpVectorEqual(p1, p2, r1, r2))
4670 return FALSE;
4671
4672 if (! n_Equal(p_GetCoeff(p1,r1), p_GetCoeff(p2,r2), r1->cf ))
4673 return FALSE;
4674
4675 pIter(p1);
4676 pIter(p2);
4677 }
4678 return (p1==p2);
4679}
4680
4681/*2
4682*returns TRUE if p1 is a skalar multiple of p2
4683*assume p1 != NULL and p2 != NULL
4684*/
4685BOOLEAN p_ComparePolys(poly p1,poly p2, const ring r)
4686{
4687 number n,nn;
4688 pAssume(p1 != NULL && p2 != NULL);
4689
4690 if (!p_LmEqual(p1,p2,r)) //compare leading mons
4691 return FALSE;
4692 if ((pNext(p1)==NULL) && (pNext(p2)!=NULL))
4693 return FALSE;
4694 if ((pNext(p2)==NULL) && (pNext(p1)!=NULL))
4695 return FALSE;
4696 if (pLength(p1) != pLength(p2))
4697 return FALSE;
4698 #ifdef HAVE_RINGS
4699 if (rField_is_Ring(r))
4700 {
4701 if (!n_DivBy(pGetCoeff(p1), pGetCoeff(p2), r->cf)) return FALSE;
4702 }
4703 #endif
4704 n=n_Div(pGetCoeff(p1),pGetCoeff(p2),r->cf);
4705 while ((p1 != NULL) /*&& (p2 != NULL)*/)
4706 {
4707 if ( ! p_LmEqual(p1, p2,r))
4708 {
4709 n_Delete(&n, r->cf);
4710 return FALSE;
4711 }
4712 if (!n_Equal(pGetCoeff(p1), nn = n_Mult(pGetCoeff(p2),n, r->cf), r->cf))
4713 {
4714 n_Delete(&n, r->cf);
4715 n_Delete(&nn, r->cf);
4716 return FALSE;
4717 }
4718 n_Delete(&nn, r->cf);
4719 pIter(p1);
4720 pIter(p2);
4721 }
4722 n_Delete(&n, r->cf);
4723 return TRUE;
4724}
4725
4726/*2
4727* returns the length of a (numbers of monomials)
4728* respect syzComp
4729*/
4730poly p_Last(const poly p, int &l, const ring r)
4731{
4732 if (p == NULL)
4733 {
4734 l = 0;
4735 return NULL;
4736 }
4737 l = 1;
4738 poly a = p;
4739 if (! rIsSyzIndexRing(r))
4740 {
4741 poly next = pNext(a);
4742 while (next!=NULL)
4743 {
4744 a = next;
4745 next = pNext(a);
4746 l++;
4747 }
4748 }
4749 else
4750 {
4751 long unsigned curr_limit = rGetCurrSyzLimit(r);
4752 poly pp = a;
4753 while ((a=pNext(a))!=NULL)
4754 {
4755 if (__p_GetComp(a,r)<=curr_limit/*syzComp*/)
4756 l++;
4757 else break;
4758 pp = a;
4759 }
4760 a=pp;
4761 }
4762 return a;
4763}
4764
4765int p_Var(poly m,const ring r)
4766{
4767 if (m==NULL) return 0;
4768 if (pNext(m)!=NULL) return 0;
4769 int i,e=0;
4770 for (i=rVar(r); i>0; i--)
4771 {
4772 int exp=p_GetExp(m,i,r);
4773 if (exp==1)
4774 {
4775 if (e==0) e=i;
4776 else return 0;
4777 }
4778 else if (exp!=0)
4779 {
4780 return 0;
4781 }
4782 }
4783 return e;
4784}
4785
4786/*2
4787*the minimal index of used variables - 1
4788*/
4789int p_LowVar (poly p, const ring r)
4790{
4791 int k,l,lex;
4792
4793 if (p == NULL) return -1;
4794
4795 k = 32000;/*a very large dummy value*/
4796 while (p != NULL)
4797 {
4798 l = 1;
4799 lex = p_GetExp(p,l,r);
4800 while ((l < (rVar(r))) && (lex == 0))
4801 {
4802 l++;
4803 lex = p_GetExp(p,l,r);
4804 }
4805 l--;
4806 if (l < k) k = l;
4807 pIter(p);
4808 }
4809 return k;
4810}
4811
4812/*2
4813* verschiebt die Indizees der Modulerzeugenden um i
4814*/
4815void p_Shift (poly * p,int i, const ring r)
4816{
4817 poly qp1 = *p,qp2 = *p;/*working pointers*/
4818 int j = p_MaxComp(*p,r),k = p_MinComp(*p,r);
4819
4820 if (j+i < 0) return ;
4821 BOOLEAN toPoly= ((j == -i) && (j == k));
4822 while (qp1 != NULL)
4823 {
4824 if (toPoly || (__p_GetComp(qp1,r)+i > 0))
4825 {
4826 p_AddComp(qp1,i,r);
4827 p_SetmComp(qp1,r);
4828 qp2 = qp1;
4829 pIter(qp1);
4830 }
4831 else
4832 {
4833 if (qp2 == *p)
4834 {
4835 pIter(*p);
4836 p_LmDelete(&qp2,r);
4837 qp2 = *p;
4838 qp1 = *p;
4839 }
4840 else
4841 {
4842 qp2->next = qp1->next;
4843 if (qp1!=NULL) p_LmDelete(&qp1,r);
4844 qp1 = qp2->next;
4845 }
4846 }
4847 }
4848}
4849
4850/***************************************************************
4851 *
4852 * Storage Management Routines
4853 *
4854 ***************************************************************/
4855
4856
4857static inline unsigned long GetBitFields(const long e,
4858 const unsigned int s, const unsigned int n)
4859{
4860 unsigned int i = 0;
4861 unsigned long ev = 0L;
4862 assume(n > 0 && s < BIT_SIZEOF_LONG);
4863 do
4864 {
4866 if (e > (long) i) ev |= Sy_bitL(s+i);
4867 else break;
4868 i++;
4869 }
4870 while (i < n);
4871 return ev;
4872}
4873
4874// Short Exponent Vectors are used for fast divisibility tests
4875// ShortExpVectors "squeeze" an exponent vector into one word as follows:
4876// Let n = BIT_SIZEOF_LONG / pVariables.
4877// If n == 0 (i.e. pVariables > BIT_SIZE_OF_LONG), let m == the number
4878// of non-zero exponents. If (m>BIT_SIZEOF_LONG), then sev = ~0, else
4879// first m bits of sev are set to 1.
4880// Otherwise (i.e. pVariables <= BIT_SIZE_OF_LONG)
4881// represented by a bit-field of length n (resp. n+1 for some
4882// exponents). If the value of an exponent is greater or equal to n, then
4883// all of its respective n bits are set to 1. If the value of an exponent
4884// is smaller than n, say m, then only the first m bits of the respective
4885// n bits are set to 1, the others are set to 0.
4886// This way, we have:
4887// exp1 / exp2 ==> (ev1 & ~ev2) == 0, i.e.,
4888// if (ev1 & ~ev2) then exp1 does not divide exp2
4889unsigned long p_GetShortExpVector(const poly p, const ring r)
4890{
4891 assume(p != NULL);
4892 unsigned long ev = 0; // short exponent vector
4893 unsigned int n = BIT_SIZEOF_LONG / r->N; // number of bits per exp
4894 unsigned int m1; // highest bit which is filled with (n+1)
4895 unsigned int i=0;
4896 int j=1;
4897
4898 if (n == 0)
4899 {
4900 if (r->N <2*BIT_SIZEOF_LONG)
4901 {
4902 n=1;
4903 m1=0;
4904 }
4905 else
4906 {
4907 for (; j<=r->N; j++)
4908 {
4909 if (p_GetExp(p,j,r) > 0) i++;
4910 if (i == BIT_SIZEOF_LONG) break;
4911 }
4912 if (i>0)
4913 ev = ~(0UL) >> (BIT_SIZEOF_LONG - i);
4914 return ev;
4915 }
4916 }
4917 else
4918 {
4919 m1 = (n+1)*(BIT_SIZEOF_LONG - n*r->N);
4920 }
4921
4922 n++;
4923 while (i<m1)
4924 {
4925 ev |= GetBitFields(p_GetExp(p, j,r), i, n);
4926 i += n;
4927 j++;
4928 }
4929
4930 n--;
4931 while (i<BIT_SIZEOF_LONG)
4932 {
4933 ev |= GetBitFields(p_GetExp(p, j,r), i, n);
4934 i += n;
4935 j++;
4936 }
4937 return ev;
4938}
4939// 1 bit per exp
4940unsigned long p_GetShortExpVector0(const poly p, const ring r)
4941{
4942 assume(p != NULL);
4943 assume(r->N >=BIT_SIZEOF_LONG);
4944 unsigned long ev = 0; // short exponent vector
4945
4946 for (int j=BIT_SIZEOF_LONG; j>0; j--)
4947 {
4948 if (p_GetExp(p, j,r)>0)
4949 ev |= Sy_bitL(j-1);
4950 }
4951 return ev;
4952}
4953
4954//1..2 bits per exp
4955unsigned long p_GetShortExpVector1(const poly p, const ring r)
4956{
4957 assume(p != NULL);
4958 assume(r->N <BIT_SIZEOF_LONG);
4959 assume(2*r->N >=BIT_SIZEOF_LONG);
4960 unsigned long ev = 0; // short exponent vector
4961 int rest=r->N;
4962 int e;
4963 // 2 bits per exp
4964 int j=r->N;
4965 for (; j>BIT_SIZEOF_LONG-r->N; j--)
4966 {
4967 if ((e=p_GetExp(p, j,r))>0)
4968 {
4969 ev |= Sy_bitL(j-1);
4970 if (e>1)
4971 {
4972 ev|=Sy_bitL(rest+j-1);
4973 }
4974 }
4975 }
4976 // 1 bit per exp
4977 for (; j>0; j--)
4978 {
4979 if (p_GetExp(p, j,r)>0)
4980 {
4981 ev |= Sy_bitL(j-1);
4982 }
4983 }
4984 return ev;
4985}
4986
4987/***************************************************************
4988 *
4989 * p_ShallowDelete
4990 *
4991 ***************************************************************/
4992#undef LINKAGE
4993#define LINKAGE
4994#undef p_Delete__T
4995#define p_Delete__T p_ShallowDelete
4996#undef n_Delete__T
4997#define n_Delete__T(n, r) do {} while (0)
4998
5000
5001/***************************************************************/
5002/*
5003* compare a and b
5004*/
5005int p_Compare(const poly a, const poly b, const ring R)
5006{
5007 int r=p_Cmp(a,b,R);
5008 if ((r==0)&&(a!=NULL))
5009 {
5010 number h=n_Sub(pGetCoeff(a),pGetCoeff(b),R->cf);
5011 /* compare lead coeffs */
5012 r = -1+n_IsZero(h,R->cf)+2*n_GreaterZero(h,R->cf); /* -1: <, 0:==, 1: > */
5013 n_Delete(&h,R->cf);
5014 }
5015 else if (a==NULL)
5016 {
5017 if (b==NULL)
5018 {
5019 /* compare 0, 0 */
5020 r=0;
5021 }
5022 else if(p_IsConstant(b,R))
5023 {
5024 /* compare 0, const */
5025 r = 1-2*n_GreaterZero(pGetCoeff(b),R->cf); /* -1: <, 1: > */
5026 }
5027 }
5028 else if (b==NULL)
5029 {
5030 if (p_IsConstant(a,R))
5031 {
5032 /* compare const, 0 */
5033 r = -1+2*n_GreaterZero(pGetCoeff(a),R->cf); /* -1: <, 1: > */
5034 }
5035 }
5036 return(r);
5037}
5038
5039poly p_GcdMon(poly f, poly g, const ring r)
5040{
5041 assume(f!=NULL);
5042 assume(g!=NULL);
5043 assume(pNext(f)==NULL);
5044 poly G=p_Head(f,r);
5045 poly h=g;
5046 int *mf=(int*)omAlloc((r->N+1)*sizeof(int));
5047 p_GetExpV(f,mf,r);
5048 int *mh=(int*)omAlloc((r->N+1)*sizeof(int));
5049 BOOLEAN const_mon;
5050 BOOLEAN one_coeff=n_IsOne(pGetCoeff(G),r->cf);
5051 loop
5052 {
5053 if (h==NULL) break;
5054 if(!one_coeff)
5055 {
5056 number n=n_SubringGcd(pGetCoeff(G),pGetCoeff(h),r->cf);
5057 one_coeff=n_IsOne(n,r->cf);
5058 p_SetCoeff(G,n,r);
5059 }
5060 p_GetExpV(h,mh,r);
5061 const_mon=TRUE;
5062 for(unsigned j=r->N;j!=0;j--)
5063 {
5064 if (mh[j]<mf[j]) mf[j]=mh[j];
5065 if (mf[j]>0) const_mon=FALSE;
5066 }
5067 if (one_coeff && const_mon) break;
5068 pIter(h);
5069 }
5070 mf[0]=0;
5071 p_SetExpV(G,mf,r); // included is p_SetComp, p_Setm
5072 omFreeSize(mf,(r->N+1)*sizeof(int));
5073 omFreeSize(mh,(r->N+1)*sizeof(int));
5074 return G;
5075}
5076
5077poly p_CopyPowerProduct0(const poly p, number n, const ring r)
5078{
5080 poly np;
5081 omTypeAllocBin(poly, np, r->PolyBin);
5082 p_SetRingOfLm(np, r);
5083 memcpy(np->exp, p->exp, r->ExpL_Size*sizeof(long));
5084 pNext(np) = NULL;
5085 pSetCoeff0(np, n);
5086 return np;
5087}
5088
5089poly p_CopyPowerProduct(const poly p, const ring r)
5090{
5091 if (p == NULL) return NULL;
5092 return p_CopyPowerProduct0(p,n_Init(1,r->cf),r);
5093}
5094
5095poly p_Head0(const poly p, const ring r)
5096{
5097 if (p==NULL) return NULL;
5098 if (pGetCoeff(p)==NULL) return p_CopyPowerProduct0(p,NULL,r);
5099 return p_Head(p,r);
5100}
5101int p_MaxExpPerVar(poly p, int i, const ring r)
5102{
5103 int m=0;
5104 while(p!=NULL)
5105 {
5106 int mm=p_GetExp(p,i,r);
5107 if (mm>m) m=mm;
5108 pIter(p);
5109 }
5110 return m;
5111}
5112
Concrete implementation of enumerators over polynomials.
All the auxiliary stuff.
long int64
Definition auxiliary.h:68
static int si_max(const int a, const int b)
Definition auxiliary.h:125
#define BIT_SIZEOF_LONG
Definition auxiliary.h:80
#define UNLIKELY(X)
Definition auxiliary.h:405
int BOOLEAN
Definition auxiliary.h:88
#define TRUE
Definition auxiliary.h:101
#define FALSE
Definition auxiliary.h:97
#define LIKELY(X)
Definition auxiliary.h:404
void * ADDRESS
Definition auxiliary.h:120
static int si_min(const int a, const int b)
Definition auxiliary.h:126
CanonicalForm FACTORY_PUBLIC pp(const CanonicalForm &)
CanonicalForm pp ( const CanonicalForm & f )
Definition cf_gcd.cc:676
Array< CanonicalForm > CFArray
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
return
Variable x
Definition cfModGcd.cc:4090
int p
Definition cfModGcd.cc:4086
g
Definition cfModGcd.cc:4098
CanonicalForm cf
Definition cfModGcd.cc:4091
CanonicalForm b
Definition cfModGcd.cc:4111
FILE * f
Definition checklibs.c:9
poly singclap_pdivide(poly f, poly g, const ring r)
Definition clapsing.cc:624
This is a polynomial enumerator for simple iteration over coefficients of polynomials.
static FORCE_INLINE number n_Mult(number a, number b, const coeffs r)
return the product of 'a' and 'b', i.e., a*b
Definition coeffs.h:637
static FORCE_INLINE number n_Param(const int iParameter, const coeffs r)
return the (iParameter^th) parameter as a NEW number NOTE: parameter numbering: 1....
Definition coeffs.h:776
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of 'n'
Definition coeffs.h:455
static FORCE_INLINE number n_NormalizeHelper(number a, number b, const coeffs r)
assume that r is a quotient field (otherwise, return 1) for arguments (a1/a2,b1/b2) return (lcm(a1,...
Definition coeffs.h:696
static FORCE_INLINE number n_GetDenom(number &n, const coeffs r)
return the denominator of n (if elements of r are by nature not fractional, result is 1)
Definition coeffs.h:604
static FORCE_INLINE BOOLEAN nCoeff_is_GF(const coeffs r)
Definition coeffs.h:832
static FORCE_INLINE BOOLEAN nCoeff_is_Extension(const coeffs r)
Definition coeffs.h:839
number ndCopyMap(number a, const coeffs src, const coeffs dst)
Definition numbers.cc:287
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition coeffs.h:713
@ n_algExt
used for all algebraic extensions, i.e., the top-most extension in an extension tower is algebraic
Definition coeffs.h:35
@ n_transExt
used for all transcendental extensions, i.e., the top-most extension in an extension tower is transce...
Definition coeffs.h:38
static FORCE_INLINE number n_Gcd(number a, number b, const coeffs r)
in Z: return the gcd of 'a' and 'b' in Z/nZ, Z/2^kZ: computed as in the case Z in Z/pZ,...
Definition coeffs.h:665
static FORCE_INLINE number n_Invers(number a, const coeffs r)
return the multiplicative inverse of 'a'; raise an error if 'a' is not invertible
Definition coeffs.h:565
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:519
static FORCE_INLINE number n_ExactDiv(number a, number b, const coeffs r)
assume that there is a canonical subring in cf and we know that division is possible for these a and ...
Definition coeffs.h:623
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:498
static FORCE_INLINE nMapFunc n_SetMap(const coeffs src, const coeffs dst)
set the mapping function pointers for translating numbers from src to dst
Definition coeffs.h:701
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:558
static FORCE_INLINE void n_Power(number a, int b, number *res, const coeffs r)
fill res with the power a^b
Definition coeffs.h:633
static FORCE_INLINE number n_Farey(number a, number b, const coeffs r)
Definition coeffs.h:760
static FORCE_INLINE number n_Div(number a, number b, const coeffs r)
return the quotient of 'a' and 'b', i.e., a/b; raises an error if 'b' is not invertible in r exceptio...
Definition coeffs.h:616
static FORCE_INLINE BOOLEAN nCoeff_is_Q(const coeffs r)
Definition coeffs.h:799
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
Definition coeffs.h:468
static FORCE_INLINE int n_Size(number n, const coeffs r)
return a non-negative measure for the complexity of n; return 0 only when n represents zero; (used fo...
Definition coeffs.h:571
static FORCE_INLINE number n_GetUnit(number n, const coeffs r)
in Z: 1 in Z/kZ (where k is not a prime): largest divisor of n (taken in Z) that is co-prime with k i...
Definition coeffs.h:535
static FORCE_INLINE number n_Sub(number a, number b, const coeffs r)
return the difference of 'a' and 'b', i.e., a-b
Definition coeffs.h:656
static FORCE_INLINE void n_ClearDenominators(ICoeffsEnumerator &numberCollectionEnumerator, number &d, const coeffs r)
(inplace) Clears denominators on a collection of numbers number d is the LCM of all the coefficient d...
Definition coeffs.h:932
static FORCE_INLINE BOOLEAN nCoeff_is_Ring(const coeffs r)
Definition coeffs.h:730
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition coeffs.h:429
static FORCE_INLINE number n_ChineseRemainderSym(number *a, number *b, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs r)
Definition coeffs.h:757
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition coeffs.h:459
static FORCE_INLINE void n_Write(number n, const coeffs r, const BOOLEAN bShortOut=TRUE)
Definition coeffs.h:592
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition coeffs.h:793
static FORCE_INLINE BOOLEAN nCoeff_is_Q_a(const coeffs r)
Definition coeffs.h:878
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:539
static FORCE_INLINE void n_ClearContent(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs r)
Computes the content and (inplace) divides it out on a collection of numbers number c is the content ...
Definition coeffs.h:925
static FORCE_INLINE BOOLEAN n_DivBy(number a, number b, const coeffs r)
test whether 'a' is divisible 'b'; for r encoding a field: TRUE iff 'b' does not represent zero in Z:...
Definition coeffs.h:748
static FORCE_INLINE BOOLEAN nCoeff_is_algExt(const coeffs r)
TRUE iff r represents an algebraic extension field.
Definition coeffs.h:903
static FORCE_INLINE const char * n_Read(const char *s, number *a, const coeffs r)
!!! Recommendation: This method is too cryptic to be part of the user- !!! interface....
Definition coeffs.h:599
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:464
static FORCE_INLINE number n_GetNumerator(number &n, const coeffs r)
return the numerator of n (if elements of r are by nature not fractional, result is n)
Definition coeffs.h:609
static FORCE_INLINE number n_SubringGcd(number a, number b, const coeffs r)
Definition coeffs.h:667
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition coeffs.h:80
static FORCE_INLINE void n_Normalize(number &n, const coeffs r)
inplace-normalization of n; produces some canonical representation of n;
Definition coeffs.h:579
static FORCE_INLINE BOOLEAN n_IsOne(number n, const coeffs r)
TRUE iff 'n' represents the one element.
Definition coeffs.h:472
static FORCE_INLINE BOOLEAN nCoeff_is_transExt(const coeffs r)
TRUE iff r represents a transcendental extension field.
Definition coeffs.h:911
#define Print
Definition emacs.cc:80
#define WarnS
Definition emacs.cc:78
return result
const CanonicalForm int s
Definition facAbsFact.cc:51
const CanonicalForm int const CFList const Variable & y
Definition facAbsFact.cc:53
CanonicalForm res
Definition facAbsFact.cc:60
const CanonicalForm & w
Definition facAbsFact.cc:51
CanonicalForm subst(const CanonicalForm &f, const CFList &a, const CFList &b, const CanonicalForm &Rstar, bool isFunctionField)
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
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
VAR short errorreported
Definition feFopen.cc:23
void WerrorS(const char *s)
Definition feFopen.cc:24
const char * eati(const char *s, int *i)
Definition reporter.cc:373
#define D(A)
Definition gentable.cc:128
#define STATIC_VAR
Definition globaldefs.h:7
#define VAR
Definition globaldefs.h:5
STATIC_VAR poly last
Definition hdegree.cc:1137
#define exponent
STATIC_VAR int offset
Definition janet.cc:29
STATIC_VAR TreeM * G
Definition janet.cc:31
STATIC_VAR Poly * h
Definition janet.cc:971
ListNode * next
Definition janet.h:31
static bool rIsSCA(const ring r)
Definition nc.h:190
poly nc_pSubst(poly p, int n, poly e, const ring r)
substitute the n-th variable by e in p destroy p e is not a constant
LINLINE number nlAdd(number la, number li, const coeffs r)
Definition longrat.cc:2693
LINLINE number nlSub(number la, number li, const coeffs r)
Definition longrat.cc:2759
LINLINE void nlDelete(number *a, const coeffs r)
Definition longrat.cc:2658
BOOLEAN nlGreaterZero(number za, const coeffs r)
Definition longrat.cc:1304
number nlGcd(number a, number b, const coeffs r)
Definition longrat.cc:1341
void nlNormalize(number &x, const coeffs r)
Definition longrat.cc:1482
#define assume(x)
Definition mod2.h:389
int dReportError(const char *fmt,...)
Definition dError.cc:44
#define p_GetComp(p, r)
Definition monomials.h:64
#define pIter(p)
Definition monomials.h:37
#define pNext(p)
Definition monomials.h:36
#define p_LmCheckPolyRing1(p, r)
Definition monomials.h:177
#define p_LmCheckPolyRing2(p, r)
Definition monomials.h:199
#define pSetCoeff0(p, n)
Definition monomials.h:59
#define p_GetCoeff(p, r)
Definition monomials.h:50
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 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
#define pAssume(cond)
Definition monomials.h:90
gmp_float exp(const gmp_float &a)
The main handler for Singular numbers which are suitable for Singular polynomials.
Definition lq.h:40
number ndGcd(number, number, const coeffs r)
Definition numbers.cc:187
void ndNormalize(number &, const coeffs)
Definition numbers.cc:185
#define omFreeSize(addr, size)
#define omAlloc(size)
#define omReallocSize(addr, o_size, size)
#define omTypeAllocBin(type, addr, bin)
#define omFree(addr)
#define omAlloc0(size)
#define NULL
Definition omList.c:12
#define TEST_OPT_INTSTRATEGY
Definition options.h:112
#define Sy_bitL(x)
Definition options.h:32
#define TEST_OPT_PROT
Definition options.h:105
#define TEST_OPT_CONTENTSB
Definition options.h:129
poly p_Diff(poly a, int k, const ring r)
Definition p_polys.cc:1902
poly p_GetMaxExpP(poly p, const ring r)
return monomial r such that GetExp(r,i) is maximum of all monomials in p; coeff == 0,...
Definition p_polys.cc:1139
poly p_DivideM(poly a, poly b, const ring r)
Definition p_polys.cc:1582
int p_IsPurePower(const poly p, const ring r)
return i, if head depends only on var(i)
Definition p_polys.cc:1227
void p_Setm_WFirstTotalDegree(poly p, const ring r)
Definition p_polys.cc:553
poly pp_Jet(poly p, int m, const ring R)
Definition p_polys.cc:4439
STATIC_VAR pLDegProc pOldLDeg
Definition p_polys.cc:3741
void p_Cleardenom_n(poly ph, const ring r, number &c)
Definition p_polys.cc:2958
long pLDegb(poly p, int *l, const ring r)
Definition p_polys.cc:812
long pLDeg1_Totaldegree(poly p, int *l, const ring r)
Definition p_polys.cc:976
long p_WFirstTotalDegree(poly p, const ring r)
Definition p_polys.cc:595
poly p_HomogenDP(poly p, int varnum, const ring r)
Definition p_polys.cc:3320
poly p_Farey(poly p, number N, const ring r)
Definition p_polys.cc:54
long pLDeg1_WFirstTotalDegree(poly p, int *l, const ring r)
Definition p_polys.cc:1039
void pRestoreDegProcs(ring r, pFDegProc old_FDeg, pLDegProc old_lDeg)
Definition p_polys.cc:3729
long pLDeg1c_WFirstTotalDegree(poly p, int *l, const ring r)
Definition p_polys.cc:1069
poly n_PermNumber(const number z, const int *par_perm, const int, const ring src, const ring dst)
Definition p_polys.cc:4108
static poly p_DiffOpM(poly a, poly b, BOOLEAN multiply, const ring r)
Definition p_polys.cc:1938
poly p_PolyDiv(poly &p, const poly divisor, const BOOLEAN needResult, const ring r)
assumes that p and divisor are univariate polynomials in r, mentioning the same variable; assumes div...
Definition p_polys.cc:1874
int p_Size(poly p, const ring r)
Definition p_polys.cc:3257
void p_Setm_Dummy(poly p, const ring r)
Definition p_polys.cc:540
static poly p_Invers(int n, poly u, intvec *w, const ring R)
Definition p_polys.cc:4578
poly p_GcdMon(poly f, poly g, const ring r)
polynomial gcd for f=mon
Definition p_polys.cc:5039
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:4685
int p_LowVar(poly p, const ring r)
the minimal index of used variables - 1
Definition p_polys.cc:4789
BOOLEAN p_DivisibleByRingCase(poly f, poly g, const ring r)
divisibility check over ground ring (which may contain zero divisors); TRUE iff LT(f) divides LT(g),...
Definition p_polys.cc:1646
poly p_Homogen(poly p, int varnum, const ring r)
Definition p_polys.cc:3274
poly p_Subst(poly p, int n, poly e, const ring r)
Definition p_polys.cc:4039
static BOOLEAN p_ExpVectorEqual(poly p1, poly p2, const ring r1, const ring r2)
Definition p_polys.cc:4635
BOOLEAN p_HasNotCF(poly p1, poly p2, const ring r)
Definition p_polys.cc:1330
void p_Content(poly ph, const ring r)
Definition p_polys.cc:2299
int p_Weight(int i, const ring r)
Definition p_polys.cc:706
void p_Setm_TotalDegree(poly p, const ring r)
Definition p_polys.cc:546
poly p_CopyPowerProduct(const poly p, const ring r)
like p_Head, but with coefficient 1
Definition p_polys.cc:5089
poly pp_DivideM(poly a, poly b, const ring r)
Definition p_polys.cc:1637
STATIC_VAR int _componentsExternal
Definition p_polys.cc:148
void p_SimpleContent(poly ph, int smax, const ring r)
Definition p_polys.cc:2568
poly p_ISet(long i, const ring r)
returns the poly representing the integer i
Definition p_polys.cc:1298
STATIC_VAR long * _componentsShifted
Definition p_polys.cc:147
void p_Vec2Polys(poly v, poly **p, int *len, const ring r)
Definition p_polys.cc:3705
static poly p_Subst0(poly p, int n, const ring r)
Definition p_polys.cc:4014
poly p_DiffOp(poly a, poly b, BOOLEAN multiply, const ring r)
Definition p_polys.cc:1977
static unsigned long p_GetMaxExpL2(unsigned long l1, unsigned long l2, const ring r, unsigned long number_of_exp)
Definition p_polys.cc:1108
poly p_Jet(poly p, int m, const ring R)
Definition p_polys.cc:4495
poly p_TakeOutComp(poly *p, int k, const ring r)
Definition p_polys.cc:3498
long pLDeg1c_Deg(poly p, int *l, const ring r)
Definition p_polys.cc:942
long pLDeg1(poly p, int *l, const ring r)
Definition p_polys.cc:842
static number * pnBin(int exp, const ring r)
Definition p_polys.cc:2062
void p_Shift(poly *p, int i, const ring r)
shifts components of the vector p by i
Definition p_polys.cc:4815
static void pnFreeBin(number *bin, int exp, const coeffs r)
Definition p_polys.cc:2093
poly p_PermPoly(poly p, const int *perm, const ring oldRing, const ring dst, nMapFunc nMap, const int *par_perm, int OldPar, BOOLEAN use_mult)
Definition p_polys.cc:4211
poly p_Power(poly p, int i, const ring r)
Definition p_polys.cc:2201
poly p_Div_nn(poly p, const number n, const ring r)
Definition p_polys.cc:1506
void p_Normalize(poly p, const ring r)
Definition p_polys.cc:3894
unsigned long p_GetShortExpVector0(const poly p, const ring r)
Definition p_polys.cc:4940
void p_DeleteComp(poly *p, int k, const ring r)
Definition p_polys.cc:3623
poly p_mInit(const char *st, BOOLEAN &ok, const ring r)
Definition p_polys.cc:1443
poly p_MDivide(poly a, poly b, const ring r)
Definition p_polys.cc:1493
void p_ContentRat(poly &ph, const ring r)
Definition p_polys.cc:1748
void p_Norm(poly p1, const ring r)
Definition p_polys.cc:3799
poly p_Div_mm(poly p, const poly m, const ring r)
divide polynomial by monomial
Definition p_polys.cc:1542
poly pp_Jet0(poly p, const ring R)
Definition p_polys.cc:4467
int p_GetVariables(poly p, int *e, const ring r)
set entry e[i] to 1 if var(i) occurs in p, ignore var(j) if e[j]>0 return #(e[i]>0)
Definition p_polys.cc:1268
int p_MinDeg(poly p, intvec *w, const ring R)
Definition p_polys.cc:4557
int p_MaxExpPerVar(poly p, int i, const ring r)
max exponent of variable x_i in p
Definition p_polys.cc:5101
STATIC_VAR BOOLEAN pOldLexOrder
Definition p_polys.cc:3742
int p_Compare(const poly a, const poly b, const ring R)
Definition p_polys.cc:5005
void p_Setm_Syz(poly p, ring r, int *Components, long *ShiftedComponents)
Definition p_polys.cc:530
STATIC_VAR pFDegProc pOldFDeg
Definition p_polys.cc:3740
void p_LmDeleteAndNextRat(poly *p, int ishift, ring r)
Definition p_polys.cc:1704
unsigned long p_GetShortExpVector(const poly p, const ring r)
Definition p_polys.cc:4889
BOOLEAN p_IsHomogeneousW(poly p, const intvec *w, const ring r)
Definition p_polys.cc:3406
VAR BOOLEAN pSetm_error
Definition p_polys.cc:150
long pLDeg1_Deg(poly p, int *l, const ring r)
Definition p_polys.cc:911
poly p_Series(int n, poly p, poly u, intvec *w, const ring R)
Definition p_polys.cc:4607
void p_ProjectiveUnique(poly ph, const ring r)
Definition p_polys.cc:3147
long p_WTotaldegree(poly p, const ring r)
Definition p_polys.cc:612
long p_DegW(poly p, const int *w, const ring R)
Definition p_polys.cc:691
p_SetmProc p_GetSetmProc(const ring r)
Definition p_polys.cc:559
void p_Setm_General(poly p, const ring r)
Definition p_polys.cc:158
BOOLEAN p_OneComp(poly p, const ring r)
return TRUE if all monoms have the same component
Definition p_polys.cc:1209
poly p_Cleardenom(poly p, const ring r)
Definition p_polys.cc:2849
long pLDeg1c(poly p, int *l, const ring r)
Definition p_polys.cc:878
void p_Split(poly p, poly *h)
Definition p_polys.cc:1321
long pLDeg1c_Totaldegree(poly p, int *l, const ring r)
Definition p_polys.cc:1006
poly p_GetCoeffRat(poly p, int ishift, ring r)
Definition p_polys.cc:1726
BOOLEAN p_VectorHasUnitB(poly p, int *k, const ring r)
Definition p_polys.cc:3442
long pLDeg0c(poly p, int *l, const ring r)
Definition p_polys.cc:771
poly p_Vec2Poly(poly v, int k, const ring r)
Definition p_polys.cc:3653
poly p_LcmRat(const poly a, const poly b, const long lCompM, const ring r)
Definition p_polys.cc:1681
unsigned long p_GetMaxExpL(poly p, const ring r, unsigned long l_max)
return the maximal exponent of p in form of the maximal long var
Definition p_polys.cc:1176
static poly p_TwoMonPower(poly p, int exp, const ring r)
Definition p_polys.cc:2110
void p_SetModDeg(intvec *w, ring r)
Definition p_polys.cc:3753
BOOLEAN p_HasNotCFRing(poly p1, poly p2, const ring r)
Definition p_polys.cc:1346
long pLDeg0(poly p, int *l, const ring r)
Definition p_polys.cc:740
int p_Var(poly m, const ring r)
Definition p_polys.cc:4765
poly p_One(const ring r)
Definition p_polys.cc:1314
poly p_Sub(poly p1, poly p2, const ring r)
Definition p_polys.cc:1994
void p_VectorHasUnit(poly p, int *k, int *len, const ring r)
Definition p_polys.cc:3465
static void p_SplitAndReversePoly(poly p, int n, poly *non_zero, poly *zero, const ring r)
Definition p_polys.cc:3910
int p_IsUnivariate(poly p, const ring r)
return i, if poly depends only on var(i)
Definition p_polys.cc:1248
STATIC_VAR int * _components
Definition p_polys.cc:146
poly p_NSet(number n, const ring r)
returns the poly representing the number n, destroys n
Definition p_polys.cc:1474
void pSetDegProcs(ring r, pFDegProc new_FDeg, pLDegProc new_lDeg)
Definition p_polys.cc:3717
void pEnlargeSet(poly **p, int l, int increment)
Definition p_polys.cc:3776
long p_WDegree(poly p, const ring r)
Definition p_polys.cc:715
static long pModDeg(poly p, ring r)
Definition p_polys.cc:3744
BOOLEAN p_IsHomogeneous(poly p, const ring r)
Definition p_polys.cc:3363
poly p_Head0(const poly p, const ring r)
like p_Head, but allow NULL coeff
Definition p_polys.cc:5095
static poly p_MonMultC(poly p, poly q, const ring rr)
Definition p_polys.cc:2048
unsigned long p_GetShortExpVector1(const poly p, const ring r)
Definition p_polys.cc:4955
static poly p_Pow_charp(poly p, int i, const ring r)
Definition p_polys.cc:2189
poly pp_JetW(poly p, int m, int *w, const ring R)
Definition p_polys.cc:4512
long p_Deg(poly a, const ring r)
Definition p_polys.cc:586
static poly p_Subst1(poly p, int n, const ring r)
Definition p_polys.cc:3946
poly p_Last(const poly p, int &l, const ring r)
Definition p_polys.cc:4730
poly p_CopyPowerProduct0(const poly p, number n, const ring r)
like p_Head, but with coefficient n
Definition p_polys.cc:5077
static void p_MonMult(poly p, poly q, const ring r)
Definition p_polys.cc:2028
BOOLEAN p_IsHomogeneousDP(poly p, const ring r)
Definition p_polys.cc:3387
number p_InitContent(poly ph, const ring r)
Definition p_polys.cc:2639
void p_Vec2Array(poly v, poly *p, int len, const ring r)
vector to already allocated array (len>=p_MaxComp(v,r))
Definition p_polys.cc:3675
static poly p_MonPower(poly p, int exp, const ring r)
Definition p_polys.cc:2004
void p_ContentForGB(poly ph, const ring r)
Definition p_polys.cc:2359
static poly p_Subst2(poly p, int n, number e, const ring r)
Definition p_polys.cc:3973
void p_Lcm(const poly a, const poly b, poly m, const ring r)
Definition p_polys.cc:1659
static unsigned long GetBitFields(const long e, const unsigned int s, const unsigned int n)
Definition p_polys.cc:4857
poly p_ChineseRemainder(poly *xx, number *x, number *q, int rl, CFArray &inv_cache, const ring R)
Definition p_polys.cc:88
const char * p_Read(const char *st, poly &rc, const ring r)
Definition p_polys.cc:1371
poly p_JetW(poly p, int m, int *w, const ring R)
Definition p_polys.cc:4539
BOOLEAN p_EqualPolys(poly p1, poly p2, const ring r)
Definition p_polys.cc:4621
static poly p_Pow(poly p, int i, const ring r)
Definition p_polys.cc:2175
static poly p_Neg(poly p, const ring r)
Definition p_polys.h:1109
static int pLength(poly a)
Definition p_polys.h:190
static void p_ExpVectorSum(poly pr, poly p1, poly p2, const ring r)
Definition p_polys.h:1441
static poly p_Add_q(poly p, poly q, const ring r)
Definition p_polys.h:938
static void p_LmDelete(poly p, const ring r)
Definition p_polys.h:725
static poly p_Mult_q(poly p, poly q, const ring r)
Definition p_polys.h:1120
BOOLEAN p_LmCheckPolyRing(poly p, ring r)
Definition pDebug.cc:123
static void p_ExpVectorAdd(poly p1, poly p2, const ring r)
Definition p_polys.h:1427
static unsigned long p_SubComp(poly p, unsigned long v, ring r)
Definition p_polys.h:455
static long p_AddExp(poly p, int v, long ee, ring r)
Definition p_polys.h:608
static poly p_LmInit(poly p, const ring r)
Definition p_polys.h:1351
#define p_LmEqual(p1, p2, r)
Definition p_polys.h:1739
static int p_Cmp(poly p1, poly p2, ring r)
Definition p_polys.h:1743
void p_Write(poly p, ring lmRing, ring tailRing)
Definition polys0.cc:342
static void p_SetExpV(poly p, int *ev, const ring r)
Definition p_polys.h:1560
static int p_Comp_k_n(poly a, poly b, int k, ring r)
Definition p_polys.h:642
static void p_SetCompP(poly p, int i, ring r)
Definition p_polys.h:256
static unsigned long p_SetExp(poly p, const unsigned long e, const unsigned long iBitmask, const int VarOffset)
set a single variable exponent @Note: VarOffset encodes the position in p->exp
Definition p_polys.h:490
static long p_MinComp(poly p, ring lmRing, ring tailRing)
Definition p_polys.h:315
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
Definition p_polys.h:249
static long p_IncrExp(poly p, int v, ring r)
Definition p_polys.h:593
static void p_ExpVectorSub(poly p1, poly p2, const ring r)
Definition p_polys.h:1456
static unsigned long p_AddComp(poly p, unsigned long v, ring r)
Definition p_polys.h:449
static void p_Setm(poly p, const ring r)
Definition p_polys.h:235
#define p_SetmComp
Definition p_polys.h:246
static number p_SetCoeff(poly p, number n, ring r)
Definition p_polys.h:414
static poly pReverse(poly p)
Definition p_polys.h:337
static BOOLEAN p_LmIsConstantComp(const poly p, const ring r)
Definition p_polys.h:1008
static poly p_Head(const poly p, const ring r)
copy the (leading) term of p
Definition p_polys.h:862
static int p_LmCmp(poly p, poly q, const ring r)
Definition p_polys.h:1596
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent @Note: the integer VarOffset encodes:
Definition p_polys.h:471
static long p_MultExp(poly p, int v, long ee, ring r)
Definition p_polys.h:623
static BOOLEAN p_IsConstant(const poly p, const ring r)
Definition p_polys.h:1980
static poly p_GetExp_k_n(poly p, int l, int k, const ring r)
Definition p_polys.h:1388
static BOOLEAN p_DivisibleBy(poly a, poly b, const ring r)
Definition p_polys.h:1916
static long p_MaxComp(poly p, ring lmRing, ring tailRing)
Definition p_polys.h:294
static void p_Delete(poly *p, const ring r)
Definition p_polys.h:903
static long p_DecrExp(poly p, int v, ring r)
Definition p_polys.h:600
static void p_GetExpV(poly p, int *ev, const ring r)
Definition p_polys.h:1536
BOOLEAN p_CheckPolyRing(poly p, ring r)
Definition pDebug.cc:115
static long p_GetOrder(poly p, ring r)
Definition p_polys.h:423
static poly p_LmFreeAndNext(poly p, ring)
Definition p_polys.h:713
static poly p_Mult_mm(poly p, poly m, const ring r)
Definition p_polys.h:1053
static void p_LmFree(poly p, ring)
Definition p_polys.h:685
static poly p_Init(const ring r, omBin bin)
Definition p_polys.h:1336
static poly p_LmDeleteAndNext(poly p, const ring r)
Definition p_polys.h:757
static poly p_SortAdd(poly p, const ring r, BOOLEAN revert=FALSE)
Definition p_polys.h:1235
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition p_polys.h:848
static long p_Totaldegree(poly p, const ring r)
Definition p_polys.h:1523
#define p_Test(p, r)
Definition p_polys.h:161
#define __p_Mult_nn(p, n, r)
Definition p_polys.h:973
void p_wrp(poly p, ring lmRing, ring tailRing)
Definition polys0.cc:373
poly singclap_gcd(poly f, poly g, const ring r)
polynomial gcd via singclap_gcd_r resp. idSyzygies destroys f and g
Definition polys.cc:383
#define NUM
Definition readcf.cc:180
void PrintS(const char *s)
Definition reporter.cc:284
void Werror(const char *fmt,...)
Definition reporter.cc:189
BOOLEAN rOrd_SetCompRequiresSetm(const ring r)
return TRUE if p_SetComp requires p_Setm
Definition ring.cc:2022
void rWrite(ring r, BOOLEAN details)
Definition ring.cc:227
int r_IsRingVar(const char *n, char **names, int N)
Definition ring.cc:213
BOOLEAN rSamePolyRep(ring r1, ring r2)
returns TRUE, if r1 and r2 represents the monomials in the same way FALSE, otherwise this is an analo...
Definition ring.cc:1804
static BOOLEAN rField_is_Zp_a(const ring r)
Definition ring.h:535
#define ringorder_rp
Definition ring.h:100
static BOOLEAN rField_is_Z(const ring r)
Definition ring.h:515
static BOOLEAN rField_is_Zp(const ring r)
Definition ring.h:506
void(* p_SetmProc)(poly p, const ring r)
Definition ring.h:40
static BOOLEAN rIsPluralRing(const ring r)
we must always have this test!
Definition ring.h:406
ro_typ ord_typ
Definition ring.h:226
long(* pFDegProc)(poly p, ring r)
Definition ring.h:39
static int rGetCurrSyzLimit(const ring r)
Definition ring.h:729
long(* pLDegProc)(poly p, int *length, ring r)
Definition ring.h:38
static BOOLEAN rIsRatGRing(const ring r)
Definition ring.h:433
static int rPar(const ring r)
(r->cf->P)
Definition ring.h:605
@ ro_wp64
Definition ring.h:56
@ ro_syz
Definition ring.h:61
@ ro_cp
Definition ring.h:59
@ ro_dp
Definition ring.h:53
@ ro_is
Definition ring.h:62
@ ro_wp_neg
Definition ring.h:57
@ ro_wp
Definition ring.h:54
@ ro_isTemp
Definition ring.h:62
@ ro_am
Definition ring.h:55
@ ro_syzcomp
Definition ring.h:60
static int rInternalChar(const ring r)
Definition ring.h:695
static BOOLEAN rIsLPRing(const ring r)
Definition ring.h:417
@ ringorder_lp
Definition ring.h:78
@ ringorder_a
Definition ring.h:71
@ ringorder_am
Definition ring.h:90
@ ringorder_a64
for int64 weights
Definition ring.h:72
@ ringorder_C
Definition ring.h:74
@ ringorder_S
S?
Definition ring.h:76
@ ringorder_ds
Definition ring.h:86
@ ringorder_Dp
Definition ring.h:81
@ ringorder_unspec
Definition ring.h:96
@ ringorder_L
Definition ring.h:91
@ ringorder_Ds
Definition ring.h:87
@ ringorder_dp
Definition ring.h:79
@ ringorder_c
Definition ring.h:73
@ ringorder_aa
for idElimination, like a, except pFDeg, pWeigths ignore it
Definition ring.h:93
@ ringorder_no
Definition ring.h:70
@ ringorder_Wp
Definition ring.h:83
@ ringorder_ws
Definition ring.h:88
@ ringorder_Ws
Definition ring.h:89
@ ringorder_IS
Induced (Schreyer) ordering.
Definition ring.h:95
@ ringorder_ls
degree, ip
Definition ring.h:85
@ ringorder_s
s?
Definition ring.h:77
@ ringorder_wp
Definition ring.h:82
@ ringorder_M
Definition ring.h:75
static BOOLEAN rField_is_Q_a(const ring r)
Definition ring.h:545
static BOOLEAN rField_is_Q(const ring r)
Definition ring.h:512
union sro_ord::@006200034235045362245112336324125006204215012002 data
#define ringorder_rs
Definition ring.h:101
static BOOLEAN rField_has_Units(const ring r)
Definition ring.h:496
static BOOLEAN rIsNCRing(const ring r)
Definition ring.h:427
static BOOLEAN rIsSyzIndexRing(const ring r)
Definition ring.h:726
static BOOLEAN rField_is_GF(const ring r)
Definition ring.h:527
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition ring.h:598
#define rField_is_Ring(R)
Definition ring.h:491
void sBucket_Add_m(sBucket_pt bucket, poly p)
Definition sbuckets.cc:173
sBucket_pt sBucketCreate(const ring r)
Definition sbuckets.cc:96
sBucket * sBucket_pt
Definition sbuckets.h:16
void sBucketDestroyAdd(sBucket_pt bucket, poly *p, int *length)
Definition sbuckets.h:68
static short scaLastAltVar(ring r)
Definition sca.h:25
static short scaFirstAltVar(ring r)
Definition sca.h:18
poly p_LPSubst(poly p, int n, poly e, const ring r)
Definition shiftop.cc:912
int status int void size_t count
Definition si_signals.h:69
#define IDELEMS(i)
#define R
Definition sirandom.c:27
#define loop
Definition structs.h:71
number ntInit(long i, const coeffs cf)
Definition transext.cc:704
int * iv2array(intvec *iv, const ring R)
Definition weight.cc:200
long totaldegreeWecart_IV(poly p, ring r, const int *w)
Definition weight.cc:231