问题
Let's say I have the following string
str1 = "a*(-d*(b+d)+d*(e*f))"
If I sympify it the result is
a*(d*e*f - d*(b + d))
But I don't want that Sympy drop those parenthesis. I want the final expression to be
a*(d*(e*f) - d*(b + d))
How can this be done?
回答1:
That's a known bug. That same bug in the google code archive.
If you follow the google code archive link, you'll find a patch that possibly fixes your issue.
Other than that, there's not much you can do. The issue's status is still open
There's also this pull request that you might find interesting, since it presumably fixes the issue.
回答2:
Products in SymPy are automatically flattened.
You can manually avoid this with Mul(..., evaluate=False)
, like
a*(Mul(d, e*f, evaluate=False) - d*(b + d))
来源:https://stackoverflow.com/questions/48462442/how-to-avoid-sympify-to-drop-parentheses-automatically