\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.000000000077041040213998712715692818165:\\
\;\;\;\;\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 r81648 = 1.0;
double r81649 = x;
double r81650 = r81648 + r81649;
double r81651 = log(r81650);
return r81651;
}
double f(double x) {
double r81652 = 1.0;
double r81653 = x;
double r81654 = r81652 + r81653;
double r81655 = 1.000000000077041;
bool r81656 = r81654 <= r81655;
double r81657 = log(r81652);
double r81658 = 0.5;
double r81659 = 2.0;
double r81660 = pow(r81653, r81659);
double r81661 = pow(r81652, r81659);
double r81662 = r81660 / r81661;
double r81663 = r81658 * r81662;
double r81664 = r81657 - r81663;
double r81665 = fma(r81653, r81652, r81664);
double r81666 = log(r81654);
double r81667 = r81656 ? r81665 : r81666;
return r81667;
}




Bits error versus x
| Original | 39.0 |
|---|---|
| Target | 0.2 |
| Herbie | 0.4 |
if (+ 1.0 x) < 1.000000000077041Initial program 59.5
Taylor expanded around 0 0.3
Simplified0.3
if 1.000000000077041 < (+ 1.0 x) Initial program 0.5
Final simplification0.4
herbie shell --seed 2019353 +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)))