Opened 4 months ago

Last modified 5 weeks ago

#31902 new defect

Bad (back?)translations to/from Mathematica

Reported by: charpent Owned by:
Priority: major Milestone: sage-9.5
Component: interfaces Keywords: Mathematica
Cc: Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges


Possible followup to #31756 : trying to enhance our interface to Mathematica by simple means.

Mathematica has many functions not implemented in Sage. Some of them are (semi-)trivial possible additions (e.g. Mathematica's HypergeometriPFQRegularized, which is but). the normalized versin of Sage's hypergeometric. They are not in the scope of this ticket, and adding them should be discussed on a case-by-case basis

Mathematica also has many "special-case" functions where Sage has only a "general case" ; for example, Sage's hypergeometric translates Mathematica's HypergeometricPFQ, but should also translate Mathematica's Hypergeometric0F1, Hypergeometric1F1 and Hypergeometric2F1 (it currently doesn't).

Such functions are a first scope of the present ticket : adding these translations add to the ability of using in Sage sime Mathematica's results.

But the most pressing enhancements are as follow : many Mathematica functions, which do have Sage equivalents, are ill-translated by the current interface. A prime example is :

sage: arctan(x)._mathematica_()==mathematica.ArcTan(x)

This (seriously) limits the ability to delecate some calculations to Mathematica when it migh be better than Sage.

Detecting such cases is not trivial. A first approximation restricted to Symbolic Functions can be obtained by :

from sage.symbolic.function import Function
Funs=[eval(u) for u in dir(sage.functions.all) if u in globals() and isinstance(eval(u), Function)]
X=var("x", n=6)
DFuns={u:u.number_of_arguments() for u in Funs}
for u in DFuns.keys():
        TransOK.update({u:bool(u(*X[:DFuns[u]]).diff(x0)._mathematica_() ==\
	                       mathematica.D(u(*X[:DFuns[u]]), x0))})
        TransOK.update({u:"Doesn't (back?)translate."})
BadTrans = [u for u in TransOK.keys() if not TransOK[u]]
NoTrans = [u for u in TransOK.keys() if type(TransOK[u]) is str]

The result is edifying :

sage: len(dir(sage.functions.all))
sage: len([u for u in dir(sage.functions.all) if u[0]!="_"])
sage: len(DFuns)
sage: len(BadTrans)
sage: len(NoTrans)

Doing the same work for the 59 functions not derived from Symbolic Function isn't as trivial. Suggestions welcome.

Suggestions also welcome on how to attack this not-trivially-sized problem...

Change History (1)

comment:1 Changed 5 weeks ago by mkoeppe

  • Milestone changed from sage-9.4 to sage-9.5
Note: See TracTickets for help on using tickets.