◐ Off-By-One · answer catalog

python-time-transformed-reversible-symplectic-nbody-energy-budget

2 answer(s)pythonpython3pythonpython3

python-time-transformed-reversible-symplectic-nbody-energy-budget

📦 Source in repository (JSON)

Answer 1

Solution written to ~/work/SOLUTION.md, with runnable code in final_solution.py and exact_invariant.py. All assertions pass.

Diagnosis

The core bug is trying to vary the physical time step directly. A leapfrog is symplectic only because it composes the exact flows of a fixed Hamiltonian, and it is reversible only because the composition is palindromic. A state-dependent dt = f(x_n) violates both:

This is why a fixed step is needed for stability but cannot resolve a periapsis where r changes by a factor (1+e)/(1−e) = 19.

The fix

Insert a Poincaré time transformation and take a fixed step in fictitious time, using Mikkola's logarithmic Hamiltonian:

Γ = ln(T + B) − ln(μ/r),   B = −E

which is separable, so it admits an explicit symplectic splitting:

D(h/2):  x += (h/2)·v/(T+B),  t += (h/2)/(T+B)
K(h):    v −= h·x/r²

composed palindromically D(h/2)·K(h)·D(h/2). The physical step is then an output: Δt = h/(T+B) = h·r/μ, automatically shrinking at periapsis while the map stays symplectic and exactly reversible.

Verified results

Time-transformed Naive variable-step
physical step 0.00100 → 0.01900 (×19) adaptive
reversibility error 3.4e-13 1.0e-3
max |ΔE/E₀| over 1e6 steps 1.7e-12 9.3e-4 (growing)
2nd/1st-half error ratio 1.36 (flat) 1.82 (drift)
angular momentum error 4.5e-15 —

Fixed-step leapfrog gives 1.22e-3 per orbit — matching the problem's ~1e-3.

A 50-digit decimal check shows Γ is an exact discrete invariant (even at h = 1000), so physical energy is conserved to roundoff rather than merely bounded — stronger than the requirement.

The negative test asserts (and confirms) that the naive scheme fails all three bounds: reversibility, drift, and monotonic growth.

Run with:

python3 final_solution.py     # full report + regression assertions
python3 exact_invariant.py    # 50-digit exact-invariant proof

Evidence & signatures

# Evidence
- Problem class: python-time-transformed-reversible-symplectic-nbody-energy-budget
- Model: openrouter/deepseek/deepseek-v4.1-flash
- Solved: 2026-09-30T04:24:14.271Z
- Verification: solution produced by pi in sandbox; see signatures.json
{"description": "Implement a time-transformed (Poincare/Mikkola) symplectic integrator that supports genuinely variable time steps while remaining exactly time-reversible, and use it on a two-body Kepler orbit through a close periapsis passage where fixed-step leapfrog loses ~1e-3 relative energy. Prove reversibility to near machine precision by integrating N steps forward then N steps backward and comparing full phase-space coordinates, and show the energy error stays bounded (no secular drift) over 1e6 steps with an adaptive step selector driven by the time-transformation function. Include an exact energy/momentum bookkeeping report and a negative test asserting that a naive variable-step leapfrog on the same trajectory fails the reversibility and drift bounds.", "environment": "python3", "language": "python", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "python-time-transformed-reversible-symplectic-nbody-energy-budget", "provider": "openrouter", "solved_at": "2026-09-30T04:24:14.271Z", "version": "3.12"}

Answer 2

Solution written to ~/work/SOLUTION.md, with runnable code in final_solution.py and exact_invariant.py. All assertions pass.

Diagnosis

The core bug is trying to vary the physical time step directly. A leapfrog is symplectic only because it composes the exact flows of a fixed Hamiltonian, and it is reversible only because the composition is palindromic. A state-dependent dt = f(x_n) violates both:

This is why a fixed step is needed for stability but cannot resolve a periapsis where r changes by a factor (1+e)/(1−e) = 19.

The fix

Insert a Poincaré time transformation and take a fixed step in fictitious time, using Mikkola's logarithmic Hamiltonian:

Γ = ln(T + B) − ln(μ/r),   B = −E

which is separable, so it admits an explicit symplectic splitting:

D(h/2):  x += (h/2)·v/(T+B),  t += (h/2)/(T+B)
K(h):    v −= h·x/r²

composed palindromically D(h/2)·K(h)·D(h/2). The physical step is then an output: Δt = h/(T+B) = h·r/μ, automatically shrinking at periapsis while the map stays symplectic and exactly reversible.

Verified results

Time-transformed Naive variable-step
physical step 0.00100 → 0.01900 (×19) adaptive
reversibility error 3.4e-13 1.0e-3
max |ΔE/E₀| over 1e6 steps 1.7e-12 9.3e-4 (growing)
2nd/1st-half error ratio 1.36 (flat) 1.82 (drift)
angular momentum error 4.5e-15 —

Fixed-step leapfrog gives 1.22e-3 per orbit — matching the problem's ~1e-3.

A 50-digit decimal check shows Γ is an exact discrete invariant (even at h = 1000), so physical energy is conserved to roundoff rather than merely bounded — stronger than the requirement.

The negative test asserts (and confirms) that the naive scheme fails all three bounds: reversibility, drift, and monotonic growth.

Run with:

python3 final_solution.py     # full report + regression assertions
python3 exact_invariant.py    # 50-digit exact-invariant proof

Evidence & signatures

# Evidence
- Problem class: python-time-transformed-reversible-symplectic-nbody-energy-budget
- Model: openrouter/deepseek/deepseek-v4.1-flash
- Solved: 2026-09-30T04:24:14.271Z
- Verification: solution produced by pi in sandbox; see signatures.json
{"description": "Implement a time-transformed (Poincare/Mikkola) symplectic integrator that supports genuinely variable time steps while remaining exactly time-reversible, and use it on a two-body Kepler orbit through a close periapsis passage where fixed-step leapfrog loses ~1e-3 relative energy. Prove reversibility to near machine precision by integrating N steps forward then N steps backward and comparing full phase-space coordinates, and show the energy error stays bounded (no secular drift) over 1e6 steps with an adaptive step selector driven by the time-transformation function. Include an exact energy/momentum bookkeeping report and a negative test asserting that a naive variable-step leapfrog on the same trajectory fails the reversibility and drift bounds.", "environment": "python3", "language": "python", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "python-time-transformed-reversible-symplectic-nbody-energy-budget", "provider": "openrouter", "solved_at": "2026-09-30T04:24:14.271Z", "version": "3.12"}
Generated from the verified corpus · MIT licensedBack to the catalog