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 781–880 of 1961. Source text is displayed literally.

781    return Cx([random.sample(range(nv), random.randint(1, dmax + 1)) for _ in range(nf)])782 783 784sec('1. Complexes as presheaves')785fv = {nm: K.fvec() for nm, K in NAMED}786okpm = all(is_pseudomanifold(K, closed=(nm != 'Moebius band')) for nm, K in NAMED)787check('C1 the six model complexes are pseudo-manifolds with f-vectors (4,6,4), (12,30,20), (7,21,14), (6,15,10), (16,48,32), (5,10,5)',788      okpm and fv['sphere'] == [4, 6, 4] and fv['icosahedron'] == [12, 30, 20] and fv['torus'] == [7, 21, 14] and fv['projective plane'] == [6, 15, 10]789      and fv['Klein bottle'] == [16, 48, 32] and fv['Moebius band'] == [5, 10, 5],790      'Euler characteristics %s' % ', '.join('%s %d' % (nm, K.chi()) for nm, K in NAMED))791 792 793def affinely_independent(pts):794    rows = [[Fr(a) - Fr(b) for a, b in zip(p, pts[0])] for p in pts[1:]]795    return rank_exact(rows) == len(pts) - 1796 797 798def moment(t, n):799    return [Fr(t) ** k for k in range(1, n + 1)]800 801 802okgp = all(affinely_independent([moment(t, 5) for t in c]) for c in itertools.combinations(range(1, 8), 6))803okgp3 = all(affinely_independent([moment(t, 3) for t in c]) for c in itertools.combinations(range(1, 8), 4))804check('C2 seven points on the moment curve of R^5 are in general position: every 2-complex on them is realized (dimension 2r+1)',805      okgp and okgp3, 'all 7 six-point subsets affinely independent in R^5; all 35 four-point subsets in R^3')806 807 808def nerve_of_stars(K):809    verts = [x[0] for x in K.S[0]]810    stars = {v: set(x for d in K.S for x in K.S[d] if v in x) for v in verts}811    F = []812    for k in range(1, K.dim + 3):813        for c in itertools.combinations(verts, k):814            if set.intersection(*[stars[v] for v in c]):815                F.append(c)816    return Cx(F)817 818 819oknerve = all(nerve_of_stars(K).S == K.S for _, K in NAMED)820check('C3 the nerve of the cover of a complex by its open vertex stars is the complex itself', oknerve, 'checked on the six model complexes')821 822 823def shuffles(p, q):824    """number of non-degenerate (p+q)-simplices of the product of a p-simplex and a q-simplex"""825    cnt = 0826    pts = list(itertools.product(range(p + 1), range(q + 1)))827    for c in itertools.combinations(pts, p + q + 1):828        if all(c[i][0] <= c[i + 1][0] and c[i][1] <= c[i + 1][1] for i in range(p + q)):829            cnt += 1830    return cnt831 832 833sh = [shuffles(1, 1), shuffles(2, 1), shuffles(2, 2), shuffles(3, 2)]834check('C4 the product of a p-simplex and a q-simplex has binomial(p+q,p) top simplices (the shuffles)', sh == [2, 3, 6, 10], 'counts %s' % sh)835 836nd = []837for n in (1, 2, 3, 4):838    # non-degenerate simplices of the nerve of the poset of non-empty subsets of an n-set = simplices of sd(simplex)839    K, _ = sd(Cx([list(range(n + 1))]))840    nd.append(K.n(n))841check('C5 the barycentric subdivision of an n-simplex has (n+1)! top simplices, one for each maximal flag of faces', nd == [2, 6, 24, 120], 'counts %s' % nd)842 843sec('2. Homology as a functor')844okdd = True845for _, K in NAMED + [('r', rand_complex()) for _ in range(10)]:846    for d in range(2, K.dim + 1):847        P = mat_mul(K.bd(d - 1), K.bd(d))848        okdd = okdd and all(v == 0 for r in P for v in r)849check('H1 the boundary of a boundary vanishes', okdd, 'six model complexes and ten random ones')850 851hom = {nm: homology(K) for nm, K in NAMED}852check('H2 Betti numbers and torsion by Smith normal form: sphere (1,0,1); torus (1,2,1); projective plane Z, Z/2, 0; Klein bottle Z, Z+Z/2, 0; Moebius band (1,1,0)',853      hom['sphere'] == [(1, []), (0, []), (1, [])] and hom['icosahedron'] == [(1, []), (0, []), (1, [])] and hom['torus'] == [(1, []), (2, []), (1, [])]854      and hom['projective plane'] == [(1, []), (0, [2]), (0, [])] and hom['Klein bottle'] == [(1, []), (1, [2]), (0, [])] and hom['Moebius band'] == [(1, []), (1, []), (0, [])],855      '; '.join('%s %s' % (nm, hom[nm]) for nm, _ in NAMED[2:5]))856 857okep = True858for K in [K for _, K in NAMED] + [rand_complex(8, 9, 3) for _ in range(20)]:859    okep = okep and K.chi() == sum((-1) ** d * b for d, b in enumerate(bettis(K)))860check('H3 Euler-Poincare: the alternating sum of the numbers of simplices is the alternating sum of the Betti numbers', okep, '6 model and 20 random complexes')861 862b2, b3 = betti_mod(RP2, 2), betti_mod(RP2, 3)863k2, k3 = betti_mod(KB, 2), betti_mod(KB, 3)864okuc = True865for K in [RP2, KB, T7] + [rand_complex(8, 9, 3) for _ in range(10)]:866    h = homology(K)867    for p in (2, 3):868        bp = betti_mod(K, p)869        for d in range(K.dim + 1):870            tor = sum(1 for t in h[d][1] if t % p == 0) + (sum(1 for t in h[d - 1][1] if t % p == 0) if d > 0 else 0)871            okuc = okuc and bp[d] == h[d][0] + tor872check('H4 mod-p Betti numbers see torsion: projective plane (1,1,1) mod 2 and (1,0,0) mod 3; Klein bottle (1,2,1) mod 2; universal coefficients',873      b2 == [1, 1, 1] and b3 == [1, 0, 0] and k2 == [1, 2, 1] and k3 == [1, 1, 0] and okuc, 'the Euler characteristic is 1, 1, 0, 0 in the four cases')874 875 876def components(K):877    par = {x[0]: x[0] for x in K.S[0]}878    def find(a):879        while par[a] != a:880            par[a] = par[par[a]]