---
title: "Subcodes"
canonical: "https://docs.magma-maths.org/v2.30-1/CodingTheory/LinearCodesOverFiniteRings/subcode.html"
source: "https://docs.magma-maths.org/v2.30-1/CodingTheory/LinearCodesOverFiniteRings/subcode.md"
part: "Coding Theory"
chapter: "Linear Codes over Finite Rings"
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": "Linear Codes over Finite Rings", "source": "https://docs.magma-maths.org/v2.30-1/CodingTheory/LinearCodesOverFiniteRings/index-linear-codes-over-finite-rings.md"}
prev: {"title": "Invariants", "source": "https://docs.magma-maths.org/v2.30-1/CodingTheory/LinearCodesOverFiniteRings/access.md"}
next: {"title": "Boolean Predicates", "source": "https://docs.magma-maths.org/v2.30-1/CodingTheory/LinearCodesOverFiniteRings/Boolean.md"}
intrinsics:
  - {"name": "sub", "signature": "sub<C | L>: Code, List -> Code"}
  - {"name": "Subcode", "signature": "Subcode(C, t): Code, RngIntElt -> Code"}
  - {"name": "Subcode", "signature": "Subcode(C, S): Code, {RngIntElt} -> Code"}
examples:
  - "ex-89c02d"
---

# Subcodes

## The Subcode Constructor

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

Given a length $n$ linear code $C$ over $R$, construct the subcode of $C$, generated 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 $R$, defining an element of $C$;

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

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

**(f)**
A set or sequence of subcodes of $C$.

<a id="function-subcode-code-rngintelt"></a>
### `Subcode(C, t): Code, RngIntElt -> Code`

Given a length $n$ linear code $C$ with $k$ generators and an integer $t$, $1 \le t < k$, return a subcode of $C$ of pseudo-dimension $t$.

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

Given a length $n$ linear code $C$ with $k$ generators and a set $S$ of integers, each of which lies in the range $[1,k]$, return the subcode of $C$ generated by the basis elements whose positions appear in $S$.

<a id="example-ex-89c02d"></a>
### `Example: Subcode over a Galois Ring (ex-89c02d)`

We construct a subcode of a code over a Galois ring by multiplying each of its generators by a zero divisor.

```magma
> R<w> := GR(4,2);
> C := RandomLinearCode(R, 4, 2);
> C;
(4, 256, 3) Linear Code over GaloisRing(2, 2, 2)
Generator matrix:
[      1       0   w + 1 3*w + 2]
[      0       1 3*w + 1       1]
> #C;
256
>
> C1 := sub< C | 2*C.1, 2*C.2 >;
> C1;
(4, 16, 3) Linear Code over GaloisRing(2, 2, 2)
Generator matrix:
[      2       0 2*w + 2     2*w]
[      0       2 2*w + 2       2]
> #C1;
16
```
