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

1101def sperner_fixed(n):1102    def pt(i, j):1103        return ((n - i - j) / n, i / n, j / n)1104    def lab(i, j):1105        p = pt(i, j)1106        q = fmap(p)1107        for k in range(3):1108            if p[k] > 0 and q[k] <= p[k]:1109                return k1110        return max(range(3), key=lambda k: p[k])1111    best = None1112    for t in sperner_grid(n):1113        if sorted(lab(*v) for v in t) == [0, 1, 2]:1114            c = tuple(sum(pt(*v)[k] for v in t) / 3 for k in range(3))1115            e = max(abs(a - b) for a, b in zip(c, fmap(c)))1116            best = e if best is None else min(best, e)1117    return best1118 1119 1120errs = [sperner_fixed(n) for n in (8, 32, 128)]1121check('S4 Brouwer from Sperner: a complete cell of mesh 1/n contains a point moved by O(1/n)', errs[0] > errs[1] > errs[2] and errs[2] < 0.01,1122      'displacement at the centre of a complete cell: %s for n = 8, 32, 128' % ', '.join('%.4f' % e for e in errs))1123 1124 1125def hex_winner(n):1126    col = [[random.random() < 0.5 for _ in range(n)] for _ in range(n)]1127    nb = [(1, 0), (-1, 0), (0, 1), (0, -1), (1, -1), (-1, 1)]1128    def connects(c, vertical):1129        seen = set()1130        stack = [(0, j) for j in range(n) if col[0][j] == c] if vertical else [(i, 0) for i in range(n) if col[i][0] == c]1131        while stack:1132            i, j = stack.pop()1133            if (i, j) in seen:1134                continue1135            seen.add((i, j))1136            if (vertical and i == n - 1) or (not vertical and j == n - 1):1137                return True1138            for a, b in nb:1139                u, v = i + a, j + b1140                if 0 <= u < n and 0 <= v < n and col[u][v] == c and (u, v) not in seen:1141                    stack.append((u, v))1142        return False1143    return connects(True, True), connects(False, False)1144 1145 1146hx = [hex_winner(9) for _ in range(300)]1147check('S5 the Hex theorem (equivalent to Brouwer in the plane): a filled board has exactly one winner', all(a != b for a, b in hx),1148      '300 random fillings of the 9 x 9 board; first player wins %d' % sum(a for a, _ in hx))1149 1150 1151def order_of_cover(kind, n=6):1152    """largest number of closed tiles meeting at a point, for a tiling of the plane by unit squares"""1153    best = 01154    for i in range(2 * n):1155        for j in range(2 * n):1156            p = (i / 2, j / 2)1157            cnt = 01158            for a in range(-1, n + 1):1159                for b in range(-1, n + 1):1160                    off = 0.5 * (b % 2) if kind == 'brick' else 0.01161                    if a + off <= p[0] <= a + off + 1 and b <= p[1] <= b + 1:1162                        cnt += 11163            best = max(best, cnt)1164    return best1165 1166 1167check('S6 Lebesgue: a cover of the plane by small closed sets has order at least 3; the brick pattern attains 3, the square grid has 4',1168      order_of_cover('brick') == 3 and order_of_cover('grid') == 4, 'orders %d and %d' % (order_of_cover('brick'), order_of_cover('grid')))1169 1170sec('5. Homotopy and the cylinder')1171okpr = True1172for nm, K in NAMED[1:5]:1173    PK, N = prism(K)1174    for d in range(0, K.dim + 1):1175        P = [[0] * K.n(d) for _ in range(PK.n(d + 1))]1176        for j, x in enumerate(K.S[d]):1177            for i in range(d + 1):1178                P[PK.idx[d + 1][x[:i + 1] + tuple(v + N for v in x[i:])]][j] = (-1) ** i1179        i0 = chain_map(K, PK, {x[0]: x[0] for x in K.S[0]}, d)1180        i1 = chain_map(K, PK, {x[0]: x[0] + N for x in K.S[0]}, d)1181        lhs = mat_mul(PK.bd(d + 1), P)1182        if d > 0:1183            Pm = [[0] * K.n(d - 1) for _ in range(PK.n(d))]1184            for j, x in enumerate(K.S[d - 1]):1185                for i in range(d):1186                    Pm[PK.idx[d][x[:i + 1] + tuple(v + N for v in x[i:])]][j] = (-1) ** i1187            lhs = [[a + b for a, b in zip(r, q)] for r, q in zip(lhs, mat_mul(Pm, K.bd(d)))]1188        okpr = okpr and mat_eq(lhs, mat_sub(i1, i0))1189check('P1 the cylindric construction: the prism operator P satisfies dP + Pd = top - bottom', okpr, 'icosahedron, torus, projective plane, Klein bottle')1190 1191PR, _ = prism(RP2)1192PM, _ = prism(MB)1193check('P2 the cylinder on a complex has the homology of the complex, torsion included', homology(PR)[:3] == homology(RP2) and homology(PR)[3] == (0, []) and bettis(PM) == [1, 1, 0, 0],1194      'projective plane times interval: %s' % homology(PR))1195 1196 1197def choice_map(K, num):1198    inv_ = {i: x for x, i in num.items()}1199    return {i: random.choice(inv_[i]) for i in inv_}1200