<?xml version="1.0" encoding="iso-8859-1"?><?xml-stylesheet  type="text/xsl" href="pmathml.xsl"?><html xmlns="http://www.w3.org/1999/xhtml" xmlns:m="http://www.w3.org/1998/Math/MathML" xml:space="preserve">
<head>
<title>The OpenMath Standard</title>

<style>
p {text-align:justify;	   
  }
code {font-size: 125%;
      font-family: monospace; 
     }
.figure {
border-width:1px;
border-color: black;
}
.footnote{
font-size: 75%;
font-style: italic;
}
.delliteral {
font-size: 75%;
background-color: #cfcfcf;
border-color: black;
border-style: solid;
border-width: 1px;
padding: 1em;
color: red;
text-decoration: line-through;
}
.newliteral {
font-size: 75%;
background-color: #cfcfcf;
border-color: black;
border-style: solid;
border-width: 1px;
padding: 1em;
color: green;
}
.literal {
font-size: 75%;
background-color: #cfcfcf;
border-color: black;
border-style: solid;
border-width: 1px;
padding: 1em;
}
.del {
color: red;
text-decoration: line-through;
}
.new {
color: green;
}
.chg {
color: blue;
}
.changetoc {
border-style: solid;
border-color: black;
border-width: 1px;
margin: 2em 2em 2em 2em;
background-color: yellow;
}

.lowerroman {
list-style-type: lower-roman;
}
</style>
</head>
<body>
<h1>The <i>OpenMath</i> Standard</h1>
<div>
Version: 2.0 Public Draft 4 (21 November 2003)
</div>

<div>
The OpenMath Society
</div>

<div>Editors<br/>
S. Buswell, O. Caprotti, D. P. Carlisle, M. C. Dewar, M. Gaetano, M. Kohlhase
</div>

<div>
November 2003
</div>

<div>
<h3>Abstract</h3>
<p>This document proposes <i>OpenMath</i> as a standard for the communication of
  semantically rich mathematical objects. This draft of the <i>OpenMath</i> 
  standard comprises the following: a description of <i>OpenMath</i> objects, the
  grammar of <span>xml</span> and of the binary encoding of objects, a
  description of Content Dictionaries and an <span>xml</span> document type
  definition for validating Content Dictionaries. The non-normative
  <a href="#cha_his">Chapter 1</a> of this document briefly overviews the history
  of <i>OpenMath</i>.</p>
</div>






  
<h2>Contents</h2><a href="#cha_his">1 <i>OpenMath</i> Movement</a><br/>
    <a href="#sec_hist">1.1 History</a><br/>
    <a href="#sec_omsoc">1.2 <i>OpenMath</i> Society</a><br/><a href="#cha_int">2 Introduction to <i>OpenMath</i></a><br/>
    <a href="#sec_om-arch">2.1 <i>OpenMath</i> Architecture</a><br/>
    <a href="#sec_intro-obj">2.2 <i>OpenMath</i> Objects and Encodings</a><br/>
    <a href="#sec_intro-cd">2.3 Content Dictionaries</a><br/>
    <a href="#sec_addnfiles">2.4 Additional Files</a><br/>
    <a href="#sec_phrasebooks">2.5 Phrasebooks</a><br/><a href="#cha_obj">3 <i>OpenMath</i> Objects</a><br/>
    <a href="#sec_omabs">3.1 Formal Definition of <i>OpenMath</i> Objects</a><br/>
        <a href="#sec_basic">3.1.1 Basic <i>OpenMath</i> objects</a><br/>
        <a href="#sec_derived">3.1.2 Derived <i>OpenMath</i> Objects</a><br/>
        <a href="#sec_compound">3.1.3 Compound <i>OpenMath</i> Objects</a><br/>
        <a href="#sec_roles">3.1.4 <i>OpenMath</i> Symbol Rôles</a><br/>
    <a href="#sec_omin">3.2 Further Description of <i>OpenMath</i> Objects</a><br/>
    <a href="#sec_names">3.3 Names</a><br/>
    <a href="#sec_summary">3.4 Summary</a><br/><a href="#cha_enco">4 <i>OpenMath</i> Encodings</a><br/>
    <a href="#sec_xml">4.1 The <span>xml</span> Encoding</a><br/>
        <a href="#ssec_xml">4.1.1 A <span>Schema</span> for the <span>xml</span> Encoding</a><br/>
        <a href="#sec_xml-desc">4.1.2 <span>Informal</span> description of
the <span><span>xml</span> Encoding</span></a><br/>
            <a href="#sec_acyclicity">4.1.2.1 An Acyclicity Constraint</a><br/>
            <a href="#sec_sharing_bvars">4.1.2.2 Sharing and Bound Variables</a><br/>
        <a href="#xmldoc">4.1.3 Embedding <i>OpenMath</i> in <span>xml</span> Documents</a><br/>
    <a href="#sec_binary">4.2 The Binary Encoding</a><br/>
        <a href="#sec_binary_grammar">4.2.1 A Grammar for the Binary Encoding</a><br/>
        <a href="#sec_bin-desc">4.2.2 Description of the Grammar</a><br/>
            <a href="#sec_sharing">4.2.2.1 Sharing <span>in Objects beginning with the identifier [24]</span></a><br/>
        <a href="#sec_sharing_references">4.2.3 Sharing with References (beginning with [24+64])</a><br/>
        <a href="#sec_impl_note">4.2.4 Implementation Note</a><br/>
        <a href="#sec_bin_example">4.2.5 Example of Binary Encoding</a><br/>
        <a href="#sec_relation_OM1_binary">4.2.6 Relation to the <i>OpenMath</i>1 binary encoding</a><br/>
    <a href="#sec_enc_summary">4.3 Summary</a><br/><a href="#cha_cd">5 Content Dictionaries</a><br/>
    <a href="#sec_cd_summary">5.1 Introduction</a><br/>
    <a href="#sect_func">5.2 Abstract Content Dictionaries</a><br/>
        <a href="#sec_status">5.2.1 Content Dictionary Status</a><br/>
        <a href="#sec_version">5.2.2 Content Dictionary Version Numbers</a><br/>
    <a href="#sec_xml_cd">5.3 The <span>Reference</span> Encoding for Content Dictionaries</a><br/>
        <a href="#sec_cd_schema">5.3.1 The RelaxNG Schema for Content Dictionaries</a><br/>
        <a href="#sect_pcdata">5.3.2 Further <span>Description of
the CD Schema</span></a><br/>
    <a href="#addfiles">5.4 Additional Information</a><br/>
        <a href="#sigfiles">5.4.1 Signature
<span>Dictionaries</span>
</a><br/>
            <a href="#sect_sigpcdata">5.4.1.1 
<span>
Abstract Specification</span>
 of a Signature File</a><br/>
            <a href="#sect_sigschema">5.4.1.2 A RelaxNG Schema for a Signature File</a><br/>
            <a href="#sect_sigex">5.4.1.3 Examples</a><br/>
        <a href="#ssec_cdgroups">5.4.2 CDGroups</a><br/>
            <a href="#sec_dtd_cdg">5.4.2.1 The Specification of CDGroups</a><br/>
            <a href="#sect_cdgpcdata">5.4.2.2 Further Requirements of a CDGroup</a><br/>
    <a href="#cdapprove">5.5 Content Dictionaries Reviewing Process</a><br/><a href="#cha_comp">6 <i>OpenMath</i> Compliance</a><br/>
    <a href="#sec_compl_encoding">6.1 Encoding</a><br/>
    <a href="#sec_compl_cd">6.2 Content Dictionaries</a><br/>
    <a href="#sec_comp_lex">6.3 Lexical Errors</a><br/><a href="#cha_conc">7 Conclusion</a><br/><a href="#app_cdfiles">A CD Files</a><br/>
    <a href="#app_cdcd">A.1 The <b>meta</b> Content Dictionary</a><br/>
    <a href="#arith1.ocd">A.2 The  <b>arith1</b> Content Dictionary File</a><br/>
    <a href="#arith1.sts">A.3 The  <b>arith1</b> STS Signature File</a><br/>
    <a href="#mathml.cdg">A.4 The  <b>MathML</b> CDGroup</a><br/>
    <a href="#errorcd">A.5 The <b>error</b> Content Dictionary</a><br/><a href="#app_openmath.rng">B <i>OpenMath</i> Schema in Relax NG XML Syntax (Normative)</a><br/><a href="#app_relaxrestricted">C Restricting the <i>OpenMath</i> Schema (Non-Normative)</a><br/><a href="#app_xsd">D <i>OpenMath</i> Schema in XSD Syntax (Non-Normative)</a><br/><a href="#app_dtd">E <i>OpenMath</i> DTD (Non-Normative)</a><br/><a href="#app_whats_new">F Changes between <i>OpenMath</i> 1.1 and <i>OpenMath</i> 2 (Non-Normative)</a><br/>
    <a href="#chgformal">F.1 Changes to the Formal Definition of Objects</a><br/>
    <a href="#chgenc">F.2 Changes to the encodings</a><br/>
    <a href="#chgcd">F.3 Changes to Content Dictionaries</a><br/><a href="#bibliography">G Bibliography</a><br/>
<h2>List of Figures</h2><a href="#fig_om">2.1 The <i>OpenMath</i> Architecture</a><br/><a href="#fig_obj">3.1 The <i>OpenMath</i> application and binding objects for
<m:math><m:mi>sin</m:mi> <m:mo>(</m:mo><m:mi>x</m:mi> <m:mo>)</m:mo></m:math>  and
<m:math><m:mi>&#955;</m:mi> <m:mi>x</m:mi><m:mo>.</m:mo><m:mi>x</m:mi> <m:mo>+</m:mo>
<m:mn>2</m:mn></m:math>  in tree-like notation.</a><br/><a href="#fig_shared_vs_unshared">4.1 Shared vs. unshared representations</a><br/><a href="#fig_bin-enc">4.2 Grammar of the binary encoding of <i>OpenMath</i> objects.</a><br/><a href="#fig_bin-enc2">4.3 A binary encoding of the <i>OpenMath</i> object from figure <a href="#fig_shared_vs_unshared">Figure 4.1</a>.</a><br/><a href="#fig_cdgroup.dtd">5.1 <span>Relax NG</span> Specification of CDGroups</a><br/>

<h2 name="cha_his" id="cha_his">
  Chapter 1<br/><i>OpenMath</i> Movement</h2>



<p>This chapter is a historical account of <i>OpenMath</i> and should be regarded
as non-normative.</p>

<p><i>OpenMath</i> is a standard for representing mathematical objects,
allowing them to be exchanged between computer programs, stored in
databases, or published on the worldwide web.  While the original
designers were mainly developers of computer algebra systems, it is
now attracting interest from other areas of scientific computation and
from many publishers of electronic documents with a significant
mathematical content.  There is a strong relationship to the MathML
recommendation <a href="#MathML_2000">[18]</a> from the Worldwide Web
Consortium, and a large overlap between the two developer communities.
MathML deals principally with the <i>presentation</i> of
mathematical objects, while <i>OpenMath</i> is solely concerned with their
semantic meaning or <i>content</i>.  While MathML does
have some limited facilities for dealing with content, it also allows
semantic information encoded in <i>OpenMath</i> to be embedded inside a MathML
structure.  Thus the two technologies may be seen as highly
complementary.</p>

<div><h3 name="sec_hist" id="sec_hist">1.1 History</h3>



<p><i>OpenMath</i> was originally developed through a series of workshops held
in Zurich (1993 and 1996), Oxford (1994), Amsterdam (1995), Copenhagen
(1995), Bath (1996), Dublin (1996), Nice (1997), Yorktown Heights
(1997), Berlin (1998), and Tallahassee (1998).  The participants in
these workshops formed a global <i>OpenMath</i> community which was coordinated
by a Steering Committee and operated through electronic mailing groups
and ad-hoc working parties.  This loose arrangement has been
formalised through the establishment of an <i>OpenMath</i> Society.  Up until the
end of 1996 much of the work of the community was funded through a
grant from the Human Capital and Mobility program of the European
Union, the contributions of several institutions and individuals.  A
document outlining the objectives and basic design of <i>OpenMath</i> was
produced (later published as
<a href="#Abbott_Leeuwen_Strotmann_98">[1]</a>).  By the end of 1996
a simplified specification had been agreed on and some prototype
implementations have come about
<a href="#Dalmas_Gaetano_Watt_97">[5]</a>.</p>


<p>In 1996 a group of European participants in <i>OpenMath</i> decided to bid
for funding under the European Union's Fourth Framework Programme for
strategic research in information technology.  This bid was successful
and the project started in late 1997.  The principal aims of the
project are to formalise <i>OpenMath</i> as a standard and to develop it
further through industrial applications; this document is a product of
that process and draws heavily on the previous work described earlier.
<i>OpenMath</i> participants from all over the world continue to meet
regularly and cooperate on areas of mutual interest, and
recent workshops in Tallahassee (November 1998) and Eindhoven (June
1999)  endorsed  drafts of this document as the current <i>OpenMath</i> standard.</p>




</div>

<div><h3 name="sec_omsoc" id="sec_omsoc">1.2 <i>OpenMath</i> Society</h3>



<p>In November 1998 the <i>OpenMath</i> Society has been established to coordinate
all <i>OpenMath</i> activities. The society is based in Helsinki, Finland and is
steered by the executive committee whose members are elected by the
society. The official web page of the society is
<a href="http://www.openmath.org">http://www.openmath.org</a>.</p>
</div>



<h2 name="cha_int" id="cha_int">
  Chapter 2<br/>Introduction to <i>OpenMath</i></h2>





<p>This chapter briefly introduces <i>OpenMath</i> concepts and notions that are
referred to in the rest of this document.</p>

<div><h3 name="sec_om-arch" id="sec_om-arch">2.1 <i>OpenMath</i> Architecture</h3>



<div class="figure"><a name="fig_om" id="fig_om"/>
    
    <img src="om-arch.png" alt="om-arch.png"/>
<div>
  Figure 2.1 The <i>OpenMath</i> Architecture</div></div>

<p>The architecture of <i>OpenMath</i> is described in <a href="#fig_om">Figure 2.1</a> and summarizes the interactions among the different
<i>OpenMath</i> components.  There are three layers of representation of a
mathematical object <a href="#OM_98">[12]</a>. A private layer that
is the internal representation used by an application.  An abstract
layer that is the representation as an <i>OpenMath</i> object. Third is a
communication layer that translates the <i>OpenMath</i> object representation to
a stream of bytes. An application dependent program manipulates the
mathematical objects using its internal representation, it can convert
them to <i>OpenMath</i> objects and communicate them by using the byte stream
representation of <i>OpenMath</i> objects.</p>
</div>

<div><h3 name="sec_intro-obj" id="sec_intro-obj">2.2 <i>OpenMath</i> Objects and Encodings</h3>






<p><i>OpenMath</i> objects are representations of mathematical entities that
can be communicated among various software applications in a
meaningful way, that is, preserving their
<span>"semantics"</span>.</p>

<p><i>OpenMath</i> objects and encodings are described in detail in <a href="#cha_obj">Chapter 3</a> and <a href="#cha_enco">Chapter 4</a>.</p>




<p>The standard endorses encodings in <span>xml</span> and binary
format. These are the encodings supported by the official <i>OpenMath</i>
libraries. However they are not the only possible encodings of <i>OpenMath</i>
objects. Users that wish to define their own encoding using some other
specific language (e.g.  Lisp) may do so provided there is an
effective translation of this encoding to an official one.</p>
</div>

<div><h3 name="sec_intro-cd" id="sec_intro-cd">2.3 Content Dictionaries</h3>



<p>Content Dictionaries (CDs) are used to assign informal and formal
semantics to all symbols used in the <i>OpenMath</i> objects. They define the
symbols used to represent concepts arising in a particular area of
mathematics.</p>

<p>The Content Dictionaries are public, they represent the actual
common knowledge among <i>OpenMath</i> applications.  Content Dictionaries fix
the <span>"meaning"</span> of objects independently of the
application.  The application receiving the object may then recognize
whether or not, according to the semantics of the symbols defined in
the Content Dictionaries, the object can be transformed to the
corresponding internal representation used by the application.</p>
</div>

<div><h3 name="sec_addnfiles" id="sec_addnfiles">2.4 Additional Files</h3>
  <p>Several
additional files are related to Content Dictionaries.  Signature files
contain the signatures of symbols defined in some <i>OpenMath</i> Content
Dictionary and their format is endorsed by this standard.</p>

<p>Furthermore, the standard fixes how to define as a CDGroup a specific
set of Content Dictionaries.</p>

<p>Auxiliary files that define presentation and rendering or that
are used for manipulating and processing Content Dictionaries are not
discussed by the standard.</p>


</div>
<div><h3 name="sec_phrasebooks" id="sec_phrasebooks">2.5 Phrasebooks</h3>




<p>The conversion of an <i>OpenMath</i> object to/from the internal
representation in a software application is performed by an interface
program called <i>Phrasebook</i>. The translation is
governed by the Content Dictionaries and the specifics of the
application. It is envisioned that a software application dealing with
a specific area of mathematics declares which Content Dictionaries it
understands. As a consequence, it is expected that the Phrasebook of
the application is able to translate <i>OpenMath</i> objects built using symbols
from these Content Dictionaries to/from the internal mathematical
objects of the application.</p>

 <p><i>OpenMath</i> objects do not
