text:
# reader.jl
# =========
#
# A reader for BCF formatted files.
#
# This file is a part of BioJulia.
# License is MIT: https://github.com/BioJulia/GeneticVariation.jl/blob/master/LICENSE

struct Reader{T<:IO} <: BioCore.IO.AbstractReader
    version::Tuple{UInt8,UInt8}  # (major, minor)
    header::VCF.Header
    stream::BGZFStreams.BGZFStream{T}
end

"""
    BCF.Reader(input::IO)
Create a data reader of the BCF file format.
# Arguments
* `input`: data source
"""
function Reader(input::IO)
    stream = BGZFStreams.BGZFStream(input)

    # magic bytes and BCF version
    B = read(stream, UInt8)
    C = read(stream, UInt8)
    F = read(stream, UInt8)
    major = read(stream, UInt8)
    minor = read(stream, UInt8)
    if (B, C, F) != map(UInt8, ('B', 'C', 'F'))
        error("not a BCF file")
    elseif (major, minor) != (0x02, 0x02)
        error("unsupported BCF version")
    end

    # NOTE: This isn't specified in the BCF specs, but seems to be a practice at least in htslib.
    # See: https://github.com/samtools/hts-specs/issues/138
    l_header = read(stream, Int32)
    data = read(stream, l_header)

    # parse VCF header
    vcfreader = VCF.Reader(BufferedStreams.BufferedInputStream(data))

    return Reader((major, minor), vcfreader.header, stream)
end

function Base.eltype(::Type{Reader{T}}) where T
    return Record
end

function BioCore.IO.stream(reader::Reader)
    return reader.stream
end

"""
    header(reader::BCF.Reader)::VCF.Header
Get the header of `reader`.
"""
function header(reader::Reader)
    return reader.header
end

function BioCore.header(reader::Reader)
    return header(reader)
end

function Base.read!(reader::Reader, record::Record)
    sharedlen = read(reader.stream, UInt32)
    indivlen = read(reader.stream, UInt32)
    datalen = sharedlen + indivlen
    resize!(record.data, datalen)
    unsafe_read(reader.stream, pointer(record.data), datalen)
    record.filled = 1:datalen
    record.sharedlen = sharedlen
    record.indivlen = indivlen
    return record
end


text:
# This is a patch for loading a data to GVar correctly.
import NiLangCore

NiLangCore.loaddata(::Type{GT}, x::T) where {T, GT<:GVar{T}} = convert(GT, x)
function NiLangCore.loaddata(t::Type{VT}, x::AbstractVector) where {T, VT<:AbstractVector{T}}
    convert.(T, x)
end

function NiLangCore.loaddata(t::VT, x::AbstractVector) where {T, VT<:AbstractVector{T}}
    convert(VT, NiLangCore.loaddata.(t, x))
end

function NiLangCore.loaddata(::Type{T}, x::XT) where {N, T<:Tuple{N}, XT<:Tuple{N}}
    ntuple(i=>NiLangCore.loaddata.(T.parameters[i], [i]), N)
end

ext: jl


text:
using DitherPunk
using DitherPunk: ColorNotImplementedError
using IndirectArrays
using ImageCore
using ImageInTerminal
using ReferenceTests
using TestImages

## Define color scheme
white = RGB{Float32}(1, 1, 1)
yellow = RGB{Float32}(1, 1, 0)
green = RGB{Float32}(0, 0.5, 0)
orange = RGB{Float32}(1, 0.5, 0)
red = RGB{Float32}(1, 0, 0)
blue = RGB{Float32}(0, 0, 1)

cs = [white, yellow, green, orange, red, blue]

# Load test image
img = testimage("fabio_color_256")
img_gray = testimage("fabio_gray_256")
imshow(img)
println()

# Run & test custom color pallete dithering methods
algs = Dict(
    "FloydSteinberg" => FloydSteinberg(),
    "ClosestColor" => ClosestColor(),
    "Bayer" => Bayer(),
)

for (name, alg) in algs
    # Test custom color dithering on color images
    local img2 = copy(img)
    local d = dither(img2, alg, cs)
    @test_reference "references/color/$(name).txt" d
    @test eltype(d) == eltype(img2)
    @test img2 == img # image not modified
    imshow(d)
    println()

    # Test custom color dithering on gray images
    local img2_gray = copy(img_gray)
    local d = dither(img2_gray, alg, cs)
    @test_reference "references/color/$(name)_from_gray.txt" d
    @test eltype(d) == eltype(cs)
    @test img2_gray == img_gray # image not modified
    imshow(d)
    println()
end

## Test API
# Test for argument errors on algorithms that don't support custom color palletes
for alg in [WhiteNoiseThreshold(), ConstantThreshold()]
    @test_throws ColorNotImplementedError dither(img, alg, cs)
end

img2 = copy(img)
alg = FloydSteinberg()
d = dither(img2, alg, cs)

# Test setting output type
d2 = dither(HSV, img2, alg, cs)
@test d2 isa IndirectArray
@test eltype(d2) <: HSV
@test RGB{N0f8}.(d2) ≈ d
@test img2 == img # image not modified

# Inplace modify output image
out = zeros(RGB{Float16}, size(img2)...)
d3 = dither!(out, img2, alg, cs)
@test out ≈ d # image updated in-place
@test d3 ≈ d
@test eltype(out) == RGB{Float16}
@test eltype(d3) == RGB{Float16}
@test img2 == img # image not modified

# Inplace modify  image
d4 = dither!(img2, alg, cs)
@test d4 == d
@test img2 == d # image updated in-place
@test eltype(d4) == eltype(img)
@test eltype(img2) == eltype(img)

## Conditional dependencies
# Test conditional dependency on ColorSchemes.jl
using ColorSchemes
@test dither(img, alg, ColorSchemes.jet) == dither(img, alg, :jet)

# Dry-run conditional dependency on Clustering.jl
using Clustering
d = dither(img, alg, 4)
imshow(d)
println()


text:
include("./modules/ReadSensors.jl")
include("./Controller.jl")
include("./modules/LoadCSV.jl")

function main()
    steps_count = 0;
    rawdata = Channel(LoadCSV.load_csv)
    #rawdata = Channel(ReadSensors.init)
    #ReadSensors.start()
    steps = Channel(Controller.controller(rawdata))
    for x in steps
        steps_count += 1
    end

    println(steps_count);
end

main()

max_stars_repo_name: eliabiraschi/pedometer

max_issues_repo_name: eliabiraschi/pedometer

max_forks_repo_name: eliabiraschi/pedometer


text:
## ---------------------------------------------------------------------------------
function _box_vol(model, idxs)
    try
        L, U = ChLP.fva(model, idxs)
        vol = prod(abs.(L .- U))
        max(0.0, log10(vol + 1e-50))
    catch; NaN end
end

## ---------------------------------------------------------------------------------
function plot_pol_box_size(iJR, Data;
        Dlim = nothing,
        cgD_Xlim = nothing,
        bins = 50
    )
    src = nameof(Data)

    model0 = iJR.load_model("max_model")
    rxns_map = iJR.load_rxns_map()
    offsetf = 1.1

    exglcidx = ChU.rxnindex(model0, iJR.EX_GLC_IDER)
    biomidx = ChU.rxnindex(model0, iJR.BIOMASS_IDER)
    exglcL, exglcU = ChU.bounds(model0, exglcidx)

    maxD = maximum(Data.val(:D)) * offsetf
    max_cgD_X = maximum(Data.ciD_X(:GLC)) * offsetf

    Dlim = isnothing(Dlim) ? [0.01, maxD] : Dlim
    Ds = range(Dlim...; length = bins)
    @show Ds

    # ug negative means uptake !!!
    cgD_Xlim = isnothing(cgD_Xlim) ? [abs(exglcU), max_cgD_X] : cgD_Xlim
    cgD_Xs = range(cgD_Xlim...; length = bins) # make possitive
    @show cgD_Xs

    cid = (:BOX_VOL, src, Dlim, cgD_Xlim, bins)
    box_vols = lcache(ChE, cid) do

        box_vols_ = zeros(bins, bins)

        ids = ["GLC"]

        model_ids = [rxns_map[id] for id in ids]
        model_idxs = [ChU.rxnindex(model0, model_id) for model_id in model_ids]

        # feeding task
        Ch = Channel(nthreads()) do Ch_
            @showprogress for (Di, D) in enumerate(Ds)
                for (cgD_Xi, cgD_X) in enumerate(cgD_Xs)
                    put!(Ch_, (Di, D, cgD_Xi, cgD_X))
                end
            end
        end

        # compute volume map
        @threads for _ in 1:nthreads()
            model = deepcopy(model0)
            for (Di, D, cgD_Xi, cgD_X) in Ch

                # Reduce Pol
                # ug negative means uptake !!!
                ChU.lb!(model, exglcidx, -cgD_X)
                ChU.bounds!(model, biomidx, D, D)
                box_vols_[Di, cgD_Xi] = _box_vol(model, model_idxs)
            end
        end

        return box_vols_
    end

    # vol map
    p = heatmap(Ds, cgD_Xs, box_vols';
        label = "",
        xlabel = _textbf("D"),
        ylabel = _textbf("c_g", "D/X"),
        color = :greys,
    )

    fontsize = 20
    text_ = _textbf("polytope volume")
    plot!(p; rightmargin = 19mm)
    annotate!(p, 0.66, 20.0, text(text_, fontsize, :black, rotation = 90))

    # exp vals
    marker = (10, source_markers[Data])
    scatter!(p, Data.val(:D), abs.(Data.ciD_X(:GLC));
        label = "", color = :white, marker
    )

    # sfig(ChE, p,
    #     @fileid, "pol_box_volume_with_dat", (;src, bins), ".png"
    # )

    return p
end


text:
struct ExtractEmpty end

"""
    extractempty

A singleton of type [`ExtractEmpty`](@ref) is used to signal
downstream extractors that they should extract an Empty Array
"""
const extractempty = ExtractEmpty()

include("auxiliary.jl")
include("extractarray.jl")
include("extractdict.jl")
include("extractcategorical.jl")
include("extractscalar.jl")
include("extractstring.jl")
include("extractvector.jl")
include("extractonehot.jl")
include("extract_keyasfield.jl")
include("multirepresentation.jl")


text:
# Note that this script can accept some limited command-line arguments, run
# `julia build_tarballs.jl --help` to see a usage message.
using BinaryBuilder

name = "LibCURL"
version = v"7.70.0"
cacert_version = "2020-01-01"

# Collection of sources required to build LibCURL
sources = [
    ArchiveSource("https://curl.haxx.se/download/curl-$(version).tar.gz",
    "ca2feeb8ef13368ce5d5e5849a5fd5e2dd4755fecf7d8f0cc94000a4206fb8e7"),
    FileSource("https://curl.haxx.se/ca/cacert-$cacert_version.pem",
    "adf770dfd574a0d6026bfaa270cb6879b063957177a991d453ff1d302c02081f",
    filename="cacert.pem")
]

# Bash recipe for building across all platforms
script = raw"""
cd $WORKSPACE/srcdir/curl-*

# Holy crow we really configure the bitlets out of this thing
FLAGS=(
    # Disable....almost everything
    --without-ssl --without-gnutls --without-gssapi
    --without-libidn --without-libidn2 --without-libmetalink --without-librtmp
    --without-nss --without-polarssl
    --without-spnego --without-libpsl --disable-ares --disable-manual
    --disable-ldap --disable-ldaps --without-zsh-functions-dir
    --disable-static

    # Two things we actually enable
    --with-libssh2=${prefix} --with-mbedtls=${prefix} --with-zlib=${prefix}
    --with-nghttp2=${prefix}
)

# We need to tell it where to find libssh2 on windows
if [[ ${target} == *mingw* ]]; then
    FLAGS+=(LDFLAGS="${LDFLAGS} -L${prefix}/bin")
fi

./configure --prefix=$prefix --host=$target --build=${MACHTYPE} "${FLAGS[@]}"
make -j${nproc}
make install
install_license COPYING
cp ../cacert.pem $prefix/share/cacert.pem
"""

# These are the platforms we will build for by default, unless further
# platforms are passed in on the command line
platforms = supported_platforms()

# The products that we will ensure are always built
products = [
    LibraryProduct("libcurl", :libcurl),
    ExecutableProduct("curl", :curl),
    FileProduct("share/cacert.pem", :cacert)
]

# Dependencies that must be installed before this package can be built
dependencies = [
    Dependency("LibSSH2_jll"),
    Dependency("MbedTLS_jll"),
    Dependency("Zlib_jll"),
    Dependency("nghttp2_jll"),
]

# Build the tarballs, and possibly a `build.jl` as well.
build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies)


text:
abstract AbstractGenome

abstract IndexableGenome{T} <: AbstractGenome

function mutate!{T<:Real}(g::IndexableGenome{T}, o::RandomNormal)
    @inbounds for i in 1:length(g)
        ɛ = T(randn() * o.std + o.mean)
        g[i] = g[i] + ɛ
    end
end

function randswap!(g::IndexableGenome)
    i1 = rand(1:length(g))
    i2 = rand(1:length(g))
    @inbounds tmp = g[i1]
    @inbounds g[i1] = g[i2]
    @inbounds g[i2] = tmp
    g
end

shuffle!(g::IndexableGenome) = error()


text:
@testset "Flow gradients" begin

    p3   = dcdp_primitives( :one_restr   , β, wp, zspace, Πp, ψspace)
    p4a  = dcdp_primitives( :dgt1_restr  , β, wp, zspace, Πp, ψspace)
    p4b  = dcdp_primitives( :Dgt0_restr  , β, wp, zspace, Πp, ψspace)
    p5   = dcdp_primitives( :one         , β, wp, zspace, Πp, ψspace)

    p6a  = dcdp_primitives( :dgt1        , β, wp, zspace, Πp, ψspace)
    p6b  = dcdp_primitives( :Dgt0        , β, wp, zspace, Πp, ψspace)

    p5a = dcdp_primitives( :dgt1_ext_restr, β, wp, zspace, Πp, ψspace)
    p7a = dcdp_primitives( :dgt1_ext      , β, wp, zspace, Πp, ψspace)

    p5c = dcdp_primitives( :dgt1_d1_restr, β, wp, zspace, Πp, ψspace)
    p7c = dcdp_primitives( :dgt1_d1      , β, wp, zspace, Πp, ψspace)

    p5d = dcdp_primitives( :dgt1_cost_restr, β, wp, (logp_space, logc_space, ), Πpconly, ψspace)
    p7d = dcdp_primitives( :dgt1_cost      , β, wp, (logp_space, logc_space, ), Πpconly, ψspace)

    p6e = dcdp_primitives( :dgt1_cost_Dgt0_restr, β, wp, (logp_space, logc_space, ), Πpconly, ψspace)
    p8e = dcdp_primitives( :dgt1_cost_Dgt0      , β, wp, (logp_space, logc_space, ), Πpconly, ψspace)

    p6f = dcdp_primitives( :dgt1_pricecost_restr, β, wp, (logp_space, logc_space, ), Πpconly, ψspace)
    p8f = dcdp_primitives( :dgt1_pricecost      , β, wp, (logp_space, logc_space, ), Πpconly, ψspace)
    p7f = dcdp_primitives( :dgt1_pricebreak_restr, β, wp, (logp_space, logc_space, ), Πpconly, ψspace)
    p9f = dcdp_primitives( :dgt1_pricebreak      , β, wp, (logp_space, logc_space, ), Πpconly, ψspace)

    p5g = dcdp_primitives( :cheb2_restr, β, wp, (logp_space, -1.0:0.2:1.0, ), Πpconly, ψspace)
    p7g = dcdp_primitives( :cheb2      , β, wp, (logp_space, -1.0:0.2:1.0, ), Πpconly, ψspace)
    p6g = dcdp_primitives( :cheb3_restr, β, wp, (logp_space, -1.0:0.2:1.0, ), Πpconly, ψspace)
    p8g = dcdp_primitives( :cheb3      , β, wp, (logp_space, -1.0:0.2:1.0, ), Πpconly, ψspace)

    p7h = dcdp_primitives( :cheb3_dgt1_restr, β, wp, (logp_space, -1.0:0.2:1.0, ), Πpconly, ψspace)
    p9h = dcdp_primitives( :cheb3_dgt1      , β, wp, (logp_space, -1.0:0.2:1.0, ), Πpconly, ψspace)

    p8i = dcdp_primitives( :cheb3_cost_restr, β, wp,  (logp_space, logc_space, -1.0:0.2:1.0, ), Πpconly, ψspace)
    p10i = dcdp_primitives( :cheb3_cost      , β, wp, (logp_space, logc_space, -1.0:0.2:1.0, ), Πpconly, ψspace)

    p9h  = dcdp_primitives( :cheb3_cost_tech_restr, β, wp, (logp_space, logc_space, -1.0:0.2:1.0, ), Πpconly, ψspace)
    p11h = dcdp_primitives( :cheb3_cost_tech      , β, wp, (logp_space, logc_space, -1.0:0.2:1.0, ), Πpconly, ψspace)

    p8j = dcdp_primitives( :ttbuild_cost_restr , β, wp, (logp_space, logc_space, ), Πpconly, ψspace)
    p10j = dcdp_primitives( :ttbuild_cost      , β, wp, (logp_space, logc_space, ), Πpconly, ψspace)

    σ = 0.25

    a = STARTING_log_ogip # 0.561244
    b = STARTING_σ_ψ      # 0.42165

    v3 = [-4.28566,       -5.45746,           -0.3, ]
    v4 = [-4.28566,       -4.71627, -5.80131, -0.3, ]
    v5 = [-4.28566, a, b, -5.45746,           -0.3, ]
    v6 = [-4.28566, a, b, -4.71627, -5.80131, -0.3, ]

    v5a = [-4.28566,       -4.71627, -5.80131, -0.2, -0.2, ]
    v7a = [-4.28566, a, b, -4.71627, -5.80131, -0.2, -0.2, ]

    v6e = [-4.28566,       -4.71627, -5.80131, -0.2, -0.2, -1.0,]
    v8e = [-4.28566, a, b, -4.71627, -5.80131, -0.2, -0.2, -1.0,]

    v6f = [-4.28566,       1.0, -2.71627, -1.80131, -0.7, -0.2, ]
    v8f = [-4.28566, a, b, 1.0, -2.71627, -1.80131, -0.7, -0.2, ]

    v7f = [-4.28566,       1.0, 1.0, -2.71627, -1.80131, -0.7, -0.2, ]
    v9f = [-4.28566, a, b, 1.0, 1.0, -2.71627, -1.80131, -0.7, -0.2, ]

    v8i  = [-3.58283,                     -13.9518*0.2, -12.5996*0.2, 11.6749*0.2, -6.40167*0.2, 2.0126*0.2, -0.2, -1.17545, ]
    v10i = [-3.58283, 0.710067, 0.442882, -13.9518*0.2, -12.5996*0.2, 11.6749*0.2, -6.40167*0.2, 2.0126*0.2, -0.2, -1.17545, ]
    v11h = [-3.58283, 0.710067, 0.442882, 0.0032, -13.9518*0.2, -12.5996*0.2, 11.6749*0.2, -6.40167*0.2, 2.0126*0.2, -0.2, -1.17545, ]

    roy = 0.225    # median royalty
    geoid = 4.706  # median geology

    println("Testing a bunch of small flow gradients now...")

    @test check_flowgrad(v8f,  σ, p9h,  geoid, roy)
    @test check_flowgrad(v11h, σ, p11h, geoid, roy)

    # @test check_flowgrad(v8i,  σ, p8j,  geoid, roy)
    # @test check_flowgrad(v10i, σ, p10j, geoid, roy)
    #
    # @test check_flowgrad(v8i,  σ, p8i,  geoid, roy)
    # @test check_flowgrad(v10i, σ, p10i, geoid, roy)
    # @test check_flowgrad(v7f, σ, p7h, geoid, roy)
    # @test check_flowgrad(v9f, σ, p9h, geoid, roy)
    #
    # @test check_flowgrad(v5a, σ, p5g, geoid, roy)
    # @test check_flowgrad(v7f, σ, p7g, geoid, roy)
    # @test check_flowgrad(v6f, σ, p6g, geoid, roy)
    # @test check_flowgrad(v8f, σ, p8g, geoid, roy)
    #
    # @test check_flowgrad(v7f, σ, p7f, geoid, roy)
    # @test check_flowgrad(v9f, σ, p9f, geoid, roy)
    #
    # @test check_flowgrad(v6f, σ, p6f, geoid, roy)
    # @test check_flowgrad(v8f, σ, p8f, geoid, roy)
    #
    # @test check_flowgrad(v6e, σ, p6e, geoid, roy)
    # @test check_flowgrad(v8e, σ, p8e, geoid, roy)
    #
    # @test check_flowgrad(v5a, σ, p5d, geoid, roy)
    # @test check_flowgrad(v7a, σ, p7d, geoid, roy)
    #
    # @test check_flowgrad(v5a, σ, p5c, geoid, roy)
    # @test check_flowgrad(v7a, σ, p7c, geoid, roy)
    #
    # @test check_flowgrad(v5a, σ, p5a, geoid, roy)
    # @test check_flowgrad(v7a, σ, p7a, geoid, roy)
    #
    # @test check_flowgrad(v3, σ, p3 , geoid, roy)
    # @test check_flowgrad(v4, σ, p4a, geoid, roy)
    # @test check_flowgrad(v4, σ, p4b, geoid, roy)
    # @test check_flowgrad(v5, σ, p5 , geoid, roy)
    @test check_flowgrad(v6, σ, p6a, geoid, roy)
    @test check_flowgrad(v6, σ, p6b, geoid, roy)
