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

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]]881            a = par[a]882        return a883    for e in K.S.get(1, []):884        par[find(e[0])] = find(e[1])885    return len({find(a) for a in par})886 887 888okh0 = all(bettis(K)[0] == components(K) for K in [rand_complex(10, 5, 2) for _ in range(30)])889check('H5 the zero-dimensional Betti number is the number of components', okh0, '30 random complexes')890 891okcone = True892for _, K in NAMED:893    CK, _ = cone(K)894    okcone = okcone and homology(CK) == [(1, [])] + [(0, [])] * CK.dim895ST = suspension(T7)896SR = suspension(RP2)897check('H6 a cone is acyclic and suspension shifts homology by one: the suspension of the projective plane has H_2 = Z/2',898      okcone and bettis(ST) == [1, 0, 2, 1] and homology(SR) == [(1, []), (0, []), (0, [2]), (0, [])], 'suspended torus %s' % bettis(ST))899 900okmv = True901for _ in range(30):902    fa = [random.sample(range(8), random.randint(1, 4)) for _ in range(5)]903    fb = [random.sample(range(8), random.randint(1, 4)) for _ in range(5)]904    A, B, U = Cx(fa), Cx(fb), Cx(fa + fb)905    inter = [x for d in A.S for x in A.S[d] if d in B.S and x in B.idx[d]]906    okmv = okmv and U.chi() == A.chi() + B.chi() - (Cx(inter).chi() if inter else 0)907check('H7 the Euler characteristic is additive: chi(A u B) = chi(A) + chi(B) - chi(A n B)', okmv, '30 random pairs')908 909G2, G3 = grid_torus(3, 2), grid_torus(4, 3)910bg3 = [betti_mod(G3, p) for p in (2, 3, BIGP)]911check('H8 Kunneth on product triangulations: the 2-torus has Betti numbers (1,2,1) and the 3-torus (1,3,3,1), over every field tried',912      is_pseudomanifold(G2) and is_pseudomanifold(G3) and bettis(G2) == [1, 2, 1] and all(b == [1, 3, 3, 1] for b in bg3),913      '3-torus on %d vertices with f-vector %s' % (G3.n(0), G3.fvec()))914 915sec('3. Invariance: subdivision, cones, approximation')916oksd = True917for nm, K in NAMED[2:5]:918    SK, _ = sd(K)919    oksd = oksd and homology(SK) == homology(K)920SRP, numrp = sd(RP2)921check('I1 barycentric subdivision does not change the homology groups, torsion included', oksd, 'subdivided projective plane: f-vector %s, homology %s' % (SRP.fvec(), homology(SRP)))922 923 924def last_vertex_map(K, num):925    inv_ = {i: x for x, i in num.items()}926    return {i: max(inv_[i]) for i in inv_}927 928 929okapp = True930for nm, K in NAMED[2:5]:931    SK, num = sd(K)932    vm = last_vertex_map(K, num)933    for d in range(1, K.dim + 1):934        okapp = okapp and mat_eq(mat_mul(K.bd(d), chain_map(SK, K, vm, d)), mat_mul(chain_map(SK, K, vm, d - 1), SK.bd(d)))935    # rank of the induced map on top homology mod 2 equals the Betti number936    d = K.dim937    Zs = nullspace(SK.bd(d), SK.n(d))938    img = [[sum(chain_map(SK, K, vm, d)[i][k] * z[k] for k in range(SK.n(d))) for i in range(K.n(d))] for z in Zs]939    okapp = okapp and (len(independent_extend([], img)) == bettis(K)[d])940check('I2 the last-vertex map from the subdivision back to the complex is a simplicial approximation of the identity: a chain map, onto in top homology',941      okapp, 'torus, projective plane, Klein bottle')942 943okcc = True944for nm, K in NAMED[:4]:945    CK, apex = cone(K)946    for d in range(0, CK.dim):947        n = CK.n(d)948        D = [[0] * n for _ in range(CK.n(d + 1))]949        for j, x in enumerate(CK.S[d]):950            if apex not in x:951                D[CK.idx[d + 1][x + (apex,)]][j] = (-1) ** (d + 1)952        lhs = mat_mul(CK.bd(d + 1), D)953        if d > 0:954            Dm = [[0] * CK.n(d - 1) for _ in range(n)]955            for j, x in enumerate(CK.S[d - 1]):956                if apex not in x:957                    Dm[CK.idx[d][x + (apex,)]][j] = (-1) ** d958            lhs = [[a + b for a, b in zip(r, q)] for r, q in zip(lhs, mat_mul(Dm, CK.bd(d)))]959            okcc = okcc and mat_eq(lhs, [[int(i == j) for j in range(n)] for i in range(n)])960        else: