Average Error: 37.1 → 0.7
Time: 12.3s
Precision: binary64
\[\tan \left(x + \varepsilon\right) - \tan x\]
\[\begin{array}{l} \mathbf{if}\;\varepsilon \leq -3.1787671774722826 \cdot 10^{-07}:\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 1.5288277488061028 \cdot 10^{-24}:\\ \;\;\;\;\frac{{\sin x}^{3} \cdot {\varepsilon}^{2}}{{\cos x}^{3}} + \left(\frac{\varepsilon \cdot {\sin x}^{2}}{{\cos x}^{2}} + \left(\varepsilon + \frac{\sin x \cdot {\varepsilon}^{2}}{\cos x}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \frac{\tan x \cdot \sin \varepsilon}{\cos \varepsilon}} - \tan x\\ \end{array}\]
\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -3.1787671774722826 \cdot 10^{-07}:\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\

\mathbf{elif}\;\varepsilon \leq 1.5288277488061028 \cdot 10^{-24}:\\
\;\;\;\;\frac{{\sin x}^{3} \cdot {\varepsilon}^{2}}{{\cos x}^{3}} + \left(\frac{\varepsilon \cdot {\sin x}^{2}}{{\cos x}^{2}} + \left(\varepsilon + \frac{\sin x \cdot {\varepsilon}^{2}}{\cos x}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \frac{\tan x \cdot \sin \varepsilon}{\cos \varepsilon}} - \tan x\\

\end{array}
(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
(FPCore (x eps)
 :precision binary64
 (if (<= eps -3.1787671774722826e-07)
   (- (/ (+ (tan x) (tan eps)) (- 1.0 (* (tan x) (tan eps)))) (tan x))
   (if (<= eps 1.5288277488061028e-24)
     (+
      (/ (* (pow (sin x) 3.0) (pow eps 2.0)) (pow (cos x) 3.0))
      (+
       (/ (* eps (pow (sin x) 2.0)) (pow (cos x) 2.0))
       (+ eps (/ (* (sin x) (pow eps 2.0)) (cos x)))))
     (-
      (/ (+ (tan x) (tan eps)) (- 1.0 (/ (* (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 <= -3.1787671774722826e-07) {
		tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) - tan(x);
	} else if (eps <= 1.5288277488061028e-24) {
		tmp = ((pow(sin(x), 3.0) * pow(eps, 2.0)) / pow(cos(x), 3.0)) + (((eps * pow(sin(x), 2.0)) / pow(cos(x), 2.0)) + (eps + ((sin(x) * pow(eps, 2.0)) / cos(x))));
	} else {
		tmp = ((tan(x) + tan(eps)) / (1.0 - ((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.1
Target15.1
Herbie0.7
\[\frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)}\]

Derivation

  1. Split input into 3 regimes
  2. if eps < -3.1787671774722826e-7

    1. Initial program 29.5

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

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

    if -3.1787671774722826e-7 < eps < 1.5288277488061028e-24

    1. Initial program 45.0

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

      \[\leadsto \color{blue}{\frac{{\sin x}^{3} \cdot {\varepsilon}^{2}}{{\cos x}^{3}} + \left(\frac{{\sin x}^{2} \cdot \varepsilon}{{\cos x}^{2}} + \left(\varepsilon + \frac{\sin x \cdot {\varepsilon}^{2}}{\cos x}\right)\right)}\]

    if 1.5288277488061028e-24 < eps

    1. Initial program 30.1

      \[\tan \left(x + \varepsilon\right) - \tan x\]
    2. Using strategy rm
    3. Applied tan-sum_binary64_19181.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_binary64_19421.8

      \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \color{blue}{\frac{\sin \varepsilon}{\cos \varepsilon}}} - \tan x\]
    6. Applied associate-*r/_binary64_17251.8

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

      \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \frac{\color{blue}{\sin \varepsilon \cdot \tan x}}{\cos \varepsilon}} - \tan x\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -3.1787671774722826 \cdot 10^{-07}:\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 1.5288277488061028 \cdot 10^{-24}:\\ \;\;\;\;\frac{{\sin x}^{3} \cdot {\varepsilon}^{2}}{{\cos x}^{3}} + \left(\frac{\varepsilon \cdot {\sin x}^{2}}{{\cos x}^{2}} + \left(\varepsilon + \frac{\sin x \cdot {\varepsilon}^{2}}{\cos x}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \frac{\tan x \cdot \sin \varepsilon}{\cos \varepsilon}} - \tan x\\ \end{array}\]

Reproduce

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