# This code defines a function countGeneratingPairs that # generates random pairs of elements of a group (pairs of # nontrivial, nonequal elements) and counts how many of them # generate the group. For example, entering: # gap> countGeneratingPairs( AlternatingGroup(10), 50 ); # produces the output: # The number of generating pairs is 44 # The number of nongenerating pairs is 6 # Repeating the command may produce different counts, since # GAP's pseudorandom generators are only reset when GAP # starts up. # To find out about the groups that GAP already knows # about, such as alternating groups, look in section 48 # of the GAP reference manual. getRandomElement := function( group ) # Returns a nontrivial element. local element; repeat element := Random( group ); until ( not element = Identity( group ) ); return element; end; getRandomPair := function( group ) # Returns a list of two nontrivial, nonequal elements. local firstElement, secondElement; firstElement := getRandomElement( group ); repeat secondElement := getRandomElement( group ); until ( not secondElement = firstElement ); return [ firstElement, secondElement ]; end; countGeneratingPairs := function( group, numTries ) local groupOrder, numGeneratingPairs, numNongeneratingPairs, randomPair, count; groupOrder := Order( group ); numGeneratingPairs := 0; numNongeneratingPairs := 0; for count in [1 .. numTries ] do randomPair := getRandomPair( group ); if ( Order(Group( randomPair[1], randomPair[2] ) ) = groupOrder ) then numGeneratingPairs := numGeneratingPairs + 1; else numNongeneratingPairs := numNongeneratingPairs + 1; fi; od; Print("\nThe number of generating pairs is ", numGeneratingPairs); Print("\nThe number of nongenerating pairs is ", numNongeneratingPairs,"\n\n"); end;