Average Error: 37.1 → 16.1
Time: 9.2s
Precision: binary64
\[\tan \left(x + \varepsilon\right) - \tan x\]
\[\begin{array}{l} \mathbf{if}\;\varepsilon \leq -2.5888280122113803 \cdot 10^{-20}:\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \frac{\tan \varepsilon \cdot \sin x}{\cos x}} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 7.335594256652865 \cdot 10^{-147}:\\ \;\;\;\;\varepsilon + \left(\varepsilon + x\right) \cdot \left(\varepsilon \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \sqrt[3]{{\left(\tan x \cdot \tan \varepsilon\right)}^{3}}} - \tan x\\ \end{array}\]
\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -2.5888280122113803 \cdot 10^{-20}:\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \frac{\tan \varepsilon \cdot \sin x}{\cos x}} - \tan x\\

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

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

\end{array}
(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
(FPCore (x eps)
 :precision binary64
 (if (<= eps -2.5888280122113803e-20)
   (-
    (/ (+ (tan x) (tan eps)) (- 1.0 (/ (* (tan eps) (sin x)) (cos x))))
    (tan x))
   (if (<= eps 7.335594256652865e-147)
     (+ eps (* (+ eps x) (* eps x)))
     (-
      (/ (+ (tan x) (tan eps)) (- 1.0 (cbrt (pow (* (tan x) (tan eps)) 3.0))))
      (tan x)))))
double code(double x, double eps) {
	return tan(x + eps) - tan(x);
}
double code(double x, double eps) {
	double tmp;
	if (eps <= -2.5888280122113803e-20) {
		tmp = ((tan(x) + tan(eps)) / (1.0 - ((tan(eps) * sin(x)) / cos(x)))) - tan(x);
	} else if (eps <= 7.335594256652865e-147) {
		tmp = eps + ((eps + x) * (eps * x));
	} else {
		tmp = ((tan(x) + tan(eps)) / (1.0 - cbrt(pow((tan(x) * tan(eps)), 3.0)))) - 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.2
Herbie16.1
\[\frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)}\]

Derivation

  1. Split input into 3 regimes
  2. if eps < -2.5888280122113803e-20

    1. Initial program 29.8

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

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

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

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

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

    if -2.5888280122113803e-20 < eps < 7.3355942566528652e-147

    1. Initial program 46.7

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

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

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

    if 7.3355942566528652e-147 < eps

    1. Initial program 32.7

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

      \[\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_binary64_181911.9

      \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \color{blue}{\sqrt[3]{\left(\left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)}}} - \tan x\]
    6. Simplified11.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -2.5888280122113803 \cdot 10^{-20}:\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \frac{\tan \varepsilon \cdot \sin x}{\cos x}} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 7.335594256652865 \cdot 10^{-147}:\\ \;\;\;\;\varepsilon + \left(\varepsilon + x\right) \cdot \left(\varepsilon \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \sqrt[3]{{\left(\tan x \cdot \tan \varepsilon\right)}^{3}}} - \tan x\\ \end{array}\]

Reproduce

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