
# Hamiltonian Mechanics

> One more reformulation, and it is the one quantum mechanics actually quantizes. Trading velocity
> for momentum turns $n$ second-order equations into $2n$ first-order ones, makes "the state of the
> system" a single point in phase space — and equips observables with an algebraic operation, the
> Poisson bracket, which is precisely the commutator of Term 1 wearing classical fur.

## Learning Objectives

After this lesson you will be able to:

1. Compute **Legendre transforms** and construct the **Hamiltonian** $H(q,p)$ from a Lagrangian.
2. Derive and apply **Hamilton's equations**, and judge when $H = T + V$ and when $H$ equals the energy.
3. Analyze motion in **phase space**: flow, non-crossing trajectories, oscillator ellipses, and the pendulum **separatrix**.
4. Compute **Poisson brackets**, exploit their algebraic properties, and evaluate the **fundamental brackets**.
5. Write time evolution as $df/dt = \{f, H\} + \partial f/\partial t$ and detect conserved quantities via $\{f, H\} = 0$.
6. State **Dirac's canonical quantization rule** and map $\{x, p\} = 1$ to $[\hat x, \hat p] = i\hbar$.
7. Include non-conservative forces through **generalized forces**, $\dot p_i = -\partial H/\partial q_i + Q_i$, and account for every change of the Hamiltonian, $dH/dt = \partial H/\partial t + \sum_i \dot q_iQ_i$.

---

## Intuition

The Lagrangian lives on positions and velocities; to know where the system goes you still must
solve second-order equations. Hamilton's move is to promote the **momentum** to an independent
variable. The payoff is conceptual as much as computational: the complete state of the system
becomes a single *point* $(q, p)$ in **phase space**, and dynamics becomes a *flow* — every point
knows exactly where it is going next. On top of this geometry sits an algebra: the Poisson bracket
combines any two observables into a third, and time evolution, conservation laws, and symmetries
are all statements about brackets. Quantum mechanics keeps the entire structure and changes one
thing: the bracket becomes a commutator, with $\hbar$ setting the exchange rate.

---

## Theory

### The Legendre transform

For a convex function $f(x)$ (i.e. $f'' > 0$), the **Legendre transform** is

$$
g(p) = p\,x(p) - f\big(x(p)\big), \qquad \text{where } x(p) \text{ solves } p = f'(x).
$$

Since $f'$ is strictly increasing, $x(p)$ is well defined. *Geometric meaning:* the tangent to $f$
at $x$ has slope $p$ and $y$-intercept $f(x) - px = -g(p)$, so $g$ re-encodes the curve by its
family of tangent lines — slope in, intercept out, no information lost. It is involutive:
$dg/dp = x + p\,x'(p) - f'(x)\,x'(p) = x$, so transforming $g$ returns $f$. *Worked scalar
example:* $f(v) = \tfrac12 mv^2$ gives $p = mv$, $v = p/m$, and
$g(p) = p(p/m) - \tfrac12 m(p/m)^2 = p^2/2m$ — the shape of every kinetic term to come.

### Canonical momentum and the Hamiltonian

Define the **canonical momentum** conjugate to $q_i$ by $p_i = \partial L/\partial\dot q_i$ (for
$L = \tfrac12 m\dot x^2 - V$ this is $m\dot x$, but *not* always — recall the magnetic Lagrangian
from [P.1.3](03-lagrangian-mechanics.md)). The **Hamiltonian** is the Legendre transform of $L$ in
its velocity slots:

$$
H(q, p, t) = \sum_i p_i\,\dot q_i - L(q, \dot q, t),
$$

with every $\dot q_i$ eliminated in favor of $(q, p)$ by inverting $p_i = \partial L/\partial\dot q_i$.

### Hamilton's equations

Take the differential of $H$ as defined above:

$$
dH = \sum_i\Big(p_i\,d\dot q_i + \dot q_i\,dp_i
- \frac{\partial L}{\partial q_i}\,dq_i - \frac{\partial L}{\partial\dot q_i}\,d\dot q_i\Big)
- \frac{\partial L}{\partial t}\,dt .
$$

