5.3 Constructor Elements

 < Day Day Up > 



5.3 Constructor Elements

Constructor elements are the building blocks of content markup. They are so called because they construct complete expressions out of more basic components such as operators, functions, variables, and numbers. They are also used to create compound objects such as lists, sets, vectors, or matrices. They accomplish this by providing a framework for combining other content elements that represent more basic mathematical objects such as numbers, identifiers, operators, and functions. In this section, we look at some important constructor elements and give simple examples to illustrate their meaning and usage.

The apply Element

We saw several examples of the apply element in Section 3.2. This is by far the most common content element, since it represents one of the most basic mathematical concepts, that of applying an operator or function to its arguments.

The first child element of the apply element is the operator or function to be applied. The subsequent elements are the arguments of the function sor the operands of the operator. The number of subsequent child elements allowed depends on the operator or function specified as the first child element. For example, the plus element can be followed by zero or more child elements while the minus element must have either one or two child elements after it.

The operator or function specified as the first child element of the apply element can be represented in three ways:

  • Using one of the existing content elements that represent specific operators or functions

  • Using the csymbol element, as explained in Section 5.2

  • Using the ci element; for example, you can specify the function f as <ci type="function">f<ci>

Here is a simple example of using the apply element:

  • sin(x)

     <apply>       <sin/>       <ci>x</ci>     </apply> 

You can easily distinguish two different expressions that look similar but have different mathematical meanings by the number and position of apply elements used in the content markup. For example, the following markup represents the result of applying the sum of two functions f and g to the argument x:

  • (f + g)(x)

     <apply>       <apply>         <plus/>         <ci>f</ci>         <ci>g</ci>       </apply>       <ci>x</ci>     </apply> 

The following markup represents the multiplication of the sum of two variables f and g with x:

  • (f + g)(x)

     <apply>       <times/>       <apply>         <plus/>         <ci>f</ci>         <ci>g</ci>       </apply>       <ci>x</ci>     </apply> 

The declare Element

The declare element is used in content markup to associate a specific property or meaning with a mathematical object. For example, you can indicate that a certain identifier A represents a vector using this markup:

    <declare type="vector"><ci>A</ci></declare> 

The declare element is always placed at the beginning of a math element, and the scope of the declaration is the entire math element. This element is not rendered visually or aurally but it does affect the semantic interpretation of the identifier it encloses. The declare element is used whenever you need to specify that a given symbol represents a particular type of object such as a vector, matrix, list, set, or function. This information is specified using the type attribute of the declare element, which can be set to the name of any content element. By setting this attribute to the name of a container element such as cn, list, set, vector, matrix, or fn, you can declare any identifier to be an object of the specified type.

For example, the following declaration states that x is a real number with the value 3.75:

     <declare>       <ci>x</ci>       <cn>3.75</cn>     </declare> 

The following declares A to be a vector with three components a, b, and c:

     <declare>       <ci>A</ci>       <vector>         <ci>a</ci>         <ci>b</ci>         <ci>c</ci>       </vector>     </declare> 

Subsequent uses of A can then take into account that A is a vector. For example, if three identifiers, R, A, and B, are all declared to be vectors, an equation like the following could be interpreted as vector addition (by a particular MathML processor):

R = A + B

You can declare an identifier to be of a specified type without providing a complete description of it. For example, the declaration

     <declare type="function">       <ci>F</ci>     </declare> 

specifies that F is a function without indicating the exact meaning of the function or the number of arguments it takes.

The lambda Element

The lambda element is used to represent the concept of a lambda function, used in calculus. The lambda calculus provides a formal syntax for specifying a statement of the form "let f be a function that takes x to x2". A typical notation for the above statement looks like f = λ(x, x2).

In content markup, the concept of a lambda function is expressed using the lambda element. A function having n variables is specified using a lambda element with n + 1 child elements. Each of the first n child elements is a bvar element that represents one of the variables of the function. The (n + 1)th element is an expression that defines the function itself. Here is an example:

  • f = λ (x, x2)

     <lambda>       <bvar><ci>x</ci></bvar>       <apply>           <power/>           <ci>x</ci>           <cn>2</cn>       </apply>     </lambda> 

