Ask Your Question
0

Can't solve equation with abs in the terms

asked 2017-01-06 23:15:29 +0200

gabboman gravatar image

Hi, I have a problem with this system:

f(x,y)=(1+y-a*abs(x),b*x)
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 "_sage_input_14.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("c29sdmUoW2ZbMF09PXgsIGZbMV09PXldLCB4LHkp"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>

  File "/tmp/tmpfPvSBx/___code___.py", 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/relation.py", 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/relation.py", 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/calculus.py", 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

Comments

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-07 05:46:21 +0200 )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 12:32:34 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-01-07 12:36:56 +0200

mforets gravatar image

updated 2017-01-07 12:38:26 +0200

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$:

assume(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)
forget()
assume(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] $$

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

forget()
solve(f, [x, y])

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

edit flag offensive delete link more

Comments

I see what is going on now. I've opened https://trac.sagemath.org/ticket/22149 for this strange lack of recognition.

kcrisman gravatar imagekcrisman ( 2017-01-07 19:47:39 +0200 )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

Stats

Asked: 2017-01-06 23:15:29 +0200

Seen: 610 times

Last updated: Jan 07 '17