'Return the multiplicative inverse of ``self`` mod ``g``
where ``self`` (and ``g``) may be symbolic expressions).
See Also
sympy.core.numbers.mod_inverse, sympy.polys.polytools.invert'

def invert(self, g, *gens, **args):

    from sympy.polys.polytools import invert
    from sympy.core.numbers import mod_inverse
    if (self.is_number and getattr(g, 'is_number', True)):
        return mod_inverse(self, g)
    return invert(self, g, *gens, **args)
