Integration formula for cubic polynomial $\int_a^bq(x)dx=\frac{b-a}{2}(q(b)+q(a))-\frac{(b-a)^2}{12}(q'(b)-q'(a))$ Show that $\forall a,b\in \mathbb{R}$, with $a<b$, we have$$\int \limits _a^bq(x)\,dx=\frac{b-a}{2}(q(b)+q(a))-\frac{(b-a)^2}{12}(q'(b)-q'(a)),$$ where $q\in \mathcal{P}_3$ is a cubic polynomial.
I've tried doing integration by parts with $1$ and $q(x)$. But that just gives $b-a$ instead of $\dfrac{b-a}{2}$.
 A: For the cubic polynomial $q(x)$, we have  $q'''(a)= q'''(b)= q’’’$ and
\begin{align}
&q'(a)-\ q'(b)=q''(b)(a-b)+\frac12 q'''(a-b)^2\\
&q'(b)-\ q'(a)=q''(a)(b-a)+\frac12 q'''(b-a)^2\\
\end{align}
which result in $q''(b)+q''(a)=\frac{2(q'(b)-q'(a))}{b-a}$. Integrate the following integral by parts twice
\begin{align}
&\int_a^b\left(x-\frac{a+b}{2}\right)q'(x)dx \\
=& \int_a^b \frac{q'(x)}2d[(x-\frac{a+b}{2})^2]
= \frac{(b-a)^2}8(q'(b)-q'(a))
 - \int_a^b \frac{q''(x)}6d[(x-\frac{a+b}{2})^3]\\
= &\ \frac{(b-a)^2}8(q'(b)-q'(a))
- \frac{(b-a)^3}{48}(q''(b)+q''(a))=\frac{(b-a)^2}{12}(q'(b)-q'(a))\tag1 \\
\end{align}
On the other hand, an alternative integration by parts yields the following
$$\int_a^b\left(x-\frac{a+b}{2}\right)q'(x)dx =\frac{b-a}2(q(b)+q(a))-\int_a^b q(x)dx\tag2
$$
Combine (1) and (2) to obtain
$$\int_a^b q(x)dx = \frac{b-a}{2}(q(b)+q(a)) - \frac{(b-a)^2}{12}(q'(b) - q'(a))$$
A: HINT:
Let $\phi(t) = q (a + t(b-a))$. Show that
$$\int_0^1 \phi(t) \, dt = \frac{1}{2}( \phi(0) + \phi(1)) - \frac{1}{12}(\phi'(1) - \phi'(0))$$
for $\phi$ ( $q$) polynomial of degree $\le 3$. This is the Euler-Maclaurin formula of order $3$.
$\bf{Added:}$ Proof of the above formula.
Consider $\psi(t)$ any function $C^4$ we have
$$\left(\psi^{(3)}(t) \phi(t) - \psi^{(2)}(t) \phi'(t) + \psi'(t) \phi^{(2)}(t) - \psi(t)\phi^{(3)}(t)\right)' = \\=\psi^{(4)}(t) \phi(t) - \psi(t) \phi^{(4)}(t)$$
Therefore
$$\int_0^1 \psi^{(4)}(t) \phi(t)\, dt = \int_0^1 \psi(t) \phi^{(4)}(t)\, dt + \\
+\left(\psi^{(3)}(t) \phi(t) - \psi^{(2)}(t) \phi'(t) + \psi'(t) \phi^{(2)}(t) - \psi(t)\phi^{(3)}(t)\right)\mid_0^1 $$
Take now in the formula above
$$\psi(t) = \frac{1}{4!} (B_4(t)- B_4(0)) = \frac{1}{24}( t^4 - 2 t^3 + t^2)$$
where $B_n(t)$ is the Bernoulli polynomial of index $n$.
We have
$$\psi^{(4)}(t)\equiv 1\\ 
\psi^{(3)}(1) = -\psi^{(3)}(0) =\frac{1}{2}\\
\psi^{(2)}(1) = \psi^{(2)}(0) = \frac{1}{12}\\
\psi'(1) = \psi'(0) = 0 \\
\psi(1) = \psi(0) = 0$$
We conclude
$$\int_0^1\phi(t)\, dt = \frac{1}{2}( \phi(0) + \phi(1)) - \frac{1}{12} (\phi'(1)- \phi'(0)) +\\ + \frac{1}{24}\int_0^1 \phi^{(4)}(t)\, t^2(1-t)^2 \,dt$$
$\bf{Added:}$ We can show the formula above considering $\phi(t)= t^n$. Assuming $n>0$ we get LHS $= \frac{1}{n+1}$ while RHS $=$
$$\frac{1}{2} -\frac{n}{12} + \frac{(n-3)(n-2)}{12 (n+1)}= \frac{6 (n+1) -n(n+1) +(n-3)(n-2)}{12(n+1)}=\frac{1}{n+1}$$
