text:
@testset "4.5.11 (e x)^m (a+b sec(c+d x^n))^p" begin
    (a, b, c, d, e, m, n, p, x, ) = @variables a b c d e m n p x

    #= ::Package:: =#

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

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

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

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

    @test_int [x^5*(a + b*sec(c + d*x^2)), x, 10, (a*x^6)/6 - (im*b*x^4*atan(ℯ^(im*(c + d*x^2))))/d + (im*b*x^2*PolyLog(2, (-im)*ℯ^(im*(c + d*x^2))))/d^2 - (im*b*x^2*PolyLog(2, im*ℯ^(im*(c + d*x^2))))/d^2 - (b*PolyLog(3, (-im)*ℯ^(im*(c + d*x^2))))/d^3 + (b*PolyLog(3, im*ℯ^(im*(c + d*x^2))))/d^3]
    @test_int [x^4*(a + b*sec(c + d*x^2)), x, 2, (a*x^5)/5 + b*Unintegrable(x^4*sec(c + d*x^2), x)]
    @test_int [x^3*(a + b*sec(c + d*x^2)), x, 8, (a*x^4)/4 - (im*b*x^2*atan(ℯ^(im*(c + d*x^2))))/d + ((im/2)*b*PolyLog(2, (-im)*ℯ^(im*(c + d*x^2))))/d^2 - ((im/2)*b*PolyLog(2, im*ℯ^(im*(c + d*x^2))))/d^2]
    @test_int [x^2*(a + b*sec(c + d*x^2)), x, 2, (a*x^3)/3 + b*Unintegrable(x^2*sec(c + d*x^2), x)]
    @test_int [x*(a + b*sec(c + d*x^2)), x, 4, (a*x^2)/2 + (b*atanh(sin(c + d*x^2)))/(2*d)]
    @test_int [(a + b*sec(c + d*x^2))/x, x, 2, a*log(x) + b*Unintegrable(sec(c + d*x^2)/x, x)]
    @test_int [(a + b*sec(c + d*x^2))/x^2, x, 2, -(a/x) + b*Unintegrable(sec(c + d*x^2)/x^2, x)]

    @test_int [x^5*(a + b*sec(c + d*x^2))^2, x, 15, ((-im/2)*b^2*x^4)/d + (a^2*x^6)/6 - ((2*im)*a*b*x^4*atan(ℯ^(im*(c + d*x^2))))/d + (b^2*x^2*log(1 + ℯ^((2*im)*(c + d*x^2))))/d^2 + ((2*im)*a*b*x^2*PolyLog(2, (-im)*ℯ^(im*(c + d*x^2))))/d^2 - ((2*im)*a*b*x^2*PolyLog(2, im*ℯ^(im*(c + d*x^2))))/d^2 - ((im/2)*b^2*PolyLog(2, -ℯ^((2*im)*(c + d*x^2))))/d^3 - (2*a*b*PolyLog(3, (-im)*ℯ^(im*(c + d*x^2))))/d^3 + (2*a*b*PolyLog(3, im*ℯ^(im*(c + d*x^2))))/d^3 + (b^2*x^4*tan(c + d*x^2))/(2*d)]
    @test_int [x^4*(a + b*sec(c + d*x^2))^2, x, 0, Unintegrable(x^4*(a + b*sec(c + d*x^2))^2, x)]
    @test_int [x^3*(a + b*sec(c + d*x^2))^2, x, 10, (a^2*x^4)/4 - ((2*im)*a*b*x^2*atan(ℯ^(im*(c + d*x^2))))/d + (b^2*log(cos(c + d*x^2)))/(2*d^2) + (im*a*b*PolyLog(2, (-im)*ℯ^(im*(c + d*x^2))))/d^2 - (im*a*b*PolyLog(2, im*ℯ^(im*(c + d*x^2))))/d^2 + (b^2*x^2*tan(c + d*x^2))/(2*d)]
    @test_int [x^2*(a + b*sec(c + d*x^2))^2, x, 0, Unintegrable(x^2*(a + b*sec(c + d*x^2))^2, x)]
    @test_int [x*(a + b*sec(c + d*x^2))^2, x, 5, (a^2*x^2)/2 + (a*b*atanh(sin(c + d*x^2)))/d + (b^2*tan(c + d*x^2))/(2*d)]
    @test_int [(a + b*sec(c + d*x^2))^2/x, x, 0, Unintegrable((a + b*sec(c + d*x^2))^2/x, x)]
    @test_int [(a + b*sec(c + d*x^2))^2/x^2, x, 0, Unintegrable((a + b*sec(c + d*x^2))^2/x^2, x)]

    @test_int [x*sec(a + b*x^2)^7, x, 5, (5*atanh(sin(a + b*x^2)))/(32*b) + (5*sec(a + b*x^2)*tan(a + b*x^2))/(32*b) + (5*sec(a + b*x^2)^3*tan(a + b*x^2))/(48*b) + (sec(a + b*x^2)^5*tan(a + b*x^2))/(12*b)]

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

    @test_int [x^5/(a + b*sec(c + d*x^2)), x, 13, x^6/(6*a) + ((im/2)*b*x^4*log(1 + (a*ℯ^(im*(c + d*x^2)))/(b - sqrt(-a^2 + b^2))))/(a*sqrt(-a^2 + b^2)*d) - ((im/2)*b*x^4*log(1 + (a*ℯ^(im*(c + d*x^2)))/(b + sqrt(-a^2 + b^2))))/(a*sqrt(-a^2 + b^2)*d) + (b*x^2*PolyLog(2, -((a*ℯ^(im*(c + d*x^2)))/(b - sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^2) - (b*x^2*PolyLog(2, -((a*ℯ^(im*(c + d*x^2)))/(b + sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^2) + (im*b*PolyLog(3, -((a*ℯ^(im*(c + d*x^2)))/(b - sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^3) - (im*b*PolyLog(3, -((a*ℯ^(im*(c + d*x^2)))/(b + sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^3)]
    @test_int [x^4/(a + b*sec(c + d*x^2)), x, 0, Unintegrable(x^4/(a + b*sec(c + d*x^2)), x)]
    @test_int [x^3/(a + b*sec(c + d*x^2)), x, 11, x^4/(4*a) + ((im/2)*b*x^2*log(1 + (a*ℯ^(im*(c + d*x^2)))/(b - sqrt(-a^2 + b^2))))/(a*sqrt(-a^2 + b^2)*d) - ((im/2)*b*x^2*log(1 + (a*ℯ^(im*(c + d*x^2)))/(b + sqrt(-a^2 + b^2))))/(a*sqrt(-a^2 + b^2)*d) + (b*PolyLog(2, -((a*ℯ^(im*(c + d*x^2)))/(b - sqrt(-a^2 + b^2)))))/(2*a*sqrt(-a^2 + b^2)*d^2) - (b*PolyLog(2, -((a*ℯ^(im*(c + d*x^2)))/(b + sqrt(-a^2 + b^2)))))/(2*a*sqrt(-a^2 + b^2)*d^2)]
    @test_int [x^2/(a + b*sec(c + d*x^2)), x, 0, Unintegrable(x^2/(a + b*sec(c + d*x^2)), x)]
    @test_int [x/(a + b*sec(c + d*x^2)), x, 4, x^2/(2*a) - (b*atanh((sqrt(a - b)*tan((c + d*x^2)/2))/sqrt(a + b)))/(a*sqrt(a - b)*sqrt(a + b)*d)]
    @test_int [1/(x*(a + b*sec(c + d*x^2))), x, 0, Unintegrable(1/(x*(a + b*sec(c + d*x^2))), x)]
    @test_int [(a + b*sec(c + d*x^2))/x^2, x, 2, -(a/x) + b*Unintegrable(sec(c + d*x^2)/x^2, x)]

    @test_int [x^5/(a + b*sec(c + d*x^2))^2, x, 31, ((-im/2)*b^2*x^4)/(a^2*(a^2 - b^2)*d) + x^6/(6*a^2) + (b^2*x^2*log(1 + (a*ℯ^(im*(c + d*x^2)))/(b - im*sqrt(a^2 - b^2))))/(a^2*(a^2 - b^2)*d^2) + (b^2*x^2*log(1 + (a*ℯ^(im*(c + d*x^2)))/(b + im*sqrt(a^2 - b^2))))/(a^2*(a^2 - b^2)*d^2) - ((im/2)*b^3*x^4*log(1 + (a*ℯ^(im*(c + d*x^2)))/(b - sqrt(-a^2 + b^2))))/(a^2*(-a^2 + b^2)^(3/2)*d) + (im*b*x^4*log(1 + (a*ℯ^(im*(c + d*x^2)))/(b - sqrt(-a^2 + b^2))))/(a^2*sqrt(-a^2 + b^2)*d) + ((im/2)*b^3*x^4*log(1 + (a*ℯ^(im*(c + d*x^2)))/(b + sqrt(-a^2 + b^2))))/(a^2*(-a^2 + b^2)^(3/2)*d) - (im*b*x^4*log(1 + (a*ℯ^(im*(c + d*x^2)))/(b + sqrt(-a^2 + b^2))))/(a^2*sqrt(-a^2 + b^2)*d) - (im*b^2*PolyLog(2, -((a*ℯ^(im*(c + d*x^2)))/(b - im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^3) - (im*b^2*PolyLog(2, -((a*ℯ^(im*(c + d*x^2)))/(b + im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^3) - (b^3*x^2*PolyLog(2, -((a*ℯ^(im*(c + d*x^2)))/(b - sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^2) + (2*b*x^2*PolyLog(2, -((a*ℯ^(im*(c + d*x^2)))/(b - sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^2) + (b^3*x^2*PolyLog(2, -((a*ℯ^(im*(c + d*x^2)))/(b + sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^2) - (2*b*x^2*PolyLog(2, -((a*ℯ^(im*(c + d*x^2)))/(b + sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^2) - (im*b^3*PolyLog(3, -((a*ℯ^(im*(c + d*x^2)))/(b - sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^3) + ((2*im)*b*PolyLog(3, -((a*ℯ^(im*(c + d*x^2)))/(b - sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^3) + (im*b^3*PolyLog(3, -((a*ℯ^(im*(c + d*x^2)))/(b + sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^3) - ((2*im)*b*PolyLog(3, -((a*ℯ^(im*(c + d*x^2)))/(b + sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^3) + (b^2*x^4*sin(c + d*x^2))/(2*a*(a^2 - b^2)*d*(b + a*cos(c + d*x^2)))]
    @test_int [x^4/(a + b*sec(c + d*x^2))^2, x, 0, Unintegrable(x^4/(a + b*sec(c + d*x^2))^2, x)]
    @test_int [x^3/(a + b*sec(c + d*x^2))^2, x, 22, x^4/(4*a^2) - ((im/2)*b^3*x^2*log(1 + (a*ℯ^(im*(c + d*x^2)))/(b - sqrt(-a^2 + b^2))))/(a^2*(-a^2 + b^2)^(3/2)*d) + (im*b*x^2*log(1 + (a*ℯ^(im*(c + d*x^2)))/(b - sqrt(-a^2 + b^2))))/(a^2*sqrt(-a^2 + b^2)*d) + ((im/2)*b^3*x^2*log(1 + (a*ℯ^(im*(c + d*x^2)))/(b + sqrt(-a^2 + b^2))))/(a^2*(-a^2 + b^2)^(3/2)*d) - (im*b*x^2*log(1 + (a*ℯ^(im*(c + d*x^2)))/(b + sqrt(-a^2 + b^2))))/(a^2*sqrt(-a^2 + b^2)*d) + (b^2*log(b + a*cos(c + d*x^2)))/(2*a^2*(a^2 - b^2)*d^2) - (b^3*PolyLog(2, -((a*ℯ^(im*(c + d*x^2)))/(b - sqrt(-a^2 + b^2)))))/(2*a^2*(-a^2 + b^2)^(3/2)*d^2) + (b*PolyLog(2, -((a*ℯ^(im*(c + d*x^2)))/(b - sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^2) + (b^3*PolyLog(2, -((a*ℯ^(im*(c + d*x^2)))/(b + sqrt(-a^2 + b^2)))))/(2*a^2*(-a^2 + b^2)^(3/2)*d^2) - (b*PolyLog(2, -((a*ℯ^(im*(c + d*x^2)))/(b + sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^2) + (b^2*x^2*sin(c + d*x^2))/(2*a*(a^2 - b^2)*d*(b + a*cos(c + d*x^2)))]
    @test_int [x^2/(a + b*sec(c + d*x^2))^2, x, 0, Unintegrable(x^2/(a + b*sec(c + d*x^2))^2, x)]
    @test_int [x/(a + b*sec(c + d*x^2))^2, x, 6, x^2/(2*a^2) - (b*(2*a^2 - b^2)*atanh((sqrt(a - b)*tan((c + d*x^2)/2))/sqrt(a + b)))/(a^2*(a - b)^(3/2)*(a + b)^(3/2)*d) + (b^2*tan(c + d*x^2))/(2*a*(a^2 - b^2)*d*(a + b*sec(c + d*x^2)))]
    @test_int [1/(x*(a + b*sec(c + d*x^2))^2), x, 0, Unintegrable(1/(x*(a + b*sec(c + d*x^2))^2), x)]
    @test_int [1/(x^2*(a + b*sec(c + d*x^2))^2), x, 0, Unintegrable(1/(x^2*(a + b*sec(c + d*x^2))^2), x)]
    @test_int [1/(x^3*(a + b*sec(c + d*x^2))^2), x, 0, Unintegrable(1/(x^3*(a + b*sec(c + d*x^2))^2), x)]

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

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

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

    @test_int [x^3*(a + b*sec(c + d*sqrt(x))), x, 20, (a*x^4)/4 - ((4*im)*b*x^(7/2)*atan(ℯ^(im*(c + d*sqrt(x)))))/d + ((14*im)*b*x^3*PolyLog(2, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^2 - ((14*im)*b*x^3*PolyLog(2, im*ℯ^(im*(c + d*sqrt(x)))))/d^2 - (84*b*x^(5/2)*PolyLog(3, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^3 + (84*b*x^(5/2)*PolyLog(3, im*ℯ^(im*(c + d*sqrt(x)))))/d^3 - ((420*im)*b*x^2*PolyLog(4, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^4 + ((420*im)*b*x^2*PolyLog(4, im*ℯ^(im*(c + d*sqrt(x)))))/d^4 + (1680*b*x^(3/2)*PolyLog(5, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^5 - (1680*b*x^(3/2)*PolyLog(5, im*ℯ^(im*(c + d*sqrt(x)))))/d^5 + ((5040*im)*b*x*PolyLog(6, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^6 - ((5040*im)*b*x*PolyLog(6, im*ℯ^(im*(c + d*sqrt(x)))))/d^6 - (10080*b*sqrt(x)*PolyLog(7, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^7 + (10080*b*sqrt(x)*PolyLog(7, im*ℯ^(im*(c + d*sqrt(x)))))/d^7 - ((10080*im)*b*PolyLog(8, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^8 + ((10080*im)*b*PolyLog(8, im*ℯ^(im*(c + d*sqrt(x)))))/d^8]
    @test_int [x^2*(a + b*sec(c + d*sqrt(x))), x, 16, (a*x^3)/3 - ((4*im)*b*x^(5/2)*atan(ℯ^(im*(c + d*sqrt(x)))))/d + ((10*im)*b*x^2*PolyLog(2, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^2 - ((10*im)*b*x^2*PolyLog(2, im*ℯ^(im*(c + d*sqrt(x)))))/d^2 - (40*b*x^(3/2)*PolyLog(3, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^3 + (40*b*x^(3/2)*PolyLog(3, im*ℯ^(im*(c + d*sqrt(x)))))/d^3 - ((120*im)*b*x*PolyLog(4, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^4 + ((120*im)*b*x*PolyLog(4, im*ℯ^(im*(c + d*sqrt(x)))))/d^4 + (240*b*sqrt(x)*PolyLog(5, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^5 - (240*b*sqrt(x)*PolyLog(5, im*ℯ^(im*(c + d*sqrt(x)))))/d^5 + ((240*im)*b*PolyLog(6, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^6 - ((240*im)*b*PolyLog(6, im*ℯ^(im*(c + d*sqrt(x)))))/d^6]
    @test_int [x*(a + b*sec(c + d*sqrt(x))), x, 12, (a*x^2)/2 - ((4*im)*b*x^(3/2)*atan(ℯ^(im*(c + d*sqrt(x)))))/d + ((6*im)*b*x*PolyLog(2, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^2 - ((6*im)*b*x*PolyLog(2, im*ℯ^(im*(c + d*sqrt(x)))))/d^2 - (12*b*sqrt(x)*PolyLog(3, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^3 + (12*b*sqrt(x)*PolyLog(3, im*ℯ^(im*(c + d*sqrt(x)))))/d^3 - ((12*im)*b*PolyLog(4, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^4 + ((12*im)*b*PolyLog(4, im*ℯ^(im*(c + d*sqrt(x)))))/d^4]
    @test_int [(a + b*sec(c + d*sqrt(x)))/x, x, 2, a*log(x) + b*Unintegrable(sec(c + d*sqrt(x))/x, x)]
    @test_int [(a + b*sec(c + d*sqrt(x)))/x^2, x, 2, -(a/x) + b*Unintegrable(sec(c + d*sqrt(x))/x^2, x)]

    @test_int [x^3*(a + b*sec(c + d*sqrt(x)))^2, x, 30, ((-2*im)*b^2*x^(7/2))/d + (a^2*x^4)/4 - ((8*im)*a*b*x^(7/2)*atan(ℯ^(im*(c + d*sqrt(x)))))/d + (14*b^2*x^3*log(1 + ℯ^((2*im)*(c + d*sqrt(x)))))/d^2 + ((28*im)*a*b*x^3*PolyLog(2, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^2 - ((28*im)*a*b*x^3*PolyLog(2, im*ℯ^(im*(c + d*sqrt(x)))))/d^2 - ((42*im)*b^2*x^(5/2)*PolyLog(2, -ℯ^((2*im)*(c + d*sqrt(x)))))/d^3 - (168*a*b*x^(5/2)*PolyLog(3, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^3 + (168*a*b*x^(5/2)*PolyLog(3, im*ℯ^(im*(c + d*sqrt(x)))))/d^3 + (105*b^2*x^2*PolyLog(3, -ℯ^((2*im)*(c + d*sqrt(x)))))/d^4 - ((840*im)*a*b*x^2*PolyLog(4, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^4 + ((840*im)*a*b*x^2*PolyLog(4, im*ℯ^(im*(c + d*sqrt(x)))))/d^4 + ((210*im)*b^2*x^(3/2)*PolyLog(4, -ℯ^((2*im)*(c + d*sqrt(x)))))/d^5 + (3360*a*b*x^(3/2)*PolyLog(5, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^5 - (3360*a*b*x^(3/2)*PolyLog(5, im*ℯ^(im*(c + d*sqrt(x)))))/d^5 - (315*b^2*x*PolyLog(5, -ℯ^((2*im)*(c + d*sqrt(x)))))/d^6 + ((10080*im)*a*b*x*PolyLog(6, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^6 - ((10080*im)*a*b*x*PolyLog(6, im*ℯ^(im*(c + d*sqrt(x)))))/d^6 - ((315*im)*b^2*sqrt(x)*PolyLog(6, -ℯ^((2*im)*(c + d*sqrt(x)))))/d^7 - (20160*a*b*sqrt(x)*PolyLog(7, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^7 + (20160*a*b*sqrt(x)*PolyLog(7, im*ℯ^(im*(c + d*sqrt(x)))))/d^7 + (315*b^2*PolyLog(7, -ℯ^((2*im)*(c + d*sqrt(x)))))/(2*d^8) - ((20160*im)*a*b*PolyLog(8, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^8 + ((20160*im)*a*b*PolyLog(8, im*ℯ^(im*(c + d*sqrt(x)))))/d^8 + (2*b^2*x^(7/2)*tan(c + d*sqrt(x)))/d]
    @test_int [x^2*(a + b*sec(c + d*sqrt(x)))^2, x, 24, ((-2*im)*b^2*x^(5/2))/d + (a^2*x^3)/3 - ((8*im)*a*b*x^(5/2)*atan(ℯ^(im*(c + d*sqrt(x)))))/d + (10*b^2*x^2*log(1 + ℯ^((2*im)*(c + d*sqrt(x)))))/d^2 + ((20*im)*a*b*x^2*PolyLog(2, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^2 - ((20*im)*a*b*x^2*PolyLog(2, im*ℯ^(im*(c + d*sqrt(x)))))/d^2 - ((20*im)*b^2*x^(3/2)*PolyLog(2, -ℯ^((2*im)*(c + d*sqrt(x)))))/d^3 - (80*a*b*x^(3/2)*PolyLog(3, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^3 + (80*a*b*x^(3/2)*PolyLog(3, im*ℯ^(im*(c + d*sqrt(x)))))/d^3 + (30*b^2*x*PolyLog(3, -ℯ^((2*im)*(c + d*sqrt(x)))))/d^4 - ((240*im)*a*b*x*PolyLog(4, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^4 + ((240*im)*a*b*x*PolyLog(4, im*ℯ^(im*(c + d*sqrt(x)))))/d^4 + ((30*im)*b^2*sqrt(x)*PolyLog(4, -ℯ^((2*im)*(c + d*sqrt(x)))))/d^5 + (480*a*b*sqrt(x)*PolyLog(5, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^5 - (480*a*b*sqrt(x)*PolyLog(5, im*ℯ^(im*(c + d*sqrt(x)))))/d^5 - (15*b^2*PolyLog(5, -ℯ^((2*im)*(c + d*sqrt(x)))))/d^6 + ((480*im)*a*b*PolyLog(6, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^6 - ((480*im)*a*b*PolyLog(6, im*ℯ^(im*(c + d*sqrt(x)))))/d^6 + (2*b^2*x^(5/2)*tan(c + d*sqrt(x)))/d]
    @test_int [x*(a + b*sec(c + d*sqrt(x)))^2, x, 18, ((-2*im)*b^2*x^(3/2))/d + (a^2*x^2)/2 - ((8*im)*a*b*x^(3/2)*atan(ℯ^(im*(c + d*sqrt(x)))))/d + (6*b^2*x*log(1 + ℯ^((2*im)*(c + d*sqrt(x)))))/d^2 + ((12*im)*a*b*x*PolyLog(2, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^2 - ((12*im)*a*b*x*PolyLog(2, im*ℯ^(im*(c + d*sqrt(x)))))/d^2 - ((6*im)*b^2*sqrt(x)*PolyLog(2, -ℯ^((2*im)*(c + d*sqrt(x)))))/d^3 - (24*a*b*sqrt(x)*PolyLog(3, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^3 + (24*a*b*sqrt(x)*PolyLog(3, im*ℯ^(im*(c + d*sqrt(x)))))/d^3 + (3*b^2*PolyLog(3, -ℯ^((2*im)*(c + d*sqrt(x)))))/d^4 - ((24*im)*a*b*PolyLog(4, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^4 + ((24*im)*a*b*PolyLog(4, im*ℯ^(im*(c + d*sqrt(x)))))/d^4 + (2*b^2*x^(3/2)*tan(c + d*sqrt(x)))/d]
    @test_int [(a + b*sec(c + d*sqrt(x)))^2/x, x, 0, Unintegrable((a + b*sec(c + d*sqrt(x)))^2/x, x)]
    @test_int [(a + b*sec(c + d*sqrt(x)))^2/x^2, x, 0, Unintegrable((a + b*sec(c + d*sqrt(x)))^2/x^2, x)]

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

    @test_int [x^3/(a + b*sec(c + d*sqrt(x))), x, 23, x^4/(4*a) + ((2*im)*b*x^(7/2)*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2))))/(a*sqrt(-a^2 + b^2)*d) - ((2*im)*b*x^(7/2)*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2))))/(a*sqrt(-a^2 + b^2)*d) + (14*b*x^3*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^2) - (14*b*x^3*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^2) + ((84*im)*b*x^(5/2)*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^3) - ((84*im)*b*x^(5/2)*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^3) - (420*b*x^2*PolyLog(4, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^4) + (420*b*x^2*PolyLog(4, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^4) - ((1680*im)*b*x^(3/2)*PolyLog(5, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^5) + ((1680*im)*b*x^(3/2)*PolyLog(5, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^5) + (5040*b*x*PolyLog(6, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^6) - (5040*b*x*PolyLog(6, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^6) + ((10080*im)*b*sqrt(x)*PolyLog(7, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^7) - ((10080*im)*b*sqrt(x)*PolyLog(7, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^7) - (10080*b*PolyLog(8, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^8) + (10080*b*PolyLog(8, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^8)]
    @test_int [x^2/(a + b*sec(c + d*sqrt(x))), x, 19, x^3/(3*a) + ((2*im)*b*x^(5/2)*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2))))/(a*sqrt(-a^2 + b^2)*d) - ((2*im)*b*x^(5/2)*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2))))/(a*sqrt(-a^2 + b^2)*d) + (10*b*x^2*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^2) - (10*b*x^2*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^2) + ((40*im)*b*x^(3/2)*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^3) - ((40*im)*b*x^(3/2)*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^3) - (120*b*x*PolyLog(4, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^4) + (120*b*x*PolyLog(4, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^4) - ((240*im)*b*sqrt(x)*PolyLog(5, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^5) + ((240*im)*b*sqrt(x)*PolyLog(5, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^5) + (240*b*PolyLog(6, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^6) - (240*b*PolyLog(6, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^6)]
    @test_int [x/(a + b*sec(c + d*sqrt(x))), x, 15, x^2/(2*a) + ((2*im)*b*x^(3/2)*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2))))/(a*sqrt(-a^2 + b^2)*d) - ((2*im)*b*x^(3/2)*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2))))/(a*sqrt(-a^2 + b^2)*d) + (6*b*x*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^2) - (6*b*x*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^2) + ((12*im)*b*sqrt(x)*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^3) - ((12*im)*b*sqrt(x)*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^3) - (12*b*PolyLog(4, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^4) + (12*b*PolyLog(4, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^4)]
    @test_int [1/(x*(a + b*sec(c + d*sqrt(x)))), x, 0, Unintegrable(1/(x*(a + b*sec(c + d*sqrt(x)))), x)]
    @test_int [(a + b*sec(c + d*sqrt(x)))/x^2, x, 2, -(a/x) + b*Unintegrable(sec(c + d*sqrt(x))/x^2, x)]

    @test_int [x^3/(a + b*sec(c + d*sqrt(x)))^2, x, 61, ((-2*im)*b^2*x^(7/2))/(a^2*(a^2 - b^2)*d) + x^4/(4*a^2) + (14*b^2*x^3*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b - im*sqrt(a^2 - b^2))))/(a^2*(a^2 - b^2)*d^2) + (14*b^2*x^3*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b + im*sqrt(a^2 - b^2))))/(a^2*(a^2 - b^2)*d^2) - ((2*im)*b^3*x^(7/2)*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2))))/(a^2*(-a^2 + b^2)^(3/2)*d) + ((4*im)*b*x^(7/2)*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2))))/(a^2*sqrt(-a^2 + b^2)*d) + ((2*im)*b^3*x^(7/2)*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2))))/(a^2*(-a^2 + b^2)^(3/2)*d) - ((4*im)*b*x^(7/2)*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2))))/(a^2*sqrt(-a^2 + b^2)*d) - ((84*im)*b^2*x^(5/2)*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^3) - ((84*im)*b^2*x^(5/2)*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^3) - (14*b^3*x^3*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^2) + (28*b*x^3*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^2) + (14*b^3*x^3*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^2) - (28*b*x^3*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^2) + (420*b^2*x^2*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^4) + (420*b^2*x^2*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^4) - ((84*im)*b^3*x^(5/2)*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^3) + ((168*im)*b*x^(5/2)*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^3) + ((84*im)*b^3*x^(5/2)*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^3) - ((168*im)*b*x^(5/2)*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^3) + ((1680*im)*b^2*x^(3/2)*PolyLog(4, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^5) + ((1680*im)*b^2*x^(3/2)*PolyLog(4, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^5) + (420*b^3*x^2*PolyLog(4, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^4) - (840*b*x^2*PolyLog(4, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^4) - (420*b^3*x^2*PolyLog(4, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^4) + (840*b*x^2*PolyLog(4, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^4) - (5040*b^2*x*PolyLog(5, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^6) - (5040*b^2*x*PolyLog(5, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^6) + ((1680*im)*b^3*x^(3/2)*PolyLog(5, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^5) - ((3360*im)*b*x^(3/2)*PolyLog(5, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^5) - ((1680*im)*b^3*x^(3/2)*PolyLog(5, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^5) + ((3360*im)*b*x^(3/2)*PolyLog(5, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^5) - ((10080*im)*b^2*sqrt(x)*PolyLog(6, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^7) - ((10080*im)*b^2*sqrt(x)*PolyLog(6, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^7) - (5040*b^3*x*PolyLog(6, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^6) + (10080*b*x*PolyLog(6, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^6) + (5040*b^3*x*PolyLog(6, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^6) - (10080*b*x*PolyLog(6, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^6) + (10080*b^2*PolyLog(7, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^8) + (10080*b^2*PolyLog(7, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^8) - ((10080*im)*b^3*sqrt(x)*PolyLog(7, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^7) + ((20160*im)*b*sqrt(x)*PolyLog(7, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^7) + ((10080*im)*b^3*sqrt(x)*PolyLog(7, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^7) - ((20160*im)*b*sqrt(x)*PolyLog(7, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^7) + (10080*b^3*PolyLog(8, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^8) - (20160*b*PolyLog(8, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^8) - (10080*b^3*PolyLog(8, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^8) + (20160*b*PolyLog(8, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^8) + (2*b^2*x^(7/2)*sin(c + d*sqrt(x)))/(a*(a^2 - b^2)*d*(b + a*cos(c + d*sqrt(x))))]
    @test_int [x^2/(a + b*sec(c + d*sqrt(x)))^2, x, 49, ((-2*im)*b^2*x^(5/2))/(a^2*(a^2 - b^2)*d) + x^3/(3*a^2) + (10*b^2*x^2*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b - im*sqrt(a^2 - b^2))))/(a^2*(a^2 - b^2)*d^2) + (10*b^2*x^2*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b + im*sqrt(a^2 - b^2))))/(a^2*(a^2 - b^2)*d^2) - ((2*im)*b^3*x^(5/2)*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2))))/(a^2*(-a^2 + b^2)^(3/2)*d) + ((4*im)*b*x^(5/2)*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2))))/(a^2*sqrt(-a^2 + b^2)*d) + ((2*im)*b^3*x^(5/2)*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2))))/(a^2*(-a^2 + b^2)^(3/2)*d) - ((4*im)*b*x^(5/2)*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2))))/(a^2*sqrt(-a^2 + b^2)*d) - ((40*im)*b^2*x^(3/2)*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^3) - ((40*im)*b^2*x^(3/2)*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^3) - (10*b^3*x^2*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^2) + (20*b*x^2*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^2) + (10*b^3*x^2*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^2) - (20*b*x^2*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^2) + (120*b^2*x*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^4) + (120*b^2*x*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^4) - ((40*im)*b^3*x^(3/2)*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^3) + ((80*im)*b*x^(3/2)*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^3) + ((40*im)*b^3*x^(3/2)*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^3) - ((80*im)*b*x^(3/2)*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^3) + ((240*im)*b^2*sqrt(x)*PolyLog(4, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^5) + ((240*im)*b^2*sqrt(x)*PolyLog(4, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^5) + (120*b^3*x*PolyLog(4, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^4) - (240*b*x*PolyLog(4, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^4) - (120*b^3*x*PolyLog(4, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^4) + (240*b*x*PolyLog(4, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^4) - (240*b^2*PolyLog(5, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^6) - (240*b^2*PolyLog(5, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^6) + ((240*im)*b^3*sqrt(x)*PolyLog(5, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^5) - ((480*im)*b*sqrt(x)*PolyLog(5, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^5) - ((240*im)*b^3*sqrt(x)*PolyLog(5, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^5) + ((480*im)*b*sqrt(x)*PolyLog(5, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^5) - (240*b^3*PolyLog(6, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^6) + (480*b*PolyLog(6, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^6) + (240*b^3*PolyLog(6, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^6) - (480*b*PolyLog(6, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^6) + (2*b^2*x^(5/2)*sin(c + d*sqrt(x)))/(a*(a^2 - b^2)*d*(b + a*cos(c + d*sqrt(x))))]
    @test_int [x/(a + b*sec(c + d*sqrt(x)))^2, x, 37, ((-2*im)*b^2*x^(3/2))/(a^2*(a^2 - b^2)*d) + x^2/(2*a^2) + (6*b^2*x*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b - im*sqrt(a^2 - b^2))))/(a^2*(a^2 - b^2)*d^2) + (6*b^2*x*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b + im*sqrt(a^2 - b^2))))/(a^2*(a^2 - b^2)*d^2) - ((2*im)*b^3*x^(3/2)*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2))))/(a^2*(-a^2 + b^2)^(3/2)*d) + ((4*im)*b*x^(3/2)*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2))))/(a^2*sqrt(-a^2 + b^2)*d) + ((2*im)*b^3*x^(3/2)*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2))))/(a^2*(-a^2 + b^2)^(3/2)*d) - ((4*im)*b*x^(3/2)*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2))))/(a^2*sqrt(-a^2 + b^2)*d) - ((12*im)*b^2*sqrt(x)*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^3) - ((12*im)*b^2*sqrt(x)*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^3) - (6*b^3*x*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^2) + (12*b*x*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^2) + (6*b^3*x*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^2) - (12*b*x*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^2) + (12*b^2*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^4) + (12*b^2*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^4) - ((12*im)*b^3*sqrt(x)*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^3) + ((24*im)*b*sqrt(x)*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^3) + ((12*im)*b^3*sqrt(x)*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^3) - ((24*im)*b*sqrt(x)*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^3) + (12*b^3*PolyLog(4, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^4) - (24*b*PolyLog(4, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^4) - (12*b^3*PolyLog(4, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^4) + (24*b*PolyLog(4, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^4) + (2*b^2*x^(3/2)*sin(c + d*sqrt(x)))/(a*(a^2 - b^2)*d*(b + a*cos(c + d*sqrt(x))))]
    @test_int [1/(x*(a + b*sec(c + d*sqrt(x)))^2), x, 0, Unintegrable(1/(x*(a + b*sec(c + d*sqrt(x)))^2), x)]
    @test_int [1/(x^2*(a + b*sec(c + d*sqrt(x)))^2), x, 0, Unintegrable(1/(x^2*(a + b*sec(c + d*sqrt(x)))^2), x)]

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

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

    @test_int [x^(3/2)*(a + b*sec(c + d*sqrt(x))), x, 14, (2*a*x^(5/2))/5 - ((4*im)*b*x^2*atan(ℯ^(im*(c + d*sqrt(x)))))/d + ((8*im)*b*x^(3/2)*PolyLog(2, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^2 - ((8*im)*b*x^(3/2)*PolyLog(2, im*ℯ^(im*(c + d*sqrt(x)))))/d^2 - (24*b*x*PolyLog(3, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^3 + (24*b*x*PolyLog(3, im*ℯ^(im*(c + d*sqrt(x)))))/d^3 - ((48*im)*b*sqrt(x)*PolyLog(4, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^4 + ((48*im)*b*sqrt(x)*PolyLog(4, im*ℯ^(im*(c + d*sqrt(x)))))/d^4 + (48*b*PolyLog(5, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^5 - (48*b*PolyLog(5, im*ℯ^(im*(c + d*sqrt(x)))))/d^5]
    @test_int [sqrt(x)*(a + b*sec(c + d*sqrt(x))), x, 10, (2*a*x^(3/2))/3 - ((4*im)*b*x*atan(ℯ^(im*(c + d*sqrt(x)))))/d + ((4*im)*b*sqrt(x)*PolyLog(2, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^2 - ((4*im)*b*sqrt(x)*PolyLog(2, im*ℯ^(im*(c + d*sqrt(x)))))/d^2 - (4*b*PolyLog(3, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^3 + (4*b*PolyLog(3, im*ℯ^(im*(c + d*sqrt(x)))))/d^3]
    @test_int [(a + b*sec(c + d*sqrt(x)))/sqrt(x), x, 4, 2*a*sqrt(x) + (2*b*atanh(sin(c + d*sqrt(x))))/d]
    @test_int [(a + b*sec(c + d*sqrt(x)))/x^(3/2), x, 2, (-2*a)/sqrt(x) + b*Unintegrable(sec(c + d*sqrt(x))/x^(3/2), x)]
    @test_int [(a + b*sec(c + d*sqrt(x)))/x^(5/2), x, 2, (-2*a)/(3*x^(3/2)) + b*Unintegrable(sec(c + d*sqrt(x))/x^(5/2), x)]

    @test_int [x^(3/2)*(a + b*sec(c + d*sqrt(x)))^2, x, 21, ((-2*im)*b^2*x^2)/d + (2*a^2*x^(5/2))/5 - ((8*im)*a*b*x^2*atan(ℯ^(im*(c + d*sqrt(x)))))/d + (8*b^2*x^(3/2)*log(1 + ℯ^((2*im)*(c + d*sqrt(x)))))/d^2 + ((16*im)*a*b*x^(3/2)*PolyLog(2, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^2 - ((16*im)*a*b*x^(3/2)*PolyLog(2, im*ℯ^(im*(c + d*sqrt(x)))))/d^2 - ((12*im)*b^2*x*PolyLog(2, -ℯ^((2*im)*(c + d*sqrt(x)))))/d^3 - (48*a*b*x*PolyLog(3, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^3 + (48*a*b*x*PolyLog(3, im*ℯ^(im*(c + d*sqrt(x)))))/d^3 + (12*b^2*sqrt(x)*PolyLog(3, -ℯ^((2*im)*(c + d*sqrt(x)))))/d^4 - ((96*im)*a*b*sqrt(x)*PolyLog(4, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^4 + ((96*im)*a*b*sqrt(x)*PolyLog(4, im*ℯ^(im*(c + d*sqrt(x)))))/d^4 + ((6*im)*b^2*PolyLog(4, -ℯ^((2*im)*(c + d*sqrt(x)))))/d^5 + (96*a*b*PolyLog(5, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^5 - (96*a*b*PolyLog(5, im*ℯ^(im*(c + d*sqrt(x)))))/d^5 + (2*b^2*x^2*tan(c + d*sqrt(x)))/d]
    @test_int [sqrt(x)*(a + b*sec(c + d*sqrt(x)))^2, x, 15, ((-2*im)*b^2*x)/d + (2*a^2*x^(3/2))/3 - ((8*im)*a*b*x*atan(ℯ^(im*(c + d*sqrt(x)))))/d + (4*b^2*sqrt(x)*log(1 + ℯ^((2*im)*(c + d*sqrt(x)))))/d^2 + ((8*im)*a*b*sqrt(x)*PolyLog(2, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^2 - ((8*im)*a*b*sqrt(x)*PolyLog(2, im*ℯ^(im*(c + d*sqrt(x)))))/d^2 - ((2*im)*b^2*PolyLog(2, -ℯ^((2*im)*(c + d*sqrt(x)))))/d^3 - (8*a*b*PolyLog(3, (-im)*ℯ^(im*(c + d*sqrt(x)))))/d^3 + (8*a*b*PolyLog(3, im*ℯ^(im*(c + d*sqrt(x)))))/d^3 + (2*b^2*x*tan(c + d*sqrt(x)))/d]
    @test_int [(a + b*sec(c + d*sqrt(x)))^2/sqrt(x), x, 5, 2*a^2*sqrt(x) + (4*a*b*atanh(sin(c + d*sqrt(x))))/d + (2*b^2*tan(c + d*sqrt(x)))/d]
    @test_int [(a + b*sec(c + d*sqrt(x)))^2/x^(3/2), x, 0, Unintegrable((a + b*sec(c + d*sqrt(x)))^2/x^(3/2), x)]
    @test_int [(a + b*sec(c + d*sqrt(x)))^2/x^(5/2), x, 0, Unintegrable((a + b*sec(c + d*sqrt(x)))^2/x^(5/2), x)]

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

    @test_int [x^(3/2)/(a + b*sec(c + d*sqrt(x))), x, 17, (2*x^(5/2))/(5*a) + ((2*im)*b*x^2*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2))))/(a*sqrt(-a^2 + b^2)*d) - ((2*im)*b*x^2*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2))))/(a*sqrt(-a^2 + b^2)*d) + (8*b*x^(3/2)*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^2) - (8*b*x^(3/2)*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^2) + ((24*im)*b*x*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^3) - ((24*im)*b*x*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^3) - (48*b*sqrt(x)*PolyLog(4, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^4) + (48*b*sqrt(x)*PolyLog(4, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^4) - ((48*im)*b*PolyLog(5, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^5) + ((48*im)*b*PolyLog(5, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^5)]
    @test_int [sqrt(x)/(a + b*sec(c + d*sqrt(x))), x, 13, (2*x^(3/2))/(3*a) + ((2*im)*b*x*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2))))/(a*sqrt(-a^2 + b^2)*d) - ((2*im)*b*x*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2))))/(a*sqrt(-a^2 + b^2)*d) + (4*b*sqrt(x)*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^2) - (4*b*sqrt(x)*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^2) + ((4*im)*b*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^3) - ((4*im)*b*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^3)]
    @test_int [1/(sqrt(x)*(a + b*sec(c + d*sqrt(x)))), x, 4, (2*sqrt(x))/a - (4*b*atanh((sqrt(a - b)*tan((c + d*sqrt(x))/2))/sqrt(a + b)))/(a*sqrt(a - b)*sqrt(a + b)*d)]
    @test_int [1/(x^(3/2)*(a + b*sec(c + d*sqrt(x)))), x, 0, Unintegrable(1/(x^(3/2)*(a + b*sec(c + d*sqrt(x)))), x)]
    @test_int [1/(x^(5/2)*(a + b*sec(c + d*sqrt(x)))), x, 0, Unintegrable(1/(x^(5/2)*(a + b*sec(c + d*sqrt(x)))), x)]

    @test_int [x^(3/2)/(a + b*sec(c + d*sqrt(x)))^2, x, 43, ((-2*im)*b^2*x^2)/(a^2*(a^2 - b^2)*d) + (2*x^(5/2))/(5*a^2) + (8*b^2*x^(3/2)*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b - im*sqrt(a^2 - b^2))))/(a^2*(a^2 - b^2)*d^2) + (8*b^2*x^(3/2)*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b + im*sqrt(a^2 - b^2))))/(a^2*(a^2 - b^2)*d^2) - ((2*im)*b^3*x^2*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2))))/(a^2*(-a^2 + b^2)^(3/2)*d) + ((4*im)*b*x^2*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2))))/(a^2*sqrt(-a^2 + b^2)*d) + ((2*im)*b^3*x^2*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2))))/(a^2*(-a^2 + b^2)^(3/2)*d) - ((4*im)*b*x^2*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2))))/(a^2*sqrt(-a^2 + b^2)*d) - ((24*im)*b^2*x*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^3) - ((24*im)*b^2*x*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^3) - (8*b^3*x^(3/2)*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^2) + (16*b*x^(3/2)*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^2) + (8*b^3*x^(3/2)*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^2) - (16*b*x^(3/2)*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^2) + (48*b^2*sqrt(x)*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^4) + (48*b^2*sqrt(x)*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^4) - ((24*im)*b^3*x*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^3) + ((48*im)*b*x*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^3) + ((24*im)*b^3*x*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^3) - ((48*im)*b*x*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^3) + ((48*im)*b^2*PolyLog(4, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^5) + ((48*im)*b^2*PolyLog(4, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^5) + (48*b^3*sqrt(x)*PolyLog(4, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^4) - (96*b*sqrt(x)*PolyLog(4, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^4) - (48*b^3*sqrt(x)*PolyLog(4, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^4) + (96*b*sqrt(x)*PolyLog(4, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^4) + ((48*im)*b^3*PolyLog(5, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^5) - ((96*im)*b*PolyLog(5, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^5) - ((48*im)*b^3*PolyLog(5, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^5) + ((96*im)*b*PolyLog(5, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^5) + (2*b^2*x^2*sin(c + d*sqrt(x)))/(a*(a^2 - b^2)*d*(b + a*cos(c + d*sqrt(x))))]
    @test_int [sqrt(x)/(a + b*sec(c + d*sqrt(x)))^2, x, 31, ((-2*im)*b^2*x)/(a^2*(a^2 - b^2)*d) + (2*x^(3/2))/(3*a^2) + (4*b^2*sqrt(x)*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b - im*sqrt(a^2 - b^2))))/(a^2*(a^2 - b^2)*d^2) + (4*b^2*sqrt(x)*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b + im*sqrt(a^2 - b^2))))/(a^2*(a^2 - b^2)*d^2) - ((2*im)*b^3*x*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2))))/(a^2*(-a^2 + b^2)^(3/2)*d) + ((4*im)*b*x*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2))))/(a^2*sqrt(-a^2 + b^2)*d) + ((2*im)*b^3*x*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2))))/(a^2*(-a^2 + b^2)^(3/2)*d) - ((4*im)*b*x*log(1 + (a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2))))/(a^2*sqrt(-a^2 + b^2)*d) - ((4*im)*b^2*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^3) - ((4*im)*b^2*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + im*sqrt(a^2 - b^2)))))/(a^2*(a^2 - b^2)*d^3) - (4*b^3*sqrt(x)*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^2) + (8*b*sqrt(x)*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^2) + (4*b^3*sqrt(x)*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^2) - (8*b*sqrt(x)*PolyLog(2, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^2) - ((4*im)*b^3*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^3) + ((8*im)*b*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b - sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^3) + ((4*im)*b^3*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^3) - ((8*im)*b*PolyLog(3, -((a*ℯ^(im*(c + d*sqrt(x))))/(b + sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^3) + (2*b^2*x*sin(c + d*sqrt(x)))/(a*(a^2 - b^2)*d*(b + a*cos(c + d*sqrt(x))))]
    @test_int [1/(sqrt(x)*(a + b*sec(c + d*sqrt(x)))^2), x, 6, (2*sqrt(x))/a^2 - (4*b*(2*a^2 - b^2)*atanh((sqrt(a - b)*tan((c + d*sqrt(x))/2))/sqrt(a + b)))/(a^2*(a - b)^(3/2)*(a + b)^(3/2)*d) + (2*b^2*tan(c + d*sqrt(x)))/(a*(a^2 - b^2)*d*(a + b*sec(c + d*sqrt(x))))]
    @test_int [1/(x^(3/2)*(a + b*sec(c + d*sqrt(x)))^2), x, 0, Unintegrable(1/(x^(3/2)*(a + b*sec(c + d*sqrt(x)))^2), x)]
    @test_int [1/(x^(5/2)*(a + b*sec(c + d*sqrt(x)))^2), x, 0, Unintegrable(1/(x^(5/2)*(a + b*sec(c + d*sqrt(x)))^2), x)]

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

    @test_int [(e*x)^m*(a + b*sec(c + d*x^n))^p, x, 1, ((e*x)^m*Unintegrable(x^m*(a + b*sec(c + d*x^n))^p, x))/x^m]

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

    @test_int [(e*x)^(-1 + n)*(a + b*sec(c + d*x^n)), x, 5, (a*(e*x)^n)/(e*n) + (b*(e*x)^n*atanh(sin(c + d*x^n)))/(d*e*n*x^n)]
    @test_int [(e*x)^(-1 + 2*n)*(a + b*sec(c + d*x^n)), x, 9, (a*(e*x)^(2*n))/(2*e*n) - ((2*im)*b*(e*x)^(2*n)*atan(ℯ^(im*(c + d*x^n))))/(d*e*n*x^n) + (im*b*(e*x)^(2*n)*PolyLog(2, (-im)*ℯ^(im*(c + d*x^n))))/(d^2*e*n*x^(2*n)) - (im*b*(e*x)^(2*n)*PolyLog(2, im*ℯ^(im*(c + d*x^n))))/(d^2*e*n*x^(2*n))]
    @test_int [(e*x)^(-1 + 3*n)*(a + b*sec(c + d*x^n)), x, 11, (a*(e*x)^(3*n))/(3*e*n) - ((2*im)*b*(e*x)^(3*n)*atan(ℯ^(im*(c + d*x^n))))/(d*e*n*x^n) + ((2*im)*b*(e*x)^(3*n)*PolyLog(2, (-im)*ℯ^(im*(c + d*x^n))))/(d^2*e*n*x^(2*n)) - ((2*im)*b*(e*x)^(3*n)*PolyLog(2, im*ℯ^(im*(c + d*x^n))))/(d^2*e*n*x^(2*n)) - (2*b*(e*x)^(3*n)*PolyLog(3, (-im)*ℯ^(im*(c + d*x^n))))/(d^3*e*n*x^(3*n)) + (2*b*(e*x)^(3*n)*PolyLog(3, im*ℯ^(im*(c + d*x^n))))/(d^3*e*n*x^(3*n))]

    @test_int [(e*x)^(-1 + n)*(a + b*sec(c + d*x^n))^2, x, 6, (a^2*(e*x)^n)/(e*n) + (2*a*b*(e*x)^n*atanh(sin(c + d*x^n)))/(d*e*n*x^n) + (b^2*(e*x)^n*tan(c + d*x^n))/(d*e*n*x^n)]
    @test_int [(e*x)^(-1 + 2*n)*(a + b*sec(c + d*x^n))^2, x, 11, (a^2*(e*x)^(2*n))/(2*e*n) - ((4*im)*a*b*(e*x)^(2*n)*atan(ℯ^(im*(c + d*x^n))))/(d*e*n*x^n) + (b^2*(e*x)^(2*n)*log(cos(c + d*x^n)))/(d^2*e*n*x^(2*n)) + ((2*im)*a*b*(e*x)^(2*n)*PolyLog(2, (-im)*ℯ^(im*(c + d*x^n))))/(d^2*e*n*x^(2*n)) - ((2*im)*a*b*(e*x)^(2*n)*PolyLog(2, im*ℯ^(im*(c + d*x^n))))/(d^2*e*n*x^(2*n)) + (b^2*(e*x)^(2*n)*tan(c + d*x^n))/(d*e*n*x^n)]
    @test_int [(e*x)^(-1 + 3*n)*(a + b*sec(c + d*x^n))^2, x, 16, (a^2*(e*x)^(3*n))/(3*e*n) - (im*b^2*(e*x)^(3*n))/(d*e*n*x^n) - ((4*im)*a*b*(e*x)^(3*n)*atan(ℯ^(im*(c + d*x^n))))/(d*e*n*x^n) + (2*b^2*(e*x)^(3*n)*log(1 + ℯ^((2*im)*(c + d*x^n))))/(d^2*e*n*x^(2*n)) + ((4*im)*a*b*(e*x)^(3*n)*PolyLog(2, (-im)*ℯ^(im*(c + d*x^n))))/(d^2*e*n*x^(2*n)) - ((4*im)*a*b*(e*x)^(3*n)*PolyLog(2, im*ℯ^(im*(c + d*x^n))))/(d^2*e*n*x^(2*n)) - (im*b^2*(e*x)^(3*n)*PolyLog(2, -ℯ^((2*im)*(c + d*x^n))))/(d^3*e*n*x^(3*n)) - (4*a*b*(e*x)^(3*n)*PolyLog(3, (-im)*ℯ^(im*(c + d*x^n))))/(d^3*e*n*x^(3*n)) + (4*a*b*(e*x)^(3*n)*PolyLog(3, im*ℯ^(im*(c + d*x^n))))/(d^3*e*n*x^(3*n)) + (b^2*(e*x)^(3*n)*tan(c + d*x^n))/(d*e*n*x^n)]

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

    @test_int [(e*x)^(-1 + n)/(a + b*sec(c + d*x^n)), x, 5, (e*x)^n/(a*e*n) - (2*b*(e*x)^n*atanh((sqrt(a - b)*tan((c + d*x^n)/2))/sqrt(a + b)))/(a*sqrt(a - b)*sqrt(a + b)*d*e*n*x^n)]
    @test_int [(e*x)^(-1 + 2*n)/(a + b*sec(c + d*x^n)), x, 12, (e*x)^(2*n)/(2*a*e*n) + (im*b*(e*x)^(2*n)*log(1 + (a*ℯ^(im*(c + d*x^n)))/(b - sqrt(-a^2 + b^2))))/(a*sqrt(-a^2 + b^2)*d*e*n*x^n) - (im*b*(e*x)^(2*n)*log(1 + (a*ℯ^(im*(c + d*x^n)))/(b + sqrt(-a^2 + b^2))))/(a*sqrt(-a^2 + b^2)*d*e*n*x^n) + (b*(e*x)^(2*n)*PolyLog(2, -((a*ℯ^(im*(c + d*x^n)))/(b - sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^2*e*n*x^(2*n)) - (b*(e*x)^(2*n)*PolyLog(2, -((a*ℯ^(im*(c + d*x^n)))/(b + sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^2*e*n*x^(2*n))]
    @test_int [(e*x)^(-1 + 3*n)/(a + b*sec(c + d*x^n)), x, 14, (e*x)^(3*n)/(3*a*e*n) + (im*b*(e*x)^(3*n)*log(1 + (a*ℯ^(im*(c + d*x^n)))/(b - sqrt(-a^2 + b^2))))/(a*sqrt(-a^2 + b^2)*d*e*n*x^n) - (im*b*(e*x)^(3*n)*log(1 + (a*ℯ^(im*(c + d*x^n)))/(b + sqrt(-a^2 + b^2))))/(a*sqrt(-a^2 + b^2)*d*e*n*x^n) + (2*b*(e*x)^(3*n)*PolyLog(2, -((a*ℯ^(im*(c + d*x^n)))/(b - sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^2*e*n*x^(2*n)) - (2*b*(e*x)^(3*n)*PolyLog(2, -((a*ℯ^(im*(c + d*x^n)))/(b + sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^2*e*n*x^(2*n)) + ((2*im)*b*(e*x)^(3*n)*PolyLog(3, -((a*ℯ^(im*(c + d*x^n)))/(b - sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^3*e*n*x^(3*n)) - ((2*im)*b*(e*x)^(3*n)*PolyLog(3, -((a*ℯ^(im*(c + d*x^n)))/(b + sqrt(-a^2 + b^2)))))/(a*sqrt(-a^2 + b^2)*d^3*e*n*x^(3*n))]

    @test_int [(e*x)^(-1 + n)/(a + b*sec(c + d*x^n))^2, x, 7, (e*x)^n/(a^2*e*n) - (2*b*(2*a^2 - b^2)*(e*x)^n*atanh((sqrt(a - b)*tan((c + d*x^n)/2))/sqrt(a + b)))/(a^2*(a - b)^(3/2)*(a + b)^(3/2)*d*e*n*x^n) + (b^2*(e*x)^n*tan(c + d*x^n))/(a*(a^2 - b^2)*d*e*n*x^n*(a + b*sec(c + d*x^n)))]
    @test_int [(e*x)^(-1 + 2*n)/(a + b*sec(c + d*x^n))^2, x, 23, (e*x)^(2*n)/(2*a^2*e*n) - (im*b^3*(e*x)^(2*n)*log(1 + (a*ℯ^(im*(c + d*x^n)))/(b - sqrt(-a^2 + b^2))))/(a^2*(-a^2 + b^2)^(3/2)*d*e*n*x^n) + ((2*im)*b*(e*x)^(2*n)*log(1 + (a*ℯ^(im*(c + d*x^n)))/(b - sqrt(-a^2 + b^2))))/(a^2*sqrt(-a^2 + b^2)*d*e*n*x^n) + (im*b^3*(e*x)^(2*n)*log(1 + (a*ℯ^(im*(c + d*x^n)))/(b + sqrt(-a^2 + b^2))))/(a^2*(-a^2 + b^2)^(3/2)*d*e*n*x^n) - ((2*im)*b*(e*x)^(2*n)*log(1 + (a*ℯ^(im*(c + d*x^n)))/(b + sqrt(-a^2 + b^2))))/(a^2*sqrt(-a^2 + b^2)*d*e*n*x^n) + (b^2*(e*x)^(2*n)*log(b + a*cos(c + d*x^n)))/(a^2*(a^2 - b^2)*d^2*e*n*x^(2*n)) - (b^3*(e*x)^(2*n)*PolyLog(2, -((a*ℯ^(im*(c + d*x^n)))/(b - sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^2*e*n*x^(2*n)) + (2*b*(e*x)^(2*n)*PolyLog(2, -((a*ℯ^(im*(c + d*x^n)))/(b - sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^2*e*n*x^(2*n)) + (b^3*(e*x)^(2*n)*PolyLog(2, -((a*ℯ^(im*(c + d*x^n)))/(b + sqrt(-a^2 + b^2)))))/(a^2*(-a^2 + b^2)^(3/2)*d^2*e*n*x^(2*n)) - (2*b*(e*x)^(2*n)*PolyLog(2, -((a*ℯ^(im*(c + d*x^n)))/(b + sqrt(-a^2 + b^2)))))/(a^2*sqrt(-a^2 + b^2)*d^2*e*n*x^(2*n)) + (b^2*(e*x)^(2*n)*sin(c + d*x^n))/(a*(a^2 - b^2)*d*e*n*x^n*(b + a*cos(c + d*x^n)))]
    @test_int [(e*x)^(-1 + 3*n)/(a + b*sec(c + d*x^n))^2, x, 32, (e*x)^(3*n)/(3*a^2*e*n) - (im*b^2*(e*x)^(3*n))/(x^n*(a^2*(a^2 - b^2)*d*e*n)) + (2*b^2*(e*x)^(3*n)*log(1 + (a*ℯ^(im*(c + d*x^n)))/(b - im*sqrt(a^2 - b^2))))/(x^(2*n)*(a^2*(a^2 - b^2)*d^2*e*n)) + (2*b^2*(e*x)^(3*n)*log(1 + (a*ℯ^(im*(c + d*x^n)))/(b + im*sqrt(a^2 - b^2))))/(x^(2*n)*(a^2*(a^2 - b^2)*d^2*e*n)) - (im*b^3*(e*x)^(3*n)*log(1 + (a*ℯ^(im*(c + d*x^n)))/(b - sqrt(-a^2 + b^2))))/(x^n*(a^2*(-a^2 + b^2)^(3/2)*d*e*n)) + (2*im*b*(e*x)^(3*n)*log(1 + (a*ℯ^(im*(c + d*x^n)))/(b - sqrt(-a^2 + b^2))))/(x^n*(a^2*sqrt(-a^2 + b^2)*d*e*n)) + (im*b^3*(e*x)^(3*n)*log(1 + (a*ℯ^(im*(c + d*x^n)))/(b + sqrt(-a^2 + b^2))))/(x^n*(a^2*(-a^2 + b^2)^(3/2)*d*e*n)) - (2*im*b*(e*x)^(3*n)*log(1 + (a*ℯ^(im*(c + d*x^n)))/(b + sqrt(-a^2 + b^2))))/(x^n*(a^2*sqrt(-a^2 + b^2)*d*e*n)) - (2*im*b^2*(e*x)^(3*n)*PolyLog(2, -((a*ℯ^(im*(c + d*x^n)))/(b - im*sqrt(a^2 - b^2)))))/(x^(3*n)*(a^2*(a^2 - b^2)*d^3*e*n)) - (2*im*b^2*(e*x)^(3*n)*PolyLog(2, -((a*ℯ^(im*(c + d*x^n)))/(b + im*sqrt(a^2 - b^2)))))/(x^(3*n)*(a^2*(a^2 - b^2)*d^3*e*n)) - (2*b^3*(e*x)^(3*n)*PolyLog(2, -((a*ℯ^(im*(c + d*x^n)))/(b - sqrt(-a^2 + b^2)))))/(x^(2*n)*(a^2*(-a^2 + b^2)^(3/2)*d^2*e*n)) + (4*b*(e*x)^(3*n)*PolyLog(2, -((a*ℯ^(im*(c + d*x^n)))/(b - sqrt(-a^2 + b^2)))))/(x^(2*n)*(a^2*sqrt(-a^2 + b^2)*d^2*e*n)) + (2*b^3*(e*x)^(3*n)*PolyLog(2, -((a*ℯ^(im*(c + d*x^n)))/(b + sqrt(-a^2 + b^2)))))/(x^(2*n)*(a^2*(-a^2 + b^2)^(3/2)*d^2*e*n)) - (4*b*(e*x)^(3*n)*PolyLog(2, -((a*ℯ^(im*(c + d*x^n)))/(b + sqrt(-a^2 + b^2)))))/(x^(2*n)*(a^2*sqrt(-a^2 + b^2)*d^2*e*n)) - (2*im*b^3*(e*x)^(3*n)*PolyLog(3, -((a*ℯ^(im*(c + d*x^n)))/(b - sqrt(-a^2 + b^2)))))/(x^(3*n)*(a^2*(-a^2 + b^2)^(3/2)*d^3*e*n)) + (4*im*b*(e*x)^(3*n)*PolyLog(3, -((a*ℯ^(im*(c + d*x^n)))/(b - sqrt(-a^2 + b^2)))))/(x^(3*n)*(a^2*sqrt(-a^2 + b^2)*d^3*e*n)) + (2*im*b^3*(e*x)^(3*n)*PolyLog(3, -((a*ℯ^(im*(c + d*x^n)))/(b + sqrt(-a^2 + b^2)))))/(x^(3*n)*(a^2*(-a^2 + b^2)^(3/2)*d^3*e*n)) - (4*im*b*(e*x)^(3*n)*PolyLog(3, -((a*ℯ^(im*(c + d*x^n)))/(b + sqrt(-a^2 + b^2)))))/(x^(3*n)*(a^2*sqrt(-a^2 + b^2)*d^3*e*n)) + (b^2*(e*x)^(3*n)*sin(c + d*x^n))/(x^n*(a*(a^2 - b^2)*d*e*n*(b + a*cos(c + d*x^n))))]
    end

max_stars_repo_path: test/4 Trig functions/4.5 Secant/4.5.11 (e x)^m (a+b sec(c+d x^n))^p.jl


text:
using Markdown
using InteractiveUtils

using Pkg, DrWatson

begin
    #@quickactivate "StatisticalRethinkingStan"
    using StanSample
    using StatisticalRethinking
end

begin
    N = 100
    df = DataFrame(
        :h0 => rand(Normal(10, 2 ), N),
        :treatment => vcat(zeros(Int, Int(N/2)), ones(Int, Int(N/2)))
    )
    df[!, :fungus] =
        [rand(Binomial.(1, 0.5 .- 0.4 .* df.treatment[i]), 1)[1] for i in 1:N]
    df[!, :h1] =
        [df[i, :h0] + rand(Normal(5 - 3 * df.fungus[i]), 1)[1] for i in 1:N]
    data = (N = nrow(df), h0 = df.h0, h1 = df.h1,
        fungus = df.fungus, treatment = df.treatment)
end;

stan6_6 = "
data {
  int <lower=1> N;
  vector[N] h0;
  vector[N] h1;
}
parameters{
  real<lower=0> p;
  real<lower=0> sigma;
}
transformed parameters {
  vector[N] mu;
  for ( i in 1:N ) {
    mu[i] = h0[i] * p;
  }
}

model {
  p ~ lognormal(0, 0.25);
  sigma ~ exponential(1);
  h1 ~ normal(mu, sigma);
}
generated quantities {
    vector[N] log_lik;
    for (i in 1:N)
        log_lik[i] = normal_lpdf(h1[i] | mu[i], sigma);
}
";

begin
    m6_6_data = Dict(
      :N => nrow(df),
      :h0 => df[:, :h0],
      :h1 => df[:, :h1]
    )
    m6_6s = SampleModel("m6.6s", stan6_6)
    rc6_6s = stan_sample(m6_6s; data)
end

stan6_7 = "
data {
  int <lower=1> N;
  vector[N] h0;
  vector[N] h1;
  vector[N] treatment;
  vector[N] fungus;
}
parameters{
  real a;
  real bt;
  real bf;
  real<lower=0> sigma;
}
transformed parameters {
  vector[N] mu;
  vector[N] p;
  for ( i in 1:N ) {
    p[i] = a + bt*treatment[i] + bf*fungus[i];
    mu[i] = h0[i] * p[i];
  }
}
model {
  a ~ lognormal(0, 0.2);
  bt ~ normal(0, 0.5);
  bf ~ normal(0, 0.5);
  sigma ~ exponential(1);
  h1 ~ normal(mu, sigma);
}
generated quantities {
    vector[N] log_lik;
    for ( i in 1:N )
        log_lik[i] = normal_lpdf( h1[i] | mu[i], sigma);
}
";

begin
    m6_7s = SampleModel("m6.7s", stan6_7)
    rc6_7s = stan_sample(m6_7s; data)
end

if success(rc6_7s)
    waic(m6_7s)
end

if success(rc6_7s)
    post6_7s_df = read_samples(m6_7s, :dataframe)
    b6_7s = post6_7s_df[:, [:a, :bt, :bf, :sigma]]
    p6_7s = b6_7s.a .+ b6_7s.bt * df.treatment' + b6_7s.bf * df.fungus'
    mu6_7s = p6_7s .* df.h0'
    log_lik = logpdf.(Normal.(mu6_7s, post6_7s_df.sigma),  df.h1')
    waic(log_lik)
end

stan6_8 = "
data {
  int <lower=1> N;
  vector[N] h0;
  vector[N] h1;
  vector[N] treatment;
}
parameters{
  real a;
  real bt;
  real<lower=0> sigma;
}
transformed parameters {
  vector[N] mu;
  vector[N] p;
  for ( i in 1:N ) {
    p[i] = a + bt*treatment[i];
    mu[i] = h0[i] * p[i];
  }
}
model {
  a ~ lognormal(0, 0.2);
  bt ~ normal(0, 0.5);
  sigma ~ exponential(1);
  h1 ~ normal(mu, sigma);
}
generated quantities {
    vector[N] log_lik;
    for (i in 1:N)
        log_lik[i] = normal_lpdf(h1[i] | mu[i], sigma);
}
";

begin
    m6_8s = SampleModel("m6.8s", stan6_8)
    rc6_8s = stan_sample(m6_8s; data)
end

# ╔═╡ 425a70dc-6bb3-11eb-1a7e-39f3133b7173
if success(rc6_6s) && success(rc6_7s) && success(rc6_8s)
    df_waic = compare([m6_6s, m6_7s, m6_8s], :waic)
end

# ╔═╡ 904b7004-6d69-11eb-07fe-65b5bb8c4dd2
if success(rc6_6s) && success(rc6_7s) && success(rc6_8s)
    df_psis = compare([m6_6s, m6_7s, m6_8s], :psis)
end

# ╔═╡ ee0899d8-68e1-11eb-2679-e304ef15e9e4
begin
    loo6_7s, loos6_7s, pk6_7s = psisloo(m6_7s)
    pk_plot(pk6_7s)
end

ext: jl


text:
#########THINGS TO DO ON STARTUP>>>>>>>>>>>
#   cd("/Users/Patrick/Documents/GitHub/SuperResolution/src")
#   press ] and type activate SuperResolution
#   CMD+A -> CMD+Enter to run SuperResolution file

##  NOTE
#   CMD+/ .. comment line
#   Ctrl+A, Ctrl+K .. delete line in terminal
#   Shift+CMD+[ or ] .. switch between open tabs/files in atom
#   Ctrl+1 or 2 .. switch between file and terminal
#   for more Keybinds check Atom settings
#

# │ import Pkg;
# │ Pkg.add("Conda")
# │ Conda.update()
# │ import Conda
# │ Pkg.build("PyPlot")

# I'd recommend just doing this kind of thing:
# using Plots
# pyplot() # this loads the `PyPlot` module
# # run your code that uses pyplot, ether using the Plots API, or the PyPlot API via `PyPlot.xxx`

# gr()
# # run your code that uses the default Plots backend, which is GR

#   Main.SuperResolution.SEGMENTtest to access the segementation
#   length(Main.SuperResolution.SEGMENTtest.idx) number of valid segments
#
#   Main.SuperResolution.EVALtest to access the test set clustering
#   Main.SuperResolution.EVALtest.K_ground_truth known number of clusters
#   Main.SuperResolution.EVALtest.diff_WK_max_idx estimated number of clusters
#   Main.SuperResolution.EVALtest.wModel[1].wkld distance matrix of segment 1
#   Main.SuperResolution.EVALtest.gapSR[1].diff_WK differences of WKLD
#   Main.SuperResolution.EVALtest.RefModel[2].K evolution for segment 2
#
#   Main.SuperResolution.EVALtest.distSR[1].Distance[1].singleDist_SR[1]
#
#   evalSR.jl   <-  clusGAP.jl  <-  clusSR.jl(DistanceSR)
##  NOTE
#   if the solveIDX is 11 for segment 1, the estimated number of clusters in this segment is
#   size(Main.SuperResolution.EVALtest.wModel[1].wkld[11],1)
#
#   if the solveIDX is 9 for segment 2, the estimated number of clusters in this segment is
#   size(Main.SuperResolution.EVALtest.wModel[2].wkld[9],1)
##  NOTE
# using Plots
# using Statistics
# tuP=0
# sel=5
#
# bar(Main.SuperResolution.EVALtest.wkldSR[sel].wkldMin)
# for i=(sel+1):5#length(Main.SuperResolution.EVALtest.wkldSR)
#     display(bar!(Main.SuperResolution.EVALtest.wkldSR[i].wkldMin))
# end
# savefig("/Users/Patrick/Documents/GitHub/SuperResolution/src/SR_Plots/01_ORI_KLC_wkldMin.pdf")
#
# sel=5
# bar(Main.SuperResolution.EVALtest.wkldSR[sel].wkldMinDelta, alpha=0.2)
# for i=(sel+1):6#length(Main.SuperResolution.EVALtest.wkldSR)
#     display(bar!(Main.SuperResolution.EVALtest.wkldSR[i].wkldMinDelta, alpha=0.2))
# end
# savefig("/Users/Patrick/Documents/GitHub/SuperResolution/src/SR_Plots/01_ORI_KLC_wkldMinDelta.pdf")
# #

# BarPlots=map(i->bar(Main.SuperResolution.EVALtest.wkldSR[i].wkldMinDelta, title="$(i)"),1:length(Main.SuperResolution.EVALtest.wkldSR))
# plot(BarPlots..., legend=false) #layout=(3,2)
# savefig("/Users/Patrick/Documents/GitHub/SuperResolution/src/SR_Plots/01_ORI_KLC_wkldMinDeltaSERIES.pdf")

# tmp=map(i->length(Main.SuperResolution.EVALtest.wkldSR[i].wkldMinDelta[Main.SuperResolution.EVALtest.wkldSR[i].wkldMinDelta.>quantile(Main.SuperResolution.EVALtest.wkldSR[i].wkldMinDelta, 0.95)])+1,1:length(Main.SuperResolution.EVALtest.wkldSR))

# #
# # plot(   bar(Main.SuperResolution.EVALtest.wkldSR[1].wkldMinDelta[2:end]./Main.SuperResolution.EVALtest.wkldSR[1].wkldMinDelta[1:end-1], title="1"),
# #         bar(Main.SuperResolution.EVALtest.wkldSR[2].wkldMinDelta[2:end]./Main.SuperResolution.EVALtest.wkldSR[2].wkldMinDelta[1:end-1], title="2"),
# #         bar(Main.SuperResolution.EVALtest.wkldSR[3].wkldMinDelta[2:end]./Main.SuperResolution.EVALtest.wkldSR[3].wkldMinDelta[1:end-1], title="3"),
# #         bar(Main.SuperResolution.EVALtest.wkldSR[4].wkldMinDelta[2:end]./Main.SuperResolution.EVALtest.wkldSR[4].wkldMinDelta[1:end-1], title="4"),
# #         bar(Main.SuperResolution.EVALtest.wkldSR[5].wkldMinDelta[2:end]./Main.SuperResolution.EVALtest.wkldSR[5].wkldMinDelta[1:end-1], title="5"),
# #         bar(Main.SuperResolution.EVALtest.wkldSR[6].wkldMinDelta[2:end]./Main.SuperResolution.EVALtest.wkldSR[6].wkldMinDelta[1:end-1], title="6"), layout=(3,2), legend=false   )
# # savefig("/Users/Patrick/Documents/GitHub/SuperResolution/src/SR_Plots/01_ORI_KLC_wkldMinSERIES.pdf")
# # #
# plot(minimum.(Main.SuperResolution.EVALtest.wModel[1].wkld[3:end-tuP]))
# plot!(minimum.(Main.SuperResolution.EVALtest.wModel[2].wkld[3:end-tuP]))
# plot(median.(Main.SuperResolution.EVALtest.wModel[1].wkld)[2:(end-tuP)])
# plot!(median.(Main.SuperResolution.EVALtest.wModel[2].wkld)[2:(end-tuP)])
#
# b1=map(i->Main.SuperResolution.EVALtest.wModel[1].wkld[i].<10^4,2:(size(Main.SuperResolution.EVALtest.wModel[1].wkld,1)-tuP))
# c1=map(i->median(Main.SuperResolution.EVALtest.wModel[1].wkld[i][b1[i-1]]),2:(size(Main.SuperResolution.EVALtest.wModel[1].wkld,1)-tuP))
# plot(c1)
#
# b2=map(i->Main.SuperResolution.EVALtest.wModel[2].wkld[i].<10^4,2:(size(Main.SuperResolution.EVALtest.wModel[2].wkld,1)-tuP))
# c2=map(i->median(Main.SuperResolution.EVALtest.wModel[2].wkld[i][b2[i-1]]),2:(size(Main.SuperResolution.EVALtest.wModel[2].wkld,1)-tuP))
# plot!(c2)
#
# b1=map(i->Main.SuperResolution.EVALtest.wModel[1].wkld[i].<10^4,2:(size(Main.SuperResolution.EVALtest.wModel[1].wkld,1)-tuP))
# c1=map(i->mean(Main.SuperResolution.EVALtest.wModel[1].wkld[i][b1[i-1]]),2:(size(Main.SuperResolution.EVALtest.wModel[1].wkld,1)-tuP))
# plot(c1)
#
# b2=map(i->Main.SuperResolution.EVALtest.wModel[2].wkld[i].<10^4,2:(size(Main.SuperResolution.EVALtest.wModel[2].wkld,1)-tuP))
# c2=map(i->mean(Main.SuperResolution.EVALtest.wModel[2].wkld[i][b2[i-1]]),2:(size(Main.SuperResolution.EVALtest.wModel[2].wkld,1)-tuP))
# plot!(c2)
#
# sel=1
# b3=map(i->Main.SuperResolution.EVALtest.wModel[sel].wkld[i].<10^4,2:(size(Main.SuperResolution.EVALtest.wModel[sel].wkld,1)-tuP))
# c3=map(i->median(Main.SuperResolution.EVALtest.wModel[sel].wkld[i][b3[i-1]]),2:(size(Main.SuperResolution.EVALtest.wModel[sel].wkld,1)-tuP))
# plot(c3)
#

# Main.SuperResolution.EVALtest.wModel[1].geom[14]
# Main.SuperResolution.EVALtest.wModel[1].weight[14]
#
# num=size(Main.SuperResolution.EVALtest.wModel,1)
#
# wkldFiltered=Array{Array{BitArray{2},1}}(undef,num)
# wkldMean=Array{Array{Float64,1},1}(undef,num)
# for k in 1:num
#     wkldFiltered[k]=map(i->Main.SuperResolution.EVALtest.wModel[k].wkld[i].<10^4,2:(size(Main.SuperResolution.EVALtest.wModel[k].wkld,1)-tuP))
#     wkldMean[k]=map(i->mean(Main.SuperResolution.EVALtest.wModel[k].wkld[i][wkldFiltered[k][i-1]]),2:(size(Main.SuperResolution.EVALtest.wModel[k].wkld,1)-tuP))
# end

#########TO DO>>>>>>>>>>>
#   - safe the SEGMENTtest segmentation in a variable so it does not need to be
#   processed every time
#
#   - find a new way to validate properly; e.g. correctly assigned members
#   (evalSR.jl, obj.corrDetecRate_GAP=...)
#
#   - transfer plot funtions from old files to new repo
#
#   - implement GAP-statistics for minKLD changes like used in RStudio
#   - allow for an additional parameter in GAP-statistics like in RStudio
#
########################################################################

module SuperResolution
global RESTR_SEG=2
global modINPUT=4
global fileINPUT_range=1:5

cd(dirname(@__FILE__))
using Statistics
using DataFrames
using Distances
using Random
using Dates
using CSV
using Distributions
using StatsPlots

global DATUM=Dates.format(now(),"yymmdd")

include("clusGAP.jl")
include("clusSR.jl")
include("evalSR.jl")
include("fctSR.jl")
include("importSR.jl")
include("plotSR.jl")
include("segmentSR.jl")
include("modelSR.jl")

greet()=print("\n\nSuper Resolution - Blinking Artifacts\n")
greet()
global filename1=Array{String,1}(undef,6)
global filename1[1]="ORI_SIM/locs_gamma.csv" # simulation data with framenumbers
global filename1[2]="ORI_SIM/locs_H57.csv"
global filename1[3]="ORI_SIM/locs_KT3.csv"
global filename1[4]="ORI_SIM/locs_PSCFP2.csv"
global filename1[5]="TET_SIM/locs_tet.csv"
global filename1[6]="MON_SIM/locs_mon.csv"
global filepath1 = map(i->joinpath(@__DIR__, filename1[i]),1:length(filename1))

global filename2=Array{String,1}(undef,6)
global filename2[1]="ORI_SIM/labels_gamma.csv"    # ground truth
global filename2[2]="ORI_SIM/labels_H57.csv"
global filename2[3]="ORI_SIM/labels_KT3.csv"
global filename2[4]="ORI_SIM/labels_PSCFP2.csv"
global filename2[5]="TET_SIM/labels_tet.csv"
global filename2[6]="MON_SIM/labels_mon.csv"
global filepath2 = map(i->joinpath(@__DIR__, filename2[i]),1:length(filename2))
# pStr1=filepath1
# pStr2=filepath2
# pStr1="/Users/Patrick/Documents/GitHub/SuperResolution/src/locs_gamma_conf.csv"
# pStr2="/Users/Patrick/Documents/GitHub/SuperResolution/src/labels_gamma.csv"
################################################################################
################################################################################

DIAGNOSTICS=true
if DIAGNOSTICS==true
        print("DIAGNOSTICS = true")
        valid_DF=Array{DataFrame,1}(undef, length(fileINPUT_range))
        error_DF=Array{DataFrame,1}(undef, length(fileINPUT_range))

        error_DF = map(i-> CSV.read(joinpath(@__DIR__,string("/Users/Patrick/Documents/GitHub/SuperResolution/src/VALID_OUT/210919fileINPUT",fileINPUT_range[i],"-modINPUT4-NUM_SEG_150-MSE_standW.csv")),
                                        types=[String,Float64,Float64],
                                        header=["idx","clus_vs_mol_MSE","clus_vs_mol_MAE"], datarow=2, DataFrame), fileINPUT_range)
        lengths = map(i->length(error_DF[i].clus_vs_mol_MAE),fileINPUT_range)
        idx = vcat(map(i->repeat([i],inner=lengths[i])[:],fileINPUT_range)...)
        errors = vcat(map(i->error_DF[i].clus_vs_mol_MAE,fileINPUT_range)...)
        # valid_DF = map(i-> CSV.read(joinpath(@__DIR__,string("/Users/Patrick/Documents/GitHub/SuperResolution/src/VALID_OUT/210919fileINPUT",fileINPUT_range[i],"-modINPUT4-NUM_SEG_150-MSE_standW.csv")),
        #                                 types=[String,Float64,Float64],
        #                                 header=["idx","clus_vs_mol_MSE","clus_vs_mol_MAE"], datarow=2, DataFrame), fileINPUT_range)

        Plots.boxplot(idx,errors,legend=false)
        Plots.savefig(joinpath(@__DIR__,string("DIAGNOSTICS/",DATUM,"_fileINPUT$(fileINPUT_range)-modINPUT$(modINPUT)-DIAGNOSTICS.pdf")))
        Plots.savefig(joinpath(@__DIR__,string("VALID_OUT/",DATUM,"_fileINPUT$(fileINPUT_range)-modINPUT$(modINPUT)-DIAGNOSTICS.pdf")))
        PyPlot.close("all")
else
        for fileINPUT=fileINPUT_range
                # print_mode=[    "K_KL_estimated_by_mean",                    #1
                #                 "K_KL_estimated_by_median",                  #2
                #                 "K_KL_estimated_by_max",                     #3
                #                 "K_KL_estimated_by_minDelta",                #4
                #                 "K_KL_estimated_by_95quantile"]              #5
                select_mode=[   :K_KL_estimated_by_mean,                    #   modINPUT=1
                                :K_KL_estimated_by_median,                  #   modINPUT=2
                                :K_KL_estimated_by_max,                     #   modINPUT=3
                                :K_KL_estimated_by_minDelta,                #   modINPUT=4
                                :K_KL_estimated_by_95quantile]              #   modINPUT=5

                global DataSim, RealLocs=importSR(filepath1[fileINPUT],filepath2[fileINPUT])
                # using SuperResolution
                #SEG_SPLIT=100 splits the data into 100x100=10^4 segments of equal size
                # SEG_SPLIT=200;
                SEGMENT_TMP_IMPORT=SuperResolution.SegmentSR(1,SuperResolution.DataSim,SuperResolution.RealLocs); #segment data
                SEG_SIZE_NM=SEGMENT_TMP_IMPORT.bounds_overall.nm_x/sqrt(SEGMENT_TMP_IMPORT.N[1])
                print("*** fileINPUT = $(fileINPUT) ***\n")
                print("*** SEG_SIZE_NM = $(SEG_SIZE_NM) ***\n")
                # SEG_SIZE_NM=100.0
                SEG_SPLIT=Int64(ceil(maximum([SEGMENT_TMP_IMPORT.bounds_overall.nm_x,SEGMENT_TMP_IMPORT.bounds_overall.nm_y])/SEG_SIZE_NM)); # 25nm^2 segments
                global SEGMENTtest=SuperResolution.SegmentSR(SEG_SPLIT,SuperResolution.DataSim,SuperResolution.RealLocs); #segment data
                print("*** $(length(SuperResolution.SEGMENTtest.idx)) valid Segments ***\n")
                # NUM_SEG=2 #sets a test set of 10 segments for clustering
                NUM_SEG=minimum([length(SuperResolution.SEGMENTtest.idx),RESTR_SEG]);   #eval all or minimum number of valid segments
                # NUM_SEG=length(SuperResolution.SEGMENTtest.idx);   #eval all valid segments
                rng=MersenneTwister(2);
                SEG_RESTR=unique(rand(rng,SEGMENTtest.idx,NUM_SEG));

                global EVALtest=SuperResolution.EvalSR(SEGMENTtest,SEG_RESTR,modINPUT);
        ## CSV OUTPUT
                CSV.write(joinpath(@__DIR__,string("VALID_OUT/",DATUM,"_fileINPUT$(fileINPUT)-modINPUT$(modINPUT)-NUM_SEG$(NUM_SEG)-absChange_standW.csv")),EVALtest.VALID_DF,header=true)
                CSV.write(joinpath(@__DIR__,string("VALID_OUT/",DATUM,"fileINPUT$(fileINPUT)-modINPUT$(modINPUT)-NUM_SEG$(NUM_SEG)-MSE_standW.csv")),EVALtest.error_DF,header=true)
                map(i->CSV.write(joinpath(@__DIR__,string("VALID_OUT/",DATUM,"_fileINPUT$(fileINPUT)-modINPUT$(modINPUT)-SEG_SIZE_NM$(Int64(floor(SEG_SIZE_NM)))-NUM_SEG$(NUM_SEG)-locID_DF_$(i)_standW.csv")),EVALtest.locID_DF[i],header=true),1:length(EVALtest._selectIDX))
                map(i->CSV.write(joinpath(@__DIR__,string("VALID_OUT/",DATUM,"_fileINPUT$(fileINPUT)-modINPUT$(modINPUT)-SEG_SIZE_NM$(Int64(floor(SEG_SIZE_NM)))-NUM_SEG$(NUM_SEG)-evo_DF_$(i)_standW.csv")),EVALtest.evo_DF[i],header=true),1:length(EVALtest._selectIDX))
        ## PLOTS
                using Plots
                global BarPlots=Array{Plots.Plot{Plots.GRBackend}}(undef,length(EVALtest.wkldSR))
                plots_per_page=16
                num_of_plots=Int64(ceil(length(EVALtest.wkldSR)/plots_per_page))
                for k=1:num_of_plots
                        for i=(1+(k-1)*plots_per_page):(minimum([k*plots_per_page,length(EVALtest.wkldSR)]))#length(EVALtest.wkldSR)
                                BarPlots[i]=Plots.bar(EVALtest.wkldSR[i].wkldMinDelta, title="part($(EVALtest._selectIDX[i][1])-$(EVALtest._selectIDX[i][2])) - $(getproperty(EVALtest, select_mode[modINPUT])[i])/$(EVALtest.K_ground_truth[i])/$(EVALtest.N_observations[i])",
                                titlefont=font(8,"Computer Modern"))
                                Plots.plot!([quantile(EVALtest.wkldSR[i].wkldMinDelta,0.95)],seriestype="hline")
                        end
                        Plots.plot(BarPlots[(1+(k-1)*plots_per_page):(minimum([k*plots_per_page,length(EVALtest.wkldSR)]))]..., legend=false) #layout=(3,2)
                        Plots.savefig(joinpath(@__DIR__,string("VALID_OUT/",DATUM,"_fileINPUT$(fileINPUT)-modINPUT$(modINPUT)-SEG_SIZE_NM$(Int64(floor(SEG_SIZE_NM)))-NUM_SEG$(NUM_SEG)-absChange_standW_$(k)of$(num_of_plots).pdf")))
                        PyPlot.close("all")
                end
                plotSR(SEGMENTtest,EVALtest,fileINPUT,modINPUT)
                PyPlot.close("all")
        end
end
end
# valid_DF=Array{DataFrame,1}(undef, length(fileINPUT_range))
# error_DF=Array{DataFrame,1}(undef, length(fileINPUT_range))

# error_DF = map(i-> CSV.read(joinpath(@__DIR__,string("/Users/Patrick/Documents/GitHub/SuperResolution/src/VALID_OUT/210919fileINPUT",fileINPUT_range[i],"-modINPUT4-NUM_SEG_150-MSE_standW.csv")),
#                                 types=[String,Float64,Float64],
#                                 header=["idx","clus_vs_mol_MSE","clus_vs_mol_MAE"], datarow=2, DataFrame), fileINPUT_range)

# # valid_DF = map(i-> CSV.read(joinpath(@__DIR__,string("/Users/Patrick/Documents/GitHub/SuperResolution/src/VALID_OUT/210919fileINPUT",fileINPUT_range[i],"-modINPUT4-NUM_SEG_150-MSE_standW.csv")),
# #                                 types=[String,Float64,Float64],
# #                                 header=["idx","clus_vs_mol_MSE","clus_vs_mol_MAE"], datarow=2, DataFrame), fileINPUT_range)
# using StatsPlots
# Plots.boxplot()
# Plots.savefig(joinpath(@__DIR__,string("VALID_OUT/",DATUM,"_fileINPUT$(fileINPUT)-modINPUT$(modINPUT)-SEG_SIZE_NM$(Int64(floor(SEG_SIZE_NM)))-NUM_SEG$(NUM_SEG)-absChange_standW_$(k)of$(num_of_plots).pdf")))
# PyPlot.close("all")

################################################################################
################################################################################
# EMP2=EVALtest;
# #tmp2=SEGMENTtest;
# #
# asdf=map(i->sum(SEGMENTtest.N[CartesianIndex(SEGMENTtest.idx[i])]),1:NUM_SEG)
# asdf2=map(i->(EVALtest.ground_truth_K-EVALtest.diff_WK_max_idx)[i]/EVALtest.ground_truth_K[i],1:NUM_SEG)
# plot([EVALtest.ground_truth_K-EVALtest.diff_WK_max_idx,log.(asdf),asdf2])
# plot(asdf2)
# #
##
# tmp2=SuperResolution.ModelSR(SEGMENTtest,(8,8),1)  #for segment create all models  WKLD
# tmp22=SuperResolution.ModelSR(SEGMENTtest,(8,8),2)  #for segment create all models KLD
# tmp3=SuperResolution.DistanceSR(tmp2,1)    #cluster WKLD
# tmp33=SuperResolution.DistanceSR(tmp2,2)   #cluster KLD
# tmp4=SuperResolution.clusGAP(tmp2,tmp22,1)  #Gap statistic
# tmp44=SuperResolution.clusGAP(tmp2,tmp22,2)  #Gap statistic
# #
# using SuperResolution
# SEGMENTtest=SuperResolution.SegmentSR(10,SuperResolution.DataSim,SuperResolution.RealLocs) #segment data
# tmp2=SuperResolution.ModelSR(SEGMENTtest,(2,3),1)  #for segment create all models  WKLD
# tmp22=SuperResolution.ModelSR(SEGMENTtest,(2,3),2)  #for segment create all models KLD
# tmp3=SuperResolution.DistanceSR(tmp2,1)    #cluster WKLD
# tmp33=SuperResolution.DistanceSR(tmp2,2)   #cluster KLD
# tmp4=SuperResolution.clusGAP(tmp2,tmp22,1)  #Gap statistic
# tmp44=SuperResolution.clusGAP(tmp2,tmp22,2)  #Gap statistic
# #
# id1=1
# id2=9
# tmp2=SuperResolution.ModelSR(SEGMENTtest,(id1,id2),1)  #for segment create all models  WKLD
# tmp22=SuperResolution.ModelSR(SEGMENTtest,(id1,id2),2)  #for segment create all models KLD
# tmp3=SuperResolution.DistanceSR(tmp2,1)    #cluster WKLD
# tmp33=SuperResolution.DistanceSR(tmp2,2)   #cluster KLD
# tmp4=SuperResolution.clusGAP(tmp2,tmp22,1)  #Gap statistic
# tmp44=SuperResolution.clusGAP(tmp2,tmp22,2)  #Gap statistic
#
# asdf=tmp4.W_K[1:(end-1)]-tmp4.W_K[2:end]
# plot(asdf)
#
# #
# scatter([SEGMENTtest.MU[2,3][:,1],tmp2.loc[end-5][:,1]],[SEGMENTtest.MU[2,3][:,2],tmp2.loc[end-5][:,2]])
# scatter(SEGMENTtest.MU[2,3][:,1],SEGMENTtest.MU[2,3][:,2])
# scatter(tmp2.loc[end-5][:,1],tmp2.loc[end-5][:,2])
# asdf=tmp4.W_K[1:(end-1)]-tmp4.W_K[2:end]
# plot(asdf)
#             K_SR::Int64
#             N_SR::Int64
#             val_bool::BitArray{1}
#             val_bool2::Array{BitArray{1},1}
#             singleDist_SR::Array{Array{Float64,2},1}
#             loc_SR::Array{Array{Array,1},1}
#             frame_SR::Array{Array{Int64,1},1}
#             cov_SR::Array{Array{Array{Float64,2},1},1}
#             D_SR::Array{Float64,1}
#             W_K::Float64
#             weight_SR::Array{Array{Float64,2},1}
# SEGMENTtest=SuperResolution.SegmentSR(10,SuperResolution.DataSim,SuperResolution.RealLocs)
# SAMPLE1=SuperResolution.ctrans(rand(tmp2.model[end-1],60))
# gather_X1=hcat(SEGMENTtest.loc[8,8][:,2],SAMPLE1[:,1])
# scatter(SuperResolution.𝕐sim[:,1],SuperResolution.𝕐sim[:,2])
# scatter(SEGMENTtest.loc[8,8][:,1],SEGMENTtest.loc[8,8][:,2])
# tmp2=SuperResolution.ModelSR(SEGMENTtest,(8,8))
# tmp3=(map(i->mean(tmp2.weight[i]),2:(length(tmp2.weight)-1)))
# tmp4=(map(i->mean(tmp2.param[i]),1:(length(tmp2.param)-1)))
# plot(tmp3)
# plot(tmp4)
# scatter(SEGMENTtest.loc[8,8][:,1],SEGMENTtest.loc[8,8][:,2])
# plot(contourf(exp(abs.(tmp2.wkld[end-8]-tmp3.wkld[end-8]))))
# global NN=20	# partition of space in (NN-1)^2 parts
#
# global evalErrSINGLE=[[0.0],]
# global evalErrGLOBAL=[[0.0],]
# global evalmeanErrGLOBAL=[0.0,]
# global evalcountErrGLOBAL=[0.0,]
# global evalcountErrGLOBAL2=[0,]
# #global evalSEED=[0,]
#
# global partN_valid=[0,]
# global partN2_valid=[0,]
#
# global estim_mol_numberGLOBAL=[0,]
# global sim_mol_numberGLOBAL=[0,]
# global obsGLOBAL=[0,]
#
# global 𝕐estAll=Array{Float64,2}(undef, 0,2)
# global 𝕐simAll=Matrix{Float64}(DataSim[[4,5],])
#
# global 𝕄simAll= Vector{Int64}(DataSim[1,])
# global 𝛍simAll= Matrix{Float64}(undef,length(unique(𝕄simAll)),2)
# #For unique molecule numbers compute means (needed for evaluation)
# for i=1:length(unique(𝕄simAll))
# 	global 𝛍simAll[i,:]=mean(𝕐simAll[𝕄simAll .== unique(𝕄simAll)[i],1:2]',dims=2)[:]
# end

max_stars_repo_name: PGSch/SuperResolution

max_issues_repo_name: PGSch/SuperResolution

max_forks_repo_name: PGSch/SuperResolution


text:
function fetch_model(instance::AbstractString;options::Dict=Dict())

    pname = replace(splitdir(instance)[end], Pair(".jl", ""))
    nakeinstance = replace(instance, Pair(".jl", ""))

    if "$(pname).jl" in special_instances
        m = getfield(MINLPLib, Symbol(pname))(options=options)
    elseif isfile(joinpath(minlplib_dir, "instances", "$(nakeinstance).jl"))
        m = include(joinpath(minlplib_dir, "instances", "$(nakeinstance).jl"))
    else
        @warn "No instances detected..."
        return nothing
    end

    return m
end

fetch_model(libname::AbstractString, pname::AbstractString; options::Dict=Dict()) = fetch_model(joinpath(libname,pname); options=options)

function fetch_meta(instance::AbstractString)

    if !isfile(joinpath(minlplib_dir, "meta", "$(instance).json"))
        @warn "No meta information for $(instance) found"
        return Dict()
    end

    m = JSON.parsefile(joinpath(minlplib_dir, "meta", "$(instance).json"))

    if haskey(m, "INTERNALLINK")
        sourcelib = m["INTERNALLINK"]
        isempty(sourcelib) && return Dict()
        pname = splitdir(instance)[end]
        return JSON.parsefile(joinpath(minlplib_dir, "meta", sourcelib, "$(pname).json"))
    end

    return m
end

fetch_meta(libname::AbstractString, pname::AbstractString) = fetch_meta(joinpath(libname,pname))

function fetch_names(libname::AbstractString; postfix=false)

    !isdir(joinpath(minlplib_dir, "instances", libname)) && error("Library $(libname) does not exist.")

    nraw = readdir(joinpath(minlplib_dir, "instances", libname))
    nlist = []
    inactive = 0
    postfix && return nlist
    for i in 1:length(nraw)
        if !(nraw[i][1] in ['_', '#']) && !(nraw[i] == "README.md")
            postfix ? push!(nlist, nraw[i]) : push!(nlist, replace(nraw[i], Pair(r".tar.gz|.jl", "")))
        else
            inactive += 1
        end
    end
    return nlist
end

function fetch_lib_names()
    libs = readdir(joinpath(minlplib_dir, "instances"))
    return [i for i in libs if i != "special"]
end

function show_basic_dimensions(libname::AbstractString, pname::AbstractString)

    !isfile("$(minlplib_dir)/meta/$(libname)/$(pname).json") && error("No meta file detected...")

    m = JSON.parsefile("$(minlplib_dir)/meta/$(libname)/$(pname).json")
	println("$(libname) $(pname) $(m["LOAD"]) $(m["OBJSENSE"]) $(m["NVARS"]) $(m["NBINVARS"]) $(m["NINTVARS"]) $(m["NCONS"]) $(m["NLINCONS"]) $(m["NNLCONS"]) $(m["NCONS"]-m["NLINCONS"]-m["NNLCONS"])")
    return
end

function add_to_meta(libname::AbstractString, pname::AbstractString, attributename::AbstractString, attributevalue::Any; injection::Bool=false)

    jlf_path = "$(minlplib_dir)/instances/$(libname)/$(pname).jl"

    if !isfile(jlf_path)
        error("No problem $(libname)/$(pname) detected...")
    end

    # Even with the instance file, meta file can still be missing
    if !isfile("$(minlplib_dir)/meta/$(libname)/$(pname).json")
        meta = Dict()
    else
        meta = JSON.parsefile("$(minlplib_dir)/meta/$(libname)/$(pname).json")
    end
    meta[attributename] = attributevalue
    if injection
        @warn "Meta injection is ON. Built-in meta info will be over-written!"
        isfile("$(minlplib_dir)/meta/$(libname)/$(pname).json") && rm("$(minlplib_dir)/meta/$(libname)/$(pname).json")
        f = open("$(minlplib_dir)/meta/$(libname)/$(pname).json", "w")
        JSON.print(f, meta)
        close(f)
        return
    end
    return meta
end

function benchmark_load(libname::AbstractString, pname::AbstractString)
	st = time()
	m = fetch_model("$(libname)/$(pname)")
	println("Load time $(libname) / $(pname) $(time()-st)")
	return
end

function add_to_lib(tolib::AbstractString, fromlib::AbstractString, instance::AbstractString; copyall=false, override=false)

    if !override
        tolib in PROTECTED_LIBS && error("In-take library is protected by package. Use override=true to change it.")
    end

    pname = replace(splitdir(instance)[end], Pair(".jl", ""))
    isempty(pname) && error("Issue recognizing instance name from string $(instance)...")

    # First check if there is actually the library
    if !isdir(joinpath(minlplib_dir, "instances", tolib))
        @info "Initializing user-library $(tolib)..."
        mkdir(joinpath(minlplib_dir, "instances", tolib))
        mkdir(joinpath(minlplib_dir, "meta", tolib))
    end

    # Then check is the intaking lib is already there.
    if isfile(joinpath(minlplib_dir, "instances", tolib, "$(pname).jl"))
        @warn "Instance $(pname) already exist in in-take library $(tolib). Not doing anything..."
        return
    end

    # Check if the source instance exist or not
    if !isfile(joinpath(minlplib_dir, "instances", fromlib, "$(pname).jl"))
        @warn "Instance $(pname) is not detected in library $(fromlib). Not doing anything..."
        return
    end

    # Check if the source meta exist or not
    nometa = false
    if !isfile(joinpath(minlplib_dir, "meta", fromlib, "$(pname).json"))
        @warn "Instance $(pname) meta info missing in library $(fromlib). Carry on without meta info..."
        nometa = true
    end

    # Adding the instance
    f = open(joinpath(minlplib_dir, "instances", tolib, "$(pname).jl"), "w")
    write(f, "include(joinpath(raw\"$(minlplib_dir)\",\"instances\",\"$(fromlib)\", \"$(pname).jl\"))")
    close(f)
    println("Successfully added instance $(fromlib)/$(pname) to library $(tolib)...")

    if !nometa
        desjson = joinpath(minlplib_dir, "meta", tolib, "$(pname).json")
        df = open(desjson, "w")
        md = Dict("INTERNALLINK"=>fromlib)
        JSON.print(df, md)
        close(df)
    end

    return
end

function remove_from_lib(libname::AbstractString, pname::AbstractString)

    # Library protection
    if libname in PROTECTED_LIBS
        error("Cannot remote instances from protected libraries $(libname)")
        return
    end

    # Finding instance
    if !isfile(joinpath(minlplib_dir, "instances",libname, "$(pname).jl"))
        @warn "No instances detected to remote."
        return
    end

    nometa = false
    if !isfile(joinpath(minlplib_dir, "meta", libname, "$(pname).json"))
        @warn "No meta detected to remote."
        nometa = true
    end

    # Removing instance
    @warn "Removing instance $(pname) from library $(libname)"
    rm(joinpath(minlplib_dir, "instances", libname, "$(pname).jl"))
    nometa || rm(joinpath(minlplib_dir, "meta", libname, "$(pname).json"))

    return
end

function clean_lib_meta(libname::AbstractString)

    names = fetch_names(libname)
    metas = Glob.glob("*.json", joinpath(minlplib_dir, "meta", libname))

    for i in metas
        n = replace(splitdir(i)[end], Pair(".json", ""))
        n in names || rm(joinpath(minlplib_dir, "meta", libname, "$(n).json",))
        @info "Cleaning $(n).json meta from library $(libname)"
    end

    return
end

function reconstruct_link_meta(libname::AbstractString)

    if libname in PROTECTED_LIBS
        @warn "Meta info cannot be reconstructed in this library since it is protected. Finishing..."
        return
    end

    names = fetch_names(libname)
    for i in names
        pf = open(joinpath(minlplib_dir, "instances", libname, "$(i).jl"), "r")
        content = readline(pf)
        sourcelib = ""
        for j in PROTECTED_LIBS
            if contains(content, j)
                sourcelib = j
            end
        end
        close(pf)
        meta = Dict("INTERNALLINK"=>sourcelib)
        pf = open(joinpath(minlplib_dir, "meta", libname, "$(i).json"), "w")
        JSON.print(pf, meta)
        close(pf)
    end

    return
end

function convert_minlplib2_meta(pname::AbstractString; outputpath="")

    if !isfile("$minlplib_dir/MINLPLib/.solvedata/minlplib2/$(pname).prop")
        show && @info "No $(pname).prop found"
        return
    end

    pf = open("$minlplib_dir/MINLPLib/.solvedata/minlplib2/$(pname).prop", "r")
    pc = Dict()

    for l in readlines(pf)
        sl = split(l, "=")
        identifier = split(sl[1])[1]
        if length(sl) > 1
            try
                pc[Symbol(identifier)] = parse(sl[2])
            catch e
                pc[Symbol(identifier)] = sl[2]
            end
        end
    end
    close(pf)

    !haskey(pc, :OBJSENSE) && @info "No detection of objective sense in $(pname).prop"
    !haskey(pc, :OBJSENSE) && return
    obj_sense = pc[:OBJSENSE]

    found = true
    i = 1
    if isfile("$minlplib_dir/MINLPLib/.solvedata/minlplib2/$(pname).prop")
        pf = open("$minlplib_dir/MINLPLib/.solvedata/minlplib2/$(pname).prop", "r")
        for l in readlines(pf)
            sl = split(l)
            if length(sl) > 2
                sl[1] == "OBJVALUE" && (pc[:OBJVALUE] = parse(sl[3]))
                sl[1] == "INFEASIBILITY" && (pc[:INFEASIBILITY] = parse(sl[3]))
            end
        end
        close(pf)
    else
        @warn "No detection of the solution p# file $(pname)"
    end

    obj_sense == :min ? bound = -Inf : bound = +Inf
    if isfile("$minlplib_dir/MINLPLib/.solvedata/minlplib2/$(pname).db")
        dbf = open("$minlplib_dir/MINLPLib/.solvedata/minlplib2/$(pname).db", "r")
        last_l = ""
        for l in readlines(dbf)
            sl = split(l)
            if length(sl) > 2 && sl[1] == "DUALBOUND"
                if obj_sense == :min
                    bound_candidate = parse(sl[3])
                    bound_candidate == :inf && (bound_candidate = Inf)
                    if bound_candidate > bound
                        bound = bound_candidate
                    end
                elseif obj_sense == :max
                    bound_candidate = parse(sl[3])
                    if bound_candidate < bound
                        bound = bound_candidate
                    end
                end
            end
            last_l = l
        end
        close(dbf)
    end

    pc[:OBJBOUND] = bound

    haskey(pc, :LIBRARY) || (pc[:LIBRARY] = "minlplib2")
    haskey(pc, :NAME) || (pc[:NAME] = pname)
    haskey(pc, :SOURCE) || (pc[:SOURCE] = "http://www.gamsworld.org/minlp/minlplib2/html/")

    if isempty(outputpath)
        f = open("$minlplib_dir/MINLPLib/meta/PODLib/$(pname).json", "w")
    else
        f = open(outputpath, "w")
    end

    JSON.print(f, pc)
    close(f)

    return pc
end

# function build_basic_meta(libname::AbstractString, pname::AbstractString; injection::Bool=false)

# 	st = time()
#     m = fetch_model(libname, pname)
# 	lt = time() - st

#     d = JuMP.NLPEvaluator(m)
#     MathProgBase.initialize(d, [:Grad, :Jac, :HessVec, :Hess, :ExprGraph])

#     meta = Dict("OBJTYPE"=> d.has_nlobj ? "nonlinear" : "linear",
#                 "LIBRARY"=> libname,
#                 "OBJSENSE"=> m.objSense,
#                 "OBJVAL" => m.objSense == :Max ? -Inf : Inf,
#                 "OBJBOUND"=> m.objSense == :Max ? Inf : -Inf,
#                 "NCONS"=> length(m.linconstr)+length(m.sosconstr)+length(m.sdpconstr)+length(m.quadconstr)+length(d.constraints),
#                 "NLINCONS"=> length(m.linconstr),
#                 "NSOSCONS"=> length(m.sosconstr),
#                 "NSDPCONS"=> length(m.sdpconstr),
#                 "NQUADCONS" => length(m.quadconstr),
#                 "NNLCONS" => length(d.constraints),
#                 "NAME"=> pname,
#                 "NLOPERANDS"=> [],  # TODO: introduce the expression sweeper here
#                 "NVARS"=> m.numCols,
#                 "NINTVARS"=> length([i for i in m.colCat if i == :Int]),
#                 "NBINVARS"=> length([i for i in m.colCat if i == :Bin]),
# 				"LOAD"=>lt)

#     if injection
#         @warn "Meta injection is ON. Built-in meta info will be over-written!"
#         !isdir(joinpath(minlplib_dir, "meta", libname)) && mkdir(joinpath(minlplib_dir, "meta", libname))
#         f = open(joinpath(minlplib_dir, "meta", libname, "$(pname).json"), "w")
#         JSON.print(f, meta)
#         close(f)
#         return
#     end

#     return meta
# end

max_stars_repo_name: PSORLab/RSActivationFunctions

max_issues_repo_name: PSORLab/RSActivationFunctions

max_forks_repo_name: PSORLab/RSActivationFunctions


text:
#####
##### Horizontal Laplacians
#####

@inline function ∇²hᶜᶜᶜ(i, j, k, grid, c)
    return 1/Vᶜᶜᶜ(i, j, k, grid) * (δxᶜᵃᵃ(i, j, k, grid, Ax_∂xᶠᶜᶜ, c) +
                                    δyᵃᶜᵃ(i, j, k, grid, Ay_∂yᶜᶠᶜ, c))
end

@inline function ∇²hᶠᶜᶜ(i, j, k, grid, u)
    return 1/Vᶠᶜᶜ(i, j, k, grid) * (δxᶠᵃᵃ(i, j, k, grid, Ax_∂xᶜᶜᶜ, u) +
                                    δyᵃᶜᵃ(i, j, k, grid, Ay_∂yᶠᶠᶜ, u))
end

@inline function ∇²hᶜᶠᶜ(i, j, k, grid, v)
    return 1/Vᶜᶠᶜ(i, j, k, grid) * (δxᶜᵃᵃ(i, j, k, grid, Ax_∂xᶠᶠᶜ, v) +
                                    δyᵃᶠᵃ(i, j, k, grid, Ay_∂yᶜᶜᶜ, v))
end

@inline function ∇²hᶜᶜᶠ(i, j, k, grid, w)
    return 1/Vᶜᶠᶜ(i, j, k, grid) * (δxᶜᵃᵃ(i, j, k, grid, Ax_∂xᶠᶠᶜ, v) +
                                    δyᵃᶠᵃ(i, j, k, grid, Ay_∂yᶜᶜᶜ, v))
end

"""
    ∇²ᶜᶜᶜ(i, j, k, grid, c)

Calculates the Laplacian of `c` via

```
1/V * [δxᶜᵃᵃ(Ax * ∂xᶠᵃᵃ(c)) + δyᵃᶜᵃ(Ay * ∂yᵃᶠᵃ(c)) + δzᵃᵃᶜ(Az * ∂zᵃᵃᶠ(c))]
```

which will end up at the location `ccc`.
"""
@inline function ∇²ᶜᶜᶜ(i, j, k, grid, c)
    return 1/Vᶜᶜᶜ(i, j, k, grid) * (δxᶜᵃᵃ(i, j, k, grid, Ax_∂xᶠᶜᶜ, c) +
                                    δyᵃᶜᵃ(i, j, k, grid, Ay_∂yᶜᶠᶜ, c) +
                                    δzᵃᵃᶜ(i, j, k, grid, Az_∂zᶜᶜᶠ, c))
end

@inline function ∇²ᶠᶜᶜ(i, j, k, grid, u)
    return 1/Vᶠᶜᶜ(i, j, k, grid) * (δxᶠᵃᵃ(i, j, k, grid, Ax_∂xᶜᶜᶜ, u) +
                                    δyᵃᶜᵃ(i, j, k, grid, Ay_∂yᶠᶠᶜ, u) +
                                    δzᵃᵃᶜ(i, j, k, grid, Az_∂zᶠᶜᶠ, u))
end

@inline function ∇²ᶜᶠᶜ(i, j, k, grid, v)
    return 1/Vᶜᶠᶜ(i, j, k, grid) * (δxᶜᵃᵃ(i, j, k, grid, Ax_∂xᶠᶠᶜ, v) +
                                    δyᵃᶠᵃ(i, j, k, grid, Ay_∂yᶜᶜᶜ, v) +
                                    δzᵃᵃᶜ(i, j, k, grid, Az_∂zᶜᶠᶠ, v))
end

@inline function ∇²ᶜᶜᶠ(i, j, k, grid, w)
    return 1/Vᶜᶜᶠ(i, j, k, grid) * (δxᶜᵃᵃ(i, j, k, grid, Ax_∂xᶠᶜᶠ, w) +
                                    δyᵃᶜᵃ(i, j, k, grid, Ay_∂yᶜᶠᶠ, w) +
                                    δzᵃᵃᶠ(i, j, k, grid, Az_∂zᶜᶜᶜ, w))
end


text:
using JuMP
using CPLEX

include("parser.jl")

start = time()

function P1(MyFileName::String)
  P, h, n, w1, w2, l, g, t = read_instance(MyFileName)
  w1 = 1
  w2 = 5

  # Create the model
  m = Model(CPLEX.Optimizer)

  ## Variables
  @variable(m, x[1:n+2,1:h+2], Bin)
  @variable(m, d[1:n+2,1:h+2] >= 0)

  ## Constraints
  @constraint(m, [i in 2:n+1, j in 2:h+1], d[i,j] <= x[i,j+1] + x[i+1,j] + x[i-1,j] + x[i,j-1] - 4 * (1 - x[i,j]))
  @constraint(m, sum(x[i,j] for i in 2:n+1, j in 2:h+1) >= 60)

  ## Objective
  @objective(m, Max, w1 * sum(t[i-1,j-1]*(1-x[i,j]) for i in 2:n+1, j in 2:h+1) + w2*g*l*sum(4*x[i,j] - d[i,j] for i in 2:n+1, j in 2:h+1))

  #resolution
  optimize!(m)

  # solution_summary(m, verbose=true)
  # z_vals = JuMP.getvalue.( m[:z] )
  # println(z_vals)

end

function P2(MyFileName::String)
  P, h, n, w1, w2, l, g, t = read_instance(MyFileName)
  w1 = 1
  w2 = 5

  # Create the model
  m = Model(CPLEX.Optimizer)

  ## Variables
  @variable(m, x[1:n+2,1:h+2] >= 0)
  @variable(m, y[1:n+2,1:h+2,1:n+2,1:h+2] >= 0)

  ## Constraints
  @constraint(m, [i in 1:n+2, j in 1:h+2], x[i,j] <= 1)
  @constraint(m, [i in 2:n+1, j in 2:h+1], y[i,j,i-1,j] <= x[i,j])
  @constraint(m, [i in 2:n+1, j in 2:h+1], y[i,j,i+1,j] <= x[i,j])
  @constraint(m, [i in 2:n+1, j in 2:h+1], y[i,j,i,j-1] <= x[i,j])
  @constraint(m, [i in 2:n+1, j in 2:h+1], y[i,j,i,j+1] <= x[i,j])

  @constraint(m, [i in 2:n+1, j in 2:h+1], y[i,j,i-1,j] <= 1 - x[i-1,j])
  @constraint(m, [i in 2:n+1, j in 2:h+1], y[i,j,i+1,j] <= 1 - x[i+1,j])
  @constraint(m, [i in 2:n+1, j in 2:h+1], y[i,j,i,j-1] <= 1 - x[i,j-1])
  @constraint(m, [i in 2:n+1, j in 2:h+1], y[i,j,i,j+1] <= 1 - x[i,j+1])

  @constraint(m, sum(x[i,j] for i in 2:n+1, j in 2:h+1) >= 60)

  ## Objective
  @objective(m, Max, w1 * sum(t[i-1,j-1]*(1-x[i,j]) for i in 2:n+1, j in 2:h+1) + w2*g*l*sum(y[i,j,i-1,j] +  y[i,j,i+1,j] + y[i,j,i,j-1] + y[i,j,i,j+1] for i in 2:n+1, j in 2:h+1))

  #resolution
  optimize!(m)

  println(JuMP.value.(x))
  println(time() - start)

end

P2("output30.txt")

max_stars_repo_name: boumpteryx/RODD

max_issues_repo_name: boumpteryx/RODD

max_forks_repo_name: boumpteryx/RODD


text:
using CSV
using LinearAlgebra: dot, I
using CairoMakie
using naumer_Dimensionality_2022

const Σ = [1.0  0.1  0.1;
           0.1  1.0  0.1;
           0.1  0.1  1.0]

const v = [1.0/sqrt(3), 1.0/sqrt(3), 1.0/sqrt(3)]
const σ² = 1

f(x) = abs2(dot(v, Σ * x)) / (dot(x, Σ * x) + σ² * dot(x, x))

# Helper function to compute extra coordinate
function getZ(x,y)
    if abs2(x) + abs2(y) > 1 - 10*eps()
        return NaN
    end
    return sqrt(1 - abs2(x) - abs2(y))
end

function rewardPositive(x,y)
    return f([x,y,getZ(x,y)])
end

function rewardNegative(x,y)
    return f([x,y,-getZ(x,y)])
end

state = zeros(3,100)
state[3,1] = 1

for i in 2:100
    state[:,i] .= actiongradientstep_1DApprox(state[:,i-1], v, Σ, σ², 0.1)
end

rewards = zeros(100)
for i in 1:100
    rewards[i] = f(state[:,i])
end

# Sample Circle
x = -1.1:0.01:1.1
y = -1.1:0.01:1.1

noto_sans = "./resources/NotoSans-Regular.ttf"
noto_sans_bold = "./resources/NotoSans-Bold.ttf"

tickfontsize    = 26
labelfontsize   = 28
basewidth = 2

fig = Figure(font=noto_sans, resolution=(1000,500), figure_padding=40)

ax1 = Axis( fig[1,1],
            xticklabelsize=tickfontsize,
            yticklabelsize=tickfontsize,
            yticklabelpad=2,
            xlabel="x", ylabel = "y",
            xlabelsize=labelfontsize,
            ylabelsize=labelfontsize,
            titlesize=labelfontsize,
            ratio=AxisAspect(1))

hm = heatmap!(ax1,x,y,rewardPositive)
lines!(ax1, state[1,:], state[2,:], color=:black, linewidth=3)

ax2 = Axis( fig[1,3],
            xticklabelsize=tickfontsize,
            yticklabelsize=tickfontsize,
            yticklabelpad=2,
            xlabel="Iteration", ylabel = "Objective",
            xlabelsize=labelfontsize,
            ylabelsize=labelfontsize,
            titlesize=labelfontsize,
            ratio=AxisAspect(1),
            xminorticksvisible = true,
            xminorgridvisible  = true,
            xminorticks = IntervalsBetween(10),
            yminorticksvisible = true,
            yminorgridvisible  = true,
            yminorticks = IntervalsBetween(5))

lines!(ax2,1:100, rewards, color=:black, width=2)
xlims!(ax2,(0,100))

Colorbar(fig[1, 2], hm, ticklabelsize=tickfontsize)

colgap!(fig.layout,2,80)

Label(fig[1,1,TopLeft()], "A", font=noto_sans_bold, textsize = 36, halign=:left, valign=:bottom, padding=(25,0,10,0))
Label(fig[1,3,TopLeft()], "B", font=noto_sans_bold, textsize = 36, halign=:left, valign=:bottom, padding=(25,0,10,0))

save("out/OptDescent.pdf",fig)


text:
name(p :: Penalty) = p.name;

is_used(p :: Penalty) = p.isUsed;
use(p :: Penalty) =  set_use(p, true);
no_use(p :: Penalty) =  set_use(p, false);
set_use(p :: Penalty, doUse :: Bool) =  (p.isUsed = doUse);

set_scalar_value(p :: Penalty, v) =  p.scalarValue = v;
scalar_value(p :: Penalty) = p.scalarValue;

function show_string(p :: Penalty)
    vStr = format_number(scalar_value(p));
    return "Penalty $(name(p)):  $vStr";
end

Base.show(io :: IO, p :: Penalty) = println(io,  show_string(p));

"""
	$(SIGNATURES)

Compute and return scalar penalty.
Multiple inputs to `scalarFct` must be packaged into a tuple. This will then be splatted into the `scalarFct`.
"""
function compute_penalty(p :: Penalty, x)
    if isa(x, Tuple)
        sv = p.scalarFct(x...);
    else
        sv = p.scalarFct(x);
    end
    set_scalar_value(p, sv);
    return sv
end

# ---------


text:
init(𝒜::ASB07, 𝑆::AbstractSystem, 𝑂::Options) = init!(𝒜, 𝑆, copy(𝑂))

function init!(::ASB07, 𝑆::AbstractSystem, 𝑂::Options)
    𝑂[:n] = statedim(𝑆)

    return validate_solver_options_and_add_default_values!(𝑂)
end