The $d\dot q_i$ terms cancel *by the definition* of $p_i$ — this is what the Legendre transform is
for. Along an actual motion, Euler–Lagrange gives $\partial L/\partial q_i = \dot p_i$, so
$dH = \sum_i(\dot q_i\,dp_i - \dot p_i\,dq_i) - (\partial L/\partial t)\,dt$. Comparing
coefficients with $dH = \sum_i\big(\tfrac{\partial H}{\partial q_i}dq_i + \tfrac{\partial H}{\partial p_i}dp_i\big) + \tfrac{\partial H}{\partial t}dt$:

$$
\boxed{\;\dot q_i = \frac{\partial H}{\partial p_i}, \qquad
\dot p_i = -\frac{\partial H}{\partial q_i}\;}
\qquad\text{and}\qquad
\frac{\partial H}{\partial t} = -\frac{\partial L}{\partial t}.
$$

**Hamilton's equations**: $2n$ first-order equations replacing $n$ second-order ones. Oscillator
check: $H = p^2/2m + \tfrac12 kx^2$ gives $\dot x = p/m$, $\dot p = -kx$ — Newton again.

### When is $H = T + V$? When is $H$ the energy?

Two *independent* facts. (i) If the map from Cartesian to generalized coordinates has no explicit
time dependence, $T$ is a homogeneous quadratic $\tfrac12\sum a_{jk}(q)\dot q_j\dot q_k$; Euler's
theorem for homogeneous functions then gives $\sum_i\dot q_i\,\partial T/\partial\dot q_i = 2T$.
With $V$ velocity-independent, $p_i = \partial T/\partial\dot q_i$, so $\sum p_i\dot q_i = 2T$ and
$H = 2T - (T - V) = T + V = E$. (ii) Independently, $dH/dt = \partial H/\partial t$ (proved
below), so $H$ is **conserved** exactly when it has no explicit time dependence. All four
combinations occur: the bead on a rotating wire (Worked Example 2) has $H$ conserved yet
$H \neq E$, because the rotating constraint makes the coordinate map time-dependent.

> **Caution.** $H \neq E$ whenever constraints (or the coordinates) are time-dependent — do not
> read "the Hamiltonian" reflexively as "the energy". And beware a notational ambush ahead: in
> this program $H$ is the Hamiltonian *here*, but the **Hadamard gate** in quantum-circuit
> contexts — [Appendix C](../../appendix/C-notation-glossary.md) flags the clash. Context decides.

### Non-conservative forces: how $H$ leaks

Everything so far assumed that every force lives inside $L$. Friction, drag and external pushes that
derive from no potential enter instead through the *generalized forces* of
[P.1.3](03-lagrangian-mechanics.md): keep the conservative part in $L = T - V$ and collect the rest in
$Q_i = \sum_a\mathbf F_a^{(\text{nc})}\cdot\partial\mathbf r_a/\partial q_i$. Lagrange's equations
become $\frac{d}{dt}\frac{\partial L}{\partial\dot q_i} - \frac{\partial L}{\partial q_i} = Q_i$, and
repeating the $dH$ derivation with $\partial L/\partial q_i = \dot p_i - Q_i$ gives

$$
\dot q_i = \frac{\partial H}{\partial p_i}, \qquad
\dot p_i = -\frac{\partial H}{\partial q_i} + Q_i .
$$

Feed these into the chain rule:

$$
\frac{dH}{dt}
= \sum_i\Big(\frac{\partial H}{\partial q_i}\dot q_i + \frac{\partial H}{\partial p_i}\dot p_i\Big) + \frac{\partial H}{\partial t}
= \sum_i\Big[\frac{\partial H}{\partial q_i}\frac{\partial H}{\partial p_i}
+ \frac{\partial H}{\partial p_i}\Big(Q_i - \frac{\partial H}{\partial q_i}\Big)\Big] + \frac{\partial H}{\partial t}
\quad\Longrightarrow\quad
\boxed{\;\frac{dH}{dt} = \frac{\partial H}{\partial t} + \sum_i\dot q_i\,Q_i\;}
$$

