def _minimal_polynomial_sq(p, n, x):
 from sympy.simplify.simplify import _is_sum_surds
 p = sympify(p)
 n = sympify(n)
 r = _is_sum_surds(p)
 if ((not n.is_Integer) or (not (n > 0)) or (not _is_sum_surds(p))):
  return None
 pn = (p ** Rational(1, n))
 p -= x
 while 1:
  p1 = _separate_sq(p)
  if (p1 is p):
   p = p1.subs({x: (x ** n)})
   break
  else:
   p = p1
 if (n == 1):
  p1 = Poly(p)
  if (p.coeff((x ** p1.degree(x))) < 0):
   p = (- p)
  p = p.primitive()[1]
  return p
 factors = factor_list(p)[1]
 result = _choose_factor(factors, x, pn)
 return result

def _minimal_polynomial_sq ( p , n , x ) : from sympy . simplify . simplify import _is_sum_surds p = sympify ( p ) n = sympify ( n ) r = _is_sum_surds ( p ) if ( ( not n . is_Integer ) or ( not ( n > 0 ) ) or ( not _is_sum_surds ( p ) ) ) : return None pn = ( p ** Rational ( 1 , n ) ) p -= x while 1 : p1 = _separate_sq ( p ) if ( p1 is p ) : p = p1 . subs ( { x : ( x ** n ) } ) break else : p = p1 if ( n == 1 ) : p1 = Poly ( p ) if ( p . coeff ( ( x ** p1 . degree ( x ) ) ) < 0 ) : p = ( - p ) p = p . primitive ( ) [ 1 ] return p factors = factor_list ( p ) [ 1 ] result = _choose_factor ( factors , x , pn ) return result
returns the minimal polynomial for the nth-root of a sum of surds or none if it fails .