Using the semantic structure of OpenMath with XPath in Jelly to do checks
beyond equivalence: fraction example.
Introduction
In interactive exercises, it is often not enough if the answer is
equivalent to the desired result, that is evaluates to the same. It
should also meet some extra criteria. Some symbols might not be desired
(the answer of a summation should not contain a plus, and forbidding
the student to be able to enter one in the editor might not be an
option). Furthermore some further constraints might be required: for a
fraction, it might be desired that the gcd of the enumerator and
denominator is 1.
This file describes some methods of how the semantic structure of
OpenMath makes it possible to get this information, using XPath and
Jelly.
First it will be described how to input the answer, then how can be
checked if the answer is a fraction (from arith1.divide). After that a
method is described to extend this to negative fractions and the
enumerator and denominator are retrieved and their gcd calculated.
Input
Enter a
fraction
update
The corresponding OpenMath source code:
${a_text}
Checking the main element: is it a fraction
It can be checked that is a fraction with the following jelly code. If the
entered formula is a fraction, the emphasized text from the code will
appear below the listing.
This OpenMath formula has as root element an application of an
arith1.divide symbol. This means that it is a fraction.
]]>
This OpenMath formula has as root element an application of an
arith1.divide symbol. This means that it is a fraction.
Checking for other symbols (that are not allowed)
It can be checked if a fraction does not contain other symbols in the
enumerator or denominator. The Jelly code below uses XPath to check this.
The code is executed below the listing: if the fraction entered does not
contain other symbols, then the emphasized text will appear.
TODO: no plus, no fractions in fractions, no symbols in a fraction (no
applications in applications)
Negative fractions and integer results
This XPath expression however does not allow for unary minus
(arith1.unary_minus) before the fraction. The following Jelly code checks
with XPath for a unary minus before a fraction. As above the code is
executed below, if it matches, the emphasized text will appear below the
listing.
This OpenMath formula has as root element an application of an
arith1.unary_minus symbol. The (single) argument of that unary minus is a
fraction.
]]>
TODO: write something about integer results.
Constructing and calculating the gcd of the enumerator and denominator
The enumerator can be selected with
]]>
The denominator can be copied with:
]]>
To generate the new expression we combine these and store it in a
xml-variable:
]]>
The formula is :
The result (from the CAS) is:
.
The following code will only display the emphasized paragraph if the gcd
is one: TODO