2tan (problem 3.3.2)

Percentage Accurate: 42.2% → 99.5%
Time: 17.4s
Alternatives: 13
Speedup: 2.0×

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 13 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.5% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan x \cdot \tan \varepsilon\\ t_1 := \frac{{\sin x}^{3}}{{\cos x}^{3}} + \frac{\sin x}{\cos x}\\ t_2 := -\tan x\\ t_3 := \tan x + \tan \varepsilon\\ t_4 := \frac{{\sin x}^{4}}{{\cos x}^{4}}\\ t_5 := \frac{{\sin x}^{2}}{{\cos x}^{2}}\\ t_6 := t_5 + 0.3333333333333333\\ t_7 := t_5 \cdot -0.3333333333333333\\ \mathbf{if}\;\varepsilon \leq -0.00023:\\ \;\;\;\;\mathsf{fma}\left(t_3, \frac{\mathsf{fma}\left(\tan x, \tan \varepsilon, 1\right) \cdot t_0 + 1}{1 - {t_0}^{3}}, t_2\right)\\ \mathbf{elif}\;\varepsilon \leq 0.000195:\\ \;\;\;\;\mathsf{fma}\left(\varepsilon, t_5 + 1, \mathsf{fma}\left({\varepsilon}^{3}, t_6 + \left(t_4 - t_7\right), t_1 \cdot \left(\varepsilon \cdot \varepsilon\right)\right)\right) + {\varepsilon}^{4} \cdot \left(\frac{t_6}{\frac{\cos x}{\sin x}} - \mathsf{fma}\left(-0.3333333333333333, t_1, \frac{\sin x}{\frac{\cos x}{t_7 - t_4}}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(t_3, \frac{-1}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}, t_2\right)\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (* (tan x) (tan eps)))
        (t_1 (+ (/ (pow (sin x) 3.0) (pow (cos x) 3.0)) (/ (sin x) (cos x))))
        (t_2 (- (tan x)))
        (t_3 (+ (tan x) (tan eps)))
        (t_4 (/ (pow (sin x) 4.0) (pow (cos x) 4.0)))
        (t_5 (/ (pow (sin x) 2.0) (pow (cos x) 2.0)))
        (t_6 (+ t_5 0.3333333333333333))
        (t_7 (* t_5 -0.3333333333333333)))
   (if (<= eps -0.00023)
     (fma
      t_3
      (/ (+ (* (fma (tan x) (tan eps) 1.0) t_0) 1.0) (- 1.0 (pow t_0 3.0)))
      t_2)
     (if (<= eps 0.000195)
       (+
        (fma
         eps
         (+ t_5 1.0)
         (fma (pow eps 3.0) (+ t_6 (- t_4 t_7)) (* t_1 (* eps eps))))
        (*
         (pow eps 4.0)
         (-
          (/ t_6 (/ (cos x) (sin x)))
          (fma -0.3333333333333333 t_1 (/ (sin x) (/ (cos x) (- t_7 t_4)))))))
       (fma t_3 (/ -1.0 (fma (tan x) (tan eps) -1.0)) t_2)))))
double code(double x, double eps) {
	double t_0 = tan(x) * tan(eps);
	double t_1 = (pow(sin(x), 3.0) / pow(cos(x), 3.0)) + (sin(x) / cos(x));
	double t_2 = -tan(x);
	double t_3 = tan(x) + tan(eps);
	double t_4 = pow(sin(x), 4.0) / pow(cos(x), 4.0);
	double t_5 = pow(sin(x), 2.0) / pow(cos(x), 2.0);
	double t_6 = t_5 + 0.3333333333333333;
	double t_7 = t_5 * -0.3333333333333333;
	double tmp;
	if (eps <= -0.00023) {
		tmp = fma(t_3, (((fma(tan(x), tan(eps), 1.0) * t_0) + 1.0) / (1.0 - pow(t_0, 3.0))), t_2);
	} else if (eps <= 0.000195) {
		tmp = fma(eps, (t_5 + 1.0), fma(pow(eps, 3.0), (t_6 + (t_4 - t_7)), (t_1 * (eps * eps)))) + (pow(eps, 4.0) * ((t_6 / (cos(x) / sin(x))) - fma(-0.3333333333333333, t_1, (sin(x) / (cos(x) / (t_7 - t_4))))));
	} else {
		tmp = fma(t_3, (-1.0 / fma(tan(x), tan(eps), -1.0)), t_2);
	}
	return tmp;
}
function code(x, eps)
	t_0 = Float64(tan(x) * tan(eps))
	t_1 = Float64(Float64((sin(x) ^ 3.0) / (cos(x) ^ 3.0)) + Float64(sin(x) / cos(x)))
	t_2 = Float64(-tan(x))
	t_3 = Float64(tan(x) + tan(eps))
	t_4 = Float64((sin(x) ^ 4.0) / (cos(x) ^ 4.0))
	t_5 = Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0))
	t_6 = Float64(t_5 + 0.3333333333333333)
	t_7 = Float64(t_5 * -0.3333333333333333)
	tmp = 0.0
	if (eps <= -0.00023)
		tmp = fma(t_3, Float64(Float64(Float64(fma(tan(x), tan(eps), 1.0) * t_0) + 1.0) / Float64(1.0 - (t_0 ^ 3.0))), t_2);
	elseif (eps <= 0.000195)
		tmp = Float64(fma(eps, Float64(t_5 + 1.0), fma((eps ^ 3.0), Float64(t_6 + Float64(t_4 - t_7)), Float64(t_1 * Float64(eps * eps)))) + Float64((eps ^ 4.0) * Float64(Float64(t_6 / Float64(cos(x) / sin(x))) - fma(-0.3333333333333333, t_1, Float64(sin(x) / Float64(cos(x) / Float64(t_7 - t_4)))))));
	else
		tmp = fma(t_3, Float64(-1.0 / fma(tan(x), tan(eps), -1.0)), t_2);
	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[(N[Power[N[Sin[x], $MachinePrecision], 3.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = (-N[Tan[x], $MachinePrecision])}, Block[{t$95$3 = N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(N[Power[N[Sin[x], $MachinePrecision], 4.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 4.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$6 = N[(t$95$5 + 0.3333333333333333), $MachinePrecision]}, Block[{t$95$7 = N[(t$95$5 * -0.3333333333333333), $MachinePrecision]}, If[LessEqual[eps, -0.00023], N[(t$95$3 * N[(N[(N[(N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision] + 1.0), $MachinePrecision] * t$95$0), $MachinePrecision] + 1.0), $MachinePrecision] / N[(1.0 - N[Power[t$95$0, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision], If[LessEqual[eps, 0.000195], N[(N[(eps * N[(t$95$5 + 1.0), $MachinePrecision] + N[(N[Power[eps, 3.0], $MachinePrecision] * N[(t$95$6 + N[(t$95$4 - t$95$7), $MachinePrecision]), $MachinePrecision] + N[(t$95$1 * N[(eps * eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Power[eps, 4.0], $MachinePrecision] * N[(N[(t$95$6 / N[(N[Cos[x], $MachinePrecision] / N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(-0.3333333333333333 * t$95$1 + N[(N[Sin[x], $MachinePrecision] / N[(N[Cos[x], $MachinePrecision] / N[(t$95$7 - t$95$4), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$3 * N[(-1.0 / N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision]]]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \tan x \cdot \tan \varepsilon\\
t_1 := \frac{{\sin x}^{3}}{{\cos x}^{3}} + \frac{\sin x}{\cos x}\\
t_2 := -\tan x\\
t_3 := \tan x + \tan \varepsilon\\
t_4 := \frac{{\sin x}^{4}}{{\cos x}^{4}}\\
t_5 := \frac{{\sin x}^{2}}{{\cos x}^{2}}\\
t_6 := t_5 + 0.3333333333333333\\
t_7 := t_5 \cdot -0.3333333333333333\\
\mathbf{if}\;\varepsilon \leq -0.00023:\\
\;\;\;\;\mathsf{fma}\left(t_3, \frac{\mathsf{fma}\left(\tan x, \tan \varepsilon, 1\right) \cdot t_0 + 1}{1 - {t_0}^{3}}, t_2\right)\\

\mathbf{elif}\;\varepsilon \leq 0.000195:\\
\;\;\;\;\mathsf{fma}\left(\varepsilon, t_5 + 1, \mathsf{fma}\left({\varepsilon}^{3}, t_6 + \left(t_4 - t_7\right), t_1 \cdot \left(\varepsilon \cdot \varepsilon\right)\right)\right) + {\varepsilon}^{4} \cdot \left(\frac{t_6}{\frac{\cos x}{\sin x}} - \mathsf{fma}\left(-0.3333333333333333, t_1, \frac{\sin x}{\frac{\cos x}{t_7 - t_4}}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t_3, \frac{-1}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}, t_2\right)\\


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

    1. Initial program 46.7%

      \[\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. flip3--99.6%

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

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{\color{blue}{1} - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}} \cdot \left(1 \cdot 1 + \left(\left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right) + 1 \cdot \left(\tan x \cdot \tan \varepsilon\right)\right)\right), -\tan x\right) \]
      4. metadata-eval99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}} \cdot \left(\color{blue}{1} + \left(\left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right) + 1 \cdot \left(\tan x \cdot \tan \varepsilon\right)\right)\right), -\tan x\right) \]
      5. *-un-lft-identity99.5%

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

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

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

      \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \color{blue}{\frac{1}{1 - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}} \cdot \left(1 + \left(\tan x \cdot \tan \varepsilon + {\left(\tan x \cdot \tan \varepsilon\right)}^{2}\right)\right)}, -\tan x\right) \]
    6. Step-by-step derivation
      1. associate-*l/99.6%

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

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1 + \left(\tan x \cdot \tan \varepsilon + \color{blue}{\left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)}\right)}{1 - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}}, -\tan x\right) \]
      4. distribute-rgt1-in99.5%

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

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

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

    if -2.3000000000000001e-4 < eps < 1.94999999999999996e-4

    1. Initial program 30.1%

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left({\varepsilon}^{4} \cdot \left(-1 \cdot \frac{\left(0.3333333333333333 - -1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right) \cdot \sin x}{\cos x} + \left(\frac{\sin x \cdot \left(-1 \cdot \frac{{\sin x}^{4}}{{\cos x}^{4}} + -0.3333333333333333 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)}{\cos x} + \left(-0.3333333333333333 \cdot \frac{{\sin x}^{3}}{{\cos x}^{3}} + -0.3333333333333333 \cdot \frac{\sin x}{\cos x}\right)\right)\right)\right) + \left(\varepsilon \cdot \left(1 - -1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right) + \left(-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) + {\varepsilon}^{3} \cdot \left(0.3333333333333333 - \left(-1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}} + \left(-1 \cdot \frac{{\sin x}^{4}}{{\cos x}^{4}} + -0.3333333333333333 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\right)\right)\right)\right)} \]
    5. Simplified99.7%

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

    if 1.94999999999999996e-4 < eps

    1. Initial program 44.7%

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

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

        \[\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.3%

      \[\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. frac-2neg99.3%

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{\color{blue}{-1} + \left(-\left(-\tan x \cdot \tan \varepsilon\right)\right)}, -\tan x\right) \]
      7. distribute-lft-neg-in99.3%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\left(-\tan x\right) \cdot \tan \varepsilon}\right)}, -\tan x\right) \]
      8. add-sqr-sqrt39.5%

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\sqrt{\left(-\tan x\right) \cdot \left(-\tan x\right)}} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      10. sqr-neg68.9%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\sqrt{\color{blue}{\tan x \cdot \tan x}} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      11. sqrt-unprod29.4%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\left(\sqrt{\tan x} \cdot \sqrt{\tan x}\right)} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      12. add-sqr-sqrt48.0%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\tan x} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      13. distribute-lft-neg-in48.0%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \color{blue}{\left(-\tan x\right) \cdot \tan \varepsilon}}, -\tan x\right) \]
      14. add-sqr-sqrt18.6%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \color{blue}{\left(\sqrt{-\tan x} \cdot \sqrt{-\tan x}\right)} \cdot \tan \varepsilon}, -\tan x\right) \]
      15. sqrt-unprod78.4%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \color{blue}{\sqrt{\left(-\tan x\right) \cdot \left(-\tan x\right)}} \cdot \tan \varepsilon}, -\tan x\right) \]
      16. sqr-neg78.4%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \sqrt{\color{blue}{\tan x \cdot \tan x}} \cdot \tan \varepsilon}, -\tan x\right) \]
      17. sqrt-unprod59.7%

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

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

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

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

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

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

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

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

Alternative 2: 99.5% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan x \cdot \tan \varepsilon\\ t_1 := \frac{{\sin x}^{2}}{{\cos x}^{2}}\\ t_2 := \frac{\sin x}{\cos x}\\ t_3 := -\tan x\\ t_4 := \frac{{\sin x}^{3}}{{\cos x}^{3}}\\ t_5 := \tan x + \tan \varepsilon\\ t_6 := -0.3333333333333333 \cdot t_2\\ t_7 := t_4 - t_6\\ \mathbf{if}\;\varepsilon \leq -0.00023:\\ \;\;\;\;\mathsf{fma}\left(t_5, \frac{\mathsf{fma}\left(\tan x, \tan \varepsilon, 1\right) \cdot t_0 + 1}{1 - {t_0}^{3}}, t_3\right)\\ \mathbf{elif}\;\varepsilon \leq 0.00023:\\ \;\;\;\;{\varepsilon}^{4} \cdot \left(0.3333333333333333 \cdot t_2 + \left(t_7 - \frac{\sin x \cdot \left(t_1 \cdot -0.3333333333333333 + \frac{\sin x \cdot \left(t_6 - t_4\right)}{\cos x}\right)}{\cos x}\right)\right) + \left(\left(t_4 + t_2\right) \cdot {\varepsilon}^{2} + \left(\varepsilon \cdot \left(t_1 + 1\right) + {\varepsilon}^{3} \cdot \left(0.3333333333333333 + \left(t_1 + \frac{\sin x \cdot t_7}{\cos x}\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(t_5, \frac{-1}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}, t_3\right)\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (* (tan x) (tan eps)))
        (t_1 (/ (pow (sin x) 2.0) (pow (cos x) 2.0)))
        (t_2 (/ (sin x) (cos x)))
        (t_3 (- (tan x)))
        (t_4 (/ (pow (sin x) 3.0) (pow (cos x) 3.0)))
        (t_5 (+ (tan x) (tan eps)))
        (t_6 (* -0.3333333333333333 t_2))
        (t_7 (- t_4 t_6)))
   (if (<= eps -0.00023)
     (fma
      t_5
      (/ (+ (* (fma (tan x) (tan eps) 1.0) t_0) 1.0) (- 1.0 (pow t_0 3.0)))
      t_3)
     (if (<= eps 0.00023)
       (+
        (*
         (pow eps 4.0)
         (+
          (* 0.3333333333333333 t_2)
          (-
           t_7
           (/
            (*
             (sin x)
             (+
              (* t_1 -0.3333333333333333)
              (/ (* (sin x) (- t_6 t_4)) (cos x))))
            (cos x)))))
        (+
         (* (+ t_4 t_2) (pow eps 2.0))
         (+
          (* eps (+ t_1 1.0))
          (*
           (pow eps 3.0)
           (+ 0.3333333333333333 (+ t_1 (/ (* (sin x) t_7) (cos x))))))))
       (fma t_5 (/ -1.0 (fma (tan x) (tan eps) -1.0)) t_3)))))
double code(double x, double eps) {
	double t_0 = tan(x) * tan(eps);
	double t_1 = pow(sin(x), 2.0) / pow(cos(x), 2.0);
	double t_2 = sin(x) / cos(x);
	double t_3 = -tan(x);
	double t_4 = pow(sin(x), 3.0) / pow(cos(x), 3.0);
	double t_5 = tan(x) + tan(eps);
	double t_6 = -0.3333333333333333 * t_2;
	double t_7 = t_4 - t_6;
	double tmp;
	if (eps <= -0.00023) {
		tmp = fma(t_5, (((fma(tan(x), tan(eps), 1.0) * t_0) + 1.0) / (1.0 - pow(t_0, 3.0))), t_3);
	} else if (eps <= 0.00023) {
		tmp = (pow(eps, 4.0) * ((0.3333333333333333 * t_2) + (t_7 - ((sin(x) * ((t_1 * -0.3333333333333333) + ((sin(x) * (t_6 - t_4)) / cos(x)))) / cos(x))))) + (((t_4 + t_2) * pow(eps, 2.0)) + ((eps * (t_1 + 1.0)) + (pow(eps, 3.0) * (0.3333333333333333 + (t_1 + ((sin(x) * t_7) / cos(x)))))));
	} else {
		tmp = fma(t_5, (-1.0 / fma(tan(x), tan(eps), -1.0)), t_3);
	}
	return tmp;
}
function code(x, eps)
	t_0 = Float64(tan(x) * tan(eps))
	t_1 = Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0))
	t_2 = Float64(sin(x) / cos(x))
	t_3 = Float64(-tan(x))
	t_4 = Float64((sin(x) ^ 3.0) / (cos(x) ^ 3.0))
	t_5 = Float64(tan(x) + tan(eps))
	t_6 = Float64(-0.3333333333333333 * t_2)
	t_7 = Float64(t_4 - t_6)
	tmp = 0.0
	if (eps <= -0.00023)
		tmp = fma(t_5, Float64(Float64(Float64(fma(tan(x), tan(eps), 1.0) * t_0) + 1.0) / Float64(1.0 - (t_0 ^ 3.0))), t_3);
	elseif (eps <= 0.00023)
		tmp = Float64(Float64((eps ^ 4.0) * Float64(Float64(0.3333333333333333 * t_2) + Float64(t_7 - Float64(Float64(sin(x) * Float64(Float64(t_1 * -0.3333333333333333) + Float64(Float64(sin(x) * Float64(t_6 - t_4)) / cos(x)))) / cos(x))))) + Float64(Float64(Float64(t_4 + t_2) * (eps ^ 2.0)) + Float64(Float64(eps * Float64(t_1 + 1.0)) + Float64((eps ^ 3.0) * Float64(0.3333333333333333 + Float64(t_1 + Float64(Float64(sin(x) * t_7) / cos(x))))))));
	else
		tmp = fma(t_5, Float64(-1.0 / fma(tan(x), tan(eps), -1.0)), t_3);
	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[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[Sin[x], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = (-N[Tan[x], $MachinePrecision])}, Block[{t$95$4 = N[(N[Power[N[Sin[x], $MachinePrecision], 3.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$6 = N[(-0.3333333333333333 * t$95$2), $MachinePrecision]}, Block[{t$95$7 = N[(t$95$4 - t$95$6), $MachinePrecision]}, If[LessEqual[eps, -0.00023], N[(t$95$5 * N[(N[(N[(N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision] + 1.0), $MachinePrecision] * t$95$0), $MachinePrecision] + 1.0), $MachinePrecision] / N[(1.0 - N[Power[t$95$0, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$3), $MachinePrecision], If[LessEqual[eps, 0.00023], N[(N[(N[Power[eps, 4.0], $MachinePrecision] * N[(N[(0.3333333333333333 * t$95$2), $MachinePrecision] + N[(t$95$7 - N[(N[(N[Sin[x], $MachinePrecision] * N[(N[(t$95$1 * -0.3333333333333333), $MachinePrecision] + N[(N[(N[Sin[x], $MachinePrecision] * N[(t$95$6 - t$95$4), $MachinePrecision]), $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(t$95$4 + t$95$2), $MachinePrecision] * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision] + N[(N[(eps * N[(t$95$1 + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[Power[eps, 3.0], $MachinePrecision] * N[(0.3333333333333333 + N[(t$95$1 + N[(N[(N[Sin[x], $MachinePrecision] * t$95$7), $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$5 * N[(-1.0 / N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] + t$95$3), $MachinePrecision]]]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \tan x \cdot \tan \varepsilon\\
t_1 := \frac{{\sin x}^{2}}{{\cos x}^{2}}\\
t_2 := \frac{\sin x}{\cos x}\\
t_3 := -\tan x\\
t_4 := \frac{{\sin x}^{3}}{{\cos x}^{3}}\\
t_5 := \tan x + \tan \varepsilon\\
t_6 := -0.3333333333333333 \cdot t_2\\
t_7 := t_4 - t_6\\
\mathbf{if}\;\varepsilon \leq -0.00023:\\
\;\;\;\;\mathsf{fma}\left(t_5, \frac{\mathsf{fma}\left(\tan x, \tan \varepsilon, 1\right) \cdot t_0 + 1}{1 - {t_0}^{3}}, t_3\right)\\

\mathbf{elif}\;\varepsilon \leq 0.00023:\\
\;\;\;\;{\varepsilon}^{4} \cdot \left(0.3333333333333333 \cdot t_2 + \left(t_7 - \frac{\sin x \cdot \left(t_1 \cdot -0.3333333333333333 + \frac{\sin x \cdot \left(t_6 - t_4\right)}{\cos x}\right)}{\cos x}\right)\right) + \left(\left(t_4 + t_2\right) \cdot {\varepsilon}^{2} + \left(\varepsilon \cdot \left(t_1 + 1\right) + {\varepsilon}^{3} \cdot \left(0.3333333333333333 + \left(t_1 + \frac{\sin x \cdot t_7}{\cos x}\right)\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t_5, \frac{-1}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}, t_3\right)\\


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

    1. Initial program 46.7%

      \[\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. flip3--99.6%

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

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{\color{blue}{1} - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}} \cdot \left(1 \cdot 1 + \left(\left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right) + 1 \cdot \left(\tan x \cdot \tan \varepsilon\right)\right)\right), -\tan x\right) \]
      4. metadata-eval99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}} \cdot \left(\color{blue}{1} + \left(\left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right) + 1 \cdot \left(\tan x \cdot \tan \varepsilon\right)\right)\right), -\tan x\right) \]
      5. *-un-lft-identity99.5%

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

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

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

      \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \color{blue}{\frac{1}{1 - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}} \cdot \left(1 + \left(\tan x \cdot \tan \varepsilon + {\left(\tan x \cdot \tan \varepsilon\right)}^{2}\right)\right)}, -\tan x\right) \]
    6. Step-by-step derivation
      1. associate-*l/99.6%

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

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1 + \left(\tan x \cdot \tan \varepsilon + \color{blue}{\left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)}\right)}{1 - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}}, -\tan x\right) \]
      4. distribute-rgt1-in99.5%

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

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

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

    if -2.3000000000000001e-4 < eps < 2.3000000000000001e-4

    1. Initial program 30.1%

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

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

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg32.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-rr32.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 eps around 0 99.7%

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

    if 2.3000000000000001e-4 < eps

    1. Initial program 44.7%

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

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

        \[\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.3%

      \[\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. frac-2neg99.3%

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{\color{blue}{-1} + \left(-\left(-\tan x \cdot \tan \varepsilon\right)\right)}, -\tan x\right) \]
      7. distribute-lft-neg-in99.3%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\left(-\tan x\right) \cdot \tan \varepsilon}\right)}, -\tan x\right) \]
      8. add-sqr-sqrt39.5%

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\sqrt{\left(-\tan x\right) \cdot \left(-\tan x\right)}} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      10. sqr-neg68.9%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\sqrt{\color{blue}{\tan x \cdot \tan x}} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      11. sqrt-unprod29.4%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\left(\sqrt{\tan x} \cdot \sqrt{\tan x}\right)} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      12. add-sqr-sqrt48.0%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\tan x} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      13. distribute-lft-neg-in48.0%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \color{blue}{\left(-\tan x\right) \cdot \tan \varepsilon}}, -\tan x\right) \]
      14. add-sqr-sqrt18.6%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \color{blue}{\left(\sqrt{-\tan x} \cdot \sqrt{-\tan x}\right)} \cdot \tan \varepsilon}, -\tan x\right) \]
      15. sqrt-unprod78.4%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \color{blue}{\sqrt{\left(-\tan x\right) \cdot \left(-\tan x\right)}} \cdot \tan \varepsilon}, -\tan x\right) \]
      16. sqr-neg78.4%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \sqrt{\color{blue}{\tan x \cdot \tan x}} \cdot \tan \varepsilon}, -\tan x\right) \]
      17. sqrt-unprod59.7%

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

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

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

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

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

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

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

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

Alternative 3: 99.6% accurate, 0.1× speedup?

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

\\
\begin{array}{l}
t_0 := \tan x \cdot \tan \varepsilon\\
t_1 := -\tan x\\
t_2 := \tan x + \tan \varepsilon\\
t_3 := \frac{{\sin x}^{2}}{{\cos x}^{2}}\\
\mathbf{if}\;\varepsilon \leq -5.2 \cdot 10^{-5}:\\
\;\;\;\;\mathsf{fma}\left(t_2, \frac{\mathsf{fma}\left(\tan x, \tan \varepsilon, 1\right) \cdot t_0 + 1}{1 - {t_0}^{3}}, t_1\right)\\

\mathbf{elif}\;\varepsilon \leq 5 \cdot 10^{-5}:\\
\;\;\;\;\mathsf{fma}\left({\varepsilon}^{3}, 0.3333333333333333 + \left(\frac{{\sin x}^{4}}{{\cos x}^{4}} - \left(\frac{\sin x}{\frac{\cos x}{\frac{\sin x \cdot -0.3333333333333333}{\cos x}}} - t_3\right)\right), \left(\varepsilon + \varepsilon \cdot t_3\right) + \left(\frac{{\sin x}^{3}}{{\cos x}^{3}} + \frac{\sin x}{\cos x}\right) \cdot \left(\varepsilon \cdot \varepsilon\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t_2, \frac{-1}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}, t_1\right)\\


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

    1. Initial program 46.7%

      \[\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. flip3--99.6%

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

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{\color{blue}{1} - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}} \cdot \left(1 \cdot 1 + \left(\left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right) + 1 \cdot \left(\tan x \cdot \tan \varepsilon\right)\right)\right), -\tan x\right) \]
      4. metadata-eval99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}} \cdot \left(\color{blue}{1} + \left(\left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right) + 1 \cdot \left(\tan x \cdot \tan \varepsilon\right)\right)\right), -\tan x\right) \]
      5. *-un-lft-identity99.5%

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

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

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

      \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \color{blue}{\frac{1}{1 - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}} \cdot \left(1 + \left(\tan x \cdot \tan \varepsilon + {\left(\tan x \cdot \tan \varepsilon\right)}^{2}\right)\right)}, -\tan x\right) \]
    6. Step-by-step derivation
      1. associate-*l/99.6%

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

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1 + \left(\tan x \cdot \tan \varepsilon + \color{blue}{\left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)}\right)}{1 - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}}, -\tan x\right) \]
      4. distribute-rgt1-in99.5%

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

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

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

    if -5.19999999999999968e-5 < eps < 5.00000000000000024e-5

    1. Initial program 30.1%

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

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

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

      \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
    4. Step-by-step derivation
      1. tan-quot32.2%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(0.3333333333333333 - \left(\frac{\sin x \cdot \left(-0.5 \cdot \frac{\sin x}{\cos x} - -0.16666666666666666 \cdot \frac{\sin x}{\cos x}\right)}{\cos x} + \left(-1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}} + -1 \cdot \frac{{\sin x}^{4}}{{\cos x}^{4}}\right)\right)\right) \cdot {\varepsilon}^{3} + \left(\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)\right)} \]
    9. Simplified99.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left({\varepsilon}^{3}, 0.3333333333333333 - \left(\left(\frac{\sin x}{\frac{\cos x}{\frac{-0.3333333333333333 \cdot \sin x}{\cos x}}} - \frac{{\sin x}^{2}}{{\cos x}^{2}}\right) - \frac{{\sin x}^{4}}{{\cos x}^{4}}\right), \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)\right)} \]

    if 5.00000000000000024e-5 < eps

    1. Initial program 44.7%

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

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

        \[\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.3%

      \[\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. frac-2neg99.3%

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{\color{blue}{-1} + \left(-\left(-\tan x \cdot \tan \varepsilon\right)\right)}, -\tan x\right) \]
      7. distribute-lft-neg-in99.3%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\left(-\tan x\right) \cdot \tan \varepsilon}\right)}, -\tan x\right) \]
      8. add-sqr-sqrt39.5%

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\sqrt{\left(-\tan x\right) \cdot \left(-\tan x\right)}} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      10. sqr-neg68.9%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\sqrt{\color{blue}{\tan x \cdot \tan x}} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      11. sqrt-unprod29.4%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\left(\sqrt{\tan x} \cdot \sqrt{\tan x}\right)} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      12. add-sqr-sqrt48.0%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\tan x} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      13. distribute-lft-neg-in48.0%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \color{blue}{\left(-\tan x\right) \cdot \tan \varepsilon}}, -\tan x\right) \]
      14. add-sqr-sqrt18.6%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \color{blue}{\left(\sqrt{-\tan x} \cdot \sqrt{-\tan x}\right)} \cdot \tan \varepsilon}, -\tan x\right) \]
      15. sqrt-unprod78.4%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \color{blue}{\sqrt{\left(-\tan x\right) \cdot \left(-\tan x\right)}} \cdot \tan \varepsilon}, -\tan x\right) \]
      16. sqr-neg78.4%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \sqrt{\color{blue}{\tan x \cdot \tan x}} \cdot \tan \varepsilon}, -\tan x\right) \]
      17. sqrt-unprod59.7%

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \color{blue}{\frac{-1}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}}, -\tan x\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.5%

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

