\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.000000000521483745075101978727616369724:\\
\;\;\;\;\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 r87925 = 1.0;
double r87926 = x;
double r87927 = r87925 + r87926;
double r87928 = log(r87927);
return r87928;
}
double f(double x) {
double r87929 = 1.0;
double r87930 = x;
double r87931 = r87929 + r87930;
double r87932 = 1.0000000005214837;
bool r87933 = r87931 <= r87932;
double r87934 = log(r87929);
double r87935 = 0.5;
double r87936 = 2.0;
double r87937 = pow(r87930, r87936);
double r87938 = pow(r87929, r87936);
double r87939 = r87937 / r87938;
double r87940 = r87935 * r87939;
double r87941 = r87934 - r87940;
double r87942 = fma(r87930, r87929, r87941);
double r87943 = log(r87931);
double r87944 = r87933 ? r87942 : r87943;
return r87944;
}




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