I tried your code and it seems to work. However, when I make a and b closer and closer to each other, say a = x - 1e-15 and b = x + 1e-15, the function does not converge to the actual derivative as expected. Why is this happening?