7 #include <polymake/Main.h> 8 #include <polymake/Matrix.h> 9 #include <polymake/Rational.h> 10 #include <polymake/Integer.h> 11 #include <polymake/Set.h> 12 #include <polymake/common/lattice_tools.h> 13 #include <polymake/IncidenceMatrix.h> 15 #include <gfanlib/gfanlib.h> 16 #include <gfanlib/gfanlib_q.h> 32 mpz_t cache; mpz_init(cache);
34 polymake::Integer
pi(cache);
40 mpq_t cache; mpq_init(cache);
42 polymake::Rational pr(cache);
48 polymake::Vector<polymake::Integer> vi(iv->
length());
58 int rows=zm->getHeight();
59 int cols=zm->getWidth();
60 polymake::Matrix<polymake::Integer> mi(rows,cols);
61 for(
int r=1;
r<=rows;
r++)
62 for(
int c=1; c<=cols; c++)
69 int rows=qm->getHeight();
70 int cols=qm->getWidth();
71 polymake::Matrix<polymake::Rational> mr(rows,cols);
72 for(
int r=1;
r<=rows;
r++)
73 for(
int c=1; c<=cols; c++)
82 mpz_class cache(pi.get_rep());
83 gfan::Integer gi(cache.get_mpz_t());
89 mpq_class cache(pr.get_rep());
90 gfan::Rational gr(cache.get_mpq_t());
98 gfan::ZMatrix zm(rows,cols);
99 for(
int r=1;
r<=rows;
r++)
100 for(
int c=1; c<=cols; c++)
109 gfan::QMatrix qm(rows,cols);
110 for(
int r=1;
r<=rows;
r++)
111 for(
int c=1; c<=cols; c++)
125 catch (
const std::exception& ex)
135 mpz_class cache(pi.get_rep());
137 if(mpz_cmp_si(cache.get_mpz_t(),
m))
139 int temp = (int) mpz_get_si(cache.get_mpz_t());
149 for(
int i=1;
i<=vi->size();
i++)
158 int rows = mi->
rows();
159 int cols = mi->cols();
161 const polymake::Integer*
pi = concat_rows(*mi).begin();
162 for (
int r = 1;
r <= rows;
r++)
163 for (
int c = 1; c <= cols; c++)
173 int rows = mi->
rows();
174 int cols = mi->cols();
176 const polymake::Integer*
pi = concat_rows(*mi).begin();
177 for (
int r = 1;
r <= rows;
r++)
178 for (
int c = 1; c <= cols; c++)
190 int rows = icmat->rows();
191 int cols = icmat->cols();
195 for (
int r = 0;
r < rows;
r++)
198 for (
int c = 0; c < cols; c++)
200 if ((*icmat).row(
r).exists(c))
205 L->
m[
r].
data = (
void*) iv;
213 int rows = icmat->rows();
214 int cols = icmat->cols();
218 for (r=0; r<rows; r++)
220 for (c=0; c<cols; c++)
222 if ((*icmat).row(r).exists(c) && r<c)
231 for (r=0; r<rows; r++)
233 for (c=0; c<cols; c++)
235 if ((*icmat).row(r).exists(c) && r<c)
238 (*iv)[0]=
r; (*iv)[1]=c;
240 L->
m[
i].
data = (
void*) iv;
251 polymake::Vector<polymake::Integer> vi(*si);
261 polymake::Matrix<polymake::Integer> mi(rows,cols);
262 for(
int r=0;
r<rows;
r++)
263 for(
int c=0; c<cols; c++)
264 mi(
r,c) = polymake::Integer(
IMATELEM(*im,
r+1, c+1));
275 polymake::Integer ambientdim1 = pc->give(
"CONE_AMBIENT_DIM");
276 bool ok=
true;
int ambientdim2 =
PmInteger2Int(ambientdim1, ok);
279 WerrorS(
"PmCone2ZCone: overflow while converting polymake::Integer to int");
281 polymake::Matrix<polymake::Rational> ineqrational = pc->give(
"FACETS");
282 polymake::Matrix<polymake::Rational> eqrational = pc->give(
"LINEAR_SPAN");
286 gfan::ZMatrix zv, zw, zx, zy, zz;
289 if (ineqrational.cols()!=0)
291 polymake::Matrix<polymake::Integer> ineqinteger = polymake::common::primitive(ineqrational);
295 zv = gfan::ZMatrix(0, ambientdim2);
296 if (eqrational.cols()!=0)
298 polymake::Matrix<polymake::Integer> eqinteger = polymake::common::primitive(eqrational);
302 zw = gfan::ZMatrix(0, ambientdim2);
319 gfan::ZCone* zc =
new gfan::ZCone(zv,zw,3);
322 WerrorS(
"PmCone2ZCone: unexpected parameters");
328 if (pp->isa(
"Polytope<Rational>"))
330 polymake::Integer ambientdim1 = pp->give(
"CONE_AMBIENT_DIM");
331 bool ok=
true;
int ambientdim2 =
PmInteger2Int(ambientdim1, ok);
334 WerrorS(
"overflow while converting polymake::Integer to int");
336 polymake::Matrix<polymake::Rational> ineqrational = pp->give(
"FACETS");
337 polymake::Matrix<polymake::Rational> eqrational = pp->give(
"AFFINE_HULL");
341 gfan::ZMatrix zv, zw;
344 if (ineqrational.cols()!=0)
346 polymake::Matrix<polymake::Integer> ineqinteger = polymake::common::primitive(ineqrational);
350 zv = gfan::ZMatrix(0, ambientdim2);
352 if (eqrational.cols()!=0)
354 polymake::Matrix<polymake::Integer> eqinteger = polymake::common::primitive(eqrational);
358 zw = gfan::ZMatrix(0, ambientdim2);
376 gfan::ZCone* zp =
new gfan::ZCone(zv,zw,3);
380 WerrorS(
"PmPolytope2ZPolytope: unexpected parameters");
386 if (pf->isa(
"PolyhedralFan"))
388 int d = (int) pf->give(
"FAN_AMBIENT_DIM");
389 gfan::ZFan* zf =
new gfan::ZFan(d);
391 int n = pf->give(
"N_MAXIMAL_CONES");
392 for (
int i=0;
i<n;
i++)
394 polymake::perl::Object pmcone=pf->CallPolymakeMethod(
"cone",
i);
400 WerrorS(
"PmFan2ZFan: unexpected parameters");
406 polymake::perl::Object* gc =
new polymake::perl::Object(
"Cone<Rational>");
411 gfan::ZMatrix
equations = zc->getEquations();
431 polymake::perl::Object*
pp =
new polymake::perl::Object(
"Polytope<Rational>");
436 gfan::ZMatrix
equations = zc->getEquations();
448 polymake::Matrix<polymake::Integer>
raysOf(gfan::ZFan* zf)
450 int d = zf->getAmbientDimension();
451 int n = zf->numberOfConesOfDimension(1,0,0);
452 gfan::ZMatrix zm(n,d);
454 for (
int i=0;
i<n;
i++)
456 gfan::ZCone zc = zf->getCone(1,
i,0,0);
457 gfan::ZMatrix ray = zc.extremeRays();
458 for (
int j=0;
j<d;
j++)
469 int n = zf->numberOfConesOfDimension(1,0,0);
475 int d = zf->getAmbientDimension();
478 for (
int i=0;
i<=d;
i++)
480 n = n + zf->numberOfConesOfDimension(
i,0,1);
486 polymake::Array<polymake::Set<int> >
conesOf(gfan::ZFan* zf)
490 polymake::Matrix<polymake::Integer> pm=
raysOf(zf);
491 polymake::Array<polymake::Set<int> > L(r);
494 for (
int d=1; d<=zf->getAmbientDimension(); d++)
496 for (
int i=0;
i<zf->numberOfConesOfDimension(d,0,1);
i++)
498 gfan::IntVector
v = zf->getConeIndices(d,
i,0,1);
499 polymake::Set<int>
s;
500 for (
int j=0;
j<(int)v.size();
j++)
513 polymake::perl::Object* pf =
new polymake::perl::Object(
"PolyhedralFan");
515 polymake::Matrix<polymake::Integer> zm =
raysOf(zf);
516 pf->take(
"RAYS") << zm;
518 polymake::Array<polymake::Set<int> > ar =
conesOf(zf);
519 pf->take(
"MAXIMAL_CONES") << ar;
const CanonicalForm int s
void resize(int new_length)
number PmInteger2Number(const polymake::Integer &pi)
lists PmIncidenceMatrix2ListOfIntvecs(polymake::IncidenceMatrix< polymake::NonSymmetric > *icmat)
lists PmAdjacencyMatrix2ListOfEdges(polymake::IncidenceMatrix< polymake::NonSymmetric > *icmat)
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
polymake::Vector< polymake::Integer > Intvec2PmVectorInteger(const intvec *iv)
polymake::perl::Object * ZCone2PmCone(gfan::ZCone *zc)
polymake::perl::Object * ZPolytope2PmPolytope(gfan::ZCone *zc)
bigintmat * PmMatrixInteger2Bigintmat(polymake::Matrix< polymake::Integer > *mi)
gfan::Rational PmRational2GfRational(const polymake::Rational &pr)
intvec * PmSetInteger2Intvec(polymake::Set< polymake::Integer > *si, bool &b)
gfan::ZFan * PmFan2ZFan(polymake::perl::Object *pf)
void WerrorS(const char *s)
polymake::Matrix< polymake::Integer > Intvec2PmMatrixInteger(const intvec *im)
polymake::Array< polymake::Set< int > > conesOf(gfan::ZFan *zf)
void set(int i, int j, number n, const coeffs C=NULL)
replace an entry with a copy (delete old + copy new!). NOTE: starts at [1,1]
int numberOfMaximalConesOf(gfan::ZFan *zf)
polymake::Integer GfInteger2PmInteger(const gfan::Integer &gi)
polymake::Matrix< polymake::Integer > raysOf(gfan::ZFan *zf)
BOOLEAN inequalities(leftv res, leftv args)
gfan::ZMatrix PmMatrixInteger2GfZMatrix(const polymake::Matrix< polymake::Integer > *mi)
intvec * PmVectorInteger2Intvec(const polymake::Vector< polymake::Integer > *vi, bool &ok)
gfan::ZCone * PmCone2ZCone(polymake::perl::Object *pc)
intvec * PmMatrixInteger2Intvec(polymake::Matrix< polymake::Integer > *mi, bool &ok)
int numberOfRaysOf(gfan::ZFan *zf)
static FORCE_INLINE number n_InitMPZ(mpz_t n, const coeffs r)
conversion of a GMP integer to number
polymake::Rational GfRational2PmRational(const gfan::Rational &gr)
polymake::Matrix< polymake::Integer > GfZMatrix2PmMatrixInteger(const gfan::ZMatrix *zm)
polymake::perl::Object * ZFan2PmFan(gfan::ZFan *zf)
gfan::QMatrix PmMatrixRational2GfQMatrix(const polymake::Matrix< polymake::Rational > *mr)
INLINE_THIS void Init(int l=0)
gfan::ZCone * PmPolytope2ZPolytope(polymake::perl::Object *pp)
const Variable & v
< [in] a sqrfree bivariate poly
BOOLEAN equations(leftv res, leftv args)
polymake::Matrix< polymake::Rational > GfQMatrix2PmMatrixRational(const gfan::QMatrix *qm)
int PmInteger2Int(const polymake::Integer &pi, bool &ok)
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
#define IMATELEM(M, I, J)
gfan::Integer PmInteger2GfInteger(const polymake::Integer &pi)