text:
import Base.eltype
export Shape2D, Circle, Polygon, Box2D, Line, Compound2D
export colliding, colliding_ends_free, closest, closeR

# ---------- Shape Definitions ----------

abstract Shape2D{T<:AbstractFloat}
typealias AnyVec2{T} Union{AbstractVector{T}, Tuple{T,T}}
eltype{T<:AbstractFloat}(::Type{Shape2D{T}}) = T
eltype{T<:Shape2D}(::Type{T}) = eltype(super(T))

immutable Circle{T} <: Shape2D{T}
    c::SVector{2,T}
    r::T
    xrange::SVector{2,T}
    yrange::SVector{2,T}

    function Circle(c::SVector{2,T}, r::T, xrange::SVector{2,T}, yrange::SVector{2,T})
        r <= 0 && error("Radius must be positive")
        new(c, r, xrange, yrange)
    end
end
Circle(c::AnyVec2, r) = Circle{eltype(c)}(SVector(c[1], c[2]), r,
                                          SVector(c[1]-r, c[1]+r),
                                          SVector(c[2]-r, c[2]+r))
projectNextrema(C::Circle, n::SVector{2}) = (d = dot(C.c,n); SVector(d-C.r, d+C.r))
changeprecision{T<:AbstractFloat}(::Type{T}, C::Circle) = Circle(changeprecision(T, C.c), T(C.r))

immutable Polygon{T} <: Shape2D{T}
    points::Vector{SVector{2,T}}
    edges::Vector{SVector{2,T}}
    normals::Vector{SVector{2,T}}
    xrange::SVector{2,T}
    yrange::SVector{2,T}
    nextrema::Vector{SVector{2,T}}

    function Polygon(points::Vector{SVector{2,T}})
        N = length(points)
        N < 3 && error("Polygons need at least 3 points! Try Line?")
        if sum([(points[wrap1(i+1,N)][1] - points[i][1])*(points[wrap1(i+1,N)][2] + points[i][2]) for i in 1:N]) > 0
            reverse!(points)
        end
        edges = [points[wrap1(i+1,N)] - points[i] for i in 1:N]
        normals = [normalize(perp(g)) for g in edges]
        any(-pi .<= diff([T[atan2(n) for n in normals]; atan2(normals[1])]) .<= 0) && error("Polygon must be convex")
        xrange = SVector(extrema([points[i][1] for i in 1:N]))
        yrange = SVector(extrema([points[i][2] for i in 1:N]))
        nextrema = [projectNextrema(points, normals[i]) for i in 1:N]
        new(points, edges, normals, xrange, yrange, nextrema)
    end
end
Polygon{T<:AnyVec2}(points::Vector{T}) = Polygon{eltype(T)}(SVector{2,eltype(T)}[SVector(p[1],p[2]) for p in points])
Box2D(xr::AnyVec2, yr::AnyVec2) = Polygon([SVector(xr[1], yr[1]),
                                           SVector(xr[2], yr[1]),
                                           SVector(xr[2], yr[2]),
                                           SVector(xr[1], yr[2])])
projectNextrema(P::Polygon, n::SVector{2}) = projectNextrema(P.points, n)
changeprecision{T<:AbstractFloat}(::Type{T}, P::Polygon) = Polygon(changeprecision(T, P.points))

immutable Line{T} <: Shape2D{T}   # special case of Polygon; only 1 edge/normal
    v::SVector{2,T}
    w::SVector{2,T}
    edge::SVector{2,T}
    normal::SVector{2,T}
    xrange::SVector{2,T}
    yrange::SVector{2,T}
    ndotv::T

    function Line(v::SVector{2,T}, w::SVector{2,T})
        edge = w - v
        normal = perp(edge)     # notably not normalized, for speed; can't be used for Circle SAT
        xrange = minmaxV(v[1],w[1])
        yrange = minmaxV(v[2],w[2])
        ndotv = dot(v, normal)
        new(v, w, edge, normal, xrange, yrange, ndotv)
    end
end
Line(v::AnyVec2, w::AnyVec2) = Line{eltype(v)}(SVector(v[1],v[2]), SVector(w[1],w[2]))
projectNextrema(L::Line, n::SVector{2}) = minmaxV(dot(L.v,n), dot(L.w,n))
changeprecision{T<:AbstractFloat}(::Type{T}, L::Line) = Line(changeprecision(T, L.v), changeprecision(T, L.w))

immutable Compound2D{T} <: Shape2D{T}
    parts::Vector{Shape2D{T}}
    xrange::SVector{2,T}
    yrange::SVector{2,T}
end
function Compound2D{S<:Shape2D}(parts::Vector{S})
    T = eltype(S)
    isempty(parts) && return Compound2D{T}(Shape2D{T}[], zeros(SVector{2,T}), zeros(SVector{2,T}))
    Compound2D(parts...)
end
function Compound2D{T}(parts::Shape2D{T}...)
    xrange = SVector(minimum([P.xrange[1] for P in parts]), maximum([P.xrange[2] for P in parts]))
    yrange = SVector(minimum([P.yrange[1] for P in parts]), maximum([P.yrange[2] for P in parts]))
    Compound2D{T}(Shape2D{T}[parts...], xrange, yrange)
end
changeprecision{T<:AbstractFloat}(::Type{T}, C::Compound2D) =
    Compound2D(Shape2D{T}[changeprecision(T,P) for P in C.parts])

typealias PolyOrLine{T} Union{Polygon{T}, Line{T}}
typealias Basic2D{T} Union{Circle{T}, Polygon{T}}    # TODO: Figure out why I have Shape2D, PolyOrLine, and Basic2D

# type AABB{T} <: Shape2D{T}  # a bit late to the party; could refactor other Shapes
#     xrange::Vector2{T}
#     yrange::Vector2{T}
# end
# AABB{T}(x1::T, x2::T, y1::T, y2::T) = AABB{T}(Vector2(x1,x2), Vector2(y1,y2))

# ---------- Separating Axis ----------

is_separating_axis(S1::Shape2D, S2::Shape2D, ax::SVector{2}) =
    !overlapping(projectNextrema(S1,ax), projectNextrema(S2,ax))
is_separating_axis(P::Polygon, S::Shape2D, i::Integer) = !overlapping(P.nextrema[i], projectNextrema(S, P.normals[i]))
is_separating_axis(L::Line, P::Polygon) = !ininterval(L.ndotv, projectNextrema(P, L.normal))

# ---------- Collision Checking ----------

## Broadphase
AABBseparated(S1::Shape2D, S2::Shape2D) = !(overlapping(S1.xrange, S2.xrange) && overlapping(S1.yrange, S2.yrange))
pointinAABB(p::AbstractVector, S::Shape2D) = ininterval(p[1], S.xrange) && ininterval(p[2], S.yrange)
## Point collision
colliding(p::AbstractVector, C::Circle) = norm2(p - C.c) <= C.r^2
colliding(C::Circle, p::AbstractVector) = norm2(p - C.c) <= C.r^2
function colliding(p::AbstractVector, P::Polygon)
    !pointinAABB(p,P) && return false
    @all [!ininterval(dot(p, P.normals[i]), P.nextrema[i]) for i in 1:length(P.normals)]
end
colliding(P::Polygon, p::AbstractVector) = colliding(p,P)
function colliding(p::AbstractVector, C::Compound2D)
    !pointinAABB(p,C) && return false
    @any [colliding(p,P) for P in C.parts]
end
colliding(C::Compound2D, p::AbstractVector) = colliding(p,C)
## Shape collision
colliding(C1::Circle, C2::Circle) = norm2(C1.c - C2.c) <= (C1.r + C2.r)^2
function colliding(C::Circle, P::Polygon)
    AABBseparated(C,P) && return false
    N = length(P.edges)
    for i in 1:N
        pi2c = C.c - P.points[i]
        VR = voronoi_region(pi2c, P.edges[i])
        if VR == 0
            dot(pi2c, P.normals[i]) > C.r && return false
        else
            j = wrap1(i+VR,N)
            pj2c = C.c - P.points[j]
            VR*voronoi_region(pj2c, P.edges[j]) < 0 && norm2(VR > 0 ? pj2c : pi2c) > C.r^2 && return false
        end
    end
    true
end
colliding(P::Polygon, C::Circle) = colliding(C,P)
function colliding(P1::Polygon, P2::Polygon)
    AABBseparated(P1,P2) && return false
    !(@any [is_separating_axis(P1,P2,i) for i in 1:length(P1.normals)]) &&
    !(@any [is_separating_axis(P2,P1,i) for i in 1:length(P2.normals)])
end
function colliding(C::Compound2D, S::Shape2D)
    AABBseparated(C,S) && return false
    @any [colliding(P,S) for P in C.parts]
end
colliding(S::Circle, C::Compound2D) = colliding(C,S)   # colliding(S::Shape2D, C::Compound2D) is type-ambiguous?
colliding(S::Polygon, C::Compound2D) = colliding(C,S)
## Swept collisions
function colliding_ends_free(L::Line, C::Circle)
    AABBseparated(L,C) && return false
    vc = C.c-L.v
    d2 = norm2(L.edge)
    d2*C.r^2 < cross(L.edge, vc)^2 && return false
    0 <= dot(vc, L.edge) <= d2
end
function colliding_ends_free(L::Line, P::Polygon)
    AABBseparated(L,P) && return false
    is_separating_axis(L,P) && return false
    !(@any [is_separating_axis(P,L,i) for i in 1:length(P.normals)])
end
colliding_ends_free(B::Basic2D, L::Line) = colliding_ends_free(L,B)
colliding(L::Line, B::Basic2D) = colliding_ends_free(L,B) || colliding(L.v,B) || colliding(L.w,B)
colliding(B::Basic2D, L::Line) = colliding(L,B)
colliding(L::Line, C::Compound2D) = colliding(C,L)
function colliding_ends_free(L::Line, C::Compound2D)
    AABBseparated(L,C) && return false
    @any [colliding_ends_free(L,P) for P in C.parts]
end
colliding_ends_free(C::Compound2D, L::Line) = colliding(C,L)

# ---------- Transformations ----------

inflate{T}(C::Circle{T}, ε; roundcorners = true) = Circle(C.c, C.r + T(ε))
function inflate{T}(P::Polygon{T}, ε; roundcorners = true)
    push_out_corner_vector(n0, n1) = (abs(cross(n0, n1)) < T(1e-6) ? n0 : (perp(n1) - perp(n0)) / cross(n0, n1))
    ε = T(ε)
    N = length(P.points)
    S = eltype(P.points)
    if !roundcorners
        return Polygon(S[P.points[i] + ε*push_out_corner_vector(P.normals[wrap1(i-1,N)], P.normals[i]) for i in 1:N])
    end
    Compound2D(
        Polygon(vcat([S[P.points[i] + ε*P.normals[wrap1(i-1,N)], P.points[i] + ε*P.normals[i]] for i in 1:N]...)),
        [Circle(p, ε) for p in P.points]...
    )
end
inflate{T}(C::Compound2D{T}, ε; roundcorners = true) =
    Compound2D(Shape2D{T}[inflate(P, T(ε), roundcorners=roundcorners) for P in C.parts])

# ---------- Closest Point ---------

function closest(p::AbstractVector, C::Circle)
    xmin = C.c + C.r*normalize(p - C.c)
    norm2(p-xmin), xmin
end
closest(p::AbstractVector, C::Circle, W::AbstractMatrix) = closest(p, C, eigfact(W))
function closest{T}(p::AbstractVector, C::Circle{T}, EF::Base.Eigen)
    ctop = p - C.c
    v1 = SVector{2,T}(EF[:vectors][1:2,1])
    v2 = SVector{2,T}(EF[:vectors][1:2,2])
    p1 = dot(v1, ctop)
    p2 = dot(v2, ctop)
    s1, s2 = EF[:values]
    lambda = one(T)
    f = (p1*s1/(lambda+s1))^2 + (p2*s2/(lambda+s2))^2 - C.r^2
    while abs(f) > 1e-8
        fp = -2/(lambda+s1)*(p1*s1/(lambda+s1))^2 + -2/(lambda+s2)*(p2*s2/(lambda+s2))^2
        alpha = one(T)
        lambdanew = one(T)
        fnew = one(T)
        while true      # crappy linesearch
            lambdanew = lambda - alpha*f/fp
            fnew = (p1*s1/(lambdanew+s1))^2 + (p2*s2/(lambdanew+s2))^2 - C.r^2
            abs(fnew) < abs(f) && break
            alpha /= 2
        end
        f = fnew
        lambda = lambdanew
    end
    xmin = C.c + v1*p1*s1/(lambda+s1) + v2*p2*s2/(lambda+s2)
    s1*(p1-p1*s1/(lambda+s1))^2 + s2*(p2-p2*s2/(lambda+s2))^2, xmin
end
closest(p::AbstractVector, P::Polygon) = closest_polypts(p, P.points)
function closest_polypts{T}(p::AbstractVector, points::Vector{SVector{2,T}})
    N = length(points)
    d2min, vmin = T(Inf), points[1]
    for i in 1:N
        edge = points[wrap1(i+1,N)] - points[i]
        x = dot(edge, p - points[i]) / norm2(edge)
        v = (x < 0 ? points[i] : (x < 1 ? points[i] + x*edge : points[wrap1(i+1,N)]))
        d2 = norm2(p - v)
        if d2 < d2min
            d2min, vmin = d2, v
        end
    end
    d2min, vmin
end
function closest(p::AbstractVector, P::Polygon, W::AbstractMatrix)
    L = SMatrix{2,2}(chol(W))
    xmin = inv(L)*closest_polypts(L*p, eltype(P.points)[L*pt for pt in P.points])[2]
    dot(xmin-p, W*(xmin-p)), xmin
end
function closest{T}(p::AbstractVector, C::Compound2D{T})
    d2min, vmin = T(Inf), zeros(SVector{2,T})
    for P in C.parts
        d2, v = closest(p, P)
        if d2 < d2min
            d2min, vmin = d2, v
        end
    end
    d2min, vmin
end
function closest{T}(p::AbstractVector, C::Compound2D{T}, W::AbstractMatrix)  # TODO: macro, iterator, or v0.5 generator
    d2min, vmin = T(Inf), zeros(SVector{2,T})
    for P in C.parts
        d2, v = closest(p, P, W)
        if d2 < d2min
            d2min, vmin = d2, v
        end
    end
    d2min, vmin
end

function closeR(p::AbstractVector, P::Basic2D, W::AbstractMatrix, r2)  # pretty janky
    cplist = [closest(p, P, W)]
    cplist[1][1] < r2 ? cplist[1:1] : cplist[1:0]
end
closeR(p::AbstractVector, C::Compound2D, W::AbstractMatrix, r2) =
    sort!(vcat([closeR(p, P, W, r2) for P in C.parts]...), by=first)

# ---------- Plotting ----------

plot(C::Circle; kwargs...) = plot_circle(C.c, C.r; kwargs...)
plot(P::Polygon; kwargs...) = plot_polygon(P.points; kwargs...)
plot(C::Compound2D; kwargs...) = for P in C.parts; plot(P; kwargs...); end
plot(L::Line; kwargs...) = plot_path([L.v L.w]; kwargs...)

# function composable(P::Polygon, opts = (fill("red"), fillopacity(1.)))
#     compose(context(), polygon([(p[1],p[2]) for p in P.points]), opts...)
# end

# function composable(C::Compound2D, opts = (fill("red"), fillopacity(1.)))
#     compose(context(), [composable(P, opts) for P in C.parts]...)
# end

# function composable(L::Line, opts = (stroke("black"),))
#     compose(context(), line([(L.v[1], L.v[2]), (L.w[1], L.w[2])]), opts...)
# end


text:
export opInverse, opCholesky, opLDL, opHouseholder, opHermitian

function mulFact(res, F, v, α, β)
  res .= α .* (F \ v) .+ β .* res
end

function tmulFact(res, F, u, α, β)
  res .= α .* conj.(F \ conj.(u)) .+ β .* res
end

"""
    opInverse(Mv, Mtu, Maw, M; symm=false, herm=false)
    opInverse(M; symm=false, herm=false)
Inverse of a matrix as a linear operator using `\\` with storage vectors `Mv`, `Mtu`, `Maw`.
Useful for triangular matrices. Note that each application of this
operator applies `\\`.
This Operator is not in-place when using `mul!`.
"""
function opInverse(Mv::AbstractVector{T}, Mtu::AbstractVector{T}, Maw::AbstractVector{T}, M::AbstractMatrix{T};
                   symm = false, herm = false) where {T}
  prod = @closure (res, v, α, β) -> mulFact(res, M, v, α, β)
  tprod = @closure (res, u, α, β) -> mulFact(res, transpose(M), u, α, β)
  ctprod = @closure (res, w, α, β) -> mulFact(res, adjoint(M), w, α, β)
  LinearOperator{T}(size(M, 2), size(M, 1), symm, herm, prod, tprod, ctprod, Mv, Mtu, Maw)
