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