Repository: sympy/sympy

Issue:
`CRootOf` should have a `lazy` option
When you construct a `CRootOf`, it makes an initial approximation of the roots
right then, at construction time. It would be good if `CRootOf` offered a `lazy` option, so
that these approximations wouldn't be computed until they were needed.

I imagine this might have many applications, but at the moment I just have one application in mind:
When you form an `AlgebraicNumber` whose root is given by a `CRootOf`, it can be extremely slow, due
to this approximation of roots.

This is not good, because there are many things you can do with an `AlgebraicNumber` that do not
require these approximations at all. For many applications, it is just wasted time.

For example, just forming a field:

```python
>>> import time
>>> from sympy import QQ
>>> t0 = time.time(); k = QQ.cyclotomic_field(47); t1=time.time();
>>> print(t1-t0)
39.494821071624756
```

can take 40 seconds. This should be instantaneous.

Discussion:

Patch:
diff --git a/.github/workflows/ci-sage.yml b/.github/workflows/ci-sage.yml
index 165cb84997..639f22642e 100644
--- a/.github/workflows/ci-sage.yml
+++ b/.github/workflows/ci-sage.yml
@@ -91,9 +91,9 @@ jobs:
       fail-fast: false
       max-parallel: 32
       matrix:
-        # ubuntu-focal uses system python 3.8
+        # debian-buster uses system python 3.7
         # archlinux-latest is at the cutting edge
-        tox_system_factor: [ubuntu-focal, archlinux-latest]
+        tox_system_factor: [debian-buster, archlinux-latest]
         # "standard" installs lots of system packages, reducing the full build and test of the
         # Sage distribution to 3-4 hours
         tox_packages_factor: [standard]
diff --git a/.mailmap b/.mailmap
index aa099638f1..c730fae84e 100644
--- a/.mailmap
+++ b/.mailmap
@@ -1388,7 +1388,6 @@ damianos <damianos@semmle.com>
 dandiez <47832466+dandiez@users.noreply.github.com>
 der-blaue-elefant <github@kklein.de>
 dimasvq <dimas.vq.2020@bristol.ac.uk>
-dispasha <dispasha@users.noreply.github.com>
 dps7ud <dps7ud@virginia.edu>
 dranknight09 <cbhaavan@gmail.com>
 dustyrockpyle <dustyrockpyle@gmail.com>
diff --git a/sympy/parsing/mathematica.py b/sympy/parsing/mathematica.py
index 7a817b26cc..65fb5374da 100644
--- a/sympy/parsing/mathematica.py
+++ b/sympy/parsing/mathematica.py
@@ -632,25 +632,7 @@ def _from_mathematica_to_tokens(self, code: str):
                 raise SyntaxError("mismatch in comment (*  *) code")
             code = code[:pos_comment_start] + code[pos_comment_end+2:]
 
-        # Find strings:
-        code_splits: List[typing.Union[str, list]] = []
-        while True:
-            string_start = code.find("\"")
-            if string_start == -1:
-                if len(code) > 0:
-                    code_splits.append(code)
-                break
-            match_end = re.search(r'(?<!\\)"', code[string_start+1:])
-            if match_end is None:
-                raise SyntaxError('mismatch in string "  " expression')
-            string_end = string_start + match_end.start() + 1
-            if string_start > 0:
-                code_splits.append(code[:string_start])
-            code_splits.append(["_Str", code[string_start+1:string_end].replace('\\"', '"')])
-            code = code[string_end+1:]
-
-        token_lists = [tokenizer.findall(i) if isinstance(i, str) else [i] for i in code_splits]
-        tokens = [j for i in token_lists for j in i]
+        tokens = tokenizer.findall(code)
 
         # Remove newlines at the beginning
         while tokens and tokens[0] == "\n":
diff --git a/sympy/polys/rootoftools.py b/sympy/polys/rootoftools.py
index e015aec9d1..033ace89db 100644
--- a/sympy/polys/rootoftools.py
+++ b/sympy/polys/rootoftools.py
@@ -356,7 +356,7 @@ def __new__(cls, f, x, index=None, radicals=False, expand=True):
         if not dom.is_ZZ:
             raise NotImplementedError("CRootOf is not supported over %s" % dom)
 
