python - Differentiation, .diff() doesn't give expected output -


i writing bit of code, problem found here:

[in>] sympy import*  [in>] t= symbol('t')       x1 = function('x1')(t)       x2 = function('x2')(t)       y1 = function('y1')(t)       y2 = function('y2')(t) 

i define expression:

[in>] f = (x1.diff(t)*y2.diff(t)- x2.diff(t)*y1.diff(t)) 

then, when differentiating expresion f wrt. factors of first summand unexpected output:

[in>] f.diff(y2.diff(t))  [out>] subs(derivative(x1(t), t), (_xi_2,), (derivative(y2(t), t),)) 

but if differentiate wrt. second summand factors

[in>] f.diff(y1.diff(t))  [out>] -derivative(x2(t), t) 

i desired , expected result. i'm totally baffled this. still more, if change order of summands, same result:

[in>] (-x2.diff(t)*y1.diff(t)+x1.diff(t)*y2.diff(t) ).diff(y2.diff(t))  [out>] subs(derivative(x1(t), t), (_xi_2,), (derivative(y2(t), t),))  [in>] (-x2.diff(t)*y1.diff(t)+x1.diff(t)*y2.diff(t) ).diff(y1.diff(t))  [out>] -derivative(x2(t), t) 

but if exchange minus `-``sign, propeblem in other pair of functions:

[in>] (+x2.diff(t)*y1.diff(t)-x1.diff(t)*y2.diff(t) ).diff(y1.diff(t))  [out>] subs(derivative(x2(t), t), (_xi_2,), (derivative(y1(t), t),)) 

ok, desired result had ad .doit(), returning subs() function.

(+x2.diff(t)*y1.diff(t)-x1.diff(t)*y2.diff(t) ).diff(y1.diff(t)).doit()  derivative(x2(t), t) 

Comments