Ask Your Question
1

How to avoid scientific notation of numbers in the Mathematica interface

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

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:

var('x,mx')
x=0.00001
resp=mathematica.set(mx,x)
mathematica('MeijerG[{{1, 3/2}, {}}, {{1, 1}, {1/2}}, mx]')

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

resp=0.00025871503616237216

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

var('x,y,mx')
x=0.000000001
resp=mathematica.set(mx,x)
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

Comments

[ Comment converted to answer... ]

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

1 Answer

Sort by ยป oldest newest most voted
1

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

Emmanuel Charpentier gravatar image

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

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_()
1/1000000

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()
9.999999999998333e-07

[ 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

Stats

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

Seen: 928 times

Last updated: Nov 28 '19