def _nthroot_solve(p, n, prec):
 from sympy.polys.numberfields import _minimal_polynomial_sq
 from sympy.solvers import solve
 while ((n % 2) == 0):
  p = sqrtdenest(sqrt(p))
  n = (n // 2)
 if (n == 1):
  return p
 pn = (p ** Rational(1, n))
 x = Symbol('x')
 f = _minimal_polynomial_sq(p, n, x)
 if (f is None):
  return None
 sols = solve(f, x)
 for sol in sols:
  if (abs((sol - pn)).n() < (1.0 / (10 ** prec))):
   sol = sqrtdenest(sol)
   if (_mexpand((sol ** n)) == p):
    return sol

def _nthroot_solve ( p , n , prec ) : from sympy . polys . numberfields import _minimal_polynomial_sq from sympy . solvers import solve while ( ( n % 2 ) == 0 ) : p = sqrtdenest ( sqrt ( p ) ) n = ( n // 2 ) if ( n == 1 ) : return p pn = ( p ** Rational ( 1 , n ) ) x = Symbol ( 'x' ) f = _minimal_polynomial_sq ( p , n , x ) if ( f is None ) : return None sols = solve ( f , x ) for sol in sols : if ( abs ( ( sol - pn ) ) . n ( ) < ( 1.0 / ( 10 ** prec ) ) ) : sol = sqrtdenest ( sol ) if ( _mexpand ( ( sol ** n ) ) == p ) : return sol
helper function for nthroot it denests p**rational using its minimal polynomial .