Home » 2015 » July

# Monthly Archives: July 2015

## Average order of group elements: a demo of test-driven development in GAP

By Alexander Konovalov, Research Fellow in the Centre for Interdisciplinary Research in Computational Algebra, University of St Andrews (reproduced from the original post here)

This blog post is based on an improvised demo that I gave at the Newcastle University on May 21st, 2015 during a short visit supported by the CoDiMa project.

Let’s consider the following exercise: for a finite group G, calculate the average order of its element (that is, the sum of orders of its elements divided by the order of the group). We begin with a very straightforward approach, iterating over all elements of the group in question:

``````
gap> S:=SymmetricGroup(10);
Sym( [ 1 .. 10 ] )
gap> sum:=0;
0
gap> for g in S do
>      sum := sum + Order(g);
>    od;
gap> sum/Size(S);
39020911/3628800
```
```

Now assume that we would like to save this fragment of the GAP code and later repeat this calculation for some other groups. (more…)