# LogExpFunctions

Various special functions based on log and exp moved from StatsFuns.jl into a separate package, to minimize dependencies. These functions only use native Julia code, so there is no need to depend on librmath or similar libraries. See the discussion at StatsFuns.jl#46.

The original authors of these functions are the StatsFuns.jl contributors.

LogExpFunctions supports InverseFunctions.inverse and ChangesOfVariables.test_with_logabsdet_jacobian for log1mexp, log1pexp, log1pexp, log2mexp, log2mexp, logexpm1, logistic, logistic, logit, and logcosh (no inverse).

LogExpFunctions.xlogxFunction
xlogx(x)


Return x * log(x) for x ≥ 0, handling $x = 0$ by taking the downward limit.

julia> xlogx(0)
0.0
source
LogExpFunctions.xlogyFunction
xlogy(x, y)


Return x * log(y) for y > 0 with correct limit at $x = 0$.

julia> xlogy(0, 0)
0.0
source
LogExpFunctions.xlog1pyFunction
xlog1py(x, y)


Return x * log(1 + y) for y ≥ -1 with correct limit at $x = 0$.

julia> xlog1py(0, -1)
0.0
source
LogExpFunctions.xexpxFunction
xexpx(x)


Return x * exp(x) for x > -Inf, or zero if x == -Inf.

julia> xexpx(-Inf)
0.0
source
LogExpFunctions.xexpyFunction
xexpy(x, y)


Return x * exp(y) for y > -Inf, or zero if y == -Inf.

julia> xexpy(1.0, -Inf)
0.0
source
LogExpFunctions.logcoshFunction
logcosh(x)


Return log(cosh(x)), carefully evaluated without intermediate calculation of cosh(x).

The implementation ensures logcosh(-x) = logcosh(x).

source
LogExpFunctions.log1pmxFunction
log1pmx(x)


Return log(1 + x) - x.

Use naive calculation or range reduction outside kernel range. Accurate ~2ulps for all x. This will fall back to the naive calculation for argument types different from Float64.

source
LogExpFunctions.logmxp1Function
logmxp1(x)


Return log(x) - x + 1 carefully evaluated. This will fall back to the naive calculation for argument types different from Float64.

source
LogExpFunctions.logaddexpFunction
logaddexp(x, y)


Return log(exp(x) + exp(y)), avoiding intermediate overflow/undeflow, and handling non-finite values.

source
LogExpFunctions.logsumexpFunction
logsumexp(X)


Compute log(sum(exp, X)).

X should be an iterator of real or complex numbers. The result is computed in a numerically stable way that avoids intermediate over- and underflow, using a single pass over the data.

See also logsumexp!.

References

Sebastian Nowozin: Streaming Log-sum-exp Computation

source
logsumexp(X; dims)


Compute log.(sum(exp.(X); dims=dims)).

The result is computed in a numerically stable way that avoids intermediate over- and underflow, using a single pass over the data.

See also logsumexp!.

References

Sebastian Nowozin: Streaming Log-sum-exp Computation

source