OR/MS Today - December 2004



Software Review


Mathematica 5.1

Additional features make software well-suited for operations research professionals.

By ManMohan S. Sodhi

In the December 2003 issue, I reviewed Mathematica 5 from operations research professionals' viewpoint [1]. I wrote how version 5 is compelling for O.R. professionals who may have been intrigued by Mathematica software in the past but did not consider it useful for their profession, at least not over the numerical and statistical packages they already use. I was initially hesitant to review version 5.1, but the additional features in terms of the Internet, graphical user interface (GUI) development, and data handling and visualization alone can be considered as a major upgrade in contrast to what the version increment would suggest.

Version 5 had introduced 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. Previous versions already had probabilistic and statistical functions and calculations, nonlinear algorithms and combinatorial calculations, so version 5 offers many features to interest O.R. professionals.

Version 5.1 has many new features as listed at the Wolfram Research Web site (www.wolfram.com). This is a long list divided into enhancements for numerical computation, symbolic computation, language system, etc. However, I will focus on the added Internet, GUI and data handling features. Included in version 5.1 is the GUIKit that allows a user to create a GUI running on top of Mathematica for other users to do specific things. You can access Web services offered by other providers from within Mathematica and use the offered functionality as a Mathematica function. Data in spreadsheets (MS Excel) and databases can be directly accessed and drawn/analyzed in more ways. For the numerically inclined, piecewise functions have been introduced.

Web Services


I used to think of Web services as one more overhyped technology (as was the opinion of a group of CIOs surveyed by InfoWorld back in 2001), but it has been coming along nicely. The idea behind Web services is that a "program" is available over the Web, and you can use its functionality in your own program. In other words, think of a Web service as an object available via the Internet for use in your program. In general there may be cost or access issues, but there are many freely available Web services available mainly to provide information. Also, you may have Web services available within your own organization or you may provide your programs as Web services for others to use.

Mathematica 5.1 allows users to query a Web site for the available services and to use these services as Mathematica functions. The functionality includes:

  • transparent access to Web services from within Mathematica,
  • support for SOAP (the protocol to exchange information) and WSDL (a Web service directory language), and
  • automatic discovery and installation of Web service functionality through WSDL.

As an example, here are the Mathematica instructions to convert Hindu-Arabic numbers into Roman and vice versa in Mathematica 5.1 along with the output of each step:

InstallService["http://www.ebob42.com/cgi-bin/Romulan.exe/wsdl/IRoman"]
{IntToRoman,RomanToInt}
IntToRoman[342]
"CCCXLII"
RomanToInt["CCCXLII"]
342

Now, let's find out the price of "Linear Programming and Extensions" by G. Dantzig and M. Thapa (Princeton University Press, 1998) at Barnes & Noble prices (U.S. dollars) assuming we already know the ISBN number 0691059136. The sequel is "Linear Programming: Theory and Extensions, Vol. 2" (Springer, 2003) with ISBN 0387986138, so we can check the price for that one as well.

InstallService["http://www.abundanttech.com/webservices/bnprice/bnprice.wsdl"]
{GetBNQuote}
GetBNQuote["0691059136"]
"59.95"
GetBNQuote["0387986138"]
"69.95"

While these are simple examples for illustration, there is no reason why a linear programming Web service cannot be available at site like NEOS. Such a service would allow you to send an AMPL or XML file(s) with the model and data and obtain the solution as XML or other output. Also, Mathematica 5.1 has enhanced string manipulation capability so you may be able to do more with the results you get from a Web service.

Allowing Web services to be used as Mathematica functions becomes increasingly important as many providers start providing information as Web services. In that case, you can try out the functionality within Mathematica first, even if your application is not going to be created within Mathematica.

GUIKit


Mathematica 5.1 comes with:

  • integrated GUIKit for building standalone user interfaces,
  • platform-independent Mathematica language GUI specification,
  • more than 100 types of controls and widgets,
  • automatic layout for complex dialog boxes,
  • a system for creating sequential wizard interfaces, and
  • a large library of sample GUI applications.

As the name suggests, GUIKit is a kit for building user interfaces and has been built with Java. Simplistically speaking, Mathematica is a command-line-oriented software. This means invoking functions with many parameters. Say you want students to experiment with a particular function as to how it changes shape with different parameters. They would have to define the function and then repeatedly invoke and draw that function with different parameters. Or, in a work situation, say you want traders or engineers to do what-if analysis in a program you wrote in Mathematica. It would not be straightforward unless you wrote an interface in some other language or package and invoked Mathematical from that program. With GUIKit, you can keep everything within Mathematica.

Some examples exist within Mathematica. One is a general-purpose calculator in which you can enter Mathematica expressions as arguments to produce the sum, difference, product and quotient. You would invoke it as follows:

