Skip to content
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

Piecewise float/int <= bounds #15083

Open
majidaldo opened this issue Aug 12, 2018 · 4 comments
Open

Piecewise float/int <= bounds #15083

majidaldo opened this issue Aug 12, 2018 · 4 comments
Labels

Comments

@majidaldo
Copy link

This difference doesn't make sense.
When 1 is a float

>>> x = Symbol('x')
>>>Piecewise((123, x < 1), (456, x >= 1.0))
Piecewise((123, x < 1), (456, x >= 1.0))

but if 1 is an int

>>> Piecewise( (123, x<1), (456 , x>=1) )
Piecewise((123, x < 1), (456, True))

I think there is the 'otherwise' behavior here. If I put more (exprs, conds) after the second Piecewise, they don't show up.

>>>Piecewise( (123, x<1), (456 , x>=1) , (789, x>4) )
Piecewise((123, x < 1), (456, True))

It shows up using the float(1).

>>>Piecewise( (123, x<1), (456 , x>=1.) , (789, x>4) )
Piecewise( (123, x<1), (456 , x>=1.) , (789, x>4) )
@majidaldo
Copy link
Author

..wait was i supposed to nest Piecewise?

@bjodah
Copy link
Member

bjodah commented Aug 13, 2018

Looks like there is deduction going on (assuming x is real I suppose). Is this what you're looking for?:

>>> pw = sympy.Piecewise((123, x<1), (456, x<=4), (789, 4<x))
>>> pw
Piecewise((123, x < 1), (456, x <= 4), (789, x > 4))

then using e.g. lambdify you get:

>>> l = sympy.lambdify(x, pw)
>>> l(0.5)
array(123.)
>>> l(1.5)
array(456.)
>>> l(4.5)
array(789.)

@majidaldo
Copy link
Author

why do i have to do it like that? i don't see the logical difference.

@asmeurer
Copy link
Member

I wouldn't be surprised if this boils down to #11707.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants