Skip to content

Commit

Permalink
Implementing an is_nilpotent() check for matrices.
Browse files Browse the repository at this point in the history
  • Loading branch information
tscrim committed Mar 31, 2024
1 parent b693ea9 commit 8ace5c7
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/sage/matrix/matrix2.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -9898,6 +9898,44 @@ cdef class Matrix(Matrix1):
self.cache(key, normal)
return normal

def is_nilpotent(self) -> bool:
r"""
Return if ``self`` is a nilpotent matrix.

A matrix `A` is *nilpotent* if there exists a positive integer
`k` such that `A^k = 0`. We test this by using the Cayley-Hamilton
theorem to see if the characteristic polynomial is `x^n = 0`.

EXAMPLES::

sage: A = matrix([[0,2,1,6], [0,0,1,2], [0,0,0,3], [0,0,0,0]])
sage: A.is_nilpotent()
True
sage: B = matrix([[2,2,2,2,-4], [7,1,1,1,-5], [1,7,1,1,-5],
....: [1,1,7,1,-5], [1,1,1,7,-5]])
sage: B.is_nilpotent()
True
sage: C = matrix(GF(7), [[1, 2], [2, 4]])
sage: C.is_nilpotent()
False
sage: Z = matrix.zero(QQ, 5)
sage: Z.is_nilpotent()
True

TESTS:

Check the corner case of the `0 \times 0` matrix::

sage: Z = matrix.zero(QQ, 0); Z
[]
sage: Z.charpoly()
1
sage: Z.is_nilpotent()
True
"""
chi = self.charpoly()
return chi.is_monomial()

def as_sum_of_permutations(self):
r"""
Returns the current matrix as a sum of permutation matrices
Expand Down

0 comments on commit 8ace5c7

Please sign in to comment.