text:
@testset "1.1.1.6 P(x) (a+b x)^m (c+d x)^n (e+f x)^p" begin
    (A, B, C, a, b, c, d, e, f, x, ) = @variables A B C a b c d e f x

    #= ::Package:: =#

    #= ::Title:: =#
    #=Integrands*of*the*form*P(x)*(a+b*x)^m*(c+d*x)^n*(e+f*x)^p=#

    #= ::Section::Closed:: =#
    #=Integrands*of*the*form*(a+b*x)^m*(c+d*x)^n*(e+f*x)^p*(A+B*x+C*x^2)*when*b*c+a*d=0*and*m=n=#

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*(a+b*x)^(m/2)*(c+d*x)^(n/2)*(e+f*x)^p*(A+B*x+C*x^2)*when*b*c+a*d=0, m=n, a>0*and*c>0=#

    #= ::Subsubsection::Closed:: =#
    #=m>0=#

    @test_int [(e + f*x)^3*(A + B*x + C*x^2)*sqrt(1 + d*x)*sqrt(1 - d*x), x, 7, ((2*C*d^2*e^3 + 8*A*d^4*e^3 + 6*B*d^2*e^2*f + 3*C*e*f^2 + 6*A*d^2*e*f^2 + B*f^3)*x*sqrt(1 - d^2*x^2))/(16*d^4) - ((7*d^2*f*(B*e + 2*A*f) - C*(3*d^2*e^2 - 8*f^2))*(e + f*x)^2*(1 - d^2*x^2)^(3/2))/(70*d^4*f) + ((3*C*e - 7*B*f)*(e + f*x)^3*(1 - d^2*x^2)^(3/2))/(42*d^2*f) - (C*(e + f*x)^4*(1 - d^2*x^2)^(3/2))/(7*d^2*f) + ((8*(C*(3*d^4*e^4 - 30*d^2*e^2*f^2 - 8*f^4) - 7*d^2*f*(2*A*f*(6*d^2*e^2 + f^2) + B*(d^2*e^3 + 6*e*f^2))) + 3*d^2*f*(6*C*d^2*e^3 - 14*B*d^2*e^2*f - 41*C*e*f^2 - 98*A*d^2*e*f^2 - 35*B*f^3)*x)*(1 - d^2*x^2)^(3/2))/(840*d^6*f) + ((2*C*d^2*e^3 + 8*A*d^4*e^3 + 6*B*d^2*e^2*f + 3*C*e*f^2 + 6*A*d^2*e*f^2 + B*f^3)*asin(d*x))/(16*d^5)]
    @test_int [(e + f*x)^2*(A + B*x + C*x^2)*sqrt(1 + d*x)*sqrt(1 - d*x), x, 6, ((C*(2*d^2*e^2 + f^2) + 2*d^2*(2*B*e*f + A*(4*d^2*e^2 + f^2)))*x*sqrt(1 - d^2*x^2))/(16*d^4) + ((C*e - 2*B*f)*(e + f*x)^2*(1 - d^2*x^2)^(3/2))/(10*d^2*f) - (C*(e + f*x)^3*(1 - d^2*x^2)^(3/2))/(6*d^2*f) + ((8*(C*(d^2*e^3 - 4*e*f^2) - 2*f*(5*A*d^2*e*f + B*(d^2*e^2 + f^2))) - 3*f*(5*(C + 2*A*d^2)*f^2 - 2*d^2*e*(C*e - 2*B*f))*x)*(1 - d^2*x^2)^(3/2))/(120*d^4*f) + ((C*(2*d^2*e^2 + f^2) + 2*d^2*(2*B*e*f + A*(4*d^2*e^2 + f^2)))*asin(d*x))/(16*d^5)]
    @test_int [(e + f*x)^1*(A + B*x + C*x^2)*sqrt(1 + d*x)*sqrt(1 - d*x), x, 5, ((C*e + 4*A*d^2*e + B*f)*x*sqrt(1 - d^2*x^2))/(8*d^2) - (C*(e + f*x)^2*(1 - d^2*x^2)^(3/2))/(5*d^2*f) - ((4*(5*d^2*f*(B*e + A*f) - C*(3*d^2*e^2 - 2*f^2)) - 3*d^2*f*(3*C*e - 5*B*f)*x)*(1 - d^2*x^2)^(3/2))/(60*d^4*f) + ((C*e + 4*A*d^2*e + B*f)*asin(d*x))/(8*d^3)]
    @test_int [(e + f*x)^0*(A + B*x + C*x^2)*sqrt(1 + d*x)*sqrt(1 - d*x), x, 5, ((C + 4*A*d^2)*x*sqrt(1 - d^2*x^2))/(8*d^2) - (B*(1 - d^2*x^2)^(3/2))/(3*d^2) - (C*x*(1 - d^2*x^2)^(3/2))/(4*d^2) + ((C + 4*A*d^2)*asin(d*x))/(8*d^3)]
    @test_int [(A + B*x + C*x^2)/(sqrt(1 + d*x)*sqrt(1 - d*x)*(e + f*x)^1), x, 6, -((C*sqrt(1 - d^2*x^2))/(d^2*f)) - ((C*e - B*f)*asin(d*x))/(d*f^2) + ((C*e^2 - B*e*f + A*f^2)*atan((f + d^2*e*x)/(sqrt(d^2*e^2 - f^2)*sqrt(1 - d^2*x^2))))/(f^2*sqrt(d^2*e^2 - f^2))]
    @test_int [(A + B*x + C*x^2)/(sqrt(1 + d*x)*sqrt(1 - d*x)*(e + f*x)^2), x, 6, ((C*e^2 - B*e*f + A*f^2)*sqrt(1 - d^2*x^2))/(f*(d^2*e^2 - f^2)*(e + f*x)) + (C*asin(d*x))/(d*f^2) - ((C*d^2*e^3 - 2*C*e*f^2 - A*d^2*e*f^2 + B*f^3)*atan((f + d^2*e*x)/(sqrt(d^2*e^2 - f^2)*sqrt(1 - d^2*x^2))))/(f^2*(d^2*e^2 - f^2)^(3/2))]
    @test_int [(A + B*x + C*x^2)/(sqrt(1 + d*x)*sqrt(1 - d*x)*(e + f*x)^3), x, 5, ((C*e^2 - B*e*f + A*f^2)*sqrt(1 - d^2*x^2))/(2*f*(d^2*e^2 - f^2)*(e + f*x)^2) - ((C*d^2*e^3 + B*d^2*e^2*f - 4*C*e*f^2 - 3*A*d^2*e*f^2 + 2*B*f^3)*sqrt(1 - d^2*x^2))/(2*f*(d^2*e^2 - f^2)^2*(e + f*x)) + ((C*(d^2*e^2 + 2*f^2) - d^2*(3*B*e*f - A*(2*d^2*e^2 + f^2)))*atan((f + d^2*e*x)/(sqrt(d^2*e^2 - f^2)*sqrt(1 - d^2*x^2))))/(2*(d^2*e^2 - f^2)^(5/2))]

    #= ::Subsubsection::Closed:: =#
    #=m<0=#

    @test_int [(e + f*x)^3*(A + B*x + C*x^2)/(sqrt(1 + d*x)*sqrt(1 - d*x)), x, 6, -(((4*(4*C + 5*A*d^2)*f^2 - 3*d^2*e*(C*e - 5*B*f))*(e + f*x)^2*sqrt(1 - d^2*x^2))/(60*d^4*f)) + ((C*e - 5*B*f)*(e + f*x)^3*sqrt(1 - d^2*x^2))/(20*d^2*f) - (C*(e + f*x)^4*sqrt(1 - d^2*x^2))/(5*d^2*f) + ((4*(C*(3*d^4*e^4 - 52*d^2*e^2*f^2 - 16*f^4) - 5*d^2*f*(4*A*f*(4*d^2*e^2 + f^2) + 3*B*(d^2*e^3 + 4*e*f^2))) + d^2*f*(6*C*d^2*e^3 - 30*B*d^2*e^2*f - 71*C*e*f^2 - 100*A*d^2*e*f^2 - 45*B*f^3)*x)*sqrt(1 - d^2*x^2))/(120*d^6*f) + ((4*C*d^2*e^3 + 8*A*d^4*e^3 + 12*B*d^2*e^2*f + 9*C*e*f^2 + 12*A*d^2*e*f^2 + 3*B*f^3)*asin(d*x))/(8*d^5)]
    @test_int [(e + f*x)^2*(A + B*x + C*x^2)/(sqrt(1 + d*x)*sqrt(1 - d*x)), x, 5, ((C*e - 4*B*f)*(e + f*x)^2*sqrt(1 - d^2*x^2))/(12*d^2*f) - (C*(e + f*x)^3*sqrt(1 - d^2*x^2))/(4*d^2*f) + ((4*(C*(d^2*e^3 - 8*e*f^2) - 4*f*(3*A*d^2*e*f + B*(d^2*e^2 + f^2))) - f*(3*(3*C + 4*A*d^2)*f^2 - 2*d^2*e*(C*e - 4*B*f))*x)*sqrt(1 - d^2*x^2))/(24*d^4*f) + ((C*(4*d^2*e^2 + 3*f^2) + 4*d^2*(2*B*e*f + A*(2*d^2*e^2 + f^2)))*asin(d*x))/(8*d^5)]
    @test_int [(e + f*x)^1*(A + B*x + C*x^2)/(sqrt(1 + d*x)*sqrt(1 - d*x)), x, 4, -((C*(e + f*x)^2*sqrt(1 - d^2*x^2))/(3*d^2*f)) - ((2*(3*d^2*f*(B*e + A*f) - C*(d^2*e^2 - 2*f^2)) - d^2*f*(C*e - 3*B*f)*x)*sqrt(1 - d^2*x^2))/(6*d^4*f) + ((C*e + 2*A*d^2*e + B*f)*asin(d*x))/(2*d^3)]
    @test_int [(e + f*x)^0*(A + B*x + C*x^2)/(sqrt(1 + d*x)*sqrt(1 - d*x)), x, 4, -((B*sqrt(1 - d^2*x^2))/d^2) - (C*x*sqrt(1 - d^2*x^2))/(2*d^2) + ((C + 2*A*d^2)*asin(d*x))/(2*d^3)]
    @test_int [(A + B*x + C*x^2)/(sqrt(1 + d*x)*sqrt(1 - d*x)*(e + f*x)^1), x, 6, -((C*sqrt(1 - d^2*x^2))/(d^2*f)) - ((C*e - B*f)*asin(d*x))/(d*f^2) + ((C*e^2 - B*e*f + A*f^2)*atan((f + d^2*e*x)/(sqrt(d^2*e^2 - f^2)*sqrt(1 - d^2*x^2))))/(f^2*sqrt(d^2*e^2 - f^2))]
    @test_int [(A + B*x + C*x^2)/(sqrt(1 + d*x)*sqrt(1 - d*x)*(e + f*x)^2), x, 6, ((C*e^2 - B*e*f + A*f^2)*sqrt(1 - d^2*x^2))/(f*(d^2*e^2 - f^2)*(e + f*x)) + (C*asin(d*x))/(d*f^2) - ((C*d^2*e^3 - 2*C*e*f^2 - A*d^2*e*f^2 + B*f^3)*atan((f + d^2*e*x)/(sqrt(d^2*e^2 - f^2)*sqrt(1 - d^2*x^2))))/(f^2*(d^2*e^2 - f^2)^(3/2))]
    @test_int [(A + B*x + C*x^2)/(sqrt(1 + d*x)*sqrt(1 - d*x)*(e + f*x)^3), x, 5, ((C*e^2 - B*e*f + A*f^2)*sqrt(1 - d^2*x^2))/(2*f*(d^2*e^2 - f^2)*(e + f*x)^2) - ((C*d^2*e^3 + B*d^2*e^2*f - 4*C*e*f^2 - 3*A*d^2*e*f^2 + 2*B*f^3)*sqrt(1 - d^2*x^2))/(2*f*(d^2*e^2 - f^2)^2*(e + f*x)) + ((C*(d^2*e^2 + 2*f^2) - d^2*(3*B*e*f - A*(2*d^2*e^2 + f^2)))*atan((f + d^2*e*x)/(sqrt(d^2*e^2 - f^2)*sqrt(1 - d^2*x^2))))/(2*(d^2*e^2 - f^2)^(5/2))]

    @test_int [x^1*(a + b*x + c*x^2)/(sqrt(1 + d*x)*sqrt(1 - d*x)), x, 4, -((c*x^2*sqrt(1 - d^2*x^2))/(3*d^2)) - ((2*(2*c + 3*a*d^2) + 3*b*d^2*x)*sqrt(1 - d^2*x^2))/(6*d^4) + (b*asin(d*x))/(2*d^3)]
    @test_int [x^0*(a + b*x + c*x^2)/(sqrt(1 + d*x)*sqrt(1 - d*x)), x, 4, -((b*sqrt(1 - d^2*x^2))/d^2) - (c*x*sqrt(1 - d^2*x^2))/(2*d^2) + ((c + 2*a*d^2)*asin(d*x))/(2*d^3)]
    @test_int [(a + b*x + c*x^2)/(x^1*sqrt(1 + d*x)*sqrt(1 - d*x)), x, 7, -((c*sqrt(1 - d^2*x^2))/d^2) + (b*asin(d*x))/d - a*atanh(sqrt(1 - d^2*x^2))]
    @test_int [(a + b*x + c*x^2)/(x^2*sqrt(1 + d*x)*sqrt(1 - d*x)), x, 7, -((a*sqrt(1 - d^2*x^2))/x) + (c*asin(d*x))/d - b*atanh(sqrt(1 - d^2*x^2))]
    @test_int [(a + b*x + c*x^2)/(x^3*sqrt(1 + d*x)*sqrt(1 - d*x)), x, 6, -((a*sqrt(1 - d^2*x^2))/(2*x^2)) - (b*sqrt(1 - d^2*x^2))/x - (1/2)*(2*c + a*d^2)*atanh(sqrt(1 - d^2*x^2))]

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*(a+b*x)^(m/2)*(c+d*x)^(n/2)*(e+f*x)^p*(A+B*x+C*x^2)*when*b*c+a*d=0*and*m=n=#

    #= ::Subsubsection::Closed:: =#
    #=m>0=#

    @test_int [(e + f*x)^3*(A + B*x + C*x^2)*sqrt(a + b*x)*sqrt(a*c - b*c*x), x, 8, ((A*(8*b^4*e^3 + 6*a^2*b^2*e*f^2) + a^2*(a^2*f^2*(3*C*e + B*f) + 2*b^2*e^2*(C*e + 3*B*f)))*x*sqrt(a + b*x)*sqrt(a*c - b*c*x))/(16*b^4) - ((8*a^2*C*f^2 - b^2*(3*C*e^2 - 7*f*(B*e + 2*A*f)))*sqrt(a + b*x)*sqrt(a*c - b*c*x)*(e + f*x)^2*(a^2 - b^2*x^2))/(70*b^4*f) + ((3*C*e - 7*B*f)*sqrt(a + b*x)*sqrt(a*c - b*c*x)*(e + f*x)^3*(a^2 - b^2*x^2))/(42*b^2*f) - (C*sqrt(a + b*x)*sqrt(a*c - b*c*x)*(e + f*x)^4*(a^2 - b^2*x^2))/(7*b^2*f) - (sqrt(a + b*x)*sqrt(a*c - b*c*x)*(8*(8*a^4*C*f^4 + 2*a^2*b^2*f^2*(15*C*e^2 + 7*f*(3*B*e + A*f)) - b^4*e^2*(3*C*e^2 - 7*f*(B*e + 12*A*f))) + 3*b^2*f*(a^2*f^2*(41*C*e + 35*B*f) - 2*b^2*e*(3*C*e^2 - 7*f*(B*e + 7*A*f)))*x)*(a^2 - b^2*x^2))/(840*b^6*f) + (a^2*sqrt(c)*(A*(8*b^4*e^3 + 6*a^2*b^2*e*f^2) + a^2*(a^2*f^2*(3*C*e + B*f) + 2*b^2*e^2*(C*e + 3*B*f)))*sqrt(a + b*x)*sqrt(a*c - b*c*x)*atan((b*sqrt(c)*x)/sqrt(a^2*c - b^2*c*x^2)))/(16*b^5*sqrt(a^2*c - b^2*c*x^2))]
    @test_int [(e + f*x)^2*(A + B*x + C*x^2)*sqrt(a + b*x)*sqrt(a*c - b*c*x), x, 7, ((2*A*(4*b^4*e^2 + a^2*b^2*f^2) + a^2*(a^2*C*f^2 + 2*b^2*e*(C*e + 2*B*f)))*x*sqrt(a + b*x)*sqrt(a*c - b*c*x))/(16*b^4) + ((C*e - 2*B*f)*sqrt(a + b*x)*sqrt(a*c - b*c*x)*(e + f*x)^2*(a^2 - b^2*x^2))/(10*b^2*f) - (C*sqrt(a + b*x)*sqrt(a*c - b*c*x)*(e + f*x)^3*(a^2 - b^2*x^2))/(6*b^2*f) - (sqrt(a + b*x)*sqrt(a*c - b*c*x)*(8*(2*a^2*f^2*(2*C*e + B*f) - b^2*e*(C*e^2 - 2*f*(B*e + 5*A*f))) + 3*f*(5*a^2*C*f^2 - b^2*(2*C*e^2 - 2*f*(2*B*e + 5*A*f)))*x)*(a^2 - b^2*x^2))/(120*b^4*f) + (a^2*sqrt(c)*(2*A*(4*b^4*e^2 + a^2*b^2*f^2) + a^2*(a^2*C*f^2 + 2*b^2*e*(C*e + 2*B*f)))*sqrt(a + b*x)*sqrt(a*c - b*c*x)*atan((b*sqrt(c)*x)/sqrt(a^2*c - b^2*c*x^2)))/(16*b^5*sqrt(a^2*c - b^2*c*x^2))]
    @test_int [(e + f*x)^1*(A + B*x + C*x^2)*sqrt(a + b*x)*sqrt(a*c - b*c*x), x, 6, ((4*A*b^2*e + a^2*(C*e + B*f))*x*sqrt(a + b*x)*sqrt(a*c - b*c*x))/(8*b^2) - (C*sqrt(a + b*x)*sqrt(a*c - b*c*x)*(e + f*x)^2*(a^2 - b^2*x^2))/(5*b^2*f) - (sqrt(a + b*x)*sqrt(a*c - b*c*x)*(4*(2*a^2*C*f^2 - b^2*(3*C*e^2 - 5*f*(B*e + A*f))) - 3*b^2*f*(3*C*e - 5*B*f)*x)*(a^2 - b^2*x^2))/(60*b^4*f) + (a^2*sqrt(c)*(4*A*b^2*e + a^2*(C*e + B*f))*sqrt(a + b*x)*sqrt(a*c - b*c*x)*atan((b*sqrt(c)*x)/sqrt(a^2*c - b^2*c*x^2)))/(8*b^3*sqrt(a^2*c - b^2*c*x^2))]
    @test_int [(e + f*x)^0*(A + B*x + C*x^2)*sqrt(a + b*x)*sqrt(a*c - b*c*x), x, 6, (1/8)*(4*A + (a^2*C)/b^2)*x*sqrt(a + b*x)*sqrt(a*c - b*c*x) - (B*sqrt(a + b*x)*sqrt(a*c - b*c*x)*(a^2 - b^2*x^2))/(3*b^2) - (C*x*sqrt(a + b*x)*sqrt(a*c - b*c*x)*(a^2 - b^2*x^2))/(4*b^2) + (a^2*sqrt(c)*(4*A*b^2 + a^2*C)*sqrt(a + b*x)*sqrt(a*c - b*c*x)*atan((b*sqrt(c)*x)/sqrt(a^2*c - b^2*c*x^2)))/(8*b^3*sqrt(a^2*c - b^2*c*x^2))]
    @test_int [(A + B*x + C*x^2)/(sqrt(a + b*x)*sqrt(a*c - b*c*x)*(e + f*x)^1), x, 7, -((C*(a^2 - b^2*x^2))/(b^2*f*sqrt(a + b*x)*sqrt(a*c - b*c*x))) - ((C*e - B*f)*sqrt(a^2*c - b^2*c*x^2)*atan((b*sqrt(c)*x)/sqrt(a^2*c - b^2*c*x^2)))/(b*sqrt(c)*f^2*sqrt(a + b*x)*sqrt(a*c - b*c*x)) + ((C*e^2 - B*e*f + A*f^2)*sqrt(a^2*c - b^2*c*x^2)*atan((sqrt(c)*(a^2*f + b^2*e*x))/(sqrt(b^2*e^2 - a^2*f^2)*sqrt(a^2*c - b^2*c*x^2))))/(sqrt(c)*f^2*sqrt(b^2*e^2 - a^2*f^2)*sqrt(a + b*x)*sqrt(a*c - b*c*x))]
    @test_int [(A + B*x + C*x^2)/(sqrt(a + b*x)*sqrt(a*c - b*c*x)*(e + f*x)^2), x, 7, (f*(A + (e*(C*e - B*f))/f^2)*(a^2 - b^2*x^2))/((b^2*e^2 - a^2*f^2)*sqrt(a + b*x)*sqrt(a*c - b*c*x)*(e + f*x)) + (C*sqrt(a^2*c - b^2*c*x^2)*atan((b*sqrt(c)*x)/sqrt(a^2*c - b^2*c*x^2)))/(b*sqrt(c)*f^2*sqrt(a + b*x)*sqrt(a*c - b*c*x)) + ((a^2*f^2*(2*C*e - B*f) - b^2*(C*e^3 - A*e*f^2))*sqrt(a^2*c - b^2*c*x^2)*atan((sqrt(c)*(a^2*f + b^2*e*x))/(sqrt(b^2*e^2 - a^2*f^2)*sqrt(a^2*c - b^2*c*x^2))))/(sqrt(c)*f^2*(b^2*e^2 - a^2*f^2)^(3/2)*sqrt(a + b*x)*sqrt(a*c - b*c*x))]
    @test_int [(A + B*x + C*x^2)/(sqrt(a + b*x)*sqrt(a*c - b*c*x)*(e + f*x)^3), x, 5, (f*(A + (e*(C*e - B*f))/f^2)*(a^2 - b^2*x^2))/(2*(b^2*e^2 - a^2*f^2)*sqrt(a + b*x)*sqrt(a*c - b*c*x)*(e + f*x)^2) + ((2*a^2*f^2*(2*C*e - B*f) - b^2*e*(C*e^2 + f*(B*e - 3*A*f)))*(a^2 - b^2*x^2))/(2*f*(b^2*e^2 - a^2*f^2)^2*sqrt(a + b*x)*sqrt(a*c - b*c*x)*(e + f*x)) + ((A*(2*b^4*e^2 + a^2*b^2*f^2) + a^2*(2*a^2*C*f^2 + b^2*e*(C*e - 3*B*f)))*sqrt(a^2*c - b^2*c*x^2)*atan((sqrt(c)*(a^2*f + b^2*e*x))/(sqrt(b^2*e^2 - a^2*f^2)*sqrt(a^2*c - b^2*c*x^2))))/(2*sqrt(c)*(b^2*e^2 - a^2*f^2)^(5/2)*sqrt(a + b*x)*sqrt(a*c - b*c*x))]

    #= ::Subsubsection::Closed:: =#
    #=m<0=#

    @test_int [(e + f*x)^3*(A + B*x + C*x^2)/(sqrt(a + b*x)*sqrt(a*c - b*c*x)), x, 7, -(((16*a^2*C*f^2 - b^2*(3*C*e^2 - 5*f*(3*B*e + 4*A*f)))*(e + f*x)^2*(a^2 - b^2*x^2))/(60*b^4*f*sqrt(a + b*x)*sqrt(a*c - b*c*x))) + ((C*e - 5*B*f)*(e + f*x)^3*(a^2 - b^2*x^2))/(20*b^2*f*sqrt(a + b*x)*sqrt(a*c - b*c*x)) - (C*(e + f*x)^4*(a^2 - b^2*x^2))/(5*b^2*f*sqrt(a + b*x)*sqrt(a*c - b*c*x)) - ((4*(16*a^4*C*f^4 + 4*a^2*b^2*f^2*(13*C*e^2 + 5*f*(3*B*e + A*f)) - b^4*e^2*(3*C*e^2 - 5*f*(3*B*e + 16*A*f))) + b^2*f*(a^2*f^2*(71*C*e + 45*B*f) - 2*b^2*e*(3*C*e^2 - 5*f*(3*B*e + 10*A*f)))*x)*(a^2 - b^2*x^2))/(120*b^6*f*sqrt(a + b*x)*sqrt(a*c - b*c*x)) + ((4*A*(2*b^4*e^3 + 3*a^2*b^2*e*f^2) + a^2*(3*a^2*f^2*(3*C*e + B*f) + 4*b^2*e^2*(C*e + 3*B*f)))*sqrt(a^2*c - b^2*c*x^2)*atan((b*sqrt(c)*x)/sqrt(a^2*c - b^2*c*x^2)))/(8*b^5*sqrt(c)*sqrt(a + b*x)*sqrt(a*c - b*c*x))]
    @test_int [(e + f*x)^2*(A + B*x + C*x^2)/(sqrt(a + b*x)*sqrt(a*c - b*c*x)), x, 6, ((C*e - 4*B*f)*(e + f*x)^2*(a^2 - b^2*x^2))/(12*b^2*f*sqrt(a + b*x)*sqrt(a*c - b*c*x)) - (C*(e + f*x)^3*(a^2 - b^2*x^2))/(4*b^2*f*sqrt(a + b*x)*sqrt(a*c - b*c*x)) - ((4*(4*a^2*f^2*(2*C*e + B*f) - b^2*e*(C*e^2 - 4*f*(B*e + 3*A*f))) + f*(9*a^2*C*f^2 - b^2*(2*C*e^2 - 4*f*(2*B*e + 3*A*f)))*x)*(a^2 - b^2*x^2))/(24*b^4*f*sqrt(a + b*x)*sqrt(a*c - b*c*x)) + ((4*A*(2*b^4*e^2 + a^2*b^2*f^2) + a^2*(3*a^2*C*f^2 + 4*b^2*e*(C*e + 2*B*f)))*sqrt(a^2*c - b^2*c*x^2)*atan((b*sqrt(c)*x)/sqrt(a^2*c - b^2*c*x^2)))/(8*b^5*sqrt(c)*sqrt(a + b*x)*sqrt(a*c - b*c*x))]
    @test_int [(e + f*x)^1*(A + B*x + C*x^2)/(sqrt(a + b*x)*sqrt(a*c - b*c*x)), x, 5, -((C*(e + f*x)^2*(a^2 - b^2*x^2))/(3*b^2*f*sqrt(a + b*x)*sqrt(a*c - b*c*x))) - ((2*(2*a^2*C*f^2 - b^2*(C*e^2 - 3*f*(B*e + A*f))) - b^2*f*(C*e - 3*B*f)*x)*(a^2 - b^2*x^2))/(6*b^4*f*sqrt(a + b*x)*sqrt(a*c - b*c*x)) + ((2*A*b^2*e + a^2*(C*e + B*f))*sqrt(a^2*c - b^2*c*x^2)*atan((b*sqrt(c)*x)/sqrt(a^2*c - b^2*c*x^2)))/(2*b^3*sqrt(c)*sqrt(a + b*x)*sqrt(a*c - b*c*x))]
    @test_int [(e + f*x)^0*(A + B*x + C*x^2)/(sqrt(a + b*x)*sqrt(a*c - b*c*x)), x, 5, -((B*(a^2 - b^2*x^2))/(b^2*sqrt(a + b*x)*sqrt(a*c - b*c*x))) - (C*x*(a^2 - b^2*x^2))/(2*b^2*sqrt(a + b*x)*sqrt(a*c - b*c*x)) + ((2*A*b^2 + a^2*C)*sqrt(a^2*c - b^2*c*x^2)*atan((b*sqrt(c)*x)/sqrt(a^2*c - b^2*c*x^2)))/(2*b^3*sqrt(c)*sqrt(a + b*x)*sqrt(a*c - b*c*x))]
    @test_int [(A + B*x + C*x^2)/(sqrt(a + b*x)*sqrt(a*c - b*c*x)*(e + f*x)^1), x, 7, -((C*(a^2 - b^2*x^2))/(b^2*f*sqrt(a + b*x)*sqrt(a*c - b*c*x))) - ((C*e - B*f)*sqrt(a^2*c - b^2*c*x^2)*atan((b*sqrt(c)*x)/sqrt(a^2*c - b^2*c*x^2)))/(b*sqrt(c)*f^2*sqrt(a + b*x)*sqrt(a*c - b*c*x)) + ((C*e^2 - B*e*f + A*f^2)*sqrt(a^2*c - b^2*c*x^2)*atan((sqrt(c)*(a^2*f + b^2*e*x))/(sqrt(b^2*e^2 - a^2*f^2)*sqrt(a^2*c - b^2*c*x^2))))/(sqrt(c)*f^2*sqrt(b^2*e^2 - a^2*f^2)*sqrt(a + b*x)*sqrt(a*c - b*c*x))]
    @test_int [(A + B*x + C*x^2)/(sqrt(a + b*x)*sqrt(a*c - b*c*x)*(e + f*x)^2), x, 7, (f*(A + (e*(C*e - B*f))/f^2)*(a^2 - b^2*x^2))/((b^2*e^2 - a^2*f^2)*sqrt(a + b*x)*sqrt(a*c - b*c*x)*(e + f*x)) + (C*sqrt(a^2*c - b^2*c*x^2)*atan((b*sqrt(c)*x)/sqrt(a^2*c - b^2*c*x^2)))/(b*sqrt(c)*f^2*sqrt(a + b*x)*sqrt(a*c - b*c*x)) + ((a^2*f^2*(2*C*e - B*f) - b^2*(C*e^3 - A*e*f^2))*sqrt(a^2*c - b^2*c*x^2)*atan((sqrt(c)*(a^2*f + b^2*e*x))/(sqrt(b^2*e^2 - a^2*f^2)*sqrt(a^2*c - b^2*c*x^2))))/(sqrt(c)*f^2*(b^2*e^2 - a^2*f^2)^(3/2)*sqrt(a + b*x)*sqrt(a*c - b*c*x))]
    @test_int [(A + B*x + C*x^2)/(sqrt(a + b*x)*sqrt(a*c - b*c*x)*(e + f*x)^3), x, 5, (f*(A + (e*(C*e - B*f))/f^2)*(a^2 - b^2*x^2))/(2*(b^2*e^2 - a^2*f^2)*sqrt(a + b*x)*sqrt(a*c - b*c*x)*(e + f*x)^2) + ((2*a^2*f^2*(2*C*e - B*f) - b^2*e*(C*e^2 + f*(B*e - 3*A*f)))*(a^2 - b^2*x^2))/(2*f*(b^2*e^2 - a^2*f^2)^2*sqrt(a + b*x)*sqrt(a*c - b*c*x)*(e + f*x)) + ((A*(2*b^4*e^2 + a^2*b^2*f^2) + a^2*(2*a^2*C*f^2 + b^2*e*(C*e - 3*B*f)))*sqrt(a^2*c - b^2*c*x^2)*atan((sqrt(c)*(a^2*f + b^2*e*x))/(sqrt(b^2*e^2 - a^2*f^2)*sqrt(a^2*c - b^2*c*x^2))))/(2*sqrt(c)*(b^2*e^2 - a^2*f^2)^(5/2)*sqrt(a + b*x)*sqrt(a*c - b*c*x))]

    @test_int [x^1*(a + b*x + c*x^2)/(sqrt(-1 + d*x)*sqrt(1 + d*x)), x, 5, (c*x^2*sqrt(-1 + d*x)*sqrt(1 + d*x))/(3*d^2) + (sqrt(-1 + d*x)*sqrt(1 + d*x)*(2*(2*c + 3*a*d^2) + 3*b*d^2*x))/(6*d^4) + (b*acosh(d*x))/(2*d^3), -((c*x^2*(1 - d^2*x^2))/(3*d^2*sqrt(-1 + d*x)*sqrt(1 + d*x))) - ((2*(2*c + 3*a*d^2) + 3*b*d^2*x)*(1 - d^2*x^2))/(6*d^4*sqrt(-1 + d*x)*sqrt(1 + d*x)) + (b*sqrt(-1 + d^2*x^2)*atanh((d*x)/sqrt(-1 + d^2*x^2)))/(2*d^3*sqrt(-1 + d*x)*sqrt(1 + d*x))]
    @test_int [x^0*(a + b*x + c*x^2)/(sqrt(-1 + d*x)*sqrt(1 + d*x)), x, 5, ((2*b + c*x)*sqrt(-1 + d*x)*sqrt(1 + d*x))/(2*d^2) + ((c + 2*a*d^2)*acosh(d*x))/(2*d^3), -((b*(1 - d^2*x^2))/(d^2*sqrt(-1 + d*x)*sqrt(1 + d*x))) - (c*x*(1 - d^2*x^2))/(2*d^2*sqrt(-1 + d*x)*sqrt(1 + d*x)) + ((c + 2*a*d^2)*sqrt(-1 + d^2*x^2)*atanh((d*x)/sqrt(-1 + d^2*x^2)))/(2*d^3*sqrt(-1 + d*x)*sqrt(1 + d*x))]
    @test_int [(a + b*x + c*x^2)/(x^1*sqrt(-1 + d*x)*sqrt(1 + d*x)), x, 8, (c*sqrt(-1 + d*x)*sqrt(1 + d*x))/d^2 + (b*acosh(d*x))/d + a*atan(sqrt(-1 + d*x)*sqrt(1 + d*x)), -((c*(1 - d^2*x^2))/(d^2*sqrt(-1 + d*x)*sqrt(1 + d*x))) + (a*sqrt(-1 + d^2*x^2)*atan(sqrt(-1 + d^2*x^2)))/(sqrt(-1 + d*x)*sqrt(1 + d*x)) + (b*sqrt(-1 + d^2*x^2)*atanh((d*x)/sqrt(-1 + d^2*x^2)))/(d*sqrt(-1 + d*x)*sqrt(1 + d*x))]
    @test_int [(a + b*x + c*x^2)/(x^2*sqrt(-1 + d*x)*sqrt(1 + d*x)), x, 8, (a*sqrt(-1 + d*x)*sqrt(1 + d*x))/x + (c*acosh(d*x))/d + b*atan(sqrt(-1 + d*x)*sqrt(1 + d*x)), -((a*(1 - d^2*x^2))/(x*sqrt(-1 + d*x)*sqrt(1 + d*x))) + (b*sqrt(-1 + d^2*x^2)*atan(sqrt(-1 + d^2*x^2)))/(sqrt(-1 + d*x)*sqrt(1 + d*x)) + (c*sqrt(-1 + d^2*x^2)*atanh((d*x)/sqrt(-1 + d^2*x^2)))/(d*sqrt(-1 + d*x)*sqrt(1 + d*x))]
    @test_int [(a + b*x + c*x^2)/(x^3*sqrt(-1 + d*x)*sqrt(1 + d*x)), x, 6, (a*sqrt(-1 + d*x)*sqrt(1 + d*x))/(2*x^2) + (b*sqrt(-1 + d*x)*sqrt(1 + d*x))/x + (1/2)*(2*c + a*d^2)*atan(sqrt(-1 + d*x)*sqrt(1 + d*x)), -((a*(1 - d^2*x^2))/(2*x^2*sqrt(-1 + d*x)*sqrt(1 + d*x))) - (b*(1 - d^2*x^2))/(x*sqrt(-1 + d*x)*sqrt(1 + d*x)) + ((2*c + a*d^2)*sqrt(-1 + d^2*x^2)*atan(sqrt(-1 + d^2*x^2)))/(2*sqrt(-1 + d*x)*sqrt(1 + d*x))]
    @test_int [(a + b*x + c*x^2)/(x^4*sqrt(-1 + d*x)*sqrt(1 + d*x)), x, 7, (a*sqrt(-1 + d*x)*sqrt(1 + d*x))/(3*x^3) + (b*sqrt(-1 + d*x)*sqrt(1 + d*x))/(2*x^2) + ((3*c + 2*a*d^2)*sqrt(-1 + d*x)*sqrt(1 + d*x))/(3*x) + (1/2)*b*d^2*atan(sqrt(-1 + d*x)*sqrt(1 + d*x)), -((a*(1 - d^2*x^2))/(3*x^3*sqrt(-1 + d*x)*sqrt(1 + d*x))) - (b*(1 - d^2*x^2))/(2*x^2*sqrt(-1 + d*x)*sqrt(1 + d*x)) - ((3*c + 2*a*d^2)*(1 - d^2*x^2))/(3*x*sqrt(-1 + d*x)*sqrt(1 + d*x)) + (b*d^2*sqrt(-1 + d^2*x^2)*atan(sqrt(-1 + d^2*x^2)))/(2*sqrt(-1 + d*x)*sqrt(1 + d*x))]

    @test_int [(a + b*x + c*x^2)/(sqrt(-1 + x)*sqrt(1 + x)*(d + e*x)^3), x, 5, -(((c*d^2 - b*d*e + a*e^2)*sqrt(-1 + x)*sqrt(1 + x))/(2*e*(d^2 - e^2)*(d + e*x)^2)) + ((c*d^3 + b*d^2*e - (3*a + 4*c)*d*e^2 + 2*b*e^3)*sqrt(-1 + x)*sqrt(1 + x))/(2*e*(d^2 - e^2)^2*(d + e*x)) + (((2*a + c)*d^2 - 3*b*d*e + (a + 2*c)*e^2)*atanh((sqrt(d + e)*sqrt(1 + x))/(sqrt(d - e)*sqrt(-1 + x))))/((d - e)^(5/2)*(d + e)^(5/2)), ((c*d^2 - b*d*e + a*e^2)*(1 - x^2))/(2*e*(d^2 - e^2)*sqrt(-1 + x)*sqrt(1 + x)*(d + e*x)^2) - ((c*(d^3 - 4*d*e^2) - e*(3*a*d*e - b*(d^2 + 2*e^2)))*(1 - x^2))/(2*e*(d^2 - e^2)^2*sqrt(-1 + x)*sqrt(1 + x)*(d + e*x)) - ((3*b*d*e - a*(2*d^2 + e^2) - c*(d^2 + 2*e^2))*sqrt(-1 + x^2)*atanh((e + d*x)/(sqrt(d^2 - e^2)*sqrt(-1 + x^2))))/(2*(d^2 - e^2)^(5/2)*sqrt(-1 + x)*sqrt(1 + x))]

    #= ::Section::Closed:: =#
    #=Integrands*of*the*form*(a+b*x)^m*(c+d*x)^n*(e+f*x)^p*(A+B*x+C*x^2)=#

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*(a+b*x)^m*(c+d*x)^(n/2)*(e+f*x)^(p/2)*(A+B*x+C*x^2)=#

    #= ::Subsubsection::Closed:: =#
    #=n>0 & p>0=#

    @test_int [(a + b*x)^2*sqrt(c + d*x)*sqrt(e + f*x)*(A + B*x + C*x^2), x, 8, (1/(512*d^5*f^5))*((d*e - c*f)*(8*a^2*d^2*f^2*(C*(5*d^2*e^2 + 6*c*d*e*f + 5*c^2*f^2) + 8*d*f*(2*A*d*f - B*(d*e + c*f))) - 8*a*b*d*f*(C*(7*d^3*e^3 + 9*c*d^2*e^2*f + 9*c^2*d*e*f^2 + 7*c^3*f^3) + 2*d*f*(8*A*d*f*(d*e + c*f) - B*(5*d^2*e^2 + 6*c*d*e*f + 5*c^2*f^2))) + b^2*(C*(21*d^4*e^4 + 28*c*d^3*e^3*f + 30*c^2*d^2*e^2*f^2 + 28*c^3*d*e*f^3 + 21*c^4*f^4) + 4*d*f*(2*A*d*f*(5*d^2*e^2 + 6*c*d*e*f + 5*c^2*f^2) - B*(7*d^3*e^3 + 9*c*d^2*e^2*f + 9*c^2*d*e*f^2 + 7*c^3*f^3))))*sqrt(c + d*x)*sqrt(e + f*x)) + (1/(256*d^5*f^4))*((8*a^2*d^2*f^2*(C*(5*d^2*e^2 + 6*c*d*e*f + 5*c^2*f^2) + 8*d*f*(2*A*d*f - B*(d*e + c*f))) - 8*a*b*d*f*(C*(7*d^3*e^3 + 9*c*d^2*e^2*f + 9*c^2*d*e*f^2 + 7*c^3*f^3) + 2*d*f*(8*A*d*f*(d*e + c*f) - B*(5*d^2*e^2 + 6*c*d*e*f + 5*c^2*f^2))) + b^2*(C*(21*d^4*e^4 + 28*c*d^3*e^3*f + 30*c^2*d^2*e^2*f^2 + 28*c^3*d*e*f^3 + 21*c^4*f^4) + 4*d*f*(2*A*d*f*(5*d^2*e^2 + 6*c*d*e*f + 5*c^2*f^2) - B*(7*d^3*e^3 + 9*c*d^2*e^2*f + 9*c^2*d*e*f^2 + 7*c^3*f^3))))*(c + d*x)^(3/2)*sqrt(e + f*x)) - ((2*a*C*d*f - b*(4*B*d*f - 3*C*(d*e + c*f)))*(a + b*x)^2*(c + d*x)^(3/2)*(e + f*x)^(3/2))/(20*b*d^2*f^2) + (C*(a + b*x)^3*(c + d*x)^(3/2)*(e + f*x)^(3/2))/(6*b*d*f) - (1/(960*b*d^4*f^4))*((c + d*x)^(3/2)*(e + f*x)^(3/2)*(64*a^3*C*d^3*f^3 - 8*a^2*b*d^2*f^2*(16*B*d*f - 7*C*(d*e + c*f)) - 8*a*b^2*d*f*(C*(35*d^2*e^2 + 38*c*d*e*f + 35*c^2*f^2) + 10*d*f*(8*A*d*f - 5*B*(d*e + c*f))) + b^3*(7*C*(15*d^3*e^3 + 17*c*d^2*e^2*f + 17*c^2*d*e*f^2 + 15*c^3*f^3) + 4*d*f*(50*A*d*f*(d*e + c*f) - B*(35*d^2*e^2 + 38*c*d*e*f + 35*c^2*f^2))) + 6*b*d*f*(10*b*d*f*(2*b*c*C*e + a*C*d*e + a*c*C*f - 4*A*b*d*f) + (4*a*d*f - 7*b*(d*e + c*f))*(2*a*C*d*f - b*(4*B*d*f - 3*C*(d*e + c*f))))*x)) - (1/(512*d^(11/2)*f^(11/2)))*((d*e - c*f)^2*(8*a^2*d^2*f^2*(C*(5*d^2*e^2 + 6*c*d*e*f + 5*c^2*f^2) + 8*d*f*(2*A*d*f - B*(d*e + c*f))) - 8*a*b*d*f*(C*(7*d^3*e^3 + 9*c*d^2*e^2*f + 9*c^2*d*e*f^2 + 7*c^3*f^3) + 2*d*f*(8*A*d*f*(d*e + c*f) - B*(5*d^2*e^2 + 6*c*d*e*f + 5*c^2*f^2))) + b^2*(C*(21*d^4*e^4 + 28*c*d^3*e^3*f + 30*c^2*d^2*e^2*f^2 + 28*c^3*d*e*f^3 + 21*c^4*f^4) + 4*d*f*(2*A*d*f*(5*d^2*e^2 + 6*c*d*e*f + 5*c^2*f^2) - B*(7*d^3*e^3 + 9*c*d^2*e^2*f + 9*c^2*d*e*f^2 + 7*c^3*f^3))))*atanh((sqrt(f)*sqrt(c + d*x))/(sqrt(d)*sqrt(e + f*x))))]
    @test_int [(a + b*x)^1*sqrt(c + d*x)*sqrt(e + f*x)*(A + B*x + C*x^2), x, 7, (1/(128*d^4*f^4))*((d*e - c*f)*(2*a*d*f*(C*(5*d^2*e^2 + 6*c*d*e*f + 5*c^2*f^2) + 8*d*f*(2*A*d*f - B*(d*e + c*f))) - b*(C*(7*d^3*e^3 + 9*c*d^2*e^2*f + 9*c^2*d*e*f^2 + 7*c^3*f^3) + 2*d*f*(8*A*d*f*(d*e + c*f) - B*(5*d^2*e^2 + 6*c*d*e*f + 5*c^2*f^2))))*sqrt(c + d*x)*sqrt(e + f*x)) + (1/(64*d^4*f^3))*((2*a*d*f*(C*(5*d^2*e^2 + 6*c*d*e*f + 5*c^2*f^2) + 8*d*f*(2*A*d*f - B*(d*e + c*f))) - b*(C*(7*d^3*e^3 + 9*c*d^2*e^2*f + 9*c^2*d*e*f^2 + 7*c^3*f^3) + 2*d*f*(8*A*d*f*(d*e + c*f) - B*(5*d^2*e^2 + 6*c*d*e*f + 5*c^2*f^2))))*(c + d*x)^(3/2)*sqrt(e + f*x)) + (C*(a + b*x)^2*(c + d*x)^(3/2)*(e + f*x)^(3/2))/(5*b*d*f) - (1/(240*b*d^3*f^3))*((c + d*x)^(3/2)*(e + f*x)^(3/2)*(48*a^2*C*d^2*f^2 - 10*a*b*d*f*(8*B*d*f - 5*C*(d*e + c*f)) - b^2*(C*(35*d^2*e^2 + 38*c*d*e*f + 35*c^2*f^2) + 10*d*f*(8*A*d*f - 5*B*(d*e + c*f))) + 6*b*d*f*(6*a*C*d*f - b*(10*B*d*f - 7*C*(d*e + c*f)))*x)) - (1/(128*d^(9/2)*f^(9/2)))*((d*e - c*f)^2*(2*a*d*f*(C*(5*d^2*e^2 + 6*c*d*e*f + 5*c^2*f^2) + 8*d*f*(2*A*d*f - B*(d*e + c*f))) - b*(C*(7*d^3*e^3 + 9*c*d^2*e^2*f + 9*c^2*d*e*f^2 + 7*c^3*f^3) + 2*d*f*(8*A*d*f*(d*e + c*f) - B*(5*d^2*e^2 + 6*c*d*e*f + 5*c^2*f^2))))*atanh((sqrt(f)*sqrt(c + d*x))/(sqrt(d)*sqrt(e + f*x))))]
    @test_int [(a + b*x)^0*sqrt(c + d*x)*sqrt(e + f*x)*(A + B*x + C*x^2), x, 7, ((d*e - c*f)*(C*(5*d^2*e^2 + 6*c*d*e*f + 5*c^2*f^2) + 8*d*f*(2*A*d*f - B*(d*e + c*f)))*sqrt(c + d*x)*sqrt(e + f*x))/(64*d^3*f^3) + ((C*(5*d^2*e^2 + 6*c*d*e*f + 5*c^2*f^2) + 8*d*f*(2*A*d*f - B*(d*e + c*f)))*(c + d*x)^(3/2)*sqrt(e + f*x))/(32*d^3*f^2) - ((5*C*d*e + 11*c*C*f - 8*B*d*f)*(c + d*x)^(3/2)*(e + f*x)^(3/2))/(24*d^2*f^2) + (C*(c + d*x)^(5/2)*(e + f*x)^(3/2))/(4*d^2*f) - ((d*e - c*f)^2*(C*(5*d^2*e^2 + 6*c*d*e*f + 5*c^2*f^2) + 8*d*f*(2*A*d*f - B*(d*e + c*f)))*atanh((sqrt(f)*sqrt(c + d*x))/(sqrt(d)*sqrt(e + f*x))))/(64*d^(7/2)*f^(7/2))]
    @test_int [sqrt(c + d*x)*sqrt(e + f*x)*(A + B*x + C*x^2)/(a + b*x)^1, x, 9, ((4*b*d*f*(2*A*b*d*f - a*C*(d*e + c*f)) + (b*d*e - b*c*f + 4*a*d*f)*(2*a*C*d*f + b*(C*d*e + c*C*f - 2*B*d*f)))*sqrt(c + d*x)*sqrt(e + f*x))/(8*b^3*d^2*f^2) - ((2*a*C*d*f + b*(C*d*e + c*C*f - 2*B*d*f))*sqrt(c + d*x)*(e + f*x)^(3/2))/(4*b^2*d*f^2) + (C*(c + d*x)^(3/2)*(e + f*x)^(3/2))/(3*b*d*f) - (1/(8*b^4*d^(5/2)*f^(5/2)))*((16*a^3*C*d^3*f^3 - 8*a^2*b*d^2*f^2*(C*d*e + c*C*f + 2*B*d*f) - 2*a*b^2*d*f*(C*(d*e - c*f)^2 - 4*d*f*(B*d*e + B*c*f + 2*A*d*f)) - b^3*(C*(d*e - c*f)^2*(d*e + c*f) - 2*d*f*(B*(d*e - c*f)^2 - 4*A*d*f*(d*e + c*f))))*atanh((sqrt(f)*sqrt(c + d*x))/(sqrt(d)*sqrt(e + f*x)))) - (2*(A*b^2 - a*(b*B - a*C))*sqrt(b*c - a*d)*sqrt(b*e - a*f)*atanh((sqrt(b*e - a*f)*sqrt(c + d*x))/(sqrt(b*c - a*d)*sqrt(e + f*x))))/b^4]
    @test_int [sqrt(c + d*x)*sqrt(e + f*x)*(A + B*x + C*x^2)/(a + b*x)^2, x, 9, ((12*a^2*C*d*f^2 - a*b*f*(7*C*d*e + c*C*f + 8*B*d*f) + b^2*(4*d*f*(B*e + A*f) - C*e*(d*e - c*f)))*sqrt(c + d*x)*sqrt(e + f*x))/(4*b^3*d*f*(b*e - a*f)) + ((3*a^2*C*d*f + b^2*(c*C*e + 2*A*d*f) - a*b*(C*d*e + c*C*f + 2*B*d*f))*sqrt(c + d*x)*(e + f*x)^(3/2))/(2*b^2*(b*c - a*d)*f*(b*e - a*f)) - ((A*b^2 - a*(b*B - a*C))*(c + d*x)^(3/2)*(e + f*x)^(3/2))/(b*(b*c - a*d)*(b*e - a*f)*(a + b*x)) + ((24*a^2*C*d^2*f^2 - 8*a*b*d*f*(C*d*e + c*C*f + 2*B*d*f) - b^2*(C*(d*e - c*f)^2 - 4*d*f*(B*d*e + B*c*f + 2*A*d*f)))*atanh((sqrt(f)*sqrt(c + d*x))/(sqrt(d)*sqrt(e + f*x))))/(4*b^4*d^(3/2)*f^(3/2)) + ((6*a^3*C*d*f - b^3*(2*B*c*e + A*d*e + A*c*f) + a*b^2*(4*c*C*e + 3*B*d*e + 3*B*c*f + 2*A*d*f) - a^2*b*(4*B*d*f + 5*C*(d*e + c*f)))*atanh((sqrt(b*e - a*f)*sqrt(c + d*x))/(sqrt(b*c - a*d)*sqrt(e + f*x))))/(b^4*sqrt(b*c - a*d)*sqrt(b*e - a*f))]
    @test_int [sqrt(c + d*x)*sqrt(e + f*x)*(A + B*x + C*x^2)/(a + b*x)^3, x, 9, -(((12*a^3*C*d*f^2 - a^2*b*f*(17*C*d*e + 11*c*C*f + 4*B*d*f) + a*b^2*(B*f*(5*d*e + 3*c*f) + 4*C*e*(d*e + 4*c*f)) - b^3*(A*d*e*f + c*(4*C*e^2 + 4*B*e*f - A*f^2)))*sqrt(c + d*x)*sqrt(e + f*x))/(4*b^3*(b*c - a*d)*(b*e - a*f)^2)) + ((6*a^3*C*d*f - b^3*(4*B*c*e - A*d*e - A*c*f) + a*b^2*(8*c*C*e + 3*B*d*e + 3*B*c*f - 2*A*d*f) - a^2*b*(2*B*d*f + 7*C*(d*e + c*f)))*sqrt(c + d*x)*(e + f*x)^(3/2))/(4*b^2*(b*c - a*d)*(b*e - a*f)^2*(a + b*x)) - ((A*b^2 - a*(b*B - a*C))*(c + d*x)^(3/2)*(e + f*x)^(3/2))/(2*b*(b*c - a*d)*(b*e - a*f)*(a + b*x)^2) - ((6*a*C*d*f - b*(C*d*e + c*C*f + 2*B*d*f))*atanh((sqrt(f)*sqrt(c + d*x))/(sqrt(d)*sqrt(e + f*x))))/(b^4*sqrt(d)*sqrt(f)) - (1/(4*b^4*(b*c - a*d)^(3/2)*(b*e - a*f)^(3/2)))*((24*a^4*C*d^2*f^2 - 3*a*b^3*(B*d^2*e^2 + c^2*f*(8*C*e + B*f) + 2*c*d*e*(4*C*e + 3*B*f)) - 8*a^3*b*d*f*(B*d*f + 5*C*(d*e + c*f)) - b^4*(A*d^2*e^2 - 2*c*d*e*(2*B*e + A*f) - c^2*(8*C*e^2 + 4*B*e*f - A*f^2)) + 3*a^2*b^2*(4*B*d*f*(d*e + c*f) + C*(5*d^2*e^2 + 22*c*d*e*f + 5*c^2*f^2)))*atanh((sqrt(b*e - a*f)*sqrt(c + d*x))/(sqrt(b*c - a*d)*sqrt(e + f*x))))]

    #= ::Subsubsection::Closed:: =#
    #=n>0 & p<0=#

    @test_int [(a + b*x)^2*sqrt(c + d*x)*(A + B*x + C*x^2)/sqrt(e + f*x), x, 7, -((1/(128*d^4*f^5))*((16*a^2*d^2*f^2*(2*d*f*(3*B*d*e + B*c*f - 4*A*d*f) - C*(5*d^2*e^2 + 2*c*d*e*f + c^2*f^2)) + 4*a*b*d*f*(C*(35*d^3*e^3 + 15*c*d^2*e^2*f + 9*c^2*d*e*f^2 + 5*c^3*f^3) + 8*d*f*(2*A*d*f*(3*d*e + c*f) - B*(5*d^2*e^2 + 2*c*d*e*f + c^2*f^2))) - b^2*(C*(63*d^4*e^4 + 28*c*d^3*e^3*f + 18*c^2*d^2*e^2*f^2 + 12*c^3*d*e*f^3 + 7*c^4*f^4) + 2*d*f*(8*A*d*f*(5*d^2*e^2 + 2*c*d*e*f + c^2*f^2) - B*(35*d^3*e^3 + 15*c*d^2*e^2*f + 9*c^2*d*e*f^2 + 5*c^3*f^3))))*sqrt(c + d*x)*sqrt(e + f*x))) - ((4*a*C*d*f + b*(9*C*d*e + 7*c*C*f - 10*B*d*f))*(a + b*x)^2*(c + d*x)^(3/2)*sqrt(e + f*x))/(40*b*d^2*f^2) + (C*(a + b*x)^3*(c + d*x)^(3/2)*sqrt(e + f*x))/(5*b*d*f) - (1/(960*b*d^4*f^4))*((c + d*x)^(3/2)*sqrt(e + f*x)*(96*a^3*C*d^3*f^3 + 8*a^2*b*d^2*f^2*(23*C*d*e + 9*c*C*f - 30*B*d*f) + 20*a*b^2*d*f*(8*d*f*(5*B*d*e + 3*B*c*f - 6*A*d*f) - C*(35*d^2*e^2 + 22*c*d*e*f + 15*c^2*f^2)) + b^3*(C*(315*d^3*e^3 + 203*c*d^2*e^2*f + 145*c^2*d*e*f^2 + 105*c^3*f^3) + 10*d*f*(8*A*d*f*(5*d*e + 3*c*f) - B*(35*d^2*e^2 + 22*c*d*e*f + 15*c^2*f^2))) + 4*b*d*f*(8*b*d*f*(6*b*c*C*e + 3*a*C*d*e + a*c*C*f - 10*A*b*d*f) - (7*b*d*e + 5*b*c*f - 4*a*d*f)*(4*a*C*d*f + b*(9*C*d*e + 7*c*C*f - 10*B*d*f)))*x)) + (1/(128*d^(9/2)*f^(11/2)))*((d*e - c*f)*(16*a^2*d^2*f^2*(2*d*f*(3*B*d*e + B*c*f - 4*A*d*f) - C*(5*d^2*e^2 + 2*c*d*e*f + c^2*f^2)) + 4*a*b*d*f*(C*(35*d^3*e^3 + 15*c*d^2*e^2*f + 9*c^2*d*e*f^2 + 5*c^3*f^3) + 8*d*f*(2*A*d*f*(3*d*e + c*f) - B*(5*d^2*e^2 + 2*c*d*e*f + c^2*f^2))) - b^2*(C*(63*d^4*e^4 + 28*c*d^3*e^3*f + 18*c^2*d^2*e^2*f^2 + 12*c^3*d*e*f^3 + 7*c^4*f^4) + 2*d*f*(8*A*d*f*(5*d^2*e^2 + 2*c*d*e*f + c^2*f^2) - B*(35*d^3*e^3 + 15*c*d^2*e^2*f + 9*c^2*d*e*f^2 + 5*c^3*f^3))))*atanh((sqrt(f)*sqrt(c + d*x))/(sqrt(d)*sqrt(e + f*x))))]
    @test_int [(a + b*x)^1*sqrt(c + d*x)*(A + B*x + C*x^2)/sqrt(e + f*x), x, 6, -((1/(64*d^3*f^4))*((8*a*d*f*(2*d*f*(3*B*d*e + B*c*f - 4*A*d*f) - C*(5*d^2*e^2 + 2*c*d*e*f + c^2*f^2)) + b*(C*(35*d^3*e^3 + 15*c*d^2*e^2*f + 9*c^2*d*e*f^2 + 5*c^3*f^3) + 8*d*f*(2*A*d*f*(3*d*e + c*f) - B*(5*d^2*e^2 + 2*c*d*e*f + c^2*f^2))))*sqrt(c + d*x)*sqrt(e + f*x))) + (C*(a + b*x)^2*(c + d*x)^(3/2)*sqrt(e + f*x))/(4*b*d*f) - (1/(96*b*d^3*f^3))*((c + d*x)^(3/2)*sqrt(e + f*x)*(24*a^2*C*d^2*f^2 + 8*a*b*d*f*(5*C*d*e + 3*c*C*f - 6*B*d*f) + b^2*(8*d*f*(5*B*d*e + 3*B*c*f - 6*A*d*f) - C*(35*d^2*e^2 + 22*c*d*e*f + 15*c^2*f^2)) + 4*b*d*f*(4*a*C*d*f + b*(7*C*d*e + 5*c*C*f - 8*B*d*f))*x)) + (1/(64*d^(7/2)*f^(9/2)))*((d*e - c*f)*(8*a*d*f*(2*d*f*(3*B*d*e + B*c*f - 4*A*d*f) - C*(5*d^2*e^2 + 2*c*d*e*f + c^2*f^2)) + b*(C*(35*d^3*e^3 + 15*c*d^2*e^2*f + 9*c^2*d*e*f^2 + 5*c^3*f^3) + 8*d*f*(2*A*d*f*(3*d*e + c*f) - B*(5*d^2*e^2 + 2*c*d*e*f + c^2*f^2))))*atanh((sqrt(f)*sqrt(c + d*x))/(sqrt(d)*sqrt(e + f*x))))]
    @test_int [(a + b*x)^0*sqrt(c + d*x)*(A + B*x + C*x^2)/sqrt(e + f*x), x, 6, ((C*(5*d^2*e^2 + 2*c*d*e*f + c^2*f^2) + 2*d*f*(4*A*d*f - B*(3*d*e + c*f)))*sqrt(c + d*x)*sqrt(e + f*x))/(8*d^2*f^3) - ((5*C*d*e + 7*c*C*f - 6*B*d*f)*(c + d*x)^(3/2)*sqrt(e + f*x))/(12*d^2*f^2) + (C*(c + d*x)^(5/2)*sqrt(e + f*x))/(3*d^2*f) - ((d*e - c*f)*(C*(5*d^2*e^2 + 2*c*d*e*f + c^2*f^2) + 2*d*f*(4*A*d*f - B*(3*d*e + c*f)))*atanh((sqrt(f)*sqrt(c + d*x))/(sqrt(d)*sqrt(e + f*x))))/(8*d^(5/2)*f^(7/2))]
    @test_int [sqrt(c + d*x)*(A + B*x + C*x^2)/((a + b*x)^1*sqrt(e + f*x)), x, 8, -(((4*a*C*d*f + b*(3*C*d*e + c*C*f - 4*B*d*f))*sqrt(c + d*x)*sqrt(e + f*x))/(4*b^2*d*f^2)) + (C*(c + d*x)^(3/2)*sqrt(e + f*x))/(2*b*d*f) + ((2*b*d*f*(4*A*b*d*f - a*C*(3*d*e + c*f)) + (b*d*e - b*c*f + 2*a*d*f)*(4*a*C*d*f + b*(3*C*d*e + c*C*f - 4*B*d*f)))*atanh((sqrt(f)*sqrt(c + d*x))/(sqrt(d)*sqrt(e + f*x))))/(4*b^3*d^(3/2)*f^(5/2)) - (2*(A*b^2 - a*(b*B - a*C))*sqrt(b*c - a*d)*atanh((sqrt(b*e - a*f)*sqrt(c + d*x))/(sqrt(b*c - a*d)*sqrt(e + f*x))))/(b^3*sqrt(b*e - a*f))]
    @test_int [sqrt(c + d*x)*(A + B*x + C*x^2)/((a + b*x)^2*sqrt(e + f*x)), x, 8, ((2*a^2*C*d*f + b^2*(c*C*e + A*d*f) - a*b*(C*d*e + c*C*f + B*d*f))*sqrt(c + d*x)*sqrt(e + f*x))/(b^2*(b*c - a*d)*f*(b*e - a*f)) - ((A*b^2 - a*(b*B - a*C))*(c + d*x)^(3/2)*sqrt(e + f*x))/(b*(b*c - a*d)*(b*e - a*f)*(a + b*x)) - ((4*a*C*d*f + b*(C*d*e - c*C*f - 2*B*d*f))*atanh((sqrt(f)*sqrt(c + d*x))/(sqrt(d)*sqrt(e + f*x))))/(b^3*sqrt(d)*f^(3/2)) + ((4*a^3*C*d*f - b^3*(2*B*c*e + A*d*e - A*c*f) + a*b^2*(4*c*C*e + 3*B*d*e + B*c*f) - a^2*b*(5*C*d*e + 3*c*C*f + 2*B*d*f))*atanh((sqrt(b*e - a*f)*sqrt(c + d*x))/(sqrt(b*c - a*d)*sqrt(e + f*x))))/(b^3*sqrt(b*c - a*d)*(b*e - a*f)^(3/2))]
    @test_int [sqrt(c + d*x)*(A + B*x + C*x^2)/((a + b*x)^3*sqrt(e + f*x)), x, 8, ((4*a^3*C*d*f - a^2*b*C*(7*d*e + 5*c*f) - b^3*(4*B*c*e - A*d*e - 3*A*c*f) + a*b^2*(8*c*C*e + 3*B*d*e + B*c*f - 4*A*d*f))*sqrt(c + d*x)*sqrt(e + f*x))/(4*b^2*(b*c - a*d)*(b*e - a*f)^2*(a + b*x)) - ((A*b^2 - a*(b*B - a*C))*(c + d*x)^(3/2)*sqrt(e + f*x))/(2*b*(b*c - a*d)*(b*e - a*f)*(a + b*x)^2) + (2*C*sqrt(d)*atanh((sqrt(f)*sqrt(c + d*x))/(sqrt(d)*sqrt(e + f*x))))/(b^3*sqrt(f)) - (1/(4*b^3*(b*c - a*d)^(3/2)*(b*e - a*f)^(5/2)))*((8*a^4*C*d^2*f^2 - 4*a^3*b*C*d*f*(5*d*e + 3*c*f) + 3*a^2*b^2*C*(5*d^2*e^2 + 10*c*d*e*f + c^2*f^2) - a*b^3*(d^2*e*(3*B*e - 4*A*f) + c^2*f*(8*C*e - B*f) + 2*c*d*(12*C*e^2 - B*e*f + 2*A*f^2)) - b^4*(A*d^2*e^2 - 2*c*d*e*(2*B*e - A*f) - c^2*(8*C*e^2 - 4*B*e*f + 3*A*f^2)))*atanh((sqrt(b*e - a*f)*sqrt(c + d*x))/(sqrt(b*c - a*d)*sqrt(e + f*x))))]
    @test_int [sqrt(c + d*x)*(A + B*x + C*x^2)/((a + b*x)^4*sqrt(e + f*x)), x, 6, ((4*a^3*C*d*f - b^3*(6*B*c*e - 3*A*d*e - 5*A*c*f) + a*b^2*(12*c*C*e + 3*B*d*e + B*c*f - 8*A*d*f) - a^2*b*(9*C*d*e + 7*c*C*f - 2*B*d*f))*sqrt(c + d*x)*sqrt(e + f*x))/(12*b^2*(b*c - a*d)*(b*e - a*f)^2*(a + b*x)^2) - (1/(24*b^2*(b*c - a*d)^2*(b*e - a*f)^3*(a + b*x)))*((8*a^4*C*d^2*f^2 - 2*a^3*b*d*f*(13*C*d*e + 7*c*C*f - 2*B*d*f) - b^4*(3*A*d^2*e^2 - 2*c*d*e*(3*B*e - 2*A*f) - 3*c^2*(8*C*e^2 - 6*B*e*f + 5*A*f^2)) - a*b^3*(d^2*e*(3*B*e - 10*A*f) + 3*c^2*f*(4*C*e - B*f) + 2*c*d*(30*C*e^2 - 14*B*e*f + 13*A*f^2)) - a^2*b^2*(4*d*f*(4*B*d*e + B*c*f - 2*A*d*f) - C*(33*d^2*e^2 + 44*c*d*e*f + 3*c^2*f^2)))*sqrt(c + d*x)*sqrt(e + f*x)) - ((A*b^2 - a*(b*B - a*C))*(c + d*x)^(3/2)*sqrt(e + f*x))/(3*b*(b*c - a*d)*(b*e - a*f)*(a + b*x)^3) - (1/(8*(b*c - a*d)^(5/2)*(b*e - a*f)^(7/2)))*((d*e - c*f)*(b^2*(A*d^2*e^2 - 2*c*d*e*(B*e - A*f) + c^2*(8*C*e^2 - 6*B*e*f + 5*A*f^2)) + a*b*(d^2*e*(B*e - 4*A*f) - c^2*f*(4*C*e - B*f) - 2*c*d*(6*C*e^2 - 7*B*e*f + 6*A*f^2)) - a^2*(2*d*f*(3*B*d*e + B*c*f - 4*A*d*f) - C*(5*d^2*e^2 + 2*c*d*e*f + c^2*f^2)))*atanh((sqrt(b*e - a*f)*sqrt(c + d*x))/(sqrt(b*c - a*d)*sqrt(e + f*x))))]

    #= ::Subsubsection::Closed:: =#
    #=n<0 & p<0=#

    @test_int [(a + b*x)^2*(A + B*x + C*x^2)/(sqrt(c + d*x)*sqrt(e + f*x)), x, 6, -(((2*a*C*d*f - b*(8*B*d*f - 7*C*(d*e + c*f)))*(a + b*x)^2*sqrt(c + d*x)*sqrt(e + f*x))/(24*b*d^2*f^2)) + (C*(a + b*x)^3*sqrt(c + d*x)*sqrt(e + f*x))/(4*b*d*f) - (1/(192*b*d^4*f^4))*(sqrt(c + d*x)*sqrt(e + f*x)*(32*a^3*C*d^3*f^3 - 8*a^2*b*d^2*f^2*(16*B*d*f - 11*C*(d*e + c*f)) - 16*a*b^2*d*f*(C*(15*d^2*e^2 + 14*c*d*e*f + 15*c^2*f^2) + 6*d*f*(4*A*d*f - 3*B*(d*e + c*f))) + b^3*(5*C*(21*d^3*e^3 + 19*c*d^2*e^2*f + 19*c^2*d*e*f^2 + 21*c^3*f^3) + 8*d*f*(18*A*d*f*(d*e + c*f) - B*(15*d^2*e^2 + 14*c*d*e*f + 15*c^2*f^2))) + 2*b*d*f*(6*b*d*f*(6*b*c*C*e + a*C*d*e + a*c*C*f - 8*A*b*d*f) + (4*a*d*f - 5*b*(d*e + c*f))*(2*a*C*d*f - b*(8*B*d*f - 7*C*(d*e + c*f))))*x)) + (1/(64*d^(9/2)*f^(9/2)))*((16*a^2*d^2*f^2*(C*(3*d^2*e^2 + 2*c*d*e*f + 3*c^2*f^2) + 4*d*f*(2*A*d*f - B*(d*e + c*f))) - 16*a*b*d*f*(C*(5*d^3*e^3 + 3*c*d^2*e^2*f + 3*c^2*d*e*f^2 + 5*c^3*f^3) + 2*d*f*(4*A*d*f*(d*e + c*f) - B*(3*d^2*e^2 + 2*c*d*e*f + 3*c^2*f^2))) + b^2*(C*(35*d^4*e^4 + 20*c*d^3*e^3*f + 18*c^2*d^2*e^2*f^2 + 20*c^3*d*e*f^3 + 35*c^4*f^4) + 8*d*f*(2*A*d*f*(3*d^2*e^2 + 2*c*d*e*f + 3*c^2*f^2) - B*(5*d^3*e^3 + 3*c*d^2*e^2*f + 3*c^2*d*e*f^2 + 5*c^3*f^3))))*atanh((sqrt(f)*sqrt(c + d*x))/(sqrt(d)*sqrt(e + f*x))))]
    @test_int [(a + b*x)^1*(A + B*x + C*x^2)/(sqrt(c + d*x)*sqrt(e + f*x)), x, 5, (C*(a + b*x)^2*sqrt(c + d*x)*sqrt(e + f*x))/(3*b*d*f) - (1/(24*b*d^3*f^3))*(sqrt(c + d*x)*sqrt(e + f*x)*(8*a^2*C*d^2*f^2 - 6*a*b*d*f*(4*B*d*f - 3*C*(d*e + c*f)) - b^2*(C*(15*d^2*e^2 + 14*c*d*e*f + 15*c^2*f^2) + 6*d*f*(4*A*d*f - 3*B*(d*e + c*f))) + 2*b*d*f*(2*a*C*d*f - b*(6*B*d*f - 5*C*(d*e + c*f)))*x)) + (1/(8*d^(7/2)*f^(7/2)))*((2*a*d*f*(C*(3*d^2*e^2 + 2*c*d*e*f + 3*c^2*f^2) + 4*d*f*(2*A*d*f - B*(d*e + c*f))) - b*(C*(5*d^3*e^3 + 3*c*d^2*e^2*f + 3*c^2*d*e*f^2 + 5*c^3*f^3) + 2*d*f*(4*A*d*f*(d*e + c*f) - B*(3*d^2*e^2 + 2*c*d*e*f + 3*c^2*f^2))))*atanh((sqrt(f)*sqrt(c + d*x))/(sqrt(d)*sqrt(e + f*x))))]
    @test_int [(a + b*x)^0*(A + B*x + C*x^2)/(sqrt(c + d*x)*sqrt(e + f*x)), x, 5, -(((3*C*d*e + 5*c*C*f - 4*B*d*f)*sqrt(c + d*x)*sqrt(e + f*x))/(4*d^2*f^2)) + (C*(c + d*x)^(3/2)*sqrt(e + f*x))/(2*d^2*f) + ((C*(3*d^2*e^2 + 2*c*d*e*f + 3*c^2*f^2) + 4*d*f*(2*A*d*f - B*(d*e + c*f)))*atanh((sqrt(f)*sqrt(c + d*x))/(sqrt(d)*sqrt(e + f*x))))/(4*d^(5/2)*f^(5/2))]
    @test_int [(A + B*x + C*x^2)/((a + b*x)^1*sqrt(c + d*x)*sqrt(e + f*x)), x, 7, (C*sqrt(c + d*x)*sqrt(e + f*x))/(b*d*f) - ((2*a*C*d*f + b*(C*d*e + c*C*f - 2*B*d*f))*atanh((sqrt(f)*sqrt(c + d*x))/(sqrt(d)*sqrt(e + f*x))))/(b^2*d^(3/2)*f^(3/2)) - (2*(A*b^2 - a*(b*B - a*C))*atanh((sqrt(b*e - a*f)*sqrt(c + d*x))/(sqrt(b*c - a*d)*sqrt(e + f*x))))/(b^2*sqrt(b*c - a*d)*sqrt(b*e - a*f))]
    @test_int [(A + B*x + C*x^2)/((a + b*x)^2*sqrt(c + d*x)*sqrt(e + f*x)), x, 7, -(((A*b^2 - a*(b*B - a*C))*sqrt(c + d*x)*sqrt(e + f*x))/(b*(b*c - a*d)*(b*e - a*f)*(a + b*x))) + (2*C*atanh((sqrt(f)*sqrt(c + d*x))/(sqrt(d)*sqrt(e + f*x))))/(b^2*sqrt(d)*sqrt(f)) + ((2*a^3*C*d*f - 3*a^2*b*C*(d*e + c*f) - b^3*(2*B*c*e - A*d*e - A*c*f) + a*b^2*(4*c*C*e + B*d*e + B*c*f - 2*A*d*f))*atanh((sqrt(b*e - a*f)*sqrt(c + d*x))/(sqrt(b*c - a*d)*sqrt(e + f*x))))/(b^2*(b*c - a*d)^(3/2)*(b*e - a*f)^(3/2))]
    @test_int [(A + B*x + C*x^2)/((a + b*x)^3*sqrt(c + d*x)*sqrt(e + f*x)), x, 5, -(((A*b^2 - a*(b*B - a*C))*sqrt(c + d*x)*sqrt(e + f*x))/(2*b*(b*c - a*d)*(b*e - a*f)*(a + b*x)^2)) + ((2*a^3*C*d*f + a*b^2*(8*c*C*e + B*d*e + B*c*f - 6*A*d*f) - b^3*(4*B*c*e - 3*A*(d*e + c*f)) + a^2*b*(2*B*d*f - 5*C*(d*e + c*f)))*sqrt(c + d*x)*sqrt(e + f*x))/(4*b*(b*c - a*d)^2*(b*e - a*f)^2*(a + b*x)) - (1/(4*(b*c - a*d)^(5/2)*(b*e - a*f)^(5/2)))*((b^2*(3*A*d^2*e^2 - 2*c*d*e*(2*B*e - A*f) + c^2*(8*C*e^2 - 4*B*e*f + 3*A*f^2)) + a*b*(d^2*e*(B*e - 8*A*f) - c^2*f*(8*C*e - B*f) - 2*c*d*(4*C*e^2 - 7*B*e*f + 4*A*f^2)) + a^2*(C*(3*d^2*e^2 + 2*c*d*e*f + 3*c^2*f^2) + 4*d*f*(2*A*d*f - B*(d*e + c*f))))*atanh((sqrt(b*e - a*f)*sqrt(c + d*x))/(sqrt(b*c - a*d)*sqrt(e + f*x))))]
    @test_int [(A + B*x + C*x^2)/((a + b*x)^4*sqrt(c + d*x)*sqrt(e + f*x)), x, 6, -(((A*b^2 - a*(b*B - a*C))*sqrt(c + d*x)*sqrt(e + f*x))/(3*b*(b*c - a*d)*(b*e - a*f)*(a + b*x)^3)) + ((2*a^3*C*d*f + a*b^2*(12*c*C*e + B*d*e + B*c*f - 10*A*d*f) - b^3*(6*B*c*e - 5*A*(d*e + c*f)) + a^2*b*(4*B*d*f - 7*C*(d*e + c*f)))*sqrt(c + d*x)*sqrt(e + f*x))/(12*b*(b*c - a*d)^2*(b*e - a*f)^2*(a + b*x)^2) + (1/(24*b*(b*c - a*d)^3*(b*e - a*f)^3*(a + b*x)))*((4*a^4*C*d^2*f^2 + 8*a^3*b*d*f*(B*d*f - 2*C*(d*e + c*f)) - b^4*(15*A*d^2*e^2 - 2*c*d*e*(9*B*e - 7*A*f) + 3*c^2*(8*C*e^2 - 6*B*e*f + 5*A*f^2)) - a*b^3*(d^2*e*(3*B*e - 44*A*f) - 3*c^2*f*(4*C*e - B*f) - 2*c*d*(6*C*e^2 - 29*B*e*f + 22*A*f^2)) - a^2*b^2*(C*(3*d^2*e^2 - 34*c*d*e*f + 3*c^2*f^2) + 2*d*f*(22*A*d*f - 5*B*(d*e + c*f))))*sqrt(c + d*x)*sqrt(e + f*x)) + (1/(8*(b*c - a*d)^(7/2)*(b*e - a*f)^(7/2)))*((b^3*(5*A*d^3*e^3 - 3*c*d^2*e^2*(2*B*e - A*f) + c^2*d*e*(8*C*e^2 - 4*B*e*f + 3*A*f^2) + c^3*f*(8*C*e^2 - 6*B*e*f + 5*A*f^2)) + a*b^2*(d^3*e^2*(B*e - 18*A*f) - c^3*f^2*(4*C*e - B*f) - c*d^2*e*(4*C*e^2 - 23*B*e*f + 12*A*f^2) - c^2*d*f*(40*C*e^2 - 23*B*e*f + 18*A*f^2)) - 2*a^3*d*f*(C*(3*d^2*e^2 + 2*c*d*e*f + 3*c^2*f^2) + 4*d*f*(2*A*d*f - B*(d*e + c*f))) + a^2*b*(C*(d^3*e^3 + 23*c*d^2*e^2*f + 23*c^2*d*e*f^2 + c^3*f^3) + 4*d*f*(6*A*d*f*(d*e + c*f) - B*(d^2*e^2 + 10*c*d*e*f + c^2*f^2))))*atanh((sqrt(b*e - a*f)*sqrt(c + d*x))/(sqrt(b*c - a*d)*sqrt(e + f*x))))]

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*(a+b*x)^(m/2)*(c+d*x)^(n/2)*(e+f*x)^(p/2)*(A+B*x+C*x^2)=#

    #= ::Subsubsection::Closed:: =#
    #=n>0 & p>0=#

    @test_int [(a + b*x)^(1/2)*sqrt(c + d*x)*sqrt(e + f*x)*(A + B*x + C*x^2), x, 10, (1/(315*b^3*d^3*f^3))*(2*(8*a^3*C*d^3*f^3 + 3*a^2*b*d^2*f^2*(C*d*e - c*C*f - 4*B*d*f) - 3*a*b^2*d*f^2*((c^2*C - 7*A*d^2)*f + B*d*(d*e - 2*c*f)) - b^3*(C*(16*d^3*e^3 - 3*c^2*d*e*f^2 - 8*c^3*f^3) + 3*d*f*(7*A*d*f*(2*d*e - c*f) - B*(8*d^2*e^2 - c*d*e*f - 4*c^2*f^2))))*sqrt(a + b*x)*sqrt(c + d*x)*sqrt(e + f*x)) - (2*(7*b*d*f*(b*c*C*e + a*C*d*e + a*c*C*f - 3*A*b*d*f) + (a*d*f - 4*b*(d*e + c*f))*(2*a*C*d*f - b*(3*B*d*f - 2*C*(d*e + c*f))))*sqrt(a + b*x)*sqrt(c + d*x)*(e + f*x)^(3/2))/(105*b^2*d^2*f^3) - (2*(2*a*C*d*f - b*(3*B*d*f - 2*C*(d*e + c*f)))*sqrt(a + b*x)*(c + d*x)^(3/2)*(e + f*x)^(3/2))/(21*b*d^2*f^2) + (2*C*(a + b*x)^(3/2)*(c + d*x)^(3/2)*(e + f*x)^(3/2))/(9*b*d*f) - (1/(315*b^4*d^(7/2)*f^4*sqrt(c + d*x)*sqrt((b*(e + f*x))/(b*e - a*f))))*(2*sqrt((-b)*c + a*d)*(16*a^4*C*d^4*f^4 - 8*a^3*b*d^3*f^3*(C*d*e + c*C*f + 3*B*d*f) + 3*a^2*b^2*d^2*f^2*(d*f*(5*B*d*e + 5*B*c*f + 14*A*d*f) - 2*C*(d^2*e^2 - c*d*e*f + c^2*f^2)) - a*b^3*d*f*(C*(8*d^3*e^3 - 6*c*d^2*e^2*f - 6*c^2*d*e*f^2 + 8*c^3*f^3) + 3*d*f*(14*A*d*f*(d*e + c*f) - B*(5*d^2*e^2 - 6*c*d*e*f + 5*c^2*f^2))) + b^4*(2*C*(8*d^4*e^4 - 4*c*d^3*e^3*f - 3*c^2*d^2*e^2*f^2 - 4*c^3*d*e*f^3 + 8*c^4*f^4) + 3*d*f*(14*A*d*f*(d^2*e^2 - c*d*e*f + c^2*f^2) - B*(8*d^3*e^3 - 5*c*d^2*e^2*f - 5*c^2*d*e*f^2 + 8*c^3*f^3))))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt(e + f*x)*Elliptic.E(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f)))) - (1/(315*b^4*d^(7/2)*f^4*sqrt(c + d*x)*sqrt(e + f*x)))*(2*sqrt((-b)*c + a*d)*(b*e - a*f)*(d*e - c*f)*(8*a^3*C*d^3*f^3 + 3*a^2*b*d^2*f^2*(C*d*e - c*C*f - 4*B*d*f) - 3*a*b^2*d*f^2*((c^2*C - 7*A*d^2)*f + B*d*(d*e - 2*c*f)) - b^3*(C*(16*d^3*e^3 - 3*c^2*d*e*f^2 - 8*c^3*f^3) + 3*d*f*(7*A*d*f*(2*d*e - c*f) - B*(8*d^2*e^2 - c*d*e*f - 4*c^2*f^2))))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt((b*(e + f*x))/(b*e - a*f))*Elliptic.F(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f))))]
    @test_int [sqrt(c + d*x)*sqrt(e + f*x)*(A + B*x + C*x^2)/(a + b*x)^(1/2), x, 9, -((2*(5*b*d*f*(3*a*C*(d*e + c*f) + b*(c*C*e - 7*A*d*f)) - (2*b*d*e - b*c*f + 4*a*d*f)*(6*a*C*d*f - b*(7*B*d*f - 4*C*(d*e + c*f))))*sqrt(a + b*x)*sqrt(c + d*x)*sqrt(e + f*x))/(105*b^3*d^2*f^2)) - (2*(6*a*C*d*f - b*(7*B*d*f - 4*C*(d*e + c*f)))*sqrt(a + b*x)*sqrt(c + d*x)*(e + f*x)^(3/2))/(35*b^2*d*f^2) + (2*C*sqrt(a + b*x)*(c + d*x)^(3/2)*(e + f*x)^(3/2))/(7*b*d*f) - (1/(105*b^4*d^(5/2)*f^3*sqrt(c + d*x)*sqrt((b*(e + f*x))/(b*e - a*f))))*(2*sqrt((-b)*c + a*d)*(3*b*d*f*(5*b*c*f*(3*a*C*(d*e + c*f) + b*(c*C*e - 7*A*d*f)) - (b*c*e + a*d*e + 3*a*c*f)*(6*a*C*d*f - b*(7*B*d*f - 4*C*(d*e + c*f)))) + 2*((b*d*e)/2 - (b*c + a*d)*f)*(5*b*d*f*(3*a*C*(d*e + c*f) + b*(c*C*e - 7*A*d*f)) - (2*b*d*e - b*c*f + 4*a*d*f)*(6*a*C*d*f - b*(7*B*d*f - 4*C*(d*e + c*f)))))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt(e + f*x)*Elliptic.E(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f)))) - (1/(105*b^4*d^(5/2)*f^3*sqrt(c + d*x)*sqrt(e + f*x)))*(2*sqrt((-b)*c + a*d)*(b*e - a*f)*(d*e - c*f)*(24*a^2*C*d^2*f^2 + a*b*d*f*(13*C*d*e - 5*c*C*f - 28*B*d*f) - b^2*(7*d*f*(2*B*d*e - B*c*f - 5*A*d*f) - C*(8*d^2*e^2 - c*d*e*f - 4*c^2*f^2)))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt((b*(e + f*x))/(b*e - a*f))*Elliptic.F(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f))))]
    @test_int [sqrt(c + d*x)*sqrt(e + f*x)*(A + B*x + C*x^2)/(a + b*x)^(3/2), x, 9, (2*(24*a^2*C*d*f^2 - a*b*f*(7*C*d*e + c*C*f + 20*B*d*f) + b^2*(5*d*f*(B*e + 3*A*f) - C*e*(2*d*e - c*f)))*sqrt(a + b*x)*sqrt(c + d*x)*sqrt(e + f*x))/(15*b^3*d*f*(b*e - a*f)) + (2*(6*a^2*C*d*f + b^2*(c*C*e + 5*A*d*f) - a*b*(C*d*e + c*C*f + 5*B*d*f))*sqrt(a + b*x)*sqrt(c + d*x)*(e + f*x)^(3/2))/(5*b^2*(b*c - a*d)*f*(b*e - a*f)) - (2*(A*b^2 - a*(b*B - a*C))*(c + d*x)^(3/2)*(e + f*x)^(3/2))/(b*(b*c - a*d)*(b*e - a*f)*sqrt(a + b*x)) + (1/(15*b^4*d^(3/2)*f^2*sqrt(c + d*x)*sqrt((b*(e + f*x))/(b*e - a*f))))*(2*sqrt((-b)*c + a*d)*(48*a^2*C*d^2*f^2 - 8*a*b*d*f*(C*d*e + c*C*f + 5*B*d*f) + b^2*(5*d*f*(B*d*e + B*c*f + 6*A*d*f) - 2*C*(d^2*e^2 - c*d*e*f + c^2*f^2)))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt(e + f*x)*Elliptic.E(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f)))) - (1/(15*b^4*d^(3/2)*f^2*sqrt(c + d*x)*sqrt(e + f*x)))*(2*sqrt((-b)*c + a*d)*(d*e - c*f)*(24*a^2*C*d*f^2 - a*b*f*(7*C*d*e + c*C*f + 20*B*d*f) + b^2*(5*d*f*(B*e + 3*A*f) - C*e*(2*d*e - c*f)))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt((b*(e + f*x))/(b*e - a*f))*Elliptic.F(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f))))]
    @test_int [sqrt(c + d*x)*sqrt(e + f*x)*(A + B*x + C*x^2)/(a + b*x)^(5/2), x, 9, (2*(8*a^2*C*d*f + b^2*(c*C*e + 3*B*c*f + A*d*f) - a*b*(C*d*e + 7*c*C*f + 4*B*d*f))*sqrt(a + b*x)*sqrt(c + d*x)*sqrt(e + f*x))/(3*b^3*(b*c - a*d)*(b*e - a*f)) - (2*(b*B - 2*a*C)*sqrt(c + d*x)*(e + f*x)^(3/2))/(b^2*(b*e - a*f)*sqrt(a + b*x)) - (2*(A*b^2 - a*(b*B - a*C))*(c + d*x)^(3/2)*(e + f*x)^(3/2))/(3*b*(b*c - a*d)*(b*e - a*f)*(a + b*x)^(3/2)) + (2*(16*a^3*C*d^2*f^2 - 8*a^2*b*d*f*(B*d*f + 2*C*(d*e + c*f)) - b^3*(c^2*C*e*f + A*d^2*e*f + c*d*(C*e^2 + 6*B*e*f + A*f^2)) + a*b^2*(d*f*(7*B*d*e + 7*B*c*f + 2*A*d*f) + C*(d^2*e^2 + 16*c*d*e*f + c^2*f^2)))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt(e + f*x)*Elliptic.E(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f))))/(3*b^4*sqrt(d)*sqrt((-b)*c + a*d)*f*(b*e - a*f)*sqrt(c + d*x)*sqrt((b*(e + f*x))/(b*e - a*f))) + (2*(d*e - c*f)*(8*a^2*C*d*f + b^2*(c*C*e + 3*B*c*f + A*d*f) - a*b*(C*d*e + 7*c*C*f + 4*B*d*f))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt((b*(e + f*x))/(b*e - a*f))*Elliptic.F(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f))))/(3*b^4*sqrt(d)*sqrt((-b)*c + a*d)*f*sqrt(c + d*x)*sqrt(e + f*x))]
    @test_int [sqrt(c + d*x)*sqrt(e + f*x)*(A + B*x + C*x^2)/(a + b*x)^(7/2), x, 9, (2*(24*a^3*C*d^2*f - a^2*b*d*(23*C*d*e + 41*c*C*f + 4*B*d*f) - b^3*(15*c^2*C*e - 2*A*d^2*e + c*d*(5*B*e + A*f)) + a*b^2*(15*c^2*C*f + d^2*(3*B*e - A*f) + c*(40*C*d*e + 6*B*d*f)))*sqrt(c + d*x)*sqrt(e + f*x))/(15*b^3*(b*c - a*d)^2*(b*e - a*f)*sqrt(a + b*x)) + (2*(6*a^3*C*d*f + a*b^2*(10*c*C*e + 3*B*d*e + 3*B*c*f - 4*A*d*f) - b^3*(5*B*c*e - 2*A*(d*e + c*f)) - a^2*b*(B*d*f + 8*C*(d*e + c*f)))*sqrt(c + d*x)*(e + f*x)^(3/2))/(15*b^2*(b*c - a*d)*(b*e - a*f)^2*(a + b*x)^(3/2)) - (2*(A*b^2 - a*(b*B - a*C))*(c + d*x)^(3/2)*(e + f*x)^(3/2))/(5*b*(b*c - a*d)*(b*e - a*f)*(a + b*x)^(5/2)) + (2*sqrt(d)*(48*a^4*C*d^2*f^2 - 8*a^3*b*d*f*(B*d*f + 11*C*(d*e + c*f)) - b^4*(2*A*d^2*e^2 - c*d*e*(5*B*e + 2*A*f) - c^2*(30*C*e^2 + 5*B*e*f - 2*A*f^2)) - a*b^3*(d^2*e*(3*B*e - 2*A*f) + c^2*f*(70*C*e + 3*B*f) + 2*c*d*(35*C*e^2 + 11*B*e*f - A*f^2)) + a^2*b^2*(2*C*(19*d^2*e^2 + 81*c*d*e*f + 19*c^2*f^2) - d*f*(2*A*d*f - 13*B*(d*e + c*f))))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt(e + f*x)*Elliptic.E(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f))))/(15*b^4*((-b)*c + a*d)^(3/2)*(b*e - a*f)^2*sqrt(c + d*x)*sqrt((b*(e + f*x))/(b*e - a*f))) + (2*(d*e - c*f)*(24*a^3*C*d^2*f - a^2*b*d*(23*C*d*e + 41*c*C*f + 4*B*d*f) - b^3*(15*c^2*C*e - 2*A*d^2*e + c*d*(5*B*e + A*f)) + a*b^2*(15*c^2*C*f + d^2*(3*B*e - A*f) + c*(40*C*d*e + 6*B*d*f)))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt((b*(e + f*x))/(b*e - a*f))*Elliptic.F(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f))))/(15*b^4*sqrt(d)*((-b)*c + a*d)^(3/2)*(b*e - a*f)*sqrt(c + d*x)*sqrt(e + f*x))]
    @test_int [sqrt(c + d*x)*sqrt(e + f*x)*(A + B*x + C*x^2)/(a + b*x)^(9/2), x, 10, -((1/(105*b^3*(b*c - a*d)^2*(b*e - a*f)^2*(a + b*x)^(3/2)))*(2*(24*a^4*C*d^2*f^2 - a^3*b*d*f*(61*C*d*e + 43*c*C*f - 4*B*d*f) - 3*a*b^3*(d^2*e*(B*e - 3*A*f) + 2*c^2*f*(7*C*e - B*f) + c*d*(28*C*e^2 - 5*B*e*f + 5*A*f^2)) - b^4*(4*A*d^2*e^2 - c*d*e*(7*B*e - A*f) - c^2*(35*C*e^2 - 14*B*e*f + 8*A*f^2)) - 3*a^2*b^2*(d*f*(3*B*d*e + 2*B*c*f - A*d*f) - C*(15*d^2*e^2 + 37*c*d*e*f + 5*c^2*f^2)))*sqrt(c + d*x)*sqrt(e + f*x))) + (1/(105*b^3*(b*c - a*d)^3*(b*e - a*f)^3*sqrt(a + b*x)))*(2*(48*a^5*C*d^3*f^3 + 8*a^4*b*d^2*f^2*(B*d*f - 16*C*(d*e + c*f)) - b^5*(8*A*d^3*e^3 - c*d^2*e^2*(14*B*e + 5*A*f) + c^2*d*e*(35*C*e^2 + 14*B*e*f - 5*A*f^2) + c^3*f*(35*C*e^2 - 14*B*e*f + 8*A*f^2)) - a*b^4*(d^3*e^2*(6*B*e - 19*A*f) - 6*c^3*f^2*(7*C*e - B*f) - c^2*d*f*(238*C*e^2 - 19*f*(B*e - A*f)) - c*d^2*e*(42*C*e^2 - f*(19*B*e + 20*A*f))) + a^3*b^2*d*f*(C*(103*d^2*e^2 + 344*c*d*e*f + 103*c^2*f^2) + d*f*(6*A*d*f - 19*B*(d*e + c*f))) - 3*a^2*b^3*(C*(5*d^3*e^3 + 94*c*d^2*e^2*f + 94*c^2*d*e*f^2 + 5*c^3*f^3) + d*f*(3*A*d*f*(d*e + c*f) - B*(3*d^2*e^2 + 16*c*d*e*f + 3*c^2*f^2))))*sqrt(c + d*x)*sqrt(e + f*x)) + (2*(6*a^3*C*d*f + a*b^2*(14*c*C*e + 3*B*d*e + 3*B*c*f - 8*A*d*f) - b^3*(7*B*c*e - 4*A*(d*e + c*f)) + a^2*b*(B*d*f - 10*C*(d*e + c*f)))*sqrt(c + d*x)*(e + f*x)^(3/2))/(35*b^2*(b*c - a*d)*(b*e - a*f)^2*(a + b*x)^(5/2)) - (2*(A*b^2 - a*(b*B - a*C))*(c + d*x)^(3/2)*(e + f*x)^(3/2))/(7*b*(b*c - a*d)*(b*e - a*f)*(a + b*x)^(7/2)) + (2*sqrt(d)*(48*a^5*C*d^3*f^3 + 8*a^4*b*d^2*f^2*(B*d*f - 16*C*(d*e + c*f)) - b^5*(8*A*d^3*e^3 - c*d^2*e^2*(14*B*e + 5*A*f) + c^2*d*e*(35*C*e^2 + 14*B*e*f - 5*A*f^2) + c^3*f*(35*C*e^2 - 14*B*e*f + 8*A*f^2)) - a*b^4*(d^3*e^2*(6*B*e - 19*A*f) - 6*c^3*f^2*(7*C*e - B*f) - c^2*d*f*(238*C*e^2 - 19*f*(B*e - A*f)) - c*d^2*e*(42*C*e^2 - f*(19*B*e + 20*A*f))) + a^3*b^2*d*f*(C*(103*d^2*e^2 + 344*c*d*e*f + 103*c^2*f^2) + d*f*(6*A*d*f - 19*B*(d*e + c*f))) - 3*a^2*b^3*(C*(5*d^3*e^3 + 94*c*d^2*e^2*f + 94*c^2*d*e*f^2 + 5*c^3*f^3) + d*f*(3*A*d*f*(d*e + c*f) - B*(3*d^2*e^2 + 16*c*d*e*f + 3*c^2*f^2))))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt(e + f*x)*Elliptic.E(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f))))/(105*b^4*((-b)*c + a*d)^(5/2)*(b*e - a*f)^3*sqrt(c + d*x)*sqrt((b*(e + f*x))/(b*e - a*f))) + (1/(105*b^4*((-b)*c + a*d)^(5/2)*(b*e - a*f)^2*sqrt(c + d*x)*sqrt(e + f*x)))*(2*sqrt(d)*(d*e - c*f)*(24*a^4*C*d^2*f^2 - a^3*b*d*f*(43*C*d*e + 61*c*C*f - 4*B*d*f) + b^4*(8*A*d^2*e^2 - c*d*e*(14*B*e + A*f) + c^2*(35*C*e^2 + 7*B*e*f - 4*A*f^2)) + 3*a*b^3*(d^2*e*(2*B*e - 5*A*f) - c^2*f*(28*C*e + B*f) - c*d*(14*C*e^2 - 5*B*e*f - 3*A*f^2)) - 3*a^2*b^2*(d*f*(2*B*d*e + 3*B*c*f - A*d*f) - C*(5*d^2*e^2 + 37*c*d*e*f + 15*c^2*f^2)))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt((b*(e + f*x))/(b*e - a*f))*Elliptic.F(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f))))]

    #= ::Subsubsection::Closed:: =#
    #=n>0 & p<0=#

    @test_int [(a + b*x)^(3/2)*sqrt(c + d*x)*(A + B*x + C*x^2)/sqrt(e + f*x), x, 10, -((1/(945*b^2*d^3*f^4))*(2*(5*b*d*f*(7*a*d*f*(5*b*c*C*e + 3*a*C*d*e + a*c*C*f - 9*A*b*d*f) - (3*b*c*e + 3*a*d*e + a*c*f)*(4*a*C*d*f + b*(8*C*d*e + 6*c*C*f - 9*B*d*f))) + 2*((a*d*f)/2 - b*(2*d*e + c*f))*(7*b*d*f*(5*b*c*C*e + 3*a*C*d*e + a*c*C*f - 9*A*b*d*f) - (6*b*d*e + 4*b*c*f - 3*a*d*f)*(4*a*C*d*f + b*(8*C*d*e + 6*c*C*f - 9*B*d*f))))*sqrt(a + b*x)*sqrt(c + d*x)*sqrt(e + f*x))) - (2*(7*b*d*f*(5*b*c*C*e + 3*a*C*d*e + a*c*C*f - 9*A*b*d*f) - (6*b*d*e + 4*b*c*f - 3*a*d*f)*(4*a*C*d*f + b*(8*C*d*e + 6*c*C*f - 9*B*d*f)))*sqrt(a + b*x)*(c + d*x)^(3/2)*sqrt(e + f*x))/(315*b*d^3*f^3) - (2*(4*a*C*d*f + b*(8*C*d*e + 6*c*C*f - 9*B*d*f))*(a + b*x)^(3/2)*(c + d*x)^(3/2)*sqrt(e + f*x))/(63*b*d^2*f^2) + (2*C*(a + b*x)^(5/2)*(c + d*x)^(3/2)*sqrt(e + f*x))/(9*b*d*f) + (1/(315*b^3*d^(7/2)*f^5*sqrt(c + d*x)*sqrt((b*(e + f*x))/(b*e - a*f))))*(2*sqrt((-b)*c + a*d)*(8*a^4*C*d^4*f^4 + a^3*b*d^3*f^3*(11*C*d*e - 7*c*C*f - 18*B*d*f) - 3*a^2*b^2*d^2*f^2*(3*d*f*(4*B*d*e - 3*B*c*f - 7*A*d*f) - C*(9*d^2*e^2 - 5*c*d*e*f - 3*c^2*f^2)) - a*b^3*d*f*(2*C*(92*d^3*e^3 - 33*c*d^2*e^2*f - 18*c^2*d*e*f^2 - 16*c^3*f^3) + 3*d*f*(7*A*d*f*(13*d*e - 7*c*f) - B*(72*d^2*e^2 - 29*c*d*e*f - 19*c^2*f^2))) + b^4*(C*(128*d^4*e^4 - 40*c*d^3*e^3*f - 21*c^2*d^2*e^2*f^2 - 16*c^3*d*e*f^3 - 16*c^4*f^4) + 3*d*f*(7*A*d*f*(8*d^2*e^2 - 3*c*d*e*f - 2*c^2*f^2) - B*(48*d^3*e^3 - 16*c*d^2*e^2*f - 9*c^2*d*e*f^2 - 8*c^3*f^3))))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt(e + f*x)*Elliptic.E(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f)))) + (1/(315*b^3*d^(7/2)*f^5*sqrt(c + d*x)*sqrt(e + f*x)))*(2*sqrt((-b)*c + a*d)*(b*e - a*f)*(d*e - c*f)*(4*a^3*C*d^3*f^3 + 3*a^2*b*d^2*f^2*(3*C*d*e - c*C*f - 3*B*d*f) - 3*a*b^2*d*f*(3*d*f*(16*B*d*e + 3*B*c*f - 21*A*d*f) - 5*C*(8*d^2*e^2 + 2*c*d*e*f + c^2*f^2)) - b^3*(C*(128*d^3*e^3 + 24*c*d^2*e^2*f + 15*c^2*d*e*f^2 + 8*c^3*f^3) + 3*d*f*(7*A*d*f*(8*d*e + c*f) - 4*B*(12*d^2*e^2 + 2*c*d*e*f + c^2*f^2))))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt((b*(e + f*x))/(b*e - a*f))*Elliptic.F(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f))))]
    @test_int [(a + b*x)^(1/2)*sqrt(c + d*x)*(A + B*x + C*x^2)/sqrt(e + f*x), x, 9, -((2*(5*b*d*f*(3*b*c*C*e + 3*a*C*d*e + a*c*C*f - 7*A*b*d*f) + (a*d*f - 2*b*(2*d*e + c*f))*(4*a*C*d*f + b*(6*C*d*e + 4*c*C*f - 7*B*d*f)))*sqrt(a + b*x)*sqrt(c + d*x)*sqrt(e + f*x))/(105*b^2*d^2*f^3)) - (2*(4*a*C*d*f + b*(6*C*d*e + 4*c*C*f - 7*B*d*f))*sqrt(a + b*x)*(c + d*x)^(3/2)*sqrt(e + f*x))/(35*b*d^2*f^2) + (2*C*(a + b*x)^(3/2)*(c + d*x)^(3/2)*sqrt(e + f*x))/(7*b*d*f) - (1/(105*b^3*d^(5/2)*f^4*sqrt(c + d*x)*sqrt((b*(e + f*x))/(b*e - a*f))))*(2*sqrt((-b)*c + a*d)*(3*b*d*f*(5*a*d*f*(3*b*c*C*e + 3*a*C*d*e + a*c*C*f - 7*A*b*d*f) - (b*c*e + 3*a*d*e + a*c*f)*(4*a*C*d*f + b*(6*C*d*e + 4*c*C*f - 7*B*d*f))) + 2*((b*c*f)/2 - d*(b*e + a*f))*(5*b*d*f*(3*b*c*C*e + 3*a*C*d*e + a*c*C*f - 7*A*b*d*f) + (a*d*f - 2*b*(2*d*e + c*f))*(4*a*C*d*f + b*(6*C*d*e + 4*c*C*f - 7*B*d*f))))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt(e + f*x)*Elliptic.E(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f)))) + (1/(105*b^3*d^(5/2)*f^4*sqrt(c + d*x)*sqrt(e + f*x)))*(2*sqrt((-b)*c + a*d)*(b*e - a*f)*(d*e - c*f)*(4*a^2*C*d^2*f^2 + a*b*d*f*(8*C*d*e - 2*c*C*f - 7*B*d*f) - b^2*(7*d*f*(8*B*d*e + B*c*f - 10*A*d*f) - 4*C*(12*d^2*e^2 + 2*c*d*e*f + c^2*f^2)))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt((b*(e + f*x))/(b*e - a*f))*Elliptic.F(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f))))]
    @test_int [sqrt(c + d*x)*(A + B*x + C*x^2)/((a + b*x)^(1/2)*sqrt(e + f*x)), x, 8, -((2*(4*a*C*d*f + b*(4*C*d*e + 2*c*C*f - 5*B*d*f))*sqrt(a + b*x)*sqrt(c + d*x)*sqrt(e + f*x))/(15*b^2*d*f^2)) + (2*C*sqrt(a + b*x)*(c + d*x)^(3/2)*sqrt(e + f*x))/(5*b*d*f) - (1/(15*b^3*d^(3/2)*f^3*sqrt(c + d*x)*sqrt((b*(e + f*x))/(b*e - a*f))))*(2*sqrt((-b)*c + a*d)*(3*b*d*f*(b*c*C*e + 3*a*C*d*e + a*c*C*f - 5*A*b*d*f) - (2*b*d*e - b*c*f + 2*a*d*f)*(4*a*C*d*f + b*(4*C*d*e + 2*c*C*f - 5*B*d*f)))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt(e + f*x)*Elliptic.E(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f)))) - (2*sqrt((-b)*c + a*d)*(d*e - c*f)*(4*a^2*C*d*f^2 + a*b*f*(3*C*d*e - c*C*f - 5*B*d*f) - b^2*(5*d*f*(2*B*e - 3*A*f) - C*e*(8*d*e + c*f)))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt((b*(e + f*x))/(b*e - a*f))*Elliptic.F(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f))))/(15*b^3*d^(3/2)*f^3*sqrt(c + d*x)*sqrt(e + f*x))]
    @test_int [sqrt(c + d*x)*(A + B*x + C*x^2)/((a + b*x)^(3/2)*sqrt(e + f*x)), x, 8, (2*(4*a^2*C*d*f + b^2*(c*C*e + 3*A*d*f) - a*b*(C*d*e + c*C*f + 3*B*d*f))*sqrt(a + b*x)*sqrt(c + d*x)*sqrt(e + f*x))/(3*b^2*(b*c - a*d)*f*(b*e - a*f)) - (2*(A*b^2 - a*(b*B - a*C))*(c + d*x)^(3/2)*sqrt(e + f*x))/(b*(b*c - a*d)*(b*e - a*f)*sqrt(a + b*x)) + (2*sqrt((-b)*c + a*d)*(8*a^2*C*d*f^2 - a*b*f*(3*C*d*e + c*C*f + 6*B*d*f) + b^2*(3*d*f*(B*e + A*f) - C*e*(2*d*e - c*f)))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt(e + f*x)*Elliptic.E(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f))))/(3*b^3*sqrt(d)*f^2*(b*e - a*f)*sqrt(c + d*x)*sqrt((b*(e + f*x))/(b*e - a*f))) + (2*sqrt((-b)*c + a*d)*(d*e - c*f)*(2*b*C*e - 3*b*B*f + 4*a*C*f)*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt((b*(e + f*x))/(b*e - a*f))*Elliptic.F(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f))))/(3*b^3*sqrt(d)*f^2*sqrt(c + d*x)*sqrt(e + f*x))]
    @test_int [sqrt(c + d*x)*(A + B*x + C*x^2)/((a + b*x)^(5/2)*sqrt(e + f*x)), x, 8, -((2*(4*a^2*C*f + b^2*(3*B*e - 2*A*f) - a*b*(6*C*e + B*f))*sqrt(c + d*x)*sqrt(e + f*x))/(3*b^2*(b*e - a*f)^2*sqrt(a + b*x))) - (2*(A*b^2 - a*(b*B - a*C))*(c + d*x)^(3/2)*sqrt(e + f*x))/(3*b*(b*c - a*d)*(b*e - a*f)*(a + b*x)^(3/2)) + (2*sqrt(d)*(8*a^3*C*d*f^2 - a^2*b*f*(13*C*d*e + 7*c*C*f + 2*B*d*f) + a*b^2*(3*C*e*(d*e + 4*c*f) + f*(4*B*d*e + B*c*f - A*d*f)) - b^3*(A*d*e*f + c*(3*C*e^2 + 3*B*e*f - 2*A*f^2)))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt(e + f*x)*Elliptic.E(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f))))/(3*b^3*sqrt((-b)*c + a*d)*f*(b*e - a*f)^2*sqrt(c + d*x)*sqrt((b*(e + f*x))/(b*e - a*f))) + (2*(d*e - c*f)*(4*a^2*C*d*f + b^2*(3*c*C*e + A*d*f) - a*b*(B*d*f + 3*C*(d*e + c*f)))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt((b*(e + f*x))/(b*e - a*f))*Elliptic.F(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f))))/(3*b^3*sqrt(d)*sqrt((-b)*c + a*d)*f*(b*e - a*f)*sqrt(c + d*x)*sqrt(e + f*x))]
    @test_int [sqrt(c + d*x)*(A + B*x + C*x^2)/((a + b*x)^(7/2)*sqrt(e + f*x)), x, 9, (2*(4*a^3*C*d*f - b^3*(5*B*c*e - 2*A*d*e - 4*A*c*f) + a*b^2*(10*c*C*e + 3*B*d*e + B*c*f - 6*A*d*f) - a^2*b*(8*C*d*e + 6*c*C*f - B*d*f))*sqrt(c + d*x)*sqrt(e + f*x))/(15*b^2*(b*c - a*d)*(b*e - a*f)^2*(a + b*x)^(3/2)) - (1/(15*b^2*(b*c - a*d)^2*(b*e - a*f)^3*sqrt(a + b*x)))*(2*(8*a^4*C*d^2*f^2 - a^3*b*d*f*(23*C*d*e + 13*c*C*f - 2*B*d*f) - b^4*(2*A*d^2*e^2 - c*d*e*(5*B*e - 3*A*f) - c^2*(15*C*e^2 - 10*B*e*f + 8*A*f^2)) - a^2*b^2*(d*f*(7*B*d*e + 2*B*c*f - 3*A*d*f) - C*(23*d^2*e^2 + 37*c*d*e*f + 3*c^2*f^2)) - a*b^3*(d^2*e*(3*B*e - 7*A*f) + 2*c^2*f*(5*C*e - B*f) + c*d*(40*C*e^2 - 13*f*(B*e - A*f))))*sqrt(c + d*x)*sqrt(e + f*x)) - (2*(A*b^2 - a*(b*B - a*C))*(c + d*x)^(3/2)*sqrt(e + f*x))/(5*b*(b*c - a*d)*(b*e - a*f)*(a + b*x)^(5/2)) + (2*sqrt(d)*(8*a^4*C*d^2*f^2 - a^3*b*d*f*(23*C*d*e + 13*c*C*f - 2*B*d*f) - b^4*(2*A*d^2*e^2 - c*d*e*(5*B*e - 3*A*f) - c^2*(15*C*e^2 - 10*B*e*f + 8*A*f^2)) - a^2*b^2*(d*f*(7*B*d*e + 2*B*c*f - 3*A*d*f) - C*(23*d^2*e^2 + 37*c*d*e*f + 3*c^2*f^2)) - a*b^3*(d^2*e*(3*B*e - 7*A*f) + 2*c^2*f*(5*C*e - B*f) + c*d*(40*C*e^2 - 13*f*(B*e - A*f))))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt(e + f*x)*Elliptic.E(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f))))/(15*b^3*((-b)*c + a*d)^(3/2)*(b*e - a*f)^3*sqrt(c + d*x)*sqrt((b*(e + f*x))/(b*e - a*f))) + (2*sqrt(d)*(d*e - c*f)*(4*a^3*C*d*f - b^3*(5*B*c*e - 2*A*d*e - 4*A*c*f) + a*b^2*(10*c*C*e + 3*B*d*e + B*c*f - 6*A*d*f) - a^2*b*(8*C*d*e + 6*c*C*f - B*d*f))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt((b*(e + f*x))/(b*e - a*f))*Elliptic.F(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f))))/(15*b^3*((-b)*c + a*d)^(3/2)*(b*e - a*f)^2*sqrt(c + d*x)*sqrt(e + f*x))]

    #= ::Subsubsection::Closed:: =#
    #=n<0 & p<0=#

    @test_int [(a + b*x)^(3/2)*(A + B*x + C*x^2)/(sqrt(c + d*x)*sqrt(e + f*x)), x, 9, -((2*(5*b*d*f*(5*b*c*C*e + a*C*d*e + a*c*C*f - 7*A*b*d*f) + (3*a*d*f - 4*b*(d*e + c*f))*(2*a*C*d*f - b*(7*B*d*f - 6*C*(d*e + c*f))))*sqrt(a + b*x)*sqrt(c + d*x)*sqrt(e + f*x))/(105*b*d^3*f^3)) - (2*(2*a*C*d*f - b*(7*B*d*f - 6*C*(d*e + c*f)))*(a + b*x)^(3/2)*sqrt(c + d*x)*sqrt(e + f*x))/(35*b*d^2*f^2) + (2*C*(a + b*x)^(5/2)*sqrt(c + d*x)*sqrt(e + f*x))/(7*b*d*f) - (1/(105*b^2*d^(7/2)*f^4*sqrt(c + d*x)*sqrt((b*(e + f*x))/(b*e - a*f))))*(2*sqrt((-b)*c + a*d)*(3*b*d*f*(5*a*d*f*(5*b*c*C*e + a*C*d*e + a*c*C*f - 7*A*b*d*f) - (3*b*c*e + a*d*e + a*c*f)*(2*a*C*d*f - b*(7*B*d*f - 6*C*(d*e + c*f)))) + 2*((a*d*f)/2 - b*(d*e + c*f))*(5*b*d*f*(5*b*c*C*e + a*C*d*e + a*c*C*f - 7*A*b*d*f) + (3*a*d*f - 4*b*(d*e + c*f))*(2*a*C*d*f - b*(7*B*d*f - 6*C*(d*e + c*f)))))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt(e + f*x)*Elliptic.E(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f)))) - (1/(105*b^2*d^(7/2)*f^4*sqrt(c + d*x)*sqrt(e + f*x)))*(2*sqrt((-b)*c + a*d)*(b*e - a*f)*(3*a^2*C*d^2*f^2*(d*e - c*f) - 3*a*b*d*f*(7*d*f*(3*B*d*e + 2*B*c*f - 5*A*d*f) - C*(16*d^2*e^2 + 8*c*d*e*f + 11*c^2*f^2)) - b^2*(C*(48*d^3*e^3 + 16*c*d^2*e^2*f + 17*c^2*d*e*f^2 + 24*c^3*f^3) + 7*d*f*(5*A*d*f*(2*d*e + c*f) - B*(8*d^2*e^2 + 3*c*d*e*f + 4*c^2*f^2))))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt((b*(e + f*x))/(b*e - a*f))*Elliptic.F(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f))))]
    @test_int [(a + b*x)^(1/2)*(A + B*x + C*x^2)/(sqrt(c + d*x)*sqrt(e + f*x)), x, 8, -((2*(2*a*C*d*f - b*(5*B*d*f - 4*C*(d*e + c*f)))*sqrt(a + b*x)*sqrt(c + d*x)*sqrt(e + f*x))/(15*b*d^2*f^2)) + (2*C*(a + b*x)^(3/2)*sqrt(c + d*x)*sqrt(e + f*x))/(5*b*d*f) - (1/(15*b^2*d^(5/2)*f^3*sqrt(c + d*x)*sqrt((b*(e + f*x))/(b*e - a*f))))*(2*sqrt((-b)*c + a*d)*(3*b*d*f*(3*b*c*C*e + a*C*d*e + a*c*C*f - 5*A*b*d*f) + (a*d*f - 2*b*(d*e + c*f))*(2*a*C*d*f - b*(5*B*d*f - 4*C*(d*e + c*f))))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt(e + f*x)*Elliptic.E(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f)))) - (2*sqrt((-b)*c + a*d)*(b*e - a*f)*(a*C*d*f*(d*e - c*f) - b*(5*d*f*(2*B*d*e + B*c*f - 3*A*d*f) - C*(8*d^2*e^2 + 3*c*d*e*f + 4*c^2*f^2)))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt((b*(e + f*x))/(b*e - a*f))*Elliptic.F(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f))))/(15*b^2*d^(5/2)*f^3*sqrt(c + d*x)*sqrt(e + f*x))]
    @test_int [(A + B*x + C*x^2)/((a + b*x)^(1/2)*sqrt(c + d*x)*sqrt(e + f*x)), x, 7, (2*C*sqrt(a + b*x)*sqrt(c + d*x)*sqrt(e + f*x))/(3*b*d*f) - (2*sqrt((-b)*c + a*d)*(2*a*C*d*f - b*(3*B*d*f - 2*C*(d*e + c*f)))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt(e + f*x)*Elliptic.E(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f))))/(3*b^2*d^(3/2)*f^2*sqrt(c + d*x)*sqrt((b*(e + f*x))/(b*e - a*f))) + (2*sqrt((-b)*c + a*d)*(a*C*f*(d*e - c*f) - b*(3*d*f*(B*e - A*f) - C*e*(2*d*e + c*f)))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt((b*(e + f*x))/(b*e - a*f))*Elliptic.F(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f))))/(3*b^2*d^(3/2)*f^2*sqrt(c + d*x)*sqrt(e + f*x))]
    @test_int [(A + B*x + C*x^2)/((a + b*x)^(3/2)*sqrt(c + d*x)*sqrt(e + f*x)), x, 7, -((2*(A*b^2 - a*(b*B - a*C))*sqrt(c + d*x)*sqrt(e + f*x))/(b*(b*c - a*d)*(b*e - a*f)*sqrt(a + b*x))) - (2*(2*a^2*C*d*f + b^2*(c*C*e + A*d*f) - a*b*(C*d*e + c*C*f + B*d*f))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt(e + f*x)*Elliptic.E(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f))))/(b^2*sqrt(d)*sqrt((-b)*c + a*d)*f*(b*e - a*f)*sqrt(c + d*x)*sqrt((b*(e + f*x))/(b*e - a*f))) - (2*(a*C*(d*e - c*f) - b*(c*C*e - B*c*f + A*d*f))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt((b*(e + f*x))/(b*e - a*f))*Elliptic.F(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f))))/(b^2*sqrt(d)*sqrt((-b)*c + a*d)*f*sqrt(c + d*x)*sqrt(e + f*x))]
    @test_int [(A + B*x + C*x^2)/((a + b*x)^(5/2)*sqrt(c + d*x)*sqrt(e + f*x)), x, 8, -((2*(A*b^2 - a*(b*B - a*C))*sqrt(c + d*x)*sqrt(e + f*x))/(3*b*(b*c - a*d)*(b*e - a*f)*(a + b*x)^(3/2))) + (2*(2*a^3*C*d*f + a*b^2*(6*c*C*e + B*d*e + B*c*f - 4*A*d*f) - b^3*(3*B*c*e - 2*A*(d*e + c*f)) + a^2*b*(B*d*f - 4*C*(d*e + c*f)))*sqrt(c + d*x)*sqrt(e + f*x))/(3*b*(b*c - a*d)^2*(b*e - a*f)^2*sqrt(a + b*x)) - (2*sqrt(d)*(2*a^3*C*d*f + a*b^2*(6*c*C*e + B*d*e + B*c*f - 4*A*d*f) - b^3*(3*B*c*e - 2*A*(d*e + c*f)) + a^2*b*(B*d*f - 4*C*(d*e + c*f)))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt(e + f*x)*Elliptic.E(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f))))/(3*b^2*((-b)*c + a*d)^(3/2)*(b*e - a*f)^2*sqrt(c + d*x)*sqrt((b*(e + f*x))/(b*e - a*f))) - (2*(a^2*C*d*(d*e - c*f) - b^2*(3*c^2*C*e - 3*B*c*d*e + 2*A*d^2*e + A*c*d*f) + a*b*(3*(c^2*C + A*d^2)*f - B*d*(d*e + 2*c*f)))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt((b*(e + f*x))/(b*e - a*f))*Elliptic.F(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f))))/(3*b^2*sqrt(d)*((-b)*c + a*d)^(3/2)*(b*e - a*f)*sqrt(c + d*x)*sqrt(e + f*x))]
    @test_int [(A + B*x + C*x^2)/((a + b*x)^(7/2)*sqrt(c + d*x)*sqrt(e + f*x)), x, 9, -((2*(A*b^2 - a*(b*B - a*C))*sqrt(c + d*x)*sqrt(e + f*x))/(5*b*(b*c - a*d)*(b*e - a*f)*(a + b*x)^(5/2))) + (2*(2*a^3*C*d*f + a*b^2*(10*c*C*e + B*d*e + B*c*f - 8*A*d*f) - b^3*(5*B*c*e - 4*A*(d*e + c*f)) + 3*a^2*b*(B*d*f - 2*C*(d*e + c*f)))*sqrt(c + d*x)*sqrt(e + f*x))/(15*b*(b*c - a*d)^2*(b*e - a*f)^2*(a + b*x)^(3/2)) + (1/(15*b*(b*c - a*d)^3*(b*e - a*f)^3*sqrt(a + b*x)))*(2*(2*a^4*C*d^2*f^2 + a^3*b*d*f*(3*B*d*f - 7*C*(d*e + c*f)) - b^4*(8*A*d^2*e^2 - c*d*e*(10*B*e - 7*A*f) + c^2*(15*C*e^2 - 10*B*e*f + 8*A*f^2)) - a*b^3*(d^2*e*(2*B*e - 23*A*f) - 2*c^2*f*(5*C*e - B*f) - c*d*(10*C*e^2 - 33*B*e*f + 23*A*f^2)) - a^2*b^2*(C*(3*d^2*e^2 - 13*c*d*e*f + 3*c^2*f^2) + d*f*(23*A*d*f - 7*B*(d*e + c*f))))*sqrt(c + d*x)*sqrt(e + f*x)) + (2*sqrt(d)*(2*a^4*C*d^2*f^2 + a^3*b*d*f*(3*B*d*f - 7*C*(d*e + c*f)) - b^4*(8*A*d^2*e^2 - c*d*e*(10*B*e - 7*A*f) + c^2*(15*C*e^2 - 10*B*e*f + 8*A*f^2)) - a*b^3*(d^2*e*(2*B*e - 23*A*f) - 2*c^2*f*(5*C*e - B*f) - c*d*(10*C*e^2 - 33*B*e*f + 23*A*f^2)) - a^2*b^2*(C*(3*d^2*e^2 - 13*c*d*e*f + 3*c^2*f^2) + d*f*(23*A*d*f - 7*B*(d*e + c*f))))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt(e + f*x)*Elliptic.E(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f))))/(15*b^2*((-b)*c + a*d)^(5/2)*(b*e - a*f)^3*sqrt(c + d*x)*sqrt((b*(e + f*x))/(b*e - a*f))) + (1/(15*b^2*((-b)*c + a*d)^(5/2)*(b*e - a*f)^2*sqrt(c + d*x)*sqrt(e + f*x)))*(2*sqrt(d)*(a^3*C*d*f*(d*e - c*f) + b^3*(8*A*d^2*e^2 - c*d*e*(10*B*e - 3*A*f) + c^2*(15*C*e^2 - 5*B*e*f + 4*A*f^2)) + a*b^2*(d^2*e*(2*B*e - 19*A*f) - c^2*f*(20*C*e - B*f) - c*d*(10*C*e^2 - 27*B*e*f + 11*A*f^2)) - 3*a^2*b*(d*f*(2*B*d*e + 3*B*c*f - 5*A*d*f) - C*(d^2*e^2 + c*d*e*f + 3*c^2*f^2)))*sqrt((b*(c + d*x))/(b*c - a*d))*sqrt((b*(e + f*x))/(b*e - a*f))*Elliptic.F(asin((sqrt(d)*sqrt(a + b*x))/sqrt((-b)*c + a*d)), ((b*c - a*d)*f)/(d*(b*e - a*f))))]
    end

