OR/MS Today - December 2003



Software Review


Mathematica 5

'Mathematical system' offers wealth of features for operations research professionals

By ManMohan S. Sodhi


Mathematica from Wolfram Research is well known as a "mathematical system" for mathematicians, but it is perhaps not as well known for its wealth of features for OR professionals. The new version 5 is even more compelling for OR professionals who have been intrigued by Mathematica software in the past but did not consider it to be a bread-and-butter package for their profession. This version of the software introduces advanced numerical analysis, linear programming — interior point as well as simplex method variants — and sparse matrix manipulation with fast algorithms that compete with dedicated numerical software tools. And this is on top of what the software already had in previous versions: probabilistic and statistical functions and calculations, nonlinear algorithms and combinatorial calculations.

I was a doctoral student when Stephen Wolfram, founder and CEO of Wolfram Research, came to UCLA in 1991 to demonstrate version 2 of the software. It was fascinating to see mathematical functions being played as music and to see that he used Mathematica itself for both word-processing and presentation. It also was clear that you could use the software close to the way you think and represent equations and symbols in your writing with Greek letters, shorthand notation, functions and operations. I was intrigued by the software but not enough to buy it then or to learn how to use it because I did not make the connection between the software and what I did: linear programming, statistics or general-purpose programming to code new algorithms.

My perception changed having explored Mathematica 4 recently as a programming tool to write and to graph some simulation programs with arrays. I was pleasantly surprised by the compactness, and at least relative to C++ or even higher level languages, the readability of the resulting computer programs. But, continuing to have the same perception of Mathematica as a "symbolic mathematics" package with some matrix and other numeric capabilities, I switched to a numerical package known for its speedy matrix manipulations and built-in functions. I knew that Mathematica has tons of built-in features besides matrices — graph-theoretic, combinatorial, statistical, and financial features for instance — as standard or as add-on packages, but I did not connect it with "serious" number crunching. The new version of Mathematica, version 5, blows away such stereotyping with its OR-related features.

New Features in Mathematica 5


Some of the new features announced by Wolfram Research [1] for Mathematica 5 that may be interesting for OR professionals are:

  • high-performance optimization and linear programming including interior-point method;
  • processor-optimized numerical linear algebra;
  • fast sparse linear algebra;
  • new-generation numerical solvers for ordinary and partial differential equations;
  • more generalized numeric solvers that now accept vector and general array variables;
  • flexible import and export of sparse matrix formats; and
  • optimized versions for 64-bit hardware and operating systems.


Linear Programming


Mathematica 5 can read an MPS file and solve the corresponding LP model with the "default" option (Mathematica chooses the appropriate method based on the size and precision of the problem), or the user can set simplex or interior point to be used by default if desired. To run an example, I first downloaded (and uncompressed) the problem "boeing1" from Netlib (www.netlib.org) in MPS format. Then, within Mathematica 5, I converted the data in the MPS file to a sparse coefficient matrix and the other arrays that Mathematica 5 (but not earlier versions) uses as default and solved it first with the built-in interior point method and then with the default simplex method (Figure 1). On 1.2 GHz Windows 2000 laptop with 512Meg RAM, it took about the same time to solve with either method, about 0.24 seconds.



Figure 1: Solving the "boeing1" LP problem from Netlib in Mathematica 5.

Mathematica 5 does not have integer programming, but you could write your own branch-and-bound code within Mathematica or, perhaps less efficiently, in C++ or Java, and use the Mathematica 5 LP solvers for the LP part via Mathlink that is a part of Mathematica 5. To run dual simplex, you can modify the input matrices and arrays by transposing the coefficient array — you can manipulate sparse arrays the same way as their dense equivalents — and invoke the LinearProgramming[.] call as before or use DualLinearProgramming[.] directly. There are a variety of options that you can use as well by invoking SetOptions[LinearProgramming[.]. A number of warnings and errors exist for LinearProgramming[.] as well.

Moreover, you can create your own sparse matrices and use those for LP or for matrix manipulation in algorithms. If you create your own matrices and you are solving real-world problems that invariably have structure, you can use sparse matrices that are handled in Mathematica just as other matrices but stored compactly.

Numerical Accuracy


Mathematica's machine-precision results are IEEE 754 compliant on all operating systems and hardware so you can expect machine-independent results. However, if you are interested in numerical stability-related aspects of a particular matrix-based algorithm like LP or matrix inversion, Mathematica allows you to specify the number of digits to which you want accuracy in numeric computation. You cannot do this in a dedicated numerical solver. So if you have a matrix whose determinant is close to zero, you might want to increase the number of decimals of accuracy from the default 16.

For linear programming problems, you can optionally provide a "tolerance" parameter (10-6 default) to determine whether or not we want the solver to consider two numbers equal to each other. I could not find any parameter to clean "dirty" zeros (any number with absolute value smaller than this parameter is set to zero by the solver in question). I expect there will be updates regarding linear programming in the "help" section with more examples and notes regarding LP-related warning and error messages in the near future.

Nonlinear Programming


Mathematica 5 (along with its earlier versions) provides global constrained optimization through two functions, Maximize[.] and Minimize[.]. These functions assume that the variables are from the real domain but integrality can be imposed as a constraint. For example, to maximize xy subject to a circle constraint and integrality, you can use

Maximize[{x y, x2 + y2 < 150 && (x | y) _ Integers}, {x, y}]
to get the result {72,{x_-9,y_-8}}.

If you had a small mixed integer linear programming problem, you can use Maximize/Minimize to solve it in this manner as well.

There are two other functions, NMinimize[.] and NMaximize[.] for smooth functions with only a few local optima, the "N" standing for numeric. These functions cannot guarantee to find absolute global minima and maxima. As a guess on my part, I would say that the first two functions work in the symbolic and numeric space whereas the latter two use numerical procedures that we are taught in mathematical programming courses, e.g., Newton-Raphson.

General Purpose Programming


Programming in Mathematica was hard going for me at first for a variety of reasons, all to do with getting used to a way of doing things different from a dedicated numerical package. First I got errors that did not make much sense to me. Eventually I discovered that the problem was either because I was using a function incorrectly or because the "package," a collection of functions within Mathematica, had not loaded properly. The help browser helped me fix the first type of problems and shutting down part of the program called the "kernel" and restarting it again took care of the latter.

Another challenge was trying to understand that computations are done in a Mathematica file or "notebook" that it is divided into a hierarchy of "cells." A cell can be (re)computed by itself, taking the state of the program from the other cells. This is a blessing when you have a large time-consuming program, allowing you to focus only on the cell being modified without having to rerun the entire notebook. But it takes getting used to because we are used to rerunning entire programs. It can also be confusing if you go back and forth to re-valuate cells not keeping the values of all the variables in mind. Finally, it took some getting used to thinking of programming constructs like the "for" loop and the "if" statement to be used as functions.

Once you have figured out the programming environment, you can make good progress. Like other good programming environments, Mathematica provides you with much help. For instance, you can hit Cntrl-K (in Windows) to "complete" the name of a function you are typing or you can right click and ask for help on that specific function. I wrote a few small programs and got useful results using such constructs as For[.], If[.] and Min[.]; these are functions in Mathematica (Figure 2) and are used as such. Still, expect progress to be slow initially; you will be tempted to go back and do your programming "quickly" in C++ or Java. I should mention here that Mathematica allows two-way linking with programs in these languages using Mathlink.



Figure 2: Example of a Mathematica program.

Probability and Statistics


Mathematica uses the notion of "packages" to add to the functionality that is specific to a user's needs. (There is no point loading all functionality of such a large system at the same time because no particular user will be using all of it.) These statistical packages include those dedicated for discrete and for continuous distributions whether in one variable or many. There are also specialised packages for statistical computations as ANOVA and linear regression. See www.wolfram.com/solutions/statistics/ for an overview of statistics-related functionality. A time series package, to be purchased separately, is also available.

Graph Theoretic Computation and Discrete Mathematics


Besides creating lots of different types of graphs each in a single function call, you can solve such problems as Traveling Salesman and ShortestPath. You can get permutations and combinations and many other combinatorial calculations. Details of this functionality can be found at www.combinatorica.com which is maintained by the author (not Wolfram Research).

Some Output Choices


You can display information as a variety of graphs, including Pareto charts in Mathematica 5. You can also export tables into CSV files to be imported into spreadsheets. When you invoke a function, you can ask Mathematica to print out the computational time quite easily with a "Timing" call and also the memory usage with a "ByteCount" call. For large sparse matrices, you can use "MatrixPlot" to display the structure of a sparse matrix such as the coefficient matrix A in the "boeing1" problem; note that this is based on sampling rather than computing every cell, though. This feature can be useful in understanding the structure of an LP problem.



Figure 3: Sparse structure produced by Mathematica for the coefficient matrix A in the LP problem "boeing1."

Help Browser and the Manuals


Mathematica's online help is a model worth emulating for any software. The interface is motivated by the way the NeXT operating system displayed directories and files (Mathematica was available on the first NeXT operating system), which allows you to connect the topic on which you are seeking help with other topics. Many sources of help are present with the same interface so it is easy to find information.

The help system was wonderful when I wanted to write a simulation program in version 4 of the software. I did so without first reading the hefty but well-written book [2] that comes with the software.



Screen shot of Mathematica Help Browser.

Linking with Other Programming Environments


You can also use Mathematica as an engine via Mathlink to allow your C++ or Java (or other) programs to call the LP routine within Mathematica and fetch the results. With Windows platforms, it offers .NET-based links with Mathematica 5.

Much has been written in OR/MS Today about the benefits — even the necessity — of using spreadsheets in teaching business students (see e.g., [3]). Mathematica supports Excel with third-party software called Mathematica Link for Excel on the Windows and Mac platforms, but not for the latest versions of Excel. This software allows you to call Mathematica functions from within Excel.

Word-Processing and Presentation


You can write an article in Mathematica because you can type in a rather impressive array of mathematical and Greek symbols that are displayed as such, aiding in readability. The cells can be used for "outlining" in word-processing packages and therefore help you organize your thoughts. I have not used these features yet myself, and I must confess that I wrote this review in Microsoft Word although I was quite tempted to write it in Mathematica itself. Moreover, you can export to TeX, MathML and XML.

There are specific features, again, not tested by me, for presentation. An advantage over Microsoft Powerpoint is that you can run programs as part of your presentation.

Finally, you can share your files easily because free reader software, called MathReader, can be downloaded from www.wolfram.com/products/mathreader/ to read Mathematica files, including from within a Web browser.

The Mathematica Universe in the Internet


Mathematica has been a staple for mathematics students and mathematicians for quite some time now so there are many resources on the Internet. Wolfram Research itself offers a number of sites. Eric Weisstein's World of Mathematics (http://mathworld.wolfram.com/) and ScienceWorld (http://scienceworld.wolfram.com/) are general-purpose resources. Wolfram's Mathematical Functions (http://functions.wolfram.com/) aims to be the world's largest source of mathematical functions (there are more than 9,000 elementary functions alone on the site). The Mathematica Information Center (http://library.wolfram.com/infocenter) has almost 4,000 items including articles on a variety of topics, conference proceedings, demos, contributed programs or packages, and information about books.

Overall Summary


Most OR professionals whether working in industry or in academia, have grown up using a large number of different tools. We have used SAS or SPSS for statistics, CPLEX for solving linear programming problems, GAUSS or MATLAB for numerical matrix manipulations, and perhaps C/C++ or even Fortran for coding our own algorithms. It is hard for us to think in terms of a single package; we use the specific tool we learned to use in graduate school. But it is worth keeping Mathematica 5 handy especially if you use multiple tools. Mathematica 5 may seem difficult to learn at first, but once you figure out how it consistently uses functions you can be quite productive. Mostly, it is a question of getting past habits formed on other tools. We are used to writing up mathematics in one way, usually in freehand or in LaTeX, and then programming in a completely different notation. Mathematica lets you use the same notation so you program the way you think. In an odd way, doing things naturally takes getting used to! With its rich set of offerings of interest to the OR user, Mathematica 5 is well on its way to becoming an essential part of every OR professional's toolkit for teaching, research, consulting or simply problem-solving.

Product Summary

Mathematica is truly multi-platform; it is one of the first major programs to be available for Mac OS X as it was for the NeXT operating system. Wolfram's Web site sells it for a number of 32-bit platforms, namely Windows, Mac OS X and Linux (PC) configurations, along with the 64-bit HP-UX, HP Tru64 Unix, Linux Alpha, Linux Itanium, Solaris and IBM AIX platforms. A G5-optimized version for Mac OS X is reportedly under way. Mathematica 5 is available for most of these platforms with Mathematica 4.2 being the most current version on the remainder.

Mathematica 5 is distributed by Wolfram Research through academic bookstores and through their Web site, www.mathematica.com. There are different prices for commercial, academic and student users, and these prices are listed on the Web site. Under a Premier Subscription, if you buy a version for work, you can also get another one at home at no cost even if you have a different platform at home.

PRICING INFORMATION
U.S. and Canada:
Commercial professional: $1,880, includes one year Premier Service.
Academic list price: $895
Student version: $139, has the same functionality as the professional version

U.K. and Europe:
Commercial professional: GBP 1,625.22 (EUR 2,660.60), includes one year Premier Service.
Academic list price: GBP 745 (EUR 1220.00)
Student version: GBP 80 (EUR 128)

For international pricing, contact your local reseller listed at www.wolfram.com/services/intdealers.

Mathematica for the Classroom is available for precollege education and community colleges at $195.


Vendor Comments

Editor's note: It is the policy of OR/MS Today to allow developers of reviewed software an opportunity to clarify and/or comment on the review article. Following are comments from Lars Hohmuth, Manager of Strategic Marketing, Wolfram Research.

A few tips Professor Sodhi and other users might find helpful:

  1. To clean "dirty" zeros, use the Chop[.] function on the result.
  2. In regard to Professor Sodhi's questions concerning the NMinimize[.] and NMaximize[.] functions, for linear cases, NMinimize and NMaximize use simplex, revised simplex or primal-dual interior point methods. For nonlinear cases, they use Nelder-Mead methods, supplemented by differential evolution, especially when integer variables are present.

Readers can download a trial copy of Mathematica 5 from www.wolfram.com/m5 and try it out for themselves.



References


  1. "What's new in Mathematica 5?" http://media.wolfram.com/notebooks/newin5.pdf.
  2. Wolfram, S., 2003. "The Mathematica Book, 5th ed.," Wolfram Media, Champaign, Ill.
  3. Grossman, T.A., 2003. "Getting Down to Business," OR/MS Today, August.



ManMohan Sodhi is a member of the operations management faculty at Cass Business School in London.





  • Table of Contents
  • OR/MS Today Home Page


    OR/MS Today copyright © 2003 by the Institute for Operations Research and the Management Sciences. All rights reserved.


    Lionheart Publishing, Inc.
    506 Roswell Rd., Suite 220, Marietta, GA 30060 USA
    Phone: 770-431-0867 | Fax: 770-432-6969
    E-mail: lpi@lionhrtpub.com
    URL: http://www.lionhrtpub.com


    Web Site © Copyright 2003 by Lionheart Publishing, Inc. All rights reserved.