A Hamiltonian can change for exactly two reasons: it depends on time explicitly, or non-conservative
forces deliver power $\sum_i\dot q_iQ_i$. When $H = T + V$, the second term is the rate at which those
forces do work, the work–energy theorem in generalized coordinates. Example: a damped oscillator with
drag $F = -b\dot x$ has $Q = -b\dot x$, so $dH/dt = -b\dot x^2 \le 0$, and the energy drains at
exactly the rate drag does work. Linear drag is common enough to have a shorthand: with *Rayleigh's
dissipation function* $\mathcal F = \tfrac12\sum_i b_i\dot q_i^2$, $Q_i = -\partial\mathcal F/\partial\dot q_i$
and $dH/dt = -2\mathcal F$ ([Gold] §1.5). The same drag, written $\dot p = \dots - \gamma p$ with
$\gamma = b/m$, is what shrinks phase-space areas in the Liouville paragraph below. A driving force can
be booked either way, as a $Q$ or as a time-dependent potential; E6 shows the two bookkeepings agree.

### Phase space

The state of the system is the point $(q, p) \in \mathbb{R}^{2n}$ — **phase space**. Hamilton's
equations attach a velocity vector to every point, defining a **flow**; by uniqueness of ODE
solutions, exactly one trajectory passes through each point, so **trajectories never cross**. For
the oscillator, $H = p^2/2m + \tfrac12 m\omega^2q^2 = E$ traces an **ellipse** with semi-axes
$q_{\max} = \sqrt{2E/m\omega^2}$ and $p_{\max} = \sqrt{2mE}$, of area

$$
\pi\,q_{\max}\,p_{\max} = \frac{2\pi E}{\omega}.
$$

Phase-space area carries units of *action* (J·s). The old quantum theory (P.2.3) will quantize
exactly this area in units of Planck's constant — nature slices phase space into cells of size
$2\pi\hbar$.

Area is also what the flow itself respects. Follow not one state but a small region of them: the
flow may stretch and fold it, yet its area never changes. This is **Liouville's theorem** — in $2n$
dimensions, the flow preserves phase-space volume, so a density of states carried along is
constant. The reason is that the velocity field
$(\dot q, \dot p) = (\partial H/\partial p, -\partial H/\partial q)$ has zero divergence,
$\partial^2 H/\partial q\,\partial p - \partial^2 H/\partial p\,\partial q = 0$. Friction adds $-\gamma p$ to $\dot p$, the divergence
becomes $-\gamma$, and areas shrink as $e^{-\gamma t}$.

```qm-demo phase-space-flow

```

### Poisson brackets

For two observables $f(q, p)$, $g(q, p)$ define the **Poisson bracket**

$$
\{f, g\} = \sum_i\left(\frac{\partial f}{\partial q_i}\frac{\partial g}{\partial p_i}
- \frac{\partial f}{\partial p_i}\frac{\partial g}{\partial q_i}\right).
$$

Its algebra: **antisymmetry** $\{f, g\} = -\{g, f\}$ (swap the two terms) and **bilinearity** in
each slot (derivatives are linear) are immediate. The **Leibniz/product rule**
$\{fg, h\} = f\{g, h\} + g\{f, h\}$ follows by direct computation: since
$\partial(fg)/\partial q_i = f\,\partial g/\partial q_i + g\,\partial f/\partial q_i$ (same for $p_i$),

$$
\{fg, h\} = \sum_i\big[(f g_{q_i} + g f_{q_i})h_{p_i} - (f g_{p_i} + g f_{p_i})h_{q_i}\big]
= f\{g, h\} + g\{f, h\}. \checkmark
$$

Finally the **Jacobi identity** $\{f, \{g, h\}\} + \{g, \{h, f\}\} + \{h, \{f, g\}\} = 0$ holds
(a patient expansion of second derivatives; you verify an instance in E4). The **fundamental
brackets** follow from $\partial q_i/\partial q_k = \delta_{ik}$ etc.:

$$
\{q_i, q_j\} = 0, \qquad \{p_i, p_j\} = 0, \qquad
\{q_i, p_j\} = \sum_k \delta_{ik}\delta_{jk} = \delta_{ij}.
$$

### Time evolution is a bracket

Let $f(q, p, t)$ be any observable, evaluated along a trajectory. Chain rule plus Hamilton's
equations:

$$
\frac{df}{dt}
= \sum_i\Big(\frac{\partial f}{\partial q_i}\dot q_i + \frac{\partial f}{\partial p_i}\dot p_i\Big) + \frac{\partial f}{\partial t}
= \sum_i\Big(\frac{\partial f}{\partial q_i}\frac{\partial H}{\partial p_i}
- \frac{\partial f}{\partial p_i}\frac{\partial H}{\partial q_i}\Big) + \frac{\partial f}{\partial t}
= \{f, H\} + \frac{\partial f}{\partial t}.
$$

