1r"""
2
3"""
4
5from sage.misc.cachefunc import cached_method, cached_function
6from sage.topology import simplicial_complex, simplicial_set, delta_complex, cubical_complex
7from sage.rings.rational_field import QQ
8from itertools import combinations
9from sage.matrix.constructor import matrix, identity_matrix
10from sage.all import *
11
12@cached_method
13def parity(p):
14 r"""
15
16 """
17 return (sum((1 for (x, px) in enumerate(p) for (y, py) in enumerate(p) if ((x < y) and (px > py)))) % 2)
18
19@cached_method
20def sgn_face(face):
21 r"""
22
23 """
24 return prod([((- 1) ** i) for i in face])
25
26@cached_method
27def sgn_perm(p):
28 r"""
29
30 """
31 return ((- 1) ** parity(p))
32
33@cached_method
34def _face_data_SComplex(K, dim_from, dim_to, base_ring=QQ):
35 r"""
36
37 """
38 upperDims = (dim_to - dim_from)
39 faces = list(combinations(range((dim_to + 1)), upperDims))
40 data = {}
41 for face in faces:
42 d = dim_to
43 m = identity_matrix(base_ring, len(K.n_cells(d)), sparse=True)
44 for f in reversed(face):
45 m = _face_matrix_SComplex(K, f, d, base_ring) * m
46 d -= 1
47 data[face] = m
48 return data
49
50@cached_method
51def _face_matrix_SComplex(K, face, dim, base_ring=QQ):
52 r"""
53
54 """
55 K1 = K._n_cells_sorted((dim - 1))
56 K2 = K._n_cells_sorted(dim)
57 M = matrix(base_ring, len(K1), len(K2), (lambda i, j: (1 if (
58 (K1[i] in K2[j].faces()) and (K2[j].face(face) == K1[i])) else 0)), sparse=True)
59 return M
60
61@cached_method
62def _face_data_SSets(K, dim_from, dim_to, base_ring = QQ):
63 r"""
64
65 """
66 upperDims = (dim_to - dim_from)
67 faces = list(combinations(range((dim_to + 1)), upperDims))
68 data = {}
69
70 def filter_mat(dim):
71 all_cells = K.all_n_simplices(dim)
72 deg_cells_idx = [i for i in range(
73 len(all_cells)) if all_cells[i].is_degenerate()]
74 filter_matrix = identity_matrix(
75 base_ring, len(all_cells), sparse=True)
76 return filter_matrix.delete_columns(deg_cells_idx)
77 from_filter = filter_mat(dim_from)
78 to_filter = filter_mat(dim_to)
79 for face in faces:
80 d = dim_to
81 m = identity_matrix(base_ring, len(
82 K.all_n_simplices(d)), sparse=True)
83 for f in reversed(face):
84 m = _face_matrix_SSets(K, f, d) * m
85 d -= 1
86 data[face] = ((from_filter.T * m) * to_filter)
87 return data
88
89@cached_method
90def _face_matrix_SSets(K, face, dim, base_ring = QQ):
91 r"""
92
93 """
94 S1 = K.all_n_simplices((dim - 1))
95 S2 = K.all_n_simplices(dim)
96 face_data = K.face_data()
97 M = matrix(base_ring, len(S1), len(S2), (lambda i, j: (1 if (
98 (S1[i] in K.faces(S2[j])) and (K.face(S2[j], face) == S1[i])) else 0)), sparse=True)
99 return M
100
101@cached_method
102def _face_data(K, dim_from, dim_to, base_ring = QQ):
103 r"""
104
105 """
106 if isinstance(K, simplicial_set.SimplicialSet_finite):
107 return _face_data_SSets(K, dim_from, dim_to, base_ring)
108 elif isinstance(K,simplicial_complex.SimplicialComplex):
109 return _face_data_SComplex(K, dim_from, dim_to, base_ring)
110 else:
111 raise ValueError(f"{K} is neither a simplicial set nor a simplicial complex")
112
113@cached_method
114def _face_matrix(K, face, dim, base_ring = QQ):
115 r"""
116
117 """
118
119 if isinstance(K, simplicial_set.SimplicialSet_finite):
120 return _face_matrix_SSets(K, dim_from, dim_to, base_ring)
121 elif isinstance(K,simplicial_complex.SimplicialComplex):
122 return _face_matrix_SComplex(K, dim_from, dim_to, base_ring)
123 else:
124 raise ValueError(f"{K} is neither a simplicial set nor a simplicial complex")
125
[docs]
126def nconnectedFacePaths(degrees):
127 dimto = sum(degrees)
128 n = len(degrees)
129 upperDims = [dimto - p for p in degrees] # face paths of lenght q = dimto - p
130 fpaths = {p:tuple(combinations(range(dimto + 1), upperDims[i])) for i,p in enumerate(degrees)}
131 npaths = {p:binomial(dimto, p) for p in degrees}
132 rawprods = list(cartesian_product([fpaths[p] for p in degrees]))
133 prods = []
134 for fcandidate in rawprods:
135 s = [set(f) for f in fcandidate]
136 globalInters = s[0]
137 for f in s[1:]:
138 globalInters = globalInters.intersection(f)
139 if not len(globalInters) == 0:
140 continue
141 # the intersection of all face paths must be 0
142 # we check now the if every pair of p- and q-face paths are is (n-p-q)-connected
143 # we check if the intersections form an sphere
144 success = True
145 for pair in combinations(range(n), 2):
146 s = [set(fcandidate[i]) for i in pair]
147 if not len(s[0].intersection(s[1])) == dimto-sum([degrees[i] for i in pair]):
148 success=False
149 continue
150 if success:
151 prods += [fcandidate]
152 return prods
153
154
155"""
156from Sullivan_MM import *
157S = SimplicialAPL(10)
158degrees = [2,1,2,1]
159n = sum(degrees)
160K = simplicial_complexes.Simplex(n)
161W = APLK(K)
162
163prods = nconnectedFacePaths(degrees)
164wprods = [prod([S.whitney_map(fpath,n) for fpath in multipath]) for multipath in prods]
165redws = [w.reduce(0) for w in wprods]
166products = {p:w for p,w in zip(prods,redws)}
167# for f,w in products.items():
168# print(f"{f} ==> {w}")
169from Sullivan_MM.utils import sgn_perm
170flatProds = [flatten(p) for p in products]
171signs = [sgn_perm(p) for p in flatProds]
172theoIntegral = (prod([factorial(d) for d in degrees]))/factorial(n+len(degrees)-1)
173print(f"absolute value of each integral ==> {theoIntegral}")
174
175sg = -1 # <== sgn
176for i,(f,w) in enumerate(products.items()):
177 print(f"sgn {f} ==> {sign(w.integral())}")
178 assert signs[i] == sg*sign(w.integral())
179 assert abs(theoIntegral) == abs(w.integral())
180 print(f"face paths {f} ==> whitney product {w} ==> integral {w.integral()}")
181 print(f"face paths {f} ==> theoretical sign {signs[i]} ==> agreement {signs[i] == sign(w.integral())}")
182 print(f"abstule value of integral agrees with theoretical formula ==> {abs(theoIntegral) == abs(w.integral())}")
183 print()
184
185for i,(f,w) in enumerate(products.items()):
186 if not w.is_zero():
187 print(f"face paths {f} ==> whitney product {w} ==> integral {w.integral()}")
188"""
189# face paths ((0, 1), (0, 2), (1, 2)) ==> theoretical sign 1 ==> agreement True ==> integral -1/60
190# face paths ((0, 1), (0, 3), (1, 3)) ==> theoretical sign 1 ==> agreement True ==> integral -1/60
191# face paths ((0, 1), (1, 2), (0, 2)) ==> theoretical sign -1 ==> agreement True ==> integral 1/60
192# face paths ((0, 1), (1, 3), (0, 3)) ==> theoretical sign -1 ==> agreement True ==> integral 1/60
193# face paths ((0, 2), (0, 1), (1, 2)) ==> theoretical sign -1 ==> agreement True ==> integral 1/60
194# face paths ((0, 2), (0, 3), (2, 3)) ==> theoretical sign 1 ==> agreement True ==> integral -1/60
195# face paths ((0, 2), (1, 2), (0, 1)) ==> theoretical sign 1 ==> agreement True ==> integral -1/60
196# face paths ((0, 2), (2, 3), (0, 3)) ==> theoretical sign -1 ==> agreement True ==> integral 1/60
197# face paths ((0, 3), (0, 1), (1, 3)) ==> theoretical sign -1 ==> agreement True ==> integral 1/60
198# face paths ((0, 3), (0, 2), (2, 3)) ==> theoretical sign -1 ==> agreement True ==> integral 1/60
199# face paths ((0, 3), (1, 3), (0, 1)) ==> theoretical sign 1 ==> agreement True ==> integral -1/60
200# face paths ((0, 3), (2, 3), (0, 2)) ==> theoretical sign 1 ==> agreement True ==> integral -1/60
201# face paths ((1, 2), (0, 1), (0, 2)) ==> theoretical sign 1 ==> agreement True ==> integral -1/60
202# face paths ((1, 2), (0, 2), (0, 1)) ==> theoretical sign -1 ==> agreement True ==> integral 1/60
203# face paths ((1, 2), (1, 3), (2, 3)) ==> theoretical sign 1 ==> agreement True ==> integral -1/60
204# face paths ((1, 2), (2, 3), (1, 3)) ==> theoretical sign -1 ==> agreement True ==> integral 1/60
205# face paths ((1, 3), (0, 1), (0, 3)) ==> theoretical sign 1 ==> agreement True ==> integral -1/60
206# face paths ((1, 3), (0, 3), (0, 1)) ==> theoretical sign -1 ==> agreement True ==> integral 1/60
207# face paths ((1, 3), (1, 2), (2, 3)) ==> theoretical sign -1 ==> agreement True ==> integral 1/60
208# face paths ((1, 3), (2, 3), (1, 2)) ==> theoretical sign 1 ==> agreement True ==> integral -1/60
209# face paths ((2, 3), (0, 2), (0, 3)) ==> theoretical sign 1 ==> agreement True ==> integral -1/60
210# face paths ((2, 3), (0, 3), (0, 2)) ==> theoretical sign -1 ==> agreement True ==> integral 1/60
211# face paths ((2, 3), (1, 2), (1, 3)) ==> theoretical sign 1 ==> agreement True ==> integral -1/60
212# face paths ((2, 3), (1, 3), (1, 2)) ==> theoretical sign -1 ==> agreement True ==> integral 1/60
213
214# from Sullivan_MM import *
215# S = SimplicialAPL(10)
216# K = simplicial_complexes.Simplex(5)
217# W = APLK(K)
218# degrees = [1,2,2]
219# prods = nconnectedFacePaths(degrees)
220# fdata = W._face_data(1,3)
221# fpaths = list(fdata.keys())
222# prods = []
223# for f1 in fpaths:
224# for f2 in fpaths:
225# for f3 in fpaths:
226# s1 = set(f1)
227# s2 = set(f2)
228# s3 = set(f3)
229# if (len(s1.intersection(s2))==1 and len(s1.intersection(s3))==1 and
230# len(s2.intersection(s3))==1 and len(s1.intersection(s2.intersection(s3))) == 0):
231# prods += [(f1,f2,f3)]