Repository: sympy/sympy

Issue:
Pow._eval_is_ error
```python
>>> i = Dummy(integer=True)
>>> (1/(i-1)).is_finite
True <-- should be None
>>> 1/S(0)
zoo
>>> _.is_finite
False
```

Another inconsistency is
```python
>>> oo/S(0)
oo
>>> 1/S(0)
zoo
```
The change to numbers.py corrects a regression relative to master and adds a test:

```diff
diff --git a/sympy/core/numbers.py b/sympy/core/numbers.py
index 222d379..d7d8ffe 100644
--- a/sympy/core/numbers.py
+++ b/sympy/core/numbers.py
@@ -2613,7 +2613,7 @@ def __neg__():
     def _eval_power(self, expt):
         if expt.is_positive:
             return self
-        if expt.is_negative:
+        if expt.is_extended_negative:
             return S.ComplexInfinity
         if expt.is_extended_real is False:
             return S.NaN
diff --git a/sympy/core/power.py b/sympy/core/power.py
index 6e65cea..8324272 100644
--- a/sympy/core/power.py
+++ b/sympy/core/power.py
@@ -555,12 +555,12 @@ def _eval_is_extended_real(self):
                 if self.exp.is_extended_nonnegative:
                     return True
             else:
-                if self.exp.is_integer:
+                if self.exp.is_integer and self.base.is_zero is not None:
                     return True
                 elif self.base.is_extended_negative:
                     if self.exp.is_Rational:
                         return False
-        if real_e and self.exp.is_extended_negative:
+        if real_e and self.exp.is_extended_negative and self.base.is_zero is not None:
             return Pow(self.base, -self.exp).is_extended_real
         im_b = self.base.is_imaginary
         im_e = self.exp.is_imaginary
@@ -618,7 +618,7 @@ def _eval_is_imaginary(self):
                 rat = self.exp.is_rational
                 if not rat:
                     return rat
-                if self.exp.is_integer:
+                if self.exp.is_integer and self.base.is_zero is not None:
                     return False
                 else:
                     half = (2*self.exp).is_integer
@@ -1244,7 +1244,8 @@ def _is_one(expr):
         elif self.exp.is_rational:
             if self.base.is_algebraic is False:
                 return self.exp.is_zero
-            return self.base.is_algebraic
+            if self.exp.is_extended_negative and self.base.is_zero is False:
+                return self.base.is_algebraic
         elif self.base.is_algebraic and self.exp.is_algebraic:
             if ((fuzzy_not(self.base.is_zero)
                 and fuzzy_not(_is_one(self.base)))
diff --git a/sympy/core/tests/test_numbers.py b/sympy/core/tests/test_numbers.py
index 4d54dfa..6087981 100644
--- a/sympy/core/tests/test_numbers.py
+++ b/sympy/core/tests/test_numbers.py
@@ -1067,7 +1067,7 @@ def test_powers_Integer():
     assert S(-1)** S.Infinity == S.NaN
     assert S(2) ** S.Infinity == S.Infinity
     assert S(-2)** S.Infinity == S.Infinity + S.Infinity * S.ImaginaryUnit
-    assert S(0) ** S.Infinity == 0
+    assert S(0) ** S.NegativeInfinity is S.ComplexInfinity
```

Discussion:

Patch:
diff --git a/sympy/core/power.py b/sympy/core/power.py
index b00014fd39..3cd7f35130 100644
--- a/sympy/core/power.py
+++ b/sympy/core/power.py
@@ -582,16 +582,16 @@ def _eval_is_extended_real(self):
         if real_b and real_e:
             if self.base.is_extended_positive:
                 return True
-            elif self.base.is_extended_nonnegative:
-                if self.exp.is_extended_nonnegative:
-                    return True
-            else:
-                if self.exp.is_integer:
-                    return True
-                elif self.base.is_extended_negative:
-                    if self.exp.is_Rational:
-                        return False
-        if real_e and self.exp.is_extended_negative:
+            elif self.base.is_extended_nonnegative and self.exp.is_extended_nonnegative:
+                return True
+            elif self.exp.is_integer and self.base.is_extended_nonzero:
+                return True
+            elif self.exp.is_integer and self.exp.is_nonnegative:
+                return True
+            elif self.base.is_extended_negative:
+                if self.exp.is_Rational:
+                    return False
+        if real_e and self.exp.is_extended_negative and self.base.is_zero is False:
             return Pow(self.base, -self.exp).is_extended_real
         im_b = self.base.is_imaginary
         im_e = self.exp.is_imaginary
