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

    #= ::Package:: =#

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

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

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

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

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

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

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

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

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

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

    #= [(d + e*x)^2*(a + b*atanh(c*x^2))^2, x, 163, a^2*d^2*x + (4*a*b*e^2*x)/(3*c) - (2/9)*a*b*e^2*x^3 + (2*a*b*d^2*atan(sqrt(c)*x))/sqrt(c) - (2*a*b*e^2*atan(sqrt(c)*x))/(3*c^(3/2)) + (4*b^2*e^2*atan(sqrt(c)*x))/(3*c^(3/2)) + (im*b^2*d^2*atan(sqrt(c)*x)^2)/sqrt(c) - (im*b^2*e^2*atan(sqrt(c)*x)^2)/(3*c^(3/2)) - (2*a*b*d^2*atanh(sqrt(c)*x))/sqrt(c) - (4*b^2*e^2*atanh(sqrt(c)*x))/(3*c^(3/2)) - (b^2*d^2*atanh(sqrt(c)*x)^2)/sqrt(c) - (b^2*e^2*atanh(sqrt(c)*x)^2)/(3*c^(3/2)) + (d*e*(a + b*atanh(c*x^2))^2)/c + d*e*x^2*(a + b*atanh(c*x^2))^2 + (2*b^2*d^2*atanh(sqrt(c)*x)*log(2/(1 - sqrt(c)*x)))/sqrt(c) + (2*b^2*e^2*atanh(sqrt(c)*x)*log(2/(1 - sqrt(c)*x)))/(3*c^(3/2)) - (2*b^2*d^2*atan(sqrt(c)*x)*log(2/(1 - im*sqrt(c)*x)))/sqrt(c) + (2*b^2*e^2*atan(sqrt(c)*x)*log(2/(1 - im*sqrt(c)*x)))/(3*c^(3/2)) + (b^2*d^2*atan(sqrt(c)*x)*log(((1 + im)*(1 - sqrt(c)*x))/(1 - im*sqrt(c)*x)))/sqrt(c) - (b^2*e^2*atan(sqrt(c)*x)*log(((1 + im)*(1 - sqrt(c)*x))/(1 - im*sqrt(c)*x)))/(3*c^(3/2)) + (2*b^2*d^2*atan(sqrt(c)*x)*log(2/(1 + im*sqrt(c)*x)))/sqrt(c) - (2*b^2*e^2*atan(sqrt(c)*x)*log(2/(1 + im*sqrt(c)*x)))/(3*c^(3/2)) - (2*b^2*d^2*atanh(sqrt(c)*x)*log(2/(1 + sqrt(c)*x)))/sqrt(c) - (2*b^2*e^2*atanh(sqrt(c)*x)*log(2/(1 + sqrt(c)*x)))/(3*c^(3/2)) + (b^2*d^2*atanh(sqrt(c)*x)*log(-((2*sqrt(c)*(1 - sqrt(-c)*x))/((sqrt(-c) - sqrt(c))*(1 + sqrt(c)*x)))))/sqrt(c) + (b^2*e^2*atanh(sqrt(c)*x)*log(-((2*sqrt(c)*(1 - sqrt(-c)*x))/((sqrt(-c) - sqrt(c))*(1 + sqrt(c)*x)))))/(3*c^(3/2)) + (b^2*d^2*atanh(sqrt(c)*x)*log((2*sqrt(c)*(1 + sqrt(-c)*x))/((sqrt(-c) + sqrt(c))*(1 + sqrt(c)*x))))/sqrt(c) + (b^2*e^2*atanh(sqrt(c)*x)*log((2*sqrt(c)*(1 + sqrt(-c)*x))/((sqrt(-c) + sqrt(c))*(1 + sqrt(c)*x))))/(3*c^(3/2)) + (b^2*d^2*atan(sqrt(c)*x)*log(((1 - im)*(1 + sqrt(c)*x))/(1 - im*sqrt(c)*x)))/sqrt(c) - (b^2*e^2*atan(sqrt(c)*x)*log(((1 - im)*(1 + sqrt(c)*x))/(1 - im*sqrt(c)*x)))/(3*c^(3/2)) - (2*b*d*e*(a + b*atanh(c*x^2))*log(2/(1 - c*x^2)))/c - a*b*d^2*x*log(1 - c*x^2) - (2*b^2*e^2*x*log(1 - c*x^2))/(3*c) + (1/9)*b^2*e^2*x^3*log(1 - c*x^2) - (b^2*d^2*atan(sqrt(c)*x)*log(1 - c*x^2))/sqrt(c) + (b^2*e^2*atan(sqrt(c)*x)*log(1 - c*x^2))/(3*c^(3/2)) + (b^2*d^2*atanh(sqrt(c)*x)*log(1 - c*x^2))/sqrt(c) + (1/4)*b^2*d^2*x*log(1 - c*x^2)^2 + (1/9)*b*e^2*x^3*(2*a - b*log(1 - c*x^2)) - (b*e^2*atanh(sqrt(c)*x)*(2*a - b*log(1 - c*x^2)))/(3*c^(3/2)) + (1/12)*e^2*x^3*(2*a - b*log(1 - c*x^2))^2 + a*b*d^2*x*log(1 + c*x^2) + (2*b^2*e^2*x*log(1 + c*x^2))/(3*c) + (1/3)*a*b*e^2*x^3*log(1 + c*x^2) + (b^2*d^2*atan(sqrt(c)*x)*log(1 + c*x^2))/sqrt(c) - (b^2*e^2*atan(sqrt(c)*x)*log(1 + c*x^2))/(3*c^(3/2)) - (b^2*d^2*atanh(sqrt(c)*x)*log(1 + c*x^2))/sqrt(c) - (b^2*e^2*atanh(sqrt(c)*x)*log(1 + c*x^2))/(3*c^(3/2)) - (1/2)*b^2*d^2*x*log(1 - c*x^2)*log(1 + c*x^2) - (1/6)*b^2*e^2*x^3*log(1 - c*x^2)*log(1 + c*x^2) + (1/4)*b^2*d^2*x*log(1 + c*x^2)^2 + (1/12)*b^2*e^2*x^3*log(1 + c*x^2)^2 + (b^2*d^2*PolyLog(2, 1 - 2/(1 - sqrt(c)*x)))/sqrt(c) + (b^2*e^2*PolyLog(2, 1 - 2/(1 - sqrt(c)*x)))/(3*c^(3/2)) + (im*b^2*d^2*PolyLog(2, 1 - 2/(1 - im*sqrt(c)*x)))/sqrt(c) - (im*b^2*e^2*PolyLog(2, 1 - 2/(1 - im*sqrt(c)*x)))/(3*c^(3/2)) - (im*b^2*d^2*PolyLog(2, 1 - ((1 + im)*(1 - sqrt(c)*x))/(1 - im*sqrt(c)*x)))/(2*sqrt(c)) + (im*b^2*e^2*PolyLog(2, 1 - ((1 + im)*(1 - sqrt(c)*x))/(1 - im*sqrt(c)*x)))/(6*c^(3/2)) + (im*b^2*d^2*PolyLog(2, 1 - 2/(1 + im*sqrt(c)*x)))/sqrt(c) - (im*b^2*e^2*PolyLog(2, 1 - 2/(1 + im*sqrt(c)*x)))/(3*c^(3/2)) + (b^2*d^2*PolyLog(2, 1 - 2/(1 + sqrt(c)*x)))/sqrt(c) + (b^2*e^2*PolyLog(2, 1 - 2/(1 + sqrt(c)*x)))/(3*c^(3/2)) - (b^2*d^2*PolyLog(2, 1 + (2*sqrt(c)*(1 - sqrt(-c)*x))/((sqrt(-c) - sqrt(c))*(1 + sqrt(c)*x))))/(2*sqrt(c)) - (b^2*e^2*PolyLog(2, 1 + (2*sqrt(c)*(1 - sqrt(-c)*x))/((sqrt(-c) - sqrt(c))*(1 + sqrt(c)*x))))/(6*c^(3/2)) - (b^2*d^2*PolyLog(2, 1 - (2*sqrt(c)*(1 + sqrt(-c)*x))/((sqrt(-c) + sqrt(c))*(1 + sqrt(c)*x))))/(2*sqrt(c)) - (b^2*e^2*PolyLog(2, 1 - (2*sqrt(c)*(1 + sqrt(-c)*x))/((sqrt(-c) + sqrt(c))*(1 + sqrt(c)*x))))/(6*c^(3/2)) - (im*b^2*d^2*PolyLog(2, 1 - ((1 - im)*(1 + sqrt(c)*x))/(1 - im*sqrt(c)*x)))/(2*sqrt(c)) + (im*b^2*e^2*PolyLog(2, 1 - ((1 - im)*(1 + sqrt(c)*x))/(1 - im*sqrt(c)*x)))/(6*c^(3/2)) - (b^2*d*e*PolyLog(2, 1 - 2/(1 - c*x^2)))/c] =#
    @test_int [(d + e*x)^1*(a + b*atanh(c*x^2))^2, x, 77, a^2*d*x + (2*a*b*d*atan(sqrt(c)*x))/sqrt(c) + (im*b^2*d*atan(sqrt(c)*x)^2)/sqrt(c) - (2*a*b*d*atanh(sqrt(c)*x))/sqrt(c) - (b^2*d*atanh(sqrt(c)*x)^2)/sqrt(c) + (e*(a + b*atanh(c*x^2))^2)/(2*c) + (1/2)*e*x^2*(a + b*atanh(c*x^2))^2 + (2*b^2*d*atanh(sqrt(c)*x)*log(2/(1 - sqrt(c)*x)))/sqrt(c) - (2*b^2*d*atan(sqrt(c)*x)*log(2/(1 - im*sqrt(c)*x)))/sqrt(c) + (b^2*d*atan(sqrt(c)*x)*log(((1 + im)*(1 - sqrt(c)*x))/(1 - im*sqrt(c)*x)))/sqrt(c) + (2*b^2*d*atan(sqrt(c)*x)*log(2/(1 + im*sqrt(c)*x)))/sqrt(c) - (2*b^2*d*atanh(sqrt(c)*x)*log(2/(1 + sqrt(c)*x)))/sqrt(c) + (b^2*d*atanh(sqrt(c)*x)*log(-((2*sqrt(c)*(1 - sqrt(-c)*x))/((sqrt(-c) - sqrt(c))*(1 + sqrt(c)*x)))))/sqrt(c) + (b^2*d*atanh(sqrt(c)*x)*log((2*sqrt(c)*(1 + sqrt(-c)*x))/((sqrt(-c) + sqrt(c))*(1 + sqrt(c)*x))))/sqrt(c) + (b^2*d*atan(sqrt(c)*x)*log(((1 - im)*(1 + sqrt(c)*x))/(1 - im*sqrt(c)*x)))/sqrt(c) - (b*e*(a + b*atanh(c*x^2))*log(2/(1 - c*x^2)))/c - a*b*d*x*log(1 - c*x^2) - (b^2*d*atan(sqrt(c)*x)*log(1 - c*x^2))/sqrt(c) + (b^2*d*atanh(sqrt(c)*x)*log(1 - c*x^2))/sqrt(c) + (1/4)*b^2*d*x*log(1 - c*x^2)^2 + a*b*d*x*log(1 + c*x^2) + (b^2*d*atan(sqrt(c)*x)*log(1 + c*x^2))/sqrt(c) - (b^2*d*atanh(sqrt(c)*x)*log(1 + c*x^2))/sqrt(c) - (1/2)*b^2*d*x*log(1 - c*x^2)*log(1 + c*x^2) + (1/4)*b^2*d*x*log(1 + c*x^2)^2 + (b^2*d*PolyLog(2, 1 - 2/(1 - sqrt(c)*x)))/sqrt(c) + (im*b^2*d*PolyLog(2, 1 - 2/(1 - im*sqrt(c)*x)))/sqrt(c) - (im*b^2*d*PolyLog(2, 1 - ((1 + im)*(1 - sqrt(c)*x))/(1 - im*sqrt(c)*x)))/(2*sqrt(c)) + (im*b^2*d*PolyLog(2, 1 - 2/(1 + im*sqrt(c)*x)))/sqrt(c) + (b^2*d*PolyLog(2, 1 - 2/(1 + sqrt(c)*x)))/sqrt(c) - (b^2*d*PolyLog(2, 1 + (2*sqrt(c)*(1 - sqrt(-c)*x))/((sqrt(-c) - sqrt(c))*(1 + sqrt(c)*x))))/(2*sqrt(c)) - (b^2*d*PolyLog(2, 1 - (2*sqrt(c)*(1 + sqrt(-c)*x))/((sqrt(-c) + sqrt(c))*(1 + sqrt(c)*x))))/(2*sqrt(c)) - (im*b^2*d*PolyLog(2, 1 - ((1 - im)*(1 + sqrt(c)*x))/(1 - im*sqrt(c)*x)))/(2*sqrt(c)) - (b^2*e*PolyLog(2, 1 - 2/(1 - c*x^2)))/(2*c)]
    @test_int [(a + b*atanh(c*x^2))^2/(d + e*x)^1, x, 0, Unintegrable((a + b*atanh(c*x^2))^2/(d + e*x), x)]
    @test_int [(a + b*atanh(c*x^2))^2/(d + e*x)^2, x, 0, Unintegrable((a + b*atanh(c*x^2))^2/(d + e*x)^2, x)]

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

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

    @test_int [(d + e*x)^2*(a + b*atanh(c*x^3)), x, 24, -((sqrt(3)*b*d*e*atan(1/sqrt(3) - (2*c^(1/3)*x)/sqrt(3)))/(2*c^(2/3))) + (sqrt(3)*b*d*e*atan(1/sqrt(3) + (2*c^(1/3)*x)/sqrt(3)))/(2*c^(2/3)) + (sqrt(3)*b*d^2*atan((1 + 2*c^(2/3)*x^2)/sqrt(3)))/(2*c^(1/3)) - (b*d*e*atanh(c^(1/3)*x))/c^(2/3) + ((d + e*x)^3*(a + b*atanh(c*x^3)))/(3*e) + (b*d^2*log(1 - c^(2/3)*x^2))/(2*c^(1/3)) + (b*d*e*log(1 - c^(1/3)*x + c^(2/3)*x^2))/(4*c^(2/3)) - (b*d*e*log(1 + c^(1/3)*x + c^(2/3)*x^2))/(4*c^(2/3)) + (b*(c*d^3 + e^3)*log(1 - c*x^3))/(6*c*e) - (b*(c*d^3 - e^3)*log(1 + c*x^3))/(6*c*e) - (b*d^2*log(1 + c^(2/3)*x^2 + c^(4/3)*x^4))/(4*c^(1/3))]
    @test_int [(d + e*x)^1*(a + b*atanh(c*x^3)), x, 22, -((sqrt(3)*b*e*atan(1/sqrt(3) - (2*c^(1/3)*x)/sqrt(3)))/(4*c^(2/3))) + (sqrt(3)*b*e*atan(1/sqrt(3) + (2*c^(1/3)*x)/sqrt(3)))/(4*c^(2/3)) + (sqrt(3)*b*d*atan((1 + 2*c^(2/3)*x^2)/sqrt(3)))/(2*c^(1/3)) - (b*e*atanh(c^(1/3)*x))/(2*c^(2/3)) - (b*d^2*atanh(c*x^3))/(2*e) + ((d + e*x)^2*(a + b*atanh(c*x^3)))/(2*e) + (b*d*log(1 - c^(2/3)*x^2))/(2*c^(1/3)) + (b*e*log(1 - c^(1/3)*x + c^(2/3)*x^2))/(8*c^(2/3)) - (b*e*log(1 + c^(1/3)*x + c^(2/3)*x^2))/(8*c^(2/3)) - (b*d*log(1 + c^(2/3)*x^2 + c^(4/3)*x^4))/(4*c^(1/3))]
    @test_int [(a + b*atanh(c*x^3))/(d + e*x)^1, x, 25, ((a + b*atanh(c*x^3))*log(d + e*x))/e + (b*log((e*(1 - c^(1/3)*x))/(c^(1/3)*d + e))*log(d + e*x))/(2*e) - (b*log(-((e*(1 + c^(1/3)*x))/(c^(1/3)*d - e)))*log(d + e*x))/(2*e) + (b*log(-((e*((-1)^(1/3) + c^(1/3)*x))/(c^(1/3)*d - (-1)^(1/3)*e)))*log(d + e*x))/(2*e) - (b*log(-((e*((-1)^(2/3) + c^(1/3)*x))/(c^(1/3)*d - (-1)^(2/3)*e)))*log(d + e*x))/(2*e) + (b*log(((-1)^(2/3)*e*(1 + (-1)^(1/3)*c^(1/3)*x))/(c^(1/3)*d + (-1)^(2/3)*e))*log(d + e*x))/(2*e) - (b*log(((-1)^(1/3)*e*(1 + (-1)^(2/3)*c^(1/3)*x))/(c^(1/3)*d + (-1)^(1/3)*e))*log(d + e*x))/(2*e) - (b*PolyLog(2, (c^(1/3)*(d + e*x))/(c^(1/3)*d - e)))/(2*e) + (b*PolyLog(2, (c^(1/3)*(d + e*x))/(c^(1/3)*d + e)))/(2*e) + (b*PolyLog(2, (c^(1/3)*(d + e*x))/(c^(1/3)*d - (-1)^(1/3)*e)))/(2*e) - (b*PolyLog(2, (c^(1/3)*(d + e*x))/(c^(1/3)*d + (-1)^(1/3)*e)))/(2*e) - (b*PolyLog(2, (c^(1/3)*(d + e*x))/(c^(1/3)*d - (-1)^(2/3)*e)))/(2*e) + (b*PolyLog(2, (c^(1/3)*(d + e*x))/(c^(1/3)*d + (-1)^(2/3)*e)))/(2*e)]
    @test_int [(a + b*atanh(c*x^3))/(d + e*x)^2, x, 19, -((sqrt(3)*b*c^(1/3)*atan((1 - 2*c^(1/3)*x)/sqrt(3)))/(2*(c^(2/3)*d^2 + c^(1/3)*d*e + e^2))) - (sqrt(3)*b*c^(1/3)*(c^(1/3)*d + e)*atan((1 + 2*c^(1/3)*x)/sqrt(3)))/(2*(c*d^3 + e^3)) - (a + b*atanh(c*x^3))/(e*(d + e*x)) + (b*c^(1/3)*(c^(1/3)*d - e)*log(1 - c^(1/3)*x))/(2*(c*d^3 + e^3)) + (b*c^(1/3)*(c^(1/3)*d + e)*log(1 + c^(1/3)*x))/(2*(c*d^3 - e^3)) - (3*b*c*d^2*e^2*log(d + e*x))/(c^2*d^6 - e^6) - (b*c^(1/3)*(c^(1/3)*d + e)*log(1 - c^(1/3)*x + c^(2/3)*x^2))/(4*(c*d^3 - e^3)) - (b*c^(1/3)*(c^(1/3)*d - e)*log(1 + c^(1/3)*x + c^(2/3)*x^2))/(4*(c*d^3 + e^3)) - (b*c*d^2*log(1 - c*x^3))/(2*e*(c*d^3 + e^3)) + (b*c*d^2*log(1 + c*x^3))/(2*e*(c*d^3 - e^3))]

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

    @test_int [x^3*(a + b*atanh(c*sqrt(x)))/(1 - c^2*x), x, 19, -((11*b*sqrt(x))/(6*c^7)) - (5*b*x^(3/2))/(18*c^5) - (b*x^(5/2))/(15*c^3) + (11*b*atanh(c*sqrt(x)))/(6*c^8) - (x*(a + b*atanh(c*sqrt(x))))/c^6 - (x^2*(a + b*atanh(c*sqrt(x))))/(2*c^4) - (x^3*(a + b*atanh(c*sqrt(x))))/(3*c^2) - (a + b*atanh(c*sqrt(x)))^2/(b*c^8) + (2*(a + b*atanh(c*sqrt(x)))*log(2/(1 - c*sqrt(x))))/c^8 + (b*PolyLog(2, 1 - 2/(1 - c*sqrt(x))))/c^8]
    @test_int [x^2*(a + b*atanh(c*sqrt(x)))/(1 - c^2*x), x, 14, -((3*b*sqrt(x))/(2*c^5)) - (b*x^(3/2))/(6*c^3) + (3*b*atanh(c*sqrt(x)))/(2*c^6) - (x*(a + b*atanh(c*sqrt(x))))/c^4 - (x^2*(a + b*atanh(c*sqrt(x))))/(2*c^2) - (a + b*atanh(c*sqrt(x)))^2/(b*c^6) + (2*(a + b*atanh(c*sqrt(x)))*log(2/(1 - c*sqrt(x))))/c^6 + (b*PolyLog(2, 1 - 2/(1 - c*sqrt(x))))/c^6]
    @test_int [x^1*(a + b*atanh(c*sqrt(x)))/(1 - c^2*x), x, 9, -((b*sqrt(x))/c^3) + (b*atanh(c*sqrt(x)))/c^4 - (x*(a + b*atanh(c*sqrt(x))))/c^2 - (a + b*atanh(c*sqrt(x)))^2/(b*c^4) + (2*(a + b*atanh(c*sqrt(x)))*log(2/(1 - c*sqrt(x))))/c^4 + (b*PolyLog(2, 1 - 2/(1 - c*sqrt(x))))/c^4]
    @test_int [x^0*(a + b*atanh(c*sqrt(x)))/(1 - c^2*x), x, 5, -((a + b*atanh(c*sqrt(x)))^2/(b*c^2)) + (2*(a + b*atanh(c*sqrt(x)))*log(2/(1 - c*sqrt(x))))/c^2 + (b*PolyLog(2, 1 - 2/(1 - c*sqrt(x))))/c^2]
    @test_int [(a + b*atanh(c*sqrt(x)))/(x^1*(1 - c^2*x)), x, 5, (a + b*atanh(c*sqrt(x)))^2/b + 2*(a + b*atanh(c*sqrt(x)))*log(2 - 2/(1 + c*sqrt(x))) - b*PolyLog(2, -1 + 2/(1 + c*sqrt(x)))]
    @test_int [(a + b*atanh(c*sqrt(x)))/(x^2*(1 - c^2*x)), x, 9, -((b*c)/sqrt(x)) + b*c^2*atanh(c*sqrt(x)) - (a + b*atanh(c*sqrt(x)))/x + (c^2*(a + b*atanh(c*sqrt(x)))^2)/b + 2*c^2*(a + b*atanh(c*sqrt(x)))*log(2 - 2/(1 + c*sqrt(x))) - b*c^2*PolyLog(2, -1 + 2/(1 + c*sqrt(x)))]
    @test_int [(a + b*atanh(c*sqrt(x)))/(x^3*(1 - c^2*x)), x, 14, -((b*c)/(6*x^(3/2))) - (3*b*c^3)/(2*sqrt(x)) + (3/2)*b*c^4*atanh(c*sqrt(x)) - (a + b*atanh(c*sqrt(x)))/(2*x^2) - (c^2*(a + b*atanh(c*sqrt(x))))/x + (c^4*(a + b*atanh(c*sqrt(x)))^2)/b + 2*c^4*(a + b*atanh(c*sqrt(x)))*log(2 - 2/(1 + c*sqrt(x))) - b*c^4*PolyLog(2, -1 + 2/(1 + c*sqrt(x)))]
    @test_int [(a + b*atanh(c*sqrt(x)))/(x^4*(1 - c^2*x)), x, 20, -((b*c)/(15*x^(5/2))) - (5*b*c^3)/(18*x^(3/2)) - (11*b*c^5)/(6*sqrt(x)) + (11/6)*b*c^6*atanh(c*sqrt(x)) - (a + b*atanh(c*sqrt(x)))/(3*x^3) - (c^2*(a + b*atanh(c*sqrt(x))))/(2*x^2) - (c^4*(a + b*atanh(c*sqrt(x))))/x + (c^6*(a + b*atanh(c*sqrt(x)))^2)/b + 2*c^6*(a + b*atanh(c*sqrt(x)))*log(2 - 2/(1 + c*sqrt(x))) - b*c^6*PolyLog(2, -1 + 2/(1 + c*sqrt(x)))]

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

    @test_int [x^2*(a + b*atanh(c*sqrt(x)))/(d + e*x), x, 20, -((b*d*sqrt(x))/(c*e^2)) + (b*sqrt(x))/(2*c^3*e) + (b*x^(3/2))/(6*c*e) + (b*d*atanh(c*sqrt(x)))/(c^2*e^2) - (b*atanh(c*sqrt(x)))/(2*c^4*e) - (d*x*(a + b*atanh(c*sqrt(x))))/e^2 + (x^2*(a + b*atanh(c*sqrt(x))))/(2*e) - (2*d^2*(a + b*atanh(c*sqrt(x)))*log(2/(1 + c*sqrt(x))))/e^3 + (d^2*(a + b*atanh(c*sqrt(x)))*log((2*c*(sqrt(-d) - sqrt(e)*sqrt(x)))/((c*sqrt(-d) - sqrt(e))*(1 + c*sqrt(x)))))/e^3 + (d^2*(a + b*atanh(c*sqrt(x)))*log((2*c*(sqrt(-d) + sqrt(e)*sqrt(x)))/((c*sqrt(-d) + sqrt(e))*(1 + c*sqrt(x)))))/e^3 + (b*d^2*PolyLog(2, 1 - 2/(1 + c*sqrt(x))))/e^3 - (b*d^2*PolyLog(2, 1 - (2*c*(sqrt(-d) - sqrt(e)*sqrt(x)))/((c*sqrt(-d) - sqrt(e))*(1 + c*sqrt(x)))))/(2*e^3) - (b*d^2*PolyLog(2, 1 - (2*c*(sqrt(-d) + sqrt(e)*sqrt(x)))/((c*sqrt(-d) + sqrt(e))*(1 + c*sqrt(x)))))/(2*e^3)]
    @test_int [x^1*(a + b*atanh(c*sqrt(x)))/(d + e*x), x, 15, (b*sqrt(x))/(c*e) - (b*atanh(c*sqrt(x)))/(c^2*e) + (x*(a + b*atanh(c*sqrt(x))))/e + (2*d*(a + b*atanh(c*sqrt(x)))*log(2/(1 + c*sqrt(x))))/e^2 - (d*(a + b*atanh(c*sqrt(x)))*log((2*c*(sqrt(-d) - sqrt(e)*sqrt(x)))/((c*sqrt(-d) - sqrt(e))*(1 + c*sqrt(x)))))/e^2 - (d*(a + b*atanh(c*sqrt(x)))*log((2*c*(sqrt(-d) + sqrt(e)*sqrt(x)))/((c*sqrt(-d) + sqrt(e))*(1 + c*sqrt(x)))))/e^2 - (b*d*PolyLog(2, 1 - 2/(1 + c*sqrt(x))))/e^2 + (b*d*PolyLog(2, 1 - (2*c*(sqrt(-d) - sqrt(e)*sqrt(x)))/((c*sqrt(-d) - sqrt(e))*(1 + c*sqrt(x)))))/(2*e^2) + (b*d*PolyLog(2, 1 - (2*c*(sqrt(-d) + sqrt(e)*sqrt(x)))/((c*sqrt(-d) + sqrt(e))*(1 + c*sqrt(x)))))/(2*e^2)]
    @test_int [x^0*(a + b*atanh(c*sqrt(x)))/(d + e*x), x, 11, -((2*(a + b*atanh(c*sqrt(x)))*log(2/(1 + c*sqrt(x))))/e) + ((a + b*atanh(c*sqrt(x)))*log((2*c*(sqrt(-d) - sqrt(e)*sqrt(x)))/((c*sqrt(-d) - sqrt(e))*(1 + c*sqrt(x)))))/e + ((a + b*atanh(c*sqrt(x)))*log((2*c*(sqrt(-d) + sqrt(e)*sqrt(x)))/((c*sqrt(-d) + sqrt(e))*(1 + c*sqrt(x)))))/e + (b*PolyLog(2, 1 - 2/(1 + c*sqrt(x))))/e - (b*PolyLog(2, 1 - (2*c*(sqrt(-d) - sqrt(e)*sqrt(x)))/((c*sqrt(-d) - sqrt(e))*(1 + c*sqrt(x)))))/(2*e) - (b*PolyLog(2, 1 - (2*c*(sqrt(-d) + sqrt(e)*sqrt(x)))/((c*sqrt(-d) + sqrt(e))*(1 + c*sqrt(x)))))/(2*e)]
    @test_int [(a + b*atanh(c*sqrt(x)))/(x^1*(d + e*x)), x, 15, (2*(a + b*atanh(c*sqrt(x)))*log(2/(1 + c*sqrt(x))))/d - ((a + b*atanh(c*sqrt(x)))*log((2*c*(sqrt(-d) - sqrt(e)*sqrt(x)))/((c*sqrt(-d) - sqrt(e))*(1 + c*sqrt(x)))))/d - ((a + b*atanh(c*sqrt(x)))*log((2*c*(sqrt(-d) + sqrt(e)*sqrt(x)))/((c*sqrt(-d) + sqrt(e))*(1 + c*sqrt(x)))))/d + (a*log(x))/d - (b*PolyLog(2, 1 - 2/(1 + c*sqrt(x))))/d + (b*PolyLog(2, 1 - (2*c*(sqrt(-d) - sqrt(e)*sqrt(x)))/((c*sqrt(-d) - sqrt(e))*(1 + c*sqrt(x)))))/(2*d) + (b*PolyLog(2, 1 - (2*c*(sqrt(-d) + sqrt(e)*sqrt(x)))/((c*sqrt(-d) + sqrt(e))*(1 + c*sqrt(x)))))/(2*d) - (b*PolyLog(2, (-c)*sqrt(x)))/d + (b*PolyLog(2, c*sqrt(x)))/d]
    @test_int [(a + b*atanh(c*sqrt(x)))/(x^2*(d + e*x)), x, 19, -((b*c)/(d*sqrt(x))) + (b*c^2*atanh(c*sqrt(x)))/d - (a + b*atanh(c*sqrt(x)))/(d*x) - (2*e*(a + b*atanh(c*sqrt(x)))*log(2/(1 + c*sqrt(x))))/d^2 + (e*(a + b*atanh(c*sqrt(x)))*log((2*c*(sqrt(-d) - sqrt(e)*sqrt(x)))/((c*sqrt(-d) - sqrt(e))*(1 + c*sqrt(x)))))/d^2 + (e*(a + b*atanh(c*sqrt(x)))*log((2*c*(sqrt(-d) + sqrt(e)*sqrt(x)))/((c*sqrt(-d) + sqrt(e))*(1 + c*sqrt(x)))))/d^2 - (a*e*log(x))/d^2 + (b*e*PolyLog(2, 1 - 2/(1 + c*sqrt(x))))/d^2 - (b*e*PolyLog(2, 1 - (2*c*(sqrt(-d) - sqrt(e)*sqrt(x)))/((c*sqrt(-d) - sqrt(e))*(1 + c*sqrt(x)))))/(2*d^2) - (b*e*PolyLog(2, 1 - (2*c*(sqrt(-d) + sqrt(e)*sqrt(x)))/((c*sqrt(-d) + sqrt(e))*(1 + c*sqrt(x)))))/(2*d^2) + (b*e*PolyLog(2, (-c)*sqrt(x)))/d^2 - (b*e*PolyLog(2, c*sqrt(x)))/d^2]
    @test_int [(a + b*atanh(c*sqrt(x)))/(x^3*(d + e*x)), x, 24, -((b*c)/(6*d*x^(3/2))) - (b*c^3)/(2*d*sqrt(x)) + (b*c*e)/(d^2*sqrt(x)) + (b*c^4*atanh(c*sqrt(x)))/(2*d) - (b*c^2*e*atanh(c*sqrt(x)))/d^2 - (a + b*atanh(c*sqrt(x)))/(2*d*x^2) + (e*(a + b*atanh(c*sqrt(x))))/(d^2*x) + (2*e^2*(a + b*atanh(c*sqrt(x)))*log(2/(1 + c*sqrt(x))))/d^3 - (e^2*(a + b*atanh(c*sqrt(x)))*log((2*c*(sqrt(-d) - sqrt(e)*sqrt(x)))/((c*sqrt(-d) - sqrt(e))*(1 + c*sqrt(x)))))/d^3 - (e^2*(a + b*atanh(c*sqrt(x)))*log((2*c*(sqrt(-d) + sqrt(e)*sqrt(x)))/((c*sqrt(-d) + sqrt(e))*(1 + c*sqrt(x)))))/d^3 + (a*e^2*log(x))/d^3 - (b*e^2*PolyLog(2, 1 - 2/(1 + c*sqrt(x))))/d^3 + (b*e^2*PolyLog(2, 1 - (2*c*(sqrt(-d) - sqrt(e)*sqrt(x)))/((c*sqrt(-d) - sqrt(e))*(1 + c*sqrt(x)))))/(2*d^3) + (b*e^2*PolyLog(2, 1 - (2*c*(sqrt(-d) + sqrt(e)*sqrt(x)))/((c*sqrt(-d) + sqrt(e))*(1 + c*sqrt(x)))))/(2*d^3) - (b*e^2*PolyLog(2, (-c)*sqrt(x)))/d^3 + (b*e^2*PolyLog(2, c*sqrt(x)))/d^3]
    end

