Average Error: 39.5 → 0.2
Time: 29.8s
Precision: binary64
Cost: 1153
\[\log \left(1 + x\right)\]
\[\begin{array}{l} \mathbf{if}\;1 + x \leq 1.0001177917014636:\\ \;\;\;\;x \cdot \left(1 + \log \left(e^{x \cdot \left(x \cdot 0.3333333333333333 + -0.5\right)}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(1 + x\right)\\ \end{array}\]
\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \leq 1.0001177917014636:\\
\;\;\;\;x \cdot \left(1 + \log \left(e^{x \cdot \left(x \cdot 0.3333333333333333 + -0.5\right)}\right)\right)\\

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

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

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original39.5
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}\]
Alternative 1
Accuracy20.8
Cost704
\[x + x \cdot \left(x \cdot \left(x \cdot 0.3333333333333333 + -0.5\right)\right)\]
Alternative 2
Accuracy20.8
Cost1216
\[x \cdot \left(1 + \frac{x \cdot \left(0.25 - \left(x \cdot x\right) \cdot 0.1111111111111111\right)}{-0.5 - x \cdot 0.3333333333333333}\right)\]

Derivation

  1. Split input into 2 regimes
  2. if (+.f64 1 x) < 1.00011779170146364

    1. Initial program 58.9

      \[\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 add-log-exp_binary64_21630.2

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

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

    if 1.00011779170146364 < (+.f64 1 x)

    1. Initial program 0.1

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

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

Reproduce

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