Average Error: 39.3 → 0.3
Time: 4.2s
Precision: 64
\[\log \left(1 + x\right)\]
\[\begin{array}{l} \mathbf{if}\;1 + x \le 1.0000000000568305:\\ \;\;\;\;\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.0000000000568305:\\
\;\;\;\;\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 r69331 = 1.0;
        double r69332 = x;
        double r69333 = r69331 + r69332;
        double r69334 = log(r69333);
        return r69334;
}

double f(double x) {
        double r69335 = 1.0;
        double r69336 = x;
        double r69337 = r69335 + r69336;
        double r69338 = 1.0000000000568305;
        bool r69339 = r69337 <= r69338;
        double r69340 = 0.3333333333333333;
        double r69341 = 3.0;
        double r69342 = pow(r69336, r69341);
        double r69343 = pow(r69335, r69341);
        double r69344 = r69342 / r69343;
        double r69345 = r69340 * r69344;
        double r69346 = r69335 * r69342;
        double r69347 = 0.5;
        double r69348 = 2.0;
        double r69349 = pow(r69336, r69348);
        double r69350 = pow(r69335, r69348);
        double r69351 = r69349 / r69350;
        double r69352 = r69347 * r69351;
        double r69353 = r69346 + r69352;
        double r69354 = r69345 + r69353;
        double r69355 = r69342 / r69350;
        double r69356 = r69349 + r69355;
        double r69357 = r69336 - r69356;
        double r69358 = r69335 * r69357;
        double r69359 = r69354 + r69358;
        double r69360 = log(r69337);
        double r69361 = r69339 ? r69359 : r69360;
        return r69361;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original39.3
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.0000000000568305

    1. Initial program 59.3

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

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

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

      \[\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.0000000000568305 < (+ 1.0 x)

    1. Initial program 0.5

      \[\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.0000000000568305:\\ \;\;\;\;\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 2020057 
(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)))