Repository: sympy/sympy

Issue:
sympy 1.6 is not importable in Python 3.5.1
From stackoverflow:
https://stackoverflow.com/questions/61995836/importerror-while-importing-sympy

```
>>> import sympy
Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    import sympy
  File "C:\Users\Alok\AppData\Local\Programs\Python\Python35\lib\site-packages\sympy\__init__.py", line 51, in <module>
    from .core import (sympify, SympifyError, cacheit, Basic, Atom,
  File "C:\Users\Alok\AppData\Local\Programs\Python\Python35\lib\site-packages\sympy\core\__init__.py", line 4, in <module>
    from .sympify import sympify, SympifyError
  File "C:\Users\Alok\AppData\Local\Programs\Python\Python35\lib\site-packages\sympy\core\sympify.py", line 3, in <module>
    from typing import Dict, Type, Callable, Any
ImportError: cannot import name 'Type'
```

`typing.Type` was added in Python 3.5.2:
https://docs.python.org/3/library/typing.html#typing.Type

Discussion:

Patch:
diff --git a/sympy/core/compatibility.py b/sympy/core/compatibility.py
index 34cf359cd2..46c370998b 100644
--- a/sympy/core/compatibility.py
+++ b/sympy/core/compatibility.py
@@ -4,7 +4,7 @@
 here for easy import.
 """
 
-from typing import Tuple, Type
+# from typing import Tuple, Type
 
 import operator
 from collections import defaultdict
@@ -728,7 +728,7 @@ def _getenv(key, default=None):
     GROUND_TYPES = 'python'
 
 # SYMPY_INTS is a tuple containing the base types for valid integer types.
-SYMPY_INTS = (int, )  # type: Tuple[Type, ...]
+SYMPY_INTS = (int, )  ## type: Tuple[Type, ...]
 
 if GROUND_TYPES == 'gmpy':
     SYMPY_INTS += (type(gmpy.mpz(0)),)
diff --git a/sympy/core/logic.py b/sympy/core/logic.py
index e46e5c4999..4215c44c44 100644
--- a/sympy/core/logic.py
+++ b/sympy/core/logic.py
@@ -7,7 +7,8 @@
 this stuff for general purpose.
 """
 
-from typing import Dict, Type, Union
+# from typing import Dict, Type
+from typing import Union
 
 
 # Type of a fuzzy bool
@@ -223,7 +224,7 @@ def fuzzy_nand(args):
 class Logic:
     """Logical expression"""
     # {} 'op' -> LogicClass
-    op_2class = {}  # type: Dict[str, Type[Logic]]
+    op_2class = {}  ## type: Dict[str, Type[Logic]]
 
     def __new__(cls, *args):
         obj = object.__new__(cls)
diff --git a/sympy/core/relational.py b/sympy/core/relational.py
index 33672037e4..df51d36d36 100644
--- a/sympy/core/relational.py
+++ b/sympy/core/relational.py
@@ -1,4 +1,4 @@
-from typing import Dict, Type, Union
+# from typing import Dict, Union, Type
 
 from sympy.utilities.exceptions import SymPyDeprecationWarning
 from .add import _unevaluated_Add, Add
@@ -59,7 +59,7 @@ class Relational(Boolean, EvalfMixin):
     """
     __slots__ = ()
 
-    ValidRelationOperator = {}  # type: Dict[Union[str, None], Type[Relational]]
+    ValidRelationOperator = {}  ## type: Dict[Union[str, None], Type[Relational]]
 
     is_Relational = True
 
diff --git a/sympy/core/singleton.py b/sympy/core/singleton.py
index 4ae3ec3e71..d3e0b75fea 100644
--- a/sympy/core/singleton.py
+++ b/sympy/core/singleton.py
@@ -1,7 +1,7 @@
 """Singleton mechanism"""
 
 
-from typing import Any, Dict, Type
+# from typing import Any, Dict, Type
 
 from .core import Registry
 from .assumptions import ManagedProperties
@@ -160,7 +160,7 @@ class is instantiated. Additionally, this instance can be accessed through
     subclass may use a subclassed metaclass).
     """
 
-    _instances = {}  # type: Dict[Type[Any], Any]
+    _instances = {}  ## type: Dict[Type[Any], Any]
     "Maps singleton classes to their instances."
 
     def __new__(cls, *args, **kwargs):
diff --git a/sympy/core/sympify.py b/sympy/core/sympify.py
index a755465446..6d64d0d62a 100644
--- a/sympy/core/sympify.py
+++ b/sympy/core/sympify.py
@@ -1,6 +1,6 @@
 """sympify -- convert objects SymPy internal format"""
 
-from typing import Dict, Type, Callable, Any
+# from typing import Any, Callable, Dict, Type
 
 from inspect import getmro
 
@@ -23,7 +23,7 @@ def __str__(self):
 
 
 # See sympify docstring.
-converter = {}  # type: Dict[Type[Any], Callable[[Any], Basic]]
+converter = {}  ## type: Dict[Type[Any], Callable[[Any], Basic]]
 
 
 class CantSympify:
@@ -542,4 +542,4 @@ def _clear(expr):
 
 
 # Avoid circular import
-from .basic import Basic
+# from .basic import Basic
diff --git a/sympy/matrices/__init__.py b/sympy/matrices/__init__.py
index 82d5161c48..7ab3f17200 100644
--- a/sympy/matrices/__init__.py
+++ b/sympy/matrices/__init__.py
@@ -30,8 +30,6 @@
     DotProduct, kronecker_product, KroneckerProduct,
     PermutationMatrix, MatrixPermute)
 
-from .utilities import dotprodsimp
-
 __all__ = [
     'ShapeError', 'NonSquareMatrixError',
 
@@ -62,6 +60,4 @@
     'det', 'diagonalize_vector', 'DiagMatrix', 'DiagonalMatrix',
     'DiagonalOf', 'trace', 'DotProduct', 'kronecker_product',
     'KroneckerProduct', 'PermutationMatrix', 'MatrixPermute',
-
-    'dotprodsimp',
 ]
diff --git a/sympy/matrices/determinant.py b/sympy/matrices/determinant.py
index d4dc046f7b..647541afef 100644
--- a/sympy/matrices/determinant.py
+++ b/sympy/matrices/determinant.py
@@ -232,8 +232,8 @@ def _berkowitz_toeplitz_matrix(M):
     # compute -R * A**n * C.
     diags = [C]
     for i in range(M.rows - 2):
-        diags.append(A.multiply(diags[i], dotprodsimp=None))
-    diags = [(-R).multiply(d, dotprodsimp=None)[0, 0] for d in diags]
+        diags.append(A.multiply(diags[i], dotprodsimp=True))
+    diags = [(-R).multiply(d, dotprodsimp=True)[0, 0] for d in diags]
     diags = [M.one, -a] + diags
 
     def entry(i,j):
@@ -289,7 +289,7 @@ def _berkowitz_vector(M):
 
     submat, toeplitz = _berkowitz_toeplitz_matrix(M)
 
-    return toeplitz.multiply(_berkowitz_vector(submat), dotprodsimp=None)
+    return toeplitz.multiply(_berkowitz_vector(submat), dotprodsimp=True)
 
 
 def _adjugate(M, method="berkowitz"):
diff --git a/sympy/matrices/eigen.py b/sympy/matrices/eigen.py
index d277c34d2d..b9e63b8ae9 100644
--- a/sympy/matrices/eigen.py
+++ b/sympy/matrices/eigen.py
@@ -873,7 +873,7 @@ def eig_mat(val, pow):
 
         if (val, pow - 1) in mat_cache:
             mat_cache[(val, pow)] = mat_cache[(val, pow - 1)].multiply(
-                    mat_cache[(val, 1)], dotprodsimp=None)
+                    mat_cache[(val, 1)], dotprodsimp=True)
         else:
             mat_cache[(val, pow)] = (mat - val*M.eye(M.rows)).pow(pow)
 
@@ -1028,7 +1028,7 @@ def pick_vec(small_basis, big_basis):
             # of any other generalized eigenvectors from a different
             # generalized eigenspace sharing the same eigenvalue.
             vec      = pick_vec(null_small + eig_basis, null_big)
