#NEWLINE# def log_to_atan( f , g ) : #NEWLINE# #INDENT# "\n    Convert complex logarithms to real arctangents.\n\n    Given a real field K and polynomials f and g in K[x], with g != 0,\n    returns a sum h of arctangents of polynomials in K[x], such that:\n\n                   dh   d         f + I g\n                   -- = -- I log( ------- )\n                   dx   dx        f - I g\n\n    Examples\n    ========\n\n        >>> from sympy.integrals.rationaltools import log_to_atan\n        >>> from sympy.abc import x\n        >>> from sympy import Poly, sqrt, S\n        >>> log_to_atan(Poly(x, x, domain='ZZ'), Poly(1, x, domain='ZZ'))\n        2*atan(x)\n        >>> log_to_atan(Poly(x + S(1)/2, x, domain='QQ'),\n        ... Poly(sqrt(3)/2, x, domain='EX'))\n        2*atan(2*sqrt(3)*x/3 + sqrt(3)/3)\n\n    See Also\n    ========\n\n    log_to_real\n    " #NEWLINE# if ( f . degree ( ) < g . degree ( ) ) : #NEWLINE# #INDENT# ( f , g ) = ( ( - g ) , f ) #NEWLINE# #UNINDENT# f = f . to_field ( ) #NEWLINE# g = g . to_field ( ) #NEWLINE# ( p , q ) = f . div ( g ) #NEWLINE# if q . is_zero : #NEWLINE# #INDENT# return ( 2 * atan ( p . as_expr ( ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ( s , t , h ) = g . gcdex ( ( - f ) ) #NEWLINE# u = ( ( f * s ) + ( g * t ) ) . quo ( h ) #NEWLINE# A = ( 2 * atan ( u . as_expr ( ) ) ) #NEWLINE# return ( A + log_to_atan ( s , t ) )