Classical Mechanics

Hamiltonian Mechanics

Phase-space formulation where position and momentum are the protagonists, not force

Hamiltonian mechanics replaces force with energy and trades two second-order equations for 2n first-order ones in phase space. The Hamiltonian H(q, p) generates flow through Hamilton's equations, and the entire structure — Poisson brackets, canonical transformations, Liouville's theorem — is the bridge from classical to quantum mechanics.

  • FormulatedWilliam Rowan Hamilton, 1833
  • Central objectH(q, p, t) = p·q̇ − L
  • Equations of motionq̇ = ∂H/∂p, ṗ = −∂H/∂q
  • Phase space dim2n for n d.o.f.
  • Quantum analog{·,·} → (1/iℏ)[·,·]

Interactive visualization

Press play, or step through manually. The visualization is yours to drive — try it before reading on.

Open visualization fullscreen ↗

Watch the 60-second explainer

A condensed visual walkthrough — narrated, captioned, under a minute.

From velocities to momenta

Lagrangian mechanics works in configuration space — the space of generalized coordinates q. Its equations are second-order in time and treat q and q̇ on equal footing. Hamiltonian mechanics performs a Legendre transform, replacing the velocity q̇ with the conjugate momentum

p_i = ∂L / ∂q̇_i

The new arena is phase space, with coordinates (q1, …, qn, p1, …, pn) — twice as many as configuration space, but the equations become first-order. The Hamiltonian is

H(q, p, t) = Σ_i p_i q̇_i − L(q, q̇, t)

where the q̇i on the right have been re-expressed in terms of (q, p) using the definition of pi. For most systems where T is quadratic in q̇ and constraints are time-independent, the algebra collapses to H = T + V — the total energy. The Hamiltonian is therefore "the energy" in most ordinary contexts, but the deeper definition is that H is the generator of time evolution.

Hamilton's equations

Substituting H into the variational principle and demanding δS = 0 with q and p varied independently gives the 2n first-order equations

q̇_i =  ∂H / ∂p_i
ṗ_i = −∂H / ∂q_i

Plus, by direct differentiation, dH/dt = ∂H/∂t. If H has no explicit time dependence, H is conserved — energy conservation as a one-line corollary. The minus sign in the second equation is the key — it gives the equations a symplectic (skew-symmetric) structure that is preserved under all valid canonical transformations.

Each pair (qi, pi) is called a canonical pair. Their Poisson bracket is

{q_i, p_j} = δ_ij,    {q_i, q_j} = {p_i, p_j} = 0

and these brackets, not the names of the variables, are what define a canonical pair. Canonical transformations (q, p) → (Q, P) are exactly the diffeomorphisms that preserve these Poisson brackets.

Worked example: the harmonic oscillator in phase space

Take a mass m on a spring of stiffness k. The Lagrangian is L = ½mẋ² − ½kx². The conjugate momentum is p = ∂L/∂ẋ = mẋ. Solving for ẋ = p/m and substituting:

H = p·ẋ − L = p·(p/m) − [½m(p/m)² − ½kx²]
  = p²/m − p²/(2m) + ½kx²
  = p²/(2m) + ½kx²

This is the textbook total energy. Hamilton's equations are

ẋ = ∂H/∂p = p/m
ṗ = −∂H/∂x = −kx

Two coupled first-order ODEs. Differentiating the first and substituting the second gives ẍ = −(k/m)x — simple harmonic motion with ω = √(k/m). Geometrically, the level sets of H in (x, p) space are ellipses, and trajectories trace them at constant rate. With m = 1 kg, k = 100 N/m, and an initial displacement x₀ = 0.1 m at rest, the orbit is an ellipse with semi-axes (0.1 m, 1.0 kg·m/s) and the period is T = 2π/ω = 2π/10 = 0.628 s. Every trajectory in phase space is closed; energy is exactly conserved by the flow because ∂H/∂t = 0.

Poisson brackets and the algebra of observables

For any two functions f(q, p, t) and g(q, p, t) on phase space, the Poisson bracket is

{f, g} = Σ_i (∂f/∂q_i · ∂g/∂p_i − ∂f/∂p_i · ∂g/∂q_i)

It is bilinear, antisymmetric, satisfies the Leibniz rule and the Jacobi identity, and it generates time evolution:

df/dt = {f, H} + ∂f/∂t