end

function opInverse(M::AbstractMatrix{T}; symm = false, herm = false) where {T}
  Mv = zeros(T, size(M, 2))
  Mtu = symm ? Mv : zeros(T, size(M, 1))
  Maw = herm ? Mv : zeros(T, size(M, 1))
  return opInverse(Mv, Mtu, Maw, M, symm = symm, herm = herm)
end

"""
    opCholesky(M, [check=false])
Inverse of a Hermitian and positive definite matrix as a linear operator
using its Cholesky factorization with storage vector `Mv`.
The factorization is computed only once.
The optional `check` argument will perform cheap hermicity and definiteness
checks.
This Operator is not in-place when using `mul!`.
"""
function opCholesky(Mv::AbstractVector{T}, M::AbstractMatrix; check::Bool = false) where {T}
  (m, n) = size(M)
  m == n || throw(LinearOperatorException("shape mismatch"))
  if check
    check_hermitian(M) || throw(LinearOperatorException("matrix is not Hermitian"))
    check_positive_definite(M) || throw(LinearOperatorException("matrix is not positive definite"))
  end
  LL = cholesky(M)
  prod = @closure (res, v, α, β) -> mulFact(res, LL, v, α, β)
  tprod = @closure (res, u, α, β) -> tmulFact(res, LL, u, α, β)  # M.' = conj(M)
  ctprod = @closure (res, w, α, β) -> mulFact(res, LL, w, α, β)
  S = eltype(LL)
  LinearOperator{S}(m, m, isreal(M), true, prod, tprod, ctprod, Mv, Mv, Mv)
  #TODO: use iterative refinement.
end

opCholesky(M::AbstractMatrix; check::Bool = false) = opCholesky(zeros(size(M,1)), M; check = check)

"""
    opLDL(M, [check=false])
Inverse of a symmetric matrix as a linear operator using its LDL' factorization
if it exists with storage vector `Mv`. The factorization is computed only once. The optional `check`
argument will perform a cheap hermicity check.
"""
function opLDL(Mv::AbstractVector{T}, M::AbstractMatrix; check::Bool = false) where {T}
  (m, n) = size(M)
  m == n || throw(LinearOperatorException("shape mismatch"))
  if check
    check_hermitian(M) || throw(LinearOperatorException("matrix is not Hermitian"))
  end
  LDL = ldlt(M)
  prod = @closure (res, v, α, β) -> mulFact(res, LDL, v, α, β)
  tprod = @closure (res, u, α, β) -> tmulFact(res, LDL, u, α, β)  # M.' = conj(M)
  ctprod = @closure (res, w, α, β) -> mulFact(res, LDL, w, α, β)
  S = eltype(LDL)
  return LinearOperator{S}(m, m, isreal(M), true, prod, tprod, ctprod, Mv, Mv, Mv)
  #TODO: use iterative refinement.
end

opLDL(M::AbstractMatrix; check::Bool = false) = opLDL(zeros(size(M,1)), M; check = check)

function mulHouseholder!(res, h, v, α, β)
  res .= α .* (v .- 2 * dot(h, v) .* h) .+ β .* res
end

"""
    opHouseholder(Mv, Mtu, h)
    opHouseholder(h)
Apply a Householder transformation defined by the vector `h` with storage vectors Mv, Mtu.
The result is `x -> (I - 2 h h') x`.
"""
function opHouseholder(Mv::AbstractVector{T}, Mtu::AbstractVector{T}, h::AbstractVector{T}) where {T}
  n = length(h)
  prod! = @closure (res, v, α, β) -> mulHouseholder!(res, h, v, α, β)  # tprod will be inferred
  LinearOperator{T}(n, n, isreal(h), true, prod!, nothing, prod!, Mv, Mtu, Mv)
end

function opHouseholder(h::AbstractVector{T}) where {T}
  Mv = similar(h, length(h))
  Mtu = isreal(h) ? Mv : copy(Mv)
  return opHouseholder(Mv, Mtu, h)
end

