The damn thing *can* be done in Sage … by using Sympy :
# Use of Sympy import sympy sx, sy = sympy.symbols("sx, sy") SL = 
[sympy.sin, sympy.cos, sympy.tan, sympy.csc, sympy.sec, sympy.cot, 
sympy.sinh, sympy.cosh, sympy.tanh, sympy.csch, sympy.sech, sympy.coth] SIL 
= [sympy.asin, sympy.acos, sympy.atan, sympy.acsc, sympy.asec, sympy.acot, 
sympy.asinh, sympy.acosh, sympy.atanh, sympy.acsch, sympy.asech, 
sympy.acoth] px = sympy.Wild("px") SD={sx:px} foo=[dict(list(map(lambda 
v:[v.subs(SD), u[0].subs(SD)], u[1]))) for u in zip([w(sx) for w in SIL], 
[w for w in [sympy.solve((u(sy)-sx).rewrite("exp"), sy) for u in SL]])] 
sD=dict() for d in foo:sD|=d # Conversion to Sage 
Dic2={u._sage_().subs({px:w0}):sD[u]._sage_().subs({px:w0}) for u in 
sD.keys()} 

Indeed :
sage: Dic2 {-I*log(I*$0 - I*sqrt($0^2 - 1)): arcsin($0), -I*log(I*$0 + 
I*sqrt($0^2 - 1)): arcsin($0), -I*log($0 - sqrt($0^2 - 1)): arccos($0), 
-I*log($0 + sqrt($0^2 - 1)): arccos($0), -I*log(-sqrt(-($0 - I)/($0 + I))): 
arctan($0), -I*log(sqrt(-($0 - I)/($0 + I))): arctan($0), 
-I*log(-(sqrt($0^2 - 1) - I)/$0): arccsc($0), -I*log((sqrt($0^2 - 1) + 
I)/$0): arccsc($0), -I*log(-(sqrt(-$0^2 + 1) - 1)/$0): arcsec($0), 
-I*log((sqrt(-$0^2 + 1) + 1)/$0): arcsec($0), -I*log(-sqrt(($0 + I)/($0 - 
I))): arccot($0), -I*log(sqrt(($0 + I)/($0 - I))): arccot($0), log($0 - 
sqrt($0^2 + 1)): arcsinh($0), log($0 + sqrt($0^2 + 1)): arcsinh($0), log($0 
- sqrt($0^2 - 1)): arccosh($0), log($0 + sqrt($0^2 - 1)): arccosh($0), 
log(-sqrt(-($0 + 1)/($0 - 1))): arctanh($0), log(sqrt(-($0 + 1)/($0 - 1))): 
arctanh($0), log(-(sqrt($0^2 + 1) - 1)/$0): arccsch($0), log((sqrt($0^2 + 
1) + 1)/$0): arccsch($0), log(-(sqrt(-$0^2 + 1) - 1)/$0): arcsech($0), 
log((sqrt(-$0^2 + 1) + 1)/$0): arcsech($0), log(-sqrt(($0 + 1)/($0 - 1))): 
arccoth($0), log(sqrt(($0 + 1)/($0 - 1))): arccoth($0)} 

But the need for this workaround makes me suspect thai it might not be as 
useful as I wish it would be…

Hints ? Ideas ?

[ Even lazzi are welcome… ]
​
Le samedi 1 juin 2024 à 22:11:43 UTC+2, Emmanuel Charpentier a écrit :

