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




Bits error versus x




Bits error versus eps
Results
| Original | 36.8 |
|---|---|
| Target | 15.2 |
| Herbie | 15.1 |
if eps < -1.9309342815525819e-97Initial program 31.0
rmApplied tan-sum_binary647.9
rmApplied flip--_binary647.9
Applied associate-/r/_binary647.9
Simplified7.9
rmApplied tan-quot_binary647.9
Applied associate-*l/_binary647.9
Applied frac-sub_binary647.9
Simplified7.9
if -1.9309342815525819e-97 < eps < 6.878727405827355e-23Initial program 46.2
Taylor expanded around 0 30.1
Simplified29.9
if 6.878727405827355e-23 < eps Initial program 30.0
rmApplied tan-sum_binary641.8
rmApplied tan-quot_binary642.0
Applied tan-quot_binary642.0
Applied frac-add_binary642.0
Applied associate-/l/_binary642.0
Final simplification15.1
herbie shell --seed 2020224
(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)))