Average Error: 39.1 → 0.2
Time: 17.0s
Precision: 64
\[\log \left(1 + x\right)\]
\[\begin{array}{l} \mathbf{if}\;x + 1 \le 1.000000095691003:\\ \;\;\;\;\frac{-1}{2} \cdot \left(x \cdot x\right) + \left(x + \left(\frac{1}{3} \cdot x\right) \cdot \left(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.000000095691003:\\
\;\;\;\;\frac{-1}{2} \cdot \left(x \cdot x\right) + \left(x + \left(\frac{1}{3} \cdot x\right) \cdot \left(x \cdot x\right)\right)\\

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

\end{array}
double f(double x) {
        double r2277781 = 1.0;
        double r2277782 = x;
        double r2277783 = r2277781 + r2277782;
        double r2277784 = log(r2277783);
        return r2277784;
}

double f(double x) {
        double r2277785 = x;
        double r2277786 = 1.0;
        double r2277787 = r2277785 + r2277786;
        double r2277788 = 1.000000095691003;
        bool r2277789 = r2277787 <= r2277788;
        double r2277790 = -0.5;
        double r2277791 = r2277785 * r2277785;
        double r2277792 = r2277790 * r2277791;
        double r2277793 = 0.3333333333333333;
        double r2277794 = r2277793 * r2277785;
        double r2277795 = r2277794 * r2277791;
        double r2277796 = r2277785 + r2277795;
        double r2277797 = r2277792 + r2277796;
        double r2277798 = log(r2277787);
        double r2277799 = r2277789 ? r2277797 : r2277798;
        return r2277799;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original39.1
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 x) < 1.000000095691003

    1. Initial program 59.2

      \[\log \left(1 + x\right)\]
    2. Taylor expanded around 0 0.2

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

      \[\leadsto \color{blue}{x + \left(x \cdot x\right) \cdot \left(\frac{1}{3} \cdot x - \frac{1}{2}\right)}\]
    4. Using strategy rm
    5. Applied sub-neg0.2

      \[\leadsto x + \left(x \cdot x\right) \cdot \color{blue}{\left(\frac{1}{3} \cdot x + \left(-\frac{1}{2}\right)\right)}\]
    6. Applied distribute-lft-in0.2

      \[\leadsto x + \color{blue}{\left(\left(x \cdot x\right) \cdot \left(\frac{1}{3} \cdot x\right) + \left(x \cdot x\right) \cdot \left(-\frac{1}{2}\right)\right)}\]
    7. Applied associate-+r+0.2

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

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

Reproduce

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

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

  (log (+ 1 x)))