max_stars_repo_path: test/7 Inverse hyperbolic functions/7.3 Inverse hyperbolic tangent/7.3.3 (d+e x)^m (a+b arctanh(c x^n))^p.jl


text:
# fashion mnist mlp
#
# reference: https://github.com/FluxML/model-zoo/blob/master/mnist/mlp.jl

using Flux
using Flux: onehotbatch, argmax, crossentropy, throttle, @epochs
using BSON: @save, @load
using Base.Iterators: repeated

using MLDatasets # FashionMNIST
using ColorTypes: N0f8, Gray

const Img = Matrix{Gray{N0f8}}

function prepare_train()
    # load full training set
    train_x, train_y = FashionMNIST.traindata() # 60_000

    trainrange = 1:6_000 # 1:60_000
    imgs = Img.([train_x[:,:,i] for i in trainrange])
    # Stack images into one large batch
    X = hcat(float.(reshape.(imgs, :))...) |> gpu
    # One-hot-encode the labels
    Y = onehotbatch(train_y[trainrange], 0:9) |> gpu
    X, Y
end

function prepare_test()
    # load full test set
    test_x,  test_y  = FashionMNIST.testdata() # 10_000

    testrange = 1:1_000 # 1:10_000
    test_imgs = Img.([test_x[:,:,i] for i in testrange])
    tX = hcat(float.(reshape.(test_imgs, :))...) |> gpu
    tY = onehotbatch(test_y[testrange], 0:9) |> gpu
    tX, tY
