5.4 Operators and Functions

 < Day Day Up > 



5.4 Operators and Functions

The majority of content elements are empty elements that represent specific operators or functions. They are organized into groups named after specific subfields of mathematics, as shown below:

  • Arithmetic, algebra, and logic

  • Relations

  • Elementary functions

  • Calculus

  • Linear algebra

  • Theory of sets

  • Sequences and series

  • Statistics

In MathML, there is no distinction between operators, functions, and relations because, viewed in an abstract sense, an operator or relation is just a special type of function. For example, the operator + can be thought of as a function that maps pairs of real numbers to real numbers. Similarly, you can think of the relation x < y as a Boolean function that maps pairs of real numbers to the logical values True or False. However, operators and functions are grouped in separate categories in the MathML DTD for the purposes of convenience and consistency with historical usage.

The rest of this section contains examples of selected elements from each category to illustrate how they are used.

Arithmetic, Algebra, and Logic

Several content elements represent common operators and functions used in arithmetic, algebra, and logic. For example, the plus, minus, divide, and times elements represent the basic arithmetic operations of addition, subtraction, division, and multiplication, respectively.

The power and root elements are used to represent taking a power or root. You can encode a fractional power using either of these elements, but the default rendering is typically different in each case. For example, you could encode the cube root of x using the power element as shown here (this element is followed by two child elements, the first of which represents the base and the second the power):

     <apply>       <power/>       <ci>x</ci>       <cn type="rational">1<sep/>3</cn>     </apply> 

Alternatively, you can use the root element to encode the same expression. By default, this would be rendered with a radical sign around the base expression. The first element following the root element is the qualifier element degree, which specifies the kind of root. It must contain the number 2 for square roots, 3 for cube roots, and so on. If no degree element is specified, a default value of 2 is assumed. Here is the relevant markup:

     <apply>       <root/>         <degree><cn>3</cn></degree>       <ci>x</ci>     </apply> 

Here are some other important content elements:

  • The factorial element is used to represent the factorial of a number.

  • The real and imaginary elements represent the real and imaginary parts of a complex number.

  • The not, and, or, xor, and not elements represent the corresponding operators in Boolean logic.

Relations

Several content elements have been defined for representing various types of arithmetic and logical relations, such as a = b or x < y. You express a relation in content markup by using a relational content element as the first argument of an apply element. You do it this way because you can think of a relational expression as the result of applying a function to a set of arguments. The result of applying the function is one of the logical values, True or False.

The following content elements represent the common types of relational operators: eq, neq, gt, lt, geq, leq, equivalent, approx, factorof, implies, and tendsto.

Here is an example of a simple equality:

  • 2 + 2 = 4

     <apply>       <eq/>       <apply>         <plus/>          <cn>2</cn>          <cn>2</cn>       </apply>       <cn>4</cn>     </apply> 

The number of child elements in the apply element is determined by the type of relational element that occurs as the first argument. Some relational elements such as neq act as binary operators since they always express a relation between two quantities. Other relational elements such as eq, leq, lt, gt, and geq act as n-ary operators; that is, they can be followed by an arbitrary number of elements to express compound relations, such as in the markup below:

  • a < b < c < d

     <apply>       <lt/>       <ci>a</ci>       <ci>b</ci>       <ci>c</ci>       <ci>d</ci>     </apply> 

Elementary Functions

Several content elements represent classical elementary functions, such as the exponential and logarithmic functions as well as the trigonometric and hyperbolic functions. Here is an example involving the exponential and natural logarithmic functions:

  • ln(ex) = X

     <apply>       <eq/>       <apply>         <ln/>         <apply>           <exp/>           <ci>x</ci>         </apply>       </apply>       <ci>x</ci>     </apply> 

The log element is used to represent the natural logarithmic function. You can use the qualifier element logbase to specify the base of the logarithm. If no logbase element is present, a default value of 10 is assumed for the base, as shown here:

  • log2(x)

     <apply>       <log/>       <logbase><cn>2</cn></logbase>       <ci>x</ci>     </apply> 

