Average Error: 37.3 → 0.6
Time: 11.5s
Precision: binary64
\[\tan \left(x + \varepsilon\right) - \tan x \]
\[\begin{array}{l} t_0 := \tan x \cdot \tan \varepsilon\\ t_1 := -\tan x\\ t_2 := \tan x + \tan \varepsilon\\ t_3 := {\cos x}^{3}\\ \mathbf{if}\;\varepsilon \leq -3.3419396080878345 \cdot 10^{-7}:\\ \;\;\;\;\mathsf{fma}\left(t_2, \frac{1}{\mathsf{fma}\left(1, 1, -t_0\right) + \mathsf{fma}\left(-\tan \varepsilon, \tan x, t_0\right)}, t_1\right)\\ \mathbf{elif}\;\varepsilon \leq 1.155034655722551 \cdot 10^{-21}:\\ \;\;\;\;\frac{{\varepsilon}^{2} \cdot {\sin x}^{3}}{t_3} + \left(\frac{{\varepsilon}^{2} \cdot \sin x}{\cos x} + \left(\varepsilon + \frac{\varepsilon \cdot {\sin x}^{2}}{{\cos x}^{2}}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{t_2}{1 - \frac{{\left(\tan \varepsilon \cdot \sin x\right)}^{3}}{t_3}}, \mathsf{fma}\left(t_0, \mathsf{fma}\left(\tan x, \tan \varepsilon, 1\right), 1\right), t_1\right)\\ \end{array} \]
(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (* (tan x) (tan eps)))
        (t_1 (- (tan x)))
        (t_2 (+ (tan x) (tan eps)))
        (t_3 (pow (cos x) 3.0)))
   (if (<= eps -3.3419396080878345e-7)
     (fma
      t_2
      (/ 1.0 (+ (fma 1.0 1.0 (- t_0)) (fma (- (tan eps)) (tan x) t_0)))
      t_1)
     (if (<= eps 1.155034655722551e-21)
       (+
        (/ (* (pow eps 2.0) (pow (sin x) 3.0)) t_3)
        (+
         (/ (* (pow eps 2.0) (sin x)) (cos x))
         (+ eps (/ (* eps (pow (sin x) 2.0)) (pow (cos x) 2.0)))))
       (fma
        (/ t_2 (- 1.0 (/ (pow (* (tan eps) (sin x)) 3.0) t_3)))
        (fma t_0 (fma (tan x) (tan eps) 1.0) 1.0)
        t_1)))))
double code(double x, double eps) {
	return tan((x + eps)) - tan(x);
}
double code(double x, double eps) {
	double t_0 = tan(x) * tan(eps);
	double t_1 = -tan(x);
	double t_2 = tan(x) + tan(eps);
	double t_3 = pow(cos(x), 3.0);
	double tmp;
	if (eps <= -3.3419396080878345e-7) {
		tmp = fma(t_2, (1.0 / (fma(1.0, 1.0, -t_0) + fma(-tan(eps), tan(x), t_0))), t_1);
	} else if (eps <= 1.155034655722551e-21) {
		tmp = ((pow(eps, 2.0) * pow(sin(x), 3.0)) / t_3) + (((pow(eps, 2.0) * sin(x)) / cos(x)) + (eps + ((eps * pow(sin(x), 2.0)) / pow(cos(x), 2.0))));
	} else {
		tmp = fma((t_2 / (1.0 - (pow((tan(eps) * sin(x)), 3.0) / t_3))), fma(t_0, fma(tan(x), tan(eps), 1.0), 1.0), t_1);
	}
	return tmp;
}
function code(x, eps)
	return Float64(tan(Float64(x + eps)) - tan(x))
