Average Error: 39.6 → 0.3
Time: 24.1s
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 r47680 = 1.0;
        double r47681 = x;
        double r47682 = r47680 + r47681;
        double r47683 = log(r47682);
        return r47683;
}

double f(double x) {
        double r47684 = 1.0;
        double r47685 = x;
        double r47686 = r47684 + r47685;
        double r47687 = 1.0000001524436755;
        bool r47688 = r47686 <= r47687;
        double r47689 = r47685 * r47684;
        double r47690 = -0.5;
        double r47691 = r47684 * r47684;
        double r47692 = r47691 / r47685;
        double r47693 = r47690 / r47692;
        double r47694 = r47685 * r47693;
        double r47695 = r47689 + r47694;
        double r47696 = log(r47684);
        double r47697 = r47695 + r47696;
        double r47698 = sqrt(r47686);
        double r47699 = log(r47698);
        double r47700 = r47699 + r47699;
        double r47701 = r47688 ? r47697 : r47700;
        return r47701;
}

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)))