\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
t_0 := {\sin x}^{3}\\
t_1 := {\cos x}^{2}\\
t_2 := {\cos x}^{3}\\
t_3 := \tan x \cdot \tan \varepsilon\\
t_4 := \tan x + \tan \varepsilon\\
t_5 := {\sin x}^{2}\\
\mathbf{if}\;\varepsilon \leq -0.00020625213391552245:\\
\;\;\;\;\frac{t_4}{1 - t_3} - \tan x\\
\mathbf{elif}\;\varepsilon \leq 6.687244365865793 \cdot 10^{-5}:\\
\;\;\;\;\frac{{\varepsilon}^{2} \cdot t_0}{t_2} + \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_0 \cdot {\varepsilon}^{4}}{t_2} + \left(\frac{{\varepsilon}^{4} \cdot {\sin x}^{5}}{{\cos x}^{5}} + \left(1.3333333333333333 \cdot \frac{{\varepsilon}^{3} \cdot t_5}{t_1} + \left(\frac{\varepsilon \cdot t_5}{t_1} + \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)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t_4, \frac{1}{1 - \sqrt[3]{{t_3}^{3}}}, -\tan x\right)\\
\end{array}
(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
(FPCore (x eps)
:precision binary64
(let* ((t_0 (pow (sin x) 3.0))
(t_1 (pow (cos x) 2.0))
(t_2 (pow (cos x) 3.0))
(t_3 (* (tan x) (tan eps)))
(t_4 (+ (tan x) (tan eps)))
(t_5 (pow (sin x) 2.0)))
(if (<= eps -0.00020625213391552245)
(- (/ t_4 (- 1.0 t_3)) (tan x))
(if (<= eps 6.687244365865793e-5)
(+
(/ (* (pow eps 2.0) t_0) t_2)
(+
(/ (* (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_0 (pow eps 4.0)) t_2))
(+
(/ (* (pow eps 4.0) (pow (sin x) 5.0)) (pow (cos x) 5.0))
(+
(* 1.3333333333333333 (/ (* (pow eps 3.0) t_5) t_1))
(+
(/ (* eps t_5) t_1)
(+
(* 0.6666666666666666 (/ (* (sin x) (pow eps 4.0)) (cos x)))
(* (pow eps 3.0) 0.3333333333333333))))))))))
(fma t_4 (/ 1.0 (- 1.0 (cbrt (pow t_3 3.0)))) (- (tan x)))))))double code(double x, double eps) {
return tan((x + eps)) - tan(x);
}
double code(double x, double eps) {
double t_0 = pow(sin(x), 3.0);
double t_1 = pow(cos(x), 2.0);
double t_2 = pow(cos(x), 3.0);
double t_3 = tan(x) * tan(eps);
double t_4 = tan(x) + tan(eps);
double t_5 = pow(sin(x), 2.0);
double tmp;
if (eps <= -0.00020625213391552245) {
tmp = (t_4 / (1.0 - t_3)) - tan(x);
} else if (eps <= 6.687244365865793e-5) {
tmp = ((pow(eps, 2.0) * t_0) / t_2) + (((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_0 * pow(eps, 4.0)) / t_2)) + (((pow(eps, 4.0) * pow(sin(x), 5.0)) / pow(cos(x), 5.0)) + ((1.3333333333333333 * ((pow(eps, 3.0) * t_5) / t_1)) + (((eps * t_5) / t_1) + ((0.6666666666666666 * ((sin(x) * pow(eps, 4.0)) / cos(x))) + (pow(eps, 3.0) * 0.3333333333333333)))))))));
} else {
tmp = fma(t_4, (1.0 / (1.0 - cbrt(pow(t_3, 3.0)))), -tan(x));
}
return tmp;
}




Bits error versus x




Bits error versus eps
| Original | 36.7 |
|---|---|
| Target | 15.0 |
| Herbie | 0.3 |
if eps < -2.06252133915522446e-4Initial program 29.1
Applied egg-rr0.4
if -2.06252133915522446e-4 < eps < 6.687244365865793e-5Initial program 44.2
Taylor expanded in eps around 0 0.2
if 6.687244365865793e-5 < eps Initial program 29.6
Applied egg-rr0.4
Applied egg-rr0.4
Final simplification0.3
herbie shell --seed 2022129
(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)))