\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.7473206182972273 \cdot 10^{-07}:\\
\;\;\;\;\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\
\mathbf{elif}\;\varepsilon \leq 3.6655339994443544 \cdot 10^{-07}:\\
\;\;\;\;\varepsilon + \left(\frac{\varepsilon \cdot {\sin x}^{2}}{{\cos x}^{2}} + \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 - \frac{\tan x}{\frac{\cos \varepsilon}{\sin \varepsilon}}} - \tan x\\
\end{array}(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
(FPCore (x eps)
:precision binary64
(if (<= eps -1.7473206182972273e-07)
(- (* (+ (tan x) (tan eps)) (/ 1.0 (- 1.0 (* (tan x) (tan eps))))) (tan x))
(if (<= eps 3.6655339994443544e-07)
(+
eps
(+
(/ (* eps (pow (sin x) 2.0)) (pow (cos x) 2.0))
(*
(* eps eps)
(+ (/ (pow (sin x) 3.0) (pow (cos x) 3.0)) (/ (sin x) (cos x))))))
(-
(/ (+ (tan x) (tan eps)) (- 1.0 (/ (tan x) (/ (cos eps) (sin 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 <= -1.7473206182972273e-07) {
tmp = ((tan(x) + tan(eps)) * (1.0 / (1.0 - (tan(x) * tan(eps))))) - tan(x);
} else if (eps <= 3.6655339994443544e-07) {
tmp = eps + (((eps * pow(sin(x), 2.0)) / pow(cos(x), 2.0)) + ((eps * eps) * ((pow(sin(x), 3.0) / pow(cos(x), 3.0)) + (sin(x) / cos(x)))));
} else {
tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) / (cos(eps) / sin(eps))))) - tan(x);
}
return tmp;
}














Bits error versus x














Bits error versus eps
Results
| Original | 36.7 |
|---|---|
| Target | 15.4 |
| Herbie | 0.3 |
| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 39874 |
| Alternative 2 | |
|---|---|
| Error | 0.4 |
| Cost | 33346 |
| Alternative 3 | |
|---|---|
| Error | 0.4 |
| Cost | 33032 |
| Alternative 4 | |
|---|---|
| Error | 14.8 |
| Cost | 26818 |
| Alternative 5 | |
|---|---|
| Error | 26.7 |
| Cost | 6464 |
| Alternative 6 | |
|---|---|
| Error | 42.0 |
| Cost | 1218 |
| Alternative 7 | |
|---|---|
| Error | 42.1 |
| Cost | 706 |
| Alternative 8 | |
|---|---|
| Error | 43.4 |
| Cost | 385 |
| Alternative 9 | |
|---|---|
| Error | 44.3 |
| Cost | 64 |
| Alternative 10 | |
|---|---|
| Error | 61.3 |
| Cost | 64 |


if eps < -1.74732061829722733e-7Initial program 29.5
rmApplied tan-sum_binary64_15770.4
rmApplied pow1_binary64_15030.4
rmApplied div-inv_binary64_14390.5
Simplified0.5
if -1.74732061829722733e-7 < eps < 3.6655339994443544e-7Initial program 44.5
Taylor expanded around 0 0.2
Simplified0.2
Simplified0.2
if 3.6655339994443544e-7 < eps Initial program 29.7
rmApplied tan-sum_binary64_15770.4
rmApplied tan-quot_binary64_16010.4
Applied associate-*r/_binary64_13840.4
rmApplied associate-/l*_binary64_13870.4
Simplified0.4
Final simplification0.3
herbie shell --seed 2021040
(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)))