text:
@testset "Sparse solving" begin
  M = sparse_matrix(QQ, [ 1 0 0; 0 0 0; 0 0 1 ])
  b = sparse_matrix(QQ, [ 1 0 3 ])

  fl, sol = can_solve_with_solution(M, b, side = :left)
  @test fl
  @test matrix(sol)*matrix(M) == matrix(b)
  sol = solve(M, b, side = :left)
  @test matrix(sol)*matrix(M) == matrix(b)

  fl, sol = can_solve_with_solution(M, transpose(b), side = :right)
  @test fl
  @test matrix(M)*matrix(sol) == matrix(transpose(b))
  sol = solve(M, transpose(b), side = :right)
  @test matrix(M)*matrix(sol) == matrix(transpose(b))

  fl, sol = can_solve_with_solution(M, b.rows[1])
  @test fl
  @test mul(sol, M) == b.rows[1]

  for i in 1:10
    r = 10
    c = 20
    M = matrix(FlintQQ, rand([0,0,0,0,0,0,0,0,0,0,1], r, c))
    Ms = sparse_matrix(M)
    N = matrix(FlintQQ, rand([0,0,0,0,0,0,0,0,0,0,1], r, 2))
    Ns = sparse_matrix(N)
    fl, sol = can_solve_with_solution(Ms, Ns, side = :right)
    fl2, sol2 = can_solve_with_solution(M, N, side = :right)
    @test fl == fl2
    if fl
      @test M*matrix(sol) == N
    end
  end
end


