> this seems like a perfect fit for automatic differentiation.
Why?
Why?
I've never worked this through to a full conclusion, but you could even write it in a way that would let you get symbolic differentiation out of it too.
See https://sritchie.github.io/emmy/src/emmy/differential.html for detail!