# Foundations example checks

Each program reproduces a worked example in the [Foundations volume](/foundations/). Choose the script for the observable or identity you want to check.

## Run

Download the desired script, then run it with Python 3:

```sh
python3 verify.py
python3 check_classical.py
python3 four_site_dynamics.py
python3 check_algebra.py
python3 check_spectral.py
python3 check_meanings_locality.py
python3 check_geometry_spectral.py
python3 check_algebra_complex.py
python3 check_limits_evidence.py
python3 cubic_branch_paths.py
python3 observable_limits.py
python3 poisson_geometry_controls.py
python3 quantum_spaces_and_flux.py
```

From the repository root, prefix each filename with `public/computations/foundations/`.

| Download | Dependencies | Scope |
|---|---|---|
| [verify.py](verify.py) | Python standard library | Wrong-frequency oscillator, exact trace brackets, thermal and continuum limits, diffusive-ring modes and pinned free-energy sums |
| [check_classical.py](check_classical.py) | SymPy | Oscillator conservation and rank, variable-coefficient Jacobi tests, spin geometry, canonical transformations and exact finite TASEP counting |
| [four_site_dynamics.py](four_site_dynamics.py) | NumPy and SciPy | Oscillator section returns, the full spin exchange restricted to one flip, a symmetric walker, opposite-site probabilities and a phase-sensitive preparation |
| [check_algebra.py](check_algebra.py) | NumPy | Variable-coupling spin/energy continuity, density tails, spin projectors, intertwiners and rational Yang–Baxter identity |
| [check_spectral.py](check_spectral.py) | SymPy and mpmath | Finite Lax transport, interval boundaries, rational and nodal curves, two independent period quadratures |
| [check_meanings_locality.py](check_meanings_locality.py) | NumPy and SymPy | Rank and symmetry generators, two-spin transfer family, isospectral reconstruction, stochastic transitions, inhomogeneous energy flux and free-fermion moment completeness |
| [check_geometry_spectral.py](check_geometry_spectral.py) | Python standard library | Canonical orientation, momentum maps, field variations, Robin boundaries, resolvents, twisted Floquet modes and reflectionless Jost data |
| [check_algebra_complex.py](check_algebra_complex.py) | NumPy, SymPy and mpmath | Commutants, partial traces, fermion signs, operator-domain counterexamples, monodromy, Cauchy jumps, periods and stationary-phase limits |
| [check_limits_evidence.py](check_limits_evidence.py) | NumPy and SymPy | Weyl corrections, variable-tension scaling, pinned and constrained covariances, uniform phase errors, level statistics and perturbative charges |
| [cubic_branch_paths.py](cubic_branch_paths.py) | Python standard library | Follow the three roots of a cubic around two branch values and compare the two orders of continuation |
| [observable_limits.py](observable_limits.py) | NumPy, SciPy and SymPy | Thermal bandwidth, the cubic commutator in the ground state, pinned-ring covariance, response to a residual and an exact quadratic invariant |
| [poisson_geometry_controls.py](poisson_geometry_controls.py) | Python standard library | Invariant areas, detuned oscillators, moving coordinates, torus windings, Heisenberg translations and field transport |
| [quantum_spaces_and_flux.py](quantum_spaces_and_flux.py) | SymPy | Three-spin intertwiners and twists, correlated charge densities, increasing charge range and power delivered to a string endpoint |

The tested environment is Python 3.9.6, NumPy 2.0.2, SciPy 1.13.1, SymPy 1.14.0 and mpmath 1.3.0. The following commands reproduce the optional dependencies in an isolated environment.

```sh
python3 -m venv .venv
.venv/bin/python -m pip install numpy==2.0.2 scipy==1.13.1 sympy==1.14.0 mpmath==1.3.0
.venv/bin/python check_classical.py
.venv/bin/python check_algebra.py
.venv/bin/python check_spectral.py
```

Python 3.9 or later is needed for these tested dependency versions; use a compatible Python when creating the environment. No dependency installation is needed for `verify.py`.

## What is checked

`verify.py` compares independently assembled matrix commutators and centered time differences. With amplitude 1.3 and frequency 1.7, the correct oscillator's normalized residual decreases by about four under step halving; the deliberately wrong frequency 1.36 has the same energy but residual tending to 0.34. Trace gradients are evaluated using exact rational matrices: the noncommuting example gives bracket 3 and rank minor 30. The code assembles the discrete second-difference action on Fourier vectors for 7, 16 and 31 sites, checks the dispersion error inequality, and compares fixed-time and diffusive-time sequences on rings of 16–128 sites. A 4,096-mode sum supplies a numerical comparison for the pinned free energy; the article's Riemann-sum argument is the convergence proof.

