(matmul)
return MatMul(*newargs)
Merge explicit MatrixBase arguments

    >>> from sympy import MatrixSymbol, eye, Matrix, MatMul, pprint
    >>> from sympy.matrices.expressions.matmul import merge_explicit
    >>> A = MatrixSymbol('A', 2, 2)
    >>> B = Matrix([[1, 1], [1, 1]])
    >>> C = Matrix([[1, 2], [3, 4]])
    >>> X = MatMul(A, B, C)
    >>> pprint(X)
    A*[1  1]*[1  2]
      [    ] [    ]
      [1  1] [3  4]
    >>> pprint(merge_explicit(X))
    A*[4  6]
      [    ]
      [4  6]

    >>> X = MatMul(B, A, C)
    >>> pprint(X)
    [1  1]*A*[1  2]
    [    ]   [    ]
    [1  1]   [3  4]
    >>> pprint(merge_explicit(X))
    [1  1]*A*[1  2]
    [    ]   [    ]
    [1  1]   [3  4]
Merge explicit MatrixBase arguments
Merge explicit MatrixBase arguments
def merge_explicit(matmul):
    """ Merge explicit MatrixBase arguments

    >>> from sympy import MatrixSymbol, eye, Matrix, MatMul, pprint
    >>> from sympy.matrices.expressions.matmul import merge_explicit
    >>> A = MatrixSymbol('A', 2, 2)
    >>> B = Matrix([[1, 1], [1, 1]])
    >>> C = Matrix([[1, 2], [3, 4]])
    >>> X = MatMul(A, B, C)
    >>> pprint(X)
    A*[1  1]*[1  2]
      [    ] [    ]
      [1  1] [3  4]
    >>> pprint(merge_explicit(X))
    A*[4  6]
      [    ]
      [4  6]

    >>> X = MatMul(B, A, C)
    >>> pprint(X)
    [1  1]*A*[1  2]
    [    ]   [    ]
    [1  1]   [3  4]
    >>> pprint(merge_explicit(X))
    [1  1]*A*[1  2]
    [    ]   [    ]
    [1  1]   [3  4]
    """
    if not any(isinstance(arg, MatrixBase) for arg in matmul.args):
        return matmul
    newargs = []
    last = matmul.args[0]
    for arg in matmul.args[1:]:
        if isinstance(arg, MatrixBase) and isinstance(last, MatrixBase):
            last = last * arg
        else:
            newargs.append(last)
            last = arg
    newargs.append(last)

    return MatMul(*newargs)
def merge_explicit ( matmul ) : if not any ( isinstance ( arg , MatrixBase ) for arg in matmul . args ) : return matmul newargs = [ ] last = matmul . args [ 0 ] for arg in matmul . args [ 1 : ] : if isinstance ( arg , MatrixBase ) and isinstance ( last , MatrixBase ) : last = last * arg else : newargs . append ( last ) last = arg newargs . append ( last ) return MatMul ( * newargs )