Repository: sympy/sympy

Issue:
solveset(oo*x - 1) -> {0}; should be {}
Substitution of 0 into the expression `oo*x - 1` gives `nan - 1` -> `nan`, so 0 should not be reported as a solution from `solveset` (and `nan` should not be reported as the solution from solve).

``` python
>>> solve(1-oo*x)
[nan]
>>> solveset(1-oo*x)
{0}
```


Discussion:
ArifAhmed1995: @smichr Can you review this PR ?
ArifAhmed1995: @smichr I've done the requested changes.
kshitij10496: Kindly squash your commits into a single commit if you can.

Patch:
diff --git a/sympy/solvers/solvers.py b/sympy/solvers/solvers.py
index f06ea35234..937955386f 100644
--- a/sympy/solvers/solvers.py
+++ b/sympy/solvers/solvers.py
@@ -1337,6 +1337,9 @@ def _solve(f, *symbols, **flags):
     if f.is_Mul:
         result = set()
         for m in f.args:
+            if m in set([S.NegativeInfinity, S.ComplexInfinity, S.Infinity]):
+                result = set()
+                break
             soln = _solve(m, symbol, **flags)
             result.update(set(soln))
         result = list(result)
@@ -1391,7 +1394,7 @@ def _solve(f, *symbols, **flags):
         # first see if it really depends on symbol and whether there
         # is only a linear solution
         f_num, sol = solve_linear(f, symbols=symbols)
-        if f_num is S.Zero:
+        if f_num is S.Zero or sol is S.NaN:
             return []
         elif f_num.is_Symbol:
             # no need to check but simplify if desired
diff --git a/sympy/solvers/solveset.py b/sympy/solvers/solveset.py
index 83d5ebbeb5..f41a769084 100644
--- a/sympy/solvers/solveset.py
+++ b/sympy/solvers/solveset.py
@@ -223,6 +223,8 @@ def _invert_complex(f, g_ys, symbol):
         g, h = f.as_independent(symbol)
 
         if g is not S.One:
+            if g in set([S.NegativeInfinity, S.ComplexInfinity, S.Infinity]):
+                return (h, S.EmptySet)
             return _invert_complex(h, imageset(Lambda(n, n/g), g_ys), symbol)
 
     if hasattr(f, 'inverse') and \
@@ -633,13 +635,19 @@ def _solveset(f, symbol, domain, _check=False):
     from sympy.simplify.simplify import signsimp
 
     orig_f = f
-    f = together(f)
+    tf = f = together(f)
     if f.is_Mul:
-        _, f = f.as_independent(symbol, as_Add=False)
+        coeff, f = f.as_independent(symbol, as_Add=False)
+        if coeff in set([S.ComplexInfinity, S.NegativeInfinity, S.Infinity]):
+            f = tf
     if f.is_Add:
         a, h = f.as_independent(symbol)
         m, h = h.as_independent(symbol, as_Add=False)
-        f = a/m + h  # XXX condition `m != 0` should be added to soln
+
+        if m not in set([S.ComplexInfinity, S.Zero, S.Infinity,
+                              S.NegativeInfinity]):
+            f = a/m + h  # XXX condition `m != 0` should be added to soln
+
     f = piecewise_fold(f)
 
     # assign the solvers to use


Test patch:
diff --git a/sympy/solvers/tests/test_solvers.py b/sympy/solvers/tests/test_solvers.py
index 63fb5d92c6..4390a11fba 100644
--- a/sympy/solvers/tests/test_solvers.py
+++ b/sympy/solvers/tests/test_solvers.py
@@ -1792,9 +1792,11 @@ def test_issue_2840_8155():
         0, -pi, pi, -2*I*log(-sqrt(3)/2 - I/2), -2*I*log(-sqrt(3)/2 + I/2),
         -2*I*log(sqrt(3)/2 - I/2), -2*I*log(sqrt(3)/2 + I/2)]
 
+
 def test_issue_9567():
     assert solve(1 + 1/(x - 1)) == [0]
 
+
 def test_issue_12114():
     a, b, c, d, e, f, g = symbols('a,b,c,d,e,f,g')
     terms = [1 + a*b + d*e, 1 + a*c + d*f, 1 + b*c + e*f,
@@ -1820,3 +1822,9 @@ def test_issue_12114():
                   b: -sqrt(3)*f/2 + sqrt(-f**2 + 2)/2, c: -sqrt(-f**2 + 2),
                   d: -f/2 + sqrt(-3*f**2 + 6)/2,
                   e: -f/2 - sqrt(3)*sqrt(-f**2 + 2)/2, g: 2}]
+
+
+def test_inf():
+    assert solve(1 - oo*x) == []
+    assert solve(oo*x, x) == []
+    assert solve(oo*x - oo, x) == []
diff --git a/sympy/solvers/tests/test_solveset.py b/sympy/solvers/tests/test_solveset.py
index 5844ef50b5..0ceeac15dd 100644
--- a/sympy/solvers/tests/test_solveset.py
+++ b/sympy/solvers/tests/test_solveset.py
@@ -496,6 +496,9 @@ def test_solveset_real_gen_is_pow():
 
 
 def test_no_sol():
+    assert solveset(1 - oo*x) == EmptySet()
+    assert solveset(oo*x, x) == EmptySet()
+    assert solveset(oo*x - oo, x) == EmptySet()
     assert solveset_real(4, x) == EmptySet()
     assert solveset_real(exp(x), x) == EmptySet()
     assert solveset_real(x**2 + 1, x) == EmptySet()