Goto Chapter: Top 1 2 3 Bib Ind
Top of Book Previous Chapter Next Chapter

2 OpenMath functionality in GAP
2.1 Loading the package
2.2 Viewing OpenMath representation of an object
2.2-1 OMPrint
2.2-2 OMString
2.3 Writing and reading OpenMath code to/from streams
2.3-1 OMGetObject
2.3-2 OMPutObject
2.3-3 OMPlainString
2.4 Utilities
2.4-1 OMTest

### 2 OpenMath functionality in GAP

#### 2.1 Loading the package

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

    gap> LoadPackage("openmath");
    -----------------------------------------------------------------------------
    Loading  openmath 10.0.4 (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

#### 2.2 Viewing OpenMath representation of an object

##### 2.2-1 OMPrint

`> OMPrint`( obj ) | ( function )

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>

##### 2.2-2 OMString

`> OMString`( obj ) | ( function )

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>"

#### 2.3 Writing and reading OpenMath code to/from streams

##### 2.3-1 OMGetObject

`> OMGetObject`( stream ) | ( function )

stream is an input stream (see `InputTextFile` (Reference: InputTextFile), `InputTextUser` (Reference: InputTextUser), `InputTextString` (Reference: InputTextString), `InputOutputLocalProcess` (Reference: InputOutputLocalProcess), `InputOutputTCPStream` (SCSCP: InputOutputTCPStream (for client)), `InputOutputTCPStream` (SCSCP: InputOutputTCPStream (for server))) with an OpenMath object on it. `OMGetObject` 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);

##### 2.3-2 OMPutObject

`> OMPutObject`( stream, obj ) | ( function )

`OMPutObject` writes (appends) the XML OpenMath encoding of the GAP object obj to output stream stream (see `InputTextFile` (Reference: InputTextFile), `OutputTextUser` (Reference: OutputTextUser), `OutputTextString` (Reference: OutputTextString), `InputOutputTCPStream` (SCSCP: InputOutputTCPStream (for client)), `InputOutputTCPStream` (SCSCP: InputOutputTCPStream (for server))).

    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>

##### 2.3-3 OMPlainString

`> OMPlainString`( string ) | ( function )

`OMPlainString` 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 `OMPutObject` (2.3-2) 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>

#### 2.4 Utilities

##### 2.4-1 OMTest

`> OMTest`( obj ) | ( function )

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

Top of Book Previous Chapter Next Chapter
Goto Chapter: Top 1 2 3 Bib Ind

generated by GAPDoc2HTML