\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 r51195 = 1.0;
double r51196 = x;
double r51197 = r51195 + r51196;
double r51198 = log(r51197);
return r51198;
}
double f(double x) {
double r51199 = 1.0;
double r51200 = x;
double r51201 = r51199 + r51200;
double r51202 = 1.0000000000000033;
bool r51203 = r51201 <= r51202;
double r51204 = -0.5;
double r51205 = 2.0;
double r51206 = pow(r51200, r51205);
double r51207 = pow(r51199, r51205);
double r51208 = r51206 / r51207;
double r51209 = log(r51199);
double r51210 = fma(r51199, r51200, r51209);
double r51211 = fma(r51204, r51208, r51210);
double r51212 = sqrt(r51201);
double r51213 = log(r51212);
double r51214 = r51213 + r51213;
double r51215 = r51203 ? r51211 : r51214;
return r51215;
}




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)))