\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
t_0 := \tan x + \tan \varepsilon\\
\mathbf{if}\;\varepsilon \leq -2.01426406875669 \cdot 10^{-8}:\\
\;\;\;\;\mathsf{fma}\left(t_0, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)\\
\mathbf{elif}\;\varepsilon \leq 3.118191246439813 \cdot 10^{-7}:\\
\;\;\;\;\begin{array}{l}
t_1 := {\cos x}^{2}\\
\mathsf{fma}\left(\varepsilon, \frac{{\sin x}^{2}}{t_1}, \varepsilon\right) + \frac{\varepsilon \cdot \varepsilon}{\cos x} \cdot \left(\sin x + \frac{{\sin x}^{3}}{t_1}\right)
\end{array}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{1 - \left(\tan x \cdot \sin \varepsilon\right) \cdot \frac{1}{\cos \varepsilon}} - \tan x\\
\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 -2.01426406875669e-8)
(fma t_0 (/ 1.0 (- 1.0 (* (tan x) (tan eps)))) (- (tan x)))
(if (<= eps 3.118191246439813e-7)
(let* ((t_1 (pow (cos x) 2.0)))
(+
(fma eps (/ (pow (sin x) 2.0) t_1) eps)
(* (/ (* eps eps) (cos x)) (+ (sin x) (/ (pow (sin x) 3.0) t_1)))))
(-
(/ t_0 (- 1.0 (* (* (tan x) (sin eps)) (/ 1.0 (cos eps)))))
(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 <= -2.01426406875669e-8) {
tmp = fma(t_0, (1.0 / (1.0 - (tan(x) * tan(eps)))), -tan(x));
} else if (eps <= 3.118191246439813e-7) {
double t_1 = pow(cos(x), 2.0);
tmp = fma(eps, (pow(sin(x), 2.0) / t_1), eps) + (((eps * eps) / cos(x)) * (sin(x) + (pow(sin(x), 3.0) / t_1)));
} else {
tmp = (t_0 / (1.0 - ((tan(x) * sin(eps)) * (1.0 / cos(eps))))) - tan(x);
}
return tmp;
}




Bits error versus x




Bits error versus eps
| Original | 36.8 |
|---|---|
| Target | 15.2 |
| Herbie | 0.3 |
if eps < -2.01426406875669e-8Initial program 29.5
Applied tan-sum_binary640.5
Applied div-inv_binary640.5
Applied fma-neg_binary640.5
if -2.01426406875669e-8 < eps < 3.118191246439813e-7Initial program 44.4
Applied tan-sum_binary6444.1
Taylor expanded in eps around 0 0.2
Simplified0.2
if 3.118191246439813e-7 < eps Initial program 29.9
Applied tan-sum_binary640.4
Applied tan-quot_binary640.4
Applied associate-*r/_binary640.4
Applied div-inv_binary640.4
Final simplification0.3
herbie shell --seed 2021280
(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)))