I am differentiating under an integral. Since the integrand does not depend explicitly on the variable, the corresponding term from the Leibniz rule would not show up. Nevertheless, sympy does not simplify it to zero. Why is that? Can it be somehow coerced to do so? That is preventing further simplification of my expressions down the road. This is my MCVE.
# Test: Check why integrating the null function does not simplify to zero
r = sym.symbols('r', real=True, positive=True)
b = sym.symbols('b', real=True, positive=True)
# Dummy integration variable
R = sym.symbols('R', real=True, positive=True)
# 1. Simple integral... simplifies ok
i1s = sym.simplify(sym.integrate(0, (R, b, r)))
print('i1s =', i1s)
# 2. Integral stemming from Leibniz rule... does not simplify
p = sym.Function('p', real=True)
i2s = sym.simplify(sym.integrate(R*p(R), (R, b, r)))
print('i2s =', i2s)
i3s = sym.simplify(sym.diff(i2s, r))
print('i3s =', i3s)
which produces
i1s = 0
i2s = Integral(R*p(R), (R, b, r))
i3s = r*p(r) + Integral(0, (R, b, r))
I would expect
i3s = r*p(r)
Note: all uses of sym.simplify
turn out to be superfluous here.
I tested this in version 1.11.1 and the 0 term was dropped. I'm not sure at what version this changed, but you should consider upgrading. For now, you can add .doit()
to the end of the i3s
line to have sympy evaluate the 0 integral.