def _invert(f_x, y, x, domain=S.Complexes):
    "\n    Reduce the complex valued equation ``f(x) = y`` to a set of equations\n    ``{g(x) = h_1(y), g(x) = h_2(y), ..., g(x) = h_n(y) }`` where ``g(x)`` is\n    a simpler function than ``f(x)``.  The return value is a tuple ``(g(x),\n    set_h)``, where ``g(x)`` is a function of ``x`` and ``set_h`` is\n    the set of function ``{h_1(y), h_2(y), ..., h_n(y)}``.\n    Here, ``y`` is not necessarily a symbol.\n\n    The ``set_h`` contains the functions along with the information\n    about their domain in which they are valid, through set\n    operations. For instance, if ``y = Abs(x) - n``, is inverted\n    in the real domain, then, the ``set_h`` doesn't simply return\n    `{-n, n}`, as the nature of `n` is unknown; rather it will return:\n    `Intersection([0, oo) {n}) U Intersection((-oo, 0], {-n})`\n\n    By default, the complex domain is used but note that inverting even\n    seemingly simple functions like ``exp(x)`` can give very different\n    result in the complex domain than are obtained in the real domain.\n    (In the case of ``exp(x)``, the inversion via ``log`` is multi-valued\n    in the complex domain, having infinitely many branches.)\n\n    If you are working with real values only (or you are not sure which\n    function to use) you should probably use set the domain to\n    ``S.Reals`` (or use `invert\\_real` which does that automatically).\n\n\n    Examples\n    ========\n\n    >>> from sympy.solvers.solveset import invert_complex, invert_real\n    >>> from sympy.abc import x, y\n    >>> from sympy import exp, log\n\n    When does exp(x) == y?\n\n    >>> invert_complex(exp(x), y, x)\n    (x, ImageSet(Lambda(_n, I*(2*_n*pi + arg(y)) + log(Abs(y))), Integers()))\n    >>> invert_real(exp(x), y, x)\n    (x, Intersection((-oo, oo), {log(y)}))\n\n    When does exp(x) == 1?\n\n    >>> invert_complex(exp(x), 1, x)\n    (x, ImageSet(Lambda(_n, 2*_n*I*pi), Integers()))\n    >>> invert_real(exp(x), 1, x)\n    (x, {0})\n\n    See Also\n    ========\n    invert_real, invert_complex\n    "
    x = sympify(x)
    if (not x.is_Symbol):
        raise ValueError('x must be a symbol')
    f_x = sympify(f_x)
    if (not f_x.has(x)):
        raise ValueError("Inverse of constant function doesn't exist")
    y = sympify(y)
    if y.has(x):
        raise ValueError('y should be independent of x ')
    if domain.is_subset(S.Reals):
        (x, s) = _invert_real(f_x, FiniteSet(y), x)
    else:
        (x, s) = _invert_complex(f_x, FiniteSet(y), x)
    return (x, (s.intersection(domain) if isinstance(s, FiniteSet) else s))
Reduce the complex valued equation ``f(x) = y`` to a set of equations
``{g(x) = h_1(y), g(x) = h_2(y), ..., g(x) = h_n(y) }`` where ``g(x)`` is
a simpler function than ``f(x)``.  The return value is a tuple ``(g(x),
set_h)``, where ``g(x)`` is a function of ``x`` and ``set_h`` is
the set of function ``{h_1(y), h_2(y), ..., h_n(y)}``.
Here, ``y`` is not necessarily a symbol.

The ``set_h`` contains the functions along with the information
about their domain in which they are valid, through set
operations. For instance, if ``y = Abs(x) - n``, is inverted
in the real domain, then, the ``set_h`` doesn't simply return
`{-n, n}`, as the nature of `n` is unknown; rather it will return:
`Intersection([0, oo) {n}) U Intersection((-oo, 0], {-n})`

By default, the complex domain is used but note that inverting even
seemingly simple functions like ``exp(x)`` can give very different
result in the complex domain than are obtained in the real domain.
(In the case of ``exp(x)``, the inversion via ``log`` is multi-valued
in the complex domain, having infinitely many branches.)

