-
-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SymPy inserts Piecewise by default #1138
Comments
As in many other cases, the problem is that Sympy and WMA have different ideas about what is the standard form of a mathematical expression. One way to avoid these incompatibilities would be to write specific rules (in WL) to deal with the specific cases, like the one in the example.
Notice that WMA is able to evaluate the sum as a function of
but it doesn't it inside |
Is your feature request related to a problem? Please describe.
Not sure if this is a bug so much as a difference in default behaviour between SymPy and WMA. WMA tends to be a bit looser in making simplifying assumptions, whereas SymPy tries to enumerate all the possible cases. For example, for the expression:
WMA gives:
Whereas Mathics gives:
which causes some issues if e.g. you're trying to extract coefficients from the polynomial.
Note
In this case, the
Piecewise
aren't actually needed, and are just a remnant of the fact that the intermediate expressionevaluates to (note the singularity at$x=1$ )
So in this particular case
Simplify
will remove them, but in general SymPy does put them there for good reason.Describe the solution you'd like
For compatibility with WMA, stripping the
Piecewise
fromSum
et al by default. The easiest way to do that is to applyto the intermediate SymPy results, though it's perhaps worth doing something a little more intelligent than that. I had a look to see if SymPy has any existing hinting for avoiding generating them in the first place but couldn't find any.
However, the behaviour of SymPy here is quite useful when you care about making sure the results are defined everywhere, so it's good to keep it as an option. As far as I know the closest analogy in WMA is
GenerateConditions
, though it doesn't quite work the same - according to the docs, setting it toAll
is supposed to have the same behaviour as SymPy here, but it doesn't in my tests, and setting it toTrue
yieldswhich isn't quite the same.
Not sure if there's a better solution to align the behaviours of the two?
Describe alternatives you've considered
A possible workaround would be to implement
PiecewiseExpand
(I think the SymPy equivalent would bepiecewise_fold
), to at least allow thePiecewise
expressions to be combined. But it's not exactly a full solution as it still results in existing WMA code that doesn't require that being broken.The text was updated successfully, but these errors were encountered: