Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions src/sage/matrix/matrix2.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -9898,6 +9898,49 @@ 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`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't that be x^k = 0?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, it might be more precise to say:

We test this by checking whether the characteristic polynomial is a monomial, `x^n`.
The Cayley-Hamilton theorem asserts that then the minimal `k` such that `A^k = 0` equals `n`.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wot ? the minimal k can be anything between 1 and n...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

upsi, sorry, in delirium I confused minimal and characteristic polynomial. now going back to sleep.


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, 6]])
sage: C.is_nilpotent()
False
sage: D = matrix([[1,0],[0,0]])
sage: D.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
"""
if self.trace():
return False
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
4 changes: 1 addition & 3 deletions src/sage/structure/element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2845,9 +2845,7 @@ cdef class RingElement(ModuleElement):
True
sage: m = matrix(QQ, 3, [[3,2,3], [9,0,3], [-9,0,-3]]) # needs sage.modules
sage: m.is_nilpotent() # needs sage.modules
Traceback (most recent call last):
...
AttributeError: '...' object has no attribute 'is_nilpotent'...
True
"""
if self.is_unit():
return False
Expand Down