# Euler–Maclaurin formula

In mathematics, the Euler–Maclaurin formula is a formula for the difference between an integral and a closely related sum. It can be used to approximate integrals by finite sums, or conversely to evaluate finite sums and infinite series using integrals and the machinery of calculus. For example, many asymptotic expansions are derived from the formula, and Faulhaber's formula for the sum of powers is an immediate consequence.

The formula was discovered independently by Leonhard Euler and Colin Maclaurin around 1735. Euler needed it to compute slowly converging infinite series while Maclaurin used it to calculate integrals. It was later generalized to Darboux's formula.

## The formula

If $\displaystyle{ m }$ and $\displaystyle{ n }$ are natural numbers and $\displaystyle{ f(x) }$ is a real or complex valued continuous function for real numbers $\displaystyle{ x }$ in the interval $\displaystyle{ [m, n] }$, then the integral $\displaystyle{ I = \int_m^n f(x)\,dx }$ can be approximated by the sum (or vice versa) $\displaystyle{ S = f(m + 1) + \cdots + f(n - 1) + f(n) }$ (see rectangle method). The Euler–Maclaurin formula provides expressions for the difference between the sum and the integral in terms of the higher derivatives $\displaystyle{ f^{(k)}(x) }$ evaluated at the endpoints of the interval, that is to say when $\displaystyle{ x=m }$ and $\displaystyle{ x=n }$.

Explicitly, for $\displaystyle{ p }$ a positive integer and a function $\displaystyle{ f(x) }$ that is $\displaystyle{ p }$ times continuously differentiable on the interval $\displaystyle{ [m, n] }$, we have $\displaystyle{ S - I = \sum_{k=1}^p {\frac{B_k}{k!} (f^{(k - 1)}(n) - f^{(k - 1)}(m))} + R_p, }$ where $\displaystyle{ B_k }$ is the $\displaystyle{ k }$th Bernoulli number (with $\displaystyle{ B_1=1/2 }$) and $\displaystyle{ R_p }$ is an error term which depends on $\displaystyle{ n }$, $\displaystyle{ m }$, $\displaystyle{ p }$, and $\displaystyle{ f }$ and is usually small for suitable values of $\displaystyle{ p }$.

The formula is often written with the subscript taking only even values, since the odd Bernoulli numbers are zero except for $\displaystyle{ B_1 }$. In this case we have[1][2] $\displaystyle{ \sum_{i=m}^n f(i) = \int^n_m f(x)\,dx + \frac{f(n) + f(m)}{2} + \sum_{k=1}^{\lfloor p/2\rfloor} \frac{B_{2k}}{(2k)!} (f^{(2k - 1)}(n) - f^{(2k - 1)}(m)) + R_p, }$ or alternatively $\displaystyle{ \sum_{i=m+1}^n f(i) = \int^n_m f(x)\,dx + \frac{f(n) - f(m)}{2} + \sum_{k=1}^{\lfloor p/2\rfloor} \frac{B_{2k}}{(2k)!} (f^{(2k - 1)}(n) - f^{(2k - 1)}(m)) + R_p. }$

### The remainder term

The remainder term arises because the integral is usually not exactly equal to the sum. The formula may be derived by applying repeated integration by parts to successive intervals $\displaystyle{ [r, r+1] }$ for $\displaystyle{ r = m, m + 1, \ldots, n - 1 }$. The boundary terms in these integrations lead to the main terms of the formula, and the leftover integrals form the remainder term.

