Loading...
Searching...
No Matches
tropical.cc
Go to the documentation of this file.
#include "polys/monomials/p_polys.h"
#include "coeffs/coeffs.h"
#include "callgfanlib_conversion.h"
#include "bbcone.h"
#include "ppinitialReduction.h"
#include "containsMonomial.h"
#include "initial.h"
#include "witness.h"
#include "tropicalCurves.h"
#include "tropicalStrategy.h"
#include "startingCone.h"
#include "groebnerFan.h"
#include "groebnerComplex.h"
#include "tropicalVariety.h"
VAR int tropicalVerboseLevel = 0;
gfan::ZCone homogeneitySpace(ideal I, ring r)
{
int n = rVar(r);
poly g;
int* leadexpv = (int*) omAlloc((n+1)*sizeof(int));
int* tailexpv = (int*) omAlloc((n+1)*sizeof(int));
gfan::ZVector leadexpw = gfan::ZVector(n);
gfan::ZVector tailexpw = gfan::ZVector(n);
gfan::ZMatrix equations = gfan::ZMatrix(0,n);
for (int i=0; i<IDELEMS(I); i++)
{
g = (poly) I->m[i];
if (g)
{
p_GetExpV(g,leadexpv,r);
leadexpw = intStar2ZVector(n,leadexpv);
pIter(g);
while (g)
{
p_GetExpV(g,tailexpv,r);
tailexpw = intStar2ZVector(n,tailexpv);
equations.appendRow(leadexpw-tailexpw);
pIter(g);
}
}
}
omFreeSize(leadexpv,(n+1)*sizeof(int));
omFreeSize(tailexpv,(n+1)*sizeof(int));
return gfan::ZCone(gfan::ZMatrix(0, equations.getWidth()),equations);
}
BOOLEAN homogeneitySpace(leftv res, leftv args)
{
leftv u = args;
if ((u != NULL) && (u->Typ() == POLY_CMD))
{
leftv v = u->next;
if (v == NULL)
{
poly g = (poly) u->Data();
ideal I = idInit(1);
I->m[0] = g;
res->rtyp = coneID;
res->data = (void*) new gfan::ZCone(homogeneitySpace(I,currRing));
I->m[0] = NULL;
id_Delete(&I,currRing);
return FALSE;
}
}
if ((u != NULL) && (u->Typ() == IDEAL_CMD))
{
leftv v = u->next;
if (v == NULL)
{
ideal I = (ideal) u->Data();
res->rtyp = coneID;
res->data = (void*) new gfan::ZCone(homogeneitySpace(I,currRing));
return FALSE;
}
}
WerrorS("homogeneitySpace: unexpected parameters");
return TRUE;
}
gfan::ZCone lowerHomogeneitySpace(ideal I, ring r)
{
int n = rVar(r);
poly g;
int* leadexpv = (int*) omAlloc((n+1)*sizeof(int));
int* tailexpv = (int*) omAlloc((n+1)*sizeof(int));
gfan::ZVector leadexpw = gfan::ZVector(n);
gfan::ZVector tailexpw = gfan::ZVector(n);
gfan::ZMatrix equations = gfan::ZMatrix(0,n);
for (int i=0; i<IDELEMS(I); i++)
{
g = (poly) I->m[i];
if (g)
{
p_GetExpV(g,leadexpv,r);
leadexpw = intStar2ZVector(n,leadexpv);
pIter(g);
while (g)
{
p_GetExpV(g,tailexpv,r);
tailexpw = intStar2ZVector(n,tailexpv);
equations.appendRow(leadexpw-tailexpw);
pIter(g);
}
}
}
gfan::ZMatrix inequalities = gfan::ZMatrix(0,n);
gfan::ZVector lowerHalfSpaceCondition = gfan::ZVector(n);
lowerHalfSpaceCondition[0] = -1;
inequalities.appendRow(lowerHalfSpaceCondition);
omFreeSize(leadexpv,(n+1)*sizeof(int));
omFreeSize(tailexpv,(n+1)*sizeof(int));
return gfan::ZCone(inequalities,equations);
}
BOOLEAN lowerHomogeneitySpace(leftv res, leftv args)
{
leftv u = args;
if ((u != NULL) && (u->Typ() == POLY_CMD))
{
leftv v = u->next;
if (v == NULL)
{
poly g = (poly) u->Data();
ideal I = idInit(1);
I->m[0] = g;
res->rtyp = coneID;
res->data = (void*) new gfan::ZCone(lowerHomogeneitySpace(I,currRing));
I->m[0] = NULL;
id_Delete(&I,currRing);
return FALSE;
}
}
if ((u != NULL) && (u->Typ() == IDEAL_CMD))
{
leftv v = u->next;
if (v == NULL)
{
ideal I = (ideal) u->Data();
res->rtyp = coneID;
res->data = (void*) new gfan::ZCone(lowerHomogeneitySpace(I,currRing));
return FALSE;
}
}
WerrorS("lowerHomogeneitySpace: unexpected parameters");
return TRUE;
}
gfan::ZCone groebnerCone(const ideal I, const ring r, const gfan::ZVector &w)
{
int n = rVar(r);
poly g = NULL;
int* leadexpv = (int*) omAlloc((n+1)*sizeof(int));
int* tailexpv = (int*) omAlloc((n+1)*sizeof(int));
gfan::ZVector leadexpw = gfan::ZVector(n);
gfan::ZVector tailexpw = gfan::ZVector(n);
gfan::ZMatrix inequalities = gfan::ZMatrix(0,n);
for (int i=0; i<IDELEMS(I); i++)
{
g = (poly) I->m[i];
if (g!=NULL)
{
p_GetExpV(g,leadexpv,currRing);
leadexpw = intStar2ZVector(n, leadexpv);
pIter(g);
while (g!=NULL)
{
p_GetExpV(g,tailexpv,currRing);
tailexpw = intStar2ZVector(n, tailexpv);
inequalities.appendRow(leadexpw-tailexpw);
pIter(g);
}
}
}
ideal inI = initial(I,currRing,w);
gfan::ZMatrix equations = gfan::ZMatrix(0,n);
for (int i=0; i<IDELEMS(I); i++)
{
g = (poly) inI->m[i];
if (g!=NULL)
{
p_GetExpV(g,leadexpv,currRing);
leadexpw = intStar2ZVector(n, leadexpv);
pIter(g);
while (g!=NULL)
{
p_GetExpV(g,tailexpv,currRing);
tailexpw = intStar2ZVector(n, tailexpv);
equations.appendRow(leadexpw-tailexpw);
pIter(g);
}
}
}
omFreeSize(leadexpv,(n+1)*sizeof(int));
omFreeSize(tailexpv,(n+1)*sizeof(int));
id_Delete(&inI,currRing);
return gfan::ZCone(inequalities,equations);
}
BOOLEAN groebnerCone(leftv res, leftv args)
{
leftv u = args;
if ((u != NULL) && (u->Typ() == POLY_CMD))
{
leftv v = u->next;
if ((v !=NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD)))
{
try
{
poly g = (poly) u->Data();
ideal I = idInit(1);
I->m[0] = g;
gfan::ZVector* weightVector;
if (v->Typ() == INTVEC_CMD)
{
intvec* w0 = (intvec*) v->Data();
bigintmat* w1 = iv2bim(w0,coeffs_BIGINT);
w1->inpTranspose();
weightVector = bigintmatToZVector(*w1);
delete w1;
}
else
{
bigintmat* w1 = (bigintmat*) v->Data();
weightVector = bigintmatToZVector(*w1);
}
res->rtyp = coneID;
res->data = (void*) new gfan::ZCone(groebnerCone(I,currRing,*weightVector));
delete weightVector;
I->m[0] = NULL;
id_Delete(&I,currRing);
return FALSE;
}
catch (const std::exception& ex)
{
Werror("ERROR: %s",ex.what());
return TRUE;
}
}
}
if ((u != NULL) && (u->Typ() == IDEAL_CMD))
{
leftv v = u->next;
if ((v !=NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD)))
{
try
{
ideal I = (ideal) u->Data();
gfan::ZVector* weightVector;
if (v->Typ() == INTVEC_CMD)
{
intvec* w0 = (intvec*) v->Data();
bigintmat* w1 = iv2bim(w0,coeffs_BIGINT);
w1->inpTranspose();
weightVector = bigintmatToZVector(*w1);
delete w1;
}
else
{
bigintmat* w1 = (bigintmat*) v->Data();
weightVector = bigintmatToZVector(*w1);
}
res->rtyp = coneID;
res->data = (void*) new gfan::ZCone(groebnerCone(I,currRing,*weightVector));
delete weightVector;
return FALSE;
}
catch (const std::exception& ex)
{
Werror("ERROR: %s",ex.what());
return TRUE;
}
}
}
WerrorS("groebnerCone: unexpected parameters");
return TRUE;
}
gfan::ZCone maximalGroebnerCone(const ideal &I, const ring &r)
{
int n = rVar(r);
poly g = NULL;
int* leadexpv = (int*) omAlloc((n+1)*sizeof(int));
int* tailexpv = (int*) omAlloc((n+1)*sizeof(int));
gfan::ZVector leadexpw = gfan::ZVector(n);
gfan::ZVector tailexpw = gfan::ZVector(n);
gfan::ZMatrix inequalities = gfan::ZMatrix(0,n);
for (int i=0; i<IDELEMS(I); i++)
{
g = (poly) I->m[i];
if (g != NULL && pNext(g) != NULL)
{
p_GetExpV(g,leadexpv,r);
leadexpw = intStar2ZVector(n, leadexpv);
pIter(g);
while (g != NULL)
{
p_GetExpV(g,tailexpv,r);
tailexpw = intStar2ZVector(n, tailexpv);
inequalities.appendRow(leadexpw-tailexpw);
pIter(g);
}
}
}
omFreeSize(leadexpv,(n+1)*sizeof(int));
omFreeSize(tailexpv,(n+1)*sizeof(int));
return gfan::ZCone(inequalities,gfan::ZMatrix(0, inequalities.getWidth()));
}
BOOLEAN maximalGroebnerCone(leftv res, leftv args)
{
leftv u = args;
if ((u != NULL) && (u->Typ() == POLY_CMD))
{
leftv v = u->next;
if (v == NULL)
{
try
{
poly g = (poly) u->Data();
ideal I = idInit(1);
I->m[0] = g;
res->rtyp = coneID;
res->data = (void*) new gfan::ZCone(maximalGroebnerCone(I,currRing));
I->m[0] = NULL;
id_Delete(&I,currRing);
return FALSE;
}
catch (const std::exception& ex)
{
Werror("ERROR: %s",ex.what());
return TRUE;
}
}
}
if ((u != NULL) && (u->Typ() == IDEAL_CMD))
{
leftv v = u->next;
if (v == NULL)
{
try
{
ideal I = (ideal) u->Data();
res->rtyp = coneID;
res->data = (void*) new gfan::ZCone(maximalGroebnerCone(I,currRing));
return FALSE;
}
catch (const std::exception& ex)
{
Werror("ERROR: %s",ex.what());
return TRUE;
}
}
}
WerrorS("maximalGroebnerCone: unexpected parameters");
return TRUE;
}
BOOLEAN initial(leftv res, leftv args)
{
leftv u = args;
if ((u != NULL) && (u->Typ() == POLY_CMD))
{
leftv v = u->next;
if ((v !=NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD)))
{
poly p = (poly) u->Data();
gfan::ZVector* weightVector;
if (v->Typ() == INTVEC_CMD)
{
intvec* w0 = (intvec*) v->Data();
bigintmat* w1 = iv2bim(w0,coeffs_BIGINT);
w1->inpTranspose();
weightVector = bigintmatToZVector(*w1);
delete w1;
}
else
{
bigintmat* w1 = (bigintmat*) v->Data();
weightVector = bigintmatToZVector(*w1);
}
res->rtyp = POLY_CMD;
res->data = (void*) initial(p, currRing, *weightVector);
delete weightVector;
return FALSE;
}
}
if ((u != NULL) && (u->Typ() == IDEAL_CMD))
{
leftv v = u->next;
if ((v !=NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD)))
{
try
{
ideal I = (ideal) u->Data();
gfan::ZVector* weightVector;
if (v->Typ() == INTVEC_CMD)
{
intvec* w0 = (intvec*) v->Data();
bigintmat* w1 = iv2bim(w0,coeffs_BIGINT);
w1->inpTranspose();
weightVector = bigintmatToZVector(*w1);
delete w1;
}
else
{
bigintmat* w1 = (bigintmat*) v->Data();
weightVector = bigintmatToZVector(*w1);
}
res->rtyp = IDEAL_CMD;
res->data = (void*) initial(I, currRing, *weightVector);
delete weightVector;
return FALSE;
}
catch (const std::exception& ex)
{
Werror("ERROR: %s",ex.what());
return TRUE;
}
}
}
WerrorS("initial: unexpected parameters");
return TRUE;
}
void tropical_setup(SModulFunctions* p)
{
p->iiAddCproc("tropical.lib","groebnerConeInternal",FALSE,groebnerCone);
p->iiAddCproc("tropical.lib","maximalGroebnerConeInternal",FALSE,maximalGroebnerCone);
p->iiAddCproc("tropical.lib","homogeneitySpaceInternal",FALSE,homogeneitySpace);
// p->iiAddCproc("","lowerHomogeneitySpaceInternal",FALSE,lowerHomogeneitySpace);
p->iiAddCproc("tropical.lib","initialInternal",FALSE,initial);
p->iiAddCproc("tropical.lib","tropicalVarietyInternal",FALSE,tropicalVariety);
p->iiAddCproc("tropical.lib","groebnerFanInternal",FALSE,groebnerFan);
p->iiAddCproc("tropical.lib","groebnerComplexInternal",FALSE,groebnerComplex);
// p->iiAddCproc("","ppreduceInitiallyInternal",FALSE,ppreduceInitially);
// p->iiAddCproc("","ttreduceInitiallyInternal",FALSE,ttreduceInitially);
}
BOOLEAN
int BOOLEAN
Definition auxiliary.h:88
TRUE
#define TRUE
Definition auxiliary.h:101
FALSE
#define FALSE
Definition auxiliary.h:97
equations
BOOLEAN equations(leftv res, leftv args)
Definition bbcone.cc:577
inequalities
BOOLEAN inequalities(leftv res, leftv args)
Definition bbcone.cc:560
coneID
VAR int coneID
Definition bbcone.cc:25
bbcone.h
iv2bim
bigintmat * iv2bim(intvec *b, const coeffs C)
Definition bigintmat.cc:347
intStar2ZVector
gfan::ZVector intStar2ZVector(const int d, const int *i)
Definition callgfanlib_conversion.cc:86
bigintmatToZVector
gfan::ZVector * bigintmatToZVector(const bigintmat &bim)
Definition callgfanlib_conversion.cc:73
callgfanlib_conversion.h
i
int i
Definition cfEzgcd.cc:132
p
int p
Definition cfModGcd.cc:4086
g
g
Definition cfModGcd.cc:4098
bigintmat
Matrices of numbers.
Definition bigintmat.h:51
bigintmat::inpTranspose
void inpTranspose()
transpose in place
Definition bigintmat.cc:48
groebnerCone
Definition groebnerCone.h:28
intvec
Definition intvec.h:24
sleftv::Typ
int Typ()
Definition subexpr.cc:1048
sleftv::Data
void * Data()
Definition subexpr.cc:1192
sleftv::next
leftv next
Definition subexpr.h:86
coeffs.h
Coefficient rings, fields and other domains suitable for Singular polynomials.
containsMonomial.h
res
CanonicalForm res
Definition facAbsFact.cc:60
w
const CanonicalForm & w
Definition facAbsFact.cc:51
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
WerrorS
void WerrorS(const char *s)
Definition feFopen.cc:24
VAR
#define VAR
Definition globaldefs.h:5
IDEAL_CMD
@ IDEAL_CMD
Definition grammar.cc:285
BIGINTMAT_CMD
@ BIGINTMAT_CMD
Definition grammar.cc:278
POLY_CMD
@ POLY_CMD
Definition grammar.cc:290
groebnerComplex
gfan::ZFan * groebnerComplex(const tropicalStrategy currentStrategy)
Definition groebnerComplex.cc:11
groebnerComplex.h
groebnerFan
gfan::ZFan * groebnerFan(const tropicalStrategy currentStrategy)
Definition groebnerFan.cc:28
groebnerFan.h
initial
poly initial(const poly p, const ring r, const gfan::ZVector &w)
Returns the initial form of p with respect to w.
Definition initial.cc:30
initial.h
SModulFunctions
Definition ipid.h:69
pIter
#define pIter(p)
Definition monomials.h:37
pNext
#define pNext(p)
Definition monomials.h:36
omFreeSize
#define omFreeSize(addr, size)
Definition omAllocDecl.h:260
omAlloc
#define omAlloc(size)
Definition omAllocDecl.h:210
NULL
#define NULL
Definition omList.c:12
p_polys.h
p_GetExpV
static void p_GetExpV(poly p, int *ev, const ring r)
Definition p_polys.h:1541
coeffs_BIGINT
VAR coeffs coeffs_BIGINT
Definition polys.cc:14
currRing
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition polys.cc:13
ppinitialReduction.h
Werror
void Werror(const char *fmt,...)
Definition reporter.cc:189
rVar
static short rVar(const ring r)
define rVar(r) (r->N)
Definition ring.h:598
idInit
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition simpleideals.cc:35
id_Delete
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
Definition simpleideals.cc:123
IDELEMS
#define IDELEMS(i)
Definition simpleideals.h:23
startingCone.h
leftv
sleftv * leftv
Definition structs.h:53
INTVEC_CMD
@ INTVEC_CMD
Definition tok.h:101
tropicalCurves.h
tropicalStrategy.h
implementation of the class tropicalStrategy
tropicalVariety
BOOLEAN tropicalVariety(leftv res, leftv args)
Definition tropicalVariety.cc:43
tropicalVariety.h
tropical_setup
void tropical_setup(SModulFunctions *p)
Definition tropical.cc:441
homogeneitySpace
gfan::ZCone homogeneitySpace(ideal I, ring r)
Definition tropical.cc:19
maximalGroebnerCone
gfan::ZCone maximalGroebnerCone(const ideal &I, const ring &r)
Definition tropical.cc:291
lowerHomogeneitySpace
gfan::ZCone lowerHomogeneitySpace(ideal I, ring r)
Definition tropical.cc:85
tropicalVerboseLevel
VAR int tropicalVerboseLevel
Definition tropical.cc:17
initial
BOOLEAN initial(leftv res, leftv args)
Definition tropical.cc:373
groebnerCone
gfan::ZCone groebnerCone(const ideal I, const ring r, const gfan::ZVector &w)
Definition tropical.cc:156
witness.h