\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.0000004755978571:\\
\;\;\;\;\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 r54020 = 1.0;
double r54021 = x;
double r54022 = r54020 + r54021;
double r54023 = log(r54022);
return r54023;
}
double f(double x) {
double r54024 = 1.0;
double r54025 = x;
double r54026 = r54024 + r54025;
double r54027 = 1.000000475597857;
bool r54028 = r54026 <= r54027;
double r54029 = log(r54024);
double r54030 = 0.5;
double r54031 = 2.0;
double r54032 = pow(r54025, r54031);
double r54033 = pow(r54024, r54031);
double r54034 = r54032 / r54033;
double r54035 = r54030 * r54034;
double r54036 = r54029 - r54035;
double r54037 = fma(r54025, r54024, r54036);
double r54038 = log(r54026);
double r54039 = r54028 ? r54037 : r54038;
return r54039;
}




Bits error versus x
| Original | 39.3 |
|---|---|
| Target | 0.2 |
| Herbie | 0.3 |
if (+ 1.0 x) < 1.000000475597857Initial program 59.0
Taylor expanded around 0 0.3
Simplified0.3
if 1.000000475597857 < (+ 1.0 x) Initial program 0.2
Final simplification0.3
herbie shell --seed 2020027 +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)))