Ask Your Question

How to avoid scientific notation of numbers in the Mathematica interface

asked 2019-11-27 16:30:46 +0200

bekalph gravatar image

I use the mathematica interface to compute numerical values of an extended hyper-geometric function MeijerG for real arguments. This function is provided only by Mathematica:

mathematica('MeijerG[{{1, 3/2}, {}}, {{1, 1}, {1/2}}, mx]')

For real arguments x >= 0.00001 I get useful numeric results, e.g.


for x =0.00001. However, for 0< x < 0.00001 this method fails. With a small argument x and

mathematica('MeijerG[{{1, 3/2}, {}}, {{1, 1}, {1/2}}, mx]'),

With this small argument, I obtain:

resp=MeijerG[{{1, 3/2}, {}}, {{1, 1}, {1/2}}, -9. + 1.*e]

Obviously, this behavious is caused by the python interpreter: It converts pure decimal presentation of numbers (see previous example) into their scientific presentation. And, as I have learned from contributions in the Mathematica's stack exchange, Mathematica doesn't accept formatted numbers like ScientficForm, etc, for numerical evaluation of functions. Thus, Mathematica lets requested numeric evaluation undone. I haven't found any hints how to prevent python from expressing the argument in scientific format. Is it possible by any means to circumvent this problem?

edit retag flag offensive close merge delete


[ Comment converted to answer... ]

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2019-11-27 21:00:34 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-11-28 15:17:08 +0200

Emmanuel Charpentier gravatar image

updated 2019-11-28 15:19:48 +0200

Converting my previous comment to an answer.

This is IMNSHO a bug, reported as Trac#28814.

The conversion is incorrect in the Sage --> Mathematica direction:

sage: 0.000001._mathematica_()
-7 + 10.*e

But doesn't affect rationals:

sage: QQ(0.000001)._mathematica_()

A workaround is to cast those inconvenient floating point quantities to rational approximations:

sage: mathematica.N(mathematica.Sin(0.000001)).sage()
-1.0*sin(-10.0*e + 7.0)
sage: mathematica.N(mathematica.Sin(QQ(0.000001))).sage()

[ Note : In general, avoiding floats in the solution of mathematical problems is IMNSHO good heuristics, if not necessarily good numerical analysis... ]

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2019-11-27 16:30:46 +0200

Seen: 866 times

Last updated: Nov 28 '19