end

X, Y = prepare_train()
tX, tY = prepare_test()

m = Chain(
  Dense(28^2, 32, relu),
  Dense(32, 10),
  softmax) |> gpu

loss(x, y) = crossentropy(m(x), y)

accuracy(x, y) = mean(argmax(m(x)) .== argmax(y))

dataset = repeated((X, Y), 200)
evalcb = () -> @show(loss(X, Y))
opt = ADAM(params(m))

@epochs 5 Flux.train!(loss, dataset, opt, cb = throttle(evalcb, 2))

accuracy(X, Y)
# 0.983

accuracy(tX, tY)
# 0.83

# @save "fashion_mnist_mlp_model.bson" m
# weights = Tracker.data.(params(m)) ;
# @save "fashion_mnist_mlp_weights.bson" weights

ext: jl


text:
module Ion

using Comonicon

export patch, minor, major, current

include("internal.jl")
include("repl.jl")

const CASTED_COMMANDS = Internal.CASTED_COMMANDS

"""
CLI&REPL toolkit for managing/developing
Julia project & packages.
"""
@main

end


text:
@testset "Searches" begin
    @testset "Searches: Binary" begin
        sample = [0, 23, 52, 552, 555, 602, 1004]
        reversed_sample = reverse(sample)
        unsorted_sample = [124, 53, 21, 163]
        binarysearch(sample, 52)
        binarysearch(reversed_sample, 52, rev=true)
        @test_throws ErrorException binarysearch(unsorted_sample, 21)  # throws an error
    end

    @testset "Searches: Linear" begin
        array = [1,3,4,7,8,11]
        search(array, 3)
        search(array, 8)
        search(array, 12)
    end

