// E03: central second difference of f(x)=x^4, exact f''(1)=12.
#include <cmath>
#include <iomanip>
#include <iostream>
static double f(double x) { return x*x*x*x; }
int main() {
    double previous=0;
    std::cout << std::setprecision(12);
    for (double h : {0.5,0.25,0.125}) {
        const double approximation=(f(1+h)-2*f(1)+f(1-h))/(h*h);
        const double error=std::abs(approximation-12.0);
        const double expected=2*h*h;
        if (std::abs(error-expected)>1e-11) return 1;
        std::cout << "h=" << h << " approx=" << approximation << " error=" << error;
        if (previous>0) {
            const double ratio=previous/error;
            std::cout << " ratio=" << ratio;
            if (std::abs(ratio-4)>1e-10) return 2;
        }
        std::cout << '\n';
        previous=error;
    }
    std::cout << "PASS E03\n";
}
