(mul)
return mul
Y * X * X.I -> Y
Y * X * X.I -> Y
Y * X * X . I - > Y
def xxinv(mul):
    """ Y * X * X.I -> Y """
    from sympy.matrices.expressions import Inverse
    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 ValueError:  # Y might not be invertible
            pass

    return mul
def xxinv ( mul ) : from sympy . matrices . expressions import Inverse 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 ValueError : # Y might not be invertible pass return mul