For $f$ twice continuously differentiable, we have$$\displaystyle\int_a^bf(x)dx = \dfrac{1}{2}(b-a)[f(a) + f(b)] + E(f)$$ where $E(f) \leq \dfrac{(b-a)^3}{2}\text{max}|f''|$. I'm reading the proof of this equation here (Trapezoid rule), and I don't understand how the upper bound of the error term is derived.
The proof is as follows:
Let $p(x) = \bigg(x - \dfrac{a+b}{2}\bigg)^2 - \dfrac{(b-a)^2}{4}$, we have $$\begin{split}E(f)&\leq \displaystyle\dfrac{1}{2}\int_a^b\left|f''(x)p(x)\right|dx\\&\leq\dfrac{\max\left|f''\right|}{2}\int_a^b\left|\bigg(x - \dfrac{a+b}{2}\bigg)^2 - \dfrac{(b-a)^2}{2}\right|dx\\&=\dfrac{\max\left| f''\right|}{2}\int_{-h}^h\left|x^2-h^2\right|dx\\&=\max\left|f''\right|\int_0^h(h^2 - x^2)dx\\&=\dfrac{\max\left|f''\right|2h^3}{3}\\&=\dfrac{(b-a)^3 \max\left|f''\right|}{12}\end{split}$$
Question: How do you go from the first inequality to the second inequality? Why is it allowed to just take $f''$ out of the integral if you choose $x$ such that $f''$ is maximal? Furthermore, what is happening with the substitution from the second inequality to the third? If I replace $-h^2$ and $h^2$ in the integral I get an integral from $-\dfrac{b}{2} + \dfrac{a}{2}$ to $\dfrac{b}{2} - \dfrac{a}{2}$. Likewise, I don't understand how interchanging $x^2$ and $h^2$ and removing the absolute value signs allows us to take the integral from $0$ to $h^2$ instead from $-h^2$ to $h^2$. Lastly, if I calculate the integral from the fourth to fifth equality, I get a minus sign. Is this my fault or is this an error in the proof?
Thanks!