end


text:
#=
BFSLevelsTest:
- Julia version: 1.6.2
- Author: samuel
- Date: 2021-09-11
=#

using SuiteSparseGraphBLAS
using SparseArrays
using LinearAlgebra
using Test

include("/Users/samuel/Documents/Jupyter/GraphBlasAlgorithmsFinal/src/BFSLevels.jl")
matrix =  GBMatrix([[false, false, false, false, false, false, false] [true, false, false, false, false, false, false] [true, false, false, false, false, false, false] [true, false, false, false, false, false, false] [false, false, false, false, false, false, true] [false, false, false, true, false, false, false] [false, false, false, false, false, true, false]])
print(matrix)
@test bfs_level(matrix, 1, 7) == GBVector([1, 2, 2, 2, 5, 3, 4])


text:
abstract NLMM{T<:FP} <: StatisticalModel

StatsBase.model_response(nm::NLMM) = model_response(nlregmod(nm))
StatsBase.residuals(nm::NLMM) = residuals(nlregmod(nm))
pnames(nm::NLMM) = pnames(nlregmod(nm))
npars(nm::NLMM) = npars(nlregmod(nm))
StatsBase.df_residual(nm::NLMM) = nobs(nm) - npars(nm)

## returns the coefficient table
function StatsBase.coeftable(nm::NLMM)
    pp = coef(nm); se = stderr(nm); tt = pp ./ se
    CoefTable(hcat(pp, se, tt, ccdf(FDist(1, df_residual(nm)), abs2(tt)))
              ["Estimate","Std.Error","t value", "Pr(>|t|)"],
              pnames(nm), 4)
end

theta(nm::NLMM) = theta(nm.lambda)
theta(lambda::Diagonal) = lambda.diag
function theta(m::Triangular)
    n = size(m,1); v = Array(eltype(m),n*(n+1)>>1); pos = 0; UL = m.UL
    for j in 1:n, i in (m.uplo == 'L' ? (j:n) : (1:j)) v[pos += 1] = UL[i,j] end
    v
end

theta!{T}(lambda::Diagonal{T},th::Vector{T}) = copy!(lambda.diag,th)
function theta!{T}(m::Triangular{T},th::Vector{T})
    n = size(m,1); pos = 0; UL = m.UL
    length(th) == n*(n+1)>>1 || error("length(th) = $(length(th)), should be $(n*(n+1)/2)")
    for j in 1:n, i in (m.uplo == 'L' ? (j:n) : (1:j)) UL[i,j] = th[pos += 1] end
    m
end

lowerbd{T<:FP}(nm::NLMM{T}) = [fill(-inf(T),length(nm.beta)),lowerbd(nm.lambda)]
lowerbd{T}(lambda::Diagonal{T}) = zeros(T,size(lambda,1))
function lowerbd{T}(m::Triangular{T})
    n = size(m,1); v = fill(-inf(T),n*(n+1)>>1); pos = 1; zt = zero(T)
    for j in 1:n, i in (m.uplo == 'L' ? (j:n) : (1:j))
        i == j && (v[pos] = zt)
        pos += 1
    end
    v
end

function setpars!{T<:FP}(nm::NLMM{T},pars::Vector{T})
    bb = nm.beta; p = length(bb); copy!(bb, view(pars,1:p))
    theta!(nm.lambda,pars[(p+1):end])
    nm
end

function StatsBase.fit(nm::NLMM; verbose=false)
    pnls!(nm; verbose=verbose)
    u0 = copy(nm.u)
    th = theta(nm); nth = length(th)
    pars = [nm.beta,th]
    o = Opt(:LN_BOBYQA,length(pars))
    ftol_abs!(o, 1e-6)    # criterion on deviance changes
    xtol_abs!(o, 1e-6)    # criterion on all parameter value changes
    lower_bounds!(o, lowerbd(nm))
    function obj(x::Vector{Float64}, g::Vector{Float64})
        length(g) == 0 || error("gradient evaluations are not provided")
        pnls!(setpars!(nm,x),u0;verbose=verbose)
    end
    if verbose
        count = 0
        function vobj(x::Vector{Float64}, g::Vector{Float64})
            count += 1
            length(g) == 0 || error("gradient evaluations are not provided")
            val = pnls!(setpars!(nm,x),u0)
            print("f_$count: $(round(val,5)), [")
            showcompact(x[1])
            for i in 2:length(x) print(","); showcompact(x[i]) end
            println("]")
            val
        end
        min_objective!(o, vobj)
    else
        min_objective!(o, obj)
    end
    fmin, xmin, ret = optimize!(o, pars)
    verbose && println(ret)
    setpars!(nm,xmin)
    nm
end

function Base.scale(nm::NLMM, sqr=false)
    ssqr = pwrss(nm)/nobs(nm)
    sqr ? ssqr : sqrt(ssqr)
end

StatsBase.vcov(nm::NLMM) = scale(nm,true) * unscaledvcov(nlregmod(nm))


text:
using Interpolations

# Routines for observations of light sources in particular images,
# rather than for sources in the abstract, in physical units,
# and rather than for images alone (that's image_model.jl).

# A contiguous box in a 2-d array.
const Box = Tuple{UnitRange{Int}, UnitRange{Int}}

clamp_box(box::Box, dims::Tuple{Int, Int}) =
    (clamp(first(box[1]), 1, dims[1]+1):
     clamp(last(box[1]), 0, dims[1]),
     clamp(first(box[2]), 1, dims[2]+1):
     clamp(last(box[2]), 0, dims[2]))

function _dilate_range(range::UnitRange{Int}, factor::Float64)
    delta = round(Int, factor * length(range) / 2)
    return (first(range) - delta):(last(range) + delta)
end

dilate_box(box::Box, factor::Float64) = (_dilate_range(box[1], factor),
                                         _dilate_range(box[2], factor))

_enclose_ranges(range1::UnitRange{Int}, range2::UnitRange{Int}) =
    min(first(range1), first(range2)):max(last(range1), last(range2))

enclose_boxes(box1::Box, box2::Box) = (_enclose_ranges(box1[1], box2[1]),
                                       _enclose_ranges(box1[2], box2[2]))

_intersect_ranges(range1::UnitRange{Int}, range2::UnitRange{Int}) =
    max(first(range1), first(range2)):min(last(range1), last(range2))

intersect_boxes(box1::Box, box2::Box) = (_intersect_ranges(box1[1], box2[1]),
                                         _intersect_ranges(box1[2], box2[2]))

_ranges_overlap(range1::UnitRange{Int}, range2::UnitRange{Int}) =
    (first(range1) <= last(range2)) && (first(range2) <= last(range1))

boxes_overlap(box1::Box, box2::Box) = (_ranges_overlap(box1[1], box2[1]) &&
                                       _ranges_overlap(box1[2], box2[2]))

"""
    ImagePatch(img::Image, ce:CatalogEntry; radius_override_pix=NaN)

Attributes of a subsection of an Image around a point of interest.

# Attributes:
- `box`: The pixel range in the image.
- `psf`: The point spread function in the center of the image
- `itp_psf`: The point spread function in this region
- `wcs_jacobian`: The jacobian of the WCS transform in this region of the
                  sky for each band.
- `world_center`: A reference position in world coordinates.
- `pixel_center`: A reference position in pixel coordinates.
- `bitmap_offset`: Lower left corner index offset.
- `active_pixel_bitmap`: Boolean mask denoting which pixels in the patch are
                         considered when processing the source.
"""
struct ImagePatch
    box::Box
    world_center::Vector{Float64}

    psf::Vector{PsfComponent}
    itp_psf::AbstractInterpolation
    wcs_jacobian::Matrix{Float64}
    pixel_center::Vector{Float64}

    bitmap_offset::SVector{2, Int64}  # lower left corner index offset
    active_pixel_bitmap::Matrix{Bool}
end

function Base.show(io::IO, patch::ImagePatch)
    print(io, "$(length(patch.box[1]))×$(length(patch.box[2])) ImagePatch at $(patch.box)")
end

# construct `ImagePatch` from box of pixels on image.
function ImagePatch(img::Image, box::Box)
    # Crop off-image portion of box. Completely off-image boxes are
    # allowed and internally indicated with a range of 1:0 or H+1:H
    # (an empty range, but still a legal index to image pixels).
    box = clamp_box(box, (img.H, img.W))

    # Get linear WCS transform at center of box.
    pixel_center = [(first(box[1]) + last(box[1])) / 2
                    (first(box[2]) + last(box[2])) / 2]
    world_center = WCS.pix_to_world(img.wcs, pixel_center)
    wcs_jacobian = pixel_world_jacobian(img.wcs, pixel_center)

    # active pixel bitmap: make masked (NaN) pixels non-active
    box_offset = SVector(first(box[1]) - 1, first(box[2]) - 1)
    active_pixel_bitmap = [!isnan(img.pixels[x, y])
                           for x in box[1], y in box[2]]

    grid_psf = img.psfmap(pixel_center[1], pixel_center[2])
    grid_psf[:, :] = max.(grid_psf, 0.0)
    grid_psf += 1e-6
    grid_psf /= sum(grid_psf)
    # The following transformation is like softplus. Its inv always returns a
    # positive value. Without this transformation, even if the psf over the
    # grid_psf is positive, the iterpolation of grid with bicubic splines often
    # has negative values.
    grid_psf[:, :] = softpluslike.(grid_psf)

    itp_psf = interpolate(grid_psf, BSpline(Cubic(Line())), OnGrid())

    ImagePatch(box,
             world_center,
             img.psf,
             itp_psf,
             wcs_jacobian,
             pixel_center,
             box_offset,
             active_pixel_bitmap)
end

"""
    box_around_point(wcs, world_center, box_radius)

Choose patch indexes given center world coordinates and a box "radius" in
pixels.
"""
function box_around_point(wcs::WCS.WCSTransform, world_center::Vector{Float64},
                          pixel_radius::Real)
    pixel_center = WCS.world_to_pix(wcs, world_center)

    xmin = round(Int, pixel_center[1] - pixel_radius)
    xmax = round(Int, pixel_center[1] + pixel_radius)
    ymin = round(Int, pixel_center[2] - pixel_radius)
    ymax = round(Int, pixel_center[2] + pixel_radius)

    return (xmin:xmax, ymin:ymax)
end

"""
    box_from_catalog(img::Image, ce::CatalogEntry, scale)

Return a box extent based on `CatalogEntry` and `Image` parameters,
optionally scaled by a multiplicative factor `scale`. This is
useful when initialing an `ImagePatch` from a catalog rather than detections.
"""
function box_from_catalog(img::Image, ce::CatalogEntry;
                          width_scale=1.0, max_radius=25)

    pixel_radius = choose_patch_radius(ce, img; width_scale=width_scale,
                                       max_radius=max_radius)
    pixel_center = WCS.world_to_pix(img.wcs, ce.pos)

    xmin = round(Int, pixel_center[1] - pixel_radius)
    xmax = round(Int, pixel_center[1] + pixel_radius)
    ymin = round(Int, pixel_center[2] - pixel_radius)
    ymax = round(Int, pixel_center[2] + pixel_radius)

    return (xmin:xmax, ymin:ymax)
end

function get_sky_patches(images::Vector{<:Image},
                         catalog::Vector{CatalogEntry};
                         radius_override_pix=NaN)
    N = length(images)
    S = length(catalog)
    patches = Matrix{ImagePatch}(S, N)

    for n in 1:N, s in 1:S
        box = (isnan(radius_override_pix)?
               box_from_catalog(images[n], catalog[s]; width_scale=1.2):
               box_around_point(images[n].wcs, catalog[s].pos,
                                radius_override_pix))
        pixel_center = WCS.world_to_pix(images[n].wcs, catalog[s].pos)
        patches[s, n] = ImagePatch(images[n], box)
    end

    patches
end

"""
Choose a reasonable patch radius based on the catalog.

Args:
  - ce: The catalog entry for the object
  - img: The image
  - width_scale: A multiple of standard deviations to use
  - max_radius: The maximum radius in pixels.

Returns:
  - A radius in pixels chosen from the catalog entry.
"""
function choose_patch_radius(ce::CatalogEntry,
                             img::Image;
                             width_scale=1.0,
                             max_radius=25)
    psf_width = Model.get_psf_width(img.psf, width_scale=width_scale)

    # The galaxy scale is the point with half the light -- if the light
    # were entirely in a univariate normal, this would be at 0.67 standard
    # deviations.  We are being a bit conservative here.
    obj_width = ce.is_star ? 0.0 : width_scale * ce.gal_radius_px / 0.67
    obj_width += psf_width

    flux = ce.is_star ? ce.star_fluxes[img.b] : ce.gal_fluxes[img.b]
    if (!(flux > 0.)) @show ce end
    @assert flux > 0.

    # Choose enough pixels that the light is either 80% of the light
    # would be captured from a 1d gaussian or 5% of the sky noise,
    # whichever is a larger radius.
    epsilon = img.sky[div(img.H, 2), div(img.W, 2)]
    pdf_90 = exp(-0.5 * (1.64)^2) / (sqrt(2pi) * obj_width)
    pdf_target = min(pdf_90, epsilon / (20 * flux))
    rhs = log(pdf_target) + 0.5 * log(2pi) + log(obj_width)
    radius_req = sqrt(-2 * (obj_width ^ 2) * rhs)

    min(radius_req, max_radius)
end

"""
    find_neighbors(patches, target)

Return indexes of objects in `patches` whose boxes overlap the object
at index `target` in any image. (The first and second axes of `patches`
are over objects and images, respectively.)
"""
function find_neighbors(patches::Matrix{ImagePatch}, target::Int)
    neighbors = Int[]
    for i in 1:size(patches, 1)  # loop over objects
        i == target && continue
        for j in 1:size(patches, 2)  # loop over images
            if boxes_overlap(patches[target, j].box, patches[i, j].box)
                push!(neighbors, i)
                break
            end
        end
    end
    return neighbors
end


text:
using DynamicalSystems, PyPlot

cd()
mkpath("hhanim")

ds = Systems.henonheiles()

# Grid of initial conditions at given energy:

energy(x,y,px,py) = 0.5(px^2 + py^2) + potential(x,y)
potential(x, y) = 0.5(x^2 + y^2) + (x^2*y - (y^3)/3)
function generate_ics(E, n)
    ys = range(-0.4, stop = 1.0, length = n)
    pys = range(-0.5, stop = 0.5, length = n)
    ics = Vector{Vector{Float64}}()
    for y in ys
        V = potential(0.0, y)
        V ≥ E && continue
        for py in pys
            Ky = 0.5*(py^2)
            Ky + V ≥ E && continue
            px = sqrt(2(E - V - Ky))
            ic = [0.0, y, px, py]
            push!(ics, [0.0, y, px, py])
        end
    end
    return ics
end

Emin = 0.1
Emax = 1/6
Es = range(Emin, stop = Emax, length = 100)

density = 20
tfinal = 2000.0
tgali = 1000.0
tinteg = tangent_integrator(ds, 4)

# Initialize required stuff for plotting
mpl = PyPlot.matplotlib
norm = mpl[:colors][:Normalize](0.0, 1.0)
c_m = mpl[:cm][:Spectral]
s_m = mpl[:cm][:ScalarMappable](cmap=c_m, norm=norm)
s_m[:set_array]([])

# %%
ioff()
for j in 1:length(Es)
    j==1 && (tim = time())
    E = Es[j]
    println("Energy $(j)/$(length(Es))")
    figure(figsize = (12, 8))
    ax = gca()

    ics = generate_ics(E, density)

    for u in ics

        # compute section:
        psos = poincaresos(ds, (1, 0.0), tfinal; u0 = u)

        # compute gali (using advanced usage)
        reinit!(tinteg, u, orthonormal(4,4))
        regularity = gali(tinteg, tgali, 1, 1e-12)[2][end]/tgali

        # Plot PSOS with color corresponding to regularity
        y = psos[:, 2]; py = psos[:, 4]
        plot(y, py, ls = "None", ms = 0.8, marker = "o",
        color = s_m[:to_rgba](regularity), alpha = 0.75)
    end
    cb = colorbar(s_m, ticks=[])
    # cb = colorbar(s_m, ticks=[lowerend, 1.0])
    # cb[:ax][:set_yticklabels](["chaotic", "periodic"], rotation="vertical")
    cb[:set_label]("regularity")
    xlim(-0.55, 1.05)
    ylim(-0.65, 0.65)
    xlabel("\$y\$")
    ylabel("\$p_y\$")
    text(0.7, 0.9, "\$E = $(round(E, digits=5))\$", transform = ax[:transAxes])
    tight_layout()
    savefig("hhanim/galipsos_$j.png", dpi = 200)
    if j == 1
        ttim = time()
        println("Average time per energy: $(round(ttim - tim, digits=3)) secs")
    end
end
close("all")
ion()

# %% produce animation

framerate = 10
savename = "hhanim/galipsos"
anim = `ffmpeg -y -framerate $(framerate) -start_number 1 -i $(savename)_%d.png
-c:v libx264 -pix_fmt yuv420p -preset veryslow -profile:v baseline
-filter:v scale=1200:-1 -b:v 2048k -level 3.0 $(savename).mp4`
run(anim)

if true
    for i in 1:length(Es)
        rm(savename*"_$(i).png")
    end
end


text:
@testset "simulation.jl" begin
    # simulation.jl is tested thoroughly throughout the other tests.
    # TODO: process store
end


text:
module BLAST

export blastn,
       blastp,
       readblastXML,
       BLASTResult

using Bio.Seq,
      Bio.Align,
      LightXML

include("blastcommandline.jl")

end # module BLAST


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