Needs["GUIKit`"]
GUIRunModal["Wolfram/example/Calculator"]

This gives the user an interface in which to enter arguments and see the results (see Figure 1).



Figure 1: A simple calculator built using the GUIKit in Mathematica 5.1.

Another example is provided on their Web site for building a GUI to generate a random number with the click (see Figure 2). The "code" for this is:

panelExpr3 = Widget["Panel", {
Widget["Button", {
"text" -> "Click Here",
BindEvent["action", Script[setText[]]]}],
Widget["TextField", {"columns" -> 20 },
Name -> "TextOutput"]
Script[ setText[] :=
SetPropertyValue[{"TextOutput", "text"},
ToString[Random[], InputForm]]
]
}];



Figure 2: Example of a GUI built within Mathematica to generate random numbers with a click.

Mathematica 5.1 comes with some serious applications already built in. For instance, there is the Equation Trekker that allows you to define-graph-and-view solutions to differential equations.

With GUIKit being built using Java, you can access the entire Java component and class library, but you will likely not need to do so. More information about the GUIKit specifically is available at www.wolfram.com/guikit. As Mathematica runs on many platforms, your GUI program can run off multiple platforms as well without having to tweak the code as can be the case with Java itself [2].

A GUI application built using GUIKit can be run within Mathematica or as a stand-alone application that launches the necessary Mathematica kernel either on the same machine or on the network for the required computations.

Data Visualization


Adding to its already impressive graphics functionality, the new version 5.1 version provides:

  • ArrayPlot for flexible large-scale array visualization, and
  • fully automated network and tree layout in 2D and 3D.

In my previous review I had given an example of the "MatrixPlot" function within Mathematica to help visualize the structure in terms of non-zeros of large sparse matrices. For large matrices, MatrixPlot only samples elements (using some heuristic for "optimum" visibility) to display the structure (see Figure 3). The instructions I used are:

p = Import[ "boeing1.mps","MPSData"];
{c, A, b, d}=ToLinearProgrammingData[p];
MatrixPlot[A]

where A is a sparse matrix comprising the coefficients of the Netlib problem boeing1 obtained as above.



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

Now, what if you wanted to check if the coefficient array of your large linear programming problem has incorrect coefficients? With the new function "ArrayPlot," all the elements of an array are checked to see if they are non-zeros before displaying the non-zero structure. These are the instructions I used within Mathematica:

ArrayPlot[A,ColorRules->{0->White,_->Black}]

The option of color rules simply makes non-zeros stand out against a white background. The default option is more interesting in that ArrayPlot shows all the numbers in an array in different shades of gray, with the largest (absolute value) numbers being the darkest and the smallest being the lightest. Of course if some of the numbers are very big in the coefficient matrix for "boeing1," then most of the numbers will show up as "white." Using the above options, we see that the matrix structure shown by ArrayPlot (see Figure 4) is the same as that produced by MatrixPlot earlier.



Figure 4: Sparse structure produced by Mathematica for the coefficient matrix in the LP problem "boeing1" using ArrayPlot.

There are additional ways to visualize data. For my money, most notable of the remainder is a package for cluster analysis and dendrograms.

Data Access and Handling


Other features include data access from databases and other sources of data. The package DatabaseLink is included within Mathematica for "universal cross-platform database connectivity." This includes:

  • bundled drivers for most common database systems,
  • integrated language interface for database discovery, query and updating,
  • a graphical interface for database connection and exploration, and
  • bundled SQL engine for creating custom databases.

For accessing data from other file formats — this could be useful if you are using software already that produces such files — the added features include:

  • import and export of MS Excel .XLS files (and CSV format),
  • support for HDF5, MAT (Matlab v5), DIF and PCX,
  • export of AVI movie files,
  • import from http and ftp URLs,
  • automated encoding and decoding of gnu-zipped.gz files, and
  • integrated TeX import and parsing in notebooks.

My experience with TeX was rather mixed. You can use File-Save_as_Special from the menu for Mathematica 5.1 to generate the equivalent AMS-LaTeX file. However, you will likely have to hand-edit the generated files before compiling using a TeX compiler to get desired results. (Mathematica does not come with a TeX compiler, but there are many available in the public domain and for sale. I used TrueTeX that comes bundled with Scientific Word from TCI Software Research.)

Importing a mathematical LaTeX expression is easy. You simply cut the expression from a plain text file with the expression and then paste it into a Mathematica cell for it to show up in the expected graphical notation. However, reading in a whole LaTeX article using File-Import simply reads in a .tex file as a plain text file without showing the mathematical expressions in graphical form. So my expectation is that you can move mathematical TeX expressions back and forth between Mathematica 5.1 and plain text LaTeX files, but that is really it for now.