-            new_vecs = [eig_mat(eig, i).multiply(vec, dotprodsimp=None)
+            new_vecs = [eig_mat(eig, i).multiply(vec, dotprodsimp=True)
                     for i in range(size)]
 
             eig_basis.extend(new_vecs)
diff --git a/sympy/matrices/matrices.py b/sympy/matrices/matrices.py
index 312407f949..ae6f9e10d9 100644
--- a/sympy/matrices/matrices.py
+++ b/sympy/matrices/matrices.py
@@ -1630,7 +1630,7 @@ def exp(self):
         from sympy import re
         eJ = diag(*blocks)
         # n = self.rows
-        ret = P.multiply(eJ, dotprodsimp=None).multiply(P.inv(), dotprodsimp=None)
+        ret = P.multiply(eJ, dotprodsimp=True).multiply(P.inv(), dotprodsimp=True)
         if all(value.is_real for value in self.values()):
             return type(self)(re(ret))
         else:
diff --git a/sympy/matrices/utilities.py b/sympy/matrices/utilities.py
index 97433c9d2d..b18955e79d 100644
--- a/sympy/matrices/utilities.py
+++ b/sympy/matrices/utilities.py
@@ -1,22 +1,50 @@
-from contextlib import contextmanager
-from threading import local
+import os
 
 from sympy.core.function import expand_mul
 from sympy.simplify.simplify import dotprodsimp as _dotprodsimp
 
 
-_dotprodsimp_state       = local()
-_dotprodsimp_state.state = None
+# The following is an internal variable for controlling the recently introduced
+# dotprodsimp intermediate simplification step in matrix operations in one
+# place. It is intended as an emergency switch in cases where user code does not
+# like the different structure of results that comes from this simplification
+# and can not be adapted for some reason. When the intermediate simplification
+# step is considered fully compatible with user code and this mechanism is no
+# longer needed in can be removed.
 
-@contextmanager
-def dotprodsimp(x):
-    old = _dotprodsimp_state.state
+# The default value of `None` specifies that dotprodsimp be used in a few
+# selected low-level functions but not in others. Setting this global variable
+# to `False` will turn off the dotprodsimp intermediate simplifications
+# everywhere and setting to `True` will turn it on everywhere in matrices where
+# it can be applied.
 
-    try:
-        _dotprodsimp_state.state = x
-        yield
-    finally:
-        _dotprodsimp_state.state = old
+# There are a few other places in the matrix code where dotprodsimp can probably
+# help, these are places where a call is made to:
+#
+# dps = _get_intermediate_simp()
+#
+# To determine whether dotprodsimp helps in these places testing needs to be
+# done, to turn dotprodsimp on in these places by default replace this call with:
+#
+# from sympy.simplify.simplify import dotprodsimp as _dotprodsimp
+# dps = _get_intermediate_simp(_dotprodsimp)
+#
+# Or possibly:
+#
+# from sympy import expand_mul
+# dps = _get_intermediate_simp(expand_mul, expand_mul)
+#
+# This second form uses lighter simplification by default but may still do
+# better than nothing.
+#
+# The other place where dotprodsimp may be added is any place where matrices are
+# multiplied via:
+#
+# A.multiply(B) -> A.multiply(B, dotprodsimp=True)
+
+# True, False or None
+_DOTPRODSIMP_MODE = False if os.environ.get('SYMPY_DOTPRODSIMP', '').lower() in \
+        ('false', 'off', '0') else None
 
 def _get_intermediate_simp(deffunc=lambda x: x, offfunc=lambda x: x,
         onfunc=_dotprodsimp, dotprodsimp=None):
@@ -28,12 +56,12 @@ def _get_intermediate_simp(deffunc=lambda x: x, offfunc=lambda x: x,
     ``offfunc``     - Function to be used if dotprodsimp has been turned off.
     ``onfunc``      - Function to be used if dotprodsimp has been turned on.
     ``dotprodsimp`` - True, False or None. Will be overriden by global
-                      _dotprodsimp_state.state if that is not None.
+                      _DOTPRODSIMP_MODE if that is not None.
     """
 
-    if dotprodsimp is False or _dotprodsimp_state.state is False:
+    if dotprodsimp is False or _DOTPRODSIMP_MODE is False:
         return offfunc
-    if dotprodsimp is True or _dotprodsimp_state.state is True:
+    if dotprodsimp is True or _DOTPRODSIMP_MODE is True:
         return onfunc
 
     return deffunc # None, None
diff --git a/sympy/polys/domains/domain.py b/sympy/polys/domains/domain.py
index 9af62b6a8f..c495672cbf 100644
--- a/sympy/polys/domains/domain.py
+++ b/sympy/polys/domains/domain.py
@@ -2,7 +2,7 @@
 
 from __future__ import print_function, division
 
-from typing import Any, Optional, Type
+from typing import Any, Optional
 
 from sympy.core import Basic, sympify
 from sympy.core.compatibility import HAS_GMPY, is_sequence
@@ -17,7 +17,7 @@
 class Domain(object):
     """Represents an abstract domain. """
 
-    dtype = None  # type: Optional[Type]
+    dtype = None  ## type: Optional[Type]
     zero = None  # type: Optional[Any]
     one = None  # type: Optional[Any]
 
diff --git a/sympy/polys/domains/modularinteger.py b/sympy/polys/domains/modularinteger.py
index 23f3b1058f..e59e68c8a5 100644
--- a/sympy/polys/domains/modularinteger.py
+++ b/sympy/polys/domains/modularinteger.py
@@ -2,7 +2,7 @@
 
 from __future__ import print_function, division
 
-from typing import Any, Dict, Tuple, Type
+# from typing import Any, Dict, Tuple, Type
 
 import operator
 
@@ -178,7 +178,7 @@ def _invert(cls, value):
     def invert(self):
         return self.__class__(self._invert(self.val))
 
-_modular_integer_cache = {}  # type: Dict[Tuple[Any, Any, Any], Type[ModularInteger]]
+_modular_integer_cache = {}  ## type: Dict[Tuple[Any, Any, Any], Type[ModularInteger]]
 
 def ModularIntegerFactory(_mod, _dom, _sym, parent):
     """Create custom class for specific integer modulus."""
diff --git a/sympy/polys/polyoptions.py b/sympy/polys/polyoptions.py
index 399588be0b..c6a6457f38 100644
--- a/sympy/polys/polyoptions.py
+++ b/sympy/polys/polyoptions.py
@@ -4,7 +4,8 @@
 
 __all__ = ["Options"]
 
-from typing import Dict, List, Optional, Type
+# from typing import Dict, Type
+from typing import List, Optional
 
 from sympy.core import S, Basic, sympify
 from sympy.polys.polyerrors import GeneratorsError, OptionError, FlagError
@@ -123,7 +124,7 @@ class Options(dict):
     """
 
     __order__ = None
-    __options__ = {}  # type: Dict[str, Type[Option]]
+    __options__ = {}  ## type: Dict[str, Type[Option]]
 
     def __init__(self, gens, args, flags=None, strict=False):
         dict.__init__(self)
diff --git a/sympy/solvers/ode/single.py b/sympy/solvers/ode/single.py
index 3a00e3320c..afe41bdfcf 100644
--- a/sympy/solvers/ode/single.py
+++ b/sympy/solvers/ode/single.py
@@ -1,11 +1,14 @@
 #
 # This is the module for ODE solver classes for single ODEs.
 #
-import typing
 
-if typing.TYPE_CHECKING:
-    from typing import ClassVar
-from typing import Dict, Iterable, List, Optional, Type
+#import typing
+#
+#if typing.TYPE_CHECKING:
+#    from typing import ClassVar
+#from typing import Dict, Type
+
+from typing import Iterable, List, Optional
 
 from sympy.core import S
 from sympy.core.exprtools import factor_terms
@@ -178,11 +181,11 @@ class SingleODESolver:
 
     # Subclasses should store the hint name (the argument to dsolve) in this
     # attribute
-    hint = None  # type: ClassVar[str]
+    hint = None  ## type: ClassVar[str]
 
     # Subclasses should define this to indicate if they support an _Integral
     # hint.
-    has_integral = None  # type: ClassVar[bool]
+    has_integral = None  ## type: ClassVar[bool]
 
     # The ODE to be solved
     ode_problem = None  # type: SingleODEProblem
@@ -351,7 +354,7 @@ def _get_general_solution(self, *, simplify: bool = True):
     # be stored in cached results we need to ensure that we always get the
     # same class back for each particular integration variable so we store these
     # classes in a global dict:
-    _diffx_stored = {}  # type: Dict[Symbol, Type[Function]]
+    _diffx_stored = {}  ## type: Dict[Symbol, Type[Function]]
 
     @staticmethod
     def _get_diffx(var):


Test patch:
diff --git a/sympy/matrices/tests/test_matrices.py b/sympy/matrices/tests/test_matrices.py
index f673ebf8a2..6d970b1f62 100644
--- a/sympy/matrices/tests/test_matrices.py
+++ b/sympy/matrices/tests/test_matrices.py
@@ -11,8 +11,7 @@
     GramSchmidt, ImmutableMatrix, ImmutableSparseMatrix, Matrix,
     SparseMatrix, casoratian, diag, eye, hessian,
     matrix_multiply_elementwise, ones, randMatrix, rot_axis1, rot_axis2,
-    rot_axis3, wronskian, zeros, MutableDenseMatrix, ImmutableDenseMatrix,
-    MatrixSymbol, dotprodsimp)
+    rot_axis3, wronskian, zeros, MutableDenseMatrix, ImmutableDenseMatrix, MatrixSymbol)
 from sympy.core.compatibility import iterable, Hashable
 from sympy.core import Tuple, Wild
 from sympy.functions.special.tensor_functions import KroneckerDelta
@@ -287,23 +286,20 @@ def test_power():
 
 def test_issue_17247_expression_blowup_1():
     M = Matrix([[1+x, 1-x], [1-x, 1+x]])
-    with dotprodsimp(True):
-        assert M.exp().expand() == Matrix([
-            [ (exp(2*x) + exp(2))/2, (-exp(2*x) + exp(2))/2],
-            [(-exp(2*x) + exp(2))/2,  (exp(2*x) + exp(2))/2]])
+    assert M.exp().expand() == Matrix([
+        [ (exp(2*x) + exp(2))/2, (-exp(2*x) + exp(2))/2],
+        [(-exp(2*x) + exp(2))/2,  (exp(2*x) + exp(2))/2]])
 
 def test_issue_17247_expression_blowup_2():
     M = Matrix([[1+x, 1-x], [1-x, 1+x]])
-    with dotprodsimp(True):
-        P, J = M.jordan_form ()
-        assert P*J*P.inv()
+    P, J = M.jordan_form ()
+    assert P*J*P.inv()
 
 def test_issue_17247_expression_blowup_3():
     M = Matrix([[1+x, 1-x], [1-x, 1+x]])
-    with dotprodsimp(True):
-        assert M**100 == Matrix([
-            [633825300114114700748351602688*x**100 + 633825300114114700748351602688, 633825300114114700748351602688 - 633825300114114700748351602688*x**100],
-            [633825300114114700748351602688 - 633825300114114700748351602688*x**100, 633825300114114700748351602688*x**100 + 633825300114114700748351602688]])
+    assert M**100 == Matrix([
+        [633825300114114700748351602688*x**100 + 633825300114114700748351602688, 633825300114114700748351602688 - 633825300114114700748351602688*x**100],
+        [633825300114114700748351602688 - 633825300114114700748351602688*x**100, 633825300114114700748351602688*x**100 + 633825300114114700748351602688]])
 
 def test_issue_17247_expression_blowup_4():
 # This matrix takes extremely long on current master even with intermediate simplification so an abbreviated version is used. It is left here for test in case of future optimizations.
