(a, d, DE, z=None)
return (ret, i, b)
Integration of primitive functions.

    Given a primitive monomial t over k and f in k(t), return g elementary over
    k(t), i in k(t), and b in {True, False} such that i = f - Dg is in k if b
    is True or i = f - Dg does not have an elementary integral over k(t) if b
    is False.

    This function returns a Basic expression for the first argument.  If b is
    True, the second argument is Basic expression in k to recursively integrate.
    If b is False, the second argument is an unevaluated Integral, which has
    been proven to be nonelementary.
Integration of primitive functions.
Integration of primitive functions .
def integrate_primitive(a, d, DE, z=None):
    """
    Integration of primitive functions.

    Given a primitive monomial t over k and f in k(t), return g elementary over
    k(t), i in k(t), and b in {True, False} such that i = f - Dg is in k if b
    is True or i = f - Dg does not have an elementary integral over k(t) if b
    is False.

    This function returns a Basic expression for the first argument.  If b is
    True, the second argument is Basic expression in k to recursively integrate.
    If b is False, the second argument is an unevaluated Integral, which has
    been proven to be nonelementary.
    """
    # XXX: a and d must be canceled, or this might return incorrect results
    z = z or Dummy("z")
    s = list(zip(reversed(DE.T), reversed([f(DE.x) for f in DE.Tfuncs])))

    g1, h, r = hermite_reduce(a, d, DE)
    g2, b = residue_reduce(h[0], h[1], DE, z=z)
    if not b:
        i = cancel(a.as_expr()/d.as_expr() - (g1[1]*derivation(g1[0], DE) -
            g1[0]*derivation(g1[1], DE)).as_expr()/(g1[1]**2).as_expr() -
            residue_reduce_derivation(g2, DE, z))
        i = NonElementaryIntegral(cancel(i).subs(s), DE.x)
        return ((g1[0].as_expr()/g1[1].as_expr()).subs(s) +
            residue_reduce_to_basic(g2, DE, z), i, b)

    # h - Dg2 + r
    p = cancel(h[0].as_expr()/h[1].as_expr() - residue_reduce_derivation(g2,
        DE, z) + r[0].as_expr()/r[1].as_expr())
    p = p.as_poly(DE.t)

    q, i, b = integrate_primitive_polynomial(p, DE)

    ret = ((g1[0].as_expr()/g1[1].as_expr() + q.as_expr()).subs(s) +
        residue_reduce_to_basic(g2, DE, z))
    if not b:
        # TODO: This does not do the right thing when b is False
        i = NonElementaryIntegral(cancel(i.as_expr()).subs(s), DE.x)
    else:
        i = cancel(i.as_expr())

    return (ret, i, b)
def integrate_primitive ( a , d , DE , z = None ) : # XXX: a and d must be canceled, or this might return incorrect results z = z or Dummy ( "z" ) s = list ( zip ( reversed ( DE . T ) , reversed ( [ f ( DE . x ) for f in DE . Tfuncs ] ) ) ) g1 , h , r = hermite_reduce ( a , d , DE ) g2 , b = residue_reduce ( h [ 0 ] , h [ 1 ] , DE , z = z ) if not b : i = cancel ( a . as_expr ( ) / d . as_expr ( ) - ( g1 [ 1 ] * derivation ( g1 [ 0 ] , DE ) - g1 [ 0 ] * derivation ( g1 [ 1 ] , DE ) ) . as_expr ( ) / ( g1 [ 1 ] ** 2 ) . as_expr ( ) - residue_reduce_derivation ( g2 , DE , z ) ) i = NonElementaryIntegral ( cancel ( i ) . subs ( s ) , DE . x ) return ( ( g1 [ 0 ] . as_expr ( ) / g1 [ 1 ] . as_expr ( ) ) . subs ( s ) + residue_reduce_to_basic ( g2 , DE , z ) , i , b ) # h - Dg2 + r p = cancel ( h [ 0 ] . as_expr ( ) / h [ 1 ] . as_expr ( ) - residue_reduce_derivation ( g2 , DE , z ) + r [ 0 ] . as_expr ( ) / r [ 1 ] . as_expr ( ) ) p = p . as_poly ( DE . t ) q , i , b = integrate_primitive_polynomial ( p , DE ) ret = ( ( g1 [ 0 ] . as_expr ( ) / g1 [ 1 ] . as_expr ( ) + q . as_expr ( ) ) . subs ( s ) + residue_reduce_to_basic ( g2 , DE , z ) ) if not b : # TODO: This does not do the right thing when b is False i = NonElementaryIntegral ( cancel ( i . as_expr ( ) ) . subs ( s ) , DE . x ) else : i = cancel ( i . as_expr ( ) ) return ( ret , i , b )