def rs_log(p, x, prec):
 if rs_is_puiseux(p, x):
  return rs_puiseux(rs_log, p, x, prec)
 R = p.ring
 if (p == 1):
  return R.zero
 if _has_constant_term(p, x):
  const = 0
  zm = R.zero_monom
  c = p[zm]
  if (c == 1):
   pass
  else:
   c_expr = c.as_expr()
   if (R.domain is EX):
    const = log(c_expr)
   elif isinstance(c, PolyElement):
    try:
     const = R(log(c_expr))
    except ValueError:
     raise DomainError("The given series can't be expanded in this domain.")
   else:
    try:
     const = R(log(c))
    except ValueError:
     raise DomainError("The given series can't be expanded in this domain.")
  dlog = p.diff(x)
  dlog = rs_mul(dlog, _series_inversion1(p, x, prec), x, (prec - 1))
  return (rs_integrate(dlog, x) + const)
 else:
  raise NotImplementedError

def rs_log ( p , x , prec ) : if rs_is_puiseux ( p , x ) : return rs_puiseux ( rs_log , p , x , prec ) R = p . ring if ( p == 1 ) : return R . zero if _has_constant_term ( p , x ) : const = 0 zm = R . zero_monom c = p [ zm ] if ( c == 1 ) : pass else : c_expr = c . as_expr ( ) if ( R . domain is EX ) : const = log ( c_expr ) elif isinstance ( c , PolyElement ) : try : const = R ( log ( c_expr ) ) except ValueError : raise DomainError ( "The given series can't be expanded in this domain." ) else : try : const = R ( log ( c ) ) except ValueError : raise DomainError ( "The given series can't be expanded in this domain." ) dlog = p . diff ( x ) dlog = rs_mul ( dlog , _series_inversion1 ( p , x , prec ) , x , ( prec - 1 ) ) return ( rs_integrate ( dlog , x ) + const ) else : raise NotImplementedError
the logarithm of p modulo o .