source: git/kernel/polys.cc @ f12c611

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