def xxinv(mul):
    """ Y * X * X.I -> Y """
    factor, matrices = mul.as_coeff_matrices()
    for i, (X, Y) in enumerate(zip(matrices[:-1], matrices[1:])):
        try:
            if X.is_square and Y.is_square and X == Y.inverse():
                I = Identity(X.rows)
                return newmul(factor, *(matrices[:i] + [I] + matrices[i+2:]))
        except __HOLE__:  # Y might not be invertible
            pass

    return mul
dataset/ETHPy150Open sympy/sympy/sympy/matrices/expressions/matmul.py/xxinv