Link explaining types of decimal numbers

40 views
Skip to first unread message

LFS

unread,
Jan 23, 2013, 11:59:47 AM1/23/13
to sage-s...@googlegroups.com
Hi - I would appreciate if someone could point me to a link explaining the difference (if there is a difference) between:

<type 'sage.rings.real_mpfr.RealLiteral'> 
(Here I input x=3.)
<type 'float'>  (Here I input xx=float(3))
<type 'sage.rings.real_mpfr.RealNumber'>  (Here I input 1/x)
.
My page: http://sage.math.canterbury.ac.nz/home/pub/247
Thanks so much, Linda


Robert Bradshaw

unread,
Jan 23, 2013, 2:09:30 PM1/23/13
to sage-s...@googlegroups.com
First, I would recommend reading up on floating point arithmetic. A
cannonical reference is
http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html , but
if that's a bit dense there are many other good sources on the web.

Things get more interesting for Sage, as there are several models for
floating point numbers available depending on the use. In turn these
are

(1) float, created with float(3.0) or 3.0r, which is the native Python
floating point represented by the machine (typically IEEE 754 double
or extended precision), fastest but potentially less accurate and
platform dependant.
(2) sage.rings.real_double.RealDoubleElement, created by RDF(3.0),
which is also IEEE 754 double or extended precision, but has more
sage-specific functionality.
(3) sage.rings.real_mpfr.RealNumber, the default, created by RR(3.0)
or doing arithmetic with 3.0, back by http://www.mpfr.org/ to 53-bits
of precision, accurate rounding on all operations,
platform-independent, but slower than the above
(3b) sage.rings.real_mpfr.RealNumber with alternative precision, e.g.
RealField(1000)(3) for 1000 bits (not digits) of precision.

Less common:

(4) sage.rings.real_mpfi.RealIntervalFieldElement, created by
RIF(3.0), which does arithmetic on intervals (as most real numbers
can't be represented accurately) and can bue used to provide provable
statements of inequality. Can also be arbitrary precision, e.g.
RealIntervalField(1000)(3)
(5) RLF, the real lazy field (mostly used under the hood for coercion
from exact to in-exact domains).
(5) sage.rings.real_mpfr.RealLiteral, which is what you get when
typing 3.0, which stores the typed value to infinite precision and
converts to a fixed precision (53-bit if implicit) upon demand. This
is needed so that RealField(1000)(1.2) is 1.2 to 1000 bits, not just
53 bits (as it would be if 1.2 was parsed to 53 bits then passed in to
RealField(1000)).

For all of the above, see RR?, RDF?, etc. for (lots!) more documentation.

- Robert
> --
> You received this message because you are subscribed to the Google Groups
> "sage-support" group.
> To post to this group, send email to sage-s...@googlegroups.com.
> To unsubscribe from this group, send email to
> sage-support...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sage-support?hl=en.
>
>

LFS

unread,
Jan 23, 2013, 4:13:28 PM1/23/13
to sage-s...@googlegroups.com
Thank-you Robert for answering so thoroughly. I did learn alot from you answer that was very clearly and concisely written.
I should have been a bit more specific. I teach engineering mathematics and basically what I want is floating double precision that doesn't make trouble with Sage functions.
(I want to spend my time teaching the mathematics.) For example, I have used n() to get a number (decimal) answer. But it won't work on any of these objects. Depending on something, Sage will either give me a number or tell me that no such function is available for this type. So I was trying to understand what is the difference between the types. I don't want my kiddies don't get stuck and frustrated on this.
Basically I have gathered that we should use float() for everything. It is reasonably fast, will work with most sage functions, give numeric answers and works on the Chrome or FireFox browser version of Sage on a Windows machine (which is what we have). (It looks like the Fortran double of my day.) Again, I thank you for your time. Linda
Reply all
Reply to author
Forward
0 new messages