text:
using BSON: @save, @load
using PyPlot
using LaTeXStrings
using Optim
using QuadGK

@load "./examples/PhaseTransition/NoiselessMeasurement.bson" E2 E3 E4

g(τ) = quadgk(u->(u-τ)^2*sqrt(2/π)*exp(-u^2/2), τ, Inf, rtol=1e-3)[1]
function δ(n, s)
    ρ = s/n
    f(τ) = ρ*(1+τ^2) + (1 - ρ)*g(τ)
    res = optimize(f, 0.0, 1000.0)
    return (minimum(res) - 2/sqrt(n*s))*n
end
# δ(n, s) = s*log(n/s);
Δ(k, n, s) = min(max(50, k^2*δ(n, s)), 200);
s = 5;
ns = collect(50:15:200)
ticks = [50, 100, 150, 200]
c = 0.5

fig, axes = subplots(nrows=1, ncols=3)
fig.subplots_adjust(bottom=0.1, top=0.9, left=0.1, right=0.85, wspace=0.27, hspace=0.02)

tol = 0.001;

subplot(1,3,1)
P2 = (E2 .< tol); S2 = sum(P2, dims=3)[:,:,1] ./ 50
im = imshow(S2, cmap="Blues", extent=[50,200,50,200], vmin=0, vmax=1)
k = 2; ms = map(n->Δ(k,n,s), ns); plot(ns, ms, color="red")
nl = 50 + mapreduce(x->x<0,+,ns - c*ms)*15
plot(repeat([nl], 11), ns, color="yellow", linestyle="dashed")
xticks(ticks, fontsize=6)
yticks(ticks, fontsize=6)
xlabel("n")
ylabel("m")
title("k=2")

subplot(1,3,2)
P3 = (E3 .< tol); S3 = sum(P3, dims=3)[:,:,1] ./ 50
im = imshow(S3, cmap="Blues", extent=[50,200,50,200], vmin=0, vmax=1)
k = 3; ms = map(n->Δ(k,n,s), ns); plot(ns, ms, color="red")
nl = 50 + mapreduce(x->x<0,+,ns - c*ms)*15
plot(repeat([nl], 11), ns, color="yellow", linestyle="dashed")
xticks(ticks, fontsize=6)
yticks(ticks, fontsize=6)
xlabel("n")
# ylabel("m")
title("k=3")

subplot(1,3,3)
P4 = (E4 .< tol); S4 = sum(P4, dims=3)[:,:,1] ./ 50
k = 4; ms = map(n->Δ(k,n,s), ns)
im = imshow(S4, cmap="Blues", extent=[50,200,50,200], vmin=0, vmax=1)
plot(ns, ms, color="red")
nl = 50 + mapreduce(x->x<0,+,ns - c*ms)*15
plot(repeat([nl], 11), ns, color="yellow", linestyle="dashed")
xticks(ticks, fontsize=6)
yticks(ticks, fontsize=6)
xlabel("n")
# ylabel("m")
title("k=4")

cb_ax = fig.add_axes([0.9, 0.36, 0.02, 0.28])
fig.colorbar(im, cax=cb_ax)


text:
using
  Documenter,
  OceanTurb

# Set up a timer to print a space ' ' every 240 seconds. This is to avoid Travis CI
# timing out when building demanding Literate.jl examples.
Timer(t -> println(" "), 0, interval=240)

makedocs(
     modules = [OceanTurb],
       clean = true,
     doctest = false,
   checkdocs = :all,
      format = Documenter.HTML(prettyurls = get(ENV, "CI", nothing) == "true",
                               mathengine = Documenter.MathJax2()),
     authors = "Gregory L. Wagner",
    sitename = "OceanTurb.jl",

       pages = Any[
                "Home" => "index.md",
                "Turbulence, fluxes, and physics" =>  "basics.md",
                "Numerical methods" => "numerics.md",
                "Turbulence models" => Any[
                  "models/kpp.md",
                  "models/modular_kpp.md",
                  "models/tke_mass_flux.md",
                  "models/pacanowskiphilander.md"],
                "DocStrings" => Any[
                      "man/types.md",
                      "man/functions.md"]
                      ]
)

deploydocs(        repo = "github.com/glwagner/OceanTurb.jl.git",
              versions = ["stable" => "v^", "v#.#", "dev" => "dev"],
          push_preview = true
          )

ext: jl


text:
function string(x::SimpleQuaternion)
    a,b,c,d = get_parts(x)
    (a,b,c,d,xx) = promote(a,b,c,d,0)
    result = string(a)

    if b<0
        result *= " - "
    else
        result *= " + "
    end

    result *= string(abs(b)) * "im"

    if c<0
        result *= " - "
    else
        result *= " + "
    end

    result *= string(abs(c)) * "jm"

    if d<0
        result *= " - "
    else
        result *= " + "
    end

    result *= string(abs(d)) * "km"
end

function show(io::IO, x::SimpleQuaternion)
    print(io, string(x))
end


text:
using Test
using CartesianMesh
# using Revise
using CutCellDG
include("../useful_routines.jl")

cm = CutCellDG.CellMap([0.,2.],[3.,3.])
@test CutCellDG.dimension(cm) == 2
@test CutCellDG.jacobian(cm) == [1.5,0.5]
@test allapprox(cm([0.,0.]),[1.5,2.5])
@test allapprox(cm([1.,0.]),[3.,2.5])

mesh = UniformMesh([0.,0.],[1.,1.],[2,2])
@test allequal(CutCellDG.elements_per_mesh_side(mesh),[2,2])
cellmaps = CutCellDG.construct_cell_maps(mesh)
cm1 = CutCellDG.CellMap([0.,0.],[0.5,0.5])
cm2 = CutCellDG.CellMap([0.,0.5],[0.5,1.])
cm3 = CutCellDG.CellMap([0.5,0.],[1.,0.5])
cm4 = CutCellDG.CellMap([0.5,0.5],[1.,1.])
@test allequal(cellmaps,[cm1,cm2,cm3,cm4])

cm = CutCellDG.CellMap([0.,0.],[1.,1.])
@test CutCellDG.determinant_jacobian(cm) ≈ 0.25

cm = CutCellDG.CellMap([1.,1.],[5.,8.])
@test CutCellDG.determinant_jacobian(cm) ≈ 7.0

cm = CutCellDG.CellMap([2.,1.],[4.,2.])
@test allapprox(CutCellDG.inverse(cm,[3,1.5]),[0.,0.])
@test allapprox(CutCellDG.inverse(cm,[4,2.]),[1.,1.])
@test allapprox(CutCellDG.inverse(cm,[2,1]),[-1.,-1.])


text:
export DynamicDrillModel,
    reward, discount, statespace, zspace, ztransition, psispace, anticipate_t1ev,
    DDM_NoVF

# -----------------------------------------
# Model
# -----------------------------------------

"Full-blown Dynamic discrete choice model"
struct DynamicDrillModel{T<:Real, PF<:DrillReward, AM<:AbstractMatrix{T},
    AUP<:AbstractUnitProblem, TT<:Tuple, AR<:StepRangeLen{T}, VF<:Union{AbstractValueFunction,Nothing}
} <: AbstractDynamicDrillModel
    reward::PF            # payoff function
    discount::T           # discount factor
    statespace::AUP       # structure of endogenous choice vars
    zspace::TT            # z-space (tuple)
    ztransition::AM       # transition for z
    psispace::AR          # ψspace = (u, ρu + sqrt(1-ρ²)*v)
    anticipate_t1ev::Bool # do we anticipate the ϵ shocks assoc w/ each choice?
    vf::VF                # value function
    tmpv::DCDPTmpVarsArray{T,AM}

    function DynamicDrillModel(
      reward::APF, discount::T, statespace::AUP, zspace::TT, ztransition::AM,
      psispace::AR, anticipate_t1ev, vf::Union{Type,Function}=ValueFunction
    ) where {
        T,N, APF, AUP, TT<:NTuple{N,AbstractRange},
        AM, AR
    }
        nz = checksquare(ztransition)
        npsi = length(psispace)
        nS = length(statespace)
        nd = length(actionspace(statespace))
        ntheta = _nparm(reward)

        0 < discount < 1 || throw(DomainError(discount))
        nz == prod(length.(zspace)) || throw(DimensionMismatch("zspace dim != ztransition dim"))

        vfout = vf(reward, discount, statespace, zspace, ztransition, psispace)
        VF = typeof(vfout)

        tmpv = DCDPTmpVars(ntheta, nz, npsi, nd, ztransition)

        return new{T,APF,AM,AUP,TT,AR,VF}(reward, discount, statespace, zspace, ztransition, psispace, anticipate_t1ev, vfout, tmpv)
    end
end

@deprecate DCDPEmax(args...) ValueFunctionArrayOnly(args...)

reward(         x::DynamicDrillModel) = x.reward
discount(       x::DynamicDrillModel) = x.discount
statespace(     x::DynamicDrillModel) = x.statespace
zspace(         x::DynamicDrillModel) = x.zspace
ztransition(    x::DynamicDrillModel) = x.ztransition
psispace(       x::DynamicDrillModel) = x.psispace
anticipate_t1ev(x::DynamicDrillModel) = x.anticipate_t1ev
value_function( x::DynamicDrillModel) = x.vf
DCDPTmpVars(    x::DynamicDrillModel) = x.tmpv

beta_1minusbeta(ddm::DynamicDrillModel) = discount(ddm) / (1-discount(ddm))

theta_drill_ρ(d::DynamicDrillModel, theta) = theta[_nparm(reward(d))]

function DynamicDrillModel(ddm::DynamicDrillModel, rwrd::DrillReward, wp = statespace(ddm))
    ddmnew = DynamicDrillModel(
        rwrd, discount(ddm), wp, zspace(ddm), ztransition(ddm),
        psispace(ddm), anticipate_t1ev(ddm)
    )
    return ddmnew
end

@deprecate DynamicDrillModel(
    rwrd::DrillReward, ddm::DynamicDrillModel, wp::AbstractStateSpace
    ) DynamicDrillModel(ddm, rwrd, wp)

# -----------------------------------------
# Outer constructors for VF from DDM
# -----------------------------------------

const DDM_NoVF       = DynamicDrillModel{T,APF,AM,AUP,TT,AR, Nothing}                  where {T,APF,AM,AUP,TT,AR}
const DDM_VFAO       = DynamicDrillModel{T,APF,AM,AUP,TT,AR, <:ValueFunctionArrayOnly} where {T,APF,AM,AUP,TT,AR}
const DDM_VF         = DynamicDrillModel{T,APF,AM,AUP,TT,AR, <:ValueFunction}          where {T,APF,AM,AUP,TT,AR}
const DDM_AbstractVF = DynamicDrillModel{T,APF,AM,AUP,TT,AR, <:AbstractValueFunction}  where {T,APF,AM,AUP,TT,AR}

DDM_NoVF(rwrd, beta, wp, z, ztrans, psi, t1ev) = DynamicDrillModel(rwrd, beta, wp, z, ztrans, psi, t1ev,  (args...) -> nothing)
DDM_NoVF(m::DynamicDrillModel) = DDM_NoVF(
        reward(m), discount(m), statespace(m), zspace(m), ztransition(m),
        psispace(m), anticipate_t1ev(m)  )

ValueFunctionArrayOnly(ddm::DDM_NoVF) = ValueFunctionArrayOnly(reward(ddm), discount(ddm), statespace(ddm), zspace(ddm), ztransition(ddm), psispace(ddm))
ValueFunction(         ddm::DDM_NoVF) = ValueFunction(         reward(ddm), discount(ddm), statespace(ddm), zspace(ddm), ztransition(ddm), psispace(ddm))

ValueFunctionArrayOnly(ddm::DDM_VFAO) = value_function(ddm)
ValueFunctionArrayOnly(ddm::DDM_VF) = ValueFunctionArrayOnly(value_function(ddm))

ValueFunction(ddm::DDM_VF) = value_function(ddm)

function ValueFunction(ddm::DDM_VFAO)
    vfao = value_function(ddm)
    ev = EV(vfao)
    dev = dEV(vfao)
    return ValueFunction(ev, dev, reward(ddm), discount(ddm), statespace(ddm), zspace(ddm), ztransition(ddm), psispace(ddm))
end

# -----------------------------------------
# Value Function Arrays
# -----------------------------------------

@inline function clamp_psi(m::DynamicDrillModel, psi)
    psis = psispace(m)
    return clamp(psi, first(psis), last(psis))
end

"""
    discounted_dynamic_payoff!(grad, d, obs, sim, dograd)

compute `β * E[ V(z',ψ'x') | z,ψ,x]` and also gradient
"""
function discounted_dynamic_payoff!(grad, d::Integer, obs::ObservationDynamicDrill, sim, dograd)

    mod = _model(obs)
    rwrd = reward(mod)
    beta = discount(mod)
    nk = length(grad)
    nk == _nparm(rwrd) || throw(DimensionMismatch())

    vf = value_function(mod)
    vf_sitp = EV_scaled_itp(vf)

    psi_unsafe = _ψ(obs, sim)
    psi = clamp_psi(mod, psi_unsafe)
    sp = sprime(statespace(mod), _x(obs), d)
    z = zchars(obs)

    if dograd
        dvf_sitp = dEV_scaled_itp(vf)
        @inbounds @simd for k in OneTo(nk)
            grad[k] += beta * dvf_sitp(z..., psi, k, sp)
        end
        dpsi = last(Interpolations.gradient(vf_sitp, z..., psi, sp)) # FIXME
        grad[idx_ρ(rwrd)] += dpsi * beta * _dψdθρ(obs, sim)
    end

    return beta * vf_sitp(z..., psi, sp)
end

function full_payoff!(grad, d::Integer, obs::ObservationDynamicDrill, theta, sim, dograd)
    rwrd = reward(_model(obs))
    static_payoff  = flow!(grad, rwrd, d, obs, theta, sim, dograd)
    if dograd
        grad[idx_ρ(rwrd)] += flowdψ(rwrd, d, obs, theta, sim) * _dψdθρ(obs, sim)
    end
    dynamic_payoff = discounted_dynamic_payoff!(grad, d, obs, sim, dograd)
    return static_payoff + dynamic_payoff
end

# -----------------------------------------
# for data generation
# -----------------------------------------

function initialize_x!(x, m::DynamicDrillModel, lease)
    s1 = 1
    s2 = end_ex1(statespace(m))+1
    x[1] = s1 # sample([s1,s2])
end

function update_x!(x, t, m::DynamicDrillModel, state, d)
    wp = statespace(m)
    @assert d in actionspace(wp,state)
    @assert state <= end_ex0(wp)+1 || state > end_lrn(wp)
    if t+1 <= length(x)
        x[t+1] = ssprime(wp, state, d)
    end
end

function ichars_sample(m::DynamicDrillModel, num_i)
    # geo, roy
    dist_geo = Normal(4.67, 0.33)
    dist_roy = [1/8, 1/6, 3/16, 1/5, 9/40, 1/4]
    geos = rand(dist_geo, num_i)
    roys = sample(dist_roy, num_i)
    return [(g,r) for (g,r) in zip(geos, roys)]
end


text:
push!(LOAD_PATH,"../src/simple_mesh/")

using PDESolver
using SimpleMesh