The remainder term has an exact expression in terms of the periodized Bernoulli functions $\displaystyle{ P_k(x) }$. The Bernoulli polynomials may be defined recursively by $\displaystyle{ B_0(x) = 1 }$ and, for $\displaystyle{ k \ge 1 }$, \displaystyle{ \begin{align} B_k'(x) &= kB_{k - 1}(x), \\ \int_0^1 B_k(x)\,dx &= 0. \end{align} } The periodized Bernoulli functions are defined as $\displaystyle{ P_k(x) = B_k(x - \lfloor x\rfloor), }$ where $\displaystyle{ \lfloor x \rfloor }$ denotes the largest integer less than or equal to $\displaystyle{ x }$, so that $\displaystyle{ x - \lfloor x \rfloor }$ always lies in the interval $\displaystyle{ [0,1) }$.

With this notation, the remainder term $\displaystyle{ R_p }$ equals $\displaystyle{ R_p = (-1)^{p+1}\int_m^n f^{(p)}(x) \frac{P_p(x)}{p!}\,dx. }$

When $\displaystyle{ k\gt 0 }$, it can be shown that $\displaystyle{ |B_k(x)| \le \frac{2 \cdot k!}{(2\pi)^k}\zeta(k), }$ where $\displaystyle{ \zeta }$ denotes the Riemann zeta function; one approach to prove this inequality is to obtain the Fourier series for the polynomials $\displaystyle{ B_k(x) }$. The bound is achieved for even $\displaystyle{ k }$ when $\displaystyle{ x }$ is zero. The term $\displaystyle{ \zeta(k) }$ may be omitted for odd $\displaystyle{ k }$ but the proof in this case is more complex (see Lehmer).[3] Using this inequality, the size of the remainder term can be estimated as $\displaystyle{ |R_p| \leq \frac{2 \zeta(p)}{(2\pi)^p}\int_m^n |f^{(p)}(x)|\,dx. }$

### Low-order cases

The Bernoulli numbers from $\displaystyle{ B_1 }$ to $\displaystyle{ B_7 }$ are $\displaystyle{ \tfrac{1}{2}, \tfrac{1}{6}, 0, -\tfrac{1}{30}, 0, \tfrac{1}{42}, 0. }$ Therefore the low-order cases of the Euler-Maclaurin formula are: \displaystyle{ \begin{align} \sum_{i=m}^n f(i) - \int_m^n f(x)\,dx &= \frac{f(m)+f(n)}{2} + \int_m^n f'(x)P_1(x)\,dx \\ &=\frac{f(m)+f(n)}{2} + \frac{1}{6}\frac{f'(n) - f'(m)}{2!} - \int_m^n f''(x)\frac{P_2(x)}{2!}\,dx \\ &=\frac{f(m)+f(n)}{2} + \frac{1}{6}\frac{f'(n) - f'(m)}{2!} + \int_m^n f'''(x)\frac{P_3(x)}{3!}\,dx \\ &=\frac{f(m)+f(n)}{2} + \frac{1}{6}\frac{f'(n) - f'(m)}{2!} - \frac{1}{30}\frac{f'''(n) - f'''(m)}{4!}-\int_m^n f^{(4)}(x) \frac{P_4(x)}{4!}\, dx \\ &=\frac{f(m)+f(n)}{2} + \frac{1}{6}\frac{f'(n) - f'(m)}{2!} - \frac{1}{30}\frac{f'''(n) - f'''(m)}{4!} + \int_m^n f^{(5)}(x)\frac{P_5(x)}{5!}\,dx \\ &=\frac{f(m)+f(n)}{2} + \frac{1}{6}\frac{f'(n) - f'(m)}{2!} - \frac{1}{30}\frac{f'''(n) - f'''(m)}{4!} + \frac{1}{42}\frac{f^{(5)}(n) - f^{(5)}(m)}{6!} - \int_m^n f^{(6)}(x)\frac{P_6(x)}{6!}\,dx \\ &=\frac{f(m)+f(n)}{2} + \frac{1}{6}\frac{f'(n) - f'(m)}{2!} - \frac{1}{30}\frac{f'''(n) - f'''(m)}{4!} + \frac{1}{42}\frac{f^{(5)}(n) - f^{(5)}(m)}{6!} + \int_m^n f^{(7)}(x)\frac{P_7(x)}{7!}\,dx. \end{align} }

## Applications

### The Basel problem

The Basel problem is to determine the sum $\displaystyle{ 1 + \frac14 + \frac19 + \frac1{16} + \frac1{25} + \cdots = \sum_{n=1}^\infty \frac{1}{n^2}. }$

Euler computed this sum to 20 decimal places with only a few terms of the Euler–Maclaurin formula in 1735. This probably convinced him that the sum equals $\displaystyle{ \pi^2/6 }$, which he proved in the same year.[4]

### Sums involving a polynomial

If $\displaystyle{ f }$ is a polynomial and $\displaystyle{ p }$ is big enough, then the remainder term vanishes. For instance, if $\displaystyle{ f(x)=x^3 }$, we can choose $\displaystyle{ p=2 }$ to obtain, after simplification, $\displaystyle{ \sum_{i=0}^n i^3 = \left(\frac{n(n + 1)}{2}\right)^2. }$

### Approximation of integrals

The formula provides a means of approximating a finite integral. Let $\displaystyle{ a \lt b }$ be the endpoints of the interval of integration. Fix $\displaystyle{ N }$, the number of points to use in the approximation, and denote the corresponding step size by $\displaystyle{ h = (b - a) / (N - 1) }$. Set $\displaystyle{ x_i = a + (i-1)h }$, so that $\displaystyle{ x_1 = a }$ and $\displaystyle{ x_N = b }$. Then:[5] \displaystyle{ \begin{align} I & = \int_a^b f(x)\,dx \\ &\sim h\left(\frac{f(x_1)}{2} + f(x_2) + \cdots + f(x_{N-1}) + \frac{f(x_N)}{2}\right) + \frac{h^2}{12}[f'(x_1) - f'(x_N)] - \frac{h^4}{720}[f'''(x_1) - f'''(x_N)] + \cdots. \end{align} }

This may be viewed as an extension of the trapezoid rule by the inclusion of correction terms. Note that this asymptotic expansion is usually not convergent; there is some $\displaystyle{ p }$, depending upon $\displaystyle{ f }$ and $\displaystyle{ h }$, such that the terms past order $\displaystyle{ p }$ increase rapidly. Thus, the remainder term generally demands close attention.[5]

The Euler–Maclaurin formula is also used for detailed error analysis in numerical quadrature. It explains the superior performance of the trapezoidal rule on smooth periodic functions and is used in certain extrapolation methods. Clenshaw–Curtis quadrature is essentially a change of variables to cast an arbitrary integral in terms of integrals of periodic functions where the Euler–Maclaurin approach is very accurate (in that particular case the Euler–Maclaurin formula takes the form of a discrete cosine transform). This technique is known as a periodizing transformation.

### Asymptotic expansion of sums

In the context of computing asymptotic expansions of sums and series, usually the most useful form of the Euler–Maclaurin formula is $\displaystyle{ \sum_{n=a}^b f(n) \sim \int_a^b f(x)\,dx + \frac{f(b) + f(a)}{2} + \sum_{k=1}^\infty \,\frac{B_{2k}}{(2k)!} \left(f^{(2k - 1)}(b) - f^{(2k - 1)}(a)\right), }$

where $\displaystyle{ a }$ and $\displaystyle{ b }$ are integers.[6] Often the expansion remains valid even after taking the limits $\displaystyle{ a\rightarrow-\infty }$ or $\displaystyle{ b\rightarrow +\infty }$ or both. In many cases the integral on the right-hand side can be evaluated in closed form in terms of elementary functions even though the sum on the left-hand side cannot. Then all the terms in the asymptotic series can be expressed in terms of elementary functions. For example, $\displaystyle{ \sum_{k=0}^\infty \frac{1}{(z + k)^2} \sim \underbrace{\int_0^\infty\frac{1}{(z + k)^2}\,dk}_{= 1/z} + \frac{1}{2z^2} + \sum_{t = 1}^\infty \frac{B_{2t}}{z^{2t + 1}}. }$

Here the left-hand side is equal to $\displaystyle{ \psi^{(1)}(z) }$, namely the first-order polygamma function defined by $\displaystyle{ \psi^{(1)}(z) = (d/dz)^2(\log \Gamma(z)) }$; the gamma function $\displaystyle{ \Gamma(z) }$ is equal to $\displaystyle{ (z-1)! }$ if $\displaystyle{ z }$ is a positive integer. This results in an asymptotic expansion for $\displaystyle{ \psi^{(1)}(z) }$. That expansion, in turn, serves as the starting point for one of the derivations of precise error estimates for Stirling's approximation of the factorial function.

#### Examples

If s is an integer greater than 1 we have: $\displaystyle{ \sum_{k=1}^n \frac{1}{k^s} \approx \frac 1{s-1}+\frac 12-\frac 1{(s-1)n^{s-1}}+\frac 1{2n^s}+\sum_{i=1}\frac{B_{2i}}{(2i)!}\left[\frac{(s+2i-2)!}{(s-1)!}-\frac{(s+2i-2)!}{(s-1)!n^{s+2i-1}}\right]. }$

Collecting the constants into a value of the Riemann zeta function, we can write an asymptotic expansion: $\displaystyle{ \sum_{k=1}^n \frac{1}{k^s} \sim\zeta(s)-\frac 1{(s-1)n^{s-1}}+\frac 1{2n^s}-\sum_{i=1}\frac{B_{2i}}{(2i)!}\frac{(s+2i-2)!}{(s-1)!n^{s+2i-1}}. }$

For s equal to 2 this simplifies to $\displaystyle{ \sum_{k=1}^n \frac{1}{k^2} \sim\zeta(2)-\frac 1n+\frac 1{2n^2}-\sum_{i=1}\frac{B_{2i}}{n^{2i+1}}, }$ or $\displaystyle{ \sum_{k=1}^n \frac{1}{k^2} \sim \frac{\pi^2}{6} -\frac{1}{n} +\frac{1}{2n^2} -\frac{1}{6n^3}+\frac{1}{30n^5}-\frac{1}{42n^7} + \cdots. }$

When s = 1, the corresponding technique gives an asymptotic expansion for the harmonic numbers: $\displaystyle{ \sum_{k=1}^n \frac{1}{k} \sim \gamma + \log n + \frac{1}{2n} - \sum_{k=1}^\infty \frac{B_{2k}}{2kn^{2k}}, }$ where $\displaystyle{ \gamma \approx 0.5772156649015328606065 }$ is the Euler–Mascheroni constant.

## Proofs

### Derivation by mathematical induction

We outline the argument given in Apostol.[1]

The Bernoulli polynomials Bn(x) and the periodic Bernoulli functions Pn(x) for n = 0, 1, 2, ... were introduced above.

The first several Bernoulli polynomials are \displaystyle{ \begin{align} B_0(x) &= 1, \\ B_1(x) &= x - \frac{1}{2}, \\ B_2(x) &= x^2 - x + \frac{1}{6}, \\ B_3(x) &= x^3 - \frac{3}{2}x^2 + \frac{1}{2}x, \\ B_4(x) &= x^4 - 2x^3 + x^2 - \frac{1}{30}, \\ & \vdots \end{align} }

The values Bn(0) are the Bernoulli numbers Bn. Notice that for n ≠ 1 we have $\displaystyle{ B_n = B_n(0) = B_n(1), }$ and for n = 1, $\displaystyle{ B_1 = B_1(0) = -B_1(1). }$

The functions Pn agree with the Bernoulli polynomials on the interval [0, 1] and are periodic with period 1. Furthermore, except when n = 1, they are also continuous. Thus, $\displaystyle{ P_n(0) = P_n(1) = B_n \quad (n \neq 1). }$

Let k be an integer, and consider the integral $\displaystyle{ \int_k^{k + 1} f(x)\,dx = \int_k^{k + 1} u\,dv, }$ where \displaystyle{ \begin{align} u &= f(x), \\ du &= f'(x)\,dx, \\ dv &= P_0(x)\,dx && (\text{since }P_0(x) = 1), \\ v &= P_1(x). \end{align} }

Integrating by parts, we get \displaystyle{ \begin{align} \int_k^{k + 1} f(x)\,dx &= \bigl[uv\bigr]_k^{k + 1} - \int_k^{k + 1} v\,du \\ &= \bigl[f(x)P_1(x)\bigr]_k^{k + 1} - \int_k^{k+1} f'(x)P_1(x)\,dx \\ &= B_1(1)f(k+1)-B_1(0)f(k) - \int_k^{k+1} f'(x)P_1(x)\,dx. \end{align} }

Using $\displaystyle{ B_1(0)=-1/2 }$, $\displaystyle{ B_1(1)=1/2 }$, and summing the above from k = 0 to k = n − 1, we get \displaystyle{ \begin{align} \int_0^n f(x)\, dx &= \int_0^1 f(x)\,dx + \dotsb + \int_{n-1}^n f(x)\,dx \\ &= \frac{f(0)}{2}+ f(1) + \dotsb + f(n-1) + \frac{f(n)}{2} - \int_0^n f'(x) P_1(x)\,dx. \end{align} }

Adding (f(n) − f(0))/2 to both sides and rearranging, we have $\displaystyle{ \sum_{k=1}^n f(k) = \int_0^n f(x)\,dx + \frac{f(n) - f(0)}{2} + \int_0^n f'(x) P_1(x)\,dx. }$

This is the p = 1 case of the summation formula. To continue the induction, we apply integration by parts to the error term: $\displaystyle{ \int_k^{k+1} f'(x)P_1(x)\,dx = \int_k^{k + 1} u\,dv, }$ where \displaystyle{ \begin{align} u &= f'(x), \\ du &= f''(x)\,dx, \\ dv &= P_1(x)\,dx, \\ v &= \frac{1}{2}P_2(x). \end{align} }

The result of integrating by parts is \displaystyle{ \begin{align} \bigl[uv\bigr]_k^{k + 1} - \int_k^{k + 1} v\,du &= \left[\frac{f'(x)P_2(x)}{2} \right]_k^{k+1} - \frac{1}{2}\int_k^{k+1} f''(x)P_2(x)\,dx \\ &= \frac{B_2}{2}(f'(k + 1) - f'(k)) - \frac{1}{2}\int_k^{k + 1} f''(x)P_2(x)\,dx. \end{align} }

Summing from k = 0 to k = n − 1 and substituting this for the lower order error term results in the p = 2 case of the formula, $\displaystyle{ \sum_{k=1}^n f(k) = \int_0^n f(x)\,dx + \frac{f(n) + f(0)}{2} + \frac{B_2}{2}(f'(n) - f'(0)) - \frac{1}{2}\int_0^n f''(x)P_2(x)\,dx. }$

This process can be iterated. In this way we get a proof of the Euler–Maclaurin summation formula which can be formalized by mathematical induction, in which the induction step relies on integration by parts and on identities for periodic Bernoulli functions.

## References

1. Apostol, T. M. (1 May 1999). "An Elementary View of Euler's Summation Formula". The American Mathematical Monthly (Mathematical Association of America) 106 (5): 409–418. doi:10.2307/2589145. ISSN 0002-9890.
2. Lehmer, D. H. (1940). "On the maxima and minima of Bernoulli polynomials". The American Mathematical Monthly 47 (8): 533–538. doi:10.2307/2303833.
3. Pengelley, David J. (2007). "Dances between continuous and discrete: Euler's summation formula". Euler at 300. MAA Spectrum. Washington, DC: Mathematical Association of America. pp. 169–189.
4. Devries, Paul L.; Hasbrun, Javier E. (2011). A first course in computational physics. (2nd ed.). Jones and Bartlett Publishers. p. 156.
5. Abramowitz, Milton; Stegun, Irene A., eds (1972). Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables. New York: Dover Publications. pp. 16, 806, 886. ISBN 978-0-486-61272-0.