I would use ITE for this case. It's the boolean version of Piecewise.

Aaron Meurer

On Thu, Aug 18, 2016 at 9:51 AM, Vincent Noel <labest...@gmail.com> wrote:
> Hi,
>
> I'm trying to represent a weird case using piecewise functions :
>
> z = sympy.Piecewise((True, x>0), (False, True))
>
> A piecewise function returning a boolean value... so far so good. The
> problems comes when I want to use that as a condition inside another
> Piecewise :
>
> z2 = sympy.Piecewise((1,z), (0, True), evaluate=False)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File
> "/usr/local/lib/python2.7/dist-packages/sympy/functions/elementary/piecewise.py",
> line 104, in __new__
>     " Boolean, or a built-in bool." % (cond, type(cond)))
> TypeError: Cond Piecewise((True, x > 0), (False, True)) is of type
> Piecewise, but must be a Relational, Boolean, or a built-in bool.
>
> z being obviously a boolean, is there no way for sympy to recognize that and
> accept it as a condition ?
>
> Vincent
>
> --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to sympy@googlegroups.com.
> 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/d0a66ce7-d965-4810-bb33-eca9bb2bdc54%40googlegroups.com.
> 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 sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
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%3D6%2BHVrOj%3DGe4LyOYk4JjRMoOmYHwcqU9%3Dj%3DwbAnTbyoy_w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to