Average Error: 39.0 → 0.2
Time: 4.2s
Precision: binary64
\[\log \left(1 + x\right)\]
\[\begin{array}{l} \mathbf{if}\;1 + x \le 1.00002052412234321:\\ \;\;\;\;\left(1 \cdot x + 0.333333333333333315 \cdot {x}^{3}\right) - 0.5 \cdot {x}^{2}\\ \mathbf{else}:\\ \;\;\;\;\log \left(1 + x\right)\\ \end{array}\]
\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.00002052412234321:\\
\;\;\;\;\left(1 \cdot x + 0.333333333333333315 \cdot {x}^{3}\right) - 0.5 \cdot {x}^{2}\\

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

\end{array}
double code(double x) {
	return ((double) log(((double) (1.0 + x))));
}
double code(double x) {
	double VAR;
	if ((((double) (1.0 + x)) <= 1.0000205241223432)) {
		VAR = ((double) (((double) (((double) (1.0 * x)) + ((double) (0.3333333333333333 * ((double) pow(x, 3.0)))))) - ((double) (0.5 * ((double) pow(x, 2.0))))));
	} else {
		VAR = ((double) log(((double) (1.0 + x))));
	}
	return VAR;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original39.0
Target0.3
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}\]

Derivation

  1. Split input into 2 regimes
  2. if (+ 1.0 x) < 1.00002052412234321

    1. Initial program 59.1

      \[\log \left(1 + x\right)\]
    2. Using strategy rm
    3. Applied flip-+59.1

      \[\leadsto \log \color{blue}{\left(\frac{1 \cdot 1 - x \cdot x}{1 - x}\right)}\]
    4. Applied log-div59.1

      \[\leadsto \color{blue}{\log \left(1 \cdot 1 - x \cdot x\right) - \log \left(1 - x\right)}\]
    5. Taylor expanded around 0 0.2

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

      \[\leadsto \color{blue}{\left(\frac{1}{3} \cdot \frac{{x}^{3}}{{1}^{3}} + \frac{1}{2} \cdot \frac{{x}^{2}}{{1}^{2}}\right) + x \cdot \left(1 - 1 \cdot x\right)}\]
    7. Taylor expanded around 0 0.2

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

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

    if 1.00002052412234321 < (+ 1.0 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 \le 1.00002052412234321:\\ \;\;\;\;\left(1 \cdot x + 0.333333333333333315 \cdot {x}^{3}\right) - 0.5 \cdot {x}^{2}\\ \mathbf{else}:\\ \;\;\;\;\log \left(1 + x\right)\\ \end{array}\]

Reproduce

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