\frac{1}{x} - \frac{1}{\tan x}\frac{2}{945} \cdot {x}^{5} + x \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{fma}\left(x \cdot \frac{1}{45}, x, \frac{1}{3}\right)\right)\right)double f(double x) {
double r1370428 = 1.0;
double r1370429 = x;
double r1370430 = r1370428 / r1370429;
double r1370431 = tan(r1370429);
double r1370432 = r1370428 / r1370431;
double r1370433 = r1370430 - r1370432;
return r1370433;
}
double f(double x) {
double r1370434 = 0.0021164021164021165;
double r1370435 = x;
double r1370436 = 5.0;
double r1370437 = pow(r1370435, r1370436);
double r1370438 = r1370434 * r1370437;
double r1370439 = 0.022222222222222223;
double r1370440 = r1370435 * r1370439;
double r1370441 = 0.3333333333333333;
double r1370442 = fma(r1370440, r1370435, r1370441);
double r1370443 = log1p(r1370442);
double r1370444 = expm1(r1370443);
double r1370445 = r1370435 * r1370444;
double r1370446 = r1370438 + r1370445;
return r1370446;
}




Bits error versus x
| Original | 59.9 |
|---|---|
| Target | 0.1 |
| Herbie | 0.4 |
Initial program 59.9
Taylor expanded around 0 0.3
Simplified0.3
Taylor expanded around -inf 0.3
Simplified0.3
rmApplied fma-udef0.3
Simplified0.3
rmApplied expm1-log1p-u0.4
Final simplification0.4
herbie shell --seed 2019151 +o rules:numerics
(FPCore (x)
:name "invcot (example 3.9)"
:pre (and (< -0.026 x) (< x 0.026))
:herbie-target
(if (< (fabs x) 0.026) (* (/ x 3) (+ 1 (/ (* x x) 15))) (- (/ 1 x) (/ 1 (tan x))))
(- (/ 1 x) (/ 1 (tan x))))