Ask Your Question

Accuracy versus precision of algebraic number calculations

asked 2013-04-23 00:27:41 -0600

GaryMak gravatar image

updated 2015-07-31 11:16:36 -0600

FrédéricC gravatar image

Hi everyone - another very basic question from me ...

I am doing some calculations of absolute norms of determinants of matrices whose entries come from cyclotomic fields. The (rational) numbers which are output are sensible but occasionally have massive prime numbers as factors which I was not expecting. My question is whether I can rely upon such numbers when they are output by SAGE's calculations inside a specified number field, or whether somewhere along the way some imprecision may have been introduced which results in a "distorted" prime number being a factor of the output.

Another stylized way of asking the same thing: is it possible that the answer to some question involving a small prime p might actually contain a factor of p^100, but nevertheless because of accumulated rounding errors etc I have ended up with p^100-2 which happens to be prime? Or does SAGE "know" only to output perfect answers involving algebraic number fields, even when the heights involved are that big?

Many thanks

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2013-04-23 01:33:55 -0600

tmonteil gravatar image

Fields of algebraic nature (like RationalField, NumberField, AlgebraicField, AlgebraicRealField) are assumed to be exact, hence no rounding is done there. You can check that there was no conversion done along the algorithm you used by testing you result with the method .parent(). If you get fields like Symbolic Ring, RealDoubleField, RealField, then the algorithm you used did some rounding. You can check that a given field is exact with the .is_exact() method. You could have a look at this question for a bigger list of fields.

For example, if you try

sage: (1/7)^100000

you will get an exact rational with a huge denominator, not a floating approximation.

When you speak about having a result like p^100-2 instead of p^100, maybe you want to speak about overflow problems, not rounding problems. This could happen if you don't have enough memory, but then you you should get an error, not a wrong answer. For example,

sage: b = (1/7)^10000000000
RuntimeError: Segmentation fault

Note also that relying on the result does not only depend on whether roundings and overflow may happen, but also related to the existence of bugs in Sage, if you are convinced Sage didn't give you the right result, maybe you found one, so please report it ;)

edit flag offensive delete link more


Thank you very much - I hadn't noticed your previous question sorry. That clarifies it - in effect what I was asking was the bit about segmentation fault - and indeed the fields I am using do return "True" for the question F.is_exact(). As you intimate though, I still have my doubts about there not being a bug, so I am going to implement some cross-referencing type tests and see whether I am truly getting these absurdly large primes!

GaryMak gravatar imageGaryMak ( 2013-04-23 01:44:08 -0600 )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


Asked: 2013-04-23 00:27:41 -0600

Seen: 359 times

Last updated: Apr 23 '13