Legacy Documentation

Mathematica® Teacher's Edition (2002)

This is documentation for an obsolete product.
Current products and services
 Documentation /  Mathematica Teacher's Edition /  The Teacher's Book /  Interlude 2: Packages and Statistics /  Packages /

23.1 Mathematica TE Packages

One of the most important features of Mathematica TE is that it is an extensible system. There is a certain amount of mathematical and other functionality that is built into Mathematica TE. But by using the Mathematica TE language, it is always possible to add more functionality.
For many kinds of calculations, what is built into the standard version of Mathematica TE will be quite sufficient. However, if you work in a particular specialized area, you may find that you often need to use certain functions that are not built into Mathematica TE.
In such cases, you may well be able to find a Mathematica TE package that contains the functions you need. Mathematica TE packages are files written in the Mathematica TE language. They consist of collections of Mathematica TE definitions that "teach" Mathematica TE about particular application areas.

Reading in Mathematica packages.

If you want to use functions from a particular package, you must first read the package into Mathematica TE. The details of how to do this are discussed in Section 30.1.

Elementary standard packages.

Some intermediate standard packages.

Mathematica TE uses the notion of "contexts" to specify packages in a way that is independent of the computer system being used. Contexts in Mathematica TE work somewhat like file directories in many operating systems. The name of a context ends with `, the backquote or grave accent character (ASCII decimal code 96), which is called a "context mark" in Mathematica TE.
Like directories in many operating systems, contexts in Mathematica TE can be hierarchical. Thus, for example, ``` can be a context name.
There are a number of subtleties associated with such issues as conflicts between names of functions in different packages. An important point to note is that you must not refer to a function that you will read from a package before actually reading in the package. If you do this by mistake, you will have to execute the command Remove["function-name"] to get rid of the function before you read in the package that defines it. If you do not call Remove, Mathematica TE will use "your" version of the function, rather than the one from the package.

Just mentioning QuarterTone before loading in the package where it is defined will block its real definition.

In[1]:= QuarterTone

Out[1]=

This command reads in the Mathematica TE package. The error message warns us about the problem.

In[2]:= <<Miscellaneous`Music`

If you try to use QuarterTone now, you don't get the value of QuarterTone as defined in the package.

In[3]:= QuarterTone

Out[3]=

This removes the shadowing QuarterTone. Note the need for double quotes.

In[4]:= Remove["QuarterTone"]

Now you get the definition of QuarterTone as given in the package.

In[5]:= QuarterTone

Out[5]=

You can explicitly tell Mathematica TE to read in a package at any point using the command <<context`. Often, however, you want to set it up so that a particular package is read in only if it is needed. The command Needs["context`"] tells Mathematica TE to read in a package if it has not been read in before. This is the preferred way to load the standard packages.

This command reads in a particular Mathematica TE package only if it wasn't read before.

In[6]:= Needs["Graphics`Shapes`"]

These are the objects defined in the package.

In[7]:= ?Graphics`Shapes`*

AffineShape PerforatePolygons
Cone RotateShape
Cylinder ShrinkPolygons
DoubleHelix Sphere
Helix Torus
MoebiusStrip TranslateShape
OutlinePolygons WireFrame

One of them is a Moebius strip.

In[8]:= Show[Graphics3D[MoebiusStrip[]]]

Out[8]=

The fact that Mathematica TE can be extended using packages means that the boundary of exactly what is "part of Mathematica TE" is quite blurred. As far as usage is concerned, there is actually no difference between functions defined in packages and functions that are fundamentally built into Mathematica TE.
In fact, a fair number of the functions described in this book are actually implemented as Mathematica TE packages. However, on most Mathematica TE systems, the necessary packages have been preloaded, so that the functions they define are always present. (On some systems with severe memory limitations, even these packages may be loaded only on request.)
As a practical matter, the functions that should be considered "part of Mathematica TE" are probably those that are present in all Mathematica TE systems. It is these functions that are primarily discussed in this book.
Nevertheless, most versions of Mathematica TE come with a standard set of Mathematica TE packages, which contain definitions for many more functions. Some of these functions are mentioned in this book. But to get them, you must usually read in the necessary packages explicitly.
Of course, it is possible to set your Mathematica TE system up so that particular packages are preloaded, or are automatically loaded when needed. If you do this, then there may be many functions that appear as standard in your version of Mathematica TE but are not documented in this book.
One point that should be mentioned is the relationship between packages and notebooks. Both are stored as files on your computer system and both can be read into Mathematica TE. However, a notebook is intended to be displayed, typically with a notebook interface, while a package is intended only to be used as Mathematica TE input. Many notebooks in fact contain sections that can be considered as packages and contain sequences of definitions intended for input to Mathematica TE.

Other Mathematica functions related to packages and contexts. (See Section 3.2.)