-        root = cls._indexed_root(poly, index)
+        root = cls._indexed_root(poly, index, lazy=True)
         return coeff * cls._postprocess_root(root, radicals)
 
     @classmethod
@@ -395,10 +395,12 @@ def free_symbols(self):
 
     def _eval_is_real(self):
         """Return ``True`` if the root is real. """
+        self._ensure_reals_init()
         return self.index < len(_reals_cache[self.poly])
 
     def _eval_is_imaginary(self):
         """Return ``True`` if the root is imaginary. """
+        self._ensure_reals_init()
         if self.index >= len(_reals_cache[self.poly]):
             ivl = self._get_interval()
             return ivl.ax*ivl.bx <= 0  # all others are on one side or the other
@@ -636,10 +638,16 @@ def _count_roots(cls, roots):
         return sum([k for _, _, k in roots])
 
     @classmethod
-    def _indexed_root(cls, poly, index):
+    def _indexed_root(cls, poly, index, lazy=False):
         """Get a root of a composite polynomial by index. """
         factors = _pure_factors(poly)
 
+        # If the given poly is already irreducible, then the index does not
+        # need to be adjusted, and we can postpone the heavy lifting of
+        # computing and refining isolating intervals until that is needed.
+        if lazy and len(factors) == 1 and factors[0][1] == 1:
+            return poly, index
+
         reals = cls._get_reals(factors)
         reals_count = cls._count_roots(reals)
 
@@ -649,6 +657,16 @@ def _indexed_root(cls, poly, index):
             complexes = cls._get_complexes(factors)
             return cls._complexes_index(complexes, index - reals_count)
 
+    def _ensure_reals_init(self):
+        """Ensure that our poly has entries in the reals cache. """
+        if self.poly not in _reals_cache:
+            self._indexed_root(self.poly, self.index)
+
+    def _ensure_complexes_init(self):
+        """Ensure that our poly has entries in the complexes cache. """
+        if self.poly not in _complexes_cache:
+            self._indexed_root(self.poly, self.index)
+
     @classmethod
     def _real_roots(cls, poly):
         """Get real roots of a composite polynomial. """
@@ -779,18 +797,22 @@ def clear_cache(cls):
 
     def _get_interval(self):
         """Internal function for retrieving isolation interval from cache. """
+        self._ensure_reals_init()
         if self.is_real:
             return _reals_cache[self.poly][self.index]
         else:
             reals_count = len(_reals_cache[self.poly])
+            self._ensure_complexes_init()
             return _complexes_cache[self.poly][self.index - reals_count]
 
     def _set_interval(self, interval):
         """Internal function for updating isolation interval in cache. """
+        self._ensure_reals_init()
         if self.is_real:
             _reals_cache[self.poly][self.index] = interval
         else:
             reals_count = len(_reals_cache[self.poly])
+            self._ensure_complexes_init()
             _complexes_cache[self.poly][self.index - reals_count] = interval
 
     def _eval_subs(self, old, new):
diff --git a/sympy/printing/latex.py b/sympy/printing/latex.py
index 6653b9468e..99f8579b24 100644
--- a/sympy/printing/latex.py
+++ b/sympy/printing/latex.py
@@ -1073,6 +1073,7 @@ def _print_Abs(self, expr, exp=None):
             return r"%s^{%s}" % (tex, exp)
         else:
             return tex
+    _print_Determinant = _print_Abs
 
     def _print_re(self, expr, exp=None):
         if self._settings['gothic_re_im']:
@@ -1663,7 +1664,7 @@ def _print_Piecewise(self, expr):
         tex = r"\begin{cases} %s \end{cases}"
         return tex % r" \\".join(ecpairs)
 
-    def _print_matrix_contents(self, expr):
+    def _print_MatrixBase(self, expr):
         lines = []
 
         for line in range(expr.rows):  # horrible, should be 'rows'
@@ -1683,16 +1684,12 @@ def _print_matrix_contents(self, expr):
         out_str = out_str.replace('%MATSTR%', mat_str)
         if mat_str == 'array':
             out_str = out_str.replace('%s', '{' + 'c'*expr.cols + '}%s')
