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

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

\end{array}
double f(double x) {
        double r54885 = 1.0;
        double r54886 = x;
        double r54887 = r54885 + r54886;
        double r54888 = log(r54887);
        return r54888;
}

double f(double x) {
        double r54889 = x;
        double r54890 = 4.228318145661536e-06;
        bool r54891 = r54889 <= r54890;
        double r54892 = -0.5;
        double r54893 = 1.0;
        double r54894 = r54892 / r54893;
        double r54895 = r54889 * r54889;
        double r54896 = r54895 / r54893;
        double r54897 = r54894 * r54896;
        double r54898 = r54893 * r54889;
        double r54899 = log(r54893);
        double r54900 = r54898 + r54899;
        double r54901 = r54897 + r54900;
        double r54902 = r54889 + r54893;
        double r54903 = log(r54902);
        double r54904 = r54891 ? r54901 : r54903;
        return r54904;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original39.2
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 x < 4.228318145661536e-06

    1. Initial program 59.2

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

      \[\leadsto \color{blue}{\log \left(x + 1\right)}\]
    3. Taylor expanded around 0 0.3

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

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

    if 4.228318145661536e-06 < 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.3

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

Reproduce

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