def rs_LambertW(p, x, prec):
 if rs_is_puiseux(p, x):
  return rs_puiseux(rs_LambertW, p, x, prec)
 R = p.ring
 p1 = R(0)
 if _has_constant_term(p, x):
  raise NotImplementedError('Polynomial must not have constant term in the series variables')
 if (x in R.gens):
  for precx in _giant_steps(prec):
   e = rs_exp(p1, x, precx)
   p2 = (rs_mul(e, p1, x, precx) - p)
   p3 = rs_mul(e, (p1 + 1), x, precx)
   p3 = rs_series_inversion(p3, x, precx)
   tmp = rs_mul(p2, p3, x, precx)
   p1 -= tmp
  return p1
 else:
  raise NotImplementedError

def rs_LambertW ( p , x , prec ) : if rs_is_puiseux ( p , x ) : return rs_puiseux ( rs_LambertW , p , x , prec ) R = p . ring p1 = R ( 0 ) if _has_constant_term ( p , x ) : raise NotImplementedError ( 'Polynomial must not have constant term in the series variables' ) if ( x in R . gens ) : for precx in _giant_steps ( prec ) : e = rs_exp ( p1 , x , precx ) p2 = ( rs_mul ( e , p1 , x , precx ) - p ) p3 = rs_mul ( e , ( p1 + 1 ) , x , precx ) p3 = rs_series_inversion ( p3 , x , precx ) tmp = rs_mul ( p2 , p3 , x , precx ) p1 -= tmp return p1 else : raise NotImplementedError
calculate the series expansion of the principal branch of the lambert w function .