\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \le -6.1493629123170849 \cdot 10^{-28}:\\
\;\;\;\;\frac{\left(\tan x + \tan \varepsilon\right) \cdot \cos x - \left(1 - \frac{\sin x \cdot \sin \varepsilon}{\cos x \cdot \cos \varepsilon}\right) \cdot \sin x}{\left(1 - \frac{\sin x \cdot \sin \varepsilon}{\cos x \cdot \cos \varepsilon}\right) \cdot \cos x}\\
\mathbf{elif}\;\varepsilon \le 9.19032739794848937 \cdot 10^{-24}:\\
\;\;\;\;\left(\varepsilon \cdot x\right) \cdot \left(x + \varepsilon\right) + \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan x \cdot \tan x - \tan \varepsilon \cdot \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} \cdot \frac{1}{\tan x - \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 VAR;
if ((eps <= -6.149362912317085e-28)) {
VAR = ((((tan(x) + tan(eps)) * cos(x)) - ((1.0 - ((sin(x) * sin(eps)) / (cos(x) * cos(eps)))) * sin(x))) / ((1.0 - ((sin(x) * sin(eps)) / (cos(x) * cos(eps)))) * cos(x)));
} else {
double VAR_1;
if ((eps <= 9.19032739794849e-24)) {
VAR_1 = (((eps * x) * (x + eps)) + eps);
} else {
VAR_1 = (((((tan(x) * tan(x)) - (tan(eps) * tan(eps))) / (1.0 - (tan(x) * tan(eps)))) * (1.0 / (tan(x) - tan(eps)))) - tan(x));
}
VAR = VAR_1;
}
return VAR;
}




Bits error versus x




Bits error versus eps
Results
| Original | 36.7 |
|---|---|
| Target | 15.8 |
| Herbie | 14.7 |
if eps < -6.149362912317085e-28Initial program 30.5
rmApplied tan-sum2.1
rmApplied tan-quot2.1
Applied tan-quot2.1
Applied frac-times2.1
rmApplied tan-quot2.2
Applied frac-sub2.2
if -6.149362912317085e-28 < eps < 9.19032739794849e-24Initial program 44.8
Taylor expanded around 0 30.9
Simplified30.7
if 9.19032739794849e-24 < eps Initial program 30.1
rmApplied tan-sum1.8
rmApplied clear-num1.9
rmApplied flip-+2.0
Applied associate-/r/2.1
Applied add-cube-cbrt2.1
Applied times-frac2.1
Simplified2.0
Simplified2.0
Final simplification14.7
herbie shell --seed 2020102
(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)))