Average Error: 39.1 → 0.3
Time: 5.2s
Precision: 64
\[\log \left(1 + x\right)\]
\[\begin{array}{l} \mathbf{if}\;1 + x \le 1.0000001235874896:\\ \;\;\;\;\left(0.333333333333333315 \cdot \frac{{x}^{3}}{{1}^{3}} + \left(1 \cdot {x}^{3} + 0.5 \cdot \frac{{x}^{2}}{{1}^{2}}\right)\right) + 1 \cdot \left(x - \left({x}^{2} + \frac{{x}^{3}}{{1}^{2}}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(1 + x\right)\\ \end{array}\]
\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.0000001235874896:\\
\;\;\;\;\left(0.333333333333333315 \cdot \frac{{x}^{3}}{{1}^{3}} + \left(1 \cdot {x}^{3} + 0.5 \cdot \frac{{x}^{2}}{{1}^{2}}\right)\right) + 1 \cdot \left(x - \left({x}^{2} + \frac{{x}^{3}}{{1}^{2}}\right)\right)\\

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

\end{array}
double f(double x) {
        double r79860 = 1.0;
        double r79861 = x;
        double r79862 = r79860 + r79861;
        double r79863 = log(r79862);
        return r79863;
}

double f(double x) {
        double r79864 = 1.0;
        double r79865 = x;
        double r79866 = r79864 + r79865;
        double r79867 = 1.0000001235874896;
        bool r79868 = r79866 <= r79867;
        double r79869 = 0.3333333333333333;
        double r79870 = 3.0;
        double r79871 = pow(r79865, r79870);
        double r79872 = pow(r79864, r79870);
        double r79873 = r79871 / r79872;
        double r79874 = r79869 * r79873;
        double r79875 = r79864 * r79871;
        double r79876 = 0.5;
        double r79877 = 2.0;
        double r79878 = pow(r79865, r79877);
        double r79879 = pow(r79864, r79877);
        double r79880 = r79878 / r79879;
        double r79881 = r79876 * r79880;
        double r79882 = r79875 + r79881;
        double r79883 = r79874 + r79882;
        double r79884 = r79871 / r79879;
        double r79885 = r79878 + r79884;
        double r79886 = r79865 - r79885;
        double r79887 = r79864 * r79886;
        double r79888 = r79883 + r79887;
        double r79889 = log(r79866);
        double r79890 = r79868 ? r79888 : r79889;
        return r79890;
}

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.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.0000001235874896

    1. Initial program 59.2

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

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

      \[\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. Taylor expanded around 0 0.3

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

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

    if 1.0000001235874896 < (+ 1.0 x)

    1. Initial program 0.2

      \[\log \left(1 + x\right)\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.3

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

Reproduce

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