Average Error: 39.1 → 0.2
Time: 23.1s
Precision: 64
\[\log \left(1 + x\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le 0.00013052268004736076:\\ \;\;\;\;x + \left(x \cdot \left(\frac{-1}{2} + \frac{1}{3} \cdot x\right)\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + 1\right)\\ \end{array}\]
double f(double x) {
        double r9890947 = 1.0;
        double r9890948 = x;
        double r9890949 = r9890947 + r9890948;
        double r9890950 = log(r9890949);
        return r9890950;
}

double f(double x) {
        double r9890951 = x;
        double r9890952 = 0.00013052268004736076;
        bool r9890953 = r9890951 <= r9890952;
        double r9890954 = -0.5;
        double r9890955 = 0.3333333333333333;
        double r9890956 = r9890955 * r9890951;
        double r9890957 = r9890954 + r9890956;
        double r9890958 = r9890951 * r9890957;
        double r9890959 = r9890958 * r9890951;
        double r9890960 = r9890951 + r9890959;
        double r9890961 = 1.0;
        double r9890962 = r9890951 + r9890961;
        double r9890963 = log(r9890962);
        double r9890964 = r9890953 ? r9890960 : r9890963;
        return r9890964;
}

\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;x \le 0.00013052268004736076:\\
\;\;\;\;x + \left(x \cdot \left(\frac{-1}{2} + \frac{1}{3} \cdot x\right)\right) \cdot x\\

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

\end{array}

Error

Bits error versus x

Target

Original39.1
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 x < 0.00013052268004736076

    1. Initial program 59.0

      \[\log \left(1 + x\right)\]
    2. Taylor expanded around 0 0.2

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

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

    if 0.00013052268004736076 < 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}\;x \le 0.00013052268004736076:\\ \;\;\;\;x + \left(x \cdot \left(\frac{-1}{2} + \frac{1}{3} \cdot x\right)\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + 1\right)\\ \end{array}\]

Reproduce

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

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

  (log (+ 1 x)))