text:
@testset "7.3.5 u (a+b arctanh(c+d x))^p" begin
    (a, b, c, d, e, f, m, x, ) = @variables a b c d e f m x

    #= ::Package:: =#

    #= ::Title:: =#
    #=Integrands*of*the*form*u*(a+b*atanh(c+d*x))^p=#

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

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

    @test_int [x^3*atanh(a + b*x)^2, x, 19, -((a*x)/b^3) + (a + b*x)^2/(12*b^4) + (a*atanh(a + b*x))/b^4 + ((1 + 6*a^2)*(a + b*x)*atanh(a + b*x))/(2*b^4) - (a*(a + b*x)^2*atanh(a + b*x))/b^4 + ((a + b*x)^3*atanh(a + b*x))/(6*b^4) - (a*(1 + a^2)*atanh(a + b*x)^2)/b^4 - ((1 + 6*a^2 + a^4)*atanh(a + b*x)^2)/(4*b^4) + (1/4)*x^4*atanh(a + b*x)^2 + (2*a*(1 + a^2)*atanh(a + b*x)*log(2/(1 - a - b*x)))/b^4 + log(1 - (a + b*x)^2)/(12*b^4) + ((1 + 6*a^2)*log(1 - (a + b*x)^2))/(4*b^4) + (a*(1 + a^2)*PolyLog(2, -((1 + a + b*x)/(1 - a - b*x))))/b^4]
    @test_int [x^2*atanh(a + b*x)^2, x, 15, x/(3*b^2) - atanh(a + b*x)/(3*b^3) - (2*a*(a + b*x)*atanh(a + b*x))/b^3 + ((a + b*x)^2*atanh(a + b*x))/(3*b^3) + (a*(3 + a^2)*atanh(a + b*x)^2)/(3*b^3) + ((1 + 3*a^2)*atanh(a + b*x)^2)/(3*b^3) + (1/3)*x^3*atanh(a + b*x)^2 - (2*(1 + 3*a^2)*atanh(a + b*x)*log(2/(1 - a - b*x)))/(3*b^3) - (a*log(1 - (a + b*x)^2))/b^3 - ((1 + 3*a^2)*PolyLog(2, -((1 + a + b*x)/(1 - a - b*x))))/(3*b^3)]
    @test_int [x^1*atanh(a + b*x)^2, x, 12, ((a + b*x)*atanh(a + b*x))/b^2 - (a*atanh(a + b*x)^2)/b^2 - ((1 + a^2)*atanh(a + b*x)^2)/(2*b^2) + (1/2)*x^2*atanh(a + b*x)^2 + (2*a*atanh(a + b*x)*log(2/(1 - a - b*x)))/b^2 + log(1 - (a + b*x)^2)/(2*b^2) + (a*PolyLog(2, -((1 + a + b*x)/(1 - a - b*x))))/b^2]
    @test_int [x^0*atanh(a + b*x)^2, x, 6, atanh(a + b*x)^2/b + ((a + b*x)*atanh(a + b*x)^2)/b - (2*atanh(a + b*x)*log(2/(1 - a - b*x)))/b - PolyLog(2, -((1 + a + b*x)/(1 - a - b*x)))/b]
    @test_int [atanh(a + b*x)^2/x^1, x, 2, (-atanh(a + b*x)^2)*log(2/(1 + a + b*x)) + atanh(a + b*x)^2*log((2*b*x)/((1 - a)*(1 + a + b*x))) + atanh(a + b*x)*PolyLog(2, 1 - 2/(1 + a + b*x)) - atanh(a + b*x)*PolyLog(2, 1 - (2*b*x)/((1 - a)*(1 + a + b*x))) + (1/2)*PolyLog(3, 1 - 2/(1 + a + b*x)) - (1/2)*PolyLog(3, 1 - (2*b*x)/((1 - a)*(1 + a + b*x)))]
    @test_int [atanh(a + b*x)^2/x^2, x, 17, -(atanh(a + b*x)^2/x) + (b*atanh(a + b*x)*log(2/(1 - a - b*x)))/(1 - a) + (b*atanh(a + b*x)*log(2/(1 + a + b*x)))/(1 + a) - (2*b*atanh(a + b*x)*log(2/(1 + a + b*x)))/(1 - a^2) + (2*b*atanh(a + b*x)*log((2*b*x)/((1 - a)*(1 + a + b*x))))/(1 - a^2) + (b*PolyLog(2, -((1 + a + b*x)/(1 - a - b*x))))/(2*(1 - a)) - (b*PolyLog(2, 1 - 2/(1 + a + b*x)))/(2*(1 + a)) + (b*PolyLog(2, 1 - 2/(1 + a + b*x)))/(1 - a^2) - (b*PolyLog(2, 1 - (2*b*x)/((1 - a)*(1 + a + b*x))))/(1 - a^2)]
    @test_int [atanh(a + b*x)^2/x^3, x, 21, -((b*atanh(a + b*x))/((1 - a^2)*x)) - atanh(a + b*x)^2/(2*x^2) + (b^2*log(x))/(1 - a^2)^2 + (b^2*atanh(a + b*x)*log(2/(1 - a - b*x)))/(2*(1 - a)^2) - (b^2*log(1 - a - b*x))/(2*(1 - a)^2*(1 + a)) - (b^2*atanh(a + b*x)*log(2/(1 + a + b*x)))/(2*(1 + a)^2) - (2*a*b^2*atanh(a + b*x)*log(2/(1 + a + b*x)))/(1 - a^2)^2 + (2*a*b^2*atanh(a + b*x)*log((2*b*x)/((1 - a)*(1 + a + b*x))))/(1 - a^2)^2 - (b^2*log(1 + a + b*x))/(2*(1 - a)*(1 + a)^2) + (b^2*PolyLog(2, -((1 + a + b*x)/(1 - a - b*x))))/(4*(1 - a)^2) + (b^2*PolyLog(2, 1 - 2/(1 + a + b*x)))/(4*(1 + a)^2) + (a*b^2*PolyLog(2, 1 - 2/(1 + a + b*x)))/(1 - a^2)^2 - (a*b^2*PolyLog(2, 1 - (2*b*x)/((1 - a)*(1 + a + b*x))))/(1 - a^2)^2]

    @test_int [atanh(1 + b*x)^2/x, x, 4, (-atanh(1 + b*x)^2)*log(-(2/(b*x))) - atanh(1 + b*x)*PolyLog(2, 1 + 2/(b*x)) + (1/2)*PolyLog(3, 1 + 2/(b*x))]

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*(e+f*x)^m*(a+b*atanh(c+d*x))^p*when*d*e-c*f=0=#

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

    @test_int [(c*e + d*e*x)^3*(a + b*atanh(c + d*x))^2, x, 13, (a*b*e^3*x)/2 + (b^2*e^3*(c + d*x)^2)/(12*d) + (b^2*e^3*(c + d*x)*atanh(c + d*x))/(2*d) + (b*e^3*(c + d*x)^3*(a + b*atanh(c + d*x)))/(6*d) - (e^3*(a + b*atanh(c + d*x))^2)/(4*d) + (e^3*(c + d*x)^4*(a + b*atanh(c + d*x))^2)/(4*d) + (b^2*e^3*log(1 - (c + d*x)^2))/(3*d)]
    @test_int [(c*e + d*e*x)^2*(a + b*atanh(c + d*x))^2, x, 11, (1/3)*b^2*e^2*x - (b^2*e^2*atanh(c + d*x))/(3*d) + (b*e^2*(c + d*x)^2*(a + b*atanh(c + d*x)))/(3*d) + (e^2*(a + b*atanh(c + d*x))^2)/(3*d) + (e^2*(c + d*x)^3*(a + b*atanh(c + d*x))^2)/(3*d) - (2*b*e^2*(a + b*atanh(c + d*x))*log(2/(1 - c - d*x)))/(3*d) - (b^2*e^2*PolyLog(2, -((1 + c + d*x)/(1 - c - d*x))))/(3*d)]
    @test_int [(c*e + d*e*x)^1*(a + b*atanh(c + d*x))^2, x, 8, a*b*e*x + (b^2*e*(c + d*x)*atanh(c + d*x))/d - (e*(a + b*atanh(c + d*x))^2)/(2*d) + (e*(c + d*x)^2*(a + b*atanh(c + d*x))^2)/(2*d) + (b^2*e*log(1 - (c + d*x)^2))/(2*d)]
    @test_int [(a + b*atanh(c + d*x))^2/(c*e + d*e*x)^1, x, 8, (2*(a + b*atanh(c + d*x))^2*atanh(1 - 2/(1 - c - d*x)))/(d*e) - (b*(a + b*atanh(c + d*x))*PolyLog(2, 1 - 2/(1 - c - d*x)))/(d*e) + (b*(a + b*atanh(c + d*x))*PolyLog(2, -1 + 2/(1 - c - d*x)))/(d*e) + (b^2*PolyLog(3, 1 - 2/(1 - c - d*x)))/(2*d*e) - (b^2*PolyLog(3, -1 + 2/(1 - c - d*x)))/(2*d*e)]
    @test_int [(a + b*atanh(c + d*x))^2/(c*e + d*e*x)^2, x, 6, (a + b*atanh(c + d*x))^2/(d*e^2) - (a + b*atanh(c + d*x))^2/(d*e^2*(c + d*x)) + (2*b*(a + b*atanh(c + d*x))*log(2 - 2/(1 + c + d*x)))/(d*e^2) - (b^2*PolyLog(2, -1 + 2/(1 + c + d*x)))/(d*e^2)]
    @test_int [(a + b*atanh(c + d*x))^2/(c*e + d*e*x)^3, x, 10, -((b*(a + b*atanh(c + d*x)))/(d*e^3*(c + d*x))) + (a + b*atanh(c + d*x))^2/(2*d*e^3) - (a + b*atanh(c + d*x))^2/(2*d*e^3*(c + d*x)^2) + (b^2*log(c + d*x))/(d*e^3) - (b^2*log(1 - (c + d*x)^2))/(2*d*e^3)]
    @test_int [(a + b*atanh(c + d*x))^2/(c*e + d*e*x)^4, x, 10, -(b^2/(3*d*e^4*(c + d*x))) + (b^2*atanh(c + d*x))/(3*d*e^4) - (b*(a + b*atanh(c + d*x)))/(3*d*e^4*(c + d*x)^2) + (a + b*atanh(c + d*x))^2/(3*d*e^4) - (a + b*atanh(c + d*x))^2/(3*d*e^4*(c + d*x)^3) + (2*b*(a + b*atanh(c + d*x))*log(2 - 2/(1 + c + d*x)))/(3*d*e^4) - (b^2*PolyLog(2, -1 + 2/(1 + c + d*x)))/(3*d*e^4)]
    @test_int [(a + b*atanh(c + d*x))^2/(c*e + d*e*x)^5, x, 15, -(b^2/(12*d*e^5*(c + d*x)^2)) - (b*(a + b*atanh(c + d*x)))/(6*d*e^5*(c + d*x)^3) - (b*(a + b*atanh(c + d*x)))/(2*d*e^5*(c + d*x)) + (a + b*atanh(c + d*x))^2/(4*d*e^5) - (a + b*atanh(c + d*x))^2/(4*d*e^5*(c + d*x)^4) + (2*b^2*log(c + d*x))/(3*d*e^5) - (b^2*log(1 - (c + d*x)^2))/(3*d*e^5)]

    @test_int [(c*e + d*e*x)^2*(a + b*atanh(c + d*x))^3, x, 14, a*b^2*e^2*x + (b^3*e^2*(c + d*x)*atanh(c + d*x))/d - (b*e^2*(a + b*atanh(c + d*x))^2)/(2*d) + (b*e^2*(c + d*x)^2*(a + b*atanh(c + d*x))^2)/(2*d) + (e^2*(a + b*atanh(c + d*x))^3)/(3*d) + (e^2*(c + d*x)^3*(a + b*atanh(c + d*x))^3)/(3*d) - (b*e^2*(a + b*atanh(c + d*x))^2*log(2/(1 - c - d*x)))/d + (b^3*e^2*log(1 - (c + d*x)^2))/(2*d) - (b^2*e^2*(a + b*atanh(c + d*x))*PolyLog(2, 1 - 2/(1 - c - d*x)))/d + (b^3*e^2*PolyLog(3, 1 - 2/(1 - c - d*x)))/(2*d)]
    @test_int [(c*e + d*e*x)^1*(a + b*atanh(c + d*x))^3, x, 10, (3*b*e*(a + b*atanh(c + d*x))^2)/(2*d) + (3*b*e*(c + d*x)*(a + b*atanh(c + d*x))^2)/(2*d) - (e*(a + b*atanh(c + d*x))^3)/(2*d) + (e*(c + d*x)^2*(a + b*atanh(c + d*x))^3)/(2*d) - (3*b^2*e*(a + b*atanh(c + d*x))*log(2/(1 - c - d*x)))/d - (3*b^3*e*PolyLog(2, -((1 + c + d*x)/(1 - c - d*x))))/(2*d)]
    @test_int [(a + b*atanh(c + d*x))^3/(c*e + d*e*x)^1, x, 10, (2*(a + b*atanh(c + d*x))^3*atanh(1 - 2/(1 - c - d*x)))/(d*e) - (3*b*(a + b*atanh(c + d*x))^2*PolyLog(2, 1 - 2/(1 - c - d*x)))/(2*d*e) + (3*b*(a + b*atanh(c + d*x))^2*PolyLog(2, -1 + 2/(1 - c - d*x)))/(2*d*e) + (3*b^2*(a + b*atanh(c + d*x))*PolyLog(3, 1 - 2/(1 - c - d*x)))/(2*d*e) - (3*b^2*(a + b*atanh(c + d*x))*PolyLog(3, -1 + 2/(1 - c - d*x)))/(2*d*e) - (3*b^3*PolyLog(4, 1 - 2/(1 - c - d*x)))/(4*d*e) + (3*b^3*PolyLog(4, -1 + 2/(1 - c - d*x)))/(4*d*e)]
    @test_int [(a + b*atanh(c + d*x))^3/(c*e + d*e*x)^2, x, 7, (a + b*atanh(c + d*x))^3/(d*e^2) - (a + b*atanh(c + d*x))^3/(d*e^2*(c + d*x)) + (3*b*(a + b*atanh(c + d*x))^2*log(2 - 2/(1 + c + d*x)))/(d*e^2) - (3*b^2*(a + b*atanh(c + d*x))*PolyLog(2, -1 + 2/(1 + c + d*x)))/(d*e^2) - (3*b^3*PolyLog(3, -1 + 2/(1 + c + d*x)))/(2*d*e^2)]
    @test_int [(a + b*atanh(c + d*x))^3/(c*e + d*e*x)^3, x, 9, (3*b*(a + b*atanh(c + d*x))^2)/(2*d*e^3) - (3*b*(a + b*atanh(c + d*x))^2)/(2*d*e^3*(c + d*x)) + (a + b*atanh(c + d*x))^3/(2*d*e^3) - (a + b*atanh(c + d*x))^3/(2*d*e^3*(c + d*x)^2) + (3*b^2*(a + b*atanh(c + d*x))*log(2 - 2/(1 + c + d*x)))/(d*e^3) - (3*b^3*PolyLog(2, -1 + 2/(1 + c + d*x)))/(2*d*e^3)]
    @test_int [(a + b*atanh(c + d*x))^3/(c*e + d*e*x)^4, x, 16, -((b^2*(a + b*atanh(c + d*x)))/(d*e^4*(c + d*x))) + (b*(a + b*atanh(c + d*x))^2)/(2*d*e^4) - (b*(a + b*atanh(c + d*x))^2)/(2*d*e^4*(c + d*x)^2) + (a + b*atanh(c + d*x))^3/(3*d*e^4) - (a + b*atanh(c + d*x))^3/(3*d*e^4*(c + d*x)^3) + (b^3*log(c + d*x))/(d*e^4) - (b^3*log(1 - (c + d*x)^2))/(2*d*e^4) + (b*(a + b*atanh(c + d*x))^2*log(2 - 2/(1 + c + d*x)))/(d*e^4) - (b^2*(a + b*atanh(c + d*x))*PolyLog(2, -1 + 2/(1 + c + d*x)))/(d*e^4) - (b^3*PolyLog(3, -1 + 2/(1 + c + d*x)))/(2*d*e^4)]

    @test_int [atanh(1 + x)/(2 + 2*x), x, 3, (-(1/4))*PolyLog(2, -1 - x) + (1/4)*PolyLog(2, 1 + x)]

    @test_int [atanh(a + b*x)/((a*d)/b + d*x), x, 3, -(PolyLog(2, -a - b*x)/(2*d)) + PolyLog(2, a + b*x)/(2*d)]

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

    @test_int [(e + f*x)^3*(a + b*atanh(c + d*x)), x, 7, (b*f*(6*d^2*e^2 - 12*c*d*e*f + (1 + 6*c^2)*f^2)*x)/(4*d^3) + (b*f^2*(d*e - c*f)*(c + d*x)^2)/(2*d^4) + (b*f^3*(c + d*x)^3)/(12*d^4) + ((e + f*x)^4*(a + b*atanh(c + d*x)))/(4*f) + (b*(d*e + f - c*f)^4*log(1 - c - d*x))/(8*d^4*f) - (b*(d*e - f - c*f)^4*log(1 + c + d*x))/(8*d^4*f)]
    @test_int [(e + f*x)^2*(a + b*atanh(c + d*x)), x, 7, (b*f*(d*e - c*f)*x)/d^2 + (b*f^2*(c + d*x)^2)/(6*d^3) + ((e + f*x)^3*(a + b*atanh(c + d*x)))/(3*f) + (b*(d*e + f - c*f)^3*log(1 - c - d*x))/(6*d^3*f) - (b*(d*e - (1 + c)*f)^3*log(1 + c + d*x))/(6*d^3*f)]
    @test_int [(e + f*x)^1*(a + b*atanh(c + d*x)), x, 7, (b*f*x)/(2*d) + ((e + f*x)^2*(a + b*atanh(c + d*x)))/(2*f) + (b*(d*e + f - c*f)^2*log(1 - c - d*x))/(4*d^2*f) - (b*(d*e - (1 + c)*f)^2*log(1 + c + d*x))/(4*d^2*f)]
    @test_int [(e + f*x)^0*(a + b*atanh(c + d*x)), x, 4, a*x + (b*(c + d*x)*atanh(c + d*x))/d + (b*log(1 - (c + d*x)^2))/(2*d)]
    @test_int [(a + b*atanh(c + d*x))/(e + f*x)^1, x, 5, -(((a + b*atanh(c + d*x))*log(2/(1 + c + d*x)))/f) + ((a + b*atanh(c + d*x))*log((2*d*(e + f*x))/((d*e + f - c*f)*(1 + c + d*x))))/f + (b*PolyLog(2, 1 - 2/(1 + c + d*x)))/(2*f) - (b*PolyLog(2, 1 - (2*d*(e + f*x))/((d*e + f - c*f)*(1 + c + d*x))))/(2*f)]
    @test_int [(a + b*atanh(c + d*x))/(e + f*x)^2, x, 7, If(13>=8, -((a + b*atanh(c + d*x))/(f*(e + f*x))) - (b*d*log(1 - c - d*x))/(2*f*(d*e + f - c*f)) + (b*d*log(1 + c + d*x))/(2*f*(d*e - f - c*f)) - (b*d*log(e + f*x))/((d*e + f - c*f)*(d*e - (1 + c)*f)), -((a + b*atanh(c + d*x))/(f*(e + f*x))) - (b*d*log(1 - c - d*x))/(2*f*(d*e + f - c*f)) + (b*d*log(1 + c + d*x))/(2*f*(d*e - f - c*f)) - (b*d*log(e + f*x))/((d*e - f - c*f)*(d*e + f - c*f)))]
    @test_int [(a + b*atanh(c + d*x))/(e + f*x)^3, x, 5, If(13>=8, (b*d)/(2*(d*e + f - c*f)*(d*e - (1 + c)*f)*(e + f*x)) - (a + b*atanh(c + d*x))/(2*f*(e + f*x)^2) - (b*d^2*log(1 - c - d*x))/(4*f*(d*e + f - c*f)^2) + (b*d^2*log(1 + c + d*x))/(4*f*(d*e - f - c*f)^2) - (b*d^2*(d*e - c*f)*log(e + f*x))/((d*e + f - c*f)^2*(d*e - (1 + c)*f)^2), (b*d)/(2*(d*e - f - c*f)*(d*e + f - c*f)*(e + f*x)) - (a + b*atanh(c + d*x))/(2*f*(e + f*x)^2) - (b*d^2*log(1 - c - d*x))/(4*f*(d*e + f - c*f)^2) + (b*d^2*log(1 + c + d*x))/(4*f*(d*e - f - c*f)^2) - (b*d^2*(d*e - c*f)*log(e + f*x))/((d*e + f - c*f)^2*(d*e - (1 + c)*f)^2))]

    @test_int [(e + f*x)^3*(a + b*atanh(c + d*x))^2, x, 20, (b^2*f^2*(d*e - c*f)*x)/d^3 + (a*b*f*(6*d^2*e^2 - 12*c*d*e*f + (1 + 6*c^2)*f^2)*x)/(2*d^3) + (b^2*f^3*(c + d*x)^2)/(12*d^4) - (b^2*f^2*(d*e - c*f)*atanh(c + d*x))/d^4 + (b^2*f*(6*d^2*e^2 - 12*c*d*e*f + (1 + 6*c^2)*f^2)*(c + d*x)*atanh(c + d*x))/(2*d^4) + (b*f^2*(d*e - c*f)*(c + d*x)^2*(a + b*atanh(c + d*x)))/d^4 + (b*f^3*(c + d*x)^3*(a + b*atanh(c + d*x)))/(6*d^4) + ((d*e - c*f)*(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2)*(a + b*atanh(c + d*x))^2)/d^4 - ((d^4*e^4 - 4*c*d^3*e^3*f + 6*(1 + c^2)*d^2*e^2*f^2 - 4*c*(3 + c^2)*d*e*f^3 + (1 + 6*c^2 + c^4)*f^4)*(a + b*atanh(c + d*x))^2)/(4*d^4*f) + ((e + f*x)^4*(a + b*atanh(c + d*x))^2)/(4*f) - (2*b*(d*e - c*f)*(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2)*(a + b*atanh(c + d*x))*log(2/(1 - c - d*x)))/d^4 + (b^2*f^3*log(1 - (c + d*x)^2))/(12*d^4) + (b^2*f*(6*d^2*e^2 - 12*c*d*e*f + (1 + 6*c^2)*f^2)*log(1 - (c + d*x)^2))/(4*d^4) - (b^2*(d*e - c*f)*(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2)*PolyLog(2, -((1 + c + d*x)/(1 - c - d*x))))/d^4]
    @test_int [(e + f*x)^2*(a + b*atanh(c + d*x))^2, x, 16, (b^2*f^2*x)/(3*d^2) + (2*a*b*f*(d*e - c*f)*x)/d^2 - (b^2*f^2*atanh(c + d*x))/(3*d^3) + (2*b^2*f*(d*e - c*f)*(c + d*x)*atanh(c + d*x))/d^3 + (b*f^2*(c + d*x)^2*(a + b*atanh(c + d*x)))/(3*d^3) - ((d*e - c*f)*(d^2*e^2 - 2*c*d*e*f + (3 + c^2)*f^2)*(a + b*atanh(c + d*x))^2)/(3*d^3*f) + ((3*d^2*e^2 - 6*c*d*e*f + (1 + 3*c^2)*f^2)*(a + b*atanh(c + d*x))^2)/(3*d^3) + ((e + f*x)^3*(a + b*atanh(c + d*x))^2)/(3*f) - (2*b*(3*d^2*e^2 - 6*c*d*e*f + (1 + 3*c^2)*f^2)*(a + b*atanh(c + d*x))*log(2/(1 - c - d*x)))/(3*d^3) + (b^2*f*(d*e - c*f)*log(1 - (c + d*x)^2))/d^3 - (b^2*(3*d^2*e^2 - 6*c*d*e*f + (1 + 3*c^2)*f^2)*PolyLog(2, -((1 + c + d*x)/(1 - c - d*x))))/(3*d^3)]
    @test_int [(e + f*x)^1*(a + b*atanh(c + d*x))^2, x, 13, (a*b*f*x)/d + (b^2*f*(c + d*x)*atanh(c + d*x))/d^2 + ((d*e - c*f)*(a + b*atanh(c + d*x))^2)/d^2 - ((d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2)*(a + b*atanh(c + d*x))^2)/(2*d^2*f) + ((e + f*x)^2*(a + b*atanh(c + d*x))^2)/(2*f) - (2*b*(d*e - c*f)*(a + b*atanh(c + d*x))*log(2/(1 - c - d*x)))/d^2 + (b^2*f*log(1 - (c + d*x)^2))/(2*d^2) - (b^2*(d*e - c*f)*PolyLog(2, -((1 + c + d*x)/(1 - c - d*x))))/d^2]
    @test_int [(e + f*x)^0*(a + b*atanh(c + d*x))^2, x, 6, (a + b*atanh(c + d*x))^2/d + ((c + d*x)*(a + b*atanh(c + d*x))^2)/d - (2*b*(a + b*atanh(c + d*x))*log(2/(1 - c - d*x)))/d - (b^2*PolyLog(2, -((1 + c + d*x)/(1 - c - d*x))))/d]
    @test_int [(a + b*atanh(c + d*x))^2/(e + f*x)^1, x, 2, -(((a + b*atanh(c + d*x))^2*log(2/(1 + c + d*x)))/f) + ((a + b*atanh(c + d*x))^2*log((2*d*(e + f*x))/((d*e + f - c*f)*(1 + c + d*x))))/f + (b*(a + b*atanh(c + d*x))*PolyLog(2, 1 - 2/(1 + c + d*x)))/f - (b*(a + b*atanh(c + d*x))*PolyLog(2, 1 - (2*d*(e + f*x))/((d*e + f - c*f)*(1 + c + d*x))))/f + (b^2*PolyLog(3, 1 - 2/(1 + c + d*x)))/(2*f) - (b^2*PolyLog(3, 1 - (2*d*(e + f*x))/((d*e + f - c*f)*(1 + c + d*x))))/(2*f)]
    @test_int [(a + b*atanh(c + d*x))^2/(e + f*x)^2, x, 24, If(13>=8, -((a + b*atanh(c + d*x))^2/(f*(e + f*x))) + (b^2*d*atanh(c + d*x)*log(2/(1 - c - d*x)))/(f*(d*e + f - c*f)) - (a*b*d*log(1 - c - d*x))/(f*(d*e + f - c*f)) - (b^2*d*atanh(c + d*x)*log(2/(1 + c + d*x)))/(f*(d*e - f - c*f)) + (2*b^2*d*atanh(c + d*x)*log(2/(1 + c + d*x)))/((d*e + f - c*f)*(d*e - (1 + c)*f)) + (a*b*d*log(1 + c + d*x))/(f*(d*e - f - c*f)) + (2*a*b*d*log(e + f*x))/(f^2 - (d*e - c*f)^2) - (2*b^2*d*atanh(c + d*x)*log((2*d*(e + f*x))/((d*e + f - c*f)*(1 + c + d*x))))/((d*e + f - c*f)*(d*e - (1 + c)*f)) + (b^2*d*PolyLog(2, -((1 + c + d*x)/(1 - c - d*x))))/(2*f*(d*e + f - c*f)) + (b^2*d*PolyLog(2, 1 - 2/(1 + c + d*x)))/(2*f*(d*e - f - c*f)) - (b^2*d*PolyLog(2, 1 - 2/(1 + c + d*x)))/((d*e + f - c*f)*(d*e - (1 + c)*f)) + (b^2*d*PolyLog(2, 1 - (2*d*(e + f*x))/((d*e + f - c*f)*(1 + c + d*x))))/((d*e + f - c*f)*(d*e - (1 + c)*f)), -((a + b*atanh(c + d*x))^2/(f*(e + f*x))) + (b^2*d*atanh(c + d*x)*log(2/(1 - c - d*x)))/(f*(d*e + f - c*f)) - (a*b*d*log(1 - c - d*x))/(f*(d*e + f - c*f)) - (b^2*d*atanh(c + d*x)*log(2/(1 + c + d*x)))/(f*(d*e - f - c*f)) + (2*b^2*d*atanh(c + d*x)*log(2/(1 + c + d*x)))/((d*e - f - c*f)*(d*e + f - c*f)) + (a*b*d*log(1 + c + d*x))/(f*(d*e - f - c*f)) + (2*a*b*d*log(e + f*x))/(f^2 - (d*e - c*f)^2) - (2*b^2*d*atanh(c + d*x)*log((2*d*(e + f*x))/((d*e + f - c*f)*(1 + c + d*x))))/((d*e - f - c*f)*(d*e + f - c*f)) + (b^2*d*PolyLog(2, -((1 + c + d*x)/(1 - c - d*x))))/(2*f*(d*e + f - c*f)) + (b^2*d*PolyLog(2, 1 - 2/(1 + c + d*x)))/(2*f*(d*e - f - c*f)) - (b^2*d*PolyLog(2, 1 - 2/(1 + c + d*x)))/((d*e - f - c*f)*(d*e + f - c*f)) + (b^2*d*PolyLog(2, 1 - (2*d*(e + f*x))/((d*e + f - c*f)*(1 + c + d*x))))/((d*e - f - c*f)*(d*e + f - c*f)))]
    @test_int [(a + b*atanh(c + d*x))^2/(e + f*x)^3, x, 26, If(13>=8, -((a*b*d)/((f^2 - (d*e - c*f)^2)*(e + f*x))) + (b^2*d*atanh(c + d*x))/((d*e + f - c*f)*(d*e - (1 + c)*f)*(e + f*x)) - (a + b*atanh(c + d*x))^2/(2*f*(e + f*x)^2) + (b^2*d^2*atanh(c + d*x)*log(2/(1 - c - d*x)))/(2*f*(d*e + f - c*f)^2) - (a*b*d^2*log(1 - c - d*x))/(2*f*(d*e + f - c*f)^2) + (b^2*d^2*log(1 - c - d*x))/(2*(d*e + f - c*f)^2*(d*e - (1 + c)*f)) - (b^2*d^2*atanh(c + d*x)*log(2/(1 + c + d*x)))/(2*f*(d*e - f - c*f)^2) + (2*b^2*d^2*(d*e - c*f)*atanh(c + d*x)*log(2/(1 + c + d*x)))/((d*e + f - c*f)^2*(d*e - (1 + c)*f)^2) + (a*b*d^2*log(1 + c + d*x))/(2*f*(d*e - f - c*f)^2) - (b^2*d^2*log(1 + c + d*x))/(2*(d*e + f - c*f)*(d*e - (1 + c)*f)^2) + (b^2*d^2*f*log(e + f*x))/((d*e + f - c*f)^2*(d*e - (1 + c)*f)^2) - (2*a*b*d^2*(d*e - c*f)*log(e + f*x))/((d*e + f - c*f)^2*(d*e - (1 + c)*f)^2) - (2*b^2*d^2*(d*e - c*f)*atanh(c + d*x)*log((2*d*(e + f*x))/((d*e + f - c*f)*(1 + c + d*x))))/((d*e + f - c*f)^2*(d*e - (1 + c)*f)^2) + (b^2*d^2*PolyLog(2, -((1 + c + d*x)/(1 - c - d*x))))/(4*f*(d*e + f - c*f)^2) + (b^2*d^2*PolyLog(2, 1 - 2/(1 + c + d*x)))/(4*f*(d*e - f - c*f)^2) - (b^2*d^2*(d*e - c*f)*PolyLog(2, 1 - 2/(1 + c + d*x)))/((d*e + f - c*f)^2*(d*e - (1 + c)*f)^2) + (b^2*d^2*(d*e - c*f)*PolyLog(2, 1 - (2*d*(e + f*x))/((d*e + f - c*f)*(1 + c + d*x))))/((d*e + f - c*f)^2*(d*e - (1 + c)*f)^2), -((a*b*d)/((f^2 - (d*e - c*f)^2)*(e + f*x))) + (b^2*d*atanh(c + d*x))/((d*e - f - c*f)*(d*e + f - c*f)*(e + f*x)) - (a + b*atanh(c + d*x))^2/(2*f*(e + f*x)^2) + (b^2*d^2*atanh(c + d*x)*log(2/(1 - c - d*x)))/(2*f*(d*e + f - c*f)^2) - (a*b*d^2*log(1 - c - d*x))/(2*f*(d*e + f - c*f)^2) + (b^2*d^2*log(1 - c - d*x))/(2*(d*e + f - c*f)^2*(d*e - (1 + c)*f)) - (b^2*d^2*atanh(c + d*x)*log(2/(1 + c + d*x)))/(2*f*(d*e - f - c*f)^2) + (2*b^2*d^2*(d*e - c*f)*atanh(c + d*x)*log(2/(1 + c + d*x)))/((d*e + f - c*f)^2*(d*e - (1 + c)*f)^2) + (a*b*d^2*log(1 + c + d*x))/(2*f*(d*e - f - c*f)^2) - (b^2*d^2*log(1 + c + d*x))/(2*(d*e + f - c*f)*(d*e - (1 + c)*f)^2) + (b^2*d^2*f*log(e + f*x))/((d*e + f - c*f)^2*(d*e - (1 + c)*f)^2) - (2*a*b*d^2*(d*e - c*f)*log(e + f*x))/((d*e + f - c*f)^2*(d*e - (1 + c)*f)^2) - (2*b^2*d^2*(d*e - c*f)*atanh(c + d*x)*log((2*d*(e + f*x))/((d*e + f - c*f)*(1 + c + d*x))))/((d*e + f - c*f)^2*(d*e - (1 + c)*f)^2) + (b^2*d^2*PolyLog(2, -((1 + c + d*x)/(1 - c - d*x))))/(4*f*(d*e + f - c*f)^2) + (b^2*d^2*PolyLog(2, 1 - 2/(1 + c + d*x)))/(4*f*(d*e - f - c*f)^2) - (b^2*d^2*(d*e - c*f)*PolyLog(2, 1 - 2/(1 + c + d*x)))/((d*e + f - c*f)^2*(d*e - (1 + c)*f)^2) + (b^2*d^2*(d*e - c*f)*PolyLog(2, 1 - (2*d*(e + f*x))/((d*e + f - c*f)*(1 + c + d*x))))/((d*e + f - c*f)^2*(d*e - (1 + c)*f)^2))]

    @test_int [(e + f*x)^2*(a + b*atanh(c + d*x))^3, x, 21, (a*b^2*f^2*x)/d^2 + (b^3*f^2*(c + d*x)*atanh(c + d*x))/d^3 - (b*f^2*(a + b*atanh(c + d*x))^2)/(2*d^3) + (3*b*f*(d*e - c*f)*(a + b*atanh(c + d*x))^2)/d^3 + (3*b*f*(d*e - c*f)*(c + d*x)*(a + b*atanh(c + d*x))^2)/d^3 + (b*f^2*(c + d*x)^2*(a + b*atanh(c + d*x))^2)/(2*d^3) - ((d*e - c*f)*(d^2*e^2 - 2*c*d*e*f + (3 + c^2)*f^2)*(a + b*atanh(c + d*x))^3)/(3*d^3*f) + ((3*d^2*e^2 - 6*c*d*e*f + (1 + 3*c^2)*f^2)*(a + b*atanh(c + d*x))^3)/(3*d^3) + ((e + f*x)^3*(a + b*atanh(c + d*x))^3)/(3*f) - (6*b^2*f*(d*e - c*f)*(a + b*atanh(c + d*x))*log(2/(1 - c - d*x)))/d^3 - (b*(3*d^2*e^2 - 6*c*d*e*f + (1 + 3*c^2)*f^2)*(a + b*atanh(c + d*x))^2*log(2/(1 - c - d*x)))/d^3 + (b^3*f^2*log(1 - (c + d*x)^2))/(2*d^3) - (3*b^3*f*(d*e - c*f)*PolyLog(2, -((1 + c + d*x)/(1 - c - d*x))))/d^3 - (b^2*(3*d^2*e^2 - 6*c*d*e*f + (1 + 3*c^2)*f^2)*(a + b*atanh(c + d*x))*PolyLog(2, 1 - 2/(1 - c - d*x)))/d^3 + (b^3*(3*d^2*e^2 - 6*c*d*e*f + (1 + 3*c^2)*f^2)*PolyLog(3, 1 - 2/(1 - c - d*x)))/(2*d^3)]
    @test_int [(e + f*x)^1*(a + b*atanh(c + d*x))^3, x, 15, (3*b*f*(a + b*atanh(c + d*x))^2)/(2*d^2) + (3*b*f*(c + d*x)*(a + b*atanh(c + d*x))^2)/(2*d^2) + ((d*e - c*f)*(a + b*atanh(c + d*x))^3)/d^2 - ((d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2)*(a + b*atanh(c + d*x))^3)/(2*d^2*f) + ((e + f*x)^2*(a + b*atanh(c + d*x))^3)/(2*f) - (3*b^2*f*(a + b*atanh(c + d*x))*log(2/(1 - c - d*x)))/d^2 - (3*b*(d*e - c*f)*(a + b*atanh(c + d*x))^2*log(2/(1 - c - d*x)))/d^2 - (3*b^3*f*PolyLog(2, -((1 + c + d*x)/(1 - c - d*x))))/(2*d^2) - (3*b^2*(d*e - c*f)*(a + b*atanh(c + d*x))*PolyLog(2, 1 - 2/(1 - c - d*x)))/d^2 + (3*b^3*(d*e - c*f)*PolyLog(3, 1 - 2/(1 - c - d*x)))/(2*d^2)]
    @test_int [(e + f*x)^0*(a + b*atanh(c + d*x))^3, x, 6, (a + b*atanh(c + d*x))^3/d + ((c + d*x)*(a + b*atanh(c + d*x))^3)/d - (3*b*(a + b*atanh(c + d*x))^2*log(2/(1 - c - d*x)))/d - (3*b^2*(a + b*atanh(c + d*x))*PolyLog(2, 1 - 2/(1 - c - d*x)))/d + (3*b^3*PolyLog(3, 1 - 2/(1 - c - d*x)))/(2*d)]
    @test_int [(a + b*atanh(c + d*x))^3/(e + f*x)^1, x, 2, -(((a + b*atanh(c + d*x))^3*log(2/(1 + c + d*x)))/f) + ((a + b*atanh(c + d*x))^3*log((2*d*(e + f*x))/((d*e + f - c*f)*(1 + c + d*x))))/f + (3*b*(a + b*atanh(c + d*x))^2*PolyLog(2, 1 - 2/(1 + c + d*x)))/(2*f) - (3*b*(a + b*atanh(c + d*x))^2*PolyLog(2, 1 - (2*d*(e + f*x))/((d*e + f - c*f)*(1 + c + d*x))))/(2*f) + (3*b^2*(a + b*atanh(c + d*x))*PolyLog(3, 1 - 2/(1 + c + d*x)))/(2*f) - (3*b^2*(a + b*atanh(c + d*x))*PolyLog(3, 1 - (2*d*(e + f*x))/((d*e + f - c*f)*(1 + c + d*x))))/(2*f) + (3*b^3*PolyLog(4, 1 - 2/(1 + c + d*x)))/(4*f) - (3*b^3*PolyLog(4, 1 - (2*d*(e + f*x))/((d*e + f - c*f)*(1 + c + d*x))))/(4*f)]
    @test_int [(a + b*atanh(c + d*x))^3/(e + f*x)^2, x, 33, If(13>=8, -((a + b*atanh(c + d*x))^3/(f*(e + f*x))) + (3*a*b^2*d*atanh(c + d*x)*log(2/(1 - c - d*x)))/(f*(d*e + f - c*f)) + (3*b^3*d*atanh(c + d*x)^2*log(2/(1 - c - d*x)))/(2*f*(d*e + f - c*f)) - (3*a^2*b*d*log(1 - c - d*x))/(2*f*(d*e + f - c*f)) - (3*a*b^2*d*atanh(c + d*x)*log(2/(1 + c + d*x)))/(f*(d*e - f - c*f)) + (6*a*b^2*d*atanh(c + d*x)*log(2/(1 + c + d*x)))/((d*e + f - c*f)*(d*e - (1 + c)*f)) - (3*b^3*d*atanh(c + d*x)^2*log(2/(1 + c + d*x)))/(2*f*(d*e - f - c*f)) + (3*b^3*d*atanh(c + d*x)^2*log(2/(1 + c + d*x)))/((d*e + f - c*f)*(d*e - (1 + c)*f)) + (3*a^2*b*d*log(1 + c + d*x))/(2*f*(d*e - f - c*f)) + (3*a^2*b*d*log(e + f*x))/(f^2 - (d*e - c*f)^2) - (6*a*b^2*d*atanh(c + d*x)*log((2*d*(e + f*x))/((d*e + f - c*f)*(1 + c + d*x))))/((d*e + f - c*f)*(d*e - (1 + c)*f)) - (3*b^3*d*atanh(c + d*x)^2*log((2*d*(e + f*x))/((d*e + f - c*f)*(1 + c + d*x))))/((d*e + f - c*f)*(d*e - (1 + c)*f)) + (3*a*b^2*d*PolyLog(2, -((1 + c + d*x)/(1 - c - d*x))))/(2*f*(d*e + f - c*f)) + (3*b^3*d*atanh(c + d*x)*PolyLog(2, 1 - 2/(1 - c - d*x)))/(2*f*(d*e + f - c*f)) + (3*a*b^2*d*PolyLog(2, 1 - 2/(1 + c + d*x)))/(2*f*(d*e - f - c*f)) - (3*a*b^2*d*PolyLog(2, 1 - 2/(1 + c + d*x)))/((d*e + f - c*f)*(d*e - (1 + c)*f)) + (3*b^3*d*atanh(c + d*x)*PolyLog(2, 1 - 2/(1 + c + d*x)))/(2*f*(d*e - f - c*f)) - (3*b^3*d*atanh(c + d*x)*PolyLog(2, 1 - 2/(1 + c + d*x)))/((d*e + f - c*f)*(d*e - (1 + c)*f)) + (3*a*b^2*d*PolyLog(2, 1 - (2*d*(e + f*x))/((d*e + f - c*f)*(1 + c + d*x))))/((d*e + f - c*f)*(d*e - (1 + c)*f)) + (3*b^3*d*atanh(c + d*x)*PolyLog(2, 1 - (2*d*(e + f*x))/((d*e + f - c*f)*(1 + c + d*x))))/((d*e + f - c*f)*(d*e - (1 + c)*f)) - (3*b^3*d*PolyLog(3, 1 - 2/(1 - c - d*x)))/(4*f*(d*e + f - c*f)) + (3*b^3*d*PolyLog(3, 1 - 2/(1 + c + d*x)))/(4*f*(d*e - f - c*f)) - (3*b^3*d*PolyLog(3, 1 - 2/(1 + c + d*x)))/(2*(d*e + f - c*f)*(d*e - (1 + c)*f)) + (3*b^3*d*PolyLog(3, 1 - (2*d*(e + f*x))/((d*e + f - c*f)*(1 + c + d*x))))/(2*(d*e + f - c*f)*(d*e - (1 + c)*f)), -((a + b*atanh(c + d*x))^3/(f*(e + f*x))) + (3*a*b^2*d*atanh(c + d*x)*log(2/(1 - c - d*x)))/(f*(d*e + f - c*f)) + (3*b^3*d*atanh(c + d*x)^2*log(2/(1 - c - d*x)))/(2*f*(d*e + f - c*f)) - (3*a^2*b*d*log(1 - c - d*x))/(2*f*(d*e + f - c*f)) - (3*a*b^2*d*atanh(c + d*x)*log(2/(1 + c + d*x)))/(f*(d*e - f - c*f)) + (6*a*b^2*d*atanh(c + d*x)*log(2/(1 + c + d*x)))/((d*e - f - c*f)*(d*e + f - c*f)) - (3*b^3*d*atanh(c + d*x)^2*log(2/(1 + c + d*x)))/(2*f*(d*e - f - c*f)) + (3*b^3*d*atanh(c + d*x)^2*log(2/(1 + c + d*x)))/((d*e - f - c*f)*(d*e + f - c*f)) + (3*a^2*b*d*log(1 + c + d*x))/(2*f*(d*e - f - c*f)) + (3*a^2*b*d*log(e + f*x))/(f^2 - (d*e - c*f)^2) - (6*a*b^2*d*atanh(c + d*x)*log((2*d*(e + f*x))/((d*e + f - c*f)*(1 + c + d*x))))/((d*e - f - c*f)*(d*e + f - c*f)) - (3*b^3*d*atanh(c + d*x)^2*log((2*d*(e + f*x))/((d*e + f - c*f)*(1 + c + d*x))))/((d*e - f - c*f)*(d*e + f - c*f)) + (3*a*b^2*d*PolyLog(2, -((1 + c + d*x)/(1 - c - d*x))))/(2*f*(d*e + f - c*f)) + (3*b^3*d*atanh(c + d*x)*PolyLog(2, 1 - 2/(1 - c - d*x)))/(2*f*(d*e + f - c*f)) + (3*a*b^2*d*PolyLog(2, 1 - 2/(1 + c + d*x)))/(2*f*(d*e - f - c*f)) - (3*a*b^2*d*PolyLog(2, 1 - 2/(1 + c + d*x)))/((d*e - f - c*f)*(d*e + f - c*f)) + (3*b^3*d*atanh(c + d*x)*PolyLog(2, 1 - 2/(1 + c + d*x)))/(2*f*(d*e - f - c*f)) - (3*b^3*d*atanh(c + d*x)*PolyLog(2, 1 - 2/(1 + c + d*x)))/((d*e - f - c*f)*(d*e + f - c*f)) + (3*a*b^2*d*PolyLog(2, 1 - (2*d*(e + f*x))/((d*e + f - c*f)*(1 + c + d*x))))/((d*e - f - c*f)*(d*e + f - c*f)) + (3*b^3*d*atanh(c + d*x)*PolyLog(2, 1 - (2*d*(e + f*x))/((d*e + f - c*f)*(1 + c + d*x))))/((d*e - f - c*f)*(d*e + f - c*f)) - (3*b^3*d*PolyLog(3, 1 - 2/(1 - c - d*x)))/(4*f*(d*e + f - c*f)) + (3*b^3*d*PolyLog(3, 1 - 2/(1 + c + d*x)))/(4*f*(d*e - f - c*f)) - (3*b^3*d*PolyLog(3, 1 - 2/(1 + c + d*x)))/(2*(d*e - f - c*f)*(d*e + f - c*f)) + (3*b^3*d*PolyLog(3, 1 - (2*d*(e + f*x))/((d*e + f - c*f)*(1 + c + d*x))))/(2*(d*e - f - c*f)*(d*e + f - c*f)))]

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*(e+f*x)^m*(a+b*atanh(c+d*x))^p*with*m*symbolic=#

    @test_int [(e + f*x)^m*(a + b*atanh(c + d*x))^3, x, 1, Unintegrable((e + f*x)^m*(a + b*atanh(c + d*x))^3, x)]
    @test_int [(e + f*x)^m*(a + b*atanh(c + d*x))^2, x, 1, Unintegrable((e + f*x)^m*(a + b*atanh(c + d*x))^2, x)]
    @test_int [(e + f*x)^m*(a + b*atanh(c + d*x))^1, x, 6, ((e + f*x)^(1 + m)*(a + b*atanh(c + d*x)))/(f*(1 + m)) + (b*d*(e + f*x)^(2 + m)*HypergeometricFunctions._₂F₁(1, 2 + m, 3 + m, (d*(e + f*x))/(d*e - f - c*f)))/(2*f*(d*e - (1 + c)*f)*(1 + m)*(2 + m)) - (b*d*(e + f*x)^(2 + m)*HypergeometricFunctions._₂F₁(1, 2 + m, 3 + m, (d*(e + f*x))/(d*e + f - c*f)))/(2*f*(d*e + f - c*f)*(1 + m)*(2 + m))]

    #= ::Section::Closed:: =#
    #=Integrands*of*the*form*AF(x)*(a+b*atanh(c+d*x))^p=#

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*(e+f*x^m)^q*(a+b*atanh(c+d*x))^p=#

    @test_int [atanh(a + b*x)/(c + d*x^3), x, 23, -((log(1 - a - b*x)*log((b*(c^(1/3) + d^(1/3)*x))/(b*c^(1/3) + (1 - a)*d^(1/3))))/(6*c^(2/3)*d^(1/3))) + (log(1 + a + b*x)*log((b*(c^(1/3) + d^(1/3)*x))/(b*c^(1/3) - (1 + a)*d^(1/3))))/(6*c^(2/3)*d^(1/3)) - ((-1)^(2/3)*log(1 - a - b*x)*log((b*(c^(1/3) - (-1)^(1/3)*d^(1/3)*x))/(b*c^(1/3) - (-1)^(1/3)*(1 - a)*d^(1/3))))/(6*c^(2/3)*d^(1/3)) + ((-1)^(2/3)*log(1 + a + b*x)*log((b*(c^(1/3) - (-1)^(1/3)*d^(1/3)*x))/(b*c^(1/3) + (-1)^(1/3)*(1 + a)*d^(1/3))))/(6*c^(2/3)*d^(1/3)) + ((-1)^(1/3)*log(1 - a - b*x)*log((b*(c^(1/3) + (-1)^(2/3)*d^(1/3)*x))/(b*c^(1/3) + (-1)^(2/3)*(1 - a)*d^(1/3))))/(6*c^(2/3)*d^(1/3)) - ((-1)^(1/3)*log(1 + a + b*x)*log((b*(c^(1/3) + (-1)^(2/3)*d^(1/3)*x))/(b*c^(1/3) - (-1)^(2/3)*(1 + a)*d^(1/3))))/(6*c^(2/3)*d^(1/3)) - PolyLog(2, (d^(1/3)*(1 - a - b*x))/(b*c^(1/3) + (1 - a)*d^(1/3)))/(6*c^(2/3)*d^(1/3)) - ((-1)^(2/3)*PolyLog(2, -(((-1)^(1/3)*d^(1/3)*(1 - a - b*x))/(b*c^(1/3) - (-1)^(1/3)*(1 - a)*d^(1/3)))))/(6*c^(2/3)*d^(1/3)) + ((-1)^(1/3)*PolyLog(2, ((-1)^(2/3)*d^(1/3)*(1 - a - b*x))/(b*c^(1/3) + (-1)^(2/3)*(1 - a)*d^(1/3))))/(6*c^(2/3)*d^(1/3)) + PolyLog(2, -((d^(1/3)*(1 + a + b*x))/(b*c^(1/3) - (1 + a)*d^(1/3))))/(6*c^(2/3)*d^(1/3)) + ((-1)^(2/3)*PolyLog(2, ((-1)^(1/3)*d^(1/3)*(1 + a + b*x))/(b*c^(1/3) + (-1)^(1/3)*(1 + a)*d^(1/3))))/(6*c^(2/3)*d^(1/3)) - ((-1)^(1/3)*PolyLog(2, -(((-1)^(2/3)*d^(1/3)*(1 + a + b*x))/(b*c^(1/3) - (-1)^(2/3)*(1 + a)*d^(1/3)))))/(6*c^(2/3)*d^(1/3))]
    @test_int [atanh(a + b*x)/(c + d*x^2), x, 17, -(log(1 - a - b*x)*log((b*(sqrt(-c) - sqrt(d)*x))/(b*sqrt(-c) - (1 - a)*sqrt(d))))/(4*sqrt(-c)*sqrt(d)) + (log(1 + a + b*x)*log((b*(sqrt(-c) - sqrt(d)*x))/(b*sqrt(-c) + (1 + a)*sqrt(d))))/(4*sqrt(-c)*sqrt(d)) + (log(1 - a - b*x)*log((b*(sqrt(-c) + sqrt(d)*x))/(b*sqrt(-c) + (1 - a)*sqrt(d))))/(4*sqrt(-c)*sqrt(d)) - (log(1 + a + b*x)*log((b*(sqrt(-c) + sqrt(d)*x))/(b*sqrt(-c) - (1 + a)*sqrt(d))))/(4*sqrt(-c)*sqrt(d)) - PolyLog(2, -((sqrt(d)*(1 - a - b*x))/(b*sqrt(-c) - (1 - a)*sqrt(d))))/(4*sqrt(-c)*sqrt(d)) + PolyLog(2, (sqrt(d)*(1 - a - b*x))/(b*sqrt(-c) + (1 - a)*sqrt(d)))/(4*sqrt(-c)*sqrt(d)) - PolyLog(2, -((sqrt(d)*(1 + a + b*x))/(b*sqrt(-c) - (1 + a)*sqrt(d))))/(4*sqrt(-c)*sqrt(d)) + PolyLog(2, (sqrt(d)*(1 + a + b*x))/(b*sqrt(-c) + (1 + a)*sqrt(d)))/(4*sqrt(-c)*sqrt(d))]
    @test_int [atanh(a + b*x)/(c + d*x^1), x, 5, -((atanh(a + b*x)*log(2/(1 + a + b*x)))/d) + (atanh(a + b*x)*log((2*b*(c + d*x))/((b*c + d - a*d)*(1 + a + b*x))))/d + PolyLog(2, 1 - 2/(1 + a + b*x))/(2*d) - PolyLog(2, 1 - (2*b*(c + d*x))/((b*c + d - a*d)*(1 + a + b*x)))/(2*d)]
    @test_int [atanh(a + b*x)/(c + d/x^1), x, 15, ((1 - a - b*x)*log(1 - a - b*x))/(2*b*c) + ((1 + a + b*x)*log(1 + a + b*x))/(2*b*c) - (d*log(1 + a + b*x)*log(-((b*(d + c*x))/(c + a*c - b*d))))/(2*c^2) + (d*log(1 - a - b*x)*log((b*(d + c*x))/(c - a*c + b*d)))/(2*c^2) + (d*PolyLog(2, (c*(1 - a - b*x))/(c - a*c + b*d)))/(2*c^2) - (d*PolyLog(2, (c*(1 + a + b*x))/(c + a*c - b*d)))/(2*c^2)]
    @test_int [atanh(a + b*x)/(c + d/x^2), x, 25, ((1 - a - b*x)*log(1 - a - b*x))/(2*b*c) + ((1 + a + b*x)*log(1 + a + b*x))/(2*b*c) + (sqrt(d)*log(1 - a - b*x)*log(-((b*(sqrt(d) - sqrt(-c)*x))/((1 - a)*sqrt(-c) - b*sqrt(d)))))/(4*(-c)^(3/2)) - (sqrt(d)*log(1 + a + b*x)*log((b*(sqrt(d) - sqrt(-c)*x))/((1 + a)*sqrt(-c) + b*sqrt(d))))/(4*(-c)^(3/2)) + (sqrt(d)*log(1 + a + b*x)*log(-((b*(sqrt(d) + sqrt(-c)*x))/((1 + a)*sqrt(-c) - b*sqrt(d)))))/(4*(-c)^(3/2)) - (sqrt(d)*log(1 - a - b*x)*log((b*(sqrt(d) + sqrt(-c)*x))/((1 - a)*sqrt(-c) + b*sqrt(d))))/(4*(-c)^(3/2)) + (sqrt(d)*PolyLog(2, (sqrt(-c)*(1 - a - b*x))/(sqrt(-c) - a*sqrt(-c) - b*sqrt(d))))/(4*(-c)^(3/2)) - (sqrt(d)*PolyLog(2, (sqrt(-c)*(1 - a - b*x))/((1 - a)*sqrt(-c) + b*sqrt(d))))/(4*(-c)^(3/2)) + (sqrt(d)*PolyLog(2, (sqrt(-c)*(1 + a + b*x))/((1 + a)*sqrt(-c) - b*sqrt(d))))/(4*(-c)^(3/2)) - (sqrt(d)*PolyLog(2, (sqrt(-c)*(1 + a + b*x))/((1 + a)*sqrt(-c) + b*sqrt(d))))/(4*(-c)^(3/2))]
    @test_int [atanh(a + b*x)/(c + d/x^3), x, 31, ((1 - a - b*x)*log(1 - a - b*x))/(2*b*c) + ((1 + a + b*x)*log(1 + a + b*x))/(2*b*c) - (d^(1/3)*log(1 + a + b*x)*log(-((b*(d^(1/3) + c^(1/3)*x))/((1 + a)*c^(1/3) - b*d^(1/3)))))/(6*c^(4/3)) + (d^(1/3)*log(1 - a - b*x)*log((b*(d^(1/3) + c^(1/3)*x))/((1 - a)*c^(1/3) + b*d^(1/3))))/(6*c^(4/3)) + ((-1)^(2/3)*d^(1/3)*log(1 - a - b*x)*log(-((b*(d^(1/3) - (-1)^(1/3)*c^(1/3)*x))/((-1)^(1/3)*(1 - a)*c^(1/3) - b*d^(1/3)))))/(6*c^(4/3)) - ((-1)^(2/3)*d^(1/3)*log(1 + a + b*x)*log((b*(d^(1/3) - (-1)^(1/3)*c^(1/3)*x))/((-1)^(1/3)*(1 + a)*c^(1/3) + b*d^(1/3))))/(6*c^(4/3)) + ((-1)^(1/3)*d^(1/3)*log(1 + a + b*x)*log(-((b*(d^(1/3) + (-1)^(2/3)*c^(1/3)*x))/((-1)^(2/3)*(1 + a)*c^(1/3) - b*d^(1/3)))))/(6*c^(4/3)) - ((-1)^(1/3)*d^(1/3)*log(1 - a - b*x)*log((b*(d^(1/3) + (-1)^(2/3)*c^(1/3)*x))/((-1)^(2/3)*(1 - a)*c^(1/3) + b*d^(1/3))))/(6*c^(4/3)) + ((-1)^(2/3)*d^(1/3)*PolyLog(2, ((-1)^(1/3)*c^(1/3)*(1 - a - b*x))/((-1)^(1/3)*(1 - a)*c^(1/3) - b*d^(1/3))))/(6*c^(4/3)) + (d^(1/3)*PolyLog(2, (c^(1/3)*(1 - a - b*x))/((1 - a)*c^(1/3) + b*d^(1/3))))/(6*c^(4/3)) - ((-1)^(1/3)*d^(1/3)*PolyLog(2, ((-1)^(2/3)*c^(1/3)*(1 - a - b*x))/((-1)^(2/3)*(1 - a)*c^(1/3) + b*d^(1/3))))/(6*c^(4/3)) - (d^(1/3)*PolyLog(2, (c^(1/3)*(1 + a + b*x))/((1 + a)*c^(1/3) - b*d^(1/3))))/(6*c^(4/3)) + ((-1)^(1/3)*d^(1/3)*PolyLog(2, ((-1)^(2/3)*c^(1/3)*(1 + a + b*x))/((-1)^(2/3)*(1 + a)*c^(1/3) - b*d^(1/3))))/(6*c^(4/3)) - ((-1)^(2/3)*d^(1/3)*PolyLog(2, ((-1)^(1/3)*c^(1/3)*(1 + a + b*x))/((-1)^(1/3)*(1 + a)*c^(1/3) + b*d^(1/3))))/(6*c^(4/3))]

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

    #= [atanh(a + b*x)/(a + b*x^(3/2)), x, 41, (log(-a^(1/3) - b^(1/3)*sqrt(x))*log((sqrt(-1 - a) - sqrt(b)*sqrt(x))/(sqrt(-1 - a) + a^(1/3)*b^(1/6))))/(3*a^(1/3)*b^(2/3)) + ((-1)^(2/3)*log((-1)^(1/3)*a^(1/3) - b^(1/3)*sqrt(x))*log((sqrt(-1 - a) - sqrt(b)*sqrt(x))/(sqrt(-1 - a) - (-1)^(1/3)*a^(1/3)*b^(1/6))))/(3*a^(1/3)*b^(2/3)) - ((-1)^(1/3)*log(-((-1)^(2/3)*a^(1/3)) - b^(1/3)*sqrt(x))*log((sqrt(-1 - a) - sqrt(b)*sqrt(x))/(sqrt(-1 - a) + (-1)^(2/3)*a^(1/3)*b^(1/6))))/(3*a^(1/3)*b^(2/3)) - (log(-a^(1/3) - b^(1/3)*sqrt(x))*log((sqrt(1 - a) - sqrt(b)*sqrt(x))/(sqrt(1 - a) + a^(1/3)*b^(1/6))))/(3*a^(1/3)*b^(2/3)) - ((-1)^(2/3)*log((-1)^(1/3)*a^(1/3) - b^(1/3)*sqrt(x))*log((sqrt(1 - a) - sqrt(b)*sqrt(x))/(sqrt(1 - a) - (-1)^(1/3)*a^(1/3)*b^(1/6))))/(3*a^(1/3)*b^(2/3)) + ((-1)^(1/3)*log(-((-1)^(2/3)*a^(1/3)) - b^(1/3)*sqrt(x))*log((sqrt(1 - a) - sqrt(b)*sqrt(x))/(sqrt(1 - a) + (-1)^(2/3)*a^(1/3)*b^(1/6))))/(3*a^(1/3)*b^(2/3)) + (log(-a^(1/3) - b^(1/3)*sqrt(x))*log((sqrt(-1 - a) + sqrt(b)*sqrt(x))/(sqrt(-1 - a) - a^(1/3)*b^(1/6))))/(3*a^(1/3)*b^(2/3)) + ((-1)^(2/3)*log((-1)^(1/3)*a^(1/3) - b^(1/3)*sqrt(x))*log((sqrt(-1 - a) + sqrt(b)*sqrt(x))/(sqrt(-1 - a) + (-1)^(1/3)*a^(1/3)*b^(1/6))))/(3*a^(1/3)*b^(2/3)) - ((-1)^(1/3)*log(-((-1)^(2/3)*a^(1/3)) - b^(1/3)*sqrt(x))*log((sqrt(-1 - a) + sqrt(b)*sqrt(x))/(sqrt(-1 - a) - (-1)^(2/3)*a^(1/3)*b^(1/6))))/(3*a^(1/3)*b^(2/3)) - (log(-a^(1/3) - b^(1/3)*sqrt(x))*log((sqrt(1 - a) + sqrt(b)*sqrt(x))/(sqrt(1 - a) - a^(1/3)*b^(1/6))))/(3*a^(1/3)*b^(2/3)) - ((-1)^(2/3)*log((-1)^(1/3)*a^(1/3) - b^(1/3)*sqrt(x))*log((sqrt(1 - a) + sqrt(b)*sqrt(x))/(sqrt(1 - a) + (-1)^(1/3)*a^(1/3)*b^(1/6))))/(3*a^(1/3)*b^(2/3)) + ((-1)^(1/3)*log(-((-1)^(2/3)*a^(1/3)) - b^(1/3)*sqrt(x))*log((sqrt(1 - a) + sqrt(b)*sqrt(x))/(sqrt(1 - a) - (-1)^(2/3)*a^(1/3)*b^(1/6))))/(3*a^(1/3)*b^(2/3)) + (log(-a^(1/3) - b^(1/3)*sqrt(x))*log(1 - a - b*x))/(3*a^(1/3)*b^(2/3)) + ((-1)^(2/3)*log((-1)^(1/3)*a^(1/3) - b^(1/3)*sqrt(x))*log(1 - a - b*x))/(3*a^(1/3)*b^(2/3)) - ((-1)^(1/3)*log(-((-1)^(2/3)*a^(1/3)) - b^(1/3)*sqrt(x))*log(1 - a - b*x))/(3*a^(1/3)*b^(2/3)) - (log(-a^(1/3) - b^(1/3)*sqrt(x))*log(1 + a + b*x))/(3*a^(1/3)*b^(2/3)) - ((-1)^(2/3)*log((-1)^(1/3)*a^(1/3) - b^(1/3)*sqrt(x))*log(1 + a + b*x))/(3*a^(1/3)*b^(2/3)) + ((-1)^(1/3)*log(-((-1)^(2/3)*a^(1/3)) - b^(1/3)*sqrt(x))*log(1 + a + b*x))/(3*a^(1/3)*b^(2/3)) + ((-1)^(2/3)*PolyLog(2, -((b^(1/6)*((-1)^(1/3)*a^(1/3) - b^(1/3)*sqrt(x)))/(sqrt(-1 - a) - (-1)^(1/3)*a^(1/3)*b^(1/6)))))/(3*a^(1/3)*b^(2/3)) - ((-1)^(2/3)*PolyLog(2, -((b^(1/6)*((-1)^(1/3)*a^(1/3) - b^(1/3)*sqrt(x)))/(sqrt(1 - a) - (-1)^(1/3)*a^(1/3)*b^(1/6)))))/(3*a^(1/3)*b^(2/3)) + PolyLog(2, -((b^(1/6)*(a^(1/3) + b^(1/3)*sqrt(x)))/(sqrt(-1 - a) - a^(1/3)*b^(1/6))))/(3*a^(1/3)*b^(2/3)) - PolyLog(2, -((b^(1/6)*(a^(1/3) + b^(1/3)*sqrt(x)))/(sqrt(1 - a) - a^(1/3)*b^(1/6))))/(3*a^(1/3)*b^(2/3)) + PolyLog(2, (b^(1/6)*(a^(1/3) + b^(1/3)*sqrt(x)))/(sqrt(-1 - a) + a^(1/3)*b^(1/6)))/(3*a^(1/3)*b^(2/3)) - PolyLog(2, (b^(1/6)*(a^(1/3) + b^(1/3)*sqrt(x)))/(sqrt(1 - a) + a^(1/3)*b^(1/6)))/(3*a^(1/3)*b^(2/3)) - ((-1)^(1/3)*PolyLog(2, -((b^(1/6)*((-1)^(2/3)*a^(1/3) + b^(1/3)*sqrt(x)))/(sqrt(-1 - a) - (-1)^(2/3)*a^(1/3)*b^(1/6)))))/(3*a^(1/3)*b^(2/3)) + ((-1)^(1/3)*PolyLog(2, -((b^(1/6)*((-1)^(2/3)*a^(1/3) + b^(1/3)*sqrt(x)))/(sqrt(1 - a) - (-1)^(2/3)*a^(1/3)*b^(1/6)))))/(3*a^(1/3)*b^(2/3)) - ((-1)^(1/3)*PolyLog(2, (b^(1/6)*((-1)^(2/3)*a^(1/3) + b^(1/3)*sqrt(x)))/(sqrt(-1 - a) + (-1)^(2/3)*a^(1/3)*b^(1/6))))/(3*a^(1/3)*b^(2/3)) + ((-1)^(1/3)*PolyLog(2, (b^(1/6)*((-1)^(2/3)*a^(1/3) + b^(1/3)*sqrt(x)))/(sqrt(1 - a) + (-1)^(2/3)*a^(1/3)*b^(1/6))))/(3*a^(1/3)*b^(2/3)) + ((-1)^(2/3)*PolyLog(2, ((-1)^(1/3)*b^(1/6)*(a^(1/3) + (-1)^(2/3)*b^(1/3)*sqrt(x)))/(sqrt(-1 - a) + (-1)^(1/3)*a^(1/3)*b^(1/6))))/(3*a^(1/3)*b^(2/3)) - ((-1)^(2/3)*PolyLog(2, ((-1)^(1/3)*b^(1/6)*(a^(1/3) + (-1)^(2/3)*b^(1/3)*sqrt(x)))/(sqrt(1 - a) + (-1)^(1/3)*a^(1/3)*b^(1/6))))/(3*a^(1/3)*b^(2/3))] =#
    @test_int [atanh(a + b*x)/(c + d*sqrt(x)), x, 31, (2*sqrt(1 + a)*atan((sqrt(b)*sqrt(x))/sqrt(1 + a)))/(sqrt(b)*d) - (2*sqrt(1 - a)*atanh((sqrt(b)*sqrt(x))/sqrt(1 - a)))/(sqrt(b)*d) + (c*log((d*(sqrt(-1 - a) - sqrt(b)*sqrt(x)))/(sqrt(b)*c + sqrt(-1 - a)*d))*log(c + d*sqrt(x)))/d^2 - (c*log((d*(sqrt(1 - a) - sqrt(b)*sqrt(x)))/(sqrt(b)*c + sqrt(1 - a)*d))*log(c + d*sqrt(x)))/d^2 + (c*log(-((d*(sqrt(-1 - a) + sqrt(b)*sqrt(x)))/(sqrt(b)*c - sqrt(-1 - a)*d)))*log(c + d*sqrt(x)))/d^2 - (c*log(-((d*(sqrt(1 - a) + sqrt(b)*sqrt(x)))/(sqrt(b)*c - sqrt(1 - a)*d)))*log(c + d*sqrt(x)))/d^2 - (sqrt(x)*log(1 - a - b*x))/d + (c*log(c + d*sqrt(x))*log(1 - a - b*x))/d^2 + (sqrt(x)*log(1 + a + b*x))/d - (c*log(c + d*sqrt(x))*log(1 + a + b*x))/d^2 + (c*PolyLog(2, (sqrt(b)*(c + d*sqrt(x)))/(sqrt(b)*c - sqrt(-1 - a)*d)))/d^2 + (c*PolyLog(2, (sqrt(b)*(c + d*sqrt(x)))/(sqrt(b)*c + sqrt(-1 - a)*d)))/d^2 - (c*PolyLog(2, (sqrt(b)*(c + d*sqrt(x)))/(sqrt(b)*c - sqrt(1 - a)*d)))/d^2 - (c*PolyLog(2, (sqrt(b)*(c + d*sqrt(x)))/(sqrt(b)*c + sqrt(1 - a)*d)))/d^2]
    @test_int [atanh(a + b*x)/(c + d/sqrt(x)), x, 37, (-2*sqrt(1 + a)*d*atan((sqrt(b)*sqrt(x))/sqrt(1 + a)))/(sqrt(b)*c^2) + (2*sqrt(1 - a)*d*atanh((sqrt(b)*sqrt(x))/sqrt(1 - a)))/(sqrt(b)*c^2) - (d^2*log((c*(sqrt(-1 - a) - sqrt(b)*sqrt(x)))/(sqrt(-1 - a)*c + sqrt(b)*d))*log(d + c*sqrt(x)))/c^3 + (d^2*log((c*(sqrt(1 - a) - sqrt(b)*sqrt(x)))/(sqrt(1 - a)*c + sqrt(b)*d))*log(d + c*sqrt(x)))/c^3 - (d^2*log((c*(sqrt(-1 - a) + sqrt(b)*sqrt(x)))/(sqrt(-1 - a)*c - sqrt(b)*d))*log(d + c*sqrt(x)))/c^3 + (d^2*log((c*(sqrt(1 - a) + sqrt(b)*sqrt(x)))/(sqrt(1 - a)*c - sqrt(b)*d))*log(d + c*sqrt(x)))/c^3 + (d*sqrt(x)*log(1 - a - b*x))/c^2 + ((1 - a - b*x)*log(1 - a - b*x))/(2*b*c) - (d^2*log(d + c*sqrt(x))*log(1 - a - b*x))/c^3 - (d*sqrt(x)*log(1 + a + b*x))/c^2 + ((1 + a + b*x)*log(1 + a + b*x))/(2*b*c) + (d^2*log(d + c*sqrt(x))*log(1 + a + b*x))/c^3 - (d^2*PolyLog(2, -((sqrt(b)*(d + c*sqrt(x)))/(sqrt(-1 - a)*c - sqrt(b)*d))))/c^3 + (d^2*PolyLog(2, -((sqrt(b)*(d + c*sqrt(x)))/(sqrt(1 - a)*c - sqrt(b)*d))))/c^3 - (d^2*PolyLog(2, (sqrt(b)*(d + c*sqrt(x)))/(sqrt(-1 - a)*c + sqrt(b)*d)))/c^3 + (d^2*PolyLog(2, (sqrt(b)*(d + c*sqrt(x)))/(sqrt(1 - a)*c + sqrt(b)*d)))/c^3]
    #= [atanh(a + b*x)/(a + b/x^(3/2)), x, 49, -(b^(2/3)*log(-b^(1/3) - a^(1/3)*sqrt(x))*log((a^(1/3)*(sqrt(-1 - a) - sqrt(b)*sqrt(x)))/(sqrt(-1 - a)*a^(1/3) + b^(5/6))))/(3*a^(5/3)) - ((-1)^(2/3)*b^(2/3)*log((-1)^(1/3)*b^(1/3) - a^(1/3)*sqrt(x))*log((a^(1/3)*(sqrt(-1 - a) - sqrt(b)*sqrt(x)))/(sqrt(-1 - a)*a^(1/3) - (-1)^(1/3)*b^(5/6))))/(3*a^(5/3)) + ((-1)^(1/3)*b^(2/3)*log(-((-1)^(2/3)*b^(1/3)) - a^(1/3)*sqrt(x))*log((a^(1/3)*(sqrt(-1 - a) - sqrt(b)*sqrt(x)))/(sqrt(-1 - a)*a^(1/3) + (-1)^(2/3)*b^(5/6))))/(3*a^(5/3)) + (b^(2/3)*log(-b^(1/3) - a^(1/3)*sqrt(x))*log((a^(1/3)*(sqrt(1 - a) - sqrt(b)*sqrt(x)))/(sqrt(1 - a)*a^(1/3) + b^(5/6))))/(3*a^(5/3)) + ((-1)^(2/3)*b^(2/3)*log((-1)^(1/3)*b^(1/3) - a^(1/3)*sqrt(x))*log((a^(1/3)*(sqrt(1 - a) - sqrt(b)*sqrt(x)))/(sqrt(1 - a)*a^(1/3) - (-1)^(1/3)*b^(5/6))))/(3*a^(5/3)) - ((-1)^(1/3)*b^(2/3)*log(-((-1)^(2/3)*b^(1/3)) - a^(1/3)*sqrt(x))*log((a^(1/3)*(sqrt(1 - a) - sqrt(b)*sqrt(x)))/(sqrt(1 - a)*a^(1/3) + (-1)^(2/3)*b^(5/6))))/(3*a^(5/3)) - (b^(2/3)*log(-b^(1/3) - a^(1/3)*sqrt(x))*log((a^(1/3)*(sqrt(-1 - a) + sqrt(b)*sqrt(x)))/(sqrt(-1 - a)*a^(1/3) - b^(5/6))))/(3*a^(5/3)) - ((-1)^(2/3)*b^(2/3)*log((-1)^(1/3)*b^(1/3) - a^(1/3)*sqrt(x))*log((a^(1/3)*(sqrt(-1 - a) + sqrt(b)*sqrt(x)))/(sqrt(-1 - a)*a^(1/3) + (-1)^(1/3)*b^(5/6))))/(3*a^(5/3)) + ((-1)^(1/3)*b^(2/3)*log(-((-1)^(2/3)*b^(1/3)) - a^(1/3)*sqrt(x))*log((a^(1/3)*(sqrt(-1 - a) + sqrt(b)*sqrt(x)))/(sqrt(-1 - a)*a^(1/3) - (-1)^(2/3)*b^(5/6))))/(3*a^(5/3)) + (b^(2/3)*log(-b^(1/3) - a^(1/3)*sqrt(x))*log((a^(1/3)*(sqrt(1 - a) + sqrt(b)*sqrt(x)))/(sqrt(1 - a)*a^(1/3) - b^(5/6))))/(3*a^(5/3)) + ((-1)^(2/3)*b^(2/3)*log((-1)^(1/3)*b^(1/3) - a^(1/3)*sqrt(x))*log((a^(1/3)*(sqrt(1 - a) + sqrt(b)*sqrt(x)))/(sqrt(1 - a)*a^(1/3) + (-1)^(1/3)*b^(5/6))))/(3*a^(5/3)) - ((-1)^(1/3)*b^(2/3)*log(-((-1)^(2/3)*b^(1/3)) - a^(1/3)*sqrt(x))*log((a^(1/3)*(sqrt(1 - a) + sqrt(b)*sqrt(x)))/(sqrt(1 - a)*a^(1/3) - (-1)^(2/3)*b^(5/6))))/(3*a^(5/3)) + ((1 - a - b*x)*log(1 - a - b*x))/(2*a*b) - (b^(2/3)*log(-b^(1/3) - a^(1/3)*sqrt(x))*log(1 - a - b*x))/(3*a^(5/3)) - ((-1)^(2/3)*b^(2/3)*log((-1)^(1/3)*b^(1/3) - a^(1/3)*sqrt(x))*log(1 - a - b*x))/(3*a^(5/3)) + ((-1)^(1/3)*b^(2/3)*log(-((-1)^(2/3)*b^(1/3)) - a^(1/3)*sqrt(x))*log(1 - a - b*x))/(3*a^(5/3)) + ((1 + a + b*x)*log(1 + a + b*x))/(2*a*b) + (b^(2/3)*log(-b^(1/3) - a^(1/3)*sqrt(x))*log(1 + a + b*x))/(3*a^(5/3)) + ((-1)^(2/3)*b^(2/3)*log((-1)^(1/3)*b^(1/3) - a^(1/3)*sqrt(x))*log(1 + a + b*x))/(3*a^(5/3)) - ((-1)^(1/3)*b^(2/3)*log(-((-1)^(2/3)*b^(1/3)) - a^(1/3)*sqrt(x))*log(1 + a + b*x))/(3*a^(5/3)) - ((-1)^(2/3)*b^(2/3)*PolyLog(2, -((sqrt(b)*((-1)^(1/3)*b^(1/3) - a^(1/3)*sqrt(x)))/(sqrt(-1 - a)*a^(1/3) - (-1)^(1/3)*b^(5/6)))))/(3*a^(5/3)) + ((-1)^(2/3)*b^(2/3)*PolyLog(2, -((sqrt(b)*((-1)^(1/3)*b^(1/3) - a^(1/3)*sqrt(x)))/(sqrt(1 - a)*a^(1/3) - (-1)^(1/3)*b^(5/6)))))/(3*a^(5/3)) - (b^(2/3)*PolyLog(2, -((sqrt(b)*(b^(1/3) + a^(1/3)*sqrt(x)))/(sqrt(-1 - a)*a^(1/3) - b^(5/6)))))/(3*a^(5/3)) + (b^(2/3)*PolyLog(2, -((sqrt(b)*(b^(1/3) + a^(1/3)*sqrt(x)))/(sqrt(1 - a)*a^(1/3) - b^(5/6)))))/(3*a^(5/3)) - (b^(2/3)*PolyLog(2, (sqrt(b)*(b^(1/3) + a^(1/3)*sqrt(x)))/(sqrt(-1 - a)*a^(1/3) + b^(5/6))))/(3*a^(5/3)) + (b^(2/3)*PolyLog(2, (sqrt(b)*(b^(1/3) + a^(1/3)*sqrt(x)))/(sqrt(1 - a)*a^(1/3) + b^(5/6))))/(3*a^(5/3)) + ((-1)^(1/3)*b^(2/3)*PolyLog(2, -((sqrt(b)*((-1)^(2/3)*b^(1/3) + a^(1/3)*sqrt(x)))/(sqrt(-1 - a)*a^(1/3) - (-1)^(2/3)*b^(5/6)))))/(3*a^(5/3)) - ((-1)^(1/3)*b^(2/3)*PolyLog(2, -((sqrt(b)*((-1)^(2/3)*b^(1/3) + a^(1/3)*sqrt(x)))/(sqrt(1 - a)*a^(1/3) - (-1)^(2/3)*b^(5/6)))))/(3*a^(5/3)) + ((-1)^(1/3)*b^(2/3)*PolyLog(2, (sqrt(b)*((-1)^(2/3)*b^(1/3) + a^(1/3)*sqrt(x)))/(sqrt(-1 - a)*a^(1/3) + (-1)^(2/3)*b^(5/6))))/(3*a^(5/3)) - ((-1)^(1/3)*b^(2/3)*PolyLog(2, (sqrt(b)*((-1)^(2/3)*b^(1/3) + a^(1/3)*sqrt(x)))/(sqrt(1 - a)*a^(1/3) + (-1)^(2/3)*b^(5/6))))/(3*a^(5/3)) - ((-1)^(2/3)*b^(2/3)*PolyLog(2, ((-1)^(1/3)*sqrt(b)*(b^(1/3) + (-1)^(2/3)*a^(1/3)*sqrt(x)))/(sqrt(-1 - a)*a^(1/3) + (-1)^(1/3)*b^(5/6))))/(3*a^(5/3)) + ((-1)^(2/3)*b^(2/3)*PolyLog(2, ((-1)^(1/3)*sqrt(b)*(b^(1/3) + (-1)^(2/3)*a^(1/3)*sqrt(x)))/(sqrt(1 - a)*a^(1/3) + (-1)^(1/3)*b^(5/6))))/(3*a^(5/3))] =#

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*(e+f*x+g*x^2)^q*(a+b*atanh(c+d*x))^p=#

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

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

    @test_int [(c*e + d*e*x)*(a + b*atanh(c + d*x))/(1 - (c + d*x)^2), x, 6, -((e*(a + b*atanh(c + d*x))^2)/(2*b*d)) + (e*(a + b*atanh(c + d*x))*log(2/(1 - c - d*x)))/d + (b*e*PolyLog(2, -((1 + c + d*x)/(1 - c - d*x))))/(2*d)]
    end

