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




Bits error versus x




Bits error versus eps
Results
| Original | 37.7 |
|---|---|
| Target | 15.3 |
| Herbie | 15.5 |
if eps < -7.780852968026817e-23Initial program 30.3
rmApplied tan-quot_binary64_160130.2
Applied tan-sum_binary64_15771.8
Applied frac-sub_binary64_14511.8
if -7.780852968026817e-23 < eps < 1.66941134976348841e-59Initial program 46.9
Taylor expanded around 0 31.4
Simplified31.2
if 1.66941134976348841e-59 < eps Initial program 30.8
rmApplied tan-sum_binary64_15775.2
rmApplied flip3--_binary64_14465.2
Applied associate-/r/_binary64_13885.2
Simplified5.2
rmApplied tan-quot_binary64_16015.2
Applied associate-*r/_binary64_13845.2
Applied associate-*l/_binary64_13855.2
Simplified5.2
Final simplification15.5
herbie shell --seed 2020356
(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)))