Repository: sympy/sympy

Issue:
Is the empty matrix nilpotent? IndexError: Index out of range: a[0]

Discussion:

Patch:
diff --git a/.mailmap b/.mailmap
index a2c68ddad7..80364fc40b 100644
--- a/.mailmap
+++ b/.mailmap
@@ -239,7 +239,3 @@ Harshil Goel <harshil158@gmail.com> harshil goel <harshil158@gmail.com>
 Lukas Zorich <lukas.zorich@gmail.com> lukas <lukas.zorich@gmail.com>
 Shashank Agarwal <shashank.agarwal94@gmail.com> shashank-agg <shashank.agarwal94@gmail.com>
 Rajath Shashidhara <rajaths.rajaths@gmail.com> rajaths589 <rajaths.rajaths@gmail.com>
-Chaitanya Sai Alaparthi <achaitanyasai@gmail.com> chaitanya sai alaparthi <achaitanyasai@gmail.com>
-Abhinav Agarwal <abhinavagarwal1996@gmail.com> abhinavagarwal07 <abhinavagarwal1996@gmail.com>
-Rishabh Daal <rishabhdaal@gmail.com> rd13123013 <rishabhdaal@gmail.com>
-Aravind Reddy <aravindreddy255@gmail.com> Aravind <aravindreddy255@gmail.com>
diff --git a/AUTHORS b/AUTHORS
index 3187f72b00..4f3b21ed51 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -481,16 +481,3 @@ Michał Radwański <enedil.isildur@gmail.com>
 Jerry Li <jerry@jerryli.ca>
 Pablo Zubieta <pabloferz@yahoo.com.mx>
 Curious72 <knowthyself2503@gmail.com>
-Chaitanya Sai Alaparthi <achaitanyasai@gmail.com>
-Ruslan Pisarev <rpisarev@cloudlinux.com>
-Akash Trehan <akash.trehan123@gmail.com>
-Nishant Nikhil <nishantiam@gmail.com>
-Vladimir Poluhsin <vovapolu@gmail.com>
-Akshay Nagar <awesomeay13@yahoo.com>
-James Brandon Milam <jmilam343@gmail.com>
-Abhinav Agarwal <abhinavagarwal1996@gmail.com>
-Rishabh Daal <rishabhdaal@gmail.com>
-Sanya Khurana <sanya@monica.in>
-Aman Deep <amandeep1024@gmail.com>
-Aravind Reddy <aravindreddy255@gmail.com>
-Abhishek Verma <iamvermaabhishek@gmail.com>
diff --git a/sympy/matrices/matrices.py b/sympy/matrices/matrices.py
index 95e44ee1fc..8fd39afdee 100644
--- a/sympy/matrices/matrices.py
+++ b/sympy/matrices/matrices.py
@@ -2080,6 +2080,8 @@ def is_nilpotent(self):
         >>> a.is_nilpotent()
         False
         """
+        if not self:
+            return True
         if not self.is_square:
             raise NonSquareMatrixError(
                 "Nilpotency is valid only for square matrices")


Test patch:
diff --git a/sympy/matrices/tests/test_matrices.py b/sympy/matrices/tests/test_matrices.py
index cfd18eeb8a..94d92b117f 100644
--- a/sympy/matrices/tests/test_matrices.py
+++ b/sympy/matrices/tests/test_matrices.py
@@ -1189,6 +1189,8 @@ def test_is_nilpotent():
     assert a.is_nilpotent()
     a = Matrix([[1, 0], [0, 1]])
     assert not a.is_nilpotent()
+    a = Matrix([])
+    assert a.is_nilpotent()
 
 
 def test_zeros_ones_fill():