Maybe it's possible by specifying a `derivative_func` in the definition of `g`, returning another [symbolic function](https://doc.sagemath.org/html/en/reference/calculus/sage/symbolic/function_factory.html#sage.symbolic.function_factory.function) with a custom `eval_func`, but even if it worked (I didn't manage) it would be very awkward and convoluted to define. I think it's better to be explicit about such substitutions anyway.
↧