(b, c, n, DE)
return q
Poly Risch Differential Equation - Cancellation: Primitive case.

    Given a derivation D on k[t], n either an integer or +oo, b in k, and
    c in k[t] with Dt in k and b != 0, either raise
    NonElementaryIntegralException, in which case the equation Dq + b*q == c
    has no solution of degree at most n in k[t], or a solution q in k[t] of
    this equation with deg(q) <= n.
Poly Risch Differential Equation - Cancellation: Primitive case.
Poly Risch Differential Equation - Cancellation : Primitive case .
def cancel_primitive(b, c, n, DE):
    """
    Poly Risch Differential Equation - Cancellation: Primitive case.

    Given a derivation D on k[t], n either an integer or +oo, b in k, and
    c in k[t] with Dt in k and b != 0, either raise
    NonElementaryIntegralException, in which case the equation Dq + b*q == c
    has no solution of degree at most n in k[t], or a solution q in k[t] of
    this equation with deg(q) <= n.
    """
    from sympy.integrals.prde import is_log_deriv_k_t_radical_in_field

    with DecrementLevel(DE):
        ba, bd = frac_in(b, DE.t)
        A = is_log_deriv_k_t_radical_in_field(ba, bd, DE)
        if A is not None:
            n, z = A
            if n == 1:  # b == Dz/z
                raise NotImplementedError("is_deriv_in_field() is required to "
                    " solve this problem.")
                # if z*c == Dp for p in k[t] and deg(p) <= n:
                #     return p/z
                # else:
                #     raise NonElementaryIntegralException

    if c.is_zero:
        return c  # return 0

    if n < c.degree(DE.t):
        raise NonElementaryIntegralException

    q = Poly(0, DE.t)
    while not c.is_zero:
        m = c.degree(DE.t)
        if n < m:
            raise NonElementaryIntegralException
        with DecrementLevel(DE):
            a2a, a2d = frac_in(c.LC(), DE.t)
            sa, sd = rischDE(ba, bd, a2a, a2d, DE)
        stm = Poly(sa.as_expr()/sd.as_expr()*DE.t**m, DE.t, expand=False)
        q += stm
        n = m - 1
        c -= b*stm + derivation(stm, DE)

    return q
def cancel_primitive ( b , c , n , DE ) : from sympy . integrals . prde import is_log_deriv_k_t_radical_in_field with DecrementLevel ( DE ) : ba , bd = frac_in ( b , DE . t ) A = is_log_deriv_k_t_radical_in_field ( ba , bd , DE ) if A is not None : n , z = A if n == 1 : # b == Dz/z raise NotImplementedError ( "is_deriv_in_field() is required to " " solve this problem." ) # if z*c == Dp for p in k[t] and deg(p) <= n: #     return p/z # else: #     raise NonElementaryIntegralException if c . is_zero : return c # return 0 if n < c . degree ( DE . t ) : raise NonElementaryIntegralException q = Poly ( 0 , DE . t ) while not c . is_zero : m = c . degree ( DE . t ) if n < m : raise NonElementaryIntegralException with DecrementLevel ( DE ) : a2a , a2d = frac_in ( c . LC ( ) , DE . t ) sa , sd = rischDE ( ba , bd , a2a , a2d , DE ) stm = Poly ( sa . as_expr ( ) / sd . as_expr ( ) * DE . t ** m , DE . t , expand = False ) q += stm n = m - 1 c -= b * stm + derivation ( stm , DE ) return q