\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;x \le 6.37915373787209162315678737109614360179 \cdot 10^{-6}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{1} \cdot \frac{x}{1}, \frac{-1}{2}, \mathsf{fma}\left(x, 1, \log 1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(1 + x\right) \cdot \frac{1}{2} + \log \left(\sqrt{1 + x}\right)\\
\end{array}double f(double x) {
double r36457 = 1.0;
double r36458 = x;
double r36459 = r36457 + r36458;
double r36460 = log(r36459);
return r36460;
}
double f(double x) {
double r36461 = x;
double r36462 = 6.379153737872092e-06;
bool r36463 = r36461 <= r36462;
double r36464 = 1.0;
double r36465 = r36461 / r36464;
double r36466 = r36465 * r36465;
double r36467 = -0.5;
double r36468 = log(r36464);
double r36469 = fma(r36461, r36464, r36468);
double r36470 = fma(r36466, r36467, r36469);
double r36471 = r36464 + r36461;
double r36472 = log(r36471);
double r36473 = 0.5;
double r36474 = r36472 * r36473;
double r36475 = sqrt(r36471);
double r36476 = log(r36475);
double r36477 = r36474 + r36476;
double r36478 = r36463 ? r36470 : r36477;
return r36478;
}




Bits error versus x
| Original | 39.3 |
|---|---|
| Target | 0.2 |
| Herbie | 0.3 |
if x < 6.379153737872092e-06Initial program 59.0
Simplified59.0
Taylor expanded around 0 0.4
Simplified0.4
if 6.379153737872092e-06 < x Initial program 0.1
Simplified0.1
rmApplied add-sqr-sqrt0.1
Applied log-prod0.1
Simplified0.1
Simplified0.1
rmApplied pow1/20.1
Applied log-pow0.1
Simplified0.1
Final simplification0.3
herbie shell --seed 2019195 +o rules:numerics
(FPCore (x)
:name "ln(1 + x)"
:herbie-target
(if (== (+ 1.0 x) 1.0) x (/ (* x (log (+ 1.0 x))) (- (+ 1.0 x) 1.0)))
(log (+ 1.0 x)))