@@ -340,63 +336,54 @@ def test_issue_17247_expression_blowup_4():
         [   -5/8 - 39*I/16,   2473/256 + 137*I/64, -149/64 + 49*I/32, -177/128 - 1369*I/128,  125/64 + 87*I/64, -2063/256 + 541*I/128],
         [            1 + I,         -19/4 + 5*I/4,           1/2 - I,         9/4 + 55*I/16,              -3/4,       45/32 - 37*I/16],
         [         21/8 + I,    -537/64 + 143*I/16,    -5/8 - 39*I/16,   2473/256 + 137*I/64, -149/64 + 49*I/32, -177/128 - 1369*I/128]]'''))
-    with dotprodsimp(True):
-        assert M**10 == Matrix(S('''[
-            [     7369525394972778926719607798014571861/604462909807314587353088 - 229284202061790301477392339912557559*I/151115727451828646838272,   -19704281515163975949388435612632058035/1208925819614629174706176 + 14319858347987648723768698170712102887*I/302231454903657293676544,      -3623281909451783042932142262164941211/604462909807314587353088 - 6039240602494288615094338643452320495*I/604462909807314587353088,    109260497799140408739847239685705357695/2417851639229258349412352 - 7427566006564572463236368211555511431*I/2417851639229258349412352, -16095803767674394244695716092817006641/2417851639229258349412352 + 10336681897356760057393429626719177583*I/1208925819614629174706176,    -42207883340488041844332828574359769743/2417851639229258349412352 - 182332262671671273188016400290188468499*I/4835703278458516698824704],
-            [50566491050825573392726324995779608259/1208925819614629174706176 - 90047007594468146222002432884052362145*I/2417851639229258349412352,  74273703462900000967697427843983822011/1208925819614629174706176 + 265947522682943571171988741842776095421*I/1208925819614629174706176, -116900341394390200556829767923360888429/2417851639229258349412352 - 53153263356679268823910621474478756845*I/2417851639229258349412352, 195407378023867871243426523048612490249/1208925819614629174706176 - 1242417915995360200584837585002906728929*I/9671406556917033397649408,   -863597594389821970177319682495878193/302231454903657293676544 + 476936100741548328800725360758734300481*I/9671406556917033397649408, -3154451590535653853562472176601754835575/19342813113834066795298816 - 232909875490506237386836489998407329215*I/2417851639229258349412352],
-            [   -1715444997702484578716037230949868543/302231454903657293676544 + 5009695651321306866158517287924120777*I/302231454903657293676544,     -30551582497996879620371947949342101301/604462909807314587353088 - 7632518367986526187139161303331519629*I/151115727451828646838272,           312680739924495153190604170938220575/18889465931478580854784 - 108664334509328818765959789219208459*I/75557863725914323419136,    -14693696966703036206178521686918865509/604462909807314587353088 + 72345386220900843930147151999899692401*I/1208925819614629174706176,  -8218872496728882299722894680635296519/1208925819614629174706176 - 16776782833358893712645864791807664983*I/1208925819614629174706176,      143237839169380078671242929143670635137/2417851639229258349412352 + 2883817094806115974748882735218469447*I/2417851639229258349412352],
-            [   3087979417831061365023111800749855987/151115727451828646838272 + 34441942370802869368851419102423997089*I/604462909807314587353088, -148309181940158040917731426845476175667/604462909807314587353088 - 263987151804109387844966835369350904919*I/9671406556917033397649408,   50259518594816377378747711930008883165/1208925819614629174706176 - 95713974916869240305450001443767979653*I/2417851639229258349412352,  153466447023875527996457943521467271119/2417851639229258349412352 + 517285524891117105834922278517084871349*I/2417851639229258349412352,  -29184653615412989036678939366291205575/604462909807314587353088 - 27551322282526322041080173287022121083*I/1208925819614629174706176,   196404220110085511863671393922447671649/1208925819614629174706176 - 1204712019400186021982272049902206202145*I/9671406556917033397649408],
-            [     -2632581805949645784625606590600098779/151115727451828646838272 - 589957435912868015140272627522612771*I/37778931862957161709568,     26727850893953715274702844733506310247/302231454903657293676544 - 10825791956782128799168209600694020481*I/302231454903657293676544,      -1036348763702366164044671908440791295/151115727451828646838272 + 3188624571414467767868303105288107375*I/151115727451828646838272,     -36814959939970644875593411585393242449/604462909807314587353088 - 18457555789119782404850043842902832647*I/302231454903657293676544,      12454491297984637815063964572803058647/604462909807314587353088 - 340489532842249733975074349495329171*I/302231454903657293676544,      -19547211751145597258386735573258916681/604462909807314587353088 + 87299583775782199663414539883938008933*I/1208925819614629174706176],
-            [  -40281994229560039213253423262678393183/604462909807314587353088 - 2939986850065527327299273003299736641*I/604462909807314587353088, 331940684638052085845743020267462794181/2417851639229258349412352 - 284574901963624403933361315517248458969*I/1208925819614629174706176,      6453843623051745485064693628073010961/302231454903657293676544 + 36062454107479732681350914931391590957*I/604462909807314587353088,  -147665869053634695632880753646441962067/604462909807314587353088 - 305987938660447291246597544085345123927*I/9671406556917033397649408,  107821369195275772166593879711259469423/2417851639229258349412352 - 11645185518211204108659001435013326687*I/302231454903657293676544,     64121228424717666402009446088588091619/1208925819614629174706176 + 265557133337095047883844369272389762133*I/1208925819614629174706176]]'''))
+    assert M**10 == Matrix(S('''[
+        [     7369525394972778926719607798014571861/604462909807314587353088 - 229284202061790301477392339912557559*I/151115727451828646838272,   -19704281515163975949388435612632058035/1208925819614629174706176 + 14319858347987648723768698170712102887*I/302231454903657293676544,      -3623281909451783042932142262164941211/604462909807314587353088 - 6039240602494288615094338643452320495*I/604462909807314587353088,    109260497799140408739847239685705357695/2417851639229258349412352 - 7427566006564572463236368211555511431*I/2417851639229258349412352, -16095803767674394244695716092817006641/2417851639229258349412352 + 10336681897356760057393429626719177583*I/1208925819614629174706176,    -42207883340488041844332828574359769743/2417851639229258349412352 - 182332262671671273188016400290188468499*I/4835703278458516698824704],
+        [50566491050825573392726324995779608259/1208925819614629174706176 - 90047007594468146222002432884052362145*I/2417851639229258349412352,  74273703462900000967697427843983822011/1208925819614629174706176 + 265947522682943571171988741842776095421*I/1208925819614629174706176, -116900341394390200556829767923360888429/2417851639229258349412352 - 53153263356679268823910621474478756845*I/2417851639229258349412352, 195407378023867871243426523048612490249/1208925819614629174706176 - 1242417915995360200584837585002906728929*I/9671406556917033397649408,   -863597594389821970177319682495878193/302231454903657293676544 + 476936100741548328800725360758734300481*I/9671406556917033397649408, -3154451590535653853562472176601754835575/19342813113834066795298816 - 232909875490506237386836489998407329215*I/2417851639229258349412352],
+        [   -1715444997702484578716037230949868543/302231454903657293676544 + 5009695651321306866158517287924120777*I/302231454903657293676544,     -30551582497996879620371947949342101301/604462909807314587353088 - 7632518367986526187139161303331519629*I/151115727451828646838272,           312680739924495153190604170938220575/18889465931478580854784 - 108664334509328818765959789219208459*I/75557863725914323419136,    -14693696966703036206178521686918865509/604462909807314587353088 + 72345386220900843930147151999899692401*I/1208925819614629174706176,  -8218872496728882299722894680635296519/1208925819614629174706176 - 16776782833358893712645864791807664983*I/1208925819614629174706176,      143237839169380078671242929143670635137/2417851639229258349412352 + 2883817094806115974748882735218469447*I/2417851639229258349412352],
+        [   3087979417831061365023111800749855987/151115727451828646838272 + 34441942370802869368851419102423997089*I/604462909807314587353088, -148309181940158040917731426845476175667/604462909807314587353088 - 263987151804109387844966835369350904919*I/9671406556917033397649408,   50259518594816377378747711930008883165/1208925819614629174706176 - 95713974916869240305450001443767979653*I/2417851639229258349412352,  153466447023875527996457943521467271119/2417851639229258349412352 + 517285524891117105834922278517084871349*I/2417851639229258349412352,  -29184653615412989036678939366291205575/604462909807314587353088 - 27551322282526322041080173287022121083*I/1208925819614629174706176,   196404220110085511863671393922447671649/1208925819614629174706176 - 1204712019400186021982272049902206202145*I/9671406556917033397649408],
+        [     -2632581805949645784625606590600098779/151115727451828646838272 - 589957435912868015140272627522612771*I/37778931862957161709568,     26727850893953715274702844733506310247/302231454903657293676544 - 10825791956782128799168209600694020481*I/302231454903657293676544,      -1036348763702366164044671908440791295/151115727451828646838272 + 3188624571414467767868303105288107375*I/151115727451828646838272,     -36814959939970644875593411585393242449/604462909807314587353088 - 18457555789119782404850043842902832647*I/302231454903657293676544,      12454491297984637815063964572803058647/604462909807314587353088 - 340489532842249733975074349495329171*I/302231454903657293676544,      -19547211751145597258386735573258916681/604462909807314587353088 + 87299583775782199663414539883938008933*I/1208925819614629174706176],
+        [  -40281994229560039213253423262678393183/604462909807314587353088 - 2939986850065527327299273003299736641*I/604462909807314587353088, 331940684638052085845743020267462794181/2417851639229258349412352 - 284574901963624403933361315517248458969*I/1208925819614629174706176,      6453843623051745485064693628073010961/302231454903657293676544 + 36062454107479732681350914931391590957*I/604462909807314587353088,  -147665869053634695632880753646441962067/604462909807314587353088 - 305987938660447291246597544085345123927*I/9671406556917033397649408,  107821369195275772166593879711259469423/2417851639229258349412352 - 11645185518211204108659001435013326687*I/302231454903657293676544,     64121228424717666402009446088588091619/1208925819614629174706176 + 265557133337095047883844369272389762133*I/1208925819614629174706176]]'''))
 
 def test_issue_17247_expression_blowup_5():
     M = Matrix(6, 6, lambda i, j: 1 + (-1)**(i+j)*I)
-    with dotprodsimp(True):
-        assert M.charpoly('x') == PurePoly(x**6 + (-6 - 6*I)*x**5 + 36*I*x**4, x, domain='EX')
+    assert M.charpoly('x') == PurePoly(x**6 + (-6 - 6*I)*x**5 + 36*I*x**4, x, domain='EX')
 
 def test_issue_17247_expression_blowup_6():
     M = Matrix(8, 8, [x+i for i in range (64)])
-    with dotprodsimp(True):
-        assert M.det('bareiss') == 0
+    assert M.det('bareiss') == 0
 
 def test_issue_17247_expression_blowup_7():
     M = Matrix(6, 6, lambda i, j: 1 + (-1)**(i+j)*I)
-    with dotprodsimp(True):
-        assert M.det('berkowitz') == 0
+    assert M.det('berkowitz') == 0
 
 @XFAIL # dotprodsimp is not on by default in this function
 def test_issue_17247_expression_blowup_8():
     M = Matrix(8, 8, [x+i for i in range (64)])
-    with dotprodsimp(True):
-        assert M.det('lu') == 0
+    assert M.det('lu') == 0
 
 def test_issue_17247_expression_blowup_9():
     M = Matrix(8, 8, [x+i for i in range (64)])
-    with dotprodsimp(True):
-        assert M.rref() == (Matrix([
-            [1, 0, -1, -2, -3, -4, -5, -6],
-            [0, 1,  2,  3,  4,  5,  6,  7],
-            [0, 0,  0,  0,  0,  0,  0,  0],
-            [0, 0,  0,  0,  0,  0,  0,  0],
-            [0, 0,  0,  0,  0,  0,  0,  0],
-            [0, 0,  0,  0,  0,  0,  0,  0],
-            [0, 0,  0,  0,  0,  0,  0,  0],
-            [0, 0,  0,  0,  0,  0,  0,  0]]), (0, 1))
+    assert M.rref() == (Matrix([
+        [1, 0, -1, -2, -3, -4, -5, -6],
+        [0, 1,  2,  3,  4,  5,  6,  7],
+        [0, 0,  0,  0,  0,  0,  0,  0],
+        [0, 0,  0,  0,  0,  0,  0,  0],
+        [0, 0,  0,  0,  0,  0,  0,  0],
+        [0, 0,  0,  0,  0,  0,  0,  0],
+        [0, 0,  0,  0,  0,  0,  0,  0],
+        [0, 0,  0,  0,  0,  0,  0,  0]]), (0, 1))
 
 def test_issue_17247_expression_blowup_10():
     M = Matrix(6, 6, lambda i, j: 1 + (-1)**(i+j)*I)
-    with dotprodsimp(True):
-        assert M.cofactor(0, 0) == 0
+    assert M.cofactor(0, 0) == 0
 
 def test_issue_17247_expression_blowup_11():
     M = Matrix(6, 6, lambda i, j: 1 + (-1)**(i+j)*I)
-    with dotprodsimp(True):
-        assert M.cofactor_matrix() == Matrix(6, 6, [0]*36)
+    assert M.cofactor_matrix() == Matrix(6, 6, [0]*36)
 
 def test_issue_17247_expression_blowup_12():
     M = Matrix(6, 6, lambda i, j: 1 + (-1)**(i+j)*I)
-    with dotprodsimp(True):
-        assert M.eigenvals() == {6: 1, 6*I: 1, 0: 4}
+    assert M.eigenvals() == {6: 1, 6*I: 1, 0: 4}
 
 def test_issue_17247_expression_blowup_13():
     M = Matrix([
@@ -404,61 +391,55 @@ def test_issue_17247_expression_blowup_13():
         [1 - x, x + 1,     0, x + 1],
         [    0, 1 - x, x + 1, 1 - x],
         [    0,     0,     1 - x, 0]])
-    with dotprodsimp(True):
-        ev = M.eigenvects()
-        assert ev[0][:2] == (0, 2)
-        assert ev[0][2][0] == Matrix([[0],[-1],[0],[1]])
-        assert ev[1][:2] == (x - sqrt(2)*(x - 1) + 1, 1)
-        assert (ev[1][2][0] - Matrix([
-            [-(-17*x**4 + 12*sqrt(2)*x**4 - 4*sqrt(2)*x**3 + 6*x**3 - 6*x - 4*sqrt(2)*x + 12*sqrt(2) + 17)/(-7*x**4 + 5*sqrt(2)*x**4 - 6*sqrt(2)*x**3 + 8*x**3 - 2*x**2 + 8*x + 6*sqrt(2)*x - 5*sqrt(2) - 7)],
-            [                      (-7*x**3 + 5*sqrt(2)*x**3 - x**2 + sqrt(2)*x**2 - sqrt(2)*x - x - 5*sqrt(2) - 7)/(-3*x**3 + 2*sqrt(2)*x**3 - 2*sqrt(2)*x**2 + 3*x**2 + 2*sqrt(2)*x + 3*x - 3 - 2*sqrt(2))],
-            [                                                                                           -(-3*x**2 + 2*sqrt(2)*x**2 + 2*x - 3 - 2*sqrt(2))/(-x**2 + sqrt(2)*x**2 - 2*sqrt(2)*x + 1 + sqrt(2))],
-            [                                                                                                                                                                                              1]])).expand() == Matrix([[0],[0],[0],[0]])
-        assert ev[2][:2] == (x + sqrt(2)*(x - 1) + 1, 1)
-        assert (ev[2][2][0] - Matrix([
-            [-(12*sqrt(2)*x**4 + 17*x**4 - 6*x**3 - 4*sqrt(2)*x**3 - 4*sqrt(2)*x + 6*x - 17 + 12*sqrt(2))/(7*x**4 + 5*sqrt(2)*x**4 - 6*sqrt(2)*x**3 - 8*x**3 + 2*x**2 - 8*x + 6*sqrt(2)*x - 5*sqrt(2) + 7)],
-            [                      (7*x**3 + 5*sqrt(2)*x**3 + x**2 + sqrt(2)*x**2 - sqrt(2)*x + x - 5*sqrt(2) + 7)/(2*sqrt(2)*x**3 + 3*x**3 - 3*x**2 - 2*sqrt(2)*x**2 - 3*x + 2*sqrt(2)*x - 2*sqrt(2) + 3)],
-            [                                                                                           -(2*sqrt(2)*x**2 + 3*x**2 - 2*x - 2*sqrt(2) + 3)/(x**2 + sqrt(2)*x**2 - 2*sqrt(2)*x - 1 + sqrt(2))],
-            [                                                                                                                                                                                            1]])).expand() == Matrix([[0],[0],[0],[0]])
+    ev = M.eigenvects()
+    assert ev[0][:2] == (0, 2)
+    assert ev[0][2][0] == Matrix([[0],[-1],[0],[1]])
+    assert ev[1][:2] == (x - sqrt(2)*(x - 1) + 1, 1)
+    assert (ev[1][2][0] - Matrix([
+        [-(-17*x**4 + 12*sqrt(2)*x**4 - 4*sqrt(2)*x**3 + 6*x**3 - 6*x - 4*sqrt(2)*x + 12*sqrt(2) + 17)/(-7*x**4 + 5*sqrt(2)*x**4 - 6*sqrt(2)*x**3 + 8*x**3 - 2*x**2 + 8*x + 6*sqrt(2)*x - 5*sqrt(2) - 7)],
+        [                      (-7*x**3 + 5*sqrt(2)*x**3 - x**2 + sqrt(2)*x**2 - sqrt(2)*x - x - 5*sqrt(2) - 7)/(-3*x**3 + 2*sqrt(2)*x**3 - 2*sqrt(2)*x**2 + 3*x**2 + 2*sqrt(2)*x + 3*x - 3 - 2*sqrt(2))],
+        [                                                                                           -(-3*x**2 + 2*sqrt(2)*x**2 + 2*x - 3 - 2*sqrt(2))/(-x**2 + sqrt(2)*x**2 - 2*sqrt(2)*x + 1 + sqrt(2))],
+        [                                                                                                                                                                                              1]])).expand() == Matrix([[0],[0],[0],[0]])
+    assert ev[2][:2] == (x + sqrt(2)*(x - 1) + 1, 1)
+    assert (ev[2][2][0] - Matrix([
+        [-(12*sqrt(2)*x**4 + 17*x**4 - 6*x**3 - 4*sqrt(2)*x**3 - 4*sqrt(2)*x + 6*x - 17 + 12*sqrt(2))/(7*x**4 + 5*sqrt(2)*x**4 - 6*sqrt(2)*x**3 - 8*x**3 + 2*x**2 - 8*x + 6*sqrt(2)*x - 5*sqrt(2) + 7)],
+        [                      (7*x**3 + 5*sqrt(2)*x**3 + x**2 + sqrt(2)*x**2 - sqrt(2)*x + x - 5*sqrt(2) + 7)/(2*sqrt(2)*x**3 + 3*x**3 - 3*x**2 - 2*sqrt(2)*x**2 - 3*x + 2*sqrt(2)*x - 2*sqrt(2) + 3)],
+        [                                                                                           -(2*sqrt(2)*x**2 + 3*x**2 - 2*x - 2*sqrt(2) + 3)/(x**2 + sqrt(2)*x**2 - 2*sqrt(2)*x - 1 + sqrt(2))],
+        [                                                                                                                                                                                            1]])).expand() == Matrix([[0],[0],[0],[0]])
 
 def test_issue_17247_expression_blowup_14():
     M = Matrix(8, 8, ([1+x, 1-x]*4 + [1-x, 1+x]*4)*4)
-    with dotprodsimp(True):
-        assert M.echelon_form() == Matrix([
-            [x + 1, 1 - x, x + 1, 1 - x, x + 1, 1 - x, x + 1, 1 - x],
-            [    0,   4*x,     0,   4*x,     0,   4*x,     0,   4*x],
-            [    0,     0,     0,     0,     0,     0,     0,     0],
-            [    0,     0,     0,     0,     0,     0,     0,     0],
-            [    0,     0,     0,     0,     0,     0,     0,     0],
-            [    0,     0,     0,     0,     0,     0,     0,     0],
-            [    0,     0,     0,     0,     0,     0,     0,     0],
-            [    0,     0,     0,     0,     0,     0,     0,     0]])
+    assert M.echelon_form() == Matrix([
+        [x + 1, 1 - x, x + 1, 1 - x, x + 1, 1 - x, x + 1, 1 - x],
+        [    0,   4*x,     0,   4*x,     0,   4*x,     0,   4*x],
+        [    0,     0,     0,     0,     0,     0,     0,     0],
+        [    0,     0,     0,     0,     0,     0,     0,     0],
+        [    0,     0,     0,     0,     0,     0,     0,     0],
+        [    0,     0,     0,     0,     0,     0,     0,     0],
+        [    0,     0,     0,     0,     0,     0,     0,     0],
+        [    0,     0,     0,     0,     0,     0,     0,     0]])
 
 def test_issue_17247_expression_blowup_15():
     M = Matrix(8, 8, ([1+x, 1-x]*4 + [1-x, 1+x]*4)*4)
-    with dotprodsimp(True):
-        assert M.rowspace() == [Matrix([[x + 1, 1 - x, x + 1, 1 - x, x + 1, 1 - x, x + 1, 1 - x]]), Matrix([[0, 4*x, 0, 4*x, 0, 4*x, 0, 4*x]])]
+    assert M.rowspace() == [Matrix([[x + 1, 1 - x, x + 1, 1 - x, x + 1, 1 - x, x + 1, 1 - x]]), Matrix([[0, 4*x, 0, 4*x, 0, 4*x, 0, 4*x]])]
 
 def test_issue_17247_expression_blowup_16():
     M = Matrix(8, 8, ([1+x, 1-x]*4 + [1-x, 1+x]*4)*4)
-    with dotprodsimp(True):
-        assert M.columnspace() == [Matrix([[x + 1],[1 - x],[x + 1],[1 - x],[x + 1],[1 - x],[x + 1],[1 - x]]), Matrix([[1 - x],[x + 1],[1 - x],[x + 1],[1 - x],[x + 1],[1 - x],[x + 1]])]
+    assert M.columnspace() == [Matrix([[x + 1],[1 - x],[x + 1],[1 - x],[x + 1],[1 - x],[x + 1],[1 - x]]), Matrix([[1 - x],[x + 1],[1 - x],[x + 1],[1 - x],[x + 1],[1 - x],[x + 1]])]
 
 def test_issue_17247_expression_blowup_17():
     M = Matrix(8, 8, [x+i for i in range (64)])
-    with dotprodsimp(True):
-        assert M.nullspace() == [
-            Matrix([[1],[-2],[1],[0],[0],[0],[0],[0]]),
-            Matrix([[2],[-3],[0],[1],[0],[0],[0],[0]]),
-            Matrix([[3],[-4],[0],[0],[1],[0],[0],[0]]),
-            Matrix([[4],[-5],[0],[0],[0],[1],[0],[0]]),
-            Matrix([[5],[-6],[0],[0],[0],[0],[1],[0]]),
-            Matrix([[6],[-7],[0],[0],[0],[0],[0],[1]])]
+    assert M.nullspace() == [
+        Matrix([[1],[-2],[1],[0],[0],[0],[0],[0]]),
+        Matrix([[2],[-3],[0],[1],[0],[0],[0],[0]]),
+        Matrix([[3],[-4],[0],[0],[1],[0],[0],[0]]),
+        Matrix([[4],[-5],[0],[0],[0],[1],[0],[0]]),
+        Matrix([[5],[-6],[0],[0],[0],[0],[1],[0]]),
+        Matrix([[6],[-7],[0],[0],[0],[0],[0],[1]])]
 
 def test_issue_17247_expression_blowup_18():
     M = Matrix(6, 6, ([1+x, 1-x]*3 + [1-x, 1+x]*3)*3)
-    with dotprodsimp(True):
-        assert not M.is_nilpotent()
+    assert not M.is_nilpotent()
 
 def test_issue_17247_expression_blowup_19():
     M = Matrix(S('''[
@@ -466,8 +447,7 @@ def test_issue_17247_expression_blowup_19():
         [                0, -177/128 - 1369*I/128,                 0, -2063/256 + 541*I/128],
         [          1/2 - I,                     0,                 0,                     0],
         [                0,                     0,                 0, -177/128 - 1369*I/128]]'''))
-    with dotprodsimp(True):
-        assert not M.is_diagonalizable()
+    assert not M.is_diagonalizable()
 
 def test_issue_17247_expression_blowup_20():
     M = Matrix([
@@ -475,17 +455,16 @@ def test_issue_17247_expression_blowup_20():
     [1 - x,  x + 1,      0,  x + 1],
     [    0,  1 - x,  x + 1,      0],
     [    0,      0,      0,  x + 1]])
-    with dotprodsimp(True):
-        assert M.diagonalize() == (Matrix([
-            [1,  1, 0, (x + 1)/(x - 1)],
-            [1, -1, 0,               0],
-            [1,  1, 1,               0],
-            [0,  0, 0,               1]]),
-            Matrix([
-            [2,   0,     0,     0],
-            [0, 2*x,     0,     0],
-            [0,   0, x + 1,     0],
-            [0,   0,     0, x + 1]]))
+    assert M.diagonalize() == (Matrix([
+        [1,  1, 0, (x + 1)/(x - 1)],
+        [1, -1, 0,               0],
+        [1,  1, 1,               0],
+        [0,  0, 0,               1]]),
+        Matrix([
+        [2,   0,     0,     0],
+        [0, 2*x,     0,     0],
+        [0,   0, x + 1,     0],
+        [0,   0,     0, x + 1]]))
 
 def test_issue_17247_expression_blowup_21():
     M = Matrix(S('''[
@@ -493,12 +472,11 @@ def test_issue_17247_expression_blowup_21():
         [-149/64 + 49*I/32, -177/128 - 1369*I/128,                   0, -2063/256 + 541*I/128],
         [                0,         9/4 + 55*I/16, 2473/256 + 137*I/64,                     0],
         [                0,                     0,                   0, -177/128 - 1369*I/128]]'''))
-    with dotprodsimp(True):
-        assert M.inv(method='GE') == Matrix(S('''[
-            [-26194832/3470993 - 31733264*I/3470993, 156352/3470993 + 10325632*I/3470993, 0, -7741283181072/3306971225785 + 2999007604624*I/3306971225785],
-            [4408224/3470993 - 9675328*I/3470993, -2422272/3470993 + 1523712*I/3470993, 0, -1824666489984/3306971225785 - 1401091949952*I/3306971225785],
-            [-26406945676288/22270005630769 + 10245925485056*I/22270005630769, 7453523312640/22270005630769 + 1601616519168*I/22270005630769, 633088/6416033 - 140288*I/6416033, 872209227109521408/21217636514687010905 + 6066405081802389504*I/21217636514687010905],
-            [0, 0, 0, -11328/952745 + 87616*I/952745]]'''))
+    assert M.inv(method='GE') == Matrix(S('''[
+        [-26194832/3470993 - 31733264*I/3470993, 156352/3470993 + 10325632*I/3470993, 0, -7741283181072/3306971225785 + 2999007604624*I/3306971225785],
+        [4408224/3470993 - 9675328*I/3470993, -2422272/3470993 + 1523712*I/3470993, 0, -1824666489984/3306971225785 - 1401091949952*I/3306971225785],
+        [-26406945676288/22270005630769 + 10245925485056*I/22270005630769, 7453523312640/22270005630769 + 1601616519168*I/22270005630769, 633088/6416033 - 140288*I/6416033, 872209227109521408/21217636514687010905 + 6066405081802389504*I/21217636514687010905],
+        [0, 0, 0, -11328/952745 + 87616*I/952745]]'''))
 
 @XFAIL # dotprodsimp is not on by default in this function
 def test_issue_17247_expression_blowup_22():
@@ -507,12 +485,11 @@ def test_issue_17247_expression_blowup_22():
         [-149/64 + 49*I/32, -177/128 - 1369*I/128,                   0, -2063/256 + 541*I/128],
         [                0,         9/4 + 55*I/16, 2473/256 + 137*I/64,                     0],
         [                0,                     0,                   0, -177/128 - 1369*I/128]]'''))
