Understanding the upper bound on the error term in the trapezium rule. 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!
 A: You have a lot of questions!
First of all: I think you did a typo:

where $E(f) \leq \dfrac{(b-a)^3}{2}\text{max}|f''|$

The correct, given the statement of Trapezoidal Rule and the context, is
$$E(f) \leq \dfrac{(b-a)^3}{12}||f''||_{\infty}$$
Where $||f||_{\infty}$ is the uniform norm of $f$ and denotes the supremum of $|f|$ for $ x \in [a,b]$.

How do you go from the first inequality to the second inequality?

Supposing you already read the proof you should know that:
$$E(f)= \dfrac{1}{2} \int_{a}^{b} f''(x)p(x) dx $$
So it is very natural that
$$E(f) \leq |E(f)| \leq  \dfrac{1}{2} \int_{a}^{b} |f''(x)p(x)| dx$$

Why is it allowed to just take $f′′$ out of the integral if you choose x such that $f′′$ is maximal?

I will try to explain it in a very informal way and as a consequence of the definition of $||f''||_\infty$:
$$| \,||f''||_{\infty}p(x) \,| \geq |f''(x)p(x)| $$ where $||f''||_{\infty}$ is a real constant and $f''(x) \in \mathbb{R} $ - notice that the statement is valid for any $x \in \mathbb{R}$. Then, you can take out the constant of the integral and get the result which you see in the proof. That is:
$$\int_{a}^{b} | \, ||f''||_{\infty}p(x) \, | dx\,\geq \int_{a}^{b} |f''(x)p(x)| dx \,\rightarrow ||f''||_{\infty} \int_{a}^{b} |p(x)|\,dx \geq \int_{a}^{b} |f''(x)p(x)|\,dx$$
The rest follows from the determination of $p(x)$.

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 $−b/2+a/2$ to $b/2−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$.

As the user New phone who this had noted that is relate to the property of even functions. And you need to notice that in the interval of integration $\dfrac{b-a}{2} \geq x$ then:
$$ \dfrac{||f''||_{\infty}}{2}\int_{-h}^{h}\left|x^2-h^2\right|dx = ||f''||_{\infty}\int_{0}^{h}\left|x^2-h^2\right|dx = ||f''||_{\infty}\int_{0}^{h} {h^2 - x^2 \, dx}$$
What's more, if you change $h ^ 2$ to $-h ^ 2$ you will have implications inside the module that should be observed.

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?

I believe that is your fault.
Read this, from here I understood your doubts and the proof
