fmpz_mod_mat – matrices over integers mod n for arbitrary n

class flint.fmpz_mod_mat(*args)

The fmpz_mod_mat type represents dense matrices over Z/nZ for arbitrary n (not necessarily word-sized unlike nmod_mat). Some operations may assume that n is a prime.

charpoly(self)

Return the characteristic polynomial of a matrix.

>>> from flint import fmpz_mod_mat, fmpz_mod_ctx
>>> ctx = fmpz_mod_ctx(7)
>>> M = fmpz_mod_mat([[1, 2], [3, 4]], ctx)
>>> M.charpoly()
x^2 + 2*x + 5
det(self)

Return the determinant of a matrix.

>>> from flint import fmpz_mod_mat, fmpz_mod_ctx
>>> ctx = fmpz_mod_ctx(7)
>>> M = fmpz_mod_mat([[1, 2], [3, 4]], ctx)
>>> M.det()
fmpz_mod(5, 7)
entries(self)

Return a list of entries.

inv(self)

Return the inverse of a matrix.

>>> from flint import fmpz_mod_mat, fmpz_mod_ctx
>>> ctx = fmpz_mod_ctx(7)
>>> M = fmpz_mod_mat([[1, 2], [3, 4]], ctx)
>>> M.inv()
[5, 1]
[5, 3]

Assumes that the modulus is prime.

minpoly(self)

Return the minimal polynomial of a matrix.

>>> from flint import fmpz_mod_mat, fmpz_mod_ctx
>>> ctx = fmpz_mod_ctx(7)
>>> M = fmpz_mod_mat([[2, 1, 0], [0, 2, 0], [0, 0, 2]], ctx)
>>> M.charpoly()
x^3 + x^2 + 5*x + 6
>>> M.minpoly()
x^2 + 3*x + 4
modulus(self)

Return the modulus.

ncols(self) slong

Return the number of columns.

nrows(self) slong

Return the number of rows.

rank(self)

Return the rank of a matrix.

>>> from flint import fmpz_mod_mat, fmpz_mod_ctx
>>> ctx = fmpz_mod_ctx(11)
>>> M = fmpz_mod_mat([[1, 2, 3], [4, 5, 6], [7, 8, 9]], ctx)
>>> M.rank()
2

Assumes that the modulus is prime.

repr(self)

Return a representation string.

rref(self, inplace=False)

Return the reduced row echelon form of a matrix and the rank.

>>> from flint import fmpz_mod_mat, fmpz_mod_ctx
>>> ctx = fmpz_mod_ctx(7)
>>> M = fmpz_mod_mat([[1, 2, 3], [4, 5, 6]], ctx)
>>> Mr, r = M.rref()
>>> Mr
[1, 0, 6]
[0, 1, 2]
>>> r
2

If inplace is True, the matrix is modified in place.

Assumes that the modulus is prime.

solve(self, rhs)

Solve a linear system.

>>> from flint import fmpz_mod_mat, fmpz_mod_ctx
>>> ctx = fmpz_mod_ctx(7)
>>> M = fmpz_mod_mat([[1, 2], [3, 4]], ctx)
>>> rhs = fmpz_mod_mat([[5], [6]], ctx)
>>> M.solve(rhs)
[3]
[1]

The matrix must be square and invertible.

Assumes that the modulus is prime.

str(self, *args, **kwargs)
table(self)
tolist()

flint_mat.table(self)

transpose(self)

Return the transpose of a matrix.

>>> from flint import fmpz_mod_mat, fmpz_mod_ctx
>>> ctx = fmpz_mod_ctx(7)
>>> M = fmpz_mod_mat([[1, 2], [3, 4]], ctx)
>>> M
[1, 2]
[3, 4]
>>> M.transpose()
[1, 3]
[2, 4]