An Introduction to Symplectic Integrators

Keirn Munro [email protected]

Abstract We aim to outline some of the basic techniques of numerical integration as it pertains to computing flows of Hamiltonian systems. The method of Symplectic Integrators has gained popularity in recent years as a relatively stable approach to long time simulations of , namely pendulum and celestial body problems. The approach makes use of the symplectic structure to move beyond naive analytic techniques and refine existing approaches.

Background and Notation Letting (M, ω) be a smooth symplectic manifold along with it’s 2-form, respectively. Given a Hamiltonian H and a starting point z0, the task at hand is to numerically solve for the flow of XH starting at z0, z(t). The numerical algorithms, or integrators, we will use to do this are those smooth families of diffeomorphisms on M,Ψ: M × R → M, such that Ψ∆t(z0) = Ψ(z0, ∆t) ≈ z(∆t). To simulate flow, the user iteratively applies Ψ∆t to z0. When we hold ∆t fixed, we may also require that Ψ∆t is a and shall herein refer to maps of this form as symplectic integrators.

We begin first with a result paraphrased from Proposition 5.4.3 in [5]:

Proposition (Conservation of Energy): Given a Hamiltonian function H : M → R and an associated vector field XH with flow ϕt : M → M, H ◦ ϕt is constant in t. Proof. Proceeding by direct computation and letting x ∈ M,

d H(ϕt(x)) = XH (H)(ϕt0 (x)) dt t0

= dH (XH (ϕt0 (x))) (1) = − (ιXH ω (XH )) ϕt0 (x)

= −ω (XH ,XH ) ϕt0 (x) = 0 by anti-symmetry

establishing the result.

∗ Lemma (Symplectomorphism Flow) Preserving definitions from the previous result, ϕt (ω) = ω

Proof. This is an application of Cartan’s Magic formula while noting that ϕ0 = Id. d ϕ∗ω = L (ω) dt t XH

= ιXH dω + dιXH ω (2) = dιXH ω since ω is closed = −ddH = 0

1 Since we aim to import everything into computers while keeping things brief, we will be working in  0 Id M = 2n for the duration of this paper. Take our 2-form ω to be represented by the matrix J = R − Id 0 and notice that are smooth functions f : M → M such that

(Df)>JDf = J

With this language, we rewrite Hamilton’s equation as

d  > (q(t), p(t)) = J ∇H dt (q(t),p(t))

Let us also define the for our context: {·, ·} : C∞(M) × C∞(M) → R via

> {f, g} = ω(Xf ,Xg) = (∇f)J (∇g)

Letting DH f = {f, H}, we once more restate Hamilton’s equations:

d (q(t), p(t)) = DH dt (q(t),p(t))

Noting that DH = XH is just a change of notation. Before proceeding, we formulate language to gauge accuracy of an integrator, paraphrased from [1]:

Definition: An integrator Ψ∆t(z0) is said to be of n-th order approximation of the desired flow z(t) (with n+1 z(0) = z0) if |Ψ∆t(z0) − z(∆t)| ∈ O(∆t ) as ∆t → 0.

Hamiltonian Splitting As a preliminary strategy for constructing an integrator given a Hamiltonian function H(q, p) and an initial point z0, it is desirable to break H apart into a sum of simpler pieces. Indeed, our strategy will be as follows: Decompose H into a sum of Hamiltonians

k X H = Hi i=1

Explicitly compute Ψ∆t,Hi as exact flows, noting that Ψ∆t,Hi = exp (∆tDHi ), and assemble via

k Y Ψ∆t := Ψ∆t,Hi i=1

where the product indicates iterated composition. The keen reader will note two things: First, that Ψ∆t is an iterated composition of symplectomorphisms and so is itself a symplectomorphism. Second, Ψ∆t(z0) 6= z(t)

in general, for the exp (∆tDHi ) do not commute unless the Lie brackets of the pairs DHi are all 0. We shall table this discussion for later and proceed instead by making things more concrete.

