Refine away Piecewise using assumptions.

80 views
Skip to first unread message

Björn Dahlgren

unread,
Oct 24, 2014, 10:45:17 AM10/24/14
to sy...@googlegroups.com
Consider the following short example:

http://nbviewer.ipython.org/urls/gist.githubusercontent.com/bjodah/720617780e83d7c35797/raw/c297ecf76a8e26a711b7c7868839f2dfb221bc10/gistfile1.txt

refine with Q.is_true(...) works ok for refining away Piecewise from a solution (although it's a bit picky, e.g. Eq(k**3,0) was needed instead of Eq(k, 0) for example)
It fails to refine to the default though (see last row).

I looked for Q.is_false without luck, I also looked for an Inequality class but found nothing.
I know work on new assumptions is still in the pipeline, my example is with latest sympy in conda (0.7.5), is there away in 0.7.5 or in master to do what I am looking for?

Btw. I have a hackish solution to get out only the defaults of Piecewise here is someone is interested.

Best regards,
/Björn


Aaron Meurer

unread,
Oct 24, 2014, 5:32:53 PM10/24/14
to sy...@googlegroups.com
On Fri, Oct 24, 2014 at 9:45 AM, Björn Dahlgren <bjo...@gmail.com> wrote:
> Consider the following short example:
>
> http://nbviewer.ipython.org/urls/gist.githubusercontent.com/bjodah/720617780e83d7c35797/raw/c297ecf76a8e26a711b7c7868839f2dfb221bc10/gistfile1.txt
>
> refine with Q.is_true(...) works ok for refining away Piecewise from a
> solution (although it's a bit picky, e.g. Eq(k**3,0) was needed instead of
> Eq(k, 0) for example)
> It fails to refine to the default though (see last row).
>
> I looked for Q.is_false without luck, I also looked for an Inequality class
> but found nothing.

Wouldn't that just be ~Q.is_true? It seems to work for me. The !=
class is called Unequality (to distinguish it from > "inequalities").

Aaron Meurer

> I know work on new assumptions is still in the pipeline, my example is with
> latest sympy in conda (0.7.5), is there away in 0.7.5 or in master to do
> what I am looking for?
>
> Btw. I have a hackish solution to get out only the defaults of Piecewise
> here is someone is interested.
>
> Best regards,
> /Björn
>
>
> --
> 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/2fd9a5db-8b47-4779-9be8-c50c02a431dd%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Björn Dahlgren

unread,
Oct 25, 2014, 9:51:16 AM10/25/14
to sy...@googlegroups.com

> I looked for Q.is_false without luck, I also looked for an Inequality class
> but found nothing.

Wouldn't that just be ~Q.is_true? It seems to work for me. The !=
class is called Unequality (to distinguish it from > "inequalities").


Yes, you are absolutely right - I always thought ~ was short for "not" (which didn't work),
now I know about __invert__, thanks!

Aaron Meurer

unread,
Oct 25, 2014, 1:28:12 PM10/25/14
to sy...@googlegroups.com
Python doesn't allow "not" to return a symbolic object, so we have to
use ~ (which normally means bitwise not).

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/9f210043-3ef9-4c34-bd5a-675106a369fe%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages