Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.