Repository: sympy/sympy

Issue:
solveset(sin(pi*x), x) raises TypeError in _solve_trig2
```
In [1]: solveset(sin(pi*x), x)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/root/sympy/sympy/core/cache.py in wrapper(*args, **kwargs)
     95                 try:
---> 96                     retval = cfunc(*args, **kwargs)
     97                 except TypeError:

/root/sympy/sympy/core/numbers.py in __new__(cls, p, q, gcd)
   1631                 if not isinstance(p, Rational):
-> 1632                     raise TypeError('invalid input: %s' % p)
   1633

TypeError: invalid input: pi

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-1-c31c3e2926eb> in <module>()
----> 1 solveset(sin(pi*x), x)

/root/sympy/sympy/solvers/solveset.py in solveset(f, symbol, domain)
   2024     f = piecewise_fold(f)
   2025
-> 2026     return _solveset(f, symbol, domain, _check=True)
   2027
   2028
/root/sympy/sympy/solvers/solveset.py in _solveset(f, symbol, domain, _check)
    920     elif _is_function_class_equation(TrigonometricFunction, f, symbol) or \
    921             _is_function_class_equation(HyperbolicFunction, f, symbol):
--> 922         result = _solve_trig(f, symbol, domain)
    923     elif isinstance(f, arg):
    924         a = f.args[0]

/root/sympy/sympy/solvers/solveset.py in _solve_trig(f, symbol, domain)
    532     if sol1 is None or isinstance(sol1, ConditionSet):
    533         try:
--> 534             sol = _solve_trig2(f, symbol, domain)
    535         except ValueError:
    536             sol = sol1

/root/sympy/sympy/solvers/solveset.py in _solve_trig2(f, symbol, domain)
    607             continue
    608         c = poly_ar.all_coeffs()[0]   # got the coefficient of 'symbol'
--> 609         numerators.append(Rational(c).p)
    610         denominators.append(Rational(c).q)
    611

/root/sympy/sympy/core/cache.py in wrapper(*args, **kwargs)
     96                     retval = cfunc(*args, **kwargs)
     97                 except TypeError:
---> 98                     retval = func(*args, **kwargs)
     99                 return retval
    100

/root/sympy/sympy/core/numbers.py in __new__(cls, p, q, gcd)
   1630
   1631                 if not isinstance(p, Rational):
-> 1632                     raise TypeError('invalid input: %s' % p)
   1633
   1634             q = 1

TypeError: invalid input: pi
```
I think the above buggy behavior has been uncovered by #18202. So that PR is doing its job :-)