max_stars_repo_path: test/7 Inverse hyperbolic functions/7.3 Inverse hyperbolic tangent/7.3.5 u (a+b arctanh(c+d x))^p.jl


text:
using ClimaCache
using PkgUtility
using Test

@testset verbose = true "ClimaCache Test" begin
    @testset "Air" begin
        for FT in [Float32, Float64]
            air = ClimaCache.AirLayer{FT}();
            @test FT_test(air, FT);
            @test NaN_test(air);
        end;
    end;

    @testset "Plant" begin
        for FT in [Float32, Float64]
            # Leaf
            leaf_c3 = ClimaCache.Leaf{FT}("C3");
            leaf_c4 = ClimaCache.Leaf{FT}("C4");
            leaf_cy = ClimaCache.Leaf{FT}("C3Cytochrome");
            leaf_d3 = ClimaCache.Leaf{FT}("C3", colimit = true);
            leaf_d4 = ClimaCache.Leaf{FT}("C4", colimit = true);
            leaf_dy = ClimaCache.Leaf{FT}("C3Cytochrome", colimit = true);
            wls     = ClimaCache.WaveLengthSet{FT}(collect(400:10:2500));
            leaf_e3 = ClimaCache.Leaf{FT}("C3", wls);
            leaf_e4 = ClimaCache.Leaf{FT}("C4", wls);
            leaf_ey = ClimaCache.Leaf{FT}("C3Cytochrome", wls);
            for leaf in [leaf_c3, leaf_c4, leaf_cy, leaf_d3, leaf_d4, leaf_dy, leaf_e3, leaf_e4, leaf_ey]
                @test FT_test(leaf, FT);
                # NaN test will not pass because of the NaNs in temperature dependency structures
                # @test NaN_test(leaf);
            end;

            # LeafBiophysics
            lbio1 = ClimaCache.LeafBiophysics{FT}();
            lbio2 = ClimaCache.LeafBiophysics{FT}(ClimaCache.WaveLengthSet{FT}(collect(400:50:2400)));
            for lbio in [lbio1, lbio2]
                @test FT_test(lbio, FT);
                @test NaN_test(lbio);
            end;

            # Fluorescence model
            vdt1 = ClimaCache.VanDerTolFluorescenceModel{FT}();
            vdt2 = ClimaCache.VanDerTolFluorescenceModel{FT}(true);
            for vdt in [vdt1, vdt2]
                @test FT_test(vdt, FT);
                @test NaN_test(vdt);
            end;

            # Reaction center
            rc1 = ClimaCache.VJPReactionCenter{FT}();
            rc2 = ClimaCache.CytochromeReactionCenter{FT}();
            for rc in [rc1, rc2]
                @test FT_test(rc, FT);
                @test NaN_test(rc);
            end;

            # Photosynthesis model
            cy_1 = ClimaCache.C3CytochromeModel{FT}();
            cy_2 = ClimaCache.C3CytochromeModel{FT}(v_cmax25 = 30, r_d25 = 1, colimit = true);
            c3_1 = ClimaCache.C3VJPModel{FT}();
            c3_2 = ClimaCache.C3VJPModel{FT}(v_cmax25 = 30, j_max25 = 50, r_d25 = 1, colimit = true);
            c4_1 = ClimaCache.C4VJPModel{FT}();
            c4_2 = ClimaCache.C4VJPModel{FT}(v_cmax25 = 30, v_pmax25 = 40, r_d25 = 1, colimit = true);
            for st in [cy_1, cy_2, c3_1, c3_2, c4_1, c4_2]
                for rc in [rc1, rc2]
                    @test FT_test(st, FT);
                    # NaN test will not pass because of the NaNs in temperature dependency structures
                    # @test NaN_test(st);
                end;
            end;

            # Mode and colimitations
            mod1 = ClimaCache.GCO₂Mode();
            mod2 = ClimaCache.PCO₂Mode();
            col1 = ClimaCache.MinimumColimit{FT}();
            col2 = ClimaCache.QuadraticColimit{FT}(0.98);
            col3 = ClimaCache.SerialColimit{FT}();
            for st in [mod1, mod2, col1, col2, col3]
                for rc in [rc1, rc2]
                    @test FT_test(st, FT);
                    @test NaN_test(st);
                end;
            end;

            # Temperature dependency
            td_1 = ClimaCache.Arrhenius{FT}(298.15, 41.0, 79430.0);
            td_2 = ClimaCache.ArrheniusPeak{FT}(298.15, 1.0, 57500.0, 439000.0, 1400.0);
            td_3 = ClimaCache.Q10{FT}(298.15, 0.0140/8760, 1.4);
            for td in [td_1, td_2, td_3]
                @test FT_test(td, FT);
                @test NaN_test(td);
            end;
        end;
    end;

    @testset "Radiation" begin
        for FT in [Float32, Float64]
            wls1 = ClimaCache.WaveLengthSet{FT}();
            wls2 = ClimaCache.WaveLengthSet{FT}(collect(400:5:2500));
            wls3 = ClimaCache.WaveLengthSet{FT}(collect(400:5:2500); opti=ClimaCache.OPTI_2017);
            for wls in [wls1, wls2, wls3]
                @test FT_test(wls, FT);
                # NaN test will not pass because of the NaNs in wls2 and wls3
                # @test NaN_test(wls);
            end;
        end;
    end;
