Average Error: 38.7 → 0.1
Time: 35.3s
Precision: binary64
Cost: 7041
\[\log \left(1 + x\right)\]
\[\begin{array}{l} \mathbf{if}\;1 + x \leq 1.0000076844218335:\\ \;\;\;\;x + \left(x \cdot x\right) \cdot \left(-0.5 + x \cdot \left(0.3333333333333333 + x \cdot -0.25\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.0000076844218335:\\
\;\;\;\;x + \left(x \cdot x\right) \cdot \left(-0.5 + x \cdot \left(0.3333333333333333 + x \cdot -0.25\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.0000076844218335)
   (+ x (* (* x x) (+ -0.5 (* x (+ 0.3333333333333333 (* x -0.25))))))
   (log (+ 1.0 x))))
double code(double x) {
	return log(1.0 + x);
}
double code(double x) {
	double tmp;
	if ((1.0 + x) <= 1.0000076844218335) {
		tmp = x + ((x * x) * (-0.5 + (x * (0.3333333333333333 + (x * -0.25)))));
	} 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

Original38.7
Target0.2
Herbie0.1
\[\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
Error0.6
Cost6785
\[\begin{array}{l} \mathbf{if}\;x \leq 1.4052688006051197:\\ \;\;\;\;x + \left(x \cdot x\right) \cdot \left(-0.5 + x \cdot \left(0.3333333333333333 + x \cdot -0.25\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log x\\ \end{array}\]
Alternative 2
Error18.8
Cost1281
\[\begin{array}{l} \mathbf{if}\;x \leq 1.1785122468865616:\\ \;\;\;\;x + \left(x \cdot x\right) \cdot \left(-0.5 + x \cdot \left(0.3333333333333333 + x \cdot -0.25\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
Alternative 3
Error18.9
Cost1025
\[\begin{array}{l} \mathbf{if}\;x \leq 1.1785122468865616:\\ \;\;\;\;x + \left(x \cdot x\right) \cdot \left(-0.5 + x \cdot 0.3333333333333333\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
Alternative 4
Error18.9
Cost1025
\[\begin{array}{l} \mathbf{if}\;x \leq 1.1785122468865616:\\ \;\;\;\;x \cdot \left(1 + x \cdot \left(-0.5 + x \cdot 0.3333333333333333\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
Alternative 5
Error19.0
Cost769
\[\begin{array}{l} \mathbf{if}\;x \leq 1.1218231084569221:\\ \;\;\;\;x + x \cdot \left(x \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
Alternative 6
Error19.5
Cost385
\[\begin{array}{l} \mathbf{if}\;x \leq 1.0084448315976433:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
Alternative 7
Error21.3
Cost64
\[x\]

Error

Time

Derivation

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

    1. Initial program 59.1

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

      \[\leadsto \log \color{blue}{\left({\left(1 + x\right)}^{1}\right)}\]
    4. Applied log-pow_binary64_119059.1

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

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

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

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

    if 1.0000076844218335 < (+.f64 1 x)

    1. Initial program 0.1

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

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

      \[\leadsto \color{blue}{\log \left(1 \cdot 1 - x \cdot x\right) - \log \left(1 - x\right)}\]
    5. Simplified62.9

      \[\leadsto \color{blue}{\log \left(1 - x \cdot x\right)} - \log \left(1 - x\right)\]
    6. Using strategy rm
    7. Applied add-sqr-sqrt_binary64_112362.9

      \[\leadsto \log \left(\color{blue}{\sqrt{1} \cdot \sqrt{1}} - x \cdot x\right) - \log \left(1 - x\right)\]
    8. Applied difference-of-squares_binary64_107063.0

      \[\leadsto \log \color{blue}{\left(\left(\sqrt{1} + x\right) \cdot \left(\sqrt{1} - x\right)\right)} - \log \left(1 - x\right)\]
    9. Applied log-prod_binary64_118763.0

      \[\leadsto \color{blue}{\left(\log \left(\sqrt{1} + x\right) + \log \left(\sqrt{1} - x\right)\right)} - \log \left(1 - x\right)\]
    10. Applied associate--l+_binary64_103863.0

      \[\leadsto \color{blue}{\log \left(\sqrt{1} + x\right) + \left(\log \left(\sqrt{1} - x\right) - \log \left(1 - x\right)\right)}\]
    11. Simplified0.1

      \[\leadsto \log \left(\sqrt{1} + x\right) + \color{blue}{0}\]
    12. Simplified0.1

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

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

Reproduce

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