Changeset ad1c3b in git for kernel/shiftgb.cc


Ignore:
Timestamp:
Mar 13, 2008, 8:25:49 PM (15 years ago)
Author:
Viktor Levandovskyy <levandov@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
Children:
ba49d9f52b36950f74de618b1a41a677fa14fa07
Parents:
411ea98eecab97fbeac7f8395433a159d6d03584
Message:
*levandov: shift GB nonhomog case


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

Legend:

Unmodified
Added
Removed
  • kernel/shiftgb.cc

    r411ea98 rad1c3b  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: shiftgb.cc,v 1.6 2008-02-24 17:41:32 levandov Exp $ */
     4/* $Id: shiftgb.cc,v 1.7 2008-03-13 19:25:49 levandov Exp $ */
    55/*
    66* ABSTRACT: kernel: utils for shift GB and free GB
     
    4141
    4242/* TODO: write p* stuff as instances of p_* for all the functions */
     43/* p_* functions are new, p* are old */
    4344
    4445poly p_LPshiftT(poly p, int sh, int uptodeg, int lV, kStrategy strat, const ring r)
     
    5253  assume(p_CheckIsFromRing(pNext(p),strat->tailRing));
    5354
    54   /* assume sh and uptodeg agree */
     55  /* assume sh and uptodeg agree  TODO check */
    5556
    5657  if (sh == 0) return(p); /* the zero shift */
     
    7475{
    7576  /* assume shift takes place */
    76   /* shifts the poly p by sh */
    77   /* deletes p */
    78 
    79   /* assume sh and uptodeg agree */
     77  /* shifts the poly p from the ring r by sh */
     78
     79  /* assume sh and uptodeg agree TODO check */
    8080
    8181  if (p==NULL) return(p);
     
    8383
    8484  poly q  = NULL;
    85   poly pp = p; // pCopy(p);
     85  poly pp = p; // do not take copies
    8686  while (pp!=NULL)
    8787  {
     
    8989    pIter(pp);
    9090  }
    91   /* delete pp? */
    92   /* int version: returns TRUE if it was successful */
    9391  return(q);
    9492}
     
    9694poly p_mLPshift(poly p, int sh, int uptodeg, int lV, const ring r)
    9795{
    98   /* pm is a monomial */
     96  /* p is a monomial from the ring r */
    9997
    10098  if (sh == 0) return(p); /* the zero shift */
     
    119117  int *s=(int *)omAlloc0((r->N+1)*sizeof(int));
    120118  p_GetExpV(p,e,r);
    121   number c = pGetCoeff(p);
     119
    122120  int j;
    123121  //  for (j=1; j<=r->N; j++)
     
    128126    {
    129127      s[j + (sh*lV)] = e[j]; /* actually 1 */
     128#ifdef PDEBUG
    130129      omCheckAddr(s);
     130#endif
    131131    }
     132#ifdef PDEBUG
    132133    else
    133134    {
    134135      if (e[j]!=0)
    135136      {
    136 #ifdef PDEBUG
    137          Print("p_mLPshift: ex[%d]=%d\n",j,e[j]);
    138 #endif
     137        //         Print("p_mLPshift: ex[%d]=%d\n",j,e[j]);
    139138      }
    140139    }
     140#endif
    141141  }
    142142  poly m = p_ISet(1,r);
    143143  p_SetExpV(m,s,r);
    144   /*  pSetm(m); */ /* done in the pSetExpV */
    145   /* think on the component */
    146   pSetCoeff0(m,c);
    147144  freeT(e, r->N);
    148145  freeT(s, r->N);
     146  /*  pSetm(m); */ /* done in the pSetExpV */
     147  /* think on the component and coefficient */
     148  //  number c = pGetCoeff(p);
     149  //  p_SetCoeff0(m,p_GetCoeff(p,r),r);
     150  p_SetComp(m,p_GetComp(p,r),r); // component is preserved
     151  p_SetCoeff0(m,p_GetCoeff(p,r),r);  // coeff is preserved
    149152  return(m);
    150153}
     
    202205  for (j=1; j<=currRing->N; j++)
    203206  {
    204     if (e[j])
     207    if (e[j]==1)
    205208    {
    206209      s[j + (sh*lV)] = e[j]; /* actually 1 */
     
    371374
    372375  /* there should be two routines: */
    373   /* 1. tests squarefreeness: in homog this suffices */
     376  /* 1. test place-squarefreeness: in homog this suffices: isInV */
    374377  /* 2. test the presence of a hole -> in the tail??? */
    375378
    376379int isInV(poly p, int lV)
    377380{
    378 
     381  /* investigate only the leading monomial of p in currRing */
    379382  if (lV <= 0) return(0);
    380383  /* returns 1 iff p is in V */
     
    382385  /* lV = the length of V = the number of orig vars */
    383386  int *e = (int *)omAlloc0((currRing->N+1)*sizeof(int));
    384   int  b = (int)(currRing->N)/lV; /* the number of blocks */
     387  int  b = (int)((currRing->N +lV-1)/lV); /* the number of blocks */
     388  //int b  = (int)(currRing->N)/lV;
    385389  int *B = (int *)omAlloc0((b+1)*sizeof(int)); /* the num of elements in a block */
    386390  pGetExpV(p,e);
     
    395399    }
    396400  }
    397   j = b;
     401  //  j = b;
    398402  //  while ( (!B[j]) && (j>=1)) j--;
    399403  for (j=b; j>=1; j--)
     
    401405    if (B[j]!=0) break;
    402406  }
    403 
    404   if (j==0)
    405   {
    406     /* it is a zero exp vector, which is in V */
    407     return(1);
    408   }
    409   /* now B[j] != 0 */
     407  /* do not need e anymore */
     408  freeT(e, currRing->N);
     409
     410  if (j==0) goto ret_true;
     411//   {
     412//     /* it is a zero exp vector, which is in V */
     413//     freeT(B, b);
     414//     return(1);
     415//   }
     416  /* now B[j] != 0 and we test place-squarefreeness */
    410417  for (j; j>=1; j--)
    411418  {
    412419    if (B[j]!=1)
    413420    {
     421      freeT(B, b);
    414422      return(0);
    415423    }
    416424  }
     425 ret_true:
     426  freeT(B, b);
    417427  return(1);
    418428}
     
    421431{
    422432  /* for poly in lmCR/tailTR presentation */
    423   /* the below situation might happen! */
     433  /* the below situation (commented out) might happen! */
    424434//   if (r == currRing)
    425435//   {
     
    439449}
    440450
     451poly p_ShrinkT(poly p, int lV, kStrategy strat, const ring r)
     452//poly p_Shrink(poly p, int uptodeg, int lV, kStrategy strat, const ring r)
     453{
     454  /* p is like TObject: lm in currRing = r, tail in tailRing  */
     455  /* proc shrinks the poly p in ring r */
     456  /* lV = the length of V = the number of orig vars */
     457  /* check assumes/exceptions */
     458  /* r->N is a multiple of lV */
     459
     460  if (p==NULL) return(p);
     461
     462  assume(p_LmCheckIsFromRing(p,r));
     463  assume(p_CheckIsFromRing(pNext(p),strat->tailRing));
     464
     465  poly q   = NULL;
     466  poly s   = p_mShrink(p, lV, r); // lm in currRing
     467  poly pp = pNext(p);
     468 
     469  while (pp != NULL)
     470  {
     471    //    q = p_Add_q(q, p_mShrink(pp,uptodeg,lV,strat->tailRing),strat->tailRing);
     472    q = p_Add_q(q, p_mShrink(pp,lV,strat->tailRing),strat->tailRing);
     473    pIter(pp);
     474  }
     475  pNext(s) = q;
     476  return(s);
     477}
     478
     479poly p_Shrink(poly p, int lV, const ring r)
     480{
     481  /* proc shrinks the poly p in ring r */
     482  /* lV = the length of V = the number of orig vars */
     483  /* check assumes/exceptions */
     484  /* r->N is a multiple of lV */
     485
     486  if (p==NULL) return(p);
     487  assume(p_CheckIsFromRing(p,r));
     488  poly q = NULL;
     489  poly pp = p;
     490 
     491  while (pp != NULL)
     492  {
     493    q = p_Add_q(q, p_mShrink(pp,lV,r),r);
     494    pIter(pp);
     495  }
     496  return(q);
     497}
     498
     499poly p_mShrink(poly p, int lV, const ring r)
     500{
     501  /* shrinks the monomial p in ring r */
     502  /* lV = the length of V = the number of orig vars */
     503
     504  /* check assumes/exceptions */
     505  /* r->N is a multiple of lV */
     506
     507  int *e = (int *)omAlloc0((r->N+1)*sizeof(int));
     508  int  b = (int)((r->N +lV-1)/lV); /* the number of blocks */
     509  //  int *B = (int *)omAlloc0((b+1)*sizeof(int)); /* the num of elements in a block */
     510  int *S = (int *)omAlloc0((r->N+1)*sizeof(int)); /* the shrinked exponent */
     511  p_GetExpV(p,e,r);
     512  int i,j; int cnt = 1; //counter for blocks in S
     513  for (j=1; j<=b; j++)
     514  {
     515    /* we go through all the vars */
     516    /* by blocks in lV vars */
     517    for (i=(j-1)*lV + 1; i<= j*lV; i++)
     518    {
     519      if (e[i]==1)
     520      {
     521        //      B[j] = B[j]+1; // for control in V?
     522         S[(cnt-1)*lV + (i - (j-1)*lV)] = e[i];
     523         /* assuming we are in V, can interrupt here */
     524         cnt++;
     525         //  break; //results in incomplete shrink!
     526         i = j*lV; // manual break under assumption p is in V
     527      }
     528    }
     529  }
     530#ifdef PDEBUG
     531  //  Print("p_mShrink: cnt = [%d], b = %d\n",cnt,b);
     532#endif
     533  // cnt -1 <= b  must hold!
     534  //  freeT(B, b);
     535  poly s = p_ISet(1,r);
     536  p_SetExpV(s,S,r);
     537  freeT(e, r->N);
     538  freeT(S, r->N);
     539  /*  p_Setm(s,r); // done by p_SetExpV */
     540  p_SetComp(s,p_GetComp(p,r),r); // component is preserved
     541  p_SetCoeff(s,p_GetCoeff(p,r),r);  // coeff is preserved
     542#ifdef PDEBUG
     543  //  Print("p_mShrink: from "); p_wrp(p,r); Print(" to "); p_wrp(s,r); PrintLn();
     544#endif
     545  return(s);
     546}
    441547
    442548/* shiftgb stuff */
Note: See TracChangeset for help on using the changeset viewer.