\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.000000380361564467079915630165487527847:\\
\;\;\;\;\mathsf{fma}\left(\frac{{x}^{2}}{{1}^{2}}, \frac{-1}{2}, \mathsf{fma}\left(1, x, \log 1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(\sqrt{1 + x}\right) + \log \left(\sqrt{1 + x}\right)\\
\end{array}double f(double x) {
double r84681 = 1.0;
double r84682 = x;
double r84683 = r84681 + r84682;
double r84684 = log(r84683);
return r84684;
}
double f(double x) {
double r84685 = 1.0;
double r84686 = x;
double r84687 = r84685 + r84686;
double r84688 = 1.0000003803615645;
bool r84689 = r84687 <= r84688;
double r84690 = 2.0;
double r84691 = pow(r84686, r84690);
double r84692 = pow(r84685, r84690);
double r84693 = r84691 / r84692;
double r84694 = -0.5;
double r84695 = log(r84685);
double r84696 = fma(r84685, r84686, r84695);
double r84697 = fma(r84693, r84694, r84696);
double r84698 = sqrt(r84687);
double r84699 = log(r84698);
double r84700 = r84699 + r84699;
double r84701 = r84689 ? r84697 : r84700;
return r84701;
}




Bits error versus x
| Original | 38.8 |
|---|---|
| Target | 0.2 |
| Herbie | 0.3 |
if (+ 1.0 x) < 1.0000003803615645Initial program 59.1
Taylor expanded around 0 0.3
Simplified0.3
if 1.0000003803615645 < (+ 1.0 x) Initial program 0.2
rmApplied add-sqr-sqrt0.2
Applied log-prod0.2
Final simplification0.3
herbie shell --seed 2019212 +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)))