MACSYMA from F to Gt
Total Page:16
File Type:pdf, Size:1020Kb
J. Symbolic Computation (1985) 1, 69-100 MACSYMA from F to Gt RICHARD PAVELLE~ AND PAUL S. WANG§ ~Symbolics Inc., 11 Cambridge Center, Cambridge, Massachusetts 02142, USA and §Department of Mathematical Sciences, Kent State University, Kent, Ohio 44242, USA (Received 14 January 1985) A descriptive, non-technical tutorial on MACSYMA,a well-known and widely used Computer Algebra system, is presented. Several examples of its capabilities are exhibited using actual MACSYMA input and output. A discussion of computer-based symbolic mathematical computation is motivated by pointing out inherent difficulties with familiar numeric computations. The inner workings of Computer Algebra systems are briefly discussed in addition to some on-going work on MACSYMAand future directions. 1. Introduction In this first article on Computer Algebra systems, for the Journal of Symbolic Computation, we are faced with a dilemma. We intend to present a descriptive, non- technical tutorial on MACS','MA, a well-known and widely used Computer Algebra system. However, many readers will likely know little about our field and will be familiar only with traditional (numeric) computing techniques. Therefore our approach will be to provide a short discussion on the inherent difficulties involved with floating-point computations as motivation for further discussion on computer-based symbolic mathematical computation. We shall then touch on the inner workings of Computer Algebra systems. After these general discussions we shall concentrate on the capabilities of ~ACSVMA and present several examples. We will conclude with a brief discussion of current directions. While this paper is directed towards MACSVMA, the development of Computer Algebra systems has been the result of an international effort. There are many systems, world- wide, of various sizes and designs which have been developed over the past 15 to 20 years (van Hulzen & Calmer, 1983). Research related to the development of these systems has lead to new results in mathematics and algorithms. These results in turn helped the development of MACSYMA as well as other systems. Computer Algebra systems~C are large software programs which compute with numbers, symbols, and formulas. These systems vary greatly in their capabilities, and there is a great deal of information available on them (Pavelle et al., 1981; Yun & Stoutemeyer, 1980). They are now important research tools and a daily resource for many engineers and scientists. They are characterised by exact computation rather than numeric t Work reported herein has been supported in part by the US National Aeronautics and Space Administration under Grant NAG 3-298 and by the US National Science Foundation under Grant MCS-82-01239 and by the Department of Energy under Grant DE-ACO2-ER760275-AO13. ~: We prefer to call these "Computer Algebra" systems but they are commonly called "Algebraic Manipulation" systems, "Algebraic Computation" systems, "Symbolic Manipulation" systems and "Symbolic Mathematical" systems. 0747-7171/85/010069+32 $03.00/0 © 1985 Academic Press Inc. (London) Ltd 70 Richard Pavelle and Paul S. Wang approximation. These systems perform the kind of computations people are trained to do using pencil and paper. Some calculations which took decades to do by hand now take hours or indeed seconds. These Computer Algebra systems can manipulate complicated formulas and return answers in terms of symbols and formulas as well as numbers. With these revolutionary tools computing will never be the same again. It is our hope that information provided here will create new users of Computer Algebra systems by showing what one might expect to gain by using them and what one will lose by not using them. 2. Symbolic and Numeric Computations The two broad categories of scientific computation are numeric and symbolic. Numeric computation signifies that a computer is used as a number cruncher. Many problems can be cast in such a way that its solution calls for nothing more than repeated computations with numbers or the processing of numeric data. In numeric computation, a computer system is used to carry out calculations only with numbers. On the other hand we now have Computer Algebra systems available which perform symbolic computation and these crunch symbols. The purpose of Computer Algebra systems is to compute with symbols, equations, and operators as well as with numbers. As we shall show, modern Computer Algebra systems perform many highly sophisticated computations that will amaze people who use mathematical tools. Computer Algebra systems emphasise exactness in the calculations while numeric systems operate on numbers that are as nearly correct as the precision of the computer system allows. Both approaches are important for the solution of problems, but for many calculations Computer Algebra systems offer enormous advantages over numeric systems. 2.1 ACCURACY OF NUMERIC COMPUTATIONS In typical examples of numeric computation one computes with floating-point numbers. The number of places retained after the decimal point, the precision, is usually dependent on the computer system used. In our examples, for the purposes of discussion, we shall assume a precision of six digits. To maintain speed of operation with floating-point numbers the precision is usually fixed. For many applications numeric approximations are accurate enough to provide reasonable answers but often they are not. Because of the limited precision, numbers such as 1/3 carry a built-in error called "roundoff error". When we add the fractions 1/3 + I/3 + 1/3 we obtain 1/3 + 1/3 + 1/3 = 1 In floating-point arithmetic, however, we have 0.333333 +0.333333 +0.333333 = 0.999999 instead of 1.0. While this example is trivial it points out that numeric systems will often give the wrong answer while all modern Computer Algebra systems can add rational numbers properly. Consider now 2/3 which is represented as the floating-point number 0.666667. What is 0,666667-0.333333? It is, of course, 0.333334. Therefore we see that 1/3 is equally well represented by 0.333334 as well as by 0.333333. A point one must remember is that when large numbers of operations are done with floating-point numbers, one must be very careful. The magnitude of the errors generated by roundoff can actually be greater than MACSYMA from F to G 71 the answer one seeks. The users of numeric systems understand many of these difficulties and have developed procedures for dealing with these problems (Knuth, 1980). However, they are expensive in terms of human and machine resources. Here is another example which provides a way to manufacture "hard" problems for floating-point systems. Consider the expression UVWXY-(UVW) ll3(vW..~Oll3(W)fY)tI3(UXy)II3(UVY)113, where U, V, W, X and Y are positive integers. This expression is identically zero. However, a numeric system uses floating-point arithmetic and will produce a number which can differ greatly from zero. For example, if the consecutive prime numbers 7919, 7927, 7933, 7937, 7949 are chosen, the floating-point result (using 16 digit precision) is 512.0 which is not even close to zero. In fact, one can always choose the five integers to be sufficiently large such that any fixed degree of precision will give a roundoff error. And the magnitude of the error can be made as large as one wishes by chooging sufficiently large integers. Another class of problems poses greater difficulties to numeric systems. Consider sqrt(-2*log (cos(u"2)))/u~'2, and suppose we are interested in values of this expression as u approaches 0. Numeric systems tend to evaluate this expression to 0, whereas the answer, found taking the limit or the Taylor series about the origin, is 1. In fact, with MACSYMA,it is readily found that sqrt(-2*log (cos (u~2)))/td2 = 1 + u^4/12 + 3*u ^ 8/160 + .... In addition to accuracy problems, resulting from keeping a fixed number of significant digits, we shall now see that some familiar mathematical operations actually lose their inherent properties. 2.2 ASSOCIATIVITYPROPERTY AND FLOATING-POINTNUMBERS The familiar mathematical operations plus, "+ ", and times, "*" satisfy "associativity". This means that if one wants to compute A + B + C, it can be done by either (A +B) + C or A + (B + C) and the result obtained is always ihe same. similarly, for the multiplication operator, A*(B*C)= (A*B)*C. Most of the common mathematical operations we are accustomed to satisfy associativity. However, for floating-point numbers, this all- important property is no longer valid for either addition or multiplication. Let us retain 6-digit accuracy and consider the computation which adds the numbers 111113.-111111.+5.51111. We can perform it as (111113.-[11111.)+5.51111 = 2.00000+5.51111 = 7.51111 and obtain one answer. Or we can perform it as 111113.+(-111111.+5.51111) = 111113.-111105. = 8.00000 to obtain a different answer. Which is correct? They both are correct and this is another difficulty with floating-point numbers. There are many other examples of this too. Given a matrix whose entries are floating-point numbers suppose one computes the inverse. It is often the case that the matrix product of the matrix and its inverse will not be the identity matrix. Further, some matrices which are almost singular cannot be inverted at all by numerical Systems. These diffÉculties further motivate the use of Computer Algebra systems which provide exact operations with numbers and mathematical expressions. 72 Richard Pavelle and Paul S. Wang 2.3 NUMERIC FEATURES OF COMPUTER ALGEBRA SYSTEMS Modern Computer Algebra systems perform exact computations with integers, rational numbers and symbolic expressions. In a Computer Algebra system, one can deal with integers of arbitrary size. The integer 200! (two hundred factorial) can be handled just as easily as 20. Fractions as I/3 and irrational numbers such as SQRT(2) are all kept exact rather than turned into floating-point numbers.