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




Bits error versus x




Bits error versus eps
Results
| Original | 36.9 |
|---|---|
| Target | 15.4 |
| Herbie | 14.9 |
if eps < -6.50607058644944646e-31Initial program 29.5
rmApplied tan-sum_binary64_15772.0
rmApplied tan-quot_binary64_16012.0
Applied associate-*r/_binary64_13842.0
if -6.50607058644944646e-31 < eps < 2.046397525732066e-33Initial program 45.7
Taylor expanded around 0 31.0
Simplified30.8
if 2.046397525732066e-33 < eps Initial program 30.2
rmApplied tan-sum_binary64_15772.5
rmApplied flip-+_binary64_14162.6
Final simplification14.9
herbie shell --seed 2020349
(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)))