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

601    """coordinates of v in the independent family cols (exact)"""602    n = len(cols)603    m = len(v)604    A = [[Fr(cols[j][i]) for j in range(n)] + [Fr(v[i])] for i in range(m)]605    rk = 0606    piv = []607    for c in range(n):608        p = next((i for i in range(rk, m) if A[i][c] != 0), None)609        if p is None:610            return None611        A[rk], A[p] = A[p], A[rk]612        A[rk] = [x / A[rk][c] for x in A[rk]]613        for i in range(m):614            if i != rk and A[i][c] != 0:615                f = A[i][c]616                A[i] = [x - f * y for x, y in zip(A[i], A[rk])]617        piv.append(c)618        rk += 1619    if any(A[i][n] != 0 for i in range(rk, m)):620        return None621    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())