max_stars_repo_path: test/1 Algebraic functions/1.1 Binomial products/1.1.1 Linear/1.1.1.6 P(x) (a+b x)^m (c+d x)^n (e+f x)^p.jl


text:
export
    SDPWRMPowerModel, SDPWRMForm

""
abstract type AbstractWRMForm <: AbstractConicPowerFormulation end

""
abstract type SDPWRMForm <: AbstractWRMForm end

""
const SDPWRMPowerModel = GenericPowerModel{SDPWRMForm}

""
SDPWRMPowerModel(data::Dict{String,Any}; kwargs...) = GenericPowerModel(data, SDPWRMForm; kwargs...)

""
function variable_voltage(pm::GenericPowerModel{T}, n::Int=pm.cnw; bounded = true) where T <: AbstractWRMForm
    wr_min, wr_max, wi_min, wi_max = calc_voltage_product_bounds(pm.ref[:nw][n][:buspairs])

    w_index = 1:length(keys(pm.ref[:nw][n][:bus]))
    lookup_w_index = Dict([(bi,i) for (i,bi) in enumerate(keys(pm.ref[:nw][n][:bus]))])

    WR = pm.var[:nw][n][:WR] = @variable(pm.model,
        [1:length(keys(pm.ref[:nw][n][:bus])), 1:length(keys(pm.ref[:nw][n][:bus]))], Symmetric, basename="$(n)_WR"
    )
    WI = pm.var[:nw][n][:WI] = @variable(pm.model,
        [1:length(keys(pm.ref[:nw][n][:bus])), 1:length(keys(pm.ref[:nw][n][:bus]))], basename="$(n)_WI"
    )

    # bounds on diagonal
    for (i, bus) in pm.ref[:nw][n][:bus]
        w_idx = lookup_w_index[i]
        wr_ii = WR[w_idx,w_idx]
        wi_ii = WR[w_idx,w_idx]

        if bounded
            setlowerbound(wr_ii, bus["vmin"]^2)
            setupperbound(wr_ii, bus["vmax"]^2)

            #this breaks SCS on the 3 bus exmple
            #setlowerbound(wi_ii, 0)
            #setupperbound(wi_ii, 0)
        else
             setlowerbound(wr_ii, 0)
        end
    end

    # bounds on off-diagonal
    for (i,j) in keys(pm.ref[:nw][n][:buspairs])
        wi_idx = lookup_w_index[i]
        wj_idx = lookup_w_index[j]

        if bounded
            setupperbound(WR[wi_idx, wj_idx], wr_max[(i,j)])
            setlowerbound(WR[wi_idx, wj_idx], wr_min[(i,j)])

            setupperbound(WI[wi_idx, wj_idx], wi_max[(i,j)])
            setlowerbound(WI[wi_idx, wj_idx], wi_min[(i,j)])
        end
    end

    pm.var[:nw][n][:w] = Dict{Int,Any}()
    for (i, bus) in pm.ref[:nw][n][:bus]
        w_idx = lookup_w_index[i]
        pm.var[:nw][n][:w][i] = WR[w_idx,w_idx]
    end

    pm.var[:nw][n][:wr] = Dict{Tuple{Int,Int},Any}()
    pm.var[:nw][n][:wi] = Dict{Tuple{Int,Int},Any}()
    for (i,j) in keys(pm.ref[:nw][n][:buspairs])
        w_fr_index = lookup_w_index[i]
        w_to_index = lookup_w_index[j]

        pm.var[:nw][n][:wr][(i,j)] = WR[w_fr_index, w_to_index]
        pm.var[:nw][n][:wi][(i,j)] = WI[w_fr_index, w_to_index]
    end

