\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -2.5520522219363244 \cdot 10^{-74}:\\
\;\;\;\;\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\
\mathbf{elif}\;\varepsilon \leq 1.455759342729981 \cdot 10^{-31}:\\
\;\;\;\;\varepsilon + \left(\varepsilon + x\right) \cdot \left(\varepsilon \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\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)}\\
\end{array}(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
(FPCore (x eps)
:precision binary64
(if (<= eps -2.5520522219363244e-74)
(- (* (+ (tan x) (tan eps)) (/ 1.0 (- 1.0 (* (tan x) (tan eps))))) (tan x))
(if (<= eps 1.455759342729981e-31)
(+ eps (* (+ eps x) (* eps x)))
(/
(-
(* (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)))))))))double code(double x, double eps) {
return tan(x + eps) - tan(x);
}
double code(double x, double eps) {
double tmp;
if (eps <= -2.5520522219363244e-74) {
tmp = ((tan(x) + tan(eps)) * (1.0 / (1.0 - (tan(x) * tan(eps))))) - tan(x);
} else if (eps <= 1.455759342729981e-31) {
tmp = eps + ((eps + x) * (eps * x));
} else {
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)))));
}
return tmp;
}




Bits error versus x




Bits error versus eps
Results
| Original | 36.6 |
|---|---|
| Target | 15.3 |
| Herbie | 15.3 |
if eps < -2.55205222193632443e-74Initial program 31.0
rmApplied tan-sum_binary64_19346.2
rmApplied div-inv_binary64_17966.2
if -2.55205222193632443e-74 < eps < 1.455759342729981e-31Initial program 45.5
Taylor expanded around 0 31.1
Simplified30.9
if 1.455759342729981e-31 < eps Initial program 29.7
rmApplied tan-sum_binary64_19342.2
rmApplied flip--_binary64_17742.2
Applied associate-/r/_binary64_17452.2
Simplified2.2
rmApplied tan-quot_binary64_19582.3
Applied associate-*l/_binary64_17422.3
Applied frac-sub_binary64_18082.3
Simplified2.3
Final simplification15.3
herbie shell --seed 2020288
(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)))