Skip to content

komm.CyclicCode

General binary cyclic code. A cyclic code is a linear block code such that, if $c$ is a codeword, then every cyclic shift of $c$ is also a codeword. It is characterized by its generator polynomial $g(X)$, of degree $m$ (the redundancy of the code), and by its check polynomial $h(X)$, of degree $k$ (the dimension of the code). Those polynomials are related by $g(X) h(X) = X^n + 1$, where $n = k + m$ is the length of the code.

Examples of generator polynomials can be found in the table below.

Code $(n, k, d)$ Generator polynomial $g(X)$ Integer representation
Hamming $(7,4,3)$ $X^3 + X + 1$ 0b1011 = 0o13 = 11
Simplex $(7,3,4)$ $X^4 + X^2 + X + 1$ 0b10111 = 0o27 = 23
BCH $(15,5,7)$ $X^{10} + X^8 + X^5 + X^4 + X^2 + X + 1$ 0b10100110111 = 0o2467 = 1335
Golay $(23,12,7)$ $X^{11} + X^9 + X^7 + X^6 + X^5 + X + 1$ 0b101011100011 = 0o5343 = 2787

For more details, see LC04, Ch. 5.

The constructor expects either the generator polynomial or the check polynomial.

Attributes:

  • length (int)

    The length $n$ of the code.

  • generator_polynomial (BinaryPolynomial)

    The generator polynomial $g(X)$ of the code, of degree $m$ (the redundancy of the code), specified either as a binary polynomial or as an integer to be converted to the former.

  • check_polynomial (BinaryPolynomial)

    The check polynomial $h(X)$ of the code, of degree $k$ (the dimension of the code), specified either as a binary polynomial or as an integer to be converted to the former.

  • systematic

    Whether the encoder is systematic. Default is True.

Examples:

>>> code = komm.CyclicCode(length=23, generator_polynomial=0b101011100011)  # Golay (23, 12)
>>> (code.length, code.dimension, code.redundancy)
(23, 12, 11)
>>> code.minimum_distance()
7
>>> code = komm.CyclicCode(length=23, check_polynomial=0b1010010011111)  # Golay (23, 12)
>>> (code.length, code.dimension, code.redundancy)
(23, 12, 11)
>>> code.minimum_distance()
7

length: int property

The length $n$ of the code.

dimension: int property

The dimension $k$ of the code.

redundancy: int property

The redundancy $m$ of the code.

rate: float property

The rate $R = k/n$ of the code.

generator_matrix: npt.NDArray[np.integer] cached property

The generator matrix $G \in \mathbb{B}^{k \times n}$ of the code.

generator_matrix_right_inverse: npt.NDArray[np.integer] cached property

The right-inverse $G^+ \in \mathbb{B}^{n \times k}$ of the generator matrix.

check_matrix: npt.NDArray[np.integer] cached property

The check matrix $H \in \mathbb{B}^{m \times n}$ of the code.

encode

Applies the encoding mapping $\Enc : \mathbb{B}^k \to \mathbb{B}^n$ of the code. This method takes one or more sequences of messages and returns their corresponding codeword sequences.

Parameters:

  • input (ArrayLike)

    The input sequence(s). Can be either a single sequence whose length is a multiple of $k$, or a multidimensional array where the last dimension is a multiple of $k$.

Returns:

  • output (NDArray[integer])

    The output sequence(s). Has the same shape as the input, with the last dimension expanded from $bk$ to $bn$, where $b$ is a positive integer.

inverse_encode

Applies the inverse encoding mapping $\Enc^{-1} : \mathbb{B}^n \to \mathbb{B}^k$ of the code. This method takes one or more sequences of codewords and returns their corresponding message sequences.

Parameters:

  • input (ArrayLike)

    The input sequence(s). Can be either a single sequence whose length is a multiple of $n$, or a multidimensional array where the last dimension is a multiple of $n$.

Returns:

  • output (NDArray[integer])

    The output sequence(s). Has the same shape as the input, with the last dimension contracted from $bn$ to $bk$, where $b$ is a positive integer.

check

Applies the check mapping $\mathrm{Chk}: \mathbb{B}^n \to \mathbb{B}^m$ of the code. This method takes one or more sequences of received words and returns their corresponding syndrome sequences.

Parameters:

  • input (ArrayLike)

    The input sequence(s). Can be either a single sequence whose length is a multiple of $n$, or a multidimensional array where the last dimension is a multiple of $n$.

Returns:

  • output (NDArray[integer])

    The output sequence(s). Has the same shape as the input, with the last dimension contracted from $bn$ to $bm$, where $b$ is a positive integer.

codewords cached

Returns the codewords of the code. This is a $2^k \times n$ matrix whose rows are all the codewords. The codeword in row $i$ corresponds to the message obtained by expressing $i$ in binary with $k$ bits (MSB in the right).

codeword_weight_distribution cached

Returns the codeword weight distribution of the code. This is an array of shape $(n + 1)$ in which element in position $w$ is equal to the number of codewords of Hamming weight $w$, for $w \in [0 : n]$.

minimum_distance cached

Returns the minimum distance $d$ of the code. This is equal to the minimum Hamming weight of the non-zero codewords.

coset_leaders cached

Returns the coset leaders of the code. This is a $2^m \times n$ matrix whose rows are all the coset leaders. The coset leader in row $i$ corresponds to the syndrome obtained by expressing $i$ in binary with $m$ bits (MSB in the right), and whose Hamming weight is minimal. This may be used as a LUT for syndrome-based decoding.

coset_leader_weight_distribution cached

Returns the coset leader weight distribution of the code. This is an array of shape $(n + 1)$ in which element in position $w$ is equal to the number of coset leaders of weight $w$, for $w \in [0 : n]$.

packing_radius cached

Returns the packing radius of the code. This is also called the error-correcting capability of the code, and is equal to $\lfloor (d - 1) / 2 \rfloor$.

covering_radius cached

Returns the covering radius of the code. This is equal to the maximum Hamming weight of the coset leaders.