-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConditional Oriented Matroids.sagews
351 lines (258 loc) · 6.48 KB
/
Conditional Oriented Matroids.sagews
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
#Conditional Oriented Matroids in SageMath
#Hery Randriamaro
#Institut für Mathematik, Universität Kassel
#hery.randriamaro@mathematik.uni-kassel.de
# 1 Conditional Oriented Matroids
# 1.1 Sign Systems
#Zero Set#
def Zero(X):
z = Set()
for i in range(len(X)):
if X[i] == 0:
z = z.union(Set([i]))
return z
#Element Support#
def Support(X):
s = Set()
for i in range(len(X)):
if X[i] in Set([-1, 1]):
s = s.union(Set([i]))
return s
#Separation Set#
def Separation(X, Y):
s = Set()
for i in range(len(X)):
if X[i] in Set([-1, 1]):
if X[i] == -Y[i]:
s = s.union(Set([i]))
return s
#Element Composition#
def sigma(a, b):
if a == 0:
return b
else:
return a
def Composition(X, Y):
return tuple(sigma(X[i], Y[i]) for i in range(len(X)))
#Sign System Fiber#
def Restriction(X, A):
return tuple(X[i] for i in Set(range(len(X))).difference(A))
def Fiber(L, X, A):
F = Set()
for Y in L:
if Restriction(Y, A) == Restriction(X, A):
F = F.union(Set([Y]))
return F
# 1.2 Conditional Oriented Matroids
#Face Symmetry Condition#
def neg(X):
return tuple(-X[i] for i in range(len(X)))
def FS(L):
a = True
for X in L:
for Y in L:
a = a & (Composition(X, neg(Y)) in L)
return a
#Strong Elimination Condition#
def SE(L):
a = True
for X in L:
for Y in L:
S = Set()
for Z in Fiber(L, Composition(X, Y), Separation(X, Y)):
S = S.union(Zero(Z))
a = a & (S.intersection(Separation(X, Y)) == Separation(X, Y))
return a
#Conditional Oriented Matroid#
def COM(L):
return FS(L) & SE(L)
# 1.3 Oriented Matroids
#Zero Vector Condition#
def Z(L):
return (tuple(0 for i in range(len(L.random_element()))) in L)
#Oriented Matroid#
def OM(L):
return COM(L) & Z(L)
# 1.4 Lopsided Systems
#Tope Composition Condition#
def TC(L):
a = True
for X in L:
for Y in Tuples([-1, 1], len(L.random_element())):
a = a & (Composition(X, Y) in L)
return a
#Lopsided System#
def LS(L):
return COM(L) & TC(L)
# 2 Construction of Conditional Oriented Matroids
# 2.1 Deletion and Contraction
#Conditional Oriented Matroid Deletion#
def Deletion(L, A):
return Set([Restriction(X, A) for X in L])
#Conditional Oriented Matroid Contraction#
def Contraction(L, A):
C = Set()
for X in L:
if Support(X).intersection(A) == Set():
C = C.union(Set([Restriction(X, A)]))
return C
# 2.2 Simplification
#Coloop Set#
def Coloop(L):
C = Set()
for e in range(len(L.random_element())):
Xe = Set([X[e] for X in L])
if len(Xe) == 1:
C = C.union(Set([e]))
return C
#Parallel Element Classes#
def parallel(L, e, f):
Le = tuple(X[e] for X in L)
Lf = tuple(X[f] for X in L)
return (Le == Lf) | (Le == neg(Lf))
def Parallel_Element(L):
E = Set(range(len(L.random_element())))
P = []
while E.cardinality() > 0:
for e in E:
Pe = Set([])
for f in E:
if parallel(L, e, f):
Pe = Pe.union(Set([f]))
if Pe.cardinality() > 0:
P.append(Pe)
E = E.difference(Pe)
return P
#Simplification#
def Simplification(L):
P = Parallel_Element(L)
F = Set()
for Q in P:
R = Q.difference(Set([Q.random_element()]))
F = F.union(R)
E = Set(range(len(L.random_element())))
A = F.union(Coloop(L))
return Deletion(L, A)
# 2.3 Generating from Topes
#Generalized Theorem of Mandel#
def Generalized_Mandel(T):
M = Set()
for X in Tuples([-1, 0, 1], len(T.random_element())):
a = True
for Y in T:
a = a & (Composition(X, neg(Y)) in T)
if a == True:
M = M.union(Set([tuple(X)]))
return M
# 3 Special Functions
# 3.1 The Varchenko Matrix
#Variables#
class VariableGenerator(object):
def __init__(self, prefix):
self.__prefix = prefix
@cached_method
def __getitem__(self, key):
return SR.var("%s%s"%(self.__prefix,key))
a = VariableGenerator('a')
b = VariableGenerator('b')
def q(k, l):
if l == -1:
return(a[k])
if l == 1:
return(b[k])
#Covector Distance Function#
def v(X, Y):
x=1
for i in Separation(X, Y):
x = x*q(i, X[i])
return x
#Varchenko Matrix#
def prec(X, Y):
a = True
for i in range(len(X)):
a = a & (X[i] in Set([0, Y[i]]))
return a
def IsMax(L, X):
a = True
if X not in L:
a = False
for Y in L.difference(Set([X])):
a = a & (not prec(X, Y))
return a
def Tope(L):
S = Set()
for X in L:
if IsMax(L, X):
S = S.union(Set([X]))
return S
def V(L):
return matrix([[v(X, Y) for Y in Tope(L)] for X in Tope(L)])
#Varchenko Determinant#
def Weight(X):
x=1
for i in Zero(X):
x = x*a[i]*b[i]
return x
def iBoundary(L, i, X):
S = Set()
for Y in L.difference(Set([X])):
if prec(Y, X) and (Y[i] == 0):
S = S.union(Set([Y]))
return S
def Theta(L, X):
M = []
i = Zero(X).random_element()
for Y in Tope(L):
if IsMax(iBoundary(L, i, Y), X):
M.append(Y)
return len(M)/2
def Varchenko(L):
return prod([(1-Weight(X))^(Theta(L, X)) for X in L.difference(Tope(L))])
# 3.2 The Aguiar-Mahajan Equation System
#Covector Face#
def Face(L, X):
S = Set()
for Y in L:
if prec(X, Y):
S = S.union(Set([Y]))
return S
#Element Corank#
def Min(L):
X = L.random_element()
for Y in L:
if prec(Y, X):
X=Y
return X
def crk(L, X):
k=0
F = Face(L, X).difference(Set([X]))
while not (F == Set()):
k = k+1
Y = Min(F)
F = Face(L, Y).difference(Set([Y]))
return k
#Element Dimensional Rank#
def rk(L):
k=0
for X in L:
k = max(k, crk(L, X))
return k
def drk(L, X):
return rk(L) - crk(L, X)
#Aguiar-Mahajan Equation System Solution#
def Inf(L, X):
S = Set()
for Y in L.difference(Set([X])):
if prec(Y, X):
S = S.union(Set([Y]))
return S
def AM(L, X, o):
S = Inf(L, X)
if X == Min(L):
return o
else:
return (-1/(1 - v(X, neg(X))*v(neg(X), X)))*sum(AM(L, Y, o) +
(-1)^(drk(L, X))*v(neg(X), X)*AM(L, neg(Y), o) for Y in S)
def AguiarMahajan(L, o):
for X in L:
print (X, " --> ", AM(L, X, o))