Pysic-rs
A mathematical-physics engine written in Rust, callable from Python.
Textbook equations — Schrödinger, Dirac, Harper, Schwarzschild,
Casimir, Maxwell — solved by compiled code that is checked against
closed-form answers rather than trusted.
Rust core
PyO3 bindings
CPU-only
MIT licensed
Documentation ·
PyPI ·
crates.io ·
GitHub
Use cases
Three worked examples. Each is an executed notebook or article in which
every number is compared against a closed form — nothing is asserted
without being checked.
Notebook
Schrödinger & Dirac in 1D
Split-step Fourier evolution of a Gaussian packet against the
exact closed form, infinite-well eigenvalues, and the unitarity
of the Dirac propagator. Includes the Ehrenfest force that a
packet feels near an attractive well — and why unitary
evolution can never capture it into a bound state.
norm drift 7×10-14 over 500 steps
well spectrum to 5×10-6
Open notebook 05 →
Notebook
Topological invariants
Berry phase, Chern number and winding number — the
quantities that stay integer under deformation. The winding of
$e^{in\theta}$ comes back as an exact integer, which is what
makes the Aharonov–Bohm phase robust to disorder and the
quantum Hall plateaux flat.
Berry phase = −π exactly
winding integers to 0.0e+00
Open notebook 10 →
Article
From Dirac to Wheeler–DeWitt
Six equations connecting quantum mechanics to quantum gravity,
each solved with pysic-rs and graded against a closed form.
Ends with the four solver bugs this exercise exposed in our own
library — and why their tests let them through.
ADM constraints exact
Wheeler–DeWitt graded vs Airy
Read the article →
New to the library? Start with the
getting-started guide,
then the
special-functions reference,
which now carries a plot of every function it documents.
Why it exists
Computational physics in Python tends to be a thin wrapper over a
fast kernel, with the interesting parts — the loop over modes,
the boundary handling, the root-finding — written in
interpreted code. That is where the time goes, and it is also where
silent errors hide.
Pysic-rs moves that layer into Rust. The gain is twofold: the loop
runs at compiled speed, and the type system removes a class of
mistakes (unit mix-ups, uninitialised state, out-of-range indices)
before the program runs at all.
The logo is Hofstadter’s butterfly — the fractal spectrum of an
electron in a magnetic field. It is not decoration: the Harper
equation that draws it is one of the equations the library solves.
What it solves
Quantum mechanics
Split-step Fourier Schrödinger propagation, and a
finite-difference Dirac solver checked against the
free-particle dispersion \(E^2 = p^2c^2 + m^2c^4\).
Topology
Harper equation, Hofstadter butterfly, Chern numbers and
Berry phase — the invariants behind the quantum Hall
effect.
General relativity
Schwarzschild metric, Christoffel symbols and geodesic
integration.
Electromagnetism & QED
Maxwell Green’s functions and radiation, plus the Casimir
force between parallel plates via Lifshitz theory.
Special functions
Gamma, Bessel, Legendre, erf, zeta, Airy and Chebyshev —
the primitives everything else is built from.
The Casimir force between parallel plates, for instance, is
\(F = -\pi^2 \hbar c A / (240\,a^4)\) — a closed form, which
means the solver can be graded rather than merely demonstrated.
Features & Resources
pysic-rs.html logo + use-case cards
The Hofstadter butterfly logo visualizes the Harper equation solved by the library. Use-case cards cover Quantum mechanics, Topology, GR, EM & QED, and Special functions — the five core domains of pysic-rs.
readthedocs mathematical-formulation article
From Quantisation to Quantum Gravity — the mathematical formulation of Schrödinger, Dirac, Maxwell/Aharonov–Bohm, the ADM constraints and Wheeler–DeWitt, each reduced to the invariant a correct implementation must preserve. Alongside Mathematical Foundations for the numerical skeleton underneath.
arXiv preprint
A Validated Mathematical-Physics Engine in Rust, and What Grading It Against
Closed Forms Revealed — the library's design, the mathematical formulation
of six equations it solves, and a post-mortem of the eight incorrect routines this
work exposed in our own code, with an analysis of why their tests could not have
failed.
Download PDF (9 pp.)
Prerequisites course — 10,99 €
30 pages, 34 exercises with full solutions (in French). Complex
analysis and special functions, floating-point cancellation, spectral linear
algebra, ODE stability, Fourier and Strang splitting, asymptotics and turning
points, Clifford algebra, and constrained systems. The thread running through it
is one question: how would I know this result is wrong?
Read the course (30 pp.)
Validated, not asserted
Every solver ships with a test that compares it against a
closed-form result or a textbook value. That is the difference
between code that should be right and code that is
demonstrably right, and it is the reason the library is usable as a
reference implementation rather than a starting point.
The same discipline runs through the sibling projects:
optimiz-rs
for numerical primitives,
Polarway
for the data layer, and
ThotBook-AI
for the local-first LLM toolset, which uses physics-informed neural
networks to check the equations it reads in papers.