Containers and Operators

Prefix Notation

Computer languages typically employ either prefix, infix, or postfix notation
to capture the idea of applying an operator to arguments. For example,
Postscript and Hewlett-Packard calculators use postfix notation. Most programing
languages and computer algebra systems use the infix notation we are accustomed
to seeing in print. However, the computer language LISP uses prefix notation,
which also corresponds more closely to many natural language constructions like
"f of x" and "subtract 5 from 8". For this and other
reasons, MathML content mark-up also uses prefix notation.

A pleasant consequence of using prefix notation is that parentheses are no
longer necessary. Using infix notation, we must use parentheses to distinguish (x
- y) / 2 from x - (y / 2). However, in MathML, the order of
operations is clear from the prefix notation, so parentheses aren't necessary.

This example also introduces the fundamental apply element. The huge
majority of content elements represent either operators or mathematical data
types, and it is the apply element's job to group operators with
arguments. The apply element expects an operator schema as it first
child, and interprets the remaining children as the arguments of that operator.

Most MathML operators and functions are represented by empty elements like <cos/>
and <intersect/>. However, expressions such as <apply><compose/><ci>f</ci><ci>g</ci></apply>
can also be used as operators.

The examples also illustrate the use of content mark-up's only token
elements, ci and cn. These elements represent identifiers and
numbers, respectively. Since functions and operators are represented by
elements, no "co" element is needed. However there is a csymbol
token for less-common symbols and operators with a well-defined mathematical
usage, but for which there are no pre-defined content MathML elements.

In MathML, an identifier is any kind of name or label. In content
mark-up, this usually means things such as variables and function names. A type
attribute on the ci element can be used to specify the type of object
which an identifier represents.

The cn element is primarily designed to mark-up integers, rational,
real or complex numbers. However, any kind of character data is permitted in the
cn tag, so it is possible to mark-up expressions like <cn>xii</cn>.
The type attribute specifies what kind of number the element encodes.
Similarly, the base attribute can be used to specify that the encoding is
to a base other than 10, such as octal or hexadecimal.

Containers

Token elements represent identifiers and numbers. Of course, an identifier
can refer to any kind of mathematical object, but in the case of common objects
like vectors and sets, it would be nice to directly encode the structure of the
object as well as its name. For this, new elements are needed to represent other
kinds of mathematical objects and data types.

MathML uses container elements to represent basic mathematical
objects and data types. In general, container elements represent things like
sets which are constructed out of other data. The main examples are sets,
intervals, vectors, and matrices.

<set> [<elt1> <elt2> ... | <condition>]
</set>

The set element constructs a mathematical set whose elements are
specified by the set element's children. This can be done in two
ways. The children can either be a list of tokens and containers which
represent the individual elements of the set, or the set elements can be
specified by a single condition child element. The condition
element is discussed below, and encodes expressions like "all x such
that x < 2".

<interval> <pt1> <pt2>
</interval>

Intervals in the real line can be specified with the interval
element. It expects exactly two children elements, which encode the end
points. The closure attribute determines which of the end points lie
in the interval, and can have the values "open",
"closed", "open-closed" and "closed-open". The
default is closed.

<vector> <elt1> <elt2> ...
</vector>

A vector element constructs a vector whose components are given in
order by its children. By convention, in MathML vectors are column vectors
for matrix multiplication.

<matrix> <row1> <row2> ...
</matrix>

Matrices actually require two elements, matrix and matrixrow.
Although matrix rows are a little odd to single out from a mathematical
viewpoint, they are necessary crutch for encoding matrices. A matrix
element expects any number of children, but they have to all be matrixrow
elements. The children of the matrixrow elements represent the
individual entries in the matrix. All matrix rows should have the same
number of elements.

Operators, Functions and Relations

There are about 90 empty operator elements in content markup, which
represent commonly-used functions and operators. They are grouped into broad
categories: arthimetic, algebra, logic, calculus, set theory, and so on. To see
the full list, take a look at the summary of Content
Elements.

Recall that because of MathML's prefix notation, there is
basically no difference between functions and operators; in common usage, we
tend to call operators which are traditionally written with prefix notation
"functions," like sin x. But from the point of view of MathML,
they are both operators which may be applied to arguments.

Expression:

Markup:

<apply><plus/>
<apply><sin/><ci>x</ci></apply>
<cn>9</cn>
</apply>

Note that the parentheses around the x do not explicitly appear in the
MathML mark-up; a renderer like WebEQ would typically use some kind of heuristic
for deciding when parentheses are visually appropriate, but they are superfluous
from the point of view of capturing the meaning of the expression.

Operators and functions are both applied to arguments using the apply
element. MathML does single out relations from other functions and operators,
even though they could be viewed a functions which return truth values. Examples
of relations are eq, leq, and subset. They are applied to
arguments using the reln element much as operators are applied to
arguments using the apply element.

Expression:

Markup:

<reln> <eq/>
<ci>x</ci>
<cn>1</cn>
</reln>

Qualifiers

A handful of operators are meant to be used in conjunction with qualifier
elements. For example, qualifier elements are used to specify the limits for the
integral operator.

The most obvious group of qualifier elements are those used with the
int, sum, and prod elements. All three of these operators
have a notion of a lower limit, an upper limit, and a bound variable. In MathML,
qualifiers are used to specify these additional parameters, as is illustrated in
this example:

Qualifier elements are examples of MathML idioms. Math is full of
examples of specialized and exceptional notation. Here and there, MathML has had
to adopt a few specialized constructions, like qualifiers, to deal with them.

One such idiom is the use of the condition element to specify the
elements of a set:

Some other less common idioms involve using lambda expressions in
function declarations, and using quantifiers with log and limit.

The semantics element

The last important thing we need to look at is the semantics element.
Content mark-up has two drawbacks: it doesn't include everything you might need,
and it doesn't always display the way you would like. The semantics
element addresses both of these problems.

When you use content markup, you have to trust a renderer like WebEQ to put
your expression on the screen in a reasonable way. Inevitably, this causes
problems -- you want to use prime notation for derivatives, like f'(x),
while WebEQ renders this as df/dx, and so on.

To remedy this, you can use the semantics element to specify both the
presentation mark-up and content mark-up for an expression separately.

It is also possible to use the semantics tag to extend MathML. The special annotation
element can serve as a wrapper for any kind of semantic information, such as
computer algebra input or links to other references. By binding an annotation
together with a MathML expression, one can send additional information along for
the ride, and specialized renderers that understand it can take advantage of it.

The "oogl" annotation in the example above allows an application
that uses the Object Oriented Graphics Library to draw a three-dimensional
representation of the surface described by the equation, a sphere with radius
one centered at the origin.

Next Steps

Here are the main points from this section:

MathML content markup uses a prefix notation style. Operators are
applied to arguments using the apply element. There are many
predefined operator elements like sin, and you can create
user-defined operators and functions with the fn element.

Mathematical objects and data types are represented by token
elements ci and cn, or by container elements like set.

There are a number of MathML idioms to handle special cases, like
the use of qualifier schema such as lowlimit with the int
operator,

You can use the semantics element to specify both presentation
mark-up for display, and content mark-up for evaluation.

Congratulations! You have now covered the MathML fundamentals, and it is time
to put your knowledge to work. A good way to get started is to is to download a
copy of WebEQ and start putting math on the Web. You can download a free, 30-day
evaluation or purchase a copy using our Online
Ordering System.