Hamiltonian Integrator Explorer

Discretisation schemes, step-size stability & energy conservation

Hamiltonian H(q, p) = p²/2 + q²/2
Equations of Motion dq/dt = p , dp/dt = −q
Initial Energy H₀ = 2.000
Harmonic q²/2
Double-well
Quartic q⁴/4
2.00
0.20
60
0.25×
0.5×
Phase Space (q, p)
Energy H(q,p) over integration steps
Exact solution — true Hamiltonian flow, energy perfectly conserved
Explicit Euler — 1st order, non-symplectic, energy spirals outward
Symplectic Euler — 1st order, symplectic, energy oscillates but bounded
Leapfrog — 2nd order, symplectic, excellent energy conservation (used in HMC)

Explicit Euler

q ← q + ε·p
p ← p − ε·∇U(q)

Both updates use the old values. This breaks the symplectic structure — the numerical flow does not preserve phase-space volume. Energy drifts monotonically, making trajectories spiral outward.

Non-symplectic · Energy diverges

Symplectic Euler

p ← p − ε·∇U(q)
q ← q + ε·pnew

Momentum updated first, then position uses the new momentum. This one-sided coupling preserves the symplectic 2-form. Energy oscillates around the true value with amplitude O(ε).

Symplectic · 1st order · O(ε) energy error

Leapfrog (Störmer-Verlet)

p ← p − (ε/2)·∇U(q)
q ← q + ε·p
p ← p − (ε/2)·∇U(qnew)

A symmetric, time-reversible composition. 2nd order accuracy means the energy shadow Hamiltonian is O(ε²) close to the true one. This is the integrator used in HMC.

Symplectic · 2nd order · O(ε²) energy error