\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -6.951010323486192 \cdot 10^{-59}:\\
\;\;\;\;\frac{\frac{\tan x \cdot \tan x - \tan \varepsilon \cdot \tan \varepsilon}{\tan x - \tan \varepsilon}}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\
\mathbf{elif}\;\varepsilon \leq 4.0501768016039094 \cdot 10^{-42}:\\
\;\;\;\;\varepsilon + \left(\varepsilon + x\right) \cdot \left(\varepsilon \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \left(\sqrt[3]{\tan x} \cdot \sqrt[3]{\tan x}\right) \cdot \left(\tan \varepsilon \cdot \sqrt[3]{\tan x}\right)} - \tan x\\
\end{array}(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
(FPCore (x eps)
:precision binary64
(if (<= eps -6.951010323486192e-59)
(-
(/
(/ (- (* (tan x) (tan x)) (* (tan eps) (tan eps))) (- (tan x) (tan eps)))
(- 1.0 (* (tan x) (tan eps))))
(tan x))
(if (<= eps 4.0501768016039094e-42)
(+ eps (* (+ eps x) (* eps x)))
(-
(/
(+ (tan x) (tan eps))
(-
1.0
(* (* (cbrt (tan x)) (cbrt (tan x))) (* (tan eps) (cbrt (tan x))))))
(tan x)))))double code(double x, double eps) {
return tan(x + eps) - tan(x);
}
double code(double x, double eps) {
double tmp;
if (eps <= -6.951010323486192e-59) {
tmp = ((((tan(x) * tan(x)) - (tan(eps) * tan(eps))) / (tan(x) - tan(eps))) / (1.0 - (tan(x) * tan(eps)))) - tan(x);
} else if (eps <= 4.0501768016039094e-42) {
tmp = eps + ((eps + x) * (eps * x));
} else {
tmp = ((tan(x) + tan(eps)) / (1.0 - ((cbrt(tan(x)) * cbrt(tan(x))) * (tan(eps) * cbrt(tan(x)))))) - tan(x);
}
return tmp;
}




Bits error versus x




Bits error versus eps
Results
| Original | 36.5 |
|---|---|
| Target | 15.0 |
| Herbie | 15.1 |
if eps < -6.95101032348619227e-59Initial program 29.9
rmApplied tan-sum_binary64_15774.7
rmApplied flip-+_binary64_14164.7
if -6.95101032348619227e-59 < eps < 4.0501768016039094e-42Initial program 46.2
Taylor expanded around 0 30.9
Simplified30.7
if 4.0501768016039094e-42 < eps Initial program 29.5
rmApplied tan-sum_binary64_15773.4
rmApplied add-cube-cbrt_binary64_14773.5
Applied associate-*l*_binary64_13833.5
Simplified3.5
Final simplification15.1
herbie shell --seed 2020354
(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)))