source: git/kernel/polys.cc @ 7d2573

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