% generated by GAPDoc2LaTeX from XML source (Frank Luebeck)
\documentclass[a4paper,11pt]{report}

\usepackage{a4wide}
\sloppy
\pagestyle{myheadings}
\usepackage{amssymb}
\usepackage[latin1]{inputenc}
\usepackage{makeidx}
\makeindex
\usepackage{color}
\definecolor{FireBrick}{rgb}{0.5812,0.0074,0.0083}
\definecolor{RoyalBlue}{rgb}{0.0236,0.0894,0.6179}
\definecolor{RoyalGreen}{rgb}{0.0236,0.6179,0.0894}
\definecolor{RoyalRed}{rgb}{0.6179,0.0236,0.0894}
\definecolor{LightBlue}{rgb}{0.8544,0.9511,1.0000}
\definecolor{Black}{rgb}{0.0,0.0,0.0}

\definecolor{linkColor}{rgb}{0.0,0.0,0.554}
\definecolor{citeColor}{rgb}{0.0,0.0,0.554}
\definecolor{fileColor}{rgb}{0.0,0.0,0.554}
\definecolor{urlColor}{rgb}{0.0,0.0,0.554}
\definecolor{promptColor}{rgb}{0.0,0.0,0.589}
\definecolor{brkpromptColor}{rgb}{0.589,0.0,0.0}
\definecolor{gapinputColor}{rgb}{0.589,0.0,0.0}
\definecolor{gapoutputColor}{rgb}{0.0,0.0,0.0}

%%  for a long time these were red and blue by default,
%%  now black, but keep variables to overwrite
\definecolor{FuncColor}{rgb}{0.0,0.0,0.0}
%% strange name because of pdflatex bug:
\definecolor{Chapter }{rgb}{0.0,0.0,0.0}
\definecolor{DarkOlive}{rgb}{0.1047,0.2412,0.0064}


\usepackage{fancyvrb}

\usepackage{mathptmx,helvet}
\usepackage[T1]{fontenc}
\usepackage{textcomp}


\usepackage[
            pdftex=true,
            bookmarks=true,        
            a4paper=true,
            pdftitle={Written with GAPDoc},
            pdfcreator={LaTeX with hyperref package / GAPDoc},
            colorlinks=true,
            backref=page,
            breaklinks=true,
            linkcolor=linkColor,
            citecolor=citeColor,
            filecolor=fileColor,
            urlcolor=urlColor,
            pdfpagemode={UseNone}, 
           ]{hyperref}

\newcommand{\maintitlesize}{\fontsize{50}{55}\selectfont}

