\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.0000000031820615:\\
\;\;\;\;\mathsf{fma}\left(\frac{{x}^{2}}{{1}^{2}}, \frac{-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 r125788 = 1.0;
double r125789 = x;
double r125790 = r125788 + r125789;
double r125791 = log(r125790);
return r125791;
}
double f(double x) {
double r125792 = 1.0;
double r125793 = x;
double r125794 = r125792 + r125793;
double r125795 = 1.0000000031820615;
bool r125796 = r125794 <= r125795;
double r125797 = 2.0;
double r125798 = pow(r125793, r125797);
double r125799 = pow(r125792, r125797);
double r125800 = r125798 / r125799;
double r125801 = -0.5;
double r125802 = log(r125792);
double r125803 = fma(r125792, r125793, r125802);
double r125804 = fma(r125800, r125801, r125803);
double r125805 = log(r125794);
double r125806 = r125796 ? r125804 : r125805;
return r125806;
}




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