end

max_stars_repo_name: madisonestabrook/Julia

max_issues_repo_name: madisonestabrook/Julia

max_forks_repo_name: madisonestabrook/Julia


text:
using Test
using MPI
using LinearAlgebra

MPI.Init()

comm = MPI.COMM_WORLD
size = MPI.Comm_size(comm)
rank = MPI.Comm_rank(comm)

dst = mod(rank+1, size)
src = mod(rank-1, size)

N = 32

send_mesg = Array{Float64}(undef,N)
recv_mesg = Array{Float64}(undef,N)
recv_mesg_expected = Array{Float64}(undef,N)

fill!(send_mesg, Float64(rank))
fill!(recv_mesg_expected, Float64(src))

rreq = MPI.Irecv!(recv_mesg, src,  src+32, comm)
sreq = MPI.Isend(send_mesg, dst, rank+32, comm)

stats = MPI.Waitall!([sreq, rreq])
@test isequal(typeof(rreq), typeof(MPI.REQUEST_NULL))
@test isequal(typeof(sreq), typeof(MPI.REQUEST_NULL))
@test MPI.Get_source(stats[2]) == src
@test MPI.Get_tag(stats[2]) == src+32
@test isapprox(norm(recv_mesg-recv_mesg_expected), 0.0)

global (done, stats) = MPI.Testall!([sreq, rreq])
@test done
rreq = nothing
sreq = nothing
GC.gc()

