How to Derivative of piecewise functions using SymPy

You would need to use sympy.Piecewise, as in:

diff(sympy.Piecewise((2x, (Ge(0,x) & Le(x, 10))), (3x^2, true)), x)

The regular Boolean operations in Julia eagerly evaluate, so x < 0 resolves to essentially Lt(x,0) == true rather than just Lt(x,0).

2 Likes