Repository: sympy/sympy

Issue:
If t is transcendental, t**n is determined (wrongly) to be non-integer
Check this:
```python
>>> t = Symbol('t', real=True, transcendental=True)
>>> n = n = Symbol('n', integer=True)  # may be 0
>>> (t**n).is_algebraic  # should be None, as n may be 0
False
>>> (t**n).is_integer  # should be None, as n may be 0
False
```
etc.

Discussion:
asmeurer: Just the one comment. Looks good otherwise. 
AnishShah: @asmeurer I have updated the PR. Can you cancel the old Travis CI for this PR?

Patch:
diff --git a/sympy/assumptions/refine.py b/sympy/assumptions/refine.py
index fd9d5e9108..bdb82f5d85 100644
--- a/sympy/assumptions/refine.py
+++ b/sympy/assumptions/refine.py
@@ -16,11 +16,12 @@ def refine(expr, assumptions=True):
     Examples
     ========
 
-        >>> from sympy import refine, sqrt, Q
-        >>> from sympy.abc import x
-        >>> refine(sqrt(x**2), Q.real(x))
+        >>> from sympy import Symbol, refine, sqrt, Q
+        >>> x = Symbol('x', real=True)
+        >>> refine(sqrt(x**2))
         Abs(x)
-        >>> refine(sqrt(x**2), Q.positive(x))
+        >>> x = Symbol('x', positive=True)
+        >>> refine(sqrt(x**2))
         x
 
     """
@@ -46,32 +47,6 @@ def refine(expr, assumptions=True):
     return refine(new_expr, assumptions)
 
 
-def refine_abs(expr, assumptions):
-    """
-    Handler for the absolute value.
-
-    Examples
-    ========
-
-    >>> from sympy import Symbol, Q, refine, Abs
-    >>> from sympy.assumptions.refine import refine_abs
-    >>> from sympy.abc import x
-    >>> refine_abs(Abs(x), Q.real(x))
-    >>> refine_abs(Abs(x), Q.positive(x))
-    x
-    >>> refine_abs(Abs(x), Q.negative(x))
-    -x
-
-    """
-    arg = expr.args[0]
-    if ask(Q.real(arg), assumptions) and \
-            fuzzy_not(ask(Q.negative(arg), assumptions)):
-        # if it's nonnegative
-        return arg
-    if ask(Q.negative(arg), assumptions):
-        return -arg
-
-
 def refine_Pow(expr, assumptions):
     """
     Handler for instances of Pow.
