Average Error: 37.2 → 13.7
Time: 8.4s
Precision: binary64
\[\tan \left(x + \varepsilon\right) - \tan x\]
\[\begin{array}{l} \mathbf{if}\;\varepsilon \le -8.4392400757911843 \cdot 10^{-22} \lor \neg \left(\varepsilon \le 1.1417540727375646 \cdot 10^{-43}\right):\\ \;\;\;\;\frac{\left(\tan x + \tan \varepsilon\right) \cdot \cos x - \left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \sin x}{\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \cos x}\\ \mathbf{else}:\\ \;\;\;\;{\varepsilon}^{2} \cdot \left(\varepsilon \cdot \frac{1}{3} + x\right) + \varepsilon\\ \end{array}\]
\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \le -8.4392400757911843 \cdot 10^{-22} \lor \neg \left(\varepsilon \le 1.1417540727375646 \cdot 10^{-43}\right):\\
\;\;\;\;\frac{\left(\tan x + \tan \varepsilon\right) \cdot \cos x - \left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \sin x}{\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \cos x}\\

\mathbf{else}:\\
\;\;\;\;{\varepsilon}^{2} \cdot \left(\varepsilon \cdot \frac{1}{3} + x\right) + \varepsilon\\

\end{array}
double code(double x, double eps) {
	return ((double) (((double) tan(((double) (x + eps)))) - ((double) tan(x))));
}
double code(double x, double eps) {
	double VAR;
	if (((eps <= -8.439240075791184e-22) || !(eps <= 1.1417540727375646e-43))) {
		VAR = ((double) (((double) (((double) (((double) (((double) tan(x)) + ((double) tan(eps)))) * ((double) cos(x)))) - ((double) (((double) (1.0 - ((double) (((double) tan(x)) * ((double) tan(eps)))))) * ((double) sin(x)))))) / ((double) (((double) (1.0 - ((double) (((double) tan(x)) * ((double) tan(eps)))))) * ((double) cos(x))))));
	} else {
		VAR = ((double) (((double) (((double) pow(eps, 2.0)) * ((double) (((double) (eps * 0.3333333333333333)) + x)))) + eps));
	}
	return VAR;
}

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.4
Herbie13.7
\[\frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)}\]

Derivation

  1. Split input into 2 regimes
  2. if eps < -8.4392400757911843e-22 or 1.1417540727375646e-43 < eps

    1. Initial program 30.3

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

      \[\leadsto \tan \left(x + \varepsilon\right) - \color{blue}{\frac{\sin x}{\cos x}}\]
    4. Applied tan-sum2.3

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \frac{\sin x}{\cos x}\]
    5. Applied frac-sub2.4

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

    if -8.4392400757911843e-22 < eps < 1.1417540727375646e-43

    1. Initial program 45.7

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

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x\]
    4. Taylor expanded around inf 45.8

      \[\leadsto \frac{\color{blue}{\frac{\sin \varepsilon}{\cos \varepsilon} + \frac{\sin x}{\cos x}}}{1 - \tan x \cdot \tan \varepsilon} - \tan x\]
    5. Taylor expanded around 0 27.5

      \[\leadsto \color{blue}{x \cdot {\varepsilon}^{2} + \left(\frac{1}{3} \cdot {\varepsilon}^{3} + \varepsilon\right)}\]
    6. Simplified27.5

      \[\leadsto \color{blue}{{\varepsilon}^{2} \cdot \left(\varepsilon \cdot \frac{1}{3} + x\right) + \varepsilon}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification13.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \le -8.4392400757911843 \cdot 10^{-22} \lor \neg \left(\varepsilon \le 1.1417540727375646 \cdot 10^{-43}\right):\\ \;\;\;\;\frac{\left(\tan x + \tan \varepsilon\right) \cdot \cos x - \left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \sin x}{\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \cos x}\\ \mathbf{else}:\\ \;\;\;\;{\varepsilon}^{2} \cdot \left(\varepsilon \cdot \frac{1}{3} + x\right) + \varepsilon\\ \end{array}\]

Reproduce

herbie shell --seed 2020175 
(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)))