Indexed text attachment
verify-topology.py
Source for Algebraic and Differential Topology in Higher Categories
View paper · Download original file
Lines 1441–1540 of 1961. Source text is displayed literally.
1441 1442grid = [Fr(i, 4) for i in range(-8, 9)]1443sing = [(x, y) for x in grid for y in grid if umbrella_rank(x, y) < 2]1444dbl = all((0, 0 * y, y * y) == (0, 0 * (-y), (-y) * (-y)) for y in grid)1445check('M3 the Whitney umbrella (x, xy, y^2) fails to be an immersion only at the origin and identifies (0,y) with (0,-y)', sing == [(Fr(0), Fr(0))] and dbl,1446 'rank 2 at the other %d grid points' % (len(grid) ** 2 - 1))1447 1448 1449def height(th, ph, R=2.0, r=1.0):1450 return (R + r * math.cos(th)) * math.cos(ph)1451 1452 1453idx = []1454for th in (0.0, PI):1455 for ph in (0.0, PI):1456 hxx = d2(lambda t: height(t, ph), th)1457 hyy = d2(lambda p: height(th, p), ph)1458 hxy = (height(th + 1e-4, ph + 1e-4) - height(th + 1e-4, ph - 1e-4) - height(th - 1e-4, ph + 1e-4) + height(th - 1e-4, ph - 1e-4)) / 4e-81459 g = max(abs(d1(lambda t: height(t, ph), th)), abs(d1(lambda p: height(th, p), ph)))1460 det = hxx * hyy - hxy * hxy1461 idx.append((g < 1e-6, 0 if (det > 0 and hxx > 0) else 2 if (det > 0) else 1))1462ind = sorted(i for _, i in idx)1463check('M4 the height function on an upright torus has four non-degenerate critical points of index 0, 1, 1, 2; the alternating count is the Euler characteristic 0',1464 all(g for g, _ in idx) and ind == [0, 1, 1, 2], 'indices %s' % ind)1465 1466 1467def poly_roots(co):1468 """roots of a complex polynomial (Durand-Kerner); co[0] is the leading coefficient"""1469 n = len(co) - 11470 co = [c / co[0] for c in co]1471 z = [(0.4 + 0.9j) ** k for k in range(n)]1472 for _ in range(400):1473 new = []1474 for i in range(n):1475 num = sum(co[k] * z[i] ** (n - k) for k in range(n + 1))1476 den = 11477 for j in range(n):1478 if j != i:1479 den *= z[i] - z[j]1480 new.append(z[i] - num / den)1481 z = new1482 return z1483 1484 1485def rational_preimages(w):1486 # f(z) = (z^3 + (1+2i) z + 0.5) / (0.7 z^2 - 1i): solve p - w q = 01487 return poly_roots([1, -0.7 * w, 1 + 2j, 0.5 + 1j * w])1488 1489 1490cnts = []1491for w in (0.3 + 0.2j, -1.1 + 0.7j, 2.0 - 1.5j):1492 rts = rational_preimages(w)1493 f = lambda z: (z ** 3 + (1 + 2j) * z + 0.5) / (0.7 * z * z - 1j)1494 cnts.append(sum(1 for z in rts if abs(f(z) - w) < 1e-8))1495# antiholomorphic example: z -> conj(z)^2 has two preimages of each value, each with Jacobian determinant -4|z|^2 < 01496check('M5 the degree counted over a regular value does not depend on the value: a rational map of degree 3 has 3 preimages; conj(z)^2 has two, each of sign -1',1497 cnts == [3, 3, 3], 'preimage counts %s; degree of conj(z)^2 is -2' % cnts)1498 1499sec('8. Framed manifolds and the main method')1500 1501 1502def circle_degree(F, dF, value, n=4000):1503 """signed number of preimages of an angle under a map of the circle given by a lift F"""1504 tot = 01505 winding = round((F(2 * PI) - F(0)) / (2 * PI))1506 for k in range(-abs(winding) - 2, abs(winding) + 3):1507 target = value + 2 * PI * k1508 prev = F(0) - target1509 for i in range(1, n + 1):1510 t = 2 * PI * i / n1511 cur = F(t) - target1512 if prev * cur < 0 or prev == 0:1513 tot += 1 if cur > prev else -11514 prev = cur1515 return tot, winding1516 1517 1518okdeg = True1519for a in (-2, -1, 0, 1, 2, 3):1520 F = lambda t: a * t + 1.3 * math.sin(2 * t) + 0.4 * math.cos(3 * t)1521 s, w = circle_degree(F, None, 0.7)1522 okdeg = okdeg and s == a == w1523check('F1 framed points: the signed number of preimages of a regular value of a circle map is its degree, also when the map folds back', okdeg, 'degrees -2..3 with a non-monotone lift')1524 1525 1526def sphere_degree(F, n=160):1527 """degree of a map of the 2-sphere by integrating the pulled-back area form"""1528 tot = 0.01529 hu, hv = PI / n, 2 * PI / n1530 def X(u, v):1531 return F([math.sin(u) * math.cos(v), math.sin(u) * math.sin(v), math.cos(u)])1532 for i in range(n):1533 for j in range(n):1534 u, v = (i + 0.5) * hu, (j + 0.5) * hv1535 a = X(u, v)1536 du = [(p - q) / (2e-5) for p, q in zip(X(u + 1e-5, v), X(u - 1e-5, v))]1537 dv = [(p - q) / (2e-5) for p, q in zip(X(u, v + 1e-5), X(u, v - 1e-5))]1538 tot += dot(a, cross(du, dv)) * hu * hv1539 return tot / (4 * PI)1540