by Jim Flanagan

The computer, if I remember my history lesson correctly in this, our baroque age of computing, was born of a need to do arithmetic computations at high speeds — speeds which are affable by contemporary measure.

Today, while computers are able to fit upon our desktop, they are still far too large, while they are orders of magnitude faster, they are still too slow, and while they store compar- atively incredible amounts of data, it is not enough. And worst of all is that modern computers do little more than the dinosaurs that we can now only read about, they still just do rapid arithmetical computations.

Of course, we the programmers, clever as we are, have invented a diverse variety of uses for arithmetic computation. And the computer, suited as it is for those sorts of things, is an ideal tool for the manifestation of these applications.

The programmers at Wolfram Research, Inc., clever as they are, have brought us yet another application for rapid arithmetical computation, called Mathematica.

I still can figure out whether Mathematica was invented for the user, or the computer itself. If computers could feel nostalgic about “The Good Ol’ Days,” each would yearn to run Mathematica, even if just once, to get a taste of what it must have been like for the pioneers. Mathematica is the most appropriate application for arithmetical computations yet: mathematical manipulations of every sort.

Now, symbolic mathmatics packages have been around for a long time, and my preamble about nostalgia might of- fend some who have grown comfortable with those, but none, I think, have been attempted at this scale.

Mathematica, in all its grotesque glory, is very close to a complete mathematics environment right when you take it out of the box. Were this not enough (it is not, of course), Mathematica is also a programming language. Let me rephrase that, Mathematica is several programming languages, incorporating programming philosophies from most languages from C to LISP. So, if you cannot find your favorite mathematical entity (after scouring the weighty tome includ- ed in the package) you can easily construct it, usually with the proper mathematical entities from which it is actually derived.

## Mathematica and the Macintosh ∆

Certainly it is a surprise to see such a thing do all the things Mathematica does, right here upon my desk. The Macintosh, with its capacity for 8 megs of RAM, and 68030 microprocessor, and math coprocessor, makes many things possible. It is the right time for Mathematica to come into being. While the Macintosh is the lowest end machine that Mathematica runs on, it has the curious advantage that its user-interface makes presentation of the information that can be generated by Mathematica pleasant and ordered. I don’t think Mathematica will sell too many Macs (I could be wrong, since the Macintosh is gaining more acceptance at education and research institutions), but the Mac is a good selling point for

Mathematica.

There are several levels of things the user can do with

Mathematica. At the simplest level, one can use Mathemat- ica as a numerical calculator, just like any other except that Mathematica can carry out numerical operations to arbitrary precision, or to a level of precision specified by the user. Mathematica will by default attempt to find the exact result, unless you use the **N[] **operator (for “Numerical” result). The symbology is fairly standard except that the multiplication operator * may be left out in certain circumstances and re- placed with a space, if you have, say, two variable names, as in “**xy**”, or with nothing at all in the case of scalar multiplica- tion, as in “**2x**”. A form such as “**xy**” would be interpreted as a single variable name.

The next level of operations is that of symbolic or alge- braic manipulations. At this level calculations may be per- formed upon quantities which might not have actually been given a value yet. For example, while

the input:

** In[1]:= p = 2
Out[1]:= 2
In[2]:= 3p - p + 2**

would result in the output:

**Out[2]:= 6,**

The input (with q not yet having been given a value):

**In[3]:= 3q - q + 2**

would produce

** Out[3]:= 2 + 2q.**

Mathematica will also reduce algebraic formulae to the sim- plest form and group like terms together, as well as expand simpler forms out by multiplying and carrying out powers.

Higher up in the order of things Mathematica can accom- plish is analytic mathematics like calculus and the solution of equations, as well as the manipulation of sums, products, and limits. Mathematica has a rather extensive table of integrals and a fairly general differentiation operator that allows for partial, multiple, repeated, and total derivatives. Mathematica will solve equations in one variable, or simultaneous linear equations, and many systems of polynomial equations, and will solve equations of more than one variable for the specified variable.

You can also define your own functions in Mathematica — functions which deal with symbolic arguments as easily as numerical arguments — and manipulate them just like any of Mathematica’s built-in functions. A simple example of this is a function that inverts its argument:

**In[4]:= invt[x_] := 1/x
In[5]:= invt[2 a^2]
**
** 1
Out[5]:= - - - -
2
2 a**

Mathematica’s graphic capability is probably where most people came to know about Mathematica, with all of the T-shirts, posters, and the like. The graphics are rather sophis- ticated, and perhaps well worth both the wait and the high memory cost (more on Mathe-matica’s speed later).

The sorts of plot Mathematica produces — either from functions or tables of data, in two or three dimensions — are many. The simplest of these is the **Plot[] **function which takes a function and a range and produces a graph. **Plot[] **is smart in that if your function goes off to infinity within the range you specify, the plot will show only the interesting parts, and not complain or blow up. The next sort of plot is the parametric plot where you specify one or more pairs of functions of a single parameter, and the range of the param- eter. In this way you can plot circles or clovers and the like. Still further there are 3-dimensional plotting routines — functional, tabular, and parametric — for which you can set the view point, the location of the lighting source, and other options too numerous to list here.

