12. Euler-Maclaurin Formula

Hide code cell content

import mmf_setup; mmf_setup.nbinit()
import os
from pathlib import Path
FIG_DIR = Path(mmf_setup.ROOT) / '../Docs/_build/figures/'
os.makedirs(FIG_DIR, exist_ok=True)
import logging; logging.getLogger("matplotlib").setLevel(logging.CRITICAL)
%matplotlib inline
import numpy as np, matplotlib.pyplot as plt
try: from myst_nb import glue
except: glue = None

This cell adds /home/docs/checkouts/readthedocs.org/user_builds/physics-571-math-methods/checkouts/latest/src to your path, and contains some definitions for equations and some CSS for styling the notebook. If things look a bit strange, please try the following:

  • Choose "Trust Notebook" from the "File" menu.
  • Re-execute this cell.
  • Reload the notebook.

12. Euler-Maclaurin Formula#

The Euler-Maclaurin Formula is the exact error \(\epsilon\) when computing a definite integral with the trapezoidal rule:

\[\begin{gather*} \int_{a}^{b}f(x)\d{x} = h\left( \frac{1}{2}f(a) + f(a+h) +\dots + f(b-h) + \frac{1}{2}f(b) \right) + \epsilon, \\ h = \frac{b-a}{N}. \end{gather*}\]

To derive the formula, we use property that the derivative \(\op{D} = \partial_x\) generates translations

\[\begin{gather*} \op{D}f(x) = f'(x), \qquad e^{h\op{D}} f(x) = f(x + h). \end{gather*}\]

This just follows from Taylor expanding the exponential. For the purposes of this discussion, consider

\[\begin{gather*} \op{E} = e^{h\op{D}} = \op{1} + h\op{D} + \frac{h^2}{2!}\op{D}^2 + \cdots, \qquad \op{E}^{n}f(a) = f(a+hn). \end{gather*}\]

If we let \(\op{D}F(x) = f(x)\) we can express the exact answer

\[\begin{gather*} \int_{a}^{b}f(x)\d{x} = F(b)-F(a) = F(a+hN) - F(a) = (\op{E}^N - 1)F(a)\\ = \frac{\op{E}^N - 1}{\op{D}}f(a), \end{gather*}\]

The error can thus be expressed:

\[\begin{gather*} \epsilon = -\left.\sum_{n=2}^{\infty}\frac{B_n h^{n}f^{(n-1)}(x)}{n!}\right|^{b}_{a} = h^{2}\frac{f'(a)-f'(b)}{12} - \left.\sum_{n=4}^{\infty}\frac{B_n h^{n}f^{(n-1)}(x)}{n!}\right|^{b}_{a}\\ \end{gather*}\]

[Arfken et al., 2013] derives the same result using integration by parts and the property \(B_n'(x) = nB'_{n-1}(x)\) of the Bernoulli polynomials.

This can be rearranged as (see [Graham et al., 1994] Eq. (9.67))

\[\begin{gather*} \sum_{a\leq n < b} f(n) = \int_{a}^{b}f(x)\d{x} + \left.\sum_{n=1}^{m}\frac{B_{n}}{n!}f^{(n-1)}(x)\right|^{b}_{a} + R_{m}\\ R_m = (-1)^{m+1}\int_a^{b}\frac{B_m(\{x\})}{m!}f^{(m)}(x)\d{x} \end{gather*}\]

where \(a\), \(b\), and \(m\) are integers, \(a\leq b\), and \(1\leq m\). Here \(\{x\}\) means the fractional part of \(x\). I.e. \(\{\pi\} = .14159\cdots\). This gives an explicit formula for the remainder and an explicit way to correct the approximation.

The remainder term (courtesy of S.D. Poisson – see [Graham et al., 1994]) is important, because the sum \(\sum_{n\geq 1} (B_n/n!)f^{(n-1)}(x)|^{b}_{a}\) can diverge (it is often an asymptotic series). Nevertheless, despite diverging, asymptotic series sometimes provide spectacular approximations, and often, using a few terms can greatly improve one’s approximation of the series as we shall now discuss in 12. Asymptotic Series.