Status: Accepted
Owner: ----
Labels: Type-Defect Priority-Medium
New issue 1400 by ondrej.certik: make cse optionally not to generate
subexpressions that are only used once
http://code.google.com/p/sympy/issues/detail?id=1400
Example:
In [1]: a1, a2, a3, a4, a5, a6 =
symbols(["a1", "a2", "a3", "a4", "a5", "a6"])
In [2]: result = sqrt((a1-a4)**2 + (a2-a5)**2 + (a3-a6)**2)
In [3]: grad = [diff(result, s) for s in (a1, a2, a3, a4, a5, a6)]
In [5]: output = [result] + grad
In [7]: cse(output)
Out[7]:
⎛⎡ ⎛ 2⎞ ⎛ 2⎞ ⎛
2⎞
⎜⎢(x₀, a₁ - a₄), (x₁, a₃ - a₆), ⎝x₂, x₁ ⎠, ⎝x₃, x₀ ⎠, (x₄, a₂ - a₅), ⎝x₅,
x₄ ⎠
⎜⎢
⎝⎣
⎛ 1 ⎞⎤ ⎡1
, (x₆, x₂ + x₃ + x₅), ⎜x₇, ──────⎟⎥, ⎢──, x₀⋅x₇, x₄⋅x₇, x₁⋅x₇, x₇⋅(a₄ -
a₁), x
⎜ ⎽⎽⎽⎽⎟⎥ ⎣x₇
⎝ ╲╱ x₆ ⎠⎦
⎤⎞
₇⋅(a₅ - a₂), x₇⋅(a₆ - a₃)⎥⎟
⎦⎟
⎠
The x2, x3 and x5 are only used once. So there should be a parameter to
cse() that would optionally make cse return something like:
(
[
(x0, a1 - a4),
(x1, a3 - a6),
(x3, a2 - a5),
(x7, (x1**2 + x3**2 + x0***2)**(-1/2))
], [
1/x7,
x0*x7,
x3*x7,
x1*x7,
x7*(a4 - a1),
x7*(a5 - a2),
x7*(a6 - a3)
]
)
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---