\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
t_0 := \tan x + \tan \varepsilon\\
t_1 := \tan x \cdot \tan \varepsilon\\
\mathbf{if}\;\varepsilon \leq -0.00020782601609953486:\\
\;\;\;\;\mathsf{fma}\left(t_0, \frac{1}{1 - t_1 \cdot t_1} \cdot \left(1 + t_1\right), -\tan x\right)\\
\mathbf{elif}\;\varepsilon \leq 0.00044940075034421095:\\
\;\;\;\;\begin{array}{l}
t_2 := {\sin x}^{3}\\
t_3 := {\sin x}^{2}\\
t_4 := {\cos x}^{2}\\
t_5 := {\cos x}^{3}\\
\frac{{\varepsilon}^{2} \cdot t_2}{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_2 \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_3}{t_4} + \left(\frac{\varepsilon \cdot t_3}{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}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\sin x, t_1 + -1, t_0 \cdot \cos x\right)}{\cos x \cdot \left(1 - t_1\right)}\\
\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) (tan eps))))
(if (<= eps -0.00020782601609953486)
(fma t_0 (* (/ 1.0 (- 1.0 (* t_1 t_1))) (+ 1.0 t_1)) (- (tan x)))
(if (<= eps 0.00044940075034421095)
(let* ((t_2 (pow (sin x) 3.0))
(t_3 (pow (sin x) 2.0))
(t_4 (pow (cos x) 2.0))
(t_5 (pow (cos x) 3.0)))
(+
(/ (* (pow eps 2.0) t_2) 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_2 (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_3) t_4))
(+
(/ (* eps t_3) t_4)
(+
(* 0.6666666666666666 (/ (* (sin x) (pow eps 4.0)) (cos x)))
(* (pow eps 3.0) 0.3333333333333333)))))))))))
(/
(fma (sin x) (+ t_1 -1.0) (* t_0 (cos x)))
(* (cos x) (- 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) * tan(eps);
double tmp;
if (eps <= -0.00020782601609953486) {
tmp = fma(t_0, ((1.0 / (1.0 - (t_1 * t_1))) * (1.0 + t_1)), -tan(x));
} else if (eps <= 0.00044940075034421095) {
double t_2 = pow(sin(x), 3.0);
double t_3 = pow(sin(x), 2.0);
double t_4 = pow(cos(x), 2.0);
double t_5 = pow(cos(x), 3.0);
tmp = ((pow(eps, 2.0) * t_2) / 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_2 * 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_3) / t_4)) + (((eps * t_3) / t_4) + ((0.6666666666666666 * ((sin(x) * pow(eps, 4.0)) / cos(x))) + (pow(eps, 3.0) * 0.3333333333333333)))))))));
} else {
tmp = fma(sin(x), (t_1 + -1.0), (t_0 * cos(x))) / (cos(x) * (1.0 - t_1));
}
return tmp;
}




Bits error versus x




Bits error versus eps
| Original | 37.1 |
|---|---|
| Target | 15.1 |
| Herbie | 0.3 |
if eps < -2.07826016099534858e-4Initial program 29.9
Applied tan-sum_binary640.3
Applied div-inv_binary640.3
Applied fma-neg_binary640.3
Applied flip--_binary640.4
Applied associate-/r/_binary640.4
Simplified0.4
if -2.07826016099534858e-4 < eps < 4.49400750344210946e-4Initial program 44.7
Taylor expanded in eps around 0 0.2
if 4.49400750344210946e-4 < eps Initial program 29.5
Applied tan-quot_binary6429.4
Applied tan-sum_binary640.4
Applied frac-sub_binary640.4
Simplified0.4
Simplified0.4
Final simplification0.3
herbie shell --seed 2021215
(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)))