Average Error: 39.6 → 0.3
Time: 23.8s
Precision: 64
\[\log \left(1 + x\right)\]
\[\begin{array}{l} \mathbf{if}\;1 + x \le 1.000000152443675460744998417794704437256:\\ \;\;\;\;\left(x \cdot 1 + x \cdot \frac{\frac{-1}{2}}{\frac{1 \cdot 1}{x}}\right) + \log 1\\ \mathbf{else}:\\ \;\;\;\;\log \left(\sqrt{1 + x}\right) + \log \left(\sqrt{1 + x}\right)\\ \end{array}\]
\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.000000152443675460744998417794704437256:\\
\;\;\;\;\left(x \cdot 1 + x \cdot \frac{\frac{-1}{2}}{\frac{1 \cdot 1}{x}}\right) + \log 1\\

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

\end{array}
double f(double x) {
        double r84429 = 1.0;
        double r84430 = x;
        double r84431 = r84429 + r84430;
        double r84432 = log(r84431);
        return r84432;
}

double f(double x) {
        double r84433 = 1.0;
        double r84434 = x;
        double r84435 = r84433 + r84434;
        double r84436 = 1.0000001524436755;
        bool r84437 = r84435 <= r84436;
        double r84438 = r84434 * r84433;
        double r84439 = -0.5;
        double r84440 = r84433 * r84433;
        double r84441 = r84440 / r84434;
        double r84442 = r84439 / r84441;
        double r84443 = r84434 * r84442;
        double r84444 = r84438 + r84443;
        double r84445 = log(r84433);
        double r84446 = r84444 + r84445;
        double r84447 = sqrt(r84435);
        double r84448 = log(r84447);
        double r84449 = r84448 + r84448;
        double r84450 = r84437 ? r84446 : r84449;
        return r84450;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original39.6
Target0.2
Herbie0.3
\[\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.0000001524436755

    1. Initial program 59.1

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

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

      \[\leadsto \color{blue}{x \cdot \left(1 + \frac{\frac{-1}{2}}{\frac{1 \cdot 1}{x}}\right) + \log 1}\]
    4. Using strategy rm
    5. Applied distribute-lft-in0.4

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

    if 1.0000001524436755 < (+ 1.0 x)

    1. Initial program 0.2

      \[\log \left(1 + x\right)\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt0.2

      \[\leadsto \log \color{blue}{\left(\sqrt{1 + x} \cdot \sqrt{1 + x}\right)}\]
    4. Applied log-prod0.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;1 + x \le 1.000000152443675460744998417794704437256:\\ \;\;\;\;\left(x \cdot 1 + x \cdot \frac{\frac{-1}{2}}{\frac{1 \cdot 1}{x}}\right) + \log 1\\ \mathbf{else}:\\ \;\;\;\;\log \left(\sqrt{1 + x}\right) + \log \left(\sqrt{1 + x}\right)\\ \end{array}\]

Reproduce

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