4 Content Markup

Overview: Mathematical Markup Language (MathML) Version 2.0 (2nd Edition)
Previous: 3 Presentation Markup
Next: 5 Combining Presentation and Content Markup

4 Content Markup
    4.1 Introduction
        4.1.1 The Intent of Content Markup
        4.1.2 The Scope of Content Markup
        4.1.3 Basic Concepts of Content Markup
    4.2 Content Element Usage Guide
        4.2.1 Overview of Syntax and Usage
            4.2.1.1 Constructing Mathematical Objects
            4.2.1.2 Constructing General Expressions
            4.2.1.3 The apply construct
            4.2.1.4 Explicitly defined functions and operators
            4.2.1.5 The inverse construct
            4.2.1.6 The declare construct
            4.2.1.7 The lambda construct
            4.2.1.8 The use of qualifier elements and the condition construct
            4.2.1.9 Rendering of Content elements
        4.2.2 Containers
            4.2.2.1 Tokens
            4.2.2.2 Constructors
            4.2.2.3 Special Constructs
        4.2.3 Functions, Operators and Qualifiers
            4.2.3.1 Predefined functions and operators
            4.2.3.2 Operators taking Qualifiers
        4.2.4 Relations
        4.2.5 Conditions
            4.2.5.1 Examples
        4.2.6 Syntax and Semantics
        4.2.7 Semantic Mappings
        4.2.8 Constants and Symbols
        4.2.9 MathML element types
    4.3 Content Element Attributes
        4.3.1 Content Element Attribute Values
        4.3.2 Attributes Modifying Content Markup Semantics
            4.3.2.1 base
            4.3.2.2 closure
            4.3.2.3 definitionURL
            4.3.2.4 encoding
            4.3.2.5 nargs
            4.3.2.6 occurrence
            4.3.2.7 order
            4.3.2.8 scope
            4.3.2.9 type
        4.3.3 Attributes Modifying Content Markup Rendering
            4.3.3.1 type
            4.3.3.2 General Attributes
    4.4 The Content Markup Elements
        4.4.1 Token Elements
            4.4.1.1 Number (cn)
            4.4.1.2 Identifier (ci)
            4.4.1.3 Externally defined symbol (csymbol)
        4.4.2 Basic Content Elements
            4.4.2.1 Apply (apply)
            4.4.2.2 Relation (reln)
            4.4.2.3 Function (fn)
            4.4.2.4 Interval (interval)
            4.4.2.5 Inverse (inverse)
            4.4.2.6 Separator (sep)
            4.4.2.7 Condition (condition)
            4.4.2.8 Declare (declare)
            4.4.2.9 Lambda (lambda)
            4.4.2.10 Function composition (compose)
            4.4.2.11 Identity function (ident)
            4.4.2.12 Domain (domain)
            4.4.2.13 codomain (codomain)
            4.4.2.14 Image (image)
            4.4.2.15 Domain of Application (domainofapplication)
            4.4.2.16 Piecewise declaration (piecewise, piece, otherwise)
        4.4.3 Arithmetic, Algebra and Logic
            4.4.3.1 Quotient (quotient)
            4.4.3.2 Factorial (factorial)
            4.4.3.3 Division (divide)
            4.4.3.4 Maximum and minimum (max, min)
            4.4.3.5 Subtraction (minus)
            4.4.3.6 Addition (plus)
            4.4.3.7 Exponentiation (power)
            4.4.3.8 Remainder (rem)
            4.4.3.9 Multiplication (times)
            4.4.3.10 Root (root)
            4.4.3.11 Greatest common divisor (gcd)
            4.4.3.12 And (and)
            4.4.3.13 Or (or)
            4.4.3.14 Exclusive Or (xor)
            4.4.3.15 Not (not)
            4.4.3.16 Implies (implies)
            4.4.3.17 Universal quantifier (forall)
            4.4.3.18 Existential quantifier (exists)
            4.4.3.19 Absolute Value (abs)
            4.4.3.20 Complex conjugate (conjugate)
            4.4.3.21 Argument (arg)
            4.4.3.22 Real part (real)
            4.4.3.23 Imaginary part (imaginary)
            4.4.3.24 Lowest common multiple (lcm)
            4.4.3.25 Floor (floor)
            4.4.3.26 Ceiling (ceiling)
        4.4.4 Relations
            4.4.4.1 Equals (eq)
            4.4.4.2 Not Equals (neq)
            4.4.4.3 Greater than (gt)
            4.4.4.4 Less Than (lt)
            4.4.4.5 Greater Than or Equal (geq)
            4.4.4.6 Less Than or Equal (leq)
            4.4.4.7 Equivalent (equivalent)
            4.4.4.8 Approximately (approx)
            4.4.4.9 Factor Of (factorof)
        4.4.5 Calculus and Vector Calculus
            4.4.5.1 Integral (int)
            4.4.5.2 Differentiation (diff)
            4.4.5.3 Partial Differentiation (partialdiff)
            4.4.5.4 Lower limit (lowlimit)
            4.4.5.5 Upper limit (uplimit)
            4.4.5.6 Bound variable (bvar)
            4.4.5.7 Degree (degree)
            4.4.5.8 Divergence (divergence)
            4.4.5.9 Gradient (grad)
            4.4.5.10 Curl (curl)
            4.4.5.11 Laplacian (laplacian)
        4.4.6 Theory of Sets
            4.4.6.1 Set (set)
            4.4.6.2 List (list)
            4.4.6.3 Union (union)
            4.4.6.4 Intersect (intersect)
            4.4.6.5 Set inclusion (in)
            4.4.6.6 Set exclusion (notin)
            4.4.6.7 Subset (subset)
            4.4.6.8 Proper Subset (prsubset)
            4.4.6.9 Not Subset (notsubset)
            4.4.6.10 Not Proper Subset (notprsubset)
            4.4.6.11 Set Difference (setdiff)
            4.4.6.12 Cardinality (card)
            4.4.6.13 Cartesian product (cartesianproduct)
        4.4.7 Sequences and Series
            4.4.7.1 Sum (sum)
            4.4.7.2 Product (product)
            4.4.7.3 Limit (limit)
            4.4.7.4 Tends To (tendsto)
        4.4.8 Elementary classical functions
            4.4.8.1 common trigonometric functions
            4.4.8.2 Exponential (exp)
            4.4.8.3 Natural Logarithm (ln)
            4.4.8.4 Logarithm (log)
        4.4.9 Statistics
            4.4.9.1 Mean (mean)
            4.4.9.2 Standard Deviation (sdev)
            4.4.9.3 Variance (variance)
            4.4.9.4 Median (median)
            4.4.9.5 Mode (mode)
            4.4.9.6 Moment (moment)
            4.4.9.7 Point of Moment (momentabout)
        4.4.10 Linear Algebra
            4.4.10.1 Vector (vector)
            4.4.10.2 Matrix (matrix)
            4.4.10.3 Matrix row (matrixrow)
            4.4.10.4 Determinant (determinant)
            4.4.10.5 Transpose (transpose)
            4.4.10.6 Selector (selector)
            4.4.10.7 Vector product (vectorproduct)
            4.4.10.8 Scalar product (scalarproduct)
            4.4.10.9 Outer product (outerproduct)
        4.4.11 Semantic Mapping Elements
            4.4.11.1 Annotation (annotation)
            4.4.11.2 Semantics (semantics)
            4.4.11.3 XML-based annotation (annotation-xml)
        4.4.12 Constant and Symbol Elements
            4.4.12.1 integers (integers)
            4.4.12.2 reals (reals)
            4.4.12.3 Rational Numbers (rationals)
            4.4.12.4 Natural Numbers (naturalnumbers)
            4.4.12.5 complexes (complexes)
            4.4.12.6 primes (primes)
            4.4.12.7 Exponential e (exponentiale)
            4.4.12.8 Imaginary i (imaginaryi)
            4.4.12.9 Not A Number (notanumber)
            4.4.12.10 True (true)
            4.4.12.11 False (false)
            4.4.12.12 Empty Set (emptyset)
            4.4.12.13 pi (pi)
            4.4.12.14 Euler gamma (eulergamma)
            4.4.12.15 infinity (infinity)

