Pysic-rs Documentation¶

High-performance mathematical physics engine in Rust with Python bindings

Version License

Pysic-rs provides CPU-only, textbook-validated implementations of standard mathematical physics, built entirely in Rust and exposed to Python through PyO3. Every algorithm is a canonical result from the established literature — nothing experimental, nothing research-pending. This is the physics companion to Optimiz-rs, which supplies the probabilistic and statistical machinery (MCMC, HMM, SDE, Kalman filtering). Where you need physics and statistics, the two libraries interoperate.

🗂 Module Map — Pysic-rs covers thirteen foundational areas:

🧼 Special Functions — Γ, B, J_n, P_ℓ, Y_ℓ^m, erf, ζ · Linear Algebra — Cholesky, LU, inverse, tensor ops · Calculus — gradient, Hessian, Simpson, Romberg
⏱ Equations — RK4/RK45, symplectic integrators · Schrödinger/Dirac split-step, heat, wave FDTD, Poisson, Maxwell 3D FDTD
⚛ Quantum — Pauli algebra, density matrices, coherent states, path integrals, propagators · 🌌 GR — Schwarzschild/Kerr/FLRW, Christoffel, geodesics, ADM
🎯 Gauge & Topology — SU(2)/SU(3), Yang–Mills, Berry phase, Chern numbers · ⚙ Classical — Hamiltonian, Lagrangian, rigid body, Euler angles
⚡ EM & Casimir — Green's functions, radiation formulas, parallel-plate/sphere/Lifshitz Casimir energy

Algorithms

Features¶

Modules Included:

  • Special Functions: Gamma (Lanczos), Beta, Bessel J/Y, Legendre P/P_ℓ^m, spherical harmonics, Chebyshev T/U, Airy, erf/erfc, exponential integral, Riemann zeta

  • Linear Algebra: Cholesky, LU with pivoting, Gauss–Jordan inverse, determinant, tensor raise/lower, metric signature, Lie bracket

  • Numerical Calculus: gradient, Hessian, Jacobian, trapezoid/Simpson/Gauss–Legendre/Romberg integration, linear & cubic-spline interpolation

  • ODE Solvers: RK4, RK45 (Dormand–Prince), backward Euler, Crank–Nicolson, leapfrog, velocity Verlet, Yoshida symplectic, Hamiltonian integration

  • PDE Solvers: Schrödinger (split-step Fourier), Dirac, heat (Crank–Nicolson + ADI), wave (FDTD 1D/2D), Poisson (FFT + SOR), Maxwell (3D Yee)

  • Fourier Analysis: FFT/IFFT, power spectral density, Welch PSD, spectral derivatives

  • Quantum Mechanics: Pauli matrices, spin operators, density matrices, partial trace, coherent/number/squeeze states, Rayleigh–Schrödinger perturbation, path integrals, Feynman propagators

  • General Relativity: Schwarzschild, Kerr, Kerr–Newman, FLRW, Minkowski; Christoffel, Riemann, Ricci, Einstein tensors; geodesics; ADM 3+1; stress–energy

  • Gauge Theory: SU(2)/SU(3) structure constants, Gell-Mann matrices, connections, covariant derivative, Yang–Mills action/EOM, instantons (‘t Hooft)

  • Classical Mechanics: Hamiltonian, Lagrange/Euler–Lagrange, Poisson bracket, rigid-body (Euler equations, quaternions, Euler angles)

  • Topology: Berry phase & curvature, Chern/TKNN numbers, winding numbers, skyrmion number

  • Electromagnetism: Green’s functions (static, retarded, Helmholtz, dyadic), radiation formulas (Larmor, dipole, cyclotron, synchrotron, Thomson, Compton)

  • Casimir Effect: parallel plates, sphere, cylinders, ζ-regularization, finite-T, Lifshitz, Polder, van der Waals

Performance:

  • Pure Rust core with zero-cost abstractions

  • Python bindings via PyO3 (abi3) — no NumPy dependency at the boundary

  • Optional Rayon parallelism

  • 50–100× faster than pure Python physics code

Quick Example¶

from pysicrs import constants, schwarzschild_metric, rk4_solve

# Physical constants
print(constants()["c"])      # 2.997925e+08

# Schwarzschild metric at r = 10M
g = schwarzschild_metric(10.0, 1.0)
print(g[0, 0])     # -(1 - 2/10) = -0.8

# Integrate the harmonic oscillator with RK4
def osc(t, y):
    return [y[1], -y[0]]

times, traj = rk4_solve(osc, [1.0, 0.0], 0.0, 10.0, 10000)
print(traj[-1][0])  # cos(10) ≈ -0.8391

Installation¶

From source:

# Clone repository
git clone https://github.com/ThotDjehuty/pysic-rs.git
cd pysic-rs

# Build and install
pip install maturin
maturin develop --release

Indices and tables¶