specify any computational behaviour, they merely represent mathematical
expressions.  Part of the <i>OpenMath</i> philosophy is to leave it to the
application to decide what it does with an object once it has received
it.  <i>OpenMath</i> is not a query or programming language. Because of this,
<i>OpenMath</i> does not prescribe a way of forcing <span>"evaluation"</span> or
<span>"simplification"</span> of objects like
<m:math><m:mn>2</m:mn><m:mo>+</m:mo><m:mn>3</m:mn></m:math>  or
<m:math><m:mi>sin</m:mi><m:mo>(</m:mo><m:mi>&#960;</m:mi><m:mo>)</m:mo></m:math>. Thus,
the same object <m:math><m:mn>2</m:mn><m:mo>+</m:mo><m:mn>3</m:mn></m:math>  could be
transformed to <m:math><m:mn>5</m:mn></m:math>  by a computer algebra system,
or displayed as <m:math><m:mn>2</m:mn><m:mo>+</m:mo><m:mn>3</m:mn></m:math>  by a
typesetting tool.</p>
</div>


<h2 name="cha_obj" id="cha_obj">
  Chapter 3<br/><i>OpenMath</i> Objects</h2>




<p>In this chapter we provide a self-contained description of <i>OpenMath</i>
objects. We first do so by means of an abstract grammar
description (<a href="#sec_omabs">Section 3.1</a>)
and then give a more informal description (<a href="#sec_omin">Section 3.2</a>).</p>


<div><h3 name="sec_omabs" id="sec_omabs">3.1 Formal Definition of <i>OpenMath</i> Objects</h3>



<p><i>OpenMath</i> represents mathematical objects as terms or as labelled
trees that are called <i>OpenMath</i> objects or <i>OpenMath</i> expressions. The definition
of an abstract <i>OpenMath</i> object is then the following.</p>


<div><h4 name="sec_basic" id="sec_basic">3.1.1 Basic <i>OpenMath</i> objects</h4>
 <p>The Basic <i>OpenMath</i> Objects form
the leaves of the <i>OpenMath</i> Object tree.  A Basic <i>OpenMath</i> Object is of one of
the following.</p> 
<ul>
<li><p><span>(i)</span> Integer.</p><p>Integers in
  the mathematical sense, with no predefined range.  They are
  <span>"infinite precision"</span> integers (also called
  <span>"bignums"</span> in computer algebra).</p></li>
<li><p><span>(ii)</span> IEEE floating point
    number.</p><p>Double precision floating-point numbers
    following the <span>ieee</span> 754-1985
    standard <a href="#ieee754_85">[8]</a>.</p></li>
<li><p><span>(iii)</span> Character string.</p><p>A Unicode Character string. This also corresponds to `characters' in
  <span>xml</span>.</p></li>
<li><p><span>(iv)</span> Bytearray.</p><p>A sequence of bytes.</p></li>
<li><p><span>(v)</span> Symbol.</p><p>A Symbol encodes three fields of
information, a <i>name</i>, a <i>Content
Dictionary</i>, and (optionally) a role.  The name of a symbol
is a sequence of characters matching the regular expression described
in <a href="#sec_names">Section 3.3</a>.  The Content Dictionary is the
location of the definition of the symbol, consisting of a name (a
sequence of characters matching the regular expression described in
<a href="#sec_names">Section 3.3</a>) and, optionally, a unique prefix called
a <i>cdbase</i> which is used to
disambiguate multiple Content Dictionaries of the same name.  The role
is a restriction on where the symbol may appear in an <i>OpenMath</i> object.
The possible roles are described in <a href="#sec_roles">Section 3.1.4</a>.

</p></li>
<li><p><span>(vi)</span> Variable.</p><p>A Variable 
<span>must have</span> a
<i>name</i> which is a sequence of characters matching a
regular expression, as described in <a href="#sec_names">Section 3.3</a>.
<span>Where the variable is a member of an
enumerated set it also has a child which is an <i>OpenMath</i> object
representing its indices.  </span></p></li>
</ul>
</div>

<div><h4 name="sec_derived" id="sec_derived">3.1.2 Derived <i>OpenMath</i> Objects</h4>


<p>A derived<i>OpenMath</i> object is built as follows: 
<ul>
<li><p><span>(i)</span> If <m:math><m:mi>A</m:mi></m:math>  is
<i>not</i> an <i>OpenMath</i> object, then <m:math><m:mi mathvariant="bold">foreign</m:mi><m:mfenced><m:mi>A</m:mi></m:mfenced></m:math>  is an <i>OpenMath</i>
<i>foreign object</i>.</p></li>
</ul>
</p>
</div>

<div><h4 name="sec_compound" id="sec_compound">3.1.3 Compound <i>OpenMath</i> Objects</h4>

  
<p><i>OpenMath</i> objects are built recursively as follows.
<ul>
<li><p><span>(i)</span> Basic <i>OpenMath</i> objects are <i>OpenMath</i> objects.
<span>Derived <i>OpenMath</i> objects are <i>not</i>
<i>OpenMath</i> objects.</span></p></li>

<li><p>
    <span>(ii)</span> If
    <m:math><m:msub><m:mi>A</m:mi><m:mn>1</m:mn></m:msub></m:math>,
    <span>&#8230;</span>,
    <m:math><m:msub><m:mi>A</m:mi><m:mi>n</m:mi></m:msub></m:math> 
    <m:math><m:mo>(</m:mo><m:mi>n</m:mi><m:mo>&gt;</m:mo><m:mn>0</m:mn><m:mo>)</m:mo></m:math> 
    are <i>OpenMath</i> objects, then
  <m:math display="block">
  <m:mi mathvariant="bold">application</m:mi><m:mo>(</m:mo><m:msub><m:mi>A</m:mi><m:mn>1</m:mn></m:msub><m:mo>,</m:mo> <m:mi>&#8230;</m:mi><m:mo>,</m:mo> <m:msub><m:mi>A</m:mi><m:mi>n</m:mi></m:msub><m:mo>)</m:mo>
  </m:math>
  is an <i>OpenMath</i> <i>application object</i>.</p></li> <li><p><span>(iii)</span> If
  <m:math><m:msub><m:mi>S</m:mi><m:mn>1</m:mn></m:msub><m:mo>,</m:mo>
  <m:mi>&#8230;</m:mi><m:mo>,</m:mo> <m:msub><m:mi>S</m:mi><m:mi>n</m:mi></m:msub></m:math> 
  are <i>OpenMath</i> symbols, and

<span>
<m:math><m:mi>A</m:mi></m:math>  is an <i>OpenMath</i> object, and
  <m:math><m:msub><m:mi>A</m:mi><m:mn>1</m:mn></m:msub></m:math>,
  <span>&#8230;</span>, <m:math><m:msub><m:mi>A</m:mi><m:mi>n</m:mi></m:msub></m:math>  <m:math><m:mo>(</m:mo><m:mi>n</m:mi><m:mo>&gt;</m:mo><m:mn>0</m:mn><m:mo>)</m:mo></m:math>  are <i>OpenMath</i> objects or <i>OpenMath</i> derived objects, then
</span>

  <m:math display="block"><m:mi mathvariant="bold">attribution</m:mi>
  <m:mo>(</m:mo><m:mi>A</m:mi><m:mo>,</m:mo> <m:msub><m:mi>S</m:mi><m:mn>1</m:mn></m:msub>
  <m:mspace width=".3em"/> <m:msub><m:mi>A</m:mi><m:mn>1</m:mn></m:msub><m:mo>,</m:mo>
  <m:mspace width=".3em"/> <m:mi>&#8230;</m:mi> <m:mspace width=".3em"/>
  <m:mo>,</m:mo> <m:msub><m:mi>S</m:mi><m:mi>n</m:mi></m:msub> <m:mspace width=".3em"/>
  <m:msub><m:mi>A</m:mi><m:mi>n</m:mi></m:msub><m:mo>)</m:mo></m:math> is an <i>OpenMath</i>
  <i>attribution object</i>. 

   <m:math><m:mi>A</m:mi></m:math> 
  is the object <i>stripped of attributions</i>. <span>
  <m:math><m:msub><m:mi>S</m:mi><m:mn>1</m:mn></m:msub><m:mo>,</m:mo>
  <m:mi>&#8230;</m:mi><m:mo>,</m:mo> <m:msub><m:mi>S</m:mi><m:mi>n</m:mi></m:msub></m:math> 
  are referred to as <i>keys</i> and
  <m:math><m:msub><m:mi>A</m:mi><m:mn>1</m:mn></m:msub></m:math>,
  <span>&#8230;</span>,
  <m:math><m:msub><m:mi>A</m:mi><m:mi>n</m:mi></m:msub></m:math>  as their associated
  <i>values</i></span>. The operation of recursively
  applying stripping to the stripped object is called
  <i>flattening of the attribution</i>.

                  When the stripped object after flattening is a
  variable, the attributed object is called <i>attributed
  variable</i>.</p></li>

<li><p><span>(iv)</span> If <m:math><m:mi>B</m:mi></m:math>  and
  <m:math><m:mi>C</m:mi></m:math>  are <i>OpenMath</i> objects, and
  <m:math><m:msub><m:mi>v</m:mi><m:mn>1</m:mn></m:msub></m:math>,
  <m:math><m:mi>&#8230;</m:mi></m:math>,
  <m:math><m:msub><m:mi>v</m:mi><m:mi>n</m:mi></m:msub></m:math> 
  <m:math><m:mo>(</m:mo><m:mi>n</m:mi> <m:mo>&#8805;</m:mo>
  <m:mn>0</m:mn><m:mo>)</m:mo></m:math>  are <i>OpenMath</i> variables or attributed
  variables, then
  <m:math display="block">
  <m:mi mathvariant="bold">binding</m:mi> <m:mo>(</m:mo><m:mi>B</m:mi><m:mo>,</m:mo> <m:msub><m:mi>v</m:mi><m:mn>1</m:mn></m:msub><m:mo>,</m:mo> <m:mi>&#8230;</m:mi><m:mo>,</m:mo> <m:msub><m:mi>v</m:mi><m:mi>n</m:mi></m:msub><m:mo>,</m:mo> <m:mi>C</m:mi><m:mo>)</m:mo>
  </m:math>
is an <i>OpenMath</i> <i>binding object</i>.</p></li>
<li><p><span>(v)</span> If <m:math><m:mi>S</m:mi></m:math>  is an
<i>OpenMath</i> symbol and <m:math><m:msub><m:mi>A</m:mi><m:mn>1</m:mn></m:msub></m:math>,
<span>&#8230;</span>,
<m:math><m:msub><m:mi>A</m:mi><m:mi>n</m:mi></m:msub></m:math> 
<m:math><m:mo>(</m:mo><m:mi>n</m:mi> <m:mo>&#8805;</m:mo>
<m:mn>0</m:mn><m:mo>)</m:mo></m:math>  are <i>OpenMath</i> objects, then <m:math display="block"><m:mi mathvariant="bold">error</m:mi>
<m:mo>(</m:mo><m:mi>S</m:mi><m:mo>,</m:mo>
<m:msub><m:mi>A</m:mi><m:mn>1</m:mn></m:msub><m:mo>,</m:mo><m:mi>&#8230;</m:mi><m:mo>,</m:mo><m:msub><m:mi>A</m:mi><m:mi>n</m:mi></m:msub><m:mo>)</m:mo>
  </m:math>
  is an <i>OpenMath</i> <i>error object</i>.</p></li>
</ul>
</p>
</div>

<div><h4 name="sec_roles" id="sec_roles">3.1.4 <i>OpenMath</i> Symbol Rôles</h4>


<p>The <i>rôle</i> of an <i>OpenMath</i> symbol is a restriction
on where it can appear in an <i>OpenMath</i> object.  A symbol cannot have more
than one role.  If no role is indicated
then the symbol can be used anywhere.  Possible roles are:
<ol class="lowerroman">

<li><p><i>binder</i> The symbol may only
appear as the first child of an <i>OpenMath</i> binding object.
</p></li>

<li><p> <i>attribution</i> The symbol may only
be used as key in an <i>OpenMath</i> attribution object, i.e. as the first
element of a key-value pair, or in an equivalent context (for example
to refer to the value of an attribution).  This form of attribution
may be ignored by an application, so should be used for information
which does not change the meaning of the attributed <i>OpenMath</i> object.
</p></li> 

<li><p> <i>semantic-attribution</i> This is the
same as <i>attribution</i> except that it modifies the
meaning of the attributed <i>OpenMath</i> object and thus cannot be ignored by an
application.  </p></li> 

<li><p> <i>error</i> The symbol can only appear
as the first child of an <i>OpenMath</i> error object.  </p></li>
<li><p> <i>default</i> The symbol can appear
anywhere not defined in the previous four cases.  </p></li>
</ol>
</p>
</div>

</div>
<div><h3 name="sec_omin" id="sec_omin">3.2 Further Description of <i>OpenMath</i> Objects</h3>




  

<p>Informally, an <i>OpenMath</i> <span><i>object</i></span> can be
viewed as a tree and is also referred to as a term.  The objects at
the leaves of <i>OpenMath</i> trees are called <span><i>basic
objects</i></span>.  The basic objects supported by <i>OpenMath</i> are:
<dl>
<dt>Integer</dt><dd><p>Arbitrary Precision
integers.</p> </dd>
<dt>Float</dt><dd> <p><i>OpenMath</i> floats are
<span>ieee</span> 754 Double precision floating-point
numbers. Other types of floating point number may be encoded in <i>OpenMath</i>
by the use of suitable content dictionaries.</p>
  
</dd>

<dt>Character strings</dt><dd><p>are
  sequences of characters. These characters come from the Unicode
  standard <a href="#UNICODE">[14]</a>.</p>
  
</dd>
<dt>Bytearrays</dt><dd><p>are sequences of
bytes. There is no <span>"byte"</span> in <i>OpenMath</i> as an object of its
own. However, a single byte can of course be represented by a
bytearray of length 1.  The difference between strings and bytearrays
is the following: a character string is a sequence of bytes with a
fixed interpretation (as characters, Unicode texts may require several
bytes to code one character), whereas a bytearray is an uninterpreted
sequence of bytes with no intrinsic meaning.  Bytearrays could be used
inside <i>OpenMath</i> errors to provide information to, for example, a debugger;
they could also contain intermediate results of calculations, or
`handles' into computations or databases.</p>
</dd>

<dt>Symbols</dt><dd>
  
  
  <p>
 are uniquely defined by the Content Dictionary in which they occur
  and by a name.
The form of these definitions is explained in
  <a href="#cha_cd">Chapter 5</a>.  Each symbol has no more than one
  definition in a Content Dictionary. Many Content Dictionaries may
  define differently a symbol with the same name (e.g. the symbol
  <small><code>union</code></small> is defined as
  associative-commutative set theoretic union in a Content Dictionary
  <small><code>set1</code></small> but another Content Dictionary,
  <small><code>multiset1</code></small> might define a symbol
  <small><code>union</code></small> as the union of multi-sets).


  
</p>
  
 
  </dd>

<dt>Variables</dt><dd><p>are meant to
  denote parameters, variables or indeterminates (such as bound
  variables of function definitions, variables in summations and
  integrals, independent variables of derivatives).   
</p>
<p>
A variable may have one or more children which are themselves <i>OpenMath</i>
objects and are treated as scripts.  Thus it is possible to create a
variable with cardinality such as
<m:math><m:msub><m:mi>x</m:mi><m:mn>1</m:mn></m:msub></m:math>  or
<m:math><m:msub><m:mi>x</m:mi><m:mi>i</m:mi></m:msub></m:math>.
</p>
</dd>

</dl> </p>


<p>Currently there is one way of making a
derived <i>OpenMath</i> object.</p>

<dl>
<dt>Foreign</dt><dd><p>is used to import a
non-<i>OpenMath</i> object into an <i>OpenMath</i> attribution.  Examples of its use could
be to annotate a formula with a visual or aural rendering, an
animation etc.
</p>
</dd>

</dl>


<p>The four following constructs can be used to make compound
 <i>OpenMath</i> objects.</p>
<dl>
<dt>Application</dt><dd><p>constructs an
  <i>OpenMath</i> object from a sequence of one or more <i>OpenMath</i> objects. The first
  argument of application is referred to as <span>"head"</span> while
  the remaining objects are called <span>"arguments"</span>.  An <i>OpenMath</i>
  application object can be used to convey the mathematical notion of
  application of a function to a set of arguments.  For instance,
  suppose that the <i>OpenMath</i> symbol <m:math><m:mi>sin</m:mi></m:math>  is defined in
  a Content Dictionary for trigonometry, then <m:math><m:mi mathvariant="bold">application</m:mi><m:mo>(</m:mo><m:mi>sin</m:mi><m:mo>,</m:mo>
  <m:mi>x</m:mi> <m:mo>)</m:mo></m:math>  is the abstract <i>OpenMath</i> object
  corresponding to <m:math><m:mi>sin</m:mi> <m:mo>(</m:mo><m:mi>x</m:mi>
  <m:mo>)</m:mo></m:math>.  More generally, an <i>OpenMath</i> application object can
  be used as a constructor to convey a mathematical object built from
  other objects such as a polynomial constructed from a set of
  monomials.  Constructors build inhabitants of some symbolic type,
  for instance the type of rational numbers or the type of
  polynomials.  The rational number, usually denoted as
  <m:math><m:mn>1</m:mn><m:mo>/</m:mo><m:mn>2</m:mn></m:math>, is represented by the
  <i>OpenMath</i> application object <m:math><m:mi mathvariant="bold">application</m:mi><m:mo>(</m:mo><m:mi>Rational</m:mi><m:mo>,</m:mo>
  <m:mn>1</m:mn><m:mo>,</m:mo> <m:mn>2</m:mn><m:mo>)</m:mo></m:math>. The symbol
  <m:math><m:mi>Rational</m:mi></m:math>  must be defined, by a Content
  Dictionary, as a constructor symbol for the rational numbers.</p>
   
<div class="figure"><a name="fig_obj" id="fig_obj"/>
      <img src="lambda.png" alt="lambda.png"/>
<div>
  Figure 3.1 The <i>OpenMath</i> application and binding objects for
<m:math><m:mi>sin</m:mi> <m:mo>(</m:mo><m:mi>x</m:mi> <m:mo>)</m:mo></m:math>  and
<m:math><m:mi>&#955;</m:mi> <m:mi>x</m:mi><m:mo>.</m:mo><m:mi>x</m:mi> <m:mo>+</m:mo>
<m:mn>2</m:mn></m:math>  in tree-like notation.</div></div>

  
</dd>

<dt>Binding</dt><dd><p>objects are
  constructed from an <i>OpenMath</i> object, and from a sequence of zero or more
  variables followed by another <i>OpenMath</i> object.  The first <i>OpenMath</i> object is
  the <span>"binder"</span> object. Arguments 2 to
  <m:math><m:mi>n</m:mi><m:mo>-</m:mo><m:mn>1</m:mn></m:math>  are always variables to
  be bound in the <span>"body"</span> which is the
  <m:math><m:msup><m:mi>n</m:mi><m:mi>th</m:mi></m:msup></m:math>  argument object. It
  is allowed to have no bound variables, but the binder object and the
  body should be present. Binding can be used to express functions or
  logical statements.  The function <m:math><m:mi>&#955;</m:mi>
  <m:mi>x</m:mi><m:mo>.</m:mo><m:mi>x</m:mi> <m:mo>+</m:mo><m:mn>2</m:mn></m:math>, in which
  the variable <m:math><m:mi>x</m:mi></m:math>  is bound by
  <m:math><m:mi>&#955;</m:mi></m:math>, corresponds to a binding object having
  as binder the <i>OpenMath</i> symbol <m:math><m:mi>lambda</m:mi></m:math>: <m:math display="block"><m:mi mathvariant="bold">binding</m:mi><m:mo>(</m:mo><m:mi>lambda</m:mi><m:mo>,</m:mo>
  <m:mi>x</m:mi> <m:mo>,</m:mo> <m:mi mathvariant="bold">application</m:mi><m:mo>(</m:mo><m:mi>plus</m:mi><m:mo>,</m:mo>
  <m:mi>x</m:mi> <m:mo>,</m:mo>
  <m:mn>2</m:mn><m:mo>)</m:mo><m:mo>)</m:mo><m:mtext>.</m:mtext></m:math></p>
  
  
  


<p>Phrasebooks are allowed to use <m:math><m:mi>&#945;</m:mi></m:math> 
  conversion in order to avoid clashes of variable names. Suppose an
  object <m:math><m:mi>&#937;</m:mi></m:math>  contains an occurrence of the
  object <m:math><m:mi mathvariant="bold">binding</m:mi>
  <m:mo>(</m:mo><m:mi>B</m:mi> <m:mo>,</m:mo> <m:mi>v</m:mi> <m:mo>,</m:mo> <m:mi>C</m:mi>
  <m:mo>)</m:mo></m:math>.  This object <m:math><m:mi mathvariant="bold">binding</m:mi> <m:mo>(</m:mo><m:mi>B</m:mi> <m:mo>,</m:mo>
  <m:mi>v</m:mi> <m:mo>,</m:mo> <m:mi>C</m:mi> <m:mo>)</m:mo></m:math>  can be replaced
  in <m:math><m:mi>&#937;</m:mi></m:math>  by <m:math><m:mi mathvariant="bold">binding</m:mi> <m:mo>(</m:mo><m:mi>B</m:mi> <m:mo>,</m:mo>
  <m:mi>z</m:mi> <m:mo>,</m:mo> <m:mi>C'</m:mi><m:mo>)</m:mo></m:math>  where
  <m:math><m:mi>z</m:mi></m:math>  is a variable not occurring free in
  <m:math><m:mi>C</m:mi></m:math>  and <m:math><m:mi>C'</m:mi></m:math>  is obtained
  from <m:math><m:mi>C</m:mi></m:math>  by replacing each free (i.e., not bound
  by any intermediate <b>binding</b> construct) occurrence
  of <m:math><m:mi>v</m:mi></m:math>  by <m:math><m:mi>z</m:mi></m:math>.  This
  operation preserves the semantics of the object
  <m:math><m:mi>&#937;</m:mi></m:math>. In the above example, a phrasebook is
  thus allowed to transform the object to, e.g.  <m:math revisionflag="deleted" display="block"><m:mi mathvariant="bold">binding</m:mi>
  <m:mo>(</m:mo><m:mi>lambda</m:mi><m:mo>,</m:mo> <m:mi>v</m:mi> <m:mo>,</m:mo> <m:mi mathvariant="bold">binding</m:mi> <m:mo>(</m:mo><m:mi>lambda</m:mi><m:mo>,</m:mo>
  <m:mi>z</m:mi> <m:mo>,</m:mo><m:mi mathvariant="bold">application</m:mi>
  <m:mo>(</m:mo><m:mi>times</m:mi><m:mo>,</m:mo><m:mi>z</m:mi>
  <m:mo>,</m:mo><m:mi>z</m:mi><m:mo>)</m:mo><m:mo>)</m:mo><m:mo>)</m:mo><m:mtext>.</m:mtext></m:math>
  <m:math revisionflag="added" display="block"><m:mi mathvariant="bold">binding</m:mi><m:mo>(</m:mo><m:mi>lambda</m:mi><m:mo>,</m:mo>
  <m:mi>z</m:mi> <m:mo>,</m:mo> <m:mi mathvariant="bold">application</m:mi><m:mo>(</m:mo><m:mi>plus</m:mi><m:mo>,</m:mo>
  <m:mi>z</m:mi> <m:mo>,</m:mo>
  <m:mn>2</m:mn><m:mo>)</m:mo><m:mo>)</m:mo><m:mtext>.</m:mtext></m:math>
</p>
<p>Repeated occurrences of the same variable in a binding operator
  are allowed. An <i>OpenMath</i> application should treat a binding with
  multiple occurrences of the same variable as equivalent to the
  binding in which all but the last occurrence of each variable is
  replaced by a new variable which does not occur free in the body of
  the binding.  <m:math display="block"><m:mi mathvariant="bold">binding</m:mi> <m:mo>(</m:mo><m:mi>lambda</m:mi><m:mo>,</m:mo>
  <m:mi>v</m:mi> <m:mo>,</m:mo> <m:mi>v</m:mi> <m:mo>,</m:mo><m:mi mathvariant="bold">application</m:mi>
  <m:mo>(</m:mo><m:mi>times</m:mi><m:mo>,</m:mo><m:mi>v</m:mi>
  <m:mo>,</m:mo><m:mi>v</m:mi><m:mo>)</m:mo> <m:mo>)</m:mo></m:math> is semantically
  equivalent to: <m:math display="block"><m:mi mathvariant="bold">binding</m:mi> <m:mo>(</m:mo><m:mi>lambda</m:mi> <m:mo>,</m:mo>
  <m:msup><m:mi>v</m:mi><m:mo>'</m:mo></m:msup> <m:mo>,</m:mo> <m:mi>v</m:mi>
  <m:mo>,</m:mo><m:mi mathvariant="bold">application</m:mi>
  <m:mo>(</m:mo><m:mi>times</m:mi><m:mo>,</m:mo><m:mi>v</m:mi>
  <m:mo>,</m:mo><m:mi>v</m:mi><m:mo>)</m:mo> <m:mo>)</m:mo></m:math> so that the
  resulting function is actually a constant in its first argument
  (<m:math><m:msup><m:mi>v</m:mi><m:mo>'</m:mo></m:msup></m:math>  does not occur free
  in the body <m:math><m:mi mathvariant="bold">application</m:mi>
  <m:mo>(</m:mo><m:mi>times</m:mi><m:mo>,</m:mo><m:mi>v</m:mi>
  <m:mo>,</m:mo><m:mi>v</m:mi><m:mo>)</m:mo> <m:mo>)</m:mo></m:math>).</p>

  
