Changeset a6a239 in git for Singular/polys.cc


Ignore:
Timestamp:
Sep 12, 2000, 6:01:23 PM (24 years ago)
Author:
Olaf Bachmann <obachman@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', '38dfc5131670d387a89455159ed1e071997eec94')
Children:
fe7bd4983d0c4322efb17bf36dbf3b28109b9608
Parents:
47e83c37a0601dd5b7dadba83e9c5b04d7efeaf1
Message:
* new implementation of polys


git-svn-id: file:///usr/local/Singular/svn/trunk@4580 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/polys.cc

    r47e83c3 ra6a239  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: polys.cc,v 1.59 2000-09-07 10:02:54 sulandra Exp $ */
     4/* $Id: polys.cc,v 1.60 2000-09-12 16:01:10 obachman Exp $ */
    55
    66/*
     
    2020#include "ring.h"
    2121#include "binom.h"
    22 #include "polys-comp.h"
    2322
    2423/* ----------- global variables, set by pSetGlobals --------------------- */
     
    7877/*-------- the several possibilities for pSetm:-----------------------*/
    7978
    80 void rSetm(poly p)
     79void p_Setm(poly p, ring r)
    8180{
    8281  int pos=0;
    83   if (currRing->typ!=NULL)
     82  if (r->typ!=NULL)
    8483  {
    8584    loop
    8685    {
    87       sro_ord* o=&(currRing->typ[pos]);
     86      sro_ord* o=&(r->typ[pos]);
    8887      switch(o->ord_typ)
    8988      {
     
    9493          e=o->data.dp.end;
    9594          long ord=0; //0x40000000;
    96           for(int i=a;i<=e;i++) ord+=pGetExp(p,i);
    97           p->exp.l[o->data.dp.place]=ord;
     95          for(int i=a;i<=e;i++) ord+=p_GetExp(p,i,r);
     96          p->exp[o->data.dp.place]=ord;
    9897          break;
    9998        }
     
    105104          int *w=o->data.wp.weights;
    106105          long ord=0; //0x40000000;
    107           for(int i=a;i<=e;i++) ord+=pGetExp(p,i)*w[i-a];
    108           p->exp.l[o->data.wp.place]=ord;
     106          for(int i=a;i<=e;i++) ord+=p_GetExp(p,i,r)*w[i-a];
     107          p->exp[o->data.wp.place]=ord;
    109108          break;
    110109        }
     
    115114          e=o->data.cp.end;
    116115          int pl=o->data.cp.place;
    117           #ifdef HAVE_SHIFTED_EXPONENTS
    118           for(int i=a;i<=e;i++) { p->exp.l[pl]=pGetExp(p,i); pl++; }
    119           #else
    120           for(int i=a;i<=e;i++) { p->exp.e[pl]=pGetExp(p,i); pl++; }
    121           #endif
     116          #ifdef HAVE_SHIFTED_EXPONENTS
     117          for(int i=a;i<=e;i++) { p->exp[pl]=p_GetExp(p,i,r); pl++; }
     118          #else
     119          for(int i=a;i<=e;i++) { p->exp.e[pl]=p_GetExp(p,i,r); pl++; }
     120          #endif
    122121          break;
    123122        }
    124123        case ro_syzcomp:
    125124        {
    126           int c=pGetComp(p);
     125          int c=p_GetComp(p,r);
    127126          long sc = c;
    128127          if (o->data.syzcomp.ShiftedComponents != NULL)
     
    134133            assume(c == 0 || sc != 0);
    135134          }
    136           p->exp.l[o->data.syzcomp.place]=sc;
     135          p->exp[o->data.syzcomp.place]=sc;
    137136          break;
    138137        }
     
    141140          int c=pGetComp(p);
    142141          if (c > o->data.syz.limit)
    143             p->exp.l[o->data.syz.place] = o->data.syz.curr_index;
     142            p->exp[o->data.syz.place] = o->data.syz.curr_index;
    144143          else if (c > 0)
    145             p->exp.l[o->data.syz.place]= o->data.syz.syz_index[c];
     144            p->exp[o->data.syz.place]= o->data.syz.syz_index[c];
    146145          else
    147146          {
    148147            assume(c == 0);
    149             p->exp.l[o->data.syz.place]= 0;
     148            p->exp[o->data.syz.place]= 0;
    150149          }
    151150          break;
     
    179178          long ord=0;
    180179          for(int i=a;i<=e;i++) ord+=pGetExp(p,i);
    181           p->exp.l[o->data.dp.place]=ord;
     180          p->exp[o->data.dp.place]=ord;
    182181          break;
    183182        }
     
    190189          long ord=0;
    191190          for(int i=a;i<=e;i++) ord+=pGetExp(p,i)*w[i-a];
    192           p->exp.l[o->data.wp.place]=ord;
     191          p->exp[o->data.wp.place]=ord;
    193192          break;
    194193        }
     
    200199          int pl=o->data.cp.place;
    201200          #ifdef HAVE_SHIFTED_EXPONENTS
    202           for(int i=a;i<=e;i++) { p->exp.l[pl]=pGetExp(p,i); pl++; }
     201          for(int i=a;i<=e;i++) { p->exp[pl]=pGetExp(p,i); pl++; }
    203202          #else
    204203          for(int i=a;i<=e;i++) { p->exp.e[pl]=pGetExp(p,i); pl++; }
     
    208207        case ro_syzcomp:
    209208        {
    210 #if 1
    211209          int c=pGetComp(p);
    212210          long sc  = ShiftedComponents[Components[c]];
    213211          assume(c == 0 || Components[c] != 0);
    214212          assume(c == 0 || sc != 0);
    215           p->exp.l[o->data.syzcomp.place]=sc;
    216 #endif
     213          p->exp[o->data.syzcomp.place]=sc;
    217214          break;
    218215        }
     
    249246
    250247
    251 /*---------------------------------------------------*/
    252 
    253 int pComp(poly p1, poly p2)
    254 {
    255   if (p2==NULL)
    256     return 1;
    257   if (p1==NULL)
    258     return -1;
    259   return pComp0(p1,p2);
    260 }
    261248
    262249
     
    293280
    294281  //if (CompP1==CompP2) return pCompOld(p1,p2);
    295   if (CompP1==CompP2) return pComp0(p1,p2);
     282  if (CompP1==CompP2) return pLmCmp(p1,p2);
    296283  pSetComp(p1,cP1);
    297284  pSetComp(p2,cP2);
    298285  //result = pCompOld(p1,p2);
    299   result = pComp0(p1,p2);
     286  result = pLmCmp(p1,p2);
    300287  pSetComp(p1,CompP1);
    301288  pSetComp(p2,CompP2);
     
    382369      for (i=indexShift;i<maxSchreyer;i++)
    383370        SchreyerOrd[i] = pGetComp(nextOrder[i-indexShift]);
    384       //pCompOld = pComp0;
    385       //pComp0 = mcompSchrM;
     371      //pCompOld = pLmCmp;
     372      //pLmCmp = mcompSchrM;
    386373      pLDegOld = pLDeg;
    387374      pLDeg = ldegSchrM;
     
    395382      maxSchreyer = 0;
    396383      indexShift = 0;
    397       //pComp0 = pCompOld;
     384      //pLmCmp = pCompOld;
    398385      pLDeg = pLDegOld;
    399386    }
     
    428415int pTotaldegree(poly p)
    429416{
    430   return pExpQuerSum(p);
     417  return (int) pExpVectorQuerSum(p);
    431418}
    432419
     
    801788      test &= ~Sy_bit(OPT_REDTAIL); /* noredTail */
    802789    }
    803     pSetm=rSetm;
    804790  }
    805791  if (pFDeg!=pWTotaldegree) pFDeg=pTotaldegree;
    806 }
    807 
    808 
    809 static Exponent_t pMultT_nok = 0;
    810 
    811 #ifndef HAVE_P_PROCS
    812 /* -------------------------------------------------------- */
    813 /*2
    814 * update the polynomial a by multipying it by
    815 * the (number) coefficient
    816 * and the exponent vector (of) exp (a well initialized polynomial)
    817 */
    818 poly pMultT(poly a, poly exp )
    819 {
    820   int i;
    821   number t,x,y=pGetCoeff(exp);
    822   poly aa=a;
    823   poly prev=NULL;
    824 
    825   pMultT_nok = pGetComp(exp);
    826 #ifdef PDEBUG
    827   pTest(a);
    828   pTest(exp);
    829 #endif
    830   while (a !=NULL)
    831   {
    832     x=pGetCoeff(a);
    833     t=nMult(x/*pGetCoeff(a)*/,y/*pGetCoeff(exp)*/);
    834     nDelete(&x/*pGetCoeff(a)*/);
    835     pSetCoeff0(a,t);
    836     if (nIsZero(t))
    837     {
    838       if (prev==NULL) { pDelete1(&a); aa=a; }
    839       else            { pDelete1(&prev->next); a=prev->next;}
    840     }
    841     else
    842     {
    843       {
    844         if (pMultT_nok)  /* comp of exp != 0 */
    845         {
    846           if (pGetComp(a) != 0)
    847           {
    848             return NULL /*FALSE*/;
    849           }
    850         }
    851         pMonAddOn(a,exp);
    852       }
    853       prev=a;
    854       pIter(a);
    855     }
    856   }
    857   pMultT_nok=0;
    858   pTest(aa);
    859   return aa; /*TRUE*/
    860 }
    861 
    862 
    863 /*2
    864 * update a by multiplying it with c (c will not be destroyed)
    865 */
    866 void pMultN(poly a, number c)
    867 {
    868   number t;
    869 
    870   while (a!=NULL)
    871   {
    872     t=nMult(pGetCoeff(a), c);
    873     //nNormalize(t);
    874     pSetCoeff(a,t);
    875     pIter(a);
    876   }
    877 }
    878 
    879 /*2
    880 * return a copy of the poly a times the number c (a,c will not be destroyed)
    881 */
    882 poly pMultCopyN(poly a, number c)
    883 {
    884   poly result=NULL,hp;
    885 
    886   if (a != NULL)
    887   {
    888     result=pNew();
    889     pCopy2(result,a);
    890     pNext(result)=NULL;
    891     pGetCoeff(result)=nMult(pGetCoeff(a),c);
    892     pIter(a);
    893     hp=result;
    894     while (a!=NULL)
    895     {
    896       hp=pNext(hp)=pNew();
    897       pCopy2(hp,a);
    898       pSetCoeff0(hp,nMult(pGetCoeff(a), c));
    899       pIter(a);
    900     }
    901     pNext(hp)=NULL;
    902   }
    903   return result;
    904 }
    905 
    906 /*2
    907 * multiply p1 with p2, p1 and p2 are destroyed
    908 * do not put attention on speed: the procedure is only used in the interpreter
    909 */
    910 
    911 #endif
    912 
    913 #ifdef HAVE_P_PROCS
    914 poly pMult_Old(poly p1, poly p2)
    915 #else
    916 poly pMult(poly p1, poly p2)
    917 #endif
    918 {
    919   poly res, r, rn, a;
    920   BOOLEAN cont;
    921 
    922   if ((p1!=NULL) && (p2!=NULL))
    923   {
    924 #ifdef PDEBUG
    925     pTest(p1);
    926     pTest(p2);
    927 #endif
    928     cont = TRUE;
    929     a = p1;
    930     if (pNext(p2)!=NULL)
    931       a = pCopy(a);
    932     else
    933       cont = FALSE;
    934     res = pMultT(a, p2);
    935     if (pMultT_nok)
    936     {
    937       if (cont) pDelete(&p1);
    938       pDelete(&res);
    939       pDelete(&p2);
    940       return NULL;
    941     }
    942     pTest(res);
    943     pDelete1(&p2);
    944     r = res;
    945     if (r!=NULL) rn = pNext(r);
    946     else         rn=NULL;
    947     while (cont)
    948     {
    949       if (pNext(p2)==NULL)
    950       {
    951         a = p1;
    952         cont = FALSE;
    953       }
    954       else
    955       {
    956         a = pCopy(p1);
    957       }
    958       a=pMultT(a, p2); //sets pMultT_nok
    959       pTest(a);
    960       if (pMultT_nok)
    961       {
    962         if (cont) pDelete(&p1);
    963         pDelete(&a);
    964         pDelete(&res);
    965         pDelete(&p2);
    966         return NULL;
    967       }
    968       while ((rn!=NULL) && (pComp0(rn,a)>0))
    969       {
    970         r = rn;
    971         pIter(rn);
    972       }
    973       if (r!=NULL) pNext(r) = rn = pAdd(a, rn);
    974       else         res=r=a;
    975       pDelete1(&p2);
    976     }
    977     pTest(res);
    978     return res;
    979   }
    980   pDelete(&p1);
    981   pDelete(&p2);
    982   return NULL;
    983792}
    984793
     
    991800{
    992801  int i;
    993   poly result=pInit();
     802  poly result = pInit();
    994803
    995804  for(i=(int)pVariables; i; i--)
     
    1037846    }
    1038847  }
    1039   pMultN(result,inv);
     848  pMult_nn(result,inv);
    1040849  nDelete(&inv);
    1041850  pDelete(&b);
     
    1176985    {
    1177986      nPower(n,i,&nn);
    1178       pMultN(P[i],nn);
     987      pMult_nn(P[i],nn);
    1179988      p = pAdd(p,P[i]);
    1180989      //P[i] =NULL; // for safety, may be removed later
Note: See TracChangeset for help on using the changeset viewer.