# Set-Theoretic Operations in a Group

## Functions Relating to Group Order

### `FactoredIndex(G, H): GrpGPC, GrpGPC -> [<RngIntElt, RngIntElt>]`

Given a group $G$ and a subgroup $H$ of $G$ of finite index, return the factored index of $H$ in $G$

### `FactoredOrder(G): GrpGPC -> [<RngIntElt, RngIntElt>]`

The factored order of the finite group $G$.

### `Index(G, H): GrpGPC, GrpGPC -> RngIntElt`

The index of the subgroup $H$ in the group $G$, returned as an ordinary integer.

### `Order(G): GrpGPC -> RngIntElt`

### `# G: GrpGPC -> RngIntElt`

The order of the group $G$, returned as an ordinary integer.

## Membership and Equality

### `g in G: GrpGPCElt, GrpGPC -> BoolElt`

Given an element $g$ and a group $G$, return `true` if $g$ is an element of $G$, `false` otherwise.

### `g notin G: GrpGPCElt, GrpGPC -> BoolElt`

Given an element $g$ and a group $G$, return `true` if $g$ is not an element of $G$, `false` otherwise.

### `S subset G: { GrpGPCElt}, GrpGPC -> BoolElt`

Given a group $G$ and a set $S$ of elements belonging to a group $H$, where $G$ and $H$ have some covering group, return `true` if $S$ is a subset of $G$, `false` otherwise.

### `S notsubset G: { GrpGPCElt}, GrpGPC -> BoolElt`

Given a group $G$ and a set $S$ of elements belonging to a group $H$, where $G$ and $H$ have some covering group, return `true` if $S$ is not a subset of $G$, `false` otherwise.

### `H subset G: GrpGPC, GrpGPC -> BoolElt`

### `IsSubgroup(H, G): GrpGPC, GrpGPC -> BoolElt`

Given groups $G$ and $H$, having some covering group, return `true` if $H$ is a subgroup of $G$, `false` otherwise.

### `H notsubset G: GrpGPC, GrpGPC -> BoolElt`

Given groups $G$ and $H$, having some covering group, return `true` if $H$ is not a subgroup of $G$, `false` otherwise.

### `G eq H: GrpGPC, GrpGPC -> BoolElt`

Given groups $G$ and $H$, having some covering group, return `true` if $G$ and $H$ are the same group, `false` otherwise.

### `G ne H: GrpGPC, GrpGPC -> BoolElt`

Given groups $G$ and $H$, having some covering group, return `true` if $G$ and $H$ are distinct groups, `false` otherwise.

## Set Operations

### `Representative(G): GrpGPC -> GrpGPCElt`

### `Rep(G): GrpGPC -> GrpGPCElt`

A representative element of $G$.

### `RandomProcess(G): GrpGPC -> Process`

```magma
Slots   : RngIntElt                    Default: 10
Scramble: RngIntElt                    Default: 100
```

Create a process to generate pseudo-randomly chosen elements from the group $G$. The process uses an ‘expansion’ procedure to construct a set of elements corresponding to fairly long words in the generators of $G$ [[Celler *et al.*, 1995](../../references.md#cite-randomelements)]. At all times, $N$ elements forming a generating set for $G$ are stored. Here, $N$ is the maximum of $n+1$ and the specified value for `GrpGPC:Slots`, where $n$ is the number of generators of $G$. Initially, these are just the generators of $G$ and products of pairs of generators of $G$. Random elements are now produced by successive calls to [`Random`](#function-grpgpc-random)`(P)`, where $P$ is the process created by this function. Each such call chooses an element previously stored by the process as the new random element. The process then replaces this stored element with the product of this element and another one of the stored elements (on the left or the right). Setting `GrpGPC:Scramble``:= m` causes $m$ such operations to be performed before the process is returned.

Care should be taken when trying to apply this function to infinite polycyclic groups. Firstly, the computations may take a considerable amount of time and secondly, the quality of the pseudo-random element generator may be extremely poor, depending on the required properties of the sequence of pseudo-random elements.

### `Random(P): Process -> GrpGPCElt`

Given a random element process $P$ created by the function [`RandomProcess`](#function-grpgpc-randomprocess)`(G)` for the group $G$, construct a pseudo-random element of $G$ by forming a random product over the expanded generating set currently stored by the process. The remarks concerning random elements of infinite polycyclic groups given in the description of [`RandomProcess`](#function-grpgpc-randomprocess) apply here.

### `Random(G): GrpGPC -> GrpGPCElt`

### `Random(G, max): GrpGPC, RngIntElt -> GrpGPCElt`

An element, pseudo-randomly chosen, from the group $G$. An exponent vector in normal form is chosen at random. Exponents of polycyclic generators for which there is no power relation, are chosen to have absolute value less or equal to `max`. A default value for `max` is 10.

It should be kept in mind that the distribution of the elements returned by `Random` is uniform only in the case that $G$ is finite.
