Average Error: 36.8 → 15.1
Time: 6.3s
Precision: binary64
\[\tan \left(x + \varepsilon\right) - \tan x\]
\[\begin{array}{l} \mathbf{if}\;\varepsilon \leq -1.930934281552582 \cdot 10^{-97}:\\ \;\;\;\;\frac{\cos x \cdot \left(\left(\tan x + \tan \varepsilon\right) \cdot \left(1 + \tan x \cdot \tan \varepsilon\right)\right) - \left(1 - \left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)\right) \cdot \sin x}{\cos x \cdot \left(1 - \left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)\right)}\\ \mathbf{elif}\;\varepsilon \leq 6.878727405827355 \cdot 10^{-23}:\\ \;\;\;\;\varepsilon + x \cdot \left(\varepsilon \cdot \left(\varepsilon + x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\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\\ \end{array}\]
\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.930934281552582 \cdot 10^{-97}:\\
\;\;\;\;\frac{\cos x \cdot \left(\left(\tan x + \tan \varepsilon\right) \cdot \left(1 + \tan x \cdot \tan \varepsilon\right)\right) - \left(1 - \left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)\right) \cdot \sin x}{\cos x \cdot \left(1 - \left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)\right)}\\

\mathbf{elif}\;\varepsilon \leq 6.878727405827355 \cdot 10^{-23}:\\
\;\;\;\;\varepsilon + x \cdot \left(\varepsilon \cdot \left(\varepsilon + x\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\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\\

\end{array}
(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
(FPCore (x eps)
 :precision binary64
 (if (<= eps -1.930934281552582e-97)
   (/
    (-
     (* (cos x) (* (+ (tan x) (tan eps)) (+ 1.0 (* (tan x) (tan eps)))))
     (* (- 1.0 (* (* (tan x) (tan eps)) (* (tan x) (tan eps)))) (sin x)))
    (* (cos x) (- 1.0 (* (* (tan x) (tan eps)) (* (tan x) (tan eps))))))
   (if (<= eps 6.878727405827355e-23)
     (+ eps (* x (* eps (+ eps x))))
     (-
      (/
       (+ (* (sin x) (cos eps)) (* (cos x) (sin eps)))
       (* (- 1.0 (* (tan x) (tan eps))) (* (cos x) (cos eps))))
      (tan x)))))
double code(double x, double eps) {
	return tan(x + eps) - tan(x);
}
double code(double x, double eps) {
	double tmp;
	if (eps <= -1.930934281552582e-97) {
		tmp = ((cos(x) * ((tan(x) + tan(eps)) * (1.0 + (tan(x) * tan(eps))))) - ((1.0 - ((tan(x) * tan(eps)) * (tan(x) * tan(eps)))) * sin(x))) / (cos(x) * (1.0 - ((tan(x) * tan(eps)) * (tan(x) * tan(eps)))));
	} else if (eps <= 6.878727405827355e-23) {
		tmp = eps + (x * (eps * (eps + x)));
	} else {
		tmp = (((sin(x) * cos(eps)) + (cos(x) * sin(eps))) / ((1.0 - (tan(x) * tan(eps))) * (cos(x) * cos(eps)))) - tan(x);
	}
	return tmp;
}

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
Target15.2
Herbie15.1
\[\frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)}\]

Derivation

  1. Split input into 3 regimes
  2. if eps < -1.9309342815525819e-97

    1. Initial program 31.0

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

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

      \[\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/_binary647.9

      \[\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. Simplified7.9

      \[\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-quot_binary647.9

      \[\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/_binary647.9

      \[\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-sub_binary647.9

      \[\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}}\]
    12. Simplified7.9

      \[\leadsto \frac{\color{blue}{\cos x \cdot \left(\left(\tan x + \tan \varepsilon\right) \cdot \left(1 + \tan x \cdot \tan \varepsilon\right)\right) - \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}\]

    if -1.9309342815525819e-97 < eps < 6.878727405827355e-23

    1. Initial program 46.2

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

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

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

    if 6.878727405827355e-23 < eps

    1. Initial program 30.0

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

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

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

      \[\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-add_binary642.0

      \[\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/_binary642.0

      \[\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\]
  3. Recombined 3 regimes into one program.
  4. Final simplification15.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -1.930934281552582 \cdot 10^{-97}:\\ \;\;\;\;\frac{\cos x \cdot \left(\left(\tan x + \tan \varepsilon\right) \cdot \left(1 + \tan x \cdot \tan \varepsilon\right)\right) - \left(1 - \left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)\right) \cdot \sin x}{\cos x \cdot \left(1 - \left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)\right)}\\ \mathbf{elif}\;\varepsilon \leq 6.878727405827355 \cdot 10^{-23}:\\ \;\;\;\;\varepsilon + x \cdot \left(\varepsilon \cdot \left(\varepsilon + x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\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\\ \end{array}\]

Reproduce

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