Indexed text attachment
verify-topology.py
Source for Algebraic and Differential Topology in Higher Categories
View paper · Download original file
Lines 621–720 of 1961. Source text is displayed literally.
621 return [A[i][n] for i in range(n)]622 623 624def homology_trace(K, vmap, d):625 """trace of the map induced on H_d(K; Q) by a simplicial self-map"""626 n = K.n(d)627 Z = nullspace(K.bd(d), n) if d > 0 else [[Fr(int(i == j)) for i in range(n)] for j in range(n)]628 Bd = K.bd(d + 1) if d < K.dim else []629 Bcols = [list(c) for c in zip(*Bd)] if Bd and Bd[0] else []630 Bbasis = independent_extend([], [[Fr(x) for x in c] for c in Bcols])631 H = independent_extend(Bbasis, Z)632 if not H:633 return 0634 F = chain_map(K, K, vmap, d)635 cols = Bbasis + H636 t = Fr(0)637 for j, h in enumerate(H):638 img = [sum(F[i][k] * h[k] for k in range(n)) for i in range(n)]639 co = solve_coords(cols, img)640 t += co[len(Bbasis) + j]641 return t642 643 644def lefschetz_chain(K, vmap):645 return sum((-1) ** d * trace(chain_map(K, K, vmap, d)) for d in range(K.dim + 1))646 647 648def lefschetz_hom(K, vmap):649 return sum((-1) ** d * homology_trace(K, vmap, d) for d in range(K.dim + 1))650 651 652def sd(K):653 """barycentric subdivision; vertices are the simplices of K, numbered by (dim, index)"""654 num = {}655 for d in range(K.dim + 1):656 for x in K.S[d]:657 num[x] = len(num)658 facets = []659 for d in range(K.dim, -1, -1):660 for x in K.S[d]:661 if any(set(x) < set(y) for y in K.S.get(d + 1, [])):662 continue663 for perm in itertools.permutations(x):664 facets.append([num[tuple(sorted(perm[:k]))] for k in range(1, len(perm) + 1)])665 return Cx(facets), num666 667 668def cone(K, apex=None):669 top = max(v for x in K.S[0] for v in x) + 1 if apex is None else apex670 return Cx([list(x) + [top] for d in K.S for x in K.S[d]]), top671 672 673def suspension(K):674 top = max(v for x in K.S[0] for v in x) + 1675 return Cx([list(x) + [top] for x in K.S[K.dim]] + [list(x) + [top + 1] for x in K.S[K.dim]] +676 [list(x) + [top] for d in K.S for x in K.S[d]] + [list(x) + [top + 1] for d in K.S for x in K.S[d]])677 678 679def facets_of(K):680 return [x for d in K.S for x in K.S[d] if not any(set(x) < set(y) for y in K.S.get(d + 1, []))]681 682 683def prism(K):684 """K x I with vertices v (bottom) and v + N (top)"""685 N = max(v for x in K.S[0] for v in x) + 1686 F = []687 for x in facets_of(K):688 for i in range(len(x)):689 F.append(list(x[:i + 1]) + [v + N for v in x[i:]])690 return Cx(F), N691 692 693def is_pseudomanifold(K, closed=True):694 d = K.dim695 cnt = {}696 for x in K.S[d]:697 for i in range(d + 1):698 f = x[:i] + x[i + 1:]699 cnt[f] = cnt.get(f, 0) + 1700 vals = set(cnt.values())701 return (vals == {2}) if closed else (vals <= {1, 2})702 703 704def torus7():705 return Cx([[i, (i + 1) % 7, (i + 3) % 7] for i in range(7)] + [[i, (i + 2) % 7, (i + 3) % 7] for i in range(7)])706 707 708def rp2():709 return Cx([[1, 2, 4], [1, 2, 6], [1, 3, 4], [1, 3, 5], [1, 5, 6], [2, 3, 5], [2, 3, 6], [2, 4, 5], [3, 4, 6], [4, 5, 6]])710 711 712def klein():713 def v(i, j):714 if i == 4:715 i, j = 0, (-j) % 4716 return 4 * i + (j % 4)717 F = []718 for i in range(4):719 for j in range(4):720 F.append([v(i, j), v(i + 1, j), v(i + 1, j + 1)])