Gravitation

A step that must not be adapted

A symplectic integrator's bounded energy error is a property of a fixed step. It is conserving a Hamiltonian a step-size away from the intended one, and changing the step changes which Hamiltonian — so refining the step at a close encounter, which is the first thing anybody does, destroys the only property the method was chosen for.

Assumes Numerical integration, Chaos and Universal variables.

The rung below set two integrators against each other on the same orbit and found the ranking inverted from what accuracy would suggest. Runge–Kutta is far the more accurate method and its energy error grows steadily; leapfrog is cruder and its energy error oscillates inside a band and stays there. Over five billion years only one of those properties survives contact with the problem.

The band has a condition attached, and it is not the one anybody expects. It is not a condition on how small the step is. It is a condition that the step be the same at every step, and it is broken by the single most natural thing a person writing an integrator does: refining the step where the orbit is moving fast.

The adaptive step starts 5.7× more accurate and ends 7.5× worse. The envelope of the relative energy error against elapsed revolutions — the worst error within each plotted interval rather than the error at one sample in it — for the same second-order symplectic integrator run two ways on a Kepler orbit at e = 0.5. The flat band is a fixed step of one 200th of a period: its error oscillates once per revolution and the envelope does not grow, because a symplectic method at constant h is the exact solution of a nearby Hamiltonian and is conserving that one. The rising curve is the same method with the step refined where the orbit is fast — h ∝ r^3/2, the free-fall time, varying by a factor of 5 around the orbit — which is the first thing anybody reaches for at a close encounter and which is strictly more accurate step for step: over its first three revolutions it stays a factor of 5.7 below the fixed run. By 1500 revolutions it is a factor of 7.5 above it and still climbing. Changing the step changes which Hamiltonian is being conserved, the errors from successive steps stop cancelling, and what is left is a random walk with no bound at all. The practical consequence is that a solar-system integration cannot adapt its step: it either keeps a step short enough for the closest encounter it will ever meet, or it detects the encounter and hands that piece of the trajectory to an entirely different, non-symplectic method for the duration — which is what every long-term integration of the planets actually does.
Fig. 1 The same integrator, run two ways on the same orbit. The flat band is a fixed step of one two-hundredth of a period; the rising curve is that same method with the step refined where the body is moving fast, which over its first three revolutions is nearly six times more accurate. By fifteen hundred revolutions it is seven times worse and still climbing. Nothing about the method has changed. Only the step has, and the step was the thing the guarantee was about.

What the guarantee actually is

A symplectic integrator does not conserve energy. It is worth saying that plainly, because the bounded band in the figure looks exactly like conservation and is not.

What it does is conserve something else. For a system with Hamiltonian HH and a fixed step hh, the map the integrator applies is — to all orders that matter — the exact time-hh flow of a different Hamiltonian,

H~=H+h2H2+h4H4+,\tilde H = H + h^2 H_2 + h^4 H_4 + \dots,

called the shadow Hamiltonian. The numerical trajectory is not an approximation to the true one; it is an exact solution of a nearby problem. And exact solutions conserve their own energy exactly.

So the measured energy error is the difference between HH and H~\tilde H evaluated along the trajectory. That difference is a smooth function of position and momentum, of size h2h^2, and it therefore oscillates as the body goes round its orbit and returns to the same value when the body returns. It does not grow, because there is nothing for it to grow out of.

Energy error over 240 revolutions, at one step size. The relative error in total energy against revolution number, for three integrators run on the same Kepler orbit at e = 0.5 with the same step of 200 per revolution. The exact energy is a constant, so every curve here is the method rather than the problem. Euler climbs steadily: its energy at the end is 106.5% wrong, and the orbit it draws has spiralled outwards. Runge–Kutta 4 begins 4.7e+2 times more accurate than leapfrog and ends at 2.22e-4, having grown by a factor of 10 across the run: the error is SECULAR. Leapfrog oscillates inside a band and stays there — worst error 2.62e-3, and the second half of the run is no worse than the first, which is measured here rather than claimed. That is the property that decides whether a five-billion-year integration means anything, and it is not accuracy: a symplectic method is the exact solution of a Hamiltonian a step-size away from the intended one, so its energy cannot wander, while a more accurate non-symplectic method has no such constraint and eventually wanders further.
Fig. 2 The property, seen against the alternatives. Euler’s energy climbs steadily and its orbit spirals outward; Runge–Kutta begins thousands of times more accurate and its error is nonetheless secular, growing by a large factor across the run; leapfrog oscillates inside a band whose second half is no worse than its first. That last statement is measured on every step of the run rather than on the drawn samples, which matters more than it sounds: the drawn curve is decimated for size, the decimation beats against the orbital period, and a band that is flat to fourteen figures can be made to look like a rising one by sampling it at the wrong stride.

