-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeometricRealizations.sage
408 lines (249 loc) · 16.7 KB
/
geometricRealizations.sage
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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
# This script contains routines to generate the illustrations for the paper "Geometry of v-Tamari lattices in types A and B", written in collaboration with Cesar Ceballos and Arnau Padrol and published in Transactions of the American Mathematical Society, 371 (2019) 2575-2622 (https://doi.org/10.1090/tran/7405)
# Below are a couple of test cases used for debugging purposes
#forests=[[(0,1),(0,10),(2,4),(3,4),(5,7),(6,7),(8,10),(9,10)], [(0,1),(0,10),(2,4),(3,4),(5,10),(6,7),(8,10),(9,10)], [(0,1),(0,10),(2,7),(3,4),(5,7),(6,7),(8,10),(9,10)], [(0,1),(0,10),(2,10),(3,4),(5,10),(6,7),(8,10),(9,10)], [(0,1),(0,10),(2,10),(3,4),(5,7),(6,7),(8,10),(9,10)]]
#forests=[[(0,10),(1,3),(2,3),(4,6),(5,6),(7,9),(8,9)], [(0,10),(1,3),(2,3),(4,6),(5,6),(7,10),(8,9)], [(0,10),(1,3),(2,3),(4,10),(5,6),(7,9),(8,9)], [(0,10),(1,10),(2,3),(4,6),(5,6),(7,9),(8,9)], [(0,10),(1,3),(2,3),(4,9),(5,6),(7,9),(8,9)], [(0,10),(1,9),(2,3),(4,6),(5,6),(7,9),(8,9)], [(0,10),(1,6),(2,3),(4,6),(5,6),(7,9),(8,9)], [(0,10),(1,3),(2,3),(4,10),(5,6),(7,10),(8,9)], [(0,10),(1,10),(2,3),(4,6),(5,6),(7,10),(8,9)], [(0,10),(1,10),(2,3),(4,10),(5,6),(7,9),(8,9)], [(0,10),(1,10),(2,3),(4,10),(5,6),(7,10),(8,9)], [(0,10),(1,9),(2,3),(4,9),(5,6),(7,9),(8,9)], [(0,10),(1,6),(2,3),(4,6),(5,6),(7,10),(8,9)], [(0,10),(1,10),(2,3),(4,9),(5,6),(7,9),(8,9)]]
#I=[0,1,2,4,5,7,8]
#J=[3,6,9,10]
#forests=[[(0,7),(1,2),(3,4),(5,6)]]
#I=[0,1,3,5]
#J=[2,4,6,7]
#cyclicForest=[[(0,0),(1,1),(2,2),(3,3)]]
#cyclicForest=[[(0,2),(1,2),(3,2),(4,5),(6,2),(7,8)], [(0,2),(1,2),(3,5),(4,5),(6,2),(7,8)], [(0,2),(1,2),(3,5),(4,5),(6,5),(7,8)], [(0,5),(1,2),(3,5),(4,5),(6,5),(7,8)], [(0,5),(1,2),(3,5),(4,5),(6,8),(7,8)], [(0,2),(1,2),(3,5),(4,5),(6,8),(7,8)], [(0,2),(1,2),(3,2),(4,5),(6,8),(7,8)], [(0,2),(1,2),(3,8),(4,5),(6,8),(7,8)], [(0,8),(1,2),(3,5),(4,5),(6,8),(7,8)], [(0,8),(1,2),(3,8),(4,5),(6,8),(7,8)]]
#cyclicForest=[[(0, 1), (2, 4), (3, 4), (5, 4), (6, 7)], [(0, 1), (2, 1), (3, 4), (5, 7), (6, 7)], [(0, 1), (2, 1), (3, 4), (5, 1), (6, 7)], [(0, 1), (2, 7), (3, 4), (5, 7), (6, 7)], [(0, 1), (2, 4), (3, 4), (5, 7), (6, 7)], [(0, 1), (2, 4), (3, 4), (5, 1), (6, 7)]]
#cyclicForest=[[(0, 1), (2, 10), (3, 4), (5, 7), (6, 7), (8, 10), (9, 10)], [(0, 1), (2, 4), (3, 4), (5, 10), (6, 7), (8, 10), (9, 10)], [(0, 1), (2, 1), (3, 4), (5, 7), (6, 7), (8, 1), (9, 10)], [(0, 1), (2, 1), (3, 4), (5, 10), (6, 7), (8, 10), (9, 10)], [(0, 1), (2, 1), (3, 4), (5, 1), (6, 7), (8, 10), (9, 10)], [(0, 1), (2, 4), (3, 4), (5, 7), (6, 7), (8, 1), (9, 10)], [(0, 1), (2, 1), (3, 4), (5, 1), (6, 7), (8, 1), (9, 10)], [(0, 1), (2, 4), (3, 4), (5, 4), (6, 7), (8, 10), (9, 10)], [(0, 1), (2, 4), (3, 4), (5, 1), (6, 7), (8, 10), (9, 10)], [(0, 1), (2, 7), (3, 4), (5, 7), (6, 7), (8, 10), (9, 10)], [(0, 1), (2, 4), (3, 4), (5, 1), (6, 7), (8, 1), (9, 10)], [(0, 1), (2, 7), (3, 4), (5, 7), (6, 7), (8, 1), (9, 10)], [(0, 1), (2, 4), (3, 4), (5, 4), (6, 7), (8, 4), (9, 10)], [(0, 1), (2, 1), (3, 4), (5, 7), (6, 7), (8, 10), (9, 10)], [(0, 1), (2, 10), (3, 4), (5, 10), (6, 7), (8, 10), (9, 10)], [(0, 1), (2, 4), (3, 4), (5, 4), (6, 7), (8, 1), (9, 10)], [(0, 1), (2, 7), (3, 4), (5, 7), (6, 7), (8, 7), (9, 10)], [(0, 1), (2, 4), (3, 4), (5, 7), (6, 7), (8, 7), (9, 10)], [(0, 1), (2, 4), (3, 4), (5, 7), (6, 7), (8, 4), (9, 10)], [(0, 1), (2, 4), (3, 4), (5, 7), (6, 7), (8, 10), (9, 10)]]
def cross(e0,e1):
#receives two edges of complete bipartite graph. returns True
#if they cyclically cross and False otherwise
n=max(max(e0[0],e0[1]),max(e1[0],e1[1]))
if ((e0[1]-e1[0])%(n+1) < (e0[1]-e0[0])%(n+1) and (e1[1]-e1[0])%(n+1)>(e0[1]-e1[0])%(n+1)) or ((e1[1]-e0[0])%(n+1)<(e0[1]-e0[0])%(n+1) and (e1[1]-e1[0])%(n+1)>(e1[1]-e0[0])%(n+1)): return True
else: return False
def coveringForests(I,J):
#receives as input two subsets I,J, produces first graph of cyclically
#crossing edges of the complete bipartite graph K_{I,J}, then its
#complement, and then the clique complex of that complement, which
#is the simplicial complex whose simplices consist of pairwise cyclically
#noncrossing edges. then it computes the boundary, and the minimal faces
# not in the boundary, which are the covering forests
# returns a list of covering forests
#first we compute the cyclically noncrossing complex:
n=max(max(I),max(J))
V=[(i,j) for i in I for j in J] # usar este para cicloedros
#V=[(i,j) for i in I for j in J if i<= j] # usar este para asociahedros
crossingGraph=Graph([V,cross])
nonCrossingGraph=crossingGraph.complement()
ncComplex=nonCrossingGraph.clique_complex()
#second we compute its interior faces:
d=ncComplex.dimension()
codim1=ncComplex.n_skeleton(d-1)
codim1Bdy=[]
for f in codim1.facets():
Link=ncComplex.link(f)
if len(Link.facets())==1: codim1Bdy.append(list(f))
Boundary=SimplicialComplex(codim1Bdy)
nonBdy=[sorted(list(F)) for F in Boundary.minimal_nonfaces()]
crossings=[sorted(list(E)) for E in crossingGraph.edges(labels=False)]
CF=[cf for cf in nonBdy if cf not in crossings]
return CF
#coveringForests=ncComplex.faces(subcomplex=Boundary)
#print coveringForests
def getInequalities(F):
# computes the inequality description, in polymake format (a matrix), of the bounded
# cell corresponding to covering forest F
I=[]
J=[]
for arc in F:
if arc[0] not in I: I.append(arc[0])
if arc[1] not in J: J.append(arc[1])
I.sort()
J.sort()
# An inequality a0 + a1 x1 + … + ad xd >= 0 is encoded as a row vector (a0,a1,…,ad)
ineqs=[]
for a in F:
for j in J:
if j >= a[0] and j != a[1]:
row=[1 if J.index(a[1])==jp else -1 if J.index(j)==jp else 0 for jp in range(len(J))]
# hij=-(j-a[0])^2+(a[1]-a[0])^2
hij=numerical_approx(sqrt((j-a[0]))-sqrt((a[1]-a[0])))
row=[hij]+row
# print row
ineqs.append(row)
cero=[[0]+[-1 if jp==len(J)-1 else 0 for jp in range(len(J))], [0]+[1 if jp==len(J)-1 else 0 for jp in range(len(J))]]
ineqs=ineqs+cero
return ineqs
def nonCrossingHeight(i,j,n):
# evaluates a cyclically non-crossing height function at a pair i, \ol j
# where the period of cyclicity is n
#f= numerical_approx(10*log((j-i)%(n+1)))
f=(-1)*numerical_approx(3^(-((j-i)%(n+1))))
return f
def getCyclic(F):
# this generates the cyclic inequalities corresponding to cyclic covering forest F
I=[]
J=[]
for arc in F:
if arc[0] not in I: I.append(arc[0])
if arc[1] not in J: J.append(arc[1])
I.sort()
J.sort()
n=max(max(I),max(J))
# computes the inequality description, in polymake format (a matrix), of the bounded
# cell corresponding to covering forest F
# An inequality a0 + a1 x1 + … + ad xd >= 0 is encoded as a row vector (a0,a1,…,ad)
ineqs=[]
for a in F:
for j in J:
#if j >= a[0] and j != a[1]: # usar este para asociaedros
if j != a[1]: # usar este para cicloedros
row=[1 if J.index(a[1])==jp else -1 if J.index(j)==jp else 0 for jp in range(len(J))]
hij=nonCrossingHeight(a[0],j,n)-nonCrossingHeight(a[0],a[1],n)
row=[hij]+row
# print row
ineqs.append(row)
cero=[[0]+[-1 if jp==len(J)-1 else 0 for jp in range(len(J))], [0]+[1 if jp==len(J)-1 else 0 for jp in range(len(J))]]
ineqs=ineqs+cero
return ineqs
# this still has to be extended like write cyclohedron
def writeAssociahedron(coveringFs):
# takes a list of covering forests and outputs polymake code with inequality
# descriptions, definition of polytopes and visualization of polytopes
m = len(coveringFs)
matrices=''
politopos=''
imprimirlos='compose('+','.join(['$pproj'+str(k)+'->VISUAL(VertexStyle=>"hidden")' for k in range(m)])+');'
for k in range(m):
ineqs=getInequalities(coveringFs[k])
matrices=matrices+'$a'+str(k)+'= new Matrix<Rational>('+str(ineqs)+');'
politopos=politopos+'$p'+str(k)+'= new Polytope<Rational>(INEQUALITIES=>$a'+str(k)+');$pproj'+str(k)+'=projection_full($p'+str(k)+');'
# change this in accordance with case being computed
with open('2cyclohedron4.txt','w') as archivo:
archivo.write(matrices+'\n')
archivo.write(politopos+'\n')
archivo.write('\n')
archivo.write('-------------------------------\n')
archivo.write(imprimirlos+'\n')
def writeCyclohedron(I,J):
# takes a list of covering forests and outputs polymake code with inequality
# descriptions, definition of polytopes and visualization of polytopes
coveringFs=coveringForests(I,J)
m = len(coveringFs)
minkowskiSums=[]
for F in range(len(coveringFs)):
oneSum=[]
for i in I:
ithSummand=[]
for e in coveringFs[F]:
if e[0]==i: ithSummand.append(e[1])
oneSum.append(ithSummand)
minkowskiSums.append(oneSum)
matrices=''
politopos=''
imprimirlos='compose('+','.join(['$pproj'+str(k)+'->VISUAL(VertexStyle=>"hidden")' for k in range(m)])+');'
for k in range(m):
ineqs=getCyclic(coveringFs[k])
matrices=matrices+'$a'+str(k)+'= new Matrix<Rational>('+str(ineqs)+');'
politopos=politopos+'$p'+str(k)+'= new Polytope<Rational>(INEQUALITIES=>$a'+str(k)+');$pproj'+str(k)+'=projection_full($p'+str(k)+');'
# change this in accordance with case being computed
with open('cyclohedron-power-'+''.join([str(i) for i in I])+'-'+''.join([str(j) for j in J])+'.txt','w') as archivo:
archivo.write(matrices+'\n')
archivo.write(politopos+'\n')
archivo.write('\n')
archivo.write('-------------------------------\n')
archivo.write(imprimirlos+'\n')
archivo.write('\n')
archivo.write(',\n'.join([str(w)+': '+str(minkowskiSums[w]) for w in range(len(minkowskiSums))]))
def mixedSubdivision(I,J):
# receives a pair of index sets I,J and produces the representation
# of the noncrossing complex as a fine mixed subdivision of a
# generalized permutahedron/polymatroid
n=len(J)-1
#V=[(i,j) for i in I for j in J] # usar este para cicloedros
V=[(i,j) for i in I for j in J if i<= j] # usar este para asociahedros
# first we compute the clique complex of the non-crossing graph
crossingGraph=Graph([V,cross])
nonCrossingGraph=crossingGraph.complement()
ncComplex=nonCrossingGraph.clique_complex()
# now we get minkowski sum representations for the facets of
# the noncrossing complex
minkowskiSums=[]
for F in ncComplex.facets():
oneSum=[]
for i in I:
ithSummand=[]
for e in F:
if e[0]==i: ithSummand.append(e[1])
oneSum.append(ithSummand)
minkowskiSums.append(oneSum)
# now generate polymake code with the minkowski sums giving
# the fine mixed subdivision
stdSimplexVertices=[v.vector() for v in polytopes.simplex(n,project=True).vertices()]
mixedCells=[sum([Polyhedron(vertices=[stdSimplexVertices[J.index(v)] for v in sumando]) for sumando in c]) for c in minkowskiSums]
mixedCellsPoly=';'.join(['; '.join(['$s'+str(i)+'=new Polytope<Rational>(POINTS=>'+str([[1]+list(stdSimplexVertices[J.index(v)]) for v in minkowskiSums[c][i]])+')' for i in range(len(minkowskiSums[c]))])+';'+'$p'+str(c)+'=minkowski_sum_fukuda('+','.join(['$s'+str(j) for j in range(len(minkowskiSums[c]))])+')' for c in range(len(minkowskiSums))])+';'
#smallSimplex=[v.vector() for v in polytopes.simplex(n-1,project=True).vertices()]
#restrictedMinkowskiSums=[[[i for i in e if i!= 0] for e in S] for S in minkowskiSums]
#restrictedMixedCellsPoly=';'.join(['; '.join(['$s'+str(i)+'=new Polytope<Rational>(POINTS=>'+str([[1]+list(smallSimplex[v-1]) for v in restrictedMinkowskiSums[c][i]])+')' for i in range(len(restrictedMinkowskiSums[c]))])+';'+'$p'+str(c)+'=minkowski_sum_fukuda('+','.join(['$s'+str(j) for j in range(len(restrictedMinkowskiSums[c]))])+')' for c in range(len(restrictedMinkowskiSums))])+';'
toPolyMatrix=';'.join(['$a'+str(c)+'=new Matrix<Rational>(['+','.join([str([1]+list(+v.vector())) for v in mixedCells[c].vertices()])+'])' for c in range(len(mixedCells))])+';'
toPolyPolytope=';'.join(['$p'+str(c)+'=new Polytope<Rational>(POINTS=>$a'+str(c)+')' for c in range(len(mixedCells))])+';'
printPoly='compose('+','.join(['$p'+str(c)+'->VISUAL(VertexStyle=>"hidden")' for c in range(len(mixedCells))])+');'
# print the output to a file
with open('mixedSubdivision'+''.join([str(i)for i in I])+'-'+''.join([str(j) for j in J])+'.txt','w') as archivo:
archivo.write(mixedCellsPoly+'\n')
archivo.write('\n')
archivo.write('-------------------------------\n')
archivo.write(printPoly+'\n')
archivo.write('\n')
archivo.write(',\n'.join([str(w)+': '+str(minkowskiSums[w]) for w in range(len(minkowskiSums))]))
def nonKCrossing(I,J,k):
# receives a pair of index sets I,J and produces the representation
# of the non-k-crossing complex as if it were a fine mixed subdivision of a
# generalized permutahedron/polymatroid.
# default for triangulations is k=1
n=len(J)-1
#V=[(i,j) for i in I for j in J] # usar este para cicloedros
V=[(i,j) for i in I for j in J if i<= j] # usar este para asociahedros
# first we compute the clique complex of the crossing graph
crossingGraph=Graph([V,cross])
crossingComplex=crossingGraph.clique_complex()
#initialize the complex of non-k-crossing edges as a full simplex
#on the edges of the graph
nonKCrossingComplex=SimplicialComplex([V])
for nonface in crossingComplex.n_cells(k):
nonKCrossingComplex.remove_face(nonface)
G=nonKCrossingComplex.flip_graph()
############## uncomment to generate fake mixed subdivision ####
# now we get fake minkowski sum representations for the facets of
# the noncrossing complex
minkowskiSums=[]
for F in nonKCrossingComplex.facets():
oneSum=[]
for i in I:
ithSummand=[]
for e in F:
if e[0]==i: ithSummand.append(e[1])
oneSum.append(ithSummand)
minkowskiSums.append(oneSum)
############## uncomment to generate fake mixed subdivision ####
# now generate polymake code with the minkowski sums giving
# the fine mixed subdivision
stdSimplexVertices=[v.vector() for v in polytopes.simplex(n,project=True).vertices()]
mixedCells=[sum([Polyhedron(vertices=[stdSimplexVertices[J.index(v)] for v in sumando]) for sumando in c]) for c in minkowskiSums]
mixedCellsPoly=';'.join(['; '.join(['$s'+str(i)+'=new Polytope<Rational>(POINTS=>'+str([[1]+list(stdSimplexVertices[J.index(v)]) for v in minkowskiSums[c][i]])+')' for i in range(len(minkowskiSums[c]))])+';'+'$p'+str(c)+'=minkowski_sum_fukuda('+','.join(['$s'+str(j) for j in range(len(minkowskiSums[c]))])+')' for c in range(len(minkowskiSums))])+';'
toPolyMatrix=';'.join(['$a'+str(c)+'=new Matrix<Rational>(['+','.join([str([1]+list(+v.vector())) for v in mixedCells[c].vertices()])+'])' for c in range(len(mixedCells))])+';'
toPolyPolytope=';'.join(['$p'+str(c)+'=new Polytope<Rational>(POINTS=>$a'+str(c)+')' for c in range(len(mixedCells))])+';'
printPoly='compose('+','.join(['$p'+str(c)+'->VISUAL(VertexStyle=>"hidden")' for c in range(len(mixedCells))])+');'
# print the output to a file
with open('non'+str(k)+'Crossing'+''.join([str(i)for i in I])+'-'+''.join([str(j) for j in J])+'.txt','w') as archivo:
archivo.write(mixedCellsPoly+'\n')
archivo.write('\n')
archivo.write('-------------------------------\n')
archivo.write(printPoly+'\n')
archivo.write('\n')
archivo.write(',\n'.join([str(w)+': '+str(minkowskiSums[w]) for w in range(len(minkowskiSums))]))
##########################
with open('dualgraphk'+str(k)+'-I'+''.join([str(i) for i in I])+'-J'+''.join([str(j) for j in J])+'.txt','w') as grafo:
for i in range(len(G.vertices())):
grafo.write(str(i)+': '+str(G.vertices()[i])+'\n')
G.relabel(perm=None)
grafoPolymake=[list(e) for e in G.edges(labels=False)]
grafo.write('$g=graph_from_edges('+str(grafoPolymake)+');\n')
grafo.write('$g->VISUAL;\n')
return nonKCrossingComplex