ln(1 + x)

?

Percentage Accurate: 39.0% → 100.0%
Time: 3.0s
Precision: binary64
Cost: 6464

?

\[\log \left(1 + x\right) \]
\[\mathsf{log1p}\left(x\right) \]
(FPCore (x) :precision binary64 (log (+ 1.0 x)))
(FPCore (x) :precision binary64 (log1p x))
double code(double x) {
	return log((1.0 + x));
}
double code(double x) {
	return log1p(x);
}
public static double code(double x) {
	return Math.log((1.0 + x));
}
public static double code(double x) {
	return Math.log1p(x);
}
def code(x):
	return math.log((1.0 + x))
def code(x):
	return math.log1p(x)
function code(x)
	return log(Float64(1.0 + x))
end
function code(x)
	return log1p(x)
end
code[x_] := N[Log[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]
code[x_] := N[Log[1 + x], $MachinePrecision]
\log \left(1 + x\right)
\mathsf{log1p}\left(x\right)

Local Percentage Accuracy?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original39.0%
Target99.7%
Herbie100.0%
\[\begin{array}{l} \mathbf{if}\;1 + x = 1:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \log \left(1 + x\right)}{\left(1 + x\right) - 1}\\ \end{array} \]

Derivation?

  1. Initial program 37.3%

    \[\log \left(1 + x\right) \]
  2. Simplified100.0%

    \[\leadsto \color{blue}{\mathsf{log1p}\left(x\right)} \]
    Step-by-step derivation

    [Start]37.3

    \[ \log \left(1 + x\right) \]

    log1p-def [=>]100.0

    \[ \color{blue}{\mathsf{log1p}\left(x\right)} \]
  3. Final simplification100.0%

    \[\leadsto \mathsf{log1p}\left(x\right) \]

Reproduce?

herbie shell --seed 2023161 
(FPCore (x)
  :name "ln(1 + x)"
  :precision binary64

  :herbie-target
  (if (== (+ 1.0 x) 1.0) x (/ (* x (log (+ 1.0 x))) (- (+ 1.0 x) 1.0)))

  (log (+ 1.0 x)))