nmod_mat – matrices over integers mod n¶
-
class
flint.
nmod_mat
¶ The nmod_poly type represents dense matrices over Z/nZ for word-size n. Some operations may assume that n is a prime.
-
det
(self)¶ Returns the determinant of self as an nmod.
>>> nmod_mat(2,2,[1,2,3,4],17).det() 15
-
entries
(self)¶
-
inv
(self)¶
-
modulus
(self) → mp_limb_t¶
-
ncols
(self) → long¶
-
nrows
(self) → long¶
-
nullspace
(self)¶ Computes a basis for the nullspace of self. Returns (X, nullity) where nullity is the rank of the nullspace of self and X is a matrix whose first (nullity) columns are linearly independent, and such that self * X = 0.
>>> A = nmod_mat(3,5,range(1,16),23) >>> X, nullity = A.nullspace() >>> A.rank(), nullity, X.rank() (2, 3, 3) >>> A * X [0, 0, 0, 0, 0] [0, 0, 0, 0, 0] [0, 0, 0, 0, 0] >>> X [ 1, 2, 3, 0, 0] [21, 20, 19, 0, 0] [ 1, 0, 0, 0, 0] [ 0, 1, 0, 0, 0] [ 0, 0, 1, 0, 0]
-
randtest
(type cls, ulong m, ulong n, ulong mod)¶ Returns a random (m, n) matrix with non-uniformly chosen entries. Zero entries are generated with increased probability.
-
rank
(self)¶
-
rref
(self, inplace=False)¶ Computes the reduced row echelon form (rref) of self, either returning a new copy or modifying self in-place. Returns (rref, rank).
>>> A = nmod_mat(3,3,range(9),23) >>> A.rref() ([1, 0, 22] [0, 1, 2] [0, 0, 0], 2) >>> A.rref(inplace=True) ([1, 0, 22] [0, 1, 2] [0, 0, 0], 2) >>> A [1, 0, 22] [0, 1, 2] [0, 0, 0]
-
solve
(self, other)¶ Given self = A and other = B, returns a matrix X such that A*X = B, assuming that self is square and invertible.
>>> A = nmod_mat(2, 2, [1,4,8,3], 11) >>> B = nmod_mat(2, 3, range(6), 11) >>> X = A.solve(B) >>> X [8, 5, 2] [9, 10, 0] >>> A*X == B True >>> nmod_mat(2, 2, [1,0,2,0], 11).solve(B) Traceback (most recent call last): ... ZeroDivisionError: singular matrix in solve() >>> A.solve(nmod_mat(1, 2, [2,3], 11)) Traceback (most recent call last): ... ValueError: need a square system and compatible right hand side
-
table
(self)¶
-
transpose
(self)¶ Returns the transpose of self.
>>> nmod_mat(2,3,range(6),7).transpose() [0, 3] [1, 4] [2, 5]
-