\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.0000000000004809:\\
\;\;\;\;\mathsf{fma}\left(-1, \mathsf{fma}\left(x, x, \frac{{x}^{3}}{{1}^{2}}\right), \mathsf{fma}\left(0.333333333333333315, \frac{{x}^{3}}{{1}^{3}}, \mathsf{fma}\left(1, {x}^{3}, \mathsf{fma}\left(0.5, \frac{{x}^{2}}{{1}^{2}}, 1 \cdot x\right)\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(1 + x\right)\\
\end{array}double f(double x) {
double r83144 = 1.0;
double r83145 = x;
double r83146 = r83144 + r83145;
double r83147 = log(r83146);
return r83147;
}
double f(double x) {
double r83148 = 1.0;
double r83149 = x;
double r83150 = r83148 + r83149;
double r83151 = 1.000000000000481;
bool r83152 = r83150 <= r83151;
double r83153 = -r83148;
double r83154 = 3.0;
double r83155 = pow(r83149, r83154);
double r83156 = 2.0;
double r83157 = pow(r83148, r83156);
double r83158 = r83155 / r83157;
double r83159 = fma(r83149, r83149, r83158);
double r83160 = 0.3333333333333333;
double r83161 = pow(r83148, r83154);
double r83162 = r83155 / r83161;
double r83163 = 0.5;
double r83164 = pow(r83149, r83156);
double r83165 = r83164 / r83157;
double r83166 = r83148 * r83149;
double r83167 = fma(r83163, r83165, r83166);
double r83168 = fma(r83148, r83155, r83167);
double r83169 = fma(r83160, r83162, r83168);
double r83170 = fma(r83153, r83159, r83169);
double r83171 = log(r83150);
double r83172 = r83152 ? r83170 : r83171;
return r83172;
}




Bits error versus x
| Original | 38.9 |
|---|---|
| Target | 0.2 |
| Herbie | 0.4 |
if (+ 1.0 x) < 1.000000000000481Initial program 59.3
rmApplied flip3-+59.4
Applied log-div59.4
Taylor expanded around 0 0.3
Simplified0.3
if 1.000000000000481 < (+ 1.0 x) Initial program 0.8
Final simplification0.4
herbie shell --seed 2020056 +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)))