Average Error: 39.1 → 0.2
Time: 11.6s
Precision: 64
\[\log \left(1 + x\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le 6.649810324851609489931695412545664680692 \cdot 10^{-6}:\\ \;\;\;\;\frac{\frac{-1}{2}}{1} \cdot \frac{x \cdot x}{1} + \left(1 \cdot x + \log 1\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + 1\right)\\ \end{array}\]
\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;x \le 6.649810324851609489931695412545664680692 \cdot 10^{-6}:\\
\;\;\;\;\frac{\frac{-1}{2}}{1} \cdot \frac{x \cdot x}{1} + \left(1 \cdot x + \log 1\right)\\

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

\end{array}
double f(double x) {
        double r50686 = 1.0;
        double r50687 = x;
        double r50688 = r50686 + r50687;
        double r50689 = log(r50688);
        return r50689;
}

double f(double x) {
        double r50690 = x;
        double r50691 = 6.6498103248516095e-06;
        bool r50692 = r50690 <= r50691;
        double r50693 = -0.5;
        double r50694 = 1.0;
        double r50695 = r50693 / r50694;
        double r50696 = r50690 * r50690;
        double r50697 = r50696 / r50694;
        double r50698 = r50695 * r50697;
        double r50699 = r50694 * r50690;
        double r50700 = log(r50694);
        double r50701 = r50699 + r50700;
        double r50702 = r50698 + r50701;
        double r50703 = r50690 + r50694;
        double r50704 = log(r50703);
        double r50705 = r50692 ? r50702 : r50704;
        return r50705;
}

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 x < 6.6498103248516095e-06

    1. Initial program 59.1

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

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

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

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

    if 6.6498103248516095e-06 < 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 6.649810324851609489931695412545664680692 \cdot 10^{-6}:\\ \;\;\;\;\frac{\frac{-1}{2}}{1} \cdot \frac{x \cdot x}{1} + \left(1 \cdot x + \log 1\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + 1\right)\\ \end{array}\]

Reproduce

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