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.Wed, 29 Mar 2017 13:04:15 +0200differences between .sage and .spyx in numerical evaluationhttps://ask.sagemath.org/question/37103/differences-between-sage-and-spyx-in-numerical-evaluation/the question seems very basic, i'm sorry but i could not find an answer in the documentation.
the content of both files `test.sage` and `test.spyx` is identical; it's just
a = 1/sqrt(2)
print a
if i run `test.sage` and with
$ sage test.sage
i get
1/2*sqrt(2)
but the outcome is different from if i run the file `test.spyx` with
$ sage test.spyx
where i get
Compiling test.spyx...
0.707106781187
how can i prevent sage from numerically evaluating $1/\sqrt(2)$ in `.spyx` mode?Tue, 28 Mar 2017 14:33:38 +0200https://ask.sagemath.org/question/37103/differences-between-sage-and-spyx-in-numerical-evaluation/Comment by kcrisman for <p>the question seems very basic, i'm sorry but i could not find an answer in the documentation.</p>
<p>the content of both files <code>test.sage</code> and <code>test.spyx</code> is identical; it's just</p>
<pre><code>a = 1/sqrt(2)
print a
</code></pre>
<p>if i run <code>test.sage</code> and with</p>
<pre><code>$ sage test.sage
</code></pre>
<p>i get</p>
<pre><code>1/2*sqrt(2)
</code></pre>
<p>but the outcome is different from if i run the file <code>test.spyx</code> with</p>
<pre><code>$ sage test.spyx
</code></pre>
<p>where i get</p>
<pre><code>Compiling test.spyx...
0.707106781187
</code></pre>
<p>how can i prevent sage from numerically evaluating $1/\sqrt(2)$ in <code>.spyx</code> mode?</p>
https://ask.sagemath.org/question/37103/differences-between-sage-and-spyx-in-numerical-evaluation/?comment=37123#post-id-37123No worries!Wed, 29 Mar 2017 13:04:15 +0200https://ask.sagemath.org/question/37103/differences-between-sage-and-spyx-in-numerical-evaluation/?comment=37123#post-id-37123Comment by kcrisman for <p>the question seems very basic, i'm sorry but i could not find an answer in the documentation.</p>
<p>the content of both files <code>test.sage</code> and <code>test.spyx</code> is identical; it's just</p>
<pre><code>a = 1/sqrt(2)
print a
</code></pre>
<p>if i run <code>test.sage</code> and with</p>
<pre><code>$ sage test.sage
</code></pre>
<p>i get</p>
<pre><code>1/2*sqrt(2)
</code></pre>
<p>but the outcome is different from if i run the file <code>test.spyx</code> with</p>
<pre><code>$ sage test.spyx
</code></pre>
<p>where i get</p>
<pre><code>Compiling test.spyx...
0.707106781187
</code></pre>
<p>how can i prevent sage from numerically evaluating $1/\sqrt(2)$ in <code>.spyx</code> mode?</p>
https://ask.sagemath.org/question/37103/differences-between-sage-and-spyx-in-numerical-evaluation/?comment=37109#post-id-37109Sorry for the confusion over getting your question approved - somehow you edited it before it was approved (first-time posts need approval to combat spam) and so the question was deleted and closed before ever being seen because it looked like there were duplicate posts. This is a very good question, actually.Tue, 28 Mar 2017 19:40:51 +0200https://ask.sagemath.org/question/37103/differences-between-sage-and-spyx-in-numerical-evaluation/?comment=37109#post-id-37109Comment by kcrisman for <p>the question seems very basic, i'm sorry but i could not find an answer in the documentation.</p>
<p>the content of both files <code>test.sage</code> and <code>test.spyx</code> is identical; it's just</p>
<pre><code>a = 1/sqrt(2)
print a
</code></pre>
<p>if i run <code>test.sage</code> and with</p>
<pre><code>$ sage test.sage
</code></pre>
<p>i get</p>
<pre><code>1/2*sqrt(2)
</code></pre>
<p>but the outcome is different from if i run the file <code>test.spyx</code> with</p>
<pre><code>$ sage test.spyx
</code></pre>
<p>where i get</p>
<pre><code>Compiling test.spyx...
0.707106781187
</code></pre>
<p>how can i prevent sage from numerically evaluating $1/\sqrt(2)$ in <code>.spyx</code> mode?</p>
https://ask.sagemath.org/question/37103/differences-between-sage-and-spyx-in-numerical-evaluation/?comment=37110#post-id-37110Cross-posted at http://stackoverflow.com/questions/43067894/differences-between-sage-and-spyx-in-numerical-evaluationTue, 28 Mar 2017 19:41:13 +0200https://ask.sagemath.org/question/37103/differences-between-sage-and-spyx-in-numerical-evaluation/?comment=37110#post-id-37110Comment by hiro protagonist for <p>the question seems very basic, i'm sorry but i could not find an answer in the documentation.</p>
<p>the content of both files <code>test.sage</code> and <code>test.spyx</code> is identical; it's just</p>
<pre><code>a = 1/sqrt(2)
print a
</code></pre>
<p>if i run <code>test.sage</code> and with</p>
<pre><code>$ sage test.sage
</code></pre>
<p>i get</p>
<pre><code>1/2*sqrt(2)
</code></pre>
<p>but the outcome is different from if i run the file <code>test.spyx</code> with</p>
<pre><code>$ sage test.spyx
</code></pre>
<p>where i get</p>
<pre><code>Compiling test.spyx...
0.707106781187
</code></pre>
<p>how can i prevent sage from numerically evaluating $1/\sqrt(2)$ in <code>.spyx</code> mode?</p>
https://ask.sagemath.org/question/37103/differences-between-sage-and-spyx-in-numerical-evaluation/?comment=37117#post-id-37117@kcrisman : yes, the first time i posted the question it took hours for it to get approved (from stackoverflow i was used to higher speeds...), and i could no longer find any trace of it. so i re-posted, etc etc etc. sorry for the confusion. hope everything is correct now.
and yes, after i could not find my question here i posted it over on stackoverflow...Wed, 29 Mar 2017 08:39:17 +0200https://ask.sagemath.org/question/37103/differences-between-sage-and-spyx-in-numerical-evaluation/?comment=37117#post-id-37117Answer by ndomes for <p>the question seems very basic, i'm sorry but i could not find an answer in the documentation.</p>
<p>the content of both files <code>test.sage</code> and <code>test.spyx</code> is identical; it's just</p>
<pre><code>a = 1/sqrt(2)
print a
</code></pre>
<p>if i run <code>test.sage</code> and with</p>
<pre><code>$ sage test.sage
</code></pre>
<p>i get</p>
<pre><code>1/2*sqrt(2)
</code></pre>
<p>but the outcome is different from if i run the file <code>test.spyx</code> with</p>
<pre><code>$ sage test.spyx
</code></pre>
<p>where i get</p>
<pre><code>Compiling test.spyx...
0.707106781187
</code></pre>
<p>how can i prevent sage from numerically evaluating $1/\sqrt(2)$ in <code>.spyx</code> mode?</p>
https://ask.sagemath.org/question/37103/differences-between-sage-and-spyx-in-numerical-evaluation/?answer=37111#post-id-37111It looks like `sqrt` in `.spyx` mode is `c sqrt` and not `sage sqrt` .
%cython
from sage.functions.other import sqrt as Sqrt
print 1/Sqrt(2)
print 1/sqrt(2)
output:
1/2*sqrt(2)
0.707106781187
Tue, 28 Mar 2017 23:13:34 +0200https://ask.sagemath.org/question/37103/differences-between-sage-and-spyx-in-numerical-evaluation/?answer=37111#post-id-37111Comment by kcrisman for <p>It looks like <code>sqrt</code> in <code>.spyx</code> mode is <code>c sqrt</code> and not <code>sage sqrt</code> .</p>
<pre><code>%cython
from sage.functions.other import sqrt as Sqrt
print 1/Sqrt(2)
print 1/sqrt(2)
</code></pre>
<p>output:</p>
<pre><code>1/2*sqrt(2)
0.707106781187
</code></pre>
https://ask.sagemath.org/question/37103/differences-between-sage-and-spyx-in-numerical-evaluation/?comment=37115#post-id-37115Which begs the question of why it isn't replaced by Sage's even when explicitly imported. Unfortunately the .c and other files are only in temp files so it's not easy to see what is going on - at least a generated .pyx file would be helpful.Wed, 29 Mar 2017 02:47:52 +0200https://ask.sagemath.org/question/37103/differences-between-sage-and-spyx-in-numerical-evaluation/?comment=37115#post-id-37115Comment by hiro protagonist for <p>It looks like <code>sqrt</code> in <code>.spyx</code> mode is <code>c sqrt</code> and not <code>sage sqrt</code> .</p>
<pre><code>%cython
from sage.functions.other import sqrt as Sqrt
print 1/Sqrt(2)
print 1/sqrt(2)
</code></pre>
<p>output:</p>
<pre><code>1/2*sqrt(2)
0.707106781187
</code></pre>
https://ask.sagemath.org/question/37103/differences-between-sage-and-spyx-in-numerical-evaluation/?comment=37118#post-id-37118thanks for the update. but then: how could i prevent this in .spyx mode?Wed, 29 Mar 2017 08:40:27 +0200https://ask.sagemath.org/question/37103/differences-between-sage-and-spyx-in-numerical-evaluation/?comment=37118#post-id-37118Comment by kcrisman for <p>It looks like <code>sqrt</code> in <code>.spyx</code> mode is <code>c sqrt</code> and not <code>sage sqrt</code> .</p>
<pre><code>%cython
from sage.functions.other import sqrt as Sqrt
print 1/Sqrt(2)
print 1/sqrt(2)
</code></pre>
<p>output:</p>
<pre><code>1/2*sqrt(2)
0.707106781187
</code></pre>
https://ask.sagemath.org/question/37103/differences-between-sage-and-spyx-in-numerical-evaluation/?comment=37122#post-id-37122Right, that is the question! You could use @ndomes workaround and use `Sqrt` instead of `sqrt`, but that is not so nice.Wed, 29 Mar 2017 13:03:56 +0200https://ask.sagemath.org/question/37103/differences-between-sage-and-spyx-in-numerical-evaluation/?comment=37122#post-id-37122