\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -2.5441009276949707 \cdot 10^{-53}:\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \frac{{\left(\sin x \cdot \sin \varepsilon\right)}^{3}}{{\left(\cos x \cdot \cos \varepsilon\right)}^{3}}} \cdot \left(1 + \left(\tan x \cdot \tan \varepsilon + \left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)\right)\right) - \tan x\\
\mathbf{elif}\;\varepsilon \leq 1.914951132073428 \cdot 10^{-114}:\\
\;\;\;\;\varepsilon + \left(\varepsilon + x\right) \cdot \left(\varepsilon \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\tan x + \tan \varepsilon\right) \cdot \cos x - \sin x \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)}{\cos x \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)}\\
\end{array}(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
(FPCore (x eps)
:precision binary64
(if (<= eps -2.5441009276949707e-53)
(-
(*
(/
(+ (tan x) (tan eps))
(-
1.0
(/ (pow (* (sin x) (sin eps)) 3.0) (pow (* (cos x) (cos eps)) 3.0))))
(+
1.0
(+
(* (tan x) (tan eps))
(* (* (tan x) (tan eps)) (* (tan x) (tan eps))))))
(tan x))
(if (<= eps 1.914951132073428e-114)
(+ eps (* (+ eps x) (* eps x)))
(/
(-
(* (+ (tan x) (tan eps)) (cos x))
(* (sin x) (- 1.0 (* (tan x) (tan eps)))))
(* (cos x) (- 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 <= -2.5441009276949707e-53) {
tmp = (((tan(x) + tan(eps)) / (1.0 - (pow((sin(x) * sin(eps)), 3.0) / pow((cos(x) * cos(eps)), 3.0)))) * (1.0 + ((tan(x) * tan(eps)) + ((tan(x) * tan(eps)) * (tan(x) * tan(eps)))))) - tan(x);
} else if (eps <= 1.914951132073428e-114) {
tmp = eps + ((eps + x) * (eps * x));
} else {
tmp = (((tan(x) + tan(eps)) * cos(x)) - (sin(x) * (1.0 - (tan(x) * tan(eps))))) / (cos(x) * (1.0 - (tan(x) * tan(eps))));
}
return tmp;
}




Bits error versus x




Bits error versus eps
Results
| Original | 37.3 |
|---|---|
| Target | 15.1 |
| Herbie | 15.8 |
if eps < -2.5441009276949707e-53Initial program 29.1
rmApplied tan-sum_binary64_18944.0
rmApplied flip3--_binary64_17664.0
Applied associate-/r/_binary64_17104.0
Simplified4.0
rmApplied tan-quot_binary64_19184.1
Applied tan-quot_binary64_19184.1
Applied frac-times_binary64_17724.1
Applied cube-div_binary64_17884.1
if -2.5441009276949707e-53 < eps < 1.9149511320734281e-114Initial program 48.5
Taylor expanded around 0 31.5
Simplified31.3
if 1.9149511320734281e-114 < eps Initial program 32.3
rmApplied tan-quot_binary64_191832.2
Applied tan-sum_binary64_18949.2
Applied frac-sub_binary64_17719.2
Final simplification15.8
herbie shell --seed 2020280
(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)))