text:
@testset "4.3.9 trig^m (a+b tan^n+c tan^(2 n))^p" begin
    (a, b, c, d, e, x, ) = @variables a b c d e x

    #= ::Package:: =#

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

    #= ::Section:: =#
    #=Integrands*of*the*form*sin(d+e*x)^m*(a+b*tan(d+e*x)^n+c*tan(d+e*x)^(2*n))^p=#

    #= ::Section:: =#
    #=Integrands*of*the*form*cos(d+e*x)^m*(a+b*tan(d+e*x)^n+c*tan(d+e*x)^(2*n))^p=#

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

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

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

    @test_int [tan(d + e*x)^5*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2), x, 21, (1/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*e))*(sqrt(a^2 + b^2 + c*(c + sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c + sqrt(a^2 + b^2 - 2*a*c + c^2)))*atan((b^2 + (a - c)*(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2)) - b*sqrt(a^2 + b^2 - 2*a*c + c^2)*tan(d + e*x))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*sqrt(a^2 + b^2 + c*(c + sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c + sqrt(a^2 + b^2 - 2*a*c + c^2)))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2)))) + (b*atanh((b + 2*c*tan(d + e*x))/(2*sqrt(c)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(2*sqrt(c)*e) - (b*(b^2 - 4*a*c)*atanh((b + 2*c*tan(d + e*x))/(2*sqrt(c)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(16*c^(5/2)*e) + (b*(7*b^2 - 12*a*c)*(b^2 - 4*a*c)*atanh((b + 2*c*tan(d + e*x))/(2*sqrt(c)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(256*c^(9/2)*e) - (1/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*e))*(sqrt(a^2 + b^2 + c*(c - sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c - sqrt(a^2 + b^2 - 2*a*c + c^2)))*atanh((b^2 + (a - c)*(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2)) + b*sqrt(a^2 + b^2 - 2*a*c + c^2)*tan(d + e*x))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*sqrt(a^2 + b^2 + c*(c - sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c - sqrt(a^2 + b^2 - 2*a*c + c^2)))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2)))) + sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2)/e + (b*(b + 2*c*tan(d + e*x))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))/(8*c^2*e) - (b*(7*b^2 - 12*a*c)*(b + 2*c*tan(d + e*x))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))/(128*c^4*e) - (a + b*tan(d + e*x) + c*tan(d + e*x)^2)^(3/2)/(3*c*e) + (tan(d + e*x)^2*(a + b*tan(d + e*x) + c*tan(d + e*x)^2)^(3/2))/(5*c*e) + ((35*b^2 - 32*a*c - 42*b*c*tan(d + e*x))*(a + b*tan(d + e*x) + c*tan(d + e*x)^2)^(3/2))/(240*c^3*e)]
    @test_int [tan(d + e*x)^4*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2), x, 19, -((1/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*e))*(sqrt(a^2 + b^2 + c*(c - sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c - sqrt(a^2 + b^2 - 2*a*c + c^2)))*atan((b*sqrt(a^2 + b^2 - 2*a*c + c^2) - (b^2 + (a - c)*(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2)))*tan(d + e*x))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*sqrt(a^2 + b^2 + c*(c - sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c - sqrt(a^2 + b^2 - 2*a*c + c^2)))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))) + (sqrt(c)*atanh((b + 2*c*tan(d + e*x))/(2*sqrt(c)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/e + ((b^2 - 4*a*c)*atanh((b + 2*c*tan(d + e*x))/(2*sqrt(c)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(8*c^(3/2)*e) - ((b^2 - 4*a*c)*(5*b^2 - 4*a*c)*atanh((b + 2*c*tan(d + e*x))/(2*sqrt(c)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(128*c^(7/2)*e) - (1/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*e))*(sqrt(a^2 + b^2 + c*(c + sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c + sqrt(a^2 + b^2 - 2*a*c + c^2)))*atanh((b*sqrt(a^2 + b^2 - 2*a*c + c^2) + (b^2 + (a - c)*(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2)))*tan(d + e*x))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*sqrt(a^2 + b^2 + c*(c + sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c + sqrt(a^2 + b^2 - 2*a*c + c^2)))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2)))) - ((b + 2*c*tan(d + e*x))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))/(4*c*e) + ((5*b^2 - 4*a*c)*(b + 2*c*tan(d + e*x))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))/(64*c^3*e) - (5*b*(a + b*tan(d + e*x) + c*tan(d + e*x)^2)^(3/2))/(24*c^2*e) + (tan(d + e*x)*(a + b*tan(d + e*x) + c*tan(d + e*x)^2)^(3/2))/(4*c*e)]
    @test_int [tan(d + e*x)^3*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2), x, 16, -((sqrt(a^2 + b^2 + c*(c + sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c + sqrt(a^2 + b^2 - 2*a*c + c^2)))*atan((b^2 + (a - c)*(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2)) - b*sqrt(a^2 + b^2 - 2*a*c + c^2)*tan(d + e*x))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*sqrt(a^2 + b^2 + c*(c + sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c + sqrt(a^2 + b^2 - 2*a*c + c^2)))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*e)) - (b*atanh((b + 2*c*tan(d + e*x))/(2*sqrt(c)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(2*sqrt(c)*e) + (b*(b^2 - 4*a*c)*atanh((b + 2*c*tan(d + e*x))/(2*sqrt(c)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(16*c^(5/2)*e) + (sqrt(a^2 + b^2 + c*(c - sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c - sqrt(a^2 + b^2 - 2*a*c + c^2)))*atanh((b^2 + (a - c)*(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2)) + b*sqrt(a^2 + b^2 - 2*a*c + c^2)*tan(d + e*x))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*sqrt(a^2 + b^2 + c*(c - sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c - sqrt(a^2 + b^2 - 2*a*c + c^2)))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*e) - sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2)/e - (b*(b + 2*c*tan(d + e*x))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))/(8*c^2*e) + (a + b*tan(d + e*x) + c*tan(d + e*x)^2)^(3/2)/(3*c*e)]
    @test_int [tan(d + e*x)^2*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2), x, 10, (sqrt(a^2 + b^2 + c*(c - sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c - sqrt(a^2 + b^2 - 2*a*c + c^2)))*atan((b*sqrt(a^2 + b^2 - 2*a*c + c^2) - (a^2 + b^2 + c*(c - sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c - sqrt(a^2 + b^2 - 2*a*c + c^2)))*tan(d + e*x))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*sqrt(a^2 + b^2 + c*(c - sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c - sqrt(a^2 + b^2 - 2*a*c + c^2)))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*e) - ((b^2 - 4*(a - 2*c)*c)*atanh((b + 2*c*tan(d + e*x))/(2*sqrt(c)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(8*c^(3/2)*e) + (sqrt(a^2 + b^2 + c*(c + sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c + sqrt(a^2 + b^2 - 2*a*c + c^2)))*atanh((b*sqrt(a^2 + b^2 - 2*a*c + c^2) + (a^2 + b^2 + c*(c + sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c + sqrt(a^2 + b^2 - 2*a*c + c^2)))*tan(d + e*x))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*sqrt(a^2 + b^2 + c*(c + sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c + sqrt(a^2 + b^2 - 2*a*c + c^2)))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*e) + ((b + 2*c*tan(d + e*x))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))/(4*c*e)]
    @test_int [tan(d + e*x)^1*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2), x, 10, (sqrt(a^2 + b^2 + c*(c + sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c + sqrt(a^2 + b^2 - 2*a*c + c^2)))*atan((b^2 + (a - c)*(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2)) - b*sqrt(a^2 + b^2 - 2*a*c + c^2)*tan(d + e*x))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*sqrt(a^2 + b^2 + c*(c + sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c + sqrt(a^2 + b^2 - 2*a*c + c^2)))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*e) + (b*atanh((b + 2*c*tan(d + e*x))/(2*sqrt(c)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(2*sqrt(c)*e) - (sqrt(a^2 + b^2 + c*(c - sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c - sqrt(a^2 + b^2 - 2*a*c + c^2)))*atanh((b^2 + (a - c)*(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2)) + b*sqrt(a^2 + b^2 - 2*a*c + c^2)*tan(d + e*x))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*sqrt(a^2 + b^2 + c*(c - sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c - sqrt(a^2 + b^2 - 2*a*c + c^2)))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*e) + sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2)/e]
    @test_int [tan(d + e*x)^0*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2), x, 9, -((sqrt(a^2 + b^2 + c*(c - sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c - sqrt(a^2 + b^2 - 2*a*c + c^2)))*atan((b*sqrt(a^2 + b^2 - 2*a*c + c^2) - (b^2 + (a - c)*(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2)))*tan(d + e*x))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*sqrt(a^2 + b^2 + c*(c - sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c - sqrt(a^2 + b^2 - 2*a*c + c^2)))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*e)) + (sqrt(c)*atanh((b + 2*c*tan(d + e*x))/(2*sqrt(c)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/e - (sqrt(a^2 + b^2 + c*(c + sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c + sqrt(a^2 + b^2 - 2*a*c + c^2)))*atanh((b*sqrt(a^2 + b^2 - 2*a*c + c^2) + (b^2 + (a - c)*(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2)))*tan(d + e*x))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*sqrt(a^2 + b^2 + c*(c + sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c + sqrt(a^2 + b^2 - 2*a*c + c^2)))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*e)]
    @test_int [cot(d + e*x)^1*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2), x, 18, -((sqrt(a^2 + b^2 + c*(c + sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c + sqrt(a^2 + b^2 - 2*a*c + c^2)))*atan((b^2 + (a - c)*(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2)) - b*sqrt(a^2 + b^2 - 2*a*c + c^2)*tan(d + e*x))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*sqrt(a^2 + b^2 + c*(c + sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c + sqrt(a^2 + b^2 - 2*a*c + c^2)))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*e)) - (sqrt(a)*atanh((2*a + b*tan(d + e*x))/(2*sqrt(a)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/e + (sqrt(a^2 + b^2 + c*(c - sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c - sqrt(a^2 + b^2 - 2*a*c + c^2)))*atanh((b^2 + (a - c)*(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2)) + b*sqrt(a^2 + b^2 - 2*a*c + c^2)*tan(d + e*x))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*sqrt(a^2 + b^2 + c*(c - sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c - sqrt(a^2 + b^2 - 2*a*c + c^2)))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*e)]
    @test_int [cot(d + e*x)^2*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2), x, 17, (sqrt(a^2 + b^2 + c*(c - sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c - sqrt(a^2 + b^2 - 2*a*c + c^2)))*atan((b*sqrt(a^2 + b^2 - 2*a*c + c^2) - (b^2 + (a - c)*(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2)))*tan(d + e*x))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*sqrt(a^2 + b^2 + c*(c - sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c - sqrt(a^2 + b^2 - 2*a*c + c^2)))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*e) - (b*atanh((2*a + b*tan(d + e*x))/(2*sqrt(a)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(2*sqrt(a)*e) + (sqrt(a^2 + b^2 + c*(c + sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c + sqrt(a^2 + b^2 - 2*a*c + c^2)))*atanh((b*sqrt(a^2 + b^2 - 2*a*c + c^2) + (b^2 + (a - c)*(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2)))*tan(d + e*x))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*sqrt(a^2 + b^2 + c*(c + sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c + sqrt(a^2 + b^2 - 2*a*c + c^2)))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*e) - (cot(d + e*x)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))/e]
    @test_int [cot(d + e*x)^3*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2), x, 21, (sqrt(a^2 + b^2 + c*(c + sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c + sqrt(a^2 + b^2 - 2*a*c + c^2)))*atan((b^2 + (a - c)*(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2)) - b*sqrt(a^2 + b^2 - 2*a*c + c^2)*tan(d + e*x))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*sqrt(a^2 + b^2 + c*(c + sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c + sqrt(a^2 + b^2 - 2*a*c + c^2)))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*e) + (sqrt(a)*atanh((2*a + b*tan(d + e*x))/(2*sqrt(a)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/e + ((b^2 - 4*a*c)*atanh((2*a + b*tan(d + e*x))/(2*sqrt(a)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(8*a^(3/2)*e) - (sqrt(a^2 + b^2 + c*(c - sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c - sqrt(a^2 + b^2 - 2*a*c + c^2)))*atanh((b^2 + (a - c)*(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2)) + b*sqrt(a^2 + b^2 - 2*a*c + c^2)*tan(d + e*x))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*sqrt(a^2 + b^2 + c*(c - sqrt(a^2 + b^2 - 2*a*c + c^2)) - a*(2*c - sqrt(a^2 + b^2 - 2*a*c + c^2)))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(1/4)*e) - (cot(d + e*x)^2*(2*a + b*tan(d + e*x))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))/(4*a*e)]

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

    @test_int [tan(d + e*x)^5/sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2), x, 15, (sqrt(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2))*atanh((a - c - sqrt(a^2 + b^2 - 2*a*c + c^2) + b*tan(d + e*x))/(sqrt(2)*sqrt(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*sqrt(a^2 + b^2 - 2*a*c + c^2)*e) - (sqrt(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2))*atanh((a - c + sqrt(a^2 + b^2 - 2*a*c + c^2) + b*tan(d + e*x))/(sqrt(2)*sqrt(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*sqrt(a^2 + b^2 - 2*a*c + c^2)*e) + (b*atanh((b + 2*c*tan(d + e*x))/(2*sqrt(c)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(2*c^(3/2)*e) - (b*(5*b^2 - 12*a*c)*atanh((b + 2*c*tan(d + e*x))/(2*sqrt(c)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(16*c^(7/2)*e) - sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2)/(c*e) + (tan(d + e*x)^2*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))/(3*c*e) + ((15*b^2 - 16*a*c - 10*b*c*tan(d + e*x))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))/(24*c^3*e)]
    @test_int [tan(d + e*x)^4/sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2), x, 14, (sqrt(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2))*atan((b - (a - c - sqrt(a^2 + b^2 - 2*a*c + c^2))*tan(d + e*x))/(sqrt(2)*sqrt(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*sqrt(a^2 + b^2 - 2*a*c + c^2)*e) - (sqrt(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2))*atan((b - (a - c + sqrt(a^2 + b^2 - 2*a*c + c^2))*tan(d + e*x))/(sqrt(2)*sqrt(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*sqrt(a^2 + b^2 - 2*a*c + c^2)*e) - atanh((b + 2*c*tan(d + e*x))/(2*sqrt(c)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2)))/(sqrt(c)*e) + ((3*b^2 - 4*a*c)*atanh((b + 2*c*tan(d + e*x))/(2*sqrt(c)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(8*c^(5/2)*e) - (3*b*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))/(4*c^2*e) + (tan(d + e*x)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))/(2*c*e)]
    @test_int [tan(d + e*x)^3/sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2), x, 11, -((sqrt(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2))*atanh((a - c - sqrt(a^2 + b^2 - 2*a*c + c^2) + b*tan(d + e*x))/(sqrt(2)*sqrt(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*sqrt(a^2 + b^2 - 2*a*c + c^2)*e)) + (sqrt(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2))*atanh((a - c + sqrt(a^2 + b^2 - 2*a*c + c^2) + b*tan(d + e*x))/(sqrt(2)*sqrt(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*sqrt(a^2 + b^2 - 2*a*c + c^2)*e) - (b*atanh((b + 2*c*tan(d + e*x))/(2*sqrt(c)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(2*c^(3/2)*e) + sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2)/(c*e)]
    @test_int [tan(d + e*x)^2/sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2), x, 9, -((sqrt(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2))*atan((b - (a - c - sqrt(a^2 + b^2 - 2*a*c + c^2))*tan(d + e*x))/(sqrt(2)*sqrt(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*sqrt(a^2 + b^2 - 2*a*c + c^2)*e)) + (sqrt(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2))*atan((b - (a - c + sqrt(a^2 + b^2 - 2*a*c + c^2))*tan(d + e*x))/(sqrt(2)*sqrt(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*sqrt(a^2 + b^2 - 2*a*c + c^2)*e) + atanh((b + 2*c*tan(d + e*x))/(2*sqrt(c)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2)))/(sqrt(c)*e)]
    @test_int [tan(d + e*x)^1/sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2), x, 6, (sqrt(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2))*atanh((a - c - sqrt(a^2 + b^2 - 2*a*c + c^2) + b*tan(d + e*x))/(sqrt(2)*sqrt(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*sqrt(a^2 + b^2 - 2*a*c + c^2)*e) - (sqrt(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2))*atanh((a - c + sqrt(a^2 + b^2 - 2*a*c + c^2) + b*tan(d + e*x))/(sqrt(2)*sqrt(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*sqrt(a^2 + b^2 - 2*a*c + c^2)*e)]
    @test_int [tan(d + e*x)^0/sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2), x, 6, (sqrt(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2))*atan((b - (a - c - sqrt(a^2 + b^2 - 2*a*c + c^2))*tan(d + e*x))/(sqrt(2)*sqrt(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*sqrt(a^2 + b^2 - 2*a*c + c^2)*e) - (sqrt(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2))*atan((b - (a - c + sqrt(a^2 + b^2 - 2*a*c + c^2))*tan(d + e*x))/(sqrt(2)*sqrt(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*sqrt(a^2 + b^2 - 2*a*c + c^2)*e)]
    @test_int [cot(d + e*x)^1/sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2), x, 10, -(atanh((2*a + b*tan(d + e*x))/(2*sqrt(a)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2)))/(sqrt(a)*e)) - (sqrt(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2))*atanh((a - c - sqrt(a^2 + b^2 - 2*a*c + c^2) + b*tan(d + e*x))/(sqrt(2)*sqrt(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*sqrt(a^2 + b^2 - 2*a*c + c^2)*e) + (sqrt(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2))*atanh((a - c + sqrt(a^2 + b^2 - 2*a*c + c^2) + b*tan(d + e*x))/(sqrt(2)*sqrt(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*sqrt(a^2 + b^2 - 2*a*c + c^2)*e)]
    @test_int [cot(d + e*x)^2/sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2), x, 11, -((sqrt(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2))*atan((b - (a - c - sqrt(a^2 + b^2 - 2*a*c + c^2))*tan(d + e*x))/(sqrt(2)*sqrt(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*sqrt(a^2 + b^2 - 2*a*c + c^2)*e)) + (sqrt(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2))*atan((b - (a - c + sqrt(a^2 + b^2 - 2*a*c + c^2))*tan(d + e*x))/(sqrt(2)*sqrt(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*sqrt(a^2 + b^2 - 2*a*c + c^2)*e) + (b*atanh((2*a + b*tan(d + e*x))/(2*sqrt(a)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(2*a^(3/2)*e) - (cot(d + e*x)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))/(a*e)]
    @test_int [cot(d + e*x)^3/sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2), x, 14, atanh((2*a + b*tan(d + e*x))/(2*sqrt(a)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2)))/(sqrt(a)*e) - ((3*b^2 - 4*a*c)*atanh((2*a + b*tan(d + e*x))/(2*sqrt(a)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(8*a^(5/2)*e) + (sqrt(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2))*atanh((a - c - sqrt(a^2 + b^2 - 2*a*c + c^2) + b*tan(d + e*x))/(sqrt(2)*sqrt(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*sqrt(a^2 + b^2 - 2*a*c + c^2)*e) - (sqrt(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2))*atanh((a - c + sqrt(a^2 + b^2 - 2*a*c + c^2) + b*tan(d + e*x))/(sqrt(2)*sqrt(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*sqrt(a^2 + b^2 - 2*a*c + c^2)*e) + (3*b*cot(d + e*x)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))/(4*a^2*e) - (cot(d + e*x)^2*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))/(2*a*e)]

    @test_int [tan(d + e*x)^7/(a + b*tan(d + e*x) + c*tan(d + e*x)^2)^(3/2), x, 20, (3*b*atanh((b + 2*c*tan(d + e*x))/(2*sqrt(c)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(2*c^(5/2)*e) - (5*b*(7*b^2 - 12*a*c)*atanh((b + 2*c*tan(d + e*x))/(2*sqrt(c)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(16*c^(9/2)*e) - (sqrt(2*a - 2*c - sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 + (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*atanh((b^2 - (a - c)*(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2)) - b*(2*a - 2*c - sqrt(a^2 + b^2 - 2*a*c + c^2))*tan(d + e*x))/(sqrt(2)*sqrt(2*a - 2*c - sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 + (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(3/2)*e) + (sqrt(2*a - 2*c + sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 - (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*atanh((b^2 - (a - c)*(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2)) - b*(2*a - 2*c + sqrt(a^2 + b^2 - 2*a*c + c^2))*tan(d + e*x))/(sqrt(2)*sqrt(2*a - 2*c + sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 - (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(3/2)*e) + (2*(2*a + b*tan(d + e*x)))/((b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2)) - (2*tan(d + e*x)^2*(2*a + b*tan(d + e*x)))/((b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2)) + (2*tan(d + e*x)^4*(2*a + b*tan(d + e*x)))/((b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2)) - (2*(a*(b^2 - 2*(a - c)*c) + b*c*(a + c)*tan(d + e*x)))/((b^2 + (a - c)^2)*(b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2)) + ((7*b^2 - 16*a*c)*tan(d + e*x)^2*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))/(3*c^2*(b^2 - 4*a*c)*e) - (2*b*tan(d + e*x)^3*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))/(c*(b^2 - 4*a*c)*e) - ((3*b^2 - 8*a*c - 2*b*c*tan(d + e*x))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))/(c^2*(b^2 - 4*a*c)*e) + ((105*b^4 - 460*a*b^2*c + 256*a^2*c^2 - 2*b*c*(35*b^2 - 116*a*c)*tan(d + e*x))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))/(24*c^4*(b^2 - 4*a*c)*e)]
    @test_int [tan(d + e*x)^5/(a + b*tan(d + e*x) + c*tan(d + e*x)^2)^(3/2), x, 14, -((3*b*atanh((b + 2*c*tan(d + e*x))/(2*sqrt(c)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(2*c^(5/2)*e)) + (sqrt(2*a - 2*c - sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 + (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*atanh((b^2 - (a - c)*(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2)) - b*(2*a - 2*c - sqrt(a^2 + b^2 - 2*a*c + c^2))*tan(d + e*x))/(sqrt(2)*sqrt(2*a - 2*c - sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 + (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(3/2)*e) - (sqrt(2*a - 2*c + sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 - (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*atanh((b^2 - (a - c)*(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2)) - b*(2*a - 2*c + sqrt(a^2 + b^2 - 2*a*c + c^2))*tan(d + e*x))/(sqrt(2)*sqrt(2*a - 2*c + sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 - (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(3/2)*e) - (2*(2*a + b*tan(d + e*x)))/((b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2)) + (2*tan(d + e*x)^2*(2*a + b*tan(d + e*x)))/((b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2)) + (2*(a*(b^2 - 2*(a - c)*c) + b*c*(a + c)*tan(d + e*x)))/((b^2 + (a - c)^2)*(b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2)) + ((3*b^2 - 8*a*c - 2*b*c*tan(d + e*x))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))/(c^2*(b^2 - 4*a*c)*e)]
    @test_int [tan(d + e*x)^3/(a + b*tan(d + e*x) + c*tan(d + e*x)^2)^(3/2), x, 10, -((sqrt(2*a - 2*c - sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 + (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*atanh((b^2 - (a - c)*(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2)) - b*(2*a - 2*c - sqrt(a^2 + b^2 - 2*a*c + c^2))*tan(d + e*x))/(sqrt(2)*sqrt(2*a - 2*c - sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 + (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(3/2)*e)) + (sqrt(2*a - 2*c + sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 - (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*atanh((b^2 - (a - c)*(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2)) - b*(2*a - 2*c + sqrt(a^2 + b^2 - 2*a*c + c^2))*tan(d + e*x))/(sqrt(2)*sqrt(2*a - 2*c + sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 - (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(3/2)*e) + (2*(2*a + b*tan(d + e*x)))/((b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2)) - (2*(a*(b^2 - 2*(a - c)*c) + b*c*(a + c)*tan(d + e*x)))/((b^2 + (a - c)^2)*(b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))]
    @test_int [tan(d + e*x)^2/(a + b*tan(d + e*x) + c*tan(d + e*x)^2)^(3/2), x, 7, -((sqrt(2*a - 2*c + sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 - (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*atan((b*(2*a - 2*c + sqrt(a^2 + b^2 - 2*a*c + c^2)) + (b^2 - (a - c)*(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2)))*tan(d + e*x))/(sqrt(2)*sqrt(2*a - 2*c + sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 - (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(3/2)*e)) + (sqrt(2*a - 2*c - sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 + (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*atan((b*(2*a - 2*c - sqrt(a^2 + b^2 - 2*a*c + c^2)) + (b^2 - (a - c)*(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2)))*tan(d + e*x))/(sqrt(2)*sqrt(2*a - 2*c - sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 + (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(3/2)*e) - (2*(a*b*(a + c) + c*(2*a^2 + b^2 - 2*a*c)*tan(d + e*x)))/((b^2 + (a - c)^2)*(b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))]
    @test_int [tan(d + e*x)^1/(a + b*tan(d + e*x) + c*tan(d + e*x)^2)^(3/2), x, 7, (sqrt(2*a - 2*c - sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 + (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*atanh((b^2 - (a - c)*(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2)) - b*(2*a - 2*c - sqrt(a^2 + b^2 - 2*a*c + c^2))*tan(d + e*x))/(sqrt(2)*sqrt(2*a - 2*c - sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 + (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(3/2)*e) - (sqrt(2*a - 2*c + sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 - (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*atanh((b^2 - (a - c)*(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2)) - b*(2*a - 2*c + sqrt(a^2 + b^2 - 2*a*c + c^2))*tan(d + e*x))/(sqrt(2)*sqrt(2*a - 2*c + sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 - (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(3/2)*e) + (2*(a*(b^2 - 2*(a - c)*c) + b*c*(a + c)*tan(d + e*x)))/((b^2 + (a - c)^2)*(b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))]
    @test_int [cot(d + e*x)^1/(a + b*tan(d + e*x) + c*tan(d + e*x)^2)^(3/2), x, 13, -(atanh((2*a + b*tan(d + e*x))/(2*sqrt(a)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2)))/(a^(3/2)*e)) - (sqrt(2*a - 2*c - sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 + (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*atanh((b^2 - (a - c)*(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2)) - b*(2*a - 2*c - sqrt(a^2 + b^2 - 2*a*c + c^2))*tan(d + e*x))/(sqrt(2)*sqrt(2*a - 2*c - sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 + (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(3/2)*e) + (sqrt(2*a - 2*c + sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 - (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*atanh((b^2 - (a - c)*(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2)) - b*(2*a - 2*c + sqrt(a^2 + b^2 - 2*a*c + c^2))*tan(d + e*x))/(sqrt(2)*sqrt(2*a - 2*c + sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 - (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(3/2)*e) + (2*(b^2 - 2*a*c + b*c*tan(d + e*x)))/(a*(b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2)) - (2*(a*(b^2 - 2*(a - c)*c) + b*c*(a + c)*tan(d + e*x)))/((b^2 + (a - c)^2)*(b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))]
    @test_int [cot(d + e*x)^2/(a + b*tan(d + e*x) + c*tan(d + e*x)^2)^(3/2), x, 13, -((sqrt(2*a - 2*c + sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 - (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*atan((b*(2*a - 2*c + sqrt(a^2 + b^2 - 2*a*c + c^2)) + (b^2 - (a - c)*(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2)))*tan(d + e*x))/(sqrt(2)*sqrt(2*a - 2*c + sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 - (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(3/2)*e)) + (sqrt(2*a - 2*c - sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 + (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*atan((b*(2*a - 2*c - sqrt(a^2 + b^2 - 2*a*c + c^2)) + (b^2 - (a - c)*(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2)))*tan(d + e*x))/(sqrt(2)*sqrt(2*a - 2*c - sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 + (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(3/2)*e) + (3*b*atanh((2*a + b*tan(d + e*x))/(2*sqrt(a)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(2*a^(5/2)*e) + (2*cot(d + e*x)*(b^2 - 2*a*c + b*c*tan(d + e*x)))/(a*(b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2)) + (2*(b*(b^2 - (3*a - c)*c) + c*(b^2 - 2*(a - c)*c)*tan(d + e*x)))/((b^2 + (a - c)^2)*(b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2)) - ((3*b^2 - 8*a*c)*cot(d + e*x)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))/(a^2*(b^2 - 4*a*c)*e)]
    @test_int [cot(d + e*x)^3/(a + b*tan(d + e*x) + c*tan(d + e*x)^2)^(3/2), x, 18, atanh((2*a + b*tan(d + e*x))/(2*sqrt(a)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2)))/(a^(3/2)*e) - (3*(5*b^2 - 4*a*c)*atanh((2*a + b*tan(d + e*x))/(2*sqrt(a)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(8*a^(7/2)*e) + (sqrt(2*a - 2*c - sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 + (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*atanh((b^2 - (a - c)*(a - c + sqrt(a^2 + b^2 - 2*a*c + c^2)) - b*(2*a - 2*c - sqrt(a^2 + b^2 - 2*a*c + c^2))*tan(d + e*x))/(sqrt(2)*sqrt(2*a - 2*c - sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 + (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(3/2)*e) - (sqrt(2*a - 2*c + sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 - (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*atanh((b^2 - (a - c)*(a - c - sqrt(a^2 + b^2 - 2*a*c + c^2)) - b*(2*a - 2*c + sqrt(a^2 + b^2 - 2*a*c + c^2))*tan(d + e*x))/(sqrt(2)*sqrt(2*a - 2*c + sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a^2 - b^2 - 2*a*c + c^2 - (a - c)*sqrt(a^2 + b^2 - 2*a*c + c^2))*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))))/(sqrt(2)*(a^2 + b^2 - 2*a*c + c^2)^(3/2)*e) - (2*(b^2 - 2*a*c + b*c*tan(d + e*x)))/(a*(b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2)) + (2*cot(d + e*x)^2*(b^2 - 2*a*c + b*c*tan(d + e*x)))/(a*(b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2)) + (2*(a*(b^2 - 2*(a - c)*c) + b*c*(a + c)*tan(d + e*x)))/((b^2 + (a - c)^2)*(b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2)) + (b*(15*b^2 - 52*a*c)*cot(d + e*x)*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))/(4*a^3*(b^2 - 4*a*c)*e) - ((5*b^2 - 12*a*c)*cot(d + e*x)^2*sqrt(a + b*tan(d + e*x) + c*tan(d + e*x)^2))/(2*a^2*(b^2 - 4*a*c)*e)]

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*tan(d+e*x)^m*(a+b*tan(d+e*x)^2+c*tan(d+e*x)^4)^(p/2)=#

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

    @test_int [tan(d + e*x)^5*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4), x, 9, -((sqrt(a - b + c)*atanh((2*a - b + (b - 2*c)*tan(d + e*x)^2)/(2*sqrt(a - b + c)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))))/(2*e)) + ((b^3 + 2*b^2*c - 4*b*(a - 2*c)*c - 8*c^2*(a + 2*c))*atanh((b + 2*c*tan(d + e*x)^2)/(2*sqrt(c)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))))/(32*c^(5/2)*e) - (((b - 2*c)*(b + 4*c) + 2*c*(b + 2*c)*tan(d + e*x)^2)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))/(16*c^2*e) + (a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)^(3/2)/(6*c*e)]
    @test_int [tan(d + e*x)^3*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4), x, 8, (sqrt(a - b + c)*atanh((2*a - b + (b - 2*c)*tan(d + e*x)^2)/(2*sqrt(a - b + c)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))))/(2*e) - ((b^2 + 4*b*c - 4*c*(a + 2*c))*atanh((b + 2*c*tan(d + e*x)^2)/(2*sqrt(c)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))))/(16*c^(3/2)*e) + ((b - 4*c + 2*c*tan(d + e*x)^2)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))/(8*c*e)]
    @test_int [tan(d + e*x)^1*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4), x, 8, -((sqrt(a - b + c)*atanh((2*a - b + (b - 2*c)*tan(d + e*x)^2)/(2*sqrt(a - b + c)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))))/(2*e)) + ((b - 2*c)*atanh((b + 2*c*tan(d + e*x)^2)/(2*sqrt(c)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))))/(4*sqrt(c)*e) + sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(2*e)]
    @test_int [cot(d + e*x)^1*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4), x, 10, -((sqrt(a)*atanh((2*a + b*tan(d + e*x)^2)/(2*sqrt(a)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))))/(2*e)) + (sqrt(a - b + c)*atanh((2*a - b + (b - 2*c)*tan(d + e*x)^2)/(2*sqrt(a - b + c)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))))/(2*e) + (sqrt(c)*atanh((b + 2*c*tan(d + e*x)^2)/(2*sqrt(c)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))))/(2*e)]
    @test_int [cot(d + e*x)^3*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4), x, 22, (sqrt(a)*atanh((2*a + b*tan(d + e*x)^2)/(2*sqrt(a)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))))/(2*e) - (b*atanh((2*a + b*tan(d + e*x)^2)/(2*sqrt(a)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))))/(4*sqrt(a)*e) - (sqrt(a - b + c)*atanh((2*a - b + (b - 2*c)*tan(d + e*x)^2)/(2*sqrt(a - b + c)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))))/(2*e) - (b*atanh((b + 2*c*tan(d + e*x)^2)/(2*sqrt(c)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))))/(4*sqrt(c)*e) + ((b - 2*c)*atanh((b + 2*c*tan(d + e*x)^2)/(2*sqrt(c)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))))/(4*sqrt(c)*e) + (sqrt(c)*atanh((b + 2*c*tan(d + e*x)^2)/(2*sqrt(c)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))))/(2*e) - (cot(d + e*x)^2*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))/(2*e)]

    @test_int [tan(d + e*x)^2*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4), x, 14, -((sqrt(a - b + c)*atan((sqrt(a - b + c)*tan(d + e*x))/sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)))/(2*e)) + (tan(d + e*x)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))/(3*e) + (b*tan(d + e*x)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))/(3*sqrt(c)*e*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)) - (sqrt(c)*tan(d + e*x)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))/(e*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)) - (a^(1/4)*b*Elliptic.E(2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(3*c^(3/4)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) + (a^(1/4)*c^(1/4)*Elliptic.E(2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) + (a^(1/4)*(b + 2*sqrt(a)*sqrt(c))*Elliptic.F(2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(6*c^(3/4)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) - ((b + sqrt(a)*sqrt(c) - c)*Elliptic.F(2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(2*a^(1/4)*c^(1/4)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) + (c^(1/4)*(a - b + c)*Elliptic.F(2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(2*a^(1/4)*(sqrt(a) - sqrt(c))*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) - ((sqrt(a) + sqrt(c))*(a - b + c)*Elliptic.Pi(-((sqrt(a) - sqrt(c))^2/(4*sqrt(a)*sqrt(c))), 2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(4*a^(1/4)*(sqrt(a) - sqrt(c))*c^(1/4)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))]
    @test_int [tan(d + e*x)^0*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4), x, 8, (sqrt(a - b + c)*atan((sqrt(a - b + c)*tan(d + e*x))/sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)))/(2*e) + (sqrt(c)*tan(d + e*x)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))/(e*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)) - (a^(1/4)*c^(1/4)*Elliptic.E(2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) + ((b + sqrt(a)*sqrt(c) - c)*Elliptic.F(2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(2*a^(1/4)*c^(1/4)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) - (c^(1/4)*(a - b + c)*Elliptic.F(2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(2*a^(1/4)*(sqrt(a) - sqrt(c))*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) + ((sqrt(a) + sqrt(c))*(a - b + c)*Elliptic.Pi(-((sqrt(a) - sqrt(c))^2/(4*sqrt(a)*sqrt(c))), 2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(4*a^(1/4)*(sqrt(a) - sqrt(c))*c^(1/4)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))]
    @test_int [cot(d + e*x)^2*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4), x, 9, -((sqrt(a - b + c)*atan((sqrt(a - b + c)*tan(d + e*x))/sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)))/(2*e)) - (cot(d + e*x)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))/e + (sqrt(c)*tan(d + e*x)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))/(e*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)) - (a^(1/4)*c^(1/4)*Elliptic.E(2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) + ((sqrt(a) + sqrt(c))*c^(1/4)*Elliptic.F(2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(2*a^(1/4)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) + (c^(1/4)*(a - b + c)*Elliptic.F(2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(2*a^(1/4)*(sqrt(a) - sqrt(c))*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) - ((sqrt(a) + sqrt(c))*(a - b + c)*Elliptic.Pi(-((sqrt(a) - sqrt(c))^2/(4*sqrt(a)*sqrt(c))), 2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(4*a^(1/4)*(sqrt(a) - sqrt(c))*c^(1/4)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))]
    @test_int [cot(d + e*x)^4*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4), x, 10, (sqrt(a - b + c)*atan((sqrt(a - b + c)*tan(d + e*x))/sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)))/(2*e) + ((3*a - b)*cot(d + e*x)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))/(3*a*e) - (cot(d + e*x)^3*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))/(3*e) - ((3*a - b)*sqrt(c)*tan(d + e*x)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))/(3*a*e*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)) + ((3*a - b)*c^(1/4)*Elliptic.E(2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(3*a^(3/4)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) - ((3*a - b + sqrt(a)*sqrt(c))*c^(1/4)*Elliptic.F(2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(6*a^(3/4)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) - (c^(1/4)*(a - b + c)*Elliptic.F(2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(2*a^(1/4)*(sqrt(a) - sqrt(c))*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) + ((sqrt(a) + sqrt(c))*(a - b + c)*Elliptic.Pi(-((sqrt(a) - sqrt(c))^2/(4*sqrt(a)*sqrt(c))), 2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(4*a^(1/4)*(sqrt(a) - sqrt(c))*c^(1/4)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))]

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

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

    @test_int [tan(d + e*x)^4/sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4), x, 5, atan((sqrt(a - b + c)*tan(d + e*x))/sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))/(2*sqrt(a - b + c)*e) + (tan(d + e*x)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))/(sqrt(c)*e*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)) - (a^(1/4)*Elliptic.E(2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(c^(3/4)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) + (a^(1/4)*(sqrt(a) - 2*sqrt(c))*Elliptic.F(2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(2*(sqrt(a) - sqrt(c))*c^(3/4)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) + ((sqrt(a) + sqrt(c))*Elliptic.Pi(-((sqrt(a) - sqrt(c))^2/(4*sqrt(a)*sqrt(c))), 2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(4*a^(1/4)*(sqrt(a) - sqrt(c))*c^(1/4)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))]
    @test_int [tan(d + e*x)^2/sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4), x, 4, -(atan((sqrt(a - b + c)*tan(d + e*x))/sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))/(2*sqrt(a - b + c)*e)) + (a^(1/4)*Elliptic.F(2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(2*(sqrt(a) - sqrt(c))*c^(1/4)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) - ((sqrt(a) + sqrt(c))*Elliptic.Pi(-((sqrt(a) - sqrt(c))^2/(4*sqrt(a)*sqrt(c))), 2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(4*a^(1/4)*(sqrt(a) - sqrt(c))*c^(1/4)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))]
    @test_int [tan(d + e*x)^0/sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4), x, 4, atan((sqrt(a - b + c)*tan(d + e*x))/sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))/(2*sqrt(a - b + c)*e) - (c^(1/4)*Elliptic.F(2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(2*a^(1/4)*(sqrt(a) - sqrt(c))*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) + ((sqrt(a) + sqrt(c))*Elliptic.Pi(-((sqrt(a) - sqrt(c))^2/(4*sqrt(a)*sqrt(c))), 2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(4*a^(1/4)*(sqrt(a) - sqrt(c))*c^(1/4)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))]
    @test_int [cot(d + e*x)^2/sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4), x, 7, -(atan((sqrt(a - b + c)*tan(d + e*x))/sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))/(2*sqrt(a - b + c)*e)) - (cot(d + e*x)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))/(a*e) + (sqrt(c)*tan(d + e*x)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))/(a*e*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)) - (c^(1/4)*Elliptic.E(2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(a^(3/4)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) + ((2*sqrt(a) - sqrt(c))*c^(1/4)*Elliptic.F(2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(2*a^(3/4)*(sqrt(a) - sqrt(c))*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) - ((sqrt(a) + sqrt(c))*Elliptic.Pi(-((sqrt(a) - sqrt(c))^2/(4*sqrt(a)*sqrt(c))), 2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(4*a^(1/4)*(sqrt(a) - sqrt(c))*c^(1/4)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))]

    @test_int [tan(d + e*x)^7/(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)^(3/2), x, 8, atanh((2*a - b + (b - 2*c)*tan(d + e*x)^2)/(2*sqrt(a - b + c)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)))/(2*(a - b + c)^(3/2)*e) + atanh((b + 2*c*tan(d + e*x)^2)/(2*sqrt(c)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)))/(2*c^(3/2)*e) + (a*(b^2 - a*(b + 2*c)) + (b^3 + 2*a^2*c - a*b*(b + 3*c))*tan(d + e*x)^2)/(c*(a - b + c)*(b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))]
    @test_int [tan(d + e*x)^5/(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)^(3/2), x, 6, -(atanh((2*a - b + (b - 2*c)*tan(d + e*x)^2)/(2*sqrt(a - b + c)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)))/(2*(a - b + c)^(3/2)*e)) + (a*(2*a - b) + ((a - b)*b + 2*a*c)*tan(d + e*x)^2)/((a - b + c)*(b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))]
    @test_int [tan(d + e*x)^3/(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)^(3/2), x, 6, atanh((2*a - b + (b - 2*c)*tan(d + e*x)^2)/(2*sqrt(a - b + c)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)))/(2*(a - b + c)^(3/2)*e) - (a*(b - 2*c) + (2*a - b)*c*tan(d + e*x)^2)/((a - b + c)*(b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))]
    @test_int [tan(d + e*x)^1/(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)^(3/2), x, 6, -(atanh((2*a - b + (b - 2*c)*tan(d + e*x)^2)/(2*sqrt(a - b + c)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)))/(2*(a - b + c)^(3/2)*e)) + (b^2 - 2*a*c - b*c + (b - 2*c)*c*tan(d + e*x)^2)/((a - b + c)*(b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))]
    @test_int [cot(d + e*x)^1/(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)^(3/2), x, 12, -(atanh((2*a + b*tan(d + e*x)^2)/(2*sqrt(a)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)))/(2*a^(3/2)*e)) + atanh((2*a - b + (b - 2*c)*tan(d + e*x)^2)/(2*sqrt(a - b + c)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)))/(2*(a - b + c)^(3/2)*e) + (b^2 - 2*a*c + b*c*tan(d + e*x)^2)/(a*(b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) - (b^2 - 2*a*c - b*c + (b - 2*c)*c*tan(d + e*x)^2)/((a - b + c)*(b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))]
    @test_int [cot(d + e*x)^3/(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)^(3/2), x, 16, atanh((2*a + b*tan(d + e*x)^2)/(2*sqrt(a)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)))/(2*a^(3/2)*e) + (3*b*atanh((2*a + b*tan(d + e*x)^2)/(2*sqrt(a)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))))/(4*a^(5/2)*e) - atanh((2*a - b + (b - 2*c)*tan(d + e*x)^2)/(2*sqrt(a - b + c)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)))/(2*(a - b + c)^(3/2)*e) - (b^2 - 2*a*c + b*c*tan(d + e*x)^2)/(a*(b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) + (cot(d + e*x)^2*(b^2 - 2*a*c + b*c*tan(d + e*x)^2))/(a*(b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) + (b^2 - 2*a*c - b*c + (b - 2*c)*c*tan(d + e*x)^2)/((a - b + c)*(b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) - ((3*b^2 - 8*a*c)*cot(d + e*x)^2*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))/(2*a^2*(b^2 - 4*a*c)*e)]

    @test_int [tan(d + e*x)^2/(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)^(3/2), x, 9, -(atan((sqrt(a - b + c)*tan(d + e*x))/sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))/(2*(a - b + c)^(3/2)*e)) + (tan(d + e*x)*(b^2 - 2*a*c - b*c + (b - 2*c)*c*tan(d + e*x)^2))/((a - b + c)*(b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) - ((b - 2*c)*sqrt(c)*tan(d + e*x)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))/((a - b + c)*(b^2 - 4*a*c)*e*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)) + (a^(1/4)*(b - 2*c)*c^(1/4)*Elliptic.E(2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/((a - b + c)*(b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) + (c^(1/4)*Elliptic.F(2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(2*a^(1/4)*(sqrt(a) - sqrt(c))*(a - b + c)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) - ((sqrt(a) - sqrt(c))*c^(1/4)*Elliptic.F(2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(2*a^(1/4)*(b - 2*sqrt(a)*sqrt(c))*(a - b + c)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) - ((sqrt(a) + sqrt(c))*Elliptic.Pi(-((sqrt(a) - sqrt(c))^2/(4*sqrt(a)*sqrt(c))), 2*atan((c^(1/4)*tan(d + e*x))/a^(1/4)), (1/4)*(2 - b/(sqrt(a)*sqrt(c))))*(sqrt(a) + sqrt(c)*tan(d + e*x)^2)*sqrt((a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)/(sqrt(a) + sqrt(c)*tan(d + e*x)^2)^2))/(4*a^(1/4)*(sqrt(a) - sqrt(c))*c^(1/4)*(a - b + c)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))]
    #= [cot(d + e*x)^2/(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)^(3/2), x, 21, (cot(d + e*x)*(b^2 - 2*a*c + b*c*tan(d + e*x)^2))/(a*(b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) + ((b^2 - 3*a*c)*(b - sqrt(b^2 - 4*a*c))*sqrt(b + sqrt(b^2 - 4*a*c))*Elliptic.E(asin((sqrt(2)*sqrt(-c)*tan(d + e*x))/sqrt(b + sqrt(b^2 - 4*a*c))), (b + sqrt(b^2 - 4*a*c))/(b - sqrt(b^2 - 4*a*c)))*sqrt(1 + (2*c*tan(d + e*x)^2)/(b - sqrt(b^2 - 4*a*c)))*sqrt(1 + (2*c*tan(d + e*x)^2)/(b + sqrt(b^2 - 4*a*c))))/(sqrt(2)*a^2*sqrt(-c)*(b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) - (sqrt(b + sqrt(b^2 - 4*a*c))*(b^3 - 4*a*b*c - sqrt(b^2 - 4*a*c)*(b^2 - 3*a*c))*Elliptic.F(asin((sqrt(2)*sqrt(-c)*tan(d + e*x))/sqrt(b + sqrt(b^2 - 4*a*c))), (b + sqrt(b^2 - 4*a*c))/(b - sqrt(b^2 - 4*a*c)))*sqrt(1 + (2*c*tan(d + e*x)^2)/(b - sqrt(b^2 - 4*a*c)))*sqrt(1 + (2*c*tan(d + e*x)^2)/(b + sqrt(b^2 - 4*a*c))))/(sqrt(2)*a^2*sqrt(-c)*(b^2 - 4*a*c)*e*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4)) - (2*(b^2 - 3*a*c)*cot(d + e*x)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))/(a^2*(b^2 - 4*a*c)*e) - ((b - sqrt(b^2 - 4*a*c))^2*tan(d + e*x)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))/(4*a^2*(a - b + c)*sqrt(b^2 - 4*a*c)*e*(1 + (2*c*tan(d + e*x)^2)/(b + sqrt(b^2 - 4*a*c)))) + (b*c*tan(d + e*x)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))/(a^2*(b^2 - 4*a*c)*(1 - (2*c)/(b - sqrt(b^2 - 4*a*c)))*e*(1 + (2*c*tan(d + e*x)^2)/(b + sqrt(b^2 - 4*a*c)))) + (c*(1 + b/sqrt(b^2 - 4*a*c))*tan(d + e*x)*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))/(a^2*(b - 2*c - sqrt(b^2 - 4*a*c))*e*(1 + (2*c*tan(d + e*x)^2)/(b - sqrt(b^2 - 4*a*c)))*(1 + (2*c*tan(d + e*x)^2)/(b + sqrt(b^2 - 4*a*c)))) - (sqrt(-c)*sqrt(b - sqrt(b^2 - 4*a*c))*Elliptic.E(asin((sqrt(2)*sqrt(-c)*tan(d + e*x))/sqrt(b - sqrt(b^2 - 4*a*c))), (b - sqrt(b^2 - 4*a*c))/(b + sqrt(b^2 - 4*a*c)))*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))/(sqrt(2)*a*(a - b + c)*sqrt(b^2 - 4*a*c)*e*sqrt(1 + (2*c*tan(d + e*x)^2)/(b - sqrt(b^2 - 4*a*c)))*sqrt(1 + (2*c*tan(d + e*x)^2)/(b + sqrt(b^2 - 4*a*c)))) + (b*(b - sqrt(b^2 - 4*a*c))^3*(b + sqrt(b^2 - 4*a*c))^(5/2)*Elliptic.E(asin((sqrt(2)*sqrt(-c)*tan(d + e*x))/sqrt(b + sqrt(b^2 - 4*a*c))), (b + sqrt(b^2 - 4*a*c))/(b - sqrt(b^2 - 4*a*c)))*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))/(16*sqrt(2)*a^4*(-c)^(3/2)*(b^2 - 4*a*c)*(b - 2*c - sqrt(b^2 - 4*a*c))*e*sqrt(1 + (2*c*tan(d + e*x)^2)/(b - sqrt(b^2 - 4*a*c)))*sqrt(1 + (2*c*tan(d + e*x)^2)/(b + sqrt(b^2 - 4*a*c)))) - ((b - sqrt(b^2 - 4*a*c))^2*(b + sqrt(b^2 - 4*a*c))^(5/2)*(b^2 - 4*a*c - b*sqrt(b^2 - 4*a*c))*Elliptic.F(asin((sqrt(2)*sqrt(-c)*tan(d + e*x))/sqrt(b + sqrt(b^2 - 4*a*c))), (b + sqrt(b^2 - 4*a*c))/(b - sqrt(b^2 - 4*a*c)))*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))/(16*sqrt(2)*a^4*(-c)^(3/2)*(b^2 - 4*a*c)*(b - 2*c - sqrt(b^2 - 4*a*c))*e*sqrt(1 + (2*c*tan(d + e*x)^2)/(b - sqrt(b^2 - 4*a*c)))*sqrt(1 + (2*c*tan(d + e*x)^2)/(b + sqrt(b^2 - 4*a*c)))) - (sqrt(b - sqrt(b^2 - 4*a*c))*Elliptic.Pi((b - sqrt(b^2 - 4*a*c))/(2*c), asin((sqrt(2)*sqrt(-c)*tan(d + e*x))/sqrt(b - sqrt(b^2 - 4*a*c))), (b - sqrt(b^2 - 4*a*c))/(b + sqrt(b^2 - 4*a*c)))*sqrt(a + b*tan(d + e*x)^2 + c*tan(d + e*x)^4))/(sqrt(2)*a*sqrt(-c)*(a - b + c)*e*sqrt(1 + (2*c*tan(d + e*x)^2)/(b - sqrt(b^2 - 4*a*c)))*sqrt(1 + (2*c*tan(d + e*x)^2)/(b + sqrt(b^2 - 4*a*c))))] =#
    end

max_stars_repo_path: test/4 Trig functions/4.3 Tangent/4.3.9 trig^m (a+b tan^n+c tan^(2 n))^p.jl


text:
module Operators

# Spacings
export Δxᶠᶠᶠ, Δxᶠᶠᶜ, Δxᶠᶜᶠ, Δxᶠᶜᶜ, Δxᶜᶠᶠ, Δxᶜᶠᶜ, Δxᶜᶜᶠ, Δxᶜᶜᶜ
export Δyᶠᶠᶠ, Δyᶠᶠᶜ, Δyᶠᶜᶠ, Δyᶠᶜᶜ, Δyᶜᶠᶠ, Δyᶜᶠᶜ, Δyᶜᶜᶠ, Δyᶜᶜᶜ
export Δzᶠᶠᶠ, Δzᶠᶠᶜ, Δzᶠᶜᶠ, Δzᶠᶜᶜ, Δzᶜᶠᶠ, Δzᶜᶠᶜ, Δzᶜᶜᶠ, Δzᶜᶜᶜ

# Areas
export Axᶠᶠᶠ, Axᶠᶠᶜ, Axᶠᶜᶠ, Axᶠᶜᶜ, Axᶜᶠᶠ, Axᶜᶠᶜ, Axᶜᶜᶠ, Axᶜᶜᶜ
export Ayᶠᶠᶠ, Ayᶠᶠᶜ, Ayᶠᶜᶠ, Ayᶠᶜᶜ, Ayᶜᶠᶠ, Ayᶜᶠᶜ, Ayᶜᶜᶠ, Ayᶜᶜᶜ
export Azᶠᶠᶠ, Azᶠᶠᶜ, Azᶠᶜᶠ, Azᶠᶜᶜ, Azᶜᶠᶠ, Azᶜᶠᶜ, Azᶜᶜᶠ, Azᶜᶜᶜ

# Volumes
export Vᶠᶠᶠ, Vᶠᶠᶜ, Vᶠᶜᶠ, Vᶠᶜᶜ, Vᶜᶠᶠ, Vᶜᶠᶜ, Vᶜᶜᶠ, Vᶜᶜᶜ

# Product between spacings and fields
export Δx_qᶠᶠᶠ, Δx_qᶠᶠᶜ, Δx_qᶠᶜᶠ, Δx_qᶠᶜᶜ, Δx_qᶜᶠᶠ, Δx_qᶜᶠᶜ, Δx_qᶜᶜᶠ, Δx_qᶜᶜᶜ
export Δy_qᶠᶠᶠ, Δy_qᶠᶠᶜ, Δy_qᶠᶜᶠ, Δy_qᶠᶜᶜ, Δy_qᶜᶠᶠ, Δy_qᶜᶠᶜ, Δy_qᶜᶜᶠ, Δy_qᶜᶜᶜ
export Δz_qᶠᶠᶠ, Δz_qᶠᶠᶜ, Δz_qᶠᶜᶠ, Δz_qᶠᶜᶜ, Δz_qᶜᶠᶠ, Δz_qᶜᶠᶜ, Δz_qᶜᶜᶠ, Δz_qᶜᶜᶜ

# Product between areas and fields
export Ax_qᶠᶠᶠ, Ax_qᶠᶠᶜ, Ax_qᶠᶜᶠ, Ax_qᶠᶜᶜ, Ax_qᶜᶠᶠ, Ax_qᶜᶠᶜ, Ax_qᶜᶜᶠ, Ax_qᶜᶜᶜ
export Ay_qᶠᶠᶠ, Ay_qᶠᶠᶜ, Ay_qᶠᶜᶠ, Ay_qᶠᶜᶜ, Ay_qᶜᶠᶠ, Ay_qᶜᶠᶜ, Ay_qᶜᶜᶠ, Ay_qᶜᶜᶜ
export Az_qᶠᶠᶠ, Az_qᶠᶠᶜ, Az_qᶠᶜᶠ, Az_qᶠᶜᶜ, Az_qᶜᶠᶠ, Az_qᶜᶠᶜ, Az_qᶜᶜᶠ, Az_qᶜᶜᶜ

# Differences
export δxᶜᵃᵃ, δxᶠᵃᵃ, δyᵃᶜᵃ, δyᵃᶠᵃ, δzᵃᵃᶜ, δzᵃᵃᶠ

# Derivatives
export ∂xᶠᶠᶠ, ∂xᶠᶠᶜ, ∂xᶠᶜᶠ, ∂xᶠᶜᶜ, ∂xᶜᶠᶠ, ∂xᶜᶠᶜ, ∂xᶜᶜᶠ, ∂xᶜᶜᶜ
export ∂yᶠᶠᶠ, ∂yᶠᶠᶜ, ∂yᶠᶜᶠ, ∂yᶠᶜᶜ, ∂yᶜᶠᶠ, ∂yᶜᶠᶜ, ∂yᶜᶜᶠ, ∂yᶜᶜᶜ
export ∂zᶠᶠᶠ, ∂zᶠᶠᶜ, ∂zᶠᶜᶠ, ∂zᶠᶜᶜ, ∂zᶜᶠᶠ, ∂zᶜᶠᶜ, ∂zᶜᶜᶠ, ∂zᶜᶜᶜ

export ∂²xᶠᶠᶠ, ∂²xᶠᶠᶜ, ∂²xᶠᶜᶠ, ∂²xᶠᶜᶜ, ∂²xᶜᶠᶠ, ∂²xᶜᶠᶜ, ∂²xᶜᶜᶠ, ∂²xᶜᶜᶜ
export ∂²yᶠᶠᶠ, ∂²yᶠᶠᶜ, ∂²yᶠᶜᶠ, ∂²yᶠᶜᶜ, ∂²yᶜᶠᶠ, ∂²yᶜᶠᶜ, ∂²yᶜᶜᶠ, ∂²yᶜᶜᶜ
export ∂²zᶠᶠᶠ, ∂²zᶠᶠᶜ, ∂²zᶠᶜᶠ, ∂²zᶠᶜᶜ, ∂²zᶜᶠᶠ, ∂²zᶜᶠᶜ, ∂²zᶜᶜᶠ, ∂²zᶜᶜᶜ

export ∂³xᶠᶠᶠ, ∂³xᶠᶠᶜ, ∂³xᶠᶜᶠ, ∂³xᶠᶜᶜ, ∂³xᶜᶠᶠ, ∂³xᶜᶠᶜ, ∂³xᶜᶜᶠ, ∂³xᶜᶜᶜ
export ∂³yᶠᶠᶠ, ∂³yᶠᶠᶜ, ∂³yᶠᶜᶠ, ∂³yᶠᶜᶜ, ∂³yᶜᶠᶠ, ∂³yᶜᶠᶜ, ∂³yᶜᶜᶠ, ∂³yᶜᶜᶜ
export ∂³zᶠᶠᶠ, ∂³zᶠᶠᶜ, ∂³zᶠᶜᶠ, ∂³zᶠᶜᶜ, ∂³zᶜᶠᶠ, ∂³zᶜᶠᶜ, ∂³zᶜᶜᶠ, ∂³zᶜᶜᶜ

export ∂⁴xᶠᶠᶠ, ∂⁴xᶠᶠᶜ, ∂⁴xᶠᶜᶠ, ∂⁴xᶠᶜᶜ, ∂⁴xᶜᶠᶠ, ∂⁴xᶜᶠᶜ, ∂⁴xᶜᶜᶠ, ∂⁴xᶜᶜᶜ
export ∂⁴yᶠᶠᶠ, ∂⁴yᶠᶠᶜ, ∂⁴yᶠᶜᶠ, ∂⁴yᶠᶜᶜ, ∂⁴yᶜᶠᶠ, ∂⁴yᶜᶠᶜ, ∂⁴yᶜᶜᶠ, ∂⁴yᶜᶜᶜ
export ∂⁴zᶠᶠᶠ, ∂⁴zᶠᶠᶜ, ∂⁴zᶠᶜᶠ, ∂⁴zᶠᶜᶜ, ∂⁴zᶜᶠᶠ, ∂⁴zᶜᶠᶜ, ∂⁴zᶜᶜᶠ, ∂⁴zᶜᶜᶜ

# Product between areas and derivatives
export Ax_∂xᶠᶠᶠ, Ax_∂xᶠᶠᶜ, Ax_∂xᶠᶜᶠ, Ax_∂xᶠᶜᶜ, Ax_∂xᶜᶠᶠ, Ax_∂xᶜᶠᶜ, Ax_∂xᶜᶜᶠ, Ax_∂xᶜᶜᶜ
export Ay_∂yᶠᶠᶠ, Ay_∂yᶠᶠᶜ, Ay_∂yᶠᶜᶠ, Ay_∂yᶠᶜᶜ, Ay_∂yᶜᶠᶠ, Ay_∂yᶜᶠᶜ, Ay_∂yᶜᶜᶠ, Ay_∂yᶜᶜᶜ
export Az_∂zᶠᶠᶠ, Az_∂zᶠᶠᶜ, Az_∂zᶠᶜᶠ, Az_∂zᶠᶜᶜ, Az_∂zᶜᶠᶠ, Az_∂zᶜᶠᶜ, Az_∂zᶜᶜᶠ, Az_∂zᶜᶜᶜ

# Divergences
export divᶜᶜᶜ, div_xyᶜᶜᶜ, ζ₃ᶠᶠᶜ
export ∇²ᶜᶜᶜ, ∇²ᶠᶜᶜ, ∇²ᶜᶠᶜ, ∇²ᶜᶜᶠ, ∇²hᶜᶜᶜ, ∇²hᶠᶜᶜ, ∇²hᶜᶠᶜ

# Interpolations
export ℑxᶜᵃᵃ, ℑxᶠᵃᵃ, ℑyᵃᶜᵃ, ℑyᵃᶠᵃ, ℑzᵃᵃᶜ, ℑzᵃᵃᶠ
export ℑᴶxᶜᵃᵃ, ℑᴶxᶠᵃᵃ, ℑᴶyᵃᶜᵃ, ℑᴶyᵃᶠᵃ, ℑᴶzᵃᵃᶜ, ℑᴶzᵃᵃᶠ
export ℑxyᶜᶜᵃ, ℑxyᶠᶜᵃ, ℑxyᶠᶠᵃ, ℑxyᶜᶠᵃ, ℑxzᶜᵃᶜ, ℑxzᶠᵃᶜ, ℑxzᶠᵃᶠ, ℑxzᶜᵃᶠ, ℑyzᵃᶜᶜ, ℑyzᵃᶠᶜ, ℑyzᵃᶠᶠ, ℑyzᵃᶜᶠ
export ℑxyzᶜᶜᶠ, ℑxyzᶜᶠᶜ, ℑxyzᶠᶜᶜ, ℑxyzᶜᶠᶠ, ℑxyzᶠᶜᶠ, ℑxyzᶠᶠᶜ

using Oceananigans.Grids

#####
##### Convenient aliases
#####

const AG   = AbstractGrid
const ARG  = AbstractRectilinearGrid
const RCG  = RectilinearGrid
const ACG  = AbstractCurvilinearGrid
const AHCG = AbstractHorizontallyCurvilinearGrid

include("difference_operators.jl")
include("interpolation_operators.jl")
include("interpolation_utils.jl")

include("spacings_and_areas_and_volumes.jl")
include("products_between_fields_and_grid_metrics.jl")

include("derivative_operators.jl")
include("divergence_operators.jl")
include("vorticity_operators.jl")
include("laplacian_operators.jl")

end # module

ext: jl


text:
#
# These scripts were used to process the UKB data for the 18 metabolomic traits
# analysis featured in the multivariate IHT paper. This file was not intended
# to be distributed, hence is not written in the most streamlined/readable way.
# Nevertheless, we provide this script in the hope that it will be useful to others.
#

#
# After running the script, the final result are:
# Phenotype file (not standardized, with header and family-ID): phenotypes.reordered.csv
# Final phenotype file (standardized, without header/family-ID): phenotypes.reordered.standardized.csv
# Final covariates file (with family ID, not standardized): covariates.reordered.csv
# Final covariates file (without family ID, standardized, extra intercept column): covariates.reordered.standardized.csv
# Final genotype file: ukb.merged.metabolic.subset.european.400K.QC.bed
#

using SnpArrays, CSV, DataFrames, DelimitedFiles, MendelIHT
global propca_exe = "/scratch/users/bbchu/ProPCA/build/propca"

# merge all chrom into 1 plink (note: this requires roughly 100GB of ram)
SnpArrays.merge_plink("ukb_chr", des="ukb.merged")

# keep only samples with phenotypes (we can match 121157 samples genotype to phenotypes)
merged = SnpData("ukb.merged")
y = CSV.read("phenotypes.csv", DataFrame)
phenotype_sampleID = y[:, 1]
genotype_sampleID = parse.(Int, merged.person_info[!, :fid])
keep_idx = indexin(phenotype_sampleID, genotype_sampleID)
filter!(x -> !isnothing(x), keep_idx)
keep_idx = sort!(convert(Vector{Int}, keep_idx))
rowidx = falses(1:size(merged.person_info, 1))
rowidx[keep_idx] .= true
SnpArrays.filter(merged, rowidx, 1:size(merged.snp_info, 1),
    des="ukb.merged.metabolic.subset")

# Get sample ancestry
pop_code = String[]
sampleID = String[]
cnt = 1
for line in eachline("/scratch/users/bbchu/ukb_iht/ukb40055.txt")
    if cnt == 1
        cnt += 1
        continue
    end
    l = split(line, '\t')
    id, population = l[2], l[6151]
    if id == "" || population == ""
        cnt += 1
        continue
    end
    push!(sampleID, id)
    push!(pop_code, population)
    cnt += 1
end
writedlm("UKB_sample_population_code.txt", [sampleID pop_code])

# only keep samples of European descent
sample_ancestry = CSV.read("UKB_sample_population_code.txt", DataFrame, header=false)
europeans = [1001, 1002, 1003]
european_idx = findall(x -> x in europeans, sample_ancestry[!, 2]) # 472128 samples
subset_merged = SnpData("ukb.merged.metabolic.subset")
subset_fam_file = subset_merged.person_info
to_keep_sampleID = sample_ancestry[european_idx, 1] ∩ parse.(Int, subset_fam_file[!, 1]) # 114256 samples
to_keep_sample_idx = findall(x -> x in to_keep_sampleID, parse.(Int, subset_fam_file[!, 1])) # 114256 samples
SnpArrays.filter(subset_merged, to_keep_sample_idx, 1:size(subset_merged.snp_info, 1),
    des="ukb.merged.metabolic.subset.european")

# filter for samples with 99% genotype success rate and only keep snps in blood pressure analysis
blood_pressure_bim = CSV.read("ukb.bloodpressure.filtered.bim", DataFrame, header=false)
euro_subset = SnpData("ukb.merged.metabolic.subset.european")
rmask, _ = SnpArrays.filter(euro_subset.snparray,
    min_success_rate_per_row = 0.99,  # 108352
    min_success_rate_per_col = 0.98)  # 580871
shared_snp_idx = indexin(euro_subset.snp_info[!, 2], blood_pressure_bim[!, 2])
cmask = trues(euro_subset.snps)
cmask[findall(isnothing, shared_snp_idx)] .= false # 470228
SnpArrays.filter(euro_subset, rmask, cmask,
    des="ukb.merged.metabolic.subset.european.400K")

# exclude 1st and 2nd relatives (i.e. GRM values > 0.125)
# note this requires 400-500 GB of memory
x = SnpArray("ukb.merged.metabolic.subset.european.400K.bed")
Φ = grm(x, method=:Robust, minmaf=0.05, t=Float32)
idx = findall(x -> x > 0.125, Φ)
xidx = [idx[i][1] for i in 1:length(idx)];
yidx = [idx[i][2] for i in 1:length(idx)];
writedlm("related_idx", [xidx yidx])
idx = Int.(readdlm("related_idx"))
related_samples = Int[]
for i in 1:size(idx, 1)
    if idx[i, 1] != idx[i, 2] # delete both for simplicity
        push!(related_samples, idx[i, 1])
        push!(related_samples, idx[i, 2])
    end
end
unique!(related_samples) # 4088
xdata = SnpData("ukb.merged.metabolic.subset.european.400K")
n, p = size(xdata)
cmask = trues(p)
rmask = trues(n)
rmask[related_samples] .= false # 104264 samples left
SnpArrays.filter(xdata, rmask, cmask,
    des="ukb.merged.metabolic.subset.european.400K.QC")

# compute PCA (this was pretty fast, around 1 hour)
seed = 2022
plinkname = "ukb.merged.metabolic.subset.european.400K.QC"
outfile = "ukb.merged.metabolic.subset.european.400K.QC."
run(`$propca_exe -g $plinkname -k 10 -o $outfile -nt $(Threads.nthreads()) -seed $seed`)

# filter phenotypes and reorder them so they match genotypes
# after all filtering, there are 104264 samples remaining
xdata = SnpData("ukb.merged.metabolic.subset.european.400K.QC")
y = CSV.read("phenotypes.csv", DataFrame) #121733 samples
phenotype_sampleID = y[:, 1]
genotype_sampleID = parse.(Int, xdata.person_info[!, :fid])
reorder_idx = indexin(genotype_sampleID, phenotype_sampleID) |> Vector{Int} # 104264 samples
n = length(reorder_idx)
p = size(y, 2)
y_reordered = zeros(n, p)
for i in 1:n
    row = reorder_idx[i]
    for j in 1:p
        y_reordered[i, j] = y[row, j]
    end
end
all(y_reordered[:, 1] .== genotype_sampleID) || error("bug in matching genotype ID to phenotype ID")
y_reordered_df = DataFrame(y_reordered, names(y))
y_reordered_df[!, 1] = y_reordered_df[!, 1] |> Vector{Int}
CSV.write("phenotypes.reordered.csv", y_reordered_df)

# log-transform and standardize phenotypes
y_df = CSV.read("phenotypes.reordered.csv", DataFrame)
y = Matrix(y_df[!, 2:end])
ylog = log.(y)
standardize!(ylog)
writedlm("phenotypes.reordered.standardized.csv", ylog, ',')

# Get sample age and BMI
sampleID, sample_age = String[], String[]
cnt = 1
for line in eachline("/scratch/users/bbchu/ukb_iht/ukb40055.txt")
    if cnt == 1
        cnt += 1
        continue
    end
    l = split(line, '\t')
    id, age = l[2], l[6162]
    if id == "" || age == ""
        cnt += 1
        continue
    end
    push!(sampleID, id)
    push!(sample_age, age)
    cnt += 1
end
writedlm("UKB_sample_age.txt", [sampleID sample_age])

# combine all non-genetic covariates (sex, bmi, age, age^2, PC1-PC10)
xdata = SnpData("ukb.merged.metabolic.subset.european.400K.QC")
z = readdlm("ukb.merged.metabolic.subset.european.400K.QC.projections.txt")
sex = parse.(Int, xdata.person_info[!, :sex]) # 1 = male, 2 = female
full_sample_age = readdlm("UKB_sample_age.txt")
cov_sampleID = full_sample_age[:, 1] |> Vector{Int}
genotype_sampleID = parse.(Int, xdata.person_info[!, :fid])
reorder_idx = indexin(genotype_sampleID, cov_sampleID) |> Vector{Int} # 104264 samples
n = length(reorder_idx)
age_reordered = zeros(n, 2)
for i in 1:n
    row = reorder_idx[i]
    for j in 1:2 # 1st column is sample ID, 2nd column is age
        age_reordered[i, j] = full_sample_age[row, j]
    end
end
all(age_reordered[:, 1] .== genotype_sampleID) || error("bug in matching genotype ID to age sample ID")
age = age_reordered[:, 2]
age_squared = age.^2
full_z = [genotype_sampleID sex age age_squared z]
column_name = ["genotype_sampleID", "sex", "age", "age_squared",
                "PC1", "PC2", "PC3", "PC4", "PC5", "PC6", "PC7", "PC8",
                "PC9", "PC10"]
z_full_df = DataFrame(full_z, column_name)
z_full_df[!, 1] = z_full_df[!, 1] |> Vector{Int} # convert Float64 columns to Int
z_full_df[!, 2] = z_full_df[!, 2] |> Vector{Int}
z_full_df[!, 3] = z_full_df[!, 3] |> Vector{Int}
z_full_df[!, 4] = z_full_df[!, 4] |> Vector{Int}
CSV.write("covariates.reordered.csv", z_full_df)

# standardize all covariates and include extra column of 1 as intercept
z_df = CSV.read("covariates.reordered.csv", DataFrame)
z = Matrix(z_df[!, 2:end])
standardize!(z)
z_full = [ones(size(z, 1)) z]
writedlm("covariates.reordered.standardized.csv", z_full, ',')

##
## Final result:
## Phenotype file (not standardized, with header and family-ID): phenotypes.reordered.csv
## Final phenotype file (standardized, without header/family-ID): phenotypes.reordered.standardized.csv
## Final covariates file (with family ID, not standardized): covariates.reordered.csv
## Final covariates file (without family ID, standardized, extra intercept column): covariates.reordered.standardized.csv
## Final genotype file: ukb.merged.metabolic.subset.european.400K.QC.bed
##


text:
using BlockArrays, Test

@testset "broadcast" begin
    @testset "BlockArray" begin
        A = BlockArray(randn(6), 1:3)

        @test BlockArrays.BroadcastStyle(typeof(A)) == BlockArrays.BlockStyle{1}()

        @test exp.(A) == exp.(Vector(A))
        @test blocksizes(A) == blocksizes(exp.(A))

        @test A+A isa BlockArray
        @test blocksizes(A + A) == blocksizes(A .+ A) == blocksizes(A)
        @test blocksizes(A .+ 1) == blocksizes(A)

        A = BlockArray(randn(6,6), 1:3,1:3)

        @test BlockArrays.BroadcastStyle(typeof(A)) == BlockArrays.BlockStyle{2}()

        @test exp.(A) == exp.(Matrix(A))
        @test blocksizes(A) == blocksizes(exp.(A))

        @test blocksizes(A + A) == blocksizes(A .+ A) == blocksizes(A)
        @test blocksizes(A .+ 1) == blocksizes(A)
    end

    @testset "PseudoBlockArray" begin
        A = PseudoBlockArray(randn(6), 1:3)

        @test BlockArrays.BroadcastStyle(typeof(A)) == BlockArrays.PseudoBlockStyle{1}()

        @test exp.(A) == exp.(Vector(A))
        @test blocksizes(A) == blocksizes(exp.(A))

        @test A+A isa PseudoBlockArray
        @test blocksizes(A + A) == blocksizes(A .+ A) == blocksizes(A)
        @test blocksizes(A .+ 1) == blocksizes(A)

        B = PseudoBlockArray(randn(6,6), 1:3,1:3)

        @test BlockArrays.BroadcastStyle(typeof(B)) == BlockArrays.PseudoBlockStyle{2}()

        @test exp.(B) == exp.(Matrix(B))
        @test blocksizes(B) == blocksizes(exp.(B))

        @test blocksizes(B + B) == blocksizes(B .+ B) == blocksizes(B)
        @test blocksizes(B .+ 1) == blocksizes(B)
        @test blocksizes(A .+ 1 .+ B) == blocksizes(B)
        @test A .+ 1 .+ B == Vector(A) .+ 1 .+ B == Vector(A) .+ 1 .+ Matrix(B)
    end

    @testset "Mixed" begin
        A = BlockArray(randn(6), 1:3)
        B = PseudoBlockArray(randn(6), 1:3)

        @test A + B isa BlockArray
        @test B + A isa BlockArray

        @test blocksizes(A + B) == blocksizes(A)

        C = randn(6)

        @test A + C isa BlockVector{Float64}
        @test C + A isa BlockVector{Float64}
        @test B + C isa PseudoBlockVector{Float64}
        @test C + B isa PseudoBlockVector{Float64}

        @test blocksizes(A+C) == blocksizes(C+A) == blocksizes(A)
        @test blocksizes(B+C) == blocksizes(C+B) == blocksizes(B)

        A = BlockArray(randn(6,6), 1:3, 1:3)
        D = Diagonal(ones(6))
        @test blocksizes(A + D) == blocksizes(A)
        @test blocksizes(B .+ D) == BlockArrays.BlockSizes([1,2,3],[6])
    end

    @testset "Mixed block sizes" begin
        A = BlockArray(randn(6), 1:3)
        B = BlockArray(randn(6), fill(2,3))
        @test blocksizes(A+B) == BlockArrays.BlockSizes([1,1,1,1,2])

        A = BlockArray(randn(6,6), 1:3, 1:3)
        B = BlockArray(randn(6,6), fill(2,3), fill(3,2))

        @test blocksizes(A+B) == BlockArrays.BlockSizes([1,1,1,1,2], 1:3)
    end

    @testset "UnitRange" begin
        n = 3
        x = mortar([1:4n, 1:n])
        @test eltype(x.blocks) <: UnitRange
        y = 1:length(x)
        z = randn(size(x))
        x2 = vcat(x.blocks...)
        y2 = copy(y)
        z2 = copy(z)
        @test (@. z = x + y + z; z) == (@. z2 = x2 + y2 + z2; z2)
    end

    @testset "Special broadcast" begin
        v = mortar([1:3,4:7])
        @test broadcast(+, v) isa BlockVector{Int,Vector{UnitRange{Int}}}
        @test broadcast(+, v) == v
        @test broadcast(-, v) isa BlockVector{Int,Vector{StepRange{Int,Int}}}
        @test broadcast(-, v) == -v == -Vector(v)
        @test broadcast(+, v, 1) isa BlockVector{Int,Vector{UnitRange{Int}}}
        @test broadcast(+, v, 1) == Vector(v).+1
        @test broadcast(*, 2, v) isa BlockVector{Int,Vector{StepRange{Int,Int}}}
        @test broadcast(*, 2, v) == 2Vector(v)
    end
end


text:
import Pkg

Pkg.add(path="https://github.com/jmurga/MKtest.jl")
Pkg.add(["Fire","IJulia","Parameters", "SparseArrays", "Distributed", "CSV", "JLD2", "DataFrames", "ProgressMeter", "Quadmath", "GZip", "StatsBase", "Unzip", "ThreadsX","Roots","NLsolve","SpecialFunctions","PoissonRandom","Distributions","Parsers","OrderedCollections","FastaIO","Random","LsqFit","HypothesisTests"])


text:
module Toolbox

import Base.string

using Revise, Genie, Genie.Util, Millboard, Genie.FileTemplates, Genie.Configuration, Genie.Loggers, Genie.Inflector

export TaskResult, VoidTaskResult, check_valid_task

const TASK_SUFFIX = "Task"

mutable struct TaskInfo
  file_name::String
  module_name::Symbol
  description::String
end

mutable struct TaskResult{T}
  code::Int
  message::String
  result::T
end

"""
    run_task(task_name::String; params...)
    function run_task(task::Module; params)

Runs the Genie task named `task_name`.
"""
function run_task(task_name::Union{String,Symbol}; params...)
  @time Base.invokelatest(import_task(string(task_name)).run_task, params)
end
function run_task(task::Module; params...)
  @time task.run_task(params)
end

"""
    import_task(task_name::String)

Brings the Genie task `task_name` into scope.
"""
function import_task(task_name::String) :: Module
  task_name = valid_task_name(task_name)
  tasks = all_tasks(filter_type_name = Symbol(task_name))

  if isempty(tasks)
    log("Task not found", :err)
    return
  end

  Core.eval(@__MODULE__, tasks[1].module_name)
  is_dev() && Revise.track(joinpath(Genie.TASKS_PATH, tasks[1].file_name))
end

function VoidTaskResult()
  TaskResult(0, "", nothing)
end

"""
    valid_task_name(task_name::String) :: String

Attempts to convert a potentially invalid (partial) `task_name` into a valid one.
"""
function valid_task_name(task_name::String) :: String
  task_name = replace(task_name, " "=>"_")
  task_name = Genie.Inflector.from_underscores(task_name)
  endswith(task_name, TASK_SUFFIX) || (task_name = task_name * TASK_SUFFIX)

  task_name
end

"""
    print_tasks() :: Nothing

Prints a list of all the registered Genie tasks to the standard output.
"""
function print_tasks() :: Nothing
  output = ""
  arr_output = []
  for t in all_tasks()
    td = Genie.to_dict(t)
    push!(arr_output, [td["module_name"], td["file_name"], td["description"]])
  end

  Millboard.table(arr_output, :colnames => ["Task name \nFilename \nDescription "], :rownames => []) |> println
end

"""
    tasks(; filter_type_name = Symbol()) :: Vector{TaskInfo}
    all_tasks(; filter_type_name = Symbol()) :: Vector{TaskInfo}

Returns a vector of all registered Genie tasks.
"""
function tasks(; filter_type_name = Symbol()) :: Vector{TaskInfo}
  tasks = TaskInfo[]

  f = readdir(Genie.config.tasks_folder)
  for i in f
    if ( endswith(i, "Task.jl") )
      module_name = Genie.Util.file_name_without_extension(i) |> Symbol
      include(joinpath(Genie.config.tasks_folder, i))
      Core.eval(@__MODULE__, :(using .$(module_name)))
      ti = TaskInfo(i, module_name, task_docs(module_name))

      if ( filter_type_name == Symbol() ) push!(tasks, ti)
      elseif ( filter_type_name == module_name ) return TaskInfo[ti]
      end
    end
  end

  tasks
end
const all_tasks = tasks

"""
    task_docs(module_name::Module) :: String

Retrieves the docstring of the run_task method and returns it as a string.
"""
function task_docs(module_name::Symbol) :: String
  try
    docs = Base.doc(Base.Docs.Binding(getfield(@__MODULE__, module_name), :run_task)) |> string
    startswith(docs, "No documentation found") && (docs = "No documentation found -- add docstring to `$(module_name).run_task()` to see it here.")

    docs
  catch ex
    log(ex, :err)
    ""
  end
end

"""
    new(cmd_args::Dict{String,Any}, config::Settings) :: Nothing
    new(task_name::String, config::Settings = App.config) :: Nothing

Generates a new Genie task file.
"""
function new(cmd_args::Dict{String,Any}, config::Settings = Genie.config) :: Nothing
  tfn = task_file_name(cmd_args, config)

  if ispath(tfn)
    error("Task file already exists")
  end

  f = open(tfn, "w")
  write(f, Genie.FileTemplates.new_task(task_module_name(cmd_args["task:new"])))
  close(f)

  log("New task created at $tfn")

  nothing
end
function new(task_name::String, config::Settings = Genie.config) :: Nothing
  new(Dict{String,Any}("task:new" => valid_task_name(task_name)), config)
end

"""
    task_file_name(cmd_args::Dict{String,Any}, config::Settings) :: String

Computes the name of a Genie task based on the command line input.
"""
function task_file_name(cmd_args::Dict{String,Any}, config::Settings = Genie.config) :: String
  joinpath(config.tasks_folder, cmd_args["task:new"] * ".jl")
end

"""
    task_module_name(underscored_task_name::String) :: String

Computes the name of a Genie task based on the command line input.
"""
function task_module_name(underscored_task_name::String) :: String
  mapreduce( x -> uppercasefirst(x), *, split(replace(underscored_task_name, ".jl"=>""), "_") )
end

"""
    check_valid_task!(parsed_args::Dict{String,Any}) :: Dict{String,Any}

Checks if the name of the task passed as the command line arg is valid task identifier -- if not, attempts to address it, by appending the TASK_SUFFIX suffix.
Returns the potentially modified `parsed_args` `Dict`.
"""
function check_valid_task!(parsed_args::Dict{String,Any}) :: Dict{String,Any}
  haskey(parsed_args, "task:new") && isa(parsed_args["task:new"], String) && ! endswith(parsed_args["task:new"], TASK_SUFFIX) && (parsed_args["task:new"] *= TASK_SUFFIX)
  haskey(parsed_args, "task:run") && isa(parsed_args["task:run"], String) &&! endswith(parsed_args["task:run"], TASK_SUFFIX) && (parsed_args["task:run"] *= TASK_SUFFIX)

  parsed_args
end

end

max_stars_repo_name: Fatalon/Dashboard

max_issues_repo_name: Fatalon/Dashboard

max_forks_repo_name: Fatalon/Dashboard


text:
using GeophysicalModelGenerator
using Documenter

#DocMeta.setdocmeta!(GeophysicalModelGenerator, :DocTestSetup, :(using GeophysicalModelGenerator); recursive=true)

makedocs(;
    modules=[GeophysicalModelGenerator],
    authors="Marcel Thielmann, Boris Kaus",
    sitename="GeophysicalModelGenerator.jl",
    format=Documenter.HTML(;
        prettyurls=get(ENV, "CI", "false") == "true",
    ),
    pages=[
        "Home" => "index.md",
        "Tutorials" => Any[
            "Overview" =>  "man/tutorials.md",
            "3D seismic tomography from ASCII" =>  "man/tutorial_load3DSeismicData.md",
            "3D seismic tomography from netCDF" =>  "man/tutorial_loadregular3DSeismicData_netCDF.md",
            "Visualize Moho topography" =>  "man/tutorial_MohoTopo.md",
            "Create GMT-based topography" =>  "man/tutorial_GMT_Topography.md",
            "Coastlines" =>  "man/tutorial_Coastlines.md",
            "Import screenshots" =>  "man/tutorial_Screenshot_To_Paraview.md",
            "Interpolate irregular 3D seismic tomography" =>  "man/tutorial_loadirregular3DSeismicData.md",
            "ETOPO1 Topography and geological maps" =>  "man/tutorial_GMT_Topography_GeologicalMap.md",
            "ISC earthquake data" =>  "man/tutorial_ISC_data.md",
            "Plot GPS vectors" =>  "man/tutorial_GPS.md",
            "Read UTM data" =>  "man/tutorial_UTM.md",
            "VoteMaps" =>  "man/Tutorial_Votemaps.md",
            "Kilometer-scale volcano" =>  "man/tutorial_local_Flegrei.md",
            "Generating LaMEM model" =>  "man/LaPalma_example.md",
            "Create movies" =>  "man/tutorial_time_Seismicity.md"
        ],
        "User Guide" => Any[
            "Installation" =>  "man/installation.md",
            "Data Structures" =>  "man/datastructures.md",
            "Data Import" =>  "man/dataimport.md",
            "Projection" =>  "man/projection.md",
            "Paraview output" => "man/paraview_output.md",
            "Tools" => "man/tools.md",
            "Gravity code" => "man/gravity_code.md",
            "LaMEM" => "man/lamem.md"
        ],
        "List of functions"  => "man/listfunctions.md"
    ],
)

deploydocs(;
    repo="github.com/JuliaGeodynamics/GeophysicalModelGenerator.jl.git",
    branch = "gh-pages",
    target = "build",
    devbranch = "main",
    devurl = "dev",
    forcepush=true,
    push_preview = true
)


text:
export topylist, doublefunc, numerical_grad
export up_index, down_index, update_circuit_param!, update_quantum_state!
using PyCall

function count_qubit_in_qubit_operator(op)
    n_qubits = 0
    for pauli_product in op.terms
        for pauli_operator in pauli_product[1]
            if n_qubits < pauli_operator[1]
                n_qubits = pauli_operator[1]
            end
        end
    end
    n_qubits+1
end

"""
Convert_openfermion_op

Args:
    n_qubit (:class:`int`)
    openfermion_op (:class:`openfermion.ops.QubitOperator`)
Returns:
    :class:`qulacs.Observable`
"""
function convert_openfermion_op(n_qubit, openfermion_op)
    ret = qulacs.Observable(n_qubit)
    for (pauli_product, coef) in openfermion_op.terms
        pauli_string = ""
        for pauli_operator in pauli_product
            pauli_string *= pauli_operator[2] * " $(pauli_operator[1]) "
        end
        ret.add_operator(real(coef), pauli_string[1:end-1])
    end
    ret
end

function doublefunc(x)
    return pyutil.doublefunc(x)
end

function topylist(array::Array{T}) where T
    pylist = PyVector(Vector{Any}())
    for x in array
        push!(pylist, x)
    end
    pylist
end

"""
Compute partial derivative of a given function at a point x
"""
function numerical_grad(f, x::Vector{Float64}; dx=1e-8, first_idx=1, last_idx=length(x))
    deriv = zero(x)
    x_new1 = copy(x)
    x_new2 = copy(x)
    for i in first_idx:last_idx
        x_new1[i] += dx
        x_new2[i] -= dx
        deriv[i] = (f(x_new1) - f(x_new2))/(2*dx)
        x_new1[i] = x_new2[i] = x[i]
    end
    deriv
end

"""
Check if the Python type of a given PyObject matches the expected one
"""
function check_py_type(py_object::PyObject, py_class_name::String)
    if py_object.__class__.__name__ != py_class_name
        error("Expected PyObject type $(py_object.__class__.__name__), expected $(py_class_name)")
    end
    py_object
end

"""
Make a wrapped scipy minimizer
"""
function mk_scipy_minimize(method::String="BFGS", callback=nothing, options=nothing)
    scipy_opt = pyimport("scipy.optimize")
    function minimize(cost, x0)
        res = scipy_opt.minimize(cost, x0, method=method, callback=callback, options=options)
        res["x"]
    end
    return minimize
end