function mulHermitian(res, d, L, v,  α, β)
  res .= α .* (d .* v .+ L * v .+ (v' * L)')[:] .+ β .* res
end

"""
    opHermitian(Mv, d, A)
    opHermitian(d, A)
A symmetric/hermitian operator based on the diagonal `d` and lower triangle of `A`.
"""
function opHermitian(Mv::AbstractVector{T}, d::AbstractVector{S}, A::AbstractMatrix{T}) where {S, T}
  m, n = size(A)
  m == n == length(d) || throw(LinearOperatorException("shape mismatch"))
  L = tril(A, -1)
  U = promote_type(S, T)
  prod = @closure (res, v, α, β) -> mulHermitian(res, d, L, v, α, β)
  LinearOperator{U}(m, m, isreal(A), true, prod, nothing, nothing, Mv, Mv, Mv)
end

opHermitian(d::AbstractVector{S}, A::AbstractMatrix{T}) where {S, T} = opHermitian(zeros(T, size(A, 1)), d, A)

"""
    opHermitian(A)
A symmetric/hermitian operator based on a matrix.
"""
function opHermitian(T::AbstractMatrix)
  d = diag(T)
  opHermitian(d, T)
end

ext: jl


text:
export Boussinesq

"""
    Boussinesq(params;kwargs)

Define an object of type `AbstractModel` in view of solving the initial-value problem for
`abcd`-Boussinesq models (with `b=d` and `c=0`).
(see Bona, J. L.; Chen, M. & Saut, J.-C., doi:10.1007/s00332-002-0466-4)

# Argument
`param` is of type `NamedTuple` and must contain

- dimensionless parameters `ϵ` (nonlinearity) and `μ` (dispersion);
- numerical parameters to construct the mesh of collocation points as `mesh = Mesh(param)`

## Optional keyword arguments
- two parameters `a` (default is `-1/3`) and `b` (default is `+1/3`) which determine the model solved. You need `a+2*b=1/3` for validity as a long wave model (without surface tension).
- `ktol`: tolerance of the low-pass Krasny filter (default is `0`, i.e. no filtering);
- `dealias`: dealiasing with Orlicz rule `1-dealias/(dealias+2)` (default is `0`, i.e. no dealiasing).
- `verbose`: prints information if `true` (default is `true`).

# Return values
Generate necessary ingredients for solving an initial-value problem via `solve!` and in particular
1. a function `Boussinesq.f!` to be called in the time-integration solver;
2. a function `Boussinesq.mapto` which from `(η,v)` of type `InitialData` provides the raw data matrix on which computations are to be executed;
3. a function `Boussinesq.mapfro` which from such data matrix returns the Tuple of real vectors `(η,v)`, where

    - `η` is the surface deformation;
    - `v` is the derivative of the trace of the velocity potential.

"""
mutable struct Boussinesq <: AbstractModel

	label   :: String
	f!		:: Function
	mapto	:: Function
	mapfro	:: Function
	param	:: NamedTuple
	kwargs	:: NamedTuple

    function Boussinesq(param::NamedTuple;
						a=-1/3,b=1/3,α=1, #α plays no role, but must be provided to WhithamBoussinesq
						dealias=0,ktol=0,verbose=true)

		m=WhithamBoussinesq(param;Boussinesq=true,a=a,b=b,
							dealias=dealias,ktol=ktol,verbose=verbose)

		new(m.label, m.f!, m.mapto, m.mapfro, m.param, m.kwargs)
    end
end


text:
import Pkg
Pkg.add("CSV")
Pkg.add("DataFrames")
Pkg.add("ArgParse")
Pkg.add("Glob")

max_stars_repo_name: Peter-Vincent/Harpist

max_issues_repo_name: Peter-Vincent/Harpist

max_forks_repo_name: Peter-Vincent/Harpist


text:
# Allow styling of GraphViz Dot diagrams independent of graph type.

md"""
A *graph style* is a type that supportes these methods:

  - graph_attributes(::GraphStyle)
  - node_attributes(::GraphStyle)
  - node_attributes(::GraphStyle, node)
  - edge_attributes(::GraphStyle)
  - edge_attributes(::GraphStyle, from, to)

These all should return a `Dict{Symbol, AbstractString}`.

Default methods are provided that give default Dot behavior.
"""

export graph_attributes, node_attributes, edge_attributes
export AbstractDotStyleWhiteOnBlack, DotStyleWhiteOnBlack

"""
    graph_attributes(dotstyle)
Return a Dict of graph level attributes (for the Dot `graph` statement).
"""
graph_attributes(dotstyle) = Dict{Symbol, AbstractString}()

"""
    node_attributes(dotstyle)
Return a Dict of the default node attributes that should apply to all nodes of `graph`.
"""
node_attributes(dotstyle) = Dict{Symbol, AbstractString}()

"""
    node_attributes(dotstyle, node)
Return a Dict of the Dot attributes to be used when rendering `node`.
"""
node_attributes(dotstyle, node) = Dict{Symbol, AbstractString}()

"""
    edge_attributes(dotstyle)
Return a Dict of the default attributes that should apply to all edges of `graph`.
"""
edge_attributes(dotstyle) = Dict{Symbol, AbstractString}()

"""
    edge_attributes(dotstyle, from, to)
Return a Dict of the Dot attributes to be used when rendering the edge
running from `from` to `to`, which are both nodes.
"""
edge_attributes(dotstyle, from, to) = Dict{Symbol, AbstractString}()

md"""
A style for formatting graphs as white against a black background.
"""
abstract type AbstractDotStyleWhiteOnBlack end

graph_attributes(style::AbstractDotStyleWhiteOnBlack) = Dict{Symbol, AbstractString}([
    (:bgcolor, "black"),
    (:color, "white")
])

node_attributes(style::AbstractDotStyleWhiteOnBlack) = Dict{Symbol, AbstractString}([
    (:color, "white"),
    (:fontcolor, "white")
])

edge_attributes(style::AbstractDotStyleWhiteOnBlack) = Dict{Symbol, AbstractString}([
    (:color, "white")
])

struct DotStyleWhiteOnBlack <: AbstractDotStyleWhiteOnBlack end


text:
function main()

  println("#######################")
  println("### AoC2021 - Day 8 ###")
  println("#######################")

  println(" 3 THREADS : 0.103469 seconds (139.97 k allocations: 7.868 MiB, 95.28% compilation time)")
  println(" 6 THREADS : 0.103764 seconds (140.03 k allocations: 7.872 MiB, 95.39% compilation time)")
  println(" 2 THREADS : 0.101803 seconds (139.96 k allocations: 7.867 MiB, 94.77% compilation time)")
  println(" 10 THREADS :  0.110305 seconds (140.11 k allocations: 7.878 MiB, 94.27% compilation time)")
  println(" 1 THREAD : 0.102803 seconds (139.96 k allocations: 7.866 MiB, 90.45% compilation time)")

  println(">> @arg1 : Input file")
  println()

  if ( size(ARGS)[1] != 1 )
    println("FATAL ERROR : Invalid number of args. Input file is required as @arg1.")
    quit()
  end

  if ( Threads.nthreads() <= 1)
    println("Launch threads in command by calling : julia --threads [n_threads] <...>")
  end

# open input file
fd = open(ARGS[1], "r")
vals = readlines(ARGS[1])
if (size(vals)[1] <= 1)
  println("INVALID INPUT : Not enough data for meaningful answer.")
  quit()
end

  # close file
  close(fd)

  # read matrix
  n_lines = length(vals)
  n_cols  = length(vals[1])

  matrix = zeros(Int, n_lines, n_cols)
  line = ""
  for i=1:n_lines
    line = vals[i]
    for j=1:length(line)
      matrix[i,j] = parse(Int,line[j])
    end
  end

  # thread compute matrixuu
  #println("input : $matrix \n")

  lowpoints = zeros(Int, n_lines, n_cols)
  # thread id repartiton per line
  Threads.@threads for t=1:n_lines

    tid = Threads.threadid()

    # create submatrixes to avoid mem conflict in each thread (naive repartiton)
    submatrix = Matrix{Int64}(undef,0,n_cols)

    is_firstline = ( t == 1)
    is_lastline =  ( t == n_lines )
    if (!is_firstline && !is_lastline)
      submatrix = matrix[(t-1):(t+1), :]
    elseif ( is_firstline )
      submatrix = matrix[t:(t+1), :]
    else
      submatrix = matrix[(t-1):t, :]
    end
    #println("SUBMAT  $t, thread $tid : $submatrix")

    # find low pointz
    for j=1:n_cols

      val = 0
      up = 0
      down = 0
      left = 0
      right = 0

      is_firstcol = (j==1)
      is_lastcol = (j == n_cols)

      if is_firstline
        val = submatrix[1,j]
        up = 9
        down = submatrix[2,j]
        right = is_lastcol ? 9 : submatrix[1,j+1]
        left = is_firstcol ? 9 : submatrix[1,j-1]
      elseif is_lastline
        val = submatrix[2,j]
        up = submatrix[1,j]
        down = 9
        right = is_lastcol ? 9 : submatrix[2,j+1]
        left = is_firstcol ? 9 : submatrix[2,j-1]
      else
        val = submatrix[2,j]
        up = submatrix[1,j]
        down = submatrix[3,j]
        right = is_lastcol ? 9 : submatrix[2,j+1]
        left = is_firstcol ? 9 : submatrix[2,j-1]
      end

      if ( (val < up) && (val < down) && (val < right) && (val<left) )
          lowpoints[t,j] = 1 + val
      end

    end

  end #!threads ends

  #println(lowpoints)
  tot_risk = sum(lowpoints)
  println("RESULT P1 : $tot_risk" )

end

@time main()


text:
module LDUFacts

using LinearAlgebra

using LinearAlgebra: checksquare
using LinearAlgebra: PivotingStrategy, NoPivot
import LinearAlgebra: rmul!, lmul!, ldiv!, rdiv!, adjoint, det, logdet, logabsdet
import Base: *, \, /, size, inv

export ldu, ldu!, ldu_update!
export NoPivot, DiagonalPivot, FullPivot, PivotLike

struct LDUPivoted{T,V<:AbstractMatrix{T},F<:Real} <: Factorization{T}
    factors::V
    piv::Vector{Int}
    rank::Int
    tol::F
    info::Int
    pam::Vector{Int}
    ame::Vector{T}
end

struct LDUPerm{T}
    piv::Vector{Int}
    pam::Vector{Int}
    ame::Vector{T}
    LDUPerm(piv, pam, ame::AbstractVector{T}) where T = new{T}(piv, pam, Vector{T}(ame))
end

struct DiagonalPivot <: PivotingStrategy end
struct FullPivot <: PivotingStrategy end
struct PivotLike{T} <: PivotingStrategy
    piv::Vector{Int}
    pam::Vector{Int}
    ame::Vector{T}
    PivotLike(la::LDUPivoted{T}) where T = new{T}(la.piv, la.pam, la.ame)
end

const SATMatrix{T} = Union{StridedMatrix{T}, Adjoint{T,<:StridedMatrix}, Transpose{T,<:StridedMatrix}}

include("ldufact.jl")
include("lduupdate.jl")

end # module


text:
struct EquationSet <: AbstractEquationSet
  eq_1::AbstractEquation
  eq_2::AbstractEquation
  eq_3::AbstractEquation

  R_0::AbstractSymbol
  B_0::AbstractSymbol
  I_P::AbstractSymbol
end

function EquationSet(cur_reactor::AbstractReactor, secondary_constraint::AbstractEquation)
  primary_constraint = power_balance_equation(cur_reactor)

  tertiary_constraint = T_bar_equation(cur_reactor, symbols(:T_bar_const))

  cur_equations = [primary_constraint, secondary_constraint, tertiary_constraint]

  cur_variable_list = [:R_0, :B_0]
  cur_indices = [1, 2]

  cur_gamma_RBI = cur_equations[first(cur_indices)].R_0 * cur_equations[last(cur_indices)].B_0

  cur_gamma_RBI -= cur_equations[last(cur_indices)].R_0 * cur_equations[first(cur_indices)].B_0

  cur_dict = OrderedDict()

  cur_I_P = safe_get(cur_reactor, :I_P)

  is_bad_I_P = !isa(cur_I_P, SymEngine.Basic) && cur_I_P < 0

  for (cur_index, cur_variable) in enumerate(cur_variable_list)
    if is_bad_I_P
      cur_dict[cur_variable] = NaN
      continue
    end

    other_variables = [ cur_variable_list[cur_index+1:end]..., cur_variable_list[1:cur_index-1]... ]

    cur_formula = 1.0

    for cur_sub_index in cur_indices
      other_indices = [ cur_indices[cur_sub_index+1:end]..., cur_indices[1:cur_sub_index-1]... ]

      cur_exponent = (
        getfield(cur_equations[first(other_indices)], first(other_variables))
      )

      ( cur_index == cur_sub_index ) ||
        ( cur_exponent *= -1 )

      cur_formula *= cur_equations[cur_sub_index].G_T ^ cur_exponent

      cur_formula /= cur_I_P ^ ( cur_exponent * cur_equations[cur_sub_index].I_P )
    end

    if !isa(cur_formula, SymEngine.Basic) && cur_formula < 0
      cur_formula = NaN
    else
      cur_formula ^= ( 1 / cur_gamma_RBI )
    end

    cur_dict[cur_variable] = cur_formula
  end

  cur_equation_set = EquationSet(
    cur_equations..., values(cur_dict)..., symbols(:I_P)
  )

  cur_equation_set
end

function EquationSet(cur_reactor::AbstractReactor, secondary_constraint::AbstractEquation, tertiary_constraint::AbstractEquation)
  primary_constraint = power_balance_equation(cur_reactor)

  cur_equations = [primary_constraint, secondary_constraint, tertiary_constraint]

  cur_variable_list = [:R_0, :B_0, :I_P]
  cur_indices = [1, 2, 3]

  cur_gamma_RBI = 0.0

  for cur_index in cur_indices
    other_indices = [ cur_indices[cur_index+1:end]..., cur_indices[1:cur_index-1]... ]

    cur_sub_gamma = cur_equations[first(other_indices)].B_0 * cur_equations[last(other_indices)].I_P

    cur_sub_gamma -= cur_equations[last(other_indices)].B_0 * cur_equations[first(other_indices)].I_P

    cur_sub_gamma *= cur_equations[cur_index].R_0

    cur_gamma_RBI += cur_sub_gamma
  end

  cur_dict = OrderedDict()

  for (cur_index, cur_variable) in enumerate(cur_variable_list)
    other_variables = [ cur_variable_list[cur_index+1:end]..., cur_variable_list[1:cur_index-1]... ]

    cur_formula = 1.0

    for cur_sub_index in cur_indices
      other_indices = [ cur_indices[cur_sub_index+1:end]..., cur_indices[1:cur_sub_index-1]... ]

      cur_exponent = (
        getfield(cur_equations[first(other_indices)], first(other_variables)) *
        getfield(cur_equations[last(other_indices)], last(other_variables))
      )

      cur_exponent -= (
        getfield(cur_equations[first(other_indices)], last(other_variables)) *
        getfield(cur_equations[last(other_indices)], first(other_variables))
      )

      cur_G_T = cur_equations[cur_sub_index].G_T

      if !isa(cur_G_T, SymEngine.Basic) && cur_G_T < 0
        cur_formula = NaN
      else
        cur_formula *= cur_G_T ^ cur_exponent
      end
    end

    cur_formula ^= ( 1 / cur_gamma_RBI )

    cur_dict[cur_variable] = cur_formula
  end

  cur_equation_set = EquationSet(
    cur_equations..., values(cur_dict)...
  )

  cur_equation_set
end

function equation_set_dict(cur_equation_set::EquationSet)
  cur_dict = Dict()

  cur_dict[symbols(:R_0)] = cur_equation_set.R_0
  cur_dict[symbols(:B_0)] = cur_equation_set.B_0

  ( cur_equation_set.I_P == symbols(:I_P) ) && return cur_dict

  cur_dict[symbols(:I_P)] = cur_equation_set.I_P

  cur_dict
end


text:
include("buffer.jl")
include("sumtree.jl")

import Random
import Base.getindex, Base.size
import DataStructures

abstract type AbstractReplay end

abstract type AbstractWeightedReplay <: AbstractReplay end

mutable struct ExperienceReplay{CB<:CircularBuffer} <: AbstractReplay
    buffer::CB
end

ExperienceReplay(size, types, column_names) =
    ExperienceReplay(CircularBuffer(size, types, column_names))

size(er::ExperienceReplay) = size(er.buffer)
@forward ExperienceReplay.buffer getindex

add!(er::ExperienceReplay, experience) = add!(er.buffer, experience)

function sample(er::ExperienceReplay, batch_size; rng=Random.GLOBAL_RNG)
    idx = rand(rng, 1:size(er), batch_size)
    return getrow(er.buffer, idx)
end

mutable struct OnlineReplay{CB<:DataStructures.CircularBuffer, T<:Tuple} <: AbstractReplay
    buffer::CB
    column_names::T
end

OnlineReplay(size, types, column_names) =
    OnlineReplay(DataStructures.CircularBuffer{Tuple{types...}}(size), tuple(column_names...))

size(er::OnlineReplay) = size(er.buffer)
@forward OnlineReplay.buffer Base.lastindex
function getindex(er::OnlineReplay, idx)
    data = er.buffer[idx]
    NamedTuple{er.column_names}((getindex.(data, i) for i in 1:length(er.column_names)))
end
isfull(er::OnlineReplay) = DataStructures.isfull(er.buffer)
add!(er::OnlineReplay, experience) = push!(er.buffer, experience)

function sample(er::OnlineReplay, batch_size; rng=Random.GLOBAL_RNG)
    @assert batch_size <= size(er.buffer)[1]
    return er[(end-batch_size+1):end]
end

mutable struct WeightedExperienceReplay{CB<:CircularBuffer} <: AbstractWeightedReplay
    buffer::CB
    sumtree::SumTree
end

WeightedExperienceReplay(size, types, column_names) =
    new(CircularBuffer(size, types, column_names),
        SumTree{Int64}(size))

size(er::WeightedExperienceReplay) = size(er.buffer)
@forward WeightedExperienceReplay.buffer getindex

function add!(er::WeightedExperienceReplay, experience, weight)
    idx = add!(er.buffer, experience)
    add!(er.sumtree, weight, idx)
    return
end

function sample(er::WeightedExperienceReplay, batch_size; rng=Random.GLOBAL_RNG)
    batch_idx, batch_priorities, idx = sample(er.sumtree, batch_size; rng=rng)
    return getrow(er.buffer, idx)
end


text:
@testset "tracked" begin

    ex = quote
        x2 = W * x .+ b
        x3 = exp.(x2)
        x4 = reshape(x3, 15)
        y = sum(x4)
    end

    inputs = [:W => rand(3,4); :x => rand(4,5); :b => rand(3)]
    g1 = ExGraph(ex; inputs...)
    g2 = ExGraph(ex; ctx=Dict(:method => :track), inputs...)

    @test evaluate!(g1) == evaluate!(g2)
end


text:
module PhaseSpaceIO
using ArgCheck
using DataStructures

include("abstract.jl")
include("iohelpers.jl")
include("common.jl")
include("iaea/iaea.jl")
include("egs/egs.jl")
include("api.jl")
include("experimental.jl")
include("getters.jl")
include("testing.jl")
include("deprecate.jl")
include("download.jl")
include("conversion.jl")

include("staticarrays.jl")
include("transforms.jl")
include("mmap.jl")

end#module


text:
#=
estim.jl

    State space model optimization abstract types and general fallback routines

@author: Quint Wiersma <q.wiersma@vu.nl>

@date: 2022/02/15
=#

"""
    StateSpaceOptimizerState

Abstract type for state space model optimizer.
"""
abstract type StateSpaceOptimizerState end
abstract type EMOptimizerState <: StateSpaceOptimizerState end
abstract type MLOptimizerState <: StateSpaceOptimizerState end

"""
    Penalization

Abstract type for penalization of state space model hyper parameters.
"""
abstract type Penalization end

# Penalization structs
struct NoPen <: Penalization
end

mutable struct Lasso{Tγ, Tw} <: Penalization
	γ::Tγ		# penalization strength
	weights::Tw	# weights
end

mutable struct GroupLasso{Tγ, Tw, Tg} <: Penalization
	γ::Tγ		# penalization strength
	weights::Tw	# weights
	groups::Tg	# group structure
end

mutable struct SparseGroupLasso{Tγ, Tw1, Tw2, Tg} <: Penalization
	γ::Tγ			# penalization strength
	α::Tγ			# mixing parameter
	weights_l1::Tw1	# weights ℓ₁-norm
	weights_l2::Tw2	# weights ℓ₂-norm
	groups::Tg		# group structure
end

# Proximal Operators
"""
    prox!(x, λ, pen)

Compute proximal operatior for type `pen` at point `x` with scale `λ`, storing
the result in `x`.

#### Arguments
  - `x::AbstractVector` : input
  - `λ::Real`           : scaling parameter
  - `pen::Penalization` : penalization variables
"""
prox!(x::AbstractVector, λ::Real, pen::NoPen)= nothing
prox!(x::AbstractVector, λ::Real, pen::Lasso)= x.= soft_thresh.(x, λ .* pen.γ .* vec(pen.weights))
function prox!(x::AbstractVector, λ::Real, pen::GroupLasso)
    idx= 1
    for g in 1:length(pen.groups)
        rng= idx:idx+pen.groups[g]-1
        x_g= view(x,rng)
        block_soft_thresh!(x_g, λ * pen.γ * pen.weights[g])
        idx+= pen.groups[g]
    end

    return nothing
end
function prox!(x::AbstractVector, λ::Real, pen::SparseGroupLasso)
    idx= 1
    x.= soft_thresh.(x, λ .* pen.γ .* pen.α .* vec(pen.weights_l1))
    for g in 1:length(pen.groups)
        rng= idx:idx+pen.groups[g]-1
        x_g= view(x,rng)
        block_soft_thresh!(x_g, λ * pen.γ * (one(pen.α) - pen.α) * pen.weights_l2[g])
        idx+= pen.groups[g]
    end

    return nothing
end

# Transformations
"""
    logistic(x; offset=0.0, scale=1.0)

Evaluate the logistic function at point `x`, with optionally an `offset` and
`scale`, mapping `x` ``∈ [-∞, +∞]`` to [-`offset`, `scale`-`offset`].

#### Arguments
  - `x::Real`       : input
  - `offset::Real`  : offset
  - `scale::Real`   : scale

#### Returns
  - `y::Real`   : output
"""
logistic(x::Real; offset::Real=0.0, scale::Real=1.0)= scale * inv(one(x) + exp(-x)) - offset

"""
    logit(x; offset=0.0, scale=1.0)

Evaluate the logit function (inverse logistic) at point `x`, with optionally an
`offset` and `scale`, mapping `x` ``∈`` [-`offset`, `scale`-`offset`] to ``[-∞,
+∞]``.

#### Arguments
  - `x::Real`       : input
  - `offset::Real`  : offset
  - `scale::Real`   : scale

#### Returns
  - `y::Real`   : output
"""
logit(x::Real; offset::Real=0.0, scale::Real=1.0)= log(inv(scale) * (x + offset) * inv(one(x) - inv(scale) * (x + offset)))


text:
"""
Error handling module.
"""
module Error

end


text:
const N_HID = 1024
const SIGMA = 0.001

function save_model(m, nzs)
    save(MODEL_FILE, "m", m)
    save(NZS_FILE, "nzs", nzs)
end

function load_model()
   load(MODEL_FILE)["m"], load(NZS_FILE)["nzs"]
end

function fit_and_save()
    @time dat, _, nzs = read_aligned(labeled_only=true)
    n_feat, n_samples = size(dat)
    m = GRBM(n_feat, N_HID, sigma=SIGMA)
    for i=1:8
        println("meta-iteration #", i)
        @time fit(m, dat, n_iter=10, n_gibbs=2, lr=0.01)
    end
    save_model(m, nzs)
end

max_stars_repo_name: dfdx/masque

max_issues_repo_name: dfdx/masque

max_forks_repo_name: dfdx/masque


text:
module Utils
export format_string_nl

"""
format_string_nl(circuit_output::String)

Simple utility to format the OpenQASM output for user readability (i.e. adds newlines).
"""
function format_string_nl(circuit_output::String)
    return replace(circuit_output, ";"=>";\n")
end

end


text:
commands = readlines("day14/input.txt")

function mask_bits(mask, value)
    value_bits = bitstring(value)
    out_bitstring = []
    for i in 0:35
        if mask[end-i] == 'X'
            pushfirst!(out_bitstring, value_bits[end-i])
        else
            pushfirst!(out_bitstring, mask[end-i])
        end
    end
    return parse(Int, join(out_bitstring); base=2)
end

current_mask = ""
memory = Dict{Int, Int}()
for instruction in commands
    if contains(instruction, "[")
        address, value = match(r"mem\[(\d+)\] = (\d+)", instruction).captures
        global memory[parse(Int, address)] = mask_bits(current_mask, parse(Int, value))
    else
        global current_mask = match(r"mask = (\w+)", instruction).captures[1]
    end
end

println(sum(v for v in values(memory)))

# That was fun! Ending with a sub 1k place too!


text:
function inverse(side::HorizonSide)
    return HorizonSide(mod(Int(side) + 2, 4))
end

function f()
    steps = []
    while !isborder(robot, Nord)
        move!(robot, Nord)
        push!(steps, inverse(Nord))
    end
    while !isborder(robot, Ost)
        move!(robot, Ost)
        push!(steps, inverse(Ost))
    end

    # Тут решение.
    side = Ost
    isOk = false
    for i = 1:10
        move!(robot, Sud)
        side = inverse(side)
        for j = 1:11
            if !isborder(robot, side)
                move!(robot, side)
            else
                isOk = true
                break
            end
        end
        if isOk
            break
        end
    end
    while isborder(robot, side)
        putmarker!(robot)
        move!(robot, Sud)
    end
    putmarker!(robot)
    move!(robot, side)
    while isborder(robot, Nord)
        putmarker!(robot)
        move!(robot, side)
    end
    putmarker!(robot)
    move!(robot, Nord)
    side = inverse(side)
    while isborder(robot, side)
        putmarker!(robot)
        move!(robot, Nord)
    end
    putmarker!(robot)
    move!(robot, side)
    while isborder(robot, Sud)
        putmarker!(robot)
        move!(robot, side)
    end
    putmarker!(robot)

    while !isborder(robot, Nord)
        move!(robot, Nord)
    end
    while !isborder(robot, Ost)
        move!(robot, Ost)
    end
    while length(steps) > 0
        move!(robot, pop!(steps))
    end
end

f()

max_stars_repo_name: TheXlebushek/mirea-progs

max_issues_repo_name: TheXlebushek/mirea-progs

max_forks_repo_name: TheXlebushek/mirea-progs


text:
# Julia wrapper for header: /home/gkraemer/.julia/dev/LevelDB/deps/src/leveldb-1.20/include/leveldb/c.h
# Automatically generated using Clang.jl wrap_c

function leveldb_open(options, name, errptr)
    ccall((:leveldb_open, libleveldb), Ptr{leveldb_t}, (Ptr{leveldb_options_t}, Cstring, Ptr{Cstring}), options, name, errptr)
end

function leveldb_close(db)
    ccall((:leveldb_close, libleveldb), Cvoid, (Ptr{leveldb_t},), db)
end

function leveldb_put(db, options, key, keylen, val, vallen, errptr)
    ccall((:leveldb_put, libleveldb), Cvoid, (Ptr{leveldb_t}, Ptr{leveldb_writeoptions_t}, Cstring, Csize_t, Cstring, Csize_t, Ptr{Cstring}), db, options, key, keylen, val, vallen, errptr)
end

function leveldb_delete(db, options, key, keylen, errptr)
    ccall((:leveldb_delete, libleveldb), Cvoid, (Ptr{leveldb_t}, Ptr{leveldb_writeoptions_t}, Cstring, Csize_t, Ptr{Cstring}), db, options, key, keylen, errptr)
end

function leveldb_write(db, options, batch, errptr)
    ccall((:leveldb_write, libleveldb), Cvoid, (Ptr{leveldb_t}, Ptr{leveldb_writeoptions_t}, Ptr{leveldb_writebatch_t}, Ptr{Cstring}), db, options, batch, errptr)
end

function leveldb_get(db, options, key, keylen, vallen, errptr)
    ccall((:leveldb_get, libleveldb), Cstring, (Ptr{leveldb_t}, Ptr{leveldb_readoptions_t}, Cstring, Csize_t, Ptr{Csize_t}, Ptr{Cstring}), db, options, key, keylen, vallen, errptr)
end

function leveldb_create_iterator(db, options)
    ccall((:leveldb_create_iterator, libleveldb), Ptr{leveldb_iterator_t}, (Ptr{leveldb_t}, Ptr{leveldb_readoptions_t}), db, options)
end

function leveldb_create_snapshot(db)
    ccall((:leveldb_create_snapshot, libleveldb), Ptr{leveldb_snapshot_t}, (Ptr{leveldb_t},), db)
end

function leveldb_release_snapshot(db, snapshot)
    ccall((:leveldb_release_snapshot, libleveldb), Cvoid, (Ptr{leveldb_t}, Ptr{leveldb_snapshot_t}), db, snapshot)
end

function leveldb_property_value(db, propname)
    ccall((:leveldb_property_value, libleveldb), Cstring, (Ptr{leveldb_t}, Cstring), db, propname)
end

function leveldb_approximate_sizes(db, num_ranges, range_start_key, range_start_key_len, range_limit_key, range_limit_key_len, sizes)
    ccall((:leveldb_approximate_sizes, libleveldb), Cvoid, (Ptr{leveldb_t}, Cint, Ptr{Cstring}, Ptr{Csize_t}, Ptr{Cstring}, Ptr{Csize_t}, Ptr{UInt64}), db, num_ranges, range_start_key, range_start_key_len, range_limit_key, range_limit_key_len, sizes)
end

function leveldb_compact_range(db, start_key, start_key_len, limit_key, limit_key_len)
    ccall((:leveldb_compact_range, libleveldb), Cvoid, (Ptr{leveldb_t}, Cstring, Csize_t, Cstring, Csize_t), db, start_key, start_key_len, limit_key, limit_key_len)
end

function leveldb_destroy_db(options, name, errptr)
    ccall((:leveldb_destroy_db, libleveldb), Cvoid, (Ptr{leveldb_options_t}, Cstring, Ptr{Cstring}), options, name, errptr)
end

function leveldb_repair_db(options, name, errptr)
    ccall((:leveldb_repair_db, libleveldb), Cvoid, (Ptr{leveldb_options_t}, Cstring, Ptr{Cstring}), options, name, errptr)
end

function leveldb_iter_destroy(arg1)
    ccall((:leveldb_iter_destroy, libleveldb), Cvoid, (Ptr{leveldb_iterator_t},), arg1)
end

function leveldb_iter_valid(arg1)
    ccall((:leveldb_iter_valid, libleveldb), Cuchar, (Ptr{leveldb_iterator_t},), arg1)
end

function leveldb_iter_seek_to_first(arg1)
    ccall((:leveldb_iter_seek_to_first, libleveldb), Cvoid, (Ptr{leveldb_iterator_t},), arg1)
end

function leveldb_iter_seek_to_last(arg1)
    ccall((:leveldb_iter_seek_to_last, libleveldb), Cvoid, (Ptr{leveldb_iterator_t},), arg1)
end

function leveldb_iter_seek(arg1, k, klen)
    ccall((:leveldb_iter_seek, libleveldb), Cvoid, (Ptr{leveldb_iterator_t}, Cstring, Csize_t), arg1, k, klen)
end

function leveldb_iter_next(arg1)
    ccall((:leveldb_iter_next, libleveldb), Cvoid, (Ptr{leveldb_iterator_t},), arg1)
end

function leveldb_iter_prev(arg1)
    ccall((:leveldb_iter_prev, libleveldb), Cvoid, (Ptr{leveldb_iterator_t},), arg1)
end

function leveldb_iter_key(arg1, klen)
    ccall((:leveldb_iter_key, libleveldb), Cstring, (Ptr{leveldb_iterator_t}, Ptr{Csize_t}), arg1, klen)
end

function leveldb_iter_value(arg1, vlen)
    ccall((:leveldb_iter_value, libleveldb), Cstring, (Ptr{leveldb_iterator_t}, Ptr{Csize_t}), arg1, vlen)
end

function leveldb_iter_get_error(arg1, errptr)
    ccall((:leveldb_iter_get_error, libleveldb), Cvoid, (Ptr{leveldb_iterator_t}, Ptr{Cstring}), arg1, errptr)
end

function leveldb_writebatch_create()
    ccall((:leveldb_writebatch_create, libleveldb), Ptr{leveldb_writebatch_t}, ())
end

function leveldb_writebatch_destroy(arg1)
    ccall((:leveldb_writebatch_destroy, libleveldb), Cvoid, (Ptr{leveldb_writebatch_t},), arg1)
end

function leveldb_writebatch_clear(arg1)
    ccall((:leveldb_writebatch_clear, libleveldb), Cvoid, (Ptr{leveldb_writebatch_t},), arg1)
end

function leveldb_writebatch_put(arg1, key, klen, val, vlen)
    ccall((:leveldb_writebatch_put, libleveldb), Cvoid, (Ptr{leveldb_writebatch_t}, Cstring, Csize_t, Cstring, Csize_t), arg1, key, klen, val, vlen)
end

function leveldb_writebatch_delete(arg1, key, klen)
    ccall((:leveldb_writebatch_delete, libleveldb), Cvoid, (Ptr{leveldb_writebatch_t}, Cstring, Csize_t), arg1, key, klen)
end

function leveldb_writebatch_iterate(arg1, state, put, deleted)
    ccall((:leveldb_writebatch_iterate, libleveldb), Cvoid, (Ptr{leveldb_writebatch_t}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}), arg1, state, put, deleted)
