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




Bits error versus x




Bits error versus eps
Results
| Original | 37.0 |
|---|---|
| Target | 15.2 |
| Herbie | 0.3 |
if eps < -2.1473042784006286e-4Initial program 29.9
Applied tan-sum_binary640.3
Applied add-log-exp_binary640.4
Applied add-log-exp_binary640.4
Applied diff-log_binary640.5
Simplified0.4
Applied *-un-lft-identity_binary640.4
if -2.1473042784006286e-4 < eps < 2.1168417335995959e-4Initial program 44.6
Taylor expanded in eps around 0 0.2
if 2.1168417335995959e-4 < eps Initial program 29.3
Applied tan-sum_binary640.3
Applied tan-quot_binary640.4
Applied associate-*l/_binary640.4
Applied add-log-exp_binary640.5
Simplified0.5
Final simplification0.3
herbie shell --seed 2022104
(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)))