Regarding Excel, although you can import .XLS files (using the Import["filename.xls"] command), you should consider using comma-delimited files (CSV) or text files for import of tabular data rather than MS Excel native format files to get more control.

I did not try the other file formats myself, but the list is impressive.

Piecewise Computation


It may sound strange but until 5.1 came up, Mathematica was weak on piecewise functions. Piecewise functions are hardly a curiosity and include such mundane items as absolute value, mod, floor and ceiling functions. Now you can integrate over such functions and do such things as:

  • numerical integration of discontinuous piecewise functions,
  • piecewise construct for representing general piece-wise functions,
  • simplification with piecewise and nested piecewise functions, reduction of piecewise equations and inequalities, including quantifiers, limit, series and D support for general piecewise functions,
  • indefinite and definite integration of general piecewise functions,
  • support for solving piecewise ordinary differential equations, and
  • symbolic multiple integration over regions defined by inequalities.

Word Processing (and Typesetting)


As I had mentioned without testing in my previous review, 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. Also, the cells can be used for "outlining" in word processing packages and therefore help you organize your thoughts.

A minor improvement since then has been that Mathematica 5.1 can read TeX expressions. If you copy and paste a TeX expression into Mathematica, it will show up as a Mathematica expression. Even older versions used to allow export of Mathematica expressions to TeX, so the functionality is more symmetric now. However, this does not mean you can read in an entire TeX file or vice versa, at least based on my experience as I recounted above.

A major improvement on this front unfortunately resides outside Mathematica: Wolfram now sells another software called Publicon 1.0 for the Windows and Mac OS X platforms only. While I am not reviewing this software here, I can mention that Publicon is intended for the scientific and technical publishing community. The native format is still Mathematica's notebook, but you can export the entire contents of a file as a TeX file. (I was also able to read the .tex files

generated by Publicon in Scientific Word, something I was not able to do with the .tex files generated by Mathematica 5.1.) For Mathematica users, Publicon would be a natural word processor for all documents for which these users would have otherwise used TeX or LaTeX. But even non-Mathematica users will find Publicon quite intuitive, and you get the typesetting power of Tex/LaTeX with the GUI of Publicon. Refer to Wolfram's Web site for details on Publicon.

Overall Summary


All in all, I think Mathematica 5.1 has two benefits for O.R. professionals. The first is letting us help others: Most O.R. professionals, whether working in industry or in academia, have grown up using a large number of different tools. Normally, we use these tools ourselves. We usually do not provide tools for others to use. Mathematica 5.1 provides functionality to allow us to provide tools or programs we create to other, less analysis-oriented users including students. As such, the Web services and GUIKit in 5.1 can enable us to provide for others the formidable array analytical tools we use and create ourselves.

The second is that it provides more reasons for staying within the Mathematica environment regardless of where the data resides. There is a tremendous range of sources of data — the Web, SQL databases, binary files of various types — and Mathematica 5.1 lets you access these sources in a straightforward manner.

Still, although the rewards can be high, learning to use the software naturally (as opposed to a one-off) requires a serious commitment and investment of time. I wish I could do all my word processing and spreadsheet within Mathematica as well, so it could be my one piece of software other than e-mail. You can already do presentations from within Mathematica, and there is new database functionality in 5.1. With GUIKit, perhaps an "office suite" for the technical user is not too far in the future!

Product Information

Mathematica is as multi-platform as software can get. Wolfram's Web site sells it for a number of 32-bit platforms, namely Windows, Mac OS X and Linux PC. Also included are a number of 64-bit platforms. These include HP-UX, Solaris, IBM AIX, IRIX and Linux x86-64 bit. Thus, Mathematica 5.1 is available for most platforms with Mathematica 5 being the most current version on the remaining platforms.

Mathematica 5.1 is distributed by Wolfram Research through academic bookstores and through their Web site, www.wolfram.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. "Semester" and "annual" downloadable student versions are also available for limited time periods at low cost.

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)
• Semester and annual downloadable student versions: start at $44.95.
 
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 1,220)
• Student version: GBP 80 (EUR 128)
• Semester and annual downloadable student versions: start at GBP 20 or EUR 29.

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

Mathematica for the Classroom is available for pre-college education and community colleges at $195.

References


  1. Sodhi, M., "Mathematica 5 for operations research professionals," OR/MS Today, December 2003 (www.lionhrtpub.com/orms/orms-12-03/frswr.html).
  2. Sodhi, M., "What's up with Java?", OR/MS Today, February 1999 (www.lionhrtpub.com/orms/orms-2-99/cyberspace.html).



ManMohan S. Sodhi is a member of the operations management faculty at Cass Business School in London. He is also the software review editor for OR/MS Today.





  • Table of Contents
  • OR/MS Today Home Page


    OR/MS Today copyright © 2004 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 2004 by Lionheart Publishing, Inc. All rights reserved.