Average Error: 37.2 → 16.0
Time: 10.5s
Precision: 64
\[\tan \left(x + \varepsilon\right) - \tan x\]
\[\begin{array}{l} \mathbf{if}\;\varepsilon \le -1.4292982892743089 \cdot 10^{-72} \lor \neg \left(\varepsilon \le 7.895037822047127 \cdot 10^{-70}\right):\\ \;\;\;\;\frac{\left(\tan x + \tan \varepsilon\right) \cdot \cos x - \left(1 - \frac{\sin x \cdot \tan \varepsilon}{\cos x}\right) \cdot \sin x}{\left(1 - \frac{\sin x \cdot \tan \varepsilon}{\cos x}\right) \cdot \cos x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left({\varepsilon}^{2}, x, \mathsf{fma}\left(\varepsilon, {x}^{2}, \varepsilon\right)\right)\\ \end{array}\]
\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \le -1.4292982892743089 \cdot 10^{-72} \lor \neg \left(\varepsilon \le 7.895037822047127 \cdot 10^{-70}\right):\\
\;\;\;\;\frac{\left(\tan x + \tan \varepsilon\right) \cdot \cos x - \left(1 - \frac{\sin x \cdot \tan \varepsilon}{\cos x}\right) \cdot \sin x}{\left(1 - \frac{\sin x \cdot \tan \varepsilon}{\cos x}\right) \cdot \cos x}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left({\varepsilon}^{2}, x, \mathsf{fma}\left(\varepsilon, {x}^{2}, \varepsilon\right)\right)\\

\end{array}
double code(double x, double eps) {
	return (tan((x + eps)) - tan(x));
}
double code(double x, double eps) {
	double temp;
	if (((eps <= -1.429298289274309e-72) || !(eps <= 7.895037822047127e-70))) {
		temp = ((((tan(x) + tan(eps)) * cos(x)) - ((1.0 - ((sin(x) * tan(eps)) / cos(x))) * sin(x))) / ((1.0 - ((sin(x) * tan(eps)) / cos(x))) * cos(x)));
	} else {
		temp = fma(pow(eps, 2.0), x, fma(eps, pow(x, 2.0), eps));
	}
	return temp;
}

Error

Bits error versus x

Bits error versus eps

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original37.2
Target15.3
Herbie16.0
\[\frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)}\]

Derivation

  1. Split input into 2 regimes
  2. if eps < -1.429298289274309e-72 or 7.895037822047127e-70 < eps

    1. Initial program 31.1

      \[\tan \left(x + \varepsilon\right) - \tan x\]
    2. Using strategy rm
    3. Applied tan-sum6.5

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x\]
    4. Using strategy rm
    5. Applied tan-quot6.5

      \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \color{blue}{\frac{\sin x}{\cos x}} \cdot \tan \varepsilon} - \tan x\]
    6. Applied associate-*l/6.5

      \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \color{blue}{\frac{\sin x \cdot \tan \varepsilon}{\cos x}}} - \tan x\]
    7. Using strategy rm
    8. Applied tan-quot6.5

      \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \frac{\sin x \cdot \tan \varepsilon}{\cos x}} - \color{blue}{\frac{\sin x}{\cos x}}\]
    9. Applied frac-sub6.6

      \[\leadsto \color{blue}{\frac{\left(\tan x + \tan \varepsilon\right) \cdot \cos x - \left(1 - \frac{\sin x \cdot \tan \varepsilon}{\cos x}\right) \cdot \sin x}{\left(1 - \frac{\sin x \cdot \tan \varepsilon}{\cos x}\right) \cdot \cos x}}\]

    if -1.429298289274309e-72 < eps < 7.895037822047127e-70

    1. Initial program 47.3

      \[\tan \left(x + \varepsilon\right) - \tan x\]
    2. Taylor expanded around 0 31.9

      \[\leadsto \color{blue}{x \cdot {\varepsilon}^{2} + \left(\varepsilon + {x}^{2} \cdot \varepsilon\right)}\]
    3. Simplified31.9

      \[\leadsto \color{blue}{\mathsf{fma}\left({\varepsilon}^{2}, x, \mathsf{fma}\left(\varepsilon, {x}^{2}, \varepsilon\right)\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification16.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \le -1.4292982892743089 \cdot 10^{-72} \lor \neg \left(\varepsilon \le 7.895037822047127 \cdot 10^{-70}\right):\\ \;\;\;\;\frac{\left(\tan x + \tan \varepsilon\right) \cdot \cos x - \left(1 - \frac{\sin x \cdot \tan \varepsilon}{\cos x}\right) \cdot \sin x}{\left(1 - \frac{\sin x \cdot \tan \varepsilon}{\cos x}\right) \cdot \cos x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left({\varepsilon}^{2}, x, \mathsf{fma}\left(\varepsilon, {x}^{2}, \varepsilon\right)\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020049 +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)))