Independent scholarship · Open accessThe monthly digest

Indexed text attachment

verify-pde.py

Source for Partial Differential Equations in Higher Categories

View paper · Download original file

Lines 1140–1239 of 1640. Source text is displayed literally.

1140Sg = [(0, 3), (0, 5), (1, 7)]1141A1, A2 = schreier(H1, Sg), schreier(H2, Sg)1142loops = (sorted(A1[i][i] for i in range(8)), sorted(A2[i][i] for i in range(8)))1143check('L8 Sunada\'s method in the smallest case: in the group of order 32 of affine maps of Z/8 two subgroups of order 4 meet every conjugacy class'1144      ' equally and are not conjugate; the two quotient graphs on 8 vertices have the same spectrum and are not isomorphic',1145      len(classes) == 11 and almost and not conj and charpoly_int(A1) == charpoly_int(A2) and loops[0] != loops[1], 'loops at the vertices: %s and %s' % loops)1146ev10, vec10 = jacobi_eig(lap1(10))1147comp = max(abs(sum(v[i] * v[j] for v in vec10) - (1.0 if i == j else 0.0)) for i in range(10) for j in range(10))1148check('L9 completeness in finite dimensions: the eigenvectors resolve the identity', comp < 1e-12)1149 1150sec('11. Distributions and transforms')1151phi_t = lambda x: math.exp(-x * x) * math.cos(x)                 # phi(0) = 1, phi''(0) = -31152rt = [(simpson(lambda x: heat(x, t) * phi_t(x), -12, 12, 20000) - 1) / t for t in (1e-2, 1e-3)]1153check('T1 the delta function as a limit: (S(.,t), phi) = phi(0) + t phi\'\'(0) + O(t^2)', abs(rt[0] + 3) < 0.2 and abs(rt[1] + 3) < 0.02, 'difference quotients %.4f, %.5f against -3' % tuple(rt))1154tf = lambda x: bump(x, 0.3)1155check('T2 derivatives by duality: H\' = delta and |x|\'\' = 2 delta against a test function supported in (-0.7, 1.3)',1156      abs(-simpson(lambda x: d1(tf, x), 0, 1.3, 4000) - tf(0.0)) < 1e-8 and abs(simpson(lambda x: abs(x) * d2(tf, x, 2e-3), -0.7, 0, 4000) + simpson(lambda x: abs(x) * d2(tf, x, 2e-3), 0, 1.3, 4000) - 2 * tf(0.0)) < 1e-6)1157fund = simpson(lambda r: (-1 / (4 * PI * r)) * (4 * r * r - 6) * math.exp(-r * r) * 4 * PI * r * r if r else 0.0, 0, 12, 4000)1158check('T3 the fundamental solution: the Laplacian of -1/(4 pi r) is delta in three dimensions (tested against exp(-r^2))', abs(fund - 1) < 1e-9)1159FT = lambda f, k, R=12, n=6000: simpson(lambda x: f(x) * cmath.exp(-1j * k * x), -R, R, n)1160gauss = lambda x: math.exp(-x * x / 2) / math.sqrt(2 * PI)1161f4 = lambda x: x * math.exp(-x * x) + math.exp(-(x - 1) ** 2)1162df4 = lambda x: (1 - 2 * x * x) * math.exp(-x * x) - 2 * (x - 1) * math.exp(-(x - 1) ** 2)1163pl = simpson(lambda k: abs(FT(f4, k, 10, 1000)) ** 2, -12, 12, 600) / (2 * PI) - simpson(lambda x: f4(x) ** 2, -10, 10, 2000)1164xp = {(3,): Fr(2), (1,): Fr(-1), (0,): Fr(5)}1165weyl = padd(pdiff(pmul(pvar(0, 1), xp), 0), pmul(pvar(0, 1), pdiff(xp, 0)), -1) == xp1166check('T4 the Fourier transform: Gaussians to Gaussians, differentiation to multiplication by ik, Plancherel; and the relation [d/dx, x] = 1'1167      ' that it preserves', all(abs(FT(gauss, k) - math.exp(-k * k / 2)) < 1e-10 for k in (0.0, 0.7, 2.5)) and all(abs(FT(df4, k) - 1j * k * FT(f4, k)) < 1e-9 for k in (0.4, 1.9))1168      and abs(pl) < 1e-8 and weyl)1169inv5 = max(abs(simpson(lambda k: math.exp(-k * k * t) * math.cos(k * x), -40, 40, 8000) / (2 * PI) - heat(x, t)) for x, t in [(0.3, 0.5), (1.5, 0.2)])1170check('T5 the source function from the transform: the inverse transform of exp(-k^2 t) is the heat kernel', inv5 < 1e-10)1171ev3, vec3 = jacobi_eig(lap1(3))1172s_ = 0.81173Rm = inv([[(s_ if i == j else 0.0) + lap1(3)[i][j] for j in range(3)] for i in range(3)])1174sem = lambda t, i, j: sum(math.exp(-lam * t) * v[i] * v[j] for lam, v in zip(ev3, vec3))1175check('T6 the Laplace transform of a semigroup is its resolvent: the integral of exp(-st) exp(-tL) is (s + L)^{-1} (3 x 3 check)',1176      max(abs(simpson(lambda t: math.exp(-s_ * t) * sem(t, i, j), 0, 30, 12000) - Rm[i][j]) for i in range(3) for j in range(3)) < 1e-9)1177pv = lambda x: 1 / (1 + (x - 0.5) ** 2)1178errs = [abs(simpson(lambda x: (1 / (x - 1j * eps)).imag / PI * pv(x), -400, 400, 400000) - pv(0.0)) for eps in (0.1, 0.01)]1179check('T7 boundary values: the imaginary part of 1/(pi(x - i eps)) is the Poisson kernel of the half-plane and tends to delta, with error of order eps',1180      abs((1 / (0.3 - 0.02j)).imag / PI - 0.02 / (PI * (0.09 + 0.0004))) < 1e-15 and errs[1] < errs[0] / 5 and errs[1] < 0.01, 'errors %.4f, %.5f' % tuple(errs))1181 1182sec('12. Discretization')1183 1184 1185def run_explicit(s, J, steps, u0):1186    P = step_matrix(J, s)1187    u_, norms = list(u0), []1188    for _ in range(steps):1189        u_ = mv(P, u_)1190        norms.append(math.sqrt(dot(u_, u_)))1191    return u_, norms1192 1193 1194J = 201195u0 = [random.uniform(-1, 1) for _ in range(J)]1196_, nb = run_explicit(0.52, J, 400, u0)1197pred = abs(1 - 2 * 0.52 * (1 + math.cos(PI / (J + 1))))1198_, ns = run_explicit(0.5, J, 400, u0)1199check('N1 von Neumann: the explicit diffusion scheme has amplification 1 - 2s(1 - cos k dx); at s = 0.52 the computed growth per step equals'1200      ' the predicted maximum; at s = 0.5 nothing grows', abs(nb[-1] / nb[-2] - pred) < 1e-9 and pred > 1 and ns[-1] < ns[0], 'growth per step %.6f' % pred)1201 1202 1203def exp_err(s, J):1204    dx = 1.0 / J1205    steps = round(0.1 / (s * dx * dx))1206    P = step_matrix(J - 1, s)1207    u_ = [math.sin(PI * (j + 1) * dx) for j in range(J - 1)]1208    for _ in range(steps):1209        u_ = mv(P, u_)1210    return max(abs(u_[j] - math.exp(-PI * PI * 0.1) * math.sin(PI * (j + 1) * dx)) for j in range(J - 1))1211 1212 1213r2_, r6_ = exp_err(0.5, 10) / exp_err(0.5, 20), exp_err(1 / 6, 10) / exp_err(1 / 6, 20)1214check('N2 consistency: halving the mesh divides the error by 4 at s = 1/2 and by 16 at the special ratio s = 1/6', abs(r2_ - 4) < 0.2 and abs(r6_ - 16) < 1.0, 'ratios %.2f, %.2f' % (r2_, r6_))1215cn = lambda s, th: (1 - s * (1 - math.cos(th))) / (1 + s * (1 - math.cos(th)))1216lamh = 2 * (1 - math.cos(PI / 40)) * 16001217cn_err = lambda dt: abs(((1 - lamh * dt / 2) / (1 + lamh * dt / 2)) ** round(0.1 / dt) - math.exp(-lamh * 0.1))1218check('N3 Crank-Nicolson is stable for every s and of second order in time', all(abs(cn(s, th)) <= 1 for s in (0.1, 1, 10, 100, 1e4) for th in (0.1, 1.0, PI))1219      and abs(cn_err(0.01) / cn_err(0.005) - 4) < 0.1, 'error ratio %.3f' % (cn_err(0.01) / cn_err(0.005)))1220c = 1.01221exact = lambda x, t: math.exp(-(x - c * t - 1) ** 2) + 0.5 * math.sin(x + c * t)1222dx = 0.11223old = [exact(j * dx, 0.0) for j in range(-80, 81)]1224cur = [exact(j * dx, dx) for j in range(-80, 81)]1225dev = 0.01226for n_ in range(2, 40):1227    new = [cur[j + 1] + cur[j - 1] - old[j] for j in range(1, len(cur) - 1)]1228    off = n_ - 11229    dev = max(dev, max(abs(new[j] - exact((j - 80 + off) * dx, n_ * dx)) for j in range(len(new))))1230    old, cur = cur[1:-1], new1231Np = 321232gr = []1233for s in (1.1,):1234    o_, c_ = [(-1.0) ** j for j in range(Np)], [(-1.0) ** j * 1.3 for j in range(Np)]1235    for _ in range(60):1236        n_ = [s * (c_[(j + 1) % Np] + c_[j - 1]) + 2 * (1 - s) * c_[j] - o_[j] for j in range(Np)]1237        o_, c_ = c_, n_1238    gr.append(abs(c_[0] / o_[0]))1239pfac = -2 * 1.1