end;

ext: jl


text:
# ---------------------------------------------------------------------------
# Violin Plot

const _violin_warned = [false]

function violin_coords(y; wts = nothing, trim::Bool=false)

    kd = wts === nothing ? KernelDensity.kde(y, npoints = 200) : KernelDensity.kde(y, weights = weights(wts), npoints = 200)
    if trim
        xmin, xmax = Plots.ignorenan_extrema(y)
        inside = Bool[ xmin <= x <= xmax for x in kd.x]
        return(kd.density[inside], kd.x[inside])
    end
    kd.density, kd.x
end

get_quantiles(quantiles::AbstractVector) = quantiles
get_quantiles(x::Real) = [x]
get_quantiles(b::Bool) = b ? [0.5] : Float64[]
get_quantiles(n::Int) = range(0, 1, length = n + 2)[2:end-1]

@recipe function f(::Type{Val{:violin}}, x, y, z; trim=true, side=:both, show_mean = false, show_median = false, quantiles = Float64[])
    # if only y is provided, then x will be UnitRange 1:size(y,2)
    if typeof(x) <: AbstractRange
        if step(x) == first(x) == 1
            x = plotattributes[:series_plotindex]
        else
            x = [getindex(x, plotattributes[:series_plotindex])]
        end
    end
    xsegs, ysegs = Segments(), Segments()
    qxsegs, qysegs = Segments(), Segments()
    mxsegs, mysegs = Segments(), Segments()
    glabels = sort(collect(unique(x)))
    bw = plotattributes[:bar_width]
    bw == nothing && (bw = 0.8)
    msc = plotattributes[:markerstrokecolor]
    for (i,glabel) in enumerate(glabels)
        fy = y[filter(i -> _cycle(x,i) == glabel, 1:length(y))]
        widths, centers = violin_coords(fy, trim=trim, wts = plotattributes[:weights])
        isempty(widths) && continue

        # normalize
        hw = 0.5_cycle(bw, i)
        widths = hw * widths / Plots.ignorenan_maximum(widths)

        # make the violin
        xcenter = Plots.discrete_value!(plotattributes[:subplot][:xaxis], glabel)[1]
        xcoords = if (side==:right)
            vcat(widths, zeros(length(widths))) .+ xcenter
        elseif (side==:left)
            vcat(zeros(length(widths)), -reverse(widths)) .+ xcenter
        else
            vcat(widths, -reverse(widths)) .+ xcenter
        end
        ycoords = vcat(centers, reverse(centers))

        push!(xsegs, xcoords)
        push!(ysegs, ycoords)

        if show_mean
            mea = StatsBase.mean(fy)
            mw = maximum(widths)
            mx = xcenter .+ [-mw, mw] * 0.75
            my = [mea, mea]
            if side == :right
                mx[1] = xcenter
            elseif side == :left
                mx[2] = xcenter
            end

            push!(mxsegs, mx)
            push!(mysegs, my)
        end

        if show_median
            med = StatsBase.median(fy)
            mw = maximum(widths)
            mx = xcenter .+ [-mw, mw] / 2
            my = [med, med]
            if side == :right
                mx[1] = xcenter
            elseif side == :left
                mx[2] = xcenter
            end

            push!(qxsegs, mx)
            push!(qysegs, my)
        end

        quantiles = get_quantiles(quantiles)
        if !isempty(quantiles)
            qy = quantile(fy, quantiles)
            maxw = maximum(widths)

            for i in eachindex(qy)
                qxi = xcenter .+ [-maxw, maxw] * (0.5 - abs(0.5 - quantiles[i]))
                qyi = [qy[i], qy[i]]
                if side == :right
                    qxi[1] = xcenter
                elseif side == :left
                    qxi[2] = xcenter
                end

                push!(qxsegs, qxi)
                push!(qysegs, qyi)
            end

            push!(qxsegs, [xcenter, xcenter])
            push!(qysegs, [extrema(qy)...])
        end
    end

    @series begin
        seriestype := :shape
        x := xsegs.pts
        y := ysegs.pts
        ()
    end

    if !isempty(mxsegs.pts)
        @series begin
            primary := false
            seriestype := :shape
            linestyle := :dot
            x := mxsegs.pts
            y := mysegs.pts
            ()
        end
    end

    if !isempty(qxsegs.pts)
        @series begin
            primary := false
            seriestype := :shape
            x := qxsegs.pts
            y := qysegs.pts
            ()
        end
    end

    seriestype := :shape
    primary := false
    x := []
    y := []
    ()
