Average Error: 36.8 → 15.3
Time: 8.2s
Precision: binary64
\[\tan \left(x + \varepsilon\right) - \tan x\]
\[\begin{array}{l} \mathbf{if}\;\varepsilon \le -3.87795122106608234 \cdot 10^{-44}:\\ \;\;\;\;\frac{1 \cdot \cos x - \frac{1 - \tan x \cdot \tan \varepsilon}{\tan x + \tan \varepsilon} \cdot \sin x}{\frac{1 - \tan x \cdot \tan \varepsilon}{\tan x + \tan \varepsilon} \cdot \cos x}\\ \mathbf{elif}\;\varepsilon \le 2.1810641200666502 \cdot 10^{-48}:\\ \;\;\;\;\left(\varepsilon \cdot x\right) \cdot \left(x + \varepsilon\right) + \varepsilon\\ \mathbf{else}:\\ \;\;\;\;\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}\\ \end{array}\]
\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \le -3.87795122106608234 \cdot 10^{-44}:\\
\;\;\;\;\frac{1 \cdot \cos x - \frac{1 - \tan x \cdot \tan \varepsilon}{\tan x + \tan \varepsilon} \cdot \sin x}{\frac{1 - \tan x \cdot \tan \varepsilon}{\tan x + \tan \varepsilon} \cdot \cos x}\\

\mathbf{elif}\;\varepsilon \le 2.1810641200666502 \cdot 10^{-48}:\\
\;\;\;\;\left(\varepsilon \cdot x\right) \cdot \left(x + \varepsilon\right) + \varepsilon\\

\mathbf{else}:\\
\;\;\;\;\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}\\

\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 <= -3.8779512210660823e-44)) {
		VAR = ((double) (((double) (((double) (1.0 * ((double) cos(x)))) - ((double) (((double) (((double) (1.0 - ((double) (((double) tan(x)) * ((double) tan(eps)))))) / ((double) (((double) tan(x)) + ((double) tan(eps)))))) * ((double) sin(x)))))) / ((double) (((double) (((double) (1.0 - ((double) (((double) tan(x)) * ((double) tan(eps)))))) / ((double) (((double) tan(x)) + ((double) tan(eps)))))) * ((double) cos(x))))));
	} else {
		double VAR_1;
		if ((eps <= 2.1810641200666502e-48)) {
			VAR_1 = ((double) (((double) (((double) (eps * x)) * ((double) (x + eps)))) + eps));
		} else {
			VAR_1 = ((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))))));
		}
		VAR = VAR_1;
	}
	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

Original36.8
Target15.3
Herbie15.3
\[\frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)}\]

Derivation

  1. Split input into 3 regimes
  2. if eps < -3.87795122106608234e-44

    1. Initial program 29.8

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

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

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

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

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

    if -3.87795122106608234e-44 < eps < 2.1810641200666502e-48

    1. Initial program 45.7

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

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

      \[\leadsto \color{blue}{\left(\varepsilon \cdot x\right) \cdot \left(x + \varepsilon\right) + \varepsilon}\]

    if 2.1810641200666502e-48 < eps

    1. Initial program 30.9

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

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

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

      \[\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}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification15.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \le -3.87795122106608234 \cdot 10^{-44}:\\ \;\;\;\;\frac{1 \cdot \cos x - \frac{1 - \tan x \cdot \tan \varepsilon}{\tan x + \tan \varepsilon} \cdot \sin x}{\frac{1 - \tan x \cdot \tan \varepsilon}{\tan x + \tan \varepsilon} \cdot \cos x}\\ \mathbf{elif}\;\varepsilon \le 2.1810641200666502 \cdot 10^{-48}:\\ \;\;\;\;\left(\varepsilon \cdot x\right) \cdot \left(x + \varepsilon\right) + \varepsilon\\ \mathbf{else}:\\ \;\;\;\;\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}\\ \end{array}\]

Reproduce

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