Example: A somewhat canonical class of examples occur when H can be expressed as a sum of poten- tial energy V (q) and kinetic energy T (p) (note that each function depends only on one of p, q):

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

Consider the Hamiltonian H : R2 → R describing the mathematical pendulum: p2 H(q, p) = − cos(q) 2

2 This function is used in [8] to illustrate a different concept (large time step chaos) than that exhibitted here. p2 Letting H1(q, p) = − cos(q) and H2(q, p) = 2 , we may then compute:  0 1 D = (∇H (q, p))> H1 −1 0 1  0 1 sin(q) = −1 0 0  0  = − sin(q)  0 1 D = (∇H (q, p))> H2 −1 0 2  0 1 0 = −1 0 p p = 0

So our Ψ∆t,Hi are  q  q + ∆tp Ψ (q, p) = , Ψ (q, p) = ∆t,H1 p − ∆t sin(q) ∆t,H2 p and our candidate (symplectic) integrator is  q + ∆tp  Ψ = Ψ ◦ Ψ = ∆t ∆t,H1 ∆t,H2 p − ∆t sin(q + ∆tp) Given this, and after picking small ∆t, we predict that our integrator will be a good candidate for running a computer simulation on in hopes to illustrate our work so far. While Ψ∆t does not conserve H exactly, it turns out that Ψ∆t is a flow for some associated Hamiltonian and that this other Hamiltonian is close to H. This is by no means a fluke and will be discussed in greater detail shortly. For amusement, we implemented the computed simulation algorithm in Python with a choice of initial point (0, 1.9999) and ∆t = 0.005 (see Appendix for code as well as an illustration). The code prints as well the maximum difference |H(q, p) − H(q0, p0)| at each step. Empirically, running this simulation for over 36, 000 steps resulted in a maximum error of approximately 3.8589 × 10−3 and as well traced out a closed curve of qualitatively similar form to z(t).    ∂T  q q + ∆t ∂p For general V (q),T (p), notice that Ψ∆t,H1 = ∂V and Ψ∆t,H2 = . The integrator p − ∆t ∂q p given by their composition as above is known in some literature as the Symplectic . We can see too that the order observation is true in general by applying Taylor’s theorem 3 times:

Lemma: The symplectic Euler method is an order 1 integrator.

As promised, the following theorem is stated by Yoshida in [8] in reference to the symplectic Euler method:

Theorem: The symplectic mapping Ψ∆t exactly describes the time-∆t evolution of an associated Hamil- tonian H˜ , which is close to the original Hamiltonian and has the expression of a formal power series in ∆t, 2 3 H˜ = H + ∆tG1 + ∆t G2 + ∆t G3 + ... where H is the original Hamiltonian, and ! 1 ∂H ∂H 1 ∂2H ∂H 2 ∂2H ∂H 2 1 ∂2H ∂2H ∂H  ∂2H ∂H  G = ,G = + ,G = ,... 1 2 ∂p ∂q 2 12 ∂p2 ∂q ∂q2 ∂p 3 12 ∂p2 ∂q2 ∂q ∂q2 ∂p

In particular, Ψ∆t conserves H˜ above exactly.

3 Moreover, in terms of closeness, Yoshida remarks that if the Symplectic Euler method happens to be of nth order, the associated Hamiltonian has the following form:

n n+1 H˜ = H + ∆t Gn + O ∆t

We remark here that it is due to the theorem above that our example simulation earlier traced out a well behaved and closed curve. Analogous results exist for more general schemes [2].

To push our analysis of Hamiltonians of the form H(q, p) = T (p) + V (q) even further, we attempt to algorithmically construct n-th order approximations. Fixing n, a fruitful strategy is to search for k ∈ Z along with constants ci, di for i = 1, . . . , k such that

k ! Y n+1 exp (∆t(DT + DV )) = exp (ci∆tDT ) exp (di∆tDV ) + O(∆t ) i=1 Remember here that we are composing in a setting where order matters:

