diff --git a/lib/randiso.gd b/lib/randiso.gd
index 2a33d8b415..5f66f30e93 100644
--- a/lib/randiso.gd
+++ b/lib/randiso.gd
@@ -21,13 +21,63 @@ DeclareAttribute( "OmegaAndLowerPCentralSeries", IsGroup );
##
##
##
-## returns the code corresponding to pcgs.
+## returns the non-negative integer code corresponding to the finite pcgs
+## pcgs, which must be in .
+## The code stores the relative orders of pcgs and
+## the right hand sides of the nontrivial power and commutator relations
+## of the pc presentation defined by pcgs. This integer encoding of
+## pc groups underlies the group construction method described in
+## .
+##
+## More precisely, let
+## g_1,\ldots,g_l be the entries of pcgs, and let
+## r_1,\ldots,r_l be their relative orders. If l=0,
+## the code is 0. Otherwise put
+## m = \max_i r_i - 1. If the relative orders are not all equal,
+## the first l base m digits are
+## r_1-2,\ldots,r_l-2, so the relative order part is
+## \sum_{i=1}^l (r_i-2)m^{l-i}. If the relative orders are all
+## equal, this part is omitted; on decoding the relative orders are then
+## read from the factorisation of the supplied group order.
+##
+## After the relative order part comes a bit mask of length
+## l(l+1)/2-1. The bits, from least significant to most
+## significant, correspond first to the power relations
+## g_1^{r_1},\ldots,g_{l-1}^{r_{l-1}}, and then to the
+## commutators [g_j,g_i] for
+## 1 \leq i < j \leq l, ordered by increasing i and, for
+## fixed i, increasing j. A bit is 1 exactly when
+## the corresponding right hand side is nontrivial. The final power
+## relation g_l^{r_l}=1 is not stored separately.
+##
+## The nontrivial right hand sides, in the same order as their set bits,
+## are stored as base |G| digits, where G is the group
+## generated by pcgs. If
+## x = g_1^{e_1} \cdots g_l^{e_l}, with
+## 0 \leq e_i < r_i, then the digit for x is
+## \sum_{i=1}^l e_i\prod_{k=i+1}^l r_k. Equivalently, this is
+## the zero-based position of x in the canonical list
+## g_1^{e_1}\cdots g_l^{e_l}, ordered according to the
+## lexicographic order of the tuples e_1,\dots,e_l.
+##
+## Thus if b is m^l when the relative order part is present
+## and 1 otherwise, if u is the bit mask, and if
+## a_1,\ldots,a_t are the digits for the nontrivial right hand
+## sides, then the complete code is
+## A + b(u + 2^{l(l+1)/2-1}(a_1 + |G|a_2 + \cdots +
+## |G|^{t-1}a_t)), where A is the relative order part, or
+## 0 if that part is omitted.
## G := CyclicGroup(512);;
+## gap> G := CyclicGroup(8);;
## gap> p := Pcgs( G );;
## gap> CodePcgs( p );
-## 162895587718739690298008513020159
+## 323
## ]]>
+## In this example the relative orders are [2,2,2], so there is
+## no relative order part. The nontrivial power tails are g_2
+## and g_3, with digits 2 and 1 in the canonical
+## list. Hence the code is
+## 1 + 2 + 2^5(2 + 8\cdot 1) = 323.
##
##
## <#/GAPDoc>
@@ -43,11 +93,15 @@ DeclareGlobalFunction( "CodePcgs" );
##
##
##
-## returns the code for a pcgs of G.
+## returns the code for the pcgs returned by Pcgs for G.
+## The encoding is the one described for .
## G := DihedralGroup(512);;
-## gap> CodePcGroup( G );
-## 2940208627577393070560341803949986912431725641726
+## gap> G := CyclicGroup(8);;
+## gap> code := CodePcGroup( G );
+## 323
+## gap> H := PcGroupCode( code, Size( G ) );;
+## gap> IsCyclic( H ) and Size( H ) = Size( G );
+## true
## ]]>
##
##
@@ -69,6 +123,15 @@ DeclareGlobalFunction( "CodePcGroup" );
## otherwise anything may happen.
## Valid codes are usually obtained by one of the functions
## or .
+## The inverse construction uses the integer format described for
+## . The length of the pcgs, and in the case where
+## all relative orders are equal also the relative orders themselves, are
+## recovered from the prime factorisation of size.
+##
+## The same integer format is also used by Magma's
+## SmallGroupEncoding and SmallGroupDecoding, and by
+## OSCAR's encode for pc groups and
+## pc_group( order, code ).
## G := SmallGroup( 24, 12 );;
## gap> p := Pcgs( G );;