\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \le -1.33565384300228764 \cdot 10^{-17} \lor \neg \left(\varepsilon \le 3.2412061887490125 \cdot 10^{-51}\right):\\
\;\;\;\;\frac{{\left(\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}\right)}^{3} - {\left(\tan x\right)}^{3}}{\mathsf{fma}\left(\tan x, \frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} + \tan x, \frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} \cdot \frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, {\varepsilon}^{2}, \mathsf{fma}\left(\frac{1}{3}, {\varepsilon}^{3}, \varepsilon\right)\right)\\
\end{array}double code(double x, double eps) {
return (tan((x + eps)) - tan(x));
}
double code(double x, double eps) {
double VAR;
if (((eps <= -1.3356538430022876e-17) || !(eps <= 3.2412061887490125e-51))) {
VAR = ((pow(((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))), 3.0) - pow(tan(x), 3.0)) / fma(tan(x), (((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) + tan(x)), (((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) * ((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))))));
} else {
VAR = fma(x, pow(eps, 2.0), fma(0.3333333333333333, pow(eps, 3.0), eps));
}
return VAR;
}




Bits error versus x




Bits error versus eps
Results
| Original | 37.3 |
|---|---|
| Target | 15.1 |
| Herbie | 13.8 |
if eps < -1.3356538430022876e-17 or 3.2412061887490125e-51 < eps Initial program 30.1
rmApplied tan-sum2.5
rmApplied flip3--2.8
Simplified2.7
if -1.3356538430022876e-17 < eps < 3.2412061887490125e-51Initial program 46.2
rmApplied tan-sum46.2
Taylor expanded around inf 46.4
Taylor expanded around 0 27.4
Simplified27.4
Final simplification13.8
herbie shell --seed 2020100 +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)))