---
title: "Operations on the Set of Group Elements"
canonical: "https://docs.magma-maths.org/v2.30-1/FinitelyPresentedGroups/GroupsDefinedByRewriteSystems/Set.html"
source: "https://docs.magma-maths.org/v2.30-1/FinitelyPresentedGroups/GroupsDefinedByRewriteSystems/Set.md"
part: "Finitely Presented Groups"
chapter: "Groups Defined by Rewrite Systems"
breadcrumbs:
  - {"title": "Magma Handbook", "source": "https://docs.magma-maths.org/v2.30-1/index.md"}
  - {"title": "Finitely Presented Groups", "source": "https://docs.magma-maths.org/v2.30-1/FinitelyPresentedGroups/index-finitely-presented-groups.md"}
  - {"title": "Groups Defined by Rewrite Systems", "source": "https://docs.magma-maths.org/v2.30-1/FinitelyPresentedGroups/GroupsDefinedByRewriteSystems/index-groups-defined-by-rewrite-systems.md"}
prev: {"title": "Arithmetic with Words", "source": "https://docs.magma-maths.org/v2.30-1/FinitelyPresentedGroups/GroupsDefinedByRewriteSystems/arithmetic.md"}
next: {"title": "Homomorphisms", "source": "https://docs.magma-maths.org/v2.30-1/FinitelyPresentedGroups/GroupsDefinedByRewriteSystems/homomorphism.md"}
intrinsics:
  - {"name": "Random", "signature": "Random(G, n): GrpRWS, RngIntElt -> GrpRWSElt"}
  - {"name": "Random", "signature": "Random(G): GrpRWS -> GrpRWSElt"}
  - {"name": "Representative", "signature": "Representative(G): GrpRWS -> GrpRWSElt"}
  - {"name": "Rep", "signature": "Rep(G): GrpRWS -> GrpRWSElt"}
  - {"name": "Set", "signature": "Set(G, a, b): GrpRWS, RngIntElt, RngIntElt -> SetEnum"}
  - {"name": "Set", "signature": "Set(G): GrpRWS -> SetEnum"}
  - {"name": "Seq", "signature": "Seq(G, a, b): GrpRWS, RngIntElt, RngIntElt -> SeqEnum"}
  - {"name": "Seq", "signature": "Seq(G): GrpRWS -> SeqEnum"}
examples:
  - "ex-6fc61b"
---

# Operations on the Set of Group Elements

<a id="function-random-grprws-rngintelt"></a>
## `Random(G, n): GrpRWS, RngIntElt -> GrpRWSElt`

A random word of length at most $n$ in the generators of $G$.

<a id="function-random-grprws"></a>
## `Random(G): GrpRWS -> GrpRWSElt`

A random word (of length at most the order of $G$) in the generators of $G$.

<a id="function-representative-grprws"></a>
## `Representative(G): GrpRWS -> GrpRWSElt`

<a id="function-rep-grprws"></a>
## `Rep(G): GrpRWS -> GrpRWSElt`

An element chosen from $G$.

<a id="function-set-grprws-rngintelt-rngintelt"></a>
## `Set(G, a, b): GrpRWS, RngIntElt, RngIntElt -> SetEnum`

```magma
Search: MonStgElt                    Default: "DFS"
```

Create the set of reduced words, $w$, in $G$ with $a \le$ length$(w) \le b$. If `Search` is set to `"DFS"` (depth-first search) then words are enumerated in lexicographical order. If `Search` is set to `"BFS"` (breadth-first-search) then words are enumerated in lexicographical order for each individual length (i.e. in short-lex order). Depth-first-search is marginally quicker. Since the result is a set the words may not appear in the resultant set in the search order specified (although internally they will be enumerated in this order).

<a id="function-set-grprws"></a>
## `Set(G): GrpRWS -> SetEnum`

```magma
Search: MonStgElt                    Default: "DFS"
```

Create the set of reduced words that is the carrier set of $G$. If `Search` is set to `"DFS"` (depth-first search) then words are enumerated in lexicographical order. If `Search` is set to `"BFS"` (breadth-first-search) then words are enumerated in lexicographical order for each individual length (i.e. in short-lex order). Depth-first-search is marginally quicker. Since the result is a set the words may not appear in the resultant set in the search order specified (although internally they will be enumerated in this order).

<a id="function-seq-grprws-rngintelt-rngintelt"></a>
## `Seq(G, a, b): GrpRWS, RngIntElt, RngIntElt -> SeqEnum`

```magma
Search: MonStgElt                    Default: "DFS"
```

Create the sequence $S$ of reduced words, $w$, in $G$ with $a \le$ length$(w) \le b$. If `Search` is set to `"DFS"` (depth-first search) then words will appear in $S$ in lexicographical order. If `Search` is set to `"BFS"` (breadth-first-search) then words will appear in $S$ in lexicographical order for each individual length (i.e. in short-lex order). Depth-first-search is marginally quicker.

<a id="function-seq-grprws"></a>
## `Seq(G): GrpRWS -> SeqEnum`

```magma
Search: MonStgElt                    Default: "DFS"
```

Create a sequence $S$ of reduced words in the carrier set of $G$. If `Search` is set to `"DFS"` (depth-first search) then words will appear in $S$ in lexicographical order. If `Search` is set to `"BFS"` (breadth-first-search) then words will appear in $S$ in lexicographical order for each individual length (i.e. in short-lex order). Depth-first-search is marginally quicker.

<a id="example-ex-6fc61b"></a>
## `Example: Element Sets of a Rewrite Group (ex-6fc61b)`

We construct the group $D_{22}$, together with a representative word from the group, a random word and a random word of length at most 5 from the group, and the set of elements of the group.

```magma
> FG<a,b,c,d,e,f> := FreeGroup(6);
> Q := quo< FG | a*c^-1*a^-1*d=1, b*f*b^-1*e^-1=1, c*e*c^-1*d^-1=1,
>                d*f^-1*d^-1*a=1, e*b*e^-1*a^-1=1, f*c^-1*f^-1*b^-1=1>;
> G<a,b,c,d,e,f> := RWSGroup(Q);
> Representative(G);
Id(G)
> Random(G);
b
> Random(G, 5);
a * d * b
> Set(G);
{ a * d * b, a * b, a * b * e, a * c, a * d, d * b, b * e, a * b * a,
  a * b * d, b * a, a * c * e, Id(G), b * d, c * e, e, f, a, a * e, b,
  c, a * f, d }
> Seq(G : Search := "DFS");
[ Id(G), a, a * b, a * b * a, a * b * d, a * b * e, a * c, a * c * e,
  a * d, a * d * b, a * e, a * f, b, b * a, b * d, b * e, c, c * e, d,
  d * b, e, f ]
```