end

function leveldb_options_create()
    ccall((:leveldb_options_create, libleveldb), Ptr{leveldb_options_t}, ())
end

function leveldb_options_destroy(arg1)
    ccall((:leveldb_options_destroy, libleveldb), Cvoid, (Ptr{leveldb_options_t},), arg1)
end

function leveldb_options_set_comparator(arg1, arg2)
    ccall((:leveldb_options_set_comparator, libleveldb), Cvoid, (Ptr{leveldb_options_t}, Ptr{leveldb_comparator_t}), arg1, arg2)
end

function leveldb_options_set_filter_policy(arg1, arg2)
    ccall((:leveldb_options_set_filter_policy, libleveldb), Cvoid, (Ptr{leveldb_options_t}, Ptr{leveldb_filterpolicy_t}), arg1, arg2)
end

function leveldb_options_set_create_if_missing(arg1, arg2)
    ccall((:leveldb_options_set_create_if_missing, libleveldb), Cvoid, (Ptr{leveldb_options_t}, Cuchar), arg1, arg2)
end

function leveldb_options_set_error_if_exists(arg1, arg2)
    ccall((:leveldb_options_set_error_if_exists, libleveldb), Cvoid, (Ptr{leveldb_options_t}, Cuchar), arg1, arg2)
end

function leveldb_options_set_paranoid_checks(arg1, arg2)
    ccall((:leveldb_options_set_paranoid_checks, libleveldb), Cvoid, (Ptr{leveldb_options_t}, Cuchar), arg1, arg2)
end

function leveldb_options_set_env(arg1, arg2)
    ccall((:leveldb_options_set_env, libleveldb), Cvoid, (Ptr{leveldb_options_t}, Ptr{leveldb_env_t}), arg1, arg2)
end

function leveldb_options_set_info_log(arg1, arg2)
    ccall((:leveldb_options_set_info_log, libleveldb), Cvoid, (Ptr{leveldb_options_t}, Ptr{leveldb_logger_t}), arg1, arg2)
end

function leveldb_options_set_write_buffer_size(arg1, arg2)
    ccall((:leveldb_options_set_write_buffer_size, libleveldb), Cvoid, (Ptr{leveldb_options_t}, Csize_t), arg1, arg2)
end

function leveldb_options_set_max_open_files(arg1, arg2)
    ccall((:leveldb_options_set_max_open_files, libleveldb), Cvoid, (Ptr{leveldb_options_t}, Cint), arg1, arg2)
end

function leveldb_options_set_cache(arg1, arg2)
    ccall((:leveldb_options_set_cache, libleveldb), Cvoid, (Ptr{leveldb_options_t}, Ptr{leveldb_cache_t}), arg1, arg2)
end

function leveldb_options_set_block_size(arg1, arg2)
    ccall((:leveldb_options_set_block_size, libleveldb), Cvoid, (Ptr{leveldb_options_t}, Csize_t), arg1, arg2)
end

function leveldb_options_set_block_restart_interval(arg1, arg2)
    ccall((:leveldb_options_set_block_restart_interval, libleveldb), Cvoid, (Ptr{leveldb_options_t}, Cint), arg1, arg2)
end

function leveldb_options_set_compression(arg1, arg2)
    ccall((:leveldb_options_set_compression, libleveldb), Cvoid, (Ptr{leveldb_options_t}, Cint), arg1, arg2)
end

function leveldb_comparator_create(state, destructor, compare, name)
    ccall((:leveldb_comparator_create, libleveldb), Ptr{leveldb_comparator_t}, (Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}), state, destructor, compare, name)
end

function leveldb_comparator_destroy(arg1)
    ccall((:leveldb_comparator_destroy, libleveldb), Cvoid, (Ptr{leveldb_comparator_t},), arg1)
end

function leveldb_filterpolicy_create(state, destructor, create_filter, key_may_match, name)
    ccall((:leveldb_filterpolicy_create, libleveldb), Ptr{leveldb_filterpolicy_t}, (Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}), state, destructor, create_filter, key_may_match, name)
end

function leveldb_filterpolicy_destroy(arg1)
    ccall((:leveldb_filterpolicy_destroy, libleveldb), Cvoid, (Ptr{leveldb_filterpolicy_t},), arg1)
end

function leveldb_filterpolicy_create_bloom(bits_per_key)
    ccall((:leveldb_filterpolicy_create_bloom, libleveldb), Ptr{leveldb_filterpolicy_t}, (Cint,), bits_per_key)
end

function leveldb_readoptions_create()
    ccall((:leveldb_readoptions_create, libleveldb), Ptr{leveldb_readoptions_t}, ())
end

function leveldb_readoptions_destroy(arg1)
    ccall((:leveldb_readoptions_destroy, libleveldb), Cvoid, (Ptr{leveldb_readoptions_t},), arg1)
end

function leveldb_readoptions_set_verify_checksums(arg1, arg2)
    ccall((:leveldb_readoptions_set_verify_checksums, libleveldb), Cvoid, (Ptr{leveldb_readoptions_t}, Cuchar), arg1, arg2)
end

function leveldb_readoptions_set_fill_cache(arg1, arg2)
    ccall((:leveldb_readoptions_set_fill_cache, libleveldb), Cvoid, (Ptr{leveldb_readoptions_t}, Cuchar), arg1, arg2)
end

function leveldb_readoptions_set_snapshot(arg1, arg2)
    ccall((:leveldb_readoptions_set_snapshot, libleveldb), Cvoid, (Ptr{leveldb_readoptions_t}, Ptr{leveldb_snapshot_t}), arg1, arg2)
end

function leveldb_writeoptions_create()
    ccall((:leveldb_writeoptions_create, libleveldb), Ptr{leveldb_writeoptions_t}, ())
end

function leveldb_writeoptions_destroy(arg1)
    ccall((:leveldb_writeoptions_destroy, libleveldb), Cvoid, (Ptr{leveldb_writeoptions_t},), arg1)
end

function leveldb_writeoptions_set_sync(arg1, arg2)
    ccall((:leveldb_writeoptions_set_sync, libleveldb), Cvoid, (Ptr{leveldb_writeoptions_t}, Cuchar), arg1, arg2)
end

function leveldb_cache_create_lru(capacity)
    ccall((:leveldb_cache_create_lru, libleveldb), Ptr{leveldb_cache_t}, (Csize_t,), capacity)
end

function leveldb_cache_destroy(cache)
    ccall((:leveldb_cache_destroy, libleveldb), Cvoid, (Ptr{leveldb_cache_t},), cache)
end

function leveldb_create_default_env()
    ccall((:leveldb_create_default_env, libleveldb), Ptr{leveldb_env_t}, ())
end

function leveldb_env_destroy(arg1)
    ccall((:leveldb_env_destroy, libleveldb), Cvoid, (Ptr{leveldb_env_t},), arg1)
end

function leveldb_free(ptr)
    ccall((:leveldb_free, libleveldb), Cvoid, (Ptr{Cvoid},), ptr)
end

function leveldb_major_version()
    ccall((:leveldb_major_version, libleveldb), Cint, ())
end

function leveldb_minor_version()
    ccall((:leveldb_minor_version, libleveldb), Cint, ())
end


text:
using QuantumOptics, CollectiveSpins
const cs = CollectiveSpins

# System parameters
const a = 0.54
const γ = 1.
const e_dipole = [0,0,1.]
const T = [0:0.05:5.;]

const system = SpinCollection(cs.geometry.cube(a), e_dipole; gamma=γ)
const N = length(system.spins)

# Initial state (Bloch state)
#const phi = Float64[(i-1)*pi for i=1:N]
#const phi = [0. for i=1:N]
const phi = [0., 0., 0., 0., 0.5*pi, 0.5*pi, 0.5*pi, 0.5*pi]
const theta = ones(Float64, N)*pi/2.

# Output
const targetdir = "."
const name = "rotsym2.dat"

# Time evolution

# Independent
state0 = cs.independent.blochstate(phi, theta)
tout, state_ind_t = cs.independent.timeevolution(T, system, state0)

# Meanfield
state0 = cs.meanfield.blochstate(phi, theta)
tout, state_mf_t = cs.meanfield.timeevolution(T, system, state0)

# Symmetric meanfield
state0 = cs.meanfield.blochstate(0., pi/2., 1)
Ωeff, Γeff = CollectiveSpins.effective_interaction_rotated.cube_orthogonal(a, pi/2.)
tout, state_mfsym_t = cs.meanfield.timeevolution_symmetric(T, state0, Ωeff, Γeff)

# #println("N: ", state_mf_t[end].N)
# println(cs.meanfield.sy(state_mf_t[1]))
# println(cs.meanfield.sy(state_mf_t[2]))
# println(cs.meanfield.sy(state_mf_t[3]))
# println(cs.meanfield.sy(state_mf_t[4]))
# println(cs.meanfield.sy(state_mf_t[end]))
# #println("N: ", state_mfsym_t[end].N)
# println(cs.meanfield.sy(state_mfsym_t[1]))
# println(cs.meanfield.sy(state_mfsym_t[2]))
# println(cs.meanfield.sy(state_mfsym_t[3]))
# println(cs.meanfield.sy(state_mfsym_t[4]))
# println(cs.meanfield.sy(state_mfsym_t[end]))
# @assert false

# Meanfield + Correlations
state0 = cs.mpc.blochstate(phi, theta)
tout, state_mpc_t = cs.mpc.timeevolution(T, system, state0)

# Quantum: master equation
sx_master = Float64[]
sy_master = Float64[]
sz_master = Float64[]

td_ind = Float64[]
td_mf  = Float64[]
td_mpc = Float64[]

const Ncenter = 5#int(N/2)+1

embed(op::Operator) = QuantumOptics.embed(cs.quantum.basis(system), Ncenter, op)

function fout(t, rho::Operator)
    i = something(findfirst(isequal(t), T), 0)
    rho_ind = cs.independent.densityoperator(state_ind_t[i])
    rho_mf  = cs.meanfield.densityoperator(state_mf_t[i])
    rho_mpc = cs.mpc.densityoperator(state_mpc_t[i])
    push!(td_ind, tracedistance(rho, rho_ind))
    push!(td_mf,  tracedistance(rho, rho_mf))
    push!(td_mpc, tracedistance(rho, rho_mpc))
    push!(sx_master, real(expect(embed(sigmax), rho)))
    push!(sy_master, real(expect(embed(sigmay), rho)))
    push!(sz_master, real(expect(embed(sigmaz), rho)))
end

Ψ₀ = cs.quantum.blochstate(phi,theta)
ρ₀ = Ψ₀⊗dagger(Ψ₀)
cs.quantum.timeevolution(T, system, ρ₀, fout=fout)

# Expectation values
mapexpect(op, states) = map(s->(op(s)[Ncenter]), states)
sx_ind = mapexpect(cs.independent.sx, state_ind_t)
sy_ind = mapexpect(cs.independent.sy, state_ind_t)
sz_ind = mapexpect(cs.independent.sz, state_ind_t)

sx_mf = mapexpect(cs.meanfield.sx, state_mf_t)
sy_mf = mapexpect(cs.meanfield.sy, state_mf_t)
sz_mf = mapexpect(cs.meanfield.sz, state_mf_t)

sx_mpc = mapexpect(cs.mpc.sx, state_mpc_t)
sy_mpc = mapexpect(cs.mpc.sy, state_mpc_t)
sz_mpc = mapexpect(cs.mpc.sz, state_mpc_t)

mapexpect(op, states) = map(s->(op(s)[1]), states)
sx_mfsym = mapexpect(cs.meanfield.sx, state_mfsym_t)
sy_mfsym = mapexpect(cs.meanfield.sy, state_mfsym_t)
sz_mfsym = mapexpect(cs.meanfield.sz, state_mfsym_t)

