#NEWLINE# def _minimal_polynomial_sq( p , n , x ) : #NEWLINE# #INDENT# '\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    >>> from sympy.polys.numberfields import _minimal_polynomial_sq\n    >>> from sympy import sqrt\n    >>> from sympy.abc import x\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    ' #NEWLINE# from sympy.simplify.simplify import _is_sum_surds #NEWLINE# p = sympify ( p ) #NEWLINE# n = sympify ( n ) #NEWLINE# r = _is_sum_surds ( p ) #NEWLINE# if ( ( not n . is_Integer ) or ( not ( n > 0 ) ) or ( not _is_sum_surds ( p ) ) ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# pn = ( p ** Rational ( 1 , n ) ) #NEWLINE# p -= x #NEWLINE# while 1 : #NEWLINE# #INDENT# p1 = _separate_sq ( p ) #NEWLINE# if ( p1 is p ) : #NEWLINE# #INDENT# p = p1 . subs ( { #NEWLINE# #INDENT# x : ( x ** n ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# break #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# p = p1 #NEWLINE# #UNINDENT# #UNINDENT# if ( n == 1 ) : #NEWLINE# #INDENT# p1 = Poly ( p ) #NEWLINE# if ( p . coeff ( ( x ** p1 . degree ( x ) ) ) < 0 ) : #NEWLINE# #INDENT# p = ( - p1 ) #NEWLINE# #UNINDENT# p = p . primitive ( ) [ 1 ] #NEWLINE# return p #NEWLINE# #UNINDENT# factors = factor_list ( p ) [ 1 ] #NEWLINE# result = _choose_factor ( factors , x , pn ) #NEWLINE# return result