def log_to_atan(f, g):
 if (f.degree() < g.degree()):
  (f, g) = ((- g), f)
 f = f.to_field()
 g = g.to_field()
 (p, q) = f.div(g)
 if q.is_zero:
  return (2 * atan(p.as_expr()))
 else:
  (s, t, h) = g.gcdex((- f))
  u = ((f * s) + (g * t)).quo(h)
  A = (2 * atan(u.as_expr()))
  return (A + log_to_atan(s, t))

def log_to_atan ( f , g ) : if ( f . degree ( ) < g . degree ( ) ) : ( f , g ) = ( ( - g ) , f ) f = f . to_field ( ) g = g . to_field ( ) ( p , q ) = f . div ( g ) if q . is_zero : return ( 2 * atan ( p . as_expr ( ) ) ) else : ( s , t , h ) = g . gcdex ( ( - f ) ) u = ( ( f * s ) + ( g * t ) ) . quo ( h ) A = ( 2 * atan ( u . as_expr ( ) ) ) return ( A + log_to_atan ( s , t ) )
convert complex logarithms to real arctangents .