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




Bits error versus x




Bits error versus eps
| Original | 37.3 |
|---|---|
| Target | 15.3 |
| Herbie | 0.3 |
if eps < -2.1428030927760745e-4Initial program 30.4
Applied tan-sum_binary640.4
Applied add-log-exp_binary640.4
Simplified0.5
if -2.1428030927760745e-4 < eps < 2.38116823070516035e-4Initial program 44.8
Taylor expanded in eps around 0 0.2
Simplified0.2
if 2.38116823070516035e-4 < eps Initial program 29.8
Applied tan-sum_binary640.4
Applied add-cube-cbrt_binary640.7
Applied flip--_binary640.7
Applied associate-/r/_binary640.7
Applied prod-diff_binary640.7
Simplified0.4
Simplified0.4
Final simplification0.3
herbie shell --seed 2022068
(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)))