Boole's rule

In mathematics, Boole's rule, named after George Boole, is a method of numerical integration.

Simple Boole's Rule
It approximates an integral: $$ \int_{a}^{b} f(x)\,dx $$ by using the values of $f$ at five equally spaced points: $$\begin{align} & x_0 = a\\ & x_1 = x_0 + h \\ & x_2 = x_0 + 2h \\ & x_3 = x_0 + 3h \\ & x_4 = x_0 + 4h = b \end{align}$$

It is expressed thus in Abramowitz and Stegun: $$ \int_{x_0}^{x_4} f(x)\,dx = \frac{2 h}{45}\bigl[ 7f(x_0) + 32 f(x_1) + 12 f(x_2) + 32 f(x_3) + 7f(x_4) \bigr] + \text{error term}$$ where the error term is $$ -\,\frac{8f^{(6)}(\xi)h^7}{945} $$ for some number $\xi$ between $x_0$ and $x_4$ where 945 = 1 × 3 × 5 × 7 × 9.

It is often known as Bode's rule, due to a typographical error that propagated from Abramowitz and Stegun.

The following constitutes a very simple implementation of the method in Common Lisp which ignores the error term:

Composite Boole's Rule
In cases where the integration is permitted to extend over equidistant sections of the interval $$[a, b]$$, the composite Boole's rule might be applied. Given $$N$$ divisions, where $$N$$ mod $$4 = 0$$, the integrated value amounts to:

$$ \int_{x_0}^{x_N} f(x)\,dx = \frac{2 h}{45} \left(        7(f(x_0) + f(x_N))      + 32\left(\sum_{i \in \{1, 3,  5, \ldots, N-1\}} f(x_i)\right)      + 12\left(\sum_{i \in \{2, 6, 10, \ldots, N-2\}} f(x_i)\right)      + 14\left(\sum_{i \in \{4, 8, 12, \ldots, N-4\}} f(x_i)\right)    \right) + \text{error term} $$

where the error term is similar to above. The following Common Lisp code implements the aforementioned formula: