2tan (problem 3.3.2)

Percentage Accurate: 42.2% → 99.4%
Time: 16.4s
Alternatives: 14
Speedup: 1.9×

Specification

?
\[\begin{array}{l} \\ \tan \left(x + \varepsilon\right) - \tan x \end{array} \]
(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
double code(double x, double eps) {
	return tan((x + eps)) - tan(x);
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = tan((x + eps)) - tan(x)
end function
public static double code(double x, double eps) {
	return Math.tan((x + eps)) - Math.tan(x);
}
def code(x, eps):
	return math.tan((x + eps)) - math.tan(x)
function code(x, eps)
	return Float64(tan(Float64(x + eps)) - tan(x))
end
function tmp = code(x, eps)
	tmp = tan((x + eps)) - tan(x);
end
code[x_, eps_] := N[(N[Tan[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\tan \left(x + \varepsilon\right) - \tan x
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 14 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 42.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \tan \left(x + \varepsilon\right) - \tan x \end{array} \]
(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
double code(double x, double eps) {
	return tan((x + eps)) - tan(x);
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = tan((x + eps)) - tan(x)
end function
public static double code(double x, double eps) {
	return Math.tan((x + eps)) - Math.tan(x);
}
def code(x, eps):
	return math.tan((x + eps)) - math.tan(x)
function code(x, eps)
	return Float64(tan(Float64(x + eps)) - tan(x))
end
function tmp = code(x, eps)
	tmp = tan((x + eps)) - tan(x);
end
code[x_, eps_] := N[(N[Tan[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\tan \left(x + \varepsilon\right) - \tan x
\end{array}

Alternative 1: 99.4% accurate, 0.2× speedup?

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

\\
\begin{array}{l}
t_0 := \tan x + \tan \varepsilon\\
\mathbf{if}\;\varepsilon \leq -2.6 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(t_0, \frac{1}{1 - \frac{\sin x \cdot \sin \varepsilon}{\cos x \cdot \cos \varepsilon}}, -\tan x\right)\\

\mathbf{elif}\;\varepsilon \leq 2.25 \cdot 10^{-10}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\sin x}{\cos x} + \frac{{\sin x}^{3}}{{\cos x}^{3}}, \varepsilon \cdot \varepsilon, \varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{t_0}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if eps < -2.59999999999999999e-7

    1. Initial program 57.8%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum99.3%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv99.4%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg99.5%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    3. Applied egg-rr99.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Taylor expanded in x around inf 99.6%

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

    if -2.59999999999999999e-7 < eps < 2.25e-10

    1. Initial program 26.3%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum27.1%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv27.1%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg27.1%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    3. Applied egg-rr27.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Taylor expanded in eps around 0 99.6%

      \[\leadsto \color{blue}{\left(\frac{\sin x}{\cos x} + \frac{{\sin x}^{3}}{{\cos x}^{3}}\right) \cdot {\varepsilon}^{2} + \varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)} \]
    5. Step-by-step derivation
      1. fma-def99.6%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\sin x}{\cos x} + \frac{{\sin x}^{3}}{{\cos x}^{3}}, {\varepsilon}^{2}, \varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\right)} \]
      2. unpow299.6%

        \[\leadsto \mathsf{fma}\left(\frac{\sin x}{\cos x} + \frac{{\sin x}^{3}}{{\cos x}^{3}}, \color{blue}{\varepsilon \cdot \varepsilon}, \varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\right) \]
    6. Simplified99.6%

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

    if 2.25e-10 < eps

    1. Initial program 46.3%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum99.6%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv99.6%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg99.6%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Step-by-step derivation
      1. fma-neg99.6%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
      2. associate-*r/99.6%

        \[\leadsto \color{blue}{\frac{\left(\tan x + \tan \varepsilon\right) \cdot 1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. *-rgt-identity99.6%

        \[\leadsto \frac{\color{blue}{\tan x + \tan \varepsilon}}{1 - \tan x \cdot \tan \varepsilon} - \tan x \]
    5. Simplified99.6%

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.6%

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

Alternative 2: 99.4% accurate, 0.2× speedup?

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

\\
\begin{array}{l}
t_0 := \tan x + \tan \varepsilon\\
\mathbf{if}\;\varepsilon \leq -2.9 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(t_0, \frac{1}{1 - \frac{\sin x \cdot \sin \varepsilon}{\cos x \cdot \cos \varepsilon}}, -\tan x\right)\\

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

\mathbf{else}:\\
\;\;\;\;\frac{t_0}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if eps < -2.8999999999999998e-7

    1. Initial program 57.8%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum99.3%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv99.4%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg99.5%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    3. Applied egg-rr99.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Taylor expanded in x around inf 99.6%

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

    if -2.8999999999999998e-7 < eps < 2.25e-10

    1. Initial program 26.3%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum27.1%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. clear-num26.7%

        \[\leadsto \color{blue}{\frac{1}{\frac{1 - \tan x \cdot \tan \varepsilon}{\tan x + \tan \varepsilon}}} - \tan x \]
    3. Applied egg-rr26.7%

      \[\leadsto \color{blue}{\frac{1}{\frac{1 - \tan x \cdot \tan \varepsilon}{\tan x + \tan \varepsilon}}} - \tan x \]
    4. Taylor expanded in eps around 0 99.6%

      \[\leadsto \color{blue}{\varepsilon \cdot \left(1 - -1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right) + -1 \cdot \left({\varepsilon}^{2} \cdot \left(-1 \cdot \frac{{\sin x}^{3}}{{\cos x}^{3}} + -1 \cdot \frac{\sin x}{\cos x}\right)\right)} \]
    5. Step-by-step derivation
      1. mul-1-neg99.6%

        \[\leadsto \varepsilon \cdot \left(1 - -1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right) + \color{blue}{\left(-{\varepsilon}^{2} \cdot \left(-1 \cdot \frac{{\sin x}^{3}}{{\cos x}^{3}} + -1 \cdot \frac{\sin x}{\cos x}\right)\right)} \]
      2. unsub-neg99.6%

        \[\leadsto \color{blue}{\varepsilon \cdot \left(1 - -1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right) - {\varepsilon}^{2} \cdot \left(-1 \cdot \frac{{\sin x}^{3}}{{\cos x}^{3}} + -1 \cdot \frac{\sin x}{\cos x}\right)} \]
      3. cancel-sign-sub-inv99.6%

        \[\leadsto \varepsilon \cdot \color{blue}{\left(1 + \left(--1\right) \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)} - {\varepsilon}^{2} \cdot \left(-1 \cdot \frac{{\sin x}^{3}}{{\cos x}^{3}} + -1 \cdot \frac{\sin x}{\cos x}\right) \]
      4. metadata-eval99.6%

        \[\leadsto \varepsilon \cdot \left(1 + \color{blue}{1} \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right) - {\varepsilon}^{2} \cdot \left(-1 \cdot \frac{{\sin x}^{3}}{{\cos x}^{3}} + -1 \cdot \frac{\sin x}{\cos x}\right) \]
      5. *-lft-identity99.6%

        \[\leadsto \varepsilon \cdot \left(1 + \color{blue}{\frac{{\sin x}^{2}}{{\cos x}^{2}}}\right) - {\varepsilon}^{2} \cdot \left(-1 \cdot \frac{{\sin x}^{3}}{{\cos x}^{3}} + -1 \cdot \frac{\sin x}{\cos x}\right) \]
      6. distribute-lft-in99.6%

        \[\leadsto \color{blue}{\left(\varepsilon \cdot 1 + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)} - {\varepsilon}^{2} \cdot \left(-1 \cdot \frac{{\sin x}^{3}}{{\cos x}^{3}} + -1 \cdot \frac{\sin x}{\cos x}\right) \]
      7. *-rgt-identity99.6%

        \[\leadsto \left(\color{blue}{\varepsilon} + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right) - {\varepsilon}^{2} \cdot \left(-1 \cdot \frac{{\sin x}^{3}}{{\cos x}^{3}} + -1 \cdot \frac{\sin x}{\cos x}\right) \]
    6. Simplified99.6%

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

    if 2.25e-10 < eps

    1. Initial program 46.3%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum99.6%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv99.6%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg99.6%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Step-by-step derivation
      1. fma-neg99.6%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
      2. associate-*r/99.6%

        \[\leadsto \color{blue}{\frac{\left(\tan x + \tan \varepsilon\right) \cdot 1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. *-rgt-identity99.6%

        \[\leadsto \frac{\color{blue}{\tan x + \tan \varepsilon}}{1 - \tan x \cdot \tan \varepsilon} - \tan x \]
    5. Simplified99.6%

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.6%

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

Alternative 3: 99.1% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan x + \tan \varepsilon\\ t_1 := \frac{\sin \varepsilon}{\cos \varepsilon}\\ \mathbf{if}\;\varepsilon \leq -2200:\\ \;\;\;\;\mathsf{fma}\left(t_0, \frac{1}{1 - \frac{\sin x \cdot \sin \varepsilon}{\cos x \cdot \cos \varepsilon}}, -\tan x\right)\\ \mathbf{elif}\;\varepsilon \leq 2.25 \cdot 10^{-10}:\\ \;\;\;\;\frac{t_1}{1 - \frac{\sin x}{\cos x} \cdot t_1} + \frac{\varepsilon}{\frac{{\cos x}^{2}}{{\sin x}^{2}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (+ (tan x) (tan eps))) (t_1 (/ (sin eps) (cos eps))))
   (if (<= eps -2200.0)
     (fma
      t_0
      (/ 1.0 (- 1.0 (/ (* (sin x) (sin eps)) (* (cos x) (cos eps)))))
      (- (tan x)))
     (if (<= eps 2.25e-10)
       (+
        (/ t_1 (- 1.0 (* (/ (sin x) (cos x)) t_1)))
        (/ eps (/ (pow (cos x) 2.0) (pow (sin x) 2.0))))
       (- (/ t_0 (- 1.0 (* (tan x) (tan eps)))) (tan x))))))
double code(double x, double eps) {
	double t_0 = tan(x) + tan(eps);
	double t_1 = sin(eps) / cos(eps);
	double tmp;
	if (eps <= -2200.0) {
		tmp = fma(t_0, (1.0 / (1.0 - ((sin(x) * sin(eps)) / (cos(x) * cos(eps))))), -tan(x));
	} else if (eps <= 2.25e-10) {
		tmp = (t_1 / (1.0 - ((sin(x) / cos(x)) * t_1))) + (eps / (pow(cos(x), 2.0) / pow(sin(x), 2.0)));
	} else {
		tmp = (t_0 / (1.0 - (tan(x) * tan(eps)))) - tan(x);
	}
	return tmp;
}
function code(x, eps)
	t_0 = Float64(tan(x) + tan(eps))
	t_1 = Float64(sin(eps) / cos(eps))
	tmp = 0.0
	if (eps <= -2200.0)
		tmp = fma(t_0, Float64(1.0 / Float64(1.0 - Float64(Float64(sin(x) * sin(eps)) / Float64(cos(x) * cos(eps))))), Float64(-tan(x)));
	elseif (eps <= 2.25e-10)
		tmp = Float64(Float64(t_1 / Float64(1.0 - Float64(Float64(sin(x) / cos(x)) * t_1))) + Float64(eps / Float64((cos(x) ^ 2.0) / (sin(x) ^ 2.0))));
	else
		tmp = Float64(Float64(t_0 / Float64(1.0 - Float64(tan(x) * tan(eps)))) - tan(x));
	end
	return tmp
end
code[x_, eps_] := Block[{t$95$0 = N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Sin[eps], $MachinePrecision] / N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -2200.0], N[(t$95$0 * N[(1.0 / N[(1.0 - N[(N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + (-N[Tan[x], $MachinePrecision])), $MachinePrecision], If[LessEqual[eps, 2.25e-10], N[(N[(t$95$1 / N[(1.0 - N[(N[(N[Sin[x], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(eps / N[(N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 / N[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \tan x + \tan \varepsilon\\
t_1 := \frac{\sin \varepsilon}{\cos \varepsilon}\\
\mathbf{if}\;\varepsilon \leq -2200:\\
\;\;\;\;\mathsf{fma}\left(t_0, \frac{1}{1 - \frac{\sin x \cdot \sin \varepsilon}{\cos x \cdot \cos \varepsilon}}, -\tan x\right)\\

\mathbf{elif}\;\varepsilon \leq 2.25 \cdot 10^{-10}:\\
\;\;\;\;\frac{t_1}{1 - \frac{\sin x}{\cos x} \cdot t_1} + \frac{\varepsilon}{\frac{{\cos x}^{2}}{{\sin x}^{2}}}\\

\mathbf{else}:\\
\;\;\;\;\frac{t_0}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if eps < -2200

    1. Initial program 56.4%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum99.3%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv99.4%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg99.5%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    3. Applied egg-rr99.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Taylor expanded in x around inf 99.6%

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

    if -2200 < eps < 2.25e-10

    1. Initial program 27.5%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum28.2%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv28.2%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg28.2%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    3. Applied egg-rr28.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Taylor expanded in x around inf 28.2%

      \[\leadsto \color{blue}{\left(\frac{\sin \varepsilon}{\cos \varepsilon \cdot \left(1 - \frac{\sin x \cdot \sin \varepsilon}{\cos \varepsilon \cdot \cos x}\right)} + \frac{\sin x}{\cos x \cdot \left(1 - \frac{\sin x \cdot \sin \varepsilon}{\cos \varepsilon \cdot \cos x}\right)}\right) - \frac{\sin x}{\cos x}} \]
    5. Step-by-step derivation
      1. associate--l+55.7%

        \[\leadsto \color{blue}{\frac{\sin \varepsilon}{\cos \varepsilon \cdot \left(1 - \frac{\sin x \cdot \sin \varepsilon}{\cos \varepsilon \cdot \cos x}\right)} + \left(\frac{\sin x}{\cos x \cdot \left(1 - \frac{\sin x \cdot \sin \varepsilon}{\cos \varepsilon \cdot \cos x}\right)} - \frac{\sin x}{\cos x}\right)} \]
      2. associate-/r*55.7%

        \[\leadsto \color{blue}{\frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\sin x \cdot \sin \varepsilon}{\cos \varepsilon \cdot \cos x}}} + \left(\frac{\sin x}{\cos x \cdot \left(1 - \frac{\sin x \cdot \sin \varepsilon}{\cos \varepsilon \cdot \cos x}\right)} - \frac{\sin x}{\cos x}\right) \]
      3. *-commutative55.7%

        \[\leadsto \frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\color{blue}{\sin \varepsilon \cdot \sin x}}{\cos \varepsilon \cdot \cos x}} + \left(\frac{\sin x}{\cos x \cdot \left(1 - \frac{\sin x \cdot \sin \varepsilon}{\cos \varepsilon \cdot \cos x}\right)} - \frac{\sin x}{\cos x}\right) \]
      4. times-frac55.7%

        \[\leadsto \frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \color{blue}{\frac{\sin \varepsilon}{\cos \varepsilon} \cdot \frac{\sin x}{\cos x}}} + \left(\frac{\sin x}{\cos x \cdot \left(1 - \frac{\sin x \cdot \sin \varepsilon}{\cos \varepsilon \cdot \cos x}\right)} - \frac{\sin x}{\cos x}\right) \]
    6. Simplified55.7%

      \[\leadsto \color{blue}{\frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\sin \varepsilon}{\cos \varepsilon} \cdot \frac{\sin x}{\cos x}} + \left(\frac{\frac{\sin x}{\cos x}}{1 - \frac{\sin \varepsilon}{\cos \varepsilon} \cdot \frac{\sin x}{\cos x}} - \frac{\sin x}{\cos x}\right)} \]
    7. Step-by-step derivation
      1. tan-quot55.7%

        \[\leadsto \frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\sin \varepsilon}{\cos \varepsilon} \cdot \frac{\sin x}{\cos x}} + \left(\frac{\frac{\sin x}{\cos x}}{1 - \color{blue}{\tan \varepsilon} \cdot \frac{\sin x}{\cos x}} - \frac{\sin x}{\cos x}\right) \]
      2. tan-quot55.7%

        \[\leadsto \frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\sin \varepsilon}{\cos \varepsilon} \cdot \frac{\sin x}{\cos x}} + \left(\frac{\frac{\sin x}{\cos x}}{1 - \tan \varepsilon \cdot \color{blue}{\tan x}} - \frac{\sin x}{\cos x}\right) \]
      3. *-commutative55.7%

        \[\leadsto \frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\sin \varepsilon}{\cos \varepsilon} \cdot \frac{\sin x}{\cos x}} + \left(\frac{\frac{\sin x}{\cos x}}{1 - \color{blue}{\tan x \cdot \tan \varepsilon}} - \frac{\sin x}{\cos x}\right) \]
      4. pow155.7%

        \[\leadsto \frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\sin \varepsilon}{\cos \varepsilon} \cdot \frac{\sin x}{\cos x}} + \left(\frac{\frac{\sin x}{\cos x}}{1 - \color{blue}{{\left(\tan x \cdot \tan \varepsilon\right)}^{1}}} - \frac{\sin x}{\cos x}\right) \]
    8. Applied egg-rr55.7%

      \[\leadsto \frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\sin \varepsilon}{\cos \varepsilon} \cdot \frac{\sin x}{\cos x}} + \left(\frac{\frac{\sin x}{\cos x}}{1 - \color{blue}{{\left(\tan x \cdot \tan \varepsilon\right)}^{1}}} - \frac{\sin x}{\cos x}\right) \]
    9. Step-by-step derivation
      1. unpow155.7%

        \[\leadsto \frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\sin \varepsilon}{\cos \varepsilon} \cdot \frac{\sin x}{\cos x}} + \left(\frac{\frac{\sin x}{\cos x}}{1 - \color{blue}{\tan x \cdot \tan \varepsilon}} - \frac{\sin x}{\cos x}\right) \]
    10. Simplified55.7%

      \[\leadsto \frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\sin \varepsilon}{\cos \varepsilon} \cdot \frac{\sin x}{\cos x}} + \left(\frac{\frac{\sin x}{\cos x}}{1 - \color{blue}{\tan x \cdot \tan \varepsilon}} - \frac{\sin x}{\cos x}\right) \]
    11. Taylor expanded in eps around 0 99.3%

      \[\leadsto \frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\sin \varepsilon}{\cos \varepsilon} \cdot \frac{\sin x}{\cos x}} + \color{blue}{\frac{\varepsilon \cdot {\sin x}^{2}}{{\cos x}^{2}}} \]
    12. Step-by-step derivation
      1. associate-/l*99.2%

        \[\leadsto \frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\sin \varepsilon}{\cos \varepsilon} \cdot \frac{\sin x}{\cos x}} + \color{blue}{\frac{\varepsilon}{\frac{{\cos x}^{2}}{{\sin x}^{2}}}} \]
    13. Simplified99.2%

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

    if 2.25e-10 < eps

    1. Initial program 46.3%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum99.6%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv99.6%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg99.6%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Step-by-step derivation
      1. fma-neg99.6%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
      2. associate-*r/99.6%

        \[\leadsto \color{blue}{\frac{\left(\tan x + \tan \varepsilon\right) \cdot 1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. *-rgt-identity99.6%

        \[\leadsto \frac{\color{blue}{\tan x + \tan \varepsilon}}{1 - \tan x \cdot \tan \varepsilon} - \tan x \]
    5. Simplified99.6%

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

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

Alternative 4: 99.1% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan x + \tan \varepsilon\\ t_1 := \frac{\sin \varepsilon}{\cos \varepsilon}\\ \mathbf{if}\;\varepsilon \leq -2200:\\ \;\;\;\;\mathsf{fma}\left(t_0, \frac{1}{1 - \frac{\sin x \cdot \sin \varepsilon}{\cos x \cdot \cos \varepsilon}}, -\tan x\right)\\ \mathbf{elif}\;\varepsilon \leq 2.25 \cdot 10^{-10}:\\ \;\;\;\;\frac{t_1}{1 - \frac{\sin x}{\cos x} \cdot t_1} + \frac{\varepsilon \cdot {\sin x}^{2}}{{\cos x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (+ (tan x) (tan eps))) (t_1 (/ (sin eps) (cos eps))))
   (if (<= eps -2200.0)
     (fma
      t_0
      (/ 1.0 (- 1.0 (/ (* (sin x) (sin eps)) (* (cos x) (cos eps)))))
      (- (tan x)))
     (if (<= eps 2.25e-10)
       (+
        (/ t_1 (- 1.0 (* (/ (sin x) (cos x)) t_1)))
        (/ (* eps (pow (sin x) 2.0)) (pow (cos x) 2.0)))
       (- (/ t_0 (- 1.0 (* (tan x) (tan eps)))) (tan x))))))
double code(double x, double eps) {
	double t_0 = tan(x) + tan(eps);
	double t_1 = sin(eps) / cos(eps);
	double tmp;
	if (eps <= -2200.0) {
		tmp = fma(t_0, (1.0 / (1.0 - ((sin(x) * sin(eps)) / (cos(x) * cos(eps))))), -tan(x));
	} else if (eps <= 2.25e-10) {
		tmp = (t_1 / (1.0 - ((sin(x) / cos(x)) * t_1))) + ((eps * pow(sin(x), 2.0)) / pow(cos(x), 2.0));
	} else {
		tmp = (t_0 / (1.0 - (tan(x) * tan(eps)))) - tan(x);
	}
	return tmp;
}
function code(x, eps)
	t_0 = Float64(tan(x) + tan(eps))
	t_1 = Float64(sin(eps) / cos(eps))
	tmp = 0.0
	if (eps <= -2200.0)
		tmp = fma(t_0, Float64(1.0 / Float64(1.0 - Float64(Float64(sin(x) * sin(eps)) / Float64(cos(x) * cos(eps))))), Float64(-tan(x)));
	elseif (eps <= 2.25e-10)
		tmp = Float64(Float64(t_1 / Float64(1.0 - Float64(Float64(sin(x) / cos(x)) * t_1))) + Float64(Float64(eps * (sin(x) ^ 2.0)) / (cos(x) ^ 2.0)));
	else
		tmp = Float64(Float64(t_0 / Float64(1.0 - Float64(tan(x) * tan(eps)))) - tan(x));
	end
	return tmp
end
code[x_, eps_] := Block[{t$95$0 = N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Sin[eps], $MachinePrecision] / N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -2200.0], N[(t$95$0 * N[(1.0 / N[(1.0 - N[(N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + (-N[Tan[x], $MachinePrecision])), $MachinePrecision], If[LessEqual[eps, 2.25e-10], N[(N[(t$95$1 / N[(1.0 - N[(N[(N[Sin[x], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(eps * N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 / N[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \tan x + \tan \varepsilon\\
t_1 := \frac{\sin \varepsilon}{\cos \varepsilon}\\
\mathbf{if}\;\varepsilon \leq -2200:\\
\;\;\;\;\mathsf{fma}\left(t_0, \frac{1}{1 - \frac{\sin x \cdot \sin \varepsilon}{\cos x \cdot \cos \varepsilon}}, -\tan x\right)\\

\mathbf{elif}\;\varepsilon \leq 2.25 \cdot 10^{-10}:\\
\;\;\;\;\frac{t_1}{1 - \frac{\sin x}{\cos x} \cdot t_1} + \frac{\varepsilon \cdot {\sin x}^{2}}{{\cos x}^{2}}\\

\mathbf{else}:\\
\;\;\;\;\frac{t_0}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if eps < -2200

    1. Initial program 56.4%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum99.3%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv99.4%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg99.5%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    3. Applied egg-rr99.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Taylor expanded in x around inf 99.6%

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

    if -2200 < eps < 2.25e-10

    1. Initial program 27.5%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum28.2%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv28.2%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg28.2%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    3. Applied egg-rr28.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Taylor expanded in x around inf 28.2%

      \[\leadsto \color{blue}{\left(\frac{\sin \varepsilon}{\cos \varepsilon \cdot \left(1 - \frac{\sin x \cdot \sin \varepsilon}{\cos \varepsilon \cdot \cos x}\right)} + \frac{\sin x}{\cos x \cdot \left(1 - \frac{\sin x \cdot \sin \varepsilon}{\cos \varepsilon \cdot \cos x}\right)}\right) - \frac{\sin x}{\cos x}} \]
    5. Step-by-step derivation
      1. associate--l+55.7%

        \[\leadsto \color{blue}{\frac{\sin \varepsilon}{\cos \varepsilon \cdot \left(1 - \frac{\sin x \cdot \sin \varepsilon}{\cos \varepsilon \cdot \cos x}\right)} + \left(\frac{\sin x}{\cos x \cdot \left(1 - \frac{\sin x \cdot \sin \varepsilon}{\cos \varepsilon \cdot \cos x}\right)} - \frac{\sin x}{\cos x}\right)} \]
      2. associate-/r*55.7%

        \[\leadsto \color{blue}{\frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\sin x \cdot \sin \varepsilon}{\cos \varepsilon \cdot \cos x}}} + \left(\frac{\sin x}{\cos x \cdot \left(1 - \frac{\sin x \cdot \sin \varepsilon}{\cos \varepsilon \cdot \cos x}\right)} - \frac{\sin x}{\cos x}\right) \]
      3. *-commutative55.7%

        \[\leadsto \frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\color{blue}{\sin \varepsilon \cdot \sin x}}{\cos \varepsilon \cdot \cos x}} + \left(\frac{\sin x}{\cos x \cdot \left(1 - \frac{\sin x \cdot \sin \varepsilon}{\cos \varepsilon \cdot \cos x}\right)} - \frac{\sin x}{\cos x}\right) \]
      4. times-frac55.7%

        \[\leadsto \frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \color{blue}{\frac{\sin \varepsilon}{\cos \varepsilon} \cdot \frac{\sin x}{\cos x}}} + \left(\frac{\sin x}{\cos x \cdot \left(1 - \frac{\sin x \cdot \sin \varepsilon}{\cos \varepsilon \cdot \cos x}\right)} - \frac{\sin x}{\cos x}\right) \]
    6. Simplified55.7%

      \[\leadsto \color{blue}{\frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\sin \varepsilon}{\cos \varepsilon} \cdot \frac{\sin x}{\cos x}} + \left(\frac{\frac{\sin x}{\cos x}}{1 - \frac{\sin \varepsilon}{\cos \varepsilon} \cdot \frac{\sin x}{\cos x}} - \frac{\sin x}{\cos x}\right)} \]
    7. Taylor expanded in eps around 0 99.3%

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

    if 2.25e-10 < eps

    1. Initial program 46.3%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum99.6%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv99.6%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg99.6%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Step-by-step derivation
      1. fma-neg99.6%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
      2. associate-*r/99.6%

        \[\leadsto \color{blue}{\frac{\left(\tan x + \tan \varepsilon\right) \cdot 1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. *-rgt-identity99.6%

        \[\leadsto \frac{\color{blue}{\tan x + \tan \varepsilon}}{1 - \tan x \cdot \tan \varepsilon} - \tan x \]
    5. Simplified99.6%

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

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

Alternative 5: 99.3% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan x + \tan \varepsilon\\ \mathbf{if}\;\varepsilon \leq -7.1 \cdot 10^{-9}:\\ \;\;\;\;\mathsf{fma}\left(t_0, \frac{1}{1 - \frac{\sin x \cdot \sin \varepsilon}{\cos x \cdot \cos \varepsilon}}, -\tan x\right)\\ \mathbf{elif}\;\varepsilon \leq 2.25 \cdot 10^{-10}:\\ \;\;\;\;\varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (+ (tan x) (tan eps))))
   (if (<= eps -7.1e-9)
     (fma
      t_0
      (/ 1.0 (- 1.0 (/ (* (sin x) (sin eps)) (* (cos x) (cos eps)))))
      (- (tan x)))
     (if (<= eps 2.25e-10)
       (* eps (+ 1.0 (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))
       (- (/ t_0 (- 1.0 (* (tan x) (tan eps)))) (tan x))))))
double code(double x, double eps) {
	double t_0 = tan(x) + tan(eps);
	double tmp;
	if (eps <= -7.1e-9) {
		tmp = fma(t_0, (1.0 / (1.0 - ((sin(x) * sin(eps)) / (cos(x) * cos(eps))))), -tan(x));
	} else if (eps <= 2.25e-10) {
		tmp = eps * (1.0 + (pow(sin(x), 2.0) / pow(cos(x), 2.0)));
	} else {
		tmp = (t_0 / (1.0 - (tan(x) * tan(eps)))) - tan(x);
	}
	return tmp;
}
function code(x, eps)
	t_0 = Float64(tan(x) + tan(eps))
	tmp = 0.0
	if (eps <= -7.1e-9)
		tmp = fma(t_0, Float64(1.0 / Float64(1.0 - Float64(Float64(sin(x) * sin(eps)) / Float64(cos(x) * cos(eps))))), Float64(-tan(x)));
	elseif (eps <= 2.25e-10)
		tmp = Float64(eps * Float64(1.0 + Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0))));
	else
		tmp = Float64(Float64(t_0 / Float64(1.0 - Float64(tan(x) * tan(eps)))) - tan(x));
	end
	return tmp
end
code[x_, eps_] := Block[{t$95$0 = N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -7.1e-9], N[(t$95$0 * N[(1.0 / N[(1.0 - N[(N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + (-N[Tan[x], $MachinePrecision])), $MachinePrecision], If[LessEqual[eps, 2.25e-10], N[(eps * N[(1.0 + N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 / N[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \tan x + \tan \varepsilon\\
\mathbf{if}\;\varepsilon \leq -7.1 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(t_0, \frac{1}{1 - \frac{\sin x \cdot \sin \varepsilon}{\cos x \cdot \cos \varepsilon}}, -\tan x\right)\\

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

\mathbf{else}:\\
\;\;\;\;\frac{t_0}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if eps < -7.09999999999999988e-9

    1. Initial program 57.8%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum99.3%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv99.4%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg99.5%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    3. Applied egg-rr99.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Taylor expanded in x around inf 99.6%

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

    if -7.09999999999999988e-9 < eps < 2.25e-10

    1. Initial program 26.3%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum27.1%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv27.1%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg27.1%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    3. Applied egg-rr27.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Taylor expanded in eps around 0 99.2%

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

    if 2.25e-10 < eps

    1. Initial program 46.3%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum99.6%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv99.6%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg99.6%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Step-by-step derivation
      1. fma-neg99.6%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
      2. associate-*r/99.6%

        \[\leadsto \color{blue}{\frac{\left(\tan x + \tan \varepsilon\right) \cdot 1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. *-rgt-identity99.6%

        \[\leadsto \frac{\color{blue}{\tan x + \tan \varepsilon}}{1 - \tan x \cdot \tan \varepsilon} - \tan x \]
    5. Simplified99.6%

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

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

Alternative 6: 99.3% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan x \cdot \tan \varepsilon\\ t_1 := \tan x + \tan \varepsilon\\ \mathbf{if}\;\varepsilon \leq -7.1 \cdot 10^{-9}:\\ \;\;\;\;\mathsf{fma}\left(t_1, \frac{1}{1 + \left(1 - \left(1 + t_0\right)\right)}, -\tan x\right)\\ \mathbf{elif}\;\varepsilon \leq 2.25 \cdot 10^{-10}:\\ \;\;\;\;\varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{t_1}{1 - t_0} - \tan x\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (* (tan x) (tan eps))) (t_1 (+ (tan x) (tan eps))))
   (if (<= eps -7.1e-9)
     (fma t_1 (/ 1.0 (+ 1.0 (- 1.0 (+ 1.0 t_0)))) (- (tan x)))
     (if (<= eps 2.25e-10)
       (* eps (+ 1.0 (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))
       (- (/ t_1 (- 1.0 t_0)) (tan x))))))
double code(double x, double eps) {
	double t_0 = tan(x) * tan(eps);
	double t_1 = tan(x) + tan(eps);
	double tmp;
	if (eps <= -7.1e-9) {
		tmp = fma(t_1, (1.0 / (1.0 + (1.0 - (1.0 + t_0)))), -tan(x));
	} else if (eps <= 2.25e-10) {
		tmp = eps * (1.0 + (pow(sin(x), 2.0) / pow(cos(x), 2.0)));
	} else {
		tmp = (t_1 / (1.0 - t_0)) - tan(x);
	}
	return tmp;
}
function code(x, eps)
	t_0 = Float64(tan(x) * tan(eps))
	t_1 = Float64(tan(x) + tan(eps))
	tmp = 0.0
	if (eps <= -7.1e-9)
		tmp = fma(t_1, Float64(1.0 / Float64(1.0 + Float64(1.0 - Float64(1.0 + t_0)))), Float64(-tan(x)));
	elseif (eps <= 2.25e-10)
		tmp = Float64(eps * Float64(1.0 + Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0))));
	else
		tmp = Float64(Float64(t_1 / Float64(1.0 - t_0)) - tan(x));
	end
	return tmp
end
code[x_, eps_] := Block[{t$95$0 = N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -7.1e-9], N[(t$95$1 * N[(1.0 / N[(1.0 + N[(1.0 - N[(1.0 + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + (-N[Tan[x], $MachinePrecision])), $MachinePrecision], If[LessEqual[eps, 2.25e-10], N[(eps * N[(1.0 + N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$1 / N[(1.0 - t$95$0), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \tan x \cdot \tan \varepsilon\\
t_1 := \tan x + \tan \varepsilon\\
\mathbf{if}\;\varepsilon \leq -7.1 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(t_1, \frac{1}{1 + \left(1 - \left(1 + t_0\right)\right)}, -\tan x\right)\\

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

\mathbf{else}:\\
\;\;\;\;\frac{t_1}{1 - t_0} - \tan x\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if eps < -7.09999999999999988e-9

    1. Initial program 57.8%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum99.3%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv99.4%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg99.5%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    3. Applied egg-rr99.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Step-by-step derivation
      1. expm1-log1p-u94.7%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\tan x \cdot \tan \varepsilon\right)\right)}}, -\tan x\right) \]
      2. expm1-udef94.8%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \color{blue}{\left(e^{\mathsf{log1p}\left(\tan x \cdot \tan \varepsilon\right)} - 1\right)}}, -\tan x\right) \]
      3. log1p-udef94.9%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \left(e^{\color{blue}{\log \left(1 + \tan x \cdot \tan \varepsilon\right)}} - 1\right)}, -\tan x\right) \]
      4. add-exp-log99.6%

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

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

    if -7.09999999999999988e-9 < eps < 2.25e-10

    1. Initial program 26.3%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum27.1%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv27.1%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg27.1%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    3. Applied egg-rr27.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Taylor expanded in eps around 0 99.2%

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

    if 2.25e-10 < eps

    1. Initial program 46.3%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum99.6%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv99.6%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg99.6%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Step-by-step derivation
      1. fma-neg99.6%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
      2. associate-*r/99.6%

        \[\leadsto \color{blue}{\frac{\left(\tan x + \tan \varepsilon\right) \cdot 1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. *-rgt-identity99.6%

        \[\leadsto \frac{\color{blue}{\tan x + \tan \varepsilon}}{1 - \tan x \cdot \tan \varepsilon} - \tan x \]
    5. Simplified99.6%

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

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

Alternative 7: 99.3% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan x + \tan \varepsilon\\ t_1 := 1 - \tan x \cdot \tan \varepsilon\\ \mathbf{if}\;\varepsilon \leq -7.1 \cdot 10^{-9}:\\ \;\;\;\;\mathsf{fma}\left(t_0, \frac{1}{t_1}, -\tan x\right)\\ \mathbf{elif}\;\varepsilon \leq 2.25 \cdot 10^{-10}:\\ \;\;\;\;\varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{t_1} - \tan x\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (+ (tan x) (tan eps))) (t_1 (- 1.0 (* (tan x) (tan eps)))))
   (if (<= eps -7.1e-9)
     (fma t_0 (/ 1.0 t_1) (- (tan x)))
     (if (<= eps 2.25e-10)
       (* eps (+ 1.0 (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))
       (- (/ t_0 t_1) (tan x))))))
double code(double x, double eps) {
	double t_0 = tan(x) + tan(eps);
	double t_1 = 1.0 - (tan(x) * tan(eps));
	double tmp;
	if (eps <= -7.1e-9) {
		tmp = fma(t_0, (1.0 / t_1), -tan(x));
	} else if (eps <= 2.25e-10) {
		tmp = eps * (1.0 + (pow(sin(x), 2.0) / pow(cos(x), 2.0)));
	} else {
		tmp = (t_0 / t_1) - tan(x);
	}
	return tmp;
}
function code(x, eps)
	t_0 = Float64(tan(x) + tan(eps))
	t_1 = Float64(1.0 - Float64(tan(x) * tan(eps)))
	tmp = 0.0
	if (eps <= -7.1e-9)
		tmp = fma(t_0, Float64(1.0 / t_1), Float64(-tan(x)));
	elseif (eps <= 2.25e-10)
		tmp = Float64(eps * Float64(1.0 + Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0))));
	else
		tmp = Float64(Float64(t_0 / t_1) - tan(x));
	end
	return tmp
end
code[x_, eps_] := Block[{t$95$0 = N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -7.1e-9], N[(t$95$0 * N[(1.0 / t$95$1), $MachinePrecision] + (-N[Tan[x], $MachinePrecision])), $MachinePrecision], If[LessEqual[eps, 2.25e-10], N[(eps * N[(1.0 + N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 / t$95$1), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \tan x + \tan \varepsilon\\
t_1 := 1 - \tan x \cdot \tan \varepsilon\\
\mathbf{if}\;\varepsilon \leq -7.1 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(t_0, \frac{1}{t_1}, -\tan x\right)\\

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

\mathbf{else}:\\
\;\;\;\;\frac{t_0}{t_1} - \tan x\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if eps < -7.09999999999999988e-9

    1. Initial program 57.8%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum99.3%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv99.4%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg99.5%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    3. Applied egg-rr99.5%

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

    if -7.09999999999999988e-9 < eps < 2.25e-10

    1. Initial program 26.3%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum27.1%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv27.1%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg27.1%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    3. Applied egg-rr27.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Taylor expanded in eps around 0 99.2%

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

    if 2.25e-10 < eps

    1. Initial program 46.3%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum99.6%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv99.6%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg99.6%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Step-by-step derivation
      1. fma-neg99.6%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
      2. associate-*r/99.6%

        \[\leadsto \color{blue}{\frac{\left(\tan x + \tan \varepsilon\right) \cdot 1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. *-rgt-identity99.6%

        \[\leadsto \frac{\color{blue}{\tan x + \tan \varepsilon}}{1 - \tan x \cdot \tan \varepsilon} - \tan x \]
    5. Simplified99.6%

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

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

Alternative 8: 99.3% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\varepsilon \leq -7.1 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 2.25 \cdot 10^{-10}\right):\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\ \mathbf{else}:\\ \;\;\;\;\varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (if (or (<= eps -7.1e-9) (not (<= eps 2.25e-10)))
   (- (/ (+ (tan x) (tan eps)) (- 1.0 (* (tan x) (tan eps)))) (tan x))
   (* eps (+ 1.0 (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))))
double code(double x, double eps) {
	double tmp;
	if ((eps <= -7.1e-9) || !(eps <= 2.25e-10)) {
		tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) - tan(x);
	} else {
		tmp = eps * (1.0 + (pow(sin(x), 2.0) / pow(cos(x), 2.0)));
	}
	return tmp;
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    real(8) :: tmp
    if ((eps <= (-7.1d-9)) .or. (.not. (eps <= 2.25d-10))) then
        tmp = ((tan(x) + tan(eps)) / (1.0d0 - (tan(x) * tan(eps)))) - tan(x)
    else
        tmp = eps * (1.0d0 + ((sin(x) ** 2.0d0) / (cos(x) ** 2.0d0)))
    end if
    code = tmp
end function
public static double code(double x, double eps) {
	double tmp;
	if ((eps <= -7.1e-9) || !(eps <= 2.25e-10)) {
		tmp = ((Math.tan(x) + Math.tan(eps)) / (1.0 - (Math.tan(x) * Math.tan(eps)))) - Math.tan(x);
	} else {
		tmp = eps * (1.0 + (Math.pow(Math.sin(x), 2.0) / Math.pow(Math.cos(x), 2.0)));
	}
	return tmp;
}
def code(x, eps):
	tmp = 0
	if (eps <= -7.1e-9) or not (eps <= 2.25e-10):
		tmp = ((math.tan(x) + math.tan(eps)) / (1.0 - (math.tan(x) * math.tan(eps)))) - math.tan(x)
	else:
		tmp = eps * (1.0 + (math.pow(math.sin(x), 2.0) / math.pow(math.cos(x), 2.0)))
	return tmp
function code(x, eps)
	tmp = 0.0
	if ((eps <= -7.1e-9) || !(eps <= 2.25e-10))
		tmp = Float64(Float64(Float64(tan(x) + tan(eps)) / Float64(1.0 - Float64(tan(x) * tan(eps)))) - tan(x));
	else
		tmp = Float64(eps * Float64(1.0 + Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0))));
	end
	return tmp
end
function tmp_2 = code(x, eps)
	tmp = 0.0;
	if ((eps <= -7.1e-9) || ~((eps <= 2.25e-10)))
		tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) - tan(x);
	else
		tmp = eps * (1.0 + ((sin(x) ^ 2.0) / (cos(x) ^ 2.0)));
	end
	tmp_2 = tmp;
end
code[x_, eps_] := If[Or[LessEqual[eps, -7.1e-9], N[Not[LessEqual[eps, 2.25e-10]], $MachinePrecision]], N[(N[(N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], N[(eps * N[(1.0 + N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -7.1 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 2.25 \cdot 10^{-10}\right):\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\

\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if eps < -7.09999999999999988e-9 or 2.25e-10 < eps

    1. Initial program 52.0%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum99.5%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv99.5%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg99.5%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    3. Applied egg-rr99.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Step-by-step derivation
      1. fma-neg99.5%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
      2. associate-*r/99.5%

        \[\leadsto \color{blue}{\frac{\left(\tan x + \tan \varepsilon\right) \cdot 1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. *-rgt-identity99.5%

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

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

    if -7.09999999999999988e-9 < eps < 2.25e-10

    1. Initial program 26.3%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum27.1%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv27.1%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg27.1%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    3. Applied egg-rr27.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Taylor expanded in eps around 0 99.2%

      \[\leadsto \color{blue}{\varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -7.1 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 2.25 \cdot 10^{-10}\right):\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\ \mathbf{else}:\\ \;\;\;\;\varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\\ \end{array} \]

Alternative 9: 99.3% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan x + \tan \varepsilon\\ t_1 := 1 - \tan x \cdot \tan \varepsilon\\ \mathbf{if}\;\varepsilon \leq -7.1 \cdot 10^{-9}:\\ \;\;\;\;t_0 \cdot \frac{1}{t_1} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 2.25 \cdot 10^{-10}:\\ \;\;\;\;\varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{t_1} - \tan x\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (+ (tan x) (tan eps))) (t_1 (- 1.0 (* (tan x) (tan eps)))))
   (if (<= eps -7.1e-9)
     (- (* t_0 (/ 1.0 t_1)) (tan x))
     (if (<= eps 2.25e-10)
       (* eps (+ 1.0 (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))
       (- (/ t_0 t_1) (tan x))))))
double code(double x, double eps) {
	double t_0 = tan(x) + tan(eps);
	double t_1 = 1.0 - (tan(x) * tan(eps));
	double tmp;
	if (eps <= -7.1e-9) {
		tmp = (t_0 * (1.0 / t_1)) - tan(x);
	} else if (eps <= 2.25e-10) {
		tmp = eps * (1.0 + (pow(sin(x), 2.0) / pow(cos(x), 2.0)));
	} else {
		tmp = (t_0 / t_1) - tan(x);
	}
	return tmp;
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = tan(x) + tan(eps)
    t_1 = 1.0d0 - (tan(x) * tan(eps))
    if (eps <= (-7.1d-9)) then
        tmp = (t_0 * (1.0d0 / t_1)) - tan(x)
    else if (eps <= 2.25d-10) then
        tmp = eps * (1.0d0 + ((sin(x) ** 2.0d0) / (cos(x) ** 2.0d0)))
    else
        tmp = (t_0 / t_1) - tan(x)
    end if
    code = tmp
end function
public static double code(double x, double eps) {
	double t_0 = Math.tan(x) + Math.tan(eps);
	double t_1 = 1.0 - (Math.tan(x) * Math.tan(eps));
	double tmp;
	if (eps <= -7.1e-9) {
		tmp = (t_0 * (1.0 / t_1)) - Math.tan(x);
	} else if (eps <= 2.25e-10) {
		tmp = eps * (1.0 + (Math.pow(Math.sin(x), 2.0) / Math.pow(Math.cos(x), 2.0)));
	} else {
		tmp = (t_0 / t_1) - Math.tan(x);
	}
	return tmp;
}
def code(x, eps):
	t_0 = math.tan(x) + math.tan(eps)
	t_1 = 1.0 - (math.tan(x) * math.tan(eps))
	tmp = 0
	if eps <= -7.1e-9:
		tmp = (t_0 * (1.0 / t_1)) - math.tan(x)
	elif eps <= 2.25e-10:
		tmp = eps * (1.0 + (math.pow(math.sin(x), 2.0) / math.pow(math.cos(x), 2.0)))
	else:
		tmp = (t_0 / t_1) - math.tan(x)
	return tmp
function code(x, eps)
	t_0 = Float64(tan(x) + tan(eps))
	t_1 = Float64(1.0 - Float64(tan(x) * tan(eps)))
	tmp = 0.0
	if (eps <= -7.1e-9)
		tmp = Float64(Float64(t_0 * Float64(1.0 / t_1)) - tan(x));
	elseif (eps <= 2.25e-10)
		tmp = Float64(eps * Float64(1.0 + Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0))));
	else
		tmp = Float64(Float64(t_0 / t_1) - tan(x));
	end
	return tmp
end
function tmp_2 = code(x, eps)
	t_0 = tan(x) + tan(eps);
	t_1 = 1.0 - (tan(x) * tan(eps));
	tmp = 0.0;
	if (eps <= -7.1e-9)
		tmp = (t_0 * (1.0 / t_1)) - tan(x);
	elseif (eps <= 2.25e-10)
		tmp = eps * (1.0 + ((sin(x) ^ 2.0) / (cos(x) ^ 2.0)));
	else
		tmp = (t_0 / t_1) - tan(x);
	end
	tmp_2 = tmp;
end
code[x_, eps_] := Block[{t$95$0 = N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -7.1e-9], N[(N[(t$95$0 * N[(1.0 / t$95$1), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 2.25e-10], N[(eps * N[(1.0 + N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 / t$95$1), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \tan x + \tan \varepsilon\\
t_1 := 1 - \tan x \cdot \tan \varepsilon\\
\mathbf{if}\;\varepsilon \leq -7.1 \cdot 10^{-9}:\\
\;\;\;\;t_0 \cdot \frac{1}{t_1} - \tan x\\

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

\mathbf{else}:\\
\;\;\;\;\frac{t_0}{t_1} - \tan x\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if eps < -7.09999999999999988e-9

    1. Initial program 57.8%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum99.3%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv99.4%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
    3. Applied egg-rr99.4%

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

    if -7.09999999999999988e-9 < eps < 2.25e-10

    1. Initial program 26.3%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum27.1%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv27.1%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg27.1%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    3. Applied egg-rr27.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Taylor expanded in eps around 0 99.2%

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

    if 2.25e-10 < eps

    1. Initial program 46.3%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum99.6%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv99.6%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg99.6%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Step-by-step derivation
      1. fma-neg99.6%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
      2. associate-*r/99.6%

        \[\leadsto \color{blue}{\frac{\left(\tan x + \tan \varepsilon\right) \cdot 1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. *-rgt-identity99.6%

        \[\leadsto \frac{\color{blue}{\tan x + \tan \varepsilon}}{1 - \tan x \cdot \tan \varepsilon} - \tan x \]
    5. Simplified99.6%

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

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

Alternative 10: 77.6% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan x + \tan \varepsilon\\ \mathbf{if}\;\varepsilon \leq -7.5 \cdot 10^{-6}:\\ \;\;\;\;\mathsf{fma}\left(t_0, 1, -\tan x\right)\\ \mathbf{elif}\;\varepsilon \leq 2.25 \cdot 10^{-10}:\\ \;\;\;\;\varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{1 - x \cdot \tan \varepsilon}{t_0}} - \tan x\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (+ (tan x) (tan eps))))
   (if (<= eps -7.5e-6)
     (fma t_0 1.0 (- (tan x)))
     (if (<= eps 2.25e-10)
       (* eps (+ 1.0 (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))
       (- (/ 1.0 (/ (- 1.0 (* x (tan eps))) t_0)) (tan x))))))
double code(double x, double eps) {
	double t_0 = tan(x) + tan(eps);
	double tmp;
	if (eps <= -7.5e-6) {
		tmp = fma(t_0, 1.0, -tan(x));
	} else if (eps <= 2.25e-10) {
		tmp = eps * (1.0 + (pow(sin(x), 2.0) / pow(cos(x), 2.0)));
	} else {
		tmp = (1.0 / ((1.0 - (x * tan(eps))) / t_0)) - tan(x);
	}
	return tmp;
}
function code(x, eps)
	t_0 = Float64(tan(x) + tan(eps))
	tmp = 0.0
	if (eps <= -7.5e-6)
		tmp = fma(t_0, 1.0, Float64(-tan(x)));
	elseif (eps <= 2.25e-10)
		tmp = Float64(eps * Float64(1.0 + Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0))));
	else
		tmp = Float64(Float64(1.0 / Float64(Float64(1.0 - Float64(x * tan(eps))) / t_0)) - tan(x));
	end
	return tmp
end
code[x_, eps_] := Block[{t$95$0 = N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -7.5e-6], N[(t$95$0 * 1.0 + (-N[Tan[x], $MachinePrecision])), $MachinePrecision], If[LessEqual[eps, 2.25e-10], N[(eps * N[(1.0 + N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(N[(1.0 - N[(x * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \tan x + \tan \varepsilon\\
\mathbf{if}\;\varepsilon \leq -7.5 \cdot 10^{-6}:\\
\;\;\;\;\mathsf{fma}\left(t_0, 1, -\tan x\right)\\

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{1 - x \cdot \tan \varepsilon}{t_0}} - \tan x\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if eps < -7.50000000000000019e-6

    1. Initial program 57.8%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum99.3%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv99.4%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg99.5%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    3. Applied egg-rr99.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Taylor expanded in x around 0 61.7%

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

    if -7.50000000000000019e-6 < eps < 2.25e-10

    1. Initial program 26.3%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum27.1%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv27.1%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg27.1%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    3. Applied egg-rr27.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Taylor expanded in eps around 0 99.2%

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

    if 2.25e-10 < eps

    1. Initial program 46.3%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum99.6%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. clear-num99.6%

        \[\leadsto \color{blue}{\frac{1}{\frac{1 - \tan x \cdot \tan \varepsilon}{\tan x + \tan \varepsilon}}} - \tan x \]
    3. Applied egg-rr99.6%

      \[\leadsto \color{blue}{\frac{1}{\frac{1 - \tan x \cdot \tan \varepsilon}{\tan x + \tan \varepsilon}}} - \tan x \]
    4. Taylor expanded in x around 0 52.2%

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

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

Alternative 11: 77.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\varepsilon \leq -3.6 \cdot 10^{-6} \lor \neg \left(\varepsilon \leq 2.25 \cdot 10^{-10}\right):\\ \;\;\;\;\mathsf{fma}\left(\tan x + \tan \varepsilon, 1, -\tan x\right)\\ \mathbf{else}:\\ \;\;\;\;\varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (if (or (<= eps -3.6e-6) (not (<= eps 2.25e-10)))
   (fma (+ (tan x) (tan eps)) 1.0 (- (tan x)))
   (* eps (+ 1.0 (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))))
double code(double x, double eps) {
	double tmp;
	if ((eps <= -3.6e-6) || !(eps <= 2.25e-10)) {
		tmp = fma((tan(x) + tan(eps)), 1.0, -tan(x));
	} else {
		tmp = eps * (1.0 + (pow(sin(x), 2.0) / pow(cos(x), 2.0)));
	}
	return tmp;
}
function code(x, eps)
	tmp = 0.0
	if ((eps <= -3.6e-6) || !(eps <= 2.25e-10))
		tmp = fma(Float64(tan(x) + tan(eps)), 1.0, Float64(-tan(x)));
	else
		tmp = Float64(eps * Float64(1.0 + Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0))));
	end
	return tmp
end
code[x_, eps_] := If[Or[LessEqual[eps, -3.6e-6], N[Not[LessEqual[eps, 2.25e-10]], $MachinePrecision]], N[(N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision] * 1.0 + (-N[Tan[x], $MachinePrecision])), $MachinePrecision], N[(eps * N[(1.0 + N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -3.6 \cdot 10^{-6} \lor \neg \left(\varepsilon \leq 2.25 \cdot 10^{-10}\right):\\
\;\;\;\;\mathsf{fma}\left(\tan x + \tan \varepsilon, 1, -\tan x\right)\\

\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if eps < -3.59999999999999984e-6 or 2.25e-10 < eps

    1. Initial program 52.0%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum99.5%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv99.5%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg99.5%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    3. Applied egg-rr99.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Taylor expanded in x around 0 56.2%

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

    if -3.59999999999999984e-6 < eps < 2.25e-10

    1. Initial program 26.3%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum27.1%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv27.1%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg27.1%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    3. Applied egg-rr27.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Taylor expanded in eps around 0 99.2%

      \[\leadsto \color{blue}{\varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification77.4%

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

Alternative 12: 57.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\sin \varepsilon}{\cos \varepsilon} \end{array} \]
(FPCore (x eps) :precision binary64 (/ (sin eps) (cos eps)))
double code(double x, double eps) {
	return sin(eps) / cos(eps);
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = sin(eps) / cos(eps)
end function
public static double code(double x, double eps) {
	return Math.sin(eps) / Math.cos(eps);
}
def code(x, eps):
	return math.sin(eps) / math.cos(eps)
function code(x, eps)
	return Float64(sin(eps) / cos(eps))
end
function tmp = code(x, eps)
	tmp = sin(eps) / cos(eps);
end
code[x_, eps_] := N[(N[Sin[eps], $MachinePrecision] / N[Cos[eps], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\sin \varepsilon}{\cos \varepsilon}
\end{array}
Derivation
  1. Initial program 39.3%

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

    \[\leadsto \color{blue}{\frac{\sin \varepsilon}{\cos \varepsilon}} \]
  3. Final simplification55.3%

    \[\leadsto \frac{\sin \varepsilon}{\cos \varepsilon} \]

Alternative 13: 54.7% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\varepsilon \leq -7.8 \cdot 10^{-7} \lor \neg \left(\varepsilon \leq 2.25 \cdot 10^{-10}\right):\\ \;\;\;\;\tan \left(\varepsilon + x\right) - x\\ \mathbf{else}:\\ \;\;\;\;\varepsilon\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (if (or (<= eps -7.8e-7) (not (<= eps 2.25e-10))) (- (tan (+ eps x)) x) eps))
double code(double x, double eps) {
	double tmp;
	if ((eps <= -7.8e-7) || !(eps <= 2.25e-10)) {
		tmp = tan((eps + x)) - x;
	} else {
		tmp = eps;
	}
	return tmp;
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    real(8) :: tmp
    if ((eps <= (-7.8d-7)) .or. (.not. (eps <= 2.25d-10))) then
        tmp = tan((eps + x)) - x
    else
        tmp = eps
    end if
    code = tmp
end function
public static double code(double x, double eps) {
	double tmp;
	if ((eps <= -7.8e-7) || !(eps <= 2.25e-10)) {
		tmp = Math.tan((eps + x)) - x;
	} else {
		tmp = eps;
	}
	return tmp;
}
def code(x, eps):
	tmp = 0
	if (eps <= -7.8e-7) or not (eps <= 2.25e-10):
		tmp = math.tan((eps + x)) - x
	else:
		tmp = eps
	return tmp
function code(x, eps)
	tmp = 0.0
	if ((eps <= -7.8e-7) || !(eps <= 2.25e-10))
		tmp = Float64(tan(Float64(eps + x)) - x);
	else
		tmp = eps;
	end
	return tmp
end
function tmp_2 = code(x, eps)
	tmp = 0.0;
	if ((eps <= -7.8e-7) || ~((eps <= 2.25e-10)))
		tmp = tan((eps + x)) - x;
	else
		tmp = eps;
	end
	tmp_2 = tmp;
end
code[x_, eps_] := If[Or[LessEqual[eps, -7.8e-7], N[Not[LessEqual[eps, 2.25e-10]], $MachinePrecision]], N[(N[Tan[N[(eps + x), $MachinePrecision]], $MachinePrecision] - x), $MachinePrecision], eps]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -7.8 \cdot 10^{-7} \lor \neg \left(\varepsilon \leq 2.25 \cdot 10^{-10}\right):\\
\;\;\;\;\tan \left(\varepsilon + x\right) - x\\

\mathbf{else}:\\
\;\;\;\;\varepsilon\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if eps < -7.80000000000000049e-7 or 2.25e-10 < eps

    1. Initial program 52.0%

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

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

    if -7.80000000000000049e-7 < eps < 2.25e-10

    1. Initial program 26.3%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. add-sqr-sqrt15.1%

        \[\leadsto \color{blue}{\sqrt{\tan \left(x + \varepsilon\right) - \tan x} \cdot \sqrt{\tan \left(x + \varepsilon\right) - \tan x}} \]
      2. sqrt-unprod13.3%

        \[\leadsto \color{blue}{\sqrt{\left(\tan \left(x + \varepsilon\right) - \tan x\right) \cdot \left(\tan \left(x + \varepsilon\right) - \tan x\right)}} \]
      3. pow213.3%

        \[\leadsto \sqrt{\color{blue}{{\left(\tan \left(x + \varepsilon\right) - \tan x\right)}^{2}}} \]
    3. Applied egg-rr13.3%

      \[\leadsto \color{blue}{\sqrt{{\left(\tan \left(x + \varepsilon\right) - \tan x\right)}^{2}}} \]
    4. Taylor expanded in eps around 0 25.1%

      \[\leadsto \sqrt{\color{blue}{{\varepsilon}^{2} \cdot {\left(1 - -1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)}^{2}}} \]
    5. Step-by-step derivation
      1. unpow225.1%

        \[\leadsto \sqrt{\color{blue}{\left(\varepsilon \cdot \varepsilon\right)} \cdot {\left(1 - -1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)}^{2}} \]
      2. cancel-sign-sub-inv25.1%

        \[\leadsto \sqrt{\left(\varepsilon \cdot \varepsilon\right) \cdot {\color{blue}{\left(1 + \left(--1\right) \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)}}^{2}} \]
      3. metadata-eval25.1%

        \[\leadsto \sqrt{\left(\varepsilon \cdot \varepsilon\right) \cdot {\left(1 + \color{blue}{1} \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)}^{2}} \]
      4. *-lft-identity25.1%

        \[\leadsto \sqrt{\left(\varepsilon \cdot \varepsilon\right) \cdot {\left(1 + \color{blue}{\frac{{\sin x}^{2}}{{\cos x}^{2}}}\right)}^{2}} \]
    6. Simplified25.1%

      \[\leadsto \sqrt{\color{blue}{\left(\varepsilon \cdot \varepsilon\right) \cdot {\left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)}^{2}}} \]
    7. Taylor expanded in x around 0 54.5%

      \[\leadsto \color{blue}{\varepsilon} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification52.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -7.8 \cdot 10^{-7} \lor \neg \left(\varepsilon \leq 2.25 \cdot 10^{-10}\right):\\ \;\;\;\;\tan \left(\varepsilon + x\right) - x\\ \mathbf{else}:\\ \;\;\;\;\varepsilon\\ \end{array} \]

Alternative 14: 30.8% accurate, 205.0× speedup?

\[\begin{array}{l} \\ \varepsilon \end{array} \]
(FPCore (x eps) :precision binary64 eps)
double code(double x, double eps) {
	return eps;
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = eps
end function
public static double code(double x, double eps) {
	return eps;
}
def code(x, eps):
	return eps
function code(x, eps)
	return eps
end
function tmp = code(x, eps)
	tmp = eps;
end
code[x_, eps_] := eps
\begin{array}{l}

\\
\varepsilon
\end{array}
Derivation
  1. Initial program 39.3%

    \[\tan \left(x + \varepsilon\right) - \tan x \]
  2. Step-by-step derivation
    1. add-sqr-sqrt20.7%

      \[\leadsto \color{blue}{\sqrt{\tan \left(x + \varepsilon\right) - \tan x} \cdot \sqrt{\tan \left(x + \varepsilon\right) - \tan x}} \]
    2. sqrt-unprod20.6%

      \[\leadsto \color{blue}{\sqrt{\left(\tan \left(x + \varepsilon\right) - \tan x\right) \cdot \left(\tan \left(x + \varepsilon\right) - \tan x\right)}} \]
    3. pow220.6%

      \[\leadsto \sqrt{\color{blue}{{\left(\tan \left(x + \varepsilon\right) - \tan x\right)}^{2}}} \]
  3. Applied egg-rr20.6%

    \[\leadsto \color{blue}{\sqrt{{\left(\tan \left(x + \varepsilon\right) - \tan x\right)}^{2}}} \]
  4. Taylor expanded in eps around 0 14.4%

    \[\leadsto \sqrt{\color{blue}{{\varepsilon}^{2} \cdot {\left(1 - -1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)}^{2}}} \]
  5. Step-by-step derivation
    1. unpow214.4%

      \[\leadsto \sqrt{\color{blue}{\left(\varepsilon \cdot \varepsilon\right)} \cdot {\left(1 - -1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)}^{2}} \]
    2. cancel-sign-sub-inv14.4%

      \[\leadsto \sqrt{\left(\varepsilon \cdot \varepsilon\right) \cdot {\color{blue}{\left(1 + \left(--1\right) \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)}}^{2}} \]
    3. metadata-eval14.4%

      \[\leadsto \sqrt{\left(\varepsilon \cdot \varepsilon\right) \cdot {\left(1 + \color{blue}{1} \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)}^{2}} \]
    4. *-lft-identity14.4%

      \[\leadsto \sqrt{\left(\varepsilon \cdot \varepsilon\right) \cdot {\left(1 + \color{blue}{\frac{{\sin x}^{2}}{{\cos x}^{2}}}\right)}^{2}} \]
  6. Simplified14.4%

    \[\leadsto \sqrt{\color{blue}{\left(\varepsilon \cdot \varepsilon\right) \cdot {\left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)}^{2}}} \]
  7. Taylor expanded in x around 0 29.2%

    \[\leadsto \color{blue}{\varepsilon} \]
  8. Final simplification29.2%

    \[\leadsto \varepsilon \]

Developer target: 76.4% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)} \end{array} \]
(FPCore (x eps) :precision binary64 (/ (sin eps) (* (cos x) (cos (+ x eps)))))
double code(double x, double eps) {
	return sin(eps) / (cos(x) * cos((x + eps)));
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = sin(eps) / (cos(x) * cos((x + eps)))
end function
public static double code(double x, double eps) {
	return Math.sin(eps) / (Math.cos(x) * Math.cos((x + eps)));
}
def code(x, eps):
	return math.sin(eps) / (math.cos(x) * math.cos((x + eps)))
function code(x, eps)
	return Float64(sin(eps) / Float64(cos(x) * cos(Float64(x + eps))))
end
function tmp = code(x, eps)
	tmp = sin(eps) / (cos(x) * cos((x + eps)));
end
code[x_, eps_] := N[(N[Sin[eps], $MachinePrecision] / N[(N[Cos[x], $MachinePrecision] * N[Cos[N[(x + eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)}
\end{array}

Reproduce

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