Average Error: 37.0 → 15.6
Time: 7.8s
Precision: 64
\[\tan \left(x + \varepsilon\right) - \tan x\]
\[\begin{array}{l} \mathbf{if}\;\varepsilon \le -7.6668898087207463 \cdot 10^{-78}:\\ \;\;\;\;\frac{\left(\tan x + \tan \varepsilon\right) \cdot \cos x - \left(1 - \frac{\sin x \cdot \sin \varepsilon}{\cos x \cdot \cos \varepsilon}\right) \cdot \sin x}{\left(1 - \frac{\sin x \cdot \sin \varepsilon}{\cos x \cdot \cos \varepsilon}\right) \cdot \cos x}\\ \mathbf{elif}\;\varepsilon \le 6.8217031386727936 \cdot 10^{-19}:\\ \;\;\;\;\left(\varepsilon \cdot x\right) \cdot \left(x + \varepsilon\right) + \varepsilon\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} \cdot \frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x \cdot \tan x}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} + \tan x}\\ \end{array}\]
\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \le -7.6668898087207463 \cdot 10^{-78}:\\
\;\;\;\;\frac{\left(\tan x + \tan \varepsilon\right) \cdot \cos x - \left(1 - \frac{\sin x \cdot \sin \varepsilon}{\cos x \cdot \cos \varepsilon}\right) \cdot \sin x}{\left(1 - \frac{\sin x \cdot \sin \varepsilon}{\cos x \cdot \cos \varepsilon}\right) \cdot \cos x}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} \cdot \frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x \cdot \tan x}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} + \tan 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 <= -7.666889808720746e-78)) {
		VAR = ((double) (((double) (((double) (((double) (((double) tan(x)) + ((double) tan(eps)))) * ((double) cos(x)))) - ((double) (((double) (1.0 - ((double) (((double) (((double) sin(x)) * ((double) sin(eps)))) / ((double) (((double) cos(x)) * ((double) cos(eps)))))))) * ((double) sin(x)))))) / ((double) (((double) (1.0 - ((double) (((double) (((double) sin(x)) * ((double) sin(eps)))) / ((double) (((double) cos(x)) * ((double) cos(eps)))))))) * ((double) cos(x))))));
	} else {
		double VAR_1;
		if ((eps <= 6.821703138672794e-19)) {
			VAR_1 = ((double) (((double) (((double) (eps * x)) * ((double) (x + eps)))) + eps));
		} else {
			VAR_1 = ((double) (((double) (((double) (((double) (((double) (((double) tan(x)) + ((double) tan(eps)))) / ((double) (1.0 - ((double) (((double) tan(x)) * ((double) tan(eps)))))))) * ((double) (((double) (((double) tan(x)) + ((double) tan(eps)))) / ((double) (1.0 - ((double) (((double) tan(x)) * ((double) tan(eps)))))))))) - ((double) (((double) tan(x)) * ((double) tan(x)))))) / ((double) (((double) (((double) (((double) tan(x)) + ((double) tan(eps)))) / ((double) (1.0 - ((double) (((double) tan(x)) * ((double) tan(eps)))))))) + ((double) tan(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

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

Derivation

  1. Split input into 3 regimes
  2. if eps < -7.666889808720746e-78

    1. Initial program 30.8

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

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

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

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

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

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

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

    if -7.666889808720746e-78 < eps < 6.821703138672794e-19

    1. Initial program 46.7

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

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

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

    if 6.821703138672794e-19 < eps

    1. Initial program 29.6

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

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

      \[\leadsto \color{blue}{\frac{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} \cdot \frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x \cdot \tan x}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} + \tan x}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification15.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \le -7.6668898087207463 \cdot 10^{-78}:\\ \;\;\;\;\frac{\left(\tan x + \tan \varepsilon\right) \cdot \cos x - \left(1 - \frac{\sin x \cdot \sin \varepsilon}{\cos x \cdot \cos \varepsilon}\right) \cdot \sin x}{\left(1 - \frac{\sin x \cdot \sin \varepsilon}{\cos x \cdot \cos \varepsilon}\right) \cdot \cos x}\\ \mathbf{elif}\;\varepsilon \le 6.8217031386727936 \cdot 10^{-19}:\\ \;\;\;\;\left(\varepsilon \cdot x\right) \cdot \left(x + \varepsilon\right) + \varepsilon\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} \cdot \frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x \cdot \tan x}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} + \tan x}\\ \end{array}\]

Reproduce

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