Average Error: 37.1 → 15.7
Time: 7.5s
Precision: binary64
\[\tan \left(x + \varepsilon\right) - \tan x\]
\[\begin{array}{l} \mathbf{if}\;\varepsilon \leq -5.059410338124564 \cdot 10^{-113} \lor \neg \left(\varepsilon \leq 3.2766669081460135 \cdot 10^{-68}\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 -5.059410338124564 \cdot 10^{-113} \lor \neg \left(\varepsilon \leq 3.2766669081460135 \cdot 10^{-68}\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 -5.059410338124564e-113)
         (not (<= eps 3.2766669081460135e-68)))
   (/
    (+
     (* (+ (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 tmp;
	if (((eps <= -5.059410338124564e-113) || !(eps <= 3.2766669081460135e-68))) {
		tmp = (((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 {
		tmp = ((double) (eps + ((double) (x * ((double) (eps * ((double) (eps + 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

Original37.1
Target15.5
Herbie15.7
\[\frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)}\]

Derivation

  1. Split input into 2 regimes
  2. if eps < -5.0594103381245639e-113 or 3.2766669081460135e-68 < eps

    1. Initial program Error: 31.5 bits

      \[\tan \left(x + \varepsilon\right) - \tan x\]
    2. Using strategy rm
    3. Applied tan-quotError: 31.3 bits

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

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

      \[\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. SimplifiedError: 7.6 bits

      \[\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 -5.0594103381245639e-113 < eps < 3.2766669081460135e-68

    1. Initial program Error: 47.9 bits

      \[\tan \left(x + \varepsilon\right) - \tan x\]
    2. Taylor expanded around 0 Error: 31.4 bits

      \[\leadsto \color{blue}{x \cdot {\varepsilon}^{2} + \left(\varepsilon + {x}^{2} \cdot \varepsilon\right)}\]
    3. SimplifiedError: 31.1 bits

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -5.059410338124564 \cdot 10^{-113} \lor \neg \left(\varepsilon \leq 3.2766669081460135 \cdot 10^{-68}\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 2020204 
(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)))