\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \le -2.2637252434053613 \cdot 10^{-90}:\\
\;\;\;\;\frac{1}{\frac{1 - \tan x \cdot \tan \varepsilon}{\tan x + \tan \varepsilon}} - \tan x\\
\mathbf{elif}\;\varepsilon \le 5.7485271720269307 \cdot 10^{-167}:\\
\;\;\;\;\left(x \cdot \varepsilon\right) \cdot \left(\varepsilon + x\right) + \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}} \cdot \left(1 + \left(\left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right) + 1 \cdot \left(\tan x \cdot \tan \varepsilon\right)\right)\right) - \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 <= -2.2637252434053613e-90)) {
temp = ((1.0 / ((1.0 - (tan(x) * tan(eps))) / (tan(x) + tan(eps)))) - tan(x));
} else {
double temp_1;
if ((eps <= 5.748527172026931e-167)) {
temp_1 = (((x * eps) * (eps + x)) + eps);
} else {
temp_1 = ((((tan(x) + tan(eps)) / (1.0 - pow((tan(x) * tan(eps)), 3.0))) * (1.0 + (((tan(x) * 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.6 |
|---|---|
| Target | 15.4 |
| Herbie | 15.8 |
if eps < -2.2637252434053613e-90Initial program 30.9
rmApplied tan-sum6.8
rmApplied clear-num6.9
if -2.2637252434053613e-90 < eps < 5.748527172026931e-167Initial program 48.9
rmApplied tan-sum48.9
rmApplied tan-quot48.9
Applied associate-*r/48.9
Taylor expanded around 0 30.0
Simplified29.7
if 5.748527172026931e-167 < eps Initial program 32.4
rmApplied tan-sum13.0
rmApplied flip3--13.1
Applied associate-/r/13.1
Simplified13.1
Final simplification15.8
herbie shell --seed 2020056
(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)))