\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \le -5.97198873028037458 \cdot 10^{-27} \lor \neg \left(\varepsilon \le 2.0534977977042638 \cdot 10^{-22}\right):\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{\frac{1 - \left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)}{1 + \tan x \cdot \tan \varepsilon}} - \tan x\\
\mathbf{else}:\\
\;\;\;\;\left(\varepsilon \cdot x\right) \cdot \left(x + \varepsilon\right) + \varepsilon\\
\end{array}double code(double x, double eps) {
return (tan((x + eps)) - tan(x));
}
double code(double x, double eps) {
double temp;
if (((eps <= -5.9719887302803746e-27) || !(eps <= 2.0534977977042638e-22))) {
temp = (((tan(x) + tan(eps)) / ((1.0 - ((tan(x) * tan(eps)) * (tan(x) * tan(eps)))) / (1.0 + (tan(x) * tan(eps))))) - tan(x));
} else {
temp = (((eps * x) * (x + eps)) + eps);
}
return temp;
}




Bits error versus x




Bits error versus eps
Results
| Original | 36.8 |
|---|---|
| Target | 15.2 |
| Herbie | 15.0 |
if eps < -5.9719887302803746e-27 or 2.0534977977042638e-22 < eps Initial program 29.8
rmApplied tan-sum1.6
rmApplied flip--1.7
Simplified1.7
if -5.9719887302803746e-27 < eps < 2.0534977977042638e-22Initial program 45.1
Taylor expanded around 0 30.9
Simplified30.7
Final simplification15.0
herbie shell --seed 2020057
(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)))