Repository: sympy/sympy

Issue:
solving inequality involving polynomial with imaginary coefficients fails
target new bahavior:

```
isolve = solve_univariate_inequality
eq = (x + I)*(x + 2*I) < 0
assert isolve(eq, x) == Eq(x, 0)  # this should not be False as in master
assert isolve(eq, x, relational=False) == FiniteSet(0)
x12 = (x - 1)*(x - 2)
assert isolve(eq.subs(x, x12), x) == Or(Eq(x, 1), Eq(x, 2))
```

Although the function is continuous for all reals, it doesn't produce reals except when the imaginary part vanishes. So there should be some additional processing to find the reals of interest for this corner case.

Discussion:

Patch:
diff --git a/sympy/solvers/inequalities.py b/sympy/solvers/inequalities.py
index 1c9172fa6d..3ae0160fb0 100644
--- a/sympy/solvers/inequalities.py
+++ b/sympy/solvers/inequalities.py
@@ -7,7 +7,7 @@
 from sympy.core.exprtools import factor_terms
 from sympy.core.relational import Relational, Eq, Ge, Lt, Ne
 from sympy.sets import Interval
-from sympy.sets.sets import FiniteSet, Union
+from sympy.sets.sets import FiniteSet, Union, EmptySet
 from sympy.sets.fancysets import ImageSet
 from sympy.core.singleton import S
 from sympy.core.function import expand_mul
@@ -440,10 +440,12 @@ def solve_univariate_inequality(expr, gen, relational=True, domain=S.Reals, cont
     Interval.open(0, pi)
 
     """
+    from sympy import im
     from sympy.calculus.util import (continuous_domain, periodicity,
         function_range)
     from sympy.solvers.solvers import denoms
-    from sympy.solvers.solveset import solveset_real, solvify
+    from sympy.solvers.solveset import solveset_real, solvify, solveset
+    from sympy.solvers.solvers import solve
 
     # This keeps the function independent of the assumptions about `gen`.
     # `solveset` makes sure this function is called only when the domain is
@@ -571,6 +573,49 @@ def valid(x):
             except NotImplementedError:
                 raise NotImplementedError('sorting of these roots is not supported')
 
+            #If expr contains imaginary coefficients
+            #Only real values of x for which the imaginary part is 0 are taken
+            make_real = S.Reals
+            if im(expanded_e) != S.Zero:
+                check = True
+                im_sol = FiniteSet()
+                try:
+                    a = solveset(im(expanded_e), gen, domain)
+                    if not isinstance(a, Interval):
+                        for z in a:
+                            if z not in singularities and valid(z) and z.is_real:
+                                im_sol += FiniteSet(z)
+                    else:
+                        start, end = a.inf, a.sup
+                        for z in _nsort(critical_points + FiniteSet(end)):
+                            valid_start = valid(start)
+                            if start != end:
+                                valid_z = valid(z)
+                                pt = _pt(start, z)
+                                if pt not in singularities and pt.is_real and valid(pt):
+                                    if valid_start and valid_z:
+                                        im_sol += Interval(start, z)
+                                    elif valid_start:
+                                        im_sol += Interval.Ropen(start, z)
+                                    elif valid_z:
+                                        im_sol += Interval.Lopen(start, z)
+                                    else:
+                                        im_sol += Interval.open(start, z)
+                            start = z
+                        for s in singularities:
+                            im_sol -= FiniteSet(s)
+                except (TypeError):
+                    im_sol = S.Reals
+                    check = False
+
+                if isinstance(im_sol, EmptySet):
+                    raise ValueError(filldedent('''
+%s contains imaginary parts which cannot be made 0 for any value of %s
+satisfying the inequality, leading to relations like I < 0.
+                '''  % (expr.subs(gen, _gen), _gen)))
+
+                make_real = make_real.intersect(im_sol)
+
             empty = sol_sets = [S.EmptySet]
 
             start = domain.inf
@@ -603,7 +648,10 @@ def valid(x):
             if valid(_pt(start, end)):
                 sol_sets.append(Interval.open(start, end))
 
-            rv = Union(*sol_sets).subs(gen, _gen)
+            if im(expanded_e) != S.Zero and check:
+                rv = (make_real)
+            else:
+                rv = (Union(*sol_sets)).intersect(make_real).subs(gen, _gen)
 
     return rv if not relational else rv.as_relational(_gen)
 
diff --git a/sympy/solvers/solveset.py b/sympy/solvers/solveset.py
index 0ab5d5539d..e4e7839eac 100644
--- a/sympy/solvers/solveset.py
+++ b/sympy/solvers/solveset.py
@@ -700,6 +700,9 @@ def _solveset(f, symbol, domain, _check=False):
     elif _is_function_class_equation(TrigonometricFunction, f, symbol) or \
             _is_function_class_equation(HyperbolicFunction, f, symbol):
         result = _solve_trig(f, symbol, domain)
+    elif isinstance(f, arg):
+        a = f.args[0]
+        result = solveset_real(a > 0, symbol)
     elif f.is_Piecewise:
         dom = domain
         result = EmptySet()


Test patch:
diff --git a/sympy/solvers/tests/test_inequalities.py b/sympy/solvers/tests/test_inequalities.py
index a24da98402..da57e9b0a5 100644
--- a/sympy/solvers/tests/test_inequalities.py
+++ b/sympy/solvers/tests/test_inequalities.py
@@ -275,6 +275,11 @@ def test_solve_univariate_inequality():
     # issue 2794:
     assert isolve(x**3 - x**2 + x - 1 > 0, x, relational=False) == \
         Interval(1, oo, True)
+    #issue 13105
+    assert isolve((x + I)*(x + 2*I) < 0, x) == Eq(x, 0)
+    assert isolve(((x - 1)*(x - 2) + I)*((x - 1)*(x - 2) + 2*I) < 0, x) == Or(Eq(x, 1), Eq(x, 2))
+    assert isolve((((x - 1)*(x - 2) + I)*((x - 1)*(x - 2) + 2*I))/(x - 2) > 0, x) == Eq(x, 1)
+    raises (ValueError, lambda: isolve((x**2 - 3*x*I + 2)/x < 0, x))
 
     # numerical testing in valid() is needed
     assert isolve(x**7 - x - 2 > 0, x) == \
diff --git a/sympy/solvers/tests/test_solveset.py b/sympy/solvers/tests/test_solveset.py
index 87f0a23ac6..4c84ceb0cb 100644
--- a/sympy/solvers/tests/test_solveset.py
+++ b/sympy/solvers/tests/test_solveset.py
@@ -1570,6 +1570,11 @@ def test_issue_12429():
     assert eq == sol
 
 
+def test_solveset_arg():
+    assert solveset(arg(x), x, S.Reals)  == Interval.open(0, oo)
+    assert solveset(arg(4*x -3), x) == Interval.open(3/4, oo)
+
+
 def test__is_finite_with_finite_vars():
     f = _is_finite_with_finite_vars
     # issue 12482