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 1021–1120 of 1640. Source text is displayed literally.

1021qb = float(-(Am[0][0] * Bm[1][1] + Am[1][1] * Bm[0][0] - 2 * Am[0][1] * Bm[0][1]))1022qc = float(Am[0][0] * Am[1][1] - Am[0][1] ** 2)1023ritz = sorted([(-qb - math.sqrt(qb * qb - 4 * qa * qc)) / (2 * qa), (-qb + math.sqrt(qb * qb - 4 * qa * qc)) / (2 * qa)])1024check('L1 Rayleigh-Ritz gives upper bounds: on (0,1) the trial function x(1-x) gives 10, and adding x^2(1-x)^2 gives 9.86975 against pi^2 = 9.86960;'1025      ' the second Ritz value bounds the third eigenvalue 9 pi^2', Am[0][0] / Bm[0][0] == 10 and 0 < ritz[0] - PI ** 2 < 2e-4 and ritz[1] > 9 * PI ** 2,1026      'Ritz values %.6f, %.4f' % tuple(ritz))1027okI = True1028for _ in range(10):1029    Ar = [[0.0] * 8 for _ in range(8)]1030    for i in range(8):1031        for j in range(i, 8):1032            Ar[i][j] = Ar[j][i] = random.uniform(-1, 1)1033    ea_, eb_ = jacobi_eig(Ar)[0], jacobi_eig([r[:7] for r in Ar[:7]])[0]1034    okI = okI and all(ea_[k] <= eb_[k] + 1e-12 and eb_[k] <= ea_[k + 1] + 1e-12 for k in range(7))1035check('L2 the minimax principle in its finite form: eigenvalues of a compression interlace those of the matrix (ten random cases)', okI)1036cells = [(i, j) for i in range(6) for j in range(6)]1037Lsh = [(i, j) for (i, j) in cells if not (i >= 3 and j >= 3)]1038 1039 1040def region_lap(cs):1041    ix = {c_: k for k, c_ in enumerate(cs)}1042    Lr = [[0.0] * len(cs) for _ in cs]1043    for (i, j), k in ix.items():1044        Lr[k][k] = 4.01045        for p in ((i + 1, j), (i - 1, j), (i, j + 1), (i, j - 1)):1046            if p in ix:1047                Lr[k][ix[p]] = -1.01048    return Lr1049 1050 1051eS, eL = jacobi_eig(region_lap(cells))[0], jacobi_eig(region_lap(Lsh))[0]1052corner = 0.5 + (0.65 + 0.05) / math.sqrt(2)1053check('L3 enlarging a domain lowers every Dirichlet eigenvalue (an L-shaped region inside a 6 x 6 square); for Neumann conditions this fails:'1054      ' a 1.3 x 0.1 rectangle fits inside the unit square along its diagonal and has the smaller second eigenvalue',1055      all(eL[k] >= eS[k] - 1e-12 for k in range(len(eL))) and corner < 1 and PI ** 2 / 1.69 < PI ** 2, 'first eigenvalues: square %.4f, L-shape %.4f; Neumann: %.3f < %.3f' % (eS[0], eL[0], PI ** 2 / 1.69, PI ** 2))1056ar, br = 1.0, math.sqrt(2.0)1057Area, Per = ar * br, 2 * (ar + br)1058 1059 1060def count(lam):1061    c_, m_ = 0, 11062    while PI ** 2 * m_ * m_ / ar ** 2 < lam:1063        rest = lam - PI ** 2 * m_ * m_ / ar ** 21064        c_ += int(math.floor(math.sqrt(rest) * br / PI - 1e-12))1065        m_ += 11066    return c_1067 1068 1069rows = []1070okW = True1071for lam in (2000.0, 8000.0, 32000.0):1072    Nn = count(lam)1073    two = Area * lam / (4 * PI) - Per * math.sqrt(lam) / (4 * PI)1074    okW = okW and abs(Nn - two) / Nn < 0.021075    rows.append('lambda=%g: N=%d, two-term Weyl %.1f, lambda/N=%.3f' % (lam, Nn, two, lam / Nn))1076check('L4 Weyl\'s law for a 1 x sqrt 2 rectangle: N(lambda) against A lambda/(4 pi) - P sqrt(lambda)/(4 pi), and lambda_n/n tending to 4 pi/A = 8.886',1077      okW and abs(32000.0 / count(32000.0) - 4 * PI / Area) < 0.25, '; '.join(rows))1078ztrace = lambda t: sum(math.exp(-PI ** 2 * m_ * m_ * t / ar ** 2) for m_ in range(1, 400)) * sum(math.exp(-PI ** 2 * n_ * n_ * t / br ** 2) for n_ in range(1, 400))1079hk = [ztrace(t) - (Area / (4 * PI * t) - Per / (8 * math.sqrt(PI * t)) + 0.25) for t in (0.02, 0.01, 0.005)]1080check('L5 the heat trace of a rectangle is A/(4 pi t) - P/(8 sqrt(pi t)) + 1/4 up to exponentially small terms: one can hear the area, the perimeter'1081      ' and the four corners', all(abs(v) < 1e-9 for v in hk), 'differences at t = 0.02, 0.01, 0.005: %.1e, %.1e, %.1e' % tuple(hk))1082a7, t7 = 1.7, 0.31083lhs = sum(math.exp(-PI ** 2 * m_ * m_ * t7 / a7 ** 2) for m_ in range(1, 200))1084rhs = a7 / (2 * math.sqrt(PI * t7)) - 0.5 + a7 / math.sqrt(PI * t7) * sum(math.exp(-(2 * a7 * k) ** 2 / (4 * t7)) for k in range(1, 200))1085check('L6 a trace formula: the sum over the spectrum of an interval equals a sum over its closed geodesics, of lengths 2ak (Poisson summation)', abs(lhs - rhs) < 1e-14)1086 1087 1088def cospectral_search(n):1089    prs = [(i, j) for i in range(n) for j in range(i + 1, n)]1090    by = {}1091    for mask in range(1 << len(prs)):1092        deg = [0] * n1093        Lg = [[0] * n for _ in range(n)]1094        for b, (i, j) in enumerate(prs):1095            if mask >> b & 1:1096                Lg[i][j] = Lg[j][i] = -11097                deg[i] += 11098                deg[j] += 11099        if min(deg) == 0:1100            continue1101        for i in range(n):1102            Lg[i][i] = deg[i]1103        cp = charpoly_int(Lg)1104        if cp[n - 1] == 0:1105            continue                                         # disconnected1106        by.setdefault(cp, {}).setdefault(tuple(sorted(deg)), [prs[b] for b in range(len(prs)) if mask >> b & 1])1107    return {cp: d for cp, d in by.items() if len(d) > 1}1108 1109 1110c5, c6 = cospectral_search(5), cospectral_search(6)1111first = c6.get((1, -14, 73, -176, 192, -72, 0), {})1112check('L7 one cannot hear the shape of a graph: among connected graphs on at most five vertices no two with different degree sequences share a'1113      ' Laplacian spectrum; on six vertices two spectra are shared, the first by graphs with seven edges',1114      len(c5) == 0 and len(c6) == 2 and sorted(first) == [(1, 2, 2, 3, 3, 3), (2, 2, 2, 2, 2, 4)], '; '.join('%s: %s' % (k, v) for k, v in sorted(first.items())))1115U8 = [1, 3, 5, 7]1116G8 = [(a, u) for a in range(8) for u in U8]1117gmul = lambda g, h_: ((g[0] + g[1] * h_[0]) % 8, (g[1] * h_[1]) % 8)1118ginv = lambda g: next(h_ for h_ in G8 if gmul(g, h_) == (0, 1))1119H1, H2 = [(0, 1), (0, 3), (0, 5), (0, 7)], [(0, 1), (4, 3), (4, 5), (0, 7)]1120classes = {frozenset(gmul(gmul(x, g), ginv(x)) for x in G8) for g in G8}