if rank == 0
    MPI.send(send_mesg, dst, rank+32, comm)
    recv_mesg = recv_mesg_expected
elseif rank == size-1
    (recv_mesg, _) = MPI.recv(src, src+32, comm)
else
    (recv_mesg, _) = MPI.recv(src, src+32, comm)
    MPI.send(send_mesg, dst, rank+32, comm)
end

@test isapprox(norm(recv_mesg-recv_mesg_expected), 0.0)

rreq = nothing
sreq = nothing
GC.gc()

if rank == 0
    MPI.send(send_mesg, dst, rank+32, comm)
    recv_mesg = recv_mesg_expected
elseif rank == size-1
    (recv_mesg, _) = MPI.recv(src, src+32, comm)
else
    (recv_mesg, _) = MPI.recv(src, src+32, comm)
    MPI.send(send_mesg, dst, rank+32, comm)
end

send_mesg = Float64(rank)
recv_mesg = Array{Float64}(undef,N)
recv_mesg_expected = Array{Float64}(undef,N)

fill!(recv_mesg_expected, Float64(src))

rreq = nothing
sreq = nothing
GC.gc()

send_mesg = Float64(rank)
recv_mesg = Array{Float64}(undef,N)
recv_mesg_expected = Array{Float64}(undef,N)