# Save data
f = open(joinpath(targetdir, name), "w")
write(f, "# Time sx_ind sy_ind sz_ind sx_mf sy_mf sz_mf sx_mfsym sy_mfsym sz_mfsym sx_mpc sy_mpc sz_mpc td_ind td_mf td_mpc\n")
for i=1:length(T)
    write(f, "$(T[i]);$(sx_ind[i]);$(sy_ind[i]);$(sz_ind[i]);$(sx_mf[i]);$(sy_mf[i]);$(sz_mf[i]);$(sx_mfsym[i]);$(sy_mfsym[i]);$(sz_mfsym[i]);$(sx_mpc[i]);$(sy_mpc[i]);$(sz_mpc[i]);$(sx_master[i]);$(sy_master[i]);$(sz_master[i]);$(td_ind[i]);$(td_mf[i]);$(td_mpc[i])\n")
end
close(f)


text:
#----------------------------------------------------------------------------------------------#
#                                       Package Defaults                                       #
#----------------------------------------------------------------------------------------------#

"""
`const DEF = Dict{Symbol,Any}(...)`\n
`EngThermBase` defaults\n
"""
const DEF = Dict{Symbol,Any}(
    # --- Bases
    :IB         => MA,      # Default Intensive Base
    :EB         => SY,      # Default Extensive Base
    :XB         => EX,      # Default Exactness Base
    # --- Print formatting
    :pprint     => true,    # Whether to pretty-print AMOUNTS
    :showPrec   => true,    # Whether to Base.show the Precision of AMOUNTS
    :showSigD   => 5,       # Significant digits for Base.show of AMOUNTS
)

export DEF


text:
# https://github.com/JuliaLang/Statistics.jl/pull/28
@static if VERSION < v"1.6.0-"
    Statistics.middle(x::Number, y::Number) = x/2 + y/2
end


text:
using MLBase
using Base.Test

# standardize

X = rand(5, 8)

(Y, t) = standardize(X; center=false, scale=false)
@test isa(t, Standardize)
@test isempty(t.mean)
@test isempty(t.scale)
@test isequal(X, Y)
@test_approx_eq transform(t, X[:,1]) Y[:,1]

(Y, t) = standardize(X; center=false, scale=true)
@test isa(t, Standardize)
@test isempty(t.mean)
@test length(t.scale) == 5
s = sqrt(sum(abs2(X), 2) ./ (8 - 1))
@test_approx_eq Y X ./ s
@test_approx_eq transform(t, X[:,1]) Y[:,1]

(Y, t) = standardize(X; center=true, scale=false)
@test isa(t, Standardize)
@test length(t.mean) == 5
@test isempty(t.scale)
@test_approx_eq Y X .- mean(X, 2)
@test_approx_eq transform(t, X[:,1]) Y[:,1]

(Y, t) = standardize(X; center=true, scale=true)
@test isa(t, Standardize)
@test length(t.mean) == 5
@test length(t.scale) == 5
@test_approx_eq Y (X .- mean(X, 2)) ./ std(X, 2)
@test_approx_eq transform(t, X[:,1]) Y[:,1]


text:
export edge_color, edge_chromatic_number

"""
`edge_color(G,k)` returns a proper `k`-edge coloring of `G` or
throws an error if one does not exist.
"""
function edge_color(G::SimpleGraph, k::Int)
    err_msg = "This graph is not $k-edge colorable"
    Delta = maximum(deg(G))
    if k<Delta
        error(err_msg)
    end

    M = max_matching(G)   # this isn't that expensive
    if NE(G) > length(M)*k
        error(err_msg)
    end

    VV = vlist(G)
    EE = elist(G)
    n = NV(G)
    m = NE(G)

    VT = vertex_type(G)
    ET = Tuple{VT,VT}

    result = Dict{ET,Int}()

    MOD = Model(with_optimizer(_SOLVER.Optimizer; _OPTS...))
    @variable(MOD, x[EE,1:k], Bin)

    # Every edge must have exactly one color
    for ed in EE
        @constraint(MOD, sum(x[ed,i] for i=1:k) == 1)
    end

    # Two edges incident with the same vertex must have different colors
    for i=1:m-1
        for j=i+1:m
            e1 = EE[i]
            e2 = EE[j]
            meet = intersect(Set(e1), Set(e2))
            if length(meet)>0
                for t=1:k
                    @constraint(MOD, x[e1,t]+x[e2,t] <= 1)
                end
            end
        end
    end

    optimize!(MOD)
    status = Int(termination_status(MOD))

    if status != 1
        error(err_msg)
    end

    X = value.(x)
    for ee in EE
        for t=1:k
            if X[ee,t] > 0
                result[ee] = t
            end
        end
    end
    return result
end

"""
`edge_chromatic_number(G)` returns the edge chromatic number
of the graph `G`.
"""
function edge_chromatic_number(G::SimpleGraph)::Int
    if cache_check(G,:edge_chromatic_number)
        return cache_recall(G,:edge_chromatic_number)
    end

    d = maximum(deg(G))
    try
        f = edge_color(G,d)
        cache_save(G, :edge_chromatic_number, d)
        return d
    catch
    end

    cache_save(G, :edge_chromatic_number, d+1)
    return d+1
end


text:
module TidalSedimentFluxes

using TidalFluxQuantities, TidalFluxCalibrations

export OBS3, AnalogLow, AnalogHigh, Turbidity, TSS

include("obs.jl")
include("tss.jl")

end # module


text:
@symbol_func function V_loop(cur_reactor::AbstractReactor)
  cur_V = R_P(cur_reactor)

  cur_V *= cur_reactor.I_P

  cur_V *= f_IN(cur_reactor)

  cur_V *= 1e6

  cur_V
end


text:
@testset "Ambiguity detection" begin
    @test isempty(Test.detect_ambiguities(StatsModels))
end


text:
# This file was generated, do not modify it. # hide
r = report(mtm)

res = r.plotting

md = res.parameter_values[:,1]
mcw = res.parameter_values[:,2]

figure(figsize=(8,6))
tricontourf(md, mcw, res.measurements)

xlabel("Maximum tree depth", fontsize=14)
ylabel("Minimum child weight", fontsize=14)
xticks(3:2:10, fontsize=12)
yticks(fontsize=12)

savefig(joinpath(@OUTPUT, "EX-crabs-xgb-heatmap.svg")) # hide


