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 $$F_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 F_q^k\}$$

REFERENCE:

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

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)

minimum_distance()#

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

class sage.coding.parity_check_code.ParityCheckCodeGeneratorMatrixEncoder(code)#

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)


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)

generator_matrix()#

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]

class sage.coding.parity_check_code.ParityCheckCodeStraightforwardEncoder(code)#

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)


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)

encode(message)#

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)

message_space()#

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

unencode_nocheck(word)#

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)