gap> ######################################################################### gap> # A GAP session gap> gap> # - some input gap> ( 1 + 2 ) * ( 3 + 4 ); 21 gap> gap> # - partial input gap> ( 1 + 2 ) * ( 3 + 4 ) > ; # simply add the missing semicolon 21 gap> gap> # - erroneous input gap> ( 1 + 2 ) / ( 3 - 3 ); Error, Rational operations: must not be zero not in any function at line 13 of *stdin* you can replace via 'return ;' brk> quit; gap> gap> # - comments gap> # This is just a comment. gap> 1 + 2; # add two numbers 3 gap> gap> # - read input from some file gap> Read( "input_from_file" ); a random pattern: x oo o oo oo o x ox o oox oxo ooxoooooxxoxxoo oo oxxxxxo x oxx xx ooxooo o x o xoo xoxoooooxooox xo x o xxxooxox xx o oo ooxxxoxo x oxxo xoo xx xoxo o xxx o oxxoxxxx xoxxoox xoxox x ooooooox xxoxxxox o x oxxoxox x o xx xx o x oo ooxo o xo ox ooooxoo xoxx ox oxx x xooxoxx xoo oxo x xxo o xxo o xx ox oxox o x o xxx oo xx xoxxxoox oo xxoo o oo oo oo ooxxxoxxoox xxo xxoxx ooooxoooo o o ooxo xo o o xxxoxx o x xo x o o oxx xoooox xxo xx xo x xox xxxxx xx xxo xoox xx o xooxx x xx o o oo ox x oxxo oxxoxxox x o xoo xox xxoo o xo xx xoxxx xxxxxoo xxo xooxo xxxxoo ooox xo oxxo ox xo xoxxxxx xx o oxoxx ox oo ox oxxx oxoox x xoxoo oxoxx o xxxxxoxo xxx o oxxx oxooooo xox ooxx ooxxo xxxoo xxoxx xoo x xoxoxxxxooooo oo oo ox o x ooo ooxxoxoxoxxooo xxoxxo oxoxoo oxo o xoox x xx x oo o oox oxo x oxx oxx o oxx oxo o xx ox oxooox xo xo ooo o o xo xooxxx xxxoxo xxo xxxoo xx xxox xxooxoo oooo xo xxoo xxoxx xo oxo xox x oxooxo oo ox xxoo oxo oxo oo xxox ooxox xxoxxx o x xo x oo ooxo xo x oxoo oo oo x xxooxx oxooox x oxxoxooxxox ooox xxo o ooxo x o o oo xx x o x o oxo x oooxx xo o ooxo oooox xx ox oo ooxx xxxo oox xxox o oxx ooooxx xoxx xo oo oxx o oxo x xx xxo xx xoxx x oox xo x x x oxoxox oo oxx ooo ox xooxoo xxoxxx o xoxooo oxoo xxx ooxxoxoooxo xoo o ooxxxoooo o oxoo o o x ooxxo oxxoo x xxxxxxo o ox o xx ox xo o o xooooooxoxo oo oxoo x o xxx x ooox ox o x oo xoxx xx o o x gap> gap> ######################################################################### gap> # The GAP Language gap> gap> # - assignments gap> a; # an unbound variable Error, Variable: 'a' must have a value not in any function at line 25 of *stdin* gap> a:= 1; 1 gap> a; 1 gap> A; # note that GAP is case sensitive Error, Variable: 'A' must have a value not in any function at line 28 of *stdin* gap> b:= 2 * a; 2 gap> b = a; # comparison for equality false gap> b:= a; # assignment 1 gap> b:= 2 * b;; # suppress GAP's output gap> b; 2 gap> a; 1 gap> Size:= 12; # a read-only variable Error, Variable: 'Size' is read only not in any function at line 35 of *stdin* you can 'return;' after making it writable brk> quit; gap> gap> # - infix operators gap> a:= ( 1 + 2 ) < ( 6 - 3 ); false gap> b:= ( 1 + 2 ) <= ( 6 - 3 ); true gap> a and b; false gap> a or b; true gap> not a; true gap> gap> # - functions gap> square:= function( n ) return n^2; end; function( n ) ... end gap> square( 1 ); square( 2 ); square( -1000 ); 1 4 1000000 gap> square:= ( n -> n^2 ); # just a shorter way to write simple functions function( n ) ... end gap> gap> # - local variables gap> test:= function( n ) > local a, b; > > a:= n^2; > b:= a + 1; > return a + b; > end; function( n ) ... end gap> gap> a; b; false true gap> test( 10 ); 201 gap> a; b; # the global variable are not changed false true gap> gap> # - a variadic function gap> test2:= function( n, m... ) > Print( m, "\n" ); > end; function( n, m... ) ... end gap> test2( 0 ); test2( 0, 1 ); test2( 0, 1, 2 ); [ ] [ 1 ] [ 1, 2 ] gap> gap> # - if statements gap> test3:= function( n ) > if n < 0 then > Print( "negative\n" ); > elif n = 0 then > Print( "zero\n" ); > else > Print( "positive\n" ); > fi; > end;; gap> test3( -1 ); test3( 0 ); test3( 1 ); negative zero positive gap> test3( false ); # we do not get an error positive gap> gap> # - recursion gap> fib:= function( n ) > if n = 1 or n = 2 then > return 1; > else > return fib( n-1 ) + fib( n-2 ); > fi; > end; function( n ) ... end gap> fib( 3 ); 2 gap> gap> # - for loop gap> a:= 0;; gap> for i in [ 1 .. 100 ] do > a:= a + i; > od; gap> a; 5050 gap> gap> # - while loop gap> a:= 0;; gap> i:= 1;; gap> while i <= 100 do > a:= a + i; > i:= i + 1; > od; gap> a; 5050 gap> gap> # - repeat loop gap> a:= 0;; gap> i:= 1; 1 gap> repeat > a:= a + i; > i:= i + 1; > until i > 100; gap> a; 5050 gap> gap> # - continue gap> a:= 0;; gap> for i in [ 1 .. 100 ] do > if i mod 2 = 0 then > continue; > fi; > a:= a + i; > od; gap> a; 2500 gap> gap> # - break gap> a:= 0;; gap> for i in [ 1 .. 100 ] do > if a > 1000 then > break; > fi; > a:= a + i; > od; gap> a; 1035 gap> gap> ######################################################################### gap> # Constants gap> gap> # - booleans gap> true = false; false gap> true <> false; true gap> true or false; true gap> true and false; false gap> not true; false gap> a:= 1;; b:= 2;; gap> ( a < b ) or ( ( 2*a = b ) and not ( a = b ) ); true gap> gap> # - integers gap> -17; 0; 5; -17 0 5 gap> 20^100 - 1; # arbitrary large, no overflow 126765060022822940149670320537599999999999999999999999999999999999999999999999\ 99999999999999999999999999999999999999999999999999999 gap> gap> # - rationals gap> 3/7; 3/7 gap> 4/6; # normal form 2/3 gap> 1/0; Error, Rational operations: must not be zero not in any function at line 154 of *stdin* you can replace via 'return ;' brk> quit; gap> gap> # - elements of cyclotomic fields gap> Sqrt( 7 ); E(28)^3-E(28)^11-E(28)^15+E(28)^19-E(28)^23+E(28)^27 gap> E(3) + E(3)^2; -1 gap> E(4)^2; -1 gap> E(3) + E(5); # natural embedding -E(15)^2-2*E(15)^8-E(15)^11-E(15)^13-E(15)^14 gap> 1 / ( E(3) + 1 ); -E(3) gap> gap> # - finite field elements gap> a:= Z(2); Z(2)^0 gap> a + a; 0*Z(2) gap> a * a; Z(2)^0 gap> a + a = 0; a + a = 0 * a; # distinguish different zeros false true gap> 0 * a = 0; a = 1; false false gap> a:= Z(4); Z(2^2) gap> a + a; 0*Z(2) gap> a * a; Z(2^2)^2 gap> a^3; Z(2)^0 gap> gap> # - permutations (on positive integers) gap> p:= (1,2,3)(4,5); (1,2,3)(4,5) gap> p * p; (1,3,2) gap> p^3; (4,5) gap> 1^p; # apply a permutation to a point 2 gap> (1,2,3)(3,4,5); # cycle notation is restrictive Error, Permutation: cycles must be disjoint and duplicate-free not in any function at line 178 of *stdin* gap> (1,2,3) * (3,4,5); (1,2,4,5,3) gap> gap> p1:= (1,2); p2:= (3,10^6); (1,2) (3,1000000) gap> p3:= p1 * p2; p4:= p3 * p2; (1,2)(3,1000000) (1,2) gap> p1 = p4; # the two move the same points in the same way true gap> MemoryUsage( p1 ); 28 gap> MemoryUsage( p4 ); 4000024 gap> gap> ######################################################################### gap> # Lists (arrays) gap> gap> # - plain lists (dense, sorted, homogeneous, ...) gap> l:= [ 2, 3, 5, 7, 11 ]; [ 2, 3, 5, 7, 11 ] gap> IsList( l ); true gap> Length( l ); 5 gap> gap> # - element and sublist access and assignment gap> l[1]; 2 gap> l[1]:= 0;; gap> l; [ 0, 3, 5, 7, 11 ] gap> l[10]:= (1,2);; gap> l; # a non-dense list [ 0, 3, 5, 7, 11,,,,, (1,2) ] gap> Length( l ); 10 gap> l[9]; Error, List Element: [9] must have an assigned value not in any function at line 202 of *stdin* you can 'return;' after assigning a value brk> quit; gap> IsBound( l[9] ); false gap> IsDenseList( l ); true gap> Unbind( l[10] ); gap> l; [ 0, -1, -2, 7, 11 ] gap> IsDenseList( l ); true gap> IsSortedList( [ 2, 3, , 5 ] ); # non-dense lists are never sorted false gap> IsSortedList( [ 2, 3, 5 ] ); true gap> l{ [ 2, 3 ] }; # sublist access [ -1, -2 ] gap> l{ [ 2, 3 ] }:= [ -1, -2 ];; # sublist assignment gap> l; [ 0, -1, -2, 7, 11 ] gap> # - common subobjects gap> l2:= [ l, l ]; [ [ 0, -1, -2, 7, 11 ], [ 0, -1, -2, 7, 11 ] ] gap> l[1]:= true;; gap> l2; [ [ true, -1, -2, 7, 11 ], [ true, -1, -2, 7, 11 ] ] gap> gap> # - mutability gap> l3:= Immutable( l ); # create an immutable copy [ true, -1, -2, 7, 11 ] gap> l = l3; # same entries at the same positions true gap> l3[1]:= false; Error, Lists Assignment: must be a mutable list not in any function at line 220 of *stdin* you can 'return;' and ignore the assignment brk> quit; gap> gap> # - sortedness: linear vs. binary search, store knowledge gap> l:= [];; gap> for i in [ 1 .. 100000 ] do l[i]:= [ i ]; od; gap> IsSSortedList( l ); # strictly sorted true gap> Position( l, [ 99000 ] ); 99000 gap> for i in [ 1 .. 1000 ] do Position( l, [ 99000 ] ); od; time; 836 gap> for i in [ 1 .. 1000 ] do PositionSorted( l, [ 99000 ] ); od; time; 4 gap> l2:= [];; gap> for i in [ 1 .. 100000 ] do l2[i]:= Immutable( [ i ] ); od; gap> for i in [ 1 .. 1000 ] do Position( l2, [ 99000 ] ); od; time; 740 gap> IsSSortedList( l2 ); true gap> for i in [ 1 .. 1000 ] do Position( l2, [ 99000 ] ); od; time; 0 gap> HasIsSSortedList( l ); false gap> HasIsSSortedList( l2 ); true gap> gap> # - ranges gap> r:= [ 2 .. 10 ]; [ 2 .. 10 ] gap> Length( r ); 9 gap> r[2]; 3 gap> r2:= [ 3, 5 .. 11 ]; [ 3, 5 .. 11 ] gap> Length( r2 ); 5 gap> Intersection( r, r2 ); [ 3, 5 .. 9 ] gap> [ 10 .. 2 ]; [ ] gap> [ 10, 9 .. 2 ]; [ 10, 9 .. 2 ] gap> l:= []; [ ] gap> for i in [ 1 .. 10000 ] do l[i]:= i; od; gap> l = [ 1 .. 10000 ]; # the same entries at the same positions true gap> MemoryUsage( l ); 96184 gap> MemoryUsage( [ 1 .. 10000 ] ); 48 gap> gap> # - list arithmetics gap> [ 1, 2, , 4 ] + [ 1, , 1, 1, 1 ]; [ 2, 2, 1, 5, 1 ] gap> 2 * [ 1, 2, 3 ]; [ 2, 4, 6 ] gap> Z(2) * [ 1, 2, 3 ]; [ Z(2)^0, 0*Z(2), Z(2)^0 ] gap> [ 1, 1, , 1 ] * [ 1, 2, 3, 4, 5 ]; 7 gap> m:= [ [ 1, 2 ], [ 3, 4 ] ]; [ [ 1, 2 ], [ 3, 4 ] ] gap> m + 1; [ [ 2, 3 ], [ 4, 5 ] ] gap> 2 * m; [ [ 2, 4 ], [ 6, 8 ] ] gap> [ 1, 2 ] + m; [ [ 2, 4 ], [ 4, 6 ] ] gap> m^2; [ [ 7, 10 ], [ 15, 22 ] ] gap> [ 1, 2 ] * m; [ 7, 10 ] gap> m * [ 1, 2 ]; [ 5, 11 ] gap> gap> # - other representations of vectors/ matrices gap> # (less flexible, more efficient) gap> m:= IdentityMat( 6 ) * Z(5)^0; [ [ Z(5)^0, 0*Z(5), 0*Z(5), 0*Z(5), 0*Z(5), 0*Z(5) ], [ 0*Z(5), Z(5)^0, 0*Z(5), 0*Z(5), 0*Z(5), 0*Z(5) ], [ 0*Z(5), 0*Z(5), Z(5)^0, 0*Z(5), 0*Z(5), 0*Z(5) ], [ 0*Z(5), 0*Z(5), 0*Z(5), Z(5)^0, 0*Z(5), 0*Z(5) ], [ 0*Z(5), 0*Z(5), 0*Z(5), 0*Z(5), Z(5)^0, 0*Z(5) ], [ 0*Z(5), 0*Z(5), 0*Z(5), 0*Z(5), 0*Z(5), Z(5)^0 ] ] gap> ConvertToMatrixRep( m ); 5 gap> m; < mutable compressed matrix 6x6 over GF(5) > gap> m:= RandomMat( 50, 50 ) * Z(5)^0;; gap> m^100000;; time; 72 gap> ConvertToMatrixRep( m ); 5 gap> m^100000;; time; 0 gap> gap> # - strings and characters gap> s:= "Hello, world!"; "Hello, world!" gap> IsList( s ); # strings are lists true gap> s[2]; # entries of strings are characters 'e' gap> Print( s, " ", s, " ", s ); Hello, world! Hello, world! Hello, world! gap> Sort( s ); s; " !,Hdellloorw" gap> String( [ 1, 2, 3, 4, 5 ] ); "[ 1, 2, 3, 4, 5 ]" gap> gap> # - shortcuts for common loops gap> l:= [ 1 .. 100 ];; gap> List( l, x -> 2 * x ); [ 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 188, 190, 192, 194, 196, 198, 200 ] gap> Filtered( l, IsPrimeInt ); [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 ] gap> First( l, x -> x > 40 ); 41 gap> ForAll( l, IsEvenInt ); false gap> ForAny( l, IsEvenInt ); true gap> gap> ######################################################################### gap> # Records gap> gap> # - label/value pairs gap> r:= rec( number:= 1, boolean:= true, perm:= (1,2,3) ); rec( boolean := true, number := 1, perm := (1,2,3) ) gap> IsRecord( r ); true gap> gap> # - component access and assignment gap> r.number; 1 gap> r.list; Error, Record: '.list' must have an assigned value not in any function at line 297 of *stdin* you can 'return;' after assigning a value brk> quit; gap> IsBound( r.list ); true gap> r.list:= [ 1, 2, 3 ]; [ 1, 2, 3 ] gap> r; rec( boolean := true, list := [ 1, 2, 3 ], number := 1 ) gap> Unbind( r.perm ); gap> r; rec( boolean := true, list := [ 1, 2, 3 ], number := 1 ) gap> gap> # - common subobjects, mutability (similar to lists) gap> r2:= rec( a:= r.list ); rec( a := [ 1, 2, 3 ] ) gap> r.list[1]:= 0; 0 gap> r2; rec( a := [ 0, 2, 3 ] ) gap> MakeImmutable( r2 ); # do not make a copy rec( a := [ 0, 2, 3 ] ) gap> r.list[2]:= 7; Error, Lists Assignment: must be a mutable list not in any function at line 308 of *stdin* you can 'return;' and ignore the assignment brk> quit; gap> gap> ######################################################################### gap> # Customization gap> gap> # - `~/.gap` directory gap> GAPInfo.UserGapRoot; "/home/sam/.gap" gap> gap> # - user preferences gap> LoadPackage( "browse" );; gap> UserPreference( "HelpViewers" ); [ "screen" ] gap> BrowseUserPreferences(); gap> UserPreference( "HelpViewers" ); [ "screen" ] gap> SetHelpViewer( "screen", "firefox", "xpdf" ); gap> UserPreference( "HelpViewers" ); [ "screen", "firefox", "xpdf" ] gap> SizeScreen(); [ 80, 52 ] gap> ######################################################################### gap> # Domains gap> gap> # - notions of generation gap> f:= FreeGroup( 2 ); gap> GeneratorsOfGroup( f ); [ f1, f2 ] gap> GeneratorsOfMonoid( f ); [ f1^-1, f1, f2^-1, f2 ] gap> gens:= GeneratorsOfSemigroup( f ); [ , f1^-1, f1, f2^-1, f2 ] gap> IsGroup( f ); IsMonoid( f ); IsSemigroup( f ); true true true gap> IsDomain( f ); true gap> IsSubset( f, gens ); true gap> gens[1] in f; true gap> gap> # - operations for groups gap> g:= SymmetricGroup( 4 ); Sym( [ 1 .. 4 ] ) gap> GeneratorsOfGroup( g ); [ (1,2,3,4), (1,2) ] gap> DerivedSubgroup( g ); Alt( [ 1 .. 4 ] ) gap> SylowSubgroup( g, 2 ); Group([ (1,2), (3,4), (1,3)(2,4) ]) gap> HasDerivedSubgroup( g ); true gap> ComputedSylowSubgroups( g ); [ 2, Group([ (1,2), (3,4), (1,3)(2,4) ]) ] gap> gap> # - fields as domains gap> Size( Rationals ); infinity gap> GeneratorsOfField( GF(27) ); [ Z(3^3) ] gap> GaloisGroup( GF(16) ); gap> Size( last ); 4 gap> gap> # - vector spaces as domains gap> BasisVectors( Basis( Rationals^3 ) ); [ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ] gap> GeneratorsOfVectorSpace( GF(2)^2 ); [ , ] gap> gap> # - algebras as domains gap> a:= Rationals^[2,2]; ( Rationals^[ 2, 2 ] ) gap> Dimension( a ); 4 gap> a:= GroupRing( Rationals, SymmetricGroup( 3 ) ); gap> GeneratorsOfAlgebra( a ); [ (1)*(), (1)*(1,2,3), (1)*(1,2) ] gap> gap> # - natural embeddings gap> IsSubset( GF(16), GF(4) ); true gap> gap> # - iterators gap> g:= Group( (1,2,3,4), (1,3) ); Group([ (1,2,3,4), (1,3) ]) gap> iter:= Iterator( g ); gap> elm:= NextIterator( iter ); () gap> while not IsDoneIterator( iter ) do > elm:= elm * NextIterator( iter ); > od; gap> gap> # - enumerators gap> enum:= Enumerator( g ); gap> Length( enum ); 8 gap> elm:= enum[5]; (2,4) gap> Position( enum, elm ); 5 gap> gap> ######################################################################### gap> # Group example: shuffle groups gap> gap> # - read the prepared input gap> EditDemoInput( "shuffle.g" ); # close the editor in order to return to GAP ShuffleGroup( n ): ----------------- permutation group on 2n points generated by 1 --> 1 1 <-- n+1 2 <-- n+1 1 --> 2 2 --> 3 3 <-- n+2 4 <-- n+2 2 --> 4 . . . . . . . . . . . . . . . . . . . . . . . . n --> 2n-1 2n-1 <-- 2n-1 2n <-- 2n n --> 2n gap> gap> g:= ShuffleGroup( 3 ); Group([ (2,3,5,4), (1,2,4)(3,6,5) ]) gap> Size( g ); 24 gap> grps:= List( [ 1 .. 16 ], ShuffleGroup );; gap> List( grps, Size ); [ 2, 8, 24, 24, 1920, 7680, 322560, 64, 92897280, 3715891200, 40874803200, 194641920, 25505877196800, 1428329123020800, 21424936845312000, 160 ] gap> DisplayCompositionSeries( grps[5] ); G (2 gens, size 1920) | A(5) ~ A(1,4) = L(2,4) ~ B(1,4) = O(3,4) ~ C(1,4) = S(2,4) ~ 2A(1,4) = U(2,\ 4) ~ A(1,5) = L(2,5) ~ B(1,5) = O(3,5) ~ C(1,5) = S(2,5) ~ 2A(1,5) = U(2,5) S (5 gens, size 32) | Z(2) S (4 gens, size 16) | Z(2) S (3 gens, size 8) | Z(2) S (2 gens, size 4) | Z(2) S (1 gens, size 2) | Z(2) 1 (0 gens, size 1) gap> DisplayCompositionSeries( grps[6] ); G (2 gens, size 7680) | Z(2) S (9 gens, size 3840) | A(5) ~ A(1,4) = L(2,4) ~ B(1,4) = O(3,4) ~ C(1,4) = S(2,4) ~ 2A(1,4) = U(2,\ 4) ~ A(1,5) = L(2,5) ~ B(1,5) = O(3,5) ~ C(1,5) = S(2,5) ~ 2A(1,5) = U(2,5) S (6 gens, size 64) | Z(2) S (5 gens, size 32) | Z(2) S (4 gens, size 16) | Z(2) S (3 gens, size 8) | Z(2) S (2 gens, size 4) | Z(2) S (1 gens, size 2) | Z(2) 1 (0 gens, size 1) gap> DisplayCompositionSeries( grps[9] ); G (2 gens, size 92897280) | A(9) S (9 gens, size 512) | Z(2) S (8 gens, size 256) | Z(2) S (7 gens, size 128) | Z(2) S (6 gens, size 64) | Z(2) S (5 gens, size 32) | Z(2) S (4 gens, size 16) | Z(2) S (3 gens, size 8) | Z(2) S (2 gens, size 4) | Z(2) S (1 gens, size 2) | Z(2) 1 (0 gens, size 1) gap> DisplayCompositionSeries( grps[11] ); G (2 gens, size 40874803200) | Z(2) S (12 gens, size 20437401600) | A(11) S (10 gens, size 1024) | Z(2) S (9 gens, size 512) | Z(2) S (8 gens, size 256) | Z(2) S (7 gens, size 128) | Z(2) S (6 gens, size 64) | Z(2) S (5 gens, size 32) | Z(2) S (4 gens, size 16) | Z(2) S (3 gens, size 8) | Z(2) S (2 gens, size 4) | Z(2) S (1 gens, size 2) | Z(2) 1 (0 gens, size 1) gap> DisplayCompositionSeries( grps[12] ); G (2 gens, size 194641920) | M(12) S (11 gens, size 2048) | Z(2) S (10 gens, size 1024) | Z(2) S (9 gens, size 512) | Z(2) S (8 gens, size 256) | Z(2) S (7 gens, size 128) | Z(2) S (6 gens, size 64) | Z(2) S (5 gens, size 32) | Z(2) S (4 gens, size 16) | Z(2) S (3 gens, size 8) | Z(2) S (2 gens, size 4) | Z(2) S (1 gens, size 2) | Z(2) 1 (0 gens, size 1) gap> g:= grps[5]; Group([ (2,3,5,9,8,6)(4,7), (1,2,4,8,5,10,9,7,3,6) ]) gap> Size( g ); 1920 gap> Factorial( 10 ); 3628800 gap> IsPerfect( g ); false gap> der:= DerivedSubgroup( g );; gap> Size( der ); 960 gap> cen:= Centre( g );; gap> Size( cen ); 2 gap> Size( Intersection( der, cen ) ); 1 gap> IsPerfect( der ); true gap> cser:= CompositionSeries( der );; gap> List( cser, Size ); [ 960, 16, 8, 4, 2, 1 ] gap> IsElementaryAbelian( cser[2] ); true gap> GeneratorsOfGroup( cser[2] ); [ (4,7)(5,6), (1,10)(5,6), (2,9)(5,6), (3,8)(4,7) ] gap> gap> ######################################################################### gap> # Group example: Sym(4) acting on a cube gap> gap> # - read the prepared input gap> EditDemoInput( "s4.g" ); # close the editor in order to return to GAP Automorphisms of a Cube: ----------------------- 2 ___________ 1 _ y /| /| /| / | / | / 3 /__|_______/4 | -/----> x | | | | | |_______|__| | / 8 | / 7 |/ |/ |__________| 5 6 g: group generated by rotations x, y (around x- and y-axes) gap> x; (1,4,6,7)(2,3,5,8) gap> y; (1,7,8,2)(3,4,6,5) gap> Size( g ); 24 gap> gap> # - common actions gap> 1^x; 4 gap> OnPoints( 1, x ); 4 gap> OnTuples( [ 1, 2 ], x ); [ 4, 3 ] gap> OnSets( [ 1, 2 ], x ); [ 3, 4 ] gap> OnSetsSets( [ [ 1, 2 ], [ 1, 7 ] ], x ); [ [ 1, 4 ], [ 3, 4 ] ] gap> gap> # - action on 6 faces gap> faces:= Orbit( g, [ 1, 2, 3, 4 ], OnSets ); [ [ 1, 2, 3, 4 ], [ 3, 4, 5, 6 ], [ 1, 4, 6, 7 ], [ 5, 6, 7, 8 ], [ 1, 2, 7, 8 ], [ 2, 3, 5, 8 ] ] gap> Stabilizer( g, faces[1], OnSets ); Group([ (1,3)(2,4)(5,7)(6,8), (1,2,3,4)(5,6,7,8) ]) gap> Permutation( x, faces, OnSets ); (1,2,4,5) gap> op1:= Action( g, faces, OnSets ); Group([ (1,2,4,5), (1,3,4,6) ]) gap> Size( op1 ); 24 gap> gap> # - action on 12 edges gap> edges:= Orbit( g, [ 1, 2 ], OnSets ); [ [ 1, 2 ], [ 3, 4 ], [ 1, 7 ], [ 5, 6 ], [ 4, 6 ], [ 1, 4 ], [ 7, 8 ], [ 3, 5 ], [ 6, 7 ], [ 2, 8 ], [ 5, 8 ], [ 2, 3 ] ] gap> op2:= Action( g, edges, OnSets ); Group([ (1,2,4,7)(3,6,5,9)(8,11,10,12), (1,3,7,10)(2,5,4,8)(6,9,11,12) ]) gap> Size( op2 ); 24 gap> gap> # - action on 4 diagonals gap> diagonals:= Orbit( g, [ 1, 5 ], OnSets ); [ [ 1, 5 ], [ 4, 8 ], [ 3, 7 ], [ 2, 6 ] ] gap> Stabilizer( g, diagonals[1], OnSets ); Group([ (2,4,7)(3,6,8), (1,5)(2,8)(3,7)(4,6) ]) gap> op3:= Action( g, diagonals, OnSets ); Group([ (1,4)(2,3), (1,3)(2,4), (1,2,4,3), (2,3,4) ]) gap> Size( op3 ); 24 gap> gap> # - action on 3 pairs of opposite faces gap> facepairs:= Orbit( g, [ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ] ], OnSetsSets ); [ [ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ] ], [ [ 1, 2, 7, 8 ], [ 3, 4, 5, 6 ] ], [ [ 1, 4, 6, 7 ], [ 2, 3, 5, 8 ] ] ] gap> hom:= ActionHomomorphism( g, facepairs, OnSetsSets ); gap> op4:= Image( hom ); Group([ (1,2), (1,3) ]) gap> Size( op4 ); 6 gap> Kernel( hom ); Group([ (1,8)(2,7)(3,6)(4,5), (1,6)(2,5)(3,8)(4,7) ]) gap> gap> # - action on 6 pairs of opposite edges gap> edgepairs:= Orbit( g, [ [ 1, 2 ], [ 5, 6 ] ], OnSetsSets ); [ [ [ 1, 2 ], [ 5, 6 ] ], [ [ 3, 4 ], [ 7, 8 ] ], [ [ 1, 7 ], [ 3, 5 ] ], [ [ 2, 8 ], [ 4, 6 ] ], [ [ 1, 4 ], [ 5, 8 ] ], [ [ 2, 3 ], [ 6, 7 ] ] ] gap> op5:= Action( g, edgepairs, OnSetsSets ); Group([ (1,2)(3,5,4,6), (1,3,2,4)(5,6) ]) gap> Size( op3 ); 24 gap> gap> # - action on 2 tetrahedra inside the cube gap> tetrahedra:= Orbit( g, [ 1, 3, 6, 8 ], OnSets ); [ [ 1, 3, 6, 8 ], [ 2, 4, 5, 7 ] ] gap> hom:= ActionHomomorphism( g, tetrahedra, OnSets ); gap> op6:= Image( hom ); Group([ (1,2) ]) gap> Size( op6 ); 2 gap> Kernel( hom ); Group([ (2,4,7)(3,6,8), (1,3)(2,4)(5,7)(6,8) ]) gap> gap> # - action on diagonals inside faces gap> facediagonals:= Orbit( g, [ 1, 6 ], OnSets ); [ [ 1, 6 ], [ 4, 7 ], [ 5, 7 ], [ 6, 8 ], [ 1, 8 ], [ 3, 8 ], [ 2, 7 ], [ 2, 5 ], [ 2, 4 ], [ 1, 3 ], [ 3, 6 ], [ 4, 5 ] ] gap> hom:= ActionHomomorphism( g, facediagonals, OnSets ); gap> op7:= Image( hom ); Group([ (1,2)(3,5,9,11)(4,7,10,12)(6,8), (1,3,6,9)(2,4,8,10)(5,7)(11,12) ]) gap> Size( op7 ); 24 gap> gap> # - properties of actions gap> IsPrimitive( g, [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); false gap> Blocks( g, [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); [ [ 1, 3, 6, 8 ], [ 2, 4, 5, 7 ] ] gap> Blocks( g, [ 1, 2, 3, 4, 5, 6, 7, 8 ], [ 1, 5 ] ); [ [ 1, 5 ], [ 2, 6 ], [ 3, 7 ], [ 4, 8 ] ] gap> gap> # - action on cosets of a Sylow 3 subgroup gap> tr:= RightTransversal( g, SylowSubgroup( g, 3 ) );; gap> Action( g, tr, OnRight ); Group([ (1,6,2,5)(3,8,4,7), (1,5,4,7)(2,8,3,6) ]) gap> gap> ######################################################################### gap> # Group example: Automorphisms of Sym(6) gap> gap> # 1. Naive approach gap> g:= SymmetricGroup( 6 ); Sym( [ 1 .. 6 ] ) gap> gens:= GeneratorsOfGroup( g ); [ (1,2,3,4,5,6), (1,2) ] gap> a:= AutomorphismGroup( g ); gap> inner:= Group( List( gens, x -> InnerAutomorphism( g, x ) ) ); gap> Size( g ); 720 gap> Size( inner ); 720 gap> Size( a ); 1440 gap> First( GeneratorsOfGroup( a ), x -> not x in inner ); [ (5,6), (1,2,3,4,5) ] -> [ (1,2)(3,5)(4,6), (1,2,3,4,5) ] gap> gap> # 2. Do not compute the automorphism group. gap> ccl:= ConjugacyClasses( g );; gap> List( ccl, Size ); [ 1, 15, 45, 15, 40, 120, 40, 90, 90, 144, 120 ] gap> reps:= List( ccl, Representative ); [ (), (1,2), (1,2)(3,4), (1,2)(3,4)(5,6), (1,2,3), (1,2,3)(4,5), (1,2,3)(4,5,6), (1,2,3,4), (1,2,3,4)(5,6), (1,2,3,4,5), (1,2,3,4,5,6) ] gap> List( reps, Order ); [ 1, 2, 2, 2, 3, 6, 3, 4, 4, 5, 6 ] gap> for elm in ccl[2] do > map:= GroupGeneralMappingByImages( g, g, [ (1,2,3,4,5,6), (1,2) ], > [ (1,2,3,4,5,6), elm ] ); > if IsGroupHomomorphism( map ) and not map in inner then > Print( "found!\n" ); > break; > fi; > od; gap> for elm in ccl[4] do > map:= GroupGeneralMappingByImages( g, g, [ (1,2,3,4,5,6), (1,2) ], > [ (1,2,3,4,5,6), elm ] ); > if IsGroupHomomorphism( map ) and not map in inner then > Print( "found!\n" ); > break; > fi; > od; gap> for elm in ccl[4] do > map:= GroupGeneralMappingByImages( g, g, [ (1,2,3,4,5,6), (1,2) ], > [ (1,2,3)(4,5), elm ] ); > if IsGroupHomomorphism( map ) and not map in inner then > Print( "found!\n" ); > break; > fi; > od; found! gap> map; [ (1,2,3,4,5,6), (1,2) ] -> [ (1,2,3)(4,5), (1,2)(3,4)(5,6) ] gap> gap> ######################################################################### gap> # Group example: fixed point free elements in Sym(n) gap> gap> # - naive approach gap> fpf:= n -> Number( SymmetricGroup( n ), x -> NrMovedPoints( x ) = n ); function( n ) ... end gap> fpf( 1 ); fpf( 2 ); fpf( 3 ); 0 1 2 gap> for n in [ 2 .. 20 ] do > Print( [ n, Factorial( n ), Float( Factorial( n ) / fpf( n ) ) ], "\n" ); > od; [ 2, 2, 2 ] [ 3, 6, 3 ] [ 4, 24, 2.666666666666667 ] [ 5, 120, 2.727272727272727 ] [ 6, 720, 2.716981132075472 ] [ 7, 5040, 2.718446601941748 ] [ 8, 40320, 2.718263331760264 ] [ 9, 362880, 2.71828369389345 ] [ 10, 3628800, 2.718281657666404 ] Error, user interrupt in iter!.rep[l] := LeftQuotient( re, iter!.rep[l - 1] ) ; at /gap/gap4r8/lib/stbc.gi:1762 called from func( elm ) at /gap/gap4r8/lib/coll.gi:1534 called from CallFuncList( NumberOp, arg ) at /gap/gap4r8/lib/coll.gi:1518 called from Number( SymmetricGroup( n ), function ( x ) return NrMovedPoints( x ) = n; end ) at *stdin*:148 called from fpf( n ) at *stdin*:151 called from ( ) called from read-eval loop at line 152 of *stdin* you can 'return;' brk> quit; gap> gap> # - try to be more clever gap> fpf2:= function( n ) > local ccl; > ccl:= ConjugacyClasses( SymmetricGroup( n ) ); > return Sum( List( Filtered( ccl, > c -> NrMovedPoints( Representative( c ) ) = n ), > Size ), > 0 ); > end; function( n ) ... end gap> for n in [ 2 .. 20 ] do > Print( [ n, Factorial( n ), Float( Factorial( n ) / fpf2( n ) ) ], "\n" ); > od; [ 2, 2, 2 ] [ 3, 6, 3 ] [ 4, 24, 2.666666666666667 ] [ 5, 120, 2.727272727272727 ] [ 6, 720, 2.716981132075472 ] [ 7, 5040, 2.718446601941748 ] [ 8, 40320, 2.718263331760264 ] [ 9, 362880, 2.71828369389345 ] [ 10, 3628800, 2.718281657666404 ] [ 11, 39916800, 2.718281842777827 ] [ 12, 479001600, 2.718281827351874 ] [ 13, 6227020800, 2.718281828538486 ] [ 14, 87178291200, 2.718281828453728 ] [ 15, 1307674368000, 2.718281828459379 ] [ 16, 20922789888000, 2.718281828459026 ] [ 17, 355687428096000, 2.718281828459046 ] [ 18, 6402373705728000, 2.718281828459045 ] [ 19, 121645100408832000, 2.718281828459045 ] [ 20, 2432902008176640000, 2.718281828459045 ] gap> # what is the limit for n -> infinity ? gap> gap> ######################################################################### gap> # Group example: Rubik's cube gap> gap> EditDemoInput( "rubik.g" ); # close the editor in order to return to GAP Rubik's cube, as a perm. group on 48 points: -------------------------------------------- +--------------+ | 1 2 3 | | 4 top 5 | | 6 7 8 | +--------------+--------------+--------------+--------------+ | 9 10 11 | 17 18 19 | 25 26 27 | 33 34 35 | | 12 left 13 | 20 front 21 | 28 right 29 | 36 rear 37 | | 14 15 16 | 22 23 24 | 30 31 32 | 38 39 40 | +--------------+--------------+--------------+--------------+ | 41 42 43 | | 44 bottom 45 | | 46 47 48 | +--------------+ cube: group generated by rotations of the six faces gap> gap> top; (1,3,8,6)(2,5,7,4)(9,33,25,17)(10,34,26,18)(11,35,27,19) gap> cube; gap> size:= Size( cube ); 43252003274489856000 gap> Collected( Factors( size ) ); [ [ 2, 27 ], [ 3, 14 ], [ 5, 3 ], [ 7, 2 ], [ 11, 1 ] ] gap> orbits:= Orbits( cube, [ 1 .. 48 ] ); [ [ 1, 3, 17, 14, 8, 38, 9, 41, 19, 48, 22, 6, 30, 33, 43, 11, 46, 40, 24, 27, 25, 35, 16, 32 ], [ 2, 5, 12, 7, 36, 10, 47, 4, 28, 45, 34, 13, 29, 44, 20, 42, 26, 21, 37, 15, 31, 18, 23, 39 ] ] gap> cube1:= Action( cube, orbits[1] ); gap> Size( cube1 ); 88179840 gap> vertices:= Blocks( cube1, [ 1 .. 24 ] ); [ [ 1, 7, 22 ], [ 2, 14, 20 ], [ 3, 12, 16 ], [ 4, 17, 18 ], [ 5, 9, 21 ], [ 6, 10, 24 ], [ 8, 11, 23 ], [ 13, 15, 19 ] ] gap> gap> # - action on the vertices gap> blockhom1:= ActionHomomorphism( cube1, vertices, OnSets );; gap> cube1b:= Image( blockhom1 ); Group([ (1,2,4,3), (1,3,6,5), (1,5,8,2), (3,4,7,6), (5,6,7,8), (2,8,7,4) ]) gap> Size( cube1b ); Factorial( 8 ); 40320 40320 gap> Factors( Size( Kernel( blockhom1 ) ) ); [ 3, 3, 3, 3, 3, 3, 3 ] gap> IsElementaryAbelian( Kernel( blockhom1 ) ); true gap> cmpl1:= Stabilizer( cube1, [1,2,3,4,5,6,8,13], OnSets );; gap> Size( cmpl1 ); 40320 gap> Size( Intersection( cmpl1, Kernel( blockhom1 ) ) ); 1 gap> ClosureGroup( cmpl1, Kernel( blockhom1 ) ) = cube1; true gap> (1,7,22) in cube1; false gap> (1,7,22)(2,20,14) in cube1; true gap> gap> # - action on the edges gap> cube2:= Action( cube, orbits[2] );; gap> Size( cube2 ); 980995276800 gap> edges:= Blocks( cube2, [ 1 .. 24 ] ); [ [ 1, 11 ], [ 2, 17 ], [ 3, 19 ], [ 4, 22 ], [ 5, 13 ], [ 6, 8 ], [ 7, 24 ], [ 9, 18 ], [ 10, 21 ], [ 12, 15 ], [ 14, 20 ], [ 16, 23 ] ] gap> blockhom2:= ActionHomomorphism( cube2, edges, OnSets );; gap> cube2b:= Image( blockhom2 ); Group([ (1,3,4,2), (1,5,11,10), (2,6,7,5), (3,10,12,8), (4,8,9,6), (7,9,12, 11) ]) gap> Size( cube2b ); 479001600 gap> Factors( Size( Kernel( blockhom2 ) ) ); [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] gap> IsElementaryAbelian( Kernel( blockhom2 ) ); true gap> cmpl2:= Stabilizer( cube2, [1,2,3,4,5,6,7,9,10,12,14,16], OnSets );; gap> Size( cmpl2 ); Factorial( 12 ); 479001600 479001600 gap> Size( Intersection( cmpl2, Kernel( blockhom2 ) ) ); 1 gap> ClosureGroup( cmpl2, Kernel( blockhom2 ) ) = cube2; true gap> (1,11) in cube2; false gap> (1,11)(2,17) in cube2; true gap> gap> # - put the results of the two actions together gap> Size( cube ); 43252003274489856000 gap> Size( cube1 ) * Size( cube2 ); 86504006548979712000 gap> Intersection( Kernel( blockhom1 ), Kernel( blockhom2 ) ); Group(()) gap> (17,19)(11,8)(6,25) in cube; false gap> (7,28)(18,21) in cube; false gap> (17,19)(11,8)(6,25)(7,28)(18,21) in cube; true gap> Centre( cube ); Group([ (2,34)(4,10)(5,26)(7,18)(12,37)(13,20)(15,44)(21,28)(23,42)(29,36) (31,45)(39,47) ]) gap> gap> ######################################################################### gap> # Group example: Symmetries of a regular icosahedron gap> gap> # look at the 3-dimensional situation gap> UrlOpen( Concatenation( "file://", Filename( demodir, "icos.pdf" ) ) ); gap> gap> # close the PDF viewer gap> gap> # load the input data gap> EditDemoInput( "icos.g" ); # close the editor in order to return to GAP Icosahedron: ----------- The 12 vertices have coordinates (0,+-b,+-1), cyclicly permuted, where b = ( 1 + sqrt{5} ) / 2. mat1: permutation of coordinate axes mat2: rotation that fixes (0,b,1) mat3: reflection in the origin g: group generated by mat1, mat2, mat3 gap> gap> b; -E(5)^2-E(5)^3 gap> mat1; [ [ 0, 1, 0 ], [ 0, 0, 1 ], [ 1, 0, 0 ] ] gap> mat2; [ [ 1/2*E(5)+1/2*E(5)^4, 1/2, 1/2*E(5)^2+1/2*E(5)^3 ], [ -1/2, -1/2*E(5)^2-1/2*E(5)^3, 1/2*E(5)+1/2*E(5)^4 ], [ -1/2*E(5)^2-1/2*E(5)^3, 1/2*E(5)+1/2*E(5)^4, 1/2 ] ] gap> p1:= [ 0, b, 1 ]; [ 0, -E(5)^2-E(5)^3, 1 ] gap> p1 * mat2; [ 0, -E(5)^2-E(5)^3, 1 ] gap> Order( mat2 ); 5 gap> Size( g ); 120 gap> gap> # - do not use the geometry gap> permiso:= IsomorphismPermGroup( g ); gap> Image( permiso ); Group([ (2,4,7)(5,9,14)(6,8,13)(10,16,12)(11,15,20)(17,18,19), (1,2,5,10,4) (3,6,11,17,8)(7,12,18,20,9)(13,19,16,14,15), (1,3)(2,6)(4,8)(5,11)(7,13)(9,15) (10,17)(12,19)(14,20)(16,18) ]) gap> gap> # - act on vertices of the icosahedron gap> orb1:= Set( Orbit( g, p1 ) ); [ [ -1, 0, -E(5)^2-E(5)^3 ], [ -1, 0, E(5)^2+E(5)^3 ], [ 0, -E(5)^2-E(5)^3, -1 ], [ 0, -E(5)^2-E(5)^3, 1 ], [ 0, E(5)^2+E(5)^3, -1 ], [ 0, E(5)^2+E(5)^3, 1 ], [ 1, 0, -E(5)^2-E(5)^3 ], [ 1, 0, E(5)^2+E(5)^3 ], [ -E(5)^2-E(5)^3, -1, 0 ], [ -E(5)^2-E(5)^3, 1, 0 ], [ E(5)^2+E(5)^3, -1, 0 ], [ E(5)^2+E(5)^3, 1, 0 ] ] gap> op1:= Action( g, orb1 ); Group([ (1,9,3)(2,11,5)(4,7,10)(6,8,12), (1,7,10,3,12)(2,11,6,9,8), (1,8)(2,7) (3,6)(4,5)(9,12)(10,11) ]) gap> Size( op1 ); 120 gap> IsPrimitive( g, orb1 ); false gap> bl1:= Blocks( g, orb1 );; gap> bl1[1]; [ [ -1, 0, -E(5)^2-E(5)^3 ], [ 1, 0, E(5)^2+E(5)^3 ] ] gap> blop1:= Action( g, bl1, OnSets ); Group([ (1,5,3)(2,6,4), (1,2,6,3,5), () ]) gap> Size( blop1 ); 60 gap> gap> # - act on faces of the icosahedron gap> p2:= [ 1, 1, 1 ];; gap> orb2:= Orbit( g, p2 );; gap> Length( orb2 ); 20 gap> bl2:= Blocks( g, orb2 );; gap> bl2[1]; [ [ -1, -1, -1 ], [ 1, 1, 1 ] ] gap> blop2:= Action( g, bl2, OnSets ); Group([ (2,4,3)(5,9,7)(6,10,8), (1,8,7,4,6)(2,3,9,5,10), () ]) gap> IsPrimitive( blop2, [ 1 .. 10 ] ); true gap> gap> # - subgroup of rotation symmetries gap> sg:= Group( mat1, mat2 );; gap> Size( sg ); 60 gap> bl3:= Blocks( sg, orb2 ); [ [ [ -1, -1, -1 ], [ -1, 1, 1 ], [ 1, -1, 1 ], [ 1, 1, -1 ] ], [ [ -1, -1, 1 ], [ 0, -E(5)-E(5)^4, E(5)^2+E(5)^3 ], [ -E(5)-E(5)^4, -E(5)^2-E(5)^3, 0 ], [ -E(5)^2-E(5)^3, 0, E(5)+E(5)^4 ] ], [ [ -1, 1, -1 ], [ 0, E(5)+E(5)^4, -E(5)^2-E(5)^3 ], [ -E(5)-E(5)^4, E(5)^2+E(5)^3, 0 ], [ -E(5)^2-E(5)^3, 0, -E(5)-E(5)^4 ] ], [ [ 0, -E(5)-E(5)^4, -E(5)^2-E(5)^3 ], [ 1, -1, -1 ], [ E(5)^2+E(5)^3, 0, -E(5)-E(5)^4 ], [ E(5)+E(5)^4, -E(5)^2-E(5)^3, 0 ] ] , [ [ 0, E(5)+E(5)^4, E(5)^2+E(5)^3 ], [ 1, 1, 1 ], [ E(5)^2+E(5)^3, 0, E(5)+E(5)^4 ], [ E(5)+E(5)^4, E(5)^2+E(5)^3, 0 ] ] ] gap> Length( bl3 ); 5 gap> Action( sg, bl3, OnSets ); Group([ (2,4,3), (1,3,5,4,2) ]) gap> gap> # - action on 5 cubes and stabilizer of a cube gap> cube:= Union( bl3[1], -bl3[1] ); [ [ -1, -1, -1 ], [ -1, -1, 1 ], [ -1, 1, -1 ], [ -1, 1, 1 ], [ 1, -1, -1 ], [ 1, -1, 1 ], [ 1, 1, -1 ], [ 1, 1, 1 ] ] gap> orb3:= Orbit( g, cube, OnSets );; gap> Action( g, orb3, OnSets ); Group([ (2,3,5), (1,2,4,5,3), () ]) gap> stab:= Stabilizer( g, cube, OnSets ); gap> GeneratorsOfGroup( stab ); [ [ [ 0, 1, 0 ], [ 0, 0, 1 ], [ 1, 0, 0 ] ], [ [ -1, 0, 0 ], [ 0, -1, 0 ], [ 0, 0, -1 ] ], [ [ 0, 0, -1 ], [ -1, 0, 0 ], [ 0, 1, 0 ] ] ] gap> gap> ######################################################################### gap> # Group example: Some triangle groups (finitely presented groups) gap> gap> f:= FreeGroup( 2 ); gap> rels:= function( f, n ) > return [ f.1^2, f.2^3, (f.1*f.2)^n ]; > end; function( f, n ) ... end gap> gap> g:= f / rels( f, 3 ); Size( g ); 12 gap> g:= f / rels( f, 4 ); Size( g ); 24 gap> g:= f / rels( f, 5 ); Size( g ); 60 gap> g:= f / rels( f, 6 ); Size( g ); #I Coset table calculation failed -- trying with bigger table limit Error, user interrupt in app[11] := firstDef; at /gap/gap4r8/lib/grpfp.gi:1237 called from TCENUM.CosetTableFromGensAndRels( fgens, grels, fsgens ) at /gap/gap4r8/lib/grpfp.gi:1032 called from CosetTableFromGensAndRels( fgens, grels, List( trial, UnderlyingElement ) ) at /gap/gap4r8/lib/grpfp.gi:3699 called from Attempt( gens ) at /gap/gap4r8/lib/grpfp.gi:3724 called from FinIndexCyclicSubgroupGenerator( G, infinity ) at /gap/gap4r8/lib/grpfp.gi:3773 called from ( ) called from read-eval loop at line 286 of *stdin* you can 'return;' brk> quit; #I Options stack has been reset gap> gap> der:= DerivedSubgroup( g ); Group() gap> AbelianInvariants( der ); # the group is infinite [ 0, 0 ] gap> gap> g:= f / rels( f, 8 ); gap> der:= DerivedSubgroup( g ); Group() gap> Index( g, der ); 2 gap> der2:= DerivedSubgroup( der ); Group() gap> Index( der, der2 ); 3 gap> der3:= DerivedSubgroup( der2 ); Group() gap> Index( der2, der3 ); 16 gap> pi:= NaturalHomomorphismByNormalSubgroup( g, der3 ); [ f1, f2 ] -> [ (1,49)(2,50)(3,51)(4,52)(5,53)(6,54)(7,55)(8,56)(9,57)(10,58)(11,59)(12, 60)(13,61)(14,62)(15,63)(16,64)(17,68)(18,71)(19,73)(20,75)(21,65)(22, 76)(23,78)(24,66)(25,79)(26,67)(27,69)(28,80)(29,70)(30,72)(31,74)(32, 77)(33,81)(34,82)(35,83)(36,84)(37,85)(38,86)(39,87)(40,88)(41,89)(42, 90)(43,91)(44,92)(45,93)(46,94)(47,95)(48,96), (1,33,17)(2,34,18)(3,35,19)(4,36,20)(5,37,21)(6,38,22)(7,39,23)(8,40,24)(9, 41,25)(10,42,26)(11,43,27)(12,44,28)(13,45,29)(14,46,30)(15,47,31)(16,48, 32)(49,65,83)(50,66,81)(51,67,86)(52,68,89)(53,69,90)(54,70,82)(55,71, 84)(56,72,85)(57,73,92)(58,74,93)(59,75,95)(60,76,87)(61,77,88)(62,78, 91)(63,79,96)(64,80,94) ] gap> Size( Image( pi ) ); 96 gap> DisplayCompositionSeries( Image( pi ) ); G (6 gens, size 96) | Z(2) S (5 gens, size 48) | Z(3) S (4 gens, size 16) | Z(2) S (3 gens, size 8) | Z(2) S (2 gens, size 4) | Z(2) S (1 gens, size 2) | Z(2) 1 (0 gens, size 1) gap> AbelianInvariants( der3 ); [ 0, 0, 0, 0, 0, 0 ] gap> # der3 is a torsion-free group gap> gap> ######################################################################### gap> # Mappings gap> gap> # - via action gap> g:= SymmetricGroup( 4 ); Sym( [ 1 .. 4 ] ) gap> tr:= RightTransversal( g, Group( (1,2) ) ); RightTransversal(Sym( [ 1 .. 4 ] ),Group([ (1,2) ])) gap> hom:= ActionHomomorphism( g, tr, OnRight ); gap> Range( hom ); Sym( [ 1 .. 12 ] ) gap> Image( hom ); Group([ (1,10,5,9)(2,12,4,8)(3,11,6,7), (2,3)(4,7)(5,8)(6,9)(10,11) ]) gap> IsSurjective( hom ); false gap> gap> # - natural epimorphism gap> n:= SubgroupNC( g, [ (1,2)(3,4), (1,3)(2,4) ] ); Group([ (1,2)(3,4), (1,3)(2,4) ]) gap> IsNormal( g, n ); true gap> epi:= NaturalHomomorphismByNormalSubgroup( g, n ); [ (1,2,3,4), (1,2) ] -> [ f1*f2, f1 ] gap> Image( epi ); Group([ f1, f2 ]) gap> Kernel( epi ); Group([ (1,2)(3,4), (1,3)(2,4) ]) gap> IsSurjective( epi ); true gap> IsInjective( epi ); false gap> inv:= Inverse( epi ); #I The mapping must be bijective and have source=range #I You might want to use `InverseGeneralMapping' fail gap> inv:= InverseGeneralMapping( epi ); [ f1*f2, f1 ] -> [ (1,2,3,4), (1,2) ] gap> IsMapping( inv ); false gap> gap> # - by images gap> h:= SymmetricGroup( 3 ); Sym( [ 1 .. 3 ] ) gap> hom:= GroupHomomorphismByImages( h, g, [ (1,2), (1,2,3) ], > [ (2,3), (2,3,4) ] ); [ (1,2), (1,2,3) ] -> [ (2,3), (2,3,4) ] gap> (1,3)^hom; (2,4) gap> gap> # - generalized mappings gap> inv:= InverseGeneralMapping( hom ); [ (2,3), (2,3,4) ] -> [ (1,2), (1,2,3) ] gap> IsMapping( inv ); true gap> gap> ######################################################################### gap> # Other Structures: fields, vector spaces, algebras gap> gap> # - finite fields gap> f:= GF(4); GF(2^2) gap> Size( f ); Dimension( f ); 4 2 gap> Basis( f ); CanonicalBasis( GF(2^2) ) gap> BasisVectors( Basis( f ) ); [ Z(2)^0, Z(2^2) ] gap> f2:= GF(256); GF(2^8) gap> f3:= AsField( f, f2 ); AsField( GF(2^2), GF(2^8) ) gap> Dimension( f2 ); Dimension( f3 ); 8 4 gap> f2 = f3; true gap> gap> # - abelian number fields gap> f:= CyclotomicField( 7 ); CF(7) gap> Sqrt( 7 ) in f; false gap> Sqrt( -7 ) in f; true gap> x:= Sqrt( 5 ); E(5)-E(5)^2-E(5)^3+E(5)^4 gap> y:= ( -1 + x ) / 2; E(5)+E(5)^4 gap> IsIntegralCyclotomic( y ); true gap> gap> # - algebraic extensions gap> x:= Indeterminate( Rationals ); x_1 gap> p:= x^2 + 1; x_1^2+1 gap> f:= AlgebraicExtension( Rationals, p ); gap> GeneratorsOfField( f ); [ a ] gap> last[1] ^ 2; !-1 gap> gap> # - row spaces gap> v:= GF(2)^4; ( GF(2)^4 ) gap> Dimension( v ); 4 gap> vec:= Random( v ); gap> LeftActingDomain( v ); GF(2) gap> m:= RandomInvertibleMat( 4, GF(2) ); [ , , , ] gap> b:= Basis( v, m ); Basis( ( GF(2)^4 ), [ , , , ] ) gap> coeff:= Coefficients( b, vec ); gap> coeff * m = vec; true gap> gap> # - matrix algebras gap> m:= [ [ 1, 2, 3 ], [ 0, 1, 6 ], [ 0, 0, 1 ] ]; [ [ 1, 2, 3 ], [ 0, 1, 6 ], [ 0, 0, 1 ] ] gap> A:= Algebra( Rationals, [ m ] ); gap> subA:= Subalgebra( A, [ m-m^2 ] ); gap> Dimension( subA ); 2 gap> idA:= Ideal( A, [ m-m^3 ] ); , (1 generators)> gap> Dimension( idA ); 2 gap> B:= A/idA; gap> gap> # - group rings gap> rg:= GroupRing( GF(4), SymmetricGroup( 3 ) ); gap> Dimension( rg ); 6 gap> id:= CentralIdempotentsOfAlgebra( rg ); [ (Z(2)^0)*()+(Z(2)^0)*(1,2,3)+(Z(2)^0)*(1,3,2), (Z(2)^0)*(1,2,3)+(Z(2)^0)*(1,3,2) ] gap> gap> # - quat. algebra gap> q:= QuaternionAlgebra( Rationals ); gap> gens:= GeneratorsOfAlgebra( q ); [ e, i, j, k ] gap> x:= Sum( gens{ [ 1 .. 3 ] } ); e+i+j gap> x^-1; (1/3)*e+(-1/3)*i+(-1/3)*j gap> IsAssociative( q ); true gap> IsCommutative( q ); false gap> bas:= CanonicalBasis( q );; gap> BasisVectors( bas ); [ e, i, j, k ] gap> op:= OperationAlgebraHomomorphism( q, bas, OnRight ); matrices of dim. 4> gap> ImagesRepresentative( op, gens[1] ); [ [ 1, 0, 0, 0 ], [ 0, 1, 0, 0 ], [ 0, 0, 1, 0 ], [ 0, 0, 0, 1 ] ] gap> ImagesRepresentative( op, gens[2] ); [ [ 0, 1, 0, 0 ], [ -1, 0, 0, 0 ], [ 0, 0, 0, -1 ], [ 0, 0, 1, 0 ] ] gap> gap> ######################################################################### gap> # Other Structures: graphs gap> gap> # use a package gap> LoadPackage( "grape" ); ───────────────────────────────────────────────────────────────────────────── Loading GRAPE 4.7 (GRaph Algorithms using PErmutation groups) by Leonard H. Soicher (http://www.maths.qmul.ac.uk/~leonard/). Homepage: http://www.maths.qmul.ac.uk/~leonard/grape/ ───────────────────────────────────────────────────────────────────────────── true gap> gap> g:= Group( (1,2)(3,4), (1,3) ); # dihedral group Group([ (1,2)(3,4), (1,3) ]) gap> gamma:= CayleyGraph( g ); rec( adjacencies := [ [ 3, 5 ] ], group := Group([ (1,3)(2,4)(5,7)(6,8), (1,5) (2,6)(3,4)(7,8) ]), isGraph := true, isSimple := true, names := [ (), (2,4), (1,2)(3,4), (1,2,3,4), (1,3), (1,3)(2,4), (1,4,3,2), (1,4)(2,3) ], order := 8, representatives := [ 1 ], schreierVector := [ -1, 1, 1, 2, 2, 2, 1, 2 ] ) gap> Adjacency( gamma, 1 ); [ 3, 5 ] gap> Diameter( gamma ); 4 gap> Distance( gamma, 1, 2 ); 3 gap> Distance( gamma, 1, 3 ); 1 gap> IsBipartite( gamma ); true gap> g:= DihedralGroup( 8 ); # dihedral group, other generators gap> gap> petersen:= Graph( SymmetricGroup( 5 ), [ [ 1, 2 ] ], OnSets, > function( x, y ) return IsEmpty( Intersection( x,y ) ); end ); rec( adjacencies := [ [ 3, 5, 8 ] ], group := Group([ (1,2,3,5,7) (4,6,8,9,10), (2,4)(6,9)(7,10) ]), isGraph := true, names := [ [ 1, 2 ], [ 2, 3 ], [ 3, 4 ], [ 1, 3 ], [ 4, 5 ], [ 2, 4 ], [ 1, 5 ], [ 3, 5 ], [ 1, 4 ], [ 2, 5 ] ], order := 10, representatives := [ 1 ], schreierVector := [ -1, 1, 1, 2, 1, 1, 1, 1, 2, 2 ] ) gap> Diameter( petersen ); 2 gap> gap> ######################################################################### gap> # Data libraries (mainly of groups) gap> gap> # - basic groups gap> gens:= GeneratorsOfGroup( GL(4,3) ); [ [ [ Z(3), 0*Z(3), 0*Z(3), 0*Z(3) ], [ 0*Z(3), Z(3)^0, 0*Z(3), 0*Z(3) ], [ 0*Z(3), 0*Z(3), Z(3)^0, 0*Z(3) ], [ 0*Z(3), 0*Z(3), 0*Z(3), Z(3)^0 ] ] , [ [ Z(3), 0*Z(3), 0*Z(3), Z(3)^0 ], [ Z(3), 0*Z(3), 0*Z(3), 0*Z(3) ], [ 0*Z(3), Z(3), 0*Z(3), 0*Z(3) ], [ 0*Z(3), 0*Z(3), Z(3), 0*Z(3) ] ] ] gap> Display( gens[1] ); 2 . . . . 1 . . . . 1 . . . . 1 gap> Display( gens[2] ); 2 . . 1 2 . . . . 2 . . . . 2 . gap> gap> # - perfect groups gap> Filtered( [ 1 .. 100 ], i -> NrPerfectGroups( i ) <> 0 ); [ 60 ] gap> g:= PerfectGroup( IsPermGroup, 168, 1 ); L3(2) gap> GeneratorsOfGroup( g ); [ (1,2)(4,5), (2,3,4)(5,6,7) ] gap> gap> # - primitive groups gap> g:= OnePrimitiveGroup( NrMovedPoints, 10, Size, 60 ); A(5) gap> GeneratorsOfGroup( g ); [ (1,5,7)(2,9,4)(3,8,10), (2,6)(3,5)(4,7)(9,10) ] gap> gap> # - small groups gap> grps:= AllSmallGroups( Size, 8, IsAbelian, false ); [ , ] gap> List( grps, g -> List( Elements( g ), Order ) ); [ [ 1, 2, 2, 2, 4, 2, 2, 4 ], [ 1, 4, 4, 2, 4, 4, 4, 4 ] ] gap> gap> # - transitive groups gap> OneTransitiveGroup( NrMovedPoints, IsPrimeInt, IsSolvableGroup, false ); #W AllTransitiveGroups: Degree restricted to [2..30] A5 gap> gap> ######################################################################### gap> # Profiling gap> gap> # 1. profile function by function gap> gap> # - switch profiling on gap> ProfileGlobalFunctions( true ); gap> ProfileOperationsAndMethods( true ); gap> gap> # - run your computations gap> g:= MathieuGroup( 24 ); Group([ (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23), (3,17, 10,7,9)(4,13,14,19,5)(8,18,11,12,23)(15,20,22,21,16), (1,24)(2,23)(3,12)(4,16) (5,18)(6,10)(7,20)(8,14)(9,21)(11,17)(13,22)(15,19) ]) gap> Size( g ); 244823040 gap> ConjugacyClasses( g );; gap> gap> # - switch profiling off gap> ProfileGlobalFunctions( false ); gap> ProfileOperationsAndMethods( false ); gap> gap> # - show profiling results gap> DisplayProfile(); count self/ms chld/ms stor/kb chld/kb package function 18078 0 0 770 0 (oprt.) ShallowCopy 12987 0 0 197 0 AddSet: for mutable i* 12235 0 0 722 0 (oprt.) Append 12106 4 0 0 0 (oprt.) IsAssociative 11938 4 0 1150 0 UniteSet: for two int* 11423 0 4 0 0 <: for a permutation,* 12987 0 4 13 197 (oprt.) AddSet 11938 0 4 76 1150 (oprt.) UniteSet 20423 4 0 638 0 GAP BasePoint 17355 20 0 12 0 <: for a permutation,* 10114 8 0 316 0 GAP IsEmpty: for a list 12534 8 4 978 0 GAP Reversed 13782 0 12 62 316 (oprt.) IsEmpty 51704 8 8 0 0 =: for two families: * 19361 12 4 0 0 (oprt.) Tester(IsAssociative) 10290 12 4 636 790 GAP ^: sliced perm 12952 16 4 439 647 GAP Concatenation 253 0 36 14 2463 (oprt.) IsSubsemigroup: for a* 275055 24 16 3 27 (oprt.) NumberOp: for a dense* 104 36 4 1167 1160 (oprt.) Permuted 8078 24 16 639 10366 GAP ChangeStabChain 2494 0 44 221 3370 GAP ForAny 8267 0 48 86 3049 (oprt.) Order: for a group 18 0 52 38 2974 GAP RightTransversalOp: g* 26 0 52 1 3082 GAP RightTransversal: try* 26 0 52 0 3082 (oprt.) RightTransversalOp 26 0 52 0 3084 (oprt.) RightTransversal 18 0 52 0 2972 GAP RightCosets 11990 12 40 686 8932 GAP ProcessFixpoint 446 0 60 160 4191 GAP TryPcgsPermGroup 20 0 68 0 8076 (oprt.) NormalizerInParent 20 0 68 1 8066 GAP NormalizerInParent: m* 273014 56 16 2896 1 (oprt.) Add 222 0 88 10 6148 GAP StabChainMutable: cal* 410 0 92 7 8111 (oprt.) StabChainOp 3267 0 92 27 6388 (oprt.) StabChainImmutable: u* 338 4 88 144 7959 GAP StabChainOp: group an* 36 0 124 0 16605 (oprt.) Normalizer 72 0 124 32 16557 GAP NormalizerPermGroup 36 0 124 2 16602 GAP Normalizer: try to ex* 36 0 124 0 16589 (oprt.) NormalizerOp 28672 276 0 0 0 (oprt.) Position 2418 12 272 188 27763 GAP in: perm class rep 226 20 264 1034 29983 GAP PartitionBacktrack 2448 4 288 1670 30343 GAP RepOpElmTuplesPermGro* 2 0 532 0 54338 (oprt.) ConjugacyClasses 1 0 532 0 53497 GAP ConjugacyClassesByRan* 1 0 532 0 54335 GAP ConjugacyClasses: per* 156 4 528 84 52860 GAP ConjugacyClassesTry 368 45290 OTHER 936 60430 TOTAL gap> gap> # - more options for this kind of profiling gap> HELP("Profiling"); gap> gap> # 2. profile line by line gap> gap> # - load the package gap> LoadPackage( "profiling" ); ───────────────────────────────────────────────────────────────────────────── Loading profiling 1.3.0 (Line by line profiling and code coverage for GAP) by Christopher Jefferson (http://caj.host.cs.st-andrews.ac.uk/). Homepage: http://gap-packages.github.io/profiling/ ───────────────────────────────────────────────────────────────────────────── true gap> gap> # - switch profiling on gap> ProfileLineByLine( "profileinfo" ); #I Profile filenames must end in .gz to enable compression true gap> gap> # - switch profiling off again gap> UnprofileLineByLine(); true gap> gap> # - switch profiling on (second attempt) gap> profiledatafile:= "profileinfo.gz";; gap> ProfileLineByLine( profiledatafile ); true gap> gap> # - run your computations gap> g:= MathieuGroup( 24 ); Group([ (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23), (3,17, 10,7,9)(4,13,14,19,5)(8,18,11,12,23)(15,20,22,21,16), (1,24)(2,23)(3,12)(4,16) (5,18)(6,10)(7,20)(8,14)(9,21)(11,17)(13,22)(15,19) ]) gap> Size( g ); 244823040 gap> ConjugacyClasses( g );; gap> gap> # - switch profiling off gap> UnprofileLineByLine(); true gap> gap> # - prepare the output files gap> profiledatadir:= "profileinfodir";; gap> OutputAnnotatedCodeCoverageFiles( profiledatafile, profiledatadir ); gap> gap> # - open a browser window with the prepared information gap> UrlOpen( Concatenation( profiledatadir, "/index.html" ) ); gap> gap> # - clean up ... gap> Exec( "rm -rf profileinfo profileinfo.gz profileinfodir" ); gap> gap> # 3. profile an individual function call gap> # (happens in a temporary directory) gap> LineByLineProfileFunction( MathieuGroup, [ 24 ] ); gap> ######################################################################### gap> # GAP's type system gap> gap> # - operations and methods gap> Size; gap> Print( Size ); gap> meth:= ApplicableMethod( Size, [ Group( (1,2,3), (1,2) ) ] ); function( G ) ... end gap> Print( meth ); function ( G ) return SizeStabChain( StabChainMutable( G ) ); end gap> PageSource( meth ); Showing source in /gap/gap4r8/lib/grpperm.gi (from line 482) gap> # enter 'q' in order to quit the pager gap> meth:= ApplicableMethod( Size, [ GF(2)^5 ] ); function( V ) ... end gap> PageSource( meth ); Showing source in /gap/gap4r8/lib/modfree.gi (from line 149) gap> # enter 'q' in order to quit the pager gap> g:= SymmetricGroup( 3 ); Sym( [ 1 .. 3 ] ) gap> meth:= ApplicableMethod( Size, [ g ] ); function( object ) ... end gap> PageSource( meth ); Cannot locate source of kernel function GetterFunc(Size). gap> HasSize( g ); # the value was already set, needs no computation true gap> gap> # - filters gap> KnownAttributesOfObject( g ); [ "Size", "NrMovedPoints", "MovedPoints", "GeneratorsOfMagmaWithInverses", "MultiplicativeNeutralElement" ] gap> KnownPropertiesOfObject( g ); [ "IsEmpty", "IsTrivial", "IsNonTrivial", "IsFinite", "CanEasilyCompareElements", "CanEasilySortElements", "IsDuplicateFree", "IsGeneratorsOfMagmaWithInverses", "IsAssociative", "IsGeneratorsOfSemigroup", "IsSimpleSemigroup", "IsRegularSemigroup", "IsInverseSemigroup", "IsCompletelyRegularSemigroup", "IsCompletelySimpleSemigroup", "IsGroupAsSemigroup", "IsMonoidAsSemigroup", "IsOrthodoxSemigroup", "IsFinitelyGeneratedGroup", "IsSubsetLocallyFiniteGroup", "KnowsHowToDecompose", "IsNaturalSymmetricGroup", "IsSymmetricGroup", "IsPrimitiveAffine", "IsNilpotentByFinite", "IsTorsionFree", "IsFreeAbelian" ] gap> CategoriesOfObject( g ); [ "IsListOrCollection", "IsCollection", "IsExtLElement", "CategoryCollections(IsExtLElement)", "IsExtRElement", "CategoryCollections(IsExtRElement)", "CategoryCollections(IsMultiplicativeElement)", "CategoryCollections(IsMultiplicativeElementWithOne)", "CategoryCollections(IsMultiplicativeElementWithInverse)", "CategoryCollections(IsAssociativeElement)", "CategoryCollections(IsFiniteOrderElement)", "IsGeneralizedDomain", "CategoryCollections(IsPerm)", "IsMagma", "IsMagmaWithOne", "IsMagmaWithInversesIfNonzero", "IsMagmaWithInverses" ] gap> RepresentationsOfObject( g ); [ "IsComponentObjectRep", "IsAttributeStoringRep" ] gap> gap> # done ... gap> quit;