Alternative 4: 99.5% accurate, 0.2× speedup?

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

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

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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t_2, \frac{-1}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}, t_1\right)\\


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

    1. Initial program 46.7%

      \[\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. flip3--99.6%

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

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{\color{blue}{1} - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}} \cdot \left(1 \cdot 1 + \left(\left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right) + 1 \cdot \left(\tan x \cdot \tan \varepsilon\right)\right)\right), -\tan x\right) \]
      4. metadata-eval99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}} \cdot \left(\color{blue}{1} + \left(\left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right) + 1 \cdot \left(\tan x \cdot \tan \varepsilon\right)\right)\right), -\tan x\right) \]
      5. *-un-lft-identity99.5%

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

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

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

      \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \color{blue}{\frac{1}{1 - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}} \cdot \left(1 + \left(\tan x \cdot \tan \varepsilon + {\left(\tan x \cdot \tan \varepsilon\right)}^{2}\right)\right)}, -\tan x\right) \]
    6. Step-by-step derivation
      1. associate-*l/99.6%

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

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1 + \left(\tan x \cdot \tan \varepsilon + \color{blue}{\left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)}\right)}{1 - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}}, -\tan x\right) \]
      4. distribute-rgt1-in99.5%

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

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

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

    if -6.1999999999999999e-7 < eps < 4.4000000000000002e-7

    1. Initial program 29.8%

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

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

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

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

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

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

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

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

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

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

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

        \[\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) \]
      8. unpow299.7%

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

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

    if 4.4000000000000002e-7 < eps

    1. Initial program 44.9%

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

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

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg99.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-rr99.1%

      \[\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. frac-2neg99.1%

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

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

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-\color{blue}{\left(1 + \left(-\tan x \cdot \tan \varepsilon\right)\right)}}, -\tan x\right) \]
      5. distribute-neg-in99.1%

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{\color{blue}{-1} + \left(-\left(-\tan x \cdot \tan \varepsilon\right)\right)}, -\tan x\right) \]
      7. distribute-lft-neg-in99.1%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\left(-\tan x\right) \cdot \tan \varepsilon}\right)}, -\tan x\right) \]
      8. add-sqr-sqrt39.6%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\left(\sqrt{-\tan x} \cdot \sqrt{-\tan x}\right)} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      9. sqrt-unprod69.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\sqrt{\left(-\tan x\right) \cdot \left(-\tan x\right)}} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      10. sqr-neg69.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\sqrt{\color{blue}{\tan x \cdot \tan x}} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      11. sqrt-unprod29.9%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\left(\sqrt{\tan x} \cdot \sqrt{\tan x}\right)} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      12. add-sqr-sqrt48.1%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\tan x} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      13. distribute-lft-neg-in48.1%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \color{blue}{\left(-\tan x\right) \cdot \tan \varepsilon}}, -\tan x\right) \]
      14. add-sqr-sqrt18.2%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \color{blue}{\left(\sqrt{-\tan x} \cdot \sqrt{-\tan x}\right)} \cdot \tan \varepsilon}, -\tan x\right) \]
      15. sqrt-unprod77.7%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \color{blue}{\sqrt{\left(-\tan x\right) \cdot \left(-\tan x\right)}} \cdot \tan \varepsilon}, -\tan x\right) \]
      16. sqr-neg77.7%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \sqrt{\color{blue}{\tan x \cdot \tan x}} \cdot \tan \varepsilon}, -\tan x\right) \]
      17. sqrt-unprod59.4%

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \color{blue}{\frac{-1}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}}, -\tan x\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.5%

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

