Comment #3 on issue 1400 by [email protected]: make cse optionally not to
generate subexpressions that are only used once
http://code.google.com/p/sympy/issues/detail?id=1400
There is no option for this, but the recent commit now gives:
h[1] >>> a1, a2, a3, a4, a5, a6 =
symbols(["a1", "a2", "a3", "a4", "a5", "a6"])
h[1] >>> result = sqrt((a1-a4)**2 + (a2-a5)**2 + (a3-a6)**2)
h[1] >>> grad = [diff(result, s) for s in (a1, a2, a3, a4, a5, a6)]
h[1] >>> output = [result] + grad
h[1] >>> cse(output)
([(x0, a1 - a4), (x1, a2 - a5), (x2, a3 - a6), (x3, x0**2 + x1**2 +
x2**2), (x4,
x3**(-1/2))], [1/x4, x0*x4, x1*x4, x2*x4, x4*(a4 - a1), x4*(a5 - a2),
x4*(a6 -
a3)])
h[2] >>> s,r=_
h[2] >>> for si in s:
... print si
...
(x0, a1 - a4)
(x1, a2 - a5)
(x2, a3 - a6)
(x3, x0**2 + x1**2 + x2**2)
(x4, x3**(-1/2))
h[2] >>> for ri in r:
... print ri
...
1/x4
x0*x4
x1*x4
x2*x4
x4*(a4 - a1)
x4*(a5 - a2)
x4*(a6 - a3)
If this is acceptable, please mark this as Fixed.
--
You received this message because you are subscribed to the Google Groups
"sympy-issues" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy-issues?hl=en.