Demonstrating mathematical integrity under GPU parallelization and reduced precision.
This document explains the mathematical foundations and numerical methods implemented in this project, with a focus on:
The goal is to simulate nonlinear dynamical systems faithfully over long time horizons, where naive high-accuracy methods often fail.
The system evolves in a 4-dimensional phase space:
[ (q, p) = (x, y, p_x, p_y) ]

This shows the trajectory in configuration space ((x, y)). For chaotic regimes, the trajectory explores complex regions of phase space.
The total energy of the system is:
[ H(x,y,p_x,p_y) = T(p) + V(x,y) ]
with:
Kinetic energy: [ T = \frac{1}{2}(p_x^2 + p_y^2) ]
Potential energy (Hénon–Heiles): [ V(x,y) = \frac{1}{2}(x^2 + y^2) + x^2 y - \frac{1}{3} y^3 ]
Hamilton’s equations:
[ \dot{x} = p_x, \quad \dot{y} = p_y ] [ \dot{p}_x = -\frac{\partial V}{\partial x}, \quad \dot{p}_y = -\frac{\partial V}{\partial y} ]
[ \frac{\partial V}{\partial x} = x + 2xy ] [ \frac{\partial V}{\partial y} = y + x^2 - y^2 ]
These are computed in the CUDA device function:
compute_gradients(x, y, grad_x, grad_y)
Hamiltonian systems have special structure:
p
↑
│ trajectories follow level sets of H
│ ⟲ ⟲ ⟲
│ ⟲ ⟲ ⟲
│ ⟲
└──────────────→ q
Standard methods (e.g., RK4):
Result:

The symplectic integrator preserves energy up to bounded oscillations, demonstrating long-term stability.
The symplectic method splits updates into half-step momentum and full-step position:
[ p_{n+1/2} = p_n - \frac{\Delta t}{2} \nabla V(q_n) ]
[ q_{n+1} = q_n + \Delta t , p_{n+1/2} ]
[ p_{n+1} = p_{n+1/2} - \frac{\Delta t}{2} \nabla V(q_{n+1}) ]
Instead of approximating the trajectory directly, we approximate the flow map:
Step splitting:
[Kick] → [Drift] → [Kick]
p ----> p_half ----> p_next
\ |
\ |
\ v
q --------> q_next
Symplectic integrators preserve:
Instead of drifting:
Energy vs Time (Symplectic)
E
│ ~~~~~~~~
│ ~ ~
│ ~ ~
│~ ~
└────────────── t
Energy error is:
[ H(t) = H(0) + \mathcal{O}(\Delta t^2) ]
but remains bounded.
| Method | Order | Symplectic | Energy Behavior | Long-Term Stability |
|---|---|---|---|---|
| Euler | 1 | ❌ | Diverges | ❌ |
| RK4 | 4 | ❌ | Drifts slowly | ❌ |
| Leapfrog | 2 | ✅ | Oscillatory, bounded | ✅ |
Each trajectory evolves independently:
[ z_i(t) \rightarrow z_i(t + \Delta t) ]
Thread i → trajectory i
(x[i], y[i], px[i], py[i])
Structure of Arrays (SoA):
x: [x0 x1 x2 x3 ...]
y: [y0 y1 y2 y3 ...]
px: [p0 p1 p2 p3 ...]
py: [p0 p1 p2 p3 ...]
Benefits:
integrator_kernel<<<grid, block>>>(...)
Each thread performs:
for step in time:
symplectic_update()
Energy is computed as:
[ E_i = \frac{1}{2}(p_x^2 + p_y^2) + V(x,y) ]
Used for:
High-order accuracy is not enough for physical simulation.
This project demonstrates:
Hamiltonian System
↓
Equations of Motion
↓
Discretization Choice
↓
┌───────────────┬─────────────────┐
│ Standard ODE │ Symplectic │
│ Methods │ Integrators │
├───────────────┼─────────────────┤
│ RK4 │ Leapfrog │
│ High accuracy │ Structure-pres. │
│ Energy drift │ Energy bounded │
└───────────────┴─────────────────┘
↓
GPU Parallel Execution
↓
Millions of trajectories
This codebase is a compact example of a deep principle:
Preserving mathematical structure is often more important than minimizing numerical error.
This is especially true in: