1 Introduction

The numerical solution of Hamiltonian problems has been the subject of many investigations in the last decades, due to the fact that Hamiltonian problems are not structurally stable against generic perturbations like those induced by a general-purpose numerical method used to approximate their solutions.

The main features of a canonical Hamiltonian system are surely the symplecticness of the map and the conservation of energy. It is well-known that these two properties are mutually exclusive when Runge-Kutta or B-series methods are considered [1]. This is the reason why numerical methods have been devised in order of either defining a symplectic discrete map, giving rise to the class of symplectic methods (see, e.g., the monographs [2,3,4,5], and references therein, and the review paper [6]), or being able to conserve the energy, resulting in the class of energy-conserving methods (see, e.g., [7,8,9,10,11,12,13,14] and the monograph [15]).

The methods we shall deal with belong to the class of energy-conserving methods: they are named Hamiltonian Boundary Value Methods (HBVMs) [12, 13, 15, 16]. HBVMs, in turn, can be also regarded as a local projection of the vector field onto a finite-dimensional function space [17]. It is worth mentioning that the same idea has been also named in different ways (e.g., functionally fitted methods [18]). Remarkably, this strategy is even more general and can be adapted to other classes of problems, also allowing the use of the methods as spectral methods in time [19,20,21,22]. This means that the accuracy of the approximation is attained by increasing the dimension of the functional space, rather than reducing the timestep. Test problems, comparing the computational cost of such methods w.r.t. collocation or other standard methods, can be found in [22], showing the good potentialities of the spectral approach. We mention that spectral methods have been also extensively used in other settings [23,24,25,26].

In this paper, we sketch how the approach resulting into HBVMs can be extended to cope with additional differential problems: for some of such instances a thorough analysis is still in progress, but the general framework can be outlined even at this stage.

With this premise, the structure of the paper is as follows: in Sect. 2 we provide a brief introduction to HBVMs; in Sect. 3 the approach is extended to cope with general initial value problems (ODE-IVPs), including special second-order problems and delay differential equations (DDEs); Sect. 4 is devoted to implicit differential algebraic equations (IDEs/DAEs), including linearly implicit DAEs; Sect. 5 concerns the case of fractional differential equations (FDEs); a few conclusions are given in Sect. 6.

2 Hamiltonian problems

A canonical Hamiltonian problem is in the form

$$\begin{aligned} \dot{y} = J \nabla H(y), \qquad y(0) = y_0\in \mathbb {R}^{2m}, \qquad J=\left( \begin{array}{cc}&I_m\mathrm{i}_m\end{array}\right) = -J^\top , \end{aligned}$$
(1)

with \(H:\mathbb {R}^{2m}\rightarrow \mathbb {R}\) the Hamiltonian function (or energy) of the system.Footnote 1 As is easily understood H is a constant of motion, since

$$\begin{aligned} \frac{\mathrm {d}}{\mathrm {d}t}H(y) = \nabla H(y)^\top \dot{y} = \nabla H(y)^\top J \nabla H(y)=0,\end{aligned}$$

being J skew-symmetric. The simple idea on which HBVMs rely on is that of reformulating the previous conservation property in terms of the line integral of \(\nabla H\) along the path defined by the solution y(t):

$$\begin{aligned} H(y(t)) = H(y_0) + \int _0^t \nabla H(y(\tau ))^\top \dot{y}(\tau )\mathrm {d}\tau .\end{aligned}$$

Clearly, the integral at the right-hand side of the previous equality vanishes, because the integrand is identically zero, so that the conservation holds true for all \(t>0\). The solution of (1) is the unique function satisfying such a conservation property for all \(t>0\). However, if we consider a discrete-time dynamics, ruled by a timestep h, there exists infinitely many paths \(\sigma \) such that:

$$\begin{aligned} \sigma (0)= & {} y_0, \qquad \sigma (h) =: y_1\approx y(h),\nonumber \\ 0= & {} h\int _0^1 \nabla H(\sigma (ch))^\top \dot{\sigma }(ch)\mathrm {d}c. \end{aligned}$$
(2)

The path \(\sigma \) obviously defines a one-step numerical method that conserves the energy, since

