-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTropHyperplanes.m2
357 lines (314 loc) · 11.9 KB
/
TropHyperplanes.m2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
newPackage(
"TropHyperplanes",
Version => "1.1",
Date => "March 1, 2023",
Authors => {
{Name => "Ayah Almousa", Email => "[email protected]", HomePage => ""},
{Name => "Demetrios Case", Email => "", HomePage => ""}},
Headline => "for computing monomial ideals associated to arrangements",
Keywords => {""},
DebuggingMode => true,
Reload => True,
PackageImports=>{"SimplicialComplexes"}
)
--export {"hyperplaneArrangement"}
--export {"hyperplaneSideId"}
export {"fineCotype"}
export {"fineCotype2"}
export {"fineType"}
export {"fineType2"}
export {"weights"}
export {"getPolyRing"}
export {"isRegular"}
export {"isMonomial"}
--export {"weightedRing"}
getPolyRing = method()
getPolyRing (ZZ, ZZ, Matrix) := (m, n, A) -> (
--use (symbol x);
x := local x;
--
Q := ZZ/101[x_(1, 1)..x_(m, n), MonomialOrder=> {Weights=> flatten entries A}];
return Q;
)
-- inputs: apex List of Reals
-- outputs: matrix representation of Tropical Hyperplane Arrangement
hyperplaneArrangement = method(TypicalValue => List)
hyperplaneArrangement List := List => apexes -> (
if isTable apexes then transpose(
matrix(apply(apexes, apex -> apply(apex, coordinate -> coordinate - last(apex))))
)
else {"NOT A VALID HYPERPLANE ARRANGEMENT"}
)
-- This is helper function that tests whether or not a point is contained within a k-sector of a single hyperplane
-- TODO: make this min/max adaptable
allLessOrEq = method()
allLessOrEq (ZZ, ZZ, List, List) := (it, akpk, apex, point) -> (
if it == 0 then (
(akpk >= apex#it - point#it)
)
else (
(akpk >= apex#it - point#it) and allLessOrEq(it - 1, akpk, apex, point)
)
)
-- inputs: apex and a point
-- outputs: the k-th sector where the point lies
hyperplaneSideId = method()
hyperplaneSideId (List, List) := (apex, point) -> (
for k from 0 to (#apex - 1) do (
if allLessOrEq(#apex - 1, apex#k - point#k, apex, point) then return (k + 1)
)
)
-- inputs: a matrix that contains weights used for computing the fine-type and -cotype ideals of a tropical hyperplane arrangement
-- outputs: a flattened version of this matrix. this doesn't do anything special but it's less to type :)
weights = method()
weights (Matrix) := (A) -> (
flatten entries A
)
-- inputs: the number of columns, number of rows, and ambient ring of a generic matrix used in computing the fine-type and -cotype ideals of a tropical hyperplane arrangement
-- outputs: the generic matrix
genericMat = method()
genericMat (ZZ, ZZ, PolynomialRing) := (n,m,Q) -> (
use Q;
Mmut := mutableMatrix(Q,n,m);
if #(gens Q) == n*m then (
for i from 0 to n-1 do (
for j from 0 to m-1 do (
Mmut_(i, j) = (gens Q)#(j + (i * m));
);
);
return matrix Mmut;
);
--else ( "ERROR" );
)
-- inputs: a matrix representing a tropical hyperplane arrangement
-- outputs: the fine cotype ideal of the hyperplane arrangement
fineCotype = method()
fineCotype (Matrix) := (A) -> (
Q := getPolyRing(numRows(A), numColumns(A), A);
use Q;
return dual (monomialIdeal leadTerm minors(2, genericMat(numRows(A), numColumns(A), Q)));
)
-- inputs: ring element
-- outputa: if the ring element is a monomial
isMonomial = method()
isMonomial (RingElement, Matrix) := (M, A) -> (
Q := getPolyRing(numRows(A), numColumns(A), A);
use Q;
return M == (leadTerm M)
)
-- inputs: a matrix representing a tropical hyperplane arrangement
-- outputs: the fine cotype ideal of the hyperplane arrangement
fineCotype2 = method()
fineCotype2 (Matrix) := (A) -> (
Q := getPolyRing(numRows(A), numColumns(A), A);
use Q;
L := flatten entries leadTerm(1, minors(2, genericMat(numRows(A), numColumns(A), Q)));
return dual (monomialIdeal select(L, (i -> i == leadTerm i)));
)
-- inputs: a monomial, a ring generator, and an ambient ring
-- outputs: a boolean value corresponding to whether or not the ring generator is in the monomial
genInMonomial = method()
genInMonomial (RingElement, RingElement, PolynomialRing) := (E, G, Q) -> (
use Q;
return numerator(E / G) != E;
)
-- inputs: a monomial and a polynomial ring
-- outputs: a list of ring generators contained in the monomial. For example, x_1*x_3 maps to {x_1, x_3}.
gensInMonomial = method()
gensInMonomial (RingElement, PolynomialRing) := (E, Q) -> (
use Q;
return select((gens Q), g -> genInMonomial(E, g, Q));
)
-- inputs: an polynomial ring generator
-- outputs: the subscripts corresponding to the ring element. For example, x_(1,2) maps to {1, 2}
ringElementIndex = method()
ringElementIndex (RingElement, PolynomialRing, ZZ, ZZ) := (E, Q, m, n) -> (
use Q;
return {floor(index(E) / n) + 1, (index(E) % n) + 1}
--return index(E);
)
-- inputs: a list of lists of generators in facets of a simplicial complex, a polynomial ring, and a matrix
-- outputs: a list of 2-element lists that correspond to the respective index of each ring generator of each facet
monomialsToSubscriptLists = method()
monomialsToSubscriptLists (List, PolynomialRing, Matrix) := (mons, Q, A) -> (
return apply(mons, mon -> apply(mon, ringGen -> ringElementIndex(ringGen, Q, numRows(A), numColumns(A))));
)
-- inputs: a list of facets of a simplicial complex, a polynomial ring
-- outputs: a list of lists of generators in each facet of the simplicial complex
divideFacets = method()
divideFacets (List, PolynomialRing) := (L, Q) -> (
use Q;
return apply(L, facet -> gensInMonomial(facet, Q));
--return apply(apply(L, facet -> gensInMonomial(facet, Q)), monomialAsList -> apply(monomialAsList, ringGenerator -> ringGenerator * 2));
)
-- inputs: a list of genetors that correspond to a facet of a simplicial complex and the ambient polynomial ring
-- outputs: a hash table whose keys and entries are divided by the "components" of the products
facetComponents = method()
facetComponents (List, PolynomialRing) := (L, Q) -> (
use Q;
return apply(L, monomialIndexes -> partition((monomialIndex -> monomialIndex#1), monomialIndexes));
)
-- inputs: a hash table corresponding to factors of the minowski sum, the ambient polynomial ring, and the number of entires in the table
-- outputs: the cartesian product of the elements of each hash table entry
minowskiSumHelperHelper = method()
minowskiSumHelperHelper (HashTable, PolynomialRing, ZZ) := (H, Q, i) -> (
use Q;
if i == 1 then (
return set(H#i);
)
else (
return set(H#i) ** minowskiSumHelperHelper(H, Q, i - 1);
)
)
-- inputs: a list of facets of a siplicial complex
-- outouts: the minowski sum of each component
minowskiSumHelper = method()
minowskiSumHelper (List, PolynomialRing) := (L, Q) -> (
use Q;
return apply(L, entryAsTable -> minowskiSumHelperHelper(entryAsTable, Q, #keys(entryAsTable)));
)
-- inputs: a list of lists
-- outputs: the flattened list
flattenListofSets = method()
flattenListofSets (List) := (L) -> (
return flatten apply(L, setOfIndexTuples -> toList(setOfIndexTuples));
)
-- inputs: a list of ring generators and a polynomial ring
-- outputs: a monomial
collapse = method()
collapse (List, PolynomialRing) := (L, Q) -> (
use Q;
if #L == 1 then return L#0
else (
return L#0 * collapse(delete(L#0, L), Q)
)
)
-- inputs: a list of tuples representing generator indexes
-- outputs: the monomials with the corresponding indexes
getMonomialsFromTupleLists = method()
getMonomialsFromTupleLists (List, PolynomialRing, ZZ) := (L, Q, m) -> (
use Q;
return apply(apply(L, mon -> apply(mon, gen -> (gens Q)#(gen#1 - 1 + ((gen#0 - 1) * m)))), gensAsTuples -> collapse(toList gensAsTuples, Q))
--
-- (gens Q)#(j + (i * m))
)
-- inputs: a list of nested tuples to be "unwound"
-- outputs: the "unwound" lists
tupleUnwind = method()
tupleUnwind (List) := (L) -> (
return apply(L, tuple -> deepSplice tuple);
)
-- inputs: a list of facets of a simplicial complex, the ambient polynomial ring, and the matrix associated with the corresponding tropical hyperplane arrangement
-- outputs: the corresponding regular subdivision
tropicalCayleyTrick = method()
tropicalCayleyTrick (List, PolynomialRing, Matrix) := (L, Q, A) -> (
use Q;
return ideal(unique(getMonomialsFromTupleLists(flattenListofSets(minowskiSumHelper(facetComponents(monomialsToSubscriptLists(divideFacets(L, Q), Q, A), Q), Q)), Q, numColumns(A))));
)
-- inputs: a matrix representation of a tropical hyperplane arrangement and a polynomial ring used for computing the ideal
-- outputs: the fine-type deal of the tropical hyperplane arrangement
fineType = method()
fineType (Matrix) := (A) -> (
Q := getPolyRing(numRows(A), numColumns(A), A);
use Q;
return tropicalCayleyTrick ((flatten (entries (facets (simplicialComplex monomialIdeal(leadTerm minors(2, genericMat(numRows(A), numColumns(A), Q))))))), Q, A)
--return divideFacets ((flatten (entries (facets (simplicialComplex monomialIdeal(leadTerm minors(2, genericMat(numRows(A), numColumns(A), Q))))))), Q)
)
tropicalCayleyTrick2 = method()
tropicalCayleyTrick2 (List, PolynomialRing, Matrix) := (L, Q, A) -> (
use Q;
M := flattenListofSets(minowskiSumHelper(facetComponents(monomialsToSubscriptLists(divideFacets(L, Q), Q, A), Q), Q)), Q, numColumns(A);
return ideal(unique(getMonomialsFromTupleLists((tupleUnwind M), Q, numColumns(A))));
-- return tupleUnwind M
-- return minowskiSumHelper(facetComponents(monomialsToSubscriptLists(divideFacets(L, Q), Q, A), Q), Q);
-- return facetComponents(monomialsToSubscriptLists(divideFacets(L, Q), Q, A), Q), Q;
)
-- inputs: a matrix representation of a tropical hyperplane arrangement and a polynomial ring used for computing the ideal
-- outputs: the fine-type deal of the tropical hyperplane arrangement
fineType2 = method()
fineType2 (Matrix) := (A) -> (
Q := getPolyRing(numRows(A), numColumns(A), A);
use Q;
return tropicalCayleyTrick2 ((flatten (entries (facets (simplicialComplex monomialIdeal(leadTerm minors(2, genericMat(numRows(A), numColumns(A), Q))))))), Q, A)
--return divideFacets ((flatten (entries (facets (simplicialComplex monomialIdeal(leadTerm minors(2, genericMat(numRows(A), numColumns(A), Q))))))), Q)
)
-- inputs: a matrix representation of a tropical hyperplane arrangement
-- outputs: a boolean whose value indicates if the hyperplane arrangement given is reagular
isRegular = method()
isRegular (Matrix) := (A) -> (
Q := getPolyRing(numRows(A), numColumns(A), A);
use Q;
return ideal(leadTerm(1, minors(2, genericMat(numRows(A), numColumns(A), Q)))) == monomialIdeal(leadTerm minors(2, genericMat(numRows(A), numColumns(A), Q)));
)
-*
beginDocumentation()
doc ///
Node
Key
TropHyperplanes
Headline
an package for computing Tropical Hyperplane Arrangements
Subnodes
:weights
:fineType
:fineCotype
Node
Key
(weights, Matrix)
weights
Headline
a function that takes a matrix and produces a list of associated weights (not too complicated, just to shorten things up)
Usage
weights hyperplaneArrangementMatrix
Inputs
weights:
Outputs
:
a list of associated weights
Description
Text
Here we show an example.
Example
weights matrix{{0,0,4},{0,1,0},{0,3,1}}
Node
Key
(fineType, Matrix, PolynomialRing)
fineType
Headline
a function that takes a matrix and a polynomial ring and returns the associated fine type ideal
Usage
fineType(mat, polyRing)
Inputs
hyperplaneArrangement:
polyRing:
Outputs
:
the fine type ideal of the tropical hyperplane arrangement
Node
Key
(fineCotype, Matrix, PolynomialRing)
fineCotype
Headline
function that takes a matrix and a polynomial ring and returns the associated fine type ideal
Usage
fineCotype(mat, polyRing)
Inputs
hyperplaneArrangement:
polyRing:
Outputs
:
the fine cotype ideal of the tropical hyperplane arrangement
///
*-
end--
restart
uninstallPackage "TropHyperplanes"
restart
installPackage "TropHyperplanes"
restart
needsPackage "TropHyperplanes"
viewHelp TropHyperplanes
FIX INDEXING PROBLEM
WAIT FOR FURTHER INSTRUCTION W THE POLYNOMIAL RING
EXTEND THE CODE TO NOT JUST GENERIC ARRANGEMENTS!!!
THEN GENERATE RANDOEM MATRIX AND TO TESTS W TRANSPOSE