Average Error: 39.2 → 0.3
Time: 3.2s
Precision: binary64
\[\log \left(1 + x\right)\]
\[\begin{array}{l} \mathbf{if}\;1 + x \le 1.00000000056375149:\\ \;\;\;\;\log 1 + \left(1 \cdot x + x \cdot \left(\frac{x}{1} \cdot \frac{\frac{-1}{2}}{1}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\sqrt{1 + x}\right) + \frac{1}{2} \cdot \log \left(1 + x\right)\\ \end{array}\]
\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.00000000056375149:\\
\;\;\;\;\log 1 + \left(1 \cdot x + x \cdot \left(\frac{x}{1} \cdot \frac{\frac{-1}{2}}{1}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\log \left(\sqrt{1 + x}\right) + \frac{1}{2} \cdot \log \left(1 + x\right)\\

\end{array}
double code(double x) {
	return ((double) log(((double) (1.0 + x))));
}
double code(double x) {
	double VAR;
	if ((((double) (1.0 + x)) <= 1.0000000005637515)) {
		VAR = ((double) (((double) log(1.0)) + ((double) (((double) (1.0 * x)) + ((double) (x * ((double) (((double) (x / 1.0)) * ((double) (-0.5 / 1.0))))))))));
	} else {
		VAR = ((double) (((double) log(((double) sqrt(((double) (1.0 + x)))))) + ((double) (0.5 * ((double) log(((double) (1.0 + x))))))));
	}
	return VAR;
}

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.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 (+ 1.0 x) < 1.00000000056375149

    1. Initial program 59.4

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

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

      \[\leadsto \color{blue}{\log 1 + x \cdot \left(1 - \frac{x \cdot \frac{1}{2}}{1 \cdot 1}\right)}\]
    4. Using strategy rm
    5. Applied sub-neg0.3

      \[\leadsto \log 1 + x \cdot \color{blue}{\left(1 + \left(-\frac{x \cdot \frac{1}{2}}{1 \cdot 1}\right)\right)}\]
    6. Applied distribute-lft-in0.3

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

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

    if 1.00000000056375149 < (+ 1.0 x)

    1. Initial program 0.4

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

      \[\leadsto \log \color{blue}{\left(\sqrt{1 + x} \cdot \sqrt{1 + x}\right)}\]
    4. Applied log-prod0.4

      \[\leadsto \color{blue}{\log \left(\sqrt{1 + x}\right) + \log \left(\sqrt{1 + x}\right)}\]
    5. Using strategy rm
    6. Applied pow1/20.4

      \[\leadsto \log \left(\sqrt{1 + x}\right) + \log \color{blue}{\left({\left(1 + x\right)}^{\frac{1}{2}}\right)}\]
    7. Applied log-pow0.4

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

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

Reproduce

herbie shell --seed 2020184 
(FPCore (x)
  :name "ln(1 + x)"
  :precision binary64

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

  (log (+ 1.0 x)))