Updates:
Status: Accepted
Labels: WrongResult
Comment #1 on issue 2617 by asmeurer: cse not working correctly with powers
http://code.google.com/p/sympy/issues/detail?id=2617
Here's the output of that:
sympy version: 0.7.0-git
equation: (x1**2/z**2 + z**(-2))/z
cse: [(a0, z**(-2))], formula: [a0**(1/2)*(a0*x1**2 + a0)]
substitution in original: -2
substitution in cse expression: 2
Here's the basic problem:
In [7]: v2[0].subs(v1)
Out[7]:
⎛ 2 ⎞
⎜x₁ 1 ⎟
-⎜─── + ──⎟
⎜ 2 2⎟
⎝ z z ⎠
───────────
z
In [8]: eq
Out[8]:
2
x₁ 1
─── + ──
2 2
z z
────────
z
The problem is that because z is defined to be negative, it pulls out a
-1. If z is vanilla, you get
In [11]: z = Symbol('z')
In [12]: eq=(x1**2/z**2+1/z**2)/z
In [13]: v1,v2=cse(eq, sympy.numbered_symbols('a'))
In [14]: v2[0].subs(v1)
Out[14]:
⎛ 2 ⎞ ⎽⎽⎽⎽
⎜x₁ 1 ⎟ ╱ 1
⎜─── + ──⎟⋅ ╱ ──
⎜ 2 2⎟ ╱ 2
⎝ z z ⎠ ╲╱ z
In [15]: eq
Out[15]:
2
x₁ 1
─── + ──
2 2
z z
────────
z
So cse() needs to be smarter about powers. Actually, the best way to fix
this would be to make cse() just use subs, and improve subs() to be smart
enough to handle everything that it does, but this is no easy task.
--
You received this message because you are subscribed to the Google Groups
"sympy-issues" group.
To post to this group, send email to sympy-issues@googlegroups.com.
To unsubscribe from this group, send email to
sympy-issues+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/sympy-issues?hl=en.