galois.generator_to_parity_check_matrix(G: FieldArray) FieldArray

Converts the generator matrix \(\mathbf{G}\) of a linear \([n, k]\) code into its parity-check matrix \(\mathbf{H}\).

The generator and parity-check matrices satisfy the equations \(\mathbf{G}\mathbf{H}^T = \mathbf{0}\).

Parameters
G: FieldArray

The \((k, n)\) generator matrix \(\mathbf{G}\) in systematic form \(\mathbf{G} = [\mathbf{I}_{k,k}\ |\ \mathbf{P}_{k,n-k}]\).

Returns

The \((n-k, n)\) parity-check matrix \(\mathbf{H} = [-\mathbf{P}_{k,n-k}^T\ |\ \mathbf{I}_{n-k,n-k}]\).

Examples

In [1]: g = galois.primitive_poly(2, 3); g
Out[1]: Poly(x^3 + x + 1, GF(2))

In [2]: G = galois.poly_to_generator_matrix(7, g); G
Out[2]: 
GF([[1, 0, 0, 0, 1, 0, 1],
    [0, 1, 0, 0, 1, 1, 1],
    [0, 0, 1, 0, 1, 1, 0],
    [0, 0, 0, 1, 0, 1, 1]], order=2)

In [3]: H = galois.generator_to_parity_check_matrix(G); H
Out[3]: 
GF([[1, 1, 1, 0, 1, 0, 0],
    [0, 1, 1, 1, 0, 1, 0],
    [1, 1, 0, 1, 0, 0, 1]], order=2)

In [4]: G @ H.T
Out[4]: 
GF([[0, 0, 0],
    [0, 0, 0],
    [0, 0, 0],
    [0, 0, 0]], order=2)