Indexed text attachment
verify-topology.py
Source for Algebraic and Differential Topology in Higher Categories
View paper · Download original file
Lines 1001–1100 of 1961. Source text is displayed literally.
1001fail = simplicial_degree(3, 8)1002check('I5 a simplicial approximation of z -> z^d from a 60-gon to a triangle has degree d; on an octagon the same vertex rule gives degree 2 for d = 3',1003 all(degs[d] == d for d in degs) and fail == 2, 'degrees %s; octagon, d = 3: degree %s' % (degs, fail))1004 1005sec('4. Sperner, Brouwer, dimension')1006 1007 1008def sperner_grid(n):1009 """triangular grid of side n: vertices (i,j), i+j<=n; returns list of (triangle, orientation)"""1010 tris = []1011 for i in range(n):1012 for j in range(n - i):1013 tris.append(((i, j), (i + 1, j), (i, j + 1)))1014 if i + j < n - 1:1015 tris.append(((i + 1, j), (i + 1, j + 1), (i, j + 1)))1016 return tris1017 1018 1019def sperner_label(n):1020 lab = {}1021 for i in range(n + 1):1022 for j in range(n + 1 - i):1023 k = n - i - j1024 allowed = [c for c, v in ((0, k), (1, i), (2, j)) if v > 0]1025 lab[(i, j)] = random.choice(allowed)1026 return lab1027 1028 1029def signed_rainbow(tris, lab):1030 tot = cnt = 01031 for t in tris:1032 l = [lab[v] for v in t]1033 if sorted(l) == [0, 1, 2]:1034 cnt += 11035 tot += perm_sign(l)1036 return cnt, tot1037 1038 1039okS = True1040counts = []1041for _ in range(200):1042 n = 121043 lab = sperner_label(n)1044 c, s = signed_rainbow(sperner_grid(n), lab)1045 counts.append(c)1046 okS = okS and c % 2 == 1 and s == 11047check('S1 Sperner: every admissible labelling of a subdivided triangle has an odd number of complete cells, and their signed count is +1',1048 okS, '200 random labellings of the grid of side 12: between %d and %d complete cells' % (min(counts), max(counts)))1049 1050okE = True1051for _ in range(200):1052 n = 121053 lab = sperner_label(n)1054 e = sum((1 if (lab[(i, 0)], lab[(i + 1, 0)]) == (0, 1) else -1 if (lab[(i, 0)], lab[(i + 1, 0)]) == (1, 0) else 0) for i in range(n))1055 okE = okE and e == 11056check('S2 the signed count is the degree of the labelling on the boundary: on the side labelled 0 and 1 the signed number of 01-edges is +1', okE, '200 labellings')1057 1058 1059def sperner3(m):1060 """m-fold barycentric subdivision of a tetrahedron with coordinates; random Sperner labels"""1061 tets = [[tuple(Fr(int(i == k)) for k in range(4)) for i in range(4)]]1062 for _ in range(m):1063 new = []1064 for t in tets:1065 for perm in itertools.permutations(t):1066 new.append([tuple(sum(p[k] for p in perm[:j]) / j for k in range(4)) for j in (1, 2, 3, 4)])1067 tets = new1068 lab = {}1069 for t in tets:1070 for v in t:1071 if v not in lab:1072 lab[v] = random.choice([k for k in range(4) if v[k] > 0])1073 cnt = tot = 01074 for t in tets:1075 l = [lab[v] for v in t]1076 if sorted(l) == [0, 1, 2, 3]:1077 M = [[Fr(1)] + list(v[:3]) for v in t]1078 # orientation of the cell times the sign of the labelling1079 rows = [[a - b for a, b in zip(v[:3], t[0][:3])] for v in t[1:]]1080 det = (rows[0][0] * (rows[1][1] * rows[2][2] - rows[1][2] * rows[2][1]) - rows[0][1] * (rows[1][0] * rows[2][2] - rows[1][2] * rows[2][0])1081 + rows[0][2] * (rows[1][0] * rows[2][1] - rows[1][1] * rows[2][0]))1082 cnt += 11083 tot += (1 if det > 0 else -1) * perm_sign(l)1084 return cnt, tot, len(tets)1085 1086 1087r3 = [sperner3(2) for _ in range(20)]1088ref = r3[0][1]1089check('S3 Sperner in dimension three: an odd number of complete cells, with signed count of absolute value one',1090 all(c % 2 == 1 and abs(s) == 1 and s == ref for c, s, _ in r3), '20 labellings of the second subdivision of a tetrahedron (%d cells): %d to %d complete cells' % (r3[0][2], min(c for c, _, _ in r3), max(c for c, _, _ in r3)))1091 1092 1093def fmap(p):1094 """a continuous self-map of the standard triangle (barycentric coordinates)"""1095 x, y, z = p1096 q = (0.2 + 0.5 * y + 0.3 * z * z, 0.1 + 0.6 * z + 0.2 * x * y, 0.3 + 0.4 * x + 0.1 * y * y)1097 s = sum(q)1098 return tuple(a / s for a in q)1099 1100