Average Error: 37.2 → 15.9
Time: 7.1s
Precision: binary64
\[\tan \left(x + \varepsilon\right) - \tan x\]
\[\begin{array}{l} \mathbf{if}\;\varepsilon \leq -1.2303582437088547 \cdot 10^{-37} \lor \neg \left(\varepsilon \leq 6.370884799891205 \cdot 10^{-62}\right):\\ \;\;\;\;\frac{\left(\tan x + \tan \varepsilon\right) \cdot \cos x + \sin x \cdot \left(\tan x \cdot \tan \varepsilon + -1\right)}{\cos x \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)}\\ \mathbf{else}:\\ \;\;\;\;\varepsilon + x \cdot \left(\varepsilon \cdot \left(\varepsilon + x\right)\right)\\ \end{array}\]
\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.2303582437088547 \cdot 10^{-37} \lor \neg \left(\varepsilon \leq 6.370884799891205 \cdot 10^{-62}\right):\\
\;\;\;\;\frac{\left(\tan x + \tan \varepsilon\right) \cdot \cos x + \sin x \cdot \left(\tan x \cdot \tan \varepsilon + -1\right)}{\cos x \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)}\\

\mathbf{else}:\\
\;\;\;\;\varepsilon + x \cdot \left(\varepsilon \cdot \left(\varepsilon + x\right)\right)\\

\end{array}
(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
(FPCore (x eps)
 :precision binary64
 (if (or (<= eps -1.2303582437088547e-37) (not (<= eps 6.370884799891205e-62)))
   (/
    (+
     (* (+ (tan x) (tan eps)) (cos x))
     (* (sin x) (+ (* (tan x) (tan eps)) -1.0)))
    (* (cos x) (- 1.0 (* (tan x) (tan eps)))))
   (+ eps (* x (* eps (+ eps x))))))
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 <= -1.2303582437088547e-37) || !(eps <= 6.370884799891205e-62))) {
		VAR = (((double) (((double) (((double) (((double) tan(x)) + ((double) tan(eps)))) * ((double) cos(x)))) + ((double) (((double) sin(x)) * ((double) (((double) (((double) tan(x)) * ((double) tan(eps)))) + -1.0)))))) / ((double) (((double) cos(x)) * ((double) (1.0 - ((double) (((double) tan(x)) * ((double) tan(eps)))))))));
	} else {
		VAR = ((double) (eps + ((double) (x * ((double) (eps * ((double) (eps + x))))))));
	}
	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.2
Target14.7
Herbie15.9
\[\frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)}\]

Derivation

  1. Split input into 2 regimes
  2. if eps < -1.23035824370885471e-37 or 6.37088479989120464e-62 < eps

    1. Initial program 30.0

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

      \[\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.4

      \[\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}}\]
    6. Simplified4.4

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

    if -1.23035824370885471e-37 < eps < 6.37088479989120464e-62

    1. Initial program 46.9

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

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

      \[\leadsto \color{blue}{\varepsilon + x \cdot \left(\varepsilon \cdot \left(x + \varepsilon\right)\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification15.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -1.2303582437088547 \cdot 10^{-37} \lor \neg \left(\varepsilon \leq 6.370884799891205 \cdot 10^{-62}\right):\\ \;\;\;\;\frac{\left(\tan x + \tan \varepsilon\right) \cdot \cos x + \sin x \cdot \left(\tan x \cdot \tan \varepsilon + -1\right)}{\cos x \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)}\\ \mathbf{else}:\\ \;\;\;\;\varepsilon + x \cdot \left(\varepsilon \cdot \left(\varepsilon + x\right)\right)\\ \end{array}\]

Reproduce

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