Average Error: 39.4 → 0.2
Time: 4.4s
Precision: 64
\[\log \left(1 + x\right)\]
\[\begin{array}{l} \mathbf{if}\;1 + x \le 1.0000020999504917:\\ \;\;\;\;\frac{\left(\left(\frac{1}{3} \cdot {x}^{3}\right) \cdot {1}^{2} + {1}^{3} \cdot \left(\frac{1}{2} \cdot {x}^{2}\right)\right) \cdot \left(1 + 1 \cdot x\right) + \left({1}^{3} \cdot {1}^{2}\right) \cdot \left(x \cdot \left(1 \cdot 1 - \left(1 \cdot x\right) \cdot \left(1 \cdot x\right)\right)\right)}{\left({1}^{3} \cdot {1}^{2}\right) \cdot \left(1 + 1 \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;\log \left(1 + x\right)\\ \end{array}\]
\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.0000020999504917:\\
\;\;\;\;\frac{\left(\left(\frac{1}{3} \cdot {x}^{3}\right) \cdot {1}^{2} + {1}^{3} \cdot \left(\frac{1}{2} \cdot {x}^{2}\right)\right) \cdot \left(1 + 1 \cdot x\right) + \left({1}^{3} \cdot {1}^{2}\right) \cdot \left(x \cdot \left(1 \cdot 1 - \left(1 \cdot x\right) \cdot \left(1 \cdot x\right)\right)\right)}{\left({1}^{3} \cdot {1}^{2}\right) \cdot \left(1 + 1 \cdot x\right)}\\

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

\end{array}
double code(double x) {
	return log((1.0 + x));
}
double code(double x) {
	double VAR;
	if (((1.0 + x) <= 1.0000020999504917)) {
		VAR = ((((((0.3333333333333333 * pow(x, 3.0)) * pow(1.0, 2.0)) + (pow(1.0, 3.0) * (0.5 * pow(x, 2.0)))) * (1.0 + (1.0 * x))) + ((pow(1.0, 3.0) * pow(1.0, 2.0)) * (x * ((1.0 * 1.0) - ((1.0 * x) * (1.0 * x)))))) / ((pow(1.0, 3.0) * pow(1.0, 2.0)) * (1.0 + (1.0 * x))));
	} else {
		VAR = log((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.4
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}\]

Derivation

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

    1. Initial program 59.2

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

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

      \[\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. Using strategy rm
    8. Applied flip--0.2

      \[\leadsto \left(\frac{1}{3} \cdot \frac{{x}^{3}}{{1}^{3}} + \frac{1}{2} \cdot \frac{{x}^{2}}{{1}^{2}}\right) + x \cdot \color{blue}{\frac{1 \cdot 1 - \left(1 \cdot x\right) \cdot \left(1 \cdot x\right)}{1 + 1 \cdot x}}\]
    9. Applied associate-*r/0.2

      \[\leadsto \left(\frac{1}{3} \cdot \frac{{x}^{3}}{{1}^{3}} + \frac{1}{2} \cdot \frac{{x}^{2}}{{1}^{2}}\right) + \color{blue}{\frac{x \cdot \left(1 \cdot 1 - \left(1 \cdot x\right) \cdot \left(1 \cdot x\right)\right)}{1 + 1 \cdot x}}\]
    10. Applied associate-*r/0.2

      \[\leadsto \left(\frac{1}{3} \cdot \frac{{x}^{3}}{{1}^{3}} + \color{blue}{\frac{\frac{1}{2} \cdot {x}^{2}}{{1}^{2}}}\right) + \frac{x \cdot \left(1 \cdot 1 - \left(1 \cdot x\right) \cdot \left(1 \cdot x\right)\right)}{1 + 1 \cdot x}\]
    11. Applied associate-*r/0.2

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

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

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

    if 1.0000020999504917 < (+ 1.0 x)

    1. Initial program 0.2

      \[\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.0000020999504917:\\ \;\;\;\;\frac{\left(\left(\frac{1}{3} \cdot {x}^{3}\right) \cdot {1}^{2} + {1}^{3} \cdot \left(\frac{1}{2} \cdot {x}^{2}\right)\right) \cdot \left(1 + 1 \cdot x\right) + \left({1}^{3} \cdot {1}^{2}\right) \cdot \left(x \cdot \left(1 \cdot 1 - \left(1 \cdot x\right) \cdot \left(1 \cdot x\right)\right)\right)}{\left({1}^{3} \cdot {1}^{2}\right) \cdot \left(1 + 1 \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;\log \left(1 + x\right)\\ \end{array}\]

Reproduce

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

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

  (log (+ 1 x)))