# Elements

Elements of a pc-group are written in terms of the generators. The pc-generators of a group $G$ can always be written as `G.1`, `G.2`, … . Any variables naming the generators, either assigned during the definition of the group, or later using standard assignment statements, can also be used to express the generators. An arbitrary element can be written as a word in the generators using the various element operations.

## Definition of Elements

A *word* is defined inductively as follows:

**(i)**
A generator is a word;

**(ii)**
The expression $(u)$ is a word, where $u$ is a word;

**(iii)**
The product $u*v$ of the words $u$ and $v$ is a word;

**(iv)**
The conjugate $u^v$ of the word $u$ by the word $v$ is a word ($u^v$ expands into the word $v^{-1}*u*v$);

**(v)**
The power of a word $u^n$, where $u$ is a word and $n$ is an integer, is a word;

**(vi)**
The commutator $(u, v)$ of the words $u$ and $v$ is a word ( $(u, v)$ expands into the word $u^{-1}*v^{-1}*u*v$).

A group element is always printed by Magma as a normal word in the pc-generators of its parent group.

It is also possible to create an element of a group $G$ from its exponent vector. That is, the sequence $[e_1, e_2, \ldots, e_n]$ corresponds to the element ${G.1}^{e_1} * {G.2}^{e_2} * \cdots * {G.n}^{e_n}$. The coercion operator `!` is used to convert the sequence to the element.

### `G ! Q: GrpPC, [RngIntElt] -> GrpPCElt`

Given the pc-group $G$ and a sequence $Q$ of length $n$, containing the distinct positive integers ${\alpha_i}$, $0\leq {\alpha_i} < p_{i}$ for $i = 1,\ldots,n$, construct the element $x$ of $G$ given by

$$
x = a_1^{\alpha_1}\ldots a_n^{\alpha_n}, \quad 0 \leq \alpha_i < p_i
   \quad\hbox{\rm for } i = 1, \ldots, n.
$$

### `ElementToSequence(x): GrpPCElt -> [RngIntElt]`

### `Eltseq(x): GrpPCElt -> [RngIntElt]`

Given an element $x$ belonging to the pc-group $G$, where

$$
x = a_1^{\alpha_1}\ldots a_n^{\alpha_n}, \quad 0 \leq \alpha_i < p_i
   \quad\hbox{\rm for } i = 1, \ldots, n,
$$

return the sequence $Q$ of $n$ integers defined by $Q[i] = {\alpha_i}$, for $i = 1,\ldots,n$.

### `Identity(G): GrpPC -> GrpPCElt`

### `Id(G): GrpPC -> GrpPCElt`

### `G ! 1: GrpPC, RngIntElt -> GrpPCElt`

Construct the identity element of the pc-group $G$.

### `Example: Elt Definition (ex-027472)`

Given a pc-group, we can define elements as words in the generators or as more general expressions.

```magma
> G := PolycyclicGroup<a,b,c|a^3,b^2,c^2,b^a=c,c^a=b*c>;
> G;
GrpPC : G of order 12 = 2^2 * 3
PC-Relations:
    G.1^3 = Id(G),
    G.2^2 = Id(G),
    G.3^2 = Id(G),
    G.2^G.1 = G.3,
    G.3^G.1 = G.2 * G.3
> x := G.1^2*G.3;
> x;
G.1^2 * G.3
> x^2;
G.1 * G.2 * G.3
> x^3;
Id(G)

```

Magma will print the element in normal form even if it is not entered that way.

```magma
> G.2*G.1;
G.1 * G.3

```

When coercing a sequence into a group element, the sequence is always interpreted as an exponent vector for a normal word.

```magma
> y := G![0,1,1];
> y;
G.2 * G.3
> x*y;
G.1^2 * G.2
> y*x;
G.1^2
> (x,y);
G.2

```

An element can also be converted into a sequence.

```magma
> x^y;
G.1^2 * G.2 * G.3
> Eltseq(x^y);
[ 2, 1, 1 ]

```

## Arithmetic Operations on Elements

New elements can be computed from existing elements using standard operations.

### `g * h: GrpPCElt, GrpPCElt -> GrpPCElt`

