  
  [1X2 [5XOpenMath[1X functionality in [5XGAP[1X[0X
  
  
  [1X2.1 Viewing [5XOpenMath[1X representation of an object[0X
  
  [1X2.1-1 OMPrint[0m
  
  [2X> OMPrint( [0X[3Xobj[0X[2X ) ___________________________________________________[0Xfunction
  
  OMPrint  writes  the  default XML [5XOpenMath[0m encoding of [5XGAP[0m object [3Xobj[0m to the
  standard output.
  
  One can try it with different [5XGAP[0m objects to see if they can be converted to
  [5XOpenMath[0m  and  learn  how  their [5XOpenMath[0m representation looks like. Here we
  show the encoding for lists of integers and rationals:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> OMPrint( [ 1, 1/2 ] );     [0X
    [4X<OMOBJ>[0X
    [4X	<OMA>[0X
    [4X		<OMS cd="list1" name="list"/>[0X
    [4X		<OMI>1</OMI>[0X
    [4X		<OMA>[0X
    [4X			<OMS cd="nums1" name="rational"/>[0X
    [4X			<OMI>1</OMI>[0X
    [4X			<OMI>2</OMI>[0X
    [4X		</OMA>[0X
    [4X	</OMA>[0X
    [4X</OMOBJ>[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Strings are encoded using [10X<OMSTR>[0m tags:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> OMPrint( "This is a string" );[0X
    [4X<OMOBJ>[0X
    [4X	<OMSTR>This is a string</OMSTR>[0X
    [4X</OMOBJ>[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Cyclotomics   may   be  encoded  in  different  ways  dependently  on  their
  properties:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> OMPrint( 1-2*E(4) );      [0X
    [4X<OMOBJ>[0X
    [4X	<OMA>[0X
    [4X		<OMS cd="complex1" name="complex_cartesian"/>[0X
    [4X		<OMI>1</OMI>[0X
    [4X		<OMI>-2</OMI>[0X
    [4X	</OMA>[0X
    [4X</OMOBJ>[0X
    [4Xgap> OMPrint(E(3));       [0X
    [4X<OMOBJ>[0X
    [4X	<OMA>[0X
    [4X		<OMS cd="arith1" name="plus"/>[0X
    [4X		<OMA>[0X
    [4X			<OMS cd="arith1" name="times"/>[0X
    [4X			<OMI>1</OMI>[0X
    [4X			<OMA>[0X
    [4X				<OMS cd="algnums" name="NthRootOfUnity"/>[0X
    [4X				<OMI>3</OMI>[0X
    [4X				<OMI>1</OMI>[0X
    [4X			</OMA>[0X
    [4X		</OMA>[0X
    [4X	</OMA>[0X
    [4X</OMOBJ>[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Various encodings may be used for various types of groups:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> OMPrint( Group( (1,2) ) );[0X
    [4X<OMOBJ>[0X
    [4X	<OMA>[0X
    [4X		<OMS cd="permgp1" name="group"/>[0X
    [4X		<OMS cd="permutation1" name="right_compose"/>[0X
    [4X		<OMA>[0X
    [4X			<OMS cd="permut1" name="permutation"/>[0X
    [4X			<OMI>2</OMI>[0X
    [4X			<OMI>1</OMI>[0X
    [4X		</OMA>[0X
    [4X	</OMA>[0X
    [4X</OMOBJ>[0X
    [4Xgap> OMPrint( Group( [ [ [ 1, 2 ],[ 0, 1 ] ] ] ) );[0X
    [4X<OMOBJ>[0X
    [4X	<OMA>[0X
    [4X		<OMS cd="group1" name="group_by_generators"/>[0X
    [4X		<OMA>[0X
    [4X			<OMS cd="linalg2" name="matrix"/>[0X
    [4X			<OMA>[0X
    [4X				<OMS cd="linalg2" name="matrixrow"/>[0X
    [4X				<OMI>1</OMI>[0X
    [4X				<OMI>2</OMI>[0X
    [4X			</OMA>[0X
    [4X			<OMA>[0X
    [4X				<OMS cd="linalg2" name="matrixrow"/>[0X
    [4X				<OMI>0</OMI>[0X
    [4X				<OMI>1</OMI>[0X
    [4X			</OMA>[0X
    [4X		</OMA>[0X
    [4X	</OMA>[0X
    [4X</OMOBJ>[0X
    [4Xgap> OMPrint( FreeGroup( 2 ) );                      [0X
    [4X<OMOBJ>[0X
    [4X	<OMA>[0X
    [4X		<OMS cd="fpgroup1" name="free_groupn"/>[0X
    [4X		<OMI>2</OMI>[0X
    [4X	</OMA>[0X
    [4X</OMOBJ>[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Producing [5XOpenMath[0m representation of polynomials, one may get a warning:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> x:=Indeterminate(Rationals,"x");; y:=Indeterminate(Rationals,"y");;[0X
    [4Xgap> OMPrint(x^2+y);[0X
    [4X#I  Warning : polynomial will be printed using its default ring [0X
    [4X#I  because the default OpenMath polynomial ring is not specified [0X
    [4X#I  or it is not contained in the default OpenMath polynomial ring.[0X
    [4X#I  You may ignore this or call SetOpenMathDefaultPolynomialRing to fix it.[0X
    [4X<OMOBJ>[0X
    [4X	<OMA>[0X
    [4X		<OMS cd="polyd1" name="DMP"/>[0X
    [4X		<OMA id="polyring9qiY2oOaiITWUORb" >[0X
    [4X			<OMS cd="polyd1" name="poly_ring_d"/>[0X
    [4X			<OMS cd="setname1" name="Q"/>[0X
    [4X			<OMI>2</OMI>[0X
    [4X		</OMA>[0X
    [4X		<OMA>[0X
    [4X			<OMS cd="polyd1" name="SDMP"/>[0X
    [4X			<OMA>[0X
    [4X				<OMS cd="polyd1" name="term"/>[0X
    [4X				<OMI>1</OMI>[0X
    [4X				<OMI>0</OMI>[0X
    [4X				<OMI>1</OMI>[0X
    [4X			</OMA>[0X
    [4X			<OMA>[0X
    [4X				<OMS cd="polyd1" name="term"/>[0X
    [4X				<OMI>1</OMI>[0X
    [4X				<OMI>2</OMI>[0X
    [4X				<OMI>0</OMI>[0X
    [4X			</OMA>[0X
    [4X		</OMA>[0X
    [4X	</OMA>[0X
    [4X</OMOBJ>[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Indeed,  now  when  another  polynomial will be printed, it will belong to a
  ring  with  a  different  identifier  (despite  [5XGAP[0m  will be able to perform
  arithmetical  operations  on  these polynomials like when they belong to the
  same ground ring):
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> OMPrint(x+1);[0X
    [4X#I  Warning : polynomial will be printed using its default ring [0X
    [4X#I  because the default OpenMath polynomial ring is not specified [0X
    [4X#I  or it is not contained in the default OpenMath polynomial ring.[0X
    [4X#I  You may ignore this or call SetOpenMathDefaultPolynomialRing to fix it.[0X
    [4X<OMOBJ>[0X
    [4X	<OMA>[0X
    [4X		<OMS cd="polyd1" name="DMP"/>[0X
    [4X		<OMA id="polyring0LqlkhnCyLldcoBl" >[0X
    [4X			<OMS cd="polyd1" name="poly_ring_d_named"/>[0X
    [4X			<OMS cd="setname1" name="Q"/>[0X
    [4X			<OMV name="x"/>[0X
    [4X		</OMA>[0X
    [4X		<OMA>[0X
    [4X			<OMS cd="polyd1" name="SDMP"/>[0X
    [4X			<OMA>[0X
    [4X				<OMS cd="polyd1" name="term"/>[0X
    [4X				<OMI>1</OMI>[0X
    [4X				<OMI>1</OMI>[0X
    [4X			</OMA>[0X
    [4X			<OMA>[0X
    [4X				<OMS cd="polyd1" name="term"/>[0X
    [4X				<OMI>1</OMI>[0X
    [4X				<OMI>0</OMI>[0X
    [4X			</OMA>[0X
    [4X		</OMA>[0X
    [4X	</OMA>[0X
    [4X</OMOBJ>[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Thus,  the  warning means that it is not guaranteed that the polynomial ring
  will  have  the same identifier [10X<OMA id="polyring..." >[0m when another or same
  polynomial  from this ring will be printed next time. If this may constitute
  a  problem,  for  example,  if  a list of polynomial is being exchanged with
  another  system  and  it is crucial that all of them will belong to the same
  ring,    then    such   ring   must   be   created   explicitly   and   then
  [10XSetOpenMathDefaultPolynomialRing[0m must be called:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> x:=Indeterminate(Rationals,"x");; y:=Indeterminate(Rationals,"y");;[0X
    [4Xgap> R:=PolynomialRing(Rationals,[x,y]);;[0X
    [4Xgap> SetOpenMathDefaultPolynomialRing(R);[0X
    [4Xgap> OMPrint(x^2+y);[0X
    [4X<OMOBJ>[0X
    [4X	<OMA>[0X
    [4X		<OMS cd="polyd1" name="DMP"/>[0X
    [4X		<OMA id="polyring9eNcBGFHXkjl2kWh" >[0X
    [4X			<OMS cd="polyd1" name="poly_ring_d"/>[0X
    [4X			<OMS cd="setname1" name="Q"/>[0X
    [4X			<OMI>2</OMI>[0X
    [4X		</OMA>[0X
    [4X		<OMA>[0X
    [4X			<OMS cd="polyd1" name="SDMP"/>[0X
    [4X			<OMA>[0X
    [4X				<OMS cd="polyd1" name="term"/>[0X
    [4X				<OMI>1</OMI>[0X
    [4X				<OMI>0</OMI>[0X
    [4X				<OMI>0</OMI>[0X
    [4X			</OMA>[0X
    [4X			<OMA>[0X
    [4X				<OMS cd="polyd1" name="term"/>[0X
    [4X				<OMI>1</OMI>[0X
    [4X				<OMI>0</OMI>[0X
    [4X				<OMI>0</OMI>[0X
    [4X			</OMA>[0X
    [4X		</OMA>[0X
    [4X	</OMA>[0X
    [4X</OMOBJ>[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Now  we  can  see  that  both  polynomials  belong to the ring with the same
  identifier,  and  the [5XOpenMath[0m representation of the 2nd polynomial properly
  reflects that it belongs to a polynomial ring with two variables.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> OMPrint(x+1);  [0X
    [4X<OMOBJ>[0X
    [4X	<OMA>[0X
    [4X		<OMS cd="polyd1" name="DMP"/>[0X
    [4X		<OMR href="#polyring9eNcBGFHXkjl2kWh" />[0X
    [4X		<OMA>[0X
    [4X			<OMS cd="polyd1" name="SDMP"/>[0X
    [4X			<OMA>[0X
    [4X				<OMS cd="polyd1" name="term"/>[0X
    [4X				<OMI>1</OMI>[0X
    [4X				<OMI>0</OMI>[0X
    [4X				<OMI>0</OMI>[0X
    [4X			</OMA>[0X
    [4X			<OMA>[0X
    [4X				<OMS cd="polyd1" name="term"/>[0X
    [4X				<OMI>1</OMI>[0X
    [4X				<OMI>0</OMI>[0X
    [4X				<OMI>0</OMI>[0X
    [4X			</OMA>[0X
    [4X		</OMA>[0X
    [4X	</OMA>[0X
    [4X</OMOBJ> [0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  [1X2.1-2 OMString[0m
  
  [2X> OMString( [0X[3Xobj[0X[2X ) __________________________________________________[0Xfunction
  
  OMString  returns  a  string  with  the default XML [5XOpenMath[0m encoding of [5XGAP[0m
  object  [3Xobj[0m. If used with the [9Xnoomobj[0m option, then initial and final <OMOBJ>
  tags will be omitted.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> OMString(42);[0X
    [4X"<OMOBJ> <OMI>42</OMI> </OMOBJ>"[0X
    [4Xgap> OMString([1,2]:noomobj);    [0X
    [4X"<OMA> <OMS cd=\"list1\" name=\"list\"/> <OMI>1</OMI> <OMI>2</OMI> </OMA>"[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  
  [1X2.2 Reading [5XOpenMath[1X code from streams[0X
  
  [1X2.2-1 OMGetObject[0m
  
  [2X> OMGetObject( [0X[3Xstream[0X[2X ) ____________________________________________[0Xfunction
  
  [3Xstream[0m  is  an  input  stream (see [2XInputTextFile[0m ([14XReference: InputTextFile[0m),
  [2XInputTextUser[0m   ([14XReference:   InputTextUser[0m),   [2XInputTextString[0m  ([14XReference:
  InputTextString[0m),             [2XInputOutputLocalProcess[0m            ([14XReference:
  InputOutputLocalProcess[0m),  [2XInputOutputTCPStream[0m ([14XSCSCP: InputOutputTCPStream
  (for   client)[0m),   [2XInputOutputTCPStream[0m  ([14XSCSCP:  InputOutputTCPStream  (for
  server)[0m))  with  an  [5XOpenMath[0m  object on it. [2XOMGetObject[0m takes precisely one
  object  off  [3Xstream[0m  and  returns  it  as  a GAP object. Both XML and binary
  [5XOpenMath[0m encoding are supported: autodetection is used.
  
  This  may  be used to retrieve objects from a file. In the following example
  we  demonsrate  reading the same content in binary and XML formats using the
  test files supplied with the package (the package autodetects whether binary
  or XML encoding is used):
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> txml:=Filename(DirectoriesPackageLibrary("openmath","tst"),"test3.omt");;   [0X
    [4Xgap> tbin:=Filename(DirectoriesPackageLibrary("openmath","tst"),"test3.bin");;   [0X
    [4Xgap> xstream := InputTextFile( txml );; bstream := InputTextFile( tbin );;   [0X
    [4Xgap> x:=OMGetObject(xstream); y:=OMGetObject(bstream);[0X
    [4X912873912381273891[0X
    [4X912873912381273891[0X
    [4Xgap> x:=OMGetObject(xstream); y:=OMGetObject(bstream);[0X
    [4XE(4)[0X
    [4XE(4)[0X
    [4Xgap> CloseStream(xstream);CloseStream(bstream);[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  To  paste  an  [5XOpenMath[0m  object  directly  into  standard  input execute the
  following command in GAP:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> s:= InputTextUser();; g := OMGetObject(s); CloseStream(s);[0X
    [4Xgap> [0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  For  XML  [5XOpenMath[0m,  this  function  requires that the [5XGAP[0m package [5XGAPDoc[0m is
  available.
  
  
  [1X2.3 Writing [5XOpenMath[1X code to streams[0X
  
  While  it  is possible to read [5XOpenMath[0m code directly from a stream, writing
  [5XOpenMath[0m  to  streams  uses  a  different setup. It requires special objects
  called  [5XOpenMath[0m  [13Xwriters[0m,  which  encapsulate  streams and may be viewed as
  transducers accepting [5XGAP[0m objects and writing them to a stream in the XML or
  binary [5XOpenMath[0m
  
  Such  setup  makes it possible to re-use the same stream for both binary and
  XML  [5XOpenMath[0m  communication,  using different [5XOpenMath[0m writers in different
  calls.  It  also  allows  to  re-use  most of the high-level code for [5XGAP[0m to
  [5XOpenMath[0m  conversion,  having separate methods for generating binary and XML
  [5XOpenMath[0m  only  for low-level output ([5XOpenMath[0m tags and basic objects). This
  makes  easier adding support to new mathematical objects and private content
  dictionaries  as  described  in Chapter [14X3[0m since it does not require changing
  the low-level functionality.
  
  [1X2.3-1 IsOpenMathWriter[0m
  
  [2X> IsOpenMathWriter__________________________________________________[0XCategory
  [2X> IsOpenMathXMLWriter_______________________________________________[0XCategory
  [2X> IsOpenMathBinaryWriter____________________________________________[0XCategory
  
  [2XIsOpenMathWriter[0mis   a   category   for   [5XOpenMath[0m   writers.   It  has  two
  subcategories: [2XIsOpenMathXMLWriter[0m and [2XIsOpenMathBinaryWriter[0m.
  
  [1X2.3-2 OpenMathXMLWriter[0m
  
  [2X> OpenMathXMLWriter( [0X[3Xs[0X[2X ) ___________________________________________[0Xfunction
  
  for  a  stream  [3Xs[0m,  returns  an  object  in the category [2XIsOpenMathXMLWriter[0m
  ([14X2.3-1[0m).
  
  [1X2.3-3 OpenMathBinaryWriter[0m
  
  [2X> OpenMathBinaryWriter( [0X[3Xs[0X[2X ) ________________________________________[0Xfunction
  
  for a stream [3Xs[0m, returns an object in the category [2XOpenMathBinaryWriter[0m.
  
  [1X2.3-4 OMPutObject[0m
  
  [2X> OMPutObject( [0X[3Xstream, obj[0X[2X ) _______________________________________[0Xfunction
  [2X> OMPutObjectNoOMOBJtags( [0X[3Xstream, obj[0X[2X ) ____________________________[0Xfunction
  
  [2XOMPutObject[0m writes (appends) the XML [5XOpenMath[0m encoding of the [5XGAP[0m object [3Xobj[0m
  to  output  stream  [3Xstream[0m  (see  [2XInputTextFile[0m  ([14XReference: InputTextFile[0m),
  [2XOutputTextUser[0m  ([14XReference:  OutputTextUser[0m),  [2XOutputTextString[0m  ([14XReference:
  OutputTextString[0m),  [2XInputOutputTCPStream[0m  ([14XSCSCP:  InputOutputTCPStream (for
  client)[0m), [2XInputOutputTCPStream[0m ([14XSCSCP: InputOutputTCPStream (for server)[0m)).
  
  The  second  version  does  the  same  but without <OMOBJ> tags, what may be
  useful for assembling complex [5XOpenMath[0m objects.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> g := [[1,2],[1,0]];;[0X
    [4Xgap> t := "";[0X
    [4X""[0X
    [4Xgap> s := OutputTextString(t, true);;[0X
    [4Xgap> w:=OpenMathXMLWriter( s );[0X
    [4X<OpenMath XML writer to OutputTextString(0)>[0X
    [4Xgap> OMPutObject(w, g);[0X
    [4Xgap> CloseStream(s);[0X
    [4Xgap> Print(t);[0X
    [4X<OMOBJ>[0X
    [4X	<OMA>[0X
    [4X		<OMS cd="linalg2" name="matrix"/>[0X
    [4X		<OMA>[0X
    [4X			<OMS cd="linalg2" name="matrixrow"/>[0X
    [4X			<OMI>1</OMI>[0X
    [4X			<OMI>2</OMI>[0X
    [4X		</OMA>[0X
    [4X		<OMA>[0X
    [4X			<OMS cd="linalg2" name="matrixrow"/>[0X
    [4X			<OMI>1</OMI>[0X
    [4X			<OMI>0</OMI>[0X
    [4X		</OMA>[0X
    [4X	</OMA>[0X
    [4X</OMOBJ>[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  [1X2.3-5 OMPlainString[0m
  
  [2X> OMPlainString( [0X[3Xstring[0X[2X ) __________________________________________[0Xfunction
  
  [2XOMPlainString[0m wraps the string into a [5XGAP[0m object of a special kind called an
  [5XOpenMath[0m  plain  string.  Internally such object is represented as a string,
  but  [2XOMPutObject[0m ([14X2.3-4[0m) threat it in a different way: instead of converting
  it  into  a  <OMSTR>  object,  an  [5XOpenMath[0m  plain  string  will  be plainly
  substituted  into  the output (this explains its name) without decorating it
  with <OMSTR> tags.
  
  It  is  assumed  that [5XOpenMath[0m plain string contains valid [5XOpenMath[0m code; no
  actual  validation  is performed during its creation. Such functionality may
  be  useful  to compose some [5XOpenMath[0m code at the [5XGAP[0m level to communicate it
  to  the  other  system,  in  particular, to send there symbols which are not
  supported by [5XGAP[0m, for example:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> s:=OMPlainString("<OMS cd=\"nums1\" name=\"pi\"/>");[0X
    [4X<OMS cd="nums1" name="pi"/>[0X
    [4Xgap> OMPrint(s);                                       [0X
    [4X<OMOBJ>[0X
    [4X	<OMS cd="nums1" name="pi"/>[0X
    [4X</OMOBJ>[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  
  [1X2.4 Utilities[0X
  
  [1X2.4-1 OMTestXML[0m
  
  [2X> OMTestXML( [0X[3Xobj[0X[2X ) _________________________________________________[0Xfunction
  [2X> OMTest( [0X[3Xobj[0X[2X ) ____________________________________________________[0Xfunction
  
  Converts  [3Xobj[0m  to  XML [5XOpenMath[0m and back. Returns true if and only if [3Xobj[0m is
  unchanged  (as  a  [5XGAP[0m object) by this operation. The [5XOpenMath[0m standard does
  not  stipulate  that  converting to and from [5XOpenMath[0m should be the identity
  function so this is a useful diagnostic tool.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> OMTestXML([[1..10],[1/2,2+E(4)],ZmodnZObj(2,6),(1,2),true,"string"]);     [0X
    [4Xtrue[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  [2XOMTest[0m is a synonym to [2XOMTestXML[0m
  
  [1X2.4-2 OMTestBinary[0m
  
  [2X> OMTestBinary( [0X[3Xobj[0X[2X ) ______________________________________________[0Xfunction
  
  Converts [3Xobj[0m to binary [5XOpenMath[0m and back. Returns true if and only if [3Xobj[0m is
  unchanged  (as  a  [5XGAP[0m object) by this operation. The [5XOpenMath[0m standard does
  not  stipulate  that  converting to and from [5XOpenMath[0m should be the identity
  function so this is a useful diagnostic tool.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> OMTestBinary([[1..10],[1/2,2+E(4)],ZmodnZObj(2,6),(1,2),true,"string"]);     [0X
    [4Xtrue[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
