Mathematica

From Wikipedia, the free encyclopedia

Mathematica
Maintainer: Wolfram Research
Stable release: 5.2  (July 12, 2005) [+/-]
Preview release: 6.0  (n/a) [+/-]
OS: Cross-platform (list)
Use: Computer algebra system
License: Proprietary
Website: Mathematica homepage

Mathematica is a computer algebra system originally conceived by Stephen Wolfram, developed by a team of mathematicians and programmers that he assembled and led, and sold by his company Wolfram Research.

It is used extensively in the sciences — such as by college students, professionals, researchers, teachers, and sometimes highschool students — who often acquire it with an educational or company-based discount.

Mathematica is also a high-level programming language emulating multiple paradigms on top of term-rewriting.

Its logo is based on the stellated icosahedron.

Contents

[edit] Overview

A screenshot of the Mathematica graphical user interface
A screenshot of the Mathematica graphical user interface

Wolfram and his team started to work on the program in 1986 and released the first version June 23, 1988. The current version is 5.2 (released July 12, 2005). It is available on a wide variety of computer systems. Version 6 is due in early 2007.

The Mathematica programming language is based on term-rewriting and supports both functional and procedural programming (though functional code is much more efficient in general). It is implemented in an object-oriented variant of C, but the bulk of the extensive code library is actually written in the Mathematica language that can be used to extend the system. Typically, new code is added in the form of Mathematica "packages", i.e., text files written in the Mathematica language.

In the Mathematica system, the core language is interpreted by a kernel that performs the actual computations. The results are usually communicated to one of several front ends. Communication between the kernel and the front end (or any other client, like user-written programs) uses the MathLink protocol, often over a network. It is possible for several front end processes to connect to the same kernel, and for one front end to be connected to several kernels.

Unlike some other computer algebra systems, for example Maxima or Maple, Mathematica tries to apply the currently stored transformation rules as long as possible, looking for a fixed point. For this to be meaningful, absence of side-effects is beneficial (though not enforced), hence the similarity to functional programming. Functions and code are first-class and not opaque. Scoping is dynamic, but there are also some constructs that try to simulate lexical scope (all of these can easily be broken).

[edit] Features

Many of the useful features of Mathematica include:

  • Working with units, so it becomes difficult to make mistakes with physical calculations
  • Being bundled with many sub-packages with specialized functions, such as linear algebra, combinatorics, image processing, graphing, etc.
  • A LISP-like generality, with the ability to pass expressions and hold expressions unevaluated
  • Rewrite-rules as the building-block of the language, so one can for example replace all instances of arbitrarily complex terms with other terms (e.g. "plugging in values" for calculations, or changing an image/graph on-the-fly by modifying its code)

[edit] Language examples

The following Mathematica sequence will find the determinant of the 6×6 matrix whose i, j'th entry contains ij with all zero entries replaced as 1.

 In[1]:= Det[Array[Times, {6, 6}, 0] /. 0 -> 1]
 Out[1]= 0

So the determinant of such a matrix is 0 (i.e. it is singular).

The following numerically calculates the root of the equation ex = x2 + 2, starting at the point x = -1.

 In[2]:= FindRoot[Exp[x] == x^2 + 2, {x, -1}]
 Out[2]= {x -> 1.3190736768573652}

Integral and differential calculus is a strong point, in particular evaluation of integrals in terms of special functions. For example:

 In[3]:= Integrate[x/Sin[x], x]//OutputForm
 Out[3]= x (Log[1 - EI x] - Log[1 + EI x]) + I (PolyLog[2, -EI x] - PolyLog[2, EI x])

Here, E and I are the base of the natural logarithms and \sqrt{-1} respectively, and PolyLog[s,z] is the polylogarithm function \mathrm{Li}_s\left(z\right).

Many symbolic sums can be calculated. For example:

  In[4]:= Sum[z^k/k^s, {k, 1, Infinity}]
  Out[4]= PolyLog[s, z]

[edit] Multiple paradigms, one language

Mathematica permits multiple programming paradigmatic approaches to programming. Consider a simple example: we want a table of values of gcd(x, y) for 1 ≤ x ≤ 5, 1 ≤ y ≤ 5.

The most concise approach is to use one of the many specialized functions:

In[3]:= Array[GCD, {5, 5}]
Out[3]=  {{1, 1, 1, 1, 1}, {1, 2, 1, 2, 1}, {1, 1, 3, 1, 1}, {1, 2, 1, 4, 1}, {1, 1, 1, 1, 5}}

There are at least three other approaches to this:

In[4]:= Table[GCD[x, y], {x, 1, 5}, {y, 1, 5}]
Out[4]=  {{1, 1, 1, 1, 1}, {1, 2, 1, 2, 1}, {1, 1, 3, 1, 1}, {1, 2, 1, 4, 1}, {1, 1, 1, 1, 5}}

