\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
t_0 := \tan x + \tan \varepsilon\\
\mathbf{if}\;\varepsilon \leq -3.231461580256822 \cdot 10^{-5}:\\
\;\;\;\;\frac{t_0}{1 - \log \left({\left(e^{\tan x}\right)}^{\tan \varepsilon}\right)} - \tan x\\
\mathbf{elif}\;\varepsilon \leq 6.61700448350665 \cdot 10^{-5}:\\
\;\;\;\;\begin{array}{l}
t_1 := {\cos x}^{2}\\
t_2 := \frac{{\sin x}^{2}}{t_1}\\
\left(\frac{{\varepsilon}^{3} \cdot {\sin x}^{4}}{{\cos x}^{4}} + \left(\varepsilon + \left(\varepsilon \cdot t_2 + \mathsf{fma}\left(0.3333333333333333, {\varepsilon}^{3}, 1.3333333333333333 \cdot \left({\varepsilon}^{3} \cdot t_2\right)\right)\right)\right)\right) + \frac{\varepsilon \cdot \varepsilon}{\cos x} \cdot \left(\sin x + \frac{{\sin x}^{3}}{t_1}\right)
\end{array}\\
\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_3 := \tan x \cdot \tan \varepsilon\\
\mathsf{fma}\left(\frac{t_0}{1 - t_3 \cdot t_3}, \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 -3.231461580256822e-5)
(- (/ t_0 (- 1.0 (log (pow (exp (tan x)) (tan eps))))) (tan x))
(if (<= eps 6.61700448350665e-5)
(let* ((t_1 (pow (cos x) 2.0)) (t_2 (/ (pow (sin x) 2.0) t_1)))
(+
(+
(/ (* (pow eps 3.0) (pow (sin x) 4.0)) (pow (cos x) 4.0))
(+
eps
(+
(* eps t_2)
(fma
0.3333333333333333
(pow eps 3.0)
(* 1.3333333333333333 (* (pow eps 3.0) t_2))))))
(* (/ (* eps eps) (cos x)) (+ (sin x) (/ (pow (sin x) 3.0) t_1)))))
(let* ((t_3 (* (tan x) (tan eps))))
(fma
(/ t_0 (- 1.0 (* t_3 t_3)))
(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 <= -3.231461580256822e-5) {
tmp = (t_0 / (1.0 - log(pow(exp(tan(x)), tan(eps))))) - tan(x);
} else if (eps <= 6.61700448350665e-5) {
double t_1 = pow(cos(x), 2.0);
double t_2 = pow(sin(x), 2.0) / t_1;
tmp = (((pow(eps, 3.0) * pow(sin(x), 4.0)) / pow(cos(x), 4.0)) + (eps + ((eps * t_2) + fma(0.3333333333333333, pow(eps, 3.0), (1.3333333333333333 * (pow(eps, 3.0) * t_2)))))) + (((eps * eps) / cos(x)) * (sin(x) + (pow(sin(x), 3.0) / t_1)));
} else {
double t_3 = tan(x) * tan(eps);
tmp = fma((t_0 / (1.0 - (t_3 * t_3))), 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 < -3.2314615802568222e-5Initial program 30.4
Applied tan-sum_binary640.4
Applied add-log-exp_binary640.4
Simplified0.5
Applied *-un-lft-identity_binary640.5
Applied pow-unpow_binary640.5
if -3.2314615802568222e-5 < eps < 6.61700448350664982e-5Initial program 44.9
Applied tan-sum_binary6444.3
Applied add-log-exp_binary6444.3
Simplified44.3
Taylor expanded in eps around 0 0.2
Simplified0.2
if 6.61700448350664982e-5 < eps Initial program 29.7
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)))