\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.00018789018785287954:\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \sqrt[3]{{\left({\left(\tan x \cdot \tan \varepsilon\right)}^{3}\right)}^{3}}} \cdot \left(1 + \left(\tan x \cdot \tan \varepsilon + \sqrt[3]{\left(\left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)\right)\right) \cdot \left(\left(\tan x \cdot \left(\tan x \cdot \tan x\right)\right) \cdot \left(\tan \varepsilon \cdot \left(\tan \varepsilon \cdot \tan \varepsilon\right)\right)\right)}\right)\right) - \tan x\\
\mathbf{elif}\;\varepsilon \leq 0.00023798155281232094:\\
\;\;\;\;1.3333333333333333 \cdot \frac{{\sin x}^{2} \cdot {\varepsilon}^{3}}{{\cos x}^{2}} + \left(\frac{\varepsilon \cdot {\sin x}^{2}}{{\cos x}^{2}} + \left(\frac{{\sin x}^{5} \cdot {\varepsilon}^{4}}{{\cos x}^{5}} + \left(1.6666666666666667 \cdot \frac{{\varepsilon}^{4} \cdot {\sin x}^{3}}{{\cos x}^{3}} + \left(\left(\left(\varepsilon + {\varepsilon}^{3} \cdot \left(\frac{{\sin x}^{4}}{{\cos x}^{4}} + 0.3333333333333333\right)\right) + 0.6666666666666666 \cdot \left({\varepsilon}^{4} \cdot \frac{\sin x}{\cos x}\right)\right) + \left(\varepsilon \cdot \varepsilon\right) \cdot \left(\frac{\sin x}{\cos x} + \frac{{\sin x}^{3}}{{\cos x}^{3}}\right)\right)\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}} \cdot \left(1 + \left(\tan x \cdot \tan \varepsilon + \left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)\right)\right) - \tan x\\
\end{array}(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
(FPCore (x eps)
:precision binary64
(if (<= eps -0.00018789018785287954)
(-
(*
(/
(+ (tan x) (tan eps))
(- 1.0 (cbrt (pow (pow (* (tan x) (tan eps)) 3.0) 3.0))))
(+
1.0
(+
(* (tan x) (tan eps))
(cbrt
(*
(*
(* (tan x) (tan eps))
(* (* (tan x) (tan eps)) (* (tan x) (tan eps))))
(*
(* (tan x) (* (tan x) (tan x)))
(* (tan eps) (* (tan eps) (tan eps)))))))))
(tan x))
(if (<= eps 0.00023798155281232094)
(+
(*
1.3333333333333333
(/ (* (pow (sin x) 2.0) (pow eps 3.0)) (pow (cos x) 2.0)))
(+
(/ (* eps (pow (sin x) 2.0)) (pow (cos x) 2.0))
(+
(/ (* (pow (sin x) 5.0) (pow eps 4.0)) (pow (cos x) 5.0))
(+
(*
1.6666666666666667
(/ (* (pow eps 4.0) (pow (sin x) 3.0)) (pow (cos x) 3.0)))
(+
(+
(+
eps
(*
(pow eps 3.0)
(+ (/ (pow (sin x) 4.0) (pow (cos x) 4.0)) 0.3333333333333333)))
(* 0.6666666666666666 (* (pow eps 4.0) (/ (sin x) (cos x)))))
(*
(* eps eps)
(+
(/ (sin x) (cos x))
(/ (pow (sin x) 3.0) (pow (cos x) 3.0)))))))))
(-
(*
(/ (+ (tan x) (tan eps)) (- 1.0 (pow (* (tan x) (tan eps)) 3.0)))
(+
1.0
(+
(* (tan x) (tan eps))
(* (* (tan x) (tan eps)) (* (tan x) (tan eps))))))
(tan x)))))double code(double x, double eps) {
return tan(x + eps) - tan(x);
}
double code(double x, double eps) {
double tmp;
if (eps <= -0.00018789018785287954) {
tmp = (((tan(x) + tan(eps)) / (1.0 - cbrt(pow(pow((tan(x) * tan(eps)), 3.0), 3.0)))) * (1.0 + ((tan(x) * tan(eps)) + cbrt(((tan(x) * tan(eps)) * ((tan(x) * tan(eps)) * (tan(x) * tan(eps)))) * ((tan(x) * (tan(x) * tan(x))) * (tan(eps) * (tan(eps) * tan(eps)))))))) - tan(x);
} else if (eps <= 0.00023798155281232094) {
tmp = (1.3333333333333333 * ((pow(sin(x), 2.0) * pow(eps, 3.0)) / pow(cos(x), 2.0))) + (((eps * pow(sin(x), 2.0)) / pow(cos(x), 2.0)) + (((pow(sin(x), 5.0) * pow(eps, 4.0)) / pow(cos(x), 5.0)) + ((1.6666666666666667 * ((pow(eps, 4.0) * pow(sin(x), 3.0)) / pow(cos(x), 3.0))) + (((eps + (pow(eps, 3.0) * ((pow(sin(x), 4.0) / pow(cos(x), 4.0)) + 0.3333333333333333))) + (0.6666666666666666 * (pow(eps, 4.0) * (sin(x) / cos(x))))) + ((eps * eps) * ((sin(x) / cos(x)) + (pow(sin(x), 3.0) / pow(cos(x), 3.0))))))));
} else {
tmp = (((tan(x) + tan(eps)) / (1.0 - pow((tan(x) * tan(eps)), 3.0))) * (1.0 + ((tan(x) * tan(eps)) + ((tan(x) * tan(eps)) * (tan(x) * tan(eps)))))) - tan(x);
}
return tmp;
}




Bits error versus x




Bits error versus eps
Results
| Original | 37.1 |
|---|---|
| Target | 15.6 |
| Herbie | 0.3 |
if eps < -1.878901878528795e-4Initial program 30.3
rmApplied tan-sum_binary64_22590.3
rmApplied flip3--_binary64_21280.4
Applied associate-/r/_binary64_20700.4
Simplified0.4
rmApplied add-cbrt-cube_binary64_21600.4
Simplified0.4
rmApplied add-cbrt-cube_binary64_21600.4
Applied add-cbrt-cube_binary64_21600.4
Applied cbrt-unprod_binary64_21570.4
Applied add-cbrt-cube_binary64_21600.4
Applied cbrt-unprod_binary64_21570.4
if -1.878901878528795e-4 < eps < 2.3798155281232094e-4Initial program 44.4
Taylor expanded around 0 0.2
Simplified0.2
if 2.3798155281232094e-4 < eps Initial program 29.9
rmApplied tan-sum_binary64_22590.3
rmApplied flip3--_binary64_21280.4
Applied associate-/r/_binary64_20700.4
Final simplification0.3
herbie shell --seed 2021050
(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)))