Mathematics

MathDox supports OpenMath for mathematical expressions. Here is an example of a MathDox document that contains an OpenMath expression.

Example 1. 

<article>
  <title>OpenMath</title>
  <subtitle>Just an expression</subtitle>
  <para>
    <OMA>
      <OMS cd="transc1" name="cos"></OMS>
      <OMA>
        <OMS cd="arith1" name="power"></OMS>
        <OMV name="x"></OMV>
        <OMI>2</OMI>
      </OMA>
    </OMA>
  </para>
</article>

The OpenMath code above is used to represent the expression \cos(x^2). It contains the cos symbol from the transc1 Content Dictionary (CD), and the power symbol from the arith1 CD. These CDs are standard OpenMath CDs. Later we will also see examples of OpenMath expressions being used for computations and editing.


The next example uses OpenMath, Jelly code, and a MONET expression.

Example 2. 


<article xmlns:monet='http://monet.nag.co.uk/monet/ns' xmlns:x="jelly:xml" >
  <title>OpenMath and MONET</title>
  <subtitle>differentiation</subtitle>
  <para>
     
    <x:parse var="formula">
      <OMOBJ>
        <OMA>
         <OMS cd='transc1' name='cos'/>
          <OMA>
            <OMS cd='arith1' name='power'/>
            <OMV name='x'/>
            <OMI>2</OMI>
          </OMA>
        </OMA>
      </OMOBJ>
    </x:parse>
    The derivative of 
    <x:copyOf select="$formula/*"/>
    is 
    <monet:query>
      <monet:classification>
        <monet:directive-type href='http://mathdox.org/phrasebook/maxima#eval'/>
      </monet:classification>
      <monet:body>
        <monet:output>
          <OMA>
            <OMS cd='calculus1' name='diff'/>
            <OMBIND>
              <OMS cd='fns1' name='lambda'/>
              <OMBVAR>
                <OMV name='x'/>
              </OMBVAR>
              <x:copyOf select="$formula/OMOBJ/*"/>
            </OMBIND>
          </OMA>
        </monet:output>
      </monet:body>
    </monet:query>
  </para>
</article>

See the example running (only if the maxima service is set up properly).

The expression \cos(x^2) we saw earlier, has now been inserted into a Jelly variable that is able to contain XML. Inserting XML-code into a Jelly variable needs some parsing. This is done by the <x:parse> tag. The aim is to reuse the XML stored in the variable as XML again instead of a value as in previous examples. To this end the XML-contents of the variable needs to be copied from the variable and into the XML structure of the document. This is done by means of the <x:copyOf> tag. In this way one and the same expression can be printed to the screen now and be used for calculations later as it will be used as input for the MONET query. This MONET query adds some more OpenMath around the contents of the XML-containing variable to tell a CAS to differentiate the function x \mapsto \cos(x^2). The result is then printed to the screen as well.


Besides OpenMath, it is also possible to include math inside the <phrase role="math"/> tag. Here one may include mathematics in MathML or (La)TeX form.

Example 3. 


<article xmlns:monet='http://monet.nag.co.uk/monet/ns' xmlns:x="jelly:xml" >
  <title>Math</title>
  <subtitle>differentiation</subtitle>
  <para>The derivative of 
    the function <phrase role="math">f</phrase> with 
    <phrase role="math">f(x)=\cos(x^2)</phrase> equals
    the function  <phrase role="math">f'</phrase> with
  <phrase role="math">f'(x)=-2x\cdot\sin(x^2)</phrase>.
  </para>
</article>

This displays as:

The derivative of the function f with f(x)=\cos(x^2) equals the function f' with f'(x)=-2x\cdot\sin(x^2).