Changeset 7723d00 in git


Ignore:
Timestamp:
Feb 4, 2015, 12:36:21 PM (9 years ago)
Author:
Yue Ren <ren@…>
Branches:
(u'spielwiese', '8e0ad00ce244dfd0756200662572aef8402f13d5')
Children:
08b7c2ac6141d36536d3eb58dd62e9ad4be529da
Parents:
f16226e1d8662eca29be06420a230cd92d756ff3
git-author:
Yue Ren <ren@mathematik.uni-kl.de>2015-02-04 12:36:21+01:00
git-committer:
Yue Ren <ren@mathematik.uni-kl.de>2015-02-06 13:47:06+01:00
Message:
chg: elimnated redundant witness computations
Location:
Singular/dyn_modules/gfanlib
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • Singular/dyn_modules/gfanlib/groebnerCone.cc

    rf16226 r7723d00  
    9898  /* check whether facet normal points outwards */
    9999  gfan::ZCone dual = polyhedralCone.dualCone();
    100   if(dual.contains(facetNormal))
     100  if(dual.containsRelatively(facetNormal))
    101101  {
    102102    std::cout << "ERROR: facetNormal is not pointing outwards!" << std::endl
     
    126126{
    127127  assume(checkPolynomialInput(I,r));
    128   if (I) polynomialIdeal = id_Copy(I,r);
    129128  if (r) polynomialRing = rCopy(r);
    130   ideal redI = id_Copy(polynomialIdeal,polynomialRing);
    131   currentCase.pReduce(redI,polynomialRing);
    132   currentCase.reduce(redI,polynomialRing);
     129  if (I)
     130  {
     131    polynomialIdeal = id_Copy(I,r);
     132    currentCase.pReduce(polynomialIdeal,polynomialRing);
     133    currentCase.reduce(polynomialIdeal,polynomialRing);
     134  }
    133135
    134136  int n = rVar(polynomialRing);
     
    139141  gfan::ZVector tailexpw = gfan::ZVector(n);
    140142  gfan::ZMatrix inequalities = gfan::ZMatrix(0,n);
    141   for (int i=0; i<idSize(redI); i++)
    142   {
    143     g = redI->m[i];
     143  for (int i=0; i<idSize(polynomialIdeal); i++)
     144  {
     145    g = polynomialIdeal->m[i];
    144146    if (g)
    145147    {
     
    169171  interiorPoint = polyhedralCone.getRelativeInteriorPoint();
    170172  assume(checkOrderingAndCone(polynomialRing,polyhedralCone));
    171   id_Delete(&redI,polynomialRing);
    172173}
    173174
     
    178179{
    179180  assume(checkPolynomialInput(I,r));
    180   if (I) polynomialIdeal = id_Copy(I,r);
    181181  if (r) polynomialRing = rCopy(r);
    182   ideal redI = id_Copy(polynomialIdeal,polynomialRing);
    183   currentCase.pReduce(redI,polynomialRing);
    184   currentCase.reduce(redI,polynomialRing);
     182  if (I)
     183  {
     184    polynomialIdeal = id_Copy(I,r);
     185    currentCase.pReduce(polynomialIdeal,polynomialRing);
     186    currentCase.reduce(polynomialIdeal,polynomialRing);
     187  }
    185188
    186189  int n = rVar(polynomialRing);
     
    188191  gfan::ZMatrix equations = gfan::ZMatrix(0,n);
    189192  int* expv = (int*) omAlloc((n+1)*sizeof(int));
    190   for (int i=0; i<idSize(redI); i++)
    191   {
    192     poly g = redI->m[i];
     193  for (int i=0; i<idSize(polynomialIdeal); i++)
     194  {
     195    poly g = polynomialIdeal->m[i];
    193196    if (g)
    194197    {
     
    222225  interiorPoint = polyhedralCone.getRelativeInteriorPoint();
    223226  assume(checkOrderingAndCone(polynomialRing,polyhedralCone));
    224   id_Delete(&redI,polynomialRing);
    225227}
    226228
     
    235237{
    236238  assume(checkPolynomialInput(I,r));
    237   if (I) polynomialIdeal = id_Copy(I,r);
    238239  if (r) polynomialRing = rCopy(r);
    239   ideal redI = id_Copy(polynomialIdeal,polynomialRing);
    240   currentCase.pReduce(redI,polynomialRing);
    241   currentCase.reduce(redI,polynomialRing);
     240  if (I)
     241  {
     242    polynomialIdeal = id_Copy(I,r);
     243    currentCase.pReduce(polynomialIdeal,polynomialRing);
     244    currentCase.reduce(polynomialIdeal,polynomialRing);
     245  }
    242246
    243247  int n = rVar(polynomialRing);
     
    245249  gfan::ZMatrix equations = gfan::ZMatrix(0,n);
    246250  int* expv = (int*) omAlloc((n+1)*sizeof(int));
    247   for (int i=0; i<idSize(redI); i++)
    248   {
    249     poly g = redI->m[i];
     251  for (int i=0; i<idSize(polynomialIdeal); i++)
     252  {
     253    poly g = polynomialIdeal->m[i];
    250254    if (g)
    251255    {
     
    280284  interiorPoint = polyhedralCone.getRelativeInteriorPoint();
    281285  assume(checkOrderingAndCone(polynomialRing,polyhedralCone));
    282   id_Delete(&redI,polynomialRing);
    283286}
    284287
     
    292295  assume(checkPolynomialInput(inI,r));
    293296
    294   ideal redI = id_Copy(polynomialIdeal,polynomialRing);
    295   currentCase.pReduce(redI,polynomialRing);
    296   currentCase.reduce(redI,polynomialRing);
     297  currentCase.pReduce(polynomialIdeal,polynomialRing);
     298  currentCase.reduce(polynomialIdeal,polynomialRing);
    297299
    298300  int n = rVar(r);
     
    315317  }
    316318  gfan::ZMatrix inequalities = gfan::ZMatrix(0,n);
    317   for (int i=0; i<idSize(redI); i++)
    318   {
    319     poly g = redI->m[i];
     319  for (int i=0; i<idSize(polynomialIdeal); i++)
     320  {
     321    poly g = polynomialIdeal->m[i];
    320322    if (g)
    321323    {
     
    342344  interiorPoint = polyhedralCone.getRelativeInteriorPoint();
    343345  assume(checkOrderingAndCone(polynomialRing,polyhedralCone));
    344   id_Delete(&redI,polynomialRing);
    345346}
    346347
     
    558559    gfan::ZFan* zf = new gfan::ZFan(sigma->getPolyhedralCone().ambientDimension());
    559560    for (; sigma!=setOfCones.end(); sigma++)
    560       zf->insert(sigma->getPolyhedralCone());
     561    {
     562      gfan::ZCone zc = sigma->getPolyhedralCone();
     563      assume(isCompatible(zf,&zc));
     564      zf->insert(zc);
     565    }
    561566    return zf;
    562567  }
  • Singular/dyn_modules/gfanlib/initial.cc

    rf16226 r7723d00  
    4141    {
    4242      p_Delete(&q0,r);
    43       q0 = p_Head(p,r);
     43      q0 = p_Head(currentTerm,r);
    4444      q1 = q0;
    4545      d = e;
  • Singular/dyn_modules/gfanlib/ppinitialReduction.h

    rf16226 r7723d00  
    1111void pReduce(ideal &I, const number p, const ring r);
    1212bool ppreduceInitially(ideal I, const ring r, const number p);
    13 BOOLEAN ppreduceInitially(leftv res, leftv args);
     13/* BOOLEAN ppreduceInitially(leftv res, leftv args); */
    1414
    1515#ifndef NDEBUG
  • Singular/dyn_modules/gfanlib/tropical.cc

    rf16226 r7723d00  
    6767
    6868
     69gfan::ZCone groebnerCone(const ideal I, const ring r, const gfan::ZVector &w)
     70{
     71  int n = rVar(r);
     72  poly g = NULL;
     73  int* leadexpv = (int*) omAlloc((n+1)*sizeof(int));
     74  int* tailexpv = (int*) omAlloc((n+1)*sizeof(int));
     75  gfan::ZVector leadexpw = gfan::ZVector(n);
     76  gfan::ZVector tailexpw = gfan::ZVector(n);
     77
     78  gfan::ZMatrix inequalities = gfan::ZMatrix(0,n);
     79  for (int i=0; i<idSize(I); i++)
     80  {
     81    g = (poly) I->m[i];
     82    if (g!=NULL)
     83    {
     84      p_GetExpV(g,leadexpv,currRing);
     85      leadexpw = intStar2ZVector(n, leadexpv);
     86      pIter(g);
     87      while (g!=NULL)
     88      {
     89        pGetExpV(g,tailexpv);
     90        tailexpw = intStar2ZVector(n, tailexpv);
     91        inequalities.appendRow(leadexpw-tailexpw);
     92        pIter(g);
     93      }
     94    }
     95  }
     96
     97  ideal inI = initial(I,currRing,w);
     98  gfan::ZMatrix equations = gfan::ZMatrix(0,n);
     99  for (int i=0; i<idSize(I); i++)
     100  {
     101    g = (poly) inI->m[i];
     102    if (g!=NULL)
     103    {
     104      p_GetExpV(g,leadexpv,currRing);
     105      leadexpw = intStar2ZVector(n, leadexpv);
     106      pIter(g);
     107      while (g!=NULL)
     108      {
     109        pGetExpV(g,tailexpv);
     110        tailexpw = intStar2ZVector(n, tailexpv);
     111        equations.appendRow(leadexpw-tailexpw);
     112        pIter(g);
     113      }
     114    }
     115  }
     116
     117  omFreeSize(leadexpv,(n+1)*sizeof(int));
     118  omFreeSize(tailexpv,(n+1)*sizeof(int));
     119  id_Delete(&inI,currRing);
     120  return gfan::ZCone(inequalities,equations);
     121}
     122
     123
    69124BOOLEAN groebnerCone(leftv res, leftv args)
    70125{
     
    73128  {
    74129    leftv v = u->next;
    75     if (v == NULL)
    76     {
    77       int n = currRing->N;
     130    if ((v !=NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD)))
     131    {
    78132      ideal I = (ideal) u->Data();
    79       poly g = NULL;
    80       int* leadexpv = (int*) omAlloc((n+1)*sizeof(int));
    81       int* tailexpv = (int*) omAlloc((n+1)*sizeof(int));
    82       gfan::ZVector leadexpw = gfan::ZVector(n);
    83       gfan::ZVector tailexpw = gfan::ZVector(n);
    84       gfan::ZMatrix inequalities = gfan::ZMatrix(0,n);
    85       gfan::ZMatrix equations = gfan::ZMatrix(0,n);
    86       long d;
    87       for (int i=0; i<IDELEMS(I); i++)
    88       {
    89         g = (poly) I->m[i]; pGetExpV(g,leadexpv);
    90         leadexpw = intStar2ZVector(n, leadexpv);
    91         pIter(g);
    92         d = p_Deg(g,currRing);
    93         while ((g != NULL) && (p_Deg(g,currRing) == d))
    94         {
    95           pGetExpV(g,tailexpv);
    96           tailexpw = intStar2ZVector(n, tailexpv);
    97           equations.appendRow(leadexpw-tailexpw);
    98           pIter(g);
    99         }
    100 
    101         if (g != NULL)
    102         {
    103           while (g != NULL)
    104           {
    105             pGetExpV(g,tailexpv);
    106             tailexpw = intStar2ZVector(n, tailexpv);
    107             inequalities.appendRow(leadexpw-tailexpw);
    108             pIter(g);
    109           }
    110         }
    111       }
    112       gfan::ZCone* gCone = new gfan::ZCone(inequalities,equations);
    113       omFreeSize(leadexpv,(n+1)*sizeof(int));
    114       omFreeSize(tailexpv,(n+1)*sizeof(int));
    115 
     133      gfan::ZVector* weightVector;
     134      if (v->Typ() == INTVEC_CMD)
     135      {
     136        intvec* w0 = (intvec*) v->Data();
     137        bigintmat* w1 = iv2bim(w0,coeffs_BIGINT);
     138        w1->inpTranspose();
     139        weightVector = bigintmatToZVector(*w1);
     140        delete w1;
     141      }
     142      else
     143      {
     144        bigintmat* w1 = (bigintmat*) v->Data();
     145        weightVector = bigintmatToZVector(*w1);
     146      }
    116147      res->rtyp = coneID;
    117       res->data = (void*) gCone;
     148      res->data = (void*) new gfan::ZCone(groebnerCone(I,currRing,*weightVector));
     149      delete weightVector;
    118150      return FALSE;
    119151    }
     
    124156
    125157
    126 gfan::ZCone* maximalGroebnerCone(const ring &r, const ideal &I)
     158gfan::ZCone maximalGroebnerCone(const ideal &I, const ring &r)
    127159{
    128160  int n = rVar(r);
     
    148180  omFreeSize(leadexpv,(n+1)*sizeof(int));
    149181  omFreeSize(tailexpv,(n+1)*sizeof(int));
    150   return new gfan::ZCone(inequalities,gfan::ZMatrix(0, inequalities.getWidth()));
     182  return gfan::ZCone(inequalities,gfan::ZMatrix(0, inequalities.getWidth()));
    151183}
    152184
     
    162194      ideal I = (ideal) u->Data();
    163195      res->rtyp = coneID;
    164       res->data = (void*) maximalGroebnerCone(currRing, I);
     196      res->data = (void*) new gfan::ZCone(maximalGroebnerCone(I,currRing));
    165197      return FALSE;
    166198    }
     
    277309  // p->iiAddCproc("","ppreduceInitially",FALSE,ppreduceInitially);
    278310  // p->iiAddCproc("","ttreduceInitially",FALSE,ttreduceInitially);
    279   p->iiAddCproc("","homogeneitySpace",FALSE,homogeneitySpace);
    280 }
     311}
  • Singular/dyn_modules/gfanlib/tropicalCurves.cc

    rf16226 r7723d00  
    150150
    151151    poly mons = currentStrategy->checkInitialIdealForMonomial(ininIs,s,w);
    152     if (mons)
    153     {
    154       // std::cout << "computing witness in tropical star!" << std::endl;
    155       poly gs = witness(mons,inIsSTD,ininIs,s);
     152    if (mons!=NULL)
     153    {
     154      poly gs;
     155      if (pNext(mons)==NULL)
     156        gs = witness(mons,inIsSTD,ininIs,s);
     157      else
     158        gs = p_Copy(mons,s);
    156159      C = intersect(C,tropicalVarietySortedByDimension(gs,s,currentStrategy),d);
    157160      nMapFunc mMap = n_SetMap(s->cf,r->cf);
     
    190193
    191194        mons = currentStrategy->checkInitialIdealForMonomial(ininIs,s,wNeg);
    192         if (mons)
    193         {
    194           poly gs = witness(mons,inIsSTD,ininIs,s);
     195        if (mons!=NULL)
     196        {
     197          poly gs;
     198          if (pNext(mons)==NULL)
     199            gs = witness(mons,inIsSTD,ininIs,s);
     200          else
     201            gs = p_Copy(mons,s);
    195202          C = intersect(C,tropicalVarietySortedByDimension(gs,s,currentStrategy),d);
    196203          nMapFunc mMap = n_SetMap(s->cf,r->cf);
     
    231238    for (ZConesSortedByDimension::iterator zc=C.begin(); zc!=C.end(); zc++)
    232239    {
    233       assume(zc->dimensionOfLinealitySpace()+1 == zc->dimension());
    234       gfan::ZMatrix ray = zc->extremeRays();
    235       raysOfC.appendRow(ray[0]);
     240      assume(zc->dimensionOfLinealitySpace()+1 >= zc->dimension());
     241      if (zc->dimensionOfLinealitySpace()+1 >= zc->dimension())
     242        raysOfC.appendRow(zc->getRelativeInteriorPoint());
     243      else
     244      {
     245        gfan::ZVector interiorPoint = zc->getRelativeInteriorPoint();
     246        if (!currentStrategy->homogeneitySpaceContains(interiorPoint))
     247        {
     248          raysOfC.appendRow(interiorPoint);
     249          raysOfC.appendRow(currentStrategy->negateWeight(interiorPoint));
     250        }
     251        else
     252        {
     253          gfan::ZMatrix zm = zc->generatorsOfLinealitySpace();
     254          for (int i=0; i<zm.getHeight(); i++)
     255          {
     256            gfan::ZVector point = zm[i];
     257            if (currentStrategy->homogeneitySpaceContains(point))
     258            {
     259              raysOfC.appendRow(point);
     260              raysOfC.appendRow(currentStrategy->negateWeight(point));
     261              break;
     262            }
     263          }
     264        }
     265      }
    236266    }
    237267  }
     
    240270    for (ZConesSortedByDimension::iterator zc=C.begin(); zc!=C.end(); zc++)
    241271    {
    242       assume(zc->dimensionOfLinealitySpace()+2 == zc->dimension());
    243       raysOfC.appendRow(zc->getRelativeInteriorPoint());
     272      assume(zc->dimensionOfLinealitySpace()+2 >= zc->dimension());
     273      if (zc->dimensionOfLinealitySpace()+2 == zc->dimension())
     274        raysOfC.appendRow(zc->getRelativeInteriorPoint());
     275      else
     276      {
     277        gfan::ZVector interiorPoint = zc->getRelativeInteriorPoint();
     278        if (!currentStrategy->homogeneitySpaceContains(interiorPoint))
     279        {
     280          raysOfC.appendRow(interiorPoint);
     281          raysOfC.appendRow(currentStrategy->negateWeight(interiorPoint));
     282        }
     283        else
     284        {
     285          gfan::ZMatrix zm = zc->generatorsOfLinealitySpace();
     286          for (int i=0; i<zm.getHeight(); i++)
     287          {
     288            gfan::ZVector point = zm[i];
     289            if (currentStrategy->homogeneitySpaceContains(point))
     290            {
     291              raysOfC.appendRow(point);
     292              raysOfC.appendRow(currentStrategy->negateWeight(point));
     293              break;
     294            }
     295          }
     296        }
     297      }
    244298    }
    245299  }
  • Singular/dyn_modules/gfanlib/tropicalStrategy.cc

    rf16226 r7723d00  
    458458poly tropicalStrategy::checkInitialIdealForMonomial(const ideal I, const ring r, const gfan::ZVector w) const
    459459{
     460  int k = idSize(I);
     461  for (int i=0; i<k; i++)
     462  {
     463    poly g = I->m[i];
     464    if (pNext(g)==NULL && (isValuationTrivial() || n_IsOne(p_GetCoeff(g,r),r->cf)))
     465    {
     466      poly monomial = p_Copy(g,r);
     467      return monomial;
     468    }
     469  }
    460470  // prepend extra weight for homogeneity
    461471  // switch to residue field if valuation is non trivial
     
    465475  // if switched to residue field, remove possibly 0 elements
    466476  ideal inI = initial(I,r,w);
    467   int k = idSize(inI);
    468477  ideal inIShortcut = idInit(k);
    469478  nMapFunc intoShortcut = n_SetMap(r->cf,rShortcut->cf);
  • Singular/dyn_modules/gfanlib/tropicalStrategy.h

    rf16226 r7723d00  
    232232
    233233  /**
     234   * returns true, if v is contained in the homogeneity space; false otherwise
     235   */
     236  bool homogeneitySpaceContains(const gfan::ZVector &v) const
     237  {
     238    return linealitySpace.contains(v);
     239  }
     240
     241  /**
    234242   * returns true, if valuation non-trivial, false otherwise
    235243   */
Note: See TracChangeset for help on using the changeset viewer.