[GAP Forum] Storing additional data
Alexander Konovalov
alexander.konovalov at st-andrews.ac.uk
Tue Apr 4 00:26:01 BST 2017
Dear Timm, dear GAP Forum,
> On 27 Mar 2017, at 09:52, Timm von Puttkamer <tvonp at gmx.net> wrote:
>
> Dear all,
>
> I have defined some numeric invariant for a group whose value I would like to save for each finite group in the SmallGroups library so that I do not have to compute it over and over again. Is there a preferred way to do this in GAP? My first idea was to set up some database, e.g. SQLite, but it seems GAP does not offer any SQL database interface directly. Of course I could use text files, but I want to be able to quickly select groups with specific values of the invariant and I wish not to reinvent basic database functionality.
>
> Kind regards,
> Timm
What about the following example, which uses lists to store data, and relies on the fact that i-th entry of the list for groups of order n is the value of the parameter for SmallGroup(n,i) ?
Consider the function that returns an average order of the element of a group (this function is taken from the GAP Software Carpentry lesson at http://alex-konovalov.github.io/gap-lesson/):
gap> AvgOrd:=function(G) return Sum(List(G,Order))/Size(G); end;
function( G ) ... end
Now we will compute lists of its values for groups, for example, of orders 8 and 105:
gap> d8:=List(AllSmallGroups(8),AvgOrd);
[ 43/8, 23/8, 19/8, 27/8, 15/8 ]
gap> d105:=List(AllSmallGroups(105),AvgOrd);
[ 17, 301/5 ]
Then we will store them in a global record, where the names of component correspond to the order of the group:
gap> AVG_ORD_DB:=rec( (8):= d8, (105):= d105);
rec( 105 := [ 17, 301/5 ], 8 := [ 43/8, 23/8, 19/8, 27/8, 15/8 ] )
Finally, the function `AvgOrdById` will retrieve the value of the parameter from this record, based on the IdGroup(G):
gap> AvgOrdById:=function(G) return AVG_ORD_DB.(IdGroup(G)[1])[IdGroup(G)[2]]; end;
function( G ) ... end
Now you can use it as follows:
gap> AllSmallGroups(8, g -> AvgOrdById(g)>3 );
[ <pc group of size 8 with 3 generators>, <pc group of size 8 with 3 generators> ]
gap> AllSmallGroups(105, g -> IsInt( AvgOrdById(g) ) );
[ <pc group of size 105 with 3 generators> ]
Of course, in this case AvgOrd computes the result quite fast and perhaps it's not worth efforts to create such "database" but I presume that in your case the calculation could be much more expensive, so it may be worth efforts.
Further extensions could be:
- triggering an error in `AvgOrdById` in case the data for a given order are not available
- automation of adding further data to AVG_ORD_DB
- splitting AVG_ORD_DB record into multiple files and reading (or unbinding) its components on demand
- storing values of parameters retrieved from the database as attributes in groups (so next time one does not even need to perform the lookup for the same object again),
etc.
I hope that this approach would not only nicely fit into selecting groups with AllSmallGroups, but will also protect from accidental mix-up of using another parameter or a list of parameters for a different order. It will also work for any group for which IdGroup works, although it may be slower - however, groups from the Small Groups Library would already have their IdGroup stored in them, so in this case there will be no overhead.
Hope this helps
Alexander
More information about the Forum
mailing list