end
Plots.@deps violin shape

# ------------------------------------------------------------------------------
# Grouped Violin

@userplot GroupedViolin

recipetype(::Val{:groupedviolin}, args...) = GroupedViolin(args)

@recipe function f(g::GroupedViolin; spacing = 0.1)
    x, y = grouped_xy(g.args...)

    # extract xnums and set default bar width.
    # might need to set xticks as well
    ux = unique(x)
    x = if eltype(x) <: Number
        bar_width --> (0.8 * mean(diff(sort(ux))))
        float.(x)
    else
        bar_width --> 0.8
        xnums = [findfirst(isequal(xi), ux) for xi in x] .- 0.5
        xticks --> (eachindex(ux) .- 0.5, ux)
        xnums
    end

    # shift x values for each group
    group = get(plotattributes, :group, nothing)
    if group != nothing
        gb = Plots.extractGroupArgs(group)
        labels, idxs = getfield(gb, 1), getfield(gb, 2)
        n = length(labels)
        bws = plotattributes[:bar_width] / n
        bar_width := bws * clamp(1 - spacing, 0, 1)
        for i in 1:n
            groupinds = idxs[i]
            Δx = _cycle(bws, i) * (i - (n + 1) / 2)
            x[groupinds] .+= Δx
        end
    end

    seriestype := :violin
    x, y
