Maxima's expression error

22 views
Skip to first unread message

Wesh Dema

unread,
Mar 5, 2026, 8:23:36 PM (yesterday) Mar 5
to sage-support
Hi! I was wondering how to fix the error of Maxima's expression?

For additional information, I have 10.7 version of Sagemath and use wsl to start up Sage Kernel to work in Jupiter Notebook. When I try to calculate exp(t*E) (where E is a matrix) Sage gives me this error: "TypeError: unable to make sense of Maxima expression 'matrixexp(matrix([5_SAGE_VAR_t,9_SAGE_VAR_t],[7_SAGE_VAR_t,3*_SAGE_VAR_t]))' in Sage". How to fix it?

My code:
var('t')
E=matrix(QQ,[[5,9],[7,3]])
exp(t*E)

Error:
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) File ~/miniforge3/envs/sage/lib/python3.11/site-packages/sage/symbolic/function.pyx:537, in sage.symbolic.function.Function.__call__ (build/cythonized/sage/symbolic/function.c:9991)() 536 try: --> 537 args = [SR.coerce(a) for a in args] 538 except TypeError as err: File ~/miniforge3/envs/sage/lib/python3.11/site-packages/sage/structure/parent.pyx:1190, in sage.structure.parent.Parent.coerce (build/cythonized/sage/structure/parent.c:15422)() 1189 -> 1190 cpdef coerce(self, x): 1191 """ File ~/miniforge3/envs/sage/lib/python3.11/site-packages/sage/structure/parent.pyx:1220, in sage.structure.parent.Parent.coerce (build/cythonized/sage/structure/parent.c:15265)() 1219 _record_exception() -> 1220 raise TypeError(_LazyString("no canonical coercion from %s to %s", (parent(x), self), {})) 1221 else: TypeError: no canonical coercion from Full MatrixSpace of 2 by 2 dense matrices over Symbolic Ring to Symbolic Ring During handling of the above exception, another exception occurred: SyntaxError Traceback (most recent call last) File ~/miniforge3/envs/sage/lib/python3.11/site-packages/sage/calculus/calculus.py:2588, in symbolic_expression_from_maxima_string(x, equals_sub, maxima) 2587 SRM_parser._callable_constructor().set_names(function_syms) -> 2588 return SRM_parser.parse_sequence(s) 2589 except SyntaxError: File ~/miniforge3/envs/sage/lib/python3.11/site-packages/sage/misc/parser.pyx:573, in sage.misc.parser.Parser.parse_sequence (build/cythonized/sage/misc/parser.c:8363)() 572 --> 573 cpdef parse_sequence(self, s): 574 """ File ~/miniforge3/envs/sage/lib/python3.11/site-packages/sage/misc/parser.pyx:590, in sage.misc.parser.Parser.parse_sequence (build/cythonized/sage/misc/parser.c:8146)() 589 cdef Tokenizer tokens = Tokenizer(s) --> 590 all = self.p_sequence(tokens) 591 if tokens.next() != EOS: File ~/miniforge3/envs/sage/lib/python3.11/site-packages/sage/misc/parser.pyx:663, in sage.misc.parser.Parser.p_sequence (build/cythonized/sage/misc/parser.c:9182)() 662 else: --> 663 obj = self.p_eqn(tokens) 664 PyList_Append(all, obj) File ~/miniforge3/envs/sage/lib/python3.11/site-packages/sage/misc/parser.pyx:754, in sage.misc.parser.Parser.p_eqn (build/cythonized/sage/misc/parser.c:10323)() 753 """ --> 754 lhs = self.p_expr(tokens) 755 cdef int op = tokens.next() File ~/miniforge3/envs/sage/lib/python3.11/site-packages/sage/misc/parser.pyx:795, in sage.misc.parser.Parser.p_expr (build/cythonized/sage/misc/parser.c:10769)() 794 cdef int op --> 795 operand1 = self.p_term(tokens) 796 op = tokens.next() File ~/miniforge3/envs/sage/lib/python3.11/site-packages/sage/misc/parser.pyx:830, in sage.misc.parser.Parser.p_term (build/cythonized/sage/misc/parser.c:11137)() 829 cdef int op --> 830 operand1 = self.p_factor(tokens) 831 op = tokens.next() File ~/miniforge3/envs/sage/lib/python3.11/site-packages/sage/misc/parser.pyx:873, in sage.misc.parser.Parser.p_factor (build/cythonized/sage/misc/parser.c:11670)() 872 tokens.backtrack() --> 873 return self.p_power(tokens) 874 File ~/miniforge3/envs/sage/lib/python3.11/site-packages/sage/misc/parser.pyx:901, in sage.misc.parser.Parser.p_power (build/cythonized/sage/misc/parser.c:11921)() 900 """ --> 901 operand1 = self.p_atom(tokens) 902 cdef int token = tokens.next() File ~/miniforge3/envs/sage/lib/python3.11/site-packages/sage/misc/parser.pyx:958, in sage.misc.parser.Parser.p_atom (build/cythonized/sage/misc/parser.c:12566)() 957 func = self.callable_constructor(name) --> 958 args, kwds = self.p_args(tokens) 959 token = tokens.next() File ~/miniforge3/envs/sage/lib/python3.11/site-packages/sage/misc/parser.pyx:995, in sage.misc.parser.Parser.p_args (build/cythonized/sage/misc/parser.c:13179)() 994 while token == c',': --> 995 arg = self.p_arg(tokens) 996 if isinstance(arg, tuple): File ~/miniforge3/envs/sage/lib/python3.11/site-packages/sage/misc/parser.pyx:1044, in sage.misc.parser.Parser.p_arg (build/cythonized/sage/misc/parser.c:13699)() 1043 tokens.backtrack() -> 1044 return self.p_expr(tokens) 1045 File ~/miniforge3/envs/sage/lib/python3.11/site-packages/sage/misc/parser.pyx:795, in sage.misc.parser.Parser.p_expr (build/cythonized/sage/misc/parser.c:10769)() 794 cdef int op --> 795 operand1 = self.p_term(tokens) 796 op = tokens.next() File ~/miniforge3/envs/sage/lib/python3.11/site-packages/sage/misc/parser.pyx:830, in sage.misc.parser.Parser.p_term (build/cythonized/sage/misc/parser.c:11137)() 829 cdef int op --> 830 operand1 = self.p_factor(tokens) 831 op = tokens.next() File ~/miniforge3/envs/sage/lib/python3.11/site-packages/sage/misc/parser.pyx:873, in sage.misc.parser.Parser.p_factor (build/cythonized/sage/misc/parser.c:11670)() 872 tokens.backtrack() --> 873 return self.p_power(tokens) 874 File ~/miniforge3/envs/sage/lib/python3.11/site-packages/sage/misc/parser.pyx:901, in sage.misc.parser.Parser.p_power (build/cythonized/sage/misc/parser.c:11921)() 900 """ --> 901 operand1 = self.p_atom(tokens) 902 cdef int token = tokens.next() File ~/miniforge3/envs/sage/lib/python3.11/site-packages/sage/misc/parser.pyx:973, in sage.misc.parser.Parser.p_atom (build/cythonized/sage/misc/parser.c:12836)() 972 else: --> 973 self.parse_error(tokens) 974 File ~/miniforge3/envs/sage/lib/python3.11/site-packages/sage/misc/parser.pyx:1047, in sage.misc.parser.Parser.parse_error (build/cythonized/sage/misc/parser.c:13906)() 1046 cdef parse_error(self, Tokenizer tokens, msg="Malformed expression"): -> 1047 raise SyntaxError(msg, tokens.s, tokens.pos) 1048 SyntaxError: Malformed expression During handling of the above exception, another exception occurred: TypeError Traceback (most recent call last) Cell In[2], line 4 2 var('t') 3 E=matrix(QQ,[[Integer(5),Integer(9)],[Integer(7),Integer(3)]]) ----> 4 exp(t*E) File ~/miniforge3/envs/sage/lib/python3.11/site-packages/sage/symbolic/function.pyx:1061, in sage.symbolic.function.BuiltinFunction.__call__ (build/cythonized/sage/symbolic/function.c:15911)() 1059 res = self._evalf_try_(*args) 1060 if res is None: -> 1061 res = super().__call__( 1062 *args, coerce=coerce, hold=hold) 1063 File ~/miniforge3/envs/sage/lib/python3.11/site-packages/sage/symbolic/function.pyx:549, in sage.symbolic.function.Function.__call__ (build/cythonized/sage/symbolic/function.c:10112)() 547 method = getattr(args[0], self._name, None) 548 if callable(method): --> 549 return method() 550 raise TypeError("cannot coerce arguments: %s" % (err)) 551 File ~/miniforge3/envs/sage/lib/python3.11/site-packages/sage/matrix/matrix_symbolic_dense.pyx:469, in sage.matrix.matrix_symbolic_dense.Matrix_symbolic_dense.exp (build/cythonized/sage/matrix/matrix_symbolic_dense.c:7660)() 467 z = maxima('matrix([%s])' % z.name()) 468 --> 469 return z._sage_() 470 471 def charpoly(self, var='x', algorithm=None): File ~/miniforge3/envs/sage/lib/python3.11/site-packages/sage/interfaces/maxima_abstract.py:1229, in MaximaAbstractElement._sage_(self) 1176 """ 1177 Attempt to make a native Sage object out of this Maxima object. 1178 This is useful for automatic coercions in addition to other (...) 1226 (True, False) 1227 """ 1228 import sage.calculus.calculus as calculus -> 1229 return calculus.symbolic_expression_from_maxima_string(self.name(), 1230 maxima=self.parent()) File ~/miniforge3/envs/sage/lib/python3.11/site-packages/sage/calculus/calculus.py:2590, in symbolic_expression_from_maxima_string(x, equals_sub, maxima) 2588 return SRM_parser.parse_sequence(s) 2589 except SyntaxError: -> 2590 raise TypeError("unable to make sense of Maxima expression '%s' in Sage" % s) 2591 finally: 2592 is_simplified = False TypeError: unable to make sense of Maxima expression 'matrixexp(matrix([5*_SAGE_VAR_t,9*_SAGE_VAR_t],[7*_SAGE_VAR_t,3*_SAGE_VAR_t]))' in Sage

 Also, I've attached screenshots of an error. I would appreciate any advice!
2.png
3.png
4.png
6.png
1.png
5.png

Nils Bruin

unread,
Mar 5, 2026, 11:35:36 PM (24 hours ago) Mar 5
to sage-support
In sage 10.8 I get:

t
sage: E=matrix(QQ,[[5,9],[7,3]])
sage: exp(t*E)
[1/16*(9*e^(16*t) + 7)*e^(-4*t)   9/16*(e^(16*t) - 1)*e^(-4*t)]
[  7/16*(e^(16*t) - 1)*e^(-4*t) 1/16*(7*e^(16*t) + 9)*e^(-4*t)]

so perhaps you can fix your problem simply by upgrading.

Wesh Dema

unread,
4:53 PM (6 hours ago) 4:53 PM
to sage-support
I changed it to 10.8 and it works! Thank you.

пятница, 6 марта 2026 г. в 07:35:36 UTC+3, Nils Bruin:
Reply all
Reply to author
Forward
0 new messages