Alternative 5: 99.5% accurate, 0.2× speedup?

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

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

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


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

    1. Initial program 45.6%

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

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

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg99.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-rr99.2%

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

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

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \color{blue}{-1 \cdot \frac{1}{-\left(1 - \tan x \cdot \tan \varepsilon\right)}}, -\tan x\right) \]
      4. sub-neg99.2%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-\color{blue}{\left(1 + \left(-\tan x \cdot \tan \varepsilon\right)\right)}}, -\tan x\right) \]
      5. distribute-neg-in99.2%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{\color{blue}{\left(-1\right) + \left(-\left(-\tan x \cdot \tan \varepsilon\right)\right)}}, -\tan x\right) \]
      6. metadata-eval99.2%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{\color{blue}{-1} + \left(-\left(-\tan x \cdot \tan \varepsilon\right)\right)}, -\tan x\right) \]
      7. distribute-lft-neg-in99.2%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\left(-\tan x\right) \cdot \tan \varepsilon}\right)}, -\tan x\right) \]
      8. add-sqr-sqrt43.5%

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\sqrt{\left(-\tan x\right) \cdot \left(-\tan x\right)}} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      10. sqr-neg71.1%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\sqrt{\color{blue}{\tan x \cdot \tan x}} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      11. sqrt-unprod27.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\left(\sqrt{\tan x} \cdot \sqrt{\tan x}\right)} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      12. add-sqr-sqrt48.0%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\tan x} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      13. distribute-lft-neg-in48.0%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \color{blue}{\left(-\tan x\right) \cdot \tan \varepsilon}}, -\tan x\right) \]
      14. add-sqr-sqrt20.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \color{blue}{\left(\sqrt{-\tan x} \cdot \sqrt{-\tan x}\right)} \cdot \tan \varepsilon}, -\tan x\right) \]
      15. sqrt-unprod76.2%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \color{blue}{\sqrt{\left(-\tan x\right) \cdot \left(-\tan x\right)}} \cdot \tan \varepsilon}, -\tan x\right) \]
      16. sqr-neg76.2%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \sqrt{\color{blue}{\tan x \cdot \tan x}} \cdot \tan \varepsilon}, -\tan x\right) \]
      17. sqrt-unprod55.7%

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

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

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

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

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

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

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

    if -3.70000000000000004e-7 < eps < 2.05e-7

    1. Initial program 29.8%

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

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

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

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

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

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

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

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

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

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

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

        \[\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) \]
      8. unpow299.7%

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

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

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