fill!(recv_mesg_expected, Float64(src))

if rank == 0
    MPI.Send(send_mesg, dst, rank+32, comm)
    recv_mesg = recv_mesg_expected
elseif rank == size-1
    (recv_mesg, _) = MPI.Recv(Float64,src, src+32, comm)
else
    (recv_mesg, _) = MPI.Recv(Float64,src, src+32, comm)
    MPI.Send(send_mesg, dst, rank+32, comm)
end

rreq = nothing
sreq = nothing
GC.gc()

recv_mesg = Array{Float64}(undef,N)
rreq = MPI.Irecv!(recv_mesg, src,  src+32, comm)
sreq = MPI.Isend(send_mesg, dst, rank+32, comm)

(inds, stats) = MPI.Waitsome!([sreq, rreq])
req_arr = [sreq,rreq]
for i in inds
    global (done, status) = MPI.Test!( req_arr[i] )
    @test done
end

rreq = nothing
sreq = nothing
GC.gc()

recv_mesg = Array{Float64}(undef,N)
sreq = MPI.Isend(send_mesg, dst, rank+32, comm)
MPI.Cancel!(sreq)
@test sreq.buffer == nothing
GC.gc()

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


text:
@testset "example simplices" begin
    @testset "2d simplex in 2d" begin
        s = Simplex((Vec(1.0,0.0), Vec(0.0,1.0), Vec(0.0,0.0)))
        @test (@inferred min_euclidean(Vec(0.0, 0.0), s)) ≈0
        @test min_euclidean(Vec(0.5, 0.0),s) ≈0
        @test min_euclidean(Vec(-1.0, -1.0),s) ≈√(2)
        @test min_euclidean(Vec(-7.0, 0.5),s) ≈7
        @test min_euclidean(Vec(1.0, 1.0), s) ≈√(0.5)
        @test (@inferred volume(s)) ≈1/2
        # containment
        @test contains(s, Vec(0.1, 0.0))
        for v in vertices(s)
            @test contains(s, v)
        end
        @test !( contains(s, Vec(1.0,0.1)) )
        @test contains(s, Vec(1.0,0.1), atol = 0.1)
    end

    @testset "counterexample" begin
        # There is a common false believe that in the proj_sqdist algorithm
        # one may throw away all negative weights. See for example
        # https://www.researchgate.net/publication/267801141_-_An_Algorithm_to_Compute_the_Distance_from_a_Point_to_a_Simplex
        # Here is a counterexample

        s = Simplex((Vec(-1.0,0.), Vec(0.0,0.), Vec(1.0,1.)))
        pt = Vec(2.,-1.0)
        @test min_euclidean(pt, s) ≈√(4.5)

        pt_proj, sqd = GeometryTypes.proj_sqdist(pt, s)
        @test pt_proj ≈ Vec(0.5, 0.5)
        @test !isapprox(pt_proj, Vec(0.0,0.), atol=1e-1)
        @test sqd ≈4.5

    end

    @testset "3d simplex in 3d" begin
        s = Simplex((Vec(1.0,0.0,0.0), Vec(0.0,1.0,0.0), Vec(0.0,0.0,1.0), Vec(0.0,0.0,0.0)))
        #@test (@inferred min_euclidean(Vec(0., 0.,0), s)) ≈ 0
        @test min_euclidean(Vec(0.0, 0.0, 0.0), s) ≈ 0
        @test min_euclidean(Vec(0.5, 0.0, 0.0),s) ≈ 0
        @test min_euclidean(Vec(-1.0, -1.0, 0.0),s) ≈ √(2)
        @test min_euclidean(Vec(-7.0, 0.5, 0.0),s) ≈ 7
        @test min_euclidean(Vec(1.0, 1.0, 0.0), s) ≈ √(0.5)
        @test min_euclidean(Vec(1.0, 1.0, 1.0), s) ≈ √(3)*(2/3)
        @test (@inferred volume(s)) ≈ 1/6
        @test !( contains(s, Vec(1.0, 0.0, 0.1)) )
        @test contains(s, Vec(0.1, 0.0, 0.1))
    end

    @testset "1d simplex in 2d" begin
        s = Simplex((Vec(-1.0, 1.), Vec(1.0, 1.)))
        proj(pt) = GeometryTypes.proj_sqdist(pt, s)[1]
        @test proj(Vec(0.0, 2.0)) ≈ Vec(0.0, 1.0)
        @test proj(Vec(0.0, -2.0)) ≈ Vec(0.0, 1.0)
        @test proj(Vec(56.0, 2.0)) ≈ Vec(1.0, 1.0)
        @test proj(Vec(-56.0, 2.0)) ≈ Vec(-1.0, 1.0)
    end

    @testset "1d simplex in 3d" begin
        s = Simplex((Vec(0.0, 0.0, 0.0), Vec(1.0, 1.0, 1.0)))
        @test (@inferred min_euclidean(Vec(0.0, 0.0, 0.0), s)) ≈ 0
        @test min_euclidean(Vec(0.5, 0.5, 0.5), s) ≈ 0
        @test min_euclidean(Vec(-1.0, 0.0, 0.0), s) ≈ 1
        @test min_euclidean(Vec(1.0, 0.0, 0.0), s) ≈ √(2/3)
        @test (@inferred volume(s)) ≈ √(3)

        @test contains(s, Vec(0.2, 0.2, 0.2))
        @test !(contains(s, Vec(0.1, 0.0999, 0.1)))
    end