The following markup uses the declare and lambda elements to construct a function f for which f(x, y) = x2 + y2 + xy:

  • f = λ (x, y, x2 + y2 + xy)

     <declare type="fn">       <ci> f </ci>       <lambda>         <bvar><ci>x</ci></bvar>         <bvar><ci>y</ci></bvar>         <apply>           <plus/>           <apply>             <power/>             <ci>x</ci>             <cn>2</cn>           </apply>           <apply>             <power/>             <ci>y</ci>             <cn>2</cn>           </apply>           <apply>             <times/>             <ci>x</ci>             <cn>y</cn>           </apply>         </apply>       </lambda>     </declare> 

Intervals

The interval element is used to represent intervals of real numbers. Here is an example of a closed interval:

  • [0, 1]

     <interval>       <cn>0</cn>       <cn>1</cn>     </interval> 

The interval element takes an attribute called closure, which specifies whether the interval is open or closed at each end. This attribute can take values that correspond to the four types of intervals: open, closed, open-closed, and closed-open. The default value is closed. Here is an example of an interval where the closure is specified explicitly:

  • [0,   )

     <interval closure="closed-open">       <cn>0</cn>       <infinity/>     </interval> 

One common use of the interval element is with the int element to specify the limits of a definite integral. Here is an example:

     <apply>       <int/>       <bvar><ci>x</ci></bvar>       <interval>         <cn>0</cn>         <pi/>       </interval>       <apply>         <sin/>         <ci>x</ci>       </apply>     </apply> 

Relations

A relation such as equality or inequality is expressed in content markup by using a relational content element as the first argument of an apply element. The apply element is appropriate for this purpose because you can think of a relational expression as the result of applying a function to a set of arguments to yield the Boolean values True or False.

Here is an example of an inequality:

  • x < y

     <apply>       <lt/>       <ci>x</ci>       <ci>y</ci>     </apply> 

In MathML 1.0, the same relation was expressed using the reln element, as shown below:

     <reln>       <lt/>       <ci>x</ci>       <ci>y</ci>     </reln> 

The reln element is still supported in MathML 2.0 for backward compatibility. However, its use is deprecated. Instead, MathML 2.0 specifies that relations be expressed using the apply element to reflect that each relational expression is equivalent to applying a Boolean function.

Functions

The fn element is used to indicate that a particular MathML expression should be interpreted as a function. This element has exactly one argument, which specifies the name or symbol used to represent the function. For example, the following markup can be used to represent a function called f:

    <fn><ci>f</ci></fn> 

A function defined in this manner can then be used as the first child element of an apply element in the same way as the existing elements that represent functions, such as times or cos. Here is an example:

  • f(x)

     <apply>       <fn><ci>f</ci></fn>       <ci>x</ci>     </apply> 

You can indicate the meaning of the function by using the definitionURL or encoding attributes. In MathML 1.0, this was the only way to extend content markup to represent user-defined function. In MathML 2.0, the csymbol element is provided for the same purpose and is the preferred way to specify user-defined functions.

Conditions

The condition element is used to encode expressions that make use of the "such that" construct used in mathematical statements. Here is an example:

  • x | x2 = 1

     <apply>       <exists/>       <bvar><ci>x</ci></bvar>       <condition>         <apply>           <eq/>           <apply>             <power/>             <ci>x</ci>             <cn>2</cn>           </apply>           <apply><minus/><cn>1</cn></apply>         </apply>       </condition>     </apply> 

A condition element has the following properties:

  • It is typically used together with an exists or forall element to define a logical expression, as in the example above.

  • It is always preceded by one or more bvar elements, each of which specifies a bound variable whose values are restricted by a relation.

  • It always has one child element that must be an apply or reln element specifying the relation used for defining the condition.

One common use of the condition element is to specify the range of integration in conjunction with an int element, as seen in the following example:

     <apply>       <int/>       <bvar>         <ci>x</ci>       </bvar>       <condition>         <apply><in/>           <ci> x </ci>           <ci type="set">D</ci>         </apply>       </condition>       <apply><ci type="fn">f</ci>         <ci>x</ci>       </apply>     </apply> 

You can use the condition element to define the elements of a list or set as well. You do so by specifying a condition that the elements must satisfy. Two examples of this are given in the "Sets and Lists" section.

Sets and Lists

