I'm guessing this won't work for a lot functions, since many are not differentiable?
@intelligentDungBeetle Actually, it can work even for non-differentiable functions. Consider for instance the piecewise differentiable function $f(x) = |x|$ (absolute value). This function has a well-defined piecewise derivative (which looks like a step function). So as long as there are nodes in your tree that can encode such functions, you're in business. Lots of symbolic and autodiff systems support this kind of thing.