Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Part 3: Symplectic Integration - Geometry Over Accuracy

Module 3: ODE Methods & Conservation | COMP 521

Learning Objectives

By the end of this section, you will be able to:


The Fundamental Insight

Symplectic integrator: A numerical method that preserves the symplectic structure (phase space volume and geometric properties) of Hamiltonian systems.

A symplectic integrator preserves the canonical two-form, a geometric constraint stronger than volume preservation in more than one degree of freedom. It still has truncation error: geometry and accuracy are both design criteria.

  1. Symplectic maps preserve canonical phase-space volume in exact arithmetic.

  2. A symmetric method such as fixed-step leapfrog is also time reversible; symplecticity alone does not imply reversibility.

  3. Near-conservation of energy over long times needs smoothness, sufficiently small fixed steps, and a trajectory in a suitable bounded region.

  4. Stability and accurate phase still need independent checks.

These distinctions let us ask a sharper question than “does it conserve physics?”: which property is exact for the discrete map, which is approximate, and over what regime have we checked it?

Hamiltonian Mechanics Refresher

Hamiltonian: A function H(q,p,t)H(q,p,t) that represents the total energy of a system, where qq are generalized coordinates and pp are conjugate momenta.

Before diving into symplectic integration, let’s recall the Hamiltonian formulation of mechanics. For a system with positions qq and momenta pp, the Hamiltonian H(q,p,t)H(q,p,t) represents total energy:

H(q,p)=T(p)+V(q)H(q,p) = T(p) + V(q)

where T(p)T(p) is kinetic energy and V(q)V(q) is potential energy.

For a particle of mass mm in potential V(q)V(q):

H=p22m+V(q)H = \frac{p^2}{2m} + V(q)

Hamilton’s equations govern the evolution:

dqdt=∂H∂p,dpdt=−∂H∂q\boxed{\frac{dq}{dt} = \frac{\partial H}{\partial p}, \quad \frac{dp}{dt} = -\frac{\partial H}{\partial q}}

These equations have remarkable properties:

The Phase Space Perspective

Phase space: The space of all possible states of a system, with position and momentum (or velocity) as coordinates.

In phase space, each point (q,p)(q,p) represents a complete state of the system. Trajectories follow contours of constant energy H=EH = E.

Oscillator and pendulum energy contours accompany equal-area phase-space regions deformed by Hamiltonian flow.

Figure 1:Phase space structure of Hamiltonian systems. (Left) Harmonic oscillator: closed orbits on energy surfaces. (Middle) Pendulum: separatrix divides oscillation from rotation. (Right) Liouville’s theorem: phase space volume is preserved under Hamiltonian flow—areas deform but don’t change size. This geometric structure is what symplectic integrators preserve, without by itself guaranteeing numerical stability for any step size.

Open full-size figure

Liouville’s Theorem

Liouville’s theorem: The phase space volume occupied by an ensemble of states is preserved under Hamiltonian evolution.

Liouville’s theorem states that phase space volume is preserved under Hamiltonian flow. Mathematically, for a volume element dV=dq dpdV = dq\,dp:

d(dV)dt=0\frac{d(dV)}{dt} = 0

This is equivalent to saying the flow is incompressible. Standard numerical methods violate this theorem! They artificially compress or expand phase space, leading to systematic errors.

The Leapfrog/Verlet Method

The leapfrog method (also called Verlet or Störmer-Verlet) staggers position and velocity updates to preserve symplectic structure.

The Algorithm

For a Hamiltonian H(q,p)=T(p)+V(q)H(q,p) = T(p) + V(q) where T(p)=p2/(2m)T(p) = p^2/(2m):

Algorithm: Leapfrog IntegrationInput: qn,pn,h,force function F(q)=−∇V(q)Step 1 (kick):pn+1/2=pn+h2F(qn)Step 2 (drift):qn+1=qn+hmpn+1/2Step 3 (kick):pn+1=pn+1/2+h2F(qn+1)Output: qn+1,pn+1\boxed{ \begin{align} \text{Algorithm: Leapfrog Integration} \\ \hline &\text{Input: } q_n, p_n, h, \text{force function } F(q) = -\nabla V(q) \\ &\text{Step 1 (kick):} \quad p_{n+1/2} = p_n + \frac{h}{2}F(q_n) \\ &\text{Step 2 (drift):} \quad q_{n+1} = q_n + \frac{h}{m}p_{n+1/2} \\ &\text{Step 3 (kick):} \quad p_{n+1} = p_{n+1/2} + \frac{h}{2}F(q_{n+1}) \\ &\text{Output: } q_{n+1}, p_{n+1} \end{align} }

Why “Leapfrog”?

Positions and momenta “leapfrog” over each other in time:

Time:     t₀    t₁/₂    t₁    t₃/₂    t₂
          |      |      |      |      |
Position: q₀            q₁            q₂
Momentum:       p₁/₂          p₃/₂