</dd>

<dt>Attribution</dt><dd><p>decorates an
  object with a sequence of one or more pairs made up of an <i>OpenMath</i>
  symbol, the <span>"attribute"</span>, and an associated  object, the <span>"value of the
  attribute"</span>.  The value of the attribute can be an <span><i>OpenMath</i></span> attribution object itself. As an
  example of this, consider the <i>OpenMath</i> objects representing groups,
  automorphism groups, and group dimensions. It is then possible to
  attribute an <i>OpenMath</i> object representing a group by its automorphism
  group, itself attributed by its dimension.</p>

<p>
<i>OpenMath</i> objects can be attributed with <i>OpenMath</i> foreign objects, which are
containers for non-<i>OpenMath</i> structures.  For example a mathematical
expression could be attributed with its spoken or visual rendering.
</p>

<p>Composition of attributions, as in
  <m:math display="block">
<m:mi mathvariant="bold">attribution</m:mi><m:mo>(</m:mo><m:mi mathvariant="bold">attribution</m:mi><m:mo>(</m:mo><m:mi>A</m:mi><m:mo>,</m:mo>
  <m:msub><m:mi>S</m:mi><m:mn>1</m:mn></m:msub> <m:mspace width=".3em"/>
  <m:msub><m:mi>A</m:mi><m:mn>1</m:mn></m:msub><m:mo>,</m:mo><m:mi>&#8230;</m:mi><m:mo>,</m:mo><m:msub><m:mi>S</m:mi><m:mi>h</m:mi></m:msub>
  <m:mspace width=".3em"/>
  <m:msub><m:mi>A</m:mi><m:mi>h</m:mi></m:msub><m:mo>)</m:mo><m:mo>,</m:mo>
  <m:msub><m:mi>S</m:mi><m:mrow><m:mi>h</m:mi><m:mo>+</m:mo><m:mn>1</m:mn></m:mrow></m:msub>
  <m:mspace width=".3em"/>
  <m:msub><m:mi>A</m:mi><m:mrow><m:mi>h</m:mi><m:mo>+</m:mo><m:mn>1</m:mn></m:mrow></m:msub><m:mo>,</m:mo>
  <m:mi>&#8230;</m:mi><m:mo>,</m:mo> <m:msub><m:mi>S</m:mi><m:mi>n</m:mi></m:msub> <m:mspace width=".3em"/> <m:msub><m:mi>A</m:mi><m:mi>n</m:mi></m:msub><m:mo>)</m:mo></m:math> is
  semantically equivalent to a single attribution, that is <m:math display="block"><m:mi mathvariant="bold">attribution</m:mi><m:mo>(</m:mo><m:mi>A</m:mi><m:mo>,</m:mo>
  <m:msub><m:mi>S</m:mi><m:mn>1</m:mn></m:msub> <m:mspace width=".3em"/>
  <m:msub><m:mi>A</m:mi><m:mn>1</m:mn></m:msub><m:mo>,</m:mo>
  <m:mi>&#8230;</m:mi><m:mo>,</m:mo> <m:msub><m:mi>S</m:mi><m:mi>h</m:mi></m:msub> <m:mspace width=".3em"/> <m:msub><m:mi>A</m:mi><m:mi>h</m:mi></m:msub><m:mo>,</m:mo>
  <m:msub><m:mi>S</m:mi><m:mrow><m:mi>h</m:mi><m:mo>+</m:mo><m:mn>1</m:mn></m:mrow></m:msub>
  <m:mspace width=".3em"/>
  <m:msub><m:mi>A</m:mi><m:mrow><m:mi>h</m:mi><m:mo>+</m:mo><m:mn>1</m:mn></m:mrow></m:msub><m:mo>,</m:mo>
  <m:mi>&#8230;</m:mi><m:mo>,</m:mo> <m:msub><m:mi>S</m:mi><m:mi>n</m:mi></m:msub> <m:mspace width=".3em"/>
  <m:msub><m:mi>A</m:mi><m:mi>n</m:mi></m:msub><m:mo>)</m:mo><m:mtext>.</m:mtext></m:math>
  The operation that produces an object with a single layer of
  attribution is called <i>flattening</i>.</p>

<p>Multiple attributes with the same name are allowed.  While the
  order of the given attributes does not imply any notion of priority,
  potentially it could be significant. For instance, consider the case
  in which <m:math><m:msub><m:mi>S</m:mi><m:mi>h</m:mi></m:msub> <m:mo>=</m:mo>
  <m:msub><m:mi>S</m:mi><m:mi>n</m:mi></m:msub></m:math>  (<m:math><m:mi>h</m:mi>
  <m:mo>&lt;</m:mo> <m:mi>n</m:mi></m:math>) in the example above. Then, the
  object is to be interpreted as if the value
  <m:math><m:msub><m:mi>A</m:mi><m:mi>n</m:mi></m:msub></m:math>  overwrites the value
  <m:math><m:msub><m:mi>A</m:mi><m:mi>h</m:mi></m:msub></m:math>.  (<i>OpenMath</i> however does
  not mandate that an application preserves the attributes or their
  order.)</p>

<p>Attribution acts as either adornment
  annotation or as semantical annotation. When the key has rôle
  <i> attribution</i>, then replacement of the
  attributed object by the object itself is not harmful and preserves
  the semantics. When the key has rôle
  <i>semantic-attribution</i> then the attributed
  object is modified by the attribution and cannot be viewed as
  semantically equivalent to the stripped object. If the attribute
  lacks the rôle specification then attribution is acting as adornment
  annotation.
  </p>


<p>Objects can be decorated in a multitude of
ways. In <a href="#OM_D131b">[3]</a>, typing of <i>OpenMath</i> objects is
expressed by using an attribution. The object <m:math><m:mi mathvariant="bold">attribution</m:mi><m:mo>(</m:mo><m:mi>A</m:mi><m:mo>,</m:mo>
<m:mi>type</m:mi> <m:mspace width=".3em"/> <m:mi>t</m:mi> <m:mo>)</m:mo></m:math> 
represents the judgment stating that object <m:math><m:mi>A</m:mi></m:math> 
has type <m:math><m:mi>t</m:mi></m:math>. Note that both
<m:math><m:mi>A</m:mi></m:math>  and <m:math><m:mi>t</m:mi></m:math>  are <i>OpenMath</i>
objects.</p>




            
  
  
</dd>

<dt>Error</dt><dd><p>is made up of an <i>OpenMath</i>
  symbol and a sequence of zero or more <i>OpenMath</i> objects. This object has
  no direct mathematical meaning.  Errors occur as the result of some
  treatment on an <i>OpenMath</i> object and are thus of real interest only when
  some sort of communication is taking place. Errors may occur inside
  other objects and also inside other errors.  Error objects might
  consist only of a symbol as in the object: <m:math><m:mi mathvariant="bold">error</m:mi> <m:mo>(</m:mo><m:mi>S</m:mi>
  <m:mo>)</m:mo></m:math>.</p> 
</dd>

</dl> 
</div>

<div><h3 name="sec_names" id="sec_names">3.3 Names</h3>

<p>

The names of symbols, variables and content dictionaries must conform to the
following rules, which are designed to be compatible with standards such as
Unicode and XML.  These standards group individual characters into letters,
digits, combining characters and extenders.  Informally, these are defined as
follows:

<dl>

<dt>Letters</dt><dd><p> are elements of an
alphabet such as latin, cyrillic, kanji etc.</p></dd>

<dt>Digits</dt><dd><p> are atomic numbers,
from which compound numbers can be constructed (for example `1' is a
digit but `11' is not).</p></dd>

<dt>Combining Characters</dt><dd><p> are
used to combine several characters to produce a new one, for example
an accented character.
</p></dd>

<dt>Extenders</dt><dd><p> are characters
which are neither letters nor combining characters but modify the
appearance of other characters in some way.
</p></dd>

</dl>
Formally, we use the precise definitions given in the Unicode
standard <a href="#UNICODE">[14]</a>.
</p>

<p>

Then a legal <i>OpenMath</i> name is defined by the following grammar:
<blockquote>
<table>
<tr>
<td>Name </td>
<td> <m:math><m:mo>&#8594;</m:mo></m:math>  </td>
<td> (Letter | '_') (Char)*
</td>
</tr>
<tr>
<td>Char</td>
<td> <m:math><m:mo>&#8594;</m:mo></m:math>  </td>
<td> Letter | Digit | '.' | '-' | '_' | CombiningChar | Extender
</td>
</tr>
</table>
</blockquote>

</p>

<p><b>CD Base</b>

<p>A cdbase must conform to the grammar for URIs described in
<a href="#IETF2396">[9]</a>.  Note that if non-ASCII characters are
used in a CD or symbol name then when a URI for that symbol is
constructed it will be necessary to map the non-ASCII characters to a
sequence of octets.  The precise mechanism for doing this depends on
the URI scheme.</p></p>

<p><b>Note on content dictionary names</b>
<p>
It is a common convention to store a Content Dictionary in a file of
the same name, which can cause difficulties on many file systems.  If
this convention is to be followed then <i>OpenMath</i>
<i>recommends</i> that the name be restricted to the
subset of the above grammar which is a legal POSIX
<a href="#POSIX">[7]</a> filename, namely:
<blockquote>
<table>
<tr>
<td>Name </td>
<td> <m:math><m:mo>&#8594;</m:mo></m:math>  </td>
<td> (PosixLetter | '_') (Char)*
</td>
</tr>
<tr>
<td>Char</td>
<td> <m:math><m:mo>&#8594;</m:mo></m:math>  </td>
<td> PosixLetter | Digit | '.' | '-' | '_' 
</td>
</tr>
<tr>
<td>PosixLetter</td>
<td> <m:math><m:mo>&#8594;</m:mo></m:math>  </td>
<td> 
'a' | 'b' | ... | 'z' | 'A' | 'B' | ... | 'Z'
</td>
</tr>
</table>
</blockquote>
</p>
</p>

</div>

<div><h3 name="sec_summary" id="sec_summary">3.4 Summary</h3>


<ul>
<li><p><i>OpenMath</i> supports basic objects like integers, symbols,
  floating-point numbers, character strings, bytearrays, and
  variables.</p></li>
<li><p><i>OpenMath</i> compound objects are of four kinds:
  applications, bindings, errors, and attributions.</p></li>
<li><p><i>OpenMath</i> objects may be attributed
with non-<i>OpenMath</i> objects via the use of foreign <i>OpenMath</i> objects.
  </p></li>
<li><p><i>OpenMath</i> objects have the expressive power to cover all
  areas of computational mathematics.</p></li>
</ul>

 <p>Observe that an <i>OpenMath</i>
application object is viewed as a <span>"tree"</span> by software
applications that do not understand Content Dictionaries, whereas a
Phrasebook that understands the semantics of the symbols, as defined
in the Content Dictionaries, should interpret the object as functional
application, constructor, or binding accordingly. Thus, for example,
for some applications, the <i>OpenMath</i> object corresponding to
<m:math><m:mn>2</m:mn><m:mo>+</m:mo><m:mn>5</m:mn></m:math>  may result in a command
that writes <m:math><m:mn>7</m:mn></m:math>.</p>
</div>


<h2 name="cha_enco" id="cha_enco">
  Chapter 4<br/><i>OpenMath</i> Encodings</h2>



<p>In this chapter, two encodings are defined that map between <i>OpenMath</i>
objects and byte streams.  These byte streams constitute a low level
representation that can be easily exchanged between processes (via
almost any communication method) or stored and retrieved from
files.</p>




<p>The first encoding is a character-based
encoding in <span>xml</span> format.  In previous versions of the <i>OpenMath</i> Standard
this encoding was a restricted subset of the full legal <span>xml</span> syntax.
In this version, however, we have removed all these restrictions so that
the earlier encoding is a strict subset of the existing one.  The
<span>xml</span> encoding can be used, for example, to send <i>OpenMath</i> objects via
e-mail, cut-and-paste, etc. and to embed <i>OpenMath</i> objects in <span>xml</span>
documents or to have <i>OpenMath</i> objects processed by <span>xml</span>-aware
applications.</p>

<p>The second encoding is a binary encoding that is meant to be
used when the compactness of the encoding is important (interprocess
communications over a network is an example).</p>

<p>Note that these two encodings are sufficiently different for
autodetection to be effective: an application reading the bytes can
very easily determine which encoding is used.</p>

<div><h3 name="sec_xml" id="sec_xml">4.1 The <span>xml</span> Encoding</h3>


<p>This encoding has been designed with two main goals in mind:
<ol>
<li><p>to provide an encoding that uses common character sets
  (so that it can be easily included in most documents and transport
  protocols) and that is both readable and writable by a human.</p></li>
<li><p>to provide an encoding that can be included (embedded) in
  <span>xml</span> documents or processed by <span>xml</span>-aware applications.</p></li>
</ol> 
</p>

<div><h4 name="ssec_xml" id="ssec_xml">4.1.1 A <span>Schema</span> for the <span>xml</span> Encoding</h4>





<p>The <span>xml</span> encoding of an <i>OpenMath</i> object is
defined by the Relax NG schema <a href="#RELAX">[11]</a> given below.
Relax NG has a number of advantages over the older XSD Schema format
<a href="#XSD">[15]</a>, in particular it allows for tighter control
of attributes and has a modular, extensible structure.  Although we
have made the <span>xml</span> form, which is given  in <a href="#app_openmath.rng">Appendix B</a> normative, it is generated from the
 compact syntax given below.  It is also very easy to restrict the schema to allow
a limited set of <i>OpenMath</i> symbols as described in <a href="#app_relaxrestricted">Appendix C</a>.  </p>

<p> Standard tools exist for generating a DTD
or an XSD schema from a Relax NG Schema.  Examples of such documents
are given in <a href="#app_dtd">Appendix E</a> and <a href="#app_xsd">Appendix D</a>
respectively.</p>

<div class="literal"><pre>
<span style="color:brown;"># RELAX NG Schema for OpenMath 2</span>


<span style="font-weight:bold;">default</span> <span style="font-weight:bold;">namespace</span> <a name="rncnamespaceom" style="color:blue;">om</a> = "http://www.openmath.org/OpenMath"
<span style="font-weight:bold;">namespace</span> <a name="rncnamespacexlink" style="color:blue;">xlink</a> = "http://www.w3.org/1999/xlink"

<span style="color:brown;"># OM2: allow OMR</span>
<a name="rncomel" style="color:blue;">omel</a> = 
  <a href="#rncOMS">OMS</a> | <a href="#rncOMV">OMV</a> | <a href="#rncOMI">OMI</a> | <a href="#rncOMB">OMB</a> | <a href="#rncOMSTR">OMSTR</a> | <a href="#rncOMF">OMF</a> | <a href="#rncOMA">OMA</a> | <a href="#rncOMBIND">OMBIND</a> | <a href="#rncOME">OME</a> | <a href="#rncOMATTR">OMATTR</a> |<a href="#rncOMR">OMR</a>

<span style="color:brown;"># things which can be variables</span>
<a name="rncomvar" style="color:blue;">omvar</a> = <a href="#rncOMV">OMV</a> | <a href="#rncattvar">attvar</a>

<a name="rncattvar" style="color:blue;">attvar</a> = <span style="font-weight:bold;">element</span> OMATTR { <a href="#rnccommon.attributes">common.attributes</a>,(<a href="#rncOMATP">OMATP</a> , (<a href="#rncOMV">OMV</a> | <a href="#rncattvar">attvar</a>))}

<span style="color:brown;">#OM2: common attributes</span>
<a name="rnccdbase" style="color:blue;">cdbase</a> = <span style="font-weight:bold;">attribute</span> cdbase { <span style="font-weight:bold;">xsd:anyURI</span>}?
<a name="rnccommon.attributes" style="color:blue;">common.attributes</a> = (<span style="font-weight:bold;">attribute</span> id { <span style="font-weight:bold;">xsd:ID</span> })?
<a name="rnccompound.attributes" style="color:blue;">compound.attributes</a> = <a href="#rnccommon.attributes">common.attributes</a>,<a href="#rnccdbase">cdbase</a>

<span style="color:brown;"># symbol</span>
<a name="rncOMS" style="color:blue;">OMS</a> = <span style="font-weight:bold;">element</span> OMS { <a href="#rnccommon.attributes">common.attributes</a>, <a href="#rncattlist.OMS">attlist.OMS</a>}
<a name="rncattlist.OMS" style="color:blue;">attlist.OMS</a> =
  <span style="font-weight:bold;">attribute</span> name { <span style="font-weight:bold;">xsd:NCName</span>},
  <span style="font-weight:bold;">attribute</span> cd { <span style="font-weight:bold;">xsd:NCName</span>},
  <a href="#rnccdbase">cdbase</a>

<span style="color:brown;"># variable</span>
<a name="rncOMV" style="color:blue;">OMV</a> = <span style="font-weight:bold;">element</span> OMV { <a href="#rnccommon.attributes">common.attributes</a>, <a href="#rncattlist.OMV">attlist.OMV</a>,<a href="#rncomel">omel</a>?}
<a name="rncattlist.OMV" style="color:blue;">attlist.OMV</a> = <span style="font-weight:bold;">attribute</span> name { <span style="font-weight:bold;">xsd:NCName</span>}

<span style="color:brown;"># integer</span>
<a name="rncOMI" style="color:blue;">OMI</a> = <span style="font-weight:bold;">element</span> OMI { <a href="#rnccommon.attributes">common.attributes</a>,
                    <span style="font-weight:bold;">xsd:string</span> {<span style="font-weight:bold;">pattern</span> = "\s*(-\s?)?[0-9]+(\s[0-9]+)*\s*"}}
<span style="color:brown;"># byte array</span>
<a name="rncOMB" style="color:blue;">OMB</a> = <span style="font-weight:bold;">element</span> OMB { <a href="#rnccommon.attributes">common.attributes</a>, <span style="font-weight:bold;">xsd:base64Binary</span> }

<span style="color:brown;"># string</span>
<a name="rncOMSTR" style="color:blue;">OMSTR</a> = <span style="font-weight:bold;">element</span> OMSTR { <a href="#rnccommon.attributes">common.attributes</a>, <span style="font-weight:bold;">text</span> }

<span style="color:brown;"># floating point</span>
<a name="rncOMF" style="color:blue;">OMF</a> = <span style="font-weight:bold;">element</span> OMF { <a href="#rnccommon.attributes">common.attributes</a>, <a href="#rncattlist.OMF">attlist.OMF</a>}
<a name="rncattlist.OMF" style="color:blue;">attlist.OMF</a> =
  <span style="font-weight:bold;">attribute</span> dec { <span style="font-weight:bold;">xsd:string</span> 
           {<span style="font-weight:bold;">pattern</span> = "(-?)([0-9]+)?(\.[0-9]+)?(e([+\-]?)[0-9]+)?"}}|
  <span style="font-weight:bold;">attribute</span> hex { <span style="font-weight:bold;">xsd:string</span> {<span style="font-weight:bold;">pattern</span> = "[0-9A-F]+"}}

<span style="color:brown;"># apply constructor</span>
<a name="rncOMA" style="color:blue;">OMA</a> = <span style="font-weight:bold;">element</span> OMA { <a href="#rnccompound.attributes">compound.attributes</a>, <a href="#rncomel">omel</a>+ }
<span style="color:brown;"># binding constructor and variable</span>
<a name="rncOMBIND" style="color:blue;">OMBIND</a> = <span style="font-weight:bold;">element</span> OMBIND { <a href="#rnccompound.attributes">compound.attributes</a>, <a href="#rncomel">omel</a>, <a href="#rncOMBVAR">OMBVAR</a>, <a href="#rncomel">omel</a> }
<a name="rncOMBVAR" style="color:blue;">OMBVAR</a> = <span style="font-weight:bold;">element</span> OMBVAR { <a href="#rnccommon.attributes">common.attributes</a>, <a href="#rncomvar">omvar</a>+ }

<span style="color:brown;"># error</span>
<a name="rncOME" style="color:blue;">OME</a> = <span style="font-weight:bold;">element</span> OME { <a href="#rnccommon.attributes">common.attributes</a>, <a href="#rncOMS">OMS</a>, <a href="#rncomel*">omel*</a> }

<span style="color:brown;"># attribution constructor and attribute pair constructor</span>
<a name="rncOMATTR" style="color:blue;">OMATTR</a> = <span style="font-weight:bold;">element</span> OMATTR { <a href="#rnccompound.attributes">compound.attributes</a>, <a href="#rncOMATP">OMATP</a>, <a href="#rncomel">omel</a> }

<span style="color:brown;"># OM2: allow OMFOREIGN </span>
<a name="rncOMATP" style="color:blue;">OMATP</a> = <span style="font-weight:bold;">element</span> OMATP { <a href="#rnccompound.attributes">compound.attributes</a>, (<a href="#rncOMS">OMS</a>, (<a href="#rncomel">omel</a> | <a href="#rncOMFOREIGN">OMFOREIGN</a>) )+ }

<span style="color:brown;"># OM2: OMFOREIGN </span>
<a name="rncOMFOREIGN" style="color:blue;">OMFOREIGN</a> =  <span style="font-weight:bold;">element</span> OMFOREIGN { <a href="#rnccompound.attributes">compound.attributes</a>, (<a href="#rncomel">omel</a>|<a href="#rncnotom">notom</a>)* }

<span style="color:brown;"># Any elements not in the om namespace (valid om is allowed as a descendant)</span>
<a name="rncnotom" style="color:blue;">notom</a> =
  (<span style="font-weight:bold;">element</span> * - <a href="#rncnamespaceom">om:</a>* {<span style="font-weight:bold;">attribute</span> * { <span style="font-weight:bold;">text</span> }*,(<a href="#rncomel">omel</a>|<a href="#rncnotom">notom</a>)*}
   | <span style="font-weight:bold;">text</span>)

<span style="color:brown;"># OM object constructor</span>
<a name="rncOMOBJ" style="color:blue;">OMOBJ</a> = <span style="font-weight:bold;">element</span> OMOBJ { <a href="#rnccompound.attributes">compound.attributes</a>, <a href="#rncomel">omel</a> }
 <a name="rncattlist.OMOBJ" style="color:blue;">attlist.OMOBJ</a> = <span style="font-weight:bold;">attribute</span> version { "1.0" | "1.2" | "2.0" }


<span style="color:brown;"># OM2: OMR</span>
<a name="rncOMR" style="color:blue;">OMR</a> = <span style="font-weight:bold;">element</span> OMR { <a href="#rnccommon.attributes">common.attributes</a>, <a href="#rncattlist.OMR">attlist.OMR</a> }
<a name="rncattlist.OMR" style="color:blue;">attlist.OMR</a> = 
        <span style="font-weight:bold;">attribute</span> <a href="#rncnamespacexlink">xlink:</a>href { <span style="font-weight:bold;">text</span> },
        <span style="font-weight:bold;">attribute</span> <a href="#rncnamespacexlink">xlink:</a>type {"simple"},
        <span style="font-weight:bold;">attribute</span> <a href="#rncnamespacexlink">xlink:</a>show {"embed"}

<a name="rncstart" style="color:blue;">start</a> = <a href="#rncOMOBJ">OMOBJ</a>

</pre></div>
<p/>








 











</div>

<div><h4 name="sec_xml-desc" id="sec_xml-desc">4.1.2 <span>Informal</span> description of
the <span><span>xml</span> Encoding</span></h4>


<p>An encoded <i>OpenMath</i> object is placed inside an <small><code>OMOBJ</code></small> element.  This 
element can contain the elements (and integers) described above.
<span> It can take an optional
<small><code>version</code></small> <span>xml</span>-attribute which indicates to which
version of the <i>OpenMath</i> standard it conforms.  This would allow an older
<i>OpenMath</i> application which, for example, could not parse the full <span>xml</span>
syntax, to accept objects with version "1" or "1.1" but reject objects
with version "2".
</span></p>

<p>We briefly discuss the <span>xml</span> encoding for each type of <i>OpenMath</i> object
starting from the basic objects.</p>

<dl>
<dt>Integers</dt>
<dd>
 <p>are encoded using the
<small><code>OMI</code></small> element around the sequence of their
digits in base 10 or 16 (most significant digit first).  White space
may be inserted between the characters of the integer representation,
this will be ignored.  After ignoring white space, integers written in
base 10 match the regular expression
<small><code>-?[0-9]+</code></small>.  Integers written in base 16 match
<small><code>-?x[0-9A-F]+</code></small>.  The integer 10 can be thus
encoded as <small><code>&lt;OMI&gt; 10 &lt;/OMI&gt; </code></small> or as
<small><code>&lt;OMI&gt; xA &lt;/OMI&gt; </code></small> but neither
<small><code>&lt;OMI&gt; +10 &lt;/OMI&gt;</code></small> nor
<small><code>&lt;OMI&gt; +xA &lt;/OMI&gt;</code></small> can be used.</p>

<p>The negative integer <m:math><m:mn>-120</m:mn></m:math>  can be encoded
       as either as decimal <small><code>&lt;OMI&gt; -120
       &lt;/OMI&gt;</code></small> or as hexadecimal <small><code>&lt;OMI&gt;
       -x78 &lt;/OMI&gt;</code></small>.</p>

  
</dd>

<dt>Symbols</dt><dd><p>are encoded using
  the <small><code>OMS</code></small> element. This element has
  
  <span>three</span>
  <span>xml</span>-attributes <small><code>cd</code></small>,
  <small><code>name</code></small><span>,  and
    <small><code>cdbase</code></small></span>. The value of
  <small><code>cd</code></small> is the name of the Content Dictionary in
  which the symbol is defined and the value of
  <small><code>name</code></small> is the name of the symbol.
  <span>The optional <small><code>cdbase</code></small>
    attribute is a URI that can be used to disambiguate between two  content
    dictionaries with the same name. The
  <small><code>cdbase</code></small> attribute may be used on any ancester
  element of the current <small><code>OMS</code></small>, any <small><code>OMS</code></small> elements without an
  explict  <small><code>cdbase</code></small> attribute which is a
  descendent of such an element is taken to
  encode an OpenMath symbol with this CD base.</span>
 For
  example:

<blockquote><p><small><code>&lt;OMS
 cdbase="http://www.openmath.org/cd" cd="transc1" name="sin"/&gt;</code></small></p>
</blockquote>
  is the encoding of the symbol named <small><code>sin</code></small> in
  the Content Dictionary named <small><code>transc1</code></small>,
<span>which is part of the collection
maintained by the <i>OpenMath</i> Society</span>.</p>

<p>The three attributes of the
  <small><code>OMS</code></small> can be used to build a URI reference for the symbol,
for use in contexts where URI-based referencing mechanisms are used. This
canonical URI reference is constructed as follows:</p>
<blockquote>
  <p><small><code>URI = cdbase-value + '/' + cd-value + '#' + name-value</code></small></p>
</blockquote>

<p>For example</p>
<blockquote>
  <div class="literal"><pre>&lt;OMS name="plus" cd="arith1" cdbase="http://www.openmath.org/cd"/&gt;</pre></div>
</blockquote>
<p>
  gives the URI <small><code>"http://www.openmath.org/cd/arith1#plus"</code></small>
  This would allow us to refer uniquely to an openmath symbol from a
MathML document <a href="#MathML_2000">[18]</a>.</p>
<blockquote>
  <div class="literal"><pre>
&lt;mathml:csymbol xmlns:mathml="http://www.w3.org/1998/Math/MathML/"
                definitionURL="http://www.openmath.org/cd/arith1#plus"&gt;
  Z
&lt;/csymbol&gt;
  </pre></div>
</blockquote>
<p>
Note that the role attribute described in <a href="#sec_roles">Section 3.1.4</a> is contained in the Content Dictionary and is not
part of the encoding of a symbol, also the <small><code>cdbase</code></small> attribute need not
be explict on each <small><code>OMS</code></small> as it is inherited
from any ancestor element.</p>
</dd>

<dt>Variables</dt><dd><p>are encoded using
  the <small><code>OMV</code></small> element, with only one
  <span>xml</span>-attribute, <small><code>name</code></small>, whose value is the
  variable name.   For instance, the encoding of the object
  representing the variable <m:math><m:mi>x</m:mi></m:math>  is:
  <small><code>&lt;OMV name="x"/&gt;</code></small></p>

<p>
For an enumerated variable the index or indices of the variable are
encoded as a child.  So for example the encoding
   of the object
  representing the variable
<m:math><m:msub><m:mi>x</m:mi><m:mrow><m:mi>i</m:mi><m:mo>+</m:mo><m:mn>1</m:mn></m:mrow></m:msub></m:math>  is:
<div class="literal"><pre>&lt;OMV name="x"&gt;  
  &lt;OMA&gt;
    &lt;OMS cdbase="http://www.openmath.org/cd" cd="arith1" name="plus"/&gt; 
    &lt;OMV name="i"/&gt;  
    &lt;OMI&gt;1&lt;/OMI&gt;
  &lt;/OMA&gt;
&lt;/OMV&gt;</pre></div>
</p>

  
</dd>

<dt>Floating-point numbers</dt><dd><p>are
  encoded using the <small><code>OMF</code></small> element that has
  either the <span>xml</span>-attribute <small><code>dec</code></small> or the
  <span>xml</span>-attribute <small><code>hex</code></small>. The two
  <span>xml</span>-attributes cannot be present simultaneously. The value of
  <small><code>dec</code></small> is the floating-point number expressed
  in base 10, using the common syntax:</p>
  
  <blockquote><p>
  <small><code>(-?)([0-9]+)?("."[0-9]+)?(e(-?)[0-9]+)?</code></small>.
  </p></blockquote>
  
  <p>The value of <small><code>hex</code></small> is the digits of the floating-point number
  expressed in base 16, with digits <small><code>0</code></small>-<small><code>9</code></small>, <small><code>A</code></small>-<small><code>F</code></small>
  (mantissa, exponent, and sign from lowest to highest bits) using a
  least significant byte ordering.  For example, <small><code>&lt;OMF
    dec="1.0e-10"/&gt;</code></small> is a valid floating-point number.</p>
  

</dd>

<dt>Character strings</dt><dd><p>are encoded using the <small><code>OMSTR</code></small> element.
  Its content is  a Unicode text . Note that as always in <span>xml</span> the
  characters <small><code>&lt;</code></small> and <small><code>&amp;</code></small>  need to be represented by the
  entity references <small><code>&amp;lt;</code></small> and
<small><code>&amp;amp;</code></small> respectively.</p>
  
</dd>

<dt>Bytearrays</dt><dd><p>are encoded using the <small><code>OMB</code></small> element. Its content
  is a sequence of characters that is a base64 encoding of the data.
  The base64 encoding is defined in <span>rfc</span> 1521 <a href="#rfc1521">[2]</a>.
  Basically, it represents an arbitrary sequence of octets using 64
  <span>"digits"</span> (<small><code>A</code></small> through <small><code>Z</code></small>, <small><code>a</code></small> through <small><code>z</code></small>, <small><code>0</code></small> through <small><code>9</code></small>, <small><code>+</code></small> and /, in order of increasing
  value). Three octets are represented as four digits (the <small><code>=</code></small>
  character for padding to the right at the end of the data). All line
  breaks and carriage return, space, form feed and horizontal
  tabulation characters are ignored. The reader is refered to
  <a href="#rfc1521">[2]</a> for more detailed information.</p>

</dd>

</dl>
 
<p>In detail the encoding of an <i>OpenMath</i> object is described below.</p>

<dl>
<dt>Applications</dt><dd><p>are encoded using the <small><code>OMA</code></small> element. The
  application whose head is the <i>OpenMath</i> object <m:math><m:msub><m:mi>e</m:mi><m:mn>0</m:mn></m:msub></m:math>  and whose arguments
  are the <i>OpenMath</i> objects <m:math><m:msub><m:mi>e</m:mi><m:mn>1</m:mn></m:msub></m:math>, <span>&#8230;</span>, <m:math><m:msub><m:mi>e</m:mi><m:mi>n</m:mi></m:msub></m:math>  is encoded as <small><code>&lt;OMA&gt;</code></small>
  <m:math><m:msub><m:mi>C</m:mi><m:mn>0</m:mn></m:msub></m:math>  <m:math><m:msub><m:mi>C</m:mi><m:mn>1</m:mn></m:msub></m:math><span>&#8230;</span> <m:math><m:msub><m:mi>C</m:mi><m:mi>n</m:mi></m:msub></m:math>  <small><code>&lt;/OMA&gt;</code></small> where <m:math><m:msub><m:mi>C</m:mi><m:mi>i</m:mi></m:msub></m:math>  is the encoding of
  <m:math><m:msub><m:mi>e</m:mi><m:mi>i</m:mi></m:msub></m:math>.</p>

<p>For example, <m:math><m:mi mathvariant="bold">application</m:mi><m:mo>(</m:mo><m:mi>sin</m:mi><m:mo>,</m:mo><m:mi>x</m:mi> <m:mo>)</m:mo></m:math>  is encoded as:
<div class="literal"><pre>&lt;OMA&gt;  
  &lt;OMS cdbase="http://www.openmath.org/cd" cd="transc1" name="sin"/&gt; 
  &lt;OMV name="x"/&gt;  
&lt;/OMA&gt;</pre></div>
  provided that the symbol <small><code>sin</code></small> is defined to be a function
  symbol in a Content Dictionary named <small><code>transc1</code></small>.</p>

  
</dd>

<dt>Binding</dt><dd><p>is encoded using the <small><code>OMBIND</code></small> element.  The binding
  by the <i>OpenMath</i> object <m:math><m:mi>b</m:mi></m:math>  of the <i>OpenMath</i> variables <m:math><m:msub><m:mi>x</m:mi><m:mn>1</m:mn></m:msub></m:math>, <m:math><m:msub><m:mi>x</m:mi><m:mn>2</m:mn></m:msub></m:math>,
  <m:math><m:mi>&#8230;</m:mi></m:math>, <m:math><m:msub><m:mi>x</m:mi><m:mi>n</m:mi></m:msub></m:math>  in the object <m:math><m:mi>c</m:mi></m:math>  is encoded as <small><code>&lt;OMBIND&gt;</code></small> <m:math><m:mi>B</m:mi></m:math> 
  <small><code>&lt;OMBVAR&gt;</code></small> <m:math><m:msub><m:mi>X</m:mi><m:mn>1</m:mn></m:msub></m:math>  <m:math><m:mi>&#8230;</m:mi></m:math>  <m:math><m:msub><m:mi>X</m:mi><m:mi>n</m:mi></m:msub></m:math>  <small><code>&lt;/OMBVAR&gt;</code></small> <m:math><m:mi>C</m:mi></m:math>  <small><code>&lt;/OMBIND&gt;</code></small> where <m:math><m:mi>B</m:mi></m:math>, <m:math><m:mi>C</m:mi></m:math>, and <m:math><m:msub><m:mi>X</m:mi><m:mi>i</m:mi></m:msub></m:math>  are the encodings of <m:math><m:mi>b</m:mi></m:math>, <m:math><m:mi>c</m:mi></m:math> 
  and <m:math><m:msub><m:mi>x</m:mi><m:mi>i</m:mi></m:msub></m:math>, respectively.</p>

<p>For instance the encoding of
  <m:math><m:mi mathvariant="bold">binding</m:mi>
       <m:mo>(</m:mo><m:mi>lambda</m:mi><m:mo>,</m:mo>
  <m:mi>x</m:mi><m:mo>,</m:mo><m:mi mathvariant="bold">application</m:mi>
     <m:mo>(</m:mo><m:mi>sin</m:mi><m:mo>,</m:mo> <m:mi>x</m:mi><m:mo>)</m:mo><m:mo>)</m:mo></m:math>  is:
<div class="literal"><pre>&lt;OMBIND&gt;
  &lt;OMS cdbase="http://www.openmath.org/cd" cd="fns1" name="lambda"/&gt;  
  &lt;OMBVAR&gt;&lt;OMV name="x"/&gt;&lt;/OMBVAR&gt;  
  &lt;OMA&gt;
    &lt;OMS cdbase="http://www.openmath.org/cd" cd="transc1" name="sin"/&gt; 
    &lt;OMV name="x"/&gt;  
  &lt;/OMA&gt;
&lt;/OMBIND&gt;</pre></div></p>
  
<p>Binders are defined in  Content Dictionaries, in particular,
  the symbol <small><code>lambda</code></small> is defined in the Content Dictionary
  <small><code>fns1</code></small> for functions over functions.</p>
  
</dd>

<dt>Attributions</dt><dd><p>are encoded using the <small><code>OMATTR</code></small> element.  If
  the <i>OpenMath</i> object <m:math><m:mi>e</m:mi></m:math>  is attributed with (<m:math><m:msub><m:mi>s</m:mi><m:mn>1</m:mn></m:msub></m:math>, <m:math><m:msub><m:mi>e</m:mi><m:mn>1</m:mn></m:msub></m:math>), <span>&#8230;</span>, 
  (<m:math><m:msub><m:mi>s</m:mi><m:mi>n</m:mi></m:msub></m:math>, <m:math><m:msub><m:mi>e</m:mi><m:mi>n</m:mi></m:msub></m:math>) pairs (where <m:math><m:msub><m:mi>s</m:mi><m:mi>i</m:mi></m:msub></m:math>  are the attributes), it is encoded
  as <small><code>&lt;OMATTR&gt;</code></small> <small><code>&lt;OMATP&gt;</code></small> <m:math><m:msub><m:mi>S</m:mi><m:mn>1</m:mn></m:msub></m:math>  <m:math><m:msub><m:mi>C</m:mi><m:mn>1</m:mn></m:msub></m:math>  <span>&#8230;</span> <m:math><m:msub><m:mi>S</m:mi><m:mi>n</m:mi></m:msub></m:math>  <m:math><m:msub><m:mi>C</m:mi><m:mi>n</m:mi></m:msub></m:math>  <small><code>&lt;/OMATP&gt;</code></small> <m:math><m:mi>E</m:mi></m:math>  <small><code>&lt;/OMATTR&gt;</code></small> where <m:math><m:msub><m:mi>S</m:mi><m:mi>i</m:mi></m:msub></m:math>  is the encoding of the
  symbol <m:math><m:msub><m:mi>s</m:mi><m:mi>i</m:mi></m:msub></m:math>, <m:math><m:msub><m:mi>C</m:mi><m:mi>i</m:mi></m:msub></m:math>  of the object <m:math><m:msub><m:mi>e</m:mi><m:mi>i</m:mi></m:msub></m:math>  and <m:math><m:mi>E</m:mi></m:math>  is the encoding of
  <m:math><m:mi>e</m:mi></m:math>.</p>

<p>Examples are the use of attribution to decorate a group by its
  automorphism group:
<div class="literal"><pre>&lt;OMATTR&gt;    
  &lt;OMATP&gt;
    &lt;OMS cd="groups" name="automorphism_group" /&gt;  
    [..group-encoding..] 
  &lt;/OMATP&gt;  
  [..group-encoding..] 
&lt;/OMATTR&gt;</pre></div>
or to express the type of a variable:
<div class="literal"><pre>&lt;OMATTR&gt;    
  &lt;OMATP&gt;
    &lt;OMS cd="ecc" name="type" /&gt; 
    &lt;OMS cd="ecc" name="real" /&gt;
  &lt;/OMATP&gt; 
  &lt;OMV name="x" /&gt;
&lt;/OMATTR&gt;</pre></div></p>

  
<p>
A special use of attributions is to associate non-<i>OpenMath</i> data with an
<i>OpenMath</i> object.  This is done using the
<small><code>OMFOREIGN</code></small> element.  The children of this
element must be well-formed <span>xml</span>.  For example the attribution of the
<i>OpenMath</i> object 
  <m:math>
     <m:mi>sin</m:mi><m:mfenced><m:mi>x</m:mi></m:mfenced></m:math>  with its
representation in Presentation MathML is:
<div class="literal"><pre>&lt;OMATTR&gt;
  &lt;OMATP&gt;
    &lt;OMS cd="presentation1" name="mathml"/&gt;  
    &lt;OMFOREIGN&gt;
      &lt;math xmlns="http://www.w3.org/1998/Math/MathML"&gt;
        &lt;mi&gt;sin&lt;/mi&gt;&lt;mfenced&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;/mfenced&gt;
      &lt;/math&gt;
    &lt;/OMFOREIGN&gt;  
  &lt;/OMATP&gt;
  &lt;OMA&gt;
   &lt;OMS cdbase="http://www.openmath.org/cd" cd="transc1" name="sin"/&gt; 
   &lt;OMV name="x"/&gt;  
  &lt;/OMA&gt;
&lt;/OMATTR&gt;</pre></div>
Of course not everything has a natural XML encoding in this way and
often the contents of a <small><code>OMFOREIGN</code></small> will just
be data or some kind of encoded string.  For example the attribution
of the previous object with its LaTeX representation could be achieved
as follows:
<div class="literal"><pre>&lt;OMATTR&gt;
  &lt;OMATP&gt;
    &lt;OMS cd="presentation1" name="latex"/&gt;  
    &lt;OMFOREIGN&gt;sin\,(x)&lt;/OMFOREIGN&gt;  
  &lt;/OMATP&gt;
  &lt;OMA&gt;
    &lt;OMS cdbase="http://www.openmath.org/cd" cd="transc1" name="sin"/&gt; 
    &lt;OMV name="x"/&gt;  
  &lt;/OMA&gt;
&lt;/OMATTR&gt;</pre></div>
</p>
</dd>




 <dt>Errors</dt> 
 <dd><p>are encoded using the <small><code>OME</code></small> element. The error whose
  symbol is <m:math><m:mi>s</m:mi></m:math>  and whose arguments are the <i>OpenMath</i> objects <m:math><m:msub><m:mi>e</m:mi><m:mn>1</m:mn></m:msub></m:math>,
  <span>&#8230;</span>, <m:math><m:msub><m:mi>e</m:mi><m:mi>n</m:mi></m:msub></m:math>  is encoded as <small><code>&lt;OME&gt;</code></small> <m:math><m:msub><m:mi>C</m:mi><m:mi>s</m:mi></m:msub></m:math>  <m:math><m:msub><m:mi>C</m:mi><m:mn>1</m:mn></m:msub></m:math><span>&#8230;</span> <m:math><m:msub><m:mi>C</m:mi><m:mi>n</m:mi></m:msub></m:math>  <small><code>&lt;/OME&gt;</code></small> where <m:math><m:msub><m:mi>C</m:mi><m:mi>s</m:mi></m:msub></m:math>  is the encoding of <m:math><m:mi>s</m:mi></m:math>  and <m:math><m:msub><m:mi>C</m:mi><m:mi>i</m:mi></m:msub></m:math>  the encoding
  of <m:math><m:msub><m:mi>e</m:mi><m:mi>i</m:mi></m:msub></m:math>.</p>

<p>If an <small><code>aritherror</code></small> Content Dictionary contained a
  <small><code>DivisionByZero</code></small> symbol, then the object
  <m:math><m:mi mathvariant="bold">error</m:mi><m:mo>(</m:mo><m:mi>DivisionByZero</m:mi><m:mo>,</m:mo> <m:mi mathvariant="bold">application</m:mi>
  <m:mo>(</m:mo><m:mi>divide</m:mi><m:mo>,</m:mo> 
  <m:mi>x</m:mi><m:mo>,</m:mo> <m:mn>0</m:mn><m:mo>)</m:mo><m:mo>)</m:mo></m:math>  would be encoded as follows:

<div class="literal"><pre>&lt;OME&gt;
  &lt;OMS cd="aritherror" name="DivisionByZero"/&gt;  
  &lt;OMA&gt;
    &lt;OMS cd="arith1" name="divide" /&gt;
    &lt;OMV name="x"/&gt;  
    &lt;OMI&gt; 0 &lt;/OMI&gt;
  &lt;/OMA&gt; 
 &lt;/OME&gt;</pre></div></p>
  
</dd>



 <dt>References</dt>
 <dd><p>
 <i>OpenMath</i> integers, floating point numbers, character strings,
 byearrays, applications, binding, attributions can also be encoded
 as an empty <small><code>OMR</code></small> element with an <small><code>xlink:href</code></small>
 attribute whose value is the value of an id attribute of an <i>OpenMath</i> object of
 that type. The <i>OpenMath</i> element represented by this <small><code>OMR</code></small>
 element is a copy of the <i>OpenMath</i> element pointed to in the
 <small><code>xlink:xref</code></small> attribute. Note that the representation of the
 <small><code>OMR</code></small>
 element is <i>structurally equal</i>, but not identical
 to the element it points to. </p>

 <p>For instance, the <i>OpenMath</i> object

 <m:math display="block">
   <m:mrow>
     <m:mi mathvariant="bold">application</m:mi>
     <m:mrow>
       <m:mo fence="true">(</m:mo>
       <m:mrow>
         <m:mi>f</m:mi>
         <m:mo separator="true">,</m:mo>
         <m:mi mathvariant="bold">application</m:mi>
         <m:mrow>
           <m:mo fence="true">(</m:mo>
           <m:mrow>
             <m:mi>f</m:mi>
             <m:mo separator="true">,</m:mo>
             <m:mi mathvariant="bold">application</m:mi>
             <m:mrow>
               <m:mo fence="true">(</m:mo>
               <m:mrow><m:mi>f</m:mi><m:mo separator="true">,</m:mo><m:mi>a</m:mi><m:mo separator="true">,</m:mo><m:mi>a</m:mi></m:mrow>
               <m:mo fence="true">)</m:mo>
             </m:mrow>
             <m:mo separator="true">,</m:mo>
             <m:mi mathvariant="bold">application</m:mi>
             <m:mrow>
               <m:mo fence="true">(</m:mo>
               <m:mrow><m:mi>f</m:mi><m:mo separator="true">,</m:mo><m:mi>a</m:mi><m:mo separator="true">,</m:mo><m:mi>a</m:mi></m:mrow>
               <m:mo fence="true">)</m:mo>
             </m:mrow>
             <m:mo fence="true">)</m:mo>
           </m:mrow>
           <m:mo separator="true">,</m:mo>
           <m:mi mathvariant="bold">application</m:mi>
           <m:mrow>
             <m:mo fence="true">(</m:mo>
             <m:mrow>
               <m:mi>f</m:mi>
               <m:mo separator="true">,</m:mo>
               <m:mi mathvariant="bold">application</m:mi>
               <m:mrow>
                 <m:mo fence="true">(</m:mo>
                 <m:mrow><m:mi>f</m:mi><m:mo separator="true">,</m:mo><m:mi>a</m:mi><m:mo separator="true">,</m:mo><m:mi>a</m:mi></m:mrow>
                 <m:mo fence="true">)</m:mo>
               </m:mrow>
               <m:mo separator="true">,</m:mo>
               <m:mi mathvariant="bold">application</m:mi>
               <m:mrow>
                 <m:mo fence="true">(</m:mo>
                 <m:mrow><m:mi>f</m:mi><m:mo separator="true">,</m:mo><m:mi>a</m:mi><m:mo separator="true">,</m:mo><m:mi>a</m:mi></m:mrow>
                 <m:mo fence="true">)</m:mo>
               </m:mrow>
               <m:mo fence="true">)</m:mo>
             </m:mrow>
           </m:mrow>
           <m:mo fence="true">)</m:mo>
         </m:mrow>
       </m:mrow>
     </m:mrow>
   </m:mrow>
 </m:math>
</p>
<p>can be encoded in the <span>xml</span> encoding as either one of the <span>xml</span> encodings
below (and some intermedidate versions as well).</p>

<div class="figure"><a name="fig_shared_vs_unshared" id="fig_shared_vs_unshared"/>
    
    
 <div class="literal"><pre>&lt;OMOBJ&gt;                      &lt;OMOBJ&gt;
  &lt;OMA&gt;                         &lt;OMA xmlns:xlink="http://www.w3.org/1999/xlink"&gt;
    &lt;OMV name="f"/&gt;               &lt;OMV name="f"/&gt; 
    &lt;OMA&gt;                         &lt;OMA id="t1"&gt;
      &lt;OMV name="f"/&gt;               &lt;OMV name="f"/&gt;
      &lt;OMA&gt;                         &lt;OMA id="t11"&gt;
        &lt;OMV name="f"/&gt;               &lt;OMV name="f"/&gt;
        &lt;OMV name="a"/&gt;               &lt;OMV name="a"/&gt;
        &lt;OMV name="a"/&gt;               &lt;OMV name="a"/&gt;
      &lt;/OMA&gt;                        &lt;/OMA&gt;
      &lt;OMA&gt;                         &lt;OMR xlink:href="t11"/&gt;
        &lt;OMV name="f"/&gt;
        &lt;OMV name="a"/&gt; 
        &lt;OMV name="a"/&gt;
      &lt;/OMA&gt;                                
    &lt;/OMA&gt;                      &lt;/OMA&gt;
    &lt;OMA&gt;                       &lt;OMR xlink:href="t1"/&gt;
      &lt;OMV name="f"/&gt;
      &lt;OMA&gt;
        &lt;OMV name="f"/&gt;
        &lt;OMV name="a"/&gt;
        &lt;OMV name="a"/&gt;
      &lt;/OMA&gt;
      &lt;OMA&gt;
        &lt;OMV name="f"/&gt;
        &lt;OMV name="a"/&gt;
        &lt;OMV name="a"/&gt;
      &lt;/OMA&gt;
    &lt;/OMA&gt;
  &lt;/OMA&gt;
&lt;/OMOBJ&gt;                     &lt;/OMOBJ&gt;
</pre></div>
<div>
  Figure 4.1 Shared vs. unshared representations</div></div>

<p>We say that an <i>OpenMath</i> element dominates all its children and all elements
they dominate. An <small><code>OMR</code></small> element dominates its target,
i.e. the element that carries the <small><code>id</code></small> attribute pointed to
by the <small><code>xref</code></small> attribute. For instance in the representation
in Figure <a href="#fig_shared_vs_unshared">Figure 4.1</a>, the
<small><code>OMA</code></small> element with <small><code>id="t1"</code></small> and
also the second <small><code>OMR</code></small> dominate the
<small><code>OMA</code></small> element with <small><code>id="t11"</code></small>.
</p> </dd>  </dl>

<div><h5 name="sec_acyclicity" id="sec_acyclicity">4.1.2.1 An Acyclicity Constraint</h5>


<p>The occurrences of the <small><code>OMR</code></small> element must obey the following global
<i>acyclicity constraint</i>: An <i>OpenMath</i> element may not dominate itself.</p>

<p>Consider for instance the following (illegal) <span>xml</span> representation
<div class="literal"><pre>&lt;OMOBJ&gt;
  &lt;OMA id="foo"&gt;
    &lt;OMS cdbase="http://www.openmath.org/cd" cd="arith1" name="divide"/&gt;
    &lt;OMI&gt;1&lt;/OMI&gt;
    &lt;OMA&gt;
       &lt;OMS cdbase="http://www.openmath.org/cd" cd="arith1" name="plus"/&gt;
       &lt;OMI&gt;1&lt;/OMI&gt;
       &lt;OMR xref="foo"/&gt;
    &lt;/OMA&gt; 
  &lt;/OMA&gt;
&lt;/OMOBJ&gt;
</pre></div>
</p>

<p>Here, the <small><code>OMA</code></small> element with
<small><code>id="foo"</code></small> dominates its third child, which dominates the
<small><code>OMR</code></small> element, which dominates its target: the element with
<small><code>id="foo"</code></small>. So by transitivity, this element dominates itself, and
by the acyclicity constraint, it is not the <span>xml</span> representation of an <i>OpenMath</i>
element. Even though it could be given the interpretation of the continued fraction
<m:math display="block">
 <m:mfrac>
   <m:mn>1</m:mn>
   <m:mrow>
     <m:mn>1</m:mn>
     <m:mo>+</m:mo>
     <m:mfrac>
       <m:mn>1</m:mn>
       <m:mrow>
         <m:mn>1</m:mn>
         <m:mo>+</m:mo>
         <m:mfrac><m:mn>1</m:mn><m:mi>...</m:mi></m:mfrac>
       </m:mrow>
     </m:mfrac>
   </m:mrow>
 </m:mfrac>
</m:math> this would correspond to an infinite tree of applications,
which is not admitted by the structure of <i>OpenMath</i> objects described
in <a href="#cha_obj">Chapter 3</a>.</p>

<p>Note that the acyclicity constraints is not restricted to such simple
cases, as the following example shows.</p>

<p><div class="literal"><pre>&lt;OMOBJ&gt;                                &lt;OMOBJ&gt;
  &lt;OMA id="bar"&gt;                         &lt;OMA id="baz"&gt;
    &lt;OMS cd="arith1" name="plus"/&gt;         &lt;OMS cd="arith1" name="plus"/&gt;
    &lt;OMI&gt;1&lt;/OMI&gt;                           &lt;OMI&gt;1&lt;/OMI&gt;
    &lt;OMR xref="baz"/&gt;                      &lt;OMR xref="bar"/&gt;
  &lt;/OMA&gt;                                 &lt;/OMA&gt;
&lt;/OMOBJ&gt;                               &lt;/OMOBJ&gt;
</pre></div></p>

<p> Here, the <small><code>OMA</code></small> with
<small><code>id="bar"</code></small> dominates its third child, the
<small><code>OMR</code></small> with <small><code>xref="baz"</code></small>,
which dominates its target <small><code>OMA</code></small> with
<small><code>id="baz"</code></small>, which in turn dominates its third
child, the <small><code>OMR</code></small> with
<small><code>xref="bar"</code></small>, this finally dominates its
target, the original <small><code>OMA</code></small> element with
<small><code>id="bar"</code></small>. So this pair of <i>OpenMath</i> objects
violates the acyclicity constraint and is not the <span>xml</span>
representation of an <i>OpenMath</i> object.</p>
</div>


<div><h5 name="sec_sharing_bvars" id="sec_sharing_bvars">4.1.2.2 Sharing and Bound Variables</h5>


<p>Note that the <small><code>OMR</code></small> element is a
<i>syntactic</i> referencing mechanism: an
<small><code>OMR</code></small> element stands for the exact <span>xml</span>
element it points to. In particular, referencing does not interact
with binding in a semantically intuitive way, since it allows for
variable capture. Consider for instance the following <span>xml</span>
representation: <div class="literal"><pre>&lt;OMBIND id="outer"&gt;
  &lt;OMS cdbase="http://www.openmath.org/cd" cd="fns1" name="lambda"/&gt;
  &lt;OMBVAR&gt;&lt;OMV name="X"/&gt;&lt;/OMBVAR&gt;
  &lt;OMA&gt;
    &lt;OMV name="f"/&gt;
    &lt;OMBIND id="inner"&gt;
      &lt;OMS cdbase="http://www.openmath.org/cd" cd="fns1" name="lambda"/&gt;
      &lt;OMBVAR&gt;&lt;OMV name="X"/&gt;&lt;/OMBVAR&gt;
      &lt;OMR id="copy" xlink:href="orig"/&gt;
    &lt;/OMBIND&gt;
    &lt;OMA id="orig"&gt;&lt;OMV name="g"/&gt;&lt;OMV name="X"/&gt;&lt;/OMA&gt;
  &lt;/OMA&gt;
&lt;/OMBIND&gt;
</pre></div>
it represents the <i>OpenMath</i> object
<m:math display="block">
  <m:mi mathvariant="bold">binding</m:mi>
  <m:mrow>
    <m:mo fence="true">(</m:mo>
    <m:mo>&#955;</m:mo>
      <m:mo separator="true">,</m:mo>
    <m:mi>X</m:mi>
    <m:mo separator="true">,</m:mo>
    <m:mrow>
      <m:mi mathvariant="bold">application</m:mi>
      <m:mo fence="true">(</m:mo>
      <m:mi>f</m:mi>
      <m:mo separator="true">,</m:mo>
      <m:mi mathvariant="bold">binding</m:mi>
      <m:mrow>
        <m:mo fence="true">(</m:mo>
        <m:mo>&#955;</m:mo>
        <m:mo separator="true">,</m:mo>
        <m:mi>X</m:mi>
        <m:mo separator="true">,</m:mo>
        <m:mrow>
          <m:mi mathvariant="bold">application</m:mi>
          <m:mo fence="true">(</m:mo>
          <m:mi>g</m:mi>
          <m:mo separator="true">,</m:mo>
          <m:mi>X</m:mi>
          <m:mo fence="true">)</m:mo>
        </m:mrow>
        <m:mo fence="true">)</m:mo>
      </m:mrow>
      <m:mo separator="true">,</m:mo>
      <m:mrow>
        <m:mi mathvariant="bold">application</m:mi>
        <m:mo fence="true">(</m:mo>
        <m:mi>g</m:mi>
        <m:mo separator="true">,</m:mo>
        <m:mi>X</m:mi>
        <m:mo fence="true">)</m:mo>
      </m:mrow>
      <m:mo fence="true">)</m:mo>
    </m:mrow>
    <m:mo fence="true">)</m:mo>
  </m:mrow>
  <m:mo fence="true">)</m:mo> </m:math> which has two subterms of the form
<m:math>
  <m:mi mathvariant="bold">application</m:mi>
  <m:mo fence="true">(</m:mo>
  <m:mi>g</m:mi>
  <m:mo separator="true">,</m:mo>
  <m:mi>X</m:mi>
  <m:mo fence="true">)
  </m:mo> </m:math>, one with <small><code>id="orig"</code></small> (the one explicitly
represented) and one with <small><code>id="copy"</code></small>, represented by the
<small><code>OMR</code></small> element. In the original, the variable
<m:math><m:mi>X</m:mi></m:math>  is bound by the <i>outer</i>
<small><code>OMBIND</code></small> element, and in the copy, the variable
<m:math><m:mi>X</m:mi></m:math>  is bound by the <i>inner</i>
<small><code>OMBIND</code></small> element. We say that the inner
<small><code>OMBIND</code></small> has captured the variable <m:math><m:mi>X</m:mi></m:math>.
</p>

<p>It is well-known that variable capture does not conserve semantics. For
  instance, we could use <m:math><m:mi>&#945;</m:mi></m:math>-conversion to rename the inner occurrence of
  <m:math><m:mi>x</m:mi></m:math>  into - say - 
  <m:math><m:mi>y</m:mi></m:math>  arriving at the (same) object
<m:math display="block">
  <m:mi mathvariant="bold">binding</m:mi>
  <m:mrow>
    <m:mo fence="true">(</m:mo>
    <m:mo>&#955;</m:mo>
      <m:mo separator="true">,</m:mo>
    <m:mi>X</m:mi>
    <m:mo separator="true">,</m:mo>
    <m:mrow>
      <m:mi mathvariant="bold">application</m:mi>
      <m:mo fence="true">(</m:mo>
      <m:mi>f</m:mi>
      <m:mo separator="true">,</m:mo>
      <m:mi mathvariant="bold">binding</m:mi>
      <m:mrow>
        <m:mo fence="true">(</m:mo>
        <m:mo>&#955;</m:mo>
        <m:mo separator="true">,</m:mo>
        <m:mi mathcolor="red">Y</m:mi>
        <m:mo separator="true">,</m:mo>
        <m:mrow>
          <m:mi mathvariant="bold">application</m:mi>
          <m:mo fence="true">(</m:mo>
          <m:mi>g</m:mi>
          <m:mo separator="true">,</m:mo>
          <m:mi mathcolor="red">Y</m:mi>
          <m:mo fence="true">)</m:mo>
        </m:mrow>
        <m:mo fence="true">)</m:mo>
      </m:mrow>
      <m:mo separator="true">,</m:mo>
      <m:mrow>
        <m:mi mathvariant="bold">application</m:mi>
        <m:mo fence="true">(</m:mo>
        <m:mi>g</m:mi>
        <m:mo separator="true">,</m:mo>
        <m:mi>X</m:mi>
        <m:mo fence="true">)</m:mo>
      </m:mrow>
      <m:mo fence="true">)</m:mo>
    </m:mrow>
    <m:mo fence="true">)</m:mo>
  </m:mrow>
  <m:mo fence="true">)</m:mo> </m:math>
 Using references that
