def _minimal_polynomial_sq(p, n, x):
    '\n    Returns the minimal polynomial for the ``nth-root`` of a sum of surds\n    or ``None`` if it fails.\n\n    Parameters\n    ==========\n\n    p : sum of surds\n    n : positive integer\n    x : variable of the returned polynomial\n\n    Examples\n    ========\n\n    >>> q = 1 + sqrt(2) + sqrt(3)\n    >>> _minimal_polynomial_sq(q, 3, x)\n    x**12 - 4*x**9 - 4*x**6 + 16*x**3 - 8\n\n    '
    p = sympify(p)
    n = sympify(n)
    assert (n.is_Integer and (n > 1) and _is_sum_surds(p))
    pn = root(p, n)
    p -= x
    while 1:
        p1 = _separate_sq(p)
        if (p1 is p):
            p = p1.subs({x: (x ** n)})
            break
        else:
            p = p1
    factors = factor_list(p)[1]
    return _choose_factor(factors, x, pn)
Returns the minimal polynomial for the ``nth-root`` of a sum of surds
or ``None`` if it fails.

Parameters
==========

p : sum of surds
n : positive integer
x : variable of the returned polynomial

Examples
========

>>> q = 1 + sqrt(2) + sqrt(3)
>>> _minimal_polynomial_sq(q, 3, x)
x**12 - 4*x**9 - 4*x**6 + 16*x**3 - 8
def _minimal_polynomial_sq(p, n, x):
    '\n    Returns the minimal polynomial for the ``nth-root`` of a sum of surds\n    or ``None`` if it fails.\n\n    Parameters\n    ==========\n\n    p : sum of surds\n    n : positive integer\n    x : variable of the returned polynomial\n\n    Examples\n    ========\n\n    >>> q = 1 + sqrt(2) + sqrt(3)\n    >>> _minimal_polynomial_sq(q, 3, x)\n    x**12 - 4*x**9 - 4*x**6 + 16*x**3 - 8\n\n    '
    p = sympify(p)
    n = sympify(n)
    assert (n.is_Integer and (n > 1) and _is_sum_surds(p))
    pn = root(p, n)
    p -= x
    while 1:
        p1 = _separate_sq(p)
        if (p1 is p):
            p = p1.subs({x: (x ** n)})
            break
        else:
            p = p1
    factors = factor_list(p)[1]
    return _choose_factor(factors, x, pn)