$$\begin{aligned} H(y_1)=H(y_0) + h\int _0^1 \nabla H(\sigma (ch))^\top \dot{\sigma }(ch)\mathrm {d}c = H(y_0),\end{aligned}$$

even though now the integrand is no more identically zero. The methods derived in this framework have been named line integral methods, due to the fact that the path \(\sigma \) is defined so that the line integral (2) vanishes. Such methods have been thoroughly analyzed in the monograph [15] (see also the review paper [27]). Clearly, in the practical implementation of the methods, the integral is replaced by a quadrature of enough high-order, thus providing a fully discrete method. However, for the sake of brevity, we shall hereafter continue to use the integral, and not the quadrature, so that the exposition is greatly simplified and more concise.Footnote 2

After some initial attempts to derive methods in this class [8,9,10, 12, 30], a systematic way for their derivation was found in [17], which is based on a local Fourier expansion of the vector field in (1). In fact, by setting

$$\begin{aligned} f(y)=J\nabla H(y), \end{aligned}$$
(3)

and using hereafter the more convenient notation, depending on the needs, one may rewrite problem (1), on the interval [0, h], as:

$$\begin{aligned} \dot{y}(ch) = \sum _{j\ge 0} P_j(c)\gamma _j(y), \qquad c\in [0,1], \qquad y(0) = y_0, \end{aligned}$$
(4)

where \(\{P_j\}_{j\ge 0}\) is the Legendre orthonormal polynomial basis on [0, 1],

$$\begin{aligned} P_i\in \Pi _i, \qquad \int _0^1 P_i(x)P_j(x)\mathrm {d}x = \delta _{ij}, \qquad i,j\ge 0, \end{aligned}$$
(5)

\(\Pi _i\) is the vector space of polynomials of degree at most i, \(\delta _{ij}\) is the Kronecker symbol, and

$$\begin{aligned} \gamma _j(y) = \int _0^1P_j(\tau )f(y(\tau h))\mathrm {d}\tau , \qquad j \ge 0, \end{aligned}$$
(6)

are the corresponding Fourier coefficients. The solution of the problem is formally obtained, in terms of the unknown Fourier coefficients, by integrating both sides of Eq. (4):

$$\begin{aligned} y(ch) = y_0 + h\sum _{j\ge 0}\int _0^c P_j(x)\mathrm {d}x\, \gamma _j(y), \qquad c\in [0,1]. \end{aligned}$$
(7)

A polynomial approximation \(\sigma \in \Pi _s\) can be formally obtained by truncating the previous series to a finite sum,

$$\begin{aligned} \dot{\sigma }(ch) = \sum _{j=0}^{s-1} P_j(c) \gamma _j(\sigma ), \qquad c\in [0,1], \qquad \sigma (0)=y_0, \end{aligned}$$
(8)

and

$$\begin{aligned} \sigma (ch) = y_0 + h\sum _{j=0}^{s-1}\int _0^c P_j(x)\mathrm {d}x\, \gamma _j(\sigma ), \qquad c\in [0,1], \end{aligned}$$
(9)

respectively, with \(\gamma _j(\sigma )\) defined according to (6), upon replacing y with \(\sigma \). Whichever the degree \(s\ge 1\) of the polynomial approximation, the following result holds true, where the same notation used above holds.

Theorem 1

Assume that the Hamiltonian H has continuous partial derivatives. Then, \(H(y_1)=H(y_0)\).

Proof

In fact, one has:

$$\begin{aligned} H(y_1)-H(y_0)= & {} H(\sigma (h))-H(\sigma (0)) = h\int _0^1 \nabla H(\sigma (ch))^\top \dot{\sigma }(ch)\mathrm {d}c\\= & {} h\int _0^1 \nabla H(\sigma (ch))^\top \sum _{j=0}^{s-1} P_j(c)\gamma _j(\sigma )\mathrm {d}c\\= & {} h\sum _{j=0}^{s-1} \left[ \int _0^1 P_j(c)\nabla H(\sigma (ch))\mathrm {d}c\right] ^\top \gamma _j(\sigma )\\= & {} h\sum _{j=0}^{s-1} \left[ \int _0^1 P_j(c)\nabla H(\sigma (ch))\mathrm {d}c\right] ^\top J \left[ \int _0^1 P_j(c)\nabla H(\sigma (ch))\mathrm {d}c\right] \\= & {} 0, \end{aligned}$$