capture variables in this way can easily lead to representation errors, and is not
  recommended.
</p>
</div>
</div>

<div><h4 name="xmldoc" id="xmldoc">4.1.3 Embedding <i>OpenMath</i> in <span>xml</span> Documents</h4>


     
<p>The above encoding of <span>xml</span> encoded <i>OpenMath</i> specifies the grammar to be
used in files that encode a single <i>OpenMath</i> object, and specifies the
character streams that a conforming <i>OpenMath</i> application should be able
to accept or produce.</p>

<p>When embedding <span>xml</span> encoded <i>OpenMath</i> objects into a larger <span>xml</span> document
one may wish, or need, to use other <span>xml</span> features. For example use of
extra <span>xml</span> attributes to specify <span>xml</span> Namespaces <a href="#xmlns">[16]</a>
or xml:lang attributes to specify the language used in strings <a href="#xml">[17]</a>.

</p>

 



<p>If such <span>xml</span> features are used then the <span>xml</span> application controlling the
document must, if passing the <i>OpenMath</i> fragment to an <i>OpenMath</i> application,
remove any such extra attributes and must ensure that the
fragment is encoded according to the grammar specified above.</p>
</div>
</div>

<div><h3 name="sec_binary" id="sec_binary">4.2 The Binary Encoding</h3>