(The equation is the one of #11218.)

Discussion:

Patch:
diff --git a/sympy/matrices/eigen.py b/sympy/matrices/eigen.py
index 48b9317b60..359009f5d7 100644
--- a/sympy/matrices/eigen.py
+++ b/sympy/matrices/eigen.py
@@ -1,6 +1,5 @@
 from types import FunctionType
 from collections import Counter
-import itertools
 
 from mpmath import mp, workprec
 from mpmath.libmp.libmpf import prec_to_dps
@@ -700,7 +699,7 @@ def _is_positive_semidefinite(M):
     if nonnegative_diagonals and M.is_weakly_diagonally_dominant:
         return True
 
-    return _is_positive_semidefinite_by_minors(M)
+    return _is_positive_semidefinite_minors(M)
 
 
 def _is_negative_definite(M):
@@ -742,14 +741,16 @@ def _is_positive_definite_GE(M):
     return True
 
 
-def _is_positive_semidefinite_by_minors(M):
+def _is_positive_semidefinite_minors(M):
     """A method to evaluate all principal minors for testing
-    positive-semidefiniteness by using Sylvestre's crieterion."""
-    return all(
-        M[idx, idx].det(method='berkowitz').is_nonnegative
-        for minor_size in range(1, M.rows+1)
-        for idx in itertools.combinations(range(M.rows), minor_size)
-    )
+    positive-semidefiniteness."""
+    size = M.rows
+    for i in range(size):
+        minor = M[:i+1, :i+1].det(method='berkowitz')
+        is_nonnegative = minor.is_nonnegative
+        if is_nonnegative is not True:
+            return is_nonnegative
+    return True
 
 
 _doc_positive_definite = \
diff --git a/sympy/solvers/solveset.py b/sympy/solvers/solveset.py
index 9aa9079b76..efce7b7e66 100644
--- a/sympy/solvers/solveset.py
+++ b/sympy/solvers/solveset.py
@@ -661,19 +661,30 @@ def _solve_trig2(f, symbol, domain):
     denominators = []
     numerators = []
 
+    # todo: This solver can be extended to hyperbolics if the
+    # analogous change of variable to tanh (instead of tan)
+    # is used.
+    if not trig_functions:
+        return ConditionSet(symbol, Eq(f_original, 0), domain)
+
+    # todo: The pre-processing below (extraction of numerators, denominators,
+    # gcd, lcm, mu, etc.) should be updated to the enhanced version in
+    # _solve_trig1. (See #19507)
     for ar in trig_arguments:
         try:
             poly_ar = Poly(ar, symbol)
-
-        except ValueError:
+        except PolynomialError:
             raise ValueError("give up, we can't solve if this is not a polynomial in x")
         if poly_ar.degree() > 1:  # degree >1 still bad
             raise ValueError("degree of variable inside polynomial should not exceed one")
         if poly_ar.degree() == 0:  # degree 0, don't care
             continue
         c = poly_ar.all_coeffs()[0]   # got the coefficient of 'symbol'
-        numerators.append(Rational(c).p)
-        denominators.append(Rational(c).q)
+        try:
+            numerators.append(Rational(c).p)
+            denominators.append(Rational(c).q)
+        except TypeError:
+            return ConditionSet(symbol, Eq(f_original, 0), domain)
 
     x = Dummy('x')
 


Test patch:
diff --git a/sympy/matrices/tests/test_eigen.py b/sympy/matrices/tests/test_eigen.py
index 5feaa5a733..26d82163d9 100644
--- a/sympy/matrices/tests/test_eigen.py
+++ b/sympy/matrices/tests/test_eigen.py
@@ -572,12 +572,3 @@ def test_definite():
     assert m.is_positive_definite == True
     assert m.is_positive_semidefinite == True
     assert m.is_indefinite == False
-
-    # test for issue 19547: https://github.com/sympy/sympy/issues/19547
-    m = Matrix([
-        [0, 0, 0],
-        [0, 1, 2],
-        [0, 2, 1]
-    ])
-    assert not m.is_positive_definite
-    assert not m.is_positive_semidefinite
diff --git a/sympy/solvers/tests/test_solveset.py b/sympy/solvers/tests/test_solveset.py
index f44182e7c8..7c8c14c6a4 100644
--- a/sympy/solvers/tests/test_solveset.py
+++ b/sympy/solvers/tests/test_solveset.py
@@ -952,6 +952,12 @@ def test_solve_hyperbolic():
         ImageSet(Lambda(n, n*pi/4 - 13*pi/16 + E), S.Integers),
         ImageSet(Lambda(n, n*pi/4 - 11*pi/16 + E), S.Integers)))
 
+    # issues #18490 / #19489
+    assert solveset(cosh(x) + cosh(3*x) - cosh(5*x), x, S.Reals) == \
+        ConditionSet(x, Eq(cosh(x) + cosh(3*x) - cosh(5*x), 0), S.Reals)
+    assert solveset(sinh(8*x) + coth(12*x)) == ConditionSet(
+        x, Eq(sinh(8*x) + coth(12*x), 0), S.Complexes)
+
 
 def test_solve_trig_hyp_symbolic():
     # actual solver: _solve_trig1