\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.0000000000000413:\\
\;\;\;\;\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 r83092 = 1.0;
double r83093 = x;
double r83094 = r83092 + r83093;
double r83095 = log(r83094);
return r83095;
}
double f(double x) {
double r83096 = 1.0;
double r83097 = x;
double r83098 = r83096 + r83097;
double r83099 = 1.0000000000000413;
bool r83100 = r83098 <= r83099;
double r83101 = log(r83096);
double r83102 = 0.5;
double r83103 = 2.0;
double r83104 = pow(r83097, r83103);
double r83105 = pow(r83096, r83103);
double r83106 = r83104 / r83105;
double r83107 = r83102 * r83106;
double r83108 = r83101 - r83107;
double r83109 = fma(r83097, r83096, r83108);
double r83110 = log(r83098);
double r83111 = r83100 ? r83109 : r83110;
return r83111;
}




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