1 Introduction

Some geophysical issues, such as the deformations of the Earth induced by the loading force imposed by the ocean and atmosphere and by the seismic forces of earthquakes, can be simplified by obtaining the corresponding Green’s functions for a spherical Earth model first and then applying the convolution of the actual two-dimensional sources in combination with these Green's functions (Longman 1962; Goad 1980; Sun and Okubo 1993; Sun and Okubo 1998; Wang 1999; Martinec 2003; Watanabe and Watanabe 2014; Pan 2019). The accurate calculation of the Green’s functions has mostly been investigated in theoretical studies (Dong and Schmitt 1994; Wang and Wang 2007; Xu et al. 2007; Johnson 2010; Zhou et al. 2019).

Several scientists have presented effective methods of calculating Green’s functions using both analytical and numerical approaches (e.g., Farrell 1972; Okubo 1988; Sun and Okubo 1993; Tang and Sun 2018b). For spherical Earth models, the associated Legendre functions are the most widely used mathematical functions for calculating Green’s functions due to their suitable properties and appropriate performance on a sphere (Freeden and Schreiner 2008). For instance, when investigating seismic deformation using the dislocation theory (e.g., Sun and Okubo 1993; Piersanti et al. 1995, 1997; Pollitz 1996; Vermeersen et al. 1996; Tanaka et al. 2006, 2007; Melini et al. 2008; Cambiotti and Sabadini 2015; Tang and Sun 2019; Zhou et al. 2019) and loading deformations using the loading theory (e.g., Farrell 1972; Vermeersen and Sabadini 1997; Piersanti et al. 1997; Guo et al. 2004; Spada and Boschi 2006), the Green’s functions for the displacement, gravity, tilt, and strain are expressed as a weighted infinite series of the associated Legendre functions and their derivatives. The weights of the series are the Love numbers (Farrell 1972; Sun et al. 1996; Guo et al. 2004), which depend on the source type and the Earth's structure.

As was highlighted by Okubo (1988), the brute force summation approach of obtaining such a series inevitably fails. Instead, Kummer’s transform (Singh et al. 1990) and the analytical expressions of the Legendre functions (e.g., Singh and Ben-Menahem 1968) can be used to obtain numerically stable Green’s functions (e.g., Farrell 1972; Sun and Okubo 1993; Guo et al. 2004) or approximately analytical Green’s functions (e.g., Sun 2003, 2004a; Tang and Sun 2017, 2018a, b).

Specific analytical summation equations of the associated Legendre functions have been introduced in previous studies; however, these equations were published in separate papers (e.g., Singh and Ben-Menahem 1968; Farrell 1972; Sun 2003). A few researchers have focused on deriving new analytical equations for the associated Legendre functions and their derivatives. Using the well-known generating function of the Legendre functions (McBride 2012; Wan and Zudilin 2013) and several integral table books, Singh and Ben-Menahem (1968) were the first to determine the recurrence relationships for the sums of infinite series of the form \(\sum P_{n}^{m} \left( x \right)t^{{n + l}} /\left( {n + k} \right)\). For ready reference, Singh and Ben-Menahem (1968) also provided the explicit expressions for \(k = 0,{\text{~}}1,{\text{~}}2,{\text{~}}3\) and \(m = 0,{\text{~}}1,{\text{~}}2\). In Appendix B of Martinec (2003), the analytical equation of the form \(\sum P_{n} \left( x \right)t^{n} /\left( {n + k} \right)\) with \(k = - 1,{\text{~}}0,{\text{~}}1,{\text{~}}2\) and their first and second derivatives with respect to \(x\) are given. Later, Guo et al. (2004) provided eight analytical equations for the forms in Appendix B: \(\sum P_{n} \left( x \right)t^{n} n^{k}\) with \(k = - 1,{\text{~}}0,{\text{~}}1\), \(\sum t^{n} \frac{d}{{d\theta }}P_{n} \left( {{\text{cos}}\theta } \right)\), \(\sum \frac{{t^{n} }}{{n^{k} }}\frac{d}{{d\theta }}P_{n} \left( {{\text{cos}}\theta } \right)\) with \(k = 1,{\text{~}}2\), and \(\sum \frac{{t^{n} }}{{n^{k} }}\frac{{d^{2} }}{{d\theta ^{2} }}P_{n} \left( {{\text{cos}}\theta } \right)\) with \(k = 1,{\text{~}}2\). However, the factor "\({\text{cos}}\theta - l\)" in the third term of Eq. (B9) in Guo et al. (2004) includes a typo, and it should be “\({\text{cos}}\theta - 1\).” Other authors such as Sun (2003), Sun (2004a), Sun (2004c), and Tang and Sun (2017) have also listed several analytical equations with similar forms in their supporting appendices.

These analytical equations are beneficial, but it is not easy to find them in the vast number of papers. Furthermore, the equations for the series of associated Legendre functions and their first and second derivations are not yet available, but they are required for studying the Green’s functions of other variables such as the strain, stress, and gravity gradients. A paper focusing on providing these equations and an open-source code for calculating them would be quite valuable for other related studies. More broadly, as long as the spherical harmonic function is involved, these analytical equations may be useful for solving the Green’s functions.

