SymPy substition with scalars doesn't work?
-
09-10-2019 - |
Question
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?
Solution
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).
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow