# File: gap2uacalc.g # Author: William DeMeo # Date: 2011.06.06 # Updated: 2011.10.24 # Updated: 2015.10.08 by David Stanovsky: function table2uacalc() added # # Description: GAP routines for creating a uacalc algebra file from GAP groups and GAP matrices (such as multiplication tables of quasigroups and loops). # # Send questions, comments, suggestions to williamdemeo@gmail.com # gset2uacalc:=function(args) # gset2uacalc:=function([G, algebraname]) # Convert a gap action group to a uacalc algebra file. # # Input: G The action group created in GAP, # for example, like this: # G := Action( K, RightCosets(K,H), OnRight ); # # algebraname (optional, default=StructureDescription(G)) # A string which will serve as both the name of # the algebra in uacalc, and also the filename # (the .ua suffix will be added). # # Output: algebraname.ua A uacalc file containing a description of the gset # as an algebra suitable for loading into the ua calculator. # # Examples: # 1. gap> G := SymmetricGroup(3);; # gap> act:=Action(G,G,OnRight);; # gap> gset2uacalc([act, "S3action"]);; # # 2. gap> G := TransitiveGroup(8,4);; # gap> gset2uacalc([G, "D8"]); # # 3. gap> G:=SmallGroup(24,13);; # C2 x A4 # gap> ccsg:=ConjugacyClassesSubgroups(G);; # gap> H:=Representative(ccsg[2]);; # gap> act:=Action(G,RightCosets(G,H),OnRight);; # gap> gset2uacalc([act, "C2xA4modC2"]); # # 4. The last example could also be accomplished in just two lines: # gap> G := TransitiveGroup(12,7); # gap> gset2uacalc([G, "C2xA4mod2"]); local nargin, G, algebraname, filename, outfile, N, opcount, g, x; G:=args[1]; if not IsTransitive(G) then Error("Usage: gset2uacalc([G, ... ]); G must be a transitive group."); fi; nargin := Length(args); if nargin < 2 then algebraname:=StructureDescription(G); else algebraname:=args[2]; fi; filename := Concatenation(algebraname, ".ua"); outfile := OutputTextFile(filename, false); SetPrintFormattingStatus(outfile, false); # This prevents automatic indentation and line breaks. N:=NrMovedPoints(G); PrintTo(outfile, "\n"); AppendTo(outfile, "\n\n", algebraname, "\n"); AppendTo(outfile, "The permutational algebra (", MovedPoints(G)-1, ", ", StructureDescription(G), ").\n"); AppendTo(outfile, "", N, "\n"); AppendTo(outfile, "\n"); opcount:=0; for g in GeneratorsOfGroup(G) do AppendTo(outfile, "\ng", opcount, "\n"); AppendTo(outfile, "1\n\n\n\n"); AppendTo(outfile, 1^g-1); for x in [2..N] do AppendTo(outfile, ",", x^g-1); od; AppendTo(outfile, "\n\n\n\n"); opcount:=opcount+1; od; AppendTo(outfile, "\n\n\n"); end; group2uacalc:=function(args) # group2uacalc:=function([G, algebraname]) # Convert a group to a uacalc algebra file. # # Input: G A group created in GAP. # # algebraname (optional, default=StructureDescription(G)) # A string which will serve as both the name of # the algebra in uacalc, and also the filename # (the .ua suffix will be added). # # Output: algebraname.ua A uacalc file containing a description of the group # as an algebra suitable for loading into the ua calculator. # # Examples: # 1. gap> G := SymmetricGroup(5); # gap> group2uacalc([G, "S5"]); # # 2. gap> G := SmallGroup(60,5); # gap> group2uacalc([G, "A5"]); # # Notes: If you want the output to display more group elements in the description of # the algebra please increase the variable MAXDISP below. local nargin, G, algebraname, filename, outfile, N, g, f, h, x, elements, pos, i, j, MAXDISP; G:=args[1]; MAXDISP:=16; nargin := Length(args); if nargin < 2 then algebraname:=StructureDescription(G); else algebraname:=args[2]; fi; filename := Concatenation(algebraname, ".ua"); outfile := OutputTextFile(filename, false); SetPrintFormattingStatus(outfile, false); # This prevents automatic indentation and line breaks. N:=Order(G); elements:=Elements(G); PrintTo(outfile, "\n"); AppendTo(outfile, "\n\n", algebraname, "\n"); AppendTo(outfile, "", StructureDescription(G), ". "); MAXDISP:=Minimum(MAXDISP,N); AppendTo(outfile, "0 = id, "); for i in [2..MAXDISP-1] do g:=elements[i]; AppendTo(outfile, i-1, " = ", g, ", "); od; AppendTo(outfile, MAXDISP-1, " = ", elements[MAXDISP]); if MAXDISP = N then AppendTo(outfile, ".\n"); else AppendTo(outfile, "...\n"); fi; AppendTo(outfile, "", N, "\n"); AppendTo(outfile, "\n"); AppendTo(outfile, "\np\n"); AppendTo(outfile, "2\n\n\n\n"); for i in [1..N] do g:=elements[i]; AppendTo(outfile, ""); for j in [1..N] do h:=elements[j]; f:=g*h; pos:=Position(elements, f); AppendTo(outfile, pos-1, ","); od; AppendTo(outfile, "\n"); od; AppendTo(outfile, "\n\n\n"); AppendTo(outfile, "\n\n\n"); end; groups2uacalc:=function(N) # groups2uacalc:=function(N) # This writes all groups of order N to a uacalc file. # # Output: GroupsOfOrderN.ua A uacalc file containing a description of the groups of order N # as an algebra suitable for loading into the ua calculator. # local nargin, G, algebraname, filename, outfile, g, f, h, x, elements, pos, i, j, k, MAXDISP; MAXDISP:=16; filename := Concatenation("GroupsOfOrder", String(N), ".ua"); outfile := OutputTextFile(filename, false); SetPrintFormattingStatus(outfile, false); # This prevents automatic indentation and line breaks. PrintTo(outfile, "\n"); AppendTo(outfile, "\n"); for k in [1..NumberSmallGroups(N)] do G:=SmallGroup(N,k); elements:=Elements(G); AppendTo(outfile, "\n\n", StructureDescription(G), "\n"); AppendTo(outfile, "", StructureDescription(G), ". "); MAXDISP:=Minimum(MAXDISP,N); AppendTo(outfile, "0 = id, "); for i in [2..MAXDISP-1] do g:=elements[i]; AppendTo(outfile, i-1, " = ", g, ", "); od; AppendTo(outfile, MAXDISP-1, " = ", elements[MAXDISP]); if MAXDISP = N then AppendTo(outfile, ".\n"); else AppendTo(outfile, "...\n"); fi; AppendTo(outfile, "", N, "\n"); AppendTo(outfile, "\n"); AppendTo(outfile, "\np\n"); AppendTo(outfile, "2\n\n\n\n"); for i in [1..N] do g:=elements[i]; AppendTo(outfile, ""); for j in [1..N] do h:=elements[j]; f:=g*h; pos:=Position(elements, f); AppendTo(outfile, pos-1, ","); od; AppendTo(outfile, "\n"); od; AppendTo(outfile, "\n\n\n"); AppendTo(outfile, "\n\n\n"); od; AppendTo(outfile, "\n"); end; table2uacalc:=function(args) # matrix2uacalc:=function([M, algebraname]) # Convert a matrix to a uacalc algebra file. # # Input: M A square matrix n x n with entries 1,...,n # i.e., a multiplication table of an algebra of size n with a single binary operation # # algebraname (optional, default="gap_algebra") # A string which will serve as both the name of # the algebra in uacalc, and also the filename # (the .ua suffix will be added). # # Output: algebraname.ua A uacalc file containing a description of the group # as an algebra suitable for loading into the ua calculator. # # Examples: # 1. gap> LoadPackage("loops"); # gap> M := MultiplicationTable(MoufangLoop(12,1)); # gap> table2uacalc([M, "ML12_1"]); # # 2. gap> M := [[1,4,3,2],[2,1,2,1],[1,4,3,2],[3,3,3,3]]; # gap> table2uacalc([M]); # # Notes: If you want the output to display more elements in the description of # the algebra please increase the variable MAXDISP below. local nargin, G, algebraname, filename, outfile, N, g, f, h, x, l, elements, pos, i, j, MAXDISP; G:=args[1]; MAXDISP:=16; nargin := Length(args); if nargin < 2 then algebraname:="gap_algebra"; else algebraname:=args[2]; fi; N:=Size(G); # check if it really is a multiplication table for x in G do if Size(x)<>N then Print("Not a multiplication table.\n"); return false; fi; od; l:=Flat(G); for i in l do if i<1 or i>N then Print("Not a multiplication table.\n"); return false; fi; od; filename := Concatenation(algebraname, ".ua"); outfile := OutputTextFile(filename, false); SetPrintFormattingStatus(outfile, false); # This prevents automatic indentation and line breaks. elements:=[1..N]; PrintTo(outfile, "\n"); AppendTo(outfile, "\n\n", algebraname, "\n"); AppendTo(outfile, " binary algebra of size ", N, ". "); MAXDISP:=Minimum(MAXDISP,N); AppendTo(outfile, "0 = id, "); for i in [2..MAXDISP-1] do g:=elements[i]; AppendTo(outfile, i-1, " = ", g, ", "); od; AppendTo(outfile, MAXDISP-1, " = ", elements[MAXDISP]); if MAXDISP = N then AppendTo(outfile, ".\n"); else AppendTo(outfile, "...\n"); fi; AppendTo(outfile, "", N, "\n"); AppendTo(outfile, "\n"); AppendTo(outfile, "\np\n"); AppendTo(outfile, "2\n\n\n\n"); for i in [1..N] do g:=elements[i]; AppendTo(outfile, ""); for j in [1..N] do h:=elements[j]; f:=G[g][h]; pos:=Position(elements, f); AppendTo(outfile, pos-1, ","); od; AppendTo(outfile, "\n"); od; AppendTo(outfile, "\n\n\n"); AppendTo(outfile, "\n\n\n"); end;