-
Notifications
You must be signed in to change notification settings - Fork 0
/
transferBR4.py
440 lines (329 loc) · 18.8 KB
/
transferBR4.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
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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
# Standard imports
from argparse import ArgumentParser
from codecs import getwriter
from re import compile
import sys
# Local imports
import CellChainParse
from support_functions import *
from formatting import *
__author__ = 'mfansler'
# Debugging
# numpy.set_printoptions(threshold=numpy.nan)
def compare_incidences(x, y):
return x[1] - y[1] if x[1] != y[1] else x[0] - y[0]
def chain_coproduct(chain, coproduct, simplify=True):
ps = [p for cell in chain for p, num in coproduct[cell].items() if num % 2]
return [el for el, num in Counter(ps).items() if num % 2] if simplify else ps
__hom_dim_re = compile('h(\d*)_')
def hom_dim(h_element):
return int(__hom_dim_re.match(h_element).group(1))
def differential2_space(AxA, diff_op):
dAxA = {}
for dim, vs in AxA.items():
dAxA[dim] = {}
for (l, r) in vs:
dLeft = [(l_i, r) for l_i in diff_op[l]] if l in diff_op else []
dRight = [(l, r_i) for r_i in diff_op[r]] if r in diff_op else []
if dLeft + dRight:
dAxA[dim][(l, r)] = dLeft + dRight
return dAxA
def main():
TEMP_MAT = "~transfer-temp.mat"
# Needed to support output of utf-8
sys.stdout = getwriter('utf-8')(sys.stdout)
argparser = ArgumentParser(description="Computes induced coproduct on homology")
argparser.add_argument('file', type=file, help="LaTeX file to be parsed")
args = None
try:
args = argparser.parse_args()
except Exception as e:
print e.strerror
argparser.print_help()
raise SystemExit
# load file
data = args.file.read()
args.file.close()
# parse file contents
result = CellChainParse.parse(data)
if not result:
raise SystemExit
# construct coalgebra
C = Coalgebra(result["groups"], result["differentials"], result["coproducts"])
differential = {n: C.incidence_matrix(n, sparse=False) for n in range(1, C.topDimension() + 1)}
delta_c = {k: [c for c, i in v.items() if i % 2] for k, v in C.coproduct.items()}
"""
Checking Coassociativity on Delta_C
"""
# (1 x Delta) Delta
id_x_Delta_Delta = {k: [(l,) + r_cp for (l, r) in v for r_cp in delta_c[r]] for k, v in delta_c.items()}
# print
# print u"(1 " + OTIMES + " " + DELTA + ") " + DELTA + " =", format_morphism({k: [format_tuple(t) for t in v] for k, v in id_x_Delta_Delta.items() if v})
# (Delta x 1) Delta
Delta_x_id_Delta = {k: [l_cp + (r,) for (l, r) in v for l_cp in delta_c[l]] for k, v in delta_c.items()}
# print
# print u"(" + DELTA + " " + OTIMES + " 1) " + DELTA + " =", format_morphism({k: [format_tuple(t) for t in v] for k, v in Delta_x_id_Delta.items() if v})
# DeltaC = (1 x Delta_C + Delta_C x 1) Delta_C
id_x_Delta_Delta_x_id_Delta = add_maps_mod_2(id_x_Delta_Delta, Delta_x_id_Delta)
id_x_Delta_Delta_x_id_Delta = {k: list_mod(ls, modulus=2) for k, ls in expand_map_all(id_x_Delta_Delta_x_id_Delta).items()}
print DELTA + "_c is co-associative?", not any(id_x_Delta_Delta_x_id_Delta.values())
if any(id_x_Delta_Delta_x_id_Delta.values()):
print u"\n(1 " + OTIMES + " " + DELTA + " + " + DELTA + " " + OTIMES + " 1) " + DELTA + " =", format_morphism({k: [format_tuple(t) for t in v] for k, v in id_x_Delta_Delta_x_id_Delta.items() if v})
#print "(raw) =", id_x_Delta_Delta_x_id_Delta
# factored_id_x_Delta_Delta_id_Delta = {k: factorize(v) for k, v in id_x_Delta_Delta_id_Delta.items()}
# print factored_id_x_Delta_Delta_id_Delta
"""
COMPUTE HOMOLOGY
"""
H_gens = {}
# Manually entering results from SageMath for basis for homology
H_gens[0] = [['v_{-2}']]
H_gens[1] = [['c_{-2}^{+}', 'c_{-2}^{-}'], ['m_{0}^{+}', 'm_{0}^{-}'],
['m_{5}^{+}', 'm_{5}^{-}'], ['m_{10}^{+}', 'm_{10}^{-}']]
H_gens[2] = [['t_{0}^{++}', 't_{0}^{+-}', 't_{0}^{-+}', 't_{0}^{--}'],
['t_{5}^{++}', 't_{5}^{+-}', 't_{5}^{-+}', 't_{5}^{--}'],
['t_{10}^{++}', 't_{10}^{+-}', 't_{10}^{-+}', 't_{10}^{--}']]
#H_gens[3] = []
H = {dim: ["h{}_{}".format(dim, i) for i, gen in enumerate(gens)] for dim, gens in H_gens.items()}
print "\nH = H*(C) = ", H
"""
DEFINE MAPS BETWEEN CHAINS AND HOMOLOGY
"""
# Define g
g = {"h{}_{}".format(dim, i): gen for dim, gens in H_gens.items() for i, gen in enumerate(gens) if gen}
print
print "g = ", format_morphism(g)
# generate f: C -> H
f, integrate = generate_f_integral(C, g)
"""
COMPUTE Delta_2, g^2
"""
# define Delta g
delta_g = {k: chain_coproduct(v, C.coproduct) for k, v in g.items()}
print
print DELTA + u"g =", format_morphism(delta_g)
print
print DELTA + u"g (unsimplified) =", {k: chain_coproduct(v, C.coproduct, simplify=False) for k, v in g.items()}
factored_delta_g = {k: factorize_cycles(v, C) for k, v in delta_g.items()}
print
print DELTA + u"g (factored) =", format_morphism(factored_delta_g)
delta2 = {k: [tuple(map(f, list(t))) for t in tuples] for k, tuples in factored_delta_g.items()}
# flatten delta2 and remove up empty elements
#delta2 = {k: [tp_i for tp in tps for tp_i in expand_tuple_list(tp)]for k, tps in delta2.items()}
delta2 = chain_map_mod(expand_map_all(delta2))
print
print DELTA + u"_2 =", format_morphism({k: [format_tuple(t) for t in v] for k, v in delta2.items()})
# (g x g) Delta2
gxgDelta = {k: [(g_l, g_r) for l, r in v for g_l in g[l] for g_r in g[r]] for k, v in delta2.items()}
print
print u"(g " + OTIMES + " g)" + DELTA + "_2 =", format_morphism({k: [format_tuple(t) for t in v] for k, v in gxgDelta.items()})
# nabla g^2
nabla_g2 = add_maps_mod_2(gxgDelta, delta_g)
print
print u"(g " + OTIMES + " g)" + DELTA + "_2 + " + DELTA + "g =", format_morphism({k: [format_tuple(t) for t in v] for k, v in nabla_g2.items() if v})
# g^2
g2 = {k: integrate(vs) for k, vs in nabla_g2.items()}
g2 = {k: [tp_i for tp in tps for tp_i in expand_tuple_list(tp)]for k, tps in g2.items()}
print
print u"g^2 =", format_morphism({k: [format_tuple(t) for t in v] for k, v in g2.items() if v})
"""
VERIFY CONSISTENCY OF DELTA2, g^2 RESULTS
"""
nabla_g2_computed = {k: [exp_tp for (l, r) in derivative(v, C) for exp_tp in expand_tuple_list((l, r)) if l and r] for k, v in g2.items() if v}
nabla_g2_computed = {k: list_mod(vs, modulus=2) for k, vs in nabla_g2_computed.items()}
print
print NABLA + u" g^2 =", format_morphism(nabla_g2_computed)
print u"\n(g " + OTIMES + " g)" + DELTA + "_2 + " + DELTA + "g + " + NABLA + "g^2 = 0 ? ",
print not any(add_maps_mod_2(nabla_g2_computed, nabla_g2).values())
# -------------------------------------------- #
"""
VERIFY DELTA2 COASSOCIATIVITY
"""
# (1 x Delta_2) Delta_2
id_x_Delta2_Delta2 = {k: [(l,) + r_cp for (l, r) in v for r_cp in delta2[r]] for k, v in delta2.items()}
# print
# print u"(1 " + OTIMES + " " + DELTA + "_2) " + DELTA + "_2 =", format_morphism({k: [format_tuple(t) for t in v] for k, v in id_x_Delta2_Delta2.items() if v})
# (Delta_2 x 1) Delta_2
Delta2_x_id_Delta2 = {k: [l_cp + (r,) for (l, r) in v for l_cp in delta2[l]] for k, v in delta2.items()}
# print
# print u"(" + DELTA + "_2 " + OTIMES + " 1) " + DELTA + "_2 =", format_morphism({k: [format_tuple(t) for t in v] for k, v in Delta2_x_id_Delta2.items() if v})
# z_1 = (1 x Delta_2 + Delta_2 x 1) Delta_2
z_1 = add_maps_mod_2(id_x_Delta2_Delta2, Delta2_x_id_Delta2)
# print
# print u"z_1 = (1 " + OTIMES + " " + DELTA + "_2 + " + DELTA + "_2 " + OTIMES + " 1) " + DELTA + "_2 =", format_morphism({k: [format_tuple(t) for t in v] for k, v in z_1.items() if v})
print
print DELTA + "_2 is co-associative?", not any(z_1.values())
"""
COMPUTE DELTA_C_3
"""
# #(1 x Delta + Delta x 1) Delta g
# id_x_Delta_Delta_id_Delta_g = {k: list_mod([tp for c in v for tp in id_x_Delta_Delta_x_id_Delta[c]], 2) for k, v in g.items()}
# print
# print u"(1 " + OTIMES + " " + DELTA + " + " + DELTA + " " + OTIMES + " 1) " + DELTA + "g =", format_morphism({k: [format_tuple(t) for t in v] for k, v in id_x_Delta_Delta_id_Delta_g.items() if v})
# Delta_c3
delta_c3 = integrate(id_x_Delta_Delta_x_id_Delta)
delta_c3 = chain_map_mod(expand_map_all(delta_c3))
print
print DELTA + u"_C3 =", format_morphism({k: [format_tuple(t) for t in v] for k, v in delta_c3.items() if v})
# verify consistency
nabla_delta_c3_computed = derivative(delta_c3, C)
nabla_delta_c3_computed = chain_map_mod(expand_map_all(nabla_delta_c3_computed))
print
print NABLA + DELTA + u"_C3 =", format_morphism(nabla_delta_c3_computed)
print u"\n(1 " + OTIMES + " " + DELTA + " + " + DELTA + " " + OTIMES + " 1) " + DELTA + " + " + NABLA + DELTA + u"_C3 = 0 ? ",
print not any(add_maps_mod_2(id_x_Delta_Delta_x_id_Delta, nabla_delta_c3_computed).values())
if any(add_maps_mod_2(id_x_Delta_Delta_x_id_Delta, nabla_delta_c3_computed).values()):
print u"\n(1 " + OTIMES + " " + DELTA + " + " + DELTA + " " + OTIMES + " 1) " + DELTA + " + " + NABLA + DELTA + u"_C3 =",
print format_morphism({k: [format_tuple(t) for t in v] for k, v in add_maps_mod_2(id_x_Delta_Delta_x_id_Delta, nabla_delta_c3_computed).items() if v})
"""
COMPUTE DELTA3, g^3
"""
# (1 x Delta) g^2
id_x_Delta_g2 = {k: [(l,) + r_cp for (l, r) in v for r_cp in C.coproduct[r].keys()] for k, v in g2.items()}
print
print u"(1 " + OTIMES + " " + DELTA + ") g^2 =", format_morphism({k: [format_tuple(t) for t in v] for k, v in id_x_Delta_g2.items() if v})
# (Delta x 1) g^2
Delta_x_id_g2 = {k: [l_cp + (r,) for (l, r) in v for l_cp in C.coproduct[l].keys()] for k, v in g2.items()}
print
print u"(" + DELTA + " " + OTIMES + " 1) g^2 =", format_morphism({k: [format_tuple(t) for t in v] for k, v in Delta_x_id_g2.items() if v})
# (g x g^2) Delta_2
g_x_g2_Delta2 = {k: [(l_cp,) + t for l, r in v for t in g2[r] for l_cp in g[l]] for k, v in delta2.items()}
print
print u"( g " + OTIMES + " g^2 ) " + DELTA + "_2 =", format_morphism({k: [format_tuple(t) for t in v] for k, v in g_x_g2_Delta2.items() if v})
# (g^2 x g) Delta_2
g2_x_g_Delta2 = {k: [t + (r_cp,) for l, r in v for t in g2[l] for r_cp in g[r]] for k, v in delta2.items()}
print
print u"( g^2 " + OTIMES + " g ) " + DELTA + "_2 =", format_morphism({k: [format_tuple(t) for t in v] for k, v in g2_x_g_Delta2.items() if v})
# delta_c3_g
delta_c3_g = {k: [tp for v in vs if v in delta_c3 for tp in delta_c3[v]] for k, vs in g.items()}
print
print DELTA + "_c3 g =", format_morphism({k: [format_tuple(t) for t in v] for k, v in delta_c3_g.items() if v})
# phi_1 = (1 x Delta + Delta x 1) g^2 + (g x g^2 + g^2 x g) Delta_2 + Delta_C3 g
phi_1 = reduce(add_maps_mod_2, [g_x_g2_Delta2, g2_x_g_Delta2, id_x_Delta_g2, Delta_x_id_g2, delta_c3_g], {})
print
print PHI + u"_1 = (g " + OTIMES + " g^2 + g^2 " + OTIMES + " g) " + DELTA + "_2 +",
print "(1 " + OTIMES + " " + DELTA + " + " + DELTA + " " + OTIMES + " 1) g^2 + " + DELTA + "_c3 =",
print format_morphism({k: [format_tuple(t) for t in v] for k, v in phi_1.items() if v})
#print PHI + u"_1 (raw) =", phi_1
# Nabla phi_1 == 0 ? (Verify consistency)
nabla_phi_1 = {k: [(l, m, r) for (l, m, r) in derivative(v, C) if l and m and r] for k, v in phi_1.items() if v}
nabla_phi_1 = chain_map_mod(expand_map_all(nabla_phi_1))
print
print NABLA + PHI + u"_1 =", format_morphism({k: [format_tuple(t) for t in v] for k, v in nabla_phi_1.items()})
# factor phi_1
factored_phi_1 = {k: factorize_cycles(v, C) for k, v in phi_1.items() if v}
print
print PHI + u"_1 (factored) =", factored_phi_1
delta3 = {k: [tuple(map(f, list(t))) for t in tuples] for k, tuples in factored_phi_1.items()}
# flatten delta3 and remove up empty elements
delta3 = chain_map_mod(expand_map_all(delta3))
#delta3 = {k: [tp_i for tp in tps for tp_i in expand_tuple_list(tp)]for k, tps in delta3.items()}
print
print DELTA + u"_3 =", format_morphism({k: [format_tuple(t) for t in v] for k, v in delta3.items()})
# (g x g x g) Delta3
gxgxg_delta3 = {k: [(g_l, g_m, g_r) for l, m, r in v for g_l in g[l] for g_m in g[m] for g_r in g[r]] for k, v in delta3.items()}
print
print u"(g " + OTIMES + " g " + OTIMES + " g)" + DELTA + "_3 =", format_morphism({k: [format_tuple(t) for t in v] for k, v in gxgxg_delta3.items()})
# Nabla phi_1 == 0 ? (Verify consistency)
nabla_gxgxg_delta3 = {k: [(l, m, r) for (l, m, r) in derivative(v, C) if l and m and r] for k, v in gxgxg_delta3.items() if v}
nabla_gxgxg_delta3 = chain_map_mod(expand_map_all(nabla_gxgxg_delta3))
print
print NABLA + u"(g x g x g) " + DELTA + u"^3 =", format_morphism({k: [format_tuple(t) for t in v] for k, v in nabla_gxgxg_delta3.items()})
# nabla g^3
nabla_g3 = add_maps_mod_2(gxgxg_delta3, phi_1)
print
print u"(g " + OTIMES + " g " + OTIMES + " g)" + DELTA + "_3 + " + PHI + "_1 =", format_morphism({k: [format_tuple(t) for t in v] for k, v in nabla_g3.items() if v})
# g^3
g3 = {k: integrate(vs) for k, vs in nabla_g3.items()}
#g3 = {k: [tp_i for tp in tps for tp_i in expand_tuple_list(tp)]for k, tps in g3.items() if tps}
g3 = chain_map_mod(expand_map_all(g3))
print
print u"g^3 =", format_morphism({k: [format_tuple(t) for t in v] for k, v in g3.items() if v})
"""
VERIFY CONSISTENCY OF phi_1, Delta_3, and g^3
"""
nabla_g3_computed = {k: [(l, m, r) for (l, m, r) in derivative(v, C) if l and m and r] for k, v in g3.items() if v}
nabla_g3_computed = chain_map_mod(expand_map_all(nabla_g3_computed))
print
print NABLA + u" g^3 =", format_morphism({k: [format_tuple(t) for t in v] for k, v in nabla_g3_computed.items()})
print u"(g " + OTIMES + " g " + OTIMES + " g)" + DELTA + "_3 + " + PHI + "_1 + " + NABLA + "g^3 = 0 ? ",
print not any(reduce(add_maps_mod_2, [gxgxg_delta3, nabla_g3_computed, phi_1], {}).values())
if any(reduce(add_maps_mod_2, [gxgxg_delta3, nabla_g3_computed, phi_1], {}).values()):
print "\t", reduce(add_maps_mod_2, [gxgxg_delta3, nabla_g3_computed, phi_1], {})
exit()
#####################
# Facets of J_4
#####################
# (1 x 1 x Delta) g^3
id_x_id_x_Delta_g3 = {k: [(l, m) + r_cp for (l, m, r) in v for r_cp in C.coproduct[r].keys()] for k, v in g3.items()}
print
print u"(1 " + OTIMES + " 1 " + OTIMES + " " + DELTA + ") g^3 =", format_morphism({k: [format_tuple(t) for t in v] for k, v in id_x_id_x_Delta_g3.items() if v})
# (1 x Delta x 1) g^3
id_x_Delta_x_id_g3 = {k: [(l, ) + m_cp + (r, ) for (l, m, r) in v for m_cp in C.coproduct[m].keys()] for k, v in g3.items()}
print
print u"(1 " + OTIMES + " " + DELTA + " " + OTIMES + " 1) g^3 =", format_morphism({k: [format_tuple(t) for t in v] for k, v in id_x_Delta_x_id_g3.items() if v})
# (Delta x 1 x 1) g^3
Delta_x_id_x_id_g3 = {k: [l_cp + (m, r) for (l, m, r) in v for l_cp in C.coproduct[l].keys()] for k, v in g3.items()}
print
print u"(" + DELTA + " " + OTIMES + " 1 " + OTIMES + " 1) g^3 =", format_morphism({k: [format_tuple(t) for t in v] for k, v in Delta_x_id_x_id_g3.items() if v})
# (g x g^3) Delta_2
g_x_g3_Delta2 = {k: [(g[l],) + t for l, r in v for t in g3[r]] for k, v in delta2.items()}
print
print u"( g " + OTIMES + " g^3 ) " + DELTA + "_2 =", format_morphism({k: [format_tuple(t) for t in v] for k, v in g_x_g3_Delta2.items() if v})
# (g^2 x g^2) Delta_2
g2_x_g2_Delta2 = {k: [s + t for l, r in v for s in g2[l] for t in g2[r]] for k, v in delta2.items()}
print
print u"( g^2 " + OTIMES + " g^2 ) " + DELTA + "_2 =", format_morphism({k: [format_tuple(t) for t in v] for k, v in g2_x_g2_Delta2.items() if v})
# (g^3 x g) Delta_2
g3_x_g_Delta2 = {k: [t + (g[r],) for l, r in v for t in g3[l]] for k, v in delta2.items()}
print
print u"( g^3 " + OTIMES + " g ) " + DELTA + "_2 =", format_morphism({k: [format_tuple(t) for t in v] for k, v in g3_x_g_Delta2.items() if v})
# (g x g x g^2) Delta_3
g_x_g_x_g2_Delta3 = {k: [(g[l], g[m]) + t for l, m, r in v for t in g2[r]] for k, v in delta3.items()}
print
print u"( g " + OTIMES + " g " + OTIMES + " g^2 ) " + DELTA + "_3 =", format_morphism({k: [format_tuple(t) for t in v] for k, v in g_x_g_x_g2_Delta3.items() if v})
# (g x g^2 x g) Delta_3
g_x_g2_x_g_Delta3 = {k: [(g[l], ) + t + (g[r], ) for l, m, r in v for t in g2[m]] for k, v in delta3.items()}
print
print u"( g " + OTIMES + " g^2 " + OTIMES + " g ) " + DELTA + "_3 =", format_morphism({k: [format_tuple(t) for t in v] for k, v in g_x_g2_x_g_Delta3.items() if v})
# (g^2 x g x g) Delta_3
g2_x_g_x_g_Delta3 = {k: [t + (g[m], g[r]) for l, m, r in v for t in g2[l]] for k, v in delta3.items()}
print
print u"( g^2 " + OTIMES + " g " + OTIMES + " g ) " + DELTA + "_3 =", format_morphism({k: [format_tuple(t) for t in v] for k, v in g2_x_g_x_g_Delta3.items() if v})
# phi_2
phi_2 = reduce(add_maps_mod_2, [id_x_id_x_Delta_g3, id_x_Delta_x_id_g3, Delta_x_id_x_id_g3, g_x_g3_Delta2,
g3_x_g_Delta2, g2_x_g2_Delta2, g_x_g_x_g2_Delta3, g_x_g2_x_g_Delta3, g2_x_g_x_g_Delta3], {})
print
print PHI + u"_2 =", format_morphism({k: [format_tuple(t) for t in v] for k, v in phi_2.items() if v})
CxCxCxC = tensor(C.groups, C.groups, C.groups, C.groups)
# print CxCxCxC # debug
dCxCxCxC = {}
for k, vs in CxCxCxC.items():
dCxCxCxC[k] = {}
for (v1, v2, v3, v4) in vs:
dv1 = [(v1_i, v2, v3, v4) for v1_i in C.differential[v1]] if v1 in C.differential else []
dv2 = [(v1, v2_i, v3, v4) for v2_i in C.differential[v2]] if v2 in C.differential else []
dv3 = [(v1, v2, v3_i, v4) for v3_i in C.differential[v3]] if v3 in C.differential else []
dv4 = [(v1, v2, v3, v4_i) for v4_i in C.differential[v4]] if v4 in C.differential else []
if dv1 + dv2 + dv3 + dv4:
dCxCxCxC[k][(v1, v2, v3, v4)] = dv1 + dv2 + dv3 + dv4
delta4 = {}
g4 = {} # all boundary found in image will become part of g4
for k, v in g.items():
dim = int(k[1])+3
img = phi_2[k]
g4[k] = []
for chain, bd in dCxCxCxC[dim].items():
if all([cell in img for cell in bd]):
g4[k].append(chain)
for cell in bd:
img.remove(cell)
delta4[k] = img
delta4 = {k: [(g_inv[v1], g_inv[v2], g_inv[v3], g_inv[v4]) for (v1, v2, v3, v4) in v] for k, v in delta4.items() if v}
print
print DELTA + u"_4 =", format_morphism({k: [format_tuple(t) for t in v] for k, v in delta4.items()})
# g^4
print
print u"g^4 =", format_morphism({k: [format_tuple(t) for t in v] for k, v in g4.items() if v})
if __name__ == '__main__':
main()