text:
@testset "5.2.5 Inverse cosine functions" begin
    (a, b, c, d, f, g, h, m, n, x, ) = @variables a b c d f g h m n x

    #= ::Package:: =#

    #= ::Title:: =#
    #=Integrands*of*the*form*u*(a+b*acos(c*x))^n=#

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

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

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

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

    @test_int [sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))*(f + g*x)^3, x, 16, -((b*f^2*g*x*sqrt(d - c^2*d*x^2))/(c*sqrt(1 - c^2*x^2))) - (2*b*g^3*x*sqrt(d - c^2*d*x^2))/(15*c^3*sqrt(1 - c^2*x^2)) + (b*c*f^3*x^2*sqrt(d - c^2*d*x^2))/(4*sqrt(1 - c^2*x^2)) - (3*b*f*g^2*x^2*sqrt(d - c^2*d*x^2))/(16*c*sqrt(1 - c^2*x^2)) + (b*c*f^2*g*x^3*sqrt(d - c^2*d*x^2))/(3*sqrt(1 - c^2*x^2)) - (b*g^3*x^3*sqrt(d - c^2*d*x^2))/(45*c*sqrt(1 - c^2*x^2)) + (3*b*c*f*g^2*x^4*sqrt(d - c^2*d*x^2))/(16*sqrt(1 - c^2*x^2)) + (b*c*g^3*x^5*sqrt(d - c^2*d*x^2))/(25*sqrt(1 - c^2*x^2)) + (1/2)*f^3*x*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)) - (3*f*g^2*x*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(8*c^2) + (3/4)*f*g^2*x^3*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)) - (f^2*g*(1 - c^2*x^2)*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/c^2 - (g^3*(1 - c^2*x^2)*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(3*c^4) + (g^3*(1 - c^2*x^2)^2*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(5*c^4) - (f^3*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(4*b*c*sqrt(1 - c^2*x^2)) - (3*f*g^2*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(16*b*c^3*sqrt(1 - c^2*x^2))]
    @test_int [sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))*(f + g*x)^2, x, 13, -((2*b*f*g*x*sqrt(d - c^2*d*x^2))/(3*c*sqrt(1 - c^2*x^2))) + (b*c*f^2*x^2*sqrt(d - c^2*d*x^2))/(4*sqrt(1 - c^2*x^2)) - (b*g^2*x^2*sqrt(d - c^2*d*x^2))/(16*c*sqrt(1 - c^2*x^2)) + (2*b*c*f*g*x^3*sqrt(d - c^2*d*x^2))/(9*sqrt(1 - c^2*x^2)) + (b*c*g^2*x^4*sqrt(d - c^2*d*x^2))/(16*sqrt(1 - c^2*x^2)) + (1/2)*f^2*x*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)) - (g^2*x*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(8*c^2) + (1/4)*g^2*x^3*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)) - (2*f*g*(1 - c^2*x^2)*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(3*c^2) - (f^2*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(4*b*c*sqrt(1 - c^2*x^2)) - (g^2*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(16*b*c^3*sqrt(1 - c^2*x^2))]
    @test_int [sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))*(f + g*x)^1, x, 8, -((b*g*x*sqrt(d - c^2*d*x^2))/(3*c*sqrt(1 - c^2*x^2))) + (b*c*f*x^2*sqrt(d - c^2*d*x^2))/(4*sqrt(1 - c^2*x^2)) + (b*c*g*x^3*sqrt(d - c^2*d*x^2))/(9*sqrt(1 - c^2*x^2)) + (1/2)*f*x*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)) - (g*(1 - c^2*x^2)*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(3*c^2) - (f*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(4*b*c*sqrt(1 - c^2*x^2))]
    @test_int [sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))/(f + g*x)^1, x, 22, (a*sqrt(d - c^2*d*x^2))/g + (b*c*x*sqrt(d - c^2*d*x^2))/(g*sqrt(1 - c^2*x^2)) + (b*sqrt(d - c^2*d*x^2)*acos(c*x))/g - (c*x*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(2*b*g*sqrt(1 - c^2*x^2)) + ((1 - (c^2*f^2)/g^2)*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(2*b*c*(f + g*x)*sqrt(1 - c^2*x^2)) - (sqrt(1 - c^2*x^2)*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(2*b*c*(f + g*x)) - (a*sqrt(c^2*f^2 - g^2)*sqrt(d - c^2*d*x^2)*atan((g + c^2*f*x)/(sqrt(c^2*f^2 - g^2)*sqrt(1 - c^2*x^2))))/(g^2*sqrt(1 - c^2*x^2)) - (im*b*sqrt(c^2*f^2 - g^2)*sqrt(d - c^2*d*x^2)*acos(c*x)*log(1 + (ℯ^(im*acos(c*x))*g)/(c*f - sqrt(c^2*f^2 - g^2))))/(g^2*sqrt(1 - c^2*x^2)) + (im*b*sqrt(c^2*f^2 - g^2)*sqrt(d - c^2*d*x^2)*acos(c*x)*log(1 + (ℯ^(im*acos(c*x))*g)/(c*f + sqrt(c^2*f^2 - g^2))))/(g^2*sqrt(1 - c^2*x^2)) - (b*sqrt(c^2*f^2 - g^2)*sqrt(d - c^2*d*x^2)*PolyLog(2, -((ℯ^(im*acos(c*x))*g)/(c*f - sqrt(c^2*f^2 - g^2)))))/(g^2*sqrt(1 - c^2*x^2)) + (b*sqrt(c^2*f^2 - g^2)*sqrt(d - c^2*d*x^2)*PolyLog(2, -((ℯ^(im*acos(c*x))*g)/(c*f + sqrt(c^2*f^2 - g^2)))))/(g^2*sqrt(1 - c^2*x^2))]
    @test_int [sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))/(f + g*x)^2, x, 35, -((a*sqrt(d - c^2*d*x^2))/(g*(f + g*x))) - (b*sqrt(d - c^2*d*x^2)*acos(c*x))/(g*(f + g*x)) + (b*c^3*f^2*sqrt(d - c^2*d*x^2)*acos(c*x)^2)/(2*g^2*(c^2*f^2 - g^2)*sqrt(1 - c^2*x^2)) - ((g + c^2*f*x)^2*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(2*b*c*(c^2*f^2 - g^2)*(f + g*x)^2*sqrt(1 - c^2*x^2)) - (sqrt(1 - c^2*x^2)*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(2*b*c*(f + g*x)^2) - (a*c^3*f^2*sqrt(d - c^2*d*x^2)*asin(c*x))/(g^2*(c^2*f^2 - g^2)*sqrt(1 - c^2*x^2)) + (a*c^2*f*sqrt(d - c^2*d*x^2)*atan((g + c^2*f*x)/(sqrt(c^2*f^2 - g^2)*sqrt(1 - c^2*x^2))))/(g^2*sqrt(c^2*f^2 - g^2)*sqrt(1 - c^2*x^2)) + (im*b*c^2*f*sqrt(d - c^2*d*x^2)*acos(c*x)*log(1 + (ℯ^(im*acos(c*x))*g)/(c*f - sqrt(c^2*f^2 - g^2))))/(g^2*sqrt(c^2*f^2 - g^2)*sqrt(1 - c^2*x^2)) - (im*b*c^2*f*sqrt(d - c^2*d*x^2)*acos(c*x)*log(1 + (ℯ^(im*acos(c*x))*g)/(c*f + sqrt(c^2*f^2 - g^2))))/(g^2*sqrt(c^2*f^2 - g^2)*sqrt(1 - c^2*x^2)) - (b*c*sqrt(d - c^2*d*x^2)*log(f + g*x))/(g^2*sqrt(1 - c^2*x^2)) + (b*c^2*f*sqrt(d - c^2*d*x^2)*PolyLog(2, -((ℯ^(im*acos(c*x))*g)/(c*f - sqrt(c^2*f^2 - g^2)))))/(g^2*sqrt(c^2*f^2 - g^2)*sqrt(1 - c^2*x^2)) - (b*c^2*f*sqrt(d - c^2*d*x^2)*PolyLog(2, -((ℯ^(im*acos(c*x))*g)/(c*f + sqrt(c^2*f^2 - g^2)))))/(g^2*sqrt(c^2*f^2 - g^2)*sqrt(1 - c^2*x^2))]

    @test_int [(d - c^2*d*x^2)^(3/2)*(a + b*acos(c*x))*(f + g*x)^3, x, 24, -((3*b*d*f^2*g*x*sqrt(d - c^2*d*x^2))/(5*c*sqrt(1 - c^2*x^2))) - (2*b*d*g^3*x*sqrt(d - c^2*d*x^2))/(35*c^3*sqrt(1 - c^2*x^2)) + (5*b*c*d*f^3*x^2*sqrt(d - c^2*d*x^2))/(16*sqrt(1 - c^2*x^2)) - (3*b*d*f*g^2*x^2*sqrt(d - c^2*d*x^2))/(32*c*sqrt(1 - c^2*x^2)) + (2*b*c*d*f^2*g*x^3*sqrt(d - c^2*d*x^2))/(5*sqrt(1 - c^2*x^2)) - (b*d*g^3*x^3*sqrt(d - c^2*d*x^2))/(105*c*sqrt(1 - c^2*x^2)) - (b*c^3*d*f^3*x^4*sqrt(d - c^2*d*x^2))/(16*sqrt(1 - c^2*x^2)) + (7*b*c*d*f*g^2*x^4*sqrt(d - c^2*d*x^2))/(32*sqrt(1 - c^2*x^2)) - (3*b*c^3*d*f^2*g*x^5*sqrt(d - c^2*d*x^2))/(25*sqrt(1 - c^2*x^2)) + (8*b*c*d*g^3*x^5*sqrt(d - c^2*d*x^2))/(175*sqrt(1 - c^2*x^2)) - (b*c^3*d*f*g^2*x^6*sqrt(d - c^2*d*x^2))/(12*sqrt(1 - c^2*x^2)) - (b*c^3*d*g^3*x^7*sqrt(d - c^2*d*x^2))/(49*sqrt(1 - c^2*x^2)) + (3/8)*d*f^3*x*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)) - (3*d*f*g^2*x*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(16*c^2) + (3/8)*d*f*g^2*x^3*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)) + (1/4)*d*f^3*x*(1 - c^2*x^2)*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)) + (1/2)*d*f*g^2*x^3*(1 - c^2*x^2)*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)) - (3*d*f^2*g*(1 - c^2*x^2)^2*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(5*c^2) - (d*g^3*(1 - c^2*x^2)^2*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(5*c^4) + (d*g^3*(1 - c^2*x^2)^3*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(7*c^4) - (3*d*f^3*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(16*b*c*sqrt(1 - c^2*x^2)) - (3*d*f*g^2*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(32*b*c^3*sqrt(1 - c^2*x^2))]
    @test_int [(d - c^2*d*x^2)^(3/2)*(a + b*acos(c*x))*(f + g*x)^2, x, 20, -((2*b*d*f*g*x*sqrt(d - c^2*d*x^2))/(5*c*sqrt(1 - c^2*x^2))) + (5*b*c*d*f^2*x^2*sqrt(d - c^2*d*x^2))/(16*sqrt(1 - c^2*x^2)) - (b*d*g^2*x^2*sqrt(d - c^2*d*x^2))/(32*c*sqrt(1 - c^2*x^2)) + (4*b*c*d*f*g*x^3*sqrt(d - c^2*d*x^2))/(15*sqrt(1 - c^2*x^2)) - (b*c^3*d*f^2*x^4*sqrt(d - c^2*d*x^2))/(16*sqrt(1 - c^2*x^2)) + (7*b*c*d*g^2*x^4*sqrt(d - c^2*d*x^2))/(96*sqrt(1 - c^2*x^2)) - (2*b*c^3*d*f*g*x^5*sqrt(d - c^2*d*x^2))/(25*sqrt(1 - c^2*x^2)) - (b*c^3*d*g^2*x^6*sqrt(d - c^2*d*x^2))/(36*sqrt(1 - c^2*x^2)) + (3/8)*d*f^2*x*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)) - (d*g^2*x*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(16*c^2) + (1/8)*d*g^2*x^3*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)) + (1/4)*d*f^2*x*(1 - c^2*x^2)*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)) + (1/6)*d*g^2*x^3*(1 - c^2*x^2)*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)) - (2*d*f*g*(1 - c^2*x^2)^2*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(5*c^2) - (3*d*f^2*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(16*b*c*sqrt(1 - c^2*x^2)) - (d*g^2*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(32*b*c^3*sqrt(1 - c^2*x^2))]
    @test_int [(d - c^2*d*x^2)^(3/2)*(a + b*acos(c*x))*(f + g*x)^1, x, 12, -((b*d*g*x*sqrt(d - c^2*d*x^2))/(5*c*sqrt(1 - c^2*x^2))) + (5*b*c*d*f*x^2*sqrt(d - c^2*d*x^2))/(16*sqrt(1 - c^2*x^2)) + (2*b*c*d*g*x^3*sqrt(d - c^2*d*x^2))/(15*sqrt(1 - c^2*x^2)) - (b*c^3*d*f*x^4*sqrt(d - c^2*d*x^2))/(16*sqrt(1 - c^2*x^2)) - (b*c^3*d*g*x^5*sqrt(d - c^2*d*x^2))/(25*sqrt(1 - c^2*x^2)) + (3/8)*d*f*x*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)) + (1/4)*d*f*x*(1 - c^2*x^2)*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)) - (d*g*(1 - c^2*x^2)^2*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(5*c^2) - (3*d*f*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(16*b*c*sqrt(1 - c^2*x^2))]
    @test_int [(d - c^2*d*x^2)^(3/2)*(a + b*acos(c*x))/(f + g*x)^1, x, 29, -((a*d*(c*f - g)*(c*f + g)*sqrt(d - c^2*d*x^2))/g^3) + (b*c*d*x*sqrt(d - c^2*d*x^2))/(3*g*sqrt(1 - c^2*x^2)) - (b*c*d*(c*f - g)*(c*f + g)*x*sqrt(d - c^2*d*x^2))/(g^3*sqrt(1 - c^2*x^2)) + (b*c^3*d*f*x^2*sqrt(d - c^2*d*x^2))/(4*g^2*sqrt(1 - c^2*x^2)) - (b*c^3*d*x^3*sqrt(d - c^2*d*x^2))/(9*g*sqrt(1 - c^2*x^2)) - (b*d*(c*f - g)*(c*f + g)*sqrt(d - c^2*d*x^2)*acos(c*x))/g^3 + (c^2*d*f*x*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(2*g^2) + (d*(1 - c^2*x^2)*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(3*g) - (c*d*f*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(4*b*g^2*sqrt(1 - c^2*x^2)) + (c*d*(c*f - g)*(c*f + g)*x*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(2*b*g^3*sqrt(1 - c^2*x^2)) + (d*(c^2*f^2 - g^2)^2*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(2*b*c*g^4*(f + g*x)*sqrt(1 - c^2*x^2)) + (d*(c*f - g)*(c*f + g)*sqrt(1 - c^2*x^2)*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(2*b*c*g^2*(f + g*x)) + (a*d*(c^2*f^2 - g^2)^(3/2)*sqrt(d - c^2*d*x^2)*atan((g + c^2*f*x)/(sqrt(c^2*f^2 - g^2)*sqrt(1 - c^2*x^2))))/(g^4*sqrt(1 - c^2*x^2)) + (im*b*d*(c^2*f^2 - g^2)^(3/2)*sqrt(d - c^2*d*x^2)*acos(c*x)*log(1 + (ℯ^(im*acos(c*x))*g)/(c*f - sqrt(c^2*f^2 - g^2))))/(g^4*sqrt(1 - c^2*x^2)) - (im*b*d*(c^2*f^2 - g^2)^(3/2)*sqrt(d - c^2*d*x^2)*acos(c*x)*log(1 + (ℯ^(im*acos(c*x))*g)/(c*f + sqrt(c^2*f^2 - g^2))))/(g^4*sqrt(1 - c^2*x^2)) + (b*d*(c^2*f^2 - g^2)^(3/2)*sqrt(d - c^2*d*x^2)*PolyLog(2, -((ℯ^(im*acos(c*x))*g)/(c*f - sqrt(c^2*f^2 - g^2)))))/(g^4*sqrt(1 - c^2*x^2)) - (b*d*(c^2*f^2 - g^2)^(3/2)*sqrt(d - c^2*d*x^2)*PolyLog(2, -((ℯ^(im*acos(c*x))*g)/(c*f + sqrt(c^2*f^2 - g^2)))))/(g^4*sqrt(1 - c^2*x^2))]
    #= [(d - c^2*d*x^2)^(3/2)*(a + b*acos(c*x))/(f + g*x)^2, x, 71, (2*a*c^2*d*f*sqrt(d - c^2*d*x^2))/g^3 + (a*d*(c*f - g)*(c*f + g)*sqrt(d - c^2*d*x^2))/(g^3*(f + g*x)) + (2*b*c^3*d*f*x*sqrt(d - c^2*d*x^2))/(g^3*sqrt(1 - c^2*x^2)) - (b*c^3*d*x^2*sqrt(d - c^2*d*x^2))/(4*g^2*sqrt(1 - c^2*x^2)) + (2*b*c^2*d*f*sqrt(d - c^2*d*x^2)*acos(c*x))/g^3 + (b*d*(c*f - g)*(c*f + g)*sqrt(d - c^2*d*x^2)*acos(c*x))/(g^3*(f + g*x)) - (b*c^3*d*f^2*sqrt(d - c^2*d*x^2)*acos(c*x)^2)/(2*g^4*sqrt(1 - c^2*x^2)) - (c^2*d*x*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(2*g^2) + (c*d*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(4*b*g^2*sqrt(1 - c^2*x^2)) - (c^3*d*f*x*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(b*g^3*sqrt(1 - c^2*x^2)) + (d*(g + c^2*f*x)^2*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(2*b*c*g^2*(f + g*x)^2*sqrt(1 - c^2*x^2)) + (c*d*f*(1 - (c^2*f^2)/g^2)*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(b*g^2*(f + g*x)*sqrt(1 - c^2*x^2)) + (d*(c*f - g)*(c*f + g)*sqrt(1 - c^2*x^2)*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(2*b*c*g^2*(f + g*x)^2) - (c*d*f*sqrt(1 - c^2*x^2)*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(b*g^2*(f + g*x)) + (a*c^3*d*f^2*sqrt(d - c^2*d*x^2)*asin(c*x))/(g^4*sqrt(1 - c^2*x^2)) - (3*a*c^2*d*f*sqrt(c^2*f^2 - g^2)*sqrt(d - c^2*d*x^2)*atan((g + c^2*f*x)/(sqrt(c^2*f^2 - g^2)*sqrt(1 - c^2*x^2))))/(g^4*sqrt(1 - c^2*x^2)) - (3*im*b*c^2*d*f*sqrt(c^2*f^2 - g^2)*sqrt(d - c^2*d*x^2)*acos(c*x)*log(1 + (ℯ^(im*acos(c*x))*g)/(c*f - sqrt(c^2*f^2 - g^2))))/(g^4*sqrt(1 - c^2*x^2)) + (3*im*b*c^2*d*f*sqrt(c^2*f^2 - g^2)*sqrt(d - c^2*d*x^2)*acos(c*x)*log(1 + (ℯ^(im*acos(c*x))*g)/(c*f + sqrt(c^2*f^2 - g^2))))/(g^4*sqrt(1 - c^2*x^2)) + (b*c*d*(c*f - g)*(c*f + g)*sqrt(d - c^2*d*x^2)*log(f + g*x))/(g^4*sqrt(1 - c^2*x^2)) - (3*b*c^2*d*f*sqrt(c^2*f^2 - g^2)*sqrt(d - c^2*d*x^2)*PolyLog(2, -((ℯ^(im*acos(c*x))*g)/(c*f - sqrt(c^2*f^2 - g^2)))))/(g^4*sqrt(1 - c^2*x^2)) + (3*b*c^2*d*f*sqrt(c^2*f^2 - g^2)*sqrt(d - c^2*d*x^2)*PolyLog(2, -((ℯ^(im*acos(c*x))*g)/(c*f + sqrt(c^2*f^2 - g^2)))))/(g^4*sqrt(1 - c^2*x^2))] =#

    @test_int [(d - c^2*d*x^2)^(5/2)*(a + b*acos(c*x))*(f + g*x)^3, x, 30, -((3*b*d^2*f^2*g*x*sqrt(d - c^2*d*x^2))/(7*c*sqrt(1 - c^2*x^2))) - (2*b*d^2*g^3*x*sqrt(d - c^2*d*x^2))/(63*c^3*sqrt(1 - c^2*x^2)) + (25*b*c*d^2*f^3*x^2*sqrt(d - c^2*d*x^2))/(96*sqrt(1 - c^2*x^2)) - (15*b*d^2*f*g^2*x^2*sqrt(d - c^2*d*x^2))/(256*c*sqrt(1 - c^2*x^2)) + (3*b*c*d^2*f^2*g*x^3*sqrt(d - c^2*d*x^2))/(7*sqrt(1 - c^2*x^2)) - (b*d^2*g^3*x^3*sqrt(d - c^2*d*x^2))/(189*c*sqrt(1 - c^2*x^2)) - (5*b*c^3*d^2*f^3*x^4*sqrt(d - c^2*d*x^2))/(96*sqrt(1 - c^2*x^2)) + (59*b*c*d^2*f*g^2*x^4*sqrt(d - c^2*d*x^2))/(256*sqrt(1 - c^2*x^2)) - (9*b*c^3*d^2*f^2*g*x^5*sqrt(d - c^2*d*x^2))/(35*sqrt(1 - c^2*x^2)) + (b*c*d^2*g^3*x^5*sqrt(d - c^2*d*x^2))/(21*sqrt(1 - c^2*x^2)) - (17*b*c^3*d^2*f*g^2*x^6*sqrt(d - c^2*d*x^2))/(96*sqrt(1 - c^2*x^2)) + (3*b*c^5*d^2*f^2*g*x^7*sqrt(d - c^2*d*x^2))/(49*sqrt(1 - c^2*x^2)) - (19*b*c^3*d^2*g^3*x^7*sqrt(d - c^2*d*x^2))/(441*sqrt(1 - c^2*x^2)) + (3*b*c^5*d^2*f*g^2*x^8*sqrt(d - c^2*d*x^2))/(64*sqrt(1 - c^2*x^2)) + (b*c^5*d^2*g^3*x^9*sqrt(d - c^2*d*x^2))/(81*sqrt(1 - c^2*x^2)) - (b*d^2*f^3*(1 - c^2*x^2)^(5/2)*sqrt(d - c^2*d*x^2))/(36*c) + (5/16)*d^2*f^3*x*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)) - (15*d^2*f*g^2*x*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(128*c^2) + (15/64)*d^2*f*g^2*x^3*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)) + (5/24)*d^2*f^3*x*(1 - c^2*x^2)*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)) + (5/16)*d^2*f*g^2*x^3*(1 - c^2*x^2)*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)) + (1/6)*d^2*f^3*x*(1 - c^2*x^2)^2*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)) + (3/8)*d^2*f*g^2*x^3*(1 - c^2*x^2)^2*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)) - (3*d^2*f^2*g*(1 - c^2*x^2)^3*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(7*c^2) - (d^2*g^3*(1 - c^2*x^2)^3*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(7*c^4) + (d^2*g^3*(1 - c^2*x^2)^4*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(9*c^4) - (5*d^2*f^3*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(32*b*c*sqrt(1 - c^2*x^2)) - (15*d^2*f*g^2*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(256*b*c^3*sqrt(1 - c^2*x^2))]
    @test_int [(d - c^2*d*x^2)^(5/2)*(a + b*acos(c*x))*(f + g*x)^2, x, 26, -((2*b*d^2*f*g*x*sqrt(d - c^2*d*x^2))/(7*c*sqrt(1 - c^2*x^2))) + (25*b*c*d^2*f^2*x^2*sqrt(d - c^2*d*x^2))/(96*sqrt(1 - c^2*x^2)) - (5*b*d^2*g^2*x^2*sqrt(d - c^2*d*x^2))/(256*c*sqrt(1 - c^2*x^2)) + (2*b*c*d^2*f*g*x^3*sqrt(d - c^2*d*x^2))/(7*sqrt(1 - c^2*x^2)) - (5*b*c^3*d^2*f^2*x^4*sqrt(d - c^2*d*x^2))/(96*sqrt(1 - c^2*x^2)) + (59*b*c*d^2*g^2*x^4*sqrt(d - c^2*d*x^2))/(768*sqrt(1 - c^2*x^2)) - (6*b*c^3*d^2*f*g*x^5*sqrt(d - c^2*d*x^2))/(35*sqrt(1 - c^2*x^2)) - (17*b*c^3*d^2*g^2*x^6*sqrt(d - c^2*d*x^2))/(288*sqrt(1 - c^2*x^2)) + (2*b*c^5*d^2*f*g*x^7*sqrt(d - c^2*d*x^2))/(49*sqrt(1 - c^2*x^2)) + (b*c^5*d^2*g^2*x^8*sqrt(d - c^2*d*x^2))/(64*sqrt(1 - c^2*x^2)) - (b*d^2*f^2*(1 - c^2*x^2)^(5/2)*sqrt(d - c^2*d*x^2))/(36*c) + (5/16)*d^2*f^2*x*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)) - (5*d^2*g^2*x*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(128*c^2) + (5/64)*d^2*g^2*x^3*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)) + (5/24)*d^2*f^2*x*(1 - c^2*x^2)*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)) + (5/48)*d^2*g^2*x^3*(1 - c^2*x^2)*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)) + (1/6)*d^2*f^2*x*(1 - c^2*x^2)^2*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)) + (1/8)*d^2*g^2*x^3*(1 - c^2*x^2)^2*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)) - (2*d^2*f*g*(1 - c^2*x^2)^3*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(7*c^2) - (5*d^2*f^2*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(32*b*c*sqrt(1 - c^2*x^2)) - (5*d^2*g^2*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(256*b*c^3*sqrt(1 - c^2*x^2))]
    @test_int [(d - c^2*d*x^2)^(5/2)*(a + b*acos(c*x))*(f + g*x)^1, x, 14, -((b*d^2*g*x*sqrt(d - c^2*d*x^2))/(7*c*sqrt(1 - c^2*x^2))) + (25*b*c*d^2*f*x^2*sqrt(d - c^2*d*x^2))/(96*sqrt(1 - c^2*x^2)) + (b*c*d^2*g*x^3*sqrt(d - c^2*d*x^2))/(7*sqrt(1 - c^2*x^2)) - (5*b*c^3*d^2*f*x^4*sqrt(d - c^2*d*x^2))/(96*sqrt(1 - c^2*x^2)) - (3*b*c^3*d^2*g*x^5*sqrt(d - c^2*d*x^2))/(35*sqrt(1 - c^2*x^2)) + (b*c^5*d^2*g*x^7*sqrt(d - c^2*d*x^2))/(49*sqrt(1 - c^2*x^2)) - (b*d^2*f*(1 - c^2*x^2)^(5/2)*sqrt(d - c^2*d*x^2))/(36*c) + (5/16)*d^2*f*x*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)) + (5/24)*d^2*f*x*(1 - c^2*x^2)*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)) + (1/6)*d^2*f*x*(1 - c^2*x^2)^2*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)) - (d^2*g*(1 - c^2*x^2)^3*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(7*c^2) - (5*d^2*f*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(32*b*c*sqrt(1 - c^2*x^2))]
    @test_int [(d - c^2*d*x^2)^(5/2)*(a + b*acos(c*x))/(f + g*x)^1, x, 37, (a*d^2*(c^2*f^2 - g^2)^2*sqrt(d - c^2*d*x^2))/g^5 - (2*b*c*d^2*x*sqrt(d - c^2*d*x^2))/(15*g*sqrt(1 - c^2*x^2)) - (b*c*d^2*(c^2*f^2 - 2*g^2)*x*sqrt(d - c^2*d*x^2))/(3*g^3*sqrt(1 - c^2*x^2)) + (b*c*d^2*(c^2*f^2 - g^2)^2*x*sqrt(d - c^2*d*x^2))/(g^5*sqrt(1 - c^2*x^2)) + (b*c^3*d^2*f*x^2*sqrt(d - c^2*d*x^2))/(16*g^2*sqrt(1 - c^2*x^2)) - (b*c^3*d^2*f*(c^2*f^2 - 2*g^2)*x^2*sqrt(d - c^2*d*x^2))/(4*g^4*sqrt(1 - c^2*x^2)) - (b*c^3*d^2*x^3*sqrt(d - c^2*d*x^2))/(45*g*sqrt(1 - c^2*x^2)) + (b*c^3*d^2*(c^2*f^2 - 2*g^2)*x^3*sqrt(d - c^2*d*x^2))/(9*g^3*sqrt(1 - c^2*x^2)) - (b*c^5*d^2*f*x^4*sqrt(d - c^2*d*x^2))/(16*g^2*sqrt(1 - c^2*x^2)) + (b*c^5*d^2*x^5*sqrt(d - c^2*d*x^2))/(25*g*sqrt(1 - c^2*x^2)) + (b*d^2*(c^2*f^2 - g^2)^2*sqrt(d - c^2*d*x^2)*acos(c*x))/g^5 + (c^2*d^2*f*x*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(8*g^2) - (c^2*d^2*f*(c^2*f^2 - 2*g^2)*x*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(2*g^4) - (c^4*d^2*f*x^3*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(4*g^2) - (d^2*(1 - c^2*x^2)*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(3*g) - (d^2*(c^2*f^2 - 2*g^2)*(1 - c^2*x^2)*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(3*g^3) + (d^2*(1 - c^2*x^2)^2*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(5*g) + (c*d^2*f*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(16*b*g^2*sqrt(1 - c^2*x^2)) + (c*d^2*f*(c^2*f^2 - 2*g^2)*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(4*b*g^4*sqrt(1 - c^2*x^2)) - (c*d^2*(c^2*f^2 - g^2)^2*x*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(2*b*g^5*sqrt(1 - c^2*x^2)) - (d^2*(c^2*f^2 - g^2)^3*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(2*b*c*g^6*(f + g*x)*sqrt(1 - c^2*x^2)) - (d^2*(c^2*f^2 - g^2)^2*sqrt(1 - c^2*x^2)*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(2*b*c*g^4*(f + g*x)) - (a*d^2*(c^2*f^2 - g^2)^(5/2)*sqrt(d - c^2*d*x^2)*atan((g + c^2*f*x)/(sqrt(c^2*f^2 - g^2)*sqrt(1 - c^2*x^2))))/(g^6*sqrt(1 - c^2*x^2)) - (im*b*d^2*(c^2*f^2 - g^2)^(5/2)*sqrt(d - c^2*d*x^2)*acos(c*x)*log(1 + (ℯ^(im*acos(c*x))*g)/(c*f - sqrt(c^2*f^2 - g^2))))/(g^6*sqrt(1 - c^2*x^2)) + (im*b*d^2*(c^2*f^2 - g^2)^(5/2)*sqrt(d - c^2*d*x^2)*acos(c*x)*log(1 + (ℯ^(im*acos(c*x))*g)/(c*f + sqrt(c^2*f^2 - g^2))))/(g^6*sqrt(1 - c^2*x^2)) - (b*d^2*(c^2*f^2 - g^2)^(5/2)*sqrt(d - c^2*d*x^2)*PolyLog(2, -((ℯ^(im*acos(c*x))*g)/(c*f - sqrt(c^2*f^2 - g^2)))))/(g^6*sqrt(1 - c^2*x^2)) + (b*d^2*(c^2*f^2 - g^2)^(5/2)*sqrt(d - c^2*d*x^2)*PolyLog(2, -((ℯ^(im*acos(c*x))*g)/(c*f + sqrt(c^2*f^2 - g^2)))))/(g^6*sqrt(1 - c^2*x^2))]
    #= [(d - c^2*d*x^2)^(5/2)*(a + b*acos(c*x))/(f + g*x)^2, x, 78, -((4*a*c^2*d^2*f*(c*f - g)*(c*f + g)*sqrt(d - c^2*d*x^2))/g^5) - (a*d^2*(c^2*f^2 - g^2)^2*sqrt(d - c^2*d*x^2))/(g^5*(f + g*x)) + (2*b*c^3*d^2*f*x*sqrt(d - c^2*d*x^2))/(3*g^3*sqrt(1 - c^2*x^2)) - (4*b*c^3*d^2*f*(c*f - g)*(c*f + g)*x*sqrt(d - c^2*d*x^2))/(g^5*sqrt(1 - c^2*x^2)) - (b*c^3*d^2*x^2*sqrt(d - c^2*d*x^2))/(16*g^2*sqrt(1 - c^2*x^2)) + (b*c^3*d^2*(3*c^2*f^2 - 2*g^2)*x^2*sqrt(d - c^2*d*x^2))/(4*g^4*sqrt(1 - c^2*x^2)) - (2*b*c^5*d^2*f*x^3*sqrt(d - c^2*d*x^2))/(9*g^3*sqrt(1 - c^2*x^2)) + (b*c^5*d^2*x^4*sqrt(d - c^2*d*x^2))/(16*g^2*sqrt(1 - c^2*x^2)) - (4*b*c^2*d^2*f*(c*f - g)*(c*f + g)*sqrt(d - c^2*d*x^2)*acos(c*x))/g^5 - (b*d^2*(c^2*f^2 - g^2)^2*sqrt(d - c^2*d*x^2)*acos(c*x))/(g^5*(f + g*x)) + (b*c^3*d^2*f^2*(c*f - g)*(c*f + g)*sqrt(d - c^2*d*x^2)*acos(c*x)^2)/(2*g^6*sqrt(1 - c^2*x^2)) - (c^2*d^2*x*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(8*g^2) + (c^2*d^2*(3*c^2*f^2 - 2*g^2)*x*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(2*g^4) + (c^4*d^2*x^3*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(4*g^2) + (2*c^2*d^2*f*(1 - c^2*x^2)*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x)))/(3*g^3) - (c*d^2*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(16*b*g^2*sqrt(1 - c^2*x^2)) - (c*d^2*(3*c^2*f^2 - 2*g^2)*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(4*b*g^4*sqrt(1 - c^2*x^2)) + (2*c^3*d^2*f*(c*f - g)*(c*f + g)*x*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(b*g^5*sqrt(1 - c^2*x^2)) - (d^2*(c*f - g)*(c*f + g)*(g + c^2*f*x)^2*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(2*b*c*g^4*(f + g*x)^2*sqrt(1 - c^2*x^2)) + (2*c*d^2*f*(c^2*f^2 - g^2)^2*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(b*g^6*(f + g*x)*sqrt(1 - c^2*x^2)) - (d^2*(c^2*f^2 - g^2)^2*sqrt(1 - c^2*x^2)*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(2*b*c*g^4*(f + g*x)^2) + (2*c*d^2*f*(c*f - g)*(c*f + g)*sqrt(1 - c^2*x^2)*sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))^2)/(b*g^4*(f + g*x)) - (a*c^3*d^2*f^2*(c*f - g)*(c*f + g)*sqrt(d - c^2*d*x^2)*asin(c*x))/(g^6*sqrt(1 - c^2*x^2)) + (5*a*c^2*d^2*f*(c^2*f^2 - g^2)^(3/2)*sqrt(d - c^2*d*x^2)*atan((g + c^2*f*x)/(sqrt(c^2*f^2 - g^2)*sqrt(1 - c^2*x^2))))/(g^6*sqrt(1 - c^2*x^2)) + (5*im*b*c^2*d^2*f*(c^2*f^2 - g^2)^(3/2)*sqrt(d - c^2*d*x^2)*acos(c*x)*log(1 + (ℯ^(im*acos(c*x))*g)/(c*f - sqrt(c^2*f^2 - g^2))))/(g^6*sqrt(1 - c^2*x^2)) - (5*im*b*c^2*d^2*f*(c^2*f^2 - g^2)^(3/2)*sqrt(d - c^2*d*x^2)*acos(c*x)*log(1 + (ℯ^(im*acos(c*x))*g)/(c*f + sqrt(c^2*f^2 - g^2))))/(g^6*sqrt(1 - c^2*x^2)) - (b*c*d^2*(c^2*f^2 - g^2)^2*sqrt(d - c^2*d*x^2)*log(f + g*x))/(g^6*sqrt(1 - c^2*x^2)) + (5*b*c^2*d^2*f*(c^2*f^2 - g^2)^(3/2)*sqrt(d - c^2*d*x^2)*PolyLog(2, -((ℯ^(im*acos(c*x))*g)/(c*f - sqrt(c^2*f^2 - g^2)))))/(g^6*sqrt(1 - c^2*x^2)) - (5*b*c^2*d^2*f*(c^2*f^2 - g^2)^(3/2)*sqrt(d - c^2*d*x^2)*PolyLog(2, -((ℯ^(im*acos(c*x))*g)/(c*f + sqrt(c^2*f^2 - g^2)))))/(g^6*sqrt(1 - c^2*x^2))] =#

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

    @test_int [1/sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))*(f + g*x)^3, x, 13, -((3*b*f^2*g*x*sqrt(1 - c^2*x^2))/(c*sqrt(d - c^2*d*x^2))) - (2*b*g^3*x*sqrt(1 - c^2*x^2))/(3*c^3*sqrt(d - c^2*d*x^2)) - (3*b*f*g^2*x^2*sqrt(1 - c^2*x^2))/(4*c*sqrt(d - c^2*d*x^2)) - (b*g^3*x^3*sqrt(1 - c^2*x^2))/(9*c*sqrt(d - c^2*d*x^2)) - (3*f^2*g*(1 - c^2*x^2)*(a + b*acos(c*x)))/(c^2*sqrt(d - c^2*d*x^2)) - (2*g^3*(1 - c^2*x^2)*(a + b*acos(c*x)))/(3*c^4*sqrt(d - c^2*d*x^2)) - (3*f*g^2*x*(1 - c^2*x^2)*(a + b*acos(c*x)))/(2*c^2*sqrt(d - c^2*d*x^2)) - (g^3*x^2*(1 - c^2*x^2)*(a + b*acos(c*x)))/(3*c^2*sqrt(d - c^2*d*x^2)) - (f^3*sqrt(1 - c^2*x^2)*(a + b*acos(c*x))^2)/(2*b*c*sqrt(d - c^2*d*x^2)) - (3*f*g^2*sqrt(1 - c^2*x^2)*(a + b*acos(c*x))^2)/(4*b*c^3*sqrt(d - c^2*d*x^2))]
    @test_int [1/sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))*(f + g*x)^2, x, 9, -((2*b*f*g*x*sqrt(1 - c^2*x^2))/(c*sqrt(d - c^2*d*x^2))) - (b*g^2*x^2*sqrt(1 - c^2*x^2))/(4*c*sqrt(d - c^2*d*x^2)) - (2*f*g*(1 - c^2*x^2)*(a + b*acos(c*x)))/(c^2*sqrt(d - c^2*d*x^2)) - (g^2*x*(1 - c^2*x^2)*(a + b*acos(c*x)))/(2*c^2*sqrt(d - c^2*d*x^2)) - (f^2*sqrt(1 - c^2*x^2)*(a + b*acos(c*x))^2)/(2*b*c*sqrt(d - c^2*d*x^2)) - (g^2*sqrt(1 - c^2*x^2)*(a + b*acos(c*x))^2)/(4*b*c^3*sqrt(d - c^2*d*x^2))]
    @test_int [1/sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))*(f + g*x)^1, x, 6, -((b*g*x*sqrt(1 - c^2*x^2))/(c*sqrt(d - c^2*d*x^2))) - (g*(1 - c^2*x^2)*(a + b*acos(c*x)))/(c^2*sqrt(d - c^2*d*x^2)) - (f*sqrt(1 - c^2*x^2)*(a + b*acos(c*x))^2)/(2*b*c*sqrt(d - c^2*d*x^2))]
    @test_int [1/sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))/(f + g*x)^1, x, 10, (im*sqrt(1 - c^2*x^2)*(a + b*acos(c*x))*log(1 + (ℯ^(im*acos(c*x))*g)/(c*f - sqrt(c^2*f^2 - g^2))))/(sqrt(c^2*f^2 - g^2)*sqrt(d - c^2*d*x^2)) - (im*sqrt(1 - c^2*x^2)*(a + b*acos(c*x))*log(1 + (ℯ^(im*acos(c*x))*g)/(c*f + sqrt(c^2*f^2 - g^2))))/(sqrt(c^2*f^2 - g^2)*sqrt(d - c^2*d*x^2)) + (b*sqrt(1 - c^2*x^2)*PolyLog(2, -((ℯ^(im*acos(c*x))*g)/(c*f - sqrt(c^2*f^2 - g^2)))))/(sqrt(c^2*f^2 - g^2)*sqrt(d - c^2*d*x^2)) - (b*sqrt(1 - c^2*x^2)*PolyLog(2, -((ℯ^(im*acos(c*x))*g)/(c*f + sqrt(c^2*f^2 - g^2)))))/(sqrt(c^2*f^2 - g^2)*sqrt(d - c^2*d*x^2))]
    @test_int [1/sqrt(d - c^2*d*x^2)*(a + b*acos(c*x))/(f + g*x)^2, x, 13, (g*(1 - c^2*x^2)*(a + b*acos(c*x)))/((c^2*f^2 - g^2)*(f + g*x)*sqrt(d - c^2*d*x^2)) + (im*c^2*f*sqrt(1 - c^2*x^2)*(a + b*acos(c*x))*log(1 + (ℯ^(im*acos(c*x))*g)/(c*f - sqrt(c^2*f^2 - g^2))))/((c^2*f^2 - g^2)^(3/2)*sqrt(d - c^2*d*x^2)) - (im*c^2*f*sqrt(1 - c^2*x^2)*(a + b*acos(c*x))*log(1 + (ℯ^(im*acos(c*x))*g)/(c*f + sqrt(c^2*f^2 - g^2))))/((c^2*f^2 - g^2)^(3/2)*sqrt(d - c^2*d*x^2)) + (b*c*sqrt(1 - c^2*x^2)*log(f + g*x))/((c^2*f^2 - g^2)*sqrt(d - c^2*d*x^2)) + (b*c^2*f*sqrt(1 - c^2*x^2)*PolyLog(2, -((ℯ^(im*acos(c*x))*g)/(c*f - sqrt(c^2*f^2 - g^2)))))/((c^2*f^2 - g^2)^(3/2)*sqrt(d - c^2*d*x^2)) - (b*c^2*f*sqrt(1 - c^2*x^2)*PolyLog(2, -((ℯ^(im*acos(c*x))*g)/(c*f + sqrt(c^2*f^2 - g^2)))))/((c^2*f^2 - g^2)^(3/2)*sqrt(d - c^2*d*x^2))]

    #= ::Subsection:: =#
    #=Integrands*of*the*form*(f+g*x)^m*(d-c^2*d*x^2)^(p/2)*(a+b*acos(c*x))^2=#

    #= ::Section::Closed:: =#
    #=Integrands*of*the*form*log(h*(f + g*x)^m)*(d+e*x^2)^p*(a+b*acos(c*x))^n*where*c^2*d+e=0=#

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*log(h*(f + g*x)^m)*(d-c^2*d*x^2)^(p/2)*(a+b*acos(c*x))^n=#

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

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

    @test_int [log(h*(f + g*x)^m)*(a + b*acos(c*x))^n/sqrt(1 - c^2*x^2), x, 0, Unintegrable(((a + b*acos(c*x))^n*log(h*(f + g*x)^m))/sqrt(1 - c^2*x^2), x)]

    #= [log(h*(f + g*x)^m)*(a + b*acos(c*x))^3/sqrt(1 - c^2*x^2), x, 18, -((im*m*(a + b*acos(c*x))^5)/(20*b^2*c)) + (m*(a + b*acos(c*x))^4*log(1 + (ℯ^(im*acos(c*x))*g)/(c*f - sqrt(c^2*f^2 - g^2))))/(4*b*c) + (m*(a + b*acos(c*x))^4*log(1 + (ℯ^(im*acos(c*x))*g)/(c*f + sqrt(c^2*f^2 - g^2))))/(4*b*c) - ((a + b*acos(c*x))^4*log(h*(f + g*x)^m))/(4*b*c) - (im*m*(a + b*acos(c*x))^3*PolyLog(2, -((ℯ^(im*acos(c*x))*g)/(c*f - sqrt(c^2*f^2 - g^2)))))/c - (im*m*(a + b*acos(c*x))^3*PolyLog(2, -((ℯ^(im*acos(c*x))*g)/(c*f + sqrt(c^2*f^2 - g^2)))))/c + (3*b*m*(a + b*acos(c*x))^2*PolyLog(3, -((ℯ^(im*acos(c*x))*g)/(c*f - sqrt(c^2*f^2 - g^2)))))/c + (3*b*m*(a + b*acos(c*x))^2*PolyLog(3, -((ℯ^(im*acos(c*x))*g)/(c*f + sqrt(c^2*f^2 - g^2)))))/c + (6*im*b^2*m*(a + b*acos(c*x))*PolyLog(4, -((ℯ^(im*acos(c*x))*g)/(c*f - sqrt(c^2*f^2 - g^2)))))/c + (6*im*b^2*m*(a + b*acos(c*x))*PolyLog(4, -((ℯ^(im*acos(c*x))*g)/(c*f + sqrt(c^2*f^2 - g^2)))))/c - (6*b^3*m*PolyLog(5, -((ℯ^(im*acos(c*x))*g)/(c*f - sqrt(c^2*f^2 - g^2)))))/c - (6*b^3*m*PolyLog(5, -((ℯ^(im*acos(c*x))*g)/(c*f + sqrt(c^2*f^2 - g^2)))))/c] =#
    @test_int [log(h*(f + g*x)^m)*(a + b*acos(c*x))^2/sqrt(1 - c^2*x^2), x, 13, -((im*m*(a + b*acos(c*x))^4)/(12*b^2*c)) + (m*(a + b*acos(c*x))^3*log(1 + (ℯ^(im*acos(c*x))*g)/(c*f - sqrt(c^2*f^2 - g^2))))/(3*b*c) + (m*(a + b*acos(c*x))^3*log(1 + (ℯ^(im*acos(c*x))*g)/(c*f + sqrt(c^2*f^2 - g^2))))/(3*b*c) - ((a + b*acos(c*x))^3*log(h*(f + g*x)^m))/(3*b*c) - (im*m*(a + b*acos(c*x))^2*PolyLog(2, -((ℯ^(im*acos(c*x))*g)/(c*f - sqrt(c^2*f^2 - g^2)))))/c - (im*m*(a + b*acos(c*x))^2*PolyLog(2, -((ℯ^(im*acos(c*x))*g)/(c*f + sqrt(c^2*f^2 - g^2)))))/c + (2*b*m*(a + b*acos(c*x))*PolyLog(3, -((ℯ^(im*acos(c*x))*g)/(c*f - sqrt(c^2*f^2 - g^2)))))/c + (2*b*m*(a + b*acos(c*x))*PolyLog(3, -((ℯ^(im*acos(c*x))*g)/(c*f + sqrt(c^2*f^2 - g^2)))))/c + (2*im*b^2*m*PolyLog(4, -((ℯ^(im*acos(c*x))*g)/(c*f - sqrt(c^2*f^2 - g^2)))))/c + (2*im*b^2*m*PolyLog(4, -((ℯ^(im*acos(c*x))*g)/(c*f + sqrt(c^2*f^2 - g^2)))))/c]
    @test_int [log(h*(f + g*x)^m)*(a + b*acos(c*x))^1/sqrt(1 - c^2*x^2), x, 11, -((im*m*(a + b*acos(c*x))^3)/(6*b^2*c)) + (m*(a + b*acos(c*x))^2*log(1 + (ℯ^(im*acos(c*x))*g)/(c*f - sqrt(c^2*f^2 - g^2))))/(2*b*c) + (m*(a + b*acos(c*x))^2*log(1 + (ℯ^(im*acos(c*x))*g)/(c*f + sqrt(c^2*f^2 - g^2))))/(2*b*c) - ((a + b*acos(c*x))^2*log(h*(f + g*x)^m))/(2*b*c) - (im*m*(a + b*acos(c*x))*PolyLog(2, -((ℯ^(im*acos(c*x))*g)/(c*f - sqrt(c^2*f^2 - g^2)))))/c - (im*m*(a + b*acos(c*x))*PolyLog(2, -((ℯ^(im*acos(c*x))*g)/(c*f + sqrt(c^2*f^2 - g^2)))))/c + (b*m*PolyLog(3, -((ℯ^(im*acos(c*x))*g)/(c*f - sqrt(c^2*f^2 - g^2)))))/c + (b*m*PolyLog(3, -((ℯ^(im*acos(c*x))*g)/(c*f + sqrt(c^2*f^2 - g^2)))))/c]
    @test_int [log(h*(f + g*x)^m)*(a + b*acos(c*x))^0/sqrt(1 - c^2*x^2), x, 9, (im*m*asin(c*x)^2)/(2*c) - (m*asin(c*x)*log(1 - (im*ℯ^(im*asin(c*x))*g)/(c*f - sqrt(c^2*f^2 - g^2))))/c - (m*asin(c*x)*log(1 - (im*ℯ^(im*asin(c*x))*g)/(c*f + sqrt(c^2*f^2 - g^2))))/c + (asin(c*x)*log(h*(f + g*x)^m))/c + (im*m*PolyLog(2, (im*ℯ^(im*asin(c*x))*g)/(c*f - sqrt(c^2*f^2 - g^2))))/c + (im*m*PolyLog(2, (im*ℯ^(im*asin(c*x))*g)/(c*f + sqrt(c^2*f^2 - g^2))))/c]
    @test_int [log(h*(f + g*x)^m)/(a + b*acos(c*x))^1/sqrt(1 - c^2*x^2), x, 0, Unintegrable(log(h*(f + g*x)^m)/(sqrt(1 - c^2*x^2)*(a + b*acos(c*x))), x)]

    #= ::Title:: =#
    #=Integrands*Involving*Inverse*Cosines=#

    #= ::Section::Closed:: =#
    #=Integrands*of*the*form*u*(a+b*acos(c+d*x))^n=#

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*x^m*acos(a+b*x)^n=#

    @test_int [x^3*acos(a + b*x), x, 6, (7*a*x^2*sqrt(1 - (a + b*x)^2))/(48*b^2) - (x^3*sqrt(1 - (a + b*x)^2))/(16*b) + ((4*a*(16 + 19*a^2) - (9 + 26*a^2)*(a + b*x))*sqrt(1 - (a + b*x)^2))/(96*b^4) + (1/4)*x^4*acos(a + b*x) + ((3 + 24*a^2 + 8*a^4)*asin(a + b*x))/(32*b^4)]
    @test_int [x^2*acos(a + b*x), x, 5, -((x^2*sqrt(1 - (a + b*x)^2))/(9*b)) - ((4 + 11*a^2 - 5*a*b*x)*sqrt(1 - (a + b*x)^2))/(18*b^3) + (1/3)*x^3*acos(a + b*x) - (a*(3 + 2*a^2)*asin(a + b*x))/(6*b^3)]
    @test_int [x^1*acos(a + b*x), x, 5, (3*a*sqrt(1 - (a + b*x)^2))/(4*b^2) - (x*sqrt(1 - (a + b*x)^2))/(4*b) + (1/2)*x^2*acos(a + b*x) + ((1 + 2*a^2)*asin(a + b*x))/(4*b^2)]
    @test_int [x^0*acos(a + b*x), x, 3, -(sqrt(1 - (a + b*x)^2)/b) + ((a + b*x)*acos(a + b*x))/b]
    @test_int [acos(a + b*x)/x^1, x, 9, (-(1/2))*im*acos(a + b*x)^2 + acos(a + b*x)*log(1 - ℯ^(im*acos(a + b*x))/(a - im*sqrt(1 - a^2))) + acos(a + b*x)*log(1 - ℯ^(im*acos(a + b*x))/(a + im*sqrt(1 - a^2))) - im*PolyLog(2, ℯ^(im*acos(a + b*x))/(a - im*sqrt(1 - a^2))) - im*PolyLog(2, ℯ^(im*acos(a + b*x))/(a + im*sqrt(1 - a^2)))]
    @test_int [acos(a + b*x)/x^2, x, 4, -(acos(a + b*x)/x) + (b*atanh((1 - a*(a + b*x))/(sqrt(1 - a^2)*sqrt(1 - (a + b*x)^2))))/sqrt(1 - a^2)]
    @test_int [acos(a + b*x)/x^3, x, 5, (b*sqrt(1 - (a + b*x)^2))/(2*(1 - a^2)*x) - acos(a + b*x)/(2*x^2) + (a*b^2*atanh((1 - a*(a + b*x))/(sqrt(1 - a^2)*sqrt(1 - (a + b*x)^2))))/(2*(1 - a^2)^(3/2))]
    @test_int [acos(a + b*x)/x^4, x, 6, (b*sqrt(1 - (a + b*x)^2))/(6*(1 - a^2)*x^2) + (a*b^2*sqrt(1 - (a + b*x)^2))/(2*(1 - a^2)^2*x) - acos(a + b*x)/(3*x^3) + ((1 + 2*a^2)*b^3*atanh((1 - a*(a + b*x))/(sqrt(1 - a^2)*sqrt(1 - (a + b*x)^2))))/(6*(1 - a^2)^(5/2))]

    @test_int [acos(a + b*x)^3, x, 5, (6*sqrt(1 - (a + b*x)^2))/b - (6*(a + b*x)*acos(a + b*x))/b - (3*sqrt(1 - (a + b*x)^2)*acos(a + b*x)^2)/b + ((a + b*x)*acos(a + b*x)^3)/b]
    @test_int [acos(a + b*x)^2, x, 4, -2*x - (2*sqrt(1 - (a + b*x)^2)*acos(a + b*x))/b + ((a + b*x)*acos(a + b*x)^2)/b]
    @test_int [1/acos(a + b*x), x, 3, -(SinIntegral(acos(a + b*x))/b)]
    @test_int [1/acos(a + b*x)^2, x, 4, sqrt(1 - (a + b*x)^2)/(b*acos(a + b*x)) - CosIntegral(acos(a + b*x))/b]
    @test_int [1/acos(a + b*x)^3, x, 5, sqrt(1 - (a + b*x)^2)/(2*b*acos(a + b*x)^2) + (a + b*x)/(2*b*acos(a + b*x)) + SinIntegral(acos(a + b*x))/(2*b)]

    @test_int [acos(a + b*x)^(5/2), x, 7, -((15*(a + b*x)*sqrt(acos(a + b*x)))/(4*b)) - (5*sqrt(1 - (a + b*x)^2)*acos(a + b*x)^(3/2))/(2*b) + ((a + b*x)*acos(a + b*x)^(5/2))/b + (15*sqrt(pi/2)*FresnelC(sqrt(2/pi)*sqrt(acos(a + b*x))))/(4*b)]
    @test_int [acos(a + b*x)^(3/2), x, 6, -((3*sqrt(1 - (a + b*x)^2)*sqrt(acos(a + b*x)))/(2*b)) + ((a + b*x)*acos(a + b*x)^(3/2))/b + (3*sqrt(pi/2)*FresnelS(sqrt(2/pi)*sqrt(acos(a + b*x))))/(2*b)]
    @test_int [acos(a + b*x)^(1/2), x, 5, ((a + b*x)*sqrt(acos(a + b*x)))/b - (sqrt(pi/2)*FresnelC(sqrt(2/pi)*sqrt(acos(a + b*x))))/b]
    @test_int [1/acos(a + b*x)^(1/2), x, 4, -((sqrt(2*pi)*FresnelS(sqrt(2/pi)*sqrt(acos(a + b*x))))/b)]
    @test_int [1/acos(a + b*x)^(3/2), x, 5, (2*sqrt(1 - (a + b*x)^2))/(b*sqrt(acos(a + b*x))) - (2*sqrt(2*pi)*FresnelC(sqrt(2/pi)*sqrt(acos(a + b*x))))/b]
    @test_int [1/acos(a + b*x)^(5/2), x, 6, (2*sqrt(1 - (a + b*x)^2))/(3*b*acos(a + b*x)^(3/2)) + (4*(a + b*x))/(3*b*sqrt(acos(a + b*x))) + (4*sqrt(2*pi)*FresnelS(sqrt(2/pi)*sqrt(acos(a + b*x))))/(3*b)]

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

    @test_int [1/sqrt(a + b*acos(c + d*x)), x, 7, -((sqrt(2*pi)*cos(a/b)*FresnelS((sqrt(2/pi)*sqrt(a + b*acos(c + d*x)))/sqrt(b)))/(sqrt(b)*d)) + (sqrt(2*pi)*FresnelC((sqrt(2/pi)*sqrt(a + b*acos(c + d*x)))/sqrt(b))*sin(a/b))/(sqrt(b)*d)]
    @test_int [1/sqrt(a - b*acos(c + d*x)), x, 7, -((sqrt(2*pi)*cos(a/b)*FresnelS((sqrt(2/pi)*sqrt(a - b*acos(c + d*x)))/sqrt(b)))/(sqrt(b)*d)) + (sqrt(2*pi)*FresnelC((sqrt(2/pi)*sqrt(a - b*acos(c + d*x)))/sqrt(b))*sin(a/b))/(sqrt(b)*d)]

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

    @test_int [acos(a + b*x)/((a*d)/b + d*x), x, 7, -((im*acos(a + b*x)^2)/(2*d)) + (acos(a + b*x)*log(1 + ℯ^(2*im*acos(a + b*x))))/d - (im*PolyLog(2, -ℯ^(2*im*acos(a + b*x))))/(2*d)]

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*(1-(a+b*x)^2)^(m/2)*acos(a+b*x)^n=#

    @test_int [sqrt(1 - x^2)*acos(x), x, 3, x^2/4 + (1/2)*x*sqrt(1 - x^2)*acos(x) - acos(x)^2/4]

    #= ::Section::Closed:: =#
    #=Integrands*of*the*form*u*acos(a+b*x^n)=#

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*x^m*acos(a*x^n)=#

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

    @test_int [x^3*acos(a*x^2), x, 5, -((x^2*sqrt(1 - a^2*x^4))/(8*a)) + (1/4)*x^4*acos(a*x^2) + asin(a*x^2)/(8*a^2)]
    @test_int [x^2*acos(a*x^2), x, 4, -((2*x*sqrt(1 - a^2*x^4))/(9*a)) + (1/3)*x^3*acos(a*x^2) + (2*Elliptic.F(asin(sqrt(a)*x), -1))/(9*a^(3/2))]
    @test_int [x^1*acos(a*x^2), x, 3, -(sqrt(1 - a^2*x^4)/(2*a)) + (1/2)*x^2*acos(a*x^2)]
    @test_int [x^0*acos(a*x^2), x, 6, x*acos(a*x^2) + (2*Elliptic.E(asin(sqrt(a)*x), -1))/sqrt(a) - (2*Elliptic.F(asin(sqrt(a)*x), -1))/sqrt(a)]
    @test_int [acos(a*x^2)/x^1, x, 5, (-(1/4))*im*acos(a*x^2)^2 + (1/2)*acos(a*x^2)*log(1 + ℯ^(2*im*acos(a*x^2))) - (1/4)*im*PolyLog(2, -ℯ^(2*im*acos(a*x^2)))]
    @test_int [acos(a*x^2)/x^2, x, 3, -(acos(a*x^2)/x) - 2*sqrt(a)*Elliptic.F(asin(sqrt(a)*x), -1)]

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

    @test_int [x^2*acos(a/x), x, 6, (-(1/6))*a*sqrt(1 - a^2/x^2)*x^2 + (1/3)*x^3*asec(x/a) - (1/6)*a^3*atanh(sqrt(1 - a^2/x^2))]
    @test_int [x^1*acos(a/x), x, 3, (-(1/2))*a*sqrt(1 - a^2/x^2)*x + (1/2)*x^2*asec(x/a)]
    @test_int [x^0*acos(a/x), x, 5, x*asec(x/a) - a*atanh(sqrt(1 - a^2/x^2))]
    @test_int [acos(a/x)/x^1, x, 5, (1/2)*im*acos(a/x)^2 - acos(a/x)*log(1 + ℯ^(2*im*acos(a/x))) + (1/2)*im*PolyLog(2, -ℯ^(2*im*acos(a/x)))]
    @test_int [acos(a/x)/x^2, x, 3, sqrt(1 - a^2/x^2)/a - asec(x/a)/x]
    @test_int [acos(a/x)/x^3, x, 5, sqrt(1 - a^2/x^2)/(4*a*x) - acsc(x/a)/(4*a^2) - asec(x/a)/(2*x^2)]
    @test_int [acos(a/x)/x^4, x, 5, sqrt(1 - a^2/x^2)/(3*a^3) - (1 - a^2/x^2)^(3/2)/(9*a^3) - asec(x/a)/(3*x^3)]

    #= ::Subsubsection::Closed:: =#
    #=n/2>0=#

    @test_int [x^2*acos(sqrt(x)), x, 8, (-(5/48))*sqrt(1 - x)*sqrt(x) - (5/72)*sqrt(1 - x)*x^(3/2) - (1/18)*sqrt(1 - x)*x^(5/2) + (1/3)*x^3*acos(sqrt(x)) - (5/96)*asin(1 - 2*x)]
    @test_int [x^1*acos(sqrt(x)), x, 7, (-(3/16))*sqrt(1 - x)*sqrt(x) - (1/8)*sqrt(1 - x)*x^(3/2) + (1/2)*x^2*acos(sqrt(x)) - (3/32)*asin(1 - 2*x)]
    @test_int [x^0*acos(sqrt(x)), x, 6, (-(1/2))*sqrt(1 - x)*sqrt(x) + x*acos(sqrt(x)) - (1/4)*asin(1 - 2*x)]
    @test_int [acos(sqrt(x))/x^1, x, 5, (-im)*acos(sqrt(x))^2 + 2*acos(sqrt(x))*log(1 + ℯ^(2*im*acos(sqrt(x)))) - im*PolyLog(2, -ℯ^(2*im*acos(sqrt(x))))]
    @test_int [acos(sqrt(x))/x^2, x, 3, sqrt(1 - x)/sqrt(x) - acos(sqrt(x))/x]
    @test_int [acos(sqrt(x))/x^3, x, 4, sqrt(1 - x)/(6*x^(3/2)) + sqrt(1 - x)/(3*sqrt(x)) - acos(sqrt(x))/(2*x^2)]
    @test_int [acos(sqrt(x))/x^4, x, 5, sqrt(1 - x)/(15*x^(5/2)) + (4*sqrt(1 - x))/(45*x^(3/2)) + (8*sqrt(1 - x))/(45*sqrt(x)) - acos(sqrt(x))/(3*x^3)]
    @test_int [acos(sqrt(x))/x^5, x, 6, sqrt(1 - x)/(28*x^(7/2)) + (3*sqrt(1 - x))/(70*x^(5/2)) + (2*sqrt(1 - x))/(35*x^(3/2)) + (4*sqrt(1 - x))/(35*sqrt(x)) - acos(sqrt(x))/(4*x^4)]

    @test_int [acos(sqrt(x))/sqrt(x), x, 3, -2*sqrt(1 - x) + 2*sqrt(x)*acos(sqrt(x))]

    #= ::Subsubsection:: =#
    #=n/2<0=#

    #= ::Subsubsection::Closed:: =#
    #=n*symbolic=#

    @test_int [acos(a*x^n)/x, x, 5, -((im*acos(a*x^n)^2)/(2*n)) + (acos(a*x^n)*log(1 + ℯ^(2*im*acos(a*x^n))))/n - (im*PolyLog(2, -ℯ^(2*im*acos(a*x^n))))/(2*n)]
    @test_int [acos(a*x^5)/x, x, 5, (-(1/10))*im*acos(a*x^5)^2 + (1/5)*acos(a*x^5)*log(1 + ℯ^(2*im*acos(a*x^5))) - (1/10)*im*PolyLog(2, -ℯ^(2*im*acos(a*x^5)))]

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*u*acos(a+b*x^n)=#

    @test_int [x^3*acos(a + b*x^4), x, 4, -(sqrt(1 - (a + b*x^4)^2)/(4*b)) + ((a + b*x^4)*acos(a + b*x^4))/(4*b)]

    @test_int [x^(n-1)*acos(a + b*x^n), x, 4, -(sqrt(1 - (a + b*x^n)^2)/(b*n)) + ((a + b*x^n)*acos(a + b*x^n))/(b*n)]

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

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*(a+b*acos(c+d*x^2))^n*when*c^2=1=#

    @test_int [(a + b*acos(1 + d*x^2))^4, x, 3, 384*b^4*x + (192*b^3*sqrt(-2*d*x^2 - d^2*x^4)*(a + b*acos(1 + d*x^2)))/(d*x) - 48*b^2*x*(a + b*acos(1 + d*x^2))^2 - (8*b*sqrt(-2*d*x^2 - d^2*x^4)*(a + b*acos(1 + d*x^2))^3)/(d*x) + x*(a + b*acos(1 + d*x^2))^4]
    @test_int [(a + b*acos(1 + d*x^2))^3, x, 5, -24*a*b^2*x + (48*b^3*sqrt(-2*d*x^2 - d^2*x^4))/(d*x) - 24*b^3*x*acos(1 + d*x^2) - (6*b*sqrt(-2*d*x^2 - d^2*x^4)*(a + b*acos(1 + d*x^2))^2)/(d*x) + x*(a + b*acos(1 + d*x^2))^3]
    @test_int [(a + b*acos(1 + d*x^2))^2, x, 2, -8*b^2*x - (4*b*sqrt(-2*d*x^2 - d^2*x^4)*(a + b*acos(1 + d*x^2)))/(d*x) + x*(a + b*acos(1 + d*x^2))^2]
    @test_int [(a + b*acos(1 + d*x^2))^1, x, 4, a*x - (2*b*sqrt(-2*d*x^2 - d^2*x^4))/(d*x) + b*x*acos(1 + d*x^2)]
    @test_int [1/(a + b*acos(1 + d*x^2))^1, x, 1, (x*cos(a/(2*b))*CosIntegral((a + b*acos(1 + d*x^2))/(2*b)))/(sqrt(2)*b*sqrt((-d)*x^2)) + (x*sin(a/(2*b))*SinIntegral((a + b*acos(1 + d*x^2))/(2*b)))/(sqrt(2)*b*sqrt((-d)*x^2))]
    @test_int [1/(a + b*acos(1 + d*x^2))^2, x, 1, sqrt(-2*d*x^2 - d^2*x^4)/(2*b*d*x*(a + b*acos(1 + d*x^2))) + (x*CosIntegral((a + b*acos(1 + d*x^2))/(2*b))*sin(a/(2*b)))/(2*sqrt(2)*b^2*sqrt((-d)*x^2)) - (x*cos(a/(2*b))*SinIntegral((a + b*acos(1 + d*x^2))/(2*b)))/(2*sqrt(2)*b^2*sqrt((-d)*x^2))]
    @test_int [1/(a + b*acos(1 + d*x^2))^3, x, 2, sqrt(-2*d*x^2 - d^2*x^4)/(4*b*d*x*(a + b*acos(1 + d*x^2))^2) + x/(8*b^2*(a + b*acos(1 + d*x^2))) - (x*cos(a/(2*b))*CosIntegral((a + b*acos(1 + d*x^2))/(2*b)))/(8*sqrt(2)*b^3*sqrt((-d)*x^2)) - (x*sin(a/(2*b))*SinIntegral((a + b*acos(1 + d*x^2))/(2*b)))/(8*sqrt(2)*b^3*sqrt((-d)*x^2))]

    @test_int [(a + b*acos(-1 + d*x^2))^4, x, 3, 384*b^4*x + (192*b^3*sqrt(2*d*x^2 - d^2*x^4)*(a + b*acos(-1 + d*x^2)))/(d*x) - 48*b^2*x*(a + b*acos(-1 + d*x^2))^2 - (8*b*sqrt(2*d*x^2 - d^2*x^4)*(a + b*acos(-1 + d*x^2))^3)/(d*x) + x*(a + b*acos(-1 + d*x^2))^4]
    @test_int [(a + b*acos(-1 + d*x^2))^3, x, 5, -24*a*b^2*x + (48*b^3*sqrt(2*d*x^2 - d^2*x^4))/(d*x) - 24*b^3*x*acos(-1 + d*x^2) - (6*b*sqrt(2*d*x^2 - d^2*x^4)*(a + b*acos(-1 + d*x^2))^2)/(d*x) + x*(a + b*acos(-1 + d*x^2))^3]
    @test_int [(a + b*acos(-1 + d*x^2))^2, x, 2, -8*b^2*x - (4*b*sqrt(2*d*x^2 - d^2*x^4)*(a + b*acos(-1 + d*x^2)))/(d*x) + x*(a + b*acos(-1 + d*x^2))^2]
    @test_int [(a + b*acos(-1 + d*x^2))^1, x, 4, a*x - (2*b*sqrt(2*d*x^2 - d^2*x^4))/(d*x) + b*x*acos(-1 + d*x^2)]
    @test_int [1/(a + b*acos(-1 + d*x^2))^1, x, 1, (x*CosIntegral((a + b*acos(-1 + d*x^2))/(2*b))*sin(a/(2*b)))/(sqrt(2)*b*sqrt(d*x^2)) - (x*cos(a/(2*b))*SinIntegral((a + b*acos(-1 + d*x^2))/(2*b)))/(sqrt(2)*b*sqrt(d*x^2))]
    @test_int [1/(a + b*acos(-1 + d*x^2))^2, x, 1, sqrt(2*d*x^2 - d^2*x^4)/(2*b*d*x*(a + b*acos(-1 + d*x^2))) - (x*cos(a/(2*b))*CosIntegral((a + b*acos(-1 + d*x^2))/(2*b)))/(2*sqrt(2)*b^2*sqrt(d*x^2)) - (x*sin(a/(2*b))*SinIntegral((a + b*acos(-1 + d*x^2))/(2*b)))/(2*sqrt(2)*b^2*sqrt(d*x^2))]
    @test_int [1/(a + b*acos(-1 + d*x^2))^3, x, 2, sqrt(2*d*x^2 - d^2*x^4)/(4*b*d*x*(a + b*acos(-1 + d*x^2))^2) + x/(8*b^2*(a + b*acos(-1 + d*x^2))) - (x*CosIntegral((a + b*acos(-1 + d*x^2))/(2*b))*sin(a/(2*b)))/(8*sqrt(2)*b^3*sqrt(d*x^2)) + (x*cos(a/(2*b))*SinIntegral((a + b*acos(-1 + d*x^2))/(2*b)))/(8*sqrt(2)*b^3*sqrt(d*x^2))]

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*(a+b*acos(c+d*x^2))^(n/2)*when*c^2=1=#

    @test_int [(a + b*acos(1 + d*x^2))^(5/2), x, 2, -((5*b*sqrt(-2*d*x^2 - d^2*x^4)*(a + b*acos(1 + d*x^2))^(3/2))/(d*x)) + x*(a + b*acos(1 + d*x^2))^(5/2) - (30*sqrt(pi)*cos(a/(2*b))*FresnelS((sqrt(1/b)*sqrt(a + b*acos(1 + d*x^2)))/sqrt(pi))*sin((1/2)*acos(1 + d*x^2)))/((1/b)^(5/2)*d*x) + (30*sqrt(pi)*FresnelC((sqrt(1/b)*sqrt(a + b*acos(1 + d*x^2)))/sqrt(pi))*sin(a/(2*b))*sin((1/2)*acos(1 + d*x^2)))/((1/b)^(5/2)*d*x) + (30*b^2*sqrt(a + b*acos(1 + d*x^2))*sin((1/2)*acos(1 + d*x^2))^2)/(d*x)]
    @test_int [(a + b*acos(1 + d*x^2))^(3/2), x, 2, -((3*b*sqrt(-2*d*x^2 - d^2*x^4)*sqrt(a + b*acos(1 + d*x^2)))/(d*x)) + x*(a + b*acos(1 + d*x^2))^(3/2) + (6*sqrt(pi)*cos(a/(2*b))*FresnelC((sqrt(1/b)*sqrt(a + b*acos(1 + d*x^2)))/sqrt(pi))*sin((1/2)*acos(1 + d*x^2)))/((1/b)^(3/2)*d*x) + (6*sqrt(pi)*FresnelS((sqrt(1/b)*sqrt(a + b*acos(1 + d*x^2)))/sqrt(pi))*sin(a/(2*b))*sin((1/2)*acos(1 + d*x^2)))/((1/b)^(3/2)*d*x)]
    @test_int [(a + b*acos(1 + d*x^2))^(1/2), x, 1, (2*sqrt(pi)*cos(a/(2*b))*FresnelS((sqrt(1/b)*sqrt(a + b*acos(1 + d*x^2)))/sqrt(pi))*sin((1/2)*acos(1 + d*x^2)))/(sqrt(1/b)*d*x) - (2*sqrt(pi)*FresnelC((sqrt(1/b)*sqrt(a + b*acos(1 + d*x^2)))/sqrt(pi))*sin(a/(2*b))*sin((1/2)*acos(1 + d*x^2)))/(sqrt(1/b)*d*x) - (2*sqrt(a + b*acos(1 + d*x^2))*sin((1/2)*acos(1 + d*x^2))^2)/(d*x)]
    @test_int [1/(a + b*acos(1 + d*x^2))^(1/2), x, 1, -((2*sqrt(1/b)*sqrt(pi)*cos(a/(2*b))*FresnelC((sqrt(1/b)*sqrt(a + b*acos(1 + d*x^2)))/sqrt(pi))*sin((1/2)*acos(1 + d*x^2)))/(d*x)) - (2*sqrt(1/b)*sqrt(pi)*FresnelS((sqrt(1/b)*sqrt(a + b*acos(1 + d*x^2)))/sqrt(pi))*sin(a/(2*b))*sin((1/2)*acos(1 + d*x^2)))/(d*x)]
    @test_int [1/(a + b*acos(1 + d*x^2))^(3/2), x, 1, sqrt(-2*d*x^2 - d^2*x^4)/(b*d*x*sqrt(a + b*acos(1 + d*x^2))) + (2*(1/b)^(3/2)*sqrt(pi)*cos(a/(2*b))*FresnelS((sqrt(1/b)*sqrt(a + b*acos(1 + d*x^2)))/sqrt(pi))*sin((1/2)*acos(1 + d*x^2)))/(d*x) - (2*(1/b)^(3/2)*sqrt(pi)*FresnelC((sqrt(1/b)*sqrt(a + b*acos(1 + d*x^2)))/sqrt(pi))*sin(a/(2*b))*sin((1/2)*acos(1 + d*x^2)))/(d*x)]
    @test_int [1/(a + b*acos(1 + d*x^2))^(5/2), x, 2, sqrt(-2*d*x^2 - d^2*x^4)/(3*b*d*x*(a + b*acos(1 + d*x^2))^(3/2)) + x/(3*b^2*sqrt(a + b*acos(1 + d*x^2))) + (2*(1/b)^(5/2)*sqrt(pi)*cos(a/(2*b))*FresnelC((sqrt(1/b)*sqrt(a + b*acos(1 + d*x^2)))/sqrt(pi))*sin((1/2)*acos(1 + d*x^2)))/(3*d*x) + (2*(1/b)^(5/2)*sqrt(pi)*FresnelS((sqrt(1/b)*sqrt(a + b*acos(1 + d*x^2)))/sqrt(pi))*sin(a/(2*b))*sin((1/2)*acos(1 + d*x^2)))/(3*d*x)]
    @test_int [1/(a + b*acos(1 + d*x^2))^(7/2), x, 2, sqrt(-2*d*x^2 - d^2*x^4)/(5*b*d*x*(a + b*acos(1 + d*x^2))^(5/2)) + x/(15*b^2*(a + b*acos(1 + d*x^2))^(3/2)) - sqrt(-2*d*x^2 - d^2*x^4)/(15*b^3*d*x*sqrt(a + b*acos(1 + d*x^2))) - (2*(1/b)^(7/2)*sqrt(pi)*cos(a/(2*b))*FresnelS((sqrt(1/b)*sqrt(a + b*acos(1 + d*x^2)))/sqrt(pi))*sin((1/2)*acos(1 + d*x^2)))/(15*d*x) + (2*(1/b)^(7/2)*sqrt(pi)*FresnelC((sqrt(1/b)*sqrt(a + b*acos(1 + d*x^2)))/sqrt(pi))*sin(a/(2*b))*sin((1/2)*acos(1 + d*x^2)))/(15*d*x)]

    @test_int [(a + b*acos(-1 + d*x^2))^(5/2), x, 2, -((5*b*sqrt(2*d*x^2 - d^2*x^4)*(a + b*acos(-1 + d*x^2))^(3/2))/(d*x)) + x*(a + b*acos(-1 + d*x^2))^(5/2) - (30*b^2*sqrt(a + b*acos(-1 + d*x^2))*cos((1/2)*acos(-1 + d*x^2))^2)/(d*x) + (30*sqrt(pi)*cos(a/(2*b))*cos((1/2)*acos(-1 + d*x^2))*FresnelC((sqrt(1/b)*sqrt(a + b*acos(-1 + d*x^2)))/sqrt(pi)))/((1/b)^(5/2)*d*x) + (30*sqrt(pi)*cos((1/2)*acos(-1 + d*x^2))*FresnelS((sqrt(1/b)*sqrt(a + b*acos(-1 + d*x^2)))/sqrt(pi))*sin(a/(2*b)))/((1/b)^(5/2)*d*x)]
    @test_int [(a + b*acos(-1 + d*x^2))^(3/2), x, 2, -((3*b*sqrt(2*d*x^2 - d^2*x^4)*sqrt(a + b*acos(-1 + d*x^2)))/(d*x)) + x*(a + b*acos(-1 + d*x^2))^(3/2) + (6*sqrt(pi)*cos(a/(2*b))*cos((1/2)*acos(-1 + d*x^2))*FresnelS((sqrt(1/b)*sqrt(a + b*acos(-1 + d*x^2)))/sqrt(pi)))/((1/b)^(3/2)*d*x) - (6*sqrt(pi)*cos((1/2)*acos(-1 + d*x^2))*FresnelC((sqrt(1/b)*sqrt(a + b*acos(-1 + d*x^2)))/sqrt(pi))*sin(a/(2*b)))/((1/b)^(3/2)*d*x)]
    @test_int [(a + b*acos(-1 + d*x^2))^(1/2), x, 1, (2*sqrt(a + b*acos(-1 + d*x^2))*cos((1/2)*acos(-1 + d*x^2))^2)/(d*x) - (2*sqrt(pi)*cos(a/(2*b))*cos((1/2)*acos(-1 + d*x^2))*FresnelC((sqrt(1/b)*sqrt(a + b*acos(-1 + d*x^2)))/sqrt(pi)))/(sqrt(1/b)*d*x) - (2*sqrt(pi)*cos((1/2)*acos(-1 + d*x^2))*FresnelS((sqrt(1/b)*sqrt(a + b*acos(-1 + d*x^2)))/sqrt(pi))*sin(a/(2*b)))/(sqrt(1/b)*d*x)]
    @test_int [1/(a + b*acos(-1 + d*x^2))^(1/2), x, 1, -((2*sqrt(1/b)*sqrt(pi)*cos(a/(2*b))*cos((1/2)*acos(-1 + d*x^2))*FresnelS((sqrt(1/b)*sqrt(a + b*acos(-1 + d*x^2)))/sqrt(pi)))/(d*x)) + (2*sqrt(1/b)*sqrt(pi)*cos((1/2)*acos(-1 + d*x^2))*FresnelC((sqrt(1/b)*sqrt(a + b*acos(-1 + d*x^2)))/sqrt(pi))*sin(a/(2*b)))/(d*x)]
    @test_int [1/(a + b*acos(-1 + d*x^2))^(3/2), x, 1, sqrt(2*d*x^2 - d^2*x^4)/(b*d*x*sqrt(a + b*acos(-1 + d*x^2))) - (2*(1/b)^(3/2)*sqrt(pi)*cos(a/(2*b))*cos((1/2)*acos(-1 + d*x^2))*FresnelC((sqrt(1/b)*sqrt(a + b*acos(-1 + d*x^2)))/sqrt(pi)))/(d*x) - (2*(1/b)^(3/2)*sqrt(pi)*cos((1/2)*acos(-1 + d*x^2))*FresnelS((sqrt(1/b)*sqrt(a + b*acos(-1 + d*x^2)))/sqrt(pi))*sin(a/(2*b)))/(d*x)]
    @test_int [1/(a + b*acos(-1 + d*x^2))^(5/2), x, 2, sqrt(2*d*x^2 - d^2*x^4)/(3*b*d*x*(a + b*acos(-1 + d*x^2))^(3/2)) + x/(3*b^2*sqrt(a + b*acos(-1 + d*x^2))) + (2*(1/b)^(5/2)*sqrt(pi)*cos(a/(2*b))*cos((1/2)*acos(-1 + d*x^2))*FresnelS((sqrt(1/b)*sqrt(a + b*acos(-1 + d*x^2)))/sqrt(pi)))/(3*d*x) - (2*(1/b)^(5/2)*sqrt(pi)*cos((1/2)*acos(-1 + d*x^2))*FresnelC((sqrt(1/b)*sqrt(a + b*acos(-1 + d*x^2)))/sqrt(pi))*sin(a/(2*b)))/(3*d*x)]
    @test_int [1/(a + b*acos(-1 + d*x^2))^(7/2), x, 2, sqrt(2*d*x^2 - d^2*x^4)/(5*b*d*x*(a + b*acos(-1 + d*x^2))^(5/2)) + x/(15*b^2*(a + b*acos(-1 + d*x^2))^(3/2)) - sqrt(2*d*x^2 - d^2*x^4)/(15*b^3*d*x*sqrt(a + b*acos(-1 + d*x^2))) + (2*(1/b)^(7/2)*sqrt(pi)*cos(a/(2*b))*cos((1/2)*acos(-1 + d*x^2))*FresnelC((sqrt(1/b)*sqrt(a + b*acos(-1 + d*x^2)))/sqrt(pi)))/(15*d*x) + (2*(1/b)^(7/2)*sqrt(pi)*cos((1/2)*acos(-1 + d*x^2))*FresnelS((sqrt(1/b)*sqrt(a + b*acos(-1 + d*x^2)))/sqrt(pi))*sin(a/(2*b)))/(15*d*x)]

    #= ::Section::Closed:: =#
    #=Integrands*of*the*form*u^m*(a+b*acos(sqrt(1-c*x)/sqrt(1+c*x)))^n=#

    @test_int [(a + b*acos(sqrt(1 - c*x)/sqrt(1 + c*x)))^n/(1 - c^2*x^2), x, 0, Unintegrable((a + b*acos(sqrt(1 - c*x)/sqrt(1 + c*x)))^n/(1 - c^2*x^2), x)]

    @test_int [(a + b*acos(sqrt(1 - c*x)/sqrt(1 + c*x)))^3/(1 - c^2*x^2), x, 8, (im*(a + b*acos(sqrt(1 - c*x)/sqrt(1 + c*x)))^4)/(4*b*c) - ((a + b*acos(sqrt(1 - c*x)/sqrt(1 + c*x)))^3*log(1 + ℯ^(2*im*acos(sqrt(1 - c*x)/sqrt(1 + c*x)))))/c + (3*im*b*(a + b*acos(sqrt(1 - c*x)/sqrt(1 + c*x)))^2*PolyLog(2, -ℯ^(2*im*acos(sqrt(1 - c*x)/sqrt(1 + c*x)))))/(2*c) - (3*b^2*(a + b*acos(sqrt(1 - c*x)/sqrt(1 + c*x)))*PolyLog(3, -ℯ^(2*im*acos(sqrt(1 - c*x)/sqrt(1 + c*x)))))/(2*c) - (3*im*b^3*PolyLog(4, -ℯ^(2*im*acos(sqrt(1 - c*x)/sqrt(1 + c*x)))))/(4*c)]
    @test_int [(a + b*acos(sqrt(1 - c*x)/sqrt(1 + c*x)))^2/(1 - c^2*x^2), x, 7, (im*(a + b*acos(sqrt(1 - c*x)/sqrt(1 + c*x)))^3)/(3*b*c) - ((a + b*acos(sqrt(1 - c*x)/sqrt(1 + c*x)))^2*log(1 + ℯ^(2*im*acos(sqrt(1 - c*x)/sqrt(1 + c*x)))))/c + (im*b*(a + b*acos(sqrt(1 - c*x)/sqrt(1 + c*x)))*PolyLog(2, -ℯ^(2*im*acos(sqrt(1 - c*x)/sqrt(1 + c*x)))))/c - (b^2*PolyLog(3, -ℯ^(2*im*acos(sqrt(1 - c*x)/sqrt(1 + c*x)))))/(2*c)]
    @test_int [(a + b*acos(sqrt(1 - c*x)/sqrt(1 + c*x)))^1/(1 - c^2*x^2), x, 6, (im*(a + b*acos(sqrt(1 - c*x)/sqrt(1 + c*x)))^2)/(2*b*c) - ((a + b*acos(sqrt(1 - c*x)/sqrt(1 + c*x)))*log(1 + ℯ^(2*im*acos(sqrt(1 - c*x)/sqrt(1 + c*x)))))/c + (im*b*PolyLog(2, -ℯ^(2*im*acos(sqrt(1 - c*x)/sqrt(1 + c*x)))))/(2*c)]
    @test_int [1/((a + b*acos(sqrt(1 - c*x)/sqrt(1 + c*x)))^1*(1 - c^2*x^2)), x, 0, Unintegrable(1/((1 - c^2*x^2)*(a + b*acos(sqrt(1 - c*x)/sqrt(1 + c*x)))), x)]
    @test_int [1/((a + b*acos(sqrt(1 - c*x)/sqrt(1 + c*x)))^2*(1 - c^2*x^2)), x, 0, Unintegrable(1/((1 - c^2*x^2)*(a + b*acos(sqrt(1 - c*x)/sqrt(1 + c*x)))^2), x)]

    #= ::Section::Closed:: =#
    #=Integrands*involving*inverse*cosines*of*exponentials=#

    @test_int [acos(c*ℯ^(a + b*x)), x, 6, -((im*acos(c*ℯ^(a + b*x))^2)/(2*b)) + (acos(c*ℯ^(a + b*x))*log(1 + ℯ^(2*im*acos(c*ℯ^(a + b*x)))))/b - (im*PolyLog(2, -ℯ^(2*im*acos(c*ℯ^(a + b*x)))))/(2*b)]

    #= ::Section::Closed:: =#
    #=Integrands*involving*exponentials*of*inverse*cosines=#

    @test_int [x^3*ℯ^acos(a*x), x, 6, (ℯ^acos(a*x)*cos(2*acos(a*x)))/(10*a^4) + (ℯ^acos(a*x)*cos(4*acos(a*x)))/(34*a^4) - (ℯ^acos(a*x)*sin(2*acos(a*x)))/(20*a^4) - (ℯ^acos(a*x)*sin(4*acos(a*x)))/(136*a^4)]
    @test_int [x^2*ℯ^acos(a*x), x, 6, (ℯ^acos(a*x)*x)/(8*a^2) - (ℯ^acos(a*x)*sqrt(1 - a^2*x^2))/(8*a^3) + (3*ℯ^acos(a*x)*cos(3*acos(a*x)))/(40*a^3) - (ℯ^acos(a*x)*sin(3*acos(a*x)))/(40*a^3)]
    @test_int [x^1*ℯ^acos(a*x), x, 5, (ℯ^acos(a*x)*cos(2*acos(a*x)))/(5*a^2) - (ℯ^acos(a*x)*sin(2*acos(a*x)))/(10*a^2)]
    @test_int [x^0*ℯ^acos(a*x), x, 2, (1/2)*ℯ^acos(a*x)*x - (ℯ^acos(a*x)*sqrt(1 - a^2*x^2))/(2*a)]
    @test_int [ℯ^acos(a*x)/x^1, x, 6, im*ℯ^acos(a*x) - 2*im*ℯ^acos(a*x)*HypergeometricFunctions._₂F₁(-(im/2), 1, 1 - im/2, -ℯ^(2*im*acos(a*x)))]
    @test_int [ℯ^acos(a*x)/x^2, x, 6, (1 + im)*a*ℯ^((1 + im)*acos(a*x))*HypergeometricFunctions._₂F₁(1/2 - im/2, 1, 3/2 - im/2, -ℯ^(2*im*acos(a*x))) - (2 + 2*im)*a*ℯ^((1 + im)*acos(a*x))*HypergeometricFunctions._₂F₁(1/2 - im/2, 2, 3/2 - im/2, -ℯ^(2*im*acos(a*x)))]

    #= ::Section::Closed:: =#
    #=Miscellaneous*integrands*involving*inverse*cosines=#

    @test_int [acos(c/(a + b*x)), x, 6, ((a + b*x)*asec(a/c + (b*x)/c))/b - (c*atanh(sqrt(1 - c^2/(a + b*x)^2)))/b]

    @test_int [x/(sqrt(1 - x^2)*sqrt(acos(x))), x, 3, -sqrt(2*pi)*FresnelC(sqrt(2/pi)*sqrt(acos(x)))]
    @test_int [x/(sqrt(1 - x^2)*acos(x)), x, 2, -CosIntegral(acos(x))]

    @test_int [acos(sqrt(1 + b*x^2))^n/sqrt(1 + b*x^2), x, 2, -((sqrt((-b)*x^2)*acos(sqrt(1 + b*x^2))^(1 + n))/(b*(1 + n)*x))]
    @test_int [1/(acos(sqrt(1 + b*x^2))*sqrt(1 + b*x^2)), x, 2, -((sqrt((-b)*x^2)*log(acos(sqrt(1 + b*x^2))))/(b*x))]
    end

ext: jl

max_stars_repo_path: test/5 Inverse trig functions/5.2 Inverse cosine/5.2.5 Inverse cosine functions.jl


text:
# ---
# title: 1147. Longest Chunked Palindrome Decomposition
# id: problem1147
# author: Tian Jun
# date: 2020-10-31
# difficulty: Hard
# categories: Dynamic Programming, Rolling Hash
# link: <https://leetcode.com/problems/longest-chunked-palindrome-decomposition/description/>
# hidden: true
# ---
#
# Return the largest possible `k` such that there exists `a_1, a_2, ..., a_k`
# such that:
#
#   * Each `a_i` is a non-empty string;
#   * Their concatenation `a_1 + a_2 + ... + a_k` is equal to `text`;
#   * For all `1 <= i <= k`,  `a_i = a_{k+1 - i}`.
#
#
#
# **Example 1:**
#
#
#
#     Input: text = "ghiabcdefhelloadamhelloabcdefghi"
#     Output: 7
#     Explanation: We can split the string on "(ghi)(abcdef)(hello)(adam)(hello)(abcdef)(ghi)".
#
#
# **Example 2:**
#
#
#
#     Input: text = "merchant"
#     Output: 1
#     Explanation: We can split the string on "(merchant)".
#
#
# **Example 3:**
#
#
#
#     Input: text = "antaprezatepzapreanta"
#     Output: 11
#     Explanation: We can split the string on "(a)(nt)(a)(pre)(za)(tpe)(za)(pre)(a)(nt)(a)".
#
#
# **Example 4:**
#
#
#
#     Input: text = "aaa"
#     Output: 3
#     Explanation: We can split the string on "(a)(a)(a)".
#
#
#
#
# **Constraints:**
#
#   * `text` consists only of lowercase English characters.
#   * `1 <= text.length <= 1000`
#
#
## @lc code=start
using LeetCode

## add your code here:
## @lc code=end


text:
###### n = 2 ##########
puzz21 = [
    3 0 4 0
    0 1 0 2
    0 4 0 3
    2 0 1 0
];

puzz22 = [
    0 1 3 0
    0 0 0 0
    0 0 0 0
    3 4 2 1
];

puzz23 = [
    0 3 0 1
    0 0 2 0
    0 0 3 0
    0 4 0 2
];

###### n = 3 ###########
puzz1 = [
9  3  0  0  0  0  0  4  0
0  0  0  0  4  2  0  9  0
8  0  0  1  9  6  7  0  0
0  0  0  4  7  0  0  0  0
0  2  0  0  0  0  0  6  0
0  0  0  0  2  3  0  0  0
0  0  8  5  3  1  0  0  2
0  9  0  2  8  0  0  0  0
0  7  0  0  0  0  0  5  3
];

puzz2 = [
0  0  9  0  1  0  0  6  0
0  0  0  0  6  7  0  0  3
0  3  5  0  0  0  0  0  0
3  0  0  0  0  2  0  0  0
5  1  7  0  0  0  2  3  4
0  0  0  3  0  0  0  0  7
0  0  0  0  0  0  9  1  0
1  0  0  6  8  0  0  0  0
0  7  0  0  3  0  5  0  0
];

puzz3 = [
0  3  7  8  6  0  0  4  0
0  0  6  0  0  7  0  0  0
0  2  0  0  3  0  0  0  6
0  8  0  2  0  0  0  0  0
9  0  0  0  0  0  0  0  1
0  0  0  0  0  6  0  9  0
5  0  0  0  7  0  0  3  0
0  0  0  3  0  0  8  0  0
0  1  0  0  8  4  2  6  0
];

#### n = 4 #####
puzz41 = [
    0 16 0 0 0 0 0 0 0 0 0 0 0 0 0 1
    10 0 0 14 2 0 5 7 15 0 0 11 0 0 13 9
    0 0 0 11 0 0 0 0 13 0 0 12 0 0 0 0
    0 0 3 0 0 10 14 0 0 0 0 0 0 0 5 0
    0 0 0 7 0 5 0 15 0 6 13 10 14 0 0 3
    9 11 0 0 3 0 12 1 0 14 0 16 7 6 0 8
    4 0 0 0 0 6 0 0 12 0 1 0 0 0 0 15
    0 0 12 0 0 0 0 11 0 0 0 0 0 0 0 16
    3 0 0 9 1 0 11 0 0 0 0 0 16 10 0 0
    0 0 0 0 7 4 0 9 0 2 0 5 0 0 0 11
    0 1 0 0 0 16 2 0 0 0 8 0 15 0 7 0
    0 0 0 0 0 0 0 8 3 0 9 0 4 0 14 0
    0 0 0 0 15 0 0 0 2 0 0 13 0 0 1 0
    1 0 0 5 0 8 0 0 0 10 0 14 11 0 0 12
    16 15 0 8 0 0 0 14 0 1 12 4 10 0 3 0
    0 0 11 0 5 0 0 0 0 0 0 15 0 8 9 2
];


text:
#The lattice
using LinearAlgebra

#print("Enter dim value: "); d = parse(Int, readline(stdin)) # use it for IO input of d! else use fixed d!
d = 4;
v = Matrix{Any}(zeros(d,d));
h = Matrix{Any}(zeros(d,d));
p = Matrix{Float64}(undef,d,d);
x = Matrix{Float64}(undef,d,d);
y = Matrix{Float64}(undef,d,d);
Φ = Matrix{Float64}(undef,d,d);

for i = 1:d
    h[i,d] = Matrix{Float64}(I,d,d)[i,:];
end

#=for k = d:-1:1
    v[k,k] = (x[k,k] + y[k,k]im)*h[k,k];

    for j = k-1:-1:1
        v[j,k] = (x[j,k] + y[j,k]im) * sqrt(complex(p[j,k])) * h[j,k] + sqrt(complex(1-p[j,k])) * v[j+1,k];
        h[j,k-1] = (x[j,k] + y[j,k]im) * sqrt(complex(1-p[j,k])) * h[j,k] - sqrt(complex(p[j,k])) * v[j+1,k];
        println("k:",k,"\t","j:",j)
    end
end=#

function H(m::Int, n::Int)
    for k = d:-1:1
        v[k,k] = (x[k,k] + y[k,k]im)*h[k,k];

        for j = k-1:-1:1
            v[j,k] = (x[j,k] + y[j,k]im) * sqrt(complex(p[j,k])) * h[j,k] + sqrt(complex(1-p[j,k])) * v[j+1,k];
            h[j,k-1] = (x[j,k] + y[j,k]im) * sqrt(complex(1-p[j,k])) * h[j,k] - sqrt(complex(p[j,k])) * v[j+1,k];
        end
    end
    return (h[m,n])
end

#Ist = transpose(v);

#-----------------------------------------------------------------------------------------------------
#DFT

m(n::Int) = 1/sqrt(n)*[exp(2*pi*im*(r-1)*(s-1)/n) for r in 1:n, s in 1:n];

#Soll = m(d);

#------------------------------------------------------------------------------------------------------
#The solution of the algorithm

Denom(j::Int,k::Int) = dot(Matrix{Float64}(I,d,d)[j,:], H(j,k)) * (j==1 ? 1.0 : prod(sqrt(complex(1-p[l,k])) for l = 1:j-1));

Num(j::Int,k::Int) = j==1 ? 0.0 : sum((x[i,k] + y[i,k]im) * dot(Matrix{Float64}(I,d,d)[j,:], H(i,k)) * sqrt(complex(p[i,k])) * (i==1 ? 1.0 : prod(sqrt(complex(1-p[l,k])) for l = 1:i-1)) for i = 1:j-1);

Z(j::Int,k::Int) = (m(d)[j,k] - Num(j,k)) / Denom(j,k);

#=function Angle(Re,Im,j,k)
    if abs(exp(asin(Float32(Im))*im) - (Re + Im*im)) < 10.0^-12
        Φ[j,k] = asin(Float32(Im));
    else
        Φ[j,k] = -asin(Float32(Im)) - pi;
    end
end=#
#Angle(Re,Im,j,k) = abs(exp(asin(Float32(Im))*im) - (Re + Float32(Im)*im)) < 10.0^-12 ? Φ[j,k] = asin(Float32(Im)) : Φ[j,k] = -asin(Float32(Im)) - pi;
Angle(Re::Float16,Im::Float16,j::Int,k::Int) = abs2(exp(asin(Im)*im) - (Re + Im*im)) < 10.0^-12 ? Φ[j,k] = asin(Im) : Φ[j,k] = -asin(Im) - pi;
# the results vary depending on the precision of the 'Float' used!

#-----------------------------------------------------------------------------------------------------
#Evaluation

@time for k = d:-1:1
    for j = 1:k-1
        p[j,k] = abs2(Z(j,k));
        x[j,k] = real(Z(j,k)/sqrt(complex(p[j,k])));
        y[j,k] = imag(Z(j,k)/sqrt(complex(p[j,k])));
        Angle(Float16(x[j,k]),Float16(y[j,k]),j,k);
        println("p(", j, ",", k, ") = ", p[j,k], "\tΦ(", j, ",", k, ") = ", Φ[j,k]*180/pi);
    end

    x[k,k] = real(Z(k,k));
    y[k,k] = imag(Z(k,k));
    Angle(Float16(x[k,k]),Float16(y[k,k]),k,k);
    println("Φ(", k, ",", k, ") = ", Φ[k,k]*180/pi);
end

#------------------------------------------------------------------------------------------------------


text:
using LinearAlgebra

@testset "qr size mismatch" begin
    X = rand(Float32, 2, 1)
    Q,R = qr(X)

    @test collect(Q) == Array(collect(Q))
    @test Array(Q) == Array(CuArray(Q))
    @test Array{Float32}(Q) == Array(CuArray{Float32}(Q))
    @test Matrix(Q) == Array(CuMatrix(Q))
    @test Matrix{Float32}(Q) == Array(CuMatrix{Float32}(Q))
    @test convert(Array, Q) == Array(convert(CuArray, Q))
    @test convert(Array{Float32}, Q) == Array(convert(CuArray{Float32}, Q))
end

@testset "normalize!" begin
    x = rand(ComplexF32, 10)
    dx = CuVector{ComplexF32}(x)
    @test isreal(norm(dx, 2))
    @test norm(normalize!(dx)) ≈ 1
end

@testset "dot" begin
    @testset for T in [Int16, Int32, Int64,
                       Float16, Float32, Float64,
                       ComplexF16, ComplexF32, ComplexF64]
        @test testf(dot, rand(T, 256), rand(Bool, 256))
        @test testf(dot, rand(Bool, 256), rand(T, 256))
    end

    @test testf(dot, rand(Bool, 1024, 1024), rand(Float64, 1024, 1024))
end


text:
###################################################################################################
#
# FlowBalances.jl
#
# by Walt McNab (May 2020)
#
# (1) Approximate potentiometric surface and hydraulic conductivity distributions by interpolation with kriging
# (2) Estimate groundwater flow vector field by Darcy's law; optional particle tracking
# (3) Numerical integration across polygon drawn on flow field to compute fluxes
#
# Current version assumes datum for head values is equal to an elevation of zero.
#
###################################################################################################

using DelimitedFiles
using Statistics
using Polynomials
using QuadGK

# miscellaneous fixed parameters
const epsilon = 0.01                	# factor used to prevent binning problems with variogram construction
const delta = 0.1 						# distance offset used to estimate hydraulic gradient

### defined types ###

mutable struct Polygon
    x::Array{Float64, 1}                # apex locations
    y::Array{Float64, 1}
    m::Array{Float64, 1}                # slope of polygon side
    n::Array{Any, 1}                    # normal vector to polygon side
    L::Array{Float64, 1}                # length of polygon side
end

mutable struct TrackParams
	dStep::Float64 						# step size for particle tracking
	phi::Float64 						# porosity
end

mutable struct Sources              	# source/sink terms (i.e., wells)
	activeSources::Bool
    x::Array{Float64, 1}
    y::Array{Float64, 1}
    Q::Array{Float64, 1}
end

mutable struct Particle
	x::Array{Float64, 1} 				# particle locations, starting with initial
	y::Array{Float64, 1}
	vx::Array{Float64, 1} 				# particle velocities (for plotting)
	vy::Array{Float64, 1}
	t::Array{Float64, 1}
	fwd::Float64 						# movement direction: 1 = forward, -1 = backward
	active::Bool
end

mutable struct Krig 					# variogram parameters
	varMatrix::Array{Float64, 2}
	m::Float64
	b::Float64
end

mutable struct Points
    x::Array{Float64, 1}
    y::Array{Float64, 1}
    v::Array{Float64, 1} 				# head measurements, or log hydraulic conductivity
end

mutable struct Grid
	x0::Float64
	xf::Float64
	y0::Float64
	yf::Float64
    x::Array{Float64, 1}
    y::Array{Float64, 1}
end

### utility functions ###

function DistVector(xp::Float64, yp::Float64, xArray::Array{Float64, 1}, yArray::Array{Float64, 1})::Array{Float64, 1}
	# return a vector of distances
	d = Float64[]
    for i = 1:length(xArray)
		dist = sqrt((xp-xArray[i])^2 + (yp-yArray[i])^2)
        push!(d, dist)
    end
	return d
end

function dot(a::Array{Float64, 1}, b::Array{Float64, 1})::Float64
    # vector dot product
    return sum(a.*b)
end

### hydro modeling functions ###

function Grad(x::Float64, y::Float64, headData::Points, krigHead::Krig)
	# estimate hydraulic gradient by finite differences
	h = Interpolate(x, y, headData, krigHead)
	hx = Interpolate(x+delta, y, headData, krigHead)
	hy = Interpolate(x, y+delta, headData, krigHead)
	dhdx = (hx-h)/delta
	dhdy = (hy-h)/delta
	return dhdx, dhdy
end

function Darcy(x::Float64, y::Float64, headData::Points, krigHead::Krig, KData::Points, krigLogK::Krig)
	# local groundwater Darcy velocity
	K = 10.0^Interpolate(x, y, KData, krigLogK)
	dhdx, dhdy = Grad(x, y, headData, krigHead)
	qx = -K * dhdx
	qy = -K * dhdy
	return qx, qy
end

function Displace(x0::Float64, y0::Float64, vx::Float64, vy::Float64, d::Float64, fwd::Float64)
	# particle movement
	vm = sqrt(vx^2 + vy^2) 	# velocity magnitude
	dt = d/vm 				# time step to move "d"
	x = x0 + fwd*vx*dt 		# implied new position
	y = y0 + fwd*vy*dt
	return x, y, dt
end

function CheckEndState(part::Particle, trackParams::TrackParams, grid::Grid, wells::Sources)::Particle
	# note if particle has exited model domain or has approached too close to a well
	part.active = (part.x[end]>=grid.x0) & (part.x[end]<=grid.xf) & (part.y[end]>=grid.y0) & (part.y[end]<=grid.yf)
	if wells.activeSources == true
		dWells = DistVector(part.x[end], part.y[end], wells.x, wells.y)
		if minimum(dWells) <= trackParams.dStep
			part.active = false
		end
	end
	return part
end

function Track(part::Particle, trackParams::TrackParams, headData::Points, krigHead::Krig, KData::Points, krigLogK::Krig, wells::Sources, grid::Grid)::Particle
	# follow the progress of a particle (initial conditions already defined)
	while part.active == true
		# single-pass particle position estimator
		xf, yf, dt = Displace(part.x[end], part.y[end], part.vx[end], part.vy[end], trackParams.dStep, part.fwd)
		vxf, vyf = Darcy(xf, yf, headData, krigHead, KData, krigLogK)./trackParams.phi
		vx = 0.5*part.vx[end] + 0.5*vxf
		vy = 0.5*part.vy[end] + 0.5*vyf
		x, y, dt = Displace(part.x[end], part.y[end], vx, vy, trackParams.dStep, part.fwd)
		push!(part.x, x)
		push!(part.y, y)
		push!(part.vx, vx)
		push!(part.vy, vy)
		push!(part.t, part.t[end]+dt)
		part = CheckEndState(part, trackParams, grid, wells)        # check to see if exit condition is met
	end
	return part
end

function FluxNorm(x::Float64, headData::Points, krigHead::Krig, KData::Points, krigLogK::Krig, polygon::Polygon, indx::Int64)
    # vertically-integrated, normal groundwater flux at a point along a transect
    y = polygon.y[indx] + polygon.m[indx]*(x-polygon.x[indx])
    qx, qy = Darcy(x, y, headData, krigHead, KData, krigLogK).*Interpolate(x, y, headData, krigHead)
    return -dot([qx, qy], polygon.n[indx])
end

function SumPolyFluxes(polygon::Polygon, headData::Points, krigHead::Krig, KData::Points, krigLogK::Krig)::Float64
    # integrate groundwater fluxes across polygon/polyline sides
    QTot = 0.0
    for i = 1:length(polygon.x)-1
        x0 = minimum([polygon.x[i], polygon.x[i+1]])
        xf = maximum([polygon.x[i], polygon.x[i+1]])
        QTot += (polygon.L[i]/abs(xf-x0)) * quadgk(x -> FluxNorm(x, headData, krigHead, KData, krigLogK, polygon, i), x0, xf)[1]
    end
    return QTot
end

### kriging functions ###

function MakeKrig(data, setName)
	# parameters to inform kriging
    S = Squareform(data.x, data.y)      			# distance matrix
    m, b = Variogram(data, S, setName)       		# linear variogram
    varMatrix = (S.*m).+b
	return Krig(varMatrix, m, b)
end

function Squareform(xArray::Array{Float64, 1}, yArray::Array{Float64, 1})::Array{Float64, 2}
	# squareform distance matrix
	N = length(xArray)
	S = zeros(Float64, N, N)
    for i = 1:N
		S[i, :] = DistVector(xArray[i], yArray[i], xArray, yArray)
    end
	return S
end

function Variogram(points::Points, S::Array{Float64, 2}, setName::AbstractString)
    # create variogram; write variogram summary to file and return linear variogram model
    dist = Float64[]
    gamma = Float64[]
    lagGroup = []
    lagMeanDist = Float64[]
    xVar = Float64[]
    yVar = Float64[]
    N = length(points.x)        # number of lag bins
    # difference in value versus distance offset
    for i = 1:N
        for j = i+1:N
            push!(dist, S[i,j])
            push!(gamma, (points.v[i]-points.v[j])^2)
        end
    end
    # populate bins
    lagStepSize = maximum(dist)/N
    for i = 1:N
        push!(lagGroup, [])                             # set up list of lag sets
        push!(lagMeanDist, (i-0.5)*lagStepSize)         # mean distance offset for each of the lag groups
    end
    # assign lags to groups
    for i = 1:length(dist)
        lagIndex = floor(Int, (dist[i]-epsilon)/lagStepSize) + 1
        push!(lagGroup[lagIndex], gamma[i])
    end
    # calculate variogram
    for i = 1:N
        if length(lagGroup[i]) > 1     # binned lag group is large enough to calculate a variance
            push!(xVar, lagMeanDist[i])
            push!(yVar, mean(lagGroup[i])/2)
        end
    end
    WriteVariogram(xVar, yVar, setName)					# write to output file
    # linear regression (i.e. linear variogram model)
    r = fit(xVar, yVar, 1)
    return r[1], r[0]               # = return m, b
end

function Interpolate(x::Float64, y::Float64, points::Points, krig::Krig)::Float64
    # interpolate field value at (x, y)
    dist = DistVector(x, y, points.x, points.y)          # calculate covariance vector for distances between (x,y) and data points
    k = (dist.*krig.m).+krig.b
    wt = \(krig.varMatrix, k)                            # compute weights
    z = sum(wt.*points.v)
    return z
end

### I/O functions ###

function ReadParticles(trackParams::TrackParams, headData::Points, krigHead::Krig, KData::Points, krigLogK::Krig)::Array{Particle, 1}
	# initialize particles
	part = []
	data = readdlm("particleStarts.txt", '\t', header=true)
    for i = 1:size(data[1], 1)
        x = Float64(data[1][i, 1])
        y = Float64(data[1][i, 2])
        fwd = Float64(data[1][i, 3])
		vx, vy = Darcy(x, y, headData, krigHead, KData, krigLogK)./trackParams.phi
		t = 0.0
		active = true
        push!(part, Particle([x], [y], [vx], [vy], [t], fwd, active))
    end
    println("Read particle starting positions and initialized.")
	return part
end

function ReadPolygon()::Polygon
    # clockwise list convention; repeat 1st point as last point
    x = Float64[]
    y = Float64[]
    m = Float64[]
    n = []
    L = Float64[]
    data = readdlm("polygon.txt", '\t', header=true)
    for i = 1:size(data[1], 1)
        push!(x, Float64(data[1][i, 1]))
        push!(y, Float64(data[1][i, 2]))
    end
    for i = 1:length(x)-1
        dx = x[i+1] - x[i]
        dy = y[i+1] - y[i]
        push!(m, dy/dx)
        d = sqrt(dx^2 + dy^2)
        push!(L, d)
        push!(n, [-dy/d, dx/d])
    end
    println("Read and processed bounding polygon.")
    return Polygon(x, y, m, n, L)
end

function ReadPoints(dataSet::AbstractString)::Points
    # read point data set and return array of point structs
    x = Float64[]
    y = Float64[]
    v = Float64[]
    data = readdlm(dataSet * ".txt", '\t', header=true)
    for i = 1:size(data[1], 1)
        push!(x, Float64(data[1][i, 1]))
        push!(y, Float64(data[1][i, 2]))
        push!(v, Float64(data[1][i, 3]))
    end
    println("Read " * dataSet * ".")
    return Points(x, y, v)
end

function ReadGrid()
    # set up grid for kriging and inverse model
    x = Float64[]
    y = Float64[]
    data = readdlm("grid.txt", '\t', header=true)
    x0 = Float64(data[1][1, 2])
    y0 = Float64(data[1][1, 3])
    xf = Float64(data[1][2, 2])
    yf = Float64(data[1][2, 3])
    nx = Int64(data[1][3, 2])
    ny = Int64(data[1][3, 3])
    dx = (xf-x0)/nx
    dy = (yf-y0)/ny
    for j = 1:ny
        for i = 1:nx
            push!(x, x0 + (i-0.5)*dx)
            push!(y, y0 + (j-0.5)*dy)
        end
    end
    println("Read grid constraints.")
    return Grid(x0, xf, y0, yf, x, y)
end

function ReadSources(dataSet::AbstractString)::Sources
    # read source/sink terms
    x = Float64[]
    y = Float64[]
    Q = Float64[]
	activeSources = true
    data = readdlm(dataSet * ".txt", '\t', header=true)
    for i = 1:size(data[1], 1)
        push!(x, Float64(data[1][i, 1]))
        push!(y, Float64(data[1][i, 2]))
        push!(Q, Float64(data[1][i, 3]))
    end
    println("Read " * dataSet * ".")
    return Sources(activeSources, x, y, Q)
end

function ReadTrack()
	# miscellaneous particle tracking parameters
    data = readdlm("trackParams.txt", '\t', header=false)
    dStep = Float64(data[1, 2])
	phi = Float64(data[2, 2])
    println("Read tracking parameters.")
	return TrackParams(dStep, phi)
end

function WriteVariogram(xVar::Array{Float64, 1}, yVar::Array{Float64, 1}, setName::AbstractString)
	# variogram output file
    csvfile = open("variogram_" * setName * ".csv","w")
    line_out = "h" * "," * "gamma"
    println(csvfile, line_out)
    for i = 1:length(xVar)
        line_out = string(xVar[i]) * "," * string(yVar[i])
        println(csvfile, line_out)
    end
    close(csvfile)
end

function WriteGridOut(grid::Grid, head::Array{Float64, 1}, logK::Array{Float64, 1})
	# write grid output, with interpolated heads and log K estimates, to file
    csvfile = open("gridResults.csv","w")
    line_out = "x" * "," * "y" * "," * "head" * "," * "logK"
    println(csvfile, line_out)
    for i = 1:length(grid.x)
        line_out = string(grid.x[i]) * "," * string(grid.y[i]) * "," * string(head[i]) * "," * string(logK[i])
        println(csvfile, line_out)
    end
    close(csvfile)
	println("Wrote grid output file.")
end

function WriteParticles(part::Array{Particle, 1})
	# write grid output, with interpolated heads and log K estimates, to file
    csvfile = open("particleTracks.csv","w")
    line_out = "particle" * "," * "time" * "," * "x" * "," * "y" * "," * "vx" * "," * "vy" * "," * "v-magn"
    println(csvfile, line_out)
    for (i, p) in enumerate(part)
		for j = 1:length(p.x)
			vMagn = sqrt(p.vx[j]^2 + p.vy[j]^2)
			line_out = string(i) * "," * string(p.t[j]) * "," * string(p.x[j]) * "," * string(p.y[j]) * "," * string(p.vx[j]) * "," * string(p.vy[j]) * "," * string(vMagn)
			println(csvfile, line_out)
		end
    end
    close(csvfile)
	println("Wrote particle tracks output file.")
end

### main ###

function FlowBalances(gridFlag, trackFlag, polyFlag, wellsFlag)

    # problem setup
	dataSet = ["heads", "logKs"]
    grid = ReadGrid()                       	# read grid
	headData = ReadPoints(dataSet[1])          	# head measurements
	KData = ReadPoints(dataSet[2])          	# log K measurements
	if wellsFlag == true 						# well locations and pumping rates, if applicable
		wells = ReadSources("wells")
	else
		wells = Sources(false, Float64[], Float64[], Float64[]) 		# empty struct, with activeSources = false
	end

	# set up kriging models
	krigHead = MakeKrig(headData, dataSet[1])
	krigLogK = MakeKrig(KData, dataSet[2])

	# read polygon, if used
    if polyFlag == true
        polygon = ReadPolygon()                                                     # read input file
        QIntegrate = SumPolyFluxes(polygon, headData, krigHead, KData, krigLogK)    # integrate
        println("Flux across polygon/polyline = ", "\t", QIntegrate)
    end

	# conduct particle tracking, if implemented
	if trackFlag == true
		trackParams = ReadTrack()													# read parameters file
		part = ReadParticles(trackParams, headData, krigHead, KData, krigLogK)		# initialize particles
		for i = 1:length(part)														# track particles
			if part[i].active == true
				part[i] = Track(part[i], trackParams, headData, krigHead, KData, krigLogK, wells, grid)
			end
		end
		WriteParticles(part)							# write to output file
	end

	# write to output grid for plotting
    if gridFlag == true
        head = Float64[]
        logK = Float64[]
        println("Interpolating heads across grid ...")
        for i = 1:length(grid.x)
            push!(head, Interpolate(grid.x[i], grid.y[i], headData, krigHead))
        end
        println("Interpolating log K estimates across grid ...")
        for i = 1:length(grid.x)
            push!(logK, Interpolate(grid.x[i], grid.y[i], KData, krigLogK))
        end
        WriteGridOut(grid, head, logK)        # write to output file
	end

    println("Finished.")

end

### run model ###

gridFlag = false
trackFlag = false
polyFlag = true
wellsFlag = true
FlowBalances(gridFlag, trackFlag, polyFlag, wellsFlag)


text:
using Stheno: Xt_invA_Y, Xt_invA_X, diag_At_A, diag_At_B, diag_Xt_invA_X, diag_Xt_invA_Y

@timedtestset "cholesky" begin
    # Set up some matrices and factorisations.
    rng, N, N′, P, Q = MersenneTwister(123456), 5, 3, 6, 2
    B = randn(rng, N, N)
    A_ = B' * B + UniformScaling(1e-6)
    A = cholesky(A_)
    x, y, z = randn(rng, N), randn(rng, N′), randn(rng, N)
    X, Y = randn(rng, N, P), randn(rng, N, Q)
    Z = randn(rng, N, P)
    A_1_ = exp(randn(rng))
    A_1 = cholesky(A_1_)

    # Specialised matrix operations.
    @test Xt_invA_X(A, x) isa Real
    @test Xt_invA_X(A, x) ≈ x' * (A \ x)

    @test Xt_invA_X(A, X) isa Symmetric
    @test Xt_invA_X(A, X) ≈ X' * (A \ X)

    @test Xt_invA_Y(X, A, Y) isa Matrix
    @test Xt_invA_Y(X, A, Y) ≈ X' * (A \ Y)

    @test diag_At_A(x) ≈ [x'x]
    @test diag_At_A(X) ≈ diag(X'X)

    @test diag_At_B(x, z) ≈ [x'z]
    @test diag_At_B(X, Z) ≈ diag(X'Z)

    @test diag_Xt_invA_X(A, X) ≈ diag(Xt_invA_X(A, X))

    @test diag_Xt_invA_Y(X, A, Z) ≈ diag(Xt_invA_Y(X, A, Z))
end


text:
"""
    AbstractGradient{T}

Magnetic field gradient ``\\vec{g}(t) \\in \\mathbb{R}^3``.
"""
abstract type AbstractGradient{T} end

"""
    GeneralGradient(g⃗)

General gradient sequence ``\\vec{g}(t) \\in \\mathbb{R}^3``. The direction and amplitude may
vary in time.
"""
Base.@kwdef struct GeneralGradient{T,F}
    g⃗::F
    TE::T
end

"""
    ScalarGradient(dir, profile, amplitude)

Gradient sequence with amplitude `amplitude`, normal direction `dir` and scalar time profile
`profile`.

The direction is constant, while the amplitude is controlled by the time profile.

The direction is normalized upon construction.
"""
struct ScalarGradient{T}
    dir::Vector{T}
    profile::TimeProfile{T}
    amplitude::T
    ScalarGradient(dir, profile, amplitude) =
        new{typeof(amplitude)}(dir / norm(dir), profile, amplitude)
end

(g::GeneralGradient)(t) = g.g⃗(t)
(g::ScalarGradient)(t) = g.amplitude * g.profile(t) * g.dir


text:
"""
```
SeisEnvelope(d)
```

Calculate the envelope attribute of  a group of input traces

# Arguments
* `d`: Input data. A 2D array where the first dimension is time.

# Examples
```
julia> dtsec = 0.002; w = Ricker(dt=dtsec);
julia> e = SeisEnvelope(w); t=dtsec*collect(0:1:length(w)-1);plot(t,w,t,e,"-r");xlabel("Time [s]")

julia> d,extent = SeisLinearEvents(); SeisPlot(d,extent,style="wiggles")
julia> out = SeisEnvelope(d); SeisPlot(out,extent,style="wiggles")
```
"""

function SeisEnvelope(d)

	D = fft(d,1)
	D[1:Int(floor(size(d,1)/2)),:] = 0.0
	return 2*abs.(ifft(D,1))

end

function SeisEnvelope(A,h::Array{Header,1})
	for itrace = 1 : size(A[:,:],2)
		A[:,itrace] = SeisEnvelope(A[:,itrace])
	end
	return A,h
end

function SeisEnvelope(in::AbstractString,out::AbstractString)
	@compat parameters = Dict()
	SeisProcess(in,out,[SeisEnvelope],[parameters];group="some",ntrace=100000)
end


text:
headers = Dict(
    # This is the expected response when the client sends
    # Sec-WebSocket-Key => "dGhlIHNhbXBsZSBub25jZQ=="
    "Sec-WebSocket-Accept" => "s3pPLMBiTxaQ9kYGzzhZRbK+xOo="
)

type MockRequest
    accept::String

    uri::Requests.URI
    method::String
    headers::Dict

    MockRequest(accept::String) =
        new(accept, Requests.URI("http://some/uri"), "method", Dict())
end

type FakeResponse
    headers::Dict{Any,Any}
end

type FakeResponseStream
    socket::IO
    response::FakeResponse
end

function mock_do_stream_request(m::MockRequest, uri::Requests.URI, method::String;
    headers=Dict(),
    tls_conf=Requests.TLS_VERIFY,
    response_headers=Dict{Any,Any}())

    m.uri = uri
    m.method = method
    m.headers = headers

    FakeResponseStream(IOBuffer(), FakeResponse(response_headers))
end

facts("Handshake") do
    context("Handshake") do
        rng = FakeRNG{UInt8}(b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10")
        key = "AQIDBAUGBwgJCgsMDQ4PEA=="
        expected_headers = DandelionWebSockets.make_headers(key)
        expected_accept = DandelionWebSockets.calculate_accept(key)
        expected_response_headers = Dict{Any, Any}("some" => "value")

        uri = Requests.URI("http://localhost:8000")

        m = MockRequest(expected_accept)
        function do_req(uri::Requests.URI, method::String; headers=Dict())
            mock_do_stream_request(m, uri, method;
                headers=headers,
                response_headers=expected_response_headers)
        end

        handshake_result = DandelionWebSockets.do_handshake(rng, uri; do_request=do_req)

        # Requirement
        # @4_1_OpeningHandshake_2 Opening handshake is an HTTP GET

        @fact m.method --> "GET"
        @fact m.uri --> uri
        @fact m.headers --> expected_headers

        @fact handshake_result.expected_accept --> expected_accept
        @fact handshake_result.headers --> expected_response_headers
    end

    context("SSL handshakes result in a TLSBufferedIO stream") do
        rng = FakeRNG{UInt8}(b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10")
        key = "AQIDBAUGBwgJCgsMDQ4PEA=="
        expected_accept = DandelionWebSockets.calculate_accept(key)

        uri = Requests.URI("http://localhost:8000")
        ssl_uri = Requests.URI("https://localhost:8000")

        m = MockRequest(expected_accept)
        do_req(uri::Requests.URI, method::String; headers=Dict()) =
            mock_do_stream_request(m, uri, method; headers=headers)

        normal_handshake_result = DandelionWebSockets.do_handshake(rng, uri; do_request=do_req)
        @fact isa(normal_handshake_result.stream, DandelionWebSockets.TLSBufferedIO) --> false

        rng = FakeRNG{UInt8}(b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10")
        ssl_handshake_result = DandelionWebSockets.do_handshake(rng, ssl_uri, do_request=do_req)
        @fact isa(ssl_handshake_result.stream, DandelionWebSockets.TLSBufferedIO) --> true
    end
end


text:
# NB: This fails if "Vega Visualization" is set to `nothing`
vis_spec =
[
    (:name, AbstractString, "Vega Visualization"),
    (:width, Int, 450),
    (:height, Int, 450),
    (:padding, Union{VegaPadding, Number, AbstractString}, "auto"),
    (:viewport, Vector{Int}, nothing),
    (:background, AbstractString, nothing),
    (:data, Vector{VegaData}, nothing),
    (:scales, Vector{VegaScale}, nothing),
    (:axes, Vector{VegaAxis}, nothing),
    (:marks, Vector{VegaMark}, nothing),
    (:legends, Vector{VegaLegend}, nothing),
    (:signals, Vector{Dict{Any, Any}}, nothing),
    (:predicates, Vector{Dict{Any, Any}}, nothing),
    (:modify, Vector{Dict{Any, Any}}, nothing)
]

primitivefactory(:VegaVisualization, vis_spec)

max_stars_repo_name: jpthor/vega


text:
@test_nowarn GibbsTypePriors.Pkn_NGG_arb(50, 100, 0.5, 0.2)
@test_nowarn GibbsTypePriors.Pkn_NGG_robust_in(50, 100, 0.5, 0.2)
@test GibbsTypePriors.log_βnk(1.3, 100, 25, 1.2) ≈ 2.1851379297320825
@test Float64(GibbsTypePriors.logxk(10, 5, 1.3, 0.9))  ≈ 0.6969596408073483
@test_nowarn GibbsTypePriors.Pkn_NGG_approx(90, 100, 1.2, 0.6)
@test_nowarn GibbsTypePriors.Pkn_NGG_approx(100, 100, 1.2, 0.6)
@test GibbsTypePriors.Pkn_NGG_approx(100, 100, 1.2, 0.6, 100, -1) == -1
@test_nowarn GibbsTypePriors.Pkn_NGG_robust(100, 100, 1.2, 0.6)
@test_nowarn GibbsTypePriors.Pkn_NGG_robust(1, 100, 1.2, 0.6)
@test_nowarn GibbsTypePriors.Pkn_NGG_robust(1, 1000, 1.2, 0.6)
@test_nowarn GibbsTypePriors.Pkn_NGG_approx(20, 1.2, 0.6)
@test_nowarn GibbsTypePriors.Pkn_NGG_robust(20, 1.2, 0.6; verbose = true)
@test_nowarn GibbsTypePriors.Pkn_NGG(1, 20, 1.2, 0.6)

@test_nowarn GibbsTypePriors.Vnk_2PD(7, 5, 0.2, 0.4)

@test_nowarn GibbsTypePriors.Pkn_PY(5, 0.2, 0.4)
@test_nowarn GibbsTypePriors.Pkn_Dirichlet(7, 10, 1.5)

@test GibbsTypePriors.log_βnk(1.3, 100, 25, 1.2) ≈ 2.1851379297320825
@test Float64(GibbsTypePriors.log_βnk(1., 10, 1, 1.2))== log(10)
@test GibbsTypePriors.log_βnk(1., 10, 2, 0.5) ≈ (log(10) -2*log(2))
@test GibbsTypePriors.βnk(1., 10, 2, 0.5) ≈ 10/4
@test_nowarn Float64(GibbsTypePriors.logxk(10., 1,1.0, 0.5)) ==  Float64(log(0.5*1 + GibbsTypePriors.βnk(1.0, 10, 1, 0.5)) + log(GibbsTypePriors.Cnk(11,2,0.5)) - log(0.5) - log(GibbsTypePriors.Cnk(11,1,0.5)))
@test_nowarn GibbsTypePriors.logxk_py(10, 1, 1.0, 0.1)
@test_nowarn Float64(GibbsTypePriors.logxk_py(10., 1,1.0, 0.5)) ==  Float64(log(0.5*1 + 1.0) + log(GibbsTypePriors.Cnk(11,2,0.5)) - log(0.5) - log(GibbsTypePriors.Cnk(11,1,0.5)))

@testset "NGG prior Kn distribution" begin
    @test_nowarn GibbsTypePriors.Pkn_NGG_arb(5, 5, 0.2, 0.4)
    @test_nowarn GibbsTypePriors.Pkn_NGG_robust_in(7, 5, 0.2, 0.4)
    @test_nowarn GibbsTypePriors.Pkn_NGG_pred_approx(100, 1.0, 0.5)
    @test  Float64(GibbsTypePriors.Pkn_NGG_robust_in(50, 100, 0.5, 0.2)) ≈  Float64(GibbsTypePriors.Pkn_NGG_arb(50, 100, 0.5, 0.2))
    #@test Nemo.isequal(GibbsTypePriors.Pkn_NGG_robust(1, 100, 1.2, 0.5),GibbsTypePriors.Pkn_NGG_robust_in(1, 100, 1.2, 0.5))
    #@test Nemo.isequal(GibbsTypePriors.Pkn_NGG_robust_in(50, 100, 0.5, 0.2),GibbsTypePriors.Pkn_NGG_arb(50, 100, 0.5, 0.2))
    @test  Float64(sum(GibbsTypePriors.Pkn_NGG_robust(100, 0.5, 0.2))) ≈  1.0
    @test  Float64(sum(GibbsTypePriors.Pkn_NGG(100, 0.5, 0.2))) ≈  1.0
    @test  Float64(sum(GibbsTypePriors.Pkn_NGG_approx(100, 0.5, 0.2))) ≈  1.0
    @test  GibbsTypePriors.Pkn_NGG_pred_approx(10, 1.0, 0.5) == convert(Array{Float64,1},GibbsTypePriors.Pkn_NGG_approx(10, 1.0, 0.5))
    @test  GibbsTypePriors.Pkn_NGG_pred_approx(50, 10.0, 0.01) == convert(Array{Float64,1},GibbsTypePriors.Pkn_NGG_approx(50, 10.0, 0.01))
    @test_nowarn GibbsTypePriors.Pkn_PY_pred_approx(100, 1.0, 0.1)
    @test  Float64(sum(GibbsTypePriors.Pkn_PY_pred_approx(100, 1.0, 0.1))) ≈  1.0
    @test  Float64(sum(GibbsTypePriors.Pkn_NGG_pred_approx(50, 10.0, 0.01))) ≈  1.0
    @test  Float64(sum(GibbsTypePriors.Pkn_NGG_approx(10, 1.0, 0.5))) ≈  1.0
    @testset "NGG  multinomial" begin
        @test_nowarn GibbsTypePriors.Pkn_NGGM_arb(1,100,100, 1.0, 0.5)
        @test_nowarn GibbsTypePriors.Pkn_NGGM_arb(99,100,100, 100.0, 0.5)
        @test_nowarn GibbsTypePriors.Pkn_NGGM(50,100,100, 100.0, 0.5)
        @test  Float64(sum(GibbsTypePriors.Pkn_NGGM_arb.(1:10,10,10, 100.0, 0.5))) ≈  1.0
        @test  sum(GibbsTypePriors.Pkn_NGGM.(1:10,10,10, 100.0, 0.5)) ==  1.0
    end
end

@testset "PY approximation for prior Kn distribution" begin
    @test_nowarn GibbsTypePriors.Pkn_PY(50, 0.2, 0.4)
    @test_nowarn GibbsTypePriors.Pkn_PY( 500, 0.2, 0.4)
    @test  Float64(sum(GibbsTypePriors.Pkn_PY( 100, 0.2, 0.4))) ≈ 1.0
    @test_nowarn GibbsTypePriors.Pkn_PY_pred_approx(100, 1.0, 0.1)
    @test_nowarn  GibbsTypePriors.Pkn_2PD_arb(1,100, 0.2, 0.4)
    @test Float64( GibbsTypePriors.Pkn_2PD_arb(1,100, 0.2, 0.4)) ==  GibbsTypePriors.Pkn_2PD(1,100, 0.2, 0.4)
    @test Float64( sum(GibbsTypePriors.Pkn_2PD_arb.(1:100,100, 0.2, 0.4))) ≈  1.
    @test Float64( sum(GibbsTypePriors.Pkn_2PD.(1:100,100, 0.2, 0.4))) ≈  1.
    @test Float64( sum(GibbsTypePriors.Pkn_PY(100, 0.2, 0.4))) ≈  1.
    @test GibbsTypePriors.Pkn_PY(100, 0.2, 0.4)== convert(Array{Float64,1},GibbsTypePriors.Pkn_2PD_arb.(1:100,100, 0.2, 0.4))
    @test  Float64(sum(GibbsTypePriors.Pkn_PY_pred_approx(100, 1.0, 0.1))) ≈  1.
    @test_nowarn GibbsTypePriors.Pkn_PDM_arb(1,100,100,1.0, 0.1)
    @test_nowarn GibbsTypePriors.Pkn_PDM_arb(1,100,200,1.0, 0.1)
    @test_nowarn GibbsTypePriors.Pkn_PDM_arb(1,100,200,100.0, 0.9)
    @test Float64(sum(GibbsTypePriors.Pkn_PDM_arb.(1:100,100,200,100.0, 0.9))) ==1
    @test_nowarn GibbsTypePriors.Pkn_PYM(1,100,200,100.0, 0.9)
    @test sum(GibbsTypePriors.Pkn_PYM.(1:100,100,200,100.0, 0.9)) ≈  1
end

@testset "DP approximation for prior Kn distribution" begin
    @test_nowarn GibbsTypePriors.Pkn_Dirichlet(7, 50, 0.2)
    @test_nowarn GibbsTypePriors.Pkn_Dirichlet_arb(7, 50, 0.2)
    @test  Float64( GibbsTypePriors.Pkn_Dirichlet_arb(7, 50, 0.2)) ==  GibbsTypePriors.Pkn_Dirichlet(7, 50, 0.2)
    @test  convert(Array{Float64,1}, GibbsTypePriors.Pkn_Dirichlet_arb.(1:50, 50, 0.2)) ==  GibbsTypePriors.Pkn_Dirichlet.(1:50, 50, 0.2)
    @test_nowarn GibbsTypePriors.Pkn_Dirichlet_mult_arb(7, 50,50,  0.2)
    @test GibbsTypePriors.Pkn_Dirichlet_mult_arb(60, 50,100,  0.2) == 0
    @test  sum(GibbsTypePriors.Pkn_Dirichlet_mult.(1:100,100, 100, 0.4)) ≈ 1.0
    @test  GibbsTypePriors.Pkn_Dirichlet_mult(50,100, 100, 0.4) <  GibbsTypePriors.Pkn_Dirichlet_mult(50,100, 400, 0.4)
    @test  GibbsTypePriors.Pkn_Dirichlet_mult(50,100, 100, 0.4) <  GibbsTypePriors.Pkn_Dirichlet(50,100, 0.4)
end

max_stars_repo_name: konkam/GibbsTypePriors

max_issues_repo_name: konkam/GibbsTypePriors

max_forks_repo_name: konkam/GibbsTypePriors


text:
Pkg.update()
Pkg.clone("https://github.com/essenciary/Genie.jl")
Pkg.clone("https://github.com/JuliaDB/DBI.jl")
Pkg.clone("https://github.com/JuliaDB/PostgreSQL.jl")
Pkg.clone("https://github.com/essenciary/Flax.jl")
Pkg.clone("https://github.com/essenciary/SearchLight.jl")

max_stars_repo_name: anirudhmurali/hello-julia-genie

max_issues_repo_name: anirudhmurali/hello-julia-genie

max_forks_repo_name: anirudhmurali/hello-julia-genie


text:
using Documenter # A package to manage documentation
using PDFHighlights # A package to create the documentation for

# Create documentation
makedocs(
    # Specify modules being used
    modules = [PDFHighlights],

    # Specify a name for the site
    sitename = "PDFHighlights.jl",

    # Specify the author
    authors = "Pavel Sobolev",

    # Specify the pages on the left side
    pages = [
        "Home" => "index.md",

        "Manual" => [
            "Guide" => "manual/guide.md",
            "Format" => "manual/format.md",
            "manual/concatenation.md"
        ],

        "Library" => [
            "Index" => "lib/index.md",
            "Public" => "lib/public.md",
            "Internals" => map(
                s -> "lib/internals/$(s)",
                [
                    "PDFHighlights.md",
                    "PDF.md",
                    "CSV.md",
                    "Both.md",
                    "Exceptions.md",
                    "Constants.md",
                ]
            ),
        ],
    ],

    # Specify a format
    format = Documenter.HTML(
            # Custom assets
            assets = ["assets/custom.css"],
            # A fallback for creating docs locally
            prettyurls = get(ENV, "CI", nothing) == "true",
        ),

    # Fail if any error occurred
    strict = true,
)

# Deploy documentation
deploydocs(
    # Specify a repository
    repo = "github.com/paveloom-j/PDFHighlights.jl.git",

    # Specify a development branch
    devbranch = "develop",
)


text:
"""
    HorizontallyCurvilinearAnisotropicDiffusivity{N, K}

Holds viscosity and diffusivities for models with prescribed isotropic diffusivities.
"""
struct HorizontallyCurvilinearAnisotropicDiffusivity{TD, NH, NZ, KH, KZ} <: AbstractTurbulenceClosure{TD}
    νh :: NH
    νz :: NZ
    κh :: KH
    κz :: KZ

    function HorizontallyCurvilinearAnisotropicDiffusivity{TD}(νh::NH, νz::NZ,
                                                               κh::KH, κz::KZ) where {TD, NH, NZ, KH, KZ}
        return new{TD, NH, NZ, KH, KZ}(νh, νz, κh, κz)
    end
end

const HCAD = HorizontallyCurvilinearAnisotropicDiffusivity

"""
    HorizontallyCurvilinearAnisotropicDiffusivity([FT=Float64;] νh=0, κh=0, νz=0, κz=0,
                                                  time_discretization = ExplicitTimeDiscretization())

Returns parameters for an anisotropic diffusivity model on curvilinear grids.

Keyword args
============

    * `νh`: Horizontal viscosity. `Number`, `AbstractArray`, or `Function(x, y, z, t)`.

    * `νz`: Vertical viscosity. `Number`, `AbstractArray`, or `Function(x, y, z, t)`.

    * `κh`: Horizontal diffusivity. `Number`, `AbstractArray`, or `Function(x, y, z, t)`, or
            `NamedTuple` of diffusivities with entries for each tracer.

    * `κz`: Vertical diffusivity. `Number`, `AbstractArray`, or `Function(x, y, z, t)`, or
            `NamedTuple` of diffusivities with entries for each tracer.
"""
function HorizontallyCurvilinearAnisotropicDiffusivity(FT=Float64; νh=0, κh=0, νz=0, κz=0,
                                                       time_discretization = ExplicitTimeDiscretization())
    νh = convert_diffusivity(FT, νh)
    νz = convert_diffusivity(FT, νz)
    κh = convert_diffusivity(FT, κh)
    κz = convert_diffusivity(FT, κz)

    TD = typeof(time_discretization)

    return HorizontallyCurvilinearAnisotropicDiffusivity{TD}(νh, νz, κh, κz)
end

function with_tracers(tracers, closure::HorizontallyCurvilinearAnisotropicDiffusivity{TD}) where TD
    κh = tracer_diffusivities(tracers, closure.κh)
    κz = tracer_diffusivities(tracers, closure.κz)
    return HorizontallyCurvilinearAnisotropicDiffusivity{TD}(closure.νh, closure.νz, κh, κz)
end

calculate_diffusivities!(diffusivities, closure::HorizontallyCurvilinearAnisotropicDiffusivity, args...) = nothing

viscous_flux_ux(i, j, k, grid, closure::HCAD, clock, U, args...) = - ν_δᶜᶜᶜ(i, j, k, grid, clock, closure.νh, U.u, U.v)
viscous_flux_uy(i, j, k, grid, closure::HCAD, clock, U, args...) = + ν_ζᶠᶠᶜ(i, j, k, grid, clock, closure.νh, U.u, U.v)
viscous_flux_uz(i, j, k, grid, closure::HCAD, clock, U, args...) = - ν_uzᶠᶜᶠ(i, j, k, grid, clock, closure.νz, U.u)

viscous_flux_vx(i, j, k, grid, closure::HCAD, clock, U, args...) = - ν_ζᶠᶠᶜ(i, j, k, grid, clock, closure.νh, U.u, U.v)
viscous_flux_vy(i, j, k, grid, closure::HCAD, clock, U, args...) = - ν_δᶜᶜᶜ(i, j, k, grid, clock, closure.νh, U.u, U.v)
viscous_flux_vz(i, j, k, grid, closure::HCAD, clock, U, args...) = - ν_vzᶜᶠᶠ(i, j, k, grid, clock, closure.νz, U.v)

@inline function diffusive_flux_x(i, j, k, grid, closure::HCAD, c, ::Val{tracer_index}, clock, args...) where tracer_index
    @inbounds κh = closure.κh[tracer_index]
    return diffusive_flux_x(i, j, k, grid, clock, κh, c)
end

@inline function diffusive_flux_y(i, j, k, grid, closure::HCAD, c, ::Val{tracer_index}, clock, args...) where tracer_index
    @inbounds κh = closure.κh[tracer_index]
    return diffusive_flux_y(i, j, k, grid, clock, κh, c)
end

@inline function diffusive_flux_z(i, j, k, grid, closure::HCAD, c, ::Val{tracer_index}, clock, args...) where tracer_index
    @inbounds κz = closure.κz[tracer_index]
    return diffusive_flux_z(i, j, k, grid, clock, κz, c)
end

#####
##### Support for vertically implicit time integration
#####

const VITD = VerticallyImplicitTimeDiscretization

z_viscosity(closure::HorizontallyCurvilinearAnisotropicDiffusivity, args...) = closure.νz
z_diffusivity(closure::HorizontallyCurvilinearAnisotropicDiffusivity, ::Val{tracer_index}, args...) where tracer_index = @inbounds closure.κz[tracer_index]

const VerticallyBoundedGrid{FT} = AbstractGrid{FT, <:Any, <:Any, <:Bounded}

@inline diffusive_flux_z(i, j, k, grid, ::VITD, closure::HCAD, args...) = zero(eltype(grid))
@inline viscous_flux_uz(i, j, k, grid, ::VITD, closure::HCAD, args...) = zero(eltype(grid))
@inline viscous_flux_vz(i, j, k, grid, ::VITD, closure::HCAD, args...) = zero(eltype(grid))

@inline function diffusive_flux_z(i, j, k, grid::VerticallyBoundedGrid{FT}, ::VITD, closure::HCAD, args...) where FT
    return ifelse(k == 1 || k == grid.Nz+1,
                  diffusive_flux_z(i, j, k, grid, ExplicitTimeDiscretization(), closure, args...), # on boundaries, calculate fluxes explicitly
                  zero(FT))
end

@inline function viscous_flux_uz(i, j, k, grid::VerticallyBoundedGrid{FT}, ::VITD, closure::HCAD, args...) where FT
    return ifelse(k == 1 || k == grid.Nz+1,
                  viscous_flux_vz(i, j, k, grid, ExplicitTimeDiscretization(), closure, args...), # on boundaries, calculate fluxes explicitly
                  zero(FT))
end

@inline function viscous_flux_vz(i, j, k, grid::VerticallyBoundedGrid{FT}, ::VITD, closure::HCAD, args...) where FT
    return ifelse(k == 1 || k == grid.Nz+1,
                  viscous_flux_uz(i, j, k, grid, ExplicitTimeDiscretization(), closure, args...), # on boundaries, calculate fluxes explicitly
                  zero(FT))
end

Base.show(io::IO, closure::HorizontallyCurvilinearAnisotropicDiffusivity) =
    print(io, "HorizontallyCurvilinearAnisotropicDiffusivity: " *
              "(νh=$(closure.νh), νz=$(closure.νz)), " *
              "(κh=$(closure.κh), κz=$(closure.κz))")


text:
using JuMP, Ipopt

@testset "dat export import consistency check" begin
    # min x - y
    # st  x + x^2 + x*y + y^2 <= 1
    #     -2 <= x, y <= 2
    # solution: x+y = -1/3
    # optimal objective -1-4/sqrt(3)

    qcqp = Problem()

    x = MPC.Variable("x", Complex)
    y = MPC.Variable("y", Real)
    b = MPC.Variable("b", Bool)

    set_objective!(qcqp, x - y)

    add_constraint!(qcqp, "ctr1", (x + x^2 + x*y + y^2) << 1)
    add_constraint!(qcqp, "ctr2", (x^3 + (1.0+3im)*conj(x^2)*x*y + y^2) << (1 + 2im))
    add_constraint!(qcqp, "ctr3", -3im << (5*b + 5im*y) << 1)
    add_constraint!(qcqp, "x_bounds", -2 << x << 2)
    add_constraint!(qcqp, "y_bounds", -2 << y << 2)

    point = Point([x], [3])
    dat_exportpath = joinpath(Pkg.dir("MathProgComplex"), "tmp_datexport")
    mkpath(splitdir(dat_exportpath)[1])

    export_to_dat(qcqp, dat_exportpath, filename="POP.dat", point=point)

    qcqp2, point2 = import_from_dat(joinpath(dat_exportpath, "POP.dat"))

    rm(joinpath(dat_exportpath, "POP.dat"))

    @test qcqp.variables == qcqp2.variables
    @test qcqp.objective == qcqp2.objective

    @test Set(keys(qcqp.constraints)) == Set(keys(qcqp2.constraints))

    for (ctrname, ctr) in qcqp.constraints
        @test qcqp.constraints[ctrname].ub == qcqp2.constraints[ctrname].ub
        @test qcqp.constraints[ctrname].lb == qcqp2.constraints[ctrname].lb
        @test qcqp.constraints[ctrname].p == qcqp2.constraints[ctrname].p
    end

    @test point == point2

    rm(dat_exportpath, recursive=true)
end

@testset "WB5.dat import and Ipopt solve" begin
    instancepath = joinpath(Pkg.dir("MathProgComplex"), "test", "instances")
    WB5_cplx, initpt = import_from_dat(joinpath(instancepath, "WB5.dat"))

    WB5 = pb_cplx2real(WB5_cplx)

    mysolver = IpoptSolver(print_level = 0)
    m, variables_jump, ctr_jump, ctr_exp = get_JuMP_cartesian_model(WB5, mysolver)
    solve(m)

    sol = get_JuMP_solution(m, variables_jump, WB5)

    @test get_objective(WB5, sol) ≈ 1146.478 atol=1e-3
end


text:
println("Hello world!");

@everywhere using Printf;

@show workdir = if length(ARGS) > 0
  ARGS[1];
else
  ".";
end

@everywhere fmt(x) = @sprintf("%07d", round(Int, 1e3*x));
@everywhere fmt_int(x) = @sprintf("%03d", x);

@everywhere function prefix(case)
  "E0-$(fmt(case[:E0]))_mu-$(fmt(case[:mu]))_kT-$(fmt(case[:kT]))_Fz-$(fmt(case[:Fz]))_Fx-$(fmt(case[:Fx]))_n-$(fmt(case[:n]))_b-$(fmt(case[:b]))";
end

cases = Any[];
E0s = [0.0; 1e-1; 1.0; 10.0];
μs = [1e-6; 1e-3; 1e-2; 1e-1; 0.5; 1.0; 2.0; 10.0];
kTs = [1.0];
Fzs = sort(vcat(-[0.25; 0.5; 0.75; 1.0; 2.0; 3.0; 4.0; 5.0; 10.0; 20.0],
                [0.0; 0.25; 0.5; 0.75; 1.0; 2.0; 3.0; 4.0; 5.0; 10.0; 20.0]));
Fxs = [0.0; 0.25; 0.5; 0.75; 1.0; 2.0; 3.0; 4.0; 5.0; 10.0; 20.0];
ns = Int[100; 200];
bs = [0.5; 1.0; 2.0];
for b in bs, n in ns, Fx in Fxs, Fz in Fzs, kT in kTs, E0 in E0s, μ in μs
    push!(cases, Dict(:E0 => E0, :mu => μ,
                      :kT => kT, :Fz => Fz,
                      :Fx => Fx, :n => n, :b => b));
end

@info "total number of cases to run: $(length(cases))";

pmap(case -> begin;
  outfile = joinpath(workdir, "$(prefix(case)).out");
  if !isfile(outfile)
    println("Running case: $case.");
    command = `julia -O 3 mcmc_eap_chain.jl --chain-type polar --energy-type interacting -b $(case[:b]) --E0 $(case[:E0]) --mu $(case[:mu]) --kT $(case[:kT]) --Fz $(case[:Fz]) --Fx $(case[:Fx]) -n $(case[:n]) --num-steps 1000000 -v 2 --prefix $(joinpath(workdir, prefix(case))) --numeric-type big`;
    output = read(command, String);
    write(outfile, output);
  else
    println("Case: $case has already been run.");
  end
end, cases);

max_stars_repo_name: grasingerm/polymer-stats

max_issues_repo_name: grasingerm/polymer-stats

max_forks_repo_name: grasingerm/polymer-stats