Ask Your Question
1

[Numerical Approx /RealField] The maximum number of digits ?

asked 2022-06-23 14:48:42 +0200

Mimi gravatar image

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.

edit retag flag offensive close merge delete

Comments

Pas de maximum. Merci de donner un exemple précis de calcul voulu.

FrédéricC gravatar imageFrédéricC ( 2022-06-25 08:44:15 +0200 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2022-06-27 16:46:56 +0200

dan_fulea gravatar image

The 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.

edit flag offensive delete link more

Comments

Ok 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).

:)

Mimi gravatar imageMimi ( 2022-06-28 23:22:34 +0200 )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: 2022-06-23 14:48:08 +0200

Seen: 149 times

Last updated: Jun 27 '22