Why changing the step destroys it

The shadow Hamiltonian depends on hh. Change the step and a different nearby Hamiltonian is being solved exactly.

While the step is constant, the numerical trajectory lies on a level set of H~\tilde H and stays there for ever. Change the step at some moment, and the state — which is on a level set of H~1\tilde H_1 — is now being propagated on a level set of H~2\tilde H_2 passing through that same point. The value of the true energy HH at that point is whatever it was; the subsequent oscillation is now about a different centre.

Do that once and nothing much happens. Do it at every step, with the step responding to the body’s position, and the offsets accumulate. They accumulate as a random walk: each change contributes a small displacement whose sign depends on where in the orbit it happened, and a sum of many such displacements grows as the square root of their number rather than cancelling.

The result is the rising curve in the first figure. It is not a bug in the implementation and it is not a matter of the control being too aggressive. It is what a symplectic integrator does when it stops being symplectic, and the moment it stops is the moment the step changes.

Order, measured off the slope rather than quoted. Position error after one complete revolution against step size, both logarithmic, for the same three integrators. The straight-line slope of each is its convergence order, fitted here over the three finest steps rather than taken from the method's name: euler 0.93, rk4 4.03, leapfrog 2.00, against the 1, 4, 2 the definitions promise. Read alone, this figure says to use Runge–Kutta: on the fitted slopes, halving the step buys 1.9× for euler, 16.3× for rk4, 4.0× for leapfrog. Read beside the energy figure it says the opposite for a long integration, and the two together are the whole of why solar-system work is done with symplectic methods that are, step for step, the worse of the two.
Fig. 3 And it cannot be fixed by taking smaller steps, which is the obvious response. The convergence order of each method is fitted here from the drawn errors, and leapfrog’s is 2 — so halving the step buys a factor of four in the size of the oscillation and does nothing whatever to the fact that a varying step accumulates. Refining a control that is wrong in kind makes the error smaller and leaves it growing.

Why the simplest scheme is the one with the property

It is worth saying where the symplectic property comes from, because it explains why the method that has it is cruder than the one that does not.

The Hamiltonian of a gravitating system splits into two pieces, each of which is exactly solvable on its own. The kinetic part alone advances positions at constant velocity — a drift. The potential part alone changes velocities at constant position — a kick. Neither is the full problem and each is integrable in closed form.

A symplectic integrator is built by alternating exact solutions of the pieces. Half a kick, a full drift, half a kick: that is leapfrog, and every step of it is an exact flow of something, so the composition is an exact flow of something too. The map is therefore area-preserving in phase space — symplectic — by construction rather than by accident, and the shadow Hamiltonian is the thing it is the exact flow of.

The symmetry of the arrangement is what makes the error second order. Kick–drift–kick is time-reversible: run it backwards and the same sequence appears. A reversible map cannot have odd-order error terms, because those would change sign under reversal and the map does not — so the leading error is h2h^2 and the expansion of the shadow Hamiltonian contains only even powers.

That is the whole construction, and its crudeness is the point. A higher-order method built by taking a weighted combination of Taylor terms is more accurate and is not the exact flow of anything, so it has no shadow Hamiltonian and no bound. Higher-order symplectic methods exist and they are built the other way: by composing more drifts and kicks with carefully chosen coefficients, so that the composition remains an exact flow while the low-order error terms cancel.

The property belongs to the composition rather than to the accuracy, and any modification that breaks the composition breaks it — which is what a varying step does.

The arithmetic of the accumulation

The random walk is worth putting numbers to, because the scaling is what decides whether the effect is a curiosity or a disaster.

A fixed-step method’s energy error is bounded by some ϵh2\epsilon \sim h^2 and stays there. A varying-step method’s error is a sum of NN independent displacements of typical size δ\delta, where δ\delta is how much the shadow Hamiltonian moves when the step changes by the amount it changes in one step. That sum grows as δN\delta\sqrt{N}.

Two consequences follow, and they pull in opposite directions. Because the growth is a square root rather than a linear drift, an adaptive symplectic method is still much better than a non-symplectic one of the same order, whose error grows as NN. And because it grows at all, there is always a run length past which the fixed step wins — and that length is short. In the first figure it is a few hundred revolutions. For a solar-system integration a few hundred revolutions is a few thousand years, against a target of five billion.