The Hamiltonian *generates* time evolution. Special cases: $\dot q = \{q, H\}$ and
$\dot p = \{p, H\}$ reproduce Hamilton's equations;
$dH/dt = \{H, H\} + \partial H/\partial t = \partial H/\partial t$ (antisymmetry kills $\{H,H\}$), proving the conservation claim above. And
for any time-independent observable,

$$
f \text{ is conserved} \iff \{f, H\} = 0 .
$$

### The angular momentum algebra

With $\mathbf L = \mathbf r \times \mathbf p$: $L_x = yp_z - zp_y$, $L_y = zp_x - xp_z$,
$L_z = xp_y - yp_x$. Compute $\{L_x, L_y\}$ by summing over $(x, y, z)$; the only nonvanishing
partials of $L_x$ are $\partial_y L_x = p_z$, $\partial_z L_x = -p_y$, $\partial_{p_y}L_x = -z$,
$\partial_{p_z}L_x = y$, and of $L_y$: $\partial_x L_y = -p_z$, $\partial_z L_y = p_x$,
$\partial_{p_x}L_y = z$, $\partial_{p_z}L_y = -x$. Term by term ($x$-, $y$-, $z$-slots):

$$
\{L_x, L_y\}
= \underbrace{(0)(z) - (0)(-p_z)}_{x}
+ \underbrace{(p_z)(0) - (-z)(0)}_{y}
+ \underbrace{(-p_y)(-x) - (y)(p_x)}_{z}
= xp_y - yp_x = L_z .
$$

Cyclically, $\{L_y, L_z\} = L_x$ and $\{L_z, L_x\} = L_y$ (E5). This closed algebra — computed
here with nothing but calculus — will single-handedly determine the quantum theory of angular
momentum in [P.6.1](../c06-angular-momentum/01-central-potentials-angular-momentum.md).

### Dirac's rule: the classical shadow of the commutator

Here is the headline. In 1925 Dirac observed that the Poisson bracket's algebra — antisymmetry,
bilinearity, Leibniz rule, Jacobi identity — is *exactly* the algebra of the operator
**commutator** $[\hat A, \hat B] = \hat A\hat B - \hat B\hat A$. **Canonical quantization**
promotes phase-space functions to operators and postulates the correspondence

$$
\{\,\cdot\,,\,\cdot\,\} \;\longrightarrow\; \frac{1}{i\hbar}\,[\,\cdot\,,\,\cdot\,] .
$$

The consequences land one for one. The fundamental bracket $\{x, p\} = 1$ becomes the canonical
commutation relation $[\hat x, \hat p] = i\hbar$ — the single equation from which position–momentum
uncertainty follows via the Robertson relation
([1.3.2](../../term-1-quantum-mechanics/c03-measurement/02-expectation-uncertainty.md)). The
evolution law $df/dt = \{f, H\}$ becomes $d\hat A/dt = \tfrac{1}{i\hbar}[\hat A, \hat H]$,
equivalently $i\hbar\,\tfrac{d}{dt}\lvert\psi\rangle = \hat H\lvert\psi\rangle$ — the Evolution
Postulate ([1.1.3](../../term-1-quantum-mechanics/c01-postulates/03-evolution-postulate.md)), with
the Hamiltonian still the generator of time translation. And $\{L_x, L_y\} = L_z$ becomes
$[\hat L_x, \hat L_y] = i\hbar\hat L_z$, fixing the entire quantum angular momentum spectrum before
any differential equation is solved. The Poisson bracket is the **classical shadow of the
commutator**: everything you computed in this lesson survives quantization with
$\{\cdot,\cdot\} \mapsto [\cdot,\cdot]/i\hbar$, and classical mechanics is recovered as the
$\hbar \to 0$ limit of the commutator algebra.

---

## Worked Examples

### Example 1 — The oscillator in phase space, with numbers