4.1 Introduction

4.1.1 The Intent of Content Markup

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 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 \blacksquare 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.

4.1.2 The Scope of Content Markup

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 (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.

4.1.3 Basic Concepts of Content Markup

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 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.

4.2 Content Element Usage Guide

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-compliant 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, 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 5.2.3 Presentation Markup Contained in Content Markup. An informal EBNF grammar describing the syntax for the content markup is given in B Content Markup Validation Grammar.

4.2.1 Overview of Syntax and Usage

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:

  • containers

  • operators and functions

  • qualifiers

  • relations

  • conditions

  • semantic mappings

  • constants and symbols

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.

4.2.1.1 Constructing Mathematical Objects

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 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 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 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 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.

4.2.1.2 Constructing General Expressions

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="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.

4.2.1.3 The 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.

4.2.1.4 Explicitly defined functions and operators

The most common operations and functions such as plus and sin have been predefined explicitly as empty elements (see 4.4 The Content Markup Elements). They have type and definitionURL attributes, and by changing these attributes, the author can 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 and do not use any external definition mechanism. 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.

To use csymbol to describe a completely new function, we write for example

<csymbol definitionURL="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 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="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>

4.2.1.5 The inverse construct

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.

4.2.1.6 The declare construct

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. The possible values for the type attribute include all the predefined container element names such as vector, matrix or set (see 4.3.2.9 type).

4.2.1.7 The lambda construct

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 \lambda(x, F(x)) = F or \lambda(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 internal variables is encoded by a lambda element with n+1 children. All but the last child must be bvar elements containing the identifiers of the internal variables. The last child is an expression defining the function. This is typically an apply, but can also be any container element.

The following constructs \lambda (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="fn">
  <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="fn">
  <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.

4.2.1.8 The use of qualifier elements and the condition construct

The last example of the preceding section illustrates the use of qualifier elements lowlimit, uplimit, and bvar used 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. 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, see 4.2.3.2 Operators taking Qualifiers.

The qualifier element bvar is also used in another important MathML construction. The condition element is used to place conditions on bound variables in other expressions. This allows MathML to define sets by rule, rather than enumeration, for example. 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>
</set>

4.2.1.9 Rendering of Content elements

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 4.4 The Content Markup Elements, and several mechanisms (including 4.3.3.2 General Attributes) are provided for associating a particular rendering with an object.

4.2.2 Containers

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, fn, lambda, piecewise, piece, otherwise
Specials declare

4.2.2.1 Tokens

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 4.2.3 Functions, Operators and Qualifiers.

cn

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 4.4.1.1 Number (cn).

ci

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 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 detailed structure and specifications are provided in 4.4.1.2 Identifier (ci).

csymbol

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 externally. 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 3.1.6 Summary of Presentation Elements). For example,

<csymbol definitionURL="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 4.4.1.3 Externally defined symbol (csymbol).

4.2.2.2 Constructors

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.

interval

The interval element is described in detail in 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].

set and list

The set and list elements are described in detail in 4.4.6.1 Set (set) and 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>

Alternatively, bvar and condition elements 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.

matrix and matrixrow

The matrix element is used to represent mathematical matrices. It is described in detail in 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.

vector

The vector element is described in detail in 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>
apply

The apply element is described in detail in 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 4.2.3 Functions, Operators and Qualifiers.

reln

The reln element is described in detail in 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.

fn

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 4.4.2.3 Function (fn).

lambda

The lambda element is used to construct a user-defined function from an expression and one or more free variables. The lambda construct with n internal variables takes n+1 children. The first (second, up to n) is a bvar containing the identifiers of the internal variables. The last is an expression defining the function. This is typically an apply, but can also be any container element. The following constructs \lambda (x, sin x)

<lambda>
  <bvar><ci> x </ci></bvar>
  <apply>
    <sin/>
    <ci> x </ci>
  </apply>
</lambda>

The following constructs the constant function \lambda (x, 3)

<lambda>
  <bvar><ci> x </ci></bvar>
  <cn> 3 </cn>
</lambda>
piecewise, piece, otherwise

The piecewise, piece, otherwise elements are used to support "piecewise" declarations of the form " H(x) = 0 if x less than 0, H(x) = 1 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 4.4.2.16 Piecewise declaration (piecewise, piece, otherwise) .

4.2.2.3 Special Constructs

The declare construct is described in detail in 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.

4.2.3 Functions, Operators and Qualifiers

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, 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.

4.2.3.1 Predefined functions and operators

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.

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 two or more child elements.

The one exception to these rules is that declare elements may be inserted in any position except the first. declare elements are not counted when satisfying the child element count for an apply containing a unary or binary operator element.

Integral, sum, product and differential operators are discussed below in 4.2.3.2 Operators taking Qualifiers.

4.2.3.2 Operators taking Qualifiers

The table below contains the qualifiers and the 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, min, max, forall, exists

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. They are used in exactly the same way as ordinary operators, except that when they are used as operators, certain qualifier elements are also permitted to be in the enclosing apply. Qualifiers always follow the operator and precede the argument if it is 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>
  <interval><cn>0</cn><cn>1</cn></interval>
  <apply>
      <power/>
    <ci>x</ci>
    <cn>2</cn>
  </apply>
</apply>

It is also valid to use qualifier schema with a function not applied to an argument. For example, a function acting on integrable functions on the interval [0,1] might be denoted:

<fn>
  <apply>
    <int/>
    <bvar><ci>x</ci></bvar>
    <lowlimit><cn>0</cn></lowlimit>
    <uplimit><cn>1</cn></uplimit>
  </apply>
</fn>

In addition to the defined usage in MathML, qualifier schema may be used with any user-defined symbol (e.g. using csymbol) or construct. The meaning of such a usage is not defined by MathML; it would normally be user-defined using the definitionURL attribute.

The meaning and usage of qualifier schema varies from function to function. The following list summarizes the usage of qualifier schema with the MathML functions taking qualifiers.

int

The int function accepts the lowlimit, uplimit, bvar, interval, condition and domainofapplication schemata. If both lowlimit and uplimit schemata are present, they denote the limits of a definite integral. The domain of integration may alternatively be specified using interval, condition or domainofapplication. The bvar schema signifies the variable of integration. When used with int, each qualifier schema is expected to contain a single child schema; otherwise an error is generated.

diff

The diff function accepts the bvar schema. The bvar schema specifies with respect to which variable the derivative is being taken. The bvar may itself contain a degree schema that is used to specify the order of the derivative, i.e. a first derivative, a second derivative, etc. For example, the second derivative of f with respect to x is:

<apply>
  <diff/>
  <bvar>
    <ci> x </ci>
    <degree>
      <cn> 2 </cn>
    </degree>
  </bvar>
  <apply><fn><ci>f</ci></fn>
    <ci> x </ci>
  </apply>
</apply>
partialdiff

The partialdiff operator accepts zero or more bvar schemata, and an optional degree qualifier schema. The bvar schema specify, in order, the variables with respect to which the derivative is being taken. Each bvar element may contain a degree schema which is used to specify the order of the derivative being taken with respect to that variable. The optional degree schema qualifier associated with the partialdiff element itself (that is, appearing as a child of the enclosing apply element rather than of one of the bvar qualifiers) is used to represent the total degree of the differentiation. Each degree schema used with partialdiff is expected to contain a single child schema. For example,

<apply>
  <partialdiff/>
  <bvar>
    <degree><cn>2</cn></degree>
    <ci>x</ci>
  </bvar>
  <bvar><ci>y</ci></bvar>
  <bvar><ci>x</ci></bvar>
  <degree><cn>4</cn></degree>
  <ci type="fn">f</ci>
</apply>

denotes the mixed partial derivative ( d4 / d2x dy dx ) f.

sum, product

The sum and product functions accept the bvar, lowlimit, uplimit, interval, condition and domainofapplication schemata. If both lowlimit and uplimit schemata are present, they denote the limits of the sum or product. The limits may alternatively be specified using the interval, condition or domainofapplication schema. The bvar schema signifies the internal variable in the sum or product. A typical example might be:

<apply>
  <sum/>
  <bvar><ci>i</ci></bvar>
  <lowlimit><cn>0</cn></lowlimit>
  <uplimit><cn>100</cn></uplimit>
  <apply>
    <power/>
    <ci>x</ci>
    <ci>i</ci>
  </apply>
</apply>

When used with sum or product, each qualifier schema is expected to contain a single child schema; otherwise an error is generated.

limit

The limit function accepts zero or more bvar schemata, and optional condition and lowlimit schemata. A condition may be used to place constraints on the bvar. The bvar schema denotes the variable with respect to which the limit is being taken. The lowlimit schema denotes the limit point. When used with limit, the bvar and lowlimit schemata are expected to contain a single child schema; otherwise an error is generated.

log

The log function accepts only the logbase schema. If present, the logbase schema denotes the base with respect to which the logarithm is being taken. Otherwise, the log is assumed to be base 10. When used with log, the logbase schema is expected to contain a single child schema; otherwise an error is generated.

moment

The moment function accepts the degree and momentabout schema. If present, the degree schema denotes the order of the moment. Otherwise, the moment is assumed to be the first order moment. When used with moment, the degree schema is expected to contain a single child schema; otherwise an error is generated. If present, the momentabout schema denotes the point about which the moment is taken. Otherwise, the moment is assumed to be the moment about zero.

min, max

The min and max functions accept a bvar schema in cases where the maximum or minimum is being taken over a set of values specified by a condition schema together with an expression to be evaluated on that set. In MathML1.0, the bvar element was optional when using a condition; if a condition element containing a single variable was given by itself following a min or max operator, the variable was implicitly assumed to be bound, and the expression to be maximized or minimized (if absent) was assumed to be the single bound variable. This usage is deprecated in MathML 2.0 in favor of explicitly stating the bound variable(s) and the expression to be maximized or minimized in all cases.

The min and max elements may also be applied to a list of values in which case no qualifier schemata are used. For examples of all three usages, see 4.4.3.4 Maximum and minimum (max, min).

forall, exists

The universal and existential quantifier operators forall and exists are used in conjunction with one or more bvar schemata to represent simple logical assertions. There are two ways of using the logical quantifier operators. The first usage is for representing a simple, quantified assertion. For example, the statement "there exists x< 9" would be represented as:

<apply>
  <exists/>
  <bvar><ci> x </ci></bvar>
  <apply><lt/>
    <ci> x </ci><cn> 9 </cn>
  </apply>
</apply>

The second usage is for representing implications. Hypotheses are given by a condition element following the bound variables. For example the statement "for all x < 9, x < 10" would be represented as:

<apply>
  <forall/>
  <bvar><ci> x </ci></bvar>
  <condition>
    <apply><lt/>
      <ci> x </ci><cn> 9 </cn>
    </apply>
  </condition>
  <apply><lt/>
    <ci> x </ci><cn> 10 </cn>
  </apply>
</apply>

Note that in both usages one or more bvar qualifiers are mandatory.

4.2.4 Relations

binary relation neq, equivalent, approx, factorof