(a, b, c, n, DE)
Rothstein's Special Polynomial Differential Equation algorithm.

    Given a derivation D on k[t], an integer n and a, b, c in k[t] with
    a != 0, either raise NonElementaryIntegralException, in which case the
    equation a*Dq + b*q == c has no solution of degree at most n in
    k[t], or return the tuple (B, C, m, alpha, beta) such that B, C,
    alpha, beta in k[t], m in ZZ, and any solution q in k[t] of degree
    at most n of a*Dq + b*q == c must be of the form
    q == alpha*h + beta, where h in k[t], deg(h) <= m, and Dh + B*h == C.

    This constitutes step 4 of the outline given in the rde.py docstring.
Rothstein's Special Polynomial Differential Equation algorithm.
Rothstein s Special Polynomial Differential Equation algorithm .
def spde(a, b, c, n, DE):
    """
    Rothstein's Special Polynomial Differential Equation algorithm.

    Given a derivation D on k[t], an integer n and a, b, c in k[t] with
    a != 0, either raise NonElementaryIntegralException, in which case the
    equation a*Dq + b*q == c has no solution of degree at most n in
    k[t], or return the tuple (B, C, m, alpha, beta) such that B, C,
    alpha, beta in k[t], m in ZZ, and any solution q in k[t] of degree
    at most n of a*Dq + b*q == c must be of the form
    q == alpha*h + beta, where h in k[t], deg(h) <= m, and Dh + B*h == C.

    This constitutes step 4 of the outline given in the rde.py docstring.
    """
    zero = Poly(0, DE.t)

    alpha = Poly(1, DE.t)
    beta = Poly(0, DE.t)
    pow_a = 0

    while True:
        if (n < 0) is True:
            if c.is_zero:
                return (zero, zero, 0, zero, beta)
            raise NonElementaryIntegralException

        g = a.gcd(b)
        if not c.rem(g).is_zero:  # g does not divide c
            raise NonElementaryIntegralException

        a, b, c = a.quo(g), b.quo(g), c.quo(g)

        if a.degree(DE.t) == 0:
            b = b.to_field().quo(a)
            c = c.to_field().quo(a)
            return (b, c, n, alpha, beta)

        r, z = gcdex_diophantine(b, a, c)
        b += derivation(a, DE)
        c = z - derivation(r, DE)
        n -= a.degree(DE.t)
        alpha *= a
        beta += (a**pow_a)*r
        pow_a += 1
def spde ( a , b , c , n , DE ) : zero = Poly ( 0 , DE . t ) alpha = Poly ( 1 , DE . t ) beta = Poly ( 0 , DE . t ) pow_a = 0 while True : if ( n < 0 ) is True : if c . is_zero : return ( zero , zero , 0 , zero , beta ) raise NonElementaryIntegralException g = a . gcd ( b ) if not c . rem ( g ) . is_zero : # g does not divide c raise NonElementaryIntegralException a , b , c = a . quo ( g ) , b . quo ( g ) , c . quo ( g ) if a . degree ( DE . t ) == 0 : b = b . to_field ( ) . quo ( a ) c = c . to_field ( ) . quo ( a ) return ( b , c , n , alpha , beta ) r , z = gcdex_diophantine ( b , a , c ) b += derivation ( a , DE ) c = z - derivation ( r , DE ) n -= a . degree ( DE . t ) alpha *= a beta += ( a ** pow_a ) * r pow_a += 1