I have a finitely presented group G in GAP, for example with the following generators and relations: generators = $[ f1, f2, f3, f4 ]$ relators = $[ f1^2, f2^2, f3^2, f4^2, (f3*f2)^2, (f2*f1)^3, (f1*f4)^3, (f3*f1)^3, (f4*f3)^3, (f2*f4)^3 ]$
Question: How can I count the number of elements G that have length equal to $i$ (which means that the element is a non-zero product in G of exactly $i$ generators $f_i$ in a minimal way)?
This cannot be done for finitely presented groups in general, because there are groups with undecidable word problems. But for possibly infinite finitely presented groups that are shortlex automatic or have complete rewriting systems, you can use the KBMAG package to do this.
Here is an easy example with an infinite Coxeter group.
You can use the function $\mathsf{EnumerateReducedWords}$ to list shortlex least representatives of group elements of specified length. So, for example,
tells us that there are 16 elements of lengths 0 to 3, and 9 elements of length exactly 4.
You can also compute the exact growth function of the group as a rational function.
The coefficients $a_n$ of the Taylor series expansion $\sum_{n=0}^\infty a_nx^n$ of this would give the number of elements of length $n$, but I don't know whether GAP has a function to compute series expansions.