source: git/kernel/polys.cc @ e543dd

fieker-DuValspielwiese
Last change on this file since e543dd was 45159a, checked in by Hans Schoenemann <hannes@…>, 13 years ago
removed printNumber git-svn-id: file:///usr/local/Singular/svn/trunk@14024 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 19.4 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id$ */
5
6/*
7* ABSTRACT - all basic methods to manipulate polynomials
8*/
9
10/* includes */
11#include <stdio.h>
12#include <string.h>
13#include <ctype.h>
14#include <kernel/mod2.h>
15#include <kernel/options.h>
16#include <omalloc/omalloc.h>
17#include <kernel/febase.h>
18#include <kernel/numbers.h>
19#include <kernel/polys.h>
20#include <kernel/ring.h>
21#include <kernel/sbuckets.h>
22
23#ifdef HAVE_PLURAL
24#include <kernel/gring.h>
25#include <kernel/sca.h>
26#endif
27
28/* ----------- global variables, set by pSetGlobals --------------------- */
29/* computes length and maximal degree of a POLYnomial */
30pLDegProc pLDeg;
31/* computes the degree of the initial term, used for std */
32pFDegProc pFDeg;
33/* the monomial ordering of the head monomials a and b */
34/* returns -1 if a comes before b, 0 if a=b, 1 otherwise */
35
36int pVariables;     // number of variables
37
38/* 1 for polynomial ring, -1 otherwise */
39int     pOrdSgn;
40// it is of type int, not BOOLEAN because it is also in ip
41/* TRUE if the monomial ordering is not compatible with pFDeg */
42BOOLEAN pLexOrder;
43
44/* ----------- global variables, set by procedures from hecke/kstd1 ----- */
45/* the highest monomial below pHEdge */
46poly      ppNoether = NULL;
47
48/* -------------------------------------------------------- */
49/*2
50* change all global variables to fit the description of the new ring
51*/
52
53
54void pSetGlobals(const ring r, BOOLEAN complete)
55{
56  int i;
57  if (ppNoether!=NULL) pDelete(&ppNoether);
58  pVariables = r->N;
59  pOrdSgn = r->OrdSgn;
60  pFDeg=r->pFDeg;
61  pLDeg=r->pLDeg;
62  pLexOrder=r->LexOrder;
63
64  if (complete)
65  {
66    test &= ~ TEST_RINGDEP_OPTS;
67    test |= r->options;
68  }
69}
70
71// resets the pFDeg and pLDeg: if pLDeg is not given, it is
72// set to currRing->pLDegOrig, i.e. to the respective LDegProc which
73// only uses pFDeg (and not pDeg, or pTotalDegree, etc)
74void pSetDegProcs(pFDegProc new_FDeg, pLDegProc new_lDeg)
75{
76  assume(new_FDeg != NULL);
77  pFDeg = new_FDeg;
78  currRing->pFDeg = new_FDeg;
79
80  if (new_lDeg == NULL)
81    new_lDeg = currRing->pLDegOrig;
82
83  pLDeg = new_lDeg;
84  currRing->pLDeg = new_lDeg;
85}
86
87
88// restores pFDeg and pLDeg:
89extern void pRestoreDegProcs(pFDegProc old_FDeg, pLDegProc old_lDeg)
90{
91  assume(old_FDeg != NULL && old_lDeg != NULL);
92  pFDeg = old_FDeg;
93  currRing->pFDeg = old_FDeg;
94  pLDeg = old_lDeg;
95  currRing->pLDeg = old_lDeg;
96}
97
98/*2
99* assumes that the head term of b is a multiple of the head term of a
100* and return the multiplicant *m
101* Frank's observation: If LM(b) = LM(a)*m, then we may actually set
102* negative(!) exponents in the below loop. I suspect that the correct
103* comment should be "assumes that LM(a) = LM(b)*m, for some monomial m..."
104*/
105poly pDivide(poly a, poly b)
106{
107  int i;
108  poly result = pInit();
109
110  for(i=(int)pVariables; i; i--)
111    pSetExp(result,i, pGetExp(a,i)- pGetExp(b,i));
112  pSetComp(result, pGetComp(a) - pGetComp(b));
113  pSetm(result);
114  return result;
115}
116
117#ifdef HAVE_RINGS   //TODO Oliver
118#define pDiv_nn(p, n)              p_Div_nn(p, n, currRing)
119
120poly p_Div_nn(poly p, const number n, const ring r)
121{
122  pAssume(!n_IsZero(n,r));
123  p_Test(p, r);
124
125  poly q = p;
126  while (p != NULL)
127  {
128    number nc = pGetCoeff(p);
129    pSetCoeff0(p, n_Div(nc, n, r));
130    n_Delete(&nc, r);
131    pIter(p);
132  }
133  p_Test(q, r);
134  return q;
135}
136#endif
137
138#ifdef HAVE_RINGS
139/* TRUE iff LT(f) | LT(g) */
140BOOLEAN pDivisibleByRingCase(poly f, poly g)
141{
142  int exponent;
143  for(int i = (int)pVariables; i; i--)
144  {
145    exponent = pGetExp(g, i) - pGetExp(f, i);
146    if (exponent < 0) return FALSE;
147  }
148  return nDivBy(pGetCoeff(g), pGetCoeff(f));
149}
150#endif
151
152/*2
153* divides a by the monomial b, ignores monomials which are not divisible
154* assumes that b is not NULL
155*/
156poly pDivideM(poly a, poly b)
157{
158  if (a==NULL) return NULL;
159  poly result=a;
160  poly prev=NULL;
161  int i;
162#ifdef HAVE_RINGS
163  number inv=pGetCoeff(b);
164#else
165  number inv=nInvers(pGetCoeff(b));
166#endif
167
168  while (a!=NULL)
169  {
170    if (pDivisibleBy(b,a))
171    {
172      for(i=(int)pVariables; i; i--)
173         pSubExp(a,i, pGetExp(b,i));
174      pSubComp(a, pGetComp(b));
175      pSetm(a);
176      prev=a;
177      pIter(a);
178    }
179    else
180    {
181      if (prev==NULL)
182      {
183        pLmDelete(&result);
184        a=result;
185      }
186      else
187      {
188        pLmDelete(&pNext(prev));
189        a=pNext(prev);
190      }
191    }
192  }
193#ifdef HAVE_RINGS
194  if (nIsUnit(inv))
195  {
196    inv = nInvers(inv);
197    pMult_nn(result,inv);
198    nDelete(&inv);
199  }
200  else
201  {
202    pDiv_nn(result,inv);
203  }
204#else
205  pMult_nn(result,inv);
206  nDelete(&inv);
207#endif
208  pDelete(&b);
209  return result;
210}
211
212/*2
213* returns the LCM of the head terms of a and b in *m
214*/
215void pLcm(poly a, poly b, poly m)
216{
217  int i;
218  for (i=pVariables; i; i--)
219  {
220    pSetExp(m,i, si_max( pGetExp(a,i), pGetExp(b,i)));
221  }
222  pSetComp(m, si_max(pGetComp(a), pGetComp(b)));
223  /* Don't do a pSetm here, otherwise hres/lres chockes */
224}
225
226/*2
227* convert monomial given as string to poly, e.g. 1x3y5z
228*/
229const char * p_Read(const char *st, poly &rc, const ring r)
230{
231  if (r==NULL) { rc=NULL;return st;}
232  int i,j;
233  rc = p_Init(r);
234  const char *s = r->cf->nRead(st,&(rc->coef));
235  if (s==st)
236  /* i.e. it does not start with a coeff: test if it is a ringvar*/
237  {
238    j = r_IsRingVar(s,r);
239    if (j >= 0)
240    {
241      p_IncrExp(rc,1+j,r);
242      while (*s!='\0') s++;
243      goto done;
244    }
245  }
246  while (*s!='\0')
247  {
248    char ss[2];
249    ss[0] = *s++;
250    ss[1] = '\0';
251    j = r_IsRingVar(ss,r);
252    if (j >= 0)
253    {
254      const char *s_save=s;
255      s = eati(s,&i);
256      if (((unsigned long)i) >  r->bitmask)
257      {
258        // exponent to large: it is not a monomial
259        p_LmDelete(&rc,r);
260        return s_save;
261      }
262      p_AddExp(rc,1+j, (long)i, r);
263    }
264    else
265    {
266      // 1st char of is not a varname
267      p_LmDelete(&rc,r);
268      s--;
269      return s;
270    }
271  }
272done:
273  if (r->cf->nIsZero(pGetCoeff(rc))) p_LmDelete(&rc,r);
274  else
275  {
276#ifdef HAVE_PLURAL
277    // in super-commutative ring
278    // squares of anti-commutative variables are zeroes!
279    if(rIsSCA(r))
280    {
281      const unsigned int iFirstAltVar = scaFirstAltVar(r);
282      const unsigned int iLastAltVar  = scaLastAltVar(r);
283
284      assume(rc != NULL);
285
286      for(unsigned int k = iFirstAltVar; k <= iLastAltVar; k++)
287        if( p_GetExp(rc, k, r) > 1 )
288        {
289          p_LmDelete(&rc, r);
290          goto finish;
291        }
292    }
293#endif
294    p_Setm(rc,r);
295  }
296finish:
297  return s;
298}
299
300BOOLEAN _p_Test(poly p, ring r, int level);
301poly pmInit(const char *st, BOOLEAN &ok)
302{
303  poly p;
304  const char *s=p_Read(st,p,currRing);
305  if (*s!='\0')
306  {
307    if ((s!=st)&&isdigit(st[0]))
308    {
309      errorreported=TRUE;
310    }
311    ok=FALSE;
312    pDelete(&p);
313    return NULL;
314  }
315  #ifdef PDEBUG
316  _p_Test(p,currRing,PDEBUG);
317  #endif
318  ok=!errorreported;
319  return p;
320}
321
322/*2
323*make p homogeneous by multiplying the monomials by powers of x_varnum
324*assume: deg(var(varnum))==1
325*/
326poly pHomogen (poly p, int varnum)
327{
328  pFDegProc deg;
329  if (pLexOrder && (currRing->order[0]==ringorder_lp))
330    deg=p_Totaldegree;
331  else
332    deg=pFDeg;
333
334  poly q=NULL, qn;
335  int  o,ii;
336  sBucket_pt bp;
337
338  if (p!=NULL)
339  {
340    if ((varnum < 1) || (varnum > pVariables))
341    {
342      return NULL;
343    }
344    o=deg(p,currRing);
345    q=pNext(p);
346    while (q != NULL)
347    {
348      ii=deg(q,currRing);
349      if (ii>o) o=ii;
350      pIter(q);
351    }
352    q = pCopy(p);
353    bp = sBucketCreate(currRing);
354    while (q != NULL)
355    {
356      ii = o-deg(q,currRing);
357      if (ii!=0)
358      {
359        pAddExp(q,varnum, (long)ii);
360        pSetm(q);
361      }
362      qn = pNext(q);
363      pNext(q) = NULL;
364      sBucket_Add_p(bp, q, 1);
365      q = qn;
366    }
367    sBucketDestroyAdd(bp, &q, &ii);
368  }
369  return q;
370}
371
372/*4
373*Returns the exponent of the maximal power of the leading monomial of
374*p2 in that of p1
375*/
376/*----------utilities for syzygies--------------*/
377poly pTakeOutComp(poly * p, int k)
378{
379  poly q = *p,qq=NULL,result = NULL;
380
381  if (q==NULL) return NULL;
382  BOOLEAN use_setmcomp=rOrd_SetCompRequiresSetm(currRing);
383  if (pGetComp(q)==k)
384  {
385    result = q;
386    do
387    {
388      pSetComp(q,0);
389      if (use_setmcomp) pSetmComp(q);
390      qq = q;
391      pIter(q);
392    }
393    while ((q!=NULL) && (pGetComp(q)==k));
394    *p = q;
395    pNext(qq) = NULL;
396  }
397  if (q==NULL) return result;
398  if (pGetComp(q) > k)
399  {
400    pSubComp(q,1);
401    if (use_setmcomp) pSetmComp(q);
402  }
403  poly pNext_q;
404  while ((pNext_q=pNext(q))!=NULL)
405  {
406    if (pGetComp(pNext_q)==k)
407    {
408      if (result==NULL)
409      {
410        result = pNext_q;
411        qq = result;
412      }
413      else
414      {
415        pNext(qq) = pNext_q;
416        pIter(qq);
417      }
418      pNext(q) = pNext(pNext_q);
419      pNext(qq) =NULL;
420      pSetComp(qq,0);
421      if (use_setmcomp) pSetmComp(qq);
422    }
423    else
424    {
425      /*pIter(q);*/ q=pNext_q;
426      if (pGetComp(q) > k)
427      {
428        pSubComp(q,1);
429        if (use_setmcomp) pSetmComp(q);
430      }
431    }
432  }
433  return result;
434}
435
436// Splits *p into two polys: *q which consists of all monoms with
437// component == comp and *p of all other monoms *lq == pLength(*q)
438void pTakeOutComp(poly *r_p, long comp, poly *r_q, int *lq)
439{
440  spolyrec pp, qq;
441  poly p, q, p_prev;
442  int l = 0;
443
444#ifdef HAVE_ASSUME
445  int lp = pLength(*r_p);
446#endif
447
448  pNext(&pp) = *r_p;
449  p = *r_p;
450  p_prev = &pp;
451  q = &qq;
452
453  while(p != NULL)
454  {
455    while (pGetComp(p) == comp)
456    {
457      pNext(q) = p;
458      pIter(q);
459      pSetComp(p, 0);
460      pSetmComp(p);
461      pIter(p);
462      l++;
463      if (p == NULL)
464      {
465        pNext(p_prev) = NULL;
466        goto Finish;
467      }
468    }
469    pNext(p_prev) = p;
470    p_prev = p;
471    pIter(p);
472  }
473
474  Finish:
475  pNext(q) = NULL;
476  *r_p = pNext(&pp);
477  *r_q = pNext(&qq);
478  *lq = l;
479#ifdef HAVE_ASSUME
480  assume(pLength(*r_p) + pLength(*r_q) == lp);
481#endif
482  pTest(*r_p);
483  pTest(*r_q);
484}
485
486#if 1
487poly pTakeOutComp1(poly * p, int k)
488{
489  poly q = *p;
490
491  if (q==NULL) return NULL;
492
493  poly qq=NULL,result = NULL;
494
495  if (pGetComp(q)==k)
496  {
497    result = q; /* *p */
498    while ((q!=NULL) && (pGetComp(q)==k))
499    {
500      pSetComp(q,0);
501      pSetmComp(q);
502      qq = q;
503      pIter(q);
504    }
505    *p = q;
506    pNext(qq) = NULL;
507  }
508  if (q==NULL) return result;
509//  if (pGetComp(q) > k) pGetComp(q)--;
510  while (pNext(q)!=NULL)
511  {
512    if (pGetComp(pNext(q))==k)
513    {
514      if (result==NULL)
515      {
516        result = pNext(q);
517        qq = result;
518      }
519      else
520      {
521        pNext(qq) = pNext(q);
522        pIter(qq);
523      }
524      pNext(q) = pNext(pNext(q));
525      pNext(qq) =NULL;
526      pSetComp(qq,0);
527      pSetmComp(qq);
528    }
529    else
530    {
531      pIter(q);
532//      if (pGetComp(q) > k) pGetComp(q)--;
533    }
534  }
535  return result;
536}
537#endif
538
539void pDeleteComp(poly * p,int k)
540{
541  poly q;
542
543  while ((*p!=NULL) && (pGetComp(*p)==k)) pLmDelete(p);
544  if (*p==NULL) return;
545  q = *p;
546  if (pGetComp(q)>k)
547  {
548    pSubComp(q,1);
549    pSetmComp(q);
550  }
551  while (pNext(q)!=NULL)
552  {
553    if (pGetComp(pNext(q))==k)
554      pLmDelete(&(pNext(q)));
555    else
556    {
557      pIter(q);
558      if (pGetComp(q)>k)
559      {
560        pSubComp(q,1);
561        pSetmComp(q);
562      }
563    }
564  }
565}
566/*----------end of utilities for syzygies--------------*/
567
568/*2
569* pair has no common factor ? or is no polynomial
570*/
571BOOLEAN pHasNotCF(poly p1, poly p2)
572{
573
574  if (pGetComp(p1) > 0 || pGetComp(p2) > 0)
575    return FALSE;
576  int i = pVariables;
577  loop
578  {
579    if ((pGetExp(p1, i) > 0) && (pGetExp(p2, i) > 0))   return FALSE;
580    i--;
581    if (i == 0)                                         return TRUE;
582  }
583}
584
585/*2
586* divides p1 by its leading coefficient if it is a unit
587* (this will always be true over fields; but not over coefficient rings)
588*/
589void pNorm(poly p1)
590{
591#ifdef HAVE_RINGS
592  if (rField_is_Ring(currRing))
593  {
594    if (!nIsUnit(pGetCoeff(p1))) return;
595  }
596#endif
597  if (p1!=NULL)
598  {
599    if (pNext(p1)==NULL)
600    {
601      pSetCoeff(p1,nInit(1));
602      return;
603    }
604    poly h;
605    if (!nIsOne(pGetCoeff(p1)))
606    {
607      number k, c;
608      nNormalize(pGetCoeff(p1));
609      k = pGetCoeff(p1);
610      c = nInit(1);
611      pSetCoeff0(p1,c);
612      h = pNext(p1);
613      while (h!=NULL)
614      {
615        c=nDiv(pGetCoeff(h),k);
616        // no need to normalize: Z/p, R
617        // normalize already in nDiv: Q_a, Z/p_a
618        // remains: Q
619        if (rField_is_Q() && (!nIsOne(c))) nNormalize(c);
620        pSetCoeff(h,c);
621        pIter(h);
622      }
623      nDelete(&k);
624    }
625    else
626    {
627      if (nNormalize != nDummy2)
628      {
629        h = pNext(p1);
630        while (h!=NULL)
631        {
632          nNormalize(pGetCoeff(h));
633          pIter(h);
634        }
635      }
636    }
637  }
638}
639
640/*2
641*normalize all coefficients
642*/
643void p_Normalize(poly p,const ring r)
644{
645  if (rField_has_simple_inverse(r)) return; /* Z/p, GF(p,n), R, long R/C */
646  while (p!=NULL)
647  {
648#ifdef LDEBUG
649    if (currRing==r) {nTest(pGetCoeff(p));}
650#endif
651    n_Normalize(pGetCoeff(p),r);
652    pIter(p);
653  }
654}
655
656// splits p into polys with Exp(n) == 0 and Exp(n) != 0
657// Poly with Exp(n) != 0 is reversed
658static void pSplitAndReversePoly(poly p, int n, poly *non_zero, poly *zero)
659{
660  if (p == NULL)
661  {
662    *non_zero = NULL;
663    *zero = NULL;
664    return;
665  }
666  spolyrec sz;
667  poly z, n_z, next;
668  z = &sz;
669  n_z = NULL;
670
671  while(p != NULL)
672  {
673    next = pNext(p);
674    if (pGetExp(p, n) == 0)
675    {
676      pNext(z) = p;
677      pIter(z);
678    }
679    else
680    {
681      pNext(p) = n_z;
682      n_z = p;
683    }
684    p = next;
685  }
686  pNext(z) = NULL;
687  *zero = pNext(&sz);
688  *non_zero = n_z;
689  return;
690}
691
692/*3
693* substitute the n-th variable by 1 in p
694* destroy p
695*/
696static poly pSubst1 (poly p,int n)
697{
698  poly qq=NULL, result = NULL;
699  poly zero=NULL, non_zero=NULL;
700
701  // reverse, so that add is likely to be linear
702  pSplitAndReversePoly(p, n, &non_zero, &zero);
703
704  while (non_zero != NULL)
705  {
706    assume(pGetExp(non_zero, n) != 0);
707    qq = non_zero;
708    pIter(non_zero);
709    qq->next = NULL;
710    pSetExp(qq,n,0);
711    pSetm(qq);
712    result = pAdd(result,qq);
713  }
714  p = pAdd(result, zero);
715  pTest(p);
716  return p;
717}
718
719/*3
720* substitute the n-th variable by number e in p
721* destroy p
722*/
723static poly pSubst2 (poly p,int n, number e)
724{
725  assume( ! nIsZero(e) );
726  poly qq,result = NULL;
727  number nn, nm;
728  poly zero, non_zero;
729
730  // reverse, so that add is likely to be linear
731  pSplitAndReversePoly(p, n, &non_zero, &zero);
732
733  while (non_zero != NULL)
734  {
735    assume(pGetExp(non_zero, n) != 0);
736    qq = non_zero;
737    pIter(non_zero);
738    qq->next = NULL;
739    nPower(e, pGetExp(qq, n), &nn);
740    nm = nMult(nn, pGetCoeff(qq));
741#ifdef HAVE_RINGS
742    if (nIsZero(nm))
743    {
744      pLmFree(&qq);
745      nDelete(&nm);
746    }
747    else
748#endif
749    {
750      pSetCoeff(qq, nm);
751      pSetExp(qq, n, 0);
752      pSetm(qq);
753      result = pAdd(result,qq);
754    }
755    nDelete(&nn);
756  }
757  p = pAdd(result, zero);
758  pTest(p);
759  return p;
760}
761
762
763/* delete monoms whose n-th exponent is different from zero */
764poly pSubst0(poly p, int n)
765{
766  spolyrec res;
767  poly h = &res;
768  pNext(h) = p;
769
770  while (pNext(h)!=NULL)
771  {
772    if (pGetExp(pNext(h),n)!=0)
773    {
774      pLmDelete(&pNext(h));
775    }
776    else
777    {
778      pIter(h);
779    }
780  }
781  pTest(pNext(&res));
782  return pNext(&res);
783}
784
785/*2
786* substitute the n-th variable by e in p
787* destroy p
788*/
789poly pSubst(poly p, int n, poly e)
790{
791  if (e == NULL) return pSubst0(p, n);
792
793  if (pIsConstant(e))
794  {
795    if (nIsOne(pGetCoeff(e))) return pSubst1(p,n);
796    else return pSubst2(p, n, pGetCoeff(e));
797  }
798
799#ifdef HAVE_PLURAL
800  if (rIsPluralRing(currRing))
801  {
802    return nc_pSubst(p,n,e);
803  }
804#endif
805
806  int exponent,i;
807  poly h, res, m;
808  int *me,*ee;
809  number nu,nu1;
810
811  me=(int *)omAlloc((pVariables+1)*sizeof(int));
812  ee=(int *)omAlloc((pVariables+1)*sizeof(int));
813  if (e!=NULL) pGetExpV(e,ee);
814  res=NULL;
815  h=p;
816  while (h!=NULL)
817  {
818    if ((e!=NULL) || (pGetExp(h,n)==0))
819    {
820      m=pHead(h);
821      pGetExpV(m,me);
822      exponent=me[n];
823      me[n]=0;
824      for(i=pVariables;i>0;i--)
825        me[i]+=exponent*ee[i];
826      pSetExpV(m,me);
827      if (e!=NULL)
828      {
829        nPower(pGetCoeff(e),exponent,&nu);
830        nu1=nMult(pGetCoeff(m),nu);
831        nDelete(&nu);
832        pSetCoeff(m,nu1);
833      }
834      res=pAdd(res,m);
835    }
836    pLmDelete(&h);
837  }
838  omFreeSize((ADDRESS)me,(pVariables+1)*sizeof(int));
839  omFreeSize((ADDRESS)ee,(pVariables+1)*sizeof(int));
840  return res;
841}
842
843/* Returns TRUE if
844     * LM(p) | LM(lcm)
845     * LC(p) | LC(lcm) only if ring
846     * Exists i, j:
847         * LE(p, i)  != LE(lcm, i)
848         * LE(p1, i) != LE(lcm, i)   ==> LCM(p1, p) != lcm
849         * LE(p, j)  != LE(lcm, j)
850         * LE(p2, j) != LE(lcm, j)   ==> LCM(p2, p) != lcm
851*/
852BOOLEAN pCompareChain (poly p,poly p1,poly p2,poly lcm)
853{
854  int k, j;
855
856  if (lcm==NULL) return FALSE;
857
858  for (j=pVariables; j; j--)
859    if ( pGetExp(p,j) >  pGetExp(lcm,j)) return FALSE;
860  if ( pGetComp(p) !=  pGetComp(lcm)) return FALSE;
861  for (j=pVariables; j; j--)
862  {
863    if (pGetExp(p1,j)!=pGetExp(lcm,j))
864    {
865      if (pGetExp(p,j)!=pGetExp(lcm,j))
866      {
867        for (k=pVariables; k>j; k--)
868        {
869          if ((pGetExp(p,k)!=pGetExp(lcm,k))
870          && (pGetExp(p2,k)!=pGetExp(lcm,k)))
871            return TRUE;
872        }
873        for (k=j-1; k; k--)
874        {
875          if ((pGetExp(p,k)!=pGetExp(lcm,k))
876          && (pGetExp(p2,k)!=pGetExp(lcm,k)))
877            return TRUE;
878        }
879        return FALSE;
880      }
881    }
882    else if (pGetExp(p2,j)!=pGetExp(lcm,j))
883    {
884      if (pGetExp(p,j)!=pGetExp(lcm,j))
885      {
886        for (k=pVariables; k>j; k--)
887        {
888          if ((pGetExp(p,k)!=pGetExp(lcm,k))
889          && (pGetExp(p1,k)!=pGetExp(lcm,k)))
890            return TRUE;
891        }
892        for (k=j-1; k!=0 ; k--)
893        {
894          if ((pGetExp(p,k)!=pGetExp(lcm,k))
895          && (pGetExp(p1,k)!=pGetExp(lcm,k)))
896            return TRUE;
897        }
898        return FALSE;
899      }
900    }
901  }
902  return FALSE;
903}
904#ifdef HAVE_RATGRING
905BOOLEAN pCompareChainPart (poly p,poly p1,poly p2,poly lcm)
906{
907  int k, j;
908
909  if (lcm==NULL) return FALSE;
910
911  for (j=currRing->real_var_end; j>=currRing->real_var_start; j--)
912    if ( pGetExp(p,j) >  pGetExp(lcm,j)) return FALSE;
913  if ( pGetComp(p) !=  pGetComp(lcm)) return FALSE;
914  for (j=currRing->real_var_end; j>=currRing->real_var_start; j--)
915  {
916    if (pGetExp(p1,j)!=pGetExp(lcm,j))
917    {
918      if (pGetExp(p,j)!=pGetExp(lcm,j))
919      {
920        for (k=pVariables; k>j; k--)
921        for (k=currRing->real_var_end; k>j; k--)
922        {
923          if ((pGetExp(p,k)!=pGetExp(lcm,k))
924          && (pGetExp(p2,k)!=pGetExp(lcm,k)))
925            return TRUE;
926        }
927        for (k=j-1; k>=currRing->real_var_start; k--)
928        {
929          if ((pGetExp(p,k)!=pGetExp(lcm,k))
930          && (pGetExp(p2,k)!=pGetExp(lcm,k)))
931            return TRUE;
932        }
933        return FALSE;
934      }
935    }
936    else if (pGetExp(p2,j)!=pGetExp(lcm,j))
937    {
938      if (pGetExp(p,j)!=pGetExp(lcm,j))
939      {
940        for (k=currRing->real_var_end; k>j; k--)
941        {
942          if ((pGetExp(p,k)!=pGetExp(lcm,k))
943          && (pGetExp(p1,k)!=pGetExp(lcm,k)))
944            return TRUE;
945        }
946        for (k=j-1; k>=currRing->real_var_start; k--)
947        {
948          if ((pGetExp(p,k)!=pGetExp(lcm,k))
949          && (pGetExp(p1,k)!=pGetExp(lcm,k)))
950            return TRUE;
951        }
952        return FALSE;
953      }
954    }
955  }
956  return FALSE;
957}
958#endif
959
960int pSize(poly p)
961{
962  int count = 0;
963  while ( p != NULL )
964  {
965    count+= nSize( pGetCoeff( p ) );
966    pIter( p );
967  }
968  return count;
969}
970
971/*2
972* returns the length of a (numbers of monomials)
973* respect syzComp
974*/
975poly pLast(poly a, int &l)
976{
977  if (a == NULL)
978  {
979    l = 0;
980    return NULL;
981  }
982  l = 1;
983  if (! rIsSyzIndexRing(currRing))
984  {
985    while (pNext(a)!=NULL)
986    {
987      pIter(a);
988      l++;
989    }
990  }
991  else
992  {
993    int curr_limit = rGetCurrSyzLimit(currRing);
994    poly pp = a;
995    while ((a=pNext(a))!=NULL)
996    {
997      if (pGetComp(a)<=curr_limit/*syzComp*/)
998        l++;
999      else break;
1000      pp = a;
1001    }
1002    a=pp;
1003  }
1004  return a;
1005}
1006
Note: See TracBrowser for help on using the repository browser.