# Educational example from Sarovi journal. Python 3; no extra dependencies.
def f(x):
    return x * x

def derivative(f, x, h=1e-3):
    return (f(x + h) - f(x - h)) / (2 * h)

for h in [1e-1, 1e-3, 1e-6]:
    print(h, derivative(f, 3, h))

assert abs(derivative(f, 3) - 6) < 1e-8