-    with dotprodsimp(True):
-        assert M.inv(method='LU') == Matrix(S('''[
-            [-26194832/3470993 - 31733264*I/3470993, 156352/3470993 + 10325632*I/3470993, 0, -7741283181072/3306971225785 + 2999007604624*I/3306971225785],
-            [4408224/3470993 - 9675328*I/3470993, -2422272/3470993 + 1523712*I/3470993, 0, -1824666489984/3306971225785 - 1401091949952*I/3306971225785],
-            [-26406945676288/22270005630769 + 10245925485056*I/22270005630769, 7453523312640/22270005630769 + 1601616519168*I/22270005630769, 633088/6416033 - 140288*I/6416033, 872209227109521408/21217636514687010905 + 6066405081802389504*I/21217636514687010905],
-            [0, 0, 0, -11328/952745 + 87616*I/952745]]'''))
+    assert M.inv(method='LU') == Matrix(S('''[
+        [-26194832/3470993 - 31733264*I/3470993, 156352/3470993 + 10325632*I/3470993, 0, -7741283181072/3306971225785 + 2999007604624*I/3306971225785],
+        [4408224/3470993 - 9675328*I/3470993, -2422272/3470993 + 1523712*I/3470993, 0, -1824666489984/3306971225785 - 1401091949952*I/3306971225785],
+        [-26406945676288/22270005630769 + 10245925485056*I/22270005630769, 7453523312640/22270005630769 + 1601616519168*I/22270005630769, 633088/6416033 - 140288*I/6416033, 872209227109521408/21217636514687010905 + 6066405081802389504*I/21217636514687010905],
+        [0, 0, 0, -11328/952745 + 87616*I/952745]]'''))
 
 def test_issue_17247_expression_blowup_23():
     M = Matrix(S('''[
@@ -520,12 +497,11 @@ def test_issue_17247_expression_blowup_23():
         [-149/64 + 49*I/32, -177/128 - 1369*I/128,                   0, -2063/256 + 541*I/128],
         [                0,         9/4 + 55*I/16, 2473/256 + 137*I/64,                     0],
         [                0,                     0,                   0, -177/128 - 1369*I/128]]'''))
