\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -4.521195450558315 \cdot 10^{-70}:\\
\;\;\;\;\frac{{\tan x}^{3} + {\tan \varepsilon}^{3}}{\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan x + \tan \varepsilon \cdot \left(\tan \varepsilon - \tan x\right)\right)} - \tan x\\
\mathbf{elif}\;\varepsilon \leq 4.907363205004435 \cdot 10^{-32}:\\
\;\;\;\;\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 -4.521195450558315e-70)
(-
(/
(+ (pow (tan x) 3.0) (pow (tan eps) 3.0))
(*
(- 1.0 (* (tan x) (tan eps)))
(+ (* (tan x) (tan x)) (* (tan eps) (- (tan eps) (tan x))))))
(tan x))
(if (<= eps 4.907363205004435e-32)
(+ 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 <= -4.521195450558315e-70) {
tmp = ((pow(tan(x), 3.0) + pow(tan(eps), 3.0)) / ((1.0 - (tan(x) * tan(eps))) * ((tan(x) * tan(x)) + (tan(eps) * (tan(eps) - tan(x)))))) - tan(x);
} else if (eps <= 4.907363205004435e-32) {
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 < -4.5211954505583148e-70Initial program 31.1
rmApplied tan-sum_binary64_15575.9
rmApplied flip3-+_binary64_14286.1
Applied associate-/l/_binary64_13746.1
Simplified6.1
if -4.5211954505583148e-70 < eps < 4.90736320500443476e-32Initial program 45.4
Taylor expanded around 0 31.0
Simplified30.8
if 4.90736320500443476e-32 < eps Initial program 29.7
rmApplied tan-sum_binary64_15572.2
rmApplied flip--_binary64_14002.2
Applied associate-/r/_binary64_13732.2
Simplified2.2
rmApplied tan-quot_binary64_15812.3
Applied associate-*l/_binary64_13702.3
Applied frac-sub_binary64_14342.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)))