Changeset 063900 in git


Ignore:
Timestamp:
Feb 22, 2011, 6:00:50 PM (13 years ago)
Author:
Frank Seelisch <seelisch@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', 'b4f17ed1d25f93d46dbe29e4b499baecc2fd51bb')
Children:
8080db95916d784e48feaaaebaba9e930533ee83
Parents:
44e1b7f0f7a27c9f7b399a40751abcd38bf57a36
Message:
further changes cones-->blackbox

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

Legend:

Unmodified
Added
Removed
  • Singular/bbcone.cc

    r44e1b7f r063900  
    88#include <gfanlib/gfanlib.h>
    99#include <Singular/bbcone.h>
     10#include <ipshell.h>
     11#include <kernel/intvec.h>
    1012#include <sstream>
    1113
    12 
    13 
    14 std::string toString1(gfan::ZMatrix const &m, char *tab=0)
     14int coneID;
     15
     16int integerToInt(gfan::Integer const &V, bool &ok)
     17{
     18  mpz_t v;
     19  mpz_init(v);
     20  V.setGmp(v);
     21  int ret=0;
     22  if(mpz_fits_sint_p(v))
     23    ret=mpz_get_si(v);
     24  else
     25    ok=false;
     26  mpz_clear(v);
     27  return ret;
     28}
     29
     30intvec* zVector2Intvec(const gfan::ZVector zv)
     31{
     32  int d=zv.size();
     33  intvec* iv = new intvec(1, d, 0);
     34  bool ok = true;
     35  for(int i=1;i<=d;i++)
     36    IMATELEM(*iv, 1, i) = integerToInt(zv[i-1], ok);
     37  if (!ok) WerrorS("overflow while converting a gfan::ZVector to an intvec");
     38  return iv;
     39}
     40
     41intvec* zMatrix2Intvec(const gfan::ZMatrix zm)
     42{
     43  int d=zm.getHeight();
     44  int n=zm.getWidth();
     45  intvec* iv = new intvec(d, n, 0);
     46  bool ok = true;
     47  for(int i=1;i<=d;i++)
     48    for(int j=1;j<=n;j++)
     49      IMATELEM(*iv, i, j) = integerToInt(zm[i-1][j-1], ok);
     50  if (!ok) WerrorS("overflow while converting a gfan::ZMatrix to an intmat");
     51  return iv;
     52}
     53
     54gfan::ZMatrix intmat2ZMatrix(const intvec* iMat)
     55{
     56  int d=iMat->rows();
     57  int n=iMat->cols();
     58  gfan::ZMatrix ret(d,n);
     59  for(int i=0;i<d;i++)
     60    for(int j=0;j<n;j++)
     61      ret[i][j]=IMATELEM(*iMat, i+1, j+1);
     62  return ret;
     63}
     64
     65/* expects iMat to have just one row */
     66gfan::ZVector intvec2ZVector(const intvec* iVec)
     67{
     68  int n =iVec->rows();
     69  gfan::ZVector ret(n);
     70  for(int j=0;j<n;j++)
     71    ret[j]=IMATELEM(*iVec, j+1, 1);
     72  return ret;
     73}
     74
     75std::string toString(gfan::ZMatrix const &m, char *tab=0)
    1576{
    1677  std::stringstream s;
     
    3293}
    3394
    34 std::string toString2(gfan::ZCone const &c)
     95std::string toString(gfan::ZCone const &c)
    3596{
    3697  std::stringstream s;
     
    40101  s<<c.ambientDimension()<<std::endl;
    41102  s<<"INEQUALITIES"<<std::endl;
    42   s<<toString1(i);
     103  s<<toString(i);
    43104  s<<"EQUATIONS"<<std::endl;
    44   s<<toString1(e);
     105  s<<toString(e);
    45106  return s.str();
    46107}
    47108
     109void *bbcone_Init(blackbox *b)
     110{
     111  return (void*)(new gfan::ZCone());
     112}
     113
    48114BOOLEAN bbcone_Assign(leftv l, leftv r)
    49115{
    50   gfan::ZCone* newZc = new gfan::ZCone();
     116  gfan::ZCone* newZc;
     117  if (r==NULL)
     118  {
     119    if (l->Data()!=NULL)
     120    {   
     121      gfan::ZCone* zd = (gfan::ZCone*)l->Data();
     122      delete zd;
     123    }
     124    newZc = new gfan::ZCone();
     125  }
     126  else if (r->Typ()==l->Typ())
     127  {
     128    if (l->Data()!=NULL)
     129    {   
     130      gfan::ZCone* zd = (gfan::ZCone*)l->Data();
     131      delete zd;
     132    }
     133    gfan::ZCone* zc = (gfan::ZCone*)r->Data();
     134    newZc = new gfan::ZCone(*zc);
     135  }
     136  else if (r->Typ()==INT_CMD)
     137  {
     138    int ambientDim = (int)(long)r->Data();
     139    if (ambientDim < 0)
     140    {
     141      Werror("expected an int >= 0, but got %d", ambientDim);
     142      return TRUE;
     143    }
     144    if (l->Data()!=NULL)
     145    {   
     146      gfan::ZCone* zd = (gfan::ZCone*)l->Data();
     147      delete zd;
     148    }
     149    newZc = new gfan::ZCone(ambientDim);
     150  }
     151  else
     152  {
     153    Werror("assign Type(%d) = Type(%d) not implemented",l->Typ(),r->Typ());
     154    return TRUE;
     155  }
     156 
    51157  if (l->rtyp==IDHDL)
    52158  {
     
    64170   else
    65171   {
    66      std::string s=toString2(*((gfan::ZCone*)d));
     172     std::string s=toString(*((gfan::ZCone*)d));
    67173     char* ns = (char*) omAlloc(strlen(s.c_str()) + 10);
    68174     sprintf(ns, "%s", s.c_str());
     
    86192  gfan::ZCone* newZc = new gfan::ZCone(*zc);
    87193  return newZc;
     194}
     195
     196static BOOLEAN jjCONERAYS1(leftv res, leftv v)
     197{
     198  /* method for generating a cone object from half-lines
     199     (cone = convex hull of the half-lines; note: there may be
     200     entire lines in the cone);
     201     valid parametrizations: (intmat) */
     202  intvec* rays = (intvec *)v->CopyD(INTVEC_CMD);
     203  gfan::ZMatrix zm = intmat2ZMatrix(rays);
     204  gfan::ZCone* zc = new gfan::ZCone();
     205  *zc = gfan::ZCone::givenByRays(zm, gfan::ZMatrix(0, zm.getWidth()));
     206  res->rtyp = coneID;
     207  res->data = (char *)zc;
     208  return FALSE;
     209}
     210
     211static BOOLEAN jjCONERAYS2(leftv res, leftv u, leftv v)
     212{
     213  /* method for generating a cone object from half-lines,
     214     and lines (any point in the cone being the sum of a point
     215     in the convex hull of the half-lines and a point in the span
     216     of the lines; the second argument may contain or entirely consist
     217     of zero rows);
     218     valid parametrizations: (intmat, intmat)
     219     Errors will be invoked in the following cases:
     220     - u and v have different numbers of columns */
     221  intvec* rays = (intvec *)u->CopyD(INTVEC_CMD);
     222  intvec* linSpace = (intvec *)v->CopyD(INTVEC_CMD);
     223  if (rays->cols() != linSpace->cols())
     224  {
     225    Werror("expected same number of columns but got %d vs. %d",
     226           rays->cols(), linSpace->cols());
     227    return TRUE;
     228  }
     229  gfan::ZMatrix zm1 = intmat2ZMatrix(rays);
     230  gfan::ZMatrix zm2 = intmat2ZMatrix(linSpace);
     231  gfan::ZCone* zc = new gfan::ZCone();
     232  *zc = gfan::ZCone::givenByRays(zm1, zm2);
     233  res->rtyp = coneID;
     234  res->data = (char *)zc;
     235  return FALSE;
     236}
     237
     238static BOOLEAN jjCONERAYS3(leftv res, leftv u, leftv v, leftv w)
     239{
     240  /* method for generating a cone object from half-lines,
     241     and lines (any point in the cone being the sum of a point
     242     in the convex hull of the half-lines and a point in the span
     243     of the lines), and an integer k;
     244     valid parametrizations: (intmat, intmat, int);
     245     Errors will be invoked in the following cases:
     246     - u and v have different numbers of columns,
     247     - k not in [0..3];
     248     if the 2^0-bit of k is set, then the lineality space is known
     249     to be the span of the provided lines;
     250     if the 2^1-bit of k is set, then the extreme rays are known:
     251     each half-line spans a (different) extreme ray */
     252  intvec* rays = (intvec *)u->CopyD(INTVEC_CMD);
     253  intvec* linSpace = (intvec *)v->CopyD(INTVEC_CMD);
     254  if (rays->cols() != linSpace->cols())
     255  {
     256    Werror("expected same number of columns but got %d vs. %d",
     257           rays->cols(), linSpace->cols());
     258    return TRUE;
     259  }
     260  int k = (int)(long)w->Data();
     261  if ((k < 0) || (k > 3))
     262  {
     263    WerrorS("expected int argument in [0..3]");
     264    return TRUE;
     265  }
     266  gfan::ZMatrix zm1 = intmat2ZMatrix(rays);
     267  gfan::ZMatrix zm2 = intmat2ZMatrix(linSpace);
     268  gfan::ZCone* zc = new gfan::ZCone();
     269  *zc = gfan::ZCone::givenByRays(zm1, zm2);
     270  //k should be passed on to zc; not available yet
     271  res->rtyp = coneID;
     272  res->data = (char *)zc;
     273  return FALSE;
     274}
     275
     276BOOLEAN cone_via_rays(leftv res, leftv args)
     277{
     278  leftv u = args;
     279  if ((u != NULL) && (u->Typ() == INTMAT_CMD))
     280  {
     281    if (u->next == NULL) return jjCONERAYS1(res, u);
     282  }
     283  leftv v = u->next;
     284  if ((v != NULL) && (v->Typ() == INTMAT_CMD))
     285  {
     286    if (v->next == NULL) return jjCONERAYS2(res, u, v);
     287  }
     288  leftv w = v->next;
     289  if ((w != NULL) && (w->Typ() == INT_CMD))
     290  {
     291    if (w->next == NULL) return jjCONERAYS3(res, u, v, w);
     292  }
     293  WerrorS("cone_via_rays: unexpected parameters");
     294  return TRUE;
     295}
     296
     297static BOOLEAN jjCONENORMALS1(leftv res, leftv v)
     298{
     299  /* method for generating a cone object from inequalities;
     300     valid parametrizations: (intmat) */
     301  intvec* inequs = (intvec *)v->CopyD(INTVEC_CMD);
     302  gfan::ZMatrix zm = intmat2ZMatrix(inequs);
     303  gfan::ZCone* zc = new gfan::ZCone(zm, gfan::ZMatrix(0, zm.getWidth()));
     304  res->rtyp = coneID;
     305  res->data = (char *)zc;
     306  return FALSE;
     307}
     308
     309static BOOLEAN jjCONENORMALS2(leftv res, leftv u, leftv v)
     310{
     311  /* method for generating a cone object from iequalities,
     312     and equations (...)
     313     valid parametrizations: (intmat, intmat)
     314     Errors will be invoked in the following cases:
     315     - u and v have different numbers of columns */
     316  intvec* inequs = (intvec *)u->CopyD(INTVEC_CMD);
     317  intvec* equs = (intvec *)v->CopyD(INTVEC_CMD);
     318  if (inequs->cols() != equs->cols())
     319  {
     320    Werror("expected same number of columns but got %d vs. %d",
     321           inequs->cols(), equs->cols());
     322    return TRUE;
     323  }
     324  gfan::ZMatrix zm1 = intmat2ZMatrix(inequs);
     325  gfan::ZMatrix zm2 = intmat2ZMatrix(equs);
     326  gfan::ZCone* zc = new gfan::ZCone(zm1, zm2);
     327  res->rtyp = coneID;
     328  res->data = (char *)zc;
     329  return FALSE;
     330}
     331
     332static BOOLEAN jjCONENORMALS3(leftv res, leftv u, leftv v, leftv w)
     333{
     334  /* method for generating a cone object from inequalities, equations,
     335     and an integer k;
     336     valid parametrizations: (intmat, intmat, int);
     337     Errors will be invoked in the following cases:
     338     - u and v have different numbers of columns,
     339     - k not in [0..3];
     340     if the 2^0-bit of k is set, then ... */
     341  intvec* inequs = (intvec *)u->CopyD(INTVEC_CMD);
     342  intvec* equs = (intvec *)v->CopyD(INTVEC_CMD);
     343  if (inequs->cols() != equs->cols())
     344  {
     345    Werror("expected same number of columns but got %d vs. %d",
     346           inequs->cols(), equs->cols());
     347    return TRUE;
     348  }
     349  int k = (int)(long)w->Data();
     350  if ((k < 0) || (k > 3))
     351  {
     352    WerrorS("expected int argument in [0..3]");
     353    return TRUE;
     354  }
     355  gfan::ZMatrix zm1 = intmat2ZMatrix(inequs);
     356  gfan::ZMatrix zm2 = intmat2ZMatrix(equs);
     357  gfan::ZCone* zc = new gfan::ZCone(zm1, zm2, k);
     358  res->rtyp = coneID;
     359  res->data = (char *)zc;
     360  return FALSE;
     361}
     362
     363BOOLEAN cone_via_normals(leftv res, leftv args)
     364{
     365  leftv u = args;
     366  if ((u != NULL) && (u->Typ() == INTMAT_CMD))
     367  {
     368    if (u->next == NULL) return jjCONENORMALS1(res, u);
     369  }
     370  leftv v = u->next;
     371  if ((v != NULL) && (v->Typ() == INTMAT_CMD))
     372  {
     373    if (v->next == NULL) return jjCONENORMALS2(res, u, v);
     374  }
     375  leftv w = v->next;
     376  if ((w != NULL) && (w->Typ() == INT_CMD))
     377  {
     378    if (w->next == NULL) return jjCONENORMALS3(res, u, v, w);
     379  }
     380  WerrorS("cone_via_normals: unexpected parameters");
     381  return TRUE;
     382}
     383
     384static BOOLEAN jjGETPROPC(leftv res, leftv u, leftv v)
     385{
     386  /* method for retrieving cone properties;
     387     valid parametrizations: (cone, string),
     388     Errors will be invoked in the following cases:
     389     - invalid property string (see below for valid ones) */
     390  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
     391  char* prop = (char*)v->Data();
     392  gfan::ZMatrix retMat;
     393  gfan::ZCone retCone;
     394  int retInt;
     395  gfan::ZVector retVec;
     396  int typeInfo;
     397
     398  /* ################ properties with return type intmat: ################## */
     399  if      (strcmp(prop, "INEQUALITIES") == 0)
     400  {
     401    retMat = zc->getInequalities();
     402    typeInfo = INTMAT_CMD;
     403  }
     404  else if (strcmp(prop, "EQUATIONS") == 0)
     405  {
     406    retMat = zc->getEquations();
     407    typeInfo = INTMAT_CMD;
     408  }
     409  else if (strcmp(prop, "FACETS") == 0)
     410  {
     411    retMat = zc->getFacets();
     412    typeInfo = INTMAT_CMD;
     413  }
     414  else if (strcmp(prop, "IMPLIED_EQUATIONS") == 0)
     415  {
     416    retMat = zc->getImpliedEquations();
     417    typeInfo = INTMAT_CMD;
     418  }
     419  else if (strcmp(prop, "GENERATORS_OF_SPAN") == 0)
     420  {
     421    retMat = zc->generatorsOfSpan();
     422    typeInfo = INTMAT_CMD;
     423  }
     424  else if (strcmp(prop, "GENERATORS_OF_LINEALITY_SPACE") == 0)
     425  {
     426    retMat = zc->generatorsOfLinealitySpace();
     427    typeInfo = INTMAT_CMD;
     428  }
     429  else if (strcmp(prop, "RAYS") == 0)
     430  {
     431    retMat = zc->extremeRays();
     432    typeInfo = INTMAT_CMD;
     433  }
     434  else if (strcmp(prop, "QUOTIENT_LATTICE_BASIS") == 0)
     435  {
     436    retMat = zc->quotientLatticeBasis();
     437    typeInfo = INTMAT_CMD;
     438  }
     439  else if (strcmp(prop, "LINEAR_FORMS") == 0)
     440  {
     441    retMat = zc->getLinearForms();
     442    typeInfo = INTMAT_CMD;
     443  }
     444  /* ################ properties with return type int: ################## */
     445  else if (strcmp(prop, "AMBIENT_DIM") == 0)
     446  {
     447    retInt = zc->ambientDimension();
     448    typeInfo = INT_CMD;
     449  }
     450  else if (strcmp(prop, "DIM") == 0)
     451  {
     452    retInt = zc->dimension();
     453    typeInfo = INT_CMD;
     454  }
     455  else if (strcmp(prop, "LINEALITY_DIM") == 0)
     456  {
     457    retInt = zc->dimensionOfLinealitySpace();
     458    typeInfo = INT_CMD;
     459  }
     460  else if (strcmp(prop, "MULTIPLICITY") == 0)
     461  {
     462    bool ok = true;
     463    retInt = integerToInt(zc->getMultiplicity(), ok);
     464    if (!ok)
     465      WerrorS("overflow while converting a gfan::Integer to an int");
     466    typeInfo = INT_CMD;
     467  }
     468  else if (strcmp(prop, "IS_ORIGIN") == 0)
     469  {
     470    retInt = zc->isOrigin() ? 1 : 0;
     471    typeInfo = INT_CMD;
     472  }
     473  else if (strcmp(prop, "IS_FULL_SPACE") == 0)
     474  {
     475    retInt = zc->isFullSpace() ? 1 : 0;
     476    typeInfo = INT_CMD;
     477  }
     478  else if (strcmp(prop, "SIMPLICIAL") == 0)
     479  {
     480    retInt = zc->isSimplicial() ? 1 : 0;
     481    typeInfo = INT_CMD;
     482  }
     483  else if (strcmp(prop, "CONTAINS_POSITIVE_VECTOR") == 0)
     484  {
     485    retInt = zc->containsPositiveVector() ? 1 : 0;
     486    typeInfo = INT_CMD;
     487  }
     488  /* ################ properties with return type ZCone: ################## */
     489  else if (strcmp(prop, "LINEALITY_SPACE") == 0)
     490  {
     491    retCone = zc->linealitySpace();
     492    typeInfo = CONE_CMD;
     493  }
     494  else if (strcmp(prop, "DUAL_CONE") == 0)
     495  {
     496    retCone = zc->dualCone();
     497    typeInfo = CONE_CMD;
     498  }
     499  else if (strcmp(prop, "NEGATED") == 0)
     500  {
     501    retCone = zc->negated();
     502    typeInfo = CONE_CMD;
     503  }
     504  /* ################ properties with return type intvec: ################## */
     505  else if (strcmp(prop, "SEMI_GROUP_GENERATOR") == 0)
     506  {
     507    /* test whether the cone's dim = dim of lin space + 1: */
     508    int d = zc->dimension();
     509    int dLS = zc->dimensionOfLinealitySpace();
     510    if (d == dLS + 1)
     511      retVec = zc->semiGroupGeneratorOfRay();
     512    else
     513    {
     514      Werror("expected dim of cone one larger than dim of lin space\n"
     515             "but got dimensions %d and %d", d, dLS);
     516    }
     517    typeInfo = INTVEC_CMD;
     518  }
     519  else if (strcmp(prop, "RELATIVE_INTERIOR_POINT") == 0)
     520  {
     521    retVec = zc->getRelativeInteriorPoint();
     522    typeInfo = INTVEC_CMD;
     523  }
     524  else if (strcmp(prop, "UNIQUE_POINT") == 0)
     525  {
     526    retVec = zc->getUniquePoint();
     527    typeInfo = INTVEC_CMD;
     528  }
     529  else
     530  {
     531    Werror("unexpected cone property '%s'", prop);
     532    return TRUE;
     533  }
     534
     535  res->rtyp = typeInfo;
     536  switch(typeInfo)
     537  {
     538    case INTMAT_CMD:
     539      res->data = (void*)zMatrix2Intvec(retMat);
     540      break;
     541    case INT_CMD:
     542      res->data = (void*)retInt;
     543      break;
     544    case CONE_CMD:
     545      res->data = (void*)new gfan::ZCone(retCone);
     546      break;
     547    case INTVEC_CMD:
     548      res->data = (void*)zVector2Intvec(retVec);
     549      break;
     550    default: ; /* should never be reached */
     551  }
     552  return FALSE;
     553}
     554
     555BOOLEAN getprop(leftv res, leftv args)
     556{
     557  leftv u = args;
     558  if ((u != NULL) && (u->Typ() == coneID))
     559  {
     560    leftv v = u->next;
     561    if ((v != NULL) && (v->Typ() == STRING_CMD))
     562    {
     563      if (v->next == NULL) return jjGETPROPC(res, u, v);
     564    }
     565  }
     566  WerrorS("getprop: unexpected parameters");
     567  return TRUE;
     568}
     569
     570BOOLEAN cone_intersect(leftv res, leftv args)
     571{
     572  leftv u = args;
     573  if ((u != NULL) && (u->Typ() == coneID))
     574  {
     575    leftv v = u->next;
     576    if ((v != NULL) && (v->Typ() == coneID))
     577    {
     578      gfan::ZCone* zc1 = (gfan::ZCone*)u->Data();
     579      gfan::ZCone* zc2 = (gfan::ZCone*)v->Data();
     580      int d1 = zc1->ambientDimension();
     581      int d2 = zc2->ambientDimension();
     582      if (d1 != d2)
     583        Werror("expected ambient dims of both cones to coincide\n"
     584               "but got %d and %d", d1, d2);
     585      gfan::ZCone zc3 = gfan::intersection(*zc1, *zc2);
     586      res->rtyp = coneID;
     587      res->data = (void *)new gfan::ZCone(zc3);
     588      return FALSE;
     589    }
     590  }
     591  WerrorS("cone_intersect: unexpected parameters");
     592  return TRUE;
     593}
     594
     595BOOLEAN cone_link(leftv res, leftv args)
     596{
     597  leftv u = args;
     598  if ((u != NULL) && (u->Typ() == coneID))
     599  {
     600    leftv v = u->next;
     601    if ((v != NULL) && (v->Typ() == INTVEC_CMD))
     602    {
     603      gfan::ZCone* zc = (gfan::ZCone*)u->Data();
     604      intvec* iv = (intvec*)v->Data();
     605      gfan::ZVector zv= intvec2ZVector(iv);
     606      int d1 = zc->ambientDimension();
     607      int d2 = zv.size();
     608      if (d1 != d2)
     609        Werror("expected ambient dim of cone and size of vector\n"
     610               "to be equal but got %d and %d", d1, d2);
     611      if(!zc->contains(zv))
     612      {
     613        WerrorS("the provided intvec does not lie in the cone");
     614      }
     615      res->rtyp = coneID;
     616      res->data = (void *)new gfan::ZCone(zc->link(zv));
     617      return FALSE;
     618    }
     619  }
     620  WerrorS("cone_link: unexpected parameters");
     621  return TRUE;
     622}
     623
     624static BOOLEAN jjCONTAINS2(leftv res, leftv u, leftv v)
     625{
     626  gfan::ZCone* zc1 = (gfan::ZCone*)u->Data();
     627  gfan::ZCone* zc2 = (gfan::ZCone*)v->Data();
     628  int d1 = zc1->ambientDimension();
     629  int d2 = zc2->ambientDimension();
     630  if (d1 != d2)
     631    Werror("expected cones with same ambient dimensions\n but got"
     632           " dimensions %d and %d", d1, d2);
     633  res->rtyp = INT_CMD;
     634  res->data = (void *)(zc1->contains(*zc2) ? 1 : 0);
     635  return FALSE;
     636}
     637
     638static BOOLEAN jjCONTAINS3(leftv res, leftv u, leftv v, leftv w)
     639{
     640  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
     641  intvec* vec = (intvec*)v->Data();
     642  int flag = (int)(long)w->Data();
     643  gfan::ZVector zv = intvec2ZVector(vec);
     644  int d1 = zc->ambientDimension();
     645  int d2 = zv.size();
     646  if (d1 != d2)
     647    Werror("expected ambient dim of cone and size of vector\n"
     648           "to be equal but got %d and %d", d1, d2);
     649  res->rtyp = INT_CMD;
     650  if (flag)
     651    res->data = (void *)(zc->containsRelatively(zv) ? 1 : 0);
     652  else
     653    res->data = (void *)(zc->contains(zv) ? 1 : 0);;
     654  return FALSE;
     655}
     656
     657BOOLEAN contains(leftv res, leftv args)
     658{
     659
     660  leftv u = args;
     661  if ((u != NULL) && (u->Typ() == coneID))
     662  {
     663    leftv v = u->next;
     664    if ((v != NULL) && (v->Typ() == coneID)) return jjCONTAINS2(res, u, v);
     665    if ((v != NULL) && (v->Typ() == INTVEC_CMD))
     666    {
     667      leftv w = v->next;
     668      if ((w != NULL) && (w->Typ() == INT_CMD)) return jjCONTAINS3(res, u, v, w);
     669    }
     670  }
     671  WerrorS("contains: unexpected parameters");
     672  return TRUE;
     673}
     674
     675static BOOLEAN jjSETPROPC3A(leftv res, leftv u, leftv v, leftv w)
     676{
     677  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
     678  char* prop = (char*)v->Data();
     679  int val = (int)(long)w->Data();
     680
     681  if (strcmp(prop, "MULTIPLICITY") == 0)
     682  {
     683    zc->setMultiplicity(gfan::Integer(val));
     684  }
     685  else
     686  {
     687    Werror("unexpected cone property '%s'", prop);
     688    return TRUE;
     689  }
     690  res->rtyp = INT_CMD;
     691  res->data = (void *) 1;
     692  return FALSE;
     693}
     694static BOOLEAN jjSETPROPC3B(leftv res, leftv u, leftv v, leftv w)
     695{
     696  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
     697  char* prop = (char*)v->Data();
     698  intvec* mat = (intvec*)w->Data();
     699  gfan::ZMatrix zm = intmat2ZMatrix(mat);
     700
     701  if (strcmp(prop, "LINEAR_FORMS") == 0)
     702  {
     703    zc->setLinearForms(zm);
     704  }
     705  else
     706  {
     707    Werror("unexpected cone property '%s'", prop);
     708    return TRUE;
     709  }
     710  res->rtyp = INT_CMD;
     711  res->data = (void *) 1;
     712  return FALSE;
     713}
     714
     715BOOLEAN setprop(leftv res, leftv args)
     716{
     717
     718  leftv u = args;
     719  if ((u != NULL) && (u->Typ() == coneID))
     720  {
     721    leftv v = u->next;
     722    if ((v != NULL) && (v->Typ() == STRING_CMD))
     723    {
     724      leftv w = v->next;
     725      if ((w != NULL) && (w->Typ() == INT_CMD)) return jjSETPROPC3A(res, u, v, w);
     726      if ((w != NULL) && (w->Typ() == INTMAT_CMD)) return jjSETPROPC3B(res, u, v, w);
     727    }
     728  }
     729  WerrorS("setprop: unexpected parameters");
     730  return TRUE;
    88731}
    89732
     
    97740  b->blackbox_String=bbcone_String;
    98741  //b->blackbox_Print=blackbox_default_Print;
    99   //b->blackbox_Init=blackbox_default_Init;
     742  b->blackbox_Init=bbcone_Init;
    100743  b->blackbox_Copy=bbcone_Copy;
    101744  b->blackbox_Assign=bbcone_Assign;
    102   int rt=setBlackboxStuff(b,"bbcone");
    103   Print("created type %d (bbcone)\n",rt);
    104 }
     745  iiAddCproc("","cone_via_rays",FALSE,cone_via_rays);
     746  iiAddCproc("","cone_via_normals",FALSE,cone_via_normals);
     747  iiAddCproc("","getprop",FALSE,getprop);
     748  iiAddCproc("","cone_intersect",FALSE,cone_intersect);
     749  iiAddCproc("","cone_link",FALSE,cone_link);
     750  iiAddCproc("","contains",FALSE,contains);
     751  iiAddCproc("","setprop",FALSE,setprop);
     752  coneID=setBlackboxStuff(b,"cone");
     753  Print("created type %d (cone)\n",coneID);
     754}
  • Singular/iparith.cc

    r44e1b7f r063900  
    31893189}
    31903190#ifdef HAVE_FANS
    3191 int integerToInt(gfan::Integer const &V, bool &ok)
     3191int _integerToInt(gfan::Integer const &V, bool &ok)
    31923192{
    31933193  mpz_t v;
     
    32023202  return ret;
    32033203}
    3204 intvec* zVector2Intvec(const gfan::ZVector zv)
     3204intvec* _zVector2Intvec(const gfan::ZVector zv)
    32053205{
    32063206  int d=zv.size();
     
    32083208  bool ok = true;
    32093209  for(int i=1;i<=d;i++)
    3210     IMATELEM(*iv, 1, i) = integerToInt(zv[i-1], ok);
     3210    IMATELEM(*iv, 1, i) = _integerToInt(zv[i-1], ok);
    32113211  if (!ok) WerrorS("overflow while converting a gfan::ZVector to an intvec");
    32123212  return iv;
    32133213}
    3214 intvec* zMatrix2Intvec(const gfan::ZMatrix zm)
     3214intvec* _zMatrix2Intvec(const gfan::ZMatrix zm)
    32153215{
    32163216  int d=zm.getHeight();
     
    32203220  for(int i=1;i<=d;i++)
    32213221    for(int j=1;j<=n;j++)
    3222       IMATELEM(*iv, i, j) = integerToInt(zm[i-1][j-1], ok);
     3222      IMATELEM(*iv, i, j) = _integerToInt(zm[i-1][j-1], ok);
    32233223  if (!ok) WerrorS("overflow while converting a gfan::ZMatrix to an intmat");
    32243224  return iv;
    32253225}
    3226 gfan::ZMatrix intmat2ZMatrix(const intvec* iMat)
     3226gfan::ZMatrix _intmat2ZMatrix(const intvec* iMat)
    32273227{
    32283228  int d=iMat->rows();
     
    32353235}
    32363236/* expects iMat to have just one row */
    3237 gfan::ZVector intvec2ZVector(const intvec* iVec)
     3237gfan::ZVector _intvec2ZVector(const intvec* iVec)
    32383238{
    32393239  int n =iVec->rows();
     
    32613261    return TRUE;
    32623262  }
    3263   gfan::ZMatrix zm1 = intmat2ZMatrix(rays);
    3264   gfan::ZMatrix zm2 = intmat2ZMatrix(linSpace);
     3263  gfan::ZMatrix zm1 = _intmat2ZMatrix(rays);
     3264  gfan::ZMatrix zm2 = _intmat2ZMatrix(linSpace);
    32653265  gfan::ZCone* zc = new gfan::ZCone();
    32663266  *zc = gfan::ZCone::givenByRays(zm1, zm2);
     
    32723272  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
    32733273  intvec* iv = (intvec*)v->Data();
    3274   gfan::ZVector zv = intvec2ZVector(iv);
     3274  gfan::ZVector zv = _intvec2ZVector(iv);
    32753275  int d1 = zc->ambientDimension();
    32763276  int d2 = zv.size();
     
    33023302  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
    33033303  intvec* iv = (intvec*)v->Data();
    3304   gfan::ZVector zv= intvec2ZVector(iv);
     3304  gfan::ZVector zv= _intvec2ZVector(iv);
    33053305  int d1 = zc->ambientDimension();
    33063306  int d2 = zv.size();
     
    33423342    return TRUE;
    33433343  }
    3344   gfan::ZMatrix zm1 = intmat2ZMatrix(inequs);
    3345   gfan::ZMatrix zm2 = intmat2ZMatrix(equs);
     3344  gfan::ZMatrix zm1 = _intmat2ZMatrix(inequs);
     3345  gfan::ZMatrix zm2 = _intmat2ZMatrix(equs);
    33463346  gfan::ZCone* zc = new gfan::ZCone(zm1, zm2);
    33473347  res->data = (char *)zc;
     
    35763576  {
    35773577    bool ok = true;
    3578     retInt = integerToInt(zc->getMultiplicity(), ok);
     3578    retInt = _integerToInt(zc->getMultiplicity(), ok);
    35793579    if (!ok)
    35803580      WerrorS("overflow while converting a gfan::Integer to an int");
     
    36523652  {
    36533653    case INTMAT_CMD:
    3654       res->data = (void*)zMatrix2Intvec(retMat);
     3654      res->data = (void*)_zMatrix2Intvec(retMat);
    36553655      break;
    36563656    case INT_CMD:
     
    36613661      break;
    36623662    case INTVEC_CMD:
    3663       res->data = (void*)zVector2Intvec(retVec);
     3663      res->data = (void*)_zVector2Intvec(retVec);
    36643664      break;
    36653665    default: ; /* should never be reached */
     
    51455145          for (int c = 1; c <= cc; c++)
    51465146            IMATELEM(*ivCopy, r, c) = IMATELEM(*iv, r, c) - 1;
    5147         gfan::ZMatrix zm = intmat2ZMatrix(ivCopy);
     5147        gfan::ZMatrix zm = _intmat2ZMatrix(ivCopy);
    51485148        gfan::IntMatrix* im = new gfan::IntMatrix(gfan::ZToIntMatrix(zm));
    51495149        return *im;
     
    52105210     valid parametrizations: (intmat) */
    52115211  intvec* rays = (intvec *)v->CopyD(INTVEC_CMD);
    5212   gfan::ZMatrix zm = intmat2ZMatrix(rays);
     5212  gfan::ZMatrix zm = _intmat2ZMatrix(rays);
    52135213  gfan::ZCone* zc = new gfan::ZCone();
    52145214  *zc = gfan::ZCone::givenByRays(zm, gfan::ZMatrix(0, zm.getWidth()));
     
    52215221     valid parametrizations: (intmat) */
    52225222  intvec* inequs = (intvec *)v->CopyD(INTVEC_CMD);
    5223   gfan::ZMatrix zm = intmat2ZMatrix(inequs);
     5223  gfan::ZMatrix zm = _intmat2ZMatrix(inequs);
    52245224  gfan::ZCone* zc = new gfan::ZCone(zm, gfan::ZMatrix(0, zm.getWidth()));
    52255225  res->data = (char *)zc;
     
    66796679  char* prop = (char*)v->Data();
    66806680  intvec* mat = (intvec*)w->Data();
    6681   gfan::ZMatrix zm = intmat2ZMatrix(mat);
     6681  gfan::ZMatrix zm = _intmat2ZMatrix(mat);
    66826682  int val = (int)(long)w->Data();
    66836683
     
    66986698  intvec* vec = (intvec*)v->Data();
    66996699  int flag = (int)(long)w->Data();
    6700   gfan::ZVector zv = intvec2ZVector(vec);
     6700  gfan::ZVector zv = _intvec2ZVector(vec);
    67016701  int d1 = zc->ambientDimension();
    67026702  int d2 = zv.size();
     
    67386738    return TRUE;
    67396739  }
    6740   gfan::ZMatrix zm1 = intmat2ZMatrix(rays);
    6741   gfan::ZMatrix zm2 = intmat2ZMatrix(linSpace);
     6740  gfan::ZMatrix zm1 = _intmat2ZMatrix(rays);
     6741  gfan::ZMatrix zm2 = _intmat2ZMatrix(linSpace);
    67426742  gfan::ZCone* zc = new gfan::ZCone();
    67436743  *zc = gfan::ZCone::givenByRays(zm1, zm2);
     
    67696769    return TRUE;
    67706770  }
    6771   gfan::ZMatrix zm1 = intmat2ZMatrix(inequs);
    6772   gfan::ZMatrix zm2 = intmat2ZMatrix(equs);
     6771  gfan::ZMatrix zm1 = _intmat2ZMatrix(inequs);
     6772  gfan::ZMatrix zm2 = _intmat2ZMatrix(equs);
    67736773  gfan::ZCone* zc = new gfan::ZCone(zm1, zm2, k);
    67746774  res->data = (char *)zc;
  • Singular/subexpr.cc

    r44e1b7f r063900  
    7070#ifdef HAVE_FANS
    7171#include <sstream>
    72 std::string toString(gfan::ZMatrix const &m, char *tab=0)
     72std::string _toString(gfan::ZMatrix const &m, char *tab=0)
    7373{
    7474  std::stringstream s;
     
    114114}
    115115
    116 std::string toString(gfan::ZCone const &c)
     116std::string _toString(gfan::ZCone const &c)
    117117{
    118118  std::stringstream s;
     
    122122  s<<c.ambientDimension()<<std::endl;
    123123  s<<"INEQUALITIES"<<std::endl;
    124   s<<toString(i);
     124  s<<_toString(i);
    125125  s<<"EQUATIONS"<<std::endl;
    126   s<<toString(e);
     126  s<<_toString(e);
    127127  return s.str();
    128128}
     
    916916        {
    917917          gfan::ZCone* zc = (gfan::ZCone*)d;
    918           std::string s = toString(*zc);
     918          std::string s = _toString(*zc);
    919919          char* ns = (char*) omAlloc(strlen(s.c_str()) + 10);
    920920          sprintf(ns, "%s", s.c_str());
  • Singular/table.h

    r44e1b7f r063900  
    882882//  { "maxrays",     0, MAXRAYS_CMD,        CMD_1},
    883883//  { "linspace",    0, LINSPACE_CMD,       CMD_1},
    884   { "cone",        0, CONE_CMD,           ROOT_DECL},
    885   { "cone_via_rays",0, CONERAYS_CMD,      CMD_123},
    886   { "cone_via_normals",0,CONENORMALS_CMD, CMD_123},
    887   { "fan_empty",   0, FANEMPTY_CMD,       CMD_1},
    888   { "fan_full",    0, FANFULL_CMD,        CMD_1},
    889   { "insert_cone", 0, INSERTCONE_CMD,     CMD_2},
    890   { "cone_intersect",0,INTERSC_CMD,       CMD_2},
    891   { "cone_link",   0, CONELINK_CMD,       CMD_2},
    892   { "contains",    0, CONTAINS_CMD,       CMD_23},
    893   { "getprop",     0, GETPROP_CMD,        CMD_2},
    894   { "setprop",     0, SETPROP_CMD,        CMD_3},
    895   { "fan",         0, FAN_CMD,            ROOT_DECL},
     884  { "_cone",        0, CONE_CMD,           ROOT_DECL},
     885  { "_cone_via_rays",0, CONERAYS_CMD,      CMD_123},
     886  { "_cone_via_normals",0,CONENORMALS_CMD, CMD_123},
     887  { "_fan_empty",   0, FANEMPTY_CMD,       CMD_1},
     888  { "_fan_full",    0, FANFULL_CMD,        CMD_1},
     889  { "_insert_cone", 0, INSERTCONE_CMD,     CMD_2},
     890  { "_cone_intersect",0,INTERSC_CMD,       CMD_2},
     891  { "_cone_link",   0, CONELINK_CMD,       CMD_2},
     892  { "_contains",    0, CONTAINS_CMD,       CMD_23},
     893  { "_getprop",     0, GETPROP_CMD,        CMD_2},
     894  { "_setprop",     0, SETPROP_CMD,        CMD_3},
     895  { "_fan",         0, FAN_CMD,            ROOT_DECL},
    896896  #endif /* HAVE_FANS */
    897897  { "alias",       0, ALIAS_CMD ,         PARAMETER},
Note: See TracChangeset for help on using the changeset viewer.