First time here? Check out the FAQ!

Ask Your Question
2

Set global RealNumber precision in .sage file

asked 5 years ago

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?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
3

answered 5 years ago

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.

Preview: (hide)
link

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 ( 5 years ago )

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: 5 years ago

Seen: 749 times

Last updated: Sep 29 '19