The crossing point moves with the aggressiveness of the control. A step that varies by ten per cent around the orbit crosses later than one that varies by a factor of five. It always crosses.

How fast the series converges, and where it stops. The largest error of the N-term Lagrange series over half a revolution, against N, on a logarithmic axis, at 0.3, 0.5, 0.6627, 0.8. Every curve below the Laplace limit is a straight line, because the convergence is geometric and the ratio is exactly e/e_L: at e = 0.3 the error falls by a factor of 2.21 per term, which is the assertion this generator makes before drawing. At the limit itself the line is horizontal — the series neither converges nor diverges — and above it the error grows without bound, so adding terms makes the answer worse and there is no warning in the equation that it will. That is why Kepler's equation is solved by iteration in every ephemeris ever written: not because no formula exists, but because the formula has a radius of convergence and comets do not respect it.
Fig. 4 Why the alternative is affordable. The dominant part of a planetary Hamiltonian is a set of independent two-body problems, and a two-body problem is solved rather than integrated: Kepler’s equation converges to machine precision in a handful of Newton iterations, at any eccentricity below about 0.99, and its cost does not depend on how long a step is being taken. Splitting the problem so that the exactly solvable part is advanced exactly is what makes a step of a twentieth of an orbit acceptable — and it means the integrator never has to resolve the orbit at all, only the perturbation.

What the step control was for

None of this would matter if a constant step were adequate everywhere. It is not, and the reason is eccentricity.

An orbit at e=0.9e = 0.9 moves nineteen times faster at perihelion than at aphelion, and its radius of curvature there is a hundredth of what it is at the far end. A step chosen to resolve perihelion is absurdly fine for the other ninety-five per cent of the orbit; a step chosen for the mean is nowhere near fine enough for perihelion, and the error committed in the few steps near closest approach dominates the whole revolution.

The natural response is to make the step follow the free-fall time, hr3/2h \propto r^{3/2} — more steps where the physics is fast and fewer where it is slow. Judged one step at a time it is unambiguously better. That is the trap: it is better at every step and ruinous over a million of them.

What is done instead

Three things, and they are all ways of avoiding the choice rather than making it.

Take a fixed step short enough for the worst encounter that will ever happen. This is what most planetary integrations do, and it is affordable only because the planets’ orbits are nearly circular and their mutual encounters are distant. It fails the moment a small body on a crossing orbit is included.

Change the independent variable rather than the step. If the equations are rewritten so that the integration proceeds in a variable that is not time — an eccentric anomaly, or a fictitious time defined by dt=rdsdt = r\,ds — then a constant step in the new variable is a variable step in time, automatically fine near perihelion, and the map remains symplectic in the transformed system. This is the same manoeuvre that turns the singularity of a collision orbit into a change of variable, and it is close kin to the solve that does not ask which conic it is. It is not free: the transformation has to be built into the splitting, and a time-transformed symplectic method for a general NN-body problem is considerably harder to construct than the two-line leapfrog it replaces. Or switch integrators for the duration of the encounter. This is what long-term solar-system codes actually do. The system is split into a dominant Keplerian part, solved exactly, and a perturbation, applied as periodic kicks; that splitting is the Wisdom–Holman map and it is what makes a step of a twentieth of the shortest orbital period sufficient for the planets, whose mutual perturbations are the small terms the elements respond to. When two bodies come within a few Hill radii of each other the splitting stops being a good one, because the “perturbation” is no longer small, and the code hands that piece of the trajectory to a conventional adaptive method — a Bulirsch–Stoer or a high-order Runge–Kutta — for as long as the encounter lasts, then hands it back. What counts as an encounter is set by the radius within which the planet rather than the Sun is in charge.

The hybrid is not symplectic during the encounter and does not pretend to be. What it relies on is that encounters are rare and brief: a bounded error committed over a few hundred years out of five billion is a bounded error, and the drift-free behaviour is restored for the whole of the remaining time.

What it costs, and how it is checked

The bookkeeping is the awkward part. Handing a subsystem to a different integrator means deciding when the encounter begins and ends, and a switch that happens at slightly the wrong moment is itself a step-size change of the kind this essay is about. Good implementations blend the two smoothly, with a changeover function that goes from zero to one over a few steps, precisely so that nothing discontinuous happens to the map.

And the check that any of it worked is the same check the rung below used, run over a longer baseline: the energy error is monitored, and a run whose energy has drifted is a run whose answer is not trusted whatever else it says.

