def _minpoly_pow(ex, pw, x, dom):
    '\n    Returns ``minimal_polynomial(ex**pw)``\n\n    Parameters\n    ==========\n\n    ex : algebraic element\n    pw : rational number\n    x : indeterminate of the polynomial\n    dom: ground domain\n\n    Examples\n    ========\n\n    >>> p = sqrt(1 + sqrt(2))\n    >>> _minpoly_pow(p, 2, x, QQ)\n    x**2 - 2*x - 1\n    >>> minimal_polynomial(p**2)(x)\n    x**2 - 2*x - 1\n    >>> _minpoly_pow(y, Rational(1, 3), x, QQ.inject(y).field)\n    x**3 - y\n    >>> minimal_polynomial(cbrt(y))(x)\n    x**3 - y\n\n    '
    pw = sympify(pw)
    mp = _minpoly_compose(ex, x, dom)
    if (not pw.is_rational):
        raise NotAlgebraic(f"{ex} doesn't seem to be an algebraic element")
    if (pw < 0):
        if (mp == x):
            raise ZeroDivisionError(f'{ex} is zero')
        mp = _invertx(mp, x)
        if (pw == (- 1)):
            return mp
        pw = (- pw)
        ex = (1 / ex)
    y = Dummy(str(x))
    mp = mp.subs({x: y})
    (n, d) = pw.as_numer_denom()
    res = resultant(mp, ((x ** d) - (y ** n)), gens=[y]).as_poly(x, domain=dom)
    (_, factors) = res.factor_list()
    res = _choose_factor(factors, x, (ex ** pw), dom)
    return res.as_expr()
Returns ``minimal_polynomial(ex**pw)``

Parameters
==========

ex : algebraic element
pw : rational number
x : indeterminate of the polynomial
dom: ground domain

Examples
========

>>> p = sqrt(1 + sqrt(2))
>>> _minpoly_pow(p, 2, x, QQ)
x**2 - 2*x - 1
>>> minimal_polynomial(p**2)(x)
x**2 - 2*x - 1
>>> _minpoly_pow(y, Rational(1, 3), x, QQ.inject(y).field)
x**3 - y
>>> minimal_polynomial(cbrt(y))(x)
x**3 - y
def _minpoly_pow(ex, pw, x, dom):
    '\n    Returns ``minimal_polynomial(ex**pw)``\n\n    Parameters\n    ==========\n\n    ex : algebraic element\n    pw : rational number\n    x : indeterminate of the polynomial\n    dom: ground domain\n\n    Examples\n    ========\n\n    >>> p = sqrt(1 + sqrt(2))\n    >>> _minpoly_pow(p, 2, x, QQ)\n    x**2 - 2*x - 1\n    >>> minimal_polynomial(p**2)(x)\n    x**2 - 2*x - 1\n    >>> _minpoly_pow(y, Rational(1, 3), x, QQ.inject(y).field)\n    x**3 - y\n    >>> minimal_polynomial(cbrt(y))(x)\n    x**3 - y\n\n    '
    pw = sympify(pw)
    mp = _minpoly_compose(ex, x, dom)
    if (not pw.is_rational):
        raise NotAlgebraic(f"{ex} doesn't seem to be an algebraic element")
    if (pw < 0):
        if (mp == x):
            raise ZeroDivisionError(f'{ex} is zero')
        mp = _invertx(mp, x)
        if (pw == (- 1)):
            return mp
        pw = (- pw)
        ex = (1 / ex)
    y = Dummy(str(x))
    mp = mp.subs({x: y})
    (n, d) = pw.as_numer_denom()
    res = resultant(mp, ((x ** d) - (y ** n)), gens=[y]).as_poly(x, domain=dom)
    (_, factors) = res.factor_list()
    res = _choose_factor(factors, x, (ex ** pw), dom)
    return res.as_expr()