Changeset d4df72 in git


Ignore:
Timestamp:
Oct 25, 2010, 3:34:57 PM (14 years ago)
Author:
Frank Seelisch <seelisch@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', 'b4f17ed1d25f93d46dbe29e4b499baecc2fd51bb')
Children:
386a8636dfd438b85470e212f44acfc042909ef7
Parents:
def863c5f805648a6621b7829a098d93a4674d70
Message:
including ZCone code to link with gfan lib

git-svn-id: file:///usr/local/Singular/svn/trunk@13559 2c84dea3-7e68-4137-9b89-c4e89433aadc
Location:
Singular
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • Singular/Makefile.in

    rdef863 rd4df72  
    9696LIBSP           = -lm @NEED_LIBSG@
    9797else
    98 LIBS            = -lsingfac -lsingcf -lntl  -static -lreadline -lhtmlhelp -Xlinker -Bdynamic -lgmp -lomalloc_ndebug -lncurses
     98LIBS            = -lsingfac -lsingcf -lntl  -static -lreadline -lhtmlhelp -lgfan -lcddgmp -Xlinker -Bdynamic -lgmp -lomalloc_ndebug -lncurses
    9999## -lpython_module -lpython2.4 /usr/local/lib/libboost_python-gcc-d-1_32.dll
    100 LIBSG           = -lsingfac -lsingcf -lntl  -static -lreadline -lhtmlhelp -Xlinker -Bdynamic -lgmp -lncurses
     100LIBSG           = -lsingfac -lsingcf -lntl  -static -lreadline -lhtmlhelp -lgfan -lcddgmp -Xlinker -Bdynamic -lgmp -lncurses
    101101endif
    102102MP_LIBS         = @MP_LIBS@
     
    381381        ${CXX} ${CXXFLAGS}  ${CPPFLAGS} ${DEFS} -c $<
    382382
    383 iparith.inc: gentable.cc grammar.h tok.h table.h mod2.h
    384         ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${CXXTEMPLFLAGS} ${DEFS} gentable.cc \
    385              -o gentable1
     383iparith.inc: ${OBJS} claptmpl.o iparith.cc \
     384                          ipconv.cc tok.h mpsr_Tok.cc grammar.h mod2.h
     385        ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${CXXTEMPLFLAGS} ${DEFS} -DGENTABLE \
     386             -o gentable1 claptmpl.o iparith.cc tesths.cc mpsr_Tok.cc \
     387             ${OBJS} ${LDFLAGS} ${LIBS} ../kernel/mmalloc.o
    386388        ./gentable1
    387389        /bin/rm -f gentable1 gentable1.exe
    388390
    389 mpsr_Tok.inc: gentable2.cc grammar.h tok.h table.h mod2.h
    390         ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${CXXTEMPLFLAGS} ${DEFS} gentable2.cc \
    391              -o gentable2
     391mpsr_Tok.inc: ${OBJS} claptmpl.o iparith.cc \
     392                          ipconv.cc tok.h mpsr_Tok.cc grammar.h mod2.h
     393        ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${CXXTEMPLFLAGS} ${DEFS} -DGENTABLE \
     394             -o gentable2 claptmpl.o iparith.cc tesths.cc mpsr_Tok.cc \
     395             ${OBJS} ${LDFLAGS} ${LIBS} ../kernel/mmalloc.o
    392396        ./gentable2
    393397        /bin/rm -f gentable2 gentable2.exe
     398
    394399
    395400svnver:
  • Singular/claptmpl.cc

    rdef863 rd4df72  
    161161  template class List<fglmDelem>;
    162162  template class ListIterator<fglmDelem>;
     163#endif
     164
     165#ifdef HAVE_FANS
     166#include <gfanlib/gfanlib.h>
    163167#endif
    164168
     
    261265template class Cache<MinorKey, PolyMinorValue>;
    262266#endif
     267
     268#ifdef HAVE_FANS
     269template class gfan::Vector<gfan::Integer>;
     270template class gfan::Vector<gfan::Rational>;
     271template class gfan::Matrix<gfan::Integer>;
     272template class gfan::Matrix<gfan::Rational>;
     273#endif
    263274//template int pos_helper(kStrategy strat, poly p, int len, intset setL, polyset set);
  • Singular/configure

    rdef863 rd4df72  
    52665266    { echo "configure: error: can not build with gmp" 1>&2; exit 1; }
    52675267  fi
     5268fi
     5269
     5270echo $ac_n "checking gfan lib""... $ac_c" 1>&6
     5271if test "$enable_gfanlib" = yes; then
     5272  echo "yes"
     5273  NEED_LIBS="${NEED_LIBS} -lcddgmp -lgfan"
     5274else
     5275  echo "no"
    52685276fi
    52695277
  • Singular/configure.in

    rdef863 rd4df72  
    884884fi
    885885
     886AC_MSG_CHECKING(gfanlib)
     887if test "$enable_gfanlib" = yes; then
     888  AC_MSG_RESULT(yes)
     889  NEED_LIBS="${NEED_LIBS} -lgfan -lcddgmp"
     890else
     891  AC_MSG_RESULT(can not build with gfan lib)
     892fi
     893
    886894AC_MSG_CHECKING(whether to use libsvd)
    887895if test "$with_svd" = yes; then
  • Singular/iparith.cc

    rdef863 rd4df72  
    7171#include <Singular/Fan.h>
    7272#include <Singular/Cone.h>
     73#include <gfanlib/gfanlib.h>
    7374
    7475#include <kernel/timer.h>
     
    31613162}
    31623163#ifdef HAVE_FANS
    3163 static BOOLEAN jjADDMCONE1(leftv res, leftv u, leftv v)
    3164 {
    3165   /* method for adding a maximal cone in the given fan;
    3166      valid parametrizations: (fan, cone),
     3164int integerToInt(gfan::Integer const &V, bool &ok)
     3165{
     3166  mpz_t v;
     3167  mpz_init(v);
     3168  V.setGmp(v);
     3169  int ret=0;
     3170  if(mpz_fits_sint_p(v))
     3171    ret=mpz_get_si(v);
     3172  else
     3173    ok=false;
     3174  mpz_clear(v);
     3175  return ret;
     3176}
     3177intvec* zVector2Intvec(const gfan::ZVector zv)
     3178{
     3179  int d=zv.size();
     3180  intvec* iv = new intvec(1, d, 0);
     3181  bool ok = true;
     3182  for(int i=1;i<=d;i++)
     3183    IMATELEM(*iv, 1, i) = integerToInt(zv[i-1], ok);
     3184  if (!ok) WerrorS("overflow while converting a gfan::ZVector to an intvec");
     3185  return iv;
     3186}
     3187intvec* zMatrix2Intvec(const gfan::ZMatrix zm)
     3188{
     3189  int d=zm.getHeight();
     3190  int n=zm.getWidth();
     3191  intvec* iv = new intvec(d, n, 0);
     3192  bool ok = true;
     3193  for(int i=1;i<=d;i++)
     3194    for(int j=1;j<=n;j++)
     3195      IMATELEM(*iv, i, j) = integerToInt(zm[i-1][j-1], ok);
     3196  if (!ok) WerrorS("overflow while converting a gfan::ZMatrix to an intmat");
     3197  return iv;
     3198}
     3199gfan::ZMatrix intmat2ZMatrix(const intvec* iMat)
     3200{
     3201  int d=iMat->rows();
     3202  int n=iMat->cols();
     3203  gfan::ZMatrix ret(d,n);
     3204  for(int i=0;i<d;i++)
     3205    for(int j=0;j<n;j++)
     3206      ret[i][j]=IMATELEM(*iMat, i+1, j+1);
     3207  return ret;
     3208}
     3209/* expects iMat to have just one row */
     3210gfan::ZVector intvec2ZVector(const intvec* iVec)
     3211{
     3212  int n =iVec->rows();
     3213  gfan::ZVector ret(n);
     3214  for(int j=0;j<n;j++)
     3215    ret[j]=IMATELEM(*iVec, j+1, 1);
     3216  return ret;
     3217}
     3218static BOOLEAN jjCONERAYS2(leftv res, leftv u, leftv v)
     3219{
     3220  /* method for generating a cone object from half-lines,
     3221     and lines (any point in the cone being the sum of a point
     3222     in the convex hull of the half-lines and a point in the span
     3223     of the lines; the second argument may contain or entirely consist
     3224     of zero rows);
     3225     valid parametrizations: (intmat, intmat)
    31673226     Errors will be invoked in the following cases:
    3168      - the cone has been generated in the context of a
    3169        fan which is different from the given one */
    3170   Fan* f = (Fan*)u->Data();
    3171   Cone* c = (Cone*)v->Data();
    3172   if (! f->addMaxCone(c))
    3173   {
    3174     WerrorS("cone references a fan which is different from the 1st argument");
    3175     return TRUE;
    3176   }
    3177   else return FALSE;
    3178 }
    3179 static BOOLEAN jjADDMCONE2(leftv res, leftv u, leftv v)
    3180 {
    3181   /* method for adding numerous maximal cones in the given fan;
    3182      valid parametrizations: (fan, list),
    3183      where the list entries are expected to be cones;
     3227     - u and v have different numbers of columns */
     3228  intvec* rays = (intvec *)u->CopyD(INTVEC_CMD);
     3229  intvec* linSpace = (intvec *)v->CopyD(INTVEC_CMD);
     3230  if (rays->cols() != linSpace->cols())
     3231  {
     3232    Werror("expected same number of columns but got %d vs. %d",
     3233           rays->cols(), linSpace->cols());
     3234    return TRUE;
     3235  }
     3236  gfan::ZMatrix zm1 = intmat2ZMatrix(rays);
     3237  gfan::ZMatrix zm2 = intmat2ZMatrix(linSpace);
     3238  gfan::ZCone* zc = new gfan::ZCone();
     3239  *zc = gfan::ZCone::givenByRays(zm1, zm2);
     3240  res->data = (char *)zc;
     3241  return FALSE;
     3242}
     3243static BOOLEAN jjFACECONT(leftv res, leftv u, leftv v)
     3244{
     3245  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
     3246  intvec* iv = (intvec*)v->Data();
     3247  gfan::ZVector zv = intvec2ZVector(iv);
     3248  int d1 = zc->ambientDimension();
     3249  int d2 = zv.size();
     3250  if (d1 != d2)
     3251    Werror("expected ambient dim of cone and size of vector\n"
     3252           "to be equal but got %d and %d", d1, d2);
     3253  if(!zc->contains(zv))
     3254  {
     3255    WerrorS("provided intvec does not lie in the cone");
     3256  }
     3257  res->data = (void *)new gfan::ZCone(zc->faceContaining(zv));
     3258  return FALSE;
     3259}
     3260static BOOLEAN jjINTERSC(leftv res, leftv u, leftv v)
     3261{
     3262  gfan::ZCone* zc1 = (gfan::ZCone*)u->Data();
     3263  gfan::ZCone* zc2 = (gfan::ZCone*)v->Data();
     3264  int d1 = zc1->ambientDimension();
     3265  int d2 = zc2->ambientDimension();
     3266  if (d1 != d2)
     3267    Werror("expected ambient dims of both cones to coincide\n"
     3268           "but got %d and %d", d1, d2);
     3269  gfan::ZCone zc3 = gfan::intersection(*zc1, *zc2);
     3270  res->data = (void *)new gfan::ZCone(zc3);
     3271  return FALSE;
     3272}
     3273static BOOLEAN jjCONELINK(leftv res, leftv u, leftv v)
     3274{
     3275  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
     3276  intvec* iv = (intvec*)v->Data();
     3277  gfan::ZVector zv= intvec2ZVector(iv);
     3278  int d1 = zc->ambientDimension();
     3279  int d2 = zv.size();
     3280  if (d1 != d2)
     3281    Werror("expected ambient dim of cone and size of vector\n"
     3282           "to be equal but got %d and %d", d1, d2);
     3283  if(!zc->contains(zv))
     3284  {
     3285    WerrorS("the provided intvec does not lie in the cone");
     3286  }
     3287  res->data = (void *)new gfan::ZCone(zc->link(zv));
     3288  return FALSE;
     3289}
     3290static BOOLEAN jjCONTAINS2(leftv res, leftv u, leftv v)
     3291{
     3292  gfan::ZCone* zc1 = (gfan::ZCone*)u->Data();
     3293  gfan::ZCone* zc2 = (gfan::ZCone*)v->Data();
     3294  int d1 = zc1->ambientDimension();
     3295  int d2 = zc2->ambientDimension();
     3296  if (d1 != d2)
     3297    Werror("expected cones with same ambient dimensions\n but got"
     3298           " dimensions %d and %d", d1, d2);
     3299  res->data = (void *)(zc1->contains(*zc2) ? 1 : 0);
     3300  return FALSE;
     3301}
     3302static BOOLEAN jjCONENORMALS2(leftv res, leftv u, leftv v)
     3303{
     3304  /* method for generating a cone object from iequalities,
     3305     and equations (...)
     3306     valid parametrizations: (intmat, intmat)
    31843307     Errors will be invoked in the following cases:
    3185      - one of the cones has been generated in the context
    3186        of a fan which is different from the given one */
    3187   Fan* f = (Fan*)u->Data();
    3188   lists L = (lists)v->Data();
    3189   int index = f->addMaxCones(L);
    3190   if (index != 0)
    3191   {
    3192     Werror("cone at position %d references a fan which %s",
    3193            index, "is different from the 1st argument");
    3194     return TRUE;
    3195   }
    3196   else return FALSE;
     3308     - u and v have different numbers of columns */
     3309  intvec* inequs = (intvec *)u->CopyD(INTVEC_CMD);
     3310  intvec* equs = (intvec *)v->CopyD(INTVEC_CMD);
     3311  if (inequs->cols() != equs->cols())
     3312  {
     3313    Werror("expected same number of columns but got %d vs. %d",
     3314           inequs->cols(), equs->cols());
     3315    return TRUE;
     3316  }
     3317  gfan::ZMatrix zm1 = intmat2ZMatrix(inequs);
     3318  gfan::ZMatrix zm2 = intmat2ZMatrix(equs);
     3319  gfan::ZCone* zc = new gfan::ZCone(zm1, zm2);
     3320  res->data = (char *)zc;
     3321  return FALSE;
    31973322}
    31983323static BOOLEAN jjDELMCONE2(leftv res, leftv u, leftv v)
     
    32013326     valid parametrizations: (fan, int),
    32023327     Errors will be invoked in the following cases:
    3203      - the given index is out of range [1..m], where m is
     3328     - the given index is out of range [0..m-1], where m is
    32043329       the number of maximal cones in the given fan */
    32053330  Fan* f = (Fan*)u->Data();
    32063331  int index = (int)(long)v->Data();
    3207   if (! f->deleteMaxCone(index))
    3208   {
    3209     Werror("cone index %d out of range [1..%d]; no cone deleted",
    3210            index, f->getMaxCones()->nr + 1);
    3211     return TRUE;
    3212   }
    3213   else return FALSE;
     3332  int n = f->getNumberOfMaxCones();
     3333  if (n == 0)
     3334  {
     3335    WerrorS("no maximal cones defined in the given fan");
     3336    return TRUE;
     3337  }
     3338  if ((index < 0) || (n <= index))
     3339  {
     3340    Werror("cone index %d out of range [0..%d]; no cone deleted",
     3341           index, f->getNumberOfMaxCones() - 1);
     3342    return TRUE;
     3343  }
     3344  f->deleteMaxCone(index);
     3345  return FALSE;
    32143346}
    32153347static BOOLEAN jjDELMCONE3(leftv res, leftv u, leftv v)
     
    32193351     valid parametrizations: (fan, intvec),
    32203352     Errors will be invoked in the following cases:
    3221      - one of the given indices is out of range [1..m],
     3353     - one of the given indices is out of range [0..m-1],
    32223354       where m is the number of maximal cones in the given
    32233355       fan;
    3224      The method does not check that the given indices are
    3225      mutually distinct. */
     3356     The method does not check whether the given indices are
     3357     mutually distinct. This is however assumed by this method. */
    32263358  Fan* f = (Fan*)u->Data();
    3227   intvec* indices = (intvec*)v->Data();
    3228   int result = f->deleteMaxCones(indices);
    3229   if (result != 0)
    3230   {
    3231     Werror("cone index %d at position %d out of range [1..%d]; %s",
    3232            (*indices)[result - 1], result, f->getMaxCones()->nr + 1,
    3233            "no cone deleted");
    3234     return TRUE;
    3235   }
    3236   else return FALSE;
    3237 }
    3238 static BOOLEAN jjMAXCONE2(leftv res, leftv u, leftv v)
    3239 {
    3240   /* method for retrieving a maximal cone of the given fan;
     3359  intvec* iv = (intvec*)v->Data();
     3360  int n = f->getNumberOfMaxCones();
     3361  if (n == 0)
     3362  {
     3363    WerrorS("no maximal cones defined in the given fan");
     3364    return TRUE;
     3365  }
     3366  for (int i = 0; i < iv->length(); i++)
     3367    if (((*iv)[i] < 0) || (n <= (*iv)[i]))
     3368    {
     3369      Werror("cone index %d out of range [0..%d]", (*iv)[i], n - 1);
     3370      return TRUE;
     3371    }
     3372  f->deleteMaxCones(iv);
     3373  return FALSE;
     3374}
     3375static BOOLEAN jjMAXCONE1(leftv res, leftv u, leftv v)
     3376{
     3377  /* method for retrieving a maximal cone from the given fan;
    32413378     valid parametrizations: (fan, int),
    32423379     Errors will be invoked in the following cases:
    32433380     - maximal cones not yet set in the fan,
    3244      - maximal cone index invalid;
     3381     - maximal cone index out of range;
    32453382     The method returns an object of type cone. */
    32463383  Fan* f = (Fan*)u->Data();
    32473384  int index = (int)(long)v->Data();
    3248   lists maxCones = f->getMaxCones();
    3249   if (maxCones == NULL)
    3250   {
    3251     WerrorS("no maximal cones set in the given fan");
    3252     return TRUE;
    3253   }
    3254   else if ((index < 1) || (maxCones->nr + 1 < index))
    3255   {
    3256     Werror("invalid cone index %d", index);
    3257     return TRUE;
    3258   }
    3259   res->data = (char*)new Cone(*(Cone*)(maxCones->m[index - 1].data));
     3385  int n = f->getNumberOfMaxCones();
     3386  if (n == 0)
     3387  {
     3388    WerrorS("no maximal cones defined in the given fan");
     3389    return TRUE;
     3390  }
     3391  if ((index < 0) || (n <= index))
     3392  {
     3393    Werror("cone index %d out of range [0..%d]", index, n - 1);
     3394    return TRUE;
     3395  }
     3396  Cone* c = f->getMaxCone(index);
     3397  res->data = (char*)c;
     3398  return FALSE;
     3399}
     3400static BOOLEAN jjMAXCONE2(leftv res, leftv u, leftv v)
     3401{
     3402  /* method for retrieving numerous maximal cones of the given fan
     3403     in a list;
     3404     valid parametrizations: (fan, intvec),
     3405     Errors will be invoked in the following cases:
     3406     - maximal cones not yet set in the fan,
     3407     - cone index out of range;
     3408     The method returns a list of cone objects. */
     3409  Fan* f = (Fan*)u->Data();
     3410  intvec* iv = (intvec*)v->Data();
     3411  int n = f->getNumberOfMaxCones();
     3412  if (n == 0)
     3413  {
     3414    WerrorS("no maximal cones defined in the given fan");
     3415    return TRUE;
     3416  }
     3417  for (int i = 0; i < iv->length(); i++)
     3418    if (((*iv)[i] < 0) || (n <= (*iv)[i]))
     3419    {
     3420      Werror("cone index %d out of range [0..%d]", (*iv)[i], n - 1);
     3421      return TRUE;
     3422    }
     3423  lists maxCones = f->getMaxCones(iv);
     3424  res->data = (char*)maxCones;
    32603425  return FALSE;
    32613426}
     
    32973462  return FALSE;
    32983463}
    3299 static BOOLEAN jjGETPROP2(leftv res, leftv u, leftv v)
     3464static BOOLEAN jjGETPROPC(leftv res, leftv u, leftv v)
    33003465{
    33013466  /* method for retrieving cone properties;
    33023467     valid parametrizations: (cone, string),
    33033468     Errors will be invoked in the following cases:
    3304      - cone has so far only been instantiated by "cone c;",
    3305      - string is not 'dim' */
    3306   Cone* c = (Cone*)u->Data();
     3469     - invalid property string (see below for valid ones) */
     3470  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
    33073471  char* prop = (char*)v->Data();
    3308   int result;
    3309 
    3310   if (c->getFan() == NULL)
    3311   {
    3312     WerrorS("the given cone has no properties yet (freshly instantiated)");
    3313     return TRUE;
    3314   }
    3315 
    3316   if (strcmp(prop, "dim") == 0)
    3317     result = c->getDim();
     3472  gfan::ZMatrix retMat;
     3473  gfan::ZCone retCone;
     3474  int retInt;
     3475  gfan::ZVector retVec;
     3476  int typeInfo;
     3477
     3478  /* ################ properties with return type intmat: ################## */
     3479  if      (strcmp(prop, "INEQUALITIES") == 0)
     3480  {
     3481    retMat = zc->getInequalities();
     3482    typeInfo = INTMAT_CMD;
     3483  }
     3484  else if (strcmp(prop, "EQUATIONS") == 0)
     3485  {
     3486    retMat = zc->getEquations();
     3487    typeInfo = INTMAT_CMD;
     3488  }
     3489  else if (strcmp(prop, "FACETS") == 0)
     3490  {
     3491    retMat = zc->getFacets();
     3492    typeInfo = INTMAT_CMD;
     3493  }
     3494  else if (strcmp(prop, "IMPLIED_EQUATIONS") == 0)
     3495  {
     3496    retMat = zc->getImpliedEquations();
     3497    typeInfo = INTMAT_CMD;
     3498  }
     3499  else if (strcmp(prop, "GENERATORS_OF_SPAN") == 0)
     3500  {
     3501    retMat = zc->generatorsOfSpan();
     3502    typeInfo = INTMAT_CMD;
     3503  }
     3504  else if (strcmp(prop, "GENERATORS_OF_LINEALITY_SPACE") == 0)
     3505  {
     3506    retMat = zc->generatorsOfLinealitySpace();
     3507    typeInfo = INTMAT_CMD;
     3508  }
     3509  else if (strcmp(prop, "RAYS") == 0)
     3510  {
     3511    retMat = zc->extremeRays();
     3512    typeInfo = INTMAT_CMD;
     3513  }
     3514  else if (strcmp(prop, "QUOTIENT_LATTICE_BASIS") == 0)
     3515  {
     3516    retMat = zc->quotientLatticeBasis();
     3517    typeInfo = INTMAT_CMD;
     3518  }
     3519  else if (strcmp(prop, "LINEAR_FORMS") == 0)
     3520  {
     3521    retMat = zc->getLinearForms();
     3522    typeInfo = INTMAT_CMD;
     3523  }
     3524  /* ################ properties with return type int: ################## */
     3525  else if (strcmp(prop, "AMBIENT_DIM") == 0)
     3526  {
     3527    retInt = zc->ambientDimension();
     3528    typeInfo = INT_CMD;
     3529  }
     3530  else if (strcmp(prop, "DIM") == 0)
     3531  {
     3532    retInt = zc->dimension();
     3533    typeInfo = INT_CMD;
     3534  }
     3535  else if (strcmp(prop, "LINEALITY_DIM") == 0)
     3536  {
     3537    retInt = zc->dimensionOfLinealitySpace();
     3538    typeInfo = INT_CMD;
     3539  }
     3540  else if (strcmp(prop, "MULTIPLICITY") == 0)
     3541  {
     3542    bool ok = true;
     3543    retInt = integerToInt(zc->getMultiplicity(), ok);
     3544    if (!ok)
     3545      WerrorS("overflow while converting a gfan::Integer to an int");
     3546    typeInfo = INT_CMD;
     3547  }
     3548  else if (strcmp(prop, "IS_ORIGIN") == 0)
     3549  {
     3550    retInt = zc->isOrigin() ? 1 : 0;
     3551    typeInfo = INT_CMD;
     3552  }
     3553  else if (strcmp(prop, "IS_FULL_SPACE") == 0)
     3554  {
     3555    retInt = zc->isFullSpace() ? 1 : 0;
     3556    typeInfo = INT_CMD;
     3557  }
     3558  else if (strcmp(prop, "SIMPLICIAL") == 0)
     3559  {
     3560    retInt = zc->isSimplicial() ? 1 : 0;
     3561    typeInfo = INT_CMD;
     3562  }
     3563  else if (strcmp(prop, "CONTAINS_POSITIVE_VECTOR") == 0)
     3564  {
     3565    retInt = zc->containsPositiveVector() ? 1 : 0;
     3566    typeInfo = INT_CMD;
     3567  }
     3568  /* ################ properties with return type ZCone: ################## */
     3569  else if (strcmp(prop, "LINEALITY_SPACE") == 0)
     3570  {
     3571    retCone = zc->linealitySpace();
     3572    typeInfo = CONE_CMD;
     3573  }
     3574  else if (strcmp(prop, "DUAL_CONE") == 0)
     3575  {
     3576    retCone = zc->dualCone();
     3577    typeInfo = CONE_CMD;
     3578  }
     3579  else if (strcmp(prop, "NEGATED") == 0)
     3580  {
     3581    retCone = zc->negated();
     3582    typeInfo = CONE_CMD;
     3583  }
     3584  /* ################ properties with return type intvec: ################## */
     3585  else if (strcmp(prop, "SEMI_GROUP_GENERATOR") == 0)
     3586  {
     3587    /* test whether the cone's dim = dim of lin space + 1: */
     3588    int d = zc->dimension();
     3589    int dLS = zc->dimensionOfLinealitySpace();
     3590    if (d == dLS + 1)
     3591      retVec = zc->semiGroupGeneratorOfRay();
     3592    else
     3593    {
     3594      Werror("expected dim of cone one larger than dim of lin space\n"
     3595             "but got dimensions %d and %d", d, dLS);
     3596    }
     3597    typeInfo = INTVEC_CMD;
     3598  }
     3599  else if (strcmp(prop, "RELATIVE_INTERIOR_POINT") == 0)
     3600  {
     3601    retVec = zc->getRelativeInteriorPoint();
     3602    typeInfo = INTVEC_CMD;
     3603  }
     3604  else if (strcmp(prop, "UNIQUE_POINT") == 0)
     3605  {
     3606    retVec = zc->getUniquePoint();
     3607    typeInfo = INTVEC_CMD;
     3608  }
    33183609  else
    33193610  {
     
    33223613  }
    33233614
    3324   res->data = (void*)result;
     3615  res->rtyp = typeInfo;
     3616  switch(typeInfo)
     3617  {
     3618    case INTMAT_CMD:
     3619      res->data = (void*)zMatrix2Intvec(retMat);
     3620      break;
     3621    case INT_CMD:
     3622      res->data = (void*)retInt;
     3623      break;
     3624    case CONE_CMD:
     3625      res->data = (void*)new gfan::ZCone(retCone);
     3626      break;
     3627    case INTVEC_CMD:
     3628      res->data = (void*)zVector2Intvec(retVec);
     3629      break;
     3630    default: ; /* should never be reached */
     3631  }
     3632  return FALSE;
     3633}
     3634static BOOLEAN jjADJACENCY2(leftv res, leftv u, leftv v)
     3635{
     3636  /* method for retrieving all maximal cones in the given fan that
     3637     are adjacent to a given maximal cone;
     3638     valid parametrizations: (fan, int),
     3639     Errors will be invoked in the following cases:
     3640     - the maximal cone index is out of range [0..m-1],
     3641       where m is the number of maximal cones in the given fan;
     3642     In case there are no neighbours (yet) of the specified maximal
     3643     cone, the method returns an intvec of length one with entry zero. */
     3644  Fan* f = (Fan*)u->Data();
     3645  int maxCone = (int)(long)v->Data();
     3646  int nMaxCones = f->getNumberOfMaxCones();
     3647  if ((maxCone < 0) || (nMaxCones <= maxCone))
     3648  {
     3649    Werror("index %d out of range [0..%d]",
     3650           maxCone, nMaxCones - 1);
     3651    return TRUE;
     3652  }
     3653  intvec* result = f->getAdjacency(maxCone);
     3654  result = ivCopy(result);
     3655  res->data = (char*)result;
    33253656  return FALSE;
    33263657}
     
    46935024}
    46945025#ifdef HAVE_FANS
     5026static BOOLEAN jjCONERAYS1(leftv res, leftv v)
     5027{
     5028  /* method for generating a cone object from half-lines
     5029     (cone = convex hull of the half-lines; note: there may be
     5030     entire lines in the cone);
     5031     valid parametrizations: (intmat) */
     5032  intvec* rays = (intvec *)v->CopyD(INTVEC_CMD);
     5033  gfan::ZMatrix zm = intmat2ZMatrix(rays);
     5034  gfan::ZCone* zc = new gfan::ZCone();
     5035  *zc = gfan::ZCone::givenByRays(zm, gfan::ZMatrix(0, zm.getWidth()));
     5036  res->data = (char *)zc;
     5037  return FALSE;
     5038}
     5039static BOOLEAN jjCONENORMALS1(leftv res, leftv v)
     5040{
     5041  /* method for generating a cone object from inequalities;
     5042     valid parametrizations: (intmat) */
     5043  intvec* inequs = (intvec *)v->CopyD(INTVEC_CMD);
     5044  gfan::ZMatrix zm = intmat2ZMatrix(inequs);
     5045  gfan::ZCone* zc = new gfan::ZCone(zm, gfan::ZMatrix(0, zm.getWidth()));
     5046  res->data = (char *)zc;
     5047  return FALSE;
     5048}
    46955049static BOOLEAN jjDELMCONE1(leftv res, leftv v)
    46965050{
    4697   /* method for deleting all maximal cones of the given fan;
     5051  /* method for deleting all maximal cones from a given fan;
    46985052     valid parametrizations: (fan) */
    46995053  Fan* f = (Fan*)v->Data();
    4700   f->deleteMaxCones(NULL);
     5054  int n = f->getNumberOfMaxCones();
     5055  intvec* iv = new intvec(1, n, 0);
     5056  for (int i = 1; i <= n; i++)
     5057    IMATELEM(*iv, 1, i) = i - 1;
     5058  f->deleteMaxCones(iv);
     5059  delete iv;
    47015060  return FALSE;
    47025061}
     
    47075066     If there are no maximal rays, the method returns a 1x1
    47085067     matrix with entry 0. Otherwise the returned matrix contains
    4709      the maximal rays as column vectors. */
     5068     the maximal rays as row vectors. */
    47105069  Fan* f = (Fan*)v->Data();
    47115070  intvec* result = NULL;
     
    47245083     If there are no maximal rays, the method returns a 1x1
    47255084     matrix with entry 0. Otherwise the returned matrix contains
    4726      the maximal rays as column vectors. */
     5085     the maximal rays as row vectors. */
    47275086  Cone* c = (Cone*)v->Data();
    47285087  intvec* result = NULL;
    4729   if (c->getRays() == NULL)
     5088  if (c->getMaxRays() == NULL)
    47305089    /* return a 1x1 matrix with sole entry zero */
    47315090    result = new intvec(1, 1, 0);
    47325091  else
    4733   {
    4734     intvec* indices = c->getRays();
    4735     intvec* maxRays = c->getFan()->getMaxRays();
    4736     result = new intvec(maxRays->rows(), indices->length(), 0);
    4737     for (int c = 1; c <= indices->length(); c++)
    4738       for (int r = 1; r <= maxRays->rows(); r++)
    4739       {
    4740         IMATELEM(*result, r, c) = IMATELEM(*maxRays, r, (*indices)[c - 1]);
    4741       }
    4742   }
     5092    result = ivCopy(c->getMaxRays());
    47435093  res->data = (char*)result;
    47445094  return FALSE;
     
    47495099     valid parametrizations: (fan),
    47505100     If there are no facet normals, a 1x1 matrix with entry 0
    4751      is returned; otherwise a matrix the columns of which are
     5101     is returned; otherwise a matrix the rows of which are
    47525102     the facet normals of the given fan. */
    47535103  Fan* f = (Fan*)v->Data();
     
    47645114{
    47655115  /* method for retrieving the facet normals of the given cone;
    4766      valid parametrizations: (fan),
     5116     valid parametrizations: (cone),
    47675117     If there are no facet normals, a 1x1 matrix with entry 0
    4768      is returned; otherwise a matrix the columns of which are
     5118     is returned; otherwise a matrix the rows of which are
    47695119     the facet normals of the given cone. */
    47705120  Cone* c = (Cone*)v->Data();
     
    47745124    result = new intvec(1, 1, 0);
    47755125  else
    4776   {
    4777     intvec* indices = c->getFacetNs();
    4778     intvec* facetNs = c->getFan()->getFacetNs();
    4779     result = new intvec(facetNs->rows(), indices->length(), 0);
    4780     for (int c = 1; c <= indices->length(); c++)
    4781       for (int r = 1; r <= facetNs->rows(); r++)
    4782       {
    4783         IMATELEM(*result, r, c) = IMATELEM(*facetNs, r, (*indices)[c - 1]);
    4784       }
    4785   }
     5126    result = ivCopy(c->getFacetNs());
    47865127  res->data = (char*)result;
    47875128  return FALSE;
    47885129}
    4789 static BOOLEAN jjLINSPACE(leftv res, leftv v)
     5130static BOOLEAN jjLINSPACE1(leftv res, leftv v)
    47905131{
    47915132  /* method for retrieving the lineality space of the given fan;
     
    47965137  return FALSE;
    47975138}
    4798 static BOOLEAN jjMAXCONE1(leftv res, leftv v)
    4799 {
    4800   /* method for retrieving all maximal cones of the given fan;
    4801      valid parametrizations: (fan),
    4802      Errors will be invoked in the following cases:
    4803      - maximal cones not yet set in the fan;
    4804      The method returns a list of cone objects. */
    4805   Fan* f = (Fan*)v->Data();
    4806   lists maxCones = lCopy(f->getMaxCones());
    4807   if (maxCones == NULL)
    4808   {
    4809     WerrorS("no maximal cones set in the given fan");
    4810     return TRUE;
    4811   }
    4812   res->data = (char*)maxCones;
     5139static BOOLEAN jjLINSPACE2(leftv res, leftv v)
     5140{
     5141  /* method for retrieving the lineality space of the given cone;
     5142     valid parametrizations: (cone) */
     5143  Cone* c = (Cone*)v->Data();
     5144  intvec* result = ivCopy(c->getLinSpace());
     5145  res->data = (char*)result;
    48135146  return FALSE;
    48145147}
    48155148static BOOLEAN jjADJACENCY1(leftv res, leftv v)
    48165149{
    4817   /* method for retrieving the adjacency matrix of the given fan;
     5150  /* method for retrieving adjacency information for the given fan;
    48185151     valid parametrizations: (fan),
    48195152     Errors will be invoked in the following cases:
    48205153     - no maximal cone has been defined yet in the given fan;
    4821      The matrix entries have the following meaning:
    4822      _[i, j] =  0: the maximal cones with indices i and j are
    4823                    not adjacent,
    4824              =  1: they are adjacent, and the intersection facet
    4825                    has been stored in the given fan,
    4826              = -1: they are adjacent but there is no intersection
    4827                    facet available */
     5154     The method returns a list with an entry for each maximal cone
     5155     in the given fan. Each such entry is an intvec with the indices
     5156     of all neighbouring maximal cones. */
    48285157  Fan* f = (Fan*)v->Data();
    4829   if (f->getMaxCones()->nr + 1 < 1)
     5158  if (f->getNumberOfMaxCones() == 0)
    48305159  {
    48315160    WerrorS("no maximal cones defined yet");
    48325161    return TRUE;
    48335162  }
    4834   intvec* adjacencyMatrix = f->getAdjacency();
    4835   res->data = (char*)adjacencyMatrix;
     5163  lists adjacencyList = f->getAdjacencyList();
     5164  adjacencyList = lCopy(adjacencyList);
     5165  res->data = (char*)adjacencyList;
    48365166  return FALSE;
    48375167}
     
    61226452}
    61236453#ifdef HAVE_FANS
    6124 static BOOLEAN jjSETPROP1(leftv res, leftv u, leftv v, leftv w)
    6125 {
    6126   /* method for setting fan properties;
    6127      valid parametrizations: (fan, string, int),
     6454static BOOLEAN jjSETPROPC1(leftv res, leftv u, leftv v, leftv w)
     6455{
     6456  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
     6457  char* prop = (char*)v->Data();
     6458  int val = (int)(long)w->Data();
     6459
     6460  if (strcmp(prop, "MULTIPLICITY") == 0)
     6461  {
     6462    zc->setMultiplicity(gfan::Integer(val));
     6463  }
     6464  else
     6465  {
     6466    Werror("unexpected cone property '%s'", prop);
     6467    return TRUE;
     6468  }
     6469  return FALSE;
     6470}
     6471static BOOLEAN jjSETPROPC2(leftv res, leftv u, leftv v, leftv w)
     6472{
     6473  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
     6474  char* prop = (char*)v->Data();
     6475  intvec* mat = (intvec*)w->Data();
     6476  gfan::ZMatrix zm = intmat2ZMatrix(mat);
     6477  int val = (int)(long)w->Data();
     6478
     6479  if (strcmp(prop, "LINEAR_FORMS") == 0)
     6480  {
     6481    zc->setLinearForms(zm);
     6482  }
     6483  else
     6484  {
     6485    Werror("unexpected cone property '%s'", prop);
     6486    return TRUE;
     6487  }
     6488  return FALSE;
     6489}
     6490static BOOLEAN jjCONTAINS3(leftv res, leftv u, leftv v, leftv w)
     6491{
     6492  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
     6493  intvec* vec = (intvec*)v->Data();
     6494  int flag = (int)(long)w->Data();
     6495  gfan::ZVector zv = intvec2ZVector(vec);
     6496  int d1 = zc->ambientDimension();
     6497  int d2 = zv.size();
     6498  if (d1 != d2)
     6499    Werror("expected ambient dim of cone and size of vector\n"
     6500           "to be equal but got %d and %d", d1, d2);
     6501  if (flag)
     6502    res->data = (void *)(zc->containsRelatively(zv) ? 1 : 0);
     6503  else
     6504    res->data = (void *)(zc->contains(zv) ? 1 : 0);;
     6505  return FALSE;
     6506}
     6507static BOOLEAN jjCONERAYS3(leftv res, leftv u, leftv v, leftv w)
     6508{
     6509  /* method for generating a cone object from half-lines,
     6510     and lines (any point in the cone being the sum of a point
     6511     in the convex hull of the half-lines and a point in the span
     6512     of the lines), and an integer k;
     6513     valid parametrizations: (intmat, intmat, int);
    61286514     Errors will be invoked in the following cases:
    6129      - string is neither of 'dim', 'complete', 'simplicial',
    6130        and 'pure';
    6131      A value 0 means that the property is not fulfilled.
    6132      1 means it is. -1 means that the answer is unknown.
    6133      Any value other than 0 and 1 will be converted to -1;
    6134      except for dim: Here, only negative values will be converted
    6135      to -1. */
    6136   Fan* f = (Fan*)u->Data();
    6137   char* prop = (char*)v->Data();
    6138   int value = (int)(long)w->Data();
    6139 
    6140   if      (strcmp(prop, "ambientdim") == 0)
    6141   {
    6142     Werror("ambient dimension of a fan cannot be set (implicitely given)");
    6143     return TRUE;
    6144   }
    6145   else if (strcmp(prop, "dim")        == 0)
    6146     f->setDim(value);
    6147   else if (strcmp(prop, "complete")   == 0)
    6148     f->setComplete(value);
    6149   else if (strcmp(prop, "simplicial") == 0)
    6150     f->setSimplicial(value);
    6151   else if (strcmp(prop, "pure")       == 0)
    6152     f->setPure(value);
    6153   else
    6154   {
    6155     Werror("unexpected fan property '%s'", prop);
    6156     return TRUE;
    6157   }
    6158 
    6159   return FALSE;
    6160 }
    6161 static BOOLEAN jjSETPROP2(leftv res, leftv u, leftv v, leftv w)
    6162 {
    6163   /* method for setting cone properties;
    6164      valid parametrizations: (fan, string, int),
     6515     - u and v have different numbers of columns,
     6516     - k not in [0..3];
     6517     if the 2^0-bit of k is set, then the lineality space is known
     6518     to be the span of the provided lines;
     6519     if the 2^1-bit of k is set, then the extreme rays are known:
     6520     each half-line spans a (different) extreme ray */
     6521  intvec* rays = (intvec *)u->CopyD(INTVEC_CMD);
     6522  intvec* linSpace = (intvec *)v->CopyD(INTVEC_CMD);
     6523  if (rays->cols() != linSpace->cols())
     6524  {
     6525    Werror("expected same number of columns but got %d vs. %d",
     6526           rays->cols(), linSpace->cols());
     6527    return TRUE;
     6528  }
     6529  int k = (int)(long)w->Data();
     6530  if ((k < 0) || (k > 3))
     6531  {
     6532    WerrorS("expected int argument in [0..3]");
     6533    return TRUE;
     6534  }
     6535  gfan::ZMatrix zm1 = intmat2ZMatrix(rays);
     6536  gfan::ZMatrix zm2 = intmat2ZMatrix(linSpace);
     6537  gfan::ZCone* zc = new gfan::ZCone();
     6538  *zc = gfan::ZCone::givenByRays(zm1, zm2);
     6539  //k should be passed on to zc; not available yet
     6540  res->data = (char *)zc;
     6541  return FALSE;
     6542}
     6543static BOOLEAN jjCONENORMALS3(leftv res, leftv u, leftv v, leftv w)
     6544{
     6545  /* method for generating a cone object from inequalities, equations,
     6546     and an integer k;
     6547     valid parametrizations: (intmat, intmat, int);
    61656548     Errors will be invoked in the following cases:
    6166      - string is not 'dim';
    6167      Any negative value will be converted to -1 signaling
    6168      that the dim is unknown. */
    6169   Cone* c = (Cone*)u->Data();
    6170   char* prop = (char*)v->Data();
    6171   int value = (int)(long)w->Data();
    6172 
    6173   if (strcmp(prop, "dim") == 0)
    6174     c->setDim(value);
    6175   else
    6176   {
    6177     Werror("unexpected cone property '%s'", prop);
    6178     return TRUE;
    6179   }
    6180 
    6181   return FALSE;
    6182 }
    6183 static BOOLEAN jjADJACENCY2(leftv res, leftv u, leftv v, leftv w)
    6184 {
    6185   /* method for retrieving the adjacency information concerning
    6186      two maximal cones of the given fan;
     6549     - u and v have different numbers of columns,
     6550     - k not in [0..3];
     6551     if the 2^0-bit of k is set, then ... */
     6552  intvec* inequs = (intvec *)u->CopyD(INTVEC_CMD);
     6553  intvec* equs = (intvec *)v->CopyD(INTVEC_CMD);
     6554  if (inequs->cols() != equs->cols())
     6555  {
     6556    Werror("expected same number of columns but got %d vs. %d",
     6557           inequs->cols(), equs->cols());
     6558    return TRUE;
     6559  }
     6560  int k = (int)(long)w->Data();
     6561  if ((k < 0) || (k > 3))
     6562  {
     6563    WerrorS("expected int argument in [0..3]");
     6564    return TRUE;
     6565  }
     6566  gfan::ZMatrix zm1 = intmat2ZMatrix(inequs);
     6567  gfan::ZMatrix zm2 = intmat2ZMatrix(equs);
     6568  gfan::ZCone* zc = new gfan::ZCone(zm1, zm2, k);
     6569  res->data = (char *)zc;
     6570  return FALSE;
     6571}
     6572static BOOLEAN jjADDADJ1(leftv res, leftv u, leftv v, leftv w)
     6573{
     6574  /* method for feeding adjacency information into the given fan;
    61876575     valid parametrizations: (fan, int, int),
    61886576     Errors will be invoked in the following cases:
    6189      - a maximal cone index is out of range [1..m],
    6190        where m is the number of maximal cones in the given fan,
    6191      - the two specified maximal cones are not adjacent,
    6192      - the two specified maximal cones are adjacent but the
    6193        intersection facet has not been stored in the fan */
     6577     - a maximal cone index is out of range [0..m-1],
     6578       where m is the number of maximal cones in the given fan;
     6579     - the two indices coincide */
    61946580  Fan* f = (Fan*)u->Data();
    6195   int maxCone1 = (int)(long)v->Data();
    6196   int maxCone2 = (int)(long)w->Data();
    6197   int nMaxCones = f->getMaxCones()->nr + 1;
    6198   if ((maxCone1 < 1) || (nMaxCones < maxCone1))
    6199   {
    6200     Werror("1st index %d out of range [1..%d]",
    6201            maxCone1, nMaxCones);
    6202     return TRUE;
    6203   }
    6204   if ((maxCone2 < 1) || (nMaxCones < maxCone2))
    6205   {
    6206     Werror("2nd index %d out of range [1..%d]",
    6207            maxCone2, nMaxCones);
    6208     return TRUE;
    6209   }
    6210   Cone* result = (Cone*)f->getAdjacencyFacet(maxCone1, maxCone2);
    6211   if (result->isNoAdj())
    6212   {
    6213     WerrorS("specified cones are not adjacent");
    6214     return TRUE;
    6215   }
    6216   if (result->isNoFacet())
    6217   {
    6218     Werror("specified cones are adjacent, %s",
    6219            "but there is no facet information available");
    6220     return TRUE;
    6221   }
    6222   res->data = (char*)result;
     6581  int i = (int)(long)v->Data();
     6582  int j = (int)(long)w->Data();
     6583  int n = f->getNumberOfMaxCones();
     6584  if (n == 0)
     6585  {
     6586    WerrorS("no maximal cones defined in the given fan");
     6587    return TRUE;
     6588  }
     6589  if ((i < 0) || (n <= i))
     6590  {
     6591    Werror("1st cone index %d out of range [0..%d]", i, n - 1);
     6592    return TRUE;
     6593  }
     6594  if ((j < 0) || (n <= j))
     6595  {
     6596    Werror("2nd cone index %d out of range [0..%d]", j, n - 1);
     6597    return TRUE;
     6598  }
     6599  if (i == j)
     6600  {
     6601    WerrorS("expected two distinct maximal cone indices");
     6602    return TRUE;
     6603  }
     6604  f->addAdjacency(i, j);
     6605  return FALSE;
     6606}
     6607static BOOLEAN jjADDADJ2(leftv res, leftv u, leftv v, leftv w)
     6608{
     6609  /* method for feeding adjacency information into the given fan;
     6610     valid parametrizations: (fan, int, intvec);
     6611     This method sets all adjacencies regarding the maximal cone
     6612     with index = second argument simultaneously.
     6613     Errors will be invoked in the following cases:
     6614     - a maximal cone index is out of range [0..m-1],
     6615       where m is the number of maximal cones in the given fan;
     6616     - the index (1st argument) appears in the intvec (2nd arg.) */
     6617  Fan* f = (Fan*)u->Data();
     6618  int i = (int)(long)v->Data();
     6619  intvec* jj = (intvec*)w->Data();
     6620  int n = f->getNumberOfMaxCones();
     6621  if (n == 0)
     6622  {
     6623    WerrorS("no maximal cones defined in the given fan");
     6624    return TRUE;
     6625  }
     6626  if ((i < 0) || (n <= i))
     6627  {
     6628    Werror("1st cone index %d out of range [0..%d]", i, n - 1);
     6629    return TRUE;
     6630  }
     6631  for (int j = 0; j < jj->length(); j++)
     6632  {
     6633    if (((*jj)[j] < 0) || (n <= (*jj)[j]))
     6634    {
     6635      Werror("cone index %d out of range [0..%d]", (*jj)[j], n - 1);
     6636      return TRUE;
     6637    }
     6638    if ((*jj)[j] == i)
     6639    {
     6640      Werror("unexpectedly found int argument %d in intvec argument", i);
     6641      return TRUE;
     6642    }
     6643  }
     6644  f->addAdjacencies(i, jj);
    62236645  return FALSE;
    62246646}
     
    63006722  return b;
    63016723}
     6724#ifdef HAVE_FANS
     6725static BOOLEAN jjSETPROP1(leftv res, leftv INPUT)
     6726{
     6727  /* method for setting fan properties;
     6728     valid parametrizations: (fan, string, int),
     6729     Errors will be invoked in the following cases:
     6730     - types are not correct,
     6731     - string is neither of 'dim', 'complete', 'simplicial',
     6732       and 'pure';
     6733     A value 0 means that the property is not fulfilled.
     6734     1 means it is. -1 means that the answer is unknown.
     6735     Any value other than 0 and 1 will be converted to -1;
     6736     except for dim: Here, only negative values will be converted
     6737     to -1. */
     6738  leftv u = INPUT;
     6739  leftv v = u->next;
     6740  leftv w = v->next;
     6741  if (u->Typ() != FAN_CMD)
     6742  {
     6743    Werror("expected a fan as 1st argument");
     6744    return TRUE;
     6745  }
     6746  if (v->Typ() != STRING_CMD)
     6747  {
     6748    Werror("expected a string as 2nd argument");
     6749    return TRUE;
     6750  }
     6751  if (w->Typ() != INT_CMD)
     6752  {
     6753    Werror("expected an int as 3rd argument");
     6754    return TRUE;
     6755  }
     6756
     6757  Fan* f = (Fan*)u->Data();
     6758  char* prop = (char*)v->Data();
     6759  int value = (int)(long)w->Data();
     6760
     6761  if      (strcmp(prop, "ambientdim") == 0)
     6762  {
     6763    Werror("ambient dimension of a fan cannot be set (implicitely given)");
     6764    return TRUE;
     6765  }
     6766  else if (strcmp(prop, "dim")        == 0)
     6767    f->setDim(value);
     6768  else if (strcmp(prop, "complete")   == 0)
     6769    f->setComplete(value);
     6770  else if (strcmp(prop, "simplicial") == 0)
     6771    f->setSimplicial(value);
     6772  else if (strcmp(prop, "pure")       == 0)
     6773    f->setPure(value);
     6774  else
     6775  {
     6776    Werror("unexpected fan property '%s'", prop);
     6777    return TRUE;
     6778  }
     6779
     6780  return FALSE;
     6781}
     6782static BOOLEAN jjSETPROP2(leftv res, leftv INPUT)
     6783{
     6784  /* method for setting cone properties;
     6785     valid parametrizations: (fan, int, string, int),
     6786     Errors will be invoked in the following cases:
     6787     - types are not correct,
     6788     - string is neither of 'dim', 'multiplicity', and 'weight',
     6789     - no maximal cones defined in the given fan,
     6790     - maximal cone index is out of range;
     6791     Any negative value will be converted to -1. */
     6792  leftv u = INPUT;    /* a fan */
     6793  leftv v = u->next;  /* a maximal cone index */
     6794  leftv w = v->next;  /* a string */
     6795  leftv x = w->next;  /* an int value */
     6796  if (u->Typ() != FAN_CMD)
     6797  {
     6798    Werror("expected a fan as 1st argument");
     6799    return TRUE;
     6800  }
     6801  if (v->Typ() != INT_CMD)
     6802  {
     6803    Werror("expected an int as 2nd argument");
     6804    return TRUE;
     6805  }
     6806  if (w->Typ() != STRING_CMD)
     6807  {
     6808    Werror("expected a string as 3rd argument");
     6809    return TRUE;
     6810  }
     6811  if (x->Typ() != INT_CMD)
     6812  {
     6813    Werror("expected an int as 4th argument");
     6814    return TRUE;
     6815  }
     6816
     6817  Fan* f = (Fan*)u->Data();
     6818  int index = (int)(long)v->Data();
     6819  char* prop = (char*)w->Data();
     6820  int value = (int)(long)x->Data();
     6821
     6822  int n = f->getNumberOfMaxCones();
     6823  if (n == 0)
     6824  {
     6825    WerrorS("no maximal cones defined in the given fan");
     6826    return TRUE;
     6827  }
     6828  if ((index < 0) || (n <= index))
     6829  {
     6830    Werror("cone index %d out of range [0..%d]", index, n - 1);
     6831    return TRUE;
     6832  }
     6833
     6834  if      (strcmp(prop, "dim")        == 0)
     6835    f->setConeDim(index, value);
     6836  else if (strcmp(prop, "multiplicity")   == 0)
     6837    f->setConeMultiplicity(index, value);
     6838  else if (strcmp(prop, "weight") == 0)
     6839    f->setConeWeight(index, value);
     6840  else
     6841  {
     6842    Werror("unexpected cone property '%s'", prop);
     6843    return TRUE;
     6844  }
     6845
     6846  return FALSE;
     6847}
     6848static BOOLEAN jjADDMCONE(leftv res, leftv INPUT)
     6849{
     6850  /* method for adding a maximal cones to the given fan;
     6851     valid parametrizations: (fan, intvec/0, intvec/0),
     6852     where not both intvec arguments may be the int zero.
     6853     Errors will be invoked in the following cases:
     6854     - 2nd and 3rd argument are int's,
     6855     - an index in one of the intvec's is out of range;
     6856     In case of an error addition of the cone fails. */
     6857  leftv u = INPUT;
     6858  leftv v = u->next;
     6859  leftv w = v->next;
     6860  Fan* f;
     6861  intvec* ii = NULL;
     6862  intvec* jj = NULL;
     6863  int n;
     6864  if (u->Typ() != FAN_CMD)
     6865  {
     6866    Werror("expected a fan as 1st argument");
     6867    return TRUE;
     6868  }
     6869  else { f = (Fan*)u->Data(); }
     6870  if (v->Typ() == INTVEC_CMD)
     6871  {
     6872    ii = (intvec*)v->Data();
     6873    n = f->getNumberOfMaxRays();
     6874    for (int i = 0; i < ii->length(); i++)
     6875    if (((*ii)[i] < 1) || (n < (*ii)[i]))
     6876    {
     6877      Werror("max. ray index %d out of range [1..%d]", (*ii)[i], n);
     6878      return TRUE;
     6879    }
     6880  }
     6881  else if ((v->Typ() != INT_CMD) || ((int)(long)v->Data() != 0))
     6882  {
     6883    Werror("expected an intvec or the int 0 as 2nd argument");
     6884    return TRUE;
     6885  }
     6886  if (w->Typ() == INTVEC_CMD)
     6887  {
     6888    jj = (intvec*)w->Data();
     6889    n = f->getNumberOfFacetNormals();
     6890    for (int j = 0; j < jj->length(); j++)
     6891    if (((*jj)[j] < 1) || (n < (*jj)[j]))
     6892    {
     6893      Werror("facet normal index %d out of range [1..%d]", (*jj)[j], n);
     6894      return TRUE;
     6895    }
     6896  }
     6897  else if ((w->Typ() != INT_CMD) || ((int)(long)w->Data() != 0))
     6898  {
     6899    Werror("expected an intvec or the int 0 as 3rd argument");
     6900    return TRUE;
     6901  }
     6902  f->addMaxCone(ii, jj);
     6903  return FALSE;
     6904}
     6905#endif /* HAVE_FANS */
    63026906static BOOLEAN jjCALL3ARG(leftv res, leftv u)
    63036907{
     
    67447348  return FALSE;
    67457349}
    6746 #ifdef HAVE_FANS
    6747 static BOOLEAN jjADDADJ(leftv res, leftv v)
    6748 {
    6749   /* method for adding one or more adjacencies between pairs of
    6750      maximal cones of the given fan;
    6751      valid parametrizations: (fan, int, int, cone),
    6752                              (fan, int, int, 0), or
    6753                              (fan, intvec, intvec, list),
    6754      where in the latter case, the list entries must either be
    6755      of type Cone* or the integer zero;
    6756      Errors will be invoked in the following cases:
    6757      - we have none of the above parametrizations,
    6758      - intvecs and list have different lengths,
    6759      - int's resp. intvec entries are out of range [1..m], where
    6760        m is the number of maximal cones in the given fan,
    6761      - int's are equal resp. intvec entries at same positions
    6762        are equal */
    6763   if ((v == NULL) || (v->next == NULL) ||
    6764       (v->next->next == NULL) || (v->next->next->next == NULL) ||
    6765       (v->next->next->next->next != NULL))
    6766   {
    6767     WerrorS("expected exactly four arguments as input");
    6768     return TRUE;
    6769   }
    6770   Fan* f = NULL;
    6771   int i; intvec* iv;
    6772   int j; intvec* jv;
    6773   Cone* c = NULL; lists L;
    6774   leftv x = v; bool listCase = false;
    6775   if (x->Typ() == FAN_CMD)
    6776     f = (Fan*)x->Data();
    6777   else
    6778   {
    6779     WerrorS("expected fan as 1st argument");
    6780     return TRUE;
    6781   }
    6782   x = x->next;
    6783   if      (x->Typ() == INT_CMD)
    6784     i = (int)(long)x->Data();
    6785   else if (x->Typ() == INTVEC_CMD)
    6786   {
    6787     iv = (intvec*)x->Data(); listCase = true;
    6788   }
    6789   else
    6790   {
    6791     WerrorS("expected int or intvec as 2nd argument");
    6792     return TRUE;
    6793   }
    6794   x = x->next;
    6795   if (listCase)
    6796   {
    6797     if ((x->Typ() != INTVEC_CMD) || ((x->next->Typ() != LIST_CMD)))
    6798     {
    6799       Werror("expected (fan, int, int, cone/0) %s",
    6800              "or (fan, intvec, intvec, list)");
    6801       return TRUE;
    6802     }
    6803     else jv = (intvec*)x->Data();
    6804     x = x->next;
    6805     L = (lists)x->Data();
    6806   }
    6807   else
    6808   {
    6809     if ((x->Typ() != INT_CMD) ||
    6810         ((x->next->Typ() != CONE_CMD) && (x->next->Typ() != INT_CMD)))
    6811     {
    6812       Werror("expected (fan, int, int, cone/0) %s",
    6813              "or (fan, intvec, intvec, list)");
    6814       return TRUE;
    6815     }
    6816     else j = (int)(long)x->Data();
    6817     x = x->next;
    6818     if ((x->Typ() == INT_CMD) && ((int)(long)x->Data() != 0))
    6819     {
    6820       WerrorS("expected (fan, int, int, cone/0)");
    6821       return TRUE;
    6822     }
    6823     if (x->Typ() != INT_CMD) c = (Cone*)x->Data();
    6824   }
    6825   int n = f->getMaxCones()->nr + 1;
    6826   if (!listCase)
    6827   {
    6828     if ((i < 1) || (n < i))
    6829     { Werror("2nd argument %d out of range [1..%d]", i, n); }
    6830     if ((j < 1) || (n < j))
    6831     { Werror("3rd argument %d out of range [1..%d]", j, n); }
    6832     if (i == j)
    6833     { WerrorS("2nd and 3rd argument are equal"); }
    6834     f->addAdjacency(i, j, c);
    6835   }
    6836   else
    6837   {
    6838     if (iv->length() != jv->length())
    6839       WerrorS("2nd and 3rd argument have different lengths");
    6840     if (iv->length() != L->nr + 1)
    6841       WerrorS("2nd and 4th argument have different lengths");
    6842     for (i = 0; i < iv->length(); i++)
    6843     {
    6844       if (((*iv)[i] < 1) || (n < (*iv)[i]))
    6845         Werror("index %d at position %d in 2nd argument out of range [1..%d]",
    6846                (*iv)[i], i + 1, n);
    6847     }
    6848     for (j = 0; j < jv->length(); j++)
    6849     {
    6850       if (((*jv)[j] < 1) || (n < (*jv)[j]))
    6851         Werror("index %d at position %d in 3rd argument out of range [1..%d]",
    6852                (*jv)[j], j + 1, n);
    6853       if ((*iv)[j] == (*jv)[j])
    6854         Werror("indices in 2nd and 3rd argument at position %d equal", j + 1);
    6855     }
    6856     for (i = 0; i < L->nr + 1; i++)
    6857     {
    6858       if ((L->m[i].Typ() != CONE_CMD) &&
    6859           ((L->m[i].Typ() != INT_CMD) || ((int)(long)L->m[i].Data() != 0)))
    6860         Werror("entry at position %d in 4th argument neither cone nor int 0",
    6861                i + 1);
    6862     }
    6863     f->addAdjacencies(iv, jv, L);
    6864   }
    6865   return FALSE;
    6866 }
    6867 #endif /* HAVE_FANS */
    68687350static BOOLEAN jjINTVEC_PL(leftv res, leftv v)
    68697351{
  • Singular/ipassign.cc

    rdef863 rd4df72  
    4141#include <kernel/sca.h>
    4242#include <Singular/Fan.h>
    43 #include <Singular/Cone.h>
     43#include <gfanlib/gfanlib.h>
    4444
    4545/*=================== proc =================*/
     
    348348  if (res->data!=NULL)
    349349  {
    350     Cone* ccc = (Cone*)res->data;
     350    gfan::ZCone* zc = (gfan::ZCone*)res->data;
    351351    res->data = NULL;
    352     delete ccc;
    353   }
    354   Cone* ccc = (Cone*)a->CopyD(CONE_CMD);
    355   res->data=(void*)ccc;
     352    delete zc;
     353  }
     354  gfan::ZCone* zc = (gfan::ZCone*)a->CopyD(CONE_CMD);
     355  res->data=(void*)zc;
    356356  return FALSE;
    357357}
     
    13941394    return TRUE;
    13951395  }
    1396   if ((facetNs != NULL) && (linSpace != NULL) &&
    1397       (facetNs->rows() != linSpace->rows()))
    1398   {
    1399     WerrorS("vector space dims do not agree (2nd vs. 3rd argument)");
    1400     return TRUE;
    1401   }
    14021396
    14031397  if (IDDATA((idhdl)l->data) != NULL)
     
    14131407{
    14141408  /* method for generating a cone;
    1415      valid parametrizations: (fan, intvec or 0, intvec or 0),
    1416      The intvec's capture indices of the maximal rays resp.
    1417      facet normals of the given fan.
    1418      2nd and 3rd argument may be the int 0, but not simultaneously.
     1409     valid parametrizations: int (ambient dimension),
    14191410     Errors will be invoked in the following cases:
    1420      - 2nd and 3rd argument simultaneously the int 0,
    1421      - invalid index for maximal row or facet normal */
    1422   Fan* fff = NULL;           /* the Fan where maximal rays and/or
    1423                                 facet normals are stored */
    1424   intvec* maxRays = NULL;    /* indices of maximal rays */
    1425   intvec* facetNs = NULL;    /* indices of facet normals */
    1426 
    1427   leftv x = r;
    1428   if (x->Typ() != FAN_CMD)
    1429   {
    1430     WerrorS("expected a fan as 1st argument");
    1431     return TRUE;
    1432   }
    1433   else
    1434   {
    1435     fff = (Fan*)x->Data();
    1436   }
    1437   x = x->next;
    1438   if (x->Typ() == INTVEC_CMD) maxRays = (intvec*)x->Data();
    1439   else if ((x->Typ() != INT_CMD) ||
    1440            ((x->Typ() == INT_CMD) && ((int)(long)x->Data() != 0)))
    1441   {
    1442     WerrorS("expected '0' or an intvec as 2nd argument");
    1443     return TRUE;
    1444   }
    1445   x = x->next;
    1446   if (x->Typ() == INTVEC_CMD) facetNs = (intvec*)x->Data();
    1447   else if ((x->Typ() != INT_CMD) ||
    1448            ((x->Typ() == INT_CMD) && ((int)(long)x->Data() != 0)))
    1449   {
    1450     WerrorS("expected '0' or an intvec as 3rd argument");
    1451     return TRUE;
    1452   }
    1453   if ((maxRays == NULL) && (facetNs == NULL))
    1454   {
    1455     WerrorS("expected 2nd or 3rd argument to be a valid intvec");
    1456     return TRUE;
    1457   }
    1458  
    1459   int check = Cone::checkConeData(fff, maxRays, facetNs);
    1460   if (check > 0)
    1461   {
    1462     Werror("invalid index %d for maximal ray at position %d",
    1463            (int)(long)((*maxRays)[check - 1]), check);
    1464     return TRUE;
    1465   }
    1466   else if (check < 0)
    1467   {
    1468     char h[150];
    1469     sprintf(h, "invalid index %d for facet normal at position %d",
    1470                (int)(long)((*facetNs)[-check - 1]), -check);
    1471     WerrorS(h);
    1472     return TRUE;
    1473   }
    1474 
     1411     - argument < 0 */
     1412  if (r->Typ() != INT_CMD)
     1413  {
     1414    WerrorS("expected an int as argument");
     1415    return TRUE;
     1416  }
     1417  int ambientDim = (int)(long)r->Data();
     1418  if (ambientDim < 0)
     1419  {
     1420    Werror("expected an int >= 0, but got %d", ambientDim);
     1421    return TRUE;
     1422  }
    14751423  if (IDDATA((idhdl)l->data) != NULL)
    14761424  {
    1477     Cone* ccc = (Cone*)IDDATA((idhdl)l->data);
    1478     delete ccc;
    1479   }
    1480   Cone* ccc = new Cone(fff, maxRays, facetNs);
    1481   IDDATA((idhdl)l->data) = (char*)ccc;
     1425    gfan::ZCone* zc = (gfan::ZCone*)IDDATA((idhdl)l->data);
     1426    delete zc;
     1427  }
     1428  gfan::ZCone* zc = new gfan::ZCone(ambientDim);
     1429  IDDATA((idhdl)l->data) = (char*)zc;
    14821430  return FALSE;
    14831431}
     
    15421490    rl=r->listLength();
    15431491    if (rl==1)
    1544     {
     1492    {               
     1493#ifdef HAVE_FANS
     1494      if ((l->Typ() == CONE_CMD) && (r->Typ() == INT_CMD))
     1495        return jjAssignCone(l, r);
     1496#endif
    15451497      /* system variables = ... */
    15461498      if(((l->rtyp>=VECHO)&&(l->rtyp<=VPRINTLEVEL))
     
    16071559    {
    16081560      return jjAssignFan(l, r);
    1609     }
    1610     else if ((lt == CONE_CMD) && (rl == 3))
    1611     {
    1612       return jjAssignCone(l, r);
    16131561    }
    16141562#endif /* HAVE_FANS */
  • Singular/ipid.cc

    rdef863 rd4df72  
    3030#include <Singular/ipid.h>
    3131#include <Singular/Fan.h>
    32 #include <Singular/Cone.h>
     32#include <gfanlib/gfanlib.h>
    3333
    3434#ifdef HAVE_DYNAMIC_LOADING
     
    201201      IDPACKAGE(h)->loaded = FALSE;
    202202    }
     203#ifdef HAVE_FANS
     204    else if (t == FAN_CMD)
     205    {
     206      IDSTRING(h) = (char*)(new Fan());
     207    }
     208    else if (t == CONE_CMD)
     209    {
     210      IDSTRING(h) = (char*)(new gfan::ZCone());
     211    }
     212#endif /* HAVE_FANS */
    203213  }
    204214  // --------------------------------------------------------
  • Singular/subexpr.cc

    rdef863 rd4df72  
    1212#include <ctype.h>
    1313#include <unistd.h>
     14#include <sstream>
    1415
    1516#include <kernel/mod2.h>
     
    3940#include <Singular/subexpr.h>
    4041#include <Singular/Fan.h>
    41 #include <Singular/Cone.h>
     42#include <gfanlib/gfanlib.h>
    4243
    4344omBin sSubexpr_bin = omGetSpecBin(sizeof(_ssubexpr));
     
    6364  }
    6465  return n;
     66}
     67
     68std::string toString(gfan::ZMatrix const &m, char *tab=0)
     69{
     70  std::stringstream s;
     71
     72  for(int i=0;i<m.getHeight();i++)
     73    {
     74      if(tab)s<<tab;
     75      for(int j=0;j<m.getWidth();j++)
     76        {
     77          s<<m[i][j];
     78          if(i+1!=m.getHeight() || j+1!=m.getWidth())
     79            {
     80              s<<",";
     81            }
     82        }
     83      s<<std::endl;
     84    }
     85  return s.str();
     86}
     87
     88std::string toPrintString(gfan::ZMatrix const &m, int fieldWidth, char *tab=0)
     89{
     90  std::stringstream s;
     91
     92  for(int i=0;i<m.getHeight();i++)
     93    {
     94      if(tab)s<<tab;
     95      for(int j=0;j<m.getWidth();j++)
     96        {
     97          std::stringstream temp;
     98          temp<<m[i][j];
     99          std::string temp2=temp.str();
     100          for(int k=temp2.size();k<fieldWidth;k++)s<<" ";
     101          s<<temp2; 
     102          if(i+1!=m.getHeight() || j+1!=m.getWidth())
     103            {
     104              s<<" ";
     105            }
     106        }
     107      s<<std::endl;
     108    }
     109  return s.str();
     110}
     111
     112std::string toString(gfan::ZCone const &c)
     113{
     114  std::stringstream s;
     115  gfan::ZMatrix i=c.getInequalities();
     116  gfan::ZMatrix e=c.getEquations();
     117  s<<"AMBIENT_DIM"<<std::endl;
     118  s<<c.ambientDimension()<<std::endl;
     119  s<<"INEQUALITIES"<<std::endl;
     120  s<<toString(i);
     121  s<<"EQUATIONS"<<std::endl;
     122  s<<toString(e);
     123  return s.str();
     124}
     125
     126std::string toPrintString(gfan::ZCone const &c, char *nameOfCone)
     127{
     128  std::stringstream s;
     129  gfan::ZMatrix i=c.getInequalities();
     130  gfan::ZMatrix e=c.getEquations();
     131  s<<nameOfCone<<"[1]:"<<std::endl;
     132  s<<c.ambientDimension()<<std::endl;
     133  s<<nameOfCone<<"[2]:"<<std::endl;
     134  s<<toPrintString(i,6,"   ");
     135  s<<nameOfCone<<"[3]:"<<std::endl;
     136  s<<toPrintString(e,6,"   ");
     137  return s.str();
    65138}
    66139
     
    508581    case CONE_CMD:
    509582      {
    510         Cone* ccc = (Cone*)d;
    511         Cone* ggg = new Cone(*ccc);
    512         return ggg;
     583        gfan::ZCone* zc = (gfan::ZCone*)d;
     584        gfan::ZCone* newZc = new gfan::ZCone(*zc);
     585        return newZc;
    513586      }
    514587#endif /* HAVE_FANS */
     
    812885        case CONE_CMD:
    813886        {
    814           Cone* ccc = (Cone*)d;
    815           s = ccc->toString();
    816           char* ns = (char*) omAlloc(strlen(s) + 10);
    817           sprintf(ns, "%s", s);
     887          gfan::ZCone* zc = (gfan::ZCone*)d;
     888          std::string s = toString(*zc);
     889          char* ns = (char*) omAlloc(strlen(s.c_str()) + 10);
     890          sprintf(ns, "%s", s.c_str());
    818891          omCheckAddr(ns);
    819892          omFree(s);
  • Singular/tok.h

    rdef863 rd4df72  
    5959//#ifdef HAVE_FANS
    6060  CONE_CMD,
     61  CONELINK_CMD,
     62  CONERAYS_CMD,
     63  CONENORMALS_CMD,
     64  CONTAINS_CMD,
     65  FACECONT_CMD,
     66  INTERSC_CMD,
    6167//#endif /* HAVE_FANS */
    6268  CONTENT_CMD,
Note: See TracChangeset for help on using the changeset viewer.