Ask Your Question
1

differences between .sage and .spyx in numerical evaluation

asked 2017-03-28 07:33:38 -0500

hiro protagonist gravatar image

updated 2017-03-28 12:37:56 -0500

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?

edit retag flag offensive close merge delete

Comments

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

kcrisman gravatar imagekcrisman ( 2017-03-28 12:40:51 -0500 )edit
kcrisman gravatar imagekcrisman ( 2017-03-28 12:41:13 -0500 )edit

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

hiro protagonist gravatar imagehiro protagonist ( 2017-03-29 01:39:17 -0500 )edit

No worries!

kcrisman gravatar imagekcrisman ( 2017-03-29 06:04:15 -0500 )edit

1 answer

Sort by » oldest newest most voted
0

answered 2017-03-28 16:13:34 -0500

ndomes gravatar image

updated 2017-03-28 16:19:20 -0500

It 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
edit flag offensive delete link more

Comments

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

kcrisman gravatar imagekcrisman ( 2017-03-28 19:47:52 -0500 )edit

thanks for the update. but then: how could i prevent this in .spyx mode?

hiro protagonist gravatar imagehiro protagonist ( 2017-03-29 01:40:27 -0500 )edit

Right, that is the question! You could use @ndomes workaround and use Sqrt instead of sqrt, but that is not so nice.

kcrisman gravatar imagekcrisman ( 2017-03-29 06:03:56 -0500 )edit

Your Answer

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

Add Answer

Question Tools

2 followers

Stats

Asked: 2017-03-28 07:33:38 -0500

Seen: 72 times

Last updated: Mar 28