# tinydiffeq

> Tiny differentiable ODE/SDE/DAE/SDAE solvers for JAX. Fixed-step (Euler, RK4) and adaptive (Tsit5 + integral or proportional-integral controller) explicit Runge-Kutta run inside one bounded lax.scan of exactly max_steps attempted steps: static shapes and forward/reverse AD, including reverse-over-forward. Nonstiff semi-explicit index-1 DAEs use nlls-gram's square LM root solve with implicit JVP/VJP. With has_aux=True the algebraic equation returns (residual, aux), where aux is a floating pytree evaluated at consistent nodes and differentiated through both direct parameters and the root. Deterministic requested-grid output uses normalized cubic Hermite for y, z, and aux; z/aux slopes come from the implicit function theorem, so no query-time nonlinear solves occur. Interpolated algebraic output has O(h^4) error under C4 smoothness, uniform nonsingularity, and sufficiently tight root tolerances, but need not satisfy the constraint exactly away from knots. Fixed-step solve_semi_explicit_sdae applies Euler-Maruyama to the reduced Ito SDE, re-solving the algebraic constraint at every stochastic node; it supports diagonal noise, pathwise AD under a fixed key, aux, and endpoint/step output. States may be arrays or arbitrary JAX pytrees; state leaves share one real floating dtype and aux leaves are nonempty real floating arrays that may use different dtypes. Adaptive-controller defaults are rtol=1e-4, atol=1e-6 for float32 and rtol=1e-7, atol=1e-9 for float64. Use diffrax/SciML for stiff or fully implicit solvers, higher-index DAEs, adaptive stochastic stepping, events, continuous interpolation objects, or specialized adjoints.

## Docs

- [Home — positioning, vector-field signature convention f(x, t, args, p), minimal examples](https://highdimensionaleconlab.github.io/tinydiffeq/)
- [Static shapes — the bounded-scan design, SaveAt observation grids, compact accepted steps and padding, why nothing recompiles](https://highdimensionaleconlab.github.io/tinydiffeq/static_shapes/)
- [Adaptive stepping and AD — stop-gradiented controller rationale, horizon-clip growth guard, non-differentiable interpolation knots, double-where NaN safety](https://highdimensionaleconlab.github.io/tinydiffeq/adaptive_ad/)
- [Semi-explicit DAEs — index-1 contract, algebraic LM roots, implicit AD, failure behavior, and SaveAt](https://highdimensionaleconlab.github.io/tinydiffeq/dae/)
- [SDEs — Euler-Maruyama orders, fixed-noise key semantics, shared-path strong-convergence testing, why SaveAt(ts) raises](https://highdimensionaleconlab.github.io/tinydiffeq/sde/)
- [Semi-explicit SDAEs — reduced-SDE Euler-Maruyama, algebraic roots, aux, convergence assumptions, and pathwise AD](https://highdimensionaleconlab.github.io/tinydiffeq/sdae/)
- [API reference — ODE/SDE/DAE solves, solvers, controllers, root configuration, SaveAt, solution types, interpolation, and quadrature](https://highdimensionaleconlab.github.io/tinydiffeq/api/)
