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




Bits error versus x




Bits error versus eps
Results
| Original | 37.0 |
|---|---|
| Target | 15.0 |
| Herbie | 15.8 |
if eps < -4.96093417396623927e-23Initial program 29.6
rmApplied tan-sum_binary64_19341.5
rmApplied div-inv_binary64_17961.6
if -4.96093417396623927e-23 < eps < 8.2973875419376863e-47Initial program 45.7
Taylor expanded around 0 32.0
Simplified31.8
if 8.2973875419376863e-47 < eps Initial program 30.1
rmApplied tan-sum_binary64_19343.2
rmApplied clear-num_binary64_17983.3
rmApplied tan-quot_binary64_19583.3
Applied frac-sub_binary64_18083.4
Simplified3.4
Final simplification15.8
herbie shell --seed 2020292
(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)))