Every one of them loses the phase. The distance between the integrated position and the exact Kepler position, against revolution number, for the same two integrators and the same orbit as the energy figure. The unit is the semi-major axis. All three grow without bound — rk4 reaches 1.47e-1, leapfrog reaches 1.30e+0 — and the symplectic method has no advantage here at all. This is the half of the story a "conserves energy" summary throws away: leapfrog's guarantee is about the shape of the orbit, not about where on it the body is. A five-billion-year integration of the solar system is therefore evidence about whether Mercury stays and no evidence whatever about where Mercury will be, and the two statements are made by the same run.
Fig. 5 And the thing neither method fixes. Position error against elapsed revolutions, for two integrators of very different quality: both grow without bound, because a small error in the period is a phase error that accumulates linearly for ever. A symplectic integrator is not more accurate about where a planet is. It is right about how much energy the system has, which is what decides whether a configuration is stable, and it is as wrong as anything else about where in its orbit the planet will be — which is why an ephemeris and a stability integration are different programs with different requirements.

What the long integrations report

The five-billion-year integrations that produce the stability statistics for the solar system are all built this way, and their published diagnostics are the ones this essay is about.

They quote a relative energy error, typically a few parts in 101110^{11} over the whole run, and they quote it as a bound rather than as an endpoint — because the whole point of the method is that the endpoint is not special. They quote the angular momentum error separately, because the splitting conserves it to machine precision by construction and a departure would indicate a coding error rather than a discretisation one. And they report how many close encounters were handed to the non-symplectic branch and for how long, because that is the part of the run whose error is not bounded by anything structural.

What none of them claims is to know where Mercury will be. A five-billion-year integration is a sample of what the system might do, not a prediction of what it will, and the reason is one the collection has already made: an exponential divergence turns a centimetre of initial uncertainty into an entire orbit in a hundred million years, so the trajectory computed is one of many consistent with the data.

Energy error over 240 revolutions, at one step size. The relative error in total energy against revolution number, for three integrators run on the same Kepler orbit at e = 0.7 with the same step of 200 per revolution. The exact energy is a constant, so every curve here is the method rather than the problem. Euler climbs steadily: its energy at the end is 124.1% wrong, and the orbit it draws has spiralled outwards. Runge–Kutta 4 begins 1.2e+1 times more accurate than leapfrog and ends at 1.99e-2, having grown by a factor of 10 across the run: the error is SECULAR. Leapfrog oscillates inside a band and stays there — worst error 2.40e-2, and the second half of the run is no worse than the first, which is measured here rather than claimed. That is the property that decides whether a five-billion-year integration means anything, and it is not accuracy: a symplectic method is the exact solution of a Hamiltonian a step-size away from the intended one, so its energy cannot wander, while a more accurate non-symplectic method has no such constraint and eventually wanders further.
Fig. 6 The same comparison at an eccentricity of 0.7, where the argument stops being academic. A fixed step that is comfortable at apoapsis is far too coarse at periapsis, because the body covers the same angle in a fraction of the time — so every method’s error is dominated by a handful of steps near closest approach, and the gap between the schemes narrows. Leapfrog still does not drift, which is the property being bought; what it loses is accuracy per step, and here a good deal of it. Push the eccentricity further and the figure cannot be drawn at all: Runge–Kutta’s error saturates within the first few revolutions and the secular growth this panel is about stops existing, which the generator refuses rather than draws.

The error that is not the method’s

There is a floor under everything above and it is arithmetic rather than analysis.

A five-billion-year integration at a step of a fiftieth of Mercury’s year is about 101210^{12} steps. Each one adds two numbers in floating point, and each addition rounds. Rounding errors are not systematic — they are as often up as down — so they accumulate as a random walk, and 101210^{12} of them at a relative size of 101610^{-16} each gives 10161012=101010^{-16}\sqrt{10^{12}} = 10^{-10}.

That is comparable with the energy errors the published integrations quote, which means the arithmetic and the discretisation are contributing at the same level and neither can be reduced by improving the other.

The response is to change how the addition is done. In compensated summation, the part of each addition lost to rounding is computed explicitly and carried forward into the next step, so the error no longer accumulates as a random walk but stays bounded. It costs a few extra operations per step and it removes a term that no amount of care about the physics would touch.

There is a second and subtler arithmetic effect. A position accumulated as a running sum loses precision as it grows, so a body whose coordinates are large in the chosen units is integrated less accurately than one whose coordinates are small — for no physical reason whatever. The fix is to carry the drift as an increment rather than as an absolute position, which is a change of variables made purely to keep the numbers near unity.