-        return out_str % r"\\".join(lines)
-
-    def _print_MatrixBase(self, expr):
-        out_str = self._print_matrix_contents(expr)
         if self._settings['mat_delim']:
             left_delim = self._settings['mat_delim']
             right_delim = self._delim_dict[left_delim]
             out_str = r'\left' + left_delim + out_str + \
                       r'\right' + right_delim
-        return out_str
+        return out_str % r"\\".join(lines)
 
     def _print_MatrixElement(self, expr):
         return self.parenthesize(expr.parent, PRECEDENCE["Atom"], strict=True)\
@@ -1717,9 +1714,8 @@ def _print_BlockMatrix(self, expr):
 
     def _print_Transpose(self, expr):
         mat = expr.arg
-        from sympy.matrices import MatrixSymbol, BlockMatrix
-        if (not isinstance(mat, MatrixSymbol) and
-            not isinstance(mat, BlockMatrix) and mat.is_MatrixExpr):
+        from sympy.matrices import MatrixSymbol
+        if not isinstance(mat, MatrixSymbol) and mat.is_MatrixExpr:
             return r"\left(%s\right)^{T}" % self._print(mat)
         else:
             s = self.parenthesize(mat, precedence_traditional(expr), True)
@@ -1734,9 +1730,8 @@ def _print_Trace(self, expr):
 
     def _print_Adjoint(self, expr):
         mat = expr.arg
-        from sympy.matrices import MatrixSymbol, BlockMatrix
-        if (not isinstance(mat, MatrixSymbol) and
-            not isinstance(mat, BlockMatrix) and mat.is_MatrixExpr):
+        from sympy.matrices import MatrixSymbol
+        if not isinstance(mat, MatrixSymbol) and mat.is_MatrixExpr:
             return r"\left(%s\right)^{\dagger}" % self._print(mat)
         else:
             s = self.parenthesize(mat, precedence_traditional(expr), True)
@@ -1766,16 +1761,6 @@ def _print_MatMul(self, expr):
         else:
             return ' '.join(map(parens, args))
 
-    def _print_Determinant(self, expr):
-        mat = expr.arg
-        if mat.is_MatrixExpr:
-            from sympy.matrices.expressions.blockmatrix import BlockMatrix
-            if isinstance(mat, BlockMatrix):
-                return r"\left|{%s}\right|" % self._print_matrix_contents(mat.blocks)
-            return r"\left|{%s}\right|" % self._print(mat)
-        return r"\left|{%s}\right|" % self._print_matrix_contents(mat)
-
-
     def _print_Mod(self, expr, exp=None):
         if exp is not None:
             return r'\left(%s \bmod %s\right)^{%s}' % \
@@ -1817,7 +1802,7 @@ def _print_KroneckerProduct(self, expr):
     def _print_MatPow(self, expr):
         base, exp = expr.base, expr.exp
         from sympy.matrices import MatrixSymbol
-        if not isinstance(base, MatrixSymbol) and base.is_MatrixExpr:
+        if not isinstance(base, MatrixSymbol):
             return "\\left(%s\\right)^{%s}" % (self._print(base),
                                               self._print(exp))
         else:
diff --git a/sympy/printing/pretty/pretty.py b/sympy/printing/pretty/pretty.py
index 20c237f1f9..3917fdd71f 100644
--- a/sympy/printing/pretty/pretty.py
+++ b/sympy/printing/pretty/pretty.py
@@ -315,6 +315,7 @@ def _print_Abs(self, e):
         pform = self._print(e.args[0])
         pform = prettyForm(*pform.parens('|', '|'))
         return pform
+    _print_Determinant = _print_Abs
 
     def _print_floor(self, e):
         if self._use_unicode:
@@ -760,24 +761,12 @@ def _print_matrix_contents(self, e):
 
         return D
 
-    def _print_MatrixBase(self, e, lparens='[', rparens=']'):
+    def _print_MatrixBase(self, e):
         D = self._print_matrix_contents(e)
         D.baseline = D.height()//2
-        D = prettyForm(*D.parens(lparens, rparens))
+        D = prettyForm(*D.parens('[', ']'))
         return D
 