due to the fact that J is skew-symmetric. \(\square \)

The next result states that the methods has order 2s.

Theorem 2

Assume that the function (3) is of class \(C^{(2s+1)}[0,h]\). Then, \(y_1-y(h)=O(h^{2s+1})\).

Proof

See [17,  Theorem 1]. \(\square \)

Remark 1

It is worth noticing that, due to the fact that (see (5))

$$\begin{aligned} \int _0^1P_j(x)\mathrm {d}x=\delta _{j0}, \end{aligned}$$
(10)

the new approximation (see (2) and (9)) is given by

$$\begin{aligned} y_1 := \sigma (h) \equiv y_0 + \int _0^h f(\sigma (t))\mathrm {d}t,\end{aligned}$$

which can be regarded as an approximation of the Fundamental Theorem of Calculus.

3 Initial value problems

The result in Theorem 2 does not depend on the Hamiltonian structure of the problem. This suggests that the above procedure also makes sense for a generic initial value problem which, on the interval [0, h] can be cast, without loss of generality, as

$$\begin{aligned} \dot{y}(ch) = f(y(ch)), \qquad c\in [0,1], \qquad y(0)=y_0\in \mathbb {R}^m. \end{aligned}$$
(11)

To cope with more general problems, hereafter we consider an alternative but equivalent approach to devise this family of methods. Consider again

$$\begin{aligned} \dot{\sigma }(ch) = \sum _{j=0}^{s-1} P_j(c)\gamma _j, \qquad \sigma (ch) = y_0+h\sum _{j=0}^{s-1} \int _0^cP_j(x)\mathrm {d}x\,\gamma _j, \qquad c\in [0,1]. \end{aligned}$$
(12)

We determine the unknown coefficients

$$\begin{aligned} \gamma _j\equiv \gamma _j(\sigma ), \qquad j=0,\dots ,s-1, \end{aligned}$$

in order that the residual function

$$\begin{aligned} r(ch) := \dot{\sigma }(ch) - f(\sigma (ch)), \qquad c\in [0,1], \end{aligned}$$
(13)

be orthogonal to \(\Pi _{s-1}\), namely

$$\begin{aligned} 0=\int _0^1 P_i(c) r(ch) \mathrm {d}c = \int _0^1 P_i(c) \left( \dot{\sigma }(ch) - f(\sigma (ch))\right) \mathrm {d}c, \qquad i=0,\dots ,s-1. \end{aligned}$$

Substituting the expansion for \(\dot{\sigma }(ch)\) in (12) and taking into account the orthogonality relations (5) again lead to the equations defining the unknown coefficients \(\gamma _i\) (compare with (6)):

$$\begin{aligned} \gamma _i = \int _0^1 P_i(c) f\left( y_0+h\sum _{j=0}^{s-1} \int _0^cP_j(x)\mathrm {d}x\,\gamma _j\right) \mathrm {d}c, \qquad i=0,\dots ,s-1. \end{aligned}$$
(14)

Remark 2

As was anticipated above, in order to get a fully discrete problem, the integrals appearing in (14) need to be approximated by suitable quadrature formulae: to this purpose, a Gauss-Legendre quadrature of order 2k is employed. The resulting integrator, first devised in the context of Hamiltonian systems, is denoted by HBVM(ks) to highlight the dependence on the two discretization parameters. When \(k=s\) the method reduces to the s-stage Gauss-Legendre collocation method but, if necessary, one can choose k large enough to ensure that the integrals are approximated to within machine precision. This, in turn, can be done without increasing too much the overall computational cost: as matter of fact, the discretized problem (14) has (block) dimesion s, independently of k. This fact is an important feature, in the case of Hamiltonian problems, as the next Example 1 will show. The resulting set of s nonlinear equations (14) can be efficiently solved by means of the blended iteration described in [31], adapted from [32, 33] (see also [34] for related approaches): in fact, such iteration only requires the factorization of one matrix of the size of the continuous problem, whichever is the value of s considered. We mention that the state-of-art Matlab code hbvm.m, implementing HBVMs, is available at the website of the monograph [15].

We observe that, in light of (14) and (12), the new approximation can be written as