Here is an example of a simple trigonometric formula:

  • sin(2x) = 2 sin(x)cos(x)

     <apply>       <eq/>       <apply>        <sin/>        <apply><times/><cn>2</cn><ci>x</ci></apply>       </apply>       <apply>        <times/>        <cn>2</cn>        <apply><sin/><ci>x</ci></apply>        <apply><cos/><ci>x</ci></apply>       </apply>     </apply> 

Calculus

The following content elements represent various operators or functions used in calculus: int, diff, partialdiff, grad, divergence, curl, and laplacian. The following sections provide examples of how these elements are used.

Integrals

Integrals are represented using the int element. The variable of integration is specified using the qualifier element bvar. Here is an example:

  • xdx

     <apply>       <int/>       <bvar><ci>x</ci></bvar>       <ci>x</ci>     </apply> 

For definite integrals, the upper and lower limits of integration can be represented using the qualifier elements lowlimit and uplimit, as shown here:

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

The limits of integration can also be specified using the interval element, while integration over a general domain can be specified using the condition element. Examples of using the interval and condition elements to represent the range of integration are provided in the discussion of these elements in Section 5.3.

Derivatives

The diff element is used to represent derivatives of functions of a single variable, as shown below:

  • f

     <diff>       <ci>f</ci>     </diff> 

The qualifier element bvar is used to specify the variable of integration. The bvar element can include a degree element to specify the degree of differentiation, as shown below:

     <apply>       <diff/>       <bvar><ci>x</ci></bvar>       <degree><cn>2</cn></degree>       <apply>         <ci type="fn">f</ci>         <ci>x</ci>       </apply>     </apply> 

Partial Derivatives

The partialdiff element is used to represent partial derivatives of multivariable functions. Here is an example:

     <apply>       <partialdiff/>         <bvar><ci>x</ci></bvar>         <bvar><ci>y</ci></bvar>         <apply><ci type="fn">f</ci>           <ci>x</ci>           <ci>y</ci>         </apply>     </apply> 

You can specify the degree of differentiation with respect to any of the variables by including a degree element inside the bvar element that corresponds to that variable. You can also include a degree element directly as a child element of the enclosing apply element to specify the total degree of differentiation, as shown here:

     <apply>      <partialdiff/>       <bvar><ci>x</ci>         <degree><ci>m</ci></degree>       </bvar>       <bvar><ci>y</ci>         <degree><ci>n</ci></degree>       </bvar>        <apply><ci type="fn">f</ci>         <ci>x</ci>         <ci>y</ci>       </apply>     </apply> 

Vector Calculus

The elements grad, divergence, curl, and laplacian represent the gradient, divergence, curl, and Laplacian operators of vector calculus, respectively. For example, here is one of Maxwell's equations of electrodynamics; it describes the divergence of the magnetic field:

     <apply>       <eq/>       <apply>         <divergence/>         <ci type="vector">B</ci>       </apply>       <cn>0</cn>     </apply> 

Linear Algebra

The following content elements represent various operators or functions used in linear algebra: determinant, transpose, selector, vectorproduct, scalarproduct, and outerproduct.

The determinant and transpose elements represent the determinant and transpose of a matrix, respectively. The matrix itself is represented using the matrix and matrixrow elements, as discussed in Section 5.3.

For example, given a matrix:

the equations that describe the transpose and determinant of A are given below:

     <apply>       <eq/>         <apply>          <transpose/>          <ci type="matrix">A</ci></apply>       <matrix>         <matrixrow><cn>1</cn><cn>3</cn></matrixrow>         <matrixrow><cn>2</cn><cn>4</cn></matrixrow>       </matrix>     </apply> 
  • det(A) = 2

     <apply>       <eq/>         <apply>           <determinant/>           <ci type="matrix">A</ci>         </apply>       <cn>2</cn>     </apply> 

The selector element is used to select a specific part of a list, vector, or matrix. This element can take one, two, or three arguments. The first argument identifies the object whose element is being selected. The remaining arguments specify the index number of the item in that object.