end


text:
using NBodyLeapFrog
using NBodyLeapFrog: acceleration, sqdistance, distance
using Test
using NiLang, NiLang.AD

@testset "functions" begin
    ra, rb = V3(rand(3)...), V3(rand(3)...)
    y1 = ra + rb
    @instr ra += rb
    @test y1 ≈ ra

    ra, rb = V3(rand(3)...), V3(rand(3)...)
    y1 = ra + rb * 3.3
    @instr ra += rb * 3.3
    @test y1 ≈ ra

    ra, rb = V3(rand(3)...), V3(rand(3)...)
    y1 = ra + 3.3 * rb
    @instr ra += 3.3 * rb
    @test y1 ≈ ra

    ra, rb = V3(rand(3)...), V3(rand(3)...)
    y1 = distance(ra, rb)
    y2 = 0.0
    @instr y2 += sqdistance(ra, rb)
    @test y1^2 ≈ y2

    ra, rb = V3(rand(3)...), V3(rand(3)...)
    y1 = acceleration(ra, rb, 7.4, 2.0)
    y2 = zero(y1)
    @instr y2 += acceleration(ra, rb, 7.4, 2.0)
    @test y1 ≈ y2
end

@testset "leapfrog" begin
    planets = Bodies.chunit_day2year.(Bodies.set)
    nplanets = length(planets)
    r, v = leapfrog(planets; n = 55, dt = 0.01, keep_history=true)
    r2, v2 = leapfrog(planets; n = 55, dt = 0.01)
    @test all(a->isapprox(a[1], a[2]), zip(v[:,end], v2))
    @test all(r->isapprox(r[1], r[2]), zip(r[:,end], r2[:,end]))
end

@testset "fr" begin
    n = 550
    planets = Bodies.chunit_day2year.(Bodies.set)
    v = getfield.(planets, :v)
    r = getfield.(planets, :r)
    m = getfield.(planets, :m)
    r1, v1 = NBodyLeapFrog.leapfrog!(copy(r), copy(v), m; n = n, dt = 0.001, G=NBodyLeapFrog.G_year_AU)
    r2, v2 = NBodyLeapFrog.fr!(copy(r), copy(v), m; n = n, dt = 0.001, G=NBodyLeapFrog.G_year_AU)
    r3, v3 = NBodyLeapFrog.pefrl!(copy(r), copy(v), m; n = n, dt = 0.001, G=NBodyLeapFrog.G_year_AU)
    @test all(isapprox.(v1, v2; rtol=1e-2))
    @test all(isapprox.(v3, v2; rtol=1e-2))
    @test all(isapprox.(v3, v1; rtol=1e-2))
    @test all(isapprox.(r1, r2; atol=1e-2))
    @test all(isapprox.(r3, r2; atol=1e-2))
    @test all(isapprox.(r3, r1; atol=1e-2))
end

@testset "reversible leapfrog" begin
    planets = Bodies.chunit_day2year.(Bodies.set)
    nplanets = length(planets)
    n = 55
    r, v = leapfrog(planets; n = n, dt = 0.01, keep_history=true)

    v2 = getfield.(planets, :v)
    r2 = getfield.(planets, :r)
    m = getfield.(planets, :m)
    @instr i_leapfrog!(r2, v2, m; n = n, dt = 0.01)
    @test check_inv(i_leapfrog!, (r2, v2, m); n = n, dt = 0.01)
    @test all(x->x[1]≈x[2], zip(r[:,end], r2))

    v2 = getfield.(planets, :v)
    r2 = getfield.(planets, :r)
    m = getfield.(planets, :m)
    @instr i_leapfrog_reuse!(r2, v2, m; n = n, dt = 0.01)
    @test check_inv(i_leapfrog!, (r2, v2, m); n = n, dt = 0.01)
    @test all(x->x[1]≈x[2], zip(r[:,end], r2))

    planets = Bodies.chunit_day2year.(Bodies.set)
    @i function loss(y!, r2, v2, m; n, dt)
        i_leapfrog!(r2, v2, m; n = n, dt = dt)
        y! += sqdistance(r2[2], r2[3])
    end
    _, _, gr, gv, gm = Grad(loss)(Val(1), 0.0, copy(r2), copy(v2), copy(m); n = n, dt = 0.01)
    δ = 1e-6
    for i=1:nplanets
        # gradients on r
        for j=1:3
            r2_ = copy(r2)
            l0 = loss(0.0, copy(r2), copy(v2), copy(m); n=n, dt=0.01)[1]

            z = zeros(3)
            z[j] += δ
            r2_[i] += V3(z...)
            l1 = loss(0.0, copy(r2_), copy(v2), copy(m); n=n, dt=0.01)[1]
            ng = (l1-l0)/δ
            @test isapprox(ng, gr[i][j].g; atol=1e-4, rtol=1e-1)
        end

        # gradients on v
        for j=1:3
            v2_ = copy(v2)
            l0 = loss(0.0, copy(r2), copy(v2_), copy(m); n=n, dt=0.01)[1]

            z = zeros(3)
            z[j] += δ
            v2_[i] += V3(z...)
            l1 = loss(0.0, copy(r2), v2_, copy(m); n=n, dt=0.01)[1]
            ng = (l1-l0)/δ
            @test isapprox(ng, gv[i][j].g; atol=δ, rtol=1e-2)
        end

        # gradients on m
        m_ = copy(m)
        l0 = loss(0.0, copy(r2), copy(v2), copy(m_); n=n, dt=0.01)[1]

        m_[i] = m_[i]+δ
        l1 = loss(0.0, copy(r2), copy(v2), m_; n=n, dt=0.01)[1]
        ng = (l1-l0)/δ
        @test isapprox(ng, gm[i].g; atol=δ, rtol=1e-2)
    end
