source: git/kernel/polys.cc @ ded4ee

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