\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \le -6.30345879620911344 \cdot 10^{-39}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\tan x + \tan \varepsilon}{1 - \left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)}, 1 + \tan x \cdot \tan \varepsilon, -\tan x\right)\\
\mathbf{elif}\;\varepsilon \le 1.0217107006174054 \cdot 10^{-22}:\\
\;\;\;\;\mathsf{fma}\left({\varepsilon}^{2}, x, \mathsf{fma}\left(\varepsilon, {x}^{2}, \varepsilon\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\tan x \cdot \tan x - \tan \varepsilon \cdot \tan \varepsilon}{\tan x - \tan \varepsilon}}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\
\end{array}double code(double x, double eps) {
return (tan((x + eps)) - tan(x));
}
double code(double x, double eps) {
double temp;
if ((eps <= -6.303458796209113e-39)) {
temp = fma(((tan(x) + tan(eps)) / (1.0 - ((tan(x) * tan(eps)) * (tan(x) * tan(eps))))), (1.0 + (tan(x) * tan(eps))), -tan(x));
} else {
double temp_1;
if ((eps <= 1.0217107006174054e-22)) {
temp_1 = fma(pow(eps, 2.0), x, fma(eps, pow(x, 2.0), eps));
} else {
temp_1 = (((((tan(x) * tan(x)) - (tan(eps) * tan(eps))) / (tan(x) - tan(eps))) / (1.0 - (tan(x) * tan(eps)))) - tan(x));
}
temp = temp_1;
}
return temp;
}




Bits error versus x




Bits error versus eps
Results
| Original | 36.9 |
|---|---|
| Target | 15.5 |
| Herbie | 15.1 |
if eps < -6.303458796209113e-39Initial program 30.5
rmApplied tan-sum3.2
rmApplied flip--3.2
Applied associate-/r/3.2
Applied fma-neg3.2
if -6.303458796209113e-39 < eps < 1.0217107006174054e-22Initial program 45.5
Taylor expanded around 0 31.3
Simplified31.3
if 1.0217107006174054e-22 < eps Initial program 29.7
rmApplied tan-sum1.4
rmApplied flip-+1.5
Final simplification15.1
herbie shell --seed 2020060 +o rules:numerics
(FPCore (x eps)
:name "2tan (problem 3.3.2)"
:precision binary64
:herbie-target
(/ (sin eps) (* (cos x) (cos (+ x eps))))
(- (tan (+ x eps)) (tan x)))