Average Error: 36.5 → 15.2
Time: 8.3s
Precision: 64
\[\tan \left(x + \varepsilon\right) - \tan x\]
\[\begin{array}{l} \mathbf{if}\;\varepsilon \le -3.63980888889557201 \cdot 10^{-18}:\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \frac{\sin x \cdot \sin \varepsilon}{\cos x \cdot \cos \varepsilon}} - \tan x\\ \mathbf{elif}\;\varepsilon \le 1.2121002027987652 \cdot 10^{-17}:\\ \;\;\;\;\left(\varepsilon \cdot x\right) \cdot \left(x + \varepsilon\right) + \varepsilon\\ \mathbf{else}:\\ \;\;\;\;\frac{\tan x \cdot \tan x - \tan \varepsilon \cdot \tan \varepsilon}{\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x - \tan \varepsilon\right)} - \tan x\\ \end{array}\]
\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \le -3.63980888889557201 \cdot 10^{-18}:\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \frac{\sin x \cdot \sin \varepsilon}{\cos x \cdot \cos \varepsilon}} - \tan x\\

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

\mathbf{else}:\\
\;\;\;\;\frac{\tan x \cdot \tan x - \tan \varepsilon \cdot \tan \varepsilon}{\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x - \tan \varepsilon\right)} - \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 <= -3.639808888895572e-18)) {
		VAR = ((double) (((double) (((double) (((double) tan(x)) + ((double) tan(eps)))) / ((double) (1.0 - ((double) (((double) (((double) sin(x)) * ((double) sin(eps)))) / ((double) (((double) cos(x)) * ((double) cos(eps)))))))))) - ((double) tan(x))));
	} else {
		double VAR_1;
		if ((eps <= 1.2121002027987652e-17)) {
			VAR_1 = ((double) (((double) (((double) (eps * x)) * ((double) (x + eps)))) + eps));
		} else {
			VAR_1 = ((double) (((double) (((double) (((double) (((double) tan(x)) * ((double) tan(x)))) - ((double) (((double) tan(eps)) * ((double) tan(eps)))))) / ((double) (((double) (1.0 - ((double) (((double) tan(x)) * ((double) tan(eps)))))) * ((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

Original36.5
Target14.9
Herbie15.2
\[\frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)}\]

Derivation

  1. Split input into 3 regimes
  2. if eps < -3.639808888895572e-18

    1. Initial program 29.0

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

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

      \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \color{blue}{\frac{\sin \varepsilon}{\cos \varepsilon}}} - \tan x\]
    6. Applied tan-quot0.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-times0.8

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

    if -3.639808888895572e-18 < eps < 1.2121002027987652e-17

    1. Initial program 44.7

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

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

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

    if 1.2121002027987652e-17 < eps

    1. Initial program 29.5

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

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

      \[\leadsto \frac{\color{blue}{\frac{\tan x \cdot \tan x - \tan \varepsilon \cdot \tan \varepsilon}{\tan x - \tan \varepsilon}}}{1 - \tan x \cdot \tan \varepsilon} - \tan x\]
    6. Applied associate-/l/1.1

      \[\leadsto \color{blue}{\frac{\tan x \cdot \tan x - \tan \varepsilon \cdot \tan \varepsilon}{\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x - \tan \varepsilon\right)}} - \tan x\]
  3. Recombined 3 regimes into one program.
  4. Final simplification15.2

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

Reproduce

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