end

""
function constraint_voltage(pm::GenericPowerModel{T}, n::Int) where T <: AbstractWRMForm
    WR = pm.var[:nw][n][:WR]
    WI = pm.var[:nw][n][:WI]

    @SDconstraint(pm.model, [WR WI; -WI WR] >= 0)

    # place holder while debugging sdp constraint
    #for (i,j) in keys(pm.ref[:nw][n][:buspairs])
    #    relaxation_complex_product(pm.model, w[i], w[j], wr[(i,j)], wi[(i,j)])
    #end
end

ext: jl


text:
abstract type Clause end
abstract type Formula end
abstract type Relation end

struct RelType <: Relation
   relname::String
end

struct Predicate <: Relation
   relname::String
   uc_id::String
   key_role_seq::Vector{String}
   value_role_seq::Vector{String}

   Predicate(r::String, uc::String, key::String, value::String) =
      new(r, uc, [key], [value])
   Predicate(r::String, uc::String, kseq::Vector{String}, value::String) =
      new(r, uc, kseq, [value])
   Predicate(r::String, uc::String, kseq::Vector{String}, vseq::Vector{String}) =
      new(r, uc, kseq, vseq)
end

role_seq(r::Predicate) = vcat( r.key_role_seq , r.value_role_seq )

struct IsFunctional <: Formula
   rel::Relation
