\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -4.409799457837537 \cdot 10^{-16} \lor \neg \left(\varepsilon \leq 1.902949990538939 \cdot 10^{-13}\right):\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\
\mathbf{else}:\\
\;\;\;\;\varepsilon + \left(\varepsilon + x\right) \cdot \left(\varepsilon \cdot x\right)\\
\end{array}(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
(FPCore (x eps) :precision binary64 (if (or (<= eps -4.409799457837537e-16) (not (<= eps 1.902949990538939e-13))) (- (/ (+ (tan x) (tan eps)) (- 1.0 (* (tan x) (tan eps)))) (tan x)) (+ eps (* (+ eps x) (* eps x)))))
double code(double x, double eps) {
return tan(x + eps) - tan(x);
}
double code(double x, double eps) {
double tmp;
if ((eps <= -4.409799457837537e-16) || !(eps <= 1.902949990538939e-13)) {
tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) - tan(x);
} else {
tmp = eps + ((eps + x) * (eps * x));
}
return tmp;
}




Bits error versus x




Bits error versus eps
Results
| Original | 37.2 |
|---|---|
| Target | 15.0 |
| Herbie | 15.4 |
if eps < -4.409799457837537e-16 or 1.902949990538939e-13 < eps Initial program 29.8
rmApplied tan-sum_binary64_19340.7
if -4.409799457837537e-16 < eps < 1.902949990538939e-13Initial program 45.2
Taylor expanded around 0 31.6
Simplified31.4
Final simplification15.4
herbie shell --seed 2020277
(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)))