5 @modify(heading,above 2)
8 Massachusetts Institute of Technology
11 Laboratory for Computer Science
12 Cambridge, Massachusetts 02139
14 A Brief Overview of MACSYMA
19 @CopyrightNotice(Massachusetts Institute of Technology)
23 MACSYMA is a large, interactive computer system, designed to
24 assist mathematicians, scientists, and engineers in solving
25 mathematical problems. It has a wide range of algebraic manipulation
26 capabilities where a user supplies symbolic inputs and MACSYMA yields
27 symbolic results. In addition a user has, at his disposal, an
28 extensive numerical subroutine library (IMSL) and plotting package.
30 The MACSYMA system has been under continual development at MIT
31 since 1969 under the direction of Professor Joel Moses.
32 Over 100 man years of effort have gone into the development of MACSYMA. The
33 current system consists of about 230,000 words of LISP code, as well as
34 hundreds of pages of MACSYMA code written by its users.
36 MACSYMA is extensively used by hundreds of researchers from government
37 laboratories, universities, and private companies throughout the U.S. There are
38 users in Europe and Canada as well. Many
39 of these users spend a substantial portion of every day logged in. MACSYMA's
40 funding is supplied almost exclusively by its user community.
42 This brief overview is intended to acquaint the reader with the
43 nature of MACSYMA as a large, interactive mathematical computing environment.
44 It sketches the range of capabilities available and introduces a number of
45 issues arising in symbolic manipulation.
47 Various commands are necessary to get connected to MACSYMA.
48 Once these commands have been carried out, the user is presented with a
49 MACSYMA "C-line", or command line, at which point he may enter his expressions.
50 C-lines are typed by the user, and D-lines, or display lines,
51 are MACSYMA's response. A line
52 may be terminated either by a ";" or a "$". If the latter is used, the
53 display is suppressed. Expressions are entered in linear form, using
54 ALGOL-like notation; and MACSYMA redisplays them in conventional
55 two-dimensional mathematical notation.
68 Note that the result in line D1 is a symbolic expression
69 that can be passed around and manipulated as a data structure.
70 For example, the user can add it to itself. At MACSYMA's command
71 level, "%" refers to the expression designated by the last D-line.
81 Notice the simplification. MACSYMA could have left the
82 result as a sum but instead recognized that the summands were
83 identical and added them together. MACSYMA automatically performs many
84 such "obvious" simplifications.
86 MACSYMA accepts transcendental functions as well as simple
87 rational functions and can apply identities about such functions to
88 produce simpler forms. Take, for example, the simplification in line D4 below
89 where the symbols %PI, %E, and %I are MACSYMA's version of the corresponding
90 mathematical constants pi, e = the base of the natural logarithm, and the
102 An important requirement for an algebraic manipulation system
103 is the ability to represent expressions in several different forms.
104 For example, the expression in line C5 can be written either as shown in
105 D5 or as in D6. Unlike some other systems, MACSYMA permits the user
106 to represent his expressions in whatever form is convenient and provides
107 a host of explicit transformations to convert between them, e.g. the
108 EXPAND command in line C6.
119 (D6) X + 30 X + 405 X + 3240 X + 17010 X
122 + 61236 X + 153090 X + 262440 X + 295245 X
128 Part of MACSYMA's mathematical knowledge is the ability to
135 (D7) 10 X + 270 X + 3240 X + 22680 X + 102060 X
138 + 306180 X + 612360 X + 787320 X + 590490 X
144 Looking at the first term, this answer appears to be correct,
145 but the other terms are more complicated. One can easily check the
146 answer by factoring. FACTOR is guaranteed to find the factorization of
147 any multivariate rational function (over the real integers) if it exists.
155 Another built-in mathematical ability is indefinite integration much
156 of which is performed algorithmically.
157 The integration package, called SIN (for @u[S]ymbolic @u[In]tegrator),
158 was written by Joel Moses and incorporates the non-algebraic case of the Risch
159 integration algorithm. Consider the expression defined in D1:
170 (C10) INTEGRATE(%,X);
173 LOG(X - X + 1) SQRT(3) LOG(X + 1)
174 (D10) --------------- + ------------- - ----------
178 In contrast with numerical problem solving, in symbolic
179 manipulation one can often check one's answers by applying the
180 inverse operator, in this case differentiation.
185 (D11) ------------------ + -------------- - ---------
187 (2 X - 1) 6 (X - X + 1)
192 This answer is not identical to the integrand. The reason
193 is that MACSYMA merely differentiated term by term. As stated earlier,
194 MACSYMA automatically applies only those simplification rules which are
195 "obvious" and always desirable. A given rule may sometimes make an
196 expression smaller and sometimes larger. In such cases, MACSYMA leaves
197 the decision to the user. In this case the integrand can be recovered by
198 rational simplification of the result with the RATSIMP command.
208 The SIN program is familiar with several special functions, such
209 as the error function, and tries to write integrals in terms of them when
210 possible. When no such "closed form" answer can be obtained, INTEGRATE
211 simply returns a symbolic form of the integral. Here, the example is
212 a definite integration from 1 to 2. For handling such cases, MACSYMA
213 also provides numerical integration via the ROMBERG algorithm.
216 (C13) INTEGRATE(%E^X^3,X,1,2);
227 (C14) ROMBERG(%E^X^3,X,1,2);
232 When computing exact solutions is intractable, one can often
233 resort to series approximations. MACSYMA has an excellent Taylor series
234 program. One can obtain truncated series representations for SIN(X) and COS(X)
235 as follows. The arguments to the TAYLOR command are the expression to
236 be expanded, the variable of expansion, the point around which the
237 expansion is to be done, and the highest degree term to be retained.
240 (C15) TAYLOR(SIN(X),X,0,5);
243 (D15)/T/ X - -- + --- + . . .
248 (C16) TAYLOR(COS(X),X,0,5);
251 (D16)/T/ 1 - -- + -- + . . .
255 A truncated series is denoted by the "/T/" next to the line
256 label and the trailing dots. MACSYMA retains certain information
257 about such expressions, such as the "quality" of the approximation, so
258 that when several series are combined, no terms are computed beyond the
259 degree of the approximation. In the example below, the X@+(4) and X@+(5)
260 in the input series would produce a term in X@+(9); but, since the inputs
261 are only good to the fifth degree, no higher order terms are computed.
262 Here, the %TH(n) refers to the nth to last line.
268 (D17)/T/ X - ---- + ---- + . . .
272 Actually, the term "Taylor series" is only an historic artifact.
273 The TAYLOR program can also handle functions with poles and branch points
274 and automatically generates Laurent series when appropriate.
277 (C18) TAYLOR(1/(COS(X)-SEC(X))^3,X,0,5);
279 1 1 11 347 6767 X 15377 X
280 (D18)/T/ - -- + ---- + ------ - ----- - ------- - -------- + ...
281 6 4 2 15120 604800 7983360
285 The SOLVE command is used to find the roots of certain
286 polynomial equations. Not all equations can be solved in terms of
287 simple radicals, but whenever SOLVE can find exact roots, it
288 returns them as a list. Here, the equation has 6 roots.
294 SQRT(3) %I + 1 SQRT(3) %I - 1
295 (D19) [X = --------------, X = --------------, X = - 1,
298 SQRT(3) %I + 1 SQRT(3) %I - 1
299 X = - --------------, X = - --------------, X = 1]
303 One can check that these are in fact roots by plugging
304 in for X and simplifying. The simplest way to do this is with the ","
305 syntax. The expression to the left of the comma is simplified in the
306 environment defined by the items to the right of the comma. Here,
307 the input to SOLVE is simplified in an environment in which the first
308 equation is true. After expansion, the result is 0.
311 (C20) X^6-1,FIRST(%);
314 (D20) ----------------- - 1
322 SOLVE also works on systems of equations. The result is a list
323 of a list of solutions, since there may be more than one solution set in
327 (C22) SOLVE([A*X+B*Y=0,C*X+D*Y=1],[X,Y]);
330 (D22) [[X = ---------, Y = - ---------]]
334 These are just a few of the mathematical functions defined
335 in MACSYMA. There are many more, but the examples above
336 hopefully illustrate the type of capabilities available. In addition to
337 algebraic expressions, MACSYMA also deals with other symbolic data types,
338 viz. vectors, matrices, tensors, equations and inequalities, strings, and even
339 code. When entering a matrix, for example, one applies the MATRIX command to
340 the rows of the matrix to be constructed.
343 (C23) MATRIX([A,B,C],[D,E,F],[G,H,I]);
352 All the usual matrix operations are defined, e.g. transpose,
353 determinant, inverse, echelon form, triangular form, etc. In the following
354 lines, the above matrix is multiplied by its transpose.
368 [ G + D + A G H + D E + A B G I + D F + A C ]
371 [ G H + D E + A B H + E + B H I + E F + B C ]
374 [ G I + D F + A C H I + E F + B C I + F + C ]
377 The operator "." denotes matrix multiplication. If the "*"
378 operator had been used, the matrices would have been multiplied
382 (C26) MATRIX([X^2,X,1],[Y^2,Y,1],[Z^2,Z,1]);
393 This is the familiar Vandermonde matrix. Its determinant has
394 the interesting property that it is the product of the differences of
395 the variables involved. This is a property that would not normally be
396 observed in a purely numerical system.
399 (C27) DETERMINANT(%);
401 (D27) - Y Z - X (Y - Z ) + Y Z + X (Y - Z)
405 (D28) - (Y - X) (Z - X) (Z - Y)
408 All the operations presented so far have been concerned with
409 the form of their arguments. However, certain other operations and
410 simplifications depend not only on the form but also the meaning of
411 the symbols involved. For example, MACSYMA returns the
412 expression in line C29 unchanged. Although the variable N may look like an
413 integer to us, MACSYMA sees it as just an ordinary symbol that can take
414 on any value. By declaring N to be an odd integer, one can get MACSYMA
415 to simplify D29 to 0.
424 (C30) DECLARE(N,ODD)$
430 Note that what the user has told MACSYMA is partial information
431 about N, not a specific value. Similarly, one can declare partial
432 information about functions.
439 (C33) DECLARE(F,LINEAR)$
445 MACSYMA has many simplification rules built in. As was remarked
446 earlier, not all these rules are automatically applied. However, the user
447 can enable most rules by setting a "switch" to TRUE. For example, the rule
448 which converts trigonometric functions of sums to expressions
449 involving only trigonometric functions of terms is called TRIGEXPAND
450 and can be enabled as shown in line C36.
457 (C36) TRIGEXPAND:TRUE$
460 (D37) COS(X) COS(Y) - SIN(X) SIN(Y)
463 (C38) TRIGEXPAND:FALSE$
466 Setting TRIGEXPAND to FALSE turns the rule off again. In contrast
467 with such dormant rules, which must be explicitly turned on, there are
468 also default rules, which the user can turn off.
482 Users can also define rules of their own. For example,
483 in order to define the exponential simplification rule above,
484 one could use the TELLSIMP command. After defining this rule,
485 the previous simplification occurs, but this time due to the
486 user-defined rule not the built-in one.
489 (C42) TELLSIMP(%E^(%I*%PI),-1)$
495 MACSYMA is also a full programming language, allowing
496 recursive function definitions, conditionals, iterations, block
497 statements, etc. As an example, consider the task of defining
498 the factorial function. MACSYMA already has a factorial operator,
499 as shown, but factorial is a good simple example. (Note, incidentally,
500 that there is no limit on the size of integers.) To define a function,
501 one uses the ":=" operator.
505 (D44) 933262154439441526816992388562667004907159682643816214#
507 685929638952175999932299156089414639761565182862536979208272#
509 23758251185210916864000000000000000000000000
512 (C45) FAC(N):=IF N=0 THEN 1 ELSE N*FAC(N-1);
513 (D45) FAC(N) := IF N = 0 THEN 1 ELSE N FAC(N - 1)
519 This programming ability has been of great value to MACSYMA.
520 A significant percentage of the available mathematical capabilities
521 were written in the MACSYMA language by users.
523 Although MACSYMA uses single precision floating point arithmetic
524 as the default, it also has the capability of unlimited precision
525 arithmetic. For example, to get 50 digits of %PI, one can simply set
526 the precision variable to 50 and then use BFLOAT.
532 (D48) 3.1415926535897932384626433832795028841971693993751B0
535 MACSYMA's numerical capabilities are currently quite powerful,
536 and the future holds even more promise in this direction. The IMSL subroutine
537 library has recently become available as part of MACSYMA. In addition,
538 there is a FORTRAN to MACSYMA translator which can modify
539 already existing FORTRAN code for use with MACSYMA.
541 There is an extensive plotting package to
542 help users view the results of their numerical computations.
543 The package's capabilities include two-dimensional, contour, parametric,
544 and three-dimensional plotting.
546 In summary, MACSYMA is a large interactive system for
547 solving mathematical problems requiring computer-based algebraic
548 manipulation, numerical computation, or plotting. There is a
549 large amount of mathematical knowledge already built-in, and MACSYMA
550 is an "operator-based" system for use as a extremely sophisticated