`check_classical.py` uses exact symbolic differentiation. It tests full rank at oscillator turning points even when a selected minor vanishes; a rank-changing equilibrium; a Jacobiator equal to one for the deliberately invalid bracket; a repaired variable bracket and Casimir; spin rotation orientation; and all fixed-population binary rings of 2–8 sites. These exhaustive small rings check the combinatorial current formula independently of its derivation.

`check_algebra.py` uses full finite matrices with the leftmost tensor factor first. Reported positive residuals are unnormalized Euclidean vector or Frobenius matrix norms, with a tolerance of `2e-12`. The four-site continuity calculation uses unequal couplings `(0.7, 1.3, 1.9, 0.4)`. Negative controls reverse the current sign, test the nonconserved total energy current of that inhomogeneous chain, and replace the rational spectral parameter by its square. Those failures must remain nonzero. The exact diagonal-string norm formula is checked on 3, 5 and 7 sites.

`check_spectral.py` first checks symbolic identities and boundary counterexamples. It then calculates the same elliptic periods in the original coordinate with integrable endpoint singularities and in a smooth trigonometric coordinate, at 50 decimal digits for parameters 0.2, 0.5 and 0.8. Their maximum observed absolute discrepancy is about `6.54e-27`, below the declared `1e-20` quadrature tolerance. Omitting the second sheet deliberately fails. This is numerical agreement of two explicit integral representations, not a certified error bound on arbitrary quadratures or a proof of a reconstruction theorem.

`check_meanings_locality.py` derives energy derivatives from an inhomogeneous Hamiltonian independently of the proposed currents. It rejects reversed current signs and the omission of the tension derivative. Explicit auxiliary-space matrices test the dimer transfer formula; generator diagonalization is compared with a convergent Poisson sum; all 4–8-site binary configurations distinguish constant-rate one-particle/one-hole sectors from variable-rate sectors. Exhaustive occupation enumeration on 12 sites checks the charge covariance, while separate Fourier sums check the missing-moment example. Numerical checks use absolute maximum-entry errors and tolerance `2e-12`; the classical derivatives and rank witnesses are exact symbolic calculations.

`check_geometry_spectral.py` combines exact rational polynomial identities with independently assembled numerical checks. It compares a field variation with a central difference at step `1e-5` using 512 periodic quadrature points, checks all ten twisted-ring Floquet eigenvectors for five cells, and refines the Jost equation's centered-difference step through `0.02`, `0.01`, and `0.005`. The observed Jost residual decreases by approximately four under halving; a separate Simpson integral checks the bound-state normalization. Endpoint counterexamples remain explicit rather than being absorbed into the bulk residual.

`check_algebra_complex.py` reports Frobenius matrix residuals unless it explicitly names operator norm, and recomputes quadratures at 35 and 50 decimal digits. It includes noncommuting multiplicity operators, failure of unrestricted partial-trace cyclicity, ordinary versus graded swaps, a domain-sensitive translation example, Cauchy boundary signs and nonuniform saddle limits. Its finite examples check the formulas in the articles; they do not prove general analytic theorems.

`check_limits_evidence.py` verifies the cubic Weyl corrections and oscillator brackets symbolically, then compares variable-tension flux differences under refinement, direct stiffness-matrix inverses with Fourier covariances, and constrained unpinned covariances with pseudoinverses. It also distinguishes a single shifted-grid spectrum from a phase ensemble, computes midpoint frequency and residual errors, executes a wrong-sign energy-preserving trajectory, and tests a first-order corrected charge against exact normal-mode evolution. Each numerical output names its norm or observable, parameters and comparison; no finite sample is treated as a proof of uniform convergence.

## Regenerate the figures

The dispersion figure uses Matplotlib 3.9.4 and the exact dimensionless formula. From the repository root:

```sh
MPLCONFIGDIR=.tmp/matplotlib python3 figures-src/foundations/dispersion-limit.py
MPLCONFIGDIR=.tmp/matplotlib python3 figures-src/foundations/charge-moments.py
MPLCONFIGDIR=.tmp/matplotlib python3 figures-src/foundations/thermal-bandwidth.py
MPLCONFIGDIR=.tmp/matplotlib python3 figures-src/foundations/returns-and-ring.py
python3 figures-src/foundations/casimir-winding.py --check
```

The sheet-lifting diagram is original TikZ source. With a TeX installation and `pdf2svg`, run from the repository root:

```sh
mkdir -p .tmp/foundations-figures
pdflatex -interaction=nonstopmode -halt-on-error -output-directory=.tmp/foundations-figures figures-src/foundations/spectral-sheets.tex
pdf2svg .tmp/foundations-figures/spectral-sheets.pdf public/figures/foundations/spectral-sheets.svg
```

The occupation plot checks its exact Fourier moments on a grid distinct from the plotting sample. The thermal plot compares finite-ring mode sums with a limiting integral. The torus diagram checks every height against its return map; omit `--check` to regenerate it. Keep intermediate TeX output under `.tmp/`.
