---
title: "Subcodes"
canonical: "https://docs.magma-maths.org/v2.30-1/CodingTheory/AdditiveCodes/subcode.html"
source: "https://docs.magma-maths.org/v2.30-1/CodingTheory/AdditiveCodes/subcode.md"
part: "Coding Theory"
chapter: "Additive Codes"
breadcrumbs:
  - {"title": "Magma Handbook", "source": "https://docs.magma-maths.org/v2.30-1/index.md"}
  - {"title": "Coding Theory", "source": "https://docs.magma-maths.org/v2.30-1/CodingTheory/index-coding-theory.md"}
  - {"title": "Additive Codes", "source": "https://docs.magma-maths.org/v2.30-1/CodingTheory/AdditiveCodes/index-additive-codes.md"}
prev: {"title": "Operations on Codewords", "source": "https://docs.magma-maths.org/v2.30-1/CodingTheory/AdditiveCodes/element.md"}
next: {"title": "Properties of Codes", "source": "https://docs.magma-maths.org/v2.30-1/CodingTheory/AdditiveCodes/Boolean.md"}
intrinsics:
  - {"name": "sub", "signature": "sub<C | L>: CodeAdd, List -> CodeAdd"}
  - {"name": "Subcode", "signature": "Subcode(C, k): CodeAdd, RngIntElt -> CodeAdd"}
  - {"name": "Subcode", "signature": "Subcode(C, S): CodeAdd, { RngIntElt } -> Code"}
  - {"name": "SubcodeBetweenCode", "signature": "SubcodeBetweenCode(C1, C2, k): CodeAdd, CodeAdd, RngIntElt -> CodeAdd"}
  - {"name": "SubcodeWordsOfWeight", "signature": "SubcodeWordsOfWeight(C, w): CodeAdd, RngIntElt -> CodeAdd"}
  - {"name": "SubcodeWordsOfWeight", "signature": "SubcodeWordsOfWeight(C, S): CodeAdd, { RngIntElt } -> CodeAdd"}
  - {"name": "+", "signature": "C + D: CodeAdd, CodeAdd -> CodeAdd"}
  - {"name": "meet", "signature": "C meet D: Code, Code -> Code"}
  - {"name": "Dual", "signature": "Dual(C): Code -> Code"}
  - {"name": "in", "signature": "u in C: ModTupRngElt, CodeAdd -> BoolElt"}
  - {"name": "notin", "signature": "u notin C: ModTupRngElt, CodeAdd -> BoolElt"}
  - {"name": "subset", "signature": "C subset D: Code, Code -> BoolElt"}
  - {"name": "notsubset", "signature": "C notsubset D: Code, Code -> BoolElt"}
  - {"name": "eq", "signature": "C eq D: Code, Code -> BoolElt"}
  - {"name": "ne", "signature": "C ne D: Code, Code -> BoolElt"}
examples:
  - "ex-18722c"
---

# Subcodes

## The Subcode Constructor

<a id="constructor-constructor-sub-codeadd-list-codeadd"></a>
### `sub<C | L>: CodeAdd, List -> CodeAdd`

Given a $K$-additive linear code $C$ over $F$, construct the subcode of $C$, generated (over $K$) by the elements specified by the list $L$, where $L$ is a list of one or more items of the following types:

**(a)**
An element of $C$;

**(b)**
A set or sequence of elements of $C$;

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

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

**(e)**
A subcode of $C$;

<a id="function-subcode-codeadd-rngintelt"></a>
### `Subcode(C, k): CodeAdd, RngIntElt -> CodeAdd`

Given an additive code $C$ and an integer $k$, where $k$ is less than the number of generators of $C$, then return a subcode of $C$ with $k$ generators.

<a id="function-subcode-codeadd-rngintelt-2"></a>
### `Subcode(C, S): CodeAdd, { RngIntElt } -> Code`

Suppose $C$ is an additive code and $S$ is a set of positive integers, each of which is less than the number of generators of $C$. The function returns the subcode of $C$ generated by the generators of $C$ indexed by $S$.

<a id="function-subcodebetweencode-codeadd-codeadd-rngintelt"></a>
### `SubcodeBetweenCode(C1, C2, k): CodeAdd, CodeAdd, RngIntElt -> CodeAdd`

Given an additive code $C_1$ and a subcode $C_2$ of $C_1$, return a subcode of $C_1$ with $k$ generators containing $C_2$.

<a id="function-subcodewordsofweight-codeadd-rngintelt"></a>
### `SubcodeWordsOfWeight(C, w): CodeAdd, RngIntElt -> CodeAdd`

Given a length $n$ additive code $C$ and an integer which lies in the range $[1,n]$, return the subcode of $C$ generated by those words of $C$ of weight $w$.

