sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.32k stars 453 forks source link

[Bug?] Unimplemented type for python_to_ecl #38597

Closed kands-code closed 1 week ago

kands-code commented 2 weeks ago

Steps To Reproduce

The code that encountered the error is as follows:

x = var("x")
cond = RealSet.point(0)
f = piecewise([(cond, 0), (cond.complement(), x^2 * sin(1 / x))], var=x)
df = diff(f, x)
df.limit(x = 0)

Expected Behavior

Returns ind or other possible return values.

Actual Behavior

The error is as follows:

details of error ```plaintext --------------------------------------------------------------------------- TypeError Traceback (most recent call last) File ~/.local/sdk/sage/sage-src/src/sage/interfaces/maxima_lib.py:1682, in sr_to_max(expr) 1681 try: -> 1682 return pyobject_to_max(expr.pyobject()) 1683 except TypeError: File ~/.local/sdk/sage/sage-src/src/sage/interfaces/maxima_lib.py:1580, in pyobject_to_max(obj) 1579 return EclObject([[mplus], pyobject_to_max(re), [[mtimes], pyobject_to_max(im), max_i]]) -> 1580 return EclObject(obj) File ~/.local/sdk/sage/sage-src/src/sage/libs/ecl.pyx:696, in sage.libs.ecl.EclObject.__init__() 695 elif len(args) == 1: --> 696 self.set_obj(python_to_ecl(args[0], True)) 697 elif len(args) == 2: File ~/.local/sdk/sage/sage-src/src/sage/libs/ecl.pyx:487, in sage.libs.ecl.python_to_ecl() 486 else: --> 487 L = python_to_ecl(pyobj[-1], read_strings) 488 for i in range(len(pyobj) - 2, -1, -1): File ~/.local/sdk/sage/sage-src/src/sage/libs/ecl.pyx:492, in sage.libs.ecl.python_to_ecl() 491 else: --> 492 raise TypeError("Unimplemented type for python_to_ecl") 493 TypeError: Unimplemented type for python_to_ecl During handling of the above exception, another exception occurred: RuntimeError Traceback (most recent call last) File ~/.local/sdk/sage/sage-src/src/sage/interfaces/interface.py:750, in InterfaceElement.__init__(self, parent, value, is_name, name) 749 try: --> 750 self._name = parent._create(value, name=name) 751 except (TypeError, RuntimeError, ValueError) as x: File ~/.local/sdk/sage/sage-src/src/sage/interfaces/maxima_lib.py:623, in MaximaLib._create(self, value, name) 622 else: --> 623 self.set(name, value) 624 except RuntimeError as error: File ~/.local/sdk/sage/sage-src/src/sage/interfaces/maxima_lib.py:533, in MaximaLib.set(self, var, value) 532 cmd = '%s : %s$' % (var, value.rstrip(';')) --> 533 self.eval(cmd) File ~/.local/sdk/sage/sage-src/src/sage/interfaces/maxima_lib.py:479, in MaximaLib._eval_line(self, line, locals, reformat, **kwds) 478 if statement: --> 479 maxima_eval("#$%s$" % statement) 480 if not reformat: File ~/.local/sdk/sage/sage-src/src/sage/libs/ecl.pyx:829, in sage.libs.ecl.EclObject.__call__() 828 """ --> 829 lispargs = EclObject(list(args)) 830 return ecl_wrap(ecl_safe_apply(self.obj, (lispargs).obj)) File ~/.local/sdk/sage/sage-src/src/sage/libs/ecl.pyx:696, in sage.libs.ecl.EclObject.__init__() 695 elif len(args) == 1: --> 696 self.set_obj(python_to_ecl(args[0], True)) 697 elif len(args) == 2: File ~/.local/sdk/sage/sage-src/src/sage/libs/ecl.pyx:481, in sage.libs.ecl.python_to_ecl() 480 for i in range(len(pyobj) - 1, -1, -1): --> 481 L = cl_cons(python_to_ecl(pyobj[i], read_strings), L) 482 return L File ~/.local/sdk/sage/sage-src/src/sage/libs/ecl.pyx:458, in sage.libs.ecl.python_to_ecl() 457 if read_strings: --> 458 return ecl_safe_funcall(read_from_string_clobj, o) 459 else: File ~/.local/sdk/sage/sage-src/src/sage/libs/ecl.pyx:342, in sage.libs.ecl.ecl_safe_funcall() 341 else: --> 342 raise RuntimeError("ECL says: {}".format(message)) 343 else: RuntimeError: ECL says: THROW: The catch MACSYMA-QUIT is undefined. During handling of the above exception, another exception occurred: TypeError Traceback (most recent call last) Cell In[5], line 5 3 __tmp__=var("x"); f = symbolic_expression(piecewise([(cond, Integer(0)), (cond.complement(), x**Integer(2) * sin(Integer(1) / x))], var=x)).function(x) 4 __tmp__=var("x"); df = symbolic_expression(diff(f(x), x)).function(x) ----> 5 df(x).limit(x = Integer(0)) File ~/.local/sdk/sage/sage-src/src/sage/symbolic/expression.pyx:13273, in sage.symbolic.expression.Expression.limit() 13271 """ 13272 from sage.calculus.calculus import limit > 13273 return limit(self, *args, **kwds) 13274 13275 def laplace(self, t, s): File ~/.local/sdk/sage/sage-src/src/sage/calculus/calculus.py:1434, in limit(ex, dir, taylor, algorithm, **argv) 1432 if algorithm == 'maxima': 1433 if dir is None: -> 1434 l = maxima.sr_limit(ex, v, a) 1435 elif dir in dir_plus: 1436 l = maxima.sr_limit(ex, v, a, 'plus') File ~/.local/sdk/sage/sage-src/src/sage/interfaces/maxima_lib.py:1000, in MaximaLib.sr_limit(self, expr, v, a, dir) 930 """ 931 Helper function to wrap calculus use of Maxima's limits. 932 (...) 997 sage: _ = m.eval('domain: complex') 998 """ 999 try: -> 1000 L = [sr_to_max(SR(aa)) for aa in [expr, v, a]] 1001 if dir == "plus": 1002 L.append(max_plus) File ~/.local/sdk/sage/sage-src/src/sage/interfaces/maxima_lib.py:1673, in sr_to_max(expr) 1670 sage_op_dict[op] = op_max 1671 max_op_dict[op_max] = op 1672 return EclObject(([sage_op_dict[op]], -> 1673 [sr_to_max(o) for o in expr.operands()])) 1674 elif expr.is_symbol() or expr._is_registered_constant_(): 1675 if expr not in sage_sym_dict: File ~/.local/sdk/sage/sage-src/src/sage/interfaces/maxima_lib.py:1659, in sr_to_max(expr) 1657 return EclObject(special_sage_to_max[op](*[sr_to_max(o) for o in expr.operands()])) 1658 elif op == tuple: -> 1659 return EclObject(([mlist], list(sr_to_max(op) for op in expr.operands()))) 1660 elif not (op in sage_op_dict): 1661 # Maxima does some simplifications automatically by default 1662 # so calling maxima(expr) can change the structure of expr (...) 1665 # furthermore, this should already use any _maxima_ methods on op, so use any 1666 # conversion methods that are registered in pynac. 1667 op_max = maxima(op).ecl() File ~/.local/sdk/sage/sage-src/src/sage/interfaces/maxima_lib.py:1659, in (.0) 1657 return EclObject(special_sage_to_max[op](*[sr_to_max(o) for o in expr.operands()])) 1658 elif op == tuple: -> 1659 return EclObject(([mlist], list(sr_to_max(op) for op in expr.operands()))) 1660 elif not (op in sage_op_dict): 1661 # Maxima does some simplifications automatically by default 1662 # so calling maxima(expr) can change the structure of expr (...) 1665 # furthermore, this should already use any _maxima_ methods on op, so use any 1666 # conversion methods that are registered in pynac. 1667 op_max = maxima(op).ecl() File ~/.local/sdk/sage/sage-src/src/sage/interfaces/maxima_lib.py:1684, in sr_to_max(expr) 1682 return pyobject_to_max(expr.pyobject()) 1683 except TypeError: -> 1684 return maxima(expr).ecl() File ~/.local/sdk/sage/sage-src/src/sage/interfaces/interface.py:306, in Interface.__call__(self, x, name) 299 return cls(self, x, name=name) 300 try: 301 # Special methods do not and should not have an option to 302 # set the name directly, as the identifier assigned by the 303 # interface should stay consistent. An identifier with a 304 # user-assigned name might change its value, so we return a 305 # new element. --> 306 result = self._coerce_from_special_method(x) 307 return result if name is None else result.name(new_name=name) 308 except TypeError: File ~/.local/sdk/sage/sage-src/src/sage/interfaces/maxima_lib.py:410, in MaximaLib._coerce_from_special_method(self, x) 408 if isinstance(x, EclObject): 409 return MaximaLibElement(self, self._create(x)) --> 410 return MaximaAbstract._coerce_from_special_method(self, x) File ~/.local/sdk/sage/sage-src/src/sage/interfaces/interface.py:334, in Interface._coerce_from_special_method(self, x) 332 s = '_gp_' 333 try: --> 334 return (x.__getattribute__(s))(self) 335 except AttributeError: 336 return self(x._interface_init_()) File ~/.local/sdk/sage/sage-src/src/sage/symbolic/expression.pyx:1219, in sage.symbolic.expression.Expression._maxima_() 1217 return super()._interface_(maxima) 1218 else: -> 1219 return super()._interface_(session) 1220 1221 def _interface_init_(self, I): File ~/.local/sdk/sage/sage-src/src/sage/structure/sage_object.pyx:723, in sage.structure.sage_object.SageObject._interface_() 721 except Exception: 722 raise NotImplementedError("coercion of object %s to %s not implemented:\n%s\n%s" % (repr(self), I)) --> 723 X = I(s) 724 if c: 725 try: File ~/.local/sdk/sage/sage-src/src/sage/interfaces/interface.py:299, in Interface.__call__(self, x, name) 296 pass 298 if isinstance(x, str): --> 299 return cls(self, x, name=name) 300 try: 301 # Special methods do not and should not have an option to 302 # set the name directly, as the identifier assigned by the 303 # interface should stay consistent. An identifier with a 304 # user-assigned name might change its value, so we return a 305 # new element. 306 result = self._coerce_from_special_method(x) File ~/.local/sdk/sage/sage-src/src/sage/interfaces/interface.py:752, in InterfaceElement.__init__(self, parent, value, is_name, name) 750 self._name = parent._create(value, name=name) 751 except (TypeError, RuntimeError, ValueError) as x: --> 752 raise TypeError(x) TypeError: ECL says: THROW: The catch MACSYMA-QUIT is undefined. ```

Additional Information

I'm new to SageMath and I don't know how to troubleshoot this kind of problem. If you need any additional information, feel free to ask.

Thanks for your help!

Environment

- **OS**: ArchLinux
- **Sage Version**: 10.5.beta2
- **From**: Build from source

Checklist

fchapoton commented 1 week ago

Maxima has some problem with the limit. You can try

sage: limit(df,x=0,algorithm='sympy')
0
kands-code commented 1 week ago

Maxima has some problem with the limit. You can try

Oh, so this is Maxima’s question, right? Got it, thanks!