We are now at a crossroads in our use of Sage. So far our computations have involved rational numbers: fractions of two integers. Sage is able to work with integers of seemingly unlimited size, and then can work with rational numbers exactly. So all of our computations have been exactly correct so far. In practice, many computations, especially those that originate with data, are not so precise. Then we represent real numbers by floating point numbers. Since the real numbers are infinite, finite computers must fake it with an extremely large, but still finite, collection of numbers. The price we pay is that some computations will be just slightly imprecise when there is no number available that represents the exact answer.
You should now appreciate two problems that occur. If we were to row-reduce a matrix with floating point numbers, there are potentially many computations and if a small amount of imprecision arises in each one, these errors can accumulate and lead to wildly incorrect answers. When we row-reduce a matrix, whether or not an entry is zero or not is critically important in the decisions we make about which row operation to perform. If we have an extremely small number, such as \(10^{-16}\text{,}\) how can we be sure if it is zero or not?
Why discuss this now? What is \(\alpha=\sqrt{7/3}\text{?}\) Hard to say exactly, but it is definitely not a rational number. Norms of vectors will feature prominently in all our discussions about orthogonal vectors, so we now have to recognize the need to work with square roots properly. We have two strategies in Sage.
The number system QQbar
, also known as the field of algebraic numbers, is a truly amazing feature of Sage. It contains the rational numbers, plus every root of every polynomial with coefficients that are rational numbers. For example, notice that \(\alpha\) above is one solution to the polynomial equation \(3x^2-7=0\) and thus is a number in QQbar
, so Sage can work with it exactly. These numbers are called “algebraic numbers” and you can recognize them since they print with a question mark near the end to remind you that when printed as a decimal they are approximations of numbers that Sage carries internally as exact quantities. For example \(\alpha\) can be created with QQbar(sqrt(7/3))
and will print as 1.527525231651947?
. Notice that complex numbers begin with the introduction of the imaginary number \(i\text{,}\) which is a root of the polynomial equation \(x^2+1=0\text{,}\) so the field of algebraic numbers contains many complex numbers. The downside of QQbar
is that computations are slow (relatively speaking), so this number system is most useful for examples and demonstrations.
The other strategy is to work strictly with approximate numbers, cognizant of the potential for inaccuracies. Sage has two such number systems: RDF
and CDF
, which are comprised of double precision floating point numbers, first limited to just the reals, then expanded to the complexes. Double-precision refers to the use of 64 bits to store the sign, mantissa and exponent in the representation of a real number. This gives 53 bits of precision. Do not confuse these fields with RR
and CC
, which are similar in appearance but very different in implementation. Sage has implementations of several computations designed exclusively for RDF
and CDF
, such as the norm. And they are very, very fast. But some computations, like echelon form, can be wildly unreliable with these approximate numbers. We will have more to say about this as we go. In practice, you can use CDF
, since RDF
is a subset and only different in very limited cases.
In summary, QQbar
is an extension of QQ
which allows exact computations, but can be slow for large examples. RDF
and CDF
are fast, with special algorithms to control much of the imprecision in some, but not all, computations. So we need to be vigilant and skeptical when we work with these approximate numbers. We will use both strategies, as appropriate.