exp (c1∆tDT ) exp (d1∆tDV ) exp (c2∆tDT ) exp (d2∆tDV ) ...

Indeed, for Hamiltonians of this form, k and a collection of (ci, di) have been determined for n ≤ 4. We have seen n = 1 above (k = 1, c1 = d1 = 1) and we list the others here for posterity:

n = 2 Stated in Yoshida [8] 1 k = 2, c = c = , d = 1, d = 0 1 2 2 1 2 n = 3 R. Ruth [7] 7 3 −1 2 −2 k = 3, c = , c = , c = , d = , d = , d = 1 1 24 2 4 3 24 1 3 2 3 3 n = 4 H. Yoshida [8]

1 1 1 1 − 2 3 1 −2 3 k = 4, c = c = , c = c = , d = d = , d = 1 4  1  2 3  1  1 3 1 2 1 2 2 − 2 3 2 2 − 2 3 2 − 2 3 2 − 2 3

We would be remiss not to remark from [4] on the slight tweak of the n = 2 method where we shift coefficients and take 1  1  exp ∆tD exp (∆tD ) exp ∆tD 2 V T 2 V This is still of order 2 and is the well enjoyed St¨ormer-Verlet method.

Adjoints and Symmetry

We remark on a definition found in both [3] and [4]:

∗ −1 Definition: Given an integrator Ψ∆t, we define its adjoint method Ψ∆t to be (Ψ−∆t) . An integrator is ∗ said to be symmetric if Ψ∆t = Ψ∆t

Without delay, we remark on the order consistency of this definition as stated in [3] and paraphrased here:

Theorem: Given an integrator Ψ∆t approximating a flow z(t), the order of Ψ∆t is equal to the order of ∗ Ψ∆t. Moreover, if we let n be the order of Ψ∆t and write

n+1 n+2 Ψ∆t(z0) = z(∆t) + C(z0)∆t + O ∆t

4 where C(z0) is a constant in z0. Then, ∗ n n+1 n+2 Ψ∆t(z0) = z(∆t) + (−1) C(z0)∆t + O ∆t

Note that a symmetric method must have even order, by equating terms so that 1 = (−1)n. If we have ∗ formula for order 1 integrators Ψ∆t, Ψ∆t, we may construct a symmetric order 2 integrator via ∗ Γ∆t := Ψ 1 ∆t ◦ Ψ 1 2 2 ∆t This can be proven in higher generality by theorems from [3] that we collect here:

Theorem: Given an order n integrator Ψ∆t and constants γ1, . . . , γs such that

γ1 + ··· + γs = 1 n+1 n+1 γ1 + ··· + γs = 0 then Γ∆t := Ψγs∆t ◦ · · · ◦ Ψγ1∆t is an order n + 1 method. Similarly, if we have constants α1, β1, . . . , αs, βs such that α1 + β1 + . . . αs + βs = 1 n+1 n n+1 n+1 n n+1 α1 + (−1) β1 + ··· + αs + (−1) βs = 0 then Γ0 := Ψ ◦ Ψ∗ ◦ · · · ◦ Ψ ◦ Ψ∗ is an order n + 1 method. ∆t αs∆t βs∆t α1∆t β1∆t

Paths Forward The literature on the topic of symplectic integrators is rich and there are a great many paths of exploration to follow. In this section we elect to introduce the absolute basics of tackling the problem of integrating linear non-autonomous Hamiltonian systems by outlining the beginnings of Marthinsen’s paper [6] and encourage the reader to explore his results further, which delve nicely into contact geometry. We work on a smooth n-dimensional manifold Q referred to as the configuration space and define our Hamiltonian H using the phase space, T ∗Q. We take our symplectic form ω on the phase space. A non-autonomous Hamiltonian ∗ H : T Q × R → R is a smooth function with an associated vector field XHt such that, writing the arguments Ht(q, p), dH = −ι ω t XHt for each t. Dependence on t immediately complicates all of the work we have done up to this point. In particular, flows ϕt(q, p) need not preserve H and, more alarmingly, there is no symplectic structure on the odd dimensional manifold T ∗Q × R. The basic strategy of attack then is to enlarge T ∗Q × R to some even dimensional space M, define a symplectic form Ω on M as a stand-in for ω, define some K : M → R as a stand-in for H, and impose a framework such that symplectic integrators on M for K can be ported over to integrators on T ∗Q for H. Marthinsen takes M = T ∗ (Q × R) and defines a projection map µ: M → T ∗Q × R via µ(q, p, t, u) = (q, p, t). Take K = H ◦ µ + u, Ω = ω + du ∧ dt, and then XK such that

