Average Error: 36.4 → 15.8
Time: 7.9s
Precision: 64
\[\tan \left(x + \varepsilon\right) - \tan x\]
\[\begin{array}{l} \mathbf{if}\;\varepsilon \le -1.58790806524755116 \cdot 10^{-31} \lor \neg \left(\varepsilon \le 2.27794334900708537 \cdot 10^{-160}\right):\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \frac{\sin x \cdot \sin \varepsilon}{\cos x \cdot \cos \varepsilon}} - \tan x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left({\varepsilon}^{2}, x, \mathsf{fma}\left(\varepsilon, {x}^{2}, \varepsilon\right)\right)\\ \end{array}\]
\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \le -1.58790806524755116 \cdot 10^{-31} \lor \neg \left(\varepsilon \le 2.27794334900708537 \cdot 10^{-160}\right):\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \frac{\sin x \cdot \sin \varepsilon}{\cos x \cdot \cos \varepsilon}} - \tan x\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left({\varepsilon}^{2}, x, \mathsf{fma}\left(\varepsilon, {x}^{2}, \varepsilon\right)\right)\\

\end{array}
double code(double x, double eps) {
	return (tan((x + eps)) - tan(x));
}
double code(double x, double eps) {
	double VAR;
	if (((eps <= -1.5879080652475512e-31) || !(eps <= 2.2779433490070854e-160))) {
		VAR = (((tan(x) + tan(eps)) / (1.0 - ((sin(x) * sin(eps)) / (cos(x) * cos(eps))))) - tan(x));
	} else {
		VAR = fma(pow(eps, 2.0), x, fma(eps, pow(x, 2.0), eps));
	}
	return VAR;
}

Error

Bits error versus x

Bits error versus eps

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original36.4
Target15.1
Herbie15.8
\[\frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)}\]

Derivation

  1. Split input into 2 regimes
  2. if eps < -1.5879080652475512e-31 or 2.2779433490070854e-160 < eps

    1. Initial program 30.8

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

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

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

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

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

    if -1.5879080652475512e-31 < eps < 2.2779433490070854e-160

    1. Initial program 47.6

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left({\varepsilon}^{2}, x, \mathsf{fma}\left(\varepsilon, {x}^{2}, \varepsilon\right)\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification15.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \le -1.58790806524755116 \cdot 10^{-31} \lor \neg \left(\varepsilon \le 2.27794334900708537 \cdot 10^{-160}\right):\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \frac{\sin x \cdot \sin \varepsilon}{\cos x \cdot \cos \varepsilon}} - \tan x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left({\varepsilon}^{2}, x, \mathsf{fma}\left(\varepsilon, {x}^{2}, \varepsilon\right)\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020092 +o rules:numerics
(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)))