piecewise_fold of nested piecewise expressions; bug?

55 views
Skip to first unread message

clayto...@gmail.com

unread,
Mar 9, 2015, 10:20:04 AM3/9/15
to sy...@googlegroups.com
Hello,

From the sympy master, I have tried to simplify a piecewise expression which contains piecewise arguments:

from sympy import Piecewise, Eq, piecewise_fold
from sympy.abc import x, y

p
= Piecewise((Piecewise((5, Eq(y, 0)), (2, True)), Eq(x, 0)), (Piecewise((1, Eq(y, 0)), (6, True)), True))
print(piecewise_fold(p))

I would expect that the result has only one "Piecewise" in it, something like:

Piecewise((5, And(Eq(y, 0), Eq(x,0))), (2, And(True, Eq(x, 0))), (1, And(Eq(y, 0), True)), (6, And(True, True))) # Expected result.

or, if simplified,

Piecewise((5, And(Eq(y, 0), Eq(x,0))), (2, Eq(x, 0)), (1, Eq(y, 0)), (6, True)) # Expected result.

But instead, the different piecewise subexpressions are not folded together.  Is this a bug, an unimplemented feature, or have I misunderstood the purpose of piecewise_fold?

Thanks,
Clayton

PS.  This testcase arose from a multiple integration which was not fully simplified -- so although it looks artificial, something equivalent did arise in actual usage.

Aaron Meurer

unread,
Mar 9, 2015, 8:03:11 PM3/9/15
to sy...@googlegroups.com
It's probably an unimplemented feature. There are a lot of things that
piecewise_fold can't handle which it could.

Aaron Meurer
> --
> 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 sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/b98bbb19-b770-49e9-8674-cd394d3447a7%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

clayto...@gmail.com

unread,
Mar 10, 2015, 3:58:43 PM3/10/15
to sy...@googlegroups.com
OK Aaron -- thanks for your reply.  I'll see if I can generate a patch...
Reply all
Reply to author
Forward
0 new messages