If you are working with real values only (or you are not sure which
function to use) you should probably use set the domain to
``S.Reals`` (or use `invert\_real` which does that automatically).


Examples
========

>>> from sympy.solvers.solveset import invert_complex, invert_real
>>> from sympy.abc import x, y
>>> from sympy import exp, log

When does exp(x) == y?

>>> invert_complex(exp(x), y, x)
(x, ImageSet(Lambda(_n, I*(2*_n*pi + arg(y)) + log(Abs(y))), Integers()))
>>> invert_real(exp(x), y, x)
(x, Intersection((-oo, oo), {log(y)}))

When does exp(x) == 1?

>>> invert_complex(exp(x), 1, x)
(x, ImageSet(Lambda(_n, 2*_n*I*pi), Integers()))
>>> invert_real(exp(x), 1, x)
(x, {0})

See Also
========
invert_real, invert_complex
def _invert(f_x, y, x, domain=S.Complexes):
    "\n    Reduce the complex valued equation ``f(x) = y`` to a set of equations\n    ``{g(x) = h_1(y), g(x) = h_2(y), ..., g(x) = h_n(y) }`` where ``g(x)`` is\n    a simpler function than ``f(x)``.  The return value is a tuple ``(g(x),\n    set_h)``, where ``g(x)`` is a function of ``x`` and ``set_h`` is\n    the set of function ``{h_1(y), h_2(y), ..., h_n(y)}``.\n    Here, ``y`` is not necessarily a symbol.\n\n    The ``set_h`` contains the functions along with the information\n    about their domain in which they are valid, through set\n    operations. For instance, if ``y = Abs(x) - n``, is inverted\n    in the real domain, then, the ``set_h`` doesn't simply return\n    `{-n, n}`, as the nature of `n` is unknown; rather it will return:\n    `Intersection([0, oo) {n}) U Intersection((-oo, 0], {-n})`\n\n    By default, the complex domain is used but note that inverting even\n    seemingly simple functions like ``exp(x)`` can give very different\n    result in the complex domain than are obtained in the real domain.\n    (In the case of ``exp(x)``, the inversion via ``log`` is multi-valued\n    in the complex domain, having infinitely many branches.)\n\n    If you are working with real values only (or you are not sure which\n    function to use) you should probably use set the domain to\n    ``S.Reals`` (or use `invert\\_real` which does that automatically).\n\n\n    Examples\n    ========\n\n    >>> from sympy.solvers.solveset import invert_complex, invert_real\n    >>> from sympy.abc import x, y\n    >>> from sympy import exp, log\n\n    When does exp(x) == y?\n\n    >>> invert_complex(exp(x), y, x)\n    (x, ImageSet(Lambda(_n, I*(2*_n*pi + arg(y)) + log(Abs(y))), Integers()))\n    >>> invert_real(exp(x), y, x)\n    (x, Intersection((-oo, oo), {log(y)}))\n\n    When does exp(x) == 1?\n\n    >>> invert_complex(exp(x), 1, x)\n    (x, ImageSet(Lambda(_n, 2*_n*I*pi), Integers()))\n    >>> invert_real(exp(x), 1, x)\n    (x, {0})\n\n    See Also\n    ========\n    invert_real, invert_complex\n    "
    x = sympify(x)
    if (not x.is_Symbol):
        raise ValueError('x must be a symbol')
    f_x = sympify(f_x)
    if (not f_x.has(x)):
        raise ValueError("Inverse of constant function doesn't exist")
    y = sympify(y)
    if y.has(x):
        raise ValueError('y should be independent of x ')
    if domain.is_subset(S.Reals):
        (x, s) = _invert_real(f_x, FiniteSet(y), x)
    else:
        (x, s) = _invert_complex(f_x, FiniteSet(y), x)
    return (x, (s.intersection(domain) if isinstance(s, FiniteSet) else s))