If I do
import sympy
k, V, Vprime = sympy.symbols('k, V, Vprime')
print sympy.diff(k + V(t), t)
I get Derivative(V(t), t)
as I expect - the derivative distributes and the constant term has zero derivative.
However, if I construct an equivalent expression via substitution, simplify
does not distribute the derivative. How can I get the same result via substitution as when I evaluate the expression directly?
sympy.diff(Vprime(t)).subs({Vprime(t): k + V(t)}).simplify()
returns Derivative(k + V(t), t)
.
The solution to this problem is provided by the doit method, which says it "Evaluate(s) objects that are not evaluated by default like limits, integrals, sums and products.":
sympy.diff(Vprime(t)).subs({Vprime(t): k + V(t)}).doit()
yields
Derivative(V(t), t)