(f, g, *gens, **args)
Invert ``f`` modulo ``g`` when possible.

    Examples
    ========

    >>> from sympy import invert
    >>> from sympy.abc import x

    >>> invert(x**2 - 1, 2*x - 1)
    -4/3

    >>> invert(x**2 - 1, x - 1)
    Traceback (most recent call last):
    ...
    NotInvertible: zero divisor
Invert ``f`` modulo ``g`` when possible.
Invert f modulo g when possible .
def invert(f, g, *gens, **args):
    """
    Invert ``f`` modulo ``g`` when possible.

    Examples
    ========

    >>> from sympy import invert
    >>> from sympy.abc import x

    >>> invert(x**2 - 1, 2*x - 1)
    -4/3

    >>> invert(x**2 - 1, x - 1)
    Traceback (most recent call last):
    ...
    NotInvertible: zero divisor

    """
    options.allowed_flags(args, ['auto', 'polys'])

    try:
        (F, G), opt = parallel_poly_from_expr((f, g), *gens, **args)
    except PolificationFailed as exc:
        domain, (a, b) = construct_domain(exc.exprs)

        try:
            return domain.to_sympy(domain.invert(a, b))
        except NotImplementedError:
            raise ComputationFailed('invert', 2, exc)

    h = F.invert(G, auto=opt.auto)

    if not opt.polys:
        return h.as_expr()
    else:
        return h
def invert ( f , g , * gens , * * args ) : options . allowed_flags ( args , [ 'auto' , 'polys' ] ) try : ( F , G ) , opt = parallel_poly_from_expr ( ( f , g ) , * gens , * * args ) except PolificationFailed as exc : domain , ( a , b ) = construct_domain ( exc . exprs ) try : return domain . to_sympy ( domain . invert ( a , b ) ) except NotImplementedError : raise ComputationFailed ( 'invert' , 2 , exc ) h = F . invert ( G , auto = opt . auto ) if not opt . polys : return h . as_expr ( ) else : return h