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

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

\end{array}
double f(double x) {
        double r57719 = 1.0;
        double r57720 = x;
        double r57721 = r57719 + r57720;
        double r57722 = log(r57721);
        return r57722;
}

double f(double x) {
        double r57723 = 1.0;
        double r57724 = x;
        double r57725 = r57723 + r57724;
        double r57726 = 1.0001054307090327;
        bool r57727 = r57725 <= r57726;
        double r57728 = 0.3333333333333333;
        double r57729 = 3.0;
        double r57730 = pow(r57724, r57729);
        double r57731 = pow(r57723, r57729);
        double r57732 = r57730 / r57731;
        double r57733 = r57728 * r57732;
        double r57734 = r57723 * r57730;
        double r57735 = 0.5;
        double r57736 = 2.0;
        double r57737 = pow(r57724, r57736);
        double r57738 = pow(r57723, r57736);
        double r57739 = r57737 / r57738;
        double r57740 = r57735 * r57739;
        double r57741 = r57723 * r57724;
        double r57742 = r57740 + r57741;
        double r57743 = r57734 + r57742;
        double r57744 = r57733 + r57743;
        double r57745 = r57724 * r57724;
        double r57746 = r57730 / r57738;
        double r57747 = r57745 + r57746;
        double r57748 = r57723 * r57747;
        double r57749 = r57744 - r57748;
        double r57750 = sqrt(r57725);
        double r57751 = log(r57750);
        double r57752 = r57751 + r57751;
        double r57753 = r57727 ? r57749 : r57752;
        return r57753;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original38.8
Target0.2
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.0001054307090327

    1. Initial program 58.9

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

      \[\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.0

      \[\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. Simplified59.0

      \[\leadsto \log \left({1}^{3} + {x}^{3}\right) - \color{blue}{\log \left(1 \cdot 1 + x \cdot \left(x - 1\right)\right)}\]
    6. Taylor expanded around 0 0.2

      \[\leadsto \color{blue}{\left(0.3333333333333333148296162562473909929395 \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)}\]
    7. Simplified0.2

      \[\leadsto \color{blue}{\left(0.3333333333333333148296162562473909929395 \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) - 1 \cdot \left(x \cdot x + \frac{{x}^{3}}{{1}^{2}}\right)}\]

    if 1.0001054307090327 < (+ 1.0 x)

    1. Initial program 0.1

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

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

      \[\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.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;1 + x \le 1.000105430709032683367354366055224090815:\\ \;\;\;\;\left(0.3333333333333333148296162562473909929395 \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) - 1 \cdot \left(x \cdot x + \frac{{x}^{3}}{{1}^{2}}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\sqrt{1 + x}\right) + \log \left(\sqrt{1 + x}\right)\\ \end{array}\]

Reproduce

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