Maple can use exact arithmetic, where rational numbers are expressed as fractions and irrational numbers are expressed using symbolic expressions such as , or floating-point arithmetic, where numbers such as are expressed using a certain number of decimal places. It is often important to decide which of these is more appropriate in a particular problem. Often there is a tradeoff to consider: exact arithmetic avoids any problems of roundoff error, but can be much slower than floating-point and may result in very complicated expressions.

The following is an example of exact arithmetic. To save space, the result has been deleted from this help page: it is a fraction where both numerator and denominator have 15710 digits. This example should be no problem to calculate (except that it takes more than one screen to write), but it is easy to construct similar examples that will use up all available memory or take a very long time to compute.

> (1+1/4321)^4321;

> (1+1./4321)^4321;

This is calculated very quickly, and the answer is in a much more convenient form.

The main disadvantage of floating point arithmetic is roundoff error. The calculation above is one in which the roundoff error is rather severe, due to the fact that we are adding a relatively small number ( 1./4321=.0002314279102 ) to a relatively large one ( 1 ), and losing significant digits in the process. This can be remedied by doing the calculation with a larger setting of the environment variable Digits , which controls the number of decimal digits used in the calculation.

> Digits:= 15:
r:= (1+1./4321)^4321:
Digits:= 10:
evalf(r);

There are some cases, however, in which even a very accurate floating-point approximation is no good, and exact arithmetic is necessary. Suppose, for example, we want to calculate where is some function and some number with as . Maple may be able to calculate it correctly if is given as an exact expression. But if instead you give Maple an inexact floating-point approximation of the correct , it will tell you that . This is in a sense perfectly correct (because approaches some finite number as ), but it is not what you wanted.

> f:= x -> 1/sin(x):
limit(f(x)*(x-Pi), x = Pi);

> b:= evalf(Pi,20);

> limit(f(x)*(x-b), x = b);

Similarly, suppose A is a matrix with eigenvalue a , and you want to find the corresponding eigenvectors. You can use kernel(A-a) if a is exact, but this will not work if it is only a floating-point approximation.

> with(linalg):

Warning, new definition for norm

Warning, new definition for trace

> A:= matrix([[1,2,3],[3,1,4],[1,5,9]]);

> evalf(Eigenvals(A));

> kernel(A-.818268536);

In this case you can express the exact eigenvalue as a root of the characteristic polynomial, using RootOf (with a third argument that identifies which root is meant):

> kernel(A-RootOf(charpoly(A,t),t,.818268536));

> evalf(");

However, a better method for large matrices might be to use the optional second argument to Eigenvals to obtain all the eigenvectors, and extract the one you want.

> evalf(Eigenvals(A,'vects'));

> col(vects,1);

See also: Automatic simplification and evalf , Digits , Eigenvals , evalf , Forcing floating-point arithmetic , RootOf , Roundoff error , The meaning of Digits

Maple Advisor Database, R. Israel 1997