Comment #1 on issue 1950 by andy.ter...@gmail.com: Piecewise((x, 0 < x), (0, Eq(x, 0)), (-x, x < 0))._eval_interval(x, -1, 1) is wrong
http://code.google.com/p/sympy/issues/detail?id=1950

Hmm, I'll take a closer look.

The code is complicated because function is dependent on which intervals are used, if just the end points are used then the middle intervals may not be considered.

For example:

p1 = Piecewise((3*x, x < 0), (2*x, x < 1), (x, x >= 1))
p1.eval(x, -2, 2)
should translate to:

(3*x)._eval_interval(x,-2, 0) + (2*x)._eval_interval(x, 0, 1) + x._eval_interval(x, 1, 2)
9

whereas p1.subs(x, 2) - p1.subs(x, -2) translates to
x.subs(x,2) - (3*x).subs(-2)
8


The bug in the above code is with the handling of the Eq(x, 0) condition, without it things work as expected:

Piecewise((x, 0 < x), (-x, x < 0))._eval_interval(x, -1, 1)
0

but there are funky cases as always with math, take for example:

Piecewise((x, 0 < x), (oo, Eq(x, 0)), (-x, x < 0))._eval_interval(x, -1, 1)
nan

but should be 1


--
You received this message because you are subscribed to the Google Groups 
"sympy-issues" group.
To post to this group, send email to sympy-issues@googlegroups.com.
To unsubscribe from this group, send email to 
sympy-issues+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy-issues?hl=en.

Reply via email to