galois.ReedSolomon.detect(codeword: ArrayLike) bool_ | ndarray

Detects if errors are present in the Reed-Solomon codeword \(\mathbf{c}\).

The \([n, k, d]_q\) Reed-Solomon code has \(d_{min} = d\) minimum distance. It can detect up to \(d_{min}-1\) errors.

Parameters
codeword: ArrayLike

The codeword as either a \(n\)-length vector or \((N, n)\) matrix, where \(N\) is the number of codewords. For systematic codes, codeword lengths less than \(n\) may be provided for shortened codewords.

Returns

A boolean scalar or array indicating if errors were detected in the corresponding codeword True or not False.

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([ 8,  0,  0,  0,  6, 12,  8, 13,  6], order=2^4)

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

Detect no errors in the valid codeword.

In [5]: rs.detect(c)
Out[5]: False

Detect \(d_{min}-1\) errors in the codeword.

In [6]: rs.d
Out[6]: 7

In [7]: e = GF.Random(rs.d - 1, low=1); e
Out[7]: GF([10, 11,  9,  6, 10, 14], order=2^4)

In [8]: c[0:rs.d - 1] += e; c
Out[8]: GF([ 2, 11,  9,  6, 12,  2,  8, 13,  6,  9,  4,  2, 13,  3,  9], order=2^4)

In [9]: rs.detect(c)
Out[9]: True

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

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

In [11]: GF = rs.field

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

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

Detect no errors in the valid codeword.

In [14]: rs.detect(c)
Out[14]: False

Detect \(d_{min}-1\) errors in the codeword.

In [15]: rs.d
Out[15]: 7

In [16]: e = GF.Random(rs.d - 1, low=1); e
Out[16]: GF([ 6,  2, 12, 11,  6,  1], order=2^4)

In [17]: c[0:rs.d - 1] += e; c
Out[17]: GF([ 8,  5,  7, 10,  1,  4,  8, 15,  4, 10,  4], order=2^4)

In [18]: rs.detect(c)
Out[18]: True

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

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

In [20]: GF = rs.field

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

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

Detect no errors in the valid codewords.

In [23]: rs.detect(c)
Out[23]: array([False, False, False])

Detect one, two, and \(d_{min}-1\) errors in the codewords.

In [24]: rs.d
Out[24]: 7

In [25]: c[0,0:1] += GF.Random(1, low=1)

In [26]: c[1,0:2] += GF.Random(2, low=1)

In [27]: c[2, 0:rs.d - 1] += GF.Random(rs.d - 1, low=1)

In [28]: c
Out[28]: 
GF([[14,  8,  0, 11,  6,  9,  7,  5,  7,  4,  2,  6,  0,  2,  2],
    [ 7,  2, 11, 14, 13, 15,  2,  6,  2,  5,  4,  5, 15, 15, 11],
    [ 3,  9,  2,  6,  4, 12,  9, 15,  6,  2,  6,  7,  2, 15, 13]],
   order=2^4)

In [29]: rs.detect(c)
Out[29]: array([ True,  True,  True])

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

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

In [31]: GF = rs.field

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

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

Detect no errors in the valid codewords.

In [34]: rs.detect(c)
Out[34]: array([False, False, False])

Detect one, two, and \(d_{min}-1\) errors in the codewords.

In [35]: rs.d
Out[35]: 7

In [36]: c[0,0:1] += GF.Random(1, low=1)

In [37]: c[1,0:2] += GF.Random(2, low=1)

In [38]: c[2, 0:rs.d - 1] += GF.Random(rs.d - 1, low=1)

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

In [40]: rs.detect(c)
Out[40]: array([ True,  True,  True])

Last update: Aug 27, 2022