def _invert_complex(f, g_ys, symbol):
    'Helper function for _invert.'
    if (f == symbol):
        return (f, g_ys)
    n = Dummy('n')
    if f.is_Add:
        (g, h) = f.as_independent(symbol)
        if (g is not S.Zero):
            return _invert_complex(h, imageset(Lambda(n, (n - g)), g_ys), symbol)
    if f.is_Mul:
        (g, h) = f.as_independent(symbol)
        if (g is not S.One):
            return _invert_complex(h, imageset(Lambda(n, (n / g)), g_ys), symbol)
    if (hasattr(f, 'inverse') and (not isinstance(f, TrigonometricFunction)) and (not isinstance(f, exp))):
        if (len(f.args) > 1):
            raise ValueError('Only functions with one argument are supported.')
        return _invert_complex(f.args[0], imageset(Lambda(n, f.inverse()(n)), g_ys), symbol)
    if isinstance(f, exp):
        if isinstance(g_ys, FiniteSet):
            exp_invs = Union(*[imageset(Lambda(n, ((I * (((2 * n) * pi) + arg(g_y))) + log(Abs(g_y)))), S.Integers) for g_y in g_ys if (g_y != 0)])
            return _invert_complex(f.args[0], exp_invs, symbol)
    return (f, g_ys)
Helper function for _invert.
def _invert_complex(f, g_ys, symbol):
    
    if (f == symbol):
        return (f, g_ys)
    n = Dummy('n')
    if f.is_Add:
        (g, h) = f.as_independent(symbol)
        if (g is not S.Zero):
            return _invert_complex(h, imageset(Lambda(n, (n - g)), g_ys), symbol)
    if f.is_Mul:
        (g, h) = f.as_independent(symbol)
        if (g is not S.One):
            return _invert_complex(h, imageset(Lambda(n, (n / g)), g_ys), symbol)
    if (hasattr(f, 'inverse') and (not isinstance(f, TrigonometricFunction)) and (not isinstance(f, exp))):
        if (len(f.args) > 1):
            raise ValueError('Only functions with one argument are supported.')
        return _invert_complex(f.args[0], imageset(Lambda(n, f.inverse()(n)), g_ys), symbol)
    if isinstance(f, exp):
        if isinstance(g_ys, FiniteSet):
            exp_invs = Union(*[imageset(Lambda(n, ((I * (((2 * n) * pi) + arg(g_y))) + log(Abs(g_y)))), S.Integers) for g_y in g_ys if (g_y != 0)])
            return _invert_complex(f.args[0], exp_invs, symbol)
    return (f, g_ys)