Indexed text attachment
verify-pde.py
Source for Partial Differential Equations in Higher Categories
View paper · Download original file
Lines 1380–1479 of 1640. Source text is displayed literally.
1380 Fc = [(v, d) for v in V for d in range(3)] # face at v normal to direction d1381 fi = {f_: a for a, f_ in enumerate(Fc)}1382 d0_ = [[0] * len(V) for _ in E]1383 for (v, d), a in ei.items():1384 d0_[a][vi[sh(v, d)]] += 11385 d0_[a][vi[v]] -= 11386 d1_ = [[0] * len(E) for _ in Fc]1387 for (v, d), a in fi.items():1388 p, q = (d + 1) % 3, (d + 2) % 31389 d1_[a][ei[(v, p)]] += 11390 d1_[a][ei[(sh(v, p), q)]] += 11391 d1_[a][ei[(sh(v, q), p)]] -= 11392 d1_[a][ei[(v, q)]] -= 11393 d2_ = [[0] * len(Fc) for _ in V]1394 for v, a in vi.items():1395 for d in range(3):1396 d2_[a][fi[(sh(v, d), d)]] += 11397 d2_[a][fi[(v, d)]] -= 11398 return d0_, d1_, d2_1399 1400 1401def zero_prod(A, B):1402 Bt = list(zip(*B))1403 return all(sum(a * b for a, b in zip(r, c_)) == 0 for r in A for c_ in Bt)1404 1405 1406e0, e1, e2 = torus_complex(3)1407t0, t1, t2 = torus_complex(2)1408rk = (rank_exact(t0), rank_exact(t1), rank_exact(t2))1409bt = (8 - rk[0], 24 - rk[0] - rk[1], 24 - rk[1] - rk[2], 8 - rk[2])1410Apot = [random.randint(-3, 3) for _ in range(81)]1411chi = [random.randint(-3, 3) for _ in range(27)]1412F1 = [sum(a * b for a, b in zip(r, Apot)) for r in e1]1413F2 = [sum(a * b for a, b in zip(r, [x + sum(p * q for p, q in zip(rr, chi)) for x, rr in zip(Apot, e0)])) for r in e1]1414check('P1 on a cubical 3-torus curl grad = 0 and div curl = 0 exactly; the field strength dA is unchanged by a gauge transformation;'1415 ' the Betti numbers are (1, 3, 3, 1), so there are closed potentials that are not gradients', zero_prod(e1, e0) and zero_prod(e2, e1) and F1 == F2 and bt == (1, 3, 3, 1))1416cl = 2.01417fw = lambda s: math.exp(-s * s) * math.sin(2 * s)1418Ey = lambda x, t: fw(x - cl * t)1419Bz = lambda x, t: fw(x - cl * t)1420mres = max(abs(d1(lambda t: Ey(0.3, t), 0.2) - cl * (-d1(lambda x: Bz(x, 0.2), 0.3))), abs(d1(lambda t: Bz(0.3, t), 0.2) + cl * d1(lambda x: Ey(x, 0.2), 0.3)))1421check('P2 Maxwell\'s equations in the source\'s form: the transverse plane wave E = (0, f(x - ct), 0), B = (0, 0, f(x - ct)) solves them', mres < 1e-8)1422gam, rho0 = 1.4, 1.21423cs = math.sqrt(gam * rho0 ** (gam - 1))1424trA, detA = 0.0, -(gam * rho0 ** (gam - 1))1425eigs = sorted([(trA - math.sqrt(trA * trA - 4 * detA)) / 2, (trA + math.sqrt(trA * trA - 4 * detA)) / 2])1426check('P3 acoustics is the tangent of fluid dynamics: the linearization of the one-dimensional Euler equations at rest has characteristic speeds'1427 ' plus and minus the sound speed', abs(eigs[0] + cs) < 1e-12 and abs(eigs[1] - cs) < 1e-12, 'sound speed %.5f' % cs)1428c1, c2 = 1.0, 3.01429Rr, Tt = (c2 - c1) / (c2 + c1), 2 * c2 / (c2 + c1)1430fin = lambda s: math.exp(-(s + 4) ** 2)1431uL = lambda x, t: fin(x - c1 * t) + Rr * fin(-x - c1 * t)1432uR = lambda x, t: Tt * fin((c1 / c2) * (x - c2 * t))1433jump = max(abs(uL(0.0, t) - uR(0.0, t)) + abs(d1(lambda x: uL(x, t), 0.0) - d1(lambda x: uR(x, t), 0.0)) for t in (3.0, 4.0, 4.6))1434check('P4 scattering on a string of two materials: reflection (c2-c1)/(c2+c1), transmission 2c2/(c2+c1); the solution and its slope are continuous,'1435 ' and the energy flux balances', jump < 1e-9 and abs(Rr ** 2 + (c1 / c2) * Tt ** 2 - 1) < 1e-15)1436 1437 1438def prop(k, V, w):1439 """transfer matrix of -psi'' + V psi = k^2 psi across a segment of constant potential, in the basis (psi, psi')"""1440 q2 = k * k - V1441 if abs(q2) < 1e-14:1442 return [[1.0, w], [0.0, 1.0]]1443 q = cmath.sqrt(q2)1444 return [[cmath.cos(q * w), cmath.sin(q * w) / q], [-q * cmath.sin(q * w), cmath.cos(q * w)]]1445 1446 1447def mm2(A, B):1448 return [[A[0][0] * B[0][0] + A[0][1] * B[1][0], A[0][0] * B[0][1] + A[0][1] * B[1][1]], [A[1][0] * B[0][0] + A[1][1] * B[1][0], A[1][0] * B[0][1] + A[1][1] * B[1][1]]]1449 1450 1451def RT(Pm, k):1452 # P (1 + R, ik(1 - R)) = (T, ikT)1453 a = [[Pm[0][0] - 1j * k * Pm[0][1], -1.0], [Pm[1][0] - 1j * k * Pm[1][1], -1j * k]]1454 b = [-(Pm[0][0] + 1j * k * Pm[0][1]), -(Pm[1][0] + 1j * k * Pm[1][1])]1455 det_ = a[0][0] * a[1][1] - a[0][1] * a[1][0]1456 return (b[0] * a[1][1] - a[0][1] * b[1]) / det_, (a[0][0] * b[1] - b[0] * a[1][0]) / det_1457 1458 1459segs = [(2.0, 0.7), (0.0, 0.5), (-1.5, 0.9), (3.0, 0.4)]1460oku, okd, okf = True, True, True1461for k in (0.6, 1.3, 2.4):1462 Pm = [[1.0, 0.0], [0.0, 1.0]]1463 for V, w in segs:1464 Pm = mm2(prop(k, V, w), Pm)1465 R_, T_ = RT(Pm, k)1466 oku = oku and abs(abs(R_) ** 2 + abs(T_) ** 2 - 1) < 1e-121467 okd = okd and abs(Pm[0][0] * Pm[1][1] - Pm[0][1] * Pm[1][0] - 1) < 1e-121468 # the same matrix by integrating the equation across the whole potential1469 cols = []1470 for y0 in ([1.0, 0.0], [0.0, 1.0]):1471 y, x = list(y0), 0.01472 for V, w in segs:1473 hstep = w / 4001474 for _ in range(400):1475 y = rk4(lambda yy, V=V: [yy[1], (V - k * k) * yy[0]], y, hstep)1476 cols.append(y)1477 okf = okf and max(abs(cols[j][i] - Pm[i][j]) for i in range(2) for j in range(2)) < 1e-81478check('P5 scattering by a potential: transfer matrices compose under concatenation (a functor to SL(2)), and the resulting reflection and transmission'1479 ' coefficients satisfy |R|^2 + |T|^2 = 1, the source\'s theorem', oku and okd and okf)