Average Error: 39.0 → 0.2
Time: 13.3s
Precision: 64
\[\log \left(1 + x\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le 1.183736951548186231136100543537281737372 \cdot 10^{-4}:\\ \;\;\;\;\left(\left(1 \cdot x + \frac{0.5}{1} \cdot \frac{x \cdot x}{1}\right) + \left(\frac{0.3333333333333333148296162562473909929395 \cdot {x}^{3}}{{1}^{3}} - 1 \cdot \left(\frac{\frac{{x}^{3}}{1}}{1} + x \cdot x\right)\right)\right) + {x}^{3} \cdot 1\\ \mathbf{else}:\\ \;\;\;\;\log \left(1 + x\right)\\ \end{array}\]
\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;x \le 1.183736951548186231136100543537281737372 \cdot 10^{-4}:\\
\;\;\;\;\left(\left(1 \cdot x + \frac{0.5}{1} \cdot \frac{x \cdot x}{1}\right) + \left(\frac{0.3333333333333333148296162562473909929395 \cdot {x}^{3}}{{1}^{3}} - 1 \cdot \left(\frac{\frac{{x}^{3}}{1}}{1} + x \cdot x\right)\right)\right) + {x}^{3} \cdot 1\\

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

\end{array}
double f(double x) {
        double r79764 = 1.0;
        double r79765 = x;
        double r79766 = r79764 + r79765;
        double r79767 = log(r79766);
        return r79767;
}

double f(double x) {
        double r79768 = x;
        double r79769 = 0.00011837369515481862;
        bool r79770 = r79768 <= r79769;
        double r79771 = 1.0;
        double r79772 = r79771 * r79768;
        double r79773 = 0.5;
        double r79774 = r79773 / r79771;
        double r79775 = r79768 * r79768;
        double r79776 = r79775 / r79771;
        double r79777 = r79774 * r79776;
        double r79778 = r79772 + r79777;
        double r79779 = 0.3333333333333333;
        double r79780 = 3.0;
        double r79781 = pow(r79768, r79780);
        double r79782 = r79779 * r79781;
        double r79783 = pow(r79771, r79780);
        double r79784 = r79782 / r79783;
        double r79785 = r79781 / r79771;
        double r79786 = r79785 / r79771;
        double r79787 = r79786 + r79775;
        double r79788 = r79771 * r79787;
        double r79789 = r79784 - r79788;
        double r79790 = r79778 + r79789;
        double r79791 = r79781 * r79771;
        double r79792 = r79790 + r79791;
        double r79793 = r79771 + r79768;
        double r79794 = log(r79793);
        double r79795 = r79770 ? r79792 : r79794;
        return r79795;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original39.0
Target0.3
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 x < 0.00011837369515481862

    1. Initial program 58.9

      \[\log \left(1 + x\right)\]
    2. Simplified58.9

      \[\leadsto \color{blue}{\log \left(x + 1\right)}\]
    3. Using strategy rm
    4. Applied flip3-+58.9

      \[\leadsto \log \color{blue}{\left(\frac{{x}^{3} + {1}^{3}}{x \cdot x + \left(1 \cdot 1 - x \cdot 1\right)}\right)}\]
    5. Applied log-div58.9

      \[\leadsto \color{blue}{\log \left({x}^{3} + {1}^{3}\right) - \log \left(x \cdot x + \left(1 \cdot 1 - x \cdot 1\right)\right)}\]
    6. Simplified58.9

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

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

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

    if 0.00011837369515481862 < x

    1. Initial program 0.1

      \[\log \left(1 + x\right)\]
    2. Simplified0.1

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

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

Reproduce

herbie shell --seed 2019174 
(FPCore (x)
  :name "ln(1 + x)"

  :herbie-target
  (if (== (+ 1.0 x) 1.0) x (/ (* x (log (+ 1.0 x))) (- (+ 1.0 x) 1.0)))

  (log (+ 1.0 x)))