-    def _print_Determinant(self, e):
-        mat = e.arg
-        if mat.is_MatrixExpr:
-            from sympy.matrices.expressions.blockmatrix import BlockMatrix
-            if isinstance(mat, BlockMatrix):
-                return self._print_MatrixBase(mat.blocks, lparens='|', rparens='|')
-            D = self._print(mat)
-            D.baseline = D.height()//2
-            return prettyForm(*D.parens('|', '|'))
-        else:
-            return self._print_MatrixBase(mat, lparens='|', rparens='|')
-
     def _print_TensorProduct(self, expr):
         # This should somehow share the code with _print_WedgeProduct:
         if self._use_unicode:
@@ -853,25 +842,21 @@ def ppslice(x, dim):
         return pform
 
     def _print_Transpose(self, expr):
-        mat = expr.arg
-        pform = self._print(mat)
-        from sympy.matrices import MatrixSymbol, BlockMatrix
-        if (not isinstance(mat, MatrixSymbol) and
-            not isinstance(mat, BlockMatrix) and mat.is_MatrixExpr):
+        pform = self._print(expr.arg)
+        from sympy.matrices import MatrixSymbol
+        if not isinstance(expr.arg, MatrixSymbol) and expr.arg.is_MatrixExpr:
             pform = prettyForm(*pform.parens())
         pform = pform**(prettyForm('T'))
         return pform
 
     def _print_Adjoint(self, expr):
-        mat = expr.arg
-        pform = self._print(mat)
+        pform = self._print(expr.arg)
         if self._use_unicode:
             dag = prettyForm('\N{DAGGER}')
         else:
             dag = prettyForm('+')
-        from sympy.matrices import MatrixSymbol, BlockMatrix
-        if (not isinstance(mat, MatrixSymbol) and
-            not isinstance(mat, BlockMatrix) and mat.is_MatrixExpr):
+        from sympy.matrices import MatrixSymbol
+        if not isinstance(expr.arg, MatrixSymbol) and expr.arg.is_MatrixExpr:
             pform = prettyForm(*pform.parens())
         pform = pform**dag
         return pform
@@ -940,7 +925,7 @@ def _print_DotProduct(self, expr):
     def _print_MatPow(self, expr):
         pform = self._print(expr.base)
         from sympy.matrices import MatrixSymbol
-        if not isinstance(expr.base, MatrixSymbol) and expr.base.is_MatrixExpr:
+        if not isinstance(expr.base, MatrixSymbol):
             pform = prettyForm(*pform.parens())
         pform = pform**(self._print(expr.exp))
         return pform


Test patch:
diff --git a/sympy/parsing/tests/test_mathematica.py b/sympy/parsing/tests/test_mathematica.py
index 4e045ebfc9..9431d2f68b 100644
--- a/sympy/parsing/tests/test_mathematica.py
+++ b/sympy/parsing/tests/test_mathematica.py
@@ -231,16 +231,6 @@ def test_parser_mathematica_tokenizer():
     assert chain("#1 + #2 & [x, y]") == [["Function", ["Plus", ["Slot", "1"], ["Slot", "2"]]], "x", "y"]
     assert chain("#1^2#2^3&") == ["Function", ["Times", ["Power", ["Slot", "1"], "2"], ["Power", ["Slot", "2"], "3"]]]
 
-    # Strings inside Mathematica expressions:
-    assert chain('"abc"') == ["_Str", "abc"]
-    assert chain('"a\\"b"') == ["_Str", 'a"b']
-    # This expression does not make sense mathematically, it's just testing the parser:
-    assert chain('x + "abc" ^ 3') == ["Plus", "x", ["Power", ["_Str", "abc"], "3"]]
-    raises(SyntaxError, lambda: chain('"'))
-    raises(SyntaxError, lambda: chain('"\\"'))
-    raises(SyntaxError, lambda: chain('"abc'))
-    raises(SyntaxError, lambda: chain('"abc\\"def'))
-
     # Invalid expressions:
     raises(SyntaxError, lambda: chain("(,"))
     raises(SyntaxError, lambda: chain("()"))
