Версия Python: 3.10.9
Версия Sympy: 1.11.1.
Вот MWE.
Код: Выделить всё
import sympy as sp
from sympy import Piecewise, Eq, cos, sin, Ne
j = sp.symbols('j', real=True)
function = Piecewise((0, Eq(j, 0)), (-Piecewise((0, Ne(j, 0)), (2, True)), True)) - Piecewise((0, Eq(j, 0)), (-Piecewise((1, Ne(j, 0)), (0, True)), True))
function_simple = sp.simplify(function)
print(function.subs({j:1})) #prints 1
print(function_simple.subs({j:1})) #prints -1
Подробнее здесь: https://stackoverflow.com/questions/790 ... -functions