Repository: sympy/sympy

Issue:
atan2._eval_evalf is missing a return keyword
`sympy.functions.atan2._eval_evalf` is missing a return keyword, and consequently `atan2` does not work with symbolic arguments that redefine their `_eval_evalf` method.

See https://groups.google.com/forum/#!msg/sympy/fpRIf9c79zw/taAssuspAgAJ

Solution: Add the return keyword.

```
import sympy
import sympy.functions as syf

class A(sympy.Symbol):
    def _eval_evalf(self, prec):
        return sympy.Float(5.0)

x = A('X', real=True)
y = A('Y', real=True)
print(syf.atan2(y, x).evalf())  # prints "atan2(Y, X)" instead of "0.785398163397448"
```

Discussion:

Patch:
diff --git a/sympy/core/power.py b/sympy/core/power.py
index 4a0d08c0a6..6e65cea856 100644
--- a/sympy/core/power.py
+++ b/sympy/core/power.py
@@ -585,10 +585,7 @@ def _eval_is_extended_real(self):
                 return True
             c = self.exp.coeff(S.ImaginaryUnit)
             if c:
-                if self.base.is_rational and c.is_rational:
-                    if self.base.is_nonzero and (self.base - 1).is_nonzero and c.is_nonzero:
-                        return False
-                ok = (c*log(self.base)/S.Pi).is_integer
+                ok = (c*log(self.base)/S.Pi).is_Integer
                 if ok is not None:
                     return ok
 
diff --git a/sympy/functions/elementary/complexes.py b/sympy/functions/elementary/complexes.py
index abfeffa76d..409250317a 100644
--- a/sympy/functions/elementary/complexes.py
+++ b/sympy/functions/elementary/complexes.py
@@ -622,8 +622,6 @@ def _eval_rewrite_as_Heaviside(self, arg, **kwargs):
     def _eval_rewrite_as_Piecewise(self, arg, **kwargs):
         if arg.is_extended_real:
             return Piecewise((arg, arg >= 0), (-arg, True))
-        elif arg.is_imaginary:
-            return Piecewise((I*arg, I*arg >= 0), (-I*arg, True))
 
     def _eval_rewrite_as_sign(self, arg, **kwargs):
         return arg/sign(arg)
diff --git a/sympy/functions/elementary/trigonometric.py b/sympy/functions/elementary/trigonometric.py
index 635e7f278d..b7a0ad11cb 100644
--- a/sympy/functions/elementary/trigonometric.py
+++ b/sympy/functions/elementary/trigonometric.py
@@ -3070,4 +3070,4 @@ def fdiff(self, argindex):
     def _eval_evalf(self, prec):
         y, x = self.args
         if x.is_extended_real and y.is_extended_real:
-            super(atan2, self)._eval_evalf(prec)
+            return super(atan2, self)._eval_evalf(prec)
diff --git a/sympy/plotting/experimental_lambdify.py b/sympy/plotting/experimental_lambdify.py
index 47ef2b6a5f..9d3dcab46d 100644
--- a/sympy/plotting/experimental_lambdify.py
+++ b/sympy/plotting/experimental_lambdify.py
@@ -289,7 +289,6 @@ def __init__(self, args, expr, print_lambda=False, use_evalf=False,
         from sympy import sqrt
         namespace.update({'sqrt': sqrt})
         namespace.update({'Eq': lambda x, y: x == y})
-        namespace.update({'Ne': lambda x, y: x != y})
         # End workaround.
         if use_python_math:
             namespace.update({'math': __import__('math')})
@@ -593,9 +592,6 @@ def translate_func(self, func_name, argtree):
             new_name = self.dict_fun[func_name]
             argstr = self.tree2str_translate(argtree)
             return new_name + '(' + argstr
-        elif func_name in ['Eq', 'Ne']:
-            op = {'Eq': '==', 'Ne': '!='}
-            return "(lambda x, y: x {} y)({}".format(op[func_name], self.tree2str_translate(argtree))
         else:
             template = '(%s(%s)).evalf(' if self.use_evalf else '%s(%s'
             if self.float_wrap_evalf:
diff --git a/sympy/simplify/simplify.py b/sympy/simplify/simplify.py
index 02abbc8c7c..ad3fd56d43 100644
--- a/sympy/simplify/simplify.py
+++ b/sympy/simplify/simplify.py
@@ -112,10 +112,7 @@ def _separatevars(expr, force):
         arg = expr.args[0]
         if arg.is_Mul and not arg.is_number:
             s = separatevars(arg, dict=True, force=force)
-            if s is not None:
-                return Mul(*map(expr.func, s.values()))
-            else:
-                return expr
+            return Mul(*map(expr.func, s.values()))
 
     if len(expr.free_symbols) < 2:
         return expr
diff --git a/sympy/solvers/solvers.py b/sympy/solvers/solvers.py
index eee19ad4a5..94f61a50ce 100644
--- a/sympy/solvers/solvers.py
+++ b/sympy/solvers/solvers.py
@@ -1020,15 +1020,22 @@ def _sympified_list(w):
     piece = Lambda(w, Piecewise((w, Ge(w, 0)), (-w, True)))
     for i, fi in enumerate(f):
         # Abs
-        fi = fi.replace(Abs, lambda arg:
-            separatevars(Abs(arg)) if arg.has(*symbols) else Abs(arg))
-        fi = fi.replace(Abs, lambda arg:
-            Abs(arg).rewrite(Piecewise) if arg.has(*symbols) else Abs(arg))
-
-        for e in fi.find(Abs):
-            if e.has(*symbols):
+        reps = []
+        _abs = fi.atoms(Abs)
+        while _abs:
+            a = _abs.pop()
+            if not a.has(*symbols):
+                continue
+            newa = separatevars(a)
+            if not isinstance(newa, Abs):
+                _abs.update(newa.atoms(Abs))
+                continue
+            if a.args[0].is_extended_real is None:
                 raise NotImplementedError('solving %s when the argument '
-                    'is not real or imaginary.' % e)
+                    'is not real or imaginary.' % a)
+            reps.append((a, piece(a.args[0]) if a.args[0].is_extended_real else \
+                piece(a.args[0]*S.ImaginaryUnit)))
+        fi = fi.subs(reps)
 
         # arg
         _arg = [a for a in fi.atoms(arg) if a.has(*symbols)]