A mass $m = 0.500$ kg on a spring $k = 200$ N/m: $\omega = \sqrt{k/m} = 20.0$ rad/s. Legendre:
$p = m\dot x$, so $H = p^2/2m + \tfrac12 kx^2$ (here $H = T + V = E$: time-independent everything).
At $E = 1.00$ J the trajectory is the ellipse with $x_{\max} = \sqrt{2E/k} = 0.100$ m and
$p_{\max} = \sqrt{2mE} = 1.00$ kg·m/s, traversed clockwise once per period $2\pi/\omega = 0.314$ s.
Enclosed area: $\pi x_{\max}p_{\max} = 0.314$ J·s $= 2\pi E/\omega$ ✓ — energy and enclosed action
are proportional, with $\omega$ the conversion factor.

### Example 2 — $H$ conserved, yet not the energy

The bead on a wire rotating at constant $\Omega$ ([P.1.3](03-lagrangian-mechanics.md), Example 2):
$L = \tfrac12 m(\dot r^2 + \Omega^2r^2)$, so $p_r = m\dot r$ and

$$
H = p_r\dot r - L = \tfrac12 m\dot r^2 - \tfrac12 m\Omega^2r^2
= \frac{p_r^2}{2m} - \tfrac12 m\Omega^2r^2 .
$$

No explicit $t$, so $H$ is **conserved**. But the energy is
$E = T = \tfrac12 m(\dot r^2 + \Omega^2r^2) = H + m\Omega^2r^2$, which *grows* as the bead flies outward — the motor does work.
The culprit: the time-dependent constraint makes $T$ non-homogeneous in $\dot r$ (it has a
velocity-independent piece $\tfrac12 m\Omega^2 r^2$), so the Euler's-theorem step fails and
$H \neq T + V$. Conserved Hamiltonian, non-conserved energy — the two notions genuinely split.
Both, plotted for the running bead:

```qm-demo h-vs-energy

```

### Example 3 — A central force in phase space

A particle of mass $m$ moves in a plane under a central potential $V(r)$. From the Lagrangian of
[P.1.3](03-lagrangian-mechanics.md), $L = \tfrac12 m(\dot r^2 + r^2\dot\theta^2) - V(r)$, the
canonical momenta are $p_r = m\dot r$ and $p_\theta = mr^2\dot\theta$, so $\dot r = p_r/m$ and
$\dot\theta = p_\theta/mr^2$. The Legendre transform gives

$$
H = p_r\dot r + p_\theta\dot\theta - L
= \frac{p_r^2}{m} + \frac{p_\theta^2}{mr^2} - \Big[\frac{p_r^2}{2m} + \frac{p_\theta^2}{2mr^2} - V(r)\Big]
= \frac{p_r^2}{2m} + \frac{p_\theta^2}{2mr^2} + V(r),
$$

which is $T + V$, as it must be for a scleronomic system. Hamilton's four equations:

$$
\dot r = \frac{p_r}{m}, \qquad
\dot\theta = \frac{p_\theta}{mr^2}, \qquad
\dot p_r = \frac{p_\theta^2}{mr^3} - V'(r), \qquad
\dot p_\theta = -\frac{\partial H}{\partial\theta} = 0 .
$$

The last says $\theta$ is cyclic and $p_\theta$, the angular momentum, is a constant. Fix its value
and the radial pair $(r, p_r)$ is a one-dimensional problem with

$$
H = \frac{p_r^2}{2m} + V_{\text{eff}}(r), \qquad V_{\text{eff}}(r) = V(r) + \frac{p_\theta^2}{2mr^2} ,
$$

the **effective potential**: the true potential plus a repulsive **centrifugal barrier**. Circular
orbits sit where $\dot p_r = 0$, at the minimum of $V_{\text{eff}}$. For the attractive Coulomb
potential $V = -k/r$ that means $p_\theta^2/mr_0^3 = k/r_0^2$, i.e. $r_0 = p_\theta^2/mk$. Put in
hydrogen's $k = e^2/4\pi\varepsilon_0$ and an angular momentum of one $\hbar$, and
$r_0 = 4\pi\varepsilon_0\hbar^2/me^2 = 0.529$ Å: Bohr's first orbit (P.2.2) is the bottom of this
well. The same reduction returns in quantum mechanics as the radial equation of
[P.6.2](../c06-angular-momentum/02-radial-equation-hydrogen.md), where the barrier becomes
$\hbar^2\ell(\ell+1)/2mr^2$.

---

