def _solve_as_poly(f, symbol, domain=S.Complexes):
    '\n    Solve the equation using polynomial techniques if it already is a\n    polynomial equation or, with a change of variables, can be made so.\n    '
    result = None
    if f.is_polynomial(symbol):
        solns = roots(f, symbol, cubics=True, quartics=True, quintics=True, domain='EX')
        num_roots = sum(solns.values())
        if (degree(f, symbol) <= num_roots):
            result = FiniteSet(*solns.keys())
        else:
            poly = Poly(f, symbol)
            solns = poly.all_roots()
            if (poly.degree() <= len(solns)):
                result = FiniteSet(*solns)
            else:
                result = ConditionSet(symbol, Eq(f, 0), domain)
    else:
        poly = Poly(f)
        if (poly is None):
            result = ConditionSet(symbol, Eq(f, 0), domain)
        gens = [g for g in poly.gens if g.has(symbol)]
        if (len(gens) == 1):
            poly = Poly(poly, gens[0])
            gen = poly.gen
            deg = poly.degree()
            poly = Poly(poly.as_expr(), poly.gen, composite=True)
            poly_solns = FiniteSet(*roots(poly, cubics=True, quartics=True, quintics=True).keys())
            if (len(poly_solns) < deg):
                result = ConditionSet(symbol, Eq(f, 0), domain)
            if (gen != symbol):
                y = Dummy('y')
                inverter = (invert_real if domain.is_subset(S.Reals) else invert_complex)
                (lhs, rhs_s) = inverter(gen, y, symbol)
                if (lhs == symbol):
                    result = Union(*[rhs_s.subs(y, s) for s in poly_solns])
                else:
                    result = ConditionSet(symbol, Eq(f, 0), domain)
        else:
            result = ConditionSet(symbol, Eq(f, 0), domain)
    if (result is not None):
        if isinstance(result, FiniteSet):
            if all([((s.free_symbols == set()) and (not isinstance(s, RootOf))) for s in result]):
                s = Dummy('s')
                result = imageset(Lambda(s, expand_complex(s)), result)
        if isinstance(result, FiniteSet):
            result = result.intersection(domain)
        return result
    else:
        return ConditionSet(symbol, Eq(f, 0), domain)
Solve the equation using polynomial techniques if it already is a
polynomial equation or, with a change of variables, can be made so.
def _solve_as_poly(f, symbol, domain=S.Complexes):
    '\n    Solve the equation using polynomial techniques if it already is a\n    polynomial equation or, with a change of variables, can be made so.\n    '
    result = None
    if f.is_polynomial(symbol):
        solns = roots(f, symbol, cubics=True, quartics=True, quintics=True, domain='EX')
        num_roots = sum(solns.values())
        if (degree(f, symbol) <= num_roots):
            result = FiniteSet(*solns.keys())
        else:
            poly = Poly(f, symbol)
            solns = poly.all_roots()
            if (poly.degree() <= len(solns)):
                result = FiniteSet(*solns)
            else:
                result = ConditionSet(symbol, Eq(f, 0), domain)
    else:
        poly = Poly(f)
        if (poly is None):
            result = ConditionSet(symbol, Eq(f, 0), domain)
        gens = [g for g in poly.gens if g.has(symbol)]
        if (len(gens) == 1):
            poly = Poly(poly, gens[0])
            gen = poly.gen
            deg = poly.degree()
            poly = Poly(poly.as_expr(), poly.gen, composite=True)
            poly_solns = FiniteSet(*roots(poly, cubics=True, quartics=True, quintics=True).keys())
            if (len(poly_solns) < deg):
                result = ConditionSet(symbol, Eq(f, 0), domain)
            if (gen != symbol):
                y = Dummy('y')
                inverter = (invert_real if domain.is_subset(S.Reals) else invert_complex)
                (lhs, rhs_s) = inverter(gen, y, symbol)
                if (lhs == symbol):
                    result = Union(*[rhs_s.subs(y, s) for s in poly_solns])
                else:
                    result = ConditionSet(symbol, Eq(f, 0), domain)
        else:
            result = ConditionSet(symbol, Eq(f, 0), domain)
    if (result is not None):
        if isinstance(result, FiniteSet):
            if all([((s.free_symbols == set()) and (not isinstance(s, RootOf))) for s in result]):
                s = Dummy('s')
                result = imageset(Lambda(s, expand_complex(s)), result)
        if isinstance(result, FiniteSet):
            result = result.intersection(domain)
        return result
    else:
        return ConditionSet(symbol, Eq(f, 0), domain)