SOL-PV-001 // aprender-contracts
Yoshida-4 Symplectic Energy Conservation Contract
Machine-checkable YAML numerical contract binding orbital integrator energy drift |dE/E_0| < 1e-9 across 100 orbits.
Measured delta: 1e8x lower energy drift (< 1e-9 vs Euler 1e-1 over 100 orbits)
Before (Failing Anti-Pattern)
pub fn euler_step(x: &mut f64, v: &mut f64, a: f64, dt: f64) {
*x += *v * dt; *v += a * dt; // secular energy drift > 1e-3/orbit
}
After (Verified Code)
pub fn energy_drift(e0: f64, et: f64) -> f64 {
((et - e0) / e0.abs().max(1e-15)).abs()
}
Verification Contract
metadata:
version: "1.0.0"
kind: pattern
description: "Yoshida-4 symplectic Hamiltonian energy conservation contract"
references:
- "Yoshida (1990) Construction of higher order symplectic integrators"
equations:
energy_drift:
formula: "abs((E_t - E_0) / E_0) < 1e-9"
proof_obligations:
- id: PO-ORB-001
type: invariant
property: "Relative Hamiltonian energy drift stays below 1e-9 over 100 orbits"
falsification_tests:
- id: FALSIFY-ORB-001
rule: "symplectic_energy_bound"
prediction: "abs((E_t - E_0) / E_0) < 1e-9"
if_fails: "Integrator introduces secular energy drift"
Verified CLI Command & Output
$ pv validate contracts/orbital-yoshida4.yaml 0 error(s), 0 warning(s) — Contract is valid.