ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 23 Apr 2013 01:44:08 -0500Accuracy versus precision of algebraic number calculationshttp://ask.sagemath.org/question/10054/accuracy-versus-precision-of-algebraic-number-calculations/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 thanksTue, 23 Apr 2013 00:27:41 -0500http://ask.sagemath.org/question/10054/accuracy-versus-precision-of-algebraic-number-calculations/Answer by tmonteil for <p>Hi everyone - another very basic question from me ...</p>
<p>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.</p>
<p>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?</p>
<p>Many thanks</p>
http://ask.sagemath.org/question/10054/accuracy-versus-precision-of-algebraic-number-calculations/?answer=14823#post-id-14823Fields 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](http://ask.sagemath.org/question/2402/what-are-the-different-real-numbers-in-sage) 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 ;)
Tue, 23 Apr 2013 01:33:55 -0500http://ask.sagemath.org/question/10054/accuracy-versus-precision-of-algebraic-number-calculations/?answer=14823#post-id-14823Comment by GaryMak for <p>Fields of algebraic nature (like <code>RationalField</code>, <code>NumberField</code>, <code>AlgebraicField</code>, <code>AlgebraicRealField</code>) 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 <code>.parent()</code>. If you get fields like <code>Symbolic Ring</code>, <code>RealDoubleField</code>, <code>RealField</code>, then the algorithm you used did some rounding. You can check that a given field is exact with the <code>.is_exact()</code> method. You could have a look at <a href="http://ask.sagemath.org/question/2402/what-are-the-different-real-numbers-in-sage">this question</a> for a bigger list of fields.</p>
<p>For example, if you try </p>
<pre><code>sage: (1/7)^100000
</code></pre>
<p>you will get an exact rational with a huge denominator, not a floating approximation.</p>
<p>When you speak about having a result like <code>p^100-2</code> instead of <code>p^100</code>, 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,</p>
<pre><code>sage: b = (1/7)^10000000000
RuntimeError: Segmentation fault
</code></pre>
<p>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 ;)</p>
http://ask.sagemath.org/question/10054/accuracy-versus-precision-of-algebraic-number-calculations/?comment=17823#post-id-17823Thank 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!Tue, 23 Apr 2013 01:44:08 -0500http://ask.sagemath.org/question/10054/accuracy-versus-precision-of-algebraic-number-calculations/?comment=17823#post-id-17823