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




Bits error versus x




Bits error versus eps
| Original | 36.5 |
|---|---|
| Target | 14.6 |
| Herbie | 0.3 |
if eps < -2.79617962064203872e-4Initial program 28.7
Applied tan-sum_binary640.3
Applied flip--_binary640.4
Applied associate-/r/_binary640.4
Applied fma-neg_binary640.4
if -2.79617962064203872e-4 < eps < 2.3084122125612065e-4Initial program 44.2
Taylor expanded in eps around 0 0.2
if 2.3084122125612065e-4 < eps Initial program 29.1
Applied tan-sum_binary640.3
Applied tan-quot_binary640.3
Applied associate-*r/_binary640.3
Applied add-cube-cbrt_binary640.7
Applied flip3--_binary640.7
Applied associate-/r/_binary640.7
Applied prod-diff_binary640.7
Simplified0.4
Simplified0.4
Final simplification0.3
herbie shell --seed 2022081
(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)))