This issue motivated us to list the useful equations and their open-source calculation codes for the analytical sums of the associated low-order \(\left( {m = 0,~1,~2} \right)\) Legendre functions. In this paper, the principles of the derivation of these equations are given in Sect. 2. Then, nearly sixty equations are listed following a careful verification. Two application cases to geodesy and geophysics are also presented. The final Mathematica, GNU Octave/MATLAB, and Fortran calculation codes can be accessed on GitHub (https://github.com/UCAStanghe2014/analytical_sums_associated_Legendre).

2 All of the equations involving the Legendre functions

2.1 Two examples with detailed derivations

First, we briefly introduce the relationship between the Legendre functions \(P_{n} \left( x \right)\) and the associated Legendre functions \(P_{n}^{m} \left( x \right)\) (Müller 1966a, b). The Legendre functions can be given in a compact form by Rodrigues’ equation (Askey 2005)

$$ P_{n} \left( x \right) = \frac{1}{{2^{n} n!}}\frac{{d^{n} }}{{dx^{n} }}\left( {x^{2} - 1} \right)^{n} . $$
(1)

The low-order (\(m \le 2\)) associated Legendre functions can be written explicitly as follows (Freeden et al. 2010; Bosch 2000):

$$ P_{n}^{1} \left( {{\text{cos}}\theta } \right) = - \frac{{dP_{n} \left( {{\text{cos}}\theta } \right)}}{{d\theta }}, $$
(2)
$$ P_{n}^{2} \left( {{\text{cos}}\theta } \right) = - 2{\text{cot}}\theta \frac{{dP_{n} \left( {{\text{cos}}\theta } \right)}}{{d\theta }} - n\left( {n + 1} \right)P_{n} \left( {{\text{cos}}\theta } \right). $$
(3)

Therefore, the closed-form equations of the associated Legendre functions can be obtained through a combination of the Legendre functions. In principle, all of the analytical sums of the Legendre functions can be directly or indirectly obtained from the generating function of the Legendre functions (Singh and Ben-Menahem 1968; McBride 2012; Weisstein 2002):

$$ G\left( {\varepsilon ,\theta } \right) \equiv \mathop \sum \limits_{{n = 0}}^{\infty } \varepsilon ^{n} P_{n} \left( {{\text{cos}}\theta } \right) = \frac{1}{{\sqrt {1 - 2\varepsilon {\text{cos}}\theta + \varepsilon ^{2} } }},\quad 0 < \varepsilon \le 1,\;0 < \theta \le \pi . $$
(4)

Here, we avoid the singularity of Eq. (4) by preventing the definition at \(\theta = 0\). The singularity of the analytical equations at this point will be discussed later.

If all of the equations are explained in detail, the interested readers can easily retrace the derivation steps using pen and paper. Thus, all of the steps in the process are given below. First, as can be seen, differentiating the generating function with respect to \(\varepsilon\) generates a factor \(n\), and integrating with respect to \(\varepsilon\) results in a factor of \(1/n\) on the left-hand side of Eq. (4). Repeated the integration or differentiation operations produces different infinite series. This is the process for constructing a new equation based on the generating function.

We take \(\mathop \sum \nolimits_{{n = 0}}^{\infty } \varepsilon ^{n} nP_{n} \left( {{\text{cos}}\theta } \right)\) and \(\mathop \sum \nolimits_{{n = 1}}^{\infty } \frac{{\varepsilon ^{n} }}{n}P_{n} \left( {{\text{cos}}\theta } \right)\) as two examples. According to Eq. (4), we obtain

$$ \mathop \sum \limits_{{n = 1}}^{\infty } \varepsilon ^{n} P_{n} \left( {{\text{cos}}\theta } \right) = G\left( {\varepsilon ,\theta } \right) - 1, $$
(5)

and its derivative with respect to \(\varepsilon\) is

$$ \mathop \sum \limits_{{n = 1}}^{\infty } \varepsilon ^{{n - 1}} nP_{n} \left( {{\text{cos}}\theta } \right) = \frac{{\partial G\left( {\varepsilon ,\theta } \right)}}{{\partial \varepsilon }}. $$
(6)

Thus,

$$ \mathop \sum \limits_{{n = 0}}^{\infty } \varepsilon ^{n} nP_{n} \left( {{\text{cos}}\theta } \right) = \varepsilon \frac{{\partial G\left( {\varepsilon ,\theta } \right)}}{{\partial \varepsilon }} = \frac{{\varepsilon \left( {{\text{cos}}\theta - \varepsilon } \right)}}{{(1 + \varepsilon ^{2} - 2\varepsilon {\text{cos}}\theta )^{{3/2}} }}. $$
(7)

This is the equation labeled as ID = 2 in Table 2, except for one constant factor.

Similarly, from Eq. (4), we have

$$ \mathop \sum \limits_{{n = 2}}^{\infty } x^{{n - 1}} P_{n} \left( {{\text{cos}}\theta } \right) = \frac{{G\left( {x,\theta } \right) - 1}}{x} - {\text{cos}}\theta ,\quad 0 < x \le 1. $$
(8)

The integration of Eq. (8) from 0 to \(\varepsilon\) (\(0 < \varepsilon \le 1\)) with respect to \(x\) will result in another fundamental equation. To obtain the result for the right-hand side of Eq. (8), we have to find the original function for the following expression:

$$ \begin{aligned} f\left( x \right) &= \frac{{G\left( {x,\theta } \right) - 1}}{x} - {\text{cos}}\theta = \frac{1}{{x\sqrt {x^{2} - 2x{\text{cos}}\theta + 1} }} \\ &\quad- \frac{1}{x} - {\text{cos}}\theta ,\quad 0 < x \le 1,0 < \theta \le \pi . \end{aligned} $$
(9)

Its original function, \(F\left( x \right),\) can be obtained by referring to a typical integral table book (Gradshteyn and Ryzhik 2000):

$$ \begin{aligned} F\left( x \right) & = - {\text{sinh}}^{{ - 1}} \left( {\frac{{ - 2x{\text{cos}}\theta + 2}}{{x\sqrt {4 - ( - 2{\text{cos}}\theta )^{2} } }}} \right) - {\text{ln}}\left( x \right) - x{\text{cos}}\theta + C_{1} \\ & = - {\text{sinh}}^{{ - 1}} \left( {\frac{{1 - x{\text{cos}}\theta }}{{x{\text{sin}}\theta }}} \right) - {\text{ln}}\left( x \right) - x{\text{cos}}\theta + C_{1} , \\ \end{aligned} $$
(10)

with \(C_{1}\) is a constant of integration.

Using the relationship \({\text{sinh}}^{{ - 1}} \left( x \right) = {\text{ln}}\left( {\sqrt {x^{2} + 1} + x} \right)\), one arrives at

$$ \begin{aligned} F\left( x \right) & = - {\text{ln}}\left( {\frac{{1 - x{\text{cos}}\theta }}{{x{\text{sin}}\theta }} + \frac{{\sqrt {x^{2} - 2x{\text{cos}}\theta + 1} }}{{x{\text{sin}}\theta }}} \right) - {\text{ln}} \left( x \right) - x{\text{cos}}\theta + C_{1} \\ ~ & = - {\text{ln}}\left( {1 - x{\text{cos}}\theta + \sqrt {x^{2} - 2x{\text{cos}}\theta + 1} } \right) - x{\text{cos}}\theta + C_{2} , \\ \end{aligned} $$
(11)

with \(C_{2}\) is another constant of integration. One can gets

$$ \mathop {{\text{lim}}}\limits_{{x \to 0^{ + } }} F\left( x \right) = - {\text{ln}}\left( 2 \right) + C_{2} . $$
(12)

Then, we have

$$ \begin{aligned} \mathop \smallint \limits_{0}^{\varepsilon } f\left( x \right)dx & = F\left( \varepsilon \right) - \mathop {{\text{lim}}}\limits_{{x \to 0^{ + } }} F\left( x \right) \\ & = - {\text{ln}}\left( {1 - \varepsilon {\text{cos}}\theta + \sqrt {\varepsilon ^{2} - 2\varepsilon {\text{cos}}\theta + 1} } \right) - \varepsilon {\text{cos}}\theta + {\text{ln}}\left( 2 \right). \\ \end{aligned} $$
(13)

The integration of Eq. (8) from 0 to \(\varepsilon\) (\(0 < \varepsilon \le 1\)) with respect to \(x\) for the left-hand side results in

$$ \begin{aligned} &\mathop \smallint \limits_{0}^{\varepsilon } \left[ {\mathop \sum \limits_{{n = 2}}^{\infty } x^{{n - 1}} P_{n} \left( {{\text{cos}}\theta } \right)} \right]dx \\ &\quad= \mathop \sum \limits_{{n = 2}}^{\infty } \left[ {\left( {\mathop \smallint \limits_{0}^{\varepsilon } x^{{n - 1}} dx} \right)P_{n} \left( {{\text{cos}}\theta } \right)} \right] = \mathop \sum \limits_{{n = 2}}^{\infty } \frac{{\varepsilon ^{n} }}{n}P_{n} \left( {{\text{cos}}\theta } \right). \end{aligned} $$
(14)

By showing that the right-hand side of Eq. (8) is indeed integrable, we show simultaneously that the Weierstrass M-Test is fulfilled such that the exchange the operation of integration and summation can be done. In addition, for the above definite integral, it is not an improper integral because nor the upper nor the lower limits of the integrand goes to infinite.

Finally, we obtain the analytical expression by combining Eqs. (8, 13, 14):

$$ \mathop \sum \limits_{{n = 1}}^{\infty } \frac{{\varepsilon ^{n} }}{n}P_{n} \left( {{\text{cos}}\theta } \right) = {\text{ln}}\left( 2 \right) - {\text{ln}}\left( {1 - \varepsilon {\text{cos}}\theta + \sqrt {1 - 2\varepsilon {\text{cos}}\theta + \varepsilon ^{2} } } \right). $$
(15)

2.2 All of the analytical equations

Using the scheme above (Singh and Ben-Menahem 1968) and the basic expressions (Eqs. 4 and 15), one can find all of the similar closed-form infinite series. It would be easier to follow if the process were formulated. Thus, the detailed process is given in Table 1 using the Wolfram Language (Wolfram 1999; Schmied 2020).

Table 1 The Mathematica code used to derive the analytical equations of the infinite series involving \(P_{n}^{m}\). The abbreviated variables \(w\), \(s\), \(c\), \(g\left[ {\varepsilon ,{\text{~}}\theta } \right]\), and Pn2 are defined in the first line. Note: opt is a parameter of the built-in function Lim[x]

To ensure the correctness of this process, we partly used Mathematica (Wolfram 1999; Abell and Braselton 2017) to complete several of the integrals and differential operations. First, we obtained the original function for the definite integral, and then, we calculated the limit values' difference at the end of the integral interval. The details of the Mathematica code used to derive each equation are given in column 3 of Table 1.

Taking the derivative of these analytical expressions will result in the analytical sums of the derivatives of the Legendre functions. This can be done using pen and paper or using a symbolic calculator. We partly used Mathematica in the verification, simplification, and derivation processes. It is advantageous, can ensure the accuracy of the results, and facilitate the checking of the compatibility of the various equations. However, it should be noted that Mathematica sometimes presents very long expressions that are not expected. We had to simplify many of the equations by hand and finally obtained the final equation with a relatively tight form (Tables 2, 3, 4). In the tables, several shorthand notations are used: \(w = (1 - 2\varepsilon c + \varepsilon ^{2} )^{{1/2}}\), \(c = {\text{cos}}\theta\), \(s = sin\theta\), \(P\left[ {n,m} \right] = P_{n}^{m} \left( {cos\theta } \right)\), \(dP\left[ {n,m} \right] = dP_{n}^{m} \left( {{\text{cos}}\theta } \right)/d\theta\), and \(ddP\left[ {n,m} \right] = d^{2} P_{n}^{m} \left( {{\text{cos}}\theta } \right)/d\theta ^{2}.\)

Table 2 Analytical sums of the series of Legendre functions
Table 3 Analytical sums of the series of the first derivatives of the Legendre functions
Table 4 Analytical sums of the series of the second derivatives of the Legendre functions

2.3 Verification and visualization

In order to thoroughly verify the above equations, we calculated the sum of the series using numerical methods and the above analytical equations. We wrote several Fortran 90 routines using double precision to calculate the first \(N\) terms of the series, and then, we summed them to obtain an approximate sum. For simplicity, but without losing generality, \(\varepsilon\) was set as 1/2. It can be inferred that without considering the rounding error, the more terms involved in the summation, the closer the numerical results will be to the analytical values. As an example, we calculated the 600 terms of the series and sum them to approximately express the sum of the series (Figs. 1, 2, 3, 4, 5, 6). The result was written to the files with 16 significant figures. Then, we compared these approximate sums with the analytical sums in Figs. 1, 3, and 5. Under various angular distances discretely sampled within \(\left[ {0.5^\circ ,{\text{~}}179.0^\circ } \right]\), the results of the numerical summation and that of the analytical equation are highly consistent, and their curves almost overlap.

Fig. 1
figure 1

Verification of the Legendre summation equation corresponding to Table 2. In each subfigure, \({\text{P}}_{i}\) denotes the i-th equation in Table 2

Fig. 2
figure 2

Relative error (RE) of the corresponding numerical calculation in Fig. 1. Note that the relative error is a common logarithmic function

Fig. 3
figure 3

Verification of the first derivatives of the Legendre summation equation corresponding to Table 3. In each subfigure, \( \partial _{\theta } P_{i} \) denotes the i-th equation in Table 3

Fig. 4
figure 4

Relative error (RE) of the corresponding numerical calculation in Fig. 3. The relative error is a common logarithmic function

Fig. 5
figure 5

Verification of the second derivatives of the Legendre summation equation corresponding to Table 4. In each subfigure, \( \partial _{{\theta \theta }} P_{i} \) denotes the i-th equation in Table 4

Fig. 6
figure 6

Relative error (RE) of the corresponding numerical calculation in Fig. 5. The relative error is a common logarithmic function

To further analyze the differences between them, we calculated the relative errors of the approximate sums in Figs. 2, 4, and 6. Because the relative error was very small, we took the logarithm of it. Note, hereafter when the absolute error with a reservation of 16 significant digits is zero, we set the logarithm relative error to 14.0 in his paper. As can be seen, the results of the numerical calculation and the analytical equation are very consistent, and the relative error between them is less than about \(10^{{ - 10}}\).

We carefully checked the Legendre function and the summation program of the numerical calculations. We also compared the results under other values of \(\varepsilon\) and found the consistency to be excellent. The comparison of the numerical methods and analytical formulas when \(\varepsilon = 1/8\) is shown in Appendix. Thus, the correctness of the analytical equations given in Tables 1, 2, 3, 4 was confirmed.

2.4 Explanation of the possible singularity

From the generating function of the Legendre functions, i.e., Eq. (4) and other analytical equations in Tables 2, 3, 4, we found that a singularity may exist for \(\varepsilon =0\), \(\varepsilon =1\), \(\theta =0\), and \(\theta =\pi \). There are four cases involving the possible singularities: (a) for \(\varepsilon =0\) and \(\theta =0\); (b) for \(\varepsilon =0\) and \(\theta =\pi \); (c) for \(\varepsilon =1\) and \(\theta =0\); (d) for \(\varepsilon =1\) and \(\theta =\pi \). For cases (a) and (b), there is no physical meaning in the scope of this paper. In addition, in the actual derivation and calculation process, we also defined that \(\varepsilon \) can be an arbitrarily small positive number, but cannot be 0. In view of the above reasons, we only discuss the possible singularities for the last two cases.

2.4.1 Singularity when \(\boldsymbol{\varepsilon }=1\) and \(\boldsymbol{\theta }=0\)

When \(\varepsilon =1\), the infinite series such as \( \sum {\frac{1}{{n \pm 1}}} P_{n} \left( {{\text{cos}}\theta } \right)\;{\text{and}}\;{\text{~}}\sum {\frac{1}{{n \pm 1}}} \frac{d}{{d\theta }}P_{n} \left( {{\text{cos}}\theta } \right), \) but not \(\sum \frac{1}{{n}^{2}}{P}_{n}(\mathrm{c}\mathrm{o}\mathrm{s}\theta )\) are not convergent at \(\theta =0\) because \(P_{n} \left( 1 \right) = 1\) and the harmonic series is the divergent infinite series. Although they are divergent series, to show their characteristics more clearly, we give their series expansion form using \(s = {\text{sin}}\theta\) around the point \(\theta = 0\) in Table 5. Here, only the leading terms were retained.

Table 5 Series expansion of the Legendre summation equations with \(s = {\text{sin}}\theta\) around point \(\theta = 0\) when \(\varepsilon = 1\). The leading term is retained here

Because of the singularity at this point, the above formulas in Tables 2, 3, 4 do not apply to this case when is \(\theta\) very small. The singularity at this point is not only mathematical. In actual physical research, this point usually means the observation point coincides with the source; it is usually irregular in physics. When dealing with practical problems, we usually need to know the physical properties near the singular point. When calculating the deformation Green's function of an earthquake or loading near the source point, we will encounter this situation. For instance, Sun and Dong (2013) discussed this type of singularity when calculating the co-seismic Green’s functions for a surface seismic rupture. When \(\varepsilon = 1\) and \(\theta \to 0\), some Green's functions tend to diverge in physics. But in the actual calculation, we need to calculate the Green's function at a relatively very small value of \(\theta\). At this case, the approximate series formula in Table 5 can be used to as some very good approximate formulas when \(\theta\) is small.

To make it clear, we compared the analytical formulas in Table 2 with the approximate series formulas in Table 5. We set \(\varepsilon\) to 1 and calculated the ratios of two kinds of formulas for different \(\theta\) values near 0. In Fig. 7, the y-axis denotes the result calculated by the approximate series formula divided by the analytical formula, and the black, red and blue line denotes formula involving \(P_{n} \left( {{\text{cos}}\theta } \right)\), \(\partial _{\theta } P_{n} \left( {{\text{cos}}\theta } \right)\) and \(\partial _{{\theta \theta }} P_{n} \left( {{\text{cos}}\theta } \right)\), respectively. We can see clearly that when \(\theta \to 0\), they tend to be consistent.

Fig. 7
figure 7

Comparison of the analytical formula in Table 2 with the approximate series formulas in Table 5 when \(\varepsilon = 1\). x-axis for \(\sin \left( \theta \right)\) and y-axis for the ratio of the series formulas and the analytical formula. Each subfigure is labeled by a number \(\left( i \right)\) denoting the i-th expression in Table 5

In addition to approximate the analytical expressions, the series formulas in Table 5 can also be used to conveniently analyze the orders of these analytical expressions approaching infinity when \(\theta \to 0\), which is also useful in the discussion of physical problems (Okubo 1988; Pan 2019) near the source.

2.4.2 No singularity, then \({\varepsilon } = 1\) and \({\theta } = {\pi }\)

Unlike the situation described in Sect. 2.4.1, all of the equations at this point are regular because \(P_{n} \left( { - 1} \right) = - 1\) and the alternating harmonic series is a convergent series. Once we have obtained the analytical expression of the Legendre functions series, by setting \(\varepsilon = 1\) and calculating the limit value when \(\theta\) approaches \(\pi\), the nature around point \(\theta = \pi\) can be fully demonstrated. The accurate limit value at \(\theta = \pi\) is given in Table 6.

Table 6 Limit values of all of the analytical equations at point \(\theta = \pi\) when \(\varepsilon = 1\)

However, one cannot guarantee a correct result using a double-precision calculation code, such as the Fortran program, when \(\theta\) approaches \(\pi\) due to the numerical calculation error. This is easy to explain because \({\text{sin}}\left( \theta \right)\) appears in the denominator of some of the calculation equations. Our double-precision Fortran program can give the correct result within [0.01°, 179.99°] using our test. For calculations outside of this interval, higher precision calculations are needed to obtain the correct results. This can be achieved using the quad-precision Fortran program or using Mathematica’s or MATLAB’s symbolic calculation functions.

3 Two application in the fields of geodesy and geophysics

3.1 Calculating the load Green’s function

A typical application of the above analytical summation equation is calculating the loading deformation on the Earth (Longman 1963; Farrell 1972; Goad 1980; Han and Wahr 1995; Agnew 1997, 2012; Boy et al. 1998; Tromp and Mitrovica 1999; Spada et al. 2011; Wijaya et al. 2013; Lu et al. 2018; Zhou et al. 2019; Tang et al. 2020). We take the radial displacement as an example. A 1 kg surface point mass at the North Pole will cause the elastic solid Earth to deform globally, and the radial displacement (Farrell 1972) is written as

$$ U\left( \theta \right) = \sum _{{n = 0}}^{{n = \infty }} h'_{n} P_{n} \left( {{\text{cos}}\theta } \right). $$
(16)

Here, \(\theta\) denotes the angular distance from the loading point; and \(P_{n} \left( {{\text{cos}}\theta } \right)\) are the Legendre functions. \(h'_{n}\) are the load Love numbers, which are responsible for the elastic response of the Earth. The Love numbers \(h'_{n}\) are usually calculated for each degree \(n\) by numerically solving ordinary differential equations (Longman 1963, 1962). However, it is challenging to obtain numerically stable values of very high degree Love numbers. Moreover, the above series Eq. (16) usually converges slowly, especially when \(\theta\) is small (Farrell 1972; Fowler et al. 2019).

As was pointed out by Okubo (1988), due to the fact that \( \mathop {\lim }\limits_{{\theta \to 0}} P_{n} \left( {\cos \theta } \right) = 1 \), \(h'_{n} \to O\left( 1 \right)\) where \(n \to \infty\), the brute force summation approach fails. Farrell (1972) and Guo (2000) derived the asymptotic expression for the Load Love number when \(n \to \infty\), \(h'_{n}\) as \( \mathop {\lim }\limits_{{n \to \infty }} h_{n}^{\prime } = h_{\infty }^{\prime } = - \frac{{g_{0} m_{e} \left( {\lambda + 2\mu } \right)}}{{4\pi a^{2} \left( {\lambda + \mu } \right)\mu }} \). Here, \(\lambda\) and \(\mu\) are the Lamé constants of the outermost layer's elastic parameters; \(g_{0}\) and \(m_{e}\) are the surface gravitation and mass of the Earth, respectively; and \(a\) is the Earth's mean radius. Then, the convergence difficulty can be circumvented by using a new series (Okubo 1988):

$$ U\left( \theta \right) = \sum _{{n = 0}}^{{n = \infty }} h'_{\infty } P_{n} \left( {{\text{cos}}\theta } \right) + \sum _{{n = 0}}^{{n = \infty }} \left( {h'_{n} - h^{\prime}_{\infty } } \right)P_{n} \left( {{\text{cos}}\theta } \right). $$
(17)