@@ -230,7 +205,6 @@ def refine_Relational(expr, assumptions):
 
 
 handlers_dict = {
-    'Abs': refine_abs,
     'Pow': refine_Pow,
     'atan2': refine_atan2,
     'Equality': refine_Relational,
diff --git a/sympy/core/basic.py b/sympy/core/basic.py
index 502a3adb8e..9699c354db 100644
--- a/sympy/core/basic.py
+++ b/sympy/core/basic.py
@@ -1635,6 +1635,7 @@ def class_key(cls):
 
     @cacheit
     def sort_key(self, order=None):
+        from sympy.core import S
         return self.class_key(), (1, (str(self),)), S.One.sort_key(), S.One
 
     def _eval_simplify(self, ratio, measure):
diff --git a/sympy/core/compatibility.py b/sympy/core/compatibility.py
index ffcf6c5e01..702a02cfc6 100644
--- a/sympy/core/compatibility.py
+++ b/sympy/core/compatibility.py
@@ -522,10 +522,9 @@ def default_sort_key(item, order=None):
 
     """
 
-    from .singleton import S
-    from .basic import Basic
-    from .sympify import sympify, SympifyError
-    from .compatibility import iterable
+    from sympy.core import S, Basic
+    from sympy.core.sympify import sympify, SympifyError
+    from sympy.core.compatibility import iterable
 
     if isinstance(item, Basic):
         return item.sort_key(order=order)
diff --git a/sympy/core/expr.py b/sympy/core/expr.py
index 50f1532a28..32954b2e7a 100644
--- a/sympy/core/expr.py
+++ b/sympy/core/expr.py
@@ -909,9 +909,8 @@ def as_ordered_terms(self, order=None, data=False):
 
     def as_terms(self):
         """Transform an expression to a list of terms. """
-        from .add import Add
-        from .mul import Mul
-        from .exprtools import decompose_power
+        from sympy.core import Add, Mul, S
+        from sympy.core.exprtools import decompose_power
 
         gens, terms = set([]), []
 
diff --git a/sympy/core/power.py b/sympy/core/power.py
index a3d5fa68da..0398d44098 100644
--- a/sympy/core/power.py
+++ b/sympy/core/power.py
@@ -229,7 +229,7 @@ def _eval_refine(self):
                 return -Pow(-b, e)
 
     def _eval_power(self, other):
-        from sympy import Abs, arg, exp, floor, im, log, re, sign
+        from sympy import Abs, arg, exp, floor, im, log, re, sign, refine
         b, e = self.as_base_exp()
         if b is S.NaN:
             return (b**e)**other  # let __new__ handle it
@@ -273,9 +273,9 @@ def _n2(e):
                             return Pow(b.conjugate()/Abs(b)**2, other)
                 elif e.is_even:
                     if b.is_real:
-                        b = abs(b)
+                        b = refine(abs(b))
                     if b.is_imaginary:
-                        b = abs(im(b))*S.ImaginaryUnit
+                        b = refine(abs(im(b)))*S.ImaginaryUnit
 
                 if (abs(e) < 1) == True or (e == 1) == True:
                     s = 1  # floor = 0
@@ -1027,6 +1027,8 @@ def _eval_is_algebraic(self):
         if self.base.is_zero or (self.base - 1).is_zero:
             return True
         elif self.exp.is_rational:
+            if self.base.is_algebraic is False:
+                return self.exp.is_nonzero
             return self.base.is_algebraic
         elif self.base.is_algebraic and self.exp.is_algebraic:
             if ((fuzzy_not(self.base.is_zero)
diff --git a/sympy/functions/elementary/complexes.py b/sympy/functions/elementary/complexes.py
index bc4190bd41..6afd10154a 100644
--- a/sympy/functions/elementary/complexes.py
+++ b/sympy/functions/elementary/complexes.py
@@ -427,6 +427,29 @@ def fdiff(self, argindex=1):
         else:
             raise ArgumentIndexError(self, argindex)
 
+    def _eval_refine(self):
+        arg = self.args[0]
+        if arg.is_zero:
+            return S.Zero
+        if arg.is_nonnegative:
+            return arg
+        if arg.is_nonpositive:
+            return -arg
+        if arg.is_Add:
+            expr_list = []
+            for _arg in Add.make_args(arg):
+                if _arg.is_negative or _arg.is_negative is None:
+                    return None
+                if _arg.is_zero:
+                    expr_list.append(S.Zero)
+                elif _arg.is_nonnegative:
+                    expr_list.append(_arg)
+                elif _arg.is_nonpositive:
+                    expr_list.append(-_arg)
+            if expr_list:
+                return Add(*expr_list)
+            return arg
+
     @classmethod
     def eval(cls, arg):
         from sympy.simplify.simplify import signsimp
@@ -444,7 +467,7 @@ def eval(cls, arg):
         if arg.is_Mul:
             known = []
             unk = []
-            for t in arg.args:
+            for t in Mul.make_args(arg):
                 tnew = cls(t)
                 if tnew.func is cls:
                     unk.append(tnew.args[0])
diff --git a/sympy/matrices/dense.py b/sympy/matrices/dense.py
index ba24f4d013..baee02a542 100644
--- a/sympy/matrices/dense.py
+++ b/sympy/matrices/dense.py
@@ -554,18 +554,10 @@ def __rsub__(self, other):
     def __mul__(self, other):
         return super(DenseMatrix, self).__mul__(_force_mutable(other))
 
-    @call_highest_priority('__rmul__')
-    def __matmul__(self, other):
-        return super(DenseMatrix, self).__mul__(_force_mutable(other))
-
     @call_highest_priority('__mul__')
     def __rmul__(self, other):
         return super(DenseMatrix, self).__rmul__(_force_mutable(other))
 
-    @call_highest_priority('__mul__')
-    def __rmatmul__(self, other):
-        return super(DenseMatrix, self).__rmul__(_force_mutable(other))
-
     @call_highest_priority('__div__')
     def __div__(self, other):
         return super(DenseMatrix, self).__div__(_force_mutable(other))
diff --git a/sympy/matrices/expressions/matexpr.py b/sympy/matrices/expressions/matexpr.py
index 706c578d74..de13236cc2 100644
--- a/sympy/matrices/expressions/matexpr.py
+++ b/sympy/matrices/expressions/matexpr.py
@@ -105,21 +105,11 @@ def __rsub__(self, other):
     def __mul__(self, other):
         return MatMul(self, other).doit()
 
-    @_sympifyit('other', NotImplemented)
-    @call_highest_priority('__rmul__')
-    def __matmul__(self, other):
-        return MatMul(self, other).doit()
-
     @_sympifyit('other', NotImplemented)
     @call_highest_priority('__mul__')
     def __rmul__(self, other):
         return MatMul(other, self).doit()
 
-    @_sympifyit('other', NotImplemented)
-    @call_highest_priority('__mul__')
-    def __rmatmul__(self, other):
-        return MatMul(other, self).doit()
-
     @_sympifyit('other', NotImplemented)
     @call_highest_priority('__rpow__')
     def __pow__(self, other):
diff --git a/sympy/matrices/immutable.py b/sympy/matrices/immutable.py
index 9a34473005..502e7980f0 100644
--- a/sympy/matrices/immutable.py
+++ b/sympy/matrices/immutable.py
@@ -106,9 +106,7 @@ def _eval_Eq(self, other):
     __add__ = MatrixBase.__add__
     __radd__ = MatrixBase.__radd__
     __mul__ = MatrixBase.__mul__
-    __matmul__ = MatrixBase.__matmul__
     __rmul__ = MatrixBase.__rmul__
-    __rmatmul__ = MatrixBase.__rmatmul__
     __pow__ = MatrixBase.__pow__
     __sub__ = MatrixBase.__sub__
     __rsub__ = MatrixBase.__rsub__
diff --git a/sympy/matrices/matrices.py b/sympy/matrices/matrices.py
index 8b1d5def3a..0a61971a3e 100644
--- a/sympy/matrices/matrices.py
+++ b/sympy/matrices/matrices.py
@@ -513,15 +513,11 @@ def __mul__(self, other):
             return self._new(self.rows, self.cols,
                 [i*other for i in self._mat])
 
-    __matmul__ = __mul__
-
     def __rmul__(self, a):
         if getattr(a, 'is_Matrix', False):
             return self._new(a)*self
         return self._new(self.rows, self.cols, [a*i for i in self._mat])
 
-    __rmatmul__ = __rmul__
-
     def __pow__(self, num):
         from sympy.matrices import eye, diag, MutableMatrix
         from sympy import binomial
diff --git a/sympy/matrices/sparse.py b/sympy/matrices/sparse.py
index 4528f1cd34..e14f5b47e0 100644
--- a/sympy/matrices/sparse.py
+++ b/sympy/matrices/sparse.py
@@ -395,8 +395,6 @@ def __mul__(self, other):
             return other._new(self*self._new(other))
         return self.scalar_multiply(other)
 
-    __matmul__ = __mul__
-
     def __rmul__(self, other):
         """Return product the same type as other (if a Matrix).
 
@@ -419,8 +417,6 @@ def __rmul__(self, other):
             return other*other._new(self)
         return self.scalar_multiply(other)
 
-    __rmatmul__ = __rmul__
-
     def __add__(self, other):
         """Add other to self, efficiently if possible.
 


Test patch:
diff --git a/sympy/assumptions/tests/test_refine.py b/sympy/assumptions/tests/test_refine.py
index ce94837680..831401071a 100644
--- a/sympy/assumptions/tests/test_refine.py
+++ b/sympy/assumptions/tests/test_refine.py
@@ -6,40 +6,57 @@
 
 
 def test_Abs():
-    assert refine(Abs(x), Q.positive(x)) == x
-    assert refine(1 + Abs(x), Q.positive(x)) == 1 + x
-    assert refine(Abs(x), Q.negative(x)) == -x
-    assert refine(1 + Abs(x), Q.negative(x)) == 1 - x
-
+    x = Symbol('x', positive=True)
+    assert Abs(x) == x
+    assert 1 + Abs(x) == 1 + x
+    x = Symbol('x', negative=True)
+    assert Abs(x) == -x
+    assert 1 + Abs(x) == 1 - x
+    x = Symbol('x')
     assert refine(Abs(x**2)) != x**2
-    assert refine(Abs(x**2), Q.real(x)) == x**2
+    x = Symbol('x', real=True)
+    assert refine(Abs(x**2)) == x**2
 
 
 def test_pow():
-    assert refine((-1)**x, Q.even(x)) == 1
-    assert refine((-1)**x, Q.odd(x)) == -1
-    assert refine((-2)**x, Q.even(x)) == 2**x
+    x = Symbol('x', even=True)
+    assert refine((-1)**x) == 1
+    x = Symbol('x', odd=True)
+    assert refine((-1)**x) == -1
+    x = Symbol('x', even=True)
+    assert refine((-2)**x) == 2**x
 
     # nested powers
+    x = Symbol('x')
+    assert refine(sqrt(x**2)) != Abs(x)
+    x = Symbol('x', complex=True)
     assert refine(sqrt(x**2)) != Abs(x)
-    assert refine(sqrt(x**2), Q.complex(x)) != Abs(x)
-    assert refine(sqrt(x**2), Q.real(x)) == Abs(x)
-    assert refine(sqrt(x**2), Q.positive(x)) == x
+    x = Symbol('x', real=True)
+    assert refine(sqrt(x**2)) == Abs(x)
+    p = Symbol('p', positive=True)
+    assert refine(sqrt(p**2)) == p
+    x = Symbol('x')
     assert refine((x**3)**(S(1)/3)) != x
-
-    assert refine((x**3)**(S(1)/3), Q.real(x)) != x
-    assert refine((x**3)**(S(1)/3), Q.positive(x)) == x
-
-    assert refine(sqrt(1/x), Q.real(x)) != 1/sqrt(x)
-    assert refine(sqrt(1/x), Q.positive(x)) == 1/sqrt(x)
+    x = Symbol('x', real=True)
+    assert refine((x**3)**(S(1)/3)) != x
+    x = Symbol('x', positive=True)
+    assert refine((x**3)**(S(1)/3)) == x
+    x = Symbol('x', real=True)
+    assert refine(sqrt(1/x)) != 1/sqrt(x)
+    x = Symbol('x', positive=True)
+    assert refine(sqrt(1/x)) == 1/sqrt(x)
 
     # powers of (-1)
+    x = Symbol('x', even=True)
     assert refine((-1)**(x + y), Q.even(x)) == (-1)**y
+    x = Symbol('x', odd=True)
+    z = Symbol('z', odd=True)
     assert refine((-1)**(x + y + z), Q.odd(x) & Q.odd(z)) == (-1)**y
     assert refine((-1)**(x + y + 1), Q.odd(x)) == (-1)**y
     assert refine((-1)**(x + y + 2), Q.odd(x)) == (-1)**(y + 1)
+    x = Symbol('x')
     assert refine((-1)**(x + 3)) == (-1)**(x + 1)
-
+    x = Symbol('x', integer=True)
     assert refine((-1)**((-1)**x/2 - S.Half), Q.integer(x)) == (-1)**x
     assert refine((-1)**((-1)**x/2 + S.Half), Q.integer(x)) == (-1)**(x + 1)
     assert refine((-1)**((-1)**x/2 + 5*S.Half), Q.integer(x)) == (-1)**(x + 1)
@@ -47,8 +64,10 @@ def test_pow():
     assert refine((-1)**((-1)**x/2 - 9*S.Half), Q.integer(x)) == (-1)**x
 
     # powers of Abs
+    x = Symbol('x', real=True)
     assert refine(Abs(x)**2, Q.real(x)) == x**2
     assert refine(Abs(x)**3, Q.real(x)) == Abs(x)**3
+    x = Symbol('x')
     assert refine(Abs(x)**2) == Abs(x)**2
 
 
diff --git a/sympy/core/tests/test_assumptions.py b/sympy/core/tests/test_assumptions.py
index b419d0d443..e1e3131638 100644
--- a/sympy/core/tests/test_assumptions.py
+++ b/sympy/core/tests/test_assumptions.py
@@ -742,7 +742,7 @@ def test_Pow_is_algebraic():
     x = Symbol('x')
     assert (a**r).is_algebraic
     assert (a**x).is_algebraic is None
-    assert (na**r).is_algebraic is False
+    assert (na**r).is_algebraic is None
     assert (ia**r).is_algebraic
     assert (ia**ib).is_algebraic is False
 
@@ -753,6 +753,13 @@ def test_Pow_is_algebraic():
 
     assert Pow(S.GoldenRatio, sqrt(3), evaluate=False).is_algebraic is False
 
+    # issue 8649
+    t = Symbol('t', real=True, transcendental=True)
+    n = Symbol('n', integer=True)
+    assert (t**n).is_algebraic is None
+    assert (t**n).is_integer is None
+
+
 def test_Mul_is_prime():
     from sympy import Mul
     x = Symbol('x', positive=True, integer=True)
diff --git a/sympy/functions/elementary/tests/test_complexes.py b/sympy/functions/elementary/tests/test_complexes.py
index d74e2e317e..2351f6570a 100644
--- a/sympy/functions/elementary/tests/test_complexes.py
+++ b/sympy/functions/elementary/tests/test_complexes.py
@@ -214,7 +214,7 @@ def test_sign():
     assert sign(x).is_integer is True
     assert sign(x).is_real is True
     assert sign(x).is_zero is False
-    assert sign(x).doit() == x / Abs(x)
+    assert sign(x).doit() == x/Abs(x)
     assert sign(Abs(x)) == 1
     assert Abs(sign(x)) == 1
 
@@ -289,7 +289,7 @@ def test_as_real_imag():
 
     assert sqrt(a**2).as_real_imag() == (sqrt(a**2), 0)
     i = symbols('i', imaginary=True)
-    assert sqrt(i**2).as_real_imag() == (0, abs(i))
+    assert sqrt(i**2).as_real_imag() == (0, Abs(-i))
 
 
 @XFAIL
@@ -317,10 +317,10 @@ def test_Abs():
     assert Abs(I) == 1
     assert Abs(-I) == 1
     assert Abs(nan) == nan
-    assert Abs(I * pi) == pi
-    assert Abs(-I * pi) == pi
-    assert Abs(I * x) == Abs(x)
-    assert Abs(-I * x) == Abs(x)
+    assert Abs(I*pi) == pi
+    assert Abs(-I*pi) == pi
+    assert Abs(I*x) == Abs(x)
+    assert Abs(-I*x) == Abs(x)
     assert Abs(-2*x) == 2*Abs(x)
     assert Abs(-2.0*x) == 2.0*Abs(x)
     assert Abs(2*pi*x*y) == 2*pi*Abs(x*y)
diff --git a/sympy/functions/elementary/tests/test_exponential.py b/sympy/functions/elementary/tests/test_exponential.py
index ec8ce348d0..40955f557e 100644
--- a/sympy/functions/elementary/tests/test_exponential.py
+++ b/sympy/functions/elementary/tests/test_exponential.py
@@ -311,7 +311,7 @@ def test_log_sign():
 
 def test_log_expand_complex():
     assert log(1 + I).expand(complex=True) == log(2)/2 + I*pi/4
-    assert log(1 - sqrt(2)).expand(complex=True) == log(sqrt(2) - 1) + I*pi
+    assert log(1 - sqrt(2)).expand(complex=True) == log(-1 + sqrt(2)) + I*pi
 
 
 def test_log_apply_evalf():
diff --git a/sympy/functions/elementary/tests/test_piecewise.py b/sympy/functions/elementary/tests/test_piecewise.py
index dc0617e20a..5a57c013d2 100644
--- a/sympy/functions/elementary/tests/test_piecewise.py
+++ b/sympy/functions/elementary/tests/test_piecewise.py
@@ -2,7 +2,7 @@
     adjoint, And, Basic, conjugate, diff, expand, Eq, Function, I,
     Integral, integrate, Interval, lambdify, log, Max, Min, oo, Or, pi,
     Piecewise, piecewise_fold, Rational, solve, symbols, transpose,
-    cos, exp, Abs, Not, Symbol, S
+    cos, exp, Abs, Not, Symbol, S, refine
 )
 from sympy.printing import srepr
 from sympy.utilities.pytest import XFAIL, raises
@@ -337,7 +337,7 @@ def test_piecewise_fold_piecewise_in_cond():
     p3 = piecewise_fold(p2)
     assert(p2.subs(x, -pi/2) == 0.0)
     assert(p2.subs(x, 1) == 0.0)
-    assert(p2.subs(x, -pi/4) == 1.0)
+    assert(refine(p2.subs(x, -pi/4)) == 1.0)
     p4 = Piecewise((0, Eq(p1, 0)), (1,True))
     assert(piecewise_fold(p4) == Piecewise(
         (0, Or(And(Eq(cos(x), 0), x < 0), Not(x < 0))), (1, True)))
diff --git a/sympy/functions/elementary/tests/test_trigonometric.py b/sympy/functions/elementary/tests/test_trigonometric.py
index 7fd817001d..7d507a25d9 100644
--- a/sympy/functions/elementary/tests/test_trigonometric.py
+++ b/sympy/functions/elementary/tests/test_trigonometric.py
@@ -1,5 +1,5 @@
 from sympy import (symbols, Symbol, nan, oo, zoo, I, sinh, sin, pi, atan,
-        acos, Rational, sqrt, asin, acot, coth, E, S, tan, tanh, cos,
+        acos, Rational, sqrt, asin, acot, coth, E, S, tan, tanh, cos, refine,
         cosh, atan2, exp, log, asinh, acoth, atanh, O, cancel, Matrix, re, im,
         Float, Pow, gcd, sec, csc, cot, diff, simplify, Heaviside, arg,
         conjugate, series, FiniteSet, asec, acsc, Mul, sinc, jn, Product,
@@ -890,7 +890,7 @@ def test_atan2():
     rewrite = e.rewrite(arg)
     reps = {i: I, r: -2}
     assert rewrite == -I*log(abs(I*i + r)/sqrt(abs(i**2 + r**2))) + arg((I*i + r)/sqrt(i**2 + r**2))
-    assert (e - rewrite).subs(reps).equals(0)
+    assert refine((e - rewrite).subs(reps)).equals(0)
 
     assert conjugate(atan2(x, y)) == atan2(conjugate(x), conjugate(y))
 
diff --git a/sympy/integrals/tests/test_meijerint.py b/sympy/integrals/tests/test_meijerint.py
index 55da116728..9cb4620920 100644
--- a/sympy/integrals/tests/test_meijerint.py
+++ b/sympy/integrals/tests/test_meijerint.py
@@ -99,7 +99,7 @@ def t(a, b, arg, n):
 
 
 def test_recursive():
-    from sympy import symbols
+    from sympy import symbols, refine
     a, b, c = symbols('a b c', positive=True)
     r = exp(-(x - a)**2)*exp(-(x - b)**2)
     e = integrate(r, (x, 0, oo), meijerg=True)
@@ -112,7 +112,7 @@ def test_recursive():
         + (2*a + 2*b + c)**2/8)/4)
     assert simplify(integrate(exp(-(x - a - b - c)**2), (x, 0, oo), meijerg=True)) == \
         sqrt(pi)/2*(1 + erf(a + b + c))
-    assert simplify(integrate(exp(-(x + a + b + c)**2), (x, 0, oo), meijerg=True)) == \
+    assert simplify(refine(integrate(exp(-(x + a + b + c)**2), (x, 0, oo), meijerg=True))) == \
         sqrt(pi)/2*(1 - erf(a + b + c))
 
 
diff --git a/sympy/integrals/tests/test_transforms.py b/sympy/integrals/tests/test_transforms.py
index 1fd77d7db5..71fbfb3e98 100644
--- a/sympy/integrals/tests/test_transforms.py
+++ b/sympy/integrals/tests/test_transforms.py
@@ -773,14 +773,14 @@ def test_issue_7173():
 
 
 def test_issue_8514():
-    from sympy import simplify
+    from sympy import simplify, refine
     a, b, c, = symbols('a b c', positive=True)
     t = symbols('t', positive=True)
     ft = simplify(inverse_laplace_transform(1/(a*s**2+b*s+c),s, t))
     assert ft == ((exp(t*(exp(I*atan2(0, -4*a*c + b**2)/2) -
                   exp(-I*atan2(0, -4*a*c + b**2)/2))*
-                  sqrt(Abs(4*a*c - b**2))/(4*a))*exp(t*cos(atan2(0, -4*a*c + b**2)/2)
-                  *sqrt(Abs(4*a*c - b**2))/a) + I*sin(t*sin(atan2(0, -4*a*c + b**2)/2)
-                  *sqrt(Abs(4*a*c - b**2))/(2*a)) - cos(t*sin(atan2(0, -4*a*c + b**2)/2)
-                  *sqrt(Abs(4*a*c - b**2))/(2*a)))*exp(-t*(b + cos(atan2(0, -4*a*c + b**2)/2)
-                  *sqrt(Abs(4*a*c - b**2)))/(2*a))/sqrt(-4*a*c + b**2))
+                  sqrt(refine(Abs(4*a*c - b**2)))/(4*a))*exp(t*cos(atan2(0, -4*a*c + b**2)/2)
+                  *sqrt(refine(Abs(4*a*c - b**2)))/a) + I*sin(t*sin(atan2(0, -4*a*c + b**2)/2)
+                  *sqrt(refine(Abs(4*a*c - b**2)))/(2*a)) - cos(t*sin(atan2(0, -4*a*c + b**2)/2)
+                  *sqrt(refine(Abs(4*a*c - b**2)))/(2*a)))*exp(-t*(b + cos(atan2(0, -4*a*c + b**2)/2)
+                  *sqrt(refine(Abs(4*a*c - b**2))))/(2*a))/sqrt(-4*a*c + b**2))
diff --git a/sympy/matrices/tests/test_matrices.py b/sympy/matrices/tests/test_matrices.py
index b9237ca780..2a9b90a0ee 100644
--- a/sympy/matrices/tests/test_matrices.py
+++ b/sympy/matrices/tests/test_matrices.py
@@ -128,18 +128,6 @@ def test_multiplication():
     assert c[2, 0] == 18
     assert c[2, 1] == 0
 
-    try:
-        eval('c = a @ b')
-    except SyntaxError:
-        pass
-    else:
-        assert c[0, 0] == 7
-        assert c[0, 1] == 2
-        assert c[1, 0] == 6
-        assert c[1, 1] == 6
-        assert c[2, 0] == 18
-        assert c[2, 1] == 0
-
     h = matrix_multiply_elementwise(a, c)
     assert h == a.multiply_elementwise(c)
     assert h[0, 0] == 7
@@ -167,17 +155,6 @@ def test_multiplication():
     assert c[1, 0] == 3*5
     assert c[1, 1] == 0
 
-    try:
-        eval('c = 5 @ b')
-    except SyntaxError:
-        pass
-    else:
-        assert isinstance(c, Matrix)
-        assert c[0, 0] == 5
-        assert c[0, 1] == 2*5
-        assert c[1, 0] == 3*5
-        assert c[1, 1] == 0
-
 
 def test_power():
     raises(NonSquareMatrixError, lambda: Matrix((1, 2))**2)
diff --git a/sympy/matrices/tests/test_sparse.py b/sympy/matrices/tests/test_sparse.py
index 2952878fe0..3695e21ddb 100644
--- a/sympy/matrices/tests/test_sparse.py
+++ b/sympy/matrices/tests/test_sparse.py
@@ -65,18 +65,6 @@ def sparse_zeros(n):
     assert c[2, 0] == 18
     assert c[2, 1] == 0
 
-    try:
-        eval('c = a @ b')
-    except SyntaxError:
-        pass
-    else:
-        assert c[0, 0] == 7
-        assert c[0, 1] == 2
-        assert c[1, 0] == 6
-        assert c[1, 1] == 6
-        assert c[2, 0] == 18
-        assert c[2, 1] == 0
-
     x = Symbol("x")
 
     c = b * Symbol("x")