Average Error: 36.7 → 15.3
Time: 8.7s
Precision: 64
\[\tan \left(x + \varepsilon\right) - \tan x\]
\[\begin{array}{l} \mathbf{if}\;\varepsilon \le -8.1479570759041135 \cdot 10^{-55}:\\ \;\;\;\;\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 1.56534825561633359 \cdot 10^{-66}:\\ \;\;\;\;\left(\varepsilon \cdot x\right) \cdot \left(x + \varepsilon\right) + \varepsilon\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\left(\tan x + \tan \varepsilon\right) \cdot \left(1 + \tan x \cdot \tan \varepsilon\right)\right) \cdot \cos x - \left(1 - \left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)\right) \cdot \sin x}{\left(1 - \left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)\right) \cdot \cos x}\\ \end{array}\]
\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \le -8.1479570759041135 \cdot 10^{-55}:\\
\;\;\;\;\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 1.56534825561633359 \cdot 10^{-66}:\\
\;\;\;\;\left(\varepsilon \cdot x\right) \cdot \left(x + \varepsilon\right) + \varepsilon\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(\tan x + \tan \varepsilon\right) \cdot \left(1 + \tan x \cdot \tan \varepsilon\right)\right) \cdot \cos x - \left(1 - \left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)\right) \cdot \sin x}{\left(1 - \left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)\right) \cdot \cos x}\\

\end{array}
double code(double x, double eps) {
	return (tan((x + eps)) - tan(x));
}
double code(double x, double eps) {
	double VAR;
	if ((eps <= -8.147957075904114e-55)) {
		VAR = ((((tan(x) + tan(eps)) * cos(x)) - ((1.0 - (tan(x) * tan(eps))) * sin(x))) / ((1.0 - (tan(x) * tan(eps))) * cos(x)));
	} else {
		double VAR_1;
		if ((eps <= 1.5653482556163336e-66)) {
			VAR_1 = (((eps * x) * (x + eps)) + eps);
		} else {
			VAR_1 = (((((tan(x) + tan(eps)) * (1.0 + (tan(x) * tan(eps)))) * cos(x)) - ((1.0 - ((tan(x) * tan(eps)) * (tan(x) * tan(eps)))) * sin(x))) / ((1.0 - ((tan(x) * tan(eps)) * (tan(x) * tan(eps)))) * 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.7
Target14.8
Herbie15.3
\[\frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)}\]

Derivation

  1. Split input into 3 regimes
  2. if eps < -8.147957075904114e-55

    1. Initial program 29.6

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

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

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

      \[\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 -8.147957075904114e-55 < eps < 1.5653482556163336e-66

    1. Initial program 47.2

      \[\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 1.5653482556163336e-66 < eps

    1. Initial program 29.9

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

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

      \[\leadsto \frac{\tan x + \tan \varepsilon}{\color{blue}{\frac{1 \cdot 1 - \left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)}{1 + \tan x \cdot \tan \varepsilon}}} - \tan x\]
    6. Applied associate-/r/5.4

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 \cdot 1 - \left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)} \cdot \left(1 + \tan x \cdot \tan \varepsilon\right)} - \tan x\]
    7. Simplified5.4

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)}} \cdot \left(1 + \tan x \cdot \tan \varepsilon\right) - \tan x\]
    8. Using strategy rm
    9. Applied tan-quot5.5

      \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)} \cdot \left(1 + \tan x \cdot \tan \varepsilon\right) - \color{blue}{\frac{\sin x}{\cos x}}\]
    10. Applied associate-*l/5.5

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

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

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

Reproduce

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