Status: New
Owner: ----
Labels: Type-Defect Priority-Medium
New issue 2961 by waks...@gwax.com: __nonzero__ method of Rel breaks solve
of Piecewise functions
http://code.google.com/p/sympy/issues/detail?id=2961
sympy/solvers/solvers.py line 1257 checks the condition associated with a
particular piece by calling bool(); since bool() bases its answer on the
__nonzero__ method of core.relational.Relational subclasses, the results
are not mathematically correct
consider, as an example solving |x-3| = y for x
x, y = symbols('x y')
absxm3 = Piecewise( (x-3, 0 <= x-3), (-(x-3), 0 > x-3) )
# absxm3 == |x-3|
...
now, we solve
solve(absxm3-y,x)
[y + 3]
this result is incorrect, we should get [-y + 3, y + 3]
the first time we reach solvers/solvers.py line 1257 we have
cond: 0 <= x - 3
candidates: [y + 3]
cond.subs(candidates[0]): 0 <= y
cond.subs(candidates[0]).__nonzero__(): True
the second time we reach solvers/solvers.py line 1257 we have
cond: x - 3 < 0
candidates: [-y + 3]
cond.subs(candidates[0]): -y < 0
cond.subs(candidates[0]).__nonzero__(): False
by changing the result of __nonzero__ we can get the behavior that is
desired but this is a pretty hack-job work-around:
StrictInequality.__nonzero__ = lambda self: True
solve(absxm3-y,x)
[-y + 3, y + 3]
--
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.