MathML Logo


#Call for Papers

#General Information

#Registration

#Accommodations

#Travel

#Tutorials

#Presentations

#Schedule

    

MathML in Maple

Laurent Bernardin, James McCarron, Douglas Harder
Waterloo Maple Inc.


Abstract

We present the capabilities of Maple, a system for symbolic and numeric computations, with respect to its abilities to handle MathML. Maple allows import of mathematical expressions encoded using MathML. The imported expressions can be used in any computations within the Maple system. The resulting expressions of any such computation can be exported back to MathML or published to the web.

We discuss selected details of the design and implementation of these capabilities and focus on difficulties that where encountered and trade-offs that had to be made.


Importing MathML into Maple

MathML2.0 comes in two flavours: Presentation MathML is mostly concerned about how a mathematical expression "looks", whereas Content MathML focuses on encoding the semantics of an expression. These two flavours can be combined into one MathML tree, providing two different encodings of the same expression, where one will be most useful, depending on the context where this MathML expression is used.

Importing Content MathML into a computational system like Maple is straightforward. The semantics of the expression is encoded explicitly and most elements within Content MathML have a one-to-one correspondence with an expression in Maple.

Importing a MathML expression with multiple different encodings (e.g. Presentation and Content MathML) is also straight-forward, as one can choose the encoding that carries the most semantic information and is easiest to correctly import.

Importing pure Presentation MathML is much more difficult. Since Presentation MathML, like most mathematical notations, is ambiguous, there is no one-to-one mapping to an expression with fixed semantics, necessary to perform computations in a system like Maple. Different users will expect the same expression encoded using Presentation MathML to map to a different semantic object. For example, the MathML expression

        <mrow>
                <msup>
                        <mi>f</mi>
                        <mn>2</mn>
                </msup>
        </mrow>
encodes a symbol f with a superscript of 2, which, depending on the context, could be interpreted as a power, a derivative, an index, etc.

We resolve the problem of disambiguating Presentation MathML with a rule based transformation engine. The rule-set encodes a fixed set of context dependent choices as to how to interpret elements from Presentation MathML. The rule-set can be exchanged with a different one depending on the user needs. The output of the transformation engine is Content MathML with unambiguous semantics, allowing us to reuse our code for importing Content MathML in order to do the final translation step to a Maple expression.

The following is one example of a rule from the rule-set, transforming ex into the corresponding <apply> element.

        <wmi:rule>
                <wmi:pattern>
                        <msup>
                                <wmi:pattern-or>
                                        <mi>ⅇ</mi>
                                        <ci>ⅇ</ci>
                                        <exponentiale/>
                                </wmi:pattern-or>
                                <wmi:mpatvar>x</wmi:mpatvar>
                        </msup>
                </wmi:pattern>
                <wmi:rewrite>
                        <apply>
                                <exp/>
                                <wmi:mpatvar>x</wmi:mpatvar>
                        </apply>
                </wmi:rewrite>
         </wmi:rule>

