MechanicsDSL is a domain-specific language for computational physics. You write a Lagrangian or Hamiltonian in LaTeX-inspired syntax; the symbolic engine derives the equations of motion, and the compiler emits production-ready code in 13 target languages — from Python and C++ to CUDA, Rust, WebAssembly, and Arduino.
pip install mechanicsdsl-core
% A simple pendulum, written as a Lagrangian \system{pendulum} \parameter{m}{1.0}{kg} \parameter{l}{1.0}{m} \parameter{g}{9.81}{m/s^2} \defvar{theta}{angle}{rad} \lagrangian{ \frac{1}{2} m l^2 \dot{theta}^2 - m g l (1 - \cos{theta}) } \initial{theta=0.5, theta_dot=0}
Edit the DSL on the left, watch the system evolve on the right. Pyodide runs the real SymPy/SciPy pipeline in your browser — toggle Python mode for the authoritative integrator.
Three stages, all symbolic. No hand-derived equations, no template hacks.
A LaTeX-inspired DSL: declare parameters, coordinates, and the Lagrangian (or Hamiltonian). What you'd write in a notebook is what the compiler reads.
SymPy applies the Euler–Lagrange (or Hamilton's) equations, simplifies, and produces a closed-form ODE system. Nothing is approximated yet.
Run it immediately with SciPy or JAX, or emit a working reference implementation in any of 13 target languages — including CUDA kernels and Arduino sketches.
Pick a language. Get a reference implementation that compiles and runs.
// Generated C++ for a simple pendulum
#include <cmath>
#include <vector>
const double g = 9.81;
const double l = 1.0;
void compute_derivatives(const double* y, double* dydt, double t) {
double theta = y[0];
double theta_dot = y[1];
dydt[0] = theta_dot;
dydt[1] = -g / l * std::sin(theta);
}
void rk4_step(double* y, double t, double dt) {
// ... classical fourth-order Runge–Kutta
}
Click a system to load it into the playground.
Built for both classroom physics and production simulations.
Built on SymPy. Derives Euler–Lagrange or Hamilton's equations, simplifies, and produces a closed-form ODE system you can inspect.
Optional GPU/TPU acceleration with JIT compilation and automatic differentiation for inverse problems.
Parameter estimation, sensitivity analysis, and MCMC uncertainty quantification — fit physical parameters to measured data.
%%mechanicsdsl cell magic for interactive notebook workflows; %mdsl_params
line magic for live parameter sweeps.
Run on Raspberry Pi and ARM devices; generate Arduino sketches for hardware-in-the-loop experiments.
Add custom physics domains, integrators, or code generators without forking the core.
Language server for completions, diagnostics, and hover docs in any LSP-aware editor; first-party VS Code extension.
CPU and CUDA container images; reference Helm charts for cluster deployment.
Note on generated code. The code generators produce working reference implementations, not production-tuned binaries. Treat them as a starting point for performance-critical work.
Requires Python 3.9+. NumPy, SciPy, SymPy, and Matplotlib install automatically.
pip install mechanicsdsl-core
pip install mechanicsdsl-core[jax]
pip install mechanicsdsl-core[jupyter]
pip install mechanicsdsl-core[all]