(h, q, x, t)
return result
Convert complex logarithms to real functions.

    Given real field K and polynomials h in K[t,x] and q in K[t],
    returns real function f such that:
                          ___
                  df   d  \  `
                  -- = --  )  a log(h(a, x))
                  dx   dx /__,
                         a | q(a) = 0

    Examples
    ========

        >>> from sympy.integrals.rationaltools import log_to_real
        >>> from sympy.abc import x, y
        >>> from sympy import Poly, sqrt, S
        >>> log_to_real(Poly(x + 3*y/2 + S(1)/2, x, domain='QQ[y]'),
        ... Poly(3*y**2 + 1, y, domain='ZZ'), x, y)
        2*sqrt(3)*atan(2*sqrt(3)*x/3 + sqrt(3)/3)/3
        >>> log_to_real(Poly(x**2 - 1, x, domain='ZZ'),
        ... Poly(-2*y + 1, y, domain='ZZ'), x, y)
        log(x**2 - 1)/2

    See Also
    ========

    log_to_atan
Convert complex logarithms to real functions.
Convert complex logarithms to real functions .
def log_to_real(h, q, x, t):
    """
    Convert complex logarithms to real functions.

    Given real field K and polynomials h in K[t,x] and q in K[t],
    returns real function f such that:
                          ___
                  df   d  \  `
                  -- = --  )  a log(h(a, x))
                  dx   dx /__,
                         a | q(a) = 0

    Examples
    ========

        >>> from sympy.integrals.rationaltools import log_to_real
        >>> from sympy.abc import x, y
        >>> from sympy import Poly, sqrt, S
        >>> log_to_real(Poly(x + 3*y/2 + S(1)/2, x, domain='QQ[y]'),
        ... Poly(3*y**2 + 1, y, domain='ZZ'), x, y)
        2*sqrt(3)*atan(2*sqrt(3)*x/3 + sqrt(3)/3)/3
        >>> log_to_real(Poly(x**2 - 1, x, domain='ZZ'),
        ... Poly(-2*y + 1, y, domain='ZZ'), x, y)
        log(x**2 - 1)/2

    See Also
    ========

    log_to_atan
    """
    u, v = symbols('u,v', cls=Dummy)

    H = h.as_expr().subs({t: u + I*v}).expand()
    Q = q.as_expr().subs({t: u + I*v}).expand()

    H_map = collect(H, I, evaluate=False)
    Q_map = collect(Q, I, evaluate=False)

    a, b = H_map.get(S(1), S(0)), H_map.get(I, S(0))
    c, d = Q_map.get(S(1), S(0)), Q_map.get(I, S(0))

    R = Poly(resultant(c, d, v), u)

    R_u = roots(R, filter='R')

    if len(R_u) != R.count_roots():
        return None

    result = S(0)

    for r_u in R_u.keys():
        C = Poly(c.subs({u: r_u}), v)
        R_v = roots(C, filter='R')

        if len(R_v) != C.count_roots():
            return None

        for r_v in R_v:
            if not r_v.is_positive:
                continue

            D = d.subs({u: r_u, v: r_v})

            if D.evalf(chop=True) != 0:
                continue

            A = Poly(a.subs({u: r_u, v: r_v}), x)
            B = Poly(b.subs({u: r_u, v: r_v}), x)

            AB = (A**2 + B**2).as_expr()

            result += r_u*log(AB) + r_v*log_to_atan(A, B)

    R_q = roots(q, filter='R')

    if len(R_q) != q.count_roots():
        return None

    for r in R_q.keys():
        result += r*log(h.as_expr().subs(t, r))

    return result
def log_to_real ( h , q , x , t ) : u , v = symbols ( 'u,v' , cls = Dummy ) H = h . as_expr ( ) . subs ( { t : u + I * v } ) . expand ( ) Q = q . as_expr ( ) . subs ( { t : u + I * v } ) . expand ( ) H_map = collect ( H , I , evaluate = False ) Q_map = collect ( Q , I , evaluate = False ) a , b = H_map . get ( S ( 1 ) , S ( 0 ) ) , H_map . get ( I , S ( 0 ) ) c , d = Q_map . get ( S ( 1 ) , S ( 0 ) ) , Q_map . get ( I , S ( 0 ) ) R = Poly ( resultant ( c , d , v ) , u ) R_u = roots ( R , filter = 'R' ) if len ( R_u ) != R . count_roots ( ) : return None result = S ( 0 ) for r_u in R_u . keys ( ) : C = Poly ( c . subs ( { u : r_u } ) , v ) R_v = roots ( C , filter = 'R' ) if len ( R_v ) != C . count_roots ( ) : return None for r_v in R_v : if not r_v . is_positive : continue D = d . subs ( { u : r_u , v : r_v } ) if D . evalf ( chop = True ) != 0 : continue A = Poly ( a . subs ( { u : r_u , v : r_v } ) , x ) B = Poly ( b . subs ( { u : r_u , v : r_v } ) , x ) AB = ( A ** 2 + B ** 2 ) . as_expr ( ) result += r_u * log ( AB ) + r_v * log_to_atan ( A , B ) R_q = roots ( q , filter = 'R' ) if len ( R_q ) != q . count_roots ( ) : return None for r in R_q . keys ( ) : result += r * log ( h . as_expr ( ) . subs ( t , r ) ) return result