Product of the element $g$ and the element $h$, where $g$ and $h$ belong to some common subgroup $G$ of a pc-group $U$. If $g$ and $h$ are given as elements belonging to the same proper subgroup $G$ of $U$, then the result will be returned as an element of $G$; if $g$ and $h$ are given as elements belonging to distinct subgroups $H$ and $K$ of $U$, then the product is returned as an element of $G$, where $G$ is the smallest subgroup of $U$ known to contain both elements.

### `g *:= h: GrpPCElt, GrpPCElt -> GrpPCElt`

Replace $g$ with the product of element $g$ and element $h$.

### `g ^ n: GrpPCElt, RngIntElt -> GrpPCElt`

The $n$-th power of the element $g$, where $n$ is a positive or negative integer.

### `g ^:= n: GrpPCElt, RngIntElt -> GrpPCElt`

Replace $g$ with the $n$-th power of the element $g$.

### `g / h: GrpPCElt, GrpPCElt -> GrpPCElt`

Quotient of the element $g$ by the element $h$, i.e. the element $g*h^{-1}$. Here $g$ and $h$ must belong to some common subgroup $G$ of a pc-group $U$. The rules for determining the parent group of $g/h$ are the same as for $g*h$.

### `g /:= h: GrpPCElt, GrpPCElt -> GrpPCElt`

Replace $g$ with the quotient of the element $g$ by the element $h$.

### `g ^ h: GrpPCElt, GrpPCElt -> GrpPCElt`

Conjugate of the element $g$ by the element $h$, i.e. the element $h^{-1}*g*h$. Here $g$ and $h$ must belong to some common subgroup $G$ of a pc-group $U$. The rules for determining the parent group of $g^h$ are the same as for $g*h$.

### `g ^:= h: GrpPCElt, GrpPCElt -> GrpPCElt`

Replace $g$ with the conjugate of the element $g$ by the element $h$.

### `(g₁, ..., gₙ): List(GrpPCElt) -> GrpPCElt`

Given the $n$ words $g_1, \ldots, g_n$ belonging to some common subgroup $G$ of a pc-group $U$, return the commutator. If $g_1, \ldots, g_n$ are given as elements belonging to the same proper subgroup $G$ of $U$, then the result will be returned as an element of $G$; if $g_1, \ldots, g_n$ are given as elements belonging to distinct subgroups of $U$, then the product is returned as an element of $G$, where $G$ is the smallest subgroup of $U$ known to contain all elements. Commutators are *left-normed*, so that they are evaluated from left to right.

## Properties of Elements

### `Order(x): GrpPCElt -> RngIntElt`

Order of the element $x$.

### `Parent(x): GrpPCElt -> GrpPC`

The parent group $G$ of the element $x$.

## Predicates for Elements

Elements in the same group can be compared using `eq` and `ne`.

### `g eq h: GrpPCElt, GrpPCElt -> BoolElt`

Given elements $g$ and $h$ belonging to a common pc-group, return `true` if $g$ and $h$ are the same element, `false` otherwise.

### `g ne h: GrpPCElt, GrpPCElt -> BoolElt`

Given elements $g$ and $h$ belonging to a common pc-group, return `true` if $g$ and $h$ are distinct elements, `false` otherwise.

### `IsIdentity(g): GrpPCElt -> BoolElt`

### `IsId(g): GrpPCElt -> BoolElt`

Returns `true` if $g$ is the identity element, `false` otherwise.

### `IsConjugate(G, g, h): GrpPC, GrpPCElt, GrpPCElt -> BoolElt, GrpPCElt`

Given a group $G$ and elements $g$ and $h$ belonging to $G$, return the value `true` if $g$ and $h$ are conjugate in $G$. The function also returns a second value in the event that the elements are conjugate: an element $z$ such that $g^z=h$.

### `Example: Elt Predicates (ex-7b7701)`

We check if one element commutes with another.

```magma
> G<a,b,c> := PolycyclicGroup<a,b,c|a^3,b^2,c^2,b^a=c,c^a=b*c>;
> b^a eq b;
false

```

The same information can also be obtained by checking the commutator.

```magma
> IsIdentity((b,a));
false

```

If we assign the result of `IsConjugate` to a single variable, it will store the boolean result.

```magma
> r := IsConjugate(G, c, b);
> r;
true

```

If we simply print `IsConjugate`, the boolean value and the conjugating element (if any) are displayed. On the other hand, using the multiple assignment, we can capture both of those values.

