Average Error: 37.3 → 16.0
Time: 27.3s
Precision: binary64
\[\tan \left(x + \varepsilon\right) - \tan x\]
\[\begin{array}{l} \mathbf{if}\;\varepsilon \le -2.1399087419179173 \cdot 10^{-60}:\\ \;\;\;\;\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{elif}\;\varepsilon \le 8.90708147804509962 \cdot 10^{-18}:\\ \;\;\;\;\left(\varepsilon \cdot x\right) \cdot \left(x + \varepsilon\right) + \varepsilon\\ \mathbf{else}:\\ \;\;\;\;\left(\sin x \cdot \cos \varepsilon + \cos x \cdot \sin \varepsilon\right) \cdot \frac{1}{\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \left(\cos x \cdot \cos \varepsilon\right)} - \tan x\\ \end{array}\]
\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \le -2.1399087419179173 \cdot 10^{-60}:\\
\;\;\;\;\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{elif}\;\varepsilon \le 8.90708147804509962 \cdot 10^{-18}:\\
\;\;\;\;\left(\varepsilon \cdot x\right) \cdot \left(x + \varepsilon\right) + \varepsilon\\

\mathbf{else}:\\
\;\;\;\;\left(\sin x \cdot \cos \varepsilon + \cos x \cdot \sin \varepsilon\right) \cdot \frac{1}{\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \left(\cos x \cdot \cos \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 <= -2.1399087419179173e-60)) {
		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 {
		double VAR_1;
		if ((eps <= 8.9070814780451e-18)) {
			VAR_1 = ((double) (((double) (((double) (eps * x)) * ((double) (x + eps)))) + eps));
		} else {
			VAR_1 = ((double) (((double) (((double) (((double) (((double) sin(x)) * ((double) cos(eps)))) + ((double) (((double) cos(x)) * ((double) sin(eps)))))) * ((double) (1.0 / ((double) (((double) (1.0 - ((double) (((double) tan(x)) * ((double) tan(eps)))))) * ((double) (((double) cos(x)) * ((double) cos(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.3
Target14.7
Herbie16.0
\[\frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)}\]

Derivation

  1. Split input into 3 regimes
  2. if eps < -2.1399087419179173e-60

    1. Initial program 29.4

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

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

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

      \[\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 -2.1399087419179173e-60 < eps < 8.90708147804509962e-18

    1. Initial program 46.7

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

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

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

    if 8.90708147804509962e-18 < eps

    1. Initial program 30.1

      \[\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 tan-quot1.1

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

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

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

      \[\leadsto \color{blue}{\frac{\sin x \cdot \cos \varepsilon + \cos x \cdot \sin \varepsilon}{\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \left(\cos x \cdot \cos \varepsilon\right)}} - \tan x\]
    9. Using strategy rm
    10. Applied div-inv1.2

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

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

Reproduce

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