Changeset eacb781 in git


Ignore:
Timestamp:
Aug 23, 2014, 4:25:47 PM (9 years ago)
Author:
Yue Ren <ren@…>
Branches:
(u'spielwiese', '91e5db82acc17434e4062bcfa44e6efa7d41fd30')
Children:
9c03260ac0404405e4994f73b30ef46f079535d8
Parents:
78abc705dd6af8b10c453361ab125294a2432189
git-author:
Yue Ren <ren@mathematik.uni-kl.de>2014-08-23 16:25:47+02:00
git-committer:
Yue Ren <ren@mathematik.uni-kl.de>2015-02-06 13:47:04+01:00
Message:
chg: status update 23.08.
Location:
Singular/dyn_modules/gfanlib
Files:
18 edited

Legend:

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

    r78abc7 reacb781  
    44static bool checkForNonPositiveEntries(const gfan::ZVector w)
    55{
    6   for (unsigned i=1; i<w.size(); i++)
     6  for (unsigned i=0; i<w.size(); i++)
    77  {
    88    if (w[i].sign()<=0)
     
    1515  return true;
    1616}
     17
     18static bool checkForNonPositiveLaterEntries(const gfan::ZVector w)
     19{
     20  if (w[0].sign()<0)
     21  {
     22    std::cout << "ERROR: negative weight in weight vector first entry" << std::endl
     23              << "weight: " << w << std::endl;
     24    return false;
     25  }
     26  for (unsigned i=1; i<w.size(); i++)
     27  {
     28    if (w[i].sign()<=0)
     29    {
     30      std::cout << "ERROR: non-positive weight in weight vector later entries" << std::endl
     31                << "weight: " << w << std::endl;
     32      return false;
     33    }
     34  }
     35  return true;
     36}
     37
    1738
    1839/***
     
    5071  for (unsigned i=1; i<w.size(); i++)
    5172    v[i]=-w[i]+max+1;
    52   assume(checkForNonPositiveEntries(v));
     73  assume(checkForNonPositiveLaterEntries(v));
    5374  return v;
    5475}
     
    87108gfan::ZVector valued_adjustWeightUnderHomogeneity(const gfan::ZVector e, const gfan::ZVector w)
    88109{
    89   assume(checkForNonPositiveEntries(w));
     110  assume(checkForNonPositiveLaterEntries(w));
    90111  /* find k such that e+k*w is strictly positive,
    91112   * i.e. k such that e[i]+k*w[i] is strictly positive
    92113   * for all i=0,...,n */
    93114  gfan::Integer k((long)0);
    94   if (e[0].sign()<=0)
     115  if (e[0].sign()<=0 && w[0].sign()>0)
    95116    k = gfan::Integer((long)1)-(e[0]/w[0]);
    96117  for (unsigned i=1; i<e.size(); i++)
     
    105126  /* compute e+k*w, check it for correctness and return it */
    106127  gfan::ZVector v = e+k*w;
    107   assume(checkForNonPositiveEntries(v));
     128  assume(checkForNonPositiveLaterEntries(v));
    108129  return v;
    109130}
  • Singular/dyn_modules/gfanlib/containsMonomial.cc

    r78abc7 reacb781  
    6262  }
    6363  rComplete(s,1);
     64  rTest(s);
    6465  return s;
    6566}
     
    9394
    9495  rComplete(s,1);
     96  rTest(s);
    9597  return s;
    9698}
     
    136138  r->cf = nInitChar(n_Zp,(void*)(long)n_Int(p_GetCoeff(I->m[0],currRing),currRing->cf));
    137139  rComplete(r);
     140  rTest(r);
    138141
    139142  ideal J = id_Copy(I, currRing); poly cache; number temp;
  • Singular/dyn_modules/gfanlib/flip.cc

    r78abc7 reacb781  
    3838 *  (2) Is is a Groebner basis of the same ideal with respect to the ordering on s
    3939 **/
    40 std::pair<ideal,ring> flip(const ideal I, const ring r, const gfan::ZVector interiorPoint, const gfan::ZVector facetNormal, const tropicalStrategy& currentStrategy)
     40std::pair<ideal,ring> flip0(const ideal I, const ring r,
     41                            const gfan::ZVector interiorPoint,
     42                            const gfan::ZVector facetNormal,
     43                            const gfan::ZVector adjustedInteriorPoint,
     44                            const gfan::ZVector adjustedFacetNormal)
    4145{
    42   /* read out appropiate functions for adjusting weights and adjust themm */
    43   gfan::ZVector adjustedInteriorPoint = currentStrategy.adjustWeightForHomogeneity(interiorPoint);
    44   gfan::ZVector adjustedFacetNormal = currentStrategy.adjustWeightUnderHomogeneity(facetNormal,adjustedInteriorPoint);
    45 
    4646  /* create a ring with weighted ordering  */
    4747  bool ok;
     
    6262  sAdjusted->wvhdl[1] = ZVectorToIntStar(adjustedFacetNormal,ok);
    6363  sAdjusted->order[2] = ringorder_C;
    64   rComplete(sAdjusted,1);
     64  rComplete(sAdjusted);
     65  rTest(sAdjusted);
    6566  nMapFunc identity = n_SetMap(r->cf,sAdjusted->cf);
    6667
     
    100101  s->block1[2] = n;
    101102  s->order[3] = ringorder_C;
    102   rComplete(s,1);
     103  rComplete(s);
     104  rTest(s);
    103105  identity = n_SetMap(sAdjusted->cf,s->cf);
    104106  k = idSize(IsAdjustedGB); ideal IsGB = idInit(k);
  • Singular/dyn_modules/gfanlib/flip.h

    r78abc7 reacb781  
    1 #ifndef FLIP_H
    2 #define FLIP_H
     1#ifndef GFANLIB_FLIP_H
     2#define GFANLIB_FLIP_H
    33
    44#include <utility>
    55#include <libpolys/polys/simpleideals.h>
     6#include <gfanlib/gfanlib_vector.h>
    67
    7 #include <gfanlib/gfanlib_vector.h>
    8 #include <tropicalStrategy.h>
    9 
    10 std::pair<ideal,ring> flip(const ideal I, const ring r, const gfan::ZVector interiorPoint, const gfan::ZVector facetNormal, const tropicalStrategy& currentCase);
     8std::pair<ideal,ring> flip0(const ideal I, const ring r,
     9                            const gfan::ZVector interiorPoint,
     10                            const gfan::ZVector facetNormal,
     11                            const gfan::ZVector adjustedInteriorPoint,
     12                            const gfan::ZVector adjustedFacetNormal);
    1113
    1214#endif
  • Singular/dyn_modules/gfanlib/groebnerCone.cc

    r78abc7 reacb781  
    7272  if (I) polynomialIdeal = id_Copy(I,r);
    7373  if (r) polynomialRing = rCopy(r);
     74  currentCase.reduce(I,r);
    7475
    7576  int n = rVar(polynomialRing);
     
    8283  for (int i=0; i<idSize(polynomialIdeal); i++)
    8384  {
    84     g = polynomialIdeal->m[i];
    85     pGetExpV(g,leadexpv);
    86     leadexpw = intStar2ZVector(n, leadexpv);
    87     pIter(g);
    88     while (g)
    89     {
    90       pGetExpV(g,tailexpv);
    91       tailexpw = intStar2ZVector(n, tailexpv);
    92       inequalities.appendRow(leadexpw-tailexpw);
     85    g = I->m[i];
     86    if (g)
     87    {
     88      p_GetExpV(g,leadexpv,r);
     89      leadexpw = intStar2ZVector(n, leadexpv);
    9390      pIter(g);
     91      while (g)
     92      {
     93        p_GetExpV(g,tailexpv,r);
     94        tailexpw = intStar2ZVector(n, tailexpv);
     95        inequalities.appendRow(leadexpw-tailexpw);
     96        pIter(g);
     97      }
    9498    }
    9599  }
    96100  omFreeSize(leadexpv,(n+1)*sizeof(int));
    97101  omFreeSize(tailexpv,(n+1)*sizeof(int));
     102  if (currentStrategy->restrictToLowerHalfSpace())
     103  {
     104    gfan::ZVector lowerHalfSpaceCondition = gfan::ZVector(n);
     105    lowerHalfSpaceCondition[0] = -1;
     106    inequalities.appendRow(lowerHalfSpaceCondition);
     107  }
     108
    98109  polyhedralCone = gfan::ZCone(inequalities,gfan::ZMatrix(0, inequalities.getWidth()));
     110  polyhedralCone.canonicalize();
    99111  interiorPoint = polyhedralCone.getRelativeInteriorPoint();
    100112  assume(checkOrderingAndCone(polynomialRing,polyhedralCone));
     
    116128  if (I) polynomialIdeal = id_Copy(I,r);
    117129  if (r) polynomialRing = rCopy(r);
     130  currentCase.reduce(I,r);
    118131
    119132  int n = rVar(r);
     
    124137  {
    125138    poly g = polynomialIdeal->m[i];
    126     p_GetExpV(g,expv,polynomialRing);
    127     gfan::ZVector leadexpv = intStar2ZVector(n,expv);
    128     long d = wDeg(g,polynomialRing,w);
    129     for (pIter(g); g; pIter(g))
     139    if (g)
    130140    {
    131141      p_GetExpV(g,expv,polynomialRing);
    132       gfan::ZVector tailexpv = intStar2ZVector(n,expv);
    133       if (wDeg(g,polynomialRing,w)==d)
    134         equations.appendRow(leadexpv-tailexpv);
    135       else
     142      gfan::ZVector leadexpv = intStar2ZVector(n,expv);
     143      long d = wDeg(g,polynomialRing,w);
     144      for (pIter(g); g; pIter(g))
    136145      {
    137         assume(wDeg(g,polynomialRing,w)<d);
    138         inequalities.appendRow(leadexpv-tailexpv);
     146        p_GetExpV(g,expv,polynomialRing);
     147        gfan::ZVector tailexpv = intStar2ZVector(n,expv);
     148        if (wDeg(g,polynomialRing,w)==d)
     149          equations.appendRow(leadexpv-tailexpv);
     150        else
     151        {
     152          assume(wDeg(g,polynomialRing,w)<d);
     153          inequalities.appendRow(leadexpv-tailexpv);
     154        }
    139155      }
    140156    }
    141157  }
    142158  omFreeSize(expv,(n+1)*sizeof(int));
     159  if (currentStrategy->restrictToLowerHalfSpace())
     160  {
     161    gfan::ZVector lowerHalfSpaceCondition = gfan::ZVector(n);
     162    lowerHalfSpaceCondition[0] = -1;
     163    inequalities.appendRow(lowerHalfSpaceCondition);
     164  }
    143165
    144166  polyhedralCone = gfan::ZCone(inequalities,equations);
     167  polyhedralCone.canonicalize();
    145168  interiorPoint = polyhedralCone.getRelativeInteriorPoint();
    146169  assume(checkOrderingAndCone(polynomialRing,polyhedralCone));
     
    159182  if (I) polynomialIdeal = id_Copy(I,r);
    160183  if (r) polynomialRing = rCopy(r);
     184  currentCase.reduce(I,r);
    161185
    162186  int n = rVar(r);
     
    167191  {
    168192    poly g = polynomialIdeal->m[i];
    169     p_GetExpV(g,expv,polynomialRing);
    170     gfan::ZVector leadexpv = intStar2ZVector(n,expv);
    171     long d1 = wDeg(g,polynomialRing,u);
    172     long d2 = wDeg(g,polynomialRing,w);
    173     for (pIter(g); g; pIter(g))
     193    if (g)
    174194    {
    175195      p_GetExpV(g,expv,polynomialRing);
    176       gfan::ZVector tailexpv = intStar2ZVector(n,expv);
    177       if (wDeg(g,polynomialRing,u)==d1 && wDeg(g,polynomialRing,w)==d2)
    178         equations.appendRow(leadexpv-tailexpv);
    179       else
     196      gfan::ZVector leadexpv = intStar2ZVector(n,expv);
     197      long d1 = wDeg(g,polynomialRing,u);
     198      long d2 = wDeg(g,polynomialRing,w);
     199      for (pIter(g); g; pIter(g))
    180200      {
    181         assume(wDeg(g,polynomialRing,u)<d1 || wDeg(g,polynomialRing,w)<d2);
    182         inequalities.appendRow(leadexpv-tailexpv);
     201        p_GetExpV(g,expv,polynomialRing);
     202        gfan::ZVector tailexpv = intStar2ZVector(n,expv);
     203        if (wDeg(g,polynomialRing,u)==d1 && wDeg(g,polynomialRing,w)==d2)
     204          equations.appendRow(leadexpv-tailexpv);
     205        else
     206        {
     207          assume(wDeg(g,polynomialRing,u)<d1 || wDeg(g,polynomialRing,w)<d2);
     208          inequalities.appendRow(leadexpv-tailexpv);
     209        }
    183210      }
    184211    }
    185212  }
    186213  omFreeSize(expv,(n+1)*sizeof(int));
     214  if (currentStrategy->restrictToLowerHalfSpace())
     215  {
     216    gfan::ZVector lowerHalfSpaceCondition = gfan::ZVector(n);
     217    lowerHalfSpaceCondition[0] = -1;
     218    inequalities.appendRow(lowerHalfSpaceCondition);
     219  }
    187220
    188221  polyhedralCone = gfan::ZCone(inequalities,equations);
     222  polyhedralCone.canonicalize();
    189223  interiorPoint = polyhedralCone.getRelativeInteriorPoint();
    190224  assume(checkOrderingAndCone(polynomialRing,polyhedralCone));
     
    205239  {
    206240    poly g = inI->m[i];
    207     p_GetExpV(g,expv,r);
    208     gfan::ZVector leadexpv = intStar2ZVector(n,expv);
    209     for (pIter(g); g; pIter(g))
     241    if (g)
    210242    {
    211243      p_GetExpV(g,expv,r);
    212       gfan::ZVector tailexpv = intStar2ZVector(n,expv);
    213       equations.appendRow(leadexpv-tailexpv);
     244      gfan::ZVector leadexpv = intStar2ZVector(n,expv);
     245      for (pIter(g); g; pIter(g))
     246      {
     247        p_GetExpV(g,expv,r);
     248        gfan::ZVector tailexpv = intStar2ZVector(n,expv);
     249        equations.appendRow(leadexpv-tailexpv);
     250      }
    214251    }
    215252  }
     
    218255  {
    219256    poly g = I->m[i];
    220     p_GetExpV(g,expv,r);
    221     gfan::ZVector leadexpv = intStar2ZVector(n,expv);
    222     for (pIter(g); g; pIter(g))
     257    if (g)
    223258    {
    224259      p_GetExpV(g,expv,r);
    225       gfan::ZVector tailexpv = intStar2ZVector(n,expv);
    226       inequalities.appendRow(leadexpv-tailexpv);
     260      gfan::ZVector leadexpv = intStar2ZVector(n,expv);
     261      for (pIter(g); g; pIter(g))
     262      {
     263        p_GetExpV(g,expv,r);
     264        gfan::ZVector tailexpv = intStar2ZVector(n,expv);
     265        inequalities.appendRow(leadexpv-tailexpv);
     266      }
    227267    }
    228268  }
    229269  omFreeSize(expv,(n+1)*sizeof(int));
     270  if (currentStrategy->restrictToLowerHalfSpace())
     271  {
     272    gfan::ZVector lowerHalfSpaceCondition = gfan::ZVector(n);
     273    lowerHalfSpaceCondition[0] = -1;
     274    inequalities.appendRow(lowerHalfSpaceCondition);
     275  }
    230276
    231277  polyhedralCone = gfan::ZCone(inequalities,equations);
     278  polyhedralCone.canonicalize();
    232279  interiorPoint = polyhedralCone.getRelativeInteriorPoint();
    233280  assume(checkOrderingAndCone(polynomialRing,polyhedralCone));
     
    277324gfan::ZVector groebnerCone::tropicalPoint() const
    278325{
     326  assume(checkOrderingAndCone(polynomialRing,polyhedralCone));
    279327  ideal I = polynomialIdeal;
    280328  ring r = polynomialRing;
    281   gfan::ZCone zc = polyhedralCone;
    282   gfan::ZMatrix R = zc.extremeRays();
    283   assume(checkOrderingAndCone(r,zc));
     329
     330  gfan::ZCone coneToCheck = polyhedralCone;
     331  gfan::ZMatrix R = coneToCheck.extremeRays();
    284332  for (int i=0; i<R.getHeight(); i++)
    285333  {
    286     ideal inI = initial(I,r,R[i]);
    287     poly s = checkForMonomialViaSuddenSaturation(inI,r);
    288     if (s == NULL)
    289     {
    290       id_Delete(&inI,r);
     334    assume(!currentStrategy->restrictToLowerHalfSpace() || R[i][0].sign()<=0);
     335    poly s = currentStrategy->checkInitialIdealForMonomial(I,r,R[i]);
     336    if (s==NULL)
     337    {
    291338      p_Delete(&s,r);
    292339      return R[i];
    293340    }
    294     id_Delete(&inI,r);
    295     p_Delete(&s,r);
    296341  }
    297342  return gfan::ZVector();
     
    346391   *   to obtain an initial form with respect to interiorPoint+e*facetNormal,
    347392   *   for e>0 sufficiently small */
    348   std::pair<ideal,ring> flipped = flip(polynomialIdeal,polynomialRing,interiorPoint,facetNormal,*currentStrategy);
     393  std::pair<ideal,ring> flipped = currentStrategy->flip(polynomialIdeal,polynomialRing,interiorPoint,facetNormal);
     394  std::cout << "finished flip" << std::endl;
    349395  assume(checkPolynomialInput(flipped.first,flipped.second));
    350396  groebnerCone flippedCone(flipped.first, flipped.second, interiorPoint, facetNormal, *currentStrategy);
     
    417463  groebnerCones neighbours;
    418464  for (int i=0; i<interiorPoints.getHeight(); i++)
     465  {
     466    std::cout << "performing flip " << i << " out of " << interiorPoints.getHeight() << std::endl;
    419467    neighbours.insert(this->flipCone(interiorPoints[i],facetNormals[i]));
    420 
     468  }
    421469  return neighbours;
    422470}
     
    477525  for (int i=0; i<interiorPoints.getHeight(); i++)
    478526  {
    479     ideal initialIdeal = initial(polynomialIdeal,polynomialRing,interiorPoints[i]);
    480     std::set<gfan::ZVector> rays = raysOfTropicalStar(initialIdeal,polynomialRing,interiorPoints[i],*currentStrategy);
    481     for (std::set<gfan::ZVector>::iterator ray = rays.begin(); ray!=rays.end(); ray++)
    482       neighbours.insert(this->flipCone(interiorPoints[i],*ray));
     527    if (!(currentStrategy->restrictToLowerHalfSpace() && interiorPoints[i][0].sign()==0))
     528    {
     529      ideal initialIdeal = initial(polynomialIdeal,polynomialRing,interiorPoints[i]);
     530      std::set<gfan::ZVector> rays = raysOfTropicalStar(initialIdeal,polynomialRing,interiorPoints[i],*currentStrategy);
     531      for (std::set<gfan::ZVector>::iterator ray = rays.begin(); ray!=rays.end(); ray++)
     532        neighbours.insert(this->flipCone(interiorPoints[i],*ray));
     533    }
    483534  }
    484535  return neighbours;
  • Singular/dyn_modules/gfanlib/groebnerCone.h

    r78abc7 reacb781  
    4040  gfan::ZCone polyhedralCone;
    4141  gfan::ZVector interiorPoint;
     42  gfan::ZVector negativePointInLineality;
    4243  const tropicalStrategy* currentStrategy;
    4344
     
    6970  gfan::ZCone getPolyhedralCone() const { return polyhedralCone; };
    7071  gfan::ZVector getInteriorPoint() const { return interiorPoint; };
     72  gfan::ZVector getNegativePointInLineality() const { return negativePointInLineality; };
    7173  const tropicalStrategy* getTropicalStrategy() const {return currentStrategy; };
    7274
  • Singular/dyn_modules/gfanlib/initial.cc

    r78abc7 reacb781  
    128128ideal initial(const ideal I, const ring r, const gfan::ZVector w)
    129129{
     130  idSkipZeroes(I);
    130131  int k = idSize(I); ideal inI = idInit(k);
    131132  for (int i=0; i<k; i++)
  • Singular/dyn_modules/gfanlib/neighbours.cc

    r78abc7 reacb781  
    178178  gfan::ZMatrix interiorPoints = facetInteriorPoints(zc);
    179179  groebnerCones neighbours;
    180   bool (*red)(ideal I, ring r, number p);
    181   red = currentCase.reduce;
    182   number p = currentCase.uniformizingParameter;
    183180
    184181  for (int i=0; i<interiorPoints.getHeight(); i++)
     
    196193      ideal I = flipped.first;
    197194      ring r = flipped.second;
    198       red(I,r,p);
     195      currentCase->reduce(I,r);
    199196      gfan::ZCone c = sloppyGroebnerCone(I,r,*ray);
    200197      gfan::ZVector p = c.getRelativeInteriorPoint();
  • Singular/dyn_modules/gfanlib/ppinitialReduction.cc

    r78abc7 reacb781  
    2121  if (g==NULL)
    2222    return false;
     23  p_Test(g,r);
    2324
    2425  poly toBeChecked = pNext(g);
     
    4344      if (n_DivBy(p_GetCoeff(toBeChecked,r),p,r->cf))
    4445      {
     46        power=1;
    4547        coeff=n_Div(p_GetCoeff(toBeChecked,r),p,r->cf);
    46         power=1;
    4748        while (n_DivBy(coeff,p,r->cf))
    4849        {
    49           coeff=n_Div(p_GetCoeff(pNext(g),r),p,r->cf);
    5050          power++;
     51          number coeff0 = n_Div(coeff,p,r->cf);
     52          n_Delete(&coeff,r->cf);
     53          coeff = coeff0;
     54          coeff0 = NULL;
    5155          if (power<1)
    5256          {
     
    6872        pIter(gEnd); pIter(toBeChecked);
    6973        pNext(gEnd)=NULL;
     74        p_Test(g,r);
    7075      }
    7176    }
     
    193198    n=j;
    194199  } while(n);
    195   for (int i=1; i<m; i++)
     200  for (int i=0; i<m; i++)
    196201    if (pReduce(I->m[i],p,r)) return true;
    197202
     
    257262bool ppreduceInitially(ideal I, const number p, const poly g, const ring r)
    258263{
     264  idInsertPoly(I,g);
    259265  int n=idSize(I);
    260   idInsertPoly(I,g);
    261266  int j;
    262   for (j=n; j>0; j--)
     267  for (j=n-1; j>0; j--)
    263268  {
    264269    if (p_LmCmp(I->m[j], I->m[j-1],r)>0)
     
    370375      {
    371376        g=T->m[i-1];
    372         T->m[i-1]=I->m[i];
     377        T->m[i-1]=T->m[i];
    373378        T->m[i]=g;
    374379        j = i;
     
    389394    if (i<k)
    390395    {
    391       g = p_Init(r);
     396      g = p_One(r);
    392397      for (int j=2; j<=r->N; j++)
    393398        p_SetExp(g,j,p_GetExp(pNext(T->m[0]),j,r)-p_GetExp(G->m[i],j,r),r);
    394       p_SetCoeff(g,n_Init(1,r->cf),r); p_Setm(g,r);
     399      p_Setm(g,r);
    395400      g = p_Mult_q(g,p_Copy(G->m[i],r),r);
    396401      ppreduceInitially(I,p,g,r);
     
    504509  for (int i=0; i<n; i++)
    505510  {
     511    I->m[i] = p_Cleardenom(I->m[i],r);
    506512    long d = 0;
    507513    for (int j=2; j<=r->N; j++)
  • Singular/dyn_modules/gfanlib/startingCone.cc

    r78abc7 reacb781  
    1111#include <tropicalVarietyOfPolynomials.h>
    1212#include <tropicalVariety.h>
     13#include <tropicalStrategy.h>
    1314
    1415
     
    2324  ideal I = sigma.getPolynomialIdeal();
    2425  ring r = sigma.getPolynomialRing();
    25   ideal inI = sloppyInitial(I,r,w);
    26   poly s = checkForMonomialViaSuddenSaturation(inI,r);
    27   id_Delete(&inI,r);
     26  const tropicalStrategy* currentStrategy = sigma.getTropicalStrategy();
     27  poly s = currentStrategy->checkInitialIdealForMonomial(I,r,w);
    2828  if (s)
    2929  {
     
    4444
    4545
    46 /***
    47  * Computes a starting point by traversing the Groebner fan,
     46/**
     47 * Computes a starting point outside the lineatliy space by traversing the Groebner fan,
    4848 * checking each cone whether it contains a ray in the tropical variety.
    49  * Returns a point in the tropical variety and a maximal Groebner cone
    50  * containing the point.
     49 * Returns a point in the tropical variety and a maximal Groebner cone containing the point.
    5150 **/
    5251std::pair<gfan::ZVector,groebnerCone> tropicalStartingDataViaGroebnerFan(const ideal I, const ring r, const tropicalStrategy& currentStrategy)
    5352{
    54   std::cout << "computing starting cone" << std::endl;
    55   currentStrategy.reduce(I,r);
    56   std::cout << "finished reduction" << std::endl;
    57 
     53  // start by computing a maximal Groebner cone and
     54  // check whether one of its rays lies in the tropical variety
    5855  const groebnerCone sigma(I,r,currentStrategy);
    59   std::cout << "finished first maximal Groebner cone" << std::endl;
    6056  gfan::ZVector startingPoint = sigma.tropicalPoint();
    6157  if (startingPoint.size() > 0)
    6258    return std::make_pair(startingPoint,sigma);
     59
     60  // if not, traverse the groebnerFan and until such a cone is found
     61  // and return the maximal cone together with a point in its ray
    6362  groebnerCones groebnerFan;
    6463  groebnerCones workingList;
    6564  workingList.insert(sigma);
    66 
    6765  while (!workingList.empty())
    6866  {
    69     std::cout << "traversing groebner fan..." << std::endl;
    7067    const groebnerCone sigma = *(workingList.begin());
    7168    groebnerCones neighbours = sigma.groebnerNeighbours();
     
    8683    workingList.erase(sigma);
    8784  }
     85
     86  // return some trivial output, if such a cone cannot be found
    8887  gfan::ZVector emptyVector = gfan::ZVector(0);
    8988  groebnerCone emptyCone = groebnerCone();
     
    264263    }
    265264    gfan::ZCone C0 = currentStrategy.getHomogeneitySpace();
    266     if (C0.dimension()==currentStrategy.getDimensionOfIdeal())
     265    if (C0.dimension()==currentStrategy.getExpectedDimension())
    267266    {
    268267      gfan::ZMatrix lin = C0.generatorsOfLinealitySpace();
     
    293292  {
    294293    poly g = I->m[i];
    295     p_GetExpV(g,expv,r);
    296     gfan::ZVector leadexp = intStar2ZVector(n,expv);
    297     for (pIter(g); g; pIter(g))
     294    if (g)
    298295    {
    299296      p_GetExpV(g,expv,r);
    300       equations.appendRow(leadexp-intStar2ZVector(n,expv));
     297      gfan::ZVector leadexp = intStar2ZVector(n,expv);
     298      for (pIter(g); g; pIter(g))
     299      {
     300        p_GetExpV(g,expv,r);
     301        equations.appendRow(leadexp-intStar2ZVector(n,expv));
     302      }
    301303    }
    302304  }
     
    304306  return gfan::ZCone(gfan::ZMatrix(0,n),equations);
    305307}
    306 
    307308
    308309/***
    309310 * Computes a starting cone in the tropical variety.
    310311 **/
    311 groebnerCone tropicalStartingCone(const ideal I, const ring r, const tropicalStrategy& currentStrategy)
    312 {
    313   ring s = rCopy(r);
    314   int k = idSize(I); ideal inI = idInit(k);
    315   nMapFunc identityMap = n_SetMap(r->cf,s->cf);
    316   for (int i=0; i<k; i++)
    317     inI->m[i] = p_PermPoly(I->m[i],NULL,r,s,identityMap,NULL,0);
    318 
    319   gfan::ZCone zc = linealitySpaceOfGroebnerFan(inI,s);
    320   gfan::ZVector startingPoint; groebnerCone ambientMaximalCone;
    321   while (zc.dimension()<currentStrategy.getDimensionOfIdeal())
    322   {
     312groebnerCone tropicalStartingCone(const tropicalStrategy& currentStrategy)
     313{
     314  ring r = currentStrategy.getStartingRing();
     315  ideal I = currentStrategy.getStartingIdeal();
     316  if (currentStrategy.isConstantCoefficientCase())
     317  {
     318    // copy the data, so that it be deleted when passed to the loop
     319    // s <- r
     320    // inI <- I
     321    ring s = rCopy(r);
     322    int k = idSize(I); ideal inI = idInit(k);
     323    nMapFunc identityMap = n_SetMap(r->cf,s->cf);
     324    for (int i=0; i<k; i++)
     325      inI->m[i] = p_PermPoly(I->m[i],NULL,r,s,identityMap,NULL,0);
     326
     327    // repeatedly computes a point in the tropical variety outside the lineality space,
     328    // take the initial ideal with respect to it
     329    // and check whether the dimension of its homogeneity space
     330    // equals the dimension of the tropical variety
     331    gfan::ZCone zc = linealitySpaceOfGroebnerFan(inI,s);
     332    gfan::ZVector startingPoint; groebnerCone ambientMaximalCone;
     333    while (zc.dimension()<currentStrategy.getExpectedDimension())
     334    {
     335      // compute a point in the tropical variety outside the lineality space
     336      std::pair<gfan::ZVector,groebnerCone> startingData = tropicalStartingDataViaGroebnerFan(inI,s,currentStrategy);
     337      startingPoint = startingData.first;
     338      ambientMaximalCone = groebnerCone(startingData.second);
     339
     340      id_Delete(&inI,s); rDelete(s);
     341      inI = ambientMaximalCone.getPolynomialIdeal();
     342      s = ambientMaximalCone.getPolynomialRing();
     343
     344      // compute the initial ideal with respect to the weight
     345      inI = sloppyInitial(inI,s,startingPoint);
     346      zc = linealitySpaceOfGroebnerFan(inI,s);
     347    }
     348
     349    // once the dimension of the homogeneity space equals that of the tropical variety
     350    // we know that we have an initial ideal with respect to a weight
     351    // in the relative interior of a maximal cone in the tropical variety
     352    // from this we can read of the inequalities and equations
     353
     354    // but before doing so, we must lift the generating set of inI
     355    // to a generating set of I
     356    ideal J = lift(I,r,inI,s);
     357    groebnerCone startingCone(J,inI,s,currentStrategy);
     358    id_Delete(&inI,s);
     359    id_Delete(&J,s);
     360
     361    assume(checkContainmentInTropicalVariety(startingCone));
     362    return startingCone;
     363  }
     364  else
     365  {
     366    // copy the data, so that it be deleted when passed to the loop
     367    // s <- r
     368    // inI <- I
     369    ring s = rCopy(r);
     370    int k = idSize(I); ideal inI = idInit(k);
     371    nMapFunc identityMap = n_SetMap(r->cf,s->cf);
     372    for (int i=0; i<k; i++)
     373      inI->m[i] = p_PermPoly(I->m[i],NULL,r,s,identityMap,NULL,0);
     374
     375    // and check whether the dimension of its homogeneity space
     376    // equals the dimension of the tropical variety
     377    gfan::ZCone zc = linealitySpaceOfGroebnerFan(inI,s);
     378    if (zc.dimension()==currentStrategy.getExpectedDimension())
     379    { // this shouldn't happen as trivial cases should be caught beforehand
     380      // this is the case that the tropical variety consists soely out of the lineality space
     381      groebnerCone startingCone(I,inI,s,currentStrategy);
     382      id_Delete(&inI,s);
     383      rDelete(s);
     384      return startingCone;
     385    }
     386
     387    // compute a point in the tropical variety outside the lineality space
     388    // compute the initial ideal with respect to the weight
    323389    std::pair<gfan::ZVector,groebnerCone> startingData = tropicalStartingDataViaGroebnerFan(inI,s,currentStrategy);
    324     startingPoint = startingData.first;
    325     ambientMaximalCone = groebnerCone(startingData.second);
    326 
     390    gfan::ZVector startingPoint = startingData.first;
     391    groebnerCone ambientMaximalCone = groebnerCone(startingData.second);
    327392    id_Delete(&inI,s); rDelete(s);
    328393    inI = ambientMaximalCone.getPolynomialIdeal();
    329394    s = ambientMaximalCone.getPolynomialRing();
    330 
    331395    inI = sloppyInitial(inI,s,startingPoint);
    332396    zc = linealitySpaceOfGroebnerFan(inI,s);
    333   }
    334 
    335   ideal J = lift(I,r,inI,s);
    336   groebnerCone tropicalStartingCone(J,inI,s,currentStrategy);
    337   id_Delete(&inI,s);
    338   id_Delete(&J,s);
    339 
    340   assume(checkContainmentInTropicalVariety(tropicalStartingCone));
    341   assume(checkOneCodimensionalLinealitySpace(tropicalStartingCone));
    342   return tropicalStartingCone;
    343 }
    344 
     397
     398    // and check whether the dimension of its homogeneity space
     399    // equals the dimension of the tropical variety
     400    if (zc.dimension()==currentStrategy.getExpectedDimension())
     401    { // this case shouldn't happen as trivial cases should be caught beforehand
     402      // this is the case that the tropical variety has a one-codimensional lineality space
     403      ideal J = lift(I,r,inI,s);
     404      groebnerCone startingCone(J,inI,s,currentStrategy);
     405      id_Delete(&inI,s);
     406      id_Delete(&J,s);
     407      return startingCone;
     408    }
     409
     410    // from this point on, inI contains the uniformizing parameter,
     411    // hence it contains a monomial if and only if its residue over the residue field does.
     412    // so we will switch to the residue field
     413    ring rShortcut = rCopy0(r);
     414    nKillChar(rShortcut->cf);
     415    rShortcut->cf = nCopyCoeff((currentStrategy.getShortcutRing())->cf);
     416    rComplete(rShortcut);
     417    rTest(rShortcut);
     418    k = idSize(inI);
     419    ideal inIShortcut = idInit(k);
     420    nMapFunc takingResidues = n_SetMap(s->cf,rShortcut->cf);
     421    for (int i=0; i<k; i++)
     422      inIShortcut->m[i] = p_PermPoly(inI->m[i],NULL,s,rShortcut,takingResidues,NULL,0);
     423    idSkipZeroes(inIShortcut);
     424    id_Delete(&inI,s);
     425
     426    // we are interested in a maximal cone of the tropical variety of inIShortcut
     427    // this basically equivalent to the case without valuation (or constant coefficient case)
     428    // except that our ideal is still only homogeneous in the later variables,
     429    // hence we set the optional parameter completelyHomogeneous as 'false'
     430    tropicalStrategy shortcutStrategy(inIShortcut,rShortcut,false);
     431    groebnerCone startingConeShortcut = tropicalStartingCone(shortcutStrategy);
     432    id_Delete(&inIShortcut,rShortcut); rDelete(rShortcut);
     433
     434    // now we need to obtain the initial of the residue of inI
     435    // with respect to a weight in the tropical cone,
     436    // and obtain the initial of inI with respect to the same weight
     437    ring sShortcut = startingConeShortcut.getPolynomialRing();
     438    inIShortcut = startingConeShortcut.getPolynomialIdeal();
     439    gfan::ZCone zd = startingConeShortcut.getPolyhedralCone();
     440    gfan::ZVector interiorPoint = startingConeShortcut.getInteriorPoint();
     441    inIShortcut = sloppyInitial(inIShortcut,sShortcut,interiorPoint);
     442
     443    s = rCopy0(sShortcut); // s will be a ring over the valuation ring
     444    nKillChar(s->cf);      // with the same ordering as sShortcut
     445    s->cf = nCopyCoeff(r->cf);
     446    rComplete(s);
     447    rTest(s);
     448
     449    k = idSize(inIShortcut); // inI will be overwritten with initial of inI
     450    inI = idInit(k+1);
     451    inI->m[0] = p_One(s);    // with respect to that weight
     452    identityMap = n_SetMap(r->cf,s->cf); // first element will obviously be p
     453    p_SetCoeff(inI->m[0],identityMap(currentStrategy.getUniformizingParameter(),r->cf,s->cf),s);
     454    nMapFunc findingRepresentatives = n_SetMap(sShortcut->cf,s->cf);
     455    for (int i=0; i<k; i++)              // and then come the rest
     456      inI->m[i+1] = p_PermPoly(inIShortcut->m[i],NULL,sShortcut,s,findingRepresentatives,NULL,0);
     457
     458    ideal J = lift(I,r,inI,s);
     459    groebnerCone startingCone(J,inI,s,currentStrategy);
     460    id_Delete(&inI,s);
     461    id_Delete(&J,s);
     462    rDelete(s);
     463
     464    return startingCone;
     465  }
     466}
    345467
    346468BOOLEAN tropicalStartingCone(leftv res, leftv args)
     
    357479      if (w==NULL)
    358480      {
    359         tropicalStrategy valuedCase(I,p,currRing);
    360         groebnerCone sigma = tropicalStartingCone(I,currRing,valuedCase);
     481        tropicalStrategy currentStrategy(I,p,currRing);
     482        groebnerCone sigma = tropicalStartingCone(currentStrategy);
     483        gfan::ZCone* startingCone = new gfan::ZCone(sigma.getPolyhedralCone());
     484        res->rtyp = coneID;
     485        res->data = (char*) startingCone;
     486        return FALSE;
     487      }
     488    }
     489    else
     490    {
     491      if (v==NULL)
     492      {
     493        tropicalStrategy currentStrategy(I,currRing);
     494        groebnerCone sigma = tropicalStartingCone(currentStrategy);
    361495        res->rtyp = coneID;
    362496        res->data = (char*) new gfan::ZCone(sigma.getPolyhedralCone());
     
    364498      }
    365499    }
    366     else
    367     {
    368       if (v==NULL)
    369       {
    370         tropicalStrategy nonValuedCase(I,currRing);
    371         groebnerCone sigma = tropicalStartingCone(I,currRing,nonValuedCase);
    372         res->rtyp = coneID;
    373         res->data = (char*) new gfan::ZCone(sigma.getPolyhedralCone());
    374         return FALSE;
    375       }
    376     }
    377500  }
    378501  WerrorS("tropicalStartingCone: unexpected parameters");
  • Singular/dyn_modules/gfanlib/startingCone.h

    r78abc7 reacb781  
    55#include <tropicalStrategy.h>
    66
    7 groebnerCone tropicalStartingCone(const ideal I, const ring r, const tropicalStrategy& currentCase);
     7groebnerCone tropicalStartingCone(const tropicalStrategy& currentCase);
    88
    99BOOLEAN tropicalStartingPoint(leftv res, leftv args);
  • Singular/dyn_modules/gfanlib/tropical.cc

    r78abc7 reacb781  
    2727  for (int i=0; i<IDELEMS(I); i++)
    2828  {
    29     g = (poly) I->m[i]; pGetExpV(g,leadexpv);
    30     leadexpw = intStar2ZVector(n, leadexpv);
    31     pIter(g);
    32     while (g != NULL)
    33     {
    34       pGetExpV(g,tailexpv);
    35       tailexpw = intStar2ZVector(n, tailexpv);
    36       equations.appendRow(leadexpw-tailexpw);
     29    g = (poly) I->m[i];
     30    if (g)
     31    {
     32      p_GetExpV(g,leadexpv,r);
     33      leadexpw = intStar2ZVector(n,leadexpv);
    3734      pIter(g);
     35      while (g)
     36      {
     37        p_GetExpV(g,tailexpv,r);
     38        tailexpw = intStar2ZVector(n,tailexpv);
     39        equations.appendRow(leadexpw-tailexpw);
     40        pIter(g);
     41      }
    3842    }
    3943  }
  • Singular/dyn_modules/gfanlib/tropicalCurves.cc

    r78abc7 reacb781  
    100100
    101101  /* complete the ring and return it */
    102   rComplete(s,1);
     102  rComplete(s);
     103  rTest(s);
    103104  return s;
    104105}
     
    114115{
    115116  int k = idSize(inI);
    116   int d = currentStrategy.getDimensionOfIdeal();
     117  int d = currentStrategy.getExpectedDimension();
    117118
    118119  /* Compute the common refinement over all tropical varieties
     
    168169  std::set<gfan::ZCone> C = tropicalStar(I,r,u,currentStrategy);
    169170  std::set<gfan::ZVector> raysOfC;
    170   for (std::set<gfan::ZCone>::iterator zc=C.begin(); zc!=C.end(); zc++)
    171   {
    172     assume(zc->dimensionOfLinealitySpace()+1 == zc->dimension());
    173     raysOfC.insert(zc->semiGroupGeneratorOfRay());
     171  if (!currentStrategy.restrictToLowerHalfSpace())
     172  {
     173    for (std::set<gfan::ZCone>::iterator zc=C.begin(); zc!=C.end(); zc++)
     174    {
     175      assume(zc->dimensionOfLinealitySpace()+1 == zc->dimension());
     176      raysOfC.insert(zc->semiGroupGeneratorOfRay());
     177    }
     178  }
     179  else
     180  {
     181    for (std::set<gfan::ZCone>::iterator zc=C.begin(); zc!=C.end(); zc++)
     182    {
     183      assume(zc->dimensionOfLinealitySpace()+2 == zc->dimension());
     184      raysOfC.insert(zc->getRelativeInteriorPoint());
     185    }
    174186  }
    175187  return raysOfC;
  • Singular/dyn_modules/gfanlib/tropicalStrategy.cc

    r78abc7 reacb781  
    4949 *g
    5050 */
    51 tropicalStrategy::tropicalStrategy(ideal I, ring r):
     51tropicalStrategy::tropicalStrategy(const ideal I, const ring r,
     52                                   const bool completelyHomogeneous,
     53                                   const bool completeSpace):
    5254  originalRing(rCopy(r)),
    5355  originalIdeal(id_Copy(I,r)),
    54   dimensionOfIdeal(dim(originalIdeal,originalRing)),
     56  expectedDimension(dim(originalIdeal,originalRing)),
    5557  linealitySpace(homogeneitySpace(originalIdeal,originalRing)),
    5658  startingRing(rCopy(originalRing)),
     
    6365  extraReductionAlgorithm(noExtraReduction)
    6466{
    65   assume(rField_is_Q(r));
     67  assume(rField_is_Q(r) || rField_is_Zp(r));
     68  if (!completelyHomogeneous)
     69  {
     70    weightAdjustingAlgorithm1 = valued_adjustWeightForHomogeneity;
     71    weightAdjustingAlgorithm2 = valued_adjustWeightUnderHomogeneity;
     72  }
     73  if (!completeSpace)
     74    onlyLowerHalfSpace = true;
    6675}
    6776
     
    101110
    102111  rComplete(s);
     112  rTest(s);
    103113  return s;
    104114}
     
    111121    ring s = rCopy0(r,FALSE,TRUE);
    112122    rComplete(s);
     123    rTest(s);
    113124    return s;
    114125  }
     
    123134  originalRing(rCopy(s)),
    124135  originalIdeal(id_Copy(J,s)),
    125   dimensionOfIdeal(dim(originalIdeal,originalRing)),
    126   linealitySpace(homogeneitySpace(originalIdeal,originalRing)),
    127   startingRing(rCopy(originalRing)),
    128   startingIdeal(id_Copy(originalIdeal,originalRing)),
    129   uniformizingParameter(NULL),
    130   shortcutRing(rCopy(originalRing)),
    131   onlyLowerHalfSpace(false),
    132   weightAdjustingAlgorithm1(nonvalued_adjustWeightForHomogeneity),
    133   weightAdjustingAlgorithm2(nonvalued_adjustWeightUnderHomogeneity),
    134   extraReductionAlgorithm(noExtraReduction)
     136  expectedDimension(dim(originalIdeal,originalRing)+1),
     137  linealitySpace(gfan::ZCone()), // to come, see below
     138  startingRing(NULL),            // to come, see below
     139  startingIdeal(NULL),           // to come, see below
     140  uniformizingParameter(NULL),   // to come, see below
     141  shortcutRing(NULL),            // to come, see below
     142  onlyLowerHalfSpace(true),
     143  weightAdjustingAlgorithm1(valued_adjustWeightForHomogeneity),
     144  weightAdjustingAlgorithm2(valued_adjustWeightUnderHomogeneity),
     145  extraReductionAlgorithm(ppreduceInitially)
    135146{
    136147  /* assume that the ground field of the originalRing is Q */
     
    164175  omFreeSize(shiftByOne,(n+1)*sizeof(int));
    165176
     177  linealitySpace = homogeneitySpace(startingIdeal,startingRing);
     178
    166179  /* construct the shorcut ring */
    167180  shortcutRing = rCopy0(startingRing);
     
    169182  shortcutRing->cf = nInitChar(n_Zp,(void*)(long)IsPrime(n_Int(uniformizingParameter,startingRing->cf)));
    170183  rComplete(shortcutRing);
    171 
    172   /* compute the dimension of the ideal in the original ring */
    173   dimensionOfIdeal = dim(J,s);
    174 
    175   /* set the flag that convex computations only occur in the lower half space to true */
    176   onlyLowerHalfSpace = true;
    177 
    178   /* set the function pointers to the appropiate functions */
    179   weightAdjustingAlgorithm1 = valued_adjustWeightForHomogeneity;
    180   weightAdjustingAlgorithm2 = valued_adjustWeightUnderHomogeneity;
    181   extraReductionAlgorithm = ppreduceInitially;
     184  rTest(shortcutRing);
    182185}
    183186
    184187tropicalStrategy::tropicalStrategy(const tropicalStrategy& currentStrategy):
    185188  originalRing(rCopy(currentStrategy.getOriginalRing())),
     189  originalIdeal(id_Copy(currentStrategy.getOriginalIdeal(),currentStrategy.getOriginalRing())),
     190  expectedDimension(currentStrategy.getExpectedDimension()),
     191  linealitySpace(currentStrategy.getHomogeneitySpace()),
    186192  startingRing(rCopy(currentStrategy.getStartingRing())),
     193  startingIdeal(id_Copy(currentStrategy.getStartingIdeal(),currentStrategy.getStartingRing())),
    187194  uniformizingParameter(n_Copy(currentStrategy.getUniformizingParameter(),startingRing->cf)),
    188   startingIdeal(id_Copy(currentStrategy.getStartingIdeal(),startingRing)),
    189   dimensionOfIdeal(currentStrategy.getDimensionOfIdeal()),
     195  shortcutRing(rCopy(currentStrategy.getShortcutRing())),
    190196  onlyLowerHalfSpace(currentStrategy.restrictToLowerHalfSpace()),
    191197  weightAdjustingAlgorithm1(currentStrategy.weightAdjustingAlgorithm1),
     
    193199  extraReductionAlgorithm(currentStrategy.extraReductionAlgorithm)
    194200{
     201  if (originalRing) rTest(originalRing);
     202  if (originalIdeal) id_Test(originalIdeal,originalRing);
    195203  if (startingRing) rTest(startingRing);
    196204  if (startingIdeal) id_Test(startingIdeal,startingRing);
     205  if (uniformizingParameter) n_Test(uniformizingParameter,startingRing->cf);
     206  if (shortcutRing) rTest(shortcutRing);
    197207}
    198208
    199209tropicalStrategy::~tropicalStrategy()
    200210{
     211  if (originalRing) rTest(originalRing);
     212  if (originalIdeal) id_Test(originalIdeal,originalRing);
    201213  if (startingRing) rTest(startingRing);
    202214  if (startingIdeal) id_Test(startingIdeal,startingRing);
    203 
     215  if (uniformizingParameter) n_Test(uniformizingParameter,startingRing->cf);
     216  if (shortcutRing) rTest(shortcutRing);
     217
     218  id_Delete(&originalIdeal,originalRing);
     219  rDelete(originalRing);
    204220  id_Delete(&startingIdeal,startingRing);
    205221  n_Delete(&uniformizingParameter,startingRing->cf);
    206   rDelete(originalRing);
    207222  rDelete(startingRing);
     223  rDelete(shortcutRing);
    208224}
    209225
     
    211227{
    212228  originalRing = rCopy(currentStrategy.getOriginalRing());
     229  originalIdeal = id_Copy(currentStrategy.getOriginalIdeal(),currentStrategy.getOriginalRing());
     230  expectedDimension = currentStrategy.getExpectedDimension();
    213231  startingRing = rCopy(currentStrategy.getStartingRing());
     232  startingIdeal = id_Copy(currentStrategy.getStartingIdeal(),currentStrategy.getStartingRing());
    214233  uniformizingParameter = n_Copy(currentStrategy.getUniformizingParameter(),startingRing->cf);
    215   startingIdeal = id_Copy(currentStrategy.getStartingIdeal(),startingRing);
    216   dimensionOfIdeal = currentStrategy.getDimensionOfIdeal();
     234  shortcutRing = rCopy(currentStrategy.getShortcutRing());
    217235  onlyLowerHalfSpace = currentStrategy.restrictToLowerHalfSpace();
    218236  weightAdjustingAlgorithm1 = currentStrategy.weightAdjustingAlgorithm1;
     
    220238  extraReductionAlgorithm = currentStrategy.extraReductionAlgorithm;
    221239
     240  if (originalRing) rTest(originalRing);
     241  if (originalIdeal) id_Test(originalIdeal,originalRing);
    222242  if (startingRing) rTest(startingRing);
    223243  if (startingIdeal) id_Test(startingIdeal,startingRing);
     244  if (uniformizingParameter) n_Test(uniformizingParameter,startingRing->cf);
     245  if (shortcutRing) rTest(shortcutRing);
    224246
    225247  return *this;
  • Singular/dyn_modules/gfanlib/tropicalStrategy.h

    r78abc7 reacb781  
    55#include <gfanlib/gfanlib_zcone.h>
    66#include <libpolys/polys/simpleideals.h>
     7#include <kernel/ideals.h> // for idSize
    78#include <set>
     9#include <callgfanlib_conversion.h>
     10#include <containsMonomial.h>
     11#include <flip.h>
     12#include <initial.h>
    813
    914/** \file
     
    3338  ideal originalIdeal;
    3439  /**
    35    * dimension of the input ideal
    36    */
    37   int dimensionOfIdeal;
     40   * the expected Dimension of the polyhedral output,
     41   * i.e. the dimension of the ideal if trivial valuation
     42   * or the dimension of the ideal plus one if non-trivial valuation
     43   * (as the output is supposed to be intersected with a hyperplane)
     44   */
     45  int expectedDimension;
    3846  /**
    3947   * the homogeneity space of the Grobner fan
     
    8795   * Constructor for the trivial valuation case
    8896   */
    89   tropicalStrategy(const ideal I, const ring r);
     97  tropicalStrategy(const ideal I, const ring r, const bool completelyHomogeneous=true, const bool completeSpace=true);
    9098  /**
    9199   * Constructor for the non-trivial valuation case
     
    106114  tropicalStrategy& operator=(const tropicalStrategy& currentStrategy);
    107115
     116  bool isConstantCoefficientCase() const
     117  {
     118    bool b = (uniformizingParameter==NULL);
     119    return b;
     120  }
    108121
    109122  /**
     
    117130
    118131  /**
     132   * returns the input ideal over the field with valuation
     133   */
     134  ideal getOriginalIdeal() const
     135  {
     136    if (originalIdeal) id_Test(originalIdeal,originalRing);
     137    return originalIdeal;
     138  }
     139
     140  /**
    119141   * returns the polynomial ring over the valuation ring
    120142   */
     
    130152  ideal getStartingIdeal() const
    131153  {
    132     id_Test(startingIdeal,startingRing);
     154    if (startingIdeal) id_Test(startingIdeal,startingRing);
    133155    return startingIdeal;
    134156  }
    135157
    136158  /**
    137    * returns the dimension of the input ideal
    138    */
    139   int getDimensionOfIdeal() const
    140   {
    141     return dimensionOfIdeal;
     159   * returns the expected Dimension of the polyhedral output
     160   */
     161  int getExpectedDimension() const
     162  {
     163    return expectedDimension;
    142164  }
    143165
     
    147169  number getUniformizingParameter() const
    148170  {
     171    if (uniformizingParameter) n_Test(uniformizingParameter,startingRing->cf);
    149172    return uniformizingParameter;
     173  }
     174
     175  ring getShortcutRing() const
     176  {
     177    rTest(shortcutRing);
     178    return shortcutRing;
    150179  }
    151180
     
    198227   * the inequalities and equations of the Groebner cone can be read off.
    199228   */
    200   bool reduce(ideal I, ring r) const
     229  bool reduce(ideal I, const ring r) const
    201230  {
    202231    rTest(r);  id_Test(I,r);
     
    212241   * returns false otherwise.
    213242   **/
    214   bool containsMonomial(ideal I, ring r) const
    215   {
    216     ring rFinite = rCopy0(r);
    217     nKillChar(rFinite.coeffs());
    218     rFinite->cf =
     243  poly checkInitialIdealForMonomial(const ideal I, const ring r, const gfan::ZVector w) const
     244  {
     245    gfan::ZVector v = adjustWeightForHomogeneity(w);
     246    if (isConstantCoefficientCase())
     247    {
     248      ring rShortcut = rCopy0(r);
     249      bool overflow;
     250      /**
     251       * prepend extra weight vector for homogeneity
     252       */
     253      int* order = rShortcut->order;
     254      int* block0 = rShortcut->block0;
     255      int* block1 = rShortcut->block1;
     256      int** wvhdl = rShortcut->wvhdl;
     257      int h = rBlocks(r); int n = rVar(r);
     258      rShortcut->order = (int*) omAlloc0((h+1)*sizeof(int));
     259      rShortcut->block0 = (int*) omAlloc0((h+1)*sizeof(int));
     260      rShortcut->block1 = (int*) omAlloc0((h+1)*sizeof(int));
     261      rShortcut->wvhdl = (int**) omAlloc0((h+1)*sizeof(int*));
     262      rShortcut->order[0] = ringorder_a;
     263      rShortcut->block0[0] = 1;
     264      rShortcut->block1[0] = n;
     265      rShortcut->wvhdl[0] = ZVectorToIntStar(v,overflow);
     266      for (int i=1; i<=h; i++)
     267      {
     268        rShortcut->order[i] = order[i-1];
     269        rShortcut->block0[i] = block0[i-1];
     270        rShortcut->block1[i] = block1[i-1];
     271        rShortcut->wvhdl[i] = wvhdl[i-1];
     272      }
     273      rComplete(rShortcut);
     274      rTest(rShortcut);
     275      omFree(order);
     276      omFree(block0);
     277      omFree(block1);
     278      omFree(wvhdl);
     279
     280      ideal inI = initial(I,r,w);
     281      int k = idSize(inI);
     282      ideal inIShortcut = idInit(k);
     283      nMapFunc identity = n_SetMap(r->cf,rShortcut->cf);
     284      for (int i=0; i<k; i++)
     285        inIShortcut->m[i] = p_PermPoly(inI->m[i],NULL,r,rShortcut,identity,NULL,0);
     286
     287      poly p = checkForMonomialViaSuddenSaturation(inIShortcut,rShortcut);
     288      poly monomial = NULL;
     289      if (p!=NULL)
     290      {
     291        monomial=p_One(r);
     292        for (int i=1; i<n; i++)
     293          p_SetExp(monomial,i,p_GetExp(p,i,rShortcut),r);
     294        p_Delete(&p,rShortcut);
     295      }
     296      id_Delete(&inI,r);
     297      id_Delete(&inIShortcut,rShortcut);
     298      rDelete(rShortcut);
     299      return monomial;
     300    }
     301    else
     302    {
     303      ring rShortcut = rCopy0(r);
     304      bool overflow;
     305      /**
     306       * prepend extra weight vector for homogeneity
     307       */
     308      int* order = rShortcut->order;
     309      int* block0 = rShortcut->block0;
     310      int* block1 = rShortcut->block1;
     311      int** wvhdl = rShortcut->wvhdl;
     312      int h = rBlocks(r); int n = rVar(r);
     313      rShortcut->order = (int*) omAlloc0((h+1)*sizeof(int));
     314      rShortcut->block0 = (int*) omAlloc0((h+1)*sizeof(int));
     315      rShortcut->block1 = (int*) omAlloc0((h+1)*sizeof(int));
     316      rShortcut->wvhdl = (int**) omAlloc0((h+1)*sizeof(int*));
     317      rShortcut->order[0] = ringorder_a;
     318      rShortcut->block0[0] = 1;
     319      rShortcut->block1[0] = n;
     320      rShortcut->wvhdl[0] = ZVectorToIntStar(v,overflow);
     321      for (int i=1; i<=h; i++)
     322      {
     323        rShortcut->order[i] = order[i-1];
     324        rShortcut->block0[i] = block0[i-1];
     325        rShortcut->block1[i] = block1[i-1];
     326        rShortcut->wvhdl[i] = wvhdl[i-1];
     327      }
     328      omFree(order);
     329      omFree(block0);
     330      omFree(block1);
     331      omFree(wvhdl);
     332      /**
     333       * change ground domain into finite field
     334       */
     335      nKillChar(rShortcut->cf);
     336      rShortcut->cf = nCopyCoeff(shortcutRing->cf);
     337      rComplete(rShortcut);
     338      rTest(rShortcut);
     339
     340      ideal inI = initial(I,r,w);
     341      int k = idSize(inI);
     342      ideal inIShortcut = idInit(k);
     343      nMapFunc takingResidues = n_SetMap(r->cf,rShortcut->cf);
     344      for (int i=0; i<k; i++)
     345        inIShortcut->m[i] = p_PermPoly(inI->m[i],NULL,r,rShortcut,takingResidues,NULL,0);
     346
     347      idSkipZeroes(inIShortcut);
     348      poly p = checkForMonomialViaSuddenSaturation(inIShortcut,rShortcut);
     349      poly monomial = NULL;
     350      if (p!=NULL)
     351      {
     352        monomial=p_One(r);
     353        for (int i=1; i<n; i++)
     354          p_SetExp(monomial,i,p_GetExp(p,i,rShortcut),r);
     355        p_Delete(&p,rShortcut);
     356      }
     357      id_Delete(&inI,r);
     358      id_Delete(&inIShortcut,rShortcut);
     359      rDelete(rShortcut);
     360      return monomial;
     361    }
     362  }
     363  std::pair<ideal,ring> flip(const ideal I, const ring r,
     364                             const gfan::ZVector interiorPoint,
     365                             const gfan::ZVector facetNormal) const
     366  {
     367    gfan::ZVector adjustedInteriorPoint = adjustWeightForHomogeneity(interiorPoint);
     368    gfan::ZVector adjustedFacetNormal = adjustWeightUnderHomogeneity(facetNormal,adjustedInteriorPoint);
     369    return flip0(I,r,interiorPoint,facetNormal,adjustedInteriorPoint,adjustedFacetNormal);
    219370  }
    220371};
  • Singular/dyn_modules/gfanlib/tropicalVariety.cc

    r78abc7 reacb781  
    3737    {
    3838      tropicalStrategy currentStrategy(I,currRing);
     39      setOptionRedSB();
    3940      gfan::ZFan* tropI = tropicalVariety(currentStrategy);
     41      undoSetOptionRedSB();
    4042      res->rtyp = fanID;
    4143      res->data = (char*) tropI;
     
    4648      number p = (number) v->CopyD();
    4749      tropicalStrategy currentStrategy(I,p,currRing);
    48       setOptionRedSB();
    4950      gfan::ZFan* tropI = tropicalVariety(currentStrategy);
    50       undoSetOptionRedSB();
    5151      res->rtyp = fanID;
    5252      res->data = (char*) tropI;
  • Singular/dyn_modules/gfanlib/tropicalVarietyOfIdeals.cc

    r78abc7 reacb781  
    77  ideal I = currentStrategy.getStartingIdeal();
    88  ring r = currentStrategy.getStartingRing();
    9   groebnerCone startingCone = tropicalStartingCone(I,r,currentStrategy);
     9  groebnerCone startingCone = tropicalStartingCone(currentStrategy);
    1010  groebnerCones tropicalVariety = tropicalTraversal(startingCone);
    1111  return toFanStar(tropicalVariety);
  • Singular/dyn_modules/gfanlib/witness.cc

    r78abc7 reacb781  
    1717{
    1818  ring origin = currRing;
    19   rComplete(r);
    2019  if (origin != r) rChangeCurrRing(r);
    2120  ideal F = idInit(1); F->m[0]=f;
    22   ideal m = idLift(G,F,NULL,FALSE,FALSE);
     21  ideal m = idLift(G,F);
     22  // ideal m = idLift(G,F,NULL,FALSE,TRUE);
    2323  F->m[0]=NULL; id_Delete(&F, currRing);
    2424  matrix Q = id_Module2formatedMatrix(m,IDELEMS(G),1,currRing);
     
    5353poly witness(const poly m, const ideal I, const ideal inI, const ring r)
    5454{
     55  assume(idSize(I)==idSize(inI));
    5556  matrix Q = divisionDiscardingRemainder(m,inI,r);
    5657
Note: See TracChangeset for help on using the changeset viewer.