/
mobius.py
255 lines (217 loc) · 7.36 KB
/
mobius.py
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
import numpy as np
import scipy as sp
import permutation_functions as pf
####COMBINATORICS OF DUAL CLASSES
def simple_neighbors(g,sigma):
print str(sigma) + ' has length ' + str(pf.perm_length(g.type,sigma))
for u in simple_reflections():
v = pf.perm_mult(u,sigma)
print 'left multiplication by ' + str(u) + ' yields ' + str(v) + ' which has length ' + str(pf.perm_length(g.type,v))
def construct_maximals(g,Q):
f = lambda x: [[y for j, y in enumerate(x) if (i >> j) & 1] for i in range(2**len(x))]
def compatible(s,t):
return ((s[1] < t[0]) or (t[1] < s[0]))
def compatible_set(M):
for i in range(len(M)):
for j in range(i):
if not compatible(M[i],M[j]):
return False
return True
ups = sorted(g.up_reflections(Q))
simple_ups = []
nonsimple_ups = []
for t in ups:
if (t[0] > 0 and t[1]-t[0] > 1) or (t[1]-t[0] > 3):
nonsimple_ups.append(t)
else:
simple_ups.append(t)
compatible_sets = [M for M in f(nonsimple_ups) if compatible_set(M)]
maximal_sets = []
for M in compatible_sets:
maximal = True
for N in compatible_sets:
if N != M:
if set(M) < set(N):
maximal = False
if maximal:
maximal_sets.append(M)
use_again=[]
for s in simple_ups:
if s[0] > 0:
for t in simple_ups:
if s[1] == t[0]:
use_again.append(s)
if (-1,2) in simple_ups and (2,3) in simple_ups:
use_again.append((-1,2))
#print maximal_sets
#print simple_ups
#print nonsimple_ups
#print use_again
maximal_elements = []
for M in maximal_sets:
u = g.index2perm(Q)
for s in M:
u = pf.perm_mult(g.trans2perm(s),u)
for s in simple_ups:
u = pf.perm_mult(g.trans2perm(s),u)
for s in use_again:
u = pf.perm_mult(g.trans2perm(s),u)
maximal_elements.append(g.perm2index(u))
return sorted(maximal_elements)
def number_of_terms_in_dual(g,Q):
f = lambda x: [[y for j, y in enumerate(x) if (i >> j) & 1] for i in range(2**len(x))]
def compatible(s,t):
return ((s[1] < t[0]) or (t[1] < s[0]))
def compatible_set(M):
for i in range(len(M)):
for j in range(i):
if not compatible(M[i],M[j]):
return False
return True
ups = sorted(g.up_reflections(Q))
simple_ups = []
nonsimple_ups = []
for t in ups:
if (t[0] > 0 and t[1]-t[0] > 1) or (t[1]-t[0] > 3):
nonsimple_ups.append(t)
else:
simple_ups.append(t)
compatible_sets = [M for M in f(nonsimple_ups) if compatible_set(M)]
consecutive_pairs = 0
for s in simple_ups:
if s[0] > 0:
for t in simple_ups:
if s[1] == t[0]:
consecutive_pairs += 1
if (-1,2) in simple_ups and (2,3) in simple_ups:
consecutive_pairs += 1
return (3**(consecutive_pairs))*(2**(len(simple_ups)-consecutive_pairs))*(len(compatible_sets))
def understanding_compatibility(g):
for Q in g.schubert_list:
g.left_multiplication = True
def compatible(s,t):
return ((s[1] < t[0]) or (t[1] < s[0])) or s==t
ups = g.up_reflections(Q)
simple_ups = []
nonsimple_ups = []
for t in ups:
if (t[0] > 0 and t[1]-t[0] > 1) or (t[1]-t[0] > 3):
nonsimple_ups.append(t)
else:
simple_ups.append(t)
g.left_multiplication = False
right_ups = g.up_reflections(Q)
incomp_pairs = []
for x,y in get_tuples(nonsimple_ups,nonsimple_ups):
if x != y:
if compatible(x,y):
print 'COMPATIBLE pair ' + str(x) + ', '+str(y) + ' corresponds to ' + str(right_ups[ups.index(x)]) + ', ' + str(right_ups[ups.index(y)])
else:
incomp_pairs.append((x,y))
for x,y in incomp_pairs:
print 'incompatible pair ' + str(x) + ', '+str(y) + ' corresponds to ' + str(right_ups[ups.index(x)]) + ', ' + str(right_ups[ups.index(y)])
####TESTS
# def test_big_hyp(g):
# for Q in g.schubert_list:
# for P in [X for X in g.schubert_list if g.leq(Q,X)]:
# if (g.mobius(Q,P) != 0) != (symmetric_interval(Q,P)):
# print 'error in interval from ' + str(Q) + ' to ' + str(P)
# print g.signature(Q,P)
#
# def test_trivial_signature_on_multiple_maximals(g):
# for Q in g.schubert_list:
# Q_max = g.maximals(Q)
# if len(Q_max) > 1:
# for P in Q_max:
# if g.signature(Q,P) not in [[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1],[1,5,10,10,5,1]]:
# g.draw_poset(Q)
def where_do_incompatible_reflections_take_us(g):
g.perm_list = [g.index2perm(P) for P in g.schubert_list]
def compatible(s,t):
return ((s[1] < t[0]) or (t[1] < s[0]))
for P in g.schubert_list:
ups = sorted(g.up_reflections(P))
simple_ups = []
nonsimple_ups = []
for t in ups:
if t[0] > 0 and t[1]-t[0] > 1:
nonsimple_ups.append(t)
else:
simple_ups.append(t)
for M in get_tuples(nonsimple_ups,nonsimple_ups):
if M[0] != M[1] and not compatible(M[0],M[1]):
u = pf.perm_mult(pf.perm_mult(g.trans2perm(M[0]), g.trans2perm(M[1])),g.index2perm(P))
if u in g.perm_list:
print str(M[0]) + ' * ' + str(M[1]) + ' * ' + str(P) + ' = ' + str(u) + ', a valid permutation.'
else:
print str(M[0]) + ' * ' + str(M[1]) + ' * ' + str(P) + ' = ' + str(u) + ', NOT a valid permutation.'
def test_maximal_construction(g):
for P in g.schubert_list:
if construct_maximals(g,P) != g.maximals(P):
print 'error at ' + str(P) + ':'
print str(construct_maximals(g,P)) + ' not in ' + str(g.maximals(P))
def test_neighbors(g):
for Q in g.schubert_list:
ups = g.up_reflections(Q)
for t in ups:
#if t[1]-t[0]==2 and t[0] != -1:
#if t[0] != -1:
# if [t[0],t[0]+1] not in ups and [t[1]-1,t[1]] not in ups:
# print 'nonsimple reflection ' + str(t) + ' without a corresponding simple one'
# print ups
if t[0]*t[1] < -1:
print 'nonsimple signed reflection ' + str(t) + ' at ' + str(Q)
print ups
def symmetric_interval(g,Q,P):
interval = g.interval(Q,P)
sig = g.signature(Q,P)
if sig == sig[::-1]:
edge_sig = [len([covering(g.index2perm(X),g.index2perm(Y)) for (X,Y) in get_tuples(interval[c],interval[c+1]) if covering(g.index2perm(X),g.index2perm(Y)) != 0]) for c in range(len(interval)-1)]
return edge_sig == edge_sig[::-1]
return False
def boolean_mobius_support(g,Q):
for P in g.maximals(Q):
if g.signature(Q,P) not in [[1],[1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1], [1,5,10,10,5,1],[1,6,15,20,15,6,1]]:
return False
return True
def special_signature(g, Q,P):
interval = g.interval(Q,P)
sig = g.signature(Q,P)
edge_sig = [len([covering(g.index2perm(X),g.index2perm(Y)) for (X,Y) in get_tuples(interval[c],interval[c+1]) if covering(g.index2perm(X),g.index2perm(Y)) != 0]) for c in range(len(interval)-1)]
return (sig,edge_sig) in [([1, 1], [1]),
([1, 2, 1], [2, 2]),
([1, 2, 2, 1], [2, 4, 2]),
([1, 3, 3, 1], [3, 6, 3]),
([1, 3, 4, 3, 1], [3, 8, 8, 3]),
([1], []),
([1, 4, 6, 4, 1], [4, 12, 12, 4]),
([1, 4, 7, 7, 4, 1], [4, 14, 20, 14, 4]),
([1, 4, 8, 10, 8, 4, 1], [4, 16, 28, 28, 16, 4]),
([1, 5, 10, 10, 5, 1], [5, 20, 30, 20, 5]),
([1, 5, 11, 14, 11, 5, 1], [5, 22, 41, 41, 22, 5]),
([1, 5, 12, 18, 18, 12, 5, 1], [5, 24, 52, 66, 52, 24, 5])]
def bad_reflections(g,T):
perm = g.index2perm(T)
refs = g.simple_reflections()
for s in refs:
a = []
for P in g.schubert_list:
if pf.perm_leq(g.type,pf.perm_mult(perm,s),g.index2perm(P)):
a.append(P)
m = []
for P in a:
minimal = True
for Q in a:
if g.leq(Q,P) and Q != P:
minimal = False
if minimal:
m.append(g.index2perm(P))
print 'minimal signed permutations violating reflection ' + str(s) + ':'
print m
####GENERAL FUNCTIONS
def get_tuples(A,B):
tuples_list = []
for i in A:
for j in B:
tuples_list.append((i,j))
return tuples_list