The symplectic argument comes from composing the exact kick and drift flows, not from staggered storage alone.

Implementation tips for an orbital calculation

Proof of Symplecticity

Symplectic condition: A transformation preserves phase space structure if its Jacobian JJ satisfies JTΩJ=ΩJ^T \Omega J = \Omega where Ω=(0I−I0)\Omega = \begin{pmatrix} 0 & I \\ -I & 0 \end{pmatrix}.

A transformation is symplectic if it preserves the symplectic 2-form. We’ll prove leapfrog is symplectic by showing each sub-step preserves the symplectic structure.

Step 1: Analyze Each Sub-step

The leapfrog map can be decomposed into three shear transformations:

  1. First kick: (q,p)↦(q,p+h2F(q))(q,p) \mapsto (q, p + \frac{h}{2}F(q))

  2. Drift: (q,p)↦(q+hmp,p)(q,p) \mapsto (q + \frac{h}{m}p, p)

  3. Second kick: (q,p)↦(q,p+h2F(q))(q,p) \mapsto (q, p + \frac{h}{2}F(q))

Step 2: Show Each Shear is Symplectic

For the momentum kick (q,p)↦(q,p−h2∇V(q))(q,p) \mapsto (q, p - \frac{h}{2}\nabla V(q)):

The Jacobian is:

Jkick=(I0−h2∇2VI)J_{\text{kick}} = \begin{pmatrix} I & 0 \\ -\frac{h}{2}\nabla^2 V & I \end{pmatrix}

Verify the symplectic condition:

JTΩJ=(I−h2(∇2V)T0I)(0I−I0)(I0−h2∇2VI)J^T \Omega J = \begin{pmatrix} I & -\frac{h}{2}(\nabla^2 V)^T \\ 0 & I \end{pmatrix} \begin{pmatrix} 0 & I \\ -I & 0 \end{pmatrix} \begin{pmatrix} I & 0 \\ -\frac{h}{2}\nabla^2 V & I \end{pmatrix}
=(0I−I0)=Ω✓= \begin{pmatrix} 0 & I \\ -I & 0 \end{pmatrix} = \Omega \quad \checkmark

Similarly for the drift step.

Step 3: Composition Preserves Symplecticity

Since the composition of symplectic maps is symplectic:

Jtotal=Jkick⋅Jdrift⋅JkickJ_{\text{total}} = J_{\text{kick}} \cdot J_{\text{drift}} \cdot J_{\text{kick}}

is symplectic. Therefore, leapfrog preserves phase space structure exactly!

Volume Preservation

The determinant of each Jacobian is 1:

det⁡(J)=1\det(J) = 1

Phase space volume is exactly preserved, satisfying Liouville’s theorem.

The Modified Hamiltonian

Modified Hamiltonian: A formal nearby Hamiltonian whose flow approximates the discrete symplectic map order by order. Its series need not converge.

Backward error analysis expresses a symmetric second-order method through a formal series

H~=H+h2H2+h4H4+⋯ .\widetilde H=H+h^2H_2+h^4H_4+\cdots.

For smooth problems, a suitable truncation describes a nearby flow; under analyticity and bounded-trajectory assumptions, sufficiently small fixed steps can give near-energy conservation over very long times. This is not a theorem that every symplectic method exactly conserves some global energy for every step and every orbit. Hairer, Lubich, and Wanner’s analysis.

An exact discrete invariant we can derive

For the unit-mass oscillator H=(p2+ω2q2)/2H=(p^2+\omega^2q^2)/2, kick–drift–kick leapfrog gives

qn+1=(1−h2ω2/2)qn+hpn,q_{n+1}=(1-h^2\omega^2/2)q_n+hp_n,
pn+1=(1−h2ω2/2)pn−hω2(1−h2ω2/4)qn.p_{n+1}=(1-h^2\omega^2/2)p_n-h\omega^2(1-h^2\omega^2/4)q_n.

Substitute these into the quadratic form

Kh(q,p)=12[p2+ω2(1−h2ω2/4)q2].K_h(q,p)=\frac12\left[p^2+\omega^2(1-h^2\omega^2/4)q^2\right].

The cross terms cancel and Kh(qn+1,pn+1)=Kh(qn,pn)K_h(q_{n+1},p_{n+1})=K_h(q_n,p_n) in exact arithmetic. This is a special exact invariant of this linear map. It differs from the physical energy by

Kh−H=−h2ω4q28.K_h-H=-\frac{h^2\omega^4q^2}{8}.

When 0<∣hω∣<20<|h\omega|<2, KhK_h is positive definite, so it bounds both coordinates and the physical energy oscillates in a bounded band. At the stability boundary it loses positive definiteness; symplecticity has not disappeared, but the energy argument no longer works. This makes the step-size condition part of the explanation, rather than a footnote.