text:
@testset "1.1.3.6 (g x)^m (a+b x^n)^p (c+d x^n)^q (e+f x^n)^r" begin
    (A, B, a, b, c, d, e, m, n, p, q, x, ) = @variables A B a b c d e m n p q x

    #= ::Package:: =#

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

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

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

    #= ::Subsubsection::Closed:: =#
    #=q>0=#

    @test_int [(e*x)^m*(a + b*x^n)^3*(c + d*x^n)*(A + B*x^n), x, 12, (a^2*(3*A*b*c + a*B*c + a*A*d)*x^(1 + n)*(e*x)^m)/(1 + m + n) + (a*(3*A*b*(b*c + a*d) + a*B*(3*b*c + a*d))*x^(1 + 2*n)*(e*x)^m)/(1 + m + 2*n) + (b*(3*a*B*(b*c + a*d) + A*b*(b*c + 3*a*d))*x^(1 + 3*n)*(e*x)^m)/(1 + m + 3*n) + (b^2*(b*B*c + A*b*d + 3*a*B*d)*x^(1 + 4*n)*(e*x)^m)/(1 + m + 4*n) + (b^3*B*d*x^(1 + 5*n)*(e*x)^m)/(1 + m + 5*n) + (a^3*A*c*(e*x)^(1 + m))/(e*(1 + m))]
    @test_int [(e*x)^m*(a + b*x^n)^2*(c + d*x^n)*(A + B*x^n), x, 10, (a*(2*A*b*c + a*B*c + a*A*d)*x^(1 + n)*(e*x)^m)/(1 + m + n) + ((a*B*(2*b*c + a*d) + A*b*(b*c + 2*a*d))*x^(1 + 2*n)*(e*x)^m)/(1 + m + 2*n) + (b*(b*B*c + A*b*d + 2*a*B*d)*x^(1 + 3*n)*(e*x)^m)/(1 + m + 3*n) + (b^2*B*d*x^(1 + 4*n)*(e*x)^m)/(1 + m + 4*n) + (a^2*A*c*(e*x)^(1 + m))/(e*(1 + m))]
    @test_int [(e*x)^m*(a + b*x^n)^1*(c + d*x^n)*(A + B*x^n), x, 8, ((A*b*c + a*B*c + a*A*d)*x^(1 + n)*(e*x)^m)/(1 + m + n) + ((b*B*c + A*b*d + a*B*d)*x^(1 + 2*n)*(e*x)^m)/(1 + m + 2*n) + (b*B*d*x^(1 + 3*n)*(e*x)^m)/(1 + m + 3*n) + (a*A*c*(e*x)^(1 + m))/(e*(1 + m))]
    @test_int [(e*x)^m*(a + b*x^n)^0*(c + d*x^n)*(A + B*x^n), x, 6, ((B*c + A*d)*x^(1 + n)*(e*x)^m)/(1 + m + n) + (B*d*x^(1 + 2*n)*(e*x)^m)/(1 + m + 2*n) + (A*c*(e*x)^(1 + m))/(e*(1 + m))]
    @test_int [(e*x)^m/(a + b*x^n)^1*(c + d*x^n)*(A + B*x^n), x, 5, (B*d*x^(1 + n)*(e*x)^m)/(b*(1 + m + n)) + ((b*B*c + A*b*d - a*B*d)*(e*x)^(1 + m))/(b^2*e*(1 + m)) + ((A*b - a*B)*(b*c - a*d)*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((b*x^n)/a)))/(a*b^2*e*(1 + m))]
    @test_int [(e*x)^m/(a + b*x^n)^2*(c + d*x^n)*(A + B*x^n), x, 3, -((d*(A*b*(1 + m) - a*B*(1 + m + n))*(e*x)^(1 + m))/(a*b^2*e*(1 + m)*n)) + ((A*b - a*B)*(e*x)^(1 + m)*(c + d*x^n))/(a*b*e*n*(a + b*x^n)) + ((b*c*(a*B*(1 + m) - A*b*(1 + m - n)) + a*d*(A*b*(1 + m) - a*B*(1 + m + n)))*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((b*x^n)/a)))/(a^2*b^2*e*(1 + m)*n)]
    @test_int [(e*x)^m/(a + b*x^n)^3*(c + d*x^n)*(A + B*x^n), x, 3, -(((A*b*(b*c*(1 + m - 2*n) - a*d*(1 + m - n)) - a*B*(b*c*(1 + m) - a*d*(1 + m + n)))*(e*x)^(1 + m))/(2*a^2*b^2*e*n^2*(a + b*x^n))) + ((A*b - a*B)*(e*x)^(1 + m)*(c + d*x^n))/(2*a*b*e*n*(a + b*x^n)^2) - ((b*c*(a*B*(1 + m) - A*b*(1 + m - 2*n))*(1 + m - n) + a*d*(1 + m)*(A*b*(1 + m - n) - a*B*(1 + m + n)))*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((b*x^n)/a)))/(2*a^3*b^2*e*(1 + m)*n^2)]

    @test_int [(e*x)^m*(a + b*x^n)^3*(c + d*x^n)^2*(A + B*x^n), x, 14, (a^2*c*(3*A*b*c + a*B*c + 2*a*A*d)*x^(1 + n)*(e*x)^m)/(1 + m + n) + (a*(a*B*c*(3*b*c + 2*a*d) + A*(3*b^2*c^2 + 6*a*b*c*d + a^2*d^2))*x^(1 + 2*n)*(e*x)^m)/(1 + m + 2*n) + ((a*B*(3*b^2*c^2 + 6*a*b*c*d + a^2*d^2) + A*b*(b^2*c^2 + 6*a*b*c*d + 3*a^2*d^2))*x^(1 + 3*n)*(e*x)^m)/(1 + m + 3*n) + (b*(3*a^2*B*d^2 + 3*a*b*d*(2*B*c + A*d) + b^2*c*(B*c + 2*A*d))*x^(1 + 4*n)*(e*x)^m)/(1 + m + 4*n) + (b^2*d*(2*b*B*c + A*b*d + 3*a*B*d)*x^(1 + 5*n)*(e*x)^m)/(1 + m + 5*n) + (b^3*B*d^2*x^(1 + 6*n)*(e*x)^m)/(1 + m + 6*n) + (a^3*A*c^2*(e*x)^(1 + m))/(e*(1 + m))]
    @test_int [(e*x)^m*(a + b*x^n)^2*(c + d*x^n)^2*(A + B*x^n), x, 12, (a*c*(a*B*c + 2*A*(b*c + a*d))*x^(1 + n)*(e*x)^m)/(1 + m + n) + ((2*a*B*c*(b*c + a*d) + A*(b^2*c^2 + 4*a*b*c*d + a^2*d^2))*x^(1 + 2*n)*(e*x)^m)/(1 + m + 2*n) + ((a^2*B*d^2 + 2*a*b*d*(2*B*c + A*d) + b^2*c*(B*c + 2*A*d))*x^(1 + 3*n)*(e*x)^m)/(1 + m + 3*n) + (b*d*(2*b*B*c + A*b*d + 2*a*B*d)*x^(1 + 4*n)*(e*x)^m)/(1 + m + 4*n) + (b^2*B*d^2*x^(1 + 5*n)*(e*x)^m)/(1 + m + 5*n) + (a^2*A*c^2*(e*x)^(1 + m))/(e*(1 + m))]
    @test_int [(e*x)^m*(a + b*x^n)^1*(c + d*x^n)^2*(A + B*x^n), x, 10, (c*(A*b*c + a*B*c + 2*a*A*d)*x^(1 + n)*(e*x)^m)/(1 + m + n) + ((a*d*(2*B*c + A*d) + b*c*(B*c + 2*A*d))*x^(1 + 2*n)*(e*x)^m)/(1 + m + 2*n) + (d*(2*b*B*c + A*b*d + a*B*d)*x^(1 + 3*n)*(e*x)^m)/(1 + m + 3*n) + (b*B*d^2*x^(1 + 4*n)*(e*x)^m)/(1 + m + 4*n) + (a*A*c^2*(e*x)^(1 + m))/(e*(1 + m))]
    @test_int [(e*x)^m*(a + b*x^n)^0*(c + d*x^n)^2*(A + B*x^n), x, 8, (c*(B*c + 2*A*d)*x^(1 + n)*(e*x)^m)/(1 + m + n) + (d*(2*B*c + A*d)*x^(1 + 2*n)*(e*x)^m)/(1 + m + 2*n) + (B*d^2*x^(1 + 3*n)*(e*x)^m)/(1 + m + 3*n) + (A*c^2*(e*x)^(1 + m))/(e*(1 + m))]
    @test_int [(e*x)^m/(a + b*x^n)^1*(c + d*x^n)^2*(A + B*x^n), x, 7, (d*(2*b*B*c + A*b*d - a*B*d)*x^(1 + n)*(e*x)^m)/(b^2*(1 + m + n)) + (B*d^2*x^(1 + 2*n)*(e*x)^m)/(b*(1 + m + 2*n)) + ((a^2*B*d^2 - a*b*d*(2*B*c + A*d) + b^2*c*(B*c + 2*A*d))*(e*x)^(1 + m))/(b^3*e*(1 + m)) + ((A*b - a*B)*(b*c - a*d)^2*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((b*x^n)/a)))/(a*b^3*e*(1 + m))]
    @test_int [(e*x)^m/(a + b*x^n)^2*(c + d*x^n)^2*(A + B*x^n), x, 6, -((d^2*(A*b*(1 + m + n) - a*B*(1 + m + 2*n))*x^(1 + n)*(e*x)^m)/(a*b^2*n*(1 + m + n))) - (d*(A*b*(2*b*c*(1 + m) - a*d*(1 + m + n)) - a*B*(2*b*c*(1 + m + n) - a*d*(1 + m + 2*n)))*(e*x)^(1 + m))/(a*b^3*e*(1 + m)*n) + ((A*b - a*B)*(e*x)^(1 + m)*(c + d*x^n)^2)/(a*b*e*n*(a + b*x^n)) - ((b*c - a*d)*(A*b*(b*c*(1 + m - n) - a*d*(1 + m + n)) - a*B*(b*c*(1 + m) - a*d*(1 + m + 2*n)))*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((b*x^n)/a)))/(a^2*b^3*e*(1 + m)*n)]
    @test_int [(e*x)^m/(a + b*x^n)^3*(c + d*x^n)^2*(A + B*x^n), x, 4, (d*(b*c*(1 + m) - a*d*(1 + m + n))*(A*b*(1 + m) - a*B*(1 + m + 2*n))*(e*x)^(1 + m))/(2*a^2*b^3*e*(1 + m)*n^2) + ((A*b - a*B)*(e*x)^(1 + m)*(c + d*x^n)^2)/(2*a*b*e*n*(a + b*x^n)^2) + ((b*c - a*d)*(e*x)^(1 + m)*(c*(a*B*(1 + m) - A*b*(1 + m - 2*n)) - d*(A*b*(1 + m) - a*B*(1 + m + 2*n))*x^n))/(2*a^2*b^2*e*n^2*(a + b*x^n)) + ((b*c*(a*B*(1 + m) - A*b*(1 + m - 2*n))*(a*d*(1 + m) - b*c*(1 + m - n)) - a*d*(b*c*(1 + m) - a*d*(1 + m + n))*(A*b*(1 + m) - a*B*(1 + m + 2*n)))*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((b*x^n)/a)))/(2*a^3*b^3*e*(1 + m)*n^2)]

    @test_int [(e*x)^m*(a + b*x^n)^3*(c + d*x^n)^3*(A + B*x^n), x, 16, (a^2*c^2*(a*B*c + 3*A*(b*c + a*d))*x^(1 + n)*(e*x)^m)/(1 + m + n) + (3*a*c*(a*B*c*(b*c + a*d) + A*(b^2*c^2 + 3*a*b*c*d + a^2*d^2))*x^(1 + 2*n)*(e*x)^m)/(1 + m + 2*n) + ((3*a*B*c*(b^2*c^2 + 3*a*b*c*d + a^2*d^2) + A*(b^3*c^3 + 9*a*b^2*c^2*d + 9*a^2*b*c*d^2 + a^3*d^3))*x^(1 + 3*n)*(e*x)^m)/(1 + m + 3*n) + ((a^3*B*d^3 + 9*a*b^2*c*d*(B*c + A*d) + 3*a^2*b*d^2*(3*B*c + A*d) + b^3*c^2*(B*c + 3*A*d))*x^(1 + 4*n)*(e*x)^m)/(1 + m + 4*n) + (3*b*d*(a^2*B*d^2 + b^2*c*(B*c + A*d) + a*b*d*(3*B*c + A*d))*x^(1 + 5*n)*(e*x)^m)/(1 + m + 5*n) + (b^2*d^2*(3*b*B*c + A*b*d + 3*a*B*d)*x^(1 + 6*n)*(e*x)^m)/(1 + m + 6*n) + (b^3*B*d^3*x^(1 + 7*n)*(e*x)^m)/(1 + m + 7*n) + (a^3*A*c^3*(e*x)^(1 + m))/(e*(1 + m))]
    @test_int [(e*x)^m*(a + b*x^n)^2*(c + d*x^n)^3*(A + B*x^n), x, 14, (a*c^2*(2*A*b*c + a*B*c + 3*a*A*d)*x^(1 + n)*(e*x)^m)/(1 + m + n) + (c*(a*B*c*(2*b*c + 3*a*d) + A*(b^2*c^2 + 6*a*b*c*d + 3*a^2*d^2))*x^(1 + 2*n)*(e*x)^m)/(1 + m + 2*n) + ((6*a*b*c*d*(B*c + A*d) + a^2*d^2*(3*B*c + A*d) + b^2*c^2*(B*c + 3*A*d))*x^(1 + 3*n)*(e*x)^m)/(1 + m + 3*n) + (d*(a^2*B*d^2 + 3*b^2*c*(B*c + A*d) + 2*a*b*d*(3*B*c + A*d))*x^(1 + 4*n)*(e*x)^m)/(1 + m + 4*n) + (b*d^2*(3*b*B*c + A*b*d + 2*a*B*d)*x^(1 + 5*n)*(e*x)^m)/(1 + m + 5*n) + (b^2*B*d^3*x^(1 + 6*n)*(e*x)^m)/(1 + m + 6*n) + (a^2*A*c^3*(e*x)^(1 + m))/(e*(1 + m))]
    @test_int [(e*x)^m*(a + b*x^n)^1*(c + d*x^n)^3*(A + B*x^n), x, 12, (c^2*(A*b*c + a*B*c + 3*a*A*d)*x^(1 + n)*(e*x)^m)/(1 + m + n) + (c*(3*a*d*(B*c + A*d) + b*c*(B*c + 3*A*d))*x^(1 + 2*n)*(e*x)^m)/(1 + m + 2*n) + (d*(3*b*c*(B*c + A*d) + a*d*(3*B*c + A*d))*x^(1 + 3*n)*(e*x)^m)/(1 + m + 3*n) + (d^2*(3*b*B*c + A*b*d + a*B*d)*x^(1 + 4*n)*(e*x)^m)/(1 + m + 4*n) + (b*B*d^3*x^(1 + 5*n)*(e*x)^m)/(1 + m + 5*n) + (a*A*c^3*(e*x)^(1 + m))/(e*(1 + m))]
    @test_int [(e*x)^m*(a + b*x^n)^0*(c + d*x^n)^3*(A + B*x^n), x, 10, (c^2*(B*c + 3*A*d)*x^(1 + n)*(e*x)^m)/(1 + m + n) + (3*c*d*(B*c + A*d)*x^(1 + 2*n)*(e*x)^m)/(1 + m + 2*n) + (d^2*(3*B*c + A*d)*x^(1 + 3*n)*(e*x)^m)/(1 + m + 3*n) + (B*d^3*x^(1 + 4*n)*(e*x)^m)/(1 + m + 4*n) + (A*c^3*(e*x)^(1 + m))/(e*(1 + m))]
    @test_int [(e*x)^m/(a + b*x^n)^1*(c + d*x^n)^3*(A + B*x^n), x, 9, (d*(a^2*B*d^2 + 3*b^2*c*(B*c + A*d) - a*b*d*(3*B*c + A*d))*x^(1 + n)*(e*x)^m)/(b^3*(1 + m + n)) + (d^2*(3*b*B*c + A*b*d - a*B*d)*x^(1 + 2*n)*(e*x)^m)/(b^2*(1 + m + 2*n)) + (B*d^3*x^(1 + 3*n)*(e*x)^m)/(b*(1 + m + 3*n)) - ((a^3*B*d^3 + 3*a*b^2*c*d*(B*c + A*d) - a^2*b*d^2*(3*B*c + A*d) - b^3*c^2*(B*c + 3*A*d))*(e*x)^(1 + m))/(b^4*e*(1 + m)) + ((A*b - a*B)*(b*c - a*d)^3*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((b*x^n)/a)))/(a*b^4*e*(1 + m))]
    @test_int [(e*x)^m/(a + b*x^n)^2*(c + d*x^n)^3*(A + B*x^n), x, 8, -((d^2*(A*b*(3*b*c*(1 + m + n) - a*d*(1 + m + 2*n)) - a*B*(3*b*c*(1 + m + 2*n) - a*d*(1 + m + 3*n)))*x^(1 + n)*(e*x)^m)/(a*b^3*n*(1 + m + n))) - (d^3*(A*b*(1 + m + 2*n) - a*B*(1 + m + 3*n))*x^(1 + 2*n)*(e*x)^m)/(a*b^2*n*(1 + m + 2*n)) - (d*(A*b*(3*b^2*c^2*(1 + m) - 3*a*b*c*d*(1 + m + n) + a^2*d^2*(1 + m + 2*n)) - a*B*(3*b^2*c^2*(1 + m + n) - 3*a*b*c*d*(1 + m + 2*n) + a^2*d^2*(1 + m + 3*n)))*(e*x)^(1 + m))/(a*b^4*e*(1 + m)*n) + ((A*b - a*B)*(e*x)^(1 + m)*(c + d*x^n)^3)/(a*b*e*n*(a + b*x^n)) - ((b*c - a*d)^2*(A*b*(b*c*(1 + m - n) - a*d*(1 + m + 2*n)) - a*B*(b*c*(1 + m) - a*d*(1 + m + 3*n)))*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((b*x^n)/a)))/(a^2*b^4*e*(1 + m)*n)]
    #= [(e*x)^m/(a + b*x^n)^3*(c + d*x^n)^3*(A + B*x^n), x, 7, (B*d^3*x^(1 + n)*(e*x)^m)/(b^3*(1 + m + n)) + (d^2*(3*b*B*c + A*b*d - 3*a*B*d)*(e*x)^(1 + m))/(b^4*e*(1 + m)) + (3*d*(b*c - a*d)*(b*B*c + A*b*d - 2*a*B*d)*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((b*x^n)/a)))/(a*b^4*e*(1 + m)) + ((b*c - a*d)^2*(b*B*c + 3*A*b*d - 4*a*B*d)*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(2, (1 + m)/n, (1 + m + n)/n, -((b*x^n)/a)))/(a^2*b^4*e*(1 + m)) + ((A*b - a*B)*(b*c - a*d)^3*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(3, (1 + m)/n, (1 + m + n)/n, -((b*x^n)/a)))/(a^3*b^4*e*(1 + m))]=#

    #= ::Subsubsection::Closed:: =#
    #=q<0=#

    @test_int [(e*x)^m*(a + b*x^n)^4*(A + B*x^n)/(c + d*x^n), x, 11, (b*(4*a^3*B*d^3 - b^3*c^2*(B*c - A*d) + 4*a*b^2*c*d*(B*c - A*d) - 6*a^2*b*d^2*(B*c - A*d))*x^(1 + n)*(e*x)^m)/(d^4*(1 + m + n)) + (b^2*(6*a^2*B*d^2 + b^2*c*(B*c - A*d) - 4*a*b*d*(B*c - A*d))*x^(1 + 2*n)*(e*x)^m)/(d^3*(1 + m + 2*n)) - (b^3*(b*B*c - A*b*d - 4*a*B*d)*x^(1 + 3*n)*(e*x)^m)/(d^2*(1 + m + 3*n)) + (b^4*B*x^(1 + 4*n)*(e*x)^m)/(d*(1 + m + 4*n)) + ((a^4*B*d^4 + b^4*c^3*(B*c - A*d) - 4*a*b^3*c^2*d*(B*c - A*d) + 6*a^2*b^2*c*d^2*(B*c - A*d) - 4*a^3*b*d^3*(B*c - A*d))*(e*x)^(1 + m))/(d^5*e*(1 + m)) - ((b*c - a*d)^4*(B*c - A*d)*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((d*x^n)/c)))/(c*d^5*e*(1 + m))]
    @test_int [(e*x)^m*(a + b*x^n)^3*(A + B*x^n)/(c + d*x^n), x, 9, (b*(3*a^2*B*d^2 + b^2*c*(B*c - A*d) - 3*a*b*d*(B*c - A*d))*x^(1 + n)*(e*x)^m)/(d^3*(1 + m + n)) - (b^2*(b*B*c - A*b*d - 3*a*B*d)*x^(1 + 2*n)*(e*x)^m)/(d^2*(1 + m + 2*n)) + (b^3*B*x^(1 + 3*n)*(e*x)^m)/(d*(1 + m + 3*n)) + ((a^3*B*d^3 - b^3*c^2*(B*c - A*d) + 3*a*b^2*c*d*(B*c - A*d) - 3*a^2*b*d^2*(B*c - A*d))*(e*x)^(1 + m))/(d^4*e*(1 + m)) + ((b*c - a*d)^3*(B*c - A*d)*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((d*x^n)/c)))/(c*d^4*e*(1 + m))]
    @test_int [(e*x)^m*(a + b*x^n)^2*(A + B*x^n)/(c + d*x^n), x, 7, -((b*(b*B*c - A*b*d - 2*a*B*d)*x^(1 + n)*(e*x)^m)/(d^2*(1 + m + n))) + (b^2*B*x^(1 + 2*n)*(e*x)^m)/(d*(1 + m + 2*n)) + ((a^2*B*d^2 + b^2*c*(B*c - A*d) - 2*a*b*d*(B*c - A*d))*(e*x)^(1 + m))/(d^3*e*(1 + m)) - ((b*c - a*d)^2*(B*c - A*d)*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((d*x^n)/c)))/(c*d^3*e*(1 + m))]
    @test_int [(e*x)^m*(a + b*x^n)^1*(A + B*x^n)/(c + d*x^n), x, 5, (b*B*x^(1 + n)*(e*x)^m)/(d*(1 + m + n)) - ((b*B*c - A*b*d - a*B*d)*(e*x)^(1 + m))/(d^2*e*(1 + m)) + ((b*c - a*d)*(B*c - A*d)*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((d*x^n)/c)))/(c*d^2*e*(1 + m))]
    @test_int [(e*x)^m*(a + b*x^n)^0*(A + B*x^n)/(c + d*x^n), x, 2, (B*(e*x)^(1 + m))/(d*e*(1 + m)) - ((B*c - A*d)*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((d*x^n)/c)))/(c*d*e*(1 + m))]
    @test_int [(e*x)^m/(a + b*x^n)^1*(A + B*x^n)/(c + d*x^n), x, 4, ((A*b - a*B)*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((b*x^n)/a)))/(a*(b*c - a*d)*e*(1 + m)) + ((B*c - A*d)*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((d*x^n)/c)))/(c*(b*c - a*d)*e*(1 + m))]
    @test_int [(e*x)^m/(a + b*x^n)^2*(A + B*x^n)/(c + d*x^n), x, 5, ((A*b - a*B)*(e*x)^(1 + m))/(a*(b*c - a*d)*e*n*(a + b*x^n)) + ((A*b*(a*d*(1 + m - 2*n) - b*c*(1 + m - n)) + a*B*(b*c*(1 + m) - a*d*(1 + m - n)))*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((b*x^n)/a)))/(a^2*(b*c - a*d)^2*e*(1 + m)*n) - (d*(B*c - A*d)*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((d*x^n)/c)))/(c*(b*c - a*d)^2*e*(1 + m))]
    @test_int [(e*x)^m/(a + b*x^n)^3*(A + B*x^n)/(c + d*x^n), x, 6, ((A*b - a*B)*(e*x)^(1 + m))/(2*a*(b*c - a*d)*e*n*(a + b*x^n)^2) + ((A*b*(a*d*(1 + m - 4*n) - b*c*(1 + m - 2*n)) + a*B*(b*c*(1 + m) - a*d*(1 + m - 2*n)))*(e*x)^(1 + m))/(2*a^2*(b*c - a*d)^2*e*n^2*(a + b*x^n)) + ((a*B*(2*a*b*c*d*(1 + m)*(1 + m - 2*n) - b^2*c^2*(1 + m)*(1 + m - n) - a^2*d^2*(1 + m^2 + m*(2 - 3*n) - 3*n + 2*n^2)) + A*b*(b^2*c^2*(1 + m^2 + m*(2 - 3*n) - 3*n + 2*n^2) - 2*a*b*c*d*(1 + m^2 + m*(2 - 4*n) - 4*n + 3*n^2) + a^2*d^2*(1 + m^2 + m*(2 - 5*n) - 5*n + 6*n^2)))*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((b*x^n)/a)))/(2*a^3*(b*c - a*d)^3*e*(1 + m)*n^2) + (d^2*(B*c - A*d)*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((d*x^n)/c)))/(c*(b*c - a*d)^3*e*(1 + m))]

    @test_int [(e*x)^m*(a + b*x^n)^3*(A + B*x^n)/(c + d*x^n)^2, x, 8, -((b^2*(3*a*d*(A*d*(1 + m + n) - B*c*(1 + m + 2*n)) - b*c*(A*d*(1 + m + 2*n) - B*c*(1 + m + 3*n)))*x^(1 + n)*(e*x)^m)/(c*d^3*n*(1 + m + n))) - (b^3*(A*d*(1 + m + 2*n) - B*c*(1 + m + 3*n))*x^(1 + 2*n)*(e*x)^m)/(c*d^2*n*(1 + m + 2*n)) - (b*(3*a^2*d^2*(A*d*(1 + m) - B*c*(1 + m + n)) - 3*a*b*c*d*(A*d*(1 + m + n) - B*c*(1 + m + 2*n)) + b^2*c^2*(A*d*(1 + m + 2*n) - B*c*(1 + m + 3*n)))*(e*x)^(1 + m))/(c*d^4*e*(1 + m)*n) - ((B*c - A*d)*(e*x)^(1 + m)*(a + b*x^n)^3)/(c*d*e*n*(c + d*x^n)) + ((b*c - a*d)^2*(a*d*(B*c*(1 + m) - A*d*(1 + m - n)) + b*c*(A*d*(1 + m + 2*n) - B*c*(1 + m + 3*n)))*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((d*x^n)/c)))/(c^2*d^4*e*(1 + m)*n)]
    @test_int [(e*x)^m*(a + b*x^n)^2*(A + B*x^n)/(c + d*x^n)^2, x, 6, -((b^2*(A*d*(1 + m + n) - B*c*(1 + m + 2*n))*x^(1 + n)*(e*x)^m)/(c*d^2*n*(1 + m + n))) - (b*(2*a*d*(A*d*(1 + m) - B*c*(1 + m + n)) - b*c*(A*d*(1 + m + n) - B*c*(1 + m + 2*n)))*(e*x)^(1 + m))/(c*d^3*e*(1 + m)*n) - ((B*c - A*d)*(e*x)^(1 + m)*(a + b*x^n)^2)/(c*d*e*n*(c + d*x^n)) - ((b*c - a*d)*(a*d*(B*c*(1 + m) - A*d*(1 + m - n)) + b*c*(A*d*(1 + m + n) - B*c*(1 + m + 2*n)))*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((d*x^n)/c)))/(c^2*d^3*e*(1 + m)*n)]
    @test_int [(e*x)^m*(a + b*x^n)^1*(A + B*x^n)/(c + d*x^n)^2, x, 3, -((B*(a*d*(1 + m) - b*c*(1 + m + n))*(e*x)^(1 + m))/(c*d^2*e*(1 + m)*n)) - ((b*c - a*d)*(e*x)^(1 + m)*(A + B*x^n))/(c*d*e*n*(c + d*x^n)) + ((A*d*(b*c*(1 + m) - a*d*(1 + m - n)) + B*c*(a*d*(1 + m) - b*c*(1 + m + n)))*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((d*x^n)/c)))/(c^2*d^2*e*(1 + m)*n)]
    @test_int [(e*x)^m*(a + b*x^n)^0*(A + B*x^n)/(c + d*x^n)^2, x, 2, -(((B*c - A*d)*(e*x)^(1 + m))/(c*d*e*n*(c + d*x^n))) + ((B*c*(1 + m) - A*d*(1 + m - n))*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((d*x^n)/c)))/(c^2*d*e*(1 + m)*n)]
    @test_int [(e*x)^m/(a + b*x^n)^1*(A + B*x^n)/(c + d*x^n)^2, x, 5, ((B*c - A*d)*(e*x)^(1 + m))/(c*(b*c - a*d)*e*n*(c + d*x^n)) + (b*(A*b - a*B)*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((b*x^n)/a)))/(a*(b*c - a*d)^2*e*(1 + m)) + ((b*c*(A*d*(1 + m - 2*n) - B*c*(1 + m - n)) + a*d*(B*c*(1 + m) - A*d*(1 + m - n)))*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((d*x^n)/c)))/(c^2*(b*c - a*d)^2*e*(1 + m)*n)]
    @test_int [(e*x)^m/(a + b*x^n)^2*(A + B*x^n)/(c + d*x^n)^2, x, 6, (d*(A*b*c - 2*a*B*c + a*A*d)*(e*x)^(1 + m))/(a*c*(b*c - a*d)^2*e*n*(c + d*x^n)) + ((A*b - a*B)*(e*x)^(1 + m))/(a*(b*c - a*d)*e*n*(a + b*x^n)*(c + d*x^n)) + (b*(a*B*(b*c*(1 + m) - a*d*(1 + m - 2*n)) + A*b*(a*d*(1 + m - 3*n) - b*c*(1 + m - n)))*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((b*x^n)/a)))/(a^2*(b*c - a*d)^3*e*(1 + m)*n) - (d*(b*c*(A*d*(1 + m - 3*n) - B*c*(1 + m - 2*n)) + a*d*(B*c*(1 + m) - A*d*(1 + m - n)))*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((d*x^n)/c)))/(c^2*(b*c - a*d)^3*e*(1 + m)*n)]
    @test_int [(e*x)^m/(a + b*x^n)^3*(A + B*x^n)/(c + d*x^n)^2, x, 7, (d*(a*B*c*(b*c*(1 + m) - a*d*(1 + m - 6*n)) + A*(a*b*c*d*(1 + m - 6*n) - b^2*c^2*(1 + m - 2*n) - 2*a^2*d^2*n))*(e*x)^(1 + m))/(2*a^2*c*(b*c - a*d)^3*e*n^2*(c + d*x^n)) + ((A*b - a*B)*(e*x)^(1 + m))/(2*a*(b*c - a*d)*e*n*(a + b*x^n)^2*(c + d*x^n)) + ((a*B*(b*c*(1 + m) - a*d*(1 + m - 3*n)) + A*b*(a*d*(1 + m - 5*n) - b*c*(1 + m - 2*n)))*(e*x)^(1 + m))/(2*a^2*(b*c - a*d)^2*e*n^2*(a + b*x^n)*(c + d*x^n)) + (b*(a*B*(2*a*b*c*d*(1 + m)*(1 + m - 3*n) - b^2*c^2*(1 + m)*(1 + m - n) - a^2*d^2*(1 + m^2 + m*(2 - 5*n) - 5*n + 6*n^2)) + A*b*(b^2*c^2*(1 + m^2 + m*(2 - 3*n) - 3*n + 2*n^2) - 2*a*b*c*d*(1 + m^2 + m*(2 - 5*n) - 5*n + 4*n^2) + a^2*d^2*(1 + m^2 + m*(2 - 7*n) - 7*n + 12*n^2)))*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((b*x^n)/a)))/(2*a^3*(b*c - a*d)^4*e*(1 + m)*n^2) + (d^2*(b*c*(A*d*(1 + m - 4*n) - B*c*(1 + m - 3*n)) + a*d*(B*c*(1 + m) - A*d*(1 + m - n)))*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((d*x^n)/c)))/(c^2*(b*c - a*d)^4*e*(1 + m)*n)]

    #= [(e*x)^m*(a + b*x^n)^3*(A + B*x^n)/(c + d*x^n)^3, x, 7, (b^3*B*x^(1 + n)*(e*x)^m)/(d^3*(1 + m + n)) - (b^2*(3*b*B*c - A*b*d - 3*a*B*d)*(e*x)^(1 + m))/(d^4*e*(1 + m)) + (3*b*(b*c - a*d)*(2*b*B*c - A*b*d - a*B*d)*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((d*x^n)/c)))/(c*d^4*e*(1 + m)) - ((b*c - a*d)^2*(4*b*B*c - 3*A*b*d - a*B*d)*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(2, (1 + m)/n, (1 + m + n)/n, -((d*x^n)/c)))/(c^2*d^4*e*(1 + m)) + ((b*c - a*d)^3*(B*c - A*d)*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(3, (1 + m)/n, (1 + m + n)/n, -((d*x^n)/c)))/(c^3*d^4*e*(1 + m))] =#
    @test_int [(e*x)^m*(a + b*x^n)^2*(A + B*x^n)/(c + d*x^n)^3, x, 4, (b*(a*d*(1 + m) - b*c*(1 + m + n))*(A*d*(1 + m) - B*c*(1 + m + 2*n))*(e*x)^(1 + m))/(2*c^2*d^3*e*(1 + m)*n^2) - ((B*c - A*d)*(e*x)^(1 + m)*(a + b*x^n)^2)/(2*c*d*e*n*(c + d*x^n)^2) - ((b*c - a*d)*(e*x)^(1 + m)*(a*(B*c*(1 + m) - A*d*(1 + m - 2*n)) - b*(A*d*(1 + m) - B*c*(1 + m + 2*n))*x^n))/(2*c^2*d^2*e*n^2*(c + d*x^n)) + ((a*d*(B*c*(1 + m) - A*d*(1 + m - 2*n))*(b*c*(1 + m) - a*d*(1 + m - n)) - b*c*(a*d*(1 + m) - b*c*(1 + m + n))*(A*d*(1 + m) - B*c*(1 + m + 2*n)))*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((d*x^n)/c)))/(2*c^3*d^3*e*(1 + m)*n^2)]
    @test_int [(e*x)^m*(a + b*x^n)^1*(A + B*x^n)/(c + d*x^n)^3, x, 3, -(((b*c - a*d)*(e*x)^(1 + m)*(A + B*x^n))/(2*c*d*e*n*(c + d*x^n)^2)) - ((a*d*(A*d*(1 + m - 2*n) - B*c*(1 + m - n)) - b*c*(A*d*(1 + m) - B*c*(1 + m + n)))*(e*x)^(1 + m))/(2*c^2*d^2*e*n^2*(c + d*x^n)) - ((A*d*(b*c*(1 + m) - a*d*(1 + m - 2*n))*(1 + m - n) + B*c*(1 + m)*(a*d*(1 + m - n) - b*c*(1 + m + n)))*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((d*x^n)/c)))/(2*c^3*d^2*e*(1 + m)*n^2)]
    @test_int [(e*x)^m*(a + b*x^n)^0*(A + B*x^n)/(c + d*x^n)^3, x, 2, -(((B*c - A*d)*(e*x)^(1 + m))/(2*c*d*e*n*(c + d*x^n)^2)) + ((B*c*(1 + m) - A*d*(1 + m - 2*n))*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(2, (1 + m)/n, (1 + m + n)/n, -((d*x^n)/c)))/(2*c^3*d*e*(1 + m)*n)]
    @test_int [(e*x)^m/(a + b*x^n)^1*(A + B*x^n)/(c + d*x^n)^3, x, 6, ((B*c - A*d)*(e*x)^(1 + m))/(2*c*(b*c - a*d)*e*n*(c + d*x^n)^2) + ((b*c*(A*d*(1 + m - 4*n) - B*c*(1 + m - 2*n)) + a*d*(B*c*(1 + m) - A*d*(1 + m - 2*n)))*(e*x)^(1 + m))/(2*c^2*(b*c - a*d)^2*e*n^2*(c + d*x^n)) + (b^2*(A*b - a*B)*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((b*x^n)/a)))/(a*(b*c - a*d)^3*e*(1 + m)) - ((b^2*c^2*(A*d*(1 + m - 3*n) - B*c*(1 + m - n))*(1 + m - 2*n) - a^2*d^2*(B*c*(1 + m) - A*d*(1 + m - 2*n))*(1 + m - n) + 2*a*b*c*d*(B*c*(1 + m)*(1 + m - 2*n) - A*d*(1 + m^2 + m*(2 - 4*n) - 4*n + 3*n^2)))*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((d*x^n)/c)))/(2*c^3*(b*c - a*d)^3*e*(1 + m)*n^2)]
    @test_int [(e*x)^m/(a + b*x^n)^2*(A + B*x^n)/(c + d*x^n)^3, x, 7, (d*(2*A*b*c - 3*a*B*c + a*A*d)*(e*x)^(1 + m))/(2*a*c*(b*c - a*d)^2*e*n*(c + d*x^n)^2) + ((A*b - a*B)*(e*x)^(1 + m))/(a*(b*c - a*d)*e*n*(a + b*x^n)*(c + d*x^n)^2) - (d*(a^2*d*(B*c*(1 + m) - A*d*(1 + m - 2*n)) - a*b*c*(B*c - A*d)*(1 + m - 6*n) - 2*A*b^2*c^2*n)*(e*x)^(1 + m))/(2*a*c^2*(b*c - a*d)^3*e*n^2*(c + d*x^n)) + (b^2*(a*B*(b*c*(1 + m) - a*d*(1 + m - 3*n)) + A*b*(a*d*(1 + m - 4*n) - b*c*(1 + m - n)))*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((b*x^n)/a)))/(a^2*(b*c - a*d)^4*e*(1 + m)*n) + (d*(b^2*c^2*(A*d*(1 + m - 4*n) - B*c*(1 + m - 2*n))*(1 + m - 3*n) - a^2*d^2*(B*c*(1 + m) - A*d*(1 + m - 2*n))*(1 + m - n) + 2*a*b*c*d*(B*c*(1 + m)*(1 + m - 3*n) - A*d*(1 + m^2 + m*(2 - 5*n) - 5*n + 4*n^2)))*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((d*x^n)/c)))/(2*c^3*(b*c - a*d)^4*e*(1 + m)*n^2)]
    #= [(e*x)^m/(a + b*x^n)^3*(A + B*x^n)/(c + d*x^n)^3, x, 8, -((3*b^2*d*(b*B*c - 2*A*b*d + a*B*d)*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((b*x^n)/a)))/(a*(b*c - a*d)^5*e*(1 + m))) + (3*b*d^2*(b*B*c - 2*A*b*d + a*B*d)*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(1, (1 + m)/n, (1 + m + n)/n, -((d*x^n)/c)))/(c*(b*c - a*d)^5*e*(1 + m)) + (b^2*(b*B*c - 3*A*b*d + 2*a*B*d)*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(2, (1 + m)/n, (1 + m + n)/n, -((b*x^n)/a)))/(a^2*(b*c - a*d)^4*e*(1 + m)) + (d^2*(2*b*B*c - 3*A*b*d + a*B*d)*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(2, (1 + m)/n, (1 + m + n)/n, -((d*x^n)/c)))/(c^2*(b*c - a*d)^4*e*(1 + m)) + (b^2*(A*b - a*B)*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(3, (1 + m)/n, (1 + m + n)/n, -((b*x^n)/a)))/(a^3*(b*c - a*d)^3*e*(1 + m)) + (d^2*(B*c - A*d)*(e*x)^(1 + m)*HypergeometricFunctions._₂F₁(3, (1 + m)/n, (1 + m + n)/n, -((d*x^n)/c)))/(c^3*(b*c - a*d)^3*e*(1 + m))] =#

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

    @test_int [(e*x)^m*(a + b*x^n)^p*(c + d*x^n)^q*(A + B*x^n), x, 7, (A*(e*x)^(1 + m)*(a + b*x^n)^p*(c + d*x^n)^q*AppellF1((1 + m)/n, -p, -q, (1 + m + n)/n, -((b*x^n)/a), -((d*x^n)/c)))/((1 + (b*x^n)/a)^p*(1 + (d*x^n)/c)^q*(e*(1 + m))) + (B*x^(1 + n)*(e*x)^m*(a + b*x^n)^p*(c + d*x^n)^q*AppellF1((1 + m + n)/n, -p, -q, (1 + m + 2*n)/n, -((b*x^n)/a), -((d*x^n)/c)))/((1 + (b*x^n)/a)^p*(1 + (d*x^n)/c)^q*(1 + m + n))]

    #= [(e*x)^m*(a + b*x^n)^p*(c + d*x^n)^3*(A + B*x^n), x, 11, (A*c^3*(e*x)^(1 + m)*(a + b*x^n)^p*HypergeometricFunctions._₂F₁((1 + m)/n, -p, (1 + m + n)/n, -((b*x^n)/a)))/((1 + (b*x^n)/a)^p*(e*(1 + m))) + (c^2*(B*c + 3*A*d)*x^(1 + n)*(e*x)^m*(a + b*x^n)^p*HypergeometricFunctions._₂F₁((1 + m + n)/n, -p, (1 + m + 2*n)/n, -((b*x^n)/a)))/((1 + (b*x^n)/a)^p*(1 + m + n)) + (3*c*d*(B*c + A*d)*x^(1 + 2*n)*(e*x)^m*(a + b*x^n)^p*HypergeometricFunctions._₂F₁((1 + m + 2*n)/n, -p, (1 + m + 3*n)/n, -((b*x^n)/a)))/((1 + (b*x^n)/a)^p*(1 + m + 2*n)) + (d^2*(3*B*c + A*d)*x^(1 + 3*n)*(e*x)^m*(a + b*x^n)^p*HypergeometricFunctions._₂F₁((1 + m + 3*n)/n, -p, (1 + m + 4*n)/n, -((b*x^n)/a)))/((1 + (b*x^n)/a)^p*(1 + m + 3*n)) + (B*d^3*x^(1 + 4*n)*(e*x)^m*(a + b*x^n)^p*HypergeometricFunctions._₂F₁((1 + m + 4*n)/n, -p, (1 + m + 5*n)/n, -((b*x^n)/a)))/((1 + (b*x^n)/a)^p*(1 + m + 4*n))] =#
    #= [(e*x)^m*(a + b*x^n)^p*(c + d*x^n)^2*(A + B*x^n), x, 9, (A*c^2*(e*x)^(1 + m)*(a + b*x^n)^p*HypergeometricFunctions._₂F₁((1 + m)/n, -p, (1 + m + n)/n, -((b*x^n)/a)))/((1 + (b*x^n)/a)^p*(e*(1 + m))) + (c*(B*c + 2*A*d)*x^(1 + n)*(e*x)^m*(a + b*x^n)^p*HypergeometricFunctions._₂F₁((1 + m + n)/n, -p, (1 + m + 2*n)/n, -((b*x^n)/a)))/((1 + (b*x^n)/a)^p*(1 + m + n)) + (d*(2*B*c + A*d)*x^(1 + 2*n)*(e*x)^m*(a + b*x^n)^p*HypergeometricFunctions._₂F₁((1 + m + 2*n)/n, -p, (1 + m + 3*n)/n, -((b*x^n)/a)))/((1 + (b*x^n)/a)^p*(1 + m + 2*n)) + (B*d^2*x^(1 + 3*n)*(e*x)^m*(a + b*x^n)^p*HypergeometricFunctions._₂F₁((1 + m + 3*n)/n, -p, (1 + m + 4*n)/n, -((b*x^n)/a)))/((1 + (b*x^n)/a)^p*(1 + m + 3*n))] =#
    @test_int [(e*x)^m*(a + b*x^n)^p*(c + d*x^n)*(A + B*x^n), x, 4, -(((a*B*d*(1 + m + n) - b*(A*d*n + B*c*(1 + m + n*(2 + p))))*(e*x)^(1 + m)*(a + b*x^n)^(1 + p))/(b^2*e*(1 + m + n + n*p)*(1 + m + n*(2 + p)))) + (d*(e*x)^(1 + m)*(a + b*x^n)^(1 + p)*(A + B*x^n))/(b*e*(1 + m + n*(2 + p))) - ((A*b*(1 + m + n + n*p)*(a*d*(1 + m) - b*c*(1 + m + n*(2 + p))) - a*(1 + m)*(a*B*d*(1 + m + n) - b*(A*d*n + B*c*(1 + m + n*(2 + p)))))*(e*x)^(1 + m)*(a + b*x^n)^p*HypergeometricFunctions._₂F₁((1 + m)/n, -p, (1 + m + n)/n, -((b*x^n)/a)))/((1 + (b*x^n)/a)^p*(b^2*e*(1 + m)*(1 + m + n + n*p)*(1 + m + n*(2 + p))))]
    @test_int [(e*x)^m*(a + b*x^n)^p*(A + B*x^n)/(c + d*x^n), x, 6, -(((B*c - A*d)*(e*x)^(1 + m)*(a + b*x^n)^p*AppellF1((1 + m)/n, -p, 1, (1 + m + n)/n, -((b*x^n)/a), -((d*x^n)/c)))/((1 + (b*x^n)/a)^p*(c*d*e*(1 + m)))) + (B*(e*x)^(1 + m)*(a + b*x^n)^p*HypergeometricFunctions._₂F₁((1 + m)/n, -p, (1 + m + n)/n, -((b*x^n)/a)))/((1 + (b*x^n)/a)^p*(d*e*(1 + m)))]
    @test_int [(e*x)^m*(a + b*x^n)^p*(A + B*x^n)/(c + d*x^n)^2, x, 7, ((B*c - A*d)*(e*x)^(1 + m)*(a + b*x^n)^(1 + p))/(c*(b*c - a*d)*e*n*(c + d*x^n)) - ((a*d*(B*c*(1 + m) - A*d*(1 + m - n)) + b*c*(A*d*(1 + m - n*(1 - p)) - B*c*(1 + m + n*p)))*(e*x)^(1 + m)*(a + b*x^n)^p*AppellF1((1 + m)/n, -p, 1, (1 + m + n)/n, -((b*x^n)/a), -((d*x^n)/c)))/((1 + (b*x^n)/a)^p*(c^2*d*(b*c - a*d)*e*(1 + m)*n)) - (b*(B*c - A*d)*(1 + m + n*p)*(e*x)^(1 + m)*(a + b*x^n)^p*HypergeometricFunctions._₂F₁((1 + m)/n, -p, (1 + m + n)/n, -((b*x^n)/a)))/((1 + (b*x^n)/a)^p*(c*d*(b*c - a*d)*e*(1 + m)*n))]
    #= [(e*x)^m*(a + b*x^n)^p*(A + B*x^n)/(c + d*x^n)^3, x, 4, (B*(e*x)^(1 + m)*(a + b*x^n)^p*(1 + (d*x^n)/c)^2*AppellF1((1 + m)/n, -p, 2, (1 + m + n)/n, -((b*x^n)/a), -((d*x^n)/c)))/((1 + (b*x^n)/a)^p*(d*e*(1 + m)*(c + d*x^n)^2)) - ((B*c - A*d)*(e*x)^(1 + m)*(a + b*x^n)^p*(1 + (d*x^n)/c)^3*AppellF1((1 + m)/n, -p, 3, (1 + m + n)/n, -((b*x^n)/a), -((d*x^n)/c)))/((1 + (b*x^n)/a)^p*(d*e*(1 + m)*(c + d*x^n)^3))] =#

    #= ::Title:: =#
    #=Integrands*of*the*form*(g*x)^m*(a+b*x^(n/2)^p*(c+d*x^(n/2))^p*(e+f*x^n)^r*with*b*c+a*d=0=#

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

    @test_int [((-a + b*x^(n/2))^(-1 + 1/n)*(a + b*x^(n/2))^(-1 + 1/n)*(c + d*x^n))/x^2, x, 4, ((c/a^2 + d/b^2)*(-a + b*x^(n/2))^(1/n)*(a + b*x^(n/2))^(1/n))/x - (d*(-a + b*x^(n/2))^(1/n)*(a + b*x^(n/2))^(1/n)*HypergeometricFunctions._₂F₁(-(1/n), -(1/n), -((1 - n)/n), (b^2*x^n)/a^2))/((1 - (b^2*x^n)/a^2)^n^(-1)*(b^2*x))]
    @test_int [((-a + b*x^(n/2))^((1 - n)/n)*(a + b*x^(n/2))^((1 - n)/n)*(c + d*x^n))/x^2, x, 4, ((c/a^2 + d/b^2)*(-a + b*x^(n/2))^(1/n)*(a + b*x^(n/2))^(1/n))/x - (d*(-a + b*x^(n/2))^(1/n)*(a + b*x^(n/2))^(1/n)*HypergeometricFunctions._₂F₁(-(1/n), -(1/n), -((1 - n)/n), (b^2*x^n)/a^2))/((1 - (b^2*x^n)/a^2)^n^(-1)*(b^2*x)), -(((c/a^2 + d/b^2)*(-a + b*x^(n/2))^(-1 + 1/n)*(a + b*x^(n/2))^(-1 + 1/n)*(a^2 - b^2*x^n))/x) + (a^2*d*(-a + b*x^(n/2))^(-1 + 1/n)*(a + b*x^(n/2))^(-1 + 1/n)*HypergeometricFunctions._₂F₁(-(1/n), -(1/n), -((1 - n)/n), (b^2*x^n)/a^2))/((1 - (b^2*x^n)/a^2)^((1 - n)/n)*(b^2*x))]
    end