## Hands-on (Python)

```python
import numpy as np
import matplotlib.pyplot as plt

# --- Phase portraits: oscillator ellipses and the pendulum separatrix ---
m, ell, g = 1.0, 1.0, 9.81
w = np.sqrt(g/ell)

fig, ax = plt.subplots(1, 2, figsize=(11, 4))
q, p = np.meshgrid(np.linspace(-2, 2, 300), np.linspace(-2, 2, 300))
ax[0].contour(q, p, p**2/(2*m) + 0.5*m*w**2*q**2, levels=10)
ax[0].set(title="Oscillator: H contours are ellipses", xlabel="q", ylabel="p")

th, pth = np.meshgrid(np.linspace(-2*np.pi, 2*np.pi, 600), np.linspace(-8, 8, 400))
H_pen = pth**2/(2*m*ell**2) - m*g*ell*np.cos(th)
ax[1].contour(th, pth, H_pen, levels=20)
ax[1].contour(th, pth, H_pen, levels=[m*g*ell], colors="r", linewidths=2)
ax[1].set(title="Pendulum: red = separatrix (E = mgl)", xlabel="theta", ylabel="p")
plt.tight_layout(); plt.show()
# Expected: nested ellipses (left). Right: closed curves (libration) inside the
# red separatrix through (+-pi, 0), open wavy curves (full rotation) outside --
# the separatrix is the trajectory that takes infinite time to reach the top.
```

```python
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp

# --- Energy drift over 100 periods: explicit vs symplectic Euler vs RK45 ---
# Oscillator with m = w = 1, (q0, p0) = (1, 0), E0 = 1/2.
dt = 0.05
steps = int(100*2*np.pi/dt)
E = lambda q, p: 0.5*(p**2 + q**2)

q_e = np.empty(steps + 1); p_e = q_e.copy(); q_e[0], p_e[0] = 1.0, 0.0
q_s = q_e.copy(); p_s = p_e.copy()
for i in range(steps):
    # explicit Euler: both updates from the OLD state
    q_e[i+1] = q_e[i] + dt*p_e[i];  p_e[i+1] = p_e[i] - dt*q_e[i]
    # symplectic Euler: momentum first, then position with the NEW momentum
    p_s[i+1] = p_s[i] - dt*q_s[i];  q_s[i+1] = q_s[i] + dt*p_s[i+1]

t = np.arange(steps + 1)*dt
sol = solve_ivp(lambda t, y: [y[1], -y[0]], (0, t[-1]), [1.0, 0.0],
                t_eval=t, rtol=1e-8, atol=1e-10)          # RK45 by default

for qq, pp, lab in [(q_e, p_e, "explicit Euler"), (q_s, p_s, "symplectic Euler"),
                    (sol.y[0], sol.y[1], "RK45")]:
    plt.semilogy(t, np.abs(E(qq, pp)/0.5 - 1) + 1e-16, label=lab)
plt.xlabel("t"); plt.ylabel("|E/E0 - 1|"); plt.legend(); plt.show()
# Expected: explicit Euler's energy error grows EXPONENTIALLY (each step
# multiplies E by 1 + dt^2); symplectic Euler's stays bounded ~ dt forever;
# RK45 is tiny but drifts secularly. The symplectic update respects the
# phase-space (bracket) structure -- geometry beats raw accuracy.
```

---

## Exercises

**E1 (easy).** Compute the Legendre transform of $f(v) = av^4$ ($a > 0$, $v > 0$).

<details><summary>Solution</summary>

$p = f'(v) = 4av^3 \Rightarrow v = (p/4a)^{1/3}$. Then
$g(p) = pv - f = p(p/4a)^{1/3} - a(p/4a)^{4/3} = \big(p - \tfrac{p}{4}\big)(p/4a)^{1/3} = \tfrac{3p}{4}\big(\tfrac{p}{4a}\big)^{1/3} \propto p^{4/3}$.
Check: $g'(p) = (p/4a)^{1/3} = v$ ✓
(the involution property).
</details>

**E2 (easy).** Construct $H$ for a projectile, $L = \tfrac12 m(\dot x^2 + \dot y^2) - mgy$, write
Hamilton's equations, and identify the conserved momentum.

<details><summary>Solution</summary>

