Solution (source code)

= Solution
{c}

Two interval Poincaré inequalities give $\|z-I_hz\|_{2,I_i}\leq h_i^2\|z''\|_{2,I_i}/\pi^2$: the error has zero endpoint values and its <derivative> has zero mean. Apply <Cauchy-Schwarz inequality> on each interval and then to the sum:
$$
\left|\int_0^1(u-u_h)\psi\right|
\leq\frac1{\pi^2}\left(\sum_i h_i^4\|R(u_h)\|_{2,I_i}^2\right)^{1/2}\|z''\|_2
\leq\frac{e+1}{\pi^2}\eta_h\|\psi\|_2.
$$
Here $\eta_h^2=\sum_i h_i^4\|R(u_h)\|_{2,I_i}^2$. Taking $\psi=u-u_h$ and cancelling its <norm>, unless it is zero already, yields
$$
\boxed{\|u-u_h\|_2\leq\frac{e+1}{\pi^2}\eta_h.}
$$
For adaptive refinement, solve the discrete problem, compute $\eta_i^2=h_i^4\|R(u_h)\|_{2,I_i}^2$, and stop when $(e+1)\eta_h/\pi^2\leq\mathrm{TOL}$. Otherwise mark intervals carrying a fixed positive fraction of $\eta_h^2$, bisect them, and repeat. Residual integration must be exact or have a certified upper bound if the stopping test is to certify the requested tolerance.

Use <residual adaptation with a uniform-refinement safeguard>, for example global bisection every second refinement, to ensure eventual termination. Discrete energy stability gives $\|u_h\|_{H^1}\leq\|f\|_2$, so $\|R(u_h)\|_2\leq(1+e)\|f\|_2$ independently of the mesh. Thus $\eta_h\leq h_{\max}^2(1+e)\|f\|_2$ tends to zero under the safeguard. Other iterations concentrate work where the residual is large.