# Creation Functions

## Creation of Structures

### `GaloisRing(q, d): RngIntElt, RngIntElt -> RngGal`

### `GR(q, d): RngIntElt, RngIntElt -> RngGal`

Given integers $q$, $d\ge 1$, where $q = p^a$ for prime $p$ and $a\ge 1$, create the default Galois ring $\operatorname{GR}({p^a}, { d})$. The defining polynomial used to construct the ring will be that used for ${\bf F}_{p^d}$, lifted to ${\mathbb{Z}}_{p^a}$. If $p$ is very large, it is advised to use the next function instead, because Magma must first factor $q$ completely. The angle bracket notation can be used to assign names to the generator; e.g.: `R<w> := GaloisRing(2, 3)`.

### `GaloisRing(p, a, d): RngIntElt, RngIntElt, RngIntElt -> RngGal`

### `GR(p, a, d): RngIntElt, RngIntElt, RngIntElt -> RngGal`

```magma
Check: BoolElt                    Default: true
```

Given a prime $p$ and integers $a, d\ge 1$, create the default Galois ring $\operatorname{GR}({p^a}, { d})$. The defining polynomial used to construct the ring will be that used for ${\bf F}_{p^d}$, lifted to ${\mathbb{Z}}_{p^a}$. By default $p$ is checked to be a strong pseudoprime for 20 random bases $b$ with $1 < b < p$; if the parameter `Check` is `false`, then no check is done on $p$ at all (this is useful when $p$ is very large and one does not wish to perform an expensive primality test on $p$).

### `GaloisRing(q, D): RngIntElt, RngUPol -> RngGal`

### `GR(q, D): RngIntElt, RngUPol -> RngGal`

Given an integer $q$, where $q = p^a$ for prime $p$ and $a\ge 1$, and a monic polynomial $D$ over ${\mathbb{Z}}$ such that $D$ is irreducible mod $p$, create the Galois ring $R = \operatorname{GR}({p^a}, { D})$. The coefficients of $D$ are reduced modulo $p^a$, and $R$ is constructed to behave like the polynomial quotient ring ${\mathbb{Z}}_{p^a}[x]/\langle D\rangle$. If $p$ is very large, it is advised to use the next function instead, because Magma must first factor $q$ completely.

### `GaloisRing(p, a, D): RngIntElt, RngIntElt, RngUPol -> RngGal`

### `GR(p, a, D): RngIntElt, RngIntElt, RngUPol -> RngGal`

```magma
Check: BoolElt                    Default: true
```

Given a prime $p$, an integer $a\ge 1$, and a monic polynomial $D$ over ${\mathbb{Z}}$ such that $D$ is irreducible mod $p$, create the Galois ring $R = \operatorname{GR}({p^a}, { D})$. The coefficients of $D$ are reduced modulo $p^a$, and $R$ is constructed to behave like the polynomial quotient ring ${\mathbb{Z}}_{p^a}[x]/\langle D\rangle$. The parameter `Check` is as above.

## Names

### `AssignNames(~R, [f]): RngGal, [ MonStgElt ])`

Procedure to change the name of the generating element in the Galois ring $R$ to the contents of the string $f$. When $R$ is created, the name will be `R.1`. This procedure only changes the name used in printing the elements of $R$. It does *not* assign to an identifier called $f$ the value of the generator in $R$; to do this, use an assignment statement, or use angle brackets when creating the ring. Note that since this is a procedure that modifies $R$, it is necessary to have a reference `~R` to $R$ in the call to this function.

### `Name(R, 1): RngGal, RngIntElt -> RngGalElt`

Given a Galois ring $R$, return the element which has the name attached to it, that is, return the element `R.1` of $R$.

## Creation of Elements

### `R . 1: RngGal -> RngGalElt`

### `Generator(R): RngGal -> RngGalElt`

The generator for $R$ as an algebra over its base ring ${\mathbb{Z}}_{p^a}$. Thus, if $R$ is viewed as ${\mathbb{Z}}_{p^a}[x]/\langle D\rangle$, then `R.1` corresponds to $x$ in this presentation.