@@ -1279,7 +1279,13 @@ def _is_one(expr):
         elif self.exp.is_rational:
             if self.base.is_algebraic is False:
                 return self.exp.is_zero
-            return self.base.is_algebraic
+            if self.base.is_zero is False:
+                if self.exp.is_nonzero:
+                    return self.base.is_algebraic
+                elif self.base.is_algebraic:
+                    return True
+            if self.exp.is_positive:
+                return self.base.is_algebraic
         elif self.base.is_algebraic and self.exp.is_algebraic:
             if ((fuzzy_not(self.base.is_zero)
                 and fuzzy_not(_is_one(self.base)))
diff --git a/sympy/functions/special/bessel.py b/sympy/functions/special/bessel.py
index 08b3d2bbbd..ef0ee08df2 100644
--- a/sympy/functions/special/bessel.py
+++ b/sympy/functions/special/bessel.py
@@ -993,25 +993,13 @@ def _eval_conjugate(self):
     def _eval_is_extended_real(self):
         return self.args[0].is_extended_real
 
-    def _as_real_imag(self, deep=True, **hints):
-        if self.args[0].is_extended_real:
-            if deep:
-                hints['complex'] = False
-                return (self.expand(deep, **hints), S.Zero)
-            else:
-                return (self, S.Zero)
-        if deep:
-            re, im = self.args[0].expand(deep, **hints).as_real_imag()
-        else:
-            re, im = self.args[0].as_real_imag()
-        return (re, im)
-
     def as_real_imag(self, deep=True, **hints):
-        x, y = self._as_real_imag(deep=deep, **hints)
-        sq = -y**2/x**2
-        re = S.Half*(self.func(x+x*sqrt(sq))+self.func(x-x*sqrt(sq)))
-        im = x/(2*y) * sqrt(sq) * (self.func(x-x*sqrt(sq)) - self.func(x+x*sqrt(sq)))
-        return (re, im)
+        z = self.args[0]
+        zc = z.conjugate()
+        f = self.func
+        u = (f(z)+f(zc))/2
+        v = I*(f(zc)-f(z))/2
+        return u, v
 
     def _eval_expand_complex(self, deep=True, **hints):
         re_part, im_part = self.as_real_imag(deep=deep, **hints)
diff --git a/sympy/functions/special/elliptic_integrals.py b/sympy/functions/special/elliptic_integrals.py
index d713a2feb8..adee570a6c 100644
--- a/sympy/functions/special/elliptic_integrals.py
+++ b/sympy/functions/special/elliptic_integrals.py
@@ -94,12 +94,6 @@ def _eval_is_zero(self):
         if m.is_infinite:
             return True
 
-    def _eval_rewrite_as_Integral(self, *args):
-        from sympy import Integral, Dummy
-        t = Dummy('t')
-        m = self.args[0]
-        return Integral(1/sqrt(1 - m*sin(t)**2), (t, 0, pi/2))
-
     def _sage_(self):
         import sage.all as sage
         return sage.elliptic_kc(self.args[0]._sage_())
@@ -173,12 +167,6 @@ def _eval_conjugate(self):
         if (m.is_real and (m - 1).is_positive) is False:
             return self.func(z.conjugate(), m.conjugate())
 
-    def _eval_rewrite_as_Integral(self, *args):
-        from sympy import Integral, Dummy
-        t = Dummy('t')
-        z, m = self.args[0], self.args[1]
-        return Integral(1/(sqrt(1 - m*sin(t)**2)), (t, 0, z))
-
     def _eval_is_zero(self):
         z, m = self.args
         if z.is_zero:
@@ -299,12 +287,6 @@ def _eval_rewrite_as_meijerg(self, *args, **kwargs):
             return -meijerg(((S.Half, Rational(3, 2)), []), \
                             ((S.Zero,), (S.Zero,)), -m)/4
 
-    def _eval_rewrite_as_Integral(self, *args):
-        from sympy import Integral, Dummy
-        z, m = (pi/2, self.args[0]) if len(self.args) == 1 else self.args
-        t = Dummy('t')
-        return Integral(sqrt(1 - m*sin(t)**2), (t, 0, z))
-
 
 class elliptic_pi(Function):
     r"""
@@ -430,12 +412,3 @@ def fdiff(self, argindex=1):
             elif argindex == 2:
                 return (elliptic_e(m)/(m - 1) + elliptic_pi(n, m))/(2*(n - m))
         raise ArgumentIndexError(self, argindex)
-
-    def _eval_rewrite_as_Integral(self, *args):
-        from sympy import Integral, Dummy
-        if len(self.args) == 2:
-            n, m, z = self.args[0], self.args[1], pi/2
-        else:
-            n, z, m = self.args
-        t = Dummy('t')
-        return Integral(1/((1 - n*sin(t)**2)*sqrt(1 - m*sin(t)**2)), (t, 0, z))
diff --git a/sympy/polys/polyroots.py b/sympy/polys/polyroots.py
index edc9b639e9..4c0a00276a 100644
--- a/sympy/polys/polyroots.py
+++ b/sympy/polys/polyroots.py
@@ -1031,7 +1031,7 @@ def _try_heuristics(f):
         handlers = {
             'Z': lambda r: r.is_Integer,
             'Q': lambda r: r.is_Rational,
-            'R': lambda r: r.is_extended_real,
+            'R': lambda r: all(a.is_real for a in r.as_numer_denom()),
             'I': lambda r: r.is_imaginary,
         }
 
diff --git a/sympy/printing/pycode.py b/sympy/printing/pycode.py
index 1c981e9a61..8b4d27e8b5 100644
--- a/sympy/printing/pycode.py
+++ b/sympy/printing/pycode.py
@@ -501,14 +501,7 @@ def pycode(expr, **settings):
     'sign': 'sign',
 })
 _known_constants_mpmath = {
-    'Exp1': 'e',
-    'Pi': 'pi',
-    'GoldenRatio': 'phi',
-    'EulerGamma': 'euler',
-    'Catalan': 'catalan',
-    'NaN': 'nan',
-    'Infinity': 'inf',
-    'NegativeInfinity': 'ninf'
+    'Pi': 'pi'
 }
 
 
@@ -524,7 +517,6 @@ class MpmathPrinter(PythonCodePrinter):
         _known_functions.items(),
         [(k, 'mpmath.' + v) for k, v in _known_functions_mpmath.items()]
     ))
-    _kc = {k: 'mpmath.'+v for k, v in _known_constants_mpmath.items()}
 
     def _print_Float(self, e):
         # XXX: This does not handle setting mpmath.mp.dps. It is assumed that
@@ -591,14 +583,6 @@ def _print_Pow(self, expr, rational=False):
     'exp2': 'exp2',
     'sign': 'sign',
 })
-_known_constants_numpy = {
-    'Exp1': 'e',
-    'Pi': 'pi',
-    'EulerGamma': 'euler_gamma',
-    'NaN': 'nan',
-    'Infinity': 'PINF',
-    'NegativeInfinity': 'NINF'
-}
 
 
 class NumPyPrinter(PythonCodePrinter):
@@ -613,7 +597,7 @@ class NumPyPrinter(PythonCodePrinter):
         PythonCodePrinter._kf.items(),
         [(k, 'numpy.' + v) for k, v in _known_functions_numpy.items()]
     ))
-    _kc = {k: 'numpy.'+v for k, v in _known_constants_numpy.items()}
+    _kc = {k: 'numpy.'+v for k, v in _known_constants_math.items()}
 
 
     def _print_seq(self, seq):
@@ -666,9 +650,7 @@ def _print_Piecewise(self, expr):
         #     it will behave the same as passing the 'default' kwarg to select()
         #     *as long as* it is the last element in expr.args.
         # If this is not the case, it may be triggered prematurely.
-        return '{0}({1}, {2}, default={3})'.format(
-            self._module_format('numpy.select'), conds, exprs,
-            self._print(S.NaN))
+        return '{0}({1}, {2}, default=numpy.nan)'.format(self._module_format('numpy.select'), conds, exprs)
 
     def _print_Relational(self, expr):
         "Relational printer for Equality and Unequality"
@@ -851,6 +833,8 @@ def _print_CodegenArrayElementwiseAdd(self, expr):
 _known_constants_scipy_constants = {
     'GoldenRatio': 'golden_ratio',
     'Pi': 'pi',
+    'E': 'e',
+    'Exp1': 'e'
 }
 
 class SciPyPrinter(NumPyPrinter):
@@ -861,10 +845,7 @@ class SciPyPrinter(NumPyPrinter):
         NumPyPrinter._kf.items(),
         [(k, 'scipy.special.' + v) for k, v in _known_functions_scipy_special.items()]
     ))
-    _kc =dict(chain(
-        NumPyPrinter._kc.items(),
-        [(k, 'scipy.constants.' + v) for k, v in _known_constants_scipy_constants.items()]
-    ))
+    _kc = {k: 'scipy.constants.' + v for k, v in _known_constants_scipy_constants.items()}
 
     def _print_SparseMatrix(self, expr):
         i, j, data = [], [], []


Test patch:
diff --git a/sympy/core/tests/test_arit.py b/sympy/core/tests/test_arit.py
index 6e2e32a74e..077bda8681 100644
--- a/sympy/core/tests/test_arit.py
+++ b/sympy/core/tests/test_arit.py
@@ -1036,6 +1036,10 @@ def test_Pow_is_real():
 
     assert sqrt(-I).is_real is False  # issue 7843
 
+    i = Symbol('i', integer=True)
+    assert (1/(i-1)).is_real is None
+    assert (1/(i-1)).is_extended_real is None
+
 
 def test_real_Pow():
     k = Symbol('k', integer=True, nonzero=True)
@@ -1047,6 +1051,7 @@ def test_Pow_is_finite():
     xr = Symbol('xr', real=True)
     p = Symbol('p', positive=True)
     n = Symbol('n', negative=True)
+    i = Symbol('i', integer=True)
 
     assert (xe**2).is_finite is None  # xe could be oo
     assert (xr**2).is_finite is True
@@ -1082,6 +1087,7 @@ def test_Pow_is_finite():
 
     assert (1/S.Pi).is_finite is True
 
+    assert (1/(i-1)).is_finite is None
 
 def test_Pow_is_even_odd():
     x = Symbol('x')
@@ -1243,8 +1249,10 @@ def test_Pow_is_nonpositive_nonnegative():
     assert (I**i).is_nonnegative is True
     assert (exp(I)**i).is_nonnegative is True
 
-    assert ((-k)**n).is_nonnegative is True
-    assert ((-k)**m).is_nonpositive is True
+    assert ((-l)**n).is_nonnegative is True
+    assert ((-l)**m).is_nonpositive is True
+    assert ((-k)**n).is_nonnegative is None
+    assert ((-k)**m).is_nonpositive is None
 
 
 def test_Mul_is_imaginary_real():
diff --git a/sympy/core/tests/test_assumptions.py b/sympy/core/tests/test_assumptions.py
index 7ce50b8024..0e7958cfd6 100644
--- a/sympy/core/tests/test_assumptions.py
+++ b/sympy/core/tests/test_assumptions.py
@@ -799,12 +799,12 @@ def test_Add_is_algebraic():
 
 def test_Mul_is_algebraic():
     a = Symbol('a', algebraic=True)
-    b = Symbol('a', algebraic=True)
+    b = Symbol('b', algebraic=True)
     na = Symbol('na', algebraic=False)
     an = Symbol('an', algebraic=True, nonzero=True)
     nb = Symbol('nb', algebraic=False)
     x = Symbol('x')
-    assert (a*b).is_algebraic
+    assert (a*b).is_algebraic is True
     assert (na*nb).is_algebraic is None
     assert (a*na).is_algebraic is None
     assert (an*na).is_algebraic is False
@@ -819,15 +819,18 @@ def test_Pow_is_algebraic():
     assert Pow(0, e, evaluate=False).is_algebraic
 
     a = Symbol('a', algebraic=True)
+    azf = Symbol('azf', algebraic=True, zero=False)
     na = Symbol('na', algebraic=False)
     ia = Symbol('ia', algebraic=True, irrational=True)
     ib = Symbol('ib', algebraic=True, irrational=True)
     r = Symbol('r', rational=True)
     x = Symbol('x')
-    assert (a**r).is_algebraic
+    assert (a**2).is_algebraic is True
+    assert (a**r).is_algebraic is None
+    assert (azf**r).is_algebraic is True
     assert (a**x).is_algebraic is None
     assert (na**r).is_algebraic is None
-    assert (ia**r).is_algebraic
+    assert (ia**r).is_algebraic is True
     assert (ia**ib).is_algebraic is False
 
     assert (a**e).is_algebraic is None
diff --git a/sympy/functions/special/tests/test_bessel.py b/sympy/functions/special/tests/test_bessel.py
index 093ac02a3c..ee6b18d491 100644
--- a/sympy/functions/special/tests/test_bessel.py
+++ b/sympy/functions/special/tests/test_bessel.py
@@ -414,9 +414,8 @@ def test_airy_base():
     assert airyai(x).is_extended_real
 
     assert airyai(x+I*y).as_real_imag() == (
-        airyai(x - I*x*Abs(y)/Abs(x))/2 + airyai(x + I*x*Abs(y)/Abs(x))/2,
-        I*x*(airyai(x - I*x*Abs(y)/Abs(x)) -
-             airyai(x + I*x*Abs(y)/Abs(x)))*Abs(y)/(2*y*Abs(x)))
+            airyai(x - I*y)/2 + airyai(x + I*y)/2,
+            I*(airyai(x - I*y) - airyai(x + I*y))/2)
 
 
 def test_airyai():
diff --git a/sympy/functions/special/tests/test_elliptic_integrals.py b/sympy/functions/special/tests/test_elliptic_integrals.py
index d9bb826110..98626d47cc 100644
--- a/sympy/functions/special/tests/test_elliptic_integrals.py
+++ b/sympy/functions/special/tests/test_elliptic_integrals.py
@@ -1,5 +1,5 @@
 from sympy import (S, Symbol, pi, I, oo, zoo, sin, sqrt, tan, gamma,
-    atanh, hyper, meijerg, O, Dummy, Integral, Rational)
+    atanh, hyper, meijerg, O, Rational)
 from sympy.functions.special.elliptic_integrals import (elliptic_k as K,
     elliptic_f as F, elliptic_e as E, elliptic_pi as P)
 from sympy.utilities.randtest import (test_derivative_numerically as td,
@@ -9,7 +9,6 @@
 
 i = Symbol('i', integer=True)
 j = Symbol('k', integer=True, positive=True)
-t = Dummy('t')
 
 def test_K():
     assert K(0) == pi/2
@@ -40,8 +39,6 @@ def test_K():
     assert K(z).series(z) == pi/2 + pi*z/8 + 9*pi*z**2/128 + \
         25*pi*z**3/512 + 1225*pi*z**4/32768 + 3969*pi*z**5/131072 + O(z**6)
 
-    assert K(m).rewrite(Integral).dummy_eq(
-        Integral(1/sqrt(1 - m*sin(t)**2), (t, 0, pi/2)))
 
 def test_F():
     assert F(z, 0) == z
@@ -67,8 +64,6 @@ def test_F():
     assert F(z, m).series(z) == \
         z + z**5*(3*m**2/40 - m/30) + m*z**3/6 + O(z**6)
 
-    assert F(z, m).rewrite(Integral).dummy_eq(
-        Integral(1/sqrt(1 - m*sin(t)**2), (t, 0, z)))
 
 def test_E():
     assert E(z, 0) == z
@@ -110,10 +105,6 @@ def test_E():
     assert E(z).series(z) == pi/2 - pi*z/8 - 3*pi*z**2/128 - \
         5*pi*z**3/512 - 175*pi*z**4/32768 - 441*pi*z**5/131072 + O(z**6)
 
-    assert E(z, m).rewrite(Integral).dummy_eq(
-        Integral(sqrt(1 - m*sin(t)**2), (t, 0, z)))
-    assert E(m).rewrite(Integral).dummy_eq(
-        Integral(sqrt(1 - m*sin(t)**2), (t, 0, pi/2)))
 
 def test_P():
     assert P(0, z, m) == F(z, m)
@@ -159,8 +150,3 @@ def test_P():
 
     assert P(n, z, m).series(z) == z + z**3*(m/6 + n/3) + \
         z**5*(3*m**2/40 + m*n/10 - m/30 + n**2/5 - n/15) + O(z**6)
-
-    assert P(n, z, m).rewrite(Integral).dummy_eq(
-        Integral(1/((1 - n*sin(t)**2)*sqrt(1 - m*sin(t)**2)), (t, 0, z)))
-    assert P(n, m).rewrite(Integral).dummy_eq(
-        Integral(1/((1 - n*sin(t)**2)*sqrt(1 - m*sin(t)**2)), (t, 0, pi/2)))
diff --git a/sympy/polys/tests/test_polyroots.py b/sympy/polys/tests/test_polyroots.py
index 0b8b087d05..617ce3fc84 100644
--- a/sympy/polys/tests/test_polyroots.py
+++ b/sympy/polys/tests/test_polyroots.py
@@ -478,6 +478,10 @@ def test_roots0():
     assert roots(x**4 - 1, x, filter='Z', multiple=True) == [-S.One, S.One]
     assert roots(x**4 - 1, x, filter='I', multiple=True) == [I, -I]
 
+    ar, br = symbols('a, b', real=True)
+    p = x**2*(ar-br)**2 + 2*x*(br-ar) + 1
+    assert roots(p, x, filter='R') == {1/(ar - br): 2}
+
     assert roots(x**3, x, multiple=True) == [S.Zero, S.Zero, S.Zero]
     assert roots(1234, x, multiple=True) == []
 
diff --git a/sympy/printing/tests/test_numpy.py b/sympy/printing/tests/test_numpy.py
index 4a4a71c3eb..db42d056a0 100644
--- a/sympy/printing/tests/test_numpy.py
+++ b/sympy/printing/tests/test_numpy.py
@@ -17,18 +17,14 @@
 
 np = import_module('numpy')
 
-
 def test_numpy_piecewise_regression():
     """
     NumPyPrinter needs to print Piecewise()'s choicelist as a list to avoid
     breaking compatibility with numpy 1.8. This is not necessary in numpy 1.9+.
     See gh-9747 and gh-9749 for details.
     """
-    printer = NumPyPrinter()
     p = Piecewise((1, x < 0), (0, True))
-    assert printer.doprint(p) == \
-        'numpy.select([numpy.less(x, 0),True], [1,0], default=numpy.nan)'
-    assert printer.module_imports == {'numpy': {'select', 'less', 'nan'}}
+    assert NumPyPrinter().doprint(p) == 'numpy.select([numpy.less(x, 0),True], [1,0], default=numpy.nan)'
 
 
 def test_sum():
diff --git a/sympy/printing/tests/test_pycode.py b/sympy/printing/tests/test_pycode.py
index 5af53b0ee5..b2d3fd554e 100644
--- a/sympy/printing/tests/test_pycode.py
+++ b/sympy/printing/tests/test_pycode.py
@@ -6,7 +6,6 @@
 from sympy.codegen.matrix_nodes import MatrixSolve
 from sympy.core import Expr, Mod, symbols, Eq, Le, Gt, zoo, oo, Rational
 from sympy.core.numbers import pi
-from sympy.core.singleton import S
 from sympy.functions import acos, Piecewise, sign, sqrt
 from sympy.logic import And, Or
 from sympy.matrices import SparseMatrix, MatrixSymbol, Identity
@@ -66,15 +65,6 @@ def test_MpmathPrinter():
     assert p.doprint(sign(x)) == 'mpmath.sign(x)'
     assert p.doprint(Rational(1, 2)) == 'mpmath.mpf(1)/mpmath.mpf(2)'
 
-    assert p.doprint(S.Exp1) == 'mpmath.e'
-    assert p.doprint(S.Pi) == 'mpmath.pi'
-    assert p.doprint(S.GoldenRatio) == 'mpmath.phi'
-    assert p.doprint(S.EulerGamma) == 'mpmath.euler'
-    assert p.doprint(S.NaN) == 'mpmath.nan'
-    assert p.doprint(S.Infinity) == 'mpmath.inf'
-    assert p.doprint(S.NegativeInfinity) == 'mpmath.ninf'
-
-
 def test_NumPyPrinter():
     p = NumPyPrinter()
     assert p.doprint(sign(x)) == 'numpy.sign(x)'
@@ -91,13 +81,6 @@ def test_NumPyPrinter():
     assert p.doprint(x**-1) == 'x**(-1.0)'
     assert p.doprint(x**-2) == 'x**(-2.0)'
 
-    assert p.doprint(S.Exp1) == 'numpy.e'
-    assert p.doprint(S.Pi) == 'numpy.pi'
-    assert p.doprint(S.EulerGamma) == 'numpy.euler_gamma'
-    assert p.doprint(S.NaN) == 'numpy.nan'
-    assert p.doprint(S.Infinity) == 'numpy.PINF'
-    assert p.doprint(S.NegativeInfinity) == 'numpy.NINF'
-
 
 def test_SciPyPrinter():
     p = SciPyPrinter()
@@ -110,10 +93,6 @@ def test_SciPyPrinter():
     assert p.doprint(smat) == 'scipy.sparse.coo_matrix([3], ([0], [1]), shape=(2, 5))'
     assert 'scipy.sparse' in p.module_imports
 
-    assert p.doprint(S.GoldenRatio) == 'scipy.constants.golden_ratio'
-    assert p.doprint(S.Pi) == 'scipy.constants.pi'
-    assert p.doprint(S.Exp1) == 'numpy.e'
-
 
 def test_pycode_reserved_words():
     s1, s2 = symbols('if else')
diff --git a/sympy/solvers/tests/test_solveset.py b/sympy/solvers/tests/test_solveset.py
index 0c68d73f4c..a96fb8c26e 100644
--- a/sympy/solvers/tests/test_solveset.py
+++ b/sympy/solvers/tests/test_solveset.py
@@ -274,7 +274,10 @@ def test_garbage_input():
 
 def test_solve_mul():
     assert solveset_real((a*x + b)*(exp(x) - 3), x) == \
-        FiniteSet(-b/a, log(3))
+        Union({log(3)}, Intersection({-b/a}, S.Reals))
+    anz = Symbol('anz', nonzero=True)
+    assert solveset_real((anz*x + b)*(exp(x) - 3), x) == \
+        FiniteSet(-b/anz, log(3))
     assert solveset_real((2*x + 8)*(8 + exp(x)), x) == FiniteSet(S(-4))
     assert solveset_real(x/log(x), x) == EmptySet()
 
@@ -1718,6 +1721,12 @@ def test_issue_14987():
 def test_simplification():
     eq = x + (a - b)/(-2*a + 2*b)
     assert solveset(eq, x) == FiniteSet(S.Half)
+    assert solveset(eq, x, S.Reals) == Intersection({-((a - b)/(-2*a + 2*b))}, S.Reals)
+    # So that ap - bn is not zero:
+    ap = Symbol('ap', positive=True)
+    bn = Symbol('bn', negative=True)
+    eq = x + (ap - bn)/(-2*ap + 2*bn)
+    assert solveset(eq, x) == FiniteSet(S.Half)
     assert solveset(eq, x, S.Reals) == FiniteSet(S.Half)
 
 
@@ -1981,11 +1990,10 @@ def test_exponential_symbols():
     w = symbols('w')
     f1 = 2*x**w - 4*y**w
     f2 = (x/y)**w - 2
-    ans1 = solveset(f1, w, S.Reals)
-    ans2 = solveset(f2, w, S.Reals)
-    assert len(ans1) == len(ans2) == 1
-    a1, a2 = [list(i)[0] for i in (ans1, ans2)]
-    assert a1.equals(a2)
+    sol1 = Intersection({log(2)/(log(x) - log(y))}, S.Reals)
+    sol2 = Intersection({log(2)/log(x/y)}, S.Reals)
+    assert solveset(f1, w, S.Reals) == sol1
+    assert solveset(f2, w, S.Reals) == sol2
 
     assert solveset(x**x, x, S.Reals) == S.EmptySet
     assert solveset(x**y - 1, y, S.Reals) == FiniteSet(0)
diff --git a/sympy/utilities/tests/test_wester.py b/sympy/utilities/tests/test_wester.py
index 954e8543ca..6529f24731 100644
--- a/sympy/utilities/tests/test_wester.py
+++ b/sympy/utilities/tests/test_wester.py
@@ -1381,7 +1381,7 @@ def test_P8():
 
 
 def test_P9():
-    a, b, c = symbols('a b c', real=True)
+    a, b, c = symbols('a b c', nonzero=True)
     M = Matrix([[a/(b*c), 1/c, 1/b],
                 [1/c, b/(a*c), 1/a],
                 [1/b, 1/a, c/(a*b)]])