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




Bits error versus x




Bits error versus eps
Results
| Original | 37.5 |
|---|---|
| Target | 14.8 |
| Herbie | 15.8 |
if eps < -2.8218801393676676e-60Initial program 30.5
rmApplied tan-sum_binary645.2
rmApplied add-cbrt-cube_binary645.2
Applied add-cbrt-cube_binary645.2
Applied cbrt-unprod_binary645.2
Simplified5.2
rmApplied add-log-exp_binary645.3
Simplified5.3
if -2.8218801393676676e-60 < eps < 5.09701380752455533e-79Initial program 48.3
Taylor expanded around 0 31.3
Simplified31.0
if 5.09701380752455533e-79 < eps Initial program 30.2
rmApplied tan-quot_binary6430.1
Applied tan-sum_binary646.2
Applied frac-sub_binary646.2
Final simplification15.8
herbie shell --seed 2020220
(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)))