using SymPy
@sysm x y
f(x,y) = sin(y-x)
df = sympy.diff(f(x,y),x) # it outputs `- cos(x-y)`: correct
df(PI/2,y) # it output `-sin(y)`: correct
df(x,PI/2) # it outputs `-1`: wrong; expected to be `-sin(x)`
I also tried the same code above in Julia running from cmd (in Windows), the output of the code is correct as expected.
Please show me the way I could run my code in VS Code to have correct answers.
On the substitution operation, the behavior still seems strange
using SymPy
@syms x y
f(x,y) = sin(y-x)
df = sympy.diff(f(x,y),x)
df(x=>PI/2,y=>y) # OK
df(x=>PI/2,y=>x) # it results to `-sin(x)`, meaning that it does not substitute `x=>PI/2` in the result `-sin(x)`, it does not use the fact `y=x` neither (because I substitute `y` by `x`).
But if I tried
df(y=>x,x=>PI/2)
Then it seems to evaluate -cos(x-x) to have -1 using the fact y=x. The cause is due to the dependence on the sequence, I think.
How can we just substitute the arguments separately before evaluating the formula (i.e., in -cos(x-y), the first argument x is changed to PI/2, the second argument y is changed to x, and now we have -cos(PI/2-x) which is then simplified to -sin(x).
Yes, the arguments are processed one by one, so that behaviour is expected. You are free to do df(x => Pi/2)(y=>x) to stage the substitutions a different way.