end

Plots.@deps groupedviolin violin


text:
#=
This file is auto-generated. Do not edit.
=#
"""
    mutable struct OneDOneQMachine <: Machine
        R::Float64
        Xd::Float64
        Xq::Float64
        Xd_p::Float64
        Xq_p::Float64
        Td0_p::Float64
        Tq0_p::Float64
        ext::Dict{String, Any}
        states::Vector{Symbol}
        n_states::Int64
        internal::InfrastructureSystemsInternal
    end

Parameters of 4-states synchronous machine: Simplified Marconato model
 The derivative of stator fluxes (ψd and ψq) is neglected and ωψd = ψd and
 ωψq = ψq is assumed (i.e. ω=1.0). This is standard when
 transmission network dynamics is neglected.

# Arguments
- `R::Float64`: Resistance after EMF in machine per unit, validation range: (0, nothing)
- `Xd::Float64`: Reactance after EMF in d-axis per unit, validation range: (0, nothing)
- `Xq::Float64`: Reactance after EMF in q-axis per unit, validation range: (0, nothing)
- `Xd_p::Float64`: Transient reactance after EMF in d-axis per unit, validation range: (0, nothing)
- `Xq_p::Float64`: Transient reactance after EMF in q-axis per unit, validation range: (0, nothing)
- `Td0_p::Float64`: Time constant of transient d-axis voltage, validation range: (0, nothing)
- `Tq0_p::Float64`: Time constant of transient q-axis voltage, validation range: (0, nothing)
- `ext::Dict{String, Any}`
- `states::Vector{Symbol}`
- `n_states::Int64`
- `internal::InfrastructureSystemsInternal`: power system internal reference, do not modify
"""
mutable struct OneDOneQMachine <: Machine
    "Resistance after EMF in machine per unit"
    R::Float64
    "Reactance after EMF in d-axis per unit"
    Xd::Float64
    "Reactance after EMF in q-axis per unit"
    Xq::Float64
    "Transient reactance after EMF in d-axis per unit"
    Xd_p::Float64
    "Transient reactance after EMF in q-axis per unit"
    Xq_p::Float64
    "Time constant of transient d-axis voltage"
    Td0_p::Float64
    "Time constant of transient q-axis voltage"
    Tq0_p::Float64
    ext::Dict{String, Any}
    states::Vector{Symbol}
    n_states::Int64
    "power system internal reference, do not modify"
    internal::InfrastructureSystemsInternal
