Ask Your Question

Revision history [back]

What is a real number 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. 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 described by an irreducible polynomial.

  • AA = AlgebraicField() The genuine algebraic numbers. 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 exact. 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:

sage: a = RLF(pi)

sage: RealField(100)(a+2)

5.1415926535897932384626433833

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 maps are also defined to embed an abstract number field into the real line.

  • The method algebraic_dependency() 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()

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 ?

What is a real number are the different real numberstit 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. 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 described by an irreducible polynomial.

  • AA = AlgebraicField() The genuine algebraic numbers. 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 exact. 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:

sage: a = RLF(pi)

sage: RealField(100)(a+2)

5.1415926535897932384626433833

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 maps are also defined to embed an abstract number field into the real line.

  • The method algebraic_dependency() 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()

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 ?

What are the different real numberstit 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. 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 described by an irreducible polynomial.

  • AA = AlgebraicField() The genuine algebraic numbers. 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 exact. 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:

sage: a = RLF(pi)

sage: RealField(100)(a+2)

5.1415926535897932384626433833

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 maps are also defined to embed an abstract number field into the real line.

  • The method algebraic_dependency() 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()

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 ?

click to hide/show revision 4
add NaN and Infty as elements of RDF and RR

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. 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 described by an irreducible polynomial.

  • AA = AlgebraicField() The genuine algebraic numbers. 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 exact. 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:

sage: a = RLF(pi)

sage: RealField(100)(a+2)

5.1415926535897932384626433833

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 maps are also defined to embed an abstract number field into the real line.

  • The method algebraic_dependency() 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()

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 ?

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. 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 described by an irreducible polynomial.

  • AA = AlgebraicField() The genuine algebraic numbers. 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 exact. 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:

sage: a = RLF(pi)

sage: RealField(100)(a+2)

5.1415926535897932384626433833

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 maps are also defined to embed an abstract number field into the real line.

  • The method algebraic_dependency() 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()

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 ?