\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.000000397479964719948952733830083161592:\\
\;\;\;\;\mathsf{fma}\left(x, \mathsf{fma}\left(\frac{\frac{-1}{2}}{1 \cdot 1}, x, 1\right), \log 1\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(\sqrt{1 + x}\right) + \log \left(\left|\sqrt[3]{1 + x}\right| \cdot \sqrt{\sqrt[3]{1 + x}}\right)\\
\end{array}double f(double x) {
double r102956 = 1.0;
double r102957 = x;
double r102958 = r102956 + r102957;
double r102959 = log(r102958);
return r102959;
}
double f(double x) {
double r102960 = 1.0;
double r102961 = x;
double r102962 = r102960 + r102961;
double r102963 = 1.0000003974799647;
bool r102964 = r102962 <= r102963;
double r102965 = -0.5;
double r102966 = r102960 * r102960;
double r102967 = r102965 / r102966;
double r102968 = fma(r102967, r102961, r102960);
double r102969 = log(r102960);
double r102970 = fma(r102961, r102968, r102969);
double r102971 = sqrt(r102962);
double r102972 = log(r102971);
double r102973 = cbrt(r102962);
double r102974 = fabs(r102973);
double r102975 = sqrt(r102973);
double r102976 = r102974 * r102975;
double r102977 = log(r102976);
double r102978 = r102972 + r102977;
double r102979 = r102964 ? r102970 : r102978;
return r102979;
}




Bits error versus x
| Original | 39.1 |
|---|---|
| Target | 0.3 |
| Herbie | 0.3 |
if (+ 1.0 x) < 1.0000003974799647Initial program 59.0
Taylor expanded around 0 0.4
Simplified0.4
if 1.0000003974799647 < (+ 1.0 x) Initial program 0.2
rmApplied add-sqr-sqrt0.2
Applied log-prod0.2
rmApplied add-cube-cbrt0.2
Applied sqrt-prod0.2
Simplified0.2
Final simplification0.3
herbie shell --seed 2019306 +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)))