end

struct RelAtom <: Formula
   rel::Relation
   params::Vector{String}

   RelAtom(r::Relation, p::String) = new(r, [p])
   RelAtom(r::Relation, p::Vector{String}) = new(r, p)
end

struct Conjunction <: Formula
   conjuncts::Vector{Formula}
end

struct Implication <: Formula
   antecedent::Formula
   consequent::Formula
end

struct IC <: Clause
   name::String
   head::Vector{String}
   body::Formula

   IC(n::String, b::Formula) = new(n, Vector{String}(), b)
   IC(n::String, var::String, b::Formula) = new(n, [var], b)
   IC(n::String, vars::Vector{String}, b::Formula) = new(n, vars, b)
end

struct Unsupported <: Clause
   error_message::String
end

conjunction(xs...)::String = join(xs, " and ")

emit(a::RelAtom) = "$(a.rel.relname)($(paramSeq(a.params)))"
emit(i::Implication) = emit(i.antecedent) * " implies " * emit(i.consequent)
emit(c::Conjunction) = conjunction((c.conjuncts .|> f -> emit(f))...)
emit(f::IsFunctional) = "function($(f.rel.relname))"

function emit(ic::IC)
   name = size(ic.head)[1] > 0 ? "$(ic.name)($(paramSeq(ic.head)))" : "$(ic.name)"
   "ic $name { $(emit(ic.body)) }"
