galois.ReedSolomon.encode(message: ArrayLike, output: 'codeword' | 'parity' = 'codeword') FieldArray

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

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.

Parameters
message: ArrayLike

The message as either a \(k\)-length vector or \((N, k)\) matrix, where \(N\) is the number of messages. For systematic codes, message lengths less than \(k\) may be provided to produce shortened codewords.

output: 'codeword' | '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.

Notes

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 [1]: rs = galois.ReedSolomon(15, 9)

In [2]: GF = rs.field

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

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

Compute the parity symbols only.

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

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

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

In [7]: GF = rs.field

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

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

Compute the parity symbols only.

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

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

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

In [12]: GF = rs.field

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

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

Compute the parity symbols only.

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

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

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

In [17]: GF = rs.field

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

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

Compute the parity symbols only.

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