Serialising objects from the GAP computer algebra system

112 Views Asked by At

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.

1

There are 1 best solutions below

3
On BEST ANSWER

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.