For matrices, the second argument specifies the row and the third argument specifies the column. For example, the element in the first row and second column of a matrix A is represented as shown below:

  • A12

     <apply>       <selector/>       <ci type="matrix">A</ci>       <cn>1</cn>       <cn>2</cn>     </apply> 

If the selector element is given with three arguments and the first argument identifies a vector or list, the third argument is ignored.

The vectorproduct, scalarproduct, and outerproduct elements represent the vector product, the scalar product, and the outerproduct of vectors, respectively. Here is an example showing the scalar product of two vectors:

  • A.B = abcos(θ)

     <apply>       <eq/>       <apply><scalarproduct/>         <ci type="vector"> A </ci>         <ci type="vector"> B </ci>       </apply>       <apply><times/>         <ci>a</ci>         <ci>b</ci>         <apply><cos/>           <ci>&theta;</ci>         </apply>       </apply>     </apply> 

Theory of Sets

We have already seen the use of the constructor elements set and list to represent sets and lists. There are several content elements that represent various operators and functions used in the theory of sets.

The elements union and intersect are used to represent the union and intersection of two sets, as seen in the following example:

  • A (B C)

     <apply>       <union/>       <ci type="set">A</ci>       <apply>         <intersect/>         <ci type="set">B</ci>         <ci type="set">C</ci>       </apply>     </apply> 

The elements in, notin, subset, prsubset, notsubset, notprsubset, and setdiff are used for representing various types of relationships between sets, as seen in the following examples:

  • a A

     <apply>       <in/>       <ci>a</ci>       <ci type="set">A</ci>     </apply> 
  • A B

     <apply>       <subset/>       <ci type="set">A</ci>       <ci type="set">B</ci>     </apply> 

The card element represents the cardinality of a set; that is, the number of elements it contains. Here is an example that uses this element:

     <apply>       <eq/>       <apply>         <card/>         <integers/>       </apply>       <cn>msub><mn>&aleph;</mn><mn>0</mn></msub></cn>       </apply>     </apply> 

The setdiff element represents the difference of two sets. The cartesianproduct element represents the Cartesian product of two sets; that is, the set of all pairs (a, b) with a A and b B. Using the elements described in this subsection, you can represent most mathematical statements encountered in the elementary theory of sets.

Sequences and Series

The following content elements can be used to represent limits, sequences, and series: sum, product, limit, and tendsto.

The sum and product elements are used to represent the summation and product operators. You can indicate the range over which the summation or product occurs either by using the uplimit and lowlimit qualifier elements, or more generally by using the condition element. Here is an example of using the sum element:

     <apply>       <sum/>       <bvar><ci>x</ci></bvar>       <lowlimit><ci>a</ci></lowlimit>       <uplimit><ci>b</ci></uplimit>       <apply>         <ci type="fn">f</ci>         <ci>x</ci>       </apply>     </apply> 

The limit element is used to represent the operation of taking a limit. The qualifier elements bvar and lowlimit are used to indicate the variable and the value it is approaching. Here is an example:

     <apply>       <limit/>         <bvar><ci>x</ci></bvar>         <lowlimit><cn>0</cn></lowlimit>       <apply>         <divide/>           <apply>             <sin/>             <ci>x</ci>           </apply>           <ci>x</ci>       </apply>     </apply> 

The tendsto element is used to indicate that a quantity is tending to a specified value. Here is an example:

  • x 0

     <apply>       <tendsto/>       <ci>x</ci>       <cn>0</cn>     </apply> 

Statistics

The content elements mean, median, mode, var, sdev, and moment represent the statistical concepts of mean, median, mode, variance, standard deviation, and moment, respectively.

For example, the mean of a distribution denoted by X would be represented as shown below:

  • X

     <apply>       <mean/>       <ci>X</ci>     </apply> 

The standard deviation of the same distribution would be represented as shown below:

  • σ(X)

     <apply>       <sdev/>       <ci>X</ci>     </apply> 



 < 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