Ask Your Question

Revision history [back]

Hello,

As Eviatar said, it would be very nice to have it in Sage documentation! Here are some more remarks.

1) There are three nice methods to get from RR to QQ:

sage: a = RR(1.2254)
sage: a.simplest_rational()
6127/5000
sage: a.exact_rational()
2759355491689903/2251799813685248
sage: a.nearby_rational(max_error=0.0001)
87/71

Note that .nearby_rational() implements its own continued fraction algorithm.

2) There should be a huge warning for comparison of elements from different fields of real numbers::

sage: pi_rlf = RLF(pi)
sage: pi_rr = RR(pi)
sage: pi_rlf
3.141592653589794?
sage: pi_rr
3.14159265358979

sage: pi_rlf == pi_rr
True
sage: RLF(pi_rr) == pi_rlf
False

More generally, if you intend to make some documentation, it may be very useful to have a two dimensional array which says given x from field F1 and y from field F2 where is made the comparison x == y.

3) RIF is especially useful to locate roots of a polynomial. Actually, AA uses RIF with various precisions in background (which is essential for comparisons):

sage: a = AA(sqrt(2) + sqrt(3) + sqrt(7))
sage: a._value.parent()
Real Interval Field with 64 bits of precision
sage: a.interval_diameter(2**-20)
5.792015681006562933?
sage: a.interval_diameter(2**-70)
5.7920156810065629328307508193548308713?
sage: a._value.parent()
Real Interval Field with 128 bits of precision

There is a big difference between AA and number fields: number fields, even with a specified embedding, are not able to make comparisons (but you may have a look at tickets #13213 and #7160).

4) SR contains much more than numbers:

sage: sin(x).parent()
Symbolic Ring

And there is a wrapper for symbolic numbers to make them an element of RLF:

sage: log(2).parent()
Symbolic Ring
sage: log2 = RLF(log(2))
sage: log2
0.6931471805599453?

But which does not work quite well:

sage: exp(log2) == 2
False

Vincent

Hello,

As Eviatar said, it would be very nice to have it in Sage documentation! Here are some more remarks.

0) RLF is not a floating point field but an exact field: those are real numbers with an arbitrary precision. But as said in the documentation, it is mostly used as an "intermediate" field between number fields and all different floating point fields.

1) There are three nice methods to get from RR to QQ:

sage: a = RR(1.2254)
sage: a.simplest_rational()
6127/5000
sage: a.exact_rational()
2759355491689903/2251799813685248
sage: a.nearby_rational(max_error=0.0001)
87/71

Note that .nearby_rational() implements its own continued fraction algorithm.

2) There should be a huge warning for comparison of elements from different fields of real numbers::

sage: pi_rlf = RLF(pi)
sage: pi_rr = RR(pi)
sage: pi_rlf
3.141592653589794?
sage: pi_rr
3.14159265358979

sage: pi_rlf == pi_rr
True
sage: RLF(pi_rr) == pi_rlf
False

More generally, if you intend to make some documentation, it may be very useful to have a two dimensional array which says given x from field F1 and y from field F2 where is made the comparison x == y.

3) RIF is especially useful to locate roots of a polynomial. Actually, AA uses RIF with various precisions in background (which is essential for comparisons):

sage: a = AA(sqrt(2) + sqrt(3) + sqrt(7))
sage: a._value.parent()
Real Interval Field with 64 bits of precision
sage: a.interval_diameter(2**-20)
5.792015681006562933?
sage: a.interval_diameter(2**-70)
5.7920156810065629328307508193548308713?
sage: a._value.parent()
Real Interval Field with 128 bits of precision

There is a big difference between AA and number fields: number fields, even with a specified embedding, are not able to make comparisons (but you may have a look at tickets #13213 and #7160).

4) SR contains much more than numbers:

sage: sin(x).parent()
Symbolic Ring

And there is a wrapper for symbolic numbers to make them an element of RLF:

sage: log(2).parent()
Symbolic Ring
sage: log2 = RLF(log(2))
sage: log2
0.6931471805599453?

But which does not work quite well:

sage: exp(log2) == 2
False

Vincent