\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \le -6.33244240103325679 \cdot 10^{-40}:\\
\;\;\;\;\frac{\left(\tan x + \tan \varepsilon\right) \cdot \cos x - \left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \sin x}{\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \cos x}\\
\mathbf{elif}\;\varepsilon \le 3.2057505173626071 \cdot 10^{-73}:\\
\;\;\;\;\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 - \left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)}, 1 + \tan x \cdot \tan \varepsilon, -\tan x\right)\\
\end{array}double code(double x, double eps) {
return ((double) (((double) tan(((double) (x + eps)))) - ((double) tan(x))));
}
double code(double x, double eps) {
double VAR;
if ((eps <= -6.332442401033257e-40)) {
VAR = ((double) (((double) (((double) (((double) (((double) tan(x)) + ((double) tan(eps)))) * ((double) cos(x)))) - ((double) (((double) (1.0 - ((double) (((double) tan(x)) * ((double) tan(eps)))))) * ((double) sin(x)))))) / ((double) (((double) (1.0 - ((double) (((double) tan(x)) * ((double) tan(eps)))))) * ((double) cos(x))))));
} else {
double VAR_1;
if ((eps <= 3.205750517362607e-73)) {
VAR_1 = ((double) fma(((double) pow(eps, 2.0)), x, ((double) fma(eps, ((double) pow(x, 2.0)), eps))));
} else {
VAR_1 = ((double) fma(((double) (((double) (((double) tan(x)) + ((double) tan(eps)))) / ((double) (1.0 - ((double) (((double) (((double) tan(x)) * ((double) tan(eps)))) * ((double) (((double) tan(x)) * ((double) tan(eps)))))))))), ((double) (1.0 + ((double) (((double) tan(x)) * ((double) tan(eps)))))), ((double) -(((double) tan(x))))));
}
VAR = VAR_1;
}
return VAR;
}




Bits error versus x




Bits error versus eps
Results
| Original | 36.9 |
|---|---|
| Target | 15.4 |
| Herbie | 14.7 |
if eps < -6.332442401033257e-40Initial program 30.1
rmApplied tan-quot29.9
Applied tan-sum3.1
Applied frac-sub3.1
if -6.332442401033257e-40 < eps < 3.205750517362607e-73Initial program 46.6
Taylor expanded around 0 30.0
Simplified30.0
if 3.205750517362607e-73 < eps Initial program 30.6
rmApplied tan-sum5.6
rmApplied flip--5.6
Applied associate-/r/5.6
Applied fma-neg5.6
Final simplification14.7
herbie shell --seed 2020120 +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)))