\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.00000002381666264:\\
\;\;\;\;\left(1 \cdot x + \log 1\right) - \frac{1}{2} \cdot \frac{{x}^{2}}{{1}^{2}}\\
\mathbf{else}:\\
\;\;\;\;\log \left(\sqrt{1 + x}\right) + \log \left(\sqrt{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.0000000238166626)) {
VAR = ((double) (((double) (((double) (1.0 * x)) + ((double) log(1.0)))) - ((double) (0.5 * ((double) (((double) pow(x, 2.0)) / ((double) pow(1.0, 2.0))))))));
} else {
VAR = ((double) (((double) log(((double) sqrt(((double) (1.0 + x)))))) + ((double) log(((double) sqrt(((double) (1.0 + x))))))));
}
return VAR;
}




Bits error versus x
Results
| Original | 39.0 |
|---|---|
| Target | 0.4 |
| Herbie | 0.3 |
if (+ 1.0 x) < 1.00000002381666264Initial program 59.2
Taylor expanded around 0 0.3
if 1.00000002381666264 < (+ 1.0 x) Initial program 0.3
rmApplied add-sqr-sqrt0.3
Applied log-prod0.3
Final simplification0.3
herbie shell --seed 2020147
(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)))