$p_x = m\dot x$, $p_y = m\dot y$, so $H = (p_x^2 + p_y^2)/2m + mgy$. Equations: $\dot x = p_x/m$,
$\dot y = p_y/m$, $\dot p_x = 0$, $\dot p_y = -mg$. Since $x$ is absent from $H$, $p_x$ is
conserved — equivalently $\{p_x, H\} = 0$.
</details>

**E3 (medium).** For a central potential, $H = \dfrac{p_r^2}{2m} + \dfrac{p_\theta^2}{2mr^2} + V(r)$.
Show $\{p_\theta, H\} = 0$ and interpret.

<details><summary>Solution</summary>

$\{p_\theta, H\} = \sum_{i\in\{r,\theta\}}\big(\partial_{q_i}p_\theta\,\partial_{p_i}H - \partial_{p_i}p_\theta\,\partial_{q_i}H\big)$.
All partials of $p_\theta$ vanish except
$\partial p_\theta/\partial p_\theta = 1$, leaving $\{p_\theta, H\} = -\partial H/\partial\theta = 0$
since $\theta$ is absent from $H$. Angular momentum is conserved because the Hamiltonian is
rotationally symmetric — the bracket version of the cyclic-coordinate argument, and the classical
seed of $[\hat L_z, \hat H] = 0$ in
[P.6.1](../c06-angular-momentum/01-central-potentials-angular-momentum.md).
</details>

**E4 (medium).** Verify the Jacobi identity for $f = x^2$, $g = p^2$, $h = xp$ (one particle, 1D).

<details><summary>Solution</summary>

Inner brackets: $\{p^2, xp\} = 0\cdot x - 2p\cdot p = -2p^2$; $\{xp, x^2\} = p\cdot0 - x\cdot2x = -2x^2$;
$\{x^2, p^2\} = 2x\cdot2p - 0 = 4xp$. Then
$\{x^2, -2p^2\} = -2(4xp) = -8xp$; $\{p^2, -2x^2\} = -2\{p^2, x^2\} = -2(-4xp) = +8xp$;
$\{xp, 4xp\} = 0$. Sum: $-8xp + 8xp + 0 = 0$ ✓.
</details>

**E5 (hard).** Show $\{L_y, L_z\} = L_x$ and $\{L_z, L_x\} = L_y$, then prove $\{L^2, L_z\} = 0$
for $L^2 = L_x^2 + L_y^2 + L_z^2$. What does this mean physically?

<details><summary>Solution</summary>

The theory computation gave $\{L_x, L_y\} = L_z$; the relabeling $x \to y \to z \to x$ maps
$\mathbf L$'s components into each other and leaves the bracket's structure invariant, so
$\{L_y, L_z\} = L_x$ and $\{L_z, L_x\} = L_y$ (or repeat the six-term computation). Compactly,
$\{L_i, L_j\} = \epsilon_{ijk}L_k$. By Leibniz and antisymmetry:
$\{L_x^2, L_z\} = 2L_x\{L_x, L_z\} = -2L_xL_y$, $\{L_y^2, L_z\} = 2L_y\{L_y, L_z\} = +2L_yL_x$,
and $\{L_z^2, L_z\} = 0$; the sum vanishes. So $L^2$ is invariant under the rotations any $L_i$
generates: the *magnitude* of angular momentum is compatible with any one component. Quantum
translation: $[\hat L^2, \hat L_z] = 0$, which is why states carry the simultaneous quantum
numbers $\ell$ and $m$ ([P.6.1](../c06-angular-momentum/01-central-potentials-angular-momentum.md)).
</details>

**E6 (medium).** A damped oscillator is driven by an external force:
$m\ddot x = -kx - b\dot x + F_0\cos\Omega t$. (a) Keep only the spring in $L$ and treat drag and drive
as generalized forces; with $H_0 = p^2/2m + \tfrac12kx^2$, find $dH_0/dt$. (b) Now put the drive into
the Lagrangian as the time-dependent potential $-xF_0\cos\Omega t$, keeping only drag as a generalized
force. Find the new Hamiltonian $H_1$ and $dH_1/dt$. Reconcile (a) and (b).

<details><summary>Solution</summary>