> Context : finding patterns of explicit forms of inverse 
> (hyperbolic|trigonometric) functions for simplification.
>
> Simple solution :
> reset() y=SR.var("y") IL = [] w0=SR.wild(0) L=[sin, cos, tan, csc, sec, 
> cot, sinh, cosh, tanh, csch, sech, coth] for f in L: 
> R=(f(y)==x).solve(y)[0].rhs() for s in (f(y)==x).exponentialize().solve(y): 
> IL += [s.rhs().subs(x==w0)==R.subs(x==w0)] # End loop 
>
> This works. But I’d like to express this list as a dictionary. Brute-force 
> solution fails with a mysterious TypeError: ECL says: THROW: The catch 
> MACSYMA-QUIT is undefined.. But calling this on *parts* of the list seems 
> to work (not shown).
>
> Try a loop :
> ID=dict() for s in IL: ID[s.lhs()]=s.rhs() # End loop 
>
> This fails again :
> --------------------------------------------------------------------------- 
> RuntimeError Traceback (most recent call last) File 
> /usr/local/sage-10/src/sage/interfaces/interface.py:749, in 
> InterfaceElement.__init__(self, parent, value, is_name, name) 748 try: --> 
> 749 self._name = parent._create(value, name=name) 750 except (TypeError, 
> RuntimeError, ValueError) as x: File 
> /usr/local/sage-10/src/sage/interfaces/maxima_lib.py:632, in 
> MaximaLib._create(self, value, name) 631 else: --> 632 self.set(name, 
> value) 633 except RuntimeError as error: File 
> /usr/local/sage-10/src/sage/interfaces/maxima_lib.py:540, in 
> MaximaLib.set(self, var, value) 539 cmd = '%s : %s$' % (var, 
> value.rstrip(';')) --> 540 self.eval(cmd) File 
> /usr/local/sage-10/src/sage/interfaces/maxima_lib.py:486, in 
> MaximaLib._eval_line(self, line, locals, reformat, **kwds) 485 if 
> statement: --> 486 maxima_eval("#$%s$" % statement) 487 if not reformat: 
> File /usr/local/sage-10/src/sage/libs/ecl.pyx:837, in 
> sage.libs.ecl.EclObject.__call__() 836 """ --> 837 lispargs = 
> EclObject(list(args)) 838 return ecl_wrap(ecl_safe_apply(self.obj, 
> (<EclObject>lispargs).obj)) File 
> /usr/local/sage-10/src/sage/libs/ecl.pyx:698, in 
> sage.libs.ecl.EclObject.__init__() 697 elif len(args) == 1: --> 698 
> self.set_obj(python_to_ecl(args[0], True)) 699 elif len(args) == 2: File 
> /usr/local/sage-10/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 /usr/local/sage-10/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 
> /usr/local/sage-10/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[231], line 1 ----> 1 
> load('/tmp/sage_shell_modeSJ8pfj/sage_shell_mode_temp.sage') File 
> /usr/local/sage-10/src/sage/misc/persist.pyx:175, in 
> sage.misc.persist.load() 173 174 if 
> sage.repl.load.is_loadable_filename(filename): --> 175 
> sage.repl.load.load(filename, globals()) 176 return 177 File 
> /usr/local/sage-10/src/sage/repl/load.py:277, in load(filename, globals, 
> attach) 275 add_attached_file(fpath) 276 with fpath.open() as f: --> 277 
> exec(preparse_file(f.read()) + "\n", globals) 278 elif ext in ['.spyx', 
> '.pyx']: 279 if attach: File <string>:5 File 
> /usr/local/sage-10/src/sage/symbolic/expression.pyx:3515, in 
> sage.symbolic.expression.Expression.__bool__() 3513 if res in (True, 
> False): 3514 return res -> 3515 res = 
> self.operator()((self.lhs()-self.rhs()).simplify_full(), 0).test_relation() 
> 3516 if res in (True, False): 3517 return res File 
> /usr/local/sage-10/src/sage/symbolic/expression.pyx:10737, in 
> sage.symbolic.expression.Expression.simplify_full() 10735 """ 10736 x = 
> self > 10737 x = x.simplify_factorial() 10738 x = x.simplify_rectform() 
> 10739 x = x.simplify_trig() File 
> /usr/local/sage-10/src/sage/symbolic/expression.pyx:11217, in 
> sage.symbolic.expression.Expression.simplify_factorial() 11215 11216 """ > 
> 11217 return 
> self.parent()(self._maxima_().makefact().factcomb().minfactorial()) 11218 
> 11219 factorial_simplify = simplify_factorial File 
> /usr/local/sage-10/src/sage/symbolic/expression.pyx:1227, in 
> sage.symbolic.expression.Expression._maxima_() 1225 # Maybe not such a 
> great idea because the "default" interface is another one 1226 from 
> sage.calculus.calculus import maxima -> 1227 return 
> super()._interface_(maxima) 1228 else: 1229 return 
> super()._interface_(session) File 
> /usr/local/sage-10/src/sage/structure/sage_object.pyx:724, in 
> sage.structure.sage_object.SageObject._interface_() 722 except Exception: 
> 723 raise NotImplementedError("coercion of object %s to %s not 
> implemented:\n%s\n%s" % (repr(self), I)) --> 724 X = I(s) 725 if c: 726 
> try: File /usr/local/sage-10/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 
> /usr/local/sage-10/src/sage/interfaces/interface.py:751, in 
> InterfaceElement.__init__(self, parent, value, is_name, name) 749 
> self._name = parent._create(value, name=name) 750 except (TypeError, 
> RuntimeError, ValueError) as x: --> 751 raise TypeError(x) TypeError: ECL 
> says: THROW: The catch MACSYMA-QUIT is undefined. 
>
> Diagnosis :
> sage: len(IL) 24 sage: len(ID) 20 
>
> Hmm. The problem starts with :
> sage: IL[len(ID)] log(-sqrt(-$0^2 + 1)/$0 + 1/$0) == arcsech($0) 
>
> which *can* be put in dictionary form :
> sage: {IL[len(ID)].lhs():IL[len(ID)].rhs()} {log(-sqrt(-$0^2 + 1)/$0 + 
> 1/$0): arcsech($0)} 
>
> But can’t be used for updating the dictionary :
> sage: foo=copy(ID)|{IL[len(ID)].lhs():IL[len(ID)].rhs()} 
> --------------------------------------------------------------------------- 
> RuntimeError Traceback (most recent call last) File 
> /usr/local/sage-10/src/sage/interfaces/interface.py:749, in 
> InterfaceElement.__init__(self, parent, value, is_name, name) 748 try: --> 
> 749 self._name = parent._create(value, name=name) 750 except (TypeError, 
> RuntimeError, ValueError) as x: File 
> /usr/local/sage-10/src/sage/interfaces/maxima_lib.py:632, in 
> MaximaLib._create(self, value, name) 631 else: --> 632 self.set(name, 
> value) 633 except RuntimeError as error: File 
> /usr/local/sage-10/src/sage/interfaces/maxima_lib.py:540, in 
> MaximaLib.set(self, var, value) 539 cmd = '%s : %s$' % (var, 
> value.rstrip(';')) --> 540 self.eval(cmd) File 
> /usr/local/sage-10/src/sage/interfaces/maxima_lib.py:486, in 
> MaximaLib._eval_line(self, line, locals, reformat, **kwds) 485 if 
> statement: --> 486 maxima_eval("#$%s$" % statement) 487 if not reformat: 
> File /usr/local/sage-10/src/sage/libs/ecl.pyx:837, in 
> sage.libs.ecl.EclObject.__call__() 836 """ --> 837 lispargs = 
> EclObject(list(args)) 838 return ecl_wrap(ecl_safe_apply(self.obj, 
> (<EclObject>lispargs).obj)) File 
> /usr/local/sage-10/src/sage/libs/ecl.pyx:698, in 
> sage.libs.ecl.EclObject.__init__() 697 elif len(args) == 1: --> 698 
> self.set_obj(python_to_ecl(args[0], True)) 699 elif len(args) == 2: File 
> /usr/local/sage-10/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 /usr/local/sage-10/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 
> /usr/local/sage-10/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[243], line 1 ----> 1 
> foo=copy(ID)|{IL[len(ID)].lhs():IL[len(ID)].rhs()} File 
> /usr/local/sage-10/src/sage/symbolic/expression.pyx:3515, in 
> sage.symbolic.expression.Expression.__bool__() 3513 if res in (True, 
> False): 3514 return res -> 3515 res = 
> self.operator()((self.lhs()-self.rhs()).simplify_full(), 0).test_relation() 
> 3516 if res in (True, False): 3517 return res File 
> /usr/local/sage-10/src/sage/symbolic/expression.pyx:10737, in 
> sage.symbolic.expression.Expression.simplify_full() 10735 """ 10736 x = 
> self > 10737 x = x.simplify_factorial() 10738 x = x.simplify_rectform() 
> 10739 x = x.simplify_trig() File 
> /usr/local/sage-10/src/sage/symbolic/expression.pyx:11217, in 
> sage.symbolic.expression.Expression.simplify_factorial() 11215 11216 """ > 
> 11217 return 
> self.parent()(self._maxima_().makefact().factcomb().minfactorial()) 11218 
> 11219 factorial_simplify = simplify_factorial File 
> /usr/local/sage-10/src/sage/symbolic/expression.pyx:1227, in 
> sage.symbolic.expression.Expression._maxima_() 1225 # Maybe not such a 
> great idea because the "default" interface is another one 1226 from 
> sage.calculus.calculus import maxima -> 1227 return 
> super()._interface_(maxima) 1228 else: 1229 return 
> super()._interface_(session) File 
> /usr/local/sage-10/src/sage/structure/sage_object.pyx:724, in 
> sage.structure.sage_object.SageObject._interface_() 722 except Exception: 
> 723 raise NotImplementedError("coercion of object %s to %s not 
> implemented:\n%s\n%s" % (repr(self), I)) --> 724 X = I(s) 725 if c: 726 
> try: File /usr/local/sage-10/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 
> /usr/local/sage-10/src/sage/interfaces/interface.py:751, in 
> InterfaceElement.__init__(self, parent, value, is_name, name) 749 
> self._name = parent._create(value, name=name) 750 except (TypeError, 
> RuntimeError, ValueError) as x: --> 751 raise TypeError(x) TypeError: ECL 
> says: THROW: The catch MACSYMA-QUIT is undefined. 
>
> I’m stymied… Any idea ?
> ​
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/045d8d09-b3fd-41f4-83cb-e957c5687ea8n%40googlegroups.com.

Reply via email to