\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \le -1.4968426811240258 \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}:\\
\;\;\;\;\mathsf{fma}\left({\varepsilon}^{2}, x, \mathsf{fma}\left(\varepsilon, {x}^{2}, \varepsilon\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\tan x + \tan \varepsilon}{{1}^{3} - {\left(\frac{\tan x \cdot \sin \varepsilon}{\cos \varepsilon}\right)}^{3}}, 1 \cdot 1 + \left(\frac{\tan x \cdot \sin \varepsilon}{\cos \varepsilon} \cdot \frac{\tan x \cdot \sin \varepsilon}{\cos \varepsilon} + 1 \cdot \frac{\tan x \cdot \sin \varepsilon}{\cos \varepsilon}\right), -\tan x\right)\\
\end{array}double code(double x, double eps) {
return (tan((x + eps)) - tan(x));
}
double code(double x, double eps) {
double temp;
if ((eps <= -1.4968426811240258e-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 = fma(pow(eps, 2.0), x, fma(eps, pow(x, 2.0), eps));
} else {
temp_1 = fma(((tan(x) + tan(eps)) / (pow(1.0, 3.0) - pow(((tan(x) * sin(eps)) / cos(eps)), 3.0))), ((1.0 * 1.0) + ((((tan(x) * sin(eps)) / cos(eps)) * ((tan(x) * sin(eps)) / cos(eps))) + (1.0 * ((tan(x) * sin(eps)) / cos(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 < -1.4968426811240258e-90Initial program 30.9
rmApplied tan-sum6.8
rmApplied clear-num6.9
if -1.4968426811240258e-90 < eps < 5.748527172026931e-167Initial program 48.9
Taylor expanded around 0 30.0
Simplified30.0
if 5.748527172026931e-167 < eps Initial program 32.4
rmApplied tan-sum13.0
rmApplied tan-quot13.1
Applied associate-*r/13.1
rmApplied flip3--13.1
Applied associate-/r/13.1
Applied fma-neg13.1
Final simplification15.8
herbie shell --seed 2020056 +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)))