Average Error: 38.8 → 0.2
Time: 13.1s
Precision: 64
\[\log \left(1 + x\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le 8.734655660045007009254641738849045395909 \cdot 10^{-5}:\\ \;\;\;\;\left(\left({x}^{3} \cdot 1 + \frac{0.3333333333333333148296162562473909929395}{\frac{{1}^{3}}{{x}^{3}}}\right) + \left(1 \cdot x + \frac{\left(0.5 \cdot x\right) \cdot x}{1 \cdot 1}\right)\right) - \left(x \cdot x + \frac{\frac{{x}^{3}}{1}}{1}\right) \cdot 1\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + 1\right)\\ \end{array}\]
\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;x \le 8.734655660045007009254641738849045395909 \cdot 10^{-5}:\\
\;\;\;\;\left(\left({x}^{3} \cdot 1 + \frac{0.3333333333333333148296162562473909929395}{\frac{{1}^{3}}{{x}^{3}}}\right) + \left(1 \cdot x + \frac{\left(0.5 \cdot x\right) \cdot x}{1 \cdot 1}\right)\right) - \left(x \cdot x + \frac{\frac{{x}^{3}}{1}}{1}\right) \cdot 1\\

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

\end{array}
double f(double x) {
        double r46277 = 1.0;
        double r46278 = x;
        double r46279 = r46277 + r46278;
        double r46280 = log(r46279);
        return r46280;
}

double f(double x) {
        double r46281 = x;
        double r46282 = 8.734655660045007e-05;
        bool r46283 = r46281 <= r46282;
        double r46284 = 3.0;
        double r46285 = pow(r46281, r46284);
        double r46286 = 1.0;
        double r46287 = r46285 * r46286;
        double r46288 = 0.3333333333333333;
        double r46289 = pow(r46286, r46284);
        double r46290 = r46289 / r46285;
        double r46291 = r46288 / r46290;
        double r46292 = r46287 + r46291;
        double r46293 = r46286 * r46281;
        double r46294 = 0.5;
        double r46295 = r46294 * r46281;
        double r46296 = r46295 * r46281;
        double r46297 = r46286 * r46286;
        double r46298 = r46296 / r46297;
        double r46299 = r46293 + r46298;
        double r46300 = r46292 + r46299;
        double r46301 = r46281 * r46281;
        double r46302 = r46285 / r46286;
        double r46303 = r46302 / r46286;
        double r46304 = r46301 + r46303;
        double r46305 = r46304 * r46286;
        double r46306 = r46300 - r46305;
        double r46307 = r46281 + r46286;
        double r46308 = log(r46307);
        double r46309 = r46283 ? r46306 : r46308;
        return r46309;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original38.8
Target0.1
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 x < 8.734655660045007e-05

    1. Initial program 59.0

      \[\log \left(1 + x\right)\]
    2. Simplified59.0

      \[\leadsto \color{blue}{\log \left(x + 1\right)}\]
    3. Using strategy rm
    4. Applied flip3-+59.1

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

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

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

      \[\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)}\]
    8. Simplified0.3

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

    if 8.734655660045007e-05 < x

    1. Initial program 0.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le 8.734655660045007009254641738849045395909 \cdot 10^{-5}:\\ \;\;\;\;\left(\left({x}^{3} \cdot 1 + \frac{0.3333333333333333148296162562473909929395}{\frac{{1}^{3}}{{x}^{3}}}\right) + \left(1 \cdot x + \frac{\left(0.5 \cdot x\right) \cdot x}{1 \cdot 1}\right)\right) - \left(x \cdot x + \frac{\frac{{x}^{3}}{1}}{1}\right) \cdot 1\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + 1\right)\\ \end{array}\]

Reproduce

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