\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -2.3047993601266133 \cdot 10^{-36}:\\
\;\;\;\;\frac{\cos x \cdot \left(\left(\tan x + \tan \varepsilon\right) \cdot \left(1 - \left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)\right)\right) - \sin x \cdot \left(\left(1 - \left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)\right) \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)\right)}{\cos x \cdot \left(\left(1 - \left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)\right) \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)\right)}\\
\mathbf{elif}\;\varepsilon \leq 1.3314514851199195 \cdot 10^{-51}:\\
\;\;\;\;x \cdot \left(\varepsilon \cdot \varepsilon\right) + \left(\varepsilon + \varepsilon \cdot \left(x \cdot x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \left(\tan x \cdot \tan x\right) \cdot \left(\tan \varepsilon \cdot \tan \varepsilon\right)} \cdot \left(1 + \tan x \cdot \tan \varepsilon\right) - \tan x\\
\end{array}(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
(FPCore (x eps)
:precision binary64
(if (<= eps -2.3047993601266133e-36)
(/
(-
(*
(cos x)
(*
(+ (tan x) (tan eps))
(- 1.0 (* (* (tan x) (tan eps)) (* (tan x) (tan eps))))))
(*
(sin x)
(*
(- 1.0 (* (* (tan x) (tan eps)) (* (tan x) (tan eps))))
(- 1.0 (* (tan x) (tan eps))))))
(*
(cos x)
(*
(- 1.0 (* (* (tan x) (tan eps)) (* (tan x) (tan eps))))
(- 1.0 (* (tan x) (tan eps))))))
(if (<= eps 1.3314514851199195e-51)
(+ (* x (* eps eps)) (+ eps (* eps (* x x))))
(-
(*
(/
(+ (tan x) (tan eps))
(- 1.0 (* (* (tan x) (tan x)) (* (tan eps) (tan eps)))))
(+ 1.0 (* (tan x) (tan eps))))
(tan x)))))double code(double x, double eps) {
return ((double) (((double) tan(((double) (x + eps)))) - ((double) tan(x))));
}
double code(double x, double eps) {
double tmp;
if ((eps <= -2.3047993601266133e-36)) {
tmp = (((double) (((double) (((double) cos(x)) * ((double) (((double) (((double) tan(x)) + ((double) tan(eps)))) * ((double) (1.0 - ((double) (((double) (((double) tan(x)) * ((double) tan(eps)))) * ((double) (((double) tan(x)) * ((double) tan(eps)))))))))))) - ((double) (((double) sin(x)) * ((double) (((double) (1.0 - ((double) (((double) (((double) tan(x)) * ((double) tan(eps)))) * ((double) (((double) tan(x)) * ((double) tan(eps)))))))) * ((double) (1.0 - ((double) (((double) tan(x)) * ((double) tan(eps)))))))))))) / ((double) (((double) cos(x)) * ((double) (((double) (1.0 - ((double) (((double) (((double) tan(x)) * ((double) tan(eps)))) * ((double) (((double) tan(x)) * ((double) tan(eps)))))))) * ((double) (1.0 - ((double) (((double) tan(x)) * ((double) tan(eps)))))))))));
} else {
double tmp_1;
if ((eps <= 1.3314514851199195e-51)) {
tmp_1 = ((double) (((double) (x * ((double) (eps * eps)))) + ((double) (eps + ((double) (eps * ((double) (x * x))))))));
} else {
tmp_1 = ((double) (((double) ((((double) (((double) tan(x)) + ((double) tan(eps)))) / ((double) (1.0 - ((double) (((double) (((double) tan(x)) * ((double) tan(x)))) * ((double) (((double) tan(eps)) * ((double) tan(eps))))))))) * ((double) (1.0 + ((double) (((double) tan(x)) * ((double) tan(eps)))))))) - ((double) tan(x))));
}
tmp = tmp_1;
}
return tmp;
}




Bits error versus x




Bits error versus eps
Results
| Original | 37.5 |
|---|---|
| Target | 15.4 |
| Herbie | 15.7 |
if eps < -2.3047993601266133e-36Initial program 30.4
rmApplied tan-sum_binary642.8
rmApplied flip--_binary642.9
Applied associate-/r/_binary642.9
Simplified2.9
rmApplied tan-quot_binary642.9
Applied flip-+_binary642.9
Applied frac-times_binary642.9
Applied frac-sub_binary642.9
Simplified2.9
Simplified2.9
if -2.3047993601266133e-36 < eps < 1.3314514851199195e-51Initial program 46.8
rmApplied tan-sum_binary6446.8
rmApplied flip--_binary6446.8
Applied associate-/r/_binary6446.8
Simplified46.8
Taylor expanded around 0 31.8
Simplified31.8
if 1.3314514851199195e-51 < eps Initial program 30.5
rmApplied tan-sum_binary644.1
rmApplied flip--_binary644.1
Applied associate-/r/_binary644.1
Simplified4.1
rmApplied swap-sqr_binary644.1
Final simplification15.7
herbie shell --seed 2020210
(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)))