Alternative 6: 99.3% accurate, 0.3× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\


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

    1. Initial program 45.3%

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

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

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

        \[\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.0%

      \[\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. frac-2neg99.0%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \color{blue}{\frac{-1}{-\left(1 - \tan x \cdot \tan \varepsilon\right)}}, -\tan x\right) \]
      2. metadata-eval99.0%

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \color{blue}{-1 \cdot \frac{1}{-\left(1 - \tan x \cdot \tan \varepsilon\right)}}, -\tan x\right) \]
      4. sub-neg99.0%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-\color{blue}{\left(1 + \left(-\tan x \cdot \tan \varepsilon\right)\right)}}, -\tan x\right) \]
      5. distribute-neg-in99.0%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{\color{blue}{\left(-1\right) + \left(-\left(-\tan x \cdot \tan \varepsilon\right)\right)}}, -\tan x\right) \]
      6. metadata-eval99.0%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{\color{blue}{-1} + \left(-\left(-\tan x \cdot \tan \varepsilon\right)\right)}, -\tan x\right) \]
      7. distribute-lft-neg-in99.0%

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\left(\sqrt{-\tan x} \cdot \sqrt{-\tan x}\right)} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      9. sqrt-unprod70.7%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\sqrt{\left(-\tan x\right) \cdot \left(-\tan x\right)}} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      10. sqr-neg70.7%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\sqrt{\color{blue}{\tan x \cdot \tan x}} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      11. sqrt-unprod27.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\left(\sqrt{\tan x} \cdot \sqrt{\tan x}\right)} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      12. add-sqr-sqrt47.8%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\tan x} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      13. distribute-lft-neg-in47.8%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \color{blue}{\left(-\tan x\right) \cdot \tan \varepsilon}}, -\tan x\right) \]
      14. add-sqr-sqrt20.3%

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \color{blue}{\sqrt{\left(-\tan x\right) \cdot \left(-\tan x\right)}} \cdot \tan \varepsilon}, -\tan x\right) \]
      16. sqr-neg76.1%

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

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

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \color{blue}{\frac{-1 \cdot 1}{-1 + \tan x \cdot \tan \varepsilon}}, -\tan x\right) \]
      2. metadata-eval99.0%

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

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

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

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

    if -4.29999999999999963e-9 < eps < 5.4999999999999996e-9

    1. Initial program 30.0%

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

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

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

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

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

        \[\leadsto \color{blue}{\varepsilon \cdot 1 + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}} \]
      5. *-rgt-identity99.3%

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

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

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

Alternative 7: 99.3% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan x + \tan \varepsilon\\ \mathbf{if}\;\varepsilon \leq -4.6 \cdot 10^{-9}:\\ \;\;\;\;t_0 \cdot \frac{-1}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 5.4 \cdot 10^{-9}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(t_0, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (+ (tan x) (tan eps))))
   (if (<= eps -4.6e-9)
     (- (* t_0 (/ -1.0 (fma (tan x) (tan eps) -1.0))) (tan x))
     (if (<= eps 5.4e-9)
       (+ eps (* eps (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))
       (fma t_0 (/ 1.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 <= -4.6e-9) {
		tmp = (t_0 * (-1.0 / fma(tan(x), tan(eps), -1.0))) - tan(x);
	} else if (eps <= 5.4e-9) {
		tmp = eps + (eps * (pow(sin(x), 2.0) / pow(cos(x), 2.0)));
	} else {
		tmp = fma(t_0, (1.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 <= -4.6e-9)
		tmp = Float64(Float64(t_0 * Float64(-1.0 / fma(tan(x), tan(eps), -1.0))) - tan(x));
	elseif (eps <= 5.4e-9)
		tmp = Float64(eps + Float64(eps * Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0))));
	else
		tmp = fma(t_0, Float64(1.0 / Float64(1.0 - Float64(tan(x) * tan(eps)))), Float64(-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, -4.6e-9], N[(N[(t$95$0 * N[(-1.0 / N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 5.4e-9], 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[(t$95$0 * N[(1.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 -4.6 \cdot 10^{-9}:\\
\;\;\;\;t_0 \cdot \frac{-1}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)} - \tan x\\

\mathbf{elif}\;\varepsilon \leq 5.4 \cdot 10^{-9}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t_0, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)\\


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

    1. Initial program 46.7%

      \[\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. Applied egg-rr99.5%

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \color{blue}{\frac{-1}{-\left(1 - \tan x \cdot \tan \varepsilon\right)}}, -\tan x\right) \]
      2. metadata-eval99.5%

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

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-\color{blue}{\left(1 + \left(-\tan x \cdot \tan \varepsilon\right)\right)}}, -\tan x\right) \]
      5. distribute-neg-in99.5%

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{\color{blue}{-1} + \left(-\left(-\tan x \cdot \tan \varepsilon\right)\right)}, -\tan x\right) \]
      7. distribute-lft-neg-in99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\left(-\tan x\right) \cdot \tan \varepsilon}\right)}, -\tan x\right) \]
      8. add-sqr-sqrt49.8%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\left(\sqrt{-\tan x} \cdot \sqrt{-\tan x}\right)} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      9. sqrt-unprod73.6%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\sqrt{\left(-\tan x\right) \cdot \left(-\tan x\right)}} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      10. sqr-neg73.6%

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\left(\sqrt{\tan x} \cdot \sqrt{\tan x}\right)} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      12. add-sqr-sqrt47.9%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\tan x} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      13. distribute-lft-neg-in47.9%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \color{blue}{\left(-\tan x\right) \cdot \tan \varepsilon}}, -\tan x\right) \]
      14. add-sqr-sqrt24.2%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \color{blue}{\left(\sqrt{-\tan x} \cdot \sqrt{-\tan x}\right)} \cdot \tan \varepsilon}, -\tan x\right) \]
      15. sqrt-unprod73.9%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \color{blue}{\sqrt{\left(-\tan x\right) \cdot \left(-\tan x\right)}} \cdot \tan \varepsilon}, -\tan x\right) \]
      16. sqr-neg73.9%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \sqrt{\color{blue}{\tan x \cdot \tan x}} \cdot \tan \varepsilon}, -\tan x\right) \]
      17. sqrt-unprod49.7%

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

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \color{blue}{\frac{-1 \cdot 1}{-1 + \tan x \cdot \tan \varepsilon}}, -\tan x\right) \]
      2. metadata-eval99.5%

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

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

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

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

    if -4.5999999999999998e-9 < eps < 5.4000000000000004e-9

    1. Initial program 30.0%

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

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

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

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

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

        \[\leadsto \color{blue}{\varepsilon \cdot 1 + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}} \]
      5. *-rgt-identity99.3%

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

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

    if 5.4000000000000004e-9 < eps

    1. Initial program 44.4%

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.2%

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

