Indexed text attachment
verify-topology.py
Source for Algebraic and Differential Topology in Higher Categories
View paper · Download original file
Lines 981–1080 of 1961. Source text is displayed literally.
981 all(r <= 2 / 3 + 1e-12 for r in ratios) and [m[1] for m in meshes] == [1, 6, 36, 216, 1296],982 'mesh %s; ratios %s' % (', '.join('%.4f' % m[0] for m in meshes), ', '.join('%.4f' % r for r in ratios)))983 984 985def simplicial_degree(d, N):986 """degree of the simplicial approximation of z -> z^d from an N-gon to a triangle"""987 def img(j):988 ang = (d * 2 * PI * j / N) % (2 * PI)989 return int(ang // (2 * PI / 3)) % 3990 tot = 0991 for j in range(N):992 a, b = img(j), img((j + 1) % N)993 if (a, b) == (2, 0):994 tot += 1995 elif (a, b) == (0, 2):996 tot -= 1997 return tot998 999 1000degs = {d: simplicial_degree(d, 60) for d in (-2, -1, 0, 1, 2, 3)}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])