\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -7.776131049831412 \cdot 10^{-16}:\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \frac{\tan \varepsilon \cdot \sin x}{\cos x}} - \tan x\\
\mathbf{elif}\;\varepsilon \leq 4.9499569793722125 \cdot 10^{-51}:\\
\;\;\;\;\varepsilon + \left(\varepsilon + x\right) \cdot \left(\varepsilon \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \frac{\tan \varepsilon \cdot \sin x}{\cos x}} - \tan x\\
\end{array}(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
(FPCore (x eps)
:precision binary64
(if (<= eps -7.776131049831412e-16)
(-
(/ (+ (tan x) (tan eps)) (- 1.0 (/ (* (tan eps) (sin x)) (cos x))))
(tan x))
(if (<= eps 4.9499569793722125e-51)
(+ eps (* (+ eps x) (* eps x)))
(-
(/ (+ (tan x) (tan eps)) (- 1.0 (/ (* (tan eps) (sin x)) (cos x))))
(tan x)))))double code(double x, double eps) {
return tan(x + eps) - tan(x);
}
double code(double x, double eps) {
double tmp;
if (eps <= -7.776131049831412e-16) {
tmp = ((tan(x) + tan(eps)) / (1.0 - ((tan(eps) * sin(x)) / cos(x)))) - tan(x);
} else if (eps <= 4.9499569793722125e-51) {
tmp = eps + ((eps + x) * (eps * x));
} else {
tmp = ((tan(x) + tan(eps)) / (1.0 - ((tan(eps) * sin(x)) / cos(x)))) - tan(x);
}
return tmp;
}




Bits error versus x




Bits error versus eps
Results
| Original | 36.8 |
|---|---|
| Target | 15.1 |
| Herbie | 15.2 |
if eps < -7.77613104983141215e-16 or 4.9499569793722125e-51 < eps Initial program 29.6
rmApplied tan-sum_binary642.3
rmApplied tan-quot_binary642.3
Applied associate-*l/_binary642.3
Simplified2.3
if -7.77613104983141215e-16 < eps < 4.9499569793722125e-51Initial program 45.7
Taylor expanded around 0 31.4
Simplified31.2
Final simplification15.2
herbie shell --seed 2020273
(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)))