Indexed text attachment
verify-pde.py
Source for Partial Differential Equations in Higher Categories
View paper · Download original file
Lines 1–100 of 1640. Source text is displayed literally.
1#!/usr/bin/env python32# verify-pde.py3# Companion script to "Partial Differential Equations in Higher Categories" (Higher Categorical Semantics, 2026; byline Anonymous).4# 107 computational checks of the numerical and finite statements in the book. Python standard library only; fixed seed.5# Usage: python3 verify-pde.py (under half a minute; exit status 0 iff every check passes)6# The checks recompute examples and test instances of structural statements. They are evidence, not proofs.7# Written and run with AI assistance (Anthropic's Claude).8import math, cmath, random, sys, itertools9from fractions import Fraction as Fr10 11random.seed(20261117)12_n = [0, 0]13PI = math.pi14 15 16def sec(title):17 print('\n== ' + title + ' ==')18 19 20def check(name, ok, detail=''):21 _n[0] += 122 _n[1] += 0 if ok else 123 print(('PASS ' if ok else 'FAIL ') + name + (('\n [' + detail + ']') if detail else ''))24 25 26def footer():27 print('\n%d checks, %d passed, %d failed' % (_n[0], _n[0] - _n[1], _n[1]))28 sys.exit(1 if _n[1] else 0)29 30 31def close(a, b, tol=1e-9):32 return abs(a - b) <= tol * (1 + abs(a) + abs(b))33 34 35# ---------- linear algebra (lists of lists) ----------36def eye(n):37 return [[1.0 if i == j else 0.0 for j in range(n)] for i in range(n)]38 39 40def tr(A):41 return [list(r) for r in zip(*A)]42 43 44def mm(A, B):45 Bt = list(zip(*B))46 return [[sum(a * b for a, b in zip(r, c)) for c in Bt] for r in A]47 48 49def mv(A, x):50 return [sum(a * b for a, b in zip(r, x)) for r in A]51 52 53def dot(x, y):54 return sum(a * b for a, b in zip(x, y))55 56 57def axpy(a, x, y):58 return [a * xi + yi for xi, yi in zip(x, y)]59 60 61def solve(A, b):62 n = len(A)63 M = [list(A[i]) + [b[i]] for i in range(n)]64 for c in range(n):65 p = max(range(c, n), key=lambda r: abs(M[r][c]))66 M[c], M[p] = M[p], M[c]67 piv = M[c][c]68 for r in range(c + 1, n):69 f = M[r][c] / piv70 if f:71 Mr, Mc = M[r], M[c]72 for k in range(c, n + 1):73 Mr[k] -= f * Mc[k]74 x = [0.0] * n75 for i in range(n - 1, -1, -1):76 x[i] = (M[i][n] - sum(M[i][k] * x[k] for k in range(i + 1, n))) / M[i][i]77 return x78 79 80def inv(A):81 n = len(A)82 cols = [solve(A, [1.0 if i == j else 0.0 for i in range(n)]) for j in range(n)]83 return tr(cols)84 85 86def rank_exact(rows):87 M = [[Fr(v) for v in r] for r in rows]88 rk, ncol = 0, (len(M[0]) if M else 0)89 for c in range(ncol):90 p = next((r for r in range(rk, len(M)) if M[r][c] != 0), None)91 if p is None:92 continue93 M[rk], M[p] = M[p], M[rk]94 for r in range(rk + 1, len(M)):95 if M[r][c] != 0:96 f = M[r][c] / M[rk][c]97 M[r] = [a - f * b for a, b in zip(M[r], M[rk])]98 rk += 199 if rk == len(M):100 break