Repository: sympy/sympy

Issue:
invert_real returns non-real value for exp(x)
``` python
>>> from sympy import *; from sympy.abc import x
>>> from sympy.solvers.solveset import invert_real
>>> invert_real(exp(x),0,x)
(x, {zoo})
```

Probably empty set should be returned?

solve generates a NaN comparison error
```python
>>> solve(Abs(x-4)-(x-1)/(x+2)-(x-3)/(x+1))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sympy\solvers\solvers.py", line 1194, in solve
    solution.sort(key=default_sort_key)
  File "sympy\core\numbers.py", line 1807, in __lt__
    return Rational.__lt__(self, other)
  File "sympy\core\numbers.py", line 1485, in __lt__
    return Expr.__lt__(expr, other)
  File "sympy\core\expr.py", line 301, in __lt__
    raise TypeError("Invalid NaN comparison")
TypeError: Invalid NaN comparison
```

It looks like the problem is that it is trying to sort the solution which contains a nan. One can see the solutions it is working with by requesting a set:

```
>>> print filldedent(solve(Abs(x-4)-(x-1)/(x+2)-(x-3)/(x+1), set=True))

([x], set([(1 + sqrt(6),), (Piecewise((2**(2/3)*(-4 + (1 +
sqrt(3)*I)*(2 + (-1 - sqrt(3)*I)*(6 + 2*sqrt(7)*I)**(1/3))*(6 +
2*sqrt(7)*I)**(1/3)/4)/((1 + sqrt(3)*I)*(3 + sqrt(7)*I)**(1/3)),
2**(2/3)*(4 + (1 + sqrt(3)*I)*(6 + 2*sqrt(7)*I)**(1/3)*(6 + (1 +
sqrt(3)*I)*(6 + 2*sqrt(7)*I)**(1/3))/4)/((1 + sqrt(3)*I)*(3 +
sqrt(7)*I)**(1/3)) <= 0), (nan, True)),), (-sqrt(6) + 1,), (nan,),
(-3,), (Piecewise((1 + 2*2**(2/3)/(3 + sqrt(7)*I)**(1/3) + 2**(1/3)*(3
+ sqrt(7)*I)**(1/3), -3 + 2*2**(2/3)/(3 + sqrt(7)*I)**(1/3) +
2**(1/3)*(3 + sqrt(7)*I)**(1/3) >= 0), (nan, True)),)]))
```

It's interesting to see that a Piecewise is present because it couldn't decide the sign of an expression.


BTW, the actual solutions (confirmed visually) are:

```
>>> nsolve(eq,-3)
mpf('-3.0')
>>> nsolve(eq,-1.5)
mpf('-1.4494897427831781')
>>> nsolve(eq,3.2)
mpf('3.4494897427831781')
>>> nsolve(eq,5)
mpf('4.8844837019393323')
```

Discussion:
sympy-bot: :white_check_mark:

