Average Error: 38.8 → 0.5
Time: 3.6s
Precision: binary64
\[\log \left(1 + x\right)\]
\[\begin{array}{l} \mathbf{if}\;1 + x \leq 1.0000000000027438:\\ \;\;\;\;1 \cdot x + \left(\log 1 + \left(x \cdot x\right) \cdot \frac{-0.5}{1 \cdot 1}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(1 + x\right)\\ \end{array}\]
\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \leq 1.0000000000027438:\\
\;\;\;\;1 \cdot x + \left(\log 1 + \left(x \cdot x\right) \cdot \frac{-0.5}{1 \cdot 1}\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.0000000000027438)
   (+ (* 1.0 x) (+ (log 1.0) (* (* x x) (/ -0.5 (* 1.0 1.0)))))
   (log (+ 1.0 x))))
double code(double x) {
	return ((double) log(((double) (1.0 + x))));
}
double code(double x) {
	double tmp;
	if ((((double) (1.0 + x)) <= 1.0000000000027438)) {
		tmp = ((double) (((double) (1.0 * x)) + ((double) (((double) log(1.0)) + ((double) (((double) (x * x)) * (-0.5 / ((double) (1.0 * 1.0)))))))));
	} else {
		tmp = ((double) log(((double) (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

Original38.8
Target0.3
Herbie0.5
\[\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. Split input into 2 regimes
  2. if (+ 1.0 x) < 1.00000000000274381

    1. Initial program Error: 59.4 bits

      \[\log \left(1 + x\right)\]
    2. Taylor expanded around 0 Error: 0.4 bits

      \[\leadsto \color{blue}{\left(1 \cdot x + \log 1\right) - 0.5 \cdot \frac{{x}^{2}}{{1}^{2}}}\]
    3. SimplifiedError: 0.4 bits

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

    if 1.00000000000274381 < (+ 1.0 x)

    1. Initial program Error: 0.7 bits

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

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

Reproduce

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