\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.0001395119845617:\\
\;\;\;\;\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 r73022 = 1.0;
double r73023 = x;
double r73024 = r73022 + r73023;
double r73025 = log(r73024);
return r73025;
}
double f(double x) {
double r73026 = 1.0;
double r73027 = x;
double r73028 = r73026 + r73027;
double r73029 = 1.0001395119845617;
bool r73030 = r73028 <= r73029;
double r73031 = -r73026;
double r73032 = 3.0;
double r73033 = pow(r73027, r73032);
double r73034 = 2.0;
double r73035 = pow(r73026, r73034);
double r73036 = r73033 / r73035;
double r73037 = fma(r73027, r73027, r73036);
double r73038 = 0.3333333333333333;
double r73039 = pow(r73026, r73032);
double r73040 = r73033 / r73039;
double r73041 = 0.5;
double r73042 = pow(r73027, r73034);
double r73043 = r73042 / r73035;
double r73044 = r73026 * r73027;
double r73045 = fma(r73041, r73043, r73044);
double r73046 = fma(r73026, r73033, r73045);
double r73047 = fma(r73038, r73040, r73046);
double r73048 = fma(r73031, r73037, r73047);
double r73049 = log(r73028);
double r73050 = r73030 ? r73048 : r73049;
return r73050;
}




Bits error versus x
| Original | 38.8 |
|---|---|
| Target | 0.3 |
| Herbie | 0.2 |
if (+ 1.0 x) < 1.0001395119845617Initial program 58.7
rmApplied flip3-+58.7
Applied log-div58.7
Taylor expanded around 0 0.3
Simplified0.3
if 1.0001395119845617 < (+ 1.0 x) Initial program 0.1
Final simplification0.2
herbie shell --seed 2020049 +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)))