\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.00000008116859207:\\
\;\;\;\;\mathsf{fma}\left(\frac{-1}{2}, \frac{{x}^{2}}{{1}^{2}}, \mathsf{fma}\left(1, x, \log 1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(1 + x\right)\\
\end{array}double f(double x) {
double r59235 = 1.0;
double r59236 = x;
double r59237 = r59235 + r59236;
double r59238 = log(r59237);
return r59238;
}
double f(double x) {
double r59239 = 1.0;
double r59240 = x;
double r59241 = r59239 + r59240;
double r59242 = 1.000000081168592;
bool r59243 = r59241 <= r59242;
double r59244 = -0.5;
double r59245 = 2.0;
double r59246 = pow(r59240, r59245);
double r59247 = pow(r59239, r59245);
double r59248 = r59246 / r59247;
double r59249 = log(r59239);
double r59250 = fma(r59239, r59240, r59249);
double r59251 = fma(r59244, r59248, r59250);
double r59252 = log(r59241);
double r59253 = r59243 ? r59251 : r59252;
return r59253;
}




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