Average Error: 37.5 → 15.8
Time: 6.1s
Precision: binary64
\[\tan \left(x + \varepsilon\right) - \tan x\]
\[\begin{array}{l} \mathbf{if}\;\varepsilon \leq -2.8218801393676676 \cdot 10^{-60}:\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \log \left(e^{\tan x \cdot \tan \varepsilon}\right)} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 5.0970138075245553 \cdot 10^{-79}:\\ \;\;\;\;\varepsilon + x \cdot \left(\varepsilon \cdot \left(\varepsilon + x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\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)}\\ \end{array}\]
\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -2.8218801393676676 \cdot 10^{-60}:\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \log \left(e^{\tan x \cdot \tan \varepsilon}\right)} - \tan x\\

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

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

\end{array}
(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
(FPCore (x eps)
 :precision binary64
 (if (<= eps -2.8218801393676676e-60)
   (-
    (/ (+ (tan x) (tan eps)) (- 1.0 (log (exp (* (tan x) (tan eps))))))
    (tan x))
   (if (<= eps 5.0970138075245553e-79)
     (+ eps (* x (* eps (+ eps x))))
     (/
      (-
       (* (+ (tan x) (tan eps)) (cos x))
       (* (- 1.0 (* (tan x) (tan eps))) (sin x)))
      (* (cos x) (- 1.0 (* (tan x) (tan eps))))))))
double code(double x, double eps) {
	return tan(x + eps) - tan(x);
}
double code(double x, double eps) {
	double tmp;
	if (eps <= -2.8218801393676676e-60) {
		tmp = ((tan(x) + tan(eps)) / (1.0 - log(exp(tan(x) * tan(eps))))) - tan(x);
	} else if (eps <= 5.0970138075245553e-79) {
		tmp = eps + (x * (eps * (eps + x)));
	} else {
		tmp = (((tan(x) + tan(eps)) * cos(x)) - ((1.0 - (tan(x) * tan(eps))) * sin(x))) / (cos(x) * (1.0 - (tan(x) * tan(eps))));
	}
	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.5
Target14.8
Herbie15.8
\[\frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)}\]

Derivation

  1. Split input into 3 regimes
  2. if eps < -2.8218801393676676e-60

    1. Initial program 30.5

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

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

      \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \color{blue}{\sqrt[3]{\left(\tan \varepsilon \cdot \tan \varepsilon\right) \cdot \tan \varepsilon}}} - \tan x\]
    6. Applied add-cbrt-cube_binary645.2

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

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

      \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \sqrt[3]{\color{blue}{{\left(\tan x \cdot \tan \varepsilon\right)}^{3}}}} - \tan x\]
    9. Using strategy rm
    10. Applied add-log-exp_binary645.3

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

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

    if -2.8218801393676676e-60 < eps < 5.09701380752455533e-79

    1. Initial program 48.3

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

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

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

    if 5.09701380752455533e-79 < eps

    1. Initial program 30.2

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -2.8218801393676676 \cdot 10^{-60}:\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \log \left(e^{\tan x \cdot \tan \varepsilon}\right)} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 5.0970138075245553 \cdot 10^{-79}:\\ \;\;\;\;\varepsilon + x \cdot \left(\varepsilon \cdot \left(\varepsilon + x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\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)}\\ \end{array}\]

Reproduce

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