end

emit(un::Unsupported) = "// Error: " * un.error_message

function paramSeq(params::Vector{String})
   @assert(size(params,1) > 0, "Cannot currently emit code for relations with no columns")
   reduce(spliceWithComma, params .|> string)
end

spliceWith(x::String, y::String, c::String)::String = x * c * y
spliceWithComma(x::String, y::String)::String = spliceWith(x, y, ", ")

"""
   Generates a sequence of variable names
"""
fresh_variables(num) = 1:num .|>  (n -> "v$(n)")

"""
Creates an atom that binds only the given role of Predicate rel
   with the given variable, existentially quantifying over all
   other roles
"""
function bind_role_to(rel::Predicate, role_id::String, var::String)::RelAtom
   key_bindings = rel.key_role_seq .|> r -> r == role_id ? var : "_"
   val_bindings = rel.value_role_seq .|> r -> r == role_id ? var : "_"
   RelAtom(rel, vcat(key_bindings, val_bindings))
end

"""
Finds first occurrence of any role from role_set in the
   role sequence of Predicate rel
"""
function first_occurrence_from(role_set::Vector{String}, rel::Predicate)
   for role_id in role_seq(rel)
      if findfirst((id -> id === role_id), role_set) !== nothing
         return role_id
      end
   end
end

