Mathematica 40
Volume Number: 15
Issue Number: 8
Column Tag: Review
Mathematica 4.0
by Fredrick Olness
A review for developers and programmers
Mathematica is a system for doing mathematics by computer. Although this definition
does a good job of characterizing Mathematica, it is difficult to convey the full scope in
a single phrase. Its various applications include: numeric and symbolic calculation,
graphical visualization, high level programming, data modeling and analysis,
scientific/mathematical typesetting, and an interactive control environment for
external processes.
Mathematica is fundamentally an interactive interpreter. This has the inherent
advantage that the user receives immediate feedback for each input, and can build and
debug complex projects with ease. Of course, the downside is that an interpreted
language is never as fast as a compiled one; however, for many applications, the
development speed more than compensates for the execution speed. For some of my
projects, I was able to write the code in a day with Mathematica, rather than the week
it would take with compiled C code - given this advantage, I wasn't bothered that the
code ran in 3 minutes instead of 1 minute.
Where Is This Review Going
The following is an overview of Mathematica aimed at programmers and developers,
and highlights some of the recently enhanced features. This is not an exhaustive
description of Mathematica; there is a comprehensive 1400 page book which fills this
need. (Wolfram 1996, 1999). Nor is this a basic introduction; you can find a succinct
tutorial at: http://www.wolfram.com/products/mathematica/tour/.
To make the code in this article easier to read, I have used the Courier font to
represent Mathematica Input and Output. Input is shown in bold Courier, and Output is
shown in normal Courier.
A Brief History of Mathematica
The first version of Mathematica was released in 1988. One of the key features that
distinguished Mathematica from earlier programs was the "notebook" interface which
allowed the user to mix input, output, and graphics in a single uniform environment.
In the following years, numerous improvements followed.
Mathematica 3.0, released in 1996, represented a major advance over the previous
versions. Significant enhancements included: integrated WYSIWYG typesetting
capabilities for input as well as output, palettes to simplify input, notebook
conversion to TeX and HTML, optimized memory usage, faster kernel algorithms, and
support for international character sets and Unicode. Note Mathematica not only
supports a wide variety of international languages, but it also supports Klingon
making it, I believe, the first intergalactic software program.
So what will you notice when you take the shrink-wrap off Mathematica 4.0? While
the "look and feel" is quite similar to version 3.0, you really need to take a good look
"under the hood" to see the large number of enhancements and improvements.
A key improvement to the kernel is packed-array technology. This technique
significantly reduces the overhead in handling large structures such as vectors and
matrices, and thereby speeds the computation. This is one of the critical features
which allows an interpreted language such as Mathematica to compete with a compiled
program. (Typical improvements are an order of magnitude, cf., Table 1.) And, the
casual observer of Mathematica 4.0 won't notice the packed-array implementation by
design; it has been seamlessly integrated into the existing framework.
Calculation Mathematica 3 Mathematica 4 Ratio
Sin[M] 2.433 Second 0.130 Second 18:1
(M+1)^100 4.426 Second 0.311 Second 14:1
Min[M] 4.487 Second 0.020 Second 22:1
Table 1.In this example, M is a 500x500 array of random real numbers, the
comparative timings are shown for a 300MHz G3 processor.
Another improvement that may not be immediately apparent is the improved
algorithms for computing exponential functions. This may not excite you until you
realize that the exponential function is at the heart of many special functions;
therefore, speeding up this one operation speeds up a wide class of computations.
A large number of functions have been added and extended. For example, a Dirac delta
function and other generalized functions have been defined. While this may not catch
your immediate attention, as soon as you need to perform analytic operations with
Fourier transforms and generalized distribution functions, such functionality becomes
essential. (This has important applications in my research field.)
Finally, there have been a number of noteworthy higher-level programmatic
improvements. Mathematica's ability to export documents in all flavors of TeX (LaTeX
2.09, LaTeX2e, and custom packages) and HTML (with support for MathML) has been
enhanced and expanded. These features, with the addition of a spell checker and
automatic hyphenation, allow you to easily compute and publish technical documents in
Mathematica.
Overview and Case Studies
It is impossible to catalogue the features of Mathematica in a short article; therefore, I
will present sample applications where the abilities of Mathematica might be of use to
an advanced programmer. Where appropriate, I will note recent enhancements.
2-D Graphics
One of the strongest features of Mathematica (and one that my physics students are
most drawn to) is the very flexible graphics capabilities. Let me illustrate my point