Average Error: 37.7 → 15.5
Time: 15.1s
Precision: binary64
\[\tan \left(x + \varepsilon\right) - \tan x\]
\[\begin{array}{l} \mathbf{if}\;\varepsilon \leq -7.780852968026817 \cdot 10^{-23}:\\ \;\;\;\;\frac{\left(\tan x + \tan \varepsilon\right) \cdot \cos x - \left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \sin x}{\cos x \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)}\\ \mathbf{elif}\;\varepsilon \leq 1.6694113497634884 \cdot 10^{-59}:\\ \;\;\;\;\varepsilon + \left(\varepsilon + x\right) \cdot \left(\varepsilon \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}} \cdot \left(1 + \left(\tan x \cdot \tan \varepsilon + \frac{\left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \sin \varepsilon\right)}{\cos \varepsilon}\right)\right) - \tan x\\ \end{array}\]
\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -7.780852968026817 \cdot 10^{-23}:\\
\;\;\;\;\frac{\left(\tan x + \tan \varepsilon\right) \cdot \cos x - \left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \sin x}{\cos x \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}} \cdot \left(1 + \left(\tan x \cdot \tan \varepsilon + \frac{\left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \sin \varepsilon\right)}{\cos \varepsilon}\right)\right) - \tan x\\

\end{array}
(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
(FPCore (x eps)
 :precision binary64
 (if (<= eps -7.780852968026817e-23)
   (/
    (-
     (* (+ (tan x) (tan eps)) (cos x))
     (* (- 1.0 (* (tan x) (tan eps))) (sin x)))
    (* (cos x) (- 1.0 (* (tan x) (tan eps)))))
   (if (<= eps 1.6694113497634884e-59)
     (+ eps (* (+ eps x) (* eps x)))
     (-
      (*
       (/ (+ (tan x) (tan eps)) (- 1.0 (pow (* (tan x) (tan eps)) 3.0)))
       (+
        1.0
        (+
         (* (tan x) (tan eps))
         (/ (* (* (tan x) (tan eps)) (* (tan x) (sin eps))) (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 <= -7.780852968026817e-23) {
		tmp = (((tan(x) + tan(eps)) * cos(x)) - ((1.0 - (tan(x) * tan(eps))) * sin(x))) / (cos(x) * (1.0 - (tan(x) * tan(eps))));
	} else if (eps <= 1.6694113497634884e-59) {
		tmp = eps + ((eps + x) * (eps * x));
	} else {
		tmp = (((tan(x) + tan(eps)) / (1.0 - pow((tan(x) * tan(eps)), 3.0))) * (1.0 + ((tan(x) * tan(eps)) + (((tan(x) * tan(eps)) * (tan(x) * sin(eps))) / 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

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

Derivation

  1. Split input into 3 regimes
  2. if eps < -7.780852968026817e-23

    1. Initial program 30.3

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

      \[\leadsto \tan \left(x + \varepsilon\right) - \color{blue}{\frac{\sin x}{\cos x}}\]
    4. Applied tan-sum_binary64_15771.8

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \frac{\sin x}{\cos x}\]
    5. Applied frac-sub_binary64_14511.8

      \[\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}}\]

    if -7.780852968026817e-23 < eps < 1.66941134976348841e-59

    1. Initial program 46.9

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

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

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

    if 1.66941134976348841e-59 < eps

    1. Initial program 30.8

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

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

      \[\leadsto \frac{\tan x + \tan \varepsilon}{\color{blue}{\frac{{1}^{3} - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}}{1 \cdot 1 + \left(\left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right) + 1 \cdot \left(\tan x \cdot \tan \varepsilon\right)\right)}}} - \tan x\]
    6. Applied associate-/r/_binary64_13885.2

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{{1}^{3} - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}} \cdot \left(1 \cdot 1 + \left(\left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right) + 1 \cdot \left(\tan x \cdot \tan \varepsilon\right)\right)\right)} - \tan x\]
    7. Simplified5.2

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

      \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}} \cdot \left(1 \cdot 1 + \left(\left(\tan x \cdot \color{blue}{\frac{\sin \varepsilon}{\cos \varepsilon}}\right) \cdot \left(\tan x \cdot \tan \varepsilon\right) + 1 \cdot \left(\tan x \cdot \tan \varepsilon\right)\right)\right) - \tan x\]
    10. Applied associate-*r/_binary64_13845.2

      \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}} \cdot \left(1 \cdot 1 + \left(\color{blue}{\frac{\tan x \cdot \sin \varepsilon}{\cos \varepsilon}} \cdot \left(\tan x \cdot \tan \varepsilon\right) + 1 \cdot \left(\tan x \cdot \tan \varepsilon\right)\right)\right) - \tan x\]
    11. Applied associate-*l/_binary64_13855.2

      \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}} \cdot \left(1 \cdot 1 + \left(\color{blue}{\frac{\left(\tan x \cdot \sin \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)}{\cos \varepsilon}} + 1 \cdot \left(\tan x \cdot \tan \varepsilon\right)\right)\right) - \tan x\]
    12. Simplified5.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -7.780852968026817 \cdot 10^{-23}:\\ \;\;\;\;\frac{\left(\tan x + \tan \varepsilon\right) \cdot \cos x - \left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \sin x}{\cos x \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)}\\ \mathbf{elif}\;\varepsilon \leq 1.6694113497634884 \cdot 10^{-59}:\\ \;\;\;\;\varepsilon + \left(\varepsilon + x\right) \cdot \left(\varepsilon \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}} \cdot \left(1 + \left(\tan x \cdot \tan \varepsilon + \frac{\left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \sin \varepsilon\right)}{\cos \varepsilon}\right)\right) - \tan x\\ \end{array}\]

Reproduce

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