I tried to use the Simpson's rule to calculate the following integral
$$ \pi = 4 \int_0^1 \frac{dx}{1+x^2} .$$
The Matlab code is as follows. I expected a scaling law $error \propto h^4 $
Nlist = 2.^(2:6);
elist = 0 * Nlist;
for s1 = 1 : length(Nlist)
N = Nlist(s1);
h = 1/N;
xlist = 0 : h/2 : 1;
ylist = 1 ./ (1 + xlist.^2 );
sum1 =4*h * ( (ylist(1) + ylist(end))*(1/6)...
+ sum(ylist(2:2: end-1))*(4/6)...
+ sum(ylist(3:2 : end-2))* (2/6));
error = abs(sum1 - pi);
elist(s1) = error;
end
plot(log2(Nlist), log2(elist),'*')
xlabel('log2(N)')
ylabel('log2(error)')
Slope is about $-6$. I expected it to be $-4$. The Simpson's rule works more accurately than expected. I am totally baffled. Is it because of some hidden property of the integrant?

Let us consider the problem of computing the integral $$T = \int_a^b f(x)dx $$ using both the composite trapezoidal rule $T_h$ as well as the Simpson rule $S_h$. If $f \in C^{(2k+1)}([a,b],\mathbb{R})$ then the error satisfies an asymptotic error expansion of the form $$T - T_h = \sum_{j=1}^k \alpha_j h^{2j} + O(h^{2k+1}), \quad h \rightarrow 0, \quad h > 0.$$ The exact value of the expansion coefficients are given by $$\alpha_j = \frac{B_{2j}}{(2j)!}(f^{(2j-1)}(b) - f^{(2j-1)}(a))$$ where $B_{j}$ is the jth Bernoulli number. We need only the first few terms, namely $$B_2 = \frac{1}{6}, \quad B_4 = \frac{1}{30}, \quad B_6 = \frac{1}{42}.$$ In the present case, we have $$f(x) = (1+x^2)^{-1}.$$ It is tedious but straightforward to verify that $$\alpha_1 \not = 0, \quad \alpha_2 = 0, \quad \alpha_3 \not = 0.$$ Hence the error for the trapezoidal rule is $O(h^2)$. Simpson's rule can be obtained from the trapezoidal rule using Richardson extrapolation. Specifically, we have $$S_h = T_h + \frac{T_h - T_{2h}}{3}.$$ Richardson extrapolation eliminates the primary error term from the error expansion and exposes the next term. In this case it is $O(h^6)$ because there never was a term that was $O(h^4)$.