from sympy import * x,y,s = symbols('xys') z = (1 - 2*x*x) w = (1 + 2*x*x) q = 2*x*x*2*y*y sub = {2*x*x: s} print w.subs(sub) print z.subs(sub) print q print q.subs(sub)
The output I get:
1 + s 1 - 2*x**2 4*x**2*y**2 4*x**2*y**2
开发者_如何学编程The output I expect:
1 + s 1 - s 4*x**2*y**2 2*y**2*s
Do I do something wrong?
Sympy seems to be inconsistent in what it matches. For instance, changing the sign on the matching substitution expression allows z to be matched with. I would consider adding this example to this issue. I would also try the Sympy mailing list. Remember, this project isn't even to version number 1.0 yet so things aren't going to be perfect just yet with it (or probably ever as with any software).
精彩评论