#include <iostream>
#include <math.h>

using namespace std;

double derivative(double (*f)(double), double x, double epsilon) {
    return (f(x + epsilon) - f(x)) / epsilon;
}

bool test_interval(double epsilon, double precision) {
    for (double x = 0; x <= 3.14; x += 0.0001) {
        double approx = derivative(sin, x, epsilon);
        double precise = cos(x);
        if (abs(approx - precise) > precision) {
            return false;
        }
    }
    return true;
}

int main() {
    for (double e = 0.003; e > 0.001; e -= 0.000001) {
        if (test_interval(e, 0.001)) {
            cout << "Epsilon found: " << e << endl;
            break;
        }
    }
    double max_diff;
    double max_x;
    for (double x = 0; x <= 3.14; x += 0.0001) {
        double diff = abs(derivative(sin, x, 0.002) - cos(x));
        if (diff > max_diff) {
            max_diff = diff;
            max_x = x;
        }
    }
    cout << "Max diff at " << max_x << " of " << max_diff << endl;
    return 0;
}