% write page numbers to a .pnr log file for online help
\newwrite\pagenrlog
\immediate\openout\pagenrlog =\jobname.pnr
\immediate\write\pagenrlog{PAGENRS := [}
\newcommand{\logpage}[1]{\protect\write\pagenrlog{#1, \thepage,}}
%% were never documented, give conflicts with some additional packages

\newcommand{\GAP}{\textsf{GAP}}

%% nicer description environments, allows long labels
\usepackage{enumitem}
\setdescription{style=nextline}

%% depth of toc
\setcounter{tocdepth}{1}





%% command for ColorPrompt style examples
\newcommand{\gapprompt}[1]{\color{promptColor}{\bfseries #1}}
\newcommand{\gapbrkprompt}[1]{\color{brkpromptColor}{\bfseries #1}}
\newcommand{\gapinput}[1]{\color{gapinputColor}{#1}}


\begin{document}

\logpage{[ 0, 0, 0 ]}
\begin{titlepage}
\mbox{}\vfill

\begin{center}{\maintitlesize \textbf{\textsf{OpenMath}\mbox{}}}\\
\vfill

\hypersetup{pdftitle=\textsf{OpenMath}}
\markright{\scriptsize \mbox{}\hfill \textsf{OpenMath} \hfill\mbox{}}
{\Huge \textbf{\textsf{OpenMath} functionality in GAP\mbox{}}}\\
\vfill

{\Huge Version 11.3.1\mbox{}}\\[1cm]
{28 January 2016\mbox{}}\\[1cm]
\mbox{}\\[2cm]
{\Large \textbf{Marco Costantini    \mbox{}}}\\
{\Large \textbf{Alexander Konovalov    \mbox{}}}\\
{\Large \textbf{Max Nicosia   \mbox{}}}\\
{\Large \textbf{Andrew Solomon    \mbox{}}}\\
\hypersetup{pdfauthor=Marco Costantini    ; Alexander Konovalov    ; Max Nicosia   ; Andrew Solomon    }
\end{center}\vfill

\mbox{}\\
{\mbox{}\\
\small \noindent \textbf{Marco Costantini    }\\
  Address: \begin{minipage}[t]{8cm}\noindent
 Department of Mathematics\\
 University of Trento\\
 \end{minipage}
}\\
{\mbox{}\\
\small \noindent \textbf{Alexander Konovalov    }  Email: \href{mailto://alexk at mcs dot st-andrews dot ac dot uk} {\texttt{alexk at mcs dot st-andrews dot ac dot uk}}\\
  Homepage: \href{http://www.cs.st-andrews.ac.uk/~alexk/} {\texttt{http://www.cs.st-andrews.ac.uk/\texttt{\symbol{126}}alexk/}}\\
  Address: \begin{minipage}[t]{8cm}\noindent
 School of Computer Science\\
 University of St Andrews\\
 Jack Cole Building, North Haugh,\\
 St Andrews, Fife, KY16 9SX, Scotland\\
 \end{minipage}
}\\
{\mbox{}\\
\small \noindent \textbf{Max Nicosia   }  Email: \href{mailto://ln73 at st-andrews dot ac dot uk} {\texttt{ln73 at st-andrews dot ac dot uk}}\\
  Address: \begin{minipage}[t]{8cm}\noindent
 School of Computer Science\\
 University of St Andrews\\
 Jack Cole Building, North Haugh,\\
 St Andrews, Fife, KY16 9SX, Scotland\\
 \end{minipage}
}\\
{\mbox{}\\
\small \noindent \textbf{Andrew Solomon    }  Email: \href{mailto://andrew at illywhacker dot net} {\texttt{andrew at illywhacker dot net}}\\
  Homepage: \href{http://www.illywhacker.net/} {\texttt{http://www.illywhacker.net/}}\\
  Address: \begin{minipage}[t]{8cm}\noindent
 Faculty of IT\\
 University of Technology, Sydney\\
 Broadway, NSW 2007\\
 Australia\\
 \end{minipage}
}\\
\end{titlepage}

\newpage\setcounter{page}{2}
{\small 
\section*{Abstract}
\logpage{[ 0, 0, 1 ]}
 \index{SCSCP package@\textsf{OpenMath} package} The \textsf{OpenMath} package provides an \textsf{OpenMath} phrasebook for \textsf{GAP}: it allows \textsf{GAP} users to import and export mathematical objects encoded in \textsf{OpenMath}, for the purpose of exchanging them with other \textsf{OpenMath}-enabled applications. \mbox{}}\\[1cm]
{\small 
\section*{Copyright}
\logpage{[ 0, 0, 2 ]}
 The \textsf{OpenMath} package is free software; you can redistribute it and/or modify it under the
terms of the \href{http://www.fsf.org/licenses/gpl.html} {GNU General Public License} as published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version. \mbox{}}\\[1cm]
{\small 
\section*{Acknowledgements}
\logpage{[ 0, 0, 3 ]}
 On various stages the development of the \textsf{OpenMath} package was supported by: 
\begin{itemize}
\item European Commission through ESPRIT grant EP 24969 ``Accessing and Using Mathematical Information Electronically'' (see 

 \href{http://web.archive.org/web/20040416013945/http://www.nag.co.uk/projects/OpenMath.html} {\texttt{http://web.archive.org/web/20040416013945/http://www.nag.co.uk/projects/OpenMath.html}}).
\item EU FP6 Programme project 026133 ``SCIEnce - Symbolic Computation Infrastructure for Europe'' (see \href{http://www.symbolic-computation.org/} {\texttt{http://www.symbolic-computation.org/}}).
\end{itemize}
 We acknowledge with gratitude this support.

 \mbox{}}\\[1cm]
\newpage

\def\contentsname{Contents\logpage{[ 0, 0, 4 ]}}

\tableofcontents
\newpage

 
\chapter{\textcolor{Chapter }{Introduction and installation}}\label{Intro}
\logpage{[ 1, 0, 0 ]}
\hyperdef{L}{X7FE7D77A82FEB4AB}{}
{
  
\section{\textcolor{Chapter }{Brief description of the package}}\label{IntroIntro}
\logpage{[ 1, 1, 0 ]}
\hyperdef{L}{X7DECBB1287D90D79}{}
{
  The \textsf{GAP} package \textsf{OpenMath} provides an \textsf{OpenMath} phrasebook for \textsf{GAP}: it allows \textsf{GAP} users to import and export mathematical objects encoded in \textsf{OpenMath} for the purpose of exchanging them with other \textsf{OpenMath}-enabled applications. 

 This manual describes: 
\begin{itemize}
\item how to view \textsf{OpenMath} representation of an object;
\item how to read \textsf{OpenMath} object from stream or write it to stream for the purposes of exchange with
another \textsf{OpenMath}-enabled application;
\item how to find which objects can be converted to/from \textsf{OpenMath} using this package;
\item how to extend the package to support private \textsf{OpenMath} content dictionaries.
\end{itemize}
 For the detailed information about \textsf{OpenMath} standard and content dictionaries see the \textsf{OpenMath} homepage \href{http://www.openmath.org} {\texttt{http://www.openmath.org}}. 

 For practical purposes, the \textsf{OpenMath} package will be most efficient if used in conjunction with the \textsf{GAP} package \textsf{SCSCP} (\cite{SCSCPpkg}) which implements the Symbolic Computation Software Composability protocol (\cite{SCSCPspec}). This protocol specifies an \textsf{OpenMath}-based remote procedure call framework, in which all messages (procedure calls
and returns of results of successful computation or error messages) are
encoded in \textsf{OpenMath} using content dictionaries \textsf{scscp1} and \textsf{scscp2} (\cite{scscp1cd}, \cite{scscp2cd}). Using the \textsf{SCSCP} package, \textsf{GAP} can communicate locally or remotely with any other \textsf{OpenMath}-enabled \textsf{SCSCP}-compliant application which may be not only another computer algebra system
but also another instance of the \textsf{GAP} system or even, for example, an external C/C++ or Java application. Such
communication will go into a seamless manner with the \textsf{GAP}/\textsf{OpenMath} conversion going in the background. }

 
\section{\textcolor{Chapter }{Installation of the package}}\label{IntroInstall}
\logpage{[ 1, 2, 0 ]}
\hyperdef{L}{X79E1ED167D631DCC}{}
{
  To use the \textsf{OpenMath} package it is required to install the \textsf{GAPDoc} package \cite{GAPDoc} to use the help system and parse \textsf{OpenMath} objects in the XML format. 

 To install the \textsf{OpenMath} package, unpack the archive and place the \texttt{openmath} directory in the \texttt{pkg} subdirectory of your \textsf{GAP}4.4 installation. When you don't have write access to the directory of your
main \textsf{GAP} installation, you can also install the package \emph{outside the \textsf{GAP} main directory} by unpacking it inside a directory \texttt{MYGAPDIR/pkg}. Then to be able to load \textsf{OpenMath} you need to call GAP with the \texttt{-l ";MYGAPDIR"} option. 

 When the \textsf{OpenMath} package is installed, it may be loaded as shown below (possibly loading
required packages at the same time): 
\begin{Verbatim}[commandchars=!|B,fontsize=\small,frame=single,label=Example]
  
  !gapprompt|gap>B !gapinput|LoadPackage("openmath");B
  -----------------------------------------------------------------------------
  Loading  OpenMath 11.0.0 (OpenMath functionality in GAP)
  by Marco Costantini,
     Alexander Konovalov (http://www.cs.st-andrews.ac.uk/~alexk/),
     Nicosia Max (ln73@st-andrews.ac.uk), and
     Andrew Solomon (http://www.illywhacker.net/).
  Homepage: http://www.cs.st-andrews.ac.uk/~alexk/openmath/
  -----------------------------------------------------------------------------
  true
  
\end{Verbatim}
 }

 }

 
\chapter{\textcolor{Chapter }{\textsf{OpenMath} functionality in \textsf{GAP}}}\label{OpenMathFunctionality}
\logpage{[ 2, 0, 0 ]}
\hyperdef{L}{X83C7040B7B389CA5}{}
{
  
\section{\textcolor{Chapter }{Viewing \textsf{OpenMath} representation of an object}}\label{ViewOpenMath}
\logpage{[ 2, 1, 0 ]}
\hyperdef{L}{X8393E7C57E539406}{}
{
  

\subsection{\textcolor{Chapter }{OMPrint}}
\logpage{[ 2, 1, 1 ]}\nobreak
\hyperdef{L}{X7B1815F078D8312B}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\ \ \texttt{OMPrint({\mdseries\slshape obj})\index{OMPrint@\texttt{OMPrint}}
\label{OMPrint}
}\hfill{\scriptsize (function)}}\\


 OMPrint writes the default XML \textsf{OpenMath} encoding of \textsf{GAP} object \mbox{\texttt{\mdseries\slshape obj}} to the standard output. 

 One can try it with different \textsf{GAP} objects to see if they can be converted to \textsf{OpenMath} and learn how their \textsf{OpenMath} representation looks like. Here we show the encoding for lists of integers and
rationals: 
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
  
  !gapprompt@gap>| !gapinput@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>
  
\end{Verbatim}
 Strings are encoded using \texttt{{\textless}OMSTR{\textgreater}} tags: 
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
  
  !gapprompt@gap>| !gapinput@OMPrint( "This is a string" );|
  <OMOBJ>
  	<OMSTR>This is a string</OMSTR>
  </OMOBJ>
  
\end{Verbatim}
 Cyclotomics may be encoded in different ways dependently on their properties: 
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
  
  !gapprompt@gap>| !gapinput@OMPrint( 1-2*E(4) );      |
  <OMOBJ>
  	<OMA>
  		<OMS cd="complex1" name="complex_cartesian"/>
  		<OMI>1</OMI>
  		<OMI>-2</OMI>
  	</OMA>
  </OMOBJ>
  !gapprompt@gap>| !gapinput@OMPrint(E(3));       |
  <OMOBJ>
  	<OMA>
  		<OMS cd="arith1" name="plus"/>
  		<OMA>
  			<OMS cd="arith1" name="times"/>
  			<OMI>1</OMI>
  			<OMA>
  				<OMS cd="algnums" name="NthRootOfUnity"/>
  				<OMI>3</OMI>
  				<OMI>1</OMI>
  			</OMA>
  		</OMA>
  	</OMA>
  </OMOBJ>
  
\end{Verbatim}
 Various encodings may be used for various types of groups: 
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
  
  !gapprompt@gap>| !gapinput@OMPrint( Group( (1,2) ) );|
  <OMOBJ>
  	<OMA>
  		<OMS cd="permgp1" name="group"/>
  		<OMS cd="permutation1" name="right_compose"/>
  		<OMA>
  			<OMS cd="permut1" name="permutation"/>
  			<OMI>2</OMI>
  			<OMI>1</OMI>
  		</OMA>
  	</OMA>
  </OMOBJ>
  !gapprompt@gap>| !gapinput@OMPrint( Group( [ [ [ 1, 2 ],[ 0, 1 ] ] ] ) );|
  <OMOBJ>
  	<OMA>
  		<OMS cd="group1" name="group_by_generators"/>
  		<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>0</OMI>
  				<OMI>1</OMI>
  			</OMA>
  		</OMA>
  	</OMA>
  </OMOBJ>
  !gapprompt@gap>| !gapinput@OMPrint( FreeGroup( 2 ) );                      |
  <OMOBJ>
  	<OMA>
  		<OMS cd="fpgroup1" name="free_groupn"/>
  		<OMI>2</OMI>
  	</OMA>
  </OMOBJ>
  
\end{Verbatim}
 }

 Producing \textsf{OpenMath} representation of polynomials, one may get a warning: 
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
  
  !gapprompt@gap>| !gapinput@x:=Indeterminate(Rationals,"x");; y:=Indeterminate(Rationals,"y");;|
  !gapprompt@gap>| !gapinput@OMPrint(x^2+y);|
  #I  Warning : polynomial will be printed using its default ring 
  #I  because the default OpenMath polynomial ring is not specified 
  #I  or it is not contained in the default OpenMath polynomial ring.
  #I  You may ignore this or call SetOpenMathDefaultPolynomialRing to fix it.
  <OMOBJ>
  	<OMA>
  		<OMS cd="polyd1" name="DMP"/>
  		<OMA id="polyring9qiY2oOaiITWUORb" >
  			<OMS cd="polyd1" name="poly_ring_d"/>
  			<OMS cd="setname1" name="Q"/>
  			<OMI>2</OMI>
  		</OMA>
  		<OMA>
  			<OMS cd="polyd1" name="SDMP"/>
  			<OMA>
  				<OMS cd="polyd1" name="term"/>
  				<OMI>1</OMI>
  				<OMI>0</OMI>
  				<OMI>1</OMI>
  			</OMA>
  			<OMA>
  				<OMS cd="polyd1" name="term"/>
  				<OMI>1</OMI>
  				<OMI>2</OMI>
  				<OMI>0</OMI>
  			</OMA>
  		</OMA>
  	</OMA>
  </OMOBJ>
  
\end{Verbatim}
 Indeed, now when another polynomial will be printed, it will belong to a ring
with a different identifier (despite \textsf{GAP} will be able to perform arithmetical operations on these polynomials like when
they belong to the same ground ring): 
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
  
  !gapprompt@gap>| !gapinput@OMPrint(x+1);|
  #I  Warning : polynomial will be printed using its default ring 
  #I  because the default OpenMath polynomial ring is not specified 
  #I  or it is not contained in the default OpenMath polynomial ring.
  #I  You may ignore this or call SetOpenMathDefaultPolynomialRing to fix it.
  <OMOBJ>
  	<OMA>
  		<OMS cd="polyd1" name="DMP"/>
  		<OMA id="polyring0LqlkhnCyLldcoBl" >
  			<OMS cd="polyd1" name="poly_ring_d_named"/>
  			<OMS cd="setname1" name="Q"/>
  			<OMV name="x"/>
  		</OMA>
  		<OMA>
  			<OMS cd="polyd1" name="SDMP"/>
  			<OMA>
  				<OMS cd="polyd1" name="term"/>
  				<OMI>1</OMI>
  				<OMI>1</OMI>
  			</OMA>
  			<OMA>
  				<OMS cd="polyd1" name="term"/>
  				<OMI>1</OMI>
  				<OMI>0</OMI>
  			</OMA>
  		</OMA>
  	</OMA>
  </OMOBJ>
  
\end{Verbatim}
 Thus, the warning means that it is not guaranteed that the polynomial ring
will have the same identifier \texttt{{\textless}OMA id="polyring..." {\textgreater}} 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 \texttt{SetOpenMathDefaultPolynomialRing} must be called: 
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
  
  !gapprompt@gap>| !gapinput@x:=Indeterminate(Rationals,"x");; y:=Indeterminate(Rationals,"y");;|
  !gapprompt@gap>| !gapinput@R:=PolynomialRing(Rationals,[x,y]);;|
  !gapprompt@gap>| !gapinput@SetOpenMathDefaultPolynomialRing(R);|
  !gapprompt@gap>| !gapinput@OMPrint(x^2+y);|
  <OMOBJ>
  	<OMA>
  		<OMS cd="polyd1" name="DMP"/>
  		<OMA id="polyring9eNcBGFHXkjl2kWh" >
  			<OMS cd="polyd1" name="poly_ring_d"/>
  			<OMS cd="setname1" name="Q"/>
  			<OMI>2</OMI>
  		</OMA>
  		<OMA>
  			<OMS cd="polyd1" name="SDMP"/>
  			<OMA>
  				<OMS cd="polyd1" name="term"/>
  				<OMI>1</OMI>
  				<OMI>0</OMI>
  				<OMI>0</OMI>
  			</OMA>
  			<OMA>
  				<OMS cd="polyd1" name="term"/>
  				<OMI>1</OMI>
  				<OMI>0</OMI>
  				<OMI>0</OMI>
  			</OMA>
  		</OMA>
  	</OMA>
  </OMOBJ>
  
\end{Verbatim}
 Now we can see that both polynomials belong to the ring with the same
identifier, and the \textsf{OpenMath} representation of the 2nd polynomial properly reflects that it belongs to a
polynomial ring with two variables. 
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
  
  !gapprompt@gap>| !gapinput@OMPrint(x+1);  |
  <OMOBJ>
  	<OMA>
  		<OMS cd="polyd1" name="DMP"/>
  		<OMR href="#polyring9eNcBGFHXkjl2kWh" />
  		<OMA>
  			<OMS cd="polyd1" name="SDMP"/>
  			<OMA>
  				<OMS cd="polyd1" name="term"/>
  				<OMI>1</OMI>
  				<OMI>0</OMI>
  				<OMI>0</OMI>
  			</OMA>
  			<OMA>
  				<OMS cd="polyd1" name="term"/>
  				<OMI>1</OMI>
  				<OMI>0</OMI>
  				<OMI>0</OMI>
  			</OMA>
  		</OMA>
  	</OMA>
  </OMOBJ> 
  
\end{Verbatim}
 

\subsection{\textcolor{Chapter }{OMString}}
\logpage{[ 2, 1, 2 ]}\nobreak
\hyperdef{L}{X876AD5BC7A8812C3}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\ \ \texttt{OMString({\mdseries\slshape obj})\index{OMString@\texttt{OMString}}
\label{OMString}
}\hfill{\scriptsize (function)}}\\


 OMString returns a string with the default XML \textsf{OpenMath} encoding of \textsf{GAP} object \mbox{\texttt{\mdseries\slshape obj}}. If used with the \texttt{noomobj} option, then initial and final {\textless}OMOBJ{\textgreater} tags will be
omitted. 
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
  
  !gapprompt@gap>| !gapinput@OMString(42);|
  "<OMOBJ> <OMI>42</OMI> </OMOBJ>"
  !gapprompt@gap>| !gapinput@OMString([1,2]:noomobj);    |
  "<OMA> <OMS cd=\"list1\" name=\"list\"/> <OMI>1</OMI> <OMI>2</OMI> </OMA>"
  
\end{Verbatim}
 }

 }

  
\section{\textcolor{Chapter }{Reading \textsf{OpenMath} code from streams and strings}}\label{Reading OpenMath from streams}
\logpage{[ 2, 2, 0 ]}
\hyperdef{L}{X7EB959397AB2B646}{}
{
  

\subsection{\textcolor{Chapter }{OMGetObject}}
\logpage{[ 2, 2, 1 ]}\nobreak
\hyperdef{L}{X7FBDCB3C83BBB115}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\ \ \texttt{OMGetObject({\mdseries\slshape stream})\index{OMGetObject@\texttt{OMGetObject}}
\label{OMGetObject}
}\hfill{\scriptsize (function)}}\\


 \mbox{\texttt{\mdseries\slshape stream}} is an input stream (see \texttt{InputTextFile} (\textbf{Reference: InputTextFile}), \texttt{InputTextUser} (\textbf{Reference: InputTextUser}), \texttt{InputTextString} (\textbf{Reference: InputTextString}), \texttt{InputOutputLocalProcess} (\textbf{Reference: InputOutputLocalProcess}), \texttt{InputOutputTCPStream} (\textbf{SCSCP: InputOutputTCPStream (for client)}), \texttt{InputOutputTCPStream} (\textbf{SCSCP: InputOutputTCPStream (for server)})) with an \textsf{OpenMath} object on it. \texttt{OMGetObject} takes precisely one object off \mbox{\texttt{\mdseries\slshape stream}} and returns it as a GAP object. Both XML and binary \textsf{OpenMath} 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): 
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
  
  !gapprompt@gap>| !gapinput@txml:=Filename(DirectoriesPackageLibrary("openmath","tst"),"test3.omt");;   |
  !gapprompt@gap>| !gapinput@tbin:=Filename(DirectoriesPackageLibrary("openmath","tst"),"test3.bin");;   |
  !gapprompt@gap>| !gapinput@xstream := InputTextFile( txml );; bstream := InputTextFile( tbin );;   |
  !gapprompt@gap>| !gapinput@x:=OMGetObject(xstream); y:=OMGetObject(bstream);|
  912873912381273891
  912873912381273891
  !gapprompt@gap>| !gapinput@x:=OMGetObject(xstream); y:=OMGetObject(bstream);|
  E(4)
  E(4)
  !gapprompt@gap>| !gapinput@CloseStream(xstream);CloseStream(bstream);|
  
\end{Verbatim}
 To paste an \textsf{OpenMath} object directly into standard input execute the following command in GAP: 
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
  
  !gapprompt@gap>| !gapinput@s:= InputTextUser();; g := OMGetObject(s); CloseStream(s);|
  !gapprompt@gap>| !gapinput@|
  
\end{Verbatim}
 

 For XML \textsf{OpenMath}, this function requires that the \textsf{GAP} package \textsf{GAPDoc} is available. }

 

\subsection{\textcolor{Chapter }{EvalOMString}}
\logpage{[ 2, 2, 2 ]}\nobreak
\hyperdef{L}{X7BFA1BAB7DA665F4}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\ \ \texttt{EvalOMString({\mdseries\slshape omstr})\index{EvalOMString@\texttt{EvalOMString}}
\label{EvalOMString}
}\hfill{\scriptsize (function)}}\\


 This function is an analog of \texttt{EvalString} (\textbf{Reference: EvalString}). Its argument \mbox{\texttt{\mdseries\slshape omstr}} must be a string containing a single \textsf{OpenMath} object. \texttt{EvalOMString} will return the \textsf{GAP} object represented by \mbox{\texttt{\mdseries\slshape omstr}}. 

 If \mbox{\texttt{\mdseries\slshape omstr}} contains more \textsf{OpenMath} objects, the rest will be ignored. 
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
  
  !gapprompt@gap>| !gapinput@s:="<OMOBJ><OMS cd=\"setname1\" name=\"Z\"/></OMOBJ>";;|
  !gapprompt@gap>| !gapinput@EvalOMString(s);|
  Integers
  !gapprompt@gap>| !gapinput@G:=SL(2,5);; G=EvalOMString(OMString(G));|
  true
  
\end{Verbatim}
 }

 }

  
\section{\textcolor{Chapter }{Writing \textsf{OpenMath} code to streams}}\label{Writing OpenMath to streams}
\logpage{[ 2, 3, 0 ]}
\hyperdef{L}{X87E11972845542AE}{}
{
  While it is possible to read \textsf{OpenMath} code directly from a stream, writing \textsf{OpenMath} to streams uses a different setup. It requires special objects called \textsf{OpenMath} \emph{writers}, which encapsulate streams and may be viewed as transducers accepting \textsf{GAP} objects and writing them to a stream in the XML or binary \textsf{OpenMath} 

 Such setup makes it possible to re-use the same stream for both binary and XML \textsf{OpenMath} communication, using different \textsf{OpenMath} writers in different calls. It also allows to re-use most of the high-level
code for \textsf{GAP} to \textsf{OpenMath} conversion, having separate methods for generating binary and XML \textsf{OpenMath} only for low-level output (\textsf{OpenMath} tags and basic objects). This makes easier adding support to new mathematical
objects and private content dictionaries as described in Chapter \ref{ExtendingOpenMath} since it does not require changing the low-level functionality. 

 

\subsection{\textcolor{Chapter }{IsOpenMathWriter}}
\logpage{[ 2, 3, 1 ]}\nobreak
\hyperdef{L}{X79EE2E8B7C83E0F4}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\ \ \texttt{IsOpenMathWriter\index{IsOpenMathWriter@\texttt{IsOpenMathWriter}}
\label{IsOpenMathWriter}
}\hfill{\scriptsize (Category)}}\\
\noindent\textcolor{FuncColor}{$\triangleright$\ \ \texttt{IsOpenMathXMLWriter\index{IsOpenMathXMLWriter@\texttt{IsOpenMathXMLWriter}}
\label{IsOpenMathXMLWriter}
}\hfill{\scriptsize (Category)}}\\
\noindent\textcolor{FuncColor}{$\triangleright$\ \ \texttt{IsOpenMathBinaryWriter\index{IsOpenMathBinaryWriter@\texttt{IsOpenMathBinaryWriter}}
\label{IsOpenMathBinaryWriter}
}\hfill{\scriptsize (Category)}}\\


 \texttt{IsOpenMathWriter}is a category for \textsf{OpenMath} writers. It has two subcategories: \texttt{IsOpenMathXMLWriter} and \texttt{IsOpenMathBinaryWriter}. }

 

\subsection{\textcolor{Chapter }{OpenMathXMLWriter}}
\logpage{[ 2, 3, 2 ]}\nobreak
\hyperdef{L}{X798979EB7E4723A2}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\ \ \texttt{OpenMathXMLWriter({\mdseries\slshape s})\index{OpenMathXMLWriter@\texttt{OpenMathXMLWriter}}
\label{OpenMathXMLWriter}
}\hfill{\scriptsize (function)}}\\


 for a stream \mbox{\texttt{\mdseries\slshape s}}, returns an object in the category \texttt{IsOpenMathXMLWriter} (\ref{IsOpenMathXMLWriter}). }

 

\subsection{\textcolor{Chapter }{OpenMathBinaryWriter}}
\logpage{[ 2, 3, 3 ]}\nobreak
\hyperdef{L}{X786D6A987C1FAB0B}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\ \ \texttt{OpenMathBinaryWriter({\mdseries\slshape s})\index{OpenMathBinaryWriter@\texttt{OpenMathBinaryWriter}}
\label{OpenMathBinaryWriter}
}\hfill{\scriptsize (function)}}\\


 for a stream \mbox{\texttt{\mdseries\slshape s}}, returns an object in the category \texttt{OpenMathBinaryWriter}. }

 

\subsection{\textcolor{Chapter }{OMPutObject}}
\logpage{[ 2, 3, 4 ]}\nobreak
\hyperdef{L}{X84FC6AD5872CBF33}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\ \ \texttt{OMPutObject({\mdseries\slshape stream, obj})\index{OMPutObject@\texttt{OMPutObject}}
\label{OMPutObject}
}\hfill{\scriptsize (function)}}\\
\noindent\textcolor{FuncColor}{$\triangleright$\ \ \texttt{OMPutObjectNoOMOBJtags({\mdseries\slshape stream, obj})\index{OMPutObjectNoOMOBJtags@\texttt{OMPutObjectNoOMOBJtags}}
\label{OMPutObjectNoOMOBJtags}
}\hfill{\scriptsize (function)}}\\


 \texttt{OMPutObject} writes (appends) the XML \textsf{OpenMath} encoding of the \textsf{GAP} object \mbox{\texttt{\mdseries\slshape obj}} to output stream \mbox{\texttt{\mdseries\slshape stream}} (see \texttt{InputTextFile} (\textbf{Reference: InputTextFile}), \texttt{OutputTextUser} (\textbf{Reference: OutputTextUser}), \texttt{OutputTextString} (\textbf{Reference: OutputTextString}), \texttt{InputOutputTCPStream} (\textbf{SCSCP: InputOutputTCPStream (for client)}), \texttt{InputOutputTCPStream} (\textbf{SCSCP: InputOutputTCPStream (for server)})). 

 The second version does the same but without {\textless}OMOBJ{\textgreater}
tags, what may be useful for assembling complex \textsf{OpenMath} objects. 
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
  
  !gapprompt@gap>| !gapinput@g := [[1,2],[1,0]];;|
  !gapprompt@gap>| !gapinput@t := "";|
  ""
  !gapprompt@gap>| !gapinput@s := OutputTextString(t, true);;|
  !gapprompt@gap>| !gapinput@w:=OpenMathXMLWriter( s );|
  <OpenMath XML writer to OutputTextString(0)>
  !gapprompt@gap>| !gapinput@OMPutObject(w, g);|
  !gapprompt@gap>| !gapinput@CloseStream(s);|
  !gapprompt@gap>| !gapinput@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>
  
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{OMPlainString}}
\logpage{[ 2, 3, 5 ]}\nobreak
\hyperdef{L}{X85297E7081470DDF}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\ \ \texttt{OMPlainString({\mdseries\slshape string})\index{OMPlainString@\texttt{OMPlainString}}
\label{OMPlainString}
}\hfill{\scriptsize (function)}}\\


 \texttt{OMPlainString} wraps the string into a \textsf{GAP} object of a special kind called an \textsf{OpenMath} plain string. Internally such object is represented as a string, but \texttt{OMPutObject} (\ref{OMPutObject}) threat it in a different way: instead of converting it into a
{\textless}OMSTR{\textgreater} object, an \textsf{OpenMath} plain string will be plainly substituted into the output (this explains its
name) without decorating it with {\textless}OMSTR{\textgreater} tags. 

 It is assumed that \textsf{OpenMath} plain string contains valid \textsf{OpenMath} code; no actual validation is performed during its creation. Such
functionality may be useful to compose some \textsf{OpenMath} code at the \textsf{GAP} level to communicate it to the other system, in particular, to send there
symbols which are not supported by \textsf{GAP}, for example: 
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
  
  !gapprompt@gap>| !gapinput@s:=OMPlainString("<OMS cd=\"nums1\" name=\"pi\"/>");|
  <OMS cd="nums1" name="pi"/>
  !gapprompt@gap>| !gapinput@OMPrint(s);                                       |
  <OMOBJ>
  	<OMS cd="nums1" name="pi"/>
  </OMOBJ>
  
\end{Verbatim}
 }

 }

  
\section{\textcolor{Chapter }{Utilities}}\label{Utilities}
\logpage{[ 2, 4, 0 ]}
\hyperdef{L}{X7DFC90B87DC503A1}{}
{
  

\subsection{\textcolor{Chapter }{OMTestXML}}
\logpage{[ 2, 4, 1 ]}\nobreak
\hyperdef{L}{X7D6B0843798A19B9}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\ \ \texttt{OMTestXML({\mdseries\slshape obj})\index{OMTestXML@\texttt{OMTestXML}}
\label{OMTestXML}
}\hfill{\scriptsize (function)}}\\
\noindent\textcolor{FuncColor}{$\triangleright$\ \ \texttt{OMTest({\mdseries\slshape obj})\index{OMTest@\texttt{OMTest}}
\label{OMTest}
}\hfill{\scriptsize (function)}}\\


 Converts \mbox{\texttt{\mdseries\slshape obj}} to XML \textsf{OpenMath} and back. Returns true if and only if \mbox{\texttt{\mdseries\slshape obj}} is unchanged (as a \textsf{GAP} object) by this operation. The \textsf{OpenMath} standard does not stipulate that converting to and from \textsf{OpenMath} should be the identity function so this is a useful diagnostic tool. 
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
  
  !gapprompt@gap>| !gapinput@OMTestXML([[1..10],[1/2,2+E(4)],ZmodnZObj(2,6),(1,2),true,"string"]);     |
  true
  
\end{Verbatim}
 \texttt{OMTest} is a synonym to \texttt{OMTestXML} }

 

\subsection{\textcolor{Chapter }{OMTestBinary}}
\logpage{[ 2, 4, 2 ]}\nobreak
\hyperdef{L}{X834694B784B5850F}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\ \ \texttt{OMTestBinary({\mdseries\slshape obj})\index{OMTestBinary@\texttt{OMTestBinary}}
\label{OMTestBinary}
}\hfill{\scriptsize (function)}}\\


 Converts \mbox{\texttt{\mdseries\slshape obj}} to binary \textsf{OpenMath} and back. Returns true if and only if \mbox{\texttt{\mdseries\slshape obj}} is unchanged (as a \textsf{GAP} object) by this operation. The \textsf{OpenMath} standard does not stipulate that converting to and from \textsf{OpenMath} should be the identity function so this is a useful diagnostic tool. 
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
  
  !gapprompt@gap>| !gapinput@OMTestBinary([[1..10],[1/2,2+E(4)],ZmodnZObj(2,6),(1,2),true,"string"]);     |
  true
  
\end{Verbatim}
 }

 }

 }

 