<a id="function-subcodewordsofweight-codeadd-rngintelt-2"></a>
### `SubcodeWordsOfWeight(C, S): CodeAdd, { RngIntElt } -> CodeAdd`

Given a length $n$ additive code $C$ and a set $S$ of integers, each of which lies in the range $[1,n]$, return the subcode of $C$ generated by those words of $C$ whose weights lie in $S$.

<a id="example-ex-18722c"></a>
### `Example: Subcode between Two Codes (ex-18722c)`

We give an example of how `SubcodeBetweenCode` may be used to create a code nested in between a subcode pair.

```magma
> F<w> := GF(8);
> C1 := AdditiveRepetitionCode(F, GF(2), 6);
> C1;
[6, 1 : 3, 6] GF(2)-Additive Code over GF(2^3)
Generator matrix:
[  1   1   1   1   1   1]
[  w   w   w   w   w   w]
[w^2 w^2 w^2 w^2 w^2 w^2]
> C3 := AdditiveZeroSumCode(F, GF(2), 6);
> C3;
[6, 5 : 15, 2] GF(2)-Additive Code over GF(2^3)
Generator matrix:
[  1   0   0   0   0   1]
[  w   0   0   0   0   w]
[w^2   0   0   0   0 w^2]
[  0   1   0   0   0   1]
[  0   w   0   0   0   w]
[  0 w^2   0   0   0 w^2]
[  0   0   1   0   0   1]
[  0   0   w   0   0   w]
[  0   0 w^2   0   0 w^2]
[  0   0   0   1   0   1]
[  0   0   0   w   0   w]
[  0   0   0 w^2   0 w^2]
[  0   0   0   0   1   1]
[  0   0   0   0   w   w]
[  0   0   0   0 w^2 w^2]
> C1 subset C3;
true
> C2 := SubcodeBetweenCode(C3, C1, 11);
> C2;
[6, 3 2/3 : 11] GF(2)-Additive Code over GF(2^3)
Generator matrix:
[  1   0   0   0   1   0]
[  w   0   0   0   w   0]
[w^2   0   0 w^2 w^2 w^2]
[  0   1   0   0   0   1]
[  0   w   0   0   0   w]
[  0 w^2   0   0   0 w^2]
[  0   0   1   0   0   1]
[  0   0   w   0   0   w]
[  0   0 w^2   0   0 w^2]
[  0   0   0   1   0   1]
[  0   0   0   w   0   w]
> (C1 subset C2) and (C2 subset C3);
true
```

## Sum, Intersection, and Dual

For the following operators, $C$ and $D$ are additive codes defined as subsets (or subspaces) of the same $R$-space $F^n$.

<a id="operation-op-plus-codeadd-codeadd"></a>
### `C + D: CodeAdd, CodeAdd -> CodeAdd`

Given two additive codes which have the same length, which are defined over the same alphabet, and which have the same coefficient ring $F$, return the sum of these two codes with respect to $F$.

<a id="operation-op-meet-code-code"></a>
### `C meet D: Code, Code -> Code`

The intersection of the additive codes $C$ and $D$.

<a id="function-dual-code"></a>
### `Dual(C): Code -> Code`

The code that is dual to the code $C$. For an additive code $C$, this is the code generated by the nullspace of $C$, relative to the trace inner product.

## Membership and Equality

<a id="operation-op-in-modtuprngelt-codeadd"></a>
### `u in C: ModTupRngElt, CodeAdd -> BoolElt`

Return `true` if and only if the vector $u$ of $V$ belongs to the additive code $C$, where $V$ is the generic vector space containing $C$.

<a id="operation-op-notin-modtuprngelt-codeadd"></a>
### `u notin C: ModTupRngElt, CodeAdd -> BoolElt`

Return `true` if and only if the vector $u$ does not belong to the additive code $C$, where $V$ is the generic vector space containing $C$.

<a id="operation-op-subset-code-code"></a>
### `C subset D: Code, Code -> BoolElt`

Return `true` if and only if the wordset of the code $C$ is a subset of the wordset of the code $D$. (Either code may possibly be additive).

<a id="operation-operation-notsubset-code-code-boolelt"></a>
### `C notsubset D: Code, Code -> BoolElt`

Return `true` if and only if the wordset of the code $C$ is not a subset of the wordset of the code $D$. (Either code may possibly be additive).

<a id="operation-op-eq-code-code"></a>
### `C eq D: Code, Code -> BoolElt`

Return `true` if and only if the codes $C$ and $D$ have the same wordsets. (Either code may possibly be additive).

<a id="operation-op-ne-code-code"></a>
### `C ne D: Code, Code -> BoolElt`

Return `true` if and only if the codes $C$ and $D$ have different wordsets. (Either code may possibly be additive).
