\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.00000000000000067:\\
\;\;\;\;\mathsf{fma}\left(x, 1, \log 1 - \frac{1}{2} \cdot \frac{{x}^{2}}{{1}^{2}}\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(\sqrt{1 + x}\right) + \frac{1}{2} \cdot \log \left(1 + x\right)\\
\end{array}double f(double x) {
double r62114 = 1.0;
double r62115 = x;
double r62116 = r62114 + r62115;
double r62117 = log(r62116);
return r62117;
}
double f(double x) {
double r62118 = 1.0;
double r62119 = x;
double r62120 = r62118 + r62119;
double r62121 = 1.0000000000000007;
bool r62122 = r62120 <= r62121;
double r62123 = log(r62118);
double r62124 = 0.5;
double r62125 = 2.0;
double r62126 = pow(r62119, r62125);
double r62127 = pow(r62118, r62125);
double r62128 = r62126 / r62127;
double r62129 = r62124 * r62128;
double r62130 = r62123 - r62129;
double r62131 = fma(r62119, r62118, r62130);
double r62132 = sqrt(r62120);
double r62133 = log(r62132);
double r62134 = log(r62120);
double r62135 = r62124 * r62134;
double r62136 = r62133 + r62135;
double r62137 = r62122 ? r62131 : r62136;
return r62137;
}




Bits error versus x
| Original | 38.5 |
|---|---|
| Target | 0.3 |
| Herbie | 0.6 |
if (+ 1.0 x) < 1.0000000000000007Initial program 59.3
Taylor expanded around 0 0.4
Simplified0.4
if 1.0000000000000007 < (+ 1.0 x) Initial program 1.0
rmApplied add-sqr-sqrt1.0
Applied log-prod1.0
rmApplied pow1/21.0
Applied log-pow1.0
Final simplification0.6
herbie shell --seed 2020025 +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)))