Hi, I am the [SymPy bot](https://github.com/sympy/sympy-bot) (v161). I'm here to help you write a release notes entry. Please read the [guide on how to write release notes](https://github.com/sympy/sympy/wiki/Writing-Release-Notes).



* No release notes entry will be added for this pull request.

<details><summary>Click here to see the pull request description that was parsed.</summary>

    <!-- Your title above should be a short description of what
    was changed. Do not include the issue number in the title. -->

    #### References to other Issues or PRs
    <!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
    format, e.g. "Fixes #1234" (see
    https://tinyurl.com/auto-closing for more information). Also, please
    write a comment on that issue linking back to this pull request once it is
    open. -->

    Closes #10086
    Closes #10876 
    Closes #12032 
    Closes #13396 
    Closes #13961 
    Closes #14541 
    Closes #14642

    #### Brief description of what is fixed or changed
    Will update which issues are actually close and which are just tested.

    No idea how to sort out the failing tests:
    * test_issue_13961: the solver produces two identical results and when trying to create an identical expression they are simplified to just a single one. Why doesn't this happen in the solver? Or can I make it not happen here?
    * test_issue_14541: forgot how to compare to floats in a sensible way... (will also uncomment the corresponding rows in test_issue_14642)
    * test_issue_13396: No idea how to write the solution so that it is identical. Tried several different approaches...

    #### Other comments
    Seems like the random position I inserted the tests in was the same as the previous batch... Will rebase as well once the tests are sorted out...

    #### Release Notes

    <!-- Write the release notes for this release below between the BEGIN and END
    statements. The basic format is a bulleted list with the name of the subpackage
    and the release note for this PR. For example:

    * solvers
      * Added a new solver for logarithmic equations.

    * functions
      * Fixed a bug with log of integers.

    or if no release note(s) should be included use:

    NO ENTRY

    See https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more
    information on how to write release notes. The bot will check your release
    notes automatically to see if they are formatted correctly. -->

    <!-- BEGIN RELEASE NOTES -->
    NO ENTRY

    <!-- END RELEASE NOTES -->


</details><p>

oscargus: I've updated the tests and original comment so that the status is correct.
oscargus: I added the `evalute=False` in the test with a comment about that they should ideally not be required.

Didn't want to change the core mul-code... 
oscargus: I have fixed the `zoo` problems in a slightly more general way than discussed in #22019.

Also fixed solving `arg` in a way that at least is correct, but may not always return "minimal" solutions. For example, `solveset(arg(x) , x)` returns

`Intersection(ConditionSet(x, Eq(im(x), 0), Complexes), ConditionSet(x, re(x) > 0, Complexes))`

where the first ConditionSet is identical to x being real.

On the other hand, `solveset(arg(x-I) , x)` now do not throw and error, but returns

`Intersection(ConditionSet(x, Eq(im(x) - 1, 0), Complexes), ConditionSet(x, re(x) > 0, Complexes))`


Patch:
diff --git a/sympy/solvers/solveset.py b/sympy/solvers/solveset.py
index 50af65d971..c3cb644149 100644
--- a/sympy/solvers/solveset.py
+++ b/sympy/solvers/solveset.py
@@ -295,16 +295,16 @@ def _invert_real(f, g_ys, symbol):
     if isinstance(f, TrigonometricFunction):
         if isinstance(g_ys, FiniteSet):
             def inv(trig):
-                if isinstance(f, (sin, csc)):
-                    F = asin if isinstance(f, sin) else acsc
+                if isinstance(trig, (sin, csc)):
+                    F = asin if isinstance(trig, sin) else acsc
                     return (lambda a: n*pi + (-1)**n*F(a),)
-                if isinstance(f, (cos, sec)):
-                    F = acos if isinstance(f, cos) else asec
+                if isinstance(trig, (cos, sec)):
+                    F = acos if isinstance(trig, cos) else asec
                     return (
                         lambda a: 2*n*pi + F(a),
                         lambda a: 2*n*pi - F(a),)
-                if isinstance(f, (tan, cot)):
-                    return (lambda a: n*pi + f.inverse()(a),)
+                if isinstance(trig, (tan, cot)):
+                    return (lambda a: n*pi + trig.inverse()(a),)
 
             n = Dummy('n', integer=True)
             invs = S.EmptySet
@@ -708,7 +708,7 @@ def _solve_trig1(f, symbol, domain):
 def _solve_trig2(f, symbol, domain):
     """Secondary helper to solve trigonometric equations,
     called when first helper fails """
-    from sympy import ilcm, expand_trig, degree
+    from sympy import ilcm, expand_trig
     f = trigsimp(f)
     f_original = f
     trig_functions = f.atoms(sin, cos, tan, sec, cot, csc)
@@ -862,7 +862,7 @@ def _solve_radical(f, unradf, symbol, solveset_solver):
         result = Union(*[imageset(Lambda(y, g_y), f_y_sols)
                          for g_y in g_y_s])
 
-    if isinstance(result, Complement) or isinstance(result,ConditionSet):
+    if isinstance(result, (Complement, ConditionSet)):
         solution_set = result
     else:
         f_set = []  # solutions for FiniteSet
@@ -1025,8 +1025,10 @@ def _solveset(f, symbol, domain, _check=False):
             _is_function_class_equation(HyperbolicFunction, f, symbol):
         result = _solve_trig(f, symbol, domain)
     elif isinstance(f, arg):
+        from sympy.functions.elementary.complexes import re, im
         a = f.args[0]
-        result = solveset_real(a > 0, symbol)
+        result = Intersection(_solveset(re(a) > 0, symbol, domain),
+                              _solveset(im(a), symbol, domain))
     elif f.is_Piecewise:
         expr_set_pairs = f.as_expr_set_pairs(domain)
         for (expr, in_set) in expr_set_pairs:
@@ -1116,7 +1118,16 @@ def _solveset(f, symbol, domain, _check=False):
         if isinstance(result, ConditionSet):
             # it wasn't solved or has enumerated all conditions
             # -- leave it alone
-            return result
+            if domain is S.Complexes:
+                return result
+            # Add domain
+            new_res = Intersection(result, domain)
+            # Check if the domain is really contributing
+            if new_res.is_subset(result):
+                return new_res
+            else:
+                return result
+
 
         # whittle away all but the symbol-containing core
         # to use this for testing
@@ -2936,9 +2947,6 @@ def substitution(system, symbols, result=[{}], known_symbols=[],
 
     """
 
-    from sympy import Complement
-    from sympy.core.compatibility import is_sequence
-
     if not system:
         return S.EmptySet
 


Test patch:
diff --git a/sympy/solvers/tests/test_solveset.py b/sympy/solvers/tests/test_solveset.py
index facc1e339c..fbbc6cddae 100644
--- a/sympy/solvers/tests/test_solveset.py
+++ b/sympy/solvers/tests/test_solveset.py
@@ -3,8 +3,7 @@
 from sympy.core.function import (Function, Lambda, nfloat, diff)
 from sympy.core.mod import Mod
 from sympy.core.numbers import (E, I, Rational, oo, pi, Integer)
-from sympy.core.relational import (Eq, Gt,
-    Ne, Ge)
+from sympy.core.relational import (Eq, Gt, Ne, Ge)
 from sympy.core.singleton import S
 from sympy.core.symbol import (Dummy, Symbol, symbols)
 from sympy.functions.elementary.complexes import (Abs, arg, im, re, sign)
@@ -185,7 +184,6 @@ def test_issue_11536():
 
 
 def test_issue_17479():
-    from sympy.solvers.solveset import nonlinsolve
     f = (x**2 + y**2)**2 + (x**2 + z**2)**2 - 2*(2*x**2 + y**2 + z**2)
     fx = f.diff(x)
     fy = f.diff(y)
@@ -222,14 +220,14 @@ def test_issue_18449():
 
 def test_issue_21047():
     f = (2 - x)**2 + (sqrt(x - 1) - 1)**6
-    assert(solveset(f, x, S.Reals)) == FiniteSet(2)
+    assert solveset(f, x, S.Reals) == FiniteSet(2)
+
     f = (sqrt(x)-1)**2 + (sqrt(x)+1)**2 -2*x**2 + sqrt(2)
     assert solveset(f, x, S.Reals) == FiniteSet(
         S.Half - sqrt(2*sqrt(2) + 5)/2, S.Half + sqrt(2*sqrt(2) + 5)/2)
 
 
 def test_is_function_class_equation():
-    from sympy.abc import x, a
     assert _is_function_class_equation(TrigonometricFunction,
                                        tan(x), x) is True
     assert _is_function_class_equation(TrigonometricFunction,
@@ -347,8 +345,6 @@ def test_solve_polynomial():
     assert solveset_real(x**2 - 1, x) == FiniteSet(-S.One, S.One)
     assert solveset_real(x - y**3, x) == FiniteSet(y ** 3)
 
-    a11, a12, a21, a22, b1, b2 = symbols('a11, a12, a21, a22, b1, b2')
-
     assert solveset_real(x**3 - 15*x - 4, x) == FiniteSet(
         -2 + 3 ** S.Half,
         S(4),
@@ -764,7 +760,6 @@ def test_solve_quintics():
 
 
 def test_solveset_complex_exp():
-    from sympy.abc import x, n
     assert dumeq(solveset_complex(exp(x) - 1, x),
         imageset(Lambda(n, I*2*n*pi), S.Integers))
     assert dumeq(solveset_complex(exp(x) - I, x),
@@ -775,7 +770,6 @@ def test_solveset_complex_exp():
 
 
 def test_solveset_real_exp():
-    from sympy.abc import x, y
     assert solveset(Eq((-2)**x, 4), x, S.Reals) == FiniteSet(2)
     assert solveset(Eq(-2**x, 4), x, S.Reals) == S.EmptySet
     assert solveset(Eq((-3)**x, 27), x, S.Reals) == S.EmptySet
@@ -810,7 +804,6 @@ def test_solveset_complex_tan():
 
 @_both_exp_pow
 def test_solve_trig():
-    from sympy.abc import n
     assert dumeq(solveset_real(sin(x), x),
         Union(imageset(Lambda(n, 2*pi*n), S.Integers),
               imageset(Lambda(n, 2*pi*n + pi), S.Integers)))
@@ -1048,7 +1041,7 @@ def test_solve_invalid_sol():
 
 @XFAIL
 def test_solve_trig_simplified():
-    from sympy.abc import n
+    n = Dummy('n')
     assert dumeq(solveset_real(sin(x), x),
         imageset(Lambda(n, n*pi), S.Integers))
 
@@ -1224,11 +1217,9 @@ def test__solveset_multi():
     from sympy import Reals
 
     # Basic univariate case:
-    from sympy.abc import x
     assert _solveset_multi([x**2-1], [x], [S.Reals]) == FiniteSet((1,), (-1,))
 
     # Linear systems of two equations
-    from sympy.abc import x, y
     assert _solveset_multi([x+y, x+1], [x, y], [Reals, Reals]) == FiniteSet((-1, 1))
     assert _solveset_multi([x+y, x+1], [y, x], [Reals, Reals]) == FiniteSet((1, -1))
     assert _solveset_multi([x+y, x-y-1], [x, y], [Reals, Reals]) == FiniteSet((S(1)/2, -S(1)/2))
@@ -1242,12 +1233,11 @@ def test__solveset_multi():
     assert _solveset_multi([x+y, x-y, x-1], [y, x], [Reals, Reals]) == S.EmptySet
 
     # Systems of three equations:
-    from sympy.abc import x, y, z
     assert _solveset_multi([x+y+z-1, x+y-z-2, x-y-z-3], [x, y, z], [Reals,
         Reals, Reals]) == FiniteSet((2, -S.Half, -S.Half))
 
     # Nonlinear systems:
-    from sympy.abc import r, theta, z, x, y
+    from sympy.abc import theta
     assert _solveset_multi([x**2+y**2-2, x+y], [x, y], [Reals, Reals]) == FiniteSet((-1, 1), (1, -1))
     assert _solveset_multi([x**2-1, y], [x, y], [Reals, Reals]) == FiniteSet((1, 0), (-1, 0))
     #assert _solveset_multi([x**2-y**2], [x, y], [Reals, Reals]) == Union(
@@ -1392,6 +1382,10 @@ def test_issue_16577():
         Matrix([[2*a, 3*a + 4]]), Matrix([[5]]))
 
 
+def test_issue_10085():
+    assert invert_real(exp(x),0,x) == (x, S.EmptySet)
+
+
 def test_linsolve():
     x1, x2, x3, x4 = symbols('x1, x2, x3, x4')
 
@@ -1630,7 +1624,7 @@ def test_trig_system_fail():
 
 
 def test_nonlinsolve_positive_dimensional():
-    x, y, z, a, b, c, d = symbols('x, y, z, a, b, c, d', extended_real=True)
+    x, y, a, b, c, d = symbols('x, y, a, b, c, d', extended_real=True)
     assert nonlinsolve([x*y, x*y - x], [x, y]) == FiniteSet((0, y))
 
     system = [a**2 + a*c, a - b]
@@ -1650,7 +1644,7 @@ def test_nonlinsolve_positive_dimensional():
 
 
 def test_nonlinsolve_polysys():
-    x, y, z = symbols('x, y, z', real=True)
+    x, y = symbols('x, y', real=True)
     assert nonlinsolve([x**2 + y - 2, x**2 + y], [x, y]) == S.EmptySet
 
     s = (-y + 2, y)
@@ -1713,7 +1707,7 @@ def test_nonlinsolve_complex():
 @XFAIL
 def test_solve_nonlinear_trans():
     # After the transcendental equation solver these will work
-    x, y, z = symbols('x, y, z', real=True)
+    x, y = symbols('x, y', real=True)
     soln1 = FiniteSet((2*LambertW(y/2), y))
     soln2 = FiniteSet((-x*sqrt(exp(x)), y), (x*sqrt(exp(x)), y))
     soln3 = FiniteSet((x*exp(x/2), x))
@@ -1724,6 +1718,135 @@ def test_solve_nonlinear_trans():
     assert nonlinsolve([x**2 - y**2/exp(x)], [x, y]) == soln4
 
 
+def test_issue_14642():
+    x = Symbol('x')
+    n1 = 0.5*x**3+x**2+0.5+I #add I in the Polynomials
+    solution = solveset(n1, x)
+    assert abs(solution.args[0] - (-2.28267560928153 - 0.312325580497716*I)) <= 1e-9
+    assert abs(solution.args[1] - (-0.297354141679308 + 1.01904778618762*I)) <= 1e-9
+    assert abs(solution.args[2] - (0.580029750960839 - 0.706722205689907*I)) <= 1e-9
+
+    # Symbolic
+    n1 = S.Half*x**3+x**2+S.Half+I
+    res = FiniteSet(-((3*sqrt(3)*31985**(S(1)/4)*sin(atan(S(172)/49)/2)/2 +
+            S(43)/2)**2 + (27 + 3*sqrt(3)*31985**(S(1)/4)*cos(atan(S(172)/49)
+            /2)/2)**2)**(S(1)/6)*cos(atan((27 + 3*sqrt(3)*31985**(S(1)/4)*
+            cos(atan(S(172)/49)/2)/2)/(3*sqrt(3)*31985**(S(1)/4)*sin(atan(
+            S(172)/49)/2)/2 + S(43)/2))/3)/3 - S(2)/3 - 4*cos(atan((27 +
+            3*sqrt(3)*31985**(S(1)/4)*cos(atan(S(172)/49)/2)/2)/(3*sqrt(3)*
+            31985**(S(1)/4)*sin(atan(S(172)/49)/2)/2 + S(43)/2))/3)/(3*((3*
+            sqrt(3)*31985**(S(1)/4)*sin(atan(S(172)/49)/2)/2 + S(43)/2)**2 +
+            (27 + 3*sqrt(3)*31985**(S(1)/4)*cos(atan(S(172)/49)/2)/2)**2)**(S(1)/
+            6)) + I*(-((3*sqrt(3)*31985**(S(1)/4)*sin(atan(S(172)/49)/2)/2 +
+            S(43)/2)**2 + (27 + 3*sqrt(3)*31985**(S(1)/4)*cos(atan(S(172)/49)/
+            2)/2)**2)**(S(1)/6)*sin(atan((27 + 3*sqrt(3)*31985**(S(1)/4)*cos(
+            atan(S(172)/49)/2)/2)/(3*sqrt(3)*31985**(S(1)/4)*sin(atan(S(172)/49)
+            /2)/2 + S(43)/2))/3)/3 + 4*sin(atan((27 + 3*sqrt(3)*31985**(S(1)/4)*
+            cos(atan(S(172)/49)/2)/2)/(3*sqrt(3)*31985**(S(1)/4)*sin(atan(S(172)
+            /49)/2)/2 + S(43)/2))/3)/(3*((3*sqrt(3)*31985**(S(1)/4)*sin(atan(
+            S(172)/49)/2)/2 + S(43)/2)**2 + (27 + 3*sqrt(3)*31985**(S(1)/4)*
+            cos(atan(S(172)/49)/2)/2)**2)**(S(1)/6))), -S(2)/3 - sqrt(3)*((3*
+            sqrt(3)*31985**(S(1)/4)*sin(atan(S(172)/49)/2)/2 + S(43)/2)**2 +
+            (27 + 3*sqrt(3)*31985**(S(1)/4)*cos(atan(S(172)/49)/2)/2)**2)**(S(1)
+            /6)*sin(atan((27 + 3*sqrt(3)*31985**(S(1)/4)*cos(atan(S(172)/49)/2)
+            /2)/(3*sqrt(3)*31985**(S(1)/4)*sin(atan(S(172)/49)/2)/2 + S(43)/2))
+            /3)/6 - 4*re(1/((-S(1)/2 - sqrt(3)*I/2)*(S(43)/2 + 27*I + sqrt(-256 +
+            (43 + 54*I)**2)/2)**(S(1)/3)))/3 + ((3*sqrt(3)*31985**(S(1)/4)*sin(
+            atan(S(172)/49)/2)/2 + S(43)/2)**2 + (27 + 3*sqrt(3)*31985**(S(1)/4)*
+            cos(atan(S(172)/49)/2)/2)**2)**(S(1)/6)*cos(atan((27 + 3*sqrt(3)*
+            31985**(S(1)/4)*cos(atan(S(172)/49)/2)/2)/(3*sqrt(3)*31985**(S(1)/4)*
+            sin(atan(S(172)/49)/2)/2 + S(43)/2))/3)/6 + I*(-4*im(1/((-S(1)/2 -
+            sqrt(3)*I/2)*(S(43)/2 + 27*I + sqrt(-256 + (43 + 54*I)**2)/2)**(S(1)/
+            3)))/3 + ((3*sqrt(3)*31985**(S(1)/4)*sin(atan(S(172)/49)/2)/2 +
+            S(43)/2)**2 + (27 + 3*sqrt(3)*31985**(S(1)/4)*cos(atan(S(172)/49)/2)
+            /2)**2)**(S(1)/6)*sin(atan((27 + 3*sqrt(3)*31985**(S(1)/4)*cos(atan(
+            S(172)/49)/2)/2)/(3*sqrt(3)*31985**(S(1)/4)*sin(atan(S(172)/49)/2)/2 +
+            S(43)/2))/3)/6 + sqrt(3)*((3*sqrt(3)*31985**(S(1)/4)*sin(atan(S(172)/
+            49)/2)/2 + S(43)/2)**2 + (27 + 3*sqrt(3)*31985**(S(1)/4)*cos(atan(
+            S(172)/49)/2)/2)**2)**(S(1)/6)*cos(atan((27 + 3*sqrt(3)*31985**(S(1)/
+            4)*cos(atan(S(172)/49)/2)/2)/(3*sqrt(3)*31985**(S(1)/4)*sin(atan(
+            S(172)/49)/2)/2 + S(43)/2))/3)/6), -S(2)/3 - 4*re(1/((-S(1)/2 +
+            sqrt(3)*I/2)*(S(43)/2 + 27*I + sqrt(-256 + (43 + 54*I)**2)/2)**(S(1)
+            /3)))/3 + sqrt(3)*((3*sqrt(3)*31985**(S(1)/4)*sin(atan(S(172)/49)/2)/2 +
+            S(43)/2)**2 + (27 + 3*sqrt(3)*31985**(S(1)/4)*cos(atan(S(172)/49)/2)
+            /2)**2)**(S(1)/6)*sin(atan((27 + 3*sqrt(3)*31985**(S(1)/4)*cos(atan(
+            S(172)/49)/2)/2)/(3*sqrt(3)*31985**(S(1)/4)*sin(atan(S(172)/49)/2)/2 +
+            S(43)/2))/3)/6 + ((3*sqrt(3)*31985**(S(1)/4)*sin(atan(S(172)/49)/2)/2 +
+            S(43)/2)**2 + (27 + 3*sqrt(3)*31985**(S(1)/4)*cos(atan(S(172)/49)/2)
+            /2)**2)**(S(1)/6)*cos(atan((27 + 3*sqrt(3)*31985**(S(1)/4)*cos(atan(
+            S(172)/49)/2)/2)/(3*sqrt(3)*31985**(S(1)/4)*sin(atan(S(172)/49)/2)/2 +
+            S(43)/2))/3)/6 + I*(-sqrt(3)*((3*sqrt(3)*31985**(S(1)/4)*sin(atan(
+            S(172)/49)/2)/2 + S(43)/2)**2 + (27 + 3*sqrt(3)*31985**(S(1)/4)*cos(
+            atan(S(172)/49)/2)/2)**2)**(S(1)/6)*cos(atan((27 + 3*sqrt(3)*31985**(
+            S(1)/4)*cos(atan(S(172)/49)/2)/2)/(3*sqrt(3)*31985**(S(1)/4)*sin(
+            atan(S(172)/49)/2)/2 + S(43)/2))/3)/6 + ((3*sqrt(3)*31985**(S(1)/4)*
+            sin(atan(S(172)/49)/2)/2 + S(43)/2)**2 + (27 + 3*sqrt(3)*31985**(S(1)/4)*
+            cos(atan(S(172)/49)/2)/2)**2)**(S(1)/6)*sin(atan((27 + 3*sqrt(3)*31985**(
+            S(1)/4)*cos(atan(S(172)/49)/2)/2)/(3*sqrt(3)*31985**(S(1)/4)*sin(
+            atan(S(172)/49)/2)/2 + S(43)/2))/3)/6 - 4*im(1/((-S(1)/2 + sqrt(3)*I/2)*
+            (S(43)/2 + 27*I + sqrt(-256 + (43 + 54*I)**2)/2)**(S(1)/3)))/3))
+
+    assert solveset(n1, x) == res
+
+
+def test_issue_13961():
+    V = (ax, bx, cx, gx, jx, lx, mx, nx, q) = symbols('ax bx cx gx jx lx mx nx q')
+    S = (ax*q - lx*q - mx, ax - gx*q - lx, bx*q**2 + cx*q - jx*q - nx, q*(-ax*q + lx*q + mx), q*(-ax + gx*q + lx))
+
+    sol = FiniteSet((lx + mx/q, (-cx*q + jx*q + nx)/q**2, cx, mx/q**2, jx, lx, mx, nx, q),
+                    (lx + mx/q, (cx*q - jx*q - nx)/q**2*-1, cx, mx/q**2, jx, lx, mx, nx, q))
+    assert nonlinsolve(S, *V) == sol
+    # The two solutions are in fact identical, so even better if only one is returned
+
+
+def test_issue_14541():
+    solutions = solveset(sqrt(-x**2 - 2.0), x)
+    assert abs(solutions.args[0]+1.4142135623731*I) <= 1e-9
+    assert abs(solutions.args[1]-1.4142135623731*I) <= 1e-9
+
+
+def test_issue_13396():
+    expr = -2*y*exp(-x**2 - y**2)*Abs(x)
+    sol = FiniteSet(0)
+
+    assert solveset(expr, y, domain=S.Reals) == sol
+
+    # Related type of equation also solved here
+    assert solveset(atan(x**2 - y**2)-pi/2, y, S.Reals) == EmptySet()
+
+
+def test_issue_12032():
+    sol = FiniteSet(-sqrt(-2/(3*(Rational(1, 16) + sqrt(849)/144)**(Rational(1, 3))) +
+                          2*(Rational(1, 16) + sqrt(849)/144)**(Rational(1, 3)))/2 +
+                    sqrt(Abs(-2*(Rational(1, 16) + sqrt(849)/144)**(Rational(1, 3)) +
+                             2/(3*(Rational(1, 16) + sqrt(849)/144)**(Rational(1, 3))) +
+                             2/sqrt(-2/(3*(Rational(1, 16) + sqrt(849)/144)**(Rational(1, 3))) +
+                                    2*(Rational(1, 16) + sqrt(849)/144)**(Rational(1, 3)))))/2,
+                    -sqrt(Abs(-2*(Rational(1, 16) + sqrt(849)/144)**(Rational(1, 3)) +
+                              2/(3*(Rational(1, 16) + sqrt(849)/144)**(Rational(1, 3))) +
+                              2/sqrt(-2/(3*(Rational(1, 16) + sqrt(849)/144)**(Rational(1, 3))) +
+                                     2*(Rational(1, 16) + sqrt(849)/144)**(Rational(1, 3)))))/2 -
+                    sqrt(-2/(3*(Rational(1, 16) + sqrt(849)/144)**(Rational(1, 3))) +
+                         2*(Rational(1, 16) + sqrt(849)/144)**(Rational(1, 3)))/2,
+                    sqrt(-2/(3*(Rational(1, 16) + sqrt(849)/144)**(Rational(1, 3))) +
+                         2*(Rational(1, 16) + sqrt(849)/144)**(Rational(1, 3)))/2 -
+                    I*sqrt(Abs(-2/sqrt(-2/(3*(Rational(1, 16) + sqrt(849)/144)**(Rational(1, 3))) +
+                                       2*(Rational(1, 16) + sqrt(849)/144)**(Rational(1, 3))) -
+                               2*(Rational(1, 16) + sqrt(849)/144)**(Rational(1, 3)) +
+                               2/(3*(Rational(1, 16) + sqrt(849)/144)**(Rational(1, 3)))))/2,
+                    sqrt(-2/(3*(Rational(1, 16) + sqrt(849)/144)**(Rational(1, 3))) +
+                         2*(Rational(1, 16) + sqrt(849)/144)**(Rational(1, 3)))/2 +
+                    I*sqrt(Abs(-2/sqrt(-2/(3*(Rational(1, 16) + sqrt(849)/144)**(Rational(1, 3))) +
+                                       2*(Rational(1, 16) + sqrt(849)/144)**(Rational(1, 3))) -
+                               2*(Rational(1, 16) + sqrt(849)/144)**(Rational(1, 3)) +
+                               2/(3*(Rational(1, 16) + sqrt(849)/144)**(Rational(1,3)))))/2)
+    assert solveset(x**4 + x - 1, x) == sol
+
+
+def test_issue_10876():
+    assert solveset(1/sqrt(x), x) == S.EmptySet
+
+
 def test_issue_19050():
     # test_issue_19050 --> TypeError removed
     assert dumeq(nonlinsolve([x + y, sin(y)], [x, y]),
@@ -1751,6 +1874,12 @@ def test_issue_17566():
         FiniteSet((-log(81)/log(3), 1))
 
 
+def test_issue_16643():
+    n = Dummy('n')
+    assert solveset(x**2*sin(x), x).dummy_eq(Union(ImageSet(Lambda(n, 2*n*pi + pi), S.Integers),
+                                                   ImageSet(Lambda(n, 2*n*pi), S.Integers)))
+
+
 def test_issue_19587():
     n,m = symbols('n m')
     assert nonlinsolve([32*2**m*2**n - 4**n, 27*3**m - 3**(-n)], m, n) ==\
@@ -1800,14 +1929,14 @@ def test_issue_5132_2():
 
 
 def test_issue_6752():
-    a,b,c,d = symbols('a, b, c, d', real=True)
+    a, b = symbols('a, b', real=True)
     assert nonlinsolve([a**2 + a, a - b], [a, b]) == {(-1, -1), (0, 0)}
 
 
 @SKIP("slow")
 def test_issue_5114_solveset():
     # slow testcase
-    from sympy.abc import d, e, f, g, h, i, j, k, l, o, p, q, r
+    from sympy.abc import o, p
 
     # there is no 'a' in the equation set but this is how the
     # problem was originally posed
@@ -1887,9 +2016,9 @@ def test_nonlinsolve_conditionset():
     f1 = f(x) - pi/2
     f2 = f(y) - pi*Rational(3, 2)
     intermediate_system = Eq(2*f(x) - pi, 0) & Eq(2*f(y) - 3*pi, 0)
-    symbols = Tuple(x, y)
+    syms = Tuple(x, y)
     soln = ConditionSet(
-        symbols,
+        syms,
         intermediate_system,
         S.Complexes**2)
     assert nonlinsolve([f1, f2], [x, y]) == soln
@@ -1983,6 +2112,19 @@ def test_issue_21022():
         assert len(result) == 8
 
 
+def test_issue_17940():
+    n = Dummy('n')
+    k1 = Dummy('k1')
+    sol = ImageSet(Lambda(((k1, n),), I*(2*k1*pi + arg(2*n*I*pi + log(5)))
+                          + log(Abs(2*n*I*pi + log(5)))),
+                   ProductSet(S.Integers, S.Integers))
+    assert solveset(exp(exp(x)) - 5, x).dummy_eq(sol)
+
+
+def test_issue_17906():
+    assert solveset(7**(x**2 - 80) - 49**x, x) == FiniteSet(-8, 10)
+
+
 def test_issue_17933():
     eq1 = x*sin(45) - y*cos(q)
     eq2 = x*cos(45) - y*sin(q)
@@ -2190,9 +2332,16 @@ def test_issue_12429():
     assert eq == sol
 
 
+def test_issue_19506():
+    eq = arg(x + I)
+    C = Dummy('C')
+    assert solveset(eq).dummy_eq(Intersection(ConditionSet(C, Eq(im(C) + 1, 0), S.Complexes),
+                                                 ConditionSet(C, re(C) > 0, S.Complexes)))
+
+
 def test_solveset_arg():
     assert solveset(arg(x), x, S.Reals)  == Interval.open(0, oo)
-    assert solveset(arg(4*x -3), x) == Interval.open(Rational(3, 4), oo)
+    assert solveset(arg(4*x -3), x, S.Reals) == Interval.open(Rational(3, 4), oo)
 
 
 def test__is_finite_with_finite_vars():
@@ -2277,7 +2426,7 @@ def test_issue_21276():
 
 # exponential tests
 def test_exponential_real():
-    from sympy.abc import x, y, z
+    from sympy.abc import y
 
     e1 = 3**(2*x) - 2**(x + 3)
     e2 = 4**(5 - 9*x) - 8**(2 - x)
@@ -2324,8 +2473,6 @@ def test_exponential_real():
 
 @XFAIL
 def test_exponential_complex():
-    from sympy.abc import x
-    from sympy import Dummy
     n = Dummy('n')
 
     assert dumeq(solveset_complex(2**x + 4**x, x),imageset(
@@ -2698,10 +2845,11 @@ def test_issue_10426():
         Intersection(S.Complexes, ImageSet(Lambda(n, -I*(I*(2*n*pi + arg(-exp(-2*I*x))) + 2*im(x))),
         S.Integers)))).dummy_eq(Dummy('x,n'))
 
+
 def test_issue_18208():
-    vars = symbols('x0:16') + symbols('y0:12')
+    variables = symbols('x0:16') + symbols('y0:12')
     x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15,\
-    y0, y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11 = vars
+    y0, y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11 = variables
 
     eqs = [x0 + x1 + x2 + x3 - 51,
            x0 + x1 + x4 + x5 - 46,
@@ -2744,23 +2892,22 @@ def test_issue_18208():
                 -y11 - y7 + y9 + 24, y11 + y7 - y9 - 3, 33 - y7, y7, 27 - y9, y9,
                 27 - y11, y11]
 
-    A, b = linear_eq_to_matrix(eqs, vars)
+    A, b = linear_eq_to_matrix(eqs, variables)
 
     # solve
-    solve_expected = {v:eq for v, eq in zip(vars, expected) if v != eq}
+    solve_expected = {v:eq for v, eq in zip(variables, expected) if v != eq}
 
-    assert solve(eqs, vars) == solve_expected
+    assert solve(eqs, variables) == solve_expected
 
     # linsolve
     linsolve_expected = FiniteSet(Tuple(*expected))
 
-    assert linsolve(eqs, vars) == linsolve_expected
-    assert linsolve((A, b), vars) == linsolve_expected
+    assert linsolve(eqs, variables) == linsolve_expected
+    assert linsolve((A, b), variables) == linsolve_expected
 
     # gauss_jordan_solve
     gj_solve, new_vars = A.gauss_jordan_solve(b)
     gj_solve = [i for i in gj_solve]
-    tau0, tau1, tau2, tau3, tau4 = symbols([str(v) for v in new_vars])
 
     gj_expected = linsolve_expected.subs(zip([x3, x7, y7, y9, y11], new_vars))
 
@@ -2778,7 +2925,7 @@ def test_issue_18208():
                                       -y5 + y7 - 1, y5 - y7 + 24, 21 - y5, y5, 33 - y7,
                                       y7, 27 - y9, y9, -y5 + y7 - y9 + 24, y5 - y7 + y9 + 3))
 
-    assert nonlinsolve(eqs, vars) == nonlinsolve_expected
+    assert nonlinsolve(eqs, variables) == nonlinsolve_expected
 
 @XFAIL
 def test_substitution_with_infeasible_solution():