max_stars_repo_path: test/1 Algebraic functions/1.1 Binomial products/1.1.3 General/1.1.3.6 (g x)^m (a+b x^n)^p (c+d x^n)^q (e+f x^n)^r.jl


text:
"""
    CartesianAxes

Alias for LinearIndices where indices are subtypes of `AbstractAxis`.

## Examples
```jldoctest
julia> using AxisIndices

julia> cartaxes = CartesianAxes((Axis(2.0:5.0), Axis(1:4)));

julia> cartinds = CartesianIndices((1:4, 1:4));

julia> cartaxes[2, 2]
CartesianIndex(2, 2)

julia> cartinds[2, 2]
CartesianIndex(2, 2)
```
"""
const CartesianAxes{N,R<:Tuple{Vararg{<:AbstractAxis,N}}} = CartesianIndices{N,R}

function CartesianAxes(axs::Tuple{Vararg{Any,N}}) where {N}
    return CartesianIndices(map(axis -> compose_axis(axis, _inds(axis)), axs))
end

# compose_axis(axis, checks) doesn't assume one based indexing in case a range is
# passed without it, but we want to assume that's what we have here unless an axplicit
# instance of AbstractAxis is passed
_inds(axis::Integer) = One():axis
_inds(axis::AbstractVector) = One():static_length(axis)
_inds(axis::AbstractAxis) = parent(axis)

