Average Error: 38.9 → 0.1
Time: 17.4s
Precision: 64
\[\log \left(1 + x\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le 0.00011249430677399227:\\ \;\;\;\;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 r2924953 = 1.0;
        double r2924954 = x;
        double r2924955 = r2924953 + r2924954;
        double r2924956 = log(r2924955);
        return r2924956;
}

double f(double x) {
        double r2924957 = x;
        double r2924958 = 0.00011249430677399227;
        bool r2924959 = r2924957 <= r2924958;
        double r2924960 = -0.5;
        double r2924961 = 0.3333333333333333;
        double r2924962 = r2924961 * r2924957;
        double r2924963 = r2924960 + r2924962;
        double r2924964 = r2924957 * r2924963;
        double r2924965 = r2924964 * r2924957;
        double r2924966 = r2924957 + r2924965;
        double r2924967 = 1.0;
        double r2924968 = r2924957 + r2924967;
        double r2924969 = log(r2924968);
        double r2924970 = r2924959 ? r2924966 : r2924969;
        return r2924970;
}

\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;x \le 0.00011249430677399227:\\
\;\;\;\;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

Original38.9
Target0.2
Herbie0.1
\[\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.00011249430677399227

    1. Initial program 58.9

      \[\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.00011249430677399227 < x

    1. Initial program 0.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le 0.00011249430677399227:\\ \;\;\;\;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 2019101 
(FPCore (x)
  :name "ln(1 + x)"

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

  (log (+ 1 x)))