An OpenMath module for GLOSS

NOTE: the modes described here are UNDER CONSTRUCTION. Please contact the author for an update if you think they would be useful.

1 Introduction

A module, http://gloss.bham.ac.ukmv/openmath/openmath.modes and driver file http://gloss.bham.ac.ukmv/openmath/openmath.mv is provided for the processing of XML files. It hooks to modes xml:element-content and xml:attributes so should work with any MV that loads and uses the http://gloss.bham.ac.ukmv/xml/xml.modes module.

OpenMath processing is initiated with the omobj tag, which creates an <om:OMOBJ> element containing the object. Inside this context, make standard GLOSS tokens create openmath objects in the way you would expect.

This document describes the openmath module through a list of examples. All CDs URIs, etc., usd here are hypothetical and do not in fact exist.

2 Direct encoding by tokens

A basic OpenMath object can be encoded by GLOSS tokens: elt; uri; int; hex; b64; str; char; fp; eref; furthermore, comments and processing-instructions are also allowed inside the GLOSS code for OpenMath objects. Where possible, GLOSS token syntax agrees with OpenMath syntax. There are a few small differences.

First, for integers written in hexadecimal, GLOSS requires a leading 0 before the x in a hexadecimal integer. (This 0 is actually disallowed in the OpenMath XML encoding.) This is to distinguish for example between the element name x123 and the hexadecimal number 0x123. (Variables x1,x2,x3,... are quite useful and we don't want them reserved for the integers 1,2,3,...)

Secondly, the GLOSS syntax for a fp is

(NaN)|(INF)|(-INF)|(-?([0-9]+)(\.[0-9]+)?([eE](-?)[0-9]+))|(-?([0-9]+)?(\.[0-9]+)([eE](-?)[0-9]+)?)

Whereas the specification in the OpenMath standard (at section 3.1.2 of my copy) is

(NaN)|(INF)|(-INF)|(-?([0-9]+)?(\.[0-9]+)?([eE](-?)[0-9]+)?)

Here I think the OpenMath standard is at fault (or the documentation is) since the empty string is a valid OpenMath floating point number, as are any integers such as 234 and -92428. GLOSS disallows this.

3 Basic OpenMath objects

Here is some sample basic open math objects, as encoded in GLOSS.

Undefined elements are assumed to be variables.

omobj v

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath"><om:OMV name="v"/></om:OMOBJ>

URI's (indicated in gloss with the ~ symbol and terminated by a space or other character that is not legal in a URI) produce OM reference objects.

omobj ~http://www.blogg.myobjects/thisone

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath"><om:OMR href="http://www.blogg.myobjects/thisone"/></om:OMOBJ>

Integers, hexadecimal numbers, base 64 data, and floating point numbers do what you'd expect.

omobj -1234

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath"><om:OMF dec="-1234"/></om:OMOBJ>
omobj 0x34DF

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath"><om:OMI>x34DF</om:OMI></om:OMOBJ>
omobj =1345TYU=

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath"><om:OMB>1345TYU=</om:OMB></om:OMOBJ>

Note the correct number of padding "=" signs are required, and the empty b64 datum is allowed.

omobj "a string"

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath"><om:OMSTR>a string</om:OMSTR></om:OMOBJ>
omobj 'c'

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath"><om:OMSTR>c</om:OMSTR></om:OMOBJ>
omobj &entref;

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">&entref;</om:OMOBJ>
omobj
  ?myappl [special command to application myappl]
  -3.14159E-34

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <?myappl special command to application myappl?>
  <om:OMF dec="-3.14159E-34"/>
</om:OMOBJ>
omobj 
  ![this is a reference to an external parsed entity]
  &external;

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <!-- this is a reference to an external parsed entity -->
  &external;
</om:OMOBJ>

4 Compound objects encoded by GLOSS-xml syntax

A basic OpenMath object can also be encoded by the standard GLOSS syntax with attributes, etc. This includes symbols too.

omobj
  oms @cdbase[http://mycdbase] @cd[mycd] @name[symb]

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <om:OMS cdbase="http://mycdbase" cd="mycd" name="symb"/>
</om:OMOBJ>
omobj
  omv @name[X]

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath"><om:OMV name="X"/></om:OMOBJ>
omobj
  omi [432]

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath"><om:OMI>432</om:OMI></om:OMOBJ>

There seems to be an inconsistency in the OpenMath spec I am reading. The text says hex integers like this are allowed, but it doesn't seem to be allowed in the relax-NG schema. I have followed the spirit but not the literal interpretation of the specification in the following:

omobj
  omi [x2A3D]

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath"><om:OMI>x2A3D</om:OMI></om:OMOBJ>
omobj
  omb [1234uytdjhg76]

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath"><om:OMB>1234uytdjhg76</om:OMB></om:OMOBJ>

Note that < in the following is automatically escaped due to general GLOSS-xml rules.

omobj 
  omstr [123<456]

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath"><om:OMSTR>123&lt;456</om:OMSTR></om:OMOBJ>
omobj
  omf @dec[43.456]

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath"><om:OMF dec="43.456"/></om:OMOBJ>
omobj
  omf @hex[FFF8000000000001]

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath"><om:OMF hex="FFF8000000000001"/></om:OMOBJ>

(This is the way one has to enter OMF data in hexadecimal.)

omobj
  omr @href[#myref]

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath"><om:OMR href="#myref"/></om:OMOBJ>

In a similar way, compound OpenMath objects and derived objects can be coded directly.

omobj
  oma f 23 56

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <om:OMA><om:OMV name="f"/><om:OMI>23</om:OMI><om:OMI>56</om:OMI></om:OMA>
</om:OMOBJ>
omobj
  ombind 
    oms @name[lambda] @cd[lambda-calc] { ombvar a b } oma a b

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <om:OMBIND>
    <om:OMS name="lambda" cd="lambda-calc"/>
    <om:OMBVAR><om:OMV name="a"/><om:OMV name="b"/></om:OMBVAR>
    <om:OMA><om:OMV name="a"/><om:OMV name="b"/></om:OMA>
  </om:OMBIND>
</om:OMOBJ>
omobj
  ome 
    oms @name[div-by-zero] @cd[errors] 
    oma oms @name[div] @cd[arith] x 0

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <om:OME>
    <om:OMS name="div-by-zero" cd="errors"/>
    <om:OMA><om:OMS name="div" cd="arith"/><om:OMV name="x"/><om:OMI>0</om:OMI></om:OMA>
  </om:OME>
</om:OMOBJ>
omobj
  omforeign
    @encoding[tex]
    [$x/0$]

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <om:OMFOREIGN encoding="tex">$x/0$</om:OMFOREIGN>
</om:OMOBJ>
omobj
  omattr
    omatp 
      oms @name[tex] @cd[attribution] 
      omforeign
        @encoding[tex]
        [$x/y$]
      oms @name[mathml] @cd[attribution] 
      omforeign
        @encoding[mathml]
        math mrow x / y
    oma oms @name[div] @cd[arith] x y

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <om:OMATTR>
    <om:OMATP>
      <om:OMS name="tex" cd="attribution"/>
      <om:OMFOREIGN encoding="tex">$x/y$</om:OMFOREIGN>
      <om:OMS name="mathml" cd="attribution"/>
      <om:OMFOREIGN encoding="mathml">
        <m:math xmlns:m="http://www.w3.org/1998/Math/MathML">
          <m:mrow><m:mi>x</m:mi><m:mo>/</m:mo><m:mi>y</m:mi></m:mrow>
        </m:math>
      </om:OMFOREIGN>
    </om:OMATP>
    <om:OMA>
      <om:OMS name="div" cd="arith"/>
      <om:OMV name="x"/>
      <om:OMV name="y"/>
    </om:OMA>
  </om:OMATTR>
</om:OMOBJ>

Note in this example how the GLOSS pmathml module can be used in conjunction with the openmath module to present mixed markup.

Note that GLOSS-OpenMath knows when objects are completed, like the pmathml module, and therefore the next object can follow directly on the same line. For example

omobj oma f 123 x 12.3

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <om:OMA><om:OMV name="f"/><om:OMI>123</om:OMI><om:OMV name="x"/><om:OMF dec="12.3"/></om:OMA>
</om:OMOBJ>

and the 123, x, 12.3, is not a child of the f, nor 12.3 a child of the x.

5 CDs and cdbases

The longest and most tedious part of OpenMath to type is the URIs of CD, and cdbases. OpenMath already makes this a little easier by allowing the cdbase attribute to be inherited from the parent element when not given. GLOSS-OpenMath has a mechanism to declare CDs, define them at a given element with a shorthard attribute, and will recognise when a definition of a CD base is not required.

omobj
  !declare-cd @name[grapefruit] @cdbase[http://grapefruit.com]
  !declare-cd @name[kumquat] @cdbase[http://kumquat.com]
  oma
    f 
    oma @kumquat
      g 1 2 3
    oma @grapefruit
      h 2 5 4
    oma @cdbase[http://grapefruit.com]
      k 3 5 6
    oma @kumquat @cdbase[http://lemon.com]
      k 3 5 oma @cdbase[http://lemon.com] 1 2 3
    oma @cdbase[http://ugli.com] @kumquat
      k 3 5 oma @cdbase[http://ugli.com] 1 2 3

yields the following warning messages

Warning: cdbase attribute already defined, line 12
Warning: cdbase attribute already defined, line 14

showing that an attempt had been made to define cdbase on a given element more than once, and the following output

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <om:OMA>
    <om:OMV name="f"/>
    <om:OMA cdbase="http://kumquat.com">
      <om:OMV name="g"/><om:OMI>1</om:OMI><om:OMI>2</om:OMI><om:OMI>3</om:OMI>
    </om:OMA>
    <om:OMA cdbase="http://grapefruit.com">
      <om:OMV name="h"/><om:OMI>2</om:OMI><om:OMI>5</om:OMI><om:OMI>4</om:OMI>
    </om:OMA>
    <om:OMA cdbase="http://grapefruit.com">
      <om:OMV name="k"/><om:OMI>3</om:OMI><om:OMI>5</om:OMI><om:OMI>6</om:OMI>
    </om:OMA>
    <om:OMA cdbase="http://kumquat.com">
      <om:OMV name="k"/>
      <om:OMI>3</om:OMI>
      <om:OMI>5</om:OMI>
      <om:OMA cdbase="http://lemon.com"><om:OMI>1</om:OMI><om:OMI>2</om:OMI><om:OMI>3</om:OMI></om:OMA>
    </om:OMA>
    <om:OMA cdbase="http://ugli.com">
      <om:OMV name="k"/><om:OMI>3</om:OMI><om:OMI>5</om:OMI>
      <om:OMA><om:OMI>1</om:OMI><om:OMI>2</om:OMI><om:OMI>3</om:OMI></om:OMA>
    </om:OMA>
  </om:OMA>
</om:OMOBJ>

The !declare-cd (like the !declare-symbol and !declare-encoding that are discussed later) can be outside the omobj (but must be inside some element). It has the obvious scoping rules. Thus it can be used for several objects in a complex document. Most of the examples on this page are short one-off examples and seem more verbose than they might be as they cannot share symbols in this way.

6 Declaration of symbols

The !declare-symbol command declares a symbol with name, cd, and (optionally) cdbase. This improves reliability, readability and saves time.

omobj
  !declare-symbol @name[lambda] @cdbase[http://www.lambda-calc.org] @cd[lambda-calc]
  !declare-symbol @name[int] @cd[calc]
  !declare-symbol @name[diff] @cdbase[http://www.calc.org] @cd[calc]
  ombind
    lambda
    ombvar x
    ombind
      int 
      ombvar y
      ombind
        diff
        ombvar z
        oma f x y z

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
<om:OMBIND>
  <om:OMS cdbase="http://www.lambda-calc.org" cd="lambda-calc" name="lambda"/>
  <om:OMBVAR><om:OMV name="x"/></om:OMBVAR>
    <om:OMBIND>
      <om:OMS cd="calc" name="int"/>
      <om:OMBVAR><om:OMV name="y"/></om:OMBVAR>
      <om:OMBIND>
        <om:OMS cdbase="http://www.calc.org" cd="calc" name="diff"/>
        <om:OMBVAR><om:OMV name="z"/></om:OMBVAR>
        <om:OMA><om:OMV name="f"/><om:OMV name="x"/><om:OMV name="y"/><om:OMV name="z"/></om:OMA>
      </om:OMBIND>
    </om:OMBIND>
  </om:OMBIND>
</om:OMOBJ>

Normally the symbol name and the GLOSS's element name used to refer to it are the same. The optional attribute @alias can be used when this is not the case.

omobj
  !declare-symbol @name[mylambda] @cdbase[http://www.lambda.org] @cd[lambda-calc] @alias[lambda]
  mylambda

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <om:OMS cdbase="http://www.lambda.org" cd="lambda-calc" name="lambda"/>
</om:OMOBJ>

Symbols may also be defined with a role, and one may also define encodings. These will be described in the next few sections.

7 Further features for OM applications

The application construction is straightforward: an oma followed by a list of expressions. Additionally, a symbol may be declared in the application role, permitting (in fact obligating) the omission of the oma. Braces can be used as usual to delimit open math objects.

omobj
  !declare-symbol @name[difference] @cdbase[http://www.arith1.com] @cd[arith1]
  oma difference x y

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <om:OMA>
    <om:OMS cdbase="http://www.arith1.com" cd="arith1" name="difference"/>
    <om:OMV name="x"/>
    <om:OMV name="y"/>
  </om:OMA>
</om:OMOBJ>
omobj 
  !declare-symbol @name[product] @cdbase[http://www.arith1.com] @cd[arith1] @role[application]
  product x y

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <om:OMA>
    <om:OMS cdbase="http://www.arith1.com" cd="arith1" name="product"/>
    <om:OMV name="x"/>
    <om:OMV name="y"/>
  </om:OMA>
</om:OMOBJ>
omobj 
  !declare-symbol @name[product] @cdbase[http://www.arith1.com] @cd[arith1] @role[application]
  product x product y z

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <om:OMA>
    <om:OMS cdbase="http://www.arith1.com" cd="arith1" name="product"/>
    <om:OMV name="x"/>
    <om:OMA>
      <om:OMS cdbase="http://www.arith1.com" cd="arith1" name="product"/>
      <om:OMV name="y"/>
      <om:OMV name="z"/>
    </om:OMA>
 </om:OMA>
</om:OMOBJ>
omobj 
  !declare-symbol @name[product] @cdbase[http://www.arith1.com] @cd[arith1] @role[application]
  product 
    product a b
    product y z

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <om:OMA>
    <om:OMS cdbase="http://www.arith1.com" cd="arith1" name="product"/>
    <om:OMA>
      <om:OMS cdbase="http://www.arith1.com" cd="arith1" name="product"/>
      <om:OMV name="a"/>
      <om:OMV name="b"/>
    </om:OMA>
    <om:OMA>
      <om:OMS cdbase="http://www.arith1.com" cd="arith1" name="product"/>
      <om:OMV name="y"/>
      <om:OMV name="z"/>
    </om:OMA>
  </om:OMA>
</om:OMOBJ>
omobj 
  !declare-symbol @name[product] @cdbase[http://www.arith1.com] @cd[arith1] @role[application]
  product { product a b } { product y z }

yields the same as the previous example.

8 Further features for OM bindings

Binding objects can be encoded directly as shown above, or there are a number of useful abbreviations. The ombvar is unnecessary for a single variable, or indeed for a group of variables if they are delimited by {..}. (I'm not quite sure about this feature... it could be removed in future versions.)

omobj
  !declare-symbol @name[int] @cd[calc] @cdbase[http://www.mycds.com/calculus]
  ombind
    int x oma times x x

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <om:OMBIND>
    <om:OMS cdbase="http://www.mycds.com/calculus" cd="calc" name="int"/>
    <om:OMBVAR><om:OMV name="x"/></om:OMBVAR>
    <om:OMA><om:OMV name="times"/><om:OMV name="x"/><om:OMV name="x"/></om:OMA>
  </om:OMBIND>
</om:OMOBJ>
omobj
  !declare-symbol @name[int] @cd[calc] @cdbase[http://www.mycds.com/calculus]
  ombind
    int { x y } oma times x y

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <om:OMBIND>
    <om:OMS cdbase="http://www.mycds.com/calculus" cd="calc" name="int"/>
    <om:OMBVAR><om:OMV name="x"/><om:OMV name="y"/></om:OMBVAR>
    <om:OMA><om:OMV name="times"/><om:OMV name="x"/><om:OMV name="y"/></om:OMA>
  </om:OMBIND>
</om:OMOBJ>
omobj
  !declare-symbol @name[int] @cd[calc] @cdbase[http://www.mycds.com/calculus]
  ombind
    int 
    ombvar x 
    oma times x x

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <om:OMBIND>
    <om:OMS cdbase="http://www.mycds.com/calculus" cd="calc" name="int"/>
    <om:OMBVAR><om:OMV name="x"/></om:OMBVAR>
    <om:OMA><om:OMV name="times"/><om:OMV name="x"/><om:OMV name="x"/></om:OMA>
  </om:OMBIND>
</om:OMOBJ>
omobj
  !declare-symbol @name[int] @cd[calc] @cdbase[http://www.mycds.com/calculus]
  ombind
    int
    ombvar x y 
    oma times x y

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <om:OMBIND>
    <om:OMS cdbase="http://www.mycds.com/calculus" cd="calc" name="int"/>
    <om:OMBVAR><om:OMV name="x"/><om:OMV name="y"/></om:OMBVAR>
    <om:OMA><om:OMV name="times"/><om:OMV name="x"/><om:OMV name="y"/></om:OMA>
  </om:OMBIND>
</om:OMOBJ>
omobj
  !declare-symbol @name[int] @cd[calc] @cdbase[http://www.mycds.com/calculus]
  ombind
    int
    { x y }
    oma times x y

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <om:OMBIND>
    <om:OMS cdbase="http://www.mycds.com/calculus" cd="calc" name="int"/>
    <om:OMBVAR><om:OMV name="x"/><om:OMV name="y"/></om:OMBVAR>
    <om:OMA><om:OMV name="times"/><om:OMV name="x"/><om:OMV name="y"/></om:OMA>
  </om:OMBIND>
</om:OMOBJ>

A symbol may be declared in the role of a binding, and then the ombind tag also becomes unnecessary. (In fact it mustn't be present, as OpenMath allows a general expression to be present as the first element of a OMBIND construct and GLOSS has no easy way of distinguishing these two possibilities.

omobj 
  !declare-symbol @name[diff] @cdbase[http://www.calc1.com] @cd[calc1] @role[binding]
  diff x oma times x x

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <om:OMBIND>
    <om:OMS cdbase="http://www.calc1.com" cd="calc1" name="diff"/>
    <om:OMBVAR><om:OMV name="x"/></om:OMBVAR>
    <om:OMA><om:OMV name="times"/><om:OMV name="x"/><om:OMV name="x"/></om:OMA>
  </om:OMBIND>
</om:OMOBJ>
omobj 
  !declare-symbol @name[diff] @cdbase[http://www.calc1.com] @cd[calc1] @role[binding]
  ombind 
    diff x oma times x x
    y 
    oma f y

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <om:OMBIND>
    <om:OMBIND>
      <om:OMS cdbase="http://www.calc1.com" cd="calc1" name="diff"/>
      <om:OMBVAR><om:OMV name="x"/></om:OMBVAR>
      <om:OMA><om:OMV name="times"/><om:OMV name="x"/><om:OMV name="x"/></om:OMA>
    </om:OMBIND>
    <om:OMBVAR><om:OMV name="y"/></om:OMBVAR>
    <om:OMA><om:OMV name="f"/><om:OMV name="y"/></om:OMA></om:OMBIND></om:OMOBJ>
  </om:OMBIND>
</om:OMOBJ>

(OK, I know that example was pretty silly, but it is legal OpenMath and illustrates why ombind shouldn't be placed before a @role[binding] declared symbol unless you know what you are doing.)

9 Further features for OM foreign objects

OMFOREIGN elements are encoded in the usual GLOSS style, or via a new symbol introduced via the !declare-encoding tag. Note that GLOSS modules for the foreign encoding methods may have to be loaded before the openmath module is loaded. (There is a work-around for this, currently implemented but not fully tested.)

Note that an element defined by !declare-encoding puts input back into the default mode, so a further command may be required to get into the correct mode. Hence the pmathml math in the example below. There may be scope for declaring a GLOSS mode along with an encoding, but this requires careful thought.

Direct coding:

omobj omforeign @encoding[tex] [$\\frac\{X\}\{Y\}$]

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <om:OMFOREIGN encoding="tex">$\frac{X}{Y}$</om:OMFOREIGN>
</om:OMOBJ>

Via a declared encoding:

omobj
  !declare-encoding @name[tex] @encoding[application/x-latex]
  tex [$\\frac\{X\}\{Y\}$]

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <om:OMFOREIGN encoding="application/x-latex">$\frac{X}{Y}$</om:OMFOREIGN>
</om:OMOBJ>

Example using MathML encoded directly:

omobj
  !declare-encoding @name[pmathml] @encoding[p-MathML]
  pmathml m:math m:mrow {m:mn [1]} {m:mo [+]} {m:mi [x]}

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <om:OMFOREIGN encoding="p-MathML">
    <m:math xmlns:m="http://www.w3.org/1998/Math/MathML">
      <m:mrow><m:mn>1</m:mn><m:mo>+</m:mo><m:mi>x</m:mi></m:mrow>
    </m:math>
  </om:OMFOREIGN>
</om:OMOBJ>

(Note that the m: namespace prefix has to be defined for this to work.

The same example using the GLOSS-pmathml module:

omobj 
  !declare-encoding @name[pmathml] @encoding[p-MathML]
  pmathml math 1 + x

10 Further features for OM errors

OM error objects are coded similarly, either via the usual GLOSS syntax or via !declare-symbol and @role[error].

omobj
  !declare-symbol @name[divide] @cdbase[http://www.arith2.com] @cd[simple2] @role[application]
  ome
    oms @name[division-by-zero] @cd[errors]
    divide x 0

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <om:OME>
    <om:OMS name="division-by-zero" cd="errors"/>
    <om:OMA>
      <om:OMS cdbase="http://www.arith2.com" cd="simple2" name="divide"/><om:OMV name="x"/><om:OMI>0</om:OMI>
    </om:OMA>
  </om:OME>
</om:OMOBJ>
omobj
  !declare-symbol @name[power] @cdbase[http://www.arith2.com] @cd[simple2] @role[application]
  !declare-symbol @name[overflow] @cdbase[http://www.arith2.com] @cd[simple2] @role[error]
  overflow power 1000000 1000000 

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <om:OME>
    <om:OMS cdbase="http://www.arith2.com" cd="simple2" name="overflow"/>
    <om:OMA>
      <om:OMS cdbase="http://www.arith2.com" cd="simple2" name="power"/>
      <om:OMI>1000000</om:OMI>
      <om:OMI>1000000</om:OMI>
    </om:OMA>
  </om:OME>
</om:OMOBJ>

11 Further features for OM attributions

The OpenMath Attribution construct is by far the most complicated. We have already seen an example. It is also possible to declare a symbol as in the attribution role and then the key words omattr and omatp may be omitted. The idiom is that the value of the attribution is a child of the symbol.

omobj
  !declare-symbol @name[myattr] @cdbase[http://www.mycdbase.com] @cd[mycd] @role[attribution]
  !declare-symbol @name[times] @cdbase[http://www.arith2.com] @cd[simple2] @alias[product]
  omattr
    omatp
      oms @name[value] @cd[mycd] 
        0xEFAD
      oms @name[value] @cd[attributions]
        123
    v

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <om:OMATTR>
    <om:OMATP>
      <om:OMS name="value" cd="mycd"/>
      <om:OMI>xEFAD</om:OMI>
      <om:OMS name="value" cd="attributions"/>
      <om:OMI>123</om:OMI>
    </om:OMATP>
    <om:OMV name="v"/>
  </om:OMATTR>
</om:OMOBJ>

In the following example, myattr is a known attribution symbol, and there is only one attribution value for this object, and both attribution and the object itself are children of myattr.

omobj
  !declare-symbol @name[myattr] @cdbase[http://www.mycdbase.com] @cd[mycd] @role[attribution]
  myattr "my second favourite variable"
    y

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <om:OMATTR>
    <om:OMATP>
      <om:OMS cdbase="http://www.mycdbase.com" cd="mycd" name="myattr"/>
      <om:OMSTR>my second favourite variable</om:OMSTR>
    </om:OMATP>
    <om:OMV name="y"/>
  </om:OMATTR>
</om:OMOBJ>

More examples:

omobj
  !declare-symbol @name[myattr] @cdbase[http://www.mycdbase.com] @cd[mycd] @role[attribution]
  !declare-symbol @name[times] @cdbase[http://www.arith2.com] @cd[simple2] @alias[product]
  myattr =3456 data

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <om:OMATTR>
    <om:OMATP>
      <om:OMS cdbase="http://www.mycdbase.com" cd="mycd" name="myattr"/>
      <om:OMB>3456</om:OMB>
    </om:OMATP>
    <om:OMV name="data"/>
  </om:OMATTR>
</om:OMOBJ>

The next example shows that the standard OpenMath structure can be used, where attribute symbols and values are siblings.

omobj
  !declare-symbol @name[myattr] @cdbase[http://www.mycdbase.com] @cd[mycd] @role[attribution]
  !declare-symbol @name[times] @cdbase[http://www.arith2.com] @cd[simple2] @alias[product]
  oma
    times
    omattr 
      omatp 
        myattr
        "my favourite variable"
        oms @name[value] @cd[attributions]
        123
      x
    myattr "my second favourite variable"
      y
    x

yields

<om:OMOBJ xmlns:om="http://www.openmath.org/OpenMath">
  <om:OMA>
    <om:OMS cdbase="http://www.arith2.com" cd="simple2" name="product"/>
    <om:OMATTR>
      <om:OMATP>
        <om:OMS cdbase="http://www.mycdbase.com" cd="mycd" name="myattr"/>
        <om:OMSTR>my favourite variable</om:OMSTR>
        <om:OMS name="value" cd="attributions"/>
        <om:OMI>123</om:OMI>
      </om:OMATP><om:OMV name="x"/>
    </om:OMATTR>
    <om:OMATTR>
      <om:OMATP>
        <om:OMS cdbase="http://www.mycdbase.com" cd="mycd" name="myattr"/>
        <om:OMSTR>my second favourite variable</om:OMSTR>
      </om:OMATP>
      <om:OMV name="y"/></om:OMATTR>
    <om:OMV name="x"/>
  </om:OMA>
</om:OMOBJ>

12 Bugs, and a TO DO list

There's plenty to do, or at least to check, here: need to check that variable attributions work properly in a binding construction in all possible legal combinations; braces { } were coded late and not thoroughly checked; no doubt more testing (and bug fixing) is required.

Currently the om: prefix is hard-coded in with no option to change it. This should not cause any real issues (and will not clash with foreign elements that also use the om prefix dues to GLOSS's XMLNS rules) but it woud be nice to provide a user option to change it.

This page is copyright. Web page design and creation by GLOSS.