If f has no explicit time dependence and {f, H} = 0, then f is a conserved quantity. The angular momentum Lz = xpy − ypx is conserved in any rotationally symmetric Hamiltonian because {Lz, H} = 0. Two of the three components of angular momentum together with H generate a Lie algebra, which classifies the integrable systems.

The Poisson bracket structure survives quantization. Dirac's prescription is to replace

{f, g}  →  (1/iℏ) [f̂, ĝ]

so that {q, p} = 1 becomes [q̂, p̂] = iℏ — the canonical commutation relation that is the foundation of quantum mechanics. Hamilton's equation df/dt = {f, H} becomes Heisenberg's equation iℏ df̂/dt = [f̂, Ĥ]. The two formalisms have the same skeleton.

Phase-space flow and Liouville's theorem

Hamilton's equations define a vector field on phase space that pushes points along trajectories. A finite blob of initial conditions evolves into a deformed blob over time. Liouville's theorem states that the 2n-dimensional phase-space volume is exactly preserved by Hamiltonian flow:

d/dt ∫ dq^n dp^n = 0

The proof is one line: the divergence of the phase-space velocity field (q̇, ṗ) is

Σ_i (∂q̇_i/∂q_i + ∂ṗ_i/∂p_i)
= Σ_i (∂²H/∂q_i ∂p_i − ∂²H/∂p_i ∂q_i) = 0

by equality of mixed partials. So Hamiltonian flow is divergence-free — the flow is incompressible in phase space. This rules out attractors: two trajectories that start at distinct points in phase space remain at distinct points forever, with the same surrounding volume. It is the structural reason why Hamiltonian systems cannot exhibit dissipation. It is also the foundation of the microcanonical ensemble and the ergodic hypothesis in statistical mechanics.

Hamilton vs Lagrange vs Newton

NewtonianLagrangianHamiltonian
Variables(x, ẋ) Cartesian(q, q̇) generalized(q, p) phase space
Number of equationsn second-ordern second-order2n first-order
Central functionF (vector)L = T − VH = T + V (usually)
Symmetry → conservationManualCyclic coords / Noether{f, H} = 0
Numerical advantageNoneTidy ODEsSymplectic integrators
QuantizationNonePath integralCanonical: {·,·} → [·,·]/(iℏ)
Statistical mechanicsAwkwardAwkwardPhase-space volumes, ensembles
Chaos / KAM theoryHardHardNative (perturbed integrable systems)

The three pictures are mathematically equivalent for any system where they all apply, but each illuminates different physics. Hamiltonian mechanics is the formulation closest to the algebraic structure of quantum theory.

Hamilton-Jacobi theory

The most powerful canonical transformation maps the original Hamiltonian to zero. If H(q, p, t) + ∂S/∂t = 0 with p = ∂S/∂q, you have the Hamilton-Jacobi equation:

∂S/∂t + H(q, ∂S/∂q, t) = 0

where S is Hamilton's principal function. This is a single first-order PDE in n+1 variables that, if solved, gives the entire dynamics by simple algebra. For a free particle, S = (m·v·x − ½mv²·t) — a plane wave. For the central force problem, separation of variables in spherical coordinates gives Kepler orbits.

The Hamilton-Jacobi equation is the closest classical analogue to the Schrödinger equation. Substituting ψ = e^(iS/ℏ) into iℏ∂ψ/∂t = Ĥψ and expanding in powers of ℏ, the leading term is exactly the Hamilton-Jacobi equation. Classical mechanics is the geometric-optics limit of quantum mechanics.

