\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -8.82532240330736 \cdot 10^{-33} \lor \neg \left(\varepsilon \leq 2.8352874239115425 \cdot 10^{-18}\right):\\
\;\;\;\;\frac{\left(\tan x + \tan \varepsilon\right) \cdot \cos x - \left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \sin x}{\cos x \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)}\\
\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 -8.82532240330736e-33) (not (<= eps 2.8352874239115425e-18)))
(/
(-
(* (+ (tan x) (tan eps)) (cos x))
(* (- 1.0 (* (tan x) (tan eps))) (sin x)))
(* (cos x) (- 1.0 (* (tan x) (tan eps)))))
(+ 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 <= -8.82532240330736e-33) || !(eps <= 2.8352874239115425e-18)) {
tmp = (((tan(x) + tan(eps)) * cos(x)) - ((1.0 - (tan(x) * tan(eps))) * sin(x))) / (cos(x) * (1.0 - (tan(x) * tan(eps))));
} else {
tmp = eps + ((eps + x) * (eps * x));
}
return tmp;
}




Bits error versus x




Bits error versus eps
Results
| Original | 36.6 |
|---|---|
| Target | 15.2 |
| Herbie | 15.2 |
if eps < -8.82532240330736014e-33 or 2.83528742391154245e-18 < eps Initial program 29.6
rmApplied tan-quot_binary64_191829.5
Applied tan-sum_binary64_18941.7
Applied frac-sub_binary64_17711.7
if -8.82532240330736014e-33 < eps < 2.83528742391154245e-18Initial program 45.0
Taylor expanded around 0 31.4
Simplified31.2
Final simplification15.2
herbie shell --seed 2020299
(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)))