$$\begin{aligned} y_1 = y_0 + h\gamma _0, \end{aligned}$$
(15)

which is easily evaluated, once the system (14) has been solved.

It is worth mentioning that, in the actual implementation of (12), it is conveniently exploited the known relation between the Legendre polynomials and their integrals:

$$\begin{aligned} \int _0^c P_0(x)\mathrm {d}x= & {} \xi _0 P_0(c) + \xi _1 P_1(c),\nonumber \\ \int _0^c P_j(x)\mathrm {d}x= & {} \xi _{j+1} P_{j+1}(c) - \xi _j P_{j-1}(c), \qquad j\ge 1,\nonumber \\ \xi _i= & {} \frac{1}{2\sqrt{ \vert 4i^2-1\vert }}, \qquad i\ge 0. \end{aligned}$$
(16)

Example 1

Let us consider the Hamiltonian problem defined by [15]:

$$\begin{aligned} H(q,p) = (q^2+p^2)^2 -10(q^2-p^2), \qquad q,p\in \mathbb {R}. \end{aligned}$$
(17)

When the initial point is chosen as

$$\begin{aligned} (q_0,p_0) = (0,\,10^{-5}), \end{aligned}$$
(18)

the solution trajectory, in the phase space, is a Cassini oval, as is shown on the left of Fig. 1, with very close branches near the origin (see the right-plot in the same figure). The solution is then periodic, with period \(T\approx 3.131990057003955\). However, when numerically solving the problem, if the Hamiltonian is not precisely conserved, then the numerical branches may intersect, thus giving a wrong simulation. If we fix \(s=2\) in (14) and we use a Gauss-Legendre formula of order 8 (\(k=4\)), then the HBVM(4,2) method is exactly energy conserving (according to Theorem 1), since the integrals are exact. We use this method and, for comparison, the 2-stage Gauss collocation method (i.e., HBVM(2,2)), with a timestep \(h=10^{-2}\). This latter method, though symplectic, is not energy-conserving. As is clearly shown in Fig. 2, the former method (left-plot) provides a correct numerical solution, whereas the latter (right-plot) does not. The two simulations have been done by using the Matlab code hbvm.m on an Intel 3GHz Intel Xeon W10 core computer, with 64GB of memory, running Matlab 2020b. Despite the very different outcomes, the computational time for the two simulations is approximately the same (about 10 sec.). This fact confirms that using values of k larger than s, for a HBVM(ks) method, is not a big issue.

Fig. 1
figure 1

Left-plot: solution of problem (17)–(18); right-plot: zoom near the origin

Fig. 2
figure 2

Numerical solution of problem (17)–(18) by using HBVM(4,2) (left) and HBVM(2,2) (right) with timestep \(h=10^{-2}\)

3.1 Special second-order problems

A relevant instance of ODE-IVPs is the case of special second-order problems, namely problems in the form

$$\begin{aligned} \ddot{y}(ch) = f(y(ch)), \qquad c\in [0,1], \qquad y(0) = y_0, ~ \dot{y}(0) = z_0~\in \mathbb {R}^m. \end{aligned}$$
(19)

As an example, separable Hamiltonian problems fall in this class. The particular structure of the problem allows to gain efficiency, with respect to just recasting the problem as the following first order problem of doubled size:Footnote 3

