Ask Your Question

Can't solve equation with abs in the terms

asked 2017-01-06 16:15:29 -0500

gabboman gravatar image

Hi, I have a problem with this system:

solve([f[0]==x, f[1]==y], x,y)

It gives me this big error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "", line 10, in <module>
    exec compile(u'open("","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("c29sdmUoW2ZbMF09PXgsIGZbMV09PXldLCB4LHkp"),globals())+"\\n"); execfile(os.path.abspath(""))
  File "", line 1, in <module>

  File "/tmp/tmpfPvSBx/", line 3, in <module>
    exec compile(u'solve([f[_sage_const_0 ]==x, f[_sage_const_1 ]==y], x,y)
  File "", line 1, in <module>

  File "/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/symbolic/", line 864, in solve
    sol_list = string_to_list_of_solutions(repr(s))
  File "/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/symbolic/", line 539, in string_to_list_of_solutions
    v = symbolic_expression_from_maxima_string(s, equals_sub=True)
  File "/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/calculus/", line 1893, in symbolic_expression_from_maxima_string
    return SRM_parser.parse_sequence(s)
  File "sage/misc/parser.pyx", line 533, in sage.misc.parser.Parser.parse_sequence (/usr/lib/sagemath//src/build/cythonized/sage/misc/parser.c:4832)
  File "sage/misc/parser.pyx", line 549, in sage.misc.parser.Parser.parse_sequence (/usr/lib/sagemath//src/build/cythonized/sage/misc/parser.c:4699)
  File "sage/misc/parser.pyx", line 613, in sage.misc.parser.Parser.p_sequence (/usr/lib/sagemath//src/build/cythonized/sage/misc/parser.c:5440)
  File "sage/misc/parser.pyx", line 645, in sage.misc.parser.Parser.p_list (/usr/lib/sagemath//src/build/cythonized/sage/misc/parser.c:5788)
  File "sage/misc/parser.pyx", line 622, in sage.misc.parser.Parser.p_sequence (/usr/lib/sagemath//src/build/cythonized/sage/misc/parser.c:5562)
  File "sage/misc/parser.pyx", line 712, in sage.misc.parser.Parser.p_eqn (/usr/lib/sagemath//src/build/cythonized/sage/misc/parser.c:6386)
  File "sage/misc/parser.pyx", line 752, in sage.misc.parser.Parser.p_expr (/usr/lib/sagemath//src/build/cythonized/sage/misc/parser.c:6766)
  File "sage/misc/parser.pyx", line 786, in sage.misc.parser.Parser.p_term (/usr/lib/sagemath//src/build/cythonized/sage/misc/parser.c:7028)
  File "sage/misc/parser.pyx", line 829, in sage.misc.parser.Parser.p_factor (/usr/lib/sagemath//src/build/cythonized/sage/misc/parser.c:7465)
  File "sage/misc/parser.pyx", line 857, in sage.misc.parser.Parser.p_power (/usr/lib/sagemath//src/build/cythonized/sage/misc/parser.c:7610)
  File "sage/misc/parser.pyx", line 916, in sage.misc.parser.Parser.p_atom (/usr/lib/sagemath//src/build/cythonized/sage/misc/parser.c:8304)
  File "sage/symbolic/function.pyx", line 471, in sage.symbolic.function.Function.__call__ (/usr/lib/sagemath//src/build/cythonized/sage/symbolic/function.cpp:6627)
TypeError: cannot coerce arguments: no canonical coercion from <type 'list'=""> to Symbolic Ring

What can I do?

edit retag flag offensive close merge delete


What is f[0] supposed to be? That isn't standard Sage syntax with a function. (Also, don't forget to include that you made var('a,b') somewhere.)

kcrisman gravatar imagekcrisman ( 2017-01-06 22:46:21 -0500 )edit

Hey! It should be f[0]=1+y-a*abs(x)

Anyway I see you opened a bug report. I found a few more bugs with ABS and I think I'll leave my worksheet over here soon.

gabboman gravatar imagegabboman ( 2017-01-13 05:32:34 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2017-01-07 05:36:56 -0500

mforets gravatar image

updated 2017-01-07 05:38:26 -0500

Consider a system of linear equations with an absolute value:

%display typeset 
var('x y a b')
f=[1+y-a*abs_symbolic(x)==x, b*x==y]; f

$\newcommand{\Bold}[1]{\mathbf{#1}}\left[-a {\left| x \right|} + y + 1 = x, b x = y\right]$

We attempt to solve the system assuming $x>0$ and then $x<0$:


solve(f, [x, y])

$$\newcommand{\Bold}[1]{\mathbf{#1}}\left[\left[x = \frac{1}{a - b + 1}, y = \frac{b}{a - b + 1}\right]\right]$$

# use `forget()` to avoid conflict with the previous assumption (use `assumptions()` to see all current symbolic assumptions)

solve(f, [x, y])

$$ \newcommand{\Bold}[1]{\mathbf{#1}}\left[\left[x = -\frac{1}{a + b - 1}, y = -\frac{b}{a + b - 1}\right]\right] $$

As you point out, there seems to be a bug if we do this straightforwardly:

solve(f, [x, y])

gives TypeError: cannot coerce arguments: no canonical coercion from <type 'list'> to Symbolic Ring.

edit flag offensive delete link more


I see what is going on now. I've opened for this strange lack of recognition.

kcrisman gravatar imagekcrisman ( 2017-01-07 12:47:39 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2017-01-06 16:15:29 -0500

Seen: 99 times

Last updated: Jan 07