\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \le -5.18345613024736167 \cdot 10^{-37} \lor \neg \left(\varepsilon \le 6.6497007082639564 \cdot 10^{-24}\right):\\
\;\;\;\;\frac{1}{\frac{1 - \tan x \cdot \tan \varepsilon}{\tan x + \tan \varepsilon}} - \tan 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 VAR;
if (((eps <= -5.183456130247362e-37) || !(eps <= 6.649700708263956e-24))) {
VAR = ((1.0 / ((1.0 - (tan(x) * tan(eps))) / (tan(x) + tan(eps)))) - tan(x));
} else {
VAR = fma(pow(eps, 2.0), x, fma(eps, pow(x, 2.0), eps));
}
return VAR;
}




Bits error versus x




Bits error versus eps
Results
| Original | 36.7 |
|---|---|
| Target | 15.8 |
| Herbie | 14.8 |
if eps < -5.183456130247362e-37 or 6.649700708263956e-24 < eps Initial program 30.3
rmApplied tan-sum2.3
rmApplied clear-num2.4
if -5.183456130247362e-37 < eps < 6.649700708263956e-24Initial program 45.0
Taylor expanded around 0 30.9
Simplified30.9
Final simplification14.8
herbie shell --seed 2020102 +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)))