ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 28 Jun 2022 23:22:34 +0200[Numerical Approx /RealField] The maximum number of digits ?https://ask.sagemath.org/question/62977/numerical-approx-realfield-the-maximum-number-of-digits/Hello from France,
I would like to know this :
N = digits ;
A = numerical_approx(x, N) ;
What is the maximum for N ?
Litteraly i want to know what is the maximum number of digits possible in sage.
Or the maximum N for :
A = RealField(N)(x)
So the maximum bits précision allowed.Thu, 23 Jun 2022 14:48:08 +0200https://ask.sagemath.org/question/62977/numerical-approx-realfield-the-maximum-number-of-digits/Comment by FrédéricC for <p>Hello from France,</p>
<p>I would like to know this :
N = digits ;
A = numerical_approx(x, N) ;
What is the maximum for N ?</p>
<p>Litteraly i want to know what is the maximum number of digits possible in sage. </p>
<p>Or the maximum N for :
A = RealField(N)(x)
So the maximum bits précision allowed.</p>
https://ask.sagemath.org/question/62977/numerical-approx-realfield-the-maximum-number-of-digits/?comment=62993#post-id-62993Pas de maximum. Merci de donner un exemple précis de calcul voulu.Sat, 25 Jun 2022 08:44:15 +0200https://ask.sagemath.org/question/62977/numerical-approx-realfield-the-maximum-number-of-digits/?comment=62993#post-id-62993Answer by dan_fulea for <p>Hello from France,</p>
<p>I would like to know this :
N = digits ;
A = numerical_approx(x, N) ;
What is the maximum for N ?</p>
<p>Litteraly i want to know what is the maximum number of digits possible in sage. </p>
<p>Or the maximum N for :
A = RealField(N)(x)
So the maximum bits précision allowed.</p>
https://ask.sagemath.org/question/62977/numerical-approx-realfield-the-maximum-number-of-digits/?answer=63032#post-id-63032The answer depends a lot on what `x` is. The code implementing `numerical_approx` is
if prec is None:
from sage.arith.numerical_approx import digits_to_bits
prec = digits_to_bits(digits)
try:
n = x.numerical_approx
except AttributeError:
from sage.arith.numerical_approx import numerical_approx_generic
return numerical_approx_generic(x, prec)
else:
return n(prec, algorithm=algorithm)
So the instance `x` belongs to some class, and the `numerical_approx` method of this class is taken.
To have an example, i will work with `pi` instead of `x`
The used precision is the one accepted by the `RealField` class. For instance:
sage: A = numerical_approx(pi, 1234)
sage: R = A.parent()
sage: R.precision()
1234
sage: R
Real Field with 1234 bits of precision
sage: R == RealField(1234)
True
So we go to the documentation of that constructor...
?RealField
Docstring:
RealField(prec, sci_not, rnd):
INPUT:
* "prec" -- (integer) precision; default = 53 prec is the number of
bits used to represent the mantissa of a floating-point number.
The precision can be any integer between "mpfr_prec_min()" and
"mpfr_prec_max()". In the current implementation,
"mpfr_prec_min()" is equal to 2.
and so on. We have to accept this, beliving that the imand the corresponding function gives...
sage: from sage.rings.real_mpfr import mpfr_prec_max
sage: mpfr_prec_max()
9223372036854775551
The implementer was really generous. For my purposes, i still have to use numbers that can be represented on my box that i take with me every day in the train... Some 1GB-numbers were never my focus, well, it is the reason and the effect of the fact that i am doing only exact mathematics in the sense of
sage: Q = RationalField()
sage: Q.is_exact()
True
sage: R = RealField()
sage: R.is_exact()
False
So from the point of view where i stay, try to always do exact computations as long as exact computations are possible. When approximations are needed (and i do need them e.g. when searching for algebraic relations among values of polylogarithms), start with some small precision (like $100$ or $10000$ if $100$ does not work) and manually raise it.
Mon, 27 Jun 2022 16:46:56 +0200https://ask.sagemath.org/question/62977/numerical-approx-realfield-the-maximum-number-of-digits/?answer=63032#post-id-63032Comment by Mimi for <p>The answer depends a lot on what <code>x</code> is. The code implementing <code>numerical_approx</code> is</p>
<pre><code>if prec is None:
from sage.arith.numerical_approx import digits_to_bits
prec = digits_to_bits(digits)
try:
n = x.numerical_approx
except AttributeError:
from sage.arith.numerical_approx import numerical_approx_generic
return numerical_approx_generic(x, prec)
else:
return n(prec, algorithm=algorithm)
</code></pre>
<p>So the instance <code>x</code> belongs to some class, and the <code>numerical_approx</code> method of this class is taken.</p>
<p>To have an example, i will work with <code>pi</code> instead of <code>x</code>
The used precision is the one accepted by the <code>RealField</code> class. For instance:</p>
<pre><code>sage: A = numerical_approx(pi, 1234)
sage: R = A.parent()
sage: R.precision()
1234
sage: R
Real Field with 1234 bits of precision
sage: R == RealField(1234)
True
</code></pre>
<p>So we go to the documentation of that constructor...</p>
<pre><code>?RealField
Docstring:
RealField(prec, sci_not, rnd):
INPUT:
* "prec" -- (integer) precision; default = 53 prec is the number of
bits used to represent the mantissa of a floating-point number.
The precision can be any integer between "mpfr_prec_min()" and
"mpfr_prec_max()". In the current implementation,
"mpfr_prec_min()" is equal to 2.
</code></pre>
<p>and so on. We have to accept this, beliving that the imand the corresponding function gives...</p>
<pre><code>sage: from sage.rings.real_mpfr import mpfr_prec_max
sage: mpfr_prec_max()
9223372036854775551
</code></pre>
<p>The implementer was really generous. For my purposes, i still have to use numbers that can be represented on my box that i take with me every day in the train... Some 1GB-numbers were never my focus, well, it is the reason and the effect of the fact that i am doing only exact mathematics in the sense of</p>
<pre><code>sage: Q = RationalField()
sage: Q.is_exact()
True
sage: R = RealField()
sage: R.is_exact()
False
</code></pre>
<p>So from the point of view where i stay, try to always do exact computations as long as exact computations are possible. When approximations are needed (and i do need them e.g. when searching for algebraic relations among values of polylogarithms), start with some small precision (like $100$ or $10000$ if $100$ does not work) and manually raise it.</p>
https://ask.sagemath.org/question/62977/numerical-approx-realfield-the-maximum-number-of-digits/?comment=63049#post-id-63049Ok thanks you a lot for your reponse , i'm trying to calculate millions of digits of pi.
I've calculated millions of digits , and i compare them to the Sage's pi .
That's why i asked to know for example the maximum for x :> pi.n(digits = x).
:)Tue, 28 Jun 2022 23:22:34 +0200https://ask.sagemath.org/question/62977/numerical-approx-realfield-the-maximum-number-of-digits/?comment=63049#post-id-63049