Repository: sympy/sympy

Issue:
Simplification gives wrong results
I am trying to simplify a simple equation:

```
import sympy

q, r = sympy.symbols("q r")
equation = (((-q + r) - (q - r)) <= 0).simplify()
print(equation) # q >= r

equation = ((sympy.sqrt(2) * (-q + r) - sympy.sqrt(2) * (q - r)) <= 0).simplify()
print(equation) # q <= r
```

As you can see from the comments, the results differ; but they should not, if I see that correctly. I am using Sympy version 1.5.1 and this happens on either Python 3.6.6 and 3.7.7. See also [this SO question](https://stackoverflow.com/questions/61965660/does-sympy-give-errorneous-simplifications). As was pointed out in the comments, this also happens for other coefficients other thant `sympy.sqrt(2)`.

Discussion:

Patch:
diff --git a/sympy/polys/polytools.py b/sympy/polys/polytools.py
index a0110db394..24347f3ae0 100644
--- a/sympy/polys/polytools.py
+++ b/sympy/polys/polytools.py
@@ -5219,7 +5219,8 @@ def try_non_polynomial_gcd(seq):
                 lc = 1
                 for frc in lst:
                     lc = lcm(lc, frc.as_numer_denom()[0])
-                return a/lc
+                # abs ensures that the gcd is always non-negative
+                return abs(a/lc)
 
     except PolificationFailed as exc:
         result = try_non_polynomial_gcd(exc.exprs)
@@ -5282,7 +5283,8 @@ def gcd(f, g=None, *gens, **args):
         if a.is_algebraic and a.is_irrational and b.is_algebraic and b.is_irrational:
             frc = (a/b).ratsimp()
             if frc.is_rational:
-                return a/frc.as_numer_denom()[0]
+                # abs ensures that the returned gcd is always non-negative
+                return abs(a/frc.as_numer_denom()[0])
 
     except PolificationFailed as exc:
         domain, (a, b) = construct_domain(exc.exprs)
diff --git a/sympy/solvers/solveset.py b/sympy/solvers/solveset.py
index efce7b7e66..9aa9079b76 100644
--- a/sympy/solvers/solveset.py
+++ b/sympy/solvers/solveset.py
@@ -661,30 +661,19 @@ 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 PolynomialError:
+
+        except ValueError:
             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'
-        try:
-            numerators.append(Rational(c).p)
-            denominators.append(Rational(c).q)
-        except TypeError:
-            return ConditionSet(symbol, Eq(f_original, 0), domain)
+        numerators.append(Rational(c).p)
+        denominators.append(Rational(c).q)
 
     x = Dummy('x')
 


Test patch:
diff --git a/sympy/core/tests/test_relational.py b/sympy/core/tests/test_relational.py
index 915af7fe4b..015c795344 100644
--- a/sympy/core/tests/test_relational.py
+++ b/sympy/core/tests/test_relational.py
@@ -705,6 +705,11 @@ def test_simplify_relational():
     assert simplify(x*(y + 1) - x*y - x + 1 < x) == (x > 1)
     assert simplify(x*(y + 1) - x*y - x - 1 < x) == (x > -1)
     assert simplify(x < x*(y + 1) - x*y - x + 1) == (x < 1)
+    q, r = symbols("q r")
+    assert (((-q + r) - (q - r)) <= 0).simplify() == (q >= r)
+    root2 = sqrt(2)
+    equation = ((root2 * (-q + r) - root2 * (q - r)) <= 0).simplify()
+    assert equation == (q >= r)
     r = S.One < x
     # canonical operations are not the same as simplification,
     # so if there is no simplification, canonicalization will
diff --git a/sympy/polys/tests/test_polytools.py b/sympy/polys/tests/test_polytools.py
index 0a159274c7..d6b94aa876 100644
--- a/sympy/polys/tests/test_polytools.py
+++ b/sympy/polys/tests/test_polytools.py
@@ -1900,6 +1900,9 @@ def test_gcd_list():
     gcd = gcd_list([], x, polys=True)
     assert gcd.is_Poly and gcd.is_zero
 
+    a = sqrt(2)
+    assert gcd_list([a, -a]) == gcd_list([-a, a]) == a
+
     raises(ComputationFailed, lambda: gcd_list([], polys=True))
 
 
@@ -1993,6 +1996,12 @@ def test_gcd():
     assert gcd(f, g, modulus=11, symmetric=False) == h
     assert lcm(f, g, modulus=11, symmetric=False) == l
 
+    a, b = sqrt(2), -sqrt(2)
+    assert gcd(a, b) == gcd(b, a) == a
+
+    a, b = sqrt(-2), -sqrt(-2)
+    assert gcd(a, b) == a
+
     raises(TypeError, lambda: gcd(x))
     raises(TypeError, lambda: lcm(x))
 
diff --git a/sympy/solvers/tests/test_solveset.py b/sympy/solvers/tests/test_solveset.py
index 7c8c14c6a4..f44182e7c8 100644
--- a/sympy/solvers/tests/test_solveset.py
+++ b/sympy/solvers/tests/test_solveset.py
@@ -952,12 +952,6 @@ 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