Solving an equation containing absolute value, with python 3

180 views
Skip to first unread message

Cesar Romani

unread,
Sep 24, 2019, 8:27:35 PM9/24/19
to sympy
I'm trying to solve the following equation, with python 3.6.3 on Windows 7:

||x² - 1| - x| = x

I did

from sympy import *
x = Symbol('x', real=True)
solve(abs((abs(x**2-1)-x))-x)

but I get the following error:

--------------------
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python36-32\lib\site-packages\sympy\solvers\solvers.py", line 1065, in solve
solution = _solve(f[0], *symbols, **flags)
  File "C:\Python36-32\lib\site-packages\sympy\solvers\solvers.py", line 1366, in _solve
candidates = _solve(piecewise_fold(expr), symbol, **flags)
  File "C:\Python36-32\lib\site-packages\sympy\solvers\solvers.py", line 1634, in _solve
raise NotImplementedError('\n'.join([msg, not_impl_msg % f]))
NotImplementedError: multiple generators [x, Abs(-x**2 + x + 1)]
No algorithms are implemented to solve equation -x + Abs(-x**2 + x + 1)
--------------------

I updated SymPy to the latest version, 1.4, but I get the same error.

But, with python 2.7.14 I get answers, namely [1, -1+sqrt(2), 1+sqrt(2)].
Am I missing something with Python 3?

Many thanks in advance,

-- 
Cesar

Aaron Meurer

unread,
Sep 24, 2019, 9:19:11 PM9/24/19
to sympy
Python 2 and Python 3 use separate installations, so it's likely that
you have different sympy versions installed. You can check which
version is being used with

import sympy
sympy.__version__

I checked and this did indeed used to work in an older version (I
tested 1.1) but doesn't work in the latest version or the git master.
Can you open an issue at https://github.com/sympy/sympy/issues for
this?

Aaron Meurer
> --
> 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+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/50f98076-a1a9-4656-b47c-7d59db36a099%40googlegroups.com.

Steve F

unread,
Oct 5, 2019, 2:52:15 AM10/5/19
to sympy
Hi,

  Here is a simple problem that worked for me:
from sympy import *
x = Symbol('x', real=True)
solve((abs(2*x-4))-14)

Chris Smith

unread,
Oct 5, 2019, 7:40:21 AM10/5/19
to sympy
This is reported as a issue 17650.
Reply all
Reply to author
Forward
0 new messages