-    with dotprodsimp(True):
-        assert M.inv(method='ADJ').expand() == Matrix(S('''[
-            [-26194832/3470993 - 31733264*I/3470993, 156352/3470993 + 10325632*I/3470993, 0, -7741283181072/3306971225785 + 2999007604624*I/3306971225785],
-            [4408224/3470993 - 9675328*I/3470993, -2422272/3470993 + 1523712*I/3470993, 0, -1824666489984/3306971225785 - 1401091949952*I/3306971225785],
-            [-26406945676288/22270005630769 + 10245925485056*I/22270005630769, 7453523312640/22270005630769 + 1601616519168*I/22270005630769, 633088/6416033 - 140288*I/6416033, 872209227109521408/21217636514687010905 + 6066405081802389504*I/21217636514687010905],
-            [0, 0, 0, -11328/952745 + 87616*I/952745]]'''))
+    assert M.inv(method='ADJ').expand() == Matrix(S('''[
+        [-26194832/3470993 - 31733264*I/3470993, 156352/3470993 + 10325632*I/3470993, 0, -7741283181072/3306971225785 + 2999007604624*I/3306971225785],
+        [4408224/3470993 - 9675328*I/3470993, -2422272/3470993 + 1523712*I/3470993, 0, -1824666489984/3306971225785 - 1401091949952*I/3306971225785],
+        [-26406945676288/22270005630769 + 10245925485056*I/22270005630769, 7453523312640/22270005630769 + 1601616519168*I/22270005630769, 633088/6416033 - 140288*I/6416033, 872209227109521408/21217636514687010905 + 6066405081802389504*I/21217636514687010905],
+        [0, 0, 0, -11328/952745 + 87616*I/952745]]'''))
 
 @XFAIL # dotprodsimp is not on by default in this function
 def test_issue_17247_expression_blowup_24():