diff --git a/sympy/polys/tests/test_rootoftools.py b/sympy/polys/tests/test_rootoftools.py
index dc132e1041..328a9ad8bd 100644
--- a/sympy/polys/tests/test_rootoftools.py
+++ b/sympy/polys/tests/test_rootoftools.py
@@ -1,6 +1,7 @@
 """Tests for the implementation of RootOf class and related tools. """
 
 from sympy.polys.polytools import Poly
+import sympy.polys.rootoftools as rootoftools
 from sympy.polys.rootoftools import (rootof, RootOf, CRootOf, RootSum,
     _pure_key_dict as D)
 
@@ -328,6 +329,50 @@ def test_CRootOf_eval_rational():
              ]
 
 
+def test_CRootOf_lazy():
+    # irreducible poly with both real and complex roots:
+    f = Poly(x**3 + 2*x + 2)
+
+    # real root:
+    CRootOf.clear_cache()
+    r = CRootOf(f, 0)
+    # Not yet in cache, after construction:
+    assert r.poly not in rootoftools._reals_cache
+    assert r.poly not in rootoftools._complexes_cache
+    r.evalf()
+    # In cache after evaluation:
+    assert r.poly in rootoftools._reals_cache
+    assert r.poly not in rootoftools._complexes_cache
+
+    # complex root:
+    CRootOf.clear_cache()
+    r = CRootOf(f, 1)
+    # Not yet in cache, after construction:
+    assert r.poly not in rootoftools._reals_cache
+    assert r.poly not in rootoftools._complexes_cache
+    r.evalf()
+    # In cache after evaluation:
+    assert r.poly in rootoftools._reals_cache
+    assert r.poly in rootoftools._complexes_cache
+
+    # composite poly with both real and complex roots:
+    f = Poly((x**2 - 2)*(x**2 + 1))
+
+    # real root:
+    CRootOf.clear_cache()
+    r = CRootOf(f, 0)
+    # In cache immediately after construction:
+    assert r.poly in rootoftools._reals_cache
+    assert r.poly not in rootoftools._complexes_cache
+
+    # complex root:
+    CRootOf.clear_cache()
+    r = CRootOf(f, 2)
+    # In cache immediately after construction:
+    assert r.poly in rootoftools._reals_cache
+    assert r.poly in rootoftools._complexes_cache
+
+
 def test_RootSum___new__():
     f = x**3 + x + 3
 
diff --git a/sympy/printing/pretty/tests/test_pretty.py b/sympy/printing/pretty/tests/test_pretty.py
index 467730ee34..239c2f4e60 100644
--- a/sympy/printing/pretty/tests/test_pretty.py
+++ b/sympy/printing/pretty/tests/test_pretty.py
@@ -53,8 +53,7 @@
     bernoulli, fibonacci, tribonacci, lucas, stieltjes, mathieuc, mathieus,
     mathieusprime, mathieucprime)
 
-from sympy.matrices import (Adjoint, Inverse, MatrixSymbol, Transpose,
-                            KroneckerProduct, BlockMatrix, OneMatrix, ZeroMatrix)
+from sympy.matrices import Adjoint, Inverse, MatrixSymbol, Transpose, KroneckerProduct
 from sympy.matrices.expressions import hadamard_power
 
 from sympy.physics import mechanics
@@ -3673,60 +3672,6 @@ def test_Adjoint():
         '⎛⎡1  2⎤    ⎞ \n'\
         '⎜⎢    ⎥ + X⎟ \n'\
         '⎝⎣3  4⎦    ⎠ '