@test integrate(x^-1*(a*x^m+b*log(c*x^n)^q)^3*log(c*x^n)^(-1+q), x) == :(1//4*b^3*n^-1*q^-1*log(c*x^n)^(4q)+-1*3^(-1q)*a^3*n^-1*x^(3m)*(c*x^n)^(-3*m*n^-1)*(-1*m*n^-1*log(c*x^n))^(-1q)*log(c*x^n)^q*SpecialFunctions.gamma(q,-3*m*n^-1*log(c*x^n))+-3*a*b^2*n^-1*x^m*(c*x^n)^(-1*m*n^-1)*(-1*m*n^-1*log(c*x^n))^(-3q)*log(c*x^n)^(3q)*SpecialFunctions.gamma(3q,-1*m*n^-1*log(c*x^n))+-3*b*4^(-1q)*a^2*n^-1*x^(2m)*(c*x^n)^(-2*m*n^-1)*(-1*m*n^-1*log(c*x^n))^(-2q)*log(c*x^n)^(2q)*SpecialFunctions.gamma(2q,-2*m*n^-1*log(c*x^n)))
@test integrate(x^-1*(a*x^m+b*log(c*x^n)^q)^2*log(c*x^n)^(-1+q), x) == :(1//3*b^2*n^-1*q^-1*log(c*x^n)^(3q)+-1*2^(-1q)*a^2*n^-1*x^(2m)*(c*x^n)^(-2*m*n^-1)*(-1*m*n^-1*log(c*x^n))^(-1q)*log(c*x^n)^q*SpecialFunctions.gamma(q,-2*m*n^-1*log(c*x^n))+-2*a*b*n^-1*x^m*(c*x^n)^(-1*m*n^-1)*(-1*m*n^-1*log(c*x^n))^(-2q)*log(c*x^n)^(2q)*SpecialFunctions.gamma(2q,-1*m*n^-1*log(c*x^n)))
@test integrate(x^-1*log(c*x^n)^(-1+q)*(a*x^m+b*log(c*x^n)^q), x) == :((1/2)*b*n^-1*q^-1*log(c*x^n)^(2q)+-1*a*n^-1*x^m*(c*x^n)^(-1*m*n^-1)*(-1*m*n^-1*log(c*x^n))^(-1q)*log(c*x^n)^q*SpecialFunctions.gamma(q,-1*m*n^-1*log(c*x^n)))
@test integrate(x^-1*log(c*x^n)^(-1+q), x) == :(n^-1*q^-1*log(c*x^n)^q)
@test integrate(x^-1*(a*x^m+b*log(c*x^n)^2)^3*log(c*x^n), x) == :(1//8*b^3*n^-1*log(c*x^n)^8+-1//9*n*a^3*m^-2*x^(3m)+1//3*a^3*m^-1*x^(3m)*log(c*x^n)+-360*a*b^2*m^-6*n^5*x^m+3*a*b^2*m^-1*x^m*log(c*x^n)^5+-9//8*b*a^2*m^-4*n^3*x^(2m)+3//2*b*a^2*m^-1*x^(2m)*log(c*x^n)^3+-180*a*b^2*m^-4*n^3*x^m*log(c*x^n)^2+-15*a*n*b^2*m^-2*x^m*log(c*x^n)^4+60*a*b^2*m^-3*n^2*x^m*log(c*x^n)^3+360*a*b^2*m^-5*n^4*x^m*log(c*x^n)+-9//4*b*n*a^2*m^-2*x^(2m)*log(c*x^n)^2+9//4*b*a^2*m^-3*n^2*x^(2m)*log(c*x^n))
@test integrate(x^-1*(a*x^m+b*log(c*x^n)^2)^2*log(c*x^n), x) == :(1//6*b^2*n^-1*log(c*x^n)^6+(1/2)*a^2*m^-1*x^(2m)*log(c*x^n)+-1//4*n*a^2*m^-2*x^(2m)+-12*a*b*m^-4*n^3*x^m+2*a*b*m^-1*x^m*log(c*x^n)^3+-6*a*b*n*m^-2*x^m*log(c*x^n)^2+12*a*b*m^-3*n^2*x^m*log(c*x^n))
@test integrate(x^-1*(a*x^m+b*log(c*x^n)^2)*log(c*x^n), x) == :(1//4*b*n^-1*log(c*x^n)^4+a*m^-1*x^m*log(c*x^n)+-1*a*n*m^-2*x^m)
@test integrate(x^-1*log(c*x^n), x) == :((1/2)*n^-1*log(c*x^n)^2)
@test integrate(x^-1*(a*x^m+b*log(c*x^n)^q)^p*(a*m*x^m+b*n*q*log(c*x^n)^(-1+q)), x) == :((1+p)^-1*(a*x^m+b*log(c*x^n)^q)^(1+p))
@test integrate(x^-1*(a*x^m+b*log(c*x^n)^q)^2*(a*m*x^m+b*n*q*log(c*x^n)^(-1+q)), x) == :(1//3*(a*x^m+b*log(c*x^n)^q)^3)
@test integrate(x^-1*(a*x^m+b*log(c*x^n)^q)*(a*m*x^m+b*n*q*log(c*x^n)^(-1+q)), x) == :((1/2)*(a*x^m+b*log(c*x^n)^q)^2)
@test integrate(x^-1*(a*m*x^m+b*n*q*log(c*x^n)^(-1+q)), x) == :(a*x^m+b*log(c*x^n)^q)
@test integrate(x^-1*(a*x^m+b*log(c*x^n)^q)^-1*(a*m*x^m+b*n*q*log(c*x^n)^(-1+q)), x) == :(log(a*x^m+b*log(c*x^n)^q))
@test integrate(x^-1*(a*x^m+b*log(c*x^n)^q)^-2*(a*m*x^m+b*n*q*log(c*x^n)^(-1+q)), x) == :(-1*(a*x^m+b*log(c*x^n)^q)^-1)
@test integrate(x^-1*(a*x^m+b*log(c*x^n)^q)^-3*(a*m*x^m+b*n*q*log(c*x^n)^(-1+q)), x) == :(-1//2*(a*x^m+b*log(c*x^n)^q)^-2)
@test integrate((a*x^2+b*x*log(c*x^n)^2)^2*(a*x^-2+2*b*n*x^-3*log(c*x^n)), x) == :(1//3*(a*x+b*log(c*x^n)^2)^3)
@test integrate((a*x^-1+2*b*n*x^-2*log(c*x^n))*(a*x^2+b*x*log(c*x^n)^2), x) == :((1/2)*(a*x+b*log(c*x^n)^2)^2)
@test integrate(a+2*b*n*x^-1*log(c*x^n), x) == :(a*x+b*log(c*x^n)^2)
@test integrate((a*x^2+b*x*log(c*x^n)^2)^-1*(a*x+2*b*n*log(c*x^n)), x) == :(log(a*x+b*log(c*x^n)^2))
@test integrate((a*x^2+b*x*log(c*x^n)^2)^-2*(a*x^2+2*b*n*x*log(c*x^n)), x) == :(-1*(a*x+b*log(c*x^n)^2)^-1)
@test integrate((a*x^2+b*x*log(c*x^n)^2)^-3*(a*x^3+2*b*n*x^2*log(c*x^n)), x) == :(-1//2*(a*x+b*log(c*x^n)^2)^-2)
@test integrate((a*x^m+b*x*log(c*x^n)^q)^-1*(a*x^(-1+m)*(-1+m)+b*n*q*log(c*x^n)^(-1+q)), x) == :(log(a*x^(-1+m)+b*log(c*x^n)^q))
@test integrate(x^-1*(a*x^m+b*log(c*x^n)^q)^3*(d*x^m+e*log(c*x^n)^(-1+q)), x) == :(1//4*e*b^-1*n^-1*q^-1*(a*x^m+b*log(c*x^n)^q)^4+-1//4*a^3*b^-1*m^-1*n^-1*q^-1*x^(4m)*(a*e*m+-1*b*d*n*q)+-1*b^2*m^-1*n^-1*q^-1*x^m*(c*x^n)^(-1*m*n^-1)*(-1*m*n^-1*log(c*x^n))^(-3q)*log(c*x^n)^(3q)*(a*e*m+-1*b*d*n*q)*SpecialFunctions.gamma(1+3q,-1*m*n^-1*log(c*x^n))+-1*3^(-1q)*a^2*m^-1*n^-1*q^-1*x^(3m)*(c*x^n)^(-3*m*n^-1)*(-1*m*n^-1*log(c*x^n))^(-1q)*log(c*x^n)^q*(a*e*m+-1*b*d*n*q)*SpecialFunctions.gamma(1+q,-3*m*n^-1*log(c*x^n))+-3*a*b*2^(-1+-2q)*m^-1*n^-1*q^-1*x^(2m)*(c*x^n)^(-2*m*n^-1)*(-1*m*n^-1*log(c*x^n))^(-2q)*log(c*x^n)^(2q)*(a*e*m+-1*b*d*n*q)*SpecialFunctions.gamma(1+2q,-2*m*n^-1*log(c*x^n)))
@test integrate(x^-1*(a*x^m+b*log(c*x^n)^q)^2*(d*x^m+e*log(c*x^n)^(-1+q)), x) == :(1//3*e*b^-1*n^-1*q^-1*(a*x^m+b*log(c*x^n)^q)^3+-1//3*a^2*b^-1*m^-1*n^-1*q^-1*x^(3m)*(a*e*m+-1*b*d*n*q)+-1*b*m^-1*n^-1*q^-1*x^m*(c*x^n)^(-1*m*n^-1)*(-1*m*n^-1*log(c*x^n))^(-2q)*log(c*x^n)^(2q)*(a*e*m+-1*b*d*n*q)*SpecialFunctions.gamma(1+2q,-1*m*n^-1*log(c*x^n))+-1*a*2^(-1q)*m^-1*n^-1*q^-1*x^(2m)*(c*x^n)^(-2*m*n^-1)*(-1*m*n^-1*log(c*x^n))^(-1q)*log(c*x^n)^q*(a*e*m+-1*b*d*n*q)*SpecialFunctions.gamma(1+q,-2*m*n^-1*log(c*x^n)))
@test integrate(x^-1*(a*x^m+b*log(c*x^n)^q)*(d*x^m+e*log(c*x^n)^(-1+q)), x) == :((1/2)*e*b^-1*n^-1*q^-1*(a*x^m+b*log(c*x^n)^q)^2+x^m*(c*x^n)^(-1*m*n^-1)*(-1*m*n^-1*log(c*x^n))^(-1q)*log(c*x^n)^q*(b*d*m^-1+-1*a*e*n^-1*q^-1)*SpecialFunctions.gamma(1+q,-1*m*n^-1*log(c*x^n))+-1//2*a*b^-1*m^-1*n^-1*q^-1*x^(2m)*(a*e*m+-1*b*d*n*q))
@test integrate(x^-1*(d*x^m+e*log(c*x^n)^(-1+q)), x) == :(d*m^-1*x^m+e*n^-1*q^-1*log(c*x^n)^q)
@test integrate(x^-1*(a*x^m+b*log(c*x^n)^q)^-2*(a*d*n*x^m+-1*a*d*m*x^m*log(c*x^n)+-1*b*d*n*log(c*x^n)^q*(-1+q)), x) == :(d*(a*x^m+b*log(c*x^n)^q)^-1*log(c*x^n))
@test integrate((d+e*x^2)^-1*log(2*x*(d+e*x^2)^-1*(d*(-1*e*d^-1)^(1/2)+e*x)), x) == :(-1//2*e^-1*(-1*e*d^-1)^(1/2)*Polylogarithms.polylog(2,1+-2*x*(d+e*x^2)^-1*(d*(-1*e*d^-1)^(1/2)+e*x)))
@test integrate((d+e*x^2)^-1*log(-2*x*(d+e*x^2)^-1*(d*(-1*e*d^-1)^(1/2)+-1*e*x)), x) == :((1/2)*e^-1*(-1*e*d^-1)^(1/2)*Polylogarithms.polylog(2,1+2*x*(d+e*x^2)^-1*(d*(-1*e*d^-1)^(1/2)+-1*e*x)))
@test integrate((d+e*x^2)^-1*log(2*x*(d+e*x^2)^-1*(e*x+d*e^(1/2)*(-1d)^-1//2)), x) == :(-1//2*e^-1//2*(-1d)^-1//2*Polylogarithms.polylog(2,1+2*x*e^(1/2)*(d+e*x^2)^-1*((-1d)^(1/2)+-1*x*e^(1/2))))
@test integrate((d+e*x^2)^-1*log(-2*x*(d+e*x^2)^-1*(-1*e*x+d*e^(1/2)*(-1d)^-1//2)), x) == :((1/2)*e^-1//2*(-1d)^-1//2*Polylogarithms.polylog(2,1+-2*x*e^(1/2)*(d+e*x^2)^-1*((-1d)^(1/2)+x*e^(1/2))))
@test integrate((d+e*x^2)^-1*log(2*x*(d+e*x^2)^-1*(e*x+d^(1/2)*(-1*e)^(1/2))), x) == :((1/2)*d^-1//2*(-1*e)^-1//2*Polylogarithms.polylog(2,1+-2*x*(d+e*x^2)^-1*(e*x+d^(1/2)*(-1*e)^(1/2))))
@test integrate((d+e*x^2)^-1*log(-2*x*(d+e*x^2)^-1*(d^(1/2)*(-1*e)^(1/2)+-1*e*x)), x) == :(-1//2*d^-1//2*(-1*e)^-1//2*Polylogarithms.polylog(2,1+2*x*(d+e*x^2)^-1*(d^(1/2)*(-1*e)^(1/2)+-1*e*x)))
@test integrate((e*x)^m*(a+b*log(c*log(d*x)^p)), x) == :(e^-1*(e*x)^(1+m)*(1+m)^-1*(a+b*log(c*log(d*x)^p))+-1*b*p*e^-1*(d*x)^(-1+-1m)*(e*x)^(1+m)*(1+m)^-1*expintegralei((1+m)*log(d*x)))
@test integrate((e*x)^m*(a+b*log(c*log(d*x^n)^p)), x) == :(e^-1*(e*x)^(1+m)*(1+m)^-1*(a+b*log(c*log(d*x^n)^p))+-1*b*p*e^-1*(d*x^n)^(-1*n^-1*(1+m))*(e*x)^(1+m)*(1+m)^-1*expintegralei(n^-1*(1+m)*log(d*x^n)))
@test integrate(x^2*(a+b*log(c*log(d*x^n)^p)), x) == :(1//3*x^3*(a+b*log(c*log(d*x^n)^p))+-1//3*b*p*x^3*(d*x^n)^(-3*n^-1)*expintegralei(3*n^-1*log(d*x^n)))
@test integrate(x*(a+b*log(c*log(d*x^n)^p)), x) == :((1/2)*x^2*(a+b*log(c*log(d*x^n)^p))+-1//2*b*p*x^2*(d*x^n)^(-2*n^-1)*expintegralei(2*n^-1*log(d*x^n)))
@test integrate(a+b*log(c*log(d*x^n)^p), x) == :(a*x+b*x*log(c*log(d*x^n)^p)+-1*b*p*x*(d*x^n)^(-1*n^-1)*expintegralei(n^-1*log(d*x^n)))
@test integrate(x^-1*(a+b*log(c*log(d*x^n)^p)), x) == :(n^-1*(a+b*log(c*log(d*x^n)^p))*log(d*x^n)+-1*b*p*log(x))
@test integrate(x^-2*(a+b*log(c*log(d*x^n)^p)), x) == :(-1*x^-1*(a+b*log(c*log(d*x^n)^p))+b*p*x^-1*(d*x^n)^(n^-1)*expintegralei(-1*n^-1*log(d*x^n)))
@test integrate(x^-3*(a+b*log(c*log(d*x^n)^p)), x) == :(-1//2*x^-2*(a+b*log(c*log(d*x^n)^p))+(1/2)*b*p*x^-2*(d*x^n)^(2*n^-1)*expintegralei(-2*n^-1*log(d*x^n)))
@test integrate(x^-4*(a+b*log(c*log(d*x^n)^p)), x) == :(-1//3*x^-3*(a+b*log(c*log(d*x^n)^p))+1//3*b*p*x^-3*(d*x^n)^(3*n^-1)*expintegralei(-3*n^-1*log(d*x^n)))
@test integrate(log(c*log(d*x)^p), x) == :(x*log(c*log(d*x)^p)+-1*p*d^-1*logintegral(d*x))
@test integrate(x^-1*log(c*log(d*x)^p), x) == :(log(c*log(d*x)^p)*log(d*x)+-1*p*log(x))
@test integrate(log(c*log(d*x^n)^p), x) == :(x*log(c*log(d*x^n)^p)+-1*p*x*(d*x^n)^(-1*n^-1)*expintegralei(n^-1*log(d*x^n)))
@test integrate(x^-1*log(c*log(d*x^n)^p), x) == :(-1*p*log(x)+n^-1*log(c*log(d*x^n)^p)*log(d*x^n))
@test integrate(x^4*log(d*(b*x+c*x^2)^n), x) == :(-2//25*n*x^5+1//5*x^5*log(d*(b*x+c*x^2)^n)+-1//5*n*x*b^4*c^-4+-1//15*n*b^2*c^-2*x^3+1//5*n*b^5*c^-5*log(b+c*x)+1//10*n*b^3*c^-3*x^2+1//20*b*n*c^-1*x^4)
@test integrate(x^3*log(d*(b*x+c*x^2)^n), x) == :(-1//8*n*x^4+1//4*x^4*log(d*(b*x+c*x^2)^n)+-1//4*n*b^4*c^-4*log(b+c*x)+-1//8*n*b^2*c^-2*x^2+1//4*n*x*b^3*c^-3+1//12*b*n*c^-1*x^3)
@test integrate(x^2*log(d*(b*x+c*x^2)^n), x) == :(-2//9*n*x^3+1//3*x^3*log(d*(b*x+c*x^2)^n)+-1//3*n*x*b^2*c^-2+1//3*n*b^3*c^-3*log(b+c*x)+1//6*b*n*c^-1*x^2)
@test integrate(x*log(d*(b*x+c*x^2)^n), x) == :((1/2)*x^2*log(d*(b*x+c*x^2)^n)+-1//2*n*x^2+(1/2)*b*n*x*c^-1+-1//2*n*b^2*c^-2*log(b+c*x))
@test integrate(log(d*(b*x+c*x^2)^n), x) == :(x*log(d*(b*x+c*x^2)^n)+-2*n*x+b*n*c^-1*log(b+c*x))
@test integrate(x^-1*log(d*(b*x+c*x^2)^n), x) == :(log(x)*log(d*(b*x+c*x^2)^n)+-1*n*Polylogarithms.polylog(2,-1*c*x*b^-1)+-1//2*n*log(x)^2+-1*n*log(x)*log(1+c*x*b^-1))
@test integrate(x^-2*log(d*(b*x+c*x^2)^n), x) == :(-1*n*x^-1+-1*x^-1*log(d*(b*x+c*x^2)^n)+c*n*b^-1*log(x)+-1*c*n*b^-1*log(b+c*x))
@test integrate(x^-3*log(d*(b*x+c*x^2)^n), x) == :(-1//2*x^-2*log(d*(b*x+c*x^2)^n)+-1//4*n*x^-2+(1/2)*n*b^-2*c^2*log(b+c*x)+-1//2*c*n*b^-1*x^-1+-1//2*n*b^-2*c^2*log(x))
@test integrate(x^-4*log(d*(b*x+c*x^2)^n), x) == :(-1//3*x^-3*log(d*(b*x+c*x^2)^n)+-1//9*n*x^-3+-1//3*n*b^-3*c^3*log(b+c*x)+-1//6*c*n*b^-1*x^-2+1//3*n*b^-3*c^3*log(x)+1//3*n*b^-2*c^2*x^-1)
@test integrate(x^-5*log(d*(b*x+c*x^2)^n), x) == :(-1//4*x^-4*log(d*(b*x+c*x^2)^n)+-1//16*n*x^-4+-1//4*n*b^-4*c^4*log(x)+-1//4*n*b^-3*c^3*x^-1+-1//12*c*n*b^-1*x^-3+1//4*n*b^-4*c^4*log(b+c*x)+1//8*n*b^-2*c^2*x^-2)
@test integrate(x^4*log(d*(a+b*x+c*x^2)^n), x) == :(-2//25*n*x^5+1//5*x^5*log(d*(a+b*x+c*x^2)^n)+-1//5*n*x*c^-4*(b^4+2*a^2*c^2+-4*a*c*b^2)+-1//15*n*c^-2*x^3*(b^2+-2*a*c)+1//20*b*n*c^-1*x^4+1//5*n*c^-5*(b^2+-4*a*c)^(1/2)*(b^4+a^2*c^2+-3*a*c*b^2)*arctanh((b^2+-4*a*c)^-1//2*(b+2*c*x))+1//10*b*n*c^-5*(b^4+5*a^2*c^2+-5*a*c*b^2)*log(a+b*x+c*x^2)+1//10*b*n*c^-3*x^2*(b^2+-3*a*c))
@test integrate(x^3*log(d*(a+b*x+c*x^2)^n), x) == :(-1//8*n*x^4+1//4*x^4*log(d*(a+b*x+c*x^2)^n)+-1//8*n*c^-4*(b^4+2*a^2*c^2+-4*a*c*b^2)*log(a+b*x+c*x^2)+-1//8*n*c^-2*x^2*(b^2+-2*a*c)+1//12*b*n*c^-1*x^3+1//4*b*n*x*c^-3*(b^2+-3*a*c)+-1//4*b*n*c^-4*(b^2+-4*a*c)^(1/2)*(b^2+-2*a*c)*arctanh((b^2+-4*a*c)^-1//2*(b+2*c*x)))
@test integrate(x^2*log(d*(a+b*x+c*x^2)^n), x) == :(-2//9*n*x^3+1//3*x^3*log(d*(a+b*x+c*x^2)^n)+-1//3*n*x*c^-2*(b^2+-2*a*c)+1//6*b*n*c^-1*x^2+1//3*n*c^-3*(b^2+-4*a*c)^(1/2)*(b^2+-1*a*c)*arctanh((b^2+-4*a*c)^-1//2*(b+2*c*x))+1//6*b*n*c^-3*(b^2+-3*a*c)*log(a+b*x+c*x^2))
@test integrate(x*log(d*(a+b*x+c*x^2)^n), x) == :((1/2)*x^2*log(d*(a+b*x+c*x^2)^n)+-1//2*n*x^2+(1/2)*b*n*x*c^-1+-1//4*n*c^-2*(b^2+-2*a*c)*log(a+b*x+c*x^2)+-1//2*b*n*c^-2*(b^2+-4*a*c)^(1/2)*arctanh((b^2+-4*a*c)^-1//2*(b+2*c*x)))
@test integrate(log(d*(a+b*x+c*x^2)^n), x) == :(x*log(d*(a+b*x+c*x^2)^n)+-2*n*x+n*c^-1*(b^2+-4*a*c)^(1/2)*arctanh((b^2+-4*a*c)^-1//2*(b+2*c*x))+(1/2)*b*n*c^-1*log(a+b*x+c*x^2))
@test integrate(x^-1*log(d*(a+b*x+c*x^2)^n), x) == :(log(x)*log(d*(a+b*x+c*x^2)^n)+-1*n*Polylogarithms.polylog(2,-2*c*x*(b+(b^2+-4*a*c)^(1/2))^-1)+-1*n*Polylogarithms.polylog(2,-2*c*x*(b+-1*(b^2+-4*a*c)^(1/2))^-1)+-1*n*log(x)*log(1+2*c*x*(b+(b^2+-4*a*c)^(1/2))^-1)+-1*n*log(x)*log(1+2*c*x*(b+-1*(b^2+-4*a*c)^(1/2))^-1))
@test integrate(x^-2*log(d*(a+b*x+c*x^2)^n), x) == :(-1*x^-1*log(d*(a+b*x+c*x^2)^n)+b*n*a^-1*log(x)+n*a^-1*(b^2+-4*a*c)^(1/2)*arctanh((b^2+-4*a*c)^-1//2*(b+2*c*x))+-1//2*b*n*a^-1*log(a+b*x+c*x^2))
@test integrate(x^-3*log(d*(a+b*x+c*x^2)^n), x) == :(-1//2*x^-2*log(d*(a+b*x+c*x^2)^n)+-1//2*b*n*a^-1*x^-1+-1//2*n*a^-2*(b^2+-2*a*c)*log(x)+1//4*n*a^-2*(b^2+-2*a*c)*log(a+b*x+c*x^2)+-1//2*b*n*a^-2*(b^2+-4*a*c)^(1/2)*arctanh((b^2+-4*a*c)^-1//2*(b+2*c*x)))
@test integrate(x^-4*log(d*(a+b*x+c*x^2)^n), x) == :(-1//3*x^-3*log(d*(a+b*x+c*x^2)^n)+-1//6*b*n*a^-1*x^-2+1//3*n*a^-2*x^-1*(b^2+-2*a*c)+-1//6*b*n*a^-3*(b^2+-3*a*c)*log(a+b*x+c*x^2)+1//3*b*n*a^-3*(b^2+-3*a*c)*log(x)+1//3*n*a^-3*(b^2+-4*a*c)^(1/2)*(b^2+-1*a*c)*arctanh((b^2+-4*a*c)^-1//2*(b+2*c*x)))
@test integrate(x^-5*log(d*(a+b*x+c*x^2)^n), x) == :(-1//4*x^-4*log(d*(a+b*x+c*x^2)^n)+-1//4*n*a^-4*(b^4+2*a^2*c^2+-4*a*c*b^2)*log(x)+-1//12*b*n*a^-1*x^-3+1//8*n*a^-4*(b^4+2*a^2*c^2+-4*a*c*b^2)*log(a+b*x+c*x^2)+1//8*n*a^-2*x^-2*(b^2+-2*a*c)+-1//4*b*n*a^-3*x^-1*(b^2+-3*a*c)+-1//4*b*n*a^-4*(b^2+-4*a*c)^(1/2)*(b^2+-2*a*c)*arctanh((b^2+-4*a*c)^-1//2*(b+2*c*x)))
@test integrate(log(1+x+x^2), x) == :((1/2)*log(1+x+x^2)+-2x+x*log(1+x+x^2)+3^(1/2)*arctan(1//3*3^(1/2)*(1+2x)))
@test integrate((d+e*x)^4*log(d*(a+b*x+c*x^2)^n), x) == :(-2//25*n*e^4*x^5+1//5*e^-1*(d+e*x)^5*log(d*(a+b*x+c*x^2)^n)+-1//5*n*x*c^-4*(b^4*e^4+10*c^4*d^4+c^2*e^2*(2*a^2*e^2+10*b^2*d^2+15*a*b*d*e)+-1*c*b^2*e^3*(4*a*e+5*b*d)+-10*e*c^3*d^2*(b*d+2*a*e))+-1//10*e*n*c^-3*x^2*(-1*b^3*e^3+20*c^3*d^3+b*c*e^2*(3*a*e+5*b*d)+-10*d*e*c^2*(a*e+b*d))+-1//15*n*c^-2*e^2*x^3*(b^2*e^2+20*c^2*d^2+-1*c*e*(2*a*e+5*b*d))+-1//20*n*c^-1*e^3*x^4*(-1*b*e+10*c*d)+1//5*n*c^-5*(b^2+-4*a*c)^(1/2)*(b^4*e^4+5*c^4*d^4+c^2*e^2*(a^2*e^2+10*b^2*d^2+10*a*b*d*e)+-1*c*b^2*e^3*(3*a*e+5*b*d)+-10*e*c^3*d^2*(a*e+b*d))*arctanh((b^2+-4*a*c)^-1//2*(b+2*c*x))+-1//10*n*c^-5*e^-1*(-1*b*e+2*c*d)*(b^4*e^4+c^4*d^4+c^2*e^2*(4*b^2*d^2+5*a^2*e^2+10*a*b*d*e)+-1*c*b^2*e^3*(3*b*d+5*a*e)+-2*e*c^3*d^2*(b*d+5*a*e))*log(a+b*x+c*x^2))
@test integrate((d+e*x)^3*log(d*(a+b*x+c*x^2)^n), x) == :(-1//8*n*e^3*x^4+1//4*e^-1*(d+e*x)^4*log(d*(a+b*x+c*x^2)^n)+-1//4*n*x*c^-3*(-1*b^3*e^3+8*c^3*d^3+b*c*e^2*(3*a*e+4*b*d)+-2*d*e*c^2*(3*b*d+4*a*e))+-1//8*e*n*c^-2*x^2*(b^2*e^2+12*c^2*d^2+-2*c*e*(a*e+2*b*d))+-1//8*n*c^-4*e^-1*(b^4*e^4+2*c^4*d^4+2*c^2*e^2*(a^2*e^2+3*b^2*d^2+6*a*b*d*e)+-4*c*b^2*e^3*(a*e+b*d)+-4*e*c^3*d^2*(b*d+3*a*e))*log(a+b*x+c*x^2)+-1//12*n*c^-1*e^2*x^3*(-1*b*e+8*c*d)+1//4*n*c^-4*(b^2+-4*a*c)^(1/2)*(-1*b*e+2*c*d)*(b^2*e^2+2*c^2*d^2+-2*c*e*(a*e+b*d))*arctanh((b^2+-4*a*c)^-1//2*(b+2*c*x)))
@test integrate((d+e*x)^2*log(d*(a+b*x+c*x^2)^n), x) == :(-2//9*n*e^2*x^3+1//3*e^-1*(d+e*x)^3*log(d*(a+b*x+c*x^2)^n)+-1//3*n*x*c^-2*(b^2*e^2+6*c^2*d^2+-1*c*e*(2*a*e+3*b*d))+-1//6*e*n*c^-1*x^2*(-1*b*e+6*c*d)+1//3*n*c^-3*(b^2+-4*a*c)^(1/2)*(b^2*e^2+3*c^2*d^2+-1*c*e*(a*e+3*b*d))*arctanh((b^2+-4*a*c)^-1//2*(b+2*c*x))+-1//6*n*c^-3*e^-1*(-1*b*e+2*c*d)*(b^2*e^2+c^2*d^2+-1*c*e*(b*d+3*a*e))*log(a+b*x+c*x^2))
@test integrate((d+e*x)*log(d*(a+b*x+c*x^2)^n), x) == :(n*x*(-2d+(1/2)*b*e*c^-1)+(1/2)*e^-1*(d+e*x)^2*log(d*(a+b*x+c*x^2)^n)+-1//2*e*n*x^2+(1/2)*n*c^-2*(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))+-1//4*n*c^-2*e^-1*(b^2*e^2+2*c^2*d^2+-2*c*e*(a*e+b*d))*log(a+b*x+c*x^2))
@test integrate(log(d*(a+b*x+c*x^2)^n), x) == :(x*log(d*(a+b*x+c*x^2)^n)+-2*n*x+n*c^-1*(b^2+-4*a*c)^(1/2)*arctanh((b^2+-4*a*c)^-1//2*(b+2*c*x))+(1/2)*b*n*c^-1*log(a+b*x+c*x^2))
@test integrate((d+e*x)^-1*log(d*(a+b*x+c*x^2)^n), x) == :(e^-1*log(d*(a+b*x+c*x^2)^n)*log(d+e*x)+-1*n*e^-1*Polylogarithms.polylog(2,2*c*(-1*e*(b+(b^2+-4*a*c)^(1/2))+2*c*d)^-1*(d+e*x))+-1*n*e^-1*Polylogarithms.polylog(2,2*c*(-1*e*(b+-1*(b^2+-4*a*c)^(1/2))+2*c*d)^-1*(d+e*x))+-1*n*e^-1*log(-1*e*(-1*e*(b+(b^2+-4*a*c)^(1/2))+2*c*d)^-1*(b+(b^2+-4*a*c)^(1/2)+2*c*x))*log(d+e*x)+-1*n*e^-1*log(-1*e*(-1*e*(b+-1*(b^2+-4*a*c)^(1/2))+2*c*d)^-1*(b+-1*(b^2+-4*a*c)^(1/2)+2*c*x))*log(d+e*x))
@test integrate((d+e*x)^-2*log(d*(a+b*x+c*x^2)^n), x) == :(-1*e^-1*(d+e*x)^-1*log(d*(a+b*x+c*x^2)^n)+n*(b^2+-4*a*c)^(1/2)*(a*e^2+c*d^2+-1*b*d*e)^-1*arctanh((b^2+-4*a*c)^-1//2*(b+2*c*x))+(1/2)*n*e^-1*(a*e^2+c*d^2+-1*b*d*e)^-1*(-1*b*e+2*c*d)*log(a+b*x+c*x^2)+-1*n*e^-1*(a*e^2+c*d^2+-1*b*d*e)^-1*(-1*b*e+2*c*d)*log(d+e*x))
@test integrate((d+e*x)^-3*log(d*(a+b*x+c*x^2)^n), x) == :(-1//2*e^-1*(d+e*x)^-2*log(d*(a+b*x+c*x^2)^n)+(1/2)*n*e^-1*(d+e*x)^-1*(a*e^2+c*d^2+-1*b*d*e)^-1*(-1*b*e+2*c*d)+(1/2)*n*(b^2+-4*a*c)^(1/2)*(a*e^2+c*d^2+-1*b*d*e)^-2*(-1*b*e+2*c*d)*arctanh((b^2+-4*a*c)^-1//2*(b+2*c*x))+-1//2*n*e^-1*(a*e^2+c*d^2+-1*b*d*e)^-2*(b^2*e^2+2*c^2*d^2+-2*c*e*(a*e+b*d))*log(d+e*x)+1//4*n*e^-1*(a*e^2+c*d^2+-1*b*d*e)^-2*(b^2*e^2+2*c^2*d^2+-2*c*e*(a*e+b*d))*log(a+b*x+c*x^2))
@test integrate((d+e*x)^-4*log(d*(a+b*x+c*x^2)^n), x) == :(-1//3*e^-1*(d+e*x)^-3*log(d*(a+b*x+c*x^2)^n)+1//3*n*e^-1*(d+e*x)^-1*(a*e^2+c*d^2+-1*b*d*e)^-2*(b^2*e^2+2*c^2*d^2+-2*c*e*(a*e+b*d))+1//3*n*(b^2+-4*a*c)^(1/2)*(a*e^2+c*d^2+-1*b*d*e)^-3*(b^2*e^2+3*c^2*d^2+-1*c*e*(a*e+3*b*d))*arctanh((b^2+-4*a*c)^-1//2*(b+2*c*x))+1//6*n*e^-1*(d+e*x)^-2*(a*e^2+c*d^2+-1*b*d*e)^-1*(-1*b*e+2*c*d)+-1//3*n*e^-1*(a*e^2+c*d^2+-1*b*d*e)^-3*(-1*b*e+2*c*d)*(b^2*e^2+c^2*d^2+-1*c*e*(b*d+3*a*e))*log(d+e*x)+1//6*n*e^-1*(a*e^2+c*d^2+-1*b*d*e)^-3*(-1*b*e+2*c*d)*(b^2*e^2+c^2*d^2+-1*c*e*(b*d+3*a*e))*log(a+b*x+c*x^2))
@test integrate((d+e*x)^-5*log(d*(a+b*x+c*x^2)^n), x) == :(-1//4*e^-1*(d+e*x)^-4*log(d*(a+b*x+c*x^2)^n)+-1//4*n*e^-1*(a*e^2+c*d^2+-1*b*d*e)^-4*(b^4*e^4+2*c^4*d^4+2*c^2*e^2*(a^2*e^2+3*b^2*d^2+6*a*b*d*e)+-4*c*b^2*e^3*(a*e+b*d)+-4*e*c^3*d^2*(b*d+3*a*e))*log(d+e*x)+1//8*n*e^-1*(d+e*x)^-2*(a*e^2+c*d^2+-1*b*d*e)^-2*(b^2*e^2+2*c^2*d^2+-2*c*e*(a*e+b*d))+1//8*n*e^-1*(a*e^2+c*d^2+-1*b*d*e)^-4*(b^4*e^4+2*c^4*d^4+2*c^2*e^2*(a^2*e^2+3*b^2*d^2+6*a*b*d*e)+-4*c*b^2*e^3*(a*e+b*d)+-4*e*c^3*d^2*(b*d+3*a*e))*log(a+b*x+c*x^2)+1//12*n*e^-1*(d+e*x)^-3*(a*e^2+c*d^2+-1*b*d*e)^-1*(-1*b*e+2*c*d)+1//4*n*e^-1*(d+e*x)^-1*(a*e^2+c*d^2+-1*b*d*e)^-3*(-1*b*e+2*c*d)*(b^2*e^2+c^2*d^2+-1*c*e*(b*d+3*a*e))+1//4*n*(b^2+-4*a*c)^(1/2)*(a*e^2+c*d^2+-1*b*d*e)^-4*(-1*b*e+2*c*d)*(b^2*e^2+2*c^2*d^2+-2*c*e*(a*e+b*d))*arctanh((b^2+-4*a*c)^-1//2*(b+2*c*x)))
@test integrate((a*e+c*e*x^2)^-1*log(d*(a+c*x^2)^n), x) == :(a^-1//2*c^-1//2*e^-1*arctan(x*a^-1//2*c^(1/2))*log(d*(a+c*x^2)^n)+im*n*a^-1//2*c^-1//2*e^-1*arctan(x*a^-1//2*c^(1/2))^2+im*n*a^-1//2*c^-1//2*e^-1*Polylogarithms.polylog(2,1+-2*a^(1/2)*(a^(1/2)+im*x*c^(1/2))^-1)+2*n*a^-1//2*c^-1//2*e^-1*arctan(x*a^-1//2*c^(1/2))*log(2*a^(1/2)*(a^(1/2)+im*x*c^(1/2))^-1))
@test integrate((a*e+b*e*x+c*e*x^2)^-1*log(d*(a+b*x+c*x^2)^n), x) == :(-2*n*e^-1*(b^2+-4*a*c)^-1//2*Polylogarithms.polylog(2,-1*(1+-1*b*(b^2+-4*a*c)^-1//2+-2*c*x*(b^2+-4*a*c)^-1//2)^-1*(1+b*(b^2+-4*a*c)^-1//2+2*c*x*(b^2+-4*a*c)^-1//2))+-2*e^-1*(b^2+-4*a*c)^-1//2*arctanh((b^2+-4*a*c)^-1//2*(b+2*c*x))*log(d*(a+b*x+c*x^2)^n)+2*n*e^-1*(b^2+-4*a*c)^-1//2*arctanh((b^2+-4*a*c)^-1//2*(b+2*c*x))^2+-4*n*e^-1*(b^2+-4*a*c)^-1//2*arctanh((b^2+-4*a*c)^-1//2*(b+2*c*x))*log(2*(1+-1*b*(b^2+-4*a*c)^-1//2+-2*c*x*(b^2+-4*a*c)^-1//2)^-1))
@test integrate((d+e*x^2)^-1*log(g*(a+b*x+c*x^2)^n), x) == :((1/2)*n*e^-1//2*(-1d)^-1//2*Polylogarithms.polylog(2,2*c*(-1*e^(1/2)*(b+(b^2+-4*a*c)^(1/2))+2*c*(-1d)^(1/2))^-1*((-1d)^(1/2)+x*e^(1/2)))+(1/2)*n*e^-1//2*(-1d)^-1//2*Polylogarithms.polylog(2,2*c*(-1*e^(1/2)*(b+-1*(b^2+-4*a*c)^(1/2))+2*c*(-1d)^(1/2))^-1*((-1d)^(1/2)+x*e^(1/2)))+(1/2)*e^-1//2*(-1d)^-1//2*log(g*(a+b*x+c*x^2)^n)*log((-1d)^(1/2)+-1*x*e^(1/2))+-1//2*n*e^-1//2*(-1d)^-1//2*Polylogarithms.polylog(2,2*c*(e^(1/2)*(b+(b^2+-4*a*c)^(1/2))+2*c*(-1d)^(1/2))^-1*((-1d)^(1/2)+-1*x*e^(1/2)))+-1//2*n*e^-1//2*(-1d)^-1//2*Polylogarithms.polylog(2,2*c*(e^(1/2)*(b+-1*(b^2+-4*a*c)^(1/2))+2*c*(-1d)^(1/2))^-1*((-1d)^(1/2)+-1*x*e^(1/2)))+-1//2*e^-1//2*(-1d)^-1//2*log(g*(a+b*x+c*x^2)^n)*log((-1d)^(1/2)+x*e^(1/2))+(1/2)*n*e^-1//2*(-1d)^-1//2*log(-1*e^(1/2)*(-1*e^(1/2)*(b+(b^2+-4*a*c)^(1/2))+2*c*(-1d)^(1/2))^-1*(b+(b^2+-4*a*c)^(1/2)+2*c*x))*log((-1d)^(1/2)+x*e^(1/2))+(1/2)*n*e^-1//2*(-1d)^-1//2*log(-1*e^(1/2)*(-1*e^(1/2)*(b+-1*(b^2+-4*a*c)^(1/2))+2*c*(-1d)^(1/2))^-1*(b+-1*(b^2+-4*a*c)^(1/2)+2*c*x))*log((-1d)^(1/2)+x*e^(1/2))+-1//2*n*e^-1//2*(-1d)^-1//2*log(e^(1/2)*(e^(1/2)*(b+(b^2+-4*a*c)^(1/2))+2*c*(-1d)^(1/2))^-1*(b+(b^2+-4*a*c)^(1/2)+2*c*x))*log((-1d)^(1/2)+-1*x*e^(1/2))+-1//2*n*e^-1//2*(-1d)^-1//2*log(e^(1/2)*(e^(1/2)*(b+-1*(b^2+-4*a*c)^(1/2))+2*c*(-1d)^(1/2))^-1*(b+-1*(b^2+-4*a*c)^(1/2)+2*c*x))*log((-1d)^(1/2)+-1*x*e^(1/2)))
@test integrate((d+e*x+f*x^2)^-1*log(g*(a+b*x+c*x^2)^n), x) == :(n*(e^2+-4*d*f)^-1//2*Polylogarithms.polylog(2,-1*c*(f*(b+(b^2+-4*a*c)^(1/2))+-1*c*(e+(e^2+-4*d*f)^(1/2)))^-1*(e+(e^2+-4*d*f)^(1/2)+2*f*x))+n*(e^2+-4*d*f)^-1//2*Polylogarithms.polylog(2,-1*c*(f*(b+-1*(b^2+-4*a*c)^(1/2))+-1*c*(e+(e^2+-4*d*f)^(1/2)))^-1*(e+(e^2+-4*d*f)^(1/2)+2*f*x))+(e^2+-4*d*f)^-1//2*log(g*(a+b*x+c*x^2)^n)*log(e+-1*(e^2+-4*d*f)^(1/2)+2*f*x)+-1*n*(e^2+-4*d*f)^-1//2*Polylogarithms.polylog(2,-1*c*(f*(b+(b^2+-4*a*c)^(1/2))+-1*c*(e+-1*(e^2+-4*d*f)^(1/2)))^-1*(e+-1*(e^2+-4*d*f)^(1/2)+2*f*x))+-1*n*(e^2+-4*d*f)^-1//2*Polylogarithms.polylog(2,-1*c*(f*(b+-1*(b^2+-4*a*c)^(1/2))+-1*c*(e+-1*(e^2+-4*d*f)^(1/2)))^-1*(e+-1*(e^2+-4*d*f)^(1/2)+2*f*x))+-1*(e^2+-4*d*f)^-1//2*log(g*(a+b*x+c*x^2)^n)*log(e+(e^2+-4*d*f)^(1/2)+2*f*x)+n*(e^2+-4*d*f)^-1//2*log(f*(f*(b+(b^2+-4*a*c)^(1/2))+-1*c*(e+(e^2+-4*d*f)^(1/2)))^-1*(b+(b^2+-4*a*c)^(1/2)+2*c*x))*log(e+(e^2+-4*d*f)^(1/2)+2*f*x)+n*(e^2+-4*d*f)^-1//2*log(f*(f*(b+-1*(b^2+-4*a*c)^(1/2))+-1*c*(e+(e^2+-4*d*f)^(1/2)))^-1*(b+-1*(b^2+-4*a*c)^(1/2)+2*c*x))*log(e+(e^2+-4*d*f)^(1/2)+2*f*x)+-1*n*(e^2+-4*d*f)^-1//2*log(f*(f*(b+(b^2+-4*a*c)^(1/2))+-1*c*(e+-1*(e^2+-4*d*f)^(1/2)))^-1*(b+(b^2+-4*a*c)^(1/2)+2*c*x))*log(e+-1*(e^2+-4*d*f)^(1/2)+2*f*x)+-1*n*(e^2+-4*d*f)^-1//2*log(-1*f*(c*e+f*(b^2+-4*a*c)^(1/2)+-1*b*f+-1*c*(e^2+-4*d*f)^(1/2))^-1*(b+-1*(b^2+-4*a*c)^(1/2)+2*c*x))*log(e+-1*(e^2+-4*d*f)^(1/2)+2*f*x))
@test integrate(log(d*(b*x+c*x^2)^n)^2, x) == :(x*log(d*(b*x+c*x^2)^n)^2+8*x*n^2+-4*n*x*log(d*(b*x+c*x^2)^n)+-1*b*c^-1*n^2*log(b+c*x)^2+-4*b*c^-1*n^2*log(b+c*x)+-2*b*c^-1*n^2*Polylogarithms.polylog(2,1+c*x*b^-1)+-2*b*c^-1*n^2*log(-1*c*x*b^-1)*log(b+c*x)+2*b*n*c^-1*log(d*(b*x+c*x^2)^n)*log(b+c*x))
@test integrate(log(d*(a+b*x+c*x^2)^n)^2, x) == :(x*log(d*(a+b*x+c*x^2)^n)^2+8*x*n^2+-4*n*x*log(d*(a+b*x+c*x^2)^n)+-1*c^-1*n^2*(b+(b^2+-4*a*c)^(1/2))*Polylogarithms.polylog(2,(1/2)*(b^2+-4*a*c)^-1//2*(b+(b^2+-4*a*c)^(1/2)+2*c*x))+-1*c^-1*n^2*(b+-1*(b^2+-4*a*c)^(1/2))*Polylogarithms.polylog(2,-1//2*(b^2+-4*a*c)^-1//2*(b+-1*(b^2+-4*a*c)^(1/2)+2*c*x))+-4*c^-1*n^2*(b^2+-4*a*c)^(1/2)*arctanh((b^2+-4*a*c)^-1//2*(b+2*c*x))+-2*b*c^-1*n^2*log(a+b*x+c*x^2)+-1//2*c^-1*n^2*log(b+(b^2+-4*a*c)^(1/2)+2*c*x)^2*(b+(b^2+-4*a*c)^(1/2))+-1//2*c^-1*n^2*log(b+-1*(b^2+-4*a*c)^(1/2)+2*c*x)^2*(b+-1*(b^2+-4*a*c)^(1/2))+n*c^-1*(b+(b^2+-4*a*c)^(1/2))*log(d*(a+b*x+c*x^2)^n)*log(b+(b^2+-4*a*c)^(1/2)+2*c*x)+n*c^-1*(b+-1*(b^2+-4*a*c)^(1/2))*log(d*(a+b*x+c*x^2)^n)*log(b+-1*(b^2+-4*a*c)^(1/2)+2*c*x)+-1*c^-1*n^2*(b+(b^2+-4*a*c)^(1/2))*log(-1//2*(b^2+-4*a*c)^-1//2*(b+-1*(b^2+-4*a*c)^(1/2)+2*c*x))*log(b+(b^2+-4*a*c)^(1/2)+2*c*x)+-1*c^-1*n^2*(b+-1*(b^2+-4*a*c)^(1/2))*log((1/2)*(b^2+-4*a*c)^-1//2*(b+(b^2+-4*a*c)^(1/2)+2*c*x))*log(b+-1*(b^2+-4*a*c)^(1/2)+2*c*x))
@test integrate(x^2*(2+x^2+3x)^-1*log(1+x+x^2), x) == :((1/2)*log(1+x+x^2)+-1*Polylogarithms.polylog(2,(1+im*3^(1/2))^-1*(2+2x))+-1*Polylogarithms.polylog(2,(1+-1*im*3^(1/2))^-1*(2+2x))+-2x+4*Polylogarithms.polylog(2,(3+im*3^(1/2))^-1*(4+2x))+4*Polylogarithms.polylog(2,(3+-1*im*3^(1/2))^-1*(4+2x))+x*log(1+x+x^2)+3^(1/2)*arctan(1//3*3^(1/2)*(1+2x))+log(2+2x)*log(1+x+x^2)+-1*log(-1*(1+im*3^(1/2))^-1*(1+2x+-1*im*3^(1/2)))*log(2+2x)+-1*log(-1*(1+-1*im*3^(1/2))^-1*(1+2x+im*3^(1/2)))*log(2+2x)+-4*log(4+2x)*log(1+x+x^2)+4*log(-1*(3+im*3^(1/2))^-1*(1+2x+-1*im*3^(1/2)))*log(4+2x)+4*log(-1*(3+-1*im*3^(1/2))^-1*(1+2x+im*3^(1/2)))*log(4+2x))
@test integrate(log(1+x+x^2)^2, x) == :(-2*log(1+x+x^2)+8x+x*log(1+x+x^2)^2+-1*log(1+2x+im*3^(1/2))^2*(1/2+(1/2)*im*3^(1/2))+-1*log(1+2x+-1*im*3^(1/2))^2*(1/2+-1//2*im*3^(1/2))+-1*(1+im*3^(1/2))*Polylogarithms.polylog(2,-1//6*3^(1/2)*(im+-1*3^(1/2)+2*im*x))+-1*(1+-1*im*3^(1/2))*Polylogarithms.polylog(2,1//6*3^(1/2)*(im+3^(1/2)+2*im*x))+-4*x*log(1+x+x^2)+-4*3^(1/2)*arctan(1//3*3^(1/2)*(1+2x))+(1+im*3^(1/2))*log(1+x+x^2)*log(1+2x+im*3^(1/2))+(1+-1*im*3^(1/2))*log(1+x+x^2)*log(1+2x+-1*im*3^(1/2))+-1*(1+im*3^(1/2))*log(1//6*im*3^(1/2)*(1+2x+-1*im*3^(1/2)))*log(1+2x+im*3^(1/2))+-1*(1+-1*im*3^(1/2))*log(-1//6*im*3^(1/2)*(1+2x+im*3^(1/2)))*log(1+2x+-1*im*3^(1/2)))
@test integrate(x^-3*log(-1+x+x^2)^2, x) == :(-3*Polylogarithms.polylog(2,1+2*x*(1+-1*5^(1/2))^-1)+3*Polylogarithms.polylog(2,-2*x*(1+5^(1/2))^-1)+x^-1*log(-1+x+x^2)+-1*log(1+5^(1/2)+2x)^2*(3//4+-1//4*5^(1/2))+-1*log(1+-1*5^(1/2)+2x)^2*(3//4+1//4*5^(1/2))+-1*(1/2+(1/2)*5^(1/2))*log(1+-1*5^(1/2)+2x)+-1*(1/2+-1//2*5^(1/2))*log(1+5^(1/2)+2x)+-1*(3//2+(1/2)*5^(1/2))*Polylogarithms.polylog(2,-1//10*5^(1/2)*(1+-1*5^(1/2)+2x))+-1*(3//2+-1//2*5^(1/2))*Polylogarithms.polylog(2,1//10*5^(1/2)*(1+5^(1/2)+2x))+-3*log(x)*log(-1+x+x^2)+3*log(x)*log(1+2*x*(1+5^(1/2))^-1)+3*log(-1//2+(1/2)*5^(1/2))*log(1+-1*5^(1/2)+2x)+-1//2*x^-2*log(-1+x+x^2)^2+(3//2+(1/2)*5^(1/2))*log(1+-1*5^(1/2)+2x)*log(-1+x+x^2)+(3//2+-1//2*5^(1/2))*log(1+5^(1/2)+2x)*log(-1+x+x^2)+-1*(3//2+(1/2)*5^(1/2))*log(1//10*5^(1/2)*(1+5^(1/2)+2x))*log(1+-1*5^(1/2)+2x)+-1*(3//2+-1//2*5^(1/2))*log(-1//10*5^(1/2)*(1+-1*5^(1/2)+2x))*log(1+5^(1/2)+2x)+log(x))
@test integrate(x^3*log(-1+4x+4*(x*(-1+x))^(1/2)), x) == :(-1537//16384*arctanh(x*(x^2+-1x)^-1//2)+-683//4096*(x^2+-1x)^(1/2)+-1//12*(x^2+-1x)^3//2+-1//32*x^4+-1//1024*x^2+-1//32768*log(1+8x)+1//192*x^3+1//4096*x+1//32768*arctanh(1//6*(x^2+-1x)^-1//2*(1+-10x))+-1//32*x*(x^2+-1x)^3//2+1//4*x^4*log(-1+4x+4*(x^2+-1x)^(1/2))+1//2048*(x^2+-1x)^(1/2)*(149+-298x))
@test integrate(x^2*log(-1+4x+4*(x*(-1+x))^(1/2)), x) == :(-223//1536*arctanh(x*(x^2+-1x)^-1//2)+-85//384*(x^2+-1x)^(1/2)+-1//18*x^3+-1//18*(x^2+-1x)^3//2+-1//384*x+-1//3072*arctanh(1//6*(x^2+-1x)^-1//2*(1+-10x))+1//96*x^2+1//3072*log(1+8x)+(x^2+-1x)^(1/2)*(5//64+-5//32*x)+1//3*x^3*log(-1+4x+4*(x^2+-1x)^(1/2)))
@test integrate(x*log(-1+4x+4*(x*(-1+x))^(1/2)), x) == :(-33//128*arctanh(x*(x^2+-1x)^-1//2)+-11//32*(x^2+-1x)^(1/2)+-1//8*x^2+-1//256*log(1+8x)+1//32*x+1//256*arctanh(1//6*(x^2+-1x)^-1//2*(1+-10x))+(x^2+-1x)^(1/2)*(1//16+-1//8*x)+(1/2)*x^2*log(-1+4x+4*(x^2+-1x)^(1/2)))
@test integrate(log(-1+4x+4*(x*(-1+x))^(1/2)), x) == :(-7//8*arctanh(x*(x^2+-1x)^-1//2)+-1//2*x+-1//2*(x^2+-1x)^(1/2)+-1//16*arctanh(1//6*(x^2+-1x)^-1//2*(1+-10x))+1//16*log(1+8x)+x*log(-1+4x+4*(x^2+-1x)^(1/2)))
@test integrate(x^-2*log(-1+4x+4*(x*(-1+x))^(1/2)), x) == :(-4*log(1+8x)+4*arctanh(1//6*(x^2+-1x)^-1//2*(1+-10x))+4*log(x)+-1*x^-1*log(-1+4x+4*(x^2+-1x)^(1/2))+4*x^-1*(x^2+-1x)^(1/2))
@test integrate(x^-3*log(-1+4x+4*(x*(-1+x))^(1/2)), x) == :(-16*arctanh(1//6*(x^2+-1x)^-1//2*(1+-10x))+-16*log(x)+-2*x^-1+16*log(1+8x)+-10*x^-1*(x^2+-1x)^(1/2)+-2//3*x^-3*(x^2+-1x)^3//2+-1//2*x^-2*log(-1+4x+4*(x^2+-1x)^(1/2)))
@test integrate(x^3//2*log(-1+4x+4*(x*(-1+x))^(1/2)), x) == :(-2//25*x^5//2+-1//160*x^(1/2)+1//60*x^3//2+-71//300*x^-3//2*(x^2+-1x)^3//2+-17//32*x^-1//2*(x^2+-1x)^(1/2)+-2//25*x^-1//2*(x^2+-1x)^3//2+1//640*2^(1/2)*arctan(2*2^(1/2)*x^(1/2))+2//5*x^5//2*log(-1+4x+4*(x^2+-1x)^(1/2))+-1//640*2^(1/2)*x^-1//2*(-1+x)^-1//2*(x^2+-1x)^(1/2)*arctan(2//3*2^(1/2)*(-1+x)^(1/2)))
@test integrate(x^(1/2)*log(-1+4x+4*(x*(-1+x))^(1/2)), x) == :(-2//9*x^3//2+1//12*x^(1/2)+-11//12*x^-1//2*(x^2+-1x)^(1/2)+-2//9*x^-3//2*(x^2+-1x)^3//2+-1//48*2^(1/2)*arctan(2*2^(1/2)*x^(1/2))+2//3*x^3//2*log(-1+4x+4*(x^2+-1x)^(1/2))+1//48*2^(1/2)*x^-1//2*(-1+x)^-1//2*(x^2+-1x)^(1/2)*arctan(2//3*2^(1/2)*(-1+x)^(1/2)))
@test integrate(x^-1//2*log(-1+4x+4*(x*(-1+x))^(1/2)), x) == :(-2*x^(1/2)+(1/2)*2^(1/2)*arctan(2*2^(1/2)*x^(1/2))+-2*x^-1//2*(x^2+-1x)^(1/2)+2*x^(1/2)*log(-1+4x+4*(x^2+-1x)^(1/2))+-1//2*2^(1/2)*x^-1//2*(-1+x)^-1//2*(x^2+-1x)^(1/2)*arctan(2//3*2^(1/2)*(-1+x)^(1/2)))
@test integrate(x^-3//2*log(-1+4x+4*(x*(-1+x))^(1/2)), x) == :(-8*arctan(x^(1/2)*(x^2+-1x)^-1//2)+-2*x^-1//2*log(-1+4x+4*(x^2+-1x)^(1/2))+4*2^(1/2)*arctan(2*2^(1/2)*x^(1/2))+-4*2^(1/2)*x^-1//2*(-1+x)^-1//2*(x^2+-1x)^(1/2)*arctan(2//3*2^(1/2)*(-1+x)^(1/2)))
@test integrate(x^-5//2*log(-1+4x+4*(x*(-1+x))^(1/2)), x) == :(-16//3*x^-1//2+44//3*arctan(x^(1/2)*(x^2+-1x)^-1//2)+-32//3*2^(1/2)*arctan(2*2^(1/2)*x^(1/2))+-2//3*x^-3//2*log(-1+4x+4*(x^2+-1x)^(1/2))+4//3*x^-3//2*(x^2+-1x)^(1/2)+32//3*2^(1/2)*x^-1//2*(-1+x)^-1//2*(x^2+-1x)^(1/2)*arctan(2//3*2^(1/2)*(-1+x)^(1/2)))
@test integrate(x^3*log(a+b*exp(x)), x) == :(6*Polylogarithms.polylog(5,-1*b*a^-1*exp(x))+-1*x^3*Polylogarithms.polylog(2,-1*b*a^-1*exp(x))+-6*x*Polylogarithms.polylog(4,-1*b*a^-1*exp(x))+3*x^2*Polylogarithms.polylog(3,-1*b*a^-1*exp(x))+-1//4*x^4*log(1+b*a^-1*exp(x))+1//4*x^4*log(a+b*exp(x)))
@test integrate(x^2*log(a+b*exp(x)), x) == :(-2*Polylogarithms.polylog(4,-1*b*a^-1*exp(x))+-1*x^2*Polylogarithms.polylog(2,-1*b*a^-1*exp(x))+2*x*Polylogarithms.polylog(3,-1*b*a^-1*exp(x))+-1//3*x^3*log(1+b*a^-1*exp(x))+1//3*x^3*log(a+b*exp(x)))
@test integrate(x*log(a+b*exp(x)), x) == :((1/2)*x^2*log(a+b*exp(x))+-1*x*Polylogarithms.polylog(2,-1*b*a^-1*exp(x))+-1//2*x^2*log(1+b*a^-1*exp(x))+Polylogarithms.polylog(3,-1*b*a^-1*exp(x)))
@test integrate(log(a+b*exp(x)), x) == :(-1*Polylogarithms.polylog(2,-1*b*a^-1*exp(x))+x*log(a+b*exp(x))+-1*x*log(1+b*a^-1*exp(x)))
@test integrate(x^3*log(1+e*(f^(c*(a+b*x)))^n), x) == :(6*b^-4*c^-4*n^-4*log(f)^-4*Polylogarithms.polylog(5,-1*e*(f^(c*(a+b*x)))^n)+-1*b^-1*c^-1*n^-1*x^3*log(f)^-1*Polylogarithms.polylog(2,-1*e*(f^(c*(a+b*x)))^n)+-6*x*b^-3*c^-3*n^-3*log(f)^-3*Polylogarithms.polylog(4,-1*e*(f^(c*(a+b*x)))^n)+3*b^-2*c^-2*n^-2*x^2*log(f)^-2*Polylogarithms.polylog(3,-1*e*(f^(c*(a+b*x)))^n))
@test integrate(x^2*log(1+e*(f^(c*(a+b*x)))^n), x) == :(-2*b^-3*c^-3*n^-3*log(f)^-3*Polylogarithms.polylog(4,-1*e*(f^(c*(a+b*x)))^n)+-1*b^-1*c^-1*n^-1*x^2*log(f)^-1*Polylogarithms.polylog(2,-1*e*(f^(c*(a+b*x)))^n)+2*x*b^-2*c^-2*n^-2*log(f)^-2*Polylogarithms.polylog(3,-1*e*(f^(c*(a+b*x)))^n))
@test integrate(x*log(1+e*(f^(c*(a+b*x)))^n), x) == :(b^-2*c^-2*n^-2*log(f)^-2*Polylogarithms.polylog(3,-1*e*(f^(c*(a+b*x)))^n)+-1*x*b^-1*c^-1*n^-1*log(f)^-1*Polylogarithms.polylog(2,-1*e*(f^(c*(a+b*x)))^n))
@test integrate(log(1+e*(f^(c*(a+b*x)))^n), x) == :(-1*b^-1*c^-1*n^-1*log(f)^-1*Polylogarithms.polylog(2,-1*e*(f^(c*(a+b*x)))^n))
@test integrate(x^3*log(d+e*(f^(c*(a+b*x)))^n), x) == :(-1//4*x^4*log(1+e*d^-1*(f^(c*(a+b*x)))^n)+1//4*x^4*log(d+e*(f^(c*(a+b*x)))^n)+6*b^-4*c^-4*n^-4*log(f)^-4*Polylogarithms.polylog(5,-1*e*d^-1*(f^(c*(a+b*x)))^n)+-1*b^-1*c^-1*n^-1*x^3*log(f)^-1*Polylogarithms.polylog(2,-1*e*d^-1*(f^(c*(a+b*x)))^n)+-6*x*b^-3*c^-3*n^-3*log(f)^-3*Polylogarithms.polylog(4,-1*e*d^-1*(f^(c*(a+b*x)))^n)+3*b^-2*c^-2*n^-2*x^2*log(f)^-2*Polylogarithms.polylog(3,-1*e*d^-1*(f^(c*(a+b*x)))^n))
@test integrate(x^2*log(d+e*(f^(c*(a+b*x)))^n), x) == :(-1//3*x^3*log(1+e*d^-1*(f^(c*(a+b*x)))^n)+1//3*x^3*log(d+e*(f^(c*(a+b*x)))^n)+-2*b^-3*c^-3*n^-3*log(f)^-3*Polylogarithms.polylog(4,-1*e*d^-1*(f^(c*(a+b*x)))^n)+-1*b^-1*c^-1*n^-1*x^2*log(f)^-1*Polylogarithms.polylog(2,-1*e*d^-1*(f^(c*(a+b*x)))^n)+2*x*b^-2*c^-2*n^-2*log(f)^-2*Polylogarithms.polylog(3,-1*e*d^-1*(f^(c*(a+b*x)))^n))
@test integrate(x*log(d+e*(f^(c*(a+b*x)))^n), x) == :((1/2)*x^2*log(d+e*(f^(c*(a+b*x)))^n)+-1//2*x^2*log(1+e*d^-1*(f^(c*(a+b*x)))^n)+b^-2*c^-2*n^-2*log(f)^-2*Polylogarithms.polylog(3,-1*e*d^-1*(f^(c*(a+b*x)))^n)+-1*x*b^-1*c^-1*n^-1*log(f)^-1*Polylogarithms.polylog(2,-1*e*d^-1*(f^(c*(a+b*x)))^n))
@test integrate(log(d+e*(f^(c*(a+b*x)))^n), x) == :(x*log(d+e*(f^(c*(a+b*x)))^n)+-1*x*log(1+e*d^-1*(f^(c*(a+b*x)))^n)+-1*b^-1*c^-1*n^-1*log(f)^-1*Polylogarithms.polylog(2,-1*e*d^-1*(f^(c*(a+b*x)))^n))
@test integrate(log(pi+b*(F^(e*(c+d*x)))^n), x) == :(x*log(pi)+-1*d^-1*e^-1*n^-1*log(F)^-1*Polylogarithms.polylog(2,-1*b*pi^-1*(F^(e*(c+d*x)))^n))
@test integrate(x^-1*(3+log(x))^-1, x) == :(log(3+log(x)))
@test integrate(x^-1*(1+log(x))^(1/2), x) == :(2//3*(1+log(x))^3//2)
@test integrate(x^-1*(1+log(x))^5, x) == :(1//6*(1+log(x))^6)
@test integrate(x^-1*log(x)^-1//2, x) == :(2*log(x)^(1/2))
@test integrate(x^-1*(1+log(x)^2)^-1, x) == :(arctan(log(x)))
@test integrate(x^-1*(-3+log(x)^2)^-1//2, x) == :(arctanh((-3+log(x)^2)^-1//2*log(x)))
@test integrate(x^-1*(4+-9*log(x)^2)^-1//2, x) == :(1//3*arcsin(3//2*log(x)))
@test integrate(x^-1*(4+log(x)^2)^-1//2, x) == :(arcsinh((1/2)*log(x)))
@test integrate(x^-1*(2+3*log(6x)^3)^-1, x) == :(-1//6*2^1//3*3^1//6*arctan(1//3*3^(1/2)+-1//3*2^2//3*3^5//6*log(6x))+-1//36*2^1//3*3^2//3*log(2^2//3+3^2//3*log(6x)^2+-1*6^1//3*log(6x))+1//18*2^1//3*3^2//3*log(2^1//3+3^1//3*log(6x)))
@test integrate(x^-1*log(6x)^-1*log(log(6x)), x) == :((1/2)*log(log(6x))^2)
@test integrate(x^-1*sin(log(x))^2, x) == :((1/2)*log(x)+-1//2*cos(log(x))*sin(log(x)))
@test integrate(x^-1*(3+log(x))^-1*(7+-1*log(x)), x) == :(-1*log(x)+10*log(3+log(x)))
@test integrate(x^-1*(3+log(x))^2*(2+-1*log(x)), x) == :(-1//4*(3+log(x))^4+5//3*(3+log(x))^3)
@test integrate(x^-1*(1+log(x)^2)^(1/2)*log(x)^2, x) == :(-1//8*arcsinh(log(x))+1//4*(1+log(x)^2)^(1/2)*log(x)^3+1//8*(1+log(x)^2)^(1/2)*log(x))
@test integrate(x^-1*(3+2*log(x))^-2*(1+log(x)), x) == :((12+8*log(x))^-1+1//4*log(3+2*log(x)))
@test integrate(x^-1*(1+log(x))^-1//2*log(x), x) == :(-2*(1+log(x))^(1/2)+2//3*(1+log(x))^3//2)
@test integrate(x^-1*(-1+4*log(x))^-1//2*log(x), x) == :(1//8*(-1+4*log(x))^(1/2)+1//24*(-1+4*log(x))^3//2)
@test integrate(x^-1*(1+log(x))^(1/2)*log(x)^-1, x) == :(-2*arctanh((1+log(x))^(1/2))+2*(1+log(x))^(1/2))
@test integrate(x^-1*(-1+log(x))^-4*(1+log(x)^2+-4*log(x)), x) == :((1+-1*log(x))^-1+(-1+log(x))^-2+-2//3*(1+-1*log(x))^-3)
@test integrate(x^-1*(log(a*x^n)^2)^p, x) == :(n^-1*(log(a*x^n)^2)^p*(1+2p)^-1*log(a*x^n))
@test integrate(x^-1*(log(a*x^n)^m)^p, x) == :(n^-1*(log(a*x^n)^m)^p*(1+m*p)^-1*log(a*x^n))
@test integrate(x^-1*(log(a*x^n)^2)^(1/2), x) == :((1/2)*n^-1*(log(a*x^n)^2)^(1/2)*log(a*x^n))
@test integrate(x^-1*(b*log(a*x^n)^m)^p, x) == :(n^-1*(b*log(a*x^n)^m)^p*(1+m*p)^-1*log(a*x^n))
@test integrate(x^-1*log(exp(x))^-1, x) == :((x+-1*log(exp(x)))^-1*log(log(exp(x)))+-1*(x+-1*log(exp(x)))^-1*log(x))
@test integrate(log(x)*sin(a+b*x), x) == :(b^-1*cos(a)*cosintegral(b*x)+-1*b^-1*cos(a+b*x)*log(x)+-1*b^-1*sin(a)*sinintegral(b*x))
@test integrate(sin(a+b*x)^2*log(x), x) == :(-1//2*x+(1/2)*x*log(x)+1//4*b^-1*cos(2a)*sinintegral(2*b*x)+1//4*b^-1*cosintegral(2*b*x)*sin(2a)+-1//2*b^-1*cos(a+b*x)*log(x)*sin(a+b*x))
@test integrate(sin(a+b*x)^3*log(x), x) == :(-1*b^-1*cos(a+b*x)*log(x)+-3//4*b^-1*sin(a)*sinintegral(b*x)+-1//12*b^-1*cos(3a)*cosintegral(3*b*x)+1//3*b^-1*cos(a+b*x)^3*log(x)+1//12*b^-1*sin(3a)*sinintegral(3*b*x)+3//4*b^-1*cos(a)*cosintegral(b*x))
@test integrate(cos(a+b*x)*log(x), x) == :(b^-1*log(x)*sin(a+b*x)+-1*b^-1*cos(a)*sinintegral(b*x)+-1*b^-1*cosintegral(b*x)*sin(a))
@test integrate(cos(a+b*x)^2*log(x), x) == :(-1//2*x+(1/2)*x*log(x)+-1//4*b^-1*cos(2a)*sinintegral(2*b*x)+-1//4*b^-1*cosintegral(2*b*x)*sin(2a)+(1/2)*b^-1*cos(a+b*x)*log(x)*sin(a+b*x))
@test integrate(cos(a+b*x)^3*log(x), x) == :(b^-1*log(x)*sin(a+b*x)+-3//4*b^-1*cos(a)*sinintegral(b*x)+-3//4*b^-1*cosintegral(b*x)*sin(a)+-1//3*b^-1*sin(a+b*x)^3*log(x)+-1//12*b^-1*cos(3a)*sinintegral(3*b*x)+-1//12*b^-1*cosintegral(3*b*x)*sin(3a))
@test integrate(x^-1*sin(x)+cos(x)*log(x), x) == :(log(x)*sin(x))
@test integrate(log(a*sin(x)), x) == :(x*log(a*sin(x))+(1/2)*im*x^2+(1/2)*im*Polylogarithms.polylog(2,exp(2*im*x))+-1*x*log(1+-1*exp(2*im*x)))
@test integrate(log(a*sin(x)^2), x) == :(im*x^2+im*Polylogarithms.polylog(2,exp(2*im*x))+x*log(a*sin(x)^2)+-2*x*log(1+-1*exp(2*im*x)))
@test integrate(log(a*sin(x)^n), x) == :(x*log(a*sin(x)^n)+(1/2)*im*n*x^2+(1/2)*im*n*Polylogarithms.polylog(2,exp(2*im*x))+-1*n*x*log(1+-1*exp(2*im*x)))
@test integrate(log(a*cos(x)), x) == :(x*log(a*cos(x))+(1/2)*im*x^2+(1/2)*im*Polylogarithms.polylog(2,-1*exp(2*im*x))+-1*x*log(1+exp(2*im*x)))
@test integrate(log(a*cos(x)^2), x) == :(im*x^2+im*Polylogarithms.polylog(2,-1*exp(2*im*x))+x*log(a*cos(x)^2)+-2*x*log(1+exp(2*im*x)))
@test integrate(log(a*cos(x)^n), x) == :(x*log(a*cos(x)^n)+(1/2)*im*n*x^2+(1/2)*im*n*Polylogarithms.polylog(2,-1*exp(2*im*x))+-1*n*x*log(1+exp(2*im*x)))
@test integrate(log(a*tan(x)), x) == :(x*log(a*tan(x))+(1/2)*im*Polylogarithms.polylog(2,exp(2*im*x))+2*x*arctanh(exp(2*im*x))+-1//2*im*Polylogarithms.polylog(2,-1*exp(2*im*x)))
@test integrate(log(a*tan(x)^2), x) == :(im*Polylogarithms.polylog(2,exp(2*im*x))+x*log(a*tan(x)^2)+-1*im*Polylogarithms.polylog(2,-1*exp(2*im*x))+4*x*arctanh(exp(2*im*x)))
@test integrate(log(a*tan(x)^n), x) == :(x*log(a*tan(x)^n)+(1/2)*im*n*Polylogarithms.polylog(2,exp(2*im*x))+2*n*x*arctanh(exp(2*im*x))+-1//2*im*n*Polylogarithms.polylog(2,-1*exp(2*im*x)))
@test integrate(log(a*cot(x)), x) == :(x*log(a*cot(x))+(1/2)*im*Polylogarithms.polylog(2,-1*exp(2*im*x))+-2*x*arctanh(exp(2*im*x))+-1//2*im*Polylogarithms.polylog(2,exp(2*im*x)))
@test integrate(log(a*cot(x)^2), x) == :(im*Polylogarithms.polylog(2,-1*exp(2*im*x))+x*log(a*cot(x)^2)+-1*im*Polylogarithms.polylog(2,exp(2*im*x))+-4*x*arctanh(exp(2*im*x)))
@test integrate(log(a*cot(x)^n), x) == :(x*log(a*cot(x)^n)+(1/2)*im*n*Polylogarithms.polylog(2,-1*exp(2*im*x))+-2*n*x*arctanh(exp(2*im*x))+-1//2*im*n*Polylogarithms.polylog(2,exp(2*im*x)))
@test integrate(log(a*sec(x)), x) == :(x*log(a*sec(x))+x*log(1+exp(2*im*x))+-1//2*im*x^2+-1//2*im*Polylogarithms.polylog(2,-1*exp(2*im*x)))
@test integrate(log(a*sec(x)^2), x) == :(x*log(a*sec(x)^2)+-1*im*x^2+-1*im*Polylogarithms.polylog(2,-1*exp(2*im*x))+2*x*log(1+exp(2*im*x)))
@test integrate(log(a*sec(x)^n), x) == :(x*log(a*sec(x)^n)+n*x*log(1+exp(2*im*x))+-1//2*im*n*x^2+-1//2*im*n*Polylogarithms.polylog(2,-1*exp(2*im*x)))
@test integrate(log(a*csc(x)), x) == :(x*log(a*csc(x))+x*log(1+-1*exp(2*im*x))+-1//2*im*x^2+-1//2*im*Polylogarithms.polylog(2,exp(2*im*x)))
@test integrate(log(a*csc(x)^2), x) == :(x*log(a*csc(x)^2)+-1*im*x^2+-1*im*Polylogarithms.polylog(2,exp(2*im*x))+2*x*log(1+-1*exp(2*im*x)))
@test integrate(log(a*csc(x)^n), x) == :(x*log(a*csc(x)^n)+n*x*log(1+-1*exp(2*im*x))+-1//2*im*n*x^2+-1//2*im*n*Polylogarithms.polylog(2,exp(2*im*x)))
@test integrate(cos(x)*log(1/2+-1//2*cos(2x)), x) == :(-2*sin(x)+log(1/2+-1//2*cos(2x))*sin(x))
@test integrate(log(exp(sin(x)))^-1*cot(x), x) == :((-1*log(exp(sin(x)))+sin(x))^-1*log(log(exp(sin(x))))+-1*(-1*log(exp(sin(x)))+sin(x))^-1*log(sin(x)))
@test integrate(sec(x)^2*log(cos(x)), x) == :(-1x+log(cos(x))*tan(x)+tan(x))
@test integrate(cot(x)*log(sin(x)), x) == :((1/2)*log(sin(x))^2)
@test integrate(sin(x)^2*cos(x)*log(sin(x)), x) == :(-1//9*sin(x)^3+1//3*sin(x)^3*log(sin(x)))
@test integrate(cos(a+b*x)*log(cos((1/2)*a+(1/2)*b*x)*sin((1/2)*a+(1/2)*b*x)), x) == :(-1*b^-1*sin(a+b*x)+b^-1*log(cos((1/2)*a+(1/2)*b*x)*sin((1/2)*a+(1/2)*b*x))*sin(a+b*x))
@test integrate(log(cos(x))^-1*tan(x), x) == :(-1*log(log(cos(x))))
@test integrate(log(cos(x))*tan(x), x) == :(-1//2*log(cos(x))^2)
@test integrate(log(cos(x))*sin(x), x) == :(-1*cos(x)*log(cos(x))+cos(x))
@test integrate(cos(x)*log(cos(x)), x) == :(-1*sin(x)+log(cos(x))*sin(x)+arctanh(sin(x)))
@test integrate(cos(x)*log(sin(x)), x) == :(-1*sin(x)+log(sin(x))*sin(x))
@test integrate(sin(x)^2*log(sin(x)), x) == :(1//4*x+(1/2)*x*log(sin(x))+-1//2*x*log(1+-1*exp(2*im*x))+1//4*im*x^2+1//4*im*Polylogarithms.polylog(2,exp(2*im*x))+1//4*cos(x)*sin(x)+-1//2*cos(x)*log(sin(x))*sin(x))
@test integrate(sin(x)^3*log(sin(x)), x) == :(-2//3*arctanh(cos(x))+-1//9*cos(x)^3+2//3*cos(x)+-1*cos(x)*log(sin(x))+1//3*cos(x)^3*log(sin(x)))
@test integrate(log(sin(x^(1/2))), x) == :(-1//2*Polylogarithms.polylog(3,exp(2*im*x^(1/2)))+x*log(sin(x^(1/2)))+-1*x*log(1+-1*exp(2*im*x^(1/2)))+1//3*im*x^3//2+im*x^(1/2)*Polylogarithms.polylog(2,exp(2*im*x^(1/2))))
@test integrate(csc(x)^2*log(sin(x)), x) == :(-1x+-1*cot(x)+-1*cot(x)*log(sin(x)))
@test integrate(log(x)*sinh(a+b*x), x) == :(b^-1*cosh(a+b*x)*log(x)+-1*b^-1*cosh(a)*coshintegral(b*x)+-1*b^-1*sinh(a)*sinhintegral(b*x))
@test integrate(sinh(a+b*x)^2*log(x), x) == :((1/2)*x+-1//2*x*log(x)+-1//4*b^-1*cosh(2a)*sinhintegral(2*b*x)+-1//4*b^-1*coshintegral(2*b*x)*sinh(2a)+(1/2)*b^-1*cosh(a+b*x)*log(x)*sinh(a+b*x))
@test integrate(sinh(a+b*x)^3*log(x), x) == :(-1*b^-1*cosh(a+b*x)*log(x)+-1//12*b^-1*cosh(3a)*coshintegral(3*b*x)+-1//12*b^-1*sinh(3a)*sinhintegral(3*b*x)+1//3*b^-1*cosh(a+b*x)^3*log(x)+3//4*b^-1*cosh(a)*coshintegral(b*x)+3//4*b^-1*sinh(a)*sinhintegral(b*x))
@test integrate(cosh(a+b*x)*log(x), x) == :(b^-1*log(x)*sinh(a+b*x)+-1*b^-1*cosh(a)*sinhintegral(b*x)+-1*b^-1*coshintegral(b*x)*sinh(a))
@test integrate(cosh(a+b*x)^2*log(x), x) == :(-1//2*x+(1/2)*x*log(x)+-1//4*b^-1*cosh(2a)*sinhintegral(2*b*x)+-1//4*b^-1*coshintegral(2*b*x)*sinh(2a)+(1/2)*b^-1*cosh(a+b*x)*log(x)*sinh(a+b*x))
@test integrate(cosh(a+b*x)^3*log(x), x) == :(b^-1*log(x)*sinh(a+b*x)+-3//4*b^-1*cosh(a)*sinhintegral(b*x)+-3//4*b^-1*coshintegral(b*x)*sinh(a)+-1//12*b^-1*cosh(3a)*sinhintegral(3*b*x)+-1//12*b^-1*coshintegral(3*b*x)*sinh(3a)+1//3*b^-1*sinh(a+b*x)^3*log(x))
@test integrate(log(a*sinh(x)), x) == :((1/2)*x^2+-1//2*Polylogarithms.polylog(2,exp(2x))+x*log(a*sinh(x))+-1*x*log(1+-1*exp(2x)))
@test integrate(log(a*sinh(x)^2), x) == :(x^2+-1*Polylogarithms.polylog(2,exp(2x))+x*log(a*sinh(x)^2)+-2*x*log(1+-1*exp(2x)))
@test integrate(log(a*sinh(x)^n), x) == :(x*log(a*sinh(x)^n)+(1/2)*n*x^2+-1//2*n*Polylogarithms.polylog(2,exp(2x))+-1*n*x*log(1+-1*exp(2x)))
@test integrate(log(a*cosh(x)), x) == :((1/2)*x^2+-1//2*Polylogarithms.polylog(2,-1*exp(2x))+x*log(a*cosh(x))+-1*x*log(1+exp(2x)))
@test integrate(log(a*cosh(x)^2), x) == :(x^2+-1*Polylogarithms.polylog(2,-1*exp(2x))+x*log(a*cosh(x)^2)+-2*x*log(1+exp(2x)))
@test integrate(log(a*cosh(x)^n), x) == :(x*log(a*cosh(x)^n)+(1/2)*n*x^2+-1//2*n*Polylogarithms.polylog(2,-1*exp(2x))+-1*n*x*log(1+exp(2x)))
@test integrate(log(tanh(x)), x) == :((1/2)*Polylogarithms.polylog(2,-1*exp(2x))+-1//2*Polylogarithms.polylog(2,exp(2x))+x*log(tanh(x))+2*x*arctanh(exp(2x)))
@test integrate(log(a*tanh(x)), x) == :((1/2)*Polylogarithms.polylog(2,-1*exp(2x))+-1//2*Polylogarithms.polylog(2,exp(2x))+x*log(a*tanh(x))+2*x*arctanh(exp(2x)))
@test integrate(log(a*tanh(x)^2), x) == :(-1*Polylogarithms.polylog(2,exp(2x))+x*log(a*tanh(x)^2)+4*x*arctanh(exp(2x))+Polylogarithms.polylog(2,-1*exp(2x)))
@test integrate(log(a*tanh(x)^n), x) == :(x*log(a*tanh(x)^n)+(1/2)*n*Polylogarithms.polylog(2,-1*exp(2x))+-1//2*n*Polylogarithms.polylog(2,exp(2x))+2*n*x*arctanh(exp(2x)))
@test integrate(log(coth(x)), x) == :((1/2)*Polylogarithms.polylog(2,exp(2x))+-1//2*Polylogarithms.polylog(2,-1*exp(2x))+x*log(coth(x))+-2*x*arctanh(exp(2x)))
@test integrate(log(a*coth(x)), x) == :((1/2)*Polylogarithms.polylog(2,exp(2x))+-1//2*Polylogarithms.polylog(2,-1*exp(2x))+x*log(a*coth(x))+-2*x*arctanh(exp(2x)))
@test integrate(log(a*coth(x)^2), x) == :(-1*Polylogarithms.polylog(2,-1*exp(2x))+x*log(a*coth(x)^2)+-4*x*arctanh(exp(2x))+Polylogarithms.polylog(2,exp(2x)))
@test integrate(log(a*coth(x)^n), x) == :(x*log(a*coth(x)^n)+(1/2)*n*Polylogarithms.polylog(2,exp(2x))+-1//2*n*Polylogarithms.polylog(2,-1*exp(2x))+-2*n*x*arctanh(exp(2x)))
@test integrate(log(a*sech(x)), x) == :((1/2)*Polylogarithms.polylog(2,-1*exp(2x))+-1//2*x^2+x*log(a*sech(x))+x*log(1+exp(2x)))
@test integrate(log(a*sech(x)^2), x) == :(-1*x^2+x*log(a*sech(x)^2)+2*x*log(1+exp(2x))+Polylogarithms.polylog(2,-1*exp(2x)))
@test integrate(log(a*sech(x)^n), x) == :(x*log(a*sech(x)^n)+(1/2)*n*Polylogarithms.polylog(2,-1*exp(2x))+-1//2*n*x^2+n*x*log(1+exp(2x)))
@test integrate(log(a*csch(x)), x) == :((1/2)*Polylogarithms.polylog(2,exp(2x))+-1//2*x^2+x*log(a*csch(x))+x*log(1+-1*exp(2x)))
@test integrate(log(a*csch(x)^2), x) == :(-1*x^2+x*log(a*csch(x)^2)+2*x*log(1+-1*exp(2x))+Polylogarithms.polylog(2,exp(2x)))
@test integrate(log(a*csch(x)^n), x) == :(x*log(a*csch(x)^n)+(1/2)*n*Polylogarithms.polylog(2,exp(2x))+-1//2*n*x^2+n*x*log(1+-1*exp(2x)))
@test integrate(cosh(a+b*x)*log(cosh((1/2)*a+(1/2)*b*x)*sinh((1/2)*a+(1/2)*b*x)), x) == :(-1*b^-1*sinh(a+b*x)+b^-1*log(cosh((1/2)*a+(1/2)*b*x)*sinh((1/2)*a+(1/2)*b*x))*sinh(a+b*x))
@test integrate(log(cosh(x)^2)*sinh(x), x) == :(-2*cosh(x)+cosh(x)*log(cosh(x)^2))
@test integrate(x^-1//2*log(x), x) == :(-4*x^(1/2)+2*x^(1/2)*log(x))
@test integrate(x*log(2+-3*x^2), x) == :(-1//2*x^2+-1*(1//3+-1//2*x^2)*log(2+-3*x^2))
@test integrate(x^-1*(1+-1*log(x)^2)^-1//2, x) == :(arcsin(log(x)))
@test integrate(16*x^3*log(x)^2, x) == :((1/2)*x^4+-2*x^4*log(x)+4*x^4*log(x)^2)
@test integrate(log((a+b*x)^(1/2)), x) == :(-1//2*x+b^-1*(a+b*x)*log((a+b*x)^(1/2)))
@test integrate(x*log((2+x)^(1/2)), x) == :((1/2)*x+-1*log(2+x)+-1//8*x^2+(1/2)*x^2*log((2+x)^(1/2)))
@test integrate(x*log((1+3x)^1//3), x) == :(-1//12*x^2+-1//54*log(1+3x)+1//18*x+(1/2)*x^2*log((1+3x)^1//3))
@test integrate(x*log(x+x^3), x) == :((1/2)*log(1+x^2)+-3//4*x^2+(1/2)*x^2*log(x+x^3))
@test integrate(log(x+(1+x^2)^(1/2)), x) == :(-1*(1+x^2)^(1/2)+x*log(x+(1+x^2)^(1/2)))
@test integrate(log(x+(-1+x^2)^(1/2)), x) == :(-1*(-1+x^2)^(1/2)+x*log(x+(-1+x^2)^(1/2)))
@test integrate(log(x+-1*(-1+x^2)^(1/2)), x) == :((-1+x^2)^(1/2)+x*log(x+-1*(-1+x^2)^(1/2)))
@test integrate(log(x^(1/2)+(1+x)^(1/2)), x) == :((1/2)*arcsinh(x^(1/2))+x*log(x^(1/2)+(1+x)^(1/2))+-1//2*x^(1/2)*(1+x)^(1/2))
@test integrate(x^1//3*log(x), x) == :(-9//16*x^4//3+3//4*x^4//3*log(x))
@test integrate(2^log(x), x) == :(x^(1+log(2))*(1+log(2))^-1)
@test integrate(x^-2*(1+-1*log(x)), x) == :(x^-1*log(x))
@test integrate(log(1+x+(1+x)^(1/2)), x) == :((1+x)^(1/2)+(1/2)*log(1+x)+-1x+x*log(1+x+(1+x)^(1/2)))
@test integrate(log(x+x^3), x) == :(-3x+2*arctan(x)+x*log(x+x^3))
@test integrate(2^log(-8+7x), x) == :((-8+7x)^(1+log(2))*(7+7*log(2))^-1)
@test integrate(log((5+76x)^-1*(-11+5x)), x) == :(-861//380*log(5+76x)+(-11//5+x)*log(-1*(5+76x)^-1*(11+-5x)))
@test integrate(log((13+x)^-1), x) == :(x+(13+x)*log((13+x)^-1))
@test integrate(x*log(x^-2*(1+x)), x) == :((1/2)*x+-1//2*log(1+x)+1//4*x^2+(1/2)*x^2*log(x^-2*(1+x)))
@test integrate(x^3*log(x^-2*(7+5x)), x) == :(-2401//2500*log(7+5x)+-49//200*x^2+1//16*x^4+7//60*x^3+343//500*x+1//4*x^4*log(x^-2*(7+5x)))
@test integrate((a+b*x)*log(a+b*x), x) == :(-1//4*b^-1*(a+b*x)^2+(1/2)*b^-1*(a+b*x)^2*log(a+b*x))
@test integrate((a+b*x)^2*log(a+b*x), x) == :(-1//9*b^-1*(a+b*x)^3+1//3*b^-1*(a+b*x)^3*log(a+b*x))
@test integrate((a+b*x)^-1*log(a+b*x), x) == :((1/2)*b^-1*log(a+b*x)^2)
@test integrate((a+b*x)^-2*log(a+b*x), x) == :(-1*b^-1*(a+b*x)^-1+-1*b^-1*(a+b*x)^-1*log(a+b*x))
@test integrate((a+b*x)^n*log(a+b*x), x) == :(-1*b^-1*(1+n)^-2*(a+b*x)^(1+n)+b^-1*(1+n)^-1*(a+b*x)^(1+n)*log(a+b*x))
@test integrate((a*x+b*x*log(c*x^n))^-1, x) == :(b^-1*n^-1*log(a+b*log(c*x^n)))
@test integrate((a*x+b*x*log(c*x^n)^2)^-1, x) == :(a^-1//2*b^-1//2*n^-1*arctan(a^-1//2*b^(1/2)*log(c*x^n)))
@test integrate((a*x+b*x*log(c*x^n)^3)^-1, x) == :(-1//6*a^-2//3*b^-1//3*n^-1*log(a^2//3+b^2//3*log(c*x^n)^2+-1*a^1//3*b^1//3*log(c*x^n))+1//3*a^-2//3*b^-1//3*n^-1*log(a^1//3+b^1//3*log(c*x^n))+-1//3*3^(1/2)*a^-2//3*b^-1//3*n^-1*arctan(1//3*3^(1/2)*a^-1//3*(a^1//3+-2*b^1//3*log(c*x^n))))
@test integrate((a*x+b*x*log(c*x^n)^4)^-1, x) == :(-1//4*2^(1/2)*a^-3//4*b^-1//4*n^-1*arctan(1+-1*2^(1/2)*a^-1//4*b^1//4*log(c*x^n))+-1//8*2^(1/2)*a^-3//4*b^-1//4*n^-1*log(a^(1/2)+b^(1/2)*log(c*x^n)^2+-1*2^(1/2)*a^1//4*b^1//4*log(c*x^n))+1//4*2^(1/2)*a^-3//4*b^-1//4*n^-1*arctan(1+2^(1/2)*a^-1//4*b^1//4*log(c*x^n))+1//8*2^(1/2)*a^-3//4*b^-1//4*n^-1*log(a^(1/2)+b^(1/2)*log(c*x^n)^2+2^(1/2)*a^1//4*b^1//4*log(c*x^n)))
@test integrate((a*x+b*x*log(c*x^n)^-1)^-1, x) == :(a^-1*log(x)+-1*b*a^-2*n^-1*log(b+a*log(c*x^n)))
@test integrate((a*x+b*x*log(c*x^n)^-2)^-1, x) == :(a^-1*log(x)+-1*a^-3//2*b^(1/2)*n^-1*arctan(a^(1/2)*b^-1//2*log(c*x^n)))
@test integrate((a*x+b*x*log(c*x^n)^-3)^-1, x) == :(a^-1*log(x)+-1//3*a^-4//3*b^1//3*n^-1*log(b^1//3+a^1//3*log(c*x^n))+1//6*a^-4//3*b^1//3*n^-1*log(b^2//3+a^2//3*log(c*x^n)^2+-1*a^1//3*b^1//3*log(c*x^n))+1//3*3^(1/2)*a^-4//3*b^1//3*n^-1*arctan(1//3*3^(1/2)*b^-1//3*(b^1//3+-2*a^1//3*log(c*x^n))))
@test integrate((a*x+b*x*log(c*x^n)^-4)^-1, x) == :(a^-1*log(x)+-1//4*2^(1/2)*a^-5//4*b^1//4*n^-1*arctan(1+2^(1/2)*a^1//4*b^-1//4*log(c*x^n))+-1//8*2^(1/2)*a^-5//4*b^1//4*n^-1*log(b^(1/2)+a^(1/2)*log(c*x^n)^2+2^(1/2)*a^1//4*b^1//4*log(c*x^n))+1//4*2^(1/2)*a^-5//4*b^1//4*n^-1*arctan(1+-1*2^(1/2)*a^1//4*b^-1//4*log(c*x^n))+1//8*2^(1/2)*a^-5//4*b^1//4*n^-1*log(b^(1/2)+a^(1/2)*log(c*x^n)^2+-1*2^(1/2)*a^1//4*b^1//4*log(c*x^n)))
@test integrate((x+x*log(7x)^2+x*log(7x))^-1, x) == :(2//3*3^(1/2)*arctan(1//3*3^(1/2)*(1+2*log(7x))))
@test integrate(x^-1*(1+log(3x)^2+-1*log(3x))^-1*(-1+log(3x)), x) == :((1/2)*log(1+log(3x)^2+-1*log(3x))+1//3*3^(1/2)*arctan(1//3*3^(1/2)*(1+-2*log(3x))))
@test integrate((x+x*log(3x)^3)^-1*(-1+log(3x)^2), x) == :((1/2)*log(1+log(3x)^2+-1*log(3x))+1//3*3^(1/2)*arctan(1//3*3^(1/2)*(1+-2*log(3x))))
@test integrate((x+x*log(3x)^2+x*log(3x))^-1*(-1+log(3x)^2), x) == :(-1//2*log(1+log(3x)^2+log(3x))+-1*3^(1/2)*arctan(1//3*3^(1/2)*(1+2*log(3x)))+log(x))
@test integrate(x^-5*log(x^-1)^2, x) == :(-1//32*x^-4+-1//4*x^-4*log(x^-1)^2+1//8*x^-4*log(x^-1))
@test integrate((-1*log(a*x^2))^-1//2, x) == :(-1//2*x*2^(1/2)*pi^(1/2)*(a*x^2)^-1//2*erf((1/2)*2^(1/2)*(-1*log(a*x^2))^(1/2)))
@test integrate((-1*log(a*x^-2))^-1//2, x) == :((1/2)*x*2^(1/2)*pi^(1/2)*(a*x^-2)^(1/2)*erfi((1/2)*2^(1/2)*(-1*log(a*x^-2))^(1/2)))
@test integrate((-1*log(a*x^n))^-1//2, x) == :(-1*x*pi^(1/2)*n^-1//2*(a*x^n)^(-1*n^-1)*erf(n^-1//2*(-1*log(a*x^n))^(1/2)))
@test integrate(x^-1*log(1+x^(1/2)+-1x), x) == :(-2*Polylogarithms.polylog(2,2*x^(1/2)*(1+-1*5^(1/2))^-1)+2*Polylogarithms.polylog(2,1+-2*x^(1/2)*(1+5^(1/2))^-1)+-2*log(x^(1/2))*log(1+-2*x^(1/2)*(1+-1*5^(1/2))^-1)+-2*log(1/2+(1/2)*5^(1/2))*log(1+5^(1/2)+-2*x^(1/2))+2*log(x^(1/2))*log(1+x^(1/2)+-1x))
@test integrate(x*(a+b*x)^-1*log(c+d*x), x) == :(-1*x*b^-1+-1*a*b^-2*Polylogarithms.polylog(2,b*(b*c+-1*a*d)^-1*(c+d*x))+b^-1*d^-1*(c+d*x)*log(c+d*x)+-1*a*b^-2*log(-1*d*(b*c+-1*a*d)^-1*(a+b*x))*log(c+d*x))
@test integrate((-1+x)^-1*log(x), x) == :(-1*Polylogarithms.polylog(2,1+-1x))
@test integrate(x*(a+b*x)^-1*log(1+-1a+-1*b*x), x) == :(-1*x*b^-1+a*b^-2*Polylogarithms.polylog(2,a+b*x)+-1*b^-2*(1+-1a+-1*b*x)*log(1+-1a+-1*b*x))
@test integrate(x^-1*(b+c*x)^-1*(b+2*c*x)*log(x), x) == :((1/2)*log(x)^2+log(x)*log(1+c*x*b^-1)+Polylogarithms.polylog(2,-1*c*x*b^-1))
@test integrate(log(x)*sin(x*log(x))+sin(x*log(x)), x) == :(-1*cos(x*log(x)))
@test integrate(x^-2*log((1+(-1+x)^2)^-1*(1+-1*(-1+x)^2)), x) == :((1/2)*log(x)+(1/2)*log(2+-1x)+-1*x^-1+-1//2*log(2+x^2+-2x)+-1*x^-1*log((1+(-1+x)^2)^-1*(1+-1*(1+-1x)^2))+arctan(1+-1x))
@test integrate(log(x+x^(1/2)), x) == :(x^(1/2)+-1x+-1*log(1+x^(1/2))+x*log(x+x^(1/2)))
@test integrate(log(-1*x*(1+x)^-1), x) == :(-1*log(1+x)+x*log(-1*x*(1+x)^-1))
@test integrate(log((1+x)^-1*(-1+x)), x) == :(-2*log(1+x)+-1*(1+-1x)*log(-1*(1+x)^-1*(1+-1x)))
@test integrate((1+x)^-2*log((1+x^2)^-1*(1+-1*x^2)), x) == :((1/2)*log(1+-1*x^2)+-1*(1+x)^-1+-1*arctan(x)+-1//2*log(1+x^2)+-1*(1+x)^-1*log((1+x^2)^-1*(1+-1*x^2)))
@test integrate((1+x^2)^-1*log(c*(1+x^2)^n), x) == :(arctan(x)*log(c*(1+x^2)^n)+im*n*arctan(x)^2+im*n*Polylogarithms.polylog(2,1+-2*(1+im*x)^-1)+2*n*arctan(x)*log(2*(1+im*x)^-1))
@test integrate((1+x^2)^-1*log(x^2*(1+x^2)^-1), x) == :(im*arctan(x)^2+im*Polylogarithms.polylog(2,-1+2*(1+-1*im*x)^-1)+arctan(x)*log(x^2*(1+x^2)^-1)+-2*arctan(x)*log(2+-2*(1+-1*im*x)^-1))
@test integrate((a+b*x^2)^-1*log(c*x^2*(a+b*x^2)^-1), x) == :(im*a^-1//2*b^-1//2*arctan(x*a^-1//2*b^(1/2))^2+im*a^-1//2*b^-1//2*Polylogarithms.polylog(2,-1+2*a^(1/2)*(a^(1/2)+-1*im*x*b^(1/2))^-1)+a^-1//2*b^-1//2*arctan(x*a^-1//2*b^(1/2))*log(c*x^2*(a+b*x^2)^-1)+-2*a^-1//2*b^-1//2*arctan(x*a^-1//2*b^(1/2))*log(2+-2*a^(1/2)*(a^(1/2)+-1*im*x*b^(1/2))^-1))
@test integrate((1+-1*a^2*x^2)^-1*log(1+im*(1+a*x)^-1//2*(1+-1*a*x)^(1/2)), x) == :(a^-1*Polylogarithms.polylog(2,-1*im*(1+a*x)^-1//2*(1+-1*a*x)^(1/2)))
@test integrate((1+-1*a^2*x^2)^-1*log(1+-1*im*(1+a*x)^-1//2*(1+-1*a*x)^(1/2)), x) == :(a^-1*Polylogarithms.polylog(2,im*(1+a*x)^-1//2*(1+-1*a*x)^(1/2)))
@test integrate(log(exp(a+b*x)), x) == :((1/2)*b^-1*log(exp(a+b*x))^2)
@test integrate(log(exp(a+b*x^n)), x) == :(x*log(exp(a+b*x^n))+-1*b*n*x^(1+n)*(1+n)^-1)
@test integrate(exp(a+b*x)*log(x), x) == :(b^-1*exp(a+b*x)*log(x)+-1*b^-1*exp(a)*expintegralei(b*x))
@test integrate((x+4*x*log(x)^2)^-1*log(x), x) == :(1//8*log(1+4*log(x)^2))
@test integrate(x^-1*(x+log(x))^-1*(1+-1*log(x)), x) == :(log(1+x^-1*log(x)))
@test integrate((x+log(x))^-1*log(x)^-1*(1+x), x) == :(-1*log(x+log(x))+log(log(x))+logintegral(x))
@test integrate(log(2+(x^-1*(1+x))^(1/2)), x) == :((1/2)*log(1+(1+x^-1)^(1/2))+-1//3*log(2+(1+x^-1)^(1/2))+-1//6*log(1+-1*(1+x^-1)^(1/2))+x*log(2+(x^-1*(1+x))^(1/2)))
@test integrate(log(1+(x^-1*(1+x))^(1/2)), x) == :((1/2)*arctanh((x^-1*(1+x))^(1/2))+-1*(2+2*(1+x^-1)^(1/2))^-1+x*log(1+(x^-1*(1+x))^(1/2)))
@test integrate(log((x^-1*(1+x))^(1/2)), x) == :((1/2)*log(1+x)+x*log((1+x^-1)^(1/2)))
@test integrate(log(-1+(x^-1*(1+x))^(1/2)), x) == :(-1*(2+-2*(1+x^-1)^(1/2))^-1+-1//2*arctanh((1+x^-1)^(1/2))+x*log(-1+(x^-1*(1+x))^(1/2)))
@test integrate(log(-2+(x^-1*(1+x))^(1/2)), x) == :((1/2)*log(1+-1*(1+x^-1)^(1/2))+-1//3*log(2+-1*(1+x^-1)^(1/2))+-1//6*log(1+(1+x^-1)^(1/2))+x*log(-2+(x^-1*(1+x))^(1/2)))
@test integrate(x^(a*x)+x^(a*x)*log(x), x) == :(a^-1*x^(a*x))
@test integrate((log(x)^m)^p, x) == :((log(x)^m)^p*(-1*log(x))^(-1*m*p)*SpecialFunctions.gamma(1+m*p,-1*log(x)))
@test integrate((a+b*log(x))^-1//2*log(x), x) == :(x*b^-1*(a+b*log(x))^(1/2)+-1//2*pi^(1/2)*b^-3//2*(b+2a)*erfi(b^-1//2*(a+b*log(x))^(1/2))*exp(-1*a*b^-1))
@test integrate((a+-1*b*log(x))^-1//2*log(x), x) == :(-1*x*b^-1*(a+-1*b*log(x))^(1/2)+-1//2*pi^(1/2)*b^-3//2*(-1b+2a)*erf(b^-1//2*(a+-1*b*log(x))^(1/2))*exp(a*b^-1))
@test integrate((a+b*log(x))^-1//2*(A+B*log(x)), x) == :(B*x*b^-1*(a+b*log(x))^(1/2)+(1/2)*pi^(1/2)*b^-3//2*(-1*B*(b+2a)+2*A*b)*erfi(b^-1//2*(a+b*log(x))^(1/2))*exp(-1*a*b^-1))
@test integrate((a+-1*b*log(x))^-1//2*(A+B*log(x)), x) == :(-1*B*x*b^-1*(a+-1*b*log(x))^(1/2)+-1//2*pi^(1/2)*b^-3//2*(-1*B*b+2*A*b+2*B*a)*erf(b^-1//2*(a+-1*b*log(x))^(1/2))*exp(a*b^-1))
@test integrate(x^2*log(log(x)*sin(x)), x) == :(-1//3*expintegralei(3*log(x))+-1//2*x*Polylogarithms.polylog(3,exp(2*im*x))+-1//3*x^3*log(1+-1*exp(2*im*x))+-1//4*im*Polylogarithms.polylog(4,exp(2*im*x))+1//3*x^3*log(log(x)*sin(x))+1//12*im*x^4+(1/2)*im*x^2*Polylogarithms.polylog(2,exp(2*im*x)))
@test integrate(x*log(log(x)*sin(x)), x) == :(-1//2*expintegralei(2*log(x))+-1//4*Polylogarithms.polylog(3,exp(2*im*x))+(1/2)*x^2*log(log(x)*sin(x))+-1//2*x^2*log(1+-1*exp(2*im*x))+1//6*im*x^3+(1/2)*im*x*Polylogarithms.polylog(2,exp(2*im*x)))
@test integrate(log(log(x)*sin(x)), x) == :(-1*logintegral(x)+x*log(log(x)*sin(x))+(1/2)*im*x^2+(1/2)*im*Polylogarithms.polylog(2,exp(2*im*x))+-1*x*log(1+-1*exp(2*im*x)))
@test integrate(x^2*log(exp(x)*log(x)*sin(x)), x) == :(-1//3*expintegralei(3*log(x))+x^4*(-1//12+1//12*im)+-1//2*x*Polylogarithms.polylog(3,exp(2*im*x))+-1//3*x^3*log(1+-1*exp(2*im*x))+-1//4*im*Polylogarithms.polylog(4,exp(2*im*x))+1//3*x^3*log(exp(x)*log(x)*sin(x))+(1/2)*im*x^2*Polylogarithms.polylog(2,exp(2*im*x)))
@test integrate(x*log(exp(x)*log(x)*sin(x)), x) == :(-1//2*expintegralei(2*log(x))+-1//4*Polylogarithms.polylog(3,exp(2*im*x))+x^3*(-1//6+1//6*im)+(1/2)*x^2*log(exp(x)*log(x)*sin(x))+-1//2*x^2*log(1+-1*exp(2*im*x))+(1/2)*im*x*Polylogarithms.polylog(2,exp(2*im*x)))
@test integrate(log(exp(x)*log(x)*sin(x)), x) == :(-1*logintegral(x)+x*log(exp(x)*log(x)*sin(x))+x^2*(-1//2+(1/2)*im)+(1/2)*im*Polylogarithms.polylog(2,exp(2*im*x))+-1*x*log(1+-1*exp(2*im*x)))

max_stars_repo_path: test/3 Logarithms/3.5 Logarithm functions.jl


text:
##################
# Load Libraries #
##################
push!(LOAD_PATH,pwd())
using JuliaPBF
using BenchmarkTools
using Printf

##################
# Initialization #
##################
INPUT_DIR   = "./JuliaPBF/input.xml" # Directory xml Inputs
ANALYDATA   = JuliaPBF.IO_dev.Parsing_xml_file(INPUT_DIR) # Parsing Inputs
SIMULDATA   = JuliaPBF.Solver.PreProcessing(ANALYDATA) # FillInitialBox, GenInitGrid

##############``
# Run Solver #
##############
global curr_time = 0.0
global ii       = 0
while curr_time < ANALYDATA.endTime
    global curr_time += ANALYDATA.timeStep.dt
    @printf("Time = %10.5f \n",curr_time)
    # @printf("  Update for          :")
    # @time
    JuliaPBF.Solver.Update(SIMULDATA, ANALYDATA)

    global ii += 1
    # @printf("  Writing Output for  :")
    # @time
    JuliaPBF.IO_dev.Writing_ascii_file(SIMULDATA, "out__"*lpad(ii,5,"0"))
end

max_stars_repo_name: Hipgineer/JuliaPBF

max_issues_repo_name: Hipgineer/JuliaPBF

max_forks_repo_name: Hipgineer/JuliaPBF


text:
# Julia wrapper for header: /usr/local/include/libavutil/pixelutils.h
# Automatically generated using Clang.jl wrap_c, version 0.0.0

export
    av_pixelutils_get_sad_fn

function av_pixelutils_get_sad_fn(w_bits::Integer,h_bits::Integer,aligned::Integer,log_ctx)
    ccall((:av_pixelutils_get_sad_fn,libavutil),av_pixelutils_sad_fn,(Cint,Cint,Cint,Ptr{Void}),w_bits,h_bits,aligned,log_ctx)
end

max_stars_repo_name: asafasban/AAVideoIO

max_issues_repo_name: asafasban/AAVideoIO

max_forks_repo_name: asafasban/AAVideoIO


text:
# Source: Lanshammar, H. (1982).
# On precision limits for derivatives numerically calculated from noisy data
# Journal of Biomechanics 15(6), 459-470

"""Define parameters for Lanshammar's polynomial filter"""
function lpparams(n, p; window=epanwin, dt::Real=1.)
    U = zeros(2n+1,p+1)
    for k=0:p
      U[:,k+1] = (-n:n).^k
    end
    w = window(2*n+1)
    W = diagm(w./maximum(w))
    V = U'*W*U
    f = map(factorial, 0:p) ./ (-dt).^(0:p)
    Dict(:h => diagm(f)*(V\eye(p+1))*U'*W, :p=>p)
end

"""Apply Lanshammar polynomial filter"""
function lpfit(x::Matrix; h::VecOrMat=[1], p::Integer=0);
y = zeros(size(x)..., p+1)
for k=1:p+1
  y[:,:,k] = filt(collect(h[k,:]),1,x)
end
y
end

function lpfit(x::Vector; h::VecOrMat=[1], p::Integer=0);
y = zeros(length(x), p+1)
for k=1:p+1
  y[:,k] = filt(collect(h[k,:]),1,x)
end
y
end

"""Table of optimal bandwidths"""
optband =
    [NaN  .275  NaN; # p=1
     .53  .275  .33; # p=2
     .53  .600  .33; # p=3
     .82  .600  .70; # p=4
     .82  .920  .70; # p=5
    1.15  .920 1.02; # p=6
    1.15 1.250 1.02; # p=7
    1.48 1.250 1.35; # p=8
    1.48   NaN 1.35] # p=9

nmin =
    [0 1 0; # p=1
     1 1 1; # p=2
     1 2 1; # p=3
     2 2 2; # p=4
     2 3 2; # p=5
     3 3 3; # p=6
     3 4 3; # p=7
     4 4 4; # p=8
     4 0 4] # p=9

function optbandn(p,k,w)
    !(1 <= p <= size(optband)[1]) &&
        error("polynomial order must be between 1 and $(size(optband)[1])")
    !(0 <= k <= size(optband)[2]) &&
        error("the target order of the derivative must be between 0 and $(size(optband)[2])")
    isnan(optband[p,k+1]) && error("value undefined for p==$p, k==$k")
    max(ceil(Integer, optband[p,k+1]/w), nmin[p,k+1])
end


text:
#!/usr/bin/env julia
# this script is thought to be designed to counduct SNAQ! on CFs
# which were obtaines from SNPs by SNPs2CF.
# input: 	- csv output of SNPs2CF
# 		- hypothetical tree as starting topology

#using Pkg # to use functions that manage packages
#Pkg.add("PhyloNetworks") # to download & install package PhyloNetworks
#Pkg.add("PhyloPlots")
#Pkg.add("RCall")      # packaage to call R from within julia
#Pkg.add("CSV")        # to read from / write to text files, e.g. csv files
#Pkg.add("DataFrames") # to create & manipulate data frames
#Pkg.add("StatsModels")# for regression formulas
using PhyloNetworks   # may take some time: pre-compiles functions in that package
# using PhyloPlots
# using Distributed

print("we are running")

snpCF = readTableCF(ARGS[1]) # input our CF table
tre = readTopology(ARGS[2]) # input a starting topology

# print(tre)

n0_out = ARGS[1][1:end-4] * "_net0"
# n1_out = ARGS[1][1:end-4] * "_net1"
# n2_out = ARGS[1][1:end-4] * "_net2"
# plot_out = ARGS[1][1:end-4] * "_plot.pdf"

# print(n0_out)

rseed = rand((100:999))
net0 = snaq!(tre,  snpCF, hmax=0, filename=n0_out, seed=rseed)
# rseed = rand((100:999))
# net1 = snaq!(net0, snpCF, hmax=1, filename=n1_out, seed=rseed)

# addprocs(2) # tells Julia to add 2 worker cores
# @everywhere using PhyloNetworks # tells these cores to load the PhyloNetworks package for themselves
# net2 = snaq!(net1, snpCF, hmax=2, filename=n2_out, seed=789, runs=5)

# plot(net0, :R);

# R"pdf"(plot_out, width=3, height=3);
# plot(net0, :R);
# R"dev.off()";

max_stars_repo_name: biothomme/--valencene

max_issues_repo_name: biothomme/--valencene

max_forks_repo_name: biothomme/--valencene


text:
# Author: Youngjun Kim, youngjun@stanford.edu
# Date: 06/16/2014

module Sensor

export
    AbstractSensor,

    initialize,
    update,

    updateSensor,

    SimpleTCASSensor,
    SimpleTCASSRState,
    SimpleTCASSensorInput,
    SimpleTCASSensorOutput,

    ACASXSensor,
    ACASXSensorState,
    ACASXSensorInput,
    ACASXSensorOutput

import CommonInterfaces: initialize, update

using AbstractSensorImpl

using SimpleTCASSensorImpl

using ACASXSensorImpl

end

max_stars_repo_name: sisl/RLES-SISLES

max_issues_repo_name: sisl/RLES-SISLES

max_forks_repo_name: sisl/RLES-SISLES


text:
export zhangyeunginequality, matus41, matus42, matus51, matus52, matus53

function zhangyeunginequality(i::Signed, j::Signed, k::Signed, l::Signed)
    n = 4
    I = set(i)
    J = set(j)
    K = set(k)
    L = set(l)
    submodular(n, K, L, I) + submodular(n, K, L, J) + submodular(n, I, J) - submodular(n, K, L) +
    submodular(n, I, K, L) + submodular(n, I, L, K) + submodular(n, K, L, I)
end
zhangyeunginequality() = zhangyeunginequality(1, 2, 3, 4)

# function constraint41()
#   ingleton(1,2)
# end
# function constraint42()
#   submodular(4,2,3,4)
# end
# function constraint43()
#   submodular(4,2,4,3) + submodular(4, 3,4,2)
# end
function checkalldifferent(x)
    s = BitSet()
    for i in x
        push!(s, i)
    end
    if length(s) < length(x)
        error("Arguments must be all different")
    end
end
function matus41(s, i=1, j=2, k=3, l=4)
    checkalldifferent((i, j, k, l))
    2s*ingleton(i, j) + 2submodular(4,j,k,l) + s*(s+1)*(submodular(4,j,l,k) + submodular(4,k,l,j))
end
function matus42(s, i=1, j=2, k=3, l=4)
    checkalldifferent((i, j, k, l))
    (k, l) = getkl(i, j)
    2s*ingleton(i, j) + 2submodular(4,i,k,l) + 2s*(submodular(4,k,l,i)+submodular(4,i,l,k)) + s*(s-1)*(submodular(4,j,l,k)+submodular(4,k,l,j))
end

function matus5aux(s, ingli, inglj, inglk, ingll, i, j, k, l, m)
    2s*(ingleton(5,ingli,inglj,inglk,ingll)+submodular(5,k,l,m)+submodular(5,l,m,k)) + 2submodular(5,k,m,l) + s*(s-1)*(submodular(5,j,l,k)+submodular(5,k,l,j))
end

function matus51(s, i=1, j=2, k=3, l=4, m=5)
    checkalldifferent((i, j, k, l, m))
    matus5aux(s, i, j, k, l, i, j, k, l, m)
end
function matus52(s, i=1, j=2, k=3, l=4, m=5)
    checkalldifferent((i, j, k, l, m))
    matus5aux(s, i, k, j, l, i, j, k, l, m)
end
function matus53(s, i=1, j=2, k=3, l=4, m=5)
    checkalldifferent((i, j, k, l, m))
    matus5aux(s, i, l, j, k, i, j, k, l, m)
end


text:
using Colors, FileIO

import Base: getindex, setindex!, size, show

export Image, width, height
export pixels

struct Image{T<:Colorant}
   pixels::Matrix{T}
end

"""
    Image(filename)
Creates an image from an image file stored on disk. If loading
a `gif` image, this will produce multiple images
"""
function Image(filename::AbstractString)
    pixels = load(filename)
    dims = ndims(pixels)
    if dims == 2
        Image(pixels)
    elseif dims == 3
        map(1:size(pixels, 3)) do i
           Image(pixels[:, :, i])
        end
    else
        error("Don't support loading imagse with $dims dimensions")
    end
end

"""
    Image(w::Int, h::Int)
Creates a blank image of width `w` and height `h`.
"""
function Image(w::Int, h::Int)
    Image(fill(colorant"black", h, w))
end

"""
    Image(w::Int, h::Int, c::Colorant)
Creates image of width `w` and height `h` filled with color `c`.
"""
function Image(w::Int, h::Int, c::Colorant)
    Image(fill(c, h, w))
end

getindex(img::Image, x::Int, y::Int) = img.pixels[y+1, x+1]

function setindex!(img::Image, color::Colorant, x::Int, y::Int)
    img.pixels[y+1, x+1] = color
end

function getindex(img::Image, X::UnitRange{Int}, Y::UnitRange{Int})
    I = first(Y)+1:last(Y)
    J = first(X)+1:last(X)
    Image(img.pixels[I, J])
end

function getindex(img::Image, x::Int, Y::UnitRange{Int})
    I = first(Y)+1:last(Y)
    j = x+1
    img.pixels[I, j]
end

function getindex(img::Image, X::UnitRange{Int}, y::Int)
    i = y+1
    J = first(X)+1:last(X)
    img.pixels[i, J]
end

width(img::Image) = size(img.pixels, 2)
height(img::Image) = size(img.pixels, 1)

"""
    size(img::Image) -> Size
Gets the width and the height of image `img`.
"""
size(img::Image) = Size(width(img), height(img))

show(io::IO, mime::MIME"text/plain", img::Image)    = show(io, mime, img.pixels)
show(io::IO, mime::MIME"image/svg+xml", img::Image) = show(io, mime, img.pixels)

function pixels(img::Image)
   img.pixels
end