'Computes inverse of a fraction ``f``.'

def invert(f, check=True):

    if (check and (f.ring is not None) and (not f.ring.is_unit(f))):
        raise NotReversible(f, f.ring)
    res = f.per(f.den, f.num, cancel=False)
    return res
