Repository: sympy/sympy

Issue:
improper inequality reduction
```python
>>> reduce_inequalities([x < oo, x >= 0, -oo < x])
And(-oo < x, x < oo)  <--- wrong
>>> And(*[x < oo, x >= 0, -oo < x]).as_set().as_relational(x)
And(0 <= x, x < oo)  <--- right
```

Discussion:

Patch:
diff --git a/sympy/integrals/risch.py b/sympy/integrals/risch.py
index ed75b61794..9b8fea56e4 100644
--- a/sympy/integrals/risch.py
+++ b/sympy/integrals/risch.py
@@ -25,7 +25,7 @@
 """
 from __future__ import print_function, division
 
-from sympy import real_roots, default_sort_key
+from sympy import real_roots
 from sympy.abc import z
 from sympy.core.function import Lambda
 from sympy.core.numbers import ilcm, oo
@@ -160,7 +160,7 @@ class DifferentialExtension(object):
     # to have a safeguard when debugging.
     __slots__ = ('f', 'x', 'T', 'D', 'fa', 'fd', 'Tfuncs', 'backsubs', 'E_K',
         'E_args', 'L_K', 'L_args', 'cases', 'case', 't', 'd', 'newf', 'level',
-        'ts',)
+        'ts')
 
     def __init__(self, f=None, x=None, handle_first='log', dummy=True, extension=None, rewrite_complex=False):
         """
@@ -247,6 +247,7 @@ def update(seq, atoms, func):
         symlogs = set()
 
         while True:
+            restart = False
             if self.newf.is_rational_function(*self.T):
                 break
 
@@ -326,12 +327,6 @@ def update(seq, atoms, func):
                         # ANSWER: Yes, otherwise we can't integrate x**x (or
                         # rather prove that it has no elementary integral)
                         # without first manually rewriting it as exp(x*log(x))
-                        self.newf = self.newf.xreplace({old: new})
-                        self.backsubs += [(new, old)]
-                        log_new_extension = self._log_part([log(i.base)],
-                            dummy=dummy)
-                        exps = update(exps, self.newf.atoms(exp), lambda i:
-                            i.exp.is_rational_function(*self.T) and i.exp.has(*self.T))
                         continue
                     ans, u, const = A
                     newterm = exp(i.exp*(log(const) + u))
@@ -382,7 +377,7 @@ def update(seq, atoms, func):
                 self.backsubs.append((new, i))
 
             # remove any duplicates
-            logs = sorted(set(logs), key=default_sort_key)
+            logs = list(set(logs))
 
             if handle_first == 'exp' or not log_new_extension:
                 exp_new_extension = self._exp_part(exps, dummy=dummy)
@@ -745,7 +740,7 @@ def as_poly_1t(p, t, z):
     Examples
     ========
 
-    >>> from sympy import random_poly
+    >>> from sympy import Symbol, random_poly
     >>> from sympy.integrals.risch import as_poly_1t
     >>> from sympy.abc import x, z
 
