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([14,  4,  2,  5,  7,  6,  4, 11,  2], order=2^4)

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


Compute the parity symbols only.

In : p = rs.encode(m, output="parity"); p
Out: GF([ 4,  1,  8,  2, 15,  3], 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([ 5, 13, 15,  0, 14], order=2^4)

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


Compute the parity symbols only.

In : p = rs.encode(m, output="parity"); p
Out: GF([ 2,  6,  4, 14,  2,  8], 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([[ 2,  8, 12, 13, 14, 14,  9,  4, 11],
[10,  8, 14, 11,  8,  0,  1,  5,  2],
[ 4,  9, 13, 14,  4, 14, 14,  4, 12]], order=2^4)

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


Compute the parity symbols only.

In : p = rs.encode(m, output="parity"); p
Out:
GF([[ 1,  6, 11,  1,  0,  8],
[14,  6,  3,  7,  6,  8],
[12,  6,  1, 11,  6,  4]], 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([[ 7, 15,  5,  1,  5],
[15, 10,  4, 10, 11],
[11,  2, 14,  5, 13]], order=2^4)

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


Compute the parity symbols only.

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