An APL-style approach:

In[5]:= Outer[GCD, Range[5], Range[5]]
Out[5]=  {{1, 1, 1, 1, 1}, {1, 2, 1, 2, 1}, {1, 1, 3, 1, 1}, {1, 2, 1, 4, 1}, {1, 1, 1, 1, 5}}

Outer corresponds to the outer product operator, Range corresponds to the iota operator. The Outer function permits any function, whether it be named, or anonymous, which are functions specified on the fly by using #n to specify the function argument and appending an &. The above function could be equivalently specified as Outer[GCD[#1, #2] &, Range[5], Range[5]], but Mathematica permits the above shortcut as well.

An iterative approach:

In[6]:= l1 = {}; (* initialize as empty list, since we want a list in the end *)
       For[i = 1, i <= 5, i++,
       l2 = {}; 
          For[j = 1, j <= 5, j++,
             l2 = Append[l2, GCD[i, j]] 
             ];                                      
          l1 = Append[l1, l2]; (* append the sublist, that is, the row *)
       ]; l1
Out[6]=  {{1, 1, 1, 1, 1}, {1, 2, 1, 2, 1}, {1, 1, 3, 1, 1}, {1, 2, 1, 4, 1}, {1, 1, 1, 1, 5}}

Observe that this solution is considerably larger than the previous ones.

[edit] Common structures, common manipulations

One guiding principle in Mathematica is a unified structure behind almost all objects representable in Mathematica. For example, the expression x4 + 1 if entered will be represented as if it were written:

In[7]:= x^4 + 1
Out[7]= 1+x4

If the FullForm command is used on this expression however:

In[8]:= FullForm[x^4 + 1]
Out[8]= Plus[1, Power[x, 4]]

Nearly all objects in Mathematica have the basic form head[e1, e2, ...] (which may be displayed or entered in some other fashion). For example, the head of the above example is Plus, and symbols such as x have form Symbol["x"]. Lists have this structure too, where the head is List.

The principle permits ordinary expressions unrelated to lists to be operated on with list operators:

In[9]:= Expand[(Cos[x] + 2 Log[x^11])/13][[2, 1]]
Out[9]= 2/13

The reverse can also occur -- lists can be modified to behave like ordinary expressions:

