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




Bits error versus x




Bits error versus eps
| Original | 36.5 |
|---|---|
| Target | 15.1 |
| Herbie | 0.3 |
if eps < -2.36802882343764439e-5Initial program 29.2
Applied tan-sum_binary640.4
Applied div-inv_binary640.4
Applied fma-neg_binary640.4
if -2.36802882343764439e-5 < eps < 5.95430330667414047e-5Initial program 44.2
Taylor expanded in eps around 0 0.2
Simplified0.2
if 5.95430330667414047e-5 < eps Initial program 29.3
Applied tan-sum_binary640.3
Applied add-cube-cbrt_binary640.7
Applied flip--_binary640.7
Applied associate-/r/_binary640.7
Applied prod-diff_binary640.7
Simplified0.4
Simplified0.4
Applied tan-quot_binary640.4
Applied tan-quot_binary640.4
Applied frac-times_binary640.4
Applied tan-quot_binary640.4
Applied tan-quot_binary640.5
Applied frac-times_binary640.5
Applied frac-times_binary640.5
Final simplification0.3
herbie shell --seed 2021344
(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)))