@@ -534,12 +510,11 @@ def test_issue_17247_expression_blowup_24():
         [-149/64 + 49*I/32, -177/128 - 1369*I/128,                   0, -2063/256 + 541*I/128],
         [                0,         9/4 + 55*I/16, 2473/256 + 137*I/64,                     0],
         [                0,                     0,                   0, -177/128 - 1369*I/128]]'''))
-    with dotprodsimp(True):
-        assert M.inv(method='CH') == Matrix(S('''[
-            [-26194832/3470993 - 31733264*I/3470993, 156352/3470993 + 10325632*I/3470993, 0, -7741283181072/3306971225785 + 2999007604624*I/3306971225785],
-            [4408224/3470993 - 9675328*I/3470993, -2422272/3470993 + 1523712*I/3470993, 0, -1824666489984/3306971225785 - 1401091949952*I/3306971225785],
-            [-26406945676288/22270005630769 + 10245925485056*I/22270005630769, 7453523312640/22270005630769 + 1601616519168*I/22270005630769, 633088/6416033 - 140288*I/6416033, 872209227109521408/21217636514687010905 + 6066405081802389504*I/21217636514687010905],
-            [0, 0, 0, -11328/952745 + 87616*I/952745]]'''))
+    assert M.inv(method='CH') == Matrix(S('''[
+        [-26194832/3470993 - 31733264*I/3470993, 156352/3470993 + 10325632*I/3470993, 0, -7741283181072/3306971225785 + 2999007604624*I/3306971225785],
+        [4408224/3470993 - 9675328*I/3470993, -2422272/3470993 + 1523712*I/3470993, 0, -1824666489984/3306971225785 - 1401091949952*I/3306971225785],
+        [-26406945676288/22270005630769 + 10245925485056*I/22270005630769, 7453523312640/22270005630769 + 1601616519168*I/22270005630769, 633088/6416033 - 140288*I/6416033, 872209227109521408/21217636514687010905 + 6066405081802389504*I/21217636514687010905],
+        [0, 0, 0, -11328/952745 + 87616*I/952745]]'''))
 
 @XFAIL # dotprodsimp is not on by default in this function
 def test_issue_17247_expression_blowup_25():
@@ -548,12 +523,11 @@ def test_issue_17247_expression_blowup_25():
         [-149/64 + 49*I/32, -177/128 - 1369*I/128,                   0, -2063/256 + 541*I/128],
         [                0,         9/4 + 55*I/16, 2473/256 + 137*I/64,                     0],
         [                0,                     0,                   0, -177/128 - 1369*I/128]]'''))
-    with dotprodsimp(True):
-        assert M.inv(method='LDL') == Matrix(S('''[
-            [-26194832/3470993 - 31733264*I/3470993, 156352/3470993 + 10325632*I/3470993, 0, -7741283181072/3306971225785 + 2999007604624*I/3306971225785],
-            [4408224/3470993 - 9675328*I/3470993, -2422272/3470993 + 1523712*I/3470993, 0, -1824666489984/3306971225785 - 1401091949952*I/3306971225785],
-            [-26406945676288/22270005630769 + 10245925485056*I/22270005630769, 7453523312640/22270005630769 + 1601616519168*I/22270005630769, 633088/6416033 - 140288*I/6416033, 872209227109521408/21217636514687010905 + 6066405081802389504*I/21217636514687010905],
-            [0, 0, 0, -11328/952745 + 87616*I/952745]]'''))
+    assert M.inv(method='LDL') == Matrix(S('''[
+        [-26194832/3470993 - 31733264*I/3470993, 156352/3470993 + 10325632*I/3470993, 0, -7741283181072/3306971225785 + 2999007604624*I/3306971225785],
+        [4408224/3470993 - 9675328*I/3470993, -2422272/3470993 + 1523712*I/3470993, 0, -1824666489984/3306971225785 - 1401091949952*I/3306971225785],
+        [-26406945676288/22270005630769 + 10245925485056*I/22270005630769, 7453523312640/22270005630769 + 1601616519168*I/22270005630769, 633088/6416033 - 140288*I/6416033, 872209227109521408/21217636514687010905 + 6066405081802389504*I/21217636514687010905],
+        [0, 0, 0, -11328/952745 + 87616*I/952745]]'''))
 
 def test_issue_17247_expression_blowup_26():
     M = Matrix(S('''[
@@ -565,8 +539,7 @@ def test_issue_17247_expression_blowup_26():
         [         21/8 + I,    -537/64 + 143*I/16,    -5/8 - 39*I/16,   2473/256 + 137*I/64, -149/64 + 49*I/32, -177/128 - 1369*I/128,     125/64 + 87*I/64,   -2063/256 + 541*I/128],
         [               -2,         17/4 - 13*I/2,             1 + I,         -19/4 + 5*I/4,           1/2 - I,         9/4 + 55*I/16,                 -3/4,         45/32 - 37*I/16],
         [     1/4 + 13*I/4,    -825/64 - 147*I/32,          21/8 + I,    -537/64 + 143*I/16,    -5/8 - 39*I/16,   2473/256 + 137*I/64,    -149/64 + 49*I/32,   -177/128 - 1369*I/128]]'''))
-    with dotprodsimp(True):
-        assert M.rank() == 4
+    assert M.rank() == 4
 
 def test_issue_17247_expression_blowup_27():
     M = Matrix([
@@ -574,18 +547,17 @@ def test_issue_17247_expression_blowup_27():
         [1 - x, x + 1,     0, x + 1],
         [    0, 1 - x, x + 1, 1 - x],
         [    0,     0,     1 - x, 0]])
