source: git/kernel/polys1.cc @ 9f73e80

spielwiese
Last change on this file since 9f73e80 was 9f73e80, checked in by Hans Schoenemann <hannes@…>, 12 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: 32.8 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id$ */
5
6/*
7* ABSTRACT - all basic methods to manipulate polynomials:
8* independent of representation
9*/
10
11/* includes */
12#include <string.h>
13#include <kernel/mod2.h>
14#include <kernel/options.h>
15#include <kernel/numbers.h>
16#include <kernel/ffields.h>
17#include <omalloc/omalloc.h>
18#include <kernel/febase.h>
19#include <kernel/weight.h>
20#include <kernel/intvec.h>
21#include <kernel/longalg.h>
22#include <kernel/longtrans.h>
23#include <kernel/ring.h>
24#include <kernel/ideals.h>
25#include <kernel/polys.h>
26//#include "ipid.h"
27#ifdef HAVE_FACTORY
28#include <kernel/clapsing.h>
29#endif
30
31#ifdef HAVE_RATGRING
32#include <kernel/ratgring.h>
33#endif
34
35/*-------- several access procedures to monomials -------------------- */
36/*
37* the module weights for std
38*/
39static pFDegProc pOldFDeg;
40static pLDegProc pOldLDeg;
41static intvec * pModW;
42static BOOLEAN pOldLexOrder;
43
44static long pModDeg(poly p, ring r = currRing)
45{
46  long d=pOldFDeg(p, r);
47  int c=p_GetComp(p, r);
48  if ((c>0) && (pModW->range(c-1))) d+= (*pModW)[c-1];
49  return d;
50  //return pOldFDeg(p, r)+(*pModW)[p_GetComp(p, r)-1];
51}
52
53void pSetModDeg(intvec *w)
54{
55  if (w!=NULL)
56  {
57    pModW = w;
58    pOldFDeg = pFDeg;
59    pOldLDeg = pLDeg;
60    pOldLexOrder = pLexOrder;
61    pSetDegProcs(pModDeg);
62    pLexOrder = TRUE;
63  }
64  else
65  {
66    pModW = NULL;
67    pRestoreDegProcs(pOldFDeg, pOldLDeg);
68    pLexOrder = pOldLexOrder;
69  }
70}
71
72
73/*2
74* subtract p2 from p1, p1 and p2 are destroyed
75* do not put attention on speed: the procedure is only used in the interpreter
76*/
77poly pSub(poly p1, poly p2)
78{
79  return pAdd(p1, pNeg(p2));
80}
81
82/*3
83*  create binomial coef.
84*/
85static number* pnBin(int exp)
86{
87  int e, i, h;
88  number x, y, *bin=NULL;
89
90  x = nInit(exp);
91  if (nIsZero(x))
92  {
93    nDelete(&x);
94    return bin;
95  }
96  h = (exp >> 1) + 1;
97  bin = (number *)omAlloc0(h*sizeof(number));
98  bin[1] = x;
99  if (exp < 4)
100    return bin;
101  i = exp - 1;
102  for (e=2; e<h; e++)
103  {
104      x = nInit(i);
105      i--;
106      y = nMult(x,bin[e-1]);
107      nDelete(&x);
108      x = nInit(e);
109      bin[e] = nIntDiv(y,x);
110      nDelete(&x);
111      nDelete(&y);
112  }
113  return bin;
114}
115
116static void pnFreeBin(number *bin, int exp)
117{
118  int e, h = (exp >> 1) + 1;
119
120  if (bin[1] != NULL)
121  {
122    for (e=1; e<h; e++)
123      nDelete(&(bin[e]));
124  }
125  omFreeSize((ADDRESS)bin, h*sizeof(number));
126}
127
128/*3
129* compute for a monomial m
130* the power m^exp, exp > 1
131* destroys p
132*/
133static poly p_MonPower(poly p, int exp, const ring r)
134{
135  int i;
136
137  if(!n_IsOne(pGetCoeff(p),r))
138  {
139    number x, y;
140    y = pGetCoeff(p);
141    n_Power(y,exp,&x,r);
142    n_Delete(&y,r);
143    pSetCoeff0(p,x);
144  }
145  for (i=rVar(r); i!=0; i--)
146  {
147    p_MultExp(p,i, exp,r);
148  }
149  p_Setm(p,r);
150  return p;
151}
152
153/*3
154* compute for monomials p*q
155* destroys p, keeps q
156*/
157static void p_MonMult(poly p, poly q, const ring r)
158{
159  number x, y;
160
161  y = pGetCoeff(p);
162  x = n_Mult(y,pGetCoeff(q),r);
163  n_Delete(&y,r);
164  pSetCoeff0(p,x);
165  //for (int i=pVariables; i!=0; i--)
166  //{
167  //  pAddExp(p,i, pGetExp(q,i));
168  //}
169  //p->Order += q->Order;
170  p_ExpVectorAdd(p,q,r);
171}
172
173/*3
174* compute for monomials p*q
175* keeps p, q
176*/
177static poly p_MonMultC(poly p, poly q, const ring rr)
178{
179  number x;
180  poly r = p_Init(rr);
181
182  x = n_Mult(pGetCoeff(p),pGetCoeff(q),rr);
183  pSetCoeff0(r,x);
184  p_ExpVectorSum(r,p, q, rr);
185  return r;
186}
187
188/*
189*  compute for a poly p = head+tail, tail is monomial
190*          (head + tail)^exp, exp > 1
191*          with binomial coef.
192*/
193static poly p_TwoMonPower(poly p, int exp, const ring r)
194{
195  int eh, e;
196  long al;
197  poly *a;
198  poly tail, b, res, h;
199  number x;
200  number *bin = pnBin(exp);
201
202  tail = pNext(p);
203  if (bin == NULL)
204  {
205    p_MonPower(p,exp,r);
206    p_MonPower(tail,exp,r);
207#ifdef PDEBUG
208    p_Test(p,r);
209#endif
210    return p;
211  }
212  eh = exp >> 1;
213  al = (exp + 1) * sizeof(poly);
214  a = (poly *)omAlloc(al);
215  a[1] = p;
216  for (e=1; e<exp; e++)
217  {
218    a[e+1] = p_MonMultC(a[e],p,r);
219  }
220  res = a[exp];
221  b = p_Head(tail,r);
222  for (e=exp-1; e>eh; e--)
223  {
224    h = a[e];
225    x = n_Mult(bin[exp-e],pGetCoeff(h),r);
226    p_SetCoeff(h,x,r);
227    p_MonMult(h,b,r);
228    res = pNext(res) = h;
229    p_MonMult(b,tail,r);
230  }
231  for (e=eh; e!=0; e--)
232  {
233    h = a[e];
234    x = n_Mult(bin[e],pGetCoeff(h),r);
235    p_SetCoeff(h,x,r);
236    p_MonMult(h,b,r);
237    res = pNext(res) = h;
238    p_MonMult(b,tail,r);
239  }
240  p_LmDelete(&tail,r);
241  pNext(res) = b;
242  pNext(b) = NULL;
243  res = a[exp];
244  omFreeSize((ADDRESS)a, al);
245  pnFreeBin(bin, exp);
246//  tail=res;
247// while((tail!=NULL)&&(pNext(tail)!=NULL))
248// {
249//   if(nIsZero(pGetCoeff(pNext(tail))))
250//   {
251//     pLmDelete(&pNext(tail));
252//   }
253//   else
254//     pIter(tail);
255// }
256#ifdef PDEBUG
257  p_Test(res,r);
258#endif
259  return res;
260}
261
262static poly p_Pow(poly p, int i, const ring r)
263{
264  poly rc = p_Copy(p,r);
265  i -= 2;
266  do
267  {
268    rc = p_Mult_q(rc,p_Copy(p,r),r);
269    p_Normalize(rc,r);
270    i--;
271  }
272  while (i != 0);
273  return p_Mult_q(rc,p,r);
274}
275
276/*2
277* returns the i-th power of p
278* p will be destroyed
279*/
280poly p_Power(poly p, int i, const ring r)
281{
282  poly rc=NULL;
283
284  if (i==0)
285  {
286    p_Delete(&p,r);
287    return p_One(r);
288  }
289
290  if(p!=NULL)
291  {
292    if ( (i > 0) && ((unsigned long ) i > (r->bitmask)))
293    {
294      Werror("exponent %d is too large, max. is %ld",i,r->bitmask);
295      return NULL;
296    }
297    switch (i)
298    {
299// cannot happen, see above
300//      case 0:
301//      {
302//        rc=pOne();
303//        pDelete(&p);
304//        break;
305//      }
306      case 1:
307        rc=p;
308        break;
309      case 2:
310        rc=p_Mult_q(p_Copy(p,r),p,r);
311        break;
312      default:
313        if (i < 0)
314        {
315          p_Delete(&p,r);
316          return NULL;
317        }
318        else
319        {
320#ifdef HAVE_PLURAL
321          if (rIsPluralRing(r)) /* in the NC case nothing helps :-( */
322          {
323            int j=i;
324            rc = p_Copy(p,r);
325            while (j>1)
326            {
327              rc = p_Mult_q(p_Copy(p,r),rc,r);
328              j--;
329            }
330            p_Delete(&p,r);
331            return rc;
332          }
333#endif
334          rc = pNext(p);
335          if (rc == NULL)
336            return p_MonPower(p,i,r);
337          /* else: binom ?*/
338          int char_p=rChar(r);
339          if ((pNext(rc) != NULL)
340#ifdef HAVE_RINGS
341             || rField_is_Ring(r)
342#endif
343             )
344            return p_Pow(p,i,r);
345          if ((char_p==0) || (i<=char_p))
346            return p_TwoMonPower(p,i,r);
347          poly p_p=p_TwoMonPower(p_Copy(p,r),char_p,r);
348          return p_Mult_q(p_Power(p,i-char_p,r),p_p,r);
349        }
350      /*end default:*/
351    }
352  }
353  return rc;
354}
355
356/*2
357* returns the partial differentiate of a by the k-th variable
358* does not destroy the input
359*/
360poly pDiff(poly a, int k)
361{
362  poly res, f, last;
363  number t;
364
365  last = res = NULL;
366  while (a!=NULL)
367  {
368    if (pGetExp(a,k)!=0)
369    {
370      f = pLmInit(a);
371      t = nInit(pGetExp(a,k));
372      pSetCoeff0(f,nMult(t,pGetCoeff(a)));
373      nDelete(&t);
374      if (nIsZero(pGetCoeff(f)))
375        pLmDelete(&f);
376      else
377      {
378        pDecrExp(f,k);
379        pSetm(f);
380        if (res==NULL)
381        {
382          res=last=f;
383        }
384        else
385        {
386          pNext(last)=f;
387          last=f;
388        }
389      }
390    }
391    pIter(a);
392  }
393  return res;
394}
395
396static poly pDiffOpM(poly a, poly b,BOOLEAN multiply)
397{
398  int i,j,s;
399  number n,h,hh;
400  poly p=pOne();
401  n=nMult(pGetCoeff(a),pGetCoeff(b));
402  for(i=pVariables;i>0;i--)
403  {
404    s=pGetExp(b,i);
405    if (s<pGetExp(a,i))
406    {
407      nDelete(&n);
408      pLmDelete(&p);
409      return NULL;
410    }
411    if (multiply)
412    {
413      for(j=pGetExp(a,i); j>0;j--)
414      {
415        h = nInit(s);
416        hh=nMult(n,h);
417        nDelete(&h);
418        nDelete(&n);
419        n=hh;
420        s--;
421      }
422      pSetExp(p,i,s);
423    }
424    else
425    {
426      pSetExp(p,i,s-pGetExp(a,i));
427    }
428  }
429  pSetm(p);
430  /*if (multiply)*/ pSetCoeff(p,n);
431  if (nIsZero(n))  p=pLmDeleteAndNext(p); // return NULL as p is a monomial
432  return p;
433}
434
435poly pDiffOp(poly a, poly b,BOOLEAN multiply)
436{
437  poly result=NULL;
438  poly h;
439  for(;a!=NULL;pIter(a))
440  {
441    for(h=b;h!=NULL;pIter(h))
442    {
443      result=pAdd(result,pDiffOpM(a,h,multiply));
444    }
445  }
446  return result;
447}
448
449
450void pSplit(poly p, poly *h)
451{
452  *h=pNext(p);
453  pNext(p)=NULL;
454}
455
456
457
458int pMaxCompProc(poly p)
459{
460  return pMaxComp(p);
461}
462
463/*2
464* handle memory request for sets of polynomials (ideals)
465* l is the length of *p, increment is the difference (may be negative)
466*/
467void pEnlargeSet(polyset *p, int l, int increment)
468{
469  polyset h;
470
471  h=(polyset)omReallocSize((poly*)*p,l*sizeof(poly),(l+increment)*sizeof(poly));
472  if (increment>0)
473  {
474    //for (i=l; i<l+increment; i++)
475    //  h[i]=NULL;
476    memset(&(h[l]),0,increment*sizeof(poly));
477  }
478  *p=h;
479}
480
481number pInitContent(poly ph);
482number pInitContent_a(poly ph);
483
484void p_Content(poly ph, const ring r)
485{
486#ifdef HAVE_RINGS
487  if (rField_is_Ring(r))
488  {
489    if (ph!=NULL)
490    {
491      number k = nGetUnit(pGetCoeff(ph));
492      if (!nGreaterZero(pGetCoeff(ph))) k = nNeg(k); // in-place negation
493      if (!nIsOne(k))
494      {
495        number tmpNumber = k;
496        k = nInvers(k);
497        nDelete(&tmpNumber);
498        poly h = pNext(ph);
499        pSetCoeff(ph, nMult(pGetCoeff(ph), k));
500        while (h != NULL)
501        {
502          pSetCoeff(h, nMult(pGetCoeff(h), k));
503          pIter(h);
504        }
505      }
506      nDelete(&k);
507    }
508    return;
509  }
510#endif
511  number h,d;
512  poly p;
513
514  //  if(TEST_OPT_CONTENTSB) return;
515  if(pNext(ph)==NULL)
516  {
517    pSetCoeff(ph,nInit(1));
518  }
519  else
520  {
521    nNormalize(pGetCoeff(ph));
522    if(!nGreaterZero(pGetCoeff(ph))) ph = pNeg(ph);
523    if (rField_is_Q())
524    {
525      h=pInitContent(ph);
526      p=ph;
527    }
528    else if ((rField_is_Extension(r))
529    && ((rPar(r)>1)||(r->minpoly==NULL)))
530    {
531      h=pInitContent_a(ph);
532      p=ph;
533    }
534    else
535    {
536      h=nCopy(pGetCoeff(ph));
537      p = pNext(ph);
538    }
539    while (p!=NULL)
540    {
541      nNormalize(pGetCoeff(p));
542      d=nGcd(h,pGetCoeff(p),r);
543      nDelete(&h);
544      h = d;
545      if(nIsOne(h))
546      {
547        break;
548      }
549      pIter(p);
550    }
551    p = ph;
552    //number tmp;
553    if(!nIsOne(h))
554    {
555      while (p!=NULL)
556      {
557        //d = nDiv(pGetCoeff(p),h);
558        //tmp = nIntDiv(pGetCoeff(p),h);
559        //if (!nEqual(d,tmp))
560        //{
561        //  StringSetS("** div0:");nWrite(pGetCoeff(p));StringAppendS("/");
562        //  nWrite(h);StringAppendS("=");nWrite(d);StringAppendS(" int:");
563        //  nWrite(tmp);Print(StringAppendS("\n"));
564        //}
565        //nDelete(&tmp);
566        if (rField_is_Zp_a(currRing) || rField_is_Q_a(currRing))
567          d = nDiv(pGetCoeff(p),h);
568        else
569          d = nIntDiv(pGetCoeff(p),h);
570        pSetCoeff(p,d);
571        pIter(p);
572      }
573    }
574    nDelete(&h);
575#ifdef HAVE_FACTORY
576    if ( (nGetChar() == 1) || (nGetChar() < 0) ) /* Q[a],Q(a),Zp[a],Z/p(a) */
577    {
578      singclap_divide_content(ph);
579      if(!nGreaterZero(pGetCoeff(ph))) ph = pNeg(ph);
580    }
581#endif
582    if (rField_is_Q_a(r))
583    {
584      number hzz = nlInit(1, r);
585      h = nlInit(1, r);
586      p=ph;
587      while (p!=NULL)
588      { // each monom: coeff in Q_a
589        lnumber c_n_n=(lnumber)pGetCoeff(p);
590        napoly c_n=c_n_n->z;
591        while (c_n!=NULL)
592        { // each monom: coeff in Q
593          d=nlLcm(hzz,pGetCoeff(c_n),r->algring);
594          n_Delete(&hzz,r->algring);
595          hzz=d;
596          pIter(c_n);
597        }
598        c_n=c_n_n->n;
599        while (c_n!=NULL)
600        { // each monom: coeff in Q
601          d=nlLcm(h,pGetCoeff(c_n),r->algring);
602          n_Delete(&h,r->algring);
603          h=d;
604          pIter(c_n);
605        }
606        pIter(p);
607      }
608      /* hzz contains the 1/lcm of all denominators in c_n_n->z*/
609      /* h contains the 1/lcm of all denominators in c_n_n->n*/
610      number htmp=nlInvers(h);
611      number hzztmp=nlInvers(hzz);
612      number hh=nlMult(hzz,h);
613      nlDelete(&hzz,r->algring);
614      nlDelete(&h,r->algring);
615      number hg=nlGcd(hzztmp,htmp,r->algring);
616      nlDelete(&hzztmp,r->algring);
617      nlDelete(&htmp,r->algring);
618      h=nlMult(hh,hg);
619      nlDelete(&hg,r->algring);
620      nlDelete(&hh,r->algring);
621      nlNormalize(h);
622      if(!nlIsOne(h))
623      {
624        p=ph;
625        while (p!=NULL)
626        { // each monom: coeff in Q_a
627          lnumber c_n_n=(lnumber)pGetCoeff(p);
628          napoly c_n=c_n_n->z;
629          while (c_n!=NULL)
630          { // each monom: coeff in Q
631            d=nlMult(h,pGetCoeff(c_n));
632            nlNormalize(d);
633            nlDelete(&pGetCoeff(c_n),r->algring);
634            pGetCoeff(c_n)=d;
635            pIter(c_n);
636          }
637          c_n=c_n_n->n;
638          while (c_n!=NULL)
639          { // each monom: coeff in Q
640            d=nlMult(h,pGetCoeff(c_n));
641            nlNormalize(d);
642            nlDelete(&pGetCoeff(c_n),r->algring);
643            pGetCoeff(c_n)=d;
644            pIter(c_n);
645          }
646          pIter(p);
647        }
648      }
649      nlDelete(&h,r->algring);
650    }
651  }
652}
653
654void pSimpleContent(poly ph,int smax)
655{
656  //if(TEST_OPT_CONTENTSB) return;
657  if (ph==NULL) return;
658  if (pNext(ph)==NULL)
659  {
660    pSetCoeff(ph,nInit(1));
661    return;
662  }
663  if ((pNext(pNext(ph))==NULL)||(!rField_is_Q()))
664  {
665    return;
666  }
667  number d=pInitContent(ph);
668  if (nlSize(d)<=smax)
669  {
670    //if (TEST_OPT_PROT) PrintS("G");
671    return;
672  }
673  poly p=ph;
674  number h=d;
675  if (smax==1) smax=2;
676  while (p!=NULL)
677  {
678#if 0
679    d=nlGcd(h,pGetCoeff(p),currRing);
680    nlDelete(&h,currRing);
681    h = d;
682#else
683    nlInpGcd(h,pGetCoeff(p),currRing);
684#endif
685    if(nlSize(h)<smax)
686    {
687      //if (TEST_OPT_PROT) PrintS("g");
688      return;
689    }
690    pIter(p);
691  }
692  p = ph;
693  if (!nlGreaterZero(pGetCoeff(p))) h=nlNeg(h);
694  if(nlIsOne(h)) return;
695  //if (TEST_OPT_PROT) PrintS("c");
696  while (p!=NULL)
697  {
698#if 1
699    d = nlIntDiv(pGetCoeff(p),h);
700    pSetCoeff(p,d);
701#else
702    nlInpIntDiv(pGetCoeff(p),h,currRing);
703#endif
704    pIter(p);
705  }
706  nlDelete(&h,currRing);
707}
708
709number pInitContent(poly ph)
710// only for coefficients in Q
711#if 0
712{
713  //assume(!TEST_OPT_CONTENTSB);
714  assume(ph!=NULL);
715  assume(pNext(ph)!=NULL);
716  assume(rField_is_Q());
717  if (pNext(pNext(ph))==NULL)
718  {
719    return nlGetNom(pGetCoeff(pNext(ph)),currRing);
720  }
721  poly p=ph;
722  number n1=nlGetNom(pGetCoeff(p),currRing);
723  pIter(p);
724  number n2=nlGetNom(pGetCoeff(p),currRing);
725  pIter(p);
726  number d;
727  number t;
728  loop
729  {
730    nlNormalize(pGetCoeff(p));
731    t=nlGetNom(pGetCoeff(p),currRing);
732    if (nlGreaterZero(t))
733      d=nlAdd(n1,t);
734    else
735      d=nlSub(n1,t);
736    nlDelete(&t,currRing);
737    nlDelete(&n1,currRing);
738    n1=d;
739    pIter(p);
740    if (p==NULL) break;
741    nlNormalize(pGetCoeff(p));
742    t=nlGetNom(pGetCoeff(p),currRing);
743    if (nlGreaterZero(t))
744      d=nlAdd(n2,t);
745    else
746      d=nlSub(n2,t);
747    nlDelete(&t,currRing);
748    nlDelete(&n2,currRing);
749    n2=d;
750    pIter(p);
751    if (p==NULL) break;
752  }
753  d=nlGcd(n1,n2,currRing);
754  nlDelete(&n1,currRing);
755  nlDelete(&n2,currRing);
756  return d;
757}
758#else
759{
760  number d=pGetCoeff(ph);
761  if(SR_HDL(d)&SR_INT) return d;
762  int s=mpz_size1(d->z);
763  int s2=-1;
764  number d2;
765  loop
766  {
767    pIter(ph);
768    if(ph==NULL)
769    {
770      if (s2==-1) return nlCopy(d);
771      break;
772    }
773    if (SR_HDL(pGetCoeff(ph))&SR_INT)
774    {
775      s2=s;
776      d2=d;
777      s=0;
778      d=pGetCoeff(ph);
779      if (s2==0) break;
780    }
781    else
782    if (mpz_size1((pGetCoeff(ph)->z))<=s)
783    {
784      s2=s;
785      d2=d;
786      d=pGetCoeff(ph);
787      s=mpz_size1(d->z);
788    }
789  }
790  return nlGcd(d,d2,currRing);
791}
792#endif
793
794number pInitContent_a(poly ph)
795// only for coefficients in K(a) anf K(a,...)
796{
797  number d=pGetCoeff(ph);
798  int s=naParDeg(d);
799  if (s /* naParDeg(d)*/ <=1) return naCopy(d);
800  int s2=-1;
801  number d2;
802  int ss;
803  loop
804  {
805    pIter(ph);
806    if(ph==NULL)
807    {
808      if (s2==-1) return naCopy(d);
809      break;
810    }
811    if ((ss=naParDeg(pGetCoeff(ph)))<s)
812    {
813      s2=s;
814      d2=d;
815      s=ss;
816      d=pGetCoeff(ph);
817      if (s2<=1) break;
818    }
819  }
820  return naGcd(d,d2,currRing);
821}
822
823
824//void pContent(poly ph)
825//{
826//  number h,d;
827//  poly p;
828//
829//  p = ph;
830//  if(pNext(p)==NULL)
831//  {
832//    pSetCoeff(p,nInit(1));
833//  }
834//  else
835//  {
836//#ifdef PDEBUG
837//    if (!pTest(p)) return;
838//#endif
839//    nNormalize(pGetCoeff(p));
840//    if(!nGreaterZero(pGetCoeff(ph)))
841//    {
842//      ph = pNeg(ph);
843//      nNormalize(pGetCoeff(p));
844//    }
845//    h=pGetCoeff(p);
846//    pIter(p);
847//    while (p!=NULL)
848//    {
849//      nNormalize(pGetCoeff(p));
850//      if (nGreater(h,pGetCoeff(p))) h=pGetCoeff(p);
851//      pIter(p);
852//    }
853//    h=nCopy(h);
854//    p=ph;
855//    while (p!=NULL)
856//    {
857//      d=nGcd(h,pGetCoeff(p));
858//      nDelete(&h);
859//      h = d;
860//      if(nIsOne(h))
861//      {
862//        break;
863//      }
864//      pIter(p);
865//    }
866//    p = ph;
867//    //number tmp;
868//    if(!nIsOne(h))
869//    {
870//      while (p!=NULL)
871//      {
872//        d = nIntDiv(pGetCoeff(p),h);
873//        pSetCoeff(p,d);
874//        pIter(p);
875//      }
876//    }
877//    nDelete(&h);
878//#ifdef HAVE_FACTORY
879//    if ( (nGetChar() == 1) || (nGetChar() < 0) ) /* Q[a],Q(a),Zp[a],Z/p(a) */
880//    {
881//      pTest(ph);
882//      singclap_divide_content(ph);
883//      pTest(ph);
884//    }
885//#endif
886//  }
887//}
888#if 0
889void p_Content(poly ph, ring r)
890{
891  number h,d;
892  poly p;
893
894  if(pNext(ph)==NULL)
895  {
896    pSetCoeff(ph,n_Init(1,r));
897  }
898  else
899  {
900    n_Normalize(pGetCoeff(ph),r);
901    if(!n_GreaterZero(pGetCoeff(ph),r)) ph = p_Neg(ph,r);
902    h=n_Copy(pGetCoeff(ph),r);
903    p = pNext(ph);
904    while (p!=NULL)
905    {
906      n_Normalize(pGetCoeff(p),r);
907      d=n_Gcd(h,pGetCoeff(p),r);
908      n_Delete(&h,r);
909      h = d;
910      if(n_IsOne(h,r))
911      {
912        break;
913      }
914      pIter(p);
915    }
916    p = ph;
917    //number tmp;
918    if(!n_IsOne(h,r))
919    {
920      while (p!=NULL)
921      {
922        //d = nDiv(pGetCoeff(p),h);
923        //tmp = nIntDiv(pGetCoeff(p),h);
924        //if (!nEqual(d,tmp))
925        //{
926        //  StringSetS("** div0:");nWrite(pGetCoeff(p));StringAppendS("/");
927        //  nWrite(h);StringAppendS("=");nWrite(d);StringAppendS(" int:");
928        //  nWrite(tmp);Print(StringAppendS("\n"));
929        //}
930        //nDelete(&tmp);
931        d = n_IntDiv(pGetCoeff(p),h,r);
932        p_SetCoeff(p,d,r);
933        pIter(p);
934      }
935    }
936    n_Delete(&h,r);
937#ifdef HAVE_FACTORY
938    //if ( (n_GetChar(r) == 1) || (n_GetChar(r) < 0) ) /* Q[a],Q(a),Zp[a],Z/p(a) */
939    //{
940    //  singclap_divide_content(ph);
941    //  if(!n_GreaterZero(pGetCoeff(ph),r)) ph = p_Neg(ph,r);
942    //}
943#endif
944  }
945}
946#endif
947
948poly p_Cleardenom(poly ph, const ring r)
949{
950  poly start=ph;
951  number d, h;
952  poly p;
953
954#ifdef HAVE_RINGS
955  if (rField_is_Ring(r))
956  {
957    p_Content(ph,r);
958    return start;
959  }
960#endif
961  if (rField_is_Zp(r) && TEST_OPT_INTSTRATEGY) return start;
962  p = ph;
963  if(pNext(p)==NULL)
964  {
965    /*
966    if (TEST_OPT_CONTENTSB)
967    {
968      number n=nGetDenom(pGetCoeff(p));
969      if (!nIsOne(n))
970      {
971        number nn=nMult(pGetCoeff(p),n);
972        nNormalize(nn);
973        pSetCoeff(p,nn);
974      }
975      nDelete(&n);
976    }
977    else
978    */
979      pSetCoeff(p,nInit(1));
980  }
981  else
982  {
983    h = nInit(1);
984    while (p!=NULL)
985    {
986      nNormalize(pGetCoeff(p));
987      d=nLcm(h,pGetCoeff(p),currRing);
988      nDelete(&h);
989      h=d;
990      pIter(p);
991    }
992    /* contains the 1/lcm of all denominators */
993    if(!nIsOne(h))
994    {
995      p = ph;
996      while (p!=NULL)
997      {
998        /* should be:
999        * number hh;
1000        * nGetDenom(p->coef,&hh);
1001        * nMult(&h,&hh,&d);
1002        * nNormalize(d);
1003        * nDelete(&hh);
1004        * nMult(d,p->coef,&hh);
1005        * nDelete(&d);
1006        * nDelete(&(p->coef));
1007        * p->coef =hh;
1008        */
1009        d=nMult(h,pGetCoeff(p));
1010        nNormalize(d);
1011        pSetCoeff(p,d);
1012        pIter(p);
1013      }
1014      nDelete(&h);
1015      if (nGetChar()==1)
1016      {
1017        loop
1018        {
1019          h = nInit(1);
1020          p=ph;
1021          while (p!=NULL)
1022          {
1023            d=nLcm(h,pGetCoeff(p),currRing);
1024            nDelete(&h);
1025            h=d;
1026            pIter(p);
1027          }
1028          /* contains the 1/lcm of all denominators */
1029          if(!nIsOne(h))
1030          {
1031            p = ph;
1032            while (p!=NULL)
1033            {
1034              /* should be:
1035              * number hh;
1036              * nGetDenom(p->coef,&hh);
1037              * nMult(&h,&hh,&d);
1038              * nNormalize(d);
1039              * nDelete(&hh);
1040              * nMult(d,p->coef,&hh);
1041              * nDelete(&d);
1042              * nDelete(&(p->coef));
1043              * p->coef =hh;
1044              */
1045              d=nMult(h,pGetCoeff(p));
1046              nNormalize(d);
1047              pSetCoeff(p,d);
1048              pIter(p);
1049            }
1050            nDelete(&h);
1051          }
1052          else
1053          {
1054            nDelete(&h);
1055            break;
1056          }
1057        }
1058      }
1059    }
1060    if (h!=NULL) nDelete(&h);
1061 
1062    p_Content(ph,r);
1063#ifdef HAVE_RATGRING
1064    if (rIsRatGRing(r))
1065    {
1066      /* quick unit detection in the rational case is done in gr_nc_bba */
1067      pContentRat(ph);
1068      start=ph;
1069    }
1070#endif
1071  }
1072  return start;
1073}
1074
1075void p_Cleardenom_n(poly ph,const ring r,number &c)
1076{
1077  number d, h;
1078  poly p;
1079
1080  p = ph;
1081  if(pNext(p)==NULL)
1082  {
1083    c=nInvers(pGetCoeff(p));
1084    pSetCoeff(p,nInit(1));
1085  }
1086  else
1087  {
1088    h = nInit(1);
1089    while (p!=NULL)
1090    {
1091      nNormalize(pGetCoeff(p));
1092      d=nLcm(h,pGetCoeff(p),r);
1093      nDelete(&h);
1094      h=d;
1095      pIter(p);
1096    }
1097    c=h;
1098    /* contains the 1/lcm of all denominators */
1099    if(!nIsOne(h))
1100    {
1101      p = ph;
1102      while (p!=NULL)
1103      {
1104        /* should be:
1105        * number hh;
1106        * nGetDenom(p->coef,&hh);
1107        * nMult(&h,&hh,&d);
1108        * nNormalize(d);
1109        * nDelete(&hh);
1110        * nMult(d,p->coef,&hh);
1111        * nDelete(&d);
1112        * nDelete(&(p->coef));
1113        * p->coef =hh;
1114        */
1115        d=nMult(h,pGetCoeff(p));
1116        nNormalize(d);
1117        pSetCoeff(p,d);
1118        pIter(p);
1119      }
1120      if (nGetChar()==1)
1121      {
1122        loop
1123        {
1124          h = nInit(1);
1125          p=ph;
1126          while (p!=NULL)
1127          {
1128            d=nLcm(h,pGetCoeff(p),r);
1129            nDelete(&h);
1130            h=d;
1131            pIter(p);
1132          }
1133          /* contains the 1/lcm of all denominators */
1134          if(!nIsOne(h))
1135          {
1136            p = ph;
1137            while (p!=NULL)
1138            {
1139              /* should be:
1140              * number hh;
1141              * nGetDenom(p->coef,&hh);
1142              * nMult(&h,&hh,&d);
1143              * nNormalize(d);
1144              * nDelete(&hh);
1145              * nMult(d,p->coef,&hh);
1146              * nDelete(&d);
1147              * nDelete(&(p->coef));
1148              * p->coef =hh;
1149              */
1150              d=nMult(h,pGetCoeff(p));
1151              nNormalize(d);
1152              pSetCoeff(p,d);
1153              pIter(p);
1154            }
1155            number t=nMult(c,h);
1156            nDelete(&c);
1157            c=t;
1158          }
1159          else
1160          {
1161            break;
1162          }
1163          nDelete(&h);
1164        }
1165      }
1166    }
1167  }
1168}
1169
1170number p_GetAllDenom(poly ph, const ring r)
1171{
1172  number d=n_Init(1,r);
1173  poly p = ph;
1174
1175  while (p!=NULL)
1176  {
1177    number h=n_GetDenom(pGetCoeff(p),r);
1178    if (!n_IsOne(h,r))
1179    {
1180      number dd=n_Mult(d,h,r);
1181      n_Delete(&d,r);
1182      d=dd;
1183    }
1184    n_Delete(&h,r);
1185    pIter(p);
1186  }
1187  return d;
1188}
1189
1190/*2
1191*tests if p is homogeneous with respect to the actual weigths
1192*/
1193BOOLEAN pIsHomogeneous (poly p)
1194{
1195  poly qp=p;
1196  int o;
1197
1198  if ((p == NULL) || (pNext(p) == NULL)) return TRUE;
1199  pFDegProc d;
1200  if (pLexOrder && (currRing->order[0]==ringorder_lp))
1201    d=p_Totaldegree;
1202  else 
1203    d=pFDeg;
1204  o = d(p,currRing);
1205  do
1206  {
1207    if (d(qp,currRing) != o) return FALSE;
1208    pIter(qp);
1209  }
1210  while (qp != NULL);
1211  return TRUE;
1212}
1213
1214/*2
1215*returns a re-ordered copy of a polynomial, with permutation of the variables
1216*/
1217poly pPermPoly (poly p, int * perm, const ring oldRing, nMapFunc nMap,
1218   int *par_perm, int OldPar)
1219{
1220  int OldpVariables = oldRing->N;
1221  poly result = NULL;
1222  poly result_last = NULL;
1223  poly aq=NULL; /* the map coefficient */
1224  poly qq; /* the mapped monomial */
1225
1226  while (p != NULL)
1227  {
1228    if ((OldPar==0)||(rField_is_GF(oldRing)))
1229    {
1230      qq = pInit();
1231      number n=nMap(pGetCoeff(p));
1232      if ((currRing->minpoly!=NULL)
1233      && ((rField_is_Zp_a()) || (rField_is_Q_a())))
1234      {
1235        nNormalize(n);
1236      }
1237      pGetCoeff(qq)=n;
1238    // coef may be zero:  pTest(qq);
1239    }
1240    else
1241    {
1242      qq=pOne();
1243      aq=napPermNumber(pGetCoeff(p),par_perm,OldPar, oldRing);
1244      if ((currRing->minpoly!=NULL)
1245      && ((rField_is_Zp_a()) || (rField_is_Q_a())))
1246      {
1247        poly tmp=aq;
1248        while (tmp!=NULL)
1249        {
1250          number n=pGetCoeff(tmp);
1251          nNormalize(n);
1252          pGetCoeff(tmp)=n;
1253          pIter(tmp);
1254        }
1255      }
1256      pTest(aq);
1257    }
1258    if (rRing_has_Comp(currRing)) pSetComp(qq, p_GetComp(p,oldRing));
1259    if (nIsZero(pGetCoeff(qq)))
1260    {
1261      pLmDelete(&qq);
1262    }
1263    else
1264    {
1265      int i;
1266      int mapped_to_par=0;
1267      for(i=1; i<=OldpVariables; i++)
1268      {
1269        int e=p_GetExp(p,i,oldRing);
1270        if (e!=0)
1271        {
1272          if (perm==NULL)
1273          {
1274            pSetExp(qq,i, e);
1275          }
1276          else if (perm[i]>0)
1277            pAddExp(qq,perm[i], e/*p_GetExp( p,i,oldRing)*/);
1278          else if (perm[i]<0)
1279          {
1280            if (rField_is_GF())
1281            {
1282              number c=pGetCoeff(qq);
1283              number ee=nfPar(1);
1284              number eee;nfPower(ee,e,&eee); //nfDelete(ee,currRing);
1285              ee=nfMult(c,eee);
1286              //nfDelete(c,currRing);nfDelete(eee,currRing);
1287              pSetCoeff0(qq,ee);
1288            }
1289            else
1290            {
1291              lnumber c=(lnumber)pGetCoeff(qq);
1292              if (c->z->next==NULL)
1293                napAddExp(c->z,-perm[i],e/*p_GetExp( p,i,oldRing)*/);
1294              else /* more difficult: we have really to multiply: */
1295              {
1296                lnumber mmc=(lnumber)naInit(1,currRing);
1297                napSetExp(mmc->z,-perm[i],e/*p_GetExp( p,i,oldRing)*/);
1298                napSetm(mmc->z);
1299                pGetCoeff(qq)=naMult((number)c,(number)mmc);
1300                nDelete((number *)&c);
1301                nDelete((number *)&mmc); 
1302              }
1303              mapped_to_par=1;
1304            }
1305          }
1306          else
1307          {
1308            /* this variable maps to 0 !*/
1309            pLmDelete(&qq);
1310            break;
1311          }
1312        }
1313      }
1314      if (mapped_to_par
1315      && (currRing->minpoly!=NULL))
1316      {
1317        number n=pGetCoeff(qq);
1318        nNormalize(n);
1319        pGetCoeff(qq)=n;
1320      }
1321    }
1322    pIter(p);
1323#if 1
1324    if (qq!=NULL)
1325    {
1326      pSetm(qq);
1327      pTest(aq);
1328      pTest(qq);
1329      if (aq!=NULL) qq=pMult(aq,qq);
1330      aq = qq;
1331      while (pNext(aq) != NULL) pIter(aq);
1332      if (result_last==NULL)
1333      {
1334        result=qq;
1335      }
1336      else
1337      {
1338        pNext(result_last)=qq;
1339      }
1340      result_last=aq;
1341      aq = NULL;
1342    }
1343    else if (aq!=NULL)
1344    {
1345      pDelete(&aq);
1346    }
1347  }
1348  result=pSortAdd(result);
1349#else
1350  //  if (qq!=NULL)
1351  //  {
1352  //    pSetm(qq);
1353  //    pTest(qq);
1354  //    pTest(aq);
1355  //    if (aq!=NULL) qq=pMult(aq,qq);
1356  //    aq = qq;
1357  //    while (pNext(aq) != NULL) pIter(aq);
1358  //    pNext(aq) = result;
1359  //    aq = NULL;
1360  //    result = qq;
1361  //  }
1362  //  else if (aq!=NULL)
1363  //  {
1364  //    pDelete(&aq);
1365  //  }
1366  //}
1367  //p = result;
1368  //result = NULL;
1369  //while (p != NULL)
1370  //{
1371  //  qq = p;
1372  //  pIter(p);
1373  //  qq->next = NULL;
1374  //  result = pAdd(result, qq);
1375  //}
1376#endif
1377  pTest(result);
1378  return result;
1379}
1380
1381poly ppJet(poly p, int m)
1382{
1383  poly r=NULL;
1384  poly t=NULL;
1385
1386  while (p!=NULL)
1387  {
1388    if (p_Totaldegree(p,currRing)<=m)
1389    {
1390      if (r==NULL)
1391        r=pHead(p);
1392      else
1393      if (t==NULL)
1394      {
1395        pNext(r)=pHead(p);
1396        t=pNext(r);
1397      }
1398      else
1399      {
1400        pNext(t)=pHead(p);
1401        pIter(t);
1402      }
1403    }
1404    pIter(p);
1405  }
1406  return r;
1407}
1408
1409poly pJet(poly p, int m)
1410{
1411  poly t=NULL;
1412
1413  while((p!=NULL) && (p_Totaldegree(p,currRing)>m)) pLmDelete(&p);
1414  if (p==NULL) return NULL;
1415  poly r=p;
1416  while (pNext(p)!=NULL)
1417  {
1418    if (p_Totaldegree(pNext(p),currRing)>m)
1419    {
1420      pLmDelete(&pNext(p));
1421    }
1422    else
1423      pIter(p);
1424  }
1425  return r;
1426}
1427
1428poly ppJetW(poly p, int m, short *w)
1429{
1430  poly r=NULL;
1431  poly t=NULL;
1432  while (p!=NULL)
1433  {
1434    if (totaldegreeWecart_IV(p,currRing,w)<=m)
1435    {
1436      if (r==NULL)
1437        r=pHead(p);
1438      else
1439      if (t==NULL)
1440      {
1441        pNext(r)=pHead(p);
1442        t=pNext(r);
1443      }
1444      else
1445      {
1446        pNext(t)=pHead(p);
1447        pIter(t);
1448      }
1449    }
1450    pIter(p);
1451  }
1452  return r;
1453}
1454
1455poly pJetW(poly p, int m, short *w)
1456{
1457  while((p!=NULL) && (totaldegreeWecart_IV(p,currRing,w)>m)) pLmDelete(&p);
1458  if (p==NULL) return NULL;
1459  poly r=p;
1460  while (pNext(p)!=NULL)
1461  {
1462    if (totaldegreeWecart_IV(pNext(p),currRing,w)>m)
1463    {
1464      pLmDelete(&pNext(p));
1465    }
1466    else
1467      pIter(p);
1468  }
1469  return r;
1470}
1471
1472int pMinDeg(poly p,intvec *w)
1473{
1474  if(p==NULL)
1475    return -1;
1476  int d=-1;
1477  while(p!=NULL)
1478  {
1479    int d0=0;
1480    for(int j=0;j<pVariables;j++)
1481      if(w==NULL||j>=w->length())
1482        d0+=pGetExp(p,j+1);
1483      else
1484        d0+=(*w)[j]*pGetExp(p,j+1);
1485    if(d0<d||d==-1)
1486      d=d0;
1487    pIter(p);
1488  }
1489  return d;
1490}
1491
1492poly pSeries(int n,poly p,poly u, intvec *w)
1493{
1494  short *ww=iv2array(w);
1495  if(p!=NULL)
1496  {
1497    if(u==NULL)
1498      p=pJetW(p,n,ww);
1499    else
1500      p=pJetW(pMult(p,pInvers(n-pMinDeg(p,w),u,w)),n,ww);
1501  }
1502  omFreeSize((ADDRESS)ww,(pVariables+1)*sizeof(short));
1503  return p;
1504}
1505
1506poly pInvers(int n,poly u,intvec *w)
1507{
1508  short *ww=iv2array(w);
1509  if(n<0)
1510    return NULL;
1511  number u0=nInvers(pGetCoeff(u));
1512  poly v=pNSet(u0);
1513  if(n==0)
1514    return v;
1515  poly u1=pJetW(pSub(pOne(),pMult_nn(u,u0)),n,ww);
1516  if(u1==NULL)
1517    return v;
1518  poly v1=pMult_nn(pCopy(u1),u0);
1519  v=pAdd(v,pCopy(v1));
1520  for(int i=n/pMinDeg(u1,w);i>1;i--)
1521  {
1522    v1=pJetW(pMult(v1,pCopy(u1)),n,ww);
1523    v=pAdd(v,pCopy(v1));
1524  }
1525  pDelete(&u1);
1526  pDelete(&v1);
1527  omFreeSize((ADDRESS)ww,(pVariables+1)*sizeof(short));
1528  return v;
1529}
1530
1531long pDegW(poly p, const short *w)
1532{
1533  long r=-LONG_MAX;
1534
1535  while (p!=NULL)
1536  {
1537    long t=totaldegreeWecart_IV(p,currRing,w);
1538    if (t>r) r=t;
1539    pIter(p);
1540  }
1541  return r;
1542}
1543
1544/*-----------type conversions ----------------------------*/
1545#if 0
1546/*2
1547* input: a set of polys (len elements: p[0]..p[len-1])
1548* output: a vector
1549* p will not be changed
1550*/
1551poly  pPolys2Vec(polyset p, int len)
1552{
1553  poly v=NULL;
1554  poly h;
1555  int i;
1556
1557  for (i=len-1; i>=0; i--)
1558  {
1559    if (p[i])
1560    {
1561      h=pCopy(p[i]);
1562      pSetCompP(h,i+1);
1563      v=pAdd(v,h);
1564    }
1565  }
1566 return v;
1567}
1568#endif
1569
1570/*2
1571* convert a vector to a set of polys,
1572* allocates the polyset, (entries 0..(*len)-1)
1573* the vector will not be changed
1574*/
1575void  pVec2Polys(poly v, polyset *p, int *len)
1576{
1577  poly h;
1578  int k;
1579
1580  *len=pMaxComp(v);
1581  if (*len==0) *len=1;
1582  *p=(polyset)omAlloc0((*len)*sizeof(poly));
1583  while (v!=NULL)
1584  {
1585    h=pHead(v);
1586    k=pGetComp(h);
1587    pSetComp(h,0);
1588    (*p)[k-1]=pAdd((*p)[k-1],h);
1589    pIter(v);
1590  }
1591}
1592
1593int p_Var(poly m,const ring r)
1594{
1595  if (m==NULL) return 0;
1596  if (pNext(m)!=NULL) return 0;
1597  int i,e=0;
1598  for (i=r->N; i>0; i--)
1599  {
1600    int exp=p_GetExp(m,i,r);
1601    if (exp==1)
1602    {
1603      if (e==0) e=i;
1604      else return 0;
1605    }
1606    else if (exp!=0)
1607    {
1608      return 0;
1609    }
1610  }
1611  return e;
1612}
1613
1614/*----------utilities for syzygies--------------*/
1615//BOOLEAN   pVectorHasUnitM(poly p, int * k)
1616//{
1617//  while (p!=NULL)
1618//  {
1619//    if (pLmIsConstantComp(p))
1620//    {
1621//      *k = pGetComp(p);
1622//      return TRUE;
1623//    }
1624//    else pIter(p);
1625//  }
1626//  return FALSE;
1627//}
1628
1629BOOLEAN   pVectorHasUnitB(poly p, int * k)
1630{
1631  poly q=p,qq;
1632  int i;
1633
1634  while (q!=NULL)
1635  {
1636    if (pLmIsConstantComp(q))
1637    {
1638      i = pGetComp(q);
1639      qq = p;
1640      while ((qq != q) && (pGetComp(qq) != i)) pIter(qq);
1641      if (qq == q)
1642      {
1643        *k = i;
1644        return TRUE;
1645      }
1646      else
1647        pIter(q);
1648    }
1649    else pIter(q);
1650  }
1651  return FALSE;
1652}
1653
1654void   pVectorHasUnit(poly p, int * k, int * len)
1655{
1656  poly q=p,qq;
1657  int i,j=0;
1658
1659  *len = 0;
1660  while (q!=NULL)
1661  {
1662    if (pLmIsConstantComp(q))
1663    {
1664      i = pGetComp(q);
1665      qq = p;
1666      while ((qq != q) && (pGetComp(qq) != i)) pIter(qq);
1667      if (qq == q)
1668      {
1669       j = 0;
1670       while (qq!=NULL)
1671       {
1672         if (pGetComp(qq)==i) j++;
1673        pIter(qq);
1674       }
1675       if ((*len == 0) || (j<*len))
1676       {
1677         *len = j;
1678         *k = i;
1679       }
1680      }
1681    }
1682    pIter(q);
1683  }
1684}
1685
1686/*2
1687* returns TRUE if p1 = p2
1688*/
1689BOOLEAN p_EqualPolys(poly p1,poly p2, const ring r)
1690{
1691  while ((p1 != NULL) && (p2 != NULL))
1692  {
1693    if (! p_LmEqual(p1, p2,r))
1694      return FALSE;
1695    if (! n_Equal(p_GetCoeff(p1,r), p_GetCoeff(p2,r),r ))
1696      return FALSE;
1697    pIter(p1);
1698    pIter(p2);
1699  }
1700  return (p1==p2);
1701}
1702
1703/*2
1704*returns TRUE if p1 is a skalar multiple of p2
1705*assume p1 != NULL and p2 != NULL
1706*/
1707BOOLEAN pComparePolys(poly p1,poly p2)
1708{
1709  number n,nn;
1710  pAssume(p1 != NULL && p2 != NULL);
1711
1712  if (!pLmEqual(p1,p2)) //compare leading mons
1713      return FALSE;
1714  if ((pNext(p1)==NULL) && (pNext(p2)!=NULL))
1715     return FALSE;
1716  if ((pNext(p2)==NULL) && (pNext(p1)!=NULL))
1717     return FALSE;
1718  if (pLength(p1) != pLength(p2))
1719    return FALSE;
1720#ifdef HAVE_RINGS
1721  if (rField_is_Ring(currRing))
1722  {
1723    if (!nDivBy(pGetCoeff(p1), pGetCoeff(p2))) return FALSE;
1724  }
1725#endif
1726  n=nDiv(pGetCoeff(p1),pGetCoeff(p2));
1727  while ((p1 != NULL) /*&& (p2 != NULL)*/)
1728  {
1729    if ( ! pLmEqual(p1, p2))
1730    {
1731        nDelete(&n);
1732        return FALSE;
1733    }
1734    if (!nEqual(pGetCoeff(p1),nn=nMult(pGetCoeff(p2),n)))
1735    {
1736      nDelete(&n);
1737      nDelete(&nn);
1738      return FALSE;
1739    }
1740    nDelete(&nn);
1741    pIter(p1);
1742    pIter(p2);
1743  }
1744  nDelete(&n);
1745  return TRUE;
1746}
Note: See TracBrowser for help on using the repository browser.