The elementwise logarithm. log computes the logarithm, by default the natural logarithm, log10 computes the common (i.e., base 10) logarithm, and log2 computes the binary (i.e., base 2) logarithms. The general form log(x, base) computes logarithms with base base. log1p computes elementwise the function \(\log(1+x)\).

# S4 method for Expression
log(x, base = base::exp(1))

# S4 method for Expression
log10(x)

# S4 method for Expression
log2(x)

# S4 method for Expression
log1p(x)

Arguments

x

An Expression.

base

(Optional) A positive number that is the base with respect to which the logarithm is computed. Defaults to \(e\).

Value

An Expression representing the exponentiated input.

Examples

# Log in objective
x <- Variable(2)
obj <- Maximize(sum(log(x)))
constr <- list(x <= matrix(c(1, exp(1))))
prob <- Problem(obj, constr)
result <- solve(prob)
result$value
#> [1] 1
result$getValue(x)
#>          [,1]
#> [1,] 1.000000
#> [2,] 2.718282

# Log in constraint
obj <- Minimize(sum(x))
constr <- list(log2(x) >= 0, x <= matrix(c(1,1)))
prob <- Problem(obj, constr)
result <- solve(prob)
result$value
#> [1] 2
result$getValue(x)
#>      [,1]
#> [1,]    1
#> [2,]    1

# Index into log
obj <- Maximize(log10(x)[2])
constr <- list(x <= matrix(c(1, exp(1))))
prob <- Problem(obj, constr)
result <- solve(prob)
result$value
#> [1] 0.4342945

# Scalar log
obj <- Maximize(log1p(x[2]))
constr <- list(x <= matrix(c(1, exp(1))))
prob <- Problem(obj, constr)
result <- solve(prob)
result$value
#> [1] 1.313262