-    assert upretty(Adjoint(BlockMatrix(((OneMatrix(2, 2), X),
-                                        (m, ZeroMatrix(2, 2)))))) == \
-        '           †\n'\
-        '⎡  𝟙     X⎤ \n'\
-        '⎢         ⎥ \n'\
-        '⎢⎡1  2⎤   ⎥ \n'\
-        '⎢⎢    ⎥  𝟘⎥ \n'\
-        '⎣⎣3  4⎦   ⎦ '
-
-
-def test_Transpose():
-    X = MatrixSymbol('X', 2, 2)
-    Y = MatrixSymbol('Y', 2, 2)
-    assert pretty(Transpose(X)) == " T\nX "
-    assert pretty(Transpose(X + Y)) == "       T\n(X + Y) "
-    assert pretty(Transpose(X) + Transpose(Y)) == " T    T\nX  + Y "
-    assert pretty(Transpose(X*Y)) == "     T\n(X*Y) "
-    assert pretty(Transpose(Y)*Transpose(X)) == " T  T\nY *X "
-    assert pretty(Transpose(X**2)) == "    T\n/ 2\\ \n\\X / "
-    assert pretty(Transpose(X)**2) == "    2\n/ T\\ \n\\X / "
-    assert pretty(Transpose(Inverse(X))) == "     T\n/ -1\\ \n\\X  / "
-    assert pretty(Inverse(Transpose(X))) == "    -1\n/ T\\  \n\\X /  "
-    assert upretty(Transpose(X)) == " T\nX "
-    assert upretty(Transpose(X + Y)) == "       T\n(X + Y) "
-    assert upretty(Transpose(X) + Transpose(Y)) == " T    T\nX  + Y "
-    assert upretty(Transpose(X*Y)) == "     T\n(X⋅Y) "
-    assert upretty(Transpose(Y)*Transpose(X)) == " T  T\nY ⋅X "
-    assert upretty(Transpose(X**2)) == \
-        "    T\n⎛ 2⎞ \n⎝X ⎠ "
-    assert upretty(Transpose(X)**2) == \
-        "    2\n⎛ T⎞ \n⎝X ⎠ "
-    assert upretty(Transpose(Inverse(X))) == \
-        "     T\n⎛ -1⎞ \n⎝X  ⎠ "
-    assert upretty(Inverse(Transpose(X))) == \
-        "    -1\n⎛ T⎞  \n⎝X ⎠  "
-    m = Matrix(((1, 2), (3, 4)))
-    assert upretty(Transpose(m)) == \
-        '      T\n'\
-        '⎡1  2⎤ \n'\
-        '⎢    ⎥ \n'\
-        '⎣3  4⎦ '
-    assert upretty(Transpose(m+X)) == \
-        '            T\n'\
-        '⎛⎡1  2⎤    ⎞ \n'\
-        '⎜⎢    ⎥ + X⎟ \n'\
-        '⎝⎣3  4⎦    ⎠ '
-    assert upretty(Transpose(BlockMatrix(((OneMatrix(2, 2), X),
-                                          (m, ZeroMatrix(2, 2)))))) == \
-        '           T\n'\
-        '⎡  𝟙     X⎤ \n'\
-        '⎢         ⎥ \n'\
-        '⎢⎡1  2⎤   ⎥ \n'\
-        '⎢⎢    ⎥  𝟘⎥ \n'\
-        '⎣⎣3  4⎦   ⎦ '
 
 
 def test_pretty_Trace_issue_9044():
@@ -3871,30 +3816,6 @@ def test_pretty_dotproduct():
     assert upretty(DotProduct(C, D)) == "[1  2  3]⋅[1  3  4]"
 
 
-def test_pretty_Determinant():
-    from sympy.matrices import Determinant, Inverse, BlockMatrix, OneMatrix, ZeroMatrix
-    m = Matrix(((1, 2), (3, 4)))
-    assert upretty(Determinant(m)) == '│1  2│\n│    │\n│3  4│'
-    assert upretty(Determinant(Inverse(m))) == \
-        '│      -1│\n'\
-        '│⎡1  2⎤  │\n'\
-        '│⎢    ⎥  │\n'\
-        '│⎣3  4⎦  │'
-    X = MatrixSymbol('X', 2, 2)
-    assert upretty(Determinant(X)) == '│X│'
-    assert upretty(Determinant(X + m)) == \
-        '│⎡1  2⎤    │\n'\
-        '│⎢    ⎥ + X│\n'\
-        '│⎣3  4⎦    │'
-    assert upretty(Determinant(BlockMatrix(((OneMatrix(2, 2), X),
-                                            (m, ZeroMatrix(2, 2)))))) == \
-        '│  𝟙     X│\n'\
-        '│         │\n'\
-        '│⎡1  2⎤   │\n'\
-        '│⎢    ⎥  𝟘│\n'\
-        '│⎣3  4⎦   │'
-
-
 def test_pretty_piecewise():
     expr = Piecewise((x, x < 1), (x**2, True))
     ascii_str = \
