&OpenMath; functionality in &GAP;
Loading the package

The package is loaded as shown below (possibly loading required packages at the same time).

gap> LoadPackage("openmath"); ----------------------------------------------------------------------------- Loading openmath 10.1.0 (OpenMath functionality in GAP) by Marco Costantini (costanti@science.unitn.it), Alexander Konovalov (http://www.cs.st-andrews.ac.uk/~alexk/), and Andrew Solomon (http://www.illywhacker.net/). ----------------------------------------------------------------------------- true
Viewing &OpenMath; representation of an object
OMPrint writes the default XML &OpenMath; encoding of &GAP; object obj to the standard output. gap> OMPrint( [ 1, 1/2 ] ); <OMOBJ> <OMA> <OMS cd="list1" name="list"/> <OMI>1</OMI> <OMA> <OMS cd="nums1" name="rational"/> <OMI>1</OMI> <OMI>2</OMI> </OMA> </OMA> </OMOBJ> gap> OMPrint( "This is a string" ); <OMOBJ> <OMSTR>This is a string</OMSTR> </OMOBJ> gap> OMPrint( 1-2*E(4) ); <OMOBJ> <OMA> <OMS cd="complex1" name="complex_cartesian"/> <OMI>1</OMI> <OMI>-2</OMI> </OMA> </OMOBJ> gap> x:=Indeterminate(Rationals,"x");; gap> OMPrint(x^2+1); <OMOBJ> <OMA> <OMS cd="polyd1" name="DMP"/> <OMR href="#polyringepTkNya5l8qdhAmO" /> <OMA> <OMS cd="polyd1" name="SDMP"/> <OMA> <OMS cd="polyd1" name="term"/> <OMI>1</OMI> <OMI>2</OMI> </OMA> <OMA> <OMS cd="polyd1" name="term"/> <OMI>1</OMI> <OMI>0</OMI> </OMA> </OMA> </OMA> </OMOBJ> gap> OMPrint( Group(1,2,3) ); <OMOBJ> <OMA> <OMS cd="group1" name="group_by_generators"/> <OMA> <OMS cd="permut1" name="permutation"/> <OMI>2</OMI> <OMI>3</OMI> <OMI>1</OMI> </OMA> </OMA> </OMOBJ>
OMString returns a string with the default XML &OpenMath; encoding of &GAP; object obj. If used with the noomobj option, then initial and final <OMOBJ> tags will be omitted. gap> OMString(42); "<OMOBJ> <OMI>42</OMI> </OMOBJ>" gap> OMString((1,2):noomobj); "<OMA> <OMS cd=\"permut1\" name=\"permutation\"/> <OMI>2</OMI> <OMI>1</OMI> </OMA>"
Writing and reading &OpenMath; code to/from streams
stream is an input stream (see , , , , , ) with an &OpenMath; object on it. takes precisely one object off stream and returns it as a GAP object. Both XML and binary &OpenMath; encoding are supported: autodetection is used. This function requires either that the &GAP; package &GAPDoc; is available (for XML &OpenMath;), or that the external program gpipe, included in this package, has been compiled (for both XML and binary &OpenMath;).

This may be used to retrieve objects from a file, for example:

gap> test3:=Filename(DirectoriesPackageLibrary("openmath","tst"),"test3.omt");; gap> stream := InputTextFile( test3 );; gap> OMGetObject(stream); 912873912381273891 gap> OMGetObject(stream); E(4) gap> CloseStream(stream);

or it can be used to retrieve them from standard input - one may paste an &OpenMath; object directly into standard input after issuing GAP with the following commands:

gap> stream := InputTextUser();; gap> g := OMGetObject(stream);CloseStream(stream);
writes (appends) the XML &OpenMath; encoding of the &GAP; object obj to output stream stream (see , , , , ).

gap> g := [[1,2],[1,0]];; gap> t := ""; "" gap> s := OutputTextString(t, true);; gap> OMPutObject(s, g); gap> CloseStream(s); gap> Print(t); <OMOBJ> <OMA> <OMS cd="linalg2" name="matrix"/> <OMA> <OMS cd="linalg2" name="matrixrow"/> <OMI>1</OMI> <OMI>2</OMI> </OMA> <OMA> <OMS cd="linalg2" name="matrixrow"/> <OMI>1</OMI> <OMI>0</OMI> </OMA> </OMA> </OMOBJ>
wraps the string into a &GAP; object of a special kind called an &OpenMath; plain string. Internally such object is represented as a string, but threat it in a different way: instead of converting it into a <OMSTR> object, an &OpenMath; plain string will be plainly substituted into the output (this explains its name) without decorating it with <OMSTR> tags.

It is assumed that &OpenMath; plain string contains valid &OpenMath; code; no actual validation is performed during its creation. Such functionality may be useful to compose some &OpenMath; code at the &GAP; level to communicate it to the other system, in particular, to send there symbols which are not supported by &GAP;, for example:

gap> s:=OMPlainString("<OMS cd=\"nums1\" name=\"pi\"/>"); <OMS cd="nums1" name="pi"/> gap> OMPrint(s); <OMOBJ> <OMS cd="nums1" name="pi"/> </OMOBJ>
Utilities
Converts obj to &OpenMath; and back. Returns true iff obj is unchanged (as a GAP object) by this operation. The &OpenMath; standard does not stipulate that converting to and from &OpenMath; should be the identity function so this is a useful diagnostic tool.

gap> OMTest( [ [1..10],[1/2,2+E(4)], ZmodnZObj(2,6), (1,2), true, "string" ] ); true