\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.00000000000000333:\\
\;\;\;\;\mathsf{fma}\left(\frac{-1}{2}, \frac{{x}^{2}}{{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 r65958 = 1.0;
double r65959 = x;
double r65960 = r65958 + r65959;
double r65961 = log(r65960);
return r65961;
}
double f(double x) {
double r65962 = 1.0;
double r65963 = x;
double r65964 = r65962 + r65963;
double r65965 = 1.0000000000000033;
bool r65966 = r65964 <= r65965;
double r65967 = -0.5;
double r65968 = 2.0;
double r65969 = pow(r65963, r65968);
double r65970 = pow(r65962, r65968);
double r65971 = r65969 / r65970;
double r65972 = log(r65962);
double r65973 = fma(r65962, r65963, r65972);
double r65974 = fma(r65967, r65971, r65973);
double r65975 = sqrt(r65964);
double r65976 = log(r65975);
double r65977 = r65976 + r65976;
double r65978 = r65966 ? r65974 : r65977;
return r65978;
}




Bits error versus x
| Original | 38.8 |
|---|---|
| Target | 0.2 |
| Herbie | 0.5 |
if (+ 1.0 x) < 1.0000000000000033Initial program 59.6
Taylor expanded around 0 0.3
Simplified0.3
if 1.0000000000000033 < (+ 1.0 x) Initial program 0.9
rmApplied add-sqr-sqrt1.0
Applied log-prod1.0
Final simplification0.5
herbie shell --seed 2020047 +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)))