-    with dotprodsimp(True):
-        P, J = M.jordan_form()
-        assert P.expand() == Matrix(S('''[
-            [    0,  4*x/(x**2 - 2*x + 1), -(-17*x**4 + 12*sqrt(2)*x**4 - 4*sqrt(2)*x**3 + 6*x**3 - 6*x - 4*sqrt(2)*x + 12*sqrt(2) + 17)/(-7*x**4 + 5*sqrt(2)*x**4 - 6*sqrt(2)*x**3 + 8*x**3 - 2*x**2 + 8*x + 6*sqrt(2)*x - 5*sqrt(2) - 7), -(12*sqrt(2)*x**4 + 17*x**4 - 6*x**3 - 4*sqrt(2)*x**3 - 4*sqrt(2)*x + 6*x - 17 + 12*sqrt(2))/(7*x**4 + 5*sqrt(2)*x**4 - 6*sqrt(2)*x**3 - 8*x**3 + 2*x**2 - 8*x + 6*sqrt(2)*x - 5*sqrt(2) + 7)],
-            [x - 1, x/(x - 1) + 1/(x - 1),                       (-7*x**3 + 5*sqrt(2)*x**3 - x**2 + sqrt(2)*x**2 - sqrt(2)*x - x - 5*sqrt(2) - 7)/(-3*x**3 + 2*sqrt(2)*x**3 - 2*sqrt(2)*x**2 + 3*x**2 + 2*sqrt(2)*x + 3*x - 3 - 2*sqrt(2)),                       (7*x**3 + 5*sqrt(2)*x**3 + x**2 + sqrt(2)*x**2 - sqrt(2)*x + x - 5*sqrt(2) + 7)/(2*sqrt(2)*x**3 + 3*x**3 - 3*x**2 - 2*sqrt(2)*x**2 - 3*x + 2*sqrt(2)*x - 2*sqrt(2) + 3)],
-            [    0,                     1,                                                                                            -(-3*x**2 + 2*sqrt(2)*x**2 + 2*x - 3 - 2*sqrt(2))/(-x**2 + sqrt(2)*x**2 - 2*sqrt(2)*x + 1 + sqrt(2)),                                                                                            -(2*sqrt(2)*x**2 + 3*x**2 - 2*x - 2*sqrt(2) + 3)/(x**2 + sqrt(2)*x**2 - 2*sqrt(2)*x - 1 + sqrt(2))],
-            [1 - x,                     0,                                                                                                                                                                                               1,                                                                                                                                                                                             1]]''')).expand()
-        assert J == Matrix(S('''[
-            [0, 1,                       0,                       0],
-            [0, 0,                       0,                       0],
-            [0, 0, x - sqrt(2)*(x - 1) + 1,                       0],
-            [0, 0,                       0, x + sqrt(2)*(x - 1) + 1]]'''))
+    P, J = M.jordan_form()
+    assert P.expand() == Matrix(S('''[
+        [    0,  4*x/(x**2 - 2*x + 1), -(-17*x**4 + 12*sqrt(2)*x**4 - 4*sqrt(2)*x**3 + 6*x**3 - 6*x - 4*sqrt(2)*x + 12*sqrt(2) + 17)/(-7*x**4 + 5*sqrt(2)*x**4 - 6*sqrt(2)*x**3 + 8*x**3 - 2*x**2 + 8*x + 6*sqrt(2)*x - 5*sqrt(2) - 7), -(12*sqrt(2)*x**4 + 17*x**4 - 6*x**3 - 4*sqrt(2)*x**3 - 4*sqrt(2)*x + 6*x - 17 + 12*sqrt(2))/(7*x**4 + 5*sqrt(2)*x**4 - 6*sqrt(2)*x**3 - 8*x**3 + 2*x**2 - 8*x + 6*sqrt(2)*x - 5*sqrt(2) + 7)],
+        [x - 1, x/(x - 1) + 1/(x - 1),                       (-7*x**3 + 5*sqrt(2)*x**3 - x**2 + sqrt(2)*x**2 - sqrt(2)*x - x - 5*sqrt(2) - 7)/(-3*x**3 + 2*sqrt(2)*x**3 - 2*sqrt(2)*x**2 + 3*x**2 + 2*sqrt(2)*x + 3*x - 3 - 2*sqrt(2)),                       (7*x**3 + 5*sqrt(2)*x**3 + x**2 + sqrt(2)*x**2 - sqrt(2)*x + x - 5*sqrt(2) + 7)/(2*sqrt(2)*x**3 + 3*x**3 - 3*x**2 - 2*sqrt(2)*x**2 - 3*x + 2*sqrt(2)*x - 2*sqrt(2) + 3)],
+        [    0,                     1,                                                                                            -(-3*x**2 + 2*sqrt(2)*x**2 + 2*x - 3 - 2*sqrt(2))/(-x**2 + sqrt(2)*x**2 - 2*sqrt(2)*x + 1 + sqrt(2)),                                                                                            -(2*sqrt(2)*x**2 + 3*x**2 - 2*x - 2*sqrt(2) + 3)/(x**2 + sqrt(2)*x**2 - 2*sqrt(2)*x - 1 + sqrt(2))],
+        [1 - x,                     0,                                                                                                                                                                                               1,                                                                                                                                                                                             1]]''')).expand()
+    assert J == Matrix(S('''[
+        [0, 1,                       0,                       0],
+        [0, 0,                       0,                       0],
+        [0, 0, x - sqrt(2)*(x - 1) + 1,                       0],
+        [0, 0,                       0, x + sqrt(2)*(x - 1) + 1]]'''))
 
 def test_issue_17247_expression_blowup_28():
     M = Matrix(S('''[
@@ -593,67 +565,11 @@ def test_issue_17247_expression_blowup_28():
         [-149/64 + 49*I/32, -177/128 - 1369*I/128,                   0, -2063/256 + 541*I/128],
         [                0,         9/4 + 55*I/16, 2473/256 + 137*I/64,                     0],
         [                0,                     0,                   0, -177/128 - 1369*I/128]]'''))
-    with dotprodsimp(True):
-        assert M.singular_values() == S('''[
-            sqrt(14609315/131072 + sqrt(64789115132571/2147483648 - 2*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3) + 76627253330829751075/(35184372088832*sqrt(64789115132571/4294967296 + 3546944054712886603889144627/(110680464442257309696*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3)) + 2*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3))) - 3546944054712886603889144627/(110680464442257309696*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3)))/2 + sqrt(64789115132571/4294967296 + 3546944054712886603889144627/(110680464442257309696*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3)) + 2*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3))/2),
-            sqrt(14609315/131072 - sqrt(64789115132571/2147483648 - 2*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3) + 76627253330829751075/(35184372088832*sqrt(64789115132571/4294967296 + 3546944054712886603889144627/(110680464442257309696*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3)) + 2*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3))) - 3546944054712886603889144627/(110680464442257309696*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3)))/2 + sqrt(64789115132571/4294967296 + 3546944054712886603889144627/(110680464442257309696*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3)) + 2*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3))/2),
-            sqrt(14609315/131072 - sqrt(64789115132571/4294967296 + 3546944054712886603889144627/(110680464442257309696*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3)) + 2*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3))/2 + sqrt(64789115132571/2147483648 - 2*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3) - 76627253330829751075/(35184372088832*sqrt(64789115132571/4294967296 + 3546944054712886603889144627/(110680464442257309696*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3)) + 2*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3))) - 3546944054712886603889144627/(110680464442257309696*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3)))/2),
-            sqrt(14609315/131072 - sqrt(64789115132571/4294967296 + 3546944054712886603889144627/(110680464442257309696*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3)) + 2*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3))/2 - sqrt(64789115132571/2147483648 - 2*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3) - 76627253330829751075/(35184372088832*sqrt(64789115132571/4294967296 + 3546944054712886603889144627/(110680464442257309696*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3)) + 2*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3))) - 3546944054712886603889144627/(110680464442257309696*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3)))/2)]''')
-
-def test_issue_17247_expression_blowup_29():
-    M = Matrix(S('''[
-        [             -3/4,       45/32 - 37*I/16,                   0,                     0],
-        [-149/64 + 49*I/32, -177/128 - 1369*I/128,                   0, -2063/256 + 541*I/128],
-        [                0,         9/4 + 55*I/16, 2473/256 + 137*I/64,                     0],
-        [                0,                     0,                   0, -177/128 - 1369*I/128]]'''))
-    with dotprodsimp(True):
-        assert M.gauss_jordan_solve(ones(4, 1)) == (Matrix(S('''[
-            [                          -32549314808672/3306971225785 - 17397006745216*I/3306971225785],
-            [                               67439348256/3306971225785 - 9167503335872*I/3306971225785],
-            [-15091965363354518272/21217636514687010905 + 16890163109293858304*I/21217636514687010905],
-            [                                                          -11328/952745 + 87616*I/952745]]''')), Matrix(0, 1, []))
-
-@XFAIL # dotprodsimp is not on by default in this function
-def test_issue_17247_expression_blowup_30():
-    M = Matrix(S('''[
-        [             -3/4,       45/32 - 37*I/16,                   0,                     0],
-        [-149/64 + 49*I/32, -177/128 - 1369*I/128,                   0, -2063/256 + 541*I/128],
-        [                0,         9/4 + 55*I/16, 2473/256 + 137*I/64,                     0],
-        [                0,                     0,                   0, -177/128 - 1369*I/128]]'''))
-    with dotprodsimp(True):
-        assert M.cholesky_solve(ones(4, 1)) == Matrix(S('''[
-            [                          -32549314808672/3306971225785 - 17397006745216*I/3306971225785],
-            [                               67439348256/3306971225785 - 9167503335872*I/3306971225785],
-            [-15091965363354518272/21217636514687010905 + 16890163109293858304*I/21217636514687010905],
-            [                                                          -11328/952745 + 87616*I/952745]]'''))
-
-# This test is commented out because without dotprodsimp this calculation hangs.
-# @XFAIL # dotprodsimp is not on by default in this function
-# def test_issue_17247_expression_blowup_31():
-#     M = Matrix([
-#         [x + 1, 1 - x,     0,     0],
-#         [1 - x, x + 1,     0, x + 1],
-#         [    0, 1 - x, x + 1,     0],
-#         [    0,     0,     0, x + 1]])
-#     assert M.LDLsolve(ones(4, 1)) == Matrix([
-#         [(x + 1)/(4*x)],
-#         [(x - 1)/(4*x)],
-#         [(x + 1)/(4*x)],
-#         [    1/(x + 1)]])
-
-@XFAIL # dotprodsimp is not on by default in this function
-def test_issue_17247_expression_blowup_32():
-    M = Matrix([
-        [x + 1, 1 - x,     0,     0],
-        [1 - x, x + 1,     0, x + 1],
-        [    0, 1 - x, x + 1,     0],
-        [    0,     0,     0, x + 1]])
-    with dotprodsimp(True):
-        assert M.LUsolve(ones(4, 1)) == Matrix([
-            [(x + 1)/(4*x)],
-            [(x - 1)/(4*x)],
-            [(x + 1)/(4*x)],
-            [    1/(x + 1)]])
+    assert M.singular_values() == S('''[
+        sqrt(14609315/131072 + sqrt(64789115132571/2147483648 - 2*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3) + 76627253330829751075/(35184372088832*sqrt(64789115132571/4294967296 + 3546944054712886603889144627/(110680464442257309696*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3)) + 2*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3))) - 3546944054712886603889144627/(110680464442257309696*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3)))/2 + sqrt(64789115132571/4294967296 + 3546944054712886603889144627/(110680464442257309696*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3)) + 2*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3))/2),
+        sqrt(14609315/131072 - sqrt(64789115132571/2147483648 - 2*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3) + 76627253330829751075/(35184372088832*sqrt(64789115132571/4294967296 + 3546944054712886603889144627/(110680464442257309696*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3)) + 2*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3))) - 3546944054712886603889144627/(110680464442257309696*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3)))/2 + sqrt(64789115132571/4294967296 + 3546944054712886603889144627/(110680464442257309696*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3)) + 2*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3))/2),
+        sqrt(14609315/131072 - sqrt(64789115132571/4294967296 + 3546944054712886603889144627/(110680464442257309696*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3)) + 2*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3))/2 + sqrt(64789115132571/2147483648 - 2*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3) - 76627253330829751075/(35184372088832*sqrt(64789115132571/4294967296 + 3546944054712886603889144627/(110680464442257309696*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3)) + 2*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3))) - 3546944054712886603889144627/(110680464442257309696*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3)))/2),
+        sqrt(14609315/131072 - sqrt(64789115132571/4294967296 + 3546944054712886603889144627/(110680464442257309696*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3)) + 2*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3))/2 - sqrt(64789115132571/2147483648 - 2*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3) - 76627253330829751075/(35184372088832*sqrt(64789115132571/4294967296 + 3546944054712886603889144627/(110680464442257309696*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3)) + 2*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3))) - 3546944054712886603889144627/(110680464442257309696*(25895222463957462655758224991455280215303/633825300114114700748351602688 + sqrt(1213909058710955930446995195883114969038524625997915131236390724543989220134670)*I/22282920707136844948184236032)**(1/3)))/2)]''')
 
 
 def test_issue_16823():