@@ -1483,21 +1490,18 @@ def _solve(f, *symbols, **flags):
                     continue
                 try:
                     v = cond.subs(symbol, candidate)
-                    _eval_simplify = getattr(v, '_eval_simplify', None)
-                    if _eval_simplify is not None:
+                    _eval_simpify = getattr(v, '_eval_simpify', None)
+                    if _eval_simpify is not None:
                         # unconditionally take the simpification of v
-                        v = _eval_simplify(ratio=2, measure=lambda x: 1)
+                        v = _eval_simpify(ratio=2, measure=lambda x: 1)
                 except TypeError:
                     # incompatible type with condition(s)
                     continue
                 if v == False:
                     continue
-                if v == True:
-                    result.add(candidate)
-                else:
-                    result.add(Piecewise(
-                        (candidate, v),
-                        (S.NaN, True)))
+                result.add(Piecewise(
+                    (candidate, v),
+                    (S.NaN, True)))
         # set flags for quick exit at end; solutions for each
         # piece were already checked and simplified
         check = False
diff --git a/sympy/solvers/solveset.py b/sympy/solvers/solveset.py
index 3f5866bb8d..9eb4ba861b 100644
--- a/sympy/solvers/solveset.py
+++ b/sympy/solvers/solveset.py
@@ -20,8 +20,6 @@
 from sympy.core.numbers import I, Number, Rational, oo
 from sympy.core.function import (Lambda, expand_complex, AppliedUndef,
                                 expand_log, _mexpand)
-from sympy.core.mod import Mod
-from sympy.core.numbers import igcd
 from sympy.core.relational import Eq, Ne
 from sympy.core.symbol import Symbol
 from sympy.core.sympify import _sympify
@@ -38,13 +36,9 @@
                         Union, ConditionSet, ImageSet, Complement, Contains)
 from sympy.sets.sets import Set
 from sympy.matrices import Matrix, MatrixBase
-from sympy.ntheory import totient
-from sympy.ntheory.factor_ import divisors
-from sympy.ntheory.residue_ntheory import discrete_log, nthroot_mod
 from sympy.polys import (roots, Poly, degree, together, PolynomialError,
                          RootOf, factor)
 from sympy.polys.polyerrors import CoercionFailed
-from sympy.polys.polytools import invert
 from sympy.solvers.solvers import (checksol, denoms, unrad,
     _simple_dens, recast_to_symbols)
 from sympy.solvers.polysys import solve_poly_system
@@ -578,7 +572,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, simplify
+    from sympy import ilcm, igcd, expand_trig, degree, simplify
     f = trigsimp(f)
     f_original = f
     trig_functions = f.atoms(sin, cos, tan, sec, cot, csc)
@@ -937,8 +931,6 @@ def _solveset(f, symbol, domain, _check=False):
         except NotImplementedError:
             result = ConditionSet(symbol, f, domain)
         return result
-    elif _is_modular(f, symbol):
-        result = _solve_modular(f, symbol, domain)
     else:
         lhs, rhs_s = inverter(f, 0, symbol)
         if lhs == symbol:
@@ -1007,291 +999,6 @@ def _solveset(f, symbol, domain, _check=False):
     return result
 
 