end

function OneDOneQMachine(R, Xd, Xq, Xd_p, Xq_p, Td0_p, Tq0_p, ext=Dict{String, Any}(), )
    OneDOneQMachine(R, Xd, Xq, Xd_p, Xq_p, Td0_p, Tq0_p, ext, [:eq_p, :ed_p], 2, InfrastructureSystemsInternal(), )
end

function OneDOneQMachine(; R, Xd, Xq, Xd_p, Xq_p, Td0_p, Tq0_p, ext=Dict{String, Any}(), )
    OneDOneQMachine(R, Xd, Xq, Xd_p, Xq_p, Td0_p, Tq0_p, ext, )
end

# Constructor for demo purposes; non-functional.
function OneDOneQMachine(::Nothing)
    OneDOneQMachine(;
        R=0,
        Xd=0,
        Xq=0,
        Xd_p=0,
        Xq_p=0,
        Td0_p=0,
        Tq0_p=0,
        ext=Dict{String, Any}(),
    )
end

"""Get OneDOneQMachine R."""
get_R(value::OneDOneQMachine) = value.R
"""Get OneDOneQMachine Xd."""
get_Xd(value::OneDOneQMachine) = value.Xd
"""Get OneDOneQMachine Xq."""
get_Xq(value::OneDOneQMachine) = value.Xq
"""Get OneDOneQMachine Xd_p."""
get_Xd_p(value::OneDOneQMachine) = value.Xd_p
"""Get OneDOneQMachine Xq_p."""
get_Xq_p(value::OneDOneQMachine) = value.Xq_p
"""Get OneDOneQMachine Td0_p."""
get_Td0_p(value::OneDOneQMachine) = value.Td0_p
"""Get OneDOneQMachine Tq0_p."""
get_Tq0_p(value::OneDOneQMachine) = value.Tq0_p
"""Get OneDOneQMachine ext."""
get_ext(value::OneDOneQMachine) = value.ext
"""Get OneDOneQMachine states."""
get_states(value::OneDOneQMachine) = value.states
"""Get OneDOneQMachine n_states."""
get_n_states(value::OneDOneQMachine) = value.n_states
"""Get OneDOneQMachine internal."""
get_internal(value::OneDOneQMachine) = value.internal

"""Set OneDOneQMachine R."""
set_R!(value::OneDOneQMachine, val::Float64) = value.R = val
"""Set OneDOneQMachine Xd."""
set_Xd!(value::OneDOneQMachine, val::Float64) = value.Xd = val
"""Set OneDOneQMachine Xq."""
set_Xq!(value::OneDOneQMachine, val::Float64) = value.Xq = val
"""Set OneDOneQMachine Xd_p."""
set_Xd_p!(value::OneDOneQMachine, val::Float64) = value.Xd_p = val
"""Set OneDOneQMachine Xq_p."""
set_Xq_p!(value::OneDOneQMachine, val::Float64) = value.Xq_p = val
"""Set OneDOneQMachine Td0_p."""
set_Td0_p!(value::OneDOneQMachine, val::Float64) = value.Td0_p = val
"""Set OneDOneQMachine Tq0_p."""
set_Tq0_p!(value::OneDOneQMachine, val::Float64) = value.Tq0_p = val
"""Set OneDOneQMachine ext."""
set_ext!(value::OneDOneQMachine, val::Dict{String, Any}) = value.ext = val
"""Set OneDOneQMachine states."""
set_states!(value::OneDOneQMachine, val::Vector{Symbol}) = value.states = val
"""Set OneDOneQMachine n_states."""
set_n_states!(value::OneDOneQMachine, val::Int64) = value.n_states = val
"""Set OneDOneQMachine internal."""
set_internal!(value::OneDOneQMachine, val::InfrastructureSystemsInternal) = value.internal = val


text:
using Utils

const Num = Int

function parse_file(f)
    collect(eachline(f))
end

function load()
    open(joinpath(@__DIR__, "18.txt"), "r") do f
        parse_file(f)
    end
end

isnodigit = !isdigit

is_paren(c) = c == '(' || c == ')'

function find_matching(s, from)
    @assert s[from] == '('
    level = 1
    while true
        cand = findnext(is_paren, s, from + 1)
        level -= s[cand] == ')' ? 1 : -1
        level == 0 && return cand
        from = cand
    end
end

function tokenize_l2r(expr)
    re = []
    cursor = 1
    while cursor <= length(expr)
        if expr[cursor] == '('
            close = find_matching(expr, cursor)
            push!(re, tokenize_l2r(expr[cursor+1:close-1]))
            cursor = close + 1
        elseif expr[cursor] == '+'
            push!(re, :plus)
            cursor += 1
        elseif expr[cursor] == '*'
            push!(re, :times)
            cursor += 1
        elseif isdigit(expr[cursor])
            after = something(findnext(isnodigit, expr, cursor), length(expr) + 1)
            push!(re, parse(Int, expr[cursor:after-1]))
            cursor = after
        else
            cursor += 1
        end
    end
    re
end

evaluate_l2r(term::Int) = term

function evaluate_l2r(terms::Array)
    acc = evaluate_l2r(terms[1])
    i = 2
    while i <= length(terms)
        if terms[i] == :plus
            acc += evaluate_l2r(terms[i + 1])
        elseif terms[i] == :times
            acc *= evaluate_l2r(terms[i + 1])
        end
        i += 2
    end
    acc
end

function reduce_stack(ops, operands)
    while true
        len = length(ops)
        if len == 0
            @assert length(operands) == 1
            return operands[1]
        elseif len >= 1 && ops[end] == :plus
            push!(operands, pop!(operands) + pop!(operands))
            pop!(ops)
        elseif len >= 2 && ops[end] == :times == ops[end - 1]
            keep = pop!(operands)
            push!(operands, pop!(operands) * pop!(operands))
            push!(operands, keep)
            pop!(ops)
        else
            push!(operands, pop!(operands) * pop!(operands))
            @assert pop!(ops) == :times
        end
    end
end

function evaluate(terms::Array)
    stack = Num[]
    for t in terms
        if isa(t, Num)
            push!(stack, t)
        else
            a = pop!(stack)
            b = pop!(stack)
            push!(stack, t == :+ ? a + b : a * b)
        end
    end

    only(stack)
end

function tokenize(expr)
    expr = replace(expr, " " => "")
    operands = Union{Num,Symbol}[]
    ops = Symbol[]

    cursor::Num = 1
    while cursor <= length(expr)
        if expr[cursor] == '('
            push!(ops, :open)
        elseif expr[cursor] == ')'
            while true
                top = pop!(ops)
                top == :open && break
                push!(operands, top)
            end
        elseif isdigit(expr[cursor])
            after = something(findnext(isnodigit, expr, cursor), length(expr) + 1)
            push!(operands, parse(Num, expr[cursor:after-1]))
            cursor = after
            continue
        elseif expr[cursor] == '+'
            push!(ops, :+)
        elseif expr[cursor] == '*'
            while !isempty(ops) && ops[end] == :+
                push!(operands, pop!(ops))
            end
            push!(ops, :*)
        end
        cursor += 1
    end

    while !isempty(ops)
        push!(operands, pop!(ops))
    end

    operands
end

function ex1(eqs)
    sum(eq -> tokenize_l2r(eq) |> evaluate_l2r, eqs)
end

function ex2(eqs)
    sum(eq -> tokenize(eq) |> evaluate, eqs)
end

eqs = load()

println("Sum of equations: ", ex1(eqs))
println("With precedence: ", ex2(eqs))

using Test

@testset "Operation Order" begin
@test find_matching("(3+5)", 1) == 5
@test find_matching("((3+5))", 1) == 7
@test find_matching("((3+5))", 1) == 7
@test find_matching("((3+5))", 2) == 6

@testset "example 1" begin
        @test ex1(parse_file(IOBuffer("1 + 2 * 3 + 4 * 5 + 6"))) == 71
        @test ex1(parse_file(IOBuffer("1 + (2 * 3) + (4 * (5 + 6))"))) == 51
        @test ex1(parse_file(IOBuffer("2 * 3 + (4 * 5)"))) == 26
        @test ex1(parse_file(IOBuffer("5 + (8 * 3 + 9 + 3 * 4 * 3)"))) == 437
        @test ex1(parse_file(IOBuffer("5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4))"))) == 12240
        @test ex1(parse_file(IOBuffer("((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2"))) == 13632
    end

    @testset "example 2" begin
        @test ex2(parse_file(IOBuffer("1 + (2 * 3) + (4 * (5 + 6))"))) == 51
        @test ex2(parse_file(IOBuffer("2 * 3 + (4 * 5)"))) == 46
        @test ex2(parse_file(IOBuffer("5 + (8 * 3 + 9 + 3 * 4 * 3)"))) == 1445
        @test ex2(parse_file(IOBuffer("5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4))"))) == 669060
        @test ex2(parse_file(IOBuffer("((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2"))) == 23340
    end

    @testset "results" begin
        @test ex1(eqs) == 12956356593940
        @test ex2(eqs) == 94240043727614
    end
end

max_stars_repo_name: CmdQ/AoC


text:
using Test
using MPI

MPI.Init()

function scatterv_array(A, counts::Vector{Cint}, root)
    comm = MPI.COMM_WORLD
    T = eltype(A)
    if MPI.Comm_rank(comm) == root
        B = copy(A)
    else
        B = Array{T}(undef,1)
    end
    C = MPI.Scatterv(B, counts, root, comm)
end

comm = MPI.COMM_WORLD
size = MPI.Comm_size(comm)
rank = MPI.Comm_rank(comm)
root = 0
isroot = (MPI.Comm_rank(comm) == root)
# Defining this to make ones work for Char
Base.one(::Type{Char}) = '\01'

for typ in Base.uniontypes(MPI.MPIDatatype)

    # Allocating
    A = ones(typ, 3 * div(size,2) + mod(size,2))
    counts = Cint[ mod(i,2) + 1 for i in 0:(size-1)]
    B = scatterv_array(A, counts, root)
    @test B == ones(typ, mod(rank,2) + 1)

    # Non Allocating
    A = ones(typ, 3 * div(size,2) + mod(size,2))
    counts = Cint[ mod(i,2) + 1 for i in 0:(size-1)]
    B = Array{typ}(undef, counts[MPI.Comm_rank(comm) + 1])
    MPI.Scatterv!(A, B, counts, root, comm)
    @test B == ones(typ, mod(rank,2) + 1)

    # IN_PLACE
    counts = Cint[ mod(i,2) + 1 for i in 0:(size-1)]
    A = ones(typ, 3 * div(size,2) + mod(size,2))
    if isroot
        B = deepcopy(A)
    else
        B = Array{typ}(undef, counts[MPI.Comm_rank(comm) + 1])
    end
    MPI.Scatterv_in_place!(B, counts, root, comm)
    isroot  && @test B == A
    !isroot && @test B == ones(typ, mod(rank,2) + 1)
end

MPI.Finalize()
@test MPI.Finalized()


text:
# A simple Euler explicit time stepping method to use and test the other
# methods of the package without requiring a full ODE solver.

import ProgressMeter

struct FixedCourant{T}
    fixed_courant::T
end

struct TimeDependantFlux{F}
    flux_at::F
end

function directional_splitting(f::TimeDependantFlux)
    (
    TimeDependantFlux(t -> directional_splitting(f.flux_at(t))[1]),
    TimeDependantFlux(t -> directional_splitting(f.flux_at(t))[2]),
    )
end

function run!(fluxes::Tuple, mesh, w, scheme, t; nb_time_steps, time_step, verbose=true, callback=nothing, kwargs...)

	if verbose
		p = ProgressMeter.Progress(nb_time_steps, dt=0.1)
	end

    current_fluxes = map(f -> f isa TimeDependantFlux ? f.flux_at(t) : f, fluxes)
    Δw = zeros(Δw_type(current_fluxes[1], mesh, w, scheme, t), size(w))

    for i_time_step in 1:nb_time_steps

        current_fluxes = map(f -> f isa TimeDependantFlux ? f.flux_at(t) : f, fluxes)

        if time_step isa FixedCourant
            dt = minimum(time_step.fixed_courant/courant(one(eltype(t)), f, mesh, w) for f in current_fluxes)
        else
            dt = time_step
        end

        for f in current_fluxes
            Δw .= zeros(eltype(Δw), size(Δw))
            div!(Δw, f, mesh, w, scheme, dt)
            w .-= dt .* Δw
        end

		if verbose
			ProgressMeter.update!(p, i_time_step)
		end

        t += dt

        if callback != nothing
            callback(i_time_step, t, w)
        end
    end

    return t
end

run!(flux, mesh, w, scheme, t; kwargs...) = run!((flux,), mesh, w, scheme, t; kwargs...)

run!(flux, mesh, w, scheme; t=0.0, kwargs...) = run!(flux, mesh, w, scheme, t; kwargs...)

run!(flux, mesh, w; scheme=Upwind(), boundary_flux=NeumannBC(), kwargs...) = run!(flux, mesh, w, (scheme, boundary_flux); kwargs...)

function run(flux, mesh, w₀, args...; kwargs...)
	w = deepcopy(w₀)
    t = run!(flux, mesh, w, args...; kwargs...)
	return t, w
end


text:
ENV["PYTHON"]=""
using Pkg
Pkg.add("Conda")
using Conda
Conda.update()
Conda.add("matplotlib")
Conda.add_channel("conda-forge")
Conda.add("starry")
Pkg.add("PyCall")
Pkg.build("PyCall")
Pkg.add("PyPlot")
Pkg.add("SpecialFunctions")
Pkg.add("ForwardDiff")
Pkg.add("DiffResults")
Pkg.add("Optim")
Pkg.add("QuadGK")

max_stars_repo_name: tagordon/limbdark

max_issues_repo_name: tagordon/limbdark

max_forks_repo_name: tagordon/limbdark


text:
using Jus

import Base.@kwdef

@enum Color red blue yellow green

@kwdef mutable struct Person
    name::String
    address::String
    favorite_color::Color
    working::Bool
