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




Bits error versus x




Bits error versus eps
| Original | 36.8 |
|---|---|
| Target | 14.9 |
| Herbie | 0.6 |
if eps < -2.7269952897157937e-4Initial program 30.1
Applied tan-sum_binary640.3
Applied div-inv_binary640.4
Applied fma-neg_binary640.3
Applied add-log-exp_binary640.4
if -2.7269952897157937e-4 < eps < 1.92821405893397928e-22Initial program 44.8
Taylor expanded in eps around 0 0.2
if 1.92821405893397928e-22 < eps Initial program 28.9
Applied tan-sum_binary641.6
Applied add-cube-cbrt_binary641.9
Applied flip3--_binary641.9
Applied associate-/r/_binary641.9
Applied prod-diff_binary641.9
Simplified1.5
Simplified1.6
Applied add-cbrt-cube_binary641.6
Simplified1.6
Final simplification0.6
herbie shell --seed 2021313
(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)))