  
  [1X2 [5XOpenMath[1X functionality in [5XGAP[1X[0X
  
  
  [1X2.1 Loading the package[0X
  
  The  package is loaded as shown below (possibly loading required packages at
  the same time).
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> LoadPackage("openmath");[0X
    [4X-----------------------------------------------------------------------------[0X
    [4XLoading  openmath 10.0.4 (OpenMath functionality in GAP)[0X
    [4Xby Marco Costantini (costanti@science.unitn.it),[0X
    [4X   Alexander Konovalov (http://www.cs.st-andrews.ac.uk/~alexk/), and[0X
    [4X   Andrew Solomon (http://www.illywhacker.net/).[0X
    [4X-----------------------------------------------------------------------------[0X
    [4Xtrue[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  
  [1X2.2 Viewing [5XOpenMath[1X representation of an object[0X
  
  [1X2.2-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.
  
  [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
    [4Xgap> OMPrint( "This is a string" );[0X
    [4X<OMOBJ>[0X
    [4X	<OMSTR>This is a string</OMSTR>[0X
    [4X</OMOBJ>[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> x:=Indeterminate(Rationals,"x");;[0X
    [4Xgap> OMPrint(x^2+1);    [0X
    [4X<OMOBJ>[0X
    [4X	<OMA>[0X
    [4X		<OMS cd="polyd1" name="DMP"/>[0X
    [4X		<OMR href="#polyringepTkNya5l8qdhAmO" />[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>2</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
    [4Xgap> OMPrint( Group(1,2,3) );[0X
    [4X<OMOBJ>[0X
    [4X	<OMA>[0X
    [4X		<OMS cd="group1" name="group_by_generators"/>[0X
    [4X		<OMA>[0X
    [4X			<OMS cd="permut1" name="permutation"/>[0X
    [4X			<OMI>2</OMI>[0X
    [4X			<OMI>3</OMI>[0X
    [4X			<OMI>1</OMI>[0X
    [4X		</OMA>[0X
    [4X	</OMA>[0X
    [4X</OMOBJ>[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  [1X2.2-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=\"permut1\" name=\"permutation\"/> <OMI>2</OMI> <OMI>1</OMI> </OMA>"[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  
  [1X2.3 Writing and reading [5XOpenMath[1X code to/from streams[0X
  
  [1X2.3-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 function
  requires either that the [5XGAP[0m package [5XGAPDoc[0m is available (for XML [5XOpenMath[0m),
  or  that  the  external  program  [11Xgpipe[0m,  included in this package, has been
  compiled  (for  both  XML and binary [5XOpenMath[0m). This may be used to retrieve
  objects from a file, for example:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> test3:=Filename(DirectoriesPackageLibrary("openmath","tst"),"test3.omt");;[0X
    [4Xgap> stream := InputTextFile( test3 );;[0X
    [4Xgap> OMGetObject(stream);[0X
    [4X912873912381273891[0X
    [4Xgap> OMGetObject(stream);[0X
    [4XE(4)[0X
    [4Xgap> CloseStream(stream);[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  or  it  can  be used to retrieve them from standard input - one may paste an
  [5XOpenMath[0m  object  directly  into  standard  input after issuing GAP with the
  following commands:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> stream := InputTextUser();;[0X
    [4Xgap> g := OMGetObject(stream);CloseStream(stream);[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  [1X2.3-2 OMPutObject[0m
  
  [2X> OMPutObject( [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)).
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> g := [[1,2],[1,0]];;[0X
    [4Xgap> t := "";[0X
    [4X""[0X
    [4Xgap> s := OutputTextString(t, true);;[0X
    [4Xgap> OMPutObject(s, 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-3 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-2[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 OMTest[0m
  
  [2X> OMTest( [0X[3Xobj[0X[2X ) ____________________________________________________[0Xfunction
  
  Converts  [3Xobj[0m  to [5XOpenMath[0m and back. Returns true iff [3Xobj[0m is unchanged (as a
  GAP 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> OMTest( [ [1..10],[1/2,2+E(4)], ZmodnZObj(2,6), (1,2), true, "string" ] );     [0X
    [4Xtrue[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
