source: git/kernel/p_polys.cc @ 5a9e7b

spielwiese
Last change on this file since 5a9e7b was 33c36d, checked in by Hans Schönemann <hannes@…>, 17 years ago
*hannes: const in pSetm git-svn-id: file:///usr/local/Singular/svn/trunk@9517 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 19.7 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/***************************************************************
5 *  File:    p_polys.cc
6 *  Purpose: implementation of currRing independent poly procedures
7 *  Author:  obachman (Olaf Bachmann)
8 *  Created: 8/00
9 *  Version: $Id: p_polys.cc,v 1.5 2006-11-23 15:04:54 Singular Exp $
10 *******************************************************************/
11
12#include "mod2.h"
13#include "structs.h"
14#include "structs.h"
15#include "p_polys.h"
16#include "ring.h"
17#include "int64vec.h"
18#ifndef NDEBUG
19#include "febase.h"
20#endif
21
22/***************************************************************
23 *
24 * Completing what needs to be set for the monomial
25 *
26 ***************************************************************/
27// this is special for the syz stuff
28static int* _Components = NULL;
29static long* _ShiftedComponents = NULL;
30static int _ExternalComponents = 0;
31
32BOOLEAN pSetm_error=0;
33
34void p_Setm_General(poly p, const ring r)
35{
36  p_LmCheckPolyRing(p, r);
37  int pos=0;
38  if (r->typ!=NULL)
39  {
40    loop
41    {
42      long ord=0;
43      sro_ord* o=&(r->typ[pos]);
44      switch(o->ord_typ)
45      {
46        case ro_dp:
47        {
48          int a,e;
49          a=o->data.dp.start;
50          e=o->data.dp.end;
51          for(int i=a;i<=e;i++) ord+=p_GetExp(p,i,r);
52          p->exp[o->data.dp.place]=ord;
53          break;
54        }
55        case ro_wp_neg:
56          ord=POLY_NEGWEIGHT_OFFSET;
57          // no break;
58        case ro_wp:
59        {
60          int a,e;
61          a=o->data.wp.start;
62          e=o->data.wp.end;
63          int *w=o->data.wp.weights;
64#if 1
65          for(int i=a;i<=e;i++) ord+=p_GetExp(p,i,r)*w[i-a];
66#else
67          long ai;
68          int ei,wi;
69          for(int i=a;i<=e;i++)
70          {
71             ei=p_GetExp(p,i,r);
72             wi=w[i-a];
73             ai=ei*wi;
74             if (ai/ei!=wi) pSetm_error=TRUE;
75             ord+=ai;
76             if (ord<ai) pSetm_error=TRUE;
77          }
78#endif 
79          p->exp[o->data.wp.place]=ord;
80          break;
81        }
82      case ro_wp64:
83        {
84          int64 ord=0;
85          int a,e;
86          a=o->data.wp64.start;
87          e=o->data.wp64.end;
88          int64 *w=o->data.wp64.weights64;
89          int64 ei,wi,ai;
90          for(int i=a;i<=e;i++) {
91            //Print("exp %d w %d \n",p_GetExp(p,i,r),(int)w[i-a]);
92            //ord+=((int64)p_GetExp(p,i,r))*w[i-a];
93            ei=(int64)p_GetExp(p,i,r);
94            wi=w[i-a];
95            ai=ei*wi;
96            if(ei!=0 && ai/ei!=wi){ 
97              pSetm_error=TRUE;
98              Print("ai %lld, wi %lld\n",ai,wi);
99            }
100            ord+=ai;
101            if (ord<ai){
102               pSetm_error=TRUE;
103               Print("ai %lld, ord %lld\n",ai,ord);
104            }
105          }
106          int64 mask=(int64)0x7fffffff;
107          long a_0=(long)(ord&mask); //2^31
108          long a_1=(long)(ord >>31 ); /*(ord/(mask+1));*/
109
110          //Print("mask: %x,  ord: %d,  a_0: %d,  a_1: %d\n"
111          //,(int)mask,(int)ord,(int)a_0,(int)a_1);
112                    //Print("mask: %d",mask);
113
114          p->exp[o->data.wp64.place]=a_1;
115          p->exp[o->data.wp64.place+1]=a_0;
116//            if(p_Setm_error) Print("***************************\n
117//                                    ***************************\n
118//                                    **WARNING: overflow error**\n
119//                                    ***************************\n
120//                                    ***************************\n");
121          break;
122        }
123        case ro_cp:
124        {
125          int a,e;
126          a=o->data.cp.start;
127          e=o->data.cp.end;
128          int pl=o->data.cp.place;
129          for(int i=a;i<=e;i++) { p->exp[pl]=p_GetExp(p,i,r); pl++; }
130          break;
131        }
132        case ro_syzcomp:
133        {
134          int c=p_GetComp(p,r);
135          long sc = c;
136          int* Components = (_ExternalComponents ? _Components : 
137                             o->data.syzcomp.Components);
138          long* ShiftedComponents = (_ExternalComponents ? _ShiftedComponents: 
139                                     o->data.syzcomp.ShiftedComponents);
140          if (ShiftedComponents != NULL)
141          {
142            assume(Components != NULL);
143            assume(c == 0 || Components[c] != 0);
144            sc = ShiftedComponents[Components[c]];
145            assume(c == 0 || sc != 0);
146          }
147          p->exp[o->data.syzcomp.place]=sc;
148          break;
149        }
150        case ro_syz:
151        {
152          int c=p_GetComp(p, r);
153          if (c > o->data.syz.limit)
154            p->exp[o->data.syz.place] = o->data.syz.curr_index;
155          else if (c > 0)
156            p->exp[o->data.syz.place]= o->data.syz.syz_index[c];
157          else
158          {
159            assume(c == 0);
160            p->exp[o->data.syz.place]= 0;
161          }
162          break;
163        }
164        default:
165          dReportError("wrong ord in rSetm:%d\n",o->ord_typ);
166          return;
167      }
168      pos++;
169      if (pos == r->OrdSize) return;
170    }
171  }
172}
173
174void p_Setm_Syz(poly p, ring r, int* Components, long* ShiftedComponents)
175{
176  _Components = Components;
177  _ShiftedComponents = ShiftedComponents;
178  _ExternalComponents = 1;
179  p_Setm_General(p, r);
180  _ExternalComponents = 0;
181}
182
183// dummy for lp, ls, etc
184void p_Setm_Dummy(poly p, const ring r)
185{
186  p_LmCheckPolyRing(p, r);
187}
188
189// for dp, Dp, ds, etc
190void p_Setm_TotalDegree(poly p, const ring r)
191{
192  p_LmCheckPolyRing(p, r);
193  p->exp[r->pOrdIndex] = p_ExpVectorQuerSum(p, r);
194}
195
196// for wp, Wp, ws, etc
197void p_Setm_WFirstTotalDegree(poly p, const ring r)
198{
199  p_LmCheckPolyRing(p, r);
200  p->exp[r->pOrdIndex] = pWFirstTotalDegree(p, r);
201}
202
203p_SetmProc p_GetSetmProc(ring r)
204{
205  // covers lp, rp, ls,
206  if (r->typ == NULL) return p_Setm_Dummy;
207
208  if (r->OrdSize == 1)
209  {
210    if (r->typ[0].ord_typ == ro_dp && 
211        r->typ[0].data.dp.start == 1 &&
212        r->typ[0].data.dp.end == r->N &&
213        r->typ[0].data.dp.place == r->pOrdIndex)
214      return p_Setm_TotalDegree;
215    if (r->typ[0].ord_typ == ro_wp && 
216        r->typ[0].data.wp.start == 1 &&
217        r->typ[0].data.wp.end == r->N &&
218        r->typ[0].data.wp.place == r->pOrdIndex &&
219        r->typ[0].data.wp.weights == r->firstwv)
220      return p_Setm_WFirstTotalDegree;
221  }
222  return p_Setm_General;
223}
224
225
226/* -------------------------------------------------------------------*/
227/* several possibilities for pFDeg: the degree of the head term       */
228/*2
229* compute the degree of the leading monomial of p
230* the ordering is compatible with degree, use a->order
231*/
232inline long _pDeg(poly a, ring r)
233{
234  p_LmCheckPolyRing(a, r);
235  assume(p_GetOrder(a, r) == pWTotaldegree(a, r));
236  return p_GetOrder(a, r);
237}
238
239long pDeg(poly a, ring r)
240{
241  return _pDeg(a, r);
242}
243
244/*2
245* compute the degree of the leading monomial of p
246* with respect to weigths 1
247* (all are 1 so save multiplications or they are of different signs)
248* the ordering is not compatible with degree so do not use p->Order
249*/
250inline long _pTotaldegree(poly p, ring r)
251{
252  p_LmCheckPolyRing(p, r);
253  return (long) p_ExpVectorQuerSum(p, r);
254}
255long pTotaldegree(poly p, ring r)
256{
257  return (long) _pTotaldegree(p, r);
258}
259
260// pWTotalDegree for weighted orderings
261// whose first block covers all variables
262inline long _pWFirstTotalDegree(poly p, ring r)
263{
264  int i;
265  long sum = 0;
266 
267  for (i=1; i<= r->firstBlockEnds; i++)
268  {
269    sum += p_GetExp(p, i, r)*r->firstwv[i-1];
270  }
271  return sum;
272}
273
274long pWFirstTotalDegree(poly p, ring r)
275{
276  return (long) _pWFirstTotalDegree(p, r);
277}
278
279/*2
280* compute the degree of the leading monomial of p
281* with respect to weigths from the ordering
282* the ordering is not compatible with degree so do not use p->Order
283*/
284long pWTotaldegree(poly p, ring r)
285{
286  p_LmCheckPolyRing(p, r);
287  int i, k;
288  long j =0;
289
290  // iterate through each block:
291  for (i=0;r->order[i]!=0;i++)
292  {
293    switch(r->order[i])
294    {
295      case ringorder_wp:
296      case ringorder_ws:
297      case ringorder_Wp:
298      case ringorder_Ws:
299        for (k=r->block0[i];k<=r->block1[i];k++)
300        { // in jedem block:
301          j+= p_GetExp(p,k,r)*r->wvhdl[i][k - r->block0[i]];
302        }
303        break;
304      case ringorder_M:
305      case ringorder_lp:
306      case ringorder_ls:
307      case ringorder_dp:
308      case ringorder_ds:
309      case ringorder_Dp:
310      case ringorder_Ds:
311      case ringorder_rp:
312        for (k=r->block0[i];k<=r->block1[i];k++)
313        {
314          j+= p_GetExp(p,k,r);
315        }
316        break;
317      case ringorder_a64:
318        {
319          int64* w=(int64*)r->wvhdl[i];
320          for (k=0;k<=(r->block1[i] - r->block0[i]);k++)
321          { 
322            //there should be added a line which checks if w[k]>2^31
323            j+= p_GetExp(p,k+1, r)*(long)w[k];
324          }
325          //break;
326          return j;
327        }
328      case ringorder_c:
329      case ringorder_C:
330      case ringorder_S:
331      case ringorder_s:
332      case ringorder_aa:
333        break;
334      case ringorder_a:
335        for (k=r->block0[i];k<=r->block1[i];k++)
336        { // only one line
337          j+= p_GetExp(p,k, r)*r->wvhdl[i][ k- r->block0[i]];
338        }
339        //break;
340        return j;
341
342#ifndef NDEBUG
343      default:
344        Print("missing order %d in pWTotaldegree\n",r->order[i]);
345        break;
346#endif
347    }
348  }
349  return  j;
350}
351
352int pWeight(int i, const ring r)
353{
354  if ((r->firstwv==NULL) || (i>r->firstBlockEnds))
355  {
356    return 1;
357  }
358  return r->firstwv[i-1];
359}
360
361long pWDegree(poly p, ring r)
362{
363  if (r->firstwv==NULL) return pTotaldegree(p, r);
364  p_LmCheckPolyRing(p, r);
365  int i, k;
366  long j =0;
367
368  for(i=1;i<=r->firstBlockEnds;i++)
369    j+=p_GetExp(p, i, r)*r->firstwv[i-1];
370
371  for (;i<=r->N;i++)
372    j+=p_GetExp(p,i, r)*pWeight(i, r);
373
374  return j;
375}
376
377
378/* ---------------------------------------------------------------------*/
379/* several possibilities for pLDeg: the maximal degree of a monomial in p*/
380/*  compute in l also the pLength of p                                   */
381
382/*2
383* compute the length of a polynomial (in l)
384* and the degree of the monomial with maximal degree: the last one
385*/
386long pLDeg0(poly p,int *l, ring r)
387{
388  p_CheckPolyRing(p, r);
389  Exponent_t k= p_GetComp(p, r);
390  int ll=1;
391
392  if (k > 0)
393  {
394    while ((pNext(p)!=NULL) && (p_GetComp(pNext(p), r)==k))
395    {
396      pIter(p);
397      ll++;
398    }
399  }
400  else
401  {
402     while (pNext(p)!=NULL)
403     {
404       pIter(p);
405       ll++;
406     }
407  }
408  *l=ll;
409  return r->pFDeg(p, r);
410}
411
412/*2
413* compute the length of a polynomial (in l)
414* and the degree of the monomial with maximal degree: the last one
415* but search in all components before syzcomp
416*/
417long pLDeg0c(poly p,int *l, ring r)
418{
419  assume(p!=NULL);
420#ifdef PDEBUG
421  _p_Test(p,r,PDEBUG);
422#endif
423  p_CheckPolyRing(p, r);
424  long o;
425  int ll=1;
426
427  if (! rIsSyzIndexRing(r))
428  {
429    while (pNext(p) != NULL) 
430    {
431      pIter(p);
432      ll++;
433    }
434    o = r->pFDeg(p, r);
435  }
436  else
437  {
438    int curr_limit = rGetCurrSyzLimit(r);
439    poly pp = p;
440    while ((p=pNext(p))!=NULL)
441    {
442      if (p_GetComp(p, r)<=curr_limit/*syzComp*/)
443        ll++;
444      else break;
445      pp = p;
446    }
447#ifdef PDEBUG
448    _p_Test(pp,r,PDEBUG);
449#endif
450    o = r->pFDeg(pp, r);
451  }
452  *l=ll;
453  return o;
454}
455
456/*2
457* compute the length of a polynomial (in l)
458* and the degree of the monomial with maximal degree: the first one
459* this works for the polynomial case with degree orderings
460* (both c,dp and dp,c)
461*/
462long pLDegb(poly p,int *l, ring r)
463{
464  p_CheckPolyRing(p, r);
465  Exponent_t k= p_GetComp(p, r);
466  long o = r->pFDeg(p, r);
467  int ll=1;
468
469  if (k != 0)
470  {
471    while (((p=pNext(p))!=NULL) && (p_GetComp(p, r)==k))
472    {
473      ll++;
474    }
475  }
476  else
477  {
478    while ((p=pNext(p)) !=NULL)
479    {
480      ll++;
481    }
482  }
483  *l=ll;
484  return o;
485}
486
487/*2
488* compute the length of a polynomial (in l)
489* and the degree of the monomial with maximal degree:
490* this is NOT the last one, we have to look for it
491*/
492long pLDeg1(poly p,int *l, ring r)
493{
494  p_CheckPolyRing(p, r);
495  Exponent_t k= p_GetComp(p, r);
496  int ll=1;
497  long  t,max;
498
499  max=r->pFDeg(p, r);
500  if (k > 0)
501  {
502    while (((p=pNext(p))!=NULL) && (p_GetComp(p, r)==k))
503    {
504      t=r->pFDeg(p, r);
505      if (t>max) max=t;
506      ll++;
507    }
508  }
509  else
510  {
511    while ((p=pNext(p))!=NULL)
512    {
513      t=r->pFDeg(p, r);
514      if (t>max) max=t;
515      ll++;
516    }
517  }
518  *l=ll;
519  return max;
520}
521
522/*2
523* compute the length of a polynomial (in l)
524* and the degree of the monomial with maximal degree:
525* this is NOT the last one, we have to look for it
526* in all components
527*/
528long pLDeg1c(poly p,int *l, ring r)
529{
530  p_CheckPolyRing(p, r);
531  int ll=1;
532  long  t,max;
533
534  max=r->pFDeg(p, r);
535  if (rIsSyzIndexRing(r))
536  {
537    long limit = rGetCurrSyzLimit(r);
538    while ((p=pNext(p))!=NULL)
539    {
540      if (p_GetComp(p, r)<=limit)
541      {
542        if ((t=r->pFDeg(p, r))>max) max=t;
543        ll++;
544      }
545      else break;
546    }
547  }
548  else
549  {
550    while ((p=pNext(p))!=NULL)
551    {
552      if ((t=r->pFDeg(p, r))>max) max=t;
553      ll++;
554    }
555  }
556  *l=ll;
557  return max;
558}
559
560// like pLDeg1, only pFDeg == pDeg
561long pLDeg1_Deg(poly p,int *l, ring r)
562{
563  assume(r->pFDeg == pDeg);
564  p_CheckPolyRing(p, r);
565  Exponent_t k= p_GetComp(p, r);
566  int ll=1;
567  long  t,max;
568
569  max=_pDeg(p, r);
570  if (k > 0)
571  {
572    while (((p=pNext(p))!=NULL) && (p_GetComp(p, r)==k))
573    {
574      t=_pDeg(p, r);
575      if (t>max) max=t;
576      ll++;
577    }
578  }
579  else
580  {
581    while ((p=pNext(p))!=NULL)
582    {
583      t=_pDeg(p, r);
584      if (t>max) max=t;
585      ll++;
586    }
587  }
588  *l=ll;
589  return max;
590}
591
592long pLDeg1c_Deg(poly p,int *l, ring r)
593{
594  assume(r->pFDeg == pDeg);
595  p_CheckPolyRing(p, r);
596  int ll=1;
597  long  t,max;
598
599  max=_pDeg(p, r);
600  if (rIsSyzIndexRing(r))
601  {
602    long limit = rGetCurrSyzLimit(r);
603    while ((p=pNext(p))!=NULL)
604    {
605      if (p_GetComp(p, r)<=limit)
606      {
607        if ((t=_pDeg(p, r))>max) max=t;
608        ll++;
609      }
610      else break;
611    }
612  }
613  else
614  {
615    while ((p=pNext(p))!=NULL)
616    {
617      if ((t=_pDeg(p, r))>max) max=t;
618      ll++;
619    }
620  }
621  *l=ll;
622  return max;
623}
624
625// like pLDeg1, only pFDeg == pTotoalDegree
626long pLDeg1_Totaldegree(poly p,int *l, ring r)
627{
628  p_CheckPolyRing(p, r);
629  Exponent_t k= p_GetComp(p, r);
630  int ll=1;
631  long  t,max;
632
633  max=_pTotaldegree(p, r);
634  if (k > 0)
635  {
636    while (((p=pNext(p))!=NULL) && (p_GetComp(p, r)==k))
637    {
638      t=_pTotaldegree(p, r);
639      if (t>max) max=t;
640      ll++;
641    }
642  }
643  else
644  {
645    while ((p=pNext(p))!=NULL)
646    {
647      t=_pTotaldegree(p, r);
648      if (t>max) max=t;
649      ll++;
650    }
651  }
652  *l=ll;
653  return max;
654}
655
656long pLDeg1c_Totaldegree(poly p,int *l, ring r)
657{
658  p_CheckPolyRing(p, r);
659  int ll=1;
660  long  t,max;
661
662  max=_pTotaldegree(p, r);
663  if (rIsSyzIndexRing(r))
664  {
665    long limit = rGetCurrSyzLimit(r);
666    while ((p=pNext(p))!=NULL)
667    {
668      if (p_GetComp(p, r)<=limit)
669      {
670        if ((t=_pTotaldegree(p, r))>max) max=t;
671        ll++;
672      }
673      else break;
674    }
675  }
676  else
677  {
678    while ((p=pNext(p))!=NULL)
679    {
680      if ((t=_pTotaldegree(p, r))>max) max=t;
681      ll++;
682    }
683  }
684  *l=ll;
685  return max;
686}
687
688// like pLDeg1, only pFDeg == pWFirstTotalDegree
689long pLDeg1_WFirstTotalDegree(poly p,int *l, ring r)
690{
691  p_CheckPolyRing(p, r);
692  Exponent_t k= p_GetComp(p, r);
693  int ll=1;
694  long  t,max;
695
696  max=_pWFirstTotalDegree(p, r);
697  if (k > 0)
698  {
699    while (((p=pNext(p))!=NULL) && (p_GetComp(p, r)==k))
700    {
701      t=_pWFirstTotalDegree(p, r);
702      if (t>max) max=t;
703      ll++;
704    }
705  }
706  else
707  {
708    while ((p=pNext(p))!=NULL)
709    {
710      t=_pWFirstTotalDegree(p, r);
711      if (t>max) max=t;
712      ll++;
713    }
714  }
715  *l=ll;
716  return max;
717}
718
719long pLDeg1c_WFirstTotalDegree(poly p,int *l, ring r)
720{
721  p_CheckPolyRing(p, r);
722  int ll=1;
723  long  t,max;
724
725  max=_pWFirstTotalDegree(p, r);
726  if (rIsSyzIndexRing(r))
727  {
728    long limit = rGetCurrSyzLimit(r);
729    while ((p=pNext(p))!=NULL)
730    {
731      if (p_GetComp(p, r)<=limit)
732      {
733        if ((t=_pTotaldegree(p, r))>max) max=t;
734        ll++;
735      }
736      else break;
737    }
738  }
739  else
740  {
741    while ((p=pNext(p))!=NULL)
742    {
743      if ((t=_pTotaldegree(p, r))>max) max=t;
744      ll++;
745    }
746  }
747  *l=ll;
748  return max;
749}
750
751/***************************************************************
752 *
753 * Maximal Exponent business
754 *
755 ***************************************************************/
756
757static inline unsigned long 
758p_GetMaxExpL2(unsigned long l1, unsigned long l2, ring r, 
759              unsigned long number_of_exp)
760{
761  const unsigned long bitmask = r->bitmask;
762  unsigned long ml1 = l1 & bitmask;
763  unsigned long ml2 = l2 & bitmask;
764  unsigned long max = (ml1 > ml2 ? ml1 : ml2);
765  unsigned long j = number_of_exp - 1;
766
767  if (j > 0)
768  {
769    unsigned long mask = bitmask << r->BitsPerExp;
770    while (1)
771    {
772      ml1 = l1 & mask;
773      ml2 = l2 & mask;
774      max |= ((ml1 > ml2 ? ml1 : ml2) & mask);
775      j--;
776      if (j == 0) break;
777      mask = mask << r->BitsPerExp;
778    }
779  }
780  return max;
781}
782
783static inline unsigned long
784p_GetMaxExpL2(unsigned long l1, unsigned long l2, ring r)
785{
786  return p_GetMaxExpL2(l1, l2, r, r->ExpPerLong);
787}
788
789poly p_GetMaxExpP(poly p, ring r)
790{
791  p_CheckPolyRing(p, r);
792  if (p == NULL) return p_Init(r);
793  poly max = p_LmInit(p, r);
794  pIter(p);
795  if (p == NULL) return max;
796  int i, offset;
797  unsigned long l_p, l_max;
798  unsigned long divmask = r->divmask;
799 
800  do
801  {
802    offset = r->VarL_Offset[0];
803    l_p = p->exp[offset];
804    l_max = max->exp[offset];
805    // do the divisibility trick to find out whether l has an exponent
806    if (l_p > l_max || 
807        (((l_max & divmask) ^ (l_p & divmask)) != ((l_max-l_p) & divmask)))
808      max->exp[offset] = p_GetMaxExpL2(l_max, l_p, r);
809
810    for (i=1; i<r->VarL_Size; i++)
811    {
812      offset = r->VarL_Offset[i];
813      l_p = p->exp[offset];
814      l_max = max->exp[offset];
815      // do the divisibility trick to find out whether l has an exponent
816      if (l_p > l_max || 
817          (((l_max & divmask) ^ (l_p & divmask)) != ((l_max-l_p) & divmask)))
818        max->exp[offset] = p_GetMaxExpL2(l_max, l_p, r);
819    }
820    pIter(p);
821  }
822  while (p != NULL);
823  return max;
824}
825
826unsigned long p_GetMaxExpL(poly p, ring r, unsigned long l_max)
827{
828  unsigned long l_p, divmask = r->divmask;
829  int i;
830 
831  while (p != NULL)
832  {
833    l_p = p->exp[r->VarL_Offset[0]];
834    if (l_p > l_max ||
835        (((l_max & divmask) ^ (l_p & divmask)) != ((l_max-l_p) & divmask)))
836      l_max = p_GetMaxExpL2(l_max, l_p, r);
837    for (i=1; i<r->VarL_Size; i++)
838    {
839      l_p = p->exp[r->VarL_Offset[i]];
840      // do the divisibility trick to find out whether l has an exponent
841      if (l_p > l_max || 
842          (((l_max & divmask) ^ (l_p & divmask)) != ((l_max-l_p) & divmask)))
843        l_max = p_GetMaxExpL2(l_max, l_p, r);
844    }
845    pIter(p);
846  }
847  return l_max;
848}
849
850
851
852   
853/***************************************************************
854 *
855 * Misc things
856 *
857 ***************************************************************/
858// returns TRUE, if all monoms have the same component
859BOOLEAN p_OneComp(poly p, ring r)
860{
861  if(p!=NULL)
862  {
863    long i = p_GetComp(p, r);
864    while (pNext(p)!=NULL)
865    {
866      pIter(p);
867      if(i != p_GetComp(p, r)) return FALSE;
868    }
869  }
870  return TRUE;
871}
872
873/*2
874*test if a monomial /head term is a pure power
875*/
876int p_IsPurePower(const poly p, const ring r)
877{
878  int i,k=0;
879
880  for (i=r->N;i;i--)
881  {
882    if (p_GetExp(p,i, r)!=0)
883    {
884      if(k!=0) return 0;
885      k=i;
886    }
887  }
888  return k;
889}
890
891/*2
892* returns a polynomial representing the integer i
893*/
894poly p_ISet(int i, ring r)
895{
896  poly rc = NULL;
897  if (i!=0)
898  {
899    rc = p_Init(r);
900    pSetCoeff0(rc,r->cf->nInit(i));
901    if (r->cf->nIsZero(p_GetCoeff(rc,r)))
902      p_DeleteLm(&rc,r);
903  }
904  return rc;
905}
906
907/*2
908* returns a polynomial representing the number n
909* destroys n
910*/
911poly p_NSet(number n, ring r)
912{
913  if (r->cf->nIsZero(n))
914  {
915    r->cf->cfDelete(&n, r);
916    return NULL;
917  }
918  else
919  {
920    poly rc = p_Init(r);
921    pSetCoeff0(rc,n);
922    return rc;
923  }
924}
925
926/***************************************************************
927 *
928 * p_ShallowDelete
929 *
930 ***************************************************************/
931#undef LINKAGE
932#define LINKAGE
933#undef p_Delete
934#define p_Delete p_ShallowDelete
935#undef n_Delete
936#define n_Delete(n, r) ((void)0)
937
938#include "p_Delete__T.cc"
939
Note: See TracBrowser for help on using the repository browser.