-def _is_modular(f, symbol):
-    """
-    Helper function to check below mentioned types of modular equations.
-    ``A - Mod(B, C) = 0``
-
-    A -> This can or cannot be a function of symbol.
-    B -> This is surely a function of symbol.
-    C -> It is an integer.
-
-    Parameters
-    ==========
-
-    f : Expr
-        The equation to be checked.
-
-    symbol : Symbol
-        The concerned variable for which the equation is to be checked.
-
-    Examples
-    ========
-
-    >>> from sympy import symbols, exp, Mod
-    >>> from sympy.solvers.solveset import _is_modular as check
-    >>> x, y = symbols('x y')
-    >>> check(Mod(x, 3) - 1, x)
-    True
-    >>> check(Mod(x, 3) - 1, y)
-    False
-    >>> check(Mod(x, 3)**2 - 5, x)
-    False
-    >>> check(Mod(x, 3)**2 - y, x)
-    False
-    >>> check(exp(Mod(x, 3)) - 1, x)
-    False
-    >>> check(Mod(3, y) - 1, y)
-    False
-    """
-
-    if not f.has(Mod):
-        return False
-
-    # extract modterms from f.
-    modterms = list(f.atoms(Mod))
-
-    return (len(modterms) == 1 and  # only one Mod should be present
-            modterms[0].args[0].has(symbol) and  # B-> function of symbol
-            modterms[0].args[1].is_integer and  # C-> to be an integer.
-            any(isinstance(term, Mod)
-            for term in list(_term_factors(f)))  # free from other funcs
-            )
-
-
-def _invert_modular(modterm, rhs, n, symbol):
-    """
-    Helper function to invert modular equation.
-    ``Mod(a, m) - rhs = 0``
-
-    Generally it is inverted as (a, ImageSet(Lambda(n, m*n + rhs), S.Integers)).
-    More simplified form will be returned if possible.
-
-    If it is not invertible then (modterm, rhs) is returned.
-
-    The following cases arise while inverting equation ``Mod(a, m) - rhs = 0``:
-
-    1. If a is symbol then  m*n + rhs is the required solution.
-
-    2. If a is an instance of ``Add`` then we try to find two symbol independent
-       parts of a and the symbol independent part gets tranferred to the other
-       side and again the ``_invert_modular`` is called on the symbol
-       dependent part.
-
-    3. If a is an instance of ``Mul`` then same as we done in ``Add`` we separate
-       out the symbol dependent and symbol independent parts and transfer the
-       symbol independent part to the rhs with the help of invert and again the
-       ``_invert_modular`` is called on the symbol dependent part.
-
-    4. If a is an instance of ``Pow`` then two cases arise as following:
-
-        - If a is of type (symbol_indep)**(symbol_dep) then the remainder is
-          evaluated with the help of discrete_log function and then the least
-          period is being found out with the help of totient function.
-          period*n + remainder is the required solution in this case.
-          For reference: (https://en.wikipedia.org/wiki/Euler's_theorem)
-
-        - If a is of type (symbol_dep)**(symbol_indep) then we try to find all
-          primitive solutions list with the help of nthroot_mod function.
-          m*n + rem is the general solution where rem belongs to solutions list
-          from nthroot_mod function.
-
-    Parameters
-    ==========
-
-    modterm, rhs : Expr
-        The modular equation to be inverted, ``modterm - rhs = 0``
-
-    symbol : Symbol
-        The variable in the equation to be inverted.
-
-    n : Dummy
-        Dummy variable for output g_n.
-
-    Returns
-    =======
-
-    A tuple (f_x, g_n) is being returned where f_x is modular independent function
-    of symbol and g_n being set of values f_x can have.
-
-    Examples
-    ========
-
-    >>> from sympy import symbols, exp, Mod, Dummy, S
-    >>> from sympy.solvers.solveset import _invert_modular as invert_modular
-    >>> x, y = symbols('x y')
-    >>> n = Dummy('n')
-    >>> invert_modular(Mod(exp(x), 7), S(5), n, x)
-    (Mod(exp(x), 7), 5)
-    >>> invert_modular(Mod(x, 7), S(5), n, x)
-    (x, ImageSet(Lambda(_n, 7*_n + 5), Integers))
-    >>> invert_modular(Mod(3*x + 8, 7), S(5), n, x)
-    (x, ImageSet(Lambda(_n, 7*_n + 6), Integers))
-    >>> invert_modular(Mod(x**4, 7), S(5), n, x)
-    (x, EmptySet())
-    >>> invert_modular(Mod(2**(x**2 + x + 1), 7), S(2), n, x)
-    (x**2 + x + 1, ImageSet(Lambda(_n, 3*_n + 1), Naturals0))
-
-    """
-    a, m = modterm.args
-
-    if rhs.is_real is False or any(term.is_real is False
-            for term in list(_term_factors(a))):
-        # Check for complex arguments
-        return modterm, rhs
-
-    if abs(rhs) >= abs(m):
-        # if rhs has value greater than value of m.
-        return symbol, EmptySet()
-
-    if a is symbol:
-        return symbol, ImageSet(Lambda(n, m*n + rhs), S.Integers)
-
-    if a.is_Add:
-        # g + h = a
-        g, h = a.as_independent(symbol)
-        if g is not S.Zero:
-            x_indep_term = rhs - Mod(g, m)
-            return _invert_modular(Mod(h, m), Mod(x_indep_term, m), n, symbol)
-
-    if a.is_Mul:
-        # g*h = a
-        g, h = a.as_independent(symbol)
-        if g is not S.One:
-            x_indep_term = rhs*invert(g, m)
-            return _invert_modular(Mod(h, m), Mod(x_indep_term, m), n, symbol)
-
-    if a.is_Pow:
-        # base**expo = a
-        base, expo = a.args
-        if expo.has(symbol) and not base.has(symbol):
-            # remainder -> solution independent of n of equation.
-            # m, rhs are made coprime by dividing igcd(m, rhs)
-            try:
-                remainder = discrete_log(m / igcd(m, rhs), rhs, a.base)
-            except ValueError:  # log does not exist
-                return modterm, rhs
-            # period -> coefficient of n in the solution and also referred as
-            # the least period of expo in which it is repeats itself.
-            # (a**(totient(m)) - 1) divides m. Here is link of theorem:
-            # (https://en.wikipedia.org/wiki/Euler's_theorem)
-            period = totient(m)
-            for p in divisors(period):
-                # there might a lesser period exist than totient(m).
-                if pow(a.base, p, m / igcd(m, a.base)) == 1:
-                    period = p
-                    break
-            # recursion is not applied here since _invert_modular is currently
-            # not smart enough to handle infinite rhs as here expo has infinite
-            # rhs = ImageSet(Lambda(n, period*n + remainder), S.Naturals0).
-            return expo, ImageSet(Lambda(n, period*n + remainder), S.Naturals0)
-        elif base.has(symbol) and not expo.has(symbol):
-            try:
-                remainder_list = nthroot_mod(rhs, expo, m, all_roots=True)
-                if remainder_list is None:
-                    return symbol, EmptySet()
-            except (ValueError, NotImplementedError):
-                return modterm, rhs
-            g_n = EmptySet()
-            for rem in remainder_list:
-                g_n += ImageSet(Lambda(n, m*n + rem), S.Integers)
-            return base, g_n
-
-    return modterm, rhs
-
-
-def _solve_modular(f, symbol, domain):
-    r"""
-    Helper function for solving modular equations of type ``A - Mod(B, C) = 0``,
-    where A can or cannot be a function of symbol, B is surely a function of
-    symbol and C is an integer.
-
-    Currently ``_solve_modular`` is only able to solve cases
-    where A is not a function of symbol.
-
-    Parameters
-    ==========
-
-    f : Expr
-        The modular equation to be solved, ``f = 0``
-
-    symbol : Symbol
-        The variable in the equation to be solved.
-
-    domain : Set
-        A set over which the equation is solved. It has to be a subset of
-        Integers.
-
-    Returns
-    =======
-
-    A set of integer solutions satisfying the given modular equation.
-    A ``ConditionSet`` if the equation is unsolvable.
-
-    Examples
-    ========
-
-    >>> from sympy.solvers.solveset import _solve_modular as solve_modulo
-    >>> from sympy import S, Symbol, sin, Intersection, Range, Interval
-    >>> from sympy.core.mod import Mod
-    >>> x = Symbol('x')
-    >>> solve_modulo(Mod(5*x - 8, 7) - 3, x, S.Integers)
-    ImageSet(Lambda(_n, 7*_n + 5), Integers)
-    >>> solve_modulo(Mod(5*x - 8, 7) - 3, x, S.Reals)  # domain should be subset of integers.
-    ConditionSet(x, Eq(Mod(5*x + 6, 7) - 3, 0), Reals)
-    >>> solve_modulo(-7 + Mod(x, 5), x, S.Integers)
-    EmptySet()
-    >>> solve_modulo(Mod(12**x, 21) - 18, x, S.Integers)
-    ImageSet(Lambda(_n, 6*_n + 2), Naturals0)
-    >>> solve_modulo(Mod(sin(x), 7) - 3, x, S.Integers) # not solvable
-    ConditionSet(x, Eq(Mod(sin(x), 7) - 3, 0), Integers)
-    >>> solve_modulo(3 - Mod(x, 5), x, Intersection(S.Integers, Interval(0, 100)))
-    Intersection(ImageSet(Lambda(_n, 5*_n + 3), Integers), Range(0, 101, 1))
-    """
-    # extract modterm and g_y from f
-    unsolved_result = ConditionSet(symbol, Eq(f, 0), domain)
-    modterm = list(f.atoms(Mod))[0]
-    rhs = -S.One*(f.subs(modterm, S.Zero))
-    if f.as_coefficients_dict()[modterm].is_negative:
-        # checks if coefficient of modterm is negative in main equation.
-        rhs *= -S.One
-
-    if not domain.is_subset(S.Integers):
-        return unsolved_result
-
-    if rhs.has(symbol):
-        # TODO Case: A-> function of symbol, can be extended here
-        # in future.
-        return unsolved_result
-
-    n = Dummy('n', integer=True)
-    f_x, g_n = _invert_modular(modterm, rhs, n, symbol)
-
-    if f_x is modterm and g_n is rhs:
-        return unsolved_result
-
-    if f_x is symbol:
-        if domain is not S.Integers:
-            return domain.intersect(g_n)
-        return g_n
-
-    if isinstance(g_n, ImageSet):
-        lamda_expr = g_n.lamda.expr
-        lamda_vars = g_n.lamda.variables
-        base_set = g_n.base_set
-        sol_set = _solveset(f_x - lamda_expr, symbol, S.Integers)
-        if isinstance(sol_set, FiniteSet):
-            tmp_sol = EmptySet()
-            for sol in sol_set:
-                tmp_sol += ImageSet(Lambda(lamda_vars, sol), base_set)
-            sol_set = tmp_sol
-        else:
-            sol_set =  ImageSet(Lambda(lamda_vars, sol_set), base_set)
-        return domain.intersect(sol_set)
-
-    return unsolved_result
-
-
 def _term_factors(f):
     """
     Iterator to get the factors of all terms present


Test patch:
diff --git a/sympy/core/tests/test_power.py b/sympy/core/tests/test_power.py
index bfd4f05902..98f70a9576 100644
--- a/sympy/core/tests/test_power.py
+++ b/sympy/core/tests/test_power.py
@@ -5,7 +5,6 @@
 from sympy.core.function import expand_multinomial
 from sympy.functions.elementary.miscellaneous import sqrt, cbrt
 from sympy.functions.elementary.exponential import exp, log
-from sympy.functions.special.error_functions import erf
 from sympy.functions.elementary.trigonometric import (
     sin, cos, tan, sec, csc, sinh, cosh, tanh, atan)
 from sympy.series.order import O
@@ -470,11 +469,3 @@ def test_issue_2993():
     eq = (2.3*x + 4)
     assert eq**2 == 16.0*(0.575*x + 1)**2
     assert (1/eq).args == (eq, -1)  # don't change trivial power
-
-
-def test_issue_17450():
-    assert (erf(cosh(1)**7)**I).is_real is None
-    assert (erf(cosh(1)**7)**I).is_imaginary is False
-    assert (Pow(exp(1+sqrt(2)), ((1-sqrt(2))*I*pi), evaluate=False)).is_real is None
-    assert ((-10)**(10*I*pi/3)).is_real is False
-    assert ((-5)**(4*I*pi)).is_real is False
diff --git a/sympy/functions/elementary/tests/test_complexes.py b/sympy/functions/elementary/tests/test_complexes.py
index 294a01910a..990e200edd 100644
--- a/sympy/functions/elementary/tests/test_complexes.py
+++ b/sympy/functions/elementary/tests/test_complexes.py
@@ -474,9 +474,6 @@ def test_Abs_rewrite():
     assert Abs(y).rewrite(Piecewise) == Abs(y)
     assert Abs(y).rewrite(sign) == y/sign(y)
 
-    i = Symbol('i', imaginary=True)
-    assert abs(i).rewrite(Piecewise) == Piecewise((I*i, I*i >= 0), (-I*i, True))
-
 
 def test_Abs_real():
     # test some properties of abs that only apply
diff --git a/sympy/functions/elementary/tests/test_trigonometric.py b/sympy/functions/elementary/tests/test_trigonometric.py
index e16312521d..895264e81f 100644
--- a/sympy/functions/elementary/tests/test_trigonometric.py
+++ b/sympy/functions/elementary/tests/test_trigonometric.py
@@ -1067,6 +1067,16 @@ def test_atan2():
     assert str(atan2(1, 2).evalf(5)) == '0.46365'
     raises(ArgumentIndexError, lambda: atan2(x, y).fdiff(3))
 
+def test_issue_17461():
+    class A(Symbol):
+        is_extended_real = True
+
+        def _eval_evalf(self, prec):
+            return Float(5.0)
+
+    x = A('X')
+    y = A('Y')
+    assert abs(atan2(x, y).evalf() - 0.785398163397448) <= 1e-10
 
 def test_acot():
     assert acot(nan) == nan
diff --git a/sympy/plotting/tests/test_plot.py b/sympy/plotting/tests/test_plot.py
index 7836263559..e014c84f0f 100644
--- a/sympy/plotting/tests/test_plot.py
+++ b/sympy/plotting/tests/test_plot.py
@@ -1,6 +1,5 @@
-from sympy import (pi, sin, cos, Symbol, Integral, Sum, sqrt, log, exp, Ne,
-                   oo, LambertW, I, meijerg, exp_polar, Max, Piecewise, And,
-                   real_root)
+from sympy import (pi, sin, cos, Symbol, Integral, Sum, sqrt, log,
+                   oo, LambertW, I, meijerg, exp_polar, Max, Piecewise, And)
 from sympy.plotting import (plot, plot_parametric, plot3d_parametric_line,
                             plot3d, plot3d_parametric_surface)
 from sympy.plotting.plot import unset_show, plot_contour, PlotGrid
@@ -548,39 +547,3 @@ def test_logplot_PR_16796():
     assert len(p[0].get_segments()) >= 30
     assert p[0].end == 100.0
     assert p[0].start == .001
-
-
-def test_issue_16572():
-    matplotlib = import_module('matplotlib', min_module_version='1.1.0', catch=(RuntimeError,))
-    if not matplotlib:
-        skip("Matplotlib not the default backend")
-    x = Symbol('x')
-    p = plot(LambertW(x), show=False)
-    # Random number of segments, probably more than 50, but we want to see
-    # that there are segments generated, as opposed to when the bug was present
-    assert len(p[0].get_segments()) >= 30
-
-
-def test_issue_11865():
-    matplotlib = import_module('matplotlib', min_module_version='1.1.0', catch=(RuntimeError,))
-    if not matplotlib:
-        skip("Matplotlib not the default backend")
-    k = Symbol('k', integer=True)
-    f = Piecewise((-I*exp(I*pi*k)/k + I*exp(-I*pi*k)/k, Ne(k, 0)), (2*pi, True))
-    p = plot(f, show=False)
-    # Random number of segments, probably more than 100, but we want to see
-    # that there are segments generated, as opposed to when the bug was present
-    # and that there are no exceptions.
-    assert len(p[0].get_segments()) >= 30
-
-
-def test_issue_11461():
-    matplotlib = import_module('matplotlib', min_module_version='1.1.0', catch=(RuntimeError,))
-    if not matplotlib:
-        skip("Matplotlib not the default backend")
-    x = Symbol('x')
-    p = plot(real_root((log(x/(x-2))), 3), show=False)
-    # Random number of segments, probably more than 100, but we want to see
-    # that there are segments generated, as opposed to when the bug was present
-    # and that there are no exceptions.
-    assert len(p[0].get_segments()) >= 30
diff --git a/sympy/series/tests/test_limits.py b/sympy/series/tests/test_limits.py
index 14447f1bdd..1869a7247f 100644
--- a/sympy/series/tests/test_limits.py
+++ b/sympy/series/tests/test_limits.py
@@ -575,7 +575,3 @@ def test_issue_15323():
 
 def test_issue_12571():
     assert limit(-LambertW(-log(x))/log(x), x, 1) == 1
-
-
-def test_issue_14590():
-    assert limit((x**3*((x + 1)/x)**x)/((x + 1)*(x + 2)*(x + 3)), x, oo) == exp(1)
diff --git a/sympy/simplify/tests/test_simplify.py b/sympy/simplify/tests/test_simplify.py
index 0b29cabf9f..7ebe3747d0 100644
--- a/sympy/simplify/tests/test_simplify.py
+++ b/sympy/simplify/tests/test_simplify.py
@@ -306,10 +306,6 @@ def test_separatevars():
     s = separatevars(abs(x*y*z))
     assert s == abs(x)*abs(y)*abs(z)
 
-    # abs(x+y)/abs(z) would be better but we test this here to
-    # see that it doesn't raise
-    assert separatevars(abs((x+y)/z)) == abs((x+y)/z)
-
 
 def test_separatevars_advanced_factor():
     x, y, z = symbols('x,y,z')
diff --git a/sympy/solvers/tests/test_solvers.py b/sympy/solvers/tests/test_solvers.py
index 986a6b573e..3a178bcdca 100644
--- a/sympy/solvers/tests/test_solvers.py
+++ b/sympy/solvers/tests/test_solvers.py
@@ -5,7 +5,7 @@
     erfcinv, exp, im, log, pi, re, sec, sin,
     sinh, solve, solve_linear, sqrt, sstr, symbols, sympify, tan, tanh,
     root, simplify, atan2, arg, Mul, SparseMatrix, ask, Tuple, nsolve, oo,
-    E, cbrt, denom, Add, Piecewise)
+    E, cbrt, denom, Add)
 
 from sympy.core.compatibility import range
 from sympy.core.function import nfloat
@@ -1095,16 +1095,6 @@ def s_check(rv, ans):
         165240*x + 61484) + 810]))
 
     assert solve(eq) == [] # not other code errors
-    eq = root(x, 3) - root(y, 3) + root(x, 5)
-    assert check(unrad(eq),
-           (s**15 + 3*s**13 + 3*s**11 + s**9 - y, [s, s**15 - x]))
-    eq = root(x, 3) + root(y, 3) + root(x*y, 4)
-    assert check(unrad(eq),
-                 (s*y*(-s**12 - 3*s**11*y - 3*s**10*y**2 - s**9*y**3 -
-                       3*s**8*y**2 + 21*s**7*y**3 - 3*s**6*y**4 - 3*s**4*y**4 -
-                       3*s**3*y**5 - y**6), [s, s**4 - x*y]))
-    raises(NotImplementedError,
-           lambda: unrad(root(x, 3) + root(y, 3) + root(x*y, 5)))
 
 
 @slow
@@ -2083,17 +2073,6 @@ def test_Abs_handling():
     assert solve(abs(x/y), x) == [0]
 
 
-def test_issue_14645():
-    x, y = symbols('x y')
-    assert solve([x*y - x - y, x*y - x - y], [x, y]) == [(y/(y - 1), y)]
-
-
-def test_issue_12024():
-    x, y = symbols('x y')
-    assert solve(Piecewise((0.0, x < 0.1), (x, x >= 0.1)) - y) == \
-        [{y: Piecewise((0.0, x < 0.1), (x, True))}]
-
-
 def test_issue_17452():
     assert solve((7**x)**x + pi, x) == [-sqrt(log(pi) + I*pi)/sqrt(log(7)),
                                         sqrt(log(pi) + I*pi)/sqrt(log(7))]
diff --git a/sympy/solvers/tests/test_solveset.py b/sympy/solvers/tests/test_solveset.py
index 6cff6431fe..3065d915ea 100644
--- a/sympy/solvers/tests/test_solveset.py
+++ b/sympy/solvers/tests/test_solveset.py
@@ -40,7 +40,7 @@
     solveset, solve_decomposition, substitution, nonlinsolve, solvify,
     _is_finite_with_finite_vars, _transolve, _is_exponential,
     _solve_exponential, _is_logarithmic,
-    _solve_logarithm, _term_factors, _is_modular)
+    _solve_logarithm, _term_factors)
 
 
 a = Symbol('a', real=True)
@@ -2025,150 +2025,3 @@ def test_linear_coeffs():
     raises(ValueError, lambda:
         linear_coeffs(1/x*(x - 1) + 1/x, x))
     assert linear_coeffs(a*(x + y), x, y) == [a, a, 0]
-
-# modular tests
-def test_is_modular():
-    x, y = symbols('x y')
-
-    assert _is_modular(y, x) is False
-    assert _is_modular(Mod(x, 3) - 1, x) is True
-    assert _is_modular(Mod(x**3 - 3*x**2 - x + 1, 3) - 1, x) is True
-    assert _is_modular(Mod(exp(x + y), 3) - 2, x) is True
-    assert _is_modular(Mod(exp(x + y), 3) - log(x), x) is True
-    assert _is_modular(Mod(x, 3) - 1, y) is False
-    assert _is_modular(Mod(x, 3)**2 - 5, x) is False
-    assert _is_modular(Mod(x, 3)**2 - y, x) is False
-    assert _is_modular(exp(Mod(x, 3)) - 1, x) is False
-    assert _is_modular(Mod(3, y) - 1, y) is False
-
-
-def test_invert_modular():
-    x, y = symbols('x y')
-    n = Dummy('n', integer=True)
-    from sympy.solvers.solveset import _invert_modular as invert_modular
-
-    # non invertible cases
-    assert invert_modular(Mod(sin(x), 7), S(5), n, x) == (Mod(sin(x), 7), 5)
-    assert invert_modular(Mod(exp(x), 7), S(5), n, x) == (Mod(exp(x), 7), 5)
-    assert invert_modular(Mod(log(x), 7), S(5), n, x) == (Mod(log(x), 7), 5)
-    # a is symbol
-    assert invert_modular(Mod(x, 7), S(5), n, x) == \
-            (x, ImageSet(Lambda(n, 7*n + 5), S.Integers))
-    # a.is_Add
-    assert invert_modular(Mod(x + 8, 7), S(5), n, x) == \
-            (x, ImageSet(Lambda(n, 7*n + 4), S.Integers))
-    assert invert_modular(Mod(x**2 + x, 7), S(5), n, x) == \
-            (Mod(x**2 + x, 7), 5)
-    # a.is_Mul
-    assert invert_modular(Mod(3*x, 7), S(5), n, x) == \
-            (x, ImageSet(Lambda(n, 7*n + 4), S.Integers))
-    assert invert_modular(Mod((x + 1)*(x + 2), 7), S(5), n, x) == \
-            (Mod((x + 1)*(x + 2), 7), 5)
-    # a.is_Pow
-    assert invert_modular(Mod(x**4, 7), S(5), n, x) == \
-            (x, EmptySet())
-    assert invert_modular(Mod(3**x, 4), S(3), n, x) == \
-            (x, ImageSet(Lambda(n, 2*n + 1), S.Naturals0))
-    assert invert_modular(Mod(2**(x**2 + x + 1), 7), S(2), n, x) == \
-            (x**2 + x + 1, ImageSet(Lambda(n, 3*n + 1), S.Naturals0))
-
-
-def test_solve_modular():
-    x = Symbol('x')
-    n = Dummy('n', integer=True)
-    # if rhs has symbol (need to be implemented in future).
-    assert solveset(Mod(x, 4) - x, x, S.Integers) == \
-            ConditionSet(x, Eq(-x + Mod(x, 4), 0), \
-            S.Integers)
-    # when _invert_modular fails to invert
-    assert solveset(3 - Mod(sin(x), 7), x, S.Integers) == \
-            ConditionSet(x, Eq(Mod(sin(x), 7) - 3, 0), S.Integers)
-    assert solveset(3 - Mod(log(x), 7), x, S.Integers) == \
-            ConditionSet(x, Eq(Mod(log(x), 7) - 3, 0), S.Integers)
-    assert solveset(3 - Mod(exp(x), 7), x, S.Integers) == \
-            ConditionSet(x, Eq(Mod(exp(x), 7) - 3, 0), S.Integers)
-    # EmptySet solution definitely
-    assert solveset(7 - Mod(x, 5), x, S.Integers) == EmptySet()
-    assert solveset(5 - Mod(x, 5), x, S.Integers) == EmptySet()
-    # Negative m
-    assert solveset(2 + Mod(x, -3), x, S.Integers) == \
-            ImageSet(Lambda(n, -3*n - 2), S.Integers)
-    assert solveset(4 + Mod(x, -3), x, S.Integers) == EmptySet()
-    # linear expression in Mod
-    assert solveset(3 - Mod(x, 5), x, S.Integers) == ImageSet(Lambda(n, 5*n + 3), S.Integers)
-    assert solveset(3 - Mod(5*x - 8, 7), x, S.Integers) == \
-                ImageSet(Lambda(n, 7*n + 5), S.Integers)
-    assert solveset(3 - Mod(5*x, 7), x, S.Integers) == \
-                ImageSet(Lambda(n, 7*n + 2), S.Integers)
-    # higher degree expression in Mod
-    assert solveset(Mod(x**2, 160) - 9, x, S.Integers) == \
-            Union(ImageSet(Lambda(n, 160*n + 3), S.Integers),
-            ImageSet(Lambda(n, 160*n + 13), S.Integers),
-            ImageSet(Lambda(n, 160*n + 67), S.Integers),
-            ImageSet(Lambda(n, 160*n + 77), S.Integers),
-            ImageSet(Lambda(n, 160*n + 83), S.Integers),
-            ImageSet(Lambda(n, 160*n + 93), S.Integers),
-            ImageSet(Lambda(n, 160*n + 147), S.Integers),
-            ImageSet(Lambda(n, 160*n + 157), S.Integers))
-    assert solveset(3 - Mod(x**4, 7), x, S.Integers) == EmptySet()
-    assert solveset(Mod(x**4, 17) - 13, x, S.Integers) == \
-            Union(ImageSet(Lambda(n, 17*n + 3), S.Integers),
-            ImageSet(Lambda(n, 17*n + 5), S.Integers),
-            ImageSet(Lambda(n, 17*n + 12), S.Integers),
-            ImageSet(Lambda(n, 17*n + 14), S.Integers))
-    # a.is_Pow tests
-    assert solveset(Mod(7**x, 41) - 15, x, S.Integers) == \
-            ImageSet(Lambda(n, 40*n + 3), S.Naturals0)
-    assert solveset(Mod(12**x, 21) - 18, x, S.Integers) == \
-            ImageSet(Lambda(n, 6*n + 2), S.Naturals0)
-    assert solveset(Mod(3**x, 4) - 3, x, S.Integers) == \
-            ImageSet(Lambda(n, 2*n + 1), S.Naturals0)
-    assert solveset(Mod(2**x, 7) - 2 , x, S.Integers) == \
-            ImageSet(Lambda(n, 3*n + 1), S.Naturals0)
-    assert solveset(Mod(3**(3**x), 4) - 3, x, S.Integers) == \
-            Intersection(ImageSet(Lambda(n, Intersection({log(2*n + 1)/log(3)},
-            S.Integers)), S.Naturals0), S.Integers)
-    # Not Implemented for m without primitive root
-    assert solveset(Mod(x**3, 8) - 1, x, S.Integers) == \
-            ConditionSet(x, Eq(Mod(x**3, 8) - 1, 0), S.Integers)
-    assert solveset(Mod(x**4, 9) - 4, x, S.Integers) == \
-            ConditionSet(x, Eq(Mod(x**4, 9) - 4, 0), S.Integers)
-    # domain intersection
-    assert solveset(3 - Mod(5*x - 8, 7), x, S.Naturals0) == \
-            Intersection(ImageSet(Lambda(n, 7*n + 5), S.Integers), S.Naturals0)
-    # Complex args
-    assert solveset(Mod(x, 3) - I, x, S.Integers) == \
-            EmptySet()
-    assert solveset(Mod(I*x, 3) - 2, x, S.Integers) == \
-            ConditionSet(x, Eq(Mod(I*x, 3) - 2, 0), S.Integers)
-    assert solveset(Mod(I + x, 3) - 2, x, S.Integers) == \
-            ConditionSet(x, Eq(Mod(x + I, 3) - 2, 0), S.Integers)
-    # issue 13178
-    n = symbols('n', integer=True)
-    a = 742938285
-    z = 1898888478
-    m = 2**31 - 1
-    x = 20170816
-    assert solveset(x - Mod(a**n*z, m), n, S.Integers) == \
-            ImageSet(Lambda(n, 2147483646*n + 100), S.Naturals0)
-    assert solveset(x - Mod(a**n*z, m), n, S.Naturals0) == \
-            Intersection(ImageSet(Lambda(n, 2147483646*n + 100), S.Naturals0),
-            S.Naturals0)
-    assert solveset(x - Mod(a**(2*n)*z, m), n, S.Integers) == \
-            Intersection(ImageSet(Lambda(n, 1073741823*n + 50), S.Naturals0),
-            S.Integers)
-    assert solveset(x - Mod(a**(2*n + 7)*z, m), n, S.Integers) == EmptySet()
-    assert solveset(x - Mod(a**(n - 4)*z, m), n, S.Integers) == \
-            Intersection(ImageSet(Lambda(n, 2147483646*n + 104), S.Naturals0),
-            S.Integers)
-
-@XFAIL
-def test_solve_modular_fail():
-    # issue 17373 (https://github.com/sympy/sympy/issues/17373)
-    assert solveset(Mod(x**4, 14) - 11, x, S.Integers) == \
-            Union(ImageSet(Lambda(n, 14*n + 3), S.Integers),
-            ImageSet(Lambda(n, 14*n + 11), S.Integers))
-    assert solveset(Mod(x**31, 74) - 43, x, S.Integers) == \
-            ImageSet(Lambda(n, 74*n + 31), S.Integers)
-
-# end of modular tests