Average Error: 38.9 → 0.3
Time: 57.7s
Precision: binary64
Cost: 27905
\[\log \left(1 + x\right)\]
\[\begin{array}{l} \mathbf{if}\;1 + x \leq 1.0000000008461332:\\ \;\;\;\;\left(\left({x}^{3} - 0.5 \cdot {x}^{6}\right) + {x}^{9} \cdot 0.3333333333333333\right) - \left(\left(x \cdot x\right) \cdot \left(0.5 + x \cdot 0.6666666666666666\right) + \left({x}^{4} \cdot 0.25 - x\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.0000000008461332:\\
\;\;\;\;\left(\left({x}^{3} - 0.5 \cdot {x}^{6}\right) + {x}^{9} \cdot 0.3333333333333333\right) - \left(\left(x \cdot x\right) \cdot \left(0.5 + x \cdot 0.6666666666666666\right) + \left({x}^{4} \cdot 0.25 - x\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.0000000008461332)
   (-
    (+ (- (pow x 3.0) (* 0.5 (pow x 6.0))) (* (pow x 9.0) 0.3333333333333333))
    (+
     (* (* x x) (+ 0.5 (* x 0.6666666666666666)))
     (- (* (pow x 4.0) 0.25) x)))
   (log (+ 1.0 x))))
double code(double x) {
	return log(1.0 + x);
}
double code(double x) {
	double tmp;
	if ((1.0 + x) <= 1.0000000008461332) {
		tmp = ((pow(x, 3.0) - (0.5 * pow(x, 6.0))) + (pow(x, 9.0) * 0.3333333333333333)) - (((x * x) * (0.5 + (x * 0.6666666666666666))) + ((pow(x, 4.0) * 0.25) - x));
	} 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.9
Target0.2
Herbie0.3
\[\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.3
Cost21185
\[\begin{array}{l} \mathbf{if}\;1 + x \leq 1.0000000008461332:\\ \;\;\;\;\left({x}^{3} - 0.5 \cdot {x}^{6}\right) - \left(\left(x \cdot x\right) \cdot \left(0.5 + x \cdot 0.6666666666666666\right) + \left({x}^{4} \cdot 0.25 - x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(1 + x\right)\\ \end{array}\]
Alternative 2
Error0.3
Cost7873
\[\begin{array}{l} \mathbf{if}\;1 + x \leq 1.0000000008461332:\\ \;\;\;\;x + \left(\left(x \cdot x\right) \cdot \left(x \cdot 0.3333333333333333 + -0.5\right) - {x}^{4} \cdot 0.25\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(1 + x\right)\\ \end{array}\]
Alternative 3
Error0.3
Cost7041
\[\begin{array}{l} \mathbf{if}\;1 + x \leq 1.0000000008461332:\\ \;\;\;\;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}\]
Alternative 4
Error0.5
Cost6785
\[\begin{array}{l} \mathbf{if}\;x \leq 1.422625085086669:\\ \;\;\;\;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 5
Error18.7
Cost1281
\[\begin{array}{l} \mathbf{if}\;x \leq 1.1716128099872232:\\ \;\;\;\;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 6
Error18.7
Cost1025
\[\begin{array}{l} \mathbf{if}\;x \leq 1.1357539135444452:\\ \;\;\;\;x + \left(x \cdot x\right) \cdot \left(x \cdot 0.3333333333333333 + -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
Alternative 7
Error18.9
Cost769
\[\begin{array}{l} \mathbf{if}\;x \leq 1.0998950171016673:\\ \;\;\;\;x + x \cdot \left(x \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
Alternative 8
Error18.9
Cost769
\[\begin{array}{l} \mathbf{if}\;x \leq 1.0998950171016673:\\ \;\;\;\;x \cdot \left(1 + x \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
Alternative 9
Error19.4
Cost385
\[\begin{array}{l} \mathbf{if}\;x \leq 0.9961591638866667:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
Alternative 10
Error21.2
Cost64
\[x\]

Error

Time

Derivation

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

    1. Initial program 59.2

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

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

      \[\leadsto \color{blue}{\log \left({1}^{3} + {x}^{3}\right) - \log \left(1 \cdot 1 + \left(x \cdot x - 1 \cdot x\right)\right)}\]
    5. Simplified59.3

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

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

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

      \[\leadsto \log \left(1 + {x}^{3}\right) - \color{blue}{\left(\left(x \cdot x\right) \cdot \left(0.5 + x \cdot 0.6666666666666666\right) + \left(0.25 \cdot {x}^{4} - x\right)\right)}\]
    9. Taylor expanded around 0 0.2

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

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

      \[\leadsto \color{blue}{\left(\left({x}^{3} - 0.5 \cdot {x}^{6}\right) + {x}^{9} \cdot 0.3333333333333333\right) - \left(\left(x \cdot x\right) \cdot \left(x \cdot 0.6666666666666666 + 0.5\right) + \left({x}^{4} \cdot 0.25 - x\right)\right)}\]

    if 1.00000000084613316 < (+.f64 1 x)

    1. Initial program 0.4

      \[\log \left(1 + x\right)\]
    2. Simplified0.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;1 + x \leq 1.0000000008461332:\\ \;\;\;\;\left(\left({x}^{3} - 0.5 \cdot {x}^{6}\right) + {x}^{9} \cdot 0.3333333333333333\right) - \left(\left(x \cdot x\right) \cdot \left(0.5 + x \cdot 0.6666666666666666\right) + \left({x}^{4} \cdot 0.25 - x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(1 + x\right)\\ \end{array}\]

Reproduce

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