Average Error: 38.9 → 0.2
Time: 5.0s
Precision: 64
\[\log \left(1 + x\right)\]
\[\begin{array}{l} \mathbf{if}\;1 + x \le 1.00000000442313008:\\ \;\;\;\;\left(1 \cdot x + 0.33333333333333326 \cdot {x}^{3}\right) - 0.5 \cdot {x}^{2}\\ \mathbf{else}:\\ \;\;\;\;\log \left(1 + x\right)\\ \end{array}\]
\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.00000000442313008:\\
\;\;\;\;\left(1 \cdot x + 0.33333333333333326 \cdot {x}^{3}\right) - 0.5 \cdot {x}^{2}\\

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

\end{array}
double f(double x) {
        double r75580 = 1.0;
        double r75581 = x;
        double r75582 = r75580 + r75581;
        double r75583 = log(r75582);
        return r75583;
}

double f(double x) {
        double r75584 = 1.0;
        double r75585 = x;
        double r75586 = r75584 + r75585;
        double r75587 = 1.00000000442313;
        bool r75588 = r75586 <= r75587;
        double r75589 = r75584 * r75585;
        double r75590 = 0.33333333333333326;
        double r75591 = 3.0;
        double r75592 = pow(r75585, r75591);
        double r75593 = r75590 * r75592;
        double r75594 = r75589 + r75593;
        double r75595 = 0.5;
        double r75596 = 2.0;
        double r75597 = pow(r75585, r75596);
        double r75598 = r75595 * r75597;
        double r75599 = r75594 - r75598;
        double r75600 = log(r75586);
        double r75601 = r75588 ? r75599 : r75600;
        return r75601;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original38.9
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.00000000442313

    1. Initial program 59.3

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

      \[\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-div59.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. Taylor expanded around 0 0.2

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

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

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

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

    if 1.00000000442313 < (+ 1.0 x)

    1. Initial program 0.3

      \[\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.00000000442313008:\\ \;\;\;\;\left(1 \cdot x + 0.33333333333333326 \cdot {x}^{3}\right) - 0.5 \cdot {x}^{2}\\ \mathbf{else}:\\ \;\;\;\;\log \left(1 + x\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020083 
(FPCore (x)
  :name "ln(1 + x)"
  :precision binary64

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

  (log (+ 1 x)))