# start GAP, then first read the file 'demo.g' Read( "demo.g" ); ############################################################################ # A GAP session # - some input ( 1 + 2 ) * ( 3 + 4 ); # - partial input ( 1 + 2 ) * ( 3 + 4 ) ; # simply add the missing semicolon # - erroneous input ( 1 + 2 ) / ( 3 - 3 ); # (quit the 'brk> ' mode by entering 'quit;') # - comments # This is just a comment. 1 + 2; # add two numbers # - read input from some file Read( "input_from_file" ); ############################################################################ # The GAP Language # - assignments a; # an unbound variable a:= 1; a; A; # note that GAP is case sensitive b:= 2 * a; b = a; # comparison for equality b:= a; # assignment b:= 2 * b;; # suppress GAP's output b; a; Size:= 12; # a read-only variable # (quit the 'brk> ' mode by entering 'quit;') # - infix operators a:= ( 1 + 2 ) < ( 6 - 3 ); b:= ( 1 + 2 ) <= ( 6 - 3 ); a and b; a or b; not a; # - functions square:= function( n ) return n^2; end; square( 1 ); square( 2 ); square( -1000 ); square:= ( n -> n^2 ); # just a shorter way to write simple functions # - local variables test:= function( n ) local a, b; a:= n^2; b:= a + 1; return a + b; end; a; b; test( 10 ); a; b; # the global variable are not changed # - a variadic function test2:= function( n, m... ) Print( m, "\n" ); end; test2( 0 ); test2( 0, 1 ); test2( 0, 1, 2 ); # - if statements test3:= function( n ) if n < 0 then Print( "negative\n" ); elif n = 0 then Print( "zero\n" ); else Print( "positive\n" ); fi; end;; test3( -1 ); test3( 0 ); test3( 1 ); test3( false ); # we do not get an error # - recursion fib:= function( n ) if n = 1 or n = 2 then return 1; else return fib( n-1 ) + fib( n-2 ); fi; end; fib( 3 ); # - for loop a:= 0;; for i in [ 1 .. 100 ] do a:= a + i; od; a; # - while loop a:= 0;; i:= 1;; while i <= 100 do a:= a + i; i:= i + 1; od; a; # - repeat loop a:= 0;; i:= 1; repeat a:= a + i; i:= i + 1; until i > 100; a; # - continue a:= 0;; for i in [ 1 .. 100 ] do if i mod 2 = 0 then continue; fi; a:= a + i; od; a; # - break a:= 0;; for i in [ 1 .. 100 ] do if a > 1000 then break; fi; a:= a + i; od; a; ############################################################################ # Constants # - booleans true = false; true <> false; true or false; true and false; not true; a:= 1;; b:= 2;; ( a < b ) or ( ( 2*a = b ) and not ( a = b ) ); # - integers -17; 0; 5; 20^100 - 1; # arbitrary large, no overflow # - rationals 3/7; 4/6; # normal form 1/0; # this is not allowes # (quit the 'brk> ' mode by entering 'quit;') # - elements of cyclotomic fields Sqrt( 7 ); E(3) + E(3)^2; E(4)^2; E(3) + E(5); # natural embedding 1 / ( E(3) + 1 ); # - finite field elements a:= Z(2); a + a; a * a; a + a = 0; a + a = 0 * a; # distinguish different zeros 0 * a = 0; a = 1; a:= Z(4); a + a; a * a; a^3; # - permutations (on positive integers) p:= (1,2,3)(4,5); p * p; p^3; 1^p; # apply a permutation to a point (1,2,3)(3,4,5); # cycle notation is restrictive (1,2,3) * (3,4,5); p1:= (1,2); p2:= (3,10^6); p3:= p1 * p2; p4:= p3 * p2; p1 = p4; # the two move the same points in the same way MemoryUsage( p1 ); MemoryUsage( p4 ); ############################################################################ # Lists (arrays) # - plain lists (dense, sorted, homogeneous, ...) l:= [ 2, 3, 5, 7, 11 ]; IsList( l ); Length( l ); # - element and sublist access and assignment l[1]; l[1]:= 0;; l; l[10]:= (1,2);; l; # a non-dense list Length( l ); l[9]; # this position is not bound # (quit the 'brk> ' mode by entering 'quit;') IsBound( l[9] ); IsDenseList( l ); Unbind( l[10] ); l; IsDenseList( l ); IsSortedList( [ 2, 3, , 5 ] ); # non-dense lists are never sorted IsSortedList( [ 2, 3, 5 ] ); l{ [ 2, 3 ] }; # sublist access l{ [ 2, 3 ] }:= [ -1, -2 ];; # sublist assignment l; # - common subobjects l2:= [ l, l ]; l[1]:= true;; l2; # - mutability l3:= Immutable( l ); # create an immutable copy l = l3; # same entries at the same positions l3[1]:= false; # not allowed assignment # (quit the 'brk> ' mode by entering 'quit;') # - sortedness: linear vs. binary search, store knowledge l:= [];; for i in [ 1 .. 100000 ] do l[i]:= [ i ]; od; IsSSortedList( l ); # strictly sorted Position( l, [ 99000 ] ); for i in [ 1 .. 1000 ] do Position( l, [ 99000 ] ); od; time; for i in [ 1 .. 1000 ] do PositionSorted( l, [ 99000 ] ); od; time; l2:= [];; for i in [ 1 .. 100000 ] do l2[i]:= Immutable( [ i ] ); od; for i in [ 1 .. 1000 ] do Position( l2, [ 99000 ] ); od; time; IsSSortedList( l2 ); for i in [ 1 .. 1000 ] do Position( l2, [ 99000 ] ); od; time; HasIsSSortedList( l ); HasIsSSortedList( l2 ); # - ranges r:= [ 2 .. 10 ]; Length( r ); r[2]; r2:= [ 3, 5 .. 11 ]; Length( r2 ); Intersection( r, r2 ); [ 10 .. 2 ]; [ 10, 9 .. 2 ]; l:= []; for i in [ 1 .. 10000 ] do l[i]:= i; od; l = [ 1 .. 10000 ]; # the same entries at the same positions MemoryUsage( l ); MemoryUsage( [ 1 .. 10000 ] ); # - list arithmetics [ 1, 2, , 4 ] + [ 1, , 1, 1, 1 ]; 2 * [ 1, 2, 3 ]; Z(2) * [ 1, 2, 3 ]; [ 1, 1, , 1 ] * [ 1, 2, 3, 4, 5 ]; m:= [ [ 1, 2 ], [ 3, 4 ] ]; m + 1; 2 * m; [ 1, 2 ] + m; m^2; [ 1, 2 ] * m; m * [ 1, 2 ]; # - other representations of vectors/ matrices # (less flexible, more efficient) m:= IdentityMat( 6 ) * Z(5)^0; ConvertToMatrixRep( m ); m; m:= RandomMat( 50, 50 ) * Z(5)^0;; m^100000;; time; ConvertToMatrixRep( m ); m^100000;; time; # - strings and characters s:= "Hello, world!"; IsList( s ); # strings are lists s[2]; # entries of strings are characters Print( s, " ", s, " ", s ); Sort( s ); s; String( [ 1, 2, 3, 4, 5 ] ); # - shortcuts for common loops l:= [ 1 .. 100 ];; List( l, x -> 2 * x ); Filtered( l, IsPrimeInt ); First( l, x -> x > 40 ); ForAll( l, IsEvenInt ); ForAny( l, IsEvenInt ); ############################################################################ # Records # - label/value pairs r:= rec( number:= 1, boolean:= true, perm:= (1,2,3) ); IsRecord( r ); # - component access and assignment r.number; r.list; # unbound component # (quit the 'brk> ' mode by entering 'quit;') IsBound( r.list ); r.list:= [ 1, 2, 3 ]; r; Unbind( r.perm ); r; # - common subobjects, mutability (similar to lists) r2:= rec( a:= r.list ); r.list[1]:= 0; r2; MakeImmutable( r2 ); # do not make a copy r.list[2]:= 7; # not allowed assignment # (quit the 'brk> ' mode by entering 'quit;') ############################################################################ # Customization # - `~/.gap` directory GAPInfo.UserGapRoot; # - user preferences LoadPackage( "browse" );; UserPreference( "HelpViewers" ); BrowseUserPreferences(); # quit the Browse application by entering 'Q' UserPreference( "HelpViewers" ); SetHelpViewer( "screen", "firefox", "xpdf" ); UserPreference( "HelpViewers" ); SizeScreen(); ############################################################################ # Domains # - notions of generation f:= FreeGroup( 2 ); GeneratorsOfGroup( f ); GeneratorsOfMonoid( f ); gens:= GeneratorsOfSemigroup( f ); IsGroup( f ); IsMonoid( f ); IsSemigroup( f ); IsDomain( f ); IsSubset( f, gens ); gens[1] in f; # - operations for groups g:= SymmetricGroup( 4 ); GeneratorsOfGroup( g ); DerivedSubgroup( g ); SylowSubgroup( g, 2 ); HasDerivedSubgroup( g ); ComputedSylowSubgroups( g ); # - fields as domains Size( Rationals ); GeneratorsOfField( GF(27) ); GaloisGroup( GF(16) ); Size( last ); # - vector spaces as domains BasisVectors( Basis( Rationals^3 ) ); GeneratorsOfVectorSpace( GF(2)^2 ); # - algebras as domains a:= Rationals^[2,2]; Dimension( a ); a:= GroupRing( Rationals, SymmetricGroup( 3 ) ); GeneratorsOfAlgebra( a ); # - natural embeddings IsSubset( GF(16), GF(4) ); # - iterators g:= Group( (1,2,3,4), (1,3) ); iter:= Iterator( g ); elm:= NextIterator( iter ); while not IsDoneIterator( iter ) do elm:= elm * NextIterator( iter ); od; # - enumerators enum:= Enumerator( g ); Length( enum ); elm:= enum[5]; Position( enum, elm ); ############################################################################ # Group example: shuffle groups # - read the prepared input EditDemoInput( "shuffle.g" ); # close the editor in order to return to GAP g:= ShuffleGroup( 3 ); Size( g ); grps:= List( [ 1 .. 16 ], ShuffleGroup );; List( grps, Size ); DisplayCompositionSeries( grps[5] ); DisplayCompositionSeries( grps[6] ); DisplayCompositionSeries( grps[9] ); DisplayCompositionSeries( grps[11] ); DisplayCompositionSeries( grps[12] ); g:= grps[5]; Size( g ); Factorial( 10 ); IsPerfect( g ); der:= DerivedSubgroup( g );; Size( der ); cen:= Centre( g );; Size( cen ); Size( Intersection( der, cen ) ); IsPerfect( der ); cser:= CompositionSeries( der );; List( cser, Size ); IsElementaryAbelian( cser[2] ); GeneratorsOfGroup( cser[2] ); ############################################################################ # Group example: Sym(4) acting on a cube # - read the prepared input EditDemoInput( "s4.g" ); # close the editor in order to return to GAP x; y; Size( g ); # - common actions 1^x; OnPoints( 1, x ); OnTuples( [ 1, 2 ], x ); OnSets( [ 1, 2 ], x ); OnSetsSets( [ [ 1, 2 ], [ 1, 7 ] ], x ); # - action on 6 faces faces:= Orbit( g, [ 1, 2, 3, 4 ], OnSets ); Stabilizer( g, faces[1], OnSets ); Permutation( x, faces, OnSets ); op1:= Action( g, faces, OnSets ); Size( op1 ); # - action on 12 edges edges:= Orbit( g, [ 1, 2 ], OnSets ); op2:= Action( g, edges, OnSets ); Size( op2 ); # - action on 4 diagonals diagonals:= Orbit( g, [ 1, 5 ], OnSets ); Stabilizer( g, diagonals[1], OnSets ); op3:= Action( g, diagonals, OnSets ); Size( op3 ); # - action on 3 pairs of opposite faces facepairs:= Orbit( g, [ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ] ], OnSetsSets ); hom:= ActionHomomorphism( g, facepairs, OnSetsSets ); op4:= Image( hom ); Size( op4 ); Kernel( hom ); # - action on 6 pairs of opposite edges edgepairs:= Orbit( g, [ [ 1, 2 ], [ 5, 6 ] ], OnSetsSets ); op5:= Action( g, edgepairs, OnSetsSets ); Size( op3 ); # - action on 2 tetrahedra inside the cube tetrahedra:= Orbit( g, [ 1, 3, 6, 8 ], OnSets ); hom:= ActionHomomorphism( g, tetrahedra, OnSets ); op6:= Image( hom ); Size( op6 ); Kernel( hom ); # - action on diagonals inside faces facediagonals:= Orbit( g, [ 1, 6 ], OnSets ); hom:= ActionHomomorphism( g, facediagonals, OnSets ); op7:= Image( hom ); Size( op7 ); # - properties of actions IsPrimitive( g, [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); Blocks( g, [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); Blocks( g, [ 1, 2, 3, 4, 5, 6, 7, 8 ], [ 1, 5 ] ); # - action on cosets of a Sylow 3 subgroup tr:= RightTransversal( g, SylowSubgroup( g, 3 ) );; Action( g, tr, OnRight ); ############################################################################ # Group example: Automorphisms of Sym(6) # 1. Naive approach g:= SymmetricGroup( 6 ); gens:= GeneratorsOfGroup( g ); a:= AutomorphismGroup( g ); inner:= Group( List( gens, x -> InnerAutomorphism( g, x ) ) ); Size( g ); Size( inner ); Size( a ); First( GeneratorsOfGroup( a ), x -> not x in inner ); # 2. Do not compute the automorphism group. ccl:= ConjugacyClasses( g );; List( ccl, Size ); reps:= List( ccl, Representative ); List( reps, Order ); 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; 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; 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; map; ############################################################################ # Group example: fixed point free elements in Sym(n) # - naive approach fpf:= n -> Number( SymmetricGroup( n ), x -> NrMovedPoints( x ) = n ); fpf( 1 ); fpf( 2 ); fpf( 3 ); for n in [ 2 .. 20 ] do Print( [ n, Factorial( n ), Float( Factorial( n ) / fpf( n ) ) ], "\n" ); od; # interrupt the computation by entering -C ... # and quit the 'brk> ' mode by entering 'quit;' # - try to be more clever fpf2:= function( n ) local ccl; ccl:= ConjugacyClasses( SymmetricGroup( n ) ); return Sum( List( Filtered( ccl, c -> NrMovedPoints( Representative( c ) ) = n ), Size ), 0 ); end; for n in [ 2 .. 20 ] do Print( [ n, Factorial( n ), Float( Factorial( n ) / fpf2( n ) ) ], "\n" ); od; # what is the limit for n -> infinity ? ############################################################################ # Group example: Rubik's cube EditDemoInput( "rubik.g" ); # close the editor in order to return to GAP top; cube; size:= Size( cube ); Collected( Factors( size ) ); orbits:= Orbits( cube, [ 1 .. 48 ] ); cube1:= Action( cube, orbits[1] ); Size( cube1 ); vertices:= Blocks( cube1, [ 1 .. 24 ] ); # - action on the vertices blockhom1:= ActionHomomorphism( cube1, vertices, OnSets );; cube1b:= Image( blockhom1 ); Size( cube1b ); Factorial( 8 ); Factors( Size( Kernel( blockhom1 ) ) ); IsElementaryAbelian( Kernel( blockhom1 ) ); cmpl1:= Stabilizer( cube1, [1,2,3,4,5,6,8,13], OnSets );; Size( cmpl1 ); Size( Intersection( cmpl1, Kernel( blockhom1 ) ) ); ClosureGroup( cmpl1, Kernel( blockhom1 ) ) = cube1; (1,7,22) in cube1; (1,7,22)(2,20,14) in cube1; # - action on the edges cube2:= Action( cube, orbits[2] );; Size( cube2 ); edges:= Blocks( cube2, [ 1 .. 24 ] ); blockhom2:= ActionHomomorphism( cube2, edges, OnSets );; cube2b:= Image( blockhom2 ); Size( cube2b ); Factors( Size( Kernel( blockhom2 ) ) ); IsElementaryAbelian( Kernel( blockhom2 ) ); cmpl2:= Stabilizer( cube2, [1,2,3,4,5,6,7,9,10,12,14,16], OnSets );; Size( cmpl2 ); Factorial( 12 ); Size( Intersection( cmpl2, Kernel( blockhom2 ) ) ); ClosureGroup( cmpl2, Kernel( blockhom2 ) ) = cube2; (1,11) in cube2; (1,11)(2,17) in cube2; # - put the results of the two actions together Size( cube ); Size( cube1 ) * Size( cube2 ); Intersection( Kernel( blockhom1 ), Kernel( blockhom2 ) ); (17,19)(11,8)(6,25) in cube; (7,28)(18,21) in cube; (17,19)(11,8)(6,25)(7,28)(18,21) in cube; Centre( cube ); ############################################################################ # Group example: Symmetries of a regular icosahedron # look at the 3-dimensional situation UrlOpen( Concatenation( "file://", Filename( demodir, "icos.pdf" ) ) ); # close the PDF viewer # load the input data EditDemoInput( "icos.g" ); # close the editor in order to return to GAP b; mat1; mat2; p1:= [ 0, b, 1 ]; p1 * mat2; Order( mat2 ); Size( g ); # - do not use the geometry permiso:= IsomorphismPermGroup( g ); Image( permiso ); # - act on vertices of the icosahedron orb1:= Set( Orbit( g, p1 ) ); op1:= Action( g, orb1 ); Size( op1 ); IsPrimitive( g, orb1 ); bl1:= Blocks( g, orb1 );; bl1[1]; blop1:= Action( g, bl1, OnSets ); Size( blop1 ); # - act on faces of the icosahedron p2:= [ 1, 1, 1 ];; orb2:= Orbit( g, p2 );; Length( orb2 ); bl2:= Blocks( g, orb2 );; bl2[1]; blop2:= Action( g, bl2, OnSets ); IsPrimitive( blop2, [ 1 .. 10 ] ); # - subgroup of rotation symmetries sg:= Group( mat1, mat2 );; Size( sg ); bl3:= Blocks( sg, orb2 ); Length( bl3 ); Action( sg, bl3, OnSets ); # - action on 5 cubes and stabilizer of a cube cube:= Union( bl3[1], -bl3[1] ); orb3:= Orbit( g, cube, OnSets );; Action( g, orb3, OnSets ); stab:= Stabilizer( g, cube, OnSets ); GeneratorsOfGroup( stab ); ############################################################################ # Group example: Some triangle groups (finitely presented groups) f:= FreeGroup( 2 ); rels:= function( f, n ) return [ f.1^2, f.2^3, (f.1*f.2)^n ]; end; g:= f / rels( f, 3 ); Size( g ); g:= f / rels( f, 4 ); Size( g ); g:= f / rels( f, 5 ); Size( g ); g:= f / rels( f, 6 ); Size( g ); # interrupt the computation by entering -C ... # and quit the 'brk> ' mode by entering 'quit;' der:= DerivedSubgroup( g ); AbelianInvariants( der ); # the group is infinite g:= f / rels( f, 8 ); der:= DerivedSubgroup( g ); Index( g, der ); der2:= DerivedSubgroup( der ); Index( der, der2 ); der3:= DerivedSubgroup( der2 ); Index( der2, der3 ); pi:= NaturalHomomorphismByNormalSubgroup( g, der3 ); Size( Image( pi ) ); DisplayCompositionSeries( Image( pi ) ); AbelianInvariants( der3 ); # der3 is a torsion-free group ############################################################################ # Mappings # - via action g:= SymmetricGroup( 4 ); tr:= RightTransversal( g, Group( (1,2) ) ); hom:= ActionHomomorphism( g, tr, OnRight ); Range( hom ); Image( hom ); IsSurjective( hom ); IsInjective( hom ); # - natural epimorphism n:= SubgroupNC( g, [ (1,2)(3,4), (1,3)(2,4) ] ); IsNormal( g, n ); epi:= NaturalHomomorphismByNormalSubgroup( g, n ); Image( epi ); Kernel( epi ); IsSurjective( epi ); IsInjective( epi ); inv:= Inverse( epi ); inv:= InverseGeneralMapping( epi ); IsMapping( inv ); # - by images h:= SymmetricGroup( 3 ); hom:= GroupHomomorphismByImages( h, g, [ (1,2), (1,2,3) ], [ (2,3), (2,3,4) ] ); (1,3)^hom; # - generalized mappings inv:= InverseGeneralMapping( hom ); IsMapping( inv ); ############################################################################ # Other Structures: fields, vector spaces, algebras # - finite fields f:= GF(4); Size( f ); Dimension( f ); Basis( f ); BasisVectors( Basis( f ) ); f2:= GF(256); f3:= AsField( f, f2 ); Dimension( f2 ); Dimension( f3 ); f2 = f3; # - abelian number fields f:= CyclotomicField( 7 ); Sqrt( 7 ) in f; Sqrt( -7 ) in f; x:= Sqrt( 5 ); y:= ( -1 + x ) / 2; IsIntegralCyclotomic( y ); # - algebraic extensions x:= Indeterminate( Rationals ); p:= x^2 + 1; f:= AlgebraicExtension( Rationals, p ); GeneratorsOfField( f ); last[1] ^ 2; # - row spaces v:= GF(2)^4; Dimension( v ); vec:= Random( v ); LeftActingDomain( v ); m:= RandomInvertibleMat( 4, GF(2) ); b:= Basis( v, m ); coeff:= Coefficients( b, vec ); coeff * m = vec; # - matrix algebras m:= [ [ 1, 2, 3 ], [ 0, 1, 6 ], [ 0, 0, 1 ] ]; A:= Algebra( Rationals, [ m ] ); subA:= Subalgebra( A, [ m-m^2 ] ); Dimension( subA ); idA:= Ideal( A, [ m-m^3 ] ); Dimension( idA ); B:= A/idA; # - group rings rg:= GroupRing( GF(4), SymmetricGroup( 3 ) ); Dimension( rg ); id:= CentralIdempotentsOfAlgebra( rg ); # - quat. algebra q:= QuaternionAlgebra( Rationals ); gens:= GeneratorsOfAlgebra( q ); x:= Sum( gens{ [ 1 .. 3 ] } ); x^-1; IsAssociative( q ); IsCommutative( q ); bas:= CanonicalBasis( q );; BasisVectors( bas ); op:= OperationAlgebraHomomorphism( q, bas, OnRight ); ImagesRepresentative( op, gens[1] ); ImagesRepresentative( op, gens[2] ); ############################################################################ # Other Structures: graphs # use a package LoadPackage( "grape" ); g:= Group( (1,2)(3,4), (1,3) ); # dihedral group gamma:= CayleyGraph( g ); Adjacency( gamma, 1 ); Diameter( gamma ); Distance( gamma, 1, 2 ); Distance( gamma, 1, 3 ); IsBipartite( gamma ); g:= DihedralGroup( 8 ); # dihedral group, other generators petersen:= Graph( SymmetricGroup( 5 ), [ [ 1, 2 ] ], OnSets, function( x, y ) return IsEmpty( Intersection( x,y ) ); end ); Diameter( petersen ); ############################################################################ # Data libraries (mainly of groups) # - basic groups gens:= GeneratorsOfGroup( GL(4,3) ); Display( gens[1] ); Display( gens[2] ); # - perfect groups Filtered( [ 1 .. 100 ], i -> NrPerfectGroups( i ) <> 0 ); g:= PerfectGroup( IsPermGroup, 168, 1 ); GeneratorsOfGroup( g ); # - primitive groups g:= OnePrimitiveGroup( NrMovedPoints, 10, Size, 60 ); GeneratorsOfGroup( g ); # - small groups grps:= AllSmallGroups( Size, 8, IsAbelian, false ); List( grps, g -> List( Elements( g ), Order ) ); # - transitive groups OneTransitiveGroup( NrMovedPoints, IsPrimeInt, IsSolvableGroup, false ); ############################################################################ # Profiling # 1. profile function by function # - switch profiling on ProfileGlobalFunctions( true ); ProfileOperationsAndMethods( true ); # - run your computations g:= MathieuGroup( 24 ); Size( g ); ConjugacyClasses( g );; # - switch profiling off ProfileGlobalFunctions( false ); ProfileOperationsAndMethods( false ); # - show profiling results DisplayProfile(); # - more options for this kind of profiling ?Profiling # quit the help system by entering 'q' # 2. profile line by line # - load the package LoadPackage( "profiling" ); # - switch profiling on ProfileLineByLine( "profileinfo" ); # - switch profiling off again UnprofileLineByLine(); # - switch profiling on (second attempt) profiledatafile:= "profileinfo.gz";; ProfileLineByLine( profiledatafile ); # - run your computations g:= MathieuGroup( 24 ); Size( g ); ConjugacyClasses( g );; # - switch profiling off UnprofileLineByLine(); # - prepare the output files profiledatadir:= "profileinfodir";; OutputAnnotatedCodeCoverageFiles( profiledatafile, profiledatadir ); # - open a browser window with the prepared information UrlOpen( Concatenation( profiledatadir, "/index.html" ) ); # inspect what the browser shows, then close the browser # - clean up ... Exec( "rm -rf profileinfo profileinfo.gz profileinfodir" ); # 3. profile an individual function call # (happens in a temporary directory) LineByLineProfileFunction( MathieuGroup, [ 24 ] ); # inspect what the browser shows, then close the browser ############################################################################ # GAP's type system # - operations and methods Size; Print( Size ); meth:= ApplicableMethod( Size, [ Group( (1,2,3), (1,2) ) ] ); Print( meth ); PageSource( meth ); # quit the pager by entering 'q' meth:= ApplicableMethod( Size, [ GF(2)^5 ] ); PageSource( meth ); # quit the pager by entering 'q' g:= SymmetricGroup( 3 ); meth:= ApplicableMethod( Size, [ g ] ); PageSource( meth ); HasSize( g ); # the value was already set, needs no computation # - filters KnownAttributesOfObject( g ); KnownPropertiesOfObject( g ); CategoriesOfObject( g ); RepresentationsOfObject( g );