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.Thu, 28 Mar 2013 12:36:28 +0100What are the different real numbers in Sage ?https://ask.sagemath.org/question/9950/what-are-the-different-real-numbers-in-sage/No computer can grasp the genuine real numbers, so I am trying to understand
how sage handles them (and going to write a small tutorial about this).
Here is a list of approaching objects i found:
#### Exact subfields of the reals: ####
- QQ = RationalField() The genuine
[rationals](http://www.sagemath.org/doc/reference/rings_standard/sage/rings/rational_field.html).
Denominators can be arbitrary big, the computations are exact, so the rounding
error is only made when approaching a real by a rational, not during furher computations. Notice that the size of the denominators may grow along the computations, which can therefore become very slow.
- NumberField? [number fields](http://www.sagemath.org/doc/reference/number_fields/sage/rings/number_field/number_field.html) described by an irreducible polynomial.
- AA = AlgebraicField() The genuine [algebraic numbers](http://www.sagemath.org/doc/reference/number_fields/sage/rings/qqbar.html). Computations are exact.
- SR = sage.symbolic.ring.SymbolicRing() This is the field made of expressions
like sqrt(2+pi). It handles a lot of real numbers but seems very slow.
Computations are not necessarily exact, since this field contains floating points
real numbers. Is there a way to express any algebraic number in SR ?
- CFF = ContinuedFractionField() reals are represented as a finite list of convergents. Claims it is exact but it actually approaches real numbers by rationals since the list of convergents are finite. However, we could imagine a future version using iterators instead of lists.
> sage: CFF(sqrt(2))^2
> [1, 1, 1491038293021224]
#### Floating point numbers: ####
- RDF = RealDoubleField() Those are the of [double precision floating numbers](http://www.sagemath.org/doc/reference/rings_numerical/sage/rings/real_double.html) the processor. Definitely the fastest, but a rounding is done at each computation.
- RR = RealField() Floating number with arbitrary (still fixed) many bits of
precision. [http://www.sagemath.org/doc/reference/rings_numerical/sage/rings/real_mpfr.html](http://www.sagemath.org/doc/reference/rings_numerical/sage/rings/real_mpfr.html)
Slower than RDF (in particular, atlas won't be used with them). Notice that
changing precision back and forth is a bad idea. Notice that NaN and Infinity belong to RDF and RR.
- RLF = RealLazyField() like RealField() but can wait that the user fixes the precision to get one. [http://www.sagemath.org/doc/reference/rings_numerical/sage/rings/real_lazy.html](http://www.sagemath.org/doc/reference/rings_numerical/sage/rings/real_lazy.html)
> sage: a = RLF(pi)
> sage: RealField(100)(a+2)
> 5.1415926535897932384626433833
- RIF = RealIntervalField() A real number is represented as an interval
containing it, and whose extremities are RealFields elements [http://www.sagemath.org/doc/reference/rings_numerical/sage/rings/real_mpfi.html](http://www.sagemath.org/doc/reference/rings_numerical/sage/rings/real_mpfi.html)
- RLF.interval_field() mixture of the two previous ones.
- sage.rings.real_lazy.LazyAlgebraic
#### Relations between those fields ####
- Two fields approaching the real numbers K and L can be compared using the
function composite_field(K,L), that finds the "best" field containing both K
and L.
> sage: composite_field(RDF,QQbar)
> Complex Double Field
- [Some](http://www.sagemath.org/doc/reference/number_fields/sage/rings/number_field/number_field_morphisms.html)
[maps](http://www.sagemath.org/doc/reference/number_fields/sage/rings/number_field/maps.html)
are also defined to embed an abstract number field into the real line.
- The method [algebraic_dependency()](http://www.sagemath.org/doc/reference/rings_numerical/sage/rings/real_double.html) that allows to guess whether a floating number corresponds to some algebraic number of a given degree.
Is this list complete or am i missing other real representations ? Im i wrong
in the previous descriptions ? Could you order them by speed, by number of
methods available (without coercion) ? Do you have any remark that could help
the beginner to understand the subtilities in the use of those fields in Sage ?
Given an algebraic number, is it faster to work on AA or on a number field (of
smaller dimension) containing it ? Notice that one can find such an associated
number field with the method [as_number_field_element()](http://www.sagemath.org/doc/reference/number_fields/sage/rings/qqbar.html#sage.rings.qqbar.AlgebraicNumber_base.as_number_field_element)
Do you have any hint, striking example, recommandations of use in special cases
that one should like to learn in a tutorial about real numbers ?
tmonteilThu, 28 Mar 2013 12:36:28 +0100https://ask.sagemath.org/question/9950/