\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.000000000143161:\\
\;\;\;\;\mathsf{fma}\left(x, 1, \log 1 - \frac{1}{2} \cdot \frac{{x}^{2}}{{1}^{2}}\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(1 + x\right)\\
\end{array}double f(double x) {
double r77396 = 1.0;
double r77397 = x;
double r77398 = r77396 + r77397;
double r77399 = log(r77398);
return r77399;
}
double f(double x) {
double r77400 = 1.0;
double r77401 = x;
double r77402 = r77400 + r77401;
double r77403 = 1.000000000143161;
bool r77404 = r77402 <= r77403;
double r77405 = log(r77400);
double r77406 = 0.5;
double r77407 = 2.0;
double r77408 = pow(r77401, r77407);
double r77409 = pow(r77400, r77407);
double r77410 = r77408 / r77409;
double r77411 = r77406 * r77410;
double r77412 = r77405 - r77411;
double r77413 = fma(r77401, r77400, r77412);
double r77414 = log(r77402);
double r77415 = r77404 ? r77413 : r77414;
return r77415;
}




Bits error versus x
| Original | 39.2 |
|---|---|
| Target | 0.2 |
| Herbie | 0.4 |
if (+ 1.0 x) < 1.000000000143161Initial program 59.2
Taylor expanded around 0 0.4
Simplified0.4
if 1.000000000143161 < (+ 1.0 x) Initial program 0.4
Final simplification0.4
herbie shell --seed 2020062 +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)))