(p, DE)
Integration of primitive polynomials.

    Given a primitive monomial t over k, and p in k[t], return q in k[t],
    r in k, and a bool b in {True, False} such that r = p - Dq is in k if b is
    True, or r = p - Dq does not have an elementary integral over k(t) if b is
    False.
Integration of primitive polynomials.
Integration of primitive polynomials .
def integrate_primitive_polynomial(p, DE):
    """
    Integration of primitive polynomials.

    Given a primitive monomial t over k, and p in k[t], return q in k[t],
    r in k, and a bool b in {True, False} such that r = p - Dq is in k if b is
    True, or r = p - Dq does not have an elementary integral over k(t) if b is
    False.
    """
    from sympy.integrals.prde import limited_integrate

    Zero = Poly(0, DE.t)
    q = Poly(0, DE.t)

    if not p.has(DE.t):
        return (Zero, p, True)

    while True:
        if not p.has(DE.t):
            return (q, p, True)

        Dta, Dtb = frac_in(DE.d, DE.T[DE.level - 1])

        with DecrementLevel(DE):  # We had better be integrating the lowest extension (x)
                                  # with ratint().
            a = p.LC()
            aa, ad = frac_in(a, DE.t)

            try:
                (ba, bd), c = limited_integrate(aa, ad, [(Dta, Dtb)], DE)
                if len(c) != 1:
                    raise ValueError("Length of c should  be 1")
            except NonElementaryIntegralException:
                return (q, p, False)

        m = p.degree(DE.t)
        q0 = c[0].as_poly(DE.t)*Poly(DE.t**(m + 1)/(m + 1), DE.t) + \
            (ba.as_expr()/bd.as_expr()).as_poly(DE.t)*Poly(DE.t**m, DE.t)

        p = p - derivation(q0, DE)
        q = q + q0
def integrate_primitive_polynomial ( p , DE ) : from sympy . integrals . prde import limited_integrate Zero = Poly ( 0 , DE . t ) q = Poly ( 0 , DE . t ) if not p . has ( DE . t ) : return ( Zero , p , True ) while True : if not p . has ( DE . t ) : return ( q , p , True ) Dta , Dtb = frac_in ( DE . d , DE . T [ DE . level - 1 ] ) with DecrementLevel ( DE ) : # We had better be integrating the lowest extension (x) # with ratint(). a = p . LC ( ) aa , ad = frac_in ( a , DE . t ) try : ( ba , bd ) , c = limited_integrate ( aa , ad , [ ( Dta , Dtb ) ] , DE ) if len ( c ) != 1 : raise ValueError ( "Length of c should  be 1" ) except NonElementaryIntegralException : return ( q , p , False ) m = p . degree ( DE . t ) q0 = c [ 0 ] . as_poly ( DE . t ) * Poly ( DE . t ** ( m + 1 ) / ( m + 1 ) , DE . t ) + ( ba . as_expr ( ) / bd . as_expr ( ) ) . as_poly ( DE . t ) * Poly ( DE . t ** m , DE . t ) p = p - derivation ( q0 , DE ) q = q + q0