\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \le -1.4292982892743089 \cdot 10^{-72} \lor \neg \left(\varepsilon \le 7.895037822047127 \cdot 10^{-70}\right):\\
\;\;\;\;\frac{\left(\tan x + \tan \varepsilon\right) \cdot \cos x - \left(1 - \frac{\sin x \cdot \tan \varepsilon}{\cos x}\right) \cdot \sin x}{\left(1 - \frac{\sin x \cdot \tan \varepsilon}{\cos x}\right) \cdot \cos x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left({\varepsilon}^{2}, x, \mathsf{fma}\left(\varepsilon, {x}^{2}, \varepsilon\right)\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.429298289274309e-72) || !(eps <= 7.895037822047127e-70))) {
temp = ((((tan(x) + tan(eps)) * cos(x)) - ((1.0 - ((sin(x) * tan(eps)) / cos(x))) * sin(x))) / ((1.0 - ((sin(x) * tan(eps)) / cos(x))) * cos(x)));
} else {
temp = fma(pow(eps, 2.0), x, fma(eps, pow(x, 2.0), eps));
}
return temp;
}




Bits error versus x




Bits error versus eps
Results
| Original | 37.2 |
|---|---|
| Target | 15.3 |
| Herbie | 16.0 |
if eps < -1.429298289274309e-72 or 7.895037822047127e-70 < eps Initial program 31.1
rmApplied tan-sum6.5
rmApplied tan-quot6.5
Applied associate-*l/6.5
rmApplied tan-quot6.5
Applied frac-sub6.6
if -1.429298289274309e-72 < eps < 7.895037822047127e-70Initial program 47.3
Taylor expanded around 0 31.9
Simplified31.9
Final simplification16.0
herbie shell --seed 2020049 +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)))