def test_integrate_hyperexponential_returns_piecewise(): a, b = symbols('a b') DE = DifferentialExtension(a**x, x) assert integrate_hyperexponential(DE.fa, DE.fd, DE) == (Piecewise( (x, Eq(log(a), 0)), (exp(x*log(a))/log(a), True)), 0, True) DE = DifferentialExtension(a**(b*x), x) assert integrate_hyperexponential(DE.fa, DE.fd, DE) == (Piecewise( (x, Eq(b*log(a), 0)), (exp(b*x*log(a))/(b*log(a)), True)), 0, True) DE = DifferentialExtension(exp(a*x), x) assert integrate_hyperexponential(DE.fa, DE.fd, DE) == (Piecewise( (x, Eq(a, 0)), (exp(a*x)/a, True)), 0, True)
def test_integrate_hyperexponential(): # TODO: Add tests for integrate_hyperexponential() from the book a = Poly((1 + 2*t1 + t1**2 + 2*t1**3)*t**2 + (1 + t1**2)*t + 1 + t1**2, t) d = Poly(1, t) DE = DifferentialExtension(extension={'D': [Poly(1, x), Poly(1 + t1**2, t1), Poly(t*(1 + t1**2), t)], 'Tfuncs': [tan, lambda x: exp(tan(x))]}) assert integrate_hyperexponential(a, d, DE) == \ (exp(2*tan(x))*tan(x) + exp(tan(x)), 1 + t1**2, True) # exp(2*tan(x))*tan(x) + tan(x) + exp(tan(x)) a = Poly((t1**3 + (x + 1)*t1**2 + t1 + x + 2)*t, t) assert integrate_hyperexponential(a, d, DE) == \ ((x + tan(x))*exp(tan(x)), 0, True) a = Poly(t, t) d = Poly(1, t) DE = DifferentialExtension(extension={'D': [Poly(1, x), Poly(2*x*t, t)], 'Tfuncs': [lambda x: exp(x**2)]}) assert integrate_hyperexponential(a, d, DE) == \ (0, NonElementaryIntegral(exp(x**2), x), False) DE = DifferentialExtension(extension={'D': [Poly(1, x), Poly(t, t)], 'Tfuncs': [exp]}) assert integrate_hyperexponential(a, d, DE) == (exp(x), 0, True) a = Poly(25*t**6 - 10*t**5 + 7*t**4 - 8*t**3 + 13*t**2 + 2*t - 1, t) d = Poly(25*t**6 + 35*t**4 + 11*t**2 + 1, t) assert integrate_hyperexponential(a, d, DE) == \ (-(55 - 50*exp(x))/(25 + 125*exp(2*x)) + log(1 + exp(2*x)), -1, True) # -(55 - 50*exp(x))/(25 + 125*exp(2*x)) - x + log(1 + exp(2*x)) DE = DifferentialExtension(extension={'D': [Poly(1, x), Poly(t0, t0), Poly(t0*t, t)], 'Tfuncs': [exp, lambda x: exp(exp(x))]}) assert integrate_hyperexponential(Poly(2*t0*t**2, t), Poly(1, t), DE) == (exp(2*exp(x)), 0, True) DE = DifferentialExtension(extension={'D': [Poly(1, x), Poly(t0, t0), Poly(-t0*t, t)], 'Tfuncs': [exp, lambda x: exp(-exp(x))]}) assert integrate_hyperexponential(Poly(-27*exp(9) - 162*t0*exp(9) + 27*x*t0*exp(9), t), Poly((36*exp(18) + x**2*exp(18) - 12*x*exp(18))*t, t), DE) == \ (27*exp(exp(x))/(-6*exp(9) + x*exp(9)), 0, True) DE = DifferentialExtension(extension={'D': [Poly(1, x), Poly(t, t)], 'Tfuncs': [exp]}) assert integrate_hyperexponential(Poly(x**2/2*t, t), Poly(1, t), DE) == \ ((2 - 2*x + x**2)*exp(x)/2, 0, True) assert integrate_hyperexponential(Poly(1 + t, t), Poly(t, t), DE) == \ (-exp(-x), 1, True) # x - exp(-x) assert integrate_hyperexponential(Poly(x, t), Poly(t + 1, t), DE) == \ (0, NonElementaryIntegral(x/(1 + exp(x)), x), False)
def test_integrate_hyperexponential_returns_piecewise(): a, b = symbols('a b') DE = DifferentialExtension(a**x, x) assert integrate_hyperexponential(DE.fa, DE.fd, DE) == (Piecewise( (x, Eq(log(a), 0)), (exp(x*log(a))/log(a), True)), 0, True) DE = DifferentialExtension(a**(b*x), x) assert integrate_hyperexponential(DE.fa, DE.fd, DE) == (Piecewise( (x, Eq(b*log(a), 0)), (exp(b*x*log(a))/(b*log(a)), True)), 0, True) DE = DifferentialExtension(exp(a*x), x) assert integrate_hyperexponential(DE.fa, DE.fd, DE) == (Piecewise( (x, Eq(a, 0)), (exp(a*x)/a, True)), 0, True) DE = DifferentialExtension(x*exp(a*x), x) assert integrate_hyperexponential(DE.fa, DE.fd, DE) == (Piecewise( (x**2/2, Eq(a**3, 0)), ((x*a**2 - a)*exp(a*x)/a**3, True)), 0, True) DE = DifferentialExtension(x**2*exp(a*x), x) assert integrate_hyperexponential(DE.fa, DE.fd, DE) == (Piecewise( (x**3/3, Eq(a**6, 0)), ((x**2*a**5 - 2*x*a**4 + 2*a**3)*exp(a*x)/a**6, True)), 0, True) DE = DifferentialExtension(x**y + z, y) assert integrate_hyperexponential(DE.fa, DE.fd, DE) == (Piecewise((y, Eq(log(x), 0)), (exp(log(x)*y)/log(x), True)), z, True) DE = DifferentialExtension(x**y + z + x**(2*y), y) assert integrate_hyperexponential(DE.fa, DE.fd, DE) == (Piecewise((2*y, Eq(2*log(x)**2, 0)), ((exp(2*log(x)*y)*log(x) + 2*exp(log(x)*y)*log(x))/(2*log(x)**2), True)), z, True)
def test_integrate_hyperexponential_returns_piecewise(): a, b = symbols('a b') DE = DifferentialExtension(a**x, x) assert integrate_hyperexponential(DE.fa, DE.fd, DE) == (Piecewise( (exp(x*log(a))/log(a), Ne(log(a), 0)), (x, True)), 0, True) DE = DifferentialExtension(a**(b*x), x) assert integrate_hyperexponential(DE.fa, DE.fd, DE) == (Piecewise( (exp(b*x*log(a))/(b*log(a)), Ne(b*log(a), 0)), (x, True)), 0, True) DE = DifferentialExtension(exp(a*x), x) assert integrate_hyperexponential(DE.fa, DE.fd, DE) == (Piecewise( (exp(a*x)/a, Ne(a, 0)), (x, True)), 0, True) DE = DifferentialExtension(x*exp(a*x), x) assert integrate_hyperexponential(DE.fa, DE.fd, DE) == (Piecewise( ((a*x - 1)*exp(a*x)/a**2, Ne(a**2, 0)), (x**2/2, True)), 0, True) DE = DifferentialExtension(x**2*exp(a*x), x) assert integrate_hyperexponential(DE.fa, DE.fd, DE) == (Piecewise( ((x**2*a**2 - 2*a*x + 2)*exp(a*x)/a**3, Ne(a**3, 0)), (x**3/3, True)), 0, True) DE = DifferentialExtension(x**y + z, y) assert integrate_hyperexponential(DE.fa, DE.fd, DE) == (Piecewise( (exp(log(x)*y)/log(x), Ne(log(x), 0)), (y, True)), z, True) DE = DifferentialExtension(x**y + z + x**(2*y), y) assert integrate_hyperexponential(DE.fa, DE.fd, DE) == (Piecewise( ((exp(2*log(x)*y)*log(x) + 2*exp(log(x)*y)*log(x))/(2*log(x)**2), Ne(2*log(x)**2, 0)), (2*y, True), ), z, True)
def test_integrate_hyperexponential(): # TODO: Add tests for integrate_hyperexponential() from the book a = Poly( (1 + 2 * t1 + t1**2 + 2 * t1**3) * t**2 + (1 + t1**2) * t + 1 + t1**2, t) d = Poly(1, t) DE = DifferentialExtension( extension={ 'D': [Poly(1, x), Poly(1 + t1**2, t1), Poly(t * (1 + t1**2), t)], 'Tfuncs': [tan, Lambda(i, exp(tan(i)))] }) assert integrate_hyperexponential(a, d, DE) == \ (exp(2*tan(x))*tan(x) + exp(tan(x)), 1 + t1**2, True) # exp(2*tan(x))*tan(x) + tan(x) + exp(tan(x)) a = Poly((t1**3 + (x + 1) * t1**2 + t1 + x + 2) * t, t) assert integrate_hyperexponential(a, d, DE) == \ ((x + tan(x))*exp(tan(x)), 0, True) a = Poly(t, t) d = Poly(1, t) DE = DifferentialExtension(extension={ 'D': [Poly(1, x), Poly(2 * x * t, t)], 'Tfuncs': [Lambda(i, exp(x**2))] }) assert integrate_hyperexponential(a, d, DE) == \ (0, NonElementaryIntegral(exp(x**2), x), False) DE = DifferentialExtension(extension={ 'D': [Poly(1, x), Poly(t, t)], 'Tfuncs': [exp] }) assert integrate_hyperexponential(a, d, DE) == (exp(x), 0, True) a = Poly( 25 * t**6 - 10 * t**5 + 7 * t**4 - 8 * t**3 + 13 * t**2 + 2 * t - 1, t) d = Poly(25 * t**6 + 35 * t**4 + 11 * t**2 + 1, t) assert integrate_hyperexponential(a, d, DE) == \ (-(11 - 10*exp(x))/(5 + 25*exp(2*x)) + log(1 + exp(2*x)), -1, True) # -(55 - 50*exp(x))/(25 + 125*exp(2*x)) - x + log(1 + exp(2*x)) DE = DifferentialExtension( extension={ 'D': [Poly(1, x), Poly(t0, t0), Poly(t0 * t, t)], 'Tfuncs': [exp, Lambda(i, exp(exp(i)))] }) assert integrate_hyperexponential(Poly(2 * t0 * t**2, t), Poly(1, t), DE) == (exp(2 * exp(x)), 0, True) DE = DifferentialExtension( extension={ 'D': [Poly(1, x), Poly(t0, t0), Poly(-t0 * t, t)], 'Tfuncs': [exp, Lambda(i, exp(-exp(i)))] }) assert integrate_hyperexponential(Poly(-27*exp(9) - 162*t0*exp(9) + 27*x*t0*exp(9), t), Poly((36*exp(18) + x**2*exp(18) - 12*x*exp(18))*t, t), DE) == \ (27*exp(exp(x))/(-6*exp(9) + x*exp(9)), 0, True) DE = DifferentialExtension(extension={ 'D': [Poly(1, x), Poly(t, t)], 'Tfuncs': [exp] }) assert integrate_hyperexponential(Poly(x**2/2*t, t), Poly(1, t), DE) == \ ((2 - 2*x + x**2)*exp(x)/2, 0, True) assert integrate_hyperexponential(Poly(1 + t, t), Poly(t, t), DE) == \ (-exp(-x), 1, True) # x - exp(-x) assert integrate_hyperexponential(Poly(x, t), Poly(t + 1, t), DE) == \ (0, NonElementaryIntegral(x/(1 + exp(x)), x), False) DE = DifferentialExtension( extension={ 'D': [Poly(1, x), Poly(1 / x, t0), Poly(2 * x * t1, t1)], 'Tfuncs': [log, Lambda(i, exp(i**2))] }) elem, nonelem, b = integrate_hyperexponential( Poly( (8 * x**7 - 12 * x**5 + 6 * x**3 - x) * t1**4 + (8 * t0 * x**7 - 8 * t0 * x**6 - 4 * t0 * x**5 + 2 * t0 * x**3 + 2 * t0 * x**2 - t0 * x + 24 * x**8 - 36 * x**6 - 4 * x**5 + 22 * x**4 + 4 * x**3 - 7 * x**2 - x + 1) * t1**3 + (8 * t0 * x**8 - 4 * t0 * x**6 - 16 * t0 * x**5 - 2 * t0 * x**4 + 12 * t0 * x**3 + t0 * x**2 - 2 * t0 * x + 24 * x**9 - 36 * x**7 - 8 * x**6 + 22 * x**5 + 12 * x**4 - 7 * x**3 - 6 * x**2 + x + 1) * t1**2 + (8 * t0 * x**8 - 8 * t0 * x**6 - 16 * t0 * x**5 + 6 * t0 * x**4 + 10 * t0 * x**3 - 2 * t0 * x**2 - t0 * x + 8 * x**10 - 12 * x**8 - 4 * x**7 + 2 * x**6 + 12 * x**5 + 3 * x**4 - 9 * x**3 - x**2 + 2 * x) * t1 + 8 * t0 * x**7 - 12 * t0 * x**6 - 4 * t0 * x**5 + 8 * t0 * x**4 - t0 * x**2 - 4 * x**7 + 4 * x**6 + 4 * x**5 - 4 * x**4 - x**3 + x**2, t1), Poly((8 * x**7 - 12 * x**5 + 6 * x**3 - x) * t1**4 + (24 * x**8 + 8 * x**7 - 36 * x**6 - 12 * x**5 + 18 * x**4 + 6 * x**3 - 3 * x**2 - x) * t1**3 + (24 * x**9 + 24 * x**8 - 36 * x**7 - 36 * x**6 + 18 * x**5 + 18 * x**4 - 3 * x**3 - 3 * x**2) * t1**2 + (8 * x**10 + 24 * x**9 - 12 * x**8 - 36 * x**7 + 6 * x**6 + 18 * x**5 - x**4 - 3 * x**3) * t1 + 8 * x**10 - 12 * x**8 + 6 * x**6 - x**4, t1), DE) assert factor(elem) == -((x - 1) * log(x) / ((x + exp(x**2)) * (2 * x**2 - 1))) assert (nonelem, b) == (NonElementaryIntegral(exp(x**2) / (exp(x**2) + 1), x), False)
def test_integrate_hyperexponential(): # TODO: Add tests for integrate_hyperexponential() from the book a = Poly((1 + 2*t1 + t1**2 + 2*t1**3)*t**2 + (1 + t1**2)*t + 1 + t1**2, t) d = Poly(1, t) DE = DifferentialExtension(extension={'D': [Poly(1, x), Poly(1 + t1**2, t1), Poly(t*(1 + t1**2), t)], 'Tfuncs': [tan, Lambda(i, exp(tan(i)))]}) assert integrate_hyperexponential(a, d, DE) == \ (exp(2*tan(x))*tan(x) + exp(tan(x)), 1 + t1**2, True) a = Poly((t1**3 + (x + 1)*t1**2 + t1 + x + 2)*t, t) assert integrate_hyperexponential(a, d, DE) == \ ((x + tan(x))*exp(tan(x)), 0, True) a = Poly(t, t) d = Poly(1, t) DE = DifferentialExtension(extension={'D': [Poly(1, x), Poly(2*x*t, t)], 'Tfuncs': [Lambda(i, exp(x**2))]}) assert integrate_hyperexponential(a, d, DE) == \ (0, NonElementaryIntegral(exp(x**2), x), False) DE = DifferentialExtension(extension={'D': [Poly(1, x), Poly(t, t)], 'Tfuncs': [exp]}) assert integrate_hyperexponential(a, d, DE) == (exp(x), 0, True) a = Poly(25*t**6 - 10*t**5 + 7*t**4 - 8*t**3 + 13*t**2 + 2*t - 1, t) d = Poly(25*t**6 + 35*t**4 + 11*t**2 + 1, t) assert integrate_hyperexponential(a, d, DE) == \ (-(11 - 10*exp(x))/(5 + 25*exp(2*x)) + log(1 + exp(2*x)), -1, True) DE = DifferentialExtension(extension={'D': [Poly(1, x), Poly(t0, t0), Poly(t0*t, t)], 'Tfuncs': [exp, Lambda(i, exp(exp(i)))]}) assert integrate_hyperexponential(Poly(2*t0*t**2, t), Poly(1, t), DE) == (exp(2*exp(x)), 0, True) DE = DifferentialExtension(extension={'D': [Poly(1, x), Poly(t0, t0), Poly(-t0*t, t)], 'Tfuncs': [exp, Lambda(i, exp(-exp(i)))]}) assert integrate_hyperexponential(Poly(-27*exp(9) - 162*t0*exp(9) + 27*x*t0*exp(9), t), Poly((36*exp(18) + x**2*exp(18) - 12*x*exp(18))*t, t), DE) == \ (27*exp(exp(x))/(-6*exp(9) + x*exp(9)), 0, True) DE = DifferentialExtension(extension={'D': [Poly(1, x), Poly(t, t)], 'Tfuncs': [exp]}) assert integrate_hyperexponential(Poly(x**2/2*t, t), Poly(1, t), DE) == \ ((2 - 2*x + x**2)*exp(x)/2, 0, True) assert integrate_hyperexponential(Poly(1 + t, t), Poly(t, t), DE) == \ (-exp(-x), 1, True) # x - exp(-x) assert integrate_hyperexponential(Poly(x, t), Poly(t + 1, t), DE) == \ (0, NonElementaryIntegral(x/(1 + exp(x)), x), False) DE = DifferentialExtension(extension={'D': [Poly(1, x), Poly(1/x, t0), Poly(2*x*t1, t1)], 'Tfuncs': [log, Lambda(i, exp(i**2))]}) elem, nonelem, b = integrate_hyperexponential(Poly((8*x**7 - 12*x**5 + 6*x**3 - x)*t1**4 + (8*t0*x**7 - 8*t0*x**6 - 4*t0*x**5 + 2*t0*x**3 + 2*t0*x**2 - t0*x + 24*x**8 - 36*x**6 - 4*x**5 + 22*x**4 + 4*x**3 - 7*x**2 - x + 1)*t1**3 + (8*t0*x**8 - 4*t0*x**6 - 16*t0*x**5 - 2*t0*x**4 + 12*t0*x**3 + t0*x**2 - 2*t0*x + 24*x**9 - 36*x**7 - 8*x**6 + 22*x**5 + 12*x**4 - 7*x**3 - 6*x**2 + x + 1)*t1**2 + (8*t0*x**8 - 8*t0*x**6 - 16*t0*x**5 + 6*t0*x**4 + 10*t0*x**3 - 2*t0*x**2 - t0*x + 8*x**10 - 12*x**8 - 4*x**7 + 2*x**6 + 12*x**5 + 3*x**4 - 9*x**3 - x**2 + 2*x)*t1 + 8*t0*x**7 - 12*t0*x**6 - 4*t0*x**5 + 8*t0*x**4 - t0*x**2 - 4*x**7 + 4*x**6 + 4*x**5 - 4*x**4 - x**3 + x**2, t1), Poly((8*x**7 - 12*x**5 + 6*x**3 - x)*t1**4 + (24*x**8 + 8*x**7 - 36*x**6 - 12*x**5 + 18*x**4 + 6*x**3 - 3*x**2 - x)*t1**3 + (24*x**9 + 24*x**8 - 36*x**7 - 36*x**6 + 18*x**5 + 18*x**4 - 3*x**3 - 3*x**2)*t1**2 + (8*x**10 + 24*x**9 - 12*x**8 - 36*x**7 + 6*x**6 + 18*x**5 - x**4 - 3*x**3)*t1 + 8*x**10 - 12*x**8 + 6*x**6 - x**4, t1), DE) assert factor(elem) == -((x - 1)*log(x)/((x + exp(x**2))*(2*x**2 - 1))) assert (nonelem, b) == (NonElementaryIntegral(exp(x**2)/(exp(x**2) + 1), x), False)