A Simple OpenMath Calculator

This is about the simplest OpenMath application I could come up with. Type in an XML encoded OpenMath arithmetical expression with variables x and y in the text area, enter values for x and y, and press the Compute button.

Version using the Riaca OpenMath Library: Version using the PolyMath OpenMath Library:
Java applet here. Java applet here.

Syntax

Expressions should be of type (floating point) number. Only atoms and binary operators from the table below are allowed. Make sure x and y are the only variables occuring in the expression. Operators are applied to argument expressions in prefix notation using the <OMA> tag.

Atoms
x <OMV name="x"/>
y <OMV name="y"/>
int <OMI>42</OMI>
float <OMF dec="3.1415"/>
Operators
+ <OMS cd="arith1" name="plus"/>
- <OMS cd="arith1" name="minus"/>
* <OMS cd="arith1" name="times"/>
/ <OMS cd="arith1" name="divide"/>

Here is an example of a valid expression representing (3x+5y):

  <OMOBJ>
    <OMA>
      <OMS cd="arith1" name="plus"/>
      <OMA>
        <OMS cd="arith1" name="times"/>
        <OMF dec="3.0"/>
        <OMV name="x"/>
      </OMA>
      <OMA>
        <OMS cd="arith1" name="times"/>
        <OMF dec="5.0"/>
        <OMV name="y"/>
      </OMA>
    </OMA>
  </OMOBJ>

More examples are available from the OpenMath website.

Source Code

The Java Sources:

OMCalcRiacaApplet.java
OMCalcPolyMathApplet.java
OMCalcException.java

Jar Archives containing the OpenMath libraries:

omriaca.jar (150 kB) Riaca OpenMath Library. Includes Sun XML packages.
ompolymath.jar (500 kB) PolyMath Development Group OpenMath Library. Includes IBM XML packages.