#GAP DERANGEMENT DEMONSTRATION: # WE WILL USE GAP TO COUNT THE NUMBER OF DERANGEMENS First lets list the derangements of 4 elements: n:=4; G:=SymmetricGroup(n); #The Symmetric Group is all permutations of 1,2,...n. It has n! elements. t:=0; for g in G do if NrMovedPoints(g)=n then #NrMovedPoints counts how many points are moved, derangements are those that move n Print(ListPerm(g), "\n"); t:=t+1; else fi; od; Print("t=", t); Print(","); Print(" The fraction of deragnments for permutations of ", n, " elements is ", Float(t/Factorial(n))); Now 6 elements: n:=8; G:=SymmetricGroup(n); t:=0; for g in G do if NrMovedPoints(g)=n then Print(ListPerm(g), "\n"); t:=t+1; else fi; od; Print("t=", t);; Print(",");; Print(" The fraction of deragnments for permutations of ", n, " elements is ", Float(t/Factorial(n)));; # Now lets loop through lots of values of n, note that ;; makes GAP suppress ouput. We won't ask it to print the derangements, just to count them, and we just print out the fraction. for n in [3..12] do G:=SymmetricGroup(n);; t:=0;; for g in G do if NrMovedPoints(g)=n then t:=t+1;; else fi; od;; Print(" The fraction of derangnments for permutations of ", n, " elements is ", Float(t/Factorial(n)), "\n"); od;