def _solveset(f, symbol, domain, _check=False):
    "Helper for solveset to return a result from an expression\n    that has already been sympify'ed and is known to contain the\n    given symbol."
    from sympy.simplify.simplify import signsimp
    orig_f = f
    f = together(f)
    if f.is_Mul:
        (_, f) = f.as_independent(symbol, as_Add=False)
    if f.is_Add:
        (a, h) = f.as_independent(symbol)
        (m, h) = h.as_independent(symbol, as_Add=False)
        f = ((a / m) + h)
    f = piecewise_fold(f)
    solver = (lambda f, x, domain=domain: _solveset(f, x, domain))
    if domain.is_subset(S.Reals):
        inverter_func = invert_real
    else:
        inverter_func = invert_complex
    inverter = (lambda f, rhs, symbol: inverter_func(f, rhs, symbol, domain))
    result = EmptySet()
    if f.expand().is_zero:
        return domain
    elif (not f.has(symbol)):
        return EmptySet()
    elif (f.is_Mul and all((_is_finite_with_finite_vars(m, domain) for m in f.args))):
        result = Union(*[solver(m, symbol) for m in f.args])
    elif (_is_function_class_equation(TrigonometricFunction, f, symbol) or _is_function_class_equation(HyperbolicFunction, f, symbol)):
        result = _solve_trig(f, symbol, domain)
    elif f.is_Piecewise:
        dom = domain
        result = EmptySet()
        expr_set_pairs = f.as_expr_set_pairs()
        for (expr, in_set) in expr_set_pairs:
            if in_set.is_Relational:
                in_set = in_set.as_set()
            if in_set.is_Interval:
                dom -= in_set
            solns = solver(expr, symbol, in_set)
            result += solns
    else:
        (lhs, rhs_s) = inverter(f, 0, symbol)
        if (lhs == symbol):
            if isinstance(rhs_s, FiniteSet):
                rhs_s = FiniteSet(*[Mul(*signsimp(i).as_content_primitive()) for i in rhs_s])
            result = rhs_s
        elif isinstance(rhs_s, FiniteSet):
            for equation in [(lhs - rhs) for rhs in rhs_s]:
                if (equation == f):
                    if (any((_has_rational_power(g, symbol)[0] for g in equation.args)) or _has_rational_power(equation, symbol)[0]):
                        result += _solve_radical(equation, symbol, solver)
                    elif equation.has(Abs):
                        result += _solve_abs(f, symbol, domain)
                    else:
                        result += _solve_as_rational(equation, symbol, domain)
                else:
                    result += solver(equation, symbol)
        elif (rhs_s is not S.EmptySet):
            result = ConditionSet(symbol, Eq(f, 0), domain)
    if _check:
        if isinstance(result, ConditionSet):
            return result
        fx = orig_f.as_independent(symbol, as_Add=True)[1]
        fx = fx.as_independent(symbol, as_Add=False)[1]
        if isinstance(result, FiniteSet):
            result = FiniteSet(*[s for s in result if (isinstance(s, RootOf) or domain_check(fx, symbol, s))])
    return result
Helper for solveset to return a result from an expression
that has already been sympify'ed and is known to contain the
given symbol.
def _solveset(f, symbol, domain, _check=False):
    "Helper for solveset to return a result from an expression\n    that has already been sympify'ed and is known to contain the\n    given symbol."
    from sympy.simplify.simplify import signsimp
    orig_f = f
    f = together(f)
    if f.is_Mul:
        (_, f) = f.as_independent(symbol, as_Add=False)
    if f.is_Add:
        (a, h) = f.as_independent(symbol)
        (m, h) = h.as_independent(symbol, as_Add=False)
        f = ((a / m) + h)
    f = piecewise_fold(f)
    solver = (lambda f, x, domain=domain: _solveset(f, x, domain))
    if domain.is_subset(S.Reals):
        inverter_func = invert_real
    else:
        inverter_func = invert_complex
    inverter = (lambda f, rhs, symbol: inverter_func(f, rhs, symbol, domain))
    result = EmptySet()
    if f.expand().is_zero:
        return domain
    elif (not f.has(symbol)):
        return EmptySet()
    elif (f.is_Mul and all((_is_finite_with_finite_vars(m, domain) for m in f.args))):
        result = Union(*[solver(m, symbol) for m in f.args])
    elif (_is_function_class_equation(TrigonometricFunction, f, symbol) or _is_function_class_equation(HyperbolicFunction, f, symbol)):
        result = _solve_trig(f, symbol, domain)
    elif f.is_Piecewise:
        dom = domain
        result = EmptySet()
        expr_set_pairs = f.as_expr_set_pairs()
        for (expr, in_set) in expr_set_pairs:
            if in_set.is_Relational:
                in_set = in_set.as_set()
            if in_set.is_Interval:
                dom -= in_set
            solns = solver(expr, symbol, in_set)
            result += solns
    else:
        (lhs, rhs_s) = inverter(f, 0, symbol)
        if (lhs == symbol):
            if isinstance(rhs_s, FiniteSet):
                rhs_s = FiniteSet(*[Mul(*signsimp(i).as_content_primitive()) for i in rhs_s])
            result = rhs_s
        elif isinstance(rhs_s, FiniteSet):
            for equation in [(lhs - rhs) for rhs in rhs_s]:
                if (equation == f):
                    if (any((_has_rational_power(g, symbol)[0] for g in equation.args)) or _has_rational_power(equation, symbol)[0]):
                        result += _solve_radical(equation, symbol, solver)
                    elif equation.has(Abs):
                        result += _solve_abs(f, symbol, domain)
                    else:
                        result += _solve_as_rational(equation, symbol, domain)
                else:
                    result += solver(equation, symbol)
        elif (rhs_s is not S.EmptySet):
            result = ConditionSet(symbol, Eq(f, 0), domain)
    if _check:
        if isinstance(result, ConditionSet):
            return result
        fx = orig_f.as_independent(symbol, as_Add=True)[1]
        fx = fx.as_independent(symbol, as_Add=False)[1]
        if isinstance(result, FiniteSet):
            result = FiniteSet(*[s for s in result if (isinstance(s, RootOf) or domain_check(fx, symbol, s))])
    return result