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




Bits error versus x




Bits error versus eps
Results
| Original | 37.1 |
|---|---|
| Target | 15.2 |
| Herbie | 16.1 |
if eps < -2.5888280122113803e-20Initial program 29.8
rmApplied tan-sum_binary64_19181.2
rmApplied tan-quot_binary64_19421.2
Applied associate-*l/_binary64_17261.2
Simplified1.2
if -2.5888280122113803e-20 < eps < 7.3355942566528652e-147Initial program 46.7
Taylor expanded around 0 31.2
Simplified31.0
if 7.3355942566528652e-147 < eps Initial program 32.7
rmApplied tan-sum_binary64_191811.9
rmApplied add-cbrt-cube_binary64_181911.9
Simplified11.9
Final simplification16.1
herbie shell --seed 2020343
(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)))