Average Error: 39.0 → 0.2
Time: 14.2s
Precision: 64
\[\log \left(1 + x\right)\]
\[\begin{array}{l} \mathbf{if}\;x + 1 \le 1.000051798647896950100744106748607009649:\\ \;\;\;\;\left(\left(\left(\frac{x}{1} \cdot \frac{x}{1}\right) \cdot \frac{x}{1}\right) \cdot 0.3333333333333333148296162562473909929395 + \left(\left(\frac{x}{1} \cdot \frac{x}{1}\right) \cdot 0.5 + 1 \cdot x\right)\right) + \left(1 \cdot \left(\left(x \cdot x\right) \cdot x\right) - 1 \cdot \left(\frac{\frac{\left(x \cdot x\right) \cdot x}{1}}{1} + x \cdot x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + 1\right)\\ \end{array}\]
\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;x + 1 \le 1.000051798647896950100744106748607009649:\\
\;\;\;\;\left(\left(\left(\frac{x}{1} \cdot \frac{x}{1}\right) \cdot \frac{x}{1}\right) \cdot 0.3333333333333333148296162562473909929395 + \left(\left(\frac{x}{1} \cdot \frac{x}{1}\right) \cdot 0.5 + 1 \cdot x\right)\right) + \left(1 \cdot \left(\left(x \cdot x\right) \cdot x\right) - 1 \cdot \left(\frac{\frac{\left(x \cdot x\right) \cdot x}{1}}{1} + x \cdot x\right)\right)\\

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

\end{array}
double f(double x) {
        double r3070363 = 1.0;
        double r3070364 = x;
        double r3070365 = r3070363 + r3070364;
        double r3070366 = log(r3070365);
        return r3070366;
}

double f(double x) {
        double r3070367 = x;
        double r3070368 = 1.0;
        double r3070369 = r3070367 + r3070368;
        double r3070370 = 1.000051798647897;
        bool r3070371 = r3070369 <= r3070370;
        double r3070372 = r3070367 / r3070368;
        double r3070373 = r3070372 * r3070372;
        double r3070374 = r3070373 * r3070372;
        double r3070375 = 0.3333333333333333;
        double r3070376 = r3070374 * r3070375;
        double r3070377 = 0.5;
        double r3070378 = r3070373 * r3070377;
        double r3070379 = r3070368 * r3070367;
        double r3070380 = r3070378 + r3070379;
        double r3070381 = r3070376 + r3070380;
        double r3070382 = r3070367 * r3070367;
        double r3070383 = r3070382 * r3070367;
        double r3070384 = r3070368 * r3070383;
        double r3070385 = r3070383 / r3070368;
        double r3070386 = r3070385 / r3070368;
        double r3070387 = r3070386 + r3070382;
        double r3070388 = r3070368 * r3070387;
        double r3070389 = r3070384 - r3070388;
        double r3070390 = r3070381 + r3070389;
        double r3070391 = log(r3070369);
        double r3070392 = r3070371 ? r3070390 : r3070391;
        return r3070392;
}

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.000051798647897

    1. Initial program 58.9

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

      \[\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-div58.9

      \[\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. Simplified58.9

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

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

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

    if 1.000051798647897 < (+ 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}\;x + 1 \le 1.000051798647896950100744106748607009649:\\ \;\;\;\;\left(\left(\left(\frac{x}{1} \cdot \frac{x}{1}\right) \cdot \frac{x}{1}\right) \cdot 0.3333333333333333148296162562473909929395 + \left(\left(\frac{x}{1} \cdot \frac{x}{1}\right) \cdot 0.5 + 1 \cdot x\right)\right) + \left(1 \cdot \left(\left(x \cdot x\right) \cdot x\right) - 1 \cdot \left(\frac{\frac{\left(x \cdot x\right) \cdot x}{1}}{1} + x \cdot x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + 1\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019174 
(FPCore (x)
  :name "ln(1 + x)"

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

  (log (+ 1.0 x)))