RK4 oscillator energy decays while leapfrog physical energy oscillates and its discrete quadratic invariant remains constant within rounding.

Figure 2:The oscillator at a fixed stable step separates physical energy from the leapfrog invariant KhK_h. RK4 damps this example; leapfrog preserves KhK_h up to floating-point effects. Both methods still accumulate phase error.

Open full-size figure

Higher-Order Symplectic Methods

Yoshida’s Fourth-Order Method

By composing leapfrog steps with carefully chosen timesteps, we can achieve higher-order accuracy while maintaining symplecticity. The coefficients come from solving order conditions to eliminate O(h3)O(h^3) errors.

The strange values involving 21/32^{1/3} arise from the algebraic constraints of maintaining symplecticity while achieving fourth-order accuracy:

w0=−21/32−21/3,w1=12−21/3w_0 = -\frac{2^{1/3}}{2 - 2^{1/3}}, \quad w_1 = \frac{1}{2 - 2^{1/3}}

Let ShS_h denote one whole second-order leapfrog step. Apply three steps, in order, with lengths w1hw_1h, w0hw_0h, and w1hw_1h:

Sh[4]=Sw1h∘Sw0h∘Sw1h.S_h^{[4]}=S_{w_1h}\circ S_{w_0h}\circ S_{w_1h}.

The coefficients satisfy 2w1+w0=12w_1+w_0=1 (advance by total time hh) and 2w13+w03=02w_1^3+w_0^3=0 (cancel the leading symmetric composition error). The middle substep is negative; this is appropriate only when the component flows are defined for those signed substeps.

If we expand kick–drift–kick steps and merge adjacent kicks, the four kick coefficients are w1/2,(w1+w0)/2,(w0+w1)/2,w1/2w_1/2,(w_1+w_0)/2,(w_0+w_1)/2,w_1/2, while the three drift coefficients are w1,w0,w1w_1,w_0,w_1. The four kick coefficients are not four whole-leapfrog-step lengths. Confusing these two levels loses fourth order.

Forest–Ruth and symmetric compositions

Forest–Ruth and Yoshida constructions belong to this family of fourth-order symmetric splitting methods. When comparing implementations, specify the actual kick/drift sequence: names alone do not identify the update ordering.

Compare diagnostics before choosing a method

Use the shared oscillator experiment to compare finite-time position, energy, and phase. A small bounded energy oscillation does not prove a small phase error, and higher order does not remove a method’s step-size restrictions. For an actual Kepler orbit, repeat the comparison at the required eccentricity and duration; the oscillator is a controlled benchmark, not evidence for a thousand-year Earth integration.

When to Use Symplectic Methods

Problem TypeRequirementCandidate methodWhat to verify
Conservative orbital modelLong-time dynamicsSuitable symplectic splittingEncounters, step restriction, phase, and energy error
Satellite trajectoryFinite-time position accuracyAdaptive RKPosition error over the requested duration and force-model adequacy
Collisionless galaxy modelPhase-space dynamicsSymplectic method for a compatible HamiltonianForce approximation, resolution, and conserved quantities
Conservative molecular dynamicsStatistical and dynamical observablesVerlet or another appropriate splittingFast modes, step size, and sampling of the intended observables
Dissipative systemCorrect loss or relaxationRK for non-stiff problems; implicit method when stiffPhysical decay and time-integration accuracy

Simple Example: Pendulum Dynamics

Let’s see symplectic integration in action with a nonlinear pendulum:

import numpy as np

def pendulum_leapfrog(theta0, omega0, g, L, h, n_steps):
    """
    Integrate pendulum with leapfrog
    Second-order fixed-step method; monitor energy error under refinement
    """
    theta, omega = theta0, omega0
    energies = []
    
    for _ in range(n_steps):
        # Initial energy
        E = 0.5*L**2*omega**2 - g*L*np.cos(theta)
        energies.append(E)
        
        # Leapfrog update
        omega_half = omega - 0.5*h*(g/L)*np.sin(theta)
        theta_new = theta + h*omega_half
        omega_new = omega_half - 0.5*h*(g/L)*np.sin(theta_new)
        
        theta, omega = theta_new, omega_new
    
    return energies

For a resolved fixed step, this experiment can show near-conservation beyond the small-angle limit. Repeat it with half the step and monitor the trajectory as well as energy, especially near the separatrix. Large steps need not preserve this behavior.


Bridge to Part 4: Stability Analysis

You’ve seen the profound difference between local accuracy and geometric preservation. Symplectic methods impose a geometric constraint as well as an accuracy order. Their favorable long-time energy behavior has conditions, and accurate trajectories require enough resolution.

But choosing the right integrator is only part of the challenge. We also need to understand when methods become unstable, how to diagnose problems, and what limits our timestep choices. In Part 4, we’ll analyze stability regions to predict when methods explode and understand the special challenges of stiff equations.

Next: Part 4 - Stability Analysis