Sets and lists are represented using the set and list elements, respectively. Sets and lists are both used to represent a collection of elements that can be numbers, identifiers, or expressions. However, lists differ from sets in two important respects:

  • In a list, the order of elements is significant. In contrast, two sets with the same elements are equivalent, regardless of the order in which the elements are written.

  • In a list, each element can occur only once, whereas a set can contain repeated elements. The set element accepts the type attribute, which can take values normal or multiset, depending on whether repeated elements are allowed or not.

You can specify the elements of a set either by explicitly listing the elements or by using the bvar and condition elements to define a condition that elements of the set must satisfy. Here is an example of a set in which the elements are listed explicitly:

  • {0, 1, 2, 3}

     <set>       <cn>0</cn>       <cn>1</cn>       <cn>2</cn>       <cn>3</cn>     </set> 

Here is an example of the same set defined using a condition:

  • {X | X < 4 X N}

     <set>       <bvar><ci>x</ci></bvar>       <condition>         <apply>           <and/>           <apply>             <lt/>             <ci>x</ci>             <cn>4</cn>           </apply>           <apply>             <in/>             <ci>x</ci>             <naturalnumbers/>           </apply>         </apply>       </condition>       <ci>x</ci>     </set> 

As with sets, you can describe lists either by explicitly listing their elements or by using a condition. Here is an example of a list in which the elements are listed explicitly:

  • [0, 1, 2, 3]

     <list>       <cn>0</cn>       <cn>1</cn>       <cn>2</cn>       <cn>3</cn>     </list> 

Here is an example of the same list defined using a condition:

  • {x | x < 4}

     <list order="numeric">       <bvar><ci> x </ci></bvar>       <condition>         <apply><lt/>           <ci>x</ci>           <cn>5</cn>         </apply>       </condition>       <ci>x</ci>     </list> 

You specify the ordering of the list elements by using the order attribute. This can take two values: numeric (which orders the elements in increasing numeric order) and lexicographic (which corresponds to an alphabetic ordering).

Vectors and Matrices

The vector element is used to represent vectors. A vector from an n-dimensional vector space is represented by a vector element that contains n child elements, each of which represents one scalar component of the vector. For example, a three-dimensional vector, (1, 0, 2), can be represented as shown below:

     <vector>       <cn>1</cn>       <cn>0</cn>       <cn>2</cn>     </vector> 

The matrix element is used to represent matrices. It contains zero or more matrixrow elements, each of which represents a single row of the matrix. Every matrixrow element, in turn, has zero or more child elements, each of which must be a number, symbol, or algebraic expression. For example, the 3 x 3 identity matrix can be represented as shown below:

     <matrix>       <matrixrow>         <cn>1</cn><cn>0</cn><cn>0</cn>       </matrixrow>       <matrixrow>         <cn>0</cn><cn>1</cn><cn>0</cn>       </matrixrow>       <matrixrow>         <cn>0</cn><cn>0</cn><cn>1</cn>       </matrixrow>     </matrix> 

Piecewise Declarations

Piecewise declarations are used in mathematics to describe a function that has a different definition in different intervals. In content markup, piecewise declarations are represented using the three constructor elements: piecewise, piece, and otherwise. The entire declaration is enclosed in a single piecewise element, and each piece of the declaration is enclosed in a separate piece element. Each piece element takes two child elements: the first one gives the value and the second argument gives the condition or interval in which that value is taken. That is, it has the form:

     <piecewise>       <piece> value condition </piece>        ....       <piece> value condition </piece>       <otherwise> value </otherwise>     </piecewise> 

Each occurrence of value and condition is itself indicated by other content elements. For example, the definition of the absolute function and its representation in content markup are shown below:

     <piecewise>       <piece>         <apply><minus/><ci>x</ci></apply>         <apply><lt/><ci>x</ci><cn>0</cn></apply>       </piece>       <piece>         <cn>0</cn>         <apply><eq/><ci>x</ci> <cn>0</cn></apply>       </piece>       <otherwise>         <ci>x</ci>       </otherwise>     </piecewise> 



 < Day Day Up > 



The MathML Handbook
The MathML Handbook (Charles River Media Internet & Web Design)
ISBN: 1584502495
EAN: 2147483647
Year: 2003
Pages: 127
Authors: Pavi Sandhu

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net