\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
t_0 := \tan x \cdot \tan \varepsilon\\
t_1 := {\sin x}^{2}\\
t_2 := -\tan x\\
t_3 := {\cos x}^{2}\\
\mathbf{if}\;\varepsilon \leq -0.00022498455180266905:\\
\;\;\;\;\mathsf{fma}\left(\frac{\tan x + \tan \varepsilon}{1 - \tan \varepsilon \cdot \left(\tan x \cdot t_0\right)}, \mathsf{fma}\left(\tan x, \tan \varepsilon, 1\right), t_2\right)\\
\mathbf{elif}\;\varepsilon \leq 2.941971583774042 \cdot 10^{-26}:\\
\;\;\;\;\left(\varepsilon + \mathsf{fma}\left(\frac{{\varepsilon}^{3}}{{\cos x}^{4}}, {\sin x}^{4}, \mathsf{fma}\left(1.6666666666666667, \frac{{\varepsilon}^{4}}{{\left(\frac{\cos x}{\sin x}\right)}^{3}}, \mathsf{fma}\left(\frac{{\varepsilon}^{4}}{{\cos x}^{5}}, {\sin x}^{5}, \mathsf{fma}\left(1.3333333333333333, \frac{{\varepsilon}^{3} \cdot t_1}{t_3}, \mathsf{fma}\left(\varepsilon, \frac{t_1}{t_3}, \mathsf{fma}\left(0.3333333333333333, {\varepsilon}^{3}, 0.6666666666666666 \cdot \left({\varepsilon}^{4} \cdot \frac{\sin x}{\cos x}\right)\right)\right)\right)\right)\right)\right)\right) + \frac{\varepsilon \cdot \varepsilon}{\cos x} \cdot \left(\sin x + \frac{{\sin x}^{3}}{t_3}\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{\frac{\tan x - \tan \varepsilon}{{\tan x}^{2} - {\tan \varepsilon}^{2}}}, \frac{1}{1 - t_0}, t_2\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 (pow (sin x) 2.0))
(t_2 (- (tan x)))
(t_3 (pow (cos x) 2.0)))
(if (<= eps -0.00022498455180266905)
(fma
(/ (+ (tan x) (tan eps)) (- 1.0 (* (tan eps) (* (tan x) t_0))))
(fma (tan x) (tan eps) 1.0)
t_2)
(if (<= eps 2.941971583774042e-26)
(+
(+
eps
(fma
(/ (pow eps 3.0) (pow (cos x) 4.0))
(pow (sin x) 4.0)
(fma
1.6666666666666667
(/ (pow eps 4.0) (pow (/ (cos x) (sin x)) 3.0))
(fma
(/ (pow eps 4.0) (pow (cos x) 5.0))
(pow (sin x) 5.0)
(fma
1.3333333333333333
(/ (* (pow eps 3.0) t_1) t_3)
(fma
eps
(/ t_1 t_3)
(fma
0.3333333333333333
(pow eps 3.0)
(*
0.6666666666666666
(* (pow eps 4.0) (/ (sin x) (cos x)))))))))))
(* (/ (* eps eps) (cos x)) (+ (sin x) (/ (pow (sin x) 3.0) t_3))))
(fma
(/
1.0
(/ (- (tan x) (tan eps)) (- (pow (tan x) 2.0) (pow (tan eps) 2.0))))
(/ 1.0 (- 1.0 t_0))
t_2)))))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 = pow(sin(x), 2.0);
double t_2 = -tan(x);
double t_3 = pow(cos(x), 2.0);
double tmp;
if (eps <= -0.00022498455180266905) {
tmp = fma(((tan(x) + tan(eps)) / (1.0 - (tan(eps) * (tan(x) * t_0)))), fma(tan(x), tan(eps), 1.0), t_2);
} else if (eps <= 2.941971583774042e-26) {
tmp = (eps + fma((pow(eps, 3.0) / pow(cos(x), 4.0)), pow(sin(x), 4.0), fma(1.6666666666666667, (pow(eps, 4.0) / pow((cos(x) / sin(x)), 3.0)), fma((pow(eps, 4.0) / pow(cos(x), 5.0)), pow(sin(x), 5.0), fma(1.3333333333333333, ((pow(eps, 3.0) * t_1) / t_3), fma(eps, (t_1 / t_3), fma(0.3333333333333333, pow(eps, 3.0), (0.6666666666666666 * (pow(eps, 4.0) * (sin(x) / cos(x))))))))))) + (((eps * eps) / cos(x)) * (sin(x) + (pow(sin(x), 3.0) / t_3)));
} else {
tmp = fma((1.0 / ((tan(x) - tan(eps)) / (pow(tan(x), 2.0) - pow(tan(eps), 2.0)))), (1.0 / (1.0 - t_0)), t_2);
}
return tmp;
}




Bits error versus x




Bits error versus eps
| Original | 37.3 |
|---|---|
| Target | 15.0 |
| Herbie | 0.7 |
if eps < -2.2498455180266905e-4Initial program 30.5
Applied egg-rr0.4
Applied egg-rr0.4
Applied egg-rr0.4
if -2.2498455180266905e-4 < eps < 2.9419715837740421e-26Initial program 45.0
Taylor expanded in eps around 0 0.2
Simplified0.2
if 2.9419715837740421e-26 < eps Initial program 29.7
Applied egg-rr1.9
Applied egg-rr2.1
Final simplification0.7
herbie shell --seed 2022130
(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)))