Average Error: 39.1 → 0.2
Time: 3.1s
Precision: binary64
Cost: 6913
\[\log \left(1 + x\right)\]
\[\begin{array}{l} \mathbf{if}\;x \leq 0.00012347626382596744:\\ \;\;\;\;x + x \cdot \left(x \cdot \left(-0.5 + x \cdot 0.3333333333333333\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + 1\right)\\ \end{array}\]
\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;x \leq 0.00012347626382596744:\\
\;\;\;\;x + x \cdot \left(x \cdot \left(-0.5 + x \cdot 0.3333333333333333\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\log \left(x + 1\right)\\

\end{array}
(FPCore (x) :precision binary64 (log (+ 1.0 x)))
(FPCore (x)
 :precision binary64
 (if (<= x 0.00012347626382596744)
   (+ x (* x (* x (+ -0.5 (* x 0.3333333333333333)))))
   (log (+ x 1.0))))
double code(double x) {
	return log(1.0 + x);
}
double code(double x) {
	double tmp;
	if (x <= 0.00012347626382596744) {
		tmp = x + (x * (x * (-0.5 + (x * 0.3333333333333333))));
	} else {
		tmp = log(x + 1.0);
	}
	return tmp;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original39.1
Target0.2
Herbie0.2
\[\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}\]

Alternatives

Alternative 1
Error39.5
Cost39104
\[\sqrt[3]{\log \left(x + 1\right)} \cdot \left(\sqrt[3]{\log \left(x + 1\right)} \cdot \sqrt[3]{\log \left(x + 1\right)}\right)\]
Alternative 2
Error53.4
Cost19968
\[\log \left(1 + {x}^{3}\right) - \log \left(1 + \left(x \cdot x - x\right)\right)\]
Alternative 3
Error40.1
Cost19392
\[e^{\log \log \left(x + 1\right)}\]
Alternative 4
Error60.5
Cost13376
\[\log \left(1 - x \cdot x\right) - \log \left(1 - x\right)\]
Alternative 5
Error39.1
Cost6592
\[\log \left(x + 1\right)\]
Alternative 6
Error42.6
Cost6464
\[\log x\]
Alternative 7
Error21.2
Cost704
\[x \cdot \left(1 + x \cdot \left(-0.5 + x \cdot 0.3333333333333333\right)\right)\]
Alternative 8
Error21.2
Cost704
\[x + x \cdot \left(x \cdot \left(-0.5 + x \cdot 0.3333333333333333\right)\right)\]
Alternative 9
Error21.6
Cost448
\[x - \left(x \cdot x\right) \cdot 0.5\]
Alternative 10
Error21.0
Cost64
\[x\]
Alternative 11
Error59.3
Cost64
\[1\]
Alternative 12
Error61.1
Cost64
\[0\]
Alternative 13
Error62.1
Cost64
\[-1\]

Error

Derivation

  1. Split input into 2 regimes
  2. if x < 1.2347626382596744e-4

    1. Initial program 59.1

      \[\log \left(1 + x\right)\]
    2. Taylor expanded around 0 0.2

      \[\leadsto \color{blue}{\left(x + 0.3333333333333333 \cdot {x}^{3}\right) - 0.5 \cdot {x}^{2}}\]
    3. Simplified0.2

      \[\leadsto \color{blue}{x \cdot \left(1 + x \cdot \left(-0.5 + x \cdot 0.3333333333333333\right)\right)}\]
    4. Using strategy rm
    5. Applied distribute-rgt-in_binary64_6870.2

      \[\leadsto \color{blue}{1 \cdot x + \left(x \cdot \left(-0.5 + x \cdot 0.3333333333333333\right)\right) \cdot x}\]
    6. Simplified0.2

      \[\leadsto \color{blue}{x} + \left(x \cdot \left(-0.5 + x \cdot 0.3333333333333333\right)\right) \cdot x\]
    7. Simplified0.2

      \[\leadsto x + \color{blue}{x \cdot \left(x \cdot \left(x \cdot 0.3333333333333333 + -0.5\right)\right)}\]
    8. Simplified0.2

      \[\leadsto \color{blue}{x + x \cdot \left(x \cdot \left(-0.5 + x \cdot 0.3333333333333333\right)\right)}\]

    if 1.2347626382596744e-4 < x

    1. Initial program 0.1

      \[\log \left(1 + x\right)\]
    2. Simplified0.1

      \[\leadsto \color{blue}{\log \left(x + 1\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.00012347626382596744:\\ \;\;\;\;x + x \cdot \left(x \cdot \left(-0.5 + x \cdot 0.3333333333333333\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + 1\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2021042 
(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)))