Average Error: 36.7 → 14.8
Time: 7.9s
Precision: 64
\[\tan \left(x + \varepsilon\right) - \tan x\]
\[\begin{array}{l} \mathbf{if}\;\varepsilon \le -5.18345613024736167 \cdot 10^{-37} \lor \neg \left(\varepsilon \le 6.6497007082639564 \cdot 10^{-24}\right):\\ \;\;\;\;\frac{1}{\frac{1 - \tan x \cdot \tan \varepsilon}{\tan x + \tan \varepsilon}} - \tan x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left({\varepsilon}^{2}, x, \mathsf{fma}\left(\varepsilon, {x}^{2}, \varepsilon\right)\right)\\ \end{array}\]
\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \le -5.18345613024736167 \cdot 10^{-37} \lor \neg \left(\varepsilon \le 6.6497007082639564 \cdot 10^{-24}\right):\\
\;\;\;\;\frac{1}{\frac{1 - \tan x \cdot \tan \varepsilon}{\tan x + \tan \varepsilon}} - \tan x\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left({\varepsilon}^{2}, x, \mathsf{fma}\left(\varepsilon, {x}^{2}, \varepsilon\right)\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 <= -5.183456130247362e-37) || !(eps <= 6.649700708263956e-24))) {
		VAR = ((1.0 / ((1.0 - (tan(x) * tan(eps))) / (tan(x) + tan(eps)))) - tan(x));
	} else {
		VAR = fma(pow(eps, 2.0), x, fma(eps, pow(x, 2.0), eps));
	}
	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
Target15.8
Herbie14.8
\[\frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)}\]

Derivation

  1. Split input into 2 regimes
  2. if eps < -5.183456130247362e-37 or 6.649700708263956e-24 < eps

    1. Initial program 30.3

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

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

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

    if -5.183456130247362e-37 < eps < 6.649700708263956e-24

    1. Initial program 45.0

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left({\varepsilon}^{2}, x, \mathsf{fma}\left(\varepsilon, {x}^{2}, \varepsilon\right)\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification14.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \le -5.18345613024736167 \cdot 10^{-37} \lor \neg \left(\varepsilon \le 6.6497007082639564 \cdot 10^{-24}\right):\\ \;\;\;\;\frac{1}{\frac{1 - \tan x \cdot \tan \varepsilon}{\tan x + \tan \varepsilon}} - \tan x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left({\varepsilon}^{2}, x, \mathsf{fma}\left(\varepsilon, {x}^{2}, \varepsilon\right)\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020102 +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)))