pascal_case_pattern = r"(?<word>^[A-Z][^A-Z]*)"

function pascal_to_snake_case(s)::String
   word_match = match(pascal_case_pattern, s)
   if word_match === nothing
      println("[Error] Expected string '" * s * "' to be in PascalCase")
      return nothing
   else
      word = lowercase(word_match[:word])
      remainder = SubString(s, length(word) + 1, length(s))
      if remainder != ""
         return word * "_" * pascal_to_snake_case(remainder)
      else
         return word
      end
   end
end

max_stars_repo_name: RelationalAI-oss/kse-tools

max_issues_repo_name: RelationalAI-oss/kse-tools

max_forks_repo_name: RelationalAI-oss/kse-tools


text:
function get_decision(d1::UInt8, d2::UInt8, i::UInt8, j::UInt8)
    to_return_1, to_return_2 = 0x08, 0x08
    for n = 0x00:0x06
        to_return_1 -= isodd(d1 >> n) &&
            Base.ctpop_int(d1 >> n) == i ? 0x07 - n : 0x00
        to_return_2 -= isodd(d2 >> n) &&
            Base.ctpop_int(d2 >> n) == j ? 0x07 - n : 0x00
    end
    return to_return_1, to_return_2
end

function get_decision(d::UInt8, i::UInt8)
    to_return = 0x08
    for n = 0x00:0x06
        to_return -= isodd(d >> n) &&
            Base.ctpop_int(d >> n) == i ? 0x07 - n : 0x00
    end
    return to_return
