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




Bits error versus x




Bits error versus eps
| Original | 37.5 |
|---|---|
| Target | 15.0 |
| Herbie | 0.3 |
if eps < -4.7981818945788272e-5Initial program 29.2
Applied tan-sum_binary640.3
Applied flip--_binary640.4
Applied associate-*r*_binary640.4
Applied pow1_binary640.4
Applied pow1_binary640.4
Applied pow-prod-down_binary640.4
if -4.7981818945788272e-5 < eps < 5.7040321848711158e-5Initial program 45.6
Taylor expanded in eps around 0 0.2
Simplified0.2
if 5.7040321848711158e-5 < eps Initial program 30.1
Applied tan-sum_binary640.4
Applied flip--_binary640.4
Applied associate-*r*_binary640.4
Applied add-sqr-sqrt_binary640.4
Final simplification0.3
herbie shell --seed 2022077
(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)))