Note that the ruleset also accepts MathML content elements in its input (for example, <ci>to allow MathML structures that contain mixed presentation/content elements to also be imported.


Exporting MathML from Maple

Even though Maple can export expressions it generates to both Presentation MathML and Content MathML, the preferred export format is a combined (parallel) tree containing both Presentation and Content MathML. Applications that reuse Maple's MathML output can choose the most appropriate format. The two trees for Presentation and Content MathML are fully cross-linked, allowing, for example, an application to identify the Content MathML markup for a sub-expression found in the Presentation tree. In particular, an application could take a MathML expression generated by Maple, extract a sub-expression from the Presentation tree and pass this sub-expression together with the corresponding Content markup (identified using the cross-links from the Presentation to the Content tree) back into Maple, preserving the semantics of the sub-expression as originally generated by Maple.

Maple has a vast library of mathematical functions and objects. As a result, base MathML is only able to represent a small subset of Maple. We use the extension mechanism built into MathML to encode objects that are not part of base MathML. For example, a Bessel J function is encoded as:

        <csymbol 
definitionURL='http://www.maplesoft.com/MathML/BesselJ'>
                BesselJ
        </csymbol>

The problem with this approach is that applications receiving MathML containing such objects need to have explicit knowledge of Maple's name-space in order to be able to correctly interpret this expression. An alternate approach would be to use a common encoding allowing a wider range of semantic objects like, for example, OpenMath.

On the other hand, using csymbol's for encoding the specific semantics of Maple still allows third party applications to work with the generated output because Maple includes both Presentation and Content MathML into its output. Applications with no knowledge of Maple's csymbol extensions are still able to interpret the Presentation fork, which is free of any system-specific extensions.

For example, the full export of the Bessel J function with index 2 and argument n looks as follows:

        <math xmlns='http://www.w3.org/1998/Math/MathML'>
                <semantics>
                        <mrow xref='id4'>
                                <msub>
                                        <mi>J</mi>
                                        <mn xref='id2'>2</mn>
                                </msub>
                                <mo>&ApplyFunction;</mo>
                                <mfenced>
                                        <mi xref='id3'>n</mi>
                                </mfenced>
                        </mrow>
                        <annotation-xml encoding='MathML-Content'>
                                <apply id='id4'>
                                        <csymbol 
definitionURL='http://www.maplesoft.com/MathML/BesselJ'>
                                                BesselJ
                                        </csymbol>
                                        <cn id='id2' 
type='integer'>2</cn>
                                        <ci id='id3'>n</ci>
                                </apply>
                        </annotation-xml>
                        <annotation 
encoding='Maple'>BesselJ(2,n)</annotation>
                </semantics>
        </math>

Worth noting is that Maple's MathML output contains a third encoding of the expression, on top of the Presentation and Content MathML encodings: A string representing the expression using Maple syntax. Since Maple always tries to use the encoding that carries the most semantic information, this will be the encoding that is used first, if available. The drawback of this encoding is that there is no mapping between sub-expressions of the Presentation and Content trees and sub-expressions of the Maple encoding. An application that extracts a sub-expression from the Presentation or Content tree has no choice but to discard the Maple encoding in its entirety.


Authoring and Publishing Semantic Information

When authoring a mathematical expression, the semantics of the expression are usually known. MathML allows authors to attach these semantics to the expression. As seen above, Maple supports authoring of mathematical expressions that carry both notational and semantic information. Many applications working with MathML today are mostly concerned with the presentational aspects. As a result a lot of the available MathML content does not include the semantic information. Computational systems like Maple, have to work very hard to infer the meaning of such content and can, in general, not guarantee to make the right choices for ambiguous notations.

The probability for successfully inferring semantics from Presentation MathML, depend heavily on the choice of constructs by the authoring tool. Maple is careful to not misuse Presentation markup to, for example, force a certain type of spacing in a particular application. In addition, proper use of MathML constructs like &ApplyFunction and &InvisibleTimes, which are part of Presentation MathML and meant as formatting hints, also make it much more likely to correctly infer semantics. For example,

        <mrow> <mi>a</mi> &InvisibleTimes <mi>b</mi> 
</mrow>

can be identified as the product of a times b, whereas

        <mrow> <mi>f</mi> &ApplyFunction <mi>x</mi> 
</mrow>

is more likely to denote the function f applied to the argument x. On the other hand, markup like

        <mrow> <mi>s</mi> <mi>t</mi> </mrow>

gives few hints as to whether this should be interpreted as a product or a function call, most likely resulting in an arbitrary choice having to be made by applications that need the semantic information. Maple, for example, would interpret the above MathML expression as the product s t.

As authoring applications as well as authors become more concerned with publishing semantic information it will become easier and more reliable to reuse mathematical content in a wider range of contexts. Systems like Maple, that allow authoring of mathematical content as well as computations with such content, are able to publish mathematics carrying the full semantic information, today.


References

MathML 2.0 - www.w3.org/TR/MathML2

W3C Math Working Group - www.w3.org/Math

Maple - www.maplesoft.com

OpenMath - www.openmath.org