Changeset f34215 in git for polys


Ignore:
Timestamp:
Nov 8, 2010, 4:57:06 PM (13 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', '5b153614cbc72bfa198d75b1e9e33dab2645d9fe')
Children:
fb4075bf0613cccede0552d05c1b4ee37a7f6530
Parents:
a04c5ec2b888d58e53a0701c12400ddca144d53e
git-author:
Hans Schoenemann <hannes@mathematik.uni-kl.de>2010-11-08 16:57:06+01:00
git-committer:
Mohamed Barakat <mohamed.barakat@rwth-aachen.de>2011-11-09 11:55:35+01:00
Message:
moved some ring-indep. stuff to p_polys
Location:
polys
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • polys/monomials/p_polys.cc

    ra04c5e rf34215  
    11341134}
    11351135
     1136void p_Split(poly p, poly *h)
     1137{
     1138  *h=pNext(p);
     1139  pNext(p)=NULL;
     1140}
     1141
     1142/*2
     1143* pair has no common factor ? or is no polynomial
     1144*/
     1145BOOLEAN p_HasNotCF(poly p1, poly p2, const ring r)
     1146{
     1147
     1148  if (p_GetComp(p1,r) > 0 || p_GetComp(p2,r) > 0)
     1149    return FALSE;
     1150  int i = rVar(r);
     1151  loop
     1152  {
     1153    if ((p_GetExp(p1, i, r) > 0) && (p_GetExp(p2, i, r) > 0))
     1154      return FALSE;
     1155    i--;
     1156    if (i == 0)
     1157      return TRUE;
     1158  }
     1159}
     1160
     1161/*2
     1162* convert monomial given as string to poly, e.g. 1x3y5z
     1163*/
     1164const char * p_Read(const char *st, poly &rc, const ring r)
     1165{
     1166  if (r==NULL) { rc=NULL;return st;}
     1167  int i,j;
     1168  rc = p_Init(r);
     1169  const char *s = r->cf->nRead(st,&(rc->coef));
     1170  if (s==st)
     1171  /* i.e. it does not start with a coeff: test if it is a ringvar*/
     1172  {
     1173    j = r_IsRingVar(s,r);
     1174    if (j >= 0)
     1175    {
     1176      p_IncrExp(rc,1+j,r);
     1177      while (*s!='\0') s++;
     1178      goto done;
     1179    }
     1180  }
     1181  while (*s!='\0')
     1182  {
     1183    char ss[2];
     1184    ss[0] = *s++;
     1185    ss[1] = '\0';
     1186    j = r_IsRingVar(ss,r);
     1187    if (j >= 0)
     1188    {
     1189      const char *s_save=s;
     1190      s = eati(s,&i);
     1191      if (((unsigned long)i) >  r->bitmask)
     1192      {
     1193        // exponent to large: it is not a monomial
     1194        p_LmDelete(&rc,r);
     1195        return s_save;
     1196      }
     1197      p_AddExp(rc,1+j, (long)i, r);
     1198    }
     1199    else
     1200    {
     1201      // 1st char of is not a varname
     1202      p_LmDelete(&rc,r);
     1203      s--;
     1204      return s;
     1205    }
     1206  }
     1207done:
     1208  if (r->cf->nIsZero(pGetCoeff(rc))) p_LmDelete(&rc,r);
     1209  else
     1210  {
     1211#ifdef HAVE_PLURAL
     1212    // in super-commutative ring
     1213    // squares of anti-commutative variables are zeroes!
     1214    if(rIsSCA(r))
     1215    {
     1216      const unsigned int iFirstAltVar = scaFirstAltVar(r);
     1217      const unsigned int iLastAltVar  = scaLastAltVar(r);
     1218
     1219      assume(rc != NULL);
     1220
     1221      for(unsigned int k = iFirstAltVar; k <= iLastAltVar; k++)
     1222        if( p_GetExp(rc, k, r) > 1 )
     1223        {
     1224          p_LmDelete(&rc, r);
     1225          goto finish;
     1226        }
     1227    }
     1228#endif
     1229   
     1230    p_Setm(rc,r);
     1231  }
     1232finish: 
     1233  return s;
     1234}
     1235poly p_mInit(const char *st, BOOLEAN &ok, const ring r)
     1236{
     1237  poly p;
     1238  const char *s=p_Read(st,p,r);
     1239  if (*s!='\0')
     1240  {
     1241    if ((s!=st)&&isdigit(st[0]))
     1242    {
     1243      errorreported=TRUE;
     1244    }
     1245    ok=FALSE;
     1246    p_Delete(&p,r);
     1247    return NULL;
     1248  }
     1249  #ifdef PDEBUG
     1250  _p_Test(p,r,PDEBUG);
     1251  #endif
     1252  ok=!errorreported;
     1253  return p;
     1254}
     1255
    11361256/*2
    11371257* returns a polynomial representing the number n
  • polys/monomials/p_polys.h

    ra04c5e rf34215  
    17511751  return TRUE;
    17521752}
     1753void      p_Split(poly p, poly * r);   /*p => IN(p), r => REST(p) */
     1754BOOLEAN p_HasNotCF(poly p1, poly p2, const ring r);
     1755poly      p_mInit(const char *s, BOOLEAN &ok, const ring r); /* monom s -> poly, interpreter */
     1756const char *    p_Read(const char *s, poly &p,const ring r); /* monom -> poly */
    17531757#endif // P_POLYS_H
    17541758
  • polys/polys.cc

    ra04c5e rf34215  
    5252{
    5353  if (ppNoether!=NULL) pDelete(&ppNoether);
    54   //pVariables = r->N;
    5554  //pOrdSgn = r->OrdSgn;
    5655  //pFDeg=r->pFDeg;
     
    223222}
    224223
    225 /*2
    226 * convert monomial given as string to poly, e.g. 1x3y5z
    227 */
    228 const char * p_Read(const char *st, poly &rc, const ring r)
    229 {
    230   if (r==NULL) { rc=NULL;return st;}
    231   int i,j;
    232   rc = p_Init(r);
    233   const char *s = r->cf->nRead(st,&(rc->coef));
    234   if (s==st)
    235   /* i.e. it does not start with a coeff: test if it is a ringvar*/
    236   {
    237     j = r_IsRingVar(s,r);
    238     if (j >= 0)
    239     {
    240       p_IncrExp(rc,1+j,r);
    241       while (*s!='\0') s++;
    242       goto done;
    243     }
    244   }
    245   while (*s!='\0')
    246   {
    247     char ss[2];
    248     ss[0] = *s++;
    249     ss[1] = '\0';
    250     j = r_IsRingVar(ss,r);
    251     if (j >= 0)
    252     {
    253       const char *s_save=s;
    254       s = eati(s,&i);
    255       if (((unsigned long)i) >  r->bitmask)
    256       {
    257         // exponent to large: it is not a monomial
    258         p_LmDelete(&rc,r);
    259         return s_save;
    260       }
    261       p_AddExp(rc,1+j, (long)i, r);
    262     }
    263     else
    264     {
    265       // 1st char of is not a varname
    266       p_LmDelete(&rc,r);
    267       s--;
    268       return s;
    269     }
    270   }
    271 done:
    272   if (r->cf->nIsZero(pGetCoeff(rc))) p_LmDelete(&rc,r);
    273   else
    274   {
    275 #ifdef HAVE_PLURAL
    276     // in super-commutative ring
    277     // squares of anti-commutative variables are zeroes!
    278     if(rIsSCA(r))
    279     {
    280       const unsigned int iFirstAltVar = scaFirstAltVar(r);
    281       const unsigned int iLastAltVar  = scaLastAltVar(r);
    282 
    283       assume(rc != NULL);
    284 
    285       for(unsigned int k = iFirstAltVar; k <= iLastAltVar; k++)
    286         if( p_GetExp(rc, k, r) > 1 )
    287         {
    288           p_LmDelete(&rc, r);
    289           goto finish;
    290         }
    291     }
    292 #endif
    293     p_Setm(rc,r);
    294   }
    295 finish:
    296   return s;
    297 }
    298 
    299224BOOLEAN _p_Test(poly p, ring r, int level);
    300 poly pmInit(const char *st, BOOLEAN &ok)
    301 {
    302   poly p;
    303   const char *s=p_Read(st,p,currRing);
    304   if (*s!='\0')
    305   {
    306     if ((s!=st)&&isdigit(st[0]))
    307     {
    308       errorreported=TRUE;
    309     }
    310     ok=FALSE;
    311     pDelete(&p);
    312     return NULL;
    313   }
    314   #ifdef PDEBUG
    315   _p_Test(p,currRing,PDEBUG);
    316   #endif
    317   ok=!errorreported;
    318   return p;
    319 }
    320225
    321226/*2
     
    560465}
    561466/*----------end of utilities for syzygies--------------*/
    562 
    563 /*2
    564 * pair has no common factor ? or is no polynomial
    565 */
    566 BOOLEAN pHasNotCF(poly p1, poly p2)
    567 {
    568 
    569   if (pGetComp(p1) > 0 || pGetComp(p2) > 0)
    570     return FALSE;
    571   int i = pVariables;
    572   loop
    573   {
    574     if ((pGetExp(p1, i) > 0) && (pGetExp(p2, i) > 0))   return FALSE;
    575     i--;
    576     if (i == 0)                                         return TRUE;
    577   }
    578 }
    579467
    580468/*2
  • polys/polys.h

    ra04c5e rf34215  
    1111
    1212#include <kernel/p_polys.h>
    13 /*
    14  Some general remarks:
    15  We divide poly operations into roughly 4 categories:
    16  Level 2: operations on monomials/polynomials with constant time,
    17           or operations which are just dispatchers to other
    18           poly routines
    19           - implemented in: pInline2.h
    20           - debugging only if PDEBUG >= 2
    21           - normally inlined, unless PDEBUG >= 2 || NO_INLINE2
    22  Level 1: operations on monomials with time proportional to length
    23           - implemented in: pInline1.h
    24           - debugging only if PDEBUG >= 1
    25           - normally inlined, unless PDEBUG >= 1 || NO_INLINE1
    26  Level 0: short operations on polynomials with time proportional to
    27           length of poly
    28           - implemented in pInline0.cc
    29           - debugging if PDEBUG
    30           - normally _not_ inlined: can be forced with
    31             #define DO_PINLINE0
    32             #include "pInline0.h"
    33  Misc   : operations on polynomials which do not fit in any of the
    34           above categories
    35           - implemented in: polys*.cc
    36           - never inlined
    37           - debugging if PDEBUG >= 0
    38 
    39  You can set PDEBUG on a per-file basis, before including "mod2.h" like
    40    #define PDEBUG 2
    41    #include "mod2.h"
    42  However, PDEBUG will only be in effect, if !NDEBUG.
    43 
    44  All p_* operations take as last argument a ring
    45  and are ring independent. Their corresponding p* operations are usually
    46  just macros to the respective p_*(..,currRing).
    47 
    48 */
    4913
    5014/***************************************************************
     
    213177 *************************************************************************/
    214178// sorts p, assumes all monomials in p are different
    215 #define pSortMerger(p)          pSort(p)
     179#define pSortMerger(p)          p_SortMerge(p, currRing)
    216180#define pSort(p)                p_SortMerge(p, currRing)
    217181
     
    256220
    257221typedef poly*   polyset;
    258 extern int      pVariables;
    259222extern int      pOrdSgn;
    260223extern BOOLEAN  pLexOrder;
     
    263226
    264227/*-------------predicate on polys ----------------------*/
    265 BOOLEAN   pHasNotCF(poly p1, poly p2);   /*has no common factor ?*/
    266 void      pSplit(poly p, poly * r);   /*p => IN(p), r => REST(p) */
     228#define  pHasNotCF(p1,p2)   p_HasNotCF(p1,p2,currRing)
     229                                /*has no common factor ?*/
     230#define  pSplit(p,r)        p_Split(p,r)
     231                                /*p => IN(p), r => REST(p) */
    267232
    268233
     
    270235/*-------------ring management:----------------------*/
    271236extern void pSetGlobals(const ring r, BOOLEAN complete = TRUE);
     237
    272238// resets the pFDeg and pLDeg: if pLDeg is not given, it is
    273239// set to currRing->pLDegOrig, i.e. to the respective LDegProc which
    274240// only uses pFDeg (and not pDeg, or pTotalDegree, etc).
    275241// If you use this, make sure your procs does not make any assumptions
    276 // on oredering and/or OrdIndex -- otherwise they might return wrong results
     242// on ordering and/or OrdIndex -- otherwise they might return wrong results
    277243// on strat->tailRing
    278244extern void pSetDegProcs(pFDegProc new_FDeg, pLDegProc new_lDeg = NULL);
     
    283249#define pSetm(p)    p_Setm(p, currRing)
    284250// TODO:
    285 #define pSetmComp   pSetm
     251#define pSetmComp(p)   p_Setm(p, currRing)
    286252
    287253/***************************************************************
     
    316282
    317283
    318 poly      pmInit(const char *s, BOOLEAN &ok); /* monom s -> poly, interpreter */
    319 const char *    p_Read(const char *s, poly &p,const ring r); /* monom -> poly */
    320 
    321284/*-------------operations on polynomials:------------*/
    322285poly      pSub(poly a, poly b);
    323286poly      p_Power(poly p, int i, const ring r);
     287#define pmInit(a,b) p_mInit(a,b,currRing)
    324288
    325289// ----------------- define to enable new p_procs -----*/
  • polys/polys1.cc

    ra04c5e rf34215  
    446446  return result;
    447447}
    448 
    449 
    450 void pSplit(poly p, poly *h)
    451 {
    452   *h=pNext(p);
    453   pNext(p)=NULL;
    454 }
    455 
    456 
    457448
    458449int pMaxCompProc(poly p)
Note: See TracChangeset for help on using the changeset viewer.