Using ForwardDiff for Symbolic.derivative() definition

i think you need to generate a wrapper function around the ForwardDiff.derivative function and use that instead:

AD_derivative(f,x) = ForwardDiff.derivative(f,x)
foo_f3(x) = x^2
@register_symbolic AD_derivative(f::Function,x)
@register_symbolic foo_3(x)
Symbolics.derivative(::typeof(foo_f3), args::NTuple{1,Any}, ::Val{1})  = AD_derivative(foo_x3,args[1])

you want to stop the tracing the original function and the derivative.

1 Like