# Using fact check for the first time
@testset "Testing SimpleMesh type" begin
  # Enter your tests here
  @testset "Check if function createMesh() works or not" begin
    # Build an element grid comprising of 2 triangular elements
    for p = 1:4
      if p == 1
        act_ien = [1 2;2 4;3 3]
        act_nnp = 4
        act_nel = 2
        act_vtx_loc = [0.0 1.0 0.0 1.0;
                       0.0 0.0 1.0 1.0]
        act_elem_edge_lengthx = 1.0
        act_elem_edge_lengthy = 1.0
        act_NodeEdgex = [1 2;3 4]
        act_NodeEdgey = [2 4;1 3]
        act_HBedges = [1;2]
        act_VBedges = [4;5]
        act_nedges = 5
        m = SimpleMesh{Float64}(1,1,1,1,p+1)
        res1 = act_ien - m.ien
        res2 = act_nnp - m.nnp
        res3 = act_nel - m.nel
        res4 = act_vtx_loc - m.vtx_loc
        res5 = act_elem_edge_lengthx - m.elem_edge_lengthx
        res6 = act_elem_edge_lengthy - m.elem_edge_lengthy
        res7 = act_NodeEdgex - m.NodeEdgex
        res8 = act_NodeEdgey - m.NodeEdgey
        res9 = act_HBedges - m.HBedges
        res10 = act_VBedges - m.VBedges
        res11 = act_nedges - m.nedges
        @test isapprox( res1, zeros(size(ien))) atol=1e-13
        @test isapprox( res2, 0) atol=1e-13
        @test isapprox( res3, 0) atol=1e-13
        @test isapprox( res4, zeros(size(act_vtx_loc))) atol=1e-13
        @test isapprox( res5, 0) atol=1e-13
        @test isapprox( res6, 0) atol=1e-13
        @test isapprox( res7, zeros(size(act_NodeEdgex))) atol=1e-13
        @test isapprox( res8, zeros(size(act_NodeEdgey))) atol=1e-13
        @test isapprox( res9, zeros(size(act_HBedges))) atol=1e-13
        @test isapprox( res10, zeros(size(act_VBedges))) atol=1e-13
        @test isapprox( res11, 0) atol=1e-13
      elseif p == 2
        act_ien = [1 3;3 9;7 7;2 6;5 8;4 5;10 11]
        act_nnp = 11
        act_nel  = 2
        act_vtx_loc = [0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0;
                       0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 1.0 0.0 0.0]
        act_elem_edge_lengthx = 1.0
        act_elem_edge_lengthy = 1.0
        act_NodeEdgex = [1 2 3;7 8 9]
        act_NodeEdgey = [3 6 9;1 4 7]
        act_HBedges = [1;2]
        act_VBedges = [4;5]
        act_nedges = 5
        m = SimpleMesh{Float64}(1,1,1,1,p+1)
        res1 = act_ien - m.ien
        res2 = act_nnp - m.nnp
        res3 = act_nel - m.nel
        res4 = act_vtx_loc - m.vtx_loc
        res5 = act_elem_edge_lengthx - m.elem_edge_lengthx
        res6 = act_elem_edge_lengthy - m.elem_edge_lengthy
        res7 = act_NodeEdgex - m.NodeEdgex
        res8 = act_NodeEdgey - m.NodeEdgey
        res9 = act_HBedges - m.HBedges
        res10 = act_VBedges - m.VBedges
        res11 = act_nedges - m.nedges
        @test isapprox( res1, zeros(size(ien))) atol=1e-13
        @test isapprox( res2, 0) atol=1e-13
        @test isapprox( res3, 0) atol=1e-13
        @test isapprox( res4, zeros(size(act_vtx_loc))) atol=1e-13
        @test isapprox( res5, 0) atol=1e-13
        @test isapprox( res6, 0) atol=1e-13
        @test isapprox( res7, zeros(size(act_NodeEdgex))) atol=1e-13
        @test isapprox( res8, zeros(size(act_NodeEdgey))) atol=1e-13
        @test isapprox( res9, zeros(size(act_HBedges))) atol=1e-13
        @test isapprox( res10, zeros(size(act_VBedges))) atol=1e-13
        @test isapprox( res11, 0) atol=1e-13
      elseif p == 3
        act_ien = [1 4;4 14;11 11;2 7;3 10;6 13;9 12;5 6;8 9;15 18; 16 19;17 20]
        act_nnp = 20
        act_nel  = 2
        act_vtx_loc = [0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0;
                       0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0]
        act_elem_edge_lengthx = 1.0
        act_elem_edge_lengthy = 1.0
        act_NodeEdgex = [1 2 3 4;11 12 13 14]
        act_NodeEdgey = [4 7 10 14;1 5 8 11]
        act_HBedges = [1;2]
        act_VBedges = [4;5]
        act_nedges = 5
        m = SimpleMesh{Float64}(1,1,1,1,p+1)
        res1 = act_ien - m.ien
        res2 = act_nnp - m.nnp
        res3 = act_nel - m.nel
        res4 = act_vtx_loc - m.vtx_loc
        res5 = act_elem_edge_lengthx - m.elem_edge_lengthx
        res6 = act_elem_edge_lengthy - m.elem_edge_lengthy
        res7 = act_NodeEdgex - m.NodeEdgex
        res8 = act_NodeEdgey - m.NodeEdgey
        res9 = act_HBedges - m.HBedges
        res10 = act_VBedges - m.VBedges
        res11 = act_nedges - m.nedges
        @test isapprox( res1, zeros(size(ien))) atol=1e-13
        @test isapprox( res2, 0) atol=1e-13
        @test isapprox( res3, 0) atol=1e-13
        @test isapprox( res4, zeros(size(act_vtx_loc))) atol=1e-13
        @test isapprox( res5, 0) atol=1e-13
        @test isapprox( res6, 0) atol=1e-13
        @test isapprox( res7, zeros(size(act_NodeEdgex))) atol=1e-13
        @test isapprox( res8, zeros(size(act_NodeEdgey))) atol=1e-13
        @test isapprox( res9, zeros(size(act_HBedges))) atol=1e-13
        @test isapprox( res10, zeros(size(act_VBedges))) atol=1e-13
        @test isapprox( res11, 0) atol=1e-13
      elseif p == 4
        act_ien = [1 5;5 19;15 15;2 8;3 11;4 14;7 18;10 17;13 16;6 7;9 10;12 13;20 26;21 27;
                   22 28;23 29;24 30;25 31]
        act_nnp = 31
        act_nel  = 2
        act_vtx_loc = [0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0;
                       0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0]
        act_elem_edge_lengthx = 1.0
        act_elem_edge_lengthy = 1.0
        act_NodeEdgex = [1 2 3 4 5;15 16 17 18 19]
        act_NodeEdgey = [5 8 11 14 19;1 6 9 12 15]
        act_HBedges = [1;2]
        act_VBedges = [4;5]
        act_nedges = 5
        m = SimpleMesh{Float64}(1,1,1,1,p+1)
        res1 = act_ien - m.ien
        res2 = act_nnp - m.nnp
        res3 = act_nel - m.nel
        res4 = act_vtx_loc - m.vtx_loc
        res5 = act_elem_edge_lengthx - m.elem_edge_lengthx
        res6 = act_elem_edge_lengthy - m.elem_edge_lengthy
        res7 = act_NodeEdgex - m.NodeEdgex
        res8 = act_NodeEdgey - m.NodeEdgey
        res9 = act_HBedges - m.HBedges
        res10 = act_VBedges - m.VBedges
        res11 = act_nedges - m.nedges
        @test isapprox( res1, zeros(size(ien))) atol=1e-13
        @test isapprox( res2, 0) atol=1e-13
        @test isapprox( res3, 0) atol=1e-13
        @test isapprox( res4, zeros(size(act_vtx_loc))) atol=1e-13
        @test isapprox( res5, 0) atol=1e-13
        @test isapprox( res6, 0) atol=1e-13
        @test isapprox( res7, zeros(size(act_NodeEdgex))) atol=1e-13
        @test isapprox( res8, zeros(size(act_NodeEdgey))) atol=1e-13
        @test isapprox( res9, zeros(size(act_HBedges))) atol=1e-13
        @test isapprox( res10, zeros(size(act_VBedges))) atol=1e-13
        @test isapprox( res11, 0) atol=1e-13
      end # Ends if-else statement
    end   # Ends for loop
  end     # Ends context

end # Ends facts


text:
module TestUngroup

using FactCheck
using DataCubes
using DataCubes: simplify_array

facts("Ungroup tests") do
  jaggedarr0 = simplify_array(nalift(reshape(Any[nalift([1,2,3]),nalift(["a","b","c"]),nalift([4,5,6,7,8]),nalift(["hello","hi","this","one","ten"]),[Nullable(9)],[Nullable("A")]], (2,3))))
  nonjaggedarr = nalift(reshape([1,2,3,4,5,6], (2,3)))
  @fact ungroup(jaggedarr0, jaggedarr0[1:1,:]) --> nalift(transpose(hcat(collect(1:9),["a","b","c","hello","hi","this","one","ten","A"])))
  @fact ungroup(jaggedarr0, 2) --> ungroup(jaggedarr0, jaggedarr0[1:1,:])
  @fact ungroup(nonjaggedarr, jaggedarr0[1:1,:]) --> nalift(transpose(hcat([1,1,1,3,3,3,3,3,5],[2,2,2,4,4,4,4,4,6])))
  @fact ungroup(transpose(jaggedarr0), transpose(jaggedarr0)[:,1]) --> transpose(ungroup(jaggedarr0, jaggedarr0[1:1,:]))
  @fact ungroup(transpose(nonjaggedarr), transpose(jaggedarr0)[:,1]) --> transpose(ungroup(nonjaggedarr, jaggedarr0[1:1,:]))
  @fact ungroup(map(Nullable, reshape(Any[[1,2,3],["a","b","c"],[4,5,6,7,8],["hello","hi","this","one","ten"],[9],["A"]], (2,3))), 2) --> nalift(transpose(hcat(collect(1:9),["a","b","c","hello","hi","this","one","ten","A"])))

  jaggedarr = nalift(reshape(nalift(Any[[1,2,3],[11,12,13],[4,5,6,7,8],[14,15,16,17,18],[9],[19]]), (2,3)))
  @fact ungroup(jaggedarr, jaggedarr[1:1,:]) --> nalift(transpose(hcat(collect(1:9),collect(11:19))))
  @fact ungroup(jaggedarr, 2) --> ungroup(jaggedarr, jaggedarr[1:1,:])
  @fact ungroup(nonjaggedarr, jaggedarr[1:1,:]) --> nalift(transpose(hcat([1,1,1,3,3,3,3,3,5],[2,2,2,4,4,4,4,4,6])))
  @fact ungroup(transpose(jaggedarr), transpose(jaggedarr)[:,1]) --> transpose(ungroup(jaggedarr, jaggedarr[1:1,:]))
  @fact ungroup(transpose(nonjaggedarr), transpose(jaggedarr)[:,1]) --> transpose(ungroup(nonjaggedarr, jaggedarr[1:1,:]))
  jagged_darr = DictArray(c1=jaggedarr)
  jagged_larr = LabeledArray(DictArray(c1=jaggedarr), axis1=@darr(k1=[1,2],k2=["a","b"]), axis2=@darr(r1=['x','y','z']))
  jagged_larr2 = LabeledArray(DictArray(c1=jaggedarr))
  @fact ungroup(jagged_darr, 2) --> @darr(c1=ungroup(jaggedarr, 2))
  @fact ungroup(jagged_larr, 2) --> @larr(r1=repmat(['x' 'x' 'x' 'y' 'y' 'y' 'y' 'y' 'z'],2),c1=pick(ungroup(jagged_darr,2),:c1),axis1[k1=[1,2],k2=["a","b"]])
  @fact ungroup(jagged_larr2, 2) --> LabeledArray(ungroup(jagged_larr2.data, 2))
  @fact ungroup(larr(fill(LDict(:a=>nalift([3,2,1])), 2, 3), axis1=11:12, axis2=darr(r=21:23)),1) --> larr(reshape(darr(x1=repmat([11,11,11,12,12,12],3),a=repmat([3,2,1],6)), 6,3), axis2=darr(r=[21,22,23]))
  @fact ungroup(larr(fill(LDict(:a=>nalift([3,2,1])), 2, 3), axis1=11:12, axis2=darr(r=21:23)),2) --> larr(reshape(larr(r=[[fill(x,6) for x in 21:23]...;], a=repeat([3,2,1],inner=[2],outer=[3])),2,9), axis1=11:12)
  context("simple combining multiple table tests") do
    d1 = darr(a=[1 2 3;4 5 6],b=['a' 'b' 'c';'d' 'e' 'f'])
    d2 = @darr(a=[10 11], b=['x' NA])
    combined1 = larr(Any[peel(d1), peel(d2)], axis1=[:set1, :set2])
    @fact ungroup(combined1, 1) --> @larr(x1=[fill(:set1,6);fill(:set2,2)],a=[1,4,2,5,3,6,10,11],b=['a','d','b','e','c','f','x',NA])
    @fact ungroup(combined1) --> @larr(x1=[fill(:set1,6);fill(:set2,2)],a=[1,4,2,5,3,6,10,11],b=['a','d','b','e','c','f','x',NA])
    combined2 = larr(darr(Any[peel(d1) peel(d2)]), axis2=darr(k=[:set1, :set2]))
    @fact ungroup(combined2, 2) --> reshape(@larr(k=[fill(:set1,6);fill(:set2,2)],a=[1,4,2,5,3,6,10,11],b=['a','d','b','e','c','f','x',NA]),1,8)
  end
end

end


text:
#=struct TestPort
  Fret::Symbol
  Ffactors::Vector{Symbol}
end=#

const BLAS_MULTITHREAD = 1

struct FactorSpecification
    df::SubDataFrame #the data used
    Fret::Symbol
    Fdate::Symbol #date or period field
    Fport::Symbol

    #these are considered factors, generally used in the time series regressions
    Ffactors::Union{Nothing,Vector{Symbol}}

    #These are chracteristics, typically used for the cross-sectional regressions
    Fcharacteristics::Union{Nothing,Vector{Symbol}}

    Fcontrols::Vector{Symbol} #holds controls only

    #accessor variables
    eachport::GroupedDataFrame
    eachdate::GroupedDataFrame
    portidx::Dict{Union{Int,Symbol}, Int}
    dateidx::Dict{Union{Date,Int}, Int}

    name::Symbol
end

#NOTE: Brackets index the test portfolios
Base.getindex(fs::FactorSpecification, sym::Symbol) = fs.eachport[portidx[sym]]
Base.getindex(fs::FactorSpecification, dt::Union{Date,Int}) = fs.eachdate[dateidx[dt]]

#the below methods could probably be improved
Base.getindex(fs::FactorSpecification, syms::Symbol...) = view(
  fs.df, (s::Symbol-> s ∈ syms).(fs.df[!,fs.Fport]), :)
Base.getindex(fs::FactorSpecification, dts::Union{Date,Int}...) = view(
  fs.df, (d::Union{Date,Int}-> s ∈ dts).(fs.df[!,fs.Fdate]), :)

@inline function notsmallgroups(df::AbstractDataFrame, Fgroup::Symbol;
  minrowspergroup::Int = error("minrowspergroup must be assigned"))::Vector{Bool}

  dfcount::DataFrame = DataFrame(group = df[!,Fgroup])
  dfcount.count = Vector{MInt}(undef, size(dfcount,1))

  for sdfcount ∈ groupby(dfcount, :group)
    sdfcount.count .= size(sdfcount,1)
  end

  return dfcount.count .≥ minrowspergroup
end

