  If $f\!:\![a,b]\to\R$ such that $f^{(n)}$ is integrable then integration by
parts gives the formula \begin{align*} &\intab f(x)\,dx =
&\frac{(-1)^n}{n!}\sum_{k=0}^{n-1}(-1)^{n-k-1}\left[
\phi_n^{(n-k-1)}(a)f^{(k)}(a)- \phi_n^{(n-k-1)}(b)f^{(k)}(b)\right] +E_n(f),
\end{align*} where $\phi_n$ is a monic polynomial of degree $n$ and the error
is given by $E_n(f)=\frac{(-1)^n}{n!}\int_a^b f^{(n)}(x)\phi_n(x)\,dx$. This
then gives a quadrature formula for $\int_a^bf(x)\,dx$. The polynomial $\phi_n$
is chosen to optimize the error estimate under the assumption that $f^{(n)}\in
L^p([a,b])$ for some $1\leq p\leq\infty$ or if $f^{(n)}$ is integrable in the
distributional or Henstock--Kurzweil sense. Sharp error estimates are obtained.
It is shown that this formula is exact for all such $\phi_n$ if $f$ is a
polynomial of degree at most $n-1$. If $\phi_n$ is a Legendre polynomial then
the formula is exact for $f$ a polynomial of degree at most $2n-1$.
