Average Error: 39.2 → 0.2
Time: 8.8s
Precision: 64
\[\log \left(1 + x\right)\]
\[\begin{array}{l} \mathbf{if}\;1 + x \le \frac{281475889873409}{281474976710656}:\\ \;\;\;\;\left(\frac{6004799503160661}{18014398509481984} \cdot \frac{{x}^{3}}{{1}^{3}} + \left(1 \cdot {x}^{3} + \frac{1}{2} \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 \frac{281475889873409}{281474976710656}:\\
\;\;\;\;\left(\frac{6004799503160661}{18014398509481984} \cdot \frac{{x}^{3}}{{1}^{3}} + \left(1 \cdot {x}^{3} + \frac{1}{2} \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 r64048 = 1.0;
        double r64049 = x;
        double r64050 = r64048 + r64049;
        double r64051 = log(r64050);
        return r64051;
}

double f(double x) {
        double r64052 = 1.0;
        double r64053 = x;
        double r64054 = r64052 + r64053;
        double r64055 = 281475889873409.0;
        double r64056 = 281474976710656.0;
        double r64057 = r64055 / r64056;
        bool r64058 = r64054 <= r64057;
        double r64059 = 6004799503160661.0;
        double r64060 = 18014398509481984.0;
        double r64061 = r64059 / r64060;
        double r64062 = 3.0;
        double r64063 = pow(r64053, r64062);
        double r64064 = pow(r64052, r64062);
        double r64065 = r64063 / r64064;
        double r64066 = r64061 * r64065;
        double r64067 = r64052 * r64063;
        double r64068 = 2.0;
        double r64069 = r64052 / r64068;
        double r64070 = 2.0;
        double r64071 = pow(r64053, r64070);
        double r64072 = pow(r64052, r64070);
        double r64073 = r64071 / r64072;
        double r64074 = r64069 * r64073;
        double r64075 = r64067 + r64074;
        double r64076 = r64066 + r64075;
        double r64077 = r64063 / r64072;
        double r64078 = r64071 + r64077;
        double r64079 = r64053 - r64078;
        double r64080 = r64052 * r64079;
        double r64081 = r64076 + r64080;
        double r64082 = log(r64054);
        double r64083 = r64058 ? r64081 : r64082;
        return r64083;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original39.2
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.0000032442058036

    1. Initial program 59.0

      \[\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. 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)}\]
    6. Simplified0.2

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

    if 1.0000032442058036 < (+ 1.0 x)

    1. Initial program 0.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;1 + x \le \frac{281475889873409}{281474976710656}:\\ \;\;\;\;\left(\frac{6004799503160661}{18014398509481984} \cdot \frac{{x}^{3}}{{1}^{3}} + \left(1 \cdot {x}^{3} + \frac{1}{2} \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 2019304 
(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)))