Changeset c96414 in git


Ignore:
Timestamp:
Nov 21, 2014, 3:23:43 PM (9 years ago)
Author:
Yue Ren <ren@…>
Branches:
(u'spielwiese', 'a719bcf0b8dbc648b128303a49777a094b57592c')
Children:
e4c54031d2902cbf09cf0ab7914602044e166cc0
Parents:
4664b33f793e7e511d9722557720dd523ec89856
git-author:
Yue Ren <ren@mathematik.uni-kl.de>2014-11-21 15:23:43+01:00
git-committer:
Yue Ren <ren@mathematik.uni-kl.de>2015-02-06 13:47:05+01:00
Message:
chg: status update 21.11.
Location:
Singular/dyn_modules/gfanlib
Files:
13 edited

Legend:

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

    r4664b3 rc96414  
    309309  leftv u=args;
    310310  if ((u != NULL) && (u->Typ() == fanID))
    311     {
    312       gfan::ZFan* zf = (gfan::ZFan*)u->Data();
    313       int d = zf->getAmbientDimension();
    314       int n = 0;
    315 
    316       for (int i=0; i<=d; i++)
    317         n = n + zf->numberOfConesOfDimension(i,0,0);
    318 
    319       res->rtyp = INT_CMD;
    320       res->data = (void*) (long) n;
    321       return FALSE;
    322     }
    323   else
    324     {
    325       WerrorS("check_compatibility: unexpected parameters");
    326       return TRUE;
    327     }
     311  {
     312    gfan::ZFan* zf = (gfan::ZFan*)u->Data();
     313    int d = zf->getAmbientDimension();
     314    int n = 0;
     315
     316    for (int i=0; i<=d; i++)
     317      n = n + zf->numberOfConesOfDimension(i,0,0);
     318
     319    res->rtyp = INT_CMD;
     320    res->data = (void*) (long) n;
     321    return FALSE;
     322  }
     323  WerrorS("ncones: unexpected parameters");
     324  return TRUE;
    328325}
    329326
     
    332329  leftv u=args;
    333330  if ((u != NULL) && (u->Typ() == fanID))
    334     {
    335       gfan::ZFan* zf = (gfan::ZFan*)u->Data();
    336 
    337       int n = 0;
    338       for (int d=0; d<=zf->getAmbientDimension(); d++)
    339         { n = n + zf->numberOfConesOfDimension(d,0,1); }
    340 
    341       res->rtyp = INT_CMD;
    342       res->data = (void*) (long) n;
    343       return FALSE;
    344     }
    345   else
    346     {
    347       WerrorS("nmaxcones: unexpected parameters");
    348       return TRUE;
    349     }
    350 }
    351 
    352 bool isCompatible(gfan::ZFan* zf, gfan::ZCone* zc)
     331  {
     332    gfan::ZFan* zf = (gfan::ZFan*)u->Data();
     333
     334    int n = 0;
     335    for (int d=0; d<=zf->getAmbientDimension(); d++)
     336      n = n + zf->numberOfConesOfDimension(d,0,1);
     337
     338    res->rtyp = INT_CMD;
     339    res->data = (void*) (long) n;
     340    return FALSE;
     341  }
     342  WerrorS("nmaxcones: unexpected parameters");
     343  return TRUE;
     344}
     345
     346bool isCompatible(const gfan::ZFan* zf, const gfan::ZCone* zc)
    353347{
    354348  bool b = (zf->getAmbientDimension() == zc->ambientDimension());
     
    466460    }
    467461  }
    468   // if ((u != NULL) && (u->Typ() == coneID))
    469   // {
    470   //   leftv v=u->next;
    471   //   if ((v != NULL) && (v->Typ() == coneID))
    472   //   {
    473   //     gfan::ZCone* zc = (gfan::ZCone*)u->Data();
    474   //     gfan::ZCone* zd = (gfan::ZCone*)v->Data();
    475   //     res->rtyp = INT_CMD;
    476   //     res->data = (void*) (int) hasFace(zc,zd);
    477   //     return FALSE;
    478   //   }
    479   // }
    480462  WerrorS("containsInCollection: unexpected parameters");
    481463  return TRUE;
    482464}
    483465
    484 // BOOLEAN coneContaining(leftv res, leftv args)
    485 // {
    486 //   leftv u=args;
    487 //   if ((u != NULL) && (u->Typ() == fanID))
    488 //   {
    489 //     if ((v != NULL) && (v->Typ() == BIGINTMAT_CMD))
    490 //     {
    491 //       gfan::ZFan* zf = (gfan::ZFan*)u->Data();
    492 //       bigintmat* vec = (bigintmat*)v->Data();
    493 //     }
    494 //   }
    495 //   WerrorS("coneContaining: unexpected parameters");
    496 //   return TRUE;
    497 // }
     466BOOLEAN coneContaining(leftv res, leftv args)
     467{
     468  leftv u=args;
     469  if ((u != NULL) && (u->Typ() == fanID))
     470  {
     471    leftv v=u->next;
     472    if ((v != NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD)))
     473    {
     474      gfan::ZFan* zf = (gfan::ZFan*)u->Data();
     475      gfan::ZVector* point;
     476      if (v->Typ() == INTVEC_CMD)
     477      {
     478        intvec* w0 = (intvec*) v->Data();
     479        bigintmat* w1 = iv2bim(w0,coeffs_BIGINT);
     480        w1->inpTranspose();
     481        point = bigintmatToZVector(*w1);
     482        delete w1;
     483      }
     484      else
     485      {
     486        bigintmat* w1 = (bigintmat*) v->Data();
     487        point = bigintmatToZVector(*w1);
     488      }
     489      lists L = (lists)omAllocBin(slists_bin);
     490      res->rtyp = LIST_CMD;
     491      res->data = (void*) L;
     492      delete point;
     493      return FALSE;
     494    }
     495  }
     496  WerrorS("coneContaining: unexpected parameters");
     497  return TRUE;
     498}
    498499
    499500BOOLEAN removeCone(leftv res, leftv args)
  • Singular/dyn_modules/gfanlib/bbfan.h

    r4664b3 rc96414  
    1414void bbfan_setup(SModulFunctions* p);
    1515
     16bool isCompatible(const gfan::ZFan* zf, const gfan::ZCone* zc);
     17
    1618int getAmbientDimension(gfan::ZFan* zf);
    1719int getCodimension(gfan::ZFan* zf);
  • Singular/dyn_modules/gfanlib/initial.cc

    r4664b3 rc96414  
    194194  return;
    195195}
     196
    196197
    197198/***
     
    341342//   return inI;
    342343// }
    343 
    344 // BOOLEAN initial(leftv res, leftv args)
    345 // {
    346 //   leftv u = args;
    347 //   if ((u != NULL) && (u->Typ() == POLY_CMD) && (u->next == NULL))
    348 //   {
    349 //     poly p = (poly) u->Data();
    350 //     res->rtyp = POLY_CMD;
    351 //     res->data = (void*) initial(p, currRing);
    352 //     return FALSE;
    353 //   }
    354 //   if ((u != NULL) && (u->Typ() == IDEAL_CMD) && (u->next == NULL))
    355 //   {
    356 //     ideal I = (ideal) u->Data();
    357 //     res->rtyp = IDEAL_CMD;
    358 //     res->data = (void*) initial(I, currRing);
    359 //     return FALSE;
    360 //   }
    361 //   WerrorS("initial: unexpected parameters");
    362 //   return TRUE;
    363 // }
  • Singular/dyn_modules/gfanlib/ppinitialReduction.cc

    r4664b3 rc96414  
    1 #include <kernel/polys.h>
     1#include <libpolys/polys/monomials/p_polys.h>
    22#include <Singular/ipid.h>
    33
    4 #include <libpolys/polys/monomials/p_polys.h>
    54#include <singularWishlist.h>
    6 #include <tropicalStrategy.h>
     5#include <ppinitialReduction.h>
    76
    87#include <map>
    98#include <set>
    10 #include <iostream>
    119#include <exception>
    1210
    13 #include <ppinitialReduction.h>
    14 
     11
     12#ifndef NDEBUG
    1513bool isOrderingLocalInT(const ring r)
    1614{
     
    2321  p_Delete(&t,r);
    2422  return (s==1);
     23}
     24#endif
     25
     26void divideByCommonGcd(poly &g, const ring r)
     27{
     28  number commonGcd = n_Copy(p_GetCoeff(g,r),r->cf);
     29  for (poly gCache=pNext(g); gCache; pIter(gCache))
     30  {
     31    number commonGcdCache = n_Gcd(commonGcd,p_GetCoeff(gCache,r),r->cf);
     32    n_Delete(&commonGcd,r->cf);
     33    commonGcd = commonGcdCache;
     34    if (n_IsOne(commonGcd,r->cf))
     35    {
     36      n_Delete(&commonGcd,r->cf);
     37      return;
     38    }
     39  }
     40  for (poly gCache=g; gCache; pIter(gCache))
     41  {
     42    number oldCoeff = p_GetCoeff(gCache,r);
     43    number newCoeff = n_Div(oldCoeff,commonGcd,r->cf);
     44    p_SetCoeff(gCache,newCoeff,r);
     45  }
     46  p_Test(g,r);
     47  n_Delete(&commonGcd,r->cf);
     48  return;
    2549}
    2650
     
    93117  }
    94118  p_Test(g,r);
     119  divideByCommonGcd(g,r);
    95120  return;
    96121}
     
    146171  return;
    147172}
     173
     174#ifndef NDEBUG
     175BOOLEAN ptNormalize(leftv res, leftv args)
     176{
     177  leftv u = args;
     178  if ((u != NULL) && (u->Typ() == IDEAL_CMD))
     179  {
     180    leftv v = u->next;
     181    if ((v!=NULL) && (v->Typ()==NUMBER_CMD))
     182    {
     183      omUpdateInfo();
     184      Print("usedBytesBefore=%ld\n",om_Info.UsedBytes);
     185      ideal I = (ideal) u->CopyD();
     186      number p = (number) v->CopyD();
     187      ptNormalize(I,p,currRing);
     188      n_Delete(&p,currRing->cf);
     189      res->rtyp = IDEAL_CMD;
     190      res->data = (char*) I;
     191      return FALSE;
     192    }
     193  }
     194  return TRUE;
     195}
     196#endif //NDEBUG
    148197
    149198#ifndef NDEBUG
     
    172221#endif //NDEBUG
    173222
    174 void pReduce0(ideal &I, const number p, const ring r)
     223void pReduce(ideal &I, const number p, const ring r)
    175224{
    176225  int k = idSize(I);
     
    188237
    189238
    190 /***
     239/**
    191240 * reduces h initially with respect to g,
    192241 * returns false if h was initially reduced in the first place,
    193242 * returns true if reductions have taken place.
    194243 * assumes that h and g are in pReduced form and homogeneous in x of the same degree
    195  **/
     244 */
    196245bool ppreduceInitially(poly* hStar, const poly g, const ring r)
    197246{
     
    377426  for (int k=j+1; k<n; k++)
    378427    if (ppreduceInitially(&I->m[k], I->m[j], r))
     428    {
    379429      pReduce(I->m[k],p,r);
     430      for (int l=j+1; l<k; l++)
     431        if (ppreduceInitially(&I->m[k], I->m[l], r))
     432          pReduce(I->m[k],p,r);
     433    }
    380434
    381435  /***
     
    387441      if (ppreduceInitially(&I->m[i], I->m[k], r))
    388442        pReduce(I->m[i],p,r);
    389   for (int k=j+1; k<n; k++)
    390     if (ppreduceInitially(&I->m[j], I->m[k], r))
    391       pReduce(I->m[j],p,r);
     443  for (int k=j; k<n-1; k++)
     444    for (int l=k+1; l<n; l++)
     445      if (ppreduceInitially(&I->m[k], I->m[l], r))
     446        pReduce(I->m[j],p,r);
    392447
    393448  /***
     
    533588   *   T is sorted by the ordering on the temrs the pairs correspond to.
    534589   **/
    535   int m=idSize(H),n=0;
     590  int m=idSize(H);
    536591  ideal I = idInit(m);
    537592  std::vector<mark> T;
     
    551606  {
    552607    sortMarks(I,r,T);
    553     std::cout << "T.size()=" << T.size() << std::endl;
    554     std::cout << "T[0] = (" << T[0].first << "," << T[0].second << ")" << std::endl;
    555608    int i=0; for (; i<k; i++)
    556609      if (p_LeadmonomDivisibleBy(G->m[i],getTerm(I,T[0]),r)) break;
    557610    if (i<k)
    558611    {
    559       if (T[0].first==10 && T[0].second==3)
    560       {
    561         std::cout << "check this" << std::endl;
    562       }
    563       std::cout << "reducing" << std::endl;
    564612      poly g = p_One(r); poly h0 = getTerm(I,T[0]);
    565613      assume(h0!=NULL);
     
    615663        G = (ideal) w->CopyD();
    616664        (void) ppreduceInitially(H,p,G,currRing);
    617         id_Delete(&H,currRing);
    618         id_Delete(&G,currRing);
    619         n_Delete(&p,currRing->cf);
    620         omUpdateInfo();
    621         Print("usedBytesAfter=%ld\n",om_Info.UsedBytes);
    622         H = (ideal) u->CopyD();
    623         p = (number) v->CopyD();
    624         G = (ideal) w->CopyD();
    625         (void) ppreduceInitially(H,p,G,currRing);
    626665        n_Delete(&p,currRing->cf);
    627666        id_Delete(&G,currRing);
     
    635674}
    636675#endif //NDEBUG
    637 
    638 
    639 static std::vector<int> synchronize(const ideal I, const ideal Hi)
    640 {
    641   int k = idSize(I);
    642   int l = idSize(Hi);
    643   std::vector<int> synch(k);
    644   int j;
    645   for (int i=0; i<k; i++)
    646   {
    647     for (j=0; j<l; j++)
    648     {
    649       if (I->m[i]==Hi->m[j])
    650       {
    651         synch[i] = j;
    652         break;
    653       }
    654     }
    655     if (j==l)
    656       synch[i] = -1;
    657   }
    658   return synch;
    659 }
    660 
    661 static void synchronize(ideal I, const ideal Hi, const std::vector<int> synch)
    662 {
    663   for (unsigned i=0; i<synch.size(); i++)
    664     if (synch[i]>=0)
    665     {
    666       I->m[i] = Hi->m[synch[i]];
    667       std::cout << i << " -> " << synch[i] << std::endl;
    668     }
    669 }
    670 
    671 void z_Write(number p, ring r)
    672 {
    673   poly g = p_One(r);
    674   p_SetCoeff(g,p,r);
    675   p_Write(g,r);
    676   return;
    677 }
    678676
    679677/**
     
    708706
    709707  std::map<long,ideal>::iterator it=H.begin();
     708  ideal Hi = it->second;
     709  idShallowDelete(&Hi);
    710710  it++;
    711   ideal Hi = it->second;
     711  Hi = it->second;
    712712
    713713  /***
     
    715715   *  and all lower components
    716716   **/
    717   // std::vector<int> synch = synchronize(I,Hi);
    718717  if (ppreduceInitially(Hi,p,r)) return true;
    719   // synchronize(I,Hi,synch);
    720718  id_Test(Hi,r);
    721719  id_Test(I,r);
     
    763761    }
    764762    m += l; IDELEMS(GG) = m; GG->m = &G->m[n-m];
    765     // std::vector<int> synch = synchronize(I,it->second);
    766763    id_Test(it->second,r);
    767764    id_Test(GG,r);
    768     if (ppreduceInitially(it->second,p,r)) return true;
    769765    if (ppreduceInitially(it->second,p,GG,r)) return true;
    770766    id_Test(it->second,r);
    771767    id_Test(GG,r);
    772     // synchronize(I,it->second,synch);
    773768    idShallowDelete(&Hi); Hi = it->second;
    774769  }
     
    776771
    777772  ptNormalize(I,p,r);
    778   omFreeBin((ADDRESS)GG, sip_sideal_bin); idShallowDelete(&G);
     773  omFreeBin((ADDRESS)GG, sip_sideal_bin);
     774  idShallowDelete(&G);
    779775  return false;
    780776}
    781777
    782778
    783 // #ifndef NDEBUG
    784 // BOOLEAN ppreduceInitially4(leftv res, leftv args)
    785 // {
    786 //   leftv u = args;
    787 //   if ((u != NULL) && (u->Typ() == IDEAL_CMD))
    788 //   {
    789 //     ideal I;
    790 //     omUpdateInfo();
    791 //     Print("usedBytesBefore=%ld\n",om_Info.UsedBytes);
    792 //     I = (ideal) u->CopyD();
    793 //     (void) ppreduceInitially(I,currRing);
    794 //     id_Delete(&I,currRing);
    795 //     omUpdateInfo();
    796 //     Print("usedBytesAfter=%ld\n",om_Info.UsedBytes);
    797 //     I = (ideal) u->CopyD();
    798 //     (void) ppreduceInitially(I,currRing);
    799 //     res->rtyp = IDEAL_CMD;
    800 //     res->data = (char*) I;
    801 //     return FALSE;
    802 //   }
    803 //   return TRUE;
    804 // }
    805 // #endif
     779#ifndef NDEBUG
     780BOOLEAN reduceInitiallyDebug(leftv res, leftv args)
     781{
     782  leftv u = args;
     783  if ((u != NULL) && (u->Typ() == IDEAL_CMD))
     784  {
     785    leftv v = u->next;
     786    if ((v != NULL) && (v->Typ() == NUMBER_CMD))
     787    {
     788      omUpdateInfo();
     789      Print("usedBytesBefore=%ld\n",om_Info.UsedBytes);
     790      ideal I = (ideal) u->CopyD();
     791      number p = (number) v->Data();
     792      (void) ppreduceInitially(I,currRing,p);
     793      res->rtyp = IDEAL_CMD;
     794      res->data = (char*) I;
     795      return FALSE;
     796    }
     797  }
     798  return TRUE;
     799}
     800#endif
    806801
    807802
  • Singular/dyn_modules/gfanlib/ppinitialReduction.h

    r4664b3 rc96414  
    55#include <tropicalStrategy.h>
    66
    7 #ifndef NDEBUG
    8 BOOLEAN pppReduce(leftv res, leftv args);
    9 BOOLEAN ppreduceInitially0(leftv res, leftv args);
    10 BOOLEAN ppreduceInitially1(leftv res, leftv args);
    11 BOOLEAN ppreduceInitially2(leftv res, leftv args);
    12 BOOLEAN ppreduceInitially3(leftv res, leftv args);
    13 BOOLEAN ppreduceInitially4(leftv res, leftv args);
    14 #endif
    15 
    167typedef std::pair<int,int> mark;
    178typedef std::vector<std::pair<int,int> > marks;
    189
    1910bool isOrderingLocalInT(const ring r);
    20 void pReduce0(ideal &I, const number p, const ring r);
     11void pReduce(ideal &I, const number p, const ring r);
    2112bool ppreduceInitially(ideal I, const ring r, const number p);
    2213BOOLEAN ppreduceInitially(leftv res, leftv args);
    2314
    24 void z_Write(number p, ring r);
     15#ifndef NDEBUG
     16BOOLEAN reduceInitiallyDebug(leftv res, leftv args);
     17BOOLEAN ptNormalize(leftv res, leftv args);
     18BOOLEAN ppreduceInitially3(leftv res, leftv args);
     19#endif
    2520
    2621#endif
  • Singular/dyn_modules/gfanlib/singularWishlist.h

    r4664b3 rc96414  
    33
    44#include <libpolys/polys/monomials/p_polys.h>
     5
     6/* #ifndef NDEBUG */
     7/* void z_Write(number p, ring r) */
     8/* { */
     9/*   poly g = p_One(r); */
     10/*   p_SetCoeff(g,p,r); */
     11/*   p_Write(g,r); */
     12/*   return; */
     13/* } */
     14/* #endif */
    515
    616static inline BOOLEAN _p_LeadmonomDivisibleByNoComp(poly a, poly b, const ring r)
     
    4757}
    4858
     59/**
     60 * p_LmDivisibleBy checks also the divisibility of coefficients
     61 **/
    4962static inline BOOLEAN p_LeadmonomDivisibleBy(poly a, poly b, const ring r)
    5063{
     
    5770}
    5871
     72/**
     73 * id_ShallowDelete deletes the monomials of the polynomials stored inside of it
     74 **/
    5975inline void idShallowDelete (ideal *h)
    6076{
  • Singular/dyn_modules/gfanlib/tropical.cc

    r4664b3 rc96414  
    171171
    172172
     173BOOLEAN initial(leftv res, leftv args)
     174{
     175  leftv u = args;
     176  if ((u != NULL) && (u->Typ() == POLY_CMD) && (u->next == NULL))
     177  {
     178    leftv v = u->next;
     179    if ((v !=NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD)))
     180    {
     181      poly p = (poly) u->Data();
     182      gfan::ZVector* weightVector;
     183      if (v->Typ() == INTVEC_CMD)
     184      {
     185        intvec* w0 = (intvec*) v->Data();
     186        bigintmat* w1 = iv2bim(w0,coeffs_BIGINT);
     187        w1->inpTranspose();
     188        weightVector = bigintmatToZVector(*w1);
     189        delete w1;
     190      }
     191      else
     192      {
     193        bigintmat* w1 = (bigintmat*) v->Data();
     194        weightVector = bigintmatToZVector(*w1);
     195      }
     196      res->rtyp = IDEAL_CMD;
     197      res->data = (void*) initial(p, currRing, *weightVector);
     198      delete weightVector;
     199      return FALSE;
     200    }
     201  }
     202  if ((u != NULL) && (u->Typ() == IDEAL_CMD) && (u->next == NULL))
     203  {
     204    leftv v = u->next;
     205    if ((v !=NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD)))
     206    {
     207      ideal I = (ideal) u->Data();
     208      gfan::ZVector* weightVector;
     209      if (v->Typ() == INTVEC_CMD)
     210      {
     211        intvec* w0 = (intvec*) v->Data();
     212        bigintmat* w1 = iv2bim(w0,coeffs_BIGINT);
     213        w1->inpTranspose();
     214        weightVector = bigintmatToZVector(*w1);
     215        delete w1;
     216      }
     217      else
     218      {
     219        bigintmat* w1 = (bigintmat*) v->Data();
     220        weightVector = bigintmatToZVector(*w1);
     221      }
     222      res->rtyp = POLY_CMD;
     223      res->data = (void*) initial(I, currRing, *weightVector);
     224      delete weightVector;
     225      return FALSE;
     226    }
     227  }
     228  WerrorS("initial: unexpected parameters");
     229  return TRUE;
     230}
     231
     232
    173233void tropical_setup(SModulFunctions* p)
    174234{
    175235  p->iiAddCproc("","groebnerCone",FALSE,groebnerCone);
    176236  p->iiAddCproc("","maximalGroebnerCone",FALSE,maximalGroebnerCone);
    177   // p->iiAddCproc("","initial",FALSE,initial);
     237  p->iiAddCproc("","initial",FALSE,initial);
    178238  // p->iiAddCproc("","tropicalNeighbours",FALSE,tropicalNeighbours);
    179239#ifndef NDEBUG
     
    183243  // p->iiAddCproc("","ppreduceInitially1",FALSE,ppreduceInitially1);
    184244  // p->iiAddCproc("","ppreduceInitially2",FALSE,ppreduceInitially2);
    185   // p->iiAddCproc("","ppreduceInitially3",FALSE,ppreduceInitially3);
     245  p->iiAddCproc("","ptNormalize",FALSE,ptNormalize);
     246  p->iiAddCproc("","ppreduceInitially3",FALSE,ppreduceInitially3);
    186247  // p->iiAddCproc("","ppreduceInitially4",FALSE,ppreduceInitially4);
    187248  // p->iiAddCproc("","ttpReduce",FALSE,ttpReduce);
     
    198259  // p->iiAddCproc("","tropicalCurve0",FALSE,tropicalCurve0);
    199260  // p->iiAddCproc("","tropicalCurve1",FALSE,tropicalCurve1);
     261  p->iiAddCproc("","reduceInitiallyDebug",FALSE,reduceInitiallyDebug);
     262  p->iiAddCproc("","getWitnessDebug",FALSE,getWitnessDebug);
     263  p->iiAddCproc("","getFlipDebug",FALSE,getFlipDebug);
    200264  p->iiAddCproc("","tropicalStartingPoint",FALSE,tropicalStartingPoint);
    201265  p->iiAddCproc("","positiveTropicalStartingPoint",FALSE,positiveTropicalStartingPoint);
  • Singular/dyn_modules/gfanlib/tropicalCurves.cc

    r4664b3 rc96414  
    130130   * and compute the common refinement with its tropical variety.
    131131   * If all initial ideals are monomial free, then we have our tropical curve */
    132   for (std::set<gfan::ZCone>::iterator zc=C.begin(); zc!=C.end(); zc++)
     132  for (std::set<gfan::ZCone>::iterator zc=C.begin(); zc!=C.end();)
    133133  {
    134134    gfan::ZVector w = zc->getRelativeInteriorPoint();
     
    157157      zc = C.begin();
    158158    }
     159    else
     160      zc++;
    159161    id_Delete(&inIs,s);
    160162    id_Delete(&ininIs,s);
  • Singular/dyn_modules/gfanlib/tropicalStrategy.cc

    r4664b3 rc96414  
    335335  nMapFunc identity = n_SetMap(startingRing->cf,r->cf);
    336336  number p = identity(uniformizingParameter,startingRing->cf,r->cf);
    337   pReduce0(I,p,r);
     337  ::pReduce(I,p,r);
    338338  n_Delete(&p,r->cf);
    339339
     
    768768  return false;
    769769}
     770
     771
     772
     773#ifndef NDEBUG
     774tropicalStrategy::tropicalStrategy():
     775  originalRing(NULL),
     776  originalIdeal(NULL),
     777  expectedDimension(NULL),
     778  linealitySpace(gfan::ZCone()), // to come, see below
     779  startingRing(NULL),            // to come, see below
     780  startingIdeal(NULL),           // to come, see below
     781  uniformizingParameter(NULL),   // to come, see below
     782  shortcutRing(NULL),            // to come, see below
     783  onlyLowerHalfSpace(false),
     784  weightAdjustingAlgorithm1(NULL),
     785  weightAdjustingAlgorithm2(NULL),
     786  extraReductionAlgorithm(NULL)
     787{
     788}
     789
     790tropicalStrategy tropicalStrategy::debugStrategy(const ideal startIdeal, number unifParameter, ring startRing)
     791{
     792  tropicalStrategy debug;
     793  debug.originalRing = rCopy(startRing);
     794  debug.originalIdeal = id_Copy(startIdeal,startRing);
     795  debug.startingRing = rCopy(startRing);
     796  debug.startingIdeal = id_Copy(startIdeal,startRing);
     797  debug.uniformizingParameter = n_Copy(unifParameter,startRing->cf);
     798
     799  debug.shortcutRing = rCopy0(startRing);
     800  nKillChar(debug.shortcutRing->cf);
     801  debug.shortcutRing->cf = nInitChar(n_Zp,(void*)(long)IsPrime(n_Int(unifParameter,startRing->cf)));
     802  rComplete(debug.shortcutRing);
     803  rTest(debug.shortcutRing);
     804
     805  debug.onlyLowerHalfSpace = true;
     806  debug.weightAdjustingAlgorithm1 = valued_adjustWeightForHomogeneity;
     807  debug.weightAdjustingAlgorithm2 = valued_adjustWeightUnderHomogeneity;
     808  debug.extraReductionAlgorithm = ppreduceInitially;
     809
     810  return debug;
     811}
     812
     813BOOLEAN getWitnessDebug(leftv res, leftv args)
     814{
     815  leftv u = args;
     816  if ((u!=NULL) && (u->Typ()==IDEAL_CMD))
     817  {
     818    leftv v = u->next;
     819    if ((v!=NULL) && (v->Typ()==IDEAL_CMD))
     820    {
     821      leftv w = v->next;
     822      if ((w!=NULL) && (w->Typ()==IDEAL_CMD))
     823      {
     824        leftv x = w->next;
     825        if ((x!=NULL) && (x->Typ()==NUMBER_CMD))
     826        {
     827          omUpdateInfo();
     828          Print("usedBytesBefore=%ld\n",om_Info.UsedBytes);
     829
     830          ideal inJ = (ideal) u->CopyD();
     831          ideal inI = (ideal) v->CopyD();
     832          ideal I = (ideal) w->CopyD();
     833          number p = (number) x->CopyD();
     834          tropicalStrategy debug = tropicalStrategy::debugStrategy(I,p,currRing);
     835          ideal J = debug.getWitness(inJ,inI,I,currRing);
     836          id_Delete(&inJ,currRing);
     837          id_Delete(&inI,currRing);
     838          id_Delete(&I,currRing);
     839          n_Delete(&p,currRing->cf);
     840          res->rtyp = IDEAL_CMD;
     841          res->data = (char*) J;
     842          return FALSE;
     843        }
     844      }
     845    }
     846  }
     847  return TRUE;
     848}
     849
     850BOOLEAN getFlipDebug(leftv res, leftv args)
     851{
     852  leftv u = args;
     853  if ((u!=NULL) && (u->Typ()==IDEAL_CMD))
     854  {
     855    leftv v = u->next;
     856    if ((v!=NULL) && (v->Typ()==NUMBER_CMD))
     857    {
     858      leftv w = v->next;
     859      if ((w!=NULL) && (w->Typ()==BIGINTMAT_CMD))
     860      {
     861        leftv x = w->next;
     862        if ((x!=NULL) && (x->Typ()==BIGINTMAT_CMD))
     863        {
     864          omUpdateInfo();
     865          Print("usedBytesBefore=%ld\n",om_Info.UsedBytes);
     866
     867          ideal I = (ideal) u->CopyD();
     868          number p = (number) v->CopyD();
     869          bigintmat* interiorPoint0 = (bigintmat*) w->CopyD();
     870          bigintmat* facetNormal0 = (bigintmat*) x->CopyD();
     871          tropicalStrategy debug = tropicalStrategy::debugStrategy(I,p,currRing);
     872
     873          gfan::ZVector* interiorPoint = bigintmatToZVector(interiorPoint0);
     874          gfan::ZVector* facetNormal = bigintmatToZVector(facetNormal0);
     875          std::pair<ideal,ring> Js = debug.getFlip(I,currRing,*interiorPoint,*facetNormal);
     876          ideal J = Js.first;
     877          ring s = Js.second;
     878
     879          id_Delete(&J,s);
     880          rDelete(s);
     881
     882          id_Delete(&I,currRing);
     883          n_Delete(&p,currRing->cf);
     884          delete interiorPoint0;
     885          delete facetNormal0;
     886          delete interiorPoint;
     887          delete facetNormal;
     888
     889          res->rtyp = NONE;
     890          res->data = NULL;
     891          return FALSE;
     892        }
     893      }
     894    }
     895  }
     896  WerrorS("getFlipDebug: unexpected parameters");
     897  return TRUE;
     898}
     899#endif
  • Singular/dyn_modules/gfanlib/tropicalStrategy.h

    r4664b3 rc96414  
    1313#include <witness.h>
    1414
     15#ifndef NDEBUG
     16
     17#include <Singular/ipshell.h> // for isPrime(int i)
     18#include <adjustWeights.h>
     19#include <ppinitialReduction.h>
     20
     21#endif
     22
    1523/** \file
    1624 * implementation of the class tropicalStrategy
     
    109117  void putUniformizingBinomialInFront(ideal I, const ring r, const number q) const;
    110118
    111 
    112119public:
    113120
     
    125132   */
    126133  tropicalStrategy(const tropicalStrategy& currentStrategy);
     134
     135
     136#ifndef NDEBUG
     137  tropicalStrategy();
     138
     139  static tropicalStrategy debugStrategy(const ideal startIdeal, number unifParameter, ring startRing);
     140#endif
     141
    127142  /**
    128143   * destructor
     
    318333int dim(ideal I, ring r);
    319334
     335#ifndef NDEBUG
     336BOOLEAN getWitnessDebug(leftv res, leftv args);
     337BOOLEAN getFlipDebug(leftv res, leftv args);
    320338#endif
     339
     340#endif
  • Singular/dyn_modules/gfanlib/tropicalVariety.cc

    r4664b3 rc96414  
    33#include <bbfan.h>
    44#include <groebnerCone.h>
     5#include <tropicalVarietyOfPolynomials.h>
    56#include <tropicalVarietyOfIdeals.h>
    67#include <libpolys/coeffs/numbers.h>
     
    89#include <kernel/structs.h>
    910
     11#include <iostream>
     12#include <gfanlib/gfanlib_zfan.h>
    1013
    1114BITSET bitsetSave1, bitsetSave2;
     
    2831}
    2932
     33static gfan::ZFan* toZFan(std::set<gfan::ZCone> maxCones)
     34{
     35  std::set<gfan::ZCone>::iterator sigma = maxCones.begin();
     36  gfan::ZFan* zf = new gfan::ZFan(sigma->ambientDimension());
     37  for (; sigma!=maxCones.end(); sigma++)
     38    zf->insert(*sigma);
     39  return zf;
     40}
     41
    3042BOOLEAN tropicalVariety(leftv res, leftv args)
    3143{
     44  omUpdateInfo();
     45  Print("usedBytesAfter=%ld\n",om_Info.UsedBytes);
    3246  leftv u = args;
    3347  if ((u!=NULL) && (u->Typ()==IDEAL_CMD))
     
    3549    ideal I = (ideal) u->CopyD();
    3650    leftv v = u->next;
     51
     52    if (idSize(I)==1)
     53    {
     54      poly g = I->m[0];
     55      if (v==NULL)
     56      {
     57        tropicalStrategy currentStrategy(I,currRing);
     58        std::set<gfan::ZCone> maxCones = tropicalVariety(g,currRing,currentStrategy);
     59        // while (1)
     60        // {
     61        //   omUpdateInfo();
     62        //   Print("usedBytesAfter=%ld\n",om_Info.UsedBytes);
     63        //   tropicalStrategy debugTest(I,currRing);
     64        //   maxCones = tropicalVariety(g,currRing,debugTest);
     65        //   gfan::ZFan* zf = toZFan(maxCones);
     66        //   delete zf;
     67        // }
     68        res->rtyp = fanID;
     69        res->data = (char*) toZFan(maxCones);
     70        id_Delete(&I,currRing);
     71        return FALSE;
     72      }
     73      if ((v!=NULL) && (v->Typ()==NUMBER_CMD))
     74      {
     75        number p = (number) v->CopyD();
     76        tropicalStrategy currentStrategy(I,p,currRing);
     77        std::set<gfan::ZCone> maxCones = tropicalVariety(g,currRing,currentStrategy);
     78        res->rtyp = fanID;
     79        res->data = (char*) toZFan(maxCones);
     80        id_Delete(&I,currRing);
     81        n_Delete(&p,currRing->cf);
     82        return FALSE;
     83      }
     84    }
     85
    3786    if (v==NULL)
    3887    {
    3988      setOptionRedSB();
    4089      if (!hasFlag(u,FLAG_STD))
    41         I = gfanlib_kStd_wrapper(I,currRing);
     90      {
     91        ideal stdI = gfanlib_kStd_wrapper(I,currRing);
     92        id_Delete(&I,currRing);
     93        I = stdI;
     94      }
    4295      tropicalStrategy currentStrategy(I,currRing);
    4396      gfan::ZFan* tropI = tropicalVariety(currentStrategy);
     
    4598      res->data = (char*) tropI;
    4699      undoSetOptionRedSB();
     100      id_Delete(&I,currRing);
    47101      return FALSE;
    48102    }
     
    51105      number p = (number) v->CopyD();
    52106      if (!hasFlag(u,FLAG_STD))
    53         I = gfanlib_kStd_wrapper(I,currRing);
     107      {
     108        ideal stdI = gfanlib_kStd_wrapper(I,currRing);
     109        id_Delete(&I,currRing);
     110        I = stdI;
     111      }
    54112      tropicalStrategy currentStrategy(I,p,currRing);
    55113      gfan::ZFan* tropI = tropicalVariety(currentStrategy);
    56114      res->rtyp = fanID;
    57115      res->data = (char*) tropI;
     116      id_Delete(&I,currRing);
    58117      return FALSE;
    59118    }
  • Singular/dyn_modules/gfanlib/tropicalVarietyOfIdeals.cc

    r4664b3 rc96414  
    55gfan::ZFan* tropicalVariety(const tropicalStrategy currentStrategy)
    66{
    7   ideal I = currentStrategy.getStartingIdeal();
    8   ring r = currentStrategy.getStartingRing();
    97  groebnerCone startingCone = tropicalStartingCone(currentStrategy);
    108  groebnerCones tropicalVariety = tropicalTraversal(startingCone);
  • Singular/dyn_modules/gfanlib/witness.cc

    r4664b3 rc96414  
    9090{
    9191  leftv u = args;
    92   leftv v = u->next;
    93   ideal inI = (ideal) u->CopyD();
    94   ideal J = (ideal) v->CopyD();
    95   omUpdateInfo();
    96   Print("usedBytesBefore=%ld\n",om_Info.UsedBytes);
    97   ideal I = witness(inI,J,currRing);
    98   id_Delete(&inI,currRing);
    99   id_Delete(&J,currRing);
    100   res->rtyp = IDEAL_CMD;
    101   res->data = (char*) I;
    102   return FALSE;
     92  if ((u != NULL) && (u->Typ() == IDEAL_CMD))
     93  {
     94    leftv v = u->next;
     95    if ((v!=NULL) && (v->Typ()==IDEAL_CMD))
     96    {
     97      omUpdateInfo();
     98      Print("usedBytesBefore=%ld\n",om_Info.UsedBytes);
     99      ideal inI = (ideal) u->CopyD();
     100      ideal J = (ideal) v->CopyD();
     101      ideal I = witness(inI,J,currRing);
     102      id_Delete(&inI,currRing);
     103      id_Delete(&J,currRing);
     104      res->rtyp = IDEAL_CMD;
     105      res->data = (char*) I;
     106      return FALSE;
     107    }
     108  }
     109  return TRUE;
    103110}
    104111#endif
Note: See TracChangeset for help on using the changeset viewer.