diff --git a/sympy/printing/tests/test_latex.py b/sympy/printing/tests/test_latex.py
index aac065ca05..de8e402c58 100644
--- a/sympy/printing/tests/test_latex.py
+++ b/sympy/printing/tests/test_latex.py
@@ -1951,21 +1951,6 @@ def test_Tr():
     assert latex(t) == r'\operatorname{tr}\left(A B\right)'
 
 
-def test_Determinant():
-    from sympy.matrices import Determinant, Inverse, BlockMatrix, OneMatrix, ZeroMatrix
-    m = Matrix(((1, 2), (3, 4)))
-    assert latex(Determinant(m)) == '\\left|{\\begin{matrix}1 & 2\\\\3 & 4\\end{matrix}}\\right|'
-    assert latex(Determinant(Inverse(m))) == \
-        '\\left|{\\left[\\begin{matrix}1 & 2\\\\3 & 4\\end{matrix}\\right]^{-1}}\\right|'
-    X = MatrixSymbol('X', 2, 2)
-    assert latex(Determinant(X)) == '\\left|{X}\\right|'
-    assert latex(Determinant(X + m)) == \
-        '\\left|{\\left[\\begin{matrix}1 & 2\\\\3 & 4\\end{matrix}\\right] + X}\\right|'
-    assert latex(Determinant(BlockMatrix(((OneMatrix(2, 2), X),
-                                          (m, ZeroMatrix(2, 2)))))) == \
-        '\\left|{\\begin{matrix}1 & X\\\\\\left[\\begin{matrix}1 & 2\\\\3 & 4\\end{matrix}\\right] & 0\\end{matrix}}\\right|'
-
-
 def test_Adjoint():
     from sympy.matrices import Adjoint, Inverse, Transpose
     X = MatrixSymbol('X', 2, 2)
@@ -1986,10 +1971,6 @@ def test_Adjoint():
     assert latex(Adjoint(m)) == '\\left[\\begin{matrix}1 & 2\\\\3 & 4\\end{matrix}\\right]^{\\dagger}'
     assert latex(Adjoint(m+X)) == \
         '\\left(\\left[\\begin{matrix}1 & 2\\\\3 & 4\\end{matrix}\\right] + X\\right)^{\\dagger}'
-    from sympy.matrices import BlockMatrix, OneMatrix, ZeroMatrix
-    assert latex(Adjoint(BlockMatrix(((OneMatrix(2, 2), X),
-                                      (m, ZeroMatrix(2, 2)))))) == \
-        '\\left[\\begin{matrix}1 & X\\\\\\left[\\begin{matrix}1 & 2\\\\3 & 4\\end{matrix}\\right] & 0\\end{matrix}\\right]^{\\dagger}'
     # Issue 20959
     Mx = MatrixSymbol('M^x', 2, 2)
     assert latex(Adjoint(Mx)) == r'\left(M^{x}\right)^{\dagger}'
@@ -2010,10 +1991,6 @@ def test_Transpose():
     assert latex(Transpose(m)) == '\\left[\\begin{matrix}1 & 2\\\\3 & 4\\end{matrix}\\right]^{T}'
     assert latex(Transpose(m+X)) == \
         '\\left(\\left[\\begin{matrix}1 & 2\\\\3 & 4\\end{matrix}\\right] + X\\right)^{T}'
-    from sympy.matrices import BlockMatrix, OneMatrix, ZeroMatrix
-    assert latex(Transpose(BlockMatrix(((OneMatrix(2, 2), X),
-                                        (m, ZeroMatrix(2, 2)))))) == \
-        '\\left[\\begin{matrix}1 & X\\\\\\left[\\begin{matrix}1 & 2\\\\3 & 4\\end{matrix}\\right] & 0\\end{matrix}\\right]^{T}'
     # Issue 20959
     Mx = MatrixSymbol('M^x', 2, 2)
     assert latex(Transpose(Mx)) == r'\left(M^{x}\right)^{T}'