I don't know if any code will break with it, but I think it's better for Piecewise to only deal with expressions. For booleans, you can get the equivalent of a Piecewise using logic classes like And, Or, Not, or even more advanced things like ITE (ITE means "if-then-else"). Piecewise on booleans is basically and ITE chain; it's the "some kind of PicewiseBoolean" that the author of that comment is looking for.
An advantage is that since the expressions themselves are booleans, it is sometimes possible to rearrange and simplify them with the conditions. As a simple example, consider Piecewise((sin(x) > 0, x > 0), (x > 0, True)). This is the same as ITE(x > 0, sin(x) > 0, x > 0), which simplifies: >>> simplify_logic(ITE(x > 0, sin(x) > 0, x > 0)) (x > 0) & (sin(x) > 0) which makes sense if you think about it: logically, x > 0 has to be true, meaning so does sin(x) > 0. Also, having a Piecewise as a condition is very confusing when printed. Aaron Meurer On Thu, May 4, 2017 at 11:12 AM, Chris Smith <[email protected]> wrote: > The following note appears in piecewise_fold and I can't see the reason > for not returning the expression that it tries to avoid. Can anyone > enlighten me? > > # If expr is Boolean, we must return some kind of PiecewiseBoolean. > # This is constructed by means of Or, And and Not. > # piecewise_fold(0 < Piecewise( (sin(x), x<0), (cos(x), True))) > # can't return Piecewise((0 < sin(x), x < 0), (0 < cos(x), True)) > <---- what's wrong with this? > # but instead Or(And(x < 0, 0 < sin(x)), And(0 < cos(x), Not(x<0))) > > /c > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/sympy. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/sympy/547f0eca-5030-41ee-9eea-978079c1af0f%40googlegroups.com > <https://groups.google.com/d/msgid/sympy/547f0eca-5030-41ee-9eea-978079c1af0f%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6KSprd5%2B9p6qOuhDtczYn7NW5YfNxXxtMq6OxsBQBs6Gg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
