1 | #include <set> |
---|
2 | #include <gfanlib/gfanlib.h> |
---|
3 | #include <polys/monomials/p_polys.h> |
---|
4 | #include <callgfanlib_conversion.h> |
---|
5 | |
---|
6 | #include <tropicalStrategy.h> |
---|
7 | #include <tropicalVarietyOfPolynomials.h> |
---|
8 | |
---|
9 | #ifndef NDEBUG |
---|
10 | #include <Singular/subexpr.h> // for leftv |
---|
11 | #include <bbfan.h> // for fanID |
---|
12 | #endif |
---|
13 | |
---|
14 | /*** |
---|
15 | * Returns the tropical variety of a polynomial g in ring r. |
---|
16 | * Depending on the current case, it will compute either the whole tropical variety |
---|
17 | * or just the part in the first lower half-space. |
---|
18 | * An empty set means that the tropical Variety is the whole space, |
---|
19 | * i.e. g is either 0 or a non-zero monomial. |
---|
20 | **/ |
---|
21 | std::set<gfan::ZCone> tropicalVariety(const poly g, const ring r, const tropicalStrategy* currentCase) |
---|
22 | { |
---|
23 | int n = rVar(r); |
---|
24 | std::set<gfan::ZCone> tropVar; |
---|
25 | if (g && g->next) |
---|
26 | { |
---|
27 | int* expv = (int*) omAlloc((n+1)*sizeof(int)); |
---|
28 | gfan::ZMatrix exponents = gfan::ZMatrix(0,n); |
---|
29 | for (poly s=g; s; pIter(s)) |
---|
30 | { |
---|
31 | p_GetExpV(s,expv,r); |
---|
32 | gfan::ZVector zv = intStar2ZVector(n,expv); |
---|
33 | exponents.appendRow(intStar2ZVector(n,expv)); |
---|
34 | } |
---|
35 | omFreeSize(expv,(n+1)*sizeof(int)); |
---|
36 | |
---|
37 | int l = exponents.getHeight(); |
---|
38 | gfan::ZVector lowerHalfSpaceCondition = gfan::ZVector(n); |
---|
39 | lowerHalfSpaceCondition[0] = -1; |
---|
40 | for (int i=0; i<l; i++) |
---|
41 | { |
---|
42 | for (int j=i+1; j<l; j++) |
---|
43 | { |
---|
44 | gfan::ZMatrix equation = gfan::ZMatrix(0,n); |
---|
45 | equation.appendRow(exponents[i]-exponents[j]); |
---|
46 | gfan::ZMatrix inequalities = gfan::ZMatrix(0,n); |
---|
47 | if (currentCase->restrictToLowerHalfSpace()) |
---|
48 | inequalities.appendRow(lowerHalfSpaceCondition); |
---|
49 | for (int k=0; k<l; k++) |
---|
50 | if (k!=i && k!=j) inequalities.appendRow(exponents[i]-exponents[k]); |
---|
51 | gfan::ZCone zc = gfan::ZCone(inequalities,equation); |
---|
52 | if (zc.dimension()>=n-1) |
---|
53 | { |
---|
54 | zc.canonicalize(); |
---|
55 | tropVar.insert(zc); |
---|
56 | } |
---|
57 | } |
---|
58 | } |
---|
59 | } |
---|
60 | return tropVar; |
---|
61 | } |
---|
62 | |
---|
63 | ZConesSortedByDimension tropicalVarietySortedByDimension(const poly g, const ring r, const tropicalStrategy* currentCase) |
---|
64 | { |
---|
65 | int n = rVar(r); |
---|
66 | ZConesSortedByDimension tropVar; |
---|
67 | if (g && g->next) |
---|
68 | { |
---|
69 | int* expv = (int*) omAlloc((n+1)*sizeof(int)); |
---|
70 | gfan::ZMatrix exponents = gfan::ZMatrix(0,n); |
---|
71 | for (poly s=g; s; pIter(s)) |
---|
72 | { |
---|
73 | p_GetExpV(s,expv,r); |
---|
74 | gfan::ZVector zv = intStar2ZVector(n,expv); |
---|
75 | exponents.appendRow(intStar2ZVector(n,expv)); |
---|
76 | } |
---|
77 | omFreeSize(expv,(n+1)*sizeof(int)); |
---|
78 | |
---|
79 | int l = exponents.getHeight(); |
---|
80 | gfan::ZVector lowerHalfSpaceCondition = gfan::ZVector(n); |
---|
81 | lowerHalfSpaceCondition[0] = -1; |
---|
82 | for (int i=0; i<l; i++) |
---|
83 | { |
---|
84 | for (int j=i+1; j<l; j++) |
---|
85 | { |
---|
86 | gfan::ZMatrix equation = gfan::ZMatrix(0,n); |
---|
87 | equation.appendRow(exponents[i]-exponents[j]); |
---|
88 | gfan::ZMatrix inequalities = gfan::ZMatrix(0,n); |
---|
89 | if (currentCase->restrictToLowerHalfSpace()) |
---|
90 | inequalities.appendRow(lowerHalfSpaceCondition); |
---|
91 | for (int k=0; k<l; k++) |
---|
92 | if (k!=i && k!=j) inequalities.appendRow(exponents[i]-exponents[k]); |
---|
93 | gfan::ZCone zc = gfan::ZCone(inequalities,equation); |
---|
94 | if (zc.dimension()>=n-1) |
---|
95 | { |
---|
96 | zc.canonicalize(); |
---|
97 | tropVar.insert(zc); |
---|
98 | } |
---|
99 | } |
---|
100 | } |
---|
101 | } |
---|
102 | return tropVar; |
---|
103 | } |
---|
104 | |
---|
105 | |
---|
106 | // #ifndef NDEBUG |
---|
107 | // BOOLEAN tropicalVariety00(leftv res, leftv args) |
---|
108 | // { |
---|
109 | // leftv u = args; |
---|
110 | // poly g = (poly) u->CopyD(); |
---|
111 | // omUpdateInfo(); |
---|
112 | // Print("usedBytesBefore=%ld\n",om_Info.UsedBytes); |
---|
113 | // std::set<gfan::ZCone> C = fullTropicalVarietyOfPolynomial(g,currRing); |
---|
114 | // p_Delete(&g,currRing); |
---|
115 | // res->rtyp = fanID; |
---|
116 | // res->data = (char*) toFanStar(C); |
---|
117 | // return FALSE; |
---|
118 | // } |
---|
119 | // BOOLEAN tropicalVariety01(leftv res, leftv args) |
---|
120 | // { |
---|
121 | // leftv u = args; |
---|
122 | // poly g = (poly) u->CopyD(); |
---|
123 | // omUpdateInfo(); |
---|
124 | // Print("usedBytesBefore=%ld\n",om_Info.UsedBytes); |
---|
125 | // std::set<gfan::ZCone> C = lowerTropicalVarietyOfPolynomial(g,currRing); |
---|
126 | // p_Delete(&g,currRing); |
---|
127 | // res->rtyp = fanID; |
---|
128 | // res->data = (char*) toFanStar(C); |
---|
129 | // return FALSE; |
---|
130 | // } |
---|
131 | // #endif |
---|