Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 5e1854624d3bc613bdd0dd13d1ef9ac7 > files > 2515

gap-system-4.4.12-5mdv2010.0.i586.rpm

<html><head><title>[openmath.htm] 1 OpenMath functionality in GAP</title></head>
<body text="#000000" bgcolor="#ffffff">
[<a href = "chapters.htm">Up</a>] [<a href = "theindex.htm">Index</a>]
<h1>1 OpenMath functionality in GAP</h1><p>
<p>
After loading the package:
<pre>
gap&gt; LoadPackage( "openmath" );
true
</pre>
the following operations are available.
<p>
<li><code>OMPrint( </code><var>obj</var><code> ) F</code>
<p>
OMPrint writes the XML OpenMath encoding of GAP object <var>obj</var> 
to the standard output.
<p>
<pre>
gap&gt; g := Group((1,2,3));;
gap&gt; OMPrint(g);
&lt;OMOBJ&gt;
	&lt;OMA&gt;
		&lt;OMS cd="group1" name="Group"/&gt;
		&lt;OMA&gt;
			&lt;OMS cd="permut1" name="Permutation"/&gt;
			&lt;OMI&gt; 2&lt;/OMI&gt;
			&lt;OMI&gt; 3&lt;/OMI&gt;
			&lt;OMI&gt; 1&lt;/OMI&gt;
		&lt;/OMA&gt;
	&lt;/OMA&gt;
&lt;/OMOBJ&gt;
</pre>
<p>
<li><code>OMGetObject( </code><var>stream</var><code> ) F</code>
<p>
<var>stream</var> is an input stream (see <a href="../../../doc/htm/ref/CHAP010.htm#SSEC005.1"> InputTextFile</a>, <a href="../../../doc/htm/ref/CHAP010.htm#SSEC006.1"> InputTextUser</a>, <a href="../../../doc/htm/ref/CHAP010.htm#SSEC007.1"> InputTextString</a>, 
<a href="../../../doc/htm/ref/CHAP010.htm#SSEC008.2"> InputOutputLocalProcess</a> ) with an OpenMath object on it.
OMGetObject takes precisely one object off <var>stream</var> 
and returns it as a GAP object.
Both XML and binary OpenMath encoding are supported, autodetection
is used.
This function requires that the external program <code>gpipe</code>, included
in this package, has been compiled.
<p>
This may be used to retrieve objects from a file,
for example:
<pre>
gap&gt; test3:=Filename(DirectoriesPackageLibrary("openmath","tst"),"test3.omt");;
gap&gt; stream := InputTextFile( test3 );;
gap&gt; OMGetObject(stream);
912873912381273891
gap&gt; OMGetObject(stream);
E(4)
gap&gt; CloseStream(stream);
</pre>
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:
<pre>
gap&gt; stream := InputTextUser();;
gap&gt; g := OMGetObject(stream);CloseStream(stream);
</pre>
<p>
<li><code>OMPutObject( </code><var>stream</var><code>, </code><var>obj</var><code> ) F</code>
<p>
OMPutObject writes (appends) the XML OpenMath encoding of the GAP
object <var>obj</var> to output stream <var>stream</var> (see <a href="../../../doc/htm/ref/CHAP010.htm#SSEC005.2"> OutputTextFile</a>,
<a href="../../../doc/htm/ref/CHAP010.htm#SSEC006.2"> OutputTextUser</a>, <a href="../../../doc/htm/ref/CHAP010.htm#SSEC007.2"> OutputTextString</a>,
<a href="../../../doc/htm/ref/CHAP010.htm#SSEC008.2"> InputOutputLocalProcess</a> ).
<p>
<pre>
gap&gt; g := [[1,2],[1,0]];;
gap&gt; t := "";
""
gap&gt; s := OutputTextString(t, true);;
gap&gt; OMPutObject(s, g);
gap&gt; CloseStream(s);
gap&gt; Print(t);
&lt;OMOBJ&gt;
	&lt;OMA&gt;
		&lt;OMS cd="linalg2" name="matrix"/&gt;
		&lt;OMA&gt;
			&lt;OMS cd="linalg2" name="matrixrow"/&gt;
			&lt;OMI&gt; 1&lt;/OMI&gt;
			&lt;OMI&gt; 2&lt;/OMI&gt;
		&lt;/OMA&gt;
		&lt;OMA&gt;
			&lt;OMS cd="linalg2" name="matrixrow"/&gt;
			&lt;OMI&gt; 1&lt;/OMI&gt;
			&lt;OMI&gt; 0&lt;/OMI&gt;
		&lt;/OMA&gt;
	&lt;/OMA&gt;
&lt;/OMOBJ&gt;
</pre>
<p>
<li><code>OMTest( </code><var>obj</var><code> ) F</code>
<p>
Converts <var>obj</var> to OpenMath and back. Returns true iff <var>obj</var> 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.
<p>
<p>
[<a href = "chapters.htm">Up</a>] [<a href = "theindex.htm">Index</a>]
<P>
<address>openmath.htm manual<br>marzo 2006
</address></body></html>