ιXK Ω = −dK Definition: A pair of diffeomorphisms (ψ, ϕ) with ψ : T ∗ (Q × R) → T ∗ (Q × R) a symplectomorphism with respect to Ω and ϕ: T ∗Q × R → T ∗Q × R an integrator are said to be canonical if the following diagram commutes: µ T ∗(Q × R) T ∗Q × R

ψ ϕ

∗ ∗ T (Q × R) µ T Q × R The interesting question then becomes, given a symplectomorphism ψ : T ∗ (Q × R) → T ∗ (Q × R), do we have such a ϕ that makes a canonical pair (ψ, ϕ)? Marthinsen lists sufficient conditions for this and remarks that given a canonical transformation (ψ, ϕ), ϕ is an integrator has order no less than ψ. He proceeds to compute the canonical transforms associated with the Symplectic Partitioned Runge-Kutta integration scheme ψ on T ∗(Q × R) and observes favorable results.

5 Appendix

Here, we exhibit the simulation code from our example:

from matplotlib import pyplot as plt from matplotlib import animation from math import sin, cos fig = plt.figure() ax = fig.add_subplot(aspect=’equal’, xlim=(-5, 5), ylim=(-5, 5)) xdata, ydata = [], [] ln, = plt.plot([], [],’r.-’, markersize=0.5) z_0 = (0, 1.9999) z_t = z_0 max_error = 0 step_num = 0 delta_t = 0.005 def hamiltonian(q, p): return 0.5 * (p ** 2) - cos(q) def update(frame): global z_t, max_error, step_num q, p = z_t z_t = ( q + delta_t * p, p - delta_t * sin(q + delta_t * p), ) max_error = max(abs(hamiltonian(*z_t) - hamiltonian(*z_0)), max_error) print(f’Max energy error encountered at step{step_num}:{max_error}’) step_num += 1 xdata.append(z_t[0]) ydata.append(z_t[1]) ln.set_data(xdata, ydata) return ln, anim = animation.FuncAnimation(fig, update, interval=5, blit=True) plt.show()

Observe that long time execution (36, 000 steps) results in the following image:

6 References

[1] Denis Donnelly and Edwin Rogers. Symplectic integrators: An introduction. American Journal of Physics, 73(10):938–945, 2005. [2] Ch. Lubich E. Hairer and G. Wanner. Geometric numerical integration: Structure-preserving algorithms for ordinary differential equations. pages 343 – 344, 2006. [3] Ernst Hairer. Lecture 2: Symplectic integrators, Jan 2010.

[4] Benedict Leimkuhler and Sebastian Reich. Simulating Hamiltonian Dynamics. Cambridge Monographs on Applied and Computational Mathematics. Cambridge University Press, 2005. [5] Jerrold E. Marsden and Ratiu Tudor S. Introduction to mechanics and symmetry: a basic exposition of classical mechanical systems. Springer, 2011.

[6] H˚akon Marthinsen and Brynjulf Owren. Geometric integration of non-autonomous linear hamiltonian problems. Advances in Computational Mathematics, 42:313–332, 04 2016. [7] R. Ruth. A Canonical Integration Technique. IEEE Trans. Nucl. Sci., 30:2669, 1983. [8] Haruo Yoshida. Recent Progress in the Theory and Application of Symplectic Integrators. and Dynamical Astronomy, 56(1-2):27–43, March 1993.

7