Average Error: 39.2 → 0.4
Time: 3.1s
Precision: 64
\[\log \left(1 + x\right)\]
\[\begin{array}{l} \mathbf{if}\;1 + x \le 1.00000022789517229:\\ \;\;\;\;\left(1 \cdot x + \log 1\right) - \frac{1}{2} \cdot \frac{{x}^{2}}{{1}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\log \left(1 + x\right)\\ \end{array}\]
\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.00000022789517229:\\
\;\;\;\;\left(1 \cdot x + \log 1\right) - \frac{1}{2} \cdot \frac{{x}^{2}}{{1}^{2}}\\

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

\end{array}
double f(double x) {
        double r66666 = 1.0;
        double r66667 = x;
        double r66668 = r66666 + r66667;
        double r66669 = log(r66668);
        return r66669;
}

double f(double x) {
        double r66670 = 1.0;
        double r66671 = x;
        double r66672 = r66670 + r66671;
        double r66673 = 1.0000002278951723;
        bool r66674 = r66672 <= r66673;
        double r66675 = r66670 * r66671;
        double r66676 = log(r66670);
        double r66677 = r66675 + r66676;
        double r66678 = 0.5;
        double r66679 = 2.0;
        double r66680 = pow(r66671, r66679);
        double r66681 = pow(r66670, r66679);
        double r66682 = r66680 / r66681;
        double r66683 = r66678 * r66682;
        double r66684 = r66677 - r66683;
        double r66685 = log(r66672);
        double r66686 = r66674 ? r66684 : r66685;
        return r66686;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original39.2
Target0.3
Herbie0.4
\[\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.0000002278951723

    1. Initial program 59.0

      \[\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}}}\]

    if 1.0000002278951723 < (+ 1.0 x)

    1. Initial program 0.2

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

      \[\leadsto \color{blue}{e^{\log \left(\log \left(1 + x\right)\right)}}\]
    4. Using strategy rm
    5. Applied rem-exp-log0.2

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

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

Reproduce

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