```magma
> IsConjugate(G, c, b);
true a^2
> r, x := IsConjugate(G, c, b);
> x, r;
a^2 true
> c^x;
b

```

## Set Operations

These functions allow one to work with the set of elements of $G$, possibly without much knowledge of the structure of $G$.

### `NumberingMap(G): GrpPC -> Map`

A bijective mapping from the group $G$ onto the set of integers $\{1 ... |G|\}$. The actual mapping depends upon the current presentation for $G$.

### `Random(G): GrpPC -> GrpPCElt`

An element, randomly chosen, from the group $G$. This function uses an entirely different procedure than that used by `RandomProcess` (see below). A group element is chosen with uniform probability by generating (pseudo-)random integers in the proper range to form a legal exponent vector for $G$. The corresponding element is returned. This is an extremely efficient process and is the recommended method for producing random elements of a pc-group.

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

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

Create a process to generate 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$. At all times, $N$ elements are stored where $N$ is the maximum of the specified value for `Slots` and `Ngens`$(G) + 1$. Initially, these are simply the generators of $G$ and products of pairs of generators of $G$. Random elements are now produced by successive calls to `Random(P)`, where $P$ is the process created by this function. Each such call chooses an element $x$ stored by the process and returns it, replacing $x$ with the product of $x$ and another random element (multiplied on the left or the right). Setting `Scramble := m` causes $m$ such operations to be performed initially.

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

Given a random element process $P$ created by the function `RandomProcess(G)` for the finite group $G$, construct a random element of $G$ by forming a random product over the expanded generating set constructed when the process was created.

### `Representative(G): GrpPC -> GrpPCElt`

### `Rep(G): GrpPC -> GrpPCElt`

A representative element of $G$. For a pc-group, this always returns the identity element.

### `Example: Set Ops (ex-0f7a7b)`

The `NumberingMap` function assigns a number to each group element.

```magma
> G := DihedralGroup(GrpPC,4);
> num_map := NumberingMap(G);
> for x in G do
>   print x,"->",num_map(x);
> end for;
Id(G) -> 1
G.3 -> 2
G.2 -> 3
G.2 * G.3 -> 4
G.1 -> 5
G.1 * G.3 -> 6
G.1 * G.2 -> 7
G.1 * G.2 * G.3 -> 8

```

The inverse map can be used to obtain the group element corresponding to a particular number.

```magma
> 6 @@ num_map;
G.1 * G.3

```

The `Random` function is sometimes useful to create a statistical profile of a group. To demonstrate, we take two groups of order $3^6$ from the `SmallGroup` database.

```magma
> G1 := SmallGroup(3^6, 60);
> G2 := SmallGroup(3^6, 392);

```

We want to build a histogram of element orders for each group. Since these are 3-groups, each order will be a power of 3 and we use `Ilog` to get the exponent of the order. First, we define a short function to compute the histogram.

```magma
> function hist(G, trials)
>   // Given a 3-group G, of exponent <= 3^5,
>   // return a sequence whose ith term is the
>   // number of elements of order p^(i-1) out
>   // of trials randomly chosen elements.
>   table := [0,0,0,0,0,0];
>   for i := 1 to trials do
>     x := Random(G);
>     n := Ilog(3, Order(x));
>     table[n+1] +:= 1;
>   end for;
>   return table;
> end function;

```

Now, we use this function to compute order distributions for 100 elements in each group.

```magma
> t1 := hist(G1,100);
> t1;
[ 0, 0, 5, 28, 67, 0 ]
> t2 := hist(G2,100);
> t2;
[ 0, 5, 5, 25, 65, 0 ]

```

We can even display them with simple character graphics.

```magma
> for e in t1 do print ":","@"^e; end for;
:
:
: @@@@@
: @@@@@@@@@@@@@@@@@@@@@@@@@@@@
: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
:
> for e in t1 do print ":","@"^e; end for;
:
: @@@@@
: @@@@@
: @@@@@@@@@@@@@@@@@@@@@@@@@
: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
:

```

### `Example: Set (ex-91703e)`

Given the subgroups $H$ and $K$ of $G$, construct the set product of the groups $H$ and $K$.

```magma
> set_product := func<G, H, K | { G | x * y : x in H, y in K }>;

```

Given a subgroup $H$ of the pc-group $G$, construct $H$ as a set of elements of $G$.

```magma
> elements := func<G, H | { G | x : x in H }>;

```
