JuliaDiff / TaylorDiff.jl

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

How to get first n derivatives all at once efficiently? #74

Closed orebas closed 5 months ago

orebas commented 5 months ago

Feature request: Based on the package design, it seems like it is probably possible to calculate the first n derivatives of a function at once (with one call).

Right now to get that out probably requires using internal details. It would be nice to have an API to return the value and the first n derivatives at once (in a tuple or vector). It would also be nice to have an example in the docs.

tansongchen commented 5 months ago

Yes, that is definitely helpful. Right now, interfaces are like

@inline function derivative(f, x, l, vN::Val{N}) where {N}
    t = make_taylor(x, l, vN)
    return extract_derivative(f(t), N)
end

where make_taylor construct the seeds, f(t) get all derivative from order 0 ~ N, and extract_derivative extract the N-th order. Did you mean returning f(t), which is a Taylor polynomial or array of polynomials, directly?

tansongchen commented 5 months ago

ok so this is a quick fix: https://github.com/JuliaDiff/TaylorDiff.jl/commit/3770f8b582432836881ed1da630cdf02b3143856

Now you can use the derivatives API to get all derivatives