1 Introduction

The construction of modified equation is generally the first step of the backward error analysis for the numerical solution of differential equations, which has obtained much success during the last decades [8, 9, 11, 12], especially in the qualitative analysis of symplectic methods for Hamiltonian systems [5, 14, 22, 23, 2628, 31, 35]. It constructs perturbed Hamiltonian systems to approximate the symplectic methods, reveals the reason for their long-time good behavior, and implies the construction of higher order methods. For a more detailed review of these see e.g. the monographs [13, 17].

The extension of the modified equations to the stochastic context is a relatively new topic. To knowledge of the authors, some prior work include [1, 6, 25, 29, 34, 36], and so on. In [34], linear Langevin equations are considered. In [29], modified equations that approximate the forward and backward Euler methods in the sense of weak convergence for Itô stochastic differential equations (SDEs) with additive noise are given, with the discussion of extension to other type of equations and approximation. Zygalakis [36] describes a general framework for deriving modified equations for SDEs with respect to weak convergence, using weak stochastic Taylor expansions. Debussche and Faou [6] builds modified equations not at the level of the SDEs, but at the level of the Kolmogorov generators associated with the process solution of the SDEs. Pavliotis et al. [25] uses modified equations to exhibit the poor behavior of the Euler methods for small random perturbations of Hamiltonian flows, and [1] proposes a new method for constructing numerical integrators with high weak order for the time integration of SDEs, inspired by the theory of stochastic modified equations. The recent work [2] analyses sufficient conditions for the Lie–Trotter splitting to preserve the invariant measure of nonlinear ergodic Langevin dynamics, with the application of the stochastic backward error analysis.

