Average Error: 36.8 → 15.5
Time: 8.3s
Precision: binary64
\[\tan \left(x + \varepsilon\right) - \tan x\]
\[\begin{array}{l} \mathbf{if}\;\varepsilon \le -7.5761833452932248 \cdot 10^{-22}:\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{\log \left(e^{1 - \tan x \cdot \tan \varepsilon}\right)} - \tan x\\ \mathbf{elif}\;\varepsilon \le 1.0303244886229992 \cdot 10^{-49}:\\ \;\;\;\;\left(\varepsilon \cdot x\right) \cdot \left(x + \varepsilon\right) + \varepsilon\\ \mathbf{else}:\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \frac{\sin x \cdot \tan \varepsilon}{\cos x}} - \tan x\\ \end{array}\]
\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \le -7.5761833452932248 \cdot 10^{-22}:\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{\log \left(e^{1 - \tan x \cdot \tan \varepsilon}\right)} - \tan x\\

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

\mathbf{else}:\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \frac{\sin x \cdot \tan \varepsilon}{\cos x}} - \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.576183345293225e-22)) {
		VAR = ((double) (((double) (((double) (((double) tan(x)) + ((double) tan(eps)))) / ((double) log(((double) exp(((double) (1.0 - ((double) (((double) tan(x)) * ((double) tan(eps)))))))))))) - ((double) tan(x))));
	} else {
		double VAR_1;
		if ((eps <= 1.0303244886229992e-49)) {
			VAR_1 = ((double) (((double) (((double) (eps * x)) * ((double) (x + eps)))) + eps));
		} else {
			VAR_1 = ((double) (((double) (((double) (((double) tan(x)) + ((double) tan(eps)))) / ((double) (1.0 - ((double) (((double) (((double) sin(x)) * ((double) tan(eps)))) / ((double) cos(x)))))))) - ((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.8
Target14.9
Herbie15.5
\[\frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)}\]

Derivation

  1. Split input into 3 regimes
  2. if eps < -7.5761833452932248e-22

    1. Initial program 29.2

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

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

      \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \color{blue}{\log \left(e^{\tan x \cdot \tan \varepsilon}\right)}} - \tan x\]
    6. Applied add-log-exp1.4

      \[\leadsto \frac{\tan x + \tan \varepsilon}{\color{blue}{\log \left(e^{1}\right)} - \log \left(e^{\tan x \cdot \tan \varepsilon}\right)} - \tan x\]
    7. Applied diff-log1.4

      \[\leadsto \frac{\tan x + \tan \varepsilon}{\color{blue}{\log \left(\frac{e^{1}}{e^{\tan x \cdot \tan \varepsilon}}\right)}} - \tan x\]
    8. Simplified1.4

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

    if -7.5761833452932248e-22 < eps < 1.0303244886229992e-49

    1. Initial program 45.6

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

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

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

    if 1.0303244886229992e-49 < eps

    1. Initial program 30.4

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \le -7.5761833452932248 \cdot 10^{-22}:\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{\log \left(e^{1 - \tan x \cdot \tan \varepsilon}\right)} - \tan x\\ \mathbf{elif}\;\varepsilon \le 1.0303244886229992 \cdot 10^{-49}:\\ \;\;\;\;\left(\varepsilon \cdot x\right) \cdot \left(x + \varepsilon\right) + \varepsilon\\ \mathbf{else}:\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \frac{\sin x \cdot \tan \varepsilon}{\cos x}} - \tan x\\ \end{array}\]

Reproduce

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