@@ -671,8 +587,7 @@ def test_issue_16823():
         [1,-9/4+3*I,-2*I,119/8+29/4*I,1/4+5/2*I,-23/8-57/16*I,1/4+13/4*I,-825/64-147/32*I,21/8+I,-537/64+143/16*I,-5/8-39/16*I,2473/256+137/64*I,-149/64+49/32*I,-177/128-1369/128*I,125/64+87/64*I,-2063/256+541/128*I],
         [0,-4*I,0,-6,-4,9-5*I,-4*I,27/2+6*I,-2,17/4-13/2*I,1+I,-19/4+5/4*I,1/2-I,9/4+55/16*I,-3/4,45/32-37/16*I],
         [0,1/4+1/2*I,1,-9/4+3*I,-2*I,119/8+29/4*I,1/4+5/2*I,-23/8-57/16*I,1/4+13/4*I,-825/64-147/32*I,21/8+I,-537/64+143/16*I,-5/8-39/16*I,2473/256+137/64*I,-149/64+49/32*I,-177/128-1369/128*I]]'''))
-    with dotprodsimp(True):
-        assert M.rank() == 8
+    assert M.rank() == 8
 
 
 def test_issue_18531():
@@ -687,16 +602,15 @@ def test_issue_18531():
         [-3 + 2*sqrt(2), -3 - 2*sqrt(2), -3 - 2*sqrt(2), -3 + 2*sqrt(2), -1, 2, -1, -2, 0],
         [1 - sqrt(2), -sqrt(2) - 1, 1 + sqrt(2), -1 + sqrt(2), -1, 1, 1, 1, 1]
         ])
-    with dotprodsimp(True):
-        assert M.rref() == (Matrix([
-            [1, 0, 0, 0, 0, 0, 0, 0,  1/2],
-            [0, 1, 0, 0, 0, 0, 0, 0, -1/2],
-            [0, 0, 1, 0, 0, 0, 0, 0,  1/2],
-            [0, 0, 0, 1, 0, 0, 0, 0, -1/2],
-            [0, 0, 0, 0, 1, 0, 0, 0,    0],
-            [0, 0, 0, 0, 0, 1, 0, 0, -1/2],
-            [0, 0, 0, 0, 0, 0, 1, 0,    0],
-            [0, 0, 0, 0, 0, 0, 0, 1, -1/2]]), (0, 1, 2, 3, 4, 5, 6, 7))
+    assert M.rref() == (Matrix([
+        [1, 0, 0, 0, 0, 0, 0, 0,  1/2],
+        [0, 1, 0, 0, 0, 0, 0, 0, -1/2],
+        [0, 0, 1, 0, 0, 0, 0, 0,  1/2],
+        [0, 0, 0, 1, 0, 0, 0, 0, -1/2],
+        [0, 0, 0, 0, 1, 0, 0, 0,    0],
+        [0, 0, 0, 0, 0, 1, 0, 0, -1/2],
+        [0, 0, 0, 0, 0, 0, 1, 0,    0],
+        [0, 0, 0, 0, 0, 0, 0, 1, -1/2]]), (0, 1, 2, 3, 4, 5, 6, 7))
 
 
 def test_creation():
diff --git a/sympy/polys/tests/test_partfrac.py b/sympy/polys/tests/test_partfrac.py
index 6d19b4174f..aa697ec448 100644
--- a/sympy/polys/tests/test_partfrac.py
+++ b/sympy/polys/tests/test_partfrac.py
@@ -9,7 +9,7 @@
 
 from sympy import (S, Poly, E, pi, I, Matrix, Eq, RootSum, Lambda,
                    Symbol, Dummy, factor, together, sqrt, Expr, Rational)
-from sympy.testing.pytest import raises, ON_TRAVIS, skip, XFAIL
+from sympy.testing.pytest import raises, XFAIL
 from sympy.abc import x, y, a, b, c
 
 
@@ -74,23 +74,6 @@ def test_apart_symbolic():
         1/((a - b)*(a - c)*(a + x))
 
 
-def _make_extension_example():
-    # https://github.com/sympy/sympy/issues/18531
-    from sympy.core import Mul
-    def mul2(expr):
-        # 2-arg mul hack...
-        return Mul(2, expr, evaluate=False)
-
-    f = ((x**2 + 1)**3/((x - 1)**2*(x + 1)**2*(-x**2 + 2*x + 1)*(x**2 + 2*x - 1)))
-    g = (1/mul2(x - sqrt(2) + 1)
-       - 1/mul2(x - sqrt(2) - 1)
-       + 1/mul2(x + 1 + sqrt(2))
-       - 1/mul2(x - 1 + sqrt(2))
-       + 1/mul2((x + 1)**2)
-       + 1/mul2((x - 1)**2))
-    return f, g
-
-
 def test_apart_extension():
     f = 2/(x**2 + 1)
     g = I/(x + I) - I/(x - I)
@@ -102,22 +85,6 @@ def test_apart_extension():
 
     assert factor(together(apart(f)).expand()) == f
 
-    f, g = _make_extension_example()
-
-    # XXX: Only works with dotprodsimp. See test_apart_extension_xfail below
-    from sympy.matrices import dotprodsimp
-    with dotprodsimp(True):
-        assert apart(f, x, extension={sqrt(2)}) == g
-
-
-# XXX: This is XFAIL just because it is slow
-@XFAIL
-def test_apart_extension_xfail():
-    if ON_TRAVIS:
-        skip('Too slow for Travis')
-    f, g = _make_extension_example()
-    assert apart(f, x, extension={sqrt(2)}) == g
-
 
 def test_apart_full():
     f = 1/(x**2 + 1)
diff --git a/sympy/utilities/tests/test_wester.py b/sympy/utilities/tests/test_wester.py
index 1db289c0fc..c5dc300806 100644
--- a/sympy/utilities/tests/test_wester.py
+++ b/sympy/utilities/tests/test_wester.py
@@ -1594,20 +1594,31 @@ def test_P27():
                 [0,  0, a, 0, 0],
                 [0,  0, 0, a, 0],
                 [0, -2, 0, 0, 2]])
-
-    assert M.eigenvects() == [
-        (a, 3, [
-            Matrix([1, 0, 0, 0, 0]),
-            Matrix([0, 0, 1, 0, 0]),
-            Matrix([0, 0, 0, 1, 0])
-        ]),
-        (1 - I, 1, [
-            Matrix([0, S(1)/2 + I/2, 0, 0, 1])
-        ]),
-        (1 + I, 1, [
-            Matrix([0, S(1)/2 - I/2, 0, 0, 1])
-        ]),
-    ]
+    assert M.eigenvects() == [(a, 3, [Matrix([[1],
+                                       [0],
+                                       [0],
+                                       [0],
+                                       [0]]),
+                               Matrix([[0],
+                                       [0],
+                                       [1],
+                                       [0],
+                                       [0]]),
+                               Matrix([[0],
+                                       [0],
+                                       [0],
+                                       [1],
+                                       [0]])]),
+                        (1 - I, 1, [Matrix([[           0],
+                                            [S(1)/2 + I/2],
+                                            [           0],
+                                            [           0],
+                                            [           1]])]),
+                        (1 + I, 1, [Matrix([[           0],
+                                            [S(1)/2 - I/2],
+                                            [           0],
+                                            [           0],
+                                            [           1]])])]
 
 
 @XFAIL