Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad (back?)translations to/from Mathematica #31902

Open
EmmanuelCharpentier mannequin opened this issue Jun 3, 2021 · 0 comments
Open

Bad (back?)translations to/from Mathematica #31902

EmmanuelCharpentier mannequin opened this issue Jun 3, 2021 · 0 comments

Comments

@EmmanuelCharpentier
Copy link
Mannequin

EmmanuelCharpentier mannequin commented Jun 3, 2021

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)
False

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}
TransOK={}
for u in DFuns.keys():
    try:
        TransOK.update({u:bool(u(*X[:DFuns[u]]).diff(x0)._mathematica_() ==\
	                       mathematica.D(u(*X[:DFuns[u]]), x0))})
    except:
        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))
197
sage: len([u for u in dir(sage.functions.all) if u[0]!="_"])
189
sage: len(DFuns)
130
sage: len(BadTrans)
43
sage: len(NoTrans)
50

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...

Component: interfaces

Keywords: Mathematica

Issue created by migration from https://trac.sagemath.org/ticket/31902

@EmmanuelCharpentier EmmanuelCharpentier mannequin added this to the sage-9.4 milestone Jun 3, 2021
@mkoeppe mkoeppe modified the milestones: sage-9.4, sage-9.5 Aug 22, 2021
@mkoeppe mkoeppe modified the milestones: sage-9.5, sage-9.6 Dec 18, 2021
@mkoeppe mkoeppe modified the milestones: sage-9.6, sage-9.7 May 3, 2022
@mkoeppe mkoeppe modified the milestones: sage-9.7, sage-9.8 Sep 19, 2022
@mkoeppe mkoeppe removed this from the sage-9.8 milestone Jan 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant