Linking related thread that seems to address the differentiable part.
As for the vectorization, f.(x) should work above?
f.(x)