galois.FieldArray.row_reduce(ncols: int | None = None, eye: 'left' | 'right' = 'left') Self

Performs Gaussian elimination on the matrix to achieve reduced row echelon form (RREF).

Parameters:
ncols: int | None = None

The number of columns to perform Gaussian elimination over. The default is None which represents the number of columns of the matrix.

eye: 'left' | 'right' = 'left'

The location of the identity matrix \(\mathbf{I}\), either on the left or the right.

Returns:

The reduced row echelon form of the input matrix.

Notes

The elementary row operations in Gaussian elimination are:

  1. Swap the position of any two rows.

  2. Multiply any row by a non-zero scalar.

  3. Add any row to a scalar multiple of another row.

Examples

Perform Gaussian elimination to get the reduced row echelon form of \(\mathbf{A}\).

In [1]: GF = galois.GF(31)

In [2]: A = GF([[16, 12, 1, 25], [1, 10, 27, 29], [1, 0, 3, 19]]); A
Out[2]: 
GF([[16, 12,  1, 25],
    [ 1, 10, 27, 29],
    [ 1,  0,  3, 19]], order=31)

In [3]: A.row_reduce()
Out[3]: 
GF([[ 1,  0,  0, 11],
    [ 0,  1,  0,  7],
    [ 0,  0,  1, 13]], order=31)

In [4]: np.linalg.matrix_rank(A)
Out[4]: 3

Perform Gaussian elimination to get an \(\mathbf{I}\) on the right side of \(\mathbf{A}\).

In [5]: A.row_reduce(eye="right")
Out[5]: 
GF([[ 5,  1,  0,  0],
    [27,  0,  1,  0],
    [17,  0,  0,  1]], order=31)

Or only perform Gaussian elimination over 2 columns.

In [6]: A.row_reduce(ncols=2)
Out[6]: 
GF([[ 1,  0,  5, 14],
    [ 0,  1, 27, 17],
    [ 0,  0, 29,  5]], order=31)