JuliaDiff / TaylorDiff.jl

Taylor-mode automatic differentiation for higher-order derivatives
https://juliadiff.org/TaylorDiff.jl/
MIT License
73 stars 8 forks source link

Odd behavior for for simple user defined functions #68

Closed CaptainKubi closed 4 months ago

CaptainKubi commented 10 months ago

The derivative function behaves really odd for simple user defined function. If I define two simple functions as follows

julia> f(x) = x*x
julia> h(x) = x^2

then the first order derivatives a 0.0 only gives the correct result for f(x).

julia> derivative(f, 0.0, 1)
0.0
julia> derivative(h, 0.0, 1)
NaN

Oddly, if the derivative is evaluated at 1.0 both functions work as expected.

julia> derivative(f, 1.0, 1)
2.0
julia> derivative(h, 1.0,1)
2.0

I tested this on v0.2.1.

I was hoping to use TaylorDiff to calculate higher order derivatives for Sellmeier Equations. But it also seems to fail for these in a not easy to understand way.

CaptainKubi commented 10 months ago

This apparantly was already addressed in #33. However it seems it is not part of the currently available latest version.

lrnv commented 7 months ago

Also this one: https://github.com/JuliaDiff/TaylorDiff.jl/issues/61

tansongchen commented 4 months ago

0.2.2 contains the fix and would be good for these functions