@@ -1652,11 +1647,11 @@ def risch_integrate(f, x, extension=None, handle_first='log',
     >>> pprint(risch_integrate(x*x**x*log(x) + x**x + x*x**x, x))
        x
     x*x
-    >>> pprint(risch_integrate(x**x, x))
+    >>> pprint(risch_integrate(x**x*log(x), x))
       /
      |
      |  x
-     | x  dx
+     | x *log(x) dx
      |
     /
 
diff --git a/sympy/solvers/inequalities.py b/sympy/solvers/inequalities.py
index 6baa44e38c..c73052a1a7 100644
--- a/sympy/solvers/inequalities.py
+++ b/sympy/solvers/inequalities.py
@@ -215,7 +215,7 @@ def reduce_rational_inequalities(exprs, gen, relational=True):
     """
     exact = True
     eqs = []
-    solution = S.EmptySet
+    solution = S.Reals if exprs else S.EmptySet
     for _exprs in exprs:
         _eqs = []
 
@@ -251,13 +251,15 @@ def reduce_rational_inequalities(exprs, gen, relational=True):
             if not (domain.is_ZZ or domain.is_QQ):
                 expr = numer/denom
                 expr = Relational(expr, 0, rel)
-                solution = Union(solution, solve_univariate_inequality(expr, gen, relational=False))
+                solution &= solve_univariate_inequality(expr, gen, relational=False)
             else:
                 _eqs.append(((numer, denom), rel))
 
-        eqs.append(_eqs)
+        if _eqs:
+            eqs.append(_eqs)
 
-    solution = Union(solution, solve_rational_inequalities(eqs))
+    if eqs:
+        solution &= solve_rational_inequalities(eqs)
 
     if not exact:
         solution = solution.evalf()


Test patch:
diff --git a/sympy/integrals/tests/test_risch.py b/sympy/integrals/tests/test_risch.py
index a0ad2fe2ae..3258230ec1 100644
--- a/sympy/integrals/tests/test_risch.py
+++ b/sympy/integrals/tests/test_risch.py
@@ -461,11 +461,9 @@ def test_DifferentialExtension_log():
 
 
 def test_DifferentialExtension_symlog():
-    # See comment on test_risch_integrate below
     assert DifferentialExtension(log(x**x), x, dummy=False)._important_attrs == \
-        (Poly(t0*x, t1), Poly(1, t1), [Poly(1, x), Poly(1/x, t0), Poly((t0 +
-            1)*t1, t1)], [x, t0, t1], [Lambda(i, log(i)), Lambda(i, exp(i*t0))],
-            [(exp(x*log(x)), x**x)], [2], [t0*x], [1], [x])
+        (Poly(x*t0, t0), Poly(1, t0), [Poly(1, x), Poly(1/x, t0)], [x, t0],
+        [Lambda(i, log(i))], [(x*log(x), log(x**x))], [], [], [1], [x])
     assert DifferentialExtension(log(x**y), x, dummy=False)._important_attrs == \
         (Poly(y*t0, t0), Poly(1, t0), [Poly(1, x), Poly(1/x, t0)], [x, t0],
         [Lambda(i, log(i))], [(y*log(x), log(x**y))], [], [], [1], [x])
@@ -646,14 +644,7 @@ def test_risch_integrate():
     # These are tested here in addition to in test_DifferentialExtension above
     # (symlogs) to test that backsubs works correctly.  The integrals should be
     # written in terms of the original logarithms in the integrands.
-
-    # XXX: Unfortunately, making backsubs work on this one is a little
-    # trickier, because x**x is converted to exp(x*log(x)), and so log(x**x)
-    # is converted to x*log(x). (x**2*log(x)).subs(x*log(x), log(x**x)) is
-    # smart enough, the issue is that these splits happen at different places
-    # in the algorithm.  Maybe a heuristic is in order
-    assert risch_integrate(log(x**x), x) == x**2*log(x)/2 - x**2/4
-
+    assert risch_integrate(log(x**x), x) == x*log(x**x)/2 - x**2/4
     assert risch_integrate(log(x**y), x) == x*log(x**y) - x*y
     assert risch_integrate(log(sqrt(x)), x) == x*log(sqrt(x)) - x/2
 
@@ -667,8 +658,3 @@ def test_NonElementaryIntegral():
     assert isinstance(risch_integrate(x**x*log(x), x), NonElementaryIntegral)
     # Make sure methods of Integral still give back a NonElementaryIntegral
     assert isinstance(NonElementaryIntegral(x**x*t0, x).subs(t0, log(x)), NonElementaryIntegral)
-
-def test_xtothex():
-    a = risch_integrate(x**x, x)
-    assert a == NonElementaryIntegral(x**x, x)
-    assert isinstance(a, NonElementaryIntegral)
diff --git a/sympy/solvers/tests/test_inequalities.py b/sympy/solvers/tests/test_inequalities.py
index ef606209a4..5ab366e2cd 100644
--- a/sympy/solvers/tests/test_inequalities.py
+++ b/sympy/solvers/tests/test_inequalities.py
@@ -168,6 +168,10 @@ def test_reduce_rational_inequalities_real_relational():
         relational=False) == \
         Union(Interval.Lopen(-oo, -2), Interval.Lopen(0, 4))
 
+    # issue sympy/sympy#10237
+    assert reduce_rational_inequalities(
+        [[x < oo, x >= 0, -oo < x]], x, relational=False) == Interval(0, oo)
+
 
 def test_reduce_abs_inequalities():
     e = abs(x - 5) < 3