\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.0000000000090492:\\
\;\;\;\;\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 r65538 = 1.0;
double r65539 = x;
double r65540 = r65538 + r65539;
double r65541 = log(r65540);
return r65541;
}
double f(double x) {
double r65542 = 1.0;
double r65543 = x;
double r65544 = r65542 + r65543;
double r65545 = 1.0000000000090492;
bool r65546 = r65544 <= r65545;
double r65547 = log(r65542);
double r65548 = 0.5;
double r65549 = 2.0;
double r65550 = pow(r65543, r65549);
double r65551 = pow(r65542, r65549);
double r65552 = r65550 / r65551;
double r65553 = r65548 * r65552;
double r65554 = r65547 - r65553;
double r65555 = fma(r65543, r65542, r65554);
double r65556 = log(r65544);
double r65557 = r65546 ? r65555 : r65556;
return r65557;
}




Bits error versus x
| Original | 39.5 |
|---|---|
| Target | 0.4 |
| Herbie | 0.4 |
if (+ 1.0 x) < 1.0000000000090492Initial program 59.4
Taylor expanded around 0 0.3
Simplified0.3
if 1.0000000000090492 < (+ 1.0 x) Initial program 0.7
Final simplification0.4
herbie shell --seed 2020020 +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)))