Base.axes(A::CartesianAxes) = getfield(A, :indices)

@propagate_inbounds function Base.getindex(A::CartesianIndices{N,R}, args::Vararg{Int, N}) where {N,R<:Tuple{Vararg{<:AbstractAxis,N}}}
    return ArrayInterface.getindex(A, args...)
end

@propagate_inbounds function Base.getindex(A::CartesianIndices{N,R}, args...) where {N,R<:Tuple{Vararg{<:AbstractAxis,N}}}
    return ArrayInterface.getindex(A, args...)
end
Base.getindex(A::CartesianIndices{N,R}, ::Ellipsis) where {N,R<:Tuple{Vararg{<:AbstractAxis,N}}} = A

"""
    LinearAxes

Alias for LinearIndices where indices are subtypes of `AbstractAxis`.

## Examples
```jldoctest
julia> using AxisIndices

julia> linaxes = LinearAxes((Axis(2.0:5.0), Axis(1:4)));

julia> lininds = LinearIndices((1:4, 1:4));

julia> linaxes[2, 2]
6

julia> lininds[2, 2]
6
```
"""
const LinearAxes{N,R<:Tuple{Vararg{<:AbstractAxis,N}}} = LinearIndices{N,R}

function LinearAxes(axs::Tuple{Vararg{<:Any,N}}) where {N}
    return LinearIndices(map(axis -> compose_axis(axis, _inds(axis)), axs))
end

Base.axes(A::LinearAxes) = getfield(A, :indices)

@boundscheck function Base.getindex(iter::LinearAxes, i::Int)
    @boundscheck if !in(i, eachindex(iter))
        throw(BoundsError(iter, i))
    end
    return i
end

@propagate_inbounds function Base.getindex(A::LinearAxes, inds...)
    return ArrayInterface.getindex(A, inds...)
    #return Base._getindex(IndexStyle(A), A, to_indices(A, Tuple(inds))...)
end

@propagate_inbounds function Base.getindex(A::LinearAxes, i::AbstractRange{I}) where {I<:Integer}
    return getindex(eachindex(A), i)
end

Base.getindex(A::LinearAxes, ::Ellipsis) = A

Base.eachindex(A::LinearAxes) = SimpleAxis(StaticInt(1):static_length(A))


text:
# Check arguments for power calculation
function check_args_power{T <: TrialTest}(
    test::T;
    n::Union{Real, Void} = nothing,
    std::Union{Real, Tuple{Real, Real}, Void} = nothing,
    alpha::Real = 0.05,
    side::String = "two",
)

    if isa(n, Real)

        if !(2.0 <= n < Inf)

            error("sample size must be in [2.0, Inf)")

        end # end if

    else

        error("sample size must be specified")

    end # end if

    if isa(test, Union{OneSampleProp, OneSamplePropInferior, OneSamplePropSuperior,
      OneSamplePropEqual, TwoSampleProp, TwoSamplePropInferior,
      TwoSamplePropSuperior, TwoSamplePropEqual, McNemarProp})

        if !isa(std, Void)

            warn("standard deviation is not used in the calculations")

        end # end if

    elseif isa(std, Real)

        if !(0.0 < std < Inf)

            error("standard deviation must be in (0.0, Inf)")

        end # end if

    elseif isa(std, Tuple{Real, Real})

        if !((min(std...) > 0.0) & (max(std...) < Inf))

            error("standard deviaitons must both be in (0.0, Inf)")

        end # end if

    else

        error("standard deviaiton must be specified")

    end # end if

    # The alpha should between 0 and 1
    if !(0.0 < alpha < 1.0)

        error("type I error rate must be in (0.0, 1.0)")

    end # end if

    # The test should always be two-sided or one-sided
    if !in(side, ("two", "one"))

        error("side must be in 'two' or 'one'")

    end # end if

end # end function

# Check arguments for sample size calculations
function check_args_sample_size{T <: TrialTest}(
    test::T;
    power::Union{Real, Void} = nothing,
    std::Union{Real, Tuple{Real, Real}, Void} = nothing,
    alpha::Real = 0.05,
    side::String = "two",
)

    if isa(power, Real)

        # The power should between 0 and 1
        if !(0.0 < power < 1.0)

            error("power must be in (0.0, 1.0)")

        end # end if

    else

        error("power must be specified")

    end # end if

    if isa(test, Union{OneSampleProp, OneSamplePropInferior, OneSamplePropSuperior,
      OneSamplePropEqual, TwoSampleProp, TwoSamplePropInferior,
      TwoSamplePropSuperior, TwoSamplePropEqual, McNemarProp})

        if !isa(std, Void)

            warn("standard deviation is not used in the calculations")

        end # end if

    elseif isa(std, Real)

        if !(0.0 < std < Inf)

            error("standard deviation must be in (0.0, Inf)")

        end # end if

    elseif isa(std, Tuple{Real, Real})

        if !((min(std...) > 0.0) & (max(std...) < Inf))

            error("standard deviaitons must both be in (0.0, Inf)")

        end # end if

    else

        error("standard deviaiton must be specified")

    end # end if

    # The alpha should between 0 and 1
    if !(0.0 < alpha < 1.0)

        error("type I error rate must be in (0.0, 1.0)")

    end # end if

    # The test should always be two-sided or one-sided
    if !in(side, ("two", "one"))

        error("side must be in 'two' or 'one'")

    end # end if

end # end function


text:
"""
```
normals{VT,FD,FT,FO}(vertices::Vector{Point{3, VT}},
                     faces::Vector{Face{FD,FT,FO}},
                     NT = Normal{3, VT})
```

Compute all vertex normals.
"""
function normals(
        vertices::AbstractVector{Point{3, VT}},
        faces::AbstractVector{F},
        NT = Normal{3, VT}
    ) where {VT, F <: Face}
    normals_result = zeros(Point{3, VT}, length(vertices)) # initilize with same type as verts but with 0
    for face in faces
        v = vertices[face]
        # we can get away with two edges since faces are planar.
        a = v[2] - v[1]
        b = v[3] - v[1]
        n = cross(a, b)
        for i =1:length(F)
            fi = face[i]
            normals_result[fi] = normals_result[fi] + n
        end
    end
    normals_result .= NT.(normalize.(normals_result))
    normals_result
end

"""
Slice an AbstractMesh at the specified Z axis value.
Returns a Vector of LineSegments generated from the faces at the specified
heights. Note: This will not slice in-plane faces.
"""
function slice(mesh::AbstractMesh{Point{3,VT}, Face{3, FT}}, height::Number) where {VT<:AbstractFloat,FT<:Integer}

    height_ct = length(height)
    # intialize the LineSegment array
    slice = Simplex{2,Point{2,VT}}[]

    for face in mesh.faces
        v1,v2,v3 = mesh.vertices[face]
        zmax = max(v1[3], v2[3], v3[3])
        zmin = min(v1[3], v2[3], v3[3])
        if height > zmax
            continue
        elseif zmin <= height
            if v1[3] < height && v2[3] >= height && v3[3] >= height
                p1 = v1
                p2 = v3
                p3 = v2
            elseif v1[3] > height && v2[3] < height && v3[3] < height
                p1 = v1
                p2 = v2
                p3 = v3
            elseif v2[3] < height && v1[3] >= height && v3[3] >= height
                p1 = v2
                p2 = v1
                p3 = v3
            elseif v2[3] > height && v1[3] < height && v3[3] < height
                p1 = v2
                p2 = v3
                p3 = v1
            elseif v3[3] < height && v2[3] >= height && v1[3] >= height
                p1 = v3
                p2 = v2
                p3 = v1
            elseif v3[3] > height && v2[3] < height && v1[3] < height
                p1 = v3
                p2 = v1
                p3 = v2
            else
                continue
            end

            start = Point{2,VT}(p1[1] + (p2[1] - p1[1]) * (height - p1[3]) / (p2[3] - p1[3]),
                                p1[2] + (p2[2] - p1[2]) * (height - p1[3]) / (p2[3] - p1[3]))
            finish = Point{2,VT}(p1[1] + (p3[1] - p1[1]) * (height - p1[3]) / (p3[3] - p1[3]),
                                 p1[2] + (p3[2] - p1[2]) * (height - p1[3]) / (p3[3] - p1[3]))

            push!(slice, Simplex{2,Point{2, VT}}(start, finish))
        end
    end

    return slice
end

# TODO this should be checkbounds(Bool, ...)
"""
```
checkbounds{VT,FT,FD,FO}(m::AbstractMesh{VT,Face{FD,FT,FO}})
```

Check the `Face` indices to ensure they are in the bounds of the vertex
array of the `AbstractMesh`.
"""
function Base.checkbounds(m::AbstractMesh{VT, Face{FD, FT}}) where {VT, FD, FT}
    isempty(faces(m)) && return true # nothing to worry about I guess
    flat_inds = reinterpret(FT, faces(m))
    checkbounds(Bool, vertices(m), flat_inds)
end