<p>The binary encoding was essentially designed to be more compact than
the <span>xml</span> encodings, so that it can be more efficient if large
amounts of data are involved. For the current encoding, we tried to
keep the right balance between compactness, speed of encoding and
decoding and simplicity (to allow a simple specification and easy
implementations).</p>

<div><h4 name="sec_binary_grammar" id="sec_binary_grammar">4.2.1 A Grammar for the Binary Encoding</h4>


     

<div class="figure"><a name="fig_bin-enc" id="fig_bin-enc"/>
    
    
    <table>
          <tr>
            <td>start </td>
            <td><m:math><m:mo>&#8594;</m:mo></m:math></td>
            <td> [24] object [25] </td>
            <td>|</td>
            <td> [24+64] object [25]</td>
          </tr>
          
          <tr>
            <td>object </td>
            <td><m:math><m:mo>&#8594;</m:mo></m:math></td>
            <td> integer </td>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td> float</td>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td> variable</td>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td> indexed_variable</td>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td> symbol</td>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td> string</td>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td> bytearray</td>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td>foreign</td>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td> construct</td>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td>internal_reference</td>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td>external_reference</td>
          </tr>
          
          <tr>
            <td>integer </td>
            <td><m:math><m:mo>&#8594;</m:mo></m:math></td>
            <td> [1] [_] </td>
            <td>|</td>
            <td> [1+64]
              [<m:math><m:mi>n</m:mi></m:math>]
              id:<m:math><m:mi>n</m:mi></m:math> 
              [_]
            </td>
          </tr>

          <tr>
            <td/>
            <td><m:math><m:mo>|</m:mo></m:math></td>
            <td> [1+32] [_] </td>
            <td/>
            <td/>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td> [1+128] {_} </td>
            <td>|</td>
            <td> [1+64+128]
              {<m:math><m:mi>n</m:mi></m:math>}
              id:<m:math><m:mi>n</m:mi></m:math> 
              {_}
            </td>
          </tr>

          <tr>
            <td/>
            <td>|</td>
            <td> [1+32+128] {_} </td>
            <td/>
            <td/>
          </tr>

          <tr>
            <td/>
            <td>|</td>
            <td> [2]
              [<m:math><m:mi>n</m:mi></m:math>]
              [_] digits:<m:math><m:mi>n</m:mi></m:math> 
            </td>
            <td>|</td>
            <td> [2+64]
              [<m:math><m:mi>n</m:mi></m:math>]
              [<m:math><m:mi>m</m:mi></m:math>]
              [_] digits:<m:math><m:mi>n</m:mi></m:math> 
              id:<m:math><m:mi>m</m:mi></m:math> 
            </td>
          </tr>

          <tr>
            <td/>
            <td>|</td>
            <td> [2+32]
              [<m:math><m:mi>n</m:mi></m:math>]
              [_] digits:<m:math><m:mi>n</m:mi></m:math> 
            </td>
            <td/>
            <td/>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td> [2+128]
              {<m:math><m:mi>n</m:mi></m:math>}
              [_] digits:<m:math><m:mi>n</m:mi></m:math> 
            </td>
            <td>|</td>
            <td> [2+64+128]
              {<m:math><m:mi>n</m:mi></m:math>}
              {<m:math><m:mi>n</m:mi></m:math>}
              [_]
              digits:<m:math><m:mi>n</m:mi></m:math> 
              id:<m:math><m:mi>n</m:mi></m:math> 
            </td>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td> [2+32+128]
              {<m:math><m:mi>n</m:mi></m:math>}
              [_] digits:<m:math><m:mi>n</m:mi></m:math> 
            </td>
            <td/>
            <td/>
          </tr>
          
          <tr>
            <td>float </td>
            <td><m:math><m:mo>&#8594;</m:mo></m:math></td>
            <td> [3] {_}{_} </td>
            <td>|</td>
            <td> [3+64]
              [<m:math><m:mi>n</m:mi></m:math>]
              id:<m:math><m:mi>n</m:mi></m:math> 
              {_}{_}</td>
          </tr>
          
          <tr>
            <td>variable </td>
            <td><m:math><m:mo>&#8594;</m:mo></m:math></td>
            <td> [5]
              [<m:math><m:mi>n</m:mi></m:math>]
              varname:<m:math><m:mi>n</m:mi></m:math> 
            </td>
            <td>|</td>
            <td> [5+64]
              [<m:math><m:mi>n</m:mi></m:math>]
              [<m:math><m:mi>m</m:mi></m:math>]
              varname:<m:math><m:mi>n</m:mi></m:math> 
              id:<m:math><m:mi>m</m:mi></m:math> 
            </td>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td> [5+128]
              {<m:math><m:mi>n</m:mi></m:math>}
              varname:<m:math><m:mi>n</m:mi></m:math> 
            </td>
            <td>|</td>
            <td> [5+64+128]
              {<m:math><m:mi>n</m:mi></m:math>}
              {<m:math><m:mi>m</m:mi></m:math>}
              varname:<m:math><m:mi>n</m:mi></m:math> 
              id:<m:math><m:mi>m</m:mi></m:math> 
            </td>
          </tr>
          
          <tr>
            <td>indexed_variable</td>
            <td><m:math><m:mo>&#8594;</m:mo></m:math></td>
            <td> [10]
              [<m:math><m:mi>n</m:mi></m:math>]
              varname:<m:math><m:mi>n</m:mi></m:math> 
              object [11]
            </td>
            <td><m:math><m:mo>|</m:mo></m:math></td>
            <td> [10+64]
              [<m:math><m:mi>n</m:mi></m:math>]
              [<m:math><m:mi>m</m:mi></m:math>]
              varname:<m:math><m:mi>n</m:mi></m:math> 
              id:<m:math><m:mi>m</m:mi></m:math> 
              object [11]
            </td>
          </tr>
          
          
          <tr>
            <td/>
            <td><m:math><m:mo>|</m:mo></m:math></td>
            <td> [10+128]
              {<m:math><m:mi>n</m:mi></m:math>}
              varname:<m:math><m:mi>n</m:mi></m:math> 
              object [11]
            </td>
            <td><m:math><m:mo>|</m:mo></m:math></td>
            <td> [10+64+128]
              {<m:math><m:mi>n</m:mi></m:math>}
              {<m:math><m:mi>m</m:mi></m:math>}
              varname:<m:math><m:mi>n</m:mi></m:math> 
              id:<m:math><m:mi>m</m:mi></m:math> 
              object [11]
            </td>
          </tr>
          
          <tr>
            <td>symbol</td>
            <td><m:math><m:mo>&#8594;</m:mo></m:math></td>
            <td> [8]
              [<m:math><m:mi>n</m:mi></m:math>]
              [<m:math><m:mi>m</m:mi></m:math>]
              cdname:<m:math><m:mi>n</m:mi></m:math> 
              symbname:<m:math><m:mi>m</m:mi></m:math> 
            </td>
            <td>|</td>
            <td> [8+64]
              [<m:math><m:mi>n</m:mi></m:math>]
              [<m:math><m:mi>m</m:mi></m:math>]
              [<m:math><m:mi>k</m:mi></m:math>]
              cdname:<m:math><m:mi>n</m:mi></m:math> 
              symbname:<m:math><m:mi>m</m:mi></m:math> 
              id:<m:math><m:mi>k</m:mi></m:math> 
            </td>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td> [8+128]
              {<m:math><m:mi>n</m:mi></m:math>}
              {<m:math><m:mi>m</m:mi></m:math>}
              cdname:<m:math><m:mi>n</m:mi></m:math> 
              symbname:<m:math><m:mi>m</m:mi></m:math> 
            </td>
            <td>|</td>
            <td> [8+64+128]
              {<m:math><m:mi>n</m:mi></m:math>}
              {<m:math><m:mi>m</m:mi></m:math>}
              {<m:math><m:mi>k</m:mi></m:math>}
              cdname:<m:math><m:mi>n</m:mi></m:math> 
              symbname:<m:math><m:mi>m</m:mi></m:math> 
              id:<m:math><m:mi>k</m:mi></m:math></td>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td> [9]
              [<m:math><m:mi>n</m:mi></m:math>]
              [<m:math><m:mi>m</m:mi></m:math>]
              [<m:math><m:mi>k</m:mi></m:math>]
              cdname:<m:math><m:mi>n</m:mi></m:math> 
              symbname:<m:math><m:mi>m</m:mi></m:math> 
              uri:<m:math><m:mi>k</m:mi></m:math> 
            </td>
            <td>|</td>
            <td> [9+64]
              [<m:math><m:mi>n</m:mi></m:math>]
              [<m:math><m:mi>m</m:mi></m:math>]
              [<m:math><m:mi>k</m:mi></m:math>]
              [<m:math><m:mi>l</m:mi></m:math>]
              cdname:<m:math><m:mi>n</m:mi></m:math> 
              symbname:<m:math><m:mi>m</m:mi></m:math> 
              uri:<m:math><m:mi>k</m:mi></m:math> 
              id:<m:math><m:mi>l</m:mi></m:math> 
            </td>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td> [9+128]
              {<m:math><m:mi>n</m:mi></m:math>}
              {<m:math><m:mi>m</m:mi></m:math>}
              {<m:math><m:mi>k</m:mi></m:math>}
              cdname:<m:math><m:mi>n</m:mi></m:math> 
              symbname:<m:math><m:mi>m</m:mi></m:math> 
              uri:<m:math><m:mi>k</m:mi></m:math> 
            </td>
            <td>|</td>
            <td> [9+64+128]
              {<m:math><m:mi>n</m:mi></m:math>}
              {<m:math><m:mi>m</m:mi></m:math>}
              {<m:math><m:mi>k</m:mi></m:math>}
              {<m:math><m:mi>l</m:mi></m:math>}
              cdname:<m:math><m:mi>n</m:mi></m:math> 
              symbname:<m:math><m:mi>m</m:mi></m:math> 
              uri:<m:math><m:mi>k</m:mi></m:math> 
            id:<m:math><m:mi>l</m:mi></m:math></td>
          </tr>
          
          <tr>
            <td>string </td>
            <td><m:math><m:mo>&#8594;</m:mo></m:math></td>
            <td> [6]
              [<m:math><m:mi>n</m:mi></m:math>]
              
              <span>bytes</span>:<m:math><m:mi>n</m:mi></m:math> 
            </td>
            <td>|</td>
            <td> [6+64]
              [<m:math><m:mi>n</m:mi></m:math>]
              
              <span>bytes</span>:<m:math><m:mi>n</m:mi></m:math> 
            </td>
          </tr>
          
          <tr>
            <td/>
            <td><m:math><m:mo>|</m:mo></m:math></td>
            <td> [6+32]
              [<m:math><m:mi>n</m:mi></m:math>]
              <span>bytes</span>:<m:math><m:mi>n</m:mi></m:math> 
            </td>
            <td/>
            <td/>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td> [6+128]
              {<m:math><m:mi>n</m:mi></m:math>}
              
              <span>bytes</span>:<m:math><m:mi>n</m:mi></m:math> 
            </td>
            <td>|</td>
            <td> [6+64+128]
              {<m:math><m:mi>n</m:mi></m:math>}
              {<m:math><m:mi>m</m:mi></m:math>}
              
              <span>bytes</span>:<m:math><m:mi>n</m:mi></m:math> 
              id:<m:math><m:mi>m</m:mi></m:math> 
            </td>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td> [6+32+128]
              {<m:math><m:mi>n</m:mi></m:math>}
              <span>bytes</span>:<m:math><m:mi>n</m:mi></m:math> 
            </td>
            <td/>
            <td/>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td> [7]
              [<m:math><m:mi>n</m:mi></m:math>]
              
              <span>bytes</span>:<m:math><m:mn>2</m:mn><m:mi>n</m:mi></m:math> 
            </td>
            <td>|</td>
            <td> [7+64]
              [<m:math><m:mi>n</m:mi></m:math>]
              [<m:math><m:mi>m</m:mi></m:math>]
              
              <span>bytes</span>:<m:math><m:mn/><m:mi>n</m:mi></m:math> 
              id:<m:math><m:mi>m</m:mi></m:math> 
            </td>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td> [7+32]
              [<m:math><m:mi>n</m:mi></m:math>]
              <span>bytes</span>:<m:math><m:mn>2</m:mn><m:mi>n</m:mi></m:math> 
            </td>
            <td/>
            <td/>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td> [7+128]
              {<m:math><m:mi>n</m:mi></m:math>}
              
              <span>bytes</span>:<m:math><m:mn>2</m:mn><m:mi>n</m:mi></m:math> 
            </td>
            <td>|</td>
            <td> [7+64+128]
              {<m:math><m:mi>n</m:mi></m:math>}
              {<m:math><m:mi>m</m:mi></m:math>}
              
              <span>bytes</span>:<m:math><m:mn>2</m:mn><m:mi>n</m:mi></m:math> 
              id:<m:math><m:mi>m</m:mi></m:math> 
            </td>
          </tr>
          
          
          <tr>
            <td/>
            <td>|</td>
            <td> [7+32+128]
              {<m:math><m:mi>n</m:mi></m:math>}
              <span>bytes</span>:<m:math><m:mn>2</m:mn><m:mi>n</m:mi></m:math> 
            </td>
            <td/>
            <td/>
          </tr>
          
          <tr>
            <td>bytearray </td>
            <td><m:math><m:mo>&#8594;</m:mo></m:math></td>
            <td> [4]
              [<m:math><m:mi>n</m:mi></m:math>]
              bytes:<m:math><m:mi>n</m:mi></m:math> 
            </td>
            <td>|</td>
            <td> [4+64]
              [<m:math><m:mi>n</m:mi></m:math>]
              [<m:math><m:mi>m</m:mi></m:math>]
              bytes:<m:math><m:mi>n</m:mi></m:math> 
              id:<m:math><m:mi>m</m:mi></m:math> 
            </td>
          </tr>
          
          <tr>
            <td/>
            <td><m:math><m:mo>|</m:mo></m:math></td>
            <td> [4+32]
              [<m:math><m:mi>n</m:mi></m:math>]
              bytes:<m:math><m:mi>n</m:mi></m:math> 
            </td>
            <td/>
            <td/>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td> [4+128]
              {<m:math><m:mi>n</m:mi></m:math>}
              bytes:<m:math><m:mi>n</m:mi></m:math> 
            </td>
            <td>|</td>
            <td> [4+64+128]
              {<m:math><m:mi>n</m:mi></m:math>}
              {<m:math><m:mi>m</m:mi></m:math>}
              bytes:<m:math><m:mi>n</m:mi></m:math> 
              id:<m:math><m:mi>m</m:mi></m:math> 
            </td>
          </tr>
          
          
          <tr>
            <td/>
            <td>|</td>
            <td> [4+32+128]
              {<m:math><m:mi>n</m:mi></m:math>}
              bytes:<m:math><m:mi>n</m:mi></m:math> 
            </td>
            <td/>
            <td/>
          </tr>
          
          <tr>
            <td>foreign</td>
            <td><m:math><m:mo>&#8594;</m:mo></m:math></td>
            <td> [12]
              [<m:math><m:mi>n</m:mi></m:math>]
              bytes:<m:math><m:mi>n</m:mi></m:math> 
            </td>
            <td>|</td>
            <td> [12+64]
              [<m:math><m:mi>n</m:mi></m:math>]
              [<m:math><m:mi>m</m:mi></m:math>]
              bytes:<m:math><m:mi>n</m:mi></m:math> 
              id:<m:math><m:mi>m</m:mi></m:math> 
            </td>
          </tr>
          
          <tr>
            <td/>
            <td><m:math><m:mo>|</m:mo></m:math></td>
            <td> [12+32]
              [<m:math><m:mi>n</m:mi></m:math>]
              bytes:<m:math><m:mi>n</m:mi></m:math> 
            </td>
            <td/>
            <td/>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td> [12+128]
              {<m:math><m:mi>n</m:mi></m:math>}
              bytes:<m:math><m:mi>n</m:mi></m:math> 
            </td>
            <td>|</td>
            <td> [12+64+128]
              {<m:math><m:mi>n</m:mi></m:math>}
              {<m:math><m:mi>m</m:mi></m:math>}
              bytes:<m:math><m:mi>n</m:mi></m:math> 
              id:<m:math><m:mi>m</m:mi></m:math> 
            </td>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td> [12+32+128]
              {<m:math><m:mi>n</m:mi></m:math>}
              bytes:<m:math><m:mi>n</m:mi></m:math> 
            </td>
            <td/>
            <td/>
          </tr>
          
          <tr>
            <td>construct </td>
            <td><m:math><m:mo>&#8594;</m:mo></m:math></td>
            <td> [16] object objects [17] </td>
            <td>|</td>
            <td> [16+64]
              {<m:math><m:mi>m</m:mi></m:math>}
              id:<m:math><m:mi>m</m:mi></m:math> 
              object objects [17]
            </td>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td> [22] symbol objects [23] </td>
            <td>|</td>
            <td> [22+64]
              {<m:math><m:mi>m</m:mi></m:math>}
              id:<m:math><m:mi>m</m:mi></m:math> 
              symbol objects [23]</td>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td> [18] attrpairs object [19] </td>
            <td>|</td>
            <td> [18+64]
              {<m:math><m:mi>m</m:mi></m:math>}
              id:<m:math><m:mi>m</m:mi></m:math> 
              attrpairs object [19]
            </td>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td> [26] object bvars object [27] </td>
            <td>|</td>
            <td> [26+64]
              {<m:math><m:mi>m</m:mi></m:math>}
              id:<m:math><m:mi>m</m:mi></m:math> 
              object bvars object [27]
            </td>
          </tr>
          
          <tr>
            <td>attrpairs </td>
            <td><m:math><m:mo>&#8594;</m:mo></m:math></td>
            <td> [20] pairs [21] </td>
            <td>|</td>
            <td> [20+64]
              {<m:math><m:mi>m</m:mi></m:math>}
              id:<m:math><m:mi>m</m:mi></m:math> 
              pairs [21]
            </td>
          </tr>
          
          <tr>
            <td>pairs </td>
            <td><m:math><m:mo>&#8594;</m:mo></m:math></td>
            <td> symbol object</td>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td> symbol object pairs</td>
          </tr>
          
          <tr>
            <td>bvars </td>
            <td><m:math><m:mo>&#8594;</m:mo></m:math></td>
            <td> [28] vars [29] </td>
            <td>|</td>
            <td> [28+64]
              {<m:math><m:mi>m</m:mi></m:math>}
              id:<m:math><m:mi>m</m:mi></m:math> 
              vars [29]
            </td>
          </tr>
          
          <tr>
            <td>vars </td>
            <td><m:math><m:mo>&#8594;</m:mo></m:math></td>
            <td> attrvar</td>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td> attrvar vars</td>
          </tr>
          
          <tr>
            <td>attrvar </td>
            <td><m:math><m:mo>&#8594;</m:mo></m:math></td>
            <td> variable</td>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td> [18] attrpairs attrvar [19] </td>
            <td>|</td>
            <td> [18+64]
              {<m:math><m:mi>m</m:mi></m:math>}
              id:<m:math><m:mi>m</m:mi></m:math> 
              attrpairs attrvar [19]
            </td>
          </tr>
          
          <tr>
            <td>objects </td>
            <td><m:math><m:mo>&#8594;</m:mo></m:math></td>
            <td> object objects</td>
          </tr>
          
          <tr>
            <td>internal_reference </td>
            <td><m:math><m:mo>&#8594;</m:mo></m:math></td>
            <td> [30] [_] </td>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td> [30+128] {_}</td>
          </tr>
          
          <tr>
            <td>external_reference </td>
            <td><m:math><m:mo>&#8594;</m:mo></m:math></td>
            <td> [31]
              [<m:math><m:mi>n</m:mi></m:math>]
              uri:<m:math><m:mi>n</m:mi></m:math> 
            </td>
          </tr>
          
          <tr>
            <td/>
            <td>|</td>
            <td> [31+128]
              {<m:math><m:mi>n</m:mi></m:math>}
              uri:<m:math><m:mi>n</m:mi></m:math> 
            </td>
          </tr>
        </table>
  <div>
  Figure 4.2 Grammar of the binary encoding of <i>OpenMath</i> objects.</div></div>
  
  <p>Figure <a href="#fig_bin-enc">Figure 4.2</a> gives a grammar for the binary
    encoding <span> (<span>"start"</span> is the start
      symbol).</span>.</p>
  <p>The following conventions are used in this section:
    [<m:math><m:mi>n</m:mi></m:math>] denotes a byte whose value is the integer
    <m:math><m:mi>n</m:mi></m:math>  (<m:math><m:mi>n</m:mi></m:math>  can range from 0 to 255),
    {<m:math><m:mi>m</m:mi></m:math>} denotes four bytes representing the (unsigned) integer
    <m:math><m:mi>m</m:mi></m:math>  in network byte order, [_] denotes an arbitrary byte, {_}
    denotes an arbitrary sequence of four bytes.
    </p>
  
  <p><i>xxxx</i>:<m:math><m:mi>n</m:mi></m:math>,
    where <i>xxxx</i> is one of <i>symbname</i>,
    <i>cdname</i>, <i>varname</i>,
    <i>uri</i>, <i>id</i>, <i>digits</i>, or
    <i>bytes</i> denotes a sequence of <m:math><m:mi>n</m:mi></m:math>  bytes
    that conforms to the constraints on <i>xxxx</i> strings. For
    instance, for <i>symbname</i>, <i>varname</i>, or
    <i>cdname</i>this is the regular expression described in
    <a href="#sec_names">Section 3.3</a>, for <i>uri</i> it is the grammar for
    URIs in <a href="#IETF2396">[9]</a>.</p>
