I want to compute the higher derivatives of f1(x) = exp(im * 2π * x) / (im * x). For example 8th derivative, ı used nth_derivative function with ForwardDiff, but 8th derivatives gives NAN. I changed the function as f2(x) = exp(im * 2π * x) * (im * x)^(-1). f2 function given NAN if I choose x=1/1000. I changed the function as f3(x) = -im * exp(im * 2π * x) * x^(-1), it is calculated. But the nth_derivative so slow.

I don’t understand the effect of the functions and how can I compute fast the nth derivative of exp(im * 2π * x) / (im * x) ?

using ForwardDiff
function nth_derivative(f, x, n)
if n == 0
return f(x)
else
return ForwardDiff.derivative(x -> nth_derivative(f, x, n - 1), x)
end
end
f3(x) = -im * exp(im * 2π * x) * x^(-1)
nth_derivative(f3, 1/1000, 8)