Ask Your Question
2

differences between .sage and .spyx in numerical evaluation

asked 2017-03-28 14:33:38 +0200

hiro protagonist gravatar image

updated 2017-03-28 19:37:56 +0200

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 19:40:51 +0200 )edit
kcrisman gravatar imagekcrisman ( 2017-03-28 19:41:13 +0200 )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 08:39:17 +0200 )edit

No worries!

kcrisman gravatar imagekcrisman ( 2017-03-29 13:04:15 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2017-03-28 23:13:34 +0200

ndomes gravatar image

updated 2017-03-28 23:19:20 +0200

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

1

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-29 02:47:52 +0200 )edit

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

hiro protagonist gravatar imagehiro protagonist ( 2017-03-29 08:40:27 +0200 )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 13:03:56 +0200 )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 14:33:38 +0200

Seen: 391 times

Last updated: Mar 28 '17