end

function is_possible(decisions::UInt8, decision::UInt8)
    for i = 0x01:Base.ctpop_int(decisions)
        get_decision(decisions, i) == decision && return true
    end
    return false
end

function select_random_decision(d1::UInt8, d2::UInt8)
    return get_decision(d1, d2,
        rand(0x01:Base.ctpop_int(d1)), rand(0x01:Base.ctpop_int(d2)))
end

function get_possible_decisions(state::DynamicState, static_state::StaticState;
    allow_nothing::Bool = false, allow_overfarming::Bool = false)
    # 00000001 - shield
    # 00000010 - nothing
    # 00000100 - fast move
    # 00001000 - charged move
    # 00010000 - switch 1
    # 00100000 - switch 2
    # 01000000 - charged move 1
    # 10000000 - charged move 2

    active = get_active(state)
    fast_moves_pending = get_fast_moves_pending(state)
    cmp = get_cmp(state)

    if isodd(cmp) # if team 1 is using a charged move and has cmp
        return (get_energy(state[0x01][active[1]]) >=
            static_state[0x01][active[1]].charged_move_2.energy ? 0xc0 : 0x40,
            has_shield(state[0x02]) ? 0x03 : 0x02)
    elseif !iszero(cmp) # if team 2 is using a charged move and has cmp
        return (has_shield(state[0x01]) ? 0x03 : 0x02,
            get_energy(state[0x02][active[2]]) >=
            static_state[0x02][active[2]].charged_move_2.energy ? 0xc0 : 0x40)
    else
        d = 0x00, 0x00
        for i = 0x01:0x02
            if get_hp(state[i][active[i]]) == 0x0000
                if get_hp(state[i][(active[i] == 0x01 ? 0x02 : 0x01)]) != 0x0000
                    d = i == 0x01 ? (d[1] + 0x10, d[2]) : (d[1], d[2] + 0x10)
                end
                if get_hp(state[i][(active[i] == 0x03 ? 0x02 : 0x03)]) != 0x0000
                    d = i == 0x01 ? (d[1] + 0x20, d[2]) : (d[1], d[2] + 0x20)
                end
            else
                if fast_moves_pending[i] <= 0x01
                    if allow_overfarming ||
                        get_energy(state[i][active[i]]) != 0x0064
                        d = i == 0x01 ? (d[1] + 0x04, d[2]) :
                            (d[1], d[2] + 0x04)
                    end
                    if get_energy(state[i][active[i]]) >=
                        static_state[i][active[i]].charged_move_1.energy
                        d = i == 0x01 ? (d[1] + 0x08, d[2]) :
                            (d[1], d[2] + 0x08)
                    end
                    if get_hp(state[i][active[i] == 0x01 ?
                        0x02 : 0x01]) != 0x0000 &&
                        state[i].switchCooldown == Int8(0)
                        d = i == 0x01 ? (d[1] + 0x10, d[2]) :
                            (d[1], d[2] + 0x10)
                    end
                    if get_hp(state[i][active[i] == 0x03 ?
                        0x02 : 0x03]) != 0x0000 &&
                        state[i].switchCooldown == Int8(0)
                        d = i == 0x01 ? (d[1] + 0x20, d[2]) :
                            (d[1], d[2] + 0x20)
                    end
                    if allow_nothing
                        d = i == 0x01 ? (d[1] + 0x02, d[2]) :
                            (d[1], d[2] + 0x02)
                    end
                else
                    d = i == 0x01 ? (d[1] + 0x02, d[2]) : (d[1], d[2] + 0x02)
                end
            end
        end
        return d
    end
end


text:
export EphemerisNBP
export get_state

#----------------#
# N-BODY SYSTEMS #
#----------------#
struct NBPSystemProperties{N}
    center :: Symbol
    center_id :: Integer
    bodies :: SVector{N, Symbol}
    body_ids :: SVector{N, <: Integer}
    μ :: SVector{N, <: Real}
end

function NBPSystemProperties(center::Symbol, bodies::Vararg{Symbol})
    # Load ephemerides for all bodies...
    map(SpiceUtils.load_ephemerides, bodies)
    bodies = SVector(bodies...)

    center_id = bodn2c(String(center))
    body_ids = @. bodn2c(String(bodies))
    μ = SpiceUtils.get_GM.(body_ids)
    NBPSystemProperties(center, center_id, bodies, body_ids, μ)
end

Base.show(io::IO, x::NBPSystemProperties) = print(io, "($(x.center), acc=$(x.bodies))")

#-----------------------------------#
# EPHEMERIS-NBP EQUATIONS OF MOTION #
#-----------------------------------#
struct _NBP_ODEFunctions{S,F,F2} <: Abstract_ModelODEFunctions
    ode_system :: S
    ode_f      :: F
    ode_stm_f  :: F2
end

# XXX: Need the "T" in place for @memoize to work
@memoize function ModelingToolkit.ODESystem(T::Type{_NBP_ODEFunctions}, props::NBPSystemProperties)
    @parameters t  # Time in J2000 epoch
    @variables x(t) y(t) z(t)
    D2 = Differential(t)^2

    accelerations = zeros(Num, 3)
    pos = [x, y, z]

    for (body, μ) in zip(props.bodies, props.μ)
        # See also [DeiTos2017, Eqs. 14], [JTOP implementation], [Ozaki2017, Eq.2]

        # Get the position of the body
        if body == props.center
            body_pos = [0., 0., 0.]
        else
            # Add the non-inertial center's acceleration (i.e. center is also pulled by this body) [?]
            # NOTE: the body and center need to be converted to Num{String} for the @registered function to work.
            #       Num{Symbol} won't work because they convert to variable names instead of Symbols.
            body_pos_term = SpiceUtils.get_pos(t, String(body), String(props.center))

            # XXX: Need to manually build the vector since the compiler won't know the size of body_pos otherwise.
            # TODO: Fix the allocation cost of this. view() and reshape() are not defined for Nums...
            body_pos = [body_pos_term[1], body_pos_term[2], body_pos_term[3]]
            accelerations += -μ * body_pos / norm(body_pos)^3
        end

        # Compute the acceleration of the spacecraft towards this body
        distance_vector = body_pos - pos
        accelerations += μ * distance_vector / norm(distance_vector)^3
    end

    # Equations of motion: sum of all accelerations
    eqs = @. D2(pos) ~ sum(accelerations)

    # Build the 2nd-order ODE props
    return ODESystem(eqs, t, pos, [])
end

#---------------------#
# EPHEMERIS-NBP MODEL #
#---------------------#
struct EphemerisNBP{O<:_NBP_ODEFunctions,P<:NBPSystemProperties} <: Abstract_DynamicalModel
    ode   :: O
    props :: P
end
function EphemerisNBP(bodies::Vararg{Symbol}; center=nothing, kwargs...)
    (!isnothing(center) && isnothing(bodn2c(center)) || center ∈ bodies) && error("Unsupported center (must not be specified in bodies)")
    all_bodies = isnothing(center) ? (bodies[1], bodies...) : (center, bodies...)
    bodies_symbols = @. Symbol(lowercase(String(all_bodies)))
    props = NBPSystemProperties(bodies_symbols...)
    EphemerisNBP(_NBP_ODEFunctions(props; kwargs...), props)
end

Base.show(io::IO, x::EphemerisNBP) = print(io, "$(nameof(typeof(x)))$(x.props)")
ModelingToolkit.parameters(model::EphemerisNBP) = SVector{0,Float64}()

# HELPERS

# TODO: Check that target is in the system?
get_state(system::EphemerisNBP, target::Symbol, t) =
    State(system, SpiceUtils.get_state(t, target, system.props.center), (t, t))

# TRAITS
default_reference_frame(::EphemerisNBP) = InertialFrame()
default_synodic_reference_frame(::EphemerisNBP) = SynodicFrame(false)

primary_body(m::EphemerisNBP) = m.props.center
secondary_body(m::EphemerisNBP) = m.props.bodies[2]

convert_to_frame(state::State{<:EphemerisNBP,F}, frame::F) where {F<:Abstract_ReferenceFrame} = state
function convert_to_frame(state::State{<:EphemerisNBP,<:Abstract_ReferenceFrame}, frame::Abstract_ReferenceFrame)
    # Get the synodic initial state of the secondary body
    # TODO: Fix up the SpiceUtils interface so the arguments are more consistently ordered.
    to_synodic = SpiceUtils.state_to_synodic(primary_body(state), secondary_body(state), state.prob.tspan[1])
    inv_synodic = inv(to_synodic)

    @assert length(state.prob.u0) >= STATE_DIMS
    # XXX: @inbounds @views is sometimes causing crashes below!!!
    # @inbounds @views begin
    converted_u0 = state_to_frame(state, frame, to_synodic, inv_synodic)
    # end

    prob1 = remake(state.prob; u0=converted_u0)
    state = State(state.model, frame, prob1)
    return state
