Solving the equality with absolute value I use sympy
with nonlinsolve
function.
For example, I solve |a + b| = a + b
as follows
from sympy import nonlinsolve, symbols, Abs
a,b = symbols('a, b', real = True)
eqn = [Abs(a + b) - (a + b)]
nonlinsolve(eqn, [a, b])
Output is OK:
{(Interval(-b, oo), b)}
However when I try to solve |a - b| = -(a + b)
as below:
from sympy import nonlinsolve, symbols, Abs
a,b = symbols('a, b', real = True)
eqn = [Abs(a - b) + (a + b)]
res = nonlinsolve(eqn, [a, b])
Output is:
False
However clearly there exists at least one solution like a = b = 0
.
Update
It seems that the different behaviour in different version.
In Python 2.7 the result is
But in Python 3 it is False
.
Could you advise the reason of such a behaviour and possible countermeasures, since I'd prefer to use Python 3?