#main constructor
function FactorSpecification(df::AbstractDataFrame, Fret::Symbol, Fdate::Symbol, Fport::Symbol;
    Ffactors::Union{Nothing, Vector{Symbol}}=nothing,
    Fcharacteristics::Union{Nothing, Vector{Symbol}}=nothing,
    bounds::Union{AbstractRange, Nothing} = nothing,
    Fcontrols = Vector{Symbol}(),
    name::Symbol = nothing,
    minrowspergroup::Int = MIN_ROWS_PER_GROUP,
    skipcrosssectiondfcheck::Bool = false,
    skiptimeseriesdfcheck::Bool = false
    )

  local sdf::SubDataFrame
  local dfnames::Vector{Symbol} = names(df)

  #make sure the dataframe has everything we want
  (Fret ∈ dfnames) || error("return field $Fret not found in dataframe!")
  (Fdate ∈ dfnames) || error("datefield $Fdate not found in dataframe!")
  (Fport ∈ dfnames) || error("port field $Fport not found in dataframe!")
  (!isnothing(Ffactors)) && (
    (s->(s ∈ dfnames) || error("Factor $s not found in dataframe!")).(Ffactors))
  (!isnothing(Fcharacteristics)) && (
    (s->(s ∈ dfnames) || error("Factor $s not found in dataframe!")).(Fcharacteristics))
  (s->(s ∈ dfnames) || error("Control $s not found in dataframe!")).(Fcontrols)
  #println("num missing = $(size(df[(!).(completecases(df[!,[Fret,Fdate,Fport]])),:]))")
  #(sum((!).(completecases(df[!,[Fdate,Fport]]))) == 0) || error("missing values found in identifiers")
  issorted(df, [Fport, Fdate]) || error("DataFrame must be sorted by $Fport and $Fdate")

  if isnothing(bounds) && typeof(df) == DataFrame
    sdf = view(df, :, :)
  elseif !isnothing(bounds)
    sdf = view(df, (d::Any ->
      (d ≥ minimum(bounds)) && (d≥maximum(bounds))).(df[!,Fdate]), :)
  else
    sdf = df
  end

  allfields::Vector{Symbol} = filter(s->!isnothing(s), [Fret; Fdate; Fport; Ffactors; Fcharacteristics; Fcontrols])
  sdf = view(sdf, completecases(sdf[!, allfields]), allfields)

  skiptimeseriesdfcheck || (sdf = view(sdf, notsmallgroups(sdf, Fport, minrowspergroup=minrowspergroup), :))
  skipcrosssectiondfcheck || (sdf = view(sdf, notsmallgroups(sdf, Fdate, minrowspergroup=minrowspergroup), :))

  (size(sdf,1)==0) && error("no rows left with reasonable sample size")

  #build subarrays of the most comon slices we will take for analysis
  eachport = groupby(sdf, Fport)
  eachdate = groupby(sdf, Fdate)
  portidx::Dict = Dict(eachport[i][1, Fport] => i for i ∈ 1:length(eachport))
  dateidx::Dict = Dict(eachdate[i][1, Fdate] => i for i ∈ 1:length(eachdate))

  return FactorSpecification(sdf, Fret, Fdate, Fport, Ffactors, Fcharacteristics, Fcontrols,
    eachport, eachdate, portidx, dateidx, name)
end

function rhs(fs::FactorSpecification, focalvars::Union{Vector{Symbol},Nothing};
    intercept::Bool = true)
  local rhs::Union{Symbol, Expr, Nothing}
  local rhsstring::String

  joinvec::Vector{NSymbol} = [focalvars; fs.Fcontrols;]
  joinvec = joinvec[(!isnothing).(joinvec)]

  rhsstring = join((string).(joinvec), " + ")
  (!intercept) && (rhsstring = "$rhsstring + 0")

  rhs = Meta.parse(rhsstring)

  return rhs
end

function rhsnames(fs::FactorSpecification, focalvars::Union{Vector{Symbol},Nothing};
    intercept::Bool = true)::Vector{Symbol}

  local nms::Vector{Union{Symbol,Nothing}}

  if intercept
    nms = [:intercept; focalvars; fs.Fcontrols;]
  else
    nms = [focalvars; fs.Fcontrols;]
  end

  return nms[(!isnothing).(nms)]
end

#creates the formulas
factorrhs(fs::FactorSpecification; intercept::Bool = true)::FMExpr = rhs(
  fs, fs.Ffactors, intercept=intercept)
factorrhsnames(fs::FactorSpecification; intercept::Bool = true)::Vector{Symbol} = rhsnames(
  fs, fs.Ffactors, intercept=intercept)
characteristicrhs(fs::FactorSpecification; intercept::Bool = true)::FMExpr = rhs(
  fs, fs.Fcharacteristics, intercept=intercept)
characteristicrhsnames(fs::FactorSpecification; intercept::Bool = true)::Vector{Symbol} = rhsnames(
  fs, fs.Fcharacteristics, intercept=intercept)

#run time series regressions with an arbitrary aggregation function
function timeseriesregressions(fs::FactorSpecification,
  ::Type{T} = FMLM,
  ::Type{M} = Matrix{Float64},
  ::Type{V} = Vector{Float64};
  timeseriesdep::Symbol=fs.Fret,
  timeseriesrhs = factorrhs(fs),
  timeseriesrhsnames = factorrhsnames(fs),
  aggfunc::Function = (f(m::FMLM)::T=m),
  parallel::Bool = false,
  qrtype::Type = Matrix{Float64})::Vector{T} where {
    T, M<:AbstractMatrix, V<:AbstractVector}

  Nreg::Int = length(fs.eachport)
  specs::FMSpecs = FMSpecs(Nreg, T, aggfunc=aggfunc)

  timeseriesrhs = factorrhs(fs)
  timeseriesrhsnames = factorrhsnames(fs)

  for i ∈ 1:length(fs.eachport)
    push!(specs, yspec = fs.Fret, xspec = timeseriesrhs, xnames = timeseriesrhsnames)
  end

  if parallel
    BLAS.set_num_threads(1)
  else
    BLAS.set_num_threads(BLAS_MULTITHREAD)
  end

  computeFMLMresults!(fs.eachport, specs, M, V,
    parallel=parallel, containsmissings=false, qrtype = qrtype)

  return specs.results
end

#run time series regressions with an arbitrary aggregation function
function crosssectionalregressions(fs::FactorSpecification, ::Type{T} = FMLM,
    ::Type{M} = Matrix{Float64}, ::Type{V} = Vector{Float64};
  aggfunc::Function = (f(m::FMLM)::T=m),
  parallel::Bool = false, qrtype::Type = Matrix{Float64})::Vector{T} where {
    T, M<:AbstractMatrix, V<:AbstractVector}

  Nreg::Int = length(fs.eachport)
  specs::FMSpecs = FMSpecs(Nreg, T, aggfunc=aggfunc)

  crosssectionalrhs = characteristicrhs(fs)
  crosssectionalrhsnames = characteristicrhsnames(fs)

  for i ∈ 1:length(fs.eachdate)
    push!(specs, yspec = fs.Fret, xspec = crosssectionalrhs, xnames = crosssectionalrhsnames)
  end

  if parallel
    BLAS.set_num_threads(1)
  else
    BLAS.set_num_threads(BLAS_MULTITHREAD)
  end
  computeFMLMresults!(fs.eachdate, specs, M, V,
    parallel=parallel, containsmissings=false,
    qrtype=qrtype)

  #alldates::Vector{Date} = (df::SubDataFrame->df[1,fs.Fdate]).(fs.eachdate)

  #dateidx::Dict = Dict(zip(alldates, specs.results))

  return specs.results
end

struct FactorRegression
  λ::Union{Nothing, Matrix{Float64}}
  λᵢ::Vector{Float64}
  σᵢ::Vector{Float64}
  t::NInt
  name::Symbol
  coefidx::Dict{Symbol, Int}
  otherstats::Dict{Symbol, Any}
end

FactorRegression( λ::Union{Nothing, Matrix{Float64}}, λᵢ::Vector{Float64},
  σᵢ::Vector{Float64}, t::NInt, name::Symbol,
  coefidx::Dict{Symbol, Int}) = FactorRegression(λ, λᵢ, σᵢ, t, name, coefidx, Dict{Symbol, Any}())

function manyFF(fs::FactorSpecification,
  ::Type{M} = Matrix{Float64}, ::Type{V} = Vector{Float64};
  parallel::Bool = false,
  errorfunction::Function = neweywestΣfunc(2),
  qrtype::Type = Matrix{Float64})::Vector{FactorRegression} where {
    M<:AbstractMatrix, V<:AbstractVector}

  local frs::Vector{FactorRegression} = Vector{FactorRegression}()

  #make the time-series regression aggregation function
  T::Type = FMLM
  @inline aggfunc(fmlm::FMLM) = fmlm

  results = timeseriesregressions(fs, T, M, V,
    aggfunc=aggfunc, parallel=parallel, qrtype=qrtype)
  coefnames::Vector{Symbol} = factorrhsnames(fs)
  coefidx = Dict{Symbol, Int}(zip(coefnames, 1:(length(coefnames))))

  #now build the factor regression objects, one for each regression
  for (i,port::SubDataFrame) ∈ enumerate(fs.eachport)
    local λᵢ::Vector{Float64} = results[i].β
    local σᵢ::Vector{Float64} = diag(errorfunction(results[i])).^0.5
    local t::Int = size(port,1)
    local name::Symbol = Symbol("$(fs.name)_col$(port[1,fs.Fport])")
    push!(frs, FactorRegression(nothing, λᵢ, σᵢ, t, name, coefidx))
  end

  return frs
end

function characteristicFM(fs::FactorSpecification,
    ::Type{M}=Matrix{Float64}, ::Type{V}=Vector{Float64};
    parallel::Bool = false, lags::Int=2,
    qrtype::Type = Matrix{Float64})::FactorRegression where {
      M<:AbstractMatrix, V<:AbstractVector}

  local t::Int
  local λ::Matrix{Float64}
  local λᵢ::Vector{Float64}
  local σᵢ::Vector{Float64}
  local name::Symbol
  local coefidx::Dict{Symbol, Int}

  #make the time-series regression aggregation function
  T::Type = Vector{Float64}
  @inline aggfunc(fmlm::FMLM) = fmlm.β

  results = crosssectionalregressions(fs, T, M, V,
    aggfunc=aggfunc, parallel=parallel, qrtype=qrtype)
  coefnames::Vector{Symbol} = characteristicrhsnames(fs)

  coefidx = Dict{Symbol, Int}(zip(coefnames, 1:(length(coefnames))))

  #now build the factor regression object
  λ = vcat((transpose).(results)...) #create rows and make result matrix
  origrows::Int = size(λ,1)
  λ = λ[(i->isfinite(sum(λ[i,:]))).(1:size(λ,1)), :] #checks for na/missing and drops such rows
  newrows::Int = size(λ,1)
  (origrows ≠ newrows) && (println("$(fs.name): removed " *
    "$(origrows - newrows) rows during DQ. $(newrows) remain."))
  t = size(λ,1)
  λᵢ = (c->mean(c)).(eachcol(λ))
  #println("coefnames: $coefnames")
  #println("λᵢ: $λᵢ\n")
  Σ::Matrix{Float64} = FMBartlett(λ, λᵢ, lags)
  σᵢ = diag(Σ).^ 0.5 ./ t^0.5

  #=println("\nFastNW: $σᵢ " *
    #"\nSlowNW: $(diag(FMBartlettSlow(λ, λᵢ, lags)).^0.5 ./ t^0.5)" *
    #"\nFMNeweyWestML: $(diag(FMBartlettML(λ, λᵢ, lags)).^0.5 ./ t^0.5)" *
    "\nNormalSE: $((c->std(c)).(eachcol(λ)) ./ t^0.5)" *
    "\nλᵢ: $λᵢ"
    )=#

  name = fs.name

  return FactorRegression(λ, λᵢ, σᵢ, t, name, coefidx)
end

function panelFM(fs::FactorSpecification,
    ::Type{M}=Matrix{Float64}, ::Type{V}=Vector{Float64};
    errorfunctions::Vector{Function}=[homoskedasticΣ!],
    withinsym::NSymbol = nothing,
    clustersyms::Union{NSymbol, Vector{Symbol}} = [fs.Fdate, fs.Fport],
    qrtype::Type = Matrix{Float64})::Vector{FactorRegression} where {
      M<:AbstractMatrix, V<:AbstractVector}

  local frs::Vector{FactorRegression} = Vector{FactorRegression}()

  #make the time-series regression aggregation function
  T::Type = Vector{Float64}
  @inline aggfunc(fmlm::FMLM) = fmlm

  rhs::FMExpr = characteristicrhs(fs)
  coefnames::Vector{Symbol} = characteristicrhsnames(fs)
  fmlm::FMLM = FMLM(fs.df, rhs, fs.Fret, M, V,
    withinsym=withinsym, clustersyms=clustersyms, Xnames=coefnames,
    containsmissings=false, qrtype=qrtype)
  coefidx = Dict{Symbol, Int}(zip(coefnames, 1:(length(coefnames))))
  local name = fs.name

  local λᵢ::Vector{Float64} = fmlm.β

  for (j,f) ∈ enumerate(errorfunctions)

    local σᵢ::Vector{Float64}

    #print("j=$j time: ")
    Σ::Matrix{Float64} = f(fmlm)
    σᵢ = diag(Σ).^ 0.5

    push!(frs, FactorRegression(nothing, λᵢ, σᵢ, nothing, name, coefidx))
  end

  return frs
end

#run time series regressions with an arbitrary aggregation function
function BJSFFrow(fs::FactorSpecification, df::AbstractDataFrame,
  ::Type{M} = Matrix{Float64}, ::Type{V} = Vector{Float64};
  parallel::Bool = false,
  errorfunction::Function = neweywestΣfunc(2),
  Ffactors::Vector{Symbol} = [fs.Fret; fs.Ffactors],
  qrtype::Type = Matrix{Float64},
  regressiongroupname::Symbol = df.portname[1])::Vector{FactorRegression} where {
    M<:AbstractMatrix, V<:AbstractVector}

  #this will hold the output
  local frs::Vector{FactorRegression} = Vector{FactorRegression}()

  #iterate through each dependent variable
  for (i, Ysym) ∈ enumerate(Ffactors)
    focals::Vector{Symbol} = setdiff(Ffactors, [Ysym]) #The Y-var is excluded here
    Xexpr = rhs(fs, focals)
    Xnames = rhsnames(fs, focals)

    #run the regression
    fmlm = FMLM(df, Xexpr, Ysym, M, V, Xnames = Xnames, containsmissings=false, qrtype=qrtype)

    #then make the FactorRegression object
    λᵢ::Vector{Float64} = fmlm.β
    σᵢ::Vector{Float64} = diag(errorfunction(fmlm)).^0.5
    t::Int = size(fs.df,1)
    name::Symbol = Symbol("$(regressiongroupname)_col$(Ysym)")
    coefidx::Dict = Dict{Symbol, Int}(zip(Xnames, 1:(length(Xnames))))
    otherstats::Dict = Dict(:R²=>R²(fmlm, adjusted=false))

    push!(frs, FactorRegression(nothing, λᵢ, σᵢ, t, name, coefidx, otherstats))
  end

  return frs
end

function BJSFF(fs::FactorSpecification,
  ::Type{M} = Matrix{Float64}, ::Type{V} = Vector{Float64};
  parallel::Bool = false,
  errorfunction::Function = neweywestΣfunc(2),
  qrtype::Type = Matrix{Float64})::Dict{Symbol, FactorRegression} where {
    M<:AbstractMatrix, V<:AbstractVector}

  #this will hold the output
  results::Dict = Dict{Symbol, FactorRegression}()

  #first build the baseline
  baselinedf::DataFrame = unique(fs.df[!, [:date; fs.Ffactors;]])
  baselinefrs::Vector{FactorRegression} = BJSFFrow(fs, baselinedf, Ffactors=fs.Ffactors, regressiongroupname=:baseline)
  for fr ∈ baselinefrs
    results[fr.name] = fr
  end

  #then build the rest
  for sdf ∈ fs.eachport
    frs::Vector{FactorRegression} = BJSFFrow(fs, sdf)
    for fr ∈ frs
      results[fr.name] = fr
    end
  end

  return results
end

max_stars_repo_name: clintonTE/CCA

max_issues_repo_name: clintonTE/CCA

max_forks_repo_name: clintonTE/CCA


text:
function get_field(obj::GeoMagneticFields, arg0::GeoMagneticFieldFactory_FieldModel, arg1::jdouble)
    return jcall(obj, "getField", GeoMagneticField, (GeoMagneticFieldFactory_FieldModel, jdouble), arg0, arg1)
end

function get_igrf(obj::GeoMagneticFields, arg0::jdouble)
    return jcall(obj, "getIGRF", GeoMagneticField, (jdouble,), arg0)
end

function get_wmm(obj::GeoMagneticFields, arg0::jdouble)
    return jcall(obj, "getWMM", GeoMagneticField, (jdouble,), arg0)
end


text:
using Rubin
using Tests
using Elliptic
using HypergeometricFunctions
using Polylogarithms
using SpecialFunctions

