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

1641 1642def framed_pushoff(t, eps=0.25):1643    return lambda s: [(1 + eps * math.cos(t * s)) * math.cos(s), (1 + eps * math.cos(t * s)) * math.sin(s), eps * math.sin(t * s)]1644 1645 1646sl = [gauss_link(cA, framed_pushoff(t)) for t in (0, 1, 2, -3)]1647check('K4 a framing of a circle in space is an integer: the linking number of the circle with its push-off along the frame that turns t times is t',1648      all(close(abs(v), abs(t), 1e-3) for v, t in zip(sl, (0, 1, 2, -3))) and sl[1] * sl[3] < 0, 'linking %s' % ', '.join('%.6f' % v for v in sl))1649 1650 1651def hopf(x):1652    z1, z2 = complex(x[0], x[1]), complex(x[2], x[3])1653    w = 2 * z1 * z2.conjugate()1654    return [w.real, w.imag, abs(z1) ** 2 - abs(z2) ** 2]1655 1656 1657okh = True1658for _ in range(50):1659    x = [random.gauss(0, 1) for _ in range(4)]1660    n = vnorm(x)1661    x = [a / n for a in x]1662    y = hopf(x)1663    th = random.uniform(0, 2 * PI)1664    e = cmath.exp(1j * th)1665    z1, z2 = complex(x[0], x[1]) * e, complex(x[2], x[3]) * e1666    y2 = hopf([z1.real, z1.imag, z2.real, z2.imag])1667    J = [[(hopf([x[k] + (1e-6 if k == j else 0) for k in range(4)])[i] - hopf([x[k] - (1e-6 if k == j else 0) for k in range(4)])[i]) / 2e-6 for j in range(4)] for i in range(3)]1668    # rank of the differential restricted to the tangent space: Gram matrix has rank 2 on the sphere1669    G = [[sum(J[i][k] * J[j][k] for k in range(4)) for j in range(3)] for i in range(3)]1670    ev, _ = jacobi_eig(G)1671    okh = okh and close(vnorm(y), 1, 1e-9) and vnorm(vsub(y, y2)) < 1e-9 and ev[1] > 1.01672check('K5 the Hopf map takes the 3-sphere onto the 2-sphere, is constant on the circles e^{it}(z1,z2), and is a submersion', okh, '50 random points')1673 1674sec('10. Rotations and the first stem')1675 1676 1677def qmul(a, b):1678    return (a[0] * b[0] - a[1] * b[1] - a[2] * b[2] - a[3] * b[3], a[0] * b[1] + a[1] * b[0] + a[2] * b[3] - a[3] * b[2],1679            a[0] * b[2] - a[1] * b[3] + a[2] * b[0] + a[3] * b[1], a[0] * b[3] + a[1] * b[2] - a[2] * b[1] + a[3] * b[0])1680 1681 1682def qconj(a):1683    return (a[0], -a[1], -a[2], -a[3])1684 1685 1686def qn2(a):1687    return sum(x * x for x in a)1688 1689 1690def qrot(q):1691    """matrix of v -> q v q^{-1} on the imaginary quaternions"""1692    n = qn2(q)1693    cols = []1694    for k in range(3):1695        v = tuple([0] + [1 if i == k else 0 for i in range(3)])1696        w = qmul(qmul(q, v), qconj(q))1697        cols.append([w[1] / n, w[2] / n, w[3] / n])1698    return [[cols[j][i] for j in range(3)] for i in range(3)]1699 1700 1701def rq():1702    return tuple(Fr(random.randint(-5, 5), random.randint(1, 4)) for _ in range(4))1703 1704 1705okq = True1706for _ in range(100):1707    a, b, c = rq(), rq(), rq()1708    okq = okq and qmul(qmul(a, b), c) == qmul(a, qmul(b, c)) and qn2(qmul(a, b)) == qn2(a) * qn2(b)1709check('R1 the quaternions are associative and their norm is multiplicative', okq, '100 random rational triples, exactly')1710 1711okr = True1712for _ in range(60):1713    a, b = rq(), rq()1714    if qn2(a) == 0 or qn2(b) == 0:1715        continue1716    A, B, AB = qrot(a), qrot(b), qrot(qmul(a, b))1717    I3 = [[Fr(int(i == j)) for j in range(3)] for i in range(3)]1718    det = (A[0][0] * (A[1][1] * A[2][2] - A[1][2] * A[2][1]) - A[0][1] * (A[1][0] * A[2][2] - A[1][2] * A[2][0]) + A[0][2] * (A[1][0] * A[2][1] - A[1][1] * A[2][0]))1719    okr = okr and mat_mul([list(r) for r in zip(*A)], A) == I3 and det == 1 and mat_mul(A, B) == AB and qrot(tuple(-x for x in a)) == A1720    okr = okr and ((A == I3) == (a[1] == a[2] == a[3] == 0))1721check('R2 q -> (v -> q v q^-1) is a homomorphism onto rotations with kernel the real quaternions: the 3-sphere covers SO(3) twice', okr, '60 random rational pairs, exactly')1722 1723 1724def mat_to_quat(R):1725    t = R[0][0] + R[1][1] + R[2][2]1726    cands = [(1 + t, R[2][1] - R[1][2], R[0][2] - R[2][0], R[1][0] - R[0][1]),1727             (R[2][1] - R[1][2], 1 + R[0][0] - R[1][1] - R[2][2], R[0][1] + R[1][0], R[0][2] + R[2][0]),1728             (R[0][2] - R[2][0], R[0][1] + R[1][0], 1 - R[0][0] + R[1][1] - R[2][2], R[1][2] + R[2][1]),1729             (R[1][0] - R[0][1], R[0][2] + R[2][0], R[1][2] + R[2][1], 1 - R[0][0] - R[1][1] + R[2][2])]1730    q = max(cands, key=lambda c: sum(x * x for x in c))1731    n = math.sqrt(sum(x * x for x in q))1732    return [x / n for x in q]1733 1734 1735def axis_rot(u, th):1736    n = vnorm(u)1737    q = (math.cos(th / 2),) + tuple(math.sin(th / 2) * x / n for x in u)1738    return [[float(v) for v in r] for r in qrot(q)]1739 1740