Independent scholarship · Open accessThe monthly digest

Indexed text attachment

verify-topology.py

Source for Algebraic and Differential Topology in Higher Categories

View paper · Download original file

Lines 661–760 of 1961. Source text is displayed literally.

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)])721            F.append([v(i, j), v(i, j + 1), v(i + 1, j + 1)])722    return Cx(F)723 724 725def moebius():726    return Cx([[i, (i + 1) % 5, (i + 2) % 5] for i in range(5)])727 728 729def simplex_boundary(n):730    return Cx([c for c in itertools.combinations(range(n + 2), n + 1)])731 732 733def cross_sphere(n):734    """boundary of the (n+1)-dimensional cross-polytope; vertex 2i is +e_i, 2i+1 is -e_i"""735    return Cx([[2 * i + s for i, s in enumerate(signs)] for signs in itertools.product((0, 1), repeat=n + 1)])736 737 738def icosahedron():739    T, B = 0, 11740    u = lambda i: 1 + i % 5741    l = lambda i: 6 + i % 5742    F = []743    for i in range(5):744        F += [[T, u(i), u(i + 1)], [u(i), u(i + 1), l(i)], [u(i + 1), l(i), l(i + 1)], [B, l(i), l(i + 1)]]745    return Cx(F)746 747 748def grid_torus(m, d):749    """Freudenthal triangulation of (Z/m)^d"""750    def num(v):751        r = 0752        for a in v:753            r = r * m + a % m754        return r755    F = []756    for v in itertools.product(range(m), repeat=d):757        for perm in itertools.permutations(range(d)):758            w = list(v)759            s = [num(w)]760            for k in perm: