galois.ReedSolomon.encode(output: Literal[codeword] | Literal[parity] = 'codeword')

Encodes the message $$\mathbf{m}$$ into the codeword $$\mathbf{c}$$.

Parameters:
message: ArrayLike

The message as either a $$k$$-length vector or $$(N, k)$$ matrix, where $$N$$ is the number of messages.

Shortened codes

For the shortened $$[n-s,\ k-s,\ d]$$ code (only applicable for systematic codes), pass $$k-s$$ symbols into encode() to return the $$n-s$$-symbol message.

output: Literal[codeword] | Literal[parity] = 'codeword'

Specify whether to return the codeword or parity symbols only. The default is "codeword".

Returns:

If output="codeword", the codeword as either a $$n$$-length vector or $$(N, n)$$ matrix. If output="parity", the parity symbols as either a $$n-k$$-length vector or $$(N, n-k)$$ matrix.

The message vector $$\mathbf{m}$$ is a member of $$\mathrm{GF}(q)^k$$. The corresponding message polynomial $$m(x)$$ is a degree-$$k$$ polynomial over $$\mathrm{GF}(q)$$.

$\mathbf{m} = [m_{k-1},\ \dots,\ m_1,\ m_0] \in \mathrm{GF}(q)^k$

$m(x) = m_{k-1} x^{k-1} + \dots + m_1 x + m_0 \in \mathrm{GF}(q)[x]$

The codeword vector $$\mathbf{c}$$ is a member of $$\mathrm{GF}(q)^n$$. The corresponding codeword polynomial $$c(x)$$ is a degree-$$n$$ polynomial over $$\mathrm{GF}(q)$$.

$\mathbf{c} = [c_{n-1},\ \dots,\ c_1,\ c_0] \in \mathrm{GF}(q)^n$

$c(x) = c_{n-1} x^{n-1} + \dots + c_1 x + c_0 \in \mathrm{GF}(q)[x]$

The codeword vector is computed by matrix multiplication of the message vector with the generator matrix. The equivalent polynomial operation is multiplication of the message polynomial with the generator polynomial.

$\mathbf{c} = \mathbf{m} \mathbf{G}$

$c(x) = m(x) g(x)$

Examples

Encode a single message using the $$\textrm{RS}(15, 9)$$ code.

In : rs = galois.ReedSolomon(15, 9)

In : GF = rs.field

In : m = GF.Random(rs.k); m
Out: GF([ 2,  0, 13,  5, 11,  0,  2,  7,  0], order=2^4)

In : c = rs.encode(m); c
Out: GF([ 2,  0, 13,  5, 11,  0,  2,  7,  0, 15,  7,  6, 15,  9, 15], order=2^4)


Compute the parity symbols only.

In : p = rs.encode(m, output="parity"); p
Out: GF([15,  7,  6, 15,  9, 15], order=2^4)


Encode a single message using the shortened $$\textrm{RS}(11, 5)$$ code.

In : rs = galois.ReedSolomon(15, 9)

In : GF = rs.field

In : m = GF.Random(rs.k - 4); m
Out: GF([ 2,  9, 12,  8,  7], order=2^4)

In : c = rs.encode(m); c
Out: GF([ 2,  9, 12,  8,  7,  1,  8,  8, 11,  5,  6], order=2^4)


Compute the parity symbols only.

In : p = rs.encode(m, output="parity"); p
Out: GF([ 1,  8,  8, 11,  5,  6], order=2^4)


Encode a matrix of three messages using the $$\textrm{RS}(15, 9)$$ code.

In : rs = galois.ReedSolomon(15, 9)

In : GF = rs.field

In : m = GF.Random((3, rs.k)); m
Out:
GF([[15, 12,  9,  0, 13,  1,  0, 12, 13],
[15, 10,  8, 13,  7,  1,  1,  8, 12],
[ 6,  8,  5,  4, 11,  1,  7,  3, 10]], order=2^4)

In : c = rs.encode(m); c
Out:
GF([[15, 12,  9,  0, 13,  1,  0, 12, 13,  4, 11, 13,  9,  8,  4],
[15, 10,  8, 13,  7,  1,  1,  8, 12, 14,  7, 10, 13, 15,  7],
[ 6,  8,  5,  4, 11,  1,  7,  3, 10,  1, 11, 13, 10,  5, 13]],
order=2^4)


Compute the parity symbols only.

In : p = rs.encode(m, output="parity"); p
Out:
GF([[ 4, 11, 13,  9,  8,  4],
[14,  7, 10, 13, 15,  7],
[ 1, 11, 13, 10,  5, 13]], order=2^4)


Encode a matrix of three messages using the shortened $$\textrm{RS}(11, 5)$$ code.

In : rs = galois.ReedSolomon(15, 9)

In : GF = rs.field

In : m = GF.Random((3, rs.k - 4)); m
Out:
GF([[12,  5, 10,  6,  9],
[ 7,  3,  2,  2, 14],
[10, 11,  1, 14,  1]], order=2^4)

In : c = rs.encode(m); c
Out:
GF([[12,  5, 10,  6,  9, 12, 12,  9, 12,  9,  2],
[ 7,  3,  2,  2, 14,  3, 14, 12,  7, 13,  7],
[10, 11,  1, 14,  1, 12,  4,  9, 10, 14,  7]], order=2^4)


Compute the parity symbols only.

In : p = rs.encode(m, output="parity"); p
Out:
GF([[12, 12,  9, 12,  9,  2],
[ 3, 14, 12,  7, 13,  7],
[12,  4,  9, 10, 14,  7]], order=2^4)