def _nth_root1(p, n, x, prec):
 if rs_is_puiseux(p, x):
  return rs_puiseux2(_nth_root1, p, n, x, prec)
 R = p.ring
 zm = R.zero_monom
 if (zm not in p):
  raise NotImplementedError('No constant term in series')
 n = as_int(n)
 assert (p[zm] == 1)
 p1 = R(1)
 if (p == 1):
  return p
 if (n == 0):
  return R(1)
 if (n == 1):
  return p
 if (n < 0):
  n = (- n)
  sign = 1
 else:
  sign = 0
 for precx in _giant_steps(prec):
  tmp = rs_pow(p1, (n + 1), x, precx)
  tmp = rs_mul(tmp, p, x, precx)
  p1 += ((p1 / n) - (tmp / n))
 if sign:
  return p1
 else:
  return _series_inversion1(p1, x, prec)

def _nth_root1 ( p , n , x , prec ) : if rs_is_puiseux ( p , x ) : return rs_puiseux2 ( _nth_root1 , p , n , x , prec ) R = p . ring zm = R . zero_monom if ( zm not in p ) : raise NotImplementedError ( 'No constant term in series' ) n = as_int ( n ) assert ( p [ zm ] == 1 ) p1 = R ( 1 ) if ( p == 1 ) : return p if ( n == 0 ) : return R ( 1 ) if ( n == 1 ) : return p if ( n < 0 ) : n = ( - n ) sign = 1 else : sign = 0 for precx in _giant_steps ( prec ) : tmp = rs_pow ( p1 , ( n + 1 ) , x , precx ) tmp = rs_mul ( tmp , p , x , precx ) p1 += ( ( p1 / n ) - ( tmp / n ) ) if sign : return p1 else : return _series_inversion1 ( p1 , x , prec )
univariate series expansion of the nth root of p .