Access to the graphics primitives is provided, so that if the plotting facilities are not enough for you, you can go off and write your own. Perhaps primitives is a poorly chosen

word, since these are things like shaded polygons in 3-space and points of various sizes. All you have to do is supply the coordinates in space and Mathematica takes care of the projection.

The most entertaining feature of Mathematica’s graphics is that you can select a group of plots and show them in sequence. All you have to do is generate the plots one at a time, shift select them all (or select the cell that they are in, a feature of the user interface), and select animate from the menu. Mathematica comes with some demo packages which show off this feature, and by investigating these, the user can become familiar with the techniques for producing impressive

animated graphs.

**Programming ∆**

The most advanced use of Mathematica is as a programming language. Mathematica has taken many of the features of several programming languages into its own, and thus there are several ways one can go about programming in Mathematica.

The most obvious of these is straight procedural program- ming. Mathematica provides a set of control structures that any C, Pascal, or BASIC programmer will recognize. The programmer can use this to do simple things like automate sessions with Mathematica, using loops to vary parameters to animate plots as an example, or do more complicated things ignoring many of the built-in functions. Like any modern programming language, recursion is of course supported, making the procedural method of programming a bit more versatile.

I still cannot figure out whether Mathematica was invented for the user, or the computer itself. If computers could feel nostalgic about “The Good Ol’ Days,” each would yearn to run Mathematica, even if just once, to get a taste of what it must have been like”for the pioneers.

The next step up is to functional programming. An analogy of this would be moving from BASIC to pascal, where subroutines can return values to the calling program. The LISP programmer will probably take full advantage of this feature of the Mathematica programming language, as itallows “lambda” sorts of in-line function definitions, where it is not necessary to specify named variables for the argu- ments. These in-line functions can also be “applied” to and “mapped” over lists (tables or arrays in Mathematica), as in LISP. Mathematica’s other programming facilities, however, make procedural programming seem taken for granted.

Object-oriented programming, the practice of writing rules to operate upon objects, rather than merely letting val- ues tumble in one end of an algorithm, and out the other, is supported in various ways. Every expression in Mathematica has what is called a head. This head is the type of object being manipulated. For example the head of 5 is integer, while the head of **x + y **is plus. The user can create different types of objects by associating a head with each. Then when the objects are created, rules can be associated with them via special definitions. Another aid to Object-oriented programming is that the operators can be “overloaded,” or used in non-standard ways, by just adding rules to the definition of the operator. Thus if you create objects which are, for example, two genetically distinct creatures, you could modify the + operator to accomplish “mating.”

All of this is dependent upon a special feature of Mathematica, which is the ability to specify transformation rules for operators. The canonical example for this would be the fact that **ln(xy) = ln(x) + ln(y) (where ln(a) **is the natural logarithm of a). In Mathematica this would be expressed:

Log[x_ y_] := Log[x] + Log[y].

Mathematica uses pattern matching to determine when these rules are to be applied, starting with the most general first, then going on down to the more specific. These sorts of rule specifications, which use the := (evaluate the left-hand- side every time the pattern in the right hand side is encountered) operator rather than the = (evaluate the left-hand-side now) operator, can be used with the existing functions, or those of your own device.

You can also do mathematical linear programming and logic programming, using the Solve[] function’s ability to solve systems of linear equations, and the special pattern matching facilities respectively.

## The Macintosh Mathematica Front End ∆

The special advantage of the Macintosh over many other computers is the user interface, and Mathematica — as well as using the standard Mac user interface — implements several other interesting features of its own.

Information in Mathematica is grouped hierarchically. The top level of this hierarchy is the notebook; the Mathematica name for a document. The Mathematica notebook is a dynamic page of text and graphics, parts of which can be displayed or hidden, animated, or executed, either automatically or at the direction of the user.

Within the notebook are cells. All information in the notebook is also contained within a cell, of which there can be many, and these nested. There are several types of cell, each suited to a particular type of data, such as a graphics cell. The cells appear as square brackets to the right side of the window which surround a certain amount of information. You click on the bracket to select the cell. Cells may be shift-selected. If a cell contains other cells, all are chosen by the shift-select. Cells may also be grouped, creating a new cell containing all of the grouped cells. Cells may be closed to hide the information until they are re-opened, so that, for example, you can turn an entire notebook into its table of contents (if you arrange it correctly) which can be expanded as the user desires. Cells can also have keywords, which allows categorizing cells for easier access to information through searching on the keywords.

