Parity-check code#

A simple way of detecting up to one error is to use the device of adding a parity check to ensure that the sum of the digits in a transmitted word is even.

A parity-check code of dimension \(k\) over \(\GF{q}\) is the set: \(\{(m_1, m_2, \dots, m_k, - \Sigma_{i=1}^k m_i) \mid (m_1, m_2, \dots, m_k) \in \GF{q}^k\}\)

REFERENCE:

class sage.coding.parity_check_code.ParityCheckCode(base_field=Finite Field of size 2, dimension=7)[source]#

Bases: AbstractLinearCode

Representation of a parity-check code.

INPUT:

  • base_field – the base field over which self is defined.

  • dimension – the dimension of self.

EXAMPLES:

sage: C = codes.ParityCheckCode(GF(5), 7)
sage: C
[8, 7] parity-check code over GF(5)
>>> from sage.all import *
>>> C = codes.ParityCheckCode(GF(Integer(5)), Integer(7))
>>> C
[8, 7] parity-check code over GF(5)
minimum_distance()[source]#

Return the minimum distance of self.

It is always 2 as self is a parity-check code.

EXAMPLES:

sage: C = codes.ParityCheckCode(GF(5), 7)
sage: C.minimum_distance()
2
>>> from sage.all import *
>>> C = codes.ParityCheckCode(GF(Integer(5)), Integer(7))
>>> C.minimum_distance()
2
class sage.coding.parity_check_code.ParityCheckCodeGeneratorMatrixEncoder(code)[source]#

Bases: LinearCodeGeneratorMatrixEncoder

Encoder for parity-check codes which uses a generator matrix to obtain codewords.

INPUT:

  • code – the associated code of this encoder.

EXAMPLES:

sage: C = codes.ParityCheckCode(GF(5), 7)
sage: E = codes.encoders.ParityCheckCodeGeneratorMatrixEncoder(C)
sage: E
Generator matrix-based encoder for [8, 7] parity-check code over GF(5)
>>> from sage.all import *
>>> C = codes.ParityCheckCode(GF(Integer(5)), Integer(7))
>>> E = codes.encoders.ParityCheckCodeGeneratorMatrixEncoder(C)
>>> E
Generator matrix-based encoder for [8, 7] parity-check code over GF(5)

Actually, we can construct the encoder from C directly:

sage: E = C.encoder("ParityCheckCodeGeneratorMatrixEncoder")
sage: E
Generator matrix-based encoder for [8, 7] parity-check code over GF(5)
>>> from sage.all import *
>>> E = C.encoder("ParityCheckCodeGeneratorMatrixEncoder")
>>> E
Generator matrix-based encoder for [8, 7] parity-check code over GF(5)
generator_matrix()[source]#

Return a generator matrix of self.

EXAMPLES:

sage: C = codes.ParityCheckCode(GF(5),7)
sage: E = codes.encoders.ParityCheckCodeGeneratorMatrixEncoder(C)
sage: E.generator_matrix()
[1 0 0 0 0 0 0 4]
[0 1 0 0 0 0 0 4]
[0 0 1 0 0 0 0 4]
[0 0 0 1 0 0 0 4]
[0 0 0 0 1 0 0 4]
[0 0 0 0 0 1 0 4]
[0 0 0 0 0 0 1 4]
>>> from sage.all import *
>>> C = codes.ParityCheckCode(GF(Integer(5)),Integer(7))
>>> E = codes.encoders.ParityCheckCodeGeneratorMatrixEncoder(C)
>>> E.generator_matrix()
[1 0 0 0 0 0 0 4]
[0 1 0 0 0 0 0 4]
[0 0 1 0 0 0 0 4]
[0 0 0 1 0 0 0 4]
[0 0 0 0 1 0 0 4]
[0 0 0 0 0 1 0 4]
[0 0 0 0 0 0 1 4]
class sage.coding.parity_check_code.ParityCheckCodeStraightforwardEncoder(code)[source]#

Bases: Encoder

Encoder for parity-check codes which computes the sum of message symbols and appends its opposite to the message to obtain codewords.

INPUT:

  • code – the associated code of this encoder.

EXAMPLES:

sage: C = codes.ParityCheckCode(GF(5), 7)
sage: E = codes.encoders.ParityCheckCodeStraightforwardEncoder(C)
sage: E
Parity-check encoder for the [8, 7] parity-check code over GF(5)
>>> from sage.all import *
>>> C = codes.ParityCheckCode(GF(Integer(5)), Integer(7))
>>> E = codes.encoders.ParityCheckCodeStraightforwardEncoder(C)
>>> E
Parity-check encoder for the [8, 7] parity-check code over GF(5)

Actually, we can construct the encoder from C directly:

sage: E = C.encoder("ParityCheckCodeStraightforwardEncoder")
sage: E
Parity-check encoder for the [8, 7] parity-check code over GF(5)
>>> from sage.all import *
>>> E = C.encoder("ParityCheckCodeStraightforwardEncoder")
>>> E
Parity-check encoder for the [8, 7] parity-check code over GF(5)
encode(message)[source]#

Transform the vector message into a codeword of code().

INPUT:

  • message – A self.code().dimension()-vector from the message space of self.

OUTPUT:

  • A codeword in associated code of self.

EXAMPLES:

sage: C = codes.ParityCheckCode(GF(5),7)
sage: message = vector(C.base_field(),[1,0,4,2,0,3,2])
sage: C.encode(message)
(1, 0, 4, 2, 0, 3, 2, 3)
>>> from sage.all import *
>>> C = codes.ParityCheckCode(GF(Integer(5)),Integer(7))
>>> message = vector(C.base_field(),[Integer(1),Integer(0),Integer(4),Integer(2),Integer(0),Integer(3),Integer(2)])
>>> C.encode(message)
(1, 0, 4, 2, 0, 3, 2, 3)
message_space()[source]#

Return the message space of self.

EXAMPLES:

sage: C = codes.ParityCheckCode(GF(5),7)
sage: E = codes.encoders.ParityCheckCodeStraightforwardEncoder(C)
sage: E.message_space()
Vector space of dimension 7 over Finite Field of size 5
>>> from sage.all import *
>>> C = codes.ParityCheckCode(GF(Integer(5)),Integer(7))
>>> E = codes.encoders.ParityCheckCodeStraightforwardEncoder(C)
>>> E.message_space()
Vector space of dimension 7 over Finite Field of size 5
unencode_nocheck(word)[source]#

Return the message corresponding to the vector word.

Use this method with caution: it does not check if word belongs to the code.

INPUT:

  • word – A self.code().length()-vector from the ambiant space of self.

OUTPUT:

  • A vector corresponding to the self.code().dimension()-first symbols in word.

EXAMPLES:

sage: C = codes.ParityCheckCode(GF(5), 7)
sage: word = vector(C.base_field(), [1, 0, 4, 2, 0, 3, 2, 3])
sage: E = codes.encoders.ParityCheckCodeStraightforwardEncoder(C)
sage: E.unencode_nocheck(word)
(1, 0, 4, 2, 0, 3, 2)
>>> from sage.all import *
>>> C = codes.ParityCheckCode(GF(Integer(5)), Integer(7))
>>> word = vector(C.base_field(), [Integer(1), Integer(0), Integer(4), Integer(2), Integer(0), Integer(3), Integer(2), Integer(3)])
>>> E = codes.encoders.ParityCheckCodeStraightforwardEncoder(C)
>>> E.unencode_nocheck(word)
(1, 0, 4, 2, 0, 3, 2)