Alternative 8: 99.3% accurate, 0.3× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\


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

    1. Initial program 45.3%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \color{blue}{\frac{-1}{-\left(1 - \tan x \cdot \tan \varepsilon\right)}}, -\tan x\right) \]
      2. metadata-eval99.0%

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \color{blue}{-1 \cdot \frac{1}{-\left(1 - \tan x \cdot \tan \varepsilon\right)}}, -\tan x\right) \]
      4. sub-neg99.0%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-\color{blue}{\left(1 + \left(-\tan x \cdot \tan \varepsilon\right)\right)}}, -\tan x\right) \]
      5. distribute-neg-in99.0%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{\color{blue}{\left(-1\right) + \left(-\left(-\tan x \cdot \tan \varepsilon\right)\right)}}, -\tan x\right) \]
      6. metadata-eval99.0%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{\color{blue}{-1} + \left(-\left(-\tan x \cdot \tan \varepsilon\right)\right)}, -\tan x\right) \]
      7. distribute-lft-neg-in99.0%

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\left(\sqrt{-\tan x} \cdot \sqrt{-\tan x}\right)} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      9. sqrt-unprod70.7%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\sqrt{\left(-\tan x\right) \cdot \left(-\tan x\right)}} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      10. sqr-neg70.7%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\sqrt{\color{blue}{\tan x \cdot \tan x}} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      11. sqrt-unprod27.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\left(\sqrt{\tan x} \cdot \sqrt{\tan x}\right)} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      12. add-sqr-sqrt47.8%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \left(-\color{blue}{\tan x} \cdot \tan \varepsilon\right)}, -\tan x\right) \]
      13. distribute-lft-neg-in47.8%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \color{blue}{\left(-\tan x\right) \cdot \tan \varepsilon}}, -\tan x\right) \]
      14. add-sqr-sqrt20.3%

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, -1 \cdot \frac{1}{-1 + \color{blue}{\sqrt{\left(-\tan x\right) \cdot \left(-\tan x\right)}} \cdot \tan \varepsilon}, -\tan x\right) \]
      16. sqr-neg76.1%

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

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

      \[\leadsto \left(\tan x + \tan \varepsilon\right) \cdot \color{blue}{\left(-1 \cdot \frac{1}{-1 + \tan x \cdot \tan \varepsilon}\right)} - \tan x \]
    6. Step-by-step derivation
      1. associate-*r/99.0%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \color{blue}{\frac{-1 \cdot 1}{-1 + \tan x \cdot \tan \varepsilon}}, -\tan x\right) \]
      2. metadata-eval99.0%

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

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

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

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

    if -4.29999999999999963e-9 < eps < 5.4000000000000004e-9

    1. Initial program 30.0%

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

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

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

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

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

        \[\leadsto \color{blue}{\varepsilon \cdot 1 + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}} \]
      5. *-rgt-identity99.3%

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

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

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

Alternative 9: 99.3% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\varepsilon \leq -2.6 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 5.4 \cdot 10^{-9}\right):\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\ \mathbf{else}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (if (or (<= eps -2.6e-9) (not (<= eps 5.4e-9)))
   (- (/ (+ (tan x) (tan eps)) (- 1.0 (* (tan x) (tan eps)))) (tan x))
   (+ eps (* eps (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))))
double code(double x, double eps) {
	double tmp;
	if ((eps <= -2.6e-9) || !(eps <= 5.4e-9)) {
		tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) - tan(x);
	} else {
		tmp = eps + (eps * (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 <= (-2.6d-9)) .or. (.not. (eps <= 5.4d-9))) then
        tmp = ((tan(x) + tan(eps)) / (1.0d0 - (tan(x) * tan(eps)))) - tan(x)
    else
        tmp = eps + (eps * ((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 <= -2.6e-9) || !(eps <= 5.4e-9)) {
		tmp = ((Math.tan(x) + Math.tan(eps)) / (1.0 - (Math.tan(x) * Math.tan(eps)))) - Math.tan(x);
	} else {
		tmp = eps + (eps * (Math.pow(Math.sin(x), 2.0) / Math.pow(Math.cos(x), 2.0)));
	}
	return tmp;
}
def code(x, eps):
	tmp = 0
	if (eps <= -2.6e-9) or not (eps <= 5.4e-9):
		tmp = ((math.tan(x) + math.tan(eps)) / (1.0 - (math.tan(x) * math.tan(eps)))) - math.tan(x)
	else:
		tmp = eps + (eps * (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 <= -2.6e-9) || !(eps <= 5.4e-9))
		tmp = Float64(Float64(Float64(tan(x) + tan(eps)) / Float64(1.0 - Float64(tan(x) * tan(eps)))) - tan(x));
	else
		tmp = Float64(eps + Float64(eps * Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0))));
	end
	return tmp
end
function tmp_2 = code(x, eps)
	tmp = 0.0;
	if ((eps <= -2.6e-9) || ~((eps <= 5.4e-9)))
		tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) - tan(x);
	else
		tmp = eps + (eps * ((sin(x) ^ 2.0) / (cos(x) ^ 2.0)));
	end
	tmp_2 = tmp;
