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




Bits error versus x




Bits error versus eps
| Original | 36.6 |
|---|---|
| Target | 15.2 |
| Herbie | 0.3 |
if eps < -2.1560437678393656e-4Initial program 29.5
Applied tan-sum_binary640.3
Applied div-inv_binary640.4
Applied *-commutative_binary640.4
if -2.1560437678393656e-4 < eps < 3.12301277159240454e-4Initial program 44.2
Taylor expanded in eps around 0 0.2
Simplified0.2
if 3.12301277159240454e-4 < eps Initial program 29.5
Applied tan-sum_binary640.3
Applied +-commutative_binary640.3
Final simplification0.3
herbie shell --seed 2021357
(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)))