(a) $Q = -b\dot x + F_0\cos\Omega t$ and $\partial H_0/\partial t = 0$, so
$dH_0/dt = \dot xQ = -b\dot x^2 + F_0\dot x\cos\Omega t$: drag drains energy, the drive feeds it.
(b) $L_1 = \tfrac12m\dot x^2 - \tfrac12kx^2 + xF_0\cos\Omega t$, $p = m\dot x$, so
$H_1 = H_0 - xF_0\cos\Omega t$. Now $\partial H_1/\partial t = xF_0\Omega\sin\Omega t$ and
$Q = -b\dot x$, giving $dH_1/dt = xF_0\Omega\sin\Omega t - b\dot x^2$.
Reconcile by differentiating $H_1 = H_0 - xF_0\cos\Omega t$ directly:
$dH_1/dt = dH_0/dt - \dot xF_0\cos\Omega t + xF_0\Omega\sin\Omega t$, and substituting (a) gives
(b) ✓. The motion is identical; only the bookkeeping differs. $H_0$ is the oscillator's own energy,
while $H_1$ also contains its interaction energy with the driver, which changes because the driver's
potential depends on time.
</details>

---

## Checkpoint

1. Define the Legendre transform and give its geometric meaning.
2. Derive Hamilton's equations from $dH$: which terms cancel by construction, and where is Euler–Lagrange used?
3. State the separate conditions for $H = T + V$ and for $H$ conserved, with an example where they come apart.
4. List the four algebraic properties of the Poisson bracket and the fundamental brackets.
5. State Dirac's quantization rule. What do $\{x, p\} = 1$ and $df/dt = \{f, H\}$ become?
6. Name the two ways a Hamiltonian can change in time, and say what the second one means physically.

<details><summary>Answers</summary>

1. $g(p) = px(p) - f(x(p))$ with $p = f'(x)$; it describes the convex curve by its tangent lines
   (slope $\to$ intercept), losing no information, and is involutive.
2. In $dH = \sum(p\,d\dot q + \dot q\,dp - L_q\,dq - L_{\dot q}\,d\dot q) - L_t\,dt$ the $d\dot q$
   terms cancel because $p \equiv \partial L/\partial\dot q$; Euler–Lagrange converts $L_q$ to
   $\dot p$; matching coefficients of $dq, dp$ gives $\dot q = H_p$, $\dot p = -H_q$.
3. $H = T + V$ needs a time-independent coordinate map (so $T$ is homogeneous quadratic) and
   velocity-independent $V$; $H$ is conserved iff $\partial H/\partial t = 0$. Bead on a rotating
   wire: $H$ conserved but $H = E - m\Omega^2r^2 \neq E$.
4. Antisymmetry, bilinearity, Leibniz product rule, Jacobi identity;
   $\{q_i, q_j\} = \{p_i, p_j\} = 0$, $\{q_i, p_j\} = \delta_{ij}$.
5. $\{\cdot,\cdot\} \to [\cdot,\cdot]/i\hbar$. Then $\{x,p\} = 1 \to [\hat x, \hat p] = i\hbar$,
   and $df/dt = \{f, H\} \to d\hat A/dt = [\hat A, \hat H]/i\hbar$ — quantum time evolution,
   equivalently $i\hbar\,d\lvert\psi\rangle/dt = \hat H\lvert\psi\rangle$
   ([1.1.3](../../term-1-quantum-mechanics/c01-postulates/03-evolution-postulate.md)).
6. $dH/dt = \partial H/\partial t + \sum_i\dot q_iQ_i$: explicit time dependence, and power delivered
   by non-conservative generalized forces. When $H = T + V$ the second term is the work–energy
   theorem: energy changes exactly by the work friction, drag or a drive does.

</details>

---

## Further Reading

- **[Gold]** Goldstein, Poole & Safko, Ch. 8 and §9.5 — Hamilton's equations; Poisson brackets and canonical invariants.
- **[Sha]** Shankar, Ch. 2 — the Hamiltonian formulation, compact and aimed squarely at quantization.
- **[Sak]** Sakurai & Napolitano, §1.6 — canonical commutation relations and Dirac's analogy, up close.

---

← Prev: [Lagrangian Mechanics](03-lagrangian-mechanics.md) · Up: [Pre-Term](../README.md) · Next: [Blackbody Radiation & Planck's Law](../c02-radiation-old-quantum/01-blackbody-radiation.md) →