end
code[x_, eps_] := If[Or[LessEqual[eps, -2.6e-9], N[Not[LessEqual[eps, 5.4e-9]], $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[(eps * 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 -2.6 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 5.4 \cdot 10^{-9}\right):\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\

\mathbf{else}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\


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

    1. Initial program 45.3%

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

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

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

        \[\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.0%

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

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

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

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

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

    if -2.6000000000000001e-9 < eps < 5.4000000000000004e-9

    1. Initial program 30.0%

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

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

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

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

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

        \[\leadsto \color{blue}{\varepsilon \cdot 1 + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}} \]
      5. *-rgt-identity99.3%

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

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

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

Alternative 10: 77.0% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -8.5 \cdot 10^{-5}:\\
\;\;\;\;\tan \varepsilon\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if eps < -8.500000000000001e-5 or 2.6999999999999999e-5 < eps

    1. Initial program 45.5%

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

        \[\leadsto \color{blue}{\log \left(e^{\tan \left(x + \varepsilon\right) - \tan x}\right)} \]
    3. Applied egg-rr45.3%

      \[\leadsto \color{blue}{\log \left(e^{\tan \left(x + \varepsilon\right) - \tan x}\right)} \]
    4. Taylor expanded in x around 0 47.5%

      \[\leadsto \log \color{blue}{\left(e^{\frac{\sin \varepsilon}{\cos \varepsilon}}\right)} \]
    5. Step-by-step derivation
      1. *-un-lft-identity47.5%

        \[\leadsto \log \color{blue}{\left(1 \cdot e^{\frac{\sin \varepsilon}{\cos \varepsilon}}\right)} \]
      2. log-prod47.5%

        \[\leadsto \color{blue}{\log 1 + \log \left(e^{\frac{\sin \varepsilon}{\cos \varepsilon}}\right)} \]
      3. metadata-eval47.5%

        \[\leadsto \color{blue}{0} + \log \left(e^{\frac{\sin \varepsilon}{\cos \varepsilon}}\right) \]
      4. add-log-exp47.7%

        \[\leadsto 0 + \color{blue}{\frac{\sin \varepsilon}{\cos \varepsilon}} \]
      5. tan-quot47.9%

        \[\leadsto 0 + \color{blue}{\tan \varepsilon} \]
    6. Applied egg-rr47.9%

      \[\leadsto \color{blue}{0 + \tan \varepsilon} \]
    7. Step-by-step derivation
      1. +-lft-identity47.9%

        \[\leadsto \color{blue}{\tan \varepsilon} \]
    8. Simplified47.9%

      \[\leadsto \color{blue}{\tan \varepsilon} \]

    if -8.500000000000001e-5 < eps < 2.6999999999999999e-5

    1. Initial program 30.1%

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

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

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg32.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-rr32.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 eps around 0 98.4%

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

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

Alternative 11: 77.0% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\varepsilon \leq -3.5 \cdot 10^{-6}:\\ \;\;\;\;\tan \varepsilon\\ \mathbf{elif}\;\varepsilon \leq 2.9 \cdot 10^{-5}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\tan \varepsilon\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (if (<= eps -3.5e-6)
   (tan eps)
   (if (<= eps 2.9e-5)
     (+ eps (* eps (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))
     (tan eps))))
double code(double x, double eps) {
	double tmp;
	if (eps <= -3.5e-6) {
		tmp = tan(eps);
	} else if (eps <= 2.9e-5) {
		tmp = eps + (eps * (pow(sin(x), 2.0) / pow(cos(x), 2.0)));
	} else {
		tmp = tan(eps);
	}
	return tmp;
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    real(8) :: tmp
    if (eps <= (-3.5d-6)) then
        tmp = tan(eps)
    else if (eps <= 2.9d-5) then
        tmp = eps + (eps * ((sin(x) ** 2.0d0) / (cos(x) ** 2.0d0)))
    else
        tmp = tan(eps)
    end if
    code = tmp
end function
public static double code(double x, double eps) {
	double tmp;
	if (eps <= -3.5e-6) {
		tmp = Math.tan(eps);
	} else if (eps <= 2.9e-5) {
		tmp = eps + (eps * (Math.pow(Math.sin(x), 2.0) / Math.pow(Math.cos(x), 2.0)));
	} else {
		tmp = Math.tan(eps);
	}
	return tmp;
}
def code(x, eps):
	tmp = 0
	if eps <= -3.5e-6:
		tmp = math.tan(eps)
	elif eps <= 2.9e-5:
		tmp = eps + (eps * (math.pow(math.sin(x), 2.0) / math.pow(math.cos(x), 2.0)))
	else:
		tmp = math.tan(eps)
	return tmp
function code(x, eps)
	tmp = 0.0
	if (eps <= -3.5e-6)
		tmp = tan(eps);
	elseif (eps <= 2.9e-5)
		tmp = Float64(eps + Float64(eps * Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0))));
	else
		tmp = tan(eps);
	end
	return tmp
end
function tmp_2 = code(x, eps)
	tmp = 0.0;
	if (eps <= -3.5e-6)
		tmp = tan(eps);
	elseif (eps <= 2.9e-5)
		tmp = eps + (eps * ((sin(x) ^ 2.0) / (cos(x) ^ 2.0)));
	else
		tmp = tan(eps);
	end
	tmp_2 = tmp;
end
code[x_, eps_] := If[LessEqual[eps, -3.5e-6], N[Tan[eps], $MachinePrecision], If[LessEqual[eps, 2.9e-5], 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[Tan[eps], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -3.5 \cdot 10^{-6}:\\
\;\;\;\;\tan \varepsilon\\

\mathbf{elif}\;\varepsilon \leq 2.9 \cdot 10^{-5}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if eps < -3.49999999999999995e-6 or 2.9e-5 < eps

    1. Initial program 45.5%

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

        \[\leadsto \color{blue}{\log \left(e^{\tan \left(x + \varepsilon\right) - \tan x}\right)} \]
    3. Applied egg-rr45.3%

      \[\leadsto \color{blue}{\log \left(e^{\tan \left(x + \varepsilon\right) - \tan x}\right)} \]
    4. Taylor expanded in x around 0 47.5%

      \[\leadsto \log \color{blue}{\left(e^{\frac{\sin \varepsilon}{\cos \varepsilon}}\right)} \]
    5. Step-by-step derivation
      1. *-un-lft-identity47.5%

        \[\leadsto \log \color{blue}{\left(1 \cdot e^{\frac{\sin \varepsilon}{\cos \varepsilon}}\right)} \]
      2. log-prod47.5%

        \[\leadsto \color{blue}{\log 1 + \log \left(e^{\frac{\sin \varepsilon}{\cos \varepsilon}}\right)} \]
      3. metadata-eval47.5%

        \[\leadsto \color{blue}{0} + \log \left(e^{\frac{\sin \varepsilon}{\cos \varepsilon}}\right) \]
      4. add-log-exp47.7%

        \[\leadsto 0 + \color{blue}{\frac{\sin \varepsilon}{\cos \varepsilon}} \]
      5. tan-quot47.9%

        \[\leadsto 0 + \color{blue}{\tan \varepsilon} \]
    6. Applied egg-rr47.9%

      \[\leadsto \color{blue}{0 + \tan \varepsilon} \]
    7. Step-by-step derivation
      1. +-lft-identity47.9%

        \[\leadsto \color{blue}{\tan \varepsilon} \]
    8. Simplified47.9%

      \[\leadsto \color{blue}{\tan \varepsilon} \]

    if -3.49999999999999995e-6 < eps < 2.9e-5

    1. Initial program 30.1%

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

      \[\leadsto \color{blue}{\varepsilon \cdot \left(1 - -1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)} \]
    3. Step-by-step derivation
      1. cancel-sign-sub-inv98.4%

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

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

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

        \[\leadsto \color{blue}{\varepsilon \cdot 1 + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}} \]
      5. *-rgt-identity98.5%

        \[\leadsto \color{blue}{\varepsilon} + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}} \]
    4. Simplified98.5%

      \[\leadsto \color{blue}{\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification73.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -3.5 \cdot 10^{-6}:\\ \;\;\;\;\tan \varepsilon\\ \mathbf{elif}\;\varepsilon \leq 2.9 \cdot 10^{-5}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\tan \varepsilon\\ \end{array} \]

Alternative 12: 57.5% accurate, 2.0× speedup?

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

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

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

      \[\leadsto \color{blue}{\log \left(e^{\tan \left(x + \varepsilon\right) - \tan x}\right)} \]
  3. Applied egg-rr26.1%

    \[\leadsto \color{blue}{\log \left(e^{\tan \left(x + \varepsilon\right) - \tan x}\right)} \]
  4. Taylor expanded in x around 0 27.6%

    \[\leadsto \log \color{blue}{\left(e^{\frac{\sin \varepsilon}{\cos \varepsilon}}\right)} \]
  5. Step-by-step derivation
    1. *-un-lft-identity27.6%

      \[\leadsto \log \color{blue}{\left(1 \cdot e^{\frac{\sin \varepsilon}{\cos \varepsilon}}\right)} \]
    2. log-prod27.6%

      \[\leadsto \color{blue}{\log 1 + \log \left(e^{\frac{\sin \varepsilon}{\cos \varepsilon}}\right)} \]
    3. metadata-eval27.6%

      \[\leadsto \color{blue}{0} + \log \left(e^{\frac{\sin \varepsilon}{\cos \varepsilon}}\right) \]
    4. add-log-exp52.8%

      \[\leadsto 0 + \color{blue}{\frac{\sin \varepsilon}{\cos \varepsilon}} \]
    5. tan-quot52.9%

      \[\leadsto 0 + \color{blue}{\tan \varepsilon} \]
  6. Applied egg-rr52.9%

    \[\leadsto \color{blue}{0 + \tan \varepsilon} \]
  7. Step-by-step derivation
    1. +-lft-identity52.9%

      \[\leadsto \color{blue}{\tan \varepsilon} \]
  8. Simplified52.9%

    \[\leadsto \color{blue}{\tan \varepsilon} \]
  9. Final simplification52.9%

    \[\leadsto \tan \varepsilon \]

Alternative 13: 30.6% 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 37.8%

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

      \[\leadsto \color{blue}{\log \left(e^{\tan \left(x + \varepsilon\right) - \tan x}\right)} \]
  3. Applied egg-rr26.1%

    \[\leadsto \color{blue}{\log \left(e^{\tan \left(x + \varepsilon\right) - \tan x}\right)} \]
  4. Taylor expanded in x around 0 27.6%

    \[\leadsto \log \color{blue}{\left(e^{\frac{\sin \varepsilon}{\cos \varepsilon}}\right)} \]
  5. Taylor expanded in eps around 0 30.7%

    \[\leadsto \color{blue}{\varepsilon} \]
  6. Final simplification30.7%

    \[\leadsto \varepsilon \]

Developer target: 76.0% 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 2023182 
(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)))