\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.00000072941427853:\\
\;\;\;\;\mathsf{fma}\left(\frac{-1}{2}, \frac{{x}^{2}}{{1}^{2}}, \mathsf{fma}\left(x, 1, \log 1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(\sqrt{1 + x}\right) + \log \left(1 + x\right) \cdot \frac{1}{2}\\
\end{array}double f(double x) {
double r34834 = 1.0;
double r34835 = x;
double r34836 = r34834 + r34835;
double r34837 = log(r34836);
return r34837;
}
double f(double x) {
double r34838 = 1.0;
double r34839 = x;
double r34840 = r34838 + r34839;
double r34841 = 1.0000007294142785;
bool r34842 = r34840 <= r34841;
double r34843 = -0.5;
double r34844 = 2.0;
double r34845 = pow(r34839, r34844);
double r34846 = pow(r34838, r34844);
double r34847 = r34845 / r34846;
double r34848 = log(r34838);
double r34849 = fma(r34839, r34838, r34848);
double r34850 = fma(r34843, r34847, r34849);
double r34851 = sqrt(r34840);
double r34852 = log(r34851);
double r34853 = log(r34840);
double r34854 = 0.5;
double r34855 = r34853 * r34854;
double r34856 = r34852 + r34855;
double r34857 = r34842 ? r34850 : r34856;
return r34857;
}




Bits error versus x
| Original | 39.3 |
|---|---|
| Target | 0.2 |
| Herbie | 0.3 |
if (+ 1.0 x) < 1.0000007294142785Initial program 59.1
Taylor expanded around 0 0.3
Simplified0.3
if 1.0000007294142785 < (+ 1.0 x) Initial program 0.2
rmApplied add-sqr-sqrt0.2
Applied log-prod0.2
rmApplied pow10.2
Applied sqrt-pow10.2
Applied log-pow0.2
Final simplification0.3
herbie shell --seed 2019195 +o rules:numerics
(FPCore (x)
:name "ln(1 + x)"
:herbie-target
(if (== (+ 1.0 x) 1.0) x (/ (* x (log (+ 1.0 x))) (- (+ 1.0 x) 1.0)))
(log (+ 1.0 x)))