Up | Next | Prev | PrevTail | Tail |
Mathematical Markup Language ( MathML) is an application of XML for describing mathematics. It has two flavours: Presentation MathML, like TeX, is intended for displaying mathematics, primarily within web pages, but its meaning can be ambiguous. Content MathML, like OpenMath, is intended for conveying meaning, but how it is displayed is determined by the display software. This package allows REDUCE to input and output Content MathML.
Author: Luis Alvarez-Sobreviela36
The MathML interface for REDUCE provides commands to evaluate and output MathML. The principal features of this package are as follows.
Evaluation of MathML code. This allows REDUCE to parse MathML expressions and evaluate them.
Generation of MathML compliant code. This provides output of REDUCE expressions in MathML code.
To use the MathML-REDUCE Interface, the package must first be loaded explicitly by executing the command
load_package mathml;
There are two switches that can be used together and are off by default.
mathml
: When on, all output will be displayed as MathML.
both
: When on, all output will be displayed as both MathML and normal REDUCE output (which is much easier to read than MathML).
The MathML-REDUCE Interface allows the user to provide MathML input via a file containing MathML or by entering MathML interactively.
MML
When reading from a file the operator mml
is used, which takes as argument the name of
the file containing the MathML.
mml
(FILE:string):expression
Example: As long as the file given contains valid MathML, no errors should be produced.
mml "ex.mml";
PARSEML
The operator parseml
takes no arguments and expects you to enter MathML markup
starting with <mathml>
and ending with </mathml>
. It then outputs an expression
resulting from evaluating the input.
Example:
Here is an extract of a REDUCE session where parseml()
is used:
parseml(); <math> <apply><plus/> <cn>3</cn> <cn>5</cn> </apply> </math> 8
MathML is always evaluated by REDUCE in algebraic
mode before outputting any
results. Hence, undefined variables remain undefined, and it is possible to use all normal
REDUCE switches and packages.
Example: The following MathML input
parseml(); <math> <reln><gt/> <ci>x</ci> <ci>y</ci> </reln> </math>
will evaluate to x>y
. (Note that this expression cannot be entered directly on its own as
REDUCE input!)
Now suppose we execute the following:
x:=3; y:=2;
If we once again enter and evaluate the above MathML input we will have as result 3>2
.
This can be evaluated to true
or false
as follows:
if ws then true else false; true
Of course, it is possible to set only one of the two variables x
or y
used above, say y:=4
.
If we once again enter and evaluate the above MathML we will get the result
x>4
.
When one of the switches mathml
or both
is on, the MathML output will
be:
<math> <reln><gt/> <ci>x</ci> <cn type="integer">4</cn> </reln> </math>
Example:
Let the file ex.mml
contain the following MathML:
<math> <apply><int/> <bvar> <ci>x</ci> </bvar> <apply><fn><ci>F</ci><fn> <ci>x</ci> </apply> </apply> </math>
If we execute the command
mml "ex.mml";
we get int(f(x),x)
or
It is clear that this has remained unevaluated. We can now define the function f(x)
as
follows:
for all x let f(x) = 2*x^2;
If we then enter mml "ex.mml";
once again, we will have the following result:
This shows that the MathML-REDUCE Interface allows normal REDUCE interactions to manipulate the evaluation of MathML input without needing to edit the MathML itself.
The MathML-REDUCE Interface has a set of error messages which aim to help the user understand and correct any invalid MathML. Because there can exist many different causes of errors, such error messages should be considered merely as advice. Here are the most important error messages.
Missing Tag:
Many MathML tags are used in pairs, e.g. <apply>
</apply>
, <reln>
</reln>
,
<ci>
</ci>
. In the case where the ending tag is missed out, or misspelled, it is very
probable that an error of this type will be thrown.
Ambiguous or Erroneous Use of <apply>
:
This error message is non-specific. When it appears, it is not very clear to the interface
where exactly the error lies. Probable causes are misuse of the <apply>
</apply>
tags, or misspelling of the tag preceding the <apply>
tag. However, other types of error
may cause this error message to appear.
Tags following an <apply>
tag may be misspelled without causing an error message,
but they will be considered as operators by REDUCE and therefore generate some
unexpected expression.
Syntax Errors: It is possible that the input MathML is not syntactically correct. In such a situation, the error will be spotted, and in some cases a resolution might be presented. There are a variety of syntax error messages, but relying on their advice might not always be helpful.
Despite the verbose nature of the error messages and their recommended resolutions, in most situations reference to the MathML specification is recommended.
Not all aspects of MathML have been perfectly fitted into the interface. There are still some unsolved problems in the present version of the interface:
MathML Presentation Markup is not supported. The interface will treat every presentation tag as either an unknown tag or a REDUCE operator.
Certain MathML tags do not play an important role in the REDUCE environment. Such tags will be parsed correctly, although their action will be ignored. These tags are:
<interval>
</interval>
<inverse>
</inverse>
<condition>
</condition>
<compose>
</compose>
<ident>
</ident>
<forall/>
<exists/>
However, the tags <condition>
</condition>
and <interval>
</interval>
are supported when used within the following tags:
<int/>
<limit/>
<sum/>
<product/>
The <declare>
construct takes one or two arguments. It sets the first argument
to the value of the second. In the case where the second argument is a vector or a
matrix, an obscure error message is produced.
Example 1: Enter the following input interactively:
on mathml; solve({z=x*a+1},{z,x});
Example 2:
Have a file ex2.mml
containing the following MathML:
<mathml> <apply><sum/> <bvar> <ci>x</ci> </bvar> <apply><fn><ci>F</ci><fn> <ci>x</ci> </apply> </apply> </mathml>
and execute the following command:
mml "ex2.mml";
Example 3:
This example illustrates how practical the switch both
can be for interpreting verbose
MathML. Introduce the following MathML into a file, say ex3.mml
:
<mathml> <apply><int/> <bvar> <ci>x</ci> </bvar> <apply><sin/> <apply><log/> <ci>x</ci> </apply> </apply> </apply> </mathml>
then execute the following:
on both; mml "ml";
The interface is primarily built in two parts. A first one which parses and evaluates MathML, and a second one which parses REDUCE’s algebraic expressions and outputs them in MathML format. Both parts use Top-Down Recursive Descent parsing with one token look ahead.
The EBNF description of the MathML grammar is defined informally in APPENDIX E
of the original MathML specification, which was used to develop the MathML parser.
The MathML parser evaluates all that is possible and returns a valid REDUCE algebraic
expression. When either of the switches mathml
or both
is on, this algebraic
expression is fed into the second part of the program, which parses these expressions and
transforms them back into MathML.
The MathML generator parses the algebraic expression produced by either REDUCE itself or the MathML parser. It works in a very similar way to the MathML parser. It is simpler, since no evaluation is involved. All the generated code is MathML compliant. It is important to note that the MathML code generator sometimes introduces Presentation Markup tags, and other tags which are not understood by the MathML parser of the interface.37
Up | Next | Prev | PrevTail | Front |