Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
GuillaumeLaplante-Anfossi
GitHub Repository: GuillaumeLaplante-Anfossi/Poissons
Path: blob/main/GeneratingDiagonalsViaShift/multiplihedra.py
1017 views
1
'''
2
Code for comparing SU and LA diagonal of multiplehdra.
3
The multipledra filter is code of Guillaume's from,
4
https://cocalc.com/projects/4ffaeb4c-c563-4526-8bbc-3d75298931c9/files/Multiplihedron_diagonal.ipynb#id=929148
5
'''
6
from itertools import combinations
7
8
from diagonals_via_shift import SU_diag, LA_diag
9
10
11
def ordered_partitions(a, k):
12
'''Splits a into k ordered partitions'''
13
n = len(a)
14
assert 1 <= k <= n, (n, k)
15
16
def split_at(js):
17
i = 0
18
19
for j in js:
20
yield a[i:j]
21
i = j
22
23
yield a[i:]
24
25
for separations in combinations(range(1, n), k - 1):
26
yield list(split_at(separations))
27
28
def all_to_right(element,j):
29
m = []
30
for x in element[j+1:]:
31
m = m + x
32
return m
33
34
def op_mult_filter(n, element):
35
'''
36
return: True if the ordered partition hits, False if not
37
'''
38
for j in range(len(element)-1):#for each block in the ordered partition / chosen face
39
if len(element[j])==1 or (n in element[j]):
40
continue
41
42
que = all_to_right(element,j)
43
44
OSP=list(ordered_partitions(element[j],2)) #all ordered partitions of this block into two pieces
45
for k in range(len(OSP)):#for each block bipartition
46
for x in que: #for each element in the queue
47
if min(element[j]) < x and x < max(element[j]):
48
#if ((max(OSP[k][0]) < x) and (x < min(OSP[k][1]))) or ((max(OSP[k][1]) < x) and (x < min(OSP[k][0]))):
49
#print(OSP[k][0],OSP[k][1])
50
return False
51
52
return True
53
54
55
def LA_Mult_diag(n):
56
valid = []
57
for p in LA_diag(n):
58
if op_mult_filter(n, p[0]) and op_mult_filter(n, p[1]):
59
valid.append(p)
60
61
return valid
62
63
def SU_Mult_diag(n):
64
valid = []
65
for p in SU_diag(n):
66
if op_mult_filter(n, p[0]) and op_mult_filter(n, p[1]):
67
valid.append(p)
68
69
return valid
70
71
def compare(n):
72
LA = sorted(LA_Mult_diag(n))
73
SU = sorted(SU_Mult_diag(n))
74
75
LA_only = []
76
SU_only = []
77
shared = []
78
for x in LA:
79
if x in SU:
80
shared.append(x)
81
else:
82
LA_only.append(x)
83
for x in SU:
84
if x not in LA:
85
SU_only.append(x)
86
87
return LA, LA_only, shared, SU_only, SU
88
89
90
def iso1(p):
91
'''
92
Applies the iso t(s x s)
93
'''
94
return [p[1][::-1],p[0][::-1]]
95
96
def iso2(p,n):
97
'''
98
Applies the iso t(r x r)
99
'''
100
def r(op,n):
101
rev = []
102
for block in op:
103
revblock = []
104
for x in block:
105
revblock.append(n-x+1)
106
rev.append(sorted(revblock))
107
return rev
108
109
return [r(p[1],n),r(p[0],n)]
110
111
if __name__ == '__main__':
112
113
print(iso2([[[1,3],[2,4]],[[1,3],[2,4]]],4))
114
115
for n in range(1,7):
116
print("\nn={}".format(n))
117
LA, LA_only, shared, SU_only, SU = compare(n)
118
119
print("|LA|={}, |LA only|={}, |shared|={}, |SU only|={}, |SU|={}".format(
120
len(LA), len(LA_only), len(shared), len(SU_only), len(SU)))
121
122
'''
123
#ILA = [iso1(x) for x in LA]
124
ILA = [iso2(x,n) for x in LA]
125
126
ILA_only = []
127
SU_only = []
128
shared = []
129
for x in ILA:
130
if x in SU:
131
shared.append(x)
132
else:
133
ILA_only.append(x)
134
for x in SU:
135
if x not in ILA:
136
SU_only.append(x)
137
138
print(len(ILA_only),len(shared),len(SU_only))
139
'''
140