end

@testset "reversible fr" begin
    n = 100
    planets = Bodies.chunit_day2year.(Bodies.set)
    v = getfield.(planets, :v)
    r = getfield.(planets, :r)
    m = getfield.(planets, :m)
    r2, v2 = NBodyLeapFrog.fr!(copy(v), copy(r), m; n = n, dt = 0.01, G=NBodyLeapFrog.G_year_AU)
    r2r, v2r = NBodyLeapFrog.i_fr!(copy(v), copy(r), m; n = n, dt = 0.01, G=NBodyLeapFrog.G_year_AU)
    @test all(r2r .≈ r2)
    @test all(v2r .≈ v2)
    #r3r, v3r = NBodyLeapFrog.i_pefrl!(copy(v), copy(r), m; n = n, dt = 0.01, G=NBodyLeapFrog.G_year_AU)

    @test check_inv(NBodyLeapFrog.i_fr!, (copy(r), copy(v), m); n = n, dt = 0.01, G=NBodyLeapFrog.G_year_AU)

    @i function loss(y!, r2, v2, m; n, dt)
        NBodyLeapFrog.i_fr!(r2, v2, m; n = n, dt = dt)
        y! += sqdistance(r2[2], r2[3])
    end
    _, _, gr, gv, gm = Grad(loss)(Val(1), 0.0, copy(r2), copy(v2), m; n = n, dt = 0.01)
    for i=1:length(m)
        # gradients on r
        for j=1:3
            l0 = loss(0.0, copy(r2), copy(v2), copy(m); n=n, dt=0.01)[1]

            z = zeros(3)
            z[j] += 1e-5
            r2_ = copy(r2)
            r2_[i] = r2[i]+V3(z...)
            l1 = loss(0.0, r2_, copy(v2), copy(m); n=n, dt=0.01)[1]
            ng = (l1-l0)/1e-5
            @test isapprox(ng, gr[i][j].g; atol=1e-5, rtol=1e-2)
        end

        # gradients on v
        for j=1:3
            l0 = loss(0.0, copy(r2), copy(v2), copy(m); n=n, dt=0.01)[1]

            z = zeros(3)
            z[j] += 1e-5
            v2_ = copy(v2)
            v2_[i] = v2[i]+V3(z...)
            l1 = loss(0.0, copy(r2), v2_, copy(m); n=n, dt=0.01)[1]
            ng = (l1-l0)/1e-5
            @test isapprox(ng, gv[i][j].g; atol=1e-5, rtol=1e-2)
        end

        # gradients on m
        l0 = loss(0.0, copy(r2), copy(v2), copy(m); n=n, dt=0.01)[1]
        m_ = copy(m)
        m_[i] += 1e-5
        l1 = loss(0.0, copy(r2), copy(v2), m_; n=n, dt=0.01)[1]
        ng = (l1-l0)/1e-5
        @test isapprox(ng, gm[i].g; atol=1e-5, rtol=1e-2)
    end
end

@testset "reversible pefrl" begin
    n = 100
    planets = Bodies.chunit_day2year.(Bodies.set)
    v = getfield.(planets, :v)
    r = getfield.(planets, :r)
    m = getfield.(planets, :m)
    r2, v2 = NBodyLeapFrog.pefrl!(copy(v), copy(r), m; n = n, dt = 0.01, G=NBodyLeapFrog.G_year_AU)
    r2r, v2r = NBodyLeapFrog.i_pefrl!(copy(v), copy(r), m; n = n, dt = 0.01, G=NBodyLeapFrog.G_year_AU)
    @test all(r2r .≈ r2)
    @test all(v2r .≈ v2)
    #r3r, v3r = NBodyLeapFrog.i_pefrl!(copy(v), copy(r), m; n = n, dt = 0.01, G=NBodyLeapFrog.G_year_AU)

    @test check_inv(NBodyLeapFrog.i_pefrl!, (copy(r), copy(v), m); n = n, dt = 0.01, G=NBodyLeapFrog.G_year_AU)

    @i function loss(y!, r2, v2, m; n, dt)
        NBodyLeapFrog.i_pefrl!(r2, v2, m; n = n, dt = dt)
        y! += sqdistance(r2[2], r2[3])
    end
    _, _, gr, gv, gm = Grad(loss)(Val(1), 0.0, copy(r2), copy(v2), m; n = n, dt = 0.01)
    for i=1:length(m)
        # gradients on r
        for j=1:3
            l0 = loss(0.0, copy(r2), copy(v2), copy(m); n=n, dt=0.01)[1]

            z = zeros(3)
            z[j] += 1e-5
            r2_ = copy(r2)
            r2_[i] = r2[i]+V3(z...)
            l1 = loss(0.0, r2_, copy(v2), copy(m); n=n, dt=0.01)[1]
            ng = (l1-l0)/1e-5
            @test isapprox(ng, gr[i][j].g; atol=1e-5, rtol=1e-2)
        end

        # gradients on v
        for j=1:3
            l0 = loss(0.0, copy(r2), copy(v2), copy(m); n=n, dt=0.01)[1]

            z = zeros(3)
            z[j] += 1e-5
            v2_ = copy(v2)
            v2_[i] = v2[i]+V3(z...)
            l1 = loss(0.0, copy(r2), v2_, copy(m); n=n, dt=0.01)[1]
            ng = (l1-l0)/1e-5
            @test isapprox(ng, gv[i][j].g; atol=1e-5, rtol=1e-2)
        end

        # gradients on m
        l0 = loss(0.0, copy(r2), copy(v2), copy(m); n=n, dt=0.01)[1]
        m_ = copy(m)
        m_[i] += 1e-5
        l1 = loss(0.0, copy(r2), copy(v2), m_; n=n, dt=0.01)[1]
        ng = (l1-l0)/1e-5
        @test isapprox(ng, gm[i].g; atol=1e-5, rtol=1e-2)
    end
end