@test integrate((d+e*x^3)^5*(a+b*x^3+c*x^6), x) == :(a*x*d^5+1//4*d^4*x^4*(b*d+5*a*e)+1//7*d^3*x^7*(c*d^2+5*e*(b*d+2*a*e))+1//16*e^3*x^16*(e*(a*e+5*b*d)+10*c*d^2)+1//19*e^4*x^19*(b*e+5*c*d)+1//22*c*e^5*x^22+(1/2)*e*d^2*x^10*(c*d^2+2*e*(a*e+b*d))+5//13*d*e^2*x^13*(e*(a*e+2*b*d)+2*c*d^2))
@test integrate((d+e*x^3)^4*(a+b*x^3+c*x^6), x) == :(a*x*d^4+1//4*d^3*x^4*(b*d+4*a*e)+1//7*d^2*x^7*(c*d^2+6*a*e^2+4*b*d*e)+1//13*e^2*x^13*(e*(a*e+4*b*d)+6*c*d^2)+1//16*e^3*x^16*(b*e+4*c*d)+1//19*c*e^4*x^19+1//5*d*e*x^10*(e*(2*a*e+3*b*d)+2*c*d^2))
@test integrate((d+e*x^3)^3*(a+b*x^3+c*x^6), x) == :(a*x*d^3+1//4*d^2*x^4*(b*d+3*a*e)+1//7*d*x^7*(c*d^2+3*e*(a*e+b*d))+1//10*e*x^10*(e*(a*e+3*b*d)+3*c*d^2)+1//13*e^2*x^13*(b*e+3*c*d)+1//16*c*e^3*x^16)
@test integrate((d+e*x^3)^2*(a+b*x^3+c*x^6), x) == :(1//7*x^7*(c*d^2+e*(a*e+2*b*d))+a*x*d^2+1//4*d*x^4*(b*d+2*a*e)+1//10*e*x^10*(b*e+2*c*d)+1//13*c*e^2*x^13)
@test integrate((d+e*x^3)*(a+b*x^3+c*x^6), x) == :(1//4*x^4*(a*e+b*d)+1//7*x^7*(b*e+c*d)+a*d*x+1//10*c*e*x^10)
@test integrate((d+e*x^3)^-1*(a+b*x^3+c*x^6), x) == :(-1*x*e^-2*(c*d+-1*b*e)+1//4*c*e^-1*x^4+-1//6*d^-2//3*e^-7//3*(a*e^2+c*d^2+-1*b*d*e)*log(d^2//3+e^2//3*x^2+-1*x*d^1//3*e^1//3)+1//3*d^-2//3*e^-7//3*(a*e^2+c*d^2+-1*b*d*e)*log(d^1//3+x*e^1//3)+-1//3*3^(1/2)*d^-2//3*e^-7//3*(a*e^2+c*d^2+-1*b*d*e)*arctan(1//3*3^(1/2)*d^-1//3*(d^1//3+-2*x*e^1//3)))
@test integrate((d+e*x^3)^-2*(a+b*x^3+c*x^6), x) == :(c*x*e^-2+-1//9*d^-5//3*e^-7//3*(-1*e*(b*d+2*a*e)+4*c*d^2)*log(d^1//3+x*e^1//3)+1//18*d^-5//3*e^-7//3*(-1*e*(b*d+2*a*e)+4*c*d^2)*log(d^2//3+e^2//3*x^2+-1*x*d^1//3*e^1//3)+1//3*x*d^-1*e^-2*(d+e*x^3)^-1*(a*e^2+c*d^2+-1*b*d*e)+1//9*3^(1/2)*d^-5//3*e^-7//3*(-1*e*(b*d+2*a*e)+4*c*d^2)*arctan(1//3*3^(1/2)*d^-1//3*(d^1//3+-2*x*e^1//3)))
@test integrate((d+e*x^3)^-3*(a+b*x^3+c*x^6), x) == :(-1//54*d^-8//3*e^-7//3*(e*(b*d+5*a*e)+2*c*d^2)*log(d^2//3+e^2//3*x^2+-1*x*d^1//3*e^1//3)+1//27*d^-8//3*e^-7//3*(e*(b*d+5*a*e)+2*c*d^2)*log(d^1//3+x*e^1//3)+-1//18*x*d^-2*e^-2*(d+e*x^3)^-1*(-1*e*(b*d+5*a*e)+7*c*d^2)+-1//27*3^(1/2)*d^-8//3*e^-7//3*(e*(b*d+5*a*e)+2*c*d^2)*arctan(1//3*3^(1/2)*d^-1//3*(d^1//3+-2*x*e^1//3))+1//6*x*d^-1*e^-2*(d+e*x^3)^-2*(a*e^2+c*d^2+-1*b*d*e))
@test integrate(x^8*(a+b*x^3+c*x^6)^-1*(d+e*x^3), x) == :(-1//6*c^-3*(-1*e*b^2+a*c*e+b*c*d)*log(a+b*x^3+c*x^6)+1//3*c^-2*x^3*(c*d+-1*b*e)+1//6*e*c^-1*x^6+-1//3*c^-3*(b^2+-4*a*c)^-1//2*(-1*e*b^3+c*d*b^2+-2*a*d*c^2+3*a*b*c*e)*arctanh((b^2+-4*a*c)^-1//2*(b+2*c*x^3)))
@test integrate(x^5*(a+b*x^3+c*x^6)^-1*(d+e*x^3), x) == :(1//3*e*c^-1*x^3+1//6*c^-2*(c*d+-1*b*e)*log(a+b*x^3+c*x^6)+1//3*c^-2*(b^2+-4*a*c)^-1//2*(-1*e*b^2+b*c*d+2*a*c*e)*arctanh((b^2+-4*a*c)^-1//2*(b+2*c*x^3)))
@test integrate(x^2*(a+b*x^3+c*x^6)^-1*(d+e*x^3), x) == :(1//6*e*c^-1*log(a+b*x^3+c*x^6)+-1//3*c^-1*(b^2+-4*a*c)^-1//2*(-1*b*e+2*c*d)*arctanh((b^2+-4*a*c)^-1//2*(b+2*c*x^3)))
@test integrate(x^-1*(a+b*x^3+c*x^6)^-1*(d+e*x^3), x) == :(d*a^-1*log(x)+-1//6*d*a^-1*log(a+b*x^3+c*x^6)+1//3*a^-1*(b^2+-4*a*c)^-1//2*(b*d+-2*a*e)*arctanh((b^2+-4*a*c)^-1//2*(b+2*c*x^3)))
@test integrate(x^-4*(a+b*x^3+c*x^6)^-1*(d+e*x^3), x) == :(-1*a^-2*(b*d+-1*a*e)*log(x)+-1//3*d*a^-1*x^-3+1//6*a^-2*(b*d+-1*a*e)*log(a+b*x^3+c*x^6)+-1//3*a^-2*(b^2+-4*a*c)^-1//2*(d*b^2+-1*a*b*e+-2*a*c*d)*arctanh((b^2+-4*a*c)^-1//2*(b+2*c*x^3)))
@test integrate(x^4*(a+b*x^3+c*x^6)^-1*(d+e*x^3), x) == :((1/2)*e*c^-1*x^2+-1//6*2^1//3*c^-5//3*(b+(b^2+-4*a*c)^(1/2))^-1//3*(c*d+(b^2+-4*a*c)^-1//2*(-1*e*b^2+b*c*d+2*a*c*e)+-1*b*e)*log((b+(b^2+-4*a*c)^(1/2))^1//3+x*2^1//3*c^1//3)+-1//6*2^1//3*c^-5//3*(b+-1*(b^2+-4*a*c)^(1/2))^-1//3*(c*d+-1*b*e+-1*(b^2+-4*a*c)^-1//2*(-1*e*b^2+b*c*d+2*a*c*e))*log((b+-1*(b^2+-4*a*c)^(1/2))^1//3+x*2^1//3*c^1//3)+1//12*2^1//3*c^-5//3*(b+(b^2+-4*a*c)^(1/2))^-1//3*(c*d+(b^2+-4*a*c)^-1//2*(-1*e*b^2+b*c*d+2*a*c*e)+-1*b*e)*log((b+(b^2+-4*a*c)^(1/2))^2//3+2^2//3*c^2//3*x^2+-1*x*2^1//3*c^1//3*(b+(b^2+-4*a*c)^(1/2))^1//3)+1//12*2^1//3*c^-5//3*(b+-1*(b^2+-4*a*c)^(1/2))^-1//3*(c*d+-1*b*e+-1*(b^2+-4*a*c)^-1//2*(-1*e*b^2+b*c*d+2*a*c*e))*log((b+-1*(b^2+-4*a*c)^(1/2))^2//3+2^2//3*c^2//3*x^2+-1*x*2^1//3*c^1//3*(b+-1*(b^2+-4*a*c)^(1/2))^1//3)+-1//6*2^1//3*3^(1/2)*c^-5//3*(b+(b^2+-4*a*c)^(1/2))^-1//3*(c*d+(b^2+-4*a*c)^-1//2*(-1*e*b^2+b*c*d+2*a*c*e)+-1*b*e)*arctan(1//3*3^(1/2)*(1+-2*x*2^1//3*c^1//3*(b+(b^2+-4*a*c)^(1/2))^-1//3))+-1//6*2^1//3*3^(1/2)*c^-5//3*(b+-1*(b^2+-4*a*c)^(1/2))^-1//3*(c*d+-1*b*e+-1*(b^2+-4*a*c)^-1//2*(-1*e*b^2+b*c*d+2*a*c*e))*arctan(1//3*3^(1/2)*(1+-2*x*2^1//3*c^1//3*(b+-1*(b^2+-4*a*c)^(1/2))^-1//3)))
@test integrate(x^3*(a+b*x^3+c*x^6)^-1*(d+e*x^3), x) == :(e*x*c^-1+-1//12*2^2//3*c^-4//3*(b+(b^2+-4*a*c)^(1/2))^-2//3*(c*d+(b^2+-4*a*c)^-1//2*(-1*e*b^2+b*c*d+2*a*c*e)+-1*b*e)*log((b+(b^2+-4*a*c)^(1/2))^2//3+2^2//3*c^2//3*x^2+-1*x*2^1//3*c^1//3*(b+(b^2+-4*a*c)^(1/2))^1//3)+-1//12*2^2//3*c^-4//3*(b+-1*(b^2+-4*a*c)^(1/2))^-2//3*(c*d+-1*b*e+-1*(b^2+-4*a*c)^-1//2*(-1*e*b^2+b*c*d+2*a*c*e))*log((b+-1*(b^2+-4*a*c)^(1/2))^2//3+2^2//3*c^2//3*x^2+-1*x*2^1//3*c^1//3*(b+-1*(b^2+-4*a*c)^(1/2))^1//3)+1//6*2^2//3*c^-4//3*(b+(b^2+-4*a*c)^(1/2))^-2//3*(c*d+(b^2+-4*a*c)^-1//2*(-1*e*b^2+b*c*d+2*a*c*e)+-1*b*e)*log((b+(b^2+-4*a*c)^(1/2))^1//3+x*2^1//3*c^1//3)+1//6*2^2//3*c^-4//3*(b+-1*(b^2+-4*a*c)^(1/2))^-2//3*(c*d+-1*b*e+-1*(b^2+-4*a*c)^-1//2*(-1*e*b^2+b*c*d+2*a*c*e))*log((b+-1*(b^2+-4*a*c)^(1/2))^1//3+x*2^1//3*c^1//3)+-1//6*2^2//3*3^(1/2)*c^-4//3*(b+(b^2+-4*a*c)^(1/2))^-2//3*(c*d+(b^2+-4*a*c)^-1//2*(-1*e*b^2+b*c*d+2*a*c*e)+-1*b*e)*arctan(1//3*3^(1/2)*(1+-2*x*2^1//3*c^1//3*(b+(b^2+-4*a*c)^(1/2))^-1//3))+-1//6*2^2//3*3^(1/2)*c^-4//3*(b+-1*(b^2+-4*a*c)^(1/2))^-2//3*(c*d+-1*b*e+-1*(b^2+-4*a*c)^-1//2*(-1*e*b^2+b*c*d+2*a*c*e))*arctan(1//3*3^(1/2)*(1+-2*x*2^1//3*c^1//3*(b+-1*(b^2+-4*a*c)^(1/2))^-1//3)))
@test integrate(x*(a+b*x^3+c*x^6)^-1*(d+e*x^3), x) == :(-1//6*2^1//3*c^-2//3*(b+(b^2+-4*a*c)^(1/2))^-1//3*(e+-1*(b^2+-4*a*c)^-1//2*(-1*b*e+2*c*d))*log((b+(b^2+-4*a*c)^(1/2))^1//3+x*2^1//3*c^1//3)+-1//6*2^1//3*c^-2//3*(b+-1*(b^2+-4*a*c)^(1/2))^-1//3*(e+(b^2+-4*a*c)^-1//2*(-1*b*e+2*c*d))*log((b+-1*(b^2+-4*a*c)^(1/2))^1//3+x*2^1//3*c^1//3)+1//12*2^1//3*c^-2//3*(b+(b^2+-4*a*c)^(1/2))^-1//3*(e+-1*(b^2+-4*a*c)^-1//2*(-1*b*e+2*c*d))*log((b+(b^2+-4*a*c)^(1/2))^2//3+2^2//3*c^2//3*x^2+-1*x*2^1//3*c^1//3*(b+(b^2+-4*a*c)^(1/2))^1//3)+1//12*2^1//3*c^-2//3*(b+-1*(b^2+-4*a*c)^(1/2))^-1//3*(e+(b^2+-4*a*c)^-1//2*(-1*b*e+2*c*d))*log((b+-1*(b^2+-4*a*c)^(1/2))^2//3+2^2//3*c^2//3*x^2+-1*x*2^1//3*c^1//3*(b+-1*(b^2+-4*a*c)^(1/2))^1//3)+-1//6*2^1//3*3^(1/2)*c^-2//3*(b+(b^2+-4*a*c)^(1/2))^-1//3*(e+-1*(b^2+-4*a*c)^-1//2*(-1*b*e+2*c*d))*arctan(1//3*3^(1/2)*(1+-2*x*2^1//3*c^1//3*(b+(b^2+-4*a*c)^(1/2))^-1//3))+-1//6*2^1//3*3^(1/2)*c^-2//3*(b+-1*(b^2+-4*a*c)^(1/2))^-1//3*(e+(b^2+-4*a*c)^-1//2*(-1*b*e+2*c*d))*arctan(1//3*3^(1/2)*(1+-2*x*2^1//3*c^1//3*(b+-1*(b^2+-4*a*c)^(1/2))^-1//3)))
@test integrate((a+b*x^3+c*x^6)^-1*(d+e*x^3), x) == :(-1//12*2^2//3*c^-1//3*(b+(b^2+-4*a*c)^(1/2))^-2//3*(e+-1*(b^2+-4*a*c)^-1//2*(-1*b*e+2*c*d))*log((b+(b^2+-4*a*c)^(1/2))^2//3+2^2//3*c^2//3*x^2+-1*x*2^1//3*c^1//3*(b+(b^2+-4*a*c)^(1/2))^1//3)+-1//12*2^2//3*c^-1//3*(b+-1*(b^2+-4*a*c)^(1/2))^-2//3*(e+(b^2+-4*a*c)^-1//2*(-1*b*e+2*c*d))*log((b+-1*(b^2+-4*a*c)^(1/2))^2//3+2^2//3*c^2//3*x^2+-1*x*2^1//3*c^1//3*(b+-1*(b^2+-4*a*c)^(1/2))^1//3)+1//6*2^2//3*c^-1//3*(b+(b^2+-4*a*c)^(1/2))^-2//3*(e+-1*(b^2+-4*a*c)^-1//2*(-1*b*e+2*c*d))*log((b+(b^2+-4*a*c)^(1/2))^1//3+x*2^1//3*c^1//3)+1//6*2^2//3*c^-1//3*(b+-1*(b^2+-4*a*c)^(1/2))^-2//3*(e+(b^2+-4*a*c)^-1//2*(-1*b*e+2*c*d))*log((b+-1*(b^2+-4*a*c)^(1/2))^1//3+x*2^1//3*c^1//3)+-1//6*2^2//3*3^(1/2)*c^-1//3*(b+(b^2+-4*a*c)^(1/2))^-2//3*(e+-1*(b^2+-4*a*c)^-1//2*(-1*b*e+2*c*d))*arctan(1//3*3^(1/2)*(1+-2*x*2^1//3*c^1//3*(b+(b^2+-4*a*c)^(1/2))^-1//3))+-1//6*2^2//3*3^(1/2)*c^-1//3*(b+-1*(b^2+-4*a*c)^(1/2))^-2//3*(e+(b^2+-4*a*c)^-1//2*(-1*b*e+2*c*d))*arctan(1//3*3^(1/2)*(1+-2*x*2^1//3*c^1//3*(b+-1*(b^2+-4*a*c)^(1/2))^-1//3)))
@test integrate(x^-2*(a+b*x^3+c*x^6)^-1*(d+e*x^3), x) == :(-1*d*a^-1*x^-1+-1//12*2^1//3*a^-1*c^1//3*(b+(b^2+-4*a*c)^(1/2))^-1//3*(d+-1*(b^2+-4*a*c)^-1//2*(b*d+-2*a*e))*log((b+(b^2+-4*a*c)^(1/2))^2//3+2^2//3*c^2//3*x^2+-1*x*2^1//3*c^1//3*(b+(b^2+-4*a*c)^(1/2))^1//3)+-1//12*2^1//3*a^-1*c^1//3*(b+-1*(b^2+-4*a*c)^(1/2))^-1//3*(d+(b^2+-4*a*c)^-1//2*(b*d+-2*a*e))*log((b+-1*(b^2+-4*a*c)^(1/2))^2//3+2^2//3*c^2//3*x^2+-1*x*2^1//3*c^1//3*(b+-1*(b^2+-4*a*c)^(1/2))^1//3)+1//6*2^1//3*a^-1*c^1//3*(b+(b^2+-4*a*c)^(1/2))^-1//3*(d+-1*(b^2+-4*a*c)^-1//2*(b*d+-2*a*e))*log((b+(b^2+-4*a*c)^(1/2))^1//3+x*2^1//3*c^1//3)+1//6*2^1//3*a^-1*c^1//3*(b+-1*(b^2+-4*a*c)^(1/2))^-1//3*(d+(b^2+-4*a*c)^-1//2*(b*d+-2*a*e))*log((b+-1*(b^2+-4*a*c)^(1/2))^1//3+x*2^1//3*c^1//3)+1//6*2^1//3*3^(1/2)*a^-1*c^1//3*(b+(b^2+-4*a*c)^(1/2))^-1//3*(d+-1*(b^2+-4*a*c)^-1//2*(b*d+-2*a*e))*arctan(1//3*3^(1/2)*(1+-2*x*2^1//3*c^1//3*(b+(b^2+-4*a*c)^(1/2))^-1//3))+1//6*2^1//3*3^(1/2)*a^-1*c^1//3*(b+-1*(b^2+-4*a*c)^(1/2))^-1//3*(d+(b^2+-4*a*c)^-1//2*(b*d+-2*a*e))*arctan(1//3*3^(1/2)*(1+-2*x*2^1//3*c^1//3*(b+-1*(b^2+-4*a*c)^(1/2))^-1//3)))
@test integrate(x^-3*(a+b*x^3+c*x^6)^-1*(d+e*x^3), x) == :(-1//2*d*a^-1*x^-2+-1//6*2^2//3*a^-1*c^2//3*(b+(b^2+-4*a*c)^(1/2))^-2//3*(d+-1*(b^2+-4*a*c)^-1//2*(b*d+-2*a*e))*log((b+(b^2+-4*a*c)^(1/2))^1//3+x*2^1//3*c^1//3)+-1//6*2^2//3*a^-1*c^2//3*(b+-1*(b^2+-4*a*c)^(1/2))^-2//3*(d+(b^2+-4*a*c)^-1//2*(b*d+-2*a*e))*log((b+-1*(b^2+-4*a*c)^(1/2))^1//3+x*2^1//3*c^1//3)+1//12*2^2//3*a^-1*c^2//3*(b+(b^2+-4*a*c)^(1/2))^-2//3*(d+-1*(b^2+-4*a*c)^-1//2*(b*d+-2*a*e))*log((b+(b^2+-4*a*c)^(1/2))^2//3+2^2//3*c^2//3*x^2+-1*x*2^1//3*c^1//3*(b+(b^2+-4*a*c)^(1/2))^1//3)+1//12*2^2//3*a^-1*c^2//3*(b+-1*(b^2+-4*a*c)^(1/2))^-2//3*(d+(b^2+-4*a*c)^-1//2*(b*d+-2*a*e))*log((b+-1*(b^2+-4*a*c)^(1/2))^2//3+2^2//3*c^2//3*x^2+-1*x*2^1//3*c^1//3*(b+-1*(b^2+-4*a*c)^(1/2))^1//3)+1//6*2^2//3*3^(1/2)*a^-1*c^2//3*(b+(b^2+-4*a*c)^(1/2))^-2//3*(d+-1*(b^2+-4*a*c)^-1//2*(b*d+-2*a*e))*arctan(1//3*3^(1/2)*(1+-2*x*2^1//3*c^1//3*(b+(b^2+-4*a*c)^(1/2))^-1//3))+1//6*2^2//3*3^(1/2)*a^-1*c^2//3*(b+-1*(b^2+-4*a*c)^(1/2))^-2//3*(d+(b^2+-4*a*c)^-1//2*(b*d+-2*a*e))*arctan(1//3*3^(1/2)*(1+-2*x*2^1//3*c^1//3*(b+-1*(b^2+-4*a*c)^(1/2))^-1//3)))
@test integrate(x^8*(1+x^6+-1*x^3)^-1*(1+-1*x^3), x) == :(-1//6*x^6+1//6*log(1+x^6+-1*x^3)+-1//9*3^(1/2)*arctan(1//3*3^(1/2)*(1+-2*x^3)))
@test integrate(x^5*(1+x^6+-1*x^3)^-1*(1+-1*x^3), x) == :(-1//3*x^3+-2//9*3^(1/2)*arctan(1//3*3^(1/2)*(1+-2*x^3)))
@test integrate(x^2*(1+x^6+-1*x^3)^-1*(1+-1*x^3), x) == :(-1//6*log(1+x^6+-1*x^3)+-1//9*3^(1/2)*arctan(1//3*3^(1/2)*(1+-2*x^3)))
@test integrate(x^-1*(1+x^6+-1*x^3)^-1*(1+-1*x^3), x) == :(-1//6*log(1+x^6+-1*x^3)+1//9*3^(1/2)*arctan(1//3*3^(1/2)*(1+-2*x^3))+log(x))
@test integrate(x^-4*(1+x^6+-1*x^3)^-1*(1+-1*x^3), x) == :(-1//3*x^-3+2//9*3^(1/2)*arctan(1//3*3^(1/2)*(1+-2*x^3)))
@test integrate(x^6*(1+x^6+-1*x^3)^-1*(1+-1*x^3), x) == :(-1//4*x^4+-1//6*2^2//3*(1+-1*im*3^(1/2))^-2//3*(im+3^(1/2))*arctan(1//3*3^(1/2)*(1+2*x*(1/2+-1//2*im*3^(1/2))^-1//3))+-1//36*2^2//3*(1+im*3^(1/2))^-2//3*(3+-1*im*3^(1/2))*log((1+im*3^(1/2))^2//3+x*(2+2*im*3^(1/2))^1//3+2^2//3*x^2)+-1//36*2^2//3*(1+-1*im*3^(1/2))^-2//3*(3+im*3^(1/2))*log((1+-1*im*3^(1/2))^2//3+x*(2+-2*im*3^(1/2))^1//3+2^2//3*x^2)+1//6*2^2//3*(1+im*3^(1/2))^-2//3*(im+-1*3^(1/2))*arctan(1//3*3^(1/2)*(1+2*x*(1/2+(1/2)*im*3^(1/2))^-1//3))+1//18*2^2//3*(1+im*3^(1/2))^-2//3*(3+-1*im*3^(1/2))*log((1+im*3^(1/2))^1//3+-1*x*2^1//3)+1//18*2^2//3*(1+-1*im*3^(1/2))^-2//3*(3+im*3^(1/2))*log((1+-1*im*3^(1/2))^1//3+-1*x*2^1//3))
@test integrate(x^4*(1+x^6+-1*x^3)^-1*(1+-1*x^3), x) == :(-1//2*x^2+-1//3*im*(1/2+(1/2)*im*3^(1/2))^-1//3*arctan(1//3*3^(1/2)*(1+2*x*(1/2+(1/2)*im*3^(1/2))^-1//3))+1//3*im*(1/2+-1//2*im*3^(1/2))^-1//3*arctan(1//3*3^(1/2)*(1+2*x*(1/2+-1//2*im*3^(1/2))^-1//3))+-1//9*im*3^(1/2)*(1/2+(1/2)*im*3^(1/2))^-1//3*log((1+im*3^(1/2))^1//3+-1*x*2^1//3)+1//9*im*3^(1/2)*(1/2+-1//2*im*3^(1/2))^-1//3*log((1+-1*im*3^(1/2))^1//3+-1*x*2^1//3)+-1//18*im*2^1//3*3^(1/2)*(1+-1*im*3^(1/2))^-1//3*log((1+-1*im*3^(1/2))^2//3+x*(2+-2*im*3^(1/2))^1//3+2^2//3*x^2)+1//18*im*2^1//3*3^(1/2)*(1+im*3^(1/2))^-1//3*log((1+im*3^(1/2))^2//3+x*(2+2*im*3^(1/2))^1//3+2^2//3*x^2))
@test integrate(x^3*(1+x^6+-1*x^3)^-1*(1+-1*x^3), x) == :(-1x+-1//3*im*(1/2+-1//2*im*3^(1/2))^-2//3*arctan(1//3*3^(1/2)*(1+2*x*(1/2+-1//2*im*3^(1/2))^-1//3))+1//3*im*(1/2+(1/2)*im*3^(1/2))^-2//3*arctan(1//3*3^(1/2)*(1+2*x*(1/2+(1/2)*im*3^(1/2))^-1//3))+-1//9*im*3^(1/2)*(1/2+(1/2)*im*3^(1/2))^-2//3*log((1+im*3^(1/2))^1//3+-1*x*2^1//3)+1//9*im*3^(1/2)*(1/2+-1//2*im*3^(1/2))^-2//3*log((1+-1*im*3^(1/2))^1//3+-1*x*2^1//3)+-1//18*im*2^2//3*3^(1/2)*(1+-1*im*3^(1/2))^-2//3*log((1+-1*im*3^(1/2))^2//3+x*(2+-2*im*3^(1/2))^1//3+2^2//3*x^2)+1//18*im*2^2//3*3^(1/2)*(1+im*3^(1/2))^-2//3*log((1+im*3^(1/2))^2//3+x*(2+2*im*3^(1/2))^1//3+2^2//3*x^2))
@test integrate(x*(1+x^6+-1*x^3)^-1*(1+-1*x^3), x) == :(-1//6*2^1//3*(1+im*3^(1/2))^-1//3*(im+3^(1/2))*arctan(1//3*3^(1/2)*(1+2*x*(1/2+(1/2)*im*3^(1/2))^-1//3))+-1//18*2^1//3*(1+im*3^(1/2))^-1//3*(3+im*3^(1/2))*log((1+im*3^(1/2))^1//3+-1*x*2^1//3)+-1//18*2^1//3*(1+-1*im*3^(1/2))^-1//3*(3+-1*im*3^(1/2))*log((1+-1*im*3^(1/2))^1//3+-1*x*2^1//3)+1//6*2^1//3*(1+-1*im*3^(1/2))^-1//3*(im+-1*3^(1/2))*arctan(1//3*3^(1/2)*(1+2*x*(1/2+-1//2*im*3^(1/2))^-1//3))+1//36*2^1//3*(1+im*3^(1/2))^-1//3*(3+im*3^(1/2))*log((1+im*3^(1/2))^2//3+x*(2+2*im*3^(1/2))^1//3+2^2//3*x^2)+1//36*2^1//3*(1+-1*im*3^(1/2))^-1//3*(3+-1*im*3^(1/2))*log((1+-1*im*3^(1/2))^2//3+x*(2+-2*im*3^(1/2))^1//3+2^2//3*x^2))
@test integrate((1+x^6+-1*x^3)^-1*(1+-1*x^3), x) == :(-1//6*2^2//3*(1+-1*im*3^(1/2))^-2//3*(im+-1*3^(1/2))*arctan(1//3*3^(1/2)*(1+2*x*(1/2+-1//2*im*3^(1/2))^-1//3))+-1//18*2^2//3*(1+im*3^(1/2))^-2//3*(3+im*3^(1/2))*log((1+im*3^(1/2))^1//3+-1*x*2^1//3)+-1//18*2^2//3*(1+-1*im*3^(1/2))^-2//3*(3+-1*im*3^(1/2))*log((1+-1*im*3^(1/2))^1//3+-1*x*2^1//3)+1//6*2^2//3*(1+im*3^(1/2))^-2//3*(im+3^(1/2))*arctan(1//3*3^(1/2)*(1+2*x*(1/2+(1/2)*im*3^(1/2))^-1//3))+1//36*2^2//3*(1+im*3^(1/2))^-2//3*(3+im*3^(1/2))*log((1+im*3^(1/2))^2//3+x*(2+2*im*3^(1/2))^1//3+2^2//3*x^2)+1//36*2^2//3*(1+-1*im*3^(1/2))^-2//3*(3+-1*im*3^(1/2))*log((1+-1*im*3^(1/2))^2//3+x*(2+-2*im*3^(1/2))^1//3+2^2//3*x^2))
@test integrate(x^-2*(1+x^6+-1*x^3)^-1*(1+-1*x^3), x) == :(-1*x^-1+-1//6*2^1//3*(1+-1*im*3^(1/2))^-1//3*(im+3^(1/2))*arctan(1//3*3^(1/2)*(1+2*x*(1/2+-1//2*im*3^(1/2))^-1//3))+-1//18*2^1//3*(1+im*3^(1/2))^-1//3*(3+-1*im*3^(1/2))*log((1+im*3^(1/2))^1//3+-1*x*2^1//3)+-1//18*2^1//3*(1+-1*im*3^(1/2))^-1//3*(3+im*3^(1/2))*log((1+-1*im*3^(1/2))^1//3+-1*x*2^1//3)+1//6*2^1//3*(1+im*3^(1/2))^-1//3*(im+-1*3^(1/2))*arctan(1//3*3^(1/2)*(1+2*x*(1/2+(1/2)*im*3^(1/2))^-1//3))+1//36*2^1//3*(1+im*3^(1/2))^-1//3*(3+-1*im*3^(1/2))*log((1+im*3^(1/2))^2//3+x*(2+2*im*3^(1/2))^1//3+2^2//3*x^2)+1//36*2^1//3*(1+-1*im*3^(1/2))^-1//3*(3+im*3^(1/2))*log((1+-1*im*3^(1/2))^2//3+x*(2+-2*im*3^(1/2))^1//3+2^2//3*x^2))
@test integrate(x^-3*(1+x^6+-1*x^3)^-1*(1+-1*x^3), x) == :(-1//2*x^-2+-1//6*2^2//3*(1+im*3^(1/2))^-2//3*(im+-1*3^(1/2))*arctan(1//3*3^(1/2)*(1+2*x*(1/2+(1/2)*im*3^(1/2))^-1//3))+-1//18*2^2//3*(1+im*3^(1/2))^-2//3*(3+-1*im*3^(1/2))*log((1+im*3^(1/2))^1//3+-1*x*2^1//3)+-1//18*2^2//3*(1+-1*im*3^(1/2))^-2//3*(3+im*3^(1/2))*log((1+-1*im*3^(1/2))^1//3+-1*x*2^1//3)+1//6*2^2//3*(1+-1*im*3^(1/2))^-2//3*(im+3^(1/2))*arctan(1//3*3^(1/2)*(1+2*x*(1/2+-1//2*im*3^(1/2))^-1//3))+1//36*2^2//3*(1+im*3^(1/2))^-2//3*(3+-1*im*3^(1/2))*log((1+im*3^(1/2))^2//3+x*(2+2*im*3^(1/2))^1//3+2^2//3*x^2)+1//36*2^2//3*(1+-1*im*3^(1/2))^-2//3*(3+im*3^(1/2))*log((1+-1*im*3^(1/2))^2//3+x*(2+-2*im*3^(1/2))^1//3+2^2//3*x^2))
@test integrate(x^2*(1+x^6+-1*x^3)^-1*(-2+x^3), x) == :(1//6*log(1+x^6+-1*x^3)+1//3*3^(1/2)*arctan(1//3*3^(1/2)*(1+-2*x^3)))
@test integrate(x^-1*(1+x^6+-1*x^3)^-1*(1+x^3), x) == :(-1//6*log(1+x^6+-1*x^3)+-1//3*3^(1/2)*arctan(1//3*3^(1/2)*(1+-2*x^3))+log(x))
@test integrate((x+x^7+-1*x^4)^-1*(1+x^3), x) == :(-1//6*log(1+x^6+-1*x^3)+-1//3*3^(1/2)*arctan(1//3*3^(1/2)*(1+-2*x^3))+log(x))
@test integrate((d+e*x^3)^5//2*(a+b*x^3+c*x^6), x) == :(-1//667*x*e^-2*(d+e*x^3)^7//2*(-58*b*e+16*c*d)+1//11339*x*e^-2*(d+e*x^3)^5//2*(32*c*d^2+1334*a*e^2+-116*b*d*e)+2//29*c*e^-1*x^4*(d+e*x^3)^7//2+30//124729*d*x*e^-2*(d+e*x^3)^3//2*(16*c*d^2+667*a*e^2+-58*b*d*e)+54//124729*x*d^2*e^-2*(d+e*x^3)^(1/2)*(16*c*d^2+667*a*e^2+-58*b*d*e)+54//124729*3^3//4*d^3*e^-7//3*((x*e^1//3+d^1//3*(1+3^(1/2)))^-2*(d^2//3+e^2//3*x^2+-1*x*d^1//3*e^1//3))^(1/2)*(d^1//3*(x*e^1//3+d^1//3*(1+3^(1/2)))^-2*(d^1//3+x*e^1//3))^-1//2*(2+3^(1/2))^(1/2)*(d+e*x^3)^-1//2*(d^1//3+x*e^1//3)*(16*c*d^2+667*a*e^2+-58*b*d*e)*Elliptic.F(arcsin((x*e^1//3+d^1//3*(1+3^(1/2)))^-1*(x*e^1//3+d^1//3*(1+-1*3^(1/2)))),-7+-4*3^(1/2)))
@test integrate((d+e*x^3)^3//2*(a+b*x^3+c*x^6), x) == :(-1//391*x*e^-2*(d+e*x^3)^5//2*(-46*b*e+16*c*d)+1//4301*x*e^-2*(d+e*x^3)^3//2*(32*c*d^2+782*a*e^2+-92*b*d*e)+2//23*c*e^-1*x^4*(d+e*x^3)^5//2+18//21505*d*x*e^-2*(d+e*x^3)^(1/2)*(16*c*d^2+391*a*e^2+-46*b*d*e)+18//21505*3^3//4*d^2*e^-7//3*((x*e^1//3+d^1//3*(1+3^(1/2)))^-2*(d^2//3+e^2//3*x^2+-1*x*d^1//3*e^1//3))^(1/2)*(d^1//3*(x*e^1//3+d^1//3*(1+3^(1/2)))^-2*(d^1//3+x*e^1//3))^-1//2*(2+3^(1/2))^(1/2)*(d+e*x^3)^-1//2*(d^1//3+x*e^1//3)*(16*c*d^2+391*a*e^2+-46*b*d*e)*Elliptic.F(arcsin((x*e^1//3+d^1//3*(1+3^(1/2)))^-1*(x*e^1//3+d^1//3*(1+-1*3^(1/2)))),-7+-4*3^(1/2)))
@test integrate((d+e*x^3)^(1/2)*(a+b*x^3+c*x^6), x) == :(-1//187*x*e^-2*(d+e*x^3)^3//2*(-34*b*e+16*c*d)+1//935*x*e^-2*(d+e*x^3)^(1/2)*(32*c*d^2+374*a*e^2+-68*b*d*e)+2//17*c*e^-1*x^4*(d+e*x^3)^3//2+2//935*d*3^3//4*e^-7//3*((x*e^1//3+d^1//3*(1+3^(1/2)))^-2*(d^2//3+e^2//3*x^2+-1*x*d^1//3*e^1//3))^(1/2)*(d^1//3*(x*e^1//3+d^1//3*(1+3^(1/2)))^-2*(d^1//3+x*e^1//3))^-1//2*(2+3^(1/2))^(1/2)*(d+e*x^3)^-1//2*(d^1//3+x*e^1//3)*(16*c*d^2+187*a*e^2+-34*b*d*e)*Elliptic.F(arcsin((x*e^1//3+d^1//3*(1+3^(1/2)))^-1*(x*e^1//3+d^1//3*(1+-1*3^(1/2)))),-7+-4*3^(1/2)))
@test integrate((d+e*x^3)^-1//2*(a+b*x^3+c*x^6), x) == :(-1//55*x*e^-2*(d+e*x^3)^(1/2)*(-22*b*e+16*c*d)+2//11*c*e^-1*x^4*(d+e*x^3)^(1/2)+2//165*3^3//4*e^-7//3*((x*e^1//3+d^1//3*(1+3^(1/2)))^-2*(d^2//3+e^2//3*x^2+-1*x*d^1//3*e^1//3))^(1/2)*(d^1//3*(x*e^1//3+d^1//3*(1+3^(1/2)))^-2*(d^1//3+x*e^1//3))^-1//2*(2+3^(1/2))^(1/2)*(d+e*x^3)^-1//2*(d^1//3+x*e^1//3)*(16*c*d^2+55*a*e^2+-22*b*d*e)*Elliptic.F(arcsin((x*e^1//3+d^1//3*(1+3^(1/2)))^-1*(x*e^1//3+d^1//3*(1+-1*3^(1/2)))),-7+-4*3^(1/2)))
@test integrate((d+e*x^3)^-3//2*(a+b*x^3+c*x^6), x) == :(2//5*c*x*e^-2*(d+e*x^3)^(1/2)+1//3*x*d^-1*e^-2*(d+e*x^3)^-1//2*(2*a*e^2+2*c*d^2+-2*b*d*e)+-2//45*3^3//4*d^-1*e^-7//3*((x*e^1//3+d^1//3*(1+3^(1/2)))^-2*(d^2//3+e^2//3*x^2+-1*x*d^1//3*e^1//3))^(1/2)*(d^1//3*(x*e^1//3+d^1//3*(1+3^(1/2)))^-2*(d^1//3+x*e^1//3))^-1//2*(2+3^(1/2))^(1/2)*(d+e*x^3)^-1//2*(d^1//3+x*e^1//3)*(-5*e*(a*e+2*b*d)+16*c*d^2)*Elliptic.F(arcsin((x*e^1//3+d^1//3*(1+3^(1/2)))^-1*(x*e^1//3+d^1//3*(1+-1*3^(1/2)))),-7+-4*3^(1/2)))
@test integrate((d+e*x^3)^-5//2*(a+b*x^3+c*x^6), x) == :(-1//27*x*d^-2*e^-2*(d+e*x^3)^-1//2*(-14*a*e^2+22*c*d^2+-4*b*d*e)+1//9*x*d^-1*e^-2*(d+e*x^3)^-3//2*(2*a*e^2+2*c*d^2+-2*b*d*e)+2//81*3^3//4*d^-2*e^-7//3*((x*e^1//3+d^1//3*(1+3^(1/2)))^-2*(d^2//3+e^2//3*x^2+-1*x*d^1//3*e^1//3))^(1/2)*(d^1//3*(x*e^1//3+d^1//3*(1+3^(1/2)))^-2*(d^1//3+x*e^1//3))^-1//2*(2+3^(1/2))^(1/2)*(d+e*x^3)^-1//2*(d^1//3+x*e^1//3)*(e*(2*b*d+7*a*e)+16*c*d^2)*Elliptic.F(arcsin((x*e^1//3+d^1//3*(1+3^(1/2)))^-1*(x*e^1//3+d^1//3*(1+-1*3^(1/2)))),-7+-4*3^(1/2)))
@test integrate((d+e*x^3)^-7//2*(a+b*x^3+c*x^6), x) == :(-1//135*x*d^-2*e^-2*(d+e*x^3)^-3//2*(-26*a*e^2+34*c*d^2+-4*b*d*e)+1//15*x*d^-1*e^-2*(d+e*x^3)^-5//2*(2*a*e^2+2*c*d^2+-2*b*d*e)+1//405*x*d^-3*e^-2*(d+e*x^3)^-1//2*(32*c*d^2+182*a*e^2+28*b*d*e)+2//1215*3^3//4*d^-3*e^-7//3*((x*e^1//3+d^1//3*(1+3^(1/2)))^-2*(d^2//3+e^2//3*x^2+-1*x*d^1//3*e^1//3))^(1/2)*(d^1//3*(x*e^1//3+d^1//3*(1+3^(1/2)))^-2*(d^1//3+x*e^1//3))^-1//2*(2+3^(1/2))^(1/2)*(d+e*x^3)^-1//2*(d^1//3+x*e^1//3)*(16*c*d^2+91*a*e^2+14*b*d*e)*Elliptic.F(arcsin((x*e^1//3+d^1//3*(1+3^(1/2)))^-1*(x*e^1//3+d^1//3*(1+-1*3^(1/2)))),-7+-4*3^(1/2)))
@test integrate((d+e*x^3)^-9//2*(a+b*x^3+c*x^6), x) == :(-1//315*x*d^-2*e^-2*(d+e*x^3)^-5//2*(-38*a*e^2+46*c*d^2+-4*b*d*e)+1//21*x*d^-1*e^-2*(d+e*x^3)^-7//2*(2*a*e^2+2*c*d^2+-2*b*d*e)+1//1215*x*d^-4*e^-2*(d+e*x^3)^-1//2*(32*c*d^2+494*a*e^2+52*b*d*e)+1//2835*x*d^-3*e^-2*(d+e*x^3)^-3//2*(32*c*d^2+494*a*e^2+52*b*d*e)+2//3645*3^3//4*d^-4*e^-7//3*((x*e^1//3+d^1//3*(1+3^(1/2)))^-2*(d^2//3+e^2//3*x^2+-1*x*d^1//3*e^1//3))^(1/2)*(d^1//3*(x*e^1//3+d^1//3*(1+3^(1/2)))^-2*(d^1//3+x*e^1//3))^-1//2*(2+3^(1/2))^(1/2)*(d+e*x^3)^-1//2*(d^1//3+x*e^1//3)*(16*c*d^2+247*a*e^2+26*b*d*e)*Elliptic.F(arcsin((x*e^1//3+d^1//3*(1+3^(1/2)))^-1*(x*e^1//3+d^1//3*(1+-1*3^(1/2)))),-7+-4*3^(1/2)))
@test integrate(x^4*(a+b*x^4+c*x^8)^-1*(d+e*x^4), x) == :(e*x*c^-1+-1//4*2^3//4*c^-5//4*((b^2+-4*a*c)^(1/2)+-1b)^-3//4*(c*d+-1*b*e+-1*(b^2+-4*a*c)^-1//2*(-1*e*b^2+b*c*d+2*a*c*e))*arctan(x*2^1//4*c^1//4*((b^2+-4*a*c)^(1/2)+-1b)^-1//4)+-1//4*2^3//4*c^-5//4*((b^2+-4*a*c)^(1/2)+-1b)^-3//4*(c*d+-1*b*e+-1*(b^2+-4*a*c)^-1//2*(-1*e*b^2+b*c*d+2*a*c*e))*arctanh(x*2^1//4*c^1//4*((b^2+-4*a*c)^(1/2)+-1b)^-1//4)+-1//4*2^3//4*c^-5//4*(-1b+-1*(b^2+-4*a*c)^(1/2))^-3//4*(c*d+(b^2+-4*a*c)^-1//2*(-1*e*b^2+b*c*d+2*a*c*e)+-1*b*e)*arctan(x*2^1//4*c^1//4*(-1b+-1*(b^2+-4*a*c)^(1/2))^-1//4)+-1//4*2^3//4*c^-5//4*(-1b+-1*(b^2+-4*a*c)^(1/2))^-3//4*(c*d+(b^2+-4*a*c)^-1//2*(-1*e*b^2+b*c*d+2*a*c*e)+-1*b*e)*arctanh(x*2^1//4*c^1//4*(-1b+-1*(b^2+-4*a*c)^(1/2))^-1//4))
@test integrate(x^3*(a+b*x^4+c*x^8)^-1*(d+e*x^4), x) == :(1//8*e*c^-1*log(a+b*x^4+c*x^8)+-1//4*c^-1*(b^2+-4*a*c)^-1//2*(-1*b*e+2*c*d)*arctanh((b^2+-4*a*c)^-1//2*(b+2*c*x^4)))
@test integrate(x^2*(a+b*x^4+c*x^8)^-1*(d+e*x^4), x) == :(-1//4*2^1//4*c^-3//4*((b^2+-4*a*c)^(1/2)+-1b)^-1//4*(e+(b^2+-4*a*c)^-1//2*(-1*b*e+2*c*d))*arctanh(x*2^1//4*c^1//4*((b^2+-4*a*c)^(1/2)+-1b)^-1//4)+-1//4*2^1//4*c^-3//4*(-1b+-1*(b^2+-4*a*c)^(1/2))^-1//4*(e+-1*(b^2+-4*a*c)^-1//2*(-1*b*e+2*c*d))*arctanh(x*2^1//4*c^1//4*(-1b+-1*(b^2+-4*a*c)^(1/2))^-1//4)+1//4*2^1//4*c^-3//4*((b^2+-4*a*c)^(1/2)+-1b)^-1//4*(e+(b^2+-4*a*c)^-1//2*(-1*b*e+2*c*d))*arctan(x*2^1//4*c^1//4*((b^2+-4*a*c)^(1/2)+-1b)^-1//4)+1//4*2^1//4*c^-3//4*(-1b+-1*(b^2+-4*a*c)^(1/2))^-1//4*(e+-1*(b^2+-4*a*c)^-1//2*(-1*b*e+2*c*d))*arctan(x*2^1//4*c^1//4*(-1b+-1*(b^2+-4*a*c)^(1/2))^-1//4))
@test integrate(x*(a+b*x^4+c*x^8)^-1*(d+e*x^4), x) == :(1//4*2^(1/2)*c^-1//2*(b+(b^2+-4*a*c)^(1/2))^-1//2*(e+-1*(b^2+-4*a*c)^-1//2*(-1*b*e+2*c*d))*arctan(2^(1/2)*c^(1/2)*x^2*(b+(b^2+-4*a*c)^(1/2))^-1//2)+1//4*2^(1/2)*c^-1//2*(b+-1*(b^2+-4*a*c)^(1/2))^-1//2*(e+(b^2+-4*a*c)^-1//2*(-1*b*e+2*c*d))*arctan(2^(1/2)*c^(1/2)*x^2*(b+-1*(b^2+-4*a*c)^(1/2))^-1//2))
@test integrate((a+b*x^4+c*x^8)^-1*(d+e*x^4), x) == :(-1//4*2^3//4*c^-1//4*((b^2+-4*a*c)^(1/2)+-1b)^-3//4*(e+(b^2+-4*a*c)^-1//2*(-1*b*e+2*c*d))*arctan(x*2^1//4*c^1//4*((b^2+-4*a*c)^(1/2)+-1b)^-1//4)+-1//4*2^3//4*c^-1//4*((b^2+-4*a*c)^(1/2)+-1b)^-3//4*(e+(b^2+-4*a*c)^-1//2*(-1*b*e+2*c*d))*arctanh(x*2^1//4*c^1//4*((b^2+-4*a*c)^(1/2)+-1b)^-1//4)+-1//4*2^3//4*c^-1//4*(-1b+-1*(b^2+-4*a*c)^(1/2))^-3//4*(e+-1*(b^2+-4*a*c)^-1//2*(-1*b*e+2*c*d))*arctan(x*2^1//4*c^1//4*(-1b+-1*(b^2+-4*a*c)^(1/2))^-1//4)+-1//4*2^3//4*c^-1//4*(-1b+-1*(b^2+-4*a*c)^(1/2))^-3//4*(e+-1*(b^2+-4*a*c)^-1//2*(-1*b*e+2*c*d))*arctanh(x*2^1//4*c^1//4*(-1b+-1*(b^2+-4*a*c)^(1/2))^-1//4))
@test integrate(x^-1*(a+b*x^4+c*x^8)^-1*(d+e*x^4), x) == :(d*a^-1*log(x)+-1//8*d*a^-1*log(a+b*x^4+c*x^8)+1//4*a^-1*(b^2+-4*a*c)^-1//2*(b*d+-2*a*e)*arctanh((b^2+-4*a*c)^-1//2*(b+2*c*x^4)))
@test integrate(x^-2*(a+b*x^4+c*x^8)^-1*(d+e*x^4), x) == :(-1*d*a^-1*x^-1+-1//4*2^1//4*a^-1*c^1//4*((b^2+-4*a*c)^(1/2)+-1b)^-1//4*(d+(b^2+-4*a*c)^-1//2*(b*d+-2*a*e))*arctan(x*2^1//4*c^1//4*((b^2+-4*a*c)^(1/2)+-1b)^-1//4)+-1//4*2^1//4*a^-1*c^1//4*(-1b+-1*(b^2+-4*a*c)^(1/2))^-1//4*(d+-1*(b^2+-4*a*c)^-1//2*(b*d+-2*a*e))*arctan(x*2^1//4*c^1//4*(-1b+-1*(b^2+-4*a*c)^(1/2))^-1//4)+1//4*2^1//4*a^-1*c^1//4*((b^2+-4*a*c)^(1/2)+-1b)^-1//4*(d+(b^2+-4*a*c)^-1//2*(b*d+-2*a*e))*arctanh(x*2^1//4*c^1//4*((b^2+-4*a*c)^(1/2)+-1b)^-1//4)+1//4*2^1//4*a^-1*c^1//4*(-1b+-1*(b^2+-4*a*c)^(1/2))^-1//4*(d+-1*(b^2+-4*a*c)^-1//2*(b*d+-2*a*e))*arctanh(x*2^1//4*c^1//4*(-1b+-1*(b^2+-4*a*c)^(1/2))^-1//4))
@test integrate(x^-3*(a+b*x^4+c*x^8)^-1*(d+e*x^4), x) == :(-1//2*d*a^-1*x^-2+-1//4*2^(1/2)*a^-1*c^(1/2)*(b+(b^2+-4*a*c)^(1/2))^-1//2*(d+-1*(b^2+-4*a*c)^-1//2*(b*d+-2*a*e))*arctan(2^(1/2)*c^(1/2)*x^2*(b+(b^2+-4*a*c)^(1/2))^-1//2)+-1//4*2^(1/2)*a^-1*c^(1/2)*(b+-1*(b^2+-4*a*c)^(1/2))^-1//2*(d+(b^2+-4*a*c)^-1//2*(b*d+-2*a*e))*arctan(2^(1/2)*c^(1/2)*x^2*(b+-1*(b^2+-4*a*c)^(1/2))^-1//2))
@test integrate(x^-4*(a+b*x^4+c*x^8)^-1*(d+e*x^4), x) == :(-1//3*d*a^-1*x^-3+1//4*2^3//4*a^-1*c^3//4*((b^2+-4*a*c)^(1/2)+-1b)^-3//4*(d+(b^2+-4*a*c)^-1//2*(b*d+-2*a*e))*arctan(x*2^1//4*c^1//4*((b^2+-4*a*c)^(1/2)+-1b)^-1//4)+1//4*2^3//4*a^-1*c^3//4*((b^2+-4*a*c)^(1/2)+-1b)^-3//4*(d+(b^2+-4*a*c)^-1//2*(b*d+-2*a*e))*arctanh(x*2^1//4*c^1//4*((b^2+-4*a*c)^(1/2)+-1b)^-1//4)+1//4*2^3//4*a^-1*c^3//4*(-1b+-1*(b^2+-4*a*c)^(1/2))^-3//4*(d+-1*(b^2+-4*a*c)^-1//2*(b*d+-2*a*e))*arctan(x*2^1//4*c^1//4*(-1b+-1*(b^2+-4*a*c)^(1/2))^-1//4)+1//4*2^3//4*a^-1*c^3//4*(-1b+-1*(b^2+-4*a*c)^(1/2))^-3//4*(d+-1*(b^2+-4*a*c)^-1//2*(b*d+-2*a*e))*arctanh(x*2^1//4*c^1//4*(-1b+-1*(b^2+-4*a*c)^(1/2))^-1//4))
@test integrate(x^4*(1+x^8+-1*x^4)^-1*(1+-1*x^4), x) == :(-1x+-1//12*6^(1/2)*arctan((2+3^(1/2))^-1//2*((2+-1*3^(1/2))^(1/2)+-2x))+-1//12*6^(1/2)*arctan((2+-1*3^(1/2))^-1//2*((2+3^(1/2))^(1/2)+-2x))+-1//24*6^(1/2)*log(1+x^2+-1*x*(2+3^(1/2))^(1/2))+-1//24*6^(1/2)*log(1+x^2+-1*x*(2+-1*3^(1/2))^(1/2))+1//12*6^(1/2)*arctan((2+3^(1/2))^-1//2*((2+-1*3^(1/2))^(1/2)+2x))+1//12*6^(1/2)*arctan((2+-1*3^(1/2))^-1//2*((2+3^(1/2))^(1/2)+2x))+1//24*6^(1/2)*log(1+x^2+x*(2+3^(1/2))^(1/2))+1//24*6^(1/2)*log(1+x^2+x*(2+-1*3^(1/2))^(1/2)))
@test integrate(x^3*(1+x^8+-1*x^4)^-1*(1+-1*x^4), x) == :(-1//8*log(1+x^8+-1*x^4)+-1//12*3^(1/2)*arctan(1//3*3^(1/2)*(1+-2*x^4)))
@test integrate(x^2*(1+x^8+-1*x^4)^-1*(1+-1*x^4), x) == :(-1//4*(6+-3*3^(1/2))^-1//2*arctan((2+3^(1/2))^-1//2*((2+-1*3^(1/2))^(1/2)+2x))+-1//4*(6+3*3^(1/2))^-1//2*arctan((2+-1*3^(1/2))^-1//2*((2+3^(1/2))^(1/2)+-2x))+-1//8*(2//3+-1//3*3^(1/2))^(1/2)*log(1+x^2+x*(2+-1*3^(1/2))^(1/2))+-1//8*(2//3+1//3*3^(1/2))^(1/2)*log(1+x^2+-1*x*(2+3^(1/2))^(1/2))+1//4*(6+-3*3^(1/2))^-1//2*arctan((2+3^(1/2))^-1//2*((2+-1*3^(1/2))^(1/2)+-2x))+1//4*(6+3*3^(1/2))^-1//2*arctan((2+-1*3^(1/2))^-1//2*((2+3^(1/2))^(1/2)+2x))+1//8*(2//3+-1//3*3^(1/2))^(1/2)*log(1+x^2+-1*x*(2+-1*3^(1/2))^(1/2))+1//8*(2//3+1//3*3^(1/2))^(1/2)*log(1+x^2+x*(2+3^(1/2))^(1/2)))
@test integrate(x*(1+x^8+-1*x^4)^-1*(1+-1*x^4), x) == :(-1//12*3^(1/2)*log(1+x^4+-1*3^(1/2)*x^2)+1//12*3^(1/2)*log(1+x^4+3^(1/2)*x^2))
@test integrate((1+x^8+-1*x^4)^-1*(1+-1*x^4), x) == :(-1//4*(6+-3*3^(1/2))^-1//2*arctan((2+3^(1/2))^-1//2*((2+-1*3^(1/2))^(1/2)+-2x))+-1//4*(6+3*3^(1/2))^-1//2*arctan((2+-1*3^(1/2))^-1//2*((2+3^(1/2))^(1/2)+2x))+-1//8*(2//3+-1//3*3^(1/2))^(1/2)*log(1+x^2+x*(2+-1*3^(1/2))^(1/2))+-1//8*(2//3+1//3*3^(1/2))^(1/2)*log(1+x^2+-1*x*(2+3^(1/2))^(1/2))+1//4*(6+-3*3^(1/2))^-1//2*arctan((2+3^(1/2))^-1//2*((2+-1*3^(1/2))^(1/2)+2x))+1//4*(6+3*3^(1/2))^-1//2*arctan((2+-1*3^(1/2))^-1//2*((2+3^(1/2))^(1/2)+-2x))+1//8*(2//3+-1//3*3^(1/2))^(1/2)*log(1+x^2+-1*x*(2+-1*3^(1/2))^(1/2))+1//8*(2//3+1//3*3^(1/2))^(1/2)*log(1+x^2+x*(2+3^(1/2))^(1/2)))
@test integrate(x^-1*(1+x^8+-1*x^4)^-1*(1+-1*x^4), x) == :(-1//8*log(1+x^8+-1*x^4)+1//12*3^(1/2)*arctan(1//3*3^(1/2)*(1+-2*x^4))+log(x))
@test integrate(x^-2*(1+x^8+-1*x^4)^-1*(1+-1*x^4), x) == :(-1*x^-1+-1//12*6^(1/2)*arctan((2+3^(1/2))^-1//2*((2+-1*3^(1/2))^(1/2)+2x))+-1//12*6^(1/2)*arctan((2+-1*3^(1/2))^-1//2*((2+3^(1/2))^(1/2)+2x))+-1//24*6^(1/2)*log(1+x^2+-1*x*(2+3^(1/2))^(1/2))+-1//24*6^(1/2)*log(1+x^2+-1*x*(2+-1*3^(1/2))^(1/2))+1//12*6^(1/2)*arctan((2+3^(1/2))^-1//2*((2+-1*3^(1/2))^(1/2)+-2x))+1//12*6^(1/2)*arctan((2+-1*3^(1/2))^-1//2*((2+3^(1/2))^(1/2)+-2x))+1//24*6^(1/2)*log(1+x^2+x*(2+3^(1/2))^(1/2))+1//24*6^(1/2)*log(1+x^2+x*(2+-1*3^(1/2))^(1/2)))
@test integrate(x^-3*(1+x^8+-1*x^4)^-1*(1+-1*x^4), x) == :(-1//2*x^-2+-1//4*arctan(3^(1/2)+2*x^2)+1//4*arctan(3^(1/2)+-2*x^2)+-1//24*3^(1/2)*log(1+x^4+-1*3^(1/2)*x^2)+1//24*3^(1/2)*log(1+x^4+3^(1/2)*x^2))
@test integrate(x^-4*(1+x^8+-1*x^4)^-1*(1+-1*x^4), x) == :(-1//3*x^-3+-1//4*(2//3+-1//3*3^(1/2))^(1/2)*arctan((2+3^(1/2))^-1//2*((2+-1*3^(1/2))^(1/2)+-2x))+-1//4*(2//3+1//3*3^(1/2))^(1/2)*arctan((2+-1*3^(1/2))^-1//2*((2+3^(1/2))^(1/2)+2x))+-1//8*(2//3+-1//3*3^(1/2))^(1/2)*log(1+x^2+-1*x*(2+3^(1/2))^(1/2))+-1//8*(2//3+1//3*3^(1/2))^(1/2)*log(1+x^2+x*(2+-1*3^(1/2))^(1/2))+1//4*(2//3+-1//3*3^(1/2))^(1/2)*arctan((2+3^(1/2))^-1//2*((2+-1*3^(1/2))^(1/2)+2x))+1//4*(2//3+1//3*3^(1/2))^(1/2)*arctan((2+-1*3^(1/2))^-1//2*((2+3^(1/2))^(1/2)+-2x))+1//8*(2//3+-1//3*3^(1/2))^(1/2)*log(1+x^2+x*(2+3^(1/2))^(1/2))+1//8*(2//3+1//3*3^(1/2))^(1/2)*log(1+x^2+-1*x*(2+-1*3^(1/2))^(1/2)))
@test integrate(x^3*(d+e*x)^-1*(a+b*x^-1+c*x^-2)^-1, x) == :(1//3*a^-1*e^-1*x^3+x*a^-3*e^-3*(a^2*d^2+b^2*e^2+a*e*(b*d+-1*c*e))+(1/2)*a^-4*(a*d^2+-1*e*(b*d+-1*c*e))^-1*(d*b^4+d*a^2*c^2+-1*c*e*b^3+-3*a*c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^-1*log(d+e*x)+-1//2*a^-1*(a*d^2+-1*e*(b*d+-1*c*e))^-1*(b*d+-1*c*e)*log(c+a*x^2+b*x)+-1*a^-1*(b^2+-4*a*c)^-1//2*(a*d^2+-1*e*(b*d+-1*c*e))^-1*(d*b^2+-1*b*c*e+-2*a*c*d)*arctanh((b^2+-4*a*c)^-1//2*(b+2*a*x)))
@test integrate(x^-1*(d+e*x)^-1*(a+b*x^-1+c*x^-2)^-1, x) == :(d*(-2*e*(b*d+-1*c*e)+2*a*d^2)^-1*log(c+a*x^2+b*x)+-1*d*(a*d^2+-1*e*(b*d+-1*c*e))^-1*log(d+e*x)+(b^2+-4*a*c)^-1//2*(a*d^2+-1*e*(b*d+-1*c*e))^-1*(b*d+-2*c*e)*arctanh((b^2+-4*a*c)^-1//2*(b+2*a*x)))
@test integrate(x^-2*(d+e*x)^-1*(a+b*x^-1+c*x^-2)^-1, x) == :(e*(a*d^2+c*e^2+-1*b*d*e)^-1*log(d+e*x)+-1*e*(2*a*d^2+2*c*e^2+-2*b*d*e)^-1*log(c+a*x^2+b*x)+-1*(b^2+-4*a*c)^-1//2*(a*d^2+-1*e*(b*d+-1*c*e))^-1*(-1*b*e+2*a*d)*arctanh((b^2+-4*a*c)^-1//2*(b+2*a*x)))
@test integrate(x^-3*(d+e*x)^-1*(a+b*x^-1+c*x^-2)^-1, x) == :(c^-1*d^-1*log(x)+-1*d^-1*e^2*(a*d^2+c*e^2+-1*b*d*e)^-1*log(d+e*x)+-1//2*c^-1*(a*d^2+-1*e*(b*d+-1*c*e))^-1*(a*d+-1*b*e)*log(c+a*x^2+b*x)+c^-1*(b^2+-4*a*c)^-1//2*(a*d^2+-1*e*(b*d+-1*c*e))^-1*(-1*e*b^2+a*b*d+2*a*c*e)*arctanh((b^2+-4*a*c)^-1//2*(b+2*a*x)))
@test integrate(x^-4*(d+e*x)^-1*(a+b*x^-1+c*x^-2)^-1, x) == :(-1*c^-1*d^-1*x^-1+d^-2*e^3*(a*d^2+-1*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^-2*(a*d^2+-1*e*(-3*c*e+2*b*d))*log(d+e*x))
@test integrate((d+e*x)^-2*(a+b*x^-1+c*x^-2)^-1, x) == :(d*(a*d^2+-1*e*(b*d+-1*c*e))^-2*(b*d+-2*c*e)*log(d+e*x)+-1*d^2*e^-1*(d+e*x)^-1*(a*d^2+c*e^2+-1*b*d*e)^-1+-1*(b^2+-4*a*c)^-1//2*(a*d^2+-1*e*(b*d+-1*c*e))^-2*(b^2*d^2+-2*c*(a*d^2+-1*c*e^2)+-2*b*c*d*e)*arctanh((b^2+-4*a*c)^-1//2*(b+2*a*x))+-1//2*d*(a*d^2+-1*e*(b*d+-1*c*e))^-2*(b*d+-2*c*e)*log(c+a*x^2+b*x))
@test integrate(x^-1*(d+e*x)^-2*(a+b*x^-1+c*x^-2)^-1, x) == :(d*(d+e*x)^-1*(a*d^2+c*e^2+-1*b*d*e)^-1+(1/2)*(a*d^2+-1*e*(b*d+-1*c*e))^-2*(a*d^2+-1*c*e^2)*log(c+a*x^2+b*x)+-1*(a*d^2+-1*e*(b*d+-1*c*e))^-2*(a*d^2+-1*c*e^2)*log(d+e*x)+(b^2+-4*a*c)^-1//2*(a*d^2+-1*e*(b*d+-1*c*e))^-2*(a*d*(b*d+-4*c*e)+b*c*e^2)*arctanh((b^2+-4*a*c)^-1//2*(b+2*a*x)))
@test integrate(x^-2*(d+e*x)^-2*(a+b*x^-1+c*x^-2)^-1, x) == :(-1*e*(d+e*x)^-1*(a*d^2+c*e^2+-1*b*d*e)^-1+e*(a*d^2+-1*e*(b*d+-1*c*e))^-2*(-1*b*e+2*a*d)*log(d+e*x)+-1*(b^2+-4*a*c)^-1//2*(a*d^2+-1*e*(b*d+-1*c*e))^-2*(b^2*e^2+2*a^2*d^2+-2*a*e*(b*d+c*e))*arctanh((b^2+-4*a*c)^-1//2*(b+2*a*x))+-1//2*e*(a*d^2+-1*e*(b*d+-1*c*e))^-2*(-1*b*e+2*a*d)*log(c+a*x^2+b*x))
@test integrate(x^-3*(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(1/2)+2*a*x))^(1/2)),-2*e*(b^2+-4*a*c)^(1/2)*(-1*e*(b+(b^2+-4*a*c)^(1/2))+2*a*d)^-1))
@test integrate((a+b*x+c*x^2)^13*(b+2*c*x), x) == :(1//14*(a+b*x+c*x^2)^14)
@test integrate(x*(a+b*x^2+c*x^4)^13*(b+2*c*x^2), x) == :(1//28*(a+b*x^2+c*x^4)^14)
@test integrate(x^2*(a+b*x^3+c*x^6)^13*(b+2*c*x^3), x) == :(1//42*(a+b*x^3+c*x^6)^14)
@test integrate(x^(-1+n)*(a+b*x^n+c*x^(2n))^13*(b+2*c*x^n), x) == :(1//14*n^-1*(a+b*x^n+c*x^(2n))^14)
@test integrate((-1a+b*x+c*x^2)^13*(b+2*c*x), x) == :(1//14*(a+-1*b*x+-1*c*x^2)^14)
@test integrate(x*(-1a+b*x^2+c*x^4)^13*(b+2*c*x^2), x) == :(1//28*(a+-1*b*x^2+-1*c*x^4)^14)
@test integrate(x^2*(-1a+b*x^3+c*x^6)^13*(b+2*c*x^3), x) == :(1//42*(a+-1*b*x^3+-1*c*x^6)^14)
@test integrate(x^(-1+n)*(-1a+b*x^n+c*x^(2n))^13*(b+2*c*x^n), x) == :(1//14*n^-1*(a+-1*b*x^n+-1*c*x^(2n))^14)
@test integrate((b*x+c*x^2)^13*(b+2*c*x), x) == :(1//14*(b*x+c*x^2)^14)
@test integrate(x*(b*x^2+c*x^4)^13*(b+2*c*x^2), x) == :(1//28*x^28*(b+c*x^2)^14)
@test integrate(x^2*(b*x^3+c*x^6)^13*(b+2*c*x^3), x) == :(1//42*x^42*(b+c*x^3)^14)
@test integrate(x^(-1+n)*(b*x^n+c*x^(2n))^13*(b+2*c*x^n), x) == :(1//14*n^-1*x^(14n)*(b+c*x^n)^14)
@test integrate((a+b*x+c*x^2)^-1*(b+2*c*x), x) == :(log(a+b*x+c*x^2))
@test integrate(x*(a+b*x^2+c*x^4)^-1*(b+2*c*x^2), x) == :((1/2)*log(a+b*x^2+c*x^4))
@test integrate(x^2*(a+b*x^3+c*x^6)^-1*(b+2*c*x^3), x) == :(1//3*log(a+b*x^3+c*x^6))
@test integrate(x^(-1+n)*(a+b*x^n+c*x^(2n))^-1*(b+2*c*x^n), x) == :(n^-1*log(a+b*x^n+c*x^(2n)))
@test integrate((a+b*x+c*x^2)^-8*(b+2*c*x), x) == :(-1//7*(a+b*x+c*x^2)^-7)
@test integrate(x*(a+b*x^2+c*x^4)^-8*(b+2*c*x^2), x) == :(-1//14*(a+b*x^2+c*x^4)^-7)
@test integrate(x^2*(a+b*x^3+c*x^6)^-8*(b+2*c*x^3), x) == :(-1//21*(a+b*x^3+c*x^6)^-7)
@test integrate(x^(-1+n)*(a+b*x^n+c*x^(2n))^-8*(b+2*c*x^n), x) == :(-1//7*n^-1*(a+b*x^n+c*x^(2n))^-7)
@test integrate((-1a+b*x+c*x^2)^-1*(b+2*c*x), x) == :(log(a+-1*b*x+-1*c*x^2))
@test integrate(x*(-1a+b*x^2+c*x^4)^-1*(b+2*c*x^2), x) == :((1/2)*log(a+-1*b*x^2+-1*c*x^4))
@test integrate(x^2*(-1a+b*x^3+c*x^6)^-1*(b+2*c*x^3), x) == :(1//3*log(a+-1*b*x^3+-1*c*x^6))
@test integrate(x^(-1+n)*(-1a+b*x^n+c*x^(2n))^-1*(b+2*c*x^n), x) == :(n^-1*log(a+-1*b*x^n+-1*c*x^(2n)))
@test integrate((-1a+b*x+c*x^2)^-8*(b+2*c*x), x) == :(1//7*(a+-1*b*x+-1*c*x^2)^-7)
@test integrate(x*(-1a+b*x^2+c*x^4)^-8*(b+2*c*x^2), x) == :(1//14*(a+-1*b*x^2+-1*c*x^4)^-7)
@test integrate(x^2*(-1a+b*x^3+c*x^6)^-8*(b+2*c*x^3), x) == :(1//21*(a+-1*b*x^3+-1*c*x^6)^-7)
@test integrate(x^(-1+n)*(-1a+b*x^n+c*x^(2n))^-8*(b+2*c*x^n), x) == :(1//7*n^-1*(a+-1*b*x^n+-1*c*x^(2n))^-7)
@test integrate((b*x+c*x^2)^-1*(b+2*c*x), x) == :(log(b*x+c*x^2))
@test integrate(x^(-1+n)*(b*x^n+c*x^(2n))^-1*(b+2*c*x^n), x) == :(n^-1*log(b+c*x^n)+log(x))
@test integrate((b*x+c*x^2)^-8*(b+2*c*x), x) == :(-1//7*(b*x+c*x^2)^-7)
@test integrate(x*(b*x^2+c*x^4)^-8*(b+2*c*x^2), x) == :(-1//14*x^-14*(b+c*x^2)^-7)
@test integrate(x^2*(b*x^3+c*x^6)^-8*(b+2*c*x^3), x) == :(-1//21*x^-21*(b+c*x^3)^-7)
@test integrate(x^(-1+n)*(b*x^n+c*x^(2n))^-8*(b+2*c*x^n), x) == :(-1//7*n^-1*x^(-7n)*(b+c*x^n)^-7)
@test integrate((a+b*x+c*x^2)^p*(b+2*c*x), x) == :((1+p)^-1*(a+b*x+c*x^2)^(1+p))
@test integrate(x*(a+b*x^2+c*x^4)^p*(b+2*c*x^2), x) == :((2+2p)^-1*(a+b*x^2+c*x^4)^(1+p))
@test integrate(x^2*(a+b*x^3+c*x^6)^p*(b+2*c*x^3), x) == :((3+3p)^-1*(a+b*x^3+c*x^6)^(1+p))
@test integrate(x^(-1+n)*(a+b*x^n+c*x^(2n))^p*(b+2*c*x^n), x) == :(n^-1*(1+p)^-1*(a+b*x^n+c*x^(2n))^(1+p))
@test integrate((-1a+b*x+c*x^2)^p*(b+2*c*x), x) == :((1+p)^-1*(-1a+b*x+c*x^2)^(1+p))
@test integrate(x*(-1a+b*x^2+c*x^4)^p*(b+2*c*x^2), x) == :((2+2p)^-1*(-1a+b*x^2+c*x^4)^(1+p))
@test integrate(x^2*(-1a+b*x^3+c*x^6)^p*(b+2*c*x^3), x) == :((3+3p)^-1*(-1a+b*x^3+c*x^6)^(1+p))
@test integrate(x^(-1+n)*(-1a+b*x^n+c*x^(2n))^p*(b+2*c*x^n), x) == :(n^-1*(1+p)^-1*(-1a+b*x^n+c*x^(2n))^(1+p))
@test integrate((b*x+c*x^2)^p*(b+2*c*x), x) == :((1+p)^-1*(b*x+c*x^2)^(1+p))
@test integrate(x*(b*x^2+c*x^4)^p*(b+2*c*x^2), x) == :((2+2p)^-1*(b*x^2+c*x^4)^(1+p))
@test integrate(x^2*(b*x^3+c*x^6)^p*(b+2*c*x^3), x) == :((3+3p)^-1*(b*x^3+c*x^6)^(1+p))
@test integrate(x^(-1+n)*(b*x^n+c*x^(2n))^p*(b+2*c*x^n), x) == :(n^-1*(1+p)^-1*(b*x^n+c*x^(2n))^(1+p))
@test integrate((c*d^1//3*x^2//3+d*c^1//3*x^4//3+-1*x*c^2//3*d^2//3)^-1*(c^1//3+-2*d^1//3*x^1//3), x) == :(-3*c^-1//3*d^-2//3*log(c^2//3+d^2//3*x^2//3+-1*c^1//3*d^1//3*x^1//3))

max_stars_repo_path: test/1 Algebraic functions/1.2 Trinomial products/1.2.3 General/1.2.3.4 (f x)^m (d+e x^n)^q (a+b x^n+c x^(2 n))^p.jl


text:
function eval_f_wrapper(ips::InteriorPointSolver, x::Vector{Float64})
    nlp = ips.nlp
    cnt = ips.cnt
    @trace(ips.logger,"Evaluating objective.")
    cnt.eval_function_time += @elapsed obj_val = (get_minimize(nlp) ? 1. : -1.) * obj(nlp,view(x,1:get_nvar(nlp)))
    cnt.obj_cnt+=1
    cnt.obj_cnt==1 && (is_valid(obj_val) || throw(InvalidNumberException()))
    return obj_val*ips.obj_scale[]
end

function eval_grad_f_wrapper!(ips::InteriorPointSolver, f::Vector{Float64},x::Vector{Float64})
    nlp = ips.nlp
    cnt = ips.cnt
    @trace(ips.logger,"Evaluating objective gradient.")
    cnt.eval_function_time += @elapsed grad!(nlp,view(x,1:get_nvar(nlp)),view(f,1:get_nvar(nlp)))
    f.*=ips.obj_scale[] * (get_minimize(nlp) ? 1. : -1.)
    cnt.obj_grad_cnt+=1
    cnt.obj_grad_cnt==1 && (is_valid(f)  || throw(InvalidNumberException()))
    return f
end

function eval_cons_wrapper!(ips::InteriorPointSolver, c::Vector{Float64},x::Vector{Float64})
    nlp = ips.nlp
    cnt = ips.cnt
    @trace(ips.logger, "Evaluating constraints.")
    cnt.eval_function_time += @elapsed cons!(nlp,view(x,1:get_nvar(nlp)),view(c,1:get_ncon(nlp)))
    view(c,ips.ind_ineq).-=view(x,get_nvar(nlp)+1:ips.n)
    c.-=ips.rhs
    c.*=ips.con_scale
    cnt.con_cnt+=1
    cnt.con_cnt==2 && (is_valid(c) || throw(InvalidNumberException()))
    return c
end

function eval_jac_wrapper!(ipp::InteriorPointSolver, kkt::AbstractKKTSystem, x::Vector{Float64})
    nlp = ipp.nlp
    cnt = ipp.cnt
    ns = length(ipp.ind_ineq)
    @trace(ipp.logger, "Evaluating constraint Jacobian.")
    jac = get_jacobian(kkt)
    cnt.eval_function_time += @elapsed jac_coord!(nlp,view(x,1:get_nvar(nlp)),view(jac,1:get_nnzj(nlp)))
    compress_jacobian!(kkt)
    cnt.con_jac_cnt+=1
    cnt.con_jac_cnt==1 && (is_valid(jac) || throw(InvalidNumberException()))
    @trace(ipp.logger,"Constraint jacobian evaluation started.")
    return jac
end

function eval_lag_hess_wrapper!(ipp::InteriorPointSolver, kkt::AbstractKKTSystem, x::Vector{Float64},l::Vector{Float64};is_resto=false)
    nlp = ipp.nlp
    cnt = ipp.cnt
    @trace(ipp.logger,"Evaluating Lagrangian Hessian.")
    dual(ipp._w1) .= l.*ipp.con_scale
    hess = get_hessian(kkt)
    cnt.eval_function_time += @elapsed hess_coord!(
        nlp, view(x,1:get_nvar(nlp)), dual(ipp._w1), view(hess, 1:get_nnzh(nlp));
        obj_weight = (get_minimize(nlp) ? 1. : -1.) * (is_resto ? 0.0 : ipp.obj_scale[]))
    compress_hessian!(kkt)
    cnt.lag_hess_cnt+=1
    cnt.lag_hess_cnt==1 && (is_valid(hess) || throw(InvalidNumberException()))
    return hess
end

function eval_jac_wrapper!(ipp::InteriorPointSolver, kkt::AbstractDenseKKTSystem, x::Vector{Float64})
    nlp = ipp.nlp
    cnt = ipp.cnt
    ns = length(ipp.ind_ineq)
    @trace(ipp.logger, "Evaluating constraint Jacobian.")
    jac = get_jacobian(kkt)
    cnt.eval_function_time += @elapsed jac_dense!(nlp,view(x,1:get_nvar(nlp)),jac)
    compress_jacobian!(kkt)
    cnt.con_jac_cnt+=1
    cnt.con_jac_cnt==1 && (is_valid(jac) || throw(InvalidNumberException()))
    @trace(ipp.logger,"Constraint jacobian evaluation started.")
    return jac
end

function eval_lag_hess_wrapper!(ipp::InteriorPointSolver, kkt::AbstractDenseKKTSystem, x::Vector{Float64},l::Vector{Float64};is_resto=false)
    nlp = ipp.nlp
    cnt = ipp.cnt
    @trace(ipp.logger,"Evaluating Lagrangian Hessian.")
    dual(ipp._w1) .= l.*ipp.con_scale
    hess = get_hessian(kkt)
    cnt.eval_function_time += @elapsed hess_dense!(
        nlp, view(x,1:get_nvar(nlp)), dual(ipp._w1), hess;
        obj_weight = (get_minimize(nlp) ? 1. : -1.) * (is_resto ? 0.0 : ipp.obj_scale[]))
    compress_hessian!(kkt)
    cnt.lag_hess_cnt+=1
    cnt.lag_hess_cnt==1 && (is_valid(hess) || throw(InvalidNumberException()))
    return hess
end