Anton, Deng and Wong have developed in their recent article [4] the approach of constructing weak stochastic symplectic methods using generating functions. In this paper, we attempt to establish modified equations of weak \(k+k'\) order apart from the k-th order weakly convergent symplectic methods, that is, stochastic symplectic methods with respect to weak convergence and of weak order k, for stochastic Hamiltonian systems in terms of their generating functions, which is an extension of the approach producing modified equations for deterministic symplectic methods employing their generating functions [5, 23]. In case that the noises are additive, or they are multiplicative but the Hamiltonian functions \(H_{r}(p,q),\,\,r\ge 1\) associated to the diffusion part depend only on p or only on q, the approach can work, and we find in such situations that the modified equation of the weakly convergent symplectic methods are again perturbed stochastic Hamiltonian systems.

The contents are arranged as follows. Section 2 is an introduction of the stochastic modified equations theory. Section 3 reviews the stochastic generating function theory for stochastic symplectic methods. In Sect. 4 we develop the approach of constructing modified equations of weakly convergent symplectic methods via their generating functions. Section 5 gives some examples, for which numerical tests are performed in Sect. 6. Section 7 is a brief conclusion.

2 Stochastic modified equations

Given a stochastic differential equation

$$\begin{aligned} dX(t)=a(X)dt+\sum _{r=1}^m\sigma _r(X)d W_r(t),\quad X(0)=x, \end{aligned}$$
(2.1)

where the drift and diffusion coefficients a(X) and \(\sigma _r(X)\) are \(\mathbf {R}^d\rightarrow \mathbf {R}^d\) functions satisfying conditions that guarantee the existence and uniqueness of the solution (see e.g. [18, 24] for details). \(W(t)=(W_1(t),\ldots , W_m(t))^T\) is m-dimensional standard Wiener process. A numerical approximation of it \(X_0,X_1,\ldots \) with step size h is said to converge weakly of order p, if for any \(T>0\) with \(N_T h=T\)

$$\begin{aligned} |\mathbf {E}(\phi (X_{N_T}))-\mathbf {E}(\phi (X(T)))|=O(h^p) \end{aligned}$$
(2.2)

for \(\phi \in C_P^{2p+1}(\mathbf {R}^d,\mathbf {R})\), the space of \(2p+1\) times continuously differentiable functions mapping from \(\mathbf {R}^d\) to \(\mathbf {R}\) which, together with their partial derivatives up to order \(2p+1\) have polynomial growth. As test functions, it is usually enough to consider polynomials up to order \(2p+1\).

In the aforementioned literature, the q-th order stochastic modified equation for a weakly convergent numerical method is the modified SDE

$$\begin{aligned} d\tilde{X}=A(\tilde{X})dt+\sum _{r=1}^m \varGamma _r(\tilde{X})dW_r(t) \end{aligned}$$
(2.3)

with

$$\begin{aligned} \begin{array}{l} A(\tilde{X})=a(\tilde{X})+a_1(\tilde{X})h+a_2(\tilde{X})h^2+\cdots +a_q(\tilde{X})h^q\\ \varGamma _r(\tilde{X})=\sigma _r(\tilde{X})+\sigma _{r,1}(\tilde{X})h+\cdots +\sigma _{r,q}(\tilde{X})h^q, \end{array} \end{aligned}$$
(2.4)

where the functions \(a_i\) and \(\sigma _{r,i}\) are to be determined such that for any \(T>0\) with \(T=hN_T\)

$$\begin{aligned} |\mathbf {E}(\phi (X_{N_T}))-\mathbf {E}(\phi (\tilde{X}(T)))|=O(h^{p+q'}), \end{aligned}$$
(2.5)

for some \(q'>0\), meaning that the solution of (2.3) is weakly \(q'\)-order ’closer’ to the numerical solution than the SDE (2.1) does. In the ODE case, the modified equation can fit its corresponding numerical method with high accuracy [13, 36].

In [36], the functions \(a_i\) and \(\sigma _{r,i}\) are found by using the Taylor expansion of \(\mathbf {E}(\phi (X)|X(0)=x)\), i.e., the Taylor expansion of the solution to the backward Kolmogorov equation associated with the SDE (2.1)

$$\begin{aligned} \frac{\partial u}{\partial t}=\mathscr {L}_0 u,\quad u(x,0)=\phi (x), \end{aligned}$$
(2.6)

where, in the case of \(d=m=1\) in (2.1), \(\mathscr {L}_0u:=a(x)\frac{du}{dx}+\frac{1}{2}\sigma ^2(x)\frac{d^2 u}{dx^2}\). The solution of probabilistic sense of (2.6) is just [24]

$$\begin{aligned} u(x,t)=\mathbf {E}(\phi (x(t))|x(0)=x), \end{aligned}$$
(2.7)

for which it holds

$$\begin{aligned} u(x,h)-\phi (x)=\sum _{k=0}^N \frac{h^{k+1}}{(k+1)!}\mathscr {L}_0^{k+1}\phi (x)+O(h^{N+2}) \end{aligned}$$
(2.8)

if u is \(N+1\) times differentiable with respect to t.

The expectation of \(\phi \) of a one-step numerical approximation of weak order p, \(\mathbf {E}(\phi (x(h))|x(0)=x)=:u_{num}(x,h)\) should have expansion coinciding with (2.8) up to terms of order \(O(h^p)\) which corresponds a local error of order \(p+1\). On the other hand, there is the backward Kolmogorov equation associated with the modified equation (2.3)

$$\begin{aligned} \frac{\partial u_{mod}}{\partial t}=\mathscr {L}^h u_{mod},\quad u_{mod}(x,0)=\phi (x), \end{aligned}$$
(2.9)

with \(\mathscr {L}^h u=A(x)\frac{du}{dx}+\frac{1}{2}\varGamma ^2(x)\frac{d^2u}{dx^2}\) for \(d=m=1\). To obtain a modified equation which is \(q'\) order closer to the numerical method than the exact solution does, one needs to equate the expansion of \(u_{num}(x,h)\) which is known from the numerical method itself, and the expansion of \(u_{mod}(x,h)\) which contains unknown functions to be determined, up to terms of order \(O(h^{p+q'})\). In this way the assumed unknown functions in the modified equations can be found [36].

In this paper, we construct the modified equations for the weakly convergent stochastic symplectic methods, not based on the backward Kolmogorov equations associated with the stochastic Hamiltonian systems, but via employing the stochastic generating functions that produce the weakly convergent symplectic schemes, which are introduced in the following section.

3 Generating functions for weakly convergent stochastic symplectic methods

Given a stochastic Hamiltonian system

$$\begin{aligned} \begin{aligned} dP&=-\frac{\partial H}{\partial Q}dt-\sum \limits _{r=1}^m \frac{\partial H_{r}}{\partial Q}\circ dW_r(t),\quad P(0)=p,\\ dQ&=\frac{\partial H}{\partial P}dt+\sum \limits _{r=1}^m \frac{\partial H_{r}}{\partial P}\circ dW_r(t),\quad Q(0)=q, \end{aligned} \end{aligned}$$
(3.1)

where \(P,Q,p,q\in \mathbf {R}^d\), H(PQ), \(H_r(P,Q)\) are Hamiltonian functions, and \((W_1(t),\ldots , W_m(t))^T\) is a m-dimensional standard Wiener process. The small circle ‘\(\circ \)’ before \(dW_r(t)\) denotes the SDEs of Stratonovich sense.

It is known that this system possesses the symplectic structure [19]

$$\begin{aligned} dP(t)\wedge dQ(t)=dp\wedge dq,\quad \forall t\ge 0. \end{aligned}$$
(3.2)

A numerical discretization \((P_n,Q_n)_n\) that preserves this structure is called a symplectic method, characterized by

$$\begin{aligned} dP_{n+1}\wedge dQ_{n+1}=dP_n\wedge dQ_n,\quad \forall n\in \mathbf {Z},\quad n\ge 0. \end{aligned}$$
(3.3)

Due to inheritation of the symplectic structure of the original systems, the symplectic methods are in most cases superior to the non-symplectic ones in tracking the phase trajectories of the underlying continuous Hamiltonian dynamical systems in the long time simulation, both in the deterministic and the stochastic context, as illustrated in [4, 20], etc. Also from the viewpoint of structure preservation, symplectic methods have, in general, good performance, although it is interesting to observe some exceptions such as the example in [2] for the simulation of the invariant measure of Langevin dynamics.

To construct symplectic methods, the stochastic generating function approach was established [3, 4, 7, 32, 33]. It is based on the fact that each symplectic mapping \((P_n,Q_n)\mapsto (P_{n+1},Q_{n+1})\) can be associated with a generating function [7, 10, 13, 32], e.g., the first kind of generating function \(S^1(P_{n+1},Q_n, h)\), \(h=t_{n+1}-t_n\), such that

$$\begin{aligned} \begin{aligned} P_{n+1}&=P_n-\frac{\partial S^1}{\partial Q_n},\\ Q_{n+1}&=Q_n+\frac{\partial S^1}{\partial P_{n+1}}, \end{aligned} \end{aligned}$$
(3.4)

Note that such expressions as \(\frac{\partial S^1}{\partial Q}\) represent d-dimensional vectors. There are other generating functions such as \(S^2(p_n, q_{n+1},h)\) and \(S^3\left( \frac{p_n+p_{n+1}}{2},\frac{q_n+q_{n+1}}{2},h\right) \), as illustration we only consider \(S^1\) in this article. Methods based on the other generating functions are similar.

It is given that [7, 32, 33], almost surely, the phase flow of the stochastic Hamiltonian system (3.1) can be generated by the generating function \(S^1(P(t),q,t)\) via the relation

$$\begin{aligned} p=P(t)+\frac{\partial S^1}{\partial q}(P(t),q,t),\quad Q(t)=q+\frac{\partial S^1}{\partial P}(P(t),q,t). \end{aligned}$$
(3.5)

\(S^1(P(t),q,t)\) can be assumed to possess the series expansion

$$\begin{aligned} S^1(P(t),q,t)=\sum _{\alpha }G_{\alpha }^1(P(t),q)J_{\alpha }, \end{aligned}$$
(3.6)

where \(\alpha =(j_1,j_2,\ldots ,j_l)\) denotes the multi-index of the stochastic multiple integrals, \(j_i\in \{0,1,\ldots ,m\}\) \((i=1,\ldots ,l)\), \(l\ge 1\), and

$$\begin{aligned} J_{\alpha }=\int _0^t\int _0^{s_l}\cdots \int _0^{s_2}\circ dW_{j_1}(s_1)\circ dW_{j_2}(s_2)\circ \cdots \circ dW_{j_l}(s_l). \end{aligned}$$
(3.7)

For convenience denote \(ds=dW_{0}(s)\). The upper index 1 in \(G_{\alpha }^1\) means that the coefficient functions G belong to the first kind of generating function.

To determine the coefficients \(G_{\alpha }^1\), the notations \(\varLambda _{\alpha _1,\ldots , \alpha _k}\) are introduced, which can be defined recursively as follows [3, 7]. First, define the concatenation \('*'\) of the indices \(\alpha =(j_1,\ldots ,j_l)\) and \(\alpha '=(j_1',\ldots ,j_{l'}')\) as \(\alpha *\alpha '=(j_1,\ldots ,j_l,j_1',\ldots ,j_{l'}')\). The concatenation of a set of multi-indices \(\varLambda \) and \(\alpha \) is \(\varLambda *\alpha =\{\beta *\alpha |\beta \in \varLambda \}\). Then, define

$$\begin{aligned} \varLambda _{_{\alpha _1, \alpha _2}}=\left\{ \begin{array}{l@{\quad }l} \{(j_1,j_1'),(j_1',j_1)\},&{} \text{ if }\,\,\,\, l=l'=1\\ \{\varLambda _{_{(j_1),\alpha _2- }}*(j_{l'}'),\alpha _2*(j_1)\}, &{}\text{ if }\,\,\,\, l=1, l'\ne 1\\ \{\varLambda _{_{ \alpha _1-,(j_1')}}*(j_l),\alpha _1 *(j_{1}')\},&{}\text{ if }\,\,\,\,l\ne 1, l'=1\\ \{\varLambda _{_{\alpha _1-,\alpha _2}}*(j_l),\varLambda _{_{\alpha _1,\alpha _2-}}*(j_{l'}')\} &{}\text{ if }\,\,\,\, l\ne 1, l'\ne 1\end{array}\right. \end{aligned}$$
(3.8)

For \(k>2\), define \(\varLambda _{\alpha _1,\ldots , \alpha _k}=\{\varLambda _{\beta , \alpha _k}|\beta \in \varLambda _{\alpha _1,\ldots , \alpha _{k-1}}\}\).

Denote \(H=H_0\). The \(G_{\alpha }^1\) are [3, 7]

$$\begin{aligned} G_{\alpha }^1=\sum _{i=1}^{l(\alpha )-1}\frac{1}{i!}\sum _{k_1,\ldots ,k_i=1}^d\frac{\partial ^i H_r}{\partial q_{k_1}\cdots \partial q_{k_i}}\mathop {\mathop {\sum }\limits _{l(\alpha _1)+\cdots +l(\alpha _i)=l(\alpha )-1}}\limits _ {\alpha -\in \varLambda _{ \alpha _1,\ldots ,\alpha _i}}\frac{\partial G_{\alpha _1}^1}{\partial P_{k_1}}\cdots \frac{\partial G_{\alpha _i}^1}{\partial P_{k_i}}\nonumber \\ \end{aligned}$$
(3.9)

for \(\alpha =(i_1,\ldots ,i_{l-1},r)\) with \(l>1\), \(i_1,\ldots ,i_{l-1},r\in \{0,1,\ldots ,m\}\), and there is no duplicate in \(\alpha \). If there are duplicates in \(\alpha \), one can still use the formula after assigning different subscripts to the duplicates. For \(l(\alpha )=1\), i.e., \(\alpha =(r)\), then

$$\begin{aligned} G_{(r)}^1=H_r. \end{aligned}$$
(3.10)

Note that, \(l(\alpha )\) denotes the length of \(\alpha \), and \(\alpha -\) is the multi-index resulted from discarding the last index of \(\alpha \).

With the \(G_{\alpha }^1\) given in (3.9), replacing the t by h, P by \(p_{n+1}\), and q by \(q_n\) in (3.6), and truncating the series (3.6) to certain terms, a symplectic scheme of corresponding order can be obtained via the relation (3.4).

Given the multi-index \(\alpha =(j_{1},j_{2},\ldots ,j_{l})\) and an adapted right continuous process f with left hand limits, define the multiple Itô integral [16]

$$\begin{aligned} I_{\alpha }:=\int _0^t\int _0^{s_l}\cdots \int _0^{s_2}dW_{j_1}(s_1) dW_{j_2}(s_2)\cdots dW_{j_l}(s_l), \end{aligned}$$
(3.11)

and

$$\begin{aligned} I_{\alpha }[f(\cdot )]_{0.t}:=\left\{ \begin{array}{l@{\quad }l}f(t),&{} \text{ if }\,\,\,\, l=0,\\ \int _{0}^{t}I_{\alpha -}[f(\cdot )]_{0,s}ds, &{}\text{ if }\,\,\,\, l\ge 1 \,and\, j_{l}=0,\\ \int _{0}^{t}I_{\alpha -}[f(\cdot )]_{0,s}dW^{j_{l}}_{s},&{}\text{ if }\,\,\,\,l\ge 1\,and\, j_{l}\ge 1.\end{array}\right. \end{aligned}$$
(3.12)

Then it holds the following relationship between the multiple Stratonovich integrals \(J_{\alpha }\) and the multiple Itô integrals \(I_{\alpha }\) [16]

$$\begin{aligned} J_{\alpha }=I_{(j_l)}[J_{\alpha -}]+\chi _{\{j_l=j_{l-1}\ne 0\}}I_{(0)} \left[ \frac{1}{2}J_{(\alpha -)-}\right] ,\quad l(\alpha )\ge 2, \end{aligned}$$
(3.13)

where \(\chi _A\) denotes the indicator function of set A and for \(l(\alpha )=1\), \(J_{\alpha }=I_{\alpha }\). To obtain a symplectic scheme of weak convergence order k, one can firstly transform the multiple Stratonovich integrals \(J_{\alpha }\) (3.7) to the multiple Itô integrals \(I_{\alpha }\) (3.11). Then, one should include in the truncation of the series (3.6) all terms with index \(\alpha \) satisfying \(l(\alpha )\le k\) [3, 4, 7, 16].

In Sect. 5, some examples of weakly convergent symplectic schemes for stochastic Hamiltonian systems produced by the generating functions are illustrated.

4 Modified equations for weakly convergent stochastic symplectic schemes via their generating functions

Inspired by the modified equation (2.3) with (2.4), we prove the following theorem about the modified equations of weakly convergent symplectic methods for stochastic Hamiltonian systems (3.1).

Theorem 4.1

Given a stochastic Hamiltonian system (3.1) for which the noises are additive, or the \(H_r(p,q),\,\,r\ge 1\) depend only on p or only on q. Suppose it has the generating function \(S^1(P(t),q,t)\), and a weakly convergent symplectic scheme \(\psi _h:(p,q)\mapsto (P,Q)\) produced by the generating function \(S^1(P,q,h)=\sum _{\alpha \in \varLambda _{\psi }}F_{\alpha }^1(P,q)\bar{I}_{\alpha }^h\), where \(F_{\alpha }^1(P,q)\) is defined on an open set D and can be a combination of some functions \(G_{\beta }^1(P,q)\) for appropriate multi-indices \(\beta \) when \(\alpha \) is fixed, and \(\bar{I}_{\alpha }^h\) are appropriate realizations of the multiple stochastic integrals \(I_{\alpha }^h\) as in (3.11) defined on (0, h). \(\varLambda _{\psi }\) is the set of indices associated with \(\psi _h\). Then the modified equation of the weakly convergent symplectic scheme \(\psi _h\) is a stochastic Hamiltonian system

$$\begin{aligned} \begin{aligned} d\tilde{P}&=-\frac{\partial \tilde{H}_{0}}{\partial \tilde{Q}}dt-\sum \limits _{r=1}^m \frac{\partial \tilde{H}_{r}}{\partial \tilde{Q}}\circ dW_r(t), \quad \tilde{P}(0)=p,\\ d\tilde{Q}&=\frac{\partial \tilde{H}_{0}}{\partial \tilde{P}}dt+\sum \limits _{r=1}^m \frac{\partial \tilde{H}_{r}}{\partial \tilde{P}}\circ dW_r(t),\quad \tilde{Q}(0)=q, \end{aligned} \end{aligned}$$
(4.1)

where

$$\begin{aligned} \begin{aligned} \tilde{H}_0&=H+H_0^{[1]}h+H_0^{[2]}h^2+\cdots ,\\ \tilde{H}_r&=H_r+H_r^{[1]}h+H_r^{[2]}h^2+\cdots , \end{aligned} \end{aligned}$$
(4.2)

and \(H_j^{[i]}(\tilde{P},\tilde{Q})\) are defined on D for \(j=0,1,2,\ldots ,m\), and \(i=1,2,\ldots \).

Proof

For convenience, denote \(H=H_0^{[0]}\), \(H_r=H_r^{[0]}\). The proof is also the procedure of finding the unknown functions \(H_j^{[i]}\), for \(j=0,1,2,\ldots ,m\), and \(i=1,2,\ldots \). Suppose the generating function that generates the stochastic Hamiltonian system (4.1) is \(\tilde{S}^1(\tilde{P}(t),q,t)\) which has the expansion

$$\begin{aligned} \tilde{S}^1(\tilde{P},q,t)=\sum _{\alpha }\tilde{G}_{\alpha }^1(\tilde{P},q,h)J_{\alpha }. \end{aligned}$$
(4.3)

According to the formula (3.9), we have for \(\alpha =(i_1,\ldots ,i_{l-1},r)\), with \(l\ge 2\)

$$\begin{aligned} \tilde{G}_{\alpha }^1=\sum ^{l(\alpha )-1}_{i=1}\frac{1}{i!}\sum _{k_1,\ldots ,k_i=1}^d\frac{\partial ^i \tilde{H}_r}{\partial q_{k_1}\cdots \partial q_{k_i}} \mathop {\mathop {\sum }\limits _{l(\alpha _1)+\cdots +l(\alpha _i)=l(\alpha )-1}}\limits _ {\alpha -\in \varLambda _{ \alpha _1,\ldots ,\alpha _i}}\frac{\partial \tilde{G}_{\alpha _1}^1}{\partial \tilde{P}_{k_1}}\cdots \frac{\partial \tilde{G}_{\alpha _i}^1}{\partial \tilde{P}_{k_i}}, \end{aligned}$$
(4.4)

and \(\tilde{G}_r^1=\tilde{H}_r\) for \(\alpha =(r)\). Now suppose

$$\begin{aligned} \tilde{G}_{\alpha }^1(\tilde{P},q,h)=G_{\alpha }^{1[0]}(\tilde{P},q)+G_{\alpha }^{1[1]}(\tilde{P},q)h+G_{\alpha }^{1[2]}(\tilde{P},q)h^2+\cdots . \end{aligned}$$
(4.5)

Substituting the series of \(\tilde{H}_r\) in (4.2), and that of \(\tilde{G}_{\alpha _j}^1\) \((j=1,\ldots ,i)\) as in (4.5) into the right hand side of (4.4), using (4.5) as the left hand side of (4.4), and then compare like powers of h on both sides of (4.4), we obtain for \(\alpha =(i_1,\ldots ,i_{l-1},r)\) with \(l\ge 2\)

$$\begin{aligned} G_{\alpha }^{1[k]}= & {} \sum \limits ^{l(\alpha )-1}_{i=1}\frac{1}{i!}\sum \limits _{k_1,\ldots ,k_i=1}^d\sum \nolimits _{j+j_1+\cdots +j_i=k}\frac{\partial ^i H_r^{[j]}}{\partial q_{k_1}\cdots \partial q_{k_i}}\nonumber \\&\times \mathop {\mathop {\sum }\limits _{l(\alpha _1)+\cdots +l(\alpha _i)=l(\alpha )-1}}\limits _{\alpha -\in \varLambda _{ \alpha _1,\ldots ,\alpha _i}}\frac{\partial G_{\alpha _1}^{1[j_1]}}{\partial \tilde{P}_{k_1}}\cdots \frac{\partial G_{\alpha _i}^{1[j_i]}}{\partial \tilde{P}_{k_i}}, \end{aligned}$$
(4.6)

and for \(\alpha =(r)\),

$$\begin{aligned} G_{(r)}^{1[k]}=H_r^{[k]}. \end{aligned}$$
(4.7)

According to (4.3) and (4.5), replacing t in (4.3) by h, we get

$$\begin{aligned} \tilde{S}^1(\tilde{P},q,h)=\sum _{\alpha }\sum _{k=0,1,\ldots }G_{\alpha }^{1[k]}(\tilde{P},q)h^k J_{\alpha }^h=\sum _{\alpha }\sum _{k=0,1,\ldots }G_{\alpha }^{1[k]}(\tilde{P},q)\sum _{\beta \in \varLambda _{ 0_k,\alpha }}k!J_{\beta }^h,\nonumber \\ \end{aligned}$$
(4.8)

where \(0_k\) denotes the index containing k zeros \(\underbrace{(0,\ldots ,0)}_{k}\). Since \(h^k=k!J_{0_k}\), the second equality in (4.8) is due to the relation [3, 7]

$$\begin{aligned} \prod _{i=1}^n J_{\alpha _i}=\sum _{\beta \in \varLambda _{ \alpha _1,\ldots ,\alpha _n}}J_{\beta }. \end{aligned}$$
(4.9)

Rearranging the summation terms in (4.8) according to different \(\beta \), we have

$$\begin{aligned} \tilde{S}^1(\tilde{P},q,h)= & {} \sum _{\beta }\left( \mathop {\mathop {\sum }\limits _{k=0,\ldots ,l(\beta )-1,}}\limits _{\beta \in \varLambda _ {0_k,\alpha }}k!\tau _{\beta }(0_k,\alpha )G_{\alpha }^{1[k]}(\tilde{P},q)\right) J_{\beta }^h,\nonumber \\=: & {} \sum _{\beta }\bar{G}_{\beta }^1(\tilde{P},q)J_{\beta }^h, \end{aligned}$$
(4.10)

where \(\tau _{\beta }(0_k,\alpha )\) denotes the number of \(\beta \) appearing in \(\varLambda _{0_k, \alpha }\), and

$$\begin{aligned} \bar{G}_{\beta }^1(\tilde{P},q):=\mathop {\mathop {\sum }\limits _{k=0,\ldots ,l(\beta )-1,}}\limits _{\beta \in \varLambda _{ 0_k,\alpha }}k!\tau _{\beta }(0_k,\alpha )G_{\alpha }^{1[k]}(\tilde{P},q). \end{aligned}$$
(4.11)

For simplicity, we denote in the following \(\tilde{P}(h)=\tilde{P}\), \(\tilde{Q}(h)=\tilde{Q}\), \(P(h)=P\), and \(Q(h)=Q\). Then we have

$$\begin{aligned} \tilde{P}=p-\frac{\partial \tilde{S}^1(\tilde{P},q,h)}{\partial q},\quad \tilde{Q}=q+\frac{\partial \tilde{S}^1(\tilde{P},q,h)}{\partial \tilde{P}}, \end{aligned}$$
(4.12)

which is equivalent to

$$\begin{aligned} \left( \begin{array}{c} \tilde{P}\\ \tilde{Q}\end{array}\right) =\left( \begin{array}{c} p\\ q\end{array}\right) +J^{-1}\nabla \tilde{S}^1(\tilde{P},q,h), \end{aligned}$$
(4.13)

with \(J=\left( \begin{array}{cc}0&{}1\\ -1&{}0\end{array}\right) \).

Theoretically, the first kind of generating function for strongly convergent symplectic schemes, denoted here by \(S^1_{s}(P,q,h)\) has the form

$$\begin{aligned} S^1_{s}(P,q,h)=\sum _{\beta }G_{\beta }^1(P,q)J_{\beta }^h. \end{aligned}$$
(4.14)

As is known from e.g. [4], the generating function for weakly convergent symplectic schemes can be obtained by transforming the \(J_{\beta }^h\) in (4.14) to their equivalent Itô integrals \(I_{\beta }^h\), choosing those terms with indices \(\beta \) satisfying \(l(\beta )\le k\) for a k-th order weakly convergent method, and then approximating the chosen \(I_{\beta }^h\) by some appropriate \(\bar{I}_{\beta }^h\). This can be expressed as the following, according to the transformation formula (3.13).

$$\begin{aligned} S^1(P,q,h)&=\sum _{\beta }G_{\beta }^1(P,q)\mathop {\mathop {\sum }\limits _{\alpha }}\limits _{ l(\alpha )\le k}C_{\alpha }^{\beta }\bar{I}_{\alpha }^h\nonumber \\&=\mathop {\mathop {\sum }\limits _{\alpha }}\limits _{l(\alpha )\le k}\left( \sum _{\beta }C_{\alpha }^{\beta }G_{\beta }^1(P,q)\right) \bar{I}_{\alpha }^h\nonumber \\&:=\mathop {\mathop {\sum }\limits _{\alpha }}\limits _ {l(\alpha )\le k}F_{\alpha }^1(P,q)\bar{I}_{\alpha }^h, \end{aligned}$$
(4.15)

where \(C_{\alpha }^{\beta }\) are some constants resulting from the transformation

$$\begin{aligned} J_{\beta }^h=\sum _{\alpha }C_{\alpha }^{\beta }I_{\alpha }^h, \end{aligned}$$
(4.16)

and \(F_{\alpha }^1(P,q)=:\sum _{\beta }C_{\alpha }^{\beta }G_{\beta }^1(P,q)\).

Suppose the symplectic method of weak convergence order k generated by the \(S^1(P,q,h)\) above is \(\psi _h:(p,q)\mapsto (P,Q)\), that is

$$\begin{aligned} P=p-\frac{\partial S^1(P,q,h)}{\partial q} ,\quad Q=q+\frac{\partial S^1(P,q,h)}{\partial P}, \end{aligned}$$
(4.17)

which is equivalent to

$$\begin{aligned} \left( \begin{array}{c}P\\ Q\end{array}\right) = \left( \begin{array}{c}p\\ q\end{array}\right) +J^{-1}\nabla S^1(P,q,h). \end{aligned}$$
(4.18)

Now we want to let the solution of the modified equation (4.1) be globally weakly \(k'\) order closer to the numerical method \(\psi _h\) than the exact solution of the original system (3.1) does, which means (see e.g. [36])

$$\begin{aligned} |\mathbf {E}\phi (P,Q)-\mathbf {E}\phi (\tilde{P},\tilde{Q})|=O(h^{k+k'+1}). \end{aligned}$$
(4.19)

According to (4.13) and (4.18), for each appropriate test functions \(\phi \) we have

$$\begin{aligned} \phi (P,Q)= & {} \phi (p,q)+\nabla \phi (p,q)\cdot J^{-1}\nabla S^1\nonumber \\&+\frac{1}{2!}\nabla ^2\phi (p,q)(J^{-1}\nabla S^1,J^{-1}\nabla S^1)+\cdots , \end{aligned}$$
(4.20)

where the functions \(\nabla S^1\) takes value at (Pqh), and

$$\begin{aligned} \phi (\tilde{P},\tilde{Q})= & {} \phi (p,q)+\nabla \phi (p,q)\cdot J^{-1}\nabla \tilde{S}^1\nonumber \\&+\frac{1}{2!}\nabla ^2\phi (p,q)(J^{-1}\nabla \tilde{S}^1,J^{-1}\nabla \tilde{S}^1)+\cdots , \end{aligned}$$
(4.21)

where the function \(\nabla \tilde{S}^1\) takes value at \((\tilde{P},q,h)\). Taking expectations on both sides of (4.20), it follows that

$$\begin{aligned} \mathbf {E}(\phi (P,Q))= & {} \phi (p,q)+\sum _{i=1}^d\frac{\partial \phi }{\partial p_i}(p,q)\mathbf {E}\left( -\frac{\partial S^1}{\partial q_i}\right) +\sum _{i=1}^d\frac{\partial \phi }{\partial q_i}(p,q)\mathbf {E}\left( \frac{\partial S^1}{\partial P_i}\right) \nonumber \\&+\frac{1}{2}\sum _{i,j=1}^d\frac{\partial ^2\phi }{\partial p_i\partial p_j}\mathbf {E}\left( \frac{\partial S^1}{\partial q_i}\frac{\partial S^1}{\partial q_j}\right) -\sum _{i,j=1}^d\frac{\partial ^2\phi }{\partial q_i\partial p_j}\mathbf {E}\left( \frac{\partial S^1}{\partial P_i}\frac{\partial S^1}{\partial q_j}\right) \nonumber \\&+\frac{1}{2}\sum _{i,j=1}^d\frac{\partial ^2\phi }{\partial q_i\partial q_j}\mathbf {E}\left( \frac{\partial S^1}{\partial P_i}\frac{\partial S^1}{\partial P_j}\right) +\cdots . \end{aligned}$$
(4.22)

Similarly,

$$\begin{aligned} \mathbf {E}(\phi (\tilde{P},\tilde{Q}))= & {} \phi (p,q)+\sum _{i=1}^d\frac{\partial \phi }{\partial p_i}(p,q)\mathbf {E}\left( -\frac{\partial \tilde{S}^1}{\partial q_i}\right) +\sum _{i=1}^d\frac{\partial \phi }{\partial q_i}(p,q)\mathbf {E}\left( \frac{\partial \tilde{S}^1}{\partial \tilde{P_i}}\right) \nonumber \\&+\frac{1}{2}\sum _{i,j=1}^d\frac{\partial ^2\phi }{\partial p_i\partial p_j}\mathbf {E}\left( \frac{\partial \tilde{S}^1}{\partial q_i}\frac{\partial \tilde{S}^1}{\partial q_j}\right) -\sum _{i,j=1}^d\frac{\partial ^2\phi }{\partial q_i\partial p_j}\mathbf {E}\left( \frac{\partial \tilde{S}^1}{\partial \tilde{P_i}}\frac{\partial \tilde{S}^1}{\partial q_j}\right) \nonumber \\&+\frac{1}{2}\sum _{i,j=1}^d\frac{\partial ^2\phi }{\partial q_i\partial q_j}\mathbf {E}\left( \frac{\partial \tilde{S}^1}{\partial \tilde{P_i}}\frac{\partial \tilde{S}^1}{\partial \tilde{P_j}}\right) +\cdots . \end{aligned}$$
(4.23)

Thus we have

$$\begin{aligned}&\mathbf {E}\phi (P,Q)-\mathbf {E}\phi (\tilde{P},\tilde{Q})\nonumber \\&\quad =\sum _{i=1}^d\frac{\partial \phi }{\partial p_i}(p,q)\mathbf {E}\left( \frac{\partial S^1}{\partial q_i}-\frac{\partial \tilde{S}^1}{\partial q_i}\right) +\sum _{i=1}^d\frac{\partial \phi }{\partial q_i}(p,q)\mathbf {E}\left( \frac{\partial S^1}{\partial P_{i}}-\frac{\partial \tilde{S}^1}{\partial \tilde{P_i}}\right) \nonumber \\&\qquad +\frac{1}{2}\sum _{i,j=1}^d\frac{\partial ^2\phi }{\partial p_i\partial p_j}\mathbf {E}\left( \frac{\partial S^1}{\partial q_i}\frac{\partial S^1}{\partial q_j}-\frac{\partial \tilde{S}^1}{\partial q_i}\frac{\partial \tilde{S}^1}{\partial q_j}\right) \nonumber \\&\qquad -\sum _{i,j=1}^d\frac{\partial ^2\phi }{\partial q_i\partial p_j}\mathbf {E}\left( \frac{\partial S^1}{\partial P_{i}}\frac{\partial S^1}{\partial q_j}-\frac{\partial \tilde{S}^1}{\partial \tilde{P_i}}\frac{\partial \tilde{S}^1}{\partial q_j}\right) \nonumber \\&\qquad +\frac{1}{2}\sum _{i,j=1}^d\frac{\partial ^2\phi }{\partial q_i\partial q_j}\mathbf {E}\left( \frac{\partial S^1}{\partial P_{i}}\frac{\partial S^1}{\partial P_{j}}-\frac{\partial \tilde{S}^1}{\partial \tilde{P_i}}\frac{\partial \tilde{S}^1}{\partial \tilde{P_j}}\right) +\cdots , \end{aligned}$$
(4.24)

and we need to let every item in the right hand side of (4.24) be not more than \(O(h^{k+k'+1})\), with \(k+k'\ge 2\). Note that, after taking expectations, the terms of order \(h^{\frac{1}{2}}\), \(h^{\frac{3}{2}}\), etc. vanish, so we only need to consider terms of integer orders of h. Since the lowest order of the \(J_{\alpha }\) is \(\frac{1}{2}\), the highest degree of the partial derivatives that can produce h is 2. Analogously, the highest degree of the partial derivatives that can produce \(h^{s}\) is 2s where s is a positive integer.

Therefore, for the coefficients of h, we only need to let them be equal within each of the following pairs, for \(i,j=1,\ldots ,d\),

$$\begin{aligned}&\mathbf {E}\frac{\partial S^1}{\partial q_i}\,\,\,\, \text{ and } \,\,\,\, \mathbf {E}\frac{\partial \tilde{S}^1}{\partial q_i};\quad \mathbf {E}\frac{\partial S^1}{\partial P_i}\,\,\,\, \text{ and } \,\,\,\, \mathbf {E}\frac{\partial \tilde{S}^1}{\partial \tilde{P}_i};\quad \mathbf {E}\left( \frac{\partial S^1}{\partial q_i}\frac{\partial S^1}{\partial q_j}\right) \,\,\,\, \text{ and } \,\,\,\,\mathbf {E}\left( \frac{\partial \tilde{S}^1}{\partial q_i}\frac{\partial \tilde{S}^1}{\partial q_j}\right) ;\nonumber \\&\mathbf {E}\frac{\partial S^1}{\partial q_i}\frac{\partial S^1}{\partial P_j}\,\,\,\, \text{ and } \,\,\,\, \mathbf {E}\frac{\partial \tilde{S}^1}{\partial q_i}\frac{\partial \tilde{S}^1}{\partial \tilde{P_j}};\quad \mathbf {E}\left( \frac{\partial S^1}{\partial P_i}\frac{\partial S^1}{\partial P_j}\right) \,\,\,\, \text{ and } \,\,\,\, \mathbf {E}\left( \frac{\partial \tilde{S}^1}{\partial \tilde{P}_i}\frac{\partial \tilde{S}^1}{\partial \tilde{P}_j}\right) , \end{aligned}$$
(4.25)

where the derivatives of \(S^1\) take value at (Pqh), whereas those of \(\tilde{S}^1\) take value at \((\tilde{P},q,h)\).

For instance, to compare the first pair in (4.25), we should perform Taylor expansion of the partial derives of \(S^1(P,q,h)\) and those of \(\tilde{S}^1(\tilde{P},q,h)\) at (pqh) recursively, and we get

$$\begin{aligned}&\mathbf {E}\frac{\partial S^1}{\partial q_i}(P,q,h)\\&\quad =\sum _{\alpha \in \varLambda _{\psi }}\mathbf {E}\left( \frac{\partial F_{\alpha }^{1}}{\partial q_i}(p,q,h)+\sum _{j=1}^d\frac{\partial ^2 F_{\alpha }^{1}}{\partial q_i \partial P_j}(p,q,h)\left( -\frac{\partial S^1}{\partial q_j}(P,q,h)\right) +\cdots \right) \bar{I}_{\alpha }^h \end{aligned}$$

and

$$\begin{aligned}&\mathbf {E}\frac{\partial \tilde{S}^1}{\partial q_i}(\tilde{P},q,h)\\&\quad =\sum _{\beta }\mathbf {E}\left( \frac{\partial \bar{G}_{\beta }^{1}}{\partial q_i}(p,q,h)+\sum _{j=1}^d\frac{\partial ^2 \bar{G}_{\beta }^{1}}{\partial q_i \partial \tilde{P}_j}(p,q,h)\left( -\frac{\partial \tilde{S}^1}{\partial q_j}(\tilde{P},q,h)\right) +\cdots \right) J_{\beta }^h, \end{aligned}$$

where the partial derives of \(S^1\) and those of \(\tilde{S}^1\) inside the expectation \(\mathbf {E}\) are to be expanded at (pqh) in the same way once again and further on. In this way we can compare like powers of h in \(\mathbf {E}\frac{\partial S^1}{\partial q_i}(P,q,h)\) and \(\mathbf {E}\frac{\partial \tilde{S}^1}{\partial q_i}(\tilde{P},q,h)\).

It is worth mentioning that, the \(\bar{I}_{\alpha }^h\) are approximations of \(I_{\alpha }^h\), and the approximation error can be controlled by choosing appropriate truncation boundary of the Gaussian random variables so that it will affect neither the convergence order of the numerical methods, nor the finding of the modified equation of desired order by comparing like powers of h within each pair, as will be explained in more details in Appendix 1.

Notice that the pairs given in (4.25) contain all possible \(h^i\) with \(i\ge 1\), so for the coefficients of \(h^2\), the pairs in (4.25) still need to be compared, and in addition, we also need to have the coefficients of \(h^2\) equal within each of the following pairs, for \(i,j,l,s=1,\ldots ,d\),

$$\begin{aligned}&\mathbf {E}\left( \frac{\partial S^1}{\partial q_i}\frac{\partial S^1}{\partial q_j}\frac{\partial S^1}{\partial q_l}\right) \,\,\,\, \text{ and } \,\,\,\, \mathbf {E}\left( \frac{\partial \tilde{S}^1}{\partial q_i}\frac{\partial \tilde{S}^1}{\partial q_j}\frac{\partial \tilde{S}^1}{\partial q_l}\right) ;\nonumber \\&\mathbf {E}\left( \frac{\partial S^1}{\partial q_i}\frac{\partial S^1}{\partial q_j}\right) \frac{\partial S^1}{\partial P_l}\,\,\,\, \text{ and } \,\,\,\, \mathbf {E}\left( \frac{\partial \tilde{S}^1}{\partial q_i}\frac{\partial \tilde{S}^1}{\partial q_j}\right) \frac{\partial \tilde{S}^1}{\partial \tilde{P_l}};\nonumber \\&\mathbf {E}\frac{\partial S^1}{\partial q_i}\left( \frac{\partial S^1}{\partial P_j}\frac{\partial S^1}{\partial P_l}\right) \,\,\,\, \text{ and } \,\,\,\, \mathbf {E}\frac{\partial \tilde{S}^1}{\partial q_i}\left( \frac{\partial \tilde{S}^1}{\partial \tilde{P}_j}\frac{\partial \tilde{S}^1}{\partial \tilde{P}_l}\right) ;\nonumber \\&\mathbf {E}\left( \frac{\partial S^1}{\partial P_i}\frac{\partial S^1}{\partial P_j}\frac{\partial S^1}{\partial P_l}\right) \,\,\,\, \text{ and } \,\,\,\, \mathbf {E}\left( \frac{\partial \tilde{S}^1}{\partial \tilde{P}_i}\frac{\partial \tilde{S}^1}{\partial \tilde{P}_j}\frac{\partial \tilde{S}^1}{\partial \tilde{P}_l}\right) ;\nonumber \\&\mathbf {E}\left( \frac{\partial S^1}{\partial q_i}\frac{\partial S^1}{\partial q_j}\frac{\partial S^1}{\partial q_l}\frac{\partial S^1}{\partial q_s}\right) \,\,\,\, \text{ and } \,\,\,\, \mathbf {E}\left( \frac{\partial \tilde{S}^1}{\partial q_i}\frac{\partial \tilde{S}^1}{\partial q_j}\frac{\partial \tilde{S}^1}{\partial q_l}\frac{\partial \tilde{S}^1}{\partial q_s}\right) ;\nonumber \\&\mathbf {E}\left( \frac{\partial S^1}{\partial q_i}\frac{\partial S^1}{\partial q_j}\frac{\partial S^1}{\partial q_l}\right) \frac{\partial S^1}{\partial P_s}\,\,\,\, \text{ and } \,\,\,\, \mathbf {E}\left( \frac{\partial \tilde{S}^1}{\partial q_i}\frac{\partial \tilde{S}^1}{\partial q_j}\frac{\partial \tilde{S}^1}{\partial q_l}\right) \frac{\partial \tilde{S}^1}{\partial \tilde{P}_s};\nonumber \\&\mathbf {E}\left( \frac{\partial S^1}{\partial q_i}\frac{\partial S^1}{\partial q_j}\right) \left( \frac{\partial S^1}{\partial P_l}\frac{\partial S^1}{\partial P_s}\right) \,\,\,\, \text{ and } \,\,\,\, \mathbf {E}\left( \frac{\partial \tilde{S}^1}{\partial q_i}\frac{\partial \tilde{S}^1}{\partial q_j}\right) \left( \frac{\partial \tilde{S}^1}{\partial \tilde{P}_l}\frac{\partial \tilde{S}^1}{\partial \tilde{P}_s}\right) ;\nonumber \\&\mathbf {E}\frac{\partial S^1}{\partial q_i}\left( \frac{\partial S^1}{\partial P_j}\frac{\partial S^1}{\partial P_l}\frac{\partial S^1}{\partial P_s}\right) \,\,\,\, \text{ and } \,\,\,\, \mathbf {E}\frac{\partial \tilde{S}^1}{\partial q_i}\left( \frac{\partial \tilde{S}^1}{\partial \tilde{P}_j}\frac{\partial \tilde{S}^1}{\partial \tilde{P}_l}\frac{\partial \tilde{S}^1}{\partial \tilde{P}_s}\right) ;\nonumber \\&\mathbf {E}\left( \frac{\partial S^1}{\partial P_i}\frac{\partial S^1}{\partial P_j}\frac{\partial S^1}{\partial P_l}\frac{\partial S^1}{\partial P_s}\right) \,\,\,\, \text{ and } \,\,\,\, \mathbf {E}\left( \frac{\partial \tilde{S}^1}{\partial \tilde{P}_i}\frac{\partial \tilde{S}^1}{\partial \tilde{P}_j}\frac{\partial \tilde{S}^1}{\partial \tilde{P}_l}\frac{\partial \tilde{S}^1}{\partial \tilde{P}_s}\right) . \end{aligned}$$
(4.26)

Further on, for a modified equation of weak \(k+k'\) order apart from the numerical method, the coefficients in pairs up to those of \(2(k+k')\)-th power of the partial derivatives of \(S^1\) and \(\tilde{S}^1\) need to be equated. In this process the unknown functions \(H_{j}^{[i]}\) for \(j=0,1,2,\ldots \) and \(i=1,2,\ldots \) can be determined.

Meanwhile, we obtain the inequalities implying the boundary of the truncated Gaussian random variables in \(\bar{I}_{\alpha }^h\) that guarantees the desired convergence order of the modified equation not being affected by the error between \(\bar{I}_{\alpha }^h\) and \(I_{\alpha }^h\), See Appendix 1 for an illustrating explanation.

Notice that, it is natural that we want to have the solution for the basic non-trivial case where \(k=1\) and \(k'=1\). In this case, as we compare the coefficients of \(h^2\) in e.g. \(\mathbf {E}\left( \frac{\partial S^1}{\partial q_i}\right) ^2\) and \(\mathbf {E}\left( \frac{\partial \tilde{S}^1}{\partial q_i}\right) ^2\), we should have

$$\begin{aligned} \left( \frac{\partial }{\partial q_i}\left( G_{(0)}^1+\frac{1}{2}\sum _{r=1}^mG_{(r,r)}^1\right) \right) ^2= & {} \left( \frac{\partial }{\partial q_i}\left( \bar{G}_{(0)}^1+\frac{1}{2}\sum _{r=1}^m\bar{G}_{(r,r)}^1\right) \right) ^2\nonumber \\&+\frac{1}{2}\sum _{r=1}^m\left( \frac{\partial }{\partial q_i}\bar{G}_{(r,r)}\right) ^2, \end{aligned}$$
(4.27)

where the functions take values at (pq). Since

$$\begin{aligned} G_{(0)}^1(p,q)=\bar{G}_{(0)}^1(p,q), \quad G_{(r,r)}^1(p,q)=\bar{G}_{(r,r)}^1(p,q), \end{aligned}$$

we must have

$$\begin{aligned} \frac{\partial }{\partial q_i}\bar{G}_{(r,r)}=0, \quad r=1,\ldots ,m,\quad i=1,\ldots ,d. \end{aligned}$$
(4.28)

Analogously, it should hold

$$\begin{aligned} \frac{\partial }{\partial p_i}\bar{G}_{(r,r)}=0,\quad r=1,\ldots ,m,\quad i=1,\ldots ,d. \end{aligned}$$
(4.29)

(4.28), (4.29), (4.11), (4.6) and (4.7) imply that \(H_r(p,q),\, r=1,\ldots ,m\) should either be linear functions of p and q, or they should depend only on p or only on q, where the former means that the noises of the stochastic Hamiltonian system are additive, while the latter includes also multiplicative noises. \(\square \)

5 Some examples

Example 1

Modified equation of weak order two apart from the symplectic scheme of weak order 1 for the linear stochastic oscillator (5.1) i.e. \(k=1\) and \(k'=1\)

The linear stochastic oscillator [30]

$$\begin{aligned} dp= & {} -qdt+\sigma dW(t),\quad p(0)=0,\nonumber \\ dq= & {} pdt,\quad q(0)=1 \end{aligned}$$
(5.1)

is a stochastic Hamiltonian system with \(H=\frac{1}{2}(p^2+q^2)\), \(H_1=-\sigma q\). According to (3.9) and (3.10), the coefficient functions \(G_{\alpha }^1\) of the generating function \(S^1\) associated with this system are

$$\begin{aligned} G_{(0)}^1= & {} H=\frac{1}{2}(P^2+q^2),\quad G_{(1)}^1=H_1=-\sigma q,\quad G_{(1,1)}^1=0,\nonumber \\ G_{(0,1)}^1= & {} -\sigma P,\quad G_{(1,0)}^1=0, \quad G_{(1,1,1)}^1=0,\quad G_{(0,0)}^1=Pq,\,\,\ldots . \end{aligned}$$
(5.2)

To obtain a symplectic method of weak order 1, however, we only need to include in the series of \(S^1\) those terms of \(I_{\alpha }\) with \(l(\alpha )\le 1\). For this, we should use the relations

$$\begin{aligned} J_{(0)}=I_{(0)},\quad J_{(1)}=I_{(1)},\quad J_{(1,1)}=I_{(1,1)}+\frac{1}{2}I_{(0)}, \end{aligned}$$
(5.3)

to get the correct coefficient of \(I_{(0)}\), which is then \(G_{(0)}^1+\frac{1}{2}G_{(1,1)}^1\), and that of \(I_{(1)}\) which is \(G_{(1)}^1\). Thus, the generating function for a symplectic scheme of weak order 1 is

$$\begin{aligned} S^1(P,q,h)=G_{(1)}^1 \sqrt{h}\bar{\xi }+\left( G_{(0)}^1+\frac{1}{2}G_{(1,1)}^1\right) h, \end{aligned}$$
(5.4)

where

$$\begin{aligned} \bar{\xi }=\left\{ \begin{array}{ll}-A_h,&{}\xi <-A_h,\\ \xi ,&{}|\xi |\le A_h,\\ A_h,&{}\xi > A_h,\end{array}\right. \end{aligned}$$

with \(\xi \sim \mathscr {N}(0,1)\) and \(A_h=\sqrt{6\ln |h|}\), where the coefficient 6 is chosen according to the analysis in Appendix 1.

Using the relation (3.4), the symplectic scheme of weak order 1 generated by (5.4) is

$$\begin{aligned} \begin{array}{l} p_{n+1}=p_n-hq_n+\sigma \sqrt{h}\bar{\xi },\\ q_{n+1}=q_n+hp_{n+1},\end{array} \end{aligned}$$
(5.5)

which is just the stochastic symplectic Euler method. We next find the \(\tilde{S}^1=\sum _{\alpha }\bar{G}_{\alpha }^1J_{\alpha }^h\) associated with this method. According to the formulae (4.11), (4.6) and (4.7), we have

$$\begin{aligned} \bar{G}_{(0)}^1= & {} G_{(0)}^{1[0]}=H_0^{[0]}=H=\frac{1}{2}(\tilde{P}^2+q^2),\quad \bar{G}_{(1)}^1=G_{(1)}^{1[0]}=H_1^{[0]}=H_1=-\sigma q,\nonumber \\ \bar{G}_{(1,1)}^1= & {} G_{(1,1)}^{1[0]}=\frac{\partial H_1^{[0]}}{\partial q}\frac{\partial G_{(1)}^{1[0]}}{\partial \tilde{P}}=0,\nonumber \\ \bar{G}_{(0,1)}^1= & {} G_{(0,1)}^{1[0]}+G_{(1)}^{1[1]}=\frac{\partial H_1^{[0]}}{\partial q}\frac{\partial G_{(0)}^{1[0]}}{\partial \tilde{p}}+H_1^{[1]}=-\sigma \tilde{P}+H_1^{[1]},\nonumber \\ \bar{G}_{(1,0)}^1= & {} G_{(1,0)}^{1[0]}+G_{(1)}^{1[1]}=\frac{\partial H_0^{[0]}}{\partial q}\frac{\partial G_{(1)}^{1[0]}}{\partial \tilde{P}}+H_1^{[1]}=H_1^{[1]},\nonumber \\ \bar{G}_{(0,0)}^1= & {} G_{(0,0)}^{1[0]}+2G_{(0)}^{1[1]}=\frac{\partial H_0^{[0]}}{\partial q}\frac{\partial G_{(0)}^{1[0]}}{\partial \tilde{P}}+2H_0^{[1]}=\tilde{P}q+2H_0^{[1]},\nonumber \\ \bar{G}_{(1,1,0)}^1= & {} G_{(1,1,0)}^{1[0]}+G_{(1,1)}^{1[1]}\nonumber \\= & {} \frac{\partial H_0^{[0]}}{\partial q}\frac{\partial G_{(1,1)}^{1[0]}}{\partial \tilde{P}}+\frac{\partial ^2 H_0^{[0]}}{\partial q^2}\frac{\partial G_{(1)}^{1[0]}}{\partial \tilde{P}}^2+\frac{\partial H_1^{[0]}}{\partial q}\frac{\partial G_{(1)}^{1[1]}}{\partial \tilde{P}}+\frac{\partial H_1^{[1]}}{\partial q}\frac{\partial G_{(1)}^{1[0]}}{\partial \tilde{P}}\nonumber \\= & {} -\sigma \frac{\partial H_1^{[1]}}{\partial \tilde{ P}}\nonumber \\ \bar{G}_{(0,1,1)}^1= & {} G_{(0,1,1)}^{1[0]}+G_{(1,1)}^{1[1]}\nonumber \\= & {} \frac{\partial H_1^{[0]}}{\partial q}\frac{\partial G_{(0,1)}^{1[0]}}{\partial \tilde{P}}+\frac{\partial ^2 H_1^{[0]}}{\partial q^2}\frac{\partial G_{(1)}^{1[0]}}{\partial \tilde{P}}\frac{\partial G_{(0)}^{1[0]}}{\partial \tilde{P}}+\frac{\partial H_1^{[0]}}{\partial q}\frac{\partial G_{(1)}^{1[1]}}{\partial \tilde{P}}+\frac{\partial H_1^{[1]}}{\partial q}\frac{\partial G_{(1)}^{1[0]}}{\partial \tilde{P}}\nonumber \\= & {} \sigma ^2-\sigma \frac{\partial H_1^{[1]}}{\partial \tilde{P}},\nonumber \\ \bar{G}_{(1,1,1)}^1= & {} G_{(1,1,1)}^{1[0]}=\frac{\partial H_1^{[0]}}{\partial q}\frac{\partial G_{(1,1)}^{1[0]}}{\partial \tilde{P}}+\frac{\partial ^2 H_1^{[0]}}{\partial q^2}\frac{\partial G_{(1)}^{1[0]}}{\partial \tilde{P}}^2=0,\nonumber \\ \bar{G}_{(1,1,1,1)}^1= & {} G_{(1,1,1,1)}^{1[0]}=\frac{\partial H_1^{[0]}}{\partial q}\frac{\partial G_{(1,1,1)}^{1[0]}}{\partial \tilde{P}}+3\frac{\partial ^2 H_1^{[0]}}{\partial q^2}\frac{\partial G_{(1,1)}^{1[0]}}{\partial \tilde{P}}\frac{\partial G_{(1)}^{1[0]}}{\partial \tilde{P}}+\frac{\partial ^3 H_1^{[0]}}{\partial q^3}\frac{\partial G_{(1)}^{1[0]}}{\partial \tilde{P}}^3\nonumber \\= & {} 0,\nonumber \\ \vdots \end{aligned}$$
(5.6)

It is easy to check that the coefficients of h within each pair in (4.25) are naturally equal. Equating the coefficients of \(h^2\) within each pair in (4.25) and (4.26) gives

$$\begin{aligned}&\frac{1}{2}\sigma \frac{\partial ^2H_1^{[1]}}{\partial p\partial q}-\frac{\partial H_0^{[1]}}{\partial q}=\frac{1}{2}p, \end{aligned}$$
(5.7)
$$\begin{aligned}&\frac{1}{2}\sigma \frac{\partial ^2H_1^{[1]}}{\partial p^2}-\frac{\partial H_0^{[1]}}{\partial p} =\frac{1}{2}q, \end{aligned}$$
(5.8)
$$\begin{aligned}&\frac{\partial H_1^{[1]}}{\partial q}=0, \end{aligned}$$
(5.9)
$$\begin{aligned}&\frac{\partial H_1^{[1]}}{\partial p}=\frac{1}{2}\sigma . \end{aligned}$$
(5.10)

Substituting (5.9) into (5.7) and (5.8) gives

$$\begin{aligned} \frac{\partial H_0^{[1]}}{\partial p}=-\frac{1}{2}q,\quad \frac{\partial H_0^{[1]}}{\partial q}=-\frac{1}{2}p. \end{aligned}$$
(5.11)

Thus, according to (4.1)–(4.2), the modified equation of weak second order apart from the numerical method (5.5) is

$$\begin{aligned} dp= & {} \left( -q+h\frac{p}{2}\right) dt+\sigma dW(t),\nonumber \\ dq= & {} \left( p-h\frac{q}{2}\right) dt+h\frac{\sigma }{2} dW(t), \end{aligned}$$
(5.12)

which coincides with the result (Eq. (4.16) in [36]) about the modified equation of the symplectic Euler method for a Langevin equation (Eq. (4.14) in [36]) as \(V'(q)=q\) and \(\gamma =0\).

For the modified equation of weak third order apart from the numerical method (5.5), we need to equate the coefficients of \(h^3\) within corresponding pairs to determine more unknown coefficients \(H_j^{[i]}\), and so on and so forth for even higher orders.

Example 2

Modified equation for a symplectic scheme of weak order 2 for the linear stochastic oscillator (5.1).

For obtaining a symplectic scheme of weak second order, we still need to calculate the following \(G_\alpha ^1\) in addition to those in (5.2)

$$\begin{aligned} G_{(1,1,0)}^1=0,\quad G_{(0,1,1)}^1=\sigma ^2,\quad G_{(1,0,1)}^1=0,\quad G_{(1,1,1,1)}^1=0. \end{aligned}$$
(5.13)

Thus, the corresponding generating function is

$$\begin{aligned} S^1(P,q,h)= & {} -\sigma q \sqrt{h}\bar{\xi }+\frac{1}{2}(P^2+q^2)h-\sigma P\left( \frac{\bar{\xi }}{2}-\frac{\sqrt{3}\bar{\eta }}{6}\right) h^{\frac{3}{2}}\nonumber \\&+\left( Pq+\frac{1}{2}\sigma ^2\right) \frac{h^2}{2}, \end{aligned}$$
(5.14)

where \(\bar{\eta }\) is the truncation of the \(\mathscr {N}(0,1)\) random variable \(\eta \) which is independent to \(\xi \) and has the same boundary \(A_{h}=\sqrt{8|\ln h|}\) as the random variable \(\bar{\xi }\) does (see Appendix 1 for the choice of the value 8), and \(\left( \frac{\bar{\xi }}{2}-\frac{\sqrt{3}\bar{\eta }}{6}\right) h^{\frac{3}{2}}\) is the simulation of \(I_{(0,1)}\) (see e.g. [21]). The numerical scheme generated by it is

$$\begin{aligned} \begin{aligned} p_{n+1}&=p_n-h q_n+\sigma \sqrt{h}\bar{\xi }-\frac{p_{n+1}}{2}h^2\\ q_{n+1}&=q_n+hp_{n+1}-\sigma \left( \frac{\bar{\xi }}{2}-\frac{\sqrt{3}\bar{\eta }}{6}\right) h^{\frac{3}{2}} +\frac{q_n}{2} h^2. \end{aligned} \end{aligned}$$
(5.15)

In addition to the \(\bar{G}_\alpha \) in (5.6), we also need to have the following

$$\begin{aligned} \begin{aligned} \bar{G}_{(0,0,1)}^1&=-\sigma q+2H_1^{[2]},\quad \bar{G}_{(1,0,0)}^1=2H_1^{[2]},\quad \bar{G}_{(0,1,0)}^1=-\sigma q+2H_1^{[2]},\\ \bar{G}_{(1,0,1,1)}^1&=\bar{G}_{(1,1,0,1)}^1=\bar{G}_{(1,1,1,0)}^1=\bar{G}_{(0,1,1,1)}^1=\bar{G}_{(1,1,1,1,1)}^1=0,\\ \bar{G}_{(0,0,0)}^1&=q^2+\tilde{P}^2+6H_{0}^{[2]}, \end{aligned} \end{aligned}$$
(5.16)

and all the other \(\bar{G}_\alpha ^1\)s needed for constructing the modified equation for the symplectic scheme of weak second order, such as \(\bar{G}_{(0,0,1,1)}^1\), \(\bar{G}_{(1,1,1,1,0)}^1\) and so on, are all equal to zero. Comparing coefficients of h, \(h^2\) within each pairs of (4.25) and (4.26), and those of \(h^3\) within corresponding pairs, we obtain the following equations

$$\begin{aligned}&\frac{\partial H_1^{[1]}}{\partial q}=0,\quad \frac{\partial H_1^{[1]}}{\partial p}=0,\quad \frac{\partial H_0^{[1]}}{\partial q}=0,\quad \frac{\partial H_0^{[1]}}{\partial p}=0,\nonumber \\&2\sigma -6\frac{\partial H_1^{[2]}}{\partial q}=0,\quad \frac{\partial H_1^{[2]}}{\partial p}=0,\quad 2q+6\frac{\partial H_0^{[2]}}{\partial q}=0,\quad 2p+6\frac{\partial H_0^{[2]}}{\partial p}=0,\nonumber \\ \end{aligned}$$
(5.17)

from which it results that

$$\begin{aligned} \frac{\partial H_0^{[2]}}{\partial q}=-\frac{q}{3},\quad \frac{\partial H_0^{[2]}}{\partial p}=-\frac{p}{3},\quad \frac{\partial H_1^{[2]}}{\partial p}=0,\quad \frac{\partial H_1^{[2]}}{\partial q}=\frac{\sigma }{3}. \end{aligned}$$
(5.18)

Therefore the modified equation third order apart from the the numerical method (5.15) which is of weak order 2, is

$$\begin{aligned} dp= & {} \left( -q+h^2\frac{q}{3}\right) dt+ \left( \sigma -h^2\frac{\sigma }{3}\right) dW(t),\nonumber \\ dq= & {} \left( p-h^2\frac{p}{3}\right) dt. \end{aligned}$$
(5.19)

Example 3

A model for synchrotron oscillations of particles in storage rings oscillator The model [20] is

$$\begin{aligned} dp= & {} -\omega ^2 \sin q dt-\sigma _1 \cos q \circ dW_1(t)-\sigma _2 \sin q\circ dW_2(t),\nonumber \\ dq= & {} pdt, \end{aligned}$$
(5.20)

where p and q are scaler. It is a stochastic Hamiltonian system with

$$\begin{aligned} H_0=-\omega ^2\cos q+\frac{1}{2}p^2,\quad H_1=\sigma _1\sin q,\quad H_2=-\sigma _2\cos q. \end{aligned}$$
(5.21)

According to (3.9) and (3.10),

$$\begin{aligned} G_{(0)}^1= & {} H_0=-\omega ^2\cos q+\frac{1}{2}P^2,\quad G_{(1)}^1=H_1=\sigma _1\sin q,\nonumber \\ G_{(2)}^1= & {} H_2=-\sigma _2\cos q,\quad G_{(1,1)}^1=G_{(2,2)}=0,\ldots . \end{aligned}$$
(5.22)

Thus the generating function \(S^1\) for a symplectic scheme of weak order 1 is

$$\begin{aligned} S^1(P,q,h)=\left( G_{(0)}^1+\frac{1}{2}G_{(1,1)}^1+\frac{1}{2}G_{(2,2)}^1 \right) h+G_{(1)}^1\sqrt{h}\bar{\xi }+G_{(2)}^1\sqrt{h}\bar{\eta }, \end{aligned}$$
(5.23)

and the scheme generated by it via the relation (3.4) is

$$\begin{aligned} p_{n+1}= & {} p_n-\left( h\omega ^2\sin q_n+ \sqrt{h}\bar{\xi }\sigma _1 \cos q_n+\sqrt{h}\bar{\eta } \sigma _2 \sin q_n\right) ,\nonumber \\ q_{n+1}= & {} q_n+hp_{n+1}, \end{aligned}$$
(5.24)

where the bounds of the truncations \(\bar{\xi }\) and \(\bar{\eta }\) are both \(A_h=\sqrt{6|\ln h|}\).

For the generating function \(\tilde{S}^1(\tilde{P},q,t)\) of the modified equation of (5.24) at \(t=h\) we have \(\tilde{S}^1(\tilde{P},q,h)=\sum _{\alpha }\bar{G}_{\alpha }(\tilde{P},q)J_{\alpha }^h\), where, according to the formulae (4.11), (4.6) and (4.7),

$$\begin{aligned} \bar{G}_{(0)}^1= & {} G_{(0)}^{1{[0]}}=H_0^{[0]}=H_0=-\omega ^2\cos q+\frac{1}{2}\tilde{P}^2,\\ \bar{G}_{(1)}^1= & {} G_{(1)}^{1{[0]}}=H_1^{[0]}=H_1=\sigma _1\sin q,\\ \bar{G}_{(2)}^1= & {} G_{(2)}^{1{[0]}}=H_2^{[0]}=H_2=-\sigma _2\cos q,\quad \bar{G}_{(1,1)}^1=G_{(1,1)}^{1{[0]}}=\frac{\partial H_1^{[0]}}{\partial q}\frac{\partial G_{(1)}^{1[0]}}{\partial \tilde{P}}=0,\\ \bar{G}_{(1,2)}^1= & {} G_{(1,2)}^{1[0]}=\frac{\partial H_2^{[0]}}{\partial q}\frac{\partial G_{(1)}^{1[0]}}{\partial \tilde{P}}=0,\quad \bar{G}_{(2,1)}^1=G_{(2,1)}^{1[0]}=\frac{\partial H_1^{[0]}}{\partial q}\frac{\partial G_{(2)}^{1[0]}}{\partial \tilde{P}}=0,\\ \bar{G}_{(2,2)}^1= & {} G_{(2,2)}^{1[0]}=\frac{\partial H_2^{[0]}}{\partial q}\frac{\partial G_{(2)}^{1[0]}}{\partial \tilde{P}}=0,\\ \bar{G}_{(0,1)}^1= & {} G_{(0,1)}^{1[0]}+G_{(1)}^{1[1]}=\frac{\partial H_1^{[0]}}{\partial q}\frac{\partial G_{(0)}^{1[0]}}{\partial \tilde{P}}+H_1^{[1]}=\sigma _1 \tilde{P}\cos q+H_1^{[1]},\\ \bar{G}_{(0,2)}^1= & {} G_{(0,2)}^{1[0]}+G_{(2)}^{1[1]}=\frac{\partial H_2^{[0]}}{\partial q}\frac{\partial G_{(0)}^{1[0]}}{\partial \tilde{P}}+H_2^{[1]}=\sigma _2 \tilde{P}\sin q+H_2^{[1]},\\ \bar{G}_{(1,0)}^1= & {} G_{(1,0)}^{1[0]}+G_{(1)}^{1[1]}=\frac{\partial H_0^{[0]}}{\partial q}\frac{\partial G_{(1)}^{[0]}}{\partial \tilde{P}}+H_1^{[1]}=H_1^{[1]},\\ \end{aligned}$$
$$\begin{aligned} \bar{G}_{(2,0)}^1= & {} G_{(2,0)}^{1[0]}+G_{(2)}^{1[1]}=\frac{\partial H_0^{[0]}}{\partial q}\frac{\partial G_{(2)}^{1[0]}}{\partial \tilde{P}}+H_2^{[1]}=H_2^{[1]},\\ \bar{G}_{(1,1,1)}^1= & {} G_{(1,1,1)}^{1[0]}=\frac{\partial H_1^{[0]}}{\partial q}\frac{\partial G_{(1,1)}^{1[0]}}{\partial \tilde{P}}+\frac{\partial ^2H_1^{[0]}}{\partial q^2}\left( \frac{\partial G_{(1)}^{1[0]}}{\partial \tilde{P}}\right) ^2=0,\\ \bar{G}_{(1,1,2)}^1= & {} G_{(1,1,2)}^{1[0]}=\frac{\partial H_2^{[0]}}{\partial q}\frac{\partial G_{(1,1)}^{1[0]}}{\partial \tilde{P}}+\frac{\partial ^2H_2^{[0]}}{\partial q^2}\left( \frac{\partial G_{(1)}^{1[0]}}{\partial \tilde{P}}\right) ^2=0,\\ \bar{G}_{(1,2,1)}^1= & {} G_{(1,2,1)}^{1[0]}=\frac{\partial H_1^{[0]}}{\partial q}\frac{\partial G_{(1,2)}^{1[0]}}{\partial \tilde{P}}+\frac{\partial ^2H_1^{[0]}}{\partial q^2}\frac{\partial G_{(1)}^{1[0]}}{\partial \tilde{P}}\frac{\partial G_{(1)}^{1[0]}}{\partial \tilde{P}}=0,\\ \bar{G}_{(1,2,2)}^1= & {} G_{(1,2,2)}^{1[0]}=\frac{\partial H_2^{[0]}}{\partial q}\frac{\partial G_{(1,2)}^{1[0]}}{\partial \tilde{P}}+\frac{\partial ^2H_2^{[0]}}{\partial q^2}\frac{\partial G_{(1)}^{1[0]}}{\partial \tilde{P}}\frac{\partial G_{(2)}^{1[0]}}{\partial \tilde{P}}=0,\\ \end{aligned}$$
$$\begin{aligned} \bar{G}_{(2,1,1)}^1= & {} G_{(2,1,1)}^{1[0]}=\frac{\partial H_1^{[0]}}{\partial q}\frac{\partial G_{(2,1)}^{1[0]}}{\partial \tilde{P}}+\frac{\partial ^2H_1^{[0]}}{\partial q^2}\frac{\partial G_{(2)}^{1[0]}}{\partial \tilde{P}}\frac{\partial G_{(1)}^{1[0]}}{\partial \tilde{P}}=0,\\ \bar{G}_{(2,1,2)}^1= & {} G_{(2,1,2)}^{1[0]}=\frac{\partial H_2^{[0]}}{\partial q}\frac{\partial G_{(2,1)}^{1[0]}}{\partial \tilde{P}}+\frac{\partial ^2H_2^{[0]}}{\partial q^2}\frac{\partial G_{(2)}^{1[0]}}{\partial \tilde{P}}\frac{\partial G_{(1)}^{1[0]}}{\partial \tilde{P}}=0,\\ \bar{G}_{(2,2,1)}^1= & {} G_{(2,2,1)}^{1[0]}=\frac{\partial H_1^{[0]}}{\partial q}\frac{\partial G_{(2,2)}^{1[0]}}{\partial \tilde{P}}+\frac{\partial ^2H_1^{[0]}}{\partial q^2}\left( \frac{\partial G_{(2)}^{1[0]}}{\partial \tilde{P}}\right) ^2=0, \end{aligned}$$
$$\begin{aligned} \bar{G}_{(2,2,2)}^1= & {} G_{(2,2,2)}^{1[0]}=\frac{\partial H_2^{[0]}}{\partial q}\frac{\partial G_{(2,2)}^{1[0]}}{\partial \tilde{P}}+\frac{\partial ^2H_2^{[0]}}{\partial q^2}\left( \frac{\partial G_{(2)}^{1[0]}}{\partial \tilde{P}}\right) ^2=0,\\ \bar{G}_{(0,0)}^1= & {} G_{(0,0)}^{1[0]}+2G_{(0)}^{1[1]}=\frac{\partial H_0^{[0]}}{\partial q}\frac{\partial G_{(0)}^{1[0]}}{\partial \tilde{P}}+2H_0^{[1]}=\omega ^2 \tilde{P}\sin q+2H_0^{[1]},\\ \bar{G}_{(1,1,0)}^1= & {} G_{(1,1,0)}^{1[0]}+G_{(1,1)}^{1[1]}=\sigma _1\cos q \frac{\partial H_1^{[1]}}{\partial \tilde{P}},\\ \bar{G}_{(1,2,0)}^1= & {} G_{(1,2,0)}^{1[0]}+G_{(1,2)}^{1[1]}=\sigma _2\sin q \frac{\partial H_1^{[1]}}{\partial \tilde{P}}, \\ \bar{G}_{(2,1,0)}^1= & {} G_{(2,1,0)}^{1[0]}+G_{(2,1)}^{1[1]}=\sigma _1\cos q \frac{\partial H_2^{[1]}}{\partial \tilde{P}}, \\ \end{aligned}$$
$$\begin{aligned} \bar{G}_{(2,2,0)}^1= & {} G_{(2,2,0)}^{1[0]}+G_{(2,2)}^{1[1]}=\sigma _2\sin q \frac{\partial H_2^{[1]}}{\partial \tilde{P}}, \\ \bar{G}_{(0,1,1)}^1= & {} G_{(0,1,1)}^{1[0]}+G_{(1,1)}^{1[1]}=\sigma _1^2\cos ^2 q+\sigma _1\cos q \frac{\partial H_1^{[1]}}{\partial \tilde{P}},\\ \bar{G}_{(0,1,2)}^1= & {} G_{(0,1,2)}^{1[0]}+G_{(1,2)}^{1[1]}=\sigma _1\sigma _2\sin q\cos q+\sigma _2\sin q \frac{\partial H_1^{[1]}}{\partial \tilde{P}},\\ \bar{G}_{(0,2,1)}^1= & {} G_{(0,2,1)}^{1[0]}+G_{(2,1)}^{1[1]}=\sigma _1\sigma _2\sin q\cos q+\sigma _1\cos q \frac{\partial H_2^{[1]}}{\partial \tilde{P}},\\ \bar{G}_{(0,2,2)}^1= & {} G_{(0,2,2)}^{1[0]}+G_{(2,2)}^{1[1]}=\sigma _2^2\sin ^2 q\cos q+\sigma _2\sin q \frac{\partial H_2^{[1]}}{\partial \tilde{P}},\\ \bar{G}_{(1,0,1)}^1= & {} G_{(1,0,1)}^{1[0]}+G_{(1,1)}^{1[1]}=\sigma _1\cos q\frac{\partial H_1^{[1]}}{\partial \tilde{P}},\\ \end{aligned}$$
$$\begin{aligned} \bar{G}_{(1,0,2)}^1= & {} G_{(1,0,2)}^{1[0]}+G_{(1,2)}^{1[1]}=\sigma _2\sin q\frac{\partial H_1^{[1]}}{\partial \tilde{P}},\\ \bar{G}_{(2,0,1)}^1= & {} G_{(2,0,1)}^{1[0]}+G_{(2,1)}^{1[1]}=\sigma _1\cos q\frac{\partial H_2^{[1]}}{\partial \tilde{P}},\\ \bar{G}_{(2,0,2)}^1= & {} G_{(2,0,2)}^{1[0]}+G_{(2,2)}^{1[1]}=\sigma _2\sin q\frac{\partial H_2^{[1]}}{\partial \tilde{P}}, \end{aligned}$$
$$\begin{aligned} \bar{G}_{(1,1,1,1)}^1= & {} G_{(1,1,1,1)}^{1[0]}=\frac{\partial H_1^{[0]}}{\partial q}\frac{\partial G_{(1,1,1)}^{1[0]}}{\partial \tilde{P}}\\&+3\frac{\partial ^2 H_1^{[0]}}{\partial q^2}\frac{\partial G_{(1,1)}^{1[0]}}{\partial \tilde{P}}\frac{\partial G_{(1)}^{1[0]}}{\partial \tilde{P}}+\frac{\partial ^3 H_1^{[0]}}{\partial q^3}\left( \frac{\partial G_{(1)}^{1[0]}}{\partial \tilde{ P}}\right) ^3=0,\\ \bar{G}_{(1,1,1,2)}^1= & {} G_{(1,1,1,2)}^{1[0]}=0,\quad \bar{G}_{(1,1,2,1)}^1=G_{(1,1,2,1)}^{1[0]}=0,\\ \bar{G}_{(1,1,2,2)}^1= & {} G_{(1,1,2,2)}^{1[0]}=0,\quad \bar{G}_{(1,2,1,1)}^1=G_{(1,2,1,1)}^{1[0]}=0,\\ \bar{G}_{(1,2,1,2)}^1= & {} G_{(1,2,1,2)}^{1[0]}=0,\quad \bar{G}_{(1,2,2,1)}^1=G_{(1,2,2,1)}^{1[0]}=0,\\ \bar{G}_{(1,2,2,2)}^1= & {} G_{(1,2,2,2)}^{1[0]}=0,\quad \bar{G}_{(2,1,1,1)}^1=G_{(2,1,1,1)}^{1[0]}=0,\\ \end{aligned}$$
$$\begin{aligned} \bar{G}_{(2,1,1,2)}^1= & {} G_{(2,1,1,2)}^{1[0]}=0,\quad \bar{G}_{(2,1,2,1)}^1=G_{(2,1,2,1)}^{1[0]}=0,\\ \bar{G}_{(2,1,2,2)}^1= & {} G_{(2,1,2,2)}^{1[0]}=0,\quad \bar{G}_{(2,2,1,1)}^1=G_{(2,2,1,1)}^{1[0]}=0,\\ \bar{G}_{(2,2,1,2)}^1= & {} G_{(2,2,1,2)}^{1[0]}=0,\quad \bar{G}_{(2,2,2,1)}^1=G_{(2,2,2,1)}^{1[0]}=0,\\ \bar{G}_{(2,2,2,2)}^1= & {} G_{(2,2,2,2)}^{1[0]}=0,\\&\vdots \end{aligned}$$

It can be easily derived that the coefficients of h in each pair of (4.25) are equal. Equating the coefficients of \(h^2\) in each pair of (4.25) and (4.26), we obtain

$$\begin{aligned}&\frac{\partial H_0^{[1]}}{\partial q}+\frac{1}{2}\left( -\sigma _1\sin q\frac{\partial H_1^{[1]}}{\partial p}+\sigma _1\cos q\frac{\partial ^2 H_1^{[1]}}{\partial p\partial q}\right) \nonumber \\&\qquad +\frac{1}{2}\left( \sigma _2\cos q\frac{\partial H_2^{[1]}}{\partial p}+\sigma _2\sin q \frac{\partial ^2H_2^{[1]}}{\partial p\partial q}\right) \nonumber \\&\quad =-\frac{1}{2}\omega ^2 p\cos q+\frac{1}{2}\sigma _1^2\sin q\cos q-\frac{1}{2}\sigma _2^2\sin q\cos q, \end{aligned}$$
(5.25)
$$\begin{aligned}&\frac{\partial H_0^{[1]}}{\partial p}+\frac{1}{2}\sigma _1\cos q\frac{\partial ^2 H_1^{[1]}}{\partial p^2}+\frac{1}{2}\sigma _2\sin q\frac{\partial ^2 H_2^{[1]}}{\partial p^2} =-\frac{1}{2}\omega ^2 \sin q, \end{aligned}$$
(5.26)
$$\begin{aligned}&2\left( \sigma _1\cos q\frac{\partial H_1^{[1]}}{\partial q}+\sigma _2\sin q\frac{\partial H_2^{[1]}}{\partial q}\right) =(\sigma _1^2-\sigma _2^2)p\sin q\cos q, \end{aligned}$$
(5.27)
$$\begin{aligned}&2\left( \sigma _1\cos q\frac{\partial H_1^{[1]}}{\partial p}+\sigma _2\sin q\frac{\partial H_2^{[1]}}{\partial p}\right) =-\sigma _1^2\cos ^2 q-\sigma _2^2\sin ^2 q. \end{aligned}$$
(5.28)

Form (5.27) and (5.28) it follows that

$$\begin{aligned} \frac{\partial H_1^{[1]}}{\partial p}= & {} -\frac{1}{2}\sigma _1\cos q,\quad \frac{\partial H_1^{[1]}}{\partial q}=\frac{1}{2}\sigma _1p\sin q,\nonumber \\ \frac{\partial H_2^{[1]}}{\partial p}= & {} -\frac{1}{2}\sigma _2\sin q,\quad \frac{\partial H_2^{[1]}}{\partial q}=-\frac{1}{2}\sigma _2p\cos q. \end{aligned}$$
(5.29)

Substituting (5.29) into (5.25) and (5.26), we get

$$\begin{aligned} \frac{\partial H_0^{[1]}}{\partial q}=-\frac{1}{2}\omega ^2 p\cos q,\quad \frac{\partial H_0^{[1]}}{\partial p}=-\frac{1}{2}\omega ^2 \sin q. \end{aligned}$$
(5.30)

Thus, the modified equation of weak second order apart from the numerical method (5.24) is

$$\begin{aligned} dp= & {} \left( -\omega ^2\sin q+\frac{h}{2}\omega ^2 p\cos q\right) dt -\left( \sigma _1\cos q+\frac{h}{2}\sigma _1 p\sin q\right) \circ dW_1(t)\nonumber \\&-\left( \sigma _2\sin q-\frac{h}{2}\sigma _2 p\cos q\right) \circ dW_2(t),\nonumber \\ dq= & {} \left( p-\frac{h}{2}\omega ^2\sin q\right) dt-\frac{h}{2}\sigma _1\cos q\circ dW_1(t)-\frac{h}{2}\sigma _2\sin q\circ dW_2(t). \end{aligned}$$
(5.31)

For higher order modified equations, more \(\bar{G}_{\alpha }\) should be computed, and more equations should be satisfied, which increases the computational complexity.

Remark 1

Similar to Example 2, where a numerical method of weak convergence order 2 finds the modified equation of weak third order apart from it, i.e., \(k=2\) and \(k'=1\), we can also construct the modified equation of weak third order apart from the numerical method (5.5) which is of weak convergence order 1, that is, \(k=1\) and \(k'=2\). The details are given in Appendix 2.

Remark 2

For the Kubo oscillator [20]

$$\begin{aligned} dp= & {} -aqdt-\sigma q\circ dW(t),\quad p(0)=p_0,\nonumber \\ dq= & {} apdt+\sigma p\circ dW(t),\quad q(0)=q_0, \end{aligned}$$
(5.32)

where \(H_1=\frac{\sigma }{2}(p^2+q^2)\), which is non-linear and depends on both p and q, we can not write the modified equations for weakly convergent symplectic methods using the generating function approach. However, if we first transform the Kubo oscillator (5.32) to its equivalent Itô form, and then use the Milstein method instead of directly using a weakly convergent symplectic method, it might be possible to obtain the modified equation for the non-symplectic Milstein method, applying the procedure given in [36].

The generating function approach for deriving modified equations for symplectic methods is therefore subject to further investigation for more general cases, for which the perturbed Hamiltonian functions \(\tilde{H}_r\,\,(r\ge 0)\) in (4.1) may have to possess a more delicate formulation.

Fig. 1
figure 1

The weak order of the scheme (5.5) and of its modified equation (5.12) (left), and the sample mean phase trajectories of (5.5), (5.12) and the exact solution (right)

6 Numerical tests

In this section, we do some numerical experiments to test the validity of our theoretical analysis. For the linear stochastic oscillator considered in Example 1 and 2 in the previous section, we have constructed the symplectic methods of weak first and second orders via the generating functions, and established their modified equations one order closer to the numerical solution than the exact solution does, i.e., the weak error between the modified equations and the numerical methods are of second and third orders, for the weak first and second order numerical methods, respectively. For convenience, we say in the following that the weak orders of the modified equations are 2 and 3, accordingly. We observe these weak orders via numerical tests. On the other hand, we draw the phase trajectories of the numerical schemes and that of their modified equations, both in one sample and in sense of sample means together with the sample mean trajectory of the exact solution, to testify their closeness. Finally, the logarithm of the weak errors between the numerical solutions and the exact solution, and that between the numerical solutions and their modified equations are illustrated against time t.

The left panel of Fig. 1 plots the value \(\ln |\mathbf {E}(P(T)+Q(T))^2-\mathbf {E}(P_{N_T}+Q_{N_T})^2|\) (red-dotted line) and \(\ln |\mathbf {E}(\tilde{P}(T)+\tilde{Q}(T))^2-\mathbf {E}(P_{N_T}+Q_{N_T})^2|\) (blue-dotted line) against \(\ln h\) for five different step sizes \(h=[0.1,0.05,0.04,0.02,0.01]\) at \(T=5\), where \(N_T\) is the subindex of one of the discrete time point such that \(t_{N_T}=T\), and the (P(T), Q(T)), \((P_{N_T},Q_{N_T})\) and \((\tilde{P}(T),\tilde{Q}(T))\) represents the phase point of the exact solution, the numerical method, and the modified equation at time T, respectively. It can be seen that the weak order of the scheme (5.5) is 1, and the weak order of the modified equation (5.12) is 2, as indicated by the reference lines of slope 1 and 2, respectively. Here we take the function \(\phi (P,Q)=(P+Q)^2\) as the test function for weak convergence. The right panel plots the sample mean phase trajectories of the exact solution (green-solid line), the numerical method (5.5) of weak order 1 (red-solid line), and the modified equation (5.12) (blue-solid line). It can be seen that coincidence between the numerical method and its modified equation is better than that between the numerical method and the exact solution. The initial values are \(p=0,\, q=1\), and \(\sigma =0.3\). The expectation \(\mathbf {E}\) is approximated by taking average over 1000 and 500 realizations for the left and right panels, respectively, and \(h=0.25\), \(T=50\) for the right panel.

Fig. 2
figure 2

A sample phase trajectory of the numerical solution (5.5) and its modified equation (5.12) (left panel), and the logarithm of the weak error between the numerical solution (5.5) and the exact solution (red line), as well as that between the numerical solution (5.5) and its modified equation (5.12) (blue line), against time t (right panel) (color figure online)

The left panel of Fig. 2 draws one sample trajectory of the numerical method (5.5), and that of its modified equation (5.12), where near coincidence can be seen. The right panel illustrates the time evolution of the logarithm of the weak error \(|\mathbf {E}(P(t)+Q(t))^2-\mathbf {E}(P_{n_t}+Q_{n_t})^2|\) and \(|\mathbf {E}(\tilde{P}(t)+\tilde{Q}(t))^2-\mathbf {E}(P_{n_t}+Q_{n_t})^2|\) on the time interval [0, 100], where \(n_t\) denotes the subindex of one of the discrete time points such that \(t_{n_t}=t\). It is obvious that the numerical solution is closer to its modified equation than to the exact solution in the weak sense. The time step size for the numerical method is \(h=0.01\), the initial values are taken as \(p=0,\,q=1\), and the coefficient is \(\sigma =0.5\). Again 500 samples are applied to simulating the expectation \(\mathbf {E}\).

Note that, a slight drift of the error curves can be seen, in the right panel both of Fig. 2, and of Fig. 4. The reference line (green solid) is the curve \(\ln (t)\), which indicates that the increase is about at the speed of \(\ln (t)\) as t grows, meaning that the errors \(|\mathbf {E}(P(t)+Q(t))^2-\mathbf {E}(P_{n_t}+Q_{n_t})^2|\) and \(|\mathbf {E}(\tilde{P}(t)+\tilde{Q}(t))^2-\mathbf {E}(P_{n_t}+Q_{n_t})^2|\) have the approximate tendency of linear growth with respect to time t. This might be caused by the fact that the quantities \(\mathbf {E}(P(t)+Q(t))^2\), \(\mathbf {E}(P_{n_t}+Q_{n_t})^2\), and \(\mathbf {E}(\tilde{P}(t)+\tilde{Q}(t))^2\), although oscillatory, all have a tendency of linear growth, as is observed in the left panel of Fig. 5, but with slightly different slope relating to the time step size h. This is similar to the result regarding the midpoint rule, a symplectic method, applied to the same system which possesses the linear growth quantity \(\mathbf {E}(P(t)^2+Q(t)^2)=1+\sigma ^2 t\) with respect to time t, where the midpoint rule produces the numerical linear growth \(\mathbf {E}(P_n^2+Q_n^2)=1+\frac{4\sigma ^2 t_n}{4+h^2}\) (Theorem 3.2 in [15]). Thus for the midpoint rule, \(\mathbf {E}(P(t)^2+Q(t)^2)-\mathbf {E}(P_{n_t}^2+Q_{n_t}^2)=\frac{h^2\sigma ^2}{4+h^2}t\), i.e., a linearly growing mean-square error.

Fig. 3
figure 3

The weak order of the scheme (5.15) and of its modified equation (5.19) (left), and the sample mean phase trajectories of (5.15), (5.19) and the exact solution (right)

Similar to the test for Fig. 1, we observe in the test for Fig. 3 the weak order of the numerical method (5.15) and that of its modified equation (5.19), which is 2 and 3, respectively, as illustrated by the left panel of Fig. 3. The data setting for the left panel of Fig. 3 is \(p=3,\,q=1\), \(\sigma =0.3\), \(T=6\), \(h=[0.5,0.4,0.3,0.25,0.2]\), and \(\phi (P,Q)=(P+Q)^2\) as the test function. The right panel draws the sample mean phase trajectories of the exact solution (green-solid line), the numerical method (5.15) (red-solid line) and the modified equation (5.19) (blue-solid line). Better coincidence of the sample mean phase trajectory of the numerical method with that of its modified equation than with that of the exact solution is also visible. The data here are the same with that for the right panel of Fig. 1.

Fig. 4
figure 4

A sample phase trajectory of the numerical solution (5.15) and its modified equation (5.19) (left panel), and the logarithm of the weak error between the numerical solution (5.15) and the exact solution (red line), as well as that between the numerical solution (5.15) and its modified equation (5.19) (blue line), against time t (right panel) (color figure online)

Fig. 5
figure 5

Evolution of \(\mathbf {E}(P+Q)^2\) for the exact solution (green-dotted), the numerical method (5.15) (red-solid) and the modified equation (5.19) (blue-solid) on the time interval [0, 15] (left panel), and the zoomed in local observation of the three curves (right panel) (color figure online)

As can be seen from Fig. 4, the sample phase trajectory produced by the numerical method (5.15) coincides visually with that of its modified equation (5.19), and the solution of the modified equation is obviously closer to the numerical solution than the exact solution of the original system (5.1) does. The data for the left panel are the same with that for the left panel of Fig. 2. For the right panel, \(p=3,\,q=0\), \(\sigma =0.3\), \(T=100\), \(h=0.1\), and the test function is taken as \(\phi (P,Q)=(P+Q)^2\). The expectation \(\mathbf {E}\) is approximated by taking average over 300 samples.

The left panel of Fig. 5 shows the evolution of the oscillatory quantity \(\mathbf {\mathbf {E}}(P+Q)^2\) for the exact solution, the numerical solution (5.15) and its modified equation (5.19), which coincides visually. Meanwhile, a linear growth tendency with rate \(\sigma ^2\) can be observed via the reference line (black-solid). The right panel is obtained by zooming in the left figure, where the numerical solution is obviously closer to its modified equation than to the exact solution. The data for this figure are \(p=1,\,q=0\), \(\sigma =0.3\), \(h=0.1\), \(T=15\), and 500 samples for approximating the expectation \(\mathbf {E}\).

7 Conclusion

We construct modified equations for weakly convergent stochastic symplectic methods using their generating functions, for stochastic Hamiltonian systems with either linear diffusion-related Hamiltonians, or non-linear ones which depend only on p or only on q. Applications of the method to three examples succeed in rewriting the modified equation obtained by another method in existing literature, and in establishing a second and a third weak order modified equation for a stochastic symplectic method of weak order 1 and another of weak order 2, respectively. Numerical experiments show validity of this approach. However, for more general situations, such as the Kubo oscillator, where the diffusion-related Hamiltonians are non-linear and rely on both p and q, our method can not work. The reason for and solution to this problem need further investigation.