Loading...
Searching...
No Matches
tropicalVarietyOfPolynomials.cc
Go to the documentation of this file.
#include "gfanlib/gfanlib.h"
#include "polys/monomials/p_polys.h"
#include "callgfanlib_conversion.h"
#include "tropicalStrategy.h"
#include "tropicalVarietyOfPolynomials.h"
#ifndef SING_NDEBUG
#include "Singular/subexpr.h" // for leftv
#include "bbfan.h" // for fanID
#endif
/***
* Returns the tropical variety of a polynomial g in ring r.
* Depending on the current case, it will compute either the whole tropical variety
* or just the part in the first lower half-space.
* An empty set means that the tropical Variety is the whole space,
* i.e. g is either 0 or a non-zero monomial.
**/
std::set<gfan::ZCone> tropicalVariety(const poly g, const ring r, const tropicalStrategy* currentCase)
{
int n = rVar(r);
std::set<gfan::ZCone> tropVar;
if (g && g->next)
{
int* expv = (int*) omAlloc((n+1)*sizeof(int));
gfan::ZMatrix exponents = gfan::ZMatrix(0,n);
for (poly s=g; s; pIter(s))
{
p_GetExpV(s,expv,r);
gfan::ZVector zv = intStar2ZVector(n,expv);
exponents.appendRow(intStar2ZVector(n,expv));
}
omFreeSize(expv,(n+1)*sizeof(int));
int l = exponents.getHeight();
gfan::ZVector lowerHalfSpaceCondition = gfan::ZVector(n);
lowerHalfSpaceCondition[0] = -1;
for (int i=0; i<l; i++)
{
for (int j=i+1; j<l; j++)
{
gfan::ZMatrix equation = gfan::ZMatrix(0,n);
equation.appendRow(exponents[i].toVector()-exponents[j].toVector());
gfan::ZMatrix inequalities = gfan::ZMatrix(0,n);
if (currentCase->restrictToLowerHalfSpace())
inequalities.appendRow(lowerHalfSpaceCondition);
for (int k=0; k<l; k++)
if (k!=i && k!=j) inequalities.appendRow(((gfan::ZVector)exponents[i])-exponents[k]);
gfan::ZCone zc = gfan::ZCone(inequalities,equation);
if (zc.dimension()>=n-1)
{
zc.canonicalize();
tropVar.insert(zc);
}
}
}
}
return tropVar;
}
ZConesSortedByDimension tropicalVarietySortedByDimension(const poly g, const ring r, const tropicalStrategy* currentCase)
{
int n = rVar(r);
ZConesSortedByDimension tropVar;
if (g && g->next)
{
int* expv = (int*) omAlloc((n+1)*sizeof(int));
gfan::ZMatrix exponents = gfan::ZMatrix(0,n);
for (poly s=g; s; pIter(s))
{
p_GetExpV(s,expv,r);
gfan::ZVector zv = intStar2ZVector(n,expv);
exponents.appendRow(intStar2ZVector(n,expv));
}
omFreeSize(expv,(n+1)*sizeof(int));
int l = exponents.getHeight();
gfan::ZVector lowerHalfSpaceCondition = gfan::ZVector(n);
lowerHalfSpaceCondition[0] = -1;
for (int i=0; i<l; i++)
{
for (int j=i+1; j<l; j++)
{
gfan::ZMatrix equation = gfan::ZMatrix(0,n);
equation.appendRow(exponents[i].toVector()-exponents[j].toVector());
gfan::ZMatrix inequalities = gfan::ZMatrix(0,n);
if (currentCase->restrictToLowerHalfSpace())
inequalities.appendRow(lowerHalfSpaceCondition);
for (int k=0; k<l; k++)
if (k!=i && k!=j) inequalities.appendRow(exponents[i].toVector()-exponents[k].toVector());
gfan::ZCone zc = gfan::ZCone(inequalities,equation);
if (zc.dimension()>=n-1)
{
zc.canonicalize();
tropVar.insert(zc);
}
}
}
}
return tropVar;
}
// #ifndef SING_NDEBUG
// BOOLEAN tropicalVariety00(leftv res, leftv args)
// {
// leftv u = args;
// poly g = (poly) u->CopyD();
// omUpdateInfo();
// Print("usedBytesBefore=%ld\n",om_Info.UsedBytes);
// std::set<gfan::ZCone> C = fullTropicalVarietyOfPolynomial(g,currRing);
// p_Delete(&g,currRing);
// res->rtyp = fanID;
// res->data = (char*) toFanStar(C);
// return FALSE;
// }
// BOOLEAN tropicalVariety01(leftv res, leftv args)
// {
// leftv u = args;
// poly g = (poly) u->CopyD();
// omUpdateInfo();
// Print("usedBytesBefore=%ld\n",om_Info.UsedBytes);
// std::set<gfan::ZCone> C = lowerTropicalVarietyOfPolynomial(g,currRing);
// p_Delete(&g,currRing);
// res->rtyp = fanID;
// res->data = (char*) toFanStar(C);
// return FALSE;
// }
// #endif
inequalities
BOOLEAN inequalities(leftv res, leftv args)
Definition bbcone.cc:560
bbfan.h
intStar2ZVector
gfan::ZVector intStar2ZVector(const int d, const int *i)
Definition callgfanlib_conversion.cc:86
callgfanlib_conversion.h
l
int l
Definition cfEzgcd.cc:100
i
int i
Definition cfEzgcd.cc:132
k
int k
Definition cfEzgcd.cc:99
g
g
Definition cfModGcd.cc:4098
tropicalStrategy
Definition tropicalStrategy.h:37
tropicalStrategy::restrictToLowerHalfSpace
bool restrictToLowerHalfSpace() const
returns true, if valuation non-trivial, false otherwise
Definition tropicalStrategy.h:238
s
const CanonicalForm int s
Definition facAbsFact.cc:51
j
int j
Definition facHensel.cc:110
pIter
#define pIter(p)
Definition monomials.h:37
omFreeSize
#define omFreeSize(addr, size)
Definition omAllocDecl.h:260
omAlloc
#define omAlloc(size)
Definition omAllocDecl.h:210
p_polys.h
p_GetExpV
static void p_GetExpV(poly p, int *ev, const ring r)
Definition p_polys.h:1541
rVar
static short rVar(const ring r)
define rVar(r) (r->N)
Definition ring.h:598
subexpr.h
tropicalStrategy.h
implementation of the class tropicalStrategy
tropicalVariety
std::set< gfan::ZCone > tropicalVariety(const poly g, const ring r, const tropicalStrategy *currentCase)
Definition tropicalVarietyOfPolynomials.cc:20
tropicalVarietySortedByDimension
ZConesSortedByDimension tropicalVarietySortedByDimension(const poly g, const ring r, const tropicalStrategy *currentCase)
Definition tropicalVarietyOfPolynomials.cc:62
tropicalVarietyOfPolynomials.h
ZConesSortedByDimension
std::set< gfan::ZCone, ZConeCompareDimensionFirst > ZConesSortedByDimension
Definition tropicalVarietyOfPolynomials.h:27