3
$\begingroup$

Note: I have asked a related question on stackoverflow, for the practical purpose of developing a web application that needs to export and import objects to/from the GAP computer algebra system, and push/pull to a relational database and the web. So far no luck, so I am posting a more detailed version here.

I guess my question is basically how to serialise GAP objects effectively and efficiently. GAP is an object-oriented computer algebra system. If I need to push any kind of data from GAP to, say, a web page or a relational database or wherever I need it, then I need to be able to serialise the relevant GAP objects. I don't know much about the OpenMath standard and the corresponding OpenMath GAP package. I am learning these things, but it would seem that this package could be a solution to my problem. But I am not clear about the practical details.

For example, if $G$ is the symmetric group of degree $3$ then the following GAP code prints to the screen the XML and binary OpenMath object versions of $G$ (as a GAP object):

#defining the group
gap> G := SymmetricGroup( 3 );
Sym( [ 1 .. 3 ] )

#creating an XML OpenMath and a binary OpenMath writer that print to the screen
gap> xw := OpenMathXMLWriter( OutputTextUser( ) );
gap> bw := OpenMathBinaryWriter( OutputTextUser( ) );
<OpenMath XML writer to OutputTextFile(*stdout*)>
<OpenMath binary writer to OutputTextFile(*stdout*)>

#making the writers print the object G to the screen
gap> OMPutObject( xw, G ); OMPutObject( bw, G );
<OMOBJ>
    <OMA>
        <OMS cd="permgp1" name="group"/>
        <OMS cd="permutation1" name="right_compose"/>
        <OMA>
            <OMS cd="permut1" name="permutation"/>
            <OMI>2</OMI>
            <OMI>3</OMI>
            <OMI>1</OMI>
        </OMA>
        <OMA>
            <OMS cd="permut1" name="permutation"/>
            <OMI>2</OMI>
            <OMI>1</OMI>
        </OMA>
    </OMA>
</OMOBJ>
gap> OMPutObject( bw, G );
permgp1group
permutation1right_compose
                        permut1permutation
                                         permut1permutationgap>

The XML version is readable, it's describing $G$ in terms of the generators $(1,2,3)$ and $(1,2)$, but the "binary" version does not make sense to me. How can I write this to a relational database table for example?

Furthermore, if $S, T, U$ are the subgroups of $G$ generated by the transpositions $(1,2)$, $(1,3)$, and $(2,3)$ respectively, then the XML writer prints out for these GAP objects the following:

    <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>
gap> OMPutObject( xw, T );
<OMOBJ>
    <OMA>
        <OMS cd="permgp1" name="group"/>
        <OMS cd="permutation1" name="right_compose"/>
        <OMA>
            <OMS cd="permut1" name="permutation"/>
            <OMI>3</OMI>
            <OMI>2</OMI>
            <OMI>1</OMI>
        </OMA>
    </OMA>
</OMOBJ>
gap> OMPutObject( xw, U );
<OMOBJ>
    <OMA>
        <OMS cd="permgp1" name="group"/>
        <OMS cd="permutation1" name="right_compose"/>
        <OMA>
            <OMS cd="permut1" name="permutation"/>
            <OMI>1</OMI>
            <OMI>3</OMI>
            <OMI>2</OMI>
        </OMA>
    </OMA>
</OMOBJ>

This doesn't make sense to me. I need to be able to distinguish between $S, T, U$ but from this XML I can't see how to do this.

$\endgroup$
  • 1
    $\begingroup$ In the first example, binary format is not printable, so it's not surprising that you see some nonsense trying to print it. You can print its hexadecimal dump or print it to a file and open in some special editor. $\endgroup$ – Alexander Konovalov Dec 22 '14 at 16:08
  • $\begingroup$ In the 2nd example, all there groups $S$,$T$,$U$ have different output, so I am not sure if I understood the question. $\endgroup$ – Alexander Konovalov Dec 22 '14 at 16:09
  • 1
    $\begingroup$ Finally, if you want the data to be accessible from a GAP session, you might be interested in the SCSCP package and also in SCSCP APIs. It uses OpenMath to send/receive data, but their encoding inside SCSCP messages may be customised, e.g. IO picked strings. $\endgroup$ – Alexander Konovalov Dec 22 '14 at 16:11
  • $\begingroup$ Thanks. In relation to the 2nd I guess my question is more to do with making sense of OpenMath - here the output for T = Group( [(1,3)] ) is <OMOBJ> <OMA> <OMS cd="permgp1" name="group"/> <OMS cd="permutation1" name="right_compose"/> <OMA> <OMS cd="permut1" name="permutation"/> <OMI>3</OMI> <OMI>2</OMI> <OMI>1</OMI> </OMA> </OMA> </OMOBJ> which I do not understand. Isn't this describing Group( [(1,3,2)]? $\endgroup$ – ramius Dec 22 '14 at 16:50
  • 1
    $\begingroup$ OpenMath symbols are described in corresponding documents, called content dictionaries. For example, here is permut1.permutation and it explains that <OMA> <OMS cd="permut1" name="permutation"/> <OMI>3</OMI> <OMI>2</OMI> <OMI>1</OMI> </OMA> maps $1$ to $3$, $2$ to $2$ and $3$ to $1$, thus it describes the transposition $(1 3)$. $\endgroup$ – Alexander Konovalov Dec 22 '14 at 18:55
3
$\begingroup$

There are lots of ways of serialising GAP objects. You mentioned one above, here are some more:

  1. Using the IO package, there is something called pickling, http://www.gap-system.org/Manuals/pkg/io-4.4.4/doc/chap5.html
  2. There is a very recent package supporting JSON: http://gap-system.github.io/json/.

I guess you might find the later more useful than anything else.

$\endgroup$
  • $\begingroup$ Thanks, the JSON repo looks interesting. I've forked it at Github. $\endgroup$ – ramius Dec 21 '14 at 13:48
  • 1
    $\begingroup$ Thanks, James - I was going to point out to the same two. In addition, SCSCP package offers IO_PickleToString and IO_UnpickleFromString. $\endgroup$ – Alexander Konovalov Dec 21 '14 at 18:24
  • $\begingroup$ I have tried out IO_PickleToString and IO_UnpickleFromString, and they seem be exactly what I need. $\endgroup$ – ramius Dec 24 '14 at 2:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.