\chapter{\textcolor{Chapter }{Extending the \textsf{OpenMath} package}}\label{ExtendingOpenMath}
\logpage{[ 3, 0, 0 ]}
\hyperdef{L}{X84EBC4EC7D3DC9CB}{}
{
  
\section{\textcolor{Chapter }{Exploring the range of supported symbols}}\label{Available}
\logpage{[ 3, 1, 0 ]}
\hyperdef{L}{X85022B8D7CFA7B03}{}
{
  \index{OMsymRecord@\texttt{OMsymRecord}} The \textsf{OpenMath} package supports such basic \textsf{OpenMath} objects as integers ( {\textless}OMI{\textgreater} ), character strings (
{\textless}OMSTR{\textgreater} ) and variables (
{\textless}OMVAR{\textgreater} ). Besides that, it supports a number of \textsf{OpenMath} content dictionaries (some of them only partially, dependently on their
relevance to \textsf{GAP}). To see which symbols from which content dictionaries are supported for the
conversion from \textsf{OpenMath} to \textsf{GAP}, explore the global record \texttt{OMsymRecord}. Its components have names of appropriate CDs, and subcomponents of each
component have names of symbols from the corresponding CD. If the value of the
component is not equal to \texttt{fail}, then it contains the function or the object which is used for conversion.
The following example of the entry for the \texttt{nums1} CD demonstrates a combination of all possible cases: 
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
  
  !gapprompt@gap>| !gapinput@Display( OMsymRecord.nums1 );          |
  rec(
    NaN := nan,
    based_integer := fail,
    e := 2.718281828459045,
    gamma := fail,
    i := E(4),
    infinity := infinity,
    pi := 3.141592653589793,
    rational := function ( x )
          return OMgapId( [ OMgap2ARGS( x ), x[1] / x[2] ] )[2];
      end )
  
\end{Verbatim}
 \texttt{OMsymRecord} contains all symbols for which conversion from \textsf{OpenMath} to \textsf{GAP} is supported except some special symbols related with errors and special
procedures from the \textsf{SCSCP} package which are treated separately. 

 To check quickly if \textsf{GAP} can parse a given \textsf{OpenMath} object, copy the \textsf{OpenMath} code and paste it directly into standard input after the following command: 
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
  
  !gapprompt@gap>| !gapinput@s:= InputTextUser();; g := OMGetObject(s); CloseStream(s);|
  
\end{Verbatim}
 The main tool for the conversion from \textsf{GAP} to \textsf{OpenMath} is \texttt{OMPut( {\textless}writer{\textgreater}, {\textless}object{\textgreater} )}. A number of methods for \texttt{OMPut} are installed in the file \texttt{openmath/gap/omput.gi}. 

 To check quickly whether the object may be converted to \textsf{OpenMath}, call \texttt{OMprint} for that object, for example: 
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
  
  !gapprompt@gap>| !gapinput@OMPrint( [ [1..10], ZmodnZObj(2,6), (1,2) ] );                |
  <OMOBJ>
  	<OMA>
  		<OMS cd="list1" name="list"/>
  		<OMA>
  			<OMS cd="interval1" name="integer_interval"/>
  			<OMI>1</OMI>
  			<OMI>10</OMI>
  		</OMA>
  		<OMA>
  			<OMS cd="integer2" name="class"/>
  			<OMI>2</OMI>
  			<OMI>6</OMI>
  		</OMA>
  		<OMA>
  			<OMS cd="permut1" name="permutation"/>
  			<OMI>2</OMI>
  			<OMI>1</OMI>
  		</OMA>
  	</OMA>
  </OMOBJ>
  
\end{Verbatim}
 The package is in the continuous development and will support even more
symbols in the future. In the meantime, if you will have any requests for the
support for particular symbols, please contact Alexander Konovalov. }

 
\section{\textcolor{Chapter }{Adding support for private content dictionaries and symbols}}\label{Private}
\logpage{[ 3, 2, 0 ]}
\hyperdef{L}{X7BF61AF183A25921}{}
{
  There is also a way for the user to extend the package adding support for
private and experimental CDs or separate symbols. We allocated the directory \texttt{openmath/private} for this purposes, and currently it contain the file \texttt{private.g} for conversions from \textsf{OpenMath} to \textsf{GAP} and the file \texttt{private.gi} for conversions from \textsf{GAP} to \textsf{OpenMath} for some symbols from private CDs contained in the \texttt{openmath/cds} directory. 

 In particular, we extended the package with the following private \textsf{OpenMath} symbols: 
\begin{itemize}
\item  \texttt{group1.group{\textunderscore}by{\textunderscore}generators} which allows us to input and output groups given by their generators as this
is a natural way to create groups in \textsf{GAP}; 
\item  \texttt{semigroup1.semigroup{\textunderscore}by{\textunderscore}generators} and \texttt{monoid1.monoid{\textunderscore}by{\textunderscore}generators} following the same considerations for semigroups and monoids; 
\item  \texttt{pcgroup1.pcgroup{\textunderscore}by{\textunderscore}pcgscode} for PcGroups given by their pcgs code and order; 
\item  \texttt{record1.record} for records as they are important data structures which we want to pass in a
straightforward manner between different \textsf{GAP} instances; 
\item  \texttt{transform1.transformation} to support transformations, transformation semigroups and their automorphism
groups. 
\end{itemize}
 The file \texttt{private.g} is loaded from \texttt{openmath/gap/new.g}, and the \texttt{private.gi} is loaded from \texttt{openmath/gap/read.g}. If the user would like to add own code, this may be done either by adding it
to these files or by placing additional files in \texttt{openmath/private} directory and load them similarly to \texttt{private.g} and \texttt{private.gi}. We will welcome user's contributions in the form of the code to support
existing content dictionaries from the \textsf{OpenMath} web site or private content dictionaries, if they may be interesting for a
wider community. }

 }

 \def\bibname{References\logpage{[ "Bib", 0, 0 ]}
\hyperdef{L}{X7A6F98FD85F02BFE}{}
}

\bibliographystyle{alpha}
\bibliography{manual}

\addcontentsline{toc}{chapter}{References}

\def\indexname{Index\logpage{[ "Ind", 0, 0 ]}
\hyperdef{L}{X83A0356F839C696F}{}
}

\cleardoublepage
\phantomsection
\addcontentsline{toc}{chapter}{Index}


\printindex

\newpage
\immediate\write\pagenrlog{["End"], \arabic{page}];}
\immediate\closeout\pagenrlog
\end{document}
