As has been noted in the introductory section of this Recommendation, mathematics can be distinguished by its use of a (relatively) formal language, mathematical notation. However, mathematics and its presentation should not be viewed as one and the same thing. Mathematical sums or products exist and are meaningful to many applications completely without regard to how they are rendered aurally or visually. The intent of the content markup in the Mathematical Markup Language is to provide an explicit encoding of the underlying mathematical structure of an expression, rather than any particular rendering for the expression.
There are many reasons for providing a specific encoding for content. Even a disciplined and systematic use of presentation tags cannot properly capture this semantic information. This is because without additional information it is impossible to decide whether a particular presentation was chosen deliberately to encode the mathematical structure or simply to achieve a particular visual or aural effect. Furthermore, an author using the same encoding to deal with both the presentation and mathematical structure might find a particular presentation encoding unavailable simply because convention had reserved it for a different semantic meaning.
The difficulties stem from the fact that there are many to one mappings from presentation to semantics and vice versa. For example the mathematical construct " H multiplied by e" is often encoded using an explicit operator as in H × e. In different presentational contexts, the multiplication operator might be invisible " H e", or rendered as the spoken word "times". Generally, many different presentations are possible depending on the context and style preferences of the author or reader. Thus, given " H e" out of context it may be impossible to decide if this is the name of a chemical or a mathematical product of two variables H and e.
Mathematical presentation also changes with culture and time: some expressions in combinatorial mathematics today have one
meaning to a Russian mathematician, and quite another to a French mathematician; see
Section 5.4.1 Notational Style Sheets for an example. Notations may lose currency, for example the use of musical sharp and flat symbols to denote maxima and minima
[Chaundy1954]. A notation in use in 1644 for the multiplication mentioned above was
H
e
[Cajori1928].
When we encode the underlying mathematical structure explicitly, without regard to how it is presented aurally or visually, we are able to interchange information more precisely with those systems that are able to manipulate the mathematics. In the trivial example above, such a system could substitute values for the variables H and e and evaluate the result. Further interesting application areas include interactive textbooks and other teaching aids.
The semantics of general mathematical notation is not a matter of consensus. It would be an enormous job to systematically codify most of mathematics - a task that can never be complete. Instead, MathML makes explicit a relatively small number of commonplace mathematical constructs, chosen carefully to be sufficient in a large number of applications. In addition, it provides a mechanism for associating semantics with new notational constructs. In this way, mathematical concepts that are not in the base collection of elements can still be encoded (Section 4.2.6 Syntax and Semantics).
The base set of content elements is chosen to be adequate for simple coding of most of the formulas used from kindergarten to the end of high school in the United States, and probably beyond through the first two years of college, that is up to A-Level or Baccalaureate level in Europe. Subject areas covered to some extent in MathML are:
arithmetic, algebra, logic and relations
calculus and vector calculus
set theory
sequences and series
elementary classical functions
statistics
linear algebra
It is not claimed, or even suggested, that the proposed set of elements is complete for these areas, but the provision for author extensibility greatly alleviates any problem omissions from this finite list might cause.
The design of the MathML content elements are driven by the following principles:
The expression tree structure of a mathematical expression should be directly encoded by the MathML content elements.
The encoding of an expression tree should be explicit, and not dependent on the special parsing of PCDATA or on additional processing such as operator precedence parsing.
The basic set of mathematical content constructs that are provided should have default mathematical semantics.
There should be a mechanism for associating specific mathematical semantics with the constructs.
The primary goal of the content encoding is to establish explicit connections between mathematical structures and their mathematical meanings. The content elements correspond directly to parts of the underlying mathematical expression tree. Each structure has an associated default semantics and there is a mechanism for associating new mathematical definitions with new constructs.
Significant advantages to the introduction of content-specific tags include:
Usage of presentation elements is less constrained. When mathematical semantics are inferred from presentation markup, processing agents must either be quite sophisticated, or they run the risk of inferring incomplete or incorrect semantics when irregular constructions are used to achieve a particular aural or visual effect.
It is immediately clear which kind of information is being encoded simply by the kind of elements that are used.
Combinations of semantic and presentation elements can be used to convey both the appearance and its mathematical meaning much more effectively than simply trying to infer one from the other.
Expressions described in terms of content elements must still be rendered. For common expressions, default visual presentations are usually clear. "Take care of the sense and the sounds will take care of themselves" wrote Lewis Carroll [Carroll1871]. Default presentations are included in the detailed description of each element occurring in Section 4.4 The Content Markup Elements.
To accomplish these goals, the MathML content encoding is based on the concept of an expression tree. A content expression tree is constructed from a collection of more primitive objects, referred to herein as containers and operators. MathML possesses a rich set of predefined container and operator objects, as well as constructs for combining containers and operators in mathematically meaningful ways. The syntax and usage of these content elements and constructions is described in the next section.
Since the intent of MathML content markup is to encode mathematical expressions in such a way that the mathematical structure of the expression is clear, the syntax and usage of content markup must be consistent enough to facilitate automated semantic interpretation. There must be no doubt when, for example, an actual sum, product or function application is intended and if specific numbers are present, there must be enough information present to reconstruct the correct number for purposes of computation. Of course, it is still up to a MathML processor to decide what is to be done with such a content-based expression, and computation is only one of many options. A renderer or a structured editor might simply use the data and its own built-in knowledge of mathematical structure to render the object. Alternatively, it might manipulate the object to build a new mathematical object. A more computationally oriented system might attempt to carry out the indicated operation or function evaluation.
The purpose of this section is to describe the intended, consistent usage. The requirements involve more than just satisfying the syntactic structure specified by an XML DTD. Failure to conform to the usage as described below will result in a MathML error, even though the expression may be syntactically valid according to the DTD.
In addition to the usage information contained in this section, Section 4.4 The Content Markup Elements gives a complete listing of each content element, providing reference information about their attributes, syntax, examples and suggested default semantics and renderings. The rules for using presentation markup within content markup are explained in Section 5.2.3 Presentation Markup Contained in Content Markup. An informal EBNF grammar describing the syntax for the content markup is given in Appendix B Content Markup Validation Grammar.
MathML content encoding is based on the concept of an expression tree. As a general rule, the terminal nodes in the tree represent basic mathematical objects, such as numbers, variables, arithmetic operations and so on. The internal nodes in the tree generally represent some kind of function application or other mathematical construction that builds up a compound object. Function application provides the most important example; an internal node might represent the application of a function to several arguments, which are themselves represented by the terminal nodes underneath the internal node.
The MathML content elements can be grouped into the following categories based on their usage:
constants and symbols
containers
operators and functions
qualifiers
relations
conditions
semantic mappings
These are the building blocks out of which MathML content expressions are constructed. Each category is discussed in a separate section below. In the remainder of this section, we will briefly introduce some of the most common elements of each type, and consider the general constructions for combining them in mathematically meaningful ways.
Content expression trees are built up from basic mathematical objects. At the lowest level,
leaf nodes are encapsulated in non-empty elements that define their type. Numbers and symbols are marked by the
token elements
cn and
ci. More elaborate constructs such as sets, vectors and matrices are also marked using elements to denote their types, but rather
than containing data directly, these
container elements are constructed out of other elements. Elements are used in order to clearly identify the underlying objects. In
this way, standard XML parsing can be used and attributes can be used to specify global properties of the objects.
The containers such as
<cn>12345</cn> ,
<ci>x</ci> and
<csymbol definitionURL="mySymbol.htm" encoding="text">S</csymbol>represent mathematical numbers , identifiers and externally defined symbols. Below, we will look at
operator elements such as
plus or
sin, which provide access to the basic mathematical operations and functions applicable to those objects. Additional containers
such as
set for sets, and
matrix for matrices are provided for representing a variety of common compound objects.
For example, the number 12345 is encoded as
<cn>12345</cn>
The attributes and
PCDATA content together provide the data necessary for an application to parse the number. For example, a default base of 10 is
assumed, but to communicate that the underlying data was actually written in base 8, simply set the
base attribute to 8 as in
<cn base="8">12345</cn>
while the complex number 3 + 4i can be encoded as
<cn type="complex-cartesian">3<sep/>4</cn>
Such information makes it possible for another application to easily parse this into the correct number.
As another example, the scalar symbol v is encoded as
<ci>v</ci>
By default,
ci elements represent elements from a commutative field (see
Appendix C Content Element Definitions). If a vector is intended then this fact can be encoded as
<ci type="vector">v</ci>
This invokes default semantics associated with the
vector element, namely an arbitrary element of a finite-dimensional vector space.
By using the
ci and
csymbol elements we have made clear that we are referring to a mathematical identifier or symbol but this does not say anything about
how it should be rendered. By default a symbol is rendered as if the
ci or
csymbol element were actually the presentation element
mi (see
Section 3.2.3 Identifier (mi)). The actual rendering of a mathematical symbol can be made as elaborate as necessary simply by using the more elaborate
presentational constructs (as described in
Chapter 3 Presentation Markup) in the body of the
ci or
csymbol element.
The default rendering of a simple
cn-tagged object is the same as for the presentation element
mn with some provision for overriding the presentation of the
PCDATA by providing explicit
mn tags. This is described in detail in
Section 4.4 The Content Markup Elements.
The issues for compound objects such as sets, vectors and matrices are all similar to those outlined above for numbers and
symbols. Each such object has global properties as a mathematical object that impact how it is to be parsed.
This may affect everything from the interpretation of operations that are applied to it to how to render
the symbols representing it. These mathematical properties are captured by setting attribute values
or by associating the properties with the object through the use of the semantics element.
The notion of constructing a general expression tree is essentially that of applying an operator to sub-objects. For example,
the sum
a +
b can be thought of as an application of the addition operator to two arguments
a and
b. In MathML, elements are used for operators for much the same reason that elements are used to contain objects. They are
recognized at the level of XML parsing, and their attributes can be used to record or modify the intended semantics. For example,
with the MathML
plus element, setting the
definitionURL and
encoding attributes as in
<plus definitionURL="http://www.example.com/VectorCalculus.htm"
encoding="text"/>
can communicate that the intended operation is vector-based.
There is also another reason for using elements to denote operators. There is a crucial semantic distinction between the function
itself and the expression resulting from applying that function to zero or more arguments which must be captured. This is
addressed by making the functions self-contained objects with their own properties and providing an explicit
apply construct corresponding to function application. We will consider the
apply construct in the next section.
MathML contains many pre-defined operator elements, covering a range of mathematical subjects. However, an important class
of expressions involve unknown or user-defined functions and symbols. For these situations, MathML provides a general
csymbol element, which is discussed below.
apply construct
The most fundamental way of building up a mathematical expression in MathML content markup is the
apply construct. An
apply element typically applies an operator to its arguments. It corresponds to a complete mathematical expression. Roughly speaking,
this means a piece of mathematics that could be surrounded by parentheses or
"logical brackets" without changing its meaning.
For example, (x + y) might be encoded as
<apply> <plus/> <ci> x </ci> <ci> y </ci> </apply>
The opening and closing tags of
apply specify exactly the scope of any operator or function. The most typical way of using
apply is simple and recursive. Symbolically, the content model can be described as:
<apply> op a b </apply>
where the
operands a and b are containers or other content-based elements themselves, and
op is an operator or function. Note that since
apply is a container, this allows
apply constructs to be nested to arbitrary depth.
An
apply may in principle have any number of operands:
<apply> op a b [c...] <apply>
For example, (x + y + z) can be encoded as
<apply> <plus/> <ci> x </ci> <ci> y </ci> <ci> z </ci> </apply>
Mathematical expressions involving a mixture of operations result in nested occurrences of
apply. For example,
a
x +
b would be encoded as
<apply>
<plus/>
<apply>
<times/>
<ci> a </ci>
<ci> x </ci>
</apply>
<ci> b </ci>
</apply>
There is no need to introduce parentheses or to resort to operator precedence in order to parse the expression correctly.
The
apply tags provide the proper grouping for the re-use of the expressions within other constructs. Any expression enclosed by an
apply element is viewed as a single coherent object.
An expression such as (F + G)(x) might be a product, as in
<apply>
<times/>
<apply>
<plus/>
<ci> F </ci>
<ci> G </ci>
</apply>
<ci> x </ci>
</apply>
or it might indicate the application of the function F + G to the argument x. This is indicated by constructing the sum
<apply> <plus/> <ci> F </ci> <ci> G </ci> </apply>
and applying it to the argument x as in
<apply>
<apply>
<plus/>
<ci> F </ci>
<ci> G </ci>
</apply>
<ci> x </ci>
</apply>
Both the function and the arguments may be simple identifiers or more complicated expressions.
In MathML 1.0 , another construction closely related to the use of the
apply element with operators and arguments was the
reln element. The
reln element was used to denote that a mathematical relation holds between its arguments, as opposed to applying an operator.
Thus, the MathML markup for the expression
x <
y was given in MathML 1.0 by:
<reln> <lt/> <ci> x </ci> <ci> y </ci> </reln>
In MathML 2.0, the
apply construct is used with all operators, including logical operators. The expression above becomes
<apply> <lt/> <ci> x </ci> <ci> y </ci> </apply>
in MathML 2.0. The use of
reln with relational operators is supported
for reasons of backwards compatibility, but deprecated. Authors creating new content are
encouraged to use
apply in all cases.
The most common operations and functions such as
plus and
sin have been predefined explicitly as empty elements (see
Section 4.4 The Content Markup Elements).
The definitionURL attribute can be used by the author to record
that a different sort of algebraic operation is intended. This allows essentially the same notation to be re-used for a
discussion taking place in a different algebraic domain.
Due to the nature of mathematics the notation must be extensible. The key to extensibility is the ability of the user to define new functions and other symbols to expand the terrain of mathematical discourse.
It is always possible to create arbitrary expressions, and then to use them as symbols in the language. Their properties can
then be inferred directly from that usage as was done in the previous section. However, such an approach would preclude being
able to encode the fact that the construct was a known symbol, or to record its mathematical properties except by actually
using it. The
csymbol element is used as a container to construct a new symbol in much the same way that
ci is used to construct an identifier. (Note that
"symbol" is used here in the abstract sense and has no connection with any presentation of the construct on screen or paper).
The difference in usage is that
csymbol should refer to some mathematically defined concept with an external definition referenced via the
definitionURL attribute, whereas
ci is used for identifiers that are essentially
"local" to the MathML expression
. The target of the
definitionURL attribute on the
csymbol element may encode the definition in any format; the particular encoding in use is given by the encoding attribute.
In contrast, the definitionURL attribute on a
ci element might be used to associate an identifier with another
sub-expression by referring to its id attribute.
This approach can be used, for example to indicate clearly that a particular
ci element is an instance of a ci element that has been declared to have some properties using the declare construct (see Section 4.4.2.8 Declare (declare))
or that it is an instance of a specific bound variable as declared
by a use of the bvar (see Section 4.4.5.6 Bound variable (bvar)) element.
To use
csymbol to describe a completely new function, we write for example
<csymbol definitionURL="http://www.example.com/VectorCalculus.htm"
encoding="text">
Christoffel
</csymbol>
The
definitionURL attribute specifies a URI that provides a written definition for the
Christoffel symbol. Suggested default definitions for the content elements of MathML appear in
Appendix C Content Element Definitions in a format based on OpenMath, although there is no requirement that a particular format be used. The role of the
definitionURL attribute is very similar to the role of definitions included at the beginning of many mathematical papers, and which often
just refer to a definition used by a particular book.
MathML 1.0 supported the use of the fn to encode the fact that a construct is explicitly being used as a function or operator. To record the fact that F+ G is being used semantically as if it were a function, it was encoded as:
<fn>
<apply>
<plus/>
<ci>F</ci>
<ci>G</ci>
</apply>
</fn>
This usage, although allowed in MathML 2.0 for reasons of backwards compatibility,
is now deprecated.
The fact that a construct is being used as an operator is clear from the position of the construct as the
first child of the
apply. If it is required to add additional information to the construct, it should be wrapped in a
semantics element, for example:
<semantics definitionURL="http://www.example.com/vectorfuncs/plus.htm"
encoding="Mathematica">
<apply>
<plus/>
<ci>F</ci>
<ci>G</ci>
</apply>
</semantics>
MathML 1.0 supported the use of
definitionURL with
fn to refer to external definitions for user-defined
functions. This usage, although allowed for reasons of backwards
compatibility, is deprecated in
MathML 2.0 in favor of using
csymbol to define the function, and then
apply to link the function to its arguments. For example:
<apply>
<csymbol definitionURL="http://www.example.org/function_spaces.html#my_def"
encoding="text">
BigK
</csymbol>
<ci>x</ci>
<ci>y</ci>
</apply>
Given functions, it is natural to have functional inverses. This is handled by the
inverse element.
Functional inverses can be problematic from a mathematical point of view in that they implicitly involve the definition of an inverse for an arbitrary function F. Even at the K-through-12 level the concept of an inverse F -1 of many common functions F is not used in a uniform way. For example, the definitions used for the inverse trigonometric functions may differ slightly depending on the choice of domain and/or branch cuts.
MathML adopts the view: if F is a function from a domain D to D', then the inverse G of F is a function over D' such that G(F(x)) = x for x in D. This definition does not assert that such an inverse exists for all or indeed any x in D, or that it is single-valued anywhere. Also, depending on the functions involved, additional properties such as F(G(y)) = y for y in D' may hold.
The
inverse element is applied to a function whenever an inverse is required. For example, application of the inverse sine function to
x, i.e. sin-1 (x), is encoded as:
<apply> <apply> <inverse/> <sin/> </apply> <ci> x </ci> </apply>
While
arcsin is one of the predefined MathML functions, an explicit reference to sin-1(x) might occur in a document discussing possible definitions of
arcsin.
Consider a document discussing the vectors
A = (a, b,
c) and
B = (d, e,
f), and later including the expression
V =
A +
B. It is important to be able to communicate the fact that wherever
A and
B are used they represent a particular vector. The properties of that vector may determine aspects of operators such as
plus.
The simple fact that A is a vector can be communicated by using the markup
<ci type="vector">A</ci>
but this still does not communicate, for example, which vector is involved or its dimensions.
The declare construct is used to associate
specific properties or meanings with an object. The actual declaration
itself is not rendered visually (or in any other form). However, it
indirectly impacts the semantics of all affected uses of the declared
object.
Declarations must occur at the beginning of a math
element. The scope of a declaration is the entire
math element in which the declaration is made.
The scope attribute of a declare
may be included but has no effect since the two possible values of
"local" or "global"
now have the same meaning. The "global" attribute value
is still allowed for backwards compatibility with MathML 1.0.,
but is deprecated in MathML 2.0.
The uses of the declare element range from
resetting default attribute values to associating an expression with a
particular instance of a more elaborate structure. Subsequent uses of the
original expression (within the scope of the declare) play the same semantic role as would the
paired object.
For example, the declaration
<declare>
<ci> A </ci>
<vector>
<ci> a </ci>
<ci> b </ci>
<ci> c </ci>
</vector>
</declare>
specifies that A stands for the particular vector (a,
b, c) so that subsequent uses of A as in
V = A + B can take this into account. When declare is used in this way, the actual encoding
<apply>
<eq/>
<ci> V </ci>
<apply>
<plus/>
<ci> A </ci>
<ci> B </ci>
</apply>
</apply>
remains unchanged but the expression can be interpreted properly as vector addition.
There is no requirement to declare an expression to stand for a specific object. For example, the declaration
<declare type="vector"> <ci> A </ci> </declare>
specifies that A is a vector without indicating the number of components or the values of specific components. Any attribute which is valid for the target element can be assigned in this way, with the possible values being the same as would ordinarily be assigned to such an object.
The lambda calculus allows a user to construct a function from a variable and an expression. For example, the lambda construct underlies the common mathematical idiom illustrated here:
Let f be the function taking x to x2 + 2
There are various notations for this concept in mathematical literature, such as
(x,
F(x)) = F or
(x,
[F]) =F, where x is a free variable in F.
This concept is implemented in MathML with the lambda element. A lambda construct with n
(possibly 0) internal variables is encoded by a lambda
element, where the first n children are bvar elements
containing the identifiers of the internal variables. This is followed by an
optional domainofapplication qualifier (see Section 4.2.3.2 Operators taking Qualifiers) and an expression defining the
function. The defining expression is typically an apply, but can also be
any expression.
The following constructs
(x, sin(x+1)):
<lambda>
<bvar><ci> x </ci></bvar>
<apply>
<sin/>
<apply>
<plus/>
<ci> x </ci>
<cn> 1 </cn>
</apply>
</apply>
</lambda>
To use
declare and
lambda to construct the function
f for which
f(
x) =
x2 +
x + 3 use:
<declare type="function">
<ci> f </ci>
<lambda>
<bvar><ci> x </ci></bvar>
<apply>
<plus/>
<apply>
<power/>
<ci> x </ci>
<cn> 2 </cn>
</apply>
<ci> x </ci>
<cn> 3 </cn>
</apply>
</lambda>
</declare>
The following markup declares and constructs the function J such that J(x, y) is the integral from x to y of t4 with respect to t.
<declare type="function">
<ci> J </ci>
<lambda>
<bvar><ci> x </ci></bvar>
<bvar><ci> y </ci></bvar>
<apply> <int/>
<bvar><ci> t </ci></bvar>
<lowlimit><ci> x </ci></lowlimit>
<uplimit><ci> y </ci></uplimit>
<apply>
<power/>
<ci>t</ci>
<cn>4</cn>
</apply>
</apply>
</lambda>
</declare>
The function J can then in turn be applied to an argument pair.
The last example of the preceding section illustrates the use of
qualifier elements
lowlimit,
uplimit, and
bvar in conjunction with the
int element. A number of common mathematical constructions involve additional data that is either
implicit in conventional notation, such as a bound variable, or thought of as part of the operator
rather than an argument, as is the case with the limits of a definite integral.
Content markup uses qualifier elements in conjunction with a number of operators, including integrals,
sums, series, and certain differential operators.
They may also be used by user defined functions such
as those added by making use of the csymbol element, or by use of lambda expressions.
Qualifier elements appear in the same
apply element with one of these operators. In general, they must appear in a
certain order, and their precise meaning depends on the operators being used. For details
about the use of qualifiers with the predefined operators see
Section 4.2.3.2 Operators taking Qualifiers. The role of qualifiers for
user defined functions is determined solely by the definition of each function.
A typical use of a qualifier is to identify a bound variable through use of
the bvar element, or to
restrict the values of the bound variable to a particular domain of application or in
some other way. For example, a domain of application can be given explicitly using
the domainofapplication element or by restricting the values of the
bound variable represented by the bvar element
to an interval or by conditions. A
condition element can be used to place restrictions directly on the bound variable.
This allows MathML to define sets by rule, rather than enumeration.
The following markup, for instance, encodes the set {x |
x < 1}:
<set>
<bvar><ci> x </ci></bvar>
<condition>
<apply>
<lt/>
<ci> x </ci>
<cn> 1 </cn>
</apply>
</condition>
<ci> x </ci>
</set>
Another typical use is the "lifting" of n-ary operators to "big operators", for instance the n-ary union operator to the union operator over sets, as the union of the U-complements over a family F of sets in this construction
<apply>
<union/>
<bvar><ci>S</ci></bvar>
<condition>
<apply><in/><ci>S</ci><ci>F</ci></apply>
</condition>
<apply><setdiff/><ci>U</ci><ci>S</ci></apply>
</apply>or this representation of the harmonic series:
<apply>
<plus/>
<domainofapplication><naturalnumbers/></domainofapplication>
<lambda>
<bvar><ci>x</ci></bvar>
<apply><quotient/><cn>1</cn><ci>x</ci></apply>
</lambda>
</apply>
This general construction gives natural lifted versions of the many
n-ary operators (including csymbol) as described
in Section 4.2.3.2 Operators taking Qualifiers.
The meaning of an expression of
the first form is that the operator is applied to the values of the
expression in the last child (where the bound variables vary as specified
in the qualifiers).
The meaning of a construction of the second form is that
the operator is applied to the set of values obtained by applying the last
child as a function to the elements of the set specified by
the domainofapplication qualifier.
While the primary role of the MathML content element set is to directly encode the mathematical structure of expressions independent of the notation used to present the objects, rendering issues cannot be ignored. Each content element has a default rendering, given in Section 4.4 The Content Markup Elements, and several mechanisms (including Section 4.3.3.2 General Attributes) are provided for associating a particular rendering with an object.
Containers provide a means for the construction of mathematical objects of a given type.
| Tokens |
ci,
cn,
csymbol |
| Constructors |
interval,
list,
matrix,
matrixrow,
set,
vector,
apply,
reln (deprecated),
fn (deprecated),
lambda,
piecewise, piece, otherwise
|
| Specials |
declare |
Token elements are typically the leaves of the MathML expression tree. Token elements are used to indicate mathematical identifiers, numbers and symbols.
It is also possible for the canonically empty operator elements such as
exp,
sin and
cos to be leaves in an expression tree. The usage of operator elements is described in
Section 4.2.3 Functions, Operators and Qualifiers.
The
cn element is the MathML token element used to represent numbers. The supported types of numbers include:
"real",
"integer",
"rational",
"complex-cartesian", and
"complex-polar", with
"real" being the default type. An attribute
base (with default value
"10") is used to help specify how the content is to be parsed. The content itself is essentially
PCDATA, separated by
<sep/> when two parts are needed in order to fully describe a number. For example, the real number 3 is constructed by
<cn type="real"> 3 </cn>, while the rational number 3/4 is constructed as
<cn type="rational"> 3<sep/>4 </cn>. The detailed structure and specifications are provided in
Section 4.4.1.1 Number (cn).
The
ci element, or
"content identifier" is used to construct a variable, or an identifier. A
type attribute indicates the type of object the symbol represents. Typically,
ci represents a real scalar, but no default is specified. The content is either
PCDATA or a general presentation construct (see
Section 3.1.6 Summary of Presentation Elements). For example,
<ci> <msub> <mi>c</mi> <mn>1</mn> </msub> </ci>
encodes an atomic symbol that displays visually as
c1
which, for purposes of content, is treated as a single symbol representing a real number.
The definitionURL attribute can be used to
identify special properties or to refer to
a defining instance of (for example) a bound variable.
The detailed structure and specifications are provided in
Section 4.4.1.2 Identifier (ci).
The
csymbol element, or
"content symbol" is used to construct a symbol whose semantics are not part of the core content elements provided by MathML,
but defined
outside of the MathML specification.
csymbol does not make any attempt to describe how to map the arguments occurring in any application of the function into a new MathML
expression. Instead, it depends on its
definitionURL attribute to point to a particular meaning, and the
encoding attribute to give the syntax of this definition. The content of a
csymbol is either
PCDATA or a general presentation construct (see
Section 3.1.6 Summary of Presentation Elements). For example,
<csymbol definitionURL="http://www.example.com/ContDiffFuncs.htm"
encoding="text">
<msup>
<mi>C</mi>
<mn>2</mn>
</msup>
</csymbol>
encodes an atomic symbol that displays visually as C2 and that, for purposes of content, is treated as a single symbol representing the space of twice-differentiable continuous functions. The detailed structure and specifications are provided in Section 4.4.1.3 Externally defined symbol (csymbol).
MathML provides a number of elements for combining elements into familiar compound objects. The compound objects include things like lists and sets. Each constructor produces a new type of object.
The
interval element is described in detail in
Section 4.4.2.4 Interval (interval). It denotes an interval on the real line with the values represented by its children as end points. The
closure attribute is used to qualify the type of interval being represented. For example,
<interval closure="open-closed"> <ci> a </ci> <ci> b </ci> </interval>
represents the open-closed interval often written (a, b].
The
set and
list elements are described in detail in
Section 4.4.6.1 Set (set) and
Section 4.4.6.2 List (list). Typically, the child elements of a possibly empty
list element are the actual components of an ordered
list. For example, an ordered list of the three symbols
a,
b, and
c is encoded as
<list> <ci> a </ci> <ci> b </ci> <ci> c </ci> </list>
Sets and lists can also be constructed by evaluating a function over a domain of
application, each evaluation corresponding to a term of the set or list. In the most
general form a domain is explicitly specified by
a domainofapplication element together with optional bvar elements.
Qualifications involving a domainofapplication element can be abbreviated
in several ways as described in Section 4.2.3.2 Operators taking Qualifiers. For example, a bvar and a
condition element can be used to define lists
where membership depends on satisfying certain conditions.
An
order attribute can be used to specify what ordering is to be used. When the nature of the child elements permits, the ordering
defaults to a numeric or lexicographic ordering.
Sets are structured much the same as lists except that there is no implied ordering and the
type of set may be
"normal" or
"multiset" with
"multiset" indicating that repetitions are allowed.
For both sets and lists, the child elements must be valid MathML content elements. The type of the child elements is not restricted. For example, one might construct a list of equations, or of inequalities.
The
matrix element is used to represent mathematical matrices. It is described in detail in
Section 4.4.10.2 Matrix (matrix). It has zero or more child elements, all of which are
matrixrow elements. These in turn expect zero or more child elements that evaluate to algebraic expressions or numbers. These sub-elements
are often real numbers, or symbols as in
<matrix> <matrixrow> <cn> 1 </cn> <cn> 2 </cn> </matrixrow> <matrixrow> <cn> 3 </cn> <cn> 4 </cn> </matrixrow> </matrix>
The
matrixrow elements must always be contained inside of a matrix, and all rows in a given matrix must have the same number of elements.
Note that the behavior of the
matrix and
matrixrow elements is substantially different from the
mtable and
mtr presentation elements.
A matrix can also be constructed by evaluating a bivariate function over a specific domain of
application, each evaluation corresponding to an entry in the matrix. In its most
general form a domain of application is explicitly specified by
a domainofapplication element and a function which when evaluated at points of the domain
produces entries in the matrix. Optionally the domainofapplication
can be augmented by bvar elements and an
algebraic expression expressed in terms of them.
Qualifications defined by a domainofapplication element can be abbreviated
in several ways as described in Section 4.2.3 Functions, Operators and Qualifiers.
The
vector element is described in detail in
Section 4.4.10.1 Vector (vector). It constructs vectors from an
n-dimensional vector space so that its
n child elements typically represent real or complex valued scalars as in the three-element vector
<vector>
<apply>
<plus/>
<ci> x </ci>
<ci> y </ci>
</apply>
<cn> 3 </cn>
<cn> 7 </cn>
</vector>
A vector can also be constructed by evaluating a function over a specific domain of
application, each evaluation corresponding to an entry in the vector. In its most
general form a domain is explicitly specified by
a domainofapplication element and a function. Optionally the domainofapplication
can be augmented by a bvar element and an
algebraic expression expressed in terms of it.
Qualifications defined by a domainofapplication element can be abbreviated
in several ways as described in Section 4.2.3 Functions, Operators and Qualifiers.
The
apply element is described in detail in
Section 4.4.2.1 Apply (apply). Its purpose is to apply a function or operator to its arguments to produce an expression representing an element of the
codomain of the function. It is involved in everything from forming sums such as
a +
b as in
<apply> <plus/> <ci> a </ci> <ci> b </ci> </apply>
through to using the sine function to construct sin(a) as in
<apply> <sin/> <ci> a </ci> </apply>
or constructing integrals. Its usage in any particular setting is determined largely by the properties of the function (the first child element) and as such its detailed usage is covered together with the functions and operators in Section 4.2.3 Functions, Operators and Qualifiers.
The
reln element is described in detail in
Section 4.4.2.2 Relation (reln). It was used in MathML 1.0 to construct an expression such as
a =
b, as in
<reln><eq/> <ci> a </ci> <ci> b </ci> </reln>
indicating an intended comparison between two mathematical values.
MathML 2.0 takes the view that this should be regarded as the application of a Boolean function, and as such could be constructed
using
apply. The use of
reln with logical operators is supported
for reasons of backwards compatibility, but deprecated in favor of
apply.
The
fn element was used in MathML 1.0 to make
explicit the fact that an expression is being used as a function or
operator. This is allowed in MathML 2.0 for backwards compatibility,
but is deprecated, as the use of
an expression as a function or operator is clear from its position as
the first child of an
apply.
fn is discussed in detail in
Section 4.4.2.3 Function (fn).
The lambda element is used to construct a user-defined function from an expression.
The last child is an expression defining the function in terms of the bound variables
declared by the bvar and any domainofapplication (see Section 4.2.3.2 Operators taking Qualifiers)
elements coming before it. The last element is typically an
apply element, but can also be any container element.
The following constructs
(x, sin
x)
<lambda>
<bvar><ci> x </ci></bvar>
<apply>
<sin/>
<ci> x </ci>
</apply>
</lambda>
The following constructs the constant function
(x, 3)
<lambda> <bvar><ci> x </ci></bvar> <cn> 3 </cn> </lambda>
The
piecewise,
piece,
otherwise
elements are used to support "piecewise" declarations of the form "
H(x) = 0 if x less than 0,
H(x) = x otherwise".
<piecewise>
<piece>
<cn> 0 </cn>
<apply><lt/><ci> x </ci> <cn> 0 </cn></apply>
</piece>
<otherwise>
<ci> x </ci>
</otherwise>
</piecewise>
The piecewise elements are discussed in detail in
Section 4.4.2.16 Piecewise declaration
(piecewise, piece,
otherwise)
.
The
declare construct is described in detail in
Section 4.4.2.8 Declare (declare). It is special in that its entire purpose is to modify
the semantics of other objects. It is not rendered visually or aurally.
The need for declarations arises any time a symbol (including more general presentations) is being used to represent an instance of an object of a particular type. For example, you may wish to declare that the symbolic identifier V represents a vector. The single argument form can be used to set properties of objects by setting the default values of implied attribute values to specific values.
The declaration
<declare type="vector"><ci>V</ci></declare>
resets the default type attribute of
<ci>V</ci> to
"vector" for all affected occurrences of
<ci>V</ci>. This avoids having to write
<ci type="vector">V</ci> every time you use the symbol.
More generally,
declare can be used to associate expressions with specific content. For example, the declaration
<declare>
<ci>F</ci>
<lambda>
<bvar><ci> U </ci></bvar>
<apply>
<int/>
<bvar><ci> x </ci></bvar>
<lowlimit><cn> 0 </cn></lowlimit>
<uplimit><ci> a </ci></uplimit>
<ci> U </ci>
</apply>
</lambda>
</declare>
associates the symbol
F with a new function defined by the
lambda construct. Within the scope where the declaration is in effect, the expression
<apply> <ci>F</ci> <ci> U </ci> </apply>
stands for the integral of U from 0 to a.
The
declare element can also be used to change the definition of a function or operator. For example, if the URL
http://.../MathML:noncommutplus described a non-commutative plus operation encoded in Maple syntax, then the declaration
<declare definitionURL="http://.../MathML:noncommutplus"
encoding="Maple">
<plus/>
</declare>
would indicate that all affected uses of
plus are to be interpreted as having that definition of
plus.
The operators and functions defined by MathML can be divided into categories as shown in the table below.
| unary arithmetic |
factorial,
minus,
abs,
conjugate,
arg,
real,
imaginary,
floor,
ceiling
|
| unary logical |
not |
| unary functional |
inverse,
ident,
domain,
codomain,
image
|
| unary elementary classical functions |
sin,
cos,
tan,
sec,
csc,
cot,
sinh,
cosh,
tanh,
sech,
csch,
coth,
arcsin,
arccos,
arctan,
arccosh,
arccot,
arccoth,
arccsc,
arccsch,
arcsec,
arcsech,
arcsinh,
arctanh,
exp,
ln,
log |
| unary linear algebra |
determinant,
transpose |
| unary calculus and vector calculus |
divergence,
grad,
curl,
laplacian |
| unary set-theoretic |
card |
| binary arithmetic |
quotient,
divide,
minus,
power,
rem |
| binary logical |
implies,
equivalent,
approx |
| binary set operators |
setdiff |
| binary linear algebra |
vectorproduct,
scalarproduct,
outerproduct |
| n-ary arithmetic |
plus,
times,
max,
min,
gcd,
lcm
|
| n-ary statistical |
mean,
sdev,
variance,
median,
mode |
| n-ary logical |
and,
or,
xor |
| n-ary linear algebra |
selector |
| n-ary set operator |
union,
intersect,
cartesianproduct
|
| n-ary functional |
fn(deprecated),
compose |
| integral, sum, product operators |
int,
sum,
product |
| differential operator |
diff,
partialdiff |
| quantifier |
forall,
exists |
From the point of view of usage, MathML regards functions (for example
sin and
cos) and operators (for example
plus and
times) in the same way. MathML predefined functions and operators are all canonically empty elements.
Note that the
csymbol element can be used to construct a user-defined symbol that can be used as a function or operator.
MathML functions can be used in two ways. They can be used as the operator within an
apply element, in which case they refer to a function evaluated at a specific value. For example,
<apply> <sin/> <cn>5</cn> </apply>
denotes a real number, namely sin(5).
MathML functions can also be used as arguments to other operators, for example
<apply> <plus/><sin/><cos/> </apply>
denotes a function, namely the result of adding the sine and cosine functions in some function space. (The default semantic
definition of
plus is such that it infers what kind of operation is intended from the type of its arguments.)
The number of child elements in the apply is defined by the element in the first (i.e. operator) position after taking into account the use
of qualifiers as described in Section 4.2.3.2 Operators taking Qualifiers.
Unary operators are followed by exactly one other child element within the
apply.
Binary operators are followed by exactly two child elements.
N-ary operators are followed by any number of child elements. Alternatively, their operands may be generated by allowing a function or expression to vary over a domain of application.
Some operators have multiple classifications depending on how they are used. For example the
minus operator can be both unary and binary.
Integral, sum, product and differential operators are discussed below in Section 4.2.3.2 Operators taking Qualifiers.
The table below contains the qualifiers and the predefined operators defined as taking qualifiers in MathML.
| qualifiers |
lowlimit,
uplimit,
bvar,
degree,
logbase,
interval,
condition,
domainofapplication,
momentabout
|
| operators |
int,
sum,
product,
root,
diff,
partialdiff,
limit,
log,
moment
forall,
exists
|
| n-ary operators |
plus,
times,
max,
min,
gcd,
lcm,
mean,
sdev,
variance,
median,
mode,
and,
or,
xor,
union,
intersect,
cartesianproduct,
compose,
eq,
leq,
lt,
geq,
gt
|
| user defined operators |
csymbol,
ci
|
Operators taking qualifiers are canonically empty functions that differ from ordinary empty functions only in that
they support the use of special qualifier elements to specify their meaning more fully.
Qualifiers always follow the operator and precede any arguments that are present.
If more than one qualifier is present, they appear in the order
bvar,
lowlimit,
uplimit,
interval,
condition,
domainofapplication,
degree,
momentabout,
logbase. A typical example is:
<apply> <int/> <bvar><ci>x</ci></bvar> <lowlimit><cn>0</cn></lowlimit> <uplimit><cn>1</cn></uplimit> <apply><power/><ci>x</ci><cn>2</cn></apply> </apply>
The (lowlimit,uplimit) pair, the interval and the condition are all shorthand notations
specifying a particular domain of application and should not be used if domainofapplication is used.
These shorthand notations are provided as they correspond to common usage cases and map more easily to familiar presentations.
For example, the lowlimit, uplimit pair can be used where explicit upper and
lower limits and a bound variable are all known, while an interval can be used in the same situation
but without an explicit bound variable as in:
<apply> <int/> <interval><cn>0</cn><cn>1</cn></interval> <sin/> </apply>
The condition qualifier corresponds to situations where the domain of application is a set described by
simple conditions placed directly on the bound variable(s). (Such conditions are often displayed in place of a lower bound.)
An example of the use of condition is:
<apply>
<int/>
<bvar><ci>x</ci></bvar>
<condition>
<apply><in/><ci>x</ci><ci type="set">C</ci></apply>
</condition>
<apply><sin/><ci>x</ci></apply>
</apply>The most general domain qualifier is the domainofapplication.
It is used to provide the name of or a description of
the set over which the operation is to take place and should be used explicitly whenever there is
danger of confusing the role of one of the short forms such as in an expression with
multiple interval elements. It can be used to write an expression for the integral a function over a named set
as in
<apply>
<int/>
<domainofapplication>
<ci type="set">C</ci>
</domainofapplication>
<ci type="function">f</ci>
</apply>
The domainofapplication element can also be used with bound variables so that
<apply> <int/> <bvar><ci>x</ci></bvar> <lowlimit><cn>0</cn></lowlimit> <uplimit><cn>1</cn></uplimit> <apply><power/><ci>x</ci><cn>2</cn></apply> </apply>
can be written as:
<apply>
<int/>
<bvar><ci>x</ci></bvar>
<domainofapplication>
<set>
<bvar><ci>t</ci></bvar>
<condition>
<apply>
<and/>
<apply><leq/><cn>0</cn><ci>t</ci></apply>
<apply><leq/><ci>t</ci><cn>1</cn></apply>
</apply>
</condition>
<ci>t</ci>
</set>
</domainofapplication>
<apply><power/><ci>x</ci><cn>2</cn></apply>
</apply>This use extends to multivariate domains by using extra bound variables and a domain corresponding to a cartesian product as in
<apply>
<int/>
<bvar><ci>x</ci></bvar>
<bvar><ci>y</ci></bvar>
<domainofapplication>
<set>
<bvar><ci>t</ci></bvar>
<bvar><ci>u</ci></bvar>
<condition>
<apply>
<and/>
<apply><leq/><cn>0</cn><ci>t</ci></apply>
<apply><leq/><ci>t</ci><cn>1</cn></apply>
<apply><leq/><cn>0</cn><ci>u</ci></apply>
<apply><leq/><ci>u</ci><cn>1</cn></apply>
</apply>
</condition>
<list><ci>t</ci><ci>u</ci></list>
</set>
</domainofapplication>
<apply>
<times/>
<apply><power/><ci>x</ci><cn>2</cn></apply>
<apply><p