\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.0000000000004809:\\
\;\;\;\;\mathsf{fma}\left(-1, \mathsf{fma}\left(x, x, \frac{{x}^{3}}{{1}^{2}}\right), \mathsf{fma}\left(0.333333333333333315, \frac{{x}^{3}}{{1}^{3}}, \mathsf{fma}\left(1, {x}^{3}, \mathsf{fma}\left(0.5, \frac{{x}^{2}}{{1}^{2}}, 1 \cdot x\right)\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(1 + x\right)\\
\end{array}double code(double x) {
return log((1.0 + x));
}
double code(double x) {
double temp;
if (((1.0 + x) <= 1.000000000000481)) {
temp = fma(-1.0, fma(x, x, (pow(x, 3.0) / pow(1.0, 2.0))), fma(0.3333333333333333, (pow(x, 3.0) / pow(1.0, 3.0)), fma(1.0, pow(x, 3.0), fma(0.5, (pow(x, 2.0) / pow(1.0, 2.0)), (1.0 * x)))));
} else {
temp = log((1.0 + x));
}
return temp;
}




Bits error versus x
Results
| Original | 38.9 |
|---|---|
| Target | 0.2 |
| Herbie | 0.4 |
if (+ 1.0 x) < 1.000000000000481Initial program 59.3
rmApplied flip3-+59.4
Applied log-div59.4
Taylor expanded around 0 0.3
Simplified0.3
if 1.000000000000481 < (+ 1.0 x) Initial program 0.8
Final simplification0.4
herbie shell --seed 2020056 +o rules:numerics
(FPCore (x)
:name "ln(1 + x)"
:precision binary64
:herbie-target
(if (== (+ 1 x) 1) x (/ (* x (log (+ 1 x))) (- (+ 1 x) 1)))
(log (+ 1 x)))