In[10]:= Map[Apply[Log, #] &, {{2, x}, {3, x}, {4, x}}]
Out[10]= {Log[x]/Log[2], Log[x]/Log[3], Log[x]/Log[4]}

where the Apply function changes the head of its second argument to that of the first, and Map behaves like the map higher-order function found in many functional languages.

Because of this equivalence between a regular mathematical object represented in Mathematica to that of a simple list structure, some built-in Mathematica functions permit threading, where functions map themselves over lists without much further specification. Indeed, Apply threads itself over lists when invoked as

In[11]:= Apply[Log, {{2,x}, {3,x}, {4,x}}, 1]
Out[10]= {Log[x]/Log[2], Log[x]/Log[3], Log[x]/Log[4]}

where the third argument being a 1 specifies that Apply replaces the heads of its argument only at the first level in the list, which is what we want, and is equivalent to the above example.

[edit] Front ends

Mathematica consists of two parts - a front end with which users interact and a kernel which performs the computations. The two communicate via the Mathlink protocol, which is discussed in another section. It is possible to use the kernel on one computer and the front end on another, although this is not how most people use Mathematica.

The default Mathematica front end features extensive layout and graphical capabilities, performs prettyprinting and offers a notebook metaphor - user input (both text and Mathematica input) as well as results sent by the kernel (including graphics and sound) are placed in a hierarchy of cells (as is the case for Maple), which also allows for outlining and sectioning of a document. Starting with version 3.0 of the software, notebooks are represented as expressions that can be manipulated by the kernel.

To allow those without Mathematica licenses to view Mathematica notebooks dedicated reader software was made available. This software, called MathReader can be downloaded free of charge. This does not use a Mathematica kernel, so new results cannot be computed.

All UNIX/Linux versions of Mathematica additionally include a command line front-end. An example of this is shown below.

% math
Mathematica 5.2 for Sun Solaris (UltraSPARC)
Copyright 1988-2005 Wolfram Research, Inc.
-- Terminal graphics initialized --

In[1]:= Solve[x^2 + 2 x - 9 == 0, x]

Out[1]= {{x -> -1 - Sqrt[10]}, {x -> -1 + Sqrt[10]}}

Old versions of Mathematica which run on MS-DOS had only a command line front end.

A screenshot of an HP iPAQ PDA accessing a Mathematica kernel is shown.
A screenshot of an HP iPAQ PDA accessing a Mathematica kernel is shown.

WITM, which is an acronym for Web Interface to Mathematica, is a web browser front end which is compatible with virtually any networked computer which has a web browser. This allows Mathematica to be used on devices like PDA's (e.g. Pocket PC or similar) for which there is no version of Mathematica available.

Several other front ends are also available, e.g., JMath or MASH, but the standard Mathematica front end is the most popular.

[edit] Connections with other applications

Communication with other applications occur through a protocol called Mathlink. It allows not only communication between the Mathematica kernel and front-end, but also provides a general interface between the kernel and arbitrary applications. Wolfram Research distributes freely a developer kit for linking applications written in the C programming language to the Mathematica kernel through MathLink. Two other components of Mathematica, whose underlying protocol is MathLink, allow developers to establish communication between the kernel and a Java or .NET program: J/Link and .NET/Link.

Using J/Link, a Java program can ask Mathematica to perform computations; also, a Mathematica program can load any Java class, manipulate Java objects and perform method calls, making it possible, for instance, to build Java graphical user interfaces from Mathematica. Similarly, a .NET software can invoke the kernel to perform calculations and send results back, and Mathematica developers can easily have access to .NET's functionality.

[edit] Mathematica on the Web

Wolfram Research also makes a program called webMathematica with which Web servers can add "interactive calculations and visualization to a website."

On Sloane's Online Encyclopedia of Integer Sequences, Mathematica and Maple are the two most often used CASs for which commands are provided with which to calculate the sequences; both of them have their own database fields on the OEIS.

[edit] Licensing and pricing

Mathematica is proprietary software protected by both trade secret and copyright law.

A regular single-user license for Mathematica 5.2 costs $1,880 for the Windows, Macintosh, or Linux.[1]; this includes one year of updates and technical support, a home use license, and a webMathematica Amateur license. Educational licenses are much cheaper. There are also various network and multi-user licenses. This is comparable to the other major supported commercial mathematics system, Maple.

[edit] Advantages

The standard Mathematica front end makes laying out computations very simple. For example, users may re-evaluate code by clicking on it and hitting shift-enter. Users may re-evaluate hierarchically-nested blocks of code by clicking on a set of braces and hitting shift-enter. This makes Mathematica ideal for tasks such as doing homework, as one error early in a computation can be fixed easily and the intermediate computations automatically redone. Compare this with Matlab's UNIX-shell approach, where redoing calculations requires finding them in your history and recopying them.

Additionally, Mathematica is able to handle arbitrary-precision numbers and rational numbers, as compared to other mathematics programs such as Matlab, Excel, and most standard programming languages.

Mathematica also has very generalized functions (for example, an outer product which takes any type of function), as well as a great variety of functions. As a higher-level multi-paradigm programming language, it requires much less code than most programming languages in order to write the same thing.

[edit] Criticisms

Wolfram Research forums and comp.soft-sys.math.mathematica newsgroup have been criticized for being moderated [1], which some argue slows down the speed at which assistance can be obtained from the community, though unmoderated independent forums also exist.

Mathematica data consists mostly of nested lists, it can be difficult to conceive the exact structure of a list if it has many dimensions. The default list structure reporting function, Dimensions[], requires the list given be rectangular (or "hyper"-rectangular).

Because of the functional nature of Mathematica programming, debugging code can be difficult as the error messages are somewhat obtuse and do not give a line number of function point at which the error occurred. A debugging framework is available, but it is part of the support package which has to be purchased at an additional cost. Some basic debugging functions (Sow and Reap) are available in the most recent versions of Mathematica, but the information they report may be difficult to use and understand for programmers unfamiliar with the style of programming.

In the first versions of Mathematica, performance for large numerical computations lagged way behind specialized software. One reason for this is that support for sparse matrices was added only in version 5.

[edit] Version history

Mathematica built on the ideas in Cole and Wolfram's earlier Symbolic Manipulation Program (SMP).

Wolfram has released the following versions:

  • Mathematica 1.0 (1988)
  • Mathematica 1.2 (1989)
  • Mathematica 2.0 (1991)
  • Mathematica 2.1 (1992)
  • Mathematica 2.2 (1993)
  • Mathematica 3.0 (1996)
  • Mathematica 4.0 (1999)
  • Mathematica 4.1 (2000)
  • Mathematica 4.2 (2002)
  • Mathematica 5.0 (2003)
  • Mathematica 5.1 (2004)
  • Mathematica 5.2 (2005)

[edit] See also

[edit] Footnotes

  1. ^ Mathematica pricing at Wolfram.com

[edit] External links

Wikibooks
Wikibooks has a book on the topic of