\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \le -7.133415199702494795047512315711631627873 \cdot 10^{-42} \lor \neg \left(\varepsilon \le 8.102442873651764516313012576112609860221 \cdot 10^{-33}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(\cos x, \tan \varepsilon + \tan x, \sin x \cdot \left(-1 + \tan x \cdot \tan \varepsilon\right)\right)}{\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \cos x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, {\varepsilon}^{2}, \mathsf{fma}\left(\frac{1}{3}, {\varepsilon}^{3}, \varepsilon\right)\right)\\
\end{array}double f(double x, double eps) {
double r171308 = x;
double r171309 = eps;
double r171310 = r171308 + r171309;
double r171311 = tan(r171310);
double r171312 = tan(r171308);
double r171313 = r171311 - r171312;
return r171313;
}
double f(double x, double eps) {
double r171314 = eps;
double r171315 = -7.133415199702495e-42;
bool r171316 = r171314 <= r171315;
double r171317 = 8.102442873651765e-33;
bool r171318 = r171314 <= r171317;
double r171319 = !r171318;
bool r171320 = r171316 || r171319;
double r171321 = x;
double r171322 = cos(r171321);
double r171323 = tan(r171314);
double r171324 = tan(r171321);
double r171325 = r171323 + r171324;
double r171326 = sin(r171321);
double r171327 = -1.0;
double r171328 = r171324 * r171323;
double r171329 = r171327 + r171328;
double r171330 = r171326 * r171329;
double r171331 = fma(r171322, r171325, r171330);
double r171332 = 1.0;
double r171333 = r171332 - r171328;
double r171334 = r171333 * r171322;
double r171335 = r171331 / r171334;
double r171336 = 2.0;
double r171337 = pow(r171314, r171336);
double r171338 = 0.3333333333333333;
double r171339 = 3.0;
double r171340 = pow(r171314, r171339);
double r171341 = fma(r171338, r171340, r171314);
double r171342 = fma(r171321, r171337, r171341);
double r171343 = r171320 ? r171335 : r171342;
return r171343;
}




Bits error versus x




Bits error versus eps
| Original | 37.1 |
|---|---|
| Target | 15.0 |
| Herbie | 14.0 |
if eps < -7.133415199702495e-42 or 8.102442873651765e-33 < eps Initial program 29.4
rmApplied tan-sum2.4
rmApplied tan-quot2.5
Applied frac-sub2.5
Simplified2.5
if -7.133415199702495e-42 < eps < 8.102442873651765e-33Initial program 46.8
rmApplied tan-sum46.8
rmApplied add-cube-cbrt47.6
Applied add-cube-cbrt47.6
Applied *-un-lft-identity47.6
Applied times-frac47.6
Applied prod-diff47.8
Simplified47.7
Simplified46.8
Taylor expanded around 0 28.7
Simplified28.7
Final simplification14.0
herbie shell --seed 2019347 +o rules:numerics
(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)))