$$\begin{aligned} \left\{ \begin{array}{l} \dot{y}(ch) = z(ch), \\ \dot{z}(ch) = f(y(ch)), \end{array} \right. \qquad c\in [0,1], \qquad y(0) = y_0, ~ \dot{z}(0) = z_0~\in \mathbb {R}^m. \end{aligned}$$
(20)

Proceeding as before, we introduce the polynomial approximations

$$\begin{aligned} \dot{y}(ch) \approx \dot{\sigma }(ch):= & {} \sum _{j=0}^{s-1} P_j(c)\mathrm {d}x\,\hat{\gamma }_j, \end{aligned}$$
(21)
$$\begin{aligned} \dot{z}(ch) \approx \dot{\mu }(ch):= & {} \sum _{j=0}^{s-1} P_j(c)\mathrm {d}x\,\gamma _j, \qquad c\in [0,1], \end{aligned}$$
(22)

satisfying the initial conditions  \(\sigma (0)=y_0, \, \mu (0)=z_0\),  and require the residual

$$\begin{aligned} r(ch) := \left( \begin{array}{c} \dot{\sigma }(ch)-\mu (ch) \\ \dot{\mu }(ch)-f(\sigma (ch)) \end{array}\right) , \qquad c\in [0,1] , \end{aligned}$$

be orthogonal to \(\Pi _{s-1}\). The s orthogonality conditions imposed on the first component of r(ch) allow us to remove the unknowns \(\hat{\gamma }_i\):

$$\begin{aligned} \hat{\gamma }_i = \int _0^1 P_i(c)\mu (ch) \mathrm {d}c, \qquad i=0,\dots ,s-1, \end{aligned}$$

so that, integrating both (21) and (22) from 0 to c, we get the two polynomial approximations of degree s for the solution and its derivative,

$$\begin{aligned} \sigma (ch)= & {} y_0 + h\sum _{j=0}^{s-1} \int _0^c P_j(x)\mathrm {d}x\,\int _0^1 P_j(\tau )\mu (\tau h)\mathrm {d}\tau , \end{aligned}$$
(23)
$$\begin{aligned} \mu (ch)= & {} z_0 + h\sum _{j=0}^{s-1} \int _0^c P_j(x)\mathrm {d}x\,\gamma _j, \qquad c\in [0,1], \end{aligned}$$
(24)

involving only the s unknown coefficients \(\gamma _j\), \(j=0,\dots ,s-1\). Such coefficients are determined from the orthogonality conditions imposed on the second component of r(ch):

$$\begin{aligned} \gamma _i = \int _0^1 P_i(c)f(\sigma (ch))\mathrm {d}c, \qquad i=0,\dots ,s-1. \end{aligned}$$
(25)

By taking into account (16) and (23)–(24), the expression of the polynomial \(\sigma \), in terms of the above coefficients, turns out to be:

$$\begin{aligned} \sigma (ch)= & {} y_0 + ch z_0 + c\frac{h^2}{2}\left( \gamma _0 -\frac{\gamma _1}{\sqrt{3}}\right) \nonumber \\&+h^2\sum _{j=1}^{s-2}\int _0^c P_j(x)\mathrm {d}x \left( \xi _j\gamma _{j-1}-\xi _{j+1}\gamma _{j+1}\right) \,\nonumber \\&+\,h^2\int _0^cP_{s-1}(x)\mathrm {d}x\,\xi _{s-1}\gamma _{s-2}. \end{aligned}$$
(26)

Once the system (25)–(26) has been solved, the new approximations are obtained, as done before, as

$$\begin{aligned} \mu (h) =: z_1 \approx \dot{y}(h), \qquad \sigma (h)=: y_1\approx y(h), \end{aligned}$$

i.e., recalling (10),

$$\begin{aligned} z_1 = z_0 + h\gamma _0, \qquad y_1 = y_0+hz_0 + \frac{h^2}{2}\left( \gamma _0 -\frac{\gamma _1}{\sqrt{3}}\right) . \end{aligned}$$

Remark 3

Also in this case, there exist efficient iterative procedures for solving the discrete counterpart of (25) (see [31]).Footnote 4 In particular, the modified blended iteration follows from the analysis in [35] (see also [33]).

We conlclude this section by mentioning that the whole approach can be extended, in a straightforward way, to higher-order equations [29].

3.2 Delay differential equations

Delay differential equations have been the subject of many investigations in the past years (we refer to the monographs [36, 37] and references therein for further informations). Here, we extend the approach described in the previous sections to cope with delay differential equations in the form

$$\begin{aligned} \dot{y}(t) = f(y(t),y(t-\tau )), \qquad t\ge 0, \qquad y(t)=\phi (t), \quad t\in [-\tau ,0], \end{aligned}$$
(27)

with \(\tau >0\) a fixed delay, and \(\phi :\mathbb {R}\rightarrow \mathbb {R}^m\) a known function. In fact, by using a timestep

$$\begin{aligned} h = \frac{\tau }{K},\end{aligned}$$

for a suitable \(K\in \mathbb {N}\), and setting

$$\begin{aligned} \sigma _n(ch) = y_{n-1}+h\sum _{j=0}^{s-1} \int _0^cP_j(x)\mathrm {d}x\,\gamma _j^n, \qquad c\in [0,1],\end{aligned}$$

the approximation to the solution over the interval Footnote 5

$$\begin{aligned} {[}t_{n-1},t_n], \qquad t_n = nh, \qquad n\ge 1-K, \qquad y_{n-1} := \sigma _{n-1}(h),\end{aligned}$$

then, for \(n\ge 1\), the unknown coefficients \(\gamma _i^n\), \(i=0,\dots ,s-1\), solve the system of equations:

$$\begin{aligned} \gamma _i^n= & {} \int _0^1 P_i(c) f\left( y_{n-1}+h\sum _{j=0}^{s-1} \int _0^cP_j(x)\mathrm {d}x\,\gamma _j^n,\sigma _{n-K}(ch)\right) \mathrm {d}c,\nonumber \\&i=0,\dots ,s-1, \end{aligned}$$
(28)

with the new approximation given by \(\sigma _n(h)=:y_n\approx y(t_n)\), i.e.,

$$\begin{aligned} y_n = y_{n-1}+h\gamma _0^n.\end{aligned}$$

We refer to [38] for full details on this approach.

4 Implicit differential algebraic equations

The procedure defined above to cope with ODE-IVPs and DDE-IVPs can be quite easily extended to solve implicit differential equations, too. For sake of simplicity we continue to deal with initial value problems, even though different kind of conditions could in principle be used, as seen in [39] in the Hamiltonian case. Let us then consider the problem

$$\begin{aligned} F(\dot{y}(ch), y(ch)) = 0, \qquad c\in [0,1], \qquad y(0)=y_0\in \mathbb {R}^m, \end{aligned}$$
(29)

with \(F:\mathbb {R}^m\times \mathbb {R}^m\rightarrow \mathbb {R}^m\). We can then look for a polynomial approximation of degree s in the form (12), with the new approximation at h given by  \( \sigma (h)=:y_1\approx y(h)\), formally still given by (15). As was done before, by requiring the corresponding residual be orthogonal to \(\Pi _{s-1}\), the unknown coefficients \(\gamma _i\), \(i=0,\dots ,s-1\), are the solution of the system of equations:

$$\begin{aligned} 0= & {} \int _0^1 P_i(c)F\left( \sum _{j=0}^{s-1} P_j(c)\gamma _j, \, y_0+h\sum _{j=0}^{s-1} \int _0^cP_j(x)\mathrm {d}x\,\gamma _j \right) \mathrm {d}c,\nonumber \\ i= & {} 0,\dots ,s-1. \end{aligned}$$
(30)

This approach, which is still under investigation, will be fully analyzed elsewhere.

4.1 Linearly implicit DAEs

An important simplification is obtained in the case of linearly implicit DAEs, for which the problem is assumed to be in the form

$$\begin{aligned} M \dot{y}(ch) = f( y(ch)), \qquad c\in [0,1],\qquad y(0)=y_0\in \mathbb {R}^m, \end{aligned}$$
(31)

with \(M\in \mathbb {R}^{m\times m}\) a (possibly singular) known matrix. In this case, in fact, one may look again for a polynomial approximation of degree s in the form (12). As a result, we obtain that the unknown coefficients \(\gamma _i\), \(i=0,\dots ,s-1\), solve the system of equations:

$$\begin{aligned} M\gamma _i = \int _0^1 P_i(c) f\left( y_0+h\sum _{j=0}^{s-1}\int _0^c P_j(x)\mathrm {d}x\,\gamma _j\right) \mathrm {d}c, \qquad i=0,\dots ,s-1. \end{aligned}$$
(32)

Remark 4

It is worth mentioning that the iterative solution of (32) can be carried out via a modified blended iteration, w.r.t. that defined in [31] for HBVMs, by following similar steps as done in [40].

5 Fractional differential equations

Fractional differential equations deserve a separate treatment, due to the fact that the underlying differential operator differs from the usual one (see, e.g., [41]; moreover, we refer to [42] for a review on numerical methods for such problems). Let us then consider, for a given \(\alpha \in (0,1]\), the FDE

$$\begin{aligned} D^\alpha y(ch) = f(y(ch)), \qquad c\in [0,1], \qquad y(0)=y_0\in \mathbb {R}^m, \end{aligned}$$
(33)

where \(D^\alpha \) is the Caputo fractional derivative. This latter derivative is defined, for a given differentiable function \(g:\mathbb {R}\rightarrow \mathbb {R}^m\), as

$$\begin{aligned} D^\alpha g(t) = \frac{1}{\Gamma (1-\alpha )} \int _0^t (t-x)^{-\alpha }\dot{g}(x)\mathrm {d}x.\end{aligned}$$

The corresponding Riemann-Liouville integral of order \(\alpha \) is defined as

$$\begin{aligned} I^\alpha g(t) = \frac{1}{\Gamma (\alpha )}\int _0^t (t-x)^{\alpha -1}g(x)\mathrm {d}x.\end{aligned}$$

It is known that:

$$\begin{aligned} D^\alpha I^\alpha g(t) = g(t), \qquad I^\alpha D^\alpha g(t) = g(t)-g(0).\end{aligned}$$

With this premise, the polynomial approximation to the solution of (33) is now looked in the form

$$\begin{aligned} D^\alpha \sigma (ch) = \sum _{j=0}^{s-1} P_j(c)\gamma _j, \qquad \sigma (ch) = y_0+h^\alpha \sum _{j=0}^{s-1} I^\alpha P_j(c)\,\gamma _j, \qquad c\in [0,1], \end{aligned}$$
(34)

instead of (12).

Remark 5

Clearly, when \(\alpha =1\) (12) and (34) coincide, due to the fact that

$$\begin{aligned} D^1g(t)=\lim _{\alpha \rightarrow 1^-} D^\alpha g(t) = \dot{g}(t), \qquad \text{ and }\qquad I^1 g(t) = \int _0^t g(x)\mathrm {d}x.\end{aligned}$$

As was done before, by formally plugging \(D^\alpha \sigma (ch)\) and \(\sigma (ch)\) into (33), the unknown coefficients \(\gamma _i\), \(i=0,\dots ,s-1\), are determined by requiring the residual be orthogonal to \(\Pi _{s-1}\), thus leading to the system of equations:

$$\begin{aligned} \gamma _i = \int _0^1 P_i(c) f\left( y_0+h^\alpha \sum _{j=0}^{s-1} I^\alpha P_j(c)\,\gamma _j\right) \mathrm {d}c, \qquad i=0,\dots ,s-1. \end{aligned}$$
(35)

In the actual implementation of (35), it is useful knowing how to compute the fractional integrals of the Legendre polynomials.Footnote 6 For this purpose, the following known result will be useful:

$$\begin{aligned} I^\alpha x^\eta = \frac{\Gamma (\eta +1)}{\Gamma (\alpha +\eta +1)} x^{\alpha +\eta }, \qquad \eta \ge 0.\end{aligned}$$
(36)

In fact, by recalling the explicit expression of the Legendre polynomials,

$$\begin{aligned} P_j(c) = \sqrt{2j+1}\sum _{i=0}^j (-1)^{j+i}\frac{(j+i)!}{(j-i)!(i!)^2}\, c^i, \qquad j\ge 0,\end{aligned}$$

from (36) one derives:

$$\begin{aligned} I^\alpha P_j(c) = \sqrt{2j+1}\,c^\alpha \sum _{i=0}^j (-1)^{j+i} \frac{(j+i)!}{(j-i)! i! \Gamma (\alpha +i+1)}\, c^i.\end{aligned}$$

This approach for solving FDEs, at first sketched in [19], will be analysized in detail elsewhere. We mention that a related approach can be found in [43].

6 Conclusions

In this paper we have recalled the basic facts about the numerical solution of differential problems via the expansion of the derivative, either integer or fractional, along the Legendre polynomial basis. Integrating such an approximation then provides a polynomial approximation to the solution.Footnote 7 The coefficients of the polynomial approximation, in turn, are determined by imposing the orthogonality of the residual to a suitable polynomial space. In addition, we mention that the obtained methods can be also used as spectral methods in time, as was described in [20,21,22] in the case of Hamiltonian problems (see also [19, 44,45,46]). Future directions of investigation will concern the extension of this framework to different kinds of differential problems. Also the numerical solution of integral equations could be a further subject of investigation.