# Construction of Additive Codes

## Construction of General Additive Codes

### `AdditiveCode<F, K, n | L>: FldFin, RngIntElt, List -> Code`

Create the $K$-additive code in $F^{(n)}$ of length $n$ which is generated by the elements specified by the list $L$, where $K$ is a subfield of $F$ and $L$ is one or more items of the following types:

**(a)**
An element of $F^{(n)}$;

**(b)**
A set or sequence of elements of $F^{(n)}$;

**(c)**
A sequence of $n$ elements of $F$, defining an element of $F^{(n)}$;

**(d)**
A set or sequence of sequences of type (c);

**(e)**
A subcode of $F^{(n)}$;

### `AdditiveCode(G): ModMatRngElt -> CodeAdd`

### `AdditiveCode(K, G): FldFin, ModMatRngElt -> CodeAdd`

Given a matrix $G$ over a field $F$ and a subfield $K$ of $F$, return the $K$-additive code over $F$ generated by the rows of $G$. If no coefficient field $K$ is specified, then the prime field of $F$ is used.

### `Example: Add Lin Diff (ex-f9cba7)`

Starting with two linearly independent vectors in ${\mathbb{F}}_4^{(3)}$, we compare the linear code over $F_4$ they generate with the corresponding $F_2$-additive code.

```magma
> F<w> := GF(4);
> G := Matrix(F, 2, 3, [1,0,w^2,0,w,0]);
> G;
[  1   0 w^2]
[  0   w   0]
> C1 := LinearCode(G);
> C2 := AdditiveCode(GF(2), G);
> #C1;
16
> #C2;
4
> C2 subset C1;
true

```

The codewords of $C_2$ are arise only through addition of the generators: scalar multiplication is not permitted.

```magma
> { v : v in C2 };
{
    (  1   w w^2),
    (  0   0   0),
    (  1   0 w^2),
    (  0   w   0)
}

```

### `Example: Code Add From Matrix (ex-9d93b8)`

We define an ${\bf F}_{2}$-additive code over ${\bf F}_{8}$ by constructing a random matrix and considering the code generated by its rows. Note that the number of generators exceeds the length of the code.

```magma
> K<w> := GF(8);
> M := KMatrixSpace(K, 5, 4);
> C := AdditiveCode(GF(2), Random(M));
> C;
[4, 1 2/3 : 5] GF(2)-Additive Code over GF(2^3)
Generator matrix:
[  1   1 w^2   0]
[  w w^2   w   1]
[w^2 w^2 w^2   1]
[  0 w^4 w^4 w^5]
[  0   0   1   0]
> WeightDistribution(C);
[ <0, 1>, <1, 1>, <2, 2>, <3, 9>, <4, 19> ]
> C;
[4, 1 2/3 : 5, 1] GF(2)-Additive Code over GF(2^3)
Generator matrix:
[  1   1 w^2   0]
[  w w^2   w   1]
[w^2 w^2 w^2   1]
[  0 w^4 w^4 w^5]
[  0   0   1   0]

```

### `AdditiveCode(K, C): FldFin, Code -> CodeAdd`

Given a code (linear or additive) $C$ over some finite field $F$, and a subfield $K$ of $F$ such that the wordset of $C$ forms a $K$-linear subspace, then return $C$ as a $K$-additive code.

### `Example: Code Add From Code (ex-8b74a8)`

Any linear code can be regarded as an additive code with respect to a subfield of its alphabet.

```magma
> C := RandomLinearCode(GF(4), 8, 3);
> C:Minimal;
[8, 3, 4] Linear Code over GF(2^2)
> A1 := AdditiveCode(GF(4), C);
> A1:Minimal;
[8, 3 : 3, 4] GF(2^2)-Additive Code over GF(2^2)
> { v : v in C } eq {v : v in A1 };
true
>
> A2 := AdditiveCode(GF(2), C);
> A2:Minimal;
[8, 3 : 6, 4] GF(2)-Additive Code over GF(2^2)
> { v : v in C } eq {v : v in A2 };
true

```

### `Example: Code Add From Code Fail (ex-770cac)`

A $K$-additive code over $F$ can be viewed as an $E$-additive code for any subfield $E \subseteq K$.

```magma
> C4 := RandomAdditiveCode(GF(16), GF(4), 8, 5);
> C4:Minimal;
[8, 2 1/2 : 5] GF(2^2)-Additive Code over GF(2^4)
>
> C2 := AdditiveCode(GF(2), C4);
> C2:Minimal;
[8, 2 1/2 : 10] GF(2)-Additive Code over GF(2^4)
> { v : v in C2 } eq {v : v in C4 };
true

```

But for any $E$ such that $K \subset E \subseteq F$ we can create an $E$-additive code if and only if the wordset is in fact an $E$-linear subspace.

```magma
> C2:Minimal;
[8, 2 1/2 : 10] GF(2)-Additive Code over GF(2^4)
> A1 := AdditiveCode(GF(4), C2);
> A1 eq C4;
true
> A2 := AdditiveCode(GF(16), C2);

>> A2 := AdditiveCode(GF(16), C2);
                     ^
Runtime error in 'AdditiveCode': Code is not additive over given field

```

## Some Trivial Additive Codes

### `AdditiveZeroCode(F, K, n): FldFin, FldFin, RngIntElt -> CodeAdd`

Given a field $F$ and subfield $K \subseteq F$ along with a positive integer $n$, return the $[n,0,n]$ code consisting of only the zero code word, (where the minimum weight is by convention equal to $n$).

### `AdditiveRepetitionCode(F, K, n): FldFin, FldFin, RngIntElt -> Code`

Given a field $F$ and subfield $K \subseteq F$ along with a positive integer $n$, return the $[n,1,n]$ code consisting of all repeating codewords.

### `AdditiveZeroSumCode(F, K, n): FldFin, FldFin, RngIntElt -> Code`

Given a field $F$ and subfield $K \subseteq F$ along with a positive integer $n$, return the $[n,n-1,2]$ $K$-additive code over $F$ such that for all codewords $(c_1,c_2,\ldots ,c_n)$, we have $\sum_{i} c_i =0$.

### `AdditiveUniverseCode(F, K, n): FldFin, FldFin, RngIntElt -> Code`

Given a field $F$ and subfield $K \subseteq F$ along with a positive integer $n$, return the $[n,n,1]$ $K$-additive code over $F$ consisting of all possible codewords.

### `RandomAdditiveCode(F, K, n, k): FldFin, FldFin, RngIntElt, RngIntElt -> Code`

Given a field $F$ and subfield $K \subseteq F$ along with positive integers $n$ and $k$, such that $0 < k \le n*[F:K]$, and $k$, return a random $K$-additive code of length $n$ and $k$ generators over the field $F$.

### `Example: Simple Code Chain (ex-24f23c)`

Over any finite field chain $K \subseteq F$, the zero code of length $n$ is contained in every code of length $n$, and similarly every code of length $n$ is contained in the universe code of length $n$.

```magma
> F := GF(9);
> K := GF(3);
> U := AdditiveUniverseCode(F, K, 5);
> Z := AdditiveZeroCode(F, K, 5);
> R := RandomAdditiveCode(F, K, 5, 2);
> (Z subset R) and (R subset U);
true

```
