Average Error: 37.1 → 15.5
Time: 6.7s
Precision: 64
\[\tan \left(x + \varepsilon\right) - \tan x\]
\[\begin{array}{l} \mathbf{if}\;\varepsilon \le -8.8270901166319843 \cdot 10^{-91}:\\ \;\;\;\;\frac{\left(\tan x + \tan \varepsilon\right) \cdot \cos x - \left(1 - \tan \varepsilon \cdot \tan x\right) \cdot \sin x}{\left(1 - \tan \varepsilon \cdot \tan x\right) \cdot \cos x}\\ \mathbf{elif}\;\varepsilon \le 1.47192102037964442 \cdot 10^{-77}:\\ \;\;\;\;\mathsf{fma}\left(x \cdot \varepsilon, \varepsilon + x, \varepsilon\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{-1}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}, -\tan x\right)\\ \end{array}\]
\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \le -8.8270901166319843 \cdot 10^{-91}:\\
\;\;\;\;\frac{\left(\tan x + \tan \varepsilon\right) \cdot \cos x - \left(1 - \tan \varepsilon \cdot \tan x\right) \cdot \sin x}{\left(1 - \tan \varepsilon \cdot \tan x\right) \cdot \cos x}\\

\mathbf{elif}\;\varepsilon \le 1.47192102037964442 \cdot 10^{-77}:\\
\;\;\;\;\mathsf{fma}\left(x \cdot \varepsilon, \varepsilon + x, \varepsilon\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{-1}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}, -\tan x\right)\\

\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.827090116631984e-91)) {
		VAR = ((((tan(x) + tan(eps)) * cos(x)) - ((1.0 - (tan(eps) * tan(x))) * sin(x))) / ((1.0 - (tan(eps) * tan(x))) * cos(x)));
	} else {
		double VAR_1;
		if ((eps <= 1.4719210203796444e-77)) {
			VAR_1 = fma((x * eps), (eps + x), eps);
		} else {
			VAR_1 = fma((tan(x) + tan(eps)), (-1.0 / fma(tan(x), tan(eps), -1.0)), -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.1
Target15.4
Herbie15.5
\[\frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)}\]

Derivation

  1. Split input into 3 regimes
  2. if eps < -8.827090116631984e-91

    1. Initial program 31.5

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

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x\]
    4. Simplified7.3

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

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

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

    if -8.827090116631984e-91 < eps < 1.4719210203796444e-77

    1. Initial program 47.7

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

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x\]
    4. Simplified47.7

      \[\leadsto \frac{\tan x + \tan \varepsilon}{\color{blue}{1 - \tan \varepsilon \cdot \tan x}} - \tan x\]
    5. Using strategy rm
    6. Applied div-inv47.7

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan \varepsilon \cdot \tan x}, -\tan x\right)}\]
    8. Taylor expanded around 0 31.1

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

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

    if 1.4719210203796444e-77 < eps

    1. Initial program 30.6

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

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x\]
    4. Simplified6.1

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan \varepsilon \cdot \tan x}, -\tan x\right)}\]
    8. Using strategy rm
    9. Applied frac-2neg6.1

      \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \color{blue}{\frac{-1}{-\left(1 - \tan \varepsilon \cdot \tan x\right)}}, -\tan x\right)\]
    10. Simplified6.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \le -8.8270901166319843 \cdot 10^{-91}:\\ \;\;\;\;\frac{\left(\tan x + \tan \varepsilon\right) \cdot \cos x - \left(1 - \tan \varepsilon \cdot \tan x\right) \cdot \sin x}{\left(1 - \tan \varepsilon \cdot \tan x\right) \cdot \cos x}\\ \mathbf{elif}\;\varepsilon \le 1.47192102037964442 \cdot 10^{-77}:\\ \;\;\;\;\mathsf{fma}\left(x \cdot \varepsilon, \varepsilon + x, \varepsilon\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{-1}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}, -\tan x\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020078 +o rules:numerics
(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)))