Simpson's rule
Simpson's rules are several ways to estimate definite integrals, which are used in numerical integration. They are named after Thomas Simpson (1710–1761).
The most basic of these rules is called Simpson's 1/3 rule, or just Simpson's rule. It estimates an integral using the function's values at the start, the middle, and the end of the range. The estimate is exact if the function is a polynomial of up to the 3rd degree.
In German and some other languages, the rule is named after Johannes Kepler, who came up with it in 1615. In German it is called the barrel rule.
Applying the 1/3 rule to several equal parts of the range gives the composite Simpson's 1/3 rule. A second rule, Simpson's 3/8 rule, also called Simpson's second rule, uses one more function value inside the range. It gives smaller error limits, but it does not make the error get smaller any faster. Its version for several equal parts is the composite Simpson's 3/8 rule. Both the 1/3 and 3/8 rules are special cases of closed Newton–Cotes formulas.
The name is also used in other fields. In naval architecture and ship stability, there is a Simpson's third rule, which is not especially important in general numerical analysis. Simpson's name is also used for a voting rule, described in Minimax Condorcet, and for rules in naval architecture, described in Simpson's rules (ship stability).
Simpson's 1/3 rule
Simpson's 1/3 rule, also simply called Simpson's rule, is a method for numerical integration. Thomas Simpson proposed it. It uses quadratic interpolation, which means it fits a curve shaped like a parabola. The rule gives exact results for any polynomial of degree three or less. It can be seen as the weighted average of the midpoint rule and the trapezoidal rule.
When a function is not smooth over the interval, the interval is split into smaller pieces. Simpson's rule is then used on each piece. This is called the composite Simpson's rule. The examples show it approximating the natural logarithm of 2 and the number π. For comparison, the Composite Trapezoidal Rule needed far more calculations to reach the same accuracy. Other methods, such as Romberg's method and the adaptive Simpson's method, build on these ideas.
Simpson's 3/8 rule
Simpson's 3/8 rule, also called Simpson's second rule, is another method for numerical integration. Thomas Simpson proposed it. It is based on a cubic curve instead of a quadratic one. It uses four evenly spaced points. Compared with the standard method, it is about twice as accurate, but it uses one more function value. There is also a composite version of the rule. A further generalization for polynomials of any degree is the Newton–Cotes formulas.
The rule can be used to estimate the arc length of a sine curve over half a period. Using six intervals, the estimate is about 3.823688376. This has a relative error of only 0.0913%. The exact value is a nonelementary integral and is about 3.820197789. This value is found using the lemniscate constant.
Alternative extended Simpson's rule
This is another way of using Simpson's rule. Instead of applying the rule to separate pieces of the area being measured, it is applied to pieces that overlap. The final result is the average of two formulas.
Simpson's rules do not work well for measuring the total area of narrow, peak-like shapes. For these, the trapezoidal rule works better. The composite Simpson's 1/3 rule needs about 1.8 times more points to reach the same accuracy. Some of these rules are linked to the Euler–MacLaurin formula, and they use the second derivative of the function.
Composite Simpson's rule for irregularly spaced data
Sometimes the interval needs to be split into parts of different sizes. This can happen when data was collected at uneven times, or when some data points are missing or damaged. If the interval is divided into an even number of smaller pieces with different widths, a version of Simpson's rule called the composite Simpson's rule is used.
If the number of pieces is odd, the same method is used up to the second-to-last piece. The last piece is handled separately, with an extra adjustment added to the result.
Algorithms
The following pseudocode shows different ways to use Simpson's rule. The first way needs an even number of intervals. The second way needs a number of intervals that is a multiple of 3. The third way works with points that are not spaced evenly. Each one gives an estimate of the integral of a function between two limits.
Numerical stability
Simpson's rule is stable when it comes to round-off error. Round-off error is the small error that builds up when numbers are rounded during calculation. All Newton–Cotes formulas share this property.
If each round-off error is smaller than a small number ε, then the total error stays below (b − a)ε. This limit does not depend on the step size h. So the method stays stable even as h gets very close to zero. This is different from numerical differentiation methods, which are harder to keep accurate.

Quiz time!
4 questions about Simpson's rule
What are Simpson's rules used for?
Pictures
Keep exploring
This article is a child-friendly adaptation of the Wikipedia article on Simpson's rule, available under CC BY-SA 4.0.
Images from Wikimedia Commons. Tap any image to view credits and license.