### `R ! a: RngGal, RngElt -> RngGalElt`

Given a Galois ring $R$ create the element specified by $a$; here $a$ is allowed to be an element coercible into $R$, which means that $a$ may be

**(i)**
An element of $R$;

**(ii)**
An integer, to be identified with $a$ modulo the characteristic $p^a$ of $R$;

**(iii)**
An element of the base ring ${\mathbb{Z}}_{p^a}$ of $R$, to be identified with the corresponding element of $R$.

**(iv)**
A sequence of elements of the base ring ${\mathbb{Z}}_{p^a}$ of $R$. In this case the element $a_0+a_1w+\cdots+a_{n-1}w^{n-1}$ is created, where $a=[a_0, \ldots a_{n-1}]$ and $w$ is the generator `R.1` of $R$ over ${\mathbb{Z}}_{p^a}$.

### `One(R): RngGal -> RngGalElt`

### `Identity(R): RngGal -> RngGalElt`

### `Zero(R): RngGal -> RngGalElt`

### `Representative(R): RngGal -> RngGalElt`

These generic functions create $1$, $1$, $0$, and $0$ respectively, in any Galois ring.

### `Random(R): RngGal -> RngGalElt`

Create a pseudo-random element of Galois ring $R$.

## Sequence Conversions

### `ElementToSequence(a): RngGalElt -> [ RngIntResElt ]`

### `Eltseq(a): RngGalElt -> [ RngIntResElt ]`

Given an element $a$ of the Galois ring $R$, return the sequence of coefficients $[a_0, \ldots, a_{n-1}]$ in the base ring ${\mathbb{Z}}_{p^a}$ of $R$ (where $R$ is ${\mathbb{Z}}_{p^a}[x]/\langle D\rangle$), such that $a=a_0+a_1w+\cdots+a_{n-1}w^{d-1}$, with $w$ the generator of $R$, and $d$ the degree of $D$.

### `Example: Create (ex-5d69d7)`

We can define the Galois ring $\operatorname{GR}({2^3}, { 2})$ using the default function:

```magma
> R<w> := GaloisRing(2^3, 2);
> R;
GaloisRing(2, 3, 2)

```

We note that $R$ has characteristic 8 and that $w^2 + w + 1 = 0$ in $R$.

```magma
> R!8;
0
> R!9;
1
> w;
w
> 4*w;
4*w
> 4*w + 4*w;
0
> w^2;
7*w + 7
> w^2 + w + 1;
0

```

We can list all the elements of $R$ by simply looping over $R$:

```magma
> [x: x in R];
[ 0, 1, 2, 3, 4, 5, 6, 7, w, w + 1, w + 2, w + 3, w + 4, w + 5, w + 6,
    w + 7, 2*w, 2*w + 1, 2*w + 2, 2*w + 3, 2*w + 4, 2*w + 5, 2*w + 6, 2*w
    + 7, 3*w, 3*w + 1, 3*w + 2, 3*w + 3, 3*w + 4, 3*w + 5, 3*w + 6,
    3*w + 7, 4*w, 4*w + 1, 4*w + 2, 4*w + 3, 4*w + 4, 4*w + 5, 4*w +
    6, 4*w + 7, 5*w, 5*w + 1, 5*w + 2, 5*w + 3, 5*w + 4, 5*w + 5, 5*w
    + 6, 5*w + 7, 6*w, 6*w + 1, 6*w + 2, 6*w + 3, 6*w + 4, 6*w + 5,
    6*w + 6, 6*w + 7, 7*w, 7*w + 1, 7*w + 2, 7*w + 3, 7*w + 4, 7*w +
    5, 7*w + 6, 7*w + 7 ]

```

We see that the elements of $R$ can be considered as polynomials of degree at most 1, with coefficients in the range $\{ 0 \ldots 7\}$. We can easily create elements of $R$ also using the `!` operator, and use the `Eltseq` function to recover the corresponding sequence of coefficients.

```magma
> R ! [1, 2];
2*w + 1
> Eltseq(2*w + 1);
[ 1, 2 ]
> Eltseq(w);
[ 0, 1 ]

```
