Ask Your Question
2

Set global RealNumber precision in .sage file

asked 2019-09-29 13:03:05 +0100

ytum gravatar image

I want to change the real number precision from 53 to, say, 100.

I found this very similar question: ask.sagemath.org/question/7887/set-global-precision-for-reals/ (sorry it doesn't let me post a link), which says to use R=RealField(100); RealNumber=R

I tried it and it only works for me in the sage commandline, but not in .sage programs. Why is that and how do I get around it?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2019-09-29 14:22:20 +0100

tmonteil gravatar image

Assume your_script.sage starts with R=RealField(100); RealNumber=R. If you run:

 sage: %attach your_script.sage

then the Sage preparsing of the file is done before the execution of the file, hence the RealNumberwhich is used is the default one, that is with 53 bits of precision. See https://doc.sagemath.org/html/en/refe... about preparsing.

Instead, if your run:

 sage: %load your_script.sage

The preparsing is done during the execution, hence the RealNumber which is used is the one defined at the beginning of the script, that is with 100 bits of precision.

edit flag offensive delete link more

Comments

Thanks a lot, this makes perfect sense! The way I was running the script was with sage "my_script.sage" directly in the linux commandline, but that logically enough also preparses before execution.

ytum gravatar imageytum ( 2019-09-29 20:34:09 +0100 )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

1 follower

Stats

Asked: 2019-09-29 13:03:05 +0100

Seen: 652 times

Last updated: Sep 29 '19