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




Bits error versus x




Bits error versus eps
Results
| Original | 37.1 |
|---|---|
| Target | 15.3 |
| Herbie | 16.0 |
if eps < -6.1878507896536801e-114Initial program 31.5
rmApplied tan-sum_binary649.3
Taylor expanded around inf 9.4
if -6.1878507896536801e-114 < eps < 5.1403356073773628e-104Initial program 49.5
Taylor expanded around 0 31.8
Simplified31.5
if 5.1403356073773628e-104 < eps Initial program 30.9
rmApplied tan-sum_binary648.0
rmApplied flip3--_binary648.0
Simplified8.0
Simplified8.0
rmApplied tan-quot_binary648.1
Applied frac-sub_binary648.1
Final simplification16.0
herbie shell --seed 2020253
(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)))