def refine_Inverse(expr, assumptions):
    """
    >>> from sympy import MatrixSymbol, Q, assuming, refine
    >>> X = MatrixSymbol('X', 2, 2)
    >>> X.I
    X^-1
    >>> with assuming(Q.orthogonal(X)):
    ...     print(refine(X.I))
    X'
    """
    if ask(Q.orthogonal(expr), assumptions):
        return expr.arg.T
    elif ask(Q.unitary(expr), assumptions):
        return expr.arg.conjugate()
    elif ask(Q.singular(expr), assumptions):
        raise ValueError("Inverse of singular matrix %s" % expr.arg)

    return expr
dataset/ETHPy150Open sympy/sympy/sympy/matrices/expressions/inverse.py/refine_Inverse/original