\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -4.110958230728241 \cdot 10^{-05}:\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\
\mathbf{elif}\;\varepsilon \leq 8.767513643243207 \cdot 10^{-20}:\\
\;\;\;\;\left(\varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}} + 1.3333333333333333 \cdot \left(\frac{{\sin x}^{2}}{{\cos x}^{2}} \cdot {\varepsilon}^{3}\right)\right) + \left(\left(\varepsilon + {\varepsilon}^{3} \cdot \left(\frac{{\sin x}^{4}}{{\cos x}^{4}} + 0.3333333333333333\right)\right) + \left(\varepsilon \cdot \varepsilon\right) \cdot \left(\frac{{\sin x}^{3}}{{\cos x}^{3}} + \frac{\sin x}{\cos x}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \log \left({\left(e^{\tan x}\right)}^{\tan \varepsilon}\right)} - \tan x\\
\end{array}(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
(FPCore (x eps)
:precision binary64
(if (<= eps -4.110958230728241e-05)
(- (/ (+ (tan x) (tan eps)) (- 1.0 (* (tan x) (tan eps)))) (tan x))
(if (<= eps 8.767513643243207e-20)
(+
(+
(* eps (/ (pow (sin x) 2.0) (pow (cos x) 2.0)))
(*
1.3333333333333333
(* (/ (pow (sin x) 2.0) (pow (cos x) 2.0)) (pow eps 3.0))))
(+
(+
eps
(*
(pow eps 3.0)
(+ (/ (pow (sin x) 4.0) (pow (cos x) 4.0)) 0.3333333333333333)))
(*
(* eps eps)
(+ (/ (pow (sin x) 3.0) (pow (cos x) 3.0)) (/ (sin x) (cos x))))))
(-
(/ (+ (tan x) (tan eps)) (- 1.0 (log (pow (exp (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 <= -4.110958230728241e-05) {
tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) - tan(x);
} else if (eps <= 8.767513643243207e-20) {
tmp = ((eps * (pow(sin(x), 2.0) / pow(cos(x), 2.0))) + (1.3333333333333333 * ((pow(sin(x), 2.0) / pow(cos(x), 2.0)) * pow(eps, 3.0)))) + ((eps + (pow(eps, 3.0) * ((pow(sin(x), 4.0) / pow(cos(x), 4.0)) + 0.3333333333333333))) + ((eps * eps) * ((pow(sin(x), 3.0) / pow(cos(x), 3.0)) + (sin(x) / cos(x)))));
} else {
tmp = ((tan(x) + tan(eps)) / (1.0 - log(pow(exp(tan(x)), tan(eps))))) - tan(x);
}
return tmp;
}




Bits error versus x




Bits error versus eps
Results
| Original | 37.3 |
|---|---|
| Target | 15.4 |
| Herbie | 0.6 |
if eps < -4.11095823072824123e-5Initial program 29.8
rmApplied tan-sum_binary64_22590.4
if -4.11095823072824123e-5 < eps < 8.76751364324320673e-20Initial program 45.6
rmApplied tan-sum_binary64_225945.3
Taylor expanded around 0 0.2
Simplified0.2
if 8.76751364324320673e-20 < eps Initial program 30.0
rmApplied tan-sum_binary64_22591.3
rmApplied add-log-exp_binary64_21631.5
Simplified1.5
Final simplification0.6
herbie shell --seed 2021045
(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)))