# Buggy code
def _minpoly_compose(ex, x, dom):
    """
    Computes the minimal polynomial of an algebraic element
    using operations on minimal polynomials

    Examples
    ========

    >>> from sympy import minimal_polynomial, sqrt, Rational
    >>> from sympy.abc import x, y
    >>> minimal_polynomial(sqrt(2) + 3*Rational(1, 3), x, compose=True)
    x**2 - 2*x - 1
    >>> minimal_polynomial(sqrt(y) + 1/y, x, compose=True)
    x**2*y**2 - 2*x*y - y**3 + 1

    """
    if ex.is_Rational:
        return ex.q * x - ex.p
    if ex is I:
        _, factors = factor_list(x**2 + 1, x, domain=dom)
        return x**2 + 1 if len(factors) == 1 else x - I
    if hasattr(dom, "symbols") and ex in dom.symbols:
        return x - ex

    if dom.is_QQ and _is_sum_surds(ex):
        # eliminate the square roots
        ex -= x
        while 1:
            ex1 = _separate_sq(ex)
            if ex1 is ex:
                return ex
            else:
                ex = ex1

    if ex.is_Add:
        res = _minpoly_add(x, dom, *ex.args)
    elif ex.is_Mul:
        f = Factors(ex).factors
        r = sift(f.items(), lambda itx: itx[0].is_Rational and itx[1].is_Rational)
        if r[True] and dom == QQ:
            ex1 = Mul(*[bx**ex for bx, ex in r[False] + r[None]])
            r1 = r[True]
            dens = [y.q for _, y in r1]
            lcmdens = reduce(lcm, dens, 1)
            nums = [base ** (y.p * lcmdens // y.q) for base, y in r1]
            ex2 = Mul(*nums)
            mp1 = minimal_polynomial(ex1, x)
            # use the fact that in SymPy canonicalization products of integers
            # raised to rational powers are organized in relatively prime
            # bases, and that in ``base**(n/d)`` a perfect power is
            # simplified with the root
            mp2 = ex2.q * x**lcmdens - ex2.p
            ex2 = ex2 ** Rational(1, lcmdens)
            res = _minpoly_op_algebraic_element(Mul, ex1, ex2, x, dom, mp1=mp1, mp2=mp2)
        else:
            res = _minpoly_mul(x, dom, *ex.args)
    elif ex.is_Pow:
        res = _minpoly_pow(ex.base, ex.exp, x, dom)
    elif ex.__class__ is sin:
        res = _minpoly_sin(ex, x)
    elif ex.__class__ is cos:
        res = _minpoly_cos(ex, x)
    elif ex.__class__ is exp:
        res = _minpoly_exp(ex, x)
    elif ex.__class__ is CRootOf:
        res = _minpoly_rootof(ex, x)
    else:
        raise NotAlgebraic("%s doesn't seem to be an algebraic element" % ex)
    return res


# Traceback (PolynomialError)
I found this from the expression from issue 5933 :

In [50]: [minpoly(i) for i in x.as_numer_denom()]
---------------------------------------------------------------------------
PolynomialError                           Traceback (most recent call last)
/Users/aaronmeurer/Documents/python/sympy/sympy/<ipython-input-50-ffbba6cffd4e> in <module>()
----> 1 [minpoly(i) for i in x.as_numer_denom()]

/Users/aaronmeurer/Documents/python/sympy/sympy/sympy/polys/numberfields.pyc in minimal_polynomial(ex, x, **args)
130     else:
131         F = [x - bottom_up_scan(ex)] + mapping.values()
--> 132         G = groebner(F, symbols.values() + [x], order='lex')
133
134         _, factors = factor_list(G[-1])

/Users/aaronmeurer/Documents/python/sympy/sympy/sympy/polys/polytools.pyc in groebner(F, *gens, **args)
5458
5459     """
-> 5460     return GroebnerBasis(F, *gens, **args)
5461
5462 def is_zero_dimensional(F, *gens, **args):

/Users/aaronmeurer/Documents/python/sympy/sympy/sympy/polys/polytools.pyc in __new__(cls, F, *gens, **args)
5485
5486         try:
-> 5487             polys, opt = parallel_poly_from_expr(F, *gens, **args)
5488         except PolificationFailed, exc:
5489             raise ComputationFailed('groebner', len(F), exc)

/Users/aaronmeurer/Documents/python/sympy/sympy/sympy/polys/polytools.pyc in parallel_poly_from_expr(exprs, *gens, **args)
3670     """Construct polynomials from expressions. """
3671     opt = options.build_options(gens, args)
-> 3672     return _parallel_poly_from_expr(exprs, opt)
3673
3674 def _parallel_poly_from_expr(exprs, opt):

/Users/aaronmeurer/Documents/python/sympy/sympy/sympy/polys/polytools.pyc in _parallel_poly_from_expr(exprs, opt)
3721
3722     try:
-> 3723         reps, opt = _parallel_dict_from_expr(exprs, opt)
3724     except GeneratorsNeeded:
3725         raise PolificationFailed(opt, origs, exprs, True)

/Users/aaronmeurer/Documents/python/sympy/sympy/sympy/polys/polyutils.pyc in _parallel_dict_from_expr(exprs, opt)
276
277     if opt.gens:
--> 278         reps, gens = _parallel_dict_from_expr_if_gens(exprs, opt)
279     else:
280         reps, gens = _parallel_dict_from_expr_no_gens(exprs, opt)

/Users/aaronmeurer/Documents/python/sympy/sympy/sympy/polys/polyutils.pyc in _parallel_dict_from_expr_if_gens(exprs, opt)
161                             coeff.append(factor)
162                         else:
--> 163                             raise PolynomialError("%s contains an element of the generators set" % factor)
164
165             monom = tuple(monom)

PolynomialError: sqrt(_a4) contains an element of the generators set

In [83]: print x
(-240*sqrt(2)*sqrt(sqrt(5) + 5)*sqrt(8*sqrt(5) + 40) - 360*sqrt(2)*sqrt(-8*sqrt(5) + 40)*sqrt(-sqrt(5) + 5) - 120*sqrt(10)*sqrt(-8*sqrt(5) + 40)*sqrt(-sqrt(5) + 5) + 120*sqrt(2)*sqrt(-8*sqrt(5) + 40)*sqrt(sqrt(5) + 5) + 120*sqrt(2)*sqrt(-sqrt(5) + 5)*sqrt(8*sqrt(5) + 40) + 120*sqrt(10)*sqrt(-8*sqrt(5) + 40)*sqrt(sqrt(5) + 5) + 120*sqrt(10)*sqrt(-sqrt(5) + 5)*sqrt(8*sqrt(5) + 40))/(-36000 - 7200*sqrt(5) + (12*sqrt(10)*sqrt(sqrt(5) + 5) + 24*sqrt(10)*sqrt(-sqrt(5) + 5))**2)

The error also occurs if you just call minpoly(x).

# Fixed code
def _minpoly_compose(ex, x, dom):
    """
    Computes the minimal polynomial of an algebraic element
    using operations on minimal polynomials

    Examples
    ========

    >>> from sympy import minimal_polynomial, sqrt, Rational
    >>> from sympy.abc import x, y
    >>> minimal_polynomial(sqrt(2) + 3*Rational(1, 3), x, compose=True)
    x**2 - 2*x - 1
    >>> minimal_polynomial(sqrt(y) + 1/y, x, compose=True)
    x**2*y**2 - 2*x*y - y**3 + 1

    """
    if ex.is_Rational:
        return ex.q * x - ex.p
    if ex is I:
        _, factors = factor_list(x**2 + 1, x, domain=dom)
        return x**2 + 1 if len(factors) == 1 else x - I
    if hasattr(dom, "symbols") and ex in dom.symbols:
        return x - ex

    if dom.is_QQ and _is_sum_surds(ex):
        # eliminate the square roots
        ex -= x
        while 1:
            ex1 = _separate_sq(ex)
            if ex1 is ex:
                return ex
            else:
                ex = ex1

    if ex.is_Add:
        res = _minpoly_add(x, dom, *ex.args)
    elif ex.is_Mul:
        f = Factors(ex).factors
        r = sift(f.items(), lambda itx: itx[0].is_Rational and itx[1].is_Rational)
        if r[True] and dom == QQ:
            ex1 = Mul(*[bx**ex for bx, ex in r[False] + r[None]])
            r1 = dict(r[True])
            dens = [y.q for y in r1.values()]
            lcmdens = reduce(lcm, dens, 1)
            neg1 = S.NegativeOne
            expn1 = r1.pop(neg1, S.Zero)
            nums = [base ** (y.p * lcmdens // y.q) for base, y in r1.items()]
            ex2 = Mul(*nums)
            mp1 = minimal_polynomial(ex1, x)
            # use the fact that in SymPy canonicalization products of integers
            # raised to rational powers are organized in relatively prime
            # bases, and that in ``base**(n/d)`` a perfect power is
            # simplified with the root
            # Powers of -1 have to be treated separately to preserve sign.
            mp2 = ex2.q * x**lcmdens - ex2.p * neg1 ** (expn1 * lcmdens)
            ex2 = neg1**expn1 * ex2 ** Rational(1, lcmdens)
            res = _minpoly_op_algebraic_element(Mul, ex1, ex2, x, dom, mp1=mp1, mp2=mp2)
        else:
            res = _minpoly_mul(x, dom, *ex.args)
    elif ex.is_Pow:
        res = _minpoly_pow(ex.base, ex.exp, x, dom)
    elif ex.__class__ is sin:
        res = _minpoly_sin(ex, x)
    elif ex.__class__ is cos:
        res = _minpoly_cos(ex, x)
    elif ex.__class__ is exp:
        res = _minpoly_exp(ex, x)
    elif ex.__class__ is CRootOf:
        res = _minpoly_rootof(ex, x)
    else:
        raise NotAlgebraic("%s doesn't seem to be an algebraic element" % ex)
    return res