end

const people = Person[]

function name(p::Person)
    println("GETTING NAME OF $p")
    p.name
end

function name(p::Person, value)
    println("SETTING NAME OF $p TO $value")
    p.name = string(value)
    p.address = "$(p.name)'s address"
end

favorite_color(p::Person) = p.favorite_color
function favorite_color(p::Person, color)
    println("SETTING FAVORITE COLOR OF $p TO $color")
    p.favorite_color = color
end

working(p::Person) = p.working
function working(p::Person, value)
    println("SETTING WORKING OF $p TO $value")
    p.working = value
end

Jus.start(
    Person(
        name="Fred",
        address="123",
        favorite_color=blue,
        working=false,
    );
    create_output="/tmp/gen")


text:
@testset "Utility Tests" begin

    @testset "Kernel Generating Functions" begin
        res = HawkesProcesses.generate_kernel_functions(Exponential())
        inferTests && @inferred HawkesProcesses.generate_kernel_functions(Exponential())
        @test length(res) == 2
    end

end


text:
        # isleft
        l = LineSegment2D(Point2D{T}(0, 0), Point2D{T}(1, 0))
        @test isleft(Point2D{T}(0, 1) , l)
        @test !isleft(Point2D{T}(0, -1) , l)
        @test !isleft(Point2D{T}(0, -1e-6) , l)
        @test isleft(Point2D{T}(0, 1e-6) , l)
        @test isleft(Point2D{T}(0.5, 0) , l)

        # sort_intersection_points
        l = LineSegment3D(Point3D{T}(0,0,0), Point3D{T}(10,0,0))
        p₁ = Point3D{T}(1, 0, 0)
        p₂ = Point3D{T}(2, 0, 0)
        p₃ = Point3D{T}(3, 0, 0)
        points = [p₃, p₁, p₂, Point3D{T}(1 + 1//1000000, 0, 0)]
        sort_intersection_points!(l, points)
        @test points[1] == p₁
        @test points[2] == p₂
        @test points[3] == p₃

max_stars_repo_name: khurrumsaleem/MOCNeutronTransport

max_issues_repo_name: khurrumsaleem/MOCNeutronTransport

max_forks_repo_name: khurrumsaleem/MOCNeutronTransport


text:
const PyExc_JuliaError__ref = Ref(PyNULL)
PyExc_JuliaError() = begin
    ptr = PyExc_JuliaError__ref[]
    if isnull(ptr)
        c = []
        t = fill(
            PyType_Create(
                c,
                name = "juliaaa.Error",
                base = PyExc_BaseException(),
                str = pyjlerr_str,
            ),
        )
        ptr = PyPtr(pointer(t))
        err = PyType_Ready(ptr)
        ism1(err) && return PyNULL
        PYJLGCCACHE[ptr] = push!(c, t)
        PyExc_JuliaError__ref[] = ptr
    end
    ptr
end

PyErr_SetJuliaError(err, bt = nothing) = begin
    t = PyExc_JuliaError()
    if isnull(t)
        PyErr_Clear()
        PyErr_SetString(
            PyExc_Exception(),
            "Julia error: $err (an error occurred while setting this error)",
        )
    else
        if bt === nothing
            bt = catch_backtrace()
        end
        v = PyJuliaValue_From((err, bt))
        if isnull(v)
            PyErr_Clear()
            PyErr_SetString(t, string(err))
        else
            PyErr_SetObject(t, v)
            Py_DecRef(v)
        end
    end
end

PyErr_SetStringFromJuliaError(t, err) = begin
    io = IOBuffer()
    showerror(io, err)
    msg = String(take!(io))
    PyErr_SetString(t, "Julia: $msg")
end

pyjlerr_str(xo::PyPtr) = begin
    args = PyObject_GetAttrString(xo, "args")
    isnull(args) && return PyNULL
    r = PyObject_TryConvert(args, Tuple{Union{String,Tuple}})
    r == -1 && (Py_DecRef(args); return PyNULL)
    r == 0 && @goto fallback
    (x,) = takeresult(Tuple{Union{String,Tuple}})
    if x isa String
        Py_DecRef(args)
        return PyUnicode_From(x)
    elseif x isa Tuple{Exception,Any}
        Py_DecRef(args)
        io = IOBuffer()
        showerror(io, x[1])
        msg = String(take!(io))
        return PyUnicode_From(msg)
    end

    @label fallback
    so = PyObject_Str(args)
    Py_DecRef(args)
    return so
end


text:
;; This file declares the various types used by intrinsic/prelude definitions
;; It is sort of special in that it doesn't care whether there are any associated definitions
;; just that there are type definitions for that particular binding's name

;; Type definitions
deftype String (Vector Char)

deftype (Int) Intrinsic

deftype (Float) Intrinsic

deftype (Char) Intrinsic

deftype (Byte) Intrinsic

deftype (Void) Intrinsic

deftype (IO a) Intrinsic

deftype (Vector a) Intrinsic

deftype (List a)
  (Empty |
   (Cons a (List a)))

deftype (Bottom)
  Undefined

deftype (Maybe a)
  (Nothing |
   (Just a))

deftype (Either a b)
  ((Left a) |
   (Right b))

;; List functions

(: :: (a -> (List a) -> (List a)))

(map :: ((a -> b) -> (List a) -> (List b)))

(head :: ((List a) -> a))

(tail :: ((List a) -> (List a)))

(!! :: (Int -> (List a) -> a))

(take :: (Int -> (List a) -> (Maybe (List a))))

(drop :: (Int -> (List a) -> (Maybe (List a))))

;; Optional functions

(maybe :: (b -> (a -> b) -> (Maybe a) -> b))

(either :: ((b -> c) -> (b -> c) -> (Either a b) -> c))

;; I/O functions

(print :: (String -> (IO Void)))

;; Operator definitions

defop 1 Left (a + b)
  (add a b)

defop 1 Left (a - b)
  (minus a b)

defop 2 Left (a * b)
  (mul a b)

defop 2 Left (a / b)
  (div a b)

defop 2 Right (a ^ b)
  (pow a b)

defop 3 Left (a ++ b)
  (listConcat a b)

defop 3 Left (a == b)
  (eq a b)

defop 3 Left (a > b)
  (gt a b)

defop 3 Left (a >= b)
  (gte a b)

defop 3 Left (a < b)
  (lt a b)

defop 3 Left (a <= b)
  (lte a b)

defop 3 Left (a && b)
  (and a b)

defop 3 Left (a || b)
  (or a b)

defop 4 Left (x : xs)
  (cons x xs)

defop 5 Left (f $ x)
  (fapply f x)

defop 5 Left (f . g)
  (compose f g)

defop 3 Left (a | b)
  (bitwiseOr a b)

defop 3 Left (a & b)
  (bitwiseAnd a b)


text:
module modelscf

export Ham, Atoms, andersonMixOptions
export eigOptions, scfOptions, init_pot!, scf!, get_force!
export hartree_pot_bc, time_evolution, velocity_verlet, update_pot!

include("Atoms.jl")
include("scfOptions.jl")
include("anderson_mix.jl")
include("kerker_mix.jl")
include("Ham.jl")
include("hartree_pot_bc.jl")
include("pseudocharge.jl")
include("getocc.jl")
include("Integrators.jl")

end

max_stars_repo_name: Forgotten/modelscf

max_issues_repo_name: Forgotten/modelscf

max_forks_repo_name: Forgotten/modelscf


text:
#LASSO
using JuMP
using Gurobi
using StatsBase
using DataFrames
using CSV
using Bootstrap #External packages, must be added
include("SupportFunction.jl")
include("DataLoad.jl")
println("Leeeeroooy Jenkins")

#Esben's path
#cd("$(homedir())/Documents/GitHub/Thesis/Data")
#path = "$(homedir())/Documents/GitHub/Thesis/Data"

# loopArr row = iteration
# boolean column: raw, time, exp, ta
#loopArr = zeros(1,4)

function runLassos(raw, time, exp, TA)
	#Skipper's path
	path = "/Users/SkipperAfRosenborg/Google Drive/DTU/10. Semester/Thesis/GitHubCode/Thesis/Data"
	#path = "/zhome/9f/d/88706/SpecialeCode/Thesis/Data"
	#mainData = loadIndexDataNoDur(path)
	mainData = loadIndexDataNoDurVIX(path)
	mainDataArr = Array(mainData)

	colNames = names(mainData)

	nRows = size(mainDataArr)[1]
	nCols = size(mainDataArr)[2]

	fileName = path*"/Results/IndexData/LassoTests/240-1/2401_Shrink_"
	#Reset HPC path
	#path = "/zhome/9f/d/88706/SpecialeCode/Thesis/ML"
	#cd(path)

	mainXarr = mainDataArr[:,1:nCols-1]
	if raw == 1
		fileName = fileName*"Raw"
		mainXarr = mainXarr[:,1:10]
	else
		fileName = fileName*"Macro"
	end

	mainYarr = mainDataArr[:, nCols:nCols]

	# Transform with time elements
	if time == 1
		fileName = fileName*"Time"
		mainXarr = expandWithTime3612(mainXarr)
	end

	# Transform #
	if exp == 1
		fileName = fileName*"Exp"
		mainXarr = expandWithTransformations(mainXarr)
	end

	if TA == 1
		fileName = fileName*"TA"
		mainXarr = expandWithMAandMomentum(mainXarr, mainYarr, (nCols-1))
	end

	# Standardize
	standX = zScoreByColumn(mainXarr)
	standY =mainDataArr[:, nCols:nCols]
	allData = hcat(standX, standY)
	bCols = size(standX)[2]
	nRows = size(standX)[1]
	println(" \n \n \nSolving Convex \n \n \n")

	fileName = fileName*"_"

	println(fileName)

	function solveLasso(Xtrain, Ytrain, Xpred, Ypred, gamma)
		bCols = size(Xtrain)[2]
		M = JuMP.Model(solver = GurobiSolver(OutputFlag = 0))
		@variables M begin
		        b[1:bCols]
		        t[1:bCols]
		        w
		end
		@objective(M,Min,0.5*w+gamma*ones(bCols)'*t)
		@constraint(M, soc, norm( [1-w;2*(Xtrain*b-Ytrain)] ) <= 1+w)
		@constraint(M,  b .<= t)
		@constraint(M, -t .<= b)

		solve(M)
		bSolved = getvalue(b)

		for i in 1:length(bSolved)
			if bSolved[i] <= 1e-6
				if bSolved[i] >= -1e-6
					bSolved[i] = 0
				end
			end
		end

		k = countnz(bSolved)

		#In-Sample R-squared value
		errors = (Ytrain-Xtrain*bSolved)
		errorTotal = sum(errors[i]^2 for i=1:length(errors))
		errorsMean = Ytrain-mean(Ytrain)
		errorMeanTotal = sum(errorsMean[i]^2 for i=1:length(errorsMean))
		ISRsquared = 1-(errorTotal/errorMeanTotal)

		#Indicator Results
		YpredValue = Ypred[1]
		Yestimate = Xpred*bSolved
		YestimateValue = Yestimate[1]
		if YpredValue >= 0 && YestimateValue >= 0
			Indicator = 1
		elseif YpredValue < 0 && YestimateValue < 0
			Indicator = 1
		else
			Indicator = 0
		end

		return ISRsquared, Indicator, YestimateValue, errors#, bSolved
	end

	nGammas = 10
	trainingSize = 240
	predictions = 1
	testRuns = nRows-trainingSize-predictions
	ISR = zeros(testRuns, nGammas)
	OOSR = zeros(testRuns, nGammas)
	Indi = zeros(testRuns, nGammas)
	gammaArray = logspace(0, 3, nGammas)
	predictedArr = zeros(testRuns, nGammas)
	realArr = zeros(testRuns, 1)
	bSolvedArr = zeros(testRuns, bCols)

	for r = 1:(nRows-trainingSize-predictions)
		Xtrain = allData[r:(trainingSize+r), 1:bCols]
		Ytrain = allData[r:(trainingSize+r), bCols+1]
		Xpred  = allData[(trainingSize+r+1):(trainingSize+r+predictions), 1:bCols]
		Ypred  = allData[(trainingSize+r+1):(trainingSize+r+predictions), bCols+1]
		realArr[r] = Ypred[1]

		#g=5
		for g = 1:nGammas
			gamma = gammaArray[g]
			#ISR[r, g], Indi[r, g], predictedArr[r, g], bSolvedArr[r,:] = solveLasso(Xtrain, Ytrain, Xpred, Ypred, gamma)
			ISR[r, g], Indi[r, g], predictedArr[r, g] = solveLasso(Xtrain, Ytrain, Xpred, Ypred, gamma)
		end

		if (r%100 == 0)
			println("Row $r/",(nRows-trainingSize-predictions))
		end
	end

	#=
	for r = 1:testRuns
		Xtrain = allData[(1+(r-1)*trainingSize):(trainingSize+(r-1)*trainingSize), 1:bCols]
		Ytrain = allData[(1+(r-1)*trainingSize):(trainingSize+(r-1)*trainingSize), bCols+1]
		Xpred  = allData[(trainingSize+(r-1)*trainingSize):(trainingSize+(r-1)*trainingSize+(predictions-1)), 1:bCols]
		Ypred  = allData[(trainingSize+(r-1)*trainingSize):(trainingSize+(r-1)*trainingSize+(predictions-1)), bCols+1]
		for g = 1:nGammas
			gamma = gammaArray[g]
			ISR[g, r], OOSR[g, r] = solveLasso(Xtrain, Ytrain, Xpred, Ypred, gamma)
		end
	end
	=#

	combinedArray = vcat((round.(gammaArray,3))', ISR)

	runCounter = collect(0:testRuns)
	ISRcomb = hcat(runCounter, combinedArray)
	writedlm(fileName*"ISRsquared.CSV", ISRcomb,",")

	combinedArray = vcat((round.(gammaArray,3))', Indi)
	Indicomb = hcat(runCounter, combinedArray)
	writedlm(fileName*"Indi.CSV", Indicomb,",")

	combinedArray = vcat((round.(gammaArray,3))', Indi)
	Indicomb = hcat(runCounter, combinedArray)
	writedlm(fileName*"real.CSV", realArr,",")

	combinedArray = vcat((round.(gammaArray,3))', Indi)
	Indicomb = hcat(runCounter, combinedArray)
	writedlm(fileName*"predicted.CSV", predictedArr,",")

	writedlm(fileName*"bSolved.CSV", bSolvedArr,",")

	println("Finished")
end

for raw = 0:1
	for time = 0:1
		for exp = 0:1
			for TA = 0:1
				runLassos(raw, time, exp, TA)
			end
		end
	end
end

#=
#Skipper's path
path = "/Users/SkipperAfRosenborg/Google Drive/DTU/10. Semester/Thesis/GitHubCode/Thesis/Data"
#path = "/zhome/9f/d/88706/SpecialeCode/Thesis/Data"
#mainData = loadIndexDataNoDur(path)
mainData = loadIndexDataNoDurVIX(path)
mainDataArr = Array(mainData)

colNames = names(mainData)

nRows = size(mainDataArr)[1]
nCols = size(mainDataArr)[2]

mainXarr = mainDataArr[:,1:nCols-1]
#mainXarr = mainXarr[:,1:10]

mainYarr = mainDataArr[:, nCols:nCols]

fileName = path*"/Results/IndexData/LassoTests/12-1 VIX/121_Shrink_MacroTime_"
println(fileName)
#Reset HPC path
#path = "/zhome/9f/d/88706/SpecialeCode/Thesis/ML"
#cd(path)

# Transform with time elements
mainXarr = expandWithTime3612(mainXarr)

# Transform #
#mainXarr = expandWithTransformations(mainXarr)

#mainXarr = expandWithMAandMomentum(mainXarr, mainYarr, (nCols-1))

# Standardize
standX = zScoreByColumn(mainXarr)
standY =mainDataArr[:, nCols:nCols]
allData = hcat(standX, standY)
bCols = size(standX)[2]
nRows = size(standX)[1]
println(" \n \n \nSolving Convex \n \n \n")

function solveLasso(Xtrain, Ytrain, Xpred, Ypred, gamma)
	bCols = size(Xtrain)[2]
	M = JuMP.Model(solver = GurobiSolver(OutputFlag = 0))
	@variables M begin
	        b[1:bCols]
	        t[1:bCols]
	        w
	end
	@objective(M,Min,0.5*w+gamma*ones(bCols)'*t)
	@constraint(M, soc, norm( [1-w;2*(Xtrain*b-Ytrain)] ) <= 1+w)
	@constraint(M,  b .<= t)
	@constraint(M, -t .<= b)

	solve(M)
	bSolved = getvalue(b)

	for i in 1:length(bSolved)
		if bSolved[i] <= 1e-6
			if bSolved[i] >= -1e-6
				bSolved[i] = 0
			end
		end
	end

	k = countnz(bSolved)

	#In-Sample R-squared value
	errors = (Ytrain-Xtrain*bSolved)
	errorTotal = sum(errors[i]^2 for i=1:length(errors))
	errorsMean = Ytrain-mean(Ytrain)
	errorMeanTotal = sum(errorsMean[i]^2 for i=1:length(errorsMean))
	ISRsquared = 1-(errorTotal/errorMeanTotal)

	#Indicator Results
	YpredValue = Ypred[1]
	Yestimate = Xpred*bSolved
	YestimateValue = Yestimate[1]
	if YpredValue >= 0 && YestimateValue >= 0
		Indicator = 1
	elseif YpredValue < 0 && YestimateValue < 0
		Indicator = 1
	else
		Indicator = 0
	end

	return ISRsquared, Indicator, YestimateValue#, bSolved
end

nGammas = 10
trainingSize = 12
predictions = 1
testRuns = nRows-trainingSize-predictions
ISR = zeros(testRuns, nGammas)
OOSR = zeros(testRuns, nGammas)
Indi = zeros(testRuns, nGammas)
gammaArray = logspace(0, 3, nGammas)
predictedArr = zeros(testRuns, nGammas)
realArr = zeros(testRuns, 1)
#bSolvedArr = zeros(testRuns, bCols)

for r = 1:(nRows-trainingSize-predictions)
	Xtrain = allData[r:(trainingSize+r), 1:bCols]
	Ytrain = allData[r:(trainingSize+r), bCols+1]
	Xpred  = allData[(trainingSize+r+1):(trainingSize+r+predictions), 1:bCols]
	Ypred  = allData[(trainingSize+r+1):(trainingSize+r+predictions), bCols+1]
	realArr[r] = Ypred[1]

	#ISR[r, g], OOSR[r, g], Indi[r, g], predictedArr[r, g] = solveLasso(Xtrain, Ytrain, Xpred, Ypred, gamma)
	#ISR[r, g], Indi[r, g], predictedArr[r, g], bSolvedArr[r,:] = solveLasso(Xtrain, Ytrain, Xpred, Ypred, gamma)
	#g=2
	for g = 1:nGammas
		gamma = gammaArray[g]
		#ISR[r, g], OOSR[r, g], Indi[r, g], predictedArr[r, g] = solveLasso(Xtrain, Ytrain, Xpred, Ypred, gamma)
		ISR[r, g], Indi[r, g], predictedArr[r, g] = solveLasso(Xtrain, Ytrain, Xpred, Ypred, gamma)
	end

	if (r%100 == 0)
		println("Row $r/",(nRows-trainingSize-predictions))
	end
end

combinedArray = vcat((round.(gammaArray,3))', ISR)

runCounter = collect(0:testRuns)
ISRcomb = hcat(runCounter, combinedArray)
writedlm(fileName*"ISRsquared.CSV", ISRcomb,",")

combinedArray = vcat((round.(gammaArray,3))', Indi)
Indicomb = hcat(runCounter, combinedArray)
writedlm(fileName*"Indi.CSV", Indicomb,",")

combinedArray = vcat((round.(gammaArray,3))', Indi)
Indicomb = hcat(runCounter, combinedArray)
writedlm(fileName*"real.CSV", realArr,",")

combinedArray = vcat((round.(gammaArray,3))', Indi)
Indicomb = hcat(runCounter, combinedArray)
writedlm(fileName*"predicted.CSV", predictedArr,",")

#writedlm(fileName*"bSolved.CSV", bSolvedArr,",")

println("Finished")
=#

max_stars_repo_path: ML/Code to hand in/LassoTest.jl

max_stars_repo_name: skipperafrosenborg/Thesis

max_issues_repo_path: ML/Code to hand in/LassoTest.jl

max_issues_repo_name: skipperafrosenborg/Thesis

max_forks_repo_path: ML/Code to hand in/LassoTest.jl

max_forks_repo_name: skipperafrosenborg/Thesis


text:
# # Schelling's segregation model

# ```@raw html
# <video width="auto" controls autoplay loop>
# <source src="../schelling.mp4" type="video/mp4">
# </video>
# ```

# In this introductory example we demonstrate Agents.jl's architecture and
# features through building
# the following definition of Schelling's segregation model:

# * Agents belong to one of two groups (0 or 1).
# * The agents live in a two-dimensional grid with a Chebyshev metric.
#   This leads to 8 neighboring positions per position (except at the edges of the grid).
# * Each position of the grid can be occupied by at most one agent.
# * If an agent has at least `3` neighbors belonging to the same group, then it is happy.
# * If an agent is unhappy, it keeps moving to new locations until it is happy.

# Schelling's model shows that even small preferences of agents to have neighbors
# belonging to the same group (e.g. preferring that at least 3/8 of neighbors to
# be in the same group) could lead to total segregation of neighborhoods.

# This model is also available as [`Models.schelling`](@ref).

# ## Creating a space

# For this example, we will be using a Chebyshev 2D grid, e.g.

using Agents

space = GridSpace((10, 10); periodic = false)

# Agents belonging in this type of space must have a position field that is a
# `NTuple{2, Int}`. We ensure this below.

# ## Defining the agent type

mutable struct SchellingAgent <: AbstractAgent
    id::Int             # The identifier number of the agent
    pos::NTuple{2, Int} # The x, y location of the agent on a 2D grid
    mood::Bool          # whether the agent is happy in its position. (true = happy)
    group::Int          # The group of the agent, determines mood as it interacts with neighbors
end

# We added two more fields for this model, namely a `mood` field which will
# store `true` for a happy agent and `false` for an unhappy one, and an `group`
# field which stores `0` or `1` representing two groups.

# Notice also that we could have taken advantage of the macro [`@agent`](@ref) (and in
# fact, this is recommended), and defined the same agent as:
# ```julia
# @agent SchellingAgent GridAgent{2} begin
#     mood::Bool
#     group::Int
# end
# ```

# ## Creating an ABM

# To make our model we follow the instructions of [`AgentBasedModel`](@ref).
# We also want to include a property `min_to_be_happy` in our model, and so we have:

properties = Dict(:min_to_be_happy => 3)
schelling = ABM(SchellingAgent, space; properties)

# Here we used the default scheduler (which is also the fastest one) to create
# the model. We could instead try to activate the agents according to their
# property `:group`, so that all agents of group 1 act first.
# We would then use the scheduler [`Schedulers.by_property`](@ref) like so:

schelling2 = ABM(
    SchellingAgent,
    space;
    properties = properties,
    scheduler = Schedulers.by_property(:group),
)

# Notice that `Schedulers.by_property` accepts an argument and returns a function,
# which is why we didn't just give `Schedulers.by_property` to `scheduler`.

# ## Creating the ABM through a function

# Here we put the model instantiation in a function so that
# it will be easy to recreate the model and change its parameters.

# In addition, inside this function, we populate the model with some agents.
# We also change the scheduler to [`Schedulers.randomly`](@ref).
# Because the function is defined based on keywords,
# it will be of further use in [`paramscan`](@ref) below.

using Random # for reproducibility
function initialize(; numagents = 320, griddims = (20, 20), min_to_be_happy = 3, seed = 125)
    space = GridSpace(griddims, periodic = false)
    properties = Dict(:min_to_be_happy => min_to_be_happy)
    rng = Random.MersenneTwister(seed)
    model = ABM(
        SchellingAgent, space;
        properties, rng, scheduler = Schedulers.randomly
    )

    ## populate the model with agents, adding equal amount of the two types of agents
    ## at random positions in the model
    for n in 1:numagents
        agent = SchellingAgent(n, (1, 1), false, n < numagents / 2 ? 1 : 2)
        add_agent_single!(agent, model)
    end
    return model
end

# Notice that the position that an agent is initialized does not matter
# in this example.
# This is because we use [`add_agent_single!`](@ref), which places the agent in a random,
# empty location on the grid, thus updating its position.

# ## Defining a step function

# Finally, we define a _step_ function to determine what happens to an
# agent when activated.

function agent_step!(agent, model)
    minhappy = model.min_to_be_happy
    count_neighbors_same_group = 0
    ## For each neighbor, get group and compare to current agent's group
    ## and increment count_neighbors_same_group as appropriately.
    ## Here `nearby_agents` (with default arguments) will provide an iterator
    ## over the nearby agents one grid point away, which are at most 8.
    for neighbor in nearby_agents(agent, model)
        if agent.group == neighbor.group
            count_neighbors_same_group += 1
        end
    end
    ## After counting the neighbors, decide whether or not to move the agent.
    ## If count_neighbors_same_group is at least the min_to_be_happy, set the
    ## mood to true. Otherwise, move the agent to a random position.
    if count_neighbors_same_group ≥ minhappy
        agent.mood = true
    else
        move_agent_single!(agent, model)
    end
    return
end

# For the purpose of this implementation of Schelling's segregation model,
# we only need an agent step function.

# When defining `agent_step!`, we used some of the built-in functions of Agents.jl,
# such as [`nearby_positions`](@ref) that returns the neighboring position
# on which the agent resides, [`ids_in_position`](@ref) that returns the
# IDs of the agents on a given position, and [`move_agent_single!`](@ref) which moves
# agents to random empty position on the grid. A full list of built-in functions
# and their explanations are available in the [API](@ref) page.

# ## Stepping the model

# Let's initialize the model with 370 agents on a 20 by 20 grid.

model = initialize()

# We can advance the model one step
step!(model, agent_step!)

# Or for three steps
step!(model, agent_step!, 3)

# ## Running the model and collecting data

# We can use the [`run!`](@ref) function with keywords to run the model for
# multiple steps and collect values of our desired fields from every agent
# and put these data in a `DataFrame` object.
# We define vector of `Symbols`
# for the agent fields that we want to collect as data
adata = [:pos, :mood, :group]

model = initialize()
data, _ = run!(model, agent_step!, 5; adata)
data[1:10, :] # print only a few rows

# We could also use functions in `adata`, for example we can define
x(agent) = agent.pos[1]
model = initialize()
adata = [x, :mood, :group]
data, _ = run!(model, agent_step!, 5; adata)
data[1:10, :]

# With the above `adata` vector, we collected all agent's data.
# We can instead collect aggregated data for the agents.
# For example, let's only get the number of happy individuals, and the
# average of the "x" (not very interesting, but anyway!)
using Statistics: mean
model = initialize();
adata = [(:mood, sum), (x, mean)]
data, _ = run!(model, agent_step!, 5; adata)
data

# Other examples in the documentation are more realistic, with more meaningful
# collected data. Don't forget to use the function [`dataname`](@ref) to access the
# columns of the resulting dataframe by name.

# ## Visualizing the data

# We can use the [`abm_plot`](@ref) function to plot the distribution of agents on a
# 2D grid at every generation, via the
# [InteractiveDynamics.jl](https://juliadynamics.github.io/InteractiveDynamics.jl/dev/) package
# and the [Makie.jl](http://makie.juliaplots.org/stable/) plotting ecosystem.

# Let's color the two groups orange and blue and make one a square and the other a circle.
using InteractiveDynamics
using CairoMakie # choosing a plotting backend

groupcolor(a) = a.group == 1 ? :blue : :orange
groupmarker(a) = a.group == 1 ? :circle : :rect
figure, _ = abm_plot(model; ac = groupcolor, am = groupmarker, as = 10)
figure # returning the figure displays it

# ## Animating the evolution

# The function [`abm_video`](@ref) can be used to save an animation of the ABM into a
# video. You could of course also explicitly use `abm_plot` in a `record` loop for
# finer control over additional plot elements.

model = initialize();
abm_video(
    "schelling.mp4", model, agent_step!;
    ac = groupcolor, am = groupmarker, as = 10,
    framerate = 4, frames = 20,
    title = "Schelling's segregation model"
)

# ```@raw html
# <video width="auto" controls autoplay loop>
# <source src="../schelling.mp4" type="video/mp4">
# </video>
# ```

# ## Launching the interactive application
# Given the definitions we have already created for a normally plotting or animating the ABM
# it is almost trivial to launch an interactive application for it, through the function
# [`abm_data_exploration`](@ref).

# We define a dictionary that maps some model-level parameters to a range of potential
# values, so that we can interactively change them.
parange = Dict(:min_to_be_happy => 0:8)

# We also define the data we want to collect and interactively explore, and also
# some labels for them, for shorter names (since the defaults can get large)
adata = [(:mood, sum), (x, mean)]
alabels = ["happy", "avg. x"]

model = initialize(; numagents = 300) # fresh model, noone happy

# ```julia
# figure, adf, mdf = abm_data_exploration(
#     model, agent_step!, dummystep, parange;
#     ac = groupcolor, am = groupmarker, as = 10,
#     adata, alabels
# )
# ```
#
# ```@raw html
# <video width="100%" height="auto" controls autoplay loop>
# <source src="https://raw.githubusercontent.com/JuliaDynamics/JuliaDynamics/master/videos/agents/schelling_app.mp4?raw=true" type="video/mp4">
# </video>
# ```

# ## Ensembles and distributed computing

# We can run ensemble simulations and collect the output of every member in a single `DataFrame`.
# To that end we use the [`ensemblerun!`](@ref) function.
# The function accepts a `Vector` of ABMs, each (typically) initialized with a different
# seed and/or agent distribution. For example we can do
models = [initialize(seed = x) for x in rand(UInt8, 3)];

# and then
adf, = ensemblerun!(models, agent_step!, dummystep, 5; adata)
adf[(end - 10):end, :]

# It is possible to run the ensemble in parallel.
# For that, we should start julia with `julia -p n` where `n` is the number
# of processing cores. Alternatively, we can define the number of cores from
# within a Julia session:

# ```julia
# using Distributed
# addprocs(4)
# ```

# For distributed computing to work, all definitions must be preceded with
# `@everywhere`, e.g.

# ```julia
# using Distributed
# @everywhere using Agents
# @everywhere mutable struct SchellingAgent ...
# @everywhere agent_step!(...) = ...
# ```

# Then we can tell the `ensemblerun!` function to run the ensemble in parallel
# using the keyword `parallel = true`:

# ```julia
# adf, = ensemblerun!(models, agent_step!, dummystep, 5; adata, parallel = true)
# ```

# ## Scanning parameter ranges

# We often are interested in the effect of different parameters on the behavior of an
# agent-based model. `Agents.jl` provides the function [`paramscan`](@ref) to automatically explore
# the effect of different parameter values.

# We have already defined our model initialization function as `initialize`.
# We now also define a processing function, that returns the percentage of
# happy agents:

happyperc(moods) = count(moods) / length(moods)
adata = [(:mood, happyperc)]

parameters = Dict(
    :min_to_be_happy => collect(2:5), # expanded
    :numagents => [200, 300],         # expanded
    :griddims => (20, 20),            # not Vector = not expanded
)

adf, _ = paramscan(parameters, initialize; adata, agent_step!, n = 3)
adf

# We nicely see that the larger `:min_to_be_happy` is, the slower the convergence to
# "total happiness".


text:
using Plots
using ThreeBodyDecay
using LaTeXStrings
pyplot()

#
ms = (Jψ = 3.09, p=0.938, Bs = 5.366) # masses of the particles
# create two-body system
tbs = ThreeBodySystem(ms.Jψ, ms.p, ms.p, m0=ms.Bs;   # masses m1,m2,m3,m0
            two_jps=([   1,  1//2, 1//2,    0] .|> x2,  # twice spin
                     [ '-',   '+',  '-',  '+'])) # parities
#
# chain 2,3, i.e. (2+3): Λs with the lowest ls, LS
Pc4430_2  = DecayChainLS(2, σ->BW(σ, 4.330, 0.02); two_s = 1/2|>x2, parity='+', tbs=tbs)
Pc4430_3  = DecayChainLS(3, σ->BW(σ, 4.330, 0.02); two_s = 1/2|>x2, parity='-', tbs=tbs)
Pcs = (Pc4430_2, Pc4430_3)
#
# chain-1, i.e. (1+2): Pentaquarks with the lowest ls, LS
ggS = DecayChainLS(1, σ->1.0; two_s = 1|>x2, tbs=tbs, parity='-')
ggL = (ggS,)
#
A(σs,two_λs,cs) = sum(c*amplitude(σs,two_λs,dc) for (c, dc) in zip(cs, (Pcs..., ggL...)))
I(σs,cs) = sum(abs2(A(σs,two_λs,cs)) for two_λs in itr(tbs.two_js))
#
const cs0 = [1.0, -1.0, 20.0+0im]
I(σs) = I(σs,cs0) # set the couplings

let
    plot(size=(500,450),
        xlab=L"m_{p J/\psi}^2\,(\mathrm{GeV})", ylab=L"m_{p J/\psi}^2\,(\mathrm{GeV})")
    #
    σ3v = range(tbs.mthsq[3], tbs.sthsq[3], length=100)
    σ2v = range(tbs.mthsq[2], tbs.sthsq[2], length=100)
    cal = [inphrange((gσ1(σ2,σ3,tbs.msq),σ2,σ3), tbs) ? I([gσ1(σ2,σ3,tbs.msq),σ2,σ3]) : NaN
        for (σ2, σ3) in Iterators.product(σ2v,σ3v)]
    heatmap!(σ2v, σ3v, cal - cal', colorbar=false, c=:viridis, title="unpolarized intensity")
end

max_stars_repo_name: mmikhasenko/ThreeBodyDecay

max_issues_repo_name: mmikhasenko/ThreeBodyDecay

max_forks_repo_name: mmikhasenko/ThreeBodyDecay


text:
using Oceananigans.Grids: halo_size
using Oceananigans.AbstractOperations: Ax, Ay, GridMetricOperation
# Has to be changed when the regression data is updated

function compute_vertically_integrated_lateral_areas!(∫ᶻ_A)

    # we have to account for halos when calculating Integrated areas, in case
    # a periodic domain, where it is not guaranteed that ηₙ == ηₙ₊₁
    # 2 halos (instead of only 1) are necessary to accomodate the preconditioner

    field_grid = ∫ᶻ_A.xᶠᶜᶜ.grid
    arch = architecture(field_grid)

    Axᶠᶜᶜ = GridMetricOperation((Face, Center, Center), Ax, field_grid)
    Ayᶜᶠᶜ = GridMetricOperation((Center, Face, Center), Ay, field_grid)

    sum!(∫ᶻ_A.xᶠᶜᶜ, Axᶠᶜᶜ)
    sum!(∫ᶻ_A.yᶜᶠᶜ, Ayᶜᶠᶜ)

    fill_halo_regions!(∫ᶻ_A.xᶠᶜᶜ, arch)
    fill_halo_regions!(∫ᶻ_A.yᶜᶠᶜ, arch)

    return nothing
end

"""
Compute the vertical integrated volume flux from the bottom to ``z=0`` (i.e., linear free-surface).

```
U★ = ∫ᶻ Ax * u★ dz
V★ = ∫ᶻ Ay * v★ dz
```
"""
### Note - what we really want is RHS = divergence of the vertically integrated volume flux
###        we can optimize this a bit later to do this all in one go to save using intermediate variables.
function compute_vertically_integrated_volume_flux!(∫ᶻ_U, model)

    # Fill halo regions for predictor velocity.
    fill_halo_regions!(model.velocities, model.architecture, model.clock, fields(model))

    sum!(∫ᶻ_U.u, Ax * model.velocities.u)
    sum!(∫ᶻ_U.v, Ay * model.velocities.v)

    # We didn't include right boundaries, so...
    fill_halo_regions!(∫ᶻ_U, model.architecture, model.clock, fields(model))

    return nothing
end