Cells have several attribute toggles, such as open/closed, formatted/unformatted, active/inactive, and locked/unlocked. There are other attributes but these are the most common ones. Formatting in a cell pertains to how the information in it is presented. For example a formatted graph- ics cell will show the graphic, while the unformatted shows the Postscript code which generates it. If the information in a cell is meaningful to Mathematica, it can be executed if the cell is active. The cell can be made inactive (if for example it contains only text which is not intended to be executed, but is only explanatory) to inhibit Mathematica from executing it. Locking a cell prevents the information within it from being changed.

The graphics cell contains a user interface of its own which allows positioning the image within the document, scaling it, editing the Postscript code, aspecting, and other options in rendering. The user may also grab values from plots by clicking on the graph, and use the values for further computation.

The front end has several utilities for transferring information from one form to another, such as changing Postscript to PICT, exporting graphics, and other such useful tricks.

## If You Find Mathematica Too Slow ∆

You can still take advantage of the Macintosh user interface and all of the extensions mentioned on the previous page, but use a more powerful computer to run the kernel. Mathematica has its own communications facilities to use a serial connection between your Mac and the machine running the kernel.

## Speaking of Speed ∆

You might find Mathematica fairly slow in several operations. While all of the functions are im- plemented with polynomial-time algorithms (when such are known…), it still seems that the rubber-band needs winding at times. For instance, on the Mac II, I tried to fill a 50 x 50 matrix up with the sums of the indices (A**(i j) = i+j**) and it took well over a minute and a half. Then I discovered that if you really don’t want to look at the output, you put a semicolon after the input, and the result won’t be displayed (useful for assignment statements). As it turns out, formatting the data for display was what was taking all the time. The 3D-plot utilities are not too awfully quick either, but

you must realize what you are getting for the time spent. The images are shaded according to a light source (which you can specify) or some other coloring algorithms, rotated according to a view-point, and, of course, rendered through Postscript. Mathematica is also very big. At least 2.5 MB of RAM

is required to run the kernel. 1 MB is all you need to run the front end alone, which does little good, unless you have a nice big computer next to your Mac. You can have Mathematica off load parts of the kernel (from the most rarely used parts to the more common parts to all of it) and load them

as needed, at the obvious sacrifice of speed. The Postscript graphics take a great deal of memory, which is sometimes maddening when you realize that for drawing 3D images, Mathematica starts from the rear of the object and draws forward, hiding the parts in the rear; so at most 50 percent (in the case of a sphere) of the image might not be visible, yet the Postscript code is still in memory.

## When Would You Want to Use Mathematica? ∆

Mathematica is a storehouse of most general mathematical knowledge. It is sort of like a dynamic mathematical handbook. And indeed the mathematician will find a great many uses for the package. I doubt that there are many areas of research in mathematics, physics, or computer science where Mathemat- ica would not be of use. Mathematica notebooks can also be beautified so as to make great animated monographs (I have yet to hear of someone presenting her thesis as a Mathematica notebook though).

Mathematica can also play an important role in mathematics training. Imagine a textbook in which the student can change parameters of the examples to see how systems react, illustrations can be animated, questions get immediate feedback, and customization problems can be explored.

The Mathematica notebook is a dynamic page of text and graphics, parts of which can be displayed or hidden, animated, or executed, either automatically or at the direction of the user

So what’s in it for the non-mathematician? The fact that Mathematica is such a diverse programming language with many routines already implemented should cause programmers to salivate. While Mathematica is an interpreted language, it is not meant for general software development. However, it is very useful for prototyping applications — especially applications with a grounding in mathematics — and testing out ideas without having to write a great deal of technical code.

I am afraid that the non-programmer, non-mathematician will get little out of Mathematica, though I have found some rather off-the-wall applications for it. The pattern-matching facilities lend themselves well to simple sentence parsing, thus a linguist might find Mathematica a useful tool, with only a very little instruction in programming. I have also used it to make templates of complicated images to trace with illustration programs on the Mac, since it will export Postscript and PICT images.

The ideal setup for Mathematica, of course, would be to use the Macintosh front-end with a more powerful machine running the kernel. While I did not get to test this (Wolfram wouldn’t send me the Cray version to test), I am confident that an improvement in performance would be achieved in calculation, though I imagine that communication with the kernel would add a little overhead.

But the place of the mathmaticians is still not threatened. Mathematica can still not accomplish the basic and necessary (but not sufficient) feat of mathematical proof (yet). An old proverb says that before the child can read words, she must learn the alphabet, but when the child is to the point of reading sentences, she would be lost if she was paying any more than a passive attention to the letters themselves. So it is with the mathematician, physicist or computer scientist. Paying attention to operations that may be carried out by machine distracts from the actual work at hand, thus a tool like Mathematica does not replace the mathematician, but affords her more freedom to further the bounds of what we know.

## About the Author

Jim Flanagan graduated from the University of Washington in 1988, with a BS in Mathematics and Computer Science. He currently works as a systems programmer and a free-lance illustrator. His interests include nonlinear dynamics, fractals, and natural language syntax.