end

function state_to_frame(state::State{<:EphemerisNBP,InertialFrame}, frame::SynodicFrame{true}, to_synodic, inv_synodic)
    u1 = state_to_frame(state, SynodicFrame(false), to_synodic, inv_synodic)
    return state_to_frame(State(state.model, SynodicFrame(false), u1, state.prob.tspan), frame, to_synodic, inv_synodic)
end

function state_to_frame(state::State{<:EphemerisNBP,SynodicFrame{false}}, ::SynodicFrame{true}, to_synodic, inv_synodic)
    secondary_u0 = SpiceUtils.get_state(state.prob.tspan[1], secondary_body(state), primary_body(state))
    synod_secondary_u0 = to_synodic * secondary_u0
    # Normalise the state
    circ_props = R3BPSystemProperties(primary_body(state), secondary_body(state))
    u1 = copy(state.prob.u0)
    P, V = norm(secondary_u0[1:3]), norm(secondary_u0[4:6])
    u1[1:3] .= (u1[1:3] - synod_secondary_u0[1:3]) ./ P + [1 - circ_props.μ, 0., 0.]
    u1[4:6] .= (u1[4:6] - synod_secondary_u0[4:6]) ./ V

    if length(u1) == (STATE_DIMS + STATE_DIMS*STATE_DIMS)
        # XXX: If there are vareqn. variables, cross-multiply them appropriately
        vareqns = reshape(@view(u1[STATE_DIMS+1:end]), (STATE_DIMS, STATE_DIMS))
        pos_vareqns = @view vareqns[1:3, :]
        vel_vareqns = @view vareqns[4:6, :]
        pos_vareqns .= pos_vareqns ./ P
        vel_vareqns .= vel_vareqns ./ V
    end

    return u1
end

function state_to_frame(state::State{<:EphemerisNBP,<:SynodicFrame{true}}, ::SynodicFrame{false}, to_synodic, inv_synodic)
    secondary_u0 = SpiceUtils.get_state(state.prob.tspan[1], secondary_body(state), primary_body(state))
    synod_secondary_u0 = to_synodic * secondary_u0
    # De-normalise
    circ_props = R3BPSystemProperties(primary_body(state), secondary_body(state))
    u1 = copy(state.prob.u0)
    P, V = norm(secondary_u0[1:3]), norm(secondary_u0[4:6])
    u1[1:3] .= (u1[1:3] - [1 - circ_props.μ, 0., 0.]) .* P + synod_secondary_u0[1:3]
    u1[4:6] .= u1[4:6] .* V + synod_secondary_u0[4:6]

    if length(u1) == (STATE_DIMS + STATE_DIMS*STATE_DIMS)
        # XXX: If there are vareqn. variables, cross-multiply them appropriately
        vareqns = reshape(@view(u1[STATE_DIMS+1:end]), (STATE_DIMS, STATE_DIMS))
        pos_vareqns = @view vareqns[1:3, :]
        vel_vareqns = @view vareqns[4:6, :]
        pos_vareqns .= pos_vareqns .* P
        vel_vareqns .= vel_vareqns .* V
    end

    return u1
end

function state_to_frame(state::State{<:EphemerisNBP,<:SynodicFrame{true}}, frame, to_synodic, inv_synodic)
    u1 = state_to_frame(state, SynodicFrame(false), to_synodic, inv_synodic)
    return state_to_frame(State(state.model, SynodicFrame(false), u1, state.prob.tspan), frame, to_synodic, inv_synodic)
end

state_to_frame(state::State{<:EphemerisNBP,<:InertialFrame}, ::SynodicFrame{false}, to_synodic, inv_synodic) =
    u0_to_frame(state.prob.u0, to_synodic)
state_to_frame(state::State{<:EphemerisNBP,<:SynodicFrame{false}}, ::InertialFrame, to_synodic, inv_synodic) =
    u0_to_frame(state.prob.u0, inv_synodic)

# Dispatch on MVectors
const STATE_DIMS = 6
u0_to_frame(u0::StaticVector{STATE_DIMS}, transform::AbstractMatrix) = transform * u0
function u0_to_frame(u0, transform::AbstractMatrix)
    # TODO: What happens if u0 is a StaticVector? Things break :(

    # XXX: Only transform the state vector, not any var.eqns.
    new_u0 = copy(u0)
    new_u0[begin:STATE_DIMS] .= transform * @view(new_u0[1:STATE_DIMS])

    if length(new_u0) == (STATE_DIMS + STATE_DIMS*STATE_DIMS)
        # XXX: If there are vareqn. variables, cross-multiply them appropriately
        vareqns = reshape(@view(new_u0[STATE_DIMS+1:end]), (STATE_DIMS, STATE_DIMS))
        vareqns .= transform * vareqns
    end

    return new_u0
end

function check_distance(u, t, system::EphemerisNBP, body)
    diam = bodvrd(String(body), "RADII")[1]  # km
    return check_distance(u, t, system, body, diam)
end

function check_distance(u, t, system::EphemerisNBP, body, distance)
    if body == primary_body(system)
        body_pos = SVector{3}(0., 0., 0.)
    else
        body_pos = SpiceUtils.get_pos(t, body, primary_body(system))
    end
    return @inbounds(norm(@view(u[1:3]) - body_pos) - distance)
end


text:
using JuMP, EAGO

                     m = Model()

                     EAGO.register_eago_operators!(m)

                     @variable(m, -1 <= x[i=1:5] <= 1)

                     @variable(m, -6.148474362391325 <= q <= 10.677081718106185)

                     add_NL_constraint(m, :(swish(-0.2518902526786948 + 0.9847866884384731*swish(0.2752793536861313 + -0.1568397657479923*swish(0.860587138591963 + -0.8175452953351838*$(x[1]) + -0.2911974841119127*$(x[2]) + -0.03381280038289569*$(x[3]) + -0.021805451939043596*$(x[4]) + 0.5056820468199099*$(x[5])) + -0.1062303426643516*swish(0.40215662414311426 + 0.47796901525165936*$(x[1]) + -0.8905174133817706*$(x[2]) + 0.3815447257070974*$(x[3]) + -0.7235559998197827*$(x[4]) + -0.43821768660130234*$(x[5])) + 0.5642457669318222*swish(-0.371366893645773 + 0.03574445051584929*$(x[1]) + 0.07916257211879385*$(x[2]) + 0.5096612381208421*$(x[3]) + 0.1651890232922466*$(x[4]) + -0.4691295251335359*$(x[5]))) + -0.7649756572019379*swish(0.9918790053549298 + 0.85981905523253*swish(0.860587138591963 + -0.8175452953351838*$(x[1]) + -0.2911974841119127*$(x[2]) + -0.03381280038289569*$(x[3]) + -0.021805451939043596*$(x[4]) + 0.5056820468199099*$(x[5])) + 0.9639515148457134*swish(0.40215662414311426 + 0.47796901525165936*$(x[1]) + -0.8905174133817706*$(x[2]) + 0.3815447257070974*$(x[3]) + -0.7235559998197827*$(x[4]) + -0.43821768660130234*$(x[5])) + -0.08816238542180388*swish(-0.371366893645773 + 0.03574445051584929*$(x[1]) + 0.07916257211879385*$(x[2]) + 0.5096612381208421*$(x[3]) + 0.1651890232922466*$(x[4]) + -0.4691295251335359*$(x[5]))) + 0.10087195663512549*swish(-0.8202416682813327 + -0.17766510212211006*swish(0.860587138591963 + -0.8175452953351838*$(x[1]) + -0.2911974841119127*$(x[2]) + -0.03381280038289569*$(x[3]) + -0.021805451939043596*$(x[4]) + 0.5056820468199099*$(x[5])) + -0.1793020696087071*swish(0.40215662414311426 + 0.47796901525165936*$(x[1]) + -0.8905174133817706*$(x[2]) + 0.3815447257070974*$(x[3]) + -0.7235559998197827*$(x[4]) + -0.43821768660130234*$(x[5])) + -0.41892665263312834*swish(-0.371366893645773 + 0.03574445051584929*$(x[1]) + 0.07916257211879385*$(x[2]) + 0.5096612381208421*$(x[3]) + 0.1651890232922466*$(x[4]) + -0.4691295251335359*$(x[5])))) + swish(0.638435553115452 + 0.09453389081965424*swish(0.2752793536861313 + -0.1568397657479923*swish(0.860587138591963 + -0.8175452953351838*$(x[1]) + -0.2911974841119127*$(x[2]) + -0.03381280038289569*$(x[3]) + -0.021805451939043596*$(x[4]) + 0.5056820468199099*$(x[5])) + -0.1062303426643516*swish(0.40215662414311426 + 0.47796901525165936*$(x[1]) + -0.8905174133817706*$(x[2]) + 0.3815447257070974*$(x[3]) + -0.7235559998197827*$(x[4]) + -0.43821768660130234*$(x[5])) + 0.5642457669318222*swish(-0.371366893645773 + 0.03574445051584929*$(x[1]) + 0.07916257211879385*$(x[2]) + 0.5096612381208421*$(x[3]) + 0.1651890232922466*$(x[4]) + -0.4691295251335359*$(x[5]))) + -0.07927014075141203*swish(0.9918790053549298 + 0.85981905523253*swish(0.860587138591963 + -0.8175452953351838*$(x[1]) + -0.2911974841119127*$(x[2]) + -0.03381280038289569*$(x[3]) + -0.021805451939043596*$(x[4]) + 0.5056820468199099*$(x[5])) + 0.9639515148457134*swish(0.40215662414311426 + 0.47796901525165936*$(x[1]) + -0.8905174133817706*$(x[2]) + 0.3815447257070974*$(x[3]) + -0.7235559998197827*$(x[4]) + -0.43821768660130234*$(x[5])) + -0.08816238542180388*swish(-0.371366893645773 + 0.03574445051584929*$(x[1]) + 0.07916257211879385*$(x[2]) + 0.5096612381208421*$(x[3]) + 0.1651890232922466*$(x[4]) + -0.4691295251335359*$(x[5]))) + 0.2624391124261729*swish(-0.8202416682813327 + -0.17766510212211006*swish(0.860587138591963 + -0.8175452953351838*$(x[1]) + -0.2911974841119127*$(x[2]) + -0.03381280038289569*$(x[3]) + -0.021805451939043596*$(x[4]) + 0.5056820468199099*$(x[5])) + -0.1793020696087071*swish(0.40215662414311426 + 0.47796901525165936*$(x[1]) + -0.8905174133817706*$(x[2]) + 0.3815447257070974*$(x[3]) + -0.7235559998197827*$(x[4]) + -0.43821768660130234*$(x[5])) + -0.41892665263312834*swish(-0.371366893645773 + 0.03574445051584929*$(x[1]) + 0.07916257211879385*$(x[2]) + 0.5096612381208421*$(x[3]) + 0.1651890232922466*$(x[4]) + -0.4691295251335359*$(x[5])))) + swish(0.5273095272255199 + 0.4025366346817978*swish(0.2752793536861313 + -0.1568397657479923*swish(0.860587138591963 + -0.8175452953351838*$(x[1]) + -0.2911974841119127*$(x[2]) + -0.03381280038289569*$(x[3]) + -0.021805451939043596*$(x[4]) + 0.5056820468199099*$(x[5])) + -0.1062303426643516*swish(0.40215662414311426 + 0.47796901525165936*$(x[1]) + -0.8905174133817706*$(x[2]) + 0.3815447257070974*$(x[3]) + -0.7235559998197827*$(x[4]) + -0.43821768660130234*$(x[5])) + 0.5642457669318222*swish(-0.371366893645773 + 0.03574445051584929*$(x[1]) + 0.07916257211879385*$(x[2]) + 0.5096612381208421*$(x[3]) + 0.1651890232922466*$(x[4]) + -0.4691295251335359*$(x[5]))) + -0.585290488444234*swish(0.9918790053549298 + 0.85981905523253*swish(0.860587138591963 + -0.8175452953351838*$(x[1]) + -0.2911974841119127*$(x[2]) + -0.03381280038289569*$(x[3]) + -0.021805451939043596*$(x[4]) + 0.5056820468199099*$(x[5])) + 0.9639515148457134*swish(0.40215662414311426 + 0.47796901525165936*$(x[1]) + -0.8905174133817706*$(x[2]) + 0.3815447257070974*$(x[3]) + -0.7235559998197827*$(x[4]) + -0.43821768660130234*$(x[5])) + -0.08816238542180388*swish(-0.371366893645773 + 0.03574445051584929*$(x[1]) + 0.07916257211879385*$(x[2]) + 0.5096612381208421*$(x[3]) + 0.1651890232922466*$(x[4]) + -0.4691295251335359*$(x[5]))) + 0.1647823489958915*swish(-0.8202416682813327 + -0.17766510212211006*swish(0.860587138591963 + -0.8175452953351838*$(x[1]) + -0.2911974841119127*$(x[2]) + -0.03381280038289569*$(x[3]) + -0.021805451939043596*$(x[4]) + 0.5056820468199099*$(x[5])) + -0.1793020696087071*swish(0.40215662414311426 + 0.47796901525165936*$(x[1]) + -0.8905174133817706*$(x[2]) + 0.3815447257070974*$(x[3]) + -0.7235559998197827*$(x[4]) + -0.43821768660130234*$(x[5])) + -0.41892665263312834*swish(-0.371366893645773 + 0.03574445051584929*$(x[1]) + 0.07916257211879385*$(x[2]) + 0.5096612381208421*$(x[3]) + 0.1651890232922466*$(x[4]) + -0.4691295251335359*$(x[5])))) - $q <= 0.0))

                     @objective(m, Min, q)

                     return m

max_stars_repo_name: PSORLab/RSActivationFunctions

max_issues_repo_name: PSORLab/RSActivationFunctions

max_forks_repo_name: PSORLab/RSActivationFunctions


text:
using Parameters
using QuantEcon
using DelimitedFiles
using MAT

# -----------------------------------------------------------------------------
# productivity process
# -----------------------------------------------------------------------------

nx      = 12
ρ       = 0.967  # persistence of productivity shock
σϵ      = sqrt(0.017)  # standard deviation  of productivity shock

#income process from MATLAB code
cd(@__DIR__)
pr = readdlm("ppr.csv",',',Float64)[:]
Pr = readdlm("Pr.csv",',',Float64)
x  = readdlm("x.csv",',',Float64)[:]
steady_mat = matopen("steady.mat")
#read(steady_mat, "b_pol1")

θ               = [0; exp.(x)... ];
S               = length(θ);
fin             = 0.8820;        # job-finding probability
sep             = 0.0573;        # separation probability

"""
Structure holding all parameters and solutions to the steady-state model
"""
@with_kw mutable struct ModelGL

    # Deep parameters
    γ::Float64           = 4.       # risk aversion
    frisch::Float64      = 1.       # avg Frisch elast.
    r::Float64           = 2.5/400  # ss interest rate
    ρ::Float64           = ρ        # persistence of productivity shock
    σϵ::Float64          = σϵ       # standard deviation  of productivity shock

    # Calibration targets
    NE::Float64         = 0.4       # avg hours of employed
    νY::Float64         = 0.4       # UI benefit per GDP
    B_4Y::Float64       = 1.6       # liquid wealth per annual GDP
    D1_4Y::Float64      = 0.18      # HH debt to annual GDP in initial ss
    D2_4Y::Float64      = 0.08      # HH debt to annual GDP in terminal ss

    η::Float64          = 1.5
    gameta::Float64     = γ / η;

    # Initial guesses for calibrated parameters, NE ~ Y
    β::Float64          = 0.8^0.25;                 # discount factor
    ν::Float64          = νY*NE;                    # UI benefits
    B::Float64          = B_4Y  * NE * 4;         # net supply of bonds
    ϕ₁::Float64         = D1_4Y * NE * 2;                  # borrowing constraint in initial ss
    ϕ₂::Float64         = D2_4Y * NE * 2;         # borrowing constraint in terminal ss
    ϕ::Float64          = ϕ₁
    ψ::Float64          = NE^(-γ) * (1-NE)^η;                  # disutility from labor as if representative agent

    # Numerical parameters
    maxit::Int64        = 500;   # maximum number of iterations in calibration
    cmin::Float64       = 1e-6;  # lower bound on consumption
    tol_pol ::Float64   = 1e-10; # tolerance lvl for policy function
    tol_dist::Float64   = 1e-10; # tolerance lvl for distribution
    tol_mkt ::Float64   = 1e-6;  # tolerance lvl for market clearing
    tol_cali::Float64   = 1e-4;  # tolerance lvl for calibration

    # bond (asset) grid
    nb::Int64                   = 200; # number of grid points
    Ic::Int64                   = 100;
    bmin::Float64               = -2.;   # lower bound
    bmax::Float64               = 50.;   # upper bound
    b_grid::Array{Float64,1}    = bmin .+ ((1:nb)/nb).^2 .* (bmax - bmin); # denser for low values
    db::Float64                 = 0.01; # step size for MPC

    # productivity shock process
    x::Array{Float64, 1}     = x
    #Pr_::Array{Float64, 2}   = Pr_
    #pr_::Array{Float64, 1}   = pr_

    # Add unemployment
    θ::Array{Float64, 1}= [0; exp.(x)... ];
    S::Int64            = length(θ);
    fin::Float64        = 0.8820;        # job-finding probability
    sep::Float64        = 0.0573;        # separation probability

    # new transition matrix
    Pr::Array{Float64, 2}   = Pr

    pr::Array{Float64,1}    = pr

    # Policies
    cl::Array{Float64,1}                = ones(S);     # consumption at borrowing constraint
    n_pol::Array{Float64,2}             = zeros(S, nb); # labor policy
    y_pol::Array{Float64,2}             = zeros(S, nb); # production policy
    b_pol::Array{Float64,2}             = zeros(S, nb); # savings policy
    c_pol::Array{Float64,2}             = zeros(S, nb); # consumption policy
    mpcs::Array{Float64,2}              = zeros(S, nb); # MPCs

    # Simulation
    JD::Array{Float64, 2}               = ones(S, nb) / (S+nb); # Joint compute_distribution

    # aggregates
    B_4Y_actual::Float64    = NaN
    D_4Y_actual::Float64    = NaN
    νY_actual::Float64      = NaN
    NE_actual::Float64      = NaN
    Y_actual::Float64       = NaN

    # diagnostic
    calibrated::Bool            = false
    steadystate_solved::Bool    = false
    steadystate_type::String    = "initial"
end

"""
Structure holding transition objects
"""
@with_kw mutable struct TransGL

    # SS Transition dynamics

    # Numerical parameters
    T::Int64               = 100                 # horizon, high enough for convergence to be complete
    maxit_trans::Int64     = 400                 # maximum number of iterations
    tol_mkt_trans::Float64 = 5e-6;               # tolerance for market clearing (lower than for ss computation)

    # Updating weights for interest rate
    speed::Float64 = 0.1
    decay::Float64 = 0.01
    weight_::Array{Float64,1} = exp.(-decay*(0:T-1))
    weight::Array{Float64,1}  = speed * weight_ / sum(weight_)

    # Transition objects
    S  = 13
    nb = 200
    ib_pol_t::Array{Int,3}     = zeros(S, nb, T); # sequence of policy functions
    wei_t::Array{Float64,3}    = zeros(S, nb, T); # sequence of weights on adjacent grid points
    Bdem_t::Array{Float64,1}   = zeros(T);        # bond demand
    Y_t::Array{Float64,1}      = zeros(T);        # GDP
    D_t::Array{Float64,1}      = zeros(T);        # debt
    D_4Y_t::Array{Float64,1}   = zeros(T);        # debt to GDP
    r_t::Array{Float64,1}      = zeros(T);        # interest rate path
    ϕ_t::Array{Float64,1}      = zeros(T+1);      # borrowing limit

    c_pol_t::Array{Float64,3} = zeros(S, nb, T);  # consumption policy in each period
    n_pol_t::Array{Float64,3} = zeros(S, nb, T);  # labour policy in each period
    y_pol_t::Array{Float64,3} = zeros(S, nb, T);  # income policy in each period

    JD_t::Array{Float64,3} = zeros(S,nb,T); # Joint compute_distribution at each point in time

end