\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
t_0 := \tan x + \tan \varepsilon\\
\mathbf{if}\;\varepsilon \leq -9.830087725539631 \cdot 10^{-5}:\\
\;\;\;\;\begin{array}{l}
t_1 := \tan x \cdot \tan \varepsilon\\
\mathsf{fma}\left(\frac{t_0}{1 - {t_1}^{3}}, 1 + \left(t_1 \cdot t_1 + \log \left({\left(e^{\tan x}\right)}^{\tan \varepsilon}\right)\right), -\tan x\right)
\end{array}\\
\mathbf{elif}\;\varepsilon \leq 0.0002654352846451175:\\
\;\;\;\;\begin{array}{l}
t_2 := {\sin x}^{2}\\
t_3 := {\cos x}^{2}\\
t_4 := \frac{\cos x}{\sin x}\\
\left(\varepsilon + \left(\frac{{\varepsilon}^{3}}{{t_4}^{4}} + \mathsf{fma}\left(1.6666666666666667, \frac{{\varepsilon}^{4}}{{t_4}^{3}}, \mathsf{fma}\left(\frac{{\varepsilon}^{4}}{{\cos x}^{5}}, {\sin x}^{5}, \mathsf{fma}\left(1.3333333333333333, \frac{{\varepsilon}^{3} \cdot t_2}{t_3}, \mathsf{fma}\left(\varepsilon, \frac{t_2}{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)
\end{array}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{1 - \frac{\frac{\sin x \cdot \sin \varepsilon}{\cos x}}{\cos \varepsilon}} - \tan x\\
\end{array}
(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (tan x) (tan eps))))
(if (<= eps -9.830087725539631e-5)
(let* ((t_1 (* (tan x) (tan eps))))
(fma
(/ t_0 (- 1.0 (pow t_1 3.0)))
(+ 1.0 (+ (* t_1 t_1) (log (pow (exp (tan x)) (tan eps)))))
(- (tan x))))
(if (<= eps 0.0002654352846451175)
(let* ((t_2 (pow (sin x) 2.0))
(t_3 (pow (cos x) 2.0))
(t_4 (/ (cos x) (sin x))))
(+
(+
eps
(+
(/ (pow eps 3.0) (pow t_4 4.0))
(fma
1.6666666666666667
(/ (pow eps 4.0) (pow t_4 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_2) t_3)
(fma
eps
(/ t_2 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)))))
(-
(/ t_0 (- 1.0 (/ (/ (* (sin x) (sin eps)) (cos x)) (cos eps))))
(tan x))))))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 tmp;
if (eps <= -9.830087725539631e-5) {
double t_1_1 = tan(x) * tan(eps);
tmp = fma((t_0 / (1.0 - pow(t_1_1, 3.0))), (1.0 + ((t_1_1 * t_1_1) + log(pow(exp(tan(x)), tan(eps))))), -tan(x));
} else if (eps <= 0.0002654352846451175) {
double t_2 = pow(sin(x), 2.0);
double t_3 = pow(cos(x), 2.0);
double t_4 = cos(x) / sin(x);
tmp = (eps + ((pow(eps, 3.0) / pow(t_4, 4.0)) + fma(1.6666666666666667, (pow(eps, 4.0) / pow(t_4, 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_2) / t_3), fma(eps, (t_2 / 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 = (t_0 / (1.0 - (((sin(x) * sin(eps)) / cos(x)) / cos(eps)))) - tan(x);
}
return tmp;
}




Bits error versus x




Bits error versus eps
| Original | 37.3 |
|---|---|
| Target | 15.2 |
| Herbie | 0.4 |
if eps < -9.830087725539631e-5Initial program 30.2
Applied tan-sum_binary640.4
Applied flip3--_binary640.4
Applied associate-/r/_binary640.4
Applied fma-neg_binary640.4
Applied add-log-exp_binary640.6
Simplified0.6
if -9.830087725539631e-5 < eps < 2.6543528464511749e-4Initial program 45.3
Taylor expanded in eps around 0 0.2
Simplified0.2
if 2.6543528464511749e-4 < eps Initial program 29.2
Applied tan-sum_binary640.3
Applied tan-quot_binary640.4
Applied tan-quot_binary640.4
Applied frac-times_binary640.4
Applied associate-/r*_binary640.4
Final simplification0.4
herbie shell --seed 2022088
(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)))