\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
t_0 := \cos \varepsilon \cdot \cos x\\
t_1 := \tan x + \tan \varepsilon\\
\mathbf{if}\;\varepsilon \leq -7.034024772968383 \cdot 10^{-5}:\\
\;\;\;\;\begin{array}{l}
t_2 := -\tan x\\
\mathsf{fma}\left(t_1, \frac{1}{1 - \frac{\sin x \cdot \sin \varepsilon}{t_0}}, t_2\right) + \mathsf{fma}\left(t_2, 1, \tan x\right)
\end{array}\\
\mathbf{elif}\;\varepsilon \leq 3.5100561387016338 \cdot 10^{-31}:\\
\;\;\;\;\begin{array}{l}
t_3 := {\sin x}^{2}\\
t_4 := {\cos x}^{2}\\
\left(\frac{{\varepsilon}^{3} \cdot {\sin x}^{4}}{{\cos x}^{4}} + \left(\mathsf{fma}\left(\varepsilon, \frac{t_3}{t_4}, \varepsilon\right) + \mathsf{fma}\left(1.3333333333333333, \frac{{\varepsilon}^{3} \cdot t_3}{t_4}, {\varepsilon}^{3} \cdot 0.3333333333333333\right)\right)\right) + \frac{\varepsilon \cdot \varepsilon}{\cos x} \cdot \left(\sin x + \frac{{\sin x}^{3}}{t_4}\right)
\end{array}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_1}{1 - \sin \varepsilon \cdot \frac{\sin x}{t_0}} - \tan x\\
\end{array}
(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* (cos eps) (cos x))) (t_1 (+ (tan x) (tan eps))))
(if (<= eps -7.034024772968383e-5)
(let* ((t_2 (- (tan x))))
(+
(fma t_1 (/ 1.0 (- 1.0 (/ (* (sin x) (sin eps)) t_0))) t_2)
(fma t_2 1.0 (tan x))))
(if (<= eps 3.5100561387016338e-31)
(let* ((t_3 (pow (sin x) 2.0)) (t_4 (pow (cos x) 2.0)))
(+
(+
(/ (* (pow eps 3.0) (pow (sin x) 4.0)) (pow (cos x) 4.0))
(+
(fma eps (/ t_3 t_4) eps)
(fma
1.3333333333333333
(/ (* (pow eps 3.0) t_3) t_4)
(* (pow eps 3.0) 0.3333333333333333))))
(* (/ (* eps eps) (cos x)) (+ (sin x) (/ (pow (sin x) 3.0) t_4)))))
(- (/ t_1 (- 1.0 (* (sin eps) (/ (sin x) t_0)))) (tan x))))))double code(double x, double eps) {
return tan(x + eps) - tan(x);
}
double code(double x, double eps) {
double t_0 = cos(eps) * cos(x);
double t_1 = tan(x) + tan(eps);
double tmp;
if (eps <= -7.034024772968383e-5) {
double t_2_1 = -tan(x);
tmp = fma(t_1, (1.0 / (1.0 - ((sin(x) * sin(eps)) / t_0))), t_2_1) + fma(t_2_1, 1.0, tan(x));
} else if (eps <= 3.5100561387016338e-31) {
double t_3 = pow(sin(x), 2.0);
double t_4 = pow(cos(x), 2.0);
tmp = (((pow(eps, 3.0) * pow(sin(x), 4.0)) / pow(cos(x), 4.0)) + (fma(eps, (t_3 / t_4), eps) + fma(1.3333333333333333, ((pow(eps, 3.0) * t_3) / t_4), (pow(eps, 3.0) * 0.3333333333333333)))) + (((eps * eps) / cos(x)) * (sin(x) + (pow(sin(x), 3.0) / t_4)));
} else {
tmp = (t_1 / (1.0 - (sin(eps) * (sin(x) / t_0)))) - tan(x);
}
return tmp;
}




Bits error versus x




Bits error versus eps
| Original | 37.1 |
|---|---|
| Target | 15.6 |
| Herbie | 1.0 |
if eps < -7.0340247729683834e-5Initial program 30.3
Applied tan-sum_binary640.3
Taylor expanded in x around inf 0.4
Applied *-un-lft-identity_binary640.4
Applied div-inv_binary640.4
Applied prod-diff_binary640.4
if -7.0340247729683834e-5 < eps < 3.5100561387016338e-31Initial program 45.2
Applied tan-sum_binary6444.8
Taylor expanded in eps around 0 0.2
Simplified0.2
if 3.5100561387016338e-31 < eps Initial program 30.1
Applied tan-sum_binary642.8
Taylor expanded in x around inf 2.8
Applied associate-/l*_binary642.9
Applied associate-/r/_binary642.8
Final simplification1.0
herbie shell --seed 2021224
(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)))