</div>

<div><h4 name="sec_bin-desc" id="sec_bin-desc">4.2.2 Description of the Grammar</h4>
  
  
<p>An <i>OpenMath</i> object is encoded as a sequence of bytes starting with the begin object tag
(
<span>values 24 and 88</span>) and ending with the end
object tag (value 25). These are similar to
the <small><code>&lt;OMOBJ&gt;</code></small> and <small><code>&lt;/OMOBJ&gt;</code></small> tags of
the <span>xml</span> encoding.</p>

<p>The encoding of each kind of <i>OpenMath</i> object begins with a tag that is a single byte,
holding a <span><i>token identifier</i></span>
<span> that describes the kind of object</span> and two flags, the <span><i>long</i></span> flag and the <span><i>shared</i></span> flag. The
identifier is stored in the first 6 bits (1 to 6). The long flag is the eighth bit
<span>and the shared flag is the seventh bit. If the long
  flag is set, this signifies that  the names, strings, and data fields in the
  encoded <i>OpenMath</i> object are longer than 255 byte or characters. The sharing flag
  indicates that the encoded object is shared in another (part of an) object
  somewhere else (see <a href="#sec_sharing_references">Section 4.2.3</a>). Note that if the sharing
  flag is set (in the right column of the grammar in Figure
  <a href="#fig_bin-enc">Figure 4.2</a>, then the encoding includes a representation of
  the identifier.</span>
</p>
<p>To facilitate the stremaing <i>OpenMath</i> objects, some basic
  objects (integers, strings, bytearrays, and foreign objects) have variant
  token identifiers with the fifth bit set. The idea behind this is that these
  basic objects can be split into packets. If the fifth bit is not set, this
  packet is the final packet of the basic object. If the bit is set, then more
  packets of the basic object will follow directly after this one. Note that all
  packets making up a basic object must have the same token identifier (up to the
  fifth bit). 
</p>

<p>Here is a description of the binary encodings of every kind of <i>OpenMath</i> object:

<dl>

  <dt>Integers</dt><dd><p>are encoded depending on how large they
      are. There are four possible formats.  Integers between -128 and 127 are
      encoded as the small integer tags (<span>token identifier</span> 1) followed by a single byte that is the
      value of the integer (interpreted as a signed character). For
      example 16 is encoded as <small><code>0x01 0x10</code></small>.  Integers between
      <m:math>
        <m:msup>
          <m:mn>-2</m:mn>
          <m:mn>31</m:mn>
        </m:msup>
      </m:math> 
      (<m:math><m:mn>-2147483648</m:mn></m:math>) and
      <m:math>
        <m:msup>
          <m:mn>2</m:mn>
          <m:mn>31</m:mn>
        </m:msup>
        <m:mo>-</m:mo>
        <m:mn>1</m:mn>
      </m:math> 
      (<m:math><m:mn>2147483647</m:mn></m:math>) are encoded as
      the small integer tag with the long flag set followed by the integer
      encoded in little endian format on four bytes (network byte order:
      the most significant byte comes first). For example, 128 is encoded
      as <small><code>0x81</code></small> <small><code>0x00000080</code></small>.  The most
      general encoding begins 
      with the big integer tag (token identifier 2) with the long flag set
      if the number of bytes in the encoding of the digits is greater or
      equal than 256. It is followed by the length (in bytes) of the
      sequence of digits, encoded on one byte (0 to 255, if the long flag
      was not set) or four bytes (network byte order, if the long flag was
      set).  It is then followed by a byte describing the sign and the
      base.  This 'sign/base' byte is <small><code>+</code></small> (0x2B) or
      <small><code>-</code></small> (0x2D) 
      for the sign ored with the base mask bits that can be 0 for base 10
      or 0x40 for base 16.  It is followed by the strings of digits (as
      characters) in their natural order (as in the <span>xml</span>
      encoding).  For example, 8589934592
      (<m:math><m:msup><m:mn>2</m:mn><m:mn>33</m:mn></m:msup></m:math>) is encoded <small><code>0x02 
        0x0A 0x2B 0x38353839393334353932</code></small> and
      xfffffff1 is 
      encoded as <small><code>0x02 0x08 0x6b 0x6666666666666631</code></small>.  Note that it is
      permitted to encode a <span>"small"</span> integer in any <span>"bigger"</span>
      format.
    </p>
    <p>To splice sequences of integer packets into
      integers, we have to consider three cases: In the case of token identifiers
      1, 33, and 65 the sequence of packets is treated as a sequence of integer digits
      to the base of <m:math><m:msup><m:mn>2</m:mn><m:mn>7</m:mn></m:msup></m:math>  (most
      significant first). The case of token identifiers 129, 161, and 193 is analogous
      with digits of base <m:math><m:msup><m:mn>2</m:mn><m:mn>31</m:mn></m:msup></m:math>. In the
      case of token identifiers 2, 34, 66, 130, 162, and 194 the integer is assembled by 
      concatenating the string of decimal digits in the packets in sequence order
      (which corresponds to most significant first).  Note that in all cases only
      the sequence-initial packet may contain a signed
      integer. The sign of this packet determines the sign of the overall
      integer.</p>
</dd>



<dt>Symbols</dt>
<dd><p>are encoded as the symbol tags
    (<span>token identifier</span> 8) with the long flag
    set if the maximum of the length <span>in bytes in the UTF-8 encoding</span> of the Content Dictionary name,
    
  the symbol name <span>or the CD base </span>
  is greater than or equal to 256
<span>. The symbol tags [8] and [8+128] are deprecated in <i>OpenMath</i>2 since
  symbols now have an optional <small><code>cdbase</code></small> field, but are
  kept for backwards compatibility. The symbol tag is  followed by the length <span>in bytes in the UTF-8 encoding</span> of the
  Content Dictionary name, the symbol name, and the CD base as a byte (if the long flag was not set)
  or a four byte integers (in network byte order). These are followed by the
  
  <span>bytes of the UTF-8 encoding</span> of the Content Dictionary name, the symbol name, and the CD base.</span></p>
</dd>



<dt>Variables</dt>
<dd><p>are encoded using the variable tags
    (<span>token identifiers</span> 5) with the long
  flag set if the number of bytes in the UTF-8 encoding of the variable name is
  greater than or equal to 256 (this should never happen if the rules
  on variables are followed).  Then, there is the number of characters
  as a byte (if the long flag was not set) or a four byte integer
  (in network byte order), followed by the characters of the name of
  the variable. For example, the variable x is encoded as <small><code>0x05
    0x01 0x78</code></small>.</p>
</dd>



<dt>Indexed Variables</dt>
<dd><p>are encoded using the indexed variable tags
    (token identifiers 10 and 11) as begin and end tags. The long
  flag set on the begin tag if the number of bytes (characters) in the variable name is
  greater than or equal to 256.  The start tag is followed by the number of
  bytes
  as a byte (if the long flag was not set) or a four byte integer
  (in network byte order), followed by the bytes 
  of  the UTF-8 encoding of the name of
  the variable. This is followed by the encoding of an <i>OpenMath</i> object and the end tag
  [11].</p>
</dd>




<dt>Floating-point number</dt>
<dd><p>are encoded using the floating-point
  number tags (<span>token identifier</span> 3) followed by eight bytes that are the IEEE 754
  representation <a href="#ieee754_85">[8]</a>, most significant bytes first. For
  example, 0.1 is encoded as <small><code>0x03 0x000000000000f03f</code></small>.</p>
</dd>



<dt>Character string</dt>
<dd><p>are encoded in two ways depending on whether
  ,
  <span>the string is encoded in
  <span>utf-16</span> or <span>iso-859-1</span>
  (<span>latin-1</span>).
  In the case of <span>latin-1</span></span> it is encoded as the one
  byte character string tags (<span>token identifier</span> 6) with the long flag set if the number
  of bytes (characters) in the string is greater than or equal to 256.
  Then, there is the number of characters as a byte (if the length
  flag was not set) or a four byte integer (in network byte order),
  followed by the characters in the string. If the string <span> is encoded in
  <span>utf-16</span></span>, it is encoded as the two byte character string
  tags (<span>token identifier</span> 7) with the long flag set if the number of characters in the
  string is greater or equal to 256. Then, there is the number of
  <span><span>utf-16</span> units, which will be the
  number of characters unless characters in the higher planes of
  Unicode are used,</span> as a byte (if the long flag was not set) or a four byte
  integer (in network byte order), followed by the characters
  (<span>utf-16</span> encoded  Unicode).</p>

<p>Sequences of string packets are assembled into strings by 
      concatenating the strings in the packets in sequence order.</p>

</dd>



<dt>Bytearrays</dt>
<dd><p>are encoded using the bytearray tags (<span>token identifier</span> 4) with the
  long flag set if the number  elements is
  greater than or equal to 256. Then, there is the number of elements,
  as a byte (if the long flag was not set) or a four byte integer
  (in network byte order), followed by the elements of the arrays in
  their normal order.</p>
<p>Sequences of bytearray packets are assembled into byte arrays by 
      concatenating the bytearrays in the packets in sequence order.</p>

</dd>



<dt>Foreign Objects</dt>
<dd>
  <p>are encoded using the foreign object tags (token identifier 12) with the
  long flag set if the number of bytes is
  greater than or equal to 256. Then, there is the number of elements,
  as a byte (if the long flag was not set) or a four byte integer
  (in network byte order), followed by the elements of the arrays in
  their normal order.</p>
<p>Sequences of foreign object packets are assembled into
  foreign objects by 
      concatenating the bytes in the packets in sequence order.</p>
</dd>



  <dt>Applications</dt>
  <dd><p>are encoded using the application tags (<span>token identifiers</span> 16 and 17). More
  precisely, the application of <m:math><m:msub><m:mi>E</m:mi><m:mn>0</m:mn></m:msub></m:math>  to
  <m:math><m:msub><m:mi>E</m:mi><m:mn>1</m:mn></m:msub></m:math><span>&#8230;</span>
  <m:math><m:msub><m:mi>E</m:mi><m:mi>n</m:mi></m:msub></m:math>  is encoded
  using the application tags (<span>token
    identifier</span> 16), the sequence of the encodings of 
  <m:math><m:msub><m:mi>E</m:mi><m:mn>0</m:mn></m:msub></m:math>  to
  <m:math><m:msub><m:mi>E</m:mi><m:mi>n</m:mi></m:msub></m:math>  and the end application tags
  (<span>token identifier</span> 17).</p> 
</dd>


 
  <dt>Bindings</dt>
  <dd><p>are encoded using the binding
 tags (<span>token identifiers</span> 26 and 27). More precisely,
 the binding by <m:math><m:mi>B</m:mi></m:math>  of variables
 <m:math><m:msub><m:mi>V</m:mi><m:mn>1</m:mn></m:msub></m:math><span>&#8230;</span>
 <m:math><m:msub><m:mi>V</m:mi><m:mi>n</m:mi></m:msub></m:math>  in <m:math><m:mi>C</m:mi></m:math>  is
 encoded as the binding tags (<span>token
 identifier</span> 26), followed by the encoding of <m:math><m:mi>B</m:mi></m:math>,
 followed by the binding variables tags (<span>token
 identifier</span> 28), followed by the encodings of the variables
 <m:math><m:msub><m:mi>V</m:mi><m:mn>1</m:mn></m:msub></m:math>  <span>&#8230;</span>
 <m:math><m:msub><m:mi>V</m:mi><m:mi>n</m:mi></m:msub></m:math>, followed by the end binding
 variables tags (<span>token identifier</span> 29),
 followed by the encoding of <m:math><m:mi>C</m:mi></m:math>, followed by the end binding
 tags (<span>token identifier</span> 27).</p>
 </dd> 


 <dt>Attribution</dt>
 <dd><p>are encoded using the attribution
     tags (<span>token identifiers </span> 18 and 19). More
     precisely, attribution of the object <m:math><m:mi>E</m:mi></m:math>  with
     (<m:math><m:msub><m:mi>S</m:mi><m:mn>1</m:mn></m:msub></m:math>,
     <m:math><m:msub><m:mi>E</m:mi><m:mn>1</m:mn></m:msub></m:math>),
     <m:math><m:mi>&#8230;</m:mi></m:math> 
     (<m:math><m:msub><m:mi>S</m:mi><m:mi>n</m:mi></m:msub></m:math>,
     <m:math><m:msub><m:mi>E</m:mi><m:mi>n</m:mi></m:msub></m:math>) pairs (where
     <m:math><m:msub><m:mi>S</m:mi><m:mi>i</m:mi></m:msub></m:math>  are the attributes) is 
     encoded as the attributed object tags (<span>token
       identifier</span> 18), followed by the encoding 
     of the attribute pairs as the attribute pairs tags
     (<span>token identifier</span> 20), followed by 
     the encoding of each symbol and value, followed by the end attribute
     pairs tags (<span>token identifier</span> 21),
     followed by the encoding of <m:math><m:mi>E</m:mi></m:math>, followed by the end 
     attributed object tags (<span>token identifier</span> 19).</p>
 </dd>



  <dt>Error</dt>
  <dd><p>are encoded using the error tags
      (<span>token identifiers</span> 22 and 23). More precisely, 
  <m:math><m:msub><m:mi>S</m:mi><m:mn>0</m:mn></m:msub></m:math>  applied to
  <m:math><m:msub><m:mi>E</m:mi><m:mn>1</m:mn></m:msub></m:math><span>&#8230;</span>
  <m:math><m:msub><m:mi>E</m:mi><m:mi>n</m:mi></m:msub></m:math>  is encoded as the error tags
  (<span>token identifier</span> 22), 
  the encoding of <m:math><m:msub><m:mi>S</m:mi><m:mn>0</m:mn></m:msub></m:math>, the sequence of
  the encodings of <m:math><m:msub><m:mi>E</m:mi><m:mn>0</m:mn></m:msub></m:math>  to
  <m:math><m:msub><m:mi>E</m:mi><m:mi>n</m:mi></m:msub></m:math>  and the end error tags
  (<span>token identifier</span> 23).</p> 
</dd>



<dt>Internal References</dt>
<dd>
  <p>are encoded using the internal reference tags [30] and [30+128] (the sharing flag cannot
  be set on this tag, since chains of references are not allowed in the <i>OpenMath</i>
  binary encoding.) with   long flag set if the number of <i>OpenMath</i> sub-objects in the
  encoded <i>OpenMath</i> is
  greater than or equal to 256. Then, there is the ordinal number of the
  referenced <i>OpenMath</i> object as a byte (if the long flag was not set) or a four byte integer
  (in network byte order).</p>
</dd>



<dt>External References</dt>
<dd>
  <p>are encoded using the external reference tags [31] and [31+128] (the sharing flag cannot
  be set on this tag, since chains of references are not allowed in the <i>OpenMath</i>
  binary encoding) with the
  long flag set if the number of bytes in the reference URI is
  greater than or equal to 256. Then, there is the number of bytes in the URI used
  for the external reference 
  as a byte (if the long flag was not set) or a four byte integer
  (in network byte order), followed by the URI.</p>
</dd>


</dl> 
</p>

<div><h5 name="sec_sharing" id="sec_sharing">4.2.2.1 Sharing <span>in Objects beginning with the identifier [24]</span></h5>

 
<p>This binary encoding supports the sharing of symbols, variables and strings
(up to a certain length for strings) within one object. That is, sharing between
objects is not supported.  A reference to a shared symbol, variable or string is
encoded as the corresponding tag with the long flag not set and the shared flag
set, followed by a positive integer <m:math><m:mi>n</m:mi></m:math>  coded on one byte (0
to 255). This integer references the <m:math><m:mi>n</m:mi> <m:mo>+</m:mo>
<m:mn>1</m:mn></m:math>-th such sharable sub-object (symbol, variable or string up to
255 characters) in the current <i>OpenMath</i> object (counted in the order they are
generated by the encoding).  For example, <small><code>0x48 0x01</code></small>
references a symbol that is identical to the second symbol that was found in the
current object.  Strings with 8 bit characters and strings with 16 bit characters
are two different kinds of objects for this sharing. Only strings containing less
than 256 characters can be shared (i.e. only strings up to 255 characters).</p>
</div>
</div>

<div><h4 name="sec_sharing_references" id="sec_sharing_references">4.2.3 Sharing with References (beginning with [24+64])</h4>
  

  <p>In the binary encoding specified in the last section (which we keep
for compatibility reasons, but deprecate in favor of the more
efficient binary encoding specified in this section) only symbols,
variables, and short strings could be shared. In this section, we will
present a second binary encoding, which shares most of the identifiers
with the one in the last one, but handles sharing differently. This
  encoding is signaled by the shared object tags [88].</p>

  <p>The main difference is the interpretation of the sharing flag (bit 7),
which can be set on all objects that allow it. Instead of encoding a reference to a
previous occurrence of an object of the same type, it indicates
whether an object will be referenced later in the encoding. This
  corresponds to the information, whether an <small><code>id</code></small>
 attribute is set
in the <span>xml</span> encoding. On the object identifier (where sharing does not
make sense), the shared flag signifies the encoding described here
([88]=[24+64]).
</p>

<p>Otherwise integers, floats, variables, symbols, strings, bytearrays, and constructs
are treated exactly as in the binary encoding described in the last section.</p>

<p>The binary encoding with references uses the additional reference tags [30]
for (short) internal references, [30+128] for long internal references, [31] for
(short) external references, [31+128] for long external references. Internal
references are used to share sub-objects in the encoded object (see <a href="#fig_bin-enc2">Figure 4.3</a> for an example) by referencing their position; external
references allow to reference <i>OpenMath</i> objects in other documents by a URI.</p>

<p>Identifiers [30+64] and [30+64+128] are not used, since they would encode
references that are shared themselves. Chains of references are redundant, and
decrease both space and time efficiency, therefore they are not allowed in the
<i>OpenMath</i> binary encoding.</p>

<p>References consist of the identifier [30] ([30+128] for long references)
followed by a positive integer <m:math><m:mi>n</m:mi></m:math>  coded on one byte (4 bytes for long
references). This integer references the
<m:math><m:mrow><m:mi>n</m:mi><m:mo>+</m:mo><m:mn>1</m:mn></m:mrow></m:math>th shared sub-object (one
where the 
shared flag is set) in the current object (counted in the order they are generated
in the encoding). For example <small><code>Ox7E Ox01</code></small> references the
second shared sub-object. Figure <a href="#fig_bin-enc2">Figure 4.3</a> shows the binary
encoding of the object in figure <a href="#fig_shared_vs_unshared">Figure 4.1</a>
above.</p>


<div class="figure"><a name="fig_bin-enc2" id="fig_bin-enc2"/>
    
<table>
<tr>
<th>Hex </th>
<th>Meaning </th>
<th>Hex </th>
<th>Meaning </th>
</tr>

<tr><td>58</td><td>begin object tag</td>
   <td>05</td><td>variable tag</td></tr>
<tr><td>10</td><td>begin application tag</td>
  <td>01</td><td>variable length</td></tr>
<tr><td>05</td><td>variable tag</td>
  <td>61</td><td>a  (variable name)</td></tr>
<tr><td>01</td><td>variable length</td>
  <td>05</td><td>variable tag</td></tr>
<tr><td>66</td><td>f  (variable name)</td>
  <td>01</td><td>variable length</td></tr>
<tr><td>50</td><td>begin application tag (shared)</td>
  <td>61</td><td>a  (variable name)</td></tr>
<tr><td>05</td><td>variable tag</td>
  <td>11</td><td>end application tag</td></tr>
<tr><td>01</td><td>variable length</td>
  <td>1E</td><td>short reference</td></tr>
<tr><td>66</td><td>f  (variable name)</td>
  <td>00</td><td>to the first shared object</td></tr>
<tr><td>50</td><td>begin application tag (shared)</td>
  <td>11</td><td>end application tag</td></tr>
<tr><td>05</td><td>variable tag</td>
  <td>1E</td><td>short reference</td></tr>
<tr><td>01</td><td>variable length</td>
  <td>00</td><td>to the second shared object</td></tr>
<tr><td>66</td><td>f  (variable name)</td>
  <td>11</td><td>end application tag</td></tr>
<tr><td/><td/><td>19</td><td>end object tag</td></tr>
</table>
<div>
  Figure 4.3 A binary encoding of the <i>OpenMath</i> object from figure <a href="#fig_shared_vs_unshared">Figure 4.1</a>.</div></div>

<p>It is easy to se