(f, x, **flags)
return coeff*result
Performs indefinite integration of rational functions.

       Given a field :math:`K` and a rational function :math:`f = p/q`,
       where :math:`p` and :math:`q` are polynomials in :math:`K[x]`,
       returns a function :math:`g` such that :math:`f = g'`.

       >>> from sympy.integrals.rationaltools import ratint
       >>> from sympy.abc import x

       >>> ratint(36/(x**5 - 2*x**4 - 2*x**3 + 4*x**2 + x - 2), x)
       (12*x + 6)/(x**2 - 1) + 4*log(x - 2) - 4*log(x + 1)

       References
       ==========

       .. [Bro05] M. Bronstein, Symbolic Integration I: Transcendental
          Functions, Second Edition, Springer-Verlag, 2005, pp. 35-70

       See Also
       ========

       sympy.integrals.integrals.Integral.doit
       ratint_logpart, ratint_ratpart
Performs indefinite integration of rational functions.
Performs indefinite integration of rational functions .
def ratint(f, x, **flags):
    """Performs indefinite integration of rational functions.

       Given a field :math:`K` and a rational function :math:`f = p/q`,
       where :math:`p` and :math:`q` are polynomials in :math:`K[x]`,
       returns a function :math:`g` such that :math:`f = g'`.

       >>> from sympy.integrals.rationaltools import ratint
       >>> from sympy.abc import x

       >>> ratint(36/(x**5 - 2*x**4 - 2*x**3 + 4*x**2 + x - 2), x)
       (12*x + 6)/(x**2 - 1) + 4*log(x - 2) - 4*log(x + 1)

       References
       ==========

       .. [Bro05] M. Bronstein, Symbolic Integration I: Transcendental
          Functions, Second Edition, Springer-Verlag, 2005, pp. 35-70

       See Also
       ========

       sympy.integrals.integrals.Integral.doit
       ratint_logpart, ratint_ratpart
    """
    if type(f) is not tuple:
        p, q = f.as_numer_denom()
    else:
        p, q = f

    p, q = Poly(p, x, composite=False, field=True), Poly(q, x, composite=False, field=True)

    coeff, p, q = p.cancel(q)
    poly, p = p.div(q)

    result = poly.integrate(x).as_expr()

    if p.is_zero:
        return coeff*result

    g, h = ratint_ratpart(p, q, x)

    P, Q = h.as_numer_denom()

    P = Poly(P, x)
    Q = Poly(Q, x)

    q, r = P.div(Q)

    result += g + q.integrate(x).as_expr()

    if not r.is_zero:
        symbol = flags.get('symbol', 't')

        if not isinstance(symbol, Symbol):
            t = Dummy(symbol)
        else:
            t = symbol.as_dummy()

        L = ratint_logpart(r, Q, x, t)

        real = flags.get('real')

        if real is None:
            if type(f) is not tuple:
                atoms = f.atoms()
            else:
                p, q = f

                atoms = p.atoms() | q.atoms()

            for elt in atoms - set([x]):
                if not elt.is_real:
                    real = False
                    break
            else:
                real = True

        eps = S(0)

        if not real:
            for h, q in L:
                eps += RootSum(
                    q, Lambda(t, t*log(h.as_expr())), quadratic=True)
        else:
            for h, q in L:
                R = log_to_real(h, q, x, t)

                if R is not None:
                    eps += R
                else:
                    eps += RootSum(
                        q, Lambda(t, t*log(h.as_expr())), quadratic=True)

        result += eps

    return coeff*result
def ratint ( f , x , * * flags ) : if type ( f ) is not tuple : p , q = f . as_numer_denom ( ) else : p , q = f p , q = Poly ( p , x , composite = False , field = True ) , Poly ( q , x , composite = False , field = True ) coeff , p , q = p . cancel ( q ) poly , p = p . div ( q ) result = poly . integrate ( x ) . as_expr ( ) if p . is_zero : return coeff * result g , h = ratint_ratpart ( p , q , x ) P , Q = h . as_numer_denom ( ) P = Poly ( P , x ) Q = Poly ( Q , x ) q , r = P . div ( Q ) result += g + q . integrate ( x ) . as_expr ( ) if not r . is_zero : symbol = flags . get ( 'symbol' , 't' ) if not isinstance ( symbol , Symbol ) : t = Dummy ( symbol ) else : t = symbol . as_dummy ( ) L = ratint_logpart ( r , Q , x , t ) real = flags . get ( 'real' ) if real is None : if type ( f ) is not tuple : atoms = f . atoms ( ) else : p , q = f atoms = p . atoms ( ) | q . atoms ( ) for elt in atoms - set ( [ x ] ) : if not elt . is_real : real = False break else : real = True eps = S ( 0 ) if not real : for h , q in L : eps += RootSum ( q , Lambda ( t , t * log ( h . as_expr ( ) ) ) , quadratic = True ) else : for h , q in L : R = log_to_real ( h , q , x , t ) if R is not None : eps += R else : eps += RootSum ( q , Lambda ( t , t * log ( h . as_expr ( ) ) ) , quadratic = True ) result += eps return coeff * result