I am trying to find the first and second-order partial derivatives of a function of four variables $S$ using pythons symbolic math package sympy.
The issue is that sympy does not automatically see that certain pairs of partial derivatives, when evaluated at the same arguments, are in fact equal, and so cancellations do not occur. For example: $$\frac{\partial S(x,y,u,v)}{\partial x}=\frac{\partial S(u,v,x,y)}{\partial u} \text{ when } x=u \text{ and } y=u.$$ You can see that in each case the functions are differentiated w.r.t their first arguments (x, u respectively) and that afterwards each partial derivative is evaluated at (x,y,x,y).
However, the code below returns False
:
sympy.diff(S(x, y, u, v), x).subs({u: x, v: y}) == sympy.diff(S(u, v, x, y), u).subs({u: x, v: y})
Any help is appreciated!