You mention AD (automatic differentiation). Have you seen this? http://www.cs.berkeley.edu/~fateman/papers/overload-AD.pdf