end
function code(x, eps)
	t_0 = Float64(tan(x) * tan(eps))
	t_1 = Float64(-tan(x))
	t_2 = Float64(tan(x) + tan(eps))
	t_3 = cos(x) ^ 3.0
	tmp = 0.0
	if (eps <= -3.3419396080878345e-7)
		tmp = fma(t_2, Float64(1.0 / Float64(fma(1.0, 1.0, Float64(-t_0)) + fma(Float64(-tan(eps)), tan(x), t_0))), t_1);
	elseif (eps <= 1.155034655722551e-21)
		tmp = Float64(Float64(Float64((eps ^ 2.0) * (sin(x) ^ 3.0)) / t_3) + Float64(Float64(Float64((eps ^ 2.0) * sin(x)) / cos(x)) + Float64(eps + Float64(Float64(eps * (sin(x) ^ 2.0)) / (cos(x) ^ 2.0)))));
	else
		tmp = fma(Float64(t_2 / Float64(1.0 - Float64((Float64(tan(eps) * sin(x)) ^ 3.0) / t_3))), fma(t_0, fma(tan(x), tan(eps), 1.0), 1.0), t_1);
	end
	return tmp
end
code[x_, eps_] := N[(N[Tan[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]
code[x_, eps_] := Block[{t$95$0 = N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = (-N[Tan[x], $MachinePrecision])}, Block[{t$95$2 = N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Power[N[Cos[x], $MachinePrecision], 3.0], $MachinePrecision]}, If[LessEqual[eps, -3.3419396080878345e-7], N[(t$95$2 * N[(1.0 / N[(N[(1.0 * 1.0 + (-t$95$0)), $MachinePrecision] + N[((-N[Tan[eps], $MachinePrecision]) * N[Tan[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision], If[LessEqual[eps, 1.155034655722551e-21], N[(N[(N[(N[Power[eps, 2.0], $MachinePrecision] * N[Power[N[Sin[x], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] / t$95$3), $MachinePrecision] + N[(N[(N[(N[Power[eps, 2.0], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision] + N[(eps + N[(N[(eps * N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$2 / N[(1.0 - N[(N[Power[N[(N[Tan[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision] / t$95$3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(t$95$0 * N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision] + 1.0), $MachinePrecision] + 1.0), $MachinePrecision] + t$95$1), $MachinePrecision]]]]]]]
\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
t_0 := \tan x \cdot \tan \varepsilon\\
t_1 := -\tan x\\
t_2 := \tan x + \tan \varepsilon\\
t_3 := {\cos x}^{3}\\
\mathbf{if}\;\varepsilon \leq -3.3419396080878345 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(t_2, \frac{1}{\mathsf{fma}\left(1, 1, -t_0\right) + \mathsf{fma}\left(-\tan \varepsilon, \tan x, t_0\right)}, t_1\right)\\

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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{t_2}{1 - \frac{{\left(\tan \varepsilon \cdot \sin x\right)}^{3}}{t_3}}, \mathsf{fma}\left(t_0, \mathsf{fma}\left(\tan x, \tan \varepsilon, 1\right), 1\right), t_1\right)\\


\end{array}

Error

Bits error versus x

Bits error versus eps

Target

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

Derivation

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

    1. Initial program 30.2

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Applied tan-sum_binary640.4

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
    3. Applied *-un-lft-identity_binary640.4

      \[\leadsto \frac{\tan x + \tan \varepsilon}{\color{blue}{1 \cdot 1} - \tan x \cdot \tan \varepsilon} - \tan x \]
    4. Applied prod-diff_binary640.4

      \[\leadsto \frac{\tan x + \tan \varepsilon}{\color{blue}{\mathsf{fma}\left(1, 1, -\tan \varepsilon \cdot \tan x\right) + \mathsf{fma}\left(-\tan \varepsilon, \tan x, \tan \varepsilon \cdot \tan x\right)}} - \tan x \]
    5. Applied div-inv_binary640.4

      \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{\mathsf{fma}\left(1, 1, -\tan \varepsilon \cdot \tan x\right) + \mathsf{fma}\left(-\tan \varepsilon, \tan x, \tan \varepsilon \cdot \tan x\right)}} - \tan x \]
    6. Applied fma-neg_binary640.4

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{\mathsf{fma}\left(1, 1, -\tan \varepsilon \cdot \tan x\right) + \mathsf{fma}\left(-\tan \varepsilon, \tan x, \tan \varepsilon \cdot \tan x\right)}, -\tan x\right)} \]

    if -3.34193960808783449e-7 < eps < 1.15503465572255098e-21

    1. Initial program 45.3

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

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

    if 1.15503465572255098e-21 < eps

    1. Initial program 30.4

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Applied tan-sum_binary641.3

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
    3. Applied add-cube-cbrt_binary641.7

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

      \[\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)}}} - \left(\sqrt[3]{\tan x} \cdot \sqrt[3]{\tan x}\right) \cdot \sqrt[3]{\tan x} \]
    5. Applied associate-/r/_binary641.7

      \[\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)} - \left(\sqrt[3]{\tan x} \cdot \sqrt[3]{\tan x}\right) \cdot \sqrt[3]{\tan x} \]
    6. Applied prod-diff_binary641.7

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\tan x + \tan \varepsilon}{{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), -\sqrt[3]{\tan x} \cdot \left(\sqrt[3]{\tan x} \cdot \sqrt[3]{\tan x}\right)\right) + \mathsf{fma}\left(-\sqrt[3]{\tan x}, \sqrt[3]{\tan x} \cdot \sqrt[3]{\tan x}, \sqrt[3]{\tan x} \cdot \left(\sqrt[3]{\tan x} \cdot \sqrt[3]{\tan x}\right)\right)} \]
    7. Simplified1.3

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\tan x + \tan \varepsilon}{1 - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}}, \mathsf{fma}\left(\tan x \cdot \tan \varepsilon, \mathsf{fma}\left(\tan x, \tan \varepsilon, 1\right), 1\right), -\tan x\right)} + \mathsf{fma}\left(-\sqrt[3]{\tan x}, \sqrt[3]{\tan x} \cdot \sqrt[3]{\tan x}, \sqrt[3]{\tan x} \cdot \left(\sqrt[3]{\tan x} \cdot \sqrt[3]{\tan x}\right)\right) \]
    8. Simplified1.3

      \[\leadsto \mathsf{fma}\left(\frac{\tan x + \tan \varepsilon}{1 - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}}, \mathsf{fma}\left(\tan x \cdot \tan \varepsilon, \mathsf{fma}\left(\tan x, \tan \varepsilon, 1\right), 1\right), -\tan x\right) + \color{blue}{0} \]
    9. Applied tan-quot_binary641.4

      \[\leadsto \mathsf{fma}\left(\frac{\tan x + \tan \varepsilon}{1 - {\left(\color{blue}{\frac{\sin x}{\cos x}} \cdot \tan \varepsilon\right)}^{3}}, \mathsf{fma}\left(\tan x \cdot \tan \varepsilon, \mathsf{fma}\left(\tan x, \tan \varepsilon, 1\right), 1\right), -\tan x\right) + 0 \]
    10. Applied associate-*l/_binary641.4

      \[\leadsto \mathsf{fma}\left(\frac{\tan x + \tan \varepsilon}{1 - {\color{blue}{\left(\frac{\sin x \cdot \tan \varepsilon}{\cos x}\right)}}^{3}}, \mathsf{fma}\left(\tan x \cdot \tan \varepsilon, \mathsf{fma}\left(\tan x, \tan \varepsilon, 1\right), 1\right), -\tan x\right) + 0 \]
    11. Applied cube-div_binary641.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -3.3419396080878345 \cdot 10^{-7}:\\ \;\;\;\;\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{\mathsf{fma}\left(1, 1, -\tan x \cdot \tan \varepsilon\right) + \mathsf{fma}\left(-\tan \varepsilon, \tan x, \tan x \cdot \tan \varepsilon\right)}, -\tan x\right)\\ \mathbf{elif}\;\varepsilon \leq 1.155034655722551 \cdot 10^{-21}:\\ \;\;\;\;\frac{{\varepsilon}^{2} \cdot {\sin x}^{3}}{{\cos x}^{3}} + \left(\frac{{\varepsilon}^{2} \cdot \sin x}{\cos x} + \left(\varepsilon + \frac{\varepsilon \cdot {\sin x}^{2}}{{\cos x}^{2}}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\tan x + \tan \varepsilon}{1 - \frac{{\left(\tan \varepsilon \cdot \sin x\right)}^{3}}{{\cos x}^{3}}}, \mathsf{fma}\left(\tan x \cdot \tan \varepsilon, \mathsf{fma}\left(\tan x, \tan \varepsilon, 1\right), 1\right), -\tan x\right)\\ \end{array} \]

Reproduce

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