# New Codes from Old

The operations described here produce a new code by modifying in some way the codewords of a given code.

## Standard Constructions

### `AugmentCode(C): CodeAdd -> Code`

Construct a new additive code by including the all-ones vector with the words of the additive code $C$.

### `CodeComplement(C, S): Code, Code -> Code`

Given a subcode $S$ of the code $C$, return a code $C'$ such that $C=S + C'$. Both $C$ and $S$ must be defined over the same field.

### `DirectSum(C, D): Code, Code -> Code`

Given codes $C$ and $D$, form the code that is direct sum of $C$ and $D$. The direct sum consists of all vectors $u|v$, where $u \in C$ and $v \in D$.

### `DirectSum(Q): [Code] -> Code`

Given a sequence of codes $Q = [C_1, \dots, C_r]$, all defined over the same field $F$, construct the direct sum of the $C_i$.

### `DirectProduct(C, D): Code, Code -> Code`

Given an $[n_1, k_1]$ code $C$ and an $[n_2, k_2]$ code $D$, both over the same ring $R$, construct the direct product of $C$ and $D$. The direct product has length $n_1\cdot n_2$ and its generator matrix is the Kronecker product of the basis matrices of $C$ and $D$.

### `ExtendCode(C): CodeAdd -> CodeAdd`

Given an $[n, k, d]$ additive code $C$, form a new code $C'$ from $C$ by adding the appropriate extra coordinate to each vector of $C$ such that the sum of the coordinates of the extended vector is zero.

### `ExtendCode(C, n): Code, RngIntElt -> Code`

Return the code obtained by extending the code $C$ extended $n$ times.

### `PadCode(C, n): CodeAdd, RngIntElt -> CodeAdd`

Add $n$ zeros to the end of each codeword of the code $C$.

### `PlotkinSum(C1, C2): Code, Code -> Code`

Given codes $C_1$ and $C_2$ defined over the same alphabet, return the code consisting of all vectors of the form $u|u+v$, where $u \in C1$ and $v \in C2$. Zeros are appended where needed to make up any length differences in the two codes.

### `PlotkinSum(C1, C2, C3: parameters): Code, Code, Code -> Code`

```magma
a: FldFinElt                    Default: -1
```

Given three codes $C_1$, $C_2$ and $C_3$ defined over the same alphabet $K$, return the code consisting of all vectors of the form $u|u+a*v|u+v+w$, where $u \in C1$, $v \in C2$ and $w \in C3$. The default value of the multiplier $a$ is a primitive element of $K$. Zeros are appended where needed to ensure that every codeword has the same length.

### `PunctureCode(C, i): CodeAdd, RngIntElt -> Code`

Given an $[n, k]$ code $C$, and an integer $i$, $1 \leq i \leq n$, construct a new code $C'$ by deleting the $i$-th coordinate from each code word of $C$.

### `PunctureCode(C, S): CodeAdd, { RngIntElt } -> Code`

Given an $[n, k]$ code $C$ and a set $S$ of distinct integers $\{ i_1, \cdots, {\mathrm{i}}_r \}$ each of which lies in the range $[1, n]$, construct a new code $C'$ by deleting the components $i_1, \cdots, i_r$ from each code word of $C$.

### `ShortenCode(C, i): Code, RngIntElt -> Code`

Given an $[n, k]$ code $C$ and an integer $i$, $1 \leq i \leq n$, construct a new code from $C$ by selecting only those codewords of $C$ having a zero as their $i$-th component and deleting the $i$-th component from these codewords. Thus, the resulting code will have length $n-1$.

### `ShortenCode(C, S): Code, { RngIntElt } -> Code`

Given an $[n, k]$ code $C$ and a set $S$ of distinct integers $\{ i_1, \cdots, {\mathrm{i}}_r\}$, each of which lies in the range $[1, n]$, construct a new code from $C$ by selecting only those codewords of $C$ having zeros in each of the coordinate positions $i_1, \cdots, i_r$, and deleting these components. Thus, the resulting code will have length $n-r$.

## Combining Codes

### `C1 cat C2: CodeAdd, CodeAdd -> CodeAdd`

Given codes $C1$ and $C2$, both defined over the same field $K$, return the concatenation $C$ of $C1$ and $C2$. The generators of the resultant code are the concatenations of the generators of $C1$ and $C2$.

### `Juxtaposition(C1, C2): Code, Code -> Code`

Given an $[n_1,k,d_1]$ code $C1$ and an $[n_2,k,d_2]$ code $C2$ of the same dimension, where both codes are defined over the same field $K$, this function returns a $[n_1+n_2,k,\geq  d_1+d_2]$ code whose generator matrix is `HorizontalJoin(A, B)`, where $A$ and $B$ are the generator matrices for codes $C1$ and $C2$, respectively.
