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




Bits error versus x




Bits error versus eps
| Original | 36.8 |
|---|---|
| Target | 15.2 |
| Herbie | 0.4 |
if eps < -3.511738504762205e-9Initial program 29.7
Applied tan-sum_binary640.4
Applied add-cube-cbrt_binary640.8
Applied flip3--_binary640.8
Applied associate-/r/_binary640.8
Applied prod-diff_binary640.8
Simplified0.5
Simplified0.5
Applied pow1_binary640.5
if -3.511738504762205e-9 < eps < 8.54299102699515649e-11Initial program 44.6
Taylor expanded in eps around 0 0.4
Simplified0.3
if 8.54299102699515649e-11 < eps Initial program 29.6
Applied tan-sum_binary640.6
Applied *-un-lft-identity_binary640.6
Applied cancel-sign-sub-inv_binary640.6
Final simplification0.4
herbie shell --seed 2022024
(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)))