Repository: sympy/sympy

Issue:
is_positive_semidefinite() gives wrong result on sympy==1.7.1
The code
```python
from sympy import Matrix, Symbol
b = Symbol('b', nonzero=True)
m = Matrix([[0, 0, 0], [0, b, 0], [0, 0, b]])
m.is_positive_semidefinite
```
gives wrong result `True`. Since `b` could be either positive or negative, the positive semidefinite-ness is inconclusive and should return `None`. The reason comes from the following line.
https://github.com/sympy/sympy/blob/347542065a39bef13d6fb9500dce631f2cf72f55/sympy/matrices/eigen.py#L825-L826
The test rejects only provably negative pivots and fails to consider _potentially_ negative pivots. It seems that adding strict nonnegativity tests like
```python
elif not (M[k, k].is_nonnegative and pivot_val.is_nonnegative):
    return None
```
will resolve this issue, but as I'm not 100% familiar with the implementation the details could be wrong.

Discussion:

Patch:
diff --git a/sympy/matrices/eigen.py b/sympy/matrices/eigen.py
index cd3be21346..72b5853480 100644
--- a/sympy/matrices/eigen.py
+++ b/sympy/matrices/eigen.py
@@ -844,6 +844,8 @@ def _is_positive_semidefinite_cholesky(M):
 
         if M[k, k].is_negative or pivot_val.is_negative:
             return False
+        elif not (M[k, k].is_nonnegative and pivot_val.is_nonnegative):
+            return None
 
         if pivot > 0:
             M.col_swap(k, k+pivot)


Test patch:
diff --git a/sympy/matrices/tests/test_eigen.py b/sympy/matrices/tests/test_eigen.py
index b2a89e416c..6572a16a8a 100644
--- a/sympy/matrices/tests/test_eigen.py
+++ b/sympy/matrices/tests/test_eigen.py
@@ -681,3 +681,9 @@ def test_issue_20275():
         [Matrix([[S(1)/2 + sqrt(5)/2], [0], [1], [1], [0]]),
          Matrix([[S(1)/2 + sqrt(5)/2], [1], [0], [0], [1]])]
     )
+
+
+def test_issue_20752():
+    b = symbols('b', nonzero=True)
+    m = Matrix([[0, 0, 0], [0, b, 0], [0, 0, b]])
+    assert m.is_positive_semidefinite is None