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

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

\end{array}
double f(double x) {
        double r4530436 = 1.0;
        double r4530437 = x;
        double r4530438 = r4530436 + r4530437;
        double r4530439 = log(r4530438);
        return r4530439;
}

double f(double x) {
        double r4530440 = 1.0;
        double r4530441 = x;
        double r4530442 = r4530440 + r4530441;
        double r4530443 = 1.000051798647897;
        bool r4530444 = r4530442 <= r4530443;
        double r4530445 = 0.3333333333333333;
        double r4530446 = r4530441 * r4530441;
        double r4530447 = r4530446 * r4530441;
        double r4530448 = r4530445 * r4530447;
        double r4530449 = r4530440 * r4530441;
        double r4530450 = r4530448 + r4530449;
        double r4530451 = 0.5;
        double r4530452 = r4530446 * r4530451;
        double r4530453 = r4530450 - r4530452;
        double r4530454 = log(r4530442);
        double r4530455 = r4530444 ? r4530453 : r4530454;
        return r4530455;
}

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 flip-+59.0

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

      \[\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(1 \cdot x + \left(\frac{1}{3} \cdot \frac{{x}^{3}}{{1}^{3}} + \frac{1}{2} \cdot \frac{{x}^{2}}{{1}^{2}}\right)\right) - 1 \cdot {x}^{2}}\]
    6. Simplified0.2

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

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

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

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