Where Hamiltonian mechanics shows up

  • Molecular dynamics simulations. The LAMMPS, GROMACS, and AMBER packages used at every biophysics lab integrate Hamilton's equations with the velocity-Verlet symplectic algorithm. A typical 100,000-atom protein-water simulation runs 10⁹ steps over a microsecond of simulated time — only a symplectic integrator preserves energy well enough to make this stable. Anton, the special-purpose machine at D. E. Shaw Research, integrates Hamilton's equations at 50 μs/day for biological systems.
  • Spacecraft long-term orbit propagation. NASA's NAIF SPICE toolkit and JPL's DE440 ephemeris use symplectic integrators to predict planetary positions to millimeter precision over decades. The 10-year-long Cassini mission needed Hamiltonian formulation just to keep round-off error from accumulating into kilometer-scale trajectory drift.
  • Particle accelerator design. The LHC at CERN uses 1232 superconducting dipole magnets to guide 7 TeV protons around a 27 km ring. The single-particle dynamics is governed by a Hamiltonian in canonical (transverse position, transverse momentum) coordinates, and stability over 10⁹ revolutions requires the magnetic lattice to preserve the symplectic form of the map. KAM theory predicts which initial conditions remain bounded.
  • Plasma physics and tokamak design. Charged-particle motion in the ITER tokamak's magnetic field is Hamiltonian in guiding-center coordinates. Confinement times of 1000+ seconds are predicted by analyzing the destruction of KAM tori in a perturbed Hamiltonian.
  • Quantum computing. The time evolution of every gate-based quantum computer is governed by U = exp(−iHt/ℏ) with H the qubit Hamiltonian. Designing a CNOT gate on superconducting qubits is solving Hamilton's equations in the Heisenberg picture with control fields tuned to the desired unitary. IBM's Eagle, Google's Sycamore, and Quantinuum's H-series all describe their gate sets via explicit qubit Hamiltonians.

Canonical transformations and action-angle

For any integrable system — n constants of motion in involution — there is a canonical transformation to action-angle variables (J, θ) in which the Hamiltonian depends only on J:

H = H(J),    θ̇ = ∂H/∂J = ω(J),    J̇ = 0

The action variables Ji are constants; the angle variables θi advance linearly at frequencies ωi(J). The motion is a torus in 2n-dimensional phase space, an n-torus parametrized by the angles. Action-angle variables make the Kepler problem trivial (the action is the Delaunay variable, the angle is the mean anomaly), the harmonic oscillator trivial (J = E/ω), and the rigid body solvable.

For non-integrable systems, KAM theory tells us most action-angle tori survive small perturbations, but a Cantor-set of resonant tori breaks up, producing the chaotic regions seen in numerical Poincaré sections. KAM is why the solar system is stable on cosmological timescales despite being a perturbation of n integrable two-body problems.

Variants and extensions

  • Symplectic geometry. The 2-form ω = Σ dqi ∧ dpi is preserved by Hamiltonian flow. Phase space is a symplectic manifold, and Hamilton's equations are equivalent to the geometric statement iXω = dH for the Hamiltonian vector field X. Modern classical mechanics is differential-geometric in this sense.
  • Constrained Hamiltonian systems. Dirac's procedure for systems with primary and secondary constraints — necessary for gauge theories like electromagnetism, Yang-Mills, and general relativity. The ADM formulation of GR is a constrained Hamiltonian system on a foliation of spacetime.
  • Symplectic integrators. Numerical schemes (leapfrog, Forest-Ruth, Yoshida) that exactly preserve a nearby Hamiltonian H̃ instead of the original H. Energy error is bounded forever, not growing with t — essential for million-year astrodynamics.
  • Geometric / Liouville integrability. Arnold-Liouville theorem: a Hamiltonian system with n independent commuting integrals of motion in involution is integrable, and motion lies on n-tori. This classifies which classical systems can be solved in closed form.
  • Quantum Hamiltonian operators. H → Ĥ via canonical quantization. The spectrum of Ĥ gives the energy levels; Heisenberg's equations of motion are the quantization of Hamilton's. The Hartree-Fock and density-functional methods at the heart of modern computational chemistry are Hamiltonian-spectrum calculations.
  • Open Hamiltonian systems / Lindblad equations. When a Hamiltonian system couples to an environment, dissipation enters via a Lindblad superoperator while the closed system remains Hamiltonian. The clean factorization is essential for quantum-thermodynamics analyses of qubits in cryogenic environments.