Here, the first term on the right-hand side of the above expression can be analytically obtained using Eq. (1) in Table 1 by setting \(\varepsilon = 1\). The second term in Eq. (17) can be numerically handled quickly since \(h'_{n} - h'_{\infty }\) is of the order \(O\left( {1/n} \right)\), and the new series converges much faster. Using this strategy, we rewrite the above equation as

$$ U\left( \theta \right) = \frac{{h'_{\infty } }}{{2{\text{sin}}\left( {\theta /2} \right)}} + \sum _{{n = 0}}^{{n = \infty }} \left( {h'_{n} - h'_{\infty } } \right)P_{n} \left( {{\text{cos}}\theta } \right). $$
(18)

This type of transformation is called Kummer’s transform (Singh et al. 1990). Because with the increase of degree \(n\), \(\left( {h'_{n} - h'_{\infty } } \right)P_{n} \left( {{\text{cos}}\theta } \right)\) approaches to 0 gradually, so the summation of the above series can be approximately replaced by the first \(N\) terms of it. We set different truncation degree \(N\) to observe the convergence performance. We calculated and plotted the radial displacement using Eqs. (16) and (18) with a truncation of the series at \(N\) in Fig. 8. For simplicity, we only calculated the first 10,000 terms of the series and their partial sums.

Fig. 8
figure 8

Comparison of the convergence speeds of the different methods used to calculate the loading Green’s function for the radial displacement. The blue lines denote the brute force numerical summation truncation at \(N\). The horizontal green lines represent the analytical partition in Eq. (18). The orange lines indicate the analytical part plus the numerical residue in Eq. (18)

Here, all of the parameters were obtained from the Preliminary Reference Earth Model (PREM) model (Dziewonski and Anderson 1981). In this figure, the blue lines denote the brute force numerical summation using Eq. (16), the horizontal green lines represent the analytical partition in Eq. (18), and the orange line represents the analytical partition plus the numerical residue in Eq. (18). Take Fig. 8b as an example to illustrate the influence of the second part of Eq. (18). The difference between the orange line and the green line reflects the effect of the second part, the sum of the residue series, of Eq. (18). It can be seen that in Fig. 8b, the sum of the residue series is about 500, the estimated true value is approximately -6500, and its relative error is 7.7%. Other graphs have similar meanings. It can be seen that with the increase in angular distance, the importance of residue series of Eq. (18) increases gradually.

We found that the direct summation method still cannot achieve convergence after using 10,000 Love numbers, especially when \(\theta\) is less than 0.5°. The convergence speed of the residue series is greatly improved. The analytical partition plays a leading role when the angular distance \(\theta\) is very small. For the sake of simplicity, sometimes the analytical part can be directly used to replace the true Green’s function in near field deformation, such as at \(\theta < 0.01^\circ\).

3.2 Calculating the co-seismic Green’s deformation

Here, we take the co-seismic areal strain Green’s functions on the Earth's surface as another example.

We suppose a point dislocation (Sun 2004b) with an area of \(dS\) undergoing a strike-slip \(U\) on a vertical fault trending in the direction of the Greenwich meridian with the location of the radius \(r = r_{s}\) below the North Pole \(\theta = 0^\circ\). The areal strain \(\Xi _{{area}}\) on the surface (\(r = a\)) of the Earth at co-latitude \(\theta\) and longitude \(\varphi\) can be expressed as

$$ \Xi _{{area}} \left( {a,\theta ,\varphi } \right) = 2{\text{sin}}\left( {2\varphi } \right) \cdot \mathop \sum \limits_{{n = 2}}^{{n = \infty }} \left[ { - 2h_{n}^{{12}} P_{n}^{2} \left( c \right) + l_{n}^{{12}} \left( {\frac{4}{{s^{2} }}P_{n}^{2} \left( c \right) - \frac{c}{s}\frac{{dP_{n}^{2} \left( c \right)}}{{d\theta }} - \frac{{d^{2} P_{n}^{2} \left( c \right)}}{{d\theta ^{2} }}} \right)} \right] \times \frac{{UdS}}{{a^{3} }}. $$
(19)

Here, \(h_{n}^{{12}}\) and \(l_{n}^{{12}}\) are the dislocation Love numbers for a vertical strike-slip source (Sun et al. 1996) of degree \(n\). They depend on the source location and the Earth model structure (Sun et al. 1996). The shorthand notations \(c = {\text{cos}}\theta\) and \(s = {\text{sin}}\theta\) are used in Eq. (19).

The asymptotic expansion of the dislocation Love number (Okubo 1988; Sun 2003) when the degree \(n\) is extremely large cannot be easily obtained. To save space, we give them directly here. Interested readers can refer to previous papers for details (Okubo 1988; Sun 2003). When \(n \to \infty\), the asymptotic form of the dislocation Love numbers can be written as

$$ \left\{ {\begin{array}{*{20}l} {h_{n}^{{asy - 12}} = \varepsilon ^{{n - 1}} \left( {y_{{230}}^{{12}} + \frac{1}{n}y_{{231}}^{{12}} + \frac{1}{{n^{2} }}y_{{232}}^{{12}} + O\left( {n^{{ - 3}} } \right)} \right)} \hfill \\ {l_{n}^{{asy - 12}} = \frac{{\varepsilon ^{{n - 1}} }}{n}\left( {y_{{330}}^{{12}} + \frac{1}{n}y_{{331}}^{{12}} + \frac{1}{{n^{2} - 1}}y_{{332}}^{{12}} + O\left( {n^{{ - 3}} } \right)} \right)} \hfill \\ \end{array} } \right.,\quad \varepsilon = r_{s} /a. $$
(20)

\(y_{{kmn}}^{{12}}\) represents the variables determined by the Earth's elastic parameters and by the seismic source, and their explicit expressions can be found in previous papers (Sun 2003, 2004a, b; Tang and Sun 2017). Because the asymptotic solution expresses the property of the Love number of degree \(n\) by expanding it as a series of \(1/n^{i}\) when \(n\) is infinitely large. Comparing with the real value, the error caused by this approximation can be ignored in the near field (Okubo 1988). Therefore, we can make a further approximation, that is, changing \(1/n^{i}\) into other form but keeping its order and this operation will not affect its coefficient (see the main text below Eq. (9) in Tang et al. (2020)). It should be noted that the third item in parentheses, \(l_{n}^{{asy - 12}}\), was modified by replacing \(1/n^{3}\) with \(1/\left( {n^{3} - n} \right)\) in order to simplify the following analytical summation process.

To show that it is difficult to calculate the convergence of the strain Green's function in the near field, we conduct a simple analysis here. A truncated Taylor series expansion of the Legendre functions near the North Pole up to the second order will help us understand its property when \(\theta \to 0\). This can be obtained by using Mathematica code “Series[LegendreP[n, 2, Cos[\[Theta]]], {\[Theta], 0, 3}]” as

$$ P_{n}^{2} \left( {{\text{cos}}\theta } \right) = n\left( {n^{2} - 1} \right)\left( {n + 2} \right)\theta ^{2} /8 + O\left( {\theta ^{4} } \right),\quad \theta \to 0. $$
(21)

It means \(P_{n}^{2} \left( {{\text{cos}}\theta } \right)\) can be approximately replaced by a simple polynomial of \(\theta\) and has an order of \(O\left( {n^{4} } \right)\) when \(~\theta \to 0\).

Thus, the general term in Eq. (19) is of the order of \(\varepsilon ^{{n - 1}} O\left( {n^{4} } \right)\). This results in the slow convergence of the series in Eq. (19) when \(\varepsilon \to 1\) because \(\varepsilon\) is slightly smaller than 1 under normal circumstances. As was shown in the above subsection, the brute force approach fails when the dislocation’s location approaches the observation point, that is, when \(\varepsilon \to 1\) and \(\theta \to 0\).

For the deformation Green’s functions in the near field, the contributions of the high degree Love numbers absolutely dominate compared to the case with low degrees. After replacing the dislocation Love numbers \(h_{n}^{{12}}\) and \(l_{n}^{{12}}\) with their asymptotic expansions \(h_{n}^{{asy - 12}}\) and \(l_{n}^{{asy - 12}}\) (Eq. 20), and using the above analytical equations involving the associated Legendre functions and their derivatives (Tables 2, 3, 4), the Green’s functions of the areal strain can be written in a closed-form as a good approximation of Eq. (19) when \(\theta\) is small. Submitting Eq. (20) into Eq. (19), one gets

$$ \begin{aligned} \Xi _{{area}}^{{asy}} \left( {a,\theta ,\varphi } \right) & = \frac{{2UdS{\text{sin}}\left( {2\varphi } \right)}}{{a^{3} }} \times \left\{ {y_{{330}}^{{12}} \left( {\frac{4}{{s^{2} }}P_{{16}} - \frac{c}{s}P_{{16}}^{\prime } - P_{{16}}^{{\prime \prime }} } \right) - 2\left( {y_{{230}}^{{12}} P_{{15}} + y_{{231}}^{{12}} P_{{16}} + y_{{232}}^{{12}} P_{{19}} } \right)} \right. \\ & \quad + y_{{332}}^{{12}} \left[ {\frac{4}{{s^{2} }}\left( {\frac{{P_{{17}} + P_{{18}} }}{2} - P_{{16}} } \right) - \frac{c}{s}\left( {\frac{{P_{{17}}^{\prime } + P_{{18}}^{\prime } }}{2} - P_{{16}}^{\prime } } \right) - \left( {\frac{{P_{{17}}^{{\prime \prime }} + P_{{18}}^{{\prime \prime }} }}{2} - P_{{16}}^{{\prime \prime }} } \right)} \right]\left. {~\quad + y_{{331}}^{{12}} \left( {\frac{4}{{s^{2} }}P_{{19}} - \frac{c}{s}P_{{19}}^{\prime } - P_{{19}}^{{\prime \prime }} } \right)} \right\}. \\ \end{aligned} $$
(22)

Here, \(P_{i}\), \(P'_{i}\), and \(P''_{i}\) denote the i-th equations of the Legendre functions and their derivatives with respect to \(\theta\) (Tables 2, 3, 4). It should be noted that \(y_{{kmn}}^{{12}}\) can be found in a previous paper (e.g., Tang and Sun 2017).

As a case study, we considered a dislocation with a depth of \(d = a - r_{s} = 32{\text{~km}}\) in a homogeneous sphere. The parameters of a slightly modified PREM model (Dziewonski and Anderson 1981; Sun and Okubo 2004) are used here: the mean radius of the Earth \(a = 6371{\text{~km}}\), Lame constants of \(\lambda = 34.2{\text{~GPa}}\) and \(\mu = 26.6{\text{~GPa}}\), and a density of \(\rho = 5.5 \times 10^{3} {\text{~kg}}/{\text{m}}^{3}\). By assuming a factor of \(10^{6} UdS/a^{3} = 1\), the areal strain was calculated and is shown in Fig. 9.

Fig. 9
figure 9

Areal strain resulting from a vertical strike-slip motion with a depth of 32 km: a calculated using the numerical method (Liu et al., 2018), b calculated using the analytical expressions using Eq. (22) and c = ab. Both were normalized by assuming \(10^{6} UdS/a^{3} = 1\)

To validate our analytical expressions, we compared our analytical results with those calculated using the numerical method (Liu et al. 2018). The main point of this numerical method is to obtain the dislocation Love number by numerically solving the differential equations for the seismic deformation and then to obtain the Green’s function by numerically summing the Love number using Eq. (19). The numerical result is shown in Fig. 9a, the analytical result is shown in Fig. 9b, and the difference is shown in Fig. 9c. The pattern and magnitude of the two results are in good agreement and their absolute errors are small.

This consistency indicates that our analytical expression for the areal strain is a good approximation when the angular distance \(\theta\) is small. If one wants to obtain more accurate results, one should add the difference between the asymptotic Love number and the exact Love number was done in the previous subsection, i.e., the second term of Kummer’s transform should be added (Eq. 18).

4 Discussion and conclusions

In this paper, starting with the Legendre functions' generating function, nearly sixty analytical equations of an infinite series were presented through rigorous verification involving the associated Legendre functions \(P_{n}^{m} \left( {{\text{cos}}\theta } \right)\) with \(m \le 2\) and their first and second derivatives. To make it accessible to all readers, we published our Mathematica, GNU Octave/MATLAB, and Fortran codes on GitHub. We recommend using Mathematica to calculate them if possible because it can provide a correct value for any \(\theta\) in the open interval \(\left( {0,\pi } \right)\). Other numerical programs written using Fortran and MATLAB with double-precision are recommended when 0.01 \(^\circ < \theta < 179.99^\circ\). If quad-precision is used, then the situation will be improved.

Here, we present the equations for the series of second derivatives of the associated Legendre functions, and their higher derivatives can be quickly obtained through differentiation. Using a process similar to that described in Sect. 2, similar infinite series, such as \(\sum \varepsilon ^{{n - 1}} /n^{k} P_{n}^{m} \left( {{\text{cos}}\theta } \right)\) with \(k > 3\) and its derivatives, can be easily written as a definite integral. If these definite integrals are obtained, one will get a new summation expression for the Legendre functions. The expansion and promotion of these equations are left for follow-up research.

Alternatively, several complex series such as \(\sum \varepsilon ^{{n - 1}} /n^{k} P_{n}^{m} \left( {{\text{cos}}\theta } \right)\) can be replaced with a simpler form to avoid this problem in practical applications. For instance, one can replace the factor \(1/n^{3}\) with \(1/\left( {n^{3} - n} \right)\), and then, the new series’ analytical summation can be easily obtained through the linear combination of the equations listed in Sect. 2.