ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 28 Nov 2019 15:17:08 +0100How to avoid scientific notation of numbers in the Mathematica interfacehttps://ask.sagemath.org/question/48908/how-to-avoid-scientific-notation-of-numbers-in-the-mathematica-interface/ 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?
Wed, 27 Nov 2019 16:30:46 +0100https://ask.sagemath.org/question/48908/how-to-avoid-scientific-notation-of-numbers-in-the-mathematica-interface/Comment by Emmanuel Charpentier for <p>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:</p>
<pre><code>var('x,mx')
x=0.00001
resp=mathematica.set(mx,x)
mathematica('MeijerG[{{1, 3/2}, {}}, {{1, 1}, {1/2}}, mx]')
</code></pre>
<p>For real arguments x >= 0.00001 I get useful numeric results, e.g. </p>
<pre><code>resp=0.00025871503616237216
</code></pre>
<p>for x =0.00001.
However, for 0< x < 0.00001 this method fails. With a small argument x and</p>
<pre><code>var('x,y,mx')
x=0.000000001
resp=mathematica.set(mx,x)
mathematica('MeijerG[{{1, 3/2}, {}}, {{1, 1}, {1/2}}, mx]'),
</code></pre>
<p>With this small argument, I obtain:</p>
<pre><code>resp=MeijerG[{{1, 3/2}, {}}, {{1, 1}, {1/2}}, -9. + 1.*e]
</code></pre>
<p>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? </p>
https://ask.sagemath.org/question/48908/how-to-avoid-scientific-notation-of-numbers-in-the-mathematica-interface/?comment=48910#post-id-48910[ Comment converted to answer... ]Wed, 27 Nov 2019 21:00:34 +0100https://ask.sagemath.org/question/48908/how-to-avoid-scientific-notation-of-numbers-in-the-mathematica-interface/?comment=48910#post-id-48910Answer by Emmanuel Charpentier for <p>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:</p>
<pre><code>var('x,mx')
x=0.00001
resp=mathematica.set(mx,x)
mathematica('MeijerG[{{1, 3/2}, {}}, {{1, 1}, {1/2}}, mx]')
</code></pre>
<p>For real arguments x >= 0.00001 I get useful numeric results, e.g. </p>
<pre><code>resp=0.00025871503616237216
</code></pre>
<p>for x =0.00001.
However, for 0< x < 0.00001 this method fails. With a small argument x and</p>
<pre><code>var('x,y,mx')
x=0.000000001
resp=mathematica.set(mx,x)
mathematica('MeijerG[{{1, 3/2}, {}}, {{1, 1}, {1/2}}, mx]'),
</code></pre>
<p>With this small argument, I obtain:</p>
<pre><code>resp=MeijerG[{{1, 3/2}, {}}, {{1, 1}, {1/2}}, -9. + 1.*e]
</code></pre>
<p>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? </p>
https://ask.sagemath.org/question/48908/how-to-avoid-scientific-notation-of-numbers-in-the-mathematica-interface/?answer=48914#post-id-48914Converting my previous comment to an answer.
This is IMNSHO a bug, reported as [Trac#28814](https://trac.sagemath.org/ticket/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... ]Thu, 28 Nov 2019 15:17:08 +0100https://ask.sagemath.org/question/48908/how-to-avoid-scientific-notation-of-numbers-in-the-mathematica-interface/?answer=48914#post-id-48914