Neither of those is physics and both change the answer, which is the usual position for a computation whose interesting property is a bound on an accumulated quantity: the bound has to hold against the arithmetic as well as against the equations.

The general shape of the mistake

It is worth naming the pattern, because it recurs and it is not about integrators.

A method is chosen for a structural property — a conserved quantity, a bounded error, an exact symmetry. The property depends on a condition that is not the obvious one. Somebody then improves the method along the obvious axis, the condition is violated as a side effect, and the improvement is measurably better on every short test and worse on the long one the method was chosen for.

Here the obvious axis is accuracy and the condition is uniformity. The tell is the first figure: over its first three revolutions the adaptive run is nearly six times better, which is exactly the evidence a short test would produce. The property the essay is about is a property of a fixed step, so it is worth drawing at a second eccentricity and a second range of step sizes.

The adaptive step starts 66.6× more accurate and ends 0.8× worse. The envelope of the relative energy error against elapsed revolutions — the worst error within each plotted interval rather than the error at one sample in it — for the same second-order symplectic integrator run two ways on a Kepler orbit at e = 0.8. The flat band is a fixed step of one 200th of a period: its error oscillates once per revolution and the envelope does not grow, because a symplectic method at constant h is the exact solution of a nearby Hamiltonian and is conserving that one. The rising curve is the same method with the step refined where the orbit is fast — h ∝ r^3/2, the free-fall time, varying by a factor of 33 around the orbit — which is the first thing anybody reaches for at a close encounter and which is strictly more accurate step for step: over its first three revolutions it stays a factor of 66.6 below the fixed run. By 1500 revolutions it is a factor of 0.8 above it and still climbing. Changing the step changes which Hamiltonian is being conserved, the errors from successive steps stop cancelling, and what is left is a random walk with no bound at all. The practical consequence is that a solar-system integration cannot adapt its step: it either keeps a step short enough for the closest encounter it will ever meet, or it detects the encounter and hands that piece of the trajectory to an entirely different, non-symplectic method for the duration — which is what every long-term integration of the planets actually does.
Fig. 7 The adaptive scheme’s energy drift at an eccentricity of 0.8 rather than 0.5. The drift is worse, because the step control works hardest near periapsis and it is precisely there that the symplectic property is being broken — a more eccentric orbit adapts more and therefore loses more.
Order, measured off the slope rather than quoted. Position error after one complete revolution against step size, both logarithmic, for the same three integrators. The straight-line slope of each is its convergence order, fitted here over the three finest steps rather than taken from the method's name: euler 0.80, rk4 4.12, leapfrog 2.00, against the 1, 4, 2 the definitions promise. Read alone, this figure says to use Runge–Kutta: on the fitted slopes, halving the step buys 1.7× for euler, 17.3× for rk4, 4.0× for leapfrog. Read beside the energy figure it says the opposite for a long integration, and the two together are the whole of why solar-system work is done with symplectic methods that are, step for step, the worse of the two.
Fig. 8 And the order measured off the drawn errors over a coarser range of steps. The slope on these axes is the order of the scheme, recovered from the integration rather than asserted from the derivation — which is the check that the implementation is the method it claims to be.

Where this ladder goes next

This rung has taken a property that a previous rung established and found its actual precondition: the bounded energy error of a symplectic method belongs to a fixed step, and every natural improvement to the step destroys it.

The rung above is the splitting itself. Separating a Hamiltonian into an exactly solvable Kepler part and a small perturbation is what makes a twenty-step-per-orbit integration of the solar system accurate at all, and the choice of how to split it — and of the order in which the pieces are applied — is where the modern work is.

Beside it lies the question of what “accurate” should mean for a chaotic system. If two integrations of the same initial condition diverge exponentially, then no integration is following the true trajectory, and what is being claimed instead is that the computed trajectory is the exact trajectory of a nearby initial condition — a shadowing statement, which is a different and much weaker claim than the one people usually think they are making.

And below it, the habit: check what a guarantee is a guarantee about. The energy band belongs to the step being constant, not to the step being small, and the difference between those two readings is the difference between an integration that means something after five billion years and one that does not.

What links here

Essays that link to this one from their own argument.

The objects this essay names

Each one links to every other essay that touches it.

Adaptive stepClose encounterEnergy driftHybrid integratorOperator splittingPhase errorRegularisationShadow hamiltonianStep sizeSymplectic integratorTime transformationWisdom holman map