Common pitfalls

  • Confusing canonical and kinetic momentum. In a magnetic field, the canonical momentum is p = mv + qA where A is the vector potential, not just mv. Most students substitute mv into the Hamiltonian and get a wrong result. The Hamiltonian for a charged particle in an EM field is H = (p − qA)²/(2m) + qφ.
  • Treating H as energy when it isn't. H = T + V only when T is quadratic in q̇ and the constraints are time-independent. For a bead on a uniformly rotating wire, H is conserved but ≠ T + V; energy is not conserved. Always check the assumptions.
  • Forgetting the Legendre transform. H is a function of q and p, not of q and q̇. After computing p = ∂L/∂q̇ you must invert to express q̇(p) and substitute, otherwise Hamilton's equations are inconsistent.
  • Ignoring time dependence. If H = H(q, p, t) explicitly, then dH/dt = ∂H/∂t, not zero. Energy is conserved only when H has no explicit time dependence — equivalently, when the Lagrangian does not.
  • Using a non-symplectic numerical integrator on long Hamiltonian runs. Runge-Kutta of any order accumulates secular energy drift in conservative systems. Even RK45 will eventually break a Kepler orbit. Use leapfrog, Yoshida-4, or any explicitly symplectic method for any conservative simulation that runs more than a few periods.

Frequently asked questions

Is the Hamiltonian always equal to the total energy?

Almost — but not exactly. H equals total energy T + V if two conditions hold: the kinetic energy T is a quadratic form in the velocities, and the constraints are time-independent (scleronomic). For most ordinary systems both hold, so the rule of thumb is fine. But for a bead on a wire that is itself rotating at fixed angular velocity, H is conserved (the Lagrangian has no explicit time dependence) but does not equal T + V. The Hamiltonian is the conserved generator of time evolution, which is a stronger statement than "energy."

Why do we use phase space (q, p) instead of configuration space (q, q̇)?

In configuration space (q, q̇), trajectories can cross — two systems with the same q at the same time can have different q̇. In phase space (q, p), trajectories cannot cross because Hamilton's equations are first-order and the initial point determines the full future. Phase space is also where Liouville's theorem, ergodicity, and chaos analysis live; it is the natural arena for statistical mechanics and for canonical quantization.

What is a canonical transformation?

A change of variables (q, p) → (Q, P) that preserves the form of Hamilton's equations: Q̇ = ∂K/∂P, Ṗ = −∂K/∂Q for some new Hamiltonian K. Canonical transformations are exactly those that preserve the Poisson bracket structure {Q_i, P_j} = δ_ij. They are far more general than coordinate changes — momenta and coordinates can swap roles, the system can move into action-angle coordinates, and so on. The whole edifice of Hamilton-Jacobi theory uses canonical transformations to flow into coordinates where the dynamics is trivial.

What is the Poisson bracket?

{f, g} = Σ_i (∂f/∂q_i · ∂g/∂p_i − ∂f/∂p_i · ∂g/∂q_i) for any two functions on phase space. Time evolution of any quantity f is df/dt = {f, H} + ∂f/∂t. The Poisson bracket of two conserved quantities is conserved, of two coordinates is zero, and {q_i, p_j} = δ_ij. Replace {·,·} with (1/iℏ)[·,·] and you get Heisenberg's equations of motion — Dirac's recipe for canonical quantization.

What does Liouville's theorem say?

Phase-space volume is preserved under Hamiltonian flow. If you start with a cloud of N initial conditions occupying volume V₀ in 2n-dimensional phase space, after any time t the same cloud occupies the same volume V₀ — the cloud may stretch, fold, and tangle, but its total measure is unchanged. This is why Hamiltonian systems cannot have attractors and is the foundation of statistical mechanics' microcanonical ensemble. Mathematically, it says the symplectic 2-form ω = Σ dq_i ∧ dp_i is preserved by the flow.

Why is Hamiltonian mechanics important for quantum mechanics?

Three reasons. First, the Hamiltonian H is the operator that generates time evolution in the Schrödinger equation: iℏ∂ψ/∂t = Ĥψ. Second, canonical quantization replaces Poisson brackets with commutators {q, p} = 1 → [q̂, p̂] = iℏ. Third, the energy spectrum of any quantum system is the spectrum of Ĥ. Almost every textbook quantum problem starts by writing down H, replacing q and p with operators, and solving. Hamiltonian mechanics is the algebraic skeleton that survives quantization.

What is the difference between Hamiltonian and Lagrangian formulations in practice?

Lagrangians give n second-order equations; Hamiltonians give 2n first-order equations. For numerical integration, first-order is usually preferable — symplectic integrators (leapfrog, Verlet, Forest-Ruth) preserve phase-space volume to machine precision and do not artificially gain or lose